qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,292,211
<p>I've got this method:</p> <pre><code>updateDate(row: TaskItem, column: keyof TaskItem, date: string) { row[column] = date; } </code></pre> <p>Where TaskItem looks like this:</p> <pre><code>export interface TaskItem { id: number, myDate: string } </code></pre> <p>And I want to be able to call it like this:</p> <pre><code>updateDate(rowItem, 'myDate', '2022-02-20'); </code></pre> <p>However, TS doesn't like it:</p> <blockquote> <p>Type 'string' is not assignable to type 'never'.ts(2322)</p> </blockquote> <p>It works as soon as I change <code>row: TaskItem</code> to <code>row: any</code>, but I'd like to be more concise.</p>
[ { "answer_id": 74292296, "author": "spender", "author_id": 14357, "author_profile": "https://Stackoverflow.com/users/14357", "pm_score": 2, "selected": false, "text": "obj" }, { "answer_id": 74292449, "author": "kind user", "author_id": 6695924, "author_profile": "https://Stackoverflow.com/users/6695924", "pm_score": 2, "selected": true, "text": "updateDate" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12375822/" ]
74,292,230
<p>I need to add an average trend line to a <code>geom_line</code> line plot in R. The result should be a dotted line on the same chart that that is the average of the values that make up the other lines, like so:</p> <p><a href="https://i.stack.imgur.com/xje0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xje0o.png" alt="enter image description here" /></a></p> <p>Here is my example code to make the chart:</p> <pre><code>df &lt;- data.frame(Name = c(&quot;Jim&quot;,&quot;Bob&quot;,&quot;Sue&quot;,&quot;Sally&quot;,&quot;Jim&quot;,&quot;Bob&quot;,&quot;Sue&quot;,&quot;Sally&quot;,&quot;Jim&quot;,&quot;Bob&quot;,&quot;Sue&quot;,&quot;Sally&quot;), Period = c(&quot;P1&quot;,&quot;P1&quot;,&quot;P1&quot;,&quot;P1&quot;,&quot;P2&quot;,&quot;P2&quot;,&quot;P2&quot;,&quot;P2&quot;,&quot;P3&quot;,&quot;P3&quot;,&quot;P3&quot;,&quot;P3&quot;), Value = c(150, 200, 325, 120, 760,245,46,244,200, 325, 120, 760) ) p&lt;-ggplot(df, aes(x=Period, y=Value, group=Name)) + geom_line(aes(color=Name)) p </code></pre> <p>I tried both solutions offered in a similar question, here - <a href="https://stackoverflow.com/questions/20397959/add-one-mean-trend-line-for-different-lines-in-one-plot">add one mean trend line for different lines in one plot</a></p> <p>But neither even result in a trend line. Examples:</p> <pre><code>p + stat_smooth( aes( y = Value, x = Period), inherit.aes = FALSE ) p + stat_summary(fun.y=mean, geom=&quot;line&quot;) </code></pre>
[ { "answer_id": 74292323, "author": "Quinten", "author_id": 14282714, "author_profile": "https://Stackoverflow.com/users/14282714", "pm_score": 1, "selected": false, "text": "group = 1" }, { "answer_id": 74292407, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 3, "selected": true, "text": "geom_smooth" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11370582/" ]
74,292,295
<p>At the moment I open automatically a new form, loading a chart, make a screenshot only in RAM and sending it to my private chat in telegram. All good so far, but is there a way, to open the form silent (also not shown and not focusing / invisible) and screenshot the silent form?</p> <p>This is atm my code and working fine but without a silent function. anyone can help me?</p> <pre><code>_f2 = new Form2(); _f2.Show(); while(true) { if(Form2Closed == true) { Form2Closed = false; break; } await Task.Delay(1000); } </code></pre> <pre><code>// loading chart stuff var frm = Form2.ActiveForm; using (MemoryStream stream = new MemoryStream()) { using (var bmp = new Bitmap(frm.Width, frm.Height)) { frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); bmp.Save(stream, ImageFormat.Png);// &quot;screenshot.png&quot;); stream.Seek(0, SeekOrigin.Begin); bmp.Dispose(); // sending stuff } } </code></pre>
[ { "answer_id": 74292396, "author": "Skundlony", "author_id": 11350734, "author_profile": "https://Stackoverflow.com/users/11350734", "pm_score": 0, "selected": false, "text": "RenderTargetBitmap.Render" }, { "answer_id": 74292464, "author": "41686d6564 stands w. Palestine", "author_id": 8967612, "author_profile": "https://Stackoverflow.com/users/8967612", "pm_score": 3, "selected": true, "text": "Opacity" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19995120/" ]
74,292,305
<p>My colleague collects data in Google Sheet A. I want to reference and index-match some of that into my sheet B where I track the progress of projects. I've tried two different ways of doing it, and neither of them work for me.</p> <p>Here are the two ways I tried:</p> <ol> <li><p>I created a new tab in sheet B. Then I used importrange to sync with the data from sheet A. Then I used index match to reference the data from the importrange in the same sheet. Indexmatch did not work with the importrange data. Only once I copied and pasted it as values, did the data come over, but that of course broke the live synced importrange.</p> </li> <li><p>I tried to do the <code>indexmatch</code> and <code>importrange</code> at the same time using this formula from this forum:</p> </li> </ol> <pre><code>=INDEX(IMPORTRANGE(&quot;SheetA&quot;,Tab&quot;!A4:H26&quot;),MATCH($Cell,IMPORTRANGE(&quot;SheetA&quot;,Tab&quot;!A4:A26&quot;),0)) </code></pre> <p>But that just gave me an error.</p> <p>Any other ideas on how to approach this?</p>
[ { "answer_id": 74292396, "author": "Skundlony", "author_id": 11350734, "author_profile": "https://Stackoverflow.com/users/11350734", "pm_score": 0, "selected": false, "text": "RenderTargetBitmap.Render" }, { "answer_id": 74292464, "author": "41686d6564 stands w. Palestine", "author_id": 8967612, "author_profile": "https://Stackoverflow.com/users/8967612", "pm_score": 3, "selected": true, "text": "Opacity" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399286/" ]
74,292,315
<p>It's my understanding that tbb may maintain pool threads for reuse... is there a way to ensure that data that I have declared using a modern C++ implementation as <code>thread_local</code> and with a non-trivial (default) constructor and destructor, which is initialized whenever the data is first used from a new thread is destroyed when tbb puts a thread into its pool and constructed again when the thread is pulled out of the pool? I am, as I said, currently just declaring my data as static and using the C++ <code>thread_local</code> specifier.</p> <p>EDIT:</p> <p>Apologies for not spelling this out initially, but an early respondent has made it clear that some assumptions might be made about the code I am hoping to update which are not valid.</p> <ol> <li><p>Refactoring usage of tbb isn't practical, because the code makes heavy use of it already and it is non-trivial to refactor them all, but I will need the threads created by it to still have access to the thread local data.</p> </li> <li><p>A have hidden all access to thread_local data behind a small number of functions, which is what I was ideally hoping to change. Is there some way, perhaps with an additional thread_local value, that I can tell that I'm on a thread that has been reused since the last time the data was accessed? This is actually the ideal solution I would be looking for.</p> </li> <li><p>One major disadvantage I find with refactoring all tbb calls in the application is not so much that there are many of them (although that is certainly a significant factor), but that then I am adding references to thread_local data in every single tbb thread, even if that particular thread did not ever actually need to access it. On systems which delay construction of thread_local data until it is first accessed, this overhead is undesirable. This is why, ideally, I would like to put the logic for it inside of the functions that accesses the thread_local data.</p> </li> </ol>
[ { "answer_id": 74427448, "author": "ANISH SAJI KUMAR", "author_id": 12309235, "author_profile": "https://Stackoverflow.com/users/12309235", "pm_score": 0, "selected": false, "text": "Code: Select all #include <tbb/tbb.h>\n\n#include <iostream>\nint main() {\ntbb::task_scheduler_init init;\ntbb::parallel_for(0, 10, 1, [](int i) {\nstd::cout << \"Thread \" << tbb::this_task_arena::current_thread_index() << \" is running\" << std::endl;\n});\n\ntbb::parallel_for(0, 10, 1, [](int i) {\nstd::cout << \"Thread \" << tbb::this_task_arena::current_thread_index() << \" is running\" << std::endl;\n});\nreturn 0;\n}\n" }, { "answer_id": 74430470, "author": "shy45", "author_id": 20313707, "author_profile": "https://Stackoverflow.com/users/20313707", "pm_score": 2, "selected": true, "text": "#include <ranges>\n#include <tbb/tbb.h>\nusing namespace std;\nusing namespace std::ranges::views;\n\nint main() {\n class A{\n public:\n A(int ctx) : m_ctx(ctx){}\n int m_ctx;\n int m_num = 0;\n };\n thread_local A a(-1); // already existing instance\n\n tbb::parallel_for(0, 7, 1, [](int i) {\n //a = A(i); // re-initialize thread local\n a.m_ctx = i; // not re-initize thread local, only assign context id \n for (auto i : iota(0, 5)) {\n a.m_num++;\n printf(\"ctx=%d count=%d th=%d \\n\", a.m_ctx, a.m_num, tbb::this_task_arena::current_thread_index());\n }\n });\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1672986/" ]
74,292,353
<p>My problem is when I enter a number in the input field, it becomes number with special character. I don't know why it's adding extra characters to input. You can see the example. I entered just 5.2 and it became '5.2&amp;</p> <pre><code>&quot;&quot;&quot; length of rectangle = a width of rectangle = b calculate the area and perimeter of the rectangle &quot;&quot;&quot; a = 6 b = float(input(&quot;width: &quot;)) area = a*b perimeter = (2*a) + (2*b) print(&quot;area: &quot; + str(area) + &quot; perimeter: &quot; + str(perimeter)) </code></pre> <pre><code>File &quot;c:\Users\HP\OneDrive - Karabuk University\Belgeler\Downloads\first.py&quot;, line 8, in &lt;module&gt; b = float(input(&quot;width: &quot;)) ValueError: could not convert string to float: '5.2&amp; </code></pre> <p>Could you please help me?</p>
[ { "answer_id": 74292429, "author": "Bhargav", "author_id": 15358800, "author_profile": "https://Stackoverflow.com/users/15358800", "pm_score": 2, "selected": true, "text": "str" }, { "answer_id": 74293083, "author": "Carl_M", "author_id": 7803702, "author_profile": "https://Stackoverflow.com/users/7803702", "pm_score": 0, "selected": false, "text": "\"\"\"\nlength of rectangle = a\nwidth of rectangle = b\ncalculate the area and perimeter of the rectangle\n\"\"\"\n\n\"\"\"\nWe cannot replicate this error.\nb = float(input(\"width: \"))\nValueError: could not convert string to float: '5.2&\n\nDebug by breaking down the code to see which function is the source of the \nerror.\n\"\"\"\na = 6\n# b = float(input(\"width: \"))\ns = input(\"width: \")\nprint(\"s= \" + s)\nb = float (s)\narea = a*b\nperimeter = (2*a) + (2*b)\n\nprint(\"area: \" + str(area) + \" perimeter: \" + str(perimeter))\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20397073/" ]
74,292,354
<p>I am currently working with SELFIES (self-referencing embedded strings, github : <a href="https://github.com/aspuru-guzik-group/selfies" rel="nofollow noreferrer">https://github.com/aspuru-guzik-group/selfies</a>) which is basically a string representation of a molecule. Basically it is a sequence of tokens that are defined by brackets , e.g. propane would be written as &quot;[C][C][C]&quot;. I would like to find the most efficient way to get a list of tokens like so:</p> <pre><code>selfies= &quot;[C][C][C]&quot; tokens= some_function(selfies) tokens [&quot;[C]&quot;,&quot;[C]&quot;,&quot;[C]&quot;] </code></pre> <p>i already found 3 ways to do it :</p> <ol> <li>with the &quot;native&quot; function from the github (<a href="https://github.com/aspuru-guzik-group/selfies/blob/master/selfies/utils/selfies_utils.py" rel="nofollow noreferrer">https://github.com/aspuru-guzik-group/selfies/blob/master/selfies/utils/selfies_utils.py</a>):</li> </ol> <pre><code>def split_selfies(selfies: str) -&gt; Iterator[str]: &quot;&quot;&quot;Tokenizes a SELFIES string into its individual symbols. :param selfies: a SELFIES string. :return: the symbols of the SELFIES string one-by-one with order preserved. :Example: &gt;&gt;&gt; import selfies as sf &gt;&gt;&gt; list(sf.split_selfies(&quot;[C][=C][F].[C]&quot;)) ['[C]', '[=C]', '[F]', '.', '[C]'] &quot;&quot;&quot; left_idx = selfies.find(&quot;[&quot;) while 0 &lt;= left_idx &lt; len(selfies): right_idx = selfies.find(&quot;]&quot;, left_idx + 1) if right_idx == -1: raise ValueError(&quot;malformed SELFIES string, hanging '[' bracket&quot;) next_symbol = selfies[left_idx: right_idx + 1] yield next_symbol left_idx = right_idx + 1 if selfies[left_idx: left_idx + 1] == &quot;.&quot;: yield &quot;.&quot; left_idx += 1 %%timeit tokens= list(sf.split_selfies(selfies)) 3.41 µs ± 22.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) </code></pre> <p>Edit: &quot;.&quot; is never present in my case and it is not considered in solution 2 and 3 for speed's sake</p> <p>This is kinda slow probably because of the conversion to a list</p> <ol start="2"> <li>One from the creator of the library (<a href="https://github.com/aspuru-guzik-group/stoned-selfies/blob/main/GA_rediscover.py" rel="nofollow noreferrer">https://github.com/aspuru-guzik-group/stoned-selfies/blob/main/GA_rediscover.py</a>) :</li> </ol> <pre><code>def get_selfie_chars(selfies): '''Obtain a list of all selfie characters in string selfie Parameters: selfie (string) : A selfie string - representing a molecule Example: &gt;&gt;&gt; get_selfie_chars('[C][=C][C][=C][C][=C][Ring1][Branch1_1]') ['[C]', '[=C]', '[C]', '[=C]', '[C]', '[=C]', '[Ring1]', '[Branch1_1]'] Returns: chars_selfie: list of selfie characters present in molecule selfie ''' chars_selfie = [] # A list of all SELFIE sybols from string selfie while selfie != '': chars_selfie.append(selfie[selfie.find('['): selfie.find(']')+1]) selfie = selfie[selfie.find(']')+1:] return chars_selfie %%timeit tokens= get_selfie_chars(selfies) 3.44 µs ± 43.9 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) </code></pre> <p>Which surprisingly take the same amount of time roughly that the native function</p> <ol start="3"> <li>My implementation with a combinaison of list comprehension,slicing and .split()</li> </ol> <pre><code>def selfies_split(selfies): return [block+&quot;]&quot; for block in selfies.split(&quot;]&quot;)][:-1] %%timeit tokens=selfies_split(selfies) 1.05 µs ± 53.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) </code></pre> <p>My implementation is roughly 3 fold faster but I recon that the most efficient way to tokenize is probably to use regex with the package re but i have never used it and i am not particularly confortable with regex. So I fail to see how to implement it in way that yield the best results.</p> <p>Edit:</p> <ol start="4"> <li>Suggested from answers:</li> </ol> <pre><code>def stackoverflow_1_split(selfies): atoms = selfies[1:-1].replace('][', &quot;$&quot;).split(&quot;$&quot;) return list(map('[{}]'.format, atoms)) %%timeit tokens=stackoverflow_1_split(selfies) 1.75 µs ± 101 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) </code></pre> <p>Without the list conversion , it is actually faster then my implementation ( 575 ns +/- 10 ns) but the list is a requirement</p> <ol start="5"> <li>Second suggestion from answers:</li> </ol> <pre><code>import re def stackoverflow_2_split(selfies): return re.findall(r&quot;.*?]&quot;, selfies) %%timeit tokens=stackoverflow_2_split(selfies) 1.81 µs ± 110 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) </code></pre> <p>Surprisingly re does not seem to outperform other solutions</p> <ol start="5"> <li>third suggestion from answers :</li> </ol> <pre><code>def stackoverflow_3_split(selfies): return selfies.replace(']', '] ').split() %%timeit tokens=stackoverflow_3_split(selfies) 485 ns ± 4.04 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) </code></pre> <p>This is the fastest solution so far , which is roughly 2 time faster then my implementation, Well done Kelly!</p>
[ { "answer_id": 74292939, "author": "keepAlive", "author_id": 4194079, "author_profile": "https://Stackoverflow.com/users/4194079", "pm_score": 0, "selected": false, "text": ">>> atoms = selfies[1:-1].split('][')\n>>> atoms\n[\"C\",\"C\",\"C\"]\n" }, { "answer_id": 74293137, "author": "trincot", "author_id": 5459839, "author_profile": "https://Stackoverflow.com/users/5459839", "pm_score": 1, "selected": false, "text": "import re\n\ndef get_selfie_chars(selfie):\n return re.findall(r\".*?]\", selfie)\n" }, { "answer_id": 74293423, "author": "Kelly Bundy", "author_id": 12671057, "author_profile": "https://Stackoverflow.com/users/12671057", "pm_score": 2, "selected": true, "text": "selfies.replace(']', '] ').split()\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19860082/" ]
74,292,356
<p>I am looking to use Regex to find all instances of a certain letter in a given string, but NOT if that letter appears in a larger word/phrase. For example:</p> <p>For test string:</p> <blockquote> <p>lag(a,1) + 252*a + max(3a*2) / 5*pctrange(a,10)</p> </blockquote> <p>I want to obtain all instances of the letter 'a' excluding the letter 'a' that appears in the following three words:</p> <blockquote> <p>lag max pctrange</p> </blockquote> <p>i.e. I would like to use Regex to get all instances of the letter 'a' as highlighted here:</p> <blockquote> <p>lag(<strong>a</strong>,1) + 252*<strong>a</strong> + max(3<strong>a</strong>*2) / 5*pctrange(<strong>a</strong>,10)</p> </blockquote> <p>I attempted to use the following Regex but it keeps including the character <em>after</em> my desired letter 'a':</p> <pre><code>a[^&quot;lag|max|pctrange&quot;] </code></pre> <p>To provide some context, I'm in Python looking to replace these 'a' instances using the re module:</p> <pre><code>import re string = &quot;lag(a,1) + 252*a + max(3a*2) / 5*pctrange(a,10)&quot; words = [&quot;lag&quot;, &quot;max&quot;, &quot;pctrange&quot;] replace = &quot;_&quot; re.sub(f&quot;a[^\&quot;{'|'.join(words)}\&quot;]&quot;, replace, string) </code></pre> <p>This results in the (undesired) output:</p> <pre><code>lag(_1) + 252*_+ max(3_2) / 5*pctrange(_10) </code></pre> <p>I would like instead for the output to be the following:</p> <pre><code>lag(_,1) + 252*_ + max(3_*2) / 5*pctrange(_,10) </code></pre> <p>Edit: Note that the search isn't always for a single letter, for example sometimes I want to search for &quot;aa&quot; instead of &quot;a&quot;, or &quot;bdg&quot; instead of &quot;a&quot; etc. It's more important to focus on the list of words to be excluded (e.g. in the above example, &quot;lag&quot; &quot;max&quot; and &quot;pctrange&quot;).. I don't need to ignore anything other than the specific words that show up in this list. Thank you.</p>
[ { "answer_id": 74292681, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 2, "selected": false, "text": "(?<=\\d)a\\b|\\ba\\b\n" }, { "answer_id": 74293577, "author": "bobble bubble", "author_id": 5527985, "author_profile": "https://Stackoverflow.com/users/5527985", "pm_score": 3, "selected": true, "text": "a" }, { "answer_id": 74301660, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 1, "selected": false, "text": "[a-z]++(?<!lag|pctrange|max)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19727988/" ]
74,292,378
<p>I am trying to extract data from a column and apply filter for the same. Below is the scenario.</p> <p>As shown in below screenshot, a <code>serviceId</code> can have multiple <code>userRoleId</code> assigned to it. 0 or more <code>userRoleId</code> are stored in a single column <code>userRoleIds</code> as string value. I am trying to write a lambda expression to filter information when I select one or more <code>userRoleId</code>.</p> <p><a href="https://i.stack.imgur.com/k2ms0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k2ms0.png" alt="enter image description here" /></a></p> <p>Let's say, if I pass user id 1,4,11,9 as a list, then it should return the following rows:</p> <p><a href="https://i.stack.imgur.com/CgvZI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CgvZI.png" alt="enter image description here" /></a></p> <p>Could you please share code snippet to achieve this in a single query without duplication records. Thanks in advance.</p> <p>Tried to implement the logic with SQL UDFs. Was able to achieve it. But required to do it from LINQ lambda expression.</p>
[ { "answer_id": 74292681, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 2, "selected": false, "text": "(?<=\\d)a\\b|\\ba\\b\n" }, { "answer_id": 74293577, "author": "bobble bubble", "author_id": 5527985, "author_profile": "https://Stackoverflow.com/users/5527985", "pm_score": 3, "selected": true, "text": "a" }, { "answer_id": 74301660, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 1, "selected": false, "text": "[a-z]++(?<!lag|pctrange|max)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7088612/" ]
74,292,386
<p>I am relatively new to web development and very new to using Web2py. The application I am currently working on is intended to take in a CSV upload from a user, then generate a PDF file based on the contents of the CSV, then allow the user to download that PDF. As part of this process I need to generate and access several intermediate files that are specific to each individual user (these files would be images, other pdfs, and some text files). I don't need to store these files in a database since they can be deleted after the session ends, but I am not sure the best way or place to store these files and keep them separate based on each session. I thought that maybe the subfolders in the <code>sessions</code> folder would make sense, but I do not know how to dynamically get the path to the correct folder for the current session. Any suggestions pointing me in the right direction are appreciated!</p>
[ { "answer_id": 74292681, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 2, "selected": false, "text": "(?<=\\d)a\\b|\\ba\\b\n" }, { "answer_id": 74293577, "author": "bobble bubble", "author_id": 5527985, "author_profile": "https://Stackoverflow.com/users/5527985", "pm_score": 3, "selected": true, "text": "a" }, { "answer_id": 74301660, "author": "Cristiano Schiaffella", "author_id": 9395753, "author_profile": "https://Stackoverflow.com/users/9395753", "pm_score": 1, "selected": false, "text": "[a-z]++(?<!lag|pctrange|max)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10941956/" ]
74,292,401
<p>I got a message from Microsoft in the last few days</p> <blockquote> <p>Azure SQL Database 2014-04-01 APIs will be retired on 31 October 2025.</p> <p><strong>You're receiving this email because you use Azure SQL Database APIs.</strong></p> <p>To improve performance and security, we're updating Azure SQL Database APIs. As part of this, all version 2014-04-01 APIs will be retired on 31 October 2025. You'll need to update your resources, including templates, tools, scripts, and programs, to use a newer API version by then. Any API calls still using the older versions after that date will stop working until you've updated them.</p> </blockquote> <p>I access my Azure SQL Databases in the following manner.</p> <ol> <li><p>From the WebApp via a Java connection and an ODBC driver</p> <pre><code>public final class DBConnection { private static DataSource ds = null; private static DBConnection instance = null; private DBConnection() throws NamingException { InitialContext ic = new InitialContext(); ds = (DataSource) ic.lookup(Monitor.getDsName()); } &lt;dependency&gt; &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt; &lt;artifactId&gt;mssql-jdbc&lt;/artifactId&gt; &lt;version&gt;10.2.1.jre11&lt;/version&gt; &lt;/dependency&gt; </code></pre> </li> <li><p>via <code>sqlcmd</code></p> </li> <li><p>via <code>node.js</code></p> <pre><code> const configDB = { user: &quot;&quot;, password: &quot;&quot;, server: &quot;myserver.database.windows.net&quot;, database: &quot;mydb&quot;, connectionTimeout: 3000, parseJSON: true, options: { encrypt: true, enableArithAbort: true }, pool: { min: 0, idleTimeoutMillis: 3000 } }; const poolDB = new sql.ConnectionPool(configDB); aLine='EXEC ...' await poolFOI.connect(); let resultDB = await poolDB.request().query(aLine); </code></pre> </li> <li><p>Via <code>Azure Logic Apps</code> (using an API Connections)</p> </li> <li><p>Via <code>Azure Function Apps</code> (connecting similar to the WebApp Above)</p> </li> <li><p>Via <code>SSMS</code></p> </li> </ol> <p>Which of these are possibly triggering the message about Azure SQL Database APIs? Also I started using Azure after 2020, so it does not make sense to me that I would be using APIs from 2014</p>
[ { "answer_id": 74292597, "author": "Stephen Cleary", "author_id": 263693, "author_profile": "https://Stackoverflow.com/users/263693", "pm_score": 1, "selected": false, "text": "2014-04-01" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/757661/" ]
74,292,410
<p>I am trying to remove the {} from the series ID.</p> <pre><code> &quot;seriesID&quot; : &quot;CUUR0000SA0&quot; }, { &quot;seriesID&quot; : &quot;CUSR0000SA0&quot; }, { &quot;seriesID&quot; : &quot;LNS14000000&quot; }, { &quot;seriesID&quot; : &quot;CES0000000001&quot; }, { &quot;seriesID&quot; : &quot;CUUR0000SA0L1E&quot; }, { &quot;seriesID&quot; : &quot;CES0500000003&quot; }, { &quot;seriesID&quot; : &quot;WPUFD4&quot; }, { &quot;seriesID&quot; : &quot;LNS12000000&quot; }, { &quot;seriesID&quot; : &quot;WPSFD4&quot; }, { &quot;seriesID&quot; : &quot;CUSR0000SA0L1E&quot; }, { &quot;seriesID&quot; : &quot;WPUFD49104&quot; }, { &quot;seriesID&quot; : &quot;WPSFD49104&quot; }, { &quot;seriesID&quot; : &quot;LNS13000000&quot; }, { &quot;seriesID&quot; : &quot;LNS11300000&quot; }, { </code></pre> <p>i tried using a jolt and a replace text in NIFI but i am not able to remove these brackets, anything helps</p>
[ { "answer_id": 74292597, "author": "Stephen Cleary", "author_id": 263693, "author_profile": "https://Stackoverflow.com/users/263693", "pm_score": 1, "selected": false, "text": "2014-04-01" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399578/" ]
74,292,421
<p>I'm still new in Swift development and I'm wondering how can I call This function with the status and results?</p> <pre><code> func getStatus(completion: @escaping (Swift.Result&lt;SubscriptionStatus, MAPIError&gt;) -&gt; Void ) { getStatus { result in switch(result) { case .success(let subscription): switch(subscription.status) { case .subscribed: completion(.success(true)) default: completion(.success(false)) } case .failure(let error): completion(.failure(error)) } } } </code></pre> <p>Many Thanks</p> <p>Calling the function</p>
[ { "answer_id": 74292539, "author": "alessandro_minopoli", "author_id": 3526925, "author_profile": "https://Stackoverflow.com/users/3526925", "pm_score": 1, "selected": false, "text": "completion(.success(value))" }, { "answer_id": 74295221, "author": "manubrio", "author_id": 14055712, "author_profile": "https://Stackoverflow.com/users/14055712", "pm_score": 0, "selected": false, "text": "completion(.success(SubscriptionStatusValue))\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399588/" ]
74,292,431
<p>I am creating an app using React Native in JavaScript.</p> <p>I have this code.</p> <pre><code> let ScoretoStore = (parseInt(TeamAShot) + &quot;A&quot;) if (End === 2){ updateScores(ID,found.ScoreEnd1,ScoretoStore) } else if (End === 3){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,ScoretoStore) } else if (End === 4){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,ScoretoStore) } else if (End === 5){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,ScoretoStore) } else if (End === 6){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5,ScoretoStore) } else if (End === 7){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,ScoretoStore) } else if (End === 8){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,ScoretoStore) } else if (End === 9){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,ScoretoStore) } else if (End === 10){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,ScoretoStore) } else if (End === 11){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10,ScoretoStore) } else if (End === 12){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,ScoretoStore) } else if (End === 13){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,ScoretoStore) } else if (End === 14){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,ScoretoStore) } else if (End === 15){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14,ScoretoStore) } else if (End === 16){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,ScoretoStore) } else if (End === 17){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,ScoretoStore) } else if (End === 18){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,ScoretoStore) } else if (End === 19){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,ScoretoStore) } else if (End === 20){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19,ScoretoStore) } else if (End === 21){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,ScoretoStore) } else if (End === 22){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,ScoretoStore) } else if (End === 23){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,ScoretoStore) } else if (End === 24){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,ScoretoStore) } else if (End === 25){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,ScoretoStore) } else if (End === 26){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,found.ScoreEnd25,ScoretoStore) } else if (End === 27){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,found.ScoreEnd25, found.ScoreEnd26,ScoretoStore) } else if (End === 28){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,found.ScoreEnd25, found.ScoreEnd26,found.ScoreEnd27,ScoretoStore) } else if (End === 29){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,found.ScoreEnd25, found.ScoreEnd26,found.ScoreEnd27,found.ScoreEnd28,ScoretoStore) } else if (End === 30){ updateScores(ID,found.ScoreEnd1,found.ScoreEnd2,found.ScoreEnd3,found.ScoreEnd4,found.ScoreEnd5, found.ScoreEnd6,found.ScoreEnd7,found.ScoreEnd8,found.ScoreEnd9,found.ScoreEnd10, found.ScoreEnd11,found.ScoreEnd12,found.ScoreEnd13,found.ScoreEnd14, found.ScoreEnd15,found.ScoreEnd16,found.ScoreEnd17,found.ScoreEnd18,found.ScoreEnd19, found.ScoreEnd20,found.ScoreEnd21,found.ScoreEnd22,found.ScoreEnd23,found.ScoreEnd24,found.ScoreEnd25, found.ScoreEnd26,found.ScoreEnd27,found.ScoreEnd28,found.ScoreEnd29,ScoretoStore) </code></pre> <p>I don't think further context is needed, but if it is required, please let me know. How do I clean it up. By that I mean how do I use loops to turn this into maybe a 10 lines piece of code. An exact answer would be appreciated, because I have already tried solving it myself.</p> <p>Alright, some more context. The &quot;End&quot; here is referring to round. Like a round in a game. &quot;found&quot; comes from this:</p> <pre><code>const found = ScoresState.find(obj =&gt; { return obj.id === ID; }); </code></pre> <p>And here is the ScoresState array in item context.</p> <pre><code>const ScoresReducer = (ScoresState,ScoresAction) =&gt; { switch(ScoresAction.type){ case actionTypes.createScores: return [ ...ScoresState, { id: ID, ScoreEnd1: ScoresAction.payload.ScoreEnd1, ScoreEnd2: ScoresAction.payload.ScoreEnd2, ScoreEnd3: ScoresAction.payload.ScoreEnd3, ScoreEnd4: ScoresAction.payload.ScoreEnd4, ScoreEnd5: ScoresAction.payload.ScoreEnd5, ScoreEnd6: ScoresAction.payload.ScoreEnd6, ScoreEnd7: ScoresAction.payload.ScoreEnd7, ScoreEnd8: ScoresAction.payload.ScoreEnd8, ScoreEnd9: ScoresAction.payload.ScoreEnd9, ScoreEnd10: ScoresAction.payload.ScoreEnd10, ScoreEnd11: ScoresAction.payload.ScoreEnd11, ScoreEnd12: ScoresAction.payload.ScoreEnd12, ScoreEnd13: ScoresAction.payload.ScoreEnd13, ScoreEnd14: ScoresAction.payload.ScoreEnd14, ScoreEnd15: ScoresAction.payload.ScoreEnd15, ScoreEnd16: ScoresAction.payload.ScoreEnd16, ScoreEnd17: ScoresAction.payload.ScoreEnd17, ScoreEnd18: ScoresAction.payload.ScoreEnd18, ScoreEnd19: ScoresAction.payload.ScoreEnd19, ScoreEnd20: ScoresAction.payload.ScoreEnd20, ScoreEnd21: ScoresAction.payload.ScoreEnd21, ScoreEnd22: ScoresAction.payload.ScoreEnd22, ScoreEnd23: ScoresAction.payload.ScoreEnd23, ScoreEnd24: ScoresAction.payload.ScoreEnd24, ScoreEnd25: ScoresAction.payload.ScoreEnd25, ScoreEnd26: ScoresAction.payload.ScoreEnd26, ScoreEnd27: ScoresAction.payload.ScoreEnd27, ScoreEnd28: ScoresAction.payload.ScoreEnd28, ScoreEnd29: ScoresAction.payload.ScoreEnd29, ScoreEnd30: ScoresAction.payload.ScoreEnd30, } ]; case actionTypes.updateScores: return ScoresState.map((e) =&gt; { if (e.id === ScoresAction.payload.id){ return ScoresAction.payload; } else { return e; } }); default: return ScoresState; }; }; </code></pre> <p>Here is the updateScores function.</p> <pre><code>const updateScores = (id,ScoreEnd1,ScoreEnd2,ScoreEnd3,ScoreEnd4,ScoreEnd5,ScoreEnd6,ScoreEnd7,ScoreEnd8,ScoreEnd9,ScoreEnd10, ScoreEnd11,ScoreEnd12,ScoreEnd13,ScoreEnd14,ScoreEnd15,ScoreEnd16,ScoreEnd17,ScoreEnd18,ScoreEnd19,ScoreEnd20,ScoreEnd21,ScoreEnd22,ScoreEnd23, ScoreEnd24,ScoreEnd25,ScoreEnd26,ScoreEnd27,ScoreEnd28,ScoreEnd29,ScoreEnd30,callback) =&gt; { dispatchSE({type: actionTypes.updateScores, payload:{id,ScoreEnd1,ScoreEnd2,ScoreEnd3,ScoreEnd4,ScoreEnd5,ScoreEnd6,ScoreEnd7,ScoreEnd8,ScoreEnd9,ScoreEnd10, ScoreEnd11,ScoreEnd12,ScoreEnd13,ScoreEnd14,ScoreEnd15,ScoreEnd16,ScoreEnd17,ScoreEnd18,ScoreEnd19,ScoreEnd20,ScoreEnd21,ScoreEnd22,ScoreEnd23, ScoreEnd24,ScoreEnd25,ScoreEnd26,ScoreEnd27,ScoreEnd28,ScoreEnd29,ScoreEnd30}}); if (callback) callback(); }; </code></pre> <p>I would also like to mention the code works perfectly fine as is.</p>
[ { "answer_id": 74292486, "author": "CertainPerformance", "author_id": 9515207, "author_profile": "https://Stackoverflow.com/users/9515207", "pm_score": 3, "selected": true, "text": "found" }, { "answer_id": 74292494, "author": "Dr. Vortex", "author_id": 17637456, "author_profile": "https://Stackoverflow.com/users/17637456", "pm_score": 0, "selected": false, "text": "found.ScoreEndN" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17143446/" ]
74,292,471
<p>I am trying to remove digits from an elements that are located from child elements. Can anyone help with with the xslt needed for this? Here is an example that should remove &quot;_0&quot; from the element &quot;mgt_interface_0&quot; . Thanks in advance!</p> <p>Piece from source XML:</p> <pre><code>&lt;mgt_interfaces dataType=&quot;fXml&quot;&gt; &lt;number_of_mgt_interfaces dataType=&quot;fInt&quot;&gt;1&lt;/number_of_mgt_interfaces&gt; &lt;mgt_interface_0 dataType=&quot;fXml&quot; modelIndex=&quot;0&quot;&gt; &lt;ip_address dataType=&quot;fSting&quot;&gt;###.##.###.###&lt;/ip_address&gt; &lt;name dataType=&quot;fString&quot;&gt;Port&lt;/name&gt; &lt;netmask dataType=&quot;fString&quot;&gt;###.###.###.###&lt;/netmask&gt; &lt;gateway dataType=&quot;fString&quot;&gt;###.##.###.###&lt;/gateway&gt; &lt;mac_address dataType=&quot;fString&quot;&gt;##:##:##:##:##:##&lt;/mac_address&gt; &lt;state dataType=&quot;fString&quot;&gt;Enabled&lt;/state&gt; &lt;/mgt_interface_0&gt; Output XML: &lt;mgt_interfaces dataType=&quot;fXml&quot;&gt; &lt;number_of_mgt_interfaces dataType=&quot;fInt&quot;&gt;1&lt;/number_of_mgt_interfaces&gt; &lt;mgt_interface dataType=&quot;fXml&quot; modelIndex=&quot;0&quot;&gt; &lt;ip_address dataType=&quot;fSting&quot;&gt;###.##.###.###&lt;/ip_address&gt; &lt;name dataType=&quot;fString&quot;&gt;Port&lt;/name&gt; &lt;netmask dataType=&quot;fString&quot;&gt;###.###.###.###&lt;/netmask&gt; &lt;gateway dataType=&quot;fString&quot;&gt;###.##.###.###&lt;/gateway&gt; &lt;mac_address dataType=&quot;fString&quot;&gt;##:##:##:##:##:##&lt;/mac_address&gt; &lt;state dataType=&quot;fString&quot;&gt;Enabled&lt;/state&gt; &lt;/mgt_interface_0&gt; </code></pre> <p>I do not have much experience in XSLT so I need some help and suggestions. Thanks!</p>
[ { "answer_id": 74292486, "author": "CertainPerformance", "author_id": 9515207, "author_profile": "https://Stackoverflow.com/users/9515207", "pm_score": 3, "selected": true, "text": "found" }, { "answer_id": 74292494, "author": "Dr. Vortex", "author_id": 17637456, "author_profile": "https://Stackoverflow.com/users/17637456", "pm_score": 0, "selected": false, "text": "found.ScoreEndN" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19349059/" ]
74,292,474
<p>I'm attempting to filter a Map using a stream. The predicate/condition I'm filtering by is another stream. I'm currently encountering the issue of IllegalStateException, probably because I'm accessing a stream which has already been accessed.</p> <pre><code>Map&lt;Integer, Double&gt; table = Map.of(10, 8.0, 15, 10.0, 20, 28.0, 40, 40.0); Stream&lt;Double&gt; streamDbl = getDoublefromInt(table, Stream.of(20, 40)); </code></pre> <p>Referencing <a href="https://www.baeldung.com/java-streams-find-list-items" rel="nofollow noreferrer">this</a> website, I came up with something like the code segment below but it does not work.</p> <pre><code>public static Stream&lt;Double&gt; getDoublefromInt(Map&lt;Integer, Double&gt; table, Stream&lt;Integer&gt; id) { return table.entrySet().stream .filter(map -&gt; id.anyMatch(id -&gt; id.equals(map.getKey()))) .map(map -&gt; map.getValue()); } </code></pre>
[ { "answer_id": 74292671, "author": "Arvind Kumar Avinash", "author_id": 10819573, "author_profile": "https://Stackoverflow.com/users/10819573", "pm_score": 0, "selected": false, "text": "Supplier" }, { "answer_id": 74292674, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 1, "selected": false, "text": "IllegalStateException" }, { "answer_id": 74292745, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 0, "selected": false, "text": "Stream" }, { "answer_id": 74292779, "author": "chptr-one", "author_id": 13797513, "author_profile": "https://Stackoverflow.com/users/13797513", "pm_score": 0, "selected": false, "text": "public class Main {\n static Map<Integer, Double> table = Map.of(10, 8.0,\n 15, 10.0,\n 20, 28.0,\n 40, 40.0);\n\n public static Stream<Double> getDoubleFromInt(Map<Integer, Double> table, Stream<Integer> id) {\n return id.map(table::get);\n }\n\n public static void main(String[] args) {\n getDoubleFromInt(table, Stream.of(20, 40))\n .forEach(System.out::println);\n }\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292474", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9203056/" ]
74,292,478
<p>I've got a script displaying multiple words stored in a text array in some sort of typewriter style. However, the script stops after a few entries and does not run through all the words in the array as supposed to. Maybe I can't see the obvious issue, but please, can I get a hint?</p> <p>Here's a pen of it: <a href="https://codepen.io/jackennils/pen/KKeVEbJ" rel="nofollow noreferrer">https://codepen.io/jackennils/pen/KKeVEbJ</a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>document.addEventListener('DOMContentLoaded', function(event) { // array with texts to type in typewriter var dataText = ["Holz", "Schiefer", "Jeans", "Edelstahl", "Spiegel", "Acryl", "Leder", "Kork", "Fliesen", "Stein"]; // type one text in the typwriter // keeps calling itself until the text is finished function typeWriter(text, i, fnCallback) { // check if text isn't finished yet if (i &lt; (text.length)) { // add next character to span document.querySelector("span.mats").innerHTML = text.substring(0, i + 1) + '&lt;span class="mats-inner" aria-hidden="true"&gt;&lt;/span&gt;'; // wait for a while and call this function again for next character setTimeout(function() { typeWriter(text, i + 1, fnCallback) }, 100); } // text finished, call callback if there is a callback function else if (typeof fnCallback == 'function') { // call callback after timeout setTimeout(fnCallback, 1000); } } // start a typewriter animation for a text in the dataText array function StartTextAnimation(i) { if (typeof dataText[i] == 'undefined') { setTimeout(function() { StartTextAnimation(0); }, 0); } // check if dataText[i] exists if (i &lt; dataText[i].length) { // text exists! start typewriter animation typeWriter(dataText[i], 0, function() { // after callback (and whole text has been animated), start next text StartTextAnimation(i + 1); }); } } // start the text animation StartTextAnimation(0); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { background-color: #362871; height: 100%; font-family: 'Raleway', sans-serif; } p { font-size: 5em; color: white; text-transform: uppercase; } span.mats-inner { border-right: 20px solid; margin-left: 10px; animation: caret 1s steps(1) infinite; } @keyframes caret { 50% { border-color: transparent; } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p&gt;Wir veredeln &lt;span class="mats"&gt;mit Licht&lt;/span&gt;&lt;/p&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74292595, "author": "Maheer Ali", "author_id": 9819146, "author_profile": "https://Stackoverflow.com/users/9819146", "pm_score": 3, "selected": true, "text": "if" }, { "answer_id": 74293052, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": 0, "selected": false, "text": "if" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3645500/" ]
74,292,492
<p>I fetched the amount from firestore, And in the UI has text field user can add value to that text field that also string I want summation both that &quot;(oneAmount?.amount)! + (amountController.text)&quot;</p> <p>code</p> <pre><code>void displayMessage() { if (amountController.text != null) { int amount = ((oneAmount?.amount)! + (amountController.text)) as int; FirebaseFirestore.instance .collection(&quot;recharge&quot;) .doc(&quot;${loggedInUser.uid}&quot;) .set({ &quot;amount&quot;: amount, }); Navigator.push( context, MaterialPageRoute(builder: (context) =&gt; const HomeScreen()), ); } else {} } </code></pre>
[ { "answer_id": 74292595, "author": "Maheer Ali", "author_id": 9819146, "author_profile": "https://Stackoverflow.com/users/9819146", "pm_score": 3, "selected": true, "text": "if" }, { "answer_id": 74293052, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": 0, "selected": false, "text": "if" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292492", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20000775/" ]
74,292,503
<p>I was asked to make a modal disappear onScroll. Which I achieved but upon code review I was told that the code should only run once and that I shouldn't add event listeners. I'm beyond confused, Any help would be appreciated.</p> <pre><code>useEffect(() =&gt; { const handleScroll = () =&gt; { return selectEntryGroup(undefined); //setting selectEntryGroup to undefined will kill the modal }; window.addEventListener('scroll', handleScroll); return () =&gt; { window.removeEventListener('scroll', handleScroll); //cleanup function }; }, []); </code></pre> <p>When I run this code the modal disappears as expected but when I add a console log inside my handleScroll function it does indeed run even when no modal is present. This I understand.</p> <p>My thinking is that if I add a condition checking if the modal is open then I could have the function only run once.</p> <p>However, I created a piece of state (popup, setPopup)that defaults to &quot;false&quot;, that is plugged in to the onClick that makes the modal open up. When I console log popup it changes to true based on the onClick but the modal doesn't disappear.</p> <p>Here's my code with the condition.</p> <p>`</p> <pre><code> useEffect(() =&gt; { if(popup === true){ const handleScroll = () =&gt; { selectEntryGroup(undefined); console.log(&quot;FIRED!&quot;) return }; window.addEventListener('scroll', handleScroll); return () =&gt; { window.removeEventListener('scroll', handleScroll); //cleanup function }; }else{ console.log(&quot;Didn't Work!&quot;) } }, []); </code></pre> <p>Any ideas?</p>
[ { "answer_id": 74292595, "author": "Maheer Ali", "author_id": 9819146, "author_profile": "https://Stackoverflow.com/users/9819146", "pm_score": 3, "selected": true, "text": "if" }, { "answer_id": 74293052, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": 0, "selected": false, "text": "if" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4580771/" ]
74,292,510
<p>I've been spending a few days trying to figure out how best to build a Python Lambda bundle when using Poetry. I found a few blogs that that outline the same technique but those didn't work in my situation. The solution provided in the blogs is to use <code>pip install</code> to install the needed dependencies into a specific directory and zip it up.</p> <pre><code>poetry run pip install -t dist/lambda . cd dist/lambda zip -r ../lambda.zip . </code></pre> <p>However, this doesn't work if you use <a href="https://python-poetry.org/docs/dependency-specification/#path-dependencies" rel="nofollow noreferrer">path dependencies</a> with Poetry. You get an error from pip stating <code>pip._vendor.pkg_resources.RequirementParseError: Invalid URL: </code> for any local dependency.</p> <p>I did run into the <a href="https://github.com/python-poetry/poetry-plugin-bundle" rel="nofollow noreferrer">Poetry Bundle Plugin</a> and it looked promising. Using it did work in that it installed the needed dependencies and the project itself into the chosen target directory.</p> <pre><code>poetry self add poetry-plugin-bundle poetry bundle venv .venv-lambda cd .venv-lambda/lib/python*/site-packages/ zip -r ../../../../dist/lambda.zip . </code></pre> <p>The problem with this approach is that it installs more than just the mainline dependencies, but also the <code>dev</code> and <code>test</code> dependencies. There is no option to specify which dependency group to include or exclude. There is an <a href="https://github.com/python-poetry/poetry-plugin-bundle/issues/8" rel="nofollow noreferrer">open issue</a> with a PR that is waiting to be merged to resolve this. Once that is resolved, this is likely the ideal solution.</p> <p>Until then, I need something different/better.</p>
[ { "answer_id": 74292595, "author": "Maheer Ali", "author_id": 9819146, "author_profile": "https://Stackoverflow.com/users/9819146", "pm_score": 3, "selected": true, "text": "if" }, { "answer_id": 74293052, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": 0, "selected": false, "text": "if" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1144086/" ]
74,292,519
<p>I created keras model and fitted it on some part of training set with validation data. Then i was satisfied with model accuracy and i want to fit it on validation set as well for maximum performance on test data. How should i do that?</p> <p>I have some guesses:</p> <ol> <li>Fit model with only validation set <code>model.fit(val_ds)</code></li> <li>Fit model with full data (train + validation) <code>model.fit(full_ds)</code></li> </ol>
[ { "answer_id": 74310700, "author": "Gerry P", "author_id": 10798917, "author_profile": "https://Stackoverflow.com/users/10798917", "pm_score": 0, "selected": false, "text": "1 - add one or more drop out layers in your model\n2 - use kernel regularizers\n3 - use an adjustable larning like keras reduce learning rate on plateau\n4 - use keras callback early stopping \n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292519", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19822348/" ]
74,292,526
<p>is there a way to customize the dart/flutter formatter for VSCode?</p> <p>The new way of formatting is terribly unreadable!</p> <p><a href="https://i.stack.imgur.com/OAnXF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OAnXF.png" alt="Terrible" /></a></p> <p>How am i supposed to find brackets if they don't respect the indentation level?</p> <p>I would like to have something like this:</p> <p><a href="https://i.stack.imgur.com/RGWn9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RGWn9.png" alt="Ordered" /></a></p> <p>As you can see here you can follow the column to find where the closure ends.</p> <p>I wonder if there is a way to customize the dart formatting.</p> <p>Thank you in advance.</p>
[ { "answer_id": 74292626, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 2, "selected": true, "text": "," }, { "answer_id": 74292628, "author": "Dani3le_", "author_id": 11442598, "author_profile": "https://Stackoverflow.com/users/11442598", "pm_score": 2, "selected": false, "text": "CTRL + ," } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2429576/" ]
74,292,532
<p>I have a table that includes a column that includes a dictionary. In this dictionary, there is a key, and a list of dictionary values as follow:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>id</th> <th>dict_vals</th> </tr> </thead> <tbody> <tr> <td>123</td> <td>{'key_a':[{'a':1,'b':8,'c':7},{'a':14,'b':6,'c':8},{'a':9,'b':4,'c':9},...,{'a_t':67,'b_t':41,'c_t':6}]}</td> </tr> <tr> <td>345</td> <td>{'key_a':[{'a':5,'b':82,'c':72},{'a':4,'b':64,'c':81},{'a':5,'b':3,'c':6},...{'a_t':34,'b_t':23,'c_t':}]}</td> </tr> </tbody> </table> </div> <p>Inside the nested dictionary list of values, all the keys are the same, expect for the last dictionary (e.g., a_t, b_t...). What I am trying to do, is to drop the last dictionary and convert everything else to column as the following:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>id</th> <th>a</th> <th>b</th> <th>c</th> </tr> </thead> <tbody> <tr> <td>123</td> <td>1</td> <td>8</td> <td>7</td> </tr> <tr> <td>123</td> <td>14</td> <td>6</td> <td>8</td> </tr> <tr> <td>123</td> <td>9</td> <td>4</td> <td>9</td> </tr> <tr> <td>345</td> <td>5</td> <td>82</td> <td>72</td> </tr> <tr> <td>345</td> <td>4</td> <td>64</td> <td>81</td> </tr> <tr> <td>345</td> <td>5</td> <td>3</td> <td>6</td> </tr> </tbody> </table> </div> <p>For the last dictionary (e.g., a_t, b_t), I have been able to separate them and convert them with the following code.</p> <pre><code>values = table.dict_vals.str.replace(&quot;'&quot;, '&quot;').apply(json.loads).tolist() df = pd.DataFrame(values) df.key_a = df.key_a.apply(lambda x: x[-1]) data_split = df[&quot;dict_vals&quot;].apply(pd.Series) </code></pre> <p>Unfortunately, I am not sure how this method can be used to separate all the other dictionaries. Any help is appreciated! Thank you!</p>
[ { "answer_id": 74293007, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": true, "text": "list" }, { "answer_id": 74293215, "author": "Sarper Makas", "author_id": 19737398, "author_profile": "https://Stackoverflow.com/users/19737398", "pm_score": 0, "selected": false, "text": "import pandas as pd\n\nkeys = [\n {'key_a':[{'a':1,'b':8,'c':7},{'a':14,'b':6,'c':8},{'a':9,'b':4,'c':9},{'a_t':67,'b_t':41,'c_t':6}]},\n {'key_a':[{'a':5,'b':82,'c':72},{'a':4,'b':64,'c':81},{'a':5,'b':3,'c':6}, {'a_t':34,'b_t':23,'c_t':2}]}\n]\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18374702/" ]
74,292,536
<p>I have an issue with the data property not updating after a click event in a v-for loop. The vue component looks like this:</p> <pre class="lang-html prettyprint-override"><code>&lt;template&gt; &lt;div v-if=&quot;showResults &amp;&amp; placeholder === 'Country'&quot; class=&quot;results-container&quot;&gt; &lt;ul&gt; &lt;li class=&quot;is-clickable&quot; v-for=&quot;country in countries&quot; :key=&quot;country.id&quot; &gt;{{country.name}} &lt;span class=&quot;is-pulled-right&quot;&gt; &lt;img class=&quot;plus mr-2&quot; src=&quot;/images/icons/plus.svg&quot; /&gt; &lt;p @click=&quot;setChosen(country.id)&quot; class=&quot;select-text&quot;&gt;SELECT&lt;/p&gt; &lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/template&gt; &lt;script&gt; export default { name: &quot;Searchbar&quot;, props: { placeholder: String, }, data() { return { countries: null, showResults: false, chosenId:null, chosenName: null, searchInput:null, }; }, methods: { getCountries() { axios .get(&quot;/api/getCountries&quot;) .then((response) =&gt; { this.countries = response.data.data; }) .catch((error) =&gt; { console.log(&quot;error&quot;); console.log(error); }); }, setChosen(id){ this.chosenId = id; } }, mounted() { this.getCountries(); }, }; &lt;/script&gt; </code></pre> <p>`</p> <p>I am expecting the chosenId to update on click but it doesn't actually update unless I update the dom, or force a reaction from vue. What am I doing wrong? I can console log the id perfectly fine.</p>
[ { "answer_id": 74292887, "author": "Tolbxela", "author_id": 2487565, "author_profile": "https://Stackoverflow.com/users/2487565", "pm_score": 0, "selected": false, "text": "<template/>" }, { "answer_id": 74299655, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 1, "selected": false, "text": "new Vue({\n el: '#app',\n data: {\n countries: [{\n id: 1,\n name: 'United State'\n }, {\n id: 2,\n name: 'Australia'\n }, {\n id: 3,\n name: 'Canada'\n }],\n chosenId: null\n },\n methods: {\n setChosen(id) {\n this.chosenId = id;\n console.log(this.chosenId);\n }\n }\n})" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14450820/" ]
74,292,541
<p>I have a daframe like the one below:</p> <p>the columns <code>str, mpr, cta, mpt</code> are all the same but for every record I have value in only 1 of these 4 columns.</p> <p>How can I merge these 4 columns in only 1 like the output below:</p> <pre><code>id str mpr cta mpt 1 10 null null null 2 null 11 null null 3 null null 6 null 4 null null null 1 </code></pre> <p>Output:</p> <pre><code>id final 1 10 2 11 3 6 4 1 </code></pre> <p>as you can see the columns <code>final</code> will always have a value coming from only one of each 4 columns.</p> <p>Important: sometimes the 4 columns is null then the <code>final</code> column will also be null</p>
[ { "answer_id": 74292663, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 3, "selected": true, "text": "# find the max along the row, starting from second columns (skipping over ID)\ndf['final']=df.iloc[:,1:].max(axis=1, numeric_only=True) #.astype(int)\ndf[['id','final']]\n\n# if a row can have all Null than don't add astype(int)\n" }, { "answer_id": 74292864, "author": "GhettoCoder", "author_id": 20224248, "author_profile": "https://Stackoverflow.com/users/20224248", "pm_score": 1, "selected": false, "text": "Final_List = []\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18333836/" ]
74,292,549
<p>Is it possible to select one or more fields from a table and map it into the entity?</p> <p>Currently trying</p> <pre><code>@Repository public interface RoleRepo extends JpaRepository&lt;Role, Long&gt;{ @Query(&quot;SELECT r.roleId, r.name FROM role r&quot;) List&lt;Role&gt; getAllRoleNames(); } </code></pre> <p>I only want those 2 values and the rest of the fields can be <code>null</code> to make it more efficient. The error I get right now is</p> <pre><code>ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [@org.springframework.data.jpa.repository.Query demo.model.Role] for value '{1, Java Dev}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [@org.springframework.data.jpa.repository.Query demo.model.Role]] with root cause </code></pre> <p>So how can I make the conversion happen when I can't just say <code>object.Id = role.roleId</code> (<code>object.Id</code> would be that <code>1</code>).</p>
[ { "answer_id": 74293645, "author": "TedEllis", "author_id": 20053884, "author_profile": "https://Stackoverflow.com/users/20053884", "pm_score": 1, "selected": false, "text": "@Entity\npublic class ExampleEntity {\n \n @Id\n private Long id;\n \n @OneToOne\n private Person person;\n\n private String name;\n\n // getters and setters\n}\n" }, { "answer_id": 74298213, "author": "thanhyou00", "author_id": 14445782, "author_profile": "https://Stackoverflow.com/users/14445782", "pm_score": 0, "selected": false, "text": "@Data\n@NoArgsConstructor\n@AllArgsConstructor\n@Entity\npublic class NewRole implements Serializable {\n\nprivate static final long serialVersionUID = 1L;\n@Id\nprivate Long id;\nprivate String name;\n\n}\n" }, { "answer_id": 74299812, "author": "zhrgci", "author_id": 10557540, "author_profile": "https://Stackoverflow.com/users/10557540", "pm_score": 0, "selected": false, "text": "@Repository\npublic interface RoleRepo extends JpaRepository<Role, Long>{ \n @Query(\"SELECT new demo.model.Role(r.roleId, r.name) FROM role r\") \n List<Role> getAllRoleNames();\n}\n\n\n\n@AllArgsConstructor //all arg constructor\n@Data\n@Entity(name = \"role\")\npublic class Role {\n public Role(Long roleId, String name) { //half arg constructor\n this.roleId = roleId;\n this.name = name;\n }\n\n @Id\n private Long roleId;\n\n private String name;\n\n // more fields, getters, and setters\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10557540/" ]
74,292,551
<p>How to align the second span text to the right? First span is already aligned but after the line break second span starts from the left</p> <pre><code>&lt;td align=&quot;right&quot;&gt; &lt;span&gt;${arabicLabels.DVD_NAV}&lt;/span&gt; &lt;br /&gt; &lt;span&gt;${arabicLabels.SCREEN}&lt;/span&gt; &lt;/td&gt; </code></pre> <p>Output:</p> <p><a href="https://i.stack.imgur.com/rumYg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rumYg.png" alt="arabic_text" /></a></p> <p>I want both of spans be aligned right. In the picture there is one TR and two TD, left side english and right side arabic. We care about the right TD which is mentioned above.</p>
[ { "answer_id": 74293645, "author": "TedEllis", "author_id": 20053884, "author_profile": "https://Stackoverflow.com/users/20053884", "pm_score": 1, "selected": false, "text": "@Entity\npublic class ExampleEntity {\n \n @Id\n private Long id;\n \n @OneToOne\n private Person person;\n\n private String name;\n\n // getters and setters\n}\n" }, { "answer_id": 74298213, "author": "thanhyou00", "author_id": 14445782, "author_profile": "https://Stackoverflow.com/users/14445782", "pm_score": 0, "selected": false, "text": "@Data\n@NoArgsConstructor\n@AllArgsConstructor\n@Entity\npublic class NewRole implements Serializable {\n\nprivate static final long serialVersionUID = 1L;\n@Id\nprivate Long id;\nprivate String name;\n\n}\n" }, { "answer_id": 74299812, "author": "zhrgci", "author_id": 10557540, "author_profile": "https://Stackoverflow.com/users/10557540", "pm_score": 0, "selected": false, "text": "@Repository\npublic interface RoleRepo extends JpaRepository<Role, Long>{ \n @Query(\"SELECT new demo.model.Role(r.roleId, r.name) FROM role r\") \n List<Role> getAllRoleNames();\n}\n\n\n\n@AllArgsConstructor //all arg constructor\n@Data\n@Entity(name = \"role\")\npublic class Role {\n public Role(Long roleId, String name) { //half arg constructor\n this.roleId = roleId;\n this.name = name;\n }\n\n @Id\n private Long roleId;\n\n private String name;\n\n // more fields, getters, and setters\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14924514/" ]
74,292,564
<p>I'm trying to run Cplex from terminal command line in Ubuntu. When I execut <code>/oplrun/path$ ./oplrun</code> I get the following error.</p> <p><code>./oplrun: error while loading shared libraries: liboplnl1.so.12: cannot open shared object file: No such file or directory </code></p> <p>How can I fix it?</p> <p>TIA</p>
[ { "answer_id": 74293645, "author": "TedEllis", "author_id": 20053884, "author_profile": "https://Stackoverflow.com/users/20053884", "pm_score": 1, "selected": false, "text": "@Entity\npublic class ExampleEntity {\n \n @Id\n private Long id;\n \n @OneToOne\n private Person person;\n\n private String name;\n\n // getters and setters\n}\n" }, { "answer_id": 74298213, "author": "thanhyou00", "author_id": 14445782, "author_profile": "https://Stackoverflow.com/users/14445782", "pm_score": 0, "selected": false, "text": "@Data\n@NoArgsConstructor\n@AllArgsConstructor\n@Entity\npublic class NewRole implements Serializable {\n\nprivate static final long serialVersionUID = 1L;\n@Id\nprivate Long id;\nprivate String name;\n\n}\n" }, { "answer_id": 74299812, "author": "zhrgci", "author_id": 10557540, "author_profile": "https://Stackoverflow.com/users/10557540", "pm_score": 0, "selected": false, "text": "@Repository\npublic interface RoleRepo extends JpaRepository<Role, Long>{ \n @Query(\"SELECT new demo.model.Role(r.roleId, r.name) FROM role r\") \n List<Role> getAllRoleNames();\n}\n\n\n\n@AllArgsConstructor //all arg constructor\n@Data\n@Entity(name = \"role\")\npublic class Role {\n public Role(Long roleId, String name) { //half arg constructor\n this.roleId = roleId;\n this.name = name;\n }\n\n @Id\n private Long roleId;\n\n private String name;\n\n // more fields, getters, and setters\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10950811/" ]
74,292,619
<p>I have a old Spring Cloud gateway working with Keyclock server. I don't have Web UI for login because the project is a Rest API. OAuth 2.0 is used with Grant type password.</p> <p>I want to migrate to OAuth 2.1 but Grant type password is deprecated.</p> <p>Can you advise in my case what would be the best way to migrate the project in order again to have user name and password to issue a token in order to authenticate users and make API requests?</p> <p>Looking at this guide <a href="https://connect2id.com/learn/oauth-2-1" rel="nofollow noreferrer">https://connect2id.com/learn/oauth-2-1</a> I think JWT bearer grant type is a good candidate?</p> <p>What if I create my own grant type similar to password grant type?</p>
[ { "answer_id": 74293463, "author": "ch4mp", "author_id": 619830, "author_profile": "https://Stackoverflow.com/users/619830", "pm_score": 2, "selected": true, "text": "authorization-code" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1103606/" ]
74,292,621
<p>I'm looking at <a href="https://stackoverflow.com/questions/31373070/why-does-sum-need-ghc-num-frominteger">this</a>, as well as contemplating the whole issue of non-decimal literals, e.g., <code>1</code>, being just sugar for <code>fromInteger 1</code> and then I find the type is</p> <pre><code>λ&gt; :t 1 1 :: Num p =&gt; p </code></pre> <p>This and the statement</p> <blockquote> <p>An integer literal represents the application of the function fromInteger to the appropriate value of type Integer.</p> </blockquote> <p>have me wondering what is really going on. Likewise,</p> <pre><code>λ&gt; :t 3.149 3.149 :: Fractional p =&gt; p </code></pre> <p>Richard Bird says</p> <blockquote> <p>A floating-point literal such as <code>3.149</code> represents the application of <code>fromRational</code> to an appropriate rational number. Thus <code>3.149 :: Fractional a =&gt; a</code></p> </blockquote> <p>Not understanding what <em>the application of <code>fromRational</code> to an appropriate rational number</em> means. Then he says this is all necessary to be able to add, e.g., <code>42 + 3.149</code>.</p> <p>I feel there's a lot going on here that I just don't understand. Like there's too much hand-waving for me. It seems like a cast of an unidentified non-decimal or decimal to specific types, <code>Integer</code> and <code>Rational</code>. So first, why is <code>1</code> actually <code>fromInteger 1</code> internally? I realize every expression must be evaluated as a type, but why is <code>fromInteger</code> and <code>fromRational</code> involved?</p> <p><strong>Auxillary</strong></p> <p>So at <a href="https://wiki.haskell.org/Converting_numbers" rel="nofollow noreferrer">this</a> page</p> <blockquote> <p>The workhorse for converting from integral types is <code>fromIntegral</code>, which will convert from any <code>Integral</code> type into any Numeric type (which includes <code>Int</code>, <code>Integer</code>, <code>Rational</code>, and <code>Double</code>): <code>fromIntegral :: (Num b, Integral a) =&gt; a -&gt; b</code></p> </blockquote> <p>Then comes the example</p> <pre><code>λ&gt; sqrt 1 1.0 λ&gt; sqrt (1 :: Int) ... error... λ&gt; sqrt (fromInteger 1) 1.0 λ&gt; :t sqrt 1 sqrt 1 :: Floating a =&gt; a λ&gt; :t sqrt (1 :: Int) ...error... λ&gt; :t sqrt sqrt :: Floating a =&gt; a -&gt; a λ&gt; :t sqrt (fromInteger 1) sqrt (fromInteger 1) :: Floating a =&gt; a </code></pre> <p>So yes, this is a cast, but I don't know the mechanism of how <code>fromI*</code> is doing this --- since technically it's not a cast in a C/C++ sense. All instances of <code>Num</code> must have a <code>fromInteger</code>. It seems like under the hood Haskell is taking whatever you put in and generic-izing it to <code>Integer</code> or <code>Rational</code>, then &quot;giving it back&quot; to the original function, e.g., with <code>sqrt (fromInteger 1)</code> being of type <code>Floating a =&gt; a</code>. This is very mysterious to someone prone to over-thinking.</p> <p>So yes, <code>1</code> is a literal, a constant that is polymorphic. It may represent <code>1</code> in any type that instantiates <code>Num</code>. The role of <code>fromInteger</code> must be to allowing a value (a cast) to be extracted from an integer constant consistent with what the situation calls for. But this is hand-waving talk at some point. I dont' get how this is actually happening.</p>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2394634/" ]
74,292,635
<p>Recently I moved from an Intel-based MacBook to a M1-based MacBook, and ever since I'm not being able to run this project, <strong>but it fails only on debug mode.</strong></p> <p>I get this message every time:</p> <pre><code>&lt;FirebaseCore/FirebaseCore.h&gt; file not found </code></pre> <p>However, on <strong>release</strong> mode, it compiles normally.</p> <p>I've tried copying the project both directly from the old machine and from git. <strong>I've already tried:</strong></p> <ul> <li>Fully reinstalling Xcode from scratch</li> <li>Deleting Derived Data folder</li> <li>Cmd + Shift + K</li> <li>Reinstalling Pods</li> <li>&quot;Find implicit dependencies&quot; is checked on the Scheme settings</li> <li>I am working on the .xcworkspace and <strong>not</strong> on .xcodeproj</li> <li>Tried adding modular_header =&gt; true to Podfile</li> <li>Tried adding &quot;arm64&quot; to excluded architectures on build settings (both on the main project and on the pods project)</li> </ul> <p>I'm using Mac OS Ventura (on both machines), as well as the latest Xcode (14.1) The Firebase package is <strong>@react-native-firebase/app v15.6.0</strong></p> <p>Thanks</p>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2291449/" ]
74,292,649
<p>I'm trying to create combinations of two lists. List A should be increasing, or a sliding window if you will. List B is static. Where List A can have any number of values.</p> <p>My question seems to be a different than what I see already posted, as I am using a sliding window on one list and keeping the other list static, so it's not as simple as every combination of both lists.</p> <p>So the inputs it would look like the below:</p> <pre><code>ListA = [Val1, Val2, Val3] ListB = [0, 1] </code></pre> <p>Giving the below output:</p> <pre><code>[Val1, 0] [Val1, 1] [Val2, 0] [Val2, 1] [Val3, 0] [Val3, 1] [[Val1, 0], [Val2, 0]] [[Val1, 0], [Val2, 1]] [[Val1, 1], [Val2, 0]] [[Val1, 1], [Val2, 1]] [[Val1, 0], [Val3, 0]] [[Val1, 0], [Val3, 1]] [[Val1, 1], [Val3, 0]] [[Val1, 1], [Val3, 1]] [[Val2, 0], [Val3, 0]] [[Val2, 0], [Val3, 1]] [[Val2, 1], [Val3, 0]] [[Val2, 1], [Val3, 1]] [[Val1, 0], [Val2, 0], [Val3, 0]] [[Val1, 0], [Val2, 0], [Val3, 1]] [[Val1, 0], [Val2, 1], [Val3, 0]] [[Val1, 0], [Val2, 1], [Val3, 1]] [[Val1, 1], [Val2, 0], [Val3, 0]] [[Val1, 1], [Val2, 0], [Val3, 1]] [[Val1, 1], [Val2, 1], [Val3, 0]] [[Val1, 1], [Val2, 1], [Val3, 1]] </code></pre> <p>I've been experimenting with itertools combinations and product for a while now, I cannot get my head around it. Covid brain fog :D. Any help would be appreciated.</p> <p>Thanks</p>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13770496/" ]
74,292,664
<p>I am using a variable group to store some secrets, that I want to deploy into a key vault as part of my pipeline.</p> <p>I do this by passing the values as secret parameters to a bicep file via the Azure CLI.</p> <p>My pipeline step looks like this:</p> <pre><code>- task: AzureCLI@2 displayName: deploy bicep template inputs: azureSubscription: ${{ parameters.azure_subscription }} scriptType: 'ps' scriptLocation: 'inlineScript' inlineScript: | az deployment group create ` --name foo.$(Build.BuildNumber) ` --resource-group my-rg-name ` --template-file $(Pipeline.Workspace)/iac/main.bicep ` --parameters environment='${{ parameters.environment }}' ` kv_secret_one='$(bd_kv_secret_one)' ` kv_secret_two='$(bd_kv_secret_two)' </code></pre> <p>Now, the issue is that these secrets could contain all sorts of special characters that break my script. So I found some suggestions that I could use double quotes inside the single quotes like this <code>kv_secret_two='&quot;$(bd_kv_secret_two)&quot;'</code></p> <p>However, if the value of the secret contains a &quot; then the script breaks.</p> <p>This leads me to think there must be a better way of doing this, but I cannot find it.</p> <p>What is the correct way to pass <code>--parameters</code> so that they are escaped properly, no matter what characters the may contain?</p>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/365592/" ]
74,292,669
<p>Hello I have looked everywhere and I can't understand what I am doing wrong. My command is called and the onpropertychanged event is called but the ContentControl in my MainWindow will not show the next view. I am new to WPF and Xaml and really trying to figure this out.</p> <p>I have attached a link to the sample application on my Github.</p> <p>The End game here is I want the Radio button to be checked when the view is active. I also want to be able to change from the home view to other views via a button on that view once I am past this first hurtle.</p> <p><a href="https://github.com/HackitNiels/LearningWPF" rel="nofollow noreferrer">Github repository</a></p> <pre><code> public class ApplicationViewModel : ObservableObject { private ICommand _changeViewCommand; private IViewModel _CurrentViewModel; private List&lt;IViewModel&gt; _viewModels; private bool _isActive; public ApplicationViewModel() { ViewModels.Add(new HomeViewModel()); ViewModels.Add(new AccountViewModel()); CurrentViewModel = ViewModels.Find(r =&gt; r.Name == &quot;Home&quot;); CurrentViewModel.IsActive = true; } public List&lt;IViewModel&gt; ViewModels { get { if (_viewModels == null) _viewModels = new List&lt;IViewModel&gt;(); return _viewModels; } } public IViewModel CurrentViewModel { get { return _CurrentViewModel; } set { if (_CurrentViewModel != value) { _CurrentViewModel = value; OnPropertyChanged(); } } } public ICommand ChangePageCommand { get { if (_changeViewCommand == null) { _changeViewCommand = new RelayCommand( p =&gt; ChangeViewModel((IViewModel)p), p =&gt; p is IViewModel); } return _changeViewCommand; } } private void ChangeViewModel(IViewModel viewModel) { CurrentViewModel = ViewModels.Find(r =&gt; r.Name == viewModel.Name); } public bool IsActive { get { return _isActive; } set { _isActive = value; OnPropertyChanged(&quot;IsActive&quot;); } } } &lt;UserControl.DataContext&gt; &lt;viewModels:ApplicationViewModel/&gt; &lt;/UserControl.DataContext&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate DataType=&quot;{x:Type viewModels:ApplicationViewModel}&quot;/&gt; &lt;DataTemplate DataType=&quot;{x:Type viewModels:HomeViewModel}&quot;&gt; &lt;views:HomeView/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType=&quot;{x:Type viewModels:AccountViewModel}&quot;&gt; &lt;views:AccountView/&gt; &lt;/DataTemplate&gt; &lt;/UserControl.Resources&gt; &lt;StackPanel Orientation=&quot;Vertical&quot;&gt; &lt;RadioButton Content=&quot;Home&quot; IsChecked=&quot;{Binding IsActive, Mode=TwoWay}&quot; Command=&quot;{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}&quot; CommandParameter=&quot;{Binding }&quot;&gt; &lt;RadioButton.DataContext&gt; &lt;viewModels:HomeViewModel/&gt; &lt;/RadioButton.DataContext&gt; &lt;/RadioButton&gt; &lt;RadioButton Content=&quot;Account&quot; IsChecked=&quot;{Binding IsActive, Mode=TwoWay}&quot; Command=&quot;{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}&quot; CommandParameter=&quot;{Binding }&quot;&gt; &lt;RadioButton.DataContext&gt; &lt;viewModels:AccountViewModel/&gt; &lt;/RadioButton.DataContext&gt; &lt;/RadioButton&gt; &lt;/StackPanel&gt; </code></pre>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13729116/" ]
74,292,703
<p>I am trying to dump the .yaml files inside of 4 folders (files are nested in a subfolder inside) to another directory, only copying the .yaml files into each of the 4 copied folders, excluding the subfolders. The subfolder in each directory has the same name. Ive got a script that does the first part of the copy, but it doesnt exclude the subfolders, and nests the files in their respective target folder still. Not sure what im doing wrong or what I need to fix with my script at the bottom.</p> <p>The current file structure:</p> <pre><code> - QA - Target **Connections** Folder - contains .yaml files - Several Other Folders - RESEARCH - Target **Connections** Folder - contains .yaml files - Several Other Folders - PROD - Target **Connections** Folder - Several Other Folders - DEV - Target **Connections** Folder - Several Other Folders </code></pre> <p>The output to the copied directory should be as follows:</p> <pre><code> - QA - .yaml files from original &quot;qa/Connections&quot; subfolder - RESEARCH - .yaml files from original &quot;research/Connections&quot; subfolder - PROD - .yaml files from original &quot;prod/Connections&quot; subfolder - DEV - .yaml files from original &quot;dev/Connections&quot; subfolder``` </code></pre> <p>I have the following script, but it only copies the 4 sub folders under the base directory, and all of the contents contained, I cant figure out how to drill those down to exclude everything except for the <strong>Connections</strong> folder, and place only the files into those 4 main environment folders.</p> <pre><code>$sourceDir = &quot;C:\Users\hhh\appdev\powershell-scripts\TEST-REPO\hhh\data\environments&quot; $targetDir = &quot;C:\Users\hhh\appdev\targetfolder&quot; Get-ChildItem $sourceDir -File -Recurse | ForEach-Object { $dest = Join-Path -Path $targetDir -ChildPath $_.DirectoryName.SubString($sourceDir.Length) if ($dest -match 'research|qa|production|global') { $null = New-Item -Path $dest -ItemType Directory -Force $_ | Copy-Item -Destination $dest -Force } } </code></pre>
[ { "answer_id": 74293153, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 2, "selected": false, "text": "1" }, { "answer_id": 74311736, "author": "K. A. Buhr", "author_id": 7203016, "author_profile": "https://Stackoverflow.com/users/7203016", "pm_score": 3, "selected": true, "text": "Num a => a" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20114824/" ]
74,292,713
<p>I've downloaded a fresh IntelliJ IDEA with the Kotlin multiplatform plugin and created a project using the Native application project template. This template creates a <code>Main.kt</code> file with the content:</p> <pre><code>fun main() { println(&quot;Hello, Kotlin/Native!&quot;) } </code></pre> <p>As well as many other gradle files referencing <code>kotlin(&quot;multiplatform&quot;) version &quot;1.7.20&quot;</code>. I can build and run the project from inside IntelliJ IDEA, but I see no hello world:</p> <p><a href="https://i.stack.imgur.com/RmGaM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RmGaM.png" alt="no hello world" /></a></p> <p>I can only see the gradle output and a success result, but no <code>Hello Kotlin/Native!</code> message anywhere. I've tried changing the <code>runDebugExecutableNative</code> settings and checked the options related to show the console/output when stdout messages are printed:</p> <p><a href="https://i.stack.imgur.com/CRTTG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CRTTG.png" alt="project settings" /></a></p> <p>I can see no other output window/pane, so… where can I see the output? The project builds a debug or release <code>Kasha.kexe</code> which I can run from the command line manually, but I'm guessing an IDE shouldn't require me to run commands from the command line every time?</p> <pre><code>$ ./build/bin/native/debugExecutable/Kasha.kexe Hello, Kotlin/Native! </code></pre> <p>I can see a greyed out symbol in the run pane, which corresponds to the output <code>&gt; Task :runDebugExecutableNative SKIPPED</code>. Does that mean the IDE can only build but not run the executable? I'm using IntelliJ IDEA 2022.2.3 (Community Edition) and <code>kotlin(&quot;multiplatform&quot;) version &quot;1.7.20&quot;</code>.</p> <p><strong>UPDATE</strong> As <a href="https://stackoverflow.com/questions/74292713/why-does-kotlin-native-hello-world-not-output-anything-inside-intellij-idea/74311410#74311410">bppleman</a> correctly guesses the problem is I'm trying to run this on an Apple M1 machine. The gradle that comes out from the template is:</p> <pre><code>kotlin { val hostOs = System.getProperty(&quot;os.name&quot;) val isMingwX64 = hostOs.startsWith(&quot;Windows&quot;) val nativeTarget = when { hostOs == &quot;Mac OS X&quot; -&gt; macosX64(&quot;native&quot;) hostOs == &quot;Linux&quot; -&gt; linuxX64(&quot;native&quot;) isMingwX64 -&gt; mingwX64(&quot;native&quot;) else -&gt; throw GradleException(&quot;Host OS is not supported in Kotlin/Native.&quot;) } … </code></pre> <p>Replacing the <code>macosX64</code> call with <code>macosArm64</code> makes everything work as expected. But I guess now intel based apple machines will be on the wrong side of the fence?</p>
[ { "answer_id": 74311410, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 2, "selected": true, "text": "kotlin {\n val hostOs = System.getProperty(\"os.name\")\n val isMingwX64 = hostOs.startsWith(\"Windows\")\n val nativeTarget = when {\n- hostOs == \"Mac OS X\" -> macosX64(\"native\")\n+ hostOs == \"Mac OS X\" -> macosArm64(\"native\")\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingwX64 -> mingwX64(\"native\")\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n }\n //………\n}\n" }, { "answer_id": 74355097, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 0, "selected": false, "text": "val hostOs = System.getProperty(\"os.name\")\nval isMingw = hostOs.startsWith(\"Windows\")\nval nativeTarget = when {\n hostOs == \"Mac OS X\" -> {\n if (System.getProperty(\"os.arch\").contains(\"aarch64\")) {\n macosArm64(\"native\")\n } else {\n macosX64(\"native\")\n }\n }\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingw -> {\n if (System.getenv(\"ProgramFiles(x86)\") != null) {\n mingwX86(\"native\")\n } else {\n mingwX64(\"native\")\n }\n }\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/172690/" ]
74,292,722
<p>I'm trying to create a bar graph in ggplot, considering a &quot;type&quot; variable in the filling of each bar.</p> <p>However, the maximum values of the bars are excessively high (above 100, when in fact they should be close to 40). My goal is to place the overlay padding.</p> <p>I appreciate any help.</p> <pre><code>df &lt;- structure(list(Count = c(&quot;Beu&quot;, &quot;Beu&quot;, &quot;Beu&quot;, &quot;Abe&quot;, &quot;Abe&quot;, &quot;Abe&quot;, &quot;Pre&quot;, &quot;Pre&quot;, &quot;Pre&quot;, &quot;Bra&quot;, &quot;Bra&quot;, &quot;Bra&quot;), Type = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), Hours = c(40.17775, 42.1492178098676, 42.1910353866317, 38.3701812919564, 39.9185282522996, 38.8002722361139, 41.6389448017412, 41.7041742286751, 41.9545826200271, 41.1375910844406, 41.0602923264312, 40.6300999927013)), row.names = c(NA, 12L), class = &quot;data.frame&quot;) </code></pre> <p>Here's the code I'm trying to run:</p> <pre><code>df %&gt;% mutate(Type = as.factor(Type)) %&gt;% ggplot(mapping = aes(x = Count, y = Hours, fill = Type)) + geom_bar(stat = 'identity') + coord_flip() + theme_classic() </code></pre>
[ { "answer_id": 74311410, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 2, "selected": true, "text": "kotlin {\n val hostOs = System.getProperty(\"os.name\")\n val isMingwX64 = hostOs.startsWith(\"Windows\")\n val nativeTarget = when {\n- hostOs == \"Mac OS X\" -> macosX64(\"native\")\n+ hostOs == \"Mac OS X\" -> macosArm64(\"native\")\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingwX64 -> mingwX64(\"native\")\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n }\n //………\n}\n" }, { "answer_id": 74355097, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 0, "selected": false, "text": "val hostOs = System.getProperty(\"os.name\")\nval isMingw = hostOs.startsWith(\"Windows\")\nval nativeTarget = when {\n hostOs == \"Mac OS X\" -> {\n if (System.getProperty(\"os.arch\").contains(\"aarch64\")) {\n macosArm64(\"native\")\n } else {\n macosX64(\"native\")\n }\n }\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingw -> {\n if (System.getenv(\"ProgramFiles(x86)\") != null) {\n mingwX86(\"native\")\n } else {\n mingwX64(\"native\")\n }\n }\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14380501/" ]
74,292,734
<p>I have sequences appearing in a file as</p> <pre><code>2282.641.33712e+06 </code></pre> <p>which I want to split into the respective floating point numbers as</p> <pre><code>2282.64 and 1.33712e+06. </code></pre> <p>The floating point number with the e+06<br /> contains a single leading digit before the decimal.</p> <p>Could this be done with sed / awk ?</p>
[ { "answer_id": 74311410, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 2, "selected": true, "text": "kotlin {\n val hostOs = System.getProperty(\"os.name\")\n val isMingwX64 = hostOs.startsWith(\"Windows\")\n val nativeTarget = when {\n- hostOs == \"Mac OS X\" -> macosX64(\"native\")\n+ hostOs == \"Mac OS X\" -> macosArm64(\"native\")\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingwX64 -> mingwX64(\"native\")\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n }\n //………\n}\n" }, { "answer_id": 74355097, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 0, "selected": false, "text": "val hostOs = System.getProperty(\"os.name\")\nval isMingw = hostOs.startsWith(\"Windows\")\nval nativeTarget = when {\n hostOs == \"Mac OS X\" -> {\n if (System.getProperty(\"os.arch\").contains(\"aarch64\")) {\n macosArm64(\"native\")\n } else {\n macosX64(\"native\")\n }\n }\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingw -> {\n if (System.getenv(\"ProgramFiles(x86)\") != null) {\n mingwX86(\"native\")\n } else {\n mingwX64(\"native\")\n }\n }\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4029776/" ]
74,292,737
<p>I currently have a GET request to a URL that returns three things: .zip file, .zipsig file, and a .txt file.</p> <p>I'm only interested in the .zip file which has dozens of .json files. I would like to extract all these .json files, preferable directly into a single pandas data frame, but extracting them into a folder also works.</p> <p>Code so far, mostly stolen:</p> <pre><code> license = requests.get(url, headers={'Authorization': &quot;Api-Token &quot; + 'blah'}) z = zipfile.ZipFile(io.BytesIO(license.content)) billingRecord = z.namelist()[0] z.extract(billingRecord, path = &quot;C:\\Users\\Me\\Downloads\\Json license&quot;) </code></pre> <p>This extracts the entire .zip file to the path. I would like to extract the individual .json files from said .zip file to the path.</p>
[ { "answer_id": 74311410, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 2, "selected": true, "text": "kotlin {\n val hostOs = System.getProperty(\"os.name\")\n val isMingwX64 = hostOs.startsWith(\"Windows\")\n val nativeTarget = when {\n- hostOs == \"Mac OS X\" -> macosX64(\"native\")\n+ hostOs == \"Mac OS X\" -> macosArm64(\"native\")\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingwX64 -> mingwX64(\"native\")\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n }\n //………\n}\n" }, { "answer_id": 74355097, "author": "bppleman", "author_id": 12346099, "author_profile": "https://Stackoverflow.com/users/12346099", "pm_score": 0, "selected": false, "text": "val hostOs = System.getProperty(\"os.name\")\nval isMingw = hostOs.startsWith(\"Windows\")\nval nativeTarget = when {\n hostOs == \"Mac OS X\" -> {\n if (System.getProperty(\"os.arch\").contains(\"aarch64\")) {\n macosArm64(\"native\")\n } else {\n macosX64(\"native\")\n }\n }\n hostOs == \"Linux\" -> linuxX64(\"native\")\n isMingw -> {\n if (System.getenv(\"ProgramFiles(x86)\") != null) {\n mingwX86(\"native\")\n } else {\n mingwX64(\"native\")\n }\n }\n else -> throw GradleException(\"Host OS is not supported in Kotlin/Native.\")\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14303407/" ]
74,292,747
<p>I am trying to clone a <code>repository</code> from another person, but after I made some changes to this, I want to make a <strong>pull request</strong> to merge my changes.</p> <p>However, I am not sure if the other person is making changes at the same time. How can I know if these changes are also '<em><strong>synchronized</strong></em>' with mine, and if I can do it from the <code>git</code> commands?</p> <p><strong>Bash</strong></p> <pre><code>$ git pull </code></pre> <ul> <li>Currently, when I type the following command, maybe I get the changes pulled under my changes, but in this case, could this command be a '<strong>rebase</strong>' !?</li> </ul>
[ { "answer_id": 74292853, "author": "Gx4", "author_id": 12223191, "author_profile": "https://Stackoverflow.com/users/12223191", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293274, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293725, "author": "pylos", "author_id": 19751436, "author_profile": "https://Stackoverflow.com/users/19751436", "pm_score": -1, "selected": false, "text": "1. $ git remote add bobs_work git@github.com:XXXX/the_repo.git\n2. $ git fetch bobs_work\n3. $ git rebase bobs_work/master\n" }, { "answer_id": 74308752, "author": "Ross Presser", "author_id": 864696, "author_profile": "https://Stackoverflow.com/users/864696", "pm_score": 1, "selected": false, "text": "git pull" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19751436/" ]
74,292,760
<p>I want to avoid repeating <code>Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}</code> in the following.</p> <pre><code>&lt;SwipeView ... xmlns:vm=&quot;clr-namespace:Todo.ViewModel&quot;&gt; &lt;SwipeView.LeftItems&gt; &lt;SwipeItems&gt; &lt;SwipeItem Text=&quot;Delete&quot; Command=&quot;{Binding DeleteCommand,Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}}&quot; /&gt; &lt;/SwipeItems&gt; &lt;/SwipeView.LeftItems&gt; &lt;Grid Padding=&quot;0,5&quot;&gt; &lt;Frame &gt; &lt;Frame.GestureRecognizers&gt; &lt;TapGestureRecognizer Command=&quot;{Binding TapCommand,Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}}&quot;/&gt; &lt;/Frame.GestureRecognizers&gt; &lt;/Frame&gt; &lt;/Grid&gt; &lt;/SwipeView&gt; </code></pre> <p>I do the following but it does not work as expected.</p> <pre><code>&lt;SwipeView ... xmlns:vm=&quot;clr-namespace:Todo.ViewModel&quot; BindingContext=&quot;{Binding Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}}&quot; &gt; &lt;SwipeView.LeftItems&gt; &lt;SwipeItems&gt; &lt;SwipeItem Text=&quot;Delete&quot; Command=&quot;{Binding DeleteCommand}&quot; /&gt; &lt;/SwipeItems&gt; &lt;/SwipeView.LeftItems&gt; &lt;Grid Padding=&quot;0,5&quot;&gt; &lt;Frame &gt; &lt;Frame.GestureRecognizers&gt; &lt;TapGestureRecognizer Command=&quot;{Binding TapCommand}&quot; /&gt; &lt;/Frame.GestureRecognizers&gt; &lt;/Frame&gt; &lt;/Grid&gt; &lt;/SwipeView&gt; </code></pre> <h2>Repo</h2> <p>Use the following repo to avoid getting inconsistent results (among us) and to make sure we are talking in the same scope.</p> <p><a href="https://github.com/pstricks-fans/Todo" rel="nofollow noreferrer">https://github.com/pstricks-fans/Todo</a></p> <p>Here are the relevant parts:</p> <p><strong>MySwipeView:</strong></p> <pre class="lang-cs prettyprint-override"><code>public partial class MySwipeView : SwipeView { public MySwipeView() { InitializeComponent(); } } </code></pre> <pre class="lang-xml prettyprint-override"><code>&lt;SwipeView ... x:Class=&quot;Todo.CustomControls.MySwipeView&quot; xmlns:vm=&quot;clr-namespace:Todo.ViewModel&quot; &gt; &lt;SwipeView.LeftItems&gt; &lt;SwipeItems&gt; &lt;SwipeItem Text=&quot;Delete&quot; Command=&quot;{Binding DeleteCommand,Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}}&quot; CommandParameter=&quot;{Binding .}&quot;/&gt; &lt;/SwipeItems&gt; &lt;/SwipeView.LeftItems&gt; &lt;Grid Padding=&quot;0,5&quot;&gt; &lt;Frame &gt; &lt;Frame.GestureRecognizers&gt; &lt;TapGestureRecognizer Command=&quot;{Binding TapCommand,Source={RelativeSource AncestorType={x:Type vm:MainViewModel}}}&quot; CommandParameter=&quot;{Binding .}&quot;/&gt; &lt;/Frame.GestureRecognizers&gt; &lt;Label Text=&quot;{Binding .}&quot; FontSize=&quot;24&quot;/&gt; &lt;/Frame&gt; &lt;/Grid&gt; &lt;/SwipeView&gt; </code></pre> <p><strong>MainPage:</strong></p> <pre class="lang-cs prettyprint-override"><code>public partial class MainPage : ContentPage { public MainPage(MainViewModel vm) { InitializeComponent(); BindingContext = vm; } } </code></pre> <pre class="lang-xml prettyprint-override"><code>&lt;ContentPage ... xmlns:local=&quot;clr-namespace:Todo.CustomControls&quot; xmlns:vm=&quot;using:Todo.ViewModel&quot; x:DataType=&quot;vm:MainViewModel&quot; &gt; &lt;Grid ... &gt; &lt;CollectionView ... &gt; &lt;CollectionView.ItemTemplate&gt; &lt;DataTemplate x:DataType=&quot;{x:Type x:String}&quot;&gt; &lt;local:MySwipeView /&gt; &lt;/DataTemplate&gt; &lt;/CollectionView.ItemTemplate&gt; &lt;/CollectionView&gt; &lt;/Grid&gt; &lt;/ContentPage&gt; </code></pre> <p><strong>MainViewModel:</strong></p> <pre class="lang-cs prettyprint-override"><code>public partial class MainViewModel : ObservableObject { [RelayCommand] void Delete(string s){} [RelayCommand] async Task Tap(string s){} } </code></pre>
[ { "answer_id": 74292853, "author": "Gx4", "author_id": 12223191, "author_profile": "https://Stackoverflow.com/users/12223191", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293274, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293725, "author": "pylos", "author_id": 19751436, "author_profile": "https://Stackoverflow.com/users/19751436", "pm_score": -1, "selected": false, "text": "1. $ git remote add bobs_work git@github.com:XXXX/the_repo.git\n2. $ git fetch bobs_work\n3. $ git rebase bobs_work/master\n" }, { "answer_id": 74308752, "author": "Ross Presser", "author_id": 864696, "author_profile": "https://Stackoverflow.com/users/864696", "pm_score": 1, "selected": false, "text": "git pull" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/835073/" ]
74,292,763
<p>I have a shared_ptr I'm trying to use in two functions of a class, not sure if I have it working right. The shared object class I'm using might be broken, but it's not my repo so I'm wanting to check if it's my issue on my end.</p> <p><strong>myHeader.h</strong></p> <pre><code>#include &quot;otherClass.h&quot; namespace myheader { class myClass : { public: // Constructor myClass(); ~myClass() = default; bool incomingMessage(); private: std::shared_ptr&lt;randomnamespace::OtherClass&gt; otherClass_ = std::make_shared&lt;randomnamespace::OtherClass&gt;(); }; }; </code></pre> <p><strong>myClass.cpp</strong></p> <pre><code>#include &quot;myHeader.h&quot; using namespace myheader; myClass::myClass() : otherClass_() { otherClass_-&gt;setConfiguration(x); std::cout &lt;&lt; &quot;Debug: Initialized&quot;; } bool myClass::incomingMessage() { otherClass_-&gt;sendData(); std::cout &lt;&lt; &quot;Debug: Data sent&quot;; return true; } </code></pre> <p>I'm wondering if it seems to be shared correctly?</p> <p>I've tried running this(compiling works), and the otherClass_-&gt;() calls don't work in either place. Have tried testing both individually with the other commented out, and I don't get the Debug print's after the otherClass_-&gt; calls.</p>
[ { "answer_id": 74292853, "author": "Gx4", "author_id": 12223191, "author_profile": "https://Stackoverflow.com/users/12223191", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293274, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": "git pull" }, { "answer_id": 74293725, "author": "pylos", "author_id": 19751436, "author_profile": "https://Stackoverflow.com/users/19751436", "pm_score": -1, "selected": false, "text": "1. $ git remote add bobs_work git@github.com:XXXX/the_repo.git\n2. $ git fetch bobs_work\n3. $ git rebase bobs_work/master\n" }, { "answer_id": 74308752, "author": "Ross Presser", "author_id": 864696, "author_profile": "https://Stackoverflow.com/users/864696", "pm_score": 1, "selected": false, "text": "git pull" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20242609/" ]
74,292,786
<p>I am testing RandomForestClassifier on simple dataset from sklearn. When I split the data with train_test_split, I get accuracy=0.89. If I use cross-validation with cross_val_score with same parameters of classifier, accuracy is smaller - about 0.83. Why?</p> <p>Here is the code:</p> <pre><code>from sklearn.model_selection import cross_val_score, StratifiedKFold,GridSearchCV,train_test_split from sklearn.metrics import accuracy_score,f1_score,make_scorer from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import make_circles np.random.seed(42) #create dataset: x, y = make_circles(n_samples=500, factor=0.1, noise=0.35, random_state=42) #initialize stratified split: skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42) #create classifier: clf = RandomForestClassifier(random_state=42, max_depth=12,n_jobs=-1, oob_score=True,n_estimators=100,min_samples_leaf=10) #average accuracy on cross-validation: results = np.mean(cross_val_score(clf, x, y, cv=skf,scoring=make_scorer(accuracy_score))) print(&quot;ACCURACY WITH CV = &quot;,results)#prints 0.832 #use train_test_split xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2) clf=RandomForestClassifier(random_state=42, max_depth=12,n_jobs=-1, oob_score=True,n_estimators=100,min_samples_leaf=10) clf.fit(xtrain,ytrain) ypred=clf.predict(xtest) print(&quot;ACCURACY WITHOUT CV = &quot;,accuracy_score(ytest,ypred))#prints 0.89 </code></pre> <p>what I got: ACCURACY WITH CV = 0.83 ACCURACY WITHOUT CV = 0.89</p>
[ { "answer_id": 74293105, "author": "Baradrist", "author_id": 16363934, "author_profile": "https://Stackoverflow.com/users/16363934", "pm_score": 1, "selected": false, "text": "random_state=42" }, { "answer_id": 74293161, "author": "Tickloop", "author_id": 12853714, "author_profile": "https://Stackoverflow.com/users/12853714", "pm_score": 2, "selected": false, "text": "cross_val_score(clf, x, y, cv=skf, scoring=make_scorer(accuracy_score))\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399580/" ]
74,292,787
<p>I'm trying to convert my local date or any local date to PST and then into timestamp. For example, this code works to convert the local time to PST:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var offset = -7; var result = new Date(new Date().getTime() + offset * 3600 * 1000) .toUTCString() .replace(/ GMT$/, ""); console.log("Result:", result);</code></pre> </div> </div> </p> <p>This one return the PST corresponding time, <strong>but when I trying to apply the function getTime() (ex: result.getTime(); )</strong> to convert this one on a Unix timestamp, I'm getting an error.</p>
[ { "answer_id": 74293105, "author": "Baradrist", "author_id": 16363934, "author_profile": "https://Stackoverflow.com/users/16363934", "pm_score": 1, "selected": false, "text": "random_state=42" }, { "answer_id": 74293161, "author": "Tickloop", "author_id": 12853714, "author_profile": "https://Stackoverflow.com/users/12853714", "pm_score": 2, "selected": false, "text": "cross_val_score(clf, x, y, cv=skf, scoring=make_scorer(accuracy_score))\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16019376/" ]
74,292,829
<p>I am merging a bot under discord.js v12 to a newer bot with discord.js v14.</p> <p>However it's my first experience on the node and I don't understand everything, I'm doing well in lua but I don't understand...</p> <p>The events return me errors either it does not find the guild or it is impossible to rename a player, or a player is not found...</p> <p>Here is how it is, I comment you the events according to the return of log that I have</p> <pre class="lang-js prettyprint-override"><code>on(&quot;DiscordBot:RenameMember&quot;, (guild, discordid, fullname) =&gt; { let targetguild = client.guilds.cache.first(); // I got on log the name of GUILD if (targetguild) { let target = targetguild.members.fetch(discordid); // I got on log : [object Promise] if (target) { target.setNickname(fullname); // I got on log : TypeError: target.setNickname is not a function target.member.setNickname(fullname); // I got on log : TypeError: Cannot read properties of undefined (reading 'setNickname') } } }); </code></pre> <p>I made a multitude of tests with cache, without cache but nothing makes it all I find is similar and does not work here...</p> <p>Here you will find the launch of the bot : <a href="https://hastebin.com/ovipelopam.js" rel="nofollow noreferrer">https://hastebin.com/ovipelopam.js</a></p> <p>And here is the file I made separately to find my way around : <a href="https://hastebin.com/azaraqituh.js" rel="nofollow noreferrer">https://hastebin.com/azaraqituh.js</a></p> <p>Do you have an idea ?</p>
[ { "answer_id": 74292919, "author": "Fabian Strathaus", "author_id": 17298437, "author_profile": "https://Stackoverflow.com/users/17298437", "pm_score": 2, "selected": true, "text": "targetguild.members.fetch(discordid)" }, { "answer_id": 74304810, "author": "Jim1120", "author_id": 20399389, "author_profile": "https://Stackoverflow.com/users/20399389", "pm_score": 0, "selected": false, "text": "on(\"DiscordBot:RenameMember\", async (guild, discordid, fullname) => {\n let targetguild = client.guilds.cache.first();\n if (targetguild) {\n let target = await targetguild.members.fetch(discordid); \n if (target) {\n // target.setNickname(fullname); // I got on log : TypeError: target.setNickname is not a function\n // target.members.setNickname(fullname); // I got on log : TypeError: Cannot read properties of undefined (reading 'setNickname')\n let targetRename = await target.setNickname(fullname, 'Modification correspondant au profile InGame'); // That work\n }\n }\n});\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399389/" ]
74,292,848
<p>here is my component method:</p> <pre><code> initiateDetailsView(detailsData) { this.router.navigate(['./personnel-details'], { relativeTo: this.activatedRoute, }); } </code></pre> <p>my test case:</p> <pre><code>it('should navigate to details page', () =&gt; { const routerNavigateSpy = spyOn(router, 'navigate'); component.initiateDetailsView({}); fixture.detectChanges(); expect(routerNavigateSpy).toHaveBeenCalledWith([ './personnel-details', { relativeTo: 'clinic-admin/scok-personnel' }, ]); }); </code></pre> <p>but getting an error as:</p> <pre><code> Expected spy navigate to have been called with: [ [ './personnel-details', Object({ relativeTo: 'clinic-admin/scok-personnel' }) ] ] but actual calls were: [ [ './personnel-details' ], Object({ relativeTo: Route(url:'', path:'') }) ]. </code></pre> <p>how to test the <code>relativeTo</code> route?</p> <p><strong>UPDATE</strong></p> <pre><code>fdescribe('ListPersonnelComponent', () =&gt; { let component: ListPersonnelComponent; let fixture: ComponentFixture&lt;ListPersonnelComponent&gt;; let location: Location; let activatedRoute:ActivatedRoute; let router; const routes = [ { path: 'personnel-details', component: PersonnelDetailsComponent, relativeTo: activatedRoute, }, ]; beforeEach(async(() =&gt; { TestBed.configureTestingModule({ imports: [ RouterTestingModule.withRoutes(routes), SharedModule, BrowserAnimationsModule, HttpClientModule, ], declarations: [ListPersonnelComponent], providers: [PersonnelDataService], }).compileComponents(); })); beforeEach(() =&gt; { fixture = TestBed.createComponent(ListPersonnelComponent); component = fixture.componentInstance; router = TestBed.inject(Router); fixture.detectChanges(); }); it('should create', () =&gt; { expect(component).toBeTruthy(); }); it('should navigate to details page', () =&gt; { const routerNavigateSpy = spyOn(router, 'navigate'); component.initiateDetailsView({}); fixture.detectChanges(); expect(routerNavigateSpy).toHaveBeenCalledWith([ './personnel-details', { relativeTo: activatedRoute }, ]); }); }); </code></pre> <p>getting an error as :</p> <p><code>Variable 'activatedRoute' is used before being assigned.ts(2454)</code></p>
[ { "answer_id": 74296235, "author": "Henry Ruhs", "author_id": 924017, "author_profile": "https://Stackoverflow.com/users/924017", "pm_score": 0, "selected": false, "text": "const router: Router = TestBed.inject(Router);\n\nspyOn(router, 'navigate');\n" }, { "answer_id": 74297840, "author": "Wesley Trantham", "author_id": 11975045, "author_profile": "https://Stackoverflow.com/users/11975045", "pm_score": 2, "selected": true, "text": "fdescribe('ListPersonnelComponent', () => {\n let component: ListPersonnelComponent;\n let fixture: ComponentFixture<ListPersonnelComponent>;\n let location: Location;\n let activatedRoute:ActivatedRoute;\n let router;\n const routes = [\n { path: 'personnel-details',\n component: PersonnelDetailsComponent,\n// here is one issue, comment next line\n// relativeTo: activatedRoute,\n },\n];\n\nbeforeEach(async(() => {\n TestBed.configureTestingModule({\n imports: [\n RouterTestingModule.withRoutes(routes),\n SharedModule,\n BrowserAnimationsModule,\n HttpClientModule,\n ],\n declarations: [ListPersonnelComponent],\n providers: [PersonnelDataService],\n }).compileComponents();\n}));\n\nbeforeEach(() => {\n fixture = TestBed.createComponent(ListPersonnelComponent);\n component = fixture.componentInstance;\n router = TestBed.inject(Router);\n // grab the instance used for this test\n activatedRoute = TestBed.inject(ActivatedRoute);\n fixture.detectChanges();\n});\n\nit('should create', () => {\n expect(component).toBeTruthy();\n});\n\nit('should navigate to details page', () => {\n const routerNavigateSpy = spyOn(router, 'navigate');\n \n component.initiateDetailsView({});\n fixture.detectChanges();\n expect(routerNavigateSpy).toHaveBeenCalledWith(\n // this is an array of itself, then relativeTo is an object after\n ['./personnel-details'],\n { relativeTo: activatedRoute },\n );\n});\n});\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/218349/" ]
74,292,868
<p>I'm trying to alphabetically sort data which will be presented in a select form field. The data will be extracted from an HTTP service, and includes four categories: bread, vegetables, fruits and dairy. This is the pipe I use:</p> <pre><code>import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'orderBy' }) export class OrderByChildPipe implements PipeTransform { transform(array: any, field: string): any[] { array.sort((a: any, b: any) =&gt; { if (a[field] &lt; b[field]) { return -1; } else if (a[field] &gt; b[field]) { return 1; } else { return 0; } }); return array; } } </code></pre> <p>This is is the ts component:</p> <pre><code>import { Component, OnInit } from '@angular/core'; import { OrderByChildPipe } from 'src/app/pipes/order-by-child.pipe'; @Component({ selector: 'app-product-form-component', templateUrl: './product-form-component.component.html', styleUrls: ['./product-form-component.component.css'] }) export class ProductFormComponentComponent implements OnInit { categories$:any; constructor(private http:HttpClient) { } ngOnInit(): void { this.http.get('http://localhost:3000/product-categories').subscribe(res=&gt; { this.categories$ = res; console.log(this.categories$) }) } } </code></pre> <p>This is the relevant part from the HTML view:</p> <pre><code> &lt;label for=&quot;category&quot;&gt;Category&lt;/label&gt; &lt;select id=&quot;category&quot; *ngFor=&quot;let c of categories$ | orderBy:'name'&quot; type=&quot;text&quot; class=&quot;form-control&quot;&gt; &lt;option value=&quot;&quot;&gt;&lt;/option&gt; &lt;option value=&quot;&quot;&gt;{{c.bread.name}}&lt;/option&gt; &lt;option value=&quot;&quot;&gt;{{c.dairy.name}}&lt;/option&gt; &lt;option value=&quot;&quot;&gt;{{c.vegetables.name}}&lt;/option&gt; &lt;option value=&quot;&quot;&gt;{{c.fruits.name}}&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; </code></pre> <p>And this is the db.json:</p> <pre><code> &quot;product-categories&quot;: [ { &quot;bread&quot;: { &quot;name&quot;:&quot;Bread&quot; }, &quot;vegetables&quot;: { &quot;name&quot;:&quot;Vegetables&quot; }, &quot;dairy&quot;: { &quot;name&quot;:&quot;Dairy&quot; }, &quot;fruits&quot;: { &quot;name&quot;:&quot;Fruits&quot; } } ] </code></pre> <p>Now I know i'm not doin it correctly since I'm populating all of the options manually and this is why the pipe doesn't work. Also, I feel it is a more tedious approcach. I just need someone to point me to the correct way of doing this. The final result should be all the options sorted alphabetically (using the pipe) once the user selects the category box. Meaning:</p> <p>Bread Dairy Fruits Vegetables</p> <p>Thanks!</p>
[ { "answer_id": 74296235, "author": "Henry Ruhs", "author_id": 924017, "author_profile": "https://Stackoverflow.com/users/924017", "pm_score": 0, "selected": false, "text": "const router: Router = TestBed.inject(Router);\n\nspyOn(router, 'navigate');\n" }, { "answer_id": 74297840, "author": "Wesley Trantham", "author_id": 11975045, "author_profile": "https://Stackoverflow.com/users/11975045", "pm_score": 2, "selected": true, "text": "fdescribe('ListPersonnelComponent', () => {\n let component: ListPersonnelComponent;\n let fixture: ComponentFixture<ListPersonnelComponent>;\n let location: Location;\n let activatedRoute:ActivatedRoute;\n let router;\n const routes = [\n { path: 'personnel-details',\n component: PersonnelDetailsComponent,\n// here is one issue, comment next line\n// relativeTo: activatedRoute,\n },\n];\n\nbeforeEach(async(() => {\n TestBed.configureTestingModule({\n imports: [\n RouterTestingModule.withRoutes(routes),\n SharedModule,\n BrowserAnimationsModule,\n HttpClientModule,\n ],\n declarations: [ListPersonnelComponent],\n providers: [PersonnelDataService],\n }).compileComponents();\n}));\n\nbeforeEach(() => {\n fixture = TestBed.createComponent(ListPersonnelComponent);\n component = fixture.componentInstance;\n router = TestBed.inject(Router);\n // grab the instance used for this test\n activatedRoute = TestBed.inject(ActivatedRoute);\n fixture.detectChanges();\n});\n\nit('should create', () => {\n expect(component).toBeTruthy();\n});\n\nit('should navigate to details page', () => {\n const routerNavigateSpy = spyOn(router, 'navigate');\n \n component.initiateDetailsView({});\n fixture.detectChanges();\n expect(routerNavigateSpy).toHaveBeenCalledWith(\n // this is an array of itself, then relativeTo is an object after\n ['./personnel-details'],\n { relativeTo: activatedRoute },\n );\n});\n});\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10627257/" ]
74,292,870
<p>I have a table (##table) with an ID and the status for each day. I need a summary per month(!) how many days each ID was in which status. (##table_result). See below.</p> <p>This was my approach. But it does not work. How can I summarize the days for each ID and per status for each month?</p> <pre><code>select item, Cur_Status, convert(varchar(7), s_date, 126) as YM_S_Date, lag(s_date) over(order by month(s_date) asc) as Start_date ,s_date , datediff (day, lag(s_date) over( order by month(s_date) asc), s_date) as duration from ##table order by item, Start_date </code></pre> <p>Data:</p> <pre><code>create table ##table (item nvarchar(30), S_date date, Cur_Status nvarchar(30)); insert into ##table values ('A','2022/01/01','AA'), ('A','2022/01/02','AA'), ('A','2022/01/03','AA'), ('A','2022/01/04','BB'), ('A','2022/01/05','BB'), ('A','2022/01/06','BB'), ('A','2022/01/07','AA'), ('A','2022/01/08','AA'), ('A','2022/01/09','AA'), ('A','2022/01/10','AA'), ('A','2022/01/11','AA'), ('A','2022/01/12','AA'), ('A','2022/01/13','CC'), ('A','2022/01/14','CC'), ('A','2022/01/15','AA'), ('A','2022/01/16','DD'), ('A','2022/01/17','DD'), ('A','2022/01/18','DD'), ('A','2022/01/19','EE'), ('A','2022/01/20','AA'), ('A','2022/01/21','BB'), ('A','2022/01/22','FF'), ('A','2022/01/23','FF'), ('A','2022/01/24','FF'), ('A','2022/01/25','FF'), ('A','2022/01/26','AA'), ('A','2022/01/27','AA'), ('A','2022/01/28','AA'), ('A','2022/01/29','AA'), ('A','2022/01/30','AA'), ('A','2022/01/31','AA'), ('A','2022/02/01','AA'), ('A','2022/02/02','AA'), ('A','2022/02/03','AA'), ('A','2022/02/04','AA'), ('A','2022/02/05','AA'), ('A','2022/02/06','BB'), ('A','2022/02/07','AA'), ('A','2022/02/08','AA'), ('A','2022/02/09','AA'), ('A','2022/02/10','AA'), ('A','2022/02/11','AA'), ('A','2022/02/12','AA'), ('A','2022/02/13','CC'), ('A','2022/02/14','CC'), ('A','2022/02/15','AA'), ('A','2022/02/16','DD'), ('A','2022/02/17','DD'), ('A','2022/02/18','DD'), ('A','2022/02/19','EE'), ('A','2022/02/20','AA'), ('A','2022/02/21','BB'), ('A','2022/02/22','AA'), ('A','2022/02/23','AA'), ('A','2022/02/24','AA'), ('A','2022/02/25','FF'), ('A','2022/02/26','AA'), ('A','2022/02/27','AA'), ('A','2022/02/28','AA'), ('A','2022/03/01','AA'), ('A','2022/03/02','AA'), ('A','2022/03/03','BB'), ('A','2022/03/04','AA'), ('B','2022/01/01','AA'), ('B','2022/01/02','AA'), ('B','2022/01/03','AA'), ('B','2022/01/04','BB'), ('B','2022/01/05','BB'), ('B','2022/01/06','BB'), ('B','2022/01/07','AA'), ('B','2022/01/08','AA'), ('B','2022/01/09','AA'), ('B','2022/01/10','AA'), ('B','2022/01/11','AA'), ('B','2022/01/12','AA'), ('B','2022/01/13','AA'), ('B','2022/01/14','AA'), ('B','2022/01/15','AA'), ('B','2022/01/16','AA'), ('B','2022/01/17','AA'), ('B','2022/01/18','AA'), ('B','2022/01/19','AA'), ('B','2022/01/20','AA'), ('B','2022/01/21','AA'), ('B','2022/01/22','AA'), ('B','2022/01/23','AA'), ('B','2022/01/24','AA'), ('B','2022/01/25','AA'), ('B','2022/01/26','AA'), ('B','2022/01/27','AA'), ('B','2022/01/28','AA'), ('B','2022/01/29','AA'), ('B','2022/01/30','AA'), ('B','2022/01/31','AA'), ('B','2022/02/01','AA'), ('B','2022/02/02','AA'), ('B','2022/02/03','AA'), ('B','2022/02/04','FF'), ('B','2022/02/05','FF'), ('B','2022/02/06','FF'), ('B','2022/02/07','AA'), ('B','2022/02/08','AA'), ('B','2022/02/09','AA'), ('B','2022/02/10','AA'), ('B','2022/02/11','AA'), ('B','2022/02/12','AA'), ('B','2022/02/13','CC'), ('B','2022/02/14','CC'), ('B','2022/02/15','AA'), ('B','2022/02/16','DD'), ('B','2022/02/17','DD'), ('B','2022/02/18','DD'), ('B','2022/02/19','EE'), ('B','2022/02/20','AA'), ('B','2022/02/21','AA'), ('B','2022/02/22','AA'), ('B','2022/02/23','AA'), ('B','2022/02/24','AA'), ('B','2022/02/25','FF'), ('B','2022/02/26','AA'), ('B','2022/02/27','AA'), ('B','2022/02/28','AA'), ('B','2022/03/01','BB'), ('B','2022/03/02','AA'), ('B','2022/03/03','AA'), ('B','2022/03/04','AA'), ('B','2022/03/05','AA'), ('B','2022/03/06','AA'), ('B','2022/03/07','AA'), ('B','2022/03/08','AA'), ('B','2022/03/09','BB'), ('B','2022/03/10','BB'), ('B','2022/03/11','BB'), ('B','2022/03/12','BB'), ('B','2022/03/13','BB'), ('B','2022/03/14','AA'), ('B','2022/03/15','AA'), ('B','2022/03/16','AA'), ('B','2022/03/17','AA'), ('B','2022/03/18','AA'), ('B','2022/03/19','DD'), ('B','2022/03/20','DD'), ('B','2022/03/21','AA'), ('B','2022/03/22','AA'), ('B','2022/03/23','AA'), ('B','2022/03/24','AA'), ('B','2022/03/25','BB'), ('B','2022/03/26','AA'), ('B','2022/03/27','AA'), ('B','2022/03/28','BB'), ('B','2022/03/30','AA'), ('B','2022/03/31','BB'), ('B','2022/04/01','BB'), ('B','2022/04/02','BB'), ('B','2022/04/04','BB'), ('C','2022/04/04','BB'), ('C','2022/04/05','BB'), ('C','2022/04/06','BB'), ('C','2022/04/07','AA'), ('C','2022/04/08','AA'), ('C','2022/04/09','AA'), ('C','2022/04/10','AA'), ('C','2022/04/11','AA'), ('C','2022/04/12','AA'), ('C','2022/04/13','CC'), ('C','2022/04/14','CC'), ('E','2022/04/15','AA'), ('E','2022/04/16','DD'), ('E','2022/04/17','DD'), ('E','2022/04/18','DD'), ('E','2022/04/19','EE'), ('E','2022/04/20','AA'), ('E','2022/04/21','BB'), ('E','2022/04/22','FF'), ('E','2022/04/23','FF'), ('E','2022/04/24','FF'), ('E','2022/04/25','FF'), ('E','2022/04/26','AA'), ('E','2022/04/27','AA'), ('E','2022/04/28','AA'), ('E','2022/04/29','AA'), ('E','2022/04/30','FF'), ('E','2022/05/01','FF'), ('E','2022/05/01','FF') ; select * from ##table order by item, S_date </code></pre> <p>Expected result:</p> <pre><code>create table ##table_Result (item nvarchar(30), Start_date date, End_date date, Cur_Status nvarchar(30), Duration int); insert into ##table_result values ('A','2022/01/01','2022/01/03','AA','3' ), ('A','2022/01/04','2022/01/06','BB','3' ), ('A','2022/01/07','2022/01/12','AA','4' ), ('A','2022/01/13','2022/01/14','CC','2' ), ('A','2022/01/15','2022/01/15','AA','2' ), ('A','2022/01/16','2022/01/18','DD','2' ), ('A','2022/01/19','2022/01/19','EE','1' ), ('A','2022/01/20','2022/01/20','AA','1' ), ('A','2022/01/21','2022/01/21','BB','1' ), ('A','2022/01/22','2022/01/25','FF','4' ), ('A','2022/01/26','2022/01/31','AA','6' ), ('A','2022/02/01','2022/02/05','AA','5' ), ('A','2022/02/06','2022/02/06','BB','5' ), ('A','2022/02/07','2022/02/12','AA','6' ), ('A','2022/02/13','2022/02/14','CC','2' ), ('A','2022/02/15','2022/02/15','AA','1' ), ('A','2022/02/16','2022/02/18','DD','3' ), ('A','2022/02/19','2022/02/19','EE','1' ), ('A','2022/02/20','2022/02/20','AA','1' ), ('A','2022/02/21','2022/02/21','BB','1' ), ('A','2022/02/22','2022/02/24','AA','1' ), ('A','2022/02/25','2022/02/25','FF','1' ), ('A','2022/02/26','2022/02/28','AA','3' ), ('A','2022/03/01','2022/03/02','AA','2' ), ('A','2022/03/03','2022/03/03','BB','2' ), ('A','2022/03/04','2022/03/04','AA','2' ), ('B','2022/01/01','2022/01/02','AA','2' ), ('B','2022/01/03','2022/01/03','AA','1' ), ('B','2022/01/04','2022/01/06','BB','2' ), ('B','2022/01/07','2022/01/31','AA','25'), ('B','2022/02/01','2022/01/03','AA','3') </code></pre>
[ { "answer_id": 74293439, "author": "Patrick Hurst", "author_id": 18522514, "author_profile": "https://Stackoverflow.com/users/18522514", "pm_score": 1, "selected": false, "text": "DECLARE @table TABLE (item NVARCHAR(30), S_date DATE, Cur_Status NVARCHAR(30));\nINSERT INTO @table (item, S_date, Cur_Status) VALUES \n('A','2022/01/01','AA'), ('A','2022/01/02','AA'), ('A','2022/01/03','AA'), ('A','2022/01/04','BB'), ('A','2022/01/05','BB'), ('A','2022/01/06','BB'), ('A','2022/01/07','AA'), ('A','2022/01/08','AA'), ('A','2022/01/09','AA'), ('A','2022/01/10','AA'), \n('A','2022/01/11','AA'), ('A','2022/01/12','AA'), ('A','2022/01/13','CC'), ('A','2022/01/14','CC'), ('A','2022/01/15','AA'), ('A','2022/01/16','DD'), ('A','2022/01/17','DD'), ('A','2022/01/18','DD'), ('A','2022/01/19','EE'), ('A','2022/01/20','AA'), \n('A','2022/01/21','BB'), ('A','2022/01/22','FF'), ('A','2022/01/23','FF'), ('A','2022/01/24','FF'), ('A','2022/01/25','FF'), ('A','2022/01/26','AA'), ('A','2022/01/27','AA'), ('A','2022/01/28','AA'), ('A','2022/01/29','AA'), ('A','2022/01/30','AA'), \n('A','2022/01/31','AA'), ('A','2022/02/01','AA'), ('A','2022/02/02','AA'), ('A','2022/02/03','AA'), ('A','2022/02/04','AA'), ('A','2022/02/05','AA'), ('A','2022/02/06','BB'), ('A','2022/02/07','AA'), ('A','2022/02/08','AA'), ('A','2022/02/09','AA'), \n('A','2022/02/10','AA'), ('A','2022/02/11','AA'), ('A','2022/02/12','AA'), ('A','2022/02/13','CC'), ('A','2022/02/14','CC'), ('A','2022/02/15','AA'), ('A','2022/02/16','DD'), ('A','2022/02/17','DD'), ('A','2022/02/18','DD'), ('A','2022/02/19','EE'), \n('A','2022/02/20','AA'), ('A','2022/02/21','BB'), ('A','2022/02/22','AA'), ('A','2022/02/23','AA'), ('A','2022/02/24','AA'), ('A','2022/02/25','FF'), ('A','2022/02/26','AA'), ('A','2022/02/27','AA'), ('A','2022/02/28','AA'), ('A','2022/03/01','AA'), \n('A','2022/03/02','AA'), ('A','2022/03/03','BB'), ('A','2022/03/04','AA'), ('B','2022/01/01','AA'), ('B','2022/01/02','AA'), ('B','2022/01/03','AA'), ('B','2022/01/04','BB'), ('B','2022/01/05','BB'), ('B','2022/01/06','BB'), ('B','2022/01/07','AA'), \n('B','2022/01/08','AA'), ('B','2022/01/09','AA'), ('B','2022/01/10','AA'), ('B','2022/01/11','AA'), ('B','2022/01/12','AA'), ('B','2022/01/13','AA'), ('B','2022/01/14','AA'), ('B','2022/01/15','AA'), ('B','2022/01/16','AA'), ('B','2022/01/17','AA'), \n('B','2022/01/18','AA'), ('B','2022/01/19','AA'), ('B','2022/01/20','AA'), ('B','2022/01/21','AA'), ('B','2022/01/22','AA'), ('B','2022/01/23','AA'), ('B','2022/01/24','AA'), ('B','2022/01/25','AA'), ('B','2022/01/26','AA'), ('B','2022/01/27','AA'), \n('B','2022/01/28','AA'), ('B','2022/01/29','AA'), ('B','2022/01/30','AA'), ('B','2022/01/31','AA'), ('B','2022/02/01','AA'), ('B','2022/02/02','AA'), ('B','2022/02/03','AA'), ('B','2022/02/04','FF'), ('B','2022/02/05','FF'), ('B','2022/02/06','FF'), \n('B','2022/02/07','AA'), ('B','2022/02/08','AA'), ('B','2022/02/09','AA'), ('B','2022/02/10','AA'), ('B','2022/02/11','AA'), ('B','2022/02/12','AA'), ('B','2022/02/13','CC'), ('B','2022/02/14','CC'), ('B','2022/02/15','AA'), ('B','2022/02/16','DD'), \n('B','2022/02/17','DD'), ('B','2022/02/18','DD'), ('B','2022/02/19','EE'), ('B','2022/02/20','AA'), ('B','2022/02/21','AA'), ('B','2022/02/22','AA'), ('B','2022/02/23','AA'), ('B','2022/02/24','AA'), ('B','2022/02/25','FF'), ('B','2022/02/26','AA'), \n('B','2022/02/27','AA'), ('B','2022/02/28','AA'), ('B','2022/03/01','BB'), ('B','2022/03/02','AA'), ('B','2022/03/03','AA'), ('B','2022/03/04','AA'), ('B','2022/03/05','AA'), ('B','2022/03/06','AA'), ('B','2022/03/07','AA'), ('B','2022/03/08','AA'), \n('B','2022/03/09','BB'), ('B','2022/03/10','BB'), ('B','2022/03/11','BB'), ('B','2022/03/12','BB'), ('B','2022/03/13','BB'), ('B','2022/03/14','AA'), ('B','2022/03/15','AA'), ('B','2022/03/16','AA'), ('B','2022/03/17','AA'), ('B','2022/03/18','AA'), \n('B','2022/03/19','DD'), ('B','2022/03/20','DD'), ('B','2022/03/21','AA'), ('B','2022/03/22','AA'), ('B','2022/03/23','AA'), ('B','2022/03/24','AA'), ('B','2022/03/25','BB'), ('B','2022/03/26','AA'), ('B','2022/03/27','AA'), ('B','2022/03/28','BB'), \n('B','2022/03/30','AA'), ('B','2022/03/31','BB'), ('B','2022/04/01','BB'), ('B','2022/04/02','BB'), ('B','2022/04/04','BB'), ('C','2022/04/04','BB'), ('C','2022/04/05','BB'), ('C','2022/04/06','BB'), ('C','2022/04/07','AA'), ('C','2022/04/08','AA'), \n('C','2022/04/09','AA'), ('C','2022/04/10','AA'), ('C','2022/04/11','AA'), ('C','2022/04/12','AA'), ('C','2022/04/13','CC'), ('C','2022/04/14','CC'), ('E','2022/04/15','AA'), ('E','2022/04/16','DD'), ('E','2022/04/17','DD'), ('E','2022/04/18','DD'), \n('E','2022/04/19','EE'), ('E','2022/04/20','AA'), ('E','2022/04/21','BB'), ('E','2022/04/22','FF'), ('E','2022/04/23','FF'), ('E','2022/04/24','FF'), ('E','2022/04/25','FF'), ('E','2022/04/26','AA'), ('E','2022/04/27','AA'), ('E','2022/04/28','AA'), \n('E','2022/04/29','AA'), ('E','2022/04/30','FF'), ('E','2022/05/01','FF'), ('E','2022/05/01','FF') ;\n" }, { "answer_id": 74304122, "author": "JMabee", "author_id": 8126219, "author_profile": "https://Stackoverflow.com/users/8126219", "pm_score": 1, "selected": true, "text": "SELECT Item,MIN(S_Date) Start_Date, MAX(S_Date) End_Date, Cur_Status, DATEDIFF(day,MIN(S_Date), MAX(s_DATE)) + 1 Duration\nFROM\n(\n SELECT * ,SUM(CASE WHEN Cur_Status <> LG THEN 1 ELSE 0 END) OVER(PARTITION BY Item,YR,MN ORDER BY s_Date) GRP\n FROM\n (\n select * ,MONTH(s_Date) MN, Year(s_Date) YR, LAG(Cur_Status,1) OVER(PARTITION BY Item ORDER BY S_Date) LG\n from #table\n ) X\n) Y\n\nGROUP BY Item,GRP,YR,MN,Cur_Status\nORDER BY Item,Start_Date\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12823444/" ]
74,292,956
<p>I'm trying to compare the minimal values of two arrays.</p> <p>I'm getting the following compilation error:</p> <blockquote> <p>Operator '&gt;' cannot be applied to 'java.util.OptionalInt', 'java.util.OptionalInt'</p> </blockquote> <p>What am I doing wrong?</p> <p><em>My code:</em></p> <pre><code>public static void main(String[] args) { int [] ints = {12,6,8,242}; int [] ints1 = {5,1,5432,5,76,146,8}; if(Arrays.stream(ints).min()&gt;Arrays.stream(ints1).min()){ System.out.println(Arrays.stream(ints1).min()); } } </code></pre>
[ { "answer_id": 74293022, "author": "Marcus Dunn", "author_id": 12639399, "author_profile": "https://Stackoverflow.com/users/12639399", "pm_score": 2, "selected": false, "text": "min" }, { "answer_id": 74293875, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "Optional" }, { "answer_id": 74293963, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 3, "selected": true, "text": "min()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20190996/" ]
74,292,984
<p>I'm very new to using Django and coding in general. So I have figured out how to make the form submit to my database but now when it submits, it just brings you to the blank blog_post view and I'm not understanding how to redirect correctly.</p> <p>here is the views.py:</p> <pre><code>from django.shortcuts import render, redirect from .models import post from django.views import generic, View from django.views.decorators.http import require_GET from django.http import HttpResponse, HttpResponseRedirect from .forms import PostForm # Views for post list class postslist(generic.ListView): model = post queryset = post.objects.filter(status=1).order_by('-created_on') template_name = 'home.html' paginate_by = 4 # view for individual post class postdetail(generic.DetailView): model = post template_name = &quot;post.html&quot; def blog_post(request): form = PostForm(request.POST or None) if request.method == &quot;POST&quot;: if form.is_valid(): form.instance.user = request.user form.save() return redirect(&quot;blog:success&quot;) context = {'form': form, } return render(request, &quot;create_post.html&quot;, context) def success(request): return HttpResponseRedirect(&quot;home.html&quot;) </code></pre> <p>urls.py:</p> <pre><code>from . import views from django.urls import path, include from .views import * urlpatterns = [ # home path('', views.postslist.as_view(), name='home'), # add post path('blog_post/', views.blog_post, name='blog_post'), # success for blog post path('success/', views.success, name='success'), # posts path('&lt;slug:slug&gt;/', views.postdetail.as_view(), name='post_detail'), ] </code></pre> <p>I have tried a few variations of httpresponseredirect and redirect but I just cant wrap my head around it, nor can I find it online.</p>
[ { "answer_id": 74293022, "author": "Marcus Dunn", "author_id": 12639399, "author_profile": "https://Stackoverflow.com/users/12639399", "pm_score": 2, "selected": false, "text": "min" }, { "answer_id": 74293875, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "Optional" }, { "answer_id": 74293963, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 3, "selected": true, "text": "min()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74292984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399868/" ]
74,293,003
<p>I am receiving files and for some files columns are named differently. For example:</p> <ol> <li>In file 1, column names are: &quot;studentID&quot; , &quot;ADDRESS&quot;, &quot;Phone_number&quot;.</li> <li>In file 2, column names are: &quot;Common_ID&quot;, &quot;Common_Address&quot;, &quot;Mobile_number&quot;.</li> <li>In file 3, column names are: &quot;S_StudentID&quot;, &quot;S_ADDRESS&quot;, &quot;HOME_MOBILE&quot;.</li> </ol> <p>I want to pass a dictionary after loading the file data into dataframes and in that dictionary I want to pass values like:</p> <pre class="lang-none prettyprint-override"><code>StudentId -&gt; STUDENT_ID Common_ID -&gt; STUDENT_ID S_StudentID -&gt; STUDENT_ID ADDRESS -&gt; S_ADDRESS Common_Address -&gt; S_ADDRESS S_ADDRESS -&gt; S_ADDRESS </code></pre> <p>The reason for doing this because in my next dataframe I am reading column names like &quot;STUDENT_ID&quot;, &quot;S_ADDRESS&quot; and if it will not find &quot;S_ADDRESS&quot;, &quot;STUDENT_ID&quot; names in the dataframe, it will throw error for files whose names are not standardized. I want to run my dataframe and get values from those files after renaming in the above DF and one question when in run the new df will it pick the column name form dictionary having data in it.</p>
[ { "answer_id": 74293022, "author": "Marcus Dunn", "author_id": 12639399, "author_profile": "https://Stackoverflow.com/users/12639399", "pm_score": 2, "selected": false, "text": "min" }, { "answer_id": 74293875, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "Optional" }, { "answer_id": 74293963, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 3, "selected": true, "text": "min()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20216373/" ]
74,293,031
<p>I have a CSV file with two columns (permno_adj and publn_year) and I want to combine them but don't know how to do it.</p> <p><strong>The code I am using:</strong></p> <pre><code>patents = pd.read_csv('E:/Work/file.csv') patents = patents[['publn_nr', 'permno_adj', 'publn_year', 'IPC1']].dropna().drop_duplicates().reset_index(drop=True) patents = patents[(patents['publn_year'] &gt;= 1980) &amp; (patents['publn_year'] &lt; 2016)].reset_index(drop=True) print(patents) </code></pre> <p><strong>The output I am currently getting i:</strong></p> <pre><code> publn_nr permno_adj publn_year IPC1 0 1830 US4060B 2005 F16F 1 24429 US4060A 2004 B29C 2 24943 US1794 2006 C08J 3 26115 US133366B 1999 A61B 4 31737 US4060A 2004 C08F </code></pre> <p>The output I am looking for is something like &quot;US4060B2005&quot;</p>
[ { "answer_id": 74293022, "author": "Marcus Dunn", "author_id": 12639399, "author_profile": "https://Stackoverflow.com/users/12639399", "pm_score": 2, "selected": false, "text": "min" }, { "answer_id": 74293875, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "Optional" }, { "answer_id": 74293963, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 3, "selected": true, "text": "min()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19381439/" ]
74,293,042
<p>I'm trying to implement a Spring Boot Rest API using Spring Data Jdbc with H2 Database. This is a microservice, and I'm trying to send a POST request to the microservice from an angular app. I know my POST is working correctly from Angular. Inside of microservice, I am trying to save the POST request to a local H2 database. This should be relatively straight forward based on documentation I've read online, but I am getting error messages. Any help would be greatly appreciated. Here are the files I have setup inside my spring boot microservice (titled 'order'):</p> <p>OrderController.java:</p> <pre><code>package com.clothingfly.order; import java.util.ListIterator; import org.springframework.web.client.RestTemplate; import com.clothingfly.order.Model.Item; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import com.clothingfly.order.Model.Order; @RestController @CrossOrigin(origins = &quot;http://localhost:4200&quot;) public class OrderController { @Autowired TempOrderRepository orderRepository; @PostMapping(&quot;/order&quot;) public Order postOrder(@RequestBody Order order) { Order _order = orderRepository.save(new Order(order.getId(), order.getAddress(), order.getPayment(), order.getItems())); return _order; } } </code></pre> <p>TempOrderRepository.java:</p> <pre><code>package com.clothingfly.order; import org.springframework.data.jpa.repository.JpaRepository; import com.clothingfly.order.Model.Order; public interface TempOrderRepository extends JpaRepository&lt;Order, Long&gt;{ } </code></pre> <p>OrderApplication.java:</p> <pre><code>package com.clothingfly.order; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class OrderApplication { public static void main(String[] args) { SpringApplication.run(OrderApplication.class, args); } } </code></pre> <p>And I have a model named Order.java:</p> <pre><code>package com.clothingfly.order.Model; import java.util.List; import javax.persistence.*; import org.springframework.data.annotation.Id; @Entity @Table(name = &quot;orders&quot;) public class Order { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(name = &quot;Address&quot;) private Address address; @Column(name = &quot;Payment&quot;) private PaymentInfo payment; @Column(name = &quot;Items&quot;) private List&lt;Item&gt; items; @Column(name = &quot;Error&quot;) private String error; public Order() { } public Order(long id, Address address, PaymentInfo payment, List&lt;Item&gt; items){ this.id = id; this.address = address; this.payment = payment; this.items = items; this.error = &quot;&quot;; } public long getId() { return id; } public Address getAddress() { return address; } public PaymentInfo getPayment() { return payment; } public List&lt;Item&gt; getItems() { return items; } public String getError() { return error; } public void setError(String error) { this.error = error; } } </code></pre> <p>The Order model takes in three other models: Item.java:</p> <pre><code>package com.clothingfly.order.Model; import javax.persistence.*; @Entity @Table(name = &quot;items&quot;) public class Item { @Id @GeneratedValue @Column(name = &quot;id&quot;) private long id; @Column(name = &quot;name&quot;) private String name; @Column(name = &quot;price&quot;) private float price; @Column(name = &quot;imageUrl&quot;) private String imageUrl; @Column(name = &quot;quantity&quot;) private long quantity; @Column(name = &quot;inventory&quot;) private long inventory; public long getId() { return id; } public String getName() { return name; } public float getPrice() { return price; } public long getQuantity() { return quantity; } public long getInventory() { return inventory; } public String getImageUrl(){ return imageUrl; } public void setInventory(long inventory) { this.inventory = inventory; } public void setName(String name) { this.name = name; } public void setPrice(float price) { this.price = price; } public void setQuantity(long quantity) { this.quantity = quantity; } public Item(long id, String name, float price, long quantity, long inventory, String imageUrl) { this.id = id; this.name = name; this.price = price; this.quantity = quantity; this.inventory = inventory; this.imageUrl = imageUrl; } public Item() { } } </code></pre> <p>Address.java:</p> <pre><code>package com.clothingfly.order.Model; import javax.persistence.*; @Entity @Table(name = &quot;addresses&quot;) public class Address { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(name = &quot;firstName&quot;) private String firstName; @Column(name = &quot;lastName&quot;) private String lastName; @Column(name = &quot;address&quot;) private String address; @Column(name = &quot;country&quot;) private String country; @Column(name = &quot;apartmentNo&quot;) private String apartmentNo; @Column(name = &quot;state&quot;) private String state; @Column(name = &quot;city&quot;) private String city; @Column(name = &quot;zipcode&quot;) private String zipcode; public Address() { } public Address(String firstName, String lastName, String address, String country, String apartmentNo, String state, String city, String zipcode) { this.firstName = firstName; this.lastName = lastName; this.address = address; this.country = country; this.apartmentNo = apartmentNo; this.state = state; this.city = city; this.zipcode = zipcode; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getApartmentNo() { return apartmentNo; } public void setApartmentNo(String apartmentNo) { this.apartmentNo = apartmentNo; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } } </code></pre> <p>PaymentInfo.java:</p> <pre><code>package com.clothingfly.order.Model; import javax.persistence.*; @Entity @Table(name = &quot;payments&quot;) public class PaymentInfo { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(name = &quot;cardHolder&quot;) private String cardHolder; @Column(name = &quot;cardNumber&quot;) private String cardNumber; @Column(name = &quot;expirationDate&quot;) private String expirationDate; @Column(name = &quot;cvv&quot;) private String cvv; public PaymentInfo(String cardHolder, String cardNumber, String expirationDate, String cvv) { this.cardHolder = cardHolder; this.cardNumber = cardNumber; this.expirationDate = expirationDate; this.cvv = cvv; } public String getCardHolder() { return cardHolder; } public void setCardHolder(String cardHolder) { this.cardHolder = cardHolder; } public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public String getExpirationDate() { return expirationDate; } public void setExpirationDate(String expirationDate) { this.expirationDate = expirationDate; } public String getCvv() { return cvv; } public void setCvv(String cvv) { this.cvv = cvv; } } </code></pre> <p>I'm getting the following error when trying to run microservice: <code>Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: com.clothingfly.order.Model.Address, at table: orders, for columns: [org.hibernate.mapping.Column(address)]</code></p> <p>How would I go about fixing this? I want to be able to display all of my models inside a table.</p> <p>I tried changing Address model so that it only returns a string of the city, but that seemed to cause more issues than anything.</p>
[ { "answer_id": 74293022, "author": "Marcus Dunn", "author_id": 12639399, "author_profile": "https://Stackoverflow.com/users/12639399", "pm_score": 2, "selected": false, "text": "min" }, { "answer_id": 74293875, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "Optional" }, { "answer_id": 74293963, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 3, "selected": true, "text": "min()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2302953/" ]
74,293,109
<p>I'm attempting to create a dynamic flask route. I want to create a parallel page for my route that internal users can see when they add 'vo/' before the URL. So essentially there are two different routes <code>/vo/feedbackform</code> and <code>/feedbackform</code>. I know I could just create two routes in the app, but I'm hoping I can optimize.</p> <pre><code>@app.route('/&lt;x&gt;feedbackform', methods=['GET', 'POST']) def feedback_portal(x): if x == 'vo/': return render_template('feedback_vo.html', title='Inquiry Submission') elif x == '': return render_template('feedback.html', title='Inquiry Submission') </code></pre> <p>So far, this only works when the URL using the vo/ in the <code>x</code> part of the URL by my <code>elif</code> isn't working, and I get an error.</p>
[ { "answer_id": 74294316, "author": "ilias-sp", "author_id": 5736671, "author_profile": "https://Stackoverflow.com/users/5736671", "pm_score": 1, "selected": false, "text": "request.path" }, { "answer_id": 74294439, "author": "Mike Mann", "author_id": 9105621, "author_profile": "https://Stackoverflow.com/users/9105621", "pm_score": 2, "selected": true, "text": "@app.route('/feedbackform/', methods=['GET', 'POST'], defaults={'x': None})\n@app.route('/<x>/feedbackform/', methods=['GET', 'POST'])\ndef feedback_portal(x):\n if x=='vo':\n return render_template('feedback_vo.html', title='Inquiry Submission')\n elif x==None:\n return render_template('feedback.html', title='Inquiry Submission')\n" }, { "answer_id": 74295262, "author": "TheMonarch", "author_id": 12634182, "author_profile": "https://Stackoverflow.com/users/12634182", "pm_score": -1, "selected": false, "text": "@app.route('/feedbackform/', methods=['GET', 'POST'])\ndef feedback_portal():\n return render_template('feedback.html', title='Inquiry Submission')\n\n@app.route('/vo/feedbackform/', methods=['GET', 'POST'])\ndef feedback_portal_vo():\n return render_template('feedback_vo.html', title='Inquiry Submission')\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9105621/" ]
74,293,125
<p><a href="https://i.stack.imgur.com/cr9wE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cr9wE.png" alt="enter image description here" /></a></p> <p>How to convert comma separated values in to multiple columns using python DataFrame, as shown in the figure?</p>
[ { "answer_id": 74293219, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": false, "text": "','" }, { "answer_id": 74293579, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 1, "selected": false, "text": "str.get_dummies" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15824200/" ]
74,293,128
<p>I have this array of objects and I want to loop through in a way that all the objects that have same value for name property, like first, third and last object has same value (person 1) for name property and total its amount.</p> <p>like the result should be like:- person 1 - 434 (total amount)</p> <pre><code>const arr = [ { name: &quot;person 1&quot;, amount: 154 }, { name: &quot;person 2&quot;, amount: 240 }, { name: &quot;person 1&quot;, amount: 100 }, { name: &quot;person 2&quot;, amount: 160 }, { name: &quot;person 2&quot;, amount: 140 }, { name: &quot;person 1&quot;, amount: 180 }, ]; </code></pre>
[ { "answer_id": 74293219, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": false, "text": "','" }, { "answer_id": 74293579, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 1, "selected": false, "text": "str.get_dummies" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19988729/" ]
74,293,145
<p>My unity project with firebase integrated got errors while archiving the Xcode project. I have searched for some issues that may be the same as mine, but with no luck. I have tried to install cocoa pods and success to build the Xcode project with no errors. When I archived the Xcode project, it shows so many Undefined symbols like the picture below <a href="https://i.stack.imgur.com/nfs6L.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nfs6L.jpg" alt="enter image description here" /></a></p> <p>Xcode Version: 14.1.<br /> Firebase SDK Version: 10.0.1.<br /> Unity Version: 2021.3.7f1.</p>
[ { "answer_id": 74293219, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": false, "text": "','" }, { "answer_id": 74293579, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 1, "selected": false, "text": "str.get_dummies" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5584806/" ]
74,293,201
<p>Assume I have the following list of strings:</p> <pre><code>animals = [ 'rhino, grey, 30 July 2022', 'giraffe, 30 March 2022', 'bird', 'llama, brown, 8 April 2022', 'tiger' ] </code></pre> <p>where the first item of the list (animal[0]) is the string <code> rhino,grey,30 July 2022</code> , the second (animal[1]) is <code>giraffe, 30 March 2022</code> and the third is <code>bird</code> and so on. The order of the items in each string is always animal name, color, birth date, but in some cases, color or date might be missing.</p> <p>The code I would like to write would need to do the following: for each string in the list, split based on the comma, and add the result to a new list:</p> <p>I have:</p> <pre><code>name = [] color = [] birthday= [] for animal in animals: name.append((animal.split(&quot;,&quot;))[0]) color.append((animal.split(&quot;,&quot;))[1]) birthday.append((animal.split(&quot;,&quot;))[2]) </code></pre> <p>However, this does not work because in some cases, the color or the birthday might be missing, so I run into an IndexError (list index out of range). Can anyone think of a way of fixing this? for example, by counting the number of times that the string has been split?</p>
[ { "answer_id": 74293416, "author": "Abhi", "author_id": 7430727, "author_profile": "https://Stackoverflow.com/users/7430727", "pm_score": 2, "selected": true, "text": "birthday" }, { "answer_id": 74293464, "author": "finman69", "author_id": 19628700, "author_profile": "https://Stackoverflow.com/users/19628700", "pm_score": 0, "selected": false, "text": "name = []\ncolor = []\nbirthday= []\n\nfor animal in animals:\n split_animal = animal.split(\",\")\n if len(split_animal) == 3:\n name.append(split_animal[0])\n color.append(split_animal[1])\n birthday.append(split_animal[2])\n elif len(split_animal) == 2:\n name.append(split_animal[0])\n color.append(split_animal[1])\n elif len(split_animal) == 1:\n name.append(split_animal[0])\n else:\n pass\n" }, { "answer_id": 74293753, "author": "Igor Moraru", "author_id": 4645291, "author_profile": "https://Stackoverflow.com/users/4645291", "pm_score": 0, "selected": false, "text": "def split_props(animal):\n parts = animal.split(',')\n if len(parts) > 1 and re.search('[0-9]+', parts[1]):\n parts.insert(1, None)\n return parts\n\nanimal_props = [split_props(animal) for animal in animals]\n\nname, color, birthday = [[a[i] if i < len(a) else None for a in animal_props] for i in [0,1,2]]\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10744269/" ]
74,293,208
<h3>Using a regular expression, I need to match only the IPv4 subnet mask from the given input string:</h3> <pre><code>ip=10.0.20.100::10.0.20.1:255.255.254.0:ws01.example.com::off </code></pre> <p>For testing this input string is contained in a text file called file.txt, however the actual use case will be to parse /proc/cmdline, and I will need a solution that starts parsing, counting fields, and matching after encountering &quot;ip=&quot; until the next white space character.</p> <p>I'm using bash 4.2.46 with GNU grep 2.20 on an EL 7.9 workstation, x86_64 to test the expression.</p> <p>Based on examples I've seen looking at other questions, I've come up with the following grep command and PCRE regular expression which gives output that is very close to what I need.</p> <pre class="lang-bash prettyprint-override"><code>[user@ws01 ~]$ grep -o -P '(?&lt;!:)(?:\:[0-9])(.*?)(?=:)' file.txt :255.255.254.0 </code></pre> <p>My understanding of what I've done here is that, I've started with a negative lookbehind with a &quot;:&quot; character to try and exclude the first &quot;::&quot; field, followed by a non capturing group to match on an escaped &quot;:&quot; character, followed by a number, [0-9], then a capturing group with .*?, for the actual match of the string itself, and finally a look ahead for the next &quot;:&quot; character.</p> <p>The problem is that this gives the desired string, but includes an extra : character at the beginning of the string.</p> <p>Expected output should look like this:</p> <pre><code>255.255.254.0 </code></pre> <p>What's making this tricky for me to figure out is that the delimiters are not consistent. The string includes both double colons, and single colon fields, so I haven't been able to just simply match on the string between the delimiters. The reason for this is because a field can have an empty value. For example</p> <pre><code>:&lt;null&gt;:ip:gw:netmask:hostname:&lt;null&gt;:off </code></pre> <p>Null is shown here to indicate an omitted value not passed by the user, that the user does not need to provide for the intended purpose.</p> <p>I've tried a few different expressions as suggested in other answers that use negative look behinds and look aheads to not start matching at a : which is neighbored by another :</p> <p>For example, see this question: <a href="https://stackoverflow.com/questions/1454913/regular-expression-to-find-a-string-included-between-two-characters-while-exclud">Regular Expression to find a string included between two characters while EXCLUDING the delimiters</a></p> <p>If I can start matching at the first single colon, by itself, which is not followed by or preceded by another : character, while excluding the colon character as the delimiter, and continue matching until the next single colon which is also not neighboring another : and without including the colon character, that should match the desired string.</p> <p>I'm able to match the exact string by including &quot;255&quot; in an expression like this: (Which will work for all of our present use cases)</p> <pre class="lang-bash prettyprint-override"><code>[user@ws01 ~]$ grep -o -P '(?:)255.*?(?=:)' file.txt 255.255.254.0 </code></pre> <p>The logic problem here is that the subnet mask itself, may not always start with &quot;255&quot;, but it should be a number, [0-9] which is why I'm attempting to use that in the expression above. For the sake of simplicity, I don't need to validate that it's not greater than 255.</p>
[ { "answer_id": 74293416, "author": "Abhi", "author_id": 7430727, "author_profile": "https://Stackoverflow.com/users/7430727", "pm_score": 2, "selected": true, "text": "birthday" }, { "answer_id": 74293464, "author": "finman69", "author_id": 19628700, "author_profile": "https://Stackoverflow.com/users/19628700", "pm_score": 0, "selected": false, "text": "name = []\ncolor = []\nbirthday= []\n\nfor animal in animals:\n split_animal = animal.split(\",\")\n if len(split_animal) == 3:\n name.append(split_animal[0])\n color.append(split_animal[1])\n birthday.append(split_animal[2])\n elif len(split_animal) == 2:\n name.append(split_animal[0])\n color.append(split_animal[1])\n elif len(split_animal) == 1:\n name.append(split_animal[0])\n else:\n pass\n" }, { "answer_id": 74293753, "author": "Igor Moraru", "author_id": 4645291, "author_profile": "https://Stackoverflow.com/users/4645291", "pm_score": 0, "selected": false, "text": "def split_props(animal):\n parts = animal.split(',')\n if len(parts) > 1 and re.search('[0-9]+', parts[1]):\n parts.insert(1, None)\n return parts\n\nanimal_props = [split_props(animal) for animal in animals]\n\nname, color, birthday = [[a[i] if i < len(a) else None for a in animal_props] for i in [0,1,2]]\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6581161/" ]
74,293,226
<p>I am trying to learn linked list in ppython. This is a really simple code. All I am trying to do here is to call a class's constructor. But it is giving me an error. It is saying:</p> <pre><code>#This is the code I have written please help me resolve this problem class node: def __init__(self,data): self.data=data self.next=None class linkedlist: def __init__(self,head): self.head=None def insertathead(self,data): newnode=node(data) if(self.head==None): self.head=newnode else: newnode.next=self.head self.head=newnode def insertatend(self,data): newnode=node(data) if(self.head==None): self.head=newnode else: temp=self.head while(temp.next!=None): temp=temp.next temp.next=newnode def insert(self,position,data): newnode=node(data) count=1 if(self.head==None): self.head=newnode elif(position==1): newnode.next=self.head self.head=newnode else: while(temp.next!=None): if(count==position): break else: prev=temp temp=temp.next count=count+1 prev.next=newnode newnode.next=temp def printlist(self): if(self.head==None): print(&quot;your list is empty&quot;) else: temp=self.head while(temp.next!=None): print(temp,end=' ') temp=temp.next mylist=linkedlist() mylist.insertathead(25) mylist.printlist </code></pre> <pre><code>File &quot;D:\roug1.py&quot;, line 51, in &lt;module&gt; mylist=linkedlist() TypeError: __init__() missing 1 required positional argument: 'head' </code></pre> <p>this is the error my compiler is giving .I don't what to do. Can anyone provide me with the correct code</p>
[ { "answer_id": 74293280, "author": "Alex", "author_id": 984885, "author_profile": "https://Stackoverflow.com/users/984885", "pm_score": 1, "selected": false, "text": " mylist=linkedlist()\n" }, { "answer_id": 74293285, "author": "finman69", "author_id": 19628700, "author_profile": "https://Stackoverflow.com/users/19628700", "pm_score": 0, "selected": false, "text": "head_node = Node(25)\nmylist=linkedlist(head_node)\n\n# now do whatever you want\nmylist.insertathead(25)\nmylist.printlist()\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399895/" ]
74,293,232
<p><a href="https://i.stack.imgur.com/cnj45.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cnj45.jpg" alt="enter image description here" /></a></p> <p>so in my assignment i have to make this screen in flutter i did this so far but we havent learned much they said search for answers and i cant find everything</p> <pre><code>import 'package:flutter/material.dart'; import 'package:cupertino_icons/cupertino_icons.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Chat App', debugShowCheckedModeBanner: false, theme: ThemeData( appBarTheme: const AppBarTheme(color: Color.fromRGBO(0, 0, 0, 1.0)), ), home: const MyHomePage(title: 'Person'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState(); } class _MyHomePageState extends State&lt;MyHomePage&gt; { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () =&gt; 0, ), title: Text(widget.title), ), body: Container( decoration: const BoxDecoration( image: DecorationImage(image: AssetImage('images/background.png'))), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: &lt;Widget&gt;[ const Text( '', ), Text( '', style: Theme.of(context).textTheme.headline4, ), ], ), ), ), floatingActionButton: FloatingActionButton( backgroundColor: const Color.fromRGBO(0, 0, 0, 1.0), onPressed: () =&gt; 0, tooltip: 'Record', child: const Icon(Icons.mic), ), ); } } </code></pre> <p>I did try to do it but I cannot get to know how to add the icons in the appbar and the texts and text field so if anyone could help that would be amazing</p>
[ { "answer_id": 74293294, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 0, "selected": false, "text": "title" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20076908/" ]
74,293,244
<p>I am working on a user registration/ log in page. I have two forms, a signUp form and a logIn form, and some state called signInState that determines which user form to display. I have two buttons that toggle the signInState, and if the signInState is true, I want it to display the log in form, if its false, I want to display the sign up form. The state is changing, but for some reason the conditional rendering is not working. Can someone help me figure out why my toggleSignInState doesn't change what's being rendered on the page? Thanks</p> <p>Here is my react code for the signInPage itself</p> <pre><code>import React from 'react' import SignUp from './SignUp' import LogIn from './LogIn' export default function SignInPage() { const [signInState, setSignInState] = React.useState(true); function toggleSignIn(event) { console.log(event.target.id) setSignInState(event.target.id); /*setSignInState(event.target.value);*/ } return ( &lt;div className=&quot;signInPage&quot;&gt; &lt;div className=&quot;signInPageFormContainer&quot;&gt; &lt;p&gt;{signInState}&lt;/p&gt; {!signInState &amp;&amp; &lt;SignUp /&gt; } {signInState &amp;&amp; &lt;LogIn /&gt; } &lt;div className=&quot;signUpPageToggleContainer&quot;&gt; &lt;button onClick={toggleSignIn} id='true'&gt;Log In&lt;/button&gt; &lt;button onClick={toggleSignIn} id='false'&gt;Sign Up&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; ) } </code></pre> <p>here is the code for the signUp form</p> <pre><code>import React from 'react' export default function SignUp() { return( &lt;form className=&quot;signUpForm&quot;&gt; &lt;input name=&quot;username&quot; type=&quot;text&quot; placeholder=&quot;Username&quot; className=&quot;signUpInput&quot; /&gt; &lt;input name=&quot;email&quot; type=&quot;text&quot; placeholder=&quot;Email&quot; className=&quot;signUpInput&quot; /&gt; &lt;input name=&quot;password&quot; type=&quot;text&quot; placeholder=&quot;Password&quot; className=&quot;signUpInput&quot; /&gt; &lt;input name=&quot;confirmPassword&quot; type=&quot;text&quot; placeholder=&quot;Confirm password&quot; className=&quot;signUpInput&quot; /&gt; &lt;div&gt; &lt;button&gt;Sign Up&lt;/button&gt; &lt;button&gt;Cancel&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; ) } </code></pre> <p>and here is the code for the log in form</p> <pre><code>import React from &quot;react&quot;; export default function LogIn() { /*functions for log in procedure*/ return ( &lt;form className=&quot;logInForm&quot;&gt; &lt;input placeholder=&quot;Username&quot; name=&quot;username&quot; type=&quot;text&quot; id=&quot;username&quot; className=&quot;logInFormInput&quot; /&gt; &lt;input placeholder=&quot;Password&quot; name=&quot;password&quot; type=&quot;text&quot; id=&quot;password&quot; className=&quot;logInFormInput&quot; /&gt; &lt;div className=&quot;logInFormButtonContainer&quot;&gt; &lt;button className=&quot;logInFormButton&quot;&gt;Log In&lt;/button&gt; &lt;button className=&quot;logInFormButton&quot;&gt;Cancel&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; ) } </code></pre>
[ { "answer_id": 74293275, "author": "CertainPerformance", "author_id": 9515207, "author_profile": "https://Stackoverflow.com/users/9515207", "pm_score": 3, "selected": true, "text": "'true'" }, { "answer_id": 74293375, "author": "KcH", "author_id": 11737596, "author_profile": "https://Stackoverflow.com/users/11737596", "pm_score": 1, "selected": false, "text": "id" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293244", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16635145/" ]
74,293,262
<p>I have an example object which is mixed of lists and dicts:</p> <pre><code>{ &quot;field_1&quot; : &quot;aaa&quot;, &quot;field_2&quot;: [ { &quot;field_3&quot; : &quot;bbb&quot;, ..... &quot;field_4&quot; : &quot;ccc&quot;, &quot;field_need_to_filter&quot; : False, }, { &quot;field_5&quot; : &quot;ddd&quot;, ..... &quot;field_6&quot;: [ { &quot;field_7&quot; : &quot;eee&quot;, .... &quot;field_8&quot; : [ { &quot;field_9&quot;: &quot;fff&quot;, ..... &quot;field_10&quot;: { &quot;field_11&quot;: &quot;rrr&quot;, ... &quot;field_12&quot;: [ { &quot;field_13&quot;: &quot;xxx&quot;, ... &quot;field_need_to_filter&quot;: True, }, { &quot;field_13&quot;: &quot;yyy&quot;, ... &quot;field_need_to_filter&quot;: True, }, { &quot;field_13&quot;: &quot;zzz&quot;, ... &quot;field_need_to_filter&quot;: False, } ] } }, ]}]} ] } </code></pre> <p>I'd like to iterate it and add all the corresponding values for <code>field_13</code> where <code>field_need_to_filter</code> is <code>True</code>, so for this example, expected output would be: <code>[&quot;xxx&quot;, &quot;yyy&quot;]</code></p>
[ { "answer_id": 74293323, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 3, "selected": true, "text": "dct = {\n \"field_1\": \"aaa\",\n \"field_2\": [\n {\n \"field_3\": \"bbb\",\n \"field_4\": \"ccc\",\n \"field_need_to_filter\": False,\n },\n {\n \"field_5\": \"ddd\",\n \"field_6\": [\n {\n \"field_7\": \"eee\",\n \"field_8\": [\n {\n \"field_9\": \"fff\",\n \"field_10\": {\n \"field_11\": \"rrr\",\n \"field_12\": [\n {\n \"field_13\": \"xxx\",\n \"field_need_to_filter\": True,\n },\n {\n \"field_13\": \"yyy\",\n \"field_need_to_filter\": True,\n },\n {\n \"field_13\": \"zzz\",\n \"field_need_to_filter\": False,\n },\n ],\n },\n },\n ],\n }\n ],\n },\n ],\n}\n\n\ndef find(o, key):\n if isinstance(o, dict):\n if key in o and o.get(\"field_need_to_filter\"):\n yield o[key]\n\n for v in o.values():\n yield from find(v, key)\n elif isinstance(o, list):\n for v in o:\n yield from find(v, key)\n\n\nout = list(find(dct, \"field_13\"))\nprint(out)\n" }, { "answer_id": 74293540, "author": "Alex", "author_id": 984885, "author_profile": "https://Stackoverflow.com/users/984885", "pm_score": 0, "selected": false, "text": " data = {\n \"field_1\" : \"aaa\",\n \"field_2\": [\n {\n \"field_3\" : \"bbb\",\n \"field_4\" : \"ccc\",\n \"field_need_to_filter\" : False,\n },\n\n {\n \"field_5\" : \"ddd\",\n \"field_6\": [\n {\n \"field_7\" : \"eee\",\n \"field_8\" : [\n {\n \"field_9\": \"fff\",\n \"field_10\": {\n \"field_11\": \"rrr\",\n \"field_12\": [\n {\n \"field_13\": \"xxx\",\n \"field_need_to_filter\": True,\n },\n {\n \"field_13\": \"yyy\",\n \"field_need_to_filter\": True,\n },\n {\n \"field_13\": \"zzz\",\n \"field_need_to_filter\": False,\n }\n ]\n }\n },\n\n\n ]}]}\n\n ]\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10581944/" ]
74,293,289
<p>I have few spring-boot microservices with actuator and exposed prometheus metrics. For example:</p> <pre><code># HELP process_uptime_seconds The uptime of the Java virtual machine # TYPE process_uptime_seconds gauge process_uptime_seconds 3074.971 </code></pre> <p>But there is no <code>application</code> tag, so I'm not able to bind it to a certain application within a grafana dashboard...</p> <p>Also I expect to have few application instances of some microservice, so in general it would be great to add an <code>instance</code> tag also.</p> <p>Is there any way to customize the standard metrics with these tags?</p>
[ { "answer_id": 74293341, "author": "Being_shawn", "author_id": 20399922, "author_profile": "https://Stackoverflow.com/users/20399922", "pm_score": 2, "selected": true, "text": "registry.config().commonTags(\"stack\", \"prod\", \"region\", \"us-east-1\");\n" }, { "answer_id": 74303400, "author": "mweirauch", "author_id": 9071502, "author_profile": "https://Stackoverflow.com/users/9071502", "pm_score": 0, "selected": false, "text": "project.artifactId" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293289", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7370205/" ]
74,293,324
<p>I'm a new C# programmer here in the early stages of creating a project in Unity where you play as a microbe that needs to eat blue food pellets to grow and survive. I've got the blue food pellets to spawn randomly across the map but I want to add a delay because too much is spawning at once. This is what I've attempted to do so far. Any help would be appreciated!</p> <pre><code>using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Threading.Tasks; public class Spawner : MonoBehaviour { public GameObject food; public async void Wait(float duration) { Vector3 randomSpawnPosition = new Vector3(Random.Range(-50, 50), 1, Random.Range(-50, 50)); Instantiate(food, randomSpawnPosition, Quaternion.identity); await Task.Delay((int)duration * 1000); } // Update is called once per frame void Update() { async void Wait(float duration); } } </code></pre> <p>What I've tried:</p> <p>Putting the delay function in the update function. The program just gets confused and thinks I'm trying to call the function.</p> <p>Calling the function after combining all my code into the one function, the program rejects this.</p>
[ { "answer_id": 74293467, "author": "Scabbage", "author_id": 8052184, "author_profile": "https://Stackoverflow.com/users/8052184", "pm_score": 1, "selected": false, "text": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class Spawner : MonoBehaviour\n{\n [SerializeField] GameObject food;\n\n protected void OnEnable()\n {\n StartCoroutine(SpawnFoodRoutine());\n }\n\n IEnumerator SpawnFoodRoutine()\n {\n while(enabled)\n {\n SpawnFood();\n\n var waitTime = Random.Range(1f, 5f);\n yield return new WaitForSeconds(waitTime);\n }\n }\n\n void SpawnFood()\n {\n Vector3 randomSpawnPosition = new Vector3(\n Random.Range(-50f, 50f), \n 1f, \n Random.Range(-50f, 50f));\n\n Instantiate(food, randomSpawnPosition, Quaternion.identity);\n }\n}\n" }, { "answer_id": 74293984, "author": "Jinwe", "author_id": 6073465, "author_profile": "https://Stackoverflow.com/users/6073465", "pm_score": -1, "selected": false, "text": "using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n \npublic class SpawnPellet : MonoBehaviour\n{\n \n public GameObject prefab;\n public bool canSpawnNewPellet = true;\n public float delay;\n \n void Update(){\n if(canSpawnNewPellet){\n Invoke(\"SpawnNewPellet\", delay);\n canSpawnNewPellet = false;\n }\n }\n \n \n void SpawnNewPellet()\n {\n GameObject instance = Instantiate(prefab);\n instance.transform.position = new Vector3(Random.Range(0,10), Random.Range(0,10), 0);\n canSpawnNewPellet = true;\n }\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19153501/" ]
74,293,329
<p>Suppose I have these data</p> <pre><code>data1 &lt;- read.delim(textConnection( &quot;id val1 1 blue 1 green 1 red 2 black 2 brown 2 white&quot; ), sep=' ') data2 &lt;- read.delim(textConnection( &quot;id val2 1 cat 1 dog 1 fish 2 hat 2 coat 2 car&quot; ), sep=' ') </code></pre> <p>I would like to calculate all permutations of blue, green, and red cat, dog, and fish for id=1 and brown, black, and white hats, coats, and cars for id=2. I could do it in a <code>for</code> loop with <code>expand.grid</code>, and then &quot;build&quot; the output using <code>rbind</code>. But my actual data have several IDs and several vals so it runs poorly.</p>
[ { "answer_id": 74293364, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 1, "selected": true, "text": "base R" }, { "answer_id": 74294066, "author": "AdamO", "author_id": 821649, "author_profile": "https://Stackoverflow.com/users/821649", "pm_score": 2, "selected": false, "text": "merge" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/821649/" ]
74,293,371
<p>I noticed that a query that used to be fast in legacy version of Django is now much slower in 4.0.8.</p> <p>There is a fairly large table with a FK 'marker' and a boolean 'flag' that has an index attached. The following queries could reasonably return tens of thousands of rows.</p> <p>In my codebase, there is a query like</p> <p><code>MyModel.objects.filter(marker_id=123, flag=False).count()</code></p> <p>In Django Debug Toolbar (and also in shell when I examine <code>str(qs.query)</code>) it now resolves to the following SQL syntax:</p> <p><code>SELECT ••• FROM `myapp_mymodel` WHERE (`myapp_mymodel`.`marker_id` = 123 AND NOT `myapp_mymodel`.`flag`)</code></p> <p>In extreme cases, this query runs for 20s or so. Meanwhile, in legacy Django version (1.11+) the same query becomes the following SQL:</p> <p><code>SELECT ••• FROM `myapp_mymodel` WHERE (`myapp_mymodel`.`marker_id` = 123 AND `myapp_mymodel`.`flag` = 0)</code></p> <p>This works, since the table schema contains 'flag' as a TINYINT(1), but most importantly, it works <strong>much</strong> faster - returning in under a second.</p> <p><strong>EDIT:</strong> I asked sql server to EXPLAIN both queries, and there is a difference in 'flag' appearing as a potential key in the latter (faster) query but not in the slower one. This is consistent with <a href="https://stackoverflow.com/questions/391637/why-does-mysql-not-use-an-index-on-a-int-field-thats-being-used-as-a-boolean">this answer</a> stating that mysql needs to see comparison against a value to know to use an index. Thus, the main question becomes, how can I enforce the syntax that makes use of the index already in place?</p> <p><strong>END EDIT</strong></p> <p><strong>Original questions</strong>: <em>Why is the difference in ORM-to-SQL translation, and where can I find the code responsible (I have checked db.backends.mysql to no avail, or failed to recognize the culprit)?</em> <strong>Is there a way to hint to Django that I'd much prefer the equals-zero behaviour?</strong></p> <p>The only workaround I see so far is to use raw SQL query. I'd rather avoid that if possible.</p>
[ { "answer_id": 74293701, "author": "Abdul Aziz Barkat", "author_id": 14991864, "author_profile": "https://Stackoverflow.com/users/14991864", "pm_score": 3, "selected": true, "text": "Value()" }, { "answer_id": 74294305, "author": "Rick James", "author_id": 1766831, "author_profile": "https://Stackoverflow.com/users/1766831", "pm_score": 0, "selected": false, "text": "INDEX(flag)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1624676/" ]
74,293,412
<p>I am making laravel API to reset password by diverting laravel standard password reset function.</p> <p>This is controller</p> <pre class="lang-php prettyprint-override"><code>&lt;?php namespace App\Http\Controllers\Api\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Log; class ResetPasswordController extends Controller { use ResetsPasswords; public function __construct() { $this-&gt;middleware('guest'); } public function resetPassword() { $credentials = request()-&gt;validate([ 'email' =&gt; 'required|email', 'token' =&gt; 'required|string', 'password' =&gt; 'required|string|confirmed' ]); $reset_password_status = Password::reset($credentials, function ($user, $password) { $user-&gt;password = bcrypt($password); $user-&gt;save(); }); if ($reset_password_status == Password::INVALID_TOKEN) { return ['success' =&gt; false]; } return ['success' =&gt; true]; } } </code></pre> <p>and api.php</p> <pre><code>Route::post('password/reset/{token}', [ResetPasswordController::class, 'resetPassword']); </code></pre> <p>Finally, vue.component code</p> <pre class="lang-html prettyprint-override"><code>&lt;template&gt; &lt;div class=&quot;l-form&quot;&gt; &lt;form v-on:submit.prevent=&quot;submit&quot;&gt; &lt;div class=&quot;p-input&quot;&gt; &lt;input id=&quot;email&quot; type=&quot;email&quot; class=&quot;c-input&quot; placeholder=&quot;email&quot; name=&quot;email&quot; v-model=&quot;passResetRequest.email&quot; required autocomplete=&quot;email&quot; autofocus&gt; &lt;/div&gt; &lt;div class=&quot;p-input&quot;&gt; &lt;input id=&quot;password&quot; type=&quot;password&quot; class=&quot;c-input&quot; placeholder=&quot;password&quot; name=&quot;password&quot; v-model=&quot;passResetRequest.password&quot; required autocomplete=&quot;new-password&quot;&gt; &lt;/div&gt; &lt;div class=&quot;p-input&quot;&gt; &lt;input id=&quot;password-confirm&quot; type=&quot;password&quot; class=&quot;c-input&quot; placeholder=&quot;password-confirm&quot; name=&quot;password_confirmation&quot; v-model=&quot;passResetRequest.password_confirmation&quot; required autocomplete=&quot;new-password&quot;&gt; &lt;/div&gt; &lt;div class=&quot;p-buttonbox&quot;&gt; &lt;button type=&quot;submit&quot; class=&quot;c-button u-mt60&quot;&gt; reset &lt;/button&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/template&gt; &lt;script&gt; import axios from 'axios'; export default { data: function () { return { passResetRequest: { email: '', token: '', password: '', password_confirmation: '' } } }, methods: { submit() { axios.post('/api/password/reset/' + this.passResetRequest) .then((res) =&gt; { this.message = &quot;success!&quot;; }).catch(error =&gt; { }); }, getToken(){ const params = document.location.search; const splitedParams = params.split( '=' ); this.passResetRequest.token = splitedParams[2]; }, }, mounted() { this.getToken(); } } &lt;/script&gt; </code></pre> <p>However, I try to get response,I get error messages with 422 error code. &quot;email is required&quot; &quot;password is required&quot; &quot;token is required&quot;</p> <p>Where should I confirm to send parameters to API?</p> <p>I confirmed request object can get parameters which are entered.</p> <p><a href="https://i.stack.imgur.com/jqKvE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jqKvE.png" alt="enter image description here" /></a></p> <p>Version Laravel v8.83.23 PHP v7.4.18 &quot;axios&quot;: &quot;^0.21.4&quot;, &quot;vue&quot;: &quot;^2.5.17&quot;,</p>
[ { "answer_id": 74293701, "author": "Abdul Aziz Barkat", "author_id": 14991864, "author_profile": "https://Stackoverflow.com/users/14991864", "pm_score": 3, "selected": true, "text": "Value()" }, { "answer_id": 74294305, "author": "Rick James", "author_id": 1766831, "author_profile": "https://Stackoverflow.com/users/1766831", "pm_score": 0, "selected": false, "text": "INDEX(flag)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19871198/" ]
74,293,430
<p><strong>Before looking for a page I wanted to check if the id exists, so if I don't find it, give up looking I tried as follows:</strong></p> <blockquote> <p>My controller product</p> </blockquote> <pre><code>public function search(Request $request) { $id = $request-&gt;input('id'); if($produto = Produto::find($id)) { return view('produtos.show', compact('produto', 'id')); } // $search_results=Produto::findOrFail($id); return 'Not found'; } </code></pre> <p>-&gt;My Route-&gt;</p> <pre><code>Route::get('/produtos/editar/{id?}','App\Http\Controllers\ProdutosController@search')-&gt;name('searchproduct'); </code></pre> <p>-&gt;My Blade Form</p> <pre><code> &lt;form id=&quot;search&quot; method=&quot;GET&quot; action=&quot;{{ route('searchproduct') }}&quot; &gt; &lt;input id=&quot;q&quot; name=&quot;q&quot; type=&quot;text&quot; /&gt;&lt;/br&gt; &lt;button type=&quot;submit&quot; id=&quot;submitButton&quot; &gt;Alterar&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>-&gt;My Jquery Script</p> <pre><code>jQuery(document).ready(function(){ jQuery(&quot;form#search&quot;).on('submit',function(e){ e.preventDefault(); var q = jQuery(&quot;#q&quot;).val(); window.location.href = jQuery(this).prop('action')+&quot;/&quot; + encodeURIComponent(q) }); }); </code></pre> <blockquote> <p>How can i check in database before? send It's always going to the default 404 page</p> </blockquote>
[ { "answer_id": 74293701, "author": "Abdul Aziz Barkat", "author_id": 14991864, "author_profile": "https://Stackoverflow.com/users/14991864", "pm_score": 3, "selected": true, "text": "Value()" }, { "answer_id": 74294305, "author": "Rick James", "author_id": 1766831, "author_profile": "https://Stackoverflow.com/users/1766831", "pm_score": 0, "selected": false, "text": "INDEX(flag)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17503767/" ]
74,293,431
<p>I recently had an interview where you had to recursively go over a string, and if it contained an <code>AB</code> || <code>BA</code> || <code>CD</code> || <code>DC</code>, it had to be deleted from the array. You would recursively go over this as deleting the <code>CD</code> from <code>ACDBB</code> would give you an <code>AB</code> which you would then have to delete to return a <code>B</code> as a string.</p> <p>This is what I have, and when I test it out, I see it comes up with the right answer deep in the loops, but it never populates back to the top.</p> <p>What am I missing?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const LETTERS = [/AB/g, /BA/g, /CD/g, /DC/g]; const stringGame = (string) =&gt; { let newString = ''; if(string.length &lt;= 1) return string; LETTERS.forEach(regExToCheck =&gt; { if(string.match(regExToCheck)) { newString = string.replace(regExToCheck, '') } stringGame(newString); }) return newString } // Expect answer: CAACC console.log(stringGame('ABDCABCABAAABCCCD'))</code></pre> </div> </div> </p>
[ { "answer_id": 74293701, "author": "Abdul Aziz Barkat", "author_id": 14991864, "author_profile": "https://Stackoverflow.com/users/14991864", "pm_score": 3, "selected": true, "text": "Value()" }, { "answer_id": 74294305, "author": "Rick James", "author_id": 1766831, "author_profile": "https://Stackoverflow.com/users/1766831", "pm_score": 0, "selected": false, "text": "INDEX(flag)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3606275/" ]
74,293,440
<p>Trying to write a program where it outputs the user entered number if it is between 30 and 70.If not, it should prompt the user to reenter. This is what I have so far, but the code is not running at all.</p> <p>What should I change?</p> <p>I tried debugging but it seems like it just gives me random quick fixes that jumble up my original code.</p> <p>here is the code:</p> <pre><code>package chpt5_project; import java.util.Scanner; public class chpt5_project { //variables public static void main(String[] args) { Scanner input = new Scanner(System.in); int count1 = input.nextInt(); while (count1 &gt; 70 || count1 &lt; 30){ System.out.println(&quot;Enter a value between 30 and 70: &quot;); input.close(); } } } </code></pre>
[ { "answer_id": 74293700, "author": "mmartinez04", "author_id": 20131874, "author_profile": "https://Stackoverflow.com/users/20131874", "pm_score": 1, "selected": false, "text": "input.nextInt()" }, { "answer_id": 74293858, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 0, "selected": false, "text": "// no need to close Scanner for System.in\nScanner scan = new Scanner(System.in);\n\n// create an loop\nwhile (true) {\n System.out.print(\"Enter a value between 30 and 70: \");\n int num = scan.nextInt();\n \n // exit the loop if number is correct\n if (num > 30 && num < 70)\n break;\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16669280/" ]
74,293,486
<p>I am learning bit manipulation using C. I encountered a problem when writing a program that converts a binary to decimal, particularly in the for loop of the program. The following is my code:</p> <pre><code>unsigned int binary_to_uint(const char *b) { unsigned int result = 0; int i, len; if (!b) return (0); len = strlen(b); for (i = 0; i &lt; len; i++) { if (b[i] == '1') { result += 2 &lt;&lt; (i-1); /*where my issue is*/ } else if (b[i] == '0') continue; else return (0); } return (9); } </code></pre> <p>I tried debugging and I realized my problem was originating from the <strong>if</strong> statement</p> <p>I therefore did some experiment with the code in the <strong>if</strong>* statement:</p> <pre><code>int main() { // Write C code here int i = 0; printf(&quot;result of 2 &lt;&lt; (%d - 1): %d\n&quot;, i, 2 &lt;&lt; (i - 1)); printf(&quot;result of 2 &lt;&lt; (0 - 1): %d&quot;, 2 &lt;&lt; (0 - 1)); return 0; } </code></pre> <p>In the first printf, displays <strong>result of 2 &lt;&lt; (0 - 1): 0</strong> in the console, while in the second printf, displays <strong>result of 2 &lt;&lt; (0 - 1): 1</strong> in the console. My expectation is that both printf should display the exact same thing, that is the value of <em><strong>2 &lt;&lt; -1 is 1</strong></em>, however that is not the case. Can someone please help me understand what is going on. why did the use of the variable i change the outcome of the shift operator to 0?</p>
[ { "answer_id": 74293551, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 2, "selected": false, "text": "b[i]" }, { "answer_id": 74293553, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 3, "selected": true, "text": "<<" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13871283/" ]
74,293,510
<p><img src="https://i.stack.imgur.com/4BFNY.png" alt="Image created from the code-&gt;" /> I am trying to edit the Y-axis scale to represent the amount the rows of Id. The numbers needed to be shown on the scale are in the millions. I need to abbreviate the number in order for it to be seen on the visualization.</p> <pre><code> ggplot(sleeptocalories1, aes(Id,TotalCalories) + geom_col(fill=&quot;steelblue&quot;) + theme(axis.text.x = element_text(angle = 90)) + theme(axis.text.y = element_text(angle = 45)) </code></pre>
[ { "answer_id": 74293774, "author": "stefan", "author_id": 12993861, "author_profile": "https://Stackoverflow.com/users/12993861", "pm_score": 1, "selected": false, "text": "labels" }, { "answer_id": 74293783, "author": "ncraig", "author_id": 13110995, "author_profile": "https://Stackoverflow.com/users/13110995", "pm_score": 0, "selected": false, "text": "scales" }, { "answer_id": 74294160, "author": "Jon Spring", "author_id": 6851825, "author_profile": "https://Stackoverflow.com/users/6851825", "pm_score": 2, "selected": true, "text": "scales::label_number_si()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19679035/" ]
74,293,515
<p>I am trying to create a function which will return the text color of a specified cell. But it never returns the correct color of the cell and instead always returns &quot;#ff000000&quot; no matter the text color of the cell. an example of someone useing the function is &quot;=fontColor(&quot;A1:A1&quot;)&quot;. `</p> <pre><code>function fontColor(a) { var b=a; if(b==undefined){ b=&quot;A1:A1&quot;; } var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var range = sheet.getRange(b); return range.getFontColorObject().asRgbColor().asHexString(); } </code></pre> <p>`</p> <p>I tried using &quot;Logger.log&quot; to see if the function worked and tried the function in a google sheet but both times it returned &quot;#ff000000&quot;. I tried this on cells which had text colors of blue and ones which had text colors of black. I was expecting the function to return the correct color for example it should return &quot;#000000&quot; for black and &quot;#0000ff&quot; for blue.</p>
[ { "answer_id": 74293777, "author": "TheMaster", "author_id": 8404453, "author_profile": "https://Stackoverflow.com/users/8404453", "pm_score": 1, "selected": false, "text": "=fontColor(\"A1\")\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20400221/" ]
74,293,533
<p>I would like to run this <a href="https://github.com/MubertAI/Mubert-Text-to-Music" rel="nofollow noreferrer">project </a>from Github to VSCode, I have cloned the repository, installed Python from the Microsoft app store, but I still get some error like this 1<a href="https://i.stack.imgur.com/R2jsd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R2jsd.png" alt="like this" /></a></p> <p>and 2 <a href="https://i.stack.imgur.com/geVyQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/geVyQ.png" alt="enter image description here" /></a></p> <p>and warnings like this <a href="https://i.stack.imgur.com/VcLAA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VcLAA.png" alt="enter image description here" /></a></p> <p>and im cannot run the project. Can you help me with this ?</p>
[ { "answer_id": 74293610, "author": "hello", "author_id": 20395710, "author_profile": "https://Stackoverflow.com/users/20395710", "pm_score": 0, "selected": false, "text": "numpy" }, { "answer_id": 74293670, "author": "Anger", "author_id": 17717094, "author_profile": "https://Stackoverflow.com/users/17717094", "pm_score": 1, "selected": false, "text": "import numpy as np\narr = np.array([1, 2, 3, 4, 5])\nprint(arr)\nprint(type(arr))\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19454412/" ]
74,293,637
<p>I coded a program to make ascii art and for the characters I have the following string: &quot;&quot;&quot;.:-=+*#%@&amp;&quot;&quot;&quot;</p> <p>But it's a pretty short one and I can't find one that's longer to make images a little more detailed than that Does anyone have this? (preferably put in order (like the one I already have))</p>
[ { "answer_id": 74293730, "author": "Alichu", "author_id": 20397961, "author_profile": "https://Stackoverflow.com/users/20397961", "pm_score": 0, "selected": false, "text": ">>> import string\n>>> string.printable\n" }, { "answer_id": 74293739, "author": "bitfliq", "author_id": 20400380, "author_profile": "https://Stackoverflow.com/users/20400380", "pm_score": 0, "selected": false, "text": "\"\".join([chr(i) for i in range(32, 1032)])\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17904974/" ]
74,293,643
<p><a href="https://i.stack.imgur.com/3B7F9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3B7F9.jpg" alt="enter image description here" /></a></p> <p>My goal is to vertically center the input in the picture. How can I do that?</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>.headmenu { background-color: rgb(47, 47, 47); width: auto; height: 30px; } .headmenu-right { float: right; padding-right: 15px; } .headmenu-right&gt;input { border-radius: 15px; padding-left: 5px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="headmenu"&gt; &lt;div class="headmenu-right"&gt; &lt;input type="text"&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74293709, "author": "Krutik Raut", "author_id": 13613400, "author_profile": "https://Stackoverflow.com/users/13613400", "pm_score": 0, "selected": false, "text": ".headmenu {\n background-color: rgb(47, 47, 47);\n width: auto;\n height: 30px;\n display:flex;\n justify-content:end;\n align-items:center;\n}\n\n.headmenu-right {\n float: right;\n padding-right: 15px;\n}\n\n.headmenu-right>input {\n border-radius: 15px;\n padding-left: 5px;\n}" }, { "answer_id": 74293758, "author": "Vsevolod Fedorov", "author_id": 10267516, "author_profile": "https://Stackoverflow.com/users/10267516", "pm_score": 3, "selected": true, "text": ".headmenu {\n background-color: rgb(47, 47, 47);\n width: auto;\n height: 30px;\n display: flex; \n align-items: center;\n}\n\n.headmenu-right {\n margin-left: auto;\n padding-right: 15px;\n}\n\n.headmenu-right>input {\n border-radius: 15px;\n padding-left: 5px;\n}" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18003111/" ]
74,293,650
<p>I have a string:</p> <pre><code>Hallux OtherToes Transmetatarsal Forefoot BelowKnee SkewFlap ThroughKnee AboveKnee Other YN. </code></pre> <p>I want to turn it into a tibble or dataframe in long format with two columns, where each value except the last is per row and the last column is repeated:</p> <pre><code> variable format_id &lt;chr&gt; &lt;chr&gt; 1 Hallux YN. 2 OtherToes YN. 3 Transmetatarsal YN. 4 Forefoot YN. 5 BelowKnee YN. 6 SkewFlap YN. 7 ThroughKnee YN. 8 AboveKnee YN. 9 Other YN. </code></pre>
[ { "answer_id": 74293711, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 2, "selected": false, "text": "s <- 'Hallux OtherToes Transmetatarsal Forefoot BelowKnee SkewFlap ThroughKnee AboveKnee Other YN.'\ns <- strsplit(s, '\\\\s+')[[1]]\ndata.frame(variable=head(s, -1),\n format_id=tail(s, 1))\n\n# variable format_id\n# 1 Hallux YN.\n# 2 OtherToes YN.\n# 3 Transmetatarsal YN.\n# 4 Forefoot YN.\n# 5 BelowKnee YN.\n# 6 SkewFlap YN.\n# 7 ThroughKnee YN.\n# 8 AboveKnee YN.\n# 9 Other YN.\n" }, { "answer_id": 74294315, "author": "jay.sf", "author_id": 6574038, "author_profile": "https://Stackoverflow.com/users/6574038", "pm_score": 0, "selected": false, "text": "scan" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19414769/" ]
74,293,665
<p>i have variable contains with binary with type int ([101, 1101, 11001]) but i want to xor it with another variable, so i must change to string and add &quot;0&quot; so it has 8 number example 101 it'll become 00000101</p> <p>i was trying change int to str but it cannot works. here's my code:</p> <pre><code>def bit8(input): print(input) y = str(input) print(y) index = 0 for index, a in enumerate(y): y[index] = a + &quot;0&quot; return y[index] </code></pre> <p>input will contains with array [101, 1101, 11001] and it will become [&quot;00000101&quot;, &quot;00001101&quot;, &quot;00011001&quot;] the idea is i will split them and i will add &quot;0&quot; and save it again to new array</p> <p>but i don't know how exactly to do it. please help me</p>
[ { "answer_id": 74293711, "author": "Robert Hacken", "author_id": 2094893, "author_profile": "https://Stackoverflow.com/users/2094893", "pm_score": 2, "selected": false, "text": "s <- 'Hallux OtherToes Transmetatarsal Forefoot BelowKnee SkewFlap ThroughKnee AboveKnee Other YN.'\ns <- strsplit(s, '\\\\s+')[[1]]\ndata.frame(variable=head(s, -1),\n format_id=tail(s, 1))\n\n# variable format_id\n# 1 Hallux YN.\n# 2 OtherToes YN.\n# 3 Transmetatarsal YN.\n# 4 Forefoot YN.\n# 5 BelowKnee YN.\n# 6 SkewFlap YN.\n# 7 ThroughKnee YN.\n# 8 AboveKnee YN.\n# 9 Other YN.\n" }, { "answer_id": 74294315, "author": "jay.sf", "author_id": 6574038, "author_profile": "https://Stackoverflow.com/users/6574038", "pm_score": 0, "selected": false, "text": "scan" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19908082/" ]
74,293,688
<p>I am trying to create a stacked bar chart but unable to create the 'stack part'. I wish to have my bar height as the gdp_per_capita column and I then wish to show the gdp_per_capita_agg_percen column as part of each column (this is as a percentage of my gdp_per_capita column). Just to be clearer here for country 1 i need a column value of 3281 then the stack part inside it to be 676 (20.6% of it).</p> <p>Data and code used below;</p> <p>data</p> <pre><code> df2 Country_Name gdp_per_capita `Agriculture_GDP%` gdp_per_capita_agg_percen 1 Albania 3281 20.6 676 2 Algeria 3515 9.86 346 3 Bosnia and Herzegovina 3828 8.21 314 4 Croatia 11285 3.90 440 5 Cyprus 24686 2.60 643 6 Egypt, Arab Rep. 2192 13.3 292 </code></pre> <p>current code with out stacks; I read about using <code>position=&quot;stack&quot;</code> in the geom_bar argument but wasnt sure how to add in my gdp_per_capita_agg_percen data for the stack</p> <pre><code>ggplot(df2, aes(x = as.factor(Country_Name), y = gdp_per_capita, fill = as.factor(Country_Name))) + geom_bar(stat = &quot;identity&quot;) </code></pre>
[ { "answer_id": 74293876, "author": "stefan", "author_id": 12993861, "author_profile": "https://Stackoverflow.com/users/12993861", "pm_score": 3, "selected": true, "text": "geom_col/bar" }, { "answer_id": 74294602, "author": "M--", "author_id": 6461462, "author_profile": "https://Stackoverflow.com/users/6461462", "pm_score": 1, "selected": false, "text": "library(tidyverse)\n\ndf2 %>% \n select(-`Agriculture_GDP%`) %>% \n pivot_longer(cols = -\"Country_Name\") %>% \nggplot() +\n geom_col(aes(x = as.factor(Country_Name), y = value, fill = name)) +\n scale_fill_manual(labels = c(\"GDP\", \"Aggriculture\"), \n values = scales::hue_pal()(2)) +\n labs(y = \"Country\", x = \"GDP\")\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18338223/" ]
74,293,732
<p>I have several hundred folders where I will have multiple files called filename.ext but also another file called filename.ext.url</p> <p>I need a way of checking if filename.pdf.url exists does filename.ext exist. If they both exist delete filename.ext.url</p> <p>I can't just do a search and delete all *.url files as they will be needed if the normal file does not exist</p> <p>I then need to repeat that in all subdirectories of a specific directory.</p> <p>I don't mind its its a batch script, powershell script that does it or any other way really. I'm just stumped on how to do what I want.</p> <p>Currently I'm doing it folder by folder, manually comparing file names, file size and file icon.</p>
[ { "answer_id": 74294443, "author": "Robert Cotterman", "author_id": 10035141, "author_profile": "https://Stackoverflow.com/users/10035141", "pm_score": 3, "selected": true, "text": "foreach ($file in ls -Recurse c:\\files\\*.url) {\n if (ls -ErrorAction Ignore \"$($file.PSParentPath)\\$($file.basename)\") {\n remove-item $file.fullname -whatif\n }\n}\n" }, { "answer_id": 74299482, "author": "Magoo", "author_id": 2128947, "author_profile": "https://Stackoverflow.com/users/2128947", "pm_score": 2, "selected": false, "text": "for /r \"startingdirectoryname\" %b in (*.url) do if exist \"%~dpnb\" ECHO del \"%b\"\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20400399/" ]
74,293,770
<p>How to convert a dynamic <code>Set&lt;Promise&lt;T&gt;&gt;</code> into <code>AsyncIterable&lt;T&gt;</code> (unordered)?</p> <p>The resulting iterable must produce values as they get resolved, and it must end just as the source runs empty.</p> <p>I have a dynamic cache of promises to be resolved, and values reported, disregarding the order.</p> <p><strong>NOTE:</strong> The source is dynamic, which means it can receive new <code>Promise&lt;T&gt;</code> elements while we progress through the resulting iterator.</p> <p><strong>UPDATE</strong></p> <p>After going through all the suggestions, I was able to <a href="https://github.com/vitaly-t/iter-ops/blob/main/src/ops/async/wait-race.ts" rel="nofollow noreferrer">implement my operator</a>. And here're <a href="https://vitaly-t.github.io/iter-ops/functions/waitRace.html" rel="nofollow noreferrer">the official docs</a>.</p> <p>I'm adding a bounty to reward anyone who can improve it further, though at this point a PR is preferable (it is for a public library), or at least something that fits the same protocol.</p>
[ { "answer_id": 74294573, "author": "Thomas", "author_id": 6567275, "author_profile": "https://Stackoverflow.com/users/6567275", "pm_score": 1, "selected": false, "text": "function createCache() {\n const resolve = [];\n const sortedPromises = [];\n const noop = () => void 0;\n\n return {\n get length() {\n return sortedPromises.length\n },\n\n add(promiseOrValue) {\n const q = new Promise(r => {\n resolve.push(r);\n\n const _ = () => {\n resolve.shift()(promiseOrValue);\n }\n\n Promise.resolve(promiseOrValue).then(_, _);\n });\n\n q.catch(noop); // prevent q from throwing when rejected.\n\n sortedPromises.push(q);\n },\n \n next() {\n return sortedPromises.length ?\n { value: sortedPromises.shift() } :\n { done: true };\n },\n\n [Symbol.iterator]() {\n return this;\n }\n }\n}\n\n(async() => {\n const sleep = (ms, value) => new Promise(resolve => setTimeout(resolve, ms, value));\n const cache = createCache();\n const start = Date.now();\n\n function addItem() {\n const t = Math.floor(Math.random() ** 2 * 8000), // when to resolve\n val = t + Date.now() - start; // ensure that the resolved value is in ASC order.\n\n console.log(\"add\", val);\n cache.add(sleep(t, val));\n }\n \n // add a few initial items\n Array(5).fill().forEach(addItem);\n \n // check error handling with a rejecting promise.\n cache.add(sleep(1500).then(() => Promise.reject(\"a rejected Promise\")));\n \n while (cache.length) {\n try {\n for await (let v of cache) {\n console.log(\"yield\", v);\n\n if (v < 15000 && Math.random() < .5) {\n addItem();\n }\n\n // slow down iteration, like if you'd await some API-call.\n // promises now resolve faster than we pull them.\n await sleep(1000);\n }\n } catch (err) {\n console.log(\"error:\", err);\n }\n }\n console.log(\"done\");\n})()" }, { "answer_id": 74323931, "author": "Bergi", "author_id": 1048572, "author_profile": "https://Stackoverflow.com/users/1048572", "pm_score": 3, "selected": true, "text": "AsyncIterable<Promise<T>>" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1102051/" ]
74,293,795
<p>I am trying to get a formula that looks up information from another table and populates the output with comma separated values. As shown below, I want to populate column D in Table 2 with information from Table 1. The desired output is in column E. I came up with this formula but it's only pulling one city per person.</p> <p>TEXTJOIN(&quot;, &quot;,,INDEX('Table 1'!B:B,MATCH(FILTERXML(&quot;&quot;&amp;SUBSTITUTE(C3,&quot;,&quot;,&quot;&quot;)&amp;&quot;&quot;,&quot;//m&quot;),'Table 1'!A:A,0)))</p> <p><a href="https://i.stack.imgur.com/EHS0N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EHS0N.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/Aw8Pb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Aw8Pb.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74294253, "author": "Mayukh Bhattacharya", "author_id": 8162520, "author_profile": "https://Stackoverflow.com/users/8162520", "pm_score": 2, "selected": false, "text": "FILTERXML()" }, { "answer_id": 74294804, "author": "JvdV", "author_id": 9758194, "author_profile": "https://Stackoverflow.com/users/9758194", "pm_score": 1, "selected": false, "text": "D3" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18804606/" ]
74,293,818
<p>Since Thymeleaf 3, Thymeleaf prefers the use of <code>SpringResourceTemplateResolver</code> (<a href="https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html" rel="nofollow noreferrer">https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html</a>). So I decided to go from <code>ClassLoaderTemplateResolver</code> to <code>SpringResourceTemplateResolver</code>:</p> <pre><code>@Configuration @EnableWebMvc public class MvcConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(&quot;/**&quot;).addResourceLocations(&quot;classpath:/static/&quot;); registry.setOrder(1); } @Bean public SpringResourceTemplateResolver templateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setPrefix(&quot;/templates/&quot;); resolver.setSuffix(&quot;.html&quot;); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding(&quot;UTF-8&quot;); resolver.setOrder(0); resolver.setCheckExistence(true); return resolver; } @Bean public SpringResourceTemplateResolver templateResolver2() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setPrefix(&quot;/templates-2/&quot;); resolver.setSuffix(&quot;.html&quot;); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding(&quot;UTF-8&quot;); resolver.setOrder(1); resolver.setCheckExistence(true); return resolver; } } </code></pre> <p>Unfortunately, when implementig like this, I'll get an error: <code>Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers</code>.</p> <p>To be honest, I've simple replaced <code>ClassLoaderTemplateResolver</code> with <code>SpringResourceTemplateResolver</code> in the hope, this will work. It doesn't. But searching for a working solution dealing with two template locations, all I find are outdated samples using ClassLoaderTemplateResolvers.</p> <p>Trying to implement the code snippet provided by Thymeleaf as shown here <a href="https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html" rel="nofollow noreferrer">https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html</a> won't work either when using two template directories, besides the fact, that this code itself uses the deprecated WebMvcConfigurerAdapter.</p> <p>Is there any example how to configure a Spring Boot application using Thymeleaf having two or more template locations which isn't completely outdated?</p>
[ { "answer_id": 74294253, "author": "Mayukh Bhattacharya", "author_id": 8162520, "author_profile": "https://Stackoverflow.com/users/8162520", "pm_score": 2, "selected": false, "text": "FILTERXML()" }, { "answer_id": 74294804, "author": "JvdV", "author_id": 9758194, "author_profile": "https://Stackoverflow.com/users/9758194", "pm_score": 1, "selected": false, "text": "D3" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13609359/" ]
74,293,859
<p>I remember that Dart objects have a method which does an object return a value by default without pointing to an property. Example:</p> <pre><code>class A { final String name; A(this.name); ... } main() { var obj = A('chesu'); print(obj + ' locuaz'); } </code></pre> <p>Output: <code>chesu locuaz</code></p> <p>But I don't remember that method or decorator and it is not <code>toString()</code>.</p>
[ { "answer_id": 74294253, "author": "Mayukh Bhattacharya", "author_id": 8162520, "author_profile": "https://Stackoverflow.com/users/8162520", "pm_score": 2, "selected": false, "text": "FILTERXML()" }, { "answer_id": 74294804, "author": "JvdV", "author_id": 9758194, "author_profile": "https://Stackoverflow.com/users/9758194", "pm_score": 1, "selected": false, "text": "D3" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/955594/" ]
74,293,861
<p>How to split the last three values of the Reference Column dataframe into three columns such as Code, PRODUCT, TYPE as shown below</p> <pre><code>Df1: **Reference** Customer/FBG/COMC/APPLE/INTEREST/ Customer/FBG/PORT/APPLE/INTEREST/ Customer/FBG/PORT/APPLE/INTEREST/ Customer/FBG/AUD/5397/APPLE/INTEREST/ Customer/FBG/BDC/APPLE/FRA/ Customer/FBG/DBG/APPLE/FRA/ Customer/FBG/BDI/APPLE/INTEREST/ Customer/FBG/BDR/APPLE/INTEREST/ Customer/FBG/BDR/APPLE/INTEREST/ Customer/FBG/SVZ/APPLE/FRA/ Customer/FBG/SANT/APPLE/INTEREST/ Customer/FBG/SAR/APPLE/FRA/ Customer/FBG/BEA/494823/APPLE/INTEREST/ Customer/FBG/CDA/APPLE/INTEREST/ </code></pre> <p>Expected Output:</p> <pre><code>DF2: **CODE PRODUCT TYPE** COMC APPLE INTEREST PORT APPLE INTEREST PORT APPLE INTEREST 5397 APPLE INTEREST BDC APPLE FRA DBG APPLE FRA BDI APPLE INTEREST BDR APPLE INTEREST BDR APPLE INTEREST SVZ APPLE FRA SANT APPLE INTEREST SAR APPLE FRA 494823 APPLE INTEREST CDA APPLE INTEREST </code></pre> <p>Tried code: df2[['CODE','PRODUCT','TYPE']]=df1['Reference'].str.split('/',-3,expand=True) , not working!</p>
[ { "answer_id": 74294253, "author": "Mayukh Bhattacharya", "author_id": 8162520, "author_profile": "https://Stackoverflow.com/users/8162520", "pm_score": 2, "selected": false, "text": "FILTERXML()" }, { "answer_id": 74294804, "author": "JvdV", "author_id": 9758194, "author_profile": "https://Stackoverflow.com/users/9758194", "pm_score": 1, "selected": false, "text": "D3" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19446467/" ]
74,293,905
<p>I'm working with data that looks like this:</p> <pre><code>id &lt;- c(&quot;673506&quot;, &quot;624401&quot;, &quot;674764&quot;) bills &lt;- c(&quot;sb 1181; ab 573; ab 2697&quot;, &quot;sb 1181; ab 573; ab 2697; ab 2448&quot;, &quot;sb 292; ab 497&quot;) df &lt;- data.frame(id, bills) df </code></pre> <p>How can I transform the data so that the data is long from, the IDs repeat per every corresponding bill separated by a semi-colon?</p> <p>Such that the data looks like this:</p> <p><a href="https://i.stack.imgur.com/a1IAw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a1IAw.png" alt="desired outcome" /></a></p> <p>Thank you!</p>
[ { "answer_id": 74293908, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "separate_rows" }, { "answer_id": 74294244, "author": "jay.sf", "author_id": 6574038, "author_profile": "https://Stackoverflow.com/users/6574038", "pm_score": 1, "selected": false, "text": "do.call(rbind, c(Map(cbind, df$id, strsplit(df$bills, '; ')))) |>\n as.data.frame() |> setNames(names(df))\n# id bills\n# 1 673506 sb 1181\n# 2 673506 ab 573\n# 3 673506 ab 2697\n# 4 624401 sb 1181\n# 5 624401 ab 573\n# 6 624401 ab 2697\n# 7 624401 ab 2448\n# 8 674764 sb 292\n# 9 674764 ab 497\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7994685/" ]
74,293,911
<p>Why am I getting the error &quot;'datetime.timezone' has no attribute 'now'&quot; when trying to run this custom command in Django that deletes guest accounts older than 30 days? It works elsewhere in views.py where I have imported it the same way. Do I have to import it differently since the command is in a different folder? (management/commands/)</p> <pre><code>from django.core.management.base import BaseCommand from datetime import timezone, timedelta from gridsquid.models import User, Tile DEFAULT_TILE_IMG_NAME = &quot;defaultsquid.svg&quot; MAX_GUEST_ACCOUNT_DAYS = 30 class Command(BaseCommand): def handle(self, *args, **options): &quot;&quot;&quot; Deletes all guest user accounts and their media if older than MAX_GUEST_ACCOUNT_DAYS &quot;&quot;&quot; # Get all guest accounts created before the limit expired_guests_count = User.objects.filter(guest=True).filter(date_joined__lt=timezone.now()-timedelta(days=MAX_GUEST_ACCOUNT_DAYS)).count() expired_guests = User.objects.filter(guest=True).filter(date_joined__lt=timezone.now()-timedelta(days=MAX_GUEST_ACCOUNT_DAYS)) for guest in expired_guests: tiles = Tile.objects.select_related(&quot;user&quot;).filter(user=guest).all() for tile in tiles: # Delete image if not default image if DEFAULT_TILE_IMG_NAME not in tile.image.url: tile.image.delete() # Delete audio file if there is one if tile.audio is not None: tile.audio.delete() # Delete guest account guest.delete() </code></pre>
[ { "answer_id": 74293908, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "separate_rows" }, { "answer_id": 74294244, "author": "jay.sf", "author_id": 6574038, "author_profile": "https://Stackoverflow.com/users/6574038", "pm_score": 1, "selected": false, "text": "do.call(rbind, c(Map(cbind, df$id, strsplit(df$bills, '; ')))) |>\n as.data.frame() |> setNames(names(df))\n# id bills\n# 1 673506 sb 1181\n# 2 673506 ab 573\n# 3 673506 ab 2697\n# 4 624401 sb 1181\n# 5 624401 ab 573\n# 6 624401 ab 2697\n# 7 624401 ab 2448\n# 8 674764 sb 292\n# 9 674764 ab 497\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17072084/" ]
74,293,931
<p>I have a large dataframe with multiple date columns. I did like to use str.contains to identify all those date columns and change the format and retain the columns in original dataframe. Here is a sample of the dataset:</p> <pre><code>dat &lt;- data.frame( SSN = c(204,401,101,666,777), date_today=c(&quot;1914-01-01&quot;,&quot;2022-03-12&quot;,&quot;2021-07-09&quot;,&quot;1914-01-01&quot;,&quot;2022-04-05&quot;), date_adm = c(&quot;2020-03-11&quot;,&quot;2022-03-12&quot;,&quot;NA&quot;,&quot;2021-04-07&quot;,&quot;2022-04-05&quot;) ) </code></pre> <p>I have tried this code but looks like its very wrong</p> <pre><code>Data %&gt;% mutate(select(contains(&quot;date&quot;)), as.Date, format=&quot;%d-%m-%Y&quot;) </code></pre> <p>End result is filter columns containing date then change format while retaining those date columns within the origina dataframe.</p>
[ { "answer_id": 74293908, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "separate_rows" }, { "answer_id": 74294244, "author": "jay.sf", "author_id": 6574038, "author_profile": "https://Stackoverflow.com/users/6574038", "pm_score": 1, "selected": false, "text": "do.call(rbind, c(Map(cbind, df$id, strsplit(df$bills, '; ')))) |>\n as.data.frame() |> setNames(names(df))\n# id bills\n# 1 673506 sb 1181\n# 2 673506 ab 573\n# 3 673506 ab 2697\n# 4 624401 sb 1181\n# 5 624401 ab 573\n# 6 624401 ab 2697\n# 7 624401 ab 2448\n# 8 674764 sb 292\n# 9 674764 ab 497\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11883900/" ]
74,293,957
<p>When you run this program it opens a csv file in the allocated folder. What should i write in this code for when i open the file it makes a copy?</p> <pre><code>Open &quot;C:\raspbbbb\users.csv&quot; For Output As #1 i = 2 Do While Cells(i, 1) &lt;&gt; &quot;&quot; myStr = &quot;&quot; For j = 9 To 10 myStr = myStr &amp; Cells(i, j) &amp; &quot;; &quot; Next Print #1, myStr i = i + 1 Loop Close #1 End Sub </code></pre> <p>I tried changing the output and close types but that just makes it crash</p>
[ { "answer_id": 74294852, "author": "Toddleson", "author_id": 14608750, "author_profile": "https://Stackoverflow.com/users/14608750", "pm_score": 1, "selected": false, "text": "ThisWorkbook" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20266188/" ]
74,293,983
<p>I would like to transform values inside an object of an object. Something like this:</p> <p>Initial object:</p> <pre><code>const studentDetails = { 'details1': {Name: &quot;John&quot;, CountryName: &quot;US&quot;, value: 1}, 'details2': {Name: &quot;David&quot;, CountryName: &quot;AUS&quot;, value: 2}, 'details3': {Name: &quot;Bob&quot;, CountryName: &quot;UK&quot;, value: 3}, }; </code></pre> <p>Transformed object:</p> <pre><code>{ 'details1': {Name: &quot;John&quot;, CountryName: &quot;US&quot;, value: 2}, 'details2': {Name: &quot;David&quot;, CountryName: &quot;AUS&quot;, value: 3}, 'details3': {Name: &quot;Bob&quot;, CountryName: &quot;UK&quot;, value: 4}, }; </code></pre> <p>I did something like this already but could not figure it out</p> <pre><code>Object.fromEntries(Object.entries(studentDetails).map(([key, value]) =&gt; [key, some data transformation on value])) </code></pre>
[ { "answer_id": 74294852, "author": "Toddleson", "author_id": 14608750, "author_profile": "https://Stackoverflow.com/users/14608750", "pm_score": 1, "selected": false, "text": "ThisWorkbook" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10167498/" ]
74,293,999
<p>I want to check whether the console for the checkpoint firewalls is working or not which python Library should I use and how to use?</p> <p>I tried telnetlib but was unable to find the correct output</p>
[ { "answer_id": 74294852, "author": "Toddleson", "author_id": 14608750, "author_profile": "https://Stackoverflow.com/users/14608750", "pm_score": 1, "selected": false, "text": "ThisWorkbook" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74293999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20009627/" ]
74,294,014
<p>Code:</p> <pre><code>namespace DriversLicenceExam { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { LoadKey(); LoadAnswer(); } private void LoadKey() { try { const int AnsLgth = 20; string[] Answers = new string[AnsLgth]; int index = 0; System.IO.StreamReader inputFile; inputFile = File.OpenText(&quot;DRIVERKEY.txt&quot;); { Answers[index] = (inputFile.ReadLine()); index++; } inputFile.Close(); for (int i = 0; i &lt;= Answers.Length; i++) { string value = Answers[i]; listBox1.Items.Add(value); } } catch (Exception) { throw; } } </code></pre> <p>I keep getting an error stating 'Value cannot be null. Parameter name; item'</p> <p>I am relatively new to coding and not sure what this means. Any help or input is appreciated.</p> <p>The goal of this program is to insert an answer key file, turn it into an array, output it into a listbox, then do the same with answer files, grade the answer files that are submitted by &quot;students&quot; by crossreferencing them with the answer key array, then output the incorrect answers into another listbox.</p> <p>This is only the first method where I am supposed to input the answer key file then turn it into an array and display it in a listbox.</p> <p>The answer key text file looks like this:</p> <pre><code>B D A A C A B A C D B C D A D C C B D A </code></pre>
[ { "answer_id": 74294100, "author": "NineBerry", "author_id": 101087, "author_profile": "https://Stackoverflow.com/users/101087", "pm_score": 1, "selected": false, "text": "inputFile = File.OpenText(\"DRIVERKEY.txt\");\n\n{\n Answers[index] = (inputFile.ReadLine());\n index++;\n}\n" }, { "answer_id": 74294146, "author": "David", "author_id": 328193, "author_profile": "https://Stackoverflow.com/users/328193", "pm_score": 2, "selected": false, "text": "null" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19892544/" ]
74,294,018
<p>I took a <a href="https://developer.android.com/codelabs/basic-android-kotlin-compose-practice-navigation?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-practice-navigation#4" rel="nofollow noreferrer">Codelab Lunch-tray App</a> it had no Tests so I tried to create these tests to practice. I tried to create testcases for it based on another codelab <a href="https://developer.android.com/codelabs/basic-android-kotlin-compose-test-cupcake?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-test-cupcake#4" rel="nofollow noreferrer">Codelab Cupcake</a> The way these 2 projects differ is that on the second codelab(Lunch-tray) the &quot;Next&quot; button is in uppercase. Which I can not figure out how to write a test to make it pass.</p> <p><a href="https://i.stack.imgur.com/KIFR8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KIFR8.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/deFmx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/deFmx.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74294100, "author": "NineBerry", "author_id": 101087, "author_profile": "https://Stackoverflow.com/users/101087", "pm_score": 1, "selected": false, "text": "inputFile = File.OpenText(\"DRIVERKEY.txt\");\n\n{\n Answers[index] = (inputFile.ReadLine());\n index++;\n}\n" }, { "answer_id": 74294146, "author": "David", "author_id": 328193, "author_profile": "https://Stackoverflow.com/users/328193", "pm_score": 2, "selected": false, "text": "null" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7005465/" ]
74,294,046
<pre><code>String Template=&quot;&lt;P&gt;sooper&lt;/p&gt; String InputFolder=&quot;D:\\project&quot; String title=&quot;name&quot; FileWriter myWriter = null; File htmlContent = new File(InputFolder + File.separator + title+ &quot;.html&quot;); myWriter = new FileWriter(htmlContent); myWriter.write(Template); myWriter.close(); </code></pre> <p>This works fine</p> <p>but when I replace the title with any string which contains special characters the html file is not being created<a href="https://i.stack.imgur.com/RcQvs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RcQvs.png" alt="b" /></a></p> <p>I was expecting a html file would be created with the name name?.html</p>
[ { "answer_id": 74294100, "author": "NineBerry", "author_id": 101087, "author_profile": "https://Stackoverflow.com/users/101087", "pm_score": 1, "selected": false, "text": "inputFile = File.OpenText(\"DRIVERKEY.txt\");\n\n{\n Answers[index] = (inputFile.ReadLine());\n index++;\n}\n" }, { "answer_id": 74294146, "author": "David", "author_id": 328193, "author_profile": "https://Stackoverflow.com/users/328193", "pm_score": 2, "selected": false, "text": "null" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20177733/" ]
74,294,062
<p>Let's say there is a GUI program with two windows. Each window has its own OpenGL context. There is only one thread.</p> <p>At some point we want to render stuff in the first and in the second window, so we allocate one buffer for each of the OpenGL contexts with <code>glGenBuffers(1, &amp;buffer_)</code> (among other stuff).</p> <p>My question is, does the <code>glGenBuffers()</code> function returns unique object names globally, or is it local for each of the OpenGL contexts? In other words, can these two OpenGL contexts have the same object names given by the <code>glGenBuffers()</code>? Apart from object name == 0 of course, which is a special object name.</p> <p>In case they can, does it mean they share this object name? What would happen if one of the OpenGL contexts deallocates the object by <code>glDeleteBuffers(1, &amp;buffer_)</code>?</p>
[ { "answer_id": 74320386, "author": "MarsaPalas", "author_id": 1344572, "author_profile": "https://Stackoverflow.com/users/1344572", "pm_score": 0, "selected": false, "text": "glGenBuffers()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1344572/" ]
74,294,210
<p>I need the program to find the prime numbers and put them in an array and return them. I only want to use <code>System.out</code> in the Main class. What should I add to my code? Thanks.</p> <p>This is my first method in the first class to find which numbers are prime:</p> <pre class="lang-java prettyprint-override"><code>private boolean isPrime(int n) { for (int i = 2; i &lt; n; i++) { if (n % i == 0) return false; } return true; } </code></pre> <p>This is the other method that I need help with:</p> <pre class="lang-java prettyprint-override"><code>public int[] test(int a, int b) { //what do I write here for (int i = a; i &lt;= b; i++) { if (isPrime(i)) { //what do I write here, I only want to use syso in the other //class(Main). } } return ?; } </code></pre> <p>And this is my main Class:</p> <pre class="lang-java prettyprint-override"><code>public static void main(String... args) { Prime p = new Prime(); System.out.println(p.test(10, 30)); } </code></pre>
[ { "answer_id": 74294308, "author": "Jens", "author_id": 3636601, "author_profile": "https://Stackoverflow.com/users/3636601", "pm_score": 1, "selected": false, "text": "public int[] test(int a, int b) {\n List<Integer> result = new ArrayList<>();\n //what do I write here\n for (int i = a; i <= b; i++) {\n if (isPrime(i))\n result.add(i);\n //what do I write here, I only want to use syso in the other\n //class(Main).\n }\n return result.stream()\n .mapToInt(Integer::intValue)\n .toArray();\n}\n" }, { "answer_id": 74294317, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 1, "selected": false, "text": "public class Prime {\n\n public static void main(String... args) throws IOException {\n System.out.println(Arrays.toString(getPrimesWithin(10, 30)));\n }\n\n public static int[] getPrimesWithin(int lo, int hi) {\n return IntStream.rangeClosed(lo, hi)\n .filter(Prime::isPrime)\n .toArray();\n }\n\n private static boolean isPrime(int val) {\n if (val < 2)\n return false;\n\n for (int i = 2, sqrt = (int)Math.sqrt(val); i <= sqrt; i++)\n if (val % i == 0)\n return false;\n\n return true;\n }\n\n}\n" }, { "answer_id": 74294367, "author": "Francesco Aiello", "author_id": 17038347, "author_profile": "https://Stackoverflow.com/users/17038347", "pm_score": 0, "selected": false, "text": "test" }, { "answer_id": 74294371, "author": "Aman Mehta", "author_id": 13378772, "author_profile": "https://Stackoverflow.com/users/13378772", "pm_score": 0, "selected": false, "text": "test()" }, { "answer_id": 74294381, "author": "I.Yuldoshev", "author_id": 10602598, "author_profile": "https://Stackoverflow.com/users/10602598", "pm_score": 0, "selected": false, "text": "public int[] test(int a, int b) {\n List<Integer> list = new ArrayList<>();\n for (int i = a; i <= b; i++) {\n if (isPrime(i))\n list.add(i);\n }\n\n int c = 0;\n int[] result = new int[list.size()];\n for(int e : list) {\n result[c++] = e;\n }\n return result;\n}\n\npublic static void main(String[] args) {\n\n Prime p = new Prime();\n System.out.println(Arrays.toString(p.test(20, 100)));\n\n}\n" }, { "answer_id": 74295974, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "2" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13689270/" ]
74,294,213
<p>I have a table such as the one below (table1), and I am trying to write a query that shows only the 1st rows for each name, but those rows have a null for the title, so I want to pull in their titles from the immediate next row.</p> <p>table1</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Title</th> <th>Row</th> </tr> </thead> <tbody> <tr> <td>Dan</td> <td>NULL</td> <td>1</td> </tr> <tr> <td>Dan</td> <td>Engineer</td> <td>2</td> </tr> <tr> <td>Dan</td> <td>Developer</td> <td>3</td> </tr> <tr> <td>Jay</td> <td>NULL</td> <td>1</td> </tr> <tr> <td>Jay</td> <td>Lawyer</td> <td>2</td> </tr> </tbody> </table> </div> <p>The final result should look like the following:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Title</th> <th>Row</th> </tr> </thead> <tbody> <tr> <td>Dan</td> <td>Engineer</td> <td>1</td> </tr> <tr> <td>Jay</td> <td>Lawyer</td> <td>1</td> </tr> </tbody> </table> </div> <p>I've only written this so far, I don't know how to pull in the titles from the previous row. Any help would be greatly appreciated.</p> <pre><code>select * from table1 where Row = 1 </code></pre>
[ { "answer_id": 74294308, "author": "Jens", "author_id": 3636601, "author_profile": "https://Stackoverflow.com/users/3636601", "pm_score": 1, "selected": false, "text": "public int[] test(int a, int b) {\n List<Integer> result = new ArrayList<>();\n //what do I write here\n for (int i = a; i <= b; i++) {\n if (isPrime(i))\n result.add(i);\n //what do I write here, I only want to use syso in the other\n //class(Main).\n }\n return result.stream()\n .mapToInt(Integer::intValue)\n .toArray();\n}\n" }, { "answer_id": 74294317, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 1, "selected": false, "text": "public class Prime {\n\n public static void main(String... args) throws IOException {\n System.out.println(Arrays.toString(getPrimesWithin(10, 30)));\n }\n\n public static int[] getPrimesWithin(int lo, int hi) {\n return IntStream.rangeClosed(lo, hi)\n .filter(Prime::isPrime)\n .toArray();\n }\n\n private static boolean isPrime(int val) {\n if (val < 2)\n return false;\n\n for (int i = 2, sqrt = (int)Math.sqrt(val); i <= sqrt; i++)\n if (val % i == 0)\n return false;\n\n return true;\n }\n\n}\n" }, { "answer_id": 74294367, "author": "Francesco Aiello", "author_id": 17038347, "author_profile": "https://Stackoverflow.com/users/17038347", "pm_score": 0, "selected": false, "text": "test" }, { "answer_id": 74294371, "author": "Aman Mehta", "author_id": 13378772, "author_profile": "https://Stackoverflow.com/users/13378772", "pm_score": 0, "selected": false, "text": "test()" }, { "answer_id": 74294381, "author": "I.Yuldoshev", "author_id": 10602598, "author_profile": "https://Stackoverflow.com/users/10602598", "pm_score": 0, "selected": false, "text": "public int[] test(int a, int b) {\n List<Integer> list = new ArrayList<>();\n for (int i = a; i <= b; i++) {\n if (isPrime(i))\n list.add(i);\n }\n\n int c = 0;\n int[] result = new int[list.size()];\n for(int e : list) {\n result[c++] = e;\n }\n return result;\n}\n\npublic static void main(String[] args) {\n\n Prime p = new Prime();\n System.out.println(Arrays.toString(p.test(20, 100)));\n\n}\n" }, { "answer_id": 74295974, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 0, "selected": false, "text": "2" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19105904/" ]
74,294,221
<p>I'm helping to make a chatbot in C# but I have never worked with C# before so please forgive my ignorance. I'm using this link as a reference: <a href="https://jd-bots.com/2020/10/15/connect-bot-framework-to-db-part-3-read-data-from-azure-sql-database/" rel="nofollow noreferrer">https://jd-bots.com/2020/10/15/connect-bot-framework-to-db-part-3-read-data-from-azure-sql-database/</a></p> <p>I want to switch out the select query for a stored procedure which accomplishes the same thing (we need to do some joins that make more sense to do within SQL Server).</p> <p>The code below is based on the example from the link:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using EchoAzureDBBot.Models; using Microsoft.Bot.Builder; using Microsoft.Bot.Schema; namespace EchoAzureDBBot.Bots { public class EchoBot : ActivityHandler { EmployeeDBContext context; public EmployeeDBContext Context { get { return context; } } public EchoBot() { context = new EmployeeDBContext(); } public Employee FetchEmployeeName(string no) { Employee employee; try { employee = (from e in Context.Employee where e.Empid == no select e).FirstOrDefault();//Query for employee details with id } catch (Exception) { throw; } return employee; } protected override async Task OnMessageActivityAsync(ITurnContext&lt;IMessageActivity&gt; turnContext, CancellationToken cancellationToken) { var empNumber = turnContext.Activity.Text; Employee employee = FetchEmployeeName(empNumber); var replyText = employee.Empid + &quot;: &quot; + employee.Empname; await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken); } protected override async Task OnMembersAddedAsync(IList&lt;ChannelAccount&gt; membersAdded, ITurnContext&lt;IConversationUpdateActivity&gt; turnContext, CancellationToken cancellationToken) { var welcomeText = &quot;Hello and welcome! I have connected this bot to Azure DB.&quot;; //welcome message foreach (var member in membersAdded) { if (member.Id != turnContext.Activity.Recipient.Id) { await turnContext.SendActivityAsync(MessageFactory.Text(welcomeText, welcomeText), cancellationToken); } } } } } </code></pre> <p>What we want to do is have a stored procedure execute the query. So basically instead of:</p> <pre><code>employee = (from e in Context.Employee where e.Empid == emp_id //the id we pass in as a variable earlier select e).FirstOrDefault();//Query for employee details with id </code></pre> <p>We want the stored procedure which does the same thing to only return the <code>EmployeeName</code> from the query:</p> <pre><code>SqlCommand cmd = new SqlCommand(&quot;GetEmployee&quot;, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter(&quot;@EmployeeID&quot;, emp_id)) using (SqlDataReader rdr = cmd.ExecuteReader()) { employee = [EmployeeName] } </code></pre> <p>Would this be how to go about it? Is there a simple way to just pass in the <code>@EmployeeID</code> param and then do the following to get it to work? If so, where would this block of code go in the original code block, where the select query is now?</p> <pre><code>EXEC GetEmployee @EmployeeID = emp_id; </code></pre> <p>Thank you for your help!</p>
[ { "answer_id": 74295240, "author": "S. Davenport", "author_id": 10066380, "author_profile": "https://Stackoverflow.com/users/10066380", "pm_score": 3, "selected": true, "text": "SqlDataReader" }, { "answer_id": 74383402, "author": "Zakaria Najim", "author_id": 10155157, "author_profile": "https://Stackoverflow.com/users/10155157", "pm_score": 0, "selected": false, "text": " CREATE PROCEDURE [GetEmployee]\n (@EmployeeID int)\n AS\n BEGIN\n \n select EMPNAME from EMPLOYEE where EMPID=@EmployeeID\n \n END\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16519848/" ]
74,294,275
<p>I would like to create filter and aggregations after filter for procuts in Elasticsearch. I am having base aggregations for all products:</p> <pre><code> &quot;size&quot;: { &quot;doc_count_error_upper_bound&quot;: 0, &quot;sum_other_doc_count&quot;: 87, &quot;buckets&quot;: [ { &quot;key&quot;: &quot;6&quot;, &quot;doc_count&quot;: 89 }, { &quot;key&quot;: &quot;5,5&quot;, &quot;doc_count&quot;: 60 } ] } }, &quot;brand&quot;: { &quot;doc_count_error_upper_bound&quot;: 0, &quot;sum_other_doc_count&quot;: 87, &quot;buckets&quot;: [ { &quot;key&quot;: &quot;Apple&quot;, &quot;doc_count&quot;: 89 }, { &quot;key&quot;: &quot;Samsung&quot;, &quot;doc_count&quot;: 60 }, { &quot;key&quot;: &quot;Xiaomi&quot;, &quot;doc_count&quot;: 48 }, { &quot;key&quot;: &quot;Huawei&quot;, &quot;doc_count&quot;: 33 } ] } } </code></pre> <p>After I make query for one of those <strong>brands</strong> and size like:</p> <pre><code>query&quot;: { &quot;bool&quot;: { &quot;filter&quot;: [ &quot;term&quot;: { &quot;brand&quot;: &quot;Samsung&quot; }, &quot;term&quot;: { &quot;size&quot;: &quot;6&quot; } ] } } </code></pre> <p>I am getting back aggregations only for selected <strong>brand</strong>. But i still want to see in aggregations all others <strong>brands</strong> with same <strong>size</strong>.</p> <p>Is this possible with ES?</p> <p>Thank you so much for all answers.</p>
[ { "answer_id": 74295240, "author": "S. Davenport", "author_id": 10066380, "author_profile": "https://Stackoverflow.com/users/10066380", "pm_score": 3, "selected": true, "text": "SqlDataReader" }, { "answer_id": 74383402, "author": "Zakaria Najim", "author_id": 10155157, "author_profile": "https://Stackoverflow.com/users/10155157", "pm_score": 0, "selected": false, "text": " CREATE PROCEDURE [GetEmployee]\n (@EmployeeID int)\n AS\n BEGIN\n \n select EMPNAME from EMPLOYEE where EMPID=@EmployeeID\n \n END\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74294275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4734257/" ]