qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,660,809
<p>I have a page with a table and dynamic filters in it. When a filter changes, I need to redirect to the current page with a new or updated query parameter. For example, if I'm in the <code>/users</code> route and the name &quot;John&quot; is being searched, I need to redirect to <code>/users?name=john</code>. If I want to see all Johns with application role, I need to redirect to <code>/users?name=john&amp;hasRole=true</code> and so on. The reason for this is that a search result must be reproducible by sharing the URL.</p> <p>I need all query parameters as a <code>Dictionary&lt;string, string&gt;</code>. How can I bind all query parameters to a <code>Dictionary&lt;string, string&gt;</code> in Blazor WASM?</p>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19363672/" ]
74,660,815
<p>Working in Google AppsScript, specifically for an add-on, and I'm defining the SHEET_NAME as a const. Specifically:</p> <pre><code>const SHEET_NAME=&quot;Values&quot; </code></pre> <p>Since Google Sheets has a default name of &quot;Sheet1&quot; for all worksheets can I also make SHEET_NAME be associated to either &quot;Values&quot; or &quot;Sheet1&quot;?</p> <p>Basically, if someone doesn't choose to name their file &quot;Values&quot; then the variable will still know to run SHEET_NAME without breaking.</p> <p>Right now I have a function that is trying to use the SHEET_NAME variable, but again, trying to see if I can have it look for either &quot;Values&quot; or &quot;Sheet1&quot;</p> <p>Is something like <code>const SHEET_NAME=&quot;Values&quot; OR &quot;Sheet1&quot;</code> doable?</p>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20368159/" ]
74,660,923
<p>pthread_kill() funktion terminates my program every time I launch it after a creation of a thread and try to send a SIGALRM signal. By the way, it works if I add a sleep() function before pthread_kill(). Then I add sleep() function in thread, because it terminates earlier then sending a signal.</p> <pre><code>void* funkcja_watku(){ struct sigaction new_action = {.sa_handler = obsluga}; sigaction(SIGALRM, &amp;new_action, NULL); sleep(2); return 0; } int main(int argc, const char * argv[]) { pthread_t watek_id; //tworze watek if(pthread_create(&amp;watek_id, NULL, &amp;funkcja_watku, NULL)) printf(&quot;Watek nie zostal utworzony\n&quot;); sleep(1); //wysylam sygnal if(pthread_kill(watek_id, SIGALRM)) printf(&quot;Sygnal nie zostal wyslany\n&quot;); //usuwam watek if(pthread_join(watek_id, NULL)) printf(&quot;Watek nie zostal usuniety\n&quot;); return 0; } </code></pre> <p>I added the sleep function, but I dont think that It is the good way</p>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20378980/" ]
74,660,943
<p>I am supposed to write a program that processes a sequence of 100 positive numbers. The program should have 3 different functions, which could be chosen from a menu.</p> <ol> <li><p>Generate a number sequence with a random generator and print the numbers on the screen. The numbers generated should be in the range 0 ≤ n ≤ 900</p> </li> <li><p>I have to sort the sequence with bubble sort and then the numbers must be printed and I cannot use built-in sorting functions, such as qsort.</p> </li> <li><p>Quit program. The 1 and 2 must be in own functions. Lasly every time the program prints out the number, it should be printed as a table with ten rows and ten columns. Choice two can not be made unless choice one has been chosen.</p> </li> </ol> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; #define SIZE 100 #define N 10 #define INVALID 0 #define VALID 1 void randomNum() { //random number gen int num[SIZE] = {0}; int i = 0; srand(time(NULL)); for(i = 0; i &lt; SIZE; i++) { num[i] = rand() % 901; } for(i = 0; i &lt; SIZE; i++) { printf(&quot;%4d&quot;, num[i]); if(i % 10 == 9) printf(&quot;\n&quot;); } } void sort() { //sort of the generated number sequence int num[SIZE] = {0}; int i = 0; int j = 0; int temp = 0; for (int i = 0 ; i &lt; SIZE; i++) { for (int j = 0; j &lt; SIZE - 1; j++) { if (num[j] &gt; num[j+1]) { temp = num[j]; num[j] = num[j+1]; num[j+1] = temp; } } } for(i = 0; i &lt; SIZE; i++) { printf(&quot;%4d&quot;, num[i]); if(i % 10 == 9) printf(&quot;\n&quot;); } } int main() { randomNum(); printf(&quot;\n&quot;); sort(); return 0; } </code></pre> <p>I have figured out the solutions for how to generate a sequene and sort it and it works correct when all the code are in main() , however, when I put in in own functions above the main() it does not work. I'm stuck and don't know how to move forward. When i run the program it generates a random sequence but then the sorting function just prints out 100 zeros.</p>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20669753/" ]
74,660,956
<p>I want to copy specific content from the page, rather than the HTML itself. And the execCommand method, is deprecated, I tried with useRef(), but no progress</p> <p>How i solve this?</p> <pre><code> const div = useRef(null); const [copySuccess, setCopySuccess] = useState(false); const copyToClipboard = () =&gt; { const html = div.current.innerHTML.trim(); navigator.clipboard.writeText(html) setCopySuccess(true); }; &lt;div&gt; {user.name &amp;&amp; ( &lt;button type=&quot;submit&quot; style={{ margin-top: '30px', margin-bottom: '10px', height: '45px', width: '85px', background-color: '#1d71a5', color: '#fff', border: 'none', border-radius: '5px', font-size: '16px', cursor: 'pointer', }} onClick={copyToClipboard} &gt; Copy &lt;/button&gt; )} {copySuccess &amp;&amp; ( &lt;div style={{ color: 'green' }}&gt; ✔︎ Copy with Success! &lt;/div&gt; )} &lt;/div&gt; </code></pre> <p>I want to copy the signature email content</p> <p>Refrence: <a href="https://vdt-email-signature.vercel.app" rel="nofollow noreferrer">https://vdt-email-signature.vercel.app</a></p> <p>I tried to use the hook useRef, i tried to use this method :</p> <pre><code>const copyDivToClipboard = () =&gt; { const range = document.createRange() const selectedDiv = document.getElementById('generated-div') range?.selectNode(selectedDiv as Node) window?.getSelection()?.removeAllRanges() // clear current selection window?.getSelection()?.addRange(range) // to select text document.execCommand('copy') window?.getSelection()?.removeAllRanges() // to deselect alert('Message copied to clipboard!') } </code></pre> <p>But is a deprecated method.</p> <p>And so far I have no progress.</p>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18983132/" ]
74,660,989
<blockquote> <p>Write a class named <code>Die</code> that simulates rolling dice. The <code>Die</code> class should have one private data attribute named <code>__value</code>. It should also have the following methods:</p> <ul> <li><code>__init__</code> : The <code>__init__</code> method should assign 1 to the <code>__value</code> data attribute.</li> <li><code>roll</code>: The roll method should set the <code>__value</code> data attribute to a random number from 1 to 6.</li> <li><code>get_value</code>: The <code>get_value</code> function should return the value of the <code>__value</code> data attribute.</li> </ul> <p>Write a program that creates a <code>Die</code> object then uses a loop to roll the die 5 times. Each time the die is rolled, display its value.</p> </blockquote> <pre><code>import random(1,6) class Die: def __init__(self): self.number int(input(&quot;Enter a number 1-6&quot;:) def get_value(self): for n in number: def main(): in </code></pre>
[ { "answer_id": 74663956, "author": "Brandon Pugh", "author_id": 1715138, "author_profile": "https://Stackoverflow.com/users/1715138", "pm_score": 1, "selected": false, "text": "NavManager Microsoft.AspNetCore.WebUtilities ParseQuery protected override void OnInitialized()\n {\n var uri = NavManager.ToAbsoluteUri(NavManager.Uri);\n if (QueryHelpers.ParseQuery(uri.Query).TryGetValue(\"initialCount\", out var _initialCount))\n {\n currentCount = Convert.ToInt32(_initialCount);\n }\n }\n" }, { "answer_id": 74665606, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 0, "selected": false, "text": "@page \"/counter\"\n@inject NavigationManager NavManager\n\n<PageTitle>Counter</PageTitle>\n\n<h1>Counter</h1>\n\n<p role=\"status\">Current count: @CurrentCount</p>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(1)\">Increment</button>\n\n<button class=\"btn btn-primary\" @onclick=\"() => IncrementCount(50)\">Count plus 50</button>\n\n@code {\n [Parameter, SupplyParameterFromQuery] public int CurrentCount { get; set; } = 0;\n\n private void IncrementCount(int value)\n => NavManager.NavigateTo($\"/counter?CurrentCount={CurrentCount + value}\");\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18123819/" ]
74,660,990
<p>I have below inputs</p> <p><strong>input 1</strong>:</p> <pre><code>[{ &quot;id&quot;: &quot;3857&quot; }, { &quot;id&quot;: &quot;57&quot; }] </code></pre> <p><strong>input 2</strong>:</p> <pre><code>[{ &quot;Date&quot;: &quot;2022-11-30&quot;, &quot;name&quot;: &quot;salesorder&quot;, &quot;brand&quot;: &quot;Apple&quot;, &quot;Requests&quot;: &quot;111&quot;, &quot;price&quot;: &quot;917.65&quot; }, { &quot;Date&quot;: &quot;2022-11-13&quot;, &quot;name&quot;: &quot;orders&quot;, &quot;brand&quot;: &quot;TV&quot;, &quot;Requests&quot;: &quot;11&quot;, &quot;price&quot;: &quot;91.60&quot; }] </code></pre> <p><strong>input 3</strong>:</p> <pre><code>[{ &quot;count&quot;: &quot;3&quot; }, { &quot;count&quot;: &quot;4&quot; }] </code></pre> <p><strong>input 4</strong>:</p> <pre><code>[{ &quot;stock&quot;: &quot;21&quot;, &quot;sold&quot;: &quot;112&quot; }, { &quot;stock&quot;: &quot;2&quot;, &quot;sold&quot;: &quot;12&quot; }] </code></pre> <p><strong>Desired Output</strong>:</p> <pre><code>[{ &quot;id&quot;: &quot;3857&quot;, &quot;Date&quot;: &quot;2022-11-30&quot;, &quot;name&quot;: &quot;salesorder&quot;, &quot;brand&quot;: &quot;Apple&quot;, &quot;Requests&quot;: &quot;111&quot;, &quot;price&quot;: &quot;917.65&quot;, &quot;count&quot;: &quot;3&quot;, &quot;stock&quot;: &quot;21&quot;, &quot;sold&quot;: &quot;112&quot; }, { &quot;id&quot;: &quot;57&quot;, &quot;Date&quot;: &quot;2022-11-13&quot;, &quot;name&quot;: &quot;orders&quot;, &quot;brand&quot;: &quot;TV&quot;, &quot;Requests&quot;: &quot;11&quot;, &quot;price&quot;: &quot;91.60&quot;, &quot;count&quot;: &quot;4&quot;, &quot;stock&quot;: &quot;2&quot;, &quot;sold&quot;: &quot;12&quot; } ] </code></pre>
[ { "answer_id": 74661698, "author": "aled", "author_id": 721855, "author_profile": "https://Stackoverflow.com/users/721855", "pm_score": 2, "selected": true, "text": "$$ %dw 2.0\noutput application/json\nvar input1=[{\"id\": \"3857\"},{\"id\": \"57\"}]\nvar input2=[{\"Date\": \"2022-11-30\",\"name\": \"salesorder\",\"brand\": \"Apple\",\"Requests\": \"111\",\"price\":\"917.65\"},{\"Date\": \"2022-11-13\",\"name\": \"orders\",\"brand\": \"TV\",\"Requests\": \"11\",\"price\": \"91.60\"}] \nvar input3=[{\"count\": \"3\" },{\"count\": \"4\" }]\nvar input4=[{\"stock\": \"21\",\"sold\": \"112\"},{\"stock\": \"2\",\"sold\": \"12\"}]\n---\ninput1 map (input1[$$] ++ input2[$$] ++ input3[$$] ++ input4[$$])\n [\n {\n \"id\": \"3857\",\n \"Date\": \"2022-11-30\",\n \"name\": \"salesorder\",\n \"brand\": \"Apple\",\n \"Requests\": \"111\",\n \"price\": \"917.65\",\n \"count\": \"3\",\n \"stock\": \"21\",\n \"sold\": \"112\"\n },\n {\n \"id\": \"57\",\n \"Date\": \"2022-11-13\",\n \"name\": \"orders\",\n \"brand\": \"TV\",\n \"Requests\": \"11\",\n \"price\": \"91.60\",\n \"count\": \"4\",\n \"stock\": \"2\",\n \"sold\": \"12\"\n }\n]\n" }, { "answer_id": 74679512, "author": "Ryan Hoegg", "author_id": 1649678, "author_profile": "https://Stackoverflow.com/users/1649678", "pm_score": 0, "selected": false, "text": "++ (input1 zip input2) // produces an array of two element arrays\n map ($[0] ++ $[1]) // combines the two elements into a single object\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18239846/" ]
74,660,993
<p>I have a 2D gaussian function <code>f(x,y)</code>. I know the values <code>x₀</code> and <code>y₀</code> at which the peak <code>g₀</code> of the function occurs. But then I want to find <code>xₑ</code> and <code>yₑ</code> values at which <code>f(xₑ, yₑ) = g₀ / e¹</code>. I know there are multiple solutions to this, but at least one is sufficient.</p> <p>So far I have</p> <pre class="lang-py prettyprint-override"><code>def f(x, y, g0,x0,y0,sigma_x,sigma_y,offset): return offset + g0* np.exp(-(((x-x0)**(2)/(2*sigma_x**(2))) + ((y-y0)**(2)/(2*sigma_y**(2))))) </code></pre> <p><em>All variables taken as parameters are known</em> as they were extracted from a curve fit.</p> <p>I understand that taking the derivative in <code>x</code> and setting <code>f() = 0</code> and similarly in <code>y</code>, gives a solvable linear system for <code>(x,y)</code>, but this seems like overkill to manually implement, there must be some library or tool out there that can do what I am trying to achieve?</p>
[ { "answer_id": 74661672, "author": "Cyzanfar", "author_id": 3307520, "author_profile": "https://Stackoverflow.com/users/3307520", "pm_score": 1, "selected": false, "text": "from scipy.optimize import fsolve\n\n# Define the function f(x, y)\ndef f(x, y, g0, x0, y0, sigma_x, sigma_y, offset):\n return offset + g0 * np.exp(-(((x-x0)**(2)/(2*sigma_x**(2))) + ((y-y0)**(2)/(2*sigma_y**(2)))))\n\n# Define the function that we want to find the roots of\ndef g(xy, g0, x0, y0, sigma_x, sigma_y, offset):\n x, y = xy\n return f(x, y, g0, x0, y0, sigma_x, sigma_y, offset) - g0 / np.exp(1)\n\n# Define the initial guess for the root\nx0_guess = x0\ny0_guess = y0\n\n# Find the roots of the function g(x, y)\nx, y = fsolve(g, (x0_guess, y0_guess), args=(g0, x0, y0, sigma_x, sigma_y, offset))\n\n# Print the result\nprint(f\"x = {x}, y = {y}\")\n" }, { "answer_id": 74662950, "author": "Jérôme Richard", "author_id": 12939557, "author_profile": "https://Stackoverflow.com/users/12939557", "pm_score": 3, "selected": true, "text": "g0 (0,0) offset (xe, ye) (xe-x0)² / a² + (ye-y0)² / b² = 1 sigma_x = sigma_y (xe-x0)² + (ye-y0)² = r a b r sigma_x sigma_x sigma_y x0 y0 x0=0 y0=0 sigma_x=1 sigma_y=1 g0 offset f offset + g0 * h(xe,ye) = g0 / e h(x,y) = 1 / e - offset / g0 h(xe, ye) = exp(-(xe² + ye²)/2) h(xe, ye) = 1 / e - offset / g0 exp(-(xe² + ye²)/2) = 1 / e - offset / g0 -(xe² + ye²)/2 = ln(1 / e - offset / g0) xe² + ye² = -2 * ln(1 / e - offset / g0) r -2*ln(1 / e - offset / g0) ln offset + g0 * exp(-((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²))) = g0 / e exp(-((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²))) = 1 / e - offset / g0 -((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²)) = ln(1 / e - offset / g0) ((x-x0)²/sigma_x² + (y-y0)²/sigma_y²)/2 = -ln(1 / e - offset / g0) (x-x0)²/sigma_x² + (y-y0)²/sigma_y² = -2 * ln(1 / e - offset / g0) r = -2 * ln(1 / e - offset / g0) a = sigma_x b = sigma_y a = sigma_x/sqrt(r) b = sigma_y/sqrt(r) (x0, y0) y=y0 (x-x0)²/sigma_x² + (y0-y0)²/sigma_y² = -2 * ln(1 / e - offset / g0) (x-x0)²/sigma_x² = -2 * ln(1 / e - offset / g0) (x-x0)² = -2 * ln(1 / e - offset / g0) * sigma_x² x = sqrt(-2 * ln(1 / e - offset / g0) * sigma_x²) + x0 -sqrt(...) + x0 (xe, ye) = (sqrt(-2*ln(1/e-offset/g0)*sigma_x²)+x0, y0)" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74660993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12985747/" ]
74,661,003
<p>I want to send ether from one walet to another…what technique to use and what is the safest method to do so? wallet A(msg.sender)=10ether wallet B=10ether with the help of smart contract send 'x' ether from A to B.</p> <p>I tried where 'x' is the varaible ether at different times. =&gt;payable().transfer(msg.value); here i am able to send ether in remix ide where i can provide the msg.value...i want to implement that it is able to change msg.value according to the value of x.</p>
[ { "answer_id": 74661672, "author": "Cyzanfar", "author_id": 3307520, "author_profile": "https://Stackoverflow.com/users/3307520", "pm_score": 1, "selected": false, "text": "from scipy.optimize import fsolve\n\n# Define the function f(x, y)\ndef f(x, y, g0, x0, y0, sigma_x, sigma_y, offset):\n return offset + g0 * np.exp(-(((x-x0)**(2)/(2*sigma_x**(2))) + ((y-y0)**(2)/(2*sigma_y**(2)))))\n\n# Define the function that we want to find the roots of\ndef g(xy, g0, x0, y0, sigma_x, sigma_y, offset):\n x, y = xy\n return f(x, y, g0, x0, y0, sigma_x, sigma_y, offset) - g0 / np.exp(1)\n\n# Define the initial guess for the root\nx0_guess = x0\ny0_guess = y0\n\n# Find the roots of the function g(x, y)\nx, y = fsolve(g, (x0_guess, y0_guess), args=(g0, x0, y0, sigma_x, sigma_y, offset))\n\n# Print the result\nprint(f\"x = {x}, y = {y}\")\n" }, { "answer_id": 74662950, "author": "Jérôme Richard", "author_id": 12939557, "author_profile": "https://Stackoverflow.com/users/12939557", "pm_score": 3, "selected": true, "text": "g0 (0,0) offset (xe, ye) (xe-x0)² / a² + (ye-y0)² / b² = 1 sigma_x = sigma_y (xe-x0)² + (ye-y0)² = r a b r sigma_x sigma_x sigma_y x0 y0 x0=0 y0=0 sigma_x=1 sigma_y=1 g0 offset f offset + g0 * h(xe,ye) = g0 / e h(x,y) = 1 / e - offset / g0 h(xe, ye) = exp(-(xe² + ye²)/2) h(xe, ye) = 1 / e - offset / g0 exp(-(xe² + ye²)/2) = 1 / e - offset / g0 -(xe² + ye²)/2 = ln(1 / e - offset / g0) xe² + ye² = -2 * ln(1 / e - offset / g0) r -2*ln(1 / e - offset / g0) ln offset + g0 * exp(-((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²))) = g0 / e exp(-((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²))) = 1 / e - offset / g0 -((x-x0)²/(2*sigma_x²) + (y-y0)²/(2*sigma_y²)) = ln(1 / e - offset / g0) ((x-x0)²/sigma_x² + (y-y0)²/sigma_y²)/2 = -ln(1 / e - offset / g0) (x-x0)²/sigma_x² + (y-y0)²/sigma_y² = -2 * ln(1 / e - offset / g0) r = -2 * ln(1 / e - offset / g0) a = sigma_x b = sigma_y a = sigma_x/sqrt(r) b = sigma_y/sqrt(r) (x0, y0) y=y0 (x-x0)²/sigma_x² + (y0-y0)²/sigma_y² = -2 * ln(1 / e - offset / g0) (x-x0)²/sigma_x² = -2 * ln(1 / e - offset / g0) (x-x0)² = -2 * ln(1 / e - offset / g0) * sigma_x² x = sqrt(-2 * ln(1 / e - offset / g0) * sigma_x²) + x0 -sqrt(...) + x0 (xe, ye) = (sqrt(-2*ln(1/e-offset/g0)*sigma_x²)+x0, y0)" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18026681/" ]
74,661,015
<p>First, apologies if this sounds too basic. I have the following semi-structured data in text format, I need to parse these into a structured format: example:</p> <pre><code>Name Alex Address 14 high street London Color blue red Name Bob Color black </code></pre> <p>**Note that Alex has two colors, while Bob does not have an address. **</p> <p>I want something that looks like this:</p> <p><a href="https://i.stack.imgur.com/RHt45.png" rel="nofollow noreferrer">example output</a></p> <p>I think the right way is using regular expressions, but I'm struggling to split the text properly since some fields may be missing. What's a proper clean way to do this?</p> <pre><code>text='Name\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\nBob\nColor\nblack' profiles=re.split('(Name\n)', text, flags=re.IGNORECASE) for profile in profiles: #get name name=re.split('(Name\n)|(Address\n)|(Color\n)', profile.strip(), flags=re.IGNORECASE)[0] print(name) #get address #get color </code></pre>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14889338/" ]
74,661,025
<p>I have a dataframe that has duplicates based on their identifying ID, but some of the columns are different. I'd like to keep the rows (or the duplicates) that have the extra bit of info. The structure of the df is as such.</p> <pre><code>id &lt;- c(&quot;3235453&quot;, &quot;3235453&quot;, &quot;21354315&quot;, &quot;21354315&quot;, &quot;2121421&quot;) Plan_name&lt;- c(&quot;angers&quot;, &quot;strasbourg&quot;, &quot;Benzema&quot;, &quot;angers&quot;, &quot;montpellier&quot;) service_line&lt;- c(&quot;&quot;, &quot;AMRS&quot;, &quot;&quot;, &quot;Therapy&quot;, &quot;&quot;) treatment&lt;-c(&quot;&quot;, &quot;MH&quot;, &quot;&quot;, &quot;MH&quot;, &quot;&quot;) df &lt;- data.frame (id, Plan_name, treatment, service_line) </code></pre> <p>As you can see, the ID row has duplicates, but I'd like to keep the second duplicate where there is more info in <code>treatment</code> and <code>service_line</code>.</p> <p>I have tried using</p> <pre><code>df[duplicated(df[,c(1,3)]),] </code></pre> <p>but it doesn't work as an empty df is returned. Any suggestions?</p>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19989813/" ]
74,661,034
<p>I'm trying to learn some flutter programming and I'm facing a problem, when I run the program I don't get the information on the screen at the first time, I mean the data is retreived from firestore but I have to reload the page several times to show the data on the screen, what might be happening I am using FutureBuilder</p> <p><em>pet_page.dart</em></p> <pre><code>import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:histovet/src/controller/pet_controller.dart'; import 'package:histovet/src/models/pet_model.dart'; import 'package:histovet/src/pages/widgets/menu_lateral.dart'; import 'package:histovet/src/pages/pet/add_pets.dart'; import 'package:histovet/src/pages/pet/pet_update.dart'; // Clases encargadas de la vista donde se enlistan todas las ventas que existan en la // base de datos class PetsPage extends StatefulWidget { static String id = &quot;pets_page&quot;; const PetsPage({Key? key}) : super(key: key); @override State&lt;PetsPage&gt; createState() =&gt; _PetsPageState(); } class _PetsPageState extends State&lt;PetsPage&gt; { TextStyle txtStyle = const TextStyle( fontWeight: FontWeight.w900, fontSize: 30, color: Colors.black); PetController petCont = PetController(); bool answer = false; @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( appBar: AppBar( centerTitle: true, title: const Text(&quot;Mascotas&quot;), actions: [ IconButton( onPressed: () { setState(() {}); }, icon: const Icon(Icons.refresh)) ], ), //drawer: const MenuLateral(), floatingActionButton: FloatingActionButton.extended( icon: const Icon(FontAwesomeIcons.plus), label: const Text('Registrar nueva mascota'), elevation: 15.0, backgroundColor: Colors.blue, onPressed: () { Navigator.pushNamed(context, AddPet.id); }), body: FutureBuilder( future: petCont.allPets(), builder: (BuildContext context, AsyncSnapshot&lt;List&gt; snapshot) { if (snapshot.hasError) { print(&quot;error&quot;); return const Text('Error'); } else if (snapshot.hasData) { List species = snapshot.data ??[]; print(species); return Padding( padding: const EdgeInsets.all(8.0), child: ListView( children: [ for (Pet specie in species) Card( margin: const EdgeInsets.all(6), elevation: 6, child: Container( decoration: const BoxDecoration( image: DecorationImage( image: AssetImage('assets/img/fondo.jpg'), fit: BoxFit.cover, opacity: 0.3), ), child: ListTile( onLongPress: () { Navigator.push( context, MaterialPageRoute( builder: (context) =&gt; UpdatePet( specie.id.toString(), specie.owner.toString()))); }, leading: const Icon( FontAwesomeIcons.paw, color: Colors.black, ), title: Text( specie.name, style: txtStyle, ), subtitle: Text( specie.specie, style: txtStyle.copyWith(fontSize: 17), ), trailing: IconButton( icon: const Icon(Icons.delete, color: Colors.black), onPressed: () { messageDelete(specie.id.toString()); Navigator.pushNamed(context, '/pets') .then((_) =&gt; setState(() {})); }, ))), ) ], ), ); } else { return const Text('Empty data'); } })), ); } // Le indica al usuario si se pudo o no eliminar el registro void messageDelete(String idPet) async { answer = await petCont.deletePet(idPet); if (answer) { Navigator.pushNamed(context, '/pets').then((_) =&gt; setState(() {})); ScaffoldMessenger.of(context).showSnackBar(const SnackBar( content: Text(&quot;Se eliminó el registro de la mascota&quot;), backgroundColor: Colors.green, )); } else { ScaffoldMessenger.of(context).showSnackBar(const SnackBar( content: Text(&quot;No se pudo eliminar el registro de la mascota&quot;), backgroundColor: Colors.green, )); } } } </code></pre> <p><em>pet_controller.dart</em></p> <pre><code>Future&lt;List&lt;Pet&gt;&gt; allPets() async { try{ _pets = await _service.getPetsBD(); return _pets; } catch (e) { return _pets; } } </code></pre> <p><em>pet_service.dart</em></p> <pre><code>Future&lt;List&lt;Pet&gt;&gt; getPetsBD() async { List&lt;Pet&gt; mascotas = []; final FirebaseAuth auth = FirebaseAuth.instance; final User? user = auth.currentUser; final uid = user?.uid; try { final collection = FirebaseFirestore.instance .collection('pets') .where('owner', isEqualTo: uid); collection.snapshots().listen((querySnapshot) { for (var doc in querySnapshot.docs) { Map&lt;String, dynamic&gt; data = doc.data(); Pet newPet = Pet( data[&quot;id&quot;], data[&quot;owner&quot;], data[&quot;birthday&quot;].toString(), data[&quot;name&quot;], data[&quot;neutering&quot;], data[&quot;age&quot;], data[&quot;breed&quot;], data[&quot;specie&quot;], data[&quot;color&quot;], data[&quot;gender&quot;], data[&quot;clinic&quot;]); mascotas.add(newPet); } }); return mascotas; } catch (e) { return mascotas; } } </code></pre>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16564884/" ]
74,661,056
<p>As a beginner in Ruby, is there a quick to extract the first and second number from this string <code>5.16.0.0-15</code>? In this case, I am looking <code>5</code> and <code>16</code>. Thanks</p>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15217560/" ]
74,661,100
<p>I have a dimensional array and I would like to order it by expiryDate ascending and keep the ones with the null value last</p> <p>here is my array:</p> <pre><code>$lessons = [ [ &quot;expiryDate&quot; =&gt; Null ], [ &quot;expiryDate&quot; =&gt; &quot;2023-11-27&quot; ], [ &quot;expiryDate&quot; =&gt; &quot;2022-11-27&quot; ] ]; </code></pre> <p>What I tried :</p> <pre><code>$price = array_column($lessons, 'expiryDate'); array_multisort($price, SORT_ASC, $lessons); </code></pre> <p>Its working fine, but I don't know how I can move the ones with expiryDate last</p> <p>The expected Result :</p> <pre><code>$lessons = [ [ &quot;expiryDate&quot; =&gt; &quot;2022-11-27&quot; ], [ &quot;expiryDate&quot; =&gt; &quot;2023-11-27&quot; ], [ &quot;expiryDate&quot; =&gt; Null ] ]; </code></pre>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15187482/" ]
74,661,120
<p>I need to make a form with 2 input fields. When you press submit it should take you to a new page and display the input data.</p> <p>This is my html code</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot; /&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt; &lt;title&gt;Film survey&lt;/title&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; /&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form&quot; action=&quot;./Success.html&quot;&gt; &lt;h1&gt;Movie survey&lt;/h1&gt; &lt;p&gt;Thank you for participating in the film festival!&lt;/p&gt; &lt;p&gt;Please fill out this short survey so we can record your feedback&lt;/p&gt; &lt;div&gt; &lt;label for=&quot;film&quot;&gt;What film did you watch?&lt;/label&gt; &lt;/div&gt; &lt;div&gt; &lt;input type=&quot;text&quot; id=&quot;film&quot; name=&quot;film&quot; required /&gt; &lt;/div&gt; &lt;div&gt; &lt;label for=&quot;rating&quot; &gt;How would you rate the film? (1 - very bad, 5 - very good) &lt;/label&gt; &lt;/div&gt; &lt;input type=&quot;text&quot; id=&quot;rating&quot; name=&quot;rating&quot; required /&gt; &lt;div&gt;&lt;button class=&quot;submit&quot;&gt;Submit&lt;/button&gt;&lt;/div&gt; &lt;/form&gt; &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is my js code</p> <pre><code>const formEl = document.querySelector(&quot;#form&quot;); formEl.addEventListener(&quot;submit&quot;, (event) =&gt; { event.preventDefault(); const formData = new FormData(formEl); fetch(&quot;https://reqres.in/api/form&quot;, { method: &quot;POST&quot;, headers: { &quot;Content-Type&quot;: &quot;application/json&quot;, }, body: JSON.stringify({ film: formData.get(&quot;film&quot;), rating: formData.get(&quot;rating&quot;), }), }) .then((response) =&gt; { window.location.href = &quot;./Success.html&quot;; }) .catch((error) =&gt; { console.error(error); }); }); </code></pre> <p>I have a second html page called Success.html which I want to display tha data given in the form. I need to make a mock API so I tried using reqres.</p> <p>This is my Success.html page</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot; /&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt; &lt;title&gt;Success&lt;/title&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; /&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Thank you for your feedback!&lt;/h1&gt; &lt;p&gt;You watched: &lt;span id=&quot;film&quot;&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;You rated it: &lt;span id=&quot;rating&quot;&gt;&lt;/span&gt;&lt;/p&gt; &lt;script&gt; const formData = JSON.parse(request.body); const filmEl = document.querySelector(&quot;#film&quot;); const ratingEl = document.querySelector(&quot;#rating&quot;); filmEl.textContent = formData.film; ratingEl.textContent = formData.rating; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I thought this would work but I get this error after pressing submit:</p> <p>`` Success.html:16 Uncaught ReferenceError: request is not defined at Success.html:16:35</p>
[ { "answer_id": 74661172, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "s = \"\"\"\\\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\"\"\"\n\n\nimport pandas as pd\nfrom itertools import groupby\n\ncolnames = [\"Name\", \"Address\", \"Color\"]\n\n\ncol1, col2 = [], []\nfor k, g in groupby(\n (l for l in s.splitlines() if l.strip()), lambda l: l in colnames\n):\n (col2, col1)[k].append(\" \".join(g))\n\ndf = pd.DataFrame({\"col1\": col1, \"col2\": col2})\ndf = df.assign(col3=df.col1.eq(\"Name\").cumsum()).pivot(\n index=\"col3\", columns=\"col1\", values=\"col2\"\n)\ndf.index.name, df.columns.name = None, None\n\n\ndf[\"Color\"] = df[\"Color\"].str.split()\ndf = df.explode(\"Color\").fillna(\"\")\n\nprint(df[colnames])\n Name Address Color\n1 Alex 14 high street London blue\n1 Alex 14 high street London red\n2 Bob black\n" }, { "answer_id": 74661364, "author": "RagingRoosevelt", "author_id": 4365003, "author_profile": "https://Stackoverflow.com/users/4365003", "pm_score": 0, "selected": false, "text": "s = \"\"\"\nName\nAlex\n\nAddress\n14 high street\nLondon\n\nColor\nblue\nred\n\nName\n\nBob\nColor\nblack\n\"\"\"\n 'Name' entities = [e for e in s.split('Name')]\n [\n '\\n',\n '\\nAlex\\n\\nAddress\\n14 high street\\nLondon\\n\\nColor\\nblue\\nred\\n\\n',\n '\\n\\nBob\\nColor\\nblack\\n'\n]\n entities = [e.replace('\\n',' ').replace(' ',' ') for e in entities]\n [\n ' ',\n ' Alex Address 14 high street London Color blue red ',\n ' Bob Color black '\n]\n entities = [\n [x for x in e.split(' ') if x != '']\n for e in entities\n]\n [\n [],\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n entities = [e for e in entities if len(e) > 0]\n [\n ['Alex', 'Address', '14', 'high', 'street', 'London', 'Color', 'blue', 'red'],\n ['Bob', 'Color', 'black']\n]\n # We'll store our findings here. \n# We'll use the name, which is the first element of our 'entity' list, \n# as the key for this dict.\n\nproperties = {}\n\nfor entity in entities:\n # We'll figure out where each token shows up in our list\n token_indices = []\n for token in tokens:\n # we could use \n # token_indices.append(entity.index(token)) \n # if we knew that each token would only show up once\n token_indices += [i for i,t in enumerate(entity) if t==token]\n\n # now we'll sort the list of indices so that we can be sure\n # we're dealing with them in order\n token_indices = sorted(token_indices)\n \n # since we haven't seen this person before, we'll establish a \n # dict for their properties.\n\n\n\n individual_properties = {}\n \n for k,_ in enumerate(token_indices):\n this_tkn_name = entity[token_indices[k]]\n this_tkn_idx = token_indices[k]\n next_tkn_idx = token_indices[k+1]\n\n # We'll iterate over each token's index\n if k+1 < len(token_indices):\n # this isn't the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:next_tkn_idx])\n\n else:\n # this is the last token\n individual_properties[\n this_tkn_name\n ] = ' '.join(entity[this_tkn_idx+1:])\n \n # the first element in the entity list is their name, so we can\n # find that with entity[0]\n properties[entity[0]] = individual_properties\n {\n 'Alex': {\n 'Address': '14 high street London', \n 'Color': 'blue red'\n },\n 'Bob': {\n 'Color': 'black'\n }\n}\n split(' ')" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20077666/" ]
74,661,123
<p>I have tried to use the 'quit()' function in python and the spyder's compiler keep says me &quot;quit&quot; is not defined</p> <pre class="lang-py prettyprint-override"><code>print(&quot;Welcome to my computer quiz&quot;) playing = input(&quot;Do you want to play? &quot;) if (playing != &quot;yes&quot; ): quit() print(&quot;Okay! Let's play :)&quot;) </code></pre> <p>the output keep says me &quot;name 'quit' is not defined&quot;, how can i solve that problem?</p>
[ { "answer_id": 74661152, "author": "Thomas Weller", "author_id": 480982, "author_profile": "https://Stackoverflow.com/users/480982", "pm_score": 1, "selected": true, "text": "print(\"Welcome to my computer quiz\")\n\nplaying = input(\"Do you want to play? \")\n\nif (playing == \"yes\" ):\n print(\"Okay! Let's play :)\")\n" }, { "answer_id": 74661221, "author": "The Myth", "author_id": 15042008, "author_profile": "https://Stackoverflow.com/users/15042008", "pm_score": 2, "selected": false, "text": "quit() exit() quit() exit() print(\"Welcome to my computer quiz\")\n\nplaying = input(\"Do you want to play? \")\n\nif (playing != \"yes\" ):\n exit()\n \nprint(\"Okay! Let's play :)\")\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20669866/" ]
74,661,125
<p>I am having trouble with a bootstrap 5 accordion. They all expand without issue but won't collapse back down. I don't know if my JS or CSS is causing an issue. I don't see any errors in Chrome's console.</p> <p><a href="https://www.harpercollege.edu/dev/whoward-dev-area/df.php" rel="nofollow noreferrer">https://www.harpercollege.edu/dev/whoward-dev-area/df.php</a></p> <p>I copied them into codepen and didn't have any issues.</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-html lang-html prettyprint-override"><code> &lt;h2&gt;Important Dates (Fall 2022)&lt;/h2&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e639"&gt; 16-Week Classes (August 22 - December 16)&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e639" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="harperTable"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 18-20, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Fall priority registration begins&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 21, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Open registration for Fall 2022 for all students.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 22, 2022&lt;/td&gt; &lt;td&gt;16-week classes begin this week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 29, 2022&lt;/td&gt; &lt;td&gt;Last day to drop for 100% refund for 16-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 5, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of Labor Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 7, 2022&lt;/td&gt; &lt;td&gt;First Financial Aid Disbursement&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 8, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of General Election Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 21, 2022&lt;/td&gt; &lt;td&gt;Last day to withdraw from 16-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 23-27, 2022&lt;/td&gt; &lt;td&gt;Thanksgiving Break&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;December 12-16, 2022&lt;/td&gt; &lt;td&gt;Final Exam Week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;December 21, 2022&lt;/td&gt; &lt;td&gt;Grades available online&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e685"&gt; First 8-Week Classes (August 22 - October 16)&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e685" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="harperTable"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 18-20, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Fall priority registration begins&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 21, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Open registration for Fall 2022 for all students.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 22, 2022&lt;/td&gt; &lt;td&gt;First 8-week classes begin this week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 29, 2022&lt;/td&gt; &lt;td&gt;Last day to drop for 100% refund for first 8-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 5, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of Labor Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 7, 2022&lt;/td&gt; &lt;td&gt;First Financial Aid Disbursement&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;October 3, 2022&lt;/td&gt; &lt;td&gt;Last day to withdraw from first 8-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;October 16, 2022&lt;/td&gt; &lt;td&gt;First 8-week classes end&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e722"&gt; Second 8-Week Classes (October 17 - December 11)&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e722" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="harperTable"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 18-20, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Fall priority registration begins&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 21, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Open registration for Fall 2022 for all students.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;October 17, 2022&lt;/td&gt; &lt;td&gt;Second 8-week classes begin this week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;October 24, 2022&lt;/td&gt; &lt;td&gt;Last day to drop for 100% refund for second 8-week classes.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 8, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of General Election Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 23-27, 2022&lt;/td&gt; &lt;td&gt;Thanksgiving Break&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 28, 2022&lt;/td&gt; &lt;td&gt;Last day to withdraw from second 8-week classes.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;December 11, 2022&lt;/td&gt; &lt;td&gt;Second 8-week term ends&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e759"&gt; First 13-week Classes (August 22 - November 20)&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e759" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="harperTable"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 18-20, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Fall priority registration begins&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 21, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Open registration for Fall 2022 for all students.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 22, 2022&lt;/td&gt; &lt;td&gt;First 13-week classes begin this week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;August 29, 2022&lt;/td&gt; &lt;td&gt;Last day to drop for 100% refund for first 13-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 5, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of Labor Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 7, 2022&lt;/td&gt; &lt;td&gt;First Financial Aid Disbursement&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 8, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of General Election Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;October 31, 2022&lt;/td&gt; &lt;td&gt;Last day to withdraw from first 13-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 22, 2022&lt;/td&gt; &lt;td&gt;First 13-week classes end.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e799"&gt; Second 13-week Classes (September 19 - December 16)&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e799" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;div class="harperTable"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 18-20, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Fall priority registration begins&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span&gt;April 21, 2022&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span&gt;Open registration for Fall 2022 for all students.&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 19, 2022&lt;/td&gt; &lt;td&gt;Second 13-week classes begin this week&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;September 26, 2022&lt;/td&gt; &lt;td&gt;Last day to drop for 100% refund for second 13-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 8, 2022&lt;/td&gt; &lt;td&gt;College closed in observance of General Election Day&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 23-27, 2022&lt;/td&gt; &lt;td&gt;Thanksgiving Break&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;November 28, 2022&lt;/td&gt; &lt;td&gt;Last day to withdraw from second 13-week classes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;December 16, 2022&lt;/td&gt; &lt;td&gt;Second 13-week classes end.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e836"&gt; Important Dates for All Parts of Term&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e836" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;p&gt;&lt;a href="https://www.harpercollege.edu/registration/pdf/web_dates_04192022.pdf"&gt;Fall 2022 Important Dates for All Parts of Term (pdf)&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="accordion"&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-alt-1"&gt; &lt;div class="accordion-heading"&gt;&lt;a class="accordion-toggle collapsed" data-bs-toggle="collapse" aria-expanded="false" href="#collapse_d15e846"&gt; Final Examination Schedule&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="collapse_d15e846" class="accordion-body collapse"&gt; &lt;div class="accordion-inner"&gt; &lt;p&gt;&lt;a href="https://www.harpercollege.edu/registration/pdf/finalexamschedule_fall_2022.pdf"&gt;Final Examination Schedule Fall 2022 (pdf)&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt;&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/js/bootstrap.min.js"&gt;&lt;/script&gt;&lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74661249, "author": "TC_Guy", "author_id": 19597666, "author_profile": "https://Stackoverflow.com/users/19597666", "pm_score": 1, "selected": false, "text": ".FAQ {\n margin: 0 auto;\n max-width: 100%;\n}\n\n.FAQcard {\n margin: 10px 0;\n position: relative;\n}\n\n.FAQtitle {\n background: #fff;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);\n color: #000;\n font-weight: bold;\n font-size: 150%;\n cursor: default;\n display: block;\n padding: 1em 1.5em;\n position: relative;\n text-align: left;\n}\n\n.FAQtitle::after {\n content: \" \";\n width: 8px;\n height: 8px;\n border-right: 1px solid #4a6e78;\n border-bottom: 1px solid #4a6e78;\n position: absolute;\n right: 20px;\n top: 20px;\n -webkit-transform: rotate(-45deg);\n transform: rotate(-45deg);\n -webkit-transition: all 0.2s ease-in-out;\n transition: all 0.2s ease-in-out;\n}\n\n.FAQtitle.active::after {\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n -webkit-transition: all 0.2s ease-in-out;\n transition: all 0.2s ease-in-out;\n}\n\n.FAQpanel {\n background: #f1f2f3;\n color: #000;\n display: none;\n margin: 0;\n padding: 2em;\n text-align: left;\n}\n\n.FAQpanel p {\n margin-bottom: 5px;\n text-align: justify;\n}\n <div class=\"FAQ\">\n <div class=\"FAQcard\">\n <div class=\"FAQtitle\">Test Panel 1</div>\n <div class=\"FAQpanel fs-5\">\n Test text for panel 1\n </div>\n </div>\n <div class=\"FAQcard\">\n <div class=\"FAQtitle\">Test Panel 2</div>\n <div class=\"FAQpanel fs-5\">\n Test text for panel 2\n </div>\n </div>\n </div>\n \n $(\".FAQtitle\").click(function (j) {\n var dropDown = $(this).closest(\".FAQcard\").find(\".FAQpanel\");\n $(this).closest(\".FAQ\").find(\".FAQpanel\").not(dropDown).slideUp();\n if ($(this).hasClass(\"active\")) {\n $(this).removeClass(\"active\").removeClass(\"selected\");\n } else {\n $(this).closest(\".FAQ\").find(\".FAQtitle.active\").removeClass(\"active\").removeClass(\"selected\");\n $(this).addClass(\"active selected\");\n }\n dropDown.stop(false, true).slideToggle();\n j.preventDefault();\n });\n" }, { "answer_id": 74661320, "author": "Monirul Islam", "author_id": 10975723, "author_profile": "https://Stackoverflow.com/users/10975723", "pm_score": 3, "selected": true, "text": "<h2>Important Dates (Fall 2022)</h2>\n<div class=\"accordion-content\" id=\"accordionExample\">\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e639\">\n 16-Week Classes (August 22 - December 16)</a></div>\n </div>\n <div id=\"collapse_d15e639\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <div class=\"harperTable\">\n <table>\n <tbody>\n <tr>\n <td><span>April 18-20, 2022</span></td>\n <td><span>Fall priority registration begins</span></td>\n </tr>\n <tr>\n <td><span>April 21, 2022</span></td>\n <td><span>Open registration for Fall 2022 for all students.</span></td>\n </tr>\n <tr>\n <td>August 22, 2022</td>\n <td>16-week classes begin this week</td>\n </tr>\n <tr>\n <td>August 29, 2022</td>\n <td>Last day to drop for 100% refund for 16-week classes</td>\n </tr>\n <tr>\n <td>September 5, 2022</td>\n <td>College closed in observance of Labor Day</td>\n </tr>\n <tr>\n <td>September 7, 2022</td>\n <td>First Financial Aid Disbursement</td>\n </tr>\n <tr>\n <td>November 8, 2022</td>\n <td>College closed in observance of General Election Day</td>\n </tr>\n <tr>\n <td>November 21, 2022</td>\n <td>Last day to withdraw from 16-week classes</td>\n </tr>\n <tr>\n <td>November 23-27, 2022</td>\n <td>Thanksgiving Break</td>\n </tr>\n <tr>\n <td>December 12-16, 2022</td>\n <td>Final Exam Week</td>\n </tr>\n <tr>\n <td>December 21, 2022</td>\n <td>Grades available online</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e685\">\n First 8-Week Classes (August 22 - October 16)</a></div>\n </div>\n <div id=\"collapse_d15e685\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <div class=\"harperTable\">\n <table>\n <tbody>\n <tr>\n <td><span>April 18-20, 2022</span></td>\n <td><span>Fall priority registration begins</span></td>\n </tr>\n <tr>\n <td><span>April 21, 2022</span></td>\n <td><span>Open registration for Fall 2022 for all students.</span></td>\n </tr>\n <tr>\n <td>August 22, 2022</td>\n <td>First 8-week classes begin this week</td>\n </tr>\n <tr>\n <td>August 29, 2022</td>\n <td>Last day to drop for 100% refund for first 8-week classes</td>\n </tr>\n <tr>\n <td>September 5, 2022</td>\n <td>College closed in observance of Labor Day</td>\n </tr>\n <tr>\n <td>September 7, 2022</td>\n <td>First Financial Aid Disbursement</td>\n </tr>\n <tr>\n <td>October 3, 2022</td>\n <td>Last day to withdraw from first 8-week classes</td>\n </tr>\n <tr>\n <td>October 16, 2022</td>\n <td>First 8-week classes end</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e722\">\n Second 8-Week Classes (October 17 - December 11)</a></div>\n </div>\n <div id=\"collapse_d15e722\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <div class=\"harperTable\">\n <table>\n <tbody>\n <tr>\n <td><span>April 18-20, 2022</span></td>\n <td><span>Fall priority registration begins</span></td>\n </tr>\n <tr>\n <td><span>April 21, 2022</span></td>\n <td><span>Open registration for Fall 2022 for all students.</span></td>\n </tr>\n <tr>\n <td>October 17, 2022</td>\n <td>Second 8-week classes begin this week</td>\n </tr>\n <tr>\n <td>October 24, 2022</td>\n <td>Last day to drop for 100% refund for second 8-week classes.</td>\n </tr>\n <tr>\n <td>November 8, 2022</td>\n <td>College closed in observance of General Election Day</td>\n </tr>\n <tr>\n <td>November 23-27, 2022</td>\n <td>Thanksgiving Break</td>\n </tr>\n <tr>\n <td>November 28, 2022</td>\n <td>Last day to withdraw from second 8-week classes.</td>\n </tr>\n <tr>\n <td>December 11, 2022</td>\n <td>Second 8-week term ends</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e759\">\n First 13-week Classes (August 22 - November 20)</a></div>\n </div>\n <div id=\"collapse_d15e759\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <div class=\"harperTable\">\n <table>\n <tbody>\n <tr>\n <td><span>April 18-20, 2022</span></td>\n <td><span>Fall priority registration begins</span></td>\n </tr>\n <tr>\n <td><span>April 21, 2022</span></td>\n <td><span>Open registration for Fall 2022 for all students.</span></td>\n </tr>\n <tr>\n <td>August 22, 2022</td>\n <td>First 13-week classes begin this week</td>\n </tr>\n <tr>\n <td>August 29, 2022</td>\n <td>Last day to drop for 100% refund for first 13-week classes</td>\n </tr>\n <tr>\n <td>September 5, 2022</td>\n <td>College closed in observance of Labor Day</td>\n </tr>\n <tr>\n <td>September 7, 2022</td>\n <td>First Financial Aid Disbursement</td>\n </tr>\n <tr>\n <td>November 8, 2022</td>\n <td>College closed in observance of General Election Day</td>\n </tr>\n <tr>\n <td>October 31, 2022</td>\n <td>Last day to withdraw from first 13-week classes</td>\n </tr>\n <tr>\n <td>November 22, 2022</td>\n <td>First 13-week classes end.</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e799\">\n Second 13-week Classes (September 19 - December 16)</a></div>\n </div>\n <div id=\"collapse_d15e799\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <div class=\"harperTable\">\n <table>\n <tbody>\n <tr>\n <td><span>April 18-20, 2022</span></td>\n <td><span>Fall priority registration begins</span></td>\n </tr>\n <tr>\n <td><span>April 21, 2022</span></td>\n <td><span>Open registration for Fall 2022 for all students.</span></td>\n </tr>\n <tr>\n <td>September 19, 2022</td>\n <td>Second 13-week classes begin this week</td>\n </tr>\n <tr>\n <td>September 26, 2022</td>\n <td>Last day to drop for 100% refund for second 13-week classes</td>\n </tr>\n <tr>\n <td>November 8, 2022</td>\n <td>College closed in observance of General Election Day</td>\n </tr>\n <tr>\n <td>November 23-27, 2022</td>\n <td>Thanksgiving Break</td>\n </tr>\n <tr>\n <td>November 28, 2022</td>\n <td>Last day to withdraw from second 13-week classes</td>\n </tr>\n <tr>\n <td>December 16, 2022</td>\n <td>Second 13-week classes end.</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e836\">\n Important Dates for All Parts of Term</a></div>\n </div>\n <div id=\"collapse_d15e836\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <p><a href=\"https://www.harpercollege.edu/registration/pdf/web_dates_04192022.pdf\">Fall 2022\n Important Dates for All Parts of Term (pdf)</a></p>\n </div>\n </div>\n </div>\n </div>\n <div class=\"accordion\">\n <div class=\"accordion-group\">\n <div class=\"accordion-alt-1\">\n <div class=\"accordion-heading\"><a class=\"accordion-toggle collapsed\" data-bs-toggle=\"collapse\"\n aria-expanded=\"false\" href=\"#collapse_d15e846\">\n Final Examination Schedule</a></div>\n </div>\n <div id=\"collapse_d15e846\" class=\"accordion-body collapse\" data-bs-parent=\"#accordionExample\">\n <div class=\"accordion-inner\">\n <p><a href=\"https://www.harpercollege.edu/registration/pdf/finalexamschedule_fall_2022.pdf\">Final\n Examination Schedule Fall 2022 (pdf)</a></p>\n </div>\n </div>\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.0/js/bootstrap.min.js\"></script>\n </div>\n\n </div>\n</div>\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8641435/" ]
74,661,127
<p>I create different <code>numpy</code> arrays as follows:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np a = np.array([[1,2,3],[1,2,3]]) # 2d array of integers b = np.array([[1,2,3],[1,2,5.0]]) # 2d array of floats c = np.array([1,2,3,4,5,6,7,8,9]) # 1d array of integers d = np.array([10,20,30]) # different 1d array of integers # python buffer object pointing to the start of the arrays data. print(a.data) print(b.data) print(c.data) print(d.data) </code></pre> <p>According to the numpy docs i expect to get a &quot;<em>python buffer object pointing to the start of the arrays data</em>&quot;. Here is the official doc (from the numpy website): <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.data.html" rel="nofollow noreferrer">https://numpy.org/doc/stable/reference/generated/numpy.ndarray.data.html</a></p> <p>So i would <strong>expect a different memory address</strong> for each array.</p> <p>but i get this:</p> <pre><code>&lt;memory at 0x000001EAE8B7CAD0&gt; &lt;memory at 0x000001EAE8B7CAD0&gt; &lt;memory at 0x000001EAE98E8A00&gt; &lt;memory at 0x000001EAE98E8A00&gt; </code></pre> <ul> <li>The first two have the same memory buffer object pointer.</li> <li>And the second two have the same memory buffer object pointer.</li> </ul> <p>Is <code>numpy</code> inferring the memory buffer object pointer based on the dimension of the array or if not, what is the rule that generates similar pointer addresses ?</p>
[ { "answer_id": 74661258, "author": "sj95126", "author_id": 13843268, "author_profile": "https://Stackoverflow.com/users/13843268", "pm_score": 2, "selected": false, "text": ".data >>> d.data\n<memory at 0x6ffff70bddc0>\n>>> d.data\n<memory at 0x6ffff70bdb80>\n>>> d.data\n<memory at 0x6ffff70bd1c0>\n print()" }, { "answer_id": 74661305, "author": "hpaulj", "author_id": 901925, "author_profile": "https://Stackoverflow.com/users/901925", "pm_score": 2, "selected": true, "text": "In [38]: type(a.data)\nOut[38]: memoryview\n docs In [39]: a.data?\nType: memoryview\nString form: <memory at 0x000002AE38BAF5F0>\nLength: 2\nDocstring: Create a new memoryview object which references the given object.\n view In [45]: aa = np.ndarray(a.shape, a.dtype, buffer=a.data) \nIn [46]: aa\nOut[46]: \narray([[1, 2, 3],\n [1, 2, 3]]) \nIn [47]: aa.base is a\nOut[47]: True\n data __array_interface__ In [48]: a.__array_interface__\nOut[48]: \n{'data': (2947257325392, False),\n 'strides': None,\n 'descr': [('', '<i4')],\n 'typestr': '<i4',\n 'shape': (2, 3),\n 'version': 3}\nIn [49]: aa.__array_interface__['data']\nOut[49]: (2947257325392, False)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7318120/" ]
74,661,141
<p>I faced a problem with React CSS. My server is picking up, but my CSS properties are not working on my component. How can I fix this problem? I tried many ways to figure it out but I didn't get a good response.</p> <p><code>App.js</code> file codes:</p> <pre><code>import styles from &quot;./App.module.css&quot;; import { ReactDOM } from &quot;react&quot;; import { useEffect, useState } from &quot;react&quot;; import { init, subscribe } from &quot;./socketApi&quot;; import Palatte from &quot;./components/Palatte&quot;; function App() { const [activeColor, setActiveColor] = useState(&quot;#282c34&quot;); useEffect(() =&gt; { init(); subscribe((color) =&gt; { setActiveColor(color); }); }, []); return ( &lt;div className=&quot;App&quot; style={{ backgroundColor: activeColor }}&gt; &lt;h1&gt;{activeColor}&lt;/h1&gt; &lt;Palatte activeColor={activeColor} /&gt; &lt;/div&gt; ); } export default App; </code></pre> <p>CSS file codes:</p> <pre><code>.App { display: flex; justify-content: center; align-items: center; height: 100vh; flex-direction: column; } .palette { display: flex; flex-direction: column; margin-top: 40px; } .palette button { margin-top: 10px; } </code></pre> <p>I tried many ways to fix it but I didn't get a solution.</p> <p><a href="https://i.stack.imgur.com/6Q4GA.png" rel="nofollow noreferrer">Current view on browser</a></p>
[ { "answer_id": 74661177, "author": "kenan238", "author_id": 13339604, "author_profile": "https://Stackoverflow.com/users/13339604", "pm_score": 1, "selected": false, "text": "import ... from ... import ./App.module.css import from" }, { "answer_id": 74661180, "author": "David", "author_id": 13019276, "author_profile": "https://Stackoverflow.com/users/13019276", "pm_score": 0, "selected": false, "text": "className=\"App\" className={styles.App}" }, { "answer_id": 74661214, "author": "Andrew Shearer", "author_id": 10688837, "author_profile": "https://Stackoverflow.com/users/10688837", "pm_score": 0, "selected": false, "text": "styles import \"./App.module.css\"; const App = () => {\n const [activeColor, setActiveColor] = useState(\"#282c34\");\n\n return (\n <div className={styles.App}>\n <h1>{activeColor}</h1>\n </div>\n );\n};\n import { ReactDOM } from \"react\";\n\nimport { useEffect, useState } from \"react\";\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19584644/" ]
74,661,146
<p>I am learning Java and I have some difficulties with the package mechanism. I have different classes in a package. I compiled it right but when I execute the Main file I have a different behavior. <em>Music3</em> is the file where is the main method.</p> <pre><code>andrea@andrea:~/Documenti/java$ java -Xdiag -cp class/ source/Music3 Errore: impossibile trovare o caricare la classe principale source.Music3 Causato da: java.lang.ClassNotFoundException: source.Music3 java.lang.ClassNotFoundException: source.Music3 at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:398) at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:791) at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:686) andrea@andrea:~/Documenti/java$ java -Xdiag -cp class/ source/Music3.java Wind.play() C_Sharp Percussion.play() C_Sharp Stringed.play() C_Sharp </code></pre> <p>As you can see I have the right output when I execute Music3.java. What is wrong?</p>
[ { "answer_id": 74661198, "author": "rzwitserloot", "author_id": 768644, "author_profile": "https://Stackoverflow.com/users/768644", "pm_score": -1, "selected": false, "text": "java java -Xdiag -cp class source.Music3 project/src/sposito/Music3.java package sposito; project/class/sposito/Music3.class project java -cp class sposito.Music3" }, { "answer_id": 74661276, "author": "CodingClown", "author_id": 20669969, "author_profile": "https://Stackoverflow.com/users/20669969", "pm_score": 1, "selected": false, "text": ".class java -Xdiag -cp class/ source/Music3.class ClassNotFoundException java java -cp class/ java Music3.class java java -Xdiag -cp class/source Music3\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17050000/" ]
74,661,176
<p><a href="https://pastebin.com/ZViCXL2b" rel="nofollow noreferrer">Grades.txt file</a></p> <p>I am currently trying to finish a assignment but I am confused on how to fix this error. I am creating a program that will analyzes grades from a file and should calculate the average score for each distinct section (given). I receive the error for</p> <p>sections[sec][&quot;total&quot;] = grade[grade]</p> <pre><code>grades = {'A': 100, 'B': 89, 'C': 79, 'D': 74, 'F': 69} # this section reads the file def calculate_average(): file = open(&quot;grades.txt&quot;, &quot;r&quot;) sections = {} for line in file: [_, sec, grade] = line.split(&quot;\t&quot;) grade = grade.strip() if sec in sections: sections[sec][&quot;count&quot;] += 1 sections[sec][&quot;total&quot;] += grade[grade] else: sections[sec] = {} sections[sec][&quot;count&quot;] = 1 sections[sec][&quot;total&quot;] = grade[grade] file.close() # This section calculates the average data based on file for sec, secdata in sections.items(): avg = secdata[&quot; total &quot;] / secdata[&quot; count&quot;] print(&quot; {0} : {1}&quot;.format(sec, round(avg, 2))) if __name__ == &quot;__main__&quot;: calculate_average() </code></pre>
[ { "answer_id": 74661217, "author": "CodingClown", "author_id": 20669969, "author_profile": "https://Stackoverflow.com/users/20669969", "pm_score": 1, "selected": true, "text": "grade grade grade sections[sec][\"total\"] += grades[grade]\n grades = {'A': 100, 'B': 89, 'C': 79, 'D': 74, 'F': 69}\n\n# this section reads the file\n\n\ndef calculate_average():\n file = open(\"grades.txt\", \"r\")\n sections = {}\n for line in file:\n [_, sec, grade] = line.split(\"\\t\")\n grade = grade.strip()\n if sec in sections:\n sections[sec][\"count\"] += 1\n sections[sec][\"total\"] += grades[grade]\n else:\n sections[sec] = {}\n sections[sec][\"count\"] = 1\n sections[sec][\"total\"] = grades[grade]\n file.close()\n\n# This section calculates the average data based on file\n\n for sec, secdata in sections.items():\n avg = secdata[\" total \"] / secdata[\" count\"]\n print(\" {0} : {1}\".format(sec, round(avg, 2)))\n\n\nif __name__ == \"__main__\":\n calculate_average()\n" }, { "answer_id": 74661229, "author": "Fabi", "author_id": 20669997, "author_profile": "https://Stackoverflow.com/users/20669997", "pm_score": 0, "selected": false, "text": "sections[sec][\"total\"] = grades[grade]\n" }, { "answer_id": 74661755, "author": "GAP2002", "author_id": 14608493, "author_profile": "https://Stackoverflow.com/users/14608493", "pm_score": -1, "selected": false, "text": "grades grade grade grades sections[sec][\"total\"] = grades[grade]\n def calculate_average():\n file = open(\"grades.txt\", \"r\")\n sections = {}\n for line in file:\n [_, sec, grade] = line.split(\"\\t\")\n grade = grade.strip()\n if sec in sections:\n sections[sec][\"count\"] += 1\n sections[sec][\"total\"] += grades[grade]\n else:\n sections[sec] = {}\n sections[sec][\"count\"] = 1\n sections[sec][\"total\"] = grades[grade]\n file.close()\n\n for sec, secdata in sections.items():\n avg = secdata[\" total \"] / secdata[\" count\"]\n print(\" {0} : {1}\".format(sec, round(avg, 2)))\n with with if for if for print(\" {sec} : {avg:.2f}\".format(sec=sec, avg=avg))\n def calculate_average():\n with open(\"grades.txt\", \"r\") as file:\n sections = {}\n for line in file:\n _, section, grade = line.split(\"\\t\")\n grade = grade.strip()\n if section not in sections:\n sections[section] = {\"count\": 0, \"total\": 0}\n sections[section][\"count\"] += 1\n sections[section][\"total\"] += grades[grade]\n\n for section, section_data in sections.items():\n avg = section_data[\"total\"] / section_data[\"count\"]\n print(\" {section} : {avg:.2f}\".format(section=section, avg=avg))\n sections[section][\"total\"] += grades.get(grade, 0)\n# rather than\nsections[section][\"total\"] += grades[grade]\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20669921/" ]
74,661,219
<p>I have 2 dataframes with same columns and indexes.</p> <pre><code> a a 1 [] 1 [5,2,7] 2 [1,2,3] 2 [1,2,3,4] 3 [7] 3 [7,5] </code></pre> <p>I want to merge them using condition, when length of list is &lt;=1 then take value and add it to 1st data frame, else left old value.</p> <p>So after that result is:</p> <pre><code> a 1 [5,2,7] 2 [1,2,3] 3 [7,5] </code></pre> <p>What is the best way to do this?</p>
[ { "answer_id": 74661217, "author": "CodingClown", "author_id": 20669969, "author_profile": "https://Stackoverflow.com/users/20669969", "pm_score": 1, "selected": true, "text": "grade grade grade sections[sec][\"total\"] += grades[grade]\n grades = {'A': 100, 'B': 89, 'C': 79, 'D': 74, 'F': 69}\n\n# this section reads the file\n\n\ndef calculate_average():\n file = open(\"grades.txt\", \"r\")\n sections = {}\n for line in file:\n [_, sec, grade] = line.split(\"\\t\")\n grade = grade.strip()\n if sec in sections:\n sections[sec][\"count\"] += 1\n sections[sec][\"total\"] += grades[grade]\n else:\n sections[sec] = {}\n sections[sec][\"count\"] = 1\n sections[sec][\"total\"] = grades[grade]\n file.close()\n\n# This section calculates the average data based on file\n\n for sec, secdata in sections.items():\n avg = secdata[\" total \"] / secdata[\" count\"]\n print(\" {0} : {1}\".format(sec, round(avg, 2)))\n\n\nif __name__ == \"__main__\":\n calculate_average()\n" }, { "answer_id": 74661229, "author": "Fabi", "author_id": 20669997, "author_profile": "https://Stackoverflow.com/users/20669997", "pm_score": 0, "selected": false, "text": "sections[sec][\"total\"] = grades[grade]\n" }, { "answer_id": 74661755, "author": "GAP2002", "author_id": 14608493, "author_profile": "https://Stackoverflow.com/users/14608493", "pm_score": -1, "selected": false, "text": "grades grade grade grades sections[sec][\"total\"] = grades[grade]\n def calculate_average():\n file = open(\"grades.txt\", \"r\")\n sections = {}\n for line in file:\n [_, sec, grade] = line.split(\"\\t\")\n grade = grade.strip()\n if sec in sections:\n sections[sec][\"count\"] += 1\n sections[sec][\"total\"] += grades[grade]\n else:\n sections[sec] = {}\n sections[sec][\"count\"] = 1\n sections[sec][\"total\"] = grades[grade]\n file.close()\n\n for sec, secdata in sections.items():\n avg = secdata[\" total \"] / secdata[\" count\"]\n print(\" {0} : {1}\".format(sec, round(avg, 2)))\n with with if for if for print(\" {sec} : {avg:.2f}\".format(sec=sec, avg=avg))\n def calculate_average():\n with open(\"grades.txt\", \"r\") as file:\n sections = {}\n for line in file:\n _, section, grade = line.split(\"\\t\")\n grade = grade.strip()\n if section not in sections:\n sections[section] = {\"count\": 0, \"total\": 0}\n sections[section][\"count\"] += 1\n sections[section][\"total\"] += grades[grade]\n\n for section, section_data in sections.items():\n avg = section_data[\"total\"] / section_data[\"count\"]\n print(\" {section} : {avg:.2f}\".format(section=section, avg=avg))\n sections[section][\"total\"] += grades.get(grade, 0)\n# rather than\nsections[section][\"total\"] += grades[grade]\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9631920/" ]
74,661,270
<p>The script is this</p> <pre><code>#!/bin/bash echo echo &quot;################################################################&quot; echo &quot; Installing Htop &quot; echo &quot;################################################################&quot; echo if ! location=$(type -p &quot;htop&quot;); then sudo apt install -y htop fi </code></pre> <p>I'm confused as to what this code snippet from the script does <code>location=$(type -p &quot;htop&quot;);</code> I need a clear explanation about this.</p>
[ { "answer_id": 74661325, "author": "choroba", "author_id": 1030675, "author_profile": "https://Stackoverflow.com/users/1030675", "pm_score": 3, "selected": true, "text": "! location=... $location $(...) type -p htop htop $PATH htop htop $location sudo apt install -y htop apt htop yes" }, { "answer_id": 74661330, "author": "chepner", "author_id": 1126841, "author_profile": "https://Stackoverflow.com/users/1126841", "pm_score": 1, "selected": false, "text": "type type -p htop htop location htop sudo apt install -y htop location htop" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19806392/" ]
74,661,277
<p>I have a JSON file. While the original file is quite large, I reduced to a much smaller reproducible example for the purposes of this question (I still get the same error no matter what size):</p> <pre><code>{ &quot;relationships_followers&quot;: [ { &quot;title&quot;: &quot;&quot;, &quot;media_list_data&quot;: [ ], &quot;string_list_data&quot;: [ { &quot;href&quot;: &quot;https://www.instagram.com/testaccount1&quot;, &quot;value&quot;: &quot;testaccount1&quot;, &quot;timestamp&quot;: 1669418204 } ] }, { &quot;title&quot;: &quot;&quot;, &quot;media_list_data&quot;: [ ], &quot;string_list_data&quot;: [ { &quot;href&quot;: &quot;https://www.instagram.com/testaccount2&quot;, &quot;value&quot;: &quot;testaccount2&quot;, &quot;timestamp&quot;: 1660426426 } ] }, { &quot;title&quot;: &quot;&quot;, &quot;media_list_data&quot;: [ ], &quot;string_list_data&quot;: [ { &quot;href&quot;: &quot;https://www.instagram.com/testaccount3&quot;, &quot;value&quot;: &quot;testaccount3&quot;, &quot;timestamp&quot;: 1648230499 } ] }, { &quot;title&quot;: &quot;&quot;, &quot;media_list_data&quot;: [ ], &quot;string_list_data&quot;: [ { &quot;href&quot;: &quot;https://www.instagram.com/testaccount4&quot;, &quot;value&quot;: &quot;testaccount4&quot;, &quot;timestamp&quot;: 1379513403 } ] } ] } </code></pre> <p>I am attempting to convert it into a dataframe in R, which contains the values for <code>href</code>, <code>value</code>, and the <code>timestamp</code> variables:</p> <p><a href="https://i.stack.imgur.com/Csgk9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Csgk9.png" alt="enter image description here" /></a></p> <p>But when I run the following, which I pulled from another SO answer about converting JSON to R:</p> <pre><code>library(&quot;rjson&quot;) result &lt;- fromJSON(file = &quot;test_file.json&quot;) json_data_frame &lt;- as.data.frame(result) </code></pre> <p>I get met with this error about differing rows.</p> <pre><code>Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 0 </code></pre> <p>How can I get what I have into the desired DF format?</p>
[ { "answer_id": 74661383, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 3, "selected": true, "text": "df<- as.data.frame(do.call(rbind, lapply(\n lapply(result$relationships_followers, \"[[\", \"string_list_data\"), \"[[\", 1)))\n\ndf\n#> href value timestamp \n#> \"https://www.instagram.com/testaccount1\" \"testaccount1\" 1669418204\n#> \"https://www.instagram.com/testaccount2\" \"testaccount2\" 1660426426\n#> \"https://www.instagram.com/testaccount3\" \"testaccount3\" 1648230499\n#> \"https://www.instagram.com/testaccount4\" \"testaccount4\" 1379513403\n jsonlite" }, { "answer_id": 74661410, "author": "cory", "author_id": 3087927, "author_profile": "https://Stackoverflow.com/users/3087927", "pm_score": 2, "selected": false, "text": "library(\"rjson\")\nlibrary(\"dplyr\")\n\nresult <- fromJSON(file = \"test_file.json\")\nresult_list <-sapply(result$relationships_followers,\n \"[[\", \"string_list_data\")\njson_data_frame <- bind_rows(result_list)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5468495/" ]
74,661,312
<p>I made some changes on my branch, I fetched changes and ran 'git merge'. I then made more local changes and wanted to amend my commit: git commit --amend. But when trying to push I received that error:</p> <pre><code>remote: error: GH006: Protected branch update failed for refs/heads/v1. remote: error: This branch must not contain merge commits. ! [remote rejected] v1 -&gt; v1 (protected branch hook declined) error: failed to push some refs to xxx </code></pre> <p>I tried to abort but:</p> <pre><code>git merge --abort fatal: There is no merge to abort (MERGE_HEAD missing). </code></pre> <p>How can I cancel the merge commit without losing my local changes?</p>
[ { "answer_id": 74661383, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 3, "selected": true, "text": "df<- as.data.frame(do.call(rbind, lapply(\n lapply(result$relationships_followers, \"[[\", \"string_list_data\"), \"[[\", 1)))\n\ndf\n#> href value timestamp \n#> \"https://www.instagram.com/testaccount1\" \"testaccount1\" 1669418204\n#> \"https://www.instagram.com/testaccount2\" \"testaccount2\" 1660426426\n#> \"https://www.instagram.com/testaccount3\" \"testaccount3\" 1648230499\n#> \"https://www.instagram.com/testaccount4\" \"testaccount4\" 1379513403\n jsonlite" }, { "answer_id": 74661410, "author": "cory", "author_id": 3087927, "author_profile": "https://Stackoverflow.com/users/3087927", "pm_score": 2, "selected": false, "text": "library(\"rjson\")\nlibrary(\"dplyr\")\n\nresult <- fromJSON(file = \"test_file.json\")\nresult_list <-sapply(result$relationships_followers,\n \"[[\", \"string_list_data\")\njson_data_frame <- bind_rows(result_list)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9195085/" ]
74,661,326
<p>I'm using <a href="https://flet.dev/" rel="nofollow noreferrer">Flet</a> and I want for my app to launch a link when clicking on a button.</p> <p>According to the docs, I can use <a href="https://flet.dev/docs/controls/page/#launch_urlurl" rel="nofollow noreferrer"><code>launch_url</code></a> method. But when I tried, I got the following error:</p> <pre><code>Exception in thread Thread-6 (open_repo): Traceback (most recent call last): File &quot;C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py&quot;, line 1038, in _bootstrap_inner self.run() File &quot;C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py&quot;, line 975, in run self._target(*self._args, **self._kwargs) File &quot;d:\Iqmal\Documents\Python Projects\flet-hello\main.py&quot;, line 58, in open_repo ft.page.launch_url('https://github.com/iqfareez/flet-hello') ^^^^^^^^^^^^^^^^^^ AttributeError: 'function' object has no attribute 'launch_url' </code></pre> <h2>Code</h2> <pre class="lang-py prettyprint-override"><code>import flet as ft def main(page: ft.Page): page.padding = ft.Padding(20, 35, 20, 20) page.theme_mode = ft.ThemeMode.LIGHT appbar = ft.AppBar( title=ft.Text(value=&quot;Flutter using Flet&quot;), bgcolor=ft.colors.BLUE, color=ft.colors.WHITE, actions=[ft.IconButton(icon=ft.icons.CODE, on_click=open_repo)]) page.controls.append(appbar) page.update() def open_repo(e): ft.page.launch_url('https://github.com/iqfareez/flet-hello') ft.app(target=main, assets_dir='assets') </code></pre>
[ { "answer_id": 74661383, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 3, "selected": true, "text": "df<- as.data.frame(do.call(rbind, lapply(\n lapply(result$relationships_followers, \"[[\", \"string_list_data\"), \"[[\", 1)))\n\ndf\n#> href value timestamp \n#> \"https://www.instagram.com/testaccount1\" \"testaccount1\" 1669418204\n#> \"https://www.instagram.com/testaccount2\" \"testaccount2\" 1660426426\n#> \"https://www.instagram.com/testaccount3\" \"testaccount3\" 1648230499\n#> \"https://www.instagram.com/testaccount4\" \"testaccount4\" 1379513403\n jsonlite" }, { "answer_id": 74661410, "author": "cory", "author_id": 3087927, "author_profile": "https://Stackoverflow.com/users/3087927", "pm_score": 2, "selected": false, "text": "library(\"rjson\")\nlibrary(\"dplyr\")\n\nresult <- fromJSON(file = \"test_file.json\")\nresult_list <-sapply(result$relationships_followers,\n \"[[\", \"string_list_data\")\njson_data_frame <- bind_rows(result_list)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13617136/" ]
74,661,344
<p>I need to create a code using loops to ask for user input on certain values. Of those values I need to ask the user if they want me to find the smallest or largest number or just end the program. If the number -1000 is entered in the program the program ends. Basically how do I link my menu of options to a the actual actions per option.Here's what I have so far.</p> <pre><code>numbersEntered = [] lengthNumbers = int(input(&quot;Please enter the length of your list/array:&quot;)) print(&quot;Please enter your numbers individually:&quot;) for x in range(lengthNumbers): data=int(input()) numbersEntered.append(data) def menu(): print(&quot;[A] Smallest&quot;) print(&quot;[B] Largest&quot;) print(&quot;[C] Quit&quot;) menu() Options=float(input(f&quot;Please select either option A,B,or C:&quot;)) optionA = min(numbersEntered) optionB = max(numbersEntered) optionC = quit while numbersEntered != C: if numbersEntered == A: print(&quot;The smallest number is:&quot;, min(numbersEntered)) elif numbersEntered == B: print(&quot;The largest number is:&quot;, max(numbersEntered) ) elif numbersEntered ==-1000: print(&quot;Quit&quot;) </code></pre> <p>I tried a while loop to connect the menu to said action but that did not work and idk why. I am a beginner programer so I'm very new to this stuff.</p>
[ { "answer_id": 74661383, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 3, "selected": true, "text": "df<- as.data.frame(do.call(rbind, lapply(\n lapply(result$relationships_followers, \"[[\", \"string_list_data\"), \"[[\", 1)))\n\ndf\n#> href value timestamp \n#> \"https://www.instagram.com/testaccount1\" \"testaccount1\" 1669418204\n#> \"https://www.instagram.com/testaccount2\" \"testaccount2\" 1660426426\n#> \"https://www.instagram.com/testaccount3\" \"testaccount3\" 1648230499\n#> \"https://www.instagram.com/testaccount4\" \"testaccount4\" 1379513403\n jsonlite" }, { "answer_id": 74661410, "author": "cory", "author_id": 3087927, "author_profile": "https://Stackoverflow.com/users/3087927", "pm_score": 2, "selected": false, "text": "library(\"rjson\")\nlibrary(\"dplyr\")\n\nresult <- fromJSON(file = \"test_file.json\")\nresult_list <-sapply(result$relationships_followers,\n \"[[\", \"string_list_data\")\njson_data_frame <- bind_rows(result_list)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670022/" ]
74,661,359
<p>I am creating a security group that has some standard ingress rules. I also want to add additional ingress rules based on a variable.</p> <pre><code>variable &quot;additional_ingress&quot; { type = list(object({ protocol = string from_port = string to_port = string cidr_blocks = list(string) })) default = [] } resource &quot;aws_security_group&quot; &quot;ec2&quot; { name = &quot;my-sg&quot; description = &quot;SG for ec2&quot; vpc_id = data.aws_vpc.this.id egress { to_port = 0 from_port = 0 protocol = &quot;-1&quot; cidr_blocks = [&quot;0.0.0.0/0&quot;] } ingress { protocol = &quot;tcp&quot; from_port = 22 to_port = 22 cidr_blocks = [&quot;10.0.0.0/8&quot;] } # rdp ingress { protocol = &quot;tcp&quot; from_port = 3389 to_port = 3389 cidr_blocks = [&quot;10.0.0.0/8&quot;] } # additional ingress rules ingress { for_each = var.additional_ingress protocol = each.value.protocol from_port = each.value.from_port to_port = each.value.to_port cidr_blocks = each.value.cidr_blocks } } </code></pre> <p>I am getting error</p> <blockquote> <p>A reference to &quot;each.value&quot; has been used in a context in which it unavailable, such as when the configuration no longer contains the value in its &quot;for_each&quot; expression. │ Remove this reference to each.value in your configuration to work around this error.</p> </blockquote> <p>How do I add ingress rules based on variable</p>
[ { "answer_id": 74661627, "author": "Matt Schuchard", "author_id": 5343387, "author_profile": "https://Stackoverflow.com/users/5343387", "pm_score": 2, "selected": false, "text": "aws_security_group_rule for_each resource \"aws_security_group_rule\" \"ec2\" {\n for_each = var.additional_ingress\n\n type = each.value.type\n from_port = each.value.from_port\n to_port = each.value.to_port\n protocol = each.value.protocol\n cidr_blocks = each.value.cidr_blocks\n security_group_id = aws_security_group.ec2.id\n}\n additional_ingress type object variable \"additional_ingress\" {\n type = list(object({\n type = string\n ...\n }))\n default = []\n}\n" }, { "answer_id": 74681465, "author": "Maciej Rostański", "author_id": 7994013, "author_profile": "https://Stackoverflow.com/users/7994013", "pm_score": 0, "selected": false, "text": "dynamic \"ingress\" {\n for_each = var.additional_ingress\n protocol = ingress.value.protocol\n from_port = ingress.value.from_port\n to_port = ingress.value.to_port\n cidr_blocks = ingress.value.cidr_blocks\n }\n additional_ingress aws_security_group_rule" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3862378/" ]
74,661,376
<p>I have a vector of numbers that contain some gaps. For example,</p> <pre><code>vec &lt;- c(3,1,7,3,5,7) </code></pre> <p>So, there are 4 different values and I would like to transform it into a vector of values (without gaps) indicating the order of the entry while respecting the same position. So, in this case, I would like to obtain</p> <pre><code>2 1 4 2 3 4 </code></pre> <p>Indicating a sequence of between 1 and 4 and showing the orders in the original vector <code>vec</code>.</p>
[ { "answer_id": 74661627, "author": "Matt Schuchard", "author_id": 5343387, "author_profile": "https://Stackoverflow.com/users/5343387", "pm_score": 2, "selected": false, "text": "aws_security_group_rule for_each resource \"aws_security_group_rule\" \"ec2\" {\n for_each = var.additional_ingress\n\n type = each.value.type\n from_port = each.value.from_port\n to_port = each.value.to_port\n protocol = each.value.protocol\n cidr_blocks = each.value.cidr_blocks\n security_group_id = aws_security_group.ec2.id\n}\n additional_ingress type object variable \"additional_ingress\" {\n type = list(object({\n type = string\n ...\n }))\n default = []\n}\n" }, { "answer_id": 74681465, "author": "Maciej Rostański", "author_id": 7994013, "author_profile": "https://Stackoverflow.com/users/7994013", "pm_score": 0, "selected": false, "text": "dynamic \"ingress\" {\n for_each = var.additional_ingress\n protocol = ingress.value.protocol\n from_port = ingress.value.from_port\n to_port = ingress.value.to_port\n cidr_blocks = ingress.value.cidr_blocks\n }\n additional_ingress aws_security_group_rule" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8384166/" ]
74,661,388
<p>I have the following three dictionaries within a list like so:</p> <pre><code>dict1 = {'key1':'x', 'key2':['one', 'two', 'three']} dict2 = {'key1':'x', 'key2':['four', 'five', 'six']} dict3 = {'key1':'y', 'key2':['one', 'two', 'three']} list = [dict1, dict2, dict3] </code></pre> <p>I'd like to merge the dictionaries that have the same value for key1 into a single dictionary with merged values (lists in this case) for key2 like so:</p> <pre><code>new_dict = {'key1':'x', 'key2':['one', 'two', 'three', 'four', 'five', 'six']} list = [new_dict, dict3] </code></pre> <p>I've come up with a very brutish solution riddled with hard codes and loops. I'd like to employ some higher-order functions but I'm new to those.</p>
[ { "answer_id": 74661438, "author": "Samwise", "author_id": 3799759, "author_profile": "https://Stackoverflow.com/users/3799759", "pm_score": 0, "selected": false, "text": "key1 key2 >>> my_dicts = [\n... {'key1':'x', 'key2':['one', 'two', 'three']},\n... {'key1':'x', 'key2':['four', 'five', 'six']},\n... {'key1':'y', 'key2':['one', 'two', 'three']},\n... ]\n>>> agg_dict = {}\n>>> for d in my_dicts:\n... agg_dict.setdefault(d['key1'], []).extend(d['key2'])\n...\n>>> [{'key1': key1, 'key2': key2} for key1, key2 in agg_dict.items()]\n[{'key1': 'x', 'key2': ['one', 'two', 'three', 'four', 'five', 'six']}, {'key1': 'y', 'key2': ['one', 'two', 'three']}]\n" }, { "answer_id": 74661703, "author": "dimnnv", "author_id": 4845935, "author_profile": "https://Stackoverflow.com/users/4845935", "pm_score": 2, "selected": false, "text": "from itertools import groupby\nfrom itertools import chain\n\ndict1 = {'key1':'x', 'key2':['one', 'two', 'three']}\ndict2 = {'key1':'x', 'key2':['four', 'five', 'six']}\ndict3 = {'key1':'y', 'key2':['one', 'two', 'three']}\nlist_of_dicts = [dict1, dict2, dict3]\n\nresult = [{'key1': k, 'key2': list(chain(*[x['key2'] for x in v]))} for k, v in groupby(list_of_dicts, lambda x: x['key1'])]\n\nprint(result)\n[{'key1': 'x', 'key2': ['one', 'two', 'three', 'four', 'five', 'six']}, {'key1': 'y', 'key2': ['one', 'two', 'three']}]\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9278515/" ]
74,661,400
<p>In my attempts to compile a single-file binary that leverages <a href="https://www.nuget.org/packages/Microsoft.Data.Sqlite" rel="nofollow noreferrer">Microsoft.Data.Sqlite</a>, I am consistently left with <em><strong>two files</strong></em> that are both required for the application to work.</p> <ol> <li><code>{ProjectName}.exe</code></li> <li><code>e_sqlite3.dll</code></li> </ol> <p>Is it possible to include the <code>e_sqlite3.dll</code> into the exe?</p> <blockquote> <p>It appears that <a href="https://www.nuget.org/packages/System.Data.Sqlite" rel="nofollow noreferrer">System.Data.Sqlite</a> exhibits the same behaviour, but instead a file called <code>SQLite.Interop.dll</code>.</p> </blockquote> <h1>Sample code</h1> <blockquote> <p>Note: I realize there is no actual interop with SQLite happening, this code is purely meant to demonstrate the compilation.</p> </blockquote> <h3>ProjectName.fsproj</h3> <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt; &lt;PropertyGroup&gt; &lt;OutputType&gt;Exe&lt;/OutputType&gt; &lt;TargetFramework&gt;net7.0&lt;/TargetFramework&gt; &lt;PublishSingleFile&gt;true&lt;/PublishSingleFile&gt; &lt;SelfContained&gt;true&lt;/SelfContained&gt; &lt;RuntimeIdentifier&gt;win-x64&lt;/RuntimeIdentifier&gt; &lt;PublishReadyToRun&gt;true&lt;/PublishReadyToRun&gt; &lt;/PropertyGroup&gt; &lt;ItemGroup&gt; &lt;PackageReference Include=&quot;Microsoft.Data.Sqlite&quot; version=&quot;7.*&quot; /&gt; &lt;/ItemGroup&gt; &lt;ItemGroup&gt; &lt;Compile Include=&quot;Program.fs&quot; /&gt; &lt;/ItemGroup&gt; &lt;/Project&gt; </code></pre> <h3>Program.fs</h3> <pre class="lang-ml prettyprint-override"><code>module ProjectName.Program open System [&lt;EntryPoint&gt;] let main (argv : string[]) = printfn &quot;Hello world&quot; 0 </code></pre> <p>Compiling the project as follows:</p> <pre><code>dotnet publish .\ProjectName.fsproj -c Release </code></pre>
[ { "answer_id": 74663407, "author": "pim", "author_id": 2421277, "author_profile": "https://Stackoverflow.com/users/2421277", "pm_score": 2, "selected": false, "text": "IncludeNativeLibrariesForSelfExtract true <Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <SelfContained>true</SelfContained>\n <PublishSingleFile>true</PublishSingleFile>\n <PublishReadyToRun>true</PublishReadyToRun>\n <PublishTrimmed>true</PublishTrimmed>\n\n <!-- Must include this line -->\n <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>\n <DebuggerSupport>false</DebuggerSupport>\n <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>\n <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>\n <InvariantGlobalization>true</InvariantGlobalization>\n <UseNativeHttpHandler>true</UseNativeHttpHandler>\n <UseSystemResourceKeys>true</UseSystemResourceKeys>\n <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>\n </PropertyGroup>\n <ItemGroup>\n <PackageReference Include=\"Microsoft.Data.Sqlite\" version=\"7.*\" />\n </ItemGroup>\n <ItemGroup>\n <Compile Include=\"Program.fs\" />\n </ItemGroup>\n</Project>\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2421277/" ]
74,661,427
<p>i am using Better Player (<a href="https://pub.dev/packages/better_player" rel="nofollow noreferrer">https://pub.dev/packages/better_player</a>) to create several video players in list view.</p> <pre><code>ListView.builder( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), addAutomaticKeepAlives: true, itemCount: awaitedContents!.length, itemBuilder: (context, index) { Content content = awaitedContents[index]; ... } else if (content.type == 'VIDEO') { return SizedBox( height: MediaQuery.of(context).size.width * 9 / 16, child: VideoContent(content.value, content.image, content.videoSubtitle, subtitlesEnabled), ); } </code></pre> <p>How can I stop one Video player from playing when users starts another one?</p>
[ { "answer_id": 74663407, "author": "pim", "author_id": 2421277, "author_profile": "https://Stackoverflow.com/users/2421277", "pm_score": 2, "selected": false, "text": "IncludeNativeLibrariesForSelfExtract true <Project Sdk=\"Microsoft.NET.Sdk\">\n <PropertyGroup>\n <SelfContained>true</SelfContained>\n <PublishSingleFile>true</PublishSingleFile>\n <PublishReadyToRun>true</PublishReadyToRun>\n <PublishTrimmed>true</PublishTrimmed>\n\n <!-- Must include this line -->\n <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>\n <DebuggerSupport>false</DebuggerSupport>\n <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>\n <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>\n <InvariantGlobalization>true</InvariantGlobalization>\n <UseNativeHttpHandler>true</UseNativeHttpHandler>\n <UseSystemResourceKeys>true</UseSystemResourceKeys>\n <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>\n </PropertyGroup>\n <ItemGroup>\n <PackageReference Include=\"Microsoft.Data.Sqlite\" version=\"7.*\" />\n </ItemGroup>\n <ItemGroup>\n <Compile Include=\"Program.fs\" />\n </ItemGroup>\n</Project>\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661427", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7370436/" ]
74,661,428
<p><strong>I have the following query:</strong> that is trying to get pt_ids that have certain diagnosis codes OR certain outcome_codes. I have accounted for these conditions by including the specific codes I'd like in the WHERE clause. However, I would like to know if I can also do this using in INNER JOIN.</p> <pre><code>SELECT DISTINCT pt_id FROM #df WHERE flag &lt;&gt; 1 AND (diagnosis IN ( SELECT Code FROM #df_codes WHERE code_id = '20' ) OR outcome_code IN ( SELECT Code FROM #df_codes WHERE code_id = '25' )); </code></pre> <p>The above code is taking quite a while to run and I am wondering if writing it in the following way 1) is appropriate/viable and 2) will leader to a faster run time. I am essentially trying to join #df with #df_codes on either Code = diagnosis OR code = outcome_code</p> <p><strong>My Solution</strong></p> <pre><code>SELECT DISTINCT pt_id FROM #df a JOIN (select * from #df_codes where code_id = '20')b ON a.diagnosis = b.Code OR (select * from #df_codes where code_id = '25')c ON a.outcome_code = c.Code WHERE flag &lt;&gt; 1 </code></pre>
[ { "answer_id": 74661624, "author": "Kevin", "author_id": 19038, "author_profile": "https://Stackoverflow.com/users/19038", "pm_score": 0, "selected": false, "text": "SELECT DISTINCT pt_id\nFROM #df\nINNER JOIN #df_codes ON (\n #df.diagnosis = #df_codes.code\n AND #df_codes.code_id = '20'\n )\n OR (\n #df.outcome_code = #df_codes.code\n AND #df_codes.code_id = '25'\n )\nWHERE flag <> 1\n" }, { "answer_id": 74661939, "author": "Jeff", "author_id": 15394900, "author_profile": "https://Stackoverflow.com/users/15394900", "pm_score": -1, "selected": false, "text": "SELECT DISTINCT\n d.pt_id\n FROM #df d\n WHERE flag <> 1\n AND EXISTS (SELECT *\n FROM #df_codes c\n WHERE (c.code = d.diagnosis AND c.code_id = '20')\n OR (c.code = d.outcome_code AND c.code_id = '25');\n" }, { "answer_id": 74662130, "author": "vendettamit", "author_id": 881798, "author_profile": "https://Stackoverflow.com/users/881798", "pm_score": 0, "selected": false, "text": "SELECT Code\ninto #x\nFROM #df_codes\nWHERE code_id = '20'\n\nSELECT Code\ninto #y\nFROM #df_codes\nWHERE code_id = '25'\n\n\nSELECT\npt_id\nFROM #df\njoin #x x on x.Code = diagnosis \nWHERE flag <> 1\nUnion\nSELECT\npt_id\nFROM #df\njoin #y y on y.Code = diagnosis \nWHERE flag <> 1\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19852587/" ]
74,661,445
<p>I am new to <code>bash</code>. I have a question about determining if all characters of one string occur within another string. For example, if the variables are:</p> <pre class="lang-bash prettyprint-override"><code>var_1=&quot;abcdefg&quot; var_2=&quot;bcg&quot; </code></pre> <p>Then I want to write an <code>if</code> statement of the form:</p> <pre class="lang-bash prettyprint-override"><code>if [all characters of var_2 occur within var_1] then echo &quot;All characters of var_2 occur in var_1.&quot; else echo &quot;Not all characters of var_2 occur in var_1.&quot; fi </code></pre> <p>In this example, the output should be <code>All characters of var_2 occur in var_1.</code> What would go in the <code>if</code> statement here?</p> <p>This is what I tried:</p> <pre class="lang-bash prettyprint-override"><code>if [[ $var_1 == *$var_2* ]] </code></pre> <p>... but I think this is only determines if <code>var_2</code> is a substring of <code>var_1</code>. What I want is to determine if the characters of <code>var_2</code> occur within <code>var_1</code> in no particular order.</p>
[ { "answer_id": 74661882, "author": "Enlico", "author_id": 5825294, "author_profile": "https://Stackoverflow.com/users/5825294", "pm_score": 2, "selected": false, "text": "echo -e \"$var_2\\0$var_1\" | sed -E ':a;s/(.)(.*\\x0)(.*)\\1(.*)/\\2\\3\\4/;ta;s/^\\x0.*/1/;s/.*\\x0.*/0/'\n 0 1 echo -e \\0 bcg abcdefg -E ( ) \\( \\) ; :a ta ba s/(.)(.*\\x0)(.*)\\1(.*)/\\2\\3\\4/ var_2 var_1 var_2 (.) var_2 (.*\\x0) \\0 \\x0 (.) var_1 var_2 var_1 ta s :a var_2 var_1 var_2 var_1 ta s/^\\x0.*/1/ \\x0 var_2 var_1 1 s/.*\\x0.*/0/ \\x0 var_2 var_1 0" }, { "answer_id": 74668877, "author": "Jetchisel", "author_id": 4452265, "author_profile": "https://Stackoverflow.com/users/4452265", "pm_score": 1, "selected": false, "text": "if #!/usr/bin/env bash\n\ni=0\nvar_2=\"bcg\"\nvar_1=\"abcdefg\"\ntotal_str=${#var_2}\n\nwhile (( i < total_str )); do\n [[ $var_1 = *\"${var_2:i++:1}\"* ]] || {\n printf >&2 'Not all characters of the string \"%s\" occur in the string \"%s\".\\n' \"$var_2\" \"$var_1\"\n exit 1\n }\ndone\n\nprintf 'All characters of the string \"%s\" occur in the string \"%s\".\\n' \"$var_2\" \"$var_1\"\n All characters of the string \"bcg\" occur in the string \"abcdefg\".\n var_2 var_2=\"bxg\"\n Not all characters of the string \"bxg\" occur in the string \"abcdefg\".\n" }, { "answer_id": 74669274, "author": "M. Nejat Aydin", "author_id": 13809001, "author_profile": "https://Stackoverflow.com/users/13809001", "pm_score": 0, "selected": false, "text": "bash #!/bin/bash\n\nvar_1=\"abcdefg\"\nvar_2=\"bcg\"\n\nif [[ ${var_2//[$var_1]} ]]; then\n echo \"Not all characters of var_2 occur in var_1.\"\nelse\n echo \"All characters of var_2 occur in var_1.\"\nfi\n ${var_2//[$var_1]} var_2 var_1 var_2 var_1" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670027/" ]
74,661,451
<p>I have a Shiny app that takes a dataset and filters it through several user inputs. To do this, I use selectizeInput functions where the user can select one or many options from a list and then these selections are run through reactive statements to get the desired final dataset. I've noticed recently that this no longer works in one of the places I have the app hosted; this app was built and deployed with Shiny 1.6.0 and it's still working in that location, but it isn't working in another spot that has Shiny 1.7.3. I'm wondering if this may be an issue with newer versions of Shiny. Here is an example where multiple selections causes the resulting table to not populate:</p> <pre><code>library(shiny) library(dplyr) data &lt;- mtcars ui &lt;- fluidPage( fluidRow( column(width = 4, wellPanel( selectizeInput(&quot;carb&quot;, &quot;carb:&quot;, c(&quot;All&quot;, sort(unique(data$carb))), selected = &quot;All&quot;, multiple = TRUE, options = list('plugins' = list('remove_button'), 'create' = TRUE, 'persist' = FALSE)))), column(width = 8, wellPanel(tableOutput(&quot;table&quot;))) ) ) server &lt;- function(input,output,session){ process &lt;- reactive({ req(input$carb) # require some input if(input$carb == &quot;All&quot;){data} #pass entire dataset if selected else(data %&gt;% dplyr::filter(carb %in% input$carb))}) # will not work with &gt; 1 selected output$table &lt;- renderTable({process()}) } shinyApp(ui = ui, server = server) </code></pre> <p>Selecting just one value allows everything to work fine, but there's an error about the condition having length &gt; 1 if multiple values are selected. Previously when this worked, I was able to select something like 1,2, and 4 for the carb variable and the resulting table would show all rows with one of those three values. I know the input is getting passed on to the argument by adding a renderTable statement into the server:</p> <pre><code>output$test &lt;- renderTable({as.data.frame(input$carb)}) </code></pre> <p>However, this isn't working when I'm trying to filter the full dataset. I can run everything when selectizeInput(multiple = FALSE), but ideally it should be equal to TRUE so the user has more functionality.</p>
[ { "answer_id": 74661518, "author": "MrFlick", "author_id": 2372064, "author_profile": "https://Stackoverflow.com/users/2372064", "pm_score": 2, "selected": true, "text": "%in% filter if(input$carb == \"All\") {data}\n carb if(\"All\" %in% input$carb) {data}\n" }, { "answer_id": 74661525, "author": "mnist", "author_id": 8107362, "author_profile": "https://Stackoverflow.com/users/8107362", "pm_score": 0, "selected": false, "text": "input$carb == \"All\" if (all(input$carb == \"All\")) # shows all rows if Only All is selected\nOR\nif (\"All\" %in% input$carb)) # shows all rows as soon as All is selected\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12270320/" ]
74,661,460
<p>The timestamps my database returns are in this format:</p> <pre><code>'2022-11-25T17:54:29.819Z' </code></pre> <p>I want to do hour(timestamp) to return just the hour but get this error</p> <pre><code>'error:&quot;function hour(timestamp with time zone) does not exist&quot;' </code></pre> <p>How do I get around this? Thanks!</p>
[ { "answer_id": 74661518, "author": "MrFlick", "author_id": 2372064, "author_profile": "https://Stackoverflow.com/users/2372064", "pm_score": 2, "selected": true, "text": "%in% filter if(input$carb == \"All\") {data}\n carb if(\"All\" %in% input$carb) {data}\n" }, { "answer_id": 74661525, "author": "mnist", "author_id": 8107362, "author_profile": "https://Stackoverflow.com/users/8107362", "pm_score": 0, "selected": false, "text": "input$carb == \"All\" if (all(input$carb == \"All\")) # shows all rows if Only All is selected\nOR\nif (\"All\" %in% input$carb)) # shows all rows as soon as All is selected\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10869169/" ]
74,661,465
<p>I have a dataframe in the following where Day_1, Day_2, Day_3 are the number of impressions in the past 3 days.</p> <pre><code>df = pd.DataFrame({'Day_1': [2, 4, 8, 0], 'Day_2': [2, 0, 0, 0], 'Day_3': [1, 1, 0, 0], index=['user1', 'user2', 'user3', 'user4']) df Day_1 Day_2 Day_3 user1 2 2 1 user2 4 0 1 user3 8 0 0 user4 0 0 0 </code></pre> <p>Now, I need to check if a user had any impression in the past <code>n</code> days. For example, if <code>num_days = 2</code>, I need to add a new column, <code>impression</code>, where it gets 1 if sum Day_1 and Day_2 is greater than zero, and <code>0</code> otherwise. Here is what I expect to see:</p> <pre><code> Day_1 Day_2 Day_3 impression user1 2 2 1 1 user2 4 0 1 1 user3 8 0 0 1 user4 0 0 0 0 </code></pre> <p>It is a straightforward process in <code>pyspark</code> and I use something like this:</p> <pre><code>imp_cols = ['Day_'+str(i) for i in range(1, num_days+1)] df = df.withColumn(&quot;impression&quot;,reduce(add, [F.col(x) for x in imp_cols])) </code></pre>
[ { "answer_id": 74661518, "author": "MrFlick", "author_id": 2372064, "author_profile": "https://Stackoverflow.com/users/2372064", "pm_score": 2, "selected": true, "text": "%in% filter if(input$carb == \"All\") {data}\n carb if(\"All\" %in% input$carb) {data}\n" }, { "answer_id": 74661525, "author": "mnist", "author_id": 8107362, "author_profile": "https://Stackoverflow.com/users/8107362", "pm_score": 0, "selected": false, "text": "input$carb == \"All\" if (all(input$carb == \"All\")) # shows all rows if Only All is selected\nOR\nif (\"All\" %in% input$carb)) # shows all rows as soon as All is selected\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15171387/" ]
74,661,466
<p>Any simple link to an external site from my Blazor Server site works....but while the site loads the user sees the Blazor &quot;Attempting to reconnect to the server: 1 of 8&quot; message first.</p> <p>How do I get rid of that and provide a more seamless experience?</p> <p>I have tried coding my own javascript exit routine by listening to the click event and manually doing window.location.href = url; with the same results.</p> <p>I have also tried calling Blazor.disconnect() before jumping to the external site, but again no luck.</p> <p>I tried embedding calls to a NavigationManager in my code, but that's really ugly, and I didn't have much luck with that either.</p> <p>...surely a very simple scenario! - my code is simply:</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-html lang-html prettyprint-override"><code>&lt;a href="https://www.google.com"&gt;Go&lt;/a&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74661518, "author": "MrFlick", "author_id": 2372064, "author_profile": "https://Stackoverflow.com/users/2372064", "pm_score": 2, "selected": true, "text": "%in% filter if(input$carb == \"All\") {data}\n carb if(\"All\" %in% input$carb) {data}\n" }, { "answer_id": 74661525, "author": "mnist", "author_id": 8107362, "author_profile": "https://Stackoverflow.com/users/8107362", "pm_score": 0, "selected": false, "text": "input$carb == \"All\" if (all(input$carb == \"All\")) # shows all rows if Only All is selected\nOR\nif (\"All\" %in% input$carb)) # shows all rows as soon as All is selected\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661466", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3895134/" ]
74,661,480
<p>I have two Tcl lists of equal length, <code>u</code> and <code>v</code>. Many of the entries in <code>u</code> are known to be identical. For every unique entry in <code>u</code>, I would like to average over the corresponding entries in <code>v</code>. So, if my lists are <code>{1 2 1 2}</code> and <code>{1 2 3 4}</code>, the output should be <code>{1 2}</code> (only the unique entries in <code>u</code>), and <code>{2 3}</code>, where 2 comes from <code>(1+3)/2</code>, and 3 comes from <code>(2+4)/2</code>.</p> <p>I have tried the following:</p> <pre><code>set unique [lsort -unique $u] foreach i $unique { set ave 0; set N 0 foreach j $u k $v { if {$i == $j} {set ave [expr {$ave+$k}]} } lappend w [expr {$ave/$N}] } </code></pre> <p>This works, but it is far too slow for larger lists. Does anyone know a more efficient way of doing this?</p> <p>Thanks in advance!</p>
[ { "answer_id": 74661512, "author": "Begging", "author_id": 16606223, "author_profile": "https://Stackoverflow.com/users/16606223", "pm_score": 1, "selected": true, "text": "# Create an array to store the sums of the corresponding entries in v\narray set sums {}\n\n# Loop through the entries in u and add the corresponding entries in v to the array\nforeach i $u j $v {\n set sums($i) [expr {$sums($i) + $j}]\n}\n\n# Create an empty list to store the results\nset result {}\n\n# Loop through the unique entries in u and compute the average of the corresponding entries in v\nforeach i [lsort -unique $u] {\n lappend result [expr {$sums($i) / [llength $u]}]\n}\n" }, { "answer_id": 74667167, "author": "Donal Fellows", "author_id": 301832, "author_profile": "https://Stackoverflow.com/users/301832", "pm_score": 1, "selected": false, "text": "foreach a $u b $v {\n dict lappend collector $a $b\n}\nset uniques [dict keys $collector]\nset averages [lmap items [dict values $collector] {\n expr { [tcl::mathop::+ {*}$items] / double([llength $items]) }\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20524827/" ]
74,661,513
<p>I am trying to create a table of elements (structs) where each element contains a dynamic list of enums in C. However, it seems this is not possible in C as I keep getting the following error:</p> <pre><code>error: initialization of flexible array member in a nested context </code></pre> <p>Here is a small sample of my code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; typedef enum { NET_0 = 0, NET_1, NET_2, TOTAL_NETS, } net_t; typedef struct { uint8_t num_nets; net_t net_list[]; } sig_to_net_t; sig_to_net_t SIG_NET_MAPPING[] = { {1, {NET_0}}, {2, {NET_1, NET_2}}, {1, {NET_2}}, }; </code></pre> <p>Any solution for this issue in C?</p> <p>FYI, the only solution I found would be to replace the dynamic array <code>net_list</code> with a fixed-size array. However, this solution is not optimal as this code will be flashed on memory-limited devices and I have cases where the <code>net_list</code> will contain 5 elements which are only a few cases out of 1000 entries in the <code>SIG_NET_MAPPING</code> table.</p>
[ { "answer_id": 74661561, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 1, "selected": false, "text": "net_list char -fshort-enums" }, { "answer_id": 74661790, "author": "0___________", "author_id": 6110094, "author_profile": "https://Stackoverflow.com/users/6110094", "pm_score": 3, "selected": true, "text": "typedef enum {\n NET_0 = 0,\n NET_1,\n NET_2,\n TOTAL_NETS,\n} net_t;\n\ntypedef struct {\n uint8_t num_nets;\n net_t *net_list;\n} sig_to_net_t;\n\nsig_to_net_t SIG_NET_MAPPING[] = {\n {.num_nets = 1, .net_list = (net_t[]){NET_0}},\n {.num_nets = 2, .net_list = (net_t[]){NET_1, NET_2}},\n};\n typedef struct {\n uint8_t num_nets;\n const net_t *const net_list;\n} sig_to_net_t;\n\nconst sig_to_net_t SIG_NET_MAPPING[] = {\n {.num_nets = 1, .net_list = (const net_t[]){NET_0}},\n {.num_nets = 2, .net_list = (const net_t[]){NET_1, NET_2}},\n};\n" }, { "answer_id": 74662325, "author": "Tim-Schaeffer_Crown", "author_id": 20660203, "author_profile": "https://Stackoverflow.com/users/20660203", "pm_score": 1, "selected": false, "text": "0___________ num_nets /* gcc -Wno-incompatible-pointer-types .\\multisize_array.c -o .\\multisize_array.exe */\n\n#include <stdio.h>\n#include <stdbool.h>\n\n#include <stdio.h>\n#include <stdint.h>\n\ntypedef enum {\n NET_0 = 0,\n NET_1,\n NET_2,\n TOTAL_NETS,\n} net_t;\n\ntypedef struct {\n uint8_t num_nets;\n net_t * net_list;\n} sig_to_net_t;\n\n#define array_size(ARR) (sizeof(ARR)/sizeof(ARR[0]))\n\n#define NET_MAPPING(...) { \\\n .num_nets = array_size(((net_t[]){__VA_ARGS__})), \\\n .net_list = (net_t[]){__VA_ARGS__} \\\n}\n\nsig_to_net_t SIG_NET_MAPPING[] = {\n NET_MAPPING(NET_0),\n NET_MAPPING(NET_1, NET_2),\n NET_MAPPING(NET_1, NET_2),\n NET_MAPPING(NET_2, NET_2, NET_2, NET_2, NET_2, NET_2, NET_2, NET_2),\n};\n\n#define array_size(ARR) (sizeof(ARR)/sizeof(ARR[0]))\n\nint main(void)\n{\n int ret = 0;\n for (int i = 0 ; i < array_size(SIG_NET_MAPPING) ; i++ ) {\n const sig_to_net_t * const pStn = &SIG_NET_MAPPING[i];\n printf(\"{\");\n const char * sep = \"\";\n for (int ii = 0 ; ii < pStn->num_nets ; ii++ ) {\n printf(\"%s%d\", sep, pStn->net_list[ii]);\n sep = \", \";\n }\n printf(\"}\\n\");\n }\n return ret;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2399465/" ]
74,661,523
<p>I have two vectors and I am trying to find all unique combinations of 3 elements from vector1 and 2 elements from vector2. I have tried the following code.</p> <pre><code>V1 = combn(1:5, 3) # 10 combinations in total V2 = combn(6:11, 2) # 15 combinations in total </code></pre> <p>How to combine V1 and V2 so that there are 10 * 15 = 150 combinations in total? Thanks.</p>
[ { "answer_id": 74661662, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 3, "selected": true, "text": "expand.grid() g <- expand.grid(seq_len(ncol(V1)), seq_len(ncol(V2)))\nV3 <- rbind(V1[, g[, 1]], V2[, g[, 2]])\n V1 V2 head(t(V3))\n# [,1] [,2] [,3] [,4] [,5]\n# [1,] 1 2 3 6 7\n# [2,] 1 2 4 6 7\n# [3,] 1 2 5 6 7\n# [4,] 1 3 4 6 7\n# [5,] 1 3 5 6 7\n# [6,] 1 4 5 6 7\n\ndim(unique(t(V3)))\n# [1] 150 5\n V V <- list(V1, V2)\ng <- do.call(expand.grid, lapply(V, \\(x) seq_len(ncol(x))))\nV.comb <- do.call(rbind, mapply('[', V, T, g))\n\nidentical(V.comb, V3)\n[1] TRUE\n" }, { "answer_id": 74661707, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "apply apply(expand.grid(seq(ncol(V1)), seq(ncol(V2))), 1, function(i) {\n c(V1[,i[1]], V2[,i[2]])})\n#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 7 7 7 7 7 7 7 7 7 7 8 8 8 8\n#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 8 8 8 8 8 8 9 9 9 9 9 9\n#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 9 9 9 9 10 10 10 10 10 10 10 10\n#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]\n#> [1,] 2 3 1 1 1 1 1 1 2 2 2 3\n#> [2,] 4 4 2 2 2 3 3 4 3 3 4 4\n#> [3,] 5 5 3 4 5 4 5 5 4 5 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 10 10 11 11 11 11 11 11 11 11 11 11\n#> [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 8 8 8 8 8 8 8 8 8 8 9 9\n#> [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74]\n#> [1,] 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 9 9 9 9 9 9 9 9 10 10 10 10\n#> [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] [,86]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 10 10 10 10 10 10 11 11 11 11 11 11\n#> [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 7 7 7 7 8 8 8 8 8 8 8 8\n#> [5,] 11 11 11 11 9 9 9 9 9 9 9 9\n#> [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107] [,108]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 9 9 10 10 10 10 10 10 10 10\n#> [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127] [,128]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 9 9 9 9 9 9 9 9\n#> [5,] 11 11 10 10 10 10 10 10 10 10\n#> [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 9 9 9 9 9 9 9 9\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,139] [,140] [,141] [,142] [,143] [,144] [,145] [,146] [,147] [,148]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 10 10 10 10 10 10 10 10\n#> [5,] 11 11 11 11 11 11 11 11 11 11\n#> [,149] [,150]\n#> [1,] 2 3\n#> [2,] 4 4\n#> [3,] 5 5\n#> [4,] 10 10\n#> [5,] 11 11\n" }, { "answer_id": 74661727, "author": "Len Greski", "author_id": 8471931, "author_profile": "https://Stackoverflow.com/users/8471931", "pm_score": 2, "selected": false, "text": "base::merge() merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n > merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n V1.x V2.x V3 V1.y V2.y\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n merge() df1 <- data.frame(t(combn(1:5, 3)))\ndf2 <- data.frame(t(combn(6:11, 2)))\ncolnames(df2) <- paste(\"y\",1:2,sep=\"\"))\n\nmerge(df1,df2,by.x=NULL,by.y = NULL)\n > merge(df1,df2,by.x=NULL,by.y = NULL)\n X1 X2 X3 y1 y2\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n21 1 2 3 6 9\n22 1 2 4 6 9\n23 1 2 5 6 9\n24 1 3 4 6 9\n25 1 3 5 6 9\n" }, { "answer_id": 74661824, "author": "Joseph Wood", "author_id": 4408538, "author_profile": "https://Stackoverflow.com/users/4408538", "pm_score": 3, "selected": false, "text": "comboGrid RcppAlgos library(RcppAlgos)\n\ngrid <- comboGrid(c(rep(list(1:5), 3), rep(list(6:11), 2)),\n repetition = FALSE)\n\nhead(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [1,] 1 2 3 6 7\n#> [2,] 1 2 3 6 8\n#> [3,] 1 2 3 6 9\n#> [4,] 1 2 3 6 10\n#> [5,] 1 2 3 6 11\n#> [6,] 1 2 3 7 8\n\ntail(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [145,] 3 4 5 8 9\n#> [146,] 3 4 5 8 10\n#> [147,] 3 4 5 8 11\n#> [148,] 3 4 5 9 10\n#> [149,] 3 4 5 9 11\n#> [150,] 3 4 5 10 11\n C++ system.time(huge <- comboGrid(c(rep(list(1:20), 5), rep(list(21:35), 3)),\n repetition = FALSE))\n#> user system elapsed \n#> 0.990 0.087 1.077\n\ndim(huge)\n#> [1] 7054320 8\n" }, { "answer_id": 74662045, "author": "ThomasIsCoding", "author_id": 12158757, "author_profile": "https://Stackoverflow.com/users/12158757", "pm_score": 3, "selected": false, "text": "expand.grid asplit expand.grid(asplit(V1,2), asplit(V2,2))\n with(\n expand.grid(asplit(V1, 2), asplit(V2, 2)),\n t(mapply(c, Var1, Var2))\n)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6162679/" ]
74,661,524
<pre><code>from selenium import webdriver from selenium.webdriver.common.proxy import * from selenium.webdriver.common.by import By from time import sleep import requests response = requests.get(&quot;http://proxy.tinsoftsv.com/api/changeProxy.php?key=mykey_apiG&amp;location=0&quot;) print(response.json()) proxy_url = &quot;127.0.0.1:9009&quot; proxy = Proxy({ 'proxyType': ProxyType.MANUAL, 'httpProxy': proxy_url, 'sslProxy': proxy_url, 'noProxy': ''}) capabilities = webdriver.DesiredCapabilities.CHROME proxy.add_to_capabilities(capabilities) driver = webdriver.Chrome(desired_capabilities=capabilities) driver.get(&quot;https://whoer.net/zh&quot;) </code></pre> <p>I am having a problem. I have rented a revolving proxy from a web service and I want to change the IP continuously via the api. I used the requests module to get a new IP, so how can it automatically get that new IP and replace it with the old one to use? I'm a newbie and really don't know much, hope someone can help me. Thanks very much!</p> <p>I read the instructions of the service site but they don't have a tutorial for python</p>
[ { "answer_id": 74661662, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 3, "selected": true, "text": "expand.grid() g <- expand.grid(seq_len(ncol(V1)), seq_len(ncol(V2)))\nV3 <- rbind(V1[, g[, 1]], V2[, g[, 2]])\n V1 V2 head(t(V3))\n# [,1] [,2] [,3] [,4] [,5]\n# [1,] 1 2 3 6 7\n# [2,] 1 2 4 6 7\n# [3,] 1 2 5 6 7\n# [4,] 1 3 4 6 7\n# [5,] 1 3 5 6 7\n# [6,] 1 4 5 6 7\n\ndim(unique(t(V3)))\n# [1] 150 5\n V V <- list(V1, V2)\ng <- do.call(expand.grid, lapply(V, \\(x) seq_len(ncol(x))))\nV.comb <- do.call(rbind, mapply('[', V, T, g))\n\nidentical(V.comb, V3)\n[1] TRUE\n" }, { "answer_id": 74661707, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "apply apply(expand.grid(seq(ncol(V1)), seq(ncol(V2))), 1, function(i) {\n c(V1[,i[1]], V2[,i[2]])})\n#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 7 7 7 7 7 7 7 7 7 7 8 8 8 8\n#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 8 8 8 8 8 8 9 9 9 9 9 9\n#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 9 9 9 9 10 10 10 10 10 10 10 10\n#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]\n#> [1,] 2 3 1 1 1 1 1 1 2 2 2 3\n#> [2,] 4 4 2 2 2 3 3 4 3 3 4 4\n#> [3,] 5 5 3 4 5 4 5 5 4 5 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 10 10 11 11 11 11 11 11 11 11 11 11\n#> [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 8 8 8 8 8 8 8 8 8 8 9 9\n#> [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74]\n#> [1,] 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 9 9 9 9 9 9 9 9 10 10 10 10\n#> [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] [,86]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 10 10 10 10 10 10 11 11 11 11 11 11\n#> [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 7 7 7 7 8 8 8 8 8 8 8 8\n#> [5,] 11 11 11 11 9 9 9 9 9 9 9 9\n#> [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107] [,108]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 9 9 10 10 10 10 10 10 10 10\n#> [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127] [,128]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 9 9 9 9 9 9 9 9\n#> [5,] 11 11 10 10 10 10 10 10 10 10\n#> [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 9 9 9 9 9 9 9 9\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,139] [,140] [,141] [,142] [,143] [,144] [,145] [,146] [,147] [,148]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 10 10 10 10 10 10 10 10\n#> [5,] 11 11 11 11 11 11 11 11 11 11\n#> [,149] [,150]\n#> [1,] 2 3\n#> [2,] 4 4\n#> [3,] 5 5\n#> [4,] 10 10\n#> [5,] 11 11\n" }, { "answer_id": 74661727, "author": "Len Greski", "author_id": 8471931, "author_profile": "https://Stackoverflow.com/users/8471931", "pm_score": 2, "selected": false, "text": "base::merge() merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n > merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n V1.x V2.x V3 V1.y V2.y\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n merge() df1 <- data.frame(t(combn(1:5, 3)))\ndf2 <- data.frame(t(combn(6:11, 2)))\ncolnames(df2) <- paste(\"y\",1:2,sep=\"\"))\n\nmerge(df1,df2,by.x=NULL,by.y = NULL)\n > merge(df1,df2,by.x=NULL,by.y = NULL)\n X1 X2 X3 y1 y2\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n21 1 2 3 6 9\n22 1 2 4 6 9\n23 1 2 5 6 9\n24 1 3 4 6 9\n25 1 3 5 6 9\n" }, { "answer_id": 74661824, "author": "Joseph Wood", "author_id": 4408538, "author_profile": "https://Stackoverflow.com/users/4408538", "pm_score": 3, "selected": false, "text": "comboGrid RcppAlgos library(RcppAlgos)\n\ngrid <- comboGrid(c(rep(list(1:5), 3), rep(list(6:11), 2)),\n repetition = FALSE)\n\nhead(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [1,] 1 2 3 6 7\n#> [2,] 1 2 3 6 8\n#> [3,] 1 2 3 6 9\n#> [4,] 1 2 3 6 10\n#> [5,] 1 2 3 6 11\n#> [6,] 1 2 3 7 8\n\ntail(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [145,] 3 4 5 8 9\n#> [146,] 3 4 5 8 10\n#> [147,] 3 4 5 8 11\n#> [148,] 3 4 5 9 10\n#> [149,] 3 4 5 9 11\n#> [150,] 3 4 5 10 11\n C++ system.time(huge <- comboGrid(c(rep(list(1:20), 5), rep(list(21:35), 3)),\n repetition = FALSE))\n#> user system elapsed \n#> 0.990 0.087 1.077\n\ndim(huge)\n#> [1] 7054320 8\n" }, { "answer_id": 74662045, "author": "ThomasIsCoding", "author_id": 12158757, "author_profile": "https://Stackoverflow.com/users/12158757", "pm_score": 3, "selected": false, "text": "expand.grid asplit expand.grid(asplit(V1,2), asplit(V2,2))\n with(\n expand.grid(asplit(V1, 2), asplit(V2, 2)),\n t(mapply(c, Var1, Var2))\n)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18043564/" ]
74,661,526
<p>I have a use case where depending on the argument passed in I may have to fetch and process 1) millions or records from database (read rdbms using jdbc, decode, convert to xml, convert to csv etc., a very time consuming process), and or 2) process only a few hundres or even handful of records. Please note that I do not know the volume of the data in this multi-tenant spark app until during the runtime of my app where I calculate total # of records I need to process. So I have two questions here:</p> <ol> <li>How do I know how many executors or cores I need to request for this spark job without knowing the data volume as I kick off the run.</li> <li>Because I making jdbc calls on a DB table, I am using the numOfPartitions, lowerbound(0), upperBound(total#OfRecords), and partitioncolumn(ROW_NUM) to parition the SparkSQL. Now how do I calculate the numOfPartitions? In one case when I am fetching millions I want to have more paritions and less for a handful. How do I decide this number? What is the logic? Would this numOFPartition be 10-20 for 100-200? We dont want to affect transaction applications by hoggin DB resources. How do people typically decide on ths numOfPartitions? Appreicate your help thank you</li> </ol> <p>Need help deciding database numOfPartitions</p>
[ { "answer_id": 74661662, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 3, "selected": true, "text": "expand.grid() g <- expand.grid(seq_len(ncol(V1)), seq_len(ncol(V2)))\nV3 <- rbind(V1[, g[, 1]], V2[, g[, 2]])\n V1 V2 head(t(V3))\n# [,1] [,2] [,3] [,4] [,5]\n# [1,] 1 2 3 6 7\n# [2,] 1 2 4 6 7\n# [3,] 1 2 5 6 7\n# [4,] 1 3 4 6 7\n# [5,] 1 3 5 6 7\n# [6,] 1 4 5 6 7\n\ndim(unique(t(V3)))\n# [1] 150 5\n V V <- list(V1, V2)\ng <- do.call(expand.grid, lapply(V, \\(x) seq_len(ncol(x))))\nV.comb <- do.call(rbind, mapply('[', V, T, g))\n\nidentical(V.comb, V3)\n[1] TRUE\n" }, { "answer_id": 74661707, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "apply apply(expand.grid(seq(ncol(V1)), seq(ncol(V2))), 1, function(i) {\n c(V1[,i[1]], V2[,i[2]])})\n#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 7 7 7 7 7 7 7 7 7 7 8 8 8 8\n#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 8 8 8 8 8 8 9 9 9 9 9 9\n#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 9 9 9 9 10 10 10 10 10 10 10 10\n#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]\n#> [1,] 2 3 1 1 1 1 1 1 2 2 2 3\n#> [2,] 4 4 2 2 2 3 3 4 3 3 4 4\n#> [3,] 5 5 3 4 5 4 5 5 4 5 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 10 10 11 11 11 11 11 11 11 11 11 11\n#> [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 8 8 8 8 8 8 8 8 8 8 9 9\n#> [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74]\n#> [1,] 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 9 9 9 9 9 9 9 9 10 10 10 10\n#> [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] [,86]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 10 10 10 10 10 10 11 11 11 11 11 11\n#> [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 7 7 7 7 8 8 8 8 8 8 8 8\n#> [5,] 11 11 11 11 9 9 9 9 9 9 9 9\n#> [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107] [,108]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 9 9 10 10 10 10 10 10 10 10\n#> [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127] [,128]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 9 9 9 9 9 9 9 9\n#> [5,] 11 11 10 10 10 10 10 10 10 10\n#> [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 9 9 9 9 9 9 9 9\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,139] [,140] [,141] [,142] [,143] [,144] [,145] [,146] [,147] [,148]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 10 10 10 10 10 10 10 10\n#> [5,] 11 11 11 11 11 11 11 11 11 11\n#> [,149] [,150]\n#> [1,] 2 3\n#> [2,] 4 4\n#> [3,] 5 5\n#> [4,] 10 10\n#> [5,] 11 11\n" }, { "answer_id": 74661727, "author": "Len Greski", "author_id": 8471931, "author_profile": "https://Stackoverflow.com/users/8471931", "pm_score": 2, "selected": false, "text": "base::merge() merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n > merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n V1.x V2.x V3 V1.y V2.y\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n merge() df1 <- data.frame(t(combn(1:5, 3)))\ndf2 <- data.frame(t(combn(6:11, 2)))\ncolnames(df2) <- paste(\"y\",1:2,sep=\"\"))\n\nmerge(df1,df2,by.x=NULL,by.y = NULL)\n > merge(df1,df2,by.x=NULL,by.y = NULL)\n X1 X2 X3 y1 y2\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n21 1 2 3 6 9\n22 1 2 4 6 9\n23 1 2 5 6 9\n24 1 3 4 6 9\n25 1 3 5 6 9\n" }, { "answer_id": 74661824, "author": "Joseph Wood", "author_id": 4408538, "author_profile": "https://Stackoverflow.com/users/4408538", "pm_score": 3, "selected": false, "text": "comboGrid RcppAlgos library(RcppAlgos)\n\ngrid <- comboGrid(c(rep(list(1:5), 3), rep(list(6:11), 2)),\n repetition = FALSE)\n\nhead(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [1,] 1 2 3 6 7\n#> [2,] 1 2 3 6 8\n#> [3,] 1 2 3 6 9\n#> [4,] 1 2 3 6 10\n#> [5,] 1 2 3 6 11\n#> [6,] 1 2 3 7 8\n\ntail(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [145,] 3 4 5 8 9\n#> [146,] 3 4 5 8 10\n#> [147,] 3 4 5 8 11\n#> [148,] 3 4 5 9 10\n#> [149,] 3 4 5 9 11\n#> [150,] 3 4 5 10 11\n C++ system.time(huge <- comboGrid(c(rep(list(1:20), 5), rep(list(21:35), 3)),\n repetition = FALSE))\n#> user system elapsed \n#> 0.990 0.087 1.077\n\ndim(huge)\n#> [1] 7054320 8\n" }, { "answer_id": 74662045, "author": "ThomasIsCoding", "author_id": 12158757, "author_profile": "https://Stackoverflow.com/users/12158757", "pm_score": 3, "selected": false, "text": "expand.grid asplit expand.grid(asplit(V1,2), asplit(V2,2))\n with(\n expand.grid(asplit(V1, 2), asplit(V2, 2)),\n t(mapply(c, Var1, Var2))\n)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19979114/" ]
74,661,541
<p>It's Known that you have to test your functions first, before deploying them to firebase to avoid loops and unwanted behavior. I need to run a local environment to test it first, How can I do that?</p>
[ { "answer_id": 74661662, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 3, "selected": true, "text": "expand.grid() g <- expand.grid(seq_len(ncol(V1)), seq_len(ncol(V2)))\nV3 <- rbind(V1[, g[, 1]], V2[, g[, 2]])\n V1 V2 head(t(V3))\n# [,1] [,2] [,3] [,4] [,5]\n# [1,] 1 2 3 6 7\n# [2,] 1 2 4 6 7\n# [3,] 1 2 5 6 7\n# [4,] 1 3 4 6 7\n# [5,] 1 3 5 6 7\n# [6,] 1 4 5 6 7\n\ndim(unique(t(V3)))\n# [1] 150 5\n V V <- list(V1, V2)\ng <- do.call(expand.grid, lapply(V, \\(x) seq_len(ncol(x))))\nV.comb <- do.call(rbind, mapply('[', V, T, g))\n\nidentical(V.comb, V3)\n[1] TRUE\n" }, { "answer_id": 74661707, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "apply apply(expand.grid(seq(ncol(V1)), seq(ncol(V2))), 1, function(i) {\n c(V1[,i[1]], V2[,i[2]])})\n#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 7 7 7 7 7 7 7 7 7 7 8 8 8 8\n#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 8 8 8 8 8 8 9 9 9 9 9 9\n#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 9 9 9 9 10 10 10 10 10 10 10 10\n#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]\n#> [1,] 2 3 1 1 1 1 1 1 2 2 2 3\n#> [2,] 4 4 2 2 2 3 3 4 3 3 4 4\n#> [3,] 5 5 3 4 5 4 5 5 4 5 5 5\n#> [4,] 6 6 6 6 6 6 6 6 6 6 6 6\n#> [5,] 10 10 11 11 11 11 11 11 11 11 11 11\n#> [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62]\n#> [1,] 1 1 1 1 1 1 2 2 2 3 1 1\n#> [2,] 2 2 2 3 3 4 3 3 4 4 2 2\n#> [3,] 3 4 5 4 5 5 4 5 5 5 3 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 8 8 8 8 8 8 8 8 8 8 9 9\n#> [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74]\n#> [1,] 1 1 1 1 2 2 2 3 1 1 1 1\n#> [2,] 2 3 3 4 3 3 4 4 2 2 2 3\n#> [3,] 5 4 5 5 4 5 5 5 3 4 5 4\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 9 9 9 9 9 9 9 9 10 10 10 10\n#> [,75] [,76] [,77] [,78] [,79] [,80] [,81] [,82] [,83] [,84] [,85] [,86]\n#> [1,] 1 1 2 2 2 3 1 1 1 1 1 1\n#> [2,] 3 4 3 3 4 4 2 2 2 3 3 4\n#> [3,] 5 5 4 5 5 5 3 4 5 4 5 5\n#> [4,] 7 7 7 7 7 7 7 7 7 7 7 7\n#> [5,] 10 10 10 10 10 10 11 11 11 11 11 11\n#> [,87] [,88] [,89] [,90] [,91] [,92] [,93] [,94] [,95] [,96] [,97] [,98]\n#> [1,] 2 2 2 3 1 1 1 1 1 1 2 2\n#> [2,] 3 3 4 4 2 2 2 3 3 4 3 3\n#> [3,] 4 5 5 5 3 4 5 4 5 5 4 5\n#> [4,] 7 7 7 7 8 8 8 8 8 8 8 8\n#> [5,] 11 11 11 11 9 9 9 9 9 9 9 9\n#> [,99] [,100] [,101] [,102] [,103] [,104] [,105] [,106] [,107] [,108]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 9 9 10 10 10 10 10 10 10 10\n#> [,109] [,110] [,111] [,112] [,113] [,114] [,115] [,116] [,117] [,118]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 8 8 8 8 8 8 8 8\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,119] [,120] [,121] [,122] [,123] [,124] [,125] [,126] [,127] [,128]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 8 8 9 9 9 9 9 9 9 9\n#> [5,] 11 11 10 10 10 10 10 10 10 10\n#> [,129] [,130] [,131] [,132] [,133] [,134] [,135] [,136] [,137] [,138]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 9 9 9 9 9 9 9 9\n#> [5,] 10 10 11 11 11 11 11 11 11 11\n#> [,139] [,140] [,141] [,142] [,143] [,144] [,145] [,146] [,147] [,148]\n#> [1,] 2 3 1 1 1 1 1 1 2 2\n#> [2,] 4 4 2 2 2 3 3 4 3 3\n#> [3,] 5 5 3 4 5 4 5 5 4 5\n#> [4,] 9 9 10 10 10 10 10 10 10 10\n#> [5,] 11 11 11 11 11 11 11 11 11 11\n#> [,149] [,150]\n#> [1,] 2 3\n#> [2,] 4 4\n#> [3,] 5 5\n#> [4,] 10 10\n#> [5,] 11 11\n" }, { "answer_id": 74661727, "author": "Len Greski", "author_id": 8471931, "author_profile": "https://Stackoverflow.com/users/8471931", "pm_score": 2, "selected": false, "text": "base::merge() merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n > merge(t(combn(1:5, 3)),t(combn(6:11, 2)),by.x=NULL,by.y = NULL)\n V1.x V2.x V3 V1.y V2.y\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n merge() df1 <- data.frame(t(combn(1:5, 3)))\ndf2 <- data.frame(t(combn(6:11, 2)))\ncolnames(df2) <- paste(\"y\",1:2,sep=\"\"))\n\nmerge(df1,df2,by.x=NULL,by.y = NULL)\n > merge(df1,df2,by.x=NULL,by.y = NULL)\n X1 X2 X3 y1 y2\n1 1 2 3 6 7\n2 1 2 4 6 7\n3 1 2 5 6 7\n4 1 3 4 6 7\n5 1 3 5 6 7\n6 1 4 5 6 7\n7 2 3 4 6 7\n8 2 3 5 6 7\n9 2 4 5 6 7\n10 3 4 5 6 7\n11 1 2 3 6 8\n12 1 2 4 6 8\n13 1 2 5 6 8\n14 1 3 4 6 8\n15 1 3 5 6 8\n16 1 4 5 6 8\n17 2 3 4 6 8\n18 2 3 5 6 8\n19 2 4 5 6 8\n20 3 4 5 6 8\n21 1 2 3 6 9\n22 1 2 4 6 9\n23 1 2 5 6 9\n24 1 3 4 6 9\n25 1 3 5 6 9\n" }, { "answer_id": 74661824, "author": "Joseph Wood", "author_id": 4408538, "author_profile": "https://Stackoverflow.com/users/4408538", "pm_score": 3, "selected": false, "text": "comboGrid RcppAlgos library(RcppAlgos)\n\ngrid <- comboGrid(c(rep(list(1:5), 3), rep(list(6:11), 2)),\n repetition = FALSE)\n\nhead(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [1,] 1 2 3 6 7\n#> [2,] 1 2 3 6 8\n#> [3,] 1 2 3 6 9\n#> [4,] 1 2 3 6 10\n#> [5,] 1 2 3 6 11\n#> [6,] 1 2 3 7 8\n\ntail(grid)\n#> Var1 Var2 Var3 Var4 Var5\n#> [145,] 3 4 5 8 9\n#> [146,] 3 4 5 8 10\n#> [147,] 3 4 5 8 11\n#> [148,] 3 4 5 9 10\n#> [149,] 3 4 5 9 11\n#> [150,] 3 4 5 10 11\n C++ system.time(huge <- comboGrid(c(rep(list(1:20), 5), rep(list(21:35), 3)),\n repetition = FALSE))\n#> user system elapsed \n#> 0.990 0.087 1.077\n\ndim(huge)\n#> [1] 7054320 8\n" }, { "answer_id": 74662045, "author": "ThomasIsCoding", "author_id": 12158757, "author_profile": "https://Stackoverflow.com/users/12158757", "pm_score": 3, "selected": false, "text": "expand.grid asplit expand.grid(asplit(V1,2), asplit(V2,2))\n with(\n expand.grid(asplit(V1, 2), asplit(V2, 2)),\n t(mapply(c, Var1, Var2))\n)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15154333/" ]
74,661,568
<p>I have little experience with javascript, I'm trying to make the image update but I'm not succeeding. This image comes through an API</p> <p><a href="https://i.stack.imgur.com/A98jD.jpg" rel="nofollow noreferrer">image here</a></p> <pre><code>&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js&quot;&gt; &lt;script type=&quot;text/javascript&quot;&gt; window.onload = function(){ setInterval(&quot;atualizarqr()&quot;,3000); // troca imagem a cada 3 segundos } function atualizarqr(){ var img = document.getElementById('img').src; document.getElementById('img').src = &quot;https://santoaleixo.com.br/wp-content/uploads/2018/11/Logo-Santo-Aleixo-3.png&quot;; } &lt;/script&gt; &lt;body onload=&quot;atualizarqr&quot;&gt; &lt;img src=&quot;&quot; id=&quot;img&quot;/&gt; &lt;/body&gt; </code></pre>
[ { "answer_id": 74661607, "author": "Andrew Shearer", "author_id": 10688837, "author_profile": "https://Stackoverflow.com/users/10688837", "pm_score": 1, "selected": true, "text": "img setInterval function atualizarqr() {\n document.getElementById(\"img\").src = \"https://santoaleixo.com.br/wp-content/uploads/2018/11/Logo-Santo-Aleixo-3.png\";\n}\n\nwindow.onload = function () {\n // troca imagem a cada 3 segundos\n setInterval(atualizarqr, 3000);\n};\n" }, { "answer_id": 74661670, "author": "Will", "author_id": 19389806, "author_profile": "https://Stackoverflow.com/users/19389806", "pm_score": -1, "selected": false, "text": "window.onload = function() {\n let counter = 0;\n setInterval(() => atualizarqr(), 3000); // troca imagem a cada 3 segundos } \n function atualizarqr() {\n counter++\n console.log(\"called \" + counter + \" times\")\n var img = document.getElementById('img').src;\n document.getElementById('img').src = \"https://santoaleixo.com.br/wp-content/uploads/2018/11/Logo-Santo-Aleixo-3.png\";\n }\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670121/" ]
74,661,576
<p>hi im a react developer and was wondering what is the best modern way to create a simple app for modern touchscreen devices. A simple app with one page, some links which lead to assets which can be viewed.</p>
[ { "answer_id": 74661607, "author": "Andrew Shearer", "author_id": 10688837, "author_profile": "https://Stackoverflow.com/users/10688837", "pm_score": 1, "selected": true, "text": "img setInterval function atualizarqr() {\n document.getElementById(\"img\").src = \"https://santoaleixo.com.br/wp-content/uploads/2018/11/Logo-Santo-Aleixo-3.png\";\n}\n\nwindow.onload = function () {\n // troca imagem a cada 3 segundos\n setInterval(atualizarqr, 3000);\n};\n" }, { "answer_id": 74661670, "author": "Will", "author_id": 19389806, "author_profile": "https://Stackoverflow.com/users/19389806", "pm_score": -1, "selected": false, "text": "window.onload = function() {\n let counter = 0;\n setInterval(() => atualizarqr(), 3000); // troca imagem a cada 3 segundos } \n function atualizarqr() {\n counter++\n console.log(\"called \" + counter + \" times\")\n var img = document.getElementById('img').src;\n document.getElementById('img').src = \"https://santoaleixo.com.br/wp-content/uploads/2018/11/Logo-Santo-Aleixo-3.png\";\n }\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11816068/" ]
74,661,592
<p>I'm trying to concatenate all rows for same ID, the rows for a ID can have null or empty value:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>country</th> <th>value</th> </tr> </thead> <tbody> <tr> <td>FR</td> <td>NULL</td> </tr> <tr> <td>FR</td> <td>1</td> </tr> <tr> <td>FR</td> <td>3</td> </tr> <tr> <td>MA</td> <td>5</td> </tr> <tr> <td>MA</td> <td>NULL</td> </tr> <tr> <td>MA</td> <td>4</td> </tr> <tr> <td>ES</td> <td>9</td> </tr> <tr> <td>ES</td> <td>10</td> </tr> <tr> <td>ES</td> <td>NULL</td> </tr> </tbody> </table> </div> <p>I would like to consider this case in my query to get this result:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>country</th> <th>value</th> </tr> </thead> <tbody> <tr> <td>FR</td> <td>NULL,1,3</td> </tr> <tr> <td>MA</td> <td>4,NULL,9</td> </tr> <tr> <td>ES</td> <td>9,10,NULL</td> </tr> </tbody> </table> </div> <p>We can consider to replace null value to get this result</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>country</th> <th>value</th> </tr> </thead> <tbody> <tr> <td>FR</td> <td>,1,3</td> </tr> <tr> <td>MA</td> <td>4,,9</td> </tr> <tr> <td>ES</td> <td>9,10,</td> </tr> </tbody> </table> </div> <blockquote> <p>sql server version : Microsoft SQL Server 2014 (SP2-GDR) (KB4505217) - 12.0.5223.6 (X64)</p> </blockquote> <p>I have tried this query</p> <pre><code>SELECT IDENT_0, PAYS_0 = STUFF SELECT ', ' + TEXTE_0 FROM UAI.YORIGINELOT AS T2 LEFT JOIN UAI.ATEXTRA ON T2.YOMP_0 = ATEXTRA.IDENT1_0 AND CODFIC_0 = 'TABCOUNTRY' AND LANGUE_0 = 'FRA' And ZONE_0 = 'CRYDES' WHERE T2.IDENT_0 = T1.IDENT_0 ORDER BY IDENT_0 FOR XML PATH (''), TYPE ).value('.', 'varchar(max)') 1, 1, '') FROM UAI.YORIGINELOT AS T1 LEFT JOIN UAI.ATEXTRA ON T1.YFABEN_0 = ATEXTRA.IDENT1_0 AND LANGUE_0='FRA' AND CODFIC_0='TABCOUNTRY' AND ZONE_0 = 'CRYDES' WHERE OBJ_0 = 'ITM' GROUP BY IDENT_0 </code></pre> <p>Thank you</p>
[ { "answer_id": 74661734, "author": "Jonas Metzler", "author_id": 18794826, "author_profile": "https://Stackoverflow.com/users/18794826", "pm_score": 1, "selected": false, "text": "STRING_AGG NULL COALESCE SELECT country, \nSTRING_AGG(COALESCE(value,'NULL'),',') AS value\nFROM yourtable\nGROUP BY country\nORDER BY country;\n STRING_AGG" }, { "answer_id": 74662494, "author": "nbk", "author_id": 5193536, "author_profile": "https://Stackoverflow.com/users/5193536", "pm_score": 0, "selected": false, "text": "SELECT country,\n val = \n STUFF (\n (SELECT \n ',' +value \n FROM yourtable\n WHERE value IS NOT NULL AND y1.country = country\n FOR XML PATH('')\n \n ), 1, 1, ''\n \n )\nFROM yourtable y1\nGROUP by country\nORDER BY country\n SELECT country,\n val = \n STUFF (\n (SELECT \n ',' + COALESCE(value,'') \n FROM yourtable\n WHERE y1.country = country\n ORDER BY COALESCE(value,0)\n FOR XML PATH('')\n \n ), 1, 1, ''\n \n )\nFROM yourtable y1\nGROUP by country\nORDER BY country\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16897693/" ]
74,661,628
<p>I'm trying to create a background modal that's supposed to fill the entire height of the page. The modal only fills about half the page, around 950px (which is the 100% viewable portion). Tried to change the units, tried using calc, used wrapping components.</p> <p>P.S. When the modal is called by JS the display changes from none to block</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#modalBackground { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgb(0 0 0 / 0.7); z-index: 10; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt; ...stuff &lt;div id="modalBackground"&gt;&lt;/div&gt; ...stuff &lt;/body&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74661788, "author": "Zach Jensz", "author_id": 14190543, "author_profile": "https://Stackoverflow.com/users/14190543", "pm_score": 2, "selected": true, "text": "position: absolute position: fixed #modalBackground {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgb(0 0 0 / 0.7);\n z-index: 10;\n} <body>\n ...stuff\n <div id=\"modalBackground\"></div>\n ...stuff\n</body>" }, { "answer_id": 74661844, "author": "Benjieee", "author_id": 11875363, "author_profile": "https://Stackoverflow.com/users/11875363", "pm_score": 0, "selected": false, "text": "#modalBackground {\n max-width: 100vw;\n aspect-ratio: 16/9 (Your prefered size);\n object-fit: cover;\n object-position: center;\n background-color: rgb(0 0 0 / 0.7);\n z-index: 10;\n }\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18494634/" ]
74,661,651
<p>Create Folder for Each File in Recursive Directory, Placing File in Folder</p> <p>On MacOS, so far I have...</p> <pre><code>for file in $(ls -R); do if [[ -f &quot;$file&quot; ]]; then mkdir &quot;${file%.*}&quot;; mv &quot;$file&quot; &quot;${file%.*}&quot;; fi; done </code></pre> <p>This operates correctly on the top level of the nested folder, but does nothing with lower levels.</p> <p>To isolate the error, I tried this instead, operating on rtf files . .</p> <pre><code>for i in $(ls -R);do if [ $i = '*.rtf' ];then echo &quot;I do something with the file $i&quot; fi done </code></pre> <p>This hangs, so I simplified to . .</p> <pre><code>for i in $(ls -R); do echo &quot;file is $i&quot; done </code></pre> <p>That hangs also, so I tried . .</p> <pre><code>for i in $(ls -R); do echo hello </code></pre> <p>That hangs also.</p> <p><code>ls -R</code> works to provide a recursive list of all files.</p> <p>Suggestions appreciated !!</p>
[ { "answer_id": 74661788, "author": "Zach Jensz", "author_id": 14190543, "author_profile": "https://Stackoverflow.com/users/14190543", "pm_score": 2, "selected": true, "text": "position: absolute position: fixed #modalBackground {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgb(0 0 0 / 0.7);\n z-index: 10;\n} <body>\n ...stuff\n <div id=\"modalBackground\"></div>\n ...stuff\n</body>" }, { "answer_id": 74661844, "author": "Benjieee", "author_id": 11875363, "author_profile": "https://Stackoverflow.com/users/11875363", "pm_score": 0, "selected": false, "text": "#modalBackground {\n max-width: 100vw;\n aspect-ratio: 16/9 (Your prefered size);\n object-fit: cover;\n object-position: center;\n background-color: rgb(0 0 0 / 0.7);\n z-index: 10;\n }\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670123/" ]
74,661,682
<p>I have this function on my code that is supposed to read a files last line, and if there is no file create one. My issue is when it creates the files and tries to read the last line it comes up as an error.</p> <pre><code>with open(HIGH_SCORES_FILE_PATH, &quot;w+&quot;) as file: last_line = file.readlines()[-1] if last_line == '\n': with open(HIGH_SCORES_FILE_PATH, 'a') as file: file.write('Jogo:') file.write('\n') file.write(str(0)) file.write('\n') </code></pre> <p>I have tried multiple ways of reading the last line but all of the ones I've tried ends in an error.</p>
[ { "answer_id": 74661916, "author": "tdelaney", "author_id": 642070, "author_profile": "https://Stackoverflow.com/users/642070", "pm_score": 2, "selected": true, "text": "readlines() IndexError os.path.exists os.path.isfile last_line last_line last_line = None\ntry:\n with open(HIGH_SCORES_FILE_PATH) as file:\n for last_line in file:\n pass \nexcept OSError:\n pass\n\nif last_line is None:\n with open(HIGH_SCORES_FILE_PATH, \"w\") as file:\n file.write('Jogo:\\n0\\n')\n last_line = '0\\n'\n" }, { "answer_id": 74661943, "author": "Cyzanfar", "author_id": 3307520, "author_profile": "https://Stackoverflow.com/users/3307520", "pm_score": 0, "selected": false, "text": "with open(HIGH_SCORES_FILE_PATH, \"w+\") as file:\n file.seek(0, 2) # Move cursor to the end of the file\n last_line = file.readline()\n if last_line == '\\n':\n with open(HIGH_SCORES_FILE_PATH, 'a') as file:\n file.write('Jogo:')\n file.write('\\n')\n file.write(str(0))\n file.write('\\n')\n with open(HIGH_SCORES_FILE_PATH, \"w+\") as file:\n file.seek(0, 2) # Move cursor to the end of the file\n last_line = file.readline()\n if last_line == '' or last_line == '\\n':\n with open(HIGH_SCORES_FILE_PATH, 'a') as file:\n file.write('Jogo:')\n file.write('\\n')\n file.write(str(0))\n file.write('\\n')\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661682", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20494616/" ]
74,661,725
<p>I need to add the column for table that if the column is not existed.</p> <p>I ran the <code>Alter Table &lt;table&gt; add &lt;column_name&gt; &lt;type&gt;;</code> however, it will have this error message if the column already exists.</p> <pre><code>InvalidRequest: Error from server: code=2200 [Invalid query] message=&quot;Invalid column name &lt;column_name&gt; because it conflicts with an existing column&quot; </code></pre> <p>Does it have a way to do a similar check on whether the column exists or not?</p> <p>Thank</p>
[ { "answer_id": 74661916, "author": "tdelaney", "author_id": 642070, "author_profile": "https://Stackoverflow.com/users/642070", "pm_score": 2, "selected": true, "text": "readlines() IndexError os.path.exists os.path.isfile last_line last_line last_line = None\ntry:\n with open(HIGH_SCORES_FILE_PATH) as file:\n for last_line in file:\n pass \nexcept OSError:\n pass\n\nif last_line is None:\n with open(HIGH_SCORES_FILE_PATH, \"w\") as file:\n file.write('Jogo:\\n0\\n')\n last_line = '0\\n'\n" }, { "answer_id": 74661943, "author": "Cyzanfar", "author_id": 3307520, "author_profile": "https://Stackoverflow.com/users/3307520", "pm_score": 0, "selected": false, "text": "with open(HIGH_SCORES_FILE_PATH, \"w+\") as file:\n file.seek(0, 2) # Move cursor to the end of the file\n last_line = file.readline()\n if last_line == '\\n':\n with open(HIGH_SCORES_FILE_PATH, 'a') as file:\n file.write('Jogo:')\n file.write('\\n')\n file.write(str(0))\n file.write('\\n')\n with open(HIGH_SCORES_FILE_PATH, \"w+\") as file:\n file.seek(0, 2) # Move cursor to the end of the file\n last_line = file.readline()\n if last_line == '' or last_line == '\\n':\n with open(HIGH_SCORES_FILE_PATH, 'a') as file:\n file.write('Jogo:')\n file.write('\\n')\n file.write(str(0))\n file.write('\\n')\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670138/" ]
74,661,730
<p>In the below type definitions why do <code>P1</code> and <code>P2</code> have different values?</p> <pre><code>type P1 = (() =&gt; 22) extends {[k:string]:any} ? 1:2 //`P1 == 1` type P2 = (() =&gt; 22) extends {[k:string]:unknown} ? 1:2 //`P2 == 2` </code></pre>
[ { "answer_id": 74663009, "author": "Tsvetan Ganev", "author_id": 8597510, "author_profile": "https://Stackoverflow.com/users/8597510", "pm_score": -1, "selected": false, "text": "P1 () => 22 any call true P1 1 P2 () => 22 unknown false unknown P2 2" }, { "answer_id": 74663845, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 2, "selected": true, "text": "{ [k: string]: unknown } {[k: string]: any} () => 22 () => 22 {[k: string]: unknown} any let anyRec: { [k: string]: any };\nanyRec = () => 22; // okay\n\nlet unkRec: { [k: string]: unknown };\nunkRec = () => 22; // error\n P1 P2" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3963067/" ]
74,661,777
<p>I working on <code>asp.net core 5 mvc</code> web application , I face issue I can't store Picture User on database table <code>[dbo].[AspNetUsers]</code>.</p> <p>so can you tell me how to store personal picture of user on table <code>[dbo].[AspNetUsers]</code>.</p> <p>I already add new column PictureUser on table <code>[dbo].[AspNetUsers]</code> to store User Picture .</p> <p>I need to know what I will modify on controller and view to store user picture on database table .</p> <p>I working on Microsoft identity membership when register user</p> <p>my model as</p> <pre><code>public class RegisterVM { public string EmailAddress { get; set; } public string Password { get; set; } public byte[] PictureUser { get; set; } } </code></pre> <p>my action controller</p> <pre><code> [HttpPost] public async Task&lt;IActionResult&gt; Register(RegisterVM registerVM) { var newUser = new ApplicationUser() { FullName = registerVM.FullName, Email = registerVM.EmailAddress, UserName = registerVM.EmailAddress, //How to add Image upload Here }; var newUserResponse = await _userManager.CreateAsync(newUser, registerVM.Password); if (newUserResponse.Succeeded) { await _signInManager.SignInAsync(newUser, isPersistent: false); return View(&quot;RegisterCompleted&quot;); } return View(registerVM); } </code></pre> <p>on view</p> <pre><code>@model RegisterVM; &lt;form asp-action=&quot;Register&quot;&gt; &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;label asp-for=&quot;EmailAddress&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt; &lt;input asp-for=&quot;EmailAddress&quot; class=&quot;form-control&quot; /&gt; &lt;span asp-validation-for=&quot;EmailAddress&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;label asp-for=&quot;Password&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt; &lt;input asp-for=&quot;Password&quot; class=&quot;form-control&quot; /&gt; &lt;span asp-validation-for=&quot;Password&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt; &lt;/div&gt; //How to add Image upload Here &lt;div class=&quot;form-group&quot;&gt; &lt;input class=&quot;btn btn-outline-success float-right&quot; type=&quot;submit&quot; value=&quot;Sign up&quot; /&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p><strong>How to add Image Upload on View And Controller Action this is Exactly my Question ?</strong></p>
[ { "answer_id": 74663009, "author": "Tsvetan Ganev", "author_id": 8597510, "author_profile": "https://Stackoverflow.com/users/8597510", "pm_score": -1, "selected": false, "text": "P1 () => 22 any call true P1 1 P2 () => 22 unknown false unknown P2 2" }, { "answer_id": 74663845, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 2, "selected": true, "text": "{ [k: string]: unknown } {[k: string]: any} () => 22 () => 22 {[k: string]: unknown} any let anyRec: { [k: string]: any };\nanyRec = () => 22; // okay\n\nlet unkRec: { [k: string]: unknown };\nunkRec = () => 22; // error\n P1 P2" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18935642/" ]
74,661,780
<p>I decide to make clock in C as my first &quot;Project&quot;, Changing minutes after 60 sec mark went well but when i need to change hours after minutes my secon number of seconds wont reset so it stayis with number 9 stuck until i go to the point of 10 sec.</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;Windows.h&gt; int main () { int h = 0,m = 59, s = 55; int prekid = 1; while (prekid == 1) { printf(&quot; \r H:%d | M: %d | S: %d&quot;,h,m,s); s++; fflush(stdout); if (s == 60) { m++; s= 0; } if (m == 60) { m = 0; s= 0; h++; } sleep(1); } return 0; } </code></pre>
[ { "answer_id": 74663009, "author": "Tsvetan Ganev", "author_id": 8597510, "author_profile": "https://Stackoverflow.com/users/8597510", "pm_score": -1, "selected": false, "text": "P1 () => 22 any call true P1 1 P2 () => 22 unknown false unknown P2 2" }, { "answer_id": 74663845, "author": "jcalz", "author_id": 2887218, "author_profile": "https://Stackoverflow.com/users/2887218", "pm_score": 2, "selected": true, "text": "{ [k: string]: unknown } {[k: string]: any} () => 22 () => 22 {[k: string]: unknown} any let anyRec: { [k: string]: any };\nanyRec = () => 22; // okay\n\nlet unkRec: { [k: string]: unknown };\nunkRec = () => 22; // error\n P1 P2" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20504197/" ]
74,661,787
<p>What did I miss to make parallax scrolling working?</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-html lang-html prettyprint-override"><code>&lt;div className="h-screen"&gt; &lt;div className="relative h-full w-full bg-cover bg-fixed bg-center bg-no-repeat"&gt; &lt;Image src="https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&amp;ixlib=rb-1.2.1&amp;auto=format&amp;fit=crop&amp;w=1955&amp;q=80'" objectFit="cover" alt="test" layout="fill" priority={true} /&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74661976, "author": "armful", "author_id": 20664163, "author_profile": "https://Stackoverflow.com/users/20664163", "pm_score": 0, "selected": false, "text": "parallax div Image <div className=\"h-screen\" parallax=\"0.5\">\n <div className=\"relative h-full w-full bg-cover bg-fixed bg-center bg-no-repeat\">\n <Image src=\"https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1955&q=80'\" objectFit=\"cover\" alt=\"test\" layout=\"fill\" priority={true} />\n </div>\n</div>\n parallax" }, { "answer_id": 74662399, "author": "Yilmaz", "author_id": 10262805, "author_profile": "https://Stackoverflow.com/users/10262805", "pm_score": 1, "selected": false, "text": "Image backGroundImage div bg-fixed <div\n className=\"relative h-full w-full bg-cover bg-center bg-fixed bg-no-repeat\"\n style={{\n backgroundImage: `url(https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1955&q=80%27)`,\n }}\n ></div>\n const Test = () => {\n return (\n <div className=\"h-screen\">\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div\n className=\"relative h-full w-full bg-cover bg-center bg-fixed bg-no-repeat\"\n style={{\n backgroundImage: `url(https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1955&q=80%27)`,\n }}\n ></div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n <div className=\"p-5 text-2xl bg-purple-300 bg-opacity-50 rounded-xl\">\n Welcome to my site!\n </div>\n </div>\n );\n};\n\nexport default Test;\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11826960/" ]
74,661,800
<p>Lets say there are functions</p> <pre><code>function a(someparams){ console.log('a called') } function b(){ console.log('b called') } ... const c (someParam) =&gt; { console.log('c called')} </code></pre> <p>I want to extend default function prototype something like <code>Function.prototype.onCall = (args) =&gt; {console.log('Proxy fn called!',args)}</code> in a very begining of a page code, so every existing and new functions, upon call, will log 'Proxy fn called!'. There are solutions to map window.functions - but they only work for existing functions, and I want to extend prototype to let it execute my piece of code. The goal is to automatically check if args are valid. No I don't want typescript or flow, thanks for suggestion. Is this possible? where to look at?</p> <p>I found</p> <pre><code>(function() { var call = Function.prototype.call; Function.prototype.call = function() { console.log(this, arguments); // Here you can do whatever actions you want return call.apply(this, arguments); }; }()); </code></pre> <p>to be the closest to what I want so far, but these aren't called when calling a function normally, e.g. <code>someFunction();</code>, without explicit <code>.call</code> or <code>.apply</code>.</p> <p>I have found maybe decorators is a way to go? the official doc said they are still not a standard <a href="https://github.com/tc39/proposal-decorators" rel="nofollow noreferrer">https://github.com/tc39/proposal-decorators</a> but there is a babel plugin <a href="https://babeljs.io/docs/en/babel-plugin-proposal-decorators" rel="nofollow noreferrer">https://babeljs.io/docs/en/babel-plugin-proposal-decorators</a> is it possible that it would do the job or am I looking into wrong direction?</p>
[ { "answer_id": 74661841, "author": "Cyzanfar", "author_id": 3307520, "author_profile": "https://Stackoverflow.com/users/3307520", "pm_score": 0, "selected": false, "text": "function onCall(target, name, descriptor) {\n const original = descriptor.value;\n\n if (typeof original === 'function') {\n descriptor.value = function(...args) {\n console.log('Proxy fn called!');\n return original.apply(this, args);\n };\n }\n\n return descriptor;\n}\n\nclass MyClass {\n @onCall\n myMethod(a, b) {\n // do something\n }\n}\n\nconst instance = new MyClass();\ninstance.myMethod(1, 2); // logs 'Proxy fn called!'\n" }, { "answer_id": 74662364, "author": "Peter Seliger", "author_id": 2627243, "author_profile": "https://Stackoverflow.com/users/2627243", "pm_score": 1, "selected": false, "text": "around before after afterThrowing afterFinally thisArg this Proxy apply construct Function.prototype.around // 1st example ... wrapping **around** a simple function\n\nfunction consumeAnyParameter(...params) {\n console.log('inside `consumeAnyParameter` ... params ...', params);\n}\nfunction interceptor(originalFunction, interceptorReference, ...params) {\n // intercept.\n console.log('inside `interceptor` ... ', {\n params,\n originalFunction,\n interceptorReference,\n });\n // proceed.\n originalFunction(...params);\n}\n\n// reassignment of ... a modified version of itself.\nconsumeAnyParameter = consumeAnyParameter.around(interceptor);\n\n// invoke modified version.\nconsumeAnyParameter('foo', 'bar', 'baz');\n\n\n// 2nd example ... wrapping **around** a type's method.\n\nconst type = {\n foo: 'foo',\n bar: 'bar',\n whoAmI: function () {\n console.log('Who am I? I\\'m `this` ...', this);\n }\n}\ntype.whoAmI();\n\ntype.whoAmI = type\n .whoAmI\n .around(function (proceed, interceptor, ...params) {\n\n console.log('interceptor\\'s `this` context ...', this);\n console.log('interceptor\\'s `params` ...', params);\n\n // proceed.apply(this, params);\n proceed.call(this);\n\n }, type); // for method modification do pass the context/target. \n\ntype.whoAmI(); .as-console-wrapper { min-height: 100%!important; top: 0; } <script>\n// poor man's module.\n(function (Function) {\n\n // module scope.\n\n function getSanitizedTarget(value) {\n return value ?? null;\n }\n function isFunction(value) {\n return (\n 'function' === typeof value &&\n 'function' === typeof value.call &&\n 'function' === typeof value.apply\n );\n }\n\n // modifier implementation.\n\n function around/*Modifier*/(handler, target) {\n target = getSanitizedTarget(target);\n\n const proceed = this;\n\n return (\n isFunction(handler) &&\n isFunction(proceed) &&\n\n function aroundType(...argumentArray) {\n // the target/context of the initial modifier/modification time\n // still can be overruled by a handler's apply/call time context.\n const context = getSanitizedTarget(this) ?? target;\n\n return handler.call(\n context,\n proceed,\n handler,\n argumentArray,\n );\n }\n ) || proceed;\n }\n\n // modifier assignment.\n\n Object.defineProperty(Function.prototype, 'around', {\n configurable: true,\n writable: true,\n value: around/*Modifier*/,\n });\n\n}(Function));\n</script>" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20480844/" ]
74,661,801
<p>I'm reading an introducty book about C and I came across the following paragraph:</p> <p><a href="https://i.stack.imgur.com/5QygF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QygF.png" alt="enter image description here" /></a></p> <p>But the following code compiles with expected output:</p> <pre><code>#include &lt;stdio.h&gt; int main() { for(int i = 0; i&lt;=10; i++) { int val = i + 1; int x = val * val; printf(&quot;%d\n&quot;, x); int y = x; } return 0; } </code></pre> <p>I use <a href="https://www.onlinegdb.com/" rel="nofollow noreferrer">https://www.onlinegdb.com/</a> and in the above code I declared many variables after the first executable statement. And this is to me does not match what the section from the book tells.</p> <p>Am I misunderstanding what the book is telling?</p>
[ { "answer_id": 74661934, "author": "Sascha Doerdelmann", "author_id": 11934850, "author_profile": "https://Stackoverflow.com/users/11934850", "pm_score": 1, "selected": true, "text": "int i ...;\nint val ...;\nint x ...;\n int y;" }, { "answer_id": 74661982, "author": "Eric Postpischil", "author_id": 298225, "author_profile": "https://Stackoverflow.com/users/298225", "pm_score": 3, "selected": false, "text": "{ } { } { } int val = i + 1; int x = val * val; { int val = i + 1; for for ( ; ; ) for ( ; ; ) for ( ; ) ; int i = 0 for(int i = 0; i<=10; i++)" }, { "answer_id": 74662104, "author": "Schwern", "author_id": 14660, "author_profile": "https://Stackoverflow.com/users/14660", "pm_score": 1, "selected": false, "text": "-std=c89 cc -Wall -Wshadow -Wwrite-strings -Wextra -Wconversion -std=c89 -pedantic -g -fsanitize=address -c -o test.o test.c\ntest.c:5:9: warning: variable declaration in for loop is a C99-specific feature [-Wc99-extensions]\n for(int i = 0; i<=10; i++)\n ^\ntest.c:5:9: warning: GCC does not allow variable declarations in for loop initializers before C99 [-Wgcc-compat]\n2 warnings generated.\n -std=c99 //" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13259521/" ]
74,661,819
<p>I am working with a number of custom classes <code>X</code> that have <code>__add__(self)</code>, and when added together return another class, <code>Y</code>.</p> <p>I often have iterables [of various sizes] of <code>X</code>, <code>ex = [X1, X2, X3]</code> that I would love to add together to get <code>Y</code>. However, <code>sum(ex)</code> throws an <code>int</code> error, because <code>sum</code> starts at 0 which can't be added to my class <code>X</code>.</p> <p>Can someone please help me with an easy, pythonic way to do <code>X1 + X2 + X3 ...</code> of an interable, so I get <code>Y</code>...</p> <p>Thanks!</p> <p>Ps it’s a 3rd party class, X, so I can’t change it. It does have <em>radd</em> though.</p> <p>My gut was that there was some way to do list comprehension? Like += on themselves</p>
[ { "answer_id": 74661852, "author": "Jon Kiparsky", "author_id": 405303, "author_profile": "https://Stackoverflow.com/users/405303", "pm_score": 3, "selected": true, "text": "sum sum([1,2,3], 10) sum([[1], [2], [3]], []) sum sum([x1, x2, x3,...], x0) class X: \n def __init__(self, val): \n self.val = val \n def __add__(self, other):\n return X(self.val + other.val) \n \n def __repr__(self): \n return \"X({})\".format(self.val) \n \nclass Y: \n def __init__(self, val): \n self.val = val \n def __add__(self, other):\n return X(self.val + other.val) \n \n def __repr__(self): \n return \"Y({})\".format(self.val) \n\n >>> sum([Y(1), Y(2), Y(3)], Y(0))\nX(6)\n>>> sum([Y(1), Y(2), Y(3)], Y(0))\nX(6)\n>>>\n" }, { "answer_id": 74661952, "author": "treuss", "author_id": 19838568, "author_profile": "https://Stackoverflow.com/users/19838568", "pm_score": -1, "selected": false, "text": "__add__ reduce functools from functools import reduce\n\nxes = [x1, x2, x3]\ny = reduce(lambda a,b: a+b, xes)\n" }, { "answer_id": 74662134, "author": "keynesiancross", "author_id": 558619, "author_profile": "https://Stackoverflow.com/users/558619", "pm_score": -1, "selected": false, "text": "Y = [ex[0]=+X for x in ex[1:]][0]\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/558619/" ]
74,661,840
<p>It's my first post on the stackoverflow so I apologize in advance if I am doing something wrong.</p> <p>I'm new to Cypress E2E test. Im trying to write a test for react WebApplication. Unfortunately I am stuck on the element when the application on mobile views e.g. viewPort 360 opens in full screen. The application is doing that when I interact with the first element (login page). After filling the login field spec then stops with the message &quot;(uncaught exception) TypeError: Fullscreen request denied&quot;.</p> <p>Is there any way to work around this? On higher resolutions where full screen is not opened spec passes without problem.</p> <p><a href="https://i.stack.imgur.com/CUBHg.png" rel="nofollow noreferrer">Screen with the error from Cypress</a></p> <p>I was searching if there is a parameter in Cypress settings to disable the blocker for full screen , unfortunately I did not find anything. The same problem occurs on Chrome and Firefox.</p> <p>The spec code is very simple</p> <p>I use the class from POM</p> <pre class="lang-js prettyprint-override"><code>class Homepage_PO { Visit_Homepage(){ cy.visit(Cypress.env('integrax_homepage'),{timeout:60000}) } Login(login, password){ cy.get('input[name=&quot;login&quot;]').type(login) cy.get('input[name=&quot;password&quot;]').type(password) cy.get('#loginBtn').click() } } export default Homepage_PO; </code></pre> <p>and the spec code</p> <pre class="lang-js prettyprint-override"><code>import Homepage_PO from &quot;../../support/pageObjects/integraX/Homepage_PO&quot;; /// &lt;reference types = 'cypress'/&gt; describe('Log in into IntegraX', () =&gt; { const homepage_PO = new Homepage_PO() beforeEach(() =&gt; { homepage_PO.Visit_Homepage(); }); it.only('log in as Integra administrator', () =&gt; { homepage_PO.Login(Cypress.env('integra_admin_login'), Cypress.env('integra_admin_password')); }); it('log in as Car Service', () =&gt; { }); }); </code></pre>
[ { "answer_id": 74661969, "author": "Paolo", "author_id": 16791505, "author_profile": "https://Stackoverflow.com/users/16791505", "pm_score": 3, "selected": true, "text": "const stub = cy.stub();\ncy.get('input[name=\"password\"]')\n .then($el => $el[0].requestFullscreen = stub)\n .type(password)\n .then(() => expect(stub).to.be.called)\n const stub = cy.stub();\ncy.document().then(doc => {\n doc.documentElement.requestFullscreen = stub\n})\ncy.get('input[name=\"password\"]')\n .type(password)\n .then(() => expect(stub).to.be.called)\n \nCypress.once('uncaught:exception', () => \n return false\n})\ncy.get('input[name=\"password\"]')\n .type(password) // error suppressed by above handler\n" }, { "answer_id": 74666339, "author": "Robert Świderski", "author_id": 20670201, "author_profile": "https://Stackoverflow.com/users/20670201", "pm_score": 0, "selected": false, "text": "const stub = cy.stub();\ncy.document().then(doc => {\n doc.documentElement.requestFullscreen = stub\n})\ncy.get('input[name=\"password\"]')\n .type(password)\n .then(() => expect(stub).to.be.called)\n Cypress.once('uncaught:exception', () => \n return false\n})\ncy.get('input[name=\"password\"]')\n .type(password) // error suppressed by above handler\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670201/" ]
74,661,843
<p>I'm currently making c++ project but this error is bothering me for long time and i cannot figure out why this doesn't work. I was searching about this error but still i don't understand it.</p> <p>Thanks in advance.</p> <pre><code>#include &lt;iostream&gt; using namespace std; class A { public: int a = 0; A(int _a) : a(a) {} }; class B { public: A a; void test() { A a1(6); a = a1; } }; int main() { B b1; b1.test(); return 0; } </code></pre> <p>I tried to initialized value in constructor in class and this worked but what if i don't want to do this?</p>
[ { "answer_id": 74661907, "author": "bolov", "author_id": 2805305, "author_profile": "https://Stackoverflow.com/users/2805305", "pm_score": 2, "selected": false, "text": "A B a a std::optional<A> a std::unique_ptr<A>" }, { "answer_id": 74663831, "author": "Remy Lebeau", "author_id": 65863, "author_profile": "https://Stackoverflow.com/users/65863", "pm_score": 1, "selected": true, "text": "A a(a) a(_a) A delete B::a B delete b1 main() A class A\n{\npublic:\n int a = 0;\n A() {}; // or: A() = default; // <-- HERE\n A(int _a) : a(_a) {}\n};\n class A\n{\npublic:\n int a = 0;\n A(int _a = 0) : a(_a) {} // <-- HERE\n};\n B B::a class B\n{\npublic:\n A a;\n B() : a(0) {} // <-- HERE\n void test()\n {\n A a1(6);\n a = a1;\n }\n};\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17037781/" ]
74,661,847
<p>I have a yearly table which on a monthly basis will append data from another table. However, I need to check the max date on the monthly table before appending it. If the max date on monthly is same as YTD, then do not append else append. How can I achieve this in SAS.</p> <p>I tried using append but don't know how to check the dates before appending.</p>
[ { "answer_id": 74661907, "author": "bolov", "author_id": 2805305, "author_profile": "https://Stackoverflow.com/users/2805305", "pm_score": 2, "selected": false, "text": "A B a a std::optional<A> a std::unique_ptr<A>" }, { "answer_id": 74663831, "author": "Remy Lebeau", "author_id": 65863, "author_profile": "https://Stackoverflow.com/users/65863", "pm_score": 1, "selected": true, "text": "A a(a) a(_a) A delete B::a B delete b1 main() A class A\n{\npublic:\n int a = 0;\n A() {}; // or: A() = default; // <-- HERE\n A(int _a) : a(_a) {}\n};\n class A\n{\npublic:\n int a = 0;\n A(int _a = 0) : a(_a) {} // <-- HERE\n};\n B B::a class B\n{\npublic:\n A a;\n B() : a(0) {} // <-- HERE\n void test()\n {\n A a1(6);\n a = a1;\n }\n};\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670296/" ]
74,661,877
<p>the goal is to move between rooms in this simplified version of a text base game. The code works exactly as planned except for if you try and input 'exit' directly after inputting 'instructions'. after inputting 'instructions' the first 'exit' get ran in the else invalid statement then the second 'exit' input exits the game as intended. If you continue at least one input after 'instructions' than exit works properly as well.</p> <pre><code>rooms = { 'Great Hall': {'South': 'Bedroom'}, 'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'}, 'Cellar': {'West': 'Bedroom'} } def instruction(): &quot;&quot;&quot;Function to give instructions on how to play the game&quot;&quot;&quot; print('Welcome to Module 6 Milestone') print('Move commands are go North, go South, go East, go West') print('Typing exit will exit the game') print('Inputting instructions will remind you of the game instructions') print('Good luck may the odds be in your favor') def invalid(): &quot;&quot;&quot;Function for if an invalid input is entered&quot;&quot;&quot; print('------------') print('Whoops invalid command, try again') print('------------') def main(): &quot;&quot;&quot;Main function that runs the movement between rooms&quot;&quot;&quot; current_room = 'Great Hall' print('\nYou are starting in the', current_room) move = input('What will you do next?\n&gt;').split() directions = ['North', 'South', 'East', 'West'] # directions in the dictionary while True: if len(move) &lt; 2: # for one word inputs if 'exit' in move: # exit the game print('\nThanks for playing!') break elif 'instructions' in move: # reprint instructions instruction() print('------------') print('\nYou are in the', current_room) else: invalid() print('You are still in the', current_room) move = input('\nWhat will you do next?\n&gt;').split() # next move input if len(move) == 2: # 2 word inputs if move[1] in directions: # checks if move is a valid direction if move[1] in rooms[current_room]: # if move is a valid direction in current room current_room = rooms[current_room][move[1]] # changes current room if valid print('------------') print('You have found the', current_room) elif move[1] not in rooms[current_room]: # if move in directions but not a valid move in current room print('------------') print('Oh no it seems to be a dead in') print('You are still in the', current_room) else: # not a valid move command invalid() print('You are still in the', current_room) move = input('What will you do next?\n&gt;').split() # next move input else: # invalid move command invalid() print('You are still in the', current_room) move = input('What will you do next?\n&gt;').split() instruction() # prints instructions function when game runs print('------------') if __name__ == '__main__': # if code is not imported than main() will run main() </code></pre>
[ { "answer_id": 74661899, "author": "treuss", "author_id": 19838568, "author_profile": "https://Stackoverflow.com/users/19838568", "pm_score": 1, "selected": false, "text": "move = input('\\nWhat will you do next?\\n>').split() # next move input\n continue" }, { "answer_id": 74661946, "author": "John Gordon", "author_id": 494134, "author_profile": "https://Stackoverflow.com/users/494134", "pm_score": 1, "selected": true, "text": "while True:\n if len(move) < 2: # for one word inputs\n # handle the input in various ways\n move = input('\\nWhat will you do next?\\n>').split() # next move input\n if len(move) == 2: # 2 word inputs\n if if elif while True:\n move = input(\"...\").split()\n if len(move) < 2:\n # handle it\n elif len(move) == 2:\n # handle it\n else:\n # handle it\n \n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20662439/" ]
74,661,880
<p>I am attempting to create an SQL query which will compress multidimentional data using PIVOT, but need to do some operations on the pivoted data.</p> <p>I have coding experience but very little experience with SQL and am using SQLPathfinder3 to create and execute queries, so what I am looking for is top level approach - what order of operations should I be going for here to achieve the desired result?</p> <p>An example of my initial result table, gotten with SELECT, is as follows:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Item</th> <th>Property</th> <th>Subproperty</th> <th>Thing</th> </tr> </thead> <tbody> <tr> <td>item1</td> <td>propertyA</td> <td>subproperty1</td> <td>value1_A_1</td> </tr> <tr> <td>item1</td> <td>propertyA</td> <td>subproperty2</td> <td>value1_A_2</td> </tr> <tr> <td>item1</td> <td>propertyB</td> <td>subproperty1</td> <td>value1_B_1</td> </tr> <tr> <td>item1</td> <td>propertyB</td> <td>subproperty2</td> <td>value1_B_2</td> </tr> <tr> <td>item2</td> <td>propertyA</td> <td>subproperty1</td> <td>value2_A_1</td> </tr> <tr> <td>item2</td> <td>propertyA</td> <td>subproperty2</td> <td>value2_A_2</td> </tr> <tr> <td>item2</td> <td>propertyB</td> <td>subproperty1</td> <td>value2_B_1</td> </tr> <tr> <td>item2</td> <td>propertyB</td> <td>subproperty2</td> <td>value2_B_2</td> </tr> </tbody> </table> </div> <p>By executing one pivot, assigning Subproperty as the CTHEADER, and Thing as the CTVALUE, I can create this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Item</th> <th>Property</th> <th>Subproperty1</th> <th>Subproperty2</th> </tr> </thead> <tbody> <tr> <td>item1</td> <td>propertyA</td> <td>value1_A_1</td> <td>value1_A_2</td> </tr> <tr> <td>item1</td> <td>propertyB</td> <td>value1_B_1</td> <td>value1_B_2</td> </tr> <tr> <td>item2</td> <td>propertyA</td> <td>value2_A_1</td> <td>value2_A_2</td> </tr> <tr> <td>item2</td> <td>propertyB</td> <td>value2_B_1</td> <td>value2_B_2</td> </tr> </tbody> </table> </div> <p>Similarly, I can pivot around &quot;Subproperty&quot; to get something analogous:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Item</th> <th>Subproperty</th> <th>Property A</th> <th>Property B</th> </tr> </thead> <tbody> <tr> <td>item1</td> <td>subproperty1</td> <td>value1_A_1</td> <td>value1_A_2</td> </tr> <tr> <td>item1</td> <td>subproperty2</td> <td>value1_B_1</td> <td>value1_B_2</td> </tr> <tr> <td>item2</td> <td>subproperty1</td> <td>value2_A_1</td> <td>value2_A_2</td> </tr> <tr> <td>item2</td> <td>subproperty2</td> <td>value2_B_1</td> <td>value2_B_2</td> </tr> </tbody> </table> </div> <p>The final result that I need is this - a combination of the above values:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Item</th> <th>Property A</th> <th>Property B</th> </tr> </thead> <tbody> <tr> <td>item1</td> <td>value1_A_1 + value1_A_2</td> <td>value1_B_1 + value1_B_2</td> </tr> <tr> <td>item2</td> <td>value2_A_1 + value2_A_2</td> <td>value2_B_1 + value2_B_2</td> </tr> </tbody> </table> </div> <p>I don't know how to go about doing this in a single query, but I would very much like to, because this is something that needs to be automated.</p> <p>I can't simply SELECT the sums that I want, because those values are on four separate lines. I could workaround in excel or python, especially if I can effect the result below, but I'm not sure how to do this.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Item</th> <th>PropA Sub1</th> <th>PropA Sub2</th> <th>PropB Sub1</th> <th>PropB Sub2</th> </tr> </thead> <tbody> <tr> <td>item1</td> <td>value1_A_1</td> <td>value1_A_2</td> <td>value1_B_1</td> <td>value1_B_2</td> </tr> <tr> <td>item2</td> <td>value2_A_1</td> <td>value2_A_2</td> <td>value2_B_1</td> <td>value2_B_2</td> </tr> </tbody> </table> </div> <p>Any help, or pointers towards educational material would be appreciated, thanks.</p>
[ { "answer_id": 74661899, "author": "treuss", "author_id": 19838568, "author_profile": "https://Stackoverflow.com/users/19838568", "pm_score": 1, "selected": false, "text": "move = input('\\nWhat will you do next?\\n>').split() # next move input\n continue" }, { "answer_id": 74661946, "author": "John Gordon", "author_id": 494134, "author_profile": "https://Stackoverflow.com/users/494134", "pm_score": 1, "selected": true, "text": "while True:\n if len(move) < 2: # for one word inputs\n # handle the input in various ways\n move = input('\\nWhat will you do next?\\n>').split() # next move input\n if len(move) == 2: # 2 word inputs\n if if elif while True:\n move = input(\"...\").split()\n if len(move) < 2:\n # handle it\n elif len(move) == 2:\n # handle it\n else:\n # handle it\n \n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10204519/" ]
74,661,920
<p>I'm trying to create <code>Match</code> between two <code>User</code>'s. However i'm getting this error</p> <pre><code>Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---&gt; Microsoft.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY &quot;PK_Users&quot; constraint. Cannot insert duplicate key into object 'dbo.Users'. Duplicate key value: (0c7a0cdc-a7ba-4cf8-ade2-0cef44761597). </code></pre> <p>I have this entities</p> <pre><code>public class Match { public Guid Id { get; set; } public User User { get; set; } public User LikedUser { get; set; } public bool Matched { get; set; } } </code></pre> <pre><code>public class User { public string Username { get; set; } public string Name { get; set; } public string Surname { get; set; } public Guid CityId { get; set; } public City City { get; set; } public Guid GenderId { get; set; } public Gender Gender { get; set; } public ICollection&lt;Match&gt; Matches { get; set; } = new HashSet&lt;Match&gt;(); public ICollection&lt;Match&gt; LikedBy { get; set; } = new HashSet&lt;Match&gt;(); } </code></pre> <p>That's unfinished method i just want to check if it would create <code>Match</code> or not</p> <pre><code>public async Task&lt;Guid&gt; Handle(CreateMatchCommand request, CancellationToken cancellationToken) { var liker = await _unitOfWork.UserRepository.FindByIdAsync(request.Dto.Liker); var liked = await _unitOfWork.UserRepository.FindByIdAsync(request.Dto.Liked); var match = new Match { LikedUser = liked, User = liker }; var matchId = await _unitOfWork.MatchRepository.CreateAsync(match); await _unitOfWork.SaveChangesAsync(cancellationToken); return matchId; } </code></pre> <p>MatchRepository</p> <pre><code>public async Task&lt;Guid&gt; CreateAsync(Match match) { var matchEntity = _mapper.Map&lt;MatchEntity&gt;(match); await _context.Matches.AddAsync(matchEntity); return matchEntity.Id; } </code></pre> <p>UserRepository</p> <pre><code>public async Task&lt;User&gt; FindByIdAsync(Guid guid) { var user = await _context.Users .FirstOrDefaultAsync(u =&gt; u.Id == guid); if (user == null) throw new NotFoundException(typeof(User), guid); _context.Entry(user).State = EntityState.Detached; return _mapper.Map&lt;User&gt;(user); } </code></pre> <p>Why i'm getting this error?</p>
[ { "answer_id": 74666021, "author": "Fitri Halim", "author_id": 13218799, "author_profile": "https://Stackoverflow.com/users/13218799", "pm_score": 0, "selected": false, "text": "public async Task<User> FindByIdAsync(Guid guid)\n {\n var user = await _context.Users\n .FirstOrDefaultAsync(u => u.Id == guid);\n if (user == null) throw new NotFoundException(typeof(User), guid);\n\n //_context.Entry(user).State = EntityState.Detached; <-- Remove this\n return _mapper.Map<User>(user);\n }\n Liked Like public async Task<Guid> Handle(CreateMatchCommand request, CancellationToken cancellationToken)\n{\n var liker = await _unitOfWork.UserRepository.FindByIdAsync(request.Dto.Liker);\n var liked = await _unitOfWork.UserRepository.FindByIdAsync(request.Dto.Liked);\n\n_unitOfWork.Entry(liker).State = EntityState.Unchanged;\n_unitOfWork.Entry(liked).State = EntityState.Unchanged;\n\n var match = new Match { LikedUser = liked, User = liker };\n\n var matchId = await \n \n \n _unitOfWork.MatchRepository.CreateAsync(match);\n await _unitOfWork.SaveChangesAsync(cancellationToken);\n\n return matchId;\n}\n Liker Liked Match Liker Liked" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17775991/" ]
74,661,922
<pre><code>package main; import java.util.Scanner; public class test { public static String[] ranks = {&quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;, &quot;Ace&quot;, &quot;Jack&quot;, &quot;Queen&quot;, &quot;King&quot;}; public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { String[] array = new String[13]; for(int i = 0; i&lt;array.length; i++) { array[i] = ranks[i] ; } for (int i = 0; i&lt;array.length; i++ ) { System.out.println(array[i]); } cutDeck(array); for (int i = 0; i&lt;array.length; i++ ) { System.out.println(array[i]); } } public static String[] cutDeck(String[] deck) { System.out.println(&quot;Cut please. 'Choose between 1-51'&quot;); int cutPoint = scanner.nextInt(); String[] topDeck= new String[52]; String[] bottomDeck = new String[52]; String[] newDeck = new String[deck.length]; for (int i = 1; i&lt;=cutPoint ; i++) { // Topdeck topDeck[i-1] = deck[deck.length-1*i]; } for (int i = 0; i &lt; cutPoint / 2; i++) // Reverse topdeck { String temp = topDeck[i]; topDeck[i] = topDeck[topDeck.length - i - 1]; topDeck[topDeck.length - i - 1] = temp; } for (int i = 0; i&lt;deck.length - cutPoint; i++) { //Bottom cut point bottomDeck[i] = deck[i]; } for (int i = 0; i&lt;deck.length; i++) { if (cutPoint &gt; i) { newDeck[i] = topDeck[i]; } else { newDeck[i] = bottomDeck[i]; } } return newDeck; } } </code></pre> <p>I am trying to cut the deck while asking to the user.</p> <p>This function does not cut the deck.</p> <p>Where am I doing wrong ?</p> <p>I tried everything but I lost my brain can you guys help me please?</p> <p>I am open to another ideas so you can give improve my code.</p> <p>Thanks in advance.</p>
[ { "answer_id": 74662116, "author": "Hesham A", "author_id": 3403829, "author_profile": "https://Stackoverflow.com/users/3403829", "pm_score": 1, "selected": false, "text": "public static void cutDeck(String[] deck) {\n System.out.println(\"Cut please. 'Choose between 1-\" + (deck.length - 1) + \"'\");\n int cutPoint = scanner.nextInt();\n \n // Check that the cut point is within the valid range for the deck size\n if (cutPoint < 1 || cutPoint >= deck.length) {\n System.out.println(\"Invalid cut point. Please try again.\");\n return;\n }\n \n // Create the top and bottom halves of the deck\n String[] topDeck = new String[cutPoint];\n String[] bottomDeck = new String[deck.length - cutPoint];\n for (int i = 0; i < cutPoint; i++) {\n topDeck[i] = deck[i];\n }\n for (int i = cutPoint; i < deck.length; i++) {\n bottomDeck[i - cutPoint] = deck[i];\n }\n \n // Reverse the top half of the deck\n for (int i = 0; i < cutPoint / 2; i++) {\n String temp = topDeck[i];\n topDeck[i] = topDeck[topDeck.length - i - 1];\n topDeck[topDeck.length - i - 1] = temp;\n }\n \n // Combine the top and bottom halves to create the shuffled deck\n for (int i = 0; i < deck.length; i++) {\n if (i < cutPoint) {\n deck[i] = topDeck[i];\n } else {\n deck[i] = bottomDeck[i - cutPoint];\n }\n }\n}\n" }, { "answer_id": 74663529, "author": "Old Dog Programmer", "author_id": 5103317, "author_profile": "https://Stackoverflow.com/users/5103317", "pm_score": 0, "selected": false, "text": "Arrays List public static String[] cutDeck (String [] deck, int n) { \n List<String> cutDeck = new ArrayList<> (deck.length);\n List<String> bottom = Arrays.asList (Arrays.copyOfRange (deck,n, deck.length));\n cutDeck.addAll (bottom);\n List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n cutDeck.addAll (top);\n return cutDeck.toArray(deck);\n }\n deck String array = cutDeck (array, cutPoint);\n cutPoint cut cutDeck reverse Collections List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n Collections.reverse(top);\n cutDeck.addAll (top);\n cutDeck(array); array = cutDeck(array); cutPoint cutDeck Arrays toString System.out.println (Arrays.toString(array));\n public static String[] cut2 (String [] deck, final int n) {\n String [] cutDeck = new String [deck.length];\n for (int i = 0; i < cutDeck.length; ++i) {\n cutDeck [i] = deck [ (i + n) % deck.length];\n }\n return cutDeck;\n }\n public static void cards () {\n String [] deck = {\n \"two clubs\", \"three clubs\", \"four clubs\"\n , \"five clubs\", \"six clubs\", \"seven clubs\"\n , \"eight clubs\", \"nine clubs\", \"ten clubs\"\n , \"jack clubs\", \"queen clubs\", \"king clubs\"\n , \"ace clubs\"\n , \"two diamonds\", \"three diamonds\", \"four diamonds\"\n , \"five diamonds\", \"six diamonds\", \"seven diamonds\"\n , \"eight diamonds\", \"nine diamonds\", \"ten diamonds\"\n , \"jack diamonds\", \"queen diamonds\", \"king diamonds\"\n , \"ace diamonds\"\n , \"two hearts\", \"three hearts\", \"four hearts\"\n , \"five hearts\", \"six hearts\", \"seven hearts\"\n , \"eight hearts\", \"nine hearts\", \"ten hearts\"\n , \"jack hearts\", \"queen hearts\", \"king hearts\"\n , \"ace hearts\"\n ,\" two spades\", \"three spades\", \"four spades\"\n , \"five spades\", \"six spades\", \"seven spades\"\n , \"eight spades\", \"nine spades\", \"ten spades\"\n , \"jack spades\", \"queen spades\", \"king spades\"\n , \"ace spades\"\n }; \n \n System.out.println (\"Original: \" + Arrays.toString(deck));\n \n \n for (int i = 0; i < 10; ++i) {\n int r = (int) (Math.random () * deck.length);\n System.out.println ();\n System.out.println (r + \" \" + \n Arrays.toString (cut (Arrays.copyOf (deck, deck.length), r)));\n System.out.println (r + \" \" + \n Arrays.toString (cut2 (Arrays.copyOf (deck, deck.length), r))); \n } \n }\n cut cut2 Collections.reverse cut cut cut2 Original: [two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades]\n\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20307796/" ]
74,661,950
<p><strong>What am I trying to do</strong></p> <p>I have 3 tables which are being joined to create a desired output.</p> <p>Table 1 (800K records) : This is a partitioned hive external table by date (parquet file structure ). The schema is deeply nested. Following is a portion of the schema</p> <pre><code>root | - uuid | - data | - k1 - string | - k2 - string | - ... | …. | - dt - string (partition column) </code></pre> <p>Table 2 (0.5 million records) /Table 3 (31K records) : metadata tables</p> <pre><code>root | - insert_date | - k_sub | - action_date | …. </code></pre> <p>SQL being executed (Generated by a internal library)</p> <pre><code>SELECT input_file_name() as filename, uuid, data.k1, data.k2, dt FROM table_1 WHERE NOT EXISTS(SELECT 1 FROM table_2 WHERE (k_sub = data.k1) AND dt &gt; action_date) AND EXISTS( SELECT 1 FROM table_3 WHERE (k_sub = data.k1) AND (dt &lt; action_date OR dt &lt; DATE_ADD(CURRENT_DATE(), -1460)) </code></pre> <p>Spark settings</p> <pre><code>Num of executors = 50 Executor memory = 10g Driver memory = 10g </code></pre> <p>The query runs very slow runs for 1.1 hrs and fails. Looking into the sparkUI (SQL table).</p> <p>I increased the num of executors to 100 and the job completed but I'm not confident. The plan looks like this</p> <p><a href="https://i.stack.imgur.com/oOHcN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oOHcN.png" alt="enter image description here" /></a></p> <p>Based on my research, <code>BroadcastNestedLoopJoin</code> is not good to have. As it is SQL, I tried adding /* +BroadcastJoin */ hint but still did not help. Anyone has thoughts of how I could approach this problem and improve the performance?</p>
[ { "answer_id": 74662116, "author": "Hesham A", "author_id": 3403829, "author_profile": "https://Stackoverflow.com/users/3403829", "pm_score": 1, "selected": false, "text": "public static void cutDeck(String[] deck) {\n System.out.println(\"Cut please. 'Choose between 1-\" + (deck.length - 1) + \"'\");\n int cutPoint = scanner.nextInt();\n \n // Check that the cut point is within the valid range for the deck size\n if (cutPoint < 1 || cutPoint >= deck.length) {\n System.out.println(\"Invalid cut point. Please try again.\");\n return;\n }\n \n // Create the top and bottom halves of the deck\n String[] topDeck = new String[cutPoint];\n String[] bottomDeck = new String[deck.length - cutPoint];\n for (int i = 0; i < cutPoint; i++) {\n topDeck[i] = deck[i];\n }\n for (int i = cutPoint; i < deck.length; i++) {\n bottomDeck[i - cutPoint] = deck[i];\n }\n \n // Reverse the top half of the deck\n for (int i = 0; i < cutPoint / 2; i++) {\n String temp = topDeck[i];\n topDeck[i] = topDeck[topDeck.length - i - 1];\n topDeck[topDeck.length - i - 1] = temp;\n }\n \n // Combine the top and bottom halves to create the shuffled deck\n for (int i = 0; i < deck.length; i++) {\n if (i < cutPoint) {\n deck[i] = topDeck[i];\n } else {\n deck[i] = bottomDeck[i - cutPoint];\n }\n }\n}\n" }, { "answer_id": 74663529, "author": "Old Dog Programmer", "author_id": 5103317, "author_profile": "https://Stackoverflow.com/users/5103317", "pm_score": 0, "selected": false, "text": "Arrays List public static String[] cutDeck (String [] deck, int n) { \n List<String> cutDeck = new ArrayList<> (deck.length);\n List<String> bottom = Arrays.asList (Arrays.copyOfRange (deck,n, deck.length));\n cutDeck.addAll (bottom);\n List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n cutDeck.addAll (top);\n return cutDeck.toArray(deck);\n }\n deck String array = cutDeck (array, cutPoint);\n cutPoint cut cutDeck reverse Collections List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n Collections.reverse(top);\n cutDeck.addAll (top);\n cutDeck(array); array = cutDeck(array); cutPoint cutDeck Arrays toString System.out.println (Arrays.toString(array));\n public static String[] cut2 (String [] deck, final int n) {\n String [] cutDeck = new String [deck.length];\n for (int i = 0; i < cutDeck.length; ++i) {\n cutDeck [i] = deck [ (i + n) % deck.length];\n }\n return cutDeck;\n }\n public static void cards () {\n String [] deck = {\n \"two clubs\", \"three clubs\", \"four clubs\"\n , \"five clubs\", \"six clubs\", \"seven clubs\"\n , \"eight clubs\", \"nine clubs\", \"ten clubs\"\n , \"jack clubs\", \"queen clubs\", \"king clubs\"\n , \"ace clubs\"\n , \"two diamonds\", \"three diamonds\", \"four diamonds\"\n , \"five diamonds\", \"six diamonds\", \"seven diamonds\"\n , \"eight diamonds\", \"nine diamonds\", \"ten diamonds\"\n , \"jack diamonds\", \"queen diamonds\", \"king diamonds\"\n , \"ace diamonds\"\n , \"two hearts\", \"three hearts\", \"four hearts\"\n , \"five hearts\", \"six hearts\", \"seven hearts\"\n , \"eight hearts\", \"nine hearts\", \"ten hearts\"\n , \"jack hearts\", \"queen hearts\", \"king hearts\"\n , \"ace hearts\"\n ,\" two spades\", \"three spades\", \"four spades\"\n , \"five spades\", \"six spades\", \"seven spades\"\n , \"eight spades\", \"nine spades\", \"ten spades\"\n , \"jack spades\", \"queen spades\", \"king spades\"\n , \"ace spades\"\n }; \n \n System.out.println (\"Original: \" + Arrays.toString(deck));\n \n \n for (int i = 0; i < 10; ++i) {\n int r = (int) (Math.random () * deck.length);\n System.out.println ();\n System.out.println (r + \" \" + \n Arrays.toString (cut (Arrays.copyOf (deck, deck.length), r)));\n System.out.println (r + \" \" + \n Arrays.toString (cut2 (Arrays.copyOf (deck, deck.length), r))); \n } \n }\n cut cut2 Collections.reverse cut cut cut2 Original: [two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades]\n\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2379259/" ]
74,661,960
<p>I get error when my column is empty.</p> <pre><code>double tot_main, tot_oper, gift, sum_tot, sum_tot_gift, amount_gift_new, amount_cut; // sum MainOper SqlCommand check_main = new SqlCommand(&quot;select Sum(amount_Gift) from MainOper where Emp_no='&quot; + TextBox1.Text + &quot;' &quot;, con); SqlDataAdapter sd1 = new SqlDataAdapter(check_main); DataTable dt1 = new DataTable(); sd1.Fill(dt1); // sum Oper SqlCommand check_Oper = new SqlCommand(&quot;select Sum(amount_Gift) from Oper where Emp_no='&quot; + TextBox1.Text + &quot;' &quot;, con); SqlDataAdapter sd2 = new SqlDataAdapter(check_Oper); DataTable dt2 = new DataTable(); sd2.Fill(dt2); // variable gift = double.Parse(TextBox8.Text); tot_main = double.Parse(dt1.Rows[0][0].ToString()); // note:when empty or 0 cat get sum_tot tot_oper = double.Parse(dt2.Rows[0][0].ToString()); // note:when empty or 0 cant get sum_tot // variable sum_tot = tot_oper + tot_main; //when have value in tot_main &amp; tot_oper is done - need every table have number sum_tot_gift = sum_tot + gift; amount_gift_new = sum_tot_gift - 1000; amount_cut = gift - amount_gift_new; </code></pre> <pre><code>else if (amount_cut &lt;= 1000) { SqlCommand co = new SqlCommand(&quot;exec gifter '&quot; + Emp_no2 + &quot;','&quot; + Emp_name2 + &quot;','&quot; + Emp_dept2 + &quot;','&quot; + Emp_poss2 + &quot;', '&quot; + Ref_Gift2 + &quot;','&quot; + Run_Gift2 + &quot;','&quot; + Date_Gift2 + &quot;','&quot; + amount_cut + &quot;', '&quot; + Type_Gift2 + &quot;','&quot; + Month_num2 + &quot;'&quot;, con); co.ExecuteNonQuery(); con.Close(); Label13.Text = &quot;successfuly&quot;; GetProductionList(); } </code></pre>
[ { "answer_id": 74662116, "author": "Hesham A", "author_id": 3403829, "author_profile": "https://Stackoverflow.com/users/3403829", "pm_score": 1, "selected": false, "text": "public static void cutDeck(String[] deck) {\n System.out.println(\"Cut please. 'Choose between 1-\" + (deck.length - 1) + \"'\");\n int cutPoint = scanner.nextInt();\n \n // Check that the cut point is within the valid range for the deck size\n if (cutPoint < 1 || cutPoint >= deck.length) {\n System.out.println(\"Invalid cut point. Please try again.\");\n return;\n }\n \n // Create the top and bottom halves of the deck\n String[] topDeck = new String[cutPoint];\n String[] bottomDeck = new String[deck.length - cutPoint];\n for (int i = 0; i < cutPoint; i++) {\n topDeck[i] = deck[i];\n }\n for (int i = cutPoint; i < deck.length; i++) {\n bottomDeck[i - cutPoint] = deck[i];\n }\n \n // Reverse the top half of the deck\n for (int i = 0; i < cutPoint / 2; i++) {\n String temp = topDeck[i];\n topDeck[i] = topDeck[topDeck.length - i - 1];\n topDeck[topDeck.length - i - 1] = temp;\n }\n \n // Combine the top and bottom halves to create the shuffled deck\n for (int i = 0; i < deck.length; i++) {\n if (i < cutPoint) {\n deck[i] = topDeck[i];\n } else {\n deck[i] = bottomDeck[i - cutPoint];\n }\n }\n}\n" }, { "answer_id": 74663529, "author": "Old Dog Programmer", "author_id": 5103317, "author_profile": "https://Stackoverflow.com/users/5103317", "pm_score": 0, "selected": false, "text": "Arrays List public static String[] cutDeck (String [] deck, int n) { \n List<String> cutDeck = new ArrayList<> (deck.length);\n List<String> bottom = Arrays.asList (Arrays.copyOfRange (deck,n, deck.length));\n cutDeck.addAll (bottom);\n List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n cutDeck.addAll (top);\n return cutDeck.toArray(deck);\n }\n deck String array = cutDeck (array, cutPoint);\n cutPoint cut cutDeck reverse Collections List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n Collections.reverse(top);\n cutDeck.addAll (top);\n cutDeck(array); array = cutDeck(array); cutPoint cutDeck Arrays toString System.out.println (Arrays.toString(array));\n public static String[] cut2 (String [] deck, final int n) {\n String [] cutDeck = new String [deck.length];\n for (int i = 0; i < cutDeck.length; ++i) {\n cutDeck [i] = deck [ (i + n) % deck.length];\n }\n return cutDeck;\n }\n public static void cards () {\n String [] deck = {\n \"two clubs\", \"three clubs\", \"four clubs\"\n , \"five clubs\", \"six clubs\", \"seven clubs\"\n , \"eight clubs\", \"nine clubs\", \"ten clubs\"\n , \"jack clubs\", \"queen clubs\", \"king clubs\"\n , \"ace clubs\"\n , \"two diamonds\", \"three diamonds\", \"four diamonds\"\n , \"five diamonds\", \"six diamonds\", \"seven diamonds\"\n , \"eight diamonds\", \"nine diamonds\", \"ten diamonds\"\n , \"jack diamonds\", \"queen diamonds\", \"king diamonds\"\n , \"ace diamonds\"\n , \"two hearts\", \"three hearts\", \"four hearts\"\n , \"five hearts\", \"six hearts\", \"seven hearts\"\n , \"eight hearts\", \"nine hearts\", \"ten hearts\"\n , \"jack hearts\", \"queen hearts\", \"king hearts\"\n , \"ace hearts\"\n ,\" two spades\", \"three spades\", \"four spades\"\n , \"five spades\", \"six spades\", \"seven spades\"\n , \"eight spades\", \"nine spades\", \"ten spades\"\n , \"jack spades\", \"queen spades\", \"king spades\"\n , \"ace spades\"\n }; \n \n System.out.println (\"Original: \" + Arrays.toString(deck));\n \n \n for (int i = 0; i < 10; ++i) {\n int r = (int) (Math.random () * deck.length);\n System.out.println ();\n System.out.println (r + \" \" + \n Arrays.toString (cut (Arrays.copyOf (deck, deck.length), r)));\n System.out.println (r + \" \" + \n Arrays.toString (cut2 (Arrays.copyOf (deck, deck.length), r))); \n } \n }\n cut cut2 Collections.reverse cut cut cut2 Original: [two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades]\n\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670339/" ]
74,661,967
<p>My full code -- <a href="https://codepen.io/featherPiano/pen/ZERqBYK?editors=1010" rel="nofollow noreferrer">Random Quote Generator Project in Codepen</a></p> <p>I used Bootstrap5 <a href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="nofollow noreferrer">https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css</a>.</p> <p>The button style <code>btn-info</code> is not styling correctly. I know that I can manually change it, but I just want to understand why it is happening.</p> <p>On the Bootstrap Demo Button for button style <code>btn-info</code> is blue and white..</p> <p><a href="https://i.stack.imgur.com/I2c7e.png" rel="nofollow noreferrer">Picture of info button default style</a></p> <p>However, when I added it to my code it, the style is appearing this way ...</p> <p><a href="https://i.stack.imgur.com/oX9XI.png" rel="nofollow noreferrer">In my project the button is styled a different shade of blue and has black text</a></p> <p><a href="https://i.stack.imgur.com/fqPQU.png" rel="nofollow noreferrer">The primary style is showing correctly as seen here when I change my code</a></p> <p>I checked the DOM and the css also shows the color to appear this way. <a href="https://i.stack.imgur.com/qB57Z.png" rel="nofollow noreferrer">Screenshot from the inspect developer tool</a></p> <p>Thank you for reading and I would really appreciate it if you could help. P.S. How do I make it so that my pictures appear instead of links to click. I pasted them in so if there is another way please advise. Again, thank you.</p> <p>I checked over my code and made sure nothing was overriding the styles. There is nothing that I noticed. It is a very small project.</p> <p>I also tested the other default button styles, and they appeared as shown on the bootstrap documentation page.</p> <p>I tested my code in the Chrome Browser and it also is appearing this way.</p>
[ { "answer_id": 74662116, "author": "Hesham A", "author_id": 3403829, "author_profile": "https://Stackoverflow.com/users/3403829", "pm_score": 1, "selected": false, "text": "public static void cutDeck(String[] deck) {\n System.out.println(\"Cut please. 'Choose between 1-\" + (deck.length - 1) + \"'\");\n int cutPoint = scanner.nextInt();\n \n // Check that the cut point is within the valid range for the deck size\n if (cutPoint < 1 || cutPoint >= deck.length) {\n System.out.println(\"Invalid cut point. Please try again.\");\n return;\n }\n \n // Create the top and bottom halves of the deck\n String[] topDeck = new String[cutPoint];\n String[] bottomDeck = new String[deck.length - cutPoint];\n for (int i = 0; i < cutPoint; i++) {\n topDeck[i] = deck[i];\n }\n for (int i = cutPoint; i < deck.length; i++) {\n bottomDeck[i - cutPoint] = deck[i];\n }\n \n // Reverse the top half of the deck\n for (int i = 0; i < cutPoint / 2; i++) {\n String temp = topDeck[i];\n topDeck[i] = topDeck[topDeck.length - i - 1];\n topDeck[topDeck.length - i - 1] = temp;\n }\n \n // Combine the top and bottom halves to create the shuffled deck\n for (int i = 0; i < deck.length; i++) {\n if (i < cutPoint) {\n deck[i] = topDeck[i];\n } else {\n deck[i] = bottomDeck[i - cutPoint];\n }\n }\n}\n" }, { "answer_id": 74663529, "author": "Old Dog Programmer", "author_id": 5103317, "author_profile": "https://Stackoverflow.com/users/5103317", "pm_score": 0, "selected": false, "text": "Arrays List public static String[] cutDeck (String [] deck, int n) { \n List<String> cutDeck = new ArrayList<> (deck.length);\n List<String> bottom = Arrays.asList (Arrays.copyOfRange (deck,n, deck.length));\n cutDeck.addAll (bottom);\n List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n cutDeck.addAll (top);\n return cutDeck.toArray(deck);\n }\n deck String array = cutDeck (array, cutPoint);\n cutPoint cut cutDeck reverse Collections List<String> top = Arrays.asList (Arrays.copyOfRange (deck, 0, n));\n Collections.reverse(top);\n cutDeck.addAll (top);\n cutDeck(array); array = cutDeck(array); cutPoint cutDeck Arrays toString System.out.println (Arrays.toString(array));\n public static String[] cut2 (String [] deck, final int n) {\n String [] cutDeck = new String [deck.length];\n for (int i = 0; i < cutDeck.length; ++i) {\n cutDeck [i] = deck [ (i + n) % deck.length];\n }\n return cutDeck;\n }\n public static void cards () {\n String [] deck = {\n \"two clubs\", \"three clubs\", \"four clubs\"\n , \"five clubs\", \"six clubs\", \"seven clubs\"\n , \"eight clubs\", \"nine clubs\", \"ten clubs\"\n , \"jack clubs\", \"queen clubs\", \"king clubs\"\n , \"ace clubs\"\n , \"two diamonds\", \"three diamonds\", \"four diamonds\"\n , \"five diamonds\", \"six diamonds\", \"seven diamonds\"\n , \"eight diamonds\", \"nine diamonds\", \"ten diamonds\"\n , \"jack diamonds\", \"queen diamonds\", \"king diamonds\"\n , \"ace diamonds\"\n , \"two hearts\", \"three hearts\", \"four hearts\"\n , \"five hearts\", \"six hearts\", \"seven hearts\"\n , \"eight hearts\", \"nine hearts\", \"ten hearts\"\n , \"jack hearts\", \"queen hearts\", \"king hearts\"\n , \"ace hearts\"\n ,\" two spades\", \"three spades\", \"four spades\"\n , \"five spades\", \"six spades\", \"seven spades\"\n , \"eight spades\", \"nine spades\", \"ten spades\"\n , \"jack spades\", \"queen spades\", \"king spades\"\n , \"ace spades\"\n }; \n \n System.out.println (\"Original: \" + Arrays.toString(deck));\n \n \n for (int i = 0; i < 10; ++i) {\n int r = (int) (Math.random () * deck.length);\n System.out.println ();\n System.out.println (r + \" \" + \n Arrays.toString (cut (Arrays.copyOf (deck, deck.length), r)));\n System.out.println (r + \" \" + \n Arrays.toString (cut2 (Arrays.copyOf (deck, deck.length), r))); \n } \n }\n cut cut2 Collections.reverse cut cut cut2 Original: [two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades]\n\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n7 [nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs]\n\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n46 [nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs, queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades]\n\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n10 [queen clubs, king clubs, ace clubs, two diamonds, three diamonds, four diamonds, five diamonds, six diamonds, seven diamonds, eight diamonds, nine diamonds, ten diamonds, jack diamonds, queen diamonds, king diamonds, ace diamonds, two hearts, three hearts, four hearts, five hearts, six hearts, seven hearts, eight hearts, nine hearts, ten hearts, jack hearts, queen hearts, king hearts, ace hearts, two spades, three spades, four spades, five spades, six spades, seven spades, eight spades, nine spades, ten spades, jack spades, queen spades, king spades, ace spades, two clubs, three clubs, four clubs, five clubs, six clubs, seven clubs, eight clubs, nine clubs, ten clubs, jack clubs]\n\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670008/" ]
74,661,977
<p>On my midterm there was a question that I believe has two correct answers, A and B. The question states:</p> <blockquote> <p>Which of the following sets of operators is composed only of comparative operators?<br /> A) &gt;, &lt;, &gt;=, &lt;=<br /> B) ==, !=<br /> C) &amp;&amp;, ||, !<br /> D) None of the above.</p> </blockquote> <p>Page 235 of my textbook (Computer Science: A Structured Programming Approach Using C by Forouzan and Gilberg) states,</p> <blockquote> <p>C provides six comparative operators. … The operators are shown in Figure 5-4.</p> </blockquote> <p>Figure 5-4 shows the operators &lt;, &lt;=, &gt;, &gt;=, ==, and !=. I emailed this to my lecturer and she responded with:</p> <blockquote> <p>I understand the point you made in your submitted paper, but the best course of action is to stick to CS159 notes packet rather than Forouzan's textbook, as the textbook is considered a supplemental resource for this course.</p> </blockquote> <p>Page 119 of my notes packet (Purdue University's CS159 notes packet) says that comparative operators are == and !=. So does comparative operator have two definitions? Even in that case the question would have two correct answers.</p>
[ { "answer_id": 74662156, "author": "chux - Reinstate Monica", "author_id": 2410359, "author_profile": "https://Stackoverflow.com/users/2410359", "pm_score": 2, "selected": false, "text": "< > <= >= == !=" }, { "answer_id": 74662157, "author": "Andreas Wenzel", "author_id": 12149471, "author_profile": "https://Stackoverflow.com/users/12149471", "pm_score": 2, "selected": false, "text": "< > <= >= == !=" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20669522/" ]
74,661,985
<p>I want to generate a dataframe with pandas where one of the columns is filled with all mondays between to dates. But I need to exclude some mondays that are in a specific list. I could generate the column with the mondays, but I could find how to remove that mondays in the given list.</p> <p>I generate the mondays using:</p> <p>import pandas as pd</p> <p>st=pd.to_datetime('8/22/2022') ed=pd.to_datetime('12/22/2022')</p> <p>a1=pd.date_range(start=st,end=ed, freq='W-MON')</p> <p>But I would like to exclude the mondays that are in this list</p> <p>fer=pd.to_datetime(['09/07/2022','10/12/2022','10/15/2022','10/28/2022','11/01/2022','11/14/2022','11/15/2022','11/20/2022'])</p> <p>I was not able to find the solution online.</p>
[ { "answer_id": 74662156, "author": "chux - Reinstate Monica", "author_id": 2410359, "author_profile": "https://Stackoverflow.com/users/2410359", "pm_score": 2, "selected": false, "text": "< > <= >= == !=" }, { "answer_id": 74662157, "author": "Andreas Wenzel", "author_id": 12149471, "author_profile": "https://Stackoverflow.com/users/12149471", "pm_score": 2, "selected": false, "text": "< > <= >= == !=" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74661985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670315/" ]
74,662,002
<pre><code>query(meetingsCollection, where(&quot;start&quot;, &quot;in&quot;, today), orderBy(&quot;start&quot;, &quot;asc&quot;) </code></pre> <p>I'd like a Firestore query, so that I can fetch all documents between 02/12/2022 - 00:00:00.000 &amp;&amp; 03/12/2022 00:00:00.000, ordered by the Date property start, so that I can bucketsize my firestore data request and limit overreads, then use said documents to visually filter accordingly via the front-end.</p> <p>Can you assist me with this?</p>
[ { "answer_id": 74662065, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 1, "selected": false, "text": "const start = new Date();\nstart.setUTCHours(0,0,0,0);\n\nconst end = new Date();\nend.setUTCHours(23,59,59,999);\n query(\n meetingsCollection,\n where(\"start\", \">=\", start),\n where(\"start\", \"<=\", end)\n orderBy(\"start\", \"asc\")\n)\n" }, { "answer_id": 74662141, "author": "erimsengezer", "author_id": 8258928, "author_profile": "https://Stackoverflow.com/users/8258928", "pm_score": 1, "selected": false, "text": " db.collection(\"collection_name\")\n .where(\"start\", \">=\", \"02/12/2022 00:00:00.000\")\n .where(\"start\", \"<=\", \"03/12/2022 00:00:00.000\")\n .orderBy(\"start\")\n .get()\n .then((querySnapshot) => {\n querySnapshot.forEach((doc) => {\n // doc.data() contains the data for the document\n });\n });\n" }, { "answer_id": 74671515, "author": "David Griffin", "author_id": 16479677, "author_profile": "https://Stackoverflow.com/users/16479677", "pm_score": 0, "selected": false, "text": "const now = new Date();\n\nconst getDateFormatted = (date) => {\n const year = date.getFullYear();\n const month = date.getMonth() + 1;\n const day = date.getDate().toString().padStart(2, \"0\");\n return `${year}-${month}-${day}`;\n} \n\nconst startNow = new Date(`${getDateFormatted(now)}T00:00:00.000z`); //2021-09-01T00:00:00.000Z\nconst endNow = new Date(`${getDateFormatted(now)}T23:59:59.000z`);\n\nconst nowEvents = ref([]);\n\nconst getNowEvents = async () => {\n onSnapshot(myEvents(startNow, endNow), (querySnapshot) => {\n let tmpEvents = [];\n querySnapshot.forEach((doc) => {\n let event = {\n id: doc.id,\n ...doc.data(),\n };\n tmpEvents.push(event);\n });\n nowEvents.value = tmpEvents;\n });\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16479677/" ]
74,662,076
<p>I have a client server that has limited rights (no internet or many install priveleges), but it contains a version of TFS. Is there any way possible to get the data and history to bring down to my local computer to put into GIt?</p> <p>I have tried Git-TFS but cannot get it installed on the server and tried running the source code.</p> <p>Any ideas besides me downloaded the code for each branch and then adding them in branch by branch and ignoring the previous commits of each branch?</p>
[ { "answer_id": 74664696, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 0, "selected": false, "text": "git bundle" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/665557/" ]
74,662,078
<p>At the moment I'm hacking away at swift to learn the language and I'm coming at it from a java/C++ perspective. I'm trying to make an app for a game I play called World War II Online. However I can't get my head around why I'm getting a binding error when trying to code in the toggle for remembering a password. Below is my code for the landing page for my app.</p> <pre><code>struct ContentView: View { @State private var empty_field = &quot;&quot; @State private var passwordState = false let userfieldTitle : String = &quot;username&quot; let passwordFieldTitle : String = &quot;password&quot; let landingPageTitle = &quot;World War II Online&quot; let toggleName = &quot;remember password&quot; var body: some View { Text(landingPageTitle).font(.largeTitle) Section { Form{ VStack { TextField(userfieldTitle,text : $empty_field) TextField(passwordFieldTitle,text : $empty_field) Toggle(toggleName, isOn: $passwordState){ print(&quot;hello world&quot;) } } .padding() } } } </code></pre> <p>I'm getting the error:</p> <p><strong>Cannot convert value of type 'Binding' to expected argument type 'KeyPath&lt;(() -&gt; ()).Element, Binding&gt;'</strong></p> <p>I'm really bad in understanding bindings and properties. Is there something I've been code blind to ?</p>
[ { "answer_id": 74662207, "author": "Jessy", "author_id": 652038, "author_profile": "https://Stackoverflow.com/users/652038", "pm_score": 1, "selected": false, "text": "public extension View {\n /// Execute imperative code.\n func callAsFunction(_ execute: () -> Void) -> Self {\n execute()\n return self\n }\n}\n" }, { "answer_id": 74663345, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 0, "selected": false, "text": "body print Toggle $passwordState Form {\n VStack {\n TextField(userfieldTitle,text : $empty_field)\n TextField(passwordFieldTitle,text : $empty_field) \n Toggle(toggleName, isOn: $passwordState)\n if passwordState {\n Text(\"hello world\")\n }\n }\n .padding()\n}\n if <IF> if" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1056576/" ]
74,662,147
<p>So by far whenever I had a dataframe that has a column of list such as the following:</p> <pre><code>'category_id' [030000, 010403, 010402, 030604, 234440] [030000, 010405, 010402, 030604, 033450] [030000, 010403, 010407, 030604, 030600] [030000, 010403, 010402, 030609, 032600] </code></pre> <p>Usually whenever I want to make this category_id column become like:</p> <pre><code>'category_id' 030000 010403 010402 030604 234440 030000 010405 010402 030604 033450 </code></pre> <p>I would usually use the following code:</p> <pre><code>df2 = df.explode('category_id') </code></pre> <p>But whenever my data size gets really big, likes the sales data over the course of an entire month, .explode() becomes extremely slow and I am always worried whether I would encounter any OOM issues related to memory leaks.</p> <p>Is there any other alternative solutions to .explode that would somehow perform better? I tried to to use flatMap() but I'm stuck on how to exactly turn a dataframe to rdd format and then change it back to dataframe format that I can utilize.</p> <p>Any info would be appreciated.</p>
[ { "answer_id": 74662207, "author": "Jessy", "author_id": 652038, "author_profile": "https://Stackoverflow.com/users/652038", "pm_score": 1, "selected": false, "text": "public extension View {\n /// Execute imperative code.\n func callAsFunction(_ execute: () -> Void) -> Self {\n execute()\n return self\n }\n}\n" }, { "answer_id": 74663345, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 0, "selected": false, "text": "body print Toggle $passwordState Form {\n VStack {\n TextField(userfieldTitle,text : $empty_field)\n TextField(passwordFieldTitle,text : $empty_field) \n Toggle(toggleName, isOn: $passwordState)\n if passwordState {\n Text(\"hello world\")\n }\n }\n .padding()\n}\n if <IF> if" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14615988/" ]
74,662,150
<p>I was curious about how I can implement the Fibonacci sequence for summing the last n elements instead of just the last 2. So I was thinking about implementing a function <code>nBonacci(n,m)</code> where n is the number of last elements we gotta sum, and m is the number of elements in this list.</p> <p>The Fibonacci sequence starts with 2 ones, and each following element is the sum of the 2 previous numbers.</p> <p>Let's make a generalization: The nBonacci sequence starts with n ones, and each following element is the sum of the previous n numbers.</p> <p>I want to define the nBonacci function that takes the positive integer n and a positive integer m, with m&gt;n, and returns a list with the first m elements of the nBonacci sequence corresponding to the value n.</p> <p>For example, <code>nBonacci(3,8)</code> should return the list [1, 1, 1, 3, 5, 9, 17, 31].</p> <pre><code>def fib(num): a = 0 b = 1 while b &lt;= num: prev_a = a a = b b = prev_a +b </code></pre> <p>The problem is that I don't know the number of times I gotta sum. Does anyone have an idea and a suggestion of resolution?</p>
[ { "answer_id": 74662207, "author": "Jessy", "author_id": 652038, "author_profile": "https://Stackoverflow.com/users/652038", "pm_score": 1, "selected": false, "text": "public extension View {\n /// Execute imperative code.\n func callAsFunction(_ execute: () -> Void) -> Self {\n execute()\n return self\n }\n}\n" }, { "answer_id": 74663345, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 0, "selected": false, "text": "body print Toggle $passwordState Form {\n VStack {\n TextField(userfieldTitle,text : $empty_field)\n TextField(passwordFieldTitle,text : $empty_field) \n Toggle(toggleName, isOn: $passwordState)\n if passwordState {\n Text(\"hello world\")\n }\n }\n .padding()\n}\n if <IF> if" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20371954/" ]
74,662,177
<p>when the first date is bigger than the second, it doesent calculate. for example: first date 22/10/2022 second date: 15/10/2022</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; using namespace std; class Date { public: Date(int d, int m, int y); void set_date(int d, int m, int y); void print_date(); void inc_one_day(); bool equals(Date d); int get_day() { return day; } int get_month() { return month; } int get_year() { return year; } private : int day; int month; int year; }; bool is_leap_year(int year) { int r = year % 33; return r == 1 || r == 5 || r == 9 || r == 13 || r == 17 || r == 22 || r == 26 || r == 30; } int days_of_month(int m, int y){ if (m &lt; 7) return 31; else if (m &lt; 12) return 30; else if (m == 12) return is_leap_year(y) ? 30 : 29; else abort(); } void Date::inc_one_day(){ day++; if (day &gt; days_of_month(month, year)) { day = 1; month++; if (month &gt; 12) { month = 1; year++; } } } bool Date::equals(Date d) { return day == d.day &amp;&amp; month == d.month &amp;&amp; year == d.year; } int days_between(Date d1, Date d2){ int count = 1; while (!d1.equals(d2)){ d1.inc_one_day(); count++; } return count; } Date::Date(int d, int m, int y){ cout &lt;&lt; &quot;constructor called \n&quot;; set_date(d, m, y); } void Date::set_date(int d, int m, int y){ if (y &lt; 0 || m &lt; 1 || m&gt;12 || d &lt; 1 || d &gt; days_of_month(m, y)) abort(); day = d; month = m; year = y; } void Date::print_date(){ cout &lt;&lt; day &lt;&lt; '/' &lt;&lt; month &lt;&lt; '/' &lt;&lt; year&lt;&lt;endl; } int main(){ Date bd(22, 12, 1395); Date be(15, 12, 1395); cout &lt;&lt; '\n'; int i; i= days_between(bd, be); cout &lt;&lt; i &lt;&lt; endl; } </code></pre> <p>here's my code. I've seen many codes that calculate the days between two dates, but they didn't use class Date. how can i solve this problem? could you guys help me please.I'm sorry i'm new in c++ so, my problem might be so basic.</p>
[ { "answer_id": 74667160, "author": "Clifford", "author_id": 168986, "author_profile": "https://Stackoverflow.com/users/168986", "pm_score": 1, "selected": false, "text": "int days_between(Date d1, Date d2)\n{\n int count = 0 ;\n \n // Initially assume d2 >= d1\n Date* earlier = &d1 ;\n Date* later = &d2 ;\n \n // Test if d1 > d2...\n int year_diff = d2.get_year() - d1.get_year() ;\n int mon_diff = d2.get_month() - d1.get_month() ;\n int day_diff = d2.get_day() - d1.get_day() ;\n if( year_diff < 0 ||\n (year_diff == 0 && (mon_diff < 0 || (mon_diff == 0 &&\n day_diff < 0 ))))\n {\n // d1 > d2, so swap\n earlier = &d2 ;\n later = &d1 ;\n }\n \n while (!earlier->equals(*later))\n {\n earlier->inc_one_day();\n count++;\n }\n \n return count;\n}\n return earlier == &d2 ? -count : count ;\n if( d1 > d2 )\n{\n earlier = &d2 ;\n later = &d1 ;\n}\n\nwhile( *earlier != *later))\n{\n earlier++ ;\n count++ ;\n}\n\nreturn earlier == &d2 ? -count : count ;\n i = be - bd;\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19452796/" ]
74,662,228
<p>It is necessary for me at a choice chekboksom that the Page2 component was drawn. I created a <code>useState</code> where I keep track of the value of the checkbox, but I don't know how to navigate programmatically when the checkbox is selected. How can I do this?</p> <pre><code>export default function Home() { const [checked, setChecked] = useState(false); const navigate = useNavigate(); const handleChange = () =&gt; { setChecked(!checked); }; return ( &lt;&gt; &lt;input type=&quot;checkbox&quot; onChange={handleChange}&gt;&lt;/input&gt; &lt;/&gt; ); } </code></pre>
[ { "answer_id": 74662273, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 3, "selected": true, "text": "const handleChange = () => {\n setChecked(!checked);\n if (!checked) {\n navigate('/')\n }\n};\n" }, { "answer_id": 74662412, "author": "Drew Reese", "author_id": 8690857, "author_profile": "https://Stackoverflow.com/users/8690857", "pm_score": 0, "selected": false, "text": "onChange export default function Home() {\n const navigate = useNavigate();\n\n const handleChange = (e) => {\n const { checked } = e.target;\n if (checked) {\n navigate(\"targetPath\");\n }\n };\n\n return (\n <>\n <input type=\"checkbox\" onChange={handleChange}></input>\n </>\n );\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20592580/" ]
74,662,229
<pre><code> x1 = ['a','1','2','b','4'] x2 = ['a','a','2','b','4'] x3 = ['a','a','a','b','4'] x4 = ['a','1','2','b','4'] xxxx = x1,x2,x3,x4 name2f = [] for i in xxxx: a1 = i[0] b1 = i[1] c1 = i[2] if a1.isalpha: if b1.isalpha: if c1.isalpha: print(&quot;false 3&quot;) p = i[0]+&quot; &quot;+i[1]+&quot; &quot;+i[2] i.remove(a1) i.remove(b1) i.remove(c1) name2f.append(p) elif a1.isalpha: if b1.isalpha: p = i[0]+&quot; &quot;+i[1] i.remove(a1) i.remove(b1) name2f.append(p) elif a1.isalpha: name2f.append(a1) i.remove(a1) print(&quot;false 1&quot;) else: print(&quot;broken&quot;) </code></pre> <p>isalpha and isdigit route does not seem to work nor does regex, not sure what is up. My results are print3 down the line. Not sure where the issue lies.</p>
[ { "answer_id": 74662514, "author": "OneCricketeer", "author_id": 2308683, "author_profile": "https://Stackoverflow.com/users/2308683", "pm_score": 0, "selected": false, "text": "isalpha() isalpha name2f = ['a', 'aa', 'aaa', 'a'] b all_chars = [x for x in lst if not x.isdigit()]\n def collect_chars(lst):\n combined = lst[:1]\n result = []\n for val in lst[1:]:\n if val != combined[-1]:\n # current char not last seen char, dump the collected values so far\n result.append(''.join(combined))\n # and start a new string\n combined = [val]\n else:\n # keep adding matching strings\n combined.append(val)\n # if reached end of string, dump what has been collected so far\n result.append(''.join(combined))\n del combined\n\n return result\n for i in xxxx:\n all_chars = [x for x in i if not x.isdigit()]\n lst = collect_chars(all_chars)\n print(lst)\n ['a', 'b']\n['aa', 'b']\n['aaa', 'b']\n['a', 'b']\n" }, { "answer_id": 74663057, "author": "Menor", "author_id": 20499621, "author_profile": "https://Stackoverflow.com/users/20499621", "pm_score": 1, "selected": false, "text": " item = []\n for items in xxxx:\n for i in items[0:3]:\n if re.match(r'[A-Z]', i) and bool(re.search(r'[0-9]', i)) == False:\n item.append(i)\n items.remove(i)\n\n w = \" \".join(item)\n print(w)\n print(\"\")\n print(items)\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20499621/" ]
74,662,260
<div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Date</th> </tr> </thead> <tbody> <tr> <td>A</td> <td>1990-10-7</td> </tr> <tr> <td>B</td> <td>1997-11-20</td> </tr> </tbody> </table> </div> <p>and i want to add column age the convert the date to the age</p> <p>i try this</p> <pre><code>data$age &lt;- age_calc(as.Date(data$dob, &quot;%Y/%m/%d&quot;), units = &quot;years&quot;) </code></pre> <p>but i got this error</p> <pre><code>Error in if (any(enddate &lt; dob)) { : missing value where TRUE/FALSE needed </code></pre>
[ { "answer_id": 74662294, "author": "Paulo M Serodio", "author_id": 20670538, "author_profile": "https://Stackoverflow.com/users/20670538", "pm_score": -1, "selected": false, "text": "data$age <- age_calc(as.Date(data$dob, \"%Y/%m/%d\"), \n as.Date(Sys.Date()), units = \"years\")\n" }, { "answer_id": 74662305, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": true, "text": "as.Date > df$age <- age_calc(as.Date(df$Date, \"%Y-%m-%d\"), units = \"years\")\n> df\n Name Date age\n1 A 1990-10-7 32.15342\n2 B 1997-11-20 25.03288\n Date - / - as.Date" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18692944/" ]
74,662,270
<p>I am learning JS prototype, and I got the following code, all is clear except the output of <code>console.log(myObj.name)</code>. How come it gives the name of the object itself, which is <code>myObj</code>? Doesn't it need to find the prototype from its upper-level object?</p> <pre><code>const myObj = function () {} myObj.prototype.name = 'prototype.name' myObj1 = new myObj() console.log(myObj.name) // =&gt; myObj console.log(myObj1.name) // =&gt; 'prototype.name' console.log(myObj.prototype.name) // =&gt; prototype.name </code></pre> <p>I was expecting the same output as <code>myObj1</code> and their prototype.</p>
[ { "answer_id": 74662294, "author": "Paulo M Serodio", "author_id": 20670538, "author_profile": "https://Stackoverflow.com/users/20670538", "pm_score": -1, "selected": false, "text": "data$age <- age_calc(as.Date(data$dob, \"%Y/%m/%d\"), \n as.Date(Sys.Date()), units = \"years\")\n" }, { "answer_id": 74662305, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": true, "text": "as.Date > df$age <- age_calc(as.Date(df$Date, \"%Y-%m-%d\"), units = \"years\")\n> df\n Name Date age\n1 A 1990-10-7 32.15342\n2 B 1997-11-20 25.03288\n Date - / - as.Date" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20441652/" ]
74,662,274
<p>Here is my list of dicts:</p> <pre><code>[{'subtopic': 'IAM', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_iam_policies_info&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': 'Sure! I can help with AWS IAM policies info'}, {'subtopic': 'ECS', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_ecs_restart_service&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': 'Sure! I can help with restarting AWS ECS Service'}, {'subtopic': 'EC2', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_ec2_create_instance&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': 'Sure, I can help creating an EC2 machine'}, {'subtopic': 'EC2', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_ec2_security_group_info&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': 'Sure, I can help with various information about AWS security groups'}, {'subtopic': 'S3', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_s3_file_copy&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-west&quot;}}'], 'text': 'Sure, I can help you with the process of copying on S3'}, {'subtopic': 'GitHub', 'topic': 'AWS', 'attachments': ['{&quot;workflow.name&quot;: &quot;view_pull_request&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-west&quot;}}'], 'text': 'Sure, I can help with GitHub pull requests'}, {'subtopic': 'Subtopic Title', 'topic': 'Topic Title', 'attachments': [], 'text': 'This is another fact'}, {'subtopic': 'Subtopic Title', 'topic': 'Topic Title', 'attachments': [], 'text': 'This is a fact'}] </code></pre> <p>I would like to group by topic and subtopic to get a final result:</p> <pre><code>{ &quot;AWS&quot;: { &quot;GitHub&quot;: { 'attachments': ['{&quot;workflow.name&quot;: &quot;view_pull_request&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-west&quot;}}'], 'text': ['Sure, I can help with GitHub pull requests'] }, &quot;S3&quot;: { 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_s3_file_copy&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-west&quot;}}'], 'text': ['Sure, I can help you with the process of copying on S3'] }, &quot;EC2&quot;: { 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_ec2_create_instance&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}', '{&quot;workflow.name&quot;: &quot;aws_ec2_security_group_info&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': ['Sure, I can help creating an EC2 machine', 'Sure, I can help with various information about AWS security groups'] }, &quot;ECS&quot;: { 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_ecs_restart_service&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': ['Sure! I can help with restarting AWS ECS Service'] }, &quot;IAM&quot;: { 'attachments': ['{&quot;workflow.name&quot;: &quot;aws_iam_policies_info&quot;,&quot;workflow.parameters&quot;: {&quot;region&quot;: &quot;us-east&quot;}}'], 'text': ['Sure! I can help with AWS IAM policies info'] } }, &quot;Topic Title&quot;: { &quot;Subtopic Title&quot;: { 'attachments': [], 'text': ['This is another fact'] } } } </code></pre> <p>I am using:</p> <pre><code>groups = ['topic', 'subtopic', &quot;text&quot;, &quot;attachments&quot;] groups.reverse() def hierachical_data(data, groups): g = groups[-1] g_list = [] for key, items in itertools.groupby(data, operator.itemgetter(g)): g_list.append({key:list(items)}) groups = groups[0:-1] if(len(groups) != 0): for e in g_list: for k, v in e.items(): e[k] = hierachical_data(v, groups) return g_list print(hierachical_data(filtered_top_facts_dicts, groups)) </code></pre> <p>But getting an error for hashing lists. Please advise how to transform my json to the desired format.</p>
[ { "answer_id": 74662294, "author": "Paulo M Serodio", "author_id": 20670538, "author_profile": "https://Stackoverflow.com/users/20670538", "pm_score": -1, "selected": false, "text": "data$age <- age_calc(as.Date(data$dob, \"%Y/%m/%d\"), \n as.Date(Sys.Date()), units = \"years\")\n" }, { "answer_id": 74662305, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": true, "text": "as.Date > df$age <- age_calc(as.Date(df$Date, \"%Y-%m-%d\"), units = \"years\")\n> df\n Name Date age\n1 A 1990-10-7 32.15342\n2 B 1997-11-20 25.03288\n Date - / - as.Date" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662274", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1030099/" ]
74,662,275
<p><a href="https://i.stack.imgur.com/5VdgZ.png" rel="nofollow noreferrer">Image of my Form</a></p> <p>I'd like to move this form to the middle of my web page. I have it center aligned currently, but it is at the top of my webpage. I want it smack dab in the middle. I've been trying to google around but this has been a surprisingly difficult answer to find.</p> <p>html</p> <pre><code>&lt;body&gt; &lt;div class=&quot;form&quot;&gt; &lt;form action=&quot;./script.js&quot; method=&quot;post&quot;&gt; &lt;ul&gt; &lt;li&gt; &lt;label for=&quot;date&quot;&gt;Date:&lt;/label&gt; &lt;input type=&quot;date&quot; id=&quot;date&quot; name=&quot;date&quot; step=&quot;0.1&quot; min=&quot;0&quot; placeholder=&quot;What's the date today?&quot; size=&quot;50&quot;&gt; &lt;/li&gt; &lt;li&gt; &lt;label for=&quot;mileage&quot;&gt;Mileage:&lt;/label&gt; &lt;input type=&quot;number&quot; id=&quot;mileage&quot; name=&quot;mileage&quot; step=&quot;0.1&quot; min=&quot;0&quot; placeholder=&quot;How many miles today?&quot; size=&quot;50&quot;&gt; &lt;/li&gt; &lt;li&gt; &lt;label for=&quot;note&quot;&gt;Notes:&lt;/label&gt; &lt;textarea id=&quot;note&quot; name=&quot;user_message&quot; placeholder=&quot;How did the run feel?&quot;&gt;&lt;/textarea&gt; &lt;/li&gt; &lt;li class=&quot;button&quot;&gt; &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>CSS</p> <pre><code>div.form { display: block; text-align: center; } form { margin: 0 auto; width: 600px; padding: 1em; border: 1px solid lightgrey; border-radius: 1em; display: inline-block; margin-left: auto; margin-right: auto; text-align: left; } form li+li { margin-top: 1em; } </code></pre>
[ { "answer_id": 74662297, "author": "anton-tchekov", "author_id": 4724047, "author_profile": "https://Stackoverflow.com/users/4724047", "pm_score": 2, "selected": true, "text": "div.form {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n\nform {\n margin: 0 auto;\n width: 600px;\n padding: 1em;\n border: 1px solid lightgrey;\n border-radius: 1em;\n text-align: left;\n}\n\nform li+li {\n margin-top: 1em;\n} <body>\n <div class=\"form\">\n <form action=\"./script.js\" method=\"post\">\n <ul>\n <li>\n <label for=\"date\">Date:</label>\n <input type=\"date\" id=\"date\" name=\"date\" step=\"0.1\" min=\"0\" \n placeholder=\"What's the date today?\" size=\"50\">\n </li>\n <li>\n <label for=\"mileage\">Mileage:</label>\n <input type=\"number\" id=\"mileage\" name=\"mileage\" step=\"0.1\" min=\"0\" \n placeholder=\"How many miles today?\" size=\"50\">\n </li>\n <li>\n <label for=\"note\">Notes:</label>\n <textarea id=\"note\" name=\"user_message\" placeholder=\"How did the run feel?\"></textarea>\n </li>\n <li class=\"button\">\n <button type=\"submit\">Submit</button>\n </li>\n </ul>\n </form>\n </div>\n</body>\n</html>" }, { "answer_id": 74662311, "author": "Mark Schultheiss", "author_id": 125981, "author_profile": "https://Stackoverflow.com/users/125981", "pm_score": -1, "selected": false, "text": ".form-container {\n height: 100vh;\n display: grid;\n place-items: center;\n}\n\n/* this is just style */\nform {\n margin: 0 auto;\n width: 50vw;\n padding: 1em;\n border: 1px solid lightgrey;\n border-radius: 1em;\n display: inline-block;\n margin-left: auto;\n margin-right: auto;\n text-align: left;\n}\n\nform li+li {\n margin-top: 1em;\n} <div class=\"form form-container\">\n <form action=\"./script.js\" method=\"post\">\n <ul>\n <li>\n <label for=\"date\">Date:</label>\n <input type=\"date\" id=\"date\" name=\"date\" step=\"0.1\" min=\"0\" placeholder=\"What's the date today?\" size=\"50\">\n </li>\n <li>\n <label for=\"mileage\">Mileage:</label>\n <input type=\"number\" id=\"mileage\" name=\"mileage\" step=\"0.1\" min=\"0\" placeholder=\"How many miles today?\" size=\"50\">\n </li>\n <li>\n <label for=\"note\">Notes:</label>\n <textarea id=\"note\" name=\"user_message\" placeholder=\"How did the run feel?\"></textarea>\n </li>\n <li class=\"button\">\n <button type=\"submit\">Submit</button>\n </li>\n </ul>\n </form>\n</div>" }, { "answer_id": 74662339, "author": "DCR", "author_id": 4398966, "author_profile": "https://Stackoverflow.com/users/4398966", "pm_score": -1, "selected": false, "text": "form {\n margin: 0 auto;\n width: 600px;\n padding: 1em;\n border: 1px solid lightgrey;\n border-radius: 1em;\n \n text-align: left;\n}\n\nform li+li {\n margin-top: 1em;\n}\n\n.form{\ndisplay:flex;\nheight:calc(100vh - 2px);\njustify-content:center;\nalign-items:center;\nborder:solid 1px red;}\n\nbody,html,div{\nmargin:0;\npadding:0;} <body>\n <div class=\"form\">\n <form action=\"./script.js\" method=\"post\">\n <ul>\n <li>\n <label for=\"date\">Date:</label>\n <input type=\"date\" id=\"date\" name=\"date\" step=\"0.1\" min=\"0\" \n placeholder=\"What's the date today?\" size=\"50\">\n </li>\n <li>\n <label for=\"mileage\">Mileage:</label>\n <input type=\"number\" id=\"mileage\" name=\"mileage\" step=\"0.1\" min=\"0\" \n placeholder=\"How many miles today?\" size=\"50\">\n </li>\n <li>\n <label for=\"note\">Notes:</label>\n <textarea id=\"note\" name=\"user_message\" placeholder=\"How did the run feel?\"></textarea>\n </li>\n <li class=\"button\">\n <button type=\"submit\">Submit</button>\n </li>\n </ul>\n </form>\n </div>\n</body>" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670476/" ]
74,662,287
<p>I have seen may tutorials on making the first row the column names, but nothing explaining how to do the reverse. I would like to have my column names as the first row values and change the column names to something like var1, var2, var3. Can this be done?</p> <p>I plan to row bind a bunch of data frames later, so they all need the same column names.</p> <pre><code>q = structure(list(shootings_per100k = c(8105.47466098618, 6925.42653239307 ), lawtotal = c(3.00137104283906, 0.903522788541896), felony = c(0.787418655097614, 0.409578330883717)), row.names = c(&quot;mean&quot;, &quot;sd&quot;), class = &quot;data.frame&quot;) </code></pre> <p><strong>Have:</strong></p> <pre><code> shootings_per100k lawtotal felony mean 8105.475 3.0013710 0.7874187 sd 6925.427 0.9035228 0.4095783 </code></pre> <p><strong>Want:</strong></p> <pre><code> var1 var2 var3 var shootings_per100k lawtotal felony mean 8105.475 3.0013710 0.7874187 sd 6925.427 0.9035228 0.4095783 </code></pre> <p><strong>edit:</strong> I just realized that since I plan to row bind several data frames later, it may be best for them to all have the same column names. I changed the 'want' section to reflect the desired outcome.</p>
[ { "answer_id": 74662350, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": true, "text": "q <- rbind(colnames(q), round(q, 4))\ncolnames(q) <- paste0(\"var\", seq_len(ncol(q)))\nrownames(q)[1] <- \"var\"\nq\n var1 var2 var3\nvar shootings_per100k lawtotal felony\nmean 8105.4747 3.0014 0.7874\nsd 6925.4265 0.9035 0.4096\n" }, { "answer_id": 74662495, "author": "rjen", "author_id": 12820205, "author_profile": "https://Stackoverflow.com/users/12820205", "pm_score": 0, "selected": false, "text": "library(tidyverse)\n\nnames <- enframe(colnames(df)) %>%\n pivot_wider(-name, names_from = value) %>%\n rename_with( ~ LETTERS[1:length(df)])\n\ndata <- as_tibble(df) %>%\n mutate(across(everything(), ~ as.character(.))) %>%\n rename_with(~ LETTERS[1:length(df)])\n\nbind_rows(names, data)\n\n# A tibble: 3 × 3\n# A B C \n# <chr> <chr> <chr> \n# 1 shootings_per100k lawtotal felony \n# 2 8105.475 3.001371 0.7874187\n# 3 6925.427 0.9035228 0.4095783\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15858688/" ]
74,662,293
<p>I have the following dataset:</p> <pre><code> Letter ID Number A A1 1 A A2 2 A A3 3 B B1 1 B B2 2 B B3 3 B B4 4 </code></pre> <p>My aim is first to create all possible combinations of IDs within the same &quot;Letter&quot; group. For example, for the letter A, it would be only three combinations: A1-A2,A2-A3,and A1-A3. The same IDs ordered differently don't count as a new combination, so for example A1-A2 is the same as A2-A1.</p> <p>Then, within those combinations, I want to add up the numbers from the &quot;Number&quot; column associated with those IDs. So for the combination A1-A2, which are associated with 1 and 2 in the &quot;Number&quot; column, this would result in the number 1+2=3.</p> <p>Finally, I want to place the ID combinations, added numbers and original Letter in a new data frame. Something like this:</p> <pre><code>Letter Combination Add.Number A A1-A2 3 A A2-A3 5 A A1-A3 4 B B1-B2 3 B B2-B3 5 B B3-B4 7 B B1-B3 4 B B2-B4 6 B B1-B4 5 </code></pre> <p>How can I do this in R, ideally using the package dplyr?</p>
[ { "answer_id": 74662370, "author": "Vinícius Félix", "author_id": 9696037, "author_profile": "https://Stackoverflow.com/users/9696037", "pm_score": 3, "selected": true, "text": "library(dplyr)\n \n\nletter <- c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\")\n\ndf <-\n data.frame(letter) %>% \n group_by(letter) %>% \n mutate(\n number = row_number(),\n id = paste0(letter,number)\n ) \n\ndf %>% \n full_join(df,by = \"letter\") %>% \n filter(number.x < number.y) %>% \n mutate(\n combination = paste0(id.x,\"-\",id.y),\n add_number = number.x + number.y) %>% \n select(letter,combination,add_number)\n\n# A tibble: 9 x 3\n# Groups: letter [2]\n letter combination add_number\n <chr> <chr> <int>\n1 A A1-A2 3\n2 A A1-A3 4\n3 A A2-A3 5\n4 B B1-B2 3\n5 B B1-B3 4\n6 B B1-B4 5\n7 B B2-B3 5\n8 B B2-B4 6\n9 B B3-B4 7\n" }, { "answer_id": 74662662, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 1, "selected": false, "text": "combn df <- data.frame(\n Letter = c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\"),\n Id = c(\"A1\",\"A2\",\"A3\",\"B1\",\"B2\",\"B3\",\"B4\"),\n Number = c(1,2,3,1,2,3,4))\n\n# combinations\nl<-lapply(split(df$Id, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"L1\",\"L2\")))\nn<-lapply(split(df$Number, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"N1\",\"N2\")))\n\n# rbind all\nresult <- do.call(rbind, mapply(cbind, Letter=names(l), l, n, SIMPLIFY = F))\nresult$combination <- paste(result$L1, result$L2, sep=\"-\")\nresult$sum = result$N1 + result$N2\nresult\n#> Letter L1 L2 N1 N2 combination sum\n#> A.1 A A1 A2 1 2 A1-A2 3\n#> A.2 A A1 A3 1 3 A1-A3 4\n#> A.3 A A2 A3 2 3 A2-A3 5\n#> B.1 B B1 B2 1 2 B1-B2 3\n#> B.2 B B1 B3 1 3 B1-B3 4\n#> B.3 B B1 B4 1 4 B1-B4 5\n#> B.4 B B2 B3 2 3 B2-B3 5\n#> B.5 B B2 B4 2 4 B2-B4 6\n#> B.6 B B3 B4 3 4 B3-B4 7\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662293", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14011731/" ]
74,662,295
<p>im doing a project-excercise of debugging using objects, im already done all the other´s excercises but im very stuck in this, i dont know how to solve.</p> <pre><code> /* Fix the `feedPet` function. `feedPet` should take in a pet name and return a function that, when invoked with a food, will return the pet's name and a list of foods that you have fed that pet. */ function feedPet(name) { const foods = []; return (food) =&gt; { return &quot;Fed &quot; + name + &quot; &quot; + foods.push(food) + &quot;.&quot;; } } const feedHydra = feedPet('Hydra'); console.log(feedHydra('bones')); // Fed Hyrda bones. console.log(feedHydra('Hercules')); // Fed Hyrda bones, Hercules. const feedHippogriff = feedPet('Hippogriff'); console.log(feedHippogriff('worms')); // Fed Hyrda worms. console.log(feedHippogriff('crickets')); // Fed Hyrda worms, crickets. console.log(feedHippogriff('chicken')); // Fed Hyrda worms, crickets, chicken. </code></pre>
[ { "answer_id": 74662370, "author": "Vinícius Félix", "author_id": 9696037, "author_profile": "https://Stackoverflow.com/users/9696037", "pm_score": 3, "selected": true, "text": "library(dplyr)\n \n\nletter <- c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\")\n\ndf <-\n data.frame(letter) %>% \n group_by(letter) %>% \n mutate(\n number = row_number(),\n id = paste0(letter,number)\n ) \n\ndf %>% \n full_join(df,by = \"letter\") %>% \n filter(number.x < number.y) %>% \n mutate(\n combination = paste0(id.x,\"-\",id.y),\n add_number = number.x + number.y) %>% \n select(letter,combination,add_number)\n\n# A tibble: 9 x 3\n# Groups: letter [2]\n letter combination add_number\n <chr> <chr> <int>\n1 A A1-A2 3\n2 A A1-A3 4\n3 A A2-A3 5\n4 B B1-B2 3\n5 B B1-B3 4\n6 B B1-B4 5\n7 B B2-B3 5\n8 B B2-B4 6\n9 B B3-B4 7\n" }, { "answer_id": 74662662, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 1, "selected": false, "text": "combn df <- data.frame(\n Letter = c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\"),\n Id = c(\"A1\",\"A2\",\"A3\",\"B1\",\"B2\",\"B3\",\"B4\"),\n Number = c(1,2,3,1,2,3,4))\n\n# combinations\nl<-lapply(split(df$Id, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"L1\",\"L2\")))\nn<-lapply(split(df$Number, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"N1\",\"N2\")))\n\n# rbind all\nresult <- do.call(rbind, mapply(cbind, Letter=names(l), l, n, SIMPLIFY = F))\nresult$combination <- paste(result$L1, result$L2, sep=\"-\")\nresult$sum = result$N1 + result$N2\nresult\n#> Letter L1 L2 N1 N2 combination sum\n#> A.1 A A1 A2 1 2 A1-A2 3\n#> A.2 A A1 A3 1 3 A1-A3 4\n#> A.3 A A2 A3 2 3 A2-A3 5\n#> B.1 B B1 B2 1 2 B1-B2 3\n#> B.2 B B1 B3 1 3 B1-B3 4\n#> B.3 B B1 B4 1 4 B1-B4 5\n#> B.4 B B2 B3 2 3 B2-B3 5\n#> B.5 B B2 B4 2 4 B2-B4 6\n#> B.6 B B3 B4 3 4 B3-B4 7\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19281834/" ]
74,662,327
<p>So I'm creating a batch project, everything is fine, but suddenly the cmd automatically opens as administrator.</p> <p>I tried finding something in registry keys, looking almost an hour for an answer online, etc.</p> <p>How can I disable cmd opening as administrator?</p> <p>(It's almost 12pm in my country, sorry if i don't answer quickly)</p>
[ { "answer_id": 74662370, "author": "Vinícius Félix", "author_id": 9696037, "author_profile": "https://Stackoverflow.com/users/9696037", "pm_score": 3, "selected": true, "text": "library(dplyr)\n \n\nletter <- c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\")\n\ndf <-\n data.frame(letter) %>% \n group_by(letter) %>% \n mutate(\n number = row_number(),\n id = paste0(letter,number)\n ) \n\ndf %>% \n full_join(df,by = \"letter\") %>% \n filter(number.x < number.y) %>% \n mutate(\n combination = paste0(id.x,\"-\",id.y),\n add_number = number.x + number.y) %>% \n select(letter,combination,add_number)\n\n# A tibble: 9 x 3\n# Groups: letter [2]\n letter combination add_number\n <chr> <chr> <int>\n1 A A1-A2 3\n2 A A1-A3 4\n3 A A2-A3 5\n4 B B1-B2 3\n5 B B1-B3 4\n6 B B1-B4 5\n7 B B2-B3 5\n8 B B2-B4 6\n9 B B3-B4 7\n" }, { "answer_id": 74662662, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 1, "selected": false, "text": "combn df <- data.frame(\n Letter = c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\"),\n Id = c(\"A1\",\"A2\",\"A3\",\"B1\",\"B2\",\"B3\",\"B4\"),\n Number = c(1,2,3,1,2,3,4))\n\n# combinations\nl<-lapply(split(df$Id, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"L1\",\"L2\")))\nn<-lapply(split(df$Number, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"N1\",\"N2\")))\n\n# rbind all\nresult <- do.call(rbind, mapply(cbind, Letter=names(l), l, n, SIMPLIFY = F))\nresult$combination <- paste(result$L1, result$L2, sep=\"-\")\nresult$sum = result$N1 + result$N2\nresult\n#> Letter L1 L2 N1 N2 combination sum\n#> A.1 A A1 A2 1 2 A1-A2 3\n#> A.2 A A1 A3 1 3 A1-A3 4\n#> A.3 A A2 A3 2 3 A2-A3 5\n#> B.1 B B1 B2 1 2 B1-B2 3\n#> B.2 B B1 B3 1 3 B1-B3 4\n#> B.3 B B1 B4 1 4 B1-B4 5\n#> B.4 B B2 B3 2 3 B2-B3 5\n#> B.5 B B2 B4 2 4 B2-B4 6\n#> B.6 B B3 B4 3 4 B3-B4 7\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19555882/" ]
74,662,331
<p><a href="https://i.stack.imgur.com/8F3sO.png" rel="nofollow noreferrer">Problem Code Picture</a></p> <p>I want to write a Python script that creates a new virtual environment with the following <a href="https://pypi.org/project/virtualenv/" rel="nofollow noreferrer"><em>virtualenv</em></a> CLI options:</p> <blockquote> <p><code>--app-data APP_DATA</code> (a folder APP_DATA for the cache)</p> <p><code>--seeder {app-data,pip}</code></p> </blockquote> <p>If I give those two as strings in a list (see picture) I get:</p> <pre><code>TypeError: options must be of type VirtualEnvOptions </code></pre>
[ { "answer_id": 74662370, "author": "Vinícius Félix", "author_id": 9696037, "author_profile": "https://Stackoverflow.com/users/9696037", "pm_score": 3, "selected": true, "text": "library(dplyr)\n \n\nletter <- c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\")\n\ndf <-\n data.frame(letter) %>% \n group_by(letter) %>% \n mutate(\n number = row_number(),\n id = paste0(letter,number)\n ) \n\ndf %>% \n full_join(df,by = \"letter\") %>% \n filter(number.x < number.y) %>% \n mutate(\n combination = paste0(id.x,\"-\",id.y),\n add_number = number.x + number.y) %>% \n select(letter,combination,add_number)\n\n# A tibble: 9 x 3\n# Groups: letter [2]\n letter combination add_number\n <chr> <chr> <int>\n1 A A1-A2 3\n2 A A1-A3 4\n3 A A2-A3 5\n4 B B1-B2 3\n5 B B1-B3 4\n6 B B1-B4 5\n7 B B2-B3 5\n8 B B2-B4 6\n9 B B3-B4 7\n" }, { "answer_id": 74662662, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 1, "selected": false, "text": "combn df <- data.frame(\n Letter = c(\"A\",\"A\",\"A\",\"B\",\"B\",\"B\",\"B\"),\n Id = c(\"A1\",\"A2\",\"A3\",\"B1\",\"B2\",\"B3\",\"B4\"),\n Number = c(1,2,3,1,2,3,4))\n\n# combinations\nl<-lapply(split(df$Id, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"L1\",\"L2\")))\nn<-lapply(split(df$Number, df$Letter) ,function(x) \n setNames(data.frame(t(combn(x,2))), c(\"N1\",\"N2\")))\n\n# rbind all\nresult <- do.call(rbind, mapply(cbind, Letter=names(l), l, n, SIMPLIFY = F))\nresult$combination <- paste(result$L1, result$L2, sep=\"-\")\nresult$sum = result$N1 + result$N2\nresult\n#> Letter L1 L2 N1 N2 combination sum\n#> A.1 A A1 A2 1 2 A1-A2 3\n#> A.2 A A1 A3 1 3 A1-A3 4\n#> A.3 A A2 A3 2 3 A2-A3 5\n#> B.1 B B1 B2 1 2 B1-B2 3\n#> B.2 B B1 B3 1 3 B1-B3 4\n#> B.3 B B1 B4 1 4 B1-B4 5\n#> B.4 B B2 B3 2 3 B2-B3 5\n#> B.5 B B2 B4 2 4 B2-B4 6\n#> B.6 B B3 B4 3 4 B3-B4 7\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15363754/" ]
74,662,334
<p>I am making a simple game with multiple players, which each player can insert their first name, last name and each player is assigned 100 poins at the begging. In my code once I am done with coding the &quot;essential&quot; information, but when it comes to user input it does not work.</p> <p>The &quot;base&quot; for the player class: (this part works)</p> <pre><code>class Players(): def __init__ (self, firstname, lastname, coins): #initialising attributes self.firstname = firstname self.lastname = lastname self.coins= coins def full_info(self): return self.firstname + self.lastname + self.coins </code></pre> <p>This is the second part where the problem is, the input is not stored in the attributes</p> <pre><code> def get_user_input(self): firstname= input(&quot;Please enter your first name:&quot;) lastname= input (&quot;Please enter your second name: &quot;) coins= 100 #they are assigned automatically return self(firstname, lastname, coins) </code></pre> <p>I would appriciate any suggesting regarding the user input.</p>
[ { "answer_id": 74662387, "author": "Samwise", "author_id": 3799759, "author_profile": "https://Stackoverflow.com/users/3799759", "pm_score": 2, "selected": false, "text": "classmethod staticmethod @dataclass __init__ full_info coins from dataclasses import dataclass\n\n@dataclass\nclass Player: \n firstname: str\n lastname: str\n coins: int\n\n def full_info(self) -> str:\n return f\"{self.firstname} {self.lastname} {self.coins}\"\n\n @classmethod\n def from_user_input(cls) -> 'Player':\n return cls(\n firstname=input(\"Please enter your first name:\"),\n lastname=input(\"Please enter your second name: \"),\n coins=100,\n )\n Player.from_user_input() Player >>> player = Player.from_user_input()\nPlease enter your first name:Bob\nPlease enter your second name: Small\n>>> player\nPlayer(firstname='Bob', lastname='Small', coins=100)\n>>> player.full_info()\n'Bob Small 100'\n" }, { "answer_id": 74662428, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 0, "selected": false, "text": "class Players(): \n def __init__ (self, firstname, lastname, coins): #initialising attributes\n self.firstname = firstname \n self.lastname = lastname\n self.coins= coins\n \n def full_info(self):\n return self.firstname + ' ' + self.lastname + ' ' + str(self.coins)\n \ndef get_user_input():\n firstname= input(\"Please enter your first name:\")\n lastname= input (\"Please enter your second name: \")\n coins= 100 #they are assigned automatically \n return Players(firstname, lastname, coins)\n a=get_user_input()\n\nPlease enter your first name:UN\n\nPlease enter your second name: Owen\n\na.full_info()\nOut[21]: 'UN Owen 100'\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20591722/" ]
74,662,347
<p>I am new to typescript and converting my jsx to tsx files. How can I define the type for a redux dispatch for my <code>onPress</code> prop? I tried using &quot;Function&quot; and the &quot;AppDispatch&quot;. Thanks in advance</p> <pre><code>import { AppDispatch } from &quot;../redux/store&quot; interface ItemProps { item: Custom_date, onPress: AppDispatch, //What should I put here? backgroundColor: any, textColor: any } const Item = ({ item, onPress, backgroundColor, textColor }: ItemProps) =&gt; ( &lt;TouchableOpacity onPress={onPress} style={[styles.item, backgroundColor]}&gt; &lt;Text style={[styles.dateTitle, textColor]}&gt;{item.title}&lt;/Text&gt; &lt;/TouchableOpacity&gt; ); export const DateHeader = () =&gt; { const { date } = useSelector((store: RootState) =&gt; store.nutrition) const dispatch = useDispatch() const renderItem = ({ item }) =&gt; { const backgroundColor = item.id === date.id ? &quot;#033F40&quot; : &quot;#BDF0CC&quot;; const color = item.id === date.id ? '#BDF0CC' : '#033F40'; return ( &lt;Item item={item} onPress={() =&gt; dispatch(setDate(item))} backgroundColor={{ backgroundColor }} textColor={{ color }} /&gt; ); } return (&lt;&gt; &lt;FlatList {props} /&gt; &lt;/&gt;) } </code></pre>
[ { "answer_id": 74662769, "author": "Dakeyras", "author_id": 1857909, "author_profile": "https://Stackoverflow.com/users/1857909", "pm_score": 2, "selected": true, "text": "dispatch() useDispatch() onPress onPress interface ItemProps {\n item: Custom_date, \n onPress: () => void,\n backgroundColor: any,\n textColor: any\n}\n" }, { "answer_id": 74662775, "author": "DotNetRussell", "author_id": 2051392, "author_profile": "https://Stackoverflow.com/users/2051392", "pm_score": 0, "selected": false, "text": "interface ItemProps {\n item: Custom_date, \n onPress: AppDispatch, \n backgroundColor: any,\n textColor: any\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662347", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18604870/" ]
74,662,348
<p>In Vuetify, if I want to move my delete button closer to the expand button.<br /> How do I do that ?</p> <pre class="lang-html prettyprint-override"><code>&lt;v-expansion-panel-header&gt; {{ vehicle.VIN }} &lt;v-icon v-if=&quot;type == 'saved'&quot; color=&quot;teal&quot;&gt; mdi-check &lt;/v-icon&gt; &lt;v-btn text v-if=&quot;type == 'saved'&quot; color=&quot;red&quot; @click=&quot;remove(index, type)&quot; &gt; DELETE &lt;/v-btn&gt; &lt;/v-expansion-panel-header&gt; </code></pre> <p><a href="https://i.stack.imgur.com/Lzghf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lzghf.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74662769, "author": "Dakeyras", "author_id": 1857909, "author_profile": "https://Stackoverflow.com/users/1857909", "pm_score": 2, "selected": true, "text": "dispatch() useDispatch() onPress onPress interface ItemProps {\n item: Custom_date, \n onPress: () => void,\n backgroundColor: any,\n textColor: any\n}\n" }, { "answer_id": 74662775, "author": "DotNetRussell", "author_id": 2051392, "author_profile": "https://Stackoverflow.com/users/2051392", "pm_score": 0, "selected": false, "text": "interface ItemProps {\n item: Custom_date, \n onPress: AppDispatch, \n backgroundColor: any,\n textColor: any\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4480164/" ]
74,662,424
<pre><code>[eslint] Plugin &quot;react&quot; was conflicted between &quot;package.json » eslint-config-rea ct-app » C:\Users\user\desktop\robofriends\node_modules\eslint-config-react-app\ base.js&quot; and &quot;BaseConfig » C:\Users\user\Desktop\robofriends\node_modules\eslint -config-react-app\base.js&quot;. ERROR in [eslint] Plugin &quot;react&quot; was conflicted between &quot;package.json » eslint-c onfig-react-app » C:\Users\user\desktop\robofriends\node_modules\eslint-config-r eact-app\base.js&quot; and &quot;BaseConfig » C:\Users\user\Desktop\robofriends\node_modul es\eslint-config-react-app\base.js&quot;. </code></pre> <p>I tried re-install everything from the start all over but still didnt work.</p>
[ { "answer_id": 74662769, "author": "Dakeyras", "author_id": 1857909, "author_profile": "https://Stackoverflow.com/users/1857909", "pm_score": 2, "selected": true, "text": "dispatch() useDispatch() onPress onPress interface ItemProps {\n item: Custom_date, \n onPress: () => void,\n backgroundColor: any,\n textColor: any\n}\n" }, { "answer_id": 74662775, "author": "DotNetRussell", "author_id": 2051392, "author_profile": "https://Stackoverflow.com/users/2051392", "pm_score": 0, "selected": false, "text": "interface ItemProps {\n item: Custom_date, \n onPress: AppDispatch, \n backgroundColor: any,\n textColor: any\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670607/" ]
74,662,454
<p>I was curious on how wheel spinning based of chances algorithm would work so I wrote this code</p> <p>I created an object with each prize and its probability</p> <pre><code>const chances = { &quot;Apple&quot; : 22.45, &quot;Peaches&quot; : 32.8, &quot;Grapes&quot; : 20, &quot;Bananas&quot; : 6.58, &quot;Strawberry&quot; : 18.17 } </code></pre> <p>then I generate a random number and check if its within the prize's winning ranges</p> <pre><code>const random = Math.floor((Math.random() * 10000) + 1); var rangeStart= 0; for (var key in chances){ var rangeEnd= rangeStart+ chances[key]; if (rangeStart*100 &lt; random &amp;&amp; random &lt;= rangeEnd*100){ console.log(rangeStart*100+&quot; &lt; &quot;+random+&quot; &lt;= &quot;+rangeEnd*100); console.log(&quot;You won a &quot;+key) break; } rangeStart+= chances[key]; } </code></pre> <p>you can check the code <a href="https://jsfiddle.net/5h9tygkd/1/" rel="nofollow noreferrer">here</a></p> <p>am I in the right path?</p>
[ { "answer_id": 74662769, "author": "Dakeyras", "author_id": 1857909, "author_profile": "https://Stackoverflow.com/users/1857909", "pm_score": 2, "selected": true, "text": "dispatch() useDispatch() onPress onPress interface ItemProps {\n item: Custom_date, \n onPress: () => void,\n backgroundColor: any,\n textColor: any\n}\n" }, { "answer_id": 74662775, "author": "DotNetRussell", "author_id": 2051392, "author_profile": "https://Stackoverflow.com/users/2051392", "pm_score": 0, "selected": false, "text": "interface ItemProps {\n item: Custom_date, \n onPress: AppDispatch, \n backgroundColor: any,\n textColor: any\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17948670/" ]
74,662,478
<p>I'm quite new to SQL so bare with me. What I'm trying to do is return the value closest to another value in a different table for every record.</p> <p>I'll show a simplified example of my two tables for clarification</p> <p>First table is the one that I want the value ENTRY_YEAR matched to:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>ENTRY_VALUE</th> </tr> </thead> <tbody> <tr> <td>1001</td> <td>1900</td> </tr> <tr> <td>1002</td> <td>2000</td> </tr> </tbody> </table> </div> <p>And the second table:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>ENTRY_VALUE</th> <th>STATUS</th> </tr> </thead> <tbody> <tr> <td>1001</td> <td>1880</td> <td>SUCCES</td> </tr> <tr> <td>1001</td> <td>1930</td> <td>FAIL</td> </tr> <tr> <td>1001</td> <td>1940</td> <td>SUCCES</td> </tr> <tr> <td>1002</td> <td>1960</td> <td>SUCCES</td> </tr> <tr> <td>1002</td> <td>1980</td> <td>FAIL</td> </tr> </tbody> </table> </div> <p>So the end result I'm looking for is:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>ENTRY_VALUE</th> <th>STATUS</th> </tr> </thead> <tbody> <tr> <td>1001</td> <td>1880</td> <td>SUCCES</td> </tr> <tr> <td>1002</td> <td>1980</td> <td>FAIL</td> </tr> </tbody> </table> </div> <p>I have currently only managed to link the id's together but can't find a way to compare the ENTRY_VALUE in both tables and return the one closest to the Table1 entry.</p> <p>So only this:</p> <pre><code>SELECT * from Table2 INNER JOIN Table1 ON (Table2.ID = Table1.ID) </code></pre> <p>Once again my bad for the basic question, I have googled right about everything but can't get it to work so any help is very welcome!</p>
[ { "answer_id": 74662739, "author": "topsail", "author_id": 1467914, "author_profile": "https://Stackoverflow.com/users/1467914", "pm_score": 1, "selected": false, "text": "select \n a.id,\n b.entry_value,\n b.[status]\nfrom \n Foo a \n inner join Bar b\n on a.id = b.id\nwhere \n abs(a.entry_value - b.entry_value) =\n (select min(abs(t1.entry_value-t2.entry_value))\n from Foo t1 \n inner join Bar t2\n on t1.id = t2.id\n where\n t1.id = a.id\n group by t1.id)\n select A.Id, A.entry_value, A.[status]\nfrom \n (\n select t1.id, t2.entry_value, abs(t1.entry_value-t2.entry_value) as diff, t2.[status]\n from Foo t1 \n inner join Bar t2\n on t1.id = t2.id\n ) A\n inner join\n (\n select t3.id, min(abs(t3.entry_value-t4.entry_value)) as diff\n from Foo t3\n inner join Bar t4\n on t3.id = t4.id\n group by t3.id\n ) B\n on A.id = B.id\n and A.diff = B.diff\n (1003,2000) (1003, 1990, 'success') (1003, 2010, 'fail') success fail select\n T.id,\n T.entry_value,\n T.[status]\nfrom\n(\n select \n t1.id,\n t2.entry_value,\n abs(t1.entry_value-t2.entry_value) as diff,\n t2.[status],\n rank() over (partition by t1.id order by abs(t1.entry_value-t2.entry_value)) as seq\n from #Foo t1 \n inner join #Bar t2\n on t1.id = t2.id\n) T\nwhere T.seq = 1;\n" }, { "answer_id": 74666448, "author": "Gustav", "author_id": 3527297, "author_profile": "https://Stackoverflow.com/users/3527297", "pm_score": 1, "selected": true, "text": "Select \n tbl1.ID, \n tbl2.ENTRY_VALUE,\n tbl2.STATUS\nFrom \n tbl1 \nInner Join \n tbl2 On tbl1.ID = tbl2.ID\nWhere \n Abs([tbl1].[ENTRY_VALUE] - [tbl2].[ENTRY_VALUE]) =\n (Select Min(Abs([tbl1].[ENTRY_VALUE] - [T2].[ENTRY_VALUE])) As Offset\n From tbl2 As T2 \n Where T2.ID = tbl1.ID);\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670565/" ]
74,662,528
<p>Font family is running. But font weight doesnt work properly. For example I added font-weight:400 or 100,etc to h3-h4,etc its doesnt work. Only one font weight does work properly and its font-weight:600 I am completely done, I am researching for two days, I'm asking my friends but my problem still here. I think my @font-face's setups are true. Bu I dont know.. Please anyone can help me?</p> <pre><code> @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-thin-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-thin-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 100; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-light-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-light-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 300; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-book-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-book-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 400; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-medium-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-medium-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 500; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-bold-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-bold-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 700; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-ultra-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-ultra-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 800; font-style: normal; } @font-face { font-family: &quot;Gotham Narrow&quot;; src: local(&quot;../font/gothamnarrow-black-webfont.woff2&quot;) format(&quot;woff2&quot;), local(&quot;../font/gothamnarrow-black-webfont.woff&quot;) format(&quot;woff&quot;); font-weight: 900; font-style: normal; } </code></pre>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17768986/" ]
74,662,545
<p>I was going through this question on leetcode: <a href="https://leetcode.com/problems/determine-if-two-strings-are-close/solutions/935916/c-o-nlogn-sort-hash-table-easy-to-understand/" rel="nofollow noreferrer">https://leetcode.com/problems/determine-if-two-strings-are-close/solutions/935916/c-o-nlogn-sort-hash-table-easy-to-understand/</a></p> <pre><code>class Solution { public: bool closeStrings(string word1, string word2) { if(word1.size()!=word2.size()) return false; int n = word1.size(); vector&lt;int&gt;freq1(26,0); vector&lt;int&gt;freq2(26,0); for(int i= 0 ; i &lt; n ; ++i){ freq1[word1[i]-'a']++; freq2[word2[i]-'a']++; } sort(freq1.rbegin(),freq1.rend()); sort(freq2.rbegin(),freq2.rend()); **if(set(word1.begin(),word1.end())!=set(word2.begin(),word2.end()))** return false; for(int i= 0;i&lt;26;++i){ if(freq1[i]!=freq2[i]) return false; } return true; } }; </code></pre> <p>I am not understanding what does <code>set(word1.begin(),word1.end())</code> mean over here, I tried to search on the internet for answer but I didn't got any satisfying answer, if someone can explain it would be very helpful. Thanks in advance!</p>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14175795/" ]
74,662,570
<p>Today we used the consult for recive a pattern of data, and, with this pattern select the results:</p> <pre><code>SELECT pm.meta_value, MONTH(RTRIM(LTRIM(SUBSTRING(pm.meta_key,23,10)))) as month FROM wp_postmeta pm </code></pre> <p><strong>The problem is</strong>: The consulting are stay slowed, and, we cant change the database. How i can make this consult stay more speed? I'm yet trying put the index, but, not solved.</p> <p>The pattern is filter the string in wp_postmeta and retry get the month.</p> <p><strong>For example</strong>:</p> <ul> <li>string-with-any-name-of-day-2022-01-32, so, we filtering this string with rtrim and substring for get the month.</li> </ul> <p>I'm tryed put the index in table wp_postdata in column meta_key and meta_value, but this not solved my problem.</p> <p>I yet think in create other table for storage this meta data, but, the problem is gonna continue.</p>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2467030/" ]
74,662,606
<p>Im trying to build a cheaty kinda multilingual site in wordpress (interim fix) and need to set the logo link to go the the correct landing page when clicked, either /en/ or /se/.</p> <p>Im trying to do this by grabing the url and then splitting the path name.</p> <p>`</p> <pre><code>&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt; const firstpath = location.pathname.split('/')[1]; &lt;/script&gt; &lt;a href=&quot;/&quot; onclick=&quot;location.href=this.href+firstpath;return false;&quot;&gt; &lt;img /&gt; &lt;/a&gt; </code></pre> <p>`</p> <p>fairly sure im missing something simple, especially as it did work awhile ago until I changed something that i dont remember :/</p> <p>When clicked the link shoulf return: root/first-folder-of-current-url</p> <p>MORE DETAILS: (sorry fairly new here)</p> <p>So I have a two folder hierarcy /en/ and /se/.</p> <p>When in the /en/ folder if i click the logo I should be taken back to the root/en/ folder.</p> <p>When in the /se/ folder if i click the logo I should be taken back to the root/se/ folder.</p> <p>I cant have unique code for each folder so stuck trying to make this work with a javascript link.</p>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20670755/" ]
74,662,635
<p>I am creating a form that allows the user to select from a group of checkboxes for automotive services. In the form, the user selects from a list of priced services and a final total is calculated based on what is selected.</p> <p>The logic of the selected services being added up is placed within a method that returns the total.</p> <p><img src="https://i.stack.imgur.com/hR4ZX.png" alt="photo of form" />.</p> <p>Once the user clicks on the calculate button, all selected prices will be added up and displayed by the total fees label.</p> <pre><code> public partial class Automotive_Shop : Form { const int salesTax = (6 / 100); // prices for services const int oilChange = 26, lubeJob = 18, radiatorFlush = 30, transissionFlush = 80, inspection = 15, mufflerReplacement = 100, tireRotation = 20; int total = 0; public Automotive_Shop() { InitializeComponent(); } private int OilLubeCharges() { if (oilChangeCheckBox.Checked == true) { total += oilChange; } if (lubeJobCheckBox.Checked == true) { total += lubeJob; } return total; } private void calculateButton_Click(object sender, EventArgs e) { totalFeesOutput.Text = OilLubeCharges().ToString(&quot;C&quot;); } private void exitButton_Click(object sender, EventArgs e) { // close application this.Close(); } } </code></pre> <p>The total should only be added once.</p> <p>For instance: if the &quot;oil change&quot; check box is selected, then the total should be $26.</p> <p>if the &quot;lube job&quot; check box is selected, then the total should be $18.</p> <p>And if both check boxes are selected, then the total should be $44.</p> <p>What ends up happening is that after the first check box is selected and the calculate button is clicked, the &quot;total&quot; variable value continues to be added up.</p> <p>So if i select &quot;oil change&quot; then click calculate, I get $26. if I deselect it and select &quot;lube job&quot; the total doesn't equal $18, but $44.</p>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12100422/" ]
74,662,654
<p>I plotted this pairplot correlating only one features with all the others, how can i visualize it in a better way? I need to visualize 4 columns. In the official documentation of pairplot i can't find the option.</p> <p>This is the df: <a href="https://i.stack.imgur.com/6CB4L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CB4L.png" alt="This is the df" /></a></p> <p>This is the part of the code:</p> <pre><code>sns.pairplot(data=dftrain, y_vars=['medv'], x_vars=dftrain.columns[:-1]) </code></pre> <p>This is the plot: <a href="https://i.stack.imgur.com/F3aFh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F3aFh.png" alt="This is the plot" /></a></p>
[ { "answer_id": 74662797, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/gothamnarrow-thin-webfont.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}" }, { "answer_id": 74663161, "author": "Chris Schober", "author_id": 8396541, "author_profile": "https://Stackoverflow.com/users/8396541", "pm_score": 1, "selected": false, "text": "@font-face {\n font-family: 'Poppins';\n font-style: normal;\n font-weight: 300;\n font-display: swap;\n src: url(https://fonts.gstatic.com/s/poppins/v20/pxiByp8kv8JHgFVrLDz8Z1xlFQ.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}" }, { "answer_id": 74672206, "author": "usul93", "author_id": 17768986, "author_profile": "https://Stackoverflow.com/users/17768986", "pm_score": 0, "selected": false, "text": "@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Thin.woff2\") format(\"woff2\");\n font-weight: 100;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Light.woff2\") format(\"woff2\");\n font-weight: 300;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Book.woff2\") format(\"woff2\");\n font-weight: 400;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Medium.woff2\") format(\"woff2\");\n font-weight: 500;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Bold.woff2\") format(\"woff2\");\n font-weight: 700;\n font-style: normal;\n}\n\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Black.woff2\") format(\"woff2\");\n font-weight: 800;\n font-style: normal;\n}\n@font-face {\n font-family: \"Gotham Narrow\";\n src: url(\"../font/GothamNarrow-Ultra.woff2\") format(\"woff2\");\n font-weight: 900;\n font-style: normal;\n}\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662654", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19610821/" ]
74,662,659
<p>I have this pattern thats composed by a quantity, a description and a price. Please not that the numbers and text can change everytime.</p> <p>I need to use powershell to find and save the results. So far I got this... the pattern format is what is driving me crazy.</p> <pre><code>$example_line = '3.00 CEBICHE CORVINA PI 26,805.00' $pattern= '\d.\d\d \D' $results = $example_line | Select-String $pattern -AllMatches $results.Matches.Value </code></pre> <p>Any help is appreciated.</p> <p>Thanks in advance !</p> <p>EDIT. After seeing the answers Im trying regex to build the array.</p> <p>I dont know why its not working for me... Im reading the txt file and I get results, but when I want to see the array I dont get any data in it.</p> <p>So for example Im using this to save all matching lines into the array</p> <blockquote> <p>function pasar_a_word($archivo) {</p> <pre><code>$content = Get-Content $root\UNB\FACTURA_FINAL\$archivo $pattern = '(\d\.\d\d) (\D+?) (\d+,\d\d\d\.\d\d)' Write-Host &quot;FUNCION PASAR A WORD&quot; for($i = 0; $i -lt $content.Count; $i++){ $line = $content[$i] $results = ([regex]::Matches($line, $pattern)).Value } Write-Host $results[1] } </code></pre> </blockquote>
[ { "answer_id": 74662698, "author": "Juan Manuel Sanchez", "author_id": 10415090, "author_profile": "https://Stackoverflow.com/users/10415090", "pm_score": 0, "selected": false, "text": "$pattern= '\\d.\\d\\d \\D* \\d*,\\d*.\\d*'\n" }, { "answer_id": 74664724, "author": "Jona", "author_id": 10730344, "author_profile": "https://Stackoverflow.com/users/10730344", "pm_score": 1, "selected": false, "text": "$example_line = '3.00 CEBICHE CORVINA PI 26,805.00'\n\n# Expression Pattern\n$pattern = '(\\d\\.\\d\\d) (\\D+?) (\\d+,\\d\\d\\d\\.\\d\\d)'\n\n# Use the -match operator to match the string against the pattern\n$match = $example_line -match $pattern\n\n# If the match is successful, extract the three captured groups\nif ($match) {\n $quantity = $matches[1]\n $description = $matches[2]\n $price = $matches[3]\n\n # Print the extracted values\n Write-Output \"Quantity: $quantity\"\n Write-Output \"Description: $description\"\n Write-Output \"Price: $price\"\n}\n" }, { "answer_id": 74677343, "author": "Theo", "author_id": 9898643, "author_profile": "https://Stackoverflow.com/users/9898643", "pm_score": 1, "selected": false, "text": ".Matches() $string = '2.00 CAUSA PERUANA GRAN 32,504.00 1.00 ENSALADA QUINUA 7,309.00'\n$results = ([regex]::Matches($string, '(\\d\\.\\d{2}\\s[\\w\\s]+\\d+,[\\d.]+)')).Value\n\n# $results[0] --> 2.00 CAUSA PERUANA GRAN 32,504.00\n# $results[1] --> 1.00 ENSALADA QUINUA 7,309.00\n" } ]
2022/12/02
[ "https://Stackoverflow.com/questions/74662659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10415090/" ]