qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,406,293
<p>Minimal reproducable Example</p> <pre><code>from tkinter import * def test(event): print(event.widget) window = Tk() window.geometry(&quot;600x600&quot;) window.bind(&quot;&lt;Motion&gt;&quot;, test) frame = Frame(window, bg=&quot;red&quot;, width=200, height=200) frame.pack() frame.bind(&quot;&lt;Motion&gt;&quot;, test) window.mainloop() </code></pre> <p>I want to call the function &quot;test&quot; from different widgets when i move over them. Instead of that, when i hover over the frame, both the window and the frame print that im hovering over the frame, which is not the behaviour i need. Can someone help me achieve the right behaviour?</p>
[ { "answer_id": 74407487, "author": "Jonesgamings", "author_id": 12453265, "author_profile": "https://Stackoverflow.com/users/12453265", "pm_score": 0, "selected": false, "text": "\ndef test(event, widget):\n print(widget)\n\nwindow = Tk()\nwindow.geometry(\"600x600\")\nwindow.bind(\"<Motion>\", test)\n\nframe = Frame(window, bg=\"red\", width=200, height=200)\nframe.pack()\nframe.bind(\"<Motion>\", lambda: test(frame))\n\nwindow.mainloop()\n\n" }, { "answer_id": 74407747, "author": "José Juan", "author_id": 20386708, "author_profile": "https://Stackoverflow.com/users/20386708", "pm_score": 1, "selected": false, "text": "from tkinter import *\n\ndef test_enter(event):\n enter.set(event.widget)\n\ndef test_left(event):\n left.set(event.widget)\n\nwindow = Tk()\nwindow.geometry(\"300x300\")\nwindow.bind(\"<Enter>\", test_enter)\nwindow.bind(\"<Leave>\", test_left)\n\nframe = Frame(window, bg=\"red\", width=200, height=200)\nframe.pack()\nframe.bind(\"<Enter>\", test_enter)\nframe.bind(\"<Leave>\", test_left)\n\nlabel1 = Label(frame, text=\"Enter\")\nlabel1.place(relx=0.1, rely=0.4, x= 0.2, y=0.2)\nenter = StringVar()\nlabel_enter = Label(frame, textvariable=enter)\nlabel_enter.place(relx=0.3, rely=0.4, x= 0.6, y=0.2)\n\nlabel2 = Label(frame, text=\"Leave\")\nlabel2.place(relx=0.1, rely=0.6, x= 0.2, y=0.2)\nleft = StringVar()\nlabel_left = Label(frame, textvariable=left)\nlabel_left.place(relx=0.3, rely=0.6, x= 0.6, y=0.2)\n\nwindow.mainloop()\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15544018/" ]
74,406,316
<p>I want to implement a switch for toggling dark mode in my application. After investigating multiple sources on how to do this correctly, I came across this one-line solution:</p> <pre><code>AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); </code></pre> <p>Unfortunately, in my case this only changes the configuration to light mode and doesn't update UI colors. Here's my code:</p> <pre><code>binding.toggleDarkMode.setOnCheckedChangeListener { _, isChecked -&gt; if (isChecked) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) activity?.recreate() } } </code></pre> <p>I'd also like to mention that I have separate theme files for light and dark mode. Light theme extends <code>Theme.Material3.Light.NoActionBar</code> and dark theme extends <code>Theme.Material3.Dark.NoActionBar</code>. Could anyone tell me what could be the problem?</p>
[ { "answer_id": 74407011, "author": "cactustictacs", "author_id": 13598222, "author_profile": "https://Stackoverflow.com/users/13598222", "pm_score": 1, "selected": false, "text": "AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3371414/" ]
74,406,349
<p>I have a div for a menu which has overflow-x set to hidden. This makes the scrollbar appear when content overflows out of the div. currently the scrollbar is only on the right side, but I want to move it over to the left. Is this possible?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>body::-webkit-scrollbar { width: 0px; } body::-webkit-scrollbar-track { background: transparent; } body::-webkit-scrollbar-thumb { background-color: transparent; border-radius: 20px; border: 3px solid transparent; } .CONT { position: relative; top: -25px; left: 20px; } .CONT_2 { position: relative; top: 25px; left: 20px; height: 100px; } #words { top: -2px; left: 25px; position: relative; } #words2 { top: 2px; left: 25px; position: relative; } .DOC_CONTAINER { font-size: 20px; font-family: Verdana; font-weight: bold; position: relative; top: 16px; left: -4px; color: #0088FF; user-select: none; cursor: pointer; width: 280px; z-index: 1; overflow: hidden; height: 46px; } #HTML_DOC { font-size: 18px; font-family: Verdana; font-weight: bold; position: relative; top: 75px; left: 15px; } #CSS_DOC { font-size: 18px; font-family: Verdana; font-weight: bold; position: relative; top: 125px; left: 15px; } #JAVA_DOC { font-size: 18px; font-family: Verdana; font-weight: bold; position: relative; top: 175px; left: 15px; } #JQUERY_DOC { font-size: 18px; font-family: Verdana; font-weight: bold; position: relative; top: 225px; left: 15px; } #LUA_DOC { font-size: 18px; font-family: Verdana; font-weight: bold; position: relative; top: 275px; left: 15px; } #ICON_1 { position: absolute; top: 0px; left: 200px; } #icon2 { position: absolute; top: 2px; left: 180px; } #ICON_2 { position: absolute; top: 4px; left: 118px; } #icon3 { position: absolute; top: 2px; left: 100px; } div.DOC_CONTAINER.expanded { width: 390px; height: 395px; top: 16px; left: -4px; position: relative; animation-name: Expand1; animation-duration: 0.2s; animation-iteration-count: 1; animation-fill-mode: forwards; } div.WEBVAR_CONTAINER.EXPAND { width: 390px; height: 395px; top: 35px; left: -4px; position: relative; animation-name: Expand2; animation-duration: 0.2s; animation-iteration-count: 1; animation-fill-mode: forwards; } @keyframes Expand2 { 0% { height: 70px; } 100% { height: 280px; } } @keyframes Expand1 { 0% { height: 70px; } 100% { height: 421px; } } #SEP2 { width: 390px; height: 1px; background-color: #2e2e2e; position: absolute; top: 65px; left: -27px; } #SEP3 { width: 390px; height: 1px; background-color: #2e2e2e; position: relative; top: 420px; left: -27px; } #SEP4 { width: 370px; height: 1px; background-color: #2e2e2e; position: absolute; top: 135px; left: 0px; } #SEP5 { width: 390px; height: 1px; background-color: #2e2e2e; position: relative; top: 420px; left: -27px; } #CREDITS { font-size: 20px; font-family: Verdana; font-weight: bold; position: relative; top: 30px; left: 20px; } #ABOUT { font-size: 20px; font-family: Verdana; font-weight: bold; position: absolute; top: 100px; left: 20px; } #COPY_RIGHT { font-size: 20px; font-family: Verdana; font-weight: bold; position: absolute; top: 170px; left: 20px; } div.scroll { margin: 4px, 4px; padding: 4px; background-color: #1f1f1f; width: 350px; height: 85vh; top: 127px; left: -5px; position: absolute; overflow-x: hidden; text-align: justify; border-bottom-right-radius: 20px; } .scroll::-webkit-scrollbar { width: 5px; color: #0088FF; height: 25px; } .scroll::-webkit-scrollbar-track { background: #2e2e2e; } .scroll::-webkit-scrollbar-thumb { background: #0088FF; } .scroll::-webkit-scrollbar-thumb:hover { background: #0088FF; } .flip { transform: rotateX(180deg); transition-duration: 0.2s; } .flip2 { transform: rotateX(180deg); transition-duration: 0.2s; } #MENU_LABEL { color: #2E2E2E; top: 11px; left: 45vw; position: absolute; font-size: 20px; font-family: verdana; } body { height: 200vh; background-color: #2E2E2E; } a { color: #0088ff; text-decoration: none; } a:hover { color: #0056A3; text-decoration: none; } .WEBVAR_CONTAINER { font-size: 20px; font-family: Verdana; font-weight: bold; position: relative; top: 35px; left: -4px; color: #0088FF; user-select: none; cursor: pointer; width: 390px; z-index: 1; overflow: hidden; height: 70px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div class="scroll"&gt; &lt;div class="DOC_CONTAINER"&gt; &lt;div id="SEP3"&gt;&lt;/div&gt; &lt;div id="words"&gt;Documentation&lt;/div&gt; &lt;div id="ICON_1"&gt;&lt;i class="fa-solid fa-angle-down"&gt;&lt;/i&gt;&lt;/div&gt; &lt;script&gt; $(document).ready(function() { $('#words').click(function(event) { event.preventDefault(); $(".DOC_CONTAINER").toggleClass('expanded'); $("#ICON_1").toggleClass("flip"); }); }); &lt;/script&gt; &lt;div class="CONT"&gt; &lt;div id="HTML_DOC"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/DocOverview/HTMLDoc/htmlDocumentation.html"&gt;HTML&lt;/a&gt;&lt;/div&gt; &lt;div id="CSS_DOC"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/DocOverview/CSSDoc/cssdocumentation.html"&gt;CSS&lt;/a&gt;&lt;/div&gt; &lt;div id="JAVA_DOC"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/DocOverview/JSDoc/javascriptdocumentation.html"&gt;Javascript&lt;/a&gt;&lt;/div&gt; &lt;div id="JQUERY_DOC"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/DocOverview/JSDoc/jquerydocumentation.html"&gt;Jquery&lt;/a&gt;&lt;/div&gt; &lt;div id="LUA_DOC"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/DocOverview/LUADoc/luadocumentation.html"&gt;Lua&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="SEP2"&gt;&lt;/div&gt; &lt;div class="WEBVAR_CONTAINER"&gt; &lt;div id="SEP5"&gt;&lt;/div&gt; &lt;div id="words2"&gt;WebVar&lt;/div&gt; &lt;div id="ICON_2"&gt;&lt;i class="fa-solid fa-angle-down"&gt;&lt;/i&gt;&lt;/div&gt; &lt;script&gt; $(document).ready(function() { $('#words2').click(function(event) { event.preventDefault(); $(".WEBVAR_CONTAINER").toggleClass('EXPAND'); $("#ICON_2").toggleClass("flip2"); }); }); &lt;/script&gt; &lt;div class="CONT_2"&gt; &lt;div id="CREDITS"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/ABT/credits.html"&gt;Credits&lt;/a&gt;&lt;/div&gt; &lt;div id="ABOUT"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/ABT/about.html"&gt;About&lt;/a&gt;&lt;/div&gt; &lt;div id="COPY_RIGHT"&gt;&lt;a href="/Users/1001891/Desktop/webVar/Content/COPY/copyright.html"&gt;Copyright&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="SEP4"&gt;&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>I tried setting float but that didn't work. If there is a solution please enlighten me.</p>
[ { "answer_id": 74406621, "author": "Kosh", "author_id": 5724303, "author_profile": "https://Stackoverflow.com/users/5724303", "pm_score": 2, "selected": false, "text": ".scroll-at-left {\n width: 200px;\n height: 95vh;\n overflow-y: scroll;\n transform: rotateY(180deg);\n}\n\n.scroll-at-left>section {\n padding: 0 1em;\n transform: rotateY(180deg);\n}" }, { "answer_id": 74406864, "author": "Luke McCrea", "author_id": 20463789, "author_profile": "https://Stackoverflow.com/users/20463789", "pm_score": 2, "selected": true, "text": ".scroll-at-left {\n width: 200px;\n height: 95vh;\n overflow-y: scroll;\n direction: rtl; \n}\n\n.scroll-at-left section {\n padding: 0 1em;\n direction: ltr; \n}" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20442916/" ]
74,406,353
<p>I am trying to use broadcast feature of numpy on my large data. I have list columns that can have hundreds of elements in many rows. I need to filter rows based on presence of columns value in the list column. If number in <code>col_a</code> is present in <code>col_b</code>, I need to filter IN that row.</p> <p>Sample data:</p> <pre><code>import pandas as pd import numpy as np dt = pd.DataFrame({'id' : ['a', 'a', 'a', 'b', 'b'], 'col_a': [[1],[2],[5],[1],[2]], 'col_b': [[2],[2,4],[2,5,7],[4],[3,2]], }) dt id col_a col_b 0 a [1] [2] 1 a [2] [2, 4] 2 a [5] [2, 5, 7] 3 b [1] [4] 4 b [2] [3, 2] </code></pre> <p>I tried below code to add dimension to <code>col_b</code> and check if the value is present in <code>col_a</code>:</p> <pre><code>(dt['col_a'] == dt['col_b'][:,None]).any(axis = 1) </code></pre> <p>but I get below error:</p> <pre><code>ValueError: ('Shapes must match', (5,), (5, 1)) </code></pre> <p>Could someone please let me know what's the correct approach.</p>
[ { "answer_id": 74406741, "author": "Brian", "author_id": 6567270, "author_profile": "https://Stackoverflow.com/users/6567270", "pm_score": 2, "selected": false, "text": "import pandas as pd\nimport numpy as np\nfrom itertools import product\n" }, { "answer_id": 74407271, "author": "hpaulj", "author_id": 901925, "author_profile": "https://Stackoverflow.com/users/901925", "pm_score": 2, "selected": true, "text": "numpy" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10722752/" ]
74,406,375
<p>I need to use asammdf as part of my app to concatenate multiple .MF4 files. If you know about other ways, I will gladly try other packages.</p> <p>Problem is that it runs on windows but once I try to build docker image (on linux) with asammdf (tried same version as I have on windows and even some other) in requirements, it fails to install.</p> <p>dockerfile:</p> <pre><code>FROM python:3.9-slim COPY ./requirements.txt requirements.txt RUN pip install --upgrade pip RUN pip install -r requirements.txt </code></pre> <p>requirements.txt</p> <p><code>asammdf==6.2.0</code></p> <p>output:</p> <p>...</p> <pre><code>Building wheels for collected packages: asammdf, future Building wheel for asammdf (pyproject.toml): started Building wheel for asammdf (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error × Building wheel for asammdf (pyproject.toml) did not run successfully. │ exit code: 1 ╰─&gt; [128 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-cpython-39 creating build/lib.linux-x86_64-cpython-39/asammdf copying asammdf/signal.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf copying asammdf/mdf.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf copying asammdf/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf copying asammdf/version.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf creating build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/v4_blocks.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/mdf_v3.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/v2_v3_blocks.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/conversion_utils.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/v4_constants.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/source_utils.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/mdf_v2.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/bus_logging_utils.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/utils.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/v2_v3_constants.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/mdf_common.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/blocks/mdf_v4.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks creating build/lib.linux-x86_64-cpython-39/asammdf/gui copying asammdf/gui/plot.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui copying asammdf/gui/cx.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui copying asammdf/gui/utils.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui copying asammdf/gui/asammdfgui.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui copying asammdf/gui/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui creating build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/channel_display.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tree_numeric.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tabular_filter.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/plot_standalone.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tabular.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/channel_info.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/mdi_area.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tree.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/plot.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/file.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/channel_stats.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/search.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/list.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/cursor.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/attachment.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/channel_group_info.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/list_item.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/can_bus_trace.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/collapsiblebox.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/main.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/formated_axis.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/numeric.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/lin_bus_trace.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tree_item.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/batch.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/dict_to_tree.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets copying asammdf/gui/widgets/tabular_base.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/widgets creating build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/search_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/tabular_filter.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/define_channel_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/multi_search_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/tabular.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/windows_selection_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_group_info_widget.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_stats.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/file_widget.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/error_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/attachment.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/batch_widget.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/range_editor_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/resource_rc.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/values_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/numeric.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_info_widget.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/main_window.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_display_widget.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui creating build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/range_editor.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/window_selection_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/tabular.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/multi_search.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/channel_info.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/error_dialog.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/channel_group_info.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/define_channel.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/advanced_search.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs copying asammdf/gui/dialogs/__init__.py -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/dialogs running egg_info writing asammdf.egg-info/PKG-INFO writing dependency_links to asammdf.egg-info/dependency_links.txt writing entry points to asammdf.egg-info/entry_points.txt writing requirements to asammdf.egg-info/requires.txt writing top-level names to asammdf.egg-info/top_level.txt reading manifest file 'asammdf.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' adding license file 'LICENSE' writing manifest file 'asammdf.egg-info/SOURCES.txt' copying asammdf/blocks/cutils.c -&gt; build/lib.linux-x86_64-cpython-39/asammdf/blocks copying asammdf/gui/ui/attachment.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/batch_widget.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_display_widget.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_group_info_widget.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_info_widget.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/channel_stats.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/define_channel_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/error_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/file_widget.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/main_window.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/multi_search_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/numeric.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/range_editor_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/resource.qrc -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/search_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/tabular.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/tabular_filter.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/values_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui copying asammdf/gui/ui/windows_selection_dialog.ui -&gt; build/lib.linux-x86_64-cpython-39/asammdf/gui/ui running build_ext building 'asammdf.blocks.cutils' extension creating build/temp.linux-x86_64-cpython-39 creating build/temp.linux-x86_64-cpython-39/asammdf creating build/temp.linux-x86_64-cpython-39/asammdf/blocks gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tmp/pip-build-env-kff6bke_/overlay/lib/python3.9/site-packages/numpy/core/include -I/usr/local/include/python3.9 -c asammdf/blocks/cutils.c -o build/temp.linux-x86_64-cpython-39/asammdf/blocks/cutils.o error: command 'gcc' failed: No such file or directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for asammdf Building wheel for future (setup.py): started Building wheel for future (setup.py): finished with status 'done' Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=9eb7454ae5d981f6797726bfaac55aab83ad106dddc62b530856a02c208bed22 Stored in directory: /root/.cache/pip/wheels/96/66/19/2de75120f5d0bc185e9d16cf0fd223d8471ed025de08e45867 Successfully built future Failed to build asammdf ERROR: Could not build wheels for asammdf, which is required to install pyproject.toml-based projects The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1 ERROR: Service 'py_data_processing' failed to build : Build failed </code></pre>
[ { "answer_id": 74432121, "author": "Takumi Okamoto", "author_id": 4776042, "author_profile": "https://Stackoverflow.com/users/4776042", "pm_score": 3, "selected": true, "text": "RUN apt-get install build-essential" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5990202/" ]
74,406,384
<p>Hey (sorry bad english) so let me explain a little further. i want to make a function that takes in a list. let's say a list with a countries and their capital also added their population. i want to return every country-capital pair that dosen't contain the same letter. like this:</p> <pre><code>countries = [ [&quot;China PR&quot;, &quot;Beijing&quot;, 20693000], [&quot;India&quot;, &quot;New Delhi&quot;, 16787949], [&quot;Japan&quot;, &quot;Tokyo&quot;, 13491000], [&quot;Philippines&quot;, &quot;Manilla&quot;, 12877253], [&quot;Russia&quot;, &quot;Moscow&quot;, 11541000], [&quot;Egypt&quot;, &quot;Cairo&quot;, 10230350] ] #the output should be: &gt;&gt;&gt; no_common_letters(countries) [[&quot;Japan&quot;, &quot;Tokyo&quot;], [&quot;Egypt&quot;, &quot;Cairo&quot;]] </code></pre> <p>because Japan and Tokyo dosen't contain the same letters. anyone know a sulotion to this? i have tried looking around and all i can find is a program that finds a specified letter and check's if it's in. i want to check every word. i am new to python and trying to learn</p>
[ { "answer_id": 74432121, "author": "Takumi Okamoto", "author_id": 4776042, "author_profile": "https://Stackoverflow.com/users/4776042", "pm_score": 3, "selected": true, "text": "RUN apt-get install build-essential" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20241890/" ]
74,406,449
<p>We use managed Airflow inside a GCP project.</p> <p>When I used BigQueryInsertJobOperator to execute queries in a query file, it used to automatically replace user_defined_macros in those files with the set value.</p> <pre><code>from airflow import DAG from datetime import datetime from airflow.providers.google.cloud.operators.bigquery import BigQueryInsertJobOperator with DAG( 'test', schedule_interval = None, start_date = datetime(2022, 1, 1), user_defined_macros = { &quot;MY_MACRO&quot;: &quot;Hello World&quot; } ) as dag: BigQueryInsertJobOperator( task_id = &quot;my_task&quot;, configuration = { &quot;query&quot;: { &quot;query&quot;: &quot;{% include '/queries/my_query.sql' %}&quot;, &quot;useLegacySql&quot;: False, }, }, dag = dag, ) </code></pre> <p>Due to some reasons, I am switching to using a regular function or PythonOperator to execute those queries using a bigquery client. However, I am unable to figure out how to get the user_defined_macro to be parsed. The below is what I have so far, but doesn't work of course. Please help.</p> <pre><code>from airflow import DAG from datetime import datetime from google.cloud import bigquery from airflow.decorators import task with DAG( 'test', schedule_interval = None, start_date = datetime(2022, 1, 1), user_defined_macros = { &quot;MY_MACRO&quot;: &quot;Hello World&quot; } ) as dag: @task def test(): query = open('/home/airflow/gcs/dags/queries/my_query.sql').read() bq_client = bigquery.Client() bq_client.query(query).result() test() </code></pre>
[ { "answer_id": 74432121, "author": "Takumi Okamoto", "author_id": 4776042, "author_profile": "https://Stackoverflow.com/users/4776042", "pm_score": 3, "selected": true, "text": "RUN apt-get install build-essential" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4635851/" ]
74,406,454
<p>I am trying to connect tot he database and extract the contents, but whenever I try, I get this error:</p> <blockquote> <p>System.InvalidOperationException: Invalid attempt to read when no data is present.</p> </blockquote> <p>I'm not sure why no data is being read from the table, it seems to work perfectly fine when I connect to the other table I have in the database.</p> <p>This is the code I use:</p> <pre><code>static void testcon() { SqlConnection con = new SqlConnection(Programe.connectionString); con.Open(); SqlCommand cmd1 = new SqlCommand(&quot;SELECT * FROM Auth WHERE Username = @username&quot;, con); cmd1.Parameters.AddWithValue(&quot;username&quot;, &quot;test&quot;); SqlDataReader reader = cmd1.ExecuteReader(); Console.WriteLine(reader[0]); con.Close(); } </code></pre> <p>The exception was thrown on this line of code:</p> <pre><code>Console.WriteLine(reader[0]); </code></pre> <p>This is the server explorer:</p> <p><a href="https://i.stack.imgur.com/pOBka.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pOBka.png" alt="enter image description here" /></a></p> <p>I have tried trying different key words in the SQL commands, different keywords in the method but I keep getting the same error.</p> <p>I have tried</p> <pre><code>if (reader.read()) { //code here } </code></pre> <p>but that wouldn't solve my issue as the data not being present would still occur</p>
[ { "answer_id": 74406497, "author": "Indept Studios", "author_id": 19262048, "author_profile": "https://Stackoverflow.com/users/19262048", "pm_score": 1, "selected": false, "text": "while(reader.read())\n{\n// code here\n}\n" }, { "answer_id": 74406568, "author": "WandererAboveTheSea", "author_id": 9680817, "author_profile": "https://Stackoverflow.com/users/9680817", "pm_score": 3, "selected": true, "text": "using (SqlDataReader reader = cmd1.ExecuteReader())\n{\n while (reader.Read()) //The loop will run for all the rows in the result.\n {\n //loop on all the columns\n for (int i = 0; i < reader.FieldCount; i++)\n {\n Console.WriteLine(reader.GetValue(i));\n }\n Console.WriteLine();\n }\n }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19529866/" ]
74,406,480
<p>Below is official example in <a href="https://reactjs.org/docs/hooks-faq.html#what-can-i-do-with-hooks-that-i-couldnt-with-classes" rel="nofollow noreferrer">React document</a>. The official explanation is</p> <blockquote> <p>The problem is that inside the setInterval callback, the value of count does not change, because we’ve created a closure with the value of count set to 0 as it was when the effect callback ran.</p> </blockquote> <p>Can you show me where is the closure? I don't understand why the closure making the counter only reaches 2. I know closure, useEffect(), ()=&gt; {} will not create a closure, but I don't understand how those concepts play together in this example to make the counter bug.</p> <pre><code>import React, { useEffect, useState } from &quot;react&quot;; function Counter() { const [count, setCount] = useState(1); useEffect(() =&gt; { const id = setInterval( () =&gt; { console.log(&quot;interval callback triggered&quot;); setCount(count + 1); // This effect depends on the `count` state }, 1000); return () =&gt; clearInterval(id); }, []); // Bug: `count` is not specified as a dependency return &lt;h1&gt;{count}&lt;/h1&gt;; } export default Counter; </code></pre>
[ { "answer_id": 74406497, "author": "Indept Studios", "author_id": 19262048, "author_profile": "https://Stackoverflow.com/users/19262048", "pm_score": 1, "selected": false, "text": "while(reader.read())\n{\n// code here\n}\n" }, { "answer_id": 74406568, "author": "WandererAboveTheSea", "author_id": 9680817, "author_profile": "https://Stackoverflow.com/users/9680817", "pm_score": 3, "selected": true, "text": "using (SqlDataReader reader = cmd1.ExecuteReader())\n{\n while (reader.Read()) //The loop will run for all the rows in the result.\n {\n //loop on all the columns\n for (int i = 0; i < reader.FieldCount; i++)\n {\n Console.WriteLine(reader.GetValue(i));\n }\n Console.WriteLine();\n }\n }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/887103/" ]
74,406,488
<p>Let's say I have 3 lists of DataFrames containing different data that I want to run the same test cases on. How do I best structure my files and code so that I have one <code>conftest.py</code> (or some sort of parent class) that contains all the test cases that each list needs to run on, and 3 child classes that have different ways of generating each list of DataFrames but run the same test cases?</p> <p>This is how I am currently constructing it.</p> <pre><code>import pytest class TestOne: # this method usually takes 10 mins to run # so we want this to run once and use the same Dict for all test cases dfs: Dict[str, pd.DataFrame] = get_list_of_dfs_somewhere(&quot;one&quot;) def test_dfs_type(self): assert isinstance(self.dfs, dict) def test_another_one(self): assert ... </code></pre> <p><code>dfs</code> will not be modified throughout the test suite, so I want to treat this like a setup.</p> <p><code>TestTwo</code> and <code>TestThree</code> are the same thing except it will be <code>get_list_of_dfs_somewhere(&quot;two&quot;)</code> and <code>get_list_of_dfs_somewhere(&quot;three&quot;)</code></p> <p>Any tips on how to efficiently structure this would be appreciated!</p>
[ { "answer_id": 74406497, "author": "Indept Studios", "author_id": 19262048, "author_profile": "https://Stackoverflow.com/users/19262048", "pm_score": 1, "selected": false, "text": "while(reader.read())\n{\n// code here\n}\n" }, { "answer_id": 74406568, "author": "WandererAboveTheSea", "author_id": 9680817, "author_profile": "https://Stackoverflow.com/users/9680817", "pm_score": 3, "selected": true, "text": "using (SqlDataReader reader = cmd1.ExecuteReader())\n{\n while (reader.Read()) //The loop will run for all the rows in the result.\n {\n //loop on all the columns\n for (int i = 0; i < reader.FieldCount; i++)\n {\n Console.WriteLine(reader.GetValue(i));\n }\n Console.WriteLine();\n }\n }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8431172/" ]
74,406,506
<p>I have the following 2 function overloads:</p> <pre><code>template&lt;typename F, typename T&gt; void func(F f, std::vector&lt;T&gt;&amp; v) { ... } template&lt;typename F, typename T&gt; void func(F f, const std::vector&lt;T&gt;&amp; v) { ... } </code></pre> <p>The body of both of them is the same. Is there an easy way to define them both with a single definition to avoid code duplication using C++17 or earlier standard?</p> <p>Just to clarify, I want the functions to be constrained based on the <code>std::vector</code> part but I want to allow const and non-const references to be passed. The reason I need both overloads is that the <code>F</code> function object will be applied to the vector and sometimes <code>F</code> will modify the vector and sometimes it will only observe the vector (and I want to allow the vector to be declared <code>const</code> in the second case).</p> <p>I guess I can use C++20 concepts to constrain the function template parameter but I was wondering if there's an easy way to achieve the same thing using C++17 or earlier version of the standard.</p>
[ { "answer_id": 74413222, "author": "apple apple", "author_id": 5980430, "author_profile": "https://Stackoverflow.com/users/5980430", "pm_score": 1, "selected": false, "text": "require" }, { "answer_id": 74446669, "author": "Zamfir Yonchev", "author_id": 5341453, "author_profile": "https://Stackoverflow.com/users/5341453", "pm_score": 1, "selected": true, "text": "template<typename F, typename VecT>\nauto func_vec(F f, VecT& vec)\n{\n //actual code\n}\n\ntemplate<typename F, typename T>\nauto func(F f, std::vector<T>& vec) { return func_vec(f, vec); }\n\ntemplate<typename F, typename T>\nauto func(F f, const std::vector<T>& vec) { return func_vec(f, vec); }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5341453/" ]
74,406,536
<p>I'm stuck, I've searched several ways and I can't get the correct output.</p> <pre><code>string = &quot;Hello! I have a Big!!! problem 666 is not a good number__$&quot; ns =''.join([i for i in string if i.isalpha()]) print(ns) </code></pre> <p>HelloIhaveaBigproblemisnotagoodnumber</p> <p>I want this output:</p> <p>Hello I have a Big problem is not a good number</p> <p>Can you help me? Thank you!!</p>
[ { "answer_id": 74406629, "author": "C-3PO", "author_id": 4667669, "author_profile": "https://Stackoverflow.com/users/4667669", "pm_score": 0, "selected": false, "text": "re" }, { "answer_id": 74406653, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 2, "selected": false, "text": "re" }, { "answer_id": 74406673, "author": "segev_gr", "author_id": 19896669, "author_profile": "https://Stackoverflow.com/users/19896669", "pm_score": 0, "selected": false, "text": "import re\n\nstring = \"Hello! I have a Big!!! problem 666 is not a good number__$\"\nregex = re.compile('[^a-zA-Z ]')\nprint(regex.sub('', string))\n" }, { "answer_id": 74406892, "author": "tdelaney", "author_id": 642070, "author_profile": "https://Stackoverflow.com/users/642070", "pm_score": 3, "selected": true, "text": "ns =''.join([i for i in string if i == \" \" or i.isalpha()])\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480225/" ]
74,406,551
<p>I am recoding a <code>df</code> with columns containing &quot;yes,&quot; &quot;no,&quot; or &quot;N/A.&quot; I want to recode &quot;yes&quot; as 1, &quot;no&quot; as 0, and keep &quot;N/A&quot; as &quot;N/A.&quot;</p> <p>I have written the following code:</p> <pre><code>df$first_column &lt;-ifelse(df$first_column==&quot;yes&quot;,1,0) </code></pre> <p>However, this replaces <code>N/A</code> with <code>0</code>. What is the easiest way to get around this problem?</p> <p>Here is reproducible <code>df</code>:</p> <pre><code>structure(list(first_column = c(&quot;yes&quot;, &quot;no&quot;, &quot;N/A&quot;, &quot;yes&quot;)), row.names = c(NA, 4L), class = &quot;data.frame&quot;) </code></pre>
[ { "answer_id": 74406629, "author": "C-3PO", "author_id": 4667669, "author_profile": "https://Stackoverflow.com/users/4667669", "pm_score": 0, "selected": false, "text": "re" }, { "answer_id": 74406653, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 2, "selected": false, "text": "re" }, { "answer_id": 74406673, "author": "segev_gr", "author_id": 19896669, "author_profile": "https://Stackoverflow.com/users/19896669", "pm_score": 0, "selected": false, "text": "import re\n\nstring = \"Hello! I have a Big!!! problem 666 is not a good number__$\"\nregex = re.compile('[^a-zA-Z ]')\nprint(regex.sub('', string))\n" }, { "answer_id": 74406892, "author": "tdelaney", "author_id": 642070, "author_profile": "https://Stackoverflow.com/users/642070", "pm_score": 3, "selected": true, "text": "ns =''.join([i for i in string if i == \" \" or i.isalpha()])\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14482089/" ]
74,406,685
<p><a href="https://i.stack.imgur.com/md16P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/md16P.png" alt="Image of the error" /></a></p> <p>when installing module on NPM i get this error and i have python 3 installed and ENV path set.</p> <p>tried to install a NPM module and expected to install</p>
[ { "answer_id": 74406629, "author": "C-3PO", "author_id": 4667669, "author_profile": "https://Stackoverflow.com/users/4667669", "pm_score": 0, "selected": false, "text": "re" }, { "answer_id": 74406653, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 2, "selected": false, "text": "re" }, { "answer_id": 74406673, "author": "segev_gr", "author_id": 19896669, "author_profile": "https://Stackoverflow.com/users/19896669", "pm_score": 0, "selected": false, "text": "import re\n\nstring = \"Hello! I have a Big!!! problem 666 is not a good number__$\"\nregex = re.compile('[^a-zA-Z ]')\nprint(regex.sub('', string))\n" }, { "answer_id": 74406892, "author": "tdelaney", "author_id": 642070, "author_profile": "https://Stackoverflow.com/users/642070", "pm_score": 3, "selected": true, "text": "ns =''.join([i for i in string if i == \" \" or i.isalpha()])\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18624731/" ]
74,406,705
<p>I have a table list:</p> <pre class="lang-lisp prettyprint-override"><code>(defvar moo '((:name &quot;vince&quot; :age 35) (:name &quot;jess&quot; :age 30))) </code></pre> <p>and I call this function on that list:</p> <pre class="lang-lisp prettyprint-override"><code>(defun test (name) (remove-if-not #'(lambda (person) (equal (getf person :name) name)) moo)) (test &quot;vince&quot;) ;; function call ;; =&gt; ((:name &quot;vince&quot; :age 35)) </code></pre> <p>In the lambda function, how does the <code>(person)</code> parameter get filled? <code>person</code> is also used in the <code>getf</code> but I'm not sure how it's being discovered in the first place if I am only supplying the <code>name</code> in the test function.</p> <p>What am I missing?</p>
[ { "answer_id": 74406853, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 1, "selected": false, "text": "remove-if-not" }, { "answer_id": 74413273, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 3, "selected": true, "text": "REMOVE-IF-NOT" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16237416/" ]
74,406,706
<p>I'm following a Python tutorial on youtube and need to create a django website, however I am unable to start, because when I enter &quot;python manage.py runserver&quot; I get the &quot;TypeError: translation() got an unexpected keyword argument 'codeset'&quot; message. I've run back the video like 20 times to see if I've missed anything, but no, because it's just the beginning of the django website tutorial. I've also tried typing python3 instead of python and some other options I saw on Stack Overflow, but none are really exactly relevant to the error message I'm getting. Perhaps someone knows how to fix this?</p> <p>I tried to start a development server by typing in &quot;python manage.py runserver&quot; which was supposed to start a django webserver at 127.0.0.1:8000 or something, but instead I got the error message specified in the title</p> <p>code:</p> <pre><code>PS C:\Users\kaspa\PycharmProjects\PyShop&gt; python manage.py runserver Exception ignored in thread started by: &lt;function check_errors.&lt;locals&gt;.wrapper at 0x00000145784C1F80&gt; Traceback (most recent call last): File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py&quot;, line 225, in wrapper fn(*args, **kwargs) File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\commands\runserver.py&quot;, line 109, in inner_run autoreload.raise_last_exception() File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py&quot;, line 248, in raise_last_exception raise _exception[1] File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py&quot;, line 337, in execute autoreload.check_errors(django.setup)() File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py&quot;, line 225, in wrapper fn(*args, **kwargs) File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\__init__.py&quot;, line 24, in setup apps.populate(settings.INSTALLED_APPS) File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\registry.py&quot;, line 112, in populate app_config.import_models() File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\config.py&quot;, line 198, in import_models self.models_module = import_module(models_module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py&quot;, line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1206, in _gcd_import File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1178, in _find_and_load File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1149, in _find_and_load_unlocked File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 690, in _load_unlocked File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 940, in exec_module File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 241, in _call_with_frames_removed File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\models.py&quot;, line 94, in &lt;module&gt; class Group(models.Model): File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py&quot;, line 139, in __new__ new_class.add_to_class(obj_name, obj) File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py&quot;, line 304, in add_to_class value.contribute_to_class(cls, name) File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py&quot;, line 1583, in contribute_to_class self.remote_field.through = create_many_to_many_intermediary_model(self, cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py&quot;, line 1051, in create_many_to_many_intermediary_model 'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to}, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py&quot;, line 149, in __mod__ return str(self) % rhs ^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py&quot;, line 113, in __text_cast return func(*self.__args, **self.__kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\__init__.py&quot;, line 75, in gettext return _trans.gettext(message) ^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py&quot;, line 286, in gettext _default = _default or translation(settings.LANGUAGE_CODE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py&quot;, line 199, in translation _translations[language] = DjangoTranslation(language) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py&quot;, line 90, in __init__ self._init_translation_catalog() File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py&quot;, line 131, in _init_translation_catalog translation = self._new_gnu_trans(localedir) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File &quot;C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py&quot;, line 119, in _new_gnu_trans return gettext_module.translation( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: translation() got an unexpected keyword argument 'codeset </code></pre> <p>'</p>
[ { "answer_id": 74406853, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 1, "selected": false, "text": "remove-if-not" }, { "answer_id": 74413273, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 3, "selected": true, "text": "REMOVE-IF-NOT" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480319/" ]
74,406,730
<p>I'm trying to create a column <code>status</code> that shows if my DataFrame values are in my directory <code>test</code>. For example does folder <code>O:\Stack\Over\Flow\2010</code> exist in the <code>O:\Stack\Over\Flow</code> directory.</p> <p>My <code>pl_dest</code> DataFrame is like so:</p> <pre><code> Folder_Name_to_create 0 O:\Stack\Over\Flow\2010 1 O:\Stack\Over\Flow\2011 </code></pre> <p>Code:</p> <pre><code>import pandas as pd pl_dest = pd.DataFrame( {'Folder_Name_to_create': [r'O:\Stack\Over\Flow\2010', r'O:\Stack\Over\Flow\2011'] } ) test = (r'O:\Stack\Over\Flow') pl_dest['status'] = pl_dest['Folder_Name_to_create'].isin(test) </code></pre> <p>I receive <code>TypeError: only list-like objects are allowed to be passed to isin(), you passed a [str]</code>.</p>
[ { "answer_id": 74406853, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 1, "selected": false, "text": "remove-if-not" }, { "answer_id": 74413273, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 3, "selected": true, "text": "REMOVE-IF-NOT" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6346514/" ]
74,406,738
<p>I can do this problem using a for loop, but I'm having trouble using the recursive method.</p> <p>I want to count how many times each vowel is called and return the most frequent vowel in an array.</p> <p>If the array does not have a vowel to return is a string.</p> <pre class="lang-js prettyprint-override"><code>const vowel = ['a', 'e', 'i', 'o', 'u']; frequentVowelCounter(word, count = {}) </code></pre> <pre class="lang-js prettyprint-override"><code>frequentVowelCounter(['cat', 'rain', 'dorm', 'apple', 'sun'])); // 'a' </code></pre> <p>I tried writing a base case:</p> <pre class="lang-js prettyprint-override"><code>if (word.length != vowel) return '' </code></pre> <p>I don't think it's right, I'm just stuck.</p>
[ { "answer_id": 74406853, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 1, "selected": false, "text": "remove-if-not" }, { "answer_id": 74413273, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 3, "selected": true, "text": "REMOVE-IF-NOT" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480353/" ]
74,406,759
<p>I'm trying to write a script that tracks payment dates in google sheets (shows a different colour (either FontColor or Background) three days before payment, another colour on the day of payment and a totally different colour after the payment date.I'd appreciate if there's anyone with know how on how to use those values to get the cell name and use it to change the FontColor or alternatively if there's a better solution Here is my google sheet [![enter image description here][1]][1]</p> <p>This is the code I've written to get the dates into a list</p> <pre><code>function myFunction() { let spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); let lastRow = spreadsheet.getLastRow(); let lastCol = spreadsheet.getLastColumn(); var dataRange = spreadsheet.getActiveSheet().getRange(2, 11, lastRow, lastCol) dataRange.setFontColor(&quot;green&quot;) var data = dataRange.getDisplayValues(); let dates=[]; for (let i=0; i &lt; dates.length; i++ ) { // console.log(dates[i]) if (dates[i] === new Date().toLocaleDateString()) { dataRange.setBackground('pink') } else if (dates[i]) { // do sth } else { // maintain the current state } } } </code></pre>
[ { "answer_id": 74406853, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 1, "selected": false, "text": "remove-if-not" }, { "answer_id": 74413273, "author": "Will Ness", "author_id": 849891, "author_profile": "https://Stackoverflow.com/users/849891", "pm_score": 3, "selected": true, "text": "REMOVE-IF-NOT" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17032431/" ]
74,406,771
<p>I am trying to convert year and quarter to date in <code>pandas</code>. In example below I am trying to get <code>1980-03-31</code> for <code>1980Q1</code> and so on.</p> <pre><code>df=pd.DataFrame({'year':['1980','1980','1980','1980'],'qtr': ['Q1','Q2','Q3','Q4']}) scenario['date']=pd.to_datetime(scenario['year']+scenario['qtr'], infer_datetime_format=True) scenario[['date','year','qtr']] date year qtr 0 1980-01-01 1980 Q1 1 1980-04-01 1980 Q2 2 1980-07-01 1980 Q3 3 1980-10-01 1980 Q4 </code></pre>
[ { "answer_id": 74406885, "author": "FObersteiner", "author_id": 10197418, "author_profile": "https://Stackoverflow.com/users/10197418", "pm_score": 2, "selected": true, "text": "QuarterEnd" }, { "answer_id": 74406932, "author": "Panda Kim", "author_id": 20430449, "author_profile": "https://Stackoverflow.com/users/20430449", "pm_score": 1, "selected": false, "text": "pd.PeriodIndex(df['year'] + df['qtr'], freq='Q').to_timestamp(freq='Q')\n" }, { "answer_id": 74406981, "author": "hknjj", "author_id": 1925445, "author_profile": "https://Stackoverflow.com/users/1925445", "pm_score": 0, "selected": false, "text": "import datetime as dt\nimport pandas as pd\n\n\ndef func(x):\n # converts columns to datetime.date object\n if x.qtr == 'Q1':\n month = 1\n elif x.qtr == 'Q2':\n month = 3\n elif x.qtr == 'Q3':\n month = 7\n elif x.qtr == 'Q4':\n month = 10\n dt_obj = dt.date(year=int(x.year), month=month, day=1)\n return dt_obj\n\n\ndf=pd.DataFrame({'year':['1980','1980','1980','1980'],'qtr':\n ['Q1','Q2','Q3','Q4']})\nprint(df)\ndf['date'] = df.apply(lambda x: func(x), axis=1)\nprint(df)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8923742/" ]
74,406,816
<p>I tried write a code that the given numbers multiply by ten for each input, and then sum all of those values. If their summation is bigger than 100 it will stop. Furthermore I want to print the output as &quot;Program ends because <code>10*3+10*1+10\*8 = 120</code>, which is not less than 100&quot; while the input parameters are 3,1,8 accordingly.</p> <p>The code is works fine but the i couldnt figure out how to print as i mentioned before. Thanks</p> <p>`</p> <pre><code>l=[] k=[] while True: n = int(input(&quot;Enter Number to calculate: &quot;)) p=n*10 l.append(p) k.append(n) s= sum(l) h = &quot;10*&quot; if s&gt;=100: for i in range(len(k)) : print(&quot;Program ends because&quot;+&quot;{}&quot;.format(h)+k[i]) break </code></pre> <p>`</p>
[ { "answer_id": 74406885, "author": "FObersteiner", "author_id": 10197418, "author_profile": "https://Stackoverflow.com/users/10197418", "pm_score": 2, "selected": true, "text": "QuarterEnd" }, { "answer_id": 74406932, "author": "Panda Kim", "author_id": 20430449, "author_profile": "https://Stackoverflow.com/users/20430449", "pm_score": 1, "selected": false, "text": "pd.PeriodIndex(df['year'] + df['qtr'], freq='Q').to_timestamp(freq='Q')\n" }, { "answer_id": 74406981, "author": "hknjj", "author_id": 1925445, "author_profile": "https://Stackoverflow.com/users/1925445", "pm_score": 0, "selected": false, "text": "import datetime as dt\nimport pandas as pd\n\n\ndef func(x):\n # converts columns to datetime.date object\n if x.qtr == 'Q1':\n month = 1\n elif x.qtr == 'Q2':\n month = 3\n elif x.qtr == 'Q3':\n month = 7\n elif x.qtr == 'Q4':\n month = 10\n dt_obj = dt.date(year=int(x.year), month=month, day=1)\n return dt_obj\n\n\ndf=pd.DataFrame({'year':['1980','1980','1980','1980'],'qtr':\n ['Q1','Q2','Q3','Q4']})\nprint(df)\ndf['date'] = df.apply(lambda x: func(x), axis=1)\nprint(df)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480352/" ]
74,406,827
<p>I am trying to pivot column values (Month_End) which I have done per a few KB's but then I also need to unpivot other columns (PAC_Contract, PAC_Projected_Cost, JTD_Actual) into row values but am getting confused and not sure if PIVOT is the right want to attack this.</p> <p>SQL2012</p> <p>This is the Table</p> <p><a href="https://i.stack.imgur.com/3iphT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3iphT.png" alt="Database Records" /></a></p> <p>This is what I would like to get to</p> <p><a href="https://i.stack.imgur.com/GhOGd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GhOGd.png" alt="Desired State" /></a></p> <p>This is where I am currently at but it seems like the scenic route :)</p> <pre><code>DECLARE @columns NVARCHAR(MAX) = '', @sql NVARCHAR(MAX) = ''; -- Get the last 3 Month End Dates SELECT TOP 3 @columns += QUOTENAME(Month_End) + ',' FROM _rec_spectrum_CTC_Master GROUP BY Month_End ORDER BY Month_End desc; -- Remove the last comma SET @columns = LEFT(@columns, LEN(@columns) - 1); PRINT @columns; -- Construct the PIVOT SET @sql =' SELECT * FROM( SELECT Job_Number, Month_End, ''PAC Contract'' AS Column_Name, PAC_Contract AS Value FROM _rec_spectrum_CTC_Master WHERE Job_Number = ''A1327'' UNION SELECT Job_Number, Month_End, ''PAC Projected Cost'' AS Column_Name, PAC_Projected_Cost AS Value FROM _rec_spectrum_CTC_Master WHERE Job_Number = ''A1327'' UNION SELECT Job_Number, Month_End, ''JTD_Actual_Cost'' AS Column_Name, JTD_Actual_Cost AS Value FROM _rec_spectrum_CTC_Master WHERE Job_Number = ''A1327'' ) d PIVOT( SUM(Value) FOR Month_End IN ('+ @columns +') ) AS ppc ;'; EXECUTE sp_executesql @sql </code></pre>
[ { "answer_id": 74406885, "author": "FObersteiner", "author_id": 10197418, "author_profile": "https://Stackoverflow.com/users/10197418", "pm_score": 2, "selected": true, "text": "QuarterEnd" }, { "answer_id": 74406932, "author": "Panda Kim", "author_id": 20430449, "author_profile": "https://Stackoverflow.com/users/20430449", "pm_score": 1, "selected": false, "text": "pd.PeriodIndex(df['year'] + df['qtr'], freq='Q').to_timestamp(freq='Q')\n" }, { "answer_id": 74406981, "author": "hknjj", "author_id": 1925445, "author_profile": "https://Stackoverflow.com/users/1925445", "pm_score": 0, "selected": false, "text": "import datetime as dt\nimport pandas as pd\n\n\ndef func(x):\n # converts columns to datetime.date object\n if x.qtr == 'Q1':\n month = 1\n elif x.qtr == 'Q2':\n month = 3\n elif x.qtr == 'Q3':\n month = 7\n elif x.qtr == 'Q4':\n month = 10\n dt_obj = dt.date(year=int(x.year), month=month, day=1)\n return dt_obj\n\n\ndf=pd.DataFrame({'year':['1980','1980','1980','1980'],'qtr':\n ['Q1','Q2','Q3','Q4']})\nprint(df)\ndf['date'] = df.apply(lambda x: func(x), axis=1)\nprint(df)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2962869/" ]
74,406,894
<p>I have looked at xy answers to this problem, not a single one helped. I'm creating a simple react app for writing notes for myself. After writing a note I want it to be saved even after refreshing the page. For this I wanted to use <code>useEffect</code> hook, but it doesn't do it and yes its imported from react in header, thank you for any suggestions!</p> <pre><code>useEffect(() =&gt;{ const savedNotes = JSON.parse(localStorage.getItem(&quot;react-notes-app-data&quot;)); if(savedNotes) { setNotes(savedNotes); } }, []); useEffect(() =&gt; { localStorage.setItem(&quot;react-notes-app-data&quot;, JSON.stringify(notes)); }, [notes]); </code></pre> <p>I tried useEffect with JSON.parse and JSON.stringify to retrieve data (my note) when refreshing page.</p>
[ { "answer_id": 74406885, "author": "FObersteiner", "author_id": 10197418, "author_profile": "https://Stackoverflow.com/users/10197418", "pm_score": 2, "selected": true, "text": "QuarterEnd" }, { "answer_id": 74406932, "author": "Panda Kim", "author_id": 20430449, "author_profile": "https://Stackoverflow.com/users/20430449", "pm_score": 1, "selected": false, "text": "pd.PeriodIndex(df['year'] + df['qtr'], freq='Q').to_timestamp(freq='Q')\n" }, { "answer_id": 74406981, "author": "hknjj", "author_id": 1925445, "author_profile": "https://Stackoverflow.com/users/1925445", "pm_score": 0, "selected": false, "text": "import datetime as dt\nimport pandas as pd\n\n\ndef func(x):\n # converts columns to datetime.date object\n if x.qtr == 'Q1':\n month = 1\n elif x.qtr == 'Q2':\n month = 3\n elif x.qtr == 'Q3':\n month = 7\n elif x.qtr == 'Q4':\n month = 10\n dt_obj = dt.date(year=int(x.year), month=month, day=1)\n return dt_obj\n\n\ndf=pd.DataFrame({'year':['1980','1980','1980','1980'],'qtr':\n ['Q1','Q2','Q3','Q4']})\nprint(df)\ndf['date'] = df.apply(lambda x: func(x), axis=1)\nprint(df)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16500834/" ]
74,406,916
<p>i have the following Problem: I try to pass a string with some kind of &quot;separators&quot; to a function: i.e. <code>string=This.string.contains.dots.as.separators</code></p> <p>In the case above i know by looking, that the separators are dots, but in runtime someone shall also be able to pass a string like: <code>string=This-string-contains-hyphens-as-separators</code></p> <p>My challenge is now to get the separators. Therefore i try to loop through the given string (as the both examples above) -&gt; <strong>char for char</strong> and if there is a char which is not between the <strong>set of a-z</strong> (all letters of alphabet) it must be the separator.</p> <p>I try to find the separator under use of an &quot;<strong>inverse class</strong>&quot; with <code>findstr</code>. The funny thing is, that the <code>findstr</code> <strong>command will work if i directly paste it into the windows cmd shell</strong>: for example, <em>the following works</em>:</p> <p><code>echo .|findstr &quot;[^a-z]&quot;</code></p> <p>and does find the dot and returns an <code>errorlevel=0</code> if there is something else than an a-z (which then must be the separator) -&gt; recap: i walk through char for char through the string and on some point get the separator.</p> <p>Here is my Code-Snippet:</p> <pre class="lang-sh prettyprint-override"><code>@echo off SETLOCAL ENABLEDELAYEDEXPANSION :MAIN setlocal REM Call a function with an string and it shall return the separator in the string call :GET_THE_SEPARATOR &quot;This.string.is.separated.by.dots&quot; &quot;return_value&quot; echo The separator is = !return_value! exit /b 0 :GET_THE_SEPARATOR setlocal set &quot;separated_string=%~1&quot; REM Iterate over the first 10 chars of the string for /l %%c in (0 1 10) do ( set &quot;act_char=!separated_string:~%%c,1!&quot; REM Search for every char not in the alphabet (means to get i.e.: . , -) REM Unfortunately the findstr SYNTAX here seems to be broken, but works if you REM directly paste it into a console.: i.e.: echo .|findstr &quot;[^a-z]&quot; echo.!act_char! | findstr &quot;&quot;[^^a-z]&quot;&quot; &gt;NUL &amp;&amp; ( set &quot;separator=!act_char! ) ) REM Return the value (endlocal if &quot;%~2&quot; neq &quot;&quot; (set &quot;%~2=%separator%&quot;) ) exit /b 0 </code></pre>
[ { "answer_id": 74409035, "author": "Magoo", "author_id": 2128947, "author_profile": "https://Stackoverflow.com/users/2128947", "pm_score": 2, "selected": false, "text": "@ECHO OFF\nSETLOCAL\n\nSET \"alphabet=a b c d e f g h i j k l m n o p q r s t u v w x y z\"\n\nCALL :getsep \"This.string.is.separated.by.dots\" separators\nECHO %separators% IN %originalstring%\nCALL :getsep \"This-string-is-separated-by-dashes\" separators\nECHO %separators% IN %originalstring%\nCALL :getsep \"This string is separated by spaces\" separators\nECHO %separators% IN %originalstring%\nCALL :getsep \"This*string*is*separated*by*stars\" separators\nECHO %separators% IN %originalstring%\nGOTO :eof\n\n:getsep\nSET \"originalstring=%~1\"\nSET \"seps=%~1\"\nSETLOCAL ENABLEDELAYEDEXPANSION\nFOR %%z IN (%alphabet%) DO SET \"seps=!seps:%%z=!\"\nendlocal&SET \"%2=%seps%\"\nGOTO :eof\n" }, { "answer_id": 74411414, "author": "T3RR0R", "author_id": 12343998, "author_profile": "https://Stackoverflow.com/users/12343998", "pm_score": 0, "selected": false, "text": "@Echo off\n\nSet \"ExampleString=test-String-example^|three^&four^>five*six^<seven=eight:nine_ten^^b~eleven!twelve!\"\n\nSetlocal EnableDelayedExpansion\nSet \"TestString=!%~1!\"\n\nIf not defined TestString (\n Endlocal\n Call %~n0 \"ExampleString\"\n Goto:Eof\n)\n\nSet /A \"[#]=1\",\"Pos[#]=-1\"\nREM start count of character position at 0 index for potential use in substring modification\nREM Set TestString\n\nREM The below parsing method splits a string into it's compenent characters.\nFor /f \"usebackq Delims=\" %%G in (`%Systemroot%\\System32\\cmd.exe /u /c ^\"Echo(!TestString!^\"^|%Systemroot%\\System32\\find.exe /v \"[false_match_%~n0]\"^|%Systemroot%\\System32\\findstr.exe \"^^\"`)Do (\n Set Char=^^^%%~G\n For /f \"UseBackQ Delims=abcdefghijklmnopqrstuvwxtzABCDEFGHIJKLMNOPQRSTUVWXYZ\" %%c in (`\"Echo(\"!Char!\"\"`) Do ( \n Set /A Pos[#]+=1\n If not \"^%%~c\" == \"^^\" (\n If \"^^^%%~c\" == \"^^^!\" (\n Set Delim.![#]!.@Char.!Pos[#]!=^^^%%~c\n ) Else Set Delim.![#]!.@Char.!Pos[#]!=^%%~c\n )\n If not \"^%%~c\" == \"^^\" Set /A [#]+=1\n ) \n)\n\nSet Delim\nPause\n\nREM // perform any actions required with the delim information here or modify the script to return the values across the endlocal.\nEndlocal & Goto:eof\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9028667/" ]
74,406,944
<p>I am trying to write a formula that would move the Unit sold from the previous years to the year selected in column G. Example if I select year 2025 in column G then product should show the number that is in 2022 example 100, 2026 101,2027 102. Similarly if I select 2026 in column G then 2026 should have 100, 2027 should have 101.</p> <p>I wrote the code <code>=IF($G$6&gt;I2,0,OFFSET(I6,5,-2,1,1))</code> but I couldnt get the refence to be dynamic by year. What am I doing wrong?</p> <p><a href="https://i.stack.imgur.com/EWpwC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EWpwC.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74407345, "author": "Fernando Barbosa", "author_id": 8060081, "author_profile": "https://Stackoverflow.com/users/8060081", "pm_score": 0, "selected": false, "text": "=IF($G$6>I2,0,OFFSET(I11,0,$I$2-$G$6))" }, { "answer_id": 74407484, "author": "P.b", "author_id": 12634230, "author_profile": "https://Stackoverflow.com/users/12634230", "pm_score": 1, "selected": false, "text": "I6" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6331185/" ]
74,406,982
<p>I need to define a function that, given a list of strings, returns a string composed by the characters that are most frequent at the i-th position of every string. If multiple characters appear at the maximum frequency, the one which comes first alphabetically is chosen. <strong>External libraries are not allowed</strong>.</p> <p>Example: ['hello, 'train', 'house', 'tank', 'car'] -&gt; haaie</p> <ol> <li>h: at index 0 we have the characters ['h', 't', 'h', 't', 'c']. 'h' and 't' appear with the maximum frequency (2) but 'h' comes first in the alphabeth so the first character is 'h'.</li> <li>a: at index 1 we have the characters ['e', 'r', 'o', 'a', 'a']. 'a' appears with the maximum frequency, so the second character is 'a'.</li> <li>a: at index 2 we have the characters ['l', 'a', 'u', 'n', 'r']. All characters appear with the maximum frequency (1) but 'a' comes first in the alphabeth than the others so the third character is 'a'.</li> </ol> <p>This continues until the final string is as long as the longest string in the list.</p> <p>My current approach is to iterate through each character of each word and appending it to a list where I put all the characters that are at index 'i' of every string (this list is the value of a pair inside of a dictionary, which has the index of the characters inside of it as its key). The function then returns a string created by joining a list containig the most frequent characters inside of the lists contained in chars.values().</p> <pre><code>def f(words: list) -&gt; str: chars = dict() for word in words: for i, char in enumerate(word): chars.setdefault(i, list()).append(char) return ''.join([max(sorted(value), key = lambda x: value.count(x)) for value in chars.values()]) </code></pre> <p>This code <strong>works</strong>, but it is extremely slow (I'm working with very large lists, 100k+ strings). I know the problem is the nested for loop, but I can't figure out another approach other than this one, I've tried literally everything I could come up with. Hope you can help me, thanks in advance and have a nice day.</p>
[ { "answer_id": 74407262, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 2, "selected": true, "text": "O(n*log(n))" }, { "answer_id": 74407292, "author": "assume_irrational_is_rational", "author_id": 11622508, "author_profile": "https://Stackoverflow.com/users/11622508", "pm_score": 0, "selected": false, "text": "l = ['hello', 'train', 'house', 'tank', 'car']\nn = len(max(l, key=len))\nl_ = [i+' '*(n-len(i)) for i in l]\n''.join(max([(k.count(r), r) for r in 'zyxwvutsrqponmlkjihgfedcba'], key=lambda x: (x[0], -ord(x[1])))[1] for k in zip(*l_))\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74406982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480001/" ]
74,407,002
<p>In the example below, when I run <code>y_file.py</code>, I need <code>5</code> printed and <code>Hello</code> not printed. How to stop the execution of an imported python script <code>x_file.py</code> without exiting the python altogether? <code>sys.exit()</code> seems to exit python altogether.</p> <p><code>x_file.py</code></p> <pre><code>import sys x = 5 if __name__ != '__main__': pass # stop executing x.py, but do not exit python # sys.exit() # this line exits python print(&quot;Hello&quot;) </code></pre> <p><code>y_file.py</code></p> <pre><code>import x_file print(x_file.x) </code></pre>
[ { "answer_id": 74407262, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 2, "selected": true, "text": "O(n*log(n))" }, { "answer_id": 74407292, "author": "assume_irrational_is_rational", "author_id": 11622508, "author_profile": "https://Stackoverflow.com/users/11622508", "pm_score": 0, "selected": false, "text": "l = ['hello', 'train', 'house', 'tank', 'car']\nn = len(max(l, key=len))\nl_ = [i+' '*(n-len(i)) for i in l]\n''.join(max([(k.count(r), r) for r in 'zyxwvutsrqponmlkjihgfedcba'], key=lambda x: (x[0], -ord(x[1])))[1] for k in zip(*l_))\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1396516/" ]
74,407,004
<p>I have html that looks something like this:</p> <pre><code> &lt;as-split unit=&quot;pixel&quot; #mainViewSplit class=&quot;custom-gutter&quot; direction=&quot;horizontal&quot; gutterSize=&quot;2&quot;&gt; &lt;ng-container *ngFor=&quot;let splitItem of splitData&quot;&gt; &lt;as-split-area [id]=&quot;splitItem.id&quot; *ngIf=&quot;(splitItem.isVisible$ | async)&quot; [order]=&quot;splitItem.order&quot;&gt; &lt;ng-container *ngTemplateOutlet=&quot;splitItem.template&quot;&gt;&lt;/ng-container&gt; &lt;/as-split-area&gt; &lt;/ng-container&gt; &lt;/as-split&gt; </code></pre> <p>This works fine for split items that have id. But some of them are undefined and then there shouldn't be id at all in html. But for items without id html looks like this:</p> <pre><code>id=&quot;undefined&quot; </code></pre> <p>I also tried</p> <pre><code>[id]=&quot;splitItem.id ? splitItem.id : null&quot; </code></pre> <p>because comment in <a href="https://stackoverflow.com/questions/62209120/how-to-only-show-id-attribute-in-html-element-when-the-value-is-defined-in-angul">this</a> question suggest to use null, but it doesn't work. It just results in</p> <pre><code>id=&quot;null&quot; </code></pre> <p>How to set binding so that there won't be id in html at all?</p>
[ { "answer_id": 74410939, "author": "jspoh", "author_id": 20255176, "author_profile": "https://Stackoverflow.com/users/20255176", "pm_score": 0, "selected": false, "text": "[id]=\"splitItem.id ? splitItem.id : ''\"\n" }, { "answer_id": 74411005, "author": "Mr. Stash", "author_id": 13625800, "author_profile": "https://Stackoverflow.com/users/13625800", "pm_score": 3, "selected": true, "text": "<as-split-area\n [attr.id]=\"splitItem.id\"\n *ngIf=\"splitItem.isVisible$ | async\"\n [order]=\"splitItem.order\"\n>\n <ng-container *ngTemplateOutlet=\"splitItem.template\"></ng-container>\n</as-split-area>\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/218640/" ]
74,407,019
<p>I have a set of NUnit tests executed on a build server. I need to see test logs (results, outputs) in ApplicationInsights in Azure.</p> <ul> <li>NUnit has <code>ResultWriter</code> but it seems difficult to implement.</li> <li>I can log from my test explicitly to AppInsights but I don't see failed test logs</li> </ul> <p>I've considered few options:</p> <ul> <li>redirecting outputs from NUnit -&gt; cannot find the right API</li> <li>Instrumenting Test application with AppInsights -&gt; doesn't seem possible</li> <li>redirecting standard output/error to ILogger -&gt; could not find a way to do it</li> </ul> <p>I tried hooking up Application Insights and overriding some of NUnit TestContext properties but without any luck</p>
[ { "answer_id": 74410939, "author": "jspoh", "author_id": 20255176, "author_profile": "https://Stackoverflow.com/users/20255176", "pm_score": 0, "selected": false, "text": "[id]=\"splitItem.id ? splitItem.id : ''\"\n" }, { "answer_id": 74411005, "author": "Mr. Stash", "author_id": 13625800, "author_profile": "https://Stackoverflow.com/users/13625800", "pm_score": 3, "selected": true, "text": "<as-split-area\n [attr.id]=\"splitItem.id\"\n *ngIf=\"splitItem.isVisible$ | async\"\n [order]=\"splitItem.order\"\n>\n <ng-container *ngTemplateOutlet=\"splitItem.template\"></ng-container>\n</as-split-area>\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/309937/" ]
74,407,032
<p>Here, we initialize two associative arrays <code>arr_A</code> and <code>arr_B</code> in exactly the same way, but <code>arr_A</code> is initialized on the top-level, whereast <code>arr_B</code> is initialized inside of a function <code>foo</code>:</p> <pre><code>#!/bin/bash declare -A arr_A arr_A[bar]=42 function foo() { declare -A arr_B arr_B[bar]=58 echo &quot;content of arr_B inside foo = ${arr_B[@]}&quot; } foo echo &quot;content of arr_A on top level = ${arr_A[@]}&quot; echo &quot;content of arr_B on top level = ${arr_B[@]}&quot; </code></pre> <p>Expected output:</p> <pre><code>content of arr_B inside foo = 58 content of arr_A on top level = 42 content of arr_B on top level = 58 </code></pre> <p>Actual output:</p> <pre><code>content of arr_B inside foo = 58 content of arr_A on top level = 42 content of arr_B on top level = </code></pre> <p>Why is this happening?</p> <p>Is there any way to initialize a new associative array inside of a function, and use it after the function has returned?</p>
[ { "answer_id": 74407169, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 4, "selected": true, "text": "declare" }, { "answer_id": 74407178, "author": "Philippe", "author_id": 2125671, "author_profile": "https://Stackoverflow.com/users/2125671", "pm_score": 1, "selected": false, "text": "declare" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2707792/" ]
74,407,038
<p>Here is my code:</p> <pre><code>import discord from discord.ext import commands bot = discord.bot(command_prefix=&quot;!&quot;, help_command=None) @bot.event async def on_ready(): print(f&quot;Bot logged in as {bot.user}&quot;) bot.run(&quot;TOKEN&quot;) </code></pre> <p>The error i am getting:</p> <pre><code> File &quot;c:\Users\user\OneDrive\Desktop\coding\discord\server bots\test.py&quot;, line 6, in &lt;module&gt; bot = discord.bot(command_prefix=&quot;!&quot;, help_command=None) TypeError: 'module' object is not callable </code></pre> <p>I haven't coded in a while and i just got back to coding. I tried a simple discord.py program but it didn't seem to work. Is there any way i could fix this?</p>
[ { "answer_id": 74407166, "author": "Clement Genninasca", "author_id": 15810170, "author_profile": "https://Stackoverflow.com/users/15810170", "pm_score": 1, "selected": true, "text": "commands.Bot()" }, { "answer_id": 74409011, "author": "jean ", "author_id": 20353157, "author_profile": "https://Stackoverflow.com/users/20353157", "pm_score": 1, "selected": false, "text": "import discord\nfrom discord.ext import commands\n\nintents = discord.Intents.all()\nbot = commands.Bot(command_prefix=\"!\", help_command=None, intents = intents)\n\n\n@bot.event\nasync def on_ready():\n print(f\"Bot logged in as {bot.user}\")\n@bot.command()\nasync def hello(ctx):\n await ctx.send(f\"hi {ctx.author.mention}\")\n\n\nbot.run(\"token\")\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18399022/" ]
74,407,054
<p>I am using eSignature REST API v2.1 Java to create envelope. Document is in html format with non English language. On the signing page these non English is not displayed properly. How to handle this case? Thanks,</p> <p><code>String htmlDoc = &quot;.... .... &lt;p&gt;Signera arbetsorderavtal för anställningsnummer&lt;/p&gt; ......&quot;;</code></p> <p><code>Document document = new Document();</code></p> <p><code>document.setDocumentId(&quot;1&quot;);</code></p> <p><code>document.setName(&quot;name&quot;);</code></p> <p><code>document.setDocumentBase64(Base64.getEncoder().encodeToString(htmlDoc));</code></p> <p><code>document.setFileExtension(&quot;html&quot;);</code></p> <p><code>envelopeDefinition.setDocuments(Arrays.asList(document));</code></p> <p>Output: <a href="https://i.stack.imgur.com/By5tD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/By5tD.png" alt="enter image description here" /></a></p> <p>Expecting proper display of the foreign language.</p>
[ { "answer_id": 74407314, "author": "Inbar Gazit", "author_id": 3255871, "author_profile": "https://Stackoverflow.com/users/3255871", "pm_score": 0, "selected": false, "text": "String htmlDoc = \".... .... <p>Signera arbetsorderavtal för anställningsnummer</p> ......\";\n\nDocument document = new Document();\n\ndocument.setDocumentId(\"1\");\n\ndocument.setName(\"name\");\n\ndocument.setDocumentBase64(Base64.getEncoder().encodeToString(htmlDoc.getBytes(StandardCharsets.UTF_8)));\n\ndocument.setFileExtension(\"html\");\n\nenvelopeDefinition.setDocuments(Arrays.asList(document));\n" }, { "answer_id": 74409351, "author": "SDi", "author_id": 20480542, "author_profile": "https://Stackoverflow.com/users/20480542", "pm_score": 1, "selected": false, "text": "String htmlDoc = \"<p>Signera arbetsorderavtal för anställningsnummer</p>\"; // removed <html> & <body>\nbyte[] byteArray = htmlDoc.getBytes(**StandardCharsets.UTF_8**);\n\nDocument document = new Document();\ndocument.setDocumentId(\"1\");\ndocument.setName(\"name\");\ndocument.setFileExtension(\"html\");\ndocument.setDocumentBase64(Base64.getEncoder().encodeToString(byteArray));\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480542/" ]
74,407,066
<p>Typescript 4.9 features some changes to how the <code>in</code> operator works.</p> <p>In the code snippet below, how do I convince tsc that <code>id</code> is not a primitive value?</p> <pre class="lang-js prettyprint-override"><code>export type KeyOrId = | { key: string; } | { id: string; }; export default function foo&lt;K extends KeyOrId | null&gt;( keyOrId: K, ) { if (!keyOrId) { return undefined; } // Type 'NonNullable&lt;K&gt;' may represent a primitive value, which is not permitted as the right operand of the 'in' operator.(2638) return 'id' in keyOrId; } </code></pre> <p>I've tried a guard with <code>typeof keyOrId !== 'object'</code>. No dice.</p> <p><a href="https://tsplay.dev/WoAPlN" rel="nofollow noreferrer">Playground example</a></p>
[ { "answer_id": 74413642, "author": "Anmol kansal", "author_id": 11652772, "author_profile": "https://Stackoverflow.com/users/11652772", "pm_score": 3, "selected": true, "text": "K extends KeyOrId | null " }, { "answer_id": 74533719, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 2, "selected": false, "text": "typescript@next" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1924257/" ]
74,407,074
<p>I have a json object</p> <pre><code>sample_json ={ &quot;workspaces&quot;: [ { &quot;wsid&quot;: &quot;1&quot;, &quot;wsname&quot;: &quot;firstworkspace&quot;, &quot;report&quot;:[{&quot;reportname&quot;:&quot;r1ws1&quot;},{&quot;reportname&quot;:&quot;r2ws1&quot;},{&quot;reportname&quot;:&quot;r1ws1&quot;}] }, { &quot;wsid&quot;: &quot;2&quot;, &quot;wsname&quot;: &quot;secondworkspace&quot;, &quot;report&quot;:[{&quot;reportname&quot;:&quot;r1ws2&quot;},{&quot;reportname&quot;:&quot;r2ws2&quot;},{&quot;reportname&quot;:&quot;r1ws2&quot;}] } ]} </code></pre> <p>I want to flatten/normalize the json so that it looks like this :</p> <p><a href="https://i.stack.imgur.com/1cobp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1cobp.png" alt="enter image description here" /></a></p> <p>I can flatten each level using the pandas function &quot;json_normalize&quot; e.g Level 1</p> <pre><code>import pandas as pd df1 = pd.json_normalize(sample_json, record_path=['workspaces']) df1 </code></pre> <p><a href="https://i.stack.imgur.com/faUSQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/faUSQ.png" alt="enter image description here" /></a></p> <p>e.g Level 2</p> <pre><code>import pandas as pd df_api = pd.json_normalize(sample_json, record_path=['workspaces','report']) df_api </code></pre> <p><a href="https://i.stack.imgur.com/kzL9R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kzL9R.png" alt="enter image description here" /></a></p> <p>I have read quiet a few articles such as <a href="https://towardsdatascience.com/all-pandas-json-normalize-you-should-know-for-flattening-json-13eae1dfb7dd" rel="nofollow noreferrer">this one</a> but I am struggling to understand how to include information from the two levels (workspaces and reports) in a single dataframe. Any advice or help would be appreciated. Copy to sample data in a google colab notebook <a href="https://colab.research.google.com/drive/1iNArvLD-8RH7EEH0KFPgktBFrc7cmkTE?usp=sharing" rel="nofollow noreferrer">is here</a></p>
[ { "answer_id": 74407402, "author": "juanpa.arrivillaga", "author_id": 5014455, "author_profile": "https://Stackoverflow.com/users/5014455", "pm_score": 0, "selected": false, "text": "df = pd.DataFrame(\n [\n {\"wsid\": ws['wsid'], \"wsname\": ws['wsname'], **rep}\n for ws in sample_json[\"workspaces\"] for rep in ws['report']\n ]\n)\n" }, { "answer_id": 74408450, "author": "The Lazy Graybeard", "author_id": 9608497, "author_profile": "https://Stackoverflow.com/users/9608497", "pm_score": 2, "selected": true, "text": "jertl" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1890364/" ]
74,407,085
<p>I'm having trouble understanding how to deserialize a hash with <code>retrieve()</code> in Perl (v5.30.0):</p> <pre><code>#!/usr/bin/perl use warnings; use strict; use Storable; package main; my %origHash = (key1 =&gt; 'data1', key2 =&gt; 'data2', key3 =&gt; 'data3', key4 =&gt; 'data4'); # Retrieve, modify, and retrieve again in %origHash: printf &quot;Retrieved: %s\n&quot;, $origHash{'key2'}; $origHash{'key2'} = 'data22'; # Modify value $origHash{'key5'} = 'data5'; # Add new value printf &quot;Retrieved: %s %s\n&quot;, $origHash{'key2'}, $origHash{'key5'}; # Serialize origHash, store in file 'file': store \%origHash, 'file'; # Deserialize the hash, now store data in ref 'hashref': my %hashref = retrieve('file'); # Line 24 # Retrieve, modify, and retrieve again in 'hashref': printf &quot;Retrieved: %s\n&quot;, $hashref{'key2'}; # Line 27 $hashref{'key2'} = 'data222'; # Modify value $hashref{'key6'} = 'data6'; # Add new value printf &quot;Retrieved: %s %s\n&quot;, $hashref{'key2'}, $hashref{'key6'}; </code></pre> <p>Output is:</p> <pre><code>me@ubuntu01$ ./SerHash.perl Retrieved: data2 Retrieved: data22 data5 Reference found where even-sized list expected at ./SerHash.perl line 24. Use of uninitialized value in printf at ./SerHash.perl line 27. Retrieved: Retrieved: data222 data6 me@ubuntu01$ </code></pre> <p>So the first half of the script is Perl/Hash 101, demonstrating the simple syntax of making, retrieving from, and modifying values in a hash. Then I successfully serialize the hash and store in in file <code>file</code> with this line: <code>store \%origHash, 'file';</code>.</p> <p>I'm not sure if that worked...? Here's what I see when I look in <code>file</code> after the above <code>store</code> command is executed:</p> <pre><code>me@ubuntu01$ more file pst0 12345678 data4 data1 data3 data5 data22 me@ubuntu01$ </code></pre> <p>Huh. So my values are there, but where are the keys?</p> <p>Back to the test script: After serializing the hash, I try to deserialize the hash from <code>file</code> in this line: <code>my %hashref = retrieve('file');</code> ...although I'm not totally certain about that syntax. Note that if I try to retrieve data from the deserialized hash with this command...</p> <pre><code>printf &quot;Retrieved: %s\n&quot;, $hashref{'key2'}; # Line 27 </code></pre> <p>...the target value appears to be uninitialized? Here's the output from that command:</p> <pre><code>Use of uninitialized value in printf at ./SerHash.perl line 27. Retrieved: </code></pre> <p>Ugh, so that's not great. I note that I can add new values into the deserialized hash, but that's kinda beside the point if the data from original hash isn't available.</p> <p>This test code was built <a href="https://perldoc.perl.org/Storable" rel="nofollow noreferrer">using this tutorial</a>, which left me with a shakey understanding of the <code>retrieve()</code> function. According to the documentation:</p> <blockquote> <p>To retrieve data stored to disk, use retrieve with a file name. The objects stored into that file are recreated into memory for you, and a reference to the root object is returned. In case an I/O error occurs while reading, undef is returned instead.</p> </blockquote> <p>So <code>retrieve()</code> returns <code>a reference to the root object[.]</code>? Hmmm... So shouldn't the code be:</p> <pre><code># Deserialize the hash, now store data in ref 'hashref': # (***NOTE*** that we define hashref with a '$', not '%' now!) my $hashref = retrieve('file'); # Line 24 # Retrieve, modify, and retrieve again in 'hashref': printf &quot;Retrieved: %s\n&quot;, $hashref{'key2'}; # Line 27 $hashref{'key2'} = 'data222'; # Modify value # Line 28 $hashref{'key6'} = 'data6'; # Add new value # Line 29 printf &quot;Retrieved: %s %s\n&quot;, $hashref{'key2'}, $hashref{'key6'}; # Line 30 </code></pre> <p>Now output is:</p> <pre><code>me@ubuntu01$ ./SerHash.perl Global symbol &quot;%hashref&quot; requires explicit package name (did you forget to declare &quot;my %hashref&quot;?) at ./SerHash.perl line 27. Global symbol &quot;%hashref&quot; requires explicit package name (did you forget to declare &quot;my %hashref&quot;?) at ./SerHash.perl line 28. Global symbol &quot;%hashref&quot; requires explicit package name (did you forget to declare &quot;my %hashref&quot;?) at ./SerHash.perl line 29. Global symbol &quot;%hashref&quot; requires explicit package name (did you forget to declare &quot;my %hashref&quot;?) at ./SerHash.perl line 30. Global symbol &quot;%hashref&quot; requires explicit package name (did you forget to declare &quot;my %hashref&quot;?) at ./SerHash.perl line 30. me@ubuntu01$ </code></pre> <p>Gah! This looks even worse. I don't understand what is being returned by <code>retrieve()</code> nor how to handle it syntactically. Can anyone help?</p>
[ { "answer_id": 74407194, "author": "toolic", "author_id": 197758, "author_profile": "https://Stackoverflow.com/users/197758", "pm_score": 3, "selected": true, "text": "$hashref" }, { "answer_id": 74414557, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 2, "selected": false, "text": "retrieve" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4040743/" ]
74,407,095
<p>Thank you for any definition of what &quot;only from the first 100 commits will be linked&quot; means.</p> <p>Will I lose commits if I complete the Pull request ( PR )?</p> <blockquote> <p>This pull request will merge over 100 commits into master. Double check the source and target branches to make sure this is intentional. Work items only from the first 100 commits will be linked.</p> </blockquote> <p><a href="https://i.stack.imgur.com/RI6eu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RI6eu.png" alt="enter image description here" /></a></p> <p>I made my dev branch from main and made too many commits before trying to do a Pull request (PR). My bad.</p> <p>Thank you for any definition of what &quot;only from the first 100 commits will be linked&quot;.</p>
[ { "answer_id": 74407194, "author": "toolic", "author_id": 197758, "author_profile": "https://Stackoverflow.com/users/197758", "pm_score": 3, "selected": true, "text": "$hashref" }, { "answer_id": 74414557, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 2, "selected": false, "text": "retrieve" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/245646/" ]
74,407,103
<p>I want to start incorporating testing with Jest in my projects but I'm having a hard time getting this test to work. When I run it I get this error thrown.</p> <pre><code>thrown: &quot;Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.&quot; 5 | 6 | &gt; 7 | test('Create a new user', async()=&gt;{ | ^ 8 | 9 | await request(app).post('/').send({ 10 | name:'alex', at Object.test (tests/user.test.js:7:1) </code></pre> <p>The code in the test file looks like this</p> <pre><code>const app = require('../app'); const usersRoute = require('../routes/users'); const request = require('supertest'); test('Create a new user', async()=&gt;{ await request(app).post('/').send({ name:'alex', email:&quot;a@gmail.com&quot;, password:&quot;1234567&quot;, role:&quot;admin&quot; }).expect(201); }) </code></pre> <p>My app.js file looks like this</p> <pre><code>const express = require(&quot;express&quot;); const colors = require('colors'); const errorHandler = require('./middleware/error'); const morgan = require('morgan'); const localdb = require('./db/bootcampDB'); const fileupload = require('express-fileupload'); const path = require('path'); const cookieParser = require('cookie-parser'); //ROUTES const reviews = require('./routes/reviews'); const auth = require('./routes/auth') const bootcamps = require('./routes/bootcamps'); const courses = require('./routes/courses') const users = require('./routes/users'); const app = express(); app.use(express.json()) if(process.env.NODE_ENV === 'development'){ app.use(morgan('dev')); } localdb(); app.use(fileupload()) //SET static folder app.use(express.static(path.join(__dirname, 'public'))); app.use('/api/v1/bootcamps', bootcamps); app.use('/api/v1/courses', courses); app.use('/api/v1/auth', auth); app.use('/api/v1/users', users); app.use('/api/v1/reviews', reviews); app.use(cookieParser); app.use(errorHandler) module.exports = app; </code></pre> <p>server.js file</p> <pre><code>const app = require('./app'); const port = process.env.PORT || 4000 const server = app.listen(port, ()=&gt;{ console.log(`Server running in ${process.env.NODE_ENV} mode on port ${port}`.yellow.bold); }) process.on('unhandledRejection',(err, promise)=&gt;{ console.log(`Error: ${err.message}`.red); //Close server server.close(()=&gt;{ process.exit(1) }) }) </code></pre> <p>This particular test needs to go through the &quot;/api/v1/users&quot; route that looks like this</p> <pre><code>router.route('/').get(advancedResults(User), getUsers).post(createUsers); </code></pre> <p>That line of of code is in file called uses.js that is in a folder called routes.</p> <p>user.js file</p> <pre><code> const express = require('express'); const {getUsers,getSingleUsers,createUsers, deleteUsers, updateUsers} = require('../controllers/users'); const User = require('../models/user'); const router = express.Router({mergeParams:true}); const {protect, authorize} = require('../middleware/auth') const advancedResults = require('../middleware/advancedResults'); router.use(protect); router.use( authorize('admin')) router.route('/').get(advancedResults(User), getUsers).post(createUsers); router.route('/:id').get(getSingleUsers).put(updateUsers).delete(deleteUsers); module.exports = router; </code></pre> <p>The method it self is in a file called user.js that is in a controllers folder. It looks like this</p> <pre><code>// @desc Create user // @route POST /api/v1/auth/users // @access Private/Admin exports.createUsers = asynHandler(async(req, res, next)=&gt; { const user = await User.create(req.body) res.status(201).json({success:true, data: user}) }); </code></pre> <p>One of the things I've done is change what's being passed into requests. For example if I pass in <code>'/api/v1/users'</code> I don't get the timed error I get this error</p> <pre><code> expected 201 &quot;Created&quot;, got 404 &quot;Not Found&quot; 12 | password:&quot;1234567&quot;, 13 | role:&quot;admin&quot; &gt; 14 | }).expect(201); | ^ 15 | 16 | }) 17 | at Object.expect (tests/user.test.js:14:8) ---- at Test._assertStatus (node_modules/supertest/lib/test.js:252:14) at node_modules/supertest/lib/test.js:308:13 at Test._assertFunction (node_modules/supertest/lib/test.js:285:13) at Test.assert (node_modules/supertest/lib/test.js:164:23) at localAssert (node_modules/supertest/lib/test.js:120:14) at node_modules/supertest/lib/test.js:125:7 at Test.fn [as callback] (node_modules/superagent/src/node/index.js:924:3) at IncomingMessage.callback (node_modules/superagent/src/node/index.js:1153:18) </code></pre> <p>This makes me even more confused because I thought I was telling the program to create data, not find it. If anyone can help me understand Jest and what's going on here I would greatly appreciate.</p> <p>Thanks</p>
[ { "answer_id": 74407194, "author": "toolic", "author_id": 197758, "author_profile": "https://Stackoverflow.com/users/197758", "pm_score": 3, "selected": true, "text": "$hashref" }, { "answer_id": 74414557, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 2, "selected": false, "text": "retrieve" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9053029/" ]
74,407,168
<p>I am re-building my Laravel app and, in the process, redesigning the data model.</p> <ol> <li>I have a subset of my Migrations (35) I need to run to create the data model in the new app.</li> <li>Then, I need to run some Seeders to populate the new tables.</li> <li>Some of the new tables (12) have a column &quot;old_id&quot; where I place the &quot;id&quot; from the old data model to handle foreign keys/joins. I run a series of Update statements to change the foreign key values from the &quot;old_id&quot; to the new id.</li> <li>Then, I want to run additional Migrations (12) that drop the &quot;old_id&quot; columns.</li> </ol> <p>Here are the commands I'm running currently that do everything for me - clear DB, run migrations, populate data, and update keys.</p> <pre><code>php artisan migrate:reset php artisan migrate:fresh --seed --seeder=DatabaseSeeder </code></pre> <p>I'm trying to find a way to only run a portion of my Migrations prior to executing DatabaseSeeder, and then run the remaining Migrations after (or as the last step of) the DatabaseSeeder.</p> <p>Contents of DatabaseSeeder::class:</p> <pre><code>public function run() { $this-&gt;call([ // Seeders to populate data UserSeeder::class, AssociationSeeder::class, ... lots more classes ... // Last Seeder class executes Update statements to update foreign keys DatabaseUpdateSeeder::class, ]); </code></pre> <p>Thank you!</p>
[ { "answer_id": 74455242, "author": "thePITman", "author_id": 744103, "author_profile": "https://Stackoverflow.com/users/744103", "pm_score": 2, "selected": true, "text": "php artisan migrate:fresh --path=/database/migrations/batch-one --seed --seeder=DatabaseSeeder\n\nphp artisan migrate --path=/database/migrations/batch-two\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/744103/" ]
74,407,172
<p>I want to search through a pdf file and find the page that contains a specific phrase. What I have so far is:</p> <pre><code>object = PyPDF2.PdfFileReader(&quot;20220625.pdf&quot;) numpages = object.getNumPages() string = &quot;SYSTEM WIDE OUTLET SUMMARY&quot; for i in range(0, numpages): page = object.getPage(i) text = page.extractText() if text.find(string): print(i) </code></pre> <p>The output of this code is: 0 1 2 3 ...</p> <p>I also used &quot;if string in text&quot; instead of &quot;text.find(string)&quot;, but it did not work either.</p> <p>This is surprising since this phrase only exists on page 77!</p>
[ { "answer_id": 74407265, "author": "romain gal", "author_id": 9612932, "author_profile": "https://Stackoverflow.com/users/9612932", "pm_score": 0, "selected": false, "text": "t = PyPDF2.PdfFileReader(\"20220625.pdf\")\nnumpages = t.getNumPages()\nstring = \"SYSTEM WIDE OUTLET SUMMARY\"\nfor i in range(0, numpages):\n page = t.getPage(i)\n text = page.extractText()\n if string in text: # changed here\n print(i)\n" }, { "answer_id": 74407267, "author": "Sebastian Baltser", "author_id": 11786068, "author_profile": "https://Stackoverflow.com/users/11786068", "pm_score": 2, "selected": false, "text": "str.find" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10298264/" ]
74,407,198
<p>I have an ASP.NET Core Web application that has an interface in the application that inherits a class from the interface. I am trying to use the interface by dependency injection in the controller constructor, but I always get the following error</p> <blockquote> <p>An unhandled exception occurred while processing the request. InvalidOperationException: Unable to resolve service for type '<strong>DependenceInjection_Dapper.Services.SendSMS</strong>' while attempting to activate '<strong>DependenceInjection_Dapper.Controllers.HomeController</strong>'. Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)</p> </blockquote> <p>The interface codes are as follows:</p> <pre class="lang-cs prettyprint-override"><code>public interface IsmsSender { string sendSms(); } </code></pre> <p>The class codes are as follows:</p> <pre class="lang-cs prettyprint-override"><code>public class SendSms : IsmsSender { public string sendSms() { return &quot;send sms&quot;; } } </code></pre> <p>And the following code is added in the <code>program.cs</code> file:</p> <pre class="lang-cs prettyprint-override"><code>builder.Services.AddTransient&lt;IsmsSender, SendSms&gt;(); </code></pre> <p>Also, the manufacturer of the controller is as follows:</p> <pre class="lang-cs prettyprint-override"><code>public class HomeController : Controller { private readonly IsmsSender _smsSender; public HomeController(SendSms smsSender) { _smsSender = smsSender; } public IActionResult Index() { ViewBag.send = _smsSender.sendSms(); return View(); } } </code></pre> <p>However, I always get an error.</p> <p>I behaved exactly according to the Microsoft documentation, but the problem was not solved.</p>
[ { "answer_id": 74407375, "author": "julealgon", "author_id": 1946412, "author_profile": "https://Stackoverflow.com/users/1946412", "pm_score": 3, "selected": true, "text": "public class HomeController : Controller\n{\n private readonly IsmsSender _smsSender;\n\n public HomeController(IsmsSender smsSender)\n {\n _smsSender = smsSender;\n }\n\n public IActionResult Index()\n {\n ViewBag.send = _smsSender.sendSms();\n return View();\n }\n}\n" }, { "answer_id": 74407982, "author": "Aym003", "author_id": 20471079, "author_profile": "https://Stackoverflow.com/users/20471079", "pm_score": -1, "selected": false, "text": " public HomeController(ISendSms smsSender)\n {\n _smsSender = smsSender;\n }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15918486/" ]
74,407,205
<p>I have simple function where I have 3 checkboxes and trying to something like if are checkboxes unchecked, button should be disabled and if I check all (not just 1 or 2), button will activate</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code> function sub() { var a = document.getElementById("ch1"); var b = document.getElementById("ch2"); var c = document.getElementById("ch3"); var btn = document.getElementById("btn") if (a.checked == true &amp;&amp; b.checked == true &amp;&amp; c.checked == true){ return btn.disabled = !!this.checked; } else { return btn.disabled; } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="checkbox" id="ch1" &gt; &lt;input type="checkbox" id="ch2" &gt; &lt;input type="checkbox" id="ch3" &gt; &lt;button onclick="sub()" id="btn"&gt;Submit&lt;/button&gt; &lt;/body&gt; &lt;script&gt; &lt;/script&gt; &lt;/html&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74407293, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 3, "selected": true, "text": "EventListener" }, { "answer_id": 74407315, "author": "Zak", "author_id": 1507691, "author_profile": "https://Stackoverflow.com/users/1507691", "pm_score": 2, "selected": false, "text": "boolean" }, { "answer_id": 74407479, "author": "Nafees", "author_id": 7005925, "author_profile": "https://Stackoverflow.com/users/7005925", "pm_score": 0, "selected": false, "text": "document.getElementById(\"ch1\").checked = true;\ndocument.getElementById(\"ch2\").checked = true;\ndocument.getElementById(\"ch3\").checked = true;\nvar checkedCount = 3;\nvar checkboxes = document.querySelectorAll(\"input[name=checkbox]\");\ncheckboxes.forEach(function(checkbox){\ncheckbox.addEventListener('change', function() {\n if (this.checked) {\n console.log(\"Checkbox is checked..\");\n checkedCount++;\n console.log(checkedCount);\n } else {\n console.log(\"Checkbox is not checked..\");\n checkedCount--;\n console.log(checkedCount);\n\n }\n if(checkedCount<3){\n document.getElementById(\"btn\").disabled = true;\n }else{\n document.getElementById(\"btn\").disabled = false;\n }\n });\n})\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10087217/" ]
74,407,242
<p>pip install Django</p> <p>'pip' is not recognized as an internal or external command, operable program or batch file.</p>
[ { "answer_id": 74407293, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 3, "selected": true, "text": "EventListener" }, { "answer_id": 74407315, "author": "Zak", "author_id": 1507691, "author_profile": "https://Stackoverflow.com/users/1507691", "pm_score": 2, "selected": false, "text": "boolean" }, { "answer_id": 74407479, "author": "Nafees", "author_id": 7005925, "author_profile": "https://Stackoverflow.com/users/7005925", "pm_score": 0, "selected": false, "text": "document.getElementById(\"ch1\").checked = true;\ndocument.getElementById(\"ch2\").checked = true;\ndocument.getElementById(\"ch3\").checked = true;\nvar checkedCount = 3;\nvar checkboxes = document.querySelectorAll(\"input[name=checkbox]\");\ncheckboxes.forEach(function(checkbox){\ncheckbox.addEventListener('change', function() {\n if (this.checked) {\n console.log(\"Checkbox is checked..\");\n checkedCount++;\n console.log(checkedCount);\n } else {\n console.log(\"Checkbox is not checked..\");\n checkedCount--;\n console.log(checkedCount);\n\n }\n if(checkedCount<3){\n document.getElementById(\"btn\").disabled = true;\n }else{\n document.getElementById(\"btn\").disabled = false;\n }\n });\n})\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480706/" ]
74,407,249
<p><strong>New to Bootstrap and using version 5-2-0</strong></p> <p>In my layout I wanted to have the image of the cat take up one side and then have the content and form on the other size (content first then form underneath) but I can't get it to work.</p> <pre><code>&lt;div class=&quot;grid&quot;&gt; &lt;div class=&quot;g-col-6 g-start-1&quot;&gt; &lt;img src=&quot;http://placekitten.com/g/200/300&quot; alt=&quot;kitty kitty&quot;&gt; &lt;/div&gt; &lt;div class=&quot;g-col-6 g-start-6&quot;&gt; &lt;h1&gt;Hello&lt;/h1&gt; &lt;p&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni natus reiciendis corrupti quasi sit, ipsam officia doloribus totam fuga pariatur aliquid! Molestias et sapiente iusto, perspiciatis similique rem ipsum dolores?&lt;/p&gt; &lt;/div&gt; &lt;div class=&quot;g-col-6 g-start-6&quot;&gt;form&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>Codepen</strong>: <a href="https://codepen.io/emmabbb/pen/ExRmgZE" rel="nofollow noreferrer">https://codepen.io/emmabbb/pen/ExRmgZE</a></p>
[ { "answer_id": 74407293, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 3, "selected": true, "text": "EventListener" }, { "answer_id": 74407315, "author": "Zak", "author_id": 1507691, "author_profile": "https://Stackoverflow.com/users/1507691", "pm_score": 2, "selected": false, "text": "boolean" }, { "answer_id": 74407479, "author": "Nafees", "author_id": 7005925, "author_profile": "https://Stackoverflow.com/users/7005925", "pm_score": 0, "selected": false, "text": "document.getElementById(\"ch1\").checked = true;\ndocument.getElementById(\"ch2\").checked = true;\ndocument.getElementById(\"ch3\").checked = true;\nvar checkedCount = 3;\nvar checkboxes = document.querySelectorAll(\"input[name=checkbox]\");\ncheckboxes.forEach(function(checkbox){\ncheckbox.addEventListener('change', function() {\n if (this.checked) {\n console.log(\"Checkbox is checked..\");\n checkedCount++;\n console.log(checkedCount);\n } else {\n console.log(\"Checkbox is not checked..\");\n checkedCount--;\n console.log(checkedCount);\n\n }\n if(checkedCount<3){\n document.getElementById(\"btn\").disabled = true;\n }else{\n document.getElementById(\"btn\").disabled = false;\n }\n });\n})\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7322572/" ]
74,407,276
<p>I am very new to Prometheus and have the following alert in Prometheus whose goal is to get triggered when number errors in the total number of requests is higher than 5 %:</p> <pre><code>sum(increase(errorMetric{service_name=&quot;someservice&quot;}[5m])) / sum(increase(http_requests_count{service_name=&quot;someservice&quot;, path=&quot;/some/path&quot;}[5m])) &gt; 0.05 </code></pre> <p>I have an overall idea of the traffic and it can range between 100 requests per hour over 24h interval. How valuable is to have the interval set for 5m? Shall this range over a longer period of time, e.g. 1h. This alert goes off and it does not really inform us of a problem. What is your view?</p> <p>Thank you</p>
[ { "answer_id": 74407293, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 3, "selected": true, "text": "EventListener" }, { "answer_id": 74407315, "author": "Zak", "author_id": 1507691, "author_profile": "https://Stackoverflow.com/users/1507691", "pm_score": 2, "selected": false, "text": "boolean" }, { "answer_id": 74407479, "author": "Nafees", "author_id": 7005925, "author_profile": "https://Stackoverflow.com/users/7005925", "pm_score": 0, "selected": false, "text": "document.getElementById(\"ch1\").checked = true;\ndocument.getElementById(\"ch2\").checked = true;\ndocument.getElementById(\"ch3\").checked = true;\nvar checkedCount = 3;\nvar checkboxes = document.querySelectorAll(\"input[name=checkbox]\");\ncheckboxes.forEach(function(checkbox){\ncheckbox.addEventListener('change', function() {\n if (this.checked) {\n console.log(\"Checkbox is checked..\");\n checkedCount++;\n console.log(checkedCount);\n } else {\n console.log(\"Checkbox is not checked..\");\n checkedCount--;\n console.log(checkedCount);\n\n }\n if(checkedCount<3){\n document.getElementById(\"btn\").disabled = true;\n }else{\n document.getElementById(\"btn\").disabled = false;\n }\n });\n})\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/397940/" ]
74,407,298
<p>I was wondering if there is any way to access the expected data type within a function similar to an event arg. I am doubtful that this is possible, though it would be an excellent feature.</p> <p>I frequently work with (old and disorganized)Mysql databases creating interfaces through VB.Net. Often I will have an optional field which contains a NULL value in the database. I am frequently dealing with errors due to NULL and dbnull values in passing data to and from the database.</p> <p>To complicate things, I often am dealing with unexpected datatypes. I might have an integer zero, a double zero, an empty string, or a string zero.</p> <p>So I spend a fair amount of code checking that each entry is of the expected type and or converting NULLs to zeros or empty strings depending on the case. I have written a function ncc(null catch convert) to speed up this process.</p> <pre><code>Public Function ncc(obj As Object, tp As Type) As Object 'Null Catch Convert Function... </code></pre> <p>My function works great, but I have to manually set the type every time I call the function. It would be so much easier if it were possible to access the expected type of the expression. Here is an example of what I mean.</p> <pre><code>Dim table as datatable adapter.fill(table) dim strinfo as string dim intinfo as long strinfo = ncc(table.Rows(0).Item(0),gettype(String)) 'here a string is expected intinfo = ncc(table.Rows(0).Item(0),gettype(Long)) 'here a long is expected </code></pre> <p>It would be so much more efficient if it were possible to access the expected type directly from the function.</p> <p>Something like this would be great:</p> <pre><code>Public Function ncc(obj As Object, optional tp As Type = nothing) As Object If tp Is Nothing Then tp = gettype(ncc.expectedtype) </code></pre> <p>That way I do not have to hard code the type on each line.</p> <pre><code>strinfo = ncc(table.Rows(0).Item(0)) </code></pre>
[ { "answer_id": 74407870, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "ncc" }, { "answer_id": 74418135, "author": "Albert D. Kallal", "author_id": 10527, "author_profile": "https://Stackoverflow.com/users/10527", "pm_score": 0, "selected": false, "text": "Public Function ncc(obj As Object, Optional nullv As Object = Nothing) As Object\n\n If obj Is Nothing OrElse IsDBNull(obj) Then\n Return nullv\n End If\n\n Return obj\n\nEnd Function\n" }, { "answer_id": 74492199, "author": "Craig", "author_id": 2659161, "author_profile": "https://Stackoverflow.com/users/2659161", "pm_score": 0, "selected": false, "text": "Sub" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11937392/" ]
74,407,325
<p>i am trying to make my button disappear if my textarea is empty</p> <p>until now i have made some code for it but i still cant do it</p> <p>in the code i am trying to make the css dynamic by having it change accoring to some ternery condition id the condition is met the css will allow the button to work and if not the other css class will turn the button off my problem is that i want the on/off condition to work only when the textfield has more than one letter ( is not empty ) this will help me in my posting application as it will not post any empty posts instead only posts with letters and words ( non empty textarea) will post</p> <p>here is the code:</p> <pre><code>function PostingNow() { const [post, setPost] = useContext(Mycontext); const tw = useRef('') const[count,setCount] = useState(false) return ( &lt;div &gt; &lt;textarea placeholder='whats up?' className=&quot;box&quot; ref={tw}&gt;&lt;/textarea&gt; &lt;button className={count?'tweetbutton':'unclickable'} &gt; Tweet &lt;/button&gt; &lt;/div&gt; {post.map((post, i) =&gt; ( &lt;Postingcomponent name ='user name'image={Photo} key={i} postContent={post}/&gt; ))} &lt;/div&gt; ); } export default PostingNow </code></pre>
[ { "answer_id": 74407410, "author": "windowsill", "author_id": 5708566, "author_profile": "https://Stackoverflow.com/users/5708566", "pm_score": 2, "selected": false, "text": "{textAreaText && <button ... />}\n" }, { "answer_id": 74407625, "author": "Mahesh Samudra", "author_id": 1481519, "author_profile": "https://Stackoverflow.com/users/1481519", "pm_score": 1, "selected": false, "text": "const [textarea, setTextarea] = useState(\"\")\n\n...\n\n<textarea onChange={e => setTextarea(e.target.value)}>{textarea}</textarea>\n\n" }, { "answer_id": 74407743, "author": "Johnny Cache", "author_id": 7767240, "author_profile": "https://Stackoverflow.com/users/7767240", "pm_score": 1, "selected": false, "text": "<textarea placeholder='whats up?' className=\"box\" ref={tw} class='unclickable' \n onkeyup=\"fixPostButton(this, 'postButton', 'unclickable', 'tweetbutton');\">\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20181776/" ]
74,407,353
<p>i have a js file action.js and i want to use javaScript in angular. so when i read about it, it says that js file must be put in assets and the path must be refered in scripts array in angular.json and then using declare in ts and ngOnInit but this raises an error that the function is undefined beside that is forbidden to access the js file and MIME type checking is enabled</p> <p>here is my js file function</p> <pre><code>function Di(){ console.log('ffffffffffffff'); } </code></pre> <p>the app.component.ts</p> <pre><code>import { AstMemoryEfficientTransformer } from '@angular/compiler'; import { Component, OnInit } from '@angular/core'; declare function Di(): any; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit{ title = 'Calculator'; ngOnInit() { Di(); } } </code></pre> <p>angular.json</p> <pre><code>&quot;styles&quot;: [ &quot;src/styles.scss&quot; ], &quot;scripts&quot;: [&quot;src/assets/js/action.js&quot;] }, </code></pre> <p>app.component.html</p> <pre><code> &lt;/div&gt; &lt;/div&gt; &lt;script src = &quot;/src/assets/action.js&quot;&gt;&lt;/script&gt; &lt;/body&gt; </code></pre> <p>thanks in advance</p> <p>want to use js functions in angular</p>
[ { "answer_id": 74407410, "author": "windowsill", "author_id": 5708566, "author_profile": "https://Stackoverflow.com/users/5708566", "pm_score": 2, "selected": false, "text": "{textAreaText && <button ... />}\n" }, { "answer_id": 74407625, "author": "Mahesh Samudra", "author_id": 1481519, "author_profile": "https://Stackoverflow.com/users/1481519", "pm_score": 1, "selected": false, "text": "const [textarea, setTextarea] = useState(\"\")\n\n...\n\n<textarea onChange={e => setTextarea(e.target.value)}>{textarea}</textarea>\n\n" }, { "answer_id": 74407743, "author": "Johnny Cache", "author_id": 7767240, "author_profile": "https://Stackoverflow.com/users/7767240", "pm_score": 1, "selected": false, "text": "<textarea placeholder='whats up?' className=\"box\" ref={tw} class='unclickable' \n onkeyup=\"fixPostButton(this, 'postButton', 'unclickable', 'tweetbutton');\">\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19671309/" ]
74,407,415
<p><a href="https://i.stack.imgur.com/uUp6e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uUp6e.png" alt="nginx configuration" /></a></p> <p>i tried to forward traffic from server 192.168.243.71 to domain that show in command &quot;oc get routes&quot; / &quot;kubectl get ingress&quot;, but its not as simple as that. The fact is my Nginx Reverse Proxy in server 192.168.243.x will forward the request to the IP Address of loadbalancer instead of the real domain that i wrote in nginx.conf</p> <p>the result <a href="https://i.stack.imgur.com/Wyqce.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wyqce.png" alt="when i access 192.168.243.71" /></a></p> <p>I was expecting it will show the same result when I access the domain via web browser that show in &quot;oc get routes&quot; or &quot;kubectl get ingress&quot;</p>
[ { "answer_id": 74407410, "author": "windowsill", "author_id": 5708566, "author_profile": "https://Stackoverflow.com/users/5708566", "pm_score": 2, "selected": false, "text": "{textAreaText && <button ... />}\n" }, { "answer_id": 74407625, "author": "Mahesh Samudra", "author_id": 1481519, "author_profile": "https://Stackoverflow.com/users/1481519", "pm_score": 1, "selected": false, "text": "const [textarea, setTextarea] = useState(\"\")\n\n...\n\n<textarea onChange={e => setTextarea(e.target.value)}>{textarea}</textarea>\n\n" }, { "answer_id": 74407743, "author": "Johnny Cache", "author_id": 7767240, "author_profile": "https://Stackoverflow.com/users/7767240", "pm_score": 1, "selected": false, "text": "<textarea placeholder='whats up?' className=\"box\" ref={tw} class='unclickable' \n onkeyup=\"fixPostButton(this, 'postButton', 'unclickable', 'tweetbutton');\">\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480806/" ]
74,407,418
<p>I am just learning R and got to functions. I have made a function of 0 or more variables, but they always return one value. I can make a function that returns a vector of values using <code>c(x,y,z)</code>, but when I input a vector, it just returns a longer vector. For example if I make a function <code>f &lt;- function(x) { c(x, x^2, x^3) }</code> and pass it <code>2</code>, it returns <code>2, 4, 8</code>. But if i pass it the vector <code>2,3,4</code>, it returns <code>2,4,8,3,9,27,4,16,64</code>. Where I would like a matrix with 3 rows corresponding to the 3 inputs I gave it, and 3 columns with the return values. So a 3x3 matrix with the columns <code>(2,3,4),(4,9,16),(8,27,64)</code>. I would also love to be able to do this using base functionality, although if I have to use a package to do this that would also be fine</p> <p>tried input <code>(2,3,4)</code>. wanted output:</p> <pre><code>2 4 8 3 9 27 4 16 64 </code></pre> <p>but got <code>(2,4,8,3,9,27,4,16,64)</code>.</p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20200813/" ]
74,407,437
<p><a href="https://i.stack.imgur.com/i1LdP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i1LdP.jpg" alt="what I want" /></a></p> <p>I want to make this - when you hover over each image, the text is different. it's for company bios. this has been driving me insane. it seems if text is in not in the image CSS can't do it? is the only solution javascript? sorry if this is a silly question, I am self-taught, probably like most of us here :)</p> <p>I have tried flex, div, lists, but it seems that if the text is in a different than the photos, CSS won't let me do it? (I've made the code super simple to portray the idea)</p> <p>if I do</p> <pre><code>&lt;div id=&quot;headshot-row&quot;&gt; &lt;div id=&quot;headshot-1&quot;&gt;headshot1&lt;/div&gt; &lt;div id=&quot;headshot-2&quot;&gt;headshot2&lt;/div&gt; &lt;div id=&quot;headshot-3&quot;&gt;headshot3&lt;/div&gt; &lt;div id=&quot;headshot-4&quot;&gt;headshot4&lt;/div&gt; &lt;/div&gt; &lt;div id=&quot;bios&quot;&gt; &lt;div id=&quot;bio-1&quot;&gt;bio1&lt;/div&gt; &lt;div id=&quot;bio-2&quot;&gt;bio2&lt;/div&gt; &lt;div id=&quot;bio-3&quot;&gt;bio3&lt;/div&gt; &lt;div id=&quot;bio-4&quot;&gt;bio4&lt;/div&gt; &lt;/div&gt; </code></pre> <p>I would like</p> <pre><code>#headshot-row { margin: 0 auto; display: flex; justify-content: space-around; } #bios { margin: 0 auto; display: none; } #headshot-1:hover #bio-1 { display: block } </code></pre>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9105397/" ]
74,407,506
<p>I have an WPF User control which is is hosted in an Elementhost. I use elementhost to include an WPF user control in my classical Windows forms app.</p> <p>Now, from Windows forms side I am trying to capture the mouseDown event that is produced in an WPF label but I don't know how to do it.</p> <p>Any ideas?</p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1624552/" ]
74,407,523
<p>Lately I've stuck with some project. What I want to do? I have some number of classes. Let's say something like that:</p> <pre class="lang-c# prettyprint-override"><code>public class ActionEventArgs : EventArgs { public Creature actor; } public class LocationEventArgs : ActionEventArgs { public Location loc; } public class Action { public virtual void Do(object sender, ActionEventArgs e) { //... do something with it; } } public class LocationAction : Action { public override void Do(object sender, LocationEventArgs e) // error, signatures differs { //... do something with it; } } public class MainClass { public Action a { get; protected set; } public void InitAction() { a = new LocationAction(); } public void DoAction(Creature actor, Location location) { a.Do(this, new LocationEventArgs() { actor = actor, loc = location }); } } </code></pre> <p>Well, it didn't work because of different methods signatures. Ok. Of course, I can use something like class checks like:</p> <pre class="lang-c# prettyprint-override"><code>public class LocationAction : Action { public override void Do(Action sender, ActionEventArgs e) { if (e is LocationEventArgs) throw new ArgumentException(&quot;e must be LocationEventArgs&quot;); //... do something with it; } } </code></pre> <p>But I don't really like it, because it's only runtime thing. So, the question is: how to do this properly? Is there a way?</p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19283087/" ]
74,407,545
<p>I am using windows 11 and have installed python 2.7 first, and python 3.10 right after. I have set the environment path for both.</p> <p>I have also made a copy of the python exe and renamed them to &quot;python2&quot; and &quot;python3&quot; (see below)</p> <p><a href="https://i.imgur.com/oZlL2iS.jpeg" rel="nofollow noreferrer">https://i.imgur.com/oZlL2iS.jpeg</a></p> <p><a href="https://i.imgur.com/MBRe9LL.jpeg" rel="nofollow noreferrer">https://i.imgur.com/MBRe9LL.jpeg</a></p> <p>In the command prompt when I type &quot;python - - version&quot; it displays the last version of python I installed which is python 3. And when I type &quot;python - 2 - - version&quot; it displays the python 2 version I installed. Everything is working as it's suppose. (see below)</p> <p><a href="https://i.imgur.com/HPXqmIM.png" rel="nofollow noreferrer">https://i.imgur.com/HPXqmIM.png</a></p> <p>Now at this point I created two different .py files (contents of files below)</p> <p><a href="https://i.imgur.com/bl6THNk.jpeg" rel="nofollow noreferrer">https://i.imgur.com/bl6THNk.jpeg</a></p> <p><a href="https://i.imgur.com/l3aTut6.jpeg" rel="nofollow noreferrer">https://i.imgur.com/l3aTut6.jpeg</a></p> <p>The problem I am running into is that when I double click these python files, the command prompt opens and displays python 2.7 on both, even though I have the shebang line to associate with python 3 in one of the files.</p> <p>In windows 10 which I set up many years ago, I have everything setup exactly the same, except for the python versions (I have python 2.7 and python 3.6). And when I double click the python 2 shebang file, the output is python 2.7, and when I double click the python 3 shebang file, it displays python 3.6.</p> <p>How can I get this same outcome in windows 11? I'm not quite sure what the problem is.</p> <p>I initially used the help from the answers given to the same question in windows 10 from many years ago, but these answers aren't working for windows 11. See below</p> <p><a href="https://stackoverflow.com/questions/4583367/how-to-run-multiple-python-versions-on-windows">How to run multiple Python versions on Windows</a></p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4472210/" ]
74,407,566
<p>My data is in decimal type eg. 1.5. I need to convert into DD: HH:MM.</p> <p>So in my case it should display as 1 Hr and 30 min. I'm new to sql &amp; plsql.</p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480963/" ]
74,407,585
<p>I am trying to update a timestamp on DB2 i Series table but it is failing.</p> <pre><code>UPDATE table1 SET datetime1 = CURRENT TIMESTAMP FROM table1 tbl1 INNER JOIN table2 tbl2 ON tbl1.ID = tbl2.ID </code></pre> <p>The error I am getting is that <code>Keyword FROM not expected</code>.</p> <p>Thx in advance</p>
[ { "answer_id": 74407474, "author": "zephryl", "author_id": 17303805, "author_profile": "https://Stackoverflow.com/users/17303805", "pm_score": 2, "selected": true, "text": "matrix()" }, { "answer_id": 74407511, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "cbind" }, { "answer_id": 74407533, "author": "Dan Adams", "author_id": 13210554, "author_profile": "https://Stackoverflow.com/users/13210554", "pm_score": 1, "selected": false, "text": "outer()" }, { "answer_id": 74407544, "author": "SamR", "author_id": 12545041, "author_profile": "https://Stackoverflow.com/users/12545041", "pm_score": 1, "selected": false, "text": "outer()" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15357969/" ]
74,407,595
<p>I am reading lines from a tsv file, and then trying to delimit them by <code>words = array.split(&quot;\t&quot;)</code></p> <p>words is an array that i have already initiated by <code>String[] words = {&quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;, &quot;0&quot;}</code> so it has a fixed length of 6. However, words[i] can have a different length of words[j]. I absolutely want words to have its length fixed to 6. Why is that happening and how do i fix this?</p> <p>Tried <code>for(int i=0; i&lt;x; i++){ String[] words = new String[6] }</code></p>
[ { "answer_id": 74408428, "author": "hayden.mumm", "author_id": 13270701, "author_profile": "https://Stackoverflow.com/users/13270701", "pm_score": 2, "selected": false, "text": "String[] splitWithoutLimit = \"Column1,Column2,Column3\".split(\",\")\n\n// splitWithoutLimit will contain the following values:\n// { \"Column1\", \"Column2\", \"Column3\" }\n\nString[] splitWithLimit = \"Column1,Column2,Column3\".split(\",\", 2)\n\n// splitWithLimit will contain the following values:\n// { \"Column1\", \"Column2,Column3\" }\n" }, { "answer_id": 74410133, "author": "BccHnw", "author_id": 14754410, "author_profile": "https://Stackoverflow.com/users/14754410", "pm_score": 1, "selected": true, "text": "\"0\"" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7143413/" ]
74,407,602
<p>I want to create two items (Circle above text, centered horizontally) according to following image:</p> <p><a href="https://i.stack.imgur.com/s68mO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s68mO.jpg" alt="enter image description here" /></a></p> <p>I have created following code:</p> <pre><code>Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ IconButton( icon: const Icon( Icons.circle, color: Colors.white, size: 40, ), onPressed: () {}, ), const Text( 'text', style: TextStyle( color: Colors.white, fontSize: 16, ), ), ], ) </code></pre> <p>However, the result is following:</p> <p><a href="https://i.stack.imgur.com/BZeFI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BZeFI.jpg" alt="enter image description here" /></a></p> <p>I found out that the problem is with the <code>size</code> of <code>IconButton</code>. When I remove this line, the icon will be smaller (as expected) and the text below would be centered. It seems that when Icon size is increased, it is not increased from the central point of the icon (to the all directions evenly), but it is increased <strong>to the right</strong>. Can somebody help me with this? Is it possible to change size of the icon without interrupting <code>Text</code> centering? Or is there a way to center it as needed? Thank you.</p>
[ { "answer_id": 74408428, "author": "hayden.mumm", "author_id": 13270701, "author_profile": "https://Stackoverflow.com/users/13270701", "pm_score": 2, "selected": false, "text": "String[] splitWithoutLimit = \"Column1,Column2,Column3\".split(\",\")\n\n// splitWithoutLimit will contain the following values:\n// { \"Column1\", \"Column2\", \"Column3\" }\n\nString[] splitWithLimit = \"Column1,Column2,Column3\".split(\",\", 2)\n\n// splitWithLimit will contain the following values:\n// { \"Column1\", \"Column2,Column3\" }\n" }, { "answer_id": 74410133, "author": "BccHnw", "author_id": 14754410, "author_profile": "https://Stackoverflow.com/users/14754410", "pm_score": 1, "selected": true, "text": "\"0\"" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1619036/" ]
74,407,603
<p>We have a system take takes a JSON array as a parameter to define matching records. To keep things simple, we have a query:</p> <pre><code>SELECT ai.ID FROM association_internal ai WHERE ai.source_object_record_id MEMBER OF('[57928,57927]'); </code></pre> <p>Now the above call takes 380ms, which is ridiculous. Why? Because the below version of the exact same call takes 11ms.</p> <pre><code>SELECT ai.ID FROM association_internal ai WHERE ai.source_object_record_id IN(57928,57927); </code></pre> <p>Just by using IN vs. MEMBER OF, it works fine. MEMBER OF is so slow, it's (honestly) unusable in an enterprise setting. The speed degrades the more numbers we have (and we can have 100+ in the above example).</p> <p>Obviously there's some crazy slow processing of MEMBER OF (perhaps it's even avoiding indexing?) but we cannot pass a JSON array as a property of IN. Now I COULD write dynamic SQL and execute that manually, but that's ugly and sloppy.</p> <p>So the question is this - is there a way to pass a JSON array for use in a hardcoded query that doesn't use MEMBER OF? Something that'll be just as fast as hardcoding the IN values? Or a way to convert a JSON array of values into a useable IN or EXISTS use case?</p>
[ { "answer_id": 74408428, "author": "hayden.mumm", "author_id": 13270701, "author_profile": "https://Stackoverflow.com/users/13270701", "pm_score": 2, "selected": false, "text": "String[] splitWithoutLimit = \"Column1,Column2,Column3\".split(\",\")\n\n// splitWithoutLimit will contain the following values:\n// { \"Column1\", \"Column2\", \"Column3\" }\n\nString[] splitWithLimit = \"Column1,Column2,Column3\".split(\",\", 2)\n\n// splitWithLimit will contain the following values:\n// { \"Column1\", \"Column2,Column3\" }\n" }, { "answer_id": 74410133, "author": "BccHnw", "author_id": 14754410, "author_profile": "https://Stackoverflow.com/users/14754410", "pm_score": 1, "selected": true, "text": "\"0\"" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1857894/" ]
74,407,615
<p>I'm having this error when I try running the app with &quot;npm run android&quot;. Everything was working perfectly until this happened. Here's the build log:</p> <p>`</p> <pre><code>&gt; DriverApp@0.0.1 android &gt; react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using &quot;--no-jetifier&quot; flag. Jetifier found 1256 file(s) to forward-jetify. Using 8 workers... info JS server already running. info Installing the app... &gt; Task :amazon-cognito-identity-js:javaPreCompileDebug FAILED Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings 8 actionable tasks: 8 executed FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':amazon-cognito-identity-js:javaPreCompileDebug'. &gt; Could not resolve all files for configuration ':amazon-cognito-identity-js:debugCompileClasspath'. &gt; Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-classes, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-api}. &gt; Execution failed for JetifyTransform: C:\Users\x\.gradle\caches\modules-2\files-2.1\com.facebook.react\react-native\0.71.0-rc.0\x\react-native-0.71.0-rc.0-debug.aar. &gt; Java heap space * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 14s error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 </code></pre> <p>`</p> <p>And here's my package.json file:</p> <pre><code>{ &quot;dependencies&quot;: { &quot;@react-native-community/geolocation&quot;: &quot;^2.0.2&quot;, &quot;@react-native-community/masked-view&quot;: &quot;^0.1.10&quot;, &quot;@react-native-community/netinfo&quot;: &quot;^5.9.10&quot;, &quot;@react-native-community/slider&quot;: &quot;^4.2.3&quot;, &quot;@react-native-picker/picker&quot;: &quot;^2.4.1&quot;, &quot;@react-navigation/drawer&quot;: &quot;^5.12.3&quot;, &quot;@react-navigation/native&quot;: &quot;^5.9.2&quot;, &quot;@react-navigation/stack&quot;: &quot;^5.14.2&quot;, &quot;amazon-cognito-identity-js&quot;: &quot;^4.5.10&quot;, &quot;aws-amplify&quot;: &quot;^3.3.18&quot;, &quot;aws-amplify-react-native&quot;: &quot;^4.3.1&quot;, &quot;react&quot;: &quot;16.13.1&quot;, &quot;react-native&quot;: &quot;0.63.4&quot;, &quot;react-native-camera&quot;: &quot;^4.2.1&quot;, &quot;react-native-geolocation-service&quot;: &quot;^5.3.0-beta.4&quot;, &quot;react-native-gesture-handler&quot;: &quot;^1.9.0&quot;, &quot;react-native-google-places-autocomplete&quot;: &quot;^2.1.2&quot;, &quot;react-native-image-picker&quot;: &quot;^4.10.0&quot;, &quot;react-native-maps&quot;: &quot;0.27.1&quot;, &quot;react-native-maps-directions&quot;: &quot;^1.8.0&quot;, &quot;react-native-material-cards&quot;: &quot;^1.0.16&quot;, &quot;react-native-reanimated&quot;: &quot;^1.13.2&quot;, &quot;react-native-safe-area-context&quot;: &quot;^3.1.9&quot;, &quot;react-native-screens&quot;: &quot;^2.17.1&quot;, &quot;react-native-vector-icons&quot;: &quot;^7.1.0&quot;, &quot;rn-qr-generator&quot;: &quot;^1.2.0&quot; }, &quot;devDependencies&quot;: { &quot;@babel/core&quot;: &quot;^7.8.4&quot;, &quot;@babel/runtime&quot;: &quot;^7.8.4&quot;, &quot;@react-native-community/eslint-config&quot;: &quot;^1.1.0&quot;, &quot;@types/react-native&quot;: &quot;~0.67.6&quot;, &quot;babel-jest&quot;: &quot;^25.1.0&quot;, &quot;eslint&quot;: &quot;^6.5.1&quot;, &quot;jest&quot;: &quot;^28.1.3&quot;, &quot;metro-react-native-babel-preset&quot;: &quot;^0.59.0&quot;, &quot;react-test-renderer&quot;: &quot;16.13.1&quot; }, } </code></pre> <p>I just tried to build my react native app as usual but it won't build due to this problem which I think is coming from AWS Cognito dose anyone had the same issue and managed to solve it, please?</p>
[ { "answer_id": 74582534, "author": "sabrim", "author_id": 13347859, "author_profile": "https://Stackoverflow.com/users/13347859", "pm_score": 1, "selected": true, "text": "buildscript {\n // ...\n}\n\n\nallprojects {\n repositories {\n exclusiveContent {\n filter {\n includeGroup \"com.facebook.react\"\n }\n forRepository {\n maven {\n url \"$rootDir/../node_modules/react-native/android\"\n }\n }\n }\n // ...\n }\n}\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13347859/" ]
74,407,626
<p>I have tried several times to code that will display text for an hour, after the functions has occurred.</p> <p>But the function <em>Date</em> exist on a time period of day, hour, minute, I just want to display the text for one hour.</p> <pre><code> Fucntion() { var Text = &quot;Show for an hour and will disappear after an hour.&quot;; } </code></pre> <p><strong>EDIT (1):</strong></p> <p>To put it simply if the user click on function called get contents in json for an hour, it appears on the site for all users, on each click of the function the data from json is called and displayed for an hour.</p> <pre><code>funtion click() { var url = &quot;https://example.com&quot;; var xhr = new XMLHttpRequest(); xhr.open(&quot;GET&quot;, url); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { console.log(xhr.status); console.log(xhr.responseText); }}; xhr.send(); var Text = xhr.responseText; setTimeout(Text, 1000); } </code></pre>
[ { "answer_id": 74407763, "author": "Carsten Massmann", "author_id": 2610061, "author_profile": "https://Stackoverflow.com/users/2610061", "pm_score": 2, "selected": false, "text": "setTimeout()" }, { "answer_id": 74415561, "author": "Alexey Zalyotov", "author_id": 11750723, "author_profile": "https://Stackoverflow.com/users/11750723", "pm_score": 1, "selected": false, "text": "countdown" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18464210/" ]
74,407,649
<p>I'm trying to build iOS Flutter app. It throwns me this error:</p> <p><a href="https://pastebin.com/NG6EWWcj" rel="nofollow noreferrer">https://pastebin.com/NG6EWWcj</a></p> <p><code>Error running pod install</code></p>
[ { "answer_id": 74407763, "author": "Carsten Massmann", "author_id": 2610061, "author_profile": "https://Stackoverflow.com/users/2610061", "pm_score": 2, "selected": false, "text": "setTimeout()" }, { "answer_id": 74415561, "author": "Alexey Zalyotov", "author_id": 11750723, "author_profile": "https://Stackoverflow.com/users/11750723", "pm_score": 1, "selected": false, "text": "countdown" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19290739/" ]
74,407,681
<p>I'm aware of mutable parameter behavior. Why the list is not set up to None when I send and unpack **dictionary as argument? The common_header.png repeads, it means is stored in list. That is weird to me and I couldn't find answer for the question... I'm learning, happy to hear any other suggestions to code, thank you</p> <pre><code>def print_user_profile(gender='female', first='Jane', last='Doe=', pictures = None): if pictures is None: pictures = [] gender_options = ('male', 'female') if gender not in gender_options: return 'Gender not correct' elif gender == 'male' and first == 'Jane': first = 'John' pictures.insert(0, 'common_header.png') print(f'The user {first} {last} has the following pictures:') for i in pictures: print(i) </code></pre> <pre><code>test_data1 = { &quot;gender&quot;: &quot;male&quot;, &quot;last&quot;: &quot;Brown&quot;, &quot;pictures&quot;: [&quot;holidays1.png&quot;, &quot;easter_grandma.png&quot;] } print_user_profile(gender='male', last='Brown', pictures=[&quot;holidays1.png&quot;, &quot;easter_grandma.png&quot;]) print_user_profile(gender='male', last='Brown', pictures=[&quot;holidays1.png&quot;, &quot;easter_grandma.png&quot;]) print_user_profile(gender='male', last='Brown', pictures=[&quot;holidays1.png&quot;, &quot;easter_grandma.png&quot;]) print_user_profile(**test_data1) print_user_profile(**test_data1) print_user_profile(**test_data1) </code></pre> <pre><code> The user John Brown has the following pictures: common_header.png holidays1.png easter_grandma.png The user John Brown has the following pictures: common_header.png holidays1.png easter_grandma.png The user John Brown has the following pictures: common_header.png holidays1.png easter_grandma.png The user John Brown has the following pictures: common_header.png holidays1.png easter_grandma.png The user John Brown has the following pictures: common_header.png common_header.png holidays1.png easter_grandma.png The user John Brown has the following pictures: common_header.png common_header.png common_header.png holidays1.png easter_grandma.png </code></pre> <p>There is no problem if I send the same arguments separately.</p>
[ { "answer_id": 74407790, "author": "Bill Lynch", "author_id": 47453, "author_profile": "https://Stackoverflow.com/users/47453", "pm_score": 2, "selected": false, "text": "pictures = [\"holidays1.png\", \"easter_grandma.png\"]\n\ntest_data1 = {\n \"gender\": \"male\",\n \"last\": \"Brown\",\n \"pictures\": pictures\n}\n\nprint_user_profile(gender='male', last='Brown', pictures=pictures) \nprint_user_profile(gender='male', last='Brown', pictures=pictures) \nprint_user_profile(gender='male', last='Brown', pictures=pictures) \nprint_user_profile(**test_data1) \nprint_user_profile(**test_data1) \nprint_user_profile(**test_data1)\n" }, { "answer_id": 74407799, "author": "Dr. V", "author_id": 7078614, "author_profile": "https://Stackoverflow.com/users/7078614", "pm_score": 2, "selected": true, "text": "pictures = [] if pictures is None else list(pictures)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480956/" ]
74,407,700
<p>I have a structure:</p> <pre class="lang-c prettyprint-override"><code>struct Path{ int8_t maxtopy; }; </code></pre> <p>And I want to create an array of pointers to structure <code>Path</code>. I've tried something like that:</p> <pre class="lang-c prettyprint-override"><code>int main(){ struct Path *paths[NUMBER_OF_PATHS]; init_paths(paths); } </code></pre> <pre class="lang-c prettyprint-override"><code>void init_paths(struct Path **paths){ paths[0]-&gt;maxtopy = -1; for(int i = 1; i &lt; NUMBER_OF_PATHS; i++) paths[i]-&gt;maxtopy = -1; } </code></pre> <p>It is not going to work. Value to the first path is assigned correctly. But when <code>for</code> loop starts I am gettting <strong>Segmentation fault</strong>. I already figured out that when I am creating array of pointers, only the first pointer is going to be assigned to some structure. So I cannot e.g. <code>paths[1]-&gt;maxtopy = -1;</code>, because <code>paths[1]</code> doesn't point to any existing structure.</p> <p>I have tried something like this:</p> <pre class="lang-c prettyprint-override"><code>for(int i = 1; i &lt; NUMBER_OF_PATHS; i++){ static struct Path a; paths[i] = &amp;a; paths[i]-&gt;maxtopy = i; } </code></pre> <p>It doesn't work because it initialize <code>a</code> only once. So every pointer in <code>paths</code> array points to the same structure.</p> <p>My question is: <strong>How to create an array of pointers that point to initialized structures?</strong></p>
[ { "answer_id": 74407893, "author": "Chris", "author_id": 15261315, "author_profile": "https://Stackoverflow.com/users/15261315", "pm_score": 2, "selected": true, "text": "malloc" }, { "answer_id": 74407896, "author": "shy45", "author_id": 20313707, "author_profile": "https://Stackoverflow.com/users/20313707", "pm_score": -1, "selected": false, "text": "const int NUMBER_OF_PATHS = 10;\n\nstruct Path {\n int8_t maxtopy;\n};\n\nvoid init_paths(struct Path** paths) {\n for (int i = 0; i < NUMBER_OF_PATHS; i++) {\n paths[i] = (Path*)malloc(sizeof(Path));\n paths[i]->maxtopy = i;\n }\n}\n\nint main() {\n struct Path* paths[NUMBER_OF_PATHS];\n\n init_paths(paths);\n\n for (auto i : paths) {\n printf(\"%d\\n\", i->maxtopy);\n }\n}\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407700", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14340849/" ]
74,407,701
<p>I'm need to declare incomplete type (may it be <code>siginfo_t</code>) in header, and in source import some system header (<code>sys/signal.h</code>), that defines that type.</p> <p>So, here is the problem:</p> <pre class="lang-cpp prettyprint-override"><code>// a.h struct siginfo_t; void foo(siginfo_t*); </code></pre> <pre class="lang-cpp prettyprint-override"><code>// a.cpp #include &quot;a.h&quot; #include &lt;signal.h&gt; void foo(siginfo_t* x) { /* implementation */ }; </code></pre> <p>But in signal.h it is defined like:</p> <pre><code>typedef struct siginfo_t { /* */ } siginfo_t; </code></pre> <p>Compiler error: <code>error: typedef redefinition with different types ('struct siginfo_t' vs 'siginfo_t')</code>.</p> <p>How to achieve no errors there? Thanks!</p>
[ { "answer_id": 74407793, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 3, "selected": false, "text": "<sys/siginfo.h>" }, { "answer_id": 74407959, "author": "Саша Новожилов", "author_id": 6872226, "author_profile": "https://Stackoverflow.com/users/6872226", "pm_score": -1, "selected": false, "text": "// a.h\n#pragma once\nextern \"C\" {\n struct siginfo;\n}\nvoid foo(siginfo*);\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6872226/" ]
74,407,705
<p>I spent 1 week trying to upgrade Magento from version 2.2 to 2.4. In order to proceed I have downloaded and I am using composer 1. My PHP version is 7.1 - Perfectly compatible with Magento 2.2. With composer 1 I was able to get a &quot;composer require&quot; without errors. I then launched the &quot;composer update&quot; command but it goes into error due to the lack of php 7.4 or higher.</p> <p>Now: I could also update the php and finish the &quot;composer update&quot; but then the &quot;magento/upgrade&quot; will not work because it is the one of Magento 2.2 which only works with php 7.1</p> <p>Do you have solutions?</p> <p>I am aspects to upgrade Magento</p>
[ { "answer_id": 74407793, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 3, "selected": false, "text": "<sys/siginfo.h>" }, { "answer_id": 74407959, "author": "Саша Новожилов", "author_id": 6872226, "author_profile": "https://Stackoverflow.com/users/6872226", "pm_score": -1, "selected": false, "text": "// a.h\n#pragma once\nextern \"C\" {\n struct siginfo;\n}\nvoid foo(siginfo*);\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10588235/" ]
74,407,709
<p>This is in discord.js. So I have three items each with a unique price (more items in the future).. Sending the name of the item for example &quot;Item 1&quot; should reply the price. How do I use the price variable in my code? I was thinking associative array but I think there's no associate array in JS.</p> <ol> <li>Item 1 = 100</li> <li>Item 2 = 300</li> <li>Item 3 = 500</li> </ol> <p>I have this code:</p> <pre><code>const items = [&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;]; const price = [100, 300, 500]; for (var i=0; i &lt; items.length; i++) { if (message.content === items[i]) { message.reply(PostPrice); } } </code></pre>
[ { "answer_id": 74408452, "author": "Josiah", "author_id": 20463298, "author_profile": "https://Stackoverflow.com/users/20463298", "pm_score": 3, "selected": true, "text": "Map" }, { "answer_id": 74408671, "author": "Root", "author_id": 16908554, "author_profile": "https://Stackoverflow.com/users/16908554", "pm_score": 1, "selected": false, "text": "const items = {\"item 1\": { price: 100 }, \"item 1\": { price: 300 }, \"item 1\": { price: 500 }}\n\nif(items[message.content.toLowerCase()) {\nmessage.reply(\"price: \"+items[message.content.toLowerCase()][\"price\"])\n} else {\nmessage.reply(\"item doesnt exist\")\n}\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/874737/" ]
74,407,724
<p>I have a sales data for a couple of years in an array: var= ['Jan-2019',325678], ['feb-2019', 456789], ['Mar-2019',-12890],.....['Dec-2021', 987460]</p> <p>1 -want to calculate the net total amount of profit/losses over the entire period. 2- Average of the (changes) in profit/losses over the entire period - track the total change in profits from month to month and find the average(total/number of months) 3 - greatest increase in profit (month and amount)over the whole period 4 - greatest decrease3in profit (month and amount)over the whole period</p> <p>Tried to solve number 1 using : `</p> <pre><code>const profitMonths = data.filter(el =&gt; el[1] &gt; 0); console.log(&quot;Total:&quot;, profitMonths.map(el =&gt; el[1]).reduce((a, b) =&gt; a + b)); console.log; </code></pre> <p>` but the sum I am getting is different from what excel and calculator is giving me. I will appreciate some help here</p>
[ { "answer_id": 74408452, "author": "Josiah", "author_id": 20463298, "author_profile": "https://Stackoverflow.com/users/20463298", "pm_score": 3, "selected": true, "text": "Map" }, { "answer_id": 74408671, "author": "Root", "author_id": 16908554, "author_profile": "https://Stackoverflow.com/users/16908554", "pm_score": 1, "selected": false, "text": "const items = {\"item 1\": { price: 100 }, \"item 1\": { price: 300 }, \"item 1\": { price: 500 }}\n\nif(items[message.content.toLowerCase()) {\nmessage.reply(\"price: \"+items[message.content.toLowerCase()][\"price\"])\n} else {\nmessage.reply(\"item doesnt exist\")\n}\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20300644/" ]
74,407,738
<p>Why I continue getting the error :</p> <blockquote> <p>missing 1 required positional argument: 'category_id'</p> </blockquote> <p>when the argument is already passed within query function in <code>Backend</code> class? I also don't understand the error of unfilled <code>self</code> or missing positional argument <code>self</code>:</p> <blockquote> <p>missing 1 required positional argument: 'self'</p> </blockquote> <p>I tried passing <code>self</code> to <code>display_account_types()</code> in <code>Frontend</code> class but it doesn't reflect. Do I need to pass <code>self</code> within the inner nested functions within a class?</p> <pre><code>import tkinter from tkinter import * from tkinter import ttk import tkinter.messagebox import sqlite3 root =Tk() root.title('Simple Application') root.config(bg='SlateGrey') root.geometry(&quot;&quot;) # BackEnd class Backend(): def __init__(self): self.conn = sqlite3.connect('accounting.db') self.cur = self.conn.cursor() self.conn.execute(&quot;&quot;&quot;CREATE TABLE IF NOT EXISTS account_type( id INTEGER PRIMARY KEY, category_type INTEGER NOT NULL, category_id TEXT NOT NULL )&quot;&quot;&quot;), self.conn.commit() self.conn.close() def insert_account_type(self, category_type, category_id): self.conn = sqlite3.connect('accounting.db') self.cur = self.conn.cursor() self.cur.execute(&quot;&quot;&quot;INSERT INTO account_type(category_id, category_type) VALUES(?,?);&quot;&quot;&quot;, (self,category_type, category_id,)) self.conn.commit() self.conn.close() def view_account_type(self): self.conn = sqlite3.connect('accounting.db') self.cur = self.conn.cursor() self.cur.execute(&quot;SELECT * FROM account_type&quot;) self.rows = self.cur.fetchall() self.conn.close() return self.rows # calling the class tb = Backend() # Front End class Frontend(): def __init__(self, master): # Frames self.top_frame = LabelFrame(master,bg ='SlateGrey', relief=SUNKEN) self.top_frame.pack() self.bottom_frame = LabelFrame(master, bg = 'SlateGrey', relief=SUNKEN) self.bottom_frame.pack() self.right_frame = LabelFrame(self.top_frame, bg = 'SlateGrey', relief = FLAT, text = 'Details Entry',fg = 'maroon') self.right_frame.pack(side = RIGHT, anchor = NE) self.side_frame = LabelFrame(self.top_frame,bg ='SlateGrey',relief=SUNKEN,text = 'Menu Buttons',fg = 'maroon') self.side_frame.pack(side = LEFT,anchor = NW) self.bot_frame = LabelFrame(self.bottom_frame, bg='Grey',relief = SUNKEN,text = 'Field View',fg = 'maroon') self.bot_frame.pack(side = BOTTOM,anchor = SW) # Side Buttons self.btn1 = Button(self.side_frame, text='Main Account Types', bg='SteelBlue4', font=('cambria', 11), anchor=W, fg='white', width=18,height=2, command=lambda :[self.main_account()]) self.btn1.grid(row=0, column=0, pady=0, sticky=W) def main_account(self): # variables self.category_type = StringVar() self.category_id = StringVar() # functions def add_main_accounts(): if self.category_type.get() == &quot;&quot; or self.category_id.get() == &quot;&quot;: tkinter.messagebox.showinfo('All fields are required') else: Backend.insert_account_type( self.category_type.get(), self.category_id.get(),) # category type unfilled tkinter.messagebox.showinfo('Entry successful') def display_account_types(self): self.trv.delete(*self.trv.get_children()) for self.rows in Backend.view_account_type(self): self.trv.insert(&quot;&quot;, END, values=self.rows) def get_account_type(e): self.selected_row = self.trv.focus() self.data = self.trv.item(self.selected_row) global row row = self.data[&quot;values&quot;] &quot;&quot;&quot;Grab items and send them to entry fields&quot;&quot;&quot; self.category_id.set(row[1]) self.category_type.set(row[2]) &quot;&quot;&quot;=================TreeView===============&quot;&quot;&quot; # Scrollbars ttk.Style().configure(&quot;Treeview&quot;, background = &quot;SlateGrey&quot;, foreground = &quot;white&quot;, fieldbackground = &quot;grey&quot;) scroll_x = Scrollbar(self.bot_frame, orient = HORIZONTAL) scroll_x.pack(side = BOTTOM, fill = X) scroll_y = Scrollbar(self.bot_frame, orient = VERTICAL) scroll_y.pack(side = RIGHT, fill = Y) # Treeview columns &amp; setting scrollbars self.trv = ttk.Treeview(self.bot_frame, height=3, columns= ('id', 'category_id', 'category_type'), xscrollcommand = scroll_x.set, yscrollcommand = scroll_y.set) # Treeview style configuration ttk.Style().configure(&quot;Treeview&quot;, background = &quot;SlateGrey&quot;, foreground = &quot;white&quot;, fieldbackground = &quot;grey&quot;) # Configure vertical and Horizontal scroll scroll_x.config(command = self.trv.xview) scroll_y.config(command = self.trv.yview) # Treeview Headings/columns self.trv.heading('id', text = &quot;No.&quot;) self.trv.heading('category_id', text = 'Category ID') self.trv.heading('category_type', text = 'Category Type') self.trv['show'] = 'headings' # Treeview columns width self.trv.column('id', width = 23) self.trv.column('category_id', width = 70) self.trv.column('category_type', width = 100) self.trv.pack(fill = BOTH, expand = YES) # Binding Treeview with data self.trv.bind('&lt;ButtonRelease-1&gt;',get_account_type) # Account Types Labels self.lbl1 = Label(self.right_frame,text = 'Category ID',anchor = W, width=10,font = ('cambria',11,),bg = 'SlateGrey') self.lbl1.grid(row = 0,column = 0,pady = 5) self.lbl2 = Label(self.right_frame, text = 'Category Type', anchor = W, width = 10,font = ('cambria',11,),bg = 'SlateGrey') self.lbl2.grid(row = 1, column = 0,pady = 5,padx=5) self.blank_label = Label(self.right_frame, bg='SlateGrey') self.blank_label.grid(row=2, columnspan=2, pady=10) # Account Type Entries self.entry1 = Entry(self.right_frame,textvariable = self.category_id, font = ('cambria',11,),bg = 'Grey',width=14) self.entry1.grid(row = 0,column=1,sticky = W,padx = 5) self.entry2 = Entry(self.right_frame, textvariable = self.category_type, font = ('cambria', 11,), bg = 'Grey',width = 14) self.entry2.grid(row = 1, column = 1, sticky = W,pady = 5,padx = 5) # Buttons self.btn_1 = Button(self.right_frame,text = 'Add',font = ('cambria',12,'bold'),bg = 'SlateGrey', activebackground='green', fg = 'white',width=12,height = 2,relief=RIDGE, command = lambda :[add_main_accounts()]) self.btn_1.grid(row = 3,column = 0,pady = 15) self.btn_2 = Button(self.right_frame, text = 'View', font = ('cambria', 12, 'bold'), bg = 'SlateGrey',command=lambda :[display_account_types()], activebackground='green', fg ='white', width=12, height = 2, relief = RIDGE) self.btn_2.grid(row = 3, column = 1) # calling the class app = Frontend(root) root.mainloop() </code></pre>
[ { "answer_id": 74408452, "author": "Josiah", "author_id": 20463298, "author_profile": "https://Stackoverflow.com/users/20463298", "pm_score": 3, "selected": true, "text": "Map" }, { "answer_id": 74408671, "author": "Root", "author_id": 16908554, "author_profile": "https://Stackoverflow.com/users/16908554", "pm_score": 1, "selected": false, "text": "const items = {\"item 1\": { price: 100 }, \"item 1\": { price: 300 }, \"item 1\": { price: 500 }}\n\nif(items[message.content.toLowerCase()) {\nmessage.reply(\"price: \"+items[message.content.toLowerCase()][\"price\"])\n} else {\nmessage.reply(\"item doesnt exist\")\n}\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18666779/" ]
74,407,755
<p>I have an array in my python program called ageArray. It contains the same attribute from each object in a group. Here's the intitialisation code:</p> <pre><code>ageArray = [[amoeba.age] for amoeba in amoebas] </code></pre> <p>Because the I want the attribute to change, I intitialise it at the start of a while statement. After this I have the following two lines of code:</p> <pre><code>for amoeba in amoebas: amoeba.age = amoeba.age + 1 </code></pre> <p>This is intended to add 1 to each age attribute, which will then be copied over to the ageArray the next time the while loop is iterated.</p> <p>The use for this array is to add an extra requirement when two of the amoeba(objects) collide, as well as checking their x and y coords, I use this:</p> <pre><code>if ageArray[i] &gt;= 10 and ageArray[h] &lt;= 10: </code></pre> <p>This code is intended to make sure that the ages of the amoebae are more than 10 (the reason for this is complex and so I won't explain). For some reason this piece of code is throwing up this error:</p> <blockquote> <pre><code>TypeError: '&gt;' not supported between instances of 'list' and 'int'. </code></pre> </blockquote> <p>Furthermore, is my code for adding 1 to each amoeba.age attribute correct? Tried using lambda with agearray but couldn't get it to work.</p>
[ { "answer_id": 74407801, "author": "Rabbid76", "author_id": 5577765, "author_profile": "https://Stackoverflow.com/users/5577765", "pm_score": 3, "selected": true, "text": "[amoeba.age]" }, { "answer_id": 74407845, "author": "nomans_", "author_id": 19569601, "author_profile": "https://Stackoverflow.com/users/19569601", "pm_score": 1, "selected": false, "text": "ageArray = [amoeba.age for amoeba in amoebas]\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11454595/" ]
74,407,770
<p>I have a data frame that has a column with the following values:</p> <pre><code>time = [5.0, 504.0, 847.0, 11.0, 1247.0] </code></pre> <p>I want to convert to a time in the <code>%H%M</code> format.</p> <p>I tried using <code>to_datetime</code> but had error codes based on <code>5.0</code> entries.</p>
[ { "answer_id": 74407801, "author": "Rabbid76", "author_id": 5577765, "author_profile": "https://Stackoverflow.com/users/5577765", "pm_score": 3, "selected": true, "text": "[amoeba.age]" }, { "answer_id": 74407845, "author": "nomans_", "author_id": 19569601, "author_profile": "https://Stackoverflow.com/users/19569601", "pm_score": 1, "selected": false, "text": "ageArray = [amoeba.age for amoeba in amoebas]\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14067573/" ]
74,407,782
<pre><code>import urllib.request import json from collections import Counter def count_coauthors(author_id): coauthors_dict = {} url_str = ('https://api.semanticscholar.org/graph/v1/author/47490276?fields=name,papers.authors') respons = urllib.request.urlopen(url_str) text = respons.read().decode() for line in respons: print(line.decode().rstip()) data = json.loads(text) print(type(data)) print(list(data.keys())) print(data[&quot;name&quot;]) print(data[&quot;authorId&quot;]) name = [] for lines in data[&quot;papers&quot;]: for authors in lines[&quot;authors&quot;]: name.append(authors.get(&quot;name&quot;)) print(name) count = dict() names = name for i in names: if i not in count: count[i] = 1 else: count[i] += 1 print(count) c = Counter(count) top = c.most_common(10) print(top) return coauthors_dict author_id = '47490276' cc = count_coauthors(author_id) top_coauthors = sorted(cc.items(), key=lambda item: item[1], reverse=True) for co_author in top_coauthors[:10]: print(co_author) </code></pre> <p>This is how my code looks this far, there are no error. I need to get rid of the rest of the text when I run it, so it should look like this:</p> <pre><code>('Diego Calvanese', 47) ('D. Lanti', 28) ('Martín Rezk', 21) ('Elem Güzel Kalayci', 18) ('B. Cogrel', 17) ('E. Botoeva', 16) ('E. Kharlamov', 16) ('I. Horrocks', 12) ('S. Brandt', 11) ('V. Ryzhikov', 11) </code></pre> <p>I have tried using rstrip and split on my 'c' variable but it doesn't work. Im only allowed importing what I already have imported and must use the link which is included.</p> <p>Tips on simplifying or bettering the code is also appreciated!</p> <p>(&quot;Extend the program below so that it prints the names of the top-10 coauthors together with the numbers of the coauthored publications&quot;)</p>
[ { "answer_id": 74407801, "author": "Rabbid76", "author_id": 5577765, "author_profile": "https://Stackoverflow.com/users/5577765", "pm_score": 3, "selected": true, "text": "[amoeba.age]" }, { "answer_id": 74407845, "author": "nomans_", "author_id": 19569601, "author_profile": "https://Stackoverflow.com/users/19569601", "pm_score": 1, "selected": false, "text": "ageArray = [amoeba.age for amoeba in amoebas]\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399033/" ]
74,407,786
<p>I have a big directory structure with lots of binary files (images) in it. I want to track which files were added/deleted/changed without actually storing the changes. Is it possible to do using git?</p> <p>Just to reiterate, I don't care about the contents of the change, just want to register the fact that the file was added/deleted/changed.</p> <p>Open to other suggestions besides git that work across Windows/Linux/macOS.</p>
[ { "answer_id": 74416938, "author": "GreenOak", "author_id": 9834089, "author_profile": "https://Stackoverflow.com/users/9834089", "pm_score": 2, "selected": true, "text": " *\n !.gitignore\n !ls.txt\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9834089/" ]
74,407,789
<p>I am looking for a way to extract images from within another image. For example: <a href="https://i.stack.imgur.com/k5s8H.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k5s8H.jpg" alt="enter image description here" /></a></p> <p>Here is a picture taken of a paper. It includes text, an image of a camera, and an image of a qr code. Is there an API that can possibly extract those two(camera and qr code) from this larger image and separate them into their own individual images. I know this is doable with the text(OCR), but I need to find some way to do Image Recognition if that even exists. For now, I cant find any reference to doing this besides extracting images from pdf's, which none of those softwares have the capability to extract them from a non-perfect pdf.</p> <p>Price for the API(node.js prefered, but i can adapt to use any language) is not a big concern, I'm just not sure this is even possible to due without programming a legitable artificial intelligence using machine learning, which I would no doubt cause a global internet shutdown from breaking everything if I attempted to do so.</p> <p>Anyway, any suggestions would be great and much appreciated. Thanks!</p> <p>EDIT: the images aren't always those, it can be an image of anything, from potatoes to flags</p>
[ { "answer_id": 74416938, "author": "GreenOak", "author_id": 9834089, "author_profile": "https://Stackoverflow.com/users/9834089", "pm_score": 2, "selected": true, "text": " *\n !.gitignore\n !ls.txt\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19553518/" ]
74,407,821
<p>I have a two dimensional array of students from different schools and countries. I want them to be grouped by name of school and country.</p> <p>How can I create the nested key structure?</p> <p>Example:</p> <pre><code>$students = [ [ &quot;country&quot; =&gt; &quot;japan&quot;, &quot;school&quot; =&gt; &quot;kyoto university&quot;, &quot;name&quot; =&gt; &quot;Naruto Uzumaki&quot; ], [ &quot;country&quot; =&gt; &quot;usa&quot;, &quot;school&quot; =&gt; &quot;harvard university&quot;, &quot;name&quot; =&gt; &quot;Naruto Uzumaki&quot; ], [ &quot;country&quot; =&gt; &quot;japan&quot;, &quot;school&quot; =&gt; &quot;tokyo university&quot;, &quot;name&quot; =&gt; &quot;sasuke Uchiha&quot; ], [ &quot;country&quot; =&gt; &quot;japan&quot;, &quot;school&quot; =&gt; &quot;tokyo university&quot;, &quot;name&quot; =&gt; &quot;kakashi hatake&quot; ], ]; </code></pre> <p>Desired result:</p> <pre><code>[ “japan” =&gt; [ “kyoto university” =&gt; [ [ “country” =&gt; “japan”, “school” =&gt; “kyoto university”, “name” =&gt; “Naruto Uzumaki” ], ], “tokyo university” =&gt; [ [ “country” =&gt; “japan”, “school” =&gt; “tokyo university”, “name” =&gt; “sasuke Uchiha” ], [ “country” =&gt; “japan”, “school” =&gt; “tokyo university”, “name” =&gt; “kakashi hatake” ], ], ], “usa” =&gt; [ “harvard university” =&gt; [ [ “country” =&gt; “usa”, “school” =&gt; “harvard university”, “name” =&gt; “Naruto Uzumaki” ], ] ] ] </code></pre>
[ { "answer_id": 74416938, "author": "GreenOak", "author_id": 9834089, "author_profile": "https://Stackoverflow.com/users/9834089", "pm_score": 2, "selected": true, "text": " *\n !.gitignore\n !ls.txt\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15180008/" ]
74,407,834
<p>Lets say I have a function like below that gets called by a button click in my component.</p> <ol> <li>What happens if I click my button twice to the first and second subscriptions?</li> <li>What happens if I click my button twice and then unsubscribe <code>mySub</code> in my ngOnDestroy()?</li> <li>If the function has potential to be called twice, should I add logic in <code>myFunction()</code> to unsubscribe from my first subscription before subscribing again?</li> </ol> <pre><code>mySub: Subscription; myFunction(){ this.mySub = this.myService.getSomeData(this.data).subscribe({ next: (val) =&gt; { //stuff }, error: (e) =&gt; { //more stuff } }); } </code></pre> <p>I'm thinking that if there's potential for a subscription to be executed twice then I should unsubscribe before making another subscription.</p>
[ { "answer_id": 74407987, "author": "AlanObject", "author_id": 527470, "author_profile": "https://Stackoverflow.com/users/527470", "pm_score": 1, "selected": false, "text": "this.myService.getSomeData" }, { "answer_id": 74408045, "author": "Tanner", "author_id": 7375929, "author_profile": "https://Stackoverflow.com/users/7375929", "pm_score": 2, "selected": false, "text": "mySub" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20325103/" ]
74,407,882
<p><strong>Problem</strong></p> <p>I want to unit test a method in my repository class that checks if a record should be updated or created new. How do I test the main function without actually having the unit test attempt to insert or query the db?</p> <p><strong>Code</strong></p> <p>I have the following repository class:</p> <pre><code> public class WidgetRepository() { public bool InsertOrUpdateWidget(Widget widgetToEval) { var retval = false; var existingRecord = FindExistingWidget(widgetToEval); if (existingRecord == null) { retval = InsertNewWidget(widgetToEval); } else { retval = UpdateExistingWidget(widgetToEval, existingRecord); } return retval; } </code></pre> <p><strong>Unit Test</strong></p> <pre><code> [Fact] public void Insert_New_Widget() { var repo = GetEmptyRepository(); var newWidget = new Widget() { ID = 1, Name= &quot;test&quot;, Description= &quot;Test widget&quot;, }; var result = repo.InsertOrUpdateWidget(newWidget); Assert.True(result); } private IWidgetRepository GetEmptyRepository() { var repo = new Mock&lt;IWidgetRepository &gt;(); repo.Setup(s =&gt; s.FindExistingWidget(It.IsAny&lt;Widget&gt;())).Returns((Widget)null); repo.Setup(s =&gt; s.InsertNewWidget(It.IsAny&lt;Widget&gt;())).Returns(true); return repo.Object; } </code></pre> <p>In the unit test, I'm trying to mock the FindExistingWidget method and have it return a null object. I've also mocked the insert function and have it return a true. When I run this test, instead of returning a true, it returns false.</p> <p>Edit 1</p> <p>So I understand that I shouldn't mock the repo... I should just create an object of this type because I should only mock things my code needs / dependencies. But I guess the question is then how do i prevent the code from actually attempting to connect to the db when it runs the FindExistingWidget() method or the actual InsertNewWidget method? I just want to unit the test the logic inside the InsertorUpdate method to make sure its doing the right thing</p>
[ { "answer_id": 74408270, "author": "Oxymoron", "author_id": 1215018, "author_profile": "https://Stackoverflow.com/users/1215018", "pm_score": 0, "selected": false, "text": " private IWidgetRepository GetEmptyRepository()\n {\n var repo = new Mock<IWidgetRepository >();\n repo.Setup(s => s.InsertOrUpdateWidget(It.IsAny<Widget>())).Returns(true); \n return repo.Object;\n }\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1078009/" ]
74,407,941
<pre><code>import getpass p = getpass.getpass(prompt='What is the code you were given?? ') if p.lower() == 'breakout': print('Welcome..!!!') else: print('The answer entered by you is incorrect..!!!') </code></pre> <p>I tried a few things, all of them gave errors.</p>
[ { "answer_id": 74407988, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 2, "selected": false, "text": "while True" }, { "answer_id": 74408062, "author": "Jenia", "author_id": 12641442, "author_profile": "https://Stackoverflow.com/users/12641442", "pm_score": 1, "selected": false, "text": "import getpass\n\np = \"\"\nwhile p.lower() != \"breakout\": \n p = getpass.getpass(prompt=\"What is the code you were given?? \")\nelse:\n print(\"Welcome..!!!\")\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481183/" ]
74,407,946
<p>I have a very large file (19M rows) and the data needs to be cleaned. I am using a windows 11 machine. The data is being loaded into SQL server 19. I am currently using a perl script to remove any commas that are between double quotes. I will post my script below. This is taking a very long time to run. I feel like powershell would be quicker, but I can not seem to get it to run the REGEX that I need.</p> <pre><code>#! /usr/bin/perl -w use strict; use warnings; my $SRC = $ARGV[0]; my $DES = $ARGV[1]; open(SRC,'&lt;',$SRC) or die $!; open(DES,'&gt;',$DES) or die $!; my $n_fields = &quot;&quot;; while (&lt;&gt;) { s/\s+$//; if (/^\#/) { # header line my @t = split(/,/); $n_fields = scalar(@t); # total number of fields } else { # actual data my $n_commas = $_ =~s/,/,/g; # total number of commas foreach my $i (0 .. $n_commas - $n_fields) { # iterate ($n_commas - $n_fields + 1) times s/(\&quot;[^&quot;,]+),([^&quot;]+\&quot;)/$1\&quot;$2/g; # single replacement per previous answers } s/\&quot;//g; # removal of double quotes (if you want) } print DES &quot;$_\n&quot;; } close (DES); close (SRC); </code></pre> <p>The code I provided above works, but is very very slow. Looking for a quicker way to process the data. Than you in advance.</p>
[ { "answer_id": 74408980, "author": "zdim", "author_id": 4653379, "author_profile": "https://Stackoverflow.com/users/4653379", "pm_score": 4, "selected": true, "text": "use warnings;\nuse strict;\nuse feature 'say';\n\nmy $file = shift // die \"Usage: $0 file\\n\";\n\nopen my $fh, $file or die \"Can't open $file: $!\";\n\nmy $header = <$fh>;\n\nif ($header !~ /^#/) { # not header but data! Process\n print $header =~ s{\"[^\"]+\"}{ $& =~ tr/,\"//dr }ger; #\" stop bad syntax hilite\n}\n\nwhile (<$fh>) {\n print s{\"[^\"]+\"}{ $& =~ tr/,\"//dr }ger; #\"\n}\n" }, { "answer_id": 74417276, "author": "TLP", "author_id": 725418, "author_profile": "https://Stackoverflow.com/users/725418", "pm_score": 0, "selected": false, "text": "my $SRC = $ARGV[0]; # files in your @ARGV will be read by <> diamond operator\nmy $DES = $ARGV[1];\n....\nwhile (<>) { # should be <SRC>, but is <>\n....\n print DES \"$_\\n\"; # adding lines to your output file while reading it with <>\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12075005/" ]
74,407,947
<p>I want to make/replace object from string in javascript.</p> <pre><code>var api_response = { key: &quot;settings.options.height&quot;, val: 500 }; keys = api_response.key.split('.'); var settings = { options: { height: 0 } }; </code></pre> <p>i have no idea how to replace value of settings.options.height to api.val. i tried to combine array to settings[keys[0]][keys[1]][keys[2]] = api.val</p> <p>but what if i will have more or less keys than 3? Is here an function to map it?</p>
[ { "answer_id": 74408980, "author": "zdim", "author_id": 4653379, "author_profile": "https://Stackoverflow.com/users/4653379", "pm_score": 4, "selected": true, "text": "use warnings;\nuse strict;\nuse feature 'say';\n\nmy $file = shift // die \"Usage: $0 file\\n\";\n\nopen my $fh, $file or die \"Can't open $file: $!\";\n\nmy $header = <$fh>;\n\nif ($header !~ /^#/) { # not header but data! Process\n print $header =~ s{\"[^\"]+\"}{ $& =~ tr/,\"//dr }ger; #\" stop bad syntax hilite\n}\n\nwhile (<$fh>) {\n print s{\"[^\"]+\"}{ $& =~ tr/,\"//dr }ger; #\"\n}\n" }, { "answer_id": 74417276, "author": "TLP", "author_id": 725418, "author_profile": "https://Stackoverflow.com/users/725418", "pm_score": 0, "selected": false, "text": "my $SRC = $ARGV[0]; # files in your @ARGV will be read by <> diamond operator\nmy $DES = $ARGV[1];\n....\nwhile (<>) { # should be <SRC>, but is <>\n....\n print DES \"$_\\n\"; # adding lines to your output file while reading it with <>\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74407947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20469282/" ]
74,408,015
<p>I'd like to filter the choices that a user can choose in my ForeignKey Field. I basically have a ForeignKey for the subject of the Test and the actual topic of the Test. These topics come from a different model and are linked to a subject. Now I'd like to filter the choices to only include the topics that are linked to the currently selected subject. Is that possible and if so, how?</p> <p>models.py</p> <pre><code>class Test(models.Model): student = models.ForeignKey(Person, on_delete=models.CASCADE, blank=True, null=True) subject = models.ForeignKey(Subject, on_delete=models.CASCADE, blank=True, null=True) thema = models.ForeignKey(Thema, on_delete=models.CASCADE, blank=True, null=True) school_class = models.ForeignKey(SchoolClass, on_delete=models.CASCADE, blank=True, null=True) grade = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(6)], blank=True, null=True) date = models.DateField(default=datetime.date.today) def save(self, *args, **kwargs): if not self.school_class and self.student: self.school_class = self.student.klasse return super().save(*args, **kwargs) class Thema(models.Model): subject = models.ForeignKey(Subject, on_delete=models.CASCADE, blank=True, null=True) thema = models.CharField(max_length=50) class Subject(models.Model): teacher = models.ForeignKey(Person, on_delete=models.CASCADE, blank=True, null=True) name = models.CharField(max_length=20) </code></pre> <p>The Problem if I use this:</p> <pre><code># thema model @staticmethod def return_thema(subject): themen = Thema.objects.filter(subject=subject) return {'thema': themen} #test model thema = models.ForeignKey(Thema, on_delete=models.CASCADE, blank=True, null=True,limit_choices_to=Thema.return_thema(subject)) </code></pre> <p>Is that I get the Error: <code>django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.</code> Meaning I can't get the objects of the Thema Model while the models are loading</p> <p>EDIT (for Swift): That seemed to resolve the error when trying to makemigrations, but I now get this error, when visiting the admin portal to create a new Test:</p> <pre><code>File &quot;/Users/di/Code/Schule/GymnasiumApp/venv/lib/python3.10/site-packages/django/db/models/sql/query.py&quot;, line 1404, in build_filter arg, value = filter_expr ValueError: too many values to unpack (expected 2) </code></pre>
[ { "answer_id": 74408115, "author": "saro", "author_id": 18366396, "author_profile": "https://Stackoverflow.com/users/18366396", "pm_score": 0, "selected": false, "text": "fields['your model field'].queryset = yourmodel.objects.filter(your filter parameters)\n" }, { "answer_id": 74408696, "author": "Swift", "author_id": 8874154, "author_profile": "https://Stackoverflow.com/users/8874154", "pm_score": 1, "selected": false, "text": "ForeignKey.limit_choices_to" }, { "answer_id": 74529459, "author": "fehimtiras", "author_id": 20570124, "author_profile": "https://Stackoverflow.com/users/20570124", "pm_score": -1, "selected": false, "text": "return super(<modelName>).save(*args, **kwargs)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18298825/" ]
74,408,105
<p>I am trying to write a function that swap two arrays in O(1) time complexity. However, when i try to write the function parameters, I get the error:</p> <pre><code>error: cannot convert ‘int (*)[4]’ to ‘int**’ </code></pre> <p>Here is my code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; void swap_array_by_ptr(int* a[], int* b[]) { int* temp = *a; *a = *b; *b = temp; } int main() { int fr[] = {1,2,3,4}; int rv[] = {4,3,2,1}; swap_array_by_ptr(&amp;fr, &amp;rv); for (int i = 0; i &lt; 4 ; i++) { cout &lt;&lt; fr[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl; for (int i = 0; i &lt; 4 ; i++) { cout &lt;&lt; rv[i] &lt;&lt; &quot; &quot;; } } </code></pre> <p>However, when i tried to define the arrays with 'new' command, this works as expected as below:</p> <pre><code>#include &lt;iostream&gt; using namespace std; void swap_array_by_ptr(int** a, int** b) { int* temp = *a; *a = *b; *b = temp; } int main() { int fr = new int[4]{1,2,3,4}; int rv = new int[4]{4,3,2,1}; swap_array_by_ptr(&amp;fr, &amp;rv); for (int i = 0; i &lt; 4 ; i++) { cout &lt;&lt; fr[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl; for (int i = 0; i &lt; 4 ; i++) { cout &lt;&lt; rv[i] &lt;&lt; &quot; &quot;; } } </code></pre> <p>Is there any way that i can define the arrays with [] method and swap the arrays by sending these arrays with '&amp;array' method ?</p> <p>As I believe, there must be a way to do that, I only achieve this when I'm trying to do with 'new' method. However, is there any way to swap two arrays in O(1) complexity with sending parameters as<br /> swap_array_by_ptr(&amp;fr, &amp;rv); ?</p> <p>Thanks for help.</p>
[ { "answer_id": 74408218, "author": "Quantale", "author_id": 19883166, "author_profile": "https://Stackoverflow.com/users/19883166", "pm_score": -1, "selected": false, "text": "void swap_array_by_ptr(int* a, int* b) {\n int* temp = *a;\n *a = *b;\n *b = temp;\n}\n" }, { "answer_id": 74408286, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 2, "selected": true, "text": "int fr[] = {1,2,3,4};\nint rv[] = {4,3,2,1};\n\nswap_array_by_ptr(&fr, &rv);\n" }, { "answer_id": 74408502, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 1, "selected": false, "text": "void swap_array_by_ptr(int* a[], int* b[]) {\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481276/" ]
74,408,119
<p>I have this pandas dataframe that looks like this:</p> <pre><code>index up_walk down_walk up_avg down_avg 0 0.000000 17.827148 0.36642 9.06815 1 1.550781 0.000000 NaN NaN 2 0.957031 0.000000 NaN NaN 3 0.000000 2.878906 NaN NaN </code></pre> <p>I wanted to calculate the missing values that currently are NAN by this formula:</p> <pre><code>df['up_avg'][i] = df['up_avg'][i-1] * 12 + df['up_walk'][i] </code></pre> <p>explanation: I want to calculate for every row the value based on the previous row in the same column, plus the value in the current row from a different column. And that for every row with missing values. and Continue this calculation to the end of the dataframe. In this case, I have a dependency in every new row calculation that is based on the previous up_avg value calculation.</p> <p>The problem is that using a loop is very slow because of the large dataframe(10K)</p> <p>Can anyone please help implement a lambda function for this?</p> <p>if this is not possible, can anyone share a script for an efficient loop?</p> <p>I tried a lot of things with no success like this:</p> <pre><code>df['up_avg'] = df.apply(lambda x: pd.Series(np.where((x.up_avg != None), x.up_avg.shift() * 12 + x.up_walk, x.up_avg))) got an error - &quot;AttributeError: 'Series' object has no attribute 'up_avg'&quot; </code></pre> <p>and also using shift to create new columns and then using a lambda function with no success</p> <p>I expect that my dataframe will look like this at the end:</p> <pre><code>index up_walk down_walk up_avg down_avg 0 0.000000 17.827148 0.36642 9.06815 1 1.550781 0.000000 5.947821 108.8178 2 0.957031 0.000000 72.330883 1305.8136 3 0.000000 2.878906 867.970596 15672.642106 </code></pre> <p>Thanks a lot!</p>
[ { "answer_id": 74408637, "author": "Bushmaster", "author_id": 15415267, "author_profile": "https://Stackoverflow.com/users/15415267", "pm_score": 2, "selected": true, "text": "#keep going until there is no nan value left\nstatus=True\nwhile status:\n df['up_avg'] = np.where((np.isnan(df.up_avg)==True), np.roll(df.up_avg,1) * 12 +df.up_walk ,df.up_avg)\n if df['up_avg'].isnull().sum() == 0:\n status=False\n \nstatus=True\nwhile status:\n df['down_avg'] = np.where((np.isnan(df.down_avg)==True), np.roll(df.down_avg,1) * 12 +df.down_walk ,df.down_avg)\n if df['down_avg'].isnull().sum() == 0:\n status=False\n\nprint(df)\n up_walk down_walk up_avg down_avg\n0 0.0 17.827148 0.36642 9.06815\n1 1.550781 0.0 5.947821 108.81779999999999\n2 0.957031 0.0 72.330883 1305.8136\n3 0.0 2.878906 867.970596 15672.642106\n\n```\n" }, { "answer_id": 74409040, "author": "Vin", "author_id": 7955271, "author_profile": "https://Stackoverflow.com/users/7955271", "pm_score": 0, "selected": false, "text": "nan" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480909/" ]
74,408,136
<p>Hello I have a project for my studies which is to display data on a dashboard that will be more or less modifiable by the user according to his needs.</p> <p>I'm trying to open a modal window but it doesn't work and i can't figure out where my mistake came from.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const body = document.querySelector("body"), sidebar = body.querySelector(".sidebar"), btn = body.querySelector("#btn"); btn.addEventListener("click", () =&gt; { sidebar.classList.toggle("active"); }) const modalContainer = document.querySelector(".modal-container"); const modalTriggers = document.querySelector(".modal-trigger"); modalTriggers.forEach(trigger =&gt; trigger.addEventListener("click", toggleModal)) function toggleModal() { modalContainer.classList.toggle("active") }</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { height: 100vh; background: var(--body-color); } .sidebar { position: fixed; top: 0; left: 0; height: 100%; width: 78px; background: var(--primary-color); padding: 6px 14px; transition: all 0.5s ease; } .sidebar.active { width: 240px } .sidebar .logo_content .logo { color: #FFF; display: flex; height: 50px; width: 100%; align-items: center; opacity: 0; pointer-events: none; } .sidebar.active .logo_content .logo { opacity: 1; pointer-events: none; } .logo_content .logo i { font-size: 28px; margin-right: 5px; } .logo_content .logo .logo_name { font-size: 20px; font-weight: 400; } .sidebar #btn { position: absolute; color: #FFF; top: 6px; left: 50%; font-size: 20px; height: 50px; width: 50px; text-align: center; line-height: 50px; cursor: pointer; transform: translateX(-50%); } .sidebar.active #btn { left: 90%; } .sidebar ul { margin-top: 20px; } .sidebar li { position: relative; height: 50px; width: 100%; margin: 0 0px; list-style: none; line-height: 50px; } .sidebar li a { color: #FFF; display: flex; align-items: center; text-decoration: none; transition: all 0.4s ease; border-radius: 12px; white-space: nowrap; } .sidebar li a:hover { color: #11101d; background: #FFF; } .sidebar li a i { height: 50px; min-width: 50px; border-radius: 12px; line-height: 50px; text-align: center; } .sidebar .links_name { opacity: 0; pointer-events: none; } .sidebar.active .links_name { opacity: 1; pointer-events: auto; } .sidebar .menu-bar { height: calc(100% - 50px); display: flex; flex-direction: column; justify-content: space-between; } .home { position: relative; height: 100vh; left: 78px; width: calc(100% - 78px); background: var(--body-color); transition: var(--tran-05); } .home .text { font-size: 30px; font-weight: 500; color: var(--text-color); padding: 8px 40px; } .sidebar.active~.home { left: 240px; width: calc(100% - 78px); } .modal-container { display: none; position: fixed; top: 0; width: 100vw; height: 100vh; } .modal-container.active { display: flex; } .overlay { position: absolute; width: 100%; height: 100%; background: #333333d3; } .modal { width: 95%; border-radius: 5px; max-width: 500px; min-width: 300px; padding: 30px; background: #FFF; position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); } .close-modal { padding: 8px 10px; border: none; border-radius: 5px; font-size: 18px; position: absolute; top: 10px; right: 10px; cursor: pointer; background: #ff365e; color: #FFF; } .modal h1 { margin-top: 0px; font-family: Montserrat, sans-serif; font-weight: 500; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;head&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;!-- &lt;link rel="stylesheet" href="style.css"&gt; --&gt; &lt;link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="sidebar"&gt; &lt;div class="logo_content"&gt; &lt;div class="logo"&gt; &lt;i class='bx bx1-c-plus-plus'&gt;&lt;/i&gt; &lt;div class="logo_name"&gt;SailVision&lt;/div&gt; &lt;/div&gt; &lt;i class='bx bx-menu' id="btn"&gt;&lt;/i&gt; &lt;/div&gt; &lt;div class="menu-bar"&gt; &lt;ul class="dash_list"&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;i class='bx bx-windows'&gt;&lt;/i&gt; &lt;span class="links_name"&gt;Dashboard n°1&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;i class='bx bx-windows'&gt;&lt;/i&gt; &lt;span class="links_name"&gt;Dashboard n°2&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;i class='bx bx-plus'&gt;&lt;/i&gt; &lt;span class="links_name"&gt;Ajouter&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;i class='bx bx-customize modal-trigger'&gt;&lt;/i&gt; &lt;span class="links_name"&gt;Template&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;div class="bottom_content"&gt; &lt;li&gt; &lt;a href="#"&gt; &lt;i class='bx bx-cog'&gt;&lt;/i&gt; &lt;span class="links_name"&gt;Paramètre&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="home"&gt; &lt;div class="template"&gt;Template n°1&lt;/div&gt; &lt;/div&gt; &lt;div class="modal-container"&gt; &lt;div class="overlay modal-trigger"&gt; &lt;div class="modal"&gt; &lt;button class="close-modal modal-trigger"&gt;X&lt;/button&gt; &lt;h1&gt;Choix des templates&lt;/h1&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- &lt;script src="script.js"&gt;&lt;/script&gt; --&gt; &lt;/body&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74408217, "author": "Franco Gabriel", "author_id": 19499461, "author_profile": "https://Stackoverflow.com/users/19499461", "pm_score": 1, "selected": false, "text": "querySelector()" }, { "answer_id": 74409042, "author": "Owusu Ansah Gerald", "author_id": 11176983, "author_profile": "https://Stackoverflow.com/users/11176983", "pm_score": 3, "selected": true, "text": "<div class=\"overlay\">" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19930293/" ]
74,408,145
<p>Here's a link to my website <a href="https://faceyneck.com" rel="nofollow noreferrer">Facey's Thoughts</a> and here's a link to the <a href="https://github.com/faceyneck/faceyneck.github.io/tree/main" rel="nofollow noreferrer">GitHub Pages</a> project.</p> <p>Cloning the (working) repository to my local machine and trying to run <code>jekyll build</code> fails with this error:</p> <blockquote> <p>Liquid Exception: Invalid syntax for include tag. File contains invalid characters or sequences: social-icons/.svg Valid syntax: {% include file.ext param='value' param2='value' %} in assets/minima-social-ico.html</p> </blockquote> <p>The Jekyll version is still the same as what's specified in my Gemfile: <code>jekyll 4.3.1</code>. I have no idea what's changed.</p> <p>I've tried removing the minima-social-ico.svg file; I've tried removing the posts that I was <em>trying</em> to add; I've tried searching Online for something similar to this issue without luck.</p> <p>I tried <code>jekyll build</code> with local files, cloning my GitHub pages repo to a new directory, and that repo <em>for sure</em> built last night, and I've tried removing any new .markdown files that I made since the last time it successfully built.</p> <p>I tried the following:</p> <p>If I comment out <code>social_links</code> from my <code>_config.yml</code> file, it will build, I assume because it's not using the <code>minima_social_icons.svg</code> file. Why did it work and now it doesn't?</p>
[ { "answer_id": 74420266, "author": "Yshmarov", "author_id": 5695646, "author_profile": "https://Stackoverflow.com/users/5695646", "pm_score": 2, "selected": false, "text": " social_links:\n - { platform: rss, user_url: \"/feed.xml\" }\n - { platform: github, user_url: \"https://github.com/yshmarov/\" }\n - { platform: twitter, user_url: \"https://twitter.com/yarotheslav\" }\n - { platform: linkedin, user_url: \"https://www.linkedin.com/in/yshmarov/\" }\n" }, { "answer_id": 74427075, "author": "Ankush", "author_id": 6770517, "author_profile": "https://Stackoverflow.com/users/6770517", "pm_score": 3, "selected": false, "text": "_config.yml" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19611975/" ]
74,408,159
<p>i have an unknow string, that contains several &quot;/&quot;. I need all characters after the last &quot;/&quot;. Example. (Remeber the actual string will be unknown) string= abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw</p> <p>I need return &quot;zyxw&quot;</p> <p>thank you all for help</p> <p>im just really bad with the symbols for pattern matching and no clue how to say &quot;return everything after the last &quot;/&quot;&quot;</p>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19478592/" ]
74,408,167
<p>I have a simple bar chart I am using in a shiny application with some filters. I am using the following code.</p> <pre><code>ggplot(users_by_month(), aes(x = month, y = n)) + geom_bar(stat = &quot;identity&quot;) + geom_text(aes(label=n), nudge_y = 4) </code></pre> <p>When no filters are being used this works and the sum of each month is above the bar. However when I use a filter and the values change the sums above the bars move to much higher above the bar. Is there a way to keep the <code>nudge_y</code> relative to the bar height so the text remains right above the bar as the underlying data changes?</p>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3249770/" ]
74,408,174
<p>Let me preface this by saying that I am new to programming. I would like to create a new array for each iteration, not add elements to the same array. How can I create a new array?</p> <p>If I use E=np.array[(...)]</p> <p>in my loop, I will be rewriting the array every single time. I want to have a series of arrays saved so that I can Add them to a data frame later and then sort the arrays by the size of the first element.</p> <p>Here is my code:</p> <pre><code> E=0 n=0 En=np.array(0) for x in range(1,7): for y in range(1,7): for z in range(1,7): E= x**2+y**2+z**2 if E&lt;=14: n= n+1 print( &quot;the energy and the nx, ny, nz is&quot;, E,x, y, z) E= if E&gt; 14: break print(f'there are {n} cobinations') </code></pre> <p>I don't know. I am new to programming and could not find any answers to &quot;create a new array in the loop&quot;, so I did try this:</p> <pre><code>for x in range(1,7): for y in range(1,7): for z in range(1,7): E= x**2+y**2+z**2 if E&lt;=14: n= n+1 print( &quot;the energy and the nx, ny, nz is&quot;, E,x, y, z) Exyz=np.array([E,x,y,z]) if E&gt; 14: </code></pre> <p>This does not allow me to create a new array corresponding to each loop.</p>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481280/" ]
74,408,180
<p>I'm testing a local Icecast server on Ubuntu, using Traefik 1.7 in Docker containers.</p> <p>When manually going to a page on a subdomain, all CORS headers are set:</p> <p><a href="https://i.stack.imgur.com/blQKg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/blQKg.png" alt="enter image description here" /></a></p> <p>But accessing the page from another local domain always gives 502 errors on OPTIONS.</p> <p>I've managed to get some debug info from the Traefik container, but I'm stuck as to how to solve this.</p> <pre><code>everse-proxy | time=&quot;2022-11-11T21:08:01Z&quot; level=debug msg=&quot;vulcand/oxy/forward/http: begin ServeHttp on request&quot; Request=&quot;{\&quot;Method\&quot;:\&quot;OPTIONS\&quot;,\&quot;URL\&quot;:{\&quot;Scheme\&quot;:\&quot;http\&quot;,\&quot;Opaque\&quot;:\&quot;\&quot;,\&quot;User\&quot;:null,\&quot;Host\&quot;:\&quot;10.10.1.8:8000\&quot;,\&quot;Path\&quot;:\&quot;\&quot;,\&quot;RawPath\&quot;:\&quot;\&quot;,\&quot;ForceQuery\&quot;:false,\&quot;RawQuery\&quot;:\&quot;\&quot;,\&quot;Fragment\&quot;:\&quot;\&quot;,\&quot;RawFragment\&quot;:\&quot;\&quot;},\&quot;Proto\&quot;:\&quot;HTTP/2.0\&quot;,\&quot;ProtoMajor\&quot;:2,\&quot;ProtoMinor\&quot;:0,\&quot;Header\&quot;:{\&quot;Accept\&quot;:[\&quot;*/*\&quot;],\&quot;Accept-Encoding\&quot;:[\&quot;gzip, deflate, br\&quot;],\&quot;Accept-Language\&quot;:[\&quot;en-US,en;q=0.9,nl;q=0.8\&quot;],\&quot;Access-Control-Request-Headers\&quot;:[\&quot;icy-metadata\&quot;],\&quot;Access-Control-Request-Method\&quot;:[\&quot;GET\&quot;],\&quot;Cache-Control\&quot;:[\&quot;no-cache\&quot;],\&quot;Origin\&quot;:[\&quot;https://gsr.localhost.traefik.me\&quot;],\&quot;Pragma\&quot;:[\&quot;no-cache\&quot;],\&quot;Referer\&quot;:[\&quot;https://gsr.localhost.traefik.me/\&quot;],\&quot;Sec-Fetch-Dest\&quot;:[\&quot;empty\&quot;],\&quot;Sec-Fetch-Mode\&quot;:[\&quot;cors\&quot;],\&quot;Sec-Fetch-Site\&quot;:[\&quot;same-site\&quot;],\&quot;User-Agent\&quot;:[\&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36\&quot;]},\&quot;ContentLength\&quot;:0,\&quot;TransferEncoding\&quot;:null,\&quot;Host\&quot;:\&quot;radio.localhost.traefik.me\&quot;,\&quot;Form\&quot;:null,\&quot;PostForm\&quot;:null,\&quot;MultipartForm\&quot;:null,\&quot;Trailer\&quot;:null,\&quot;RemoteAddr\&quot;:\&quot;127.0.0.1:53784\&quot;,\&quot;RequestURI\&quot;:\&quot;/radio\&quot;,\&quot;TLS\&quot;:null}&quot; reverse-proxy | time=&quot;2022-11-11T21:08:01Z&quot; level=debug msg=&quot;Upstream ResponseWriter of type *pipelining.writerWithoutCloseNotify does not implement http.CloseNotifier. Returning dummy channel.&quot; reverse-proxy | time=&quot;2022-11-11T21:08:01Z&quot; level=debug msg=&quot;'502 Bad Gateway' caused by: EOF&quot; reverse-proxy | time=&quot;2022-11-11T21:08:01Z&quot; level=debug msg=&quot;vulcand/oxy/forward/http: Round trip: http://10.10.1.8:8000, code: 502, Length: 11, duration: 5.960359ms tls:version: 303, tls:resume:true, tls:csuite:c02f, tls:server:radio.localhost.traefik.me&quot; </code></pre> <p>The <code>docker-compose.yml</code>:</p> <pre><code>version: &quot;3.1&quot; networks: db_default: external: true services: reverse-proxy: container_name: reverse-proxy image: traefik:v1.7-alpine # The official Traefik docker image network_mode: &quot;host&quot; command: --api --docker # Enables the web UI and tells Tr fik to listen to docker volumes: - ./docker:/certs:ro - ./docker/traefik.toml:/etc/traefik/traefik.toml - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events gsr2: container_name: gsrdev2 build: docker volumes: - .bash_history:/root/.bash_history - ./:/var/www - ./log:/tmp/audit environment: #PHP_IDE_CONFIG: &quot;serverName=gsr2.localhost.xip.io&quot; XDEBUG_CONFIG: &quot;start_with_request=yes&quot; labels: - traefik.enable=true - &quot;traefik.frontend.rule=Host:gsr.localhost.traefik.me&quot; networks: - db_default icecast2: image: pltnk/icecast2 container_name: icecast2 expose: - 8000 volumes: - ./icecast.xml:/etc/icecast2/icecast.xml - ./log:/var/log/icecast2 - ./docker/bundle.pem:/etc/icecast2/bundle.pem labels: - traefik.enable=true - &quot;traefik.frontend.rule=Host:radio.localhost.traefik.me&quot; networks: - db_default </code></pre> <p>The <code>traefik.toml</code>:</p> <pre><code> defaultEntryPoints = [&quot;http&quot;,&quot;https&quot;] loglevel=&quot;DEBUG&quot; [api] dashboard = false [entryPoints] [entryPoints.http] address = &quot;:80&quot; #[entryPoints.http.redirect] # regex = &quot;^http://(www.)*(.*)&quot; # replacement = &quot;https://$2&quot; # permanent = true [entryPoints.https] address = &quot;:443&quot; [entryPoints.https.tls] [[entryPoints.https.tls.certificates]] certFile = &quot;/certs/cert.pem&quot; keyFile = &quot;/certs/key.pem&quot; [docker] endpoint = &quot;unix:///var/run/docker.sock&quot; domain = &quot;localhost.traefik.me&quot; watch = true exposedbydefault = false network = &quot;proxy&quot; </code></pre> <p>Header config in Icecast server:</p> <pre><code> &lt;http-headers&gt; &lt;header name=&quot;Access-Control-Allow-Origin&quot; value=&quot;*&quot; /&gt; &lt;header name=&quot;Vary&quot; value=&quot;Origin&quot; /&gt; &lt;header name=&quot;Access-Control-Allow-Methods&quot; value=&quot;GET, OPTIONS, PUT, POST&quot; /&gt; &lt;header name=&quot;Access-Control-Allow-Headers&quot; value=&quot;Content-Type, Icy-Metadata&quot; /&gt; &lt;header name=&quot;Access-Control-Expose-Headers&quot; value=&quot;Icy-MetaInt, Icy-Br, Icy-Description, Icy-Genre, Icy-Name, Ice-Audio-Info, Icy-Url, Icy-Sr, Icy-Vbr, Icy-Pub&quot; /&gt; &lt;/http-headers&gt; </code></pre>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/350048/" ]
74,408,198
<p>All the documentation I've found on Eleventy pagination has to do with a single level, and I've got that working pretty well.</p> <ul> <li>Take a collection (ex. of tags) and create one page each</li> <li>Take a collection of posts and put 10 on each page and so on.</li> </ul> <p>What I'd like to do now is combine them: loop over all the tags, and then paginate each tag's collection so if I use some tags a lot, they don't end up with 50 posts on the same page. Basically the way WordPress generates paginated views for each tag.</p> <p>Something like this: (simplified, I know filters need to be in there)</p> <pre><code>pagination: data: collections size: 1 alias: tag pagination: data: tag size: 10 alias: tagpost </code></pre> <p>Though that didn't seem to work.</p> <p>Is there some way to do multi-level pagination, or would I need to take some other approach for the outer loop?</p>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17938513/" ]
74,408,219
<p>As simple as this sounds I cannot figure it out... Here's what I want to do</p> <pre><code>df = pd.DataFrame( [ {'first names' : ['trey', 'tagg']}, {'first names' : ['teague', 'tanner']}, ] ) </code></pre> <p>df</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th></th> <th>first names</th> </tr> </thead> <tbody> <tr> <td>0</td> <td>[trey, tagg]</td> </tr> <tr> <td>1</td> <td>['teague', 'tanner']</td> </tr> </tbody> </table> </div> <p>I would like to do something such as <code>df['first names'].append('joe')</code> and get the result..</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th></th> <th>first names</th> </tr> </thead> <tbody> <tr> <td>0</td> <td>[trey, tagg, joe]</td> </tr> <tr> <td>1</td> <td>['teague', 'tanner', joe]</td> </tr> </tbody> </table> </div>
[ { "answer_id": 74409203, "author": "Shawn Bragdon", "author_id": 19753194, "author_profile": "https://Stackoverflow.com/users/19753194", "pm_score": 2, "selected": false, "text": "local function getLastFromPath(path)\n local last = path:match(\"([^/]+)$\")\n return last\nend\n\nprint(getLastFromPath(\"abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw\"))\n" }, { "answer_id": 74411660, "author": "koyaanisqatsi", "author_id": 11740758, "author_profile": "https://Stackoverflow.com/users/11740758", "pm_score": 3, "selected": true, "text": "> ustr = 'abcdefg/hijkl/123hgj-sg/diejdu/duhd3/zyxw'\n> last = ustr:gsub('.*%/', '') -- I prefer gsub() method on string\n> print(last)\nzyxw\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13972322/" ]
74,408,224
<p>I have a table in PostgreSQL:</p> <pre><code>| id | country| type | | 1 | USA | FOO | | 2 | null | BAR | </code></pre> <p>I want to change the column type for the <code>country</code> column from <code>text</code> to <code>array</code> and cast to the new type only non-null values to have the table look as follows:</p> <pre><code>| id | country | type | | 1 | {USA} | FOO | | 2 | null | BAR | </code></pre> <p>So far, I have come up with this expression that casts any value to the array. So for the 2nd row, I have an array with a <code>null</code> value.</p> <pre><code>ALTER TABLE my_table ALTER COLUMN country TYPE TEXT[] USING ARRAY[country]; </code></pre> <p>How can I use the <code>USING</code> expression to cast only not null values?</p>
[ { "answer_id": 74408512, "author": "a_horse_with_no_name", "author_id": 330315, "author_profile": "https://Stackoverflow.com/users/330315", "pm_score": 0, "selected": false, "text": "ALTER TABLE my_table\n ALTER COLUMN country TYPE TEXT[]\n USING case \n when country is null then null \n else ARRAY[country] \n end;\n" }, { "answer_id": 74408534, "author": "Pepe N O", "author_id": 15062361, "author_profile": "https://Stackoverflow.com/users/15062361", "pm_score": 2, "selected": true, "text": "ALTER TABLE my_table\nALTER COLUMN country TYPE TEXT[]\nUSING string_to_array(country,'');\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6934058/" ]
74,408,245
<p>How can I use data from my first fetch in the second fetch? I am getting undefined for the first search and then it's ok, how can I get it on the first search without getting &quot;undefined&quot;?</p> <pre><code> const [summoner, setSummoner] = useState(&quot;&quot;); const [playerData, setPlayerData] = useState({}); const [playerRank, setPlayerRank] = useState({}); function searchPlayer(event) { axios.get(&quot;API1&quot; + summoner + API_KEY).then(function (response) { setPlayerData(response.data); }).catch(function (error) { console.log(error); }); console.log(playerData.id); axios.get(&quot;API2&quot; + playerData.id + API_KEY).then(function (response) { setPlayerRank(response.data) }).catch(function (error) { console.log(error); }); } </code></pre> <p>This is my console:</p> <pre><code>log: undefined log: id </code></pre>
[ { "answer_id": 74408512, "author": "a_horse_with_no_name", "author_id": 330315, "author_profile": "https://Stackoverflow.com/users/330315", "pm_score": 0, "selected": false, "text": "ALTER TABLE my_table\n ALTER COLUMN country TYPE TEXT[]\n USING case \n when country is null then null \n else ARRAY[country] \n end;\n" }, { "answer_id": 74408534, "author": "Pepe N O", "author_id": 15062361, "author_profile": "https://Stackoverflow.com/users/15062361", "pm_score": 2, "selected": true, "text": "ALTER TABLE my_table\nALTER COLUMN country TYPE TEXT[]\nUSING string_to_array(country,'');\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12533737/" ]
74,408,260
<p>I used a regex expression which extracted numbers from some line and this created some list which i combined using the append function how do i combine these sublists into one list</p> <pre><code>fname=input('Enter file name:') if len(fname)&lt;1: fname='regex_sum_42.txt' fhand=open(fname) total=0 numlist=list() for line in fhand: line.rstrip() numl= re.findall('([0-9]+)',line ) if len(numl)&lt;1: continue numlist.append(numl[0:]) print(numlist) </code></pre> <p>What i got : [[1,2,3],[4,5]] ,i expected to get [1,2,3,4,5]</p>
[ { "answer_id": 74408609, "author": "0x0fba", "author_id": 20339407, "author_profile": "https://Stackoverflow.com/users/20339407", "pm_score": 2, "selected": true, "text": "sum(numlist, [])\n" }, { "answer_id": 74409425, "author": "Hai Vu", "author_id": 459745, "author_profile": "https://Stackoverflow.com/users/459745", "pm_score": 0, "selected": false, "text": "# Assume file_name is defined\n\nwith open(file_name) as stream:\n contents = stream.read()\n \nnumbers_list = re.findall(r\"\\d+\", contents)\nnumbers_list = [int(number) for number in numbers_list]\nprint(numbers_list)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481350/" ]
74,408,271
<p>The existing code I’m working with is creating a new method with duplicate code each time because it is using @<strong>ManagedListener</strong> configured for the different Kafka Topics and diff configurations using <strong>Java Spring Boot</strong>.</p> <pre><code>`@ManagedListener({configurations for Kafka topic-a}) method1(){ //logic to handle data } @ManagedListener({configurations for Kafka topic-b}) method2(){ //same logic as method1 copied } @ManagedListener({configurations for Kafka topic-c}) method3(){ //same logic as method1 copied again }` </code></pre> <p>Is there a way I can have a listener configured to different Kafka topics configurations that all call method1 directly? I’m trying to find a way to avoid duplicate code.</p> <p>I tried to add multiple @managedListener annotations to the same method, but it seems like it has to be one to one. It will work if I duplicate the code, but it seems counterintuitive</p> <p>The expected result is to be able to receive messages from multiple different Kafka topics.</p>
[ { "answer_id": 74408609, "author": "0x0fba", "author_id": 20339407, "author_profile": "https://Stackoverflow.com/users/20339407", "pm_score": 2, "selected": true, "text": "sum(numlist, [])\n" }, { "answer_id": 74409425, "author": "Hai Vu", "author_id": 459745, "author_profile": "https://Stackoverflow.com/users/459745", "pm_score": 0, "selected": false, "text": "# Assume file_name is defined\n\nwith open(file_name) as stream:\n contents = stream.read()\n \nnumbers_list = re.findall(r\"\\d+\", contents)\nnumbers_list = [int(number) for number in numbers_list]\nprint(numbers_list)\n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481080/" ]
74,408,278
<p>In my job, we needed to implement authentication because of security and we wanted the DB not to be completely open. We have implemented anonymous authentication because the app is not based on a user profile. It works well, but it is creating too many users (every time the app is uninstalled or the cache is cleared a new user is created). Although there isn't any limit for anonymous users, it is not good to have so many <a href="https://en.wikipedia.org/wiki/User_identifier" rel="nofollow noreferrer">UIDs</a> in the project.</p> <p>Now I was thinking of creating one user in the console (email/password authentication), and all devices authenticate using such email and password.</p> <p>Would there be a problem with that? Would Firebase limit the number of sessions with the same user?</p> <p>My app has about 20 000 active users. Is it a problem with 20 000 sessions at the same time and also with so many requests to Firebase products with the same user? It's important to be completely sure that a limit problem will not occur before I make that migration from anonymous to email/password (unique user).</p>
[ { "answer_id": 74408897, "author": "Tim", "author_id": 20317091, "author_profile": "https://Stackoverflow.com/users/20317091", "pm_score": 0, "selected": false, "text": "beforeCreate" }, { "answer_id": 74428355, "author": "Alex Mamo", "author_id": 5246885, "author_profile": "https://Stackoverflow.com/users/5246885", "pm_score": 2, "selected": false, "text": "auth.uid==$user.uid" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14107943/" ]
74,408,311
<p>I'm wanting to correlate two variables in R but only for specific values of two other variables. For example, I want to look at the correlation between test scores (v1) and study time (v2) for people 16 or older who are female (gender=1).</p> <p>In STATA, I would write something like this:</p> <p>pwcorr v1 v2 if age&gt;15 &amp; gender==1</p> <p>How would I do this in R? Is there a way to do this without creating a data subset?</p>
[ { "answer_id": 74408897, "author": "Tim", "author_id": 20317091, "author_profile": "https://Stackoverflow.com/users/20317091", "pm_score": 0, "selected": false, "text": "beforeCreate" }, { "answer_id": 74428355, "author": "Alex Mamo", "author_id": 5246885, "author_profile": "https://Stackoverflow.com/users/5246885", "pm_score": 2, "selected": false, "text": "auth.uid==$user.uid" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20463228/" ]
74,408,312
<p>I have a list of strings in my program, for example:</p> <p>[ 'home', 'dog', 'park', 'house', 'hotel', 'fire' ]</p> <p>and I want to know which is the most first frequent letter .</p> <p>for example in that string is the letter H because it is in hotel, house and home.</p> <p>I tried just 2 for cycles but I didn't get the result</p>
[ { "answer_id": 74408426, "author": "John Shallow", "author_id": 18195837, "author_profile": "https://Stackoverflow.com/users/18195837", "pm_score": 0, "selected": false, "text": "from collections import Counter\n\n\nlist_ = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\n\n\nif __name__ == '__main__':\n counter = Counter(word[0] for word in list_)\n print(counter.most_common(1)[0][0])\n" }, { "answer_id": 74408430, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 1, "selected": false, "text": "from collections import Counter\nls= [ 'home', 'dog', 'park', 'house', 'hotel', 'fire' ]\nls = [w[0] for w in ls]\n\ns=(Counter(ls))\n\nprint(max(s, key=s.get))\n" }, { "answer_id": 74408433, "author": "DeusDev", "author_id": 10312417, "author_profile": "https://Stackoverflow.com/users/10312417", "pm_score": 1, "selected": false, "text": "collections.Counter" }, { "answer_id": 74408434, "author": "yutytuty", "author_id": 11412148, "author_profile": "https://Stackoverflow.com/users/11412148", "pm_score": 2, "selected": false, "text": "lst = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\nmax([item[0] for item in lst], key=lst.count)\n" }, { "answer_id": 74408446, "author": "James_481", "author_id": 13633328, "author_profile": "https://Stackoverflow.com/users/13633328", "pm_score": 1, "selected": false, "text": "from statistics import mode\ndef most_common_first_letter(words):\n first_letters = []\n for word in words:\n first_letters.append(word[0])\n return mode(first_letters)\n \n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16797605/" ]
74,408,340
<p>I have the following package file</p> <pre class="lang-json prettyprint-override"><code>{ &quot;version&quot;: &quot;1.0.0&quot;, &quot;scripts&quot;: { &quot;dev&quot;: &quot;node ./pm2.js&quot;, }, &quot;dependencies&quot;: { &quot;@nuxtjs/axios&quot;: &quot;5.10.2&quot;, &quot;@nuxtjs/style-resources&quot;: &quot;1.0.0&quot;, &quot;@sendgrid/mail&quot;: &quot;6.3.1&quot;, &quot;axios&quot;: &quot;0.19.2&quot;, &quot;cheerio&quot;: &quot;1.0.0-rc.2&quot;, &quot;compression&quot;: &quot;1.7.4&quot;, &quot;cookie-parser&quot;: &quot;1.4.6&quot;, &quot;express&quot;: &quot;4.17.1&quot;, &quot;geoip2ws&quot;: &quot;1.8.10&quot;, &quot;gsap&quot;: &quot;2.1.3&quot;, &quot;lodash&quot;: &quot;4.17.21&quot;, &quot;moment&quot;: &quot;2.29.4&quot;, &quot;mongoose&quot;: &quot;5.9.10&quot;, &quot;morgan&quot;: &quot;1.10.0&quot;, &quot;nuxt&quot;: &quot;2.15.8&quot;, &quot;pm2&quot;: &quot;4.4.0&quot;, &quot;request&quot;: &quot;2.88.0&quot;, &quot;sitemap&quot;: &quot;2.2.0&quot;, &quot;vcards-js&quot;: &quot;2.10.0&quot;, &quot;vuex-router-sync&quot;: &quot;5.0.0&quot; }, &quot;devDependencies&quot;: { &quot;@babel/core&quot;: &quot;7.18.10&quot;, &quot;@babel/eslint-parser&quot;: &quot;7.18.9&quot;, &quot;chokidar&quot;: &quot;3.4.0&quot;, &quot;eslint&quot;: &quot;8.21.0&quot;, &quot;eslint-config-standard&quot;: &quot;17.0.0&quot;, &quot;eslint-plugin-vue&quot;: &quot;9.3.0&quot;, &quot;eslint-webpack-plugin&quot;: &quot;2.7.0&quot;, &quot;normalize-scss&quot;: &quot;7.0.1&quot;, &quot;postcss-preset-env&quot;: &quot;6.7.0&quot;, &quot;sass&quot;: &quot;1.54.0&quot;, &quot;sass-loader&quot;: &quot;10.3.1&quot; }, &quot;engines&quot;: { &quot;node&quot;: &quot;18.7.0&quot;, &quot;npm&quot;: &quot;8.13.2&quot; } } </code></pre> <p>But upon running I get the following error</p> <blockquote> <p>| Error: Rule can only have one resource source (provided resource and test + include + exclude) in { | &quot;use&quot;: [ | { | &quot;loader&quot;: &quot;/usr/src/app/node_modules/babel-loader/lib/index.js&quot;, |<br /> &quot;options&quot;: { | &quot;configFile&quot;: false, | &quot;babelrc&quot;: false, | &quot;cacheDirectory&quot;: true, | &quot;envName&quot;: &quot;server&quot;, | &quot;presets&quot;: [ | [ |<br /> /usr/src/app/node_modules/@nuxt/babel-preset-app/src/index.js, |<br /> { | &quot;corejs&quot;: { | &quot;version&quot;: 2 |<br /> } | } | ] | ] | }, |<br /> &quot;ident&quot;: &quot;clonedRuleSet-30.use[0]&quot; | } | ] | } | at checkResourceSource (/usr/src/app/node_modules/@nuxt/webpack/node_modules/webpack/lib/RuleSet.js:167:11) | at RuleSet.normalizeRule (/usr/src/app/node_modules/@nuxt/webpack/node_modules/webpack/lib/RuleSet.js:198:4)</p> </blockquote> <p>I am not sure which package is causing this?</p>
[ { "answer_id": 74408426, "author": "John Shallow", "author_id": 18195837, "author_profile": "https://Stackoverflow.com/users/18195837", "pm_score": 0, "selected": false, "text": "from collections import Counter\n\n\nlist_ = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\n\n\nif __name__ == '__main__':\n counter = Counter(word[0] for word in list_)\n print(counter.most_common(1)[0][0])\n" }, { "answer_id": 74408430, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 1, "selected": false, "text": "from collections import Counter\nls= [ 'home', 'dog', 'park', 'house', 'hotel', 'fire' ]\nls = [w[0] for w in ls]\n\ns=(Counter(ls))\n\nprint(max(s, key=s.get))\n" }, { "answer_id": 74408433, "author": "DeusDev", "author_id": 10312417, "author_profile": "https://Stackoverflow.com/users/10312417", "pm_score": 1, "selected": false, "text": "collections.Counter" }, { "answer_id": 74408434, "author": "yutytuty", "author_id": 11412148, "author_profile": "https://Stackoverflow.com/users/11412148", "pm_score": 2, "selected": false, "text": "lst = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\nmax([item[0] for item in lst], key=lst.count)\n" }, { "answer_id": 74408446, "author": "James_481", "author_id": 13633328, "author_profile": "https://Stackoverflow.com/users/13633328", "pm_score": 1, "selected": false, "text": "from statistics import mode\ndef most_common_first_letter(words):\n first_letters = []\n for word in words:\n first_letters.append(word[0])\n return mode(first_letters)\n \n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2148090/" ]
74,408,345
<p>I'm new to batch and trying to format the way my file runs, so the user input following the line below is not in the same line with the &quot;What's your name?&quot; part, if that makes sense.</p> <p><code>set /p &quot;Playername=What's your name?&quot;</code></p> <p>I tried using:</p> <p><code>/f &quot;eol=\&quot; tokens=3 delims=:{ &quot; %%A in (SType_txt.sys) do echo %%A</code></p> <p>(copy-pasted from somewhere online without fully understanding the contents) and using &quot; \ &quot; as a EOL as shown below,</p> <p><code>set /p &quot;Playername=What's your name?&quot; \</code></p> <p>but that just doesn't work, no error-message or anything, just not doing what I wanted.</p> <p>What can I do to stop the input being positioned right after the question but in the line below?</p>
[ { "answer_id": 74408426, "author": "John Shallow", "author_id": 18195837, "author_profile": "https://Stackoverflow.com/users/18195837", "pm_score": 0, "selected": false, "text": "from collections import Counter\n\n\nlist_ = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\n\n\nif __name__ == '__main__':\n counter = Counter(word[0] for word in list_)\n print(counter.most_common(1)[0][0])\n" }, { "answer_id": 74408430, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 1, "selected": false, "text": "from collections import Counter\nls= [ 'home', 'dog', 'park', 'house', 'hotel', 'fire' ]\nls = [w[0] for w in ls]\n\ns=(Counter(ls))\n\nprint(max(s, key=s.get))\n" }, { "answer_id": 74408433, "author": "DeusDev", "author_id": 10312417, "author_profile": "https://Stackoverflow.com/users/10312417", "pm_score": 1, "selected": false, "text": "collections.Counter" }, { "answer_id": 74408434, "author": "yutytuty", "author_id": 11412148, "author_profile": "https://Stackoverflow.com/users/11412148", "pm_score": 2, "selected": false, "text": "lst = ['home', 'dog', 'park', 'house', 'hotel', 'fire']\nmax([item[0] for item in lst], key=lst.count)\n" }, { "answer_id": 74408446, "author": "James_481", "author_id": 13633328, "author_profile": "https://Stackoverflow.com/users/13633328", "pm_score": 1, "selected": false, "text": "from statistics import mode\ndef most_common_first_letter(words):\n first_letters = []\n for word in words:\n first_letters.append(word[0])\n return mode(first_letters)\n \n" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20481140/" ]
74,408,356
<p>I'm currently reading a book and I'm stuck right at the start of a particularly chapter. Because of where I'm stuck, <a href="https://www.oreilly.com/library/view/c-10-in/9781098121945/ch09.html" rel="nofollow noreferrer">the context</a> can be found online without breaching the paywall. The relevant codeblock is this:</p> <pre class="lang-cs prettyprint-override"><code>public class NutshellContext : DbContext { public DbSet&lt;Customer&gt; Customers { get; set; } public DbSet&lt;Purchase&gt; Purchases { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity&lt;Customer&gt;(entity =&gt; { entity.ToTable(&quot;Customer&quot;); entity.Property(e =&gt; e.Name).IsRequired(); // Column is not nullable }); modelBuilder.Entity&lt;Purchase&gt;(entity =&gt; { entity.ToTable(&quot;Purchase&quot;); entity.Property(e =&gt; e.Date).IsRequired(); entity.Property(e =&gt; e.Description).IsRequired(); }); } } public class Customer { public int ID { get; set; } public string Name { get; set; } public virtual List&lt;Purchase&gt; Purchases { get; set; } = new List&lt;Purchase&gt;(); } public class Purchase { public int ID { get; set; } public int? CustomerID { get; set; } public DateTime Date { get; set; } public string Description { get; set; } public decimal Price { get; set; } public virtual Customer Customer { get; set; } } </code></pre> <p>The bit where I'm suck is here</p> <pre class="lang-cs prettyprint-override"><code>modelBuilder.Entity&lt;Customer&gt;(entity =&gt; { entity.ToTable(&quot;Customer&quot;); entity.Property(e =&gt; e.Name).IsRequired(); // Column is not nullable }); </code></pre> <p>My questions are as follows:</p> <ol> <li><code>modelBuilder.Entity&lt;Customer&gt;</code> appears to be a function call. What does it mean to place a lambda expression inside a function call?</li> <li>What is <code>entity</code> and why is it in scope? If it is just a free variable, then where in the documentation for <code>modelBuilder.Entity&lt;T&gt;</code> does it say that it can take such a construction as an input?</li> <li>The above two questions, but for the <code>Property(e =&gt; e.Name)</code> piece of code.</li> <li>If <code>modelBuilder.Entity&lt;Customer&gt;</code> isn't a function call, then what is it?</li> </ol>
[ { "answer_id": 74408483, "author": "Denis", "author_id": 14202100, "author_profile": "https://Stackoverflow.com/users/14202100", "pm_score": 0, "selected": false, "text": "modelBuilder.Entity<Customer>" }, { "answer_id": 74439613, "author": "jomsk1e", "author_id": 1638261, "author_profile": "https://Stackoverflow.com/users/1638261", "pm_score": 0, "selected": false, "text": "modelBuilder.Entity<Customer>().ToTable(\"Customer\").Property(e => e.Name).IsRequired();\n" }, { "answer_id": 74492291, "author": "thunderkill", "author_id": 10670947, "author_profile": "https://Stackoverflow.com/users/10670947", "pm_score": 0, "selected": false, "text": "modelBuilder.Entity<Customer>" }, { "answer_id": 74517729, "author": "Matteo Umili", "author_id": 2541809, "author_profile": "https://Stackoverflow.com/users/2541809", "pm_score": 2, "selected": true, "text": "modelBuilder.Entity<Customer>" } ]
2022/11/11
[ "https://Stackoverflow.com/questions/74408356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10319707/" ]