qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,143,798
<p>I would like to know how to pass a vector of text into a string within R.</p> <hr /> <p>I have a list of emails stored as a character vector:</p> <pre><code>all.emails &lt;- list( c('email_1@emailaddress_1.com', 'email_2@emailaddress_2.com', 'email_3@emailaddress_3.com', 'email_r@emailaddress_n.com' ) ) </code></pre> <p>Also within R, I have some SQL code stored as a string that I will pass to our database via a database connection in R. To do this, I created a string that is the query written in SQL but I want to pass the emails above into the string below so I can query the database only for those emails.</p> <p>The SQL query will look something like this:</p> <pre><code>sql &lt;- &quot; 1&gt; SELECT column_1, column_2,..., column_n 2&gt; FROM name.of.table 3&gt; WHERE toaddress = '[this is where to pass the email list above into]'. &quot; </code></pre> <p>It is line 3 where I need to pass my email list into.</p> <p>Any help will be appreciated.</p>
[ { "answer_id": 74143888, "author": "langtang", "author_id": 4447540, "author_profile": "https://Stackoverflow.com/users/4447540", "pm_score": 2, "selected": false, "text": "sql = paste0(\n \"SELECT column_1, column_2,..., column_n \",\n \"FROM name.of.table \",\n \"WHERE toaddress IN ...
2022/10/20
[ "https://Stackoverflow.com/questions/74143798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17726639/" ]
74,143,799
<p>I have a simple shell file that has this:</p> <pre><code>#! /bin/bash echo &quot;Hello&quot; echo &quot;Full Name: $1&quot;; echo &quot;Age: $2&quot;; </code></pre> <p>I am calling this file from the python jupyter notebook like this:</p> <pre><code>import subprocess filePath = 'testScript.sh' arg1 = 'John Doe' arg2 = 2 subprocess.run([filePath, arg1, str(arg2)], shell=True, check=True) </code></pre> <p>The file runs fine and I get this output:</p> <pre><code>CompletedProcess(args=['testScript.sh', 'John Doe', '2'], returncode=0) </code></pre> <p>While the code is running, it pops open a command line window and the output flashes for a second before the window closes. I was wondering is there a way to print output into python rather than only seeing the output in the command line window? Or is there a way to prevent the command line window from closing so I can see the output?</p>
[ { "answer_id": 74143897, "author": "learner", "author_id": 17658327, "author_profile": "https://Stackoverflow.com/users/17658327", "pm_score": 0, "selected": false, "text": "subdir = ... #<========= Path of executable\n\nfout = open(os.path.join(subdir, \"out.txt\"), \"w\")\nferr = open(...
2022/10/20
[ "https://Stackoverflow.com/questions/74143799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5977110/" ]
74,143,811
<p>For a given set of words, I would like to get all the words in between inclusively. For example : words = ['word1', 'word2', 'word3']</p> <blockquote> <p>Lorem ipsum dolor sit <em><strong>word2</strong>, consectetur adipiscing elit. <strong>word3</strong> tristique in dolor vel consequat. Nulla tincidunt suscipit molestie. Suspendisse mauris turpis, ultricies pulvinar facilisis <strong>word1</strong></em>, vulputate sit amet . Donec cursus odio ut ipsum rutrum faucibus. Ut accumsan arcu ac ex scelerisque, ac sodales metus dictum. Nam efficitur velit sed lorem pharetra commodo. Morbi velit massa, feugiat nec ligula nec, finibus tincidunt nulla. Nulla a suscipit elit. Proin in nibh nec ipsum eleifend tempor. .</p> </blockquote> <p>The words in Italic should be a match.</p>
[ { "answer_id": 74144098, "author": "Roberto Vallejo", "author_id": 16291664, "author_profile": "https://Stackoverflow.com/users/16291664", "pm_score": -1, "selected": false, "text": "\"hello from somewhere, this is a nice place\".match(/(hello|this)/gi)\n" }, { "answer_id": 74144...
2022/10/20
[ "https://Stackoverflow.com/questions/74143811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8434474/" ]
74,143,818
<p>I'm placing a bunch of images on a grid in the center of the page and want to add a check for when each individual image is clicked. The images are created with js and added to the document, could it be an issue of them not being 'ready' yet or something?</p> <pre class="lang-js prettyprint-override"><code>function placePieces() { for (var i = 0; i &lt; setup.length; i++) { if ((setup[i]+'' == &quot;undefined&quot;)) {continue;} var element = document.createElement(&quot;img&quot;); element.src = &quot;Images/&quot; + pieces[Object.keys(pieces)[setup[i]]] + &quot;.png&quot;; element.style.width = &quot;10vh&quot;; element.style.height = &quot;10vh&quot;; element.style.marginTop = (Math.floor(i/8) * 10) + &quot;vh&quot;; element.style.marginLeft = &quot;calc(((100vw - 80vh)/2) + &quot; + (10 * (i%8) - 1) + &quot;vh)&quot;; element.style.zIndex = 10; element.style.position = &quot;absolute&quot;; element.id = i+1; document.body.innerHTML = &quot;\n&quot; + element.outerHTML + document.body.innerHTML; console.log(element.outerHTML) var nelement = document.getElementById(i+1); console.log(nelement) nelement.addEventListener(&quot;click&quot;,highlight); } } placePieces() function highlight(n) { console.log(n) n = n.currentTarget.myParam; if (setup[n] == 0 || setup[n] == 6) { var moves = []; var m = n while (True) { if (!(Math.floor((m-9)/8)&lt;=0)) { console.log(&quot;test&quot;) } } } } </code></pre> <p>The second function is far from finished but it still does not return anything when it should.</p>
[ { "answer_id": 74144280, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 2, "selected": false, "text": "const element = document.createElement('div')\nelement.style.background = 'red'\nelement.style.width = '100px'\neleme...
2022/10/20
[ "https://Stackoverflow.com/questions/74143818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17039302/" ]
74,143,836
<p>I'm working with an array like this one :</p> <pre><code>var table = ['view-only-access', 'restricted-access', 'full-access']; </code></pre> <p>I wanted to find the index by only string like <code>'view' , 'restricted', or 'full'.</code> I have tried the .indexOf() but it requires the full string. does anyone know how to do this ?</p>
[ { "answer_id": 74143865, "author": "Andrew Parks", "author_id": 5898421, "author_profile": "https://Stackoverflow.com/users/5898421", "pm_score": 0, "selected": false, "text": "var table = ['view-only-access', 'restricted-access', 'full-access'];\n\nconsole.log(table.findIndex(i=>i.inclu...
2022/10/20
[ "https://Stackoverflow.com/questions/74143836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9131311/" ]
74,143,837
<p>I'm not clear how to search for this, if there's a duplicate feel free to point me to it.</p> <p>I'm wondering if there's a way to tell mysql that something will be sorted before filtering so that it can perform the filter with a binary search instead of a linear search.</p> <p>For example, consider a table with columns id, value, and created_at id is an auto-increment and created_at is a timestamp field with default of CURRENT_TIMESTAMP</p> <p>then consider the following query:</p> <pre><code>SELECT * FROM `table` WHERE created_at BETWEEN '2022-10-05' AND '2022-10-06' ORDER BY id </code></pre> <p>Because I have context on the data that mysql doesn't, namely that if id is sorted then created_at will also be sorted, I can conclude that we can binary search on created_at. However mysql does a full table scan for the filter as it's unaware of, or unwilling to assume this fact. The explain on the query on my test dataset shows that it's scanning all 50 rows to return the 24 that match the filter, when it's possible to do it by only scanning approximately <code>log2(50)</code> rows. This isn't a huge difference for my test dataset but on larger data it can have an impact.</p> <p>I'll note that the obvious answer here is to add an index on created_at, but on more real life queries that's not always possible. For example if you were filtering on another indexed column it wouldn't be able to use that created_at index, but we might still be able to make assumptions about the ordering based on other order bys.</p> <p>Anyway, after all that setup my question is: Is there a way that I can tell MySQL that I know that this data is already sorted so that it need not perform a table scan? Something similar to <code>FORCE INDEX</code> that can be used to overwrite the behaviour of picking an index for a query</p>
[ { "answer_id": 74144024, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "created_at" }, { "answer_id": 74144124, "author": "Schwern", "author_id": 14660, "author_profile...
2022/10/20
[ "https://Stackoverflow.com/questions/74143837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1624202/" ]
74,143,867
<p>I'm building a sidebar with the Transition and Dialog Headless UI components.</p> <p><a href="https://headlessui.com/react/transition" rel="nofollow noreferrer">Transition docs</a></p> <p>When I break out the code that's passed between &lt;Transition.Child&gt; to it's own component. I get this error:</p> <pre><code>Unhandled Runtime Error Error: Did you forget to passthrough the `ref` to the actual DOM node? Call Stack eval node_modules/@headlessui/react/dist/components/transitions/transition.js (1:3632) </code></pre> <p>Failing code:</p> <pre><code>&lt;Transition.Child as={Fragment}&gt; &lt;Cart cancelButtonReference={cancelButtonReference} setCartOpen={setCartOpen} checkoutUrl={checkoutUrl} removeCartItem={removeCartItem} clearCart={clearCart} cartLoading={cartLoading} incrementCartItem={incrementCartItem} decrementCartItem={decrementCartItem} cartTotal={cartTotal} cart={cart} /&gt; &lt;/Transition.Child&gt; </code></pre> <p>Working code:</p> <pre><code>&lt;Transition.Child as={Fragment}&gt; &lt;div&gt; ... &lt;/div&gt; &lt;/Transition.Child&gt; </code></pre> <p>I understand the error I believe, which is that when I break out the code to it's own component Transition.Child wants me to pass a ref so that React knows that it should render a component and not a fragment.</p> <p>If I remove as={Fragment}, which makes the Transition default to a div the error goes away, but then I get an unneeded div..</p> <p>What ref do I need to pass? This is what I don't get.</p>
[ { "answer_id": 74144024, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "created_at" }, { "answer_id": 74144124, "author": "Schwern", "author_id": 14660, "author_profile...
2022/10/20
[ "https://Stackoverflow.com/questions/74143867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11826960/" ]
74,143,896
<p>I need to merge the payload if the reference number(refNo) is the same in different messages. My limitation is that I can only use a <code>KTable</code> and if the key is an <strong>even number</strong> I don't need to merge the payload. Additionally, the order of incoming messages should not change the result.</p> <p>For example, if we have an empty topic and incoming messages are:</p> <pre><code>1: { key: &quot;1&quot;, value: {refNo:1, payload:{data1}} } 2: { key: &quot;2&quot;, value: {refNo:1, payload:{data2}} } 3: { key: &quot;3&quot;, value: {refNo:2, payload:{data3}} } // this one should be not effected and left how it is </code></pre> <p>Expected result: <br /></p> <pre><code>1: { key: &quot;1&quot;, value: {refNo:1, payload:{data1, data2}} } 2: { key: &quot;2&quot;, value: {refNo:1, payload:{data2}} } 3: { key: &quot;3&quot;, value: {refNo:2, payload:{data3}} } </code></pre> <p>The only way I can think of to do this is to use two times <code>.groupBy</code> and join with the original topic everything again.</p> <ol> <li>First change the key to <code>refNo</code>, save the key to the value itself, and join the payload during aggregation.</li> <li>Secondly <code>.groupBy</code> revert key to the initial state.</li> <li>The last step joins everything to the original topic because I lost one message during grouping by.</li> </ol> <p>I'm pretty sure there's an easier way to do this. What is the most optimized and elegant way to solve this issue?</p> <p>Edit: Its downstream and there is output topic, original is not edited.</p>
[ { "answer_id": 74144024, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "created_at" }, { "answer_id": 74144124, "author": "Schwern", "author_id": 14660, "author_profile...
2022/10/20
[ "https://Stackoverflow.com/questions/74143896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9918701/" ]
74,143,905
<p>I want to re-render a function after array values changes(i.e swap) but useeffect is not re-rendering it. Do not worry about the external components.Can you help me to this as i i want to add this code in my major project. I have attached the jsx and css file. In App.js file i am making a bar graph using the array and trying to re-render the bar() function after swapping the values.</p> <pre><code>import './App.css'; import &quot;./components/Bar&quot;; import Bar from './components/Bar'; import Footer from './components/Footer'; import Header from './components/Header'; import {useEffect} from 'react'; function App() { function bar(){ return ( arr.map((val, idx) =&gt; ( &lt;div className='element-bar' // key={idx} style={{ height: `${val}px`, width: `${wid}px`, backgroundColor: &quot;red&quot;, WebkitTransition: `background-color ${delay}ms linear`, msTransition: `background-color ${delay}ms linear`, transition: `background-color ${delay}ms linear`, transition: `${delay}ms` }} &gt; &lt;/div&gt; )) ) } var arr = [10, 20, 30, 40, 50, 60]; useEffect(() =&gt; { console.log(1); bar(); },[arr,bar]); function swap(x,y){ var t = x; x = y; y = t; } function change(){ console.log(arr); swap(arr[0],arr[4]); } const wid = 4; const delay = 2; return ( &lt;div&gt; &lt;Header/&gt; &lt;button onClick={change} style={{ color: 'red' }}&gt;Swap&lt;/button&gt; &lt;Bar/&gt; &lt;div className='array'&gt; { bar() } &lt;/div&gt; &lt;Footer/&gt; &lt;/div&gt; ); } export default App; </code></pre> <p>CSS</p> <pre><code>body { background-color: black; } .array { position: fixed; text-align: center; left: 250px; top: auto; bottom: 50px; display: flex; align-items: flex-end; flex-wrap: nowrap; width: 1260px; } .element-bar { display: inline-block; margin: 0 auto; } .sideNavbar { text-align: center; height: 100%; width: 210px; position: fixed; z-index: 1; top: 0; left: 0; background-color: rgb(29, 29, 29); overflow-x: hidden; padding-top: 20px; box-shadow: 0 4px 8px 0 rgba(81, 81, 81, 0.7), 0 6px 20px 0 rgb(81, 81, 81,0.7); } .sideNavbar h3 { font-size: 23px; text-decoration: underline; color: #818181; display: block; transition: 0.4s; } .sideNavbar h3:hover { color: #f1f1f1; } .sliderLabel { color: #f1f1f1; } .btn { margin: 10px 0; display: inline-block; padding: 6px; width: 100px; color: #818181; font-weight: 400; border: 2px solid #818181; background-color: transparent; text-transform: uppercase; cursor: pointer; border-radius: 100px; transition: 0.4s; } .btn:hover { color: #f1f1f1; border: 2px solid #f1f1f1; box-shadow: 0 12px 16px 0 rgba(81, 81, 81, 0.7), 0 17px 50px 0 rgba(81, 81, 81, 0.7); text-shadow: 0 12px 16px 0 rgba(81, 81, 81, 0.7), 0 17px 50px 0 rgba(81, 81, 81, 0.7); } .btndisabled { margin: 10px 0; display: inline-block; padding: 6px; width: 100px; border-radius: 100px; font-weight: 400; background-color: transparent; cursor: not-allowed; text-transform: uppercase; color: #f1f1f1; border: 2px solid #f1f1f1; box-shadow: 0 12px 16px 0 rgba(81, 81, 81, 0.7), 0 17px 50px 0 rgba(81, 81, 81, 0.7); text-shadow: 0 12px 16px 0 rgba(81, 81, 81, 0.7), 0 17px 50px 0 rgba(81, 81, 81, 0.7); } </code></pre>
[ { "answer_id": 74144024, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "created_at" }, { "answer_id": 74144124, "author": "Schwern", "author_id": 14660, "author_profile...
2022/10/20
[ "https://Stackoverflow.com/questions/74143905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17948088/" ]
74,143,926
<pre><code>void main(int argc,char *argv[]) { for (int i = 0; i &lt; argc; i++) { printf(&quot;%s &quot;, argv[i]); } } </code></pre> <p>when I use command <code>./test 1 2 3</code> in terminal to execute this program, I got result <code>./test 1 2 3</code> ,but when I use function <code>execl(&quot;/usr/src/test&quot;, &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, NULL)</code> in another program I got result <code>1 2 3</code>,why?</p>
[ { "answer_id": 74143985, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 4, "selected": true, "text": "execl()" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74143926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17589476/" ]
74,143,973
<p>I have asked a question why my attempt to do a function chaining did not work: <a href="https://stackoverflow.com/questions/74117157/make-a-function-return-itself-after-doing-some-work">Make a function return itself after doing some work</a>, the answer was: for a function to return itself you need recursive types enabled with <code>-rectypes</code>. This confused me. Why is this feature hidden behind a compiler flag? There must be a good reason not to enable it by default. So my question is: what are the tradeoffs when using this flag? Should I avoid it or can I safely use it for all my code and it is not enabled for compatibility with old code only?</p>
[ { "answer_id": 74144357, "author": "jthulhu", "author_id": 5956261, "author_profile": "https://Stackoverflow.com/users/5956261", "pm_score": 2, "selected": false, "text": "let included l1 l2 = \n let rec mem x = function \n | [] -> false \n | hd::tail -> (tail=x) || (mem x hd) ...
2022/10/20
[ "https://Stackoverflow.com/questions/74143973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1968972/" ]
74,144,004
<p>Not sure how else to word the title, but this is what I need:</p> <p>Print either the number zero, the number one or a phrase in no consecutive order twenty times. This is what I have:</p> <pre><code> n = 0 x = “hello” for i in range(20): print(n, end= ‘’) or print(n+1, end= ‘’) or print(x) </code></pre> <p>The only problem is that it prints them out in order so that it is always 01hello01hello01hello and so on. I need it to be randomized so that it could print something like 000hello1hello101 or just any random variation of the three variables.</p> <p>Let me know how :)</p>
[ { "answer_id": 74144044, "author": "picobit", "author_id": 6030926, "author_profile": "https://Stackoverflow.com/users/6030926", "pm_score": 3, "selected": false, "text": "random" }, { "answer_id": 74144052, "author": "bitflip", "author_id": 20027803, "author_profile"...
2022/10/20
[ "https://Stackoverflow.com/questions/74144004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20115402/" ]
74,144,022
<h2>Background</h2> <p>I have a Playwright test I can run locally with VS Code in all 3 browser engines: Chromium, Firefox, and WebKit. The tests succeed running against both the locally running app and the app deployed to pre-production environments.</p> <p>The test:</p> <pre><code>test('that clicking link navigates to the next page', async ({ page }) =&gt; { await page.goto('/relative/url'); await page.locator('hyperlink:has-text(&quot;relative url&quot;)').getByRole('link').click(); await page.waitForNavigation(); await expect(page).toHaveURL('https://www.example.com/relative/url'); }); </code></pre> <p>The partial <code>Playwright.config.ts</code> file:</p> <pre><code>use: { ... baseURL: 'https://www.example.com', ... }, </code></pre> <p>The app structure:</p> <pre><code>- My app - Deployment - azure-pipelines.yml - src - tests - playwright.config.ts </code></pre> <p>The Azure DevOps pipeline stage, most of which was copied from the <a href="https://playwright.dev/docs/ci#azure-pipelines" rel="nofollow noreferrer">Playwright Azure pipelines documentation</a></p> <pre><code> - stage: PlaywrightTests dependsOn: - PreprodDeployment jobs: - deployment: PlaywrightTests pool: vmImage: ubuntu-20.04 container: mcr.microsoft.com/playwright:v1.27.0-focal environment: testing strategy: runOnce: deploy: steps: - checkout: self - task: NodeTool@0 inputs: versionSpec: '16.13.0' - task: Bash@3 displayName: 'Run Playwright tests' inputs: workingDirectory: 'tests' targetType: 'inline' failOnStderr: true # env: # Unexpected property. Fails pipeline. # CI: true script: | npm install npx playwright test </code></pre> <h2>Problem</h2> <p>However, when Playwright runs my tests from the Azure DevOps pipeline, the test fails.</p> <p>The pipeline failure:</p> <pre><code>1) links.spec.ts:3:1 › that clicking link navigates to the next page =============== page.goto: Protocol error (Page.navigate): Cannot navigate to invalid URL =========================== logs =========================== navigating to &quot;/relative/url&quot;, waiting until &quot;load&quot; ============================================================ 3 | test('that clicking link navigates to the next page', async ({ page }) =&gt; { 4 | &gt; 5 | await page.goto('/relative/url'); | ^ 6 | await page.locator('hyperlink:has-text(&quot;relative url&quot;)').getByRole('link').click(); 7 | await page.waitForNavigation(); 8 | at /__w/1/s/tests/links.spec.ts:5:14 1 failed links.spec.ts:3:1 › that clicking link navigates to the next page ================ ##[error]Bash exited with code '1'. </code></pre> <p>I can see that the pipeline is not using the <code>baseURL</code> value from the <code>playwright.config.ts</code> file.</p> <h2>Question</h2> <p><strong>How do I fix the <code>azure-pipeline.yml</code> so that it uses <code>playwright.config.ts</code>'s <code>baseURL</code> value?</strong></p> <br>
[ { "answer_id": 74144044, "author": "picobit", "author_id": 6030926, "author_profile": "https://Stackoverflow.com/users/6030926", "pm_score": 3, "selected": false, "text": "random" }, { "answer_id": 74144052, "author": "bitflip", "author_id": 20027803, "author_profile"...
2022/10/20
[ "https://Stackoverflow.com/questions/74144022", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5587356/" ]
74,144,043
<p>I have data frame in R that looks like this :</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <td>8</td> <td>-16</td> </tr> <tr> <td>19</td> <td>-26</td> </tr> <tr> <td>30</td> <td>-36</td> </tr> <tr> <td>41</td> <td>-46</td> </tr> <tr> <td>52</td> <td>-56</td> </tr> </tbody> </table> </div> <p>I want to slide it or rollapply it with width 3 in both columns and calculate the the sum of the two minimum.</p> <p>BUT.!!!!</p> <p>I want progressively go tho width 3 starting with width (3+1)/2 = 2 and then go to width 3.</p> <p>In my example must start with the first 2 rows:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">a</th> <th style="text-align: center;">b</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">8</td> <td style="text-align: center;">-16</td> </tr> <tr> <td style="text-align: left;">19</td> <td style="text-align: center;">-26</td> </tr> </tbody> </table> </div> <p>result must be the sum of the minimums of columns a and b 8+(-26)=-18 next</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">a</th> <th style="text-align: center;">b</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">8</td> <td style="text-align: center;">-16</td> </tr> <tr> <td style="text-align: left;">19</td> <td style="text-align: center;">-26</td> </tr> <tr> <td style="text-align: left;">30</td> <td style="text-align: center;">-36</td> </tr> </tbody> </table> </div> <p>result must be the sum of the minimums of columns a and b 8+(-36)=-28</p> <p>next</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> </tr> <tr> <td>19</td> <td>-26</td> </tr> <tr> <td>30</td> <td>-36</td> </tr> <tr> <td>41</td> <td>-46</td> </tr> </tbody> </table> </div> <p>19-46 = -27</p> <p>next</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <td>30</td> <td>-36</td> </tr> <tr> <td>41</td> <td>-46</td> </tr> <tr> <td>52</td> <td>-56</td> </tr> </tbody> </table> </div> <p>30-56 = -26</p> <p>and last</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <td>41</td> <td>-46</td> </tr> <tr> <td>52</td> <td>-56</td> </tr> </tbody> </table> </div> <p>41-56=-15.</p> <p>The width must be 2,3,3,3,2.</p> <p>In general if this data frame had 100 rows with window 13 it will start from top to bottom with window (or width) (13+1)/2 = 7, then it will continue to 8,9,10,12,13,13,...,13,12,11,10,9,8,7.</p> <p>How can I do this in R ?</p> <pre><code>library(tidyverse) a = c(800,1900,3000,4100,5200) b = c(-1600,-2600,-3600,-4600,-5600) w = tibble(a,b) </code></pre>
[ { "answer_id": 74144290, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "rollapply" }, { "answer_id": 74144333, "author": "onyambu", "author_id": 8380272, "author_profile":...
2022/10/20
[ "https://Stackoverflow.com/questions/74144043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16346449/" ]
74,144,056
<p>Product has many product attributes:</p> <pre class="lang-rb prettyprint-override"><code>class Product &lt; ApplicationRecord has_many :product_attributes end class ProductAttribute &lt; ApplicationRecord belongs_to :product end </code></pre> <p>I can sort it with <code>sort_by</code>:</p> <pre class="lang-rb prettyprint-override"><code>@products.includes(:product_attributes).to_a.sort_by do |product| product.product_attributes.find_by(title: &quot;Volume&quot;).value.to_i end </code></pre> <p>Is it possible to make the same sort with <code>order</code> method?<br /> I don’t understand how to order by particular attribute title (like &quot;Volume&quot;, etc).</p> <pre class="lang-rb prettyprint-override"><code>@products = Product.includes(:product_attributes).order( ??? ) </code></pre> <p>Here is similar question:<br /> <a href="https://stackoverflow.com/questions/9197649/rails-sort-by-join-table-data">Rails - Sort by join table data</a><br /> Maybe I don't see the obvious, but I think it doesn't answer my question. I select item not by attribute name, but by attribute value, like &quot;Volume&quot;. In other words, I <code>find_by</code> by attribute's value with title &quot;Volume&quot; (look at the code above). And I don't understand how to make such selection with <code>order</code>.</p>
[ { "answer_id": 74144290, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "rollapply" }, { "answer_id": 74144333, "author": "onyambu", "author_id": 8380272, "author_profile":...
2022/10/20
[ "https://Stackoverflow.com/questions/74144056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9185715/" ]
74,144,081
<p>I am having an issue with a Nan error in my typescript. I have set a variable type to number and loop throuh an element where I get all the different balance amounts. They come in the form of &quot;$...&quot; like $10.00 and $20.00, so I do a replace and then finally include each balance amount into the total sum balance variable.</p> <p>However, in my console log it outputs:</p> <pre><code>Expected: NaN Actual: 20.00 </code></pre> <p>I am not sure why that is. Why does it think it's not a number and how can this be rectified (should show 20.00)</p> <pre><code>balance: Selector; this.balance = Selector('.balance'); this.balanceTotal = Selector('.balance-total '); async validateTotalBalance() { let sumBalanceTotal: number = 0; for (let i = 0; i &lt; (await this.balance.count); i++) { let amount = await this.balance.nth(i).textContent; amount.replace('$', ''); let convertedAmount = Number(amount); convertedAmount.toFixed(2); sumBalanceTotal += convertedAmount; } console.log('Expected: ' + sumBalanceTotal); console.log( 'Actual: ' + (await this.balanceTotal.textContent).replace('$', '') ); } </code></pre>
[ { "answer_id": 74144153, "author": "Roberto Vallejo", "author_id": 16291664, "author_profile": "https://Stackoverflow.com/users/16291664", "pm_score": 1, "selected": false, "text": "toFixed()" }, { "answer_id": 74144169, "author": "Steve V", "author_id": 20284428, "au...
2022/10/20
[ "https://Stackoverflow.com/questions/74144081", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1096892/" ]
74,144,082
<p>I am a beginner and this is what I came up with so far. However, it does not output the correct number of words that end with &quot;a&quot; or &quot;b.&quot; Any tips on how to correct this code?</p> <pre><code>names = input(&quot;Enter list of names: &quot;) name = names.split(&quot; &quot;) num = len(name) ab = &quot;&quot; print(&quot;Number of words:&quot;, num) for i in range(num): if name[i] == ' ': if name[i-1] == a: ab.append() + &quot; &quot; elif name[i-1] == b: ab.append() + &quot; &quot; a_b = ab.split(' ') print(&quot;Number of words that end with a or b: &quot;,len(a_b)) </code></pre>
[ { "answer_id": 74144113, "author": "Jamie.Sgro", "author_id": 11550733, "author_profile": "https://Stackoverflow.com/users/11550733", "pm_score": 1, "selected": false, "text": "words = [\"ab\", \"bab\", \"pa\", \"pap\"]\n\nresult = 0\nfor word in words:\n if word[-1] in \"ab\":\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20177890/" ]
74,144,096
<p>thanks for helping me out this code was very helpful too</p> <pre><code>#include &lt;string&gt; #include &lt;sstream&gt; #include &lt;array&gt; #include &lt;iostream&gt; int main(void) { std::array&lt;int,'Z'-'A'+1&gt; counters{0}; // 26 counters std::string s; std::stringstream fileIn (&quot;Hello world&quot;); // I use a string instead of a file for demo purpose while (fileIn&gt;&gt;s) { if (s.empty()) continue; char c = toupper(s.back()); if ('A' &lt;= c &amp;&amp; c &lt;= 'Z') counters[c-'A']++; } for (char c='A'; c&lt;='Z'; c++) { std::cout &lt;&lt; &quot;There are &quot;&lt;&lt; counters[c-'A'] &lt;&lt;&quot; words that end with &quot; &lt;&lt; c &lt;&lt; std::endl; // std::cout &lt;&lt; std::format(&quot;There are {} words that end with {}&quot;, counters[c-'A'], c) &lt;&lt; std::endl; // C++20 } } </code></pre> <p>thanks for the help every1, i learned alot from ur help</p>
[ { "answer_id": 74144140, "author": "dvbngln", "author_id": 13534297, "author_profile": "https://Stackoverflow.com/users/13534297", "pm_score": 2, "selected": false, "text": "back()" }, { "answer_id": 74144329, "author": "Thomas Weller", "author_id": 480982, "author_pr...
2022/10/20
[ "https://Stackoverflow.com/questions/74144096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14744560/" ]
74,144,116
<p>I'm using material ui select element with added functionality such as multiple selection with checkbox, my question is, is there a way to delete and update name from select element itself ? for example: by clicking the pen next to 'Oliver Hansen' i could update that name or by clicking recycle bin delete that name ?</p> <p>code to try:</p> <p><a href="https://codesandbox.io/s/material-ui-multiple-select-with-select-all-option-forked-nrm6z4?file=/src/App.js" rel="nofollow noreferrer">https://codesandbox.io/s/material-ui-multiple-select-with-select-all-option-forked-nrm6z4?file=/src/App.js</a></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>code: import React, { useState } from "react"; import Checkbox from "@material-ui/core/Checkbox"; import InputLabel from "@material-ui/core/InputLabel"; import ListItemIcon from "@material-ui/core/ListItemIcon"; import ListItemText from "@material-ui/core/ListItemText"; import MenuItem from "@material-ui/core/MenuItem"; import FormControl from "@material-ui/core/FormControl"; import Select from "@material-ui/core/Select"; import DeleteIcon from "@material-ui/icons/Delete"; import CreateIcon from "@material-ui/icons/Create"; import { MenuProps, useStyles, options } from "./utils"; function App() { const classes = useStyles(); const [selected, setSelected] = useState([]); const handleChange = (event) =&gt; { console.log("vals", event.target); const value = event.target.value; setSelected(value); console.log("values", selected); }; return ( &lt;FormControl className={classes.formControl}&gt; &lt;InputLabel id="mutiple-select-label"&gt;Multiple Select&lt;/InputLabel&gt; &lt;Select labelId="mutiple-select-label" multiple variant="outlined" value={selected || []} onChange={handleChange} renderValue={(selected) =&gt; selected} MenuProps={MenuProps} &gt; {options.map((option) =&gt; ( &lt;MenuItem key={option.id} value={option}&gt; &lt;ListItemIcon&gt; &lt;Checkbox checked={selected?.includes(option)} /&gt; &lt;/ListItemIcon&gt; &lt;ListItemText primary={option.title}&gt;{option}&lt;/ListItemText&gt; &lt;DeleteIcon /&gt; &lt;ListItemIcon&gt; &lt;CreateIcon /&gt; &lt;/ListItemIcon&gt; &lt;/MenuItem&gt; ))} &lt;/Select&gt; &lt;p&gt;{selected}&lt;/p&gt; &lt;/FormControl&gt; ); } export default App;</code></pre> </div> </div> </p>
[ { "answer_id": 74144140, "author": "dvbngln", "author_id": 13534297, "author_profile": "https://Stackoverflow.com/users/13534297", "pm_score": 2, "selected": false, "text": "back()" }, { "answer_id": 74144329, "author": "Thomas Weller", "author_id": 480982, "author_pr...
2022/10/20
[ "https://Stackoverflow.com/questions/74144116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17292277/" ]
74,144,120
<p>Trying to solve this problem: keys containing arrays should be named as plurals. then return a new object that is a copy of the input but with any keys that contain arrays pluralized (an 's' added to the end.).</p> <p>My approach is to loop into this new object and figure out whether the key is an array or not(Array.isArray(value). Once done that I have what I need which are the keys: (job, and favoriteShop) now my last step where I am stuck is to replace the default key values (job and favoriteShop) with the new ones which must be (jobs, favoriteShops)</p> <pre><code> function pluraliseKeys(obj) { const newObj = { ...obj }; for (const [key, value] of Object.entries(newObj)) { if (Array.isArray(value)) { console.log(key); *// here I would like to say that the keys (in this case job and favoriteShop are = jobs and favoriteShops)* newObj[key] = key + &quot;s&quot;; //not working } } return newObj; } console.log( pluraliseKeys({ name: &quot;Tom&quot;, job: [&quot;writing katas&quot;, &quot;marking&quot;], favouriteShop: [ &quot;Paul's Donkey University&quot;, &quot;Shaq's Taxidermy Shack&quot;, &quot;Sam's Pet Shop&quot;, ], }) ); </code></pre> <p>I am trying different solutions but with no results.</p> <p>the result should be like:</p> <pre><code>name: 'Tom', jobs: ['writing katas', 'marking'], favouriteShops: [ &quot;Paul's Donkey University&quot;, &quot;Shaq's Taxidermy Shack&quot;, &quot;Sam's Pet Shop&quot; </code></pre> <p>there is a way to achieve this following the way I am doing? or should I need to change the approach?</p> <p>thank you for your support.</p>
[ { "answer_id": 74144140, "author": "dvbngln", "author_id": 13534297, "author_profile": "https://Stackoverflow.com/users/13534297", "pm_score": 2, "selected": false, "text": "back()" }, { "answer_id": 74144329, "author": "Thomas Weller", "author_id": 480982, "author_pr...
2022/10/20
[ "https://Stackoverflow.com/questions/74144120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19459850/" ]
74,144,133
<p>I am trying to delete a folder using robocopy mirroring like this: <code>Start-Process -FilePath &quot;robocopy.exe&quot; -ArgumentList &quot;$emptyDir $sourcePath /mir /e /np /ns /nc /njs /njh /nfl /ndl&quot; -Wait -PassThru -NoNewWindow</code> but still get a line of output for every deleted file <a href="https://i.stack.imgur.com/UrGXb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UrGXb.png" alt="enter image description here" /></a></p> <p>I tried adding <code>&gt;nul 2&gt;&amp;1</code> as explained in another <a href="https://stackoverflow.com/questions/47157426/how-to-silence-robocopy-when-mirroring-directory">answer here</a> <code>Start-Process -FilePath &quot;robocopy.exe&quot; -ArgumentList &quot;$emptyDir $sourcePath /mir /e /np /ns /nc /njs /njh /nfl /ndl &gt;nul 2&gt;&amp;1&quot; -Wait -PassThru -NoNewWindow</code> but still get the same output.</p>
[ { "answer_id": 74144975, "author": "Start-Automating", "author_id": 221631, "author_profile": "https://Stackoverflow.com/users/221631", "pm_score": 1, "selected": false, "text": "$roboFileArgs = @(\n <#\n If you're sure your argument is already a string or\n a primitive type, th...
2022/10/20
[ "https://Stackoverflow.com/questions/74144133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15085168/" ]
74,144,149
<p>I have two classes (Car and Bus) like below</p> <p>with the same property (name)</p> <p>Class 1</p> <pre><code>class Car { public String name; } </code></pre> <p>Class 2</p> <pre><code>class Bus { public String name; } </code></pre> <p>and i have an array of objects of the two classes</p> <pre><code>ArrayList&lt;Object&gt; vehicles = new ArrayList&lt;&gt;(); vehicles.add(new Car(&quot;Fiat&quot;)); vehicles.add(new Car(&quot;Citroen&quot;)); vehicles.add(new Bus(&quot;Ford&quot;)); vehicles.add(new Bus(&quot;Toyota&quot;)); </code></pre> <p>How do I order the array by the name property alphabetically if they are 2 different classes?</p>
[ { "answer_id": 74144215, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 3, "selected": true, "text": "interface NamedVehicle {\n String getName();\n}\n\nclass Car implements NamedVehicle {\n public String name;\n @O...
2022/10/20
[ "https://Stackoverflow.com/questions/74144149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/518657/" ]
74,144,204
<p>How do I replace only the integer values in the ID column with a sequence of consecutive numbers? I'd like any non-integer or NaN cells skipped.</p> <p>Current df:</p> <pre><code> ID AMOUNT 1 0.00 test 5.00 test test 0.00 test 0.00 1 0.00 xx 304.95 x xx 304.95 1 0.00 1 0.00 xxxxx 0.00 1 0.00 xxx 0.00 xx xx 0.00 1 0.00 </code></pre> <p>Desired Outcome:</p> <pre><code> ID AMOUNT 1 0.00 test 5.00 test test 0.00 test 0.00 2 0.00 xx 304.95 x xx 304.95 3 0.00 4 0.00 xxxxx 0.00 5 0.00 xxx 0.00 xx xx 0.00 6 0.00 </code></pre> <p>I tried making a new column using np.arange(len(df)) and then replacing the ID values with that, but it's not giving me the expected outcome.</p> <p>Thank you!</p>
[ { "answer_id": 74144347, "author": "Hyalunar", "author_id": 17781827, "author_profile": "https://Stackoverflow.com/users/17781827", "pm_score": 1, "selected": false, "text": "isinstance(object, class)" }, { "answer_id": 74144402, "author": "mozway", "author_id": 16343464,...
2022/10/20
[ "https://Stackoverflow.com/questions/74144204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8651669/" ]
74,144,235
<p>I want to show a text input field whenever changeEmail is true. So I handleClick to set it to true. However, when I click on a button nothing happens. Would appreciate any help.</p> <pre><code> let changeEmail = false; function handleClick() { console.log(changeEmail) changeEmail = !changeEmail; } $: changeEmail; &lt;/script&gt; &lt;div class=&quot;card&quot;&gt; &lt;div class=&quot;info-column&quot;&gt; &lt;h2&gt;About&lt;/h2&gt; &lt;div class=&quot;info-field&quot;&gt; &lt;h4&gt;Name&lt;/h4&gt; {userModel.firstName} {userModel.lastName} &lt;/div&gt; &lt;div class=&quot;info-field&quot;&gt; &lt;h4&gt;Email&lt;/h4&gt; {#if changeEmail === false} {userModel.email} {:else} &lt;TextInput placeholder=&quot;${userModel.email}&quot;/&gt; {/if} &lt;Button on:click={handleClick}&gt;Edit&lt;/Button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>this is a component that looks like this on page</p> <pre><code>&lt;section&gt; &lt;PersonalSettingsCard userModel={$user}&gt; &lt;/PersonalSettingsCard&gt; &lt;/section&gt; </code></pre>
[ { "answer_id": 74144347, "author": "Hyalunar", "author_id": 17781827, "author_profile": "https://Stackoverflow.com/users/17781827", "pm_score": 1, "selected": false, "text": "isinstance(object, class)" }, { "answer_id": 74144402, "author": "mozway", "author_id": 16343464,...
2022/10/20
[ "https://Stackoverflow.com/questions/74144235", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18032631/" ]
74,144,238
<p>I'm reading about data flows and the benefit seems to be the ability to pull data from source once and that can be reused by all reports.</p> <p>My experience is that the same thing can be achieved by making use of a shared dataset.</p> <p>So what is the practical difference between shared dataset and dataflows?</p>
[ { "answer_id": 74144347, "author": "Hyalunar", "author_id": 17781827, "author_profile": "https://Stackoverflow.com/users/17781827", "pm_score": 1, "selected": false, "text": "isinstance(object, class)" }, { "answer_id": 74144402, "author": "mozway", "author_id": 16343464,...
2022/10/20
[ "https://Stackoverflow.com/questions/74144238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1779091/" ]
74,144,240
<p>I'd like to use <code>Mirror</code>s or some other technology to serialize ADTs.</p> <p>My concrete use case is that I'm serializing messages over a channel. I can model the messages with case classes; that's easy enough. That gives me the following code:</p> <pre><code>sealed trait Message final case class A(a: Int) extends Message final case class B(b: Int, s: String) extends Message def serializeMessage(m: Message) = Tuple.fromProductTyped(m).toList.map(_.serialize) // doesn't work because `m` is a Sum type Primitive = Int | String extension (p: Primitive) def serialize = p match { case i: Int =&gt; s&quot;an Int: $i&quot; case s: String =&gt; s&quot;an String: $s&quot; } </code></pre> <p>As far as I can see, I have two problems:</p> <ul> <li>How can I guarantee at type level that all messsage case classes only include fields that have a <code>serialize</code> method available?</li> <li>How do I convert an <code>m: Message</code> to a generic tuple of &quot;serializables&quot; that I can act on?</li> </ul> <p>I could use <code>match</code>. The core logic is then:</p> <pre><code>def serializeMessage(m: Message) = m match { case a: A =&gt; Tuple.fromProductTyped(a).toList.map(_.serialize) case b: B =&gt; Tuple.fromProductTyped(b).toList.map(_.serialize) } </code></pre> <p>This compiles. Unfortunately, my API has 50+ messages, and I might also want to support usecases other than serialization, so I'd like to automate the derivation. It's perfectly mechanical and very repetitive, so I feel like it &quot;should&quot; be doable.</p>
[ { "answer_id": 74144347, "author": "Hyalunar", "author_id": 17781827, "author_profile": "https://Stackoverflow.com/users/17781827", "pm_score": 1, "selected": false, "text": "isinstance(object, class)" }, { "answer_id": 74144402, "author": "mozway", "author_id": 16343464,...
2022/10/20
[ "https://Stackoverflow.com/questions/74144240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8027549/" ]
74,144,247
<p>I`m trying to disabled 6 buttons when a condition is met. I have given the buttons the same class. Is there a simplest/shorter way to write ;</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>var ButtonCollection = document.getElementsByClassName("button"); function PopUp() { x = L + Y; var Count = 0; MonsterDiv2.addEventListener("click", function () { Count += 1; if (Count == 2) MonsterDiv2.style.display = "none"; ActionList.innerHTML += `&lt;li&gt;.&lt;/li&gt;`; ButtonCollection[0].disabled = false; ButtonCollection[1].disabled = false; ButtonCollection[2].disabled = false; ButtonCollection[3].disabled = false; ButtonCollection[4].disabled = false; ButtonCollection[5].disabled = false; // }); }</code></pre> </div> </div> </p>
[ { "answer_id": 74144395, "author": "Andrii H", "author_id": 16774247, "author_profile": "https://Stackoverflow.com/users/16774247", "pm_score": 0, "selected": false, "text": "enableButtons()" }, { "answer_id": 74144405, "author": "YSLdev", "author_id": 16092295, "auth...
2022/10/20
[ "https://Stackoverflow.com/questions/74144247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20245204/" ]
74,144,253
<p>I am trying to connect CloudSQL from Kubernetes cluster using Cloud proxy with Sidecar container pattern. Both the proxy and Cloudsql containers are in a same pod and they both are successfully running.</p> <p>But the cloudproxy container is always &quot;RUNNING&quot; status and the job is not going in completed state. Because of this, the other jobs are not getting triggered.</p> <p>Can I know the best possible solution to deal with this?</p> <p><a href="https://i.stack.imgur.com/H5BhL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H5BhL.png" alt="enter image description here" /></a></p> <p>Also please find my .yml template.</p> <pre><code> restartPolicy: Never securityContext: {{- toYaml .Values.mysqlSetupJob.podSecurityContext | nindent 8 }} containers: - name: mysql-setup-job image: &quot;{{ .Values.mysqlSetupJob.image.repository }}:{{ .Values.mysqlSetupJob.image.tag }}&quot; imagePullPolicy: {{ .Values.mysqlSetupJob.imagePullPolicy | default &quot;IfNotPresent&quot; }} env: - name: MYSQL_USERNAME value: {{ .Values.global.sql.datasource.username | quote }} - name: MYSQL_PASSWORD valueFrom: secretKeyRef: name: &quot;{{ .Values.global.sql.datasource.password.secretRef }}&quot; key: &quot;{{ .Values.global.sql.datasource.password.secretKey }}&quot; - name: MYSQL_HOST value: {{ .Values.global.sql.datasource.hostForMysqlClient | quote }} - name: MYSQL_PORT value: {{ .Values.global.sql.datasource.port | quote }} {{- with .Values.mysqlSetupJob.extraEnvs }} {{- toYaml . | nindent 12 }} {{- end }} securityContext: {{- toYaml .Values.mysqlSetupJob.securityContext | nindent 12 }} volumeMounts: {{- with .Values.mysqlSetupJob.extraVolumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} resources: limits: cpu: 500m memory: 512Mi requests: cpu: 300m memory: 256Mi {{- if .Values.cloudsqlProxy.required }} - name: cloud-sql-proxy image: {{ .Values.cloudsqlProxy.image }} command: - &quot;/cloud_sql_proxy&quot; - &quot;-instances={{ .Values.cloudsqlProxy.instance_connection_name }}=tcp:{{ .Values.cloudsqlProxy.port }}&quot; {{- if .Values.gcp.serviceAccount.secretName }} - &quot;-credential_file={{ .Values.gcp.serviceAccount.mountPoint }}/{{ .Values.gcp.serviceAccount.secretKey }}&quot; {{- end }} securityContext: runAsNonRoot: true resources: {{- toYaml .Values.cloudsqlProxy.resources | nindent 12 }} {{- if .Values.gcp.serviceAccount.secretName }} volumeMounts: - name: serviceaccount mountPath: {{ .Values.gcp.serviceAccount.mountPoint }} readOnly: true {{- end }} {{- end }} {{- with .Values.mysqlSetupJob.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.mysqlSetupJob.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.mysqlSetupJob.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} </code></pre> <p>{{- end -}}</p>
[ { "answer_id": 74144395, "author": "Andrii H", "author_id": 16774247, "author_profile": "https://Stackoverflow.com/users/16774247", "pm_score": 0, "selected": false, "text": "enableButtons()" }, { "answer_id": 74144405, "author": "YSLdev", "author_id": 16092295, "auth...
2022/10/20
[ "https://Stackoverflow.com/questions/74144253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10601337/" ]
74,144,320
<p>I have been trying to make a fragment fullscreen, but almost every answer on the web has deprecated methods. Even the android official site has a deprecated method <a href="https://developer.android.com/develop/ui/views/layout/immersive" rel="nofollow noreferrer">Link</a>.</p> <p>I'm using kotlin and after following <a href="https://stackoverflow.com/questions/49446881/android-set-full-screen-from-fragment">this</a> answer, I have tried this in fragment.</p> <pre class="lang-kotlin prettyprint-override"><code>override fun onAttach(context: Context) { super.onAttach(context) requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) } override fun onDetach() { super.onDetach() requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) } </code></pre> <p>but the result that I got is this</p> <p><a href="https://i.stack.imgur.com/NSeV9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NSeV9.jpg" alt="enter image description here" /></a></p> <p>You can clearly see navigation and status bars are still there.</p> <p>Can you share the proper and latest way to get fullscreen in fragment?</p>
[ { "answer_id": 74149717, "author": "Adin D", "author_id": 20291569, "author_profile": "https://Stackoverflow.com/users/20291569", "pm_score": 1, "selected": false, "text": " <style name=\"AppTheme\"parent=\"Theme.MaterialComponents.DayNight.NoActionBar\">\n <item name=\"android:win...
2022/10/20
[ "https://Stackoverflow.com/questions/74144320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13622207/" ]
74,144,343
<p>I have two models that look like this:</p> <pre><code>class TeamMember(models.Model): member = models.ForeignKey(User, on_delete=models.SET(get_default_team_member), verbose_name='Member Name', related_name=&quot;team_members&quot;) team = models.ManyToManyField('Team', verbose_name='Team Name', related_name=&quot;team_members&quot;, blank=False, default=team_id) shift = models.ForeignKey(Shift, on_delete=models.PROTECT) ... class Team(models.Model): name = models.CharField(max_length=50) members = models.ManyToManyField(TeamMember, blank=True, related_name=&quot;members&quot;) ` </code></pre> <p>The users use the admin panel to add new members. When adding a new member, I want to automatically add the member to the associated team.</p> <p>For example, when adding John, it is required to assign a team to him(blank=False), and the team is from what we have in the Team model. Then how do I update the members in the Team model to add John to one of the teams accordingly?</p>
[ { "answer_id": 74149717, "author": "Adin D", "author_id": 20291569, "author_profile": "https://Stackoverflow.com/users/20291569", "pm_score": 1, "selected": false, "text": " <style name=\"AppTheme\"parent=\"Theme.MaterialComponents.DayNight.NoActionBar\">\n <item name=\"android:win...
2022/10/20
[ "https://Stackoverflow.com/questions/74144343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10602570/" ]
74,144,348
<p>New to learning typescript- trying to complete this problem from <a href="https://www.executeprogram.com/courses/typescript-basics/quizzes/add-or-subtract" rel="nofollow noreferrer">execute program</a>:</p> <blockquote> <p>Write a function that adds or subtracts 1 from a number. Argument 1 is the number. Argument 2 is a boolean. When it's true, add; otherwise, subtract.</p> </blockquote> <p>Have tried many variations of the following:</p> <pre><code>function addOrSubtract(x: number, y: boolean): any { if (y = true) { return x+1; } else { return x-1; } return x; } addOrSubtract(5, true); addOrSubtract(5, false); </code></pre> <p>The issue i am having is the test is only picking up the first condition. Specifying when y is false with an <code>else if (y = false)</code> statement gives me the same results.</p> <p><a href="https://i.stack.imgur.com/UaF0c.png" rel="nofollow noreferrer">Four tests results: addOrSubtract(5, true); Expected: 6 OK! addOrSubtract(5, false); Expected: 4 but got: 6 addOrSubtract('5', true); Expected: type error OK! addOrSubtract('5', null); Expected: type error OK!</a></p> <p>Thanks in advance</p>
[ { "answer_id": 74144421, "author": "Aman Mehta", "author_id": 13378772, "author_profile": "https://Stackoverflow.com/users/13378772", "pm_score": 3, "selected": true, "text": "=" }, { "answer_id": 74144556, "author": "Archigan", "author_id": 14333778, "author_profile"...
2022/10/20
[ "https://Stackoverflow.com/questions/74144348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294294/" ]
74,144,375
<p>Note that class x and y are two separate entities and you can not see their private data members from outside of their bodies.</p> <p>It is known that from int main() I can not see the private member of class x or y.</p> <p>My question in the following code in line 22:</p> <p>Why class x can see the private members of class y ? (note here I am sending class y as reference not as a copy) isn't the referenced class y should be protected from strangers like class x ?</p> <p>Note that the function getForeignNumber(const Player &amp;r) inside class x is not a friend to class y!</p> <pre><code>#include&lt;iostream&gt; class Account{ private: int number{ } ; public: Account(int numberValue) :number{numberValue} { std::cout&lt;&lt;&quot;constructor is called&quot;&lt;&lt;std::endl; } int getLocalNumber() { return this-&gt;number; } int getForeignNumber(const Account &amp;r) { return r.number; // line 22 } }; int main() { Account x{1}; Account y{2}; std::cout&lt;&lt;&quot;get local number=&quot;&lt;&lt;x.getLocalNumber()&lt;&lt;std::endl; std::cout&lt;&lt;&quot;get foreign number x =&quot;&lt;&lt;x.getForeignNumber(x)&lt;&lt;std::endl; std::cout&lt;&lt;&quot;get foreign number y=&quot;&lt;&lt;y.getForeignNumber(y)&lt;&lt;std::endl; std::cout&lt;&lt;&quot;Hello world&quot;&lt;&lt;std::endl; return 0; } </code></pre>
[ { "answer_id": 74144479, "author": "463035818_is_not_a_number", "author_id": 4117728, "author_profile": "https://Stackoverflow.com/users/4117728", "pm_score": 3, "selected": true, "text": "x" }, { "answer_id": 74144630, "author": "Keith Thompson", "author_id": 827263, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19359722/" ]
74,144,380
<p>How can I draw the line showing in the picture below? <a href="https://i.stack.imgur.com/pC5bV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pC5bV.jpg" alt="enter image description here" /></a></p> <p>my current page looks like this: <a href="https://i.stack.imgur.com/5tx4X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5tx4X.jpg" alt="enter image description here" /></a></p> <p>I want to add that line at the top with the same title (just to mention I'm using bootstrap 5)</p> <pre><code>&lt;div class=&quot;container-fluid fixed-bottom&quot; style=&quot;margin-bottom: 16px;&quot;&gt; &lt;div class=&quot;row align-items-center&quot; style=&quot;margin-left: 196px; margin-right: 196px;&quot;&gt; &lt;div class=&quot;col align-items-center d-flex justify-content-center&quot;&gt; &lt;div class=&quot;text-center bottomElement&quot;&gt; &lt;img class=&quot;img-fluid bottomIcon&quot; src=&quot;/assets/business.png&quot; width=&quot;56px&quot; height=&quot;56px&quot; /&gt; &lt;p class=&quot;bottomText&quot; style=&quot;color: white;&quot;&gt;Business&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col align-items-center d-flex justify-content-center&quot;&gt; &lt;div class=&quot;text-center bottomElement&quot;&gt; &lt;img class=&quot;img-fluid bottomIcon&quot; src=&quot;/assets/calculator.png&quot; width=&quot;56px&quot; height=&quot;56px&quot; /&gt; &lt;p class=&quot;bottomText&quot; style=&quot;color: white;&quot;&gt;Calculator&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col align-items-center d-flex justify-content-center&quot;&gt; &lt;div class=&quot;text-center bottomElement&quot;&gt; &lt;img class=&quot;img-fluid bottomIcon&quot; src=&quot;/assets/oogPermits.png&quot; width=&quot;56px&quot; height=&quot;56px&quot; /&gt; &lt;p class=&quot;bottomText&quot; style=&quot;color: white;&quot;&gt;OOG Permits&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col align-items-center d-flex justify-content-center&quot;&gt; &lt;div class=&quot;text-center bottomElement&quot;&gt; &lt;img class=&quot;img-fluid bottomIcon&quot; src=&quot;/assets/services.png&quot; width=&quot;56px&quot; height=&quot;56px&quot; /&gt; &lt;p class=&quot;bottomText&quot; style=&quot;color: white;&quot;&gt;Services&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col align-items-center d-flex justify-content-center&quot;&gt; &lt;div class=&quot;text-center bottomElement&quot;&gt; &lt;img class=&quot;img-fluid bottomIcon&quot; src=&quot;/assets/career.png&quot; width=&quot;56px&quot; height=&quot;56px&quot; /&gt; &lt;p class=&quot;bottomText&quot; style=&quot;color: white;&quot;&gt;Career&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
[ { "answer_id": 74144479, "author": "463035818_is_not_a_number", "author_id": 4117728, "author_profile": "https://Stackoverflow.com/users/4117728", "pm_score": 3, "selected": true, "text": "x" }, { "answer_id": 74144630, "author": "Keith Thompson", "author_id": 827263, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220048/" ]
74,144,428
<p>I want to make it so when someone clicks the escape key it will hide the tag. how would I do that? Here is my current code:</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>boxid = "div"; hidden = "false"; window.onkeyup = function(event) { if (event.keyCode == 27) &amp;&amp; hidden = "true" { document.getElementById(boxid).style.visibility = "block"; hidden = "false" } } window.onkeyup = function(event) { if (event.keyCode == 27) &amp;&amp; hidden = "true" { document.getElementById(boxid).style.visibility = "hidden"; hidden = "true" } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;center id="div"&gt; &lt;div style="width: 100%;position: fixed;background: white;display: flex;justify-content: center;align-items: center;text-align: center;overflow: hidden;"&gt; &lt;a href="home"&gt; &lt;img src="https://www.freeiconspng.com/thumbs/homepage-icon-png/house-icon-png-white-32.png" width="35px" height="35px"&gt; &lt;/a&gt; &lt;/center&gt;</code></pre> </div> </div> </p> <p>Thank you all for the help! i got many answers, I didn't notice everything I did wrong, I will check the answers and see what works! Sorry if I wasn't clear, I was just trying to hide the tag.</p>
[ { "answer_id": 74144479, "author": "463035818_is_not_a_number", "author_id": 4117728, "author_profile": "https://Stackoverflow.com/users/4117728", "pm_score": 3, "selected": true, "text": "x" }, { "answer_id": 74144630, "author": "Keith Thompson", "author_id": 827263, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18840569/" ]
74,144,436
<p>Find all the url links in a html text using regex Arguments. below text assigned to html vaiable.</p> <pre><code>html = &quot;&quot;&quot; &lt;a href=&quot;#fragment-only&quot;&gt;anchor link&lt;/a&gt; &lt;a id=&quot;some-id&quot; href=&quot;/relative/path#fragment&quot;&gt;relative link&lt;/a&gt; &lt;a href=&quot;//other.host/same-protocol&quot;&gt;same-protocol link&lt;/a&gt; &lt;a href=&quot;https://example.com&quot;&gt;absolute URL&lt;/a&gt; &quot;&quot;&quot; </code></pre> <p>output should be like that:</p> <pre><code>[&quot;/relative/path&quot;,&quot;//other.host/same-protocol&quot;,&quot;https://example.com&quot;] </code></pre> <p>The function should ignore fragment identifiers (link targets that begin with #). I.e., if the url points to a specific fragment/section using the hash symbol, the fragment part (the part starting with #) of the url should be stripped before it is returned by the function</p> <pre><code>//I have tried this bellow one but not working its only give output: [&quot;https://example.com&quot;] urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', html) print(urls) </code></pre>
[ { "answer_id": 74144479, "author": "463035818_is_not_a_number", "author_id": 4117728, "author_profile": "https://Stackoverflow.com/users/4117728", "pm_score": 3, "selected": true, "text": "x" }, { "answer_id": 74144630, "author": "Keith Thompson", "author_id": 827263, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10387282/" ]
74,144,438
<p>Im new to ASP.NET Core and am tasked with creating an app that can import CSV files and basically convert the rows into Data Objects.</p> <p>Ex.</p> <p>Import CSV with Name Address and DOB Insert each record into Customer object</p> <p>This needs to be done from a user uploading the CSV to the web app, so uploading the CSV straight to the SQL DB will not work.</p> <p>Im curious how I approach this as I am new to ASP.NET Core and Razor pages.</p>
[ { "answer_id": 74145321, "author": "Whaaa", "author_id": 19307152, "author_profile": "https://Stackoverflow.com/users/19307152", "pm_score": 1, "selected": false, "text": " public DataTable GetDataTabletFromCSVFile(string path)\n {\n\n DataTable csvData = new DataTable()...
2022/10/20
[ "https://Stackoverflow.com/questions/74144438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16804877/" ]
74,144,447
<p>I have the following pre-commit hook:</p> <pre><code>repos: - repo: https://github.com/pre-commit/mirrors-clang-format rev: v14.0.6 hooks: - id: clang-format </code></pre> <p>While in the past I have seen pre-commit skip over non-CPP files, a coworker just showed me an example with many .js files where it <em>did</em> try to format all of them - resulting in a complete mess.</p> <p>How do I prevent pre-commit or the clang-format itself from running on these files?</p> <p>Or preferably just have it only run on certain extensions (.c/.cpp/.h/.hpp/.cxx/etc)</p> <p>Pre-commit has <code>files</code> but I don't understand how to use it for this (would it be regex?), and I always seem to get something about the formatting wrong. Does it go a nested level under the clang-format line? Or at the same level as it? Or at the uppermost level of &quot;repos&quot;?</p> <p>Would it just be the following?</p> <pre><code>repos: - repo: https://github.com/pre-commit/mirrors-clang-format rev: v14.0.6 hooks: - id: clang-format files: '(some regex here)' </code></pre>
[ { "answer_id": 74144547, "author": "Pierre.Sassoulas", "author_id": 2519059, "author_profile": "https://Stackoverflow.com/users/2519059", "pm_score": 0, "selected": false, "text": "type_or" }, { "answer_id": 74145714, "author": "anthony sottile", "author_id": 812183, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5403466/" ]
74,144,454
<p>I am trying the ransom note challenge:</p> <p>Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.</p> <p>Each letter in magazine can only be used once in ransomNote.</p> <p>Example 1:</p> <p>Input: ransomNote = &quot;a&quot;, magazine = &quot;b&quot; Output: false Example 2:</p> <p>Input: ransomNote = &quot;aa&quot;, magazine = &quot;ab&quot; Output: false Example 3:</p> <p>Input: ransomNote = &quot;aa&quot;, magazine = &quot;aab&quot; Output: true</p> <p>here is my solution:</p> <pre><code>public static boolean canConstruct(String ransomNote, String magazine) { ArrayList&lt;Character&gt; ransomChar = new ArrayList&lt;Character&gt;(); ArrayList&lt;Character&gt; magazineChar = new ArrayList&lt;Character&gt;(); if (ransomNote.length() == 1 &amp;&amp; magazine.length() == 1) { if (ransomNote.equals(magazine)) { return true; } return false; } else if (ransomNote.length() == 1 &amp;&amp; magazine.length() &gt; 1) { for (int i = 0; i &lt; magazine.length(); i++) { if (magazine.charAt(i) == ransomNote.charAt(0)) { return true; } } return false; } else if (ransomNote.length() &gt; 1 &amp;&amp; magazine.length() &gt; 1) { for (int i = 0; i &lt; ransomNote.length(); i++) { ransomChar.add(ransomNote.charAt(i)); } for (int i = 0; i &lt; magazine.length(); i++) { magazineChar.add(magazine.charAt(i)); } while (ransomChar.size() &gt; 1) { for (int i = 0; i &lt; ransomChar.size(); i++) { boolean flag = false; for (int j = 0; j &lt; magazineChar.size(); j++) { if (ransomChar.get(i).equals(magazineChar.get(j))) { ransomChar.remove(i); magazineChar.remove(j); flag = true; } else if (ransomChar.isEmpty()) { return true; } } if (!flag) { return false; } } } if (ransomChar.size() == 1 &amp;&amp; magazineChar.size() == 1) { if (ransomChar.equals(magazineChar)) { return true; } return false; } else if (ransomChar.size() == 1 &amp;&amp; magazineChar.size() &gt; 1) { for (int i = 0; i &lt; magazineChar.size(); i++) { if (ransomChar.get(0).equals(magazineChar.get(i))) { return true; } } return false; } } return false; } </code></pre> <p>I am passing most test cases but it throws an error at input:</p> <pre><code> &quot;bg&quot; &quot;efjbdfbdgfjhhaiigfhbaejahgfbbgbjagbddfgdiaigdadhcfcj&quot; </code></pre> <p>It throws error:</p> <pre><code>java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 at line: if (ransomChar.get(i).equals(magazineChar.get(j))) </code></pre>
[ { "answer_id": 74144888, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 0, "selected": false, "text": " for (int i = 0; i < ransomChar.size(); i++) {\n boolean flag = false;\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294358/" ]
74,144,482
<p>Hopefully this is an easy one...</p> <p>I am having an issue with Bootstrap 5 floating labels not working when I create HTML elements using Razor syntax.</p> <p>If I use plain HTML they work as expected. Using razor the labels are appearing in the state you'd expect if the text box has focus (top left of input)</p> <pre><code>&lt;div class=&quot;form-floating mb-3&quot;&gt; @Html.EditorFor(model =&gt; model.Recipient, new { htmlAttributes = new { @class = &quot;form-control&quot;, @onchange = &quot;javascript: Changed( this, 'recipient-name' );&quot; } }) @Html.ValidationMessageFor(model =&gt; model.Recipient, &quot;&quot;, new { @class = &quot;text-danger&quot; }) @Html.LabelFor(model =&gt; model.Recipient) &lt;/div&gt; </code></pre> <p>Here is an image of the above on load - <a href="https://i.stack.imgur.com/cpCwS.png" rel="nofollow noreferrer">Code output in UI</a></p> <p>Has anyone had this issue, know a way to get around it or spot what I am doing wrong? (I need the input tag to be populated from the model as the form can be used to create a new request or update and existing request)</p> <p>Thanks</p>
[ { "answer_id": 74144888, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 0, "selected": false, "text": " for (int i = 0; i < ransomChar.size(); i++) {\n boolean flag = false;\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6019948/" ]
74,144,493
<p>I am trying to make a form, where users can change their email address of the account. I want them to enter their password to validate them. So I have a function that is doing the email change, but before it calls the <code>validate</code> function. If the return value is true it goes on. If not an error appears. But when testing it with the correct credentials it always goes into the <code>else</code> although i get a valid axios response.</p> <pre><code> emailChange() { if (this.validate() == true) { var data = JSON.stringify({ email: this.email, }); this.put(data); } else { this.error = &quot;Falsches Passwort&quot;; this.snackbar = true; } }, validate() { var data = JSON.stringify({ identifier: this.loggedInUser.email, password: &quot;123456&quot;, }); var config = { method: &quot;post&quot;, url: &quot;http://192.168.190.112:1337/api/auth/local&quot;, headers: { &quot;Content-Type&quot;: &quot;application/json&quot;, }, data: data, }; this.$axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .then(function () { return true; }) .catch(function (error) { console.log(error); }); }, </code></pre>
[ { "answer_id": 74144888, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 0, "selected": false, "text": " for (int i = 0; i < ransomChar.size(); i++) {\n boolean flag = false;\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15635029/" ]
74,144,502
<p>Here is my code for Roman to Integer problem I can not understand why the for loop is only working on the first two elements.</p> <pre><code>class Solution(object): def romanToInt(self, S): ran = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} sum = 0 for i in S: num = ran[i] num2 = ran[S[S.index(i) + 1]] if num &gt;= num2: sum = num + num2 else: sum = num - num2 return sum </code></pre>
[ { "answer_id": 74145417, "author": "Ahmed Amr", "author_id": 20294493, "author_profile": "https://Stackoverflow.com/users/20294493", "pm_score": 0, "selected": false, "text": " def romanToInt(S):\n ran = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n sum = 0\n for...
2022/10/20
[ "https://Stackoverflow.com/questions/74144502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19796395/" ]
74,144,512
<p>I'm adding Firestore to an existing angular project but I have a TS error when trying to ad dit to the constructor with the documentation code:</p> <pre><code>import { Firestore, collectionData, collection } from '@angular/fire/firestore'; constructor(db: Firestore) { const collection: any = collection(db, 'songs'); this.songs$ = collectionData(collection); } TS error: Block-scoped variable 'collection' used before its declaration.ts(2448) Type 'Observable&lt;DocumentData[]&gt;' is missing the following properties from type '{ new (subscribe?: ((this: Observable&lt;Song[]&gt;, subscriber: Subscriber&lt;Song[]&gt;) =&gt; TeardownLogic) | undefined): Observable&lt;Song[]&gt;; prototype: Observable&lt;...&gt;; create: (...args: any[]) =&gt; any; }': prototype, create ts(2739) </code></pre> <p>The firestore version: &quot;@angular/fire&quot;: &quot;^7.4.1&quot; And the ts version: typescript&quot;: &quot;~4.7.2&quot;</p> <p>I don't understand how to get around this, and haven't been able to fin any answers on this specific issue.</p>
[ { "answer_id": 74145184, "author": "Marjory", "author_id": 8009227, "author_profile": "https://Stackoverflow.com/users/8009227", "pm_score": -1, "selected": false, "text": "import * as firebase from 'firebase/app';\n\nimport 'firebase/firestore';\n" }, { "answer_id": 74294352, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74144512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294484/" ]
74,144,538
<p>I have developed API which call the class mediator via sequence in WSO2 EI 6.5.0. Initially API logs are getting printed except class mediator logs in Server log.</p> <p>To enable logs for class mediator as per <a href="https://stackoverflow.com/questions/31451723/class-mediator-logs-are-not-reflecting-in-wso2-esb">this</a>, I logged into management console <code>Home&gt; Configure&gt; Logging</code> section and went to section <code>Configure Log4J Loggers</code> , searched log keyword whatever i added inside class mediator to find out class mediator and changed class level to <code>Debug</code></p> <p><a href="https://i.stack.imgur.com/Kicjl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kicjl.png" alt="management console" /></a></p> <p>post this change, nothing is printed when i invoke service via postman, but API response getting. I just restarted server, post this management console url also not getting printed in server logs.</p> <p>Below is the management console logging configuration image for reference.</p> <p><a href="https://i.stack.imgur.com/voDxa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/voDxa.png" alt="total page" /></a></p> <p>Class Mediator:</p> <pre><code>package com.abc.in; import org.apache.synapse.MessageContext; import org.apache.synapse.mediators.AbstractMediator; import org.apache.synapse.core.axis2.Axis2MessageContext; /*import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;*/ import java.util.ArrayList; import java.util.Map; public class DuplicateHeadersMediator extends AbstractMediator { // private static final Log logger = LogFactory.getLog(DuplicateHeadersMediator.class); public boolean mediate(MessageContext messageContext) { log.info(&quot;DuplicateHeadersMediator called********** : &quot; ); trace.info(&quot;trace DuplicateHeadersMediator called********** :&quot;); org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); Map excessHeaders = (Map) axis2MessageContext.getProperty(&quot;EXCESS_TRANSPORT_HEADERS&quot;); log.info(&quot;excessHeaders : &quot; + excessHeaders.entrySet()); trace.info(&quot;trace excessHeaders : &quot; + excessHeaders.entrySet()); Map transportHeaders = (Map) axis2MessageContext.getProperty(&quot;TRANSPORT_HEADERS&quot;); log.info(&quot;transportHeaders : &quot; + transportHeaders.entrySet()); trace.info(&quot;trace transportHeaders : &quot; + transportHeaders.entrySet()); if (excessHeaders.size() != 0 &amp;&amp; transportHeaders.size() != 0) { for (Object key : transportHeaders.keySet()) { addPropertiesForExcessHeaders((String)key,excessHeaders,messageContext); } } return true; } // Add extra properties to the synapse message context for duplicated headers. private void addPropertiesForExcessHeaders(String headerName, Map excessHeaders, MessageContext messageContext) { if (excessHeaders.get(headerName) != null) { ArrayList&lt;String&gt; list = (ArrayList) excessHeaders.get(headerName); if (list.size() &gt; 0) { int i = 2; for (String value : list) { String propName = headerName + i; messageContext.setProperty(propName, value); log.info(&quot;propName : &quot; + propName); trace.info(&quot;trace propName : &quot; + propName); i += 1; } } } } } </code></pre> <p>API:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;api context=&quot;/readcookiesapi&quot; name=&quot;ReadCookiesAPI&quot; xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt; &lt;resource methods=&quot;POST&quot;&gt; &lt;inSequence&gt; &lt;log level=&quot;custom&quot;&gt; &lt;property name=&quot;ReadCookiesAPI&quot; value=&quot;is called *****&quot;/&gt; &lt;/log&gt; &lt;sequence key=&quot;HeaderMediatorCall_Sequecne&quot;/&gt; &lt;log level=&quot;custom&quot;&gt; &lt;property expression=&quot;$trp:test&quot; name=&quot;test1&quot;/&gt; &lt;property expression=&quot;$ctx:test2&quot; name=&quot;test2&quot;/&gt; &lt;property expression=&quot;$ctx:test3&quot; name=&quot;test3&quot;/&gt; &lt;/log&gt; &lt;respond/&gt; &lt;/inSequence&gt; &lt;outSequence/&gt; &lt;faultSequence/&gt; &lt;/resource&gt; &lt;/api&gt; </code></pre> <p>Sequence:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;sequence name=&quot;HeaderMediatorCall_Sequecne&quot; trace=&quot;disable&quot; xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt; &lt;log level=&quot;custom&quot;&gt; &lt;property name=&quot;HeaderMediatorCall_Sequecne&quot; value=&quot;B4 *****&quot;/&gt; &lt;/log&gt; &lt;class name=&quot;com.abc.in.DuplicateHeadersMediator&quot;/&gt; &lt;log level=&quot;custom&quot;&gt; &lt;property name=&quot;HeaderMediatorCall_Sequecne&quot; value=&quot;after *****&quot;/&gt; &lt;/log&gt; &lt;/sequence&gt; </code></pre> <p>Kindly clarify my doubts mentioned below.</p> <ol> <li>how can I recover default logging mechanism since this change made product logging weird, so that artifacts like API, Sequence etc and server logs i'll get properly</li> <li>why class mediator logs are not getting printed initially or how can i get those class mediators log in wso2 ei server 6.5.0</li> </ol>
[ { "answer_id": 74156198, "author": "Justin", "author_id": 9907182, "author_profile": "https://Stackoverflow.com/users/9907182", "pm_score": 1, "selected": true, "text": "java.util.logging.Logger" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9907182/" ]
74,144,542
<p>I have this quite complex class structure:</p> <pre class="lang-java prettyprint-override"><code>public interface SubComponent&lt;T&gt; {...} public interface Component&lt;T, C extends SubComponent&lt;T&gt;&gt; {...} public class Control&lt;T, I extends Component&lt;T, ? extends SubComponent&lt;T&gt;&gt;&gt; {...} </code></pre> <p>Then I have two classes that will hold the current state of the Control and of each Component, like this:</p> <pre class="lang-java prettyprint-override"><code>public class ControlState&lt;T, I extends Component&lt;T, ? extends SubComponent&lt;T&gt;&gt;&gt; { // The state keeps a reference to the Control, // and a map that holds all the states for each component private final Control&lt;T, I&gt; control; private final Map&lt;Integer, ComponentState&lt;T, ? extends SubComponent&lt;T&gt;&gt;&gt; components = new TreeMap&lt;&gt;(); // Has a method to add new components public void addComponent(int index) { // Here I have error on the control parameter ComponentState&lt;T, ? extends SubComponent&lt;T&gt;&gt; state = new ComponentState&lt;&gt;(control, index); ... } } public class ComponentState&lt;T, C extends SubComponent&lt;T&gt;&gt; { // The component state also has a reference to the Control // and the index to retrieve the Component from a List in the Control private final Control&lt;T, ? extends Component&lt;T, C&gt;&gt; control; private final int index; public ComponentState(Control&lt;T, ? extends Component&lt;T, C&gt;&gt; control, int index) { this.control = control; this.index = index; } } </code></pre> <p>In the <code>addComponent(int index)</code> method the IDE says:<br /> Required type: <code>Control&lt;T, ? extends Component&lt;T, C&gt;&gt;</code><br /> Provided: <code>Control&lt;T, I&gt;</code><br /> But, since I is: <code>I extends Component&lt;T, ? extends SubComponent&lt;T&gt;&gt;</code> I don't understand where the issue is, types should be compatible, what am I doing wrong?</p>
[ { "answer_id": 74156198, "author": "Justin", "author_id": 9907182, "author_profile": "https://Stackoverflow.com/users/9907182", "pm_score": 1, "selected": true, "text": "java.util.logging.Logger" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144542", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12903860/" ]
74,144,551
<p>I have two DataFrames:</p> <pre><code>df1: ticker A B C date 2022-01-01 NaN NaN 100 2022-01-02 NaN 200 NaN 2022-01-03 100 NaN NaN 2022-01-04 NaN NaN 120 df2: ticker A B C date 2022-01-02 145 233 100 2022-01-03 231 200 241 2022-01-04 100 200 422 2022-01-05 424 324 222 2022-01-06 400 421 320 </code></pre> <p>I want to fill the values in <code>df2</code> as <code>np.nan</code> for each index and column, where the value in <code>df1</code> is not null to get the following:</p> <pre><code>df3: ticker A B C date 2022-01-02 145 NaN 100 2022-01-03 NaN 200 241 2022-01-04 100 200 NaN 2022-01-05 424 324 222 2022-01-06 400 421 320 </code></pre> <p>How can this be done Pythonically without going into many loops?</p>
[ { "answer_id": 74156198, "author": "Justin", "author_id": 9907182, "author_profile": "https://Stackoverflow.com/users/9907182", "pm_score": 1, "selected": true, "text": "java.util.logging.Logger" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12244355/" ]
74,144,565
<p>This is a function of a calculator using GOTO and i wanted to know is it correct or not</p> <p>ALSO how can i return 'NAN' if ( char op doesn't equal to + - * / operators ) ??</p> <pre><code> float calcu(float num1, float num2, char op){ float R; if (op =='+') goto add; if (op =='-') goto sou; if (op =='*') goto mult; if (op =='/') goto div; add: R=num1 + num2; goto end; sou: R=num1 -num2; goto end; mult: R=num1 * num2; goto end; div: R=num1 /num2; goto end; end: return R; } </code></pre>
[ { "answer_id": 74156198, "author": "Justin", "author_id": 9907182, "author_profile": "https://Stackoverflow.com/users/9907182", "pm_score": 1, "selected": true, "text": "java.util.logging.Logger" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18900688/" ]
74,144,580
<p>We are binding a table using jqgrid. We have the first column start as a time column with a 12-hour format. We are facing an issue with sorting this data. The data is sorted correctly but it is not taking am/pm into consideration. Below is our code for binding the jqgrid:</p> <pre><code>var newFieldsArray = [ { name: &quot;ID&quot;, title: &quot;ID&quot;, type: &quot;number&quot;, width: &quot;50px&quot;, visible: false }, { name: &quot;TimeStart&quot;, title: &quot;Start&quot;, type: &quot;customTime&quot;, width: &quot;100px&quot;, validate: &quot;required&quot;, sorttype: &quot;date&quot;, formatter : { date : { AmPm : [&quot;am&quot;,&quot;pm&quot;,&quot;AM&quot;,&quot;PM&quot;], } }, // datefmt: &quot;m/d/Y h:i A&quot;, //sorttype: 'datetime', formatter: 'date', formatoptions: {newformat: 'd/m/y', srcformat: 'Y-m-d H:i:s'}, insertTemplate: function () { var $result = jsGrid.fields.customTime.prototype.insertTemplate.call(this); // original input $result.val(varendTime); return $result; }, itemTemplate: function (value, item) { return &quot;&lt;b style='display:none'&gt;&quot; + Date.parse(item.StartDate) + &quot;&lt;/b&gt;&lt;span&gt;&quot; + (item.TimeStart) + &quot;&lt;/span&gt;&quot;; } }, { name: &quot;TimeEnd&quot;, title: &quot;End&quot;, type: &quot;customTime&quot;, width: &quot;100px&quot;, validate: &quot;required&quot;,sorttype: &quot;date&quot;, datefmt: &quot;h:i&quot; }, { name: &quot;TimeTotal&quot;, title: &quot;Time&quot;, type: &quot;text&quot;, width: &quot;50px&quot;, readOnly: true }, { name: &quot;CoilPO&quot;, title: &quot;Coil PO&quot;, type: &quot;text&quot;, width: &quot;50px&quot;, validate: &quot;required&quot;, insertTemplate: function () { var $result = jsGrid.fields.text.prototype.insertTemplate.call(this); // original input $result.val(varlot); return $result; } }, { name: &quot;Joints&quot;, title: &quot;Joints&quot;, type: &quot;integer&quot;, width: &quot;60px&quot; }, { name: &quot;CommercialGrade&quot;, title: &quot;Commercial Grade&quot;, type: &quot;integer&quot;, width: &quot;80px&quot; }, { name: &quot;QAHold&quot;, title: &quot;QA Hold&quot;, type: &quot;integer&quot;, width: &quot;60px&quot; }, { name: &quot;Rejected&quot;, title: &quot;Reject&quot;, type: &quot;integer&quot;, width: &quot;60px&quot; }, { name: &quot;ActionTaken&quot;, title: &quot;Reason of Delay / Action Taken&quot;, type: &quot;text&quot;, width: &quot;120px&quot; }, { name: &quot;ClassId&quot;, title: &quot;Class&quot;, type: &quot;select&quot;, items: classDataArr,//classData.filter(function(n){return classdt.indexOf(n.Id) != -1 }),//classData, valueField: &quot;Id&quot;, textField: &quot;Title&quot;, insertTemplate: function () { debugger; var taxCategoryField = this._grid.fields[12]; var $insertControl = jsGrid.fields.select.prototype.insertTemplate.call(this); var classId = 0; var taxCategory = $.grep(voiceData, function (team) { return (team.ClassId) === classId &amp;&amp; (team.StationId) == parseInt($('#ddlEquipmentName').val()); }); taxCategoryField.items = taxCategory; $(&quot;.tax-insert&quot;).empty().append(taxCategoryField.insertTemplate()); $insertControl.on(&quot;change&quot;, function () { debugger; var classId = parseInt($(this).val()); var taxCategory = $.grep(voiceData, function (team) { return (team.ClassId) === classId &amp;&amp; (team.StationId) == parseInt($('#ddlEquipmentName').val()); }); taxCategoryField.items = taxCategory; $(&quot;.tax-insert&quot;).empty().append(taxCategoryField.insertTemplate()); }); return $insertControl; }, editTemplate: function (value) { var taxCategoryField = this._grid.fields[12]; var $editControl = jsGrid.fields.select.prototype.editTemplate.call(this, value); var changeCountry = function () { var classId = parseInt($editControl.val()); var taxCategory = $.grep(voiceData, function (team) { return (team.ClassId) === classId &amp;&amp; (team.StationId) == parseInt($('#ddlEquipmentName').val()); }); taxCategoryField.items = taxCategory; $(&quot;.tax-edit&quot;).empty().append(taxCategoryField.editTemplate()); }; debugger; $editControl.on(&quot;change&quot;, changeCountry); changeCountry(); return $editControl; } }, { name: &quot;VoiceId&quot;, title: &quot;Voice&quot;, type: &quot;select&quot;, items: voiceData, valueField: &quot;Id&quot;, textField: &quot;Title&quot;, width: &quot;120px&quot;, validate: &quot;required&quot;, insertcss: &quot;tax-insert&quot;, editcss: &quot;tax-edit&quot;, itemTemplate: function (teamId) { var t = $.grep(voiceData, function (team) { return team.Id === teamId; })[0].Title; return t; }, }, { name: &quot;Remarks&quot;, title: &quot;Remarks&quot;, type: &quot;text&quot;, width: &quot;110px&quot; }, { name: &quot;control&quot;, type: &quot;control&quot; } ]; hoursGrid.jsGrid(&quot;option&quot;, &quot;fields&quot;, newFieldsArray); </code></pre> <p>Below is two screenshots of data that appear when we sort: <a href="https://i.stack.imgur.com/lhCvk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lhCvk.jpg" alt="Ascending" /></a></p> <p><a href="https://i.stack.imgur.com/3cRgY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3cRgY.jpg" alt="Descending" /></a></p> <p>Can someone tell me what we are doing wrong?</p>
[ { "answer_id": 74156198, "author": "Justin", "author_id": 9907182, "author_profile": "https://Stackoverflow.com/users/9907182", "pm_score": 1, "selected": true, "text": "java.util.logging.Logger" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3282721/" ]
74,144,594
<p>I am trying to make a function that will take elements and values input by the user, and list whichever element has the highest value. For example,</p> <pre><code>['H', 14.5, 'Be', 2.5, 'C', 50.5, 'O', 22.5 'Mg', 4.0, 'Si', 6.0] </code></pre> <p>the correct answer is 'C'. I can't seem to figure out how to get this to work. I don't have any code yet, unfortunately.</p>
[ { "answer_id": 74144679, "author": "Mark", "author_id": 3874623, "author_profile": "https://Stackoverflow.com/users/3874623", "pm_score": 2, "selected": false, "text": "max()" }, { "answer_id": 74144713, "author": "JayJay", "author_id": 8816968, "author_profile": "htt...
2022/10/20
[ "https://Stackoverflow.com/questions/74144594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20056396/" ]
74,144,604
<p>I've got a border that i would like to reveal when in the viewport and then stay as the complete line. i've used the following css. Does anyone know some lightweight JS to activate the animation?</p> <pre class="lang-css prettyprint-override"><code>.draw-line { border-left:1px solid rgb(255,0,0); animation: draw-line 5s; Animation-fill-mode: forwards } @keyframes draw-line { 0% { height:0 } 50% { border-left:1px solid rgb(89,0,255) } 100% { height:100vh; border-left:1px solid rgb(255,0,0) } } </code></pre>
[ { "answer_id": 74144679, "author": "Mark", "author_id": 3874623, "author_profile": "https://Stackoverflow.com/users/3874623", "pm_score": 2, "selected": false, "text": "max()" }, { "answer_id": 74144713, "author": "JayJay", "author_id": 8816968, "author_profile": "htt...
2022/10/20
[ "https://Stackoverflow.com/questions/74144604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294533/" ]
74,144,609
<p>I want to check the response status and export it to CSV file using Scrapy. I tried with <code>response.status</code> but it only shows '200' and exports to the CSV file. How to get other status codes like &quot;404&quot;, &quot;502&quot; etc.</p> <pre><code>def parse(self, response): yield { 'URL': response.url, 'Status': response.status } </code></pre>
[ { "answer_id": 74145048, "author": "Alexander", "author_id": 17829451, "author_profile": "https://Stackoverflow.com/users/17829451", "pm_score": 2, "selected": true, "text": "settings.py" }, { "answer_id": 74145271, "author": "msenior_", "author_id": 8179939, "author_...
2022/10/20
[ "https://Stackoverflow.com/questions/74144609", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16414611/" ]
74,144,612
<p>I'm going through some practice for arrays (let me specify this is NOT homework i just completed a test which i know in my soul i failed and i'm practicing) and performing functions on them and I'm running into this problem. My method for finding highest number, average, and total works but, find the lowest number isn't and I'm honestly stuck as to why.</p> <p>To explain my array: index 0 is where i want to store my highest number index 1 is where i want to store my lowest number</p> <p>my method starts at index 2 to find lowest / highest numbers since the lowest / highest would be store in the first two element of the array. my array size also takes this into concideration as well as the file reader, they all start at index 2.</p> <p>I've also tried value returning methods while still getting the same end result.</p> <p>Below are the methods i've tried that aren't putting out the desired information:</p> <p>this method assigns highest to salesArray[0] and lowest to salesArray<a href="https://i.stack.imgur.com/uTCAp.png" rel="nofollow noreferrer">1</a>, and accomodates array size and array read starts at 2.</p> <pre><code>private void Lowest() { //method variables double lowest = salesArray[1]; //find lowest sale for (int index = 2; index &lt; salesArray.Length; index++) { if(salesArray[index] &lt; lowest) { lowest = salesArray[index]; } } </code></pre> <p>This way I used making both highest/lowest index 0 to try what was suggest in a previous comment:</p> <pre><code>private void Lowest() { //method variables double lowest = salesArray[0]; //find lowest sale for (int index = 1; index &lt; salesArray.Length; index++) { if(salesArray[index] &lt; lowest) { lowest = salesArray[index]; } </code></pre> <p>This is the value returning method I tried:</p> <pre><code>private double Lowest(double[] salesArray) { //method variables double lowest = salesArray[0]; //find lowest sale for (int index = 1; index &lt; salesArray.Length; index++) { if (salesArray[index] &lt; lowest) { lowest = salesArray[index]; } } return lowest; } </code></pre> <p>Below is a picture of the output: <a href="https://i.stack.imgur.com/uTCAp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uTCAp.png" alt="ProgramOutput" /></a></p>
[ { "answer_id": 74145048, "author": "Alexander", "author_id": 17829451, "author_profile": "https://Stackoverflow.com/users/17829451", "pm_score": 2, "selected": true, "text": "settings.py" }, { "answer_id": 74145271, "author": "msenior_", "author_id": 8179939, "author_...
2022/10/20
[ "https://Stackoverflow.com/questions/74144612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20245024/" ]
74,144,617
<pre><code>[ { data:&quot;Jan 12&quot;, year:2020 }, { data:&quot;Jan 12&quot;, year:2021 }, { data:&quot;Jan 5&quot;, year:2020 }, { data:&quot;Oct 12&quot;, year:2021 }, { data:&quot;Oct 12&quot;, year:2022 } ] </code></pre> <hr />
[ { "answer_id": 74145048, "author": "Alexander", "author_id": 17829451, "author_profile": "https://Stackoverflow.com/users/17829451", "pm_score": 2, "selected": true, "text": "settings.py" }, { "answer_id": 74145271, "author": "msenior_", "author_id": 8179939, "author_...
2022/10/20
[ "https://Stackoverflow.com/questions/74144617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294570/" ]
74,144,626
<p>I'd like to have the indexes of duplicated column elements as a list. So far, the way I found is</p> <pre><code>test = ['a', 'a', 'b', 'c', 'b'] testdf = pd.DataFrame(test, columns=['test']) np.asarray(np.where(list(testdf['test'].duplicated()))).tolist()[0] # [1, 4] </code></pre> <p>Which seems ridiculously convoluted.</p> <p>Any better way?</p>
[ { "answer_id": 74144682, "author": "Scott Boston", "author_id": 6361531, "author_profile": "https://Stackoverflow.com/users/6361531", "pm_score": 1, "selected": false, "text": "testdf.index[testdf['test'].duplicated()]\n" }, { "answer_id": 74144718, "author": "bitflip", "...
2022/10/20
[ "https://Stackoverflow.com/questions/74144626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5224236/" ]
74,144,627
<p>I have questions about this one Every two adjacent elements in this list forms an ordered pair</p> <p>Input: 1 4 2 4 3 8</p> <p>Output: RELATION: { (1,4), (2,4), (3,8) }</p> <p>I use Scanner to read the line and after that I use :</p> <pre><code>List&lt;String&gt; rel = Arrays.asList(relation.split(&quot; &quot;)); String rel1 = String.join(&quot;, &quot;, rel); System.out.println(&quot;RELATION: &quot;+&quot;{ &quot;+rel1+&quot; }&quot;); </code></pre> <p>but the output just gave me: RELATION: { 1, 4, 2, 4, 3, 8 } not pair them in 2 like the output I wanted. Could someone help me with this please?</p> <p>I also used this code but it gives me wrong pairs</p> <pre><code>(1,4 4,2 2,4): for (int i=0;i&lt;rel.size()/2;i++){ System.out.println(rel.get(i)+&quot;,&quot;+rel.get(i+1));} </code></pre>
[ { "answer_id": 74144682, "author": "Scott Boston", "author_id": 6361531, "author_profile": "https://Stackoverflow.com/users/6361531", "pm_score": 1, "selected": false, "text": "testdf.index[testdf['test'].duplicated()]\n" }, { "answer_id": 74144718, "author": "bitflip", "...
2022/10/20
[ "https://Stackoverflow.com/questions/74144627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20291881/" ]
74,144,639
<p>This is part of a code to count white spaces, numbers, or other from the K&amp;R &quot;C programming book.&quot; I am confused why it compares &quot;int c&quot; to digits using '0' and '9' instead of 0 and 9. I realize the code doesn't work if I use 0 and 9 without quotes. I am just trying to understand why. Does this have to do with c being equal to getchar()?</p> <pre><code>while ((c = getchar()) != EOF) if (c &gt;= '0' &amp;&amp; c &lt;= '9') ++ndigit[c-'0']; else if (c == ' ' || c == '\n' || c == '\t') ++nwhite; else ++nother; </code></pre>
[ { "answer_id": 74144682, "author": "Scott Boston", "author_id": 6361531, "author_profile": "https://Stackoverflow.com/users/6361531", "pm_score": 1, "selected": false, "text": "testdf.index[testdf['test'].duplicated()]\n" }, { "answer_id": 74144718, "author": "bitflip", "...
2022/10/20
[ "https://Stackoverflow.com/questions/74144639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14097473/" ]
74,144,649
<p>JS/TS does automatic boxing and unboxing of <code>String</code>, <code>Number</code> and <code>Boolean</code> types, which allows to use a mix of literals and objects in the same expression, without explicit conversion, like:</p> <p><code>const a = &quot;3&quot; + new String(&quot;abc&quot;);</code></p> <p>I'm trying to implement something similar for <code>bigint</code> and <code>number</code> by providing a custom class <code>Long</code>:</p> <pre><code>class Long { public constructor(private value: bigint | number) { } public valueOf(): bigint { return BigInt(this.value); } } const long = new Long(123); console.log(456n + long); </code></pre> <p>This works pretty well (and prints <code>579n</code>), but causes both, my linter and the TS compiler to show errors for the last expression. I can suppress them with comments like this:</p> <pre><code>// @ts-expect-error // eslint-disable-next-line @typescript-eslint/restrict-plus-operands console.log(456n + long); </code></pre> <p>but that's not a good solution for entire apps.</p> <p>Is there a way to tell that <code>Long</code> is to be treated as a <code>bigint</code> or anything else to avoid the errors?</p> <p><strong>About Why Doing That:</strong></p> <p>I'm working on a tool to convert <a href="https://github.com/mike-lischke/java2typescript" rel="nofollow noreferrer">Java to Typescript</a> and want to support as many of the Java semantics as possible. The type <code>Long</code> holds a <code>long</code> integer, which is 64 bit wide, which can only be represented in TS by using <code>bigint</code>. The main problem with that is that Java automatically unboxes <code>Long</code> just like <code>String</code> and I want to support this semantic as far as I can.</p> <p>For @caTS: so this will never be normal TS code but always used as <code>java.lang.Long</code> and hence there will be no confusion.</p>
[ { "answer_id": 74160563, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 1, "selected": false, "text": "Object.prototype.valueOf()" }, { "answer_id": 74508566, "author": "Mike Lischke", "author_id": 1137174...
2022/10/20
[ "https://Stackoverflow.com/questions/74144649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1137174/" ]
74,144,670
<p>I've a <code>Data Frame</code> like this. I'm trying to use <code>pd.numeric</code> <a href="https://pandas.pydata.org/docs/reference/api/pandas.to_numeric.html" rel="nofollow noreferrer">pd.numeric</a></p> <pre><code>import pandas as pd import numpy as np series = pd.Series([0,1,2,2,3,4,7,8.2,&quot;stackoverflow&quot;,7,9.9]) df = pd.to_numeric(series, errors=&quot;coerce&quot;) print(df) </code></pre> <p>output I got as expected</p> <hr /> <pre><code> 0 0.0 1 1.0 2 2.0 3 2.0 4 3.0 5 4.0 6 7.0 7 8.2 |------------------ 8 NaN |------------------- 9 7.0 10 9.9 |----------------------- dtype: float64 |-------------------------- </code></pre> <p>when I use with <code>pd series</code> giving me different outputs</p> <pre><code>import pandas as pd import numpy as np series = pd.Series([0,1,2,2,3,np.array(4),7,8.2,&quot;stackoverflow&quot;,7,9.9]) df = pd.to_numeric(series, errors=&quot;coerce&quot;) print(df) </code></pre> <p>Output I got in case 2 not as expected. It's not even converting <code>string</code> to Nan as it done above example. It's not even converting to <code>dtype</code> as float</p> <hr /> <pre><code>0 0 1 1 2 2 3 2 4 3 5 4 6 7 7 8.2 ----------------------------------- 8 stackoverflow ---------------------------------- 9 7 10 9.9 dtype: object </code></pre>
[ { "answer_id": 74160563, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 1, "selected": false, "text": "Object.prototype.valueOf()" }, { "answer_id": 74508566, "author": "Mike Lischke", "author_id": 1137174...
2022/10/20
[ "https://Stackoverflow.com/questions/74144670", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294464/" ]
74,144,688
<p>as part of teaching myself SQL, I'm coding a loot drop table that I hope to use in D&amp;D campaigns.</p> <p>the simplest form of the query is:</p> <pre><code>SELECT rarity, CASE WHEN item=common THEN (SELECT item FROM common.table) WHEN item=uncommon THEN (SELECT item FROM unommon.table) ...etc END AS loot FROM rarity.table ORDER BY RAND()*(1/weight) LIMIT 1 </code></pre> <p>the idea is that the query randomly chooses a rarity from the rarity.table based on a weighted probability. There are 10 types of rarity, each represented on the rarity.table as a single row and having a column for probabilistic weight.</p> <p>If I want to randomly output 1 item (limit 1), this works great.</p> <p>However, attempting to output more than 1 item at a time isn't probabilistic in that the query can only put out 1 row of each rarity. If say I want to roll 10 items (limit 10) for my players, it will just output all 10 rows, producing 1 item from each rarity, and never multiple of the higher weighted rarities.</p> <p>I have tried something similar, creating a different rarity.table that was 1000 rows long, and instead of having a 'weight' column representing probabilistic weight in rows, ex. common is rows 1-20, uncommon rows 21-35...etc. Then writing the query as</p> <pre><code>ORDER BY RAND() LIMIT x </code></pre> <p>-- (where x is the number of items I want to output)</p> <p>and while this is better in some ways, it results are still limited by the number of rows for each rarity. I.E. if I set limit to 100, it again just gives me the whole table without taking probability into consideration. This is fine in that I probably won't be rolling 100 items at once, but feels incorrect that the output will always be limited to 20 common items, 15 uncommon, etc. This is also MUCH slower, as my actual code has a lot of case and sub-case statements.</p> <p>So, my thought moved on to if is possible to run the query with a limit 1, but to set the query to run x number of times, and then include each result on the same table, preserving probability and not being limited by the number of rows in the table. However, I haven't figured out how to do so.</p> <p>Any thoughts on how to achieve these results? Or maybe a better approach? Please let me know if I can clarify anything.</p> <p>Thank you!</p>
[ { "answer_id": 74160563, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 1, "selected": false, "text": "Object.prototype.valueOf()" }, { "answer_id": 74508566, "author": "Mike Lischke", "author_id": 1137174...
2022/10/20
[ "https://Stackoverflow.com/questions/74144688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20276900/" ]
74,144,732
<p>This works:</p> <pre><code>int a = 7; char b = a + '0'; write(1,&amp;b,1); </code></pre> <p>but this does not:</p> <pre><code>int a = 7; char b = (char) a; write(1,&amp;b,1); </code></pre> <p>Could someone tell me why? I just want to convert the integer 7 to '7' as a character.</p>
[ { "answer_id": 74144889, "author": "John Bode", "author_id": 134554, "author_profile": "https://Stackoverflow.com/users/134554", "pm_score": 3, "selected": true, "text": "char" }, { "answer_id": 74144944, "author": "Felipe_SC", "author_id": 19950416, "author_profile":...
2022/10/20
[ "https://Stackoverflow.com/questions/74144732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383695/" ]
74,144,738
<pre><code>void change(char *string){ string = &quot;Hello&quot;; printf(&quot;%s&quot;, string); } int main (void){ char* s = &quot;Hey&quot;; change(s); printf(&quot;%s&quot;, s); return 0; } </code></pre> <p>Shouldn't the code above print &quot;Hello&quot;, as the parameter passed to the function is a pointer?</p>
[ { "answer_id": 74144889, "author": "John Bode", "author_id": 134554, "author_profile": "https://Stackoverflow.com/users/134554", "pm_score": 3, "selected": true, "text": "char" }, { "answer_id": 74144944, "author": "Felipe_SC", "author_id": 19950416, "author_profile":...
2022/10/20
[ "https://Stackoverflow.com/questions/74144738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19564165/" ]
74,144,743
<p>I have this simple template which has a button:</p> <pre><code>&lt;a class=&quot;button&quot; href=&quot;{% url 'function' %}&quot;&gt; &lt;button&gt; Settings &lt;/button&gt; &lt;/a&gt; </code></pre> <p>And <code>views.py</code> in which I have function definition.</p> <pre><code>def function(request): context = {} object = Runner() object.prepate_sth() context['tasks'] = runner.tasks.remaining try: thread = threading.Thread(target=runner.run_sth, args=()) thread.start() except Exception: raise Exception return render(request, 'home.html', context) </code></pre> <p>I am creating separate thread in order to not to block the function execution and run some other function in the background. That task in the background changes the quantity of elements in <code>runner.tasks.remaining</code> list variable. I would want to have that variable shown in the template and being updated constantly when its value changes. How can I achieve that?</p>
[ { "answer_id": 74145290, "author": "Nealium", "author_id": 10229768, "author_profile": "https://Stackoverflow.com/users/10229768", "pm_score": 2, "selected": true, "text": "every x seconds" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10686785/" ]
74,144,744
<p>I need to make plot for: <a href="https://i.stack.imgur.com/PFX3S.png" rel="nofollow noreferrer">this function</a> or <a href="https://i.stack.imgur.com/BXXha.png" rel="nofollow noreferrer">this</a></p> <p>I made plots before with this code:</p> <pre><code>x = np.arange(-5, 5, 0.1) y1 = np.tanh(x) plt.plot(x,y1) </code></pre> <p>but how to make something like this?</p> <pre><code> if(x &lt;= 0): y4 = 0 else: y4 = x </code></pre> <p>gives valueerror:The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</p>
[ { "answer_id": 74145290, "author": "Nealium", "author_id": 10229768, "author_profile": "https://Stackoverflow.com/users/10229768", "pm_score": 2, "selected": true, "text": "every x seconds" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74144744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20243675/" ]
74,144,778
<p>I get unexpected results for a NOT IN criteria, when the subquery returns a single NULL result row.</p> <p>There's two tables, brands and media. The goal is to get a result only including the brands that does not have media of the given media_type associated with it.</p> <pre><code>SELECT * FROM brands WHERE id NOT IN ( SELECT DISTINCT brand AS 'id' FROM media WHERE media_type=7 ) </code></pre> <p>When there are entries of media_type=7 with brands associated, so the subquery returns a list of at least one valid id, the query works as expected.</p> <p>However if no entries of media_type=7 are associated with any brand the subquery returns a single row with a NULL value. Then the total query returns an empty set instead of the expected: a result with all brands rows.</p> <p>What's the error I'm doing here?</p> <p>Using 10.4.26-MariaDB and tables are InnoDB types</p>
[ { "answer_id": 74145029, "author": "Stu", "author_id": 15332650, "author_profile": "https://Stackoverflow.com/users/15332650", "pm_score": 2, "selected": true, "text": "select * \nfrom brands b\nwhere not exists (\n select * from media m\n where m.media_type = 7 and m.brand = b.Id\n)...
2022/10/20
[ "https://Stackoverflow.com/questions/74144778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4038380/" ]
74,144,785
<p>I wrote a function to detect which columns are getting updated for a table.</p> <p>This Table is present in Oracle Apex.</p> <p>I use this function to send mail for Update performed <strong>through APEX UI</strong> on it.</p> <p>Trigger Code:</p> <pre><code> create or replace TRIGGER TRIAL AFTER UPDATE ON TABLE FOR EACH ROW DECLARE result varchar2(4000); begin result := snap_fun('TABLE_NAME'); SEND_MAIL('JOHN@****', 'TABLE Modified',result,'bidev-noreply@***','HOST'); end; </code></pre> <p>Function Code</p> <pre><code>create or replace function SNAP_FUN(inTableName in varchar2) return varchar2 is result varchar2(4000); sep varchar2(2) := null; begin for c in (select column_name from all_tab_columns where table_name = inTableName) loop if updating(c.column_name) then result := result || sep || c.column_name; sep := ', '; end if; end loop; return result; end; </code></pre> <p>Problem : When i am updating any column through back end, i am receiving correct mail with only columns that are <strong>actually</strong> being updated but when i Update through Oracle Apex (using UI), I receive the list of all the columns.</p>
[ { "answer_id": 74145029, "author": "Stu", "author_id": 15332650, "author_profile": "https://Stackoverflow.com/users/15332650", "pm_score": 2, "selected": true, "text": "select * \nfrom brands b\nwhere not exists (\n select * from media m\n where m.media_type = 7 and m.brand = b.Id\n)...
2022/10/20
[ "https://Stackoverflow.com/questions/74144785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19854398/" ]
74,144,799
<p>I have a Series that looks like this</p> <pre><code>index column A [41, 13, 4, 50] A [41, 13, 4, 5] . . . </code></pre> <p>What I want to do is aggregate the rows of lists, but only the unique values.</p> <p>The result should look like this:</p> <pre><code>index column A [41, 13, 4, 50, 5] . . . </code></pre> <p>Is there any simple way to do this?</p>
[ { "answer_id": 74144995, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 3, "selected": true, "text": "(df.explode('column') # explode list to bring values in rows\n .drop_duplicates() # drop duplicates\n .groupby('index...
2022/10/20
[ "https://Stackoverflow.com/questions/74144799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2873277/" ]
74,144,865
<p>I want to save the object which triggered as a variable and afterwards destroy it by pushing a key but I couldn't figure out how to save it as a variable.</p> <pre class="lang-cs prettyprint-override"><code>private void OnTriggerEnter(Collider other) { if (other.gameObject) _canHit = true; } </code></pre> <p>Edit: (Added the whole script to make it more understandable)</p> <pre class="lang-cs prettyprint-override"><code> //GameObject variable public GameObject collidedWith; //store the collided GameObject private void OnTriggerEnter(Collider other) { collidedWith = other.gameObject; } private bool _canHit; //if can hit true make it false and do the task private void Update() { if (_canHit) { if (Input.GetKeyDown(KeyCode.A) &amp;&amp; collidedWith != null) { Destroy(collidedWith); _canHit = false; Debug.Log(&quot;Left&quot;); } } } //set _canHit true if object enters trigger private void OnTriggerEnter(Collider other) { if (other.attachedRigidbody) _canHit = true; } private void OnTriggerEnter(Collider other) { if (other.gameObject) trigObj = other.gameObject() } //set _canHit false if object enters trigger private void OnTriggerExit(Collider other) { if (other.attachedRigidbody) _canHit = false; } </code></pre>
[ { "answer_id": 74144948, "author": "R Astra", "author_id": 9586370, "author_profile": "https://Stackoverflow.com/users/9586370", "pm_score": 3, "selected": true, "text": "public GameObject collidedWith;//GameObject variable\nprivate void OnTriggerEnter(Collider other)\n{\n collidedWit...
2022/10/20
[ "https://Stackoverflow.com/questions/74144865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19952343/" ]
74,144,933
<p>I have a function that maps a lookup class into a usable array for my React project. I was able to get the function to work, but right now it is looping through the enum twice and returning undefined for the first iteration.</p> <p>This works but is returning 8 elements, 4 undefined then 4 correct objects. Why is it looping twice?</p>
[ { "answer_id": 74144948, "author": "R Astra", "author_id": 9586370, "author_profile": "https://Stackoverflow.com/users/9586370", "pm_score": 3, "selected": true, "text": "public GameObject collidedWith;//GameObject variable\nprivate void OnTriggerEnter(Collider other)\n{\n collidedWit...
2022/10/20
[ "https://Stackoverflow.com/questions/74144933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11726149/" ]
74,144,940
<p>I have a question regarding parametrizing the test method with another method that returns the list of test data that I want to use in my test:</p> <p>When I execute code in this way:</p> <pre><code>class Test: @pytest.mark.parametrize(&quot;country_code&quot;, get_country_code_list()) def test_display_country_code(self, country_code): print(country_code) @classmethod def get_country_code_list(cls) -&gt; list: return [1, 2, 3] </code></pre> <p>I get error: Unresolved referency: get_country_code_list. It doesn't make a difference if get_country_code_list method is a static method, class method or self.</p> <p>But if I put the method get_country_code_list() above the test method, I don't get this error. Does the order of test methods make a difference in Python?</p>
[ { "answer_id": 74144948, "author": "R Astra", "author_id": 9586370, "author_profile": "https://Stackoverflow.com/users/9586370", "pm_score": 3, "selected": true, "text": "public GameObject collidedWith;//GameObject variable\nprivate void OnTriggerEnter(Collider other)\n{\n collidedWit...
2022/10/20
[ "https://Stackoverflow.com/questions/74144940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7900520/" ]
74,144,946
<p>Any help is greatly Appreciated.</p> <p>I Have input JSON that can have Phone in array or it can be blank or it can be missing.</p> <pre class="lang-json prettyprint-override"><code>[ { &quot;Name&quot;: &quot;abc&quot;, &quot;Phone&quot;: [ { &quot;office-1&quot;: &quot;123&quot;, &quot;home-1&quot;: &quot;989&quot; }, { &quot;office-1&quot;: &quot;456&quot;, &quot;home-1&quot;: &quot;999&quot; } ], &quot;Email&quot;: &quot;abc@123.com&quot; }, { &quot;Name&quot;: &quot;efg&quot;, &quot;Phone&quot;: [], &quot;Email&quot;: &quot;efg@123.com&quot; }, { &quot;Name&quot;: &quot;xyz&quot;, &quot;Email&quot;: &quot;xyz@123.com&quot; } ] </code></pre> <p>My Jolt is already able to convert the Phone number array, but it is not working if the label Phone is missing in JSON input.</p> <p>Expected output:</p> <pre class="lang-json prettyprint-override"><code>[ { &quot;Name&quot;: &quot;abc&quot;, &quot;office-1&quot;: &quot;123&quot;, &quot;home-1&quot;: &quot;989&quot;, &quot;Email&quot;: &quot;abc@123.com&quot; }, { &quot;Name&quot;: &quot;abc&quot;, &quot;office-1&quot;: &quot;456&quot;, &quot;home-1&quot;: &quot;999&quot;, &quot;Email&quot;: &quot;abc@123.com&quot; }, { &quot;Name&quot;: &quot;efg&quot;, &quot;Email&quot;: &quot;efg@123.com&quot; }, { &quot;Name&quot;: &quot;xyz&quot;, &quot;Email&quot;: &quot;xyz@123.com&quot; } ] </code></pre> <p>Please help</p>
[ { "answer_id": 74144948, "author": "R Astra", "author_id": 9586370, "author_profile": "https://Stackoverflow.com/users/9586370", "pm_score": 3, "selected": true, "text": "public GameObject collidedWith;//GameObject variable\nprivate void OnTriggerEnter(Collider other)\n{\n collidedWit...
2022/10/20
[ "https://Stackoverflow.com/questions/74144946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294731/" ]
74,144,957
<pre><code> class CardWidget extends StatelessWidget { final String title; final Color color; final FaIcon icon; final Function()? onTap; const CardWidget( {super.key, required this.title, required this.color, this.onTap, required this.icon}); @override Widget build(BuildContext context) { return GestureDetector( onTap: onTap, child: Card( elevation: 4, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(25.0), ), color: color, ), ); } } </code></pre> <p>I created a class as above and defined FaIcon in it, but I cannot use the icon property in the card.</p> <p><a href="https://i.stack.imgur.com/qcQB0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qcQB0.png" alt="enter image description here" /></a></p> <p>I want to use a text in the middle of the card as above and an icon in the middle of the card above the text.</p> <p>I took the card structure I created into Column and tried to add an icon like that. But since I can't define the icon inside the Card Widget, it places the icon outside the card.</p>
[ { "answer_id": 74144978, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "Card" }, { "answer_id": 74145013, "author": "Code Master", "author_id": 19960585, "author...
2022/10/20
[ "https://Stackoverflow.com/questions/74144957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17906689/" ]
74,145,000
<p>My formula for sin(x) in taylor series(picture under the code). In general if i enter Start 1 and end 20 with step 2, console output '-nan' after x = 9; sin(X) and Taylor should be the same;, for example:</p> <p>x = 9; sin(x) = 0.412118; taylor = 0.412118</p> <p>x = 11; sin(x) = -0.99999; taylor -0.999976;</p> <p>x = 13; sin(x) = 0.420167; taylor = -nan;</p> <p>like this all the time; i need some help; its for my laboratory</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;math.h&gt; int main(void) { float a, b, left, right, eps = 0.00001, step, x, add = 1, chis, znam, fact, sum = 0, delta; printf(&quot;Plese enter your start: &quot;); scanf(&quot;%f&quot;, &amp;a); printf(&quot;Your end: &quot;); scanf(&quot;%f&quot;, &amp;b); printf(&quot;and step: &quot;); scanf(&quot;%f&quot;, &amp;step); if (b &lt; a || a &lt; eps) { printf(&quot;Your inputs aren't correct&quot;); return -1; } printf(&quot;\tX\t sin(x)\tTaylor\t Delta\n&quot;); for (x = a; x &lt; b; x += step) { printf(&quot; x = %9f\t&quot;, x); left = sin(x); printf(&quot;%9f&quot;, left); chis = -x; znam = 1; sum = 0; add = 1; fact = 1; while (fabs(add) &gt; eps) { add = -1 * chis / znam; sum += add; chis *= -1 * (x * x); fact++; znam *= fact * (fact + 1); fact++; } printf(&quot; %9f &quot;, sum); printf(&quot;%e\n&quot;, fabs(left - sum)); } } </code></pre> <p><a href="https://i.stack.imgur.com/YnWEG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YnWEG.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74145268, "author": "ikegami", "author_id": 589924, "author_profile": "https://Stackoverflow.com/users/589924", "pm_score": 2, "selected": true, "text": "znam" }, { "answer_id": 74145536, "author": "0___________", "author_id": 6110094, "author_profile":...
2022/10/20
[ "https://Stackoverflow.com/questions/74145000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294643/" ]
74,145,023
<p>I am having issues trying to aggregate data with multiple conditions in PowerBI Dax.</p> <p>I have a PowerBI Dataset similar to the one below, which lists Call ID and multiple vehicle codes and am trying to create a measure that acts as a flag using the logic below:</p> <ul> <li>IF Vehicle_Code=H OR Vehicle_Code=HX are both present per CallID THEN Count the distinct CallID</li> </ul> <p>Dataset:</p> <p><a href="https://i.stack.imgur.com/7xQut.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7xQut.png" alt="CallID 1 1 1 2 2 2 3 3 3" /></a></p> <p>Result:</p> <p><a href="https://i.stack.imgur.com/HoisZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HoisZ.png" alt="enter image description here" /></a></p> <p>Any help or advise would be much appreciated. Thanks</p>
[ { "answer_id": 74145571, "author": "Jos Woolley", "author_id": 17007704, "author_profile": "https://Stackoverflow.com/users/17007704", "pm_score": 0, "selected": false, "text": "H HX Flag = \nVAR T1 =\n SUMMARIZE(\n 'Table',\n 'Table'[CALLID],\n \"Flag\",\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74145023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13425868/" ]
74,145,032
<p>Im trying to make a loop where i have <code>let sum = 0</code> When i click on a button Sum goes to 1 and when i press the button again it goes back to 0, and loop it every time i press the button</p> <pre><code>let sum = 0 button.addEventListener(&quot;click&quot;, loop()) function loop(){ } </code></pre>
[ { "answer_id": 74145571, "author": "Jos Woolley", "author_id": 17007704, "author_profile": "https://Stackoverflow.com/users/17007704", "pm_score": 0, "selected": false, "text": "H HX Flag = \nVAR T1 =\n SUMMARIZE(\n 'Table',\n 'Table'[CALLID],\n \"Flag\",\n ...
2022/10/20
[ "https://Stackoverflow.com/questions/74145032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15757167/" ]
74,145,050
<p>I am trying to remove big spaces from the code result:</p> <pre><code>from bs4 import BeautifulSoup import requests url = 'https://www.rucoyonline.com/characters/Something' response = requests.get(url) print(response.status_code) soup = BeautifulSoup(response.text, 'html.parser') table = soup.find('table', class_ = 'character-table table table-bordered') print(table.get_text()) </code></pre> <p>Result after running code :</p> <pre><code>Character Information Name Something Level 28 Last online about 6 years ago Born September 03, 2016 </code></pre> <p><code>string()</code> is not working, I think it's because <code>beautifulsoup</code></p>
[ { "answer_id": 74145081, "author": "rafathasan", "author_id": 9465840, "author_profile": "https://Stackoverflow.com/users/9465840", "pm_score": 2, "selected": true, "text": "print(\"\\n\".join([s for s in table.get_text().split(\"\\n\") if s]))\n" }, { "answer_id": 74145141, ...
2022/10/20
[ "https://Stackoverflow.com/questions/74145050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16464689/" ]
74,145,058
<p>I'm trying to implement UIcollectionView inside UITableViewCell. I've tried several methods but none of them works for me. Looks like tableView just doesn't know which size cell should be.</p> <pre><code>import UIKit class MovieVideosTableViewCell: UITableViewCell { static let identifier = &quot;MovieVideosTableViewCell&quot; private var collectionView: UICollectionView! = nil override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) print(&quot;Inited \(type(of: self))&quot;) setupCollectionView() addSubview(collectionView) setupConstraints() } required init?(coder: NSCoder) { fatalError(&quot;init(coder:) has not been implemented&quot;) } } private extension MovieVideosTableViewCell { func setupCollectionView() { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.itemSize = CGSize(width: contentView.bounds.width/2, height: contentView.bounds.height) collectionView = UICollectionView(frame: contentView.bounds, collectionViewLayout: layout) collectionView.translatesAutoresizingMaskIntoConstraints = false collectionView.register(MovieDetailsCollectionViewCell.self, forCellWithReuseIdentifier: MovieDetailsCollectionViewCell.identifier) collectionView.delegate = self collectionView.dataSource = self } func setupConstraints() { NSLayoutConstraint.activate([ collectionView.topAnchor.constraint(equalTo: contentView.topAnchor), collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor) ]) } } </code></pre>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294799/" ]
74,145,093
<p>For some reason I acquire the same array but not the new array that repeats. I don't receive the new array that is supposed to be free of non-repeating values. I attempted to filter out the array through &quot;[i]&quot; and if it did not equal the value it pushes</p> <p><strong>Problem: Take the following array, remove the duplicates, and return a new array. You are more than likely going to want to check out the Array methods indexOf and includes. Do this in the form of a function uniquifyArray that receives an array of words as a argument.</strong></p> <pre class="lang-js prettyprint-override"><code>const words = [ 'crab', 'poison', 'contagious', 'simple', 'bring', 'sharp', 'playground', 'poison', 'communion', 'simple', 'bring', ] function uniquifyArray(arrays) { if (arrays.length === 0) { return null } let newArray = [] for (i = 0; i &lt; arrays.length; i++) { if (newArray[i] !== arrays[i]) { newArray.push(arrays[i]) } } return newArray } </code></pre>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20123957/" ]
74,145,106
<br> I have those two models Article and Tags <pre><code>class Article &lt; ApplicationRecord after_initialize :set_defaults belongs_to :author, class_name: &quot;User&quot; has_many :article_tags, dependent: :destroy has_many :tags, through: :article_tags validates :slug, presence: true, uniqueness: true validates :title, presence: :true validates :body, presence: :true validates :description, presence: :true validates :favorites_count, presence: :true scope :recent, -&gt; { order(created_at: :desc) } end </code></pre> <hr /> <pre><code>class Tag &lt; ApplicationRecord has_many :article_tags, dependent: :destroy has_many :articles, through: :article_tags validates :name, presence: true, uniqueness: true end </code></pre> <p>I Create those serializers for each model</p> <pre><code>class ArticleSerializer &lt; ActiveModel::Serializer attributes :title, :slug, :favorites_count, :description, :body, :favoritesCount attribute :updated_at, key: &quot;updatedAt&quot; attribute :created_at, key: &quot;createdAt&quot; has_many :tags, key: &quot;tagList&quot;, serializer: TagSerializer has_one :author, serializer: AuthorSerializer def favoritesCount # To be implemented 0 end end </code></pre> <hr /> <pre><code>class TagSerializer &lt; ActiveModel::Serializer attributes :name end </code></pre> <p>Here when I call the /articles api it returns like this which is logic since I put name attribute on my tag serializer</p> <p><a href="https://i.stack.imgur.com/beYP1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/beYP1.png" alt="enter image description here" /></a></p> <p>How can I make the tagList field returns an array of values instead of objects so it will be like this tagList = ['hola','test','react','angular']</p> <p>I'm using ruby 3.1 and rails 7.0 and ActiveModelSerializer</p> <p>Any help please??!</p>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15109007/" ]
74,145,108
<p>I want to access the value of the term 'just' but somehow it gives the error: 'NoneType' object is not subscriptable. How can I solve this</p> <pre><code>def count_words(word_list): &quot;Count word frequencies of words in a list.&quot; cnt_dict = dict() for word in word_list: if word in cnt_dict: cnt_dict[word] += 1 else: cnt_dict[word] = 1 print(cnt_dict) my_words = ['this', 'is', 'just', 'a', 'test', 'example', 'to', 'test', 'some', 'example', 'code'] cnt = count_words(my_words) cnt['just'] </code></pre>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19519766/" ]
74,145,125
<p>I am writing a program in Delphi that displays fresh information in balloons.</p> <p>Is there a way to determine which balloon I clicked on?</p> <p>Like this:</p> <pre><code>sendername := 'Gert'; TrayIcon1.Visible := True; TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!'; TrayIcon1.ShowBalloonHint; </code></pre> <p>...</p> <pre><code>sendername := 'Peter'; TrayIcon1.Visible := True; TrayIcon1.BalloonHint := 'You got a new message from '+sendername+'!'; TrayIcon1.ShowBalloonHint; </code></pre> <p>Now I would like to show the related letter in a BalloonClick event, but how can I determine which one was clicked?</p>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13635808/" ]
74,145,134
<p>I'm having issues writing an If statement in React Native. I'm building the mobile version of my React Js project where I already have the &quot;if&quot; statement but I'm not being able to write it in Native.</p> <p>Here is what I got so far:</p> <pre><code>{renderItems &amp;&amp; ( &lt;FlatList data={data} keyExtractor={(item)=&gt;{return item.date}} numColumns={numberOfCols} renderItem={({item})=&gt;( ####################################### if (item.copyright &quot;exists&quot; return ( &lt;Image source(require(a specific local image)/&gt; else( return the code below ####################################### &lt;View style={styles.viewpic}&gt; &lt;TouchableOpacity onPress={() =&gt; navigation.navigate('ImageDetails', item)}&gt; &lt;Image style={{ height: 104, width: square - 20, margin: 10, borderWidth: 1, borderColor:'white', borderRadius:2, }} source={{uri:item.url}}/&gt; &lt;/TouchableOpacity&gt; &lt;/View&gt; )} /&gt;) } </code></pre> <p>the code works fine without the if part. I tried a few combos with &quot;{&quot; ,&quot;(&quot; ,&quot;({&quot; but nothing worked.</p> <p>Thanks everyone for your help! Cheers,</p>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20029377/" ]
74,145,142
<p>In my App.js script it looks like this:</p> <pre><code>import React from &quot;react&quot;; function App() { const [colorsData, setColorsData] = React.useState(); React.useEffect(() =&gt; { const url = `https://www.thecolorapi.com/scheme?hex=0047AB&amp;rgb=0,71,171&amp;hsl=215,100%,34%&amp;cmyk=100,58,0,33&amp;mode=analogic&amp;count=6` fetch(url) .then(res =&gt; res.json()) .then(data =&gt; setColorsData(data)) }, []) console.log(colorsData); return ( &lt;div className=&quot;App&quot;&gt; &lt;h1&gt;{colorsData ? colorsData.colors[0].hex.value : &quot;Loading...&quot;}&lt;/h1&gt; &lt;img src={colorsData ? colorsData.colors[0].image.named : &quot;Loading...&quot;} /&gt; &lt;/div&gt; ); } export default App; </code></pre> <p>Instead of checking if there's <code>colorsData</code> or not in every element which approach should I use for more clean code? If I don't check if there's <code>colorsData</code>, I get an error for undefined.</p>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16620819/" ]
74,145,181
<p>I'm new to javascript. as I know using array.map over async function returns array of promises. and I can use await Promise.all to reolve all promise and it returns me data. <strong>I want to understand how can I use asyn function inside array of object's key. As I know using async function it never block as execution for unimportant line, ( here other execution is not dependent on url , so I'm trying to make it asynchronous)</strong></p> <pre><code>async function showPost() { const posts = [ { title: 'a', url: ['q', 'o'] }, { title: 'b', url: ['t', 'y'] }, ]; const formattedPost = await formatPosts(posts); console.log(formattedPost); } const formatPosts = async (posts) =&gt; { const formattedPosts = await Promise.all( // NOTE: await promise.all on map posts.map(async (post) =&gt; { post.url = addUrl(post.url); //NOTE: here if I don' add await here post.url is Promise&lt;Unknown&gt; return post; }) ); return formattedPosts; }; const addUrl = async (d) =&gt; { const mm = await Promise.all(d.map((item) =&gt; item + '-dummyUrl')); return mm; }; showPost(); </code></pre> <p>**CODE 1 without await , but inside await Promise.all ** <a href="https://i.stack.imgur.com/eHNpB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eHNpB.png" alt="enter image description here" /></a></p> <p><strong>CODE 2 with AWAIT on addURL call</strong> I get output</p> <p><a href="https://i.stack.imgur.com/H0EzN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H0EzN.png" alt="enter image description here" /></a></p> <p>Why is it not resolving though it is inside await promise.all</p> <p>thanks for help in advance</p>
[ { "answer_id": 74256399, "author": "Oleksandr Vasylenko", "author_id": 20294799, "author_profile": "https://Stackoverflow.com/users/20294799", "pm_score": 1, "selected": true, "text": "collectionView.leadingAnchor.constraint" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17214070/" ]
74,145,215
<p>I have to take two inputs from the user with % input example: 20% 30% I tried this<br /> <code>scanf(&quot;%d%d &quot;, &amp;x,&amp;y); </code></p> <p>how can I input two values with %? I can only take two integer values.</p>
[ { "answer_id": 74145316, "author": "hyde", "author_id": 1717300, "author_profile": "https://Stackoverflow.com/users/1717300", "pm_score": 2, "selected": false, "text": "%%" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294901/" ]
74,145,222
<p>I need to make validations on my custom ConstraintValidator that uses an @Inject needed for some validations, it's like this example from quarkus <a href="https://quarkus.io/guides/validation" rel="nofollow noreferrer">https://quarkus.io/guides/validation</a></p> <pre class="lang-java prettyprint-override"><code>@ApplicationScoped public class MyConstraintValidator implements ConstraintValidator&lt;MyConstraint, String&gt; { @Inject MyService service; @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return true; } return service.validate(value); } } </code></pre> <p>When i run the application I see that is made the right validation, but i'm trying to make unit test using mockito i can't mock the object is always null on the default using the Default Bean validation.</p> <p>On the example from quarkus is unit test only for integration.</p> <p>this is my implementation</p> <pre class="lang-java prettyprint-override"><code>@ApplicationScoped public class MyConstraintValidator implements ConstraintValidator&lt;MyConstraint, String&gt; { @Inject BookService service; @ConfigProperty(name = &quot;my.property&quot;) int myLimit; public MyConstraintValidator(BookService service) { this.service = service; } @Override public boolean isValid(String value, ConstraintValidatorContext context) { System.out.println(&quot;myLimit property: &quot; + myLimit); int limit = Integer.parseInt(value); if (limit &lt; myLimit) { return service.validate(value); } else { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(NAME_EMPTY).addConstraintViolation(); return false; } } } </code></pre> <p>Unit test for testing the custom Validator</p> <pre class="lang-java prettyprint-override"><code> @Test void testAmountValidationWithContext() { BookRequest bookRequest = new BookRequest(); bookRequest.setTitle(&quot;my title&quot;); bookRequest.setAuthor(&quot;my Author&quot;); bookRequest.setPages(2L); bookRequest.setAmount(&quot;11&quot;); //when: myConstraintValidator = new MyConstraintValidator(service); Mockito.when(service.validate(anyString())).thenReturn(true); //then: Set&lt;ConstraintViolation&lt;BookRequest&gt;&gt; violations = validator.validate(bookRequest); // verify that the context is called with the correct argument Mockito.verify(context).buildConstraintViolationWithTemplate(NAME_EMPTY); } </code></pre> <p>The unit test to test the default @NoBlank.</p> <pre class="lang-java prettyprint-override"><code> @Test void testBeanValidationWithInvalidAmount() { BookRequest bookRequest = new BookRequest(); bookRequest.setTitle(&quot;my title&quot;); bookRequest.setAuthor(&quot;my Author&quot;); bookRequest.setPages(2L); bookRequest.setAmount(&quot;AA&quot;); //when: Set&lt;ConstraintViolation&lt;BookRequest&gt;&gt; violations = validator.validate(bookRequest); //then: assertEquals(1, violations.size()); assertEquals(NOT_EMPTY, violations.stream().findFirst().get().getMessage()); } </code></pre> <p>The first unit test works weel, i can mock the object and test the result.</p> <p>The problem is on my second test, when i try to test the other validations @NotNull, @Pattern. On this test the method <strong>isValid()</strong> is also invoked and here it's my problem because the <strong>@ConfigProperty</strong> and the <strong>@Inject</strong> are always null, and i can't mocked them.</p> <p>I already saw several examples over internet but doesn't work and are almost for spring but i need to make the custom validation on quarkus.</p> <p>How can i implement the custom ConstraintValidator unit test using quarkus?</p> <p>Does any one have any example with this working?</p>
[ { "answer_id": 74145316, "author": "hyde", "author_id": 1717300, "author_profile": "https://Stackoverflow.com/users/1717300", "pm_score": 2, "selected": false, "text": "%%" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8007045/" ]
74,145,240
<p>I have connected to a REST API and the data is structured in a nested JSON format that requires some transformation before I can insert into a SQL table. I am trying to use Azure Data Factory (Copy into) to facilitate the transformation.</p> <p>Each UserID is an Object, so when I try to map the fields, it gives me an error that I have duplicate field mappings. <a href="https://i.stack.imgur.com/p3YMR.png" rel="nofollow noreferrer">see screenshot of mapping</a></p> <p>I do not know how to trim off the unnecessary data. This is what it looks like:</p> <pre><code> { &quot;count&quot;: 216, &quot;results&quot;: [ { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603444&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603297&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603298&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603445&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;16407315&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18636176&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18588630&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18588941&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603301&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603302&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603303&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18588634&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18722305&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603446&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18604710&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18624916&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18625925&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603447&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603448&quot; }, { &quot;key&quot;: &quot;users&quot;, &quot;id&quot;: &quot;18603305&quot; } ], &quot;users&quot;: { &quot;18603444&quot;: { &quot;full_name&quot;: &quot;&quot;, &quot;photo_path&quot;: &quot;&quot;, &quot;email_address&quot;: &quot;&quot;, &quot;headline&quot;: &quot;&quot;, &quot;generic&quot;: false, &quot;disabled&quot;: false, &quot;update_whitelist&quot;: [ &quot;full_name&quot;, &quot;headline&quot;, &quot;email_address&quot;, &quot;external_reference&quot;, &quot;linkedin_url&quot;, &quot;bio&quot;, &quot;website&quot;, &quot;company_name&quot;, &quot;address1&quot;, &quot;address2&quot;, &quot;city&quot;, &quot;state&quot;, &quot;zip&quot; ], &quot;account_id&quot;: &quot;&quot;, &quot;id&quot;: &quot;18603444&quot; }, &quot;18603302&quot;: { &quot;full_name&quot;: &quot;&quot;, &quot;photo_path&quot;: &quot;&quot;, &quot;email_address&quot;: &quot;&quot;, &quot;headline&quot;: &quot;&quot;, &quot;generic&quot;: false, &quot;disabled&quot;: false, &quot;update_whitelist&quot;: [ &quot;full_name&quot;, &quot;headline&quot;, &quot;email_address&quot;, &quot;external_reference&quot;, &quot;linkedin_url&quot;, &quot;bio&quot;, &quot;website&quot;, &quot;company_name&quot;, &quot;address1&quot;, &quot;address2&quot;, &quot;city&quot;, &quot;state&quot;, &quot;zip&quot; ], &quot;account_id&quot;: &quot;7600865&quot;, &quot;id&quot;: &quot;18603302&quot; }, &quot;18603303&quot;: { &quot;full_name&quot;: &quot;&quot;, &quot;photo_path&quot;: &quot;, &quot;email_address&quot;: &quot;&quot;, &quot;headline&quot;: &quot;&quot;, &quot;generic&quot;: false, &quot;disabled&quot;: false, &quot;update_whitelist&quot;: [ &quot;full_name&quot;, &quot;headline&quot;, &quot;email_address&quot;, &quot;external_reference&quot;, &quot;linkedin_url&quot;, &quot;bio&quot;, &quot;website&quot;, &quot;company_name&quot;, &quot;address1&quot;, &quot;address2&quot;, &quot;city&quot;, &quot;state&quot;, &quot;zip&quot; ], &quot;account_id&quot;: &quot;7600865&quot;, &quot;id&quot;: &quot;18603303&quot; }, &quot;meta&quot;: { &quot;count&quot;: 216, &quot;page_count&quot;: 11, &quot;page_number&quot;: 1, &quot;page_size&quot;: 20 }} </code></pre> <p>Each user is structured with their ID and their respective data. I want to remove the first part with the count and results and the last part with the meta and ONLY keep the data in each ID object. I think i can delete those two pieces in the mapping of the Copy into step, but I am not sure the best practice.</p> <p>How do I do this with Azure Data Factory and SQL? Or should I use an Azure Function? I am not allowed to use python or any other scripting (if it is possible). Can someone please assist?</p>
[ { "answer_id": 74145316, "author": "hyde", "author_id": 1717300, "author_profile": "https://Stackoverflow.com/users/1717300", "pm_score": 2, "selected": false, "text": "%%" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20292372/" ]
74,145,286
<p>Is there a way to call an async function from a sync one without waiting for it to complete?</p> <p>My current tests:</p> <ol> <li>Issue: Waits for test_timer_function to complete</li> </ol> <pre><code>async def test_timer_function(): await asyncio.sleep(10) return def main(): print(&quot;Starting timer at {}&quot;.format(datetime.now())) asyncio.run(test_timer_function()) print(&quot;Ending timer at {}&quot;.format(datetime.now())) </code></pre> <ol start="2"> <li>Issue: Does not call test_timer_function</li> </ol> <pre><code>async def test_timer_function(): await asyncio.sleep(10) return def main(): print(&quot;Starting timer at {}&quot;.format(datetime.now())) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) asyncio.ensure_future(test_timer_function()) print(&quot;Ending timer at {}&quot;.format(datetime.now())) </code></pre> <p>Any suggestions?</p>
[ { "answer_id": 74145609, "author": "jsbueno", "author_id": 108205, "author_profile": "https://Stackoverflow.com/users/108205", "pm_score": 2, "selected": false, "text": "await" }, { "answer_id": 74145765, "author": "S.B", "author_id": 13944524, "author_profile": "http...
2022/10/20
[ "https://Stackoverflow.com/questions/74145286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7976024/" ]
74,145,289
<p>python manage.py loaddata --settings <code>definme.settings.dev django-dump.json</code></p> <p>wagtail.models.i18n.Locale.DoesNotExist: Problem installing fixture Locale matching query does not exist.</p>
[ { "answer_id": 74145609, "author": "jsbueno", "author_id": 108205, "author_profile": "https://Stackoverflow.com/users/108205", "pm_score": 2, "selected": false, "text": "await" }, { "answer_id": 74145765, "author": "S.B", "author_id": 13944524, "author_profile": "http...
2022/10/20
[ "https://Stackoverflow.com/questions/74145289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294970/" ]
74,145,291
<p>I am trying to write a code that would select 5 numbers between 1-10 and choose the maximum of them. I repeat the experiment 1000 times but I want to see how many times ı get the which result</p> <pre><code>import random for i in range (1,1000): b = random.choices(range(1, 11), k=5) max(b) print(&quot;The X value for %(n)s is {%(c)s} &quot; % {'n': b, 'c': max(b)}) </code></pre> <p>I want to see something like 10 occurring 500 times, 9 occurring 300 times. I tried to define a dictionary but couldn't manage to do so. Any help would be appreciated</p>
[ { "answer_id": 74145371, "author": "scotscotmcc", "author_id": 15804190, "author_profile": "https://Stackoverflow.com/users/15804190", "pm_score": 1, "selected": false, "text": "import random\nnumber_counts = {x:0 for x in range(1,11)} # this will create a dictionary with 1-10 as keys an...
2022/10/20
[ "https://Stackoverflow.com/questions/74145291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20088393/" ]
74,145,294
<p>I accidentally merged a Pull Request when what I really meant to do was a squash and merge. As a result, my commit history now contains the ~20 individual commits from that PR.</p> <p><strong>My goal is twofold</strong>:</p> <ol> <li>Revert back to the last &quot;good&quot; commit</li> <li>Clear the &quot;bad&quot; commits from my commit history</li> </ol> <p><em>Most of these &quot;bad&quot; commits appear AFTER the last &quot;good&quot; commit, <strong>but a handful of them appear BEFORE the last &quot;good&quot; commit (I'm guessing this is due to their commit dates), which I'm afraid complicates things for me.</strong></em></p> <p>Fortunately, there haven't been any additional commits since this mistake was made.</p> <p>Based on my research thus far, I can revert back to the last &quot;good&quot; commit by doing the following:</p> <pre><code>git reset --hard &lt;commit-before-the-merge&gt; </code></pre> <p>But given that the &quot;bad&quot; commits appear both before AND after the last &quot;good&quot; commit, I'm uncertain this will resolve the issue, and I don't want to try it without being reasonably confident it will work.</p> <p>Will the command noted above do the trick, or should I be using a different set of commands to get myself out of this mess?</p>
[ { "answer_id": 74145573, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 2, "selected": true, "text": "parent:" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8016458/" ]
74,145,298
<p>I have a response currently like below, and I want it to make it in one line.</p> <p>Current Reponse:</p> <pre class="lang-json prettyprint-override"><code>[ { &quot;user_id&quot;:30826889, &quot;hr&quot;:{ &quot;1664325660&quot;:65, &quot;1664325720&quot;:65, &quot;1664325780&quot;:70 }, &quot;rr&quot;:{ &quot;1664325660&quot;:18, &quot;1664325720&quot;:17, &quot;1664325780&quot;:15 }, &quot;snoring&quot;:{ &quot;1664325660&quot;:0, &quot;1664325720&quot;:0, &quot;1664325780&quot;:0 } }, { &quot;user_id&quot;:30826889, &quot;hr&quot;:{ &quot;1664340780&quot;:72, &quot;1664340840&quot;:70, &quot;1664340900&quot;:71, &quot;1664340960&quot;:70, &quot;1664341020&quot;:67, &quot;1664341080&quot;:71, &quot;1664341140&quot;:69, &quot;1664341200&quot;:68, &quot;1664341260&quot;:66, &quot;1664341320&quot;:68 }, &quot;rr&quot;:{ &quot;1664340780&quot;:20, &quot;1664340840&quot;:20, &quot;1664340900&quot;:19, &quot;1664340960&quot;:20, &quot;1664341020&quot;:19, &quot;1664341080&quot;:19, &quot;1664341140&quot;:19, &quot;1664341200&quot;:21, &quot;1664341260&quot;:22, &quot;1664341320&quot;:22 }, &quot;snoring&quot;:{ &quot;1664340780&quot;:0, &quot;1664340840&quot;:0, &quot;1664340900&quot;:0, &quot;1664340960&quot;:0, &quot;1664341020&quot;:0, &quot;1664341080&quot;:0, &quot;1664341140&quot;:0, &quot;1664341200&quot;:0, &quot;1664341260&quot;:0, &quot;1664341320&quot;:0 } } ] </code></pre> <p>and so on....</p> <p>I want it like below to make it key value-pairs. Like this;</p> <pre><code>{&quot;user_id&quot;: 30826889, &quot;timestamp&quot;: &quot;166432xxxx&quot;,&quot;hr&quot;:65, &quot;rr&quot;:45, &quot;snoring&quot;:1 } {&quot;user_id&quot;: 30826889, &quot;timestamp&quot;: &quot;166432yyyy&quot;,&quot;hr&quot;:67, &quot;rr&quot;:23, &quot;snoring&quot;:2 } </code></pre> <p>and So on.... for every response..</p> <p>I tried many things but couldn't succeeded. Please guide, how can i achieve above.. ............................................</p>
[ { "answer_id": 74145573, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 2, "selected": true, "text": "parent:" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10186726/" ]
74,145,335
<ol start="0"> <li>An error occurred during the process of utilizing the notion API.</li> <li>I want to categorize the titles separately and make them look good, but my code can't find the variable 'title'.</li> </ol> <p>ERR: UnboundLocalError: local variable 'title' referenced before assignment</p> <pre><code>import requests, json def read_database(database_id, token): &quot;&quot;&quot; A function that receives and returns information from the database id &quot;&quot;&quot; headers = { &quot;Authorization&quot;: &quot;Bearer &quot; + token, &quot;Notion-Version&quot;: &quot;2022-06-28&quot; } read_url = f&quot;https://api.notion.com/v1/databases/{database_id}/query&quot; res = requests.request(&quot;POST&quot;, read_url, headers=headers) data = res.json() if res.status_code == 200: key_data = list(data[&quot;results&quot;][0][&quot;properties&quot;].keys()) print(&quot;Data lookup successful&quot;) for i in data[&quot;results&quot;][0][&quot;properties&quot;]: if &quot;title&quot; in i: title = i print(title) print(f&quot;The total number of columns is {len(key_data)} and the name of each item is&quot;) print(f&quot;{', '.join(key_data)}.&quot;) print(f&quot;The title type is {title} here.&quot;) </code></pre> <p>Below is the full error code.</p> <pre><code>Traceback (most recent call last): File &quot;/Users/notion_API/main.py&quot;, line 10, in &lt;module&gt; read_database(database_id, token) File &quot;/Users/notion_API/notion_function.py&quot;, line 36, in read_database print(f&quot;The title type is {title} here.&quot;) UnboundLocalError: local variable 'title' referenced before assignment </code></pre> <p>It's a problem I've had since I started Python. I'm taking this opportunity to ask you a proper questionPlease give me some advice</p>
[ { "answer_id": 74145388, "author": "Hyalunar", "author_id": 17781827, "author_profile": "https://Stackoverflow.com/users/17781827", "pm_score": 0, "selected": false, "text": "if 'title' in i" }, { "answer_id": 74145408, "author": "Asav Patel", "author_id": 2260553, "a...
2022/10/20
[ "https://Stackoverflow.com/questions/74145335", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294915/" ]
74,145,345
<p>I did quite a lot of research and did not find an answer to the following questions regarding the <a href="https://github.com/adeckmyn/maps" rel="nofollow noreferrer"><code>maps</code></a> package in R:</p> <p>(EDIT: I did not notice that it only works with <code>ggplot2</code>, as I still had this package cached in RStudio and I had the wrong assumption that <code>map_data()</code> is part of <code>maps</code> package, <a href="https://www.rdocumentation.org/packages/ggplot2/versions/3.3.6/topics/map_data" rel="nofollow noreferrer">whereas it's part of <code>ggplot2</code></a>. It's inserted into the code now.)</p> <pre><code>library(maps) library(ggplot2) map_data('world') </code></pre> <p>This outputs the data from the data frame object. The columns are <em>long</em>, <em>lat</em>, <em>group</em>, <em>order</em>, <em>region</em>, and <em>subregion</em>. <em>long</em> and <em>lat</em> columns contain single values for longitude and latitude. No other geometry data is visible in the data frame.</p> <pre><code>map('world') </code></pre> <p>This plots a world map with country polygons.</p> <p>So my questions are:</p> <ol> <li>Where is the geometry data of the polygons being stored?</li> <li>How can I access the geometry and work with it?</li> <li>How can I transform the geometry data to other useful formats like an <code>sf</code> object for example?</li> </ol> <p>I am quite new to R and maybe the answers are quite simple. Anyways, I could not find them by myself and any help is highly appreciated.</p> <p>EDIT: My goal is to visualise polygons from the <code>'world'</code> data of the <code>maps</code> package on an interactive map using <code>leaflet</code>. But if this is too complicated, I can use other sources for country polygons as well.</p>
[ { "answer_id": 74146159, "author": "Grzegorz Sapijaszko", "author_id": 17486894, "author_profile": "https://Stackoverflow.com/users/17486894", "pm_score": 3, "selected": true, "text": "world" }, { "answer_id": 74146703, "author": "winnewoerp", "author_id": 4921339, "a...
2022/10/20
[ "https://Stackoverflow.com/questions/74145345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4921339/" ]
74,145,352
<p>I have a dataframe that contains a column with state abbreviations ie. &quot;IA&quot;, &quot;IL&quot;, &quot;IN,&quot;, etc. I would like to create a new column in my dataframe that assigns each row with the corresponding region ie. &quot;Midwest&quot;, &quot;Northeast,&quot; etc. Is there a package or good way to do this manually/with <code>mutate()</code> or something similar?</p>
[ { "answer_id": 74145390, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "df1$region <- setNames(state.region, state.abb)[df1$stateabb]\n" } ]
2022/10/20
[ "https://Stackoverflow.com/questions/74145352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12317572/" ]
74,145,360
<p>I am very very new to python so I'm still figuring out the basics.</p> <p>I have a nested list with each element containing two strings like so:</p> <pre><code>mylist = [['Wowza', 'Here is a string'],['omg', 'yet another string']] </code></pre> <p>I would like to iterate through each element in mylist, and split the second string into multiple strings so it looks like:</p> <pre><code>mylist = [['wowza', 'Here', 'is', 'a', 'string'],['omg', 'yet', 'another', 'string']] </code></pre> <p>I have tried so many things, such as unzipping and</p> <pre><code>for elem in mylist: mylist.append(elem) NewList = [item[1].split(' ') for item in mylist] print(NewList) </code></pre> <p>and even</p> <pre><code>for elem in mylist: NewList = ' '.join(elem) def Convert(string): li = list(string.split(' ')) return li print(Convert(NewList)) </code></pre> <p>Which just gives me a variable that contains a bunch of lists</p> <p>I know I'm way over complicating this, so any advice would be greatly appreciated</p>
[ { "answer_id": 74145397, "author": "assume_irrational_is_rational", "author_id": 11622508, "author_profile": "https://Stackoverflow.com/users/11622508", "pm_score": 3, "selected": true, "text": "mylist = [['Wowza', 'Here is a string'],['omg', 'yet another string']]\nreq_list = [[i[0]]+ i...
2022/10/20
[ "https://Stackoverflow.com/questions/74145360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19853854/" ]
74,145,421
<p>Child component is managing the state of parent objects using callback function. The code blow works well with just one variable but gives and error while dealing with Objects. The error I get is while entering values to the textarea..</p> <blockquote> <p>remarks.map is not a function</p> </blockquote> <p>Please help me out with this problem.</p> <p>Also please do let me know if Ref here is of any use. Thank you.</p> <pre><code> return ( &lt;div className=&quot;container&quot;&gt; {remarks?.map((items: any) =&gt; { return ( &lt;div key={items?.id}&gt; &lt;label&gt; &lt;textarea name=&quot;remarkVal&quot; id={items?.id} onChange={(e) =&gt; onSliderChangeHandler(e)} value={items?.remarksVal} ref={childRef} placeholder={placeholder} /&gt; &lt;/label&gt; &lt;/div&gt; ); })} &lt;/div&gt; ); }; </code></pre> <p>Getting a new row on edit the code as per answers.</p> <pre><code> setChildState((prevState: any) =&gt; [ ...prevState, { [e.target.name]: e.target.value } ]); </code></pre>
[ { "answer_id": 74145397, "author": "assume_irrational_is_rational", "author_id": 11622508, "author_profile": "https://Stackoverflow.com/users/11622508", "pm_score": 3, "selected": true, "text": "mylist = [['Wowza', 'Here is a string'],['omg', 'yet another string']]\nreq_list = [[i[0]]+ i...
2022/10/20
[ "https://Stackoverflow.com/questions/74145421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19079815/" ]
74,145,441
<p>I am new to julia, and I am trying to take the irfft of B, which is a 3d array of size (n/2, n, n) where B = rfft(A). However, the irfft in julia reqires an additional input d for the size of the transformed real array, and I'm unsure of what to put. I tried n and n/2, but both did not seem to work as expected when I printed the resulting matrix out.</p> <p>EDIT: I should've lowered my dimensions to check if everything was working, turns out using d = n is ok. Thanks to everyone who answered!</p>
[ { "answer_id": 74148704, "author": "Bill", "author_id": 4282847, "author_profile": "https://Stackoverflow.com/users/4282847", "pm_score": 1, "selected": false, "text": "using FFTW\n\nfunction test(n = 16)\n a = rand(n ÷ 2, n, n)\n f = rfft(a)\n @show irfft(f, n ÷ 2 + 1)\nend\n\n...
2022/10/20
[ "https://Stackoverflow.com/questions/74145441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20200286/" ]
74,145,472
<p>I build a bash script to verify if certain container exists or not. If there is no input, it complains. Does your mind helping me?</p> <pre><code>#!/bin/bash if [[ $# -eq 0 ]] then echo &quot;Docker container ID not supplied&quot; elif [[ docker images | grep -q $1 ]] then echo &quot;No such container $1&quot; else echo $1 fi; </code></pre> <p>Edit:</p> <p>A common output for docker images is the sample below. In case the token matches the 12 input characters and no more, the container indeed exists.</p> <pre><code>REPOSITORY TAG IMAGE ID CREATED SIZE sappio latest 091f1bf3491c About an hour ago 556MB postgres 11.4 53912975086f 3 years ago 312MB node 7.7.2-alpine 95b4a6de40c3 5 years ago 59.2MB </code></pre> <p>The use cases for this shell script are:</p> <p>1.</p> <pre><code>input: bash has_contained_id.sh output: Docker container ID not supplied </code></pre> <ol start="2"> <li></li> </ol> <pre><code>input: bash has_contained_id.sh 1 output: &quot;No such container 1&quot; </code></pre> <ol start="3"> <li></li> </ol> <pre><code>input: bash has_contained_id.sh 091f1bf3491 output: &quot;No such container 091f1bf3491&quot; </code></pre> <ol start="4"> <li></li> </ol> <pre><code>input: bash has_contained_id.sh 091f1bf3491c output: &quot;091f1bf3491c&quot; </code></pre>
[ { "answer_id": 74148704, "author": "Bill", "author_id": 4282847, "author_profile": "https://Stackoverflow.com/users/4282847", "pm_score": 1, "selected": false, "text": "using FFTW\n\nfunction test(n = 16)\n a = rand(n ÷ 2, n, n)\n f = rfft(a)\n @show irfft(f, n ÷ 2 + 1)\nend\n\n...
2022/10/20
[ "https://Stackoverflow.com/questions/74145472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19299349/" ]
74,145,488
<p>What is the root of the error I get when running this function and why? The error I get is &quot;name 'one' is not defined&quot;. I did define it though?</p> <pre><code>def One(): one = input(&quot;Type something: &quot;) def Two(one): One() print(one) Two(one) </code></pre>
[ { "answer_id": 74145527, "author": "Luiz", "author_id": 13113537, "author_profile": "https://Stackoverflow.com/users/13113537", "pm_score": 1, "selected": false, "text": "one" }, { "answer_id": 74145551, "author": "nigh_anxiety", "author_id": 17030540, "author_profile...
2022/10/20
[ "https://Stackoverflow.com/questions/74145488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15821540/" ]
74,145,504
<p>I am trying to create a cash register system. Now I want to create an order list, which contains products and how many of each I sold. I am using redux store here.</p> <p>My problem is when I use the ADDORDERITEM case, it receives an action.order like {id: 1, name:&quot;halve zolen&quot;, categoryId:1, price: 1.0} for example. In the case statement, the numberOfOrderItems gets set to what number is at that moment in the state.numberOfOrderItems. This works for one item, but if I add the same item with a different amount, I end up with an array with 2 objects with the amount that was last entered, while this should be 2 different amounts here. If I check action.order after I set the numberOfOrderItems it is a correct order, so what is going wrong here? My guess it has something to do with me using state.numberOfOrderItems here which make a subscription to that, and updates it whenever this variable is used somewhere. Is there some way to just take a snapshot of it and never update it again?</p> <p>My code: Store.js:</p> <pre><code>import {createStore} from 'redux'; const kassaReducer = (state = {orders: [], numberOfOrderItems: &quot;&quot;}, action) =&gt; { switch (action.type){ case &quot;ADDORDERITEM&quot;: let newOrder = action.order; newOrder.numberOfOrderItems = state.numberOfOrderItems; return {orders: [...state.orders, newOrder], numberOfOrderItems: &quot;&quot;}; case &quot;REMOVEORDERITEM&quot;: return {orders : state.orders.remove(state.orders.indexOf(action.order)), numberOfOrderItems: state.numberOfOrderItems}; case &quot;SETITEMNUMBER&quot;: return {orders : state.orders, numberOfOrderItems: state.numberOfOrderItems === &quot;&quot; ? action.numberOfOrderItems : (state.numberOfOrderItems + action.numberOfOrderItems)}; } return state; } const store = createStore(kassaReducer); export default store; </code></pre>
[ { "answer_id": 74145520, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 1, "selected": true, "text": "action.order.numberOfOrderItems = state.numberOfOrderItems;\n" }, { "answer_id": 74147382, "author": "mark...
2022/10/20
[ "https://Stackoverflow.com/questions/74145504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13321125/" ]
74,145,512
<p>I have an array in which another array of agents is stored. In this agents array only the id of each agent is located. Using the id's, I fetch the data I need for each agent and I want to replace the original agent array with the new, completed agent data. Or at least push the new data to the specific agent. Here is what I have tried so far. Is there a simple way to do it?</p> <p><strong>How to use the fetched agent in filteredEvents?</strong> As seen in my expected result</p> <pre class="lang-js prettyprint-override"><code>filteredEvents: [ { agents: ['id', 'id'], // the id's are as plain text located eventData: '' } ] // Expected result filteredEvents: [ { agents: [ { id: '', name: '', ...}, // the data from the fetched id { id: '', name: '', ...}, ], eventData: '' } ] </code></pre> <pre class="lang-js prettyprint-override"><code>otherAgentsEvents() { // Not that relevant currently // const events = this.events // const user = this.getUser._id // const filteredEvents = events.filter(event =&gt; !event.agents.includes(user)); filteredEvents.forEach(event =&gt; { const agents = event.agents agents.forEach(agent =&gt; { const data = this.fetchAgentData(agent) // replace 'event.agents[agent]' with this data }) }) return filteredEvents } </code></pre> <pre class="lang-js prettyprint-override"><code>async fetchAgentData(agentID) { try { const agent = await this.$axios.$get(`/api/get-specific-agent/${agentID}`) if (agent.success) { return agent.data } } catch (err) { console.log(err) } } </code></pre> <p>Html for better understanding</p> <pre class="lang-html prettyprint-override"><code>&lt;div v-for=&quot;(event, key) in otherAgentsEvents&quot; :key=&quot;key&quot;&gt; &lt;div v-for=&quot;agent in event.agents&quot; :key=&quot;agent.id&quot;&gt; // Currently I haven't access to first_name etc. // only to agent where only the plain ID is stored &lt;p&gt;{{ agent.first_name }}&lt;/p&gt; &lt;/div&gt; &lt;div&gt; {{ event.eventData }} &lt;/div&gt; &lt;/div&gt; </code></pre> <hr /> <p><strong>Update based on tao's answer</strong></p> <p>I have tried to implement the code, but am probably doing something wrong. Here's what I did.</p> <p>I use <code>vuex</code>, I have never worked with <code>pinia</code>. <em>Reactive</em> is not defined, I left it out. I don't know where to get it.</p> <pre class="lang-js prettyprint-override"><code>import axios from 'axios' const store = { agents: [], getAgent: (id) =&gt; new Promise((resolve) =&gt; { console.log(id) const agent = store.agents.find(({ id: i }) =&gt; i === id) if (agent) { resolve(agent) } else { axios.get(`/api/get-specific-agent/${id}`).then(({ data }) =&gt; { store.agents.push(data) resolve(data) }) } }), } export const useAgents = () =&gt; store </code></pre> <pre class="lang-js prettyprint-override"><code>otherAgentsEvents() { // const events = this.events // const user = this.getUser._id // const filteredEvents = events.filter(event =&gt; // !event.agents.includes(user)) filteredEvents.map(async (event) =&gt; { const agents = event.agents event.agents = await Promise.all( agents.map((id) =&gt; useAgents().getAgent(id)) ) return event }) return filteredEvents }, </code></pre> <p>Here I actually achieve the wanted result for a short time, but then my app crashes with following errors.</p> <p><a href="https://i.stack.imgur.com/jRJxh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jRJxh.png" alt="Console" /></a> <a href="https://i.stack.imgur.com/sOKYq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sOKYq.png" alt="Console" /></a></p>
[ { "answer_id": 74145774, "author": "Ömer Can Korkmaz", "author_id": 12475930, "author_profile": "https://Stackoverflow.com/users/12475930", "pm_score": 2, "selected": false, "text": "for (const event of filteredEvents) {\n for (let agent of event.agents) {\n const data = this.fe...
2022/10/20
[ "https://Stackoverflow.com/questions/74145512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13212068/" ]