question
dict
answers
list
id
stringlengths
2
5
accepted_answer_id
stringlengths
2
5
popular_answer_id
stringlengths
2
5
{ "accepted_answer_id": null, "answer_count": 1, "body": "コンボボックスの選択中の項目について文字を右寄せに表示することは可能でしょうか。\n\nTEXTboxではプロパティにTEXTAlighnがあるため設定できますがcomboboxにはないため設定ができず困っています", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-21T14:47:15.473", "favorite_count": 0, "id": "65826", "last_activity_date": "2023-05-31T01:02:05.263", "last_edit_date": "2023-02-10T01:28:06.263", "last_editor_user_id": "3060", "owner_user_id": "39747", "post_type": "question", "score": 0, "tags": [ "c#" ], "title": "C#のコンボボックスの表示時の文字を右寄せで表示したい", "view_count": 5352 }
[ { "body": "コメントに紹介した [Align Text in\nCombobox](https://stackoverflow.com/q/11817062/9014308) の\n[この回答](https://stackoverflow.com/a/58955315/9014308)\nを参考に`ComboBox`に`TextAlign`プロパティを追加してみました。\n\n元記事回答は以下のようにセンタリング固定でしたが、TextAlignプロパティ追加で変更が出来るようにしてあります。\n\n> The post is a bit old but it may be still worth to say: \n> both requirements are possible for Windows Forms ComboBox:\n>\n> * Text align center (text area and the dropdown)\n> * For the text area, find the `Edit` control and set the `ES_CENTER`\n> style for the control.\n> * For the dropdown items or the selected item in drop-down mode, to\n> align text to center, just make the control owner-drawn and draw the text at\n> center.\n> * Get rid of focus rectangle\n> * Make the control owner-drawn and just don't draw focus rectangle.\n>\n\n>\n> 投稿は少し古いですが、それでも言う価値があるかもしれません: \n> Windowsフォームコンボボックスでは、両方の要件が可能です。\n>\n> * テキストの中央揃え(テキスト領域とドロップダウン)\n> * テキスト領域の場合は、`Edit`コントロールを見つけて、コントロールの`ES_CENTER`スタイルを設定します。\n> *\n> ドロップダウンアイテムまたはドロップダウンモードで選択されたアイテムの場合、テキストを中央に揃えるには、コントロールをオーナー描画し、テキストを中央に描画します。\n> * フォーカス長方形を取り除く\n> * コントロールをオーナー描画にし、フォーカス長方形を描画しないようにします。\n>\n\n* * *\n\n`ComboBoxAlign.Designer.cs`\n\n```\n\n namespace ComboBoxAlign\n {\n partial class ComboBoxAlign\n {\n private System.ComponentModel.IContainer components = null;\n protected override void Dispose(bool disposing)\n {\n if (disposing && (components != null))\n {\n components.Dispose();\n }\n base.Dispose(disposing);\n }\n private void InitializeComponent()\n {\n components = new System.ComponentModel.Container();\n }\n }\n }\n \n```\n\n* * *\n\n`ComboBoxAlign.cs`\n\n```\n\n using System;\n using System.Runtime.InteropServices;\n using System.Windows.Forms;\n namespace ComboBoxAlign\n {\n public partial class ComboBoxAlign : ComboBox\n {\n private HorizontalAlignment _TextAlign;\n public HorizontalAlignment TextAlign\n {\n get { return _TextAlign; }\n set { _TextAlign = value; SetupEdit(); } // 直ぐに反映したいなら this.Refresh(); を追加\n }\n public ComboBoxAlign()\n {\n InitializeComponent();\n this.DrawMode = DrawMode.OwnerDrawFixed;\n _TextAlign = HorizontalAlignment.Left;\n }\n [DllImport(\"user32.dll\")]\n private static extern int GetWindowLong(IntPtr hWnd, int nIndex);\n [DllImport(\"user32.dll\")]\n private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);\n private const int GWL_STYLE = -16;\n private const int ES_MASK = -4;\n private const int ES_LEFT = 0x0000;\n private const int ES_CENTER = 0x0001;\n private const int ES_RIGHT = 0x0002;\n [StructLayout(LayoutKind.Sequential)]\n public struct RECT\n {\n public int Left;\n public int Top;\n public int Right;\n public int Bottom;\n public int Width { get { return Right - Left; } }\n public int Height { get { return Bottom - Top; } }\n }\n [DllImport(\"user32.dll\")]\n public static extern bool GetComboBoxInfo(IntPtr hWnd, ref COMBOBOXINFO pcbi);\n [StructLayout(LayoutKind.Sequential)]\n public struct COMBOBOXINFO\n {\n public int cbSize;\n public RECT rcItem;\n public RECT rcButton;\n public int stateButton;\n public IntPtr hwndCombo;\n public IntPtr hwndEdit;\n public IntPtr hwndList;\n }\n protected override void OnHandleCreated(EventArgs e)\n {\n base.OnHandleCreated(e);\n SetupEdit();\n }\n private int buttonWidth = SystemInformation.HorizontalScrollBarArrowWidth;\n private void SetupEdit()\n {\n var info = new COMBOBOXINFO();\n info.cbSize = Marshal.SizeOf(info);\n GetComboBoxInfo(this.Handle, ref info);\n var style = GetWindowLong(info.hwndEdit, GWL_STYLE);\n style &= ES_MASK;\n int align = ES_LEFT;\n switch (_TextAlign)\n {\n case HorizontalAlignment.Center: align = ES_CENTER; break;\n case HorizontalAlignment.Right: align = ES_RIGHT; break;\n }\n style |= align;\n SetWindowLong(info.hwndEdit, GWL_STYLE, style);\n }\n protected override void OnDrawItem(DrawItemEventArgs e)\n {\n base.OnDrawItem(e);\n e.DrawBackground();\n var text = \"\";\n if (e.Index >= 0)\n {\n text = GetItemText(Items[e.Index]);\n }\n TextFormatFlags flags = TextFormatFlags.Left;\n switch (this.TextAlign)\n {\n case HorizontalAlignment.Center: flags = TextFormatFlags.HorizontalCenter; break;\n case HorizontalAlignment.Right: flags = TextFormatFlags.Right; break;\n }\n TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, e.ForeColor, flags);\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T17:02:36.823", "id": "66041", "last_activity_date": "2020-04-27T17:02:36.823", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "65826", "post_type": "answer", "score": 0 } ]
65826
null
66041
{ "accepted_answer_id": null, "answer_count": 1, "body": "YouTubeにPythonのrequestsを使って定期的にアクセスするBOTを作成中です\n\nYouTubeの規約にはこのような記載があります\n\nTerms of Service :\n[https://www.youtube.com/static?template=terms&hl=en&gl=US](https://www.youtube.com/static?template=terms&hl=en&gl=US)\n\n> You are not allowed to: \n> ~中略~ \n> 3\\. access the Service using any automated means (such as robots, botnets\n> or scrapers) except (a) in the case of public search engines, in accordance\n> with YouTube’s robots.txt file; or (b) with YouTube’s prior written\n> permission;\n\n[YouTubeのrobots.txt](https://youtube.com/robots.txt) 内にある `Disallow:`\nで記述されてないリンクにアクセスします \nこの場合は規約に遵守しているといえるでしょうか?\n\n## 追記\n\n背景:\n\n * YouTubeのAPIは厳しい使用制限がかかっておりアプリケーションを非常に作りにくい。\n * 現在作っているのが開発者側のサーバーを用意せず、クライアント側でYouTubeと通信するアプリケーションを作成しているためAPIを使用した実装はほぼ不可能。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-21T15:01:23.710", "favorite_count": 0, "id": "65828", "last_activity_date": "2020-04-22T06:46:53.217", "last_edit_date": "2020-04-22T06:46:53.217", "last_editor_user_id": "19110", "owner_user_id": "39750", "post_type": "question", "score": 0, "tags": [ "python", "youtube-data-api", "youtube" ], "title": "YouTube の robots.txt に従ってプログラムからアクセスしても問題ありませんか?", "view_count": 691 }
[ { "body": "前提として、私は法律の専門家ではないので厳密なところは専門家に聞かないと分からないですが、規約を文字通りに受け取ると、\n\n> access the Service using any automated means **except in the case of public\n> search engines** , in accordance with YouTube’s robots.txt file\n\n太字にした部分に書かれているように、YouTube\nの事前の許可なくクローリングが可能なのは誰でも使える検索エンジンに限定されています。つまり用途次第ではないでしょうか。\n\n※後からこの Q&A を見に来られた方へ:規約の内容は変わりうるので、必ず最新の利用規約をご確認ください。\n\nAPI\nの制限が厳しいのでクロールしたいとのことですが、制限がかかっているのには何かしら理由があるはずなので、これを意図的に回避するのはサービス公開側に親切でなさそうです。YouTube\nAPI のクォータを増やす申請をすることを検討してみてください。", "comment_count": 12, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T00:43:08.490", "id": "65832", "last_activity_date": "2020-04-22T03:35:49.380", "last_edit_date": "2020-04-22T03:35:49.380", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "65828", "post_type": "answer", "score": 2 } ]
65828
null
65832
{ "accepted_answer_id": null, "answer_count": 1, "body": "AndroidをWebカメラとして使うアプリがありますが、あのようなアプリはどのような仕組みで動いているのでしょうか?\n\nAndroid自体をUVC(USB Video Class)対応のデバイスとして動作させるようなことはできなかったと思うのですが、 \nどのようにカメラから映像を取得して、USBカメラとしてPC側に認識させているのでしょうか? \n(もしかして: Android Accessory\nProtocolのドライバをPC側にインストールしてPC側をホストとして認識させてカメラの映像を流している?)\n\n勉強のためにDroidCamのようなアプリを作ってみたいのですがどこから始めればよいのかわからないのです。 \n(Androidのアプリはいくつか作ったことがあります) \nどうすればよいのでしょうか?", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-21T16:54:24.600", "favorite_count": 0, "id": "65831", "last_activity_date": "2020-04-22T12:21:32.800", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5246", "post_type": "question", "score": 0, "tags": [ "android", "usb" ], "title": "AndroidをWeb Cameraとして使うアプリの仕組み", "view_count": 658 }
[ { "body": "間近に迫ったWindows10のアップデート(20H1)でネットワークカメラのサポートが行われるようです。\n\n[Windows 10 デバイスへのネットワーク カメラの接続 (ビルド 18995)](https://docs.microsoft.com/ja-\njp/windows-insider/at-home/whats-new-wip-at-\nhome-20h1#windows-10-%E3%83%87%E3%83%90%E3%82%A4%E3%82%B9%E3%81%B8%E3%81%AE%E3%83%8D%E3%83%83%E3%83%88%E3%83%AF%E3%83%BC%E3%82%AF-%E3%82%AB%E3%83%A1%E3%83%A9%E3%81%AE%E6%8E%A5%E7%B6%9A-%E3%83%93%E3%83%AB%E3%83%89-18995connecting-\nnetwork-cameras-to-windows-10-devices-build-18995) \n[Announcing Windows 10 support for Network\nCameras!](https://blogs.windows.com/windowsdeveloper/2019/10/15/announcing-\nwindows-10-support-for-network-cameras/)\n\n[Connecting Network Cameras to Windows 10\nDevices](https://blogs.windows.com/windowsdeveloper/2019/10/10/connecting-\nnetwork-cameras-to-windows-10-devices/)\n\nONVIF Profile SとかRTSP Uniform Resource\nIdentifierといった仕様をAndroid側で実装していると、Windows10 (20H1)以後はネットワークカメラとして使えるようです。 \nその場合はAndroid側での開発だけで出来るのではないでしょうか。\n\n[ONVIF](https://www.onvif.org/) / [ONVIF Streaming\nSpecification](https://www.onvif.org/specs/stream/ONVIF-Streaming-Spec.pdf) \n[RFC 7826 - Real-Time Streaming Protocol Version 2.0](https://www.rfc-\neditor.org/rfc/rfc7826)\n\nONVIF/RTSP サーバー/クライアントのソースコードを公開しているらしい会社?サイトがありました。 \n[Happytime ONVIF & RTSP Source Code](http://www.happytimesoft.com/index.html)\n\n* * *\n\nアップデート前だと以下のような概要の記事があります。 \n[AndroidスマホをWEBカメラとして使えるようにするアプリ「IP\nWebcam」&「DroidCam」](https://guitarsk.com/pc/archives/1703) \n[How to use your Android phone as a webcam for your\nPC](https://www.digitalcitizen.life/turn-android-smartphone-webcam-windows) \n[How to Use an Android Phone As a Webcam For PC [Windows &\nLinux].](http://www.skipser.com/p/2/p/android-as-webcam.html) \n[AndroidスマホをWebカメラにしてテレワーク](https://k-tai.watch.impress.co.jp/docs/column/minna/1247138.html)\n\nこれらの記事ではいずれもネットワークでサーバー(Android側)/クライアント(PC側)の接続をしているようですね。 \n接続は独自プロトコルか、RTSP等の既存プロトコルを使って、仮想Webカメラデバイスとして実現しているのでしょう。\n\n[Convert RTSP stream to virtual web\ncamera](https://stackoverflow.com/q/26590174/9014308) \n[RTSP stream to virtual video device on Windows\n8](https://stackoverflow.com/q/28231603/9014308)\n\nデバイスドライバの考え方についての記事がこれだと思われます。 \n[In Skype, can I use a camera installed on another\ncomputer?](https://superuser.com/q/936664) \n[USB/IP PROJECT](http://usbip.sourceforge.net/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T12:21:32.800", "id": "65866", "last_activity_date": "2020-04-22T12:21:32.800", "last_edit_date": "2021-10-07T07:34:52.683", "last_editor_user_id": "-1", "owner_user_id": "26370", "parent_id": "65831", "post_type": "answer", "score": 1 } ]
65831
null
65866
{ "accepted_answer_id": null, "answer_count": 0, "body": "Python初心者です。\n\n```\n\n import tkinter as tk\n root= tk.Tk()\n root.mainloop()\n \n```\n\nIDLEで上記コードで1つ画面を出しました。Atomでキーボードのaltとrを押してこのコードを実行すると\n\n```\n\n No module named tkinter\n \n```\n\nと表示されます。atom-runnerやscriptをインストール済みです。 \nAtomではどうやれば実行できるか教えていただきたいです。何卒宜しくお願いします。\n\n### 環境\n\nMac、Python 3.8.2です。python3は、python公式サイトよりインストールしました。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T02:06:37.933", "favorite_count": 0, "id": "65835", "last_activity_date": "2020-04-22T11:30:02.560", "last_edit_date": "2020-04-22T11:30:02.560", "last_editor_user_id": "19110", "owner_user_id": "39758", "post_type": "question", "score": 1, "tags": [ "python", "atom-editor", "tkinter" ], "title": "Atomでコードを実行するとエラーが発生する: No module named tkinter", "view_count": 759 }
[]
65835
null
null
{ "accepted_answer_id": "65840", "answer_count": 2, "body": "### 前提・実現したいこと\n\nGoogle Colab上でGoogle Spread Sheetの指定のページを読み込みたい。\n\n### 発生している問題・エラーメッセージ\n\nURLの末尾に\"gid=\" で指定しても、一番左側のページしか読み込まない \n該当のソースコードで指定したURLは\"gid=57719256\"。これは「罹患者関係」というタブのページのもの。\n\nしかし、以下のページはスプレッドシートの一番左側のタブの「はじめに」というページが表示されている。\n\n```\n\n 0 <!DOCTYPE html><html lang=\"en-US\"><head><scrip...\n 1 はじめにお読みください。\n 2 本データセットの構築プロジェクトは、株式会社SIGNATE(https://signate....\n 3 プロジェクトに参加される方は、「COVID-19チャレンジ(https://signate....\n 4 趣意やタスクの内容を理解した上で、ご参加ください。\n .. ...\n 344 (function(){var a=_.wd();if(_.C(a,18))Jj();els...\n 345 }catch(e){_._DumpException(e)}\n 346 })(this.gbar_);\n 347 // Google Inc.\n 348 </script><script nonce=\"QCXx6uXK7nhk+YWIYJMCBA...\n \n```\n\n### 該当のソースコード\n\n```\n\n !wget --no-check-certificate --output-document=data.csv \"https://docs.google.com/spreadsheets/d/1CnQOf6eN18Kw5Q6ScE_9tFoyddk4FBwFZqZpt_tMOm4/edit#gid=57719256\"\n import pandas as pd\n df = pd.read_csv('data.csv',header=None, sep='\\n')\n print(df) \n \n```\n\n### 補足情報(FW/ツールのバージョンなど)\n\n・使用しているGoogle Spread Sheet :[SIGNATE COVID-2019\nDataset](https://docs.google.com/spreadsheets/d/1CnQOf6eN18Kw5Q6ScE_9tFoyddk4FBwFZqZpt_tMOm4/edit#gid=642719404)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T02:44:33.930", "favorite_count": 0, "id": "65837", "last_activity_date": "2020-04-24T06:32:56.357", "last_edit_date": "2020-04-22T03:30:02.240", "last_editor_user_id": "19110", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "python", "google-spreadsheet", "google-colaboratory" ], "title": "Google Colab上でGoogle Spread Sheetの指定のページを読み込みたい", "view_count": 566 }
[ { "body": "ちゃんと調べていませんが、wget だと JavaScript が実行されておらずシートが変わらないのかもしれません。\n\nプログラムから spreadsheet にアクセスするには、Google Sheets API を使うのが一般的です。\n\n * API の説明:<https://developers.google.com/sheets/api/guides/concepts?hl=ja>\n * Python での使い方の説明:<https://developers.google.com/sheets/api/quickstart/python?hl=ja>", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T03:29:47.063", "id": "65840", "last_activity_date": "2020-04-22T03:29:47.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65837", "post_type": "answer", "score": 0 }, { "body": "自己回答です。\n\nnekketsuuuさんの回答を元に解決した方法を記しておきます。\n\n# 1\\. gspreadをインストール\n\n```\n\n !pip install gspread\n \n```\n\n# 2\\. 各種パッケージをimport\n\n```\n\n from google.colab import auth\n from oauth2client.client import GoogleCredentials\n import gspread\n \n```\n\n# 3\\. 認証処理\n\n```\n\n # 認証処理\n auth.authenticate_user()\n gc = gspread.authorize(GoogleCredentials.get_application_default())\n \n```\n\n# 4.スプレッドシートを開く\n\n```\n\n workbook = gc.open_by_url(スプレッドシートのURL)\n \n```\n\n# 5.該当タブにアクセス\n\n```\n\n worksheet = workbook.worksheet(タブの名前)\n \n```\n\n以上の流れで取得したいワークシートにアクセスできました\n\n* * *\n\n【参考にしたサイト】\n\n * [Google ColaboratoryでGoogleスプレッドシートを読み書きしてみる - uepon日々の備忘録](https://uepon.hatenadiary.com/entry/2018/04/08/110916)\n * [gspreadライブラリの使い方まとめ!Pythonでスプレッドシートを操作する | たぬハック](https://tanuhack.com/library-gspread/)\n * [【Python】スプレッドシートを操作するライブラリ「gspread」の使い方まとめ|Fresopiya](https://fresopiya.com/2019/04/19/gspread/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T05:17:45.990", "id": "65917", "last_activity_date": "2020-04-24T06:32:56.357", "last_edit_date": "2020-04-24T06:32:56.357", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "65837", "post_type": "answer", "score": 2 } ]
65837
65840
65917
{ "accepted_answer_id": null, "answer_count": 1, "body": "## 動的に形が変わる JSON\n\nJSON 中の特定のキーの値などに対応してそれ以外のキーの形が変わるという決まりをもった JSON を考えます。たとえば次のようなものです:\n\n### Externally Tagged\n\n```\n\n [\n {\"RGB\": {\"R\": 98, \"G\": 218, \"B\": 255}},\n {\"YCbCr\": {\"Y\": 255, \"Cb\": 0, \"Cr\": -10}}\n ]\n \n```\n\n### Internally Tagged\n\n```\n\n [\n {\"Space\": \"RGB\", \"R\": 98, \"G\": 218, \"B\": 255},\n {\"Space\": \"YCbCr\", \"Y\": 255, \"Cb\": 0, \"Cr\": -10}\n ]\n \n```\n\n### Adjacently Tagged\n\n```\n\n [\n {\"Space\": \"RGB\", \"Point\": {\"R\": 98, \"G\": 218, \"B\": 255}},\n {\"Space\": \"YCbCr\", \"Point\": {\"Y\": 255, \"Cb\": 0, \"Cr\": -10}}\n ]\n \n```\n\n※ \"○○ Tagged\" という言い方は [Rust の serde のドキュメント](https://serde.rs/enum-\nrepresentations.html)から借用しました。\n\nこのように、特定の値に依存して型が変わるような JSON を Go で unmarshal したい、というのがこの質問の本題です。\n\n## json.RawMessage\n\nこのような JSON を unmarshal するための仕組みのひとつとして、encoding/json には\n[`json.RawMessage`](https://pkg.go.dev/encoding/json?tab=doc#RawMessage)\nという型があります。これは unmarshal する前の生の文字列を保持することで unmarshal を遅延させ、使うときになって必要に応じて\nunmarshal させる、という使われ方が想定されているものです。\n\nAdjacently tagged\nな場合の具体的なソースコードが[ドキュメントに書かれています](https://pkg.go.dev/encoding/json?tab=doc#example-\nRawMessage-Unmarshal)。タグと RawMessage の組として一度 unmarshal し、その後タグで switch して\nRawMessage を unmarshal するというものです。\n\nInternally tagged の場合も、たとえば一度タグだけ unmarshal し、その値で switch して再度全体を unmarshal\nするという流れで書けます。[サンプルコードはこんな感じです](https://play.golang.org/p/K5mOWvyliog)。全体を 2 回\nunmarshal しているのが微妙ではあります。\n\nこのように `json.RawMessage` を使った場合のつらいところが、RawMessage としてデータを取り回していると使うたびに\nunmarshal する必要があるところです。可能であれば、一度 unmarshal すれば後は unmarshal\nせずデータが使い回せるように書きたいです。\n\n## map\n\nスタック・オーバーフローの既存の質問では、map として unmarshal するものも見当たりました。\n\n * [Goで数字がキーのJsonをUnmarshalしたい](https://ja.stackoverflow.com/q/20497/19110)\n * [キーが変動するJsonをパースしたい](https://ja.stackoverflow.com/q/19393/19110)\n * [How to parse/deserialize dynamic JSON](https://stackoverflow.com/q/29347092/5989200)\n\nしかし map として受け取ってしまうと、折角の型システムの恩恵を受けられません:\n\n * 不正な値があったとしても unmarshal 時に弾くことができません。たとえば `map[string]interface{}` として unmarshal すると、string が想定されているキーに int が書かれていたとしてもエラーになりません。`map[string]string` として unmarshal すると、int や struct など string 以外が想定されているキーがあると対応できません。\n * また、JSON の形を型によって一箇所にまとめて管理するのも難しくなります。\n\n同じ理由で、`interface{}` として unmarshal し、使うときに型アサーションするのもやや微妙です。\n\nゆるふわに unmarshal したいときは逆に map や `interface{}`\nは便利でしょうが、今回はしっかり見てあげたいです。なおこの方向性だと型アサーション相当のことを良い感じに裏でやってくれる\n[dproxy](https://github.com/koron/go-dproxy) や\n[jsonpointer](https://github.com/mattn/go-jsonpointer)\nというライブラリが知られており、これはこれで便利そうです。\n\n## 質問\n\nタグに依存して動的に形が変わるような JSON を、上手く unmarshal する方法はあるでしょうか?\n\n使うたびに unmarshal するのではなく、一度 unmarshal すればその後 unmarshal\nしなくてよい方法が良いです。また可能な限り型の恩恵を受けたく、かつ最初の unmarshal 時にエラーが分かると嬉しいです。\n\n環境: Go 1.14", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T03:01:13.403", "favorite_count": 0, "id": "65838", "last_activity_date": "2020-04-22T10:02:15.090", "last_edit_date": "2020-04-22T10:02:15.090", "last_editor_user_id": "19110", "owner_user_id": "19110", "post_type": "question", "score": 1, "tags": [ "go", "json" ], "title": "タグによって動的に形が変わる JSON を Go で一括 unmarshal し、値を保持したい", "view_count": 605 }
[ { "body": "`UnmarshalJSON` メソッドを使う方法を見つけました。このメソッドを生やした型は\n[`json.Unmarshaler`](https://pkg.go.dev/encoding/json?tab=doc#Unmarshaler)\nとして扱われ、`json.Unmarshal` したときに `UnmarshalJSON` が使われるようにカスタムできます。\n\nInternally tagged な場合のサンプルコード:\n\n```\n\n type Color struct {\n Space string\n Content interface{}\n }\n type RGB struct {\n R uint8\n G uint8\n B uint8\n }\n type YCbCr struct {\n Y uint8\n Cb int8\n Cr int8\n }\n \n func (c *Color) UnmarshalJSON(data []byte) error {\n // By convention, Unmarshalers implement UnmarshalJSON([]byte(\"null\")) as a no-op.\n // TODO: ↑この文の解釈、こういうことで合ってるんでしょうか……。\n if bytes.Equal(data, []byte(\"null\")) {\n return nil\n }\n \n var space = struct {\n Space string\n }{}\n err := json.Unmarshal(data, &space)\n if err != nil {\n return fmt.Errorf(\"Space not found: %w\", err)\n }\n c.Space = space.Space\n \n switch space.Space {\n case \"RGB\":\n var rgb RGB\n if err := json.Unmarshal(data, &rgb); err != nil {\n return fmt.Errorf(\"Space says this is RGB, but cannot unmarshal as RGB: %w\", err)\n }\n c.Content = rgb\n case \"YCbCr\":\n var ycbcr YCbCr\n if err := json.Unmarshal(data, &ycbcr); err != nil {\n return fmt.Errorf(\"Space says this is YCbCr, but cannot unmarshal as YCbCr: %w\", err)\n }\n c.Content = ycbcr\n default:\n return errors.New(\"Unknown Space: \" + space.Space)\n }\n \n return nil\n }\n \n func main() {\n var j = []byte(`[\n {\"Space\": \"YCbCr\", \"Y\": 255, \"Cb\": 0, \"Cr\": -10},\n {\"Space\": \"RGB\", \"R\": 98, \"G\": 218, \"B\": 255}\n ]`)\n var colors []Color\n err := json.Unmarshal(j, &colors)\n if err != nil {\n log.Fatal(err)\n }\n \n for _, c := range colors {\n switch c.Space {\n case \"RGB\":\n rgb, _ := c.Content.(RGB)\n fmt.Println(c.Space, rgb)\n case \"YCbCr\":\n ycbcr, _ := c.Content.(YCbCr)\n fmt.Println(c.Space, ycbcr)\n }\n }\n }\n \n```\n\nこれで unmarshal は 1 回になりました。\n\n欠点として、タグを string で比較している点と、必ず成功する型アサーションをしないといけない点があります(実質 tagged union\n的なことをしています)。このあたりを何とかできる方法があればコメントや別回答で教えていただけるとありがたいです。go generate\nで上手くやるなどありそう……?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T03:01:13.403", "id": "65839", "last_activity_date": "2020-04-22T03:48:59.737", "last_edit_date": "2020-04-22T03:48:59.737", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "65838", "post_type": "answer", "score": 1 } ]
65838
null
65839
{ "accepted_answer_id": "65844", "answer_count": 1, "body": "if else文の中に更にif else文を作りたいのですが、エラーが出ます。 \nエラー内容は、以下の通りです。\n\n```\n\n File \"type.py\", line 14\n if d==\"handsum\":\n ^\n IndentationError: unindent does not match any outer indentation level\n \n```\n\n2つ目のif文(if d==\"handsum\":)は1つ目のif文より右に書いているのですが、うまくいきません。 \nどなたか解決策を教えていただければ幸いです。\n\nコード\n\n```\n\n qs=[\"What is your name?\",\n \"What is your favorite\",\n \"What is your queset?\"]\n c=[\"trump\",\"USA\"]\n \n a=input(qs)\n \n if a==\"president\":\n d=input(c) \n if d==\"handsum\":\n print(\"great\")\n else:\n print(\"you are fired\")\n else:\n print(\"bye\")\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T03:43:05.010", "favorite_count": 0, "id": "65841", "last_activity_date": "2020-04-22T04:26:22.857", "last_edit_date": "2020-04-22T04:22:19.003", "last_editor_user_id": "3060", "owner_user_id": "39688", "post_type": "question", "score": 1, "tags": [ "python" ], "title": "if else文の中に更にif else文を作りたいのですが、エラーが出ます。どうすればいいでしょうか?", "view_count": 160 }
[ { "body": "単純に、同じレベルのインデントの桁位置が合っていないからです。 \n大雑把に感じだけでインデントしているように見えているだけでは駄目で、厳密に桁位置も合わせる必要があります。\n\n以下は何処が間違っているかの指摘です。 \n(他に微妙にインデント桁位置が統一されていません)\n\n```\n\n if a==\"president\":\n d=input(c) ## この行のインデントの桁位置と\n if d==\"handsum\": ## 上の行と桁位置が合っていない\n print(\"great\")\n else: ## 対応する if と桁位置が合っていない\n print(\"you are fired\")\n else:\n print(\"bye\")\n \n```\n\n修正すると以下になります。他の行のインデントも併せて1インデント4桁にしてあります。\n\n```\n\n if a==\"president\":\n d=input(c) ## この行のインデントの桁位置と\n if d==\"handsum\": ## 上の行と桁位置が合っていない\n print(\"great\")\n else: ## 対応する if と桁位置が合っていない\n print(\"you are fired\")\n else:\n print(\"bye\")\n \n```\n\nまた、空白とタブを混在させてもいけません。見た目は同じでも文字数としては違うのでインデントが合わないことになります。どちらかに統一していればOKです。 \nそれからたまに間違えて全角空白を入れてしまうこともあるので注意しましょう。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T04:26:22.857", "id": "65844", "last_activity_date": "2020-04-22T04:26:22.857", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "65841", "post_type": "answer", "score": 3 } ]
65841
65844
65844
{ "accepted_answer_id": null, "answer_count": 1, "body": "こんにちは。 \n現在以下のようなソースコードでxmlを生成しています。\n\n```\n\n public class Main {\n \n public static void main(String[] args) {\n \n Kusa kusa = new Kusa();\n kusa.setKusa(\"草\");\n Kusa2 kusa2 = new Kusa2();\n kusa2.setKusa2(\"草2\");\n kusa.setKusa2(kusa2);\n Kusa3 kusa3 = new Kusa3();\n kusa3.setKusa3(\"草3\");\n kusa.setKusa3(kusa3);\n System.out.println(\"**************************************\");\n JAXB.marshal(kusa, System.out);\n System.out.println(\"**************************************\");\n }\n }\n \n```\n\n```\n\n public class Kusa {\n \n private String kusa;\n private Kusa2 kusa2;\n private Kusa3 kusa3;\n @XmlElement(nillable = true)\n public String getKusa() {\n return kusa;\n }\n \n public void setKusa(String kusa) {\n this.kusa = kusa;\n }\n \n public Kusa2 getKusa2() {\n return kusa2;\n }\n \n public void setKusa2(Kusa2 kusa2) {\n this.kusa2 = kusa2;\n }\n public Kusa3 getKusa3() {\n return kusa3;\n }\n \n public void setKusa3(Kusa3 kusa3) {\n this.kusa3 = kusa3;\n }\n \n }\n \n```\n\n```\n\n public class Kusa2 {\n private String kusa2;\n \n \n public String getKusa2() {\n return kusa2;\n }\n @XmlElement(nillable = true)\n public void setKusa2(String kusa2) {\n this.kusa2 = kusa2;\n }\n \n }\n \n```\n\n```\n\n public class Kusa3 {\n private String kusa3;\n \n public String getKusa3() {\n return kusa3;\n }\n @XmlElement(nillable = true)\n public void setKusa3(String kusa3) {\n this.kusa3 = kusa3;\n }\n }\n \n```\n\nこのソースにより生成されるxmlが\n\n```\n\n <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n <kusa>\n <kusa>草</kusa>\n <kusa2>\n <kusa2>草2</kusa2>\n </kusa2>\n <kusa3>\n <kusa3>草3</kusa3>\n </kusa3>\n </kusa>\n \n```\n\nになるのですが、やりたいこととして、kusa2・kusa3のクラスを分けた状態で、\n\n```\n\n <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n <kusa>\n <kusa>草</kusa>\n <kusa2>\n <kusa2>草2</kusa2>\n <kusa3>草3</kusa3>\n </kusa2>\n </kusa>\n \n```\n\nの様にxmlを出力したいです。\n\n勉強を始めて間もない為、見当違いなことを言っているかもしれませんが、ご教授のほど宜しくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T04:36:55.797", "favorite_count": 0, "id": "65845", "last_activity_date": "2020-04-28T07:33:06.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37980", "post_type": "question", "score": 0, "tags": [ "java", "xml" ], "title": "JAXB.marshal時の階層について", "view_count": 185 }
[ { "body": "`kusa2`と`kusa3`をelementに持つクラスを新しく定義してやればよいかと考えます。 \n下記では `Kusa2Parent` というクラスを定義しています。\n\n```\n\n class Kusa {\n \n private String kusa;\n private Kusa2Parent kusa2 = new Kusa2Parent();\n \n @XmlElement(nillable = true)\n public String getKusa() {\n return kusa;\n }\n \n public void setKusa(String kusa) {\n this.kusa = kusa;\n }\n \n @XmlElement(nillable = true, name = \"kusa2\")\n public Kusa2Parent getKusa2() {\n return kusa2;\n }\n \n public void setKusa2(Kusa2 kusa2) {\n this.kusa2.setKusa2(kusa2);\n }\n \n public void setKusa3(Kusa3 kusa3) {\n this.kusa2.setKusa3(kusa3);\n }\n }\n \n class Kusa2Parent {\n private Kusa2 kusa2;\n private Kusa3 kusa3;\n \n @XmlElement\n public String getKusa2() {\n return kusa2.getKusa2();\n }\n \n @XmlElement\n public String getKusa3() {\n return kusa3.getKusa3();\n }\n \n public void setKusa2(Kusa2 kusa2) {\n this.kusa2 = kusa2;\n }\n \n public void setKusa3(Kusa3 kusa3) {\n this.kusa3 = kusa3;\n }\n }\n \n```\n\n[コード差分](https://github.com/yukihane/stackoverflow-qa/compare/01eca65..1f249e9)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:26:43.943", "id": "66061", "last_activity_date": "2020-04-28T07:33:06.773", "last_edit_date": "2020-04-28T07:33:06.773", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "65845", "post_type": "answer", "score": 0 } ]
65845
null
66061
{ "accepted_answer_id": "65849", "answer_count": 1, "body": "### 前提・実現したいこと\n\nNode.jsで画像をサーバーアップロードして表示するというちょっとしたWebアプリケーションを作ろうとしています。 \nまずは画像をアップロードするところを作ろうと思い下記のサイトを参考にして作成しました。 \nしかし、アップロードされた画像が表示できない形式になってしまっているため、どうしたら表示できる形式で出力できるのか教えていただきたいです。\n\n[Node.jsで画像アップロードを受けつけるサーバー](https://qiita.com/n0bisuke/items/12a1d0fed0f544269489)\n\n### 発生している問題\n\nFiddlerを用いてJEPG画像をPOSTしたところ、サーバー側で受信し、JPEG形式のファイルを出力させることができました。 \nしかし、いざJPEG画像を開くと「サポートされていない」とでてしまい、ファイル自体は0KBでもないのですが、開くことができません。\n\n[![写真ビューワーで表示](https://i.stack.imgur.com/qhSRv.png)](https://i.stack.imgur.com/qhSRv.png)\n\nTextに出力させたところ沢山の文字列が入ってたため何かしら出力されているものと思いますが、なぜ表示できないのかわかりません。\n\n[![画像の出力をテキストファイル](https://i.stack.imgur.com/gvNCx.png)](https://i.stack.imgur.com/gvNCx.png)\n\n### 該当のソースコード\n\nNode.js\n\n```\n\n 'use strict';\n \n const fs = require('fs');\n const express = require('express');\n const app = express();\n const PORT = process.env.PORT || 3000;\n \n app.get('/', (req, res) => res.send('POSTでアップロードしてください。'));\n \n app.post('/', (req, res) => {\n let buffers = [];\n let cnt = 0;\n \n req.on('data', (chunk) => {\n buffers.push(chunk);\n console.log(++cnt);\n });\n \n req.on('end', () => {\n console.log(`[done] Image upload`);\n req.rawBody = Buffer.concat(buffers);\n //書き込み\n fs.writeFile('./img.jpg', req.rawBody, 'utf-8',(err) => {\n if(err) return;\n console.log(`[done] Image save`);\n });\n });\n });\n \n app.listen(PORT);\n \n```\n\n### 試したこと\n\n様々なJEPG画像で試しましたが、出力されるファイルのKBが変わるため送信はできていると思います。\n\n### 補足情報(FW/ツールのバージョンなど)\n\n環境は \nWindows 10 \nNode.js v6.11.5 \nPowershell \nを使用しています。\n\n他にも画像をアップロードする方法をご存知でしたらご教授願いたいです。 \nまた、そもそも画像をアップロード自体、Node.jsではしない等あれば、Webアプリケーションでは通常どのような手法が用いられるのかも教えていただきたいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T04:54:47.410", "favorite_count": 0, "id": "65846", "last_activity_date": "2020-04-22T09:07:38.830", "last_edit_date": "2020-04-22T05:34:13.407", "last_editor_user_id": "3060", "owner_user_id": "39762", "post_type": "question", "score": 0, "tags": [ "node.js" ], "title": "Node.jsのwriteFileで出力したjpeg画像がサポートされていない形式になってしまっていて見ることができない。", "view_count": 397 }
[ { "body": "受信する方法と送信する方法がミスマッチしているのだと思います。\n\n質問者さんは `<input type=file name=\"fieldNameHere\">` のようなフォームを `multipart/form-\ndata` 形式で送っているようです。 \n参考にされたページのコードは、フォームではない手段でバイナリを直接リクエストボディに入れた場合のものです。\n\nフォームで送信されたファイルを受け取るには、[multer](https://github.com/expressjs/multer)\nなどを使うと簡単そうです。\n\n```\n\n let multer = require('multer')\n let upload = multer({dest: './'})\n ...\n app.post('/', upload.single('fieldNameHere'), (req, res) => {\n // req.file がアップロードされたファイルのメタデータ(ファイル内容そのものではない)\n });\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T06:30:53.413", "id": "65849", "last_activity_date": "2020-04-22T09:07:38.830", "last_edit_date": "2020-04-22T09:07:38.830", "last_editor_user_id": "3475", "owner_user_id": "3475", "parent_id": "65846", "post_type": "answer", "score": 0 } ]
65846
65849
65849
{ "accepted_answer_id": null, "answer_count": 0, "body": "・環境 \nAmazon Linux上で、以下のバージョンのモジュールをインストール\n\napache 2.2.34 (Unix) \nmysql Ver 14.14 Distrib 5.7.28 \npython 3.6.10 \n(pip 20.0.2) \nmod_wsgi 4.7.1 \ndjango 3.0.5\n\n・Python仮想環境の作成 \n/home配下にvenvで仮想環境(/home/myenv)を作成(python3を使用)\n\n・Djangoプロジェクト作成 \n/home/myenv配下にDjangoプロジェクト(ここではoozumou_project2というプロジェクト)作成\n\n・できていること \nApacheからmod_wsgiを介してDjangoにリクエストを渡すところまではできていることを確認しています(ブラウザにテキストを表示するところまでは確認済み)\n\n・できていないこと \n以下のエラーが出ています。\n\n```\n\n sudo vi /etc/httpd/logs/error_log\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] mod_wsgi (pid=17407): Failed to exec Python script file '/var/www/oozumou/oozumou_project/oozumou_project/wsgi.py'.\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] mod_wsgi (pid=17407): Exception occurred processing WSGI script '/var/www/oozumou/oozumou_project/oozumou_project/wsgi.py'.\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] Traceback (most recent call last):\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] File \"/var/www/oozumou/oozumou_project/oozumou_project/wsgi.py\", line 12, in <module>\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] from django.core.wsgi import get_wsgi_application\n [Mon Apr 20 09:00:31 2020] [error] [client 210.138.73.119] ModuleNotFoundError: No module named 'django'\n \n```\n\n最終行を読むとdjangoモジュールを読み込むことができていないことが予想されます。\n\n・Apacheの設定ファイル \n/etc/httpd/conf.d 配下に django.conf という設定ファイルを作っています。\n\n```\n\n LoadModule wsgi_module modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so\n \n WSGIScriptAlias / /home/myenv/oozumou_project2/oozumou_project2/wsgi.py\n WSGIPythonPath /home/myenv/\n WSGIPythonHome /home/myenv/\n \n <Directory /home/myenv/oozumou_project2/oozumou_project2/>\n <Files wsgi.py>\n </Files>\n # Require all granted\n Order allow,deny\n Allow from all\n Satisfy Any\n </Directory>\n \n```\n\n問題なのは、WSGIPythonPathかWSGIPythonHomeかと思われます。 \nWSGIの公式サイトやDjangoチュートリアルを読んでもこれらの意味がイマイチ理解できません。\n\n正しい設定とともに、意味を教えていただけると幸いです。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T05:20:57.387", "favorite_count": 0, "id": "65847", "last_activity_date": "2020-04-22T05:20:57.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39763", "post_type": "question", "score": 0, "tags": [ "apache", "django" ], "title": "Amazon Linux + Django 3.0.5 + Apache 2.2.34 + mod_wsgi 4.7.1でModuleNotFoundError: No module named 'django'", "view_count": 837 }
[]
65847
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "MicrosoftのWeb版Officeを使っているのですが、印刷する際、一旦PDF形式でローカルに保存してからAcrobatReaderで開いて印刷しないといけません。\n\nローカルプリンタにダイレクトに印刷する方法ありますか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T05:31:46.080", "favorite_count": 0, "id": "65848", "last_activity_date": "2020-04-22T06:36:08.910", "last_edit_date": "2020-04-22T05:40:21.693", "last_editor_user_id": "3060", "owner_user_id": "39638", "post_type": "question", "score": 0, "tags": [ "ms-office" ], "title": "MicrosoftのWeb版Officeでローカルプリンタにダイレクトに印刷する方法ありますか?", "view_count": 354 }
[ { "body": "すいませんでした。そもそも、プリンタのドライバインストールしてませんでした。申し訳ありませんでした。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T06:36:08.910", "id": "65850", "last_activity_date": "2020-04-22T06:36:08.910", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39638", "parent_id": "65848", "post_type": "answer", "score": 1 } ]
65848
null
65850
{ "accepted_answer_id": null, "answer_count": 4, "body": "C#の **const**\nは、変数の型の前につけますね。値を書き換えられなくなります。値が変えられなくなったらどうなりますか?どういう意味があるのでしょうか?そして、そのメリットとは何ですか。constはどんなときに必要ですか?\n\n```\n\n namespace test\n {\n class Program\n {\n static void Main(string[] args)\n {\n const double TAX = 0.08\n int price = 1000;\n double result;\n \n result = price * TAX;\n }\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T06:39:08.897", "favorite_count": 0, "id": "65851", "last_activity_date": "2020-12-21T00:41:50.710", "last_edit_date": "2020-12-21T00:41:50.710", "last_editor_user_id": "3060", "owner_user_id": "38025", "post_type": "question", "score": 1, "tags": [ "c#" ], "title": "constをつける意味とメリットを教えてください。", "view_count": 785 }
[ { "body": "[constキーワード](https://docs.microsoft.com/ja-jp/dotnet/csharp/language-\nreference/keywords/const)で説明されています。\n\n> いずれかの時点で変わることが予想される情報を表すために定数を作成してはなりません。\n> たとえば、サービスの価格、製品バージョン番号、会社のブランド名などを格納するためには定数フィールドを使用しないでください。\n> これらの値は時間の経過とともに変更される場合があります。\n\nというわけでほとんど使わなくてもいいと思います。\n\n* * *\n\nマイナス投票するほどとは思いませんが、速度や効率が上がるとは思いません。.NETではJITコンパイルされます。つまり実行時に変数のアクセス状況を判断してコンパイルが可能なため、const未指定であったとしても変更されないことを検出した上で最適化が行われます。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T06:57:07.670", "id": "65852", "last_activity_date": "2020-04-22T10:43:11.033", "last_edit_date": "2020-04-22T10:43:11.033", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "65851", "post_type": "answer", "score": 3 }, { "body": "値が変わらないことが保証されます。 \nそれを前提としたコードが組めるようになったり、それを前提とした最適化が施せるようになり、実行速度、実行効率が向上します", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T06:58:38.177", "id": "65853", "last_activity_date": "2020-04-22T06:58:38.177", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27481", "parent_id": "65851", "post_type": "answer", "score": 1 }, { "body": "オイラんところのソースコードを grep したら `const` を使っているのは\n\n * 既にある外部機器を制御するソフトで、当該機器の仕様を表記しているところ(通信電文の電文長とかビット位置の意味とか)\n * `DllImport` で呼ぶ外部関数の仕様を表記しているところ(固定バッファサイズとか)\n * 仕様公開済みバイナリファイルでのマジックナンバー\n\nなどでした。\n\n[c#](/questions/tagged/c%23 \"'c#' のタグが付いた質問を表示\") においては、プログラム自体の何かを記述するために\n`const` を使う必要はまず無いでしょう。「既に仕様が決まっている何かに由来する定数」を表記するには便利に使えます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T07:15:35.403", "id": "65854", "last_activity_date": "2020-04-22T07:15:35.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "65851", "post_type": "answer", "score": 0 }, { "body": "大人数で開発するとき、書き換えられちゃ困る変数てのは結構ある。 \nconstはコンパイラのためのものというよりプログラマのためのものかな。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T10:52:43.550", "id": "65862", "last_activity_date": "2020-04-22T10:52:43.550", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18637", "parent_id": "65851", "post_type": "answer", "score": 1 } ]
65851
null
65852
{ "accepted_answer_id": null, "answer_count": 0, "body": "PostgreSQLで、特定のDBのサイズ(不要領域を除く)を知りたいのですが、\n\n```\n\n select pg_database_size('DBNAME');\n \n```\n\nとして得られるサイズは、不要領域も含む実サイズのようで、ここから VACUUM 後に減るであろうサイズにできるだけ近い \n不要領域を除いたサイズが知りたいのですが、何か良い方法はあるでしょうか?\n\nできるだけ軽い方法だとありがたいのですが。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T07:29:43.323", "favorite_count": 0, "id": "65856", "last_activity_date": "2020-04-22T07:29:43.323", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14738", "post_type": "question", "score": 1, "tags": [ "postgresql", "database" ], "title": "PostgreSQLで、特定のDBのサイズ(不要領域を除く)を知りたい", "view_count": 120 }
[]
65856
null
null
{ "accepted_answer_id": "65868", "answer_count": 2, "body": "djangoのmanage.py help でコマンドを確認できますが、そのコマンドの詳細な使い方を見れるコマンドはありますか?\n\n<https://hodalog.com/how-to-revert-migrations/> \nリンク先のmigrateの使い方などをhelpなどを使ってオプションを確認できますか?\n\nたとえば、manage.py\nでmigrateコマンドでマイグレイションを以前を戻したり、zeroを使ってリセットしたりできるとおもいますが、helpなどのコマンドから確認できるかということです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T08:48:41.070", "favorite_count": 0, "id": "65857", "last_activity_date": "2020-04-22T15:12:16.073", "last_edit_date": "2020-04-22T12:18:50.123", "last_editor_user_id": "19110", "owner_user_id": "36091", "post_type": "question", "score": 2, "tags": [ "django" ], "title": "manage.pyのコマンドの詳細なヘルプが見たい", "view_count": 151 }
[ { "body": "コマンドよりも、このページで解説されている内容と思われます。 \nhelpコマンドも冒頭に記述されていますが、コマンド記述とオプションのリスト程度らしいので、結局このページの内容になるのでは?\n\n[django-admin と manage.py](https://docs.djangoproject.com/ja/3.0/ref/django-\nadmin/)\n\n> 本項ではコマンドラインの実行例は一貫して **django-admin** を使用しますが、実行例は全て **manage.py** もしくは\n> **python -m django** でも同様に利用可能です。\n\nただし、日本語化は少なめで多くが英語のままなので、英語のページを機械翻訳に掛けた方が良いかもしれません。 \nいきなりhelpの呼び出し方自身が以下のように英語のままです。\n\n> **Getting runtime help**\n>\n> django-admin help\n>\n> Run **django-admin help** to display usage information and a list of the\n> commands provided by each application. \n> Run **django-admin help --commands** to display a list of all available\n> commands. \n> Run **django-admin help <command>** to display a description of the given\n> command and a list of its available options.\n\n上記の英語ページ \n[django-admin and manage.py](https://docs.djangoproject.com/en/3.0/ref/django-\nadmin/) \n[migrate](https://docs.djangoproject.com/en/3.0/ref/django-admin/#migrate) \n[showmigrations](https://docs.djangoproject.com/en/3.0/ref/django-\nadmin/#showmigrations)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T13:30:49.280", "id": "65868", "last_activity_date": "2020-04-22T13:30:49.280", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "26370", "parent_id": "65857", "post_type": "answer", "score": 1 }, { "body": "`manage.py help 〈知りたいコマンド〉` で表示されます。\n\n最初に `manage.py help` した際にこのように出力されている通りです。\n\n> Type 'manage.py help <subcommand>' for help on a specific subcommand.", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T15:12:16.073", "id": "65874", "last_activity_date": "2020-04-22T15:12:16.073", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65857", "post_type": "answer", "score": 1 } ]
65857
65868
65868
{ "accepted_answer_id": "65871", "answer_count": 1, "body": "**やりたいこと**\n\n 1. 2つの色(16進数カラーコード)から、両者の関係性を数値化したい \n例えば2色が「#ea4c89」「#e83e80」だった場合、「#ea4c89」から「#e83e80」を得るための「色相・彩度・明度」の差分値を求める方法を知りたいです。\n\n 2. 上記で数値化した関係性(差分値)を、異なる色へ適用させることで新たな色を求めたい \n上記結果を「#0000ff」に適用させることで新たな色を取得する方法も知りたいです。\n\n* * *\n\n**質問経緯**\n\n配色で悩んでいます。動的に色を取得したいです。 \nあるサイトのボタンカラーが「#ea4c89」でマウスオーバーカラーが「#e83e80」でした。この関係性を、異なる色(例えば青色など)にも適用させることで、色の関係性を保ったマウスオーバーカラーを取得できるのではないかと思い質問しました。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T08:54:13.110", "favorite_count": 0, "id": "65858", "last_activity_date": "2020-04-22T23:49:30.587", "last_edit_date": "2020-04-22T23:49:30.587", "last_editor_user_id": "19110", "owner_user_id": "7886", "post_type": "question", "score": 2, "tags": [ "javascript", "php", "css" ], "title": "異なる色の関係性を数値化したい", "view_count": 198 }
[ { "body": "「色相・彩度・明度」の差分値、と書かれているのが RGB 色空間から HSV\n色空間に変換して要素ごとの差をとりたい、という意味だとすると、これは[素直に変換して](https://ja.wikipedia.org/wiki/HSV%E8%89%B2%E7%A9%BA%E9%96%93#RGB%E3%81%8B%E3%82%89HSV%E3%81%B8%E3%81%AE%E5%A4%89%E6%8F%9B)差をとってやれば良いです。雑な変換で良ければこれで\nOK\nそうです。細かい計算が面倒であればオンラインに色々変換ツールが転がっているのでそれを利用できるでしょう(ユーザーの入力に合わせて計算したい訳じゃなくて、自分が\n1 回計算できれば良い、というシチュエーションに見えたので)。\n\nもしこれで期待されているような精度にならなければ、[色空間](https://ja.wikipedia.org/wiki/%E8%89%B2%E7%A9%BA%E9%96%93)の知識が必要になってきます。というのも、RGB\nや HSV において、色空間における距離と人間の感じる色の \"近さ\"\nが必ずしも似ていないとされているのを気にしています。逆に色空間での距離が人間の感じ方と似ているように作られた色空間を均等色空間と言い、たとえば\n[L*a*b*\n色空間](https://ja.wikipedia.org/wiki/Lab%E8%89%B2%E7%A9%BA%E9%96%93)というのが知られています。こういった色空間に変換してから計算すればより正確になるでしょう(少なくとも理論上は……)。\n\nまた、ディスプレイで表示しているという関係上、[ガンマ値](https://ja.wikipedia.org/wiki/%E3%82%AC%E3%83%B3%E3%83%9E%E5%80%A4)を使った補正がどのタイミングでかかっているのかも気にすべきです。つまり最初の\nRGB が sRGB なのか線形な RGB なのかそれ以外なのか注意してくださいという意味です。CSS の [16\n進表記色コード](https://www.w3.org/TR/css-color-4/#hex-notation)は sRGB\nなので、足し引きする前に線形な RGB\nに[引き戻して](https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation)おいた方が正確です。\n\n※ガンマ値については個人的にはこのブログ記事が分かりやすかったです:[物理ベースレンダリング -リニアワークフロー編\n(1)-](https://tech.cygames.co.jp/archives/2296/) \\-- Cygames Engineers' Blog", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T14:17:24.533", "id": "65871", "last_activity_date": "2020-04-22T14:17:24.533", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65858", "post_type": "answer", "score": 5 } ]
65858
65871
65871
{ "accepted_answer_id": null, "answer_count": 1, "body": "eclipseについて質問があります。 \n外部フォルダにあるpropertiesファイルを \n読み込みたいのですが、 \neclipseのVM引数から \nJavaのビルドパス>ライブラリー>クラスパスの \n外部フォルダーを設定する方法はありますか。\n\nよろしくお願いいたします。\n\n補足 \nThymeleafを使ってhtmlに直接messages.propertiesの値をを読み込んでいるため、 \n外部ディレクトリをクラスパスに追加したいです。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T08:56:13.360", "favorite_count": 0, "id": "65859", "last_activity_date": "2022-08-08T09:04:55.433", "last_edit_date": "2020-04-25T08:21:41.490", "last_editor_user_id": "2808", "owner_user_id": "18565", "post_type": "question", "score": 0, "tags": [ "java", "eclipse", "spring-boot", "tomcat" ], "title": "eclipseのVM引数からクラスパスを設定する方法", "view_count": 2350 }
[ { "body": "Eclipse(STS)から実行する際は \"Javaのビルドパス>ライブラリー>クラスパスの外部フォルダー\" によって外部の\n`messages.properties` を読めるようにしているが、 `java -jar <spring-bootアプリ>`\nコマンドで実行する場合にどう指定すれば良いか、という意図の質問ということでよいでしょうか。\n\n* * *\n\nメッセージソース(リソースバンドル)のロケーション指定は\n[`spring.massages.basename`](https://docs.spring.io/spring-\nboot/docs/2.2.6.RELEASE/reference/htmlsingle/#boot-features-\ninternationalization)で行いますが、ここでは`file:`でファイルシステム上のファイル(のベースネーム)を指定することもできます(参考:\n[How to externalize i18n properties files in spring-boot applications - Stack\nOverflow](https://stackoverflow.com/a/39487085/4506703))。\n\nまたプロパティ設定はコマンドライン引数で指定できます([4.2.2. Accessing Command Line\nProperties](https://docs.spring.io/spring-\nboot/docs/2.2.6.RELEASE/reference/htmlsingle/#boot-features-external-config-\ncommand-line-args))。\n\nしたがって、例えば `./external-resources/messages.properties` が読ませたいファイルだとすると、\n\n```\n\n java -jar <spring-bootアプリ>.jar --spring.messages.basename=file:external-resources/messages\n \n```\n\nで実現可能です。\n\n[実行サンプルコード](https://github.com/yukihane/stackoverflow-\nqa/tree/master/so65859/jar-version),\n[Thymeleafを使ったwarバージョン](https://github.com/yukihane/stackoverflow-\nqa/tree/master/so65859/war-version)\n\n* * *\n\nTomcatにデプロイする場合、Tomcat側に指示する必要があります。設定方法はこちらに詳しいです:\n\n * [Can I create a custom classpath on a per application basis in Tomcat - Stack Overflow](https://stackoverflow.com/a/26126563/4506703)\n * [Apache Tomcat 9 Configuration Reference (9.0.34) - The Resources Component](http://tomcat.apache.org/tomcat-9.0-doc/config/resources.html)\n\n[前出したwar](https://github.com/yukihane/stackoverflow-\nqa/tree/master/so65859/war-version)をTomcat9にデプロイし `/tmp/external-resources`\nディレクトリ配下のメッセージリソースを読む場合を例にすると、\n\n * `messages.properties` ファイルを `/tmp/external-resources/` ディレクトリ下に移動する\n * Tomcatの本体配下に `conf/Catalina/localhost/demo-0.0.1-SNAPSHOT.xml` ファイルを作成する。内容は次の通り:\n\n```\n\n <Context>\n <Resources>\n <PostResources\n className=\"org.apache.catalina.webresources.DirResourceSet\"\n base=\"/tmp/external-resources\"\n webAppMount=\"/WEB-INF/classes\" />\n </Resources>\n </Context>\n \n```\n\nこの設定で `/tmp/external-resources` ディレクトリがwarファイル内 `/WEB-INF/classes`\nに差し込まれますのでアプリケーションはメッセージリソースをクラスパス内で見つけることができるようになります。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T04:20:49.817", "id": "65913", "last_activity_date": "2020-04-25T08:21:12.543", "last_edit_date": "2020-04-25T08:21:12.543", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "65859", "post_type": "answer", "score": 1 } ]
65859
null
65913
{ "accepted_answer_id": "66058", "answer_count": 2, "body": "Mac上でSpresense SDK(コマンドライン)を使用した開発を行っていましたが、本体への書き込みが不可能になってしまいました。\n\n最も遅い115200bpsで書き込んでいますが、flash_writerが起動するのみで、しばらく待っていても何も起きません。しかし、UARTで接続すると、正常にNuttShellからプログラムを起動することができます。ブートローダーの再書き込みを試しましたが、ブートローダーも同じように書き込みができません。\n\nそこで、本体のリセット、ホストの再起動、USBドライバの再インストール、ケーブルの交換、USBポートの変更、拡張ボードの取り外し、Arduino\nIDEによる書き込み、Windows上のArduino IDEによる書き込みを試しましたが、結果は同じく書き込みができませんでした。\n\nその後もNuttShellへのアクセスは依然として可能です。ですからこれまでの試みでは、書き込みが始まってすらいないようです。\n\n心当たりがあるとすれば、LTE拡張ボードに電源を接続して動かしている最中に、メインボード側のUSB端子をMacに接続し、その状態で拡張ボード側の電源を抜いて再び指し直したことです。しかし、NuttShellを通じてアクセスは可能であるため、原因が全く分からずお手上げです。(うんともすんとも言わないのならまだ納得は行くのですが...)\n\nこのようにしてSpresenseに書き込みができなくなってしまった場合、なにかできることはあるのでしょうか?\n\nもしくは、このような症状の場合、書き込み部?の故障と捉えて新たに買い直すしかないのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T09:18:00.643", "favorite_count": 0, "id": "65860", "last_activity_date": "2020-04-28T07:07:52.950", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39766", "post_type": "question", "score": 1, "tags": [ "spresense" ], "title": "NuttShellにはアクセスできるがSpresenseへの書き込みができない", "view_count": 312 }
[ { "body": "LTE拡張ボードのモニターキャンペーンの時に借りた基板で同じ症状が時々発生していました。\n\nその時は、書込みが始まらないときにメインボードのリセットボタンを押すと書込みが開始されました。\n\nすでに試されているかもしれませんが、ご参考まで。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T01:37:19.100", "id": "66010", "last_activity_date": "2020-04-27T01:37:19.100", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27334", "parent_id": "65860", "post_type": "answer", "score": 0 }, { "body": "工場出荷時の状態にリセットしたところ、無事に解決しました。\n\n結局原因は分からず終いとなり、泣く泣く諦めて新しいメインボードを購入してしまったあと、[Spresense recovery\ntool](https://developer.sony.com/ja/develop/spresense/developer-\ntools/spresense-recovery-tool)の存在を英語版ドキュメントにて発見した次第です。\n\n[Spresense SDK\nスタートガイド](https://developer.sony.com/develop/spresense/docs/sdk_set_up_ja.html)や[Spresense\nSDK\n開発ガイド](https://developer.sony.com/develop/spresense/docs/sdk_developer_guide_ja.html)にはこのツールについての記載がないため、[サポート](https://ja.stackoverflow.com/users/29520/spresense)にはその存在だけでも記載していただけたら良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:07:52.950", "id": "66058", "last_activity_date": "2020-04-28T07:07:52.950", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39766", "parent_id": "65860", "post_type": "answer", "score": 2 } ]
65860
66058
66058
{ "accepted_answer_id": "65875", "answer_count": 2, "body": "[この質問](https://ja.stackoverflow.com/q/65787/19110)の続きで、Vagrantで構築したCentOS\n6上でRailsサーバーを立ち上げるコマンド\n\n```\n\n rails server -b 192.168.33.10/ -d\n \n```\n\nを行ったところ、下記のように表示され\n\n```\n\n /home/vagrant/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /home/vagrant/rails_lessons/myapp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /home/vagrant/rails_lessons/myapp/config/webpacker.yml (RuntimeError)\n \n```\n\n`rails webpacker:install` のコマンドを実行したところ\n\n```\n\n Webpacker requires Node.js >= 8.16.0 and you are using 0.10.48\n Please upgrade Node.js nodejs.org/en/download\n \n```\n\nと出ました。 \nこれはNode.jsをアップデートしろとのことですが \nCentOS上でupdateするにはどうしたらいいでしょうか?\n\nNode.jsのupdateの件\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/FhPFK.png)](https://i.stack.imgur.com/FhPFK.png)\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/DFLTQ.png)](https://i.stack.imgur.com/DFLTQ.png)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T10:42:15.770", "favorite_count": 0, "id": "65861", "last_activity_date": "2020-04-25T03:09:35.343", "last_edit_date": "2020-04-23T08:59:14.810", "last_editor_user_id": "3060", "owner_user_id": "39719", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "centos", "vagrant" ], "title": "CentOS 6でのNode.jsのアップグレード方法について", "view_count": 1762 }
[ { "body": "出力に書かれているウェブサイト <https://nodejs.org/en/download/> から新しい NodeJS をインストールしましょう。\n\n## NodeSource を使う方法\n\n[ダウンロードページのここ](https://nodejs.org/en/download/package-manager/#debian-and-\nubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-\npackages)に書かれているように、Node.js 公式のパッケージ・リポジトリとして\n[NodeSource](https://github.com/nodesource/distributions/blob/master/README.md)\nというのが管理されており、このリポジトリを yum に登録すると yum install できるようになります。\n\nが、2020 年 4 月現在 CentOS 6 はサポート対象外です。このため、 **思い切って新しいバージョンの CentOS\nを使うというのも選択肢です** 。\n\n※CentOS 6\nも[助けようとしてくれてはいる](https://github.com/nodesource/distributions/blob/master/OLDER_DISTROS.md)のですが、最近の\nNode.js をインストールするには glibc のバージョンが古くて上手くいかないという issue が立っています:\n<https://github.com/nodesource/distributions/issues/859> あるいは、今回必要とされている程度に\nNode.js のバージョンを下げれば対応できるかもしれません。\n\n## 配布されている Node.js バイナリを使う方法\n\n※最新バージョンを入れようとするとそれなりに大変です。古いバージョンを使うと(セキュリティ的な問題はおいておけば)ラクです。どのくらい古ければ良いかについては\n[cubick さんの回答](https://ja.stackoverflow.com/a/65928/19110)をご覧ください。\n\n<https://nodejs.org/en/download/> からバイナリをダウンロードします。\n\n * 選択肢1: 公開されている Linux Binaries の URL を直接 wget または curl する。\n``` wget https://nodejs.org/dist/vほにゃらら/node-ほにゃらら-linux-ほにゃらら.tar.xz\n\n \n```\n\n * 選択肢2: ホスト OS で普通にダウンロードし、Vagrant の synced folder を経由してゲスト OS に移す。\n\n圧縮されているので展開します。\n\n```\n\n tar Jxfv node-vほにゃらら-linux-ほにゃらら.tar.xz\n \n```\n\nあとはこのフォルダを適当な場所に mv し、bin フォルダに PATH を通せば node コマンドは認識されます。公式 wiki を参考にしてください:\n<https://github.com/nodejs/help/wiki/Installation>\n\n```\n\n # 例(必要に応じて先頭に sudo をつけてください)\n mkdir -p /usr/local/lib/nodejs\n mv node-vほにゃらら-linux-ほにゃらら /usr/local/lib/nodejs/\n echo 'export PATH=\"/usr/local/lib/nodejs/node-vほにゃらら-linux-ほにゃらら/bin:$PATH\"' >> ~/.bashrc\n source ~/.bashrc\n \n```\n\nこれで `node --version` が新しくなっていれば無事終了です。\n\nしかし CentOS 6 では `node --version` が以下のように glibc などが見つからないというエラーを出す場合があります。\n\n```\n\n node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by node)\n node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by node)\n node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by node)\n node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by node)\n node: /lib64/libc.so.6: version `GLIBC_2.16' not found (required by node)\n node: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by node)\n node: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by node)\n \n```\n\n実際調べるとこんな感じで古いものしか無いと分かります:\n\n```\n\n # strings /usr/lib64/libstdc++.so.6 | grep GLIBC\n GLIBCXX_3.4\n GLIBCXX_3.4.1\n GLIBCXX_3.4.2\n GLIBCXX_3.4.3\n GLIBCXX_3.4.4\n GLIBCXX_3.4.5\n GLIBCXX_3.4.6\n GLIBCXX_3.4.7\n GLIBCXX_3.4.8\n GLIBCXX_3.4.9\n GLIBCXX_3.4.10\n GLIBCXX_3.4.11\n GLIBCXX_3.4.12\n GLIBCXX_3.4.13\n GLIBC_2.2.5\n GLIBC_2.3\n GLIBC_2.4\n GLIBC_2.3.2\n GLIBCXX_FORCE_NEW\n GLIBCXX_DEBUG_MESSAGE_LENGTH\n \n```\n\nという訳で glibc を新しいものにしましょう。たとえば自分で gcc\nのソースコードからビルドして入れ替える方法があります。この回答で解説し始めると長くなりすぎるので、ブログ記事にリンクしておきます: [CentOS 6 の\nstdlibc++ を更新する](http://dotnsf.blog.jp/archives/1064353059.html)", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T15:25:05.903", "id": "65875", "last_activity_date": "2020-04-25T03:09:35.343", "last_edit_date": "2020-04-25T03:09:35.343", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "65861", "post_type": "answer", "score": 1 }, { "body": "### 前置き\n\n理想としては CentOS6 の環境で動く Node.js のバージョンを確認したいところですが、 \nリリースノート等を見ても参考になりそうな情報が見当たりません。\n\n今回は `rails` 実行時のエラーに出ている \"node.js の v8.16.0 以上が必要\" と出ているので、\n\n> `Webpacker requires Node.js >= 8.16.0 and you are using 0.10.48`\n\n[Node.js のダウンロードページ](https://nodejs.org/ja/download/releases/) からリンクを辿って\n[v8.16.2](https://nodejs.org/download/release/v8.16.2/) を選択してみます。 \nlinuxの64bit版を例に進めますが、実際の環境に合わせて読み替えてください。\n\nまた、余計なトラブルを避けるため、OS標準パッケージでインストールされた node.js は \n事前にいったん削除しておくことをおすすめします。\n\n```\n\n $ sudo yum remove nodejs -y\n \n```\n\n* * *\n\n### ダウンロードとインストール手順\n\nファイルをダウンロード (ファイル名と拡張子に注意)\n\n```\n\n $ curl -O https://nodejs.org/download/release/v8.16.2/node-v8.16.2-linux-x64.tar.xz\n \n```\n\nインストール先をここでは `/usr/local/lib/nodejs/` 以下とし、必要なディレクトリを作成してから \nアーカイブを展開\n\n```\n\n $ sudo mkdir -p /usr/local/lib/nodejs\n $ sudo tar xJvf node-v8.16.2-linux-x64.tar.xz -C /usr/local/lib/nodejs\n \n```\n\nディレクトリの配置を確認\n\n```\n\n $ ls /usr/local/lib/nodejs/\n node-v8.16.2-linux-x64/\n \n```\n\n設定ファイル (ここでは `~/.bashrc`) に追記して環境変数 PATH を通す\n\n```\n\n $ echo 'export PATH=\"/usr/local/lib/nodejs/node-v8.16.2-linux-x64/bin:$PATH\"' >> ~/.bashrc\n \n```\n\n設定ファイルを読み直して PATH が通っているかと、node.js のバージョンを確認\n\n```\n\n $ . ~/.bashrc\n $ which node\n /usr/local/lib/nodejs/node-v8.16.2-linux-x64/bin/node\n $ node -v\n v8.16.2\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T12:01:47.990", "id": "65928", "last_activity_date": "2020-04-24T12:01:47.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "65861", "post_type": "answer", "score": 2 } ]
65861
65875
65928
{ "accepted_answer_id": "65870", "answer_count": 1, "body": "htaccessについての質問です\n\nあるblogディレクトリに次のように記されたhtaccessファイルがあります\n\n```\n\n RewriteEngine On\n RewriteRule ^/blog/view/([0-9]+)/?$ /php/article$1 [L]\n \n```\n\nしかし何かのきっかけで、検索エンジンは前者のアドレスだけでなく、 \n後者のアドレスを不本意にもインデックスしてしまいしました。 \nこのphpディレクトリを含む後者のアドレスのインデックスを検索エンジンから正式に取り除くには、 \nphpディリクトリにhtaccessファイルを置き、 \nそこに前者のアドレスへのリダイレクトを記さないといけませんが、 \nこの場合必ずループに陥ります。どうすればよいでしょうか。\n\nphpディレクトリを含むアドレスをインデックスさせないように \nルートにrobots.txtファイルを設置することで対策は十分でしょうか。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T11:19:12.630", "favorite_count": 0, "id": "65863", "last_activity_date": "2020-04-22T14:05:55.367", "last_edit_date": "2020-04-22T11:34:22.763", "last_editor_user_id": "19110", "owner_user_id": "39768", "post_type": "question", "score": 1, "tags": [ "php", ".htaccess" ], "title": "htaccessのリダイレクトループに関して", "view_count": 80 }
[ { "body": "httpd-2.4 以降であれば、`[END]` フラグが利用できます。\n\n```\n\n RewriteEngine On\n RewriteRule ^blog/view/([0-9]+)/?$ /php/article$1 [END]\n RewriteRule ^php/article([0-9]+)$ /blog/view/$1 [R,END]\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T14:05:55.367", "id": "65870", "last_activity_date": "2020-04-22T14:05:55.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4603", "parent_id": "65863", "post_type": "answer", "score": 0 } ]
65863
65870
65870
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n !pip list\n \n```\n\nでpymc3のバージョンを確認すると 3.8 となっているのですが、\n\n```\n\n import pymc3 as pm\n print(pm.__version__)\n \n```\n\nとすると 3.7 と出力されます。どうすれば、3.8でインストールできますか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T12:02:39.183", "favorite_count": 0, "id": "65864", "last_activity_date": "2022-09-12T07:00:25.067", "last_edit_date": "2020-04-22T15:27:32.357", "last_editor_user_id": "19110", "owner_user_id": "39720", "post_type": "question", "score": 0, "tags": [ "python", "google-colaboratory" ], "title": "Google Colab内のパッケージpymc3のバージョン表示が合わない", "view_count": 671 }
[ { "body": "セルの実行順序の関係で古い情報が表示されている可能性があります。上のメニュー、「ランタイム」から「再起動して全てのセルを実行」することで、上のセルから順番に実行し直してみてください。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T13:20:15.720", "id": "65867", "last_activity_date": "2020-04-22T14:40:02.123", "last_edit_date": "2020-04-22T14:40:02.123", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "65864", "post_type": "answer", "score": 1 } ]
65864
null
65867
{ "accepted_answer_id": null, "answer_count": 1, "body": "∇(ナブラ)を使って内積 ∇・b の計算をしたいのですが、ここからどうすればうまくいくのでしょうか。3を出力したいです。\n\n```\n\n import numpy as np\n x = Symbol('x')\n y = Symbol('y')\n z = Symbol('z')\n \n del_x = np.gradient(,dx)\n del_y = np.gradient(,dy)\n del_z = np.gradient(,dz)\n nabra = np.array([del_x,del_y,del_z])\n b = np.array([x,y,z])\n np.inner(nabla,b)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T13:49:50.087", "favorite_count": 0, "id": "65869", "last_activity_date": "2020-04-23T11:48:50.330", "last_edit_date": "2020-04-23T02:12:26.653", "last_editor_user_id": "19110", "owner_user_id": "39563", "post_type": "question", "score": 3, "tags": [ "python", "numpy", "sympy" ], "title": "ナブラの内積を計算したいです", "view_count": 519 }
[ { "body": "まず、SymPy と NumPy の違いをご理解ください。SymPy はシンボリック計算のためのライブラリで、NumPy は数値計算のためのライブラリです。\n\nその上で、SymPy にはベクトル場を表すための関数が用意されています。このドキュメントをご覧ください:[Scalar and Vector Field\nFunctionality](https://docs.sympy.org/latest/modules/vector/fields.html)\n\nサンプルプログラムです:\n\n```\n\n >>> from sympy.vector import CoordSys3D, Del, divergence\n >>> # 座標系を決めます\n ... C = CoordSys3D('C')\n >>> # ナブラは Del() として定義されています\n ... nabla = Del()\n >>> # C.i, C.j, C.k が標準的な基底、C.x, C.y, C.z がベクトル場の仮引数です\n ... b = C.x * C.i + C.y * C.j + C.z * C.k\n >>> # 内積は dot です\n ... nabla.dot(b)\n Derivative(C.x, C.x) + Derivative(C.y, C.y) + Derivative(C.z, C.z)\n >>> # 微分計算をしてもらうためには doit() を使います\n ... nabla.dot(b).doit()\n 3\n >>> # ナブラとの内積は divergence としても定義されています\n ... divergence(b).doit()\n 3\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T11:48:50.330", "id": "65894", "last_activity_date": "2020-04-23T11:48:50.330", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65869", "post_type": "answer", "score": 1 } ]
65869
null
65894
{ "accepted_answer_id": null, "answer_count": 0, "body": "Bundleに録音データを保存したいのですがうまくいきません。\n\nDocumentフォルダに録音したファイルを保存するコードは問題なく動いており、以下のようになっています。\n\n```\n\n var audioFilename: URL!\n \n //Audio録音周りの関数\n func startRecording() {\n audioFilename = self.getDocumentsDirectory().appendingPathComponent(\"recordedAudio.wav\")\n \n let settings = [\n AVFormatIDKey: Int(kAudioFormatLinearPCM),\n AVSampleRateKey: 44100,\n AVNumberOfChannelsKey: 2,\n AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue\n ]\n \n do {\n audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)\n audioRecorder.delegate = self\n audioRecorder.record()\n \n } catch {\n finishRecording(success: false)\n }\n }\n \n func finishRecording(success: Bool) {\n audioRecorder.stop()\n audioRecorder = nil\n }\n \n func getDocumentsDirectory() -> URL {\n let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)\n return paths[0]\n }\n \n```\n\nデータをBundleに保存しようとして、以下のように書き換えるとエラーになってしまいます。\n\n```\n\n var audioFilename: URL!\n \n //Audio録音周りの関数\n func startRecording() {\n audioFilename = Bundle.main.bundleURL.appendingPathComponent(\"recordedAudio.wav\")\n \n let settings = [\n AVFormatIDKey: Int(kAudioFormatLinearPCM),\n AVSampleRateKey: 44100,\n AVNumberOfChannelsKey: 2,\n AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue\n ]\n \n do {\n audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)\n audioRecorder.delegate = self\n audioRecorder.record()\n \n } catch {\n finishRecording(success: false)\n }\n }\n \n func finishRecording(success: Bool) {\n audioRecorder.stop()\n audioRecorder = nil\n }\n \n```\n\nエラー内容は以下の通りです。\n\n```\n\n CreateDataFile failed\n Couldn't create a new audio file object\n \n```\n\nどうしたらDocumentフォルダではなくBundleにAudioファイルを保存することができますか?", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T14:36:38.070", "favorite_count": 0, "id": "65872", "last_activity_date": "2020-04-22T14:36:38.070", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36446", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "SwiftでBundleにAudioファイルを保存したい", "view_count": 220 }
[]
65872
null
null
{ "accepted_answer_id": "65876", "answer_count": 1, "body": "```\n\n regression_conjugate = pm.Model()\n with regression_conjugate:\n sigma2 = pm.InverseGamma(\"sigma2\",alpha = 0.5*nu0,beta=0.5*lam0)\n sigma = pm.math.sqrt(sigma2)\n a = pm.Normal(\"a\",mu = b0[0],sd = sigma*sd0[0])\n b = pm.Normal(\"b\",mu = b0[1],sd = sigma*sd0[1])\n y_hat = a+b*x\n likelihood = pm.Normal(\"y\",mu = y_hat,sd = sigma,observed = y)\n \n n_draws = 50\n n_chains = 4\n n_tune = 1000\n with regression_conjugate:\n trace = pm.sample(draws = n_draws, chains=n_chains,tune=n_tune,random_seed=123)\n \n print(pm.summary(trace))\n \n```\n\n上のコードを実行しようとしたのですが、下のエラーが出てきました。\n\n```\n\n TypeError Traceback (most recent call last)\n <ipython-input-44-4e1a1fef1a74> in <module>()\n 26 trace = pm.sample(draws = n_draws, chains=n_chains,tune=n_tune,random_seed=123)\n 27 \n ---> 28 print(pm.summary(trace))\n \n TypeError: concat() got an unexpected keyword argument 'join_axes'\n \n```\n\n解決法がわかる方いらっしゃいましたら、回答お願いします。 \n環境とパッケージのバージョンは以下の通りです \nGoogle Colab \npymc3 : 3.7 \npandas : 1.0.3", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T14:39:41.580", "favorite_count": 0, "id": "65873", "last_activity_date": "2020-05-26T06:02:05.217", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39720", "post_type": "question", "score": 1, "tags": [ "python", "google-colaboratory" ], "title": "pymc3内のエラー \"concat() got an unexpected keyword argument 'join_axes'\"", "view_count": 2223 }
[ { "body": "pymc3 のバージョン 3.7 は pandas のバージョン 1.0 以上と一緒には使えません。`join_axes` は pandas 1.0\nで削除されており、pymc3 3.7 はこれを利用しています。pymc3 のバージョンを 3.8 以上に上げるか、pandas\nのバージョンを下げてください。\n\n関連 issue: [FutureWarning in pm.summary(trace) when using Python\n3.7](https://github.com/pymc-devs/pymc3/issues/3606) \\-- pymc-devs/pymc3", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-22T15:33:58.283", "id": "65876", "last_activity_date": "2020-04-22T15:33:58.283", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65873", "post_type": "answer", "score": 0 } ]
65873
65876
65876
{ "accepted_answer_id": null, "answer_count": 0, "body": "Windows10のVisual studioでDLLを開発しています。 \n今まで、VS2015で開発していたのですが、VS2017にバージョンアップしました。\n\nすると、VS2015で作成していたものは、正常に動作していたDLLが、VS2017に移植したDLLが動作しなくなりました。 \nその原因が分からないのですが、 \nVS2015で作成していたDLLのサイズはDebug版で12MBありました。 \nところが、VS2017で作成したDLLのサイズが2MBしかありません。\n\nこの為に、動作しなくなったと考えられるのですが、 \nVS2017でDLLがうまくリンクされていなくて、サイズが極端に小さくなってしまったのだと思います。\n\nサイズが小さくなってしまった原因として考えられることは、 \n何があるでしょうか?\n\ncl.exeの引数は、新しい方で\n\n```\n\n /FR\"Build\\x64\\Debug\\\" /GS /TP /W3 /wd\"4996\" /Gy /Zc:wchar_t- /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Inc\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GSRoot\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GSRoot\\STL\\imp\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GSUtils\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\Geometry\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\DGLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GX\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GXImage\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\GXImageBase\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\DGGraphix\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\Graphix\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\TextEngine\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\InputOutput\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\UCLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\UDLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\Pattern\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\VectorImage\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Modules\\VBAttrDialogs\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 23.3006\\Support\\Extensions\\APIOutputFramework\" /Zi /Gm- /Od /Fd\"Build\\x64\\Debug\\Object23.pdb\" /Zc:inline /fp:precise /D \"API_VERSION=23\" /D \"WIN32\" /D \"_DEBUG\" /D \"WINDOWS\" /D \"_WINDOWS\" /D \"_STLP_DONT_FORCE_MSVC_LIB_NAME\" /D \"_WINDLL\" /errorReport:prompt /GF /WX- /Zc:forScope /RTC1 /GR /Gr /MDd /FC /Fa\"Build\\x64\\Debug\\\" /EHsc /nologo /Fo\"Build\\x64\\Debug\\\" /Fp\"Build\\x64\\Debug\\Object23.pch\" /diagnostics:classic \n \n```\n\nで、古い方では\n\n```\n\n /FR\"Build\\x64\\Debug\\\" /GS /TP /W3 /wd\"4996\" /Gy /Zc:wchar_t- /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Inc\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GSRoot\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GSRoot\\STL\\imp\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GSUtils\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\Geometry\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\DGLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GX\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GXImage\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\GXImageBase\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\DGGraphix\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\Graphix\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\TextEngine\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\InputOutput\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\UCLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\UDLib\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\Pattern\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\VectorImage\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Modules\\VBAttrDialogs\" /I\"C:\\Program Files\\GRAPHISOFT\\API Development Kit 22.3004\\Support\\Extensions\\APIOutputFramework\" /Zi /Gm- /Od /Fd\"Build\\x64\\Debug\\Object22.pdb\" /Zc:inline /fp:precise /D \"API_VERSION=22\" /D \"WIN32\" /D \"_DEBUG\" /D \"WINDOWS\" /D \"_WINDOWS\" /D \"_STLP_DONT_FORCE_MSVC_LIB_NAME\" /D \"_WINDLL\" /errorReport:prompt /GF /WX- /Zc:forScope /RTC1 /GR /Gr /MDd /Fa\"Build\\x64\\Debug\\\" /EHsc /nologo /Fo\"Build\\x64\\Debug\\\" /Fp\"Build\\x64\\Debug\\Object22.pch\" \n \n```\n\nで、少し違いました。\n\nlink.exe は古い方で\n\n```\n\n /OUT:\"Build\\x64\\Debug\\Object22.apx\" /MANIFEST /NXCOMPAT /PDB:\"Build\\x64\\Debug\\Object22.pdb\" /DYNAMICBASE \"kernel32.lib\" \"user32.lib\" \"gdi32.lib\" \"winspool.lib\" \"comdlg32.lib\" \"advapi32.lib\" \"shell32.lib\" \"ole32.lib\" \"oleaut32.lib\" \"uuid.lib\" \"odbc32.lib\" \"odbccp32.lib\" /DEBUG /DLL /MACHINE:X64 /ENTRY:\"DllMainEntry\" /INCREMENTAL /PGD:\"Build\\x64\\Debug\\Object22.pgd\" /MANIFESTUAC:\"level='asInvoker' uiAccess='false'\" /ManifestFile:\"Build\\x64\\Debug\\Object22.apx.intermediate.manifest\" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1\n \n```\n\n新しい方で\n\n```\n\n /OUT:\"Build\\x64\\Debug\\Object23.apx\" /MANIFEST /NXCOMPAT /PDB:\"Build\\x64\\Debug\\Object23.pdb\" /DYNAMICBASE \"kernel32.lib\" \"user32.lib\" \"gdi32.lib\" \"winspool.lib\" \"comdlg32.lib\" \"advapi32.lib\" \"shell32.lib\" \"ole32.lib\" \"oleaut32.lib\" \"uuid.lib\" \"odbc32.lib\" \"odbccp32.lib\" /DEBUG /DLL /MACHINE:X64 /ENTRY:\"DllMainEntry\" /INCREMENTAL /PGD:\"Build\\x64\\Debug\\Object23.pgd\" /MANIFESTUAC:\"level='asInvoker' uiAccess='false'\" /ManifestFile:\"Build\\x64\\Debug\\Object23.apx.intermediate.manifest\" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1\n \n```\n\nと、オプションは同じのようです。\n\n以上。ご教授下さい", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T00:42:54.983", "favorite_count": 0, "id": "65877", "last_activity_date": "2020-04-23T03:42:28.967", "last_edit_date": "2020-04-23T03:42:28.967", "last_editor_user_id": "19110", "owner_user_id": "39774", "post_type": "question", "score": 0, "tags": [ "visual-studio" ], "title": "VS2017で出力DLLのサイズが小さくなった", "view_count": 196 }
[]
65877
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "VBAでIJCADの操作をするプログラムが、IJCADのアップデート(2018→2019)により \n「実行時エラー91 オブジェクト変数withブロック変数が設定されていません」 と表示されるようになってしまいました。\n\nVBAの参照設定はGcadの2019に修正しています。 \n操作対象のCADは起動した状態でもエラーが出ます。\n\n```\n\n Dim getTimesec As Double\n Dim GcadApp As GcadApplication\n Set GcadApp = GetObject(, \"Gcad.Application\")  ←ここの行でオブジェクトが取得できていない\n Set GcadDoc = GcadApp.ActiveDocument\n \n```\n\nオブジェクトが取得できなくなったのは、IJCADのバージョンによるものなのか、コードがおかしいのでしょうか。 \nVBA初心者なので上記の情報で判断材料が足りるか分かりませんが…よろしくお願いいたします。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/G95KY.png)](https://i.stack.imgur.com/G95KY.png)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T01:34:16.213", "favorite_count": 0, "id": "65879", "last_activity_date": "2020-04-24T07:44:31.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39775", "post_type": "question", "score": 0, "tags": [ "vba", "ijcad" ], "title": "IJCADのバージョンアップによりGcad.Applicationのオブジェクトが取得できなくなった", "view_count": 349 }
[ { "body": "IJCAD 2019でGetObjectを使う際はバージョンを指定すると正常にオブジェクトを取得できると思います。\n\nまずは、VBAでIJCADのライブラリを参照していて、VBAで参照しているIJCADが起動しているのを確認してください。\n\nそして\n\n```\n\n GetObject(, \"Gcad.Application\")\n \n```\n\nで取得するIJCADのバージョンを指定するために\n\n```\n\n GetObject(, \"Gcad.Application.19\")\n \n```\n\nに書き換えてみてください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T07:44:31.403", "id": "65920", "last_activity_date": "2020-04-24T07:44:31.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39778", "parent_id": "65879", "post_type": "answer", "score": 0 } ]
65879
null
65920
{ "accepted_answer_id": "66017", "answer_count": 1, "body": "Node.jsで作成したローカルPC上のWebサーバに同一ローカルネットワーク上のAndroid端末からアクセスしようとしています。 \nポート番号は「3000」を利用しており、PC上のブラウザから `http://PCのIPアドレス:3000`\nにアクセスすると正常にページが表示されますが、Android端末からアクセスするとうまくいきません。\n\n以下の設定を実施しました。\n\n * PCのIPアドレスを固定\n * ルーターのポート開放設定(今回、ポート番号は「3000」を使用)\n * PCのファイアウォール設定にて、3000番ポートの通信許可設定を追加\n\nなお、PCのファイアウォール自体を無効化するとAndroid端末から正常にアクセスできます。 \nファイアウォールの特定ポートの許可設定はいろいろなサイトを見て確認しましたが、間違ってはいなさそうです。\n\n上記のほかに、何か必要な設定があるのでしょうか。ご存じの方はご教授願います。\n\n* * *\n\n(2020/4/27追記)\n\n 1. netstatコマンドで3000番ポートが「node.exe」で使用され、かつ「LISTENING」状態であることを確認しました。\n 2. ファイアウォールの特定ポートの許可設定内容を追記します。\n\n(以下「セキュリティが強化されたWindows\nDefenderファイアウォール」>「受信の規則」で今回追加した特定ポートの許可設定の「プロパティ」表示内容) \n※[リモートコンピューター][スコープ][ローカルプリンシパル][リモートユーザー]は設定なし\n\n[![全般タブ](https://i.stack.imgur.com/kDGYn.png)](https://i.stack.imgur.com/kDGYn.png)\n\n[![プログラム及びサービスタブ](https://i.stack.imgur.com/IRov6.png)](https://i.stack.imgur.com/IRov6.png)\n\n[![プロトコル及びポートタブ](https://i.stack.imgur.com/NlTva.png)](https://i.stack.imgur.com/NlTva.png)\n\n[![詳細設定タブ](https://i.stack.imgur.com/wYcWf.png)](https://i.stack.imgur.com/wYcWf.png)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T05:27:58.767", "favorite_count": 0, "id": "65881", "last_activity_date": "2020-04-27T04:57:26.440", "last_edit_date": "2020-04-27T02:10:57.413", "last_editor_user_id": "3060", "owner_user_id": "39780", "post_type": "question", "score": 0, "tags": [ "network", "windows-10" ], "title": "Windows10で特定ポートの開放ができない", "view_count": 4925 }
[ { "body": "すみません、自己解決しました。 \n今回自分で追加した受信の規則とは別に、Nodejsのアプリケーションに対する通信をブロックする定義が存在していたことが原因でした。\n\n[![参考画像](https://i.stack.imgur.com/F7iB2.png)](https://i.stack.imgur.com/F7iB2.png)\n\nおそらく、Node.jsインストール時にWindowsファイアウォールの警告ポップアップで誤って「ブロックする」を選択してしまったのではないかと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T04:57:26.440", "id": "66017", "last_activity_date": "2020-04-27T04:57:26.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39780", "parent_id": "65881", "post_type": "answer", "score": 1 } ]
65881
66017
66017
{ "accepted_answer_id": "65888", "answer_count": 1, "body": "## 概要\n\nVisual Studioで開発中に発生したC2280コンパイルエラーが発生する理由と解決できた理由を教えてください。\n\n## 詳細\n\n簡単な画像処理を実行するコード作成中にC2280コンパイルエラーが発生しました。 \nコンパイラのエラーメッセージに従ってコードを修正するとエラーが発生しなくなり、正常に動作しているように見えました。 \nしかし、いったいどのような理由でエラーが発生して、結局解決できたのかがわからずもやもやしている状態です。\n\n## コード\n\n```\n\n #include <iostream>\n #include <memory>\n #include \"opencv2\\opencv.hpp\"\n \n class CImage {\n public:\n CImage() = delete; //引数無しのコンストラクタは禁止したい\n CImage(const cv::Mat& inImage) :m_MatImage(inImage) {}; //必ず引数有のコンストラクタを実行してほしい\n ~CImage(){m_MatImage.release();};\n \n cv::Mat getMatImage() const { return m_MatImage.clone(); };\n \n private:\n cv::Mat m_MatImage;\n };\n \n class CParameter {\n public:\n CParameter() :m_ReferenceImagePtr(nullptr) {};\n CParameter(const CParameter &); //この行を挿入することでエラーを回避できる No1\n //CParameter(const CParameter &) =default; //=defaultにするとエラーは残ったまま No2\n ~CParameter() { m_ReferenceImagePtr.reset(); }; //デストラクタを省略するとコピーコンストラクタ無しで もエラーを回避できる No3\n \n void setImage(const CImage& inImage)\n {\n m_ReferenceImagePtr = std::make_unique<CImage>(inImage);\n };\n cv::Mat getImage()\n {\n return m_ReferenceImagePtr->getMatImage();\n };\n \n private:\n std::unique_ptr<CImage> m_ReferenceImagePtr;\n };\n \n void main() {\n cv::Mat img = cv::Mat::zeros(100, 100, CV_8UC1);\n CImage image = CImage(img);\n CParameter parameter = CParameter(); //C2280エラー発生個所\n //何らかの画像処理が続く...\n }\n \n```\n\nエラーメッセージを抜粋したものが以下になります\n\n> error C2280: 'CParameter::CParameter(const CParameter &)': \n> 削除された関数を参照しようとしています \n> コンパイラが 'CParameter::CParameter' をここに生成しました。\n\n## 質問\n\nコードのコメント中のナンバー毎に質問があります \nNo1: どうしてコピーコンストラクタを追加するとC2280エラーが解消されるのか \nNo2: コピーコンストラクタの追加で=defaultの場合はエラーが解消されないがNo1との違いは何か \nNo3: デストラクタを除外するとコピーコンストラクタなしでもエラーが発生しない理由は何か\n\n## 環境\n\n開発環境: Visual Studio 2015 14.0.25431.01 Update3 \nOpenCV: Ver3.4.3\n\n## 参考にした情報\n\n[エラーに関するMicrosoftのドキュメントページ](https://docs.microsoft.com/ja-jp/cpp/error-\nmessages/compiler-errors-1/compiler-\nerror-c2280?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev16.query%3FappId%3DDev16IDEF1%26l%3DJA-\nJP%26k%3Dk\\(C2280\\)%26rd%3Dtrue&view=vs-2019) \n[C++のdefault/deleteの参考](https://cpprefjp.github.io/lang/cpp11/defaulted_and_deleted_functions.html)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T08:37:21.813", "favorite_count": 0, "id": "65885", "last_activity_date": "2020-04-23T09:26:12.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19500", "post_type": "question", "score": 0, "tags": [ "c++", "visual-studio", "c++11" ], "title": "C2280エラーが発生した理由と解決できた理由を知りたい", "view_count": 2422 }
[ { "body": "`std::unique_ptr<CImage>` はコピーコンストラクタを持たないので `CParameter`\nもデフォルトコピーコンストラクタを利用できません。\n\nNo1とNo3については、C++11~C++14ではコピーコンストラクタ呼び出しが省略されることもされないこともあるため、質問のプログラムは環境依存です。\n<https://ja.cppreference.com/w/cpp/language/copy_elision>\n\nNo2はデフォルトでないコピーコンストラクタは作成可能なので、コピーコンストラクタを宣言すればコンパイル時のエラーは回避出来て、(コピーコンストラクタを定義しなければ)リンク時にエラーになります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T09:26:12.307", "id": "65888", "last_activity_date": "2020-04-23T09:26:12.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "241", "parent_id": "65885", "post_type": "answer", "score": 1 } ]
65885
65888
65888
{ "accepted_answer_id": "65897", "answer_count": 1, "body": "Djangoの勉強をしており、AWSでアプリケーションを公開しようというところまできたのですが、ブラウザでアクセスしてみると以下のエラーが出てしまいます。\n\n```\n\n Bad Request (400)\n \n```\n\nまた、Djangoのlogには以下のエラーが出ます。\n\n```\n\n Invalid HTTP_HOST header: '<IP アドレス>'. You may need to add '<IP アドレス'>' to ALLOWED_HOSTS.\n \n```\n\nこのエラー文でググってみると、Djangoの設定ファイル(settings.py)のALLOWED_HOSTSに \nIPアドレスを設定すれば良いと出てくるのですが、変更してもエラーの内容は変わりません。\n\n実際の設定は次のようにしています。\n\n```\n\n ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS')]\n \n```\n\n環境変数のALLOWED_HOSTSにAWSで割り当てられているIPアドレスを入れています。 \n直接IPアドレスを入れたり、ワイルドカードを使ってもダメでした。 (= ['*']のように)\n\nDjangoやAWSなど初めてだらけでどうやってデバッグすれば良いかもわからず、完全に行き詰まってしまいました。\n\n何か少しでも心当たりがある方にアドバイスをいただきたいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T08:49:09.093", "favorite_count": 0, "id": "65887", "last_activity_date": "2020-04-23T12:38:10.253", "last_edit_date": "2020-04-23T11:48:48.490", "last_editor_user_id": "3060", "owner_user_id": "36888", "post_type": "question", "score": 0, "tags": [ "aws", "django", "nginx" ], "title": "エラーInvalid HTTP_HOST header: '<IP アドレス>'. You may need to add '<IP アドレス'>' to ALLOWED_HOSTS. (Django、AWSに詳しい方お願いします。)", "view_count": 1206 }
[ { "body": "エラーメッセージの『Invalid HTTP_HOST header: ''. You may need to add '' to\nALLOWED_HOSTS.』のの部分にはDjangoにアクセスしたブラウザが稼働しているマシン(以下、\"クライアントマシン\"と呼びます)のIPアドレスが書かれていたと思います。\n\nこの問題を解決するには、クライアントマシンのホスト名かIPアドレスを、ALLOWED_HOSTSに追加してください。\n\n<具体的な方法> \nまず、settings.pyのプログラムから、\"ALLOWED_HOSTS = []\"か\"ALLOWED_HOSTS =\n[aaa,bbb,ccc]\"(aaa,bbb,cccの部分はホスト名かIPアドレスの並び)という行を探します。 \n\"ALLOWED_HOSTS = []\" という行が見つかったら、\"ALLOWED_HOSTS =\n[クライアントマシンのホスト名かIPアドレス]\"と変更してください。 \n\"ALLOWED_HOSTS = [aaa,bbb,ccc]\"という行が見つかったら、\"ALLOWED_HOSTS =\n[aaa,bbb,ccc,クライアントマシンのホスト名かIPアドレス]\"と変更してください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T12:38:10.253", "id": "65897", "last_activity_date": "2020-04-23T12:38:10.253", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "65887", "post_type": "answer", "score": 0 } ]
65887
65897
65897
{ "accepted_answer_id": "65892", "answer_count": 2, "body": "c言語でシーザー暗号の暗号化と復号を実現したくてコードを書いたのですがうまくいきません。\n\n**エラーメッセージ** \nコンパイル時に\n\n```\n\n sizer3.c:31:2: warning: implicit declaration of function 'elseif' is invalid in C99 [-Wimplicit-function-declaration] elseif(j==1){ ^ sizer3.c:31:14: error: expected ';' after expression elseif(j==1){ ^ ; sizer3.c:46:3: error: expected expression else{ ^ 1 warning and 2 errors generated.\n \n```\n\nとでます。\n\n**ソースコード**\n\n```\n\n #include <stdio.h>\n #define LEN 255\n \n int main(void)\n {\n char string[LEN];\n char angou[LEN];\n int key, number, i,j;\n \n printf(\"暗号作成のときは0を\\n\");\n printf(\"暗号解読のときは1を\\n\");\n printf(\"終了するときは2を入力して下さい:\");\n scanf(\"%d\",&j);\n \n if(j==0){\n printf(\"鍵を入力してくだい:\");\n scanf(\"%d\", &key);\n printf(\"文字列を入力してください:\");\n scanf(\"%s\", string);\n \n i = 0;\n while(string[i] != '\\0'){\n number = string[i] + key;\n angou[i] = number;\n ++i;\n }\n angou[i] = '\\0';\n \n printf(\"作成された暗号:%s\\n\", angou);\n }\n elseif(j==1){\n printf(\"鍵を入力してくだい:\");\n scanf(\"%d\", &key);\n printf(\"文字列を入力してください:\");\n scanf(\"%s\", string);\n i = 0;\n while(string[i] != '\\0'){\n angou[i] = string[i] - key;\n i++;\n }\n angou[i] = '\\0';\n printf(\"暗号の解読結果(平文):%s\\n\", angou);\n }\n else{\n printf(\"終了\");\n }\n \n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T10:02:27.700", "favorite_count": 0, "id": "65889", "last_activity_date": "2020-04-29T23:39:49.970", "last_edit_date": "2020-04-28T06:43:24.360", "last_editor_user_id": "19110", "owner_user_id": "39787", "post_type": "question", "score": 0, "tags": [ "c" ], "title": "シーザー暗号の暗号化と復号", "view_count": 1050 }
[ { "body": "`elseif(j==1)` と続けて書いてしまうと `elseif`\nという関数の呼び出しと解釈されてしまいます。そんな関数は宣言されていないよ+実際リンクしても存在しないよ、でエラーとなっています。真にやりたいのは\n`else if(j==1)`\nなのだろうと推測(あなたのコードと違いスペースが1つ入っています。これによってキーワードが分離できているので当初の期待通りであろうと思う)\n\nこういうのを避けるには\n\n * `if` には必ず `{ ...}` のように(複文でなくても)必ず鍵かっこを使う\n * `if` でなくて `switch` を使う\n\nのがまあ定石ですよね。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T11:08:50.760", "id": "65892", "last_activity_date": "2020-04-23T11:08:50.760", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "65889", "post_type": "answer", "score": 2 }, { "body": "Cの`if`には他言語にあるような`elseif`または`elsif`構文はありません。`else`の中に`if`をネストすればよいので、こうは書けます\n\n```\n\n if(条件) {\n :\n }\n else if(条件){\n :\n }\n \n```\n\nただし、典型的なバグを作り込みがちな書き方ではあるので、\n\n```\n\n if(条件) {\n :\n }\n else {\n if(条件){\n :\n }\n }\n \n```\n\nこう書くことをお勧めします。\n\n* * *\n\nちなみにエラーの内容は以下のとおりです\n\n> `sizer3.c:31:2: warning: implicit declaration of function 'elseif' is\n> invalid in C99 [-Wimplicit-function-declaration] elseif(j==1){ ^`\n\n`elseif`という関数が宣言または定義されていないのに呼び出そうとしていることへの警告です。これは **エラーではありません** 。\n\n> `sizer3.c:31:14: error: expected ';' after expression elseif(j==1){ ^ ;`\n\n`elseif`が関数呼び出しと解釈されているために、文法上`elseif()`の後にセミコロンが必要です。\n\n> `sizer3.c:46:3: error: expected expression else{ ^ 1 warning and 2 errors\n> generated.`\n\n今のコードは、\n\n```\n\n if(...){\n :\n } //ここでifは終わり\n \n elseif();\n \n {\n //空のブロック\n }\n \n else { \n }\n \n```\n\nこう解釈されています。ifに対応しないelseが現れているのでこれに対するエラーです。\n\nコンパイルが失敗している直接の原因は`elseif`が定義されていないことではなく、文法違反となっていることです。仮に`elseif`関数を定義したとしても、文法違反は解消しないのでコンパイルできないことには変わりありません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T23:55:41.347", "id": "65934", "last_activity_date": "2020-04-29T23:39:49.970", "last_edit_date": "2020-04-29T23:39:49.970", "last_editor_user_id": "5793", "owner_user_id": "5793", "parent_id": "65889", "post_type": "answer", "score": 1 } ]
65889
65892
65892
{ "accepted_answer_id": "65908", "answer_count": 1, "body": "本番サイト(`https://www.mydomain.or.jp/`)のファイルをコピーし修正したものを、テストサイトで確認しています。\n\n本番とテストは別のサーバーです。\n\nファイルのリンクはルートパスから書かれており、テストサイトでリンク切れとなってしまいます。\n\nそこで以下のように`.htaccess`をつかってファイルパスを読み替えて参照するようにして、リンク切れを解消したいです。(リンクのコードを書き換えない方法としたい)\n\nbeforeはリンク切れが起こっているもので、afterのような絶対パスにリダイレクトさせたいということです。\n\nこの場合`.htaccess`の書き方、設置場所はどのようになりますか?\n\n`/`から始まる全てのリンクを差し替えたいです。\n\nよろしくお願いいたします。\n\n**before**\n\n```\n\n <link rel=\"stylesheet\" href=\"/common/css/import.css\" type=\"text/css\">\n \n```\n\n**after**\n\n```\n\n <link rel=\"stylesheet\" href=\"https://www.mydomain.or.jp/common/css/import.css\" type=\"text/css\">\n \n```\n\n \n \n次の記事にならって、下のように`.htaccess`を作成しましたがうまくいきません。 \n<https://qiita.com/awesam86/items/de58cf6afc83b0d52890> \nどこが誤りでしょうか? \n \n\n```\n\n RewriteEngine on\n RewriteRule ^(.*)\\.((gif|png|jpe?g|css|ico|js|svg))$ https://www.mydomain.or.jp/$1.$2\n \n```\n\n`mydir/index.html`で`index.html`がリンク切れを起こしている時、`.htaccess`を \n`mydir`と同じ階層に格納。`mydir` 配下の同様のリンクを全て差し替えたい。", "comment_count": 9, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T10:33:46.813", "favorite_count": 0, "id": "65890", "last_activity_date": "2020-04-24T06:17:17.327", "last_edit_date": "2020-04-24T06:17:17.327", "last_editor_user_id": "3060", "owner_user_id": "12297", "post_type": "question", "score": 1, "tags": [ "html", ".htaccess" ], "title": "テスト環境のHTMLからルートパスで書かれた本番環境のリソースを参照したい", "view_count": 1072 }
[ { "body": "> mydir/index.htmlでindex.htmlがリンク切れを起こしている時、.htaccessを \n> mydirと同じ階層に格納。mydir 配下の同様のリンクを全て差し替えたい。\n\nこの場合、`.htaccess` を置くのはリダイレクトしたいリソースに対応するディレクトリです。例:\n`ドキュメントルート/common/.htaccess` \nブラウザは `mydir/index.html` を取得したあとに `mydir/` にはアクセスしません。\n\nテスト環境であれば、`.htaccess` を使わずに `httpd.conf` に書いてしまってもいいかもしれません。\n\n * そもそも mod_rewrite が使える環境かどうかも要確認です\n * .htaccess が使える設定かどうかも要確認です\n * 私だったら `index.html` に `<base href=\"http://www.mydomain.or.jp/\">` を書くだけで済ませるかもしれません。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T02:09:02.000", "id": "65908", "last_activity_date": "2020-04-24T02:09:02.000", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3475", "parent_id": "65890", "post_type": "answer", "score": 2 } ]
65890
65908
65908
{ "accepted_answer_id": null, "answer_count": 1, "body": "github action でできる限り OSS のルーチンを自動化しようと思うと、タグを元のレポジトリに push したくなります。\n\n# 質問\n\n * github action にて、元レポジトリへのタグの push はどうやったらできるでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T12:31:48.923", "favorite_count": 0, "id": "65896", "last_activity_date": "2021-08-04T11:58:07.377", "last_edit_date": "2021-08-04T11:58:07.377", "last_editor_user_id": "3060", "owner_user_id": "754", "post_type": "question", "score": 1, "tags": [ "github-actions" ], "title": "github actions の中から元のレポジトリへタグを push できますか?", "view_count": 104 }
[ { "body": "[Tagを打ってくれるActionはいくらか存在](https://github.com/marketplace?type=actions&query=tag)するようですので、これらを使えば実現できるでしょうか。\n\n公式の機能で実装するには、[`github-script`](https://github.com/marketplace/actions/github-\nscript)を使い、[`createTag()`](https://octokit.github.io/rest.js/v17#git-create-\ntag)を呼ぶことでしょうか。\n\n```\n\n uses: actions/[email protected]\n with:\n github-token: ${{secrets.GITHUB_TOKEN}}\n script: |\n github.git.createTag({\n owner: context.repo.owner,\n repo: context.repo.repo,\n tag: ...,\n message: ...,\n object: ...,\n type: ...\n })\n \n```\n\n(試したわけではありません。)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T23:10:14.337", "id": "65905", "last_activity_date": "2020-04-23T23:10:14.337", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "65896", "post_type": "answer", "score": 1 } ]
65896
null
65905
{ "accepted_answer_id": null, "answer_count": 1, "body": "うさぎとカメの判別AIの開発をしています。 \nしかし、なぜか学習がうまくいかず、lossやacc(判別成功率)の値が良くなりません。 \n通常、lossとaccは反比例で片方の数値が増加すればもう片方が減少するはずなのに、lossが膨大に増加してaccは0.5あたりで変化しません。 \nこれはニューラルネットワークの設計がいけないのでしょうか?? \n以下に、スペックとソースコードと結果画面を載せます。\n\n仕様スペック \n・windows10 \n・Docker \n・Python3.7.3\n\n```\n\n import sys\n import os\n import numpy as np\n import pandas as pd\n import gc\n from keras.models import Sequential\n from keras.layers import Convolution2D, MaxPooling2D\n from keras.layers import Activation, Dropout, Flatten, Dense\n from keras.utils import np_utils\n \n class TrainModel : \n def __init__(self):\n input_dir = './Gazo'\n self.nb_classes = len([name for name in os.listdir(input_dir) if name != \".DS_Store\"])\n x_train, x_test, y_train, y_test = np.load(\"./Gakushu.npy\")\n # データを正規化する\n self.x_train = x_train.astype(\"float\") / 256\n self.x_test = x_test.astype(\"float\") / 256\n self.y_train = np_utils.to_categorical(y_train, self.nb_classes)\n self.y_test = np_utils.to_categorical(y_test, self.nb_classes)\n def train(self, input=None) :\n model = Sequential()\n # K=32, M=3, H=3\n if input == None :\n model.add(Convolution2D(32, 3, 3, border_mode='same', input_shape=self.x_train.shape[1:]))\n else :\n model.add(Convolution2D(32, 3, 3, border_mode='same', input_shape=input))\n # K=64, M=3, H=3(調整)\n model.add(Activation('relu'))\n model.add(MaxPooling2D(pool_size=(2, 2)))\n model.add(Dropout(0.25))\n model.add(Convolution2D(64, 3, 3, border_mode='same'))\n model.add(Activation('relu'))\n # K=64, M=3, H=3(調整)\n model.add(Convolution2D(64, 3, 3))\n model.add(MaxPooling2D(pool_size=(2, 2)))\n model.add(Dropout(0.25))\n model.add(Flatten()) \n model.add(Dense(512))\n # biases nb_classes\n model.add(Activation('relu'))\n model.add(Dropout(0.5))\n model.add(Dense(self.nb_classes))\n model.add(Activation('softmax'))\n model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])\n if input == None :\n # 学習してモデルを保存\n model.fit(self.x_train, self.y_train, batch_size=32, nb_epoch=int(kaisu), validation_data=(self.x_test,self.y_test))\n hdf5_file = \"./AImodel.hdf5\"\n model.save_weights(hdf5_file)\n score = model.evaluate(self.x_test, self.y_test, verbose = 0)\n print('-----------------------------------------------------------------------------')\n print(\"\")\n print(\"トレーニング終了!\")\n print(\"\")\n print('loss=', score[0])\n print('判別成功率=', score[1])\n print(\"\")\n return model\n if __name__ == \"__main__\":\n args = sys.argv\n train = TrainModel()\n train.train()\n gc.collect()\n \n```\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/tW9kn.png)](https://i.stack.imgur.com/tW9kn.png)\n\n参考ページ:<https://qiita.com/tsunaki/items/608ff3cd941d82cd656b>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T15:03:01.907", "favorite_count": 0, "id": "65900", "last_activity_date": "2020-05-13T08:06:02.770", "last_edit_date": "2020-04-23T15:15:54.763", "last_editor_user_id": "37702", "owner_user_id": "37702", "post_type": "question", "score": 1, "tags": [ "python", "docker", "機械学習", "深層学習" ], "title": "画像判別AIモデルのloss率とacc率を良くしたい", "view_count": 386 }
[ { "body": "Epochの2以降は学習できていない状態ですね。 \n168枚というデータ枚数に対して、モデル構造が複雑すぎるためだと推察します。 \ndata\naugmentationによって訓練データの枚数を増やすか、もしくは畳み込み層やプーリング層におけるフィルタの大きさや枚数を減らすのが良いと思います。 \nまた、乱数値の設定状態によって訓練する度に結果が変わってしまうので、予め設定しておくと良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-13T08:06:02.770", "id": "66565", "last_activity_date": "2020-05-13T08:06:02.770", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30009", "parent_id": "65900", "post_type": "answer", "score": 0 } ]
65900
null
66565
{ "accepted_answer_id": "67059", "answer_count": 1, "body": "複数のテーブルを結合した結果を取得したいです。 \nメインとなるテーブルからは直接紐づかない形になります。 \n言葉では説明が難しいので以下に例を記載します。\n\n良い例が浮かばず不自然なテーブル構成になっていますがご了承ください。\n\n### モデル定義\n\n```\n\n class User(models.Model):\n class Meta:\n db_table = 'user'\n user_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n user_name = models.CharField()\n \n class UserGroup(models.Model):\n class Meta:\n db_table = 'user_group'\n \n comment = models.CharField()\n user = models.ForeignKey(UserMaster, on_delete=models.CASCADE)\n group = models.ForeignKey(UserMaster, on_delete=models.CASCADE)\n \n class Group(models.Model):\n class Meta:\n db_table = 'group'\n \n group_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)\n group_name = models.CharField()\n \n```\n\n### テーブルのデータ\n\n```\n\n ## User\n user_id, user_name\n 1, taro\n 2, hanako\n \n ## Group\n group_id, group_name\n 1, group1\n 2, group2\n \n ## UserGroup\n id, comment, user_id, group_id\n 1, comment_x, 1, 1\n 2, comment_y, 1, 2\n \n```\n\n### 取得したい形\n\nイメージですので、細部が異なっていても問題ありません\n\n```\n\n users = User.objects..... # 質問したい所\n \n users[0].group[0].name # group1\n users[0].user_group[0].comment # comment_x\n users[0].user_group[0].group.group_name # group1\n \n```\n\n### JSON的なイメージ\n\n```\n\n {\n user_id: 1,\n user_name: taro,\n group:[\n {\n group_id: 1,\n group_name: group1\n },\n {\n group_id: 2,\n group_name: group2\n }\n ],\n user_group:[\n {\n comment: comment_x,\n group: {\n group_id: 1,\n group_name: group1\n }\n },\n {\n comment: comment_y,\n group: {\n group_id: 2,\n group_name: group2\n }\n }\n ]\n }\n \n```\n\n### SQLで取得する場合\n\n構造化されないので厳密には異なりますが。。。\n\n```\n\n select * from user\n inner join user_group on user.user_id = user_group.user_id\n inner join group on group.group_id = user_group.group_id;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T16:03:02.000", "favorite_count": 0, "id": "65901", "last_activity_date": "2020-11-01T01:01:20.140", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13022", "post_type": "question", "score": 0, "tags": [ "python", "django" ], "title": "Djangoで複数のテーブルを結合して取得したい", "view_count": 3877 }
[ { "body": "ManyToManyFieldで2つモデム(User,Group)のみでいいと思います。\n\n```\n\n class Group(models.Model):\n group_name = models.CharField()\n \n class User(models.Model):\n group = models.ManyToManyField(Group)\n user_name = models.CharField()\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-28T01:25:43.327", "id": "67059", "last_activity_date": "2020-05-28T03:24:17.073", "last_edit_date": "2020-05-28T03:24:17.073", "last_editor_user_id": "3060", "owner_user_id": "35698", "parent_id": "65901", "post_type": "answer", "score": 1 } ]
65901
67059
67059
{ "accepted_answer_id": "65919", "answer_count": 2, "body": "以下のサイトを参考に、MFCでアプリケーションを終了したときのアプリケーションの座標を取得し、再度アプリケーションを起動したときに前回アプリケーションを終了したときの座標にアプリケーションを起動させる処理を作っていますが、以下の参考サイトにある、\n\n```\n\n LPTSTR pBuff = csInifile.GetBuffer(MAX_LEN + 1);\n \n```\n\nという処理が何のためにしているかをちゃんと理解したくて質問させて頂きました。\n\n参考にしているサイト: \n<http://pg-sample.sagami-ss.net/?eid=29>\n\nこれを理解するために私なりにしたことは、 \nまずバッファが何かよく分からなかったので、調べました。 \n結果、コンピュータとハードディスクなど、処理速度に大きな差があるときに、コンピュータが一時的にデータを溜めこんで、ハードディスクに読み書きをしている間に待ち時間が発生しないようにするための仕組みだと理解しました。\n\nしかし、なぜ上記の`GetBuffer`の処理でパスの文字列を作るためにバッファを作る必要があるか分かりませんでした。分からない理由は、パスの文字列を作るだけならコンピュータとハードディスクに処理速度は関係なくすぐに作れるのでは?と思ったからです。\n\nただ、仮説としては、コンピュータとハードディスクに処理速度の差は圧倒的で、パスを`GetModuleFileName`で作るだけでもバッファがないと本当にコンマ数秒くらい遅延するのかと思いました。(しかしながら、ただ単に`GetModuleFileName`の第二引数の型が`LPTSTR`なので、`CString`型である`csInifile`を`LPTSTR`にキャストすることがメインの目的で`GetBuffer`を使用されているのかもしれませんが...)\n\n上記、教えて頂けるとありがたいです。どうかよろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T21:55:25.777", "favorite_count": 0, "id": "65902", "last_activity_date": "2020-04-24T06:11:47.890", "last_edit_date": "2020-04-24T00:18:32.257", "last_editor_user_id": "2238", "owner_user_id": "21034", "post_type": "question", "score": 1, "tags": [ "c++", "mfc" ], "title": "ファイル名の文字列を作る処理でGetBufferを使ってバッファを取得する意味が分からない", "view_count": 1413 }
[ { "body": "バッファに対する理解が誤っています。Wikipediaの[バッファ](https://ja.wikipedia.org/wiki/%E3%83%90%E3%83%83%E3%83%95%E3%82%A1)には\n\n> 情報処理機器におけるバッファ・緩衝(域)(英: buffer)とは,記憶単位間のデータ転送において一時的にデータを記憶することを指す。\n\nと説明しています。「何の」バッファであるかが重要であり、質問者さんは誤解しています。ハードディスク等は無関係であり、[GetBuffer](https://docs.microsoft.com/en-\nus/cpp/atl-mfc-shared/reference/csimplestringt-\nclass?view=vs-2019#getbuffer)の説明には\n\n> Returns a pointer to the internal character buffer for the CSimpleStringT\n> object.\n\nとあるように、文字通り、「文字の」バッファを得るものです。文字のバッファが無ければGetModuleFileNameで得られる文字列を格納できません。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T22:49:03.923", "id": "65903", "last_activity_date": "2020-04-24T02:40:30.947", "last_edit_date": "2020-04-24T02:40:30.947", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "65902", "post_type": "answer", "score": 2 }, { "body": "いくつか誤解と言うか「理解不足」があります。\n\n**バッファについて**\n\nコンピュータのソフトウェア用語として使われるバッファは、少し長めに言うと「(○○のための)バッファ(用のデータ(メモリ)領域)」になるでしょう。 \nカッコ内の部分は記述されることもあるし省略されることもあります。まあ省略されることが多いでしょうが。\n\nハードディスクに係わる仕組みは大きな1例であって全てではありません。 \n@sayuri さん回答のように、「何の」ためのバッファか、については使われ方によってそれぞれ違い、目的は山のように存在します。\n\n質問記事の場合は以下に説明しますが、処理を速くするのが目的ではありません。\n\n**ファイル名の文字列を作る処理?**\n\n質問タイトルの「ファイル名の文字列を作る処理」そのものは間違ってはいないのですが、その4行の処理も2行づつ別々の処理に分けることができます。\n\n質問にも引用された行を含む最初の2行は、現在のプロセス(自分自身のプログラム)の実行可能ファイルのパスを文字列変数に取得します。 \n2行目の[GetModuleFileNameW function](https://docs.microsoft.com/en-\nus/windows/win32/api/libloaderapi/nf-libloaderapi-\ngetmodulefilenamew)の第2、第3パラメータには、パスを格納するバッファへのポインタとそのバッファのサイズを指定する必要がありますし、そのバッファは`GetModuleFileName`を呼び出す前に確保されている必要があります。\n\nしかし、`CString csInifile`変数はクラスメンバとして定義されているだけであり、\n**この時点ではこの変数に空文字列を示す終端の0くらいしかデータは存在しておらず、パスを格納するのに十分なバッファは確保されていません。**\n\nそのため、 **「実行可能ファイルのパスを格納するバッファ」を`MAX_LEN + 1`文字の長さを指定して確保するために行っている**\n、というのが質問の処理です。\n\n確保した後、実行可能ファイルのパスを取得するために`GetModuleFileName`を呼び出しています。\n\nそしてその次の2行が狭義の「ファイル名の文字列を作る処理」であり、実行可能ファイルのパスの最後の`exe`を`ini`に書き換えて、iniファイル名のパスを作っています。\n\n**最終的にiniファイル名のパスを格納しておく`CString`変数があるので、作業用として実行可能ファイルのパスを格納するバッファの確保も、その変数の`GetBuffer`メソッドで行っているのでしょう。**\n\n行数も変わらないしあまり意味はありませんが、`MAX_LEN`のサイズが小さいなら`GetBuffer`を使わずに自動変数としてバッファを定義して使う以下のような方法も考えられます。 \n参照記事に定義された`2048`くらいでも問題無く動作するでしょう。\n\n```\n\n TCHAR pBuff[MAX_LEN + 1];\n DWORD PathLen = GetModuleFileName(NULL, pBuff, MAX_LEN) - 3;\n errno_t ernt = _tcscpy_s(&pBuff[PathLen], (MAX_PATH - PathLen), _T(\"ini\"));\n csInifile = pBuff;\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T06:11:47.890", "id": "65919", "last_activity_date": "2020-04-24T06:11:47.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "65902", "post_type": "answer", "score": 2 } ]
65902
65919
65903
{ "accepted_answer_id": "65906", "answer_count": 1, "body": "**やりたいこと** \n「display:flex;」の「orderプロパティ」適用後の要素に対して「:first-child」を適用したい \n※orderプロパティはランダムに割り振る\n\n* * *\n\n**「orderプロパティ」適用前** \n「:first-child」は期待通り動作している\n\n```\n\n <style>\n section{display:flex;}\n div{0 0.5rem;}\n div:first-child{margin-left:1rem;}\n div:last-child{margin-right:1rem;}\n </style>\n \n <section>\n <div></div>\n <div></div>\n <div></div>\n <div></div>\n </section>\n \n```\n\n**「orderプロパティ」適用後** \n「orderプロパティ」をランダムに割り振ると、「:first-child」の位置そのものもランダムに移動してしまう\n\n* * *\n\n**試したこと** \n「:first-child」記述を、最後に記述すれば、「orderプロパティ」適用後の要素に対して「:first-\nchild」を適用できるかと思いましたが、期待した通り動作しませんでした\n\n**質問** \n「display:flex;」の「orderプロパティ」適用後の要素順に対して「:first-child」を適用することは出来ますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-23T22:58:16.877", "favorite_count": 0, "id": "65904", "last_activity_date": "2020-04-24T01:09:00.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "css" ], "title": "「display:flex;」の「orderプロパティ」適用後の要素順に対して、「:first-child」を適用することは出来ますか?", "view_count": 172 }
[ { "body": "いいえ、不可能です。なぜならば、 `:first-child` 疑似クラスが **DOM の順序**\nを基準に要素を選択する[[1]](https://drafts.csswg.org/selectors-3/#nth-child-pseudo)のに対して、\n`order` プロパティは **視覚上の順序** にのみ影響を及ぼす[[2]](https://drafts.csswg.org/css-\nflexbox-1/#order-accessibility)ためです。\n\n> ### 6.6.5.2. :nth-child() pseudo-\n> class[[1]](https://drafts.csswg.org/selectors-3/#nth-child-pseudo)\n>\n> The `:nth-child(an+b)` pseudo-class notation represents an element that has\n> `an+b-1` siblings before it in the document tree, for any positive integer\n> or zero value of `n`. It is not required to have a parent. For values of a\n> and b greater than zero, this effectively divides the element's children\n> into groups of a elements (the last group taking the remainder), and\n> selecting the bth element of each group.\n\nもし flex アイテムの数が判明しており、それが増減しない場合には、属性セレクタにより `order` プロパティの順番に応じた装飾が CSS\nのみで可能です。しかし、アイテムの数が増減する場合には、 JavaScript を用いる必要があります。\n\n```\n\n document.addEventListener(\"click\", () => {\n const item = document.querySelectorAll(\"section > div\");\n const rand = [...Array(item.length).keys()].map(e => e + 1).sort(() => Math.random() - 0.5);\n \n item.forEach(e => (e.style.order = rand.shift()) && (e.dataset.order = e.style.order) && (e.classList.remove(\"first\", \"last\")));\n \n document.querySelector(`div[data-order=\"1\"]`).classList.add(\"first\");\n document.querySelector(`div[data-order=\"${item.length}\"]`).classList.add(\"last\");\n });\n```\n\n```\n\n section {\n display: flex;\n }\n \n div {\n background: #ffa;\n width: 100px;\n height: 100px;\n }\n \n .first {\n margin-left: 1rem;\n background: red;\n }\n \n .last {\n margin-right: 1rem;\n background: blue;\n }\n```\n\n```\n\n <section>\n <div>1</div>\n <div>2</div>\n <div>3</div>\n <div>4</div>\n </section>\n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T01:09:00.990", "id": "65906", "last_activity_date": "2020-04-24T01:09:00.990", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "32986", "parent_id": "65904", "post_type": "answer", "score": 3 } ]
65904
65906
65906
{ "accepted_answer_id": "65915", "answer_count": 1, "body": "図のようなもの作成しています。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/lrjNP.png)](https://i.stack.imgur.com/lrjNP.png)\n\n従業員IDのところに参照したい従業員のIDを入力します。 \n参照ボタンを押すと、名前や交通手段などのデータが参照されます。\n\nデータの参照をするための文がわからず困っています。 \nまた、ラジオボタンに参照させる方法も教えていただきたいです。\n\n```\n\n '参照ボタンを押した時の処理'\n Private Sub ReferenceBtn_Click()\n \n 'もし参照する値が入力されていなかったら'\n If Me.IDTextBox = \"\" Then\n MsgBox \"参照する番号を入力してください。\"\n Exit Sub\n End If\n \n i=\n \n '姓を出力'\n .Cells(i, 2) = Me.TextBox2\n \n '名を出力'\n .Cells(i, 3) = Me.TextBox3\n \n 'セイを出力'\n .Cells(i, 4) = Me.TextBox4\n \n 'メイを出力'\n .Cells(i, 5) = Me.TextBox5\n \n '性別を出力'\n .Cells(i, 6) =\n \n '交通手段を出力'\n .Cells(i, 7) = Me.ComboBox1\n \n '最寄り駅を出力'\n .Cells(i, 8) = Me.TextBox6\n \n '交通費を出力'\n .Cells(i, 9) = Me.TextBox7\n \n '時給を出力'\n .Cells(i, 10) = Me.TextBox8\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T01:48:39.837", "favorite_count": 0, "id": "65907", "last_activity_date": "2020-04-24T04:48:23.717", "last_edit_date": "2020-04-24T04:48:23.717", "last_editor_user_id": "9820", "owner_user_id": "39792", "post_type": "question", "score": 0, "tags": [ "vba" ], "title": "VBAでテキストボックスに入力された値のデータを参照したいです。", "view_count": 726 }
[ { "body": "`Me.IDTextBox.Text`の記述でTextBoxコントロールのデータを参照することができます。(`Me`は省略可能です)\n\n間違えやすいポイントは`IDTextBox`がTextBoxコントロールという入力欄そのものを表すことです。 \n一つ一つの入力欄はデータの他にName(\"IDTextBox\"という識別名)、TopやLeft(フォーム内の配置座標)、TopやWidth(コントロールの大きさ)を表す\n**プロパティ** を持っています。\n\n例えば`MsgBox IDTextBox.Width`と入力することでIDTextBoxコントロールの幅データを表示できます。 \n上記のようにTextも入力されたデータを管理するプロパティのひとつです。\n\nまたラジオボタンはチェック状態を`Value`プロパティで管理します。 \n`Value = True`ならば選択されている状態です。\n\n複数のラジオボタンをグループ化して管理するために`GroupName`というプロパティも用意されています。 \n任意のラジオボタンをチェック状態にすると同一グループ名の他のラジオボタンは全てチェックが外れます。 \n性別のみ管理する場合は`GroupName`を設定しなくても普通に動きますが、性別以外にラジオボタンで管理する項目が増えた場合はグループごとに設定が必要です。\n\n```\n\n Private Sub ReferenceBtn_Click()\n If IDTextBox.Text = \"\" Then\n MsgBox \"参照する番号を入力してください。\" \n Exit Sub\n End If\n '1行目から最終行までループ\n For i = 1 To Sheet1.Cells(Rows.Count, 1).End(xlUp) + 1\n 'IDが一致する行のみ処理\n Set ID = Sheet1.Cells(i, 1)\n If ID = IDTextBox.Text Then\n 'TextBoxのTextプロパティを変更\n TextBox2.Text = Sheet1.Cells(i, 2)\n 'OptionButtonのValueプロパティを変更\n If Sheet1.Cells(i, 3) = \"男\" Then\n OptionButton1.Value = True\n Else\n OptionButton2.Value = True\n End If\n Exit Sub\n End If\n Next\n \n End Sub\n \n Private Sub UserForm_Initialize()\n 'プロパティウィンドウでGroupNameを設定してもOK\n OptionButton1.GroupName = \"Sex\" \n OptionButton2.GroupName = \"Sex\" \n End Sub\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T04:47:42.863", "id": "65915", "last_activity_date": "2020-04-24T04:47:42.863", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "65907", "post_type": "answer", "score": 0 } ]
65907
65915
65915
{ "accepted_answer_id": "65958", "answer_count": 1, "body": "初心者です \nサンプルコードを実行したところ、HTMLとCSSは機能していますが、スニペットから外部ファイルのjsファイルが機能していません。Google\nchromeのF12で確認しましたが、エラーは出ていません。何が問題なのかわかりません。 \nどなたかご教示頂ければ幸いです。\n\nサンプルコードの引用先は下記の \n<https://digipress.info/tech/3d-rotating-hidden-menu-sample/> で一番下のサンプルです。\n\n```\n\n  <script type=\"text/javascript\" src=\"menu.js\"></script>\n \n```\n\n```\n\n var mqWidth = 680,\r\n scrollTrigger = 40,\r\n isMobile = null,\r\n burgerCheckbox = $('#humberger_check'), \r\n hiddenMenu = $('.hidden_menu li'),\r\n slideBar = $('.menu_underline'),\r\n headerBar = $('.header_bar');\r\n \r\n function sliderBarAnimation(){\r\n if ( $(window).width() > mqWidth ){\r\n if (isMobile === false) return;\r\n isMobile = false;\r\n hiddenMenu.off('mouseenter mouseleave').hover(\r\n // nmouseenter\r\n function(){\r\n var current = $(this),\r\n barColor = current.data('bar-color');\r\n slideBar.addClass('visible').css({\r\n 'top':'auto',\r\n 'left' : current.position().left,\r\n 'background-color':barColor\r\n })\r\n },\r\n //mouseleave\r\n function(){\r\n slideBar.removeClass('visible');\r\n }\r\n );\r\n } else {\r\n if (isMobile === true) return;\r\n isMobile = true;\r\n hiddenMenu.off('mouseenter mouseleave').hover(\r\n // nmouseenter\r\n function(){\r\n var current = $(this),\r\n barColor = current.data('bar-color');\r\n slideBar.addClass('visible').css({\r\n 'left':0,\r\n 'top':current.offset().top + 60,\r\n 'background-color':barColor\r\n });\r\n },\r\n //mouseleave\r\n function(){\r\n slideBar.css({'top':0}).removeClass('visible');\r\n }\r\n );\r\n }\r\n }\r\n $(window).on({\r\n 'resize' : function(){\r\n sliderBarAnimation();\r\n },\r\n 'scroll' : function(){\r\n if ($(window).scrollTop() > scrollTrigger){\r\n headerBar.addClass('show-bg');\r\n } else {\r\n headerBar.removeClass('show-bg');\r\n }\r\n }\r\n });\r\n (function(){\r\n sliderBarAnimation();\r\n \r\n hiddenMenu.on('click', function(){\r\n var current = $(this);\r\n current.addClass('selected');\r\n setTimeout(function(){\r\n current.removeClass('selected');\r\n burgerCheckbox.prop('checked',false);\r\n }, 400);\r\n });\r\n hiddenMenu.children('a:not([target]):not([href^=\"tel:\"])').on('click', function(e){\r\n var url = $(this).attr(\"href\");\r\n if (!url) return;\r\n e.preventDefault();\r\n setTimeout(function(){\r\n window.location = url;\r\n },400);\r\n });\r\n })(jQuery);\n```\n\n```\n\n @charset \"utf-8\";\r\n * {\r\n box-sizing: border-box;\r\n }\r\n *:before, *:after {\r\n padding: 0;\r\n margin: 0;\r\n }\r\n \r\n body {\r\n font-family: Lato, Arial, \"Hiragino Kaku Gothic Pro W3\", Meiryo, sans-serif;\r\n background-color: #333;\r\n color: #efefef;\r\n text-align: center;\r\n margin: 0;\r\n padding: 0;\r\n }\r\n body a, body a:visited {\r\n color: #efefef;\r\n text-decoration: none;\r\n }\r\n body a:hover {\r\n color: #ccc;\r\n }\r\n \r\n .container {\r\n position: relative;\r\n }\r\n \r\n .content {\r\n margin: 0 auto;\r\n padding: 5% 40px;\r\n }\r\n \r\n .hidden_menu, .hidden_menu ul {\r\n backface-visibility: hidden;\r\n -webkit-backface-visibility: hidden;\r\n }\r\n \r\n .hidden_menu ul li, .menu_underline, .header_bar::before {\r\n transition: all 0.3s ease;\r\n }\r\n \r\n .humberger, .hidden_menu, .hidden_menu ul, .header_bar, .container {\r\n transition: all 0.5s ease;\r\n }\r\n \r\n .hidden_menu ul li::before, .header_bar::before, .container::before {\r\n content: '';\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 100%;\r\n }\r\n \r\n #humberger_check {\r\n width: 0;\r\n height: 0;\r\n opacity: 0;\r\n visibility: hidden;\r\n }\r\n #humberger_check:checked + .humberger {\r\n transform: translateY(160px);\r\n }\r\n #humberger_check:checked + .humberger span {\r\n background-color: transparent;\r\n }\r\n #humberger_check:checked + .humberger span::before {\r\n top: 2px;\r\n transition: top 0.1s cubic-bezier(0.33333, 0, 0.66667, 0.33333) 0.15s, transform 0.13s cubic-bezier(0.215, 0.61, 0.355, 1) 0.22s;\r\n -webkit-transform: translate3d(0, 10px, 0) rotate(45deg);\r\n transform: translate3d(0, 10px, 0) rotate(45deg);\r\n }\r\n #humberger_check:checked + .humberger span::after {\r\n top: 6px;\r\n transition: top 0.2s cubic-bezier(0.33333, 0, 0.66667, 0.33333), transform 0.13s cubic-bezier(0.215, 0.61, 0.355, 1) 0.22s;\r\n -webkit-transform: translate3d(0, 6px, 0) rotate(-45deg);\r\n transform: translate3d(0, 6px, 0) rotate(-45deg);\r\n }\r\n #humberger_check:checked ~ .header_bar,\r\n #humberger_check:checked ~ .container {\r\n transform: translateY(160px);\r\n }\r\n #humberger_check:checked ~ .hidden_menu {\r\n transform: translateY(0);\r\n }\r\n #humberger_check:checked ~ .hidden_menu ul {\r\n opacity: 1;\r\n transform: rotateX(0);\r\n }\r\n \r\n .humberger {\r\n position: fixed;\r\n top: 20px;\r\n right: 5vw;\r\n width: 40px;\r\n height: 40px;\r\n cursor: pointer;\r\n z-index: 3;\r\n }\r\n .humberger span {\r\n position: absolute;\r\n top: 6px;\r\n left: 50%;\r\n width: 30px;\r\n height: 4px;\r\n margin: 0 auto auto -15px;\r\n background-color: #fff;\r\n transition: background-color .1s linear .13s;\r\n }\r\n .humberger span::before, .humberger span::after {\r\n content: '';\r\n position: absolute;\r\n left: 0;\r\n width: 100%;\r\n height: 4px;\r\n background-color: #fff;\r\n }\r\n .humberger span::before {\r\n top: 12px;\r\n transition: top 0.1s cubic-bezier(0.33333, 0.66667, 0.66667, 1) 0.2s, transform 0.13s cubic-bezier(0.55, 0.055, 0.675, 0.19);\r\n }\r\n .humberger span::after {\r\n top: 24px;\r\n transition: top 0.2s cubic-bezier(0.33333, 0.66667, 0.66667, 1) 0.2s, transform 0.13s cubic-bezier(0.55, 0.055, 0.675, 0.19);\r\n }\r\n \r\n .hidden_menu {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 160px;\r\n -webkit-perspective: 1600px;\r\n perspective: 1600px;\r\n background-color: #222;\r\n z-index: 3;\r\n transform: translateY(-100%);\r\n }\r\n .hidden_menu ul {\r\n list-style: none;\r\n width: 100%;\r\n height: 100%;\r\n margin: 0;\r\n padding: 0;\r\n opacity: 0;\r\n background-color: rgba(255, 255, 255, 0.08);\r\n -webkit-transform-origin: center bottom;\r\n transform-origin: center bottom;\r\n transform: rotateX(90deg);\r\n }\r\n .hidden_menu ul li {\r\n position: relative;\r\n display: table;\r\n width: 20%;\r\n height: 100%;\r\n float: left;\r\n font-size: 13px;\r\n }\r\n .hidden_menu ul li::before {\r\n opacity: 0;\r\n transform: scale(0);\r\n }\r\n .hidden_menu ul li:nth-child(1)::before {\r\n background-color: #FA3687;\r\n }\r\n .hidden_menu ul li:nth-child(2)::before {\r\n background-color: #21D7A8;\r\n }\r\n .hidden_menu ul li:nth-child(3)::before {\r\n background-color: #1E9ED4;\r\n }\r\n .hidden_menu ul li:nth-child(4)::before {\r\n background-color: #B0D44A;\r\n }\r\n .hidden_menu ul li:nth-child(5)::before {\r\n background-color: #A865D5;\r\n }\r\n .hidden_menu ul li.selected::before {\r\n animation: scaling .4s linear;\r\n }\r\n .hidden_menu ul li:hover {\r\n background-color: rgba(0, 0, 0, 0.14);\r\n }\r\n .hidden_menu ul li a {\r\n position: relative;\r\n display: table-cell;\r\n vertical-align: middle;\r\n }\r\n .hidden_menu ul li i {\r\n display: block;\r\n margin-bottom: 15px;\r\n font-size: 25px;\r\n }\r\n \r\n .menu_underline {\r\n position: absolute;\r\n bottom: 0;\r\n height: 0;\r\n width: 20%;\r\n background-color: #fff;\r\n }\r\n .menu_underline.visible {\r\n height: 3px;\r\n }\r\n \r\n .header_bar {\r\n position: fixed;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n height: 80px;\r\n padding: 0 5vw;\r\n text-align: left;\r\n border-bottom: 1px solid rgba(255, 255, 255, 0.2);\r\n z-index: 2;\r\n }\r\n .header_bar::before {\r\n background-color: rgba(0, 0, 0, 0.84);\r\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);\r\n opacity: 0;\r\n }\r\n .header_bar.show-bg::before {\r\n opacity: 1;\r\n }\r\n .header_bar h1 {\r\n position: relative;\r\n margin: 26px 0 0;\r\n font-size: 20px;\r\n display: inline-block;\r\n }\r\n \r\n .container {\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n width: 100%;\r\n z-index: 1;\r\n background-size: cover;\r\n background-attachment: fixed;\r\n background-position: center;\r\n background-image: url(https://drive.google.com/uc?export=view&id=0B_koKn2rKOkLSXZCakVGZWhOV00);\r\n }\r\n .container::before {\r\n position: fixed;\r\n background-color: rgba(0, 0, 0, 0.6);\r\n }\r\n \r\n .content {\r\n position: relative;\r\n margin: 100px auto 4vw;\r\n padding: 0 5vw;\r\n height: 100vh;\r\n }\r\n .content h2 {\r\n position: relative;\r\n top: 30vh;\r\n font-size: 38px;\r\n }\r\n \r\n @keyframes scaling {\r\n 50% {\r\n opacity: .28;\r\n transform: scale(0.5);\r\n }\r\n 100% {\r\n opacity: 0;\r\n transform: scale(1.05);\r\n }\r\n }\r\n @media (max-width: 680px) {\r\n #humberger_check:checked + .humberger,\r\n #humberger_check:checked ~ .header_bar,\r\n #humberger_check:checked ~ .container {\r\n transform: translateY(300px);\r\n }\r\n \r\n .hidden_menu {\r\n height: 300px;\r\n }\r\n .hidden_menu ul li {\r\n float: none;\r\n width: 100%;\r\n height: 60px;\r\n font-size: 12px;\r\n }\r\n .hidden_menu ul li i {\r\n display: inline;\r\n font-size: 18px;\r\n margin-right: 15px;\r\n }\r\n \r\n .menu_underline {\r\n width: 100%;\r\n left: 0;\r\n bottom: auto;\r\n }\r\n }\n```\n\n```\n\n <!doctype html>\r\n <html>\r\n <head>\r\n <script type=\"text/javascript\" src=\"menu.js\"></script>\r\n <meta charset=\"utf-8\">\r\n <title>MENU</title>\r\n <link href=\"menu.css\" rel=\"stylesheet\" type=\"text/css\"></head>\r\n \r\n <body>\r\n <input type=\"checkbox\" role=\"button\" title=\"menu\" id=\"humberger_check\" />\r\n <label for=\"humberger_check\" class=\"humberger\" aria-hidden=\"true\" title=\"menu\">\r\n <span></span>\r\n </label>\r\n <header class=\"header_bar\">\r\n <h1>SITE TITLE</h1>\r\n </header>\r\n <main class=\"container\">\r\n <section class=\"content\">\r\n <h2>3D Rotating Hidden Menu</h2>\r\n </section>\r\n </main>\r\n <nav class=\"hidden_menu\">\r\n <ul>\r\n <li data-bar-color=\"#FA3687\">\r\n <a href=\"#\"><i class=\"icon-picture\"></i>IMAGE</a>\r\n </li>\r\n <li data-bar-color=\"#21D7A8\">\r\n <a href=\"#\"><i class=\"icon-film\"></i>VIDEO</a>\r\n </li>\r\n <li data-bar-color=\"#1E9ED4\">\r\n <a href=\"#\"><i class=\"icon-music\"></i>MUSIC</a>\r\n </li>\r\n <li data-bar-color=\"#B0D44A\">\r\n <a href=\"#\"><i class=\"icon-headphones\"></i>PERSONAL</a>\r\n </li>\r\n <li data-bar-color=\"#A865D5\">\r\n <a href=\"#\"><i class=\"icon-cogs\"></i>SETTINGS</a>\r\n </li>\r\n </ul>\r\n <span class=\"menu_underline\"></span>\r\n </nav>\r\n \r\n </body>\r\n </html>\n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T02:37:36.143", "favorite_count": 0, "id": "65909", "last_activity_date": "2020-04-25T12:47:54.617", "last_edit_date": "2020-04-24T02:56:06.843", "last_editor_user_id": "37940", "owner_user_id": "37940", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "Javascriptを利用したメニューのサンプルコードについて、jsファイルが読み込まれない", "view_count": 79 }
[ { "body": "jQueryを使用されていますが、HTMLファイル内でどこにもjQeuryの本体を読み込んでいる記述がありません。 \n[Google Hosted\nLibraries](https://developers.google.com/speed/libraries#jquery) \nなどを参考に使用するバージョンを決めて読み込むよう記述してやる必要があります。(下記の例はver.1.12.4) \nそのあとにご自身で作成されたjsファイルを読み込ませてやれば、動作すると思います。\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js\"></script>\n <script type=\"text/javascript\" src=\"menu.js\"></script>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T12:47:54.617", "id": "65958", "last_activity_date": "2020-04-25T12:47:54.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9515", "parent_id": "65909", "post_type": "answer", "score": 0 } ]
65909
65958
65958
{ "accepted_answer_id": null, "answer_count": 2, "body": "普段、 emacs の設定ファイル群を編集する際には、 emacs 自身でそれを行なっています。今、普段と大きく構成が異なる init.el\nに対して、これを実際に試しながら、必要とあれば修正をかけていきたいと思っています。その試行錯誤を行う際に利用するエディタには、 emacs\nを用いて、かつ普段使いの設定でもってこれを行いたいと考えています。\n\n具体的にどういうことかというと、 [Spacemacs](https://www.spacemacs.org/)\nを使ってみたいのですが、いきなりこれでもって emacs 設定ディレクトリである .emacs.d を置き換えるのは学習曲線が急すぎると思っているので、\n\n 1. 普段の emacs で spacemacs の init.el を編集する。\n 2. 別プロセスで emacs を立ち上げ、 spacemacs の設定を読み込ませ、 spacemacs としての挙動を確認する\n\nを実行したいな、と思っています。\n\nこれを行うにあたり、しかし、自分の知る限り .emacs.d の場所を切り替えながら emacs\nを起動する手法を自分は知らないので、これは果たしてこういうことは実現できるのだろうか、と思っている次第です。\n\n# 質問\n\nこのような設定ファイル(.emacs.d/init.el)の編集ワークフローを実現したいときに、これができる手法・ツールなどはありますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T03:20:02.073", "favorite_count": 0, "id": "65911", "last_activity_date": "2020-04-24T04:21:18.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "post_type": "question", "score": 0, "tags": [ "emacs" ], "title": "emacs で、大きく設定が異なる設定ファイル(init.el) を編集ないし開発するには?", "view_count": 285 }
[ { "body": "まず/path/to/init.elに以下のように記述します。\n\n```\n\n (when load-file-name\n (setq user-emacs-directory (file-name-directory load-file-name)))\n \n```\n\n起動時にこのelをロードしてやれば、~/.emacs.dの代わりに/path/toを設定ディレクトリとして使うことができます。\n\n```\n\n % emacs -q -l /path/to/init.el\n \n```\n\nとはいえ~/.emacs.dなどがハードコードされていないことが前提(代わりに`locate-user-emacs-\nfile`などを使うべき)なので、spacemacs等が絶対に機能するとは言い切れないところがあります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T04:19:08.537", "id": "65912", "last_activity_date": "2020-04-24T04:19:08.537", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13199", "parent_id": "65911", "post_type": "answer", "score": 1 }, { "body": "部分的な回答ですが、`--no-init-file` オプションを使うと初期化ファイルを読み込まずに Emacs を起動できます。\n\n<https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-\nOptions.html>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T04:21:18.110", "id": "65914", "last_activity_date": "2020-04-24T04:21:18.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "65911", "post_type": "answer", "score": 0 } ]
65911
null
65912
{ "accepted_answer_id": null, "answer_count": 1, "body": "Windows PCのMySQLにて既存のデータベースのダンプを取ろうとして\n\n```\n\n mysqldump -uroot -p testdb > testdb.dump\n \n```\n\nを実行したところ、結果は以下のようなエラーとなりました\n\n```\n\n mysqldump Error: 'Illegal mix of collations (utf8_general_ci,CORECIBLE) and (uft8_unicode_ci,CORECIBLE) for operation '='' when trying to dump tablespaces\n \n```\n\n似たようなトラブルをネットで調べてみて以下のようにmysql\nclientにてデータベース文字コードを確認しましたが、特にutf8_general_ciとutf8_unicode_ciが混在しているように見えませんでした\n\n```\n\n mysql> show variables like 'char%' ;\n variable_name | Value\n character_set_clinet | uft8\n character_set_connection | utf8\n character_set_database | utf8\n character_set_filesystem | utf8\n character_set_results | utf8\n character_set_server | utf8\n character_set_system | utf8\n character_sets_dir | c:\\Program Files\\MySQL\\MySQL Server 8.0\\share\\charsets\\\n \n```\n\n```\n\n mysql> show variables like 'coll%' ;\n Variable_name | Value\n collation_connection | utf8_unicode_ci\n collation_database | utf8_unicode_ci\n collation_server | utf8_unicode_ci\n \n```\n\n```\n\n mysql> show table status from testDB ;\n \n```\n\n(省略しますが、すべてのテーブルがutf8_unicode_ciであることを確認済)\n\n**MySQL バージョン** \nmysqld: ver 8.0.16 for win64 on x86_64 \nmysql : ver 8.0.16 for win64 on x86_64\n\nどこに問題があるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T04:54:39.803", "favorite_count": 0, "id": "65916", "last_activity_date": "2023-06-14T04:06:40.817", "last_edit_date": "2020-04-25T11:06:09.837", "last_editor_user_id": "32986", "owner_user_id": "39794", "post_type": "question", "score": 0, "tags": [ "mysql" ], "title": "mysqldumpを実行すると'Illegal mix of collations' Errorが発生する", "view_count": 615 }
[ { "body": "あてずっぽうですが、mysql と mysqldump で設定が違うということはないですか? 具体的には my.cnf or my.ini で\n[mysql] [mysqldump] などのセクションの設定が一致しているか確認してみてください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T10:39:13.603", "id": "65953", "last_activity_date": "2020-04-25T10:39:13.603", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "65916", "post_type": "answer", "score": 0 } ]
65916
null
65953
{ "accepted_answer_id": null, "answer_count": 1, "body": "下記のコマンドで応答ファイルを作成し、応答ファイル使ってサイレントインストールを行った所、ResultCode=-3でエラーになってしまいます。 \nこのエラーコードは応答ファイルに必要なデータがないのが原因とのことですが、応答ファイルを作成したマシンとサイレントインストールを行ったマシンは同じであり、システムの違いなどはありません。考えられる原因は何かありますでしょうか? \n環境はwindows10 proです。\n\n```\n\n > hogeapp.exe /r /f1\"c:\\setup.iss\"\n > hogeapp.exe /s /f1\"c:\\setup.iss\" /f2\"c:\\test.log\"\n \n```\n\n**test.log**\n\n```\n\n [ResponseResult]\n ResultCode=-3\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T08:19:53.213", "favorite_count": 0, "id": "65921", "last_activity_date": "2020-04-24T09:49:37.363", "last_edit_date": "2020-04-24T09:33:16.213", "last_editor_user_id": "32986", "owner_user_id": "39798", "post_type": "question", "score": 1, "tags": [ "windows" ], "title": "応答ファイルを使ったサイレントインストールについて", "view_count": 1126 }
[ { "body": "アンインストールせずに続けてサイレントインストールを行っていませんか?\n\n初回インストールとインストール済み環境へのインストールは処理手順が変わることが多いでしょう。\n\n初回インストールに伴って自動的に作られる応答ファイルでは、そうした状況に対応できないのでは?\n\n以下のような対処が考えられます。\n\n * いったんアンインストールしてからサイレントインストールする\n * インストールされていない他のPCでサイレントインストールする\n * インストール済み環境へのインストールの応答ファイルも作って、 \n別途インストール有無をチェックして指定する応答ファイルを切り替える\n\n* * *\n\nInstallShieldのFAQ記事 \n[01745 : サイレントインストールを行う方法](https://tec-world.networld.co.jp/faq/show/1745)\n\n> 1.コマンドラインから /r オプションを指定してインストールを実行し、応答ファイルを作成します\n>\n> setup.exe /r\n>\n> ※ダイアログで操作した内容が、自動的に応答ファイルへ記録されます\n>\n> 2.Setup.iss(応答ファイル)が Windows フォルダー(c:\\windows)に作成されていることを確認します\n>\n> ※応答ファイル作成後は、製品がインストールされた状態となっています。必要に応じて、アンインストールを行ってください。\n\n類似の現象と思われる記事 \n[11.2.3\nインストール型クライアントのサイレントインストール](https://software.fujitsu.com/jp/manual/manualfiles/M070166/B1WW8131/02Z200/dti11/dti00160.html)\n\n>\n> V13.2.0の検疫クライアントをすでにインストールしている場合は、エラーとなります。\\Disk1\\setup.logファイルには以下のように出力されます。\n```\n\n> [InstallShield Silent]\n> Version=v7.00\n> File=Log File\n> [ResponseResult]\n> ResultCode=-3\n> \n```\n\n[付録B\nサイレントインストール](https://software.fujitsu.com/jp/manual/manualfiles/m110011/b1ws0925/02z200/b0925-b-00-00.html)\n\n> ログファイルの確認と対処 \n> \\- インストール結果の確認 \n> ログファイルを開き、[ResponseResult]セクションの“ResultCode”を参照してください。 \n> 以下に復帰値の意味を記載します。\n```\n\n> -3 対象システムの環境により、応答ファイルと異なるシーケンスで実行された場合\n> ・インストールフォルダ配下にInterstageの資源が残っている、またはInterstageがインストール済\n> ・ディスク容量不足\n> ・排他ソフトウェアが存在\n> ・異なるバージョン・レベル/エディション、またはサーバパッケージのインストーラを用いて作成した応答ファイルを指定した場合。\n> \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T09:36:56.527", "id": "65926", "last_activity_date": "2020-04-24T09:49:37.363", "last_edit_date": "2020-04-24T09:49:37.363", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "65921", "post_type": "answer", "score": 1 } ]
65921
null
65926
{ "accepted_answer_id": null, "answer_count": 1, "body": "numpyの2次元配列の累乗(要素ごとの累乗)が正常にできず困っていましたので教えてください。\n\n環境: \nPython: 3.7.5 \nNumpy: 1.17.4\n\nfloat32型・2次元のnp.array(正または負の実数値を格納、一部NaNを含む)を1.514乗しようとすると、``**`でも`np.power()`\nでも以下のエラーが発生して全てNaNになるか、その要素を1.514乗した値ではない値が格納されたnp.arrayが返されます。\n\n```\n\n RuntimeWarning: invalid value encountered in power\n \n```\n\nfooはfloat32型で,気象データの配信サーバーからNetCDF形式で取得してきたものです。\n\nNaNが入っているからか?と思い、要素を一つとりだして1.514乗した場合、以下の記述でもRuntime warningになります。\n\n```\n\n foo[0][0] ** 1.514\n (foo:2次元のnp.array)\n \n```\n\nところが、以下の方法でループで要素を一つずつ抜き出して再格納した配列varをつくり、`var ** 1.514` をすると正常な値が戻ってきます。\n\n```\n\n var = np.zeros((len(lat), len(lon))\n for i in range(len(lat)):\n for j in range(len(lon)):\n var[i][j] = foo[i][j]\n (fooがオリジナルのnp.array)\n \n```\n\nこの方法を使えばとりあえず問題は解消できますが、気味が悪いので原因を教えていただけないでしょうか。 \nよろしくお願いします。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T08:42:52.343", "favorite_count": 0, "id": "65922", "last_activity_date": "2022-01-13T02:03:45.420", "last_edit_date": "2021-11-07T07:44:14.233", "last_editor_user_id": "3060", "owner_user_id": "35230", "post_type": "question", "score": 3, "tags": [ "python", "numpy" ], "title": "np.arrayの累乗でRuntime warningが発生する", "view_count": 4207 }
[ { "body": "どうも numPyの `power()` 関数は、負や複素数の累乗には対応していないようです。 \n私も同じことでひっかかってしまい、この質問に達しましたが、いろいろとぐぐっているうちに、英語のページに同様の質問があり、同様の推察がなされていました。\n\n2乗などの時は、おそらくこの問題は発生しないのですが、1.7乗などとすると、対象がマイナスでなくてもエラーになるようです。\n\n私の対策としては、`abs()` で絶対値をとってしまうことで、多少効率は悪くなりますが対応できました。\n\n```\n\n z = np.power(abs(x), y)\n z = abs(x)**y\n \n```\n\nという感じです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2021-11-07T05:09:08.967", "id": "83467", "last_activity_date": "2021-11-07T16:22:51.463", "last_edit_date": "2021-11-07T16:22:51.463", "last_editor_user_id": "3060", "owner_user_id": "24768", "parent_id": "65922", "post_type": "answer", "score": 2 } ]
65922
null
83467
{ "accepted_answer_id": "66725", "answer_count": 1, "body": "お世話になっております。 \n下記の問題に対して知見がある方がいらっしゃいましたらご教示お願いします。\n\n# 起きている問題\n\nいいね機能を実装中にエラーが発生しました。 \n\n```\n\n # _like.html.erb\n \n <% if @post.liked_by?(current_user) %>\n <%= button_to 'いいね解除', post_like_path(@post), method: :delete, remote: true %>\n <% else %>\n <%= button_to 'いいね', post_likes_path(@post), method: :post, remote: true %>\n <% end %>\n \n```\n\nいいねボタンを押したときに起きました。 \n更新ボタンを押すと正常に`likes.count`が1つ足されているので(いいねされている)`Ajax`に何か問題があるのでしょうか。 \nまた、いいねされている状態であると正常にいいね解除できます。\n\n# アプリケーションの挙動\n\n1、いいねされていない状態でいいねボタンをクリック \n[![画像の説明をここに入力](https://i.stack.imgur.com/OV6W9.png)](https://i.stack.imgur.com/OV6W9.png)クリック \n⬇️ \nエラー発生 \n[![画像の説明をここに入力](https://i.stack.imgur.com/izcs6.png)](https://i.stack.imgur.com/izcs6.png) \n⬇️ \n更新ボタンを押下 \n[![画像の説明をここに入力](https://i.stack.imgur.com/uCMi8.png)](https://i.stack.imgur.com/uCMi8.png)正常に稼働する\n\n2、いいねされている状態でいいねボタンをクリック \n[![画像の説明をここに入力](https://i.stack.imgur.com/LDAiu.png)](https://i.stack.imgur.com/LDAiu.png) \n⬇︎ \n[![画像の説明をここに入力](https://i.stack.imgur.com/jkSvn.png)](https://i.stack.imgur.com/jkSvn.png)正常に稼働する\n\n# 関連ファイル\n\n```\n\n #likes/_like.html.erb\n \n <% if @post.liked_by?(current_user) %>\n <%= button_to 'いいね解除', post_like_path(@post), method: :delete, remote: true %>\n <% else %>\n <%= button_to 'いいね', post_likes_path(@post), method: :post, remote: true %>\n <% end %>\n \n```\n\n```\n\n #likes/destroy.js.erb\n \n $('.like_button').html(\"<%= j(render 'likes/like' , post: @post) %>\");\n \n```\n\n```\n\n #likes/create.js.erb\n \n $('.like_button').html(\"<%= j(render 'likes/like' , post: @post) %>\");\n \n```\n\n```\n\n #posts/show.html.erb\n \n <% provide(:title, '投稿詳細画面') %>\n <div class=\"row\">\n <div class=\"title\"><p>投稿詳細画面</p></div>\n <div class=\"col-md-2\">\n </div>\n <div class=\"col-md-8\">\n <%= render 'static_pages/show', post: @post %>\n </div>\n <div class=\"col-md-2\">\n </div>\n </div>\n \n```\n\n```\n\n #static_pages/_show.html.erb\n \n <div class=\"Allpost\">\n <div class=\"showAllpost_detail\">\n <div class=\"Post_image\">\n <%= image_tag @post.image, :size =>'350x250'%>\n \n <div class=\"like_button\">\n <%= render 'likes/like' , post: @post%>\n </div>\n :\n (省略)\n :\n \n```\n\n```\n\n #models/post.rb\n \n class Post < ApplicationRecord\n :\n (省略)\n :\n def liked_by?(user)\n likes.where(user_id: user.id).exists?\n end\n end\n \n```\n\n```\n\n #controllers/likes_controller.rb\n \n class LikesController < ApplicationController\n protect_from_forgery except: %i[create destroy]\n before_action :set_post\n def create\n @post = Post.find(params[:post_id])\n @like = current_user.likes.new(post_id: params[:post_id])\n @like.save\n end\n \n def destroy\n @post = Post.find(params[:post_id])\n @like = Like.find_by(post_id: params[:post_id], user_id: current_user.id)\n @like.destroy\n end\n \n private\n \n def set_post\n @post = Post.find(params[:post_id])\n end\n end\n \n```\n\n```\n\n #config/routes.rb\n # frozen_string_literal: true\n \n Rails.application.routes.draw do\n get 'maps/index'\n \n root 'maps#index'\n get '/signup', to: 'users#new'\n get '/login', to: 'sessions#new'\n post '/login', to: 'sessions#create'\n delete '/logout', to: 'sessions#destroy'\n get '/test_login', to: 'users#test_login'\n post '/posts', to: 'posts#confirm'\n post '/post/create', to: 'posts#create'\n get 'post/:id', to: 'posts#show'\n get '/map_request', to: 'maps#map', as: 'map_request'\n get '/map', to: 'posts#map'\n resources :maps, only: [:index, :create]\n resources :users do\n member do\n get :following, :followers\n end\n end\n \n resources :account_activations, only: [:edit]\n resources :password_resets, only: %i[new create edit update]\n resources :posts do\n resources :likes, only: %i[destroy create]\n end\n resources :relationships, only: %i[create destroy]\n end\n \n```\n\n# 環境\n\nRails 5.1.6 \nRuby 2.5.1", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T09:29:14.530", "favorite_count": 0, "id": "65925", "last_activity_date": "2020-05-17T18:31:13.303", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ajax" ], "title": "No route matches", "view_count": 286 }
[ { "body": "`likes/_like.html.erb`の\n\n```\n\n <%= button_to 'いいね解除', post_like_path(@post), method: :delete, remote: true %>\n \n```\n\nを\n\n```\n\n <%= button_to 'いいね解除', post_like_path(@post, Like.find_by(post: @post, user: current_user)), method: :delete, remote: true %>\n \n```\n\nのように修正してみてください(実際には `Like.find_by`の部分はモデルクラスに書いたほうがいいでしょう)。\n\n* * *\n\nここで、削除したいのはLikeなので、LikeのIDを渡さないと削除のURLが呼べなくなっています。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-17T18:31:13.303", "id": "66725", "last_activity_date": "2020-05-17T18:31:13.303", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "442", "parent_id": "65925", "post_type": "answer", "score": 0 } ]
65925
66725
66725
{ "accepted_answer_id": "65940", "answer_count": 2, "body": "djangoのDetailViewをつかわずその機能が書かれた以下のコードがありました。\n\n```\n\n class TopicTemplateView_InsteadOfDetailView(TemplateView):\n template_name = 'thread/detail_topic.html'\n \n def get_context_data(self, **kwargs):\n context = super().get_context_data(**kwargs)\n context['topic'] = get_object_or_404(Topic, id=self.kwargs.get('pk', ''))\n \n return context\n \n```\n\n気になったラインが一行あって、\n\n```\n\n context['topic'] = get_object_or_404(Topic, id=self.kwargs.get('pk', ''))\n \n```\n\nこのラインは,selfがついていてなぜセルフが必要なのか、絶対必要なのかと思い、selfなしをプリントしてみたところ、どちらも同じ結果を返しました。 \n(pkの値を位置を与えたときは、どちらも1が返ってきた。)\n\n```\n\n print(kwargs.get('pk','')) # 1 \n print(self.kwargs.get('pk','')) # 1\n \n```\n\nself.kwargs, kwargs ともにdictオブジェクトでした。\n\nクラス内では、変数宣言するときに `self.変数 = 値` としますが、`変数 = 値` とでは何が違うのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T15:24:39.250", "favorite_count": 0, "id": "65929", "last_activity_date": "2020-04-25T07:59:28.640", "last_edit_date": "2020-04-25T07:59:28.640", "last_editor_user_id": "3060", "owner_user_id": "36091", "post_type": "question", "score": 0, "tags": [ "python", "python3", "django" ], "title": "class内での「self.変数」と「変数」の違いについて", "view_count": 579 }
[ { "body": "<https://uxmilk.jp/41600>\n\n上記のサイトによると、 \nクラス変数と、インスタンス変数の違いで \nクラス変数はそのクラスですべてに共通する値で、インスタンス変数はそのインスタンスごとに別々の値を持つのが特徴のようです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T16:18:05.490", "id": "65931", "last_activity_date": "2020-04-24T16:18:05.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36091", "parent_id": "65929", "post_type": "answer", "score": 0 }, { "body": "インスタンス変数self.kwargsはsetupメソッドの中で[作成されていて](https://github.com/django/django/blob/3.0.5/django/views/generic/base.py#L87)、setupはas_viewメソッドが返す[関数の中で呼ばれます](https://github.com/django/django/blob/3.0.5/django/views/generic/base.py#L65)。 \nアクセスがあると、[dispatch](https://github.com/django/django/blob/3.0.5/django/views/generic/base.py#L89)されて、[getattr](https://github.com/django/django/blob/3.0.5/django/views/generic/base.py#L94)で探し出されて、[TemplateViewのget](https://github.com/django/django/blob/3.0.5/django/views/generic/base.py#L157)が呼び出されます。\n\nTemplateViewのgetは\n\n```\n\n def get(self, request, *args, **kwargs):\n context = self.get_context_data(**kwargs)\n return self.render_to_response(context)\n \n```\n\nこうです。\n\nここでget_context_dataが呼び出されて、質問のget_context_dataが実行されるので、その時点でkwargsとself.kwargsはオブジェクトとして等しいものを指していると思います。 \n(実行して確認はしてません。悪しからず)\n\n私は\"self.kwargsとする方が紛らわしい\"という感想を持ちました。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T02:56:48.210", "id": "65940", "last_activity_date": "2020-04-25T02:56:48.210", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12274", "parent_id": "65929", "post_type": "answer", "score": 2 } ]
65929
65940
65940
{ "accepted_answer_id": null, "answer_count": 1, "body": "Apache2.4ですが、新しいWindowsマシンに移行したら、nttpd.confをコピーしたのに、NAS HDDのエイリアス登録がうまくいきません。 \n4種類ためしましたが、全部だめです。\n\n```\n\n # NAS HDDのIPアドレスバージョン(¥)\n # Alias /video3 \"\\\\192.168.1.2\\share\">\n \n # <Directory \"\\\\192.168.1.2\\share\">\n # Options Indexes FollowSymLinks\n # AllowOverride All\n # Require all granted\n # </Directory>\n \n```\n\n```\n\n # NAS HDDのデバイス名バージョン\n # Alias /video3 \"\\\\LS210DA0C\\share\"\n #\n # <Directory \"\\\\LS210DA0C\\share\">\n # Options Indexes FollowSymLinks\n # AllowOverride None\n # Require all granted\n # </Directory>\n \n```\n\n```\n\n # NAS HDDのネットワークドライブ割り当て名\n # Alias /video3 \"L:/share\"\n #\n # <Directory \"L:/share\">\n # Options Indexes FollowSymLinks\n # AllowOverride None\n # Require all granted\n # </Directory>\n \n```\n\n```\n\n # NAS HDDのIPアドレスバージョン(¥)\n # Alias /videov3 \"//192.168.1.2/share\">\n #\n # <Directory \"//192.168.1.2/share\">\n # Options Indexes FollowSymLinks\n # AllowOverride All\n # Require all granted\n # </Directory>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T17:19:16.683", "favorite_count": 0, "id": "65932", "last_activity_date": "2020-04-26T00:02:21.387", "last_edit_date": "2020-04-24T17:25:30.247", "last_editor_user_id": "3060", "owner_user_id": "39638", "post_type": "question", "score": 0, "tags": [ "apache" ], "title": "Windows10マシンを変えたら、Apache2.4で、NAS HDDをエイリアス登録できません。", "view_count": 259 }
[ { "body": "Apacheを起動しているユーザとネットワークドライブを設定しているユーザは同じですか? \n以下の順で確認しみてはいかがでしょうか\n\n 1. 起動スクリプトを修正する。 \n1\\. %USERNAME%入れる \n2\\. Netuseコマンドを起動前に仕込む\n\n 2. 起動させて状態を確認する\n\nそのほか、すでに確認されていると思いますが、起動時のエラーログなど定時されれば \nわりとそのもんずばりの回答に近づけるかと思います。\n\nそのほか、どうやってインストールして、どのフォルダのhttpd.confを修正しているかなども \n参考になるかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T00:02:21.387", "id": "65967", "last_activity_date": "2020-04-26T00:02:21.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10174", "parent_id": "65932", "post_type": "answer", "score": 0 } ]
65932
null
65967
{ "accepted_answer_id": "65949", "answer_count": 1, "body": "Railsでサーバーを立ち上げ、ChromeブラウザでIPアドレスを入力し開いたところ、下記のような画面が表示されました。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/jwXsu.jpg)](https://i.stack.imgur.com/jwXsu.jpg)\n\nこれはSQLiteを3.8以上にするようにということでしょうが \nアップデートの方法が調べてもわかりませんでした。 \nCentoOS6の環境でアップデートするにはどのようにしたらよろしいでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-24T20:40:36.800", "favorite_count": 0, "id": "65933", "last_activity_date": "2020-04-25T08:56:49.200", "last_edit_date": "2020-04-25T08:56:49.200", "last_editor_user_id": "3060", "owner_user_id": "39719", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "centos", "sqlite" ], "title": "CentOS6 で SQLite を3.8 以上にアップグレードするには?", "view_count": 1727 }
[ { "body": "[前回の質問](https://ja.stackoverflow.com/q/65861) でのやり取りと根本的な原因は同じで、CentOS6\nの標準パッケージで提供されているSQLiteのバージョンとしては **v3.6.20** が最新です。参考までに CentOS7 でも\n**v3.7.17** までしか利用できません。\n\nSQLite の v3.8 以降が必要な場合には、[公式サイトからソースコード](https://www.sqlite.org/download.html)\nを入手し、コンパイルして自力でインストールする必要があります。現時点では v3.31.1 が最新版です。\n\n**手順**\n\n```\n\n $ curl -O https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz\n $ tar xzvf sqlite-autoconf-3310100.tar.gz\n $ cd sqlite-autoconf-3310100\n $ ./configure\n $ make\n $ make install\n \n```\n\n* * *\n\n**蛇足な補足**\n\nCentOS は \"枯れた\" (=安定した)\nバージョンのパッケージを採用するディストリビューションになるので、一部を除いて収録されているアプリやライブラリのメジャーバージョンが上がる事はほぼありません。\n\n安定運用が求められる用途向けのLinuxなので、 **最新版**\nのコードを使用するような開発向けにはあまり向きません。CentOS6を使い続ける限り、今後も同じような問題が出続ける可能性があるでしょう。\n\n(ドキュメントがメンテされていなさそうなので、「ドットインストール」のサイト自体がお手本として参照するのにあまり向かないような気がします)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T06:34:00.753", "id": "65949", "last_activity_date": "2020-04-25T06:34:00.753", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "65933", "post_type": "answer", "score": 3 } ]
65933
65949
65949
{ "accepted_answer_id": "65944", "answer_count": 3, "body": "以下に示したようなデータリストがあります。 \n列見出しは `data1,data2,data3`、行見出しは `A,B,C,...M` として、以下のようなダミー変数を作りたいです。\n\nPythonを使ってどのようにすれば良いでしょうか? \nよろしくお願いします。\n\n* * *\n\n**データリスト**\n\n```\n\n data1=[\"A\",\"B\",\"C\",\"D\",\"E\"]\n data2=[\"A\",\"B\",\"G\",\"H\",\"I\"]\n data3=[\"A\",\"J\",\"K\",\"L\",\"M\"]\n \n```\n\n**ダミー変数**\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/P4bph.png)](https://i.stack.imgur.com/P4bph.png)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T01:29:38.023", "favorite_count": 0, "id": "65935", "last_activity_date": "2020-04-25T05:34:26.230", "last_edit_date": "2020-04-25T05:34:26.230", "last_editor_user_id": "3060", "owner_user_id": "21301", "post_type": "question", "score": 4, "tags": [ "python" ], "title": "pythonで質的変数→量的変数(ダミー変数化)", "view_count": 264 }
[ { "body": "pandas を使って DataFrameを作成し、変換することで\n\n```\n\n import pandas as pd\n \n data1 = [\"A\",\"B\",\"C\",\"D\",\"E\"]\n data2 = [\"A\",\"B\",\"G\",\"H\",\"I\"]\n data3 = [\"A\",\"J\",\"K\",\"L\",\"M\"]\n \n df = pd.DataFrame([data1,data2,data3], index=['data1','data2','data3'])\n df = df.apply(lambda row: row.value_counts(),axis=1).fillna(0).astype(int)\n print(df)\n # A B C D E G H I J K L M\n #data1 1 1 1 1 1 0 0 0 0 0 0 0\n #data2 1 1 0 0 0 1 1 1 0 0 0 0\n #data3 1 0 0 0 0 0 0 0 1 1 1 1\n \n```\n\nのように実現できます。\n\nただし、上記の方法は data1,data2,data3 が同サイズの時しか使えません。\n\ndata1,data2,data3 のサイズが違う場合はそれぞれのデータでDataFrameを作成して結合すると実現できます。\n\n```\n\n import pandas as pd\n \n data1 = [\"A\",\"B\",\"C\",\"D\",\"E\"]\n data2 = [\"A\",\"B\",\"G\",\"H\",\"I\"]\n data3 = [\"A\",\"J\",\"K\",\"L\",\"M\"]\n \n datas = [pd.DataFrame(1, columns=d, index=[n]) for d,n in zip([data1,data2,data3], ['data1','data2','data3'])]\n df = pd.concat(datas).fillna(0).astype(int)\n print(df)\n # A B C D E G H I J K L M\n #data1 1 1 1 1 1 0 0 0 0 0 0 0\n #data2 1 1 0 0 0 1 1 1 0 0 0 0\n #data3 1 0 0 0 0 0 0 0 1 1 1 1\n \n```\n\nSeries使っても書けますが、コード量的にはあまり変わりませんね。\n\n```\n\n datas = [pd.Series(1, index=d, name=n) for d,n in zip([data1,data2,data3], ['data1','data2','data3'])]\n df = pd.concat(datas, axis=1).fillna(0).astype(int).T\n print(df)\n # A B C D E G H I J K L M\n #data1 1 1 1 1 1 0 0 0 0 0 0 0\n #data2 1 1 0 0 0 1 1 1 0 0 0 0\n #data3 1 0 0 0 0 0 0 0 1 1 1 1\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T03:00:44.587", "id": "65941", "last_activity_date": "2020-04-25T03:00:44.587", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24801", "parent_id": "65935", "post_type": "answer", "score": 2 }, { "body": "カラムは `string.ascii_uppercase` から作成しています。この場合、`data1`, `data2`, `data3`\nには含まれていない `F` も結果に含める事ができます。\n\n```\n\n from string import ascii_uppercase\n from collections import Counter\n import pandas as pd\n \n data1 = [\"A\", \"B\", \"C\", \"D\", \"E\"]\n data2 = [\"A\", \"B\", \"G\", \"H\", \"I\"]\n data3 = [\"A\", \"J\", \"K\", \"L\", \"M\"]\n \n pd.DataFrame(\n [Counter(x) for x in (data1, data2, data3)],\n index=['data1', 'data2', 'data3'],\n columns=list(ascii_uppercase)[:13],\n dtype='Int64'\n ).fillna(0)\n \n =>\n A B C D E F G H I J K L M\n data1 1 1 1 1 1 0 0 0 0 0 0 0 0\n data2 1 1 0 0 0 0 1 1 1 0 0 0 0\n data3 1 0 0 0 0 0 0 0 0 1 1 1 1\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T03:50:51.183", "id": "65944", "last_activity_date": "2020-04-25T03:50:51.183", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "65935", "post_type": "answer", "score": 4 }, { "body": "既に解決済みですが、別解です。ライブラリは使っていません。\n\n**コード**\n\n```\n\n data1 = [\"A\",\"B\",\"C\",\"D\",\"E\"]\n data2 = [\"A\",\"B\",\"G\",\"H\",\"I\"]\n data3 = [\"A\",\"J\",\"K\",\"L\",\"M\"]\n row_heading = list(map(lambda x: chr(x),list(range(ord(\"A\"),ord(\"M\")+1))))\n out_1 = [(1 if x in data1 else 0) for x in row_heading]\n out_2 = [(1 if x in data2 else 0) for x in row_heading]\n out_3 = [(1 if x in data3 else 0) for x in row_heading]\n \n print(row_heading)\n print(data1)\n print(out_1)\n print(data2)\n print(out_2)\n print(data3)\n print(out_3)\n \n```\n\n**結果**\n\n```\n\n ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']\n ['A', 'B', 'C', 'D', 'E']\n [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]\n ['A', 'B', 'G', 'H', 'I']\n [1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0]\n ['A', 'J', 'K', 'L', 'M']\n [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T04:15:42.697", "id": "65945", "last_activity_date": "2020-04-25T04:15:42.697", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "35558", "parent_id": "65935", "post_type": "answer", "score": 0 } ]
65935
65944
65944
{ "accepted_answer_id": null, "answer_count": 1, "body": "もともとPythonを入れていて、言語をC言語に変えたいのですがうまくいきません。 \nターミナルがPython仕様になっているようです。どうすればうまくいくでしょうか\n\n[![](https://i.stack.imgur.com/DAEZA.jpg)](https://i.stack.imgur.com/DAEZA.jpg)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T01:35:43.960", "favorite_count": 0, "id": "65936", "last_activity_date": "2020-04-25T06:36:39.067", "last_edit_date": "2020-04-25T06:36:39.067", "last_editor_user_id": "3060", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "python", "c", "vscode" ], "title": "Vscodeで、プログラミング言語を変えたい", "view_count": 858 }
[ { "body": "右下にPythonと表示されている箇所がありませんか? \nそこをクリックすると「言語モードの選択」と表示されて他の言語に変更できると思います", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T01:41:16.700", "id": "65938", "last_activity_date": "2020-04-25T01:41:16.700", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "65936", "post_type": "answer", "score": 1 } ]
65936
null
65938
{ "accepted_answer_id": null, "answer_count": 0, "body": "spacemacs を入れてみました。これは、コミュニティで .emacs.d を共通化・構造化していこうとしているプロジェクトだと自分は理解しています。\n\n今、画面をスクロールするにあたって、これは vim (evil) binding\nですので、そのキー操作は`C-f`に割り当てられているのですが、マニュアル的なテキストを読んでいる際には、 less や info\nのように、1文字キーボードでスクロールしてほしいな、と思います。\n\n素の emacs をカスタマイズする際であるならば、空いているキーバインドに適当にスクロールの関数を割り当てれば話は終わるのですが、 spacemacs\nだと、 spacemacs に付属している既存の layer\nたちが壊れないように、キーバインドを割り当てるなどの設定をしていかなければならなさそうだ、と思っています。\n\n# 質問\n\nspacemacs で less や info のような1キースクロールを行いたくなった際には、どのような設定が推奨されるものなのでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T03:06:16.690", "favorite_count": 0, "id": "65942", "last_activity_date": "2020-04-25T03:06:16.690", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "post_type": "question", "score": 0, "tags": [ "spacemacs" ], "title": "spacemacs で less/info のように、 1 キーボードでスクロールできるようにしたい", "view_count": 67 }
[]
65942
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "VScode でC言語の実行のところからデバッグをしようと思ったんですが、以下のエラーが発生してしまい実行できません。\n\n```\n\n launch:program'C:\\C\\launch.exe'does not exist\n \n```\n\nMinGWをインストールして環境変数PATHも設定追加済みです。 \nOSはWindows10で、MinGWは公式サイトからインストールしました。インストール対象はmingw-32-base-binのみにチェックを入れました。\n\n編集しようとしているCファイルは、Acer(C:)の中のCという名前で作成したフォルダに.vscode(この中にはlanch.jsonというJSONファイルが入っていました)というファイルフォルダとともに入れてあります。 \nC/C++ExtensionはVScode内でインストールしてあります。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T03:42:21.430", "favorite_count": 0, "id": "65943", "last_activity_date": "2022-04-12T11:06:15.740", "last_edit_date": "2021-10-21T06:14:11.543", "last_editor_user_id": "3060", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "c", "vscode" ], "title": "VScode でC言語のデバッグができません \"launch:program'C:\\C\\launch.exe'does not exist\"", "view_count": 8076 }
[ { "body": "エラーメッセージは「`C:\\C\\launch.exe` が存在しません」というものです。\n\n原因と対処方法は以下のような事になるかと。\n\n * `C:\\C\\launch.exe` というファイルを作り忘れている (まだコンパイルしていない)。 \n-> launch.exeを作ればOK\n\n * launch.exeを `C:\\C\\` とは異なるフォルダーに作ってしまった。 \n-> launch.exeを `C:\\C\\` に移せばOK", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T05:24:35.613", "id": "65947", "last_activity_date": "2021-10-21T06:16:58.180", "last_edit_date": "2021-10-21T06:16:58.180", "last_editor_user_id": "3060", "owner_user_id": "217", "parent_id": "65943", "post_type": "answer", "score": 1 } ]
65943
null
65947
{ "accepted_answer_id": null, "answer_count": 1, "body": "**Cmd+D** に設定したいです。\n\n[VisualStudioで行複製をCtrl+Shift+Dでできますか? -\nteratail](https://teratail.com/questions/213085)\n\nにある **Keyboard Shortcuts Manager** というもののMac版があればいいのですが。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T06:22:17.017", "favorite_count": 0, "id": "65948", "last_activity_date": "2020-04-25T09:29:46.237", "last_edit_date": "2020-04-25T08:06:59.290", "last_editor_user_id": "3060", "owner_user_id": "12297", "post_type": "question", "score": 0, "tags": [ "macos", "visual-studio" ], "title": "Visual Studio for Macで「行の複製」のショートカットを設定するには?", "view_count": 621 }
[ { "body": "おそらくインストールと設定だけで出来るようなものは「今は無い」と思われます。\n\n参照記事の回答にも書いてある通り、元々Windows版VidualStudioに「行の複製」の機能があるからショートカットを割り当てることが出来ると考えられます。 \n[VisualStudioで行複製をCtrl+Shift+Dでできますか?](https://teratail.com/questions/213085)\n\n>\n> 4.`Commaond`に`Edit.Duplicate`、`Scope`に`テキストエディタ`、`Shortcut`で`CTRL+SHIFT+D`を入力、`Add\n> Shortcut`して`Close`する\n\nVisual Studio の既定のキーボード ショートカット \n[編集](https://docs.microsoft.com/ja-jp/visualstudio/ide/default-keyboard-\nshortcuts-in-visual-studio?view=vs-2019#bkmk_edit)\n\n> Edit.Duplicate **Ctrl** \\+ **D**\n\nVisual Studio for Mac の既定のキーボード ショートカット \n[編集](https://docs.microsoft.com/ja-jp/visualstudio/mac/keyboard-\nshortcuts?view=vsmac-2019#edit) \nDefault keyboard shortcuts in Visual Studio for Mac \n[Edit](https://docs.microsoft.com/en-us/visualstudio/mac/keyboard-\nshortcuts?view=vsmac-2019#edit)\n\nMac版では日本語/英語どちらのページでも編集機能に行の複製(Duplicate)に関する項目は有りません。\n\n* * *\n\n代替出来る機能としてのマクロ機能はVisualStudio2012で削除されていて、それを補うExtensionもWindows版はあってもMac版は無い状況です。\n\n[Visual Studio Community\n2013でマクロ機能を使う](http://jirolabo.hatenablog.com/entry/2015/01/11/114443)\n\n> マクロの記録・再生機能は Visual Studio 2012 で廃止されてしまいました。 \n> ただし、Visual Studio (Community) 2013で拡張機能をインストールすることでマクロ機能が使えます。\n\nその拡張機能の現在はこれですが、MacOSに対応している(Tagsリストにmacosが有る)という情報はありません。 \n[Macros for Visual\nStudio](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MacrosforVisualStudio)\n\nというよりVisual Studio for Mac用の拡張機能は非常に少なく8個しかありません。 \n[tag:macosを指定して検索した結果](https://marketplace.visualstudio.com/search?term=tag%3Amacos&target=VS&category=All%20categories&vsVersion=&sortBy=Relevance)\n\nちなみにWindows版でもマクロ機能の復活を望む声は有るようですが、実現性は乏しそうです。 \n[Macros for Visual Studio\nVS2019](https://developercommunityapi.westus.cloudapp.azure.com/idea/477471/macros-\nfor-visual-studio-vs2019.html)\n\n* * *\n\n無ければ自分で作ってしまえという情報がこの記事の回答に書かれています。 \n[Visual Studio : short cut Key : Duplicate\nLine](https://stackoverflow.com/q/2279000/9014308)\n\n> **Macro solution (pre VS2017)** \n> If you'd like to implement a more complete solution, perhaps to create a\n> simpler keyboard shortcut or you don't want to effect the clipboard, see\n> this guide:\n>\n>\n> より完全なソリューションを実装したい場合、より単純なキーボードショートカットを作成したい場合、またはクリップボードに影響を与えたくない場合は、次のガイドを参照してください。\n\n「次のガイドを参照してください。」で紹介されているリンクは今は存在しないようです。 \nしかし、そのVisualBasicによる内容はコピーされているので、それを参考に自分で作ることは出来るかもしれません。\n\n* * *\n\nあとはWindows版には機能があるわけですから、それをMac版にも移植して欲しいと要望を出しておいて、実現される様なら気長に待つということも考えられます。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T09:29:46.237", "id": "65950", "last_activity_date": "2020-04-25T09:29:46.237", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "26370", "parent_id": "65948", "post_type": "answer", "score": 1 } ]
65948
null
65950
{ "accepted_answer_id": null, "answer_count": 1, "body": "### 前提・実現したいこと\n\nRuby on Rails6 実践ガイドの書籍を用いてDockerでRuby on Railsの環境構築をしたいです。 \n以下のコマンドを実行するとエラーが出て、データベースに接続されないようです。解決策をお教え下さい。\n\n### 発生している問題・エラーメッセージ\n\n```\n\n bash-4.4$ bin/rails db:create\n could not translate host name \"db\" to address: Name does not resolve\n Couldn't create 'baukis2_development' database. Please check your configuration.\n rails aborted!\n PG::ConnectionBad: could not translate host name \"db\" to address: Name does not resolve\n /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'\n /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new'\n /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:889:in `new_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `checkout_new_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:912:in `try_to_checkout_new_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:873:in `acquire_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:595:in `checkout'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:439:in `connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1121:in `retrieve_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_handling.rb:238:in `retrieve_connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/connection_handling.rb:206:in `connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:126:in `create'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:185:in `block in create_current'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:479:in `block (2 levels) in each_current_configuration'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:476:in `each'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:476:in `block in each_current_configuration'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:475:in `each'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:475:in `each_current_configuration'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/tasks/database_tasks.rb:184:in `create_current'\n /usr/local/bundle/gems/activerecord-6.0.2.2/lib/active_record/railties/databases.rake:39:in `block (2 levels) in <main>'\n /usr/local/bundle/gems/railties-6.0.2.2/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'\n /usr/local/bundle/gems/railties-6.0.2.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'\n /usr/local/bundle/gems/railties-6.0.2.2/lib/rails/command.rb:48:in `invoke'\n /usr/local/bundle/gems/railties-6.0.2.2/lib/rails/commands.rb:18:in `<main>'\n /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'\n /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'\n /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'\n /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'\n /usr/local/bundle/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'\n /usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require'\n /usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency'\n /usr/local/bundle/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require'\n /apps/baukis2/bin/rails:9:in `<top (required)>'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'\n /usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'\n /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'\n /apps/baukis2/bin/spring:15:in `<top (required)>'\n bin/rails:3:in `load'\n bin/rails:3:in `<main>'\n Tasks: TOP => db:create\n (See full trace by running task with --trace)\n \n```\n\n### 該当のソースコード\n\ndatabase.yml\n\n```\n\n # PostgreSQL. Versions 9.3 and up are supported.\n #\n # Install the pg driver:\n # gem install pg\n # On macOS with Homebrew:\n # gem install pg -- --with-pg-config=/usr/local/bin/pg_config\n # On macOS with MacPorts:\n # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config\n # On Windows:\n # gem install pg\n # Choose the win32 build.\n # Install PostgreSQL and put its /bin directory on your path.\n #\n # Configure Using Gemfile\n # gem 'pg'\n #\n default: &default\n adapter: postgresql\n encoding: unicode\n # For details on connection pooling, see Rails configuration guide\n # https://guides.rubyonrails.org/configuring.html#database-pooling\n pool: <%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>\n host: db\n username: postgres\n password: \"\"\n \n development:\n <<: *default\n database: baukis2_development\n \n # The specified database role being used to connect to postgres.\n # To create additional roles in postgres see `$ createuser --help`.\n # When left blank, postgres will use the default role. This is\n # the same name as the operating system user that initialized the database.\n #username: baukis2\n \n # The password associated with the postgres role (username).\n #password:\n \n # Connect on a TCP socket. Omitted by default since the client uses a\n # domain socket that doesn't need configuration. Windows does not have\n # domain sockets, so uncomment these lines.\n #host: localhost\n \n # The TCP port the server listens on. Defaults to 5432.\n # If your server runs on a different port number, change accordingly.\n #port: 5432\n \n # Schema search path. The server defaults to $user,public\n #schema_search_path: myapp,sharedapp,public\n \n # Minimum log levels, in increasing order:\n # debug5, debug4, debug3, debug2, debug1,\n # log, notice, warning, error, fatal, and panic\n # Defaults to warning.\n #min_messages: notice\n \n # Warning: The database defined as \"test\" will be erased and\n # re-generated from your development database when you run \"rake\".\n # Do not set this db to the same as development or production.\n test:\n <<: *default\n database: baukis2_test\n \n # As with config/credentials.yml, you never want to store sensitive information,\n # like your database password, in your source code. If your source code is\n # ever seen by anyone, they now have access to your database.\n #\n # Instead, provide the password as a unix environment variable when you boot\n # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database\n # for a full rundown on how to provide these environment variables in a\n # production deployment.\n #\n # On Heroku and other platform providers, you may have a full connection URL\n # available as an environment variable. For example:\n #\n # DATABASE_URL=\"postgres://myuser:mypass@localhost/somedatabase\"\n #\n # You can use this database configuration with:\n #\n # production:\n # url: <%= ENV['DATABASE_URL'] %>\n #\n production:\n <<: *default\n database: baukis2_production\n username: baukis2\n password: <%= ENV['BAUKIS2_DATABASE_PASSWORD'] %>\n \n \n```\n\ndocker-compose.yml\n\n```\n\n version: '3'\n services:\n db:\n image: postgres:11.2-alpine\n volumes:\n - ./tmp/db:/var/lib/postgresql/data\n web:\n build: .\n command: /bin/sh\n environment:\n WEBPACKER_DEV_SERVER_HOST: \"0.0.0.0\"\n RAILS_SERVE_STATIC_FILES: \"1\"\n EDITOR: \"vim\"\n volumes:\n - ./apps:/apps\n ports:\n - \"3000:3000\"\n - \"3035:3035\"\n depends_on:\n - db\n tty: true\n \n \n```\n\nDockerfile\n\n```\n\n FROM oiax/rails6-deps:latest\n \n ARG UID=1000\n ARG GID=1000\n \n RUN mkdir /var/mail\n RUN groupadd -g $GID devel\n RUN useradd -u $UID -g devel -m devel\n RUN echo \"devel ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers\n \n WORKDIR /tmp\n COPY init/Gemfile /tmp/Gemfile\n COPY init/Gemfile.lock /tmp/Gemfile.lock\n RUN bundle install\n \n COPY ./apps /apps\n \n RUN apk add --no-cache openssl\n \n USER devel\n \n RUN openssl rand -hex 64 > /home/devel/.secret_key_base\n RUN echo $'export SECRET_KEY_BASE=$(cat /home/devel/.secret_key_base)' \\\n >> /home/devel/.bashrc\n \n WORKDIR /apps\n \n```\n\n### 試したこと\n\n 1. `docker-compose run web rails db:create` を実行したが、変化はなかった。\n 2. config/database.ymlのuserをrootにし、実行したが、変化はなかった。\n 3. config/database.ymlのhostをlocalhostにし、実行したが、変化はなかった。\n\npostgresqlのプロセスを確認したところ \n存在していなかった\n\n```\n\n ps -ef | grep ps -ef | grep post\n devel 1407 1333 0 09:46 pts/1 00:00:00 grep post\n \n```\n\npostgresqlに関するディレクトリが存在するか確認したところ複数件ヒットした。 \nしかし、どのようにしてサービスのステータスを確認および、起動させるかわからず調査中。\n\n```\n\n find / -type f | xargs grep postgres\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T09:54:45.850", "favorite_count": 0, "id": "65951", "last_activity_date": "2022-05-09T11:05:35.657", "last_edit_date": "2020-04-25T11:26:10.943", "last_editor_user_id": "3060", "owner_user_id": "39658", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "docker", "docker-compose", "docker-for-mac" ], "title": "docker-composeでのRuby on Rails環境構築でPostgreSQLに接続できない", "view_count": 790 }
[ { "body": "> could not translate host name \"db\" to address: Name does not resolve\n\nとあるので、Docker内部DNSの名前解決ができていないように見えます。 \nアプリケーションのコンテナの中から ping db などは通りますか?", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T10:38:26.973", "id": "65952", "last_activity_date": "2020-04-25T10:38:26.973", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21329", "parent_id": "65951", "post_type": "answer", "score": 1 } ]
65951
null
65952
{ "accepted_answer_id": "65972", "answer_count": 3, "body": "CentOS 7での環境でRuby、及びRailsのインストールをしたいと思っているのですが、うまくいきません。\n\nインストールの途中で作業を中断したせいか、何か余計なファイルができてしまったのかもしれません。\n\n下記がエラー内容になります。\n\n```\n\n [vagrant@localhost ~]$ rbenv install 2.7.1\n Downloading ruby-2.7.1.tar.bz2...\n -> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2\n Installing ruby-2.7.1...\n mkdir: cannot create directory '/usr/local/rbenv/versions': Permission denied\n \n BUILD FAILED (CentOS Linux 7 using ruby-build 20200401)\n \n Inspect or clean up the working tree at /tmp/ruby-build.20200425104357.15616.hMCHV3\n Results logged to /tmp/ruby-build.20200425104357.15616.log\n \n Last 10 log lines:\n /tmp/ruby-build.20200425104357.15616.hMCHV3 ~\n /tmp/ruby-build.20200425104357.15616.hMCHV3/ruby-2.7.1 /tmp/ruby-build.20200425104357.15616.hMCHV3 ~\n \n```\n\nこの内容によると、おそらく「`/tmp/ruby-build.20200424224509.11267.eBUEN2`というものを \nクリーンアップして」ということかと思いますが、調べても自分ではクリーンアップの方法がわかりませんでした。\n\nRuby、及びRailsをダウンロードするにはどうすればいいでしょうか?\n\n* * *\n\n**追記** \n以下のようにしてみましたが、同じエラーになります。\n\n```\n\n [vagrant@localhost ~]$ /usr/local/rbenv/bin/rbenv\n rbenv 1.1.2-30-gc879cb0\n Usage: rbenv <command> [<args>]\n \n Some useful rbenv commands are:\n commands List all available rbenv commands\n local Set or show the local application-specific Ruby version\n global Set or show the global Ruby version\n shell Set or show the shell-specific Ruby version\n install Install a Ruby version using ruby-build\n uninstall Uninstall a specific Ruby version\n rehash Rehash rbenv shims (run this after installing executables)\n version Show the current Ruby version and its origin\n versions List installed Ruby versions\n which Display the full path to an executable\n whence List all Ruby versions that contain the given executable\n \n See 'rbenv help <command>' for information on a specific command.\n For full documentation, see: https://github.com/rbenv/rbenv#readme\n \n [vagrant@localhost ~]$ echo 'export PATH=\"/usr/local/bin:$PATH\"' >> ~/.bashrc\n [vagrant@localhost ~]$ . ~/.bashrc\n [vagrant@localhost ~]$ rbenv install 2.7.1\n Downloading ruby-2.7.1.tar.bz2...\n -> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2\n Installing ruby-2.7.1...\n mkdir: cannot create directory '/usr/local/rbenv/versions': Permission denied\n \n BUILD FAILED (CentOS Linux 7 using ruby-build 20200401)\n \n Inspect or clean up the working tree at /tmp/ruby-build.20200425144427.16489.ZFZUgA\n Results logged to /tmp/ruby-build.20200425144427.16489.log\n \n Last 10 log lines:\n /tmp/ruby-build.20200425144427.16489.ZFZUgA ~\n /tmp/ruby-build.20200425144427.16489.ZFZUgA/ruby-2.7.1 /tmp/ruby-build.20200425144427.16489.ZFZUgA ~\n \n```\n\n`sudo /usr/local/rbenv/bin/rbenv install` の実行結果は以下の通りです。\n\n```\n\n [vagrant@localhost ~]$ sudo /usr/local/rbenv/bin/rbenv install 2.7.1\n rbenv: no such command `install' \n \n```\n\n* * *\n\n**追記2(rbenvのアンインストールのためにやったこと)**\n\n 1. rbenvのバージョンを確認\n\n```\n\n [vagrant@localhost .rbenv]$ rbenv -v\n rbenv 1.1.2-30-gc879cb0\n \n```\n\n 2. アンインストールを試すがそんなバージョンはないと言われる\n\n```\n\n [vagrant@localhost .rbenv]$ rbenv uninstall 1.1.2-30-gc879cb0\n rbenv: version `1.1.2-30-gc879cb0' not installed\n [vagrant@localhost .rbenv]$ rbenv uninstall 1.1.2\n rbenv: version `1.1.2' not installed\n \n```\n\n 3. 下記のコマンドを試してみる\n\n```\n\n [vagrant@localhost .rbenv]$ rm -rf `rbenv root`\n [vagrant@localhost .rbenv]$ \n \n```\n\n 4. うまく行ったのかと思い、ヴァージョンを確かめるもまだ存在している\n\n```\n\n [vagrant@localhost .rbenv]$ rbenv -v\n rbenv 1.1.2-30-gc879cb0\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T10:53:00.827", "favorite_count": 0, "id": "65954", "last_activity_date": "2020-04-26T13:29:07.207", "last_edit_date": "2020-04-26T13:29:07.207", "last_editor_user_id": "32986", "owner_user_id": "39719", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "centos" ], "title": "rbenv install 2.7.1でエラー: mkdir: cannot create directory '/usr/local/rbenv/versions': Permission denied", "view_count": 2745 }
[ { "body": "> mkdir: cannot create directory '/usr/local/rbenv/versions': Permission\n> denied\n\n問題はこれでは", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T11:03:24.783", "id": "65955", "last_activity_date": "2020-04-25T11:03:24.783", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21329", "parent_id": "65954", "post_type": "answer", "score": -1 }, { "body": "事前に `rbenv` を root 権限でインストールしていませんか? `/usr/local/rbenv/`\n以下にインストールされているようなので、この状態であるなら Ruby のインストールにも root 権限が必要となります。\n\n具体的には `sudo` コマンドを使用する必要があると思います。\n\n```\n\n $ sudo rbenv install 2.7.1\n \n```\n\n* * *\n\nあなたは rbenv を一般ユーザーの権限で実行していますが、以下のエラーは対象のディレクトリに対して \"適切な権限が無い (ファイルが作成できない)\"\nという内容です。\n\n```\n\n mkdir: cannot create directory '/usr/local/rbenv/versions': Permission denied\n \n```\n\n対象のディレクトリ `/usr` を含め、システムディレクトリに対して変更を加えるには Linux だと管理者 (root) 権限が必要になります。 \nroot ユーザーでログインする代わりに、通常は `sudo` コマンドを使用するのが一般的です。\n\n* * *\n\n**追記**\n\n`/usr/local/rbenv/` 以下にインストールされているなら、`rbenv` コマンドは恐らく以下のパスで呼び出す必要があります。\n\n```\n\n /usr/local/rbenv/bin/rbenv\n \n```\n\n環境変数 PATH に追加しておくと便利でしょう。\n\n```\n\n $ echo 'export PATH=\"/usr/local/bin:$PATH\"' >> ~/.bashrc\n $ . ~/.bashrc\n \n```\n\n環境変数 PATH の設定を含め、rbenv の使い方に関しては [README](https://github.com/rbenv/rbenv)\nにも記載があるので、今一度確認してみてください。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T11:29:31.477", "id": "65956", "last_activity_date": "2020-04-25T13:48:01.850", "last_edit_date": "2020-04-25T13:48:01.850", "last_editor_user_id": "3060", "owner_user_id": "3060", "parent_id": "65954", "post_type": "answer", "score": 3 }, { "body": "root 権限が無いと書きこめない場所に書きこもうとしてエラーになっています。自分用に使いたいだけであれば rbenv は root\n権限が無くても諸々を管理できるように設定するのが便利ですし、そちらの方が一般的かと思います。rbenv を一度アンインストールして、sudo\nせずにインストールするのは如何でしょうか。\n\nrbenv をどのようにインストールされたのか分からないのでアンインストール方法はお任せします。\n\nアンインストール後、[rbenv の README.md](https://github.com/rbenv/rbenv)\nに従ってインストールしてください。\"Basic GitHub Checkout\" と書かれているやり方です。\n\n以下に実行するであろうコマンドの列を書いておきますが、これをこのままコピペするのではなく、README.md の説明を読みつつやるのをオススメします。\n\n```\n\n git clone https://github.com/rbenv/rbenv.git ~/.rbenv\n cd ~/.rbenv && src/configure && make -C src\n echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bashrc # あるいは ~/.bash_profile\n ~/.rbenv/bin/rbenv init\n # ↑表示された出力に従う\n # シェルを再起動する\n mkdir -p \"$(rbenv root)\"/plugins\n git clone https://github.com/rbenv/ruby-build.git \"$(rbenv root)\"/plugins/ruby-build\n \n```\n\nこのあと `rbenv install ほにゃらら`\nをすると色々エラーが出るかもしれません。その多くは依存しているバイナリやライブラリが足りないことに起因しています。エラーログを読んで足りないものを yum\nからインストールしてください。場合によっては \"Results logged to ほにゃらら\" と書かれているログファイルを読む必要があるでしょう。\n\nたとえば下のあたりが必要そうです。\n\n```\n\n yum install wget git gcc autoconf make bzip2 openssl-devel\n \n```", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T02:32:38.557", "id": "65972", "last_activity_date": "2020-04-26T03:04:15.920", "last_edit_date": "2020-04-26T03:04:15.920", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "65954", "post_type": "answer", "score": 2 } ]
65954
65972
65956
{ "accepted_answer_id": "65965", "answer_count": 1, "body": "kotlinはまったく初めての者ですが、googleのandroidデベロッパーズサイト掲載のkotlinコードについての質問です。 \nダイアログの解説ページ( <https://developer.android.com/guide/topics/ui/dialogs#kotlin>\n)に、kotlinのコードで下記のように \"activity?\" というものが記述されています。 \n「nullでなければActivityが存在している」ということと思います。 \n一方、Android Studioでkotlinでのプロジェクトを作って activity?.println(\"OK\") と書くと unresolved\nreference となります。 \nデベロッパーズサイトのようにactivityを使うにはどうすればよいのでしょうか?\n\n```\n\n override fun onCreateDialog(savedInstanceState: Bundle): Dialog {\n return activity?.let {\n ....\n } ?: throw IllegalStateException(\"Activity cannot be null\")\n }\n \n```\n\nOOPer様、ありがとうございます。\n\n「activityと言うのは、DialogFragmentのプロパティ(親クラスのFragmentから継承したもの)です。(JavaのgetterメソッドgetActivity()が、Kotlinではプロパティとして扱われています。)」についてですが、デベロッパーズサイトを見ると、 \n\"Activity! getActivity() Return the Activity this fragment is currently\nassociated with.\" とありますが、activityフィールドについての記述はありません。 \n「activity?ってなんだろう?」と思った時、どうやって調べればよいのでしょうか?\n\n自分で書いてみたコードは下記の単純なものです。activityプロパティの無いクラスですね。\n\n```\n\n class MainActivity : AppCompatActivity() {\n \n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_main)\n activity?.println(\"OK\")\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T13:08:41.753", "favorite_count": 0, "id": "65960", "last_activity_date": "2020-04-26T00:47:17.427", "last_edit_date": "2020-04-26T00:21:23.510", "last_editor_user_id": "32105", "owner_user_id": "32105", "post_type": "question", "score": 1, "tags": [ "android", "kotlin" ], "title": "android kotlinでのactivity?.let{ }のactivityについて", "view_count": 537 }
[ { "body": "## _「nullでなければActivityが存在している」ということと思います。_\n\n正直、この書き方ではあなたが正しく理解できているのかどうかが見えてこないのですが、Kotlin学習において「null安全なコードの書き方」は肝になるところなので、「思います」なんて、あやふやなまま放置されない方がいいでしょう。\n\nまず、`activity`と言うのは、`DialogFragment`のプロパティ(親クラスの`Fragment`から継承したもの)です。(Javaのgetterメソッド`getActivity()`が、Kotlinではプロパティとして扱われています。)\n\nその値は`FragmentActivity?`と言うNullableな型ですので、`?.`と言う[safe\ncall演算子](https://kotlinlang.org/docs/reference/null-safety.html#safe-\ncalls)を使っています。\n\n * `activity`が非`null`なら`let`を呼ぶ、`null`なら何もせず`null`を返す\n\nと言う動作になります。\n\n* * *\n\n## _activity?.println(\"OK\") と書くと unresolved reference となります。_\n\nコードを示される場合には、コードの一部分をそれだけ示されても意味を持ちません。できるだけ、そのコードが呼び出される文脈(少なくともどのクラスのどのメソッド、できればそのクラスやメソッドがどう使われるのかわかる情報も)を示してください。\n\n上に書いたように、`FireMissilesDialogFragment`というクラスは、`activity`というプロパティを(継承して)持っています。したがって、メソッド(メンバ関数)中で`activity`と書けば、そのプロパティの値を表すことになります。\n\n「Android\nStudioでkotlinでのプロジェクトを作って」としか書いていないので、どこにそのコードを書かれたのかがわからないのですが、`activity`なんてプロパティを持たないクラスの中に書かれたのではないですか?\n\nまた、`println`はKotlinではトップレベル関数ですから、呼び出しにドット記法は使いません。\n\n`activity`という名称のプロパティを持つクラス中であれば、\n\n```\n\n activity?.let {\n println(it)\n }\n \n```\n\nという書き方なら動くでしょう。\n\n* * *\n\nこちらもKotlinに関しては、ざっくり基本を学んだばかりなので、何もかもに詳しくお答えすることは難しいですが、上記の説明で分かりにくいところなどあれば、コメントしてください。\n\n* * *\n\n追記部分について。\n\n### _デベロッパーズサイトを見ると、\"Activity! getActivity() Return the Activity this fragment\nis currently associated with.\" とありますが、activityフィールドについての記述はありません。_\n\nその通りですね。現在のAndroidサイトのKotlin用リファレンスでは、そこら辺がうまく表現できていないようです。\n\nKotlinからJavaのクラスを使う場合、次の記事も意識しておかないといけません。 \n[Calling Java from Kotlin](https://kotlinlang.org/docs/reference/java-\ninterop.html#calling-java-code-from-kotlin)\n\n[Getters and Setters](https://kotlinlang.org/docs/reference/java-\ninterop.html#getters-and-setters)\n\n要はJavaのクラスに`get〜()`と言うgetterと`set〜(...)`と言うsetterメソッドがある場合(setterはなくても良いんですが)、それらは(メソッドではなく)Kotlinのプロパティになる、ってことが書いてあります。\n\nAndroidのKotlin版ドキュメントについては、改善要望など出されると良いと思いますが、その辺が完全に反映されるまで、`activity...`と言う式を見つけたら、`activity`と言うプロパティ定義がないかだけでなく、`getActivity()`と言うgetterメソッドがないかも一緒に探さないといけないと言うことになります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T19:54:05.747", "id": "65965", "last_activity_date": "2020-04-26T00:47:17.427", "last_edit_date": "2020-04-26T00:47:17.427", "last_editor_user_id": "13972", "owner_user_id": "13972", "parent_id": "65960", "post_type": "answer", "score": 1 } ]
65960
65965
65965
{ "accepted_answer_id": null, "answer_count": 1, "body": "こんにちは。AndroidとOkhttp3についての質問です。\n\nOkhttp3(3.10.0)と[PersistentCookieStore](https://gist.github.com/franmontiel/ed12a2295566b7076161)を用いてセッションログインを実装しているのですが、Android7では問題なくログインできるのですがAndroid10ではログインできません。([ログイン先](https://x.mirm.jp/login)がOSによって違う動作をさせるということはありません。)\n\n通信内容をStethoを用いて調べてみると、タイトルの通りHttpヘッダのSet-\nCookieがAndroid10では動いていなかったようです。(※Android7および通常のJRE 11ではSet-\nCookieが動作してCookieとして返し、正しくログインできました。) \n以下に周辺のコードと通信のデバッグ内容を記載します。どなたか原因及び解決法のご教示をお願いいたします。\n\n```\n\n compileSdkVersion 29\n buildToolsVersion \"29.0.2\"\n minSdkVersion 22\n targetSdkVersion 29\n \n```\n\n```\n\n // 便宜上loginを実行する関数\n fun loginTest() {\n API.login(\"serverId\", \"my_password\")\n }\n \n```\n\n```\n\n object API {\n private val gson = Gson()\n var loggedIn = false\n var serverId = \"\"\n \n // LoginResponseおよびAbstractResponseはレスポンスのデータクラス\n fun login(serverId: String, password: String): LoginResponse {\n try {\n val response = Http.postXWwwFormUrlEncoded(\n \"https://x.mirm.jp/authenticate\", mapOf(\n \"serverId\" to URLEncoder.encode(serverId),\n \"password\" to URLEncoder.encode(password),\n \"_csrf\" to getCsrf() // ログインのため一度CSRFトークンを取得する\n )\n ) ?: return LoginResponse(AbstractResponse.STATUS_ERROR, LoginResponse.LOGIN_STATUS_FAILED)\n \n if (response.contains(\"期限切れでサーバーが削除されました。\")) return LoginResponse(AbstractResponse.STATUS_SUCCEEDED, LoginResponse.LOGIN_STATUS_DELETED_SERVER)\n if (response.contains(\"サーバー削除ボタンによって削除されています。\")) return LoginResponse(AbstractResponse.STATUS_SUCCEEDED, LoginResponse.LOGIN_STATUS_USER_DELETED)\n \n return response.contains(\"MiRm | コントロールパネル\").let {\n if (it) {\n this.loggedIn = true\n this.serverId = serverId\n return LoginResponse(AbstractResponse.STATUS_SUCCEEDED, LoginResponse.LOGIN_STATUS_SUCCEEDED)\n \n } else {\n return LoginResponse(AbstractResponse.STATUS_SUCCEEDED, LoginResponse.LOGIN_STATUS_FAILED)\n }\n }\n \n } catch (e: MissingRequestException) {\n if (e.errorCode == 503) {\n return LoginResponse(AbstractResponse.STATUS_OUT_OF_SERVICE, LoginResponse.LOGIN_STATUS_FAILED)\n }\n \n } catch (e: Exception) {\n e.printStackTrace()\n }\n return LoginResponse(AbstractResponse.STATUS_ERROR, LoginResponse.LOGIN_STATUS_FAILED)\n }\n \n private fun getCsrf(): String {\n val document = Jsoup.parse(Http.get(\"https://x.mirm.jp/login\"))\n return document.select(\"input[name=_csrf]\").attr(\"value\") // CSRFトークンを返す\n }\n }\n \n```\n\n```\n\n object Http {\n \n private const val USER_AGENT = \"MiRmGo/0.0.1\"\n private val client: OkHttpClient\n private val headers: Headers\n \n init {\n val cookieHandler = CookieManager(PersistentCookieStore(MyApplication.getApplication()), CookiePolicy.ACCEPT_ALL)\n \n client = OkHttpClient.Builder()\n .cookieJar(JavaNetCookieJar(cookieHandler))\n .addNetworkInterceptor(StethoInterceptor())\n .build()\n \n headers = Headers.Builder()\n .set(\"Accept\", \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\")\n .set(\"User-agent\", USER_AGENT)\n .set(\"Accept-Language\", \"ja,en-US;q=0.9,en;q=0.8\")\n .set(\"Connection\", \"keep-alive\")\n .set(\"Referer\", \"https://x.mirm.jp/login\")\n .set(\"Origin\", \"https://x.mirm.jp\")\n .build()\n }\n \n fun postXWwwFormUrlEncoded(url: String, data: Map<String, String>): String? {\n val postData = data.let {\n var str = \"\"\n it.forEach {\n str += \"${it.key}=${URLEncoder.encode(it.value, StandardCharsets.UTF_8.name())}&\"\n }\n str.removeSuffix(\"&\")\n }\n \n val requestBody = RequestBody.create(MediaType.parse(\"application/x-www-form-urlencoded\"), postData)\n val request = Request.Builder()\n .url(url)\n .headers(headers)\n .header(\"Content-Length\", postData.length.toString())\n .header(\"Content-Type\", \"application/x-www-form-urlencoded\")\n .post(requestBody)\n .build()\n val response = client.newCall(request).execute()\n \n if (!response.isSuccessful) throw MissingRequestException(response.code())\n return response.body()?.string()\n }\n \n fun get(url: String, data: Map<String, String> = mapOf()): String? {\n var postUrl = url\n \n if (data.isNotEmpty()) {\n postUrl += \"?\"\n data.forEach {\n postUrl += \"${it.key}=${it.value}&\"\n }\n postUrl = postUrl.removeSuffix(\"&\")\n }\n \n val request = Request.Builder()\n .url(postUrl)\n .headers(headers)\n .build()\n val response = client.newCall(request).execute()\n \n if (!response.isSuccessful) throw MissingRequestException(response.code())\n return response.body()?.string()\n }\n }\n \n```\n\nAndroid7 /login \n[![Android7\n/login](https://i.stack.imgur.com/CPRBU.png)](https://i.stack.imgur.com/CPRBU.png)\n\nAndroid7 /authenticate \n[![Android7\n/authenticate](https://i.stack.imgur.com/ldIog.png)](https://i.stack.imgur.com/ldIog.png)\n\nAndroid10 /login \n[![Android10\n/login](https://i.stack.imgur.com/825z9.png)](https://i.stack.imgur.com/825z9.png)\n\nAndroid10 /authenticate \n[![Android10\n/authenticate](https://i.stack.imgur.com/FLAun.png)](https://i.stack.imgur.com/FLAun.png)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T15:48:48.947", "favorite_count": 0, "id": "65961", "last_activity_date": "2020-04-26T03:59:01.000", "last_edit_date": "2020-04-26T00:36:07.463", "last_editor_user_id": "32986", "owner_user_id": "30610", "post_type": "question", "score": 1, "tags": [ "android", "http", "cookie" ], "title": "Android7ではSet-Cookieが動作するがAndroid10では動作しない", "view_count": 332 }
[ { "body": "`Set-Cookie: (...) ; HttpOnly` 核心はこれでしょうね。\n\nAndroid 9 (API28) から HTTP はデフォルトで無効化されます。[公式:フレームワーク\nセキュリティの変更](https://developer.android.com/about/versions/pie/android-9.0-changes-28?hl=ja#framework-\nsecurity-changes)\n\n従って、\n\n 1. サーバー側の動作仕様を、HttpOnly の Cookie に依存しないように修正する\n\nまたは\n\n 2. クライアントアプリ(Android 9 以上)側では、デフォルトの動作を変更して、「[公式:アプリで特定のドメインのクリアテキストを有効にする](https://developer.android.com/training/articles/security-config?hl=ja)」要するに、特定サイトに対して例外的に HTTP を許可する\n\n必要があります。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T03:59:01.000", "id": "65975", "last_activity_date": "2020-04-26T03:59:01.000", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7290", "parent_id": "65961", "post_type": "answer", "score": 1 } ]
65961
null
65975
{ "accepted_answer_id": null, "answer_count": 1, "body": "タイトルがわかりづらくすみません\n\n# 知りたいこと\n\n下記リンク先にある、くら寿司のメニュー画像から \n<http://www.kura-corpo.co.jp/menu-cp/img/menu-index-pc-01.jpg>\n\n・各商品(まぐろ | サーモン | いくら...)ごとに \n・文字列(まぐろ | 100円 | 提供エリア:全店舗 | 持ち帰り:可) \n・画像(商品ごとの寿司の画像) \nを生成するなら、 \n・ **どういったライブラリ** を使って、 \n・ **どう認識したり、どう切り抜いたり** \nすると楽に実装できそうか、教えてほしいです。\n\n[![各商品ごとに切り抜いたイメージ](https://i.stack.imgur.com/R0Ljl.jpg)](https://i.stack.imgur.com/R0Ljl.jpg)\n\n# これを作ろうと思ったきっかけ\n\n家族で寿司を注文するときに、 \n誰が何を何個頼む を 紙にメモしたりするのが面倒であるために、 \n楽に集計できるシステムを作りたいと思ったからです。\n\n# 動作イメージ\n\n**1日ごと** に、Pythonスクリプトを実行すると、リンク先画像から、 \n・画像認識(?) \n・文字起こし(?) \n・パース,整形 \nして、以下のようなテーブルに \n・INSERT, UPDATE \nするようなものを想像しています。\n\n```\n\n +----+-------------+-------+------+------------------+\n | id | name | price | erea | jpg_path |\n +----+-------------+-------+------+------------------+\n | 1 | maguro | 108 | all | hoge/maguro.jpg |\n | 2 | salmon | 108 | all | hoge/salmon.jpg |\n | 3 | ikura | 108 | all | hoge/ikura.jpg |\n | 4 | new_sushiA | 108 | all | null |\n ...\n \n```\n\n# 最終的には\n\nPythonスクリプトでテーブルが毎日更新される \n(新商品があればレコードを追加し、 \nもとの商品は特に更新しない)ので、 \nそれをもとに、htmlを生成し、 \n商品をタップするとカウントが1増えたりする(Javascript?) \nようなWebサイトを作りたいです\n\n# なぜ修羅の道を進もうとするのか\n\nうちの近くにあるのが **くら寿司だけ** だからです\n\n普通、商品ごとにhtmlの要素が分かれていて、 \nbeautifulsoup4みたいなのを使って、パースして、 \n文字列やら画像やら収集すると思いますが、 \nくら寿司はそうではなかったので、やってみようと思いました。\n\n## 調べてみたこと\n\n## 聞いてみたいと思ったこと\n\nOpenCVで人の顔を検出するだとか、 \n輪郭を検出するような方法はあったのですが、\n\nOpenCVでは、今回のような \n文字列を認識したり、 \n商品ごとの画像を切り抜いたり \n・するのには向いているのか \n・他によいライブラリはないのか\n\n例えば、 \n白背景と茶色背景でくっきり色が分かれているから、 \n・以外と簡単に認識できる方法があるよとか、 \n・画像編集ソフトで切りぬけばすぐだよとか、\n\n画像認識のことは忘れて、 \n一定の長さごとにぶつ切りにした方がいいとか\n\n画像からは文字起こしすればいいよとか\n\nそういった意見をお聞きしたいです。 \n初質問ですが、よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T17:13:27.090", "favorite_count": 0, "id": "65963", "last_activity_date": "2020-04-25T17:45:05.253", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "37120", "post_type": "question", "score": 0, "tags": [ "python", "python3", "opencv" ], "title": "Pythonを使って、リンク先のメニュー画像から、商品ごとの画像と文字列を生成するにはどうすればいいか", "view_count": 96 }
[ { "body": "やや質問の範囲が広いように感じますが、ひとまず \"考え方の方針\" を回答してみたいと思います。\n\nメニューの画像をよく見れば、個々の商品ごとに文字の位置は決まっているようなので、OCRを使う場合でも切り分けてしまえば良さそうです。\n\n下記サイトではOCRエンジンの「Tesseract」、これを扱うPythonモジュールの「PyOCR」を使ったOCRの方法が紹介されています。認識の精度を高めるために画像の一部を切り抜く方法も言及されているので、これらを応用すればやりたいことは実現できそうな気がします。\n\n[PythonでOCRを実行する方法](https://gammasoft.jp/blog/ocr-by-python/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T17:45:05.253", "id": "65964", "last_activity_date": "2020-04-25T17:45:05.253", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "65963", "post_type": "answer", "score": 1 } ]
65963
null
65964
{ "accepted_answer_id": null, "answer_count": 1, "body": "「VSCodeのターミナルでプログラムの実行中にエラーが発生した際、通知音を鳴らす」という設定をすることは可能でしょうか。\n\n(例:PythonでSeleniumを動かしている際にselenium.common.exceptions.WebDriverExceptionエラーが発生した際に、通知音を鳴らす)\n\nSeleniumによる自動作業をさせているのですが、時々エラーが生じた際にそれに気づくことが遅れるため、その解決のためこの質問をさせていただいてます。見える所にターミナル置いて気づけ等は無しでお願いします。\n\n環境:Windows 10", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-25T21:50:27.530", "favorite_count": 0, "id": "65966", "last_activity_date": "2020-04-27T00:56:25.550", "last_edit_date": "2020-04-27T00:56:25.550", "last_editor_user_id": "19110", "owner_user_id": "39812", "post_type": "question", "score": 3, "tags": [ "vscode" ], "title": "VSCodeのターミナルでエラー時に通知音を設定するには?", "view_count": 1468 }
[ { "body": "この場合「VSCodeのターミナル」は単に「Seleniumを動かしている」Pythonプログラムを起動しているだけで特に連携している訳ではないのでは?\n\nつまり、「VSCodeのターミナル」が「Pythonプログラムの動作を監視して何かアクションする」とか、「Pythonプログラム」が「VSCodeのターミナルへ何か通知してアクションを取ってもらう」といったことでは無く、「Seleniumを動かしているPythonプログラムが例外発生時に単独でエラー音を鳴らす」だけで良いと思われます。\n\nそうした場合にこの記事が応用できるのではないでしょうか? \n[windowsのGUIからpython呼び出す時のエラー通知方法というかwinsound.Beep](https://qiita.com/noexpect/items/382ee6bdb3b718aa838a)\n\n> windowsのpythonで例外が上がった時だけ音を鳴らすようにしてみた。\n```\n\n> import winsound\n> \n> def hoge():\n> # 何か例外が起きる\n> \n> if __name__ == '__main__':\n> try:\n> hoge()\n> except:\n> winsound.Beep(400, 200)\n> \n```\n\n>\n> **経緯** \n>\n> windowsでエクスプローラーなどGUIから、.batよろしくpythonのスクリプトファイルを単発で起動することがある。その時、実行時だけはシェルウインドウが開いて標準出力が表示され、処理が終わったら閉じたりする。 \n>\n> 問題として、スクリプトが異常終了した時もシェルウィンドウは閉じてしまい、標準エラー出力などが見れない。(エラーは表示されるけど即シェルウィンドウは閉じてしまう) \n> すると、正常終了なのか、異常終了なのかがわからない。 \n> 私は以下な感じでTablacus Exporerからpythonスクリプトを直に呼び出してたりするので、この問題に出くわした。\n>\n> **何がいいのか? というかやりたかったこと**\n>\n> これだと音がなったらなんか問題あるな?とわかるので、あとはIDEなり開いて好きにデバックすればいいなと。\n\n**追記:**\n\nコメントでは`winsound.Beep()`では鳴らなかったが、以下記事を基に`winsound.PlaySound()`を使えば出来たようです。`wav`ファイルを用意して任意の音を鳴らせたとか。 \n[Pythonのwinsoundで音楽再生する方法を現役エンジニアが解説【初心者向け】](https://techacademy.jp/magazine/20870)\n\n> カレントディレクトリに音声ファイル`sample.wav`があるものとします。\n```\n\n> import winsound\n> \n> with open('sample.wav', 'rb') as f:\n> data = f.read()\n> \n> winsound.PlaySound(data, winsound.SND_MEMORY)\n> \n```\n\n上記が出来るなら、システムで用意されている`wav`ファイルを使用する`winsound.MessageBeep()`が使えるかもしれません。 \n[winsound.MessageBeep(type = MB_OK\n)](https://docs.python.org/3.9/library/winsound.html#winsound.MessageBeep) \n元のAPIとパラメータはこちら [MessageBeep function](https://docs.microsoft.com/en-\nus/windows/win32/api/winuser/nf-winuser-messagebeep)\n\n他にはエスケープシーケンス`\\a`によるアラート音の鳴動があるようです。 \nただしIDEの中だと駄目だったりするようですが。 \n[Play simple beep with python without external\nlibrary](https://stackoverflow.com/q/4467240/9014308)\n\n> So `sys.stdout.write(\"\\a\")` might be better.\n\n[How to make a sound in OSX using python\n3](https://stackoverflow.com/q/42150309/9014308)\n\n>\n```\n\n> import sys\n> sys.stdout.write('\\a')\n> sys.stdout.flush()\n> \n```\n\n>\n> Acutually,`sys.stdout.write('\\a')` works for me,but not in IDE,try to run\n> this code in **Terminal**.You will hear the system sound. \n> 実際には`sys.stdout.write('\\a')`機能しますが、IDE では機能しません。このコードを **ターミナル**\n> で実行してみてください。システムサウンドが聞こえます。\n\n* * *\n\nWindows以外だと、この辺の記事の内容で置き換えれば出来るでしょう。 \n[[Python] ビープ音を鳴らす(Windows/Mac対応)](https://www.yoheim.net/blog.php?q=20180313)\n\n> ビープ音はWindowsとMacでそれぞれ実現方式が違うので、`platform.system()`で環境別に実装します。\n```\n\n> def beep(freq, dur=100):\n> \"\"\"\n> ビープ音を鳴らす.\n> @param freq 周波数\n> @param dur 継続時間(ms)\n> \"\"\"\n> if platform.system() == \"Windows\":\n> # Windowsの場合は、winsoundというPython標準ライブラリを使います.\n> import winsound\n> winsound.Beep(freq, dur)\n> else:\n> # Macの場合には、Macに標準インストールされたplayコマンドを使います.\n> import os\n> os.system('play -n synth %s sin %s' % (dur/1000, freq))\n> \n> // 2000Hzで500ms秒鳴らす\n> beep(2000, 500)\n> \n```\n\n実は`play`はMacOSの`SoX`というパッケージに入っているようです。 \n下記Linux系記事のコメントに以下のようにあります。\n\n> On MacOS you can install sox via ports (sudo port install sox). Sox contain\n> the play command. \n> MacOSでは、ポートを介してsoxをインストールできます(sudo port install\n> sox)。Soxには、playコマンドが含まれています。\n\nLinux系でも使えるかもしれません。 \n[play(1) - Linux man page](https://linux.die.net/man/1/play)\n\n[Python: what are the nearest Linux and OSX equivalents of\nwinsound.Beep?](https://stackoverflow.com/q/12354586/9014308)\n\n> However, you can try the os.system command to do the same with the system\n> command\n> [beep](https://www.chiark.greenend.org.uk/~sgtatham/utils/beep.html). Here\n> is a snippet, which defines the function playsound in a platform independent\n> way \n>\n> ただし、os.systemコマンドを試して、システムコマンドbeepで同じことを行うことができます。これは、プラットフォームに依存しない方法で関数playsoundを定義するスニペットです\n```\n\n> try:\n> import winsound\n> except ImportError:\n> import os\n> def playsound(frequency,duration):\n> #apt-get install beep\n> os.system('beep -f %s -l %s' % (frequency,duration))\n> else:\n> def playsound(frequency,duration):\n> winsound.Beep(frequency,duration)\n> \n```\n\nLinux系の記事です。MacOS同様、`beep`もインストールする必要があるかもしれません。\n\n> You will need to install the beep package on linux to run the beep command.\n> You can install by giving the command \n> ビープコマンドを実行するには、ビープパッケージをLinuxにインストールする必要があります。コマンドを与えることでインストールできます\n```\n\n> sudo apt-get install beep\n> \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T02:32:21.933", "id": "65971", "last_activity_date": "2020-04-27T00:12:59.547", "last_edit_date": "2020-04-27T00:12:59.547", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "65966", "post_type": "answer", "score": 1 } ]
65966
null
65971
{ "accepted_answer_id": "65983", "answer_count": 2, "body": "お世話になっております。 \nバッチファイルでは「^」記号でコマンドや変数等を複数行にわけて入力することができます。 \nしかし、この際、ダブルクォーテーションがあるとエラーとなってしまいます。 \n一応サンプルのバッチファイルを掲載します。\n\n```\n\n @echo off\n set ProgramPath=C:\\Program Files\\example\\test.exe\n set var1=あいうえお\n set var2=かきくけこ\n set runcmd=^\n \"%ProgramPath%\" ^\n /var1=\"%var1%\" ^\n /var2=\"%var2%\"\n echo \"running %runcmd%\"\n pause\n \n```\n\nこれを実行すると、下記のようにエラーが出力され、うまく実行することができません。\n\n```\n\n '/var1' は、内部コマンドまたは外部コマンド、\n 操作可能なプログラムまたはバッチ ファイルとして認識されていません。\n \"running \"C:\\Program Files\\example\\test.exe\" ^\"\n \n```\n\n環境は、Windows10 1909 64ビットです。 \n何かよい対処法はないでしょうか。 \nアドバイスいただけますと幸いです。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T01:24:56.860", "favorite_count": 0, "id": "65968", "last_activity_date": "2020-04-26T06:54:35.623", "last_edit_date": "2020-04-26T06:54:35.623", "last_editor_user_id": "3060", "owner_user_id": "29034", "post_type": "question", "score": 1, "tags": [ "windows", "batch-file" ], "title": "バッチファイルで変数を複数行にわけて指定したときのダブルクォーテーションの指定について", "view_count": 3466 }
[ { "body": "スマートとは言えませんが、単なる環境変数の編集なので、1度にやろうとせず順次追記していけば良いのではないでしょうか? \n%PATH%の編集(追記)と同じ考え方ですね。\n\n```\n\n set runcmd=\"%ProgramPath%\"\n set runcmd=%runcmd% /var1=\"%var1%\"\n set runcmd=%runcmd% /var2=\"%var2%\"\n \n```\n\n`echo \"running %runcmd%\"`の結果は以下のようになります。\n\n```\n\n \"running \"C:\\Program Files\\example\\test.exe\" /var1=\"あいうえお\" /var2=\"かきくけこ\"\"\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T01:54:00.470", "id": "65969", "last_activity_date": "2020-04-26T01:54:00.470", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "65968", "post_type": "answer", "score": 1 }, { "body": "BATファイルで見栄えを良くしようというのは諦めた方がいいです。ですので無理に改行を入れるよりは1行で記述すべきです。 \nその上で`^`がうまく機能しない件については、行頭に空白を入れると良さそうです。\n\n```\n\n @echo off\n set ProgramPath=C:\\Program Files\\example\\test.exe\n set var1=あいうえお\n set var2=かきくけこ\n set runcmd=^\n \"%ProgramPath%\"^\n /var1=\"%var1%\"^\n /var2=\"%var2%\"\n echo \"running %runcmd%\"\n pause\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T06:25:48.760", "id": "65983", "last_activity_date": "2020-04-26T06:25:48.760", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "65968", "post_type": "answer", "score": 0 } ]
65968
65983
65969
{ "accepted_answer_id": null, "answer_count": 1, "body": "dockerを用いてrailsアプリケーションを開発しようとしているところです。\n\ndocker-compose run web rails db:migrate \nを実行しデータベースが作成されたことまでは確認できましたがlocalhost:3000へアクセスをしたところ、以下のように表示されました。\n\n```\n\n このページは動作していませんlocalhost からデータが送信されませんでした。\n ERR_EMPTY_RESPONSE\n \n```\n\n想定として、railsアプリケーションのデフォルトページが表示されることを期待しております。\n\nどなたかアドバイスをいただけたらと思います。\n\n* * *\n\n**docker-compose.yml**\n\n```\n\n version: '3'\n services:\n db:\n image: postgres\n environment:\n POSTGRES_USER: 'postgresql'\n POSTGRES_PASSWORD: 'postgresql-pass'\n restart: always\n web:\n build: .\n command: bundle exec rails s -p 3000 -b '0.0.0.0'\n volumes:\n - .:/myapp\n ports:\n - \"3000:3000\"\n depends_on:\n - db\n \n```\n\n**Dockerfile**\n\n```\n\n FROM ruby:2.3.3\n RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs\n RUN mkdir /myapp\n WORKDIR /myapp\n COPY Gemfile /myapp/Gemfile\n COPY Gemfile.lock /myapp/Gemfile.lock\n RUN bundle install\n COPY . /myapp\n \n```\n\n* * *\n\n**試したこと**\n\n`http://0.0.0.0:3000` でアクセス → 変化なし\n\n`http://127.0.0.1:3000` でアクセス → 変化なし\n\n`docker-compose run web rails s` すでに存在していた\n\n`docker-compose exec web bash` にて仮想環境に入り下記コマンドを打ったところ \n標準のHTMLファイルが取得できたため、仮想環境内だと正常に動作しているようです。\n\n```\n\n curl localhost:3000\n \n 〜〜〜\n <h1>Yay! You&rsquo;re on Rails!</h1>\n 〜〜〜\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T02:06:11.277", "favorite_count": 0, "id": "65970", "last_activity_date": "2022-04-19T08:05:20.490", "last_edit_date": "2020-04-26T07:14:10.610", "last_editor_user_id": "3060", "owner_user_id": "39658", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "docker", "docker-compose" ], "title": "Rails + docker-compose localhostへアクセスができない", "view_count": 752 }
[ { "body": "swarmクラスタを別で構築しておりそれが邪魔していました。 \ndocker swarm leave --force コマンドでswarmクラスタから抜けて再度docker up\n-dを実行したところ正常に動作いたしました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T15:31:27.870", "id": "66003", "last_activity_date": "2020-04-26T15:31:27.870", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39658", "parent_id": "65970", "post_type": "answer", "score": 1 } ]
65970
null
66003
{ "accepted_answer_id": "66009", "answer_count": 2, "body": "閲覧いただきありがとうございます。\n\n## エラーが生じた経緯\n\ngoogle\ncolaboratory上で作成し動作確認をしたコードをローカル環境の仮想マシン上で実行したところ、タイトルのとおりエラーが生じてしまいました。\n\n## やりたいこと\n\nPythonスクリプトからGoogle Sheets APIを利用しスプレッドシートにアクセスする\n\nSheetsAPIを利用する上で同時に必要となるGoogle DriveのAPIも利用しています。 \nSheetsAPIの認証にはサービスアカウントキーを利用し、秘密鍵のjsonファイルを.pyファイルと同じディレクトリに配置しております。 \nスプレッドシート側において共有設定も済ませています。\n\n## ローカルの実行環境\n\nWindowsマシン上にVagrantで構築したCentOS \nPython 3.5.2\n\n## 問題のコード writeToSheets.py\n\n```\n\n import gspread\n from oauth2client.service_account import ServiceAccountCredentials\n import json\n import pandas as pd\n \n SP_CREDENTIAL_FILE = 'pittustatsroyale-a37bcb54c774.json'\n SP_SCOPE = [\n 'https://www.googleapis.com/auth/drive',\n 'https://spreadsheets.google.com/feeds'\n ]\n SP_SHEET_KEY = '1_zyQWw_Kwn1nhLfsjHlm2baxH9CUweqPo6kZ38dcwo4'\n SP_SHEET = 'pittu'\n \n credentials = ServiceAccountCredentials.from_json_keyfile_name(SP_CREDENTIAL_FILE,SP_SCOPE)\n gc = gspread.authorize(credentials)\n workbook = gc.open_by_key(SP_SHEET_KEY)\n worksheet = workbook.worksheet(SP_SHEET)\n data = worksheet.get_all_values()\n \n```\n\n## 実行時のエラーメッセージ\n\n```\n\n [vagrant@localhost pittuStatsRoyale]$ python writeToSheets.py\n Traceback (most recent call last):\n File \"writeToSheets.py\", line 17, in <module>\n worksheet = workbook.worksheet(SP_SHEET)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/gspread/models.py\", line 314, in worksheet\n sheet_data = self.fetch_sheet_metadata()\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/gspread/models.py\", line 263, in fetch_sheet_metadata\n r = self.client.request('get', url, params=params)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/gspread/client.py\", line 67, in request\n headers=headers\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/requests/sessions.py\", line 543, in get\n return self.request('GET', url, **kwargs)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/auth/transport/requests.py\", line 442, in request\n self.credentials.before_request(auth_request, method, url, request_headers)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/auth/credentials.py\", line 124, in before_request\n self.refresh(request)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/oauth2/service_account.py\", line 334, in refresh\n access_token, expiry, _ = _client.jwt_grant(request, self._token_uri, assertion)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/oauth2/_client.py\", line 153, in jwt_grant\n response_data = _token_endpoint_request(request, token_uri, body)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/oauth2/_client.py\", line 124, in _token_endpoint_request\n _handle_error_response(response_body)\n File \"/home/vagrant/.pyenv/versions/3.5.2/lib/python3.5/site-packages/google/oauth2/_client.py\", line 60, in _handle_error_response\n raise exceptions.RefreshError(error_details, response_body)\n google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.', '{\"error\":\"invalid_grant\",\"error_description\":\"Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.\"}')\n \n```\n\n## 試したこと\n\nファイルのパスなど、環境の移行に応じてコード内で変更が必要な箇所はできる限り精査しました。 \n16行目までは正常に実行できていると確認しましたので、スプレッドシートにはアクセスできていますが、具体的なシートを選択する段階で問題が生じているのではないかと原因を調査しました。\n\n## 分からないこと\n\n・Google Colaboratoryとローカル開発環境の違い。前者で実行できたコードを後者の環境で実行する場合に必要となる変更事項はあるか。\n\n・gspreadライブラリを利用している場合において、worksheet()呼び出しに起因するエラーが生じた場合、どのようなケースが存在するのか。\n\n## コードの作成において参考にしたもの\n\n・Colab上での実行で参考にした動画 \n<https://www.youtube.com/watch?v=uBy7F4Wd9cE>\n\n・ローカルでの実行で参考にしたサイト \n<https://tanuhack.com/operate-spreadsheet/#i-6> \n<https://tanuhack.com/library-gspread/#i-2>\n\n## 助力いただけますよう、よろしくお願いいたします\n\n初めてこちらで質問させていただきました。至らぬ点ございましたらご不便をかけします。ご指摘いただけたら幸いです。何卒よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T03:51:12.453", "favorite_count": 0, "id": "65973", "last_activity_date": "2020-04-27T01:21:59.257", "last_edit_date": "2020-04-26T06:22:46.710", "last_editor_user_id": "39816", "owner_user_id": "39816", "post_type": "question", "score": 0, "tags": [ "python", "google-api", "google-spreadsheet", "google-colaboratory" ], "title": "gspreadライブラリのworksheet()実行時に生じたエラーが解決できません。", "view_count": 1782 }
[ { "body": "改めて……\n\nSP_SCOPE の順番を入れ替えて\n\n```\n\n SP_SCOPE = [\n 'https://spreadsheets.google.com/feeds',\n 'https://www.googleapis.com/auth/drive'\n ]\n \n```\n\nとしたらどうでしょうか?\n\nエラーの出ている部分とは違うのですが、私自身のテストコード、[公式ドキュメント](https://gspread.readthedocs.io/en/latest/oauth2.html#for-\nbots-using-service-account)、参考にされたリンクを見ても、そこくらいしか違いが見当りませんでした。", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T04:24:19.047", "id": "65976", "last_activity_date": "2020-04-26T13:52:56.973", "last_edit_date": "2020-04-26T13:52:56.973", "last_editor_user_id": "7290", "owner_user_id": "7290", "parent_id": "65973", "post_type": "answer", "score": 0 }, { "body": "エラーメッセージ末尾に\n\n```\n\n google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT: Token must be a \n short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp \n values in the JWT claim.', '{\"error\":\"invalid_grant\",\"error_description\":\"Invalid JWT: \n Token must be a short-lived token (60 minutes)\n \n```\n\nとあるように \n仮想マシンCentOS上の時刻設定が現時刻よりも遅れてズレていることが原因でした。 \nCentOSのコマンドライン上でnpt関連の設定を行うことで解消しました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T01:21:59.257", "id": "66009", "last_activity_date": "2020-04-27T01:21:59.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39816", "parent_id": "65973", "post_type": "answer", "score": 0 } ]
65973
66009
65976
{ "accepted_answer_id": null, "answer_count": 0, "body": "```\n\n import re\n \n source = 'english_words.txt'\n \n with open(source) as f:\n data = f.read()\n \n print(data)\n \n```\n\nと入力してテキストファイルを読み込もうと思ったら、\n\n```\n\n UnicodeDecodeError Traceback (most recent call last)\n <ipython-input-1-724186bfb095> in <module>\n 4 \n 5 with open(source) as f:\n ----> 6 data = f.read()\n 7 \n 8 print(data)\n \n UnicodeDecodeError: 'cp932' codec can't decode byte 0x88 in position 19: illegal multibyte sequence\n \n```\n\nとエラーが出てしまい、読み込めませんでした。環境はjupyter Notebookです。\n\nテキストファイルの中身は、\n\n```\n\n a double line\n 二列\n a far cry from \n ~とはほど遠い\n a walk of life\n 職業\n ・・・\n ・・・\n \n```\n\nというように英語と日本語が交互に入っています。 \nどうすれば解決できますか?\n\n<編集>\n\n```\n\n # -*- coding: utf-8 -*-\n import re\n \n source = 'english_words.txt'\n \n with open(source, \"w\", encoding=\"utf-8\") as f:\n data = f.read()\n \n print(data)\n \n```\n\nというように書き換えて実行してみましたが、今度は別のエラーが出てしまいました\n\n```\n\n UnsupportedOperation Traceback (most recent call last)\n <ipython-input-3-d1531ad10560> in <module>\n 5 \n 6 with open(source, \"w\", encoding=\"utf-8\") as f:\n ----> 7 data = f.read()\n 8 \n 9 print(data)\n \n UnsupportedOperation: not readable\n \n```", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T03:56:15.523", "favorite_count": 0, "id": "65974", "last_activity_date": "2020-04-26T04:26:01.117", "last_edit_date": "2020-04-26T04:26:01.117", "last_editor_user_id": "39563", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "python", "python3", "テキストファイル" ], "title": "pythonでtxtファイルが読み込めません", "view_count": 706 }
[]
65974
null
null
{ "accepted_answer_id": "65978", "answer_count": 2, "body": "`:` は記法の一つで、与えられるデータタイプを意味していると分かりましたが、 \n一番右の `-> List[int]` の意味が分かりません。\n\n```\n\n class Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T05:24:35.563", "favorite_count": 0, "id": "65977", "last_activity_date": "2020-04-26T07:09:02.153", "last_edit_date": "2020-04-26T07:09:02.153", "last_editor_user_id": "3060", "owner_user_id": "36091", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "パラメーターの表記法について", "view_count": 68 }
[ { "body": "戻り値の型を表しています。intのListで返るということですね。\n\n[typing --- 型ヒントのサポート](https://docs.python.org/ja/3/library/typing.html)\n\n> バージョン 3.5 で追加. \n> 以下の関数は文字列を受け取って文字列を返す関数で、次のようにアノテーションがつけられます:\n```\n\n> def greeting(name: str) -> str:\n> return 'Hello ' + name\n> \n```\n\n>\n> 関数 greeting で、実引数 name の型は str であり、返り値の型は str\n> であることが期待されます。サブタイプも実引数として許容されます。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T05:41:32.967", "id": "65978", "last_activity_date": "2020-04-26T05:41:32.967", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "26370", "parent_id": "65977", "post_type": "answer", "score": 1 }, { "body": "関数の戻り値に対する型ヒントとなります \n詳細は下記のリンクを参照してください。\n\n<https://www.python.org/dev/peps/pep-3107/#return-values>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T05:42:26.720", "id": "65980", "last_activity_date": "2020-04-26T05:42:26.720", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24801", "parent_id": "65977", "post_type": "answer", "score": 1 } ]
65977
65978
65978
{ "accepted_answer_id": "65981", "answer_count": 3, "body": "以下のようなテキストの奇数行(英語の部分)のみを取り出してそれぞれ、同じリストの別の要素として収めたいです。どのようにすればいいでしょうか。\n\n```\n\n a double line\n 二列\n a far cry from \n ~とはほど遠い\n a walk of life\n 職業\n abandon\n ~を捨てる\n ・・・\n ・・・\n ・・・\n \n```\n\n```\n\n # -*- coding: utf-8 -*-\n import re\n \n source = 'english_words.txt'\n \n with open(source, \"r\", encoding=\"utf-8\") as f:\n data = f.read()\n \n \n english_words = re.findall('[a-z]+', data)\n ja = re.findall('\\n.*\\n',data)\n \n jp_meanings = []\n for word in ja:\n m = re.sub('\\n','',word)\n jp_meanings.append(m)\n \n words_dict = dict(zip(english_words,jp_meanings))\n \n print(jp_meanings)\n \n```\n\n現在のコードはこんな感じです。re.findallでは熟語の空白で要素がかわってしまい、うまくいかなかったので、行ごとに読み込むことにしました。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T05:41:40.283", "favorite_count": 0, "id": "65979", "last_activity_date": "2020-04-26T07:03:55.740", "last_edit_date": "2020-04-26T07:03:55.740", "last_editor_user_id": "3060", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "python", "テキストファイル" ], "title": "Pythonでテキストから奇数行をリストにしたい", "view_count": 854 }
[ { "body": "行毎に処理するだけなら正規表現は不要ですね。以下のようにできます。 \n(ついでに前後の空白も削除しておきます。ちなみにsplitlines()は改行コード混在もOKです)\n\n```\n\n # -*- coding: utf-8 -*-\n source = 'english_words.txt'\n \n with open(source, 'r', encoding='utf-8') as f:\n data = f.read().splitlines()\n english_words = [l.strip() for i, l in enumerate(data) if ((i%2) == 0)]\n jp_meanings = [l.strip() for i, l in enumerate(data) if ((i%2) != 0)]\n \n words_dict = dict(zip(english_words,jp_meanings))\n \n print(data)\n print(english_words)\n print(jp_meanings)\n print(words_dict)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T06:21:23.523", "id": "65981", "last_activity_date": "2020-04-26T06:41:09.913", "last_edit_date": "2020-04-26T06:41:09.913", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "65979", "post_type": "answer", "score": 0 }, { "body": "ファイルから奇数行だけ抽出する原始的な方法を示します。もっと華麗な方法があるのかもしれませんが。\n\n```\n\n >>> file = open(\"c:\\\\temp\\\\test.txt\",\"r\")\n >>> number_of_line = 1\n >>> line = file.readline()\n >>> while line:\n ... if number_of_line %2 == 1:\n       ★2で割って1余る場合に出力\n ... print(line)\n ... number_of_line += 1\n ... line = file.readline()\n ...\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T06:22:59.577", "id": "65982", "last_activity_date": "2020-04-26T06:22:59.577", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10174", "parent_id": "65979", "post_type": "answer", "score": 0 }, { "body": "皆さんがいくつか回答しておられますが、私も作ってみたので、載せておきます。 \nかなり原始的ですが、while分でループして追加しているだけです。 \n少し追記した点として、改行コードが混在してもいいように、改行コードを統一しています。\n\n```\n\n import re\n \n source = 'test.txt'\n with open(source, \"r\", encoding=\"utf-8\") as f:\n data = f.read()\n data = re.sub(r'\\r\\n|\\r|\\n', '\\n', data)\n array = data.split(\"\\n\")\n english_words = []\n jp_meanings = []\n i = 0\n while i < len(array):\n english_words.append(array[i])\n jp_meanings.append(array[i+1])\n i += 2\n words_dict = dict(zip(english_words,jp_meanings))\n print(words_dict)\n print(english_words)\n print(jp_meanings)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T06:30:08.753", "id": "65984", "last_activity_date": "2020-04-26T06:30:08.753", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29034", "parent_id": "65979", "post_type": "answer", "score": 0 } ]
65979
65981
65981
{ "accepted_answer_id": null, "answer_count": 1, "body": "python経験暦3ヶ月の人です。何回も書き直しても\n\n```\n\n python nameerror name 'ture' is not defined\n \n```\n\nと表示されてしまいます。\n\nちなみにこのパソコンはWindows7なのですが、そのことが関係しますか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T07:17:17.257", "favorite_count": 0, "id": "65987", "last_activity_date": "2020-04-27T05:25:30.650", "last_edit_date": "2020-04-26T08:45:59.837", "last_editor_user_id": "3060", "owner_user_id": "39821", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "プログラム実行時「python nameerror name 'ture' is not defined」と表示されてしまう原因は何ですか?", "view_count": 819 }
[ { "body": "スペルが間違っているのと最初の`t`が大文字でないからでは? `True`に変えてみてください。\n\n**追記:**\n\n以下のように過去に同様の質問が有ったようです。 \n[pythonプログラム実行時に「NameError: name 'true' is not\ndefined」とエラーになってしまう](https://ja.stackoverflow.com/q/44160/26370)\n\n* * *\n\n本当にこの名前`ture`という何かを使いたかったのであれば、事前に定義や初期化していない状態で値を代入しようとしたり、関数やメソッドのパラメータに指定しようとした可能性が考えられます。\n\nエラーメッセージ自身はもっと行数があるはずで、そこにソースコードの何行目(更には何桁目)で発生しているか、といった情報が出ているはずです。\n\n実行しようとしているソースコードや使用しているテストデータと、発生しているエラーメッセージの全てを質問記事に追記してみてください。\n\nそれらが巨大で掲載するのが大変ならば、問題を再現できる状態で最小限のサイズまで削減してから追記してみてください。\n\n案外そうした作業中に自分で原因を特定出来たりするものです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T07:29:32.033", "id": "65989", "last_activity_date": "2020-04-27T05:25:30.650", "last_edit_date": "2020-04-27T05:25:30.650", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "65987", "post_type": "answer", "score": 1 } ]
65987
null
65989
{ "accepted_answer_id": "65990", "answer_count": 1, "body": "以下のコードを書いて英単語テストを作ろうとしたのですが、エラーが出てしまいました。 \nどうすれば解決するのでしょうか。環境はjupyter Notebook です。\n\n**エラーメッセージ**\n\n```\n\n AttributeError Traceback (most recent call last)\n <ipython-input-16-60260a1521a9> in <module>\n 19 with open('英単語テスト_{:02d}.txt'.format(test_num +1),'w') as f:\n 20 \n ---> 21 f.write一('第{}回英単語テスト\\n\\n'.format(test_num +1))\n 22 \n 23 for question_num in range(n_questions):\n \n AttributeError: '_io.TextIOWrapper' object has no attribute 'write一'\n \n```\n\n**コード**\n\n```\n\n # -*- coding: utf-8 -*-\n import re\n import random\n \n source = 'english_words.txt'\n \n with open(source, 'r', encoding='utf-8') as f:\n data = f.read().splitlines()\n english_words = [l.strip() for i, l in enumerate(data) if ((i%2) == 0)]\n jp_meanings = [l.strip() for i, l in enumerate(data) if ((i%2) != 0)]\n \n words_dict = dict(zip(english_words,jp_meanings))\n \n print(words_dict)\n \n n_tests = 5\n n_questions = 50\n for test_num in range(n_tests):\n with open('英単語テスト_{:02d}.txt'.format(test_num +1),'w') as f:\n \n f.write一('第{}回英単語テスト\\n\\n'.format(test_num +1))\n \n for question_num in range(n_questions):\n question_word = random_choice(english_words)\n correct_answer = words_dict[question_word]\n \n meanings_copy = meanings.copy()\n meanings_copy.remove(correct_answer)\n wrong_answers = random.sample(meanings_copy,3)\n \n answer_options = [correct_answer] + wrong_answers\n \n random.shuffle(answer_options)\n \n f.write('問{}. {}\\n\\n'.format(question_num + 1,question_word))\n \n for i in range(4):\n f.write('{}.{}\\n'.format(i + 1, answer_options[i]))\n f.write('\\n\\n')\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T07:28:06.183", "favorite_count": 0, "id": "65988", "last_activity_date": "2020-04-26T07:54:50.007", "last_edit_date": "2020-04-26T07:51:03.233", "last_editor_user_id": "3060", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "'write一 アトリビュートがない' とエラーになってしまう", "view_count": 260 }
[ { "body": "> `f.write一('第{}回英単語テスト\\n\\n'.format(test_num +1))`\n\nメソッド名が間違ってますね `write一`", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T07:31:02.467", "id": "65990", "last_activity_date": "2020-04-26T07:54:50.007", "last_edit_date": "2020-04-26T07:54:50.007", "last_editor_user_id": "32986", "owner_user_id": "27481", "parent_id": "65988", "post_type": "answer", "score": 1 } ]
65988
65990
65990
{ "accepted_answer_id": "65993", "answer_count": 1, "body": "以下のように入力して作ったファイルに英単語テストを書きたかったのですが、生成したテキストファイルを開いてみたらエラーが出ていました。\n\nこの場合どうしたら対応できるのでしょうか。環境はJupyter Notebookです。\n\n**エラーメッセージ**\n\n```\n\n Error! C:\\Users\\Ryotaro Arakawa\\programming\\英単語テスト_01.txt is not UTF-8 encoded\n Saving disabled.\n See Console for more details.\n \n```\n\n**ソースコード**\n\n```\n\n # -*- coding: utf-8 -*-\n import re\n import random\n \n source = 'english_words.txt'\n \n with open(source, 'r', encoding='utf-8') as f:\n data = f.read().splitlines()\n english_words = [l.strip() for i, l in enumerate(data) if ((i%2) == 0)]\n jp_meanings = [l.strip() for i, l in enumerate(data) if ((i%2) != 0)]\n \n words_dict = dict(zip(english_words,jp_meanings))\n \n print(words_dict)\n \n n_tests = 5\n n_questions = 50\n for test_num in range(n_tests):\n with open('英単語テスト_{:02d}.txt'.format(test_num +1),'w') as f:\n \n f.write('第{}回英単語テスト\\n\\n'.format(test_num +1))\n \n for question_num in range(n_questions):\n question_word = random.choice(english_words)\n correct_answer = words_dict[question_word]\n \n meanings_copy =jp_meanings.copy()\n meanings_copy.remove(correct_answer)\n wrong_answers = random.sample(meanings_copy,3)\n \n answer_options = [correct_answer] + wrong_answers\n \n random.shuffle(answer_options)\n \n f.write('問{}. {}\\n\\n'.format(question_num + 1,question_word))\n \n for i in range(4):\n f.write('{}.{}\\n'.format(i + 1, answer_options[i]))\n f.write('\\n\\n')\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T08:10:01.833", "favorite_count": 0, "id": "65991", "last_activity_date": "2020-04-26T08:54:20.987", "last_edit_date": "2020-04-26T08:15:39.487", "last_editor_user_id": "19110", "owner_user_id": "39563", "post_type": "question", "score": 1, "tags": [ "python", "python3", "文字コード" ], "title": "作ったテキストファイルに文字が入らない", "view_count": 202 }
[ { "body": "まずはエラーメッセージのとおりに、書き込み用ファイルの`open`時にも`encoding='utf-8'`を指定してみましょう。 \nこれを:\n\n```\n\n with open('英単語テスト_{:02d}.txt'.format(test_num +1),'w') as f:\n \n```\n\nこうしてみてください。\n\n```\n\n with open('英単語テスト_{:02d}.txt'.format(test_num +1),'w',encoding='utf-8') as f:\n \n```\n\nそれと、エラーメッセージに`See Console for more details.`とあるので、Jupyter\nNotebookのConsoleに何かメッセージが出ているでしょう。 \nそちらも読み取って質問に追記してみてください。 \nその内容によっては別の対処が必要になるかもしれません。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T08:54:20.987", "id": "65993", "last_activity_date": "2020-04-26T08:54:20.987", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "65991", "post_type": "answer", "score": 1 } ]
65991
65993
65993
{ "accepted_answer_id": null, "answer_count": 0, "body": "# 問題点\n\nFirebaseのAnalyticsを使ったコードを実行したところ、次の様なエラーが表示され、画面が表示されませんでした。\n\n```\n\n 2020-04-26 19:59:56.713197+0900 ShrineApp2[3548:1604575] - <AppMeasurement>[I-ACS036001] Analytics screen reporting is disabled. UIViewController transitions will not be logged.\n 2020-04-26 19:59:57.123631+0900 ShrineApp2[3548:1604575] 6.22.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60401000 started\n 2020-04-26 19:59:57.124085+0900 ShrineApp2[3548:1604575] 6.22.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)\n 2020-04-26 19:59:57.143741+0900 ShrineApp2[3548:1604588] 6.22.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement\n 2020-04-26 19:59:57.156748+0900 ShrineApp2[3548:1604588] 6.22.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled\n \n```\n\n# 試したこと\n\n私のinfo.plist内で、FirebaseScreenReportingEnabledを逆にYESに設定したところ、以下のエラーが表示され、画面が表示されませんでした。\n\n```\n\n 2020-04-26 20:12:53.585528+0900 ShrineApp2[3552:1609111] 6.22.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist\n 2020-04-26 20:12:53.610520+0900 ShrineApp2[3552:1609111] 6.22.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60401000 started\n 2020-04-26 20:12:53.610666+0900 ShrineApp2[3552:1609111] 6.22.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)\n 2020-04-26 20:12:53.635436+0900 ShrineApp2[3552:1609114] 6.22.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement\n 2020-04-26 20:12:53.649835+0900 ShrineApp2[3552:1609115] 6.22.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement\n 2020-04-26 20:12:53.661723+0900 ShrineApp2[3552:1609111] 6.22.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled\n \n```\n\nどの様にすればエラーを消せるでしょうか、ご教示お願いします。\n\n最初に表示するViewControllerのコードは以下の通りです。\n\n```\n\n import UIKit\n \n class ViewController: UINavigationController {\n \n override func viewDidLoad() {\n super.viewDidLoad()\n self.navigationController?.isNavigationBarHidden = true\n \n // Do any additional setup after loading the view.\n }\n \n \n @IBAction func managerLogin(_ sender: Any) {\n performSegue(withIdentifier: \"managerlogin\", sender: nil)\n }\n \n @IBAction func createAcount(_ sender: Any) {\n performSegue(withIdentifier: \"create\", sender: nil)\n }\n \n @IBAction func userLogin(_ sender: Any) {\n performSegue(withIdentifier: \"userlogin\", sender: nil)\n \n }\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T11:16:07.487", "favorite_count": 0, "id": "65995", "last_activity_date": "2020-04-27T01:59:12.820", "last_edit_date": "2020-04-27T01:59:12.820", "last_editor_user_id": "39825", "owner_user_id": "39825", "post_type": "question", "score": 0, "tags": [ "swift", "xcode", "firebase" ], "title": "FirebaseAnalyticsを使うと、使うなというエラーが、使わないと、画面指定してないというエラーが出ます。", "view_count": 622 }
[]
65995
null
null
{ "accepted_answer_id": null, "answer_count": 0, "body": "Ubuntu20.04ISOをダウンロードしてUSBにメディアを作ってフォーマットしたSSDにインストールしようとしたのですが、 \nおよそ80%の確率でブートしたあと画面を表示できずブラックアウトします。 \n20%の確率で何故かBootモード(Ubuntu installやUbuntu safe Graphic install、Try\nubuntuなどの選択肢が出てくる画面)にはたどり着け、Safe\nGraphicモードでインストールに進むと問題なくインストール出来るのですが、終了後、インストールメディアを取り外してリブートするとブート後に即ブラックアウトします。\n\n```\n\n CPU:Ryzen9 3900X\n GPU:NVIDIA RTX2080ti\n SSD:Crucial\n \n```\n\nおそらくRTXカードの問題だと思うのですが、手元に差し替えて試せる古いGPUがなく、困っています。\n\nDockerしか使ったことがないので想像でしかないのですが、Vagrantを使うとISOをCLIで開いてNVIDIAドライバーだけ追加してから再度ISO化してインストールメディアを作る。。。といったような事が出来たりしますでしょうか? \nまたはNVIDIAドライバがすでに入っているISOが配布されていたりする場所など、、何か解決法をご存知の方が入れば教えていただけると助かります。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T12:17:23.593", "favorite_count": 0, "id": "65996", "last_activity_date": "2020-04-26T13:30:34.577", "last_edit_date": "2020-04-26T13:30:34.577", "last_editor_user_id": "19110", "owner_user_id": "39826", "post_type": "question", "score": 0, "tags": [ "linux", "ubuntu", "vagrant", "gpu" ], "title": "Ubuntu20.04 LTSをインストールしてもブラックアウトする", "view_count": 1525 }
[]
65996
null
null
{ "accepted_answer_id": "66000", "answer_count": 2, "body": "コード\n\n```\n\n l=[\"Mon\",\"tue\",\"Wed\",\"sat\"]\n \n for i in range(len(l)):\n print(i) \n l[i] = l[i].upper()\n print(i)\n print(l)\n \n```\n\n上のコードにおいて、1つ目のprint(i)では結果が「0,1,2,3」と出ますが、2つ目のprint(i)では結果が「3」とのみ出ます。この二つの違いはなんでしょうか?\n\n結果を以下に示します。よろしくお願いします。\n\n```\n\n 0\n 1\n 2\n 3\n 3\n ['MON', 'TUE', 'WED', 'SAT']\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T12:33:00.460", "favorite_count": 0, "id": "65997", "last_activity_date": "2020-04-26T13:15:48.127", "last_edit_date": "2020-04-26T12:37:00.777", "last_editor_user_id": "3060", "owner_user_id": "39688", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "for i in rangeについての質問", "view_count": 101 }
[ { "body": "違い:ループの内か外か\n\n1つ目の print(i) は for ループの内側にある。→ ループに伴って i = 0, 1, 2, 3\n\n2つ目の print(i) は for ループの外側にある。→ ループが止った最後の状態の i がそのまま使われる。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T13:08:12.390", "id": "65999", "last_activity_date": "2020-04-26T13:08:12.390", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7290", "parent_id": "65997", "post_type": "answer", "score": 2 }, { "body": "結論から言えば2つの「print(i)」に違いはありません。\n\n```\n\n for i in range(len(l)):\n ★iの中に0から配列lのサイズまでループする。つまりiは0,1,2,3が入ってくる\n print(i)\n ★iの内容を標準出力に出力する。前述の通り、iは0,1,2,3とループ内で変更させるので\n 0\n 1\n 2\n 3 \n と表示される。この時iの値は最終的に3が入っていることに注意\n print(i) \n ★前述の通りループは終了し、i=3のままこの処理を実行するので、3が出力される。\n 面白いのは、iの変数スコープってforの中で切れてないんですね。。。エラー返してくれたほうがわかりやすいのに。。\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T13:15:48.127", "id": "66000", "last_activity_date": "2020-04-26T13:15:48.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10174", "parent_id": "65997", "post_type": "answer", "score": 2 } ]
65997
66000
65999
{ "accepted_answer_id": "66035", "answer_count": 1, "body": "VagrantとCentOS7環境下にてRuby及びRailsをインストールしたいと思っています。 \n[前回](https://ja.stackoverflow.com/questions/65954/rbenv-\ninstall-2-7-1%E3%81%A7%E3%82%A8%E3%83%A9%E3%83%BC-mkdir-cannot-create-\ndirectory-usr-local-rbenv-versio)、失敗したため詳しい手順をご存知の方がいましたら順序立ててご教示いただけますと幸いです。\n\n追記\n\n下記のコマンドまで進みましたが \nエラーが出ました。原因がわかりません。。。\n\n```\n\n [vagrant@localhost ~]$ rbenv install 2.7.1\n Downloading ruby-2.7.1.tar.bz2...\n -> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2\n Installing ruby-2.7.1...\n \n BUILD FAILED (CentOS Linux 7 using ruby-build 20200401-9-g3ef704e)\n \n Inspect or clean up the working tree at /tmp/ruby-build.20200427052059.2195.A64Isy\n Results logged to /tmp/ruby-build.20200427052059.2195.log\n \n Last 10 log lines:\n from ./tool/rbinstall.rb:846:in `block (2 levels) in install_default_gem'\n from ./tool/rbinstall.rb:279:in `open_for_install'\n from ./tool/rbinstall.rb:845:in `block in install_default_gem'\n from ./tool/rbinstall.rb:835:in `each'\n from ./tool/rbinstall.rb:835:in `install_default_gem'\n from ./tool/rbinstall.rb:799:in `block in <main>'\n from ./tool/rbinstall.rb:950:in `block in <main>'\n from ./tool/rbinstall.rb:947:in `each'\n from ./tool/rbinstall.rb:947:in `<main>'\n make: *** [do-install-all] Error 1\n \n```", "comment_count": 12, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T12:51:28.010", "favorite_count": 0, "id": "65998", "last_activity_date": "2020-04-27T13:35:21.310", "last_edit_date": "2020-04-27T09:51:30.293", "last_editor_user_id": "32986", "owner_user_id": "39719", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "centos", "vagrant" ], "title": "VagrantとCentOS7環境下でRuby及びRailsをインストールしたい。", "view_count": 422 }
[ { "body": "公式のGetting Started, [4.1 Starting up the Web\nServer](https://guides.rubyonrails.org/getting_started.html#starting-up-the-\nweb-server)で `rails server`コマンドを実行し、 \"Yay! You’re on\nRails!\"のページが表示されるところまで確認しました:\n\n```\n\n sudo yum -y update\n sudo yum -y groupinstall \"Development Tools\"\n sudo yum -y install gdbm-devel openssl-devel readline-devel zlib-devel\n \n # SQLite >= 3.8 インストール(ここでは最新版の3.31.1をインストール)\n # https://www.sqlite.org/download.html\n curl -s https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz | tar xz -C /tmp\n cd /tmp/sqlite-autoconf-3310100\n ./configure --prefix=/usr/local\n make\n sudo make install\n \n # nodejs v12(LTS) インストール\n # https://nodejs.org/ja/download/package-manager/#debian-and-ubuntu-based-linux-distributions-enterprise-linux-fedora-and-snap-packages より\n # https://github.com/nodesource/distributions/blob/master/README.md#rpminstall\n curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -\n sudo yum -y install nodejs\n \n # yarn インストール\n # https://classic.yarnpkg.com/en/docs/install/#centos-stable\n curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo\n sudo yum -y install yarn\n \n # rbenv, rbenv-build インストール\n # https://github.com/rbenv/rbenv#basic-github-checkout\n git clone https://github.com/rbenv/rbenv.git ~/.rbenv\n cd ~/.rbenv && src/configure && make -C src\n echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bash_profile\n echo 'eval \"$(rbenv init -)\"' >> ~/.bash_profile\n source ~/.bash_profile\n mkdir -p \"$(rbenv root)\"/plugins\n git clone https://github.com/rbenv/ruby-build.git \"$(rbenv root)\"/plugins/ruby-build\n \n # ruby インストール\n rbenv install 2.7.1\n rbenv global 2.7.1\n \n # sqlite3 最新版利用設定\n # https://url4u.jp/centos7-rails6-sqlite3/\n bundle config build.sqlite3 \"--with-sqlite3-lib=/usr/local/lib\"\n \n # rails インストール\n # https://guides.rubyonrails.org/getting_started.html#installing-rails\n gem install rails\n \n```\n\n[サンプル`Vagrantfile`](https://github.com/yukihane/stackoverflow-\nqa/tree/master/so65998)\n\n* * *\n\n質問へのコメントでも示唆されていますが、質問文中にあるエラーはビルドに必要なライブラリが不足しているためで、何が不足しているかはエラーログに出力されています。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T13:24:21.170", "id": "66035", "last_activity_date": "2020-04-27T13:35:21.310", "last_edit_date": "2020-04-27T13:35:21.310", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "65998", "post_type": "answer", "score": 2 } ]
65998
66035
66035
{ "accepted_answer_id": null, "answer_count": 3, "body": "ディスクイメージのファイルフォーマットとして、.iso が拡張子なものと .img が拡張子なものをよく見かけます。\n\n例:\n\n * .iso: [Ubuntu Desktop 日本語 Remix](https://www.ubuntulinux.jp/download/ja-remix)\n * .img: [Raspbian](https://www.raspberrypi.org/downloads/raspbian/)\n\nこれらはどう違うのでしょうか?\n\nたとえば[英語版 Wikipedia](https://en.wikipedia.org/wiki/IMG_\\(file_format\\)) には\n\n> ISO images are another type of optical disc image files, which commonly use\n> the `.iso` file extension, but sometimes use the `.img` file extension as\n> well.\n\nと書かれており、とすると同じファイルフォーマットを指していそうな気がするのですが、具体的にこのことを示した規格やマニュアルなどはありますか? 同じページにて\n.img\nが他のいくつかのファイルフォーマットの拡張子としても使われているようにとれる記述もあり、やや混乱しています。たとえば自分でディスクイメージを作る際、拡張子を選ぶ参考になるような情報が欲しいです。\n\n追記:なるべく出典が欲しいです。Wikipedia の記事もいくつか見たのですが、特に img\nファイルについてなかなかコレといった出典がありませんでした。歴史的経緯により成り立っていったファイルフォーマットということであればなかなか出典となるような文献を見つけるのが難しいのかもしれません……。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T14:25:28.150", "favorite_count": 0, "id": "66001", "last_activity_date": "2020-11-15T03:03:55.277", "last_edit_date": "2020-04-27T00:45:38.447", "last_editor_user_id": "19110", "owner_user_id": "19110", "post_type": "question", "score": 2, "tags": [ "バイナリファイル" ], "title": "iso と img の違いはなんですか?", "view_count": 4290 }
[ { "body": "* ISO ファイルは国際標準化機構 (ISO) の定義した **光学メディア向け** のアーカイブフォーマット。\n\n * IMG ファイルはフロッピーディスクに始まるバックアップを単一のファイルにまとめるためのフォーマット。現在はハードディスクなどのイメージファイル作成にも使用される。\n\nISOはCDなどの光学ディスクをまとめたもの、IMGは(CD含めた)より広い範囲のバックアップイメージ、といった印象です。\n\n質問に書かれているUbuntu等のディストリビューションは基本的にCD/DVDに焼き付ける事を前提としたISOイメージを配布しますが、Raspbian等のRasPi向けディストリビューションは\n**SDカード** を使用するため、IMGファイルとして配布しているのではないでしょうか。\n\nなお、最近のUbuntuはUSBにも直接書き込める \"ハイブリッドISO\" という形式を採用しています。\n\nまた、IMGファイルについては [参考サイト](https://ja.computersm.com/36-what-are-the-differences-\nbetween-iso-and-img-files-41625) に以下のような記述もありました。\n\n> ISOフォーマットには1つのバージョンしかありませんが、IMGには2つのバージョンがあります。 \n> 圧縮と非圧縮です。\n\n**参考:** \n[ISOイメージ -\nWikipedia](https://ja.wikipedia.org/wiki/ISO%E3%82%A4%E3%83%A1%E3%83%BC%E3%82%B8) \n[ISOファイルとIMGファイルの違いは何ですか?](https://ja.computersm.com/36-what-are-the-\ndifferences-between-iso-and-img-files-41625)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T15:31:36.023", "id": "66004", "last_activity_date": "2020-04-26T15:31:36.023", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "66001", "post_type": "answer", "score": -1 }, { "body": "規格があるかは確認できてないですが、一般的には\n\n * `.iso`の拡張子のファイルは、CDROM、DVDROM等、光学メディアのイメージファイル\n * `.img`の拡張子のファイルは、SDカード、USBディスク等、ディスクのイメージファイル\n\nという使い分けになっていると思います。\n\n* * *\n\n`.iso`については、[英語版WikipediaのISO image](https://en.wikipedia.org/wiki/ISO_image)の \nページに説明があります。\n\nWikipediaより引用:\n\n> An ISO image is a disk image of an optical disc. In other words, it is an\n> archive file that contains everything that would be written to an optical\n> disc, sector by sector, including the optical disc file system. \n> ISO image files bear the `.iso` filename extension.\n\n#歴史的経緯から予想すると、[`mkisofs`のマニュアル](https://linux.die.net/man/8/mkisofs)の実行例で、出力ファイル名を「`cd.iso`」と記載していたので、慣用的に広まったものと思います。\n\nマニュアルより引用:\n\n> To create a vanilla ISO-9660 filesystem image in the file cd.iso, where the\n> directory cd_dir will become the root directory if the CD, call:\n>\n> `% mkisofs -o cd.iso cd_dir`\n\n* * *\n\n一方、`.img`ファイルは、[英語版WikipediaのIMG(file\nformat)](https://en.wikipedia.org/wiki/IMG_\\(file_format\\))には、「元々フロッピーディスクイメージファイルの拡張子」と記載があります。\n\nWikepediaより引用:\n\n> The `.img` file extension was originally used for floppy disk raw disk\n> images only.\n\nただ、フロッピーディスクは使われなくなったため、現在は「raw disk\nimages」の意味合いが流用されて、起動可能なディスクイメージファイル全般を指すようになっていると思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T16:00:02.230", "id": "66005", "last_activity_date": "2020-04-26T16:00:02.230", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20098", "parent_id": "66001", "post_type": "answer", "score": 3 }, { "body": ".iso は ISO9660 を意味していると思います。 \n.img は デバイスのバイト列をそのままファイルに書き込んだ イメージファイルのことだと思います。\n\n> とすると同じファイルフォーマットを指していそうな気がするのですが\n\nUNIX系のシステムでは拡張子にはほとんど意味がありませんので、単なるファイル名の一部だと思ってください。したがって 拡張子で判断することは出来ません。\n\nただ、.img は何かしらのデバイスのイメージファイルと言う意味で、より広義の捉え方が出来ますので、そういった解釈も成り立つと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T17:00:42.217", "id": "66006", "last_activity_date": "2020-04-26T17:00:42.217", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "66001", "post_type": "answer", "score": 0 } ]
66001
null
66005
{ "accepted_answer_id": null, "answer_count": 1, "body": "ffmpegの-filter_complexの中身を読み解いて自分で応用したいと思っていますが、Googleで調べてもわかりません。\n\n> -filter_complex\n> '[v:0]hwupload=extra_hw_frames=64,split=4[o1][o2][o3][o4],[o1]vpp_qsv=cw=1920:ch=1080:cx=0:cy=0[out1],[out1]split=3[r11][r12][r13],[r12]scale_qsv=w=1280:h=720[ro12],[r13]scale_qsv=w=960:h=540[ro13],[o2]vpp_qsv=cw=1920:ch=1080:cx=1920:cy=0[out2],[out2]split=3[r21][r22][r23],[r22]scale_qsv=w=1280:h=720[ro22],[r23]scale_qsv=w=960:h=540[ro23],[o3]vpp_qsv=cw=1920:ch=1080:cx=0:cy=1080[out3],[out3]split=3[r31][r32][r33],[r32]scale_qsv=w=1280:h=720[ro32],[r33]scale_qsv=w=960:h=540[ro33],[o4]vpp_qsv=cw=1920:ch=1080:cx=1920:cy=1080[out4],[out4]split=3[r41][r42][r43],[r42]scale_qsv=w=1280:h=720[ro42],[r43]scale_qsv=w=960:h=540[ro43]'\n\n4Kでキャプチャーしたものをqsv処理するのですが、\n\n 1. hwupload=extra_hw_frames=64 とは何の処理をしている?\n 2. vpp_qsv, scale_qsvとは?\n 3. split=4[o1][o2][o3][o4]の4は何を指定しているのでしょうか?\n\nこのようなfilter_complexの中で使われる処理は皆さんは何を見て調べているのでしょうか。 \nご教示いただけると助かります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T15:22:00.177", "favorite_count": 0, "id": "66002", "last_activity_date": "2020-04-27T04:10:54.033", "last_edit_date": "2020-04-26T15:35:02.910", "last_editor_user_id": "3060", "owner_user_id": "8593", "post_type": "question", "score": 0, "tags": [ "ffmpeg" ], "title": "ffmpegのfilter_complexの中身を読み解きたい", "view_count": 836 }
[ { "body": "> hwupload=extra_hw_frames=64 とは何の処理をしている?\n\n[hwuploadフィルタ](https://ffmpeg.org/ffmpeg-\nfilters.html#hwupload-1)によりGPUサーフェイスへの映像転送を指示しています。 \n[extra_hw_frameオプション](https://github.com/FFmpeg/FFmpeg/blob/n4.2.2/libavfilter/avfilter.c#L635-L636)はメモリ確保するフレーム枚数です。\n\n> vpp_qsv, scale_qsvとは?\n\n * [vpp_qsv](https://github.com/FFmpeg/FFmpeg/blob/n4.2.2/libavfilter/vf_vpp_qsv.c):QSVを利用した汎用画像フィルタ。ここでは画像切り抜き(crop)処理を行っています。\n * [scale_qsv](https://github.com/FFmpeg/FFmpeg/blob/n4.2.2/libavfilter/vf_scale_qsv.c):QSVを利用した画像スケーリング(サイズ変更)フィルタ。\n\n> split=4[o1][o2][o3][o4]の4は何を指定しているのでしょうか?\n\n[splitフィルタ](https://ffmpeg.org/ffmpeg-\nfilters.html#split_002c-asplit)の分岐出力数です。入力映像を4分岐し、それぞれに o1,... o4\nのラベルを付与しています。\n\n* * *\n\n> このようなfilter_complexの中で使われる処理は皆さんは何を見て調べているのでしょうか。\n\n基本的には[公式オンラインマニュアル](https://www.ffmpeg.org/ffmpeg-\nfilters.html)をあたりますが、必要に応じて[ソースコード](https://github.com/FFmpeg/FFmpeg/)も参照しています。 \n今回のようにハードウェア・アクセラレーション系はドキュメント整備が不十分なようですから、ソースコードを確認したほうが早いことが多そうです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T04:10:54.033", "id": "66012", "last_activity_date": "2020-04-27T04:10:54.033", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "49", "parent_id": "66002", "post_type": "answer", "score": 3 } ]
66002
null
66012
{ "accepted_answer_id": null, "answer_count": 1, "body": "会社でバージョン管理を行うため、AzureDevOpsを構築しています。 \nそこでユーザーのSSHキーの登録があるのですが、このSSHキーは最初にAzureDevOpsからローカルにクローンするときのみ使用されるものですか? \nそれともクローン後も安全性を保つために使用されていますか? \nSSHキーを登録してもしなくてもクローンができ、pushなども普通にできてしまうので \nセキュリティ的に大丈夫なのかと不安になりました。 \nそのため \n・AzureDevOpsでのSSHキーのクローン時以外の役割はあるか \n・SSHキーを登録する場合としない場合のサーバの安全性の違い\n\nについて教えていただけませんか。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-26T21:25:30.963", "favorite_count": 0, "id": "66008", "last_activity_date": "2021-06-27T04:18:09.740", "last_edit_date": "2021-06-27T04:18:09.740", "last_editor_user_id": "3060", "owner_user_id": "39713", "post_type": "question", "score": 0, "tags": [ "visual-studio", "ssh", "azure", "openssh" ], "title": "AzureDevOpsのSSHキーの役割について", "view_count": 133 }
[ { "body": "SSHという語は、Secure\nSHell(安全な(secure)はシェル(shell))に由来していて、ネットワークを経由して他のマシンの操作を安全に操作できるようにする仕組みの事です。 \n「安全に」というのは、ネットワークを流れる情報が暗号化されているので、情報を盗み見したり、情報を書き換えたりすることが困難だという意味です。\n\nSSHキーは、情報の暗号化・復号化(暗号化されたデータを元に戻すこと)につかう情報です。\n\nSSHはマシン間の通信を安全にするための仕組みで、様々な操作(DevOps関連の操作、メール送受、ファイル転送、等々)において盗聴、データ改ざん、乗っ取りなどを防ぐ効果があります。\n\nSSHキーがないということは、SSHを使っていないということですから、盗聴などをされる危険な状態にあるということです。 \nちゃんとSSHキーを設定して、安全に運用できるシステムにすべきです。\n\n== \n例えば、二人の人が銀行に大金を預金しに行くとします。 \nAさんは現金輸送車をつかって銀行に行きます。 \nBさんは札束を透明なビニールバッグに入れて歩いて銀行に行きます。 \nどちらも、銀行で預金することに変わりはありませんが、Bさんのほうが強盗にある可能性は高いですよね。\n\nSSHを使うと現金輸送車を使うと強盗などに合いにくい、使わないと強盗などに合いにくい、という訳で安全性で差がありますが、それを使って行われる事(銀行で預金する、借金を払いに行く、等々)によってSSHが変わるわけではありません。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T05:13:11.253", "id": "66019", "last_activity_date": "2020-04-27T05:13:11.253", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "66008", "post_type": "answer", "score": 0 } ]
66008
null
66019
{ "accepted_answer_id": "66134", "answer_count": 1, "body": "Xcodeやドキュメントでうまく調べる方法についてご質問です。\n\nプロトコルを準拠しているクラスか調べる方法はありますでしょうか?\n\n例えば、`Color構造体`が`ShapeStyleプロトコル`に準拠しておりますが、`Developer\nDocumation`を開いて右側にある`Relationships`をクリックしても`ShapeStyle`が見つかりませんでした。\n\nおそらく基底クラスで準拠していると思います。コードエディタから`Jump to Definition`して追っていくしか方法はないのでしょうか?\n\n基底クラスを含めて簡単に調べることを出来ると助かります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T04:34:01.890", "favorite_count": 0, "id": "66013", "last_activity_date": "2020-04-30T01:42:23.037", "last_edit_date": "2020-04-27T06:44:04.130", "last_editor_user_id": "36965", "owner_user_id": "36965", "post_type": "question", "score": 0, "tags": [ "swift", "xcode" ], "title": "プロトコルを準拠しているクラスか調べる方法", "view_count": 145 }
[ { "body": "基底クラスと書く時にどのように書いたらいいか迷って書きました。ご指摘ありがとうございます。やはりドキュメントに記載がないだけの様子なんですね。要望を報告してみたいと思います。ご回答ありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-30T01:42:23.037", "id": "66134", "last_activity_date": "2020-04-30T01:42:23.037", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36965", "parent_id": "66013", "post_type": "answer", "score": 0 } ]
66013
66134
66134
{ "accepted_answer_id": null, "answer_count": 1, "body": "最近、[テキストエディタ](https://github.com/vivisuke/openViVi)を開発しているのですが、ビューにフォーカスがあるとき、Tab\nキーを押すとフォーカスが別のウィジェットに移ってしまい、Tab文字を挿入することができません。 \nタブによるフォーカス移動を禁止する設定みたいなものがあったはずなのですが、それを思い出せません。 \n具体的にどうすればタブキーによるフォカース移動を禁止できるのか、ご教授いただけると助かります。\n\n開発環境:Windows 10, Visual Studio 2019, C++, Qt5.14", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T04:39:28.843", "favorite_count": 0, "id": "66014", "last_activity_date": "2020-04-27T04:51:47.767", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3431", "post_type": "question", "score": 0, "tags": [ "c++", "qt", "qt5" ], "title": "Tab を押すとフォーカスが切り替わるのを禁止したい", "view_count": 134 }
[ { "body": "ビューウィジェットで bool focusNextPrevChild(bool next); を再実装し、 \nfalse を返すとフォーカス移動が禁止され、keyPressEvent() がちゃんとコールされるようです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T04:51:47.767", "id": "66016", "last_activity_date": "2020-04-27T04:51:47.767", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3431", "parent_id": "66014", "post_type": "answer", "score": 0 } ]
66014
null
66016
{ "accepted_answer_id": "66020", "answer_count": 1, "body": "## 質問内容\n\n左側のメニューのlabelを押すと、右側のメインメニューが干渉して動き、灰色の背景が現れます。 \n原因は分かりましたが、理由と対処法がわかりません。 \nよろしくお願いします。 \n[jsfiddle](https://jsfiddle.net/akatsuki1910/oh67vk8m/)\n\n## コード\n\n```\n\n <!DOCTYPE html>\n <html lang=\"en\">\n \n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Document</title>\n <link rel=\"stylesheet\" href=\"style.css\">\n </head>\n \n <body>\n <div class=\"main-all-wrap\">\n <div class=\"index-all-wrap\">\n <div class=\"profile\">\n <div class=\"profile-box\">\n <img src=\"#\" class=\"trim-image-to-circle\">\n <div class=\"pro-name\">a</div>\n <div class=\"pro-text\">\n afa\n </div>\n <div class=\"pro-link\">\n <a href=\"#\"><i class=\"fab fa-twitter-square\"></i></a>\n <a href=\"#\"><i class=\"fab fa-facebook\"></i></a>\n <a href=\"#\"><i class=\"fab fa-instagram-square\"></i></a>\n </div>\n </div>\n <div class=\"pro-menu\">\n <label for=\"menu_bar1\">label1</label>\n <input type=\"checkbox\" id=\"menu_bar1\">\n <ul id=\"links1\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n <label for=\"menu_bar2\">label2</label>\n <input type=\"checkbox\" id=\"menu_bar2\">\n <ul id=\"links2\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n <label for=\"menu_bar3\">label3</label>\n <input type=\"checkbox\" id=\"menu_bar3\">\n <ul id=\"links3\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n <label for=\"menu_bar4\">label4</label>\n <input type=\"checkbox\" id=\"menu_bar4\">\n <ul id=\"links4\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n <label for=\"menu_bar5\">label5</label>\n <input type=\"checkbox\" id=\"menu_bar5\">\n <ul id=\"links5\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n <label for=\"menu_bar6\">label6</label>\n <input type=\"checkbox\" id=\"menu_bar6\">\n <ul id=\"links6\">\n <li><a href=\"#\">Link01</a></li>\n <li><a href=\"#\">Link02</a></li>\n </ul>\n </div>\n </div>\n <div class=\"main-contents-wrap\">\n <div class=\"contents-main\">\n <img src=\"#\">\n <div class=\"main-title\">{$maintitle}</div>\n <div class=\"sub-title\">{$subtitle}</div>\n <div class=\"sub-title\">{$subtitle}</div>\n <div class=\"main-text\">{$maintext}</div>\n <a href=\"#\" target=\"_self\"></a>\n </div>\n <div class=\"contents-main\">\n <img src=\"#\">\n <div class=\"main-title\">{$maintitle}</div>\n <div class=\"sub-title\">{$subtitle}</div>\n <div class=\"sub-title\">{$subtitle}</div>\n <div class=\"main-text\">{$maintext}</div>\n <a href=\"#\" target=\"_self\"></a>\n </div>\n </div>\n </div>\n </div>\n </body>\n \n </html>\n \n```\n\n```\n\n @mixin center() {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translateX(-50%) translateY(-50%);\n }\n \n @mixin flexcenter() {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n }\n \n $header-height:100px;\n $menu-box-wigth:400px;\n $pic-size-width:400px;\n $pic-size-height:300px;\n \n * {\n margin: 0;\n padding: 0;\n }\n \n html {\n height: 100%;\n }\n \n body {\n display: flex;\n flex-direction: column;\n height: 100vh;\n }\n \n .main-all-wrap {\n margin-top: $header-height;\n flex: 1 0 auto;\n }\n \n .index-all-wrap {\n display: flex;\n flex-direction: row;\n }\n \n $profile-width:25vmin;\n \n .profile {\n width: $profile-width;\n \n .profile-box {\n width: 100%;\n background-color: red;\n \n .trim-image-to-circle {\n width: calc(#{$profile-width} - 2px);\n height: calc(#{$profile-width} - 2px);\n border-radius: 50%;\n border: 1px solid black;\n }\n \n .pro-name {\n font-size: 2rem;\n }\n \n .pro-text {\n word-break: break-all;\n }\n \n .pro-link {\n font-size: 2rem;\n \n a {\n color: black;\n text-decoration: none;\n \n :visited,\n :hover {\n color: black;\n }\n }\n }\n }\n \n .pro-menu {\n width: $profile-width;\n \n a {\n display: block;\n padding: 15px;\n text-decoration: none;\n color: #000;\n }\n \n ul {\n margin: 0;\n padding: 0;\n background: #f4f4f4;\n list-style: none;\n }\n \n li {\n height: 0;\n overflow: hidden;\n transition: all 0.5s;\n }\n \n input {\n display: none;\n }\n \n label {\n display: block;\n margin: 0 0 4px 0;\n padding: 15px; //To Do 原因\n line-height: 1;\n color: #fff;\n background: green;\n cursor: pointer;\n }\n \n @for $i from 1 through 7 {\n #menu_bar#{$i}:checked~#links#{$i} li {\n height: calc(15px *2 + 1rem + 4px);\n opacity: 1;\n }\n }\n }\n }\n \n \n .main-contents-wrap {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: center;\n \n .contents-main {\n width: calc(100% - 20px);\n max-width: $pic-size-width + 200px;\n margin: 5px 10px;\n position: relative;\n background-color: #999999;\n display: grid;\n grid-template-rows: 20% 20% calc(#{$pic-size-width} - 40%);\n grid-template-columns: $pic-size-width 1fr;\n \n img {\n grid-row: 1 /span 3;\n grid-column: 1;\n min-width: $pic-size-width;\n max-width: $pic-size-width;\n min-height: $pic-size-height;\n max-height: $pic-size-height;\n object-fit: cover;\n background-color: black;\n }\n \n .main-title {\n grid-row: 1;\n grid-column: 2;\n font-size: 2rem;\n max-height: calc(#{$pic-size-height} * 0.2);\n position: relative;\n overflow: hidden;\n word-wrap: break-word;\n }\n \n .sub-title {\n grid-row: 2;\n grid-column: 2;\n font-size: large;\n max-height: calc(#{$pic-size-height} * 0.2);\n position: relative;\n overflow: hidden;\n word-wrap: break-word;\n }\n \n .main-text {\n grid-row: 3;\n grid-column: 2;\n max-height: calc(#{$pic-size-height} * 0.6);\n position: relative;\n overflow: hidden;\n word-wrap: break-word;\n }\n \n a {\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T05:11:12.527", "favorite_count": 0, "id": "66018", "last_activity_date": "2020-04-27T06:14:44.333", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "29881", "post_type": "question", "score": 0, "tags": [ "html", "css", "sass" ], "title": "Flexboxで隣り合う要素の高さが揃ってしまう", "view_count": 156 }
[ { "body": "質問文のコードを読むと、 `.profile` と `.main-contents-wrap` を横並びにするために `.index-all-wrap` で\n`display: flex` を使用しています。ここで、 flexbox で使用される `align-items` プロパティは\n**初期値が`stretch`** であるため、 `.profile` と `.main-contents-wrap` の **高さが自動的に揃えられる**\nとわかります。このため、メニューをクリックし、メニューの高さがメインコンテンツより大きくなると、メニューと高さを合わせるために、メインコンテンツに灰色の領域が生じます。\n\n以上から、この問題を解決するには、 `align-items` プロパティに対して `stretch`\n以外の値を適用すれば良いことになります。たとえば、以下のように `align-items: start` を適用すると問題が解消していることが確認出来ます。\n\n```\n\n .index-all-wrap {\n display: flex;\n flex-direction: row;\n align-items: start; // 追加\n }\n \n```\n\n```\n\n * {\r\n margin: 0;\r\n padding: 0;\r\n }\r\n \r\n html {\r\n height: 100%;\r\n }\r\n \r\n body {\r\n display: flex;\r\n flex-direction: column;\r\n height: 100vh;\r\n }\r\n \r\n .main-all-wrap {\r\n margin-top: 100px;\r\n flex: 1 0 auto;\r\n }\r\n \r\n .index-all-wrap {\r\n display: flex;\r\n flex-direction: row;\r\n align-items: start; /* 追加 */\r\n }\r\n \r\n .profile {\r\n width: 25vmin;\r\n }\r\n .profile .profile-box {\r\n width: 100%;\r\n background-color: red;\r\n }\r\n .profile .profile-box .trim-image-to-circle {\r\n width: calc(25vmin - 2px);\r\n height: calc(25vmin - 2px);\r\n border-radius: 50%;\r\n border: 1px solid black;\r\n }\r\n .profile .profile-box .pro-name {\r\n font-size: 2rem;\r\n }\r\n .profile .profile-box .pro-text {\r\n word-break: break-all;\r\n }\r\n .profile .profile-box .pro-link {\r\n font-size: 2rem;\r\n }\r\n .profile .profile-box .pro-link a {\r\n color: black;\r\n text-decoration: none;\r\n }\r\n .profile .profile-box .pro-link a :visited,\r\n .profile .profile-box .pro-link a :hover {\r\n color: black;\r\n }\r\n .profile .pro-menu {\r\n width: 25vmin;\r\n }\r\n .profile .pro-menu a {\r\n display: block;\r\n padding: 15px;\r\n text-decoration: none;\r\n color: #000;\r\n }\r\n .profile .pro-menu ul {\r\n margin: 0;\r\n padding: 0;\r\n background: #f4f4f4;\r\n list-style: none;\r\n }\r\n .profile .pro-menu li {\r\n height: 0;\r\n overflow: hidden;\r\n transition: all 0.5s;\r\n }\r\n .profile .pro-menu input {\r\n display: none;\r\n }\r\n .profile .pro-menu label {\r\n display: block;\r\n margin: 0 0 4px 0;\r\n padding: 15px;\r\n line-height: 1;\r\n color: #fff;\r\n background: green;\r\n cursor: pointer;\r\n }\r\n .profile .pro-menu #menu_bar1:checked ~ #links1 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar2:checked ~ #links2 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar3:checked ~ #links3 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar4:checked ~ #links4 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar5:checked ~ #links5 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar6:checked ~ #links6 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n .profile .pro-menu #menu_bar7:checked ~ #links7 li {\r\n height: calc(15px *2 + 1rem + 4px);\r\n opacity: 1;\r\n }\r\n \r\n .main-contents-wrap {\r\n width: 1fr;\r\n display: flex;\r\n flex-direction: row;\r\n flex-wrap: wrap;\r\n justify-content: center;\r\n }\r\n .main-contents-wrap .contents-main {\r\n width: calc(100% - 20px);\r\n max-width: 600px;\r\n margin: 5px 10px;\r\n position: relative;\r\n background-color: #999999;\r\n display: grid;\r\n grid-template-rows: 20% 20% calc(400px - 40%);\r\n grid-template-columns: 400px 1fr;\r\n }\r\n .main-contents-wrap .contents-main img {\r\n grid-row: 1/span 3;\r\n grid-column: 1;\r\n min-width: 400px;\r\n max-width: 400px;\r\n min-height: 300px;\r\n max-height: 300px;\r\n object-fit: cover;\r\n background-color: black;\r\n }\r\n .main-contents-wrap .contents-main .main-title {\r\n grid-row: 1;\r\n grid-column: 2;\r\n font-size: 2rem;\r\n max-height: calc(300px * 0.2);\r\n position: relative;\r\n overflow: hidden;\r\n word-wrap: break-word;\r\n }\r\n .main-contents-wrap .contents-main .sub-title {\r\n grid-row: 2;\r\n grid-column: 2;\r\n font-size: large;\r\n max-height: calc(300px * 0.2);\r\n position: relative;\r\n overflow: hidden;\r\n word-wrap: break-word;\r\n }\r\n .main-contents-wrap .contents-main .main-text {\r\n grid-row: 3;\r\n grid-column: 2;\r\n max-height: calc(300px * 0.6);\r\n position: relative;\r\n overflow: hidden;\r\n word-wrap: break-word;\r\n }\r\n .main-contents-wrap .contents-main a {\r\n position: absolute;\r\n top: 0;\r\n left: 0;\r\n height: 100%;\r\n width: 100%;\r\n }\n```\n\n```\n\n <!DOCTYPE html>\r\n <html lang=\"jp\">\r\n \r\n <head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>TopPage</title>\r\n </head>\r\n \r\n <body>\r\n <div class=\"main-all-wrap\">\r\n <div class=\"index-all-wrap\">\r\n <div class=\"profile\">\r\n <div class=\"profile-box\">\r\n <img src=\"#\" class=\"trim-image-to-circle\">\r\n <div class=\"pro-name\">a</div>\r\n <div class=\"pro-text\">\r\n afa\r\n </div>\r\n <div class=\"pro-link\">\r\n <a href=\"#\"><i class=\"fab fa-twitter-square\"></i></a>\r\n <a href=\"#\"><i class=\"fab fa-facebook\"></i></a>\r\n <a href=\"#\"><i class=\"fab fa-instagram-square\"></i></a>\r\n </div>\r\n </div>\r\n <div class=\"pro-menu\">\r\n <label for=\"menu_bar1\">label1</label>\r\n <input type=\"checkbox\" id=\"menu_bar1\">\r\n <ul id=\"links1\">\r\n <li><a href=\"#\">Link01</a></li>\r\n <li><a href=\"#\">Link02</a></li>\r\n </ul>\r\n <label for=\"menu_bar2\">label2</label>\r\n <input type=\"checkbox\" id=\"menu_bar2\">\r\n <ul id=\"links2\">\r\n <li><a href=\"#\">Link01</a></li>\r\n <li><a href=\"#\">Link02</a></li>\r\n </ul>\r\n </div>\r\n </div>\r\n <div class=\"main-contents-wrap\">\r\n <div class=\"contents-main\">\r\n <img src=\"#\">\r\n <div class=\"main-title\">{$maintitle}</div>\r\n <div class=\"sub-title\">{$subtitle}</div>\r\n <div class=\"sub-title\">{$subtitle}</div>\r\n <div class=\"main-text\">{$maintext}</div>\r\n <a href=\"#\" target=\"_self\"></a>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </body>\r\n \r\n </html>\n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T05:38:49.503", "id": "66020", "last_activity_date": "2020-04-27T06:03:28.727", "last_edit_date": "2020-04-27T06:03:28.727", "last_editor_user_id": "32986", "owner_user_id": "32986", "parent_id": "66018", "post_type": "answer", "score": 1 } ]
66018
66020
66020
{ "accepted_answer_id": "66023", "answer_count": 1, "body": "input関数を使おうとしたら以下のようなエラーになってしまいました。\n\n```\n\n File \"<ipython-input-21-dfdd02906783>\", line 39\n answer_num = input(\"解答:\")\n ^\n SyntaxError: invalid syntax\n \n```\n\nどのようにしたら解決できますか?\n\n```\n\n # -*- coding: utf-8 -*-\n import re\n import random\n import numpy as np\n source = 'english_words.txt'\n \n with oprn(source,'r',encoding = 'utf-8') as f:\n data = f.read().splitlines() \n english_words = [l.strip() for i, l in enumerate(data) if ((i%2) == 0)] \n jp_meanings = [l.strip() for i, l in enumerate(data) if ((i%2) != 0)] \n \n words_dict = dict(zip(english_words,jp_meanings)) \n \n \n n_questions = 50 \n \n \n \n random_index = np.random.randint(low = 0, high = len(english_words), size = n_questions) \n for question_num in range(n_questions): \n question_word = english_words[random_index[question_num]] \n correct_answer = words_dict[question_word] \n meanings_copy =jp_meanings.copy() \n meanings_copy.remove(correct_answer)\n wrong_answers = random.sample(meanings_copy,3) \n \n answer_options = [correct_answer] + wrong_answers \n \n random.shuffle(answer_options) \n correct_index = answer_options.index(correct_answer)\n \n print('問{}. {}\\n\\n'.format(question_num + 1,question_word)) \n for i in range(4):\n print('{}.{}\\n'.format(i + 1, answer_options[i]) \n answer_num = input(\"解答:\") # ←←←←←←←←←←←←←←←←←←←←←ここです\n answer_num = int(answer_num)\n if answer_num = correct_index + 1:\n print('correct!')\n else:\n print('wrong!')\n print('correct answer is '+'correct_answer')\n print('\\n\\n')\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T06:10:30.600", "favorite_count": 0, "id": "66022", "last_activity_date": "2020-04-27T07:20:31.263", "last_edit_date": "2020-04-27T07:20:31.263", "last_editor_user_id": "3060", "owner_user_id": "39563", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "input関数でSyntaxErrorになってしまう", "view_count": 436 }
[ { "body": ">\n```\n\n> print('{}.{}\\n'.format(i + 1, answer_options[i]) \n> \n```\n\nカッコの数があってません", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T06:19:20.427", "id": "66023", "last_activity_date": "2020-04-27T06:19:20.427", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27481", "parent_id": "66022", "post_type": "answer", "score": 1 } ]
66022
66023
66023
{ "accepted_answer_id": "72797", "answer_count": 2, "body": "現在、組込みLinuxのプロジェクトに携わっており、 \nターゲットCPUは TI AM3352, Kernel Version 4.19.59です。\n\n要求項目として \n・スリープ →DDR3-SDRAM セルフリフレッシュで内容を保持、他のデバイスはPower Off \n・レジューム →スリープから通常の動作状態に復帰する。 \nがあります。\n\n一応、コンフィグレーション項目としては\n\n```\n\n CONFIG_SUSPEND:\n Allow the system to enter sleep states in which main memory is\n powered and thus its contents are preserved, such as the\n suspend-to-RAM state (e.g. the ACPI S3 state).\n \n Symbol: SUSPEND [=y]\n Type : bool\n Prompt: Suspend to RAM and standby\n Location:\n -> Power management options\n Defined at kernel/power/Kconfig:1\n Depends on: ARCH_SUSPEND_POSSIBLE [=y]\n \n```\n\nがあるので、これを'y'にするのが必須とは考えております。\n\nだが仕組みがわかりません。とくにPower Offされるデバイスに対する状態の保持と復帰についてです。\n\nDDR3-SDRAMはスリープ時Self refreshモードにし、電源はPower Onのままのため \nスリープ時も内容が保持されるためあまり気にする必要は無いと思いますが \nスリープ時Power Offされる各(というか実装されている全ての)デバイスはPower\nOffされる前に今までデバイスに設定した状態の保持と復帰が必要になるはずです。 \nそのような仕組みがあるとすれば、おそらく、その仕組は、それぞれのデバイスドライバで担務していると考えています。\n\n## 質問\n\n(1) Linuxのデバイスドライバは、そのようにsuspend-to-RAMに対応した仕組みがあるのでしょうか? \nだとすれば、そればどのような仕組みでしょうか? このソースが参考になる的でも構いません。 \n(2) suspend-to-RAMに関する仕組みについてよい解説かリンク先があればお教えください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T07:03:56.843", "favorite_count": 0, "id": "66024", "last_activity_date": "2020-12-21T08:58:03.493", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "7844", "post_type": "question", "score": 6, "tags": [ "linux", "kernel" ], "title": "LinuxにおけるSuspend to RAMの仕組みをお教えください。", "view_count": 1515 }
[ { "body": "[AM335x\nSitara™プロセッサのマニュアル](https://www.tij.co.jp/jp/lit/ds/symlink/am3352.pdf?ts=1608530538705&ref_url=https%253A%252F%252Fwww.tij.co.jp%252Fproduct%252Fjp%252FAM3352)の88ページにある、\n\n> 表 5-11. AM335x Low-Power Modes Power Consumption Summary\n\nが参考になるのではないでしょうか?\n\n表から、低消費電力モードには、Standby, Deepsleep1, Deepsleep0の3種類があり、それぞれについて \n・保たれる情報、失われる情報が何で、それらをどのメモリに保存すべきか \n・起動(Wakeup)の手順 \nが概説されています。\n\n例えば、Deepsleep0だと、以下のように説明されています(括弧内は直訳です。あまり正確ではない可能性があります)\n\n> ・PD_PER peripheral and CortexA8/MPU register information will be lost. \n> (PD_PERのperipheralおよびContexA8/MPUのレジスタの情報は失われる。) \n> ・On-chip peripheral register(context) information of PD-PER domain must be\n> saved by (application to SDRAM before entering this mode. \n> チップ上のperipheralレジスタのPD-\n> PERドメインの情報は、このモードに入る前にアプリケーションでSDRAMに保存しておかなければならない。) \n> ・DDR is in selfrefresh. \n> (DDRは、selfrefreshモードになる。) \n> ・For wakeup, boot ROM executes and branches to peripheral context restore\n> followed by system resume. \n> (ウェイクアップは、boot ROMを実行し、peripheralのcontextの復元、systemの復元と続く)\n\n== \nこうしたCPUチップ内プログラム(boot ROM等)、OS(Linux)のカーネル、Linuxが、どのような構成/階層になるのかは判りません。 \nsleep時の情報保存・復元の機能が、デバイスドライバという形式で提供されるかどうかも判りません。\n\nマニュアルから僕が拾い出せた情報を回答しました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-12-21T07:42:47.480", "id": "72794", "last_activity_date": "2020-12-21T07:42:47.480", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "66024", "post_type": "answer", "score": 1 }, { "body": "### (1)について\n\nLinuxカーネルにはその仕組みがあります。 \nデバイスドライバーにとってはオプションなので, 実装しているとは限りません。(ちなみにドライバー作ったことありますがデスクトップ用だったので\n`open`/`close` `read`/`write` 程度の実装でした) \n`suspend` や `resume` といったエントリーを実装できるので, 実装し・その情報をセットするだけです。 \nソースについては, Linux kernel標準のドライバーの中から実装してそうなのを探し出すしか無いと思います\n(ディスプレイドライバー辺り実装してそうな?)\n\n### (2)資料について\n\n * 4.19の Power Management資料 [Device Power Management Basics](https://www.kernel.org/doc/html/v4.19/driver-api/pm/devices.html)\n * 2.4のころのですが日本語資料です (ただしものによってはバージョンで構造体がお大きく異なることもあるので注意)。[電源管理の使用方法と電源管理のドライバの追加方法](http://linuxjf.osdn.jp/JFdocs/kernel-docs-2.4/pm.txt.html)\n * これも古いですが詳細が分かるのではないかと [LinuxにおけるACPI構造の解説](https://osdn.co.jp/event/kernel2002/pdf/C06.pdf)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-12-21T08:58:03.493", "id": "72797", "last_activity_date": "2020-12-21T08:58:03.493", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "43025", "parent_id": "66024", "post_type": "answer", "score": 2 } ]
66024
72797
72797
{ "accepted_answer_id": "66028", "answer_count": 1, "body": "Javaで文字列を与えて「漢字かそれ以外か」でグルーピングしたいです.つまり、1文字とも取りこぼす文字はあってはならないのが条件です.次のようなサンプルを作ってみたのですが...\n\n```\n\n import java.util.regex.Matcher;\n import java.util.regex.Pattern;\n \n public class RegexTest {\n \n private static Pattern cjkIdeoGraphicOrNotPattern = Pattern.compile(\"(?U)([\\\\P{InCJKUnifiedIdeographs}]&&[\\\\P{InCJKUnifiedIdeographsExtensionA}]&&[\\\\P{InCJKUnifiedIdeographsExtensionB}]&&[\\\\P{InCJKUnifiedIdeographsExtensionC}]&&[\\\\P{InCJKUnifiedIdeographsExtensionD}])+|([\\\\p{InCJKUnifiedIdeographs}]|[\\\\p{InCJKUnifiedIdeographsExtensionA}]|[\\\\p{InCJKUnifiedIdeographsExtensionB}]|[\\\\p{InCJKUnifiedIdeographsExtensionC}]|[\\\\p{InCJKUnifiedIdeographsExtensionD}])+\");\n \n public static void main(String[] args) {\n String target = \"2000年问题 2001年问题\";\n Matcher matcher = cjkIdeoGraphicOrNotPattern.matcher(target);\n while (matcher.find()) {\n System.out.println(\"Matches = \\\"\" + matcher.group() + \"\\\"\");\n }\n }\n }\n \n```\n\n結果は漢字の部分だけにマッチしてしまいます.\n\n```\n\n Matches = \"年问题\"\n Matches = \"年问题\"\n \n```\n\n望まれる結果は\n\n```\n\n Matches = \"2000\"\n Matches = \"年问题\"\n Matches = \" 2001\"\n Matches = \"年问题\"\n \n```\n\nなのですが、このようなことって正規表現で実現できますでしょうか?\n\n以上 よろしくお願いいたします.", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T07:08:33.643", "favorite_count": 0, "id": "66025", "last_activity_date": "2020-04-27T08:26:24.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9503", "post_type": "question", "score": 1, "tags": [ "java", "正規表現", "unicode" ], "title": "文字列を漢字かそれ以外でグルーピングする", "view_count": 232 }
[ { "body": "問題は、文字クラスの積の書き方の間違いです。`&&[` は `[ ]` の内側に書く必要があります。\n\n```\n\n \"(?U)([\\\\P{...}&&[\\\\P{...}]&&[\\\\P{...}]&&[\\\\P{...}]&&[\\\\P{...}]]+...\"\n \n```\n\nこの場合は文字クラス積を使わなくてもいいかと思います。否定 `^` で十分です。\n\n```\n\n private static String cjkIdeoGraphic =\n \"\\\\p{In...}\\\\p{In...A}\\\\p{In...B}\\\\p{In...C}\\\\p{In...D}\";\n private static Pattern cjkIdeoGraphicOrNotPattern = Pattern.compile(\n \"(?U)([^\" + cjkIdeoGraphic + \"]+|[\" + cjkIdeoGraphic + \"]+)\");\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T08:20:29.517", "id": "66028", "last_activity_date": "2020-04-27T08:26:24.617", "last_edit_date": "2020-04-27T08:26:24.617", "last_editor_user_id": "3475", "owner_user_id": "3475", "parent_id": "66025", "post_type": "answer", "score": 1 } ]
66025
66028
66028
{ "accepted_answer_id": "66056", "answer_count": 1, "body": "Docker(CentOS7)でnginxとrailsの構築をしています。\n\nNginxコンテナとrailsコンテナをそれぞれ起動し、ソケット通信を利用してMacOSのChromeでアクセスしたいのですが、 \nソケット通信がうまくいっていないのか、`localhost:8080`にアクセスすると`502 Bad Gateway`エラーになる状況です。\n\nアクセス後のnginxのエラー(/var/log/nginx/error)\n\n```\n\n 2020/04/27 06:45:32 [error] 125#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.25.0.1, server: localhost, request: \"GET / HTTP/1.1\", upstream: \"http://127.0.0.1:8080/\", host: \"localhost:8080\"\n 2020/04/27 06:45:32 [warn] 125#0: *1 upstream server temporarily disabled while connecting to upstream, client: 172.25.0.1, server: localhost, request: \"GET / HTTP/1.1\", upstream: \"http://127.0.0.1:8080/\", host: \"localhost:8080\"\n 2020/04/27 06:45:32 [error] 125#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.25.0.1, server: localhost, request: \"GET / HTTP/1.1\", upstream: \"http://127.0.0.1:8080/\", host: \"localhost:8080\"\n 2020/04/27 06:45:32 [warn] 125#0: *1 upstream server temporarily disabled while connecting to upstream, client: 172.25.0.1, server: localhost, request: \"GET / HTTP/1.1\", upstream: \"http://127.0.0.1:8080/\", host: \"localhost:8080\"\n 2020/04/27 06:45:33 [error] 125#0: *1 no live upstreams while connecting to upstream, client: 172.25.0.1, server: localhost, request: \"GET /favicon.ico HTTP/1.1\", upstream: \"http://localhost/favicon.ico\", host: \"localhost:8080\", referrer: \"http://localhost:8080/\"\n 2020/04/27 06:47:36 [error] 127#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.25.0.1, server: 127.0.0.1, request: \"GET / HTTP/1.1\", upstream: \"http://127.0.0.1:8080/\", host: \"localhost:8080\"\n 2020/04/27 06:47:38 [error] 127#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.25.0.1, server: 127.0.0.1, request: \"GET /favicon.ico HTTP/1.1\", upstream: \"http://127.0.0.1:8080/favicon.ico\", host: \"localhost:8080\", referrer: \"http://localhost:8080/\"\n \n```\n\n下記にあるnginx.confのソースコードの通り、色々試してみたのですが、うまくいかず、どのように設定すれば正常にアクセスできるのか悩んでいます。 \n解決策をご教授いただけると幸いです。\n\n * pumaを使用しています。\n * `/tmp/sockets/server.pid`のマウント設定もdocker-compose.ymlで設定しています。\n * railsはポート番号5000で起動しています。\n\n# ソースコード\n\nnginx.conf\n\n```\n\n error_log /var/log/nginx/error warn;\n \n worker_processes 2;\n worker_rlimit_nofile 150000;\n \n events {\n worker_connections 1024;\n }\n \n http {\n upstream testdocker {\n server unix:///var/www/testdocker/tmp/pids/server.pid;\n # 試したコード\n # server localhost:5000;\n # server 127.0.0.1:5000;\n # server 0.0.0.0:5000;\n }\n \n server {\n listen 80;\n server_name 127.0.0.1:8000;\n # 試したコード\n # listen 8080;\n # server_name localhost;\n # server_name testdocker;\n \n location / {\n proxy_pass http://127.0.0.1:8080;\n # proxy_pass http://localhost:8080; # 試したコード\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n proxy_set_header Host $http_host;\n proxy_redirect off;\n }\n }\n }\n \n```\n\ndocker-compose.yml\n\n```\n\n version: '3'\n \n services:\n rails:\n build: .\n tty: true\n stdin_open: true\n volumes:\n - ./testdocker:/var/www/testdocker\n working_dir: /var/www/testdocker\n command: >\n bash -c \"rails s -b 0.0.0.0;\n bash\"\n ports:\n - '5000:3000'\n \n nginx:\n build: .\n tty: true\n stdin_open: true\n privileged: true\n restart: always\n volumes:\n - ./nginx.conf:/etc/nginx/nginx.conf\n - ./nginx.repo:/etc/yum.repos.d/nginx.repo\n - ./testdocker/tmp/pids:/var/www/testdocker/tmp/pids # server.pidをマウントする\n command: /sbin/init\n ports:\n - \"8080:80\"\n \n```\n\nDocker\n\n```\n\n FROM centos:7.7.1908\n \n ENV LANG C.UTF-8\n ENV TZ Asia/Tokyo\n ENV LC_ALL=C\n \n # 必要なパッケージをインストール\n RUN yum -y update\n RUN yum install -y git tzdata libxml2-devel.x86_64 libcurl-devel.x86_64 gcc-c++.x86_64 glibc-devel.x86_64 mariadb-devel.x86_64 ImageMagick.x86_64 bzip2 make which epel-release gmp-devel.x86_64\n \n # NodeJSのインストール\n RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash -\n RUN yum install -y nodejs\n \n # rubyとrailsをインストール\n RUN git clone --depth=1 https://github.com/rbenv/ruby-build && PREFIX=/usr/local ./ruby-build/install.sh && rm -rf ruby-build\n RUN ruby-build 2.7.1 /usr/local\n RUN gem install -v 5.2.4 rails --no-document\n \n # Gemfileのインストール\n RUN mkdir -p /var/www/testdocker\n WORKDIR /var/www/testdocker\n COPY /testdocker/Gemfile Gemfile\n COPY /testdocker/Gemfile.lock Gemfile.lock\n RUN bundle install\n \n # Nigixのインストール\n COPY nginx.repo ./etc/yum.repos.d/nginx.repo\n RUN yum install -y nginx\n \n```\n\n# バージョン\n\nnginx 1.16.1", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T08:44:44.067", "favorite_count": 0, "id": "66029", "last_activity_date": "2020-04-28T06:27:15.270", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25223", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "docker", "nginx" ], "title": "Docker Nginx+Railsでサーバ起動すると502 Bad Gatewayになる", "view_count": 6852 }
[ { "body": "rails コンテナ内部から見ると 3000 番ポートで起動していて、ホストの 5000 番ポートからポートフォワードしているのですよね?\n\nもし、そうならば、nginx コンテナからは、ホストの 5000 番ポートではなく、rails コンテナの 3000\n番ポートに接続するよう、`proxy_pass` を設定する必要があります。\n\n```\n\n location / {\n proxy_pass http://rails:3000;\n (略)\n }\n \n```\n\nただし、nginx コンテナから \"rails\"\nで名前解決するには、[links](https://docs.docker.com/compose/compose-file/compose-\nfile-v2/#links) で設定するか、[networks](https://docs.docker.com/compose/compose-\nfile/compose-file-v2/#networks) で両コンテナを同じネットワークに配置するか、どちらかになると思います。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T06:27:15.270", "id": "66056", "last_activity_date": "2020-04-28T06:27:15.270", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4603", "parent_id": "66029", "post_type": "answer", "score": 3 } ]
66029
66056
66056
{ "accepted_answer_id": "66033", "answer_count": 1, "body": "下記の様なjsonをjacksonのライブラリを使用してobjectに変換したいのです。\n\n```\n\n {\n \"jsonrpc\": \"2.0\",\n \"result\":[\n {\n \"hostid\": \"9999\",\n \"name\": \"test\",\n \"type\": \"1\",\n },\n {\n \"hostid\": \"9998\",\n \"name\": \"test2\",\n \"type\": \"1\",\n }\n ],\n \"id\": 1\n }\n \n```\n\njacksonのreadValueメソッドを使用してobjectへ変換しようと試みておりますが、\n\n```\n\n TestDto test= mapper.readValue(json, TestDto.class);\n \n```\n\n下記のようなエラーとなってしまいます。\n\n```\n\n com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class TestDto$Result]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?)\n \n```\n\nなお、TestDtoは下記のように宣言しております。\n\n```\n\n public class TestDto {\n \n public String jsonrpc;\n \n public List<Result> result;\n \n public class Result {\n public String hostid;\n \n public String name;\n \n public String type;\n }\n public Integer id;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T11:02:16.783", "favorite_count": 0, "id": "66030", "last_activity_date": "2020-04-27T12:52:18.940", "last_edit_date": "2020-04-27T11:30:23.840", "last_editor_user_id": "3060", "owner_user_id": "31179", "post_type": "question", "score": 0, "tags": [ "java", "json", "array", "jackson" ], "title": "入れ子になったjson配列をjacksonのライブラリを使用してobjectに変換したい", "view_count": 5321 }
[ { "body": "`Result` を\n[ネストされたクラス](https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html)として定義するなら\n`static` にする必要がります。\n\n```\n\n public class TestDto {\n ...\n public static class Result {\n ...\n }\n }\n \n```\n\n(なお、強いてネストされたクラスとして定義する必要はなく、 `TestDto` から独立した通常のクラスとして定義しても問題ありません。)\n\n加えて、入力JSONも妥当ではないので修正する必要があります。\n\n```\n\n {\n \"jsonrpc\": \"2.0\",\n \"result\": [\n {\n \"hostid\": \"9999\",\n \"name\": \"test\",\n \"type\": \"1\"\n },\n {\n \"hostid\": \"9998\",\n \"name\": \"test2\",\n \"type\": \"1\"\n }\n ],\n \"id\": 1\n }\n \n```\n\n[差分](https://github.com/yukihane/stackoverflow-qa/compare/b6ba2bde..db72b)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T12:52:18.940", "id": "66033", "last_activity_date": "2020-04-27T12:52:18.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "66030", "post_type": "answer", "score": 1 } ]
66030
66033
66033
{ "accepted_answer_id": "66032", "answer_count": 2, "body": "このようなDockerfileを見ていたのですが、`chown`をしている所がありました。\n\n```\n\n FROM alpine:3.11\n \n RUN adduser -D -u 1000 server\n COPY --from=builder /go/src/simple-udp/server /home/server/server\n RUN chown -R server /home/server && \\\n chmod o+x /home/server/server\n \n USER 1000\n ENTRYPOINT [\"/home/server/server\"]\n \n```\n\nこういった`chown`はどういう意味で行っているのでしょうか。 \n私はアクセス権限の話に疎く、一般的な意味で`chown`の使い所がわからないのですが、一般的な用法はどのようなものなのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T11:15:53.787", "favorite_count": 0, "id": "66031", "last_activity_date": "2020-04-28T10:04:56.767", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37013", "post_type": "question", "score": 1, "tags": [ "linux" ], "title": "chownは何のために行いますか?", "view_count": 166 }
[ { "body": "`chown` に限らずLinuxでのアクセス権限は、対象のファイルやディレクトリへのアクセスを許可または禁止する仕組みになります。\n\nLinuxでは複数ユーザーでの利用が前提なので、仮にファイルの所有者やアクセス権限という考え方が無かった場合、あなたが作った大事なファイルが別の誰かに勝手に書き換えられたり、最悪だと削除されてしまう可能性が出てきます。\n\nまた、人間のユーザーに限らずLinux上で動くプログラム(サーバ/デーモン)に対しても個別の \"ユーザー\"\nとしての権限を割り当てておくことで、大事なファイルをユーザーが書き換えてしまう…といった事故を防ぐことができます。\n\nファイルに対するアクセス権限や所有者は、「ファイルの保護」や「責任の所在」を明確にするための仕組みと考えてみてください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T11:40:03.943", "id": "66032", "last_activity_date": "2020-04-28T10:04:56.767", "last_edit_date": "2020-04-28T10:04:56.767", "last_editor_user_id": "3060", "owner_user_id": "3060", "parent_id": "66031", "post_type": "answer", "score": 4 }, { "body": "(一般的な用法を尋ねられているので質問の意図とは異なるかもしれませんが…)\n\n今回のコンテナは、`server`実行ファイルを`server`ユーザ(だけ)が実行するものなので、 \nファイルを`server`ユーザのホームディレクトリ `/home/server` に置くのが自然だ、ownerも\n`server`ユーザに変更しておくのが自然だ、と実装者が考えた結果そうなっているだけかと思います。\n\n`server`ユーザに対して実行権限が付与されていれば、ownerは`root`ユーザのままでも支障ないかと考えます。 \n要するに、今回の `chown` に必然性はない、ということです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T16:01:26.133", "id": "66040", "last_activity_date": "2020-04-27T16:01:26.133", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "66031", "post_type": "answer", "score": 2 } ]
66031
66032
66032
{ "accepted_answer_id": null, "answer_count": 1, "body": "参照ボタンに検索したい従業員の番号を入力すると、フォームにデータが参照されます。 \nそこからデータを編集し、編集確定ボタンを押すと表に上書きされるような仕様にしたいです。 \nしかし、今のコードだと14行のような感じで反映されてしまいます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/paePq.png)](https://i.stack.imgur.com/paePq.png)\n\n* * *\n\n**VBA**\n\n参照ボタンを押した際の処理です\n\n```\n\n '編集確定ボタンを押したとき'\n Private Sub OkButton1_Click()\n \n Dim x As Integer\n With Worksheets(\"メンバー\")\n For x = 2 To 10\n Cells(ActiveCell.Row, x).Value = Me.Controls(\"TextBox\" & x).Text\n Me.Controls(\"TextBox\" & x).Text = \"\"\n Next\n End With\n \n End Sub\n \n '参照ボタンを押した時の処理'\n Private Sub RefBtn_Click()\n \n 'もし参照する値が入力されていなかったら'\n If Me.IDTextBox = \"\" Then\n MsgBox \"参照する番号を入力してください。\"\n Exit Sub\n End If\n \n 'データの参照'\n Dim rng As Range\n Dim r As Variant\n Dim i As Integer\n With Worksheets(\"メンバー\")\n \n Set rng = .Range(\"A2:A\" & .Cells(Rows.Count, 1).End(xlUp).Row)\n r = Application.Match(Val(IDTextBox.Text), rng, 0)\n \n For i = 2 To 5\n Controls(\"TextBox\" & i).Text = .Cells(r + 1, i)\n Next i\n If .Cells(r + 1, 6) = \"男\" Then\n Man.Value = True\n Else\n Woman.Value = True\n End If\n \n ComboBox1.Text = .Cells(r + 1, 7)\n For i = 6 To 8\n Controls(\"TextBox\" & i).Text = .Cells(r + 1, i + 2)\n Next i\n End With\n \n End Sub\n \n```\n\n一応メンバー追加の登録のコードです\n\n```\n\n '現在作業中のシートを選択'\n ActiveSheet.Select\n If Cells(8, 1).Value = 1 Then 'cell値変更あるかも'\n \n '入力されている一番最後のセルの番号を取得'\n CellCount = Cells(7, 1).End(xlDown).Row + 1\n \n 'IDTextBoxの値を\"従業員番号\"の欄に入力'\n Cells(CellCount, 1).Value = Me.IDTextBox.Value\n \n '姓を入力'\n Cells(CellCount, 2).Value = Me.TextBox2.Value\n \n '名を入力'\n Cells(CellCount, 3).Value = Me.TextBox3.Value\n \n 'セイを入力'\n Cells(CellCount, 4).Value = Me.TextBox4.Value\n \n 'メイを入力 '\n Cells(CellCount, 5).Value = Me.TextBox5.Value\n \n '選択した性別を入力'\n If Man.Value = True Then\n Cells(CellCount, 6).Value = Me.Man.Caption\n \n ElseIf Woman.Value = True Then\n Cells(CellCount, 6).Value = Me.Woman.Caption\n \n End If\n \n '交通手段を入力'\n Cells(CellCount, 7).Value = Me.ComboBox1.Value\n \n '最寄り駅を入力'\n Cells(CellCount, 8).Value = Me.TextBox6.Value\n \n '交通費を入力'\n Cells(CellCount, 9).Value = Me.TextBox7.Value\n \n '時給を入力'\n Cells(CellCount, 10).Value = Me.TextBox8.Value\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T13:25:51.507", "favorite_count": 0, "id": "66036", "last_activity_date": "2020-04-28T09:12:06.160", "last_edit_date": "2020-04-27T16:35:32.613", "last_editor_user_id": "3060", "owner_user_id": "39792", "post_type": "question", "score": 0, "tags": [ "vba" ], "title": "VBA編集データを上書きしたい", "view_count": 998 }
[ { "body": "'参照ボタンを押した時の処理'のプログラムは以下のようになっていて、書き込み先のセルの行は、ActiveCell.Row です。 \n質問のスクリーンショットで、G14セルが選択されている(ActiveCellになっている)ようなので、14行目(B14:H14)にデータが書き込まれたのは、そのせいだと思います。(A15セルを選択した状態で、編集確定ボタンをクリックすると15行目に書き込まれるだろうと思います。\n\n```\n\n Private Sub OkButton1_Click()\n Dim x As Integer\n With Worksheets(\"メンバー\")\n For x = 2 To 10\n Cells(ActiveCell.Row, x).Value = Me.Controls(\"TextBox\" & x).Text\n Me.Controls(\"TextBox\" & x).Text = \"\"\n Next\n End With\n End Sub\n \n```\n\n『編集確定ボタンを押すと表に上書きされるような仕様にしたい』というのであれば、 \nどの行からデータを取得したのかを覚えておいて、その行にデータを書き戻すようにしてください。 \n(ActiveCell.Rowを書き戻す行にするのは、まずいです。どこのセルを選択した状態でプログラムを実行するのかが判らないですから)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T09:12:06.160", "id": "66068", "last_activity_date": "2020-04-28T09:12:06.160", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "66036", "post_type": "answer", "score": 1 } ]
66036
null
66068
{ "accepted_answer_id": "66038", "answer_count": 1, "body": "1. タイトルの通り。GETリクエストしてきたユーザーのipアドレスを取得したいです。\n 2. 少し調べた結果、クッキーを使ってipアドレスを取得しようと思うのですがそれは正しい方法でしょうか。 \n以上の2点について回答お願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T13:34:06.193", "favorite_count": 0, "id": "66037", "last_activity_date": "2020-04-27T14:08:46.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "javascript", "node.js" ], "title": "Express+Node.jsでGETリクエストしたユーザーのipアドレスを取得したい", "view_count": 4174 }
[ { "body": "`req.ip`で良いかと思います。\n\n * <https://expressjs.com/ja/api.html#req.ip>\n * <https://expressjs.com/ja/guide/behind-proxies.html>\n\n```\n\n const express = require(\"express\");\n const app = express();\n \n app.get(\"/\", (req, res) => res.send(`remote address: ${req.ip}`));\n \n app.listen(3000, () => console.log(\"Example app listening on port 3000!\"));\n \n```\n\n文脈が分かりませんが、cookiesは全く無関係だと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T14:08:46.507", "id": "66038", "last_activity_date": "2020-04-27T14:08:46.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "66037", "post_type": "answer", "score": 0 } ]
66037
66038
66038
{ "accepted_answer_id": "66077", "answer_count": 1, "body": "go と database/sql を使って以下のようなコードを書きました。 \nやりたい事としては、hoge テーブルからデータを select して、その内容を取得する事です。\n\nDB のデータ構造は構造体におこさない条件があります。\n\n`*val` には DB から取得した値が入る想定でしたが、数値の配列が入っています。 \nこの数値は何を表しているのでしょうか? また、正しくレコードの値を取得する方法があれば教えていただきたいです。\n\n```\n\n rows, err := db.Query(\"select * from hoge\")\n if err != nil {\n return err\n }\n columns, err := rows.Columns()\n if err != nil {\n return err\n }\n \n count := len(columnNames)\n args := make([]interface{}, count)\n pointers := make([]interface{}, count)\n \n for i, _ := range args {\n pointers[i] = &args[i]\n }\n \n for rows.Next() {\n err := rows.Scan(pointers...)\n if err != nil {\n return err\n }\n for i, n := range columnNames {\n val := pointers[i].(*interface{})\n log.Println(*val) // [50 48 50 48 45 48 51 45 48 54 32 49 50 58 53 56 58 52 55]\n }\n ...\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T15:45:02.173", "favorite_count": 0, "id": "66039", "last_activity_date": "2020-04-28T13:35:44.463", "last_edit_date": "2020-04-27T16:37:13.497", "last_editor_user_id": "3060", "owner_user_id": "10865", "post_type": "question", "score": 0, "tags": [ "sql", "go", "database" ], "title": "go と database/sql で構造体がない場合でも値を取得したい。", "view_count": 611 }
[ { "body": "データベーステーブルのカラム情報を、[sql.Rows.ColumnTypes()](https://golang.org/pkg/database/sql/#Rows.ColumnTypes)\nと\n[sql.ColumnType.ScanType()](https://golang.org/pkg/database/sql/#ColumnType.ScanType)\nを利用して取得するサンプルプログラムを以下に示します。データベースは sqlite3 を使用しています。\n\n`reflect.New()` で各カラムに対応する Go の型(type)のインスタンス(ポインタ)を作成して、それらを\n`sql.Rows.Scan()` に渡しています。ポインタですので、値を取り出すのに `reflect.Value.Elem()` を使います。\n\n**sql_example.go**\n\n```\n\n package main\n \n import (\n \"database/sql\"\n \"fmt\"\n \"reflect\"\n \n _ \"github.com/mattn/go-sqlite3\"\n )\n \n func main() {\n // Connect to database\n db, err := sql.Open(\"sqlite3\", \"./test.db\")\n if err != nil {\n panic(err)\n }\n defer db.Close()\n \n // Select records\n rows, err := db.Query(\"SELECT * from hoge\")\n if err != nil {\n panic(err)\n }\n defer rows.Close()\n \n // No records\n if !rows.Next() {\n return\n }\n \n // Column types\n ct, err := rows.ColumnTypes()\n if err != nil {\n panic(err)\n }\n types := make([]reflect.Type, len(ct))\n for i, typ := range ct {\n types[i] = typ.ScanType()\n }\n \n // Column values\n values := make([]interface{}, len(ct))\n for i := range values {\n values[i] = reflect.New(types[i]).Interface()\n }\n \n // Scan\n for {\n err := rows.Scan(values...)\n if err != nil {\n panic(err)\n }\n \n for _, v := range values {\n fmt.Printf(\"%v|\", reflect.ValueOf(v).Elem())\n }\n fmt.Println()\n \n if !rows.Next() {\n break\n }\n }\n }\n \n```\n\n**実行結果**\n\n```\n\n $ sqlite3 test.db <<EOS\n CREATE TABLE hoge (\n id INTEGER PRIMARY KEY,\n created_at TIMESTAMP DEFAULT (datetime(CURRENT_TIMESTAMP, 'localtime'))\n );\n INSERT INTO hoge VALUES (1, '2020-03-06 12:58:47');\n INSERT INTO hoge VALUES (2, '2020-04-28 01:36:20');\n INSERT INTO hoge VALUES (3, '2020-05-15 15:10:12');\n EOS\n \n $ sqlite3 test.db <<EOS\n SELECT * from hoge;\n EOS\n 1|2020-03-06 12:58:47\n 2|2020-04-28 01:36:20\n 3|2020-05-15 15:10:12\n \n $ go run sql_example.go\n 1|2020-03-06T12:58:47Z|\n 2|2020-04-28T01:36:20Z|\n 3|2020-05-15T15:10:12Z|\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T13:35:44.463", "id": "66077", "last_activity_date": "2020-04-28T13:35:44.463", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "66039", "post_type": "answer", "score": 0 } ]
66039
66077
66077
{ "accepted_answer_id": "66045", "answer_count": 2, "body": "こんにちは。Python初心者です。オブジェクト指向を学びたいと思いこちらの \nサイトのコードを利用して、クラスのことを勉強しています。 \n<https://www.sejuku.net/blog/64106> \n上記のサイトのコードを自分で変えてみてどのように動くかを試していました。\n\nサイトには\n\n```\n\n class className():\n def methodName(self):\n print(\"Hello World!\")\n \n instance = className()\n instance.methodName()\n \n```\n\nとあるのですが、このコードの6行目をこう変更しました。\n\n```\n\n class className():\n def methodName(self):\n print(\"Hello World!\")\n \n instance =className()\n print(instance)\n \n```\n\n出力されるのが、クラスかインスタンスのアドレス \nのようになります。\n\n出力結果\n\n```\n\n <__main__.Class object at 0x03636390>\n \n```\n\nprintの引数をインスタンス名にすると \nそのアドレスが出力される理由を教え下さい。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-27T23:11:20.493", "favorite_count": 0, "id": "66042", "last_activity_date": "2020-04-28T02:56:09.337", "last_edit_date": "2020-04-28T02:56:09.337", "last_editor_user_id": "19110", "owner_user_id": "39846", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "printの引数をインスタンス名にするとそのアドレスが出力される理由を教えて下さい。", "view_count": 1277 }
[ { "body": "下記のような動作が行われ、そのインスタンスオブジェクトに`__str__()`や`__repr__()`が定義されていないので、objectのデフォルト実装の結果`<...some\nuseful description...>`形式の文字列として`<__main__.Class object at\n0x03636390>`が表示されると考えられます。\n\n 1. `str()`関数が呼ばれたように動作して文字列化する \n[print(*objects, sep=' ', end='\\n', file=sys.stdout,\nflush=False)](https://docs.python.org/ja/3/library/functions.html#print)の「キーワードなしの引数はすべて、\nstr() がするように文字列に変換され、」の部分\n\n 2. 内部的に、そのオブジェクトの`__str__()`メソッドが呼ばれる \n[object.__str__(self)](https://docs.python.org/ja/3/reference/datamodel.html#object.__str__)の「オブジェクトの「非公式の\n(informal)」あるいは表示に適した文字列表現を計算するために、 str(object) と組み込み関数 format(), print()\nによって呼ばれます。」の部分\n\n 3. `__str__()`が定義されていなければ、そのオブジェクトの`__repr__()`が呼ばれる \n[object.__str__(self)](https://docs.python.org/ja/3/reference/datamodel.html#object.__str__)の「組み込み型\nobject によって定義されたデフォルト実装は、 object.__repr__() を呼び出します。」の部分\n\n 4. `__repr__()`が定義されていなければ、おそらく組み込み型 object によって定義されたデフォルト実装が呼ばれる \n内容は[object.__repr__(self)](https://docs.python.org/ja/3/reference/datamodel.html#object.__repr__)の「オブジェクトを表す「公式の\n(official)」文字列を計算します。可能なら、これは (適切な環境が与えられれば) 同じ値のオブジェクトを再生成するのに使える、有効な Python\n式のようなものであるべきです。できないなら、`<...some useful description...>`形式の文字列が返されるべきです。」の部分\n\n参考: \n[Python 3の組み込み関数を速攻理解しよう: オブジェクト/スコープ/モジュール/動的評価/入出力編\n(1/3)](https://www.atmarkit.co.jp/ait/articles/1704/28/news041.html)\n\n> オブジェクトの文字列表現を取得する: ascii/repr\n>\n>\n> 組み込み関数reprを呼び出すと、最終的にはそのオブジェクトが持つ__repr__メソッドが呼び出される。このメソッドは「オブジェクトのオフィシャルな表現」を返送する。「オフィシャルな表現」とはPythonのドキュメント「object.__repr__」の説明によれば、「(適切な環境が与えられれば)\n> 同じ値のオブジェクトを再生成するのに使える、有効な Python 式のようなものであるべき」であり、それが無理であれば「<...some useful\n> description...>\n> 形式の文字列」を返送すべきとなっている。そのため、上のサンプルでは文字列やリスト、タプルについては前者の表現が得られ、関数やクラス、インスタンスについては「<...some\n> useful description...>」形式の文字列が得られている。\n\n[Python、対話モードでの自動表示とprintの違い](https://torina.top/detail/450/)\n\n[クラスオブジェクトとインスタンスオブジェクトってなに?](https://python.ms/instance-and-class/)\n\n[Pythonのstr( )とrepr( )の使い分け](https://gammasoft.jp/blog/use-diffence-str-and-\nrepr-python/)\n\n[[python]__repr__と__str__の違い](https://chaingng.github.io/post/python_repr/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T00:38:11.247", "id": "66044", "last_activity_date": "2020-04-28T00:38:11.247", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "26370", "parent_id": "66042", "post_type": "answer", "score": 1 }, { "body": "> printの引数をインスタンス名にすると\n\nprintに渡している`instance`は`インスタンス名`ではなく、 \nクラス`className`のインスタンスそのものです、インスタンスの名前ではありません。\n\nクラスに`__str__()`が定義されていれば`__str__()`の復帰値が表示されますが、 \n未定義の場合は`<main.Class object at 0x03636390>`が表示されるようです。\n\n`__str__()`を定義した次のコードを実行すると`ABC`と表示されます。\n\n```\n\n class className():\n def __str__(self):\n return \"ABC\"\n def methodName(self):\n print(\"Hello World!\")\n \n instance =className()\n print(instance)\n \n```\n\n私には、どうしてそうなのかを説明することができません、そういう仕様だと理解しています。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T01:05:11.630", "id": "66045", "last_activity_date": "2020-04-28T01:05:11.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "35558", "parent_id": "66042", "post_type": "answer", "score": 1 } ]
66042
66045
66044
{ "accepted_answer_id": "66201", "answer_count": 1, "body": "プログラミング勉強中なのですが、仮想環境という概念がイマイチ分からないので自分の認識があっているか質問させてください。\n\nプログラミング勉強用にUbuntu LTS 18.04をホストOSとしてインストールしました。デフォルトではPython 3.6.9が入っています。\n\n今まで特に意識していなかったのですが、今回はローカル環境をあまり汚さず作業をしたいのでPythonの仮想環境を作ってそこで作業をしたいと考えています。 \nそこで現状の自分の認識が合っているか確認したいです。\n\n 1. Ubuntuをインストールした段階で初期から入っているソフトなどの中にPythonを使っている物があるので、Python3.6.9とそれらソフトの動作に必要十分なPythonライブラリが入っている。\n 2. Pythonの最新版である3.8を使いたいのと、ローカルにライブラリ入れすぎて管理できなくなるのが怖いので仮想環境を作ることで解決したい。\n 3. Python3.6.9が入っているので標準ライブラリである”venv”が使える。\n 4. 新規のディレクトリを作成し”venv”で仮想環境を作成、そのディレクトリ内のみで稼働するPython3.8や任意のライブラリの入った環境を作れる。\n 5. 環境が壊れてもディレクトリを削除すれば別途pipインストールしたライブラリも消える\n 6. Python3.8で動かしたい、または別途入れたライブラリを動かしたいPythonスクリプトを書いたら.pyファイルを仮想環境ディレクトリに移動させてターミナルから.pyを動かせば問題なく動く(またはそもそも仮想環境下でコードを書いて実行でもいいですが)\n\n以上の認識はあっていますでしょうか?数が多いのでここが間違っているなどお教えいただけると幸いです。\n\n不勉強な質問ですがよろしくお願いいたします。\n\n追加での関連質問なのですが、データ分析などで有名なAnacondaディストリビューションは仮想環境だと聞きました。それは上記のような仕組みなんでしょうか。\n\nつまりどこかにAnacondaというディレクトリが作成されて”conda”コマンドでインストールされたライブラリはその仮想環境内で保存され、Jupyter\nnotebookやSpyderなどから使用できる。Anacondaをアンインストールしたらそれらも消える。\n\nという認識であっていますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T00:22:01.927", "favorite_count": 0, "id": "66043", "last_activity_date": "2020-05-02T07:27:22.930", "last_edit_date": "2020-04-28T03:27:45.187", "last_editor_user_id": "32986", "owner_user_id": "39847", "post_type": "question", "score": 0, "tags": [ "python", "python3", "ubuntu", "pip" ], "title": "Python 仮想環境について", "view_count": 238 }
[ { "body": "> 1.\n> Ubuntuをインストールした段階で初期から入っているソフトなどの中にPythonを使っている物があるので、Python3.6.9とそれらソフトの動作に必要十分なPythonライブラリが入っている。\n>\n\nおそらく、はい。\n\n「初期から入っているソフト」が、Ubuntuが用意した `python3-xxxxx`\nといったパッケージに依存している場合、Ubuntu標準でインストールされているPython-3.6.9にそれらのライブラリがインストールされます。\n\nしかし、「初期から入っているソフト」が独自にvenv等の仮想環境を用意してそのなかに依存ライブラリを入れる可能性もありそうです。\n\n> 2. Pythonの最新版である3.8を使いたいのと、ローカルにライブラリ入れすぎて管理できなくなるのが怖いので仮想環境を作ることで解決したい。\n>\n\n仮想環境を作るか、Pythonを複数バージョンインストールすることで解決できます。 \n仮想環境には「VMWaeやVirtualBoxのような仮想マシン」と、「Pythonの仮想環境」がありますが、文脈から後者のことかと思います。 \n今回の場合、「最初からインストールされているPython-3.6以外に、Python-3.8もインストールしたうで、Python-3.8を使ってvenvでPython仮想環境を作る」必要があります。\n\n「venvでPythonの仮想環境をつくってそこにPython-3.8をインストールする」ということはできません。 \npyenvやcondaであればそういったこともできそうに見えますが、考え方はあくまで「Python-3.8もインストールしたうで、Python-3.8を使ってPython仮想環境を作る」ことになります。\n\n> 3. Python3.6.9が入っているので標準ライブラリである”venv”が使える。\n>\n\nUbuntuの場合は「いいえ」です。 \nPython-3.5以降、デフォルトでvenvが使えるのですが、Ubuntuはvenvを取り除いて別パッケージにしてしまっているため、デフォルトではvenvが使えません。 \nUbuntuで `venv` を使うには、 `apt install python3-venv` を実行してインストールする必要があります。\n\n> 4.\n> 新規のディレクトリを作成し”venv”で仮想環境を作成、そのディレクトリ内のみで稼働するPython3.8や任意のライブラリの入った環境を作れる。\n>\n\nはい。 \nただし、前述したように「仮想環境にPython3.8をインストールするのではない」ことに注意して下さい。 \n以下のコマンドのように実行して、Python-3.8で仮想環境を作る必要があります。\n\n```\n\n $ python3.8 -m venv my-venv-dir\n $ source my-venv-dir/bin/activate\n (my-venv-dir) $ python3 -V\n Python 3.8.0\n (my-venv-dir) $ pip3 install requests\n (my-venv-dir) $ pip3 list\n \n```\n\nmy-venv-dir 仮想環境を有効化するのに `my-venv-dir/bin/activate` を実行しています。 \nその後で実行した `pip3` コマンドでは、 `my-venv-dir` 仮想環境へのインストールやインストール済みの一覧などを確認できます。\n\n> 5. 環境が壊れてもディレクトリを削除すれば別途pipインストールしたライブラリも消える\n>\n\nはい。 \n上記例で言えば、仮想環境を有効化した状態で `pip3 install requests` でインストールしたライブラリ群は `my-venv-dir`\nディレクトリ以下にのみインストールされているため、ディレクトリを消せば消えます。\n\n> 6.\n> Python3.8で動かしたい、または別途入れたライブラリを動かしたいPythonスクリプトを書いたら.pyファイルを仮想環境ディレクトリに移動させてターミナルから.pyを動かせば問題なく動く(またはそもそも仮想環境下でコードを書いて実行でもいいですが)\n>\n\nいいえ。スクリプトがどのディレクトリにあるかは関係ありません。\n\n「有効化したPython仮想環境」で動作させてください。 \nPython仮想環境を有効化するには、 `source my-venv-dir/bin/activate` を実行します。\n\nあるいは、 `my-venv-dir/bin/python3 script.py`\nのように、仮想環境内のpythonコマンドを使ってスクリプトを実行してください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-02T07:27:22.930", "id": "66201", "last_activity_date": "2020-05-02T07:27:22.930", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "806", "parent_id": "66043", "post_type": "answer", "score": 1 } ]
66043
66201
66201
{ "accepted_answer_id": "66048", "answer_count": 3, "body": "独学で学習を始めた超初心者です。 \nPythonをバージョンアップしたいのですが、どうしてもうまくいきません。\n\n自分で色々調べ、pyenvを使用して Python3.5 をインストールしたのですが、切り替えがうまくいかないようです。\n\n↓試した記事 \n<https://qiita.com/1000ch/items/93841f76ea52551b6a97>\n\n↓試した手順 \n▼pyenv で Pythonをインストール`$ pyenv install 3.5.9` \n▼上記記事の指示のまま`$ pyenv rehash` \n▼使う Python を指定する`$ pyenv global 3.5.9` \n▼以下の通り、パスが .pyenv 配下の pythonを向かない。\n\n```\n\n $ which python\n /usr/bin/python\n \n```\n\nOS=macOS Catalina\n\n現状以下のバージョンです。\n\n```\n\n $ python --version\n Python 2.7.16\n \n```\n\nPython2.7.16のファイルパスは以下です。\n\n```\n\n $ which python\n /usr/bin/python\n \n```\n\npyenvのファイルパス\n\n```\n\n $ which pyenv\n /usr/local/bin/pyenv\n \n```\n\npyenvのバージョン\n\n```\n\n $ pyenv versions\n system\n * 3.5.6 (set by /Users/yusukekurimoto/.python-version)\n 3.5.7\n 3.5.9\n \n```\n\nどうぞよろしくお願い申し上げます。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T02:47:29.487", "favorite_count": 0, "id": "66047", "last_activity_date": "2020-05-01T08:29:16.943", "last_edit_date": "2020-04-28T04:54:06.837", "last_editor_user_id": "39734", "owner_user_id": "39734", "post_type": "question", "score": 0, "tags": [ "python", "python3", "python2", "pyenv" ], "title": "pyenvを使ったPython2.7からPython3.5へバージョンアップの方法を教えていただけますか?", "view_count": 441 }
[ { "body": "pyenv を使った場合、忘れそうなのは以下の点です。\n\n * pyenv のパスを通す。`echo $PATH` の出力に pyenv へのパスが含まれていますか? 設定したはずなのに含まれていない場合、設定したあとシェルを再起動するなどして設定スクリプトを読み込ませましたか?\n * `pyenv rehash` する。\n * `pyenv global` によるシステム全体のバージョン指定か、`pyenv local` による特定のディレクトリ下でのバージョン指定を行う。特に `pyenv local` の場合は `.python-version` があるディレクトリ下でないと駄目です。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T03:04:14.010", "id": "66048", "last_activity_date": "2020-04-28T03:04:14.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "66047", "post_type": "answer", "score": 1 }, { "body": "通りがかりですまないが、件の参考記事の「pyenv にパスを通す」は実行しただろうか?\n\n[pyenv にパスを通す | pyenvを使ってMacにPythonの環境を構築する -\nQiita](https://qiita.com/1000ch/items/93841f76ea52551b6a97#pyenv-%E3%81%AB%E3%83%91%E3%82%B9%E3%82%92%E9%80%9A%E3%81%99)\n\nもし、やっているなら、次に以下のコマンドでシェルを確認してほしい。\n\n```\n\n echo $SHELL\n \n```\n\nmacOS Catalina からはデフォルトのシェルが `zsh` になってしまったのだが、上記コマンドの結果が `bash` でないのなら、「pyenv\nにパスを通す」が `bash` のプロファイルに対して行われたが、`zsh` のプロファイルにないため機能していない可能性がある。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-29T23:48:27.330", "id": "66133", "last_activity_date": "2020-04-30T00:17:25.827", "last_edit_date": "2020-04-30T00:17:25.827", "last_editor_user_id": "3060", "owner_user_id": "39886", "parent_id": "66047", "post_type": "answer", "score": 1 }, { "body": "シンボリックリンクにパスを追加することによって、うまくいきました。\n\n**■手順** \n▼`env`で現在のPATHをチェック \n▼`sudo ln -s /Library/Frameworks/Python.framework/Versions/3.5/bin/python3\n/usr/local/bin/python`でpython3のファイルがあるディレクトリをシンボリックリンクに追加 \n▼`conda create -n py35 python=3.5 anaconda`で3.5をインストール \n▼`conda activate py35`でアクティベート\n\n完了\n\nみなさまありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-01T07:54:11.087", "id": "66174", "last_activity_date": "2020-05-01T08:29:16.943", "last_edit_date": "2020-05-01T08:29:16.943", "last_editor_user_id": "39734", "owner_user_id": "39734", "parent_id": "66047", "post_type": "answer", "score": 2 } ]
66047
66048
66174
{ "accepted_answer_id": "66051", "answer_count": 1, "body": "# 質問\n\nReact公式ガイドの[6.イベント処理](https://ja.reactjs.org/docs/handling-\nevents.html)の最後の項目に以下のようなコードがありました。\n\n> ループ内では、イベントハンドラに追加のパラメータを渡したくなることがよくあります。例えば、id という行の ID\n> がある場合、以下のどちらでも動作します:\n```\n\n <button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button>\n <button onClick={this.deleteRow.bind(this, id)}>Delete Row</button>\n \n```\n\nドキュメントに記載のある、「ループ内で、イベントハンドラに追加のパラメータを渡す」という例がイメージできません。 \n以下のコードと何が異なっているのか、ご教示いただけますと幸いです。\n\n```\n\n <button onClick={id => this.deleteRow(id)>Delete Row</button>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T03:53:24.557", "favorite_count": 0, "id": "66049", "last_activity_date": "2020-04-28T04:24:09.217", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39848", "post_type": "question", "score": 1, "tags": [ "reactjs" ], "title": "Reactのイベントハンドラに引数を渡す場合について", "view_count": 1266 }
[ { "body": "もし、ガイドを前から順番に読みすすめている途中なのであれば、まずは[8\\. リストと\nkey](https://ja.reactjs.org/docs/lists-and-keys.html)まで読みすすめればいいかもしれません。\n\nループ、リストレンダリング、ようするには配列をループでレンダリングするようなケースにおいてはハンドラにその配列のうち当該要素やそのプロパティなどを渡す必要が多くの場合に存在するでしょう。これを実現するための手段、ということです。\n\n```\n\n class ButtonList extends React.Component {\r\n handleClick(item, e) {\r\n console.log('item is:', item)\r\n //console.log('event is:', e)\r\n //console.log('this is:', this)\r\n }\r\n render() {\r\n const arr = ['hoge', 'fuga', 'piyo']\r\n \r\n return <div>{\r\n arr.map(item =>\r\n <button onClick={ e => this.handleClick(item, e)} >Click me</button>\r\n )\r\n }</div>\r\n }\r\n \r\n }\r\n \r\n ReactDOM.render( <ButtonList / > ,\r\n document.getElementById('root')\r\n )\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js\"></script>\r\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js\"></script>\r\n \r\n <div id=\"root\"></div>\n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T04:24:09.217", "id": "66051", "last_activity_date": "2020-04-28T04:24:09.217", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "66049", "post_type": "answer", "score": 1 } ]
66049
66051
66051
{ "accepted_answer_id": "66053", "answer_count": 1, "body": "### 前提・実現したいこと\n\n辞書のcopy()に変更を加えているのにかかわらず元の辞書も変更するのはなぜか?\n\nまた、fromkeys(辞書)に変更を加えると、指定したkey以外にも変更が加わるのはなぜか?\n\n### copy()\n\ncopy()を使用したnew_dictsに変更を加えているのにもかかわらず、元のdictsも変更されている。\n\n```\n\n dicts = {'A': [[0, 0]], 'B': [[3, 3]]}\n new_dicts = dicts.copy()\n \n new_dicts[\"A\"].append(1)\n print(dicts)\n \n >> {'A': [[0, 0], 1], 'B': [[3, 3]]}\n \n```\n\n### fromkeys(辞書)\n\nキーは\"A\"を指定しているにもかかわらず、\"B\"の値まで変更されている。\n\n```\n\n dicts = {'A': [[0, 0]], 'B': [[3, 3]]}\n new_dicts = dict.fromkeys(dicts,[])\n \n new_dicts[\"A\"].append(1)\n print(new_dicts)\n \n >> {'A': [1], 'B': [1]}\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T04:39:14.420", "favorite_count": 0, "id": "66052", "last_activity_date": "2020-04-28T07:03:18.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "python" ], "title": "辞書のcopy()とdict.fromkeys(辞書)の振る舞いについて知りたい", "view_count": 122 }
[ { "body": "> 辞書のcopy()に変更を加えているのにかかわらず元の辞書も変更するのはなぜか?\n\n[`copy()`が浅いコピー](https://docs.python.org/ja/3/library/stdtypes.html#dict.copy)だからです。新しい辞書オブジェクトが作られますが、辞書の中の値は共有されます。\n\n[`copy.deepcopy(dicts)`](https://docs.python.org/ja/3/library/copy.html#copy.deepcopy)とすることで値もコピーになります。\n\n* * *\n\n> また、fromkeys(辞書)に変更を加えると、指定したkey以外にも変更が加わるのはなぜか?\n\n[`fromkeys()`](https://docs.python.org/ja/3/library/stdtypes.html#dict.fromkeys)のマニュアルに書いてあります。\n\n> All of the values refer to just a single instance, so it generally doesn't\n> make sense for value to be a mutable object such as an empty list.\n\n「辞書のすべてのエントリが同一の値を参照するため、空リストなどの変更可能なオブジェクトを指定するのは一般的に役に立ちません。」\n\nリストを初期値としたい場合は、`fromkeys()`を使わないでループで初期化するか、\n\n```\n\n new_dict = {key: [] for key in dicts.keys()}\n \n```\n\n初期化を諦めて\n[`setdefault()`](https://docs.python.org/ja/3/library/stdtypes.html#dict.setdefault)を使うといいかもしれません。\n\n```\n\n new_dict = {}\n new_dict.setdefault(\"A\", []).append(1)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T05:18:20.793", "id": "66053", "last_activity_date": "2020-04-28T07:03:18.520", "last_edit_date": "2020-04-28T07:03:18.520", "last_editor_user_id": "3475", "owner_user_id": "3475", "parent_id": "66052", "post_type": "answer", "score": 2 } ]
66052
66053
66053
{ "accepted_answer_id": "66370", "answer_count": 1, "body": "ASP.NET Core MVC(Core 3.1)のWebアプリケーションにおいて、 \n1 Request、1 Context内限定のGlobal変数を置きたいのですが、 \nどのような方法が適切でしょうか。\n\n単純なSingletonを作り、処理完了後破棄するような実装の場合、 \n並列で動いたContext間で情報が共有されるため問題があります。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T06:49:31.770", "favorite_count": 0, "id": "66057", "last_activity_date": "2020-05-07T02:59:49.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8647", "post_type": "question", "score": 0, "tags": [ "mvc", ".net-core", "asp.net-core" ], "title": "ASP.NET Core MVCにてCurrent Context限定のGlobal変数を作りたい", "view_count": 641 }
[ { "body": "HttpContext.Items が実質的にCurrentContextのGlobal変数として働く。\n\nAspNetCoreCurrentRequestContext と組み合わせることで、Applicationのどの場所からも参照することが可能になる。 \n<https://qiita.com/taiga_takahari/items/d224b273a7ca66439429>\n\n```\n\n AspNetCoreHttpContext.Current.Items[\"SomeKeyName\"] = \"SomeValue\";\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-07T02:59:49.343", "id": "66370", "last_activity_date": "2020-05-07T02:59:49.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8647", "parent_id": "66057", "post_type": "answer", "score": 0 } ]
66057
66370
66370
{ "accepted_answer_id": "66083", "answer_count": 1, "body": "JRIを使い、正規分布の下に色を塗りたいなと考えています。Rで動く以下のようなコードをengine.evalを前につけて実行させようと思ったのですが、グラフが作成できません\n\n```\n\n curve(dnorm(x,171,10),xlim=c(140,210))\n cord.x=c(160,seq(160,180,length=100),180)\n cord.y=c(0,dnorm(seq(160,180,length=100),171,10),0)\n polygon(cord.x,cord.y,col='skyblue')\n abline(h=0)\n \n```\n\njavaではこう書きました。\n\n```\n\n Rengine engine = new Rengine(new String[]{\"--no-save\"}, false, null);\n engine.eval(\"png('curve.png', 640, 480)\");\n engine.eval(\"curve(dnorm(x,171,10),xlim=c(140,210))\");\n engine.eval(\"cord.x=c(160,seq(160,180,length=100),180)\");\n engine.eval(\"cord.y=c(0,dnorm(seq(160,180,length=100),171,10),0)\");\n engine.eval(\"polygon(cord.x,cord.y,col='skyblue')\");\n engine.eval(\"abline(h=0)\");\n engine.eval(\"dev.off()\");\n engine.end();\n \n```\n\nこれではグラフが作成できないのですが何がいけないのでしょうか? \n教えてくださると幸いです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:08:33.463", "favorite_count": 0, "id": "66059", "last_activity_date": "2020-04-28T16:56:46.340", "last_edit_date": "2020-04-28T07:22:48.130", "last_editor_user_id": "7290", "owner_user_id": "36217", "post_type": "question", "score": 0, "tags": [ "java", "r" ], "title": "正規分布の下に色を塗る。", "view_count": 81 }
[ { "body": "上記の `Java` のコードで 下記のような `curve.jpg` ファイルができましたが、どこが問題なのでしょう。\n\n参考までに私の動作確認した手順を書いておきます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/Y0LiH.png)](https://i.stack.imgur.com/Y0LiH.png)\n\nJRI を詳しく知らなかったので <http://rforge.net/JRI/> を参考に インストール。 \n動作確認しました。\n\n### 設定手順\n\nEclipse をインストール \nR を インストール <https://www.r-project.org/>(私は R 4.0.0 for Windows を使いました) \nR Console で `install.packages(\"rJava\")` を 実行 \nユーザの `C:\\Users\\[ユーザ名]\\Documents\\R\\win-library\\4.0\\rJava` \nフォルダに ライブラリ等がインストールされました。\n\nEclipse で 質問にある Java ソースを記述\n\nビルドバスには さきほど `rJava` パッケージをインストールした時の \n`C:\\Users\\[ユーザ名]\\Documents\\R\\win-library\\4.0\\rJava\\jri` \nにある `JRI.jar` `JRIEngine.jar` `REngine.jar` を追加。\n\nJava プログラムを実行するときの VM arguments に \n`-Djava.library.path=C:\\Users\\[ユーザ名]\\Documents\\R\\win-\nlibrary\\4.0\\rJava\\jri\\x64` \n環境変数 PATH に `C:\\Program Files/R/R-4.0.0/bin/x64` \nを指定して プログラムを実行。\n\nすると Java の プロジェクトフォルダの中に 上記のような画像ファイルが作成されました。\n\nにゅZen さんの手順と何が違っていますか?\n\n### dotnet Core の場合\n\n参考までに dotnet core だと超簡単で\n\n```\n\n dotnet new console\n dotnet add package R.Net\n ** ここで Program.cs 編集して保存\n dotnet run\n \n```\n\nだけで同じ画像が作成されました。\n\n`Program.cs` の例\n\n```\n\n using System;\n using RDotNet;\n \n namespace test1\n {\n class Program\n {\n static void Main(string[] args)\n {\n // R.dll のある ディレクトリを設定する\n REngine.SetEnvironmentVariables(@\"C:\\Program Files\\R\\R-4.0.0\\bin\\x64\");\n \n REngine engine = REngine.GetInstance();\n engine.Evaluate(@\"\n png('curve.png', 640, 480)\n curve(dnorm(x,171,10),xlim=c(140,210))\n cord.x=c(160,seq(160,180,length=100),180)\n cord.y=c(0,dnorm(seq(160,180,length=100),171,10),0)\n polygon(cord.x,cord.y,col='skyblue')\n abline(h=0)\n dev.off()\n \");\n \n }\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T16:43:20.760", "id": "66083", "last_activity_date": "2020-04-28T16:56:46.340", "last_edit_date": "2020-04-28T16:56:46.340", "last_editor_user_id": "18851", "owner_user_id": "18851", "parent_id": "66059", "post_type": "answer", "score": 1 } ]
66059
66083
66083
{ "accepted_answer_id": "66084", "answer_count": 1, "body": "**クラスを使用せず、1ファイルから呼び出す際は、下記で期待通り動作するのですが、** \nindex.php\n\n```\n\n require '../../composer/vendor/autoload.php';\n use Abraham\\TwitterOAuth\\TwitterOAuth;\n require_once('config.php');\n new TwitterOAuth(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_SECRET);\n \n```\n\n* * *\n\n**複数クラス(複数ファイル)から呼び出す際、下記ではエラー発生します**\n\n> Uncaught Error: Class 'TwitterOAuth' not found\n\nconfig.php\n\n```\n\n require '../../composer/vendor/autoload.php';\n use Abraham\\TwitterOAuth\\TwitterOAuth;\n \n```\n\nHogeController.php\n\n```\n\n class HogeController extends Controller{\n new TwitterOAuth(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_SECRET);\n }\n \n```\n\n* * *\n\n**複数クラス(複数ファイル)から呼び出す際は、どうやって記述すればよいですか?**\n\nconfig.php\n\n```\n\n require '../../composer/vendor/autoload.php';\n \n```\n\n方法A.各クラス(各ファイル)毎に下記記述が必要ですか? \nHogeController.php\n\n```\n\n use Abraham\\TwitterOAuth\\TwitterOAuth;\n \n class HogeController extends Controller{\n new TwitterOAuth(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_SECRET);\n }\n \n```\n\n方法B.そこからincludeする場合は、include先のファイルでも use が必要ですか?\n\nHogeController.php\n\n```\n\n use Abraham\\TwitterOAuth\\TwitterOAuth;\n \n class HogeController extends Controller{\n include(dirname(__FILE__).'/twitter.php');\n }\n \n```\n\ntwitter.php\n\n```\n\n use Abraham\\TwitterOAuth\\TwitterOAuth;\n \n new TwitterOAuth(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_SECRET);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:38:07.147", "favorite_count": 0, "id": "66062", "last_activity_date": "2020-04-28T19:07:50.223", "last_edit_date": "2020-04-28T07:43:53.573", "last_editor_user_id": "7886", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "php", "composer" ], "title": "名前空間が設定されているライブラリを、複数クラス(複数ファイル)から呼び出す方法について", "view_count": 72 }
[ { "body": "ちとご質問の意味を勘違いしているかもしれませんが、requireなどで読み込まれるファイルをうまく記述することで、`use`を各ファイルごとに記述しなくてもいいようにできないか?と言うことだと理解しました。\n\nPHPの公式ドキュメントに以下のような記載があります。\n\n[名前空間の使用法:\nエイリアス/インポート](https://www.php.net/manual/ja/language.namespaces.importing.php)\n\n> **注意:** \n> インポート規則はファイル単位のものです。つまり、インクルードされたファイルは インクロード元の親ファイルのインポート規則を 引き継ぎません。\n\n(公式サイトなのに単純な綴りミスがありますが、それは置いといて。)\n\n## _複数クラス(複数ファイル)から呼び出す際は、どうやって記述すればよいですか?_\n\n上記の記述から、\n\n### _方法A.各クラス(各ファイル)毎に下記記述が必要ですか?_\n\n(「下記記述」がどこからどこまでを指すのかが不明ですが) \n→`use Abraham\\TwitterOAuth\\TwitterOAuth;`は各ファイルごとに必要\n\n### _方法B.そこからincludeする場合は、include先のファイルでも use が必要ですか?_\n\n→Yes.\n\nと言うことが導き出されます。あなたの経験された事象についても、きちんと公式サイトの記述通り動いているように思われます。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T19:07:50.223", "id": "66084", "last_activity_date": "2020-04-28T19:07:50.223", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "66062", "post_type": "answer", "score": 1 } ]
66062
66084
66084
{ "accepted_answer_id": "66069", "answer_count": 1, "body": "vagrantのLinuxにminikubeを動かしたいですが、エラーとなり止まっています。 \ndockerやkubanetesを勉強したいためです。\n\n手順1. \npower-shellで、Cドライブ直下で以下のコマンドを実行\n\n```\n\n git clone https://github.com/takara9/vagrant-minikube\n \n```\n\n手順2. \npower-shellで、以下のコマンドを実行\n\n```\n\n cd vagrant-minikube\n \n```\n\n手順3. \npower-shellで、以下のコマンドを実行\n\n```\n\n vagrant up\n \n```\n\n### エラーメッセージ\n\n```\n\n TASK [Add GlusterFS Repository] ************************************************\n changed: [minikube]\n \n TASK [Install GlusterFS] *******************************************************\n changed: [minikube]\n \n TASK [download] ****************************************************************\n changed: [minikube]\n \n TASK [download] ****************************************************************\n changed: [minikube]\n \n TASK [start Minikube temporary] ************************************************\n fatal: [minikube]: FAILED! => {\"changed\": true, \"cmd\": [\"/usr/local/bin/minikube\", \"start\", \"--vm-driver\", \"none\"], \"delta\": \"0:00:00.330972\", \n \"end\": \"2020-04-28 07:16:58.499318\", \"msg\": \"non-zero return code\", \"rc\": 78, \"start\": \"2020-04-28 07:16:58.168346\", \"stderr\": \"X Sorry, Kubern\n etes v1.18.0 requires conntrack to be installed in root's path\", \"stderr_lines\": [\"X Sorry, Kubernetes v1.18.0 requires conntrack to be install\n ed in root's path\"], \"stdout\": \"* minikube v1.9.2 on Ubuntu 16.04 (vbox/amd64)\\n* Using the none driver based on user configuration\", \"stdout_l\n ines\": [\"* minikube v1.9.2 on Ubuntu 16.04 (vbox/amd64)\", \"* Using the none driver based on user configuration\"]}\n \n PLAY RECAP *********************************************************************\n minikube : ok=11 changed=10 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 \n \n```\n\n途中まではうまくいっている様子だが、以下のエラーメッセージが出力されてしまいます。 \nこの作業を行うまでは、windowsの管理者アカウントが漢字名であったため、英語名の管理者権限を作りなおして実施しました。 \ndockerやminikubeを何度か入れなおしたりもしております。 \nまた、windows10もhomeでしたが、dockerが正しく動かなかったため、proにしました。\n\n同じような事象がないか調べましたが、なかなか見つからない状況です。 \n当方、インフラ構築は不慣れで、エラーを見ても見当がつかないです。 \nご存知の方、詳しい方がいらっしゃったら、ご回答いただきたいです。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:39:02.650", "favorite_count": 0, "id": "66063", "last_activity_date": "2020-04-28T09:15:21.767", "last_edit_date": "2020-04-28T08:25:14.200", "last_editor_user_id": "32986", "owner_user_id": "39856", "post_type": "question", "score": 0, "tags": [ "linux", "docker", "ansible", "kubernetes" ], "title": "vagrantのLinuxでminikubeを動かしたい", "view_count": 223 }
[ { "body": "最近のバージョンではnoneドライバで動作させる場合に `conntrack`\nというパッケージのインストールも必要になったようで、エラーメッセージはそれを表しています:\n\n> X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's\n> path\n\n * [none driver integration tests: k8s 1.18 needs conntrack installed #7179](https://github.com/kubernetes/minikube/issues/7179)\n\nセットアップ時にこのパッケージもインストールするようにすれば([差分](https://github.com/takara9/vagrant-\nminikube/pull/1/files))動作しました。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T09:15:21.767", "id": "66069", "last_activity_date": "2020-04-28T09:15:21.767", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "66063", "post_type": "answer", "score": 1 } ]
66063
66069
66069
{ "accepted_answer_id": null, "answer_count": 2, "body": "以下の様な文字列を含むデータがあり、1列目のみ整数にしたいのですが、うまくいかずエラーが表示エラーがでます。 \nなぜでしょうか。 \nよくわかりません。\n\nデータは以下。\n\n```\n\n [['id_NO', 'PROC_YM', 'CL_START', 'CL_STOP'], \n ['000001', '201912', '2019/12/1', '2019/12/31'],\n ['000022', '201912', '2019/12/1', '2019/12/31'], \n ['000333', '201912', '2019/12/1', '2019/12/31'], \n ['004444', '201912', '2019/12/1', '2019/12/31'], \n ['055555', '201912', '2019/12/1', '2019/12/31'], \n ['666666', '201912', '2019/12/1', '2019/12/31'], \n ['020000', '201912', '2019/12/1', '2019/12/31'], \n ['003300', '201912', '2019/12/1', '2019/12/31'], \n ['040044', '201912', '2019/12/1', '2019/12/31']]\n \n```\n\nスクリプト\n\n```\n\n date['id_NO'] = date['id_NO'].astype(int)\n print(date)\n \n```\n\nエラー内容\n\n```\n\n TypeError: list indices must be integers or slices, not str\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T07:52:17.990", "favorite_count": 0, "id": "66064", "last_activity_date": "2020-04-28T09:03:59.817", "last_edit_date": "2020-04-28T09:03:59.817", "last_editor_user_id": "3060", "owner_user_id": "38096", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "文字列を整数に変換できない。", "view_count": 226 }
[ { "body": "* データの書き方を見るに Python 組み込みの普通のリストでしょうか。Python の普通のリストはあくまで単なるリストであり、辞書や pandas DataFrame のように文字列を添え字として使いません。`date[1][0]` のように整数を添え字とします。あるいはこのリストを元に pandas DataFrame などに変換してから作業しても良いでしょう。\n * このデータが pandas DataFrame や NumPy Array だったとしても、列の名前として `'id_NO'` 等が使われているのではなく、単に 1 行目に列名が入っているだけに見えます。適切に列の名前を設定する必要があります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T08:07:48.583", "id": "66066", "last_activity_date": "2020-04-28T08:54:19.080", "last_edit_date": "2020-04-28T08:54:19.080", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "66064", "post_type": "answer", "score": 1 }, { "body": "質問にある `.astype()` は `numpy.ndarray` および `pandas.Series`,`pandas.DataFrame` の\nmethod ですので、通常のリストには使用できません。\n\n今回のデータはテーブルデータのようですので、`pandas.DataFrame` に変換してから、質問のmethodを使用するのが良いのかと思います。\n\n```\n\n import pandas as pd\n \n data = [['id_NO', 'PROC_YM', 'CL_START', 'CL_STOP'],\n ['000001', '201912', '2019/12/1', '2019/12/31'],\n ['000022', '201912', '2019/12/1', '2019/12/31'],\n ['000333', '201912', '2019/12/1', '2019/12/31'],\n ['004444', '201912', '2019/12/1', '2019/12/31'],\n ['055555', '201912', '2019/12/1', '2019/12/31'],\n ['666666', '201912', '2019/12/1', '2019/12/31'],\n ['020000', '201912', '2019/12/1', '2019/12/31'],\n ['003300', '201912', '2019/12/1', '2019/12/31'],\n ['040044', '201912', '2019/12/1', '2019/12/31']]\n \n df = pd.DataFrame(data[1:], columns=data[0])\n df['id_NO'] = df['id_NO'].astype(int)\n print(df)\n # id_NO PROC_YM CL_START CL_STOP\n #0 1 201912 2019/12/1 2019/12/31\n #1 22 201912 2019/12/1 2019/12/31\n #2 333 201912 2019/12/1 2019/12/31\n #3 4444 201912 2019/12/1 2019/12/31\n #4 55555 201912 2019/12/1 2019/12/31\n #5 666666 201912 2019/12/1 2019/12/31\n #6 20000 201912 2019/12/1 2019/12/31\n #7 3300 201912 2019/12/1 2019/12/31\n #8 40044 201912 2019/12/1 2019/12/31\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T08:20:50.827", "id": "66067", "last_activity_date": "2020-04-28T08:20:50.827", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24801", "parent_id": "66064", "post_type": "answer", "score": 2 } ]
66064
null
66067
{ "accepted_answer_id": "66080", "answer_count": 1, "body": "## 概要\n\n現在、GatsbyJSでWebサイトを作っていますが、CSSの重なり順で詰まってしまいました。 \n具体的には、headerを`position sticky; top:\n0;`で最上部に固定し、そのheaderはページ共通にするためにlayoutコンポーネントに入れています。また、その一つ下に`<main>{children}</main>`の様にして、main要素として子コンポーネントを表示する様にしています。 \nそして、ページをスクロールしたときにはmain要素のコンテンツがheaderの下に潜る様にしようと思い、`z-index`などを指定してみましたが、中々思った通りの挙動をしてくれません。 \nレイアウトには`styled-components`を使用しています。\n\n自分なりに調べてみましたが、解決せず。 \nどなたか解決方法のご教授お願いいたします。\n\n## 該当するコード\n\n```\n\n // header.js\n \n import React from 'react';\n import styled from 'styled-components';\n import { Primary } from '../const/color';\n import Menu from '../images/Menu.png';\n import { Link } from 'gatsby';\n \n const Header = () => (\n <$Header>\n <$Ul>\n <$Li style={{ color: `${Primary}` }}>\n <$Link to=\"/\">Home</$Link>\n </$Li>\n <$Li>\n <img src={Menu} alt=\"Menubar\" />\n </$Li>\n </$Ul>\n </$Header>\n );\n \n const $Header = styled.header`\n width: 100%;\n height: 50px;\n position: sticky;\n top: 0;\n z-index: 100;\n \n box-shadow: 1px 0 1em;\n `;\n const $Ul = styled.ul`\n height: 100%;\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin: auto;\n `;\n const $Li = styled.li`\n margin: 0 1em;\n `;\n const $Link = styled(Link)`\n text-decoration: none;\n color: ${Primary};\n `;\n \n export default Header;\n \n \n```\n\n```\n\n // pages/about.js\n \n import React from 'react';\n import styled from 'styled-components';\n import Title from '../images/title/About.png';\n import Layout from '../layouts';\n \n export default () => (\n <Layout>\n <$H1>\n <img src={Title} alt=\"Title for About\" style={{ margin: '0 auto' }} />\n </$H1>\n <h1>test</h1>\n </Layout>\n );\n \n const $H1 = styled.h1`\n margin-top: 40px;\n `;\n \n \n```\n\n```\n\n // layout/index.js\n \n import React from 'react';\n import styled from 'styled-components';\n import Footer from '../components/footer';\n import Header from '../components/header';\n \n export default ({ children }) => (\n <Wrapper>\n <Header />\n <main>{children}</main>\n <Footer />\n </Wrapper>\n );\n \n const Wrapper = styled.div`\n width: 100%;\n position: relative;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n `;\n \n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T08:03:02.337", "favorite_count": 0, "id": "66065", "last_activity_date": "2020-04-28T14:31:34.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32711", "post_type": "question", "score": 0, "tags": [ "css", "reactjs", "gatsby" ], "title": "position: sticky; しているheaderのz-indexが効かない。", "view_count": 1216 }
[ { "body": "headerにbackground-colorが設定されておらず、背景が透過されているだけでした…。 \n確認不足で申し訳ございません…。 \nご回答ありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T14:31:34.890", "id": "66080", "last_activity_date": "2020-04-28T14:31:34.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32711", "parent_id": "66065", "post_type": "answer", "score": 1 } ]
66065
66080
66080
{ "accepted_answer_id": null, "answer_count": 1, "body": "確かにこのままでも実行は可能ですが、冗長にならないようにどうすればいいのかと思ったので質問させて頂きました。 \n試した事は「my_goals」−「enemy_goals」ですが「Unknown columns」になってしまいました。\n\n元となるSQLは、下記リンク先の正解部分です。from句に全てまとめるのでしょうか? \nバージョンは8.0.19です\n\n```\n\n SELECT p1.kickoff, c1.name AS my_country, c2.name AS enemy_country, \n c1.ranking AS my_ranking, c2.ranking AS enemy_ranking,\n (SELECT COUNT(g1.id) FROM goals g1 WHERE p1.id = g1.pairing_id) AS my_goals,\n (\n SELECT COUNT(g2.id) \n FROM goals g2 \n LEFT JOIN pairings p2 ON p2.id = g2.pairing_id\n WHERE p2.my_country_id = p1.enemy_country_id AND p2.enemy_country_id = p1.my_country_id\n ) AS enemy_goals,\n -- 追加ここから\n (SELECT COUNT(g1.id) FROM goals g1 WHERE p1.id = g1.pairing_id) - ( \n SELECT COUNT(g2.id) \n FROM goals g2 \n LEFT JOIN pairings p2 ON p2.id = g2.pairing_id\n WHERE p2.my_country_id = p1.enemy_country_id AND p2.enemy_country_id = p1.my_country_id\n ) AS goal_diff\n -- 追加ここまで\n FROM pairings p1\n LEFT JOIN countries c1 ON c1.id = p1.my_country_id\n LEFT JOIN countries c2 ON c2.id = p1.enemy_country_id\n WHERE c1.group_name = 'C' AND c2.group_name = 'C'\n ORDER BY p1.kickoff, c1.ranking\n \n```\n\n[SQL練習問題 – 問17 | TECH\nProjin](https://tech.pjin.jp/blog/2016/08/26/sql%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C-%E5%95%8F17/)\n\n> ### 問題:問題16の結果に得失点差を追加してください。\n>\n> 表示するカラム \n> ・キックオフ日時 \n> ・自国名 \n> ・対戦相手国名 \n> ・自国FIFAランク \n> ・対戦相手国FIFAランク \n> ・自国のゴール数 \n> ・対戦国のゴール数 \n> ・得失点差(※追加!)\n>\n> ソート順 \n> ・キックオフ日時 \n> ・自国FIFAランク\n>\n>\n> [![画像の説明をここに入力](https://i.stack.imgur.com/Y5s2U.jpg)](https://i.stack.imgur.com/Y5s2U.jpg)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T09:21:31.120", "favorite_count": 0, "id": "66070", "last_activity_date": "2020-10-28T02:04:30.363", "last_edit_date": "2020-04-29T05:28:25.793", "last_editor_user_id": "3068", "owner_user_id": "39860", "post_type": "question", "score": 0, "tags": [ "mysql", "sql" ], "title": "クエリが冗長なので同じクエリを何回も書かないようにしたい", "view_count": 282 }
[ { "body": "リンク先の模範回答で`my_goals`と`enemy_goals`カラムを求める副問い合わせを`goal_diff`カラムにコピペしている部分に関して回答します。\n\n> 試した事は「my_goals」−「enemy_goals」ですが「Unknown columns」になってしまいました。\n\nはい。 \nselect句で求めた`my_goals`カラムなどを、同一のselect句の中で使いまわすことはできません。(下のSQLはエラーになります)\n\n```\n\n SELECT 1 AS a,\n 2 - a AS b -- Unknown columns!\n FROM hoge; -- ダミーテーブル\n \n```\n\n冗長にならないためにはfrom句に全てまとめるのが正解のひとつです。 \n変更前のSQLを大きな副問い合わせとして括弧で囲えば、その外側で`my_goals - enemy_goals`を取得することができます。 \n冗長性は減りましたが、副問い合わせでSQLの階層が深くなりました。\n\n```\n\n SELECT t.*, my_goals - enemy_goals AS goal_diff\n FROM (\n SELECT p1.kickoff, c1.name AS my_country, c2.name AS enemy_country, \n c1.ranking AS my_ranking, c2.ranking AS enemy_ranking,\n (SELECT COUNT(g1.id) FROM goals g1 WHERE p1.id = g1.pairing_id) AS my_goals,\n (\n SELECT COUNT(g2.id) \n FROM goals g2 \n LEFT JOIN pairings p2 ON p2.id = g2.pairing_id\n WHERE p2.my_country_id = p1.enemy_country_id AND p2.enemy_country_id = p1.my_country_id\n ) AS enemy_goals\n FROM pairings p1\n LEFT JOIN countries c1 ON c1.id = p1.my_country_id\n LEFT JOIN countries c2 ON c2.id = p1.enemy_country_id\n WHERE c1.group_name = 'C' AND c2.group_name = 'C'\n ORDER BY p1.kickoff, c1.ranking\n ) AS t;\n \n```\n\nもう一つの正解はwith句を使って試合・チームごとのゴール数を取得するクエリを分離する方法です。 \nあまり短くなってはいませんが、副問い合わせをselect句の上に書くことができます。\n\n```\n\n with goal_count as (\n select p.id id, count(g.id) value\n from pairings p, goals g\n where p.id = g.pairing_id\n group by p.id)\n SELECT p1.kickoff, c1.name AS my_country, c2.name AS enemy_country,\n c1.ranking AS my_ranking, c2.ranking AS enemy_ranking,\n ifnull(g1.value, 0) AS my_goals,\n ifnull(g2.value, 0) AS enemy_goals,\n ifnull(g1.value, 0) - ifnull(g2.value, 0) AS goal_diff\n FROM pairings p1\n LEFT JOIN countries c1 ON c1.id = p1.my_country_id\n LEFT JOIN goal_count g1 ON g1.id = p1.id,\n pairings p2\n LEFT JOIN countries c2 ON c2.id = p2.my_country_id\n LEFT JOIN goal_count g2 ON g2.id = p2.id\n WHERE p1.my_country_id = p2.enemy_country_id\n AND p1.enemy_country_id = p2.my_country_id\n AND c1.group_name = 'C' AND c2.group_name = 'C'\n ORDER BY p1.kickoff, c1.ranking;\n \n```\n\n余談ですが1つのSQLで全てを取得するとあまりに複雑になる場合は、SQLを分割して複数回クエリを発行することやプログラムで計算処理することも検討します。 \n例えば`goal_diff`はSQLで取得せず、プログラムのループで求めるなどの方法です。\n\n今回のSQLは大して複雑ではありませんし、練習問題なので上記の対応は要件を満たしていませんが、複雑なSQLは速度低下や不具合の原因になりやすいので冗長さに加えて複雑さを避けることも簡潔なSQL作成の視点として大事だと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-29T02:55:05.540", "id": "66092", "last_activity_date": "2020-04-29T02:55:05.540", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "66070", "post_type": "answer", "score": 1 } ]
66070
null
66092
{ "accepted_answer_id": null, "answer_count": 1, "body": "Owl\nCarouselを使ってスライドをサイトに導入していたのですが、今回、モバイルフレンドリー対応での「コンテンツ幅が画面サイズを超えている」という忠告を受けました。 \n他の部分ではないかといろいろ検証した結果、Owl\nCarouseの部分のdivを削除すると、モバイルフレンドリーの結果はクリアするので、やはりスライドの部分が問題だという結論に至りました。 \nいろいろなサイトを調べてみたのですが、Owl\nCarouselはレスポンシブ対応しているなどの意見しかなく、エラーが出ている事例はあまり見受けられませんでした。 \n何かいい解決方法はありますか?\n\n```\n\n <div class=\"container-fluid mb15\">\n <div class=\"row\">\n <div class=\"owl-carousel\">\n <?php\n $rows = get_field('***', ***);\n if ($rows) {\n foreach ($rows as $row) { ?>\n <div>\n <?php if (!empty($row['url'])) : ?>\n <a href=\"<?php echo $row['url']; ?>\">\n <?php echo wp_get_attachment_image($row['image']['ID'], 'full', $row['image']['alt']); ?>\n </a>\n <?php else : ?>\n <?php echo wp_get_attachment_image($row['image']['ID'], 'full', $row['image']['alt']); ?>\n <?php endif; ?>\n </div>\n <?php\n }\n } \n ?>\n </div>\n </div>\n \n```\n\n \nこの様にしているのですが、スライドはコンテンツ幅の画面内に対応はできないのですかね。。?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T09:51:29.227", "favorite_count": 0, "id": "66072", "last_activity_date": "2020-08-07T07:45:45.567", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37613", "post_type": "question", "score": 0, "tags": [ "php", "html", "css" ], "title": "Owl Carouselを使ってスライドを導入していたのですが、サーチコンソールからの忠告でコンテンツ幅が画面サイズを超えていると出てしまいました。", "view_count": 153 }
[ { "body": "同じ現象で悩んでいましたが、\n\n```\n\n <div class=\"owl-carousel\" style=\"overflow:hidden;\">\n \n```\n\nであっけなく解決しましたぁぁ。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-08-07T07:45:45.567", "id": "69329", "last_activity_date": "2020-08-07T07:45:45.567", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "41411", "parent_id": "66072", "post_type": "answer", "score": 1 } ]
66072
null
69329
{ "accepted_answer_id": null, "answer_count": 2, "body": "## 実現したいこと\n\nn番目の `ul` 要素の最後の子要素のテキストを取得したいです。\n\n現状では `ul` 要素の最後の子要素のテキストを取得までできています。\n\n* * *\n\n## 該当のソースコード\n\n```\n\n var lastChild = document.querySelector('ul:last-child');\n console.log(lastChild);\n console.log(lastChild.textContent);\n \n```\n\nn番目のタグは、このように取得できることまではわかりました。\n\n```\n\n var nthTag = document.getElementsByTagName('ul')[2];\n \n```\n\nこれを `querySelector` メソッドの `ul` 部分に繋げる方法に辿り着けずにいます。 \n`ul = nthTag` を挿入して繋げようとしても、最初のulの子要素が取得されてしまうので、うまく繋がっていないようです。\n\n答えもしくはヒントをいただけないでしょうか。\n\n* * *\n\n## 参考にしたサイト\n\n * [要素の取得方法まとめ - Qiita](https://qiita.com/amamamaou/items/25e8b4e1b41c8d3211f4)\n * [getElementsByTagName() タグ名から要素を取得 | JavaScript中級編 - ウェブプログラミングポータル](https://wp-p.info/tpl_rep.php?cat=js-intermediate&fl=r3)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T12:32:36.150", "favorite_count": 0, "id": "66073", "last_activity_date": "2022-08-09T01:40:33.507", "last_edit_date": "2020-05-01T09:21:16.847", "last_editor_user_id": "32986", "owner_user_id": "39863", "post_type": "question", "score": 1, "tags": [ "javascript", "html", "dom" ], "title": "n番目のul要素の最後のli要素を取得したい", "view_count": 1027 }
[ { "body": "`document.getElementsByTagName('ul')[2]` によって得られるのは **`Element`\nノード**です[[1]](https://dom.spec.whatwg.org/#interface-htmlcollection)。\n\n> ### § 4.2.10.2. Interface\n> HTMLCollection[[1]](https://dom.spec.whatwg.org/#interface-htmlcollection)\n```\n\n> interface HTMLCollection {\n> readonly attribute unsigned long length;\n> getter Element? item(unsigned long index);\n> getter Element? namedItem(DOMString name);\n> };\n> \n```\n\n`Element` ノードは **`ParentNode`\nミックスインを実装している**[[2]](https://dom.spec.whatwg.org/#interface-parentnode)ため、当該\n`getElementsByTagName` メソッドの返り値に直接 `querySelector` メソッドを用いることが出来ます。\n\n> ### § 4.2.6. Mixin ParentNode[[2]](https://dom.spec.whatwg.org/#interface-\n> parentnode)\n```\n\n> interface mixin ParentNode {\n> [SameObject] readonly attribute HTMLCollection children;\n> readonly attribute Element? firstElementChild;\n> readonly attribute Element? lastElementChild;\n> readonly attribute unsigned long childElementCount;\n> \n> [CEReactions, Unscopable] void prepend((Node or DOMString)... nodes);\n> [CEReactions, Unscopable] void append((Node or DOMString)... nodes);\n> [CEReactions, Unscopable] void replaceChildren((Node or DOMString)...\n> nodes);\n> \n> Element? querySelector(DOMString selectors);\n> [NewObject] NodeList querySelectorAll(DOMString selectors);\n> };\n> Document includes ParentNode;\n> DocumentFragment includes ParentNode;\n> Element includes ParentNode;\n> \n```\n\n```\n\n var lastChild = document.getElementsByTagName('ul')[2].querySelector(\":last-child\").textContent;\n \n console.log(lastChild);\n```\n\n```\n\n <ul>\n <li>1</li>\n <li>2</li>\n <li>3</li>\n <li>4</li>\n <li>5</li>\n </ul>\n <ul>\n <li>6</li>\n <li>7</li>\n </ul>\n <ul>\n <li>8</li>\n <li>9</li>\n <li>10</li>\n </ul>\n```\n\nもしくは、 `parentNode` ミックスインが実装されていることから、単に当該 `Element` ノードの `lastElementChild`\n属性を用いることでも同様のことが行えます。\n\n```\n\n var lastChild = document.getElementsByTagName('ul')[2].lastElementChild;\n \n console.log(lastChild);\n```\n\n```\n\n <ul>\n <li>1</li>\n <li>2</li>\n <li>3</li>\n <li>4</li>\n <li>5</li>\n </ul>\n <ul>\n <li>6</li>\n <li>7</li>\n </ul>\n <ul>\n <li>8</li>\n <li>9</li>\n <li>10</li>\n </ul>\n```\n\n* * *\n\n**参考**\n\n 1. [DOM Standard](https://dom.spec.whatwg.org/)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T13:08:35.250", "id": "66075", "last_activity_date": "2020-04-29T00:16:15.617", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "32986", "parent_id": "66073", "post_type": "answer", "score": 1 }, { "body": "## Selectors API\n\nSelectors APIであれば、下記のセレクタを用いて実装可能です。\n\n * [:nth-of-type() - CSS: カスケーディングスタイルシート | MDN](https://developer.mozilla.org/ja/docs/Web/CSS/:nth-of-type)\n * [:last-child - CSS: カスケーディングスタイルシート | MDN](https://developer.mozilla.org/ja/docs/Web/CSS/:last-child)\n * [Selectors Level 4 (日本語訳)](https://triple-underscore.github.io/selectors4-ja.html)\n\n## コード\n\n```\n\n 'use strict';\n console.log(document.querySelector('ul:nth-of-type(1)>:last-child').textContent); // \"1-4\"\n console.log(document.querySelector('ul:nth-of-type(2)>:last-child').textContent); // \"2-4\"\n console.log(document.querySelector('ul:nth-of-type(3)>:last-child').textContent); // \"3-4\"\n```\n\n```\n\n <ul>\n <li>1-1</li>\n <li>1-2</li>\n <li>1-3</li>\n <li>1-4</li>\n </ul>\n <ul>\n <li>2-1</li>\n <li>2-2</li>\n <li>2-3</li>\n <li>2-4</li>\n </ul>\n <ul>\n <li>3-1</li>\n <li>3-2</li>\n <li>3-3</li>\n <li>3-4</li>\n </ul>\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-29T05:21:50.187", "id": "66095", "last_activity_date": "2022-08-09T01:40:33.507", "last_edit_date": "2022-08-09T01:40:33.507", "last_editor_user_id": "3060", "owner_user_id": "20262", "parent_id": "66073", "post_type": "answer", "score": 1 } ]
66073
null
66075
{ "accepted_answer_id": null, "answer_count": 0, "body": "メトリックス監視基盤であるgrafanaを起動させたいです。\n\n[vagrantのLinuxでminikubeを動かしたい](https://ja.stackoverflow.com/questions/66063/vagrant%e3%81%aelinux%e3%81%a7minikube%e3%82%92%e5%8b%95%e3%81%8b%e3%81%97%e3%81%9f%e3%81%84) \nにて、vagrant上でminikubeが実行できたので \n以下の流れで、grafanaを起動させようと試みております。\n\nここから、 \n`http://Vagrant-Minikubeの仮想マシンのIP:30002/` \n※IPは\"172.16.10.10\"で、30002は `kubectl get svc -n kube-system` で調べたポート番号\n\nなんていうURLをたたいてみましたが、2.のような画面が表示されてしまいます。 \nざっくりした情報しかだせておらず、申し訳ありません。 \n精通されている方がいらっしゃいましたら、不足している手順などがあれば、教えていただけますでしょうか。 \nよろしくお願いいたします。\n\n**1.実行したコマンド**\n\n```\n\n vagrant@minikube:~$ kubectl apply -f https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/heapster-rbac.yaml\n clusterrolebinding.rbac.authorization.k8s.io/heapster created\n \n vagrant@minikube:~$ kubectl apply -f https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/heapster.yaml\n serviceaccount/heapster created\n service/heapster created\n error: unable to recognize \"https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/heapster.yaml\": no matches for kind \"Deployment\" in version \"extensions/v1beta1\"\n \n vagrant@minikube:~$ kubectl apply -f https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/influxdb.yaml\n service/monitoring-influxdb created\n error: unable to recognize \"https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/influxdb.yaml\": no matches for kind \"Deployment\" in version \"extensions/v1beta1\"\n \n vagrant@minikube:~$ kubectl apply -f https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/grafana.yaml\n service/monitoring-grafana created\n error: unable to recognize \"https://raw.githubusercontent.com/takara9/vagrant-k8s/master/mon-influxdb/grafana.yaml\": no matches for kind \"Deployment\" in version \"extensions/v1beta1\"\n \n vagrant@minikube:~$ kubectl get svc -n kube-system\n NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE\n heapster ClusterIP 10.106.18.235 <none> 80/TCP 58s\n kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 56m\n metrics-server ClusterIP 10.100.25.238 <none> 443/TCP 35m\n monitoring-grafana NodePort 10.110.18.201 <none> 80:31500/TCP 18s\n monitoring-influxdb ClusterIP 10.102.218.128 <none> 8086/TCP 37s\n \n vagrant@minikube:~$ sudo minikube ip\n 10.0.2.15\n \n vagrant@minikube:~$ kubectl proxy --address=\"0.0.0.0\" -p 30002 --accept-hosts='^*$' -n kube-system\n Starting to serve on [::]:30002\n \n```\n\n**2.`http://172.16.10.10:30002/` で表示した画面**\n\n```\n\n {\n \"paths\": [\n \"/api\",\n \"/api/v1\",\n \"/apis\",\n \"/apis/\",\n \"/apis/admissionregistration.k8s.io\",\n \"/apis/admissionregistration.k8s.io/v1\",\n \"/apis/admissionregistration.k8s.io/v1beta1\",\n \"/apis/apiextensions.k8s.io\",\n \"/apis/apiextensions.k8s.io/v1\",\n \"/apis/apiextensions.k8s.io/v1beta1\",\n \"/apis/apiregistration.k8s.io\",\n \"/apis/apiregistration.k8s.io/v1\",\n \"/apis/apiregistration.k8s.io/v1beta1\",\n \"/apis/apps\",\n \n```\n\n* * *\n\n個人的な見解では、githubからheapsterなどをインストールする時点でerrorとなっているので、うまくいっていないと推測してます。 \nただ、「kubectl get svc -n kube-\nsystem」を実行したとき、heapsterなどのIPがでているので、なんとも判断がつきにくいです。 \nこの状態は何を意味しているのか?また、正しいインストール先も知りたいところです。\n\n私の独力では、限界があると感じてます。ご存知の方、対応策を思いつく方がいらっしゃいましたらアドバイスいただきたいです。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T12:46:52.363", "favorite_count": 0, "id": "66074", "last_activity_date": "2020-05-06T06:03:51.137", "last_edit_date": "2020-04-29T07:59:49.127", "last_editor_user_id": "3060", "owner_user_id": "39856", "post_type": "question", "score": 1, "tags": [ "linux", "docker", "github", "vagrant", "kubernetes" ], "title": "minikubeでのgrafanaの起動方法", "view_count": 241 }
[]
66074
null
null
{ "accepted_answer_id": "66081", "answer_count": 1, "body": "SPRESENSEで使うために既存のライブラリを修正しています。 \nSPRESENSEであることを判別するために、ボード定義のdefineで設定を切替をしようとしているのですが、うまく行きません。 \n実際に試した記述は以下です。\n\n```\n\n #if defined (ESP32)\n #include \"Processors/xxx.h\"\n #elif defined (ESP8266)\n #include \"Processors/xxx.h\"\n #elif defined (SPRESENSE)\n #include \"Processors/SPRESENSE.h\"\n #else\n #include \"Processors/Generic.h\"\n #endif\n \n```\n\nSPRESENSEのボードを選択した際にdefinedとなるプロセッサタイプを教えてください。 \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T13:15:23.910", "favorite_count": 0, "id": "66076", "last_activity_date": "2020-04-28T14:48:21.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "35981", "post_type": "question", "score": 0, "tags": [ "spresense", "arduino" ], "title": "Sony SPRESENSE Arduino Libraryでのボード定義での設定切替方法", "view_count": 139 }
[ { "body": "ビルドログをみると -DARDUINO_ARCH_SPRESENSE\nが定義されており、いくつかのライブラリではこのdefineを使って識別しているようです。(-DSPRESENSE\nという定義があっても良いような気がしますが...)\n\n```\n\n #if defined (ESP32)\n #include \"Processors/xxx.h\"\n #elif defined (ESP8266)\n #include \"Processors/xxx.h\"\n #elif defined (ARDUINO_ARCH_SPRESENSE)\n #include \"Processors/SPRESENSE.h\"\n #else\n #include \"Processors/Generic.h\"\n #endif\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-04-28T14:48:21.773", "id": "66081", "last_activity_date": "2020-04-28T14:48:21.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31378", "parent_id": "66076", "post_type": "answer", "score": 0 } ]
66076
66081
66081