qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,304,019
<p>I have css file</p> <pre><code>table { border: 1px solid; width: 400px; } </code></pre> <p>And i have html file</p> <pre><code>&lt;link rel=&quot;stylesheet&quot; href=&quot;mytablediv.css&quot;&gt; &lt;table&gt;&lt;tr&gt;&lt;td&gt;table&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;div style=&quot;width:1000px;&quot;&gt;div&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; </code></pre> <p>I can't change html file but i can change css file.</p> <p>How to restrict width div element into table element and make it 400px?</p> <p>I tried div{ max-width:100% !important;} and it dont't work. Width of table with div is 1000px but i need 400 px.</p>
[ { "answer_id": 74304081, "author": "BeSter Development", "author_id": 20356148, "author_profile": "https://Stackoverflow.com/users/20356148", "pm_score": 1, "selected": true, "text": "table div { width: 100% !important; }\n" }, { "answer_id": 74304135, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 1, "selected": false, "text": "max-width: 400px" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408149/" ]
74,304,028
<p>I've trained a <code>segmentation_models_pytorch.PSPNet</code> model for image segmentation. For prediction I load whole image in <code>PyTorch tensor</code> and scan it with 384x384 pixels window.</p> <pre><code>result = model.predict(image_tensor[:, :, y:y+384, x:x+384]) </code></pre> <p>My Windows machine has 6Gb GPU, while Ubuntu has 8 Gb GPU. When all models are loaded they consume some 1.4 Gb GPU. When processing a large image on Windows the memory consumption increases to 1.7 Gb GPU.</p> <p>Under Windows the model can handle 25 M pixel images. Under Ubuntu the same code can only process up to 5 M pixel image. Debugging is difficult because I only have ssh access to the Ubuntu machine. What could cause this discrepancy and how to debug this issue?</p>
[ { "answer_id": 74304081, "author": "BeSter Development", "author_id": 20356148, "author_profile": "https://Stackoverflow.com/users/20356148", "pm_score": 1, "selected": true, "text": "table div { width: 100% !important; }\n" }, { "answer_id": 74304135, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 1, "selected": false, "text": "max-width: 400px" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304028", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6447563/" ]
74,304,041
<p>I have an <code>ArrayList</code> of <code>HashMap</code>s and each <code>HashMap</code> looks like:</p> <pre><code>{&quot;Start&quot;:&quot;A&quot;, &quot;End&quot;:&quot;B&quot;,&quot;Length&quot;:5} </code></pre> <p>I want to find the one that has the longest length, or maybe more than one, they all have the same length equal to the max length.</p> <p>Trying to use stream, how should I do it?</p> <pre><code>ArrayList&lt;HashMap&lt;String, Object&gt;&gt; resultslist = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;(); ArrayList&lt;HashMap&lt;String, Object&gt;&gt; finalresult = resultslist.stream().max() </code></pre>
[ { "answer_id": 74304413, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 3, "selected": true, "text": "{\"Start\":\"A\", \"End\":\"B\",\"Length\":5}" }, { "answer_id": 74304439, "author": "YCF_L", "author_id": 5558072, "author_profile": "https://Stackoverflow.com/users/5558072", "pm_score": 1, "selected": false, "text": "Collectors.groupingBy" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11019702/" ]
74,304,050
<p><strong>Problem: Return true if the sum of two different elements of the array equals the target, otherwise return false</strong> <br> I want to optimize the time complexity of this code. Now, code has O(n^2) complexity. How can I reduce complexity? input is unsorted array(<code>number[]</code>) and target(<code>number</code>), output is true or false.</p> <p>Here`s my code.</p> <pre class="lang-js prettyprint-override"><code>function find(arr, target) { for(let i = 0; i &lt; arr.length; i++){ for(let j = i + 1; j &lt; arr.length; j++){ if(target === (arr[i]+arr[j])){ return true; } } } return false; } </code></pre> <p>I think hint is <code>unsorted</code> array. And I don`t know at all..</p>
[ { "answer_id": 74304205, "author": "Marko Durasinovic", "author_id": 7131606, "author_profile": "https://Stackoverflow.com/users/7131606", "pm_score": 3, "selected": true, "text": "O(n log n)" }, { "answer_id": 74305563, "author": "Asraf", "author_id": 20361860, "author_profile": "https://Stackoverflow.com/users/20361860", "pm_score": 1, "selected": false, "text": "O(nlogn)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17685810/" ]
74,304,051
<p>So where I work we use a variety of IDEs. I'm the only one that is using Rider so I don't want to add it to the project <code>.gitignore</code> file. Rider creates a <code>.run</code> folder in the root of every project. I want to tell git to ignore this folder in all projects. I added a local <code>~/.gitignore</code> with the following content:</p> <pre><code>.run/ </code></pre> <p>Yet i'm still seeing the <code>.run</code> in <code>git status</code>. The <code>.run</code> folder is untracked: <a href="https://i.stack.imgur.com/H7lkB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H7lkB.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74304205, "author": "Marko Durasinovic", "author_id": 7131606, "author_profile": "https://Stackoverflow.com/users/7131606", "pm_score": 3, "selected": true, "text": "O(n log n)" }, { "answer_id": 74305563, "author": "Asraf", "author_id": 20361860, "author_profile": "https://Stackoverflow.com/users/20361860", "pm_score": 1, "selected": false, "text": "O(nlogn)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127954/" ]
74,304,052
<p>`I am writing a program for my computer science class and for whatever reason cannot get it to return the programs original menu after completing a task.</p> <p>I need the program to go back to the original menu and not just stop after completing an option. Ive tried adding a while loop and a for loop to the beginning of the program but it does not fix it. Should be a simple fix but idk what it is. Thanks.</p> <pre><code>import javax.lang.model.type.ArrayType; import java.sql.SQLOutput; import java.util.ArrayList; //import the arrayList class import java.util.Scanner; public class Main { static ArrayList&lt;String&gt; planets = new ArrayList&lt;&gt;(); public static void main(String[] args) { //Default values, can leave blank or remove planets.add(0, &quot;Mars&quot;); planets.add(1, &quot;Jupiter&quot;); planets.add(2, &quot;Earth&quot;); planets.add(3, &quot;Venus&quot;); planets.add(4, &quot;Neptune&quot;); planets.add(5, &quot;Saturn&quot;); boolean isactive; if (isactive =true) { System.out.println(&quot;Choose your favorite planets with this program. This program edits arrays, please choose an array position to edit [0,1,2,3]&quot;); System.out.println(&quot;1. Print Array&quot;); System.out.println(&quot;2. Edit Array&quot;); System.out.println(&quot;3. Add to array&quot;); System.out.println(&quot;4. Exit the program&quot;); ArrayList&lt;String&gt; cars = new ArrayList&lt;String&gt;(); Scanner scn = new Scanner(System.in); int MenuOption = scn.nextInt(); //Scan result if (MenuOption == 1) { System.out.println(planets); } if (MenuOption == 2) { System.out.println(&quot;Please choose which element to edit&quot;); System.out.println(&quot;0&quot;); System.out.println(&quot;1&quot;); System.out.println(&quot;2&quot;); System.out.println(&quot;3&quot;); System.out.println(&quot;4&quot;); System.out.println(&quot;5&quot;); System.out.println(&quot;6&quot;); System.out.println(&quot;7&quot;); System.out.println(&quot;Press 9 to exit&quot;); Scanner editMenu = new Scanner(System.in); int editMenuOption = editMenu.nextInt(); if (editMenuOption == 0) { System.out.println(&quot;what would you like to change position 0 to&quot;); Scanner posZeroScan = new Scanner(System.in); String posZeroScanEdit = posZeroScan.next(); planets.add(0, posZeroScanEdit); System.out.println(planets); } if (editMenuOption == 1) { System.out.println(&quot;what would you like to change position 1 to&quot;); Scanner posOneScan = new Scanner(System.in); String posOneScanEdit = posOneScan.next(); planets.add(1, posOneScanEdit); System.out.println(planets); } if (editMenuOption == 2) { System.out.println(&quot;what would you like to change position 2 to&quot;); Scanner posTwoScan = new Scanner(System.in); String posTwoScanEdit = posTwoScan.next(); planets.add(2, posTwoScanEdit); System.out.println(planets); } if (editMenuOption == 3) { System.out.println(&quot;what would you like to change position 3 to&quot;); Scanner posThreeScan = new Scanner(System.in); String posThreeScanEdit = posThreeScan.next(); planets.add(3, posThreeScanEdit); System.out.println(planets); } if (editMenuOption == 4) { System.out.println(&quot;what would you like to change position 4 to&quot;); Scanner posFourScan = new Scanner(System.in); String posFourScanEdit = posFourScan.next(); planets.add(4, posFourScanEdit); System.out.println(planets); } if (editMenuOption == 5) { System.out.println(&quot;what would you like to change position 4 to&quot;); Scanner posFiveScan = new Scanner(System.in); String posFiveScanEdit = posFiveScan.next(); planets.add(5, posFiveScanEdit); System.out.println(planets); } if (editMenuOption == 6) { System.out.println(&quot;what would you like to change position 4 to&quot;); Scanner posSixScan = new Scanner(System.in); String posSixScanEdit = posSixScan.next(); planets.add(6, posSixScanEdit); System.out.println(planets); } if (editMenuOption == 7) { System.out.println(&quot;what would you like to change position 4 to&quot;); Scanner posSevenScan = new Scanner(System.in); String posSevenScanEdit = posSevenScan.next(); planets.add(7, posSevenScanEdit); System.out.println(planets); } else { System.exit(1); } } if (MenuOption == 3) { System.out.println(&quot;What would you like to add&quot;); Scanner add = new Scanner(System.in); String addRes = add.next(); planets.add(addRes); System.out.println(planets); } if (MenuOption == 4) { System.out.println(&quot;Thanks for checking out my program!&quot;); System.exit(0); } } } } </code></pre> <pre><code>` </code></pre>
[ { "answer_id": 74304205, "author": "Marko Durasinovic", "author_id": 7131606, "author_profile": "https://Stackoverflow.com/users/7131606", "pm_score": 3, "selected": true, "text": "O(n log n)" }, { "answer_id": 74305563, "author": "Asraf", "author_id": 20361860, "author_profile": "https://Stackoverflow.com/users/20361860", "pm_score": 1, "selected": false, "text": "O(nlogn)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20275402/" ]
74,304,067
<p>Below you can see a code to build a network. With <code>probs = tf.nn.softmax(logits)</code>, I am getting probabilities:</p> <pre><code>def build_network_test(input_images, labels, num_classes): logits = embedding_model(input_images, train_phase=True) logits = fully_connected(logits, num_classes, activation_fn=None, scope='tmp') with tf.variable_scope('loss') as scope: with tf.name_scope('soft_loss'): softmax = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels)) probs = tf.nn.softmax(logits) scope.reuse_variables() with tf.name_scope('acc'): accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(logits, 1), labels), tf.float32)) with tf.name_scope('loss/'): tf.summary.scalar('TotalLoss', softmax) return logits, softmax, accuracy,probs # returns total loss </code></pre> <p>In addition, I am computing <code>accuracy</code> and <code>loss</code> with following code snippet:</p> <pre><code>for idx in range(num_of_batches): batch_images, batch_labels = get_batch(idx, FLAGS.batch_size, mm_labels, mm_data) _, summary_str, train_batch_acc, train_batch_loss, probabilities_1 = sess.run( [train_op, summary_op, accuracy, total_loss, probs], feed_dict={ input_images: batch_images - mean_data_img_train, labels: batch_labels, }) train_acc += train_batch_acc train_loss += train_batch_loss train_acc /= num_of_batches train_acc = train_acc * 100 </code></pre> <p><strong>My question:</strong></p> <p>I am getting probabilities with two feature values. Afterwards, I am averaging these probabilities with following code</p> <pre><code>mvalue = np.mean(np.array([probabilities_1, probabilities_2]), axis=0) </code></pre> <p>Now, I want to compute <code>accuracy</code> on <code>mvalue</code>. Can someone give me pointers on how to do it?</p> <p><strong>What I had done so far</strong></p> <pre><code>tmp = tf.argmax(input=mvalue, axis=1) an_array = tmp.eval(session=tf.compat.v1.Session()) </code></pre> <p>It gives me predicated labels however, I want to have an accuracy value.</p>
[ { "answer_id": 74411077, "author": "Mohammad Ahmed", "author_id": 7746219, "author_profile": "https://Stackoverflow.com/users/7746219", "pm_score": 2, "selected": false, "text": "tf.compat.v1.keras.metrics.categorical_accuracy()" }, { "answer_id": 74427458, "author": "saad_saeed", "author_id": 15900935, "author_profile": "https://Stackoverflow.com/users/15900935", "pm_score": 2, "selected": true, "text": "mvalue = np.mean(np.array([probabilities_1, probabilities_2]), axis=0)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8967121/" ]
74,304,071
<p>I am working on .NET 6 application with entity framework core. I am creating record search query using LINQ where I am expecting to receive List of string. No of string values are not fixed and will varies. How I can use List in LINQ contain?</p> <pre><code>List&lt;string&gt; Roles = new List&lt;string&gt;() { &quot;Business Analyst&quot;, &quot;Business Analysis Lead&quot;, &quot;Application Support Analyst&quot; }; var records = (from jobProfile in db.JobProfiles where jobProfile.Role.Contains(Roles) select jobProfile).ToList(); </code></pre>
[ { "answer_id": 74304266, "author": "Dave Cousineau", "author_id": 621316, "author_profile": "https://Stackoverflow.com/users/621316", "pm_score": 3, "selected": true, "text": "var records = (\n from jobProfile in db.JobProfiles\n where jobProfile.Role.Any(r => Roles.Contains(r.Name))\n select jobProfile\n).ToList();\n" }, { "answer_id": 74304317, "author": "kaffekopp", "author_id": 10428821, "author_profile": "https://Stackoverflow.com/users/10428821", "pm_score": 1, "selected": false, "text": "var records = (from jobProfile in db.JobProfiles\n where Roles.Contains(jobProfile.Role) \n select jobProfile).ToList();\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304071", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1892256/" ]
74,304,076
<p>I am trying to complete a homework exercise for the following and I am stumped:</p> <blockquote> <p>Create a variable called <code>mark</code> and assign it the value 65. Then write a series of <code>if ... elif ... else</code> statements to assign a new variable a grade such that marks below 50 produce &quot;Fail&quot;, from 50 to 59 produce &quot;Pass&quot;, from 60 to 69 produce &quot;Merit&quot; and from 70 and up produce &quot;Distiction&quot;.</p> <p>Print the grade.</p> <p>Then implement the same logic again, but this time without using if statements.</p> </blockquote> <p>I am able to complete the first part but I am unsure on how to do the same avoiding IF functions - can anyone help?</p> <p>Using IF functions I have the following which works as expected:</p> <pre><code>mark = 50 if mark &gt; 69: print(mark, &quot;marks is a Distinction&quot;) elif mark &lt;= 69 and mark &gt;= 60: print(mark, &quot;marks is a Merit&quot;) elif mark &lt;= 59 and mark &gt;= 50: print(mark, &quot;markss is a Pass&quot;) else: print(mark, &quot;marks is a Fail&quot;) </code></pre> <p>I have no idea where to begin for avoiding if functions</p>
[ { "answer_id": 74304248, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 3, "selected": false, "text": "mark = 50\nif mark > 69:\n print(mark, \"marks is a Distinction\")\nelif mark >= 60:\n print(mark, \"marks is a Merit\")\nelif mark >= 50:\n print(mark, \"marks is a Pass\")\nelse:\n print(mark, \"marks is a Fail\")\n" }, { "answer_id": 74304252, "author": "Yevhen Kuzmovych", "author_id": 4727702, "author_profile": "https://Stackoverflow.com/users/4727702", "pm_score": 2, "selected": false, "text": "[\"Fail\", \"Pass\", \"Merit\", \"Distinction\"]" }, { "answer_id": 74304356, "author": "Gábor Fekete", "author_id": 6464041, "author_profile": "https://Stackoverflow.com/users/6464041", "pm_score": 1, "selected": false, "text": "grades = [\"Fail\"]*50 + [\"Pass\"]*10 + [\"Merit\"]*10 + [\"Distiction\"]\n\nfor mark in [-100,0,49,50,51,59,60,61,69,70,71,120]:\n print(mark,grades[min(len(grades)-1,max(0,mark))])\n" }, { "answer_id": 74304466, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 1, "selected": false, "text": "mark = 65\n\nprint(\"Fail\"*(mark < 50) + \"Pass\"*(50 <= mark < 60) + \"Merit\"*(60 <= mark < 70) + \"Distinction\"*(70 <= mark))\n\n# Merit\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408318/" ]
74,304,092
<p>I have table days table.There is oper_day column:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>oper_day</th> </tr> </thead> <tbody> <tr> <td>01.01.2021</td> </tr> <tr> <td>02.01.2021</td> </tr> <tr> <td>03.01.2021</td> </tr> <tr> <td>**********</td> </tr> <tr> <td>**********</td> </tr> <tr> <td>31.12.2022</td> </tr> </tbody> </table> </div> <p>I want to output the maximum date available in a table that is less than the first date of each quarter <strong>for example:</strong> quarter_date: 01.10.2022 if 30.09.2022 has in a table I give 30.09.2022 else 29.09.2022 .How can I write query?</p>
[ { "answer_id": 74304248, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 3, "selected": false, "text": "mark = 50\nif mark > 69:\n print(mark, \"marks is a Distinction\")\nelif mark >= 60:\n print(mark, \"marks is a Merit\")\nelif mark >= 50:\n print(mark, \"marks is a Pass\")\nelse:\n print(mark, \"marks is a Fail\")\n" }, { "answer_id": 74304252, "author": "Yevhen Kuzmovych", "author_id": 4727702, "author_profile": "https://Stackoverflow.com/users/4727702", "pm_score": 2, "selected": false, "text": "[\"Fail\", \"Pass\", \"Merit\", \"Distinction\"]" }, { "answer_id": 74304356, "author": "Gábor Fekete", "author_id": 6464041, "author_profile": "https://Stackoverflow.com/users/6464041", "pm_score": 1, "selected": false, "text": "grades = [\"Fail\"]*50 + [\"Pass\"]*10 + [\"Merit\"]*10 + [\"Distiction\"]\n\nfor mark in [-100,0,49,50,51,59,60,61,69,70,71,120]:\n print(mark,grades[min(len(grades)-1,max(0,mark))])\n" }, { "answer_id": 74304466, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 1, "selected": false, "text": "mark = 65\n\nprint(\"Fail\"*(mark < 50) + \"Pass\"*(50 <= mark < 60) + \"Merit\"*(60 <= mark < 70) + \"Distinction\"*(70 <= mark))\n\n# Merit\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17757058/" ]
74,304,194
<p>I try to add folder scanning into my web page. Folder selection works fine and I get prompted if I want to allow the access to selected folder. But then nothing happens. In console I see &quot;1&quot; as the last log entry, so await never returns.</p> <p>Any ideas what I should do?</p> <pre><code>jQuery(document).ready(function ($) { const butDir = document.getElementById('butDirectory'); butDir.addEventListener('click', async() =&gt; { console.log(&quot;1&quot;); const dirHandle = await window.showDirectoryPicker(); console.log(&quot;2&quot;); const promises = []; for await (const entry of dirHandle.values()) { if (entry.kind !== 'file') { continue; } promises.push(entry.getFile().then((file) =&gt; `${file.name} (${file.size})`)); } console.log(await Promise.all(promises)); }); }); </code></pre>
[ { "answer_id": 74304248, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 3, "selected": false, "text": "mark = 50\nif mark > 69:\n print(mark, \"marks is a Distinction\")\nelif mark >= 60:\n print(mark, \"marks is a Merit\")\nelif mark >= 50:\n print(mark, \"marks is a Pass\")\nelse:\n print(mark, \"marks is a Fail\")\n" }, { "answer_id": 74304252, "author": "Yevhen Kuzmovych", "author_id": 4727702, "author_profile": "https://Stackoverflow.com/users/4727702", "pm_score": 2, "selected": false, "text": "[\"Fail\", \"Pass\", \"Merit\", \"Distinction\"]" }, { "answer_id": 74304356, "author": "Gábor Fekete", "author_id": 6464041, "author_profile": "https://Stackoverflow.com/users/6464041", "pm_score": 1, "selected": false, "text": "grades = [\"Fail\"]*50 + [\"Pass\"]*10 + [\"Merit\"]*10 + [\"Distiction\"]\n\nfor mark in [-100,0,49,50,51,59,60,61,69,70,71,120]:\n print(mark,grades[min(len(grades)-1,max(0,mark))])\n" }, { "answer_id": 74304466, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 1, "selected": false, "text": "mark = 65\n\nprint(\"Fail\"*(mark < 50) + \"Pass\"*(50 <= mark < 60) + \"Merit\"*(60 <= mark < 70) + \"Distinction\"*(70 <= mark))\n\n# Merit\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44715/" ]
74,304,200
<p>I have the following question:</p> <p>I have three Buttons that are displayed next to each other in either yellow, red or green. I would like to have them, say, 20 times in a random colour order.</p> <p>But with my code, I only get them in the order of my statusCases, and only three times. The colour of the buttons is defined by the class they have.</p> <p>How can I iterate over the list more then once to get more buttons? Do I have to edit my object?</p> <p>Here is my code:</p> <pre><code>&lt;button *ngFor=&quot;let case of statusCases; let i = index&quot; class= {{case.cases}} &gt; &lt;/button&gt; </code></pre> <p>(Button in the html)</p> <pre><code>export class AvgProvisioningTimeComponent implements OnInit { @Output() updateTestStatuses = new EventEmitter&lt;string&gt;(); statusCases: Object[]; constructor() { this.statusCases = [ {cases: &quot;status__button status__button--red&quot;}, {cases: &quot;status__button status__button--yellow&quot;}, {cases: &quot;status__button status__button--green&quot;}, ]; } ngOnInit(): void { } updateTestStatus(status: string): void { this.updateTestStatuses.emit(status); } } </code></pre> <p>( My class in .ts)</p> <p>I would be very happy, if anyone could help me :)</p>
[ { "answer_id": 74304542, "author": "Morty", "author_id": 12189042, "author_profile": "https://Stackoverflow.com/users/12189042", "pm_score": 2, "selected": true, "text": "<div *ngFor=\"let button of [0, 1, 2, 3, 4, 5]; index as i\">\n <button id={{i}} [ngStyle]=\"getClassrandom(i)\">Hello</button>\n</div>\n" }, { "answer_id": 74306056, "author": "Mohamed Ali", "author_id": 15920337, "author_profile": "https://Stackoverflow.com/users/15920337", "pm_score": 0, "selected": false, "text": "this.statusCases.fill(20)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17248515/" ]
74,304,202
<p>As we know, Microsoft has stopped basic authentication for all of its services. Now we need to use modern authentication.</p> <p>A few years ago, I developed (in C#) a service that ran on a Windows server and sent emails automatically. I was using SMTP with basic authentication (login + password). The implementation was very simple and the program worked like a charm. Now that's another story. I have to use OAuth2 and since the program is a service the authentication has to be done without user interaction.</p> <p>I contacted our O365 expert who simply created an application in Azure. Nothing more... I have to deal with that. He gave me this information (obviously the information is hidden):</p> <p>TenantID: xxxxxxxx CLientID: xxxxxxx ClientSecret: xxxxxxx SecretID: xxxxxxxx</p> <p>What is strange here is that I don't see any link with the mailbox I use to send emails.</p> <p>Also I asked him to make me a screenshot with the permissions configuration in Azure. <a href="https://i.stack.imgur.com/OWdep.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OWdep.jpg" alt="Screenshot" /></a></p> <p>What I want to do is simple. I just want to send mails using the mailbox that I used with the SMTP protocol. I don't want to do anything else, just send.</p> <p>I tried the code below (in VB.NET) and I do get a token.</p> <pre><code>Dim credentials = New ClientSecretCredential(tenantID, clientID, clientSecret, New TokenCredentialOptions With {.AuthorityHost = AzureAuthorityHosts.AzurePublicCloud}) Dim graphServiceClient As New GraphServiceClient(credentials) </code></pre> <p>After I used this code to send an email (variables are initialized with the correct values) :</p> <pre><code> Dim mailMessage = New Message With { .Subject = subject, .Body = New ItemBody With { .ContentType = BodyType.Html, .Content = message }, .ToRecipients = toRecipients, .CcRecipients = ccRecipients } ' Send mail as the given user. graphServiceClient.Users(fromAddress).SendMail(mailMessage, True).Request().PostAsync().Wait() </code></pre> <p>But I get an error:</p> <p><a href="https://i.stack.imgur.com/m3dJi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m3dJi.jpg" alt="enter image description here" /></a></p> <p>Apparently I don't have the right to use the email address that is in the 'fromAddress' variable.</p> <p>I can understand it because as I said at the beginning, what link can the application registered in Azure have with the mailbox that I want to use to send an email?</p> <p>This is where I arrived. And there, I turn around.</p> <p>If anyone could help me and point me in the right direction...</p> <p>Thank you all.</p>
[ { "answer_id": 74304542, "author": "Morty", "author_id": 12189042, "author_profile": "https://Stackoverflow.com/users/12189042", "pm_score": 2, "selected": true, "text": "<div *ngFor=\"let button of [0, 1, 2, 3, 4, 5]; index as i\">\n <button id={{i}} [ngStyle]=\"getClassrandom(i)\">Hello</button>\n</div>\n" }, { "answer_id": 74306056, "author": "Mohamed Ali", "author_id": 15920337, "author_profile": "https://Stackoverflow.com/users/15920337", "pm_score": 0, "selected": false, "text": "this.statusCases.fill(20)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20407953/" ]
74,304,267
<p>I have an array of tasks [begin, end, period].</p> <p>Each task needs to be completed within the time range from begin to end, and the period is the length of time required to finish the task.</p> <ol> <li>The period can be discontinuous time</li> <li>The begin and end are included</li> <li>We can handle an unlimited number of tasks at the same time.</li> </ol> <p>Find the minimum time to process all the tasks</p> <p><strong>Example:</strong> <strong>Input:</strong></p> <pre><code>[[1,3,2],[2,5,3],[5,6,2]] </code></pre> <p><strong>Output:</strong></p> <pre><code>4 </code></pre> <p><strong>Explanation:</strong></p> <pre><code>For tasks[0] we can have time points 2,3 For tasks[1] we can have time points 2, 3, 5 For tasks[2] we can time points 5, 6 </code></pre> <p>So we only needs to be on at time points 2,3,5 and 6 to complete the task.</p> <p><strong>My approach:</strong></p> <pre><code>int process(List&lt;List&lt;Integer&gt;&gt; list) { Set&lt;Integer&gt; s = new HashSet&lt;&gt;(); for(List&lt;Integer&gt; p : list) { int period = p.get(p.size()-1); List&lt;Integer&gt; other = new ArrayList&lt;&gt;(); int i=0; int s = p.get(0); int e = p.get(1); for(i=s; i&lt;=e &amp;&amp; period &gt;=0; i++) { if(s.contains(i)) { period--; } else { other.add(i); } } if(period != 0) { for(i=other.size()-1; i&gt;=0 &amp;&amp; period &gt;0; i--, period--) { s.add(other.get(i)); } } } return s.size(); } </code></pre> <p>Here I am trying to add the tasks to a set, and when I have already got the required tasks for a time period I am going to the next task. But my approach is not correct.</p> <p>What is the correct approach to solving this problem? I am looking for an approach in Java or python.</p>
[ { "answer_id": 74317904, "author": "lzl", "author_id": 20312513, "author_profile": "https://Stackoverflow.com/users/20312513", "pm_score": -1, "selected": false, "text": "int process(List<Integer> list) {\n Set<Integer> s = new HashSet<>();\n for(List<Integer> p : list) {\n int period = p.get(p.size()-1);\n int s = p.get(0);\n int e = p.get(1);\n for(int i=s; i<=e; i++) {\n s.add(i);\n }\n }\n\n return s.size();\n}\n" }, { "answer_id": 74331405, "author": "leetcode_dafu", "author_id": 20428392, "author_profile": "https://Stackoverflow.com/users/20428392", "pm_score": 2, "selected": false, "text": "at time 1, we meet (1,2,starting), start at 1 and need 2 time, stack=[(1,2)]\n\nat time 2, we meet (2,3,starting), start at 2 and need 3 time, stack=[(1,2),(2,3]\n\nat time 3, we meet ending time 3 for (1,2). res+=2 as 2 is what (1,2) left. now we remove (1,2) and substract all active tasks in stack by at most 2. for (2,3), we can take away 2 pts. stack=[(2,1)]\n\nat time 5, we first meet (5,2,starting), start at 5 and need 2 time, stack=[(2,1),(5,2)]\n\nat time 5, we also meet endining pt for (2,1), res+=1, which is what (2,1) left, we remove (2,1) from stack and substract all active tasks in stack by at most 1. (5,2) starts at 5, it can have 1 pts at 5, so it becomes(5,1), stack=[(5,1)]\n\nat time 6, we meet the end of (5,1), res+=1, stop.\n\nres=4\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3181365/" ]
74,304,273
<p>I have tens of thousands of files which will need to be renamed in large batches after being manually manipulated. All of the files will have a barcode followed by a unique identifying string of alphanumerics. They will all have the same .PDF extension as well. All files should have an underscore before the unique identifier.</p> <p>For example: <code>12 44571 522110_10_E-354-98-U90368.ENG</code><br /> or : <code>14 44571 500169_9_Monroe NE_G-462-02-5674.GER</code></p> <p>What I need to keep after renaming these files is the unique identifier which looks like this:</p> <pre><code> E-354-98-U90368.ENG G-462-02-5674.GER </code></pre> <p>I am not versed in Powershell and have found a 2-step process that works, but if there is an error in the file name, to begin with, it deletes the extension and the important unique identifier above.</p> <p>The two-step process is this. 1st, get rid of the barcode and <em>#</em> after it for each file. If it does not have a name after this, then I'm done. If in the 2nd example, there is <em>Monroe NE</em> between the barcode and the unique identifier, I use the 2nd step.</p> <p>How can I delete everything before the LAST occurrence of the Underscore in one step?</p> <p>This is what I tried:</p> <p>1st Step :</p> <pre><code>Get-ChildItem -File &quot;Folder Path Name&quot; | Rename-Item -NewName { $_.Name -replace &quot;Barcode&quot;, &quot;&quot; } </code></pre> <p>2nd Step:</p> <pre><code>$Files = Get-ChildItem -Path 'Folder Path Name’ -File foreach ($File in $Files) { $Split = $File.Name -split '_' if ($Split.Count -gt 1) { Rename-Item -Path $File.FullName -NewName $Split[1]}} </code></pre>
[ { "answer_id": 74317904, "author": "lzl", "author_id": 20312513, "author_profile": "https://Stackoverflow.com/users/20312513", "pm_score": -1, "selected": false, "text": "int process(List<Integer> list) {\n Set<Integer> s = new HashSet<>();\n for(List<Integer> p : list) {\n int period = p.get(p.size()-1);\n int s = p.get(0);\n int e = p.get(1);\n for(int i=s; i<=e; i++) {\n s.add(i);\n }\n }\n\n return s.size();\n}\n" }, { "answer_id": 74331405, "author": "leetcode_dafu", "author_id": 20428392, "author_profile": "https://Stackoverflow.com/users/20428392", "pm_score": 2, "selected": false, "text": "at time 1, we meet (1,2,starting), start at 1 and need 2 time, stack=[(1,2)]\n\nat time 2, we meet (2,3,starting), start at 2 and need 3 time, stack=[(1,2),(2,3]\n\nat time 3, we meet ending time 3 for (1,2). res+=2 as 2 is what (1,2) left. now we remove (1,2) and substract all active tasks in stack by at most 2. for (2,3), we can take away 2 pts. stack=[(2,1)]\n\nat time 5, we first meet (5,2,starting), start at 5 and need 2 time, stack=[(2,1),(5,2)]\n\nat time 5, we also meet endining pt for (2,1), res+=1, which is what (2,1) left, we remove (2,1) from stack and substract all active tasks in stack by at most 1. (5,2) starts at 5, it can have 1 pts at 5, so it becomes(5,1), stack=[(5,1)]\n\nat time 6, we meet the end of (5,1), res+=1, stop.\n\nres=4\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304273", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408169/" ]
74,304,290
<p>I am making a React-Native mobile application and want to incorporate Firebase and Firebase Authentication. However, I am facing this error when I run 'pod install' or 'pod update':</p> <p><a href="https://i.stack.imgur.com/vbtmv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vbtmv.png" alt="enter image description here" /></a></p> <p>I did some research and found out that this issue has not yet been resolved by Google (<a href="https://issuetracker.google.com/issues/254418199" rel="noreferrer">https://issuetracker.google.com/issues/254418199</a>), but I came across a workaround (<a href="https://github.com/firebase/firebase-ios-sdk/issues/10359" rel="noreferrer">https://github.com/firebase/firebase-ios-sdk/issues/10359</a>) which said to add a version specifier to the Podfile: pod 'FirebaseAuth', '&gt;= 9.6.0'. However, even after I added the line into the Podfile in my iOS folder, the same error still persists. May I know if I'm doing something wrongly?</p>
[ { "answer_id": 74310601, "author": "Alex Rendón", "author_id": 5627152, "author_profile": "https://Stackoverflow.com/users/5627152", "pm_score": 3, "selected": false, "text": "$FirebaseSDKVersion = '9.6.0'" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18731432/" ]
74,304,304
<p>I have the below nested data array. I would like to filter on the second level of children leaving only the children that have a name of either &quot;Assistant&quot; or &quot;Advisor&quot; while keeping the rest of the underlying data structure the same.</p> <pre><code>data = [{ &quot;name&quot;: &quot;root&quot;, &quot;median&quot;: 60000.0, &quot;children&quot;: [{ &quot;name&quot;: &quot;Defence&quot;, &quot;median&quot;: 60000.0, &quot;children&quot;: [{ &quot;name&quot;: &quot;Assistant&quot;, &quot;median&quot;: 30000.0, }, { &quot;name&quot;: &quot;Advisor&quot;, &quot;median&quot;: 50000.0, }, { &quot;name&quot;: &quot;Secretary&quot;, &quot;median&quot;: 60000.0, }, { &quot;name&quot;: &quot;Administrator&quot;, &quot;median&quot;: 60000.0, }, { &quot;name&quot;: &quot;Assistant&quot;, &quot;median&quot;: 20000.0, }, ] }, { &quot;name&quot;: &quot;Healthcare&quot;, &quot;median&quot;: 60000, &quot;children&quot;: [{ &quot;name&quot;: &quot;Manager&quot;, &quot;median&quot;: 80000, }, { &quot;name&quot;: &quot;Advisor&quot;, &quot;median&quot;: 60000, }, { &quot;name&quot;: &quot;Legal&quot;, &quot;median&quot;: 20000, }, { &quot;name&quot;: &quot;Cashier&quot;, &quot;median&quot;: 30000, }, ] } ] }] </code></pre> <p>The desired outcome leaves the upper level children the same while returning the second level children that match &quot;Assistant&quot; and &quot;Advisor&quot;.</p> <pre><code>data = [{ &quot;name&quot;: &quot;root&quot;, &quot;median&quot;: 60000.0, &quot;children&quot;: [{ &quot;name&quot;: &quot;Defence&quot;, &quot;median&quot;: 60000.0, &quot;children&quot;: [{ &quot;name&quot;: &quot;Assistant&quot;, &quot;median&quot;: 30000.0, }, { &quot;name&quot;: &quot;Advisor&quot;, &quot;median&quot;: 50000.0, }, { &quot;name&quot;: &quot;Assistant&quot;, &quot;median&quot;: 20000.0, }, ] }, { &quot;name&quot;: &quot;Healthcare&quot;, &quot;median&quot;: 60000, &quot;children&quot;: [{ &quot;name&quot;: &quot;Advisor&quot;, &quot;median&quot;: 60000, }, ] } ] }] </code></pre> <p>I have tried to use a combination of <code>map()</code> and <code>filter()</code> but it only returns the matching second level children.</p> <pre><code>var fmatch = [&quot;Assistant&quot;, &quot;Advisor&quot;] console.log(data.map(c=&gt; c.children.map(c =&gt; c.children.filter(c =&gt; fmatch.includes(c.name))))) </code></pre> <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>data = data = [{ "name": "root", "median": 60000.0, "children": [{ "name": "Defence", "median": 60000.0, "children": [{ "name": "Assistant", "median": 30000.0, }, { "name": "Advisor", "median": 50000.0, }, { "name": "Secretary", "median": 60000.0, }, { "name": "Administrator", "median": 60000.0, }, { "name": "Assistant", "median": 20000.0, }, ] }, { "name": "Healthcare", "median": 60000, "children": [{ "name": "Manager", "median": 80000, }, { "name": "Advisor", "median": 60000, }, { "name": "Legal", "median": 20000, }, { "name": "Cashier", "median": 30000, }, ] } ] }] var fmatch = ["Assistant", "Advisor"] console.log(data.map(c=&gt; c.children.map(c =&gt; c.children.filter(c =&gt; fmatch.includes(c.name)))))</code></pre> </div> </div> </p>
[ { "answer_id": 74310601, "author": "Alex Rendón", "author_id": 5627152, "author_profile": "https://Stackoverflow.com/users/5627152", "pm_score": 3, "selected": false, "text": "$FirebaseSDKVersion = '9.6.0'" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9710121/" ]
74,304,321
<p>I'm attempting to create a new array from an existing array and add &quot;!&quot; to each username from the old array. What i am getting is ['[object Object]!'].</p> <pre><code>// Complete the below questions using this array: const array = [ { username: &quot;john&quot;, team: &quot;red&quot;, score: 5, items: [&quot;ball&quot;, &quot;book&quot;, &quot;pen&quot;] }, { username: &quot;becky&quot;, team: &quot;blue&quot;, score: 10, items: [&quot;tape&quot;, &quot;backpack&quot;, &quot;pen&quot;] }, { username: &quot;susy&quot;, team: &quot;red&quot;, score: 55, items: [&quot;ball&quot;, &quot;eraser&quot;, &quot;pen&quot;] }, { username: &quot;tyson&quot;, team: &quot;green&quot;, score: 1, items: [&quot;book&quot;, &quot;pen&quot;] }, ]; //Create an array using forEach that has all the usernames with a &quot;!&quot; to each of the usernames const player = [] const newArray = array.forEach((username) =&gt; { player.push(username + '!'); }) console.log(player); </code></pre>
[ { "answer_id": 74304390, "author": "Axekan", "author_id": 12519793, "author_profile": "https://Stackoverflow.com/users/12519793", "pm_score": 0, "selected": false, "text": "username" }, { "answer_id": 74304410, "author": "Michiel Janssen", "author_id": 20169332, "author_profile": "https://Stackoverflow.com/users/20169332", "pm_score": 0, "selected": false, "text": "// Complete the below questions using this array:\nconst array = [\n {\n username: \"john\",\n team: \"red\",\n score: 5,\n items: [\"ball\", \"book\", \"pen\"]\n },\n {\n username: \"becky\",\n team: \"blue\",\n score: 10,\n items: [\"tape\", \"backpack\", \"pen\"]\n },\n {\n username: \"susy\",\n team: \"red\",\n score: 55,\n items: [\"ball\", \"eraser\", \"pen\"]\n },\n {\n username: \"tyson\",\n team: \"green\",\n score: 1,\n items: [\"book\", \"pen\"]\n },\n \n ];\n \n //Create an array using forEach that has all the usernames with a \"!\" to each of the usernames\n const player = []\n const newArray = array.forEach((username) => {\n player.push(username.username + '!');\n })\n console.log(player);\n" }, { "answer_id": 74304460, "author": "bloodyKnuckles", "author_id": 2743458, "author_profile": "https://Stackoverflow.com/users/2743458", "pm_score": 0, "selected": false, "text": "forEach()" }, { "answer_id": 74304507, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "const array=[{username:\"john\",team:\"red\",score:5,items:[\"ball\",\"book\",\"pen\"]},{username:\"becky\",team:\"blue\",score:10,items:[\"tape\",\"backpack\",\"pen\"]},{username:\"susy\",team:\"red\",score:55,items:[\"ball\",\"eraser\",\"pen\"]},{username:\"tyson\",team:\"green\",score:1,items:[\"book\",\"pen\"]}];\n\n// using each player, append \"!\" to the end to create a new array\nconst players = array.map((user) => user.username + \"!\");\n\nconsole.log(players);" }, { "answer_id": 74313530, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 0, "selected": false, "text": "Array.map()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15205760/" ]
74,304,365
<p>I am trying to understand how <code>tokio</code> runtime works, i created two runtimes(on purpose) using <code>#[tokio::main]</code> macro, the first should executes <code>function a()</code> and the second executes <code>function b()</code>.</p> <p>I am assuming that they should be both printing <code>&quot;im awake A&quot;</code> and <code>&quot;im awake B&quot;</code> simultaniosuly forever (since they are calling a function that has a loop <code>async_task</code>), however that is not the case, it only prints <code>&quot;im awake A&quot;.</code></p> <p>since each runtime has its own thread pool; why they are not running in parallel?</p> <pre><code>use std::thread; fn main() { a(); b(); } #[tokio::main] async fn a() { tokio::spawn(async move { async_task(&quot;A&quot;.to_string()).await }); } pub async fn async_task(msg: String) { loop { thread::sleep(std::time::Duration::from_millis(1000)); println!(&quot;im awake {}&quot;, msg); } } #[tokio::main] async fn b() { tokio::spawn(async move { async_task(&quot;B&quot;.to_string()).await }); } </code></pre>
[ { "answer_id": 74304390, "author": "Axekan", "author_id": 12519793, "author_profile": "https://Stackoverflow.com/users/12519793", "pm_score": 0, "selected": false, "text": "username" }, { "answer_id": 74304410, "author": "Michiel Janssen", "author_id": 20169332, "author_profile": "https://Stackoverflow.com/users/20169332", "pm_score": 0, "selected": false, "text": "// Complete the below questions using this array:\nconst array = [\n {\n username: \"john\",\n team: \"red\",\n score: 5,\n items: [\"ball\", \"book\", \"pen\"]\n },\n {\n username: \"becky\",\n team: \"blue\",\n score: 10,\n items: [\"tape\", \"backpack\", \"pen\"]\n },\n {\n username: \"susy\",\n team: \"red\",\n score: 55,\n items: [\"ball\", \"eraser\", \"pen\"]\n },\n {\n username: \"tyson\",\n team: \"green\",\n score: 1,\n items: [\"book\", \"pen\"]\n },\n \n ];\n \n //Create an array using forEach that has all the usernames with a \"!\" to each of the usernames\n const player = []\n const newArray = array.forEach((username) => {\n player.push(username.username + '!');\n })\n console.log(player);\n" }, { "answer_id": 74304460, "author": "bloodyKnuckles", "author_id": 2743458, "author_profile": "https://Stackoverflow.com/users/2743458", "pm_score": 0, "selected": false, "text": "forEach()" }, { "answer_id": 74304507, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "const array=[{username:\"john\",team:\"red\",score:5,items:[\"ball\",\"book\",\"pen\"]},{username:\"becky\",team:\"blue\",score:10,items:[\"tape\",\"backpack\",\"pen\"]},{username:\"susy\",team:\"red\",score:55,items:[\"ball\",\"eraser\",\"pen\"]},{username:\"tyson\",team:\"green\",score:1,items:[\"book\",\"pen\"]}];\n\n// using each player, append \"!\" to the end to create a new array\nconst players = array.map((user) => user.username + \"!\");\n\nconsole.log(players);" }, { "answer_id": 74313530, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 0, "selected": false, "text": "Array.map()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13347445/" ]
74,304,384
<p>I have a huge nested json file and I want to get the values of &quot;text&quot; but only on a certain level as there are many &quot;text&quot; keys deeper in the json file. The level I mean would be the &quot;text:&quot;Hi&quot; after &quot;event&quot;:&quot;user&quot;.</p> <p>The file looks like this:</p> <p>`</p> <pre><code> { &quot;_id&quot;:{ &quot;$oid&quot;:&quot;123&quot; }, &quot;events&quot;:[ { &quot;event&quot;:&quot;action&quot;, &quot;metadata&quot;:{ &quot;model_id&quot;:&quot;12&quot; }, &quot;action_text&quot;:null, &quot;hide_rule_turn&quot;:false }, { &quot;event&quot;:&quot;user&quot;, &quot;text&quot;:&quot;Hi&quot;, &quot;parse_data&quot;:{ &quot;intent&quot;:{ &quot;name&quot;:&quot;greet&quot;, &quot;confidence&quot;:{ &quot;$numberDouble&quot;:&quot;0.9601748585700989&quot; } }, &quot;entities&quot;:[ ], &quot;text&quot;:&quot;Hi&quot;, &quot;metadata&quot;:{ }, &quot;text_tokens&quot;:[ [ { &quot;$numberInt&quot;:&quot;0&quot; }, { &quot;$numberInt&quot;:&quot;2&quot; } ] ], &quot;selector&quot;:{ &quot;ideas&quot;:{ &quot;response&quot;:{ &quot;responses&quot;:[ { &quot;text&quot;:&quot;yeah&quot; }, { &quot;text&quot;:&quot;No&quot; }, { &quot;text&quot;:&quot;Goo&quot; } ] }, </code></pre> <p>`</p> <p>First I uses this function to get the text data but of course if gave me all of them:</p> <pre><code> def json_extract(obj, key): &quot;&quot;&quot;Recursively fetch values from nested JSON.&quot;&quot;&quot; arr = [] def extract(obj, arr, key): &quot;&quot;&quot;Recursively search for values of key in JSON tree.&quot;&quot;&quot; if isinstance(obj, dict): for k, v in obj.items(): if isinstance(v, (dict, list)): extract(v, arr, key) elif k == key: arr.append(v) elif isinstance(obj, list): for item in obj: extract(item, arr, key) return arr values = extract(obj, arr, key) return values </code></pre> <p>I also tried to access only the second level through this text but it gave me a KeyNotFound Error:</p> <pre><code> for i in data[&quot;events&quot;][0]: print(i[&quot;text&quot;]) </code></pre> <p>Maybe because that key is not in every nested list? ... I really don't know what else I could do</p>
[ { "answer_id": 74304602, "author": "Caldazar", "author_id": 1992773, "author_profile": "https://Stackoverflow.com/users/1992773", "pm_score": 2, "selected": true, "text": "events" }, { "answer_id": 74304819, "author": "Cobra", "author_id": 17580381, "author_profile": "https://Stackoverflow.com/users/17580381", "pm_score": 0, "selected": false, "text": "def json_extract(jdata):\n assert isinstance(jdata, dict)\n arr = []\n\n def _extract(d, arr):\n if 'event' in d and (t := d.get('text')):\n arr.append(t)\n for k, v in d.items():\n if k not in {'event', 'text'}:\n if isinstance(v, list):\n for e in v:\n if isinstance(e, dict):\n _extract(e, arr)\n elif isinstance(v, dict):\n _extract(v, arr)\n return arr\n return _extract(jdata, arr)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20379749/" ]
74,304,389
<p>I have an array of hashes in ruby like this</p> <pre><code>blah = [{&quot;key1&quot;=&gt;&quot;value1&quot;,&quot;key2&quot;=&gt;&quot;value2&quot;,&quot;key3&quot;=&gt;&quot;value3&quot;....}] </code></pre> <p>Now let's say I want to get the value of key2.</p> <p>What I am doing is <code>puts &quot;key 2 is #{blah[&quot;key2&quot;]}&quot;</code>, but then I get <code>ERROR: &quot;no implicit conversion of String into Integer (TypeError)&quot;</code></p>
[ { "answer_id": 74304602, "author": "Caldazar", "author_id": 1992773, "author_profile": "https://Stackoverflow.com/users/1992773", "pm_score": 2, "selected": true, "text": "events" }, { "answer_id": 74304819, "author": "Cobra", "author_id": 17580381, "author_profile": "https://Stackoverflow.com/users/17580381", "pm_score": 0, "selected": false, "text": "def json_extract(jdata):\n assert isinstance(jdata, dict)\n arr = []\n\n def _extract(d, arr):\n if 'event' in d and (t := d.get('text')):\n arr.append(t)\n for k, v in d.items():\n if k not in {'event', 'text'}:\n if isinstance(v, list):\n for e in v:\n if isinstance(e, dict):\n _extract(e, arr)\n elif isinstance(v, dict):\n _extract(v, arr)\n return arr\n return _extract(jdata, arr)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19958572/" ]
74,304,405
<p>I have the list:</p> <pre class="lang-py prettyprint-override"><code>[0, 15, 19, 26, 34, 62] </code></pre> <p>How would I go about converting it into the following?</p> <pre class="lang-py prettyprint-override"><code>[[0, 15], [19, 26], [34, 62]] </code></pre>
[ { "answer_id": 74304464, "author": "KillerRebooted", "author_id": 18554284, "author_profile": "https://Stackoverflow.com/users/18554284", "pm_score": 0, "selected": false, "text": "list = [0, 15, 19, 26, 34, 62]\n\nnew_list = []\nfor i in range(0, len(list), 2):\n new_list.append([list[i], list[i+1]])\n" }, { "answer_id": 74304469, "author": "Shahab Rahnama", "author_id": 8767186, "author_profile": "https://Stackoverflow.com/users/8767186", "pm_score": 1, "selected": false, "text": "numpy" }, { "answer_id": 74304490, "author": "Yuri", "author_id": 15822654, "author_profile": "https://Stackoverflow.com/users/15822654", "pm_score": 0, "selected": false, "text": ">>> a = [0, 15, 19, 26, 34, 62]\n>>> [[a[l*2], a[l*2 + 1]] for l in range(int(len(a)/2))]\n[[0, 15], [19, 26], [34, 62]]\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11774730/" ]
74,304,407
<p>I am working on adding pagination to a table using antd. This is the following code</p> <pre><code>const columns = [ { title: &quot;Name&quot;, dataIndex: &quot;name&quot;, width: 150 }, { title: &quot;Age&quot;, dataIndex: &quot;age&quot;, width: 150 }, { title: &quot;Address&quot;, dataIndex: &quot;address&quot; } ]; const data = []; for (let i = 0; i &lt; 100; i++) { data.push({ key: i, name: `Edward King ${i}`, age: 32, address: `London, Park Lane no. ${i}` }); } const App = () =&gt; ( &lt;Table columns={columns} dataSource={data} pagination={{ pageSizeOptions: [5, 10, 15, 20], defaultPageSize: 5 }} /&gt; ); </code></pre> <p>I want 5/page(as shown in the image attached) to be customized to 5people/page. The 5/page comes by default but how I customize it to my requirement? I checked the properties of pagination but I am not sure what to do.</p> <p><a href="https://i.stack.imgur.com/AF54F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AF54F.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74334318, "author": "stasdes", "author_id": 2091359, "author_profile": "https://Stackoverflow.com/users/2091359", "pm_score": 1, "selected": false, "text": "<Table>" }, { "answer_id": 74342558, "author": "Renee", "author_id": 10419901, "author_profile": "https://Stackoverflow.com/users/10419901", "pm_score": 1, "selected": true, "text": "pagination={{\n pageSizeOptions: [5, 10, 15, 20],\n defaultPageSize: 5\n locale: {items_per_page: \"people / page\"}\n}}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10419901/" ]
74,304,426
<p>I'm having an issue where my code just feels messy and I need some help on how I could structure it better.</p> <p>example:</p> <pre><code>if (object.getDescription() == Status.Expected &amp;&amp; !logEvent.equals(&quot;Expected&quot;)) { System.out.println(&quot;Do nothing&quot;); // ??? } else { status.setChangedBy(logEvent); } </code></pre> <p>How can i format this if in a cleaner way? I want the <code>changedBy</code> method to be called in every case except when <code>getDescription == Status.Expected</code> and <code>logEvent</code> is not <code>&quot;Expected&quot;</code>. But I don't want an empty if statement either.</p> <p>An alternative is:</p> <pre><code>if (object.getDescription() == Status.Expected) { if (logEvent.equals(&quot;Expected&quot;)) { status.setChangedBy(logEvent); } } else { status.setChangedBy(logEvent); } </code></pre> <p>Both examples work. But neither examples &quot;feels right&quot;. Is there any other solution I'm not seeing?</p>
[ { "answer_id": 74304564, "author": "Coline MIGNOT", "author_id": 19103327, "author_profile": "https://Stackoverflow.com/users/19103327", "pm_score": 1, "selected": false, "text": "if (object.getDescription() != Status.Expected || logEvent.equals(\"Expected\")) {\n status.setChangedBy(logEvent);\n}\n" }, { "answer_id": 74304585, "author": "Sweeper", "author_id": 5133585, "author_profile": "https://Stackoverflow.com/users/5133585", "pm_score": 4, "selected": true, "text": "!" }, { "answer_id": 74304596, "author": "Morph21", "author_id": 7406338, "author_profile": "https://Stackoverflow.com/users/7406338", "pm_score": 1, "selected": false, "text": "if (shouldChangeStatus(object, logEvent))\n status.setChangedBy(logEvent);\n}\n\nprivate boolean shouldChangeStatus(Object object, Object logEvent) {\n if (object.getDescription() != Status.Expected) {\n return true;\n }\n if (logEvent.equals(\"Expected\")) {\n return true;\n }\n return false;\n}\n" }, { "answer_id": 74306443, "author": "Jared Renzullo", "author_id": 20409306, "author_profile": "https://Stackoverflow.com/users/20409306", "pm_score": 0, "selected": false, "text": "\"Expected\".equals(logEvent)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10832299/" ]
74,304,446
<p>I'm creating an application with the bottom navigator. I used a <code>ShellRoute</code> but our requirement is to hide bottom navigator on screen For example: main page can have bottom navigator when i go to another screen (such an user profile page) I have to hide bottom navigator but i use <code>ShellRoute</code> and sub route in the same <code>ShellRoute</code>, it doesn't hide bottom navigator.</p> <pre><code>ShellRoute( navigatorKey: _shellNavigatorKey, builder: (context, state, child) { return MainScreen(child: child); }, routes: [ GoRoute( path: '/$dashboardRouteName', name: dashboardRouteName, pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: UniqueKey(), child: const DashboardScreen(), ), routes: [ GoRoute( path: leaveRequestRouteName, name: '$dashboardRouteName/$leaveRequestRouteName', pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: state.pageKey, child: const LeaveRequestScreen(), ), ), GoRoute( path: switchHolidayRouteName, name: '$dashboardRouteName/$switchHolidayRouteName', pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: state.pageKey, child: const SwitchHolidayScreen(), ), ), ], ), </code></pre> <p>after that, i separate sub route into general route like below:</p> <pre><code> ShellRoute( navigatorKey: _shellNavigatorKey, builder: (context, state, child) { return MainScreen(child: child); }, routes: [ GoRoute( path: '/$dashboardRouteName', name: dashboardRouteName, pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: UniqueKey(), child: const DashboardScreen(), ), ), .... GoRoute( path: '/$switchHolidayRouteName', name: switchHolidayRouteName, pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: state.pageKey, child: const SwitchHolidayScreen(), ), ), GoRoute( path: '/$leaveRequestRouteName', name: leaveRequestRouteName, pageBuilder: (context, state) =&gt; CustomPageRouteBuilder.route( key: state.pageKey, child: const LeaveRequestScreen(), ), ), </code></pre> <p>and i use <code>context.go()</code>, it works but i can't back to previous screen with <code>context.pop()</code>.</p> <p>anyone has any idea?</p>
[ { "answer_id": 74305757, "author": "john", "author_id": 16146701, "author_profile": "https://Stackoverflow.com/users/16146701", "pm_score": 0, "selected": false, "text": "GoRouter.of(context).location" }, { "answer_id": 74315654, "author": "Unemploy", "author_id": 18167489, "author_profile": "https://Stackoverflow.com/users/18167489", "pm_score": 1, "selected": false, "text": "final _navigatorKey = GlobalKey<NavigatorState>();\nfinal _shellNavigatorKey = GlobalKey<NavigatorState>();\n...\nShellRoute(\n navigatorKey: _shellNavigatorKey,\n builder: (context, state, child) {\n return MainScreen(child: child);\n },\n routes: [\n GoRoute(\n path: '/$dashboardRouteName',\n name: dashboardRouteName,\n pageBuilder: (context, state) => CustomPageRouteBuilder.route(\n key: UniqueKey(),\n child: const DashboardScreen(),\n ),\n routes: [\n GoRoute(\n path: leaveRequestRouteName,\n parentNavigatorKey: _navigatorKey,\n name: '$dashboardRouteName/$leaveRequestRouteName',\n pageBuilder: (context, state) => CustomPageRouteBuilder.route(\n key: state.pageKey,\n child: const LeaveRequestScreen(),\n ),\n ),\n GoRoute(\n path: switchHolidayRouteName,\n parentNavigatorKey: _navigatorKey,\n name: '$dashboardRouteName/$switchHolidayRouteName',\n pageBuilder: (context, state) => CustomPageRouteBuilder.route(\n key: state.pageKey,\n child: const SwitchHolidayScreen(),\n ),\n ),\n ],\n ),\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18167489/" ]
74,304,449
<p>I'm trying to extract even number from an array.</p> <p>I feel like I'm almost getting it, but I keep getting this error and don't know what to do.</p> <blockquote> <p>(int[])': not all code paths return a value</p> </blockquote> <p>I know I need a return value but I want to return nothing, but just the values as per the if statement.</p> <p>The If statement is basically:</p> <pre class="lang-cs prettyprint-override"><code>if (arr[i] % 2 == 0) </code></pre> <p>so this is the condition for me to get even values in the array, which is what I want.</p> <p>Then now I need to return something apparently, based on my research. But I just want to return the even values as gotten from the if statement. My current code:</p> <pre class="lang-cs prettyprint-override"><code>static int[] ExtractEvenNumber(int[] arr) { for (int i = 0; i &lt; arr.Length; i++) { if (arr[i] % 2 == 0) { Console.Write(arr[i] + &quot; &quot;); } } // so I need a return value here? what do I return? //I dont want to return arr; cause it'll just repeat the arr. } </code></pre> <p>EDIT:</p> <p>This is what I want to get (the bold value):</p> <p>[ 4 1 2 5 6 1 3 ] -&gt; <strong>[ 4 2 6 ]</strong></p> <p>The sample array is on the left.</p> <p>I tried to return int[];</p> <p>but it is giving me more errors?</p> <p><a href="https://i.stack.imgur.com/I3J7A.png" rel="nofollow noreferrer">enter image description here</a></p> <p><em>Question has been solved. Thank you everyone! :)</em></p>
[ { "answer_id": 74304614, "author": "AoooR", "author_id": 16233618, "author_profile": "https://Stackoverflow.com/users/16233618", "pm_score": 0, "selected": false, "text": "static int[] ExtractEvenNumber(int[] arr)" }, { "answer_id": 74304908, "author": "Matthew Watson", "author_id": 106159, "author_profile": "https://Stackoverflow.com/users/106159", "pm_score": 2, "selected": true, "text": "List<T>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408471/" ]
74,304,457
<p>After looking at <a href="https://stackoverflow.com/questions/54020807/python-type-hints-ignored">this question</a> I learned that the type hints are, by default, not enforced whilst executing Python code.</p> <p>One can detect <em>some</em> discrepancies between the type hints and actual argument types using a slightly convoluted process of running <code>pyannotate</code> to generate stubs whilst running Python code, and scanning for differences after applying these stubs to the code.</p> <p>However, it would be more convenient/faster to directly raise an exception if an incoming argument is not of the type included in the type hint. This can be achieved by manually including:</p> <pre class="lang-py prettyprint-override"><code>if not isinstance(some_argument, the_type_hint_type): raise TypeError(&quot;Argument:{argument} is not of type:{the_type_hint_type}&quot;) </code></pre> <p>However, that is quite labour intensive. Hence, I was curious, is it possible to make Python raise an error if a type-hint is violated, using an CLI argument or pip package or something like that?</p>
[ { "answer_id": 74304755, "author": "a.t.", "author_id": 7437143, "author_profile": "https://Stackoverflow.com/users/7437143", "pm_score": 0, "selected": false, "text": "pip install typeguard\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7437143/" ]
74,304,467
<p>I have two arrays of objects. One with a json variable and one with an information variable. The information variable is the one that should be equal to the json variable. This is because, information is data from the front and json is data from the database, so I must check that this information is totally the same. In this case the example that I put in all are the same. But it is just for example. So what should I do:</p> <ol> <li>Compare the information variable with the json variable.</li> <li>Start comparing data by data.</li> <li>If the data is the same a message 'Everything went well' and if not 'there is an error'</li> </ol> <p>I was trying it like this so that it goes through all the data but it throws me certain errors, such as the same element going through me twice. I was reading that it can also be done with filter, I have seen a lot of documentation but I cannot implement it in my case. Below in the code I show with whom to compare</p> <pre><code> var json = [ { Transacción: &quot;999999&quot;, Tarjeta: &quot;0190&quot;, Tipo: &quot;Contr ctdo&quot;, FechaDePago: &quot;07/08/2022&quot;, Ventas: &quot;-5.000,00&quot;, }, { Transacción: &quot;999997&quot;, Tarjeta: &quot;0194&quot;, Tipo: &quot;Contr ctdo&quot;, FechaDePago: &quot;06/08/2022&quot;, Ventas: &quot;4.000,00&quot;, }, { Transacción: &quot;999998&quot;, Tarjeta: &quot;0195&quot;, Tipo: &quot;Contr ctdo&quot;, &quot;FechaDePago&quot;: &quot;08/08/2022&quot;, Ventas: &quot;6.000,00&quot;, }, ]; var informacion = [ { Trx: &quot;Contr ctdo&quot;, Fecha: &quot;07/08/2022&quot;, TermLoteCupon: &quot;999999&quot;, Tarj: &quot;0190&quot;, VentasconDto: &quot;-5.000,00&quot;, }, { Trx: &quot;Contr ctdo&quot;, Fecha: &quot;06/08/2022&quot;, TermLoteCupon: &quot;999997&quot;, Tarj: &quot;0194&quot;, VentasconDto: &quot;4.000,00&quot;, }, { Trx: &quot;Contr ctdo&quot;, Fecha: &quot;08/08/2022&quot;, TermLoteCupon: &quot;999998&quot;, Tarj: &quot;0195&quot;, VentasconDto: &quot;6.000,00&quot;, }, ]; // The comparison should be that the data object array must be equal to the array of json objects. //The comparison is : //Trx must be equal to Tipo //Fecha must be equal to FechaDePago //TermLoteCupon must be equal to Transacción // Tarj must be equal to Tarjeta //VentasconDto must be equal to Ventas // What I did was the following: for (let i = 0; i &lt; informacion.length; i++) { console.log('soy newarray', informacion[i]); for(let j = 0; j &lt; json.length; j++){ console.log('soy json parseado',json[j]); if(json[j] == informacion[i]){ console.log('La informacion es compatible') }else{ console.log('Hay error.') } } } </code></pre> <p><a href="https://i.stack.imgur.com/3qz18.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3qz18.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74304571, "author": "Marko Durasinovic", "author_id": 7131606, "author_profile": "https://Stackoverflow.com/users/7131606", "pm_score": -1, "selected": false, "text": "function isEqual(json, informaction) {\n return json.Transacción === informacion.TermLoteCupon &&\n json.Tarjeta === informacion.Tarj &&\n json.Tipo === informacion.Trx &&\n json.FechaDePago === informacion.Fecha &&\n json.Ventas === informacion.VentasconDto;\n}\n" }, { "answer_id": 74304832, "author": "MWO", "author_id": 9175097, "author_profile": "https://Stackoverflow.com/users/9175097", "pm_score": 0, "selected": false, "text": "var json = [\n {\n Transacción: \"999999\",\n Tarjeta: \"0190\",\n Tipo: \"Contr ctdo\",\n FechaDePago: \"07/08/2022\",\n Ventas: \"-5.000,00\",\n },\n {\n Transacción: \"999997\",\n Tarjeta: \"0194\",\n Tipo: \"Contr ctdo\",\n FechaDePago: \"06/08/2022\",\n Ventas: \"4.000,00\",\n },\n {\n Transacción: \"999998\",\n Tarjeta: \"0195\",\n Tipo: \"Contr ctdo\",\n \"FechaDePago\": \"08/08/2022\",\n Ventas: \"6.000,00\",\n },\n ];\n \n \n var informacion = [\n {\n Trx: \"Contr ctdo\",\n Fecha: \"07/08/2022\",\n TermLoteCupon: \"999999\",\n Tarj: \"0190\",\n VentasconDto: \"-5.000,00\",\n },\n {\n Trx: \"Contr ctdo\",\n Fecha: \"06/08/2022\",\n TermLoteCupon: \"999997\",\n Tarj: \"0194\",\n VentasconDto: \"4.000,00\",\n },\n {\n Trx: \"Contr ctdo\",\n Fecha: \"08/08/2022\",\n TermLoteCupon: \"999998\",\n Tarj: \"0195\",\n VentasconDto: \"6.000,00\",\n },\n ];\n\n const result = json.filter((item, i) =>\n (item.Tipo === informacion[i].Trx) \n && (item.FechaDePago === informacion[i].Fecha) \n && (item.Transacción === informacion[i].TermLoteCupon) \n && (item.Tarjeta === informacion[i].Tarj) \n && (item.Ventas === informacion[i].VentasconDto)\n )\n\n console.log(result)\n\n if(result.length === json.length){\n console.log(\"it's equal\");\n }else{\n console.log(\"it's not equal\");\n }" }, { "answer_id": 74305764, "author": "Peter Seliger", "author_id": 2627243, "author_profile": "https://Stackoverflow.com/users/2627243", "pm_score": 2, "selected": true, "text": "informacion" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19047022/" ]
74,304,500
<p>I'm trying to mock out my requests. get with a side effect. I would like to associate a different status_code for each side effect value but I didn't succeed so far.</p> <pre class="lang-py prettyprint-override"><code> def test_func1(mocker): side_effect = [&quot;Ok&quot;,'','','Failed'] # This line should be changed fake_resp.status_code = 200 fake_resp = mocker.Mock() fake_resp.json = mocker.Mock(side_effect=side_effect) mocker.patch(&quot;app.main.requests.get&quot;, return_value=fake_resp) # The func1 is executing multiple API calls using requests.get() and status_code is needed a = func1(a, b) assert a == &quot;something&quot; </code></pre> <p>I have not been able to find a way (in the doc and SO) to associate the status_code for each mock request.</p> <p>I was thinking about something like this but it's obviously not working:</p> <pre class="lang-py prettyprint-override"><code> def test_func1(mocker): side_effect = [(status_code=200, return=&quot;Ok&quot;), (status_code=204, return=&quot;&quot;), (status_code=204, return=&quot;&quot;), (status_code=500, return=&quot;Failed&quot;)] .... </code></pre> <p>Edit: add func1 code</p> <pre class="lang-py prettyprint-override"><code>from datetime import datetime, timedelta import requests def func1(days, delta_1): &quot;&quot;&quot; days: number of days before first search (80, 25, 3) delta_1: number of days for the date range search (40, 20, 15) &quot;&quot;&quot; now = datetime.now() start_date = now + timedelta(days=days) # Var to stop loop when price is found loop_stop = 0 # Var to stop loop when search date is more than a year later delta_time = 0 price = 0 departureDate = &quot;n/a&quot; # For loop to check prices till one year. while loop_stop == 0 and delta_time &lt; (365 - days): date_range = ( (start_date + timedelta(days=delta_time)).strftime(&quot;%Y%m%d&quot;) + &quot;-&quot; + (start_date + timedelta(days=delta_time + (delta_1 / 2))).strftime( &quot;%Y%m%d&quot; ) ) # Needs to be mocked response = requests.get(&quot;fake_url_using_date_range_var&quot;) if response.status_code == 204: print(&quot;No data found on this data range&quot;) delta_time += delta_1 elif response.status_code == 200: price = response.json()[&quot;XXX&quot;][0] departureDate = response.json()[&quot;YYY&quot;][0] loop_stop = 1 else: raise NameError( response.status_code, &quot;Error occured while querying API&quot;, response.json(), ) return price, departureDate </code></pre>
[ { "answer_id": 74307001, "author": "frankfalse", "author_id": 18108367, "author_profile": "https://Stackoverflow.com/users/18108367", "pm_score": 2, "selected": true, "text": "unittest" }, { "answer_id": 74314831, "author": "baguette", "author_id": 16317072, "author_profile": "https://Stackoverflow.com/users/16317072", "pm_score": 0, "selected": false, "text": "class MockResponse:\n def __init__(self, json_data, status_code=requests.codes.ok):\n self.json_data = json_data\n self.status_code = status_code\n\n def json(self):\n return self.json_data\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16317072/" ]
74,304,504
<p>So, i made a script with a rather large table be warned,</p> <pre><code>mod = { {&quot;1&quot;, &quot;a&quot;}, {&quot;2&quot;, &quot;i&quot;}, {&quot;3&quot;, &quot;u&quot;}, {&quot;4&quot;, &quot;e&quot;}, {&quot;5&quot;, &quot;o&quot;}, {&quot;6&quot;, &quot;ka&quot;}, {&quot;7&quot;, &quot;ki&quot;}, {&quot;8&quot;, &quot;ku&quot;}, {&quot;9&quot;, &quot;ke&quot;}, {&quot;10&quot;, &quot;ko&quot;}, {&quot;11&quot;, &quot;sa&quot;}, {&quot;12&quot;, &quot;shi&quot;}, {&quot;13&quot;, &quot;su&quot;}, {&quot;14&quot;, &quot;se&quot;}, {&quot;15&quot;, &quot;so&quot;}, {&quot;16&quot;, &quot;ta&quot;}, {&quot;17&quot;, &quot;chi&quot;}, {&quot;18&quot;, &quot;tsu&quot;}, {&quot;19&quot;, &quot;te&quot;}, {&quot;20&quot;, &quot;to&quot;}, {&quot;21&quot;, &quot;na&quot;}, {&quot;22&quot;, &quot;ni&quot;}, {&quot;23&quot;, &quot;nu&quot;}, {&quot;24&quot;, &quot;ne&quot;}, {&quot;25&quot;, &quot;no&quot;}, {&quot;26&quot;, &quot;ha&quot;}, {&quot;27&quot;, &quot;hi&quot;}, {&quot;28&quot;, &quot;fu&quot;}, {&quot;29&quot;, &quot;he&quot;}, {&quot;30&quot;, &quot;ho&quot;}, {&quot;31&quot;, &quot;ma&quot;}, {&quot;32&quot;, &quot;mi&quot;}, {&quot;33&quot;, &quot;mu&quot;}, {&quot;34&quot;, &quot;me&quot;}, {&quot;35&quot;, &quot;mo&quot;}, {&quot;36&quot;, &quot;ya&quot;}, {&quot;37&quot;, &quot;yu&quot;}, {&quot;38&quot;, &quot;yo&quot;}, {&quot;39&quot;, &quot;ra&quot;}, {&quot;40&quot;, &quot;ri&quot;}, {&quot;41&quot;, &quot;ru&quot;}, {&quot;42&quot;, &quot;re&quot;}, {&quot;43&quot;, &quot;ro&quot;}, {&quot;44&quot;, &quot;wa&quot;}, {&quot;45&quot;, &quot;wo&quot;}, {&quot;46&quot;, &quot;n&quot;}, {&quot;47&quot;, &quot;ga&quot;}, {&quot;48&quot;, &quot;gi&quot;}, {&quot;49&quot;, &quot;gu&quot;}, {&quot;50&quot;, &quot;ge&quot;}, {&quot;51&quot;, &quot;go&quot;}, {&quot;52&quot;, &quot;za&quot;}, {&quot;53&quot;, &quot;ji&quot;}, {&quot;54&quot;, &quot;zu&quot;}, {&quot;55&quot;, &quot;ze&quot;}, {&quot;56&quot;, &quot;zo&quot;}, {&quot;57&quot;, &quot;da&quot;}, {&quot;58&quot;, &quot;ji&quot;}, {&quot;59&quot;, &quot;zu&quot;}, {&quot;60&quot;, &quot;de&quot;}, {&quot;61&quot;, &quot;do&quot;}, {&quot;62&quot;, &quot;ba&quot;}, {&quot;63&quot;, &quot;bi&quot;}, {&quot;64&quot;, &quot;bu&quot;}, {&quot;65&quot;, &quot;be&quot;}, {&quot;66&quot;, &quot;bo&quot;}, {&quot;67&quot;, &quot;pa&quot;}, {&quot;68&quot;, &quot;pi&quot;}, {&quot;69&quot;, &quot;pu&quot;}, {&quot;70&quot;, &quot;pe&quot;}, {&quot;71&quot;, &quot;po&quot;}, {&quot;72&quot;, &quot;kya&quot;}, {&quot;73&quot;, &quot;kyu&quot;}, {&quot;74&quot;, &quot;kyo&quot;}, {&quot;75&quot;, &quot;gya&quot;}, {&quot;76&quot;, &quot;gyu&quot;}, {&quot;77&quot;, &quot;gyo&quot;}, {&quot;78&quot;, &quot;sha&quot;}, {&quot;79&quot;, &quot;shu&quot;}, {&quot;80&quot;, &quot;sho&quot;}, {&quot;81&quot;, &quot;jya&quot;}, {&quot;82&quot;, &quot;jyu&quot;}, {&quot;83&quot;, &quot;jyo&quot;}, {&quot;84&quot;, &quot;cha&quot;}, {&quot;85&quot;, &quot;chu&quot;}, {&quot;86&quot;, &quot;cho&quot;}, {&quot;87&quot;, &quot;nya&quot;}, {&quot;88&quot;, &quot;nyu&quot;}, {&quot;89&quot;, &quot;nyo&quot;}, {&quot;90&quot;, &quot;hya&quot;}, {&quot;91&quot;, &quot;hyu&quot;}, {&quot;92&quot;, &quot;hyo&quot;}, {&quot;93&quot;, &quot;bya&quot;}, {&quot;94&quot;, &quot;byu&quot;}, {&quot;95&quot;, &quot;byo&quot;}, {&quot;96&quot;, &quot;pya&quot;}, {&quot;97&quot;, &quot;pyu&quot;}, {&quot;98&quot;, &quot;pyo&quot;}, {&quot;99&quot;, &quot;mya&quot;}, {&quot;100&quot;, &quot;myu&quot;}, {&quot;101&quot;, &quot;myo&quot;}, {&quot;102&quot;, &quot;rya&quot;}, {&quot;103&quot;, &quot;ryu&quot;}, {&quot;104&quot;, &quot;ryo&quot;}, } local str = &quot;&quot; local RN = 0 local c = 0 local NL = 5 repeat RN = 13 -- for i,v in ipairs(mod) do if v[1] == RN then ------ here local RL = v[2] str = str.. RL print(str) c = c + 1 end end until c == NL </code></pre> <p>and i was having issues with the line i have marked, I am attempting to retreive the 13th item in the table, (&quot;su&quot;) and if i were to type 13 instead of RN (which has a value of 13) it would work but it doesnt using this variable. How do i do this</p>
[ { "answer_id": 74304638, "author": "Ivo", "author_id": 1514861, "author_profile": "https://Stackoverflow.com/users/1514861", "pm_score": 1, "selected": false, "text": "RN = 13\n" }, { "answer_id": 74305701, "author": "Ramon0", "author_id": 2805176, "author_profile": "https://Stackoverflow.com/users/2805176", "pm_score": 1, "selected": true, "text": " if tonumber(v[1]) == RN then ------ here\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408612/" ]
74,304,506
<p>I am working on an '<strong>IP address tracker</strong>' project and everything is working fine. My question is how can I reduce that <code>useState()</code> to behave like it should or can I set it as an object?</p> <p>Currently I am using that method:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function App() { const [trakerData, setTrakerData] = useState({ ipAddress: "", location: "", timezone: "", isp: "", latitude: "", longitude: "", }); const url = `${BASE_URL}apiKey=${process.env.REACT_APP_API_KEY}&amp;ipAddress=${ipAddress}`; useEffect(() =&gt; { const getData = async () =&gt; { axios.get(url).then((respone) =&gt; { setTrakerData({ ...trakerData, ipAddress: respone.data.ip, location: respone.data.location.region, timezone: respone.data.location.timezone, isp: respone.data.isp, latitude: respone.data.location.lat, longitude: respone.data.location.lng, }); }); }; getData(); }, [url]); return ( &lt;div className="App"&gt; &lt;SearchSection ipAddress={ipAddress} location={location} timezone={timezone} isp={isp} setIpAddress={setIpAddress} /&gt; &lt;MapSection latitude={latitude} longitude={longitude} /&gt; &lt;/div&gt; ); } export default App;</code></pre> </div> </div> </p>
[ { "answer_id": 74304735, "author": "todevv", "author_id": 19099618, "author_profile": "https://Stackoverflow.com/users/19099618", "pm_score": 3, "selected": true, "text": "const [trakerData, setTrakerData] = useState({ \n ipAddress: '',\n location: '',\n // the rest values\n\n})\n" }, { "answer_id": 74304869, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": " const [options, setOptions] = useState({\n ipAddress: \"\",\n location: \"\",\n timezone: \"\",\n isp: \"\",\n latitude: \"\",\n longitude: \"\",\n });\n\n\n const changeFunction = useCallback((e, property) => {\n e.preventDefault();\n setOptions({...options, [property]: e.target.value})\n }, []);\n\n <input\n value={options.timezone}\n onChange={e => changeFunction(e, 'timezone')}\n />\n" }, { "answer_id": 74305088, "author": "Erick Willian", "author_id": 15429697, "author_profile": "https://Stackoverflow.com/users/15429697", "pm_score": 1, "selected": false, "text": " const [latitude, setLatitude] = useState(\"\");\n const [longitude, setLongitude] = useState(\"\");\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19358225/" ]
74,304,554
<p>I would like to create a multivariate function that takes the max value of 2 functions and then to plot it. However by using the max function there is an error when applying the function on the meshgrid. I have tried this on other multivariate function without the max function and it worked.</p> <pre><code>import numpy as np import pandas as pd import plotly.graph_objects as go def f(x,y): return max(np.cos(x),np.sin(y)) x=np.linspace(0,5,20) y=np.linspace(-3,2,20) X, Y = np.meshgrid(x, y) Z=f(X,Y) fig = go.Figure(data=[go.Surface(x=X, y=Y, z=Z)]) fig.show() </code></pre> <p>The error I get is : <code>The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</code>. However, I don't think that the suggestion is adapted to my case. I also tried by defining the max function with if statement but as I expected I get the same error. Does anyone could help?</p>
[ { "answer_id": 74304735, "author": "todevv", "author_id": 19099618, "author_profile": "https://Stackoverflow.com/users/19099618", "pm_score": 3, "selected": true, "text": "const [trakerData, setTrakerData] = useState({ \n ipAddress: '',\n location: '',\n // the rest values\n\n})\n" }, { "answer_id": 74304869, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": " const [options, setOptions] = useState({\n ipAddress: \"\",\n location: \"\",\n timezone: \"\",\n isp: \"\",\n latitude: \"\",\n longitude: \"\",\n });\n\n\n const changeFunction = useCallback((e, property) => {\n e.preventDefault();\n setOptions({...options, [property]: e.target.value})\n }, []);\n\n <input\n value={options.timezone}\n onChange={e => changeFunction(e, 'timezone')}\n />\n" }, { "answer_id": 74305088, "author": "Erick Willian", "author_id": 15429697, "author_profile": "https://Stackoverflow.com/users/15429697", "pm_score": 1, "selected": false, "text": " const [latitude, setLatitude] = useState(\"\");\n const [longitude, setLongitude] = useState(\"\");\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304554", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19982944/" ]
74,304,562
<p>In Postgres I need to sort text with natural order, but with one exception - if the string has only number, it should be placed at top. So I need such order:</p> <pre><code>[&quot;98&quot;, &quot;125&quot;, &quot;134&quot;, &quot;148&quot;, &quot;265&quot;, &quot;634&quot;, &quot;1233&quot;, &quot;5231&quot;, &quot;1m1ds&quot;, &quot;1m2&quot;, &quot;1m3&quot;, &quot;1n3&quot;, &quot;1w3r&quot;, &quot;2m3&quot;, &quot;2n3ds&quot;, &quot;9t6&quot;,&quot;12gh&quot;, &quot;13jy&quot;,&quot;25hg&quot;, &quot;123y&quot;, &quot;des2&quot;, &quot;nme&quot;, &quot;wer5&quot;] </code></pre> <p>I tried with this:</p> <pre class="lang-sql prettyprint-override"><code>CREATE COLLATION IF NOT EXISTS numeric (provider = icu, locale = 'en@colNumeric=yes'); ALTER TABLE &quot;baggage_belts&quot; ALTER COLUMN &quot;name&quot; type TEXT COLLATE numeric; </code></pre> <p>and it is ok, but numbers are mixed into numbers+text:</p> <pre><code>[1m1ds, 1m2, 1m3, 1n3, 1w3r, 2m3, 2n3ds, 9t6, 12gh, 13jy, 25hg, 98, 123y, 125, 134, 148, 265, 634, 1233, 5231, des2, nme, wer5] </code></pre> <p>Anyone has knowledge is it possible make it works with &quot;empty&quot; numbers first?</p>
[ { "answer_id": 74304735, "author": "todevv", "author_id": 19099618, "author_profile": "https://Stackoverflow.com/users/19099618", "pm_score": 3, "selected": true, "text": "const [trakerData, setTrakerData] = useState({ \n ipAddress: '',\n location: '',\n // the rest values\n\n})\n" }, { "answer_id": 74304869, "author": "Gonzalo Cugiani", "author_id": 20149906, "author_profile": "https://Stackoverflow.com/users/20149906", "pm_score": 1, "selected": false, "text": " const [options, setOptions] = useState({\n ipAddress: \"\",\n location: \"\",\n timezone: \"\",\n isp: \"\",\n latitude: \"\",\n longitude: \"\",\n });\n\n\n const changeFunction = useCallback((e, property) => {\n e.preventDefault();\n setOptions({...options, [property]: e.target.value})\n }, []);\n\n <input\n value={options.timezone}\n onChange={e => changeFunction(e, 'timezone')}\n />\n" }, { "answer_id": 74305088, "author": "Erick Willian", "author_id": 15429697, "author_profile": "https://Stackoverflow.com/users/15429697", "pm_score": 1, "selected": false, "text": " const [latitude, setLatitude] = useState(\"\");\n const [longitude, setLongitude] = useState(\"\");\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2513797/" ]
74,304,570
<p>I'm trying to import Entity.py into Tower.py in the same directory, in order to instantiate the Entity class inside Tower.py. However, it keeps coming up with the same error.</p> <pre><code>folder |_ scripts |_ Tower.py |_ Entity.py |_ Main.py </code></pre> <p>Entity.py</p> <pre><code>class Entity: ... </code></pre> <p>Tower.py</p> <pre><code>import Entity </code></pre> <pre><code> File &quot;C:\...\scripts\Tower.py&quot;, line 3, in &lt;module&gt; import Entity ModuleNotFoundError: No module named 'Entity' </code></pre> <p>I'm confused as to why this is happening and what I'm doing wrong.</p>
[ { "answer_id": 74304618, "author": "KillerRebooted", "author_id": 18554284, "author_profile": "https://Stackoverflow.com/users/18554284", "pm_score": 0, "selected": false, "text": "folder\n Wrong X scripts\n | Tower.py\n | Entity.py\n |_ Main.py\n" }, { "answer_id": 74304711, "author": "Kris", "author_id": 995052, "author_profile": "https://Stackoverflow.com/users/995052", "pm_score": 2, "selected": true, "text": "Main.py" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408407/" ]
74,304,589
<p>In this exercise, I need to write a function that take input a string representing a filename. The file contains a list of integers, one integer per line. Function should return a tuple containing the smallest and largest numbers in the file.</p> <p>My code attempt below did pass the auto-grader, but it is ugly. Would like to ask if there is a more efficient way of solving this.</p> <pre><code>def find_range(filename): tu = () with open(filename, 'r') as file: m = max(file.readlines(), key=lambda x: int(x)) with open(filename, 'r') as file: s = min(file.readlines(), key=lambda y: int(y)) tu = int(s), int(m) return tu </code></pre>
[ { "answer_id": 74304741, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 0, "selected": false, "text": "itertools.tee" }, { "answer_id": 74305045, "author": "JustLearning", "author_id": 19962393, "author_profile": "https://Stackoverflow.com/users/19962393", "pm_score": 0, "selected": false, "text": "readlines()" }, { "answer_id": 74305046, "author": "tobias_k", "author_id": 1639625, "author_profile": "https://Stackoverflow.com/users/1639625", "pm_score": 1, "selected": false, "text": "file.readlines" }, { "answer_id": 74305079, "author": "cards", "author_id": 16462878, "author_profile": "https://Stackoverflow.com/users/16462878", "pm_score": 0, "selected": false, "text": "min" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11952763/" ]
74,304,601
<p>The code is supposed to take any string input and check if the word is an isogram (word that does not use repeating letters). But it doesn't actually do that sadly.</p> <pre><code># word input and defining variables word = list(str(input())) letter = 0 letters = len(word) x = 0 while letter &lt;= letters: # while loop to repeat once for each letter if word.count([letter]) &gt; 1: # checks if the letter is repeated more than once x += 1 letter += 1 # letter is raised by one so it moves onto the next place in the list else: letter += 1 # printing result if x == 0: print(&quot;true&quot;) else: print(&quot;false&quot;) </code></pre>
[ { "answer_id": 74304731, "author": "Robin Nicole", "author_id": 2197372, "author_profile": "https://Stackoverflow.com/users/2197372", "pm_score": -1, "selected": false, "text": "word = str(input())\nif len(set(word)) == len(word):\n print(\"true\")\nelse:\n print(\"false\")\n" }, { "answer_id": 74304740, "author": "JNevill", "author_id": 2221001, "author_profile": "https://Stackoverflow.com/users/2221001", "pm_score": 1, "selected": true, "text": "letter" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408647/" ]
74,304,627
<p>I have a form with a drop-down box. The user selects an option from the dropdown box and hits submit. On submit, a new page opens up with a new form. The option that was selected is not being transferred to the next page. My form code is:</p> <pre><code>&lt;form method=&quot;post&quot; action=&quot;hero_modify_form.php&quot;&gt; &lt;div&gt; &lt;label&gt;Select a hero to add or modify: &lt;/label&gt; &lt;select name=&quot;heroname&quot; type=&quot;input&quot;&gt; &lt;option&gt;&lt;/option&gt; &lt;?php foreach ($data as $row): ?&gt; &lt;option&gt; &lt;?php echo $row['Hero_Name'] ?&gt; &lt;/option&gt; &lt;?php endforeach ?&gt; &lt;/select&gt; &lt;/div&gt; &lt;div&gt; &lt;button type=&quot;submit&quot; name=&quot;heroname&quot;&gt;Submit&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>The next page loads and displays some test variables at the top, but the variable from the POST is empty. My code on the page is</p> <pre><code>&lt;?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); include('header.php'); $username = $_SESSION['username']; echo $_POST['heroname']; echo $username; $test1 = &quot;test 1, before the if statement&quot;; echo $test1; </code></pre> <p>I get no errors on the page. The username variable and the test1 variable echo normally. The heroname variable doesn't. I need help figuring out why the selection from the form is not transferring to the next page. Thanks in advance.</p>
[ { "answer_id": 74304715, "author": "Ramil Huseynov", "author_id": 6711823, "author_profile": "https://Stackoverflow.com/users/6711823", "pm_score": 1, "selected": false, "text": "value" }, { "answer_id": 74305433, "author": "mexslacker", "author_id": 13000645, "author_profile": "https://Stackoverflow.com/users/13000645", "pm_score": -1, "selected": false, "text": "<form method=\"post\" action=\"hero_modify_form.php\">\n \n <div>\n <label>Select a hero to add or modify: </label>\n <select name=\"heroname\">\n <option></option>\n <?php foreach ($data as $row): ?>\n <option value=\"<?php echo $row['Hero_Name'] ?>\">\n <?php echo $row['Hero_Name'] ?>\n </option>\n <?php endforeach ?>\n </select>\n </div>\n <div>\n <button type=\"submit\">Submit</button>\n </div>\n </form>\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20334921/" ]
74,304,649
<p>I want to edit a file using Notepad++, in such a way that I can replace a line containing a specific word, For example :</p> <pre><code> edit 792 set name &quot;XXXXX&quot; set action accept next edit 957 set name &quot;YYYYY&quot; set action accept next edit 021 set name &quot;ZZZZZ&quot; set action accept next </code></pre> <p><strong>I want to change it to :</strong></p> <pre><code> edit 0 set name &quot;XXXXX&quot; set action accept next edit 0 set name &quot;YYYYY&quot; set action accept next edit 0 set name &quot;ZZZZZ&quot; set action accept next </code></pre> <p>I would like to replace the &quot;edit 792 or edit 957 or edit 021&quot; and change it to &quot;edit 0&quot;</p> <p>Do any ideas on how this can be done using Notepad++?</p> <p>Thanks everybody.</p> <p>Hopefully, I can get suggestions for solving this issue.</p>
[ { "answer_id": 74304715, "author": "Ramil Huseynov", "author_id": 6711823, "author_profile": "https://Stackoverflow.com/users/6711823", "pm_score": 1, "selected": false, "text": "value" }, { "answer_id": 74305433, "author": "mexslacker", "author_id": 13000645, "author_profile": "https://Stackoverflow.com/users/13000645", "pm_score": -1, "selected": false, "text": "<form method=\"post\" action=\"hero_modify_form.php\">\n \n <div>\n <label>Select a hero to add or modify: </label>\n <select name=\"heroname\">\n <option></option>\n <?php foreach ($data as $row): ?>\n <option value=\"<?php echo $row['Hero_Name'] ?>\">\n <?php echo $row['Hero_Name'] ?>\n </option>\n <?php endforeach ?>\n </select>\n </div>\n <div>\n <button type=\"submit\">Submit</button>\n </div>\n </form>\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408614/" ]
74,304,657
<p>Can you please help me with the following. I have the following pandas df:</p> <pre><code> FB AMZN AAPL NFLX GOOG date 2004-01-01 10 4 1 7 0 2004-02-01 4 0 0 0 23 2004-03-01 6 0 0 0 34 2004-04-01 0 0 0 0 0 2004-05-01 0 0 0 0 0 </code></pre> <p>Instead of the columns as in the above df, I want to have three columns: Companym, date and Score, Particularly, how can I make the pd DF in the following template:</p> <pre><code>Company date Score FB 01.01.2004 10 FB 01.02.2004 4 FB 01.03.2004 6 FB 01.04.2004 0 FB 01.05.2004 0 AMZN 01.01.2004 4 AMZN 01.02.2004 0 AMZN 01.03.2004 0 AMZN 01.04.2004 0 AMZN 01.05.2004 0 AAPL 01.01.2004 1 AAPL 01.02.2004 0 AAPL 01.03.2004 0 AAPL 01.04.2004 0 AAPL 01.05.2004 0 NFLX 01.01.2004 7 NFLX 01.02.2004 0 NFLX 01.03.2004 0 NFLX 01.04.2004 0 NFLX 01.05.2004 0 GOOG 01.01.2004 0 GOOG 01.02.2004 23 GOOG 01.03.2004 34 GOOG 01.04.2004 0 GOOG 01.05.2004 0 </code></pre>
[ { "answer_id": 74304718, "author": "It_is_Chris", "author_id": 9177877, "author_profile": "https://Stackoverflow.com/users/9177877", "pm_score": 2, "selected": true, "text": "new = df.unstack().reset_index()\nnew.columns = ['Company', 'Date', 'Score']\n\n Company Date Score\n0 FB 2004-01-01 10\n1 FB 2004-02-01 4\n2 FB 2004-03-01 6\n3 FB 2004-04-01 0\n4 FB 2004-05-01 0\n5 AMZN 2004-01-01 4\n6 AMZN 2004-02-01 0\n7 AMZN 2004-03-01 0\n8 AMZN 2004-04-01 0\n9 AMZN 2004-05-01 0\n10 AAPL 2004-01-01 1\n11 AAPL 2004-02-01 0\n12 AAPL 2004-03-01 0\n13 AAPL 2004-04-01 0\n14 AAPL 2004-05-01 0\n15 NFLX 2004-01-01 7\n16 NFLX 2004-02-01 0\n17 NFLX 2004-03-01 0\n18 NFLX 2004-04-01 0\n19 NFLX 2004-05-01 0\n20 GOOG 2004-01-01 0\n21 GOOG 2004-02-01 23\n22 GOOG 2004-03-01 34\n23 GOOG 2004-04-01 0\n24 GOOG 2004-05-01 0\n" }, { "answer_id": 74304736, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": false, "text": "#melt the dataframe\ndf=df.melt( var_name='Company', value_name='Score', ignore_index=False)\n\n# reformat the date\ndf.index=pd.to_datetime(df.index).strftime('%d.%m.%Y')\ndf\n\n" }, { "answer_id": 74304805, "author": "eshirvana", "author_id": 1367454, "author_profile": "https://Stackoverflow.com/users/1367454", "pm_score": 0, "selected": false, "text": "melt" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8260088/" ]
74,304,669
<p>I need to change white space to a character, but only if there are two or more white spaces and there is only one I want to keep it.</p> <p>An example of text is:<br /> <code>142526 0x8520003 2 2022-10-20 The interface status changes. (ifName=Gig.</code></p> <p>I need:<br /> <code>142526;0x8520003;2;2022-10-20 The interface status changes. (ifName=Gig.</code></p> <p>I use:</p> <pre><code>';'.join(headers.split()) </code></pre> <p>but change one space white also. Thanks!!</p>
[ { "answer_id": 74304812, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 3, "selected": true, "text": "re.split()" }, { "answer_id": 74304813, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 1, "selected": false, "text": "maxsplit=" }, { "answer_id": 74304942, "author": "bobble bubble", "author_id": 5527985, "author_profile": "https://Stackoverflow.com/users/5527985", "pm_score": 1, "selected": false, "text": "re.sub" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20390958/" ]
74,304,675
<p>Let's assume I have an array of nested hash like this one :</p> <pre><code>array = [ { &quot;id&quot;: 8444, &quot;version&quot;: &quot;2.1.0&quot;, &quot;data&quot;: { &quot;data1&quot;: { &quot;data1-1&quot;: { &quot;a&quot;: 132.6, &quot;b&quot;: 128.36, &quot;c&quot;: 153.59, &quot;d&quot;: 136.48 } }, &quot;data2&quot;: { &quot;data2-1&quot;: { &quot;a&quot;: 1283.0, &quot;b&quot;: 1254.0, &quot;c&quot;: 1288.5, &quot;d&quot;: 1329.0 } } } }, { &quot;id&quot;: 8443, &quot;version&quot;: &quot;2.1.0&quot;, &quot;data&quot;: { &quot;data1&quot;: { &quot;data1-1&quot;: { &quot;a&quot;: 32.6, &quot;b&quot;: 28.36, &quot;c&quot;: 53.59, &quot;d&quot;: 36.48 } }, &quot;data2&quot;: { &quot;data2-1&quot;: { &quot;a&quot;: 283.0, &quot;b&quot;: 254.0, &quot;c&quot;: 288.5, &quot;d&quot;: 329.0 } } } }, { &quot;id&quot;: 8442, &quot;version&quot;: &quot;2.1.0&quot;, &quot;data&quot;: { &quot;data1&quot;: { &quot;data1-1&quot;: { &quot;a&quot;: 32.6, &quot;b&quot;: 28.36, &quot;c&quot;: 53.59, &quot;d&quot;: 36.48 } }, &quot;data2&quot;: { &quot;data2-1&quot;: { &quot;a&quot;: 283.0, &quot;b&quot;: 254.0, &quot;c&quot;: 288.5, &quot;d&quot;: 329.0 } } } } ] </code></pre> <p>Each hash of the array has the same map structure.</p> <p>I would like to create a new hash with the same hash map structure than <code>data</code> and for each values of <code>a, b, c, d</code> to have the average.</p> <p>What is the best approach for this ? Because I cannot <code>group_by</code> key since I have the same key in different subkey (<code>data1-1</code> and <code>data2-1</code>)</p> <p>The result would then be :</p> <pre><code>{ &quot;data1&quot;: { &quot;data1-1&quot;: { &quot;a&quot;: 65.9, &quot;b&quot;: 61.7, &quot;c&quot;: 86.9, &quot;d&quot;: 69.8 } }, &quot;data2&quot;: { &quot;data2-1&quot;: { &quot;a&quot;: 616.3, &quot;b&quot;: 587.3, &quot;c&quot;: 621.8, &quot;d&quot;: 662.3 } } } </code></pre> <p>I have tried this:</p> <pre><code>array.reduce({}) do |acc, hash| hash[:data].each do |k,v| acc[k] = v end end # =&gt; {:data1=&gt;{:&quot;data1-1&quot;=&gt;{:a=&gt;32.6, :b=&gt;28.36, :c=&gt;53.59, :d=&gt;36.48}}, # :data2=&gt;{:&quot;data2-1&quot;=&gt;{:a=&gt;283.0, :b=&gt;254.0, :c=&gt;288.5, :d=&gt;329.0}}} </code></pre>
[ { "answer_id": 74308600, "author": "Chris", "author_id": 15261315, "author_profile": "https://Stackoverflow.com/users/15261315", "pm_score": 3, "selected": true, "text": "grouped = array.each_with_object({}) do |h, acc| \n h[:data].each do |k, v| \n acc[k] ||= []\n acc[k] << v \n end\nend\n" }, { "answer_id": 74311325, "author": "Cary Swoveland", "author_id": 256970, "author_profile": "https://Stackoverflow.com/users/256970", "pm_score": 1, "selected": false, "text": "fac = 1.fdiv(array.size)\n #=> 0.3333333333333333\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1805275/" ]
74,304,683
<p>Hello I have the following problem</p> <p>Say I have a file <code>base.R</code></p> <pre><code>x &lt;- 1 # comment y &lt;- Y ~ X1 + X2 # comment 2 z &lt;- function(x) { x + 1 } t &lt;- z(x) </code></pre> <p>and another file <code>override.R</code></p> <pre><code>x &lt;- 2 y &lt;- Y ~ X1 + X3 </code></pre> <p>my goal would be to create another file <code>new.R</code> which is essentially <code>base.R</code> overriden by <code>override.R</code></p> <pre><code>x &lt;- 2 # comment y &lt;- Y ~ X1 + X3 # comment 2 z &lt;- function(x) { x + 1 } t &lt;- z(x) </code></pre> <p>Obviously if all expressions in <code>base.R</code> were 1 liners I would be able to use <code>sed</code> but unfortunately it's not the case. Note that I only need it to work for assignations <code>lhs &lt;- rhs</code> either if ideally <code>lhs = rhs</code> would work as well.</p> <p><strong>EDIT: the above is a minimization of my actual problem</strong></p>
[ { "answer_id": 74306097, "author": "r2evans - GO NAVY BEAT ARMY", "author_id": 3358272, "author_profile": "https://Stackoverflow.com/users/3358272", "pm_score": 2, "selected": false, "text": "base.R" }, { "answer_id": 74307541, "author": "G. Grothendieck", "author_id": 516548, "author_profile": "https://Stackoverflow.com/users/516548", "pm_score": 3, "selected": true, "text": "comments 2" }, { "answer_id": 74398026, "author": "jared_mamrot", "author_id": 12957340, "author_profile": "https://Stackoverflow.com/users/12957340", "pm_score": 0, "selected": false, "text": "sed" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1846968/" ]
74,304,688
<p>I've found a code in <a href="https://www.extendoffice.com/documents/outlook/7047-outlook-vba-get-sender-email-address.html" rel="nofollow noreferrer">this site</a> to get the e-mail addresses of a selected outlook e-mail and then export them as .txt file. However, it only gets the sender address. In my case, I'd need to get the e-mail addresses of the CC field as well</p> <p>Here's the code:</p> <pre><code>Sub GetSmtpAddressOfSelectionEmail() Dim xExplorer As Explorer Dim xSelection As Selection Dim xItem As Object Dim xMail As MailItem Dim xAddress As String Dim xFldObj As Object Dim FilePath As String Dim xFSO As Scripting.FileSystemObject On Error Resume Next Set xExplorer = Application.ActiveExplorer Set xSelection = xExplorer.Selection For Each xItem In xSelection If xItem.Class = olMail Then Set xMail = xItem xAddress = xAddress &amp; VBA.vbCrLf &amp; &quot; &quot; &amp; GetSmtpAddress(xMail) End If Next If MsgBox(&quot;Sender SMTP Address is: &quot; &amp; xAddress &amp; vbCrLf &amp; vbCrLf &amp; &quot;Do you want to export the address list to a txt file? &quot;, vbYesNo, &quot;Kutools for Outlook&quot;) = vbYes Then Set xFldObj = CreateObject(&quot;Shell.Application&quot;).BrowseforFolder(0, &quot;Select a Folder&quot;, 0, 16) Set xFSO = New Scripting.FileSystemObject If xFldObj Is Nothing Then Exit Sub FilePath = xFldObj.Items.Item.Path &amp; &quot;\Address.txt&quot; Close #1 Open FilePath For Output As #1 Print #1, &quot;Sender SMTP Address is: &quot; &amp; xAddress Close #1 Set xFSO = Nothing Set xFldObj = Nothing MsgBox &quot;Address list has been exported to:&quot; &amp; FilePath, vbOKOnly + vbInformation, &quot;Kutools for Outlook&quot; End If End Sub Function GetSmtpAddress(Mail As MailItem) Dim xNameSpace As Outlook.NameSpace Dim xEntryID As String Dim xAddressEntry As AddressEntry Dim PR_SENT_REPRESENTING_ENTRYID As String Dim PR_SMTP_ADDRESS As String Dim xExchangeUser As exchangeUser On Error Resume Next GetSmtpAddress = &quot;&quot; Set xNameSpace = Application.Session If Mail.sender.Type &lt;&gt; &quot;EX&quot; Then GetSmtpAddress = Mail.sender.Address Else PR_SENT_REPRESENTING_ENTRYID = &quot;http://schemas.microsoft.com/mapi/proptag/0x00410102&quot; xEntryID = Mail.PropertyAccessor.BinaryToString(Mail.PropertyAccessor.GetProperty(PR_SENT_REPRESENTING_ENTRYID)) Set xAddressEntry = xNameSpace.GetAddressEntryFromID(xEntryID) If xAddressEntry Is Nothing Then Exit Function If xAddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Or xAddressEntry.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then Set xExchangeUser = xAddressEntry.GetExchangeUser() If xExchangeUser Is Nothing Then Exit Function GetSmtpAddress = xExchangeUser.PrimarySmtpAddress Else PR_SMTP_ADDRESS = &quot;http://schemas.microsoft.com/mapi/proptag/0x39FE001E&quot; GetSmtpAddress = xAddressEntry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) End If End If End Function </code></pre> <p>So, how could I adapt the code to include the e-mail addresses from the CC field as well?</p> <p>Thanks in advance!</p> <p>I've tried setting Recipients but couldn't get the desired outcome</p>
[ { "answer_id": 74305614, "author": "Dmitry Streblechenko", "author_id": 332059, "author_profile": "https://Stackoverflow.com/users/332059", "pm_score": 0, "selected": false, "text": "MailItem.Recipients" }, { "answer_id": 74310064, "author": "Eugene Astafiev", "author_id": 1603351, "author_profile": "https://Stackoverflow.com/users/1603351", "pm_score": 1, "selected": false, "text": "GetSmtpAddress" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19444677/" ]
74,304,690
<p>I have a nested dictionary:</p> <pre><code>some_dictionary = { &quot;sub_dict1&quot;: { &quot;miles&quot;: &quot;5,024,279&quot; }, &quot;sub_dict2&quot;: { &quot;miles&quot;: &quot;733,391&quot; }, &quot;sub_dict3&quot;: { &quot;miles&quot;: &quot;7,151,502&quot; } } </code></pre> <p>I need to sort some_dictionary by the numerical values of miles so when I display it should be something like this:</p> <pre><code>&quot;sub_dict2&quot;: {&quot;miles&quot;: &quot;733,391&quot;}, &quot;sub_dict1&quot;: {&quot;miles&quot;: &quot;5,024,279&quot;}, &quot;sub_dict3&quot;: {&quot;miles&quot;: &quot;7,151,502&quot;} </code></pre> <p>My most recent attempt was:</p> <pre><code>top = OrderedDict(sorted(some_dictionary.items(), key=lambda x: (x[1], &quot;miles&quot;.replace(',', ''))) print(top) </code></pre> <p>This resulted in a TypeError. I'm pretty lost here, and any help would be appreciated.</p>
[ { "answer_id": 74305614, "author": "Dmitry Streblechenko", "author_id": 332059, "author_profile": "https://Stackoverflow.com/users/332059", "pm_score": 0, "selected": false, "text": "MailItem.Recipients" }, { "answer_id": 74310064, "author": "Eugene Astafiev", "author_id": 1603351, "author_profile": "https://Stackoverflow.com/users/1603351", "pm_score": 1, "selected": false, "text": "GetSmtpAddress" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19449071/" ]
74,304,744
<p>in a class I have 3 private methods (two voids and one that returns an id).. depending on a boolean variable I need to call this methods in a specific order.</p> <p>I can simply do:</p> <pre><code>if(booleanIstrue){ var id = method1(); method2(); method3(); } else { method2(); method3(); id = method1(); } </code></pre> <p>but is there is a better way to do this ?</p>
[ { "answer_id": 74305614, "author": "Dmitry Streblechenko", "author_id": 332059, "author_profile": "https://Stackoverflow.com/users/332059", "pm_score": 0, "selected": false, "text": "MailItem.Recipients" }, { "answer_id": 74310064, "author": "Eugene Astafiev", "author_id": 1603351, "author_profile": "https://Stackoverflow.com/users/1603351", "pm_score": 1, "selected": false, "text": "GetSmtpAddress" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304744", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12394751/" ]
74,304,747
<p>I have an express node js server, which listens to localhost at port 3000, and prints the JSON content. If I use postman, it prints the JSON properly.</p> <pre><code>var express = require('express'); var bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()) var port = 3000; app.post('/instance', function(req, res) { const obj = JSON.parse(JSON.stringify(req.body)) console.log(obj); //res.send(req.body); }); // start the server app.listen(port); console.log('Server started! At http://localhost:' + port); </code></pre> <p>In angular html, i have an ngFor that sends a list item when a button is clicked.</p> <pre><code>&lt;ng-container *ngFor=&quot;let instance of instancesList&quot;&gt; &lt;tr class=&quot;col-sm border border-primary&quot; style=&quot;color:#111111&quot;&gt; &lt;td&gt;{{instance.id}}&lt;/td&gt; &lt;td&gt;{{instance.name}}&lt;/td&gt; &lt;td&gt;{{instance.zone}}&lt;/td&gt; &lt;td&gt;{{instance.ip}}&lt;/td&gt; &lt;td&gt; &lt;button (click)=&quot;onClick(instance)&quot; type=&quot;button&quot; class=&quot;btn border-primary btn-lg&quot;&gt;test&lt;/button&gt;&lt;/td&gt; &lt;/ng-container&gt; </code></pre> <p>At this point, when the button is clicked, I want a JSON with the item data to be sent to the server, and just be printed. It does not happen, the server doesn't print the json content, but it prints the content if sent from postman.</p> <p>i've been strugling for a few days now, I appreciate any help.</p> <pre><code> const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', }) }; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) @Injectable({providedIn:'root'}) export class AppComponent{ instancesList = instances; baseUrl = &quot;http://localhost:3000/instance&quot; constructor(private http: HttpClient) { } onClick(instance: Instance) : Observable&lt;Instance&gt;{ const json = JSON.stringify(instance) return this.http.post&lt;Instance&gt;(this.baseUrl, json, httpOptions) // prints the json on the webpage just for testing alert(JSON.stringify(instance)); } } </code></pre> <p>I tried searching stackoverflow and try different methods, none helped.</p>
[ { "answer_id": 74305614, "author": "Dmitry Streblechenko", "author_id": 332059, "author_profile": "https://Stackoverflow.com/users/332059", "pm_score": 0, "selected": false, "text": "MailItem.Recipients" }, { "answer_id": 74310064, "author": "Eugene Astafiev", "author_id": 1603351, "author_profile": "https://Stackoverflow.com/users/1603351", "pm_score": 1, "selected": false, "text": "GetSmtpAddress" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408701/" ]
74,304,765
<p>I am a beginner in postgresql and databases in general. I have a table with a column product_id. Some of the values in that column are null. I need to change those null values to the values from another table.</p> <p>I want to do something like this:</p> <pre><code>insert into a(product_id) (select product_id from b where product_name='foo') where product_id = null; </code></pre> <p>I realize that this syntax doesn't work but I just need help figuring it out.</p>
[ { "answer_id": 74304863, "author": "SwAn", "author_id": 6357309, "author_profile": "https://Stackoverflow.com/users/6357309", "pm_score": 0, "selected": false, "text": "INSERT INTO a (product_id)\nselect product_id from b where product_name='foo';\n" }, { "answer_id": 74305090, "author": "itsmarwen", "author_id": 7447410, "author_profile": "https://Stackoverflow.com/users/7447410", "pm_score": 1, "selected": false, "text": "Update a\nset product_id = select product_id from b where b.product_name = 'foo' \nWhere product_id is null\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/203952/" ]
74,304,774
<p>I'm trying to get the second latest full hour. So if the time is 15:30 now, I'm trying to get 14:00, so I basically need to truncate the current minutes and then furthermore truncate an hour..</p> <p>I'm trying to project the date like this:</p> <pre><code>// Let's say the current time is 15:46 &quot;period&quot;: { &quot;start&quot;: 2022-11-03T14:00:00.000, &quot;end&quot;: 2022-11-03T15:00:00.000 } </code></pre> <p>It's gonna be something like this:</p> <pre><code>{ $project: { period: { start: { &quot;$subtract&quot;: [ { $hour: { &quot;$toDate&quot;: &quot;$$NOW&quot; } }, 1 ] }, end: { &quot;$subtract&quot;: [ { $hour: { &quot;$toDate&quot;: &quot;$$NOW&quot; } }, 1 ] }, </code></pre> <p>} }</p> <p>How do I do that?</p>
[ { "answer_id": 74304989, "author": "wardialer", "author_id": 2463455, "author_profile": "https://Stackoverflow.com/users/2463455", "pm_score": 0, "selected": false, "text": "db.collection.aggregate([\n {\n \"$project\": {\n hour: {\n \"$subtract\": [\n {\n $hour: {\n \"$toDate\": \"$period.start\"\n }\n },\n 1\n ]\n }\n }\n },\n \n])\n" }, { "answer_id": 74305153, "author": "Wernfried Domscheit", "author_id": 3027266, "author_profile": "https://Stackoverflow.com/users/3027266", "pm_score": 2, "selected": true, "text": "db.collection.aggregate([\n {\n \"$project\": {\n start: {\n $dateSubtract: {\n startDate: { $dateTrunc: { date: \"$$NOW\", unit: \"hour\" } },\n unit: \"hour\",\n amount: 1\n }\n },\n end: { $dateTrunc: { date: \"$$NOW\", unit: \"hour\" } }\n }\n])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15989592/" ]
74,304,797
<p>I have this function <code>setValue(binaryString)</code> that takes inputs binary string &quot;<code>binaryString</code>&quot; and returns the set of positions between 0 and len(binaryString)-1 whose corresponding entry in binaryString is '1'.</p> <p>so for example:</p> <p><code>binaryString = 10101</code> will return set <code>{0, 2, 4}</code>. the returned set indicates the position of number '1' ini binaryString</p> <p>The final result is will be put together in dictionary D={}, with binaryString as key and stringToSet(binaryString) as value.</p> <p>So far I have tried this code:</p> <pre><code>def setValue(binaryString): values = set() for pos,char in enumerate(binaryString): if(char == '1'): values.add(pos) print(values) def main(): D = {} keys = [] while True: binaryString = input(str(&quot;Input Binary String: &quot;)) if binaryString == &quot;exit&quot;: break else: keys.append(binaryString) print(keys) for i in keys: setValue(i) if __name__ == &quot;__main__&quot;: main() </code></pre> <p>my code resulted in:</p> <pre><code>Input Binary String: 10101 Input Binary String: 110011 Input Binary String: exit ['10101', '110011'] {0, 2, 4} {0, 1, 4, 5} </code></pre> <p>while I wish to get result like this:</p> <pre><code>Input Binary String: 10101 Input Binary String: 0 Input Binary String: 1 Input Binary String: 1111 Input Binary String: exit 10101: {0, 2, 4} 0: set() 1: {0} 1111: {0, 1, 2, 3} </code></pre> <p>I don't know how to fetch the key from <code>binaryString</code> and value from <code>setValue(binaryString)</code> and put them in dictionary <code>D{}</code></p> <p>Thanks in advance</p>
[ { "answer_id": 74304915, "author": "Jon Kiparsky", "author_id": 405303, "author_profile": "https://Stackoverflow.com/users/405303", "pm_score": 0, "selected": false, "text": "dict" }, { "answer_id": 74304922, "author": "Mortz", "author_id": 4248842, "author_profile": "https://Stackoverflow.com/users/4248842", "pm_score": 0, "selected": false, "text": "values" }, { "answer_id": 74304930, "author": "Gábor Fekete", "author_id": 6464041, "author_profile": "https://Stackoverflow.com/users/6464041", "pm_score": 0, "selected": false, "text": "import itertools\n\ninputs = [10101, 0, 1, 1111]\nmapping = dict()\nfor i in inputs:\n s = str(i)\n indices = range(len(s))\n selectors = map(int,list(s))\n c = itertools.compress(indices,selectors)\n mapping[i] = set(c)\n\nfor k,v in mapping.items():\n print(k,v)\n" }, { "answer_id": 74305107, "author": "Cobra", "author_id": 17580381, "author_profile": "https://Stackoverflow.com/users/17580381", "pm_score": 1, "selected": false, "text": "def one_index(s):\n return {i for i, e in enumerate(s) if e == '1'}\n\nexamples = '0', '1', '110011', '10101'\n\nresult = {bs: one_index(bs) for bs in examples}\n\nprint(result)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408785/" ]
74,304,798
<p>In the following case:</p> <pre><code>CREATE TABLE Persons ( groupId int, age int, Person varchar(255) ); insert into Persons (Person, groupId, age) values('Bob' , 1 , 32); insert into Persons (Person, groupId, age) values('Jill' , 1 , 34); insert into Persons (Person, groupId, age)values('Shawn' , 1 , 42); insert into Persons (Person, groupId, age) values('Shawn' , 1 , 42); insert into Persons (Person, groupId, age) values('Jake' , 2 , 29); insert into Persons (Person, groupId, age) values('Paul' , 2 , 36); insert into Persons (Person, groupId, age) values('Laura' , 2 , 39); </code></pre> <p>The following query:</p> <pre><code>SELECT * FROM `Persons` o LEFT JOIN `Persons` b ON o.groupId = b.groupId AND o.age &lt; b.age </code></pre> <p>returns (executed in <a href="http://sqlfiddle.com/#!9/cae8023/5" rel="nofollow noreferrer">http://sqlfiddle.com/#!9/cae8023/5</a>):</p> <pre><code>1 32 Bob 1 34 Jill 1 32 Bob 1 42 Shawn 1 34 Jill 1 42 Shawn 1 32 Bob 1 42 Shawn 1 34 Jill 1 42 Shawn 1 42 Shawn (null) (null) (null) 1 42 Shawn (null) (null) (null) 2 29 Jake 2 36 Paul 2 29 Jake 2 39 Laura 2 36 Paul 2 39 Laura 2 39 Laura (null) (null) (null). </code></pre> <p>I don't understand the result.<br /> I was expecting</p> <pre><code>1 32 Bob 1 34 Jill 1 32 Bob 1 42 Shawn 1 34 Jill 1 42 Shawn 1 42 Shawn (null) (null) (null) 2 29 Jake 2 36 Paul 2 29 Jake 2 39 Laura 2 39 Laura (null) (null) (null) </code></pre> <p>Reason I was expecting that is that in my understanding the left join picks each row from the left table, tries to match it each row of the right table and if there is a match it adds the row. If there is no match in the condition it adds the left row with null values for the right columns.<br /> So if that is correct why in the fiddle output we have after <code>1 34 Jill 1 42 Shawn</code> rows for Bob and Jill repeated?</p>
[ { "answer_id": 74304883, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 1, "selected": false, "text": "o.age < b.age" }, { "answer_id": 74305823, "author": "Ehab", "author_id": 20342736, "author_profile": "https://Stackoverflow.com/users/20342736", "pm_score": 0, "selected": false, "text": "CREATE TABLE Persons (\n groupId int,\n age int,\n Person varchar(255)\n);\n\ninsert into Persons (Person, groupId, age) values('Bob' , 1 , 32);\ninsert into Persons (Person, groupId, age) values('Jill' , 1 , 34);\ninsert into Persons (Person, groupId, age)values('Shawn' , 1 , 42);\ninsert into Persons (Person, groupId, age) values('Jake' , 2 , 29);\ninsert into Persons (Person, groupId, age) values('Paul' , 2 , 36);\ninsert into Persons (Person, groupId, age) values('Laura' , 2 , 39);\n\nSELECT *\nFROM `Persons` o \n LEFT JOIN `Persons` b \n ON o.groupId = b.groupId AND o.age < b.age\n;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9055634/" ]
74,304,828
<p>Is it possible to remove rows if the values in the <code>Block</code> column occurs at least twice which has different values in the <code>ID</code> column?</p> <p>My data looks like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>Block</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>A</td> </tr> <tr> <td>1</td> <td>C</td> </tr> <tr> <td>1</td> <td>C</td> </tr> <tr> <td>3</td> <td>A</td> </tr> <tr> <td>3</td> <td>B</td> </tr> </tbody> </table> </div> <p>In the above case, the value <code>A</code> in the <code>Block</code> column occurs twice, which has values 1 and 3 in the <code>ID</code> column. So the rows are removed.</p> <p>The expected output should be:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>Block</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>C</td> </tr> <tr> <td>1</td> <td>C</td> </tr> <tr> <td>3</td> <td>B</td> </tr> </tbody> </table> </div> <p>I tried to use the <code>dropDuplicates</code> after the <code>groupBy</code>, but I don't know how to filter with this type of condition. It appears that I would need a <code>set</code> for the <code>Block</code> column to check with the <code>ID</code> column.</p>
[ { "answer_id": 74308887, "author": "ZygD", "author_id": 2753501, "author_profile": "https://Stackoverflow.com/users/2753501", "pm_score": 2, "selected": true, "text": "lag" }, { "answer_id": 74312662, "author": "wwnde", "author_id": 8986975, "author_profile": "https://Stackoverflow.com/users/8986975", "pm_score": 0, "selected": false, "text": "(df.withColumn('index', row_number().over(Window.partitionBy().orderBy('ID','Block')))#create an index to reorder after comps\n .withColumn('BlockRank', rank().over(Window.partitionBy('Block').orderBy('ID'))).orderBy('index')#Rank per Block\n .where(col('BlockRank')==1)\n .drop('index','BlockRank')\n).show()\n\n+---+-----+\n| ID|Block|\n+---+-----+\n| 1| A|\n| 1| C|\n| 1| C|\n| 3| B|\n+---+-----+\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8529798/" ]
74,304,884
<p>I am saving some images which created &amp; upload by Summernote Editor in my Laravel application and it getting saved properly. But when I want to edit the content, sometimes I am getting the content from DB and load it into Summernote Editor.</p> <p>But Most of the cases, the page loading &amp; loading ..... And The content not loads. Sometimes loads properly, but see the string as the attached image below.</p> <p><a href="https://i.stack.imgur.com/9x5SI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9x5SI.jpg" alt="enter image description here" /></a></p> <pre><code> &lt;textarea name=&quot;long_desc&quot; class=&quot;form-control&quot; id=&quot;summernote&quot; rows=&quot;20&quot;&gt;{{ $portfolio_data-&gt;long_desc}}&lt;/textarea&gt; </code></pre> <p>How to solve this error!!</p>
[ { "answer_id": 74308887, "author": "ZygD", "author_id": 2753501, "author_profile": "https://Stackoverflow.com/users/2753501", "pm_score": 2, "selected": true, "text": "lag" }, { "answer_id": 74312662, "author": "wwnde", "author_id": 8986975, "author_profile": "https://Stackoverflow.com/users/8986975", "pm_score": 0, "selected": false, "text": "(df.withColumn('index', row_number().over(Window.partitionBy().orderBy('ID','Block')))#create an index to reorder after comps\n .withColumn('BlockRank', rank().over(Window.partitionBy('Block').orderBy('ID'))).orderBy('index')#Rank per Block\n .where(col('BlockRank')==1)\n .drop('index','BlockRank')\n).show()\n\n+---+-----+\n| ID|Block|\n+---+-----+\n| 1| A|\n| 1| C|\n| 1| C|\n| 3| B|\n+---+-----+\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13127640/" ]
74,304,895
<p>I have the following proto message</p> <pre><code>message ListGamesResponse{ repeated Game games =1; string nextCursor =2; string previousCursor =3; } </code></pre> <p>So I have an entity for Game for example. But here I run into a scenatio where I also have cursors. Does this mean that I should make models and entities for responses and requests? In some implementations of this architecture that I used for reference I don't see responses or requests in the domain layer.</p> <p>How can I avoid having request and response entities in the domain layer? But still pass on the cursors?</p>
[ { "answer_id": 74308887, "author": "ZygD", "author_id": 2753501, "author_profile": "https://Stackoverflow.com/users/2753501", "pm_score": 2, "selected": true, "text": "lag" }, { "answer_id": 74312662, "author": "wwnde", "author_id": 8986975, "author_profile": "https://Stackoverflow.com/users/8986975", "pm_score": 0, "selected": false, "text": "(df.withColumn('index', row_number().over(Window.partitionBy().orderBy('ID','Block')))#create an index to reorder after comps\n .withColumn('BlockRank', rank().over(Window.partitionBy('Block').orderBy('ID'))).orderBy('index')#Rank per Block\n .where(col('BlockRank')==1)\n .drop('index','BlockRank')\n).show()\n\n+---+-----+\n| ID|Block|\n+---+-----+\n| 1| A|\n| 1| C|\n| 1| C|\n| 3| B|\n+---+-----+\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304895", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4214922/" ]
74,304,917
<p>I'm having trouble trying to find the parameters of a gaussian curve fit.</p> <p>The site <a href="https://mycurvefit.com/" rel="nofollow noreferrer">https://mycurvefit.com/</a> provides a good answer fairly quickly. However, my implementation with python's curve_fit(), from the scipy.optimize library, is not providing good results (even when inputting the answers).</p> <p>For instance, the equation I'm trying to fit is the following:</p> <pre><code>def gauss_func(x, a, b, c): return a * np.exp(-(x-b)**2/(2*c**2)) </code></pre> <p>With input points:</p> <pre><code>x_main = np.array([19.748, 39.611, 59.465]) y_main = np.array([0.438160379, 0.008706677, 0.000160106]) </code></pre> <p>where I want to find the parameters <strong>a</strong>, <strong>b</strong> and <strong>c</strong>. From the mycurvefit website, I get the answers:</p> <p>a = 4821416</p> <p>b = -154.0293</p> <p>c = 30.51661</p> <p>Which fit nicely the given points. But when I try to run with curve_fit():</p> <pre><code>poptMain, pcovMain = curve_fit(gauss_func, x_main, y_main, p0=(1, -1, 1),sigma=np.array([1,1,1])) </code></pre> <p>I get the <strong>&quot;RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 800.&quot;</strong> error.</p> <p>What I tried:</p> <ul> <li>Changing the maxfev to other values, such as 5000, 10000, 100000 (no effect).</li> <li>Replacing the initial guess p0 to values closer to the mycurvefit answer (no effect) and common values such as [1, 1, 1], [1, 0, 1], etc (no effect).</li> </ul> <p>Even when inputting the answer, it still won't find the parameters! I have used this same code before with other similar cases, and it worked nicely. But this time it's not converging at all. What could I do to solve this?</p>
[ { "answer_id": 74308887, "author": "ZygD", "author_id": 2753501, "author_profile": "https://Stackoverflow.com/users/2753501", "pm_score": 2, "selected": true, "text": "lag" }, { "answer_id": 74312662, "author": "wwnde", "author_id": 8986975, "author_profile": "https://Stackoverflow.com/users/8986975", "pm_score": 0, "selected": false, "text": "(df.withColumn('index', row_number().over(Window.partitionBy().orderBy('ID','Block')))#create an index to reorder after comps\n .withColumn('BlockRank', rank().over(Window.partitionBy('Block').orderBy('ID'))).orderBy('index')#Rank per Block\n .where(col('BlockRank')==1)\n .drop('index','BlockRank')\n).show()\n\n+---+-----+\n| ID|Block|\n+---+-----+\n| 1| A|\n| 1| C|\n| 1| C|\n| 3| B|\n+---+-----+\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14703689/" ]
74,304,929
<p>I am unable to use OAuth 2 token generated in JMeter to execute following requests.</p> <p>I am able to successfully POST to our identity server and obtain a token, capture it using a JSON Extractor, and pass that variable to a following GET call. But every time I execute the Test Plan, I get a 403 error on the GET call.</p> <p>What is strange, is if I obtain a OAuth 2 token from Postman using the same parameters, copy the token from Postman, and then update my GET request in JMeter to use that token, it works.</p> <p>I have tried to record in JMeter the POST and GET calls from Postman, but it results in same 403 error. The token only works if I get it from Postman first.</p>
[ { "answer_id": 74308887, "author": "ZygD", "author_id": 2753501, "author_profile": "https://Stackoverflow.com/users/2753501", "pm_score": 2, "selected": true, "text": "lag" }, { "answer_id": 74312662, "author": "wwnde", "author_id": 8986975, "author_profile": "https://Stackoverflow.com/users/8986975", "pm_score": 0, "selected": false, "text": "(df.withColumn('index', row_number().over(Window.partitionBy().orderBy('ID','Block')))#create an index to reorder after comps\n .withColumn('BlockRank', rank().over(Window.partitionBy('Block').orderBy('ID'))).orderBy('index')#Rank per Block\n .where(col('BlockRank')==1)\n .drop('index','BlockRank')\n).show()\n\n+---+-----+\n| ID|Block|\n+---+-----+\n| 1| A|\n| 1| C|\n| 1| C|\n| 3| B|\n+---+-----+\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408529/" ]
74,304,945
<pre><code>data={'id':[1, 2, 3],'A': ['edx',None , 'edx'],'B': [None,'com',None ],'C': ['tab','tab',None ] } df = pd.DataFrame(data) </code></pre> <p>Given data frame :</p> <pre><code>id A B C 1 edx None tab 2 None com tab 3 edx None None </code></pre> <p>Desired Result:</p> <pre><code>id Learn 1 edx 1 tab 2 com 2 tab 3 edx </code></pre> <p>Same I Expect that I have mentioned above.</p>
[ { "answer_id": 74305017, "author": "Chris", "author_id": 4718350, "author_profile": "https://Stackoverflow.com/users/4718350", "pm_score": 2, "selected": true, "text": "pd.melt" }, { "answer_id": 74305076, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "out=(df.set_index('id') # set index\n .stack() # stack\n .droplevel(1) # remove the unwanted level\n .reset_index()\n .rename(columns={0:'Learn'}))\nout\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17822538/" ]
74,304,963
<p>Just as I said in the title I need to mimic a ConcurrentDictionary using Dictionaries because I need to serialize the said collection and the concurrent variant is not serializable. Any Idea in how ConcurrentDictionary handles multi-threading and how I should implement it?</p> <p>I haven't tried it yet, i feel like a fish out of water.</p>
[ { "answer_id": 74305039, "author": "jmcilhinney", "author_id": 584183, "author_profile": "https://Stackoverflow.com/users/584183", "pm_score": 0, "selected": false, "text": "lock" }, { "answer_id": 74305506, "author": "JuanR", "author_id": 4190402, "author_profile": "https://Stackoverflow.com/users/4190402", "pm_score": -1, "selected": true, "text": "BinaryFormatter" }, { "answer_id": 74306178, "author": "JonasH", "author_id": 12342238, "author_profile": "https://Stackoverflow.com/users/12342238", "pm_score": 0, "selected": false, "text": "myQueue.GetConsumingEnumerable()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16009197/" ]
74,304,966
<p>I have SQL table like the below in an oracle DB:</p> <p><a href="https://i.stack.imgur.com/XsdYY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XsdYY.png" alt="enter image description here" /></a></p> <p>I would like to obtain the below view from the above table:</p> <p><a href="https://i.stack.imgur.com/NC17e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NC17e.png" alt="enter image description here" /></a></p> <p>I am able to produce 1 row of the view with the below query (in this example Item_id 'a').</p> <pre><code>SELECT Item_ID, transaction_date as Latest_transaction FROM ( SELECT * FROM TABLE WHERE Item_id LIKE '%a%' ORDER BY transaction_date DESC ) WHERE ROWNUM = 1 </code></pre> <p>I would like to perform the following query on each on each value in the array ['a', 'b' , 'd' , 'e' , 'z' ] and then append each row to a view via a UNION. However, I am unsure how to do this since SQL is not able to do FOR loops.</p> <p>I have tried running a giant query with a union for each ID, but in my actual use case there are too many Item_IDs(~4k) for SQL to execute this query.</p> <pre><code>SELECT Item_ID, transaction_date as Latest_transaction FROM ( SELECT * FROM TABLE WHERE Item_id LIKE '%a%' ORDER BY transaction_date DESC ) WHERE ROWNUM = 1 UNION SELECT Item_ID, transaction_date as Latest_transaction FROM ( SELECT * FROM TABLE WHERE Item_id LIKE '%b%' ORDER BY transaction_date DESC ) WHERE ROWNUM = 1 ...con't for all IDs. </code></pre>
[ { "answer_id": 74305225, "author": "Austin", "author_id": 12571241, "author_profile": "https://Stackoverflow.com/users/12571241", "pm_score": 1, "selected": false, "text": "regexp_substr" }, { "answer_id": 74306212, "author": "p3consulting", "author_id": 4956336, "author_profile": "https://Stackoverflow.com/users/4956336", "pm_score": 2, "selected": false, "text": "WITH data(transaction_date, item_ids) AS (\n SELECT TO_DATE('10/11/2022','MM/DD/YYYY'), 'a;b;z' FROM DUAL UNION ALL\n SELECT TO_DATE('10/10/2022','MM/DD/YYYY'), 'a;d' FROM DUAL UNION ALL \n SELECT TO_DATE('10/9/2022','MM/DD/YYYY'), 'a;b;d;z' FROM DUAL UNION ALL \n SELECT TO_DATE('10/8/2022','MM/DD/YYYY'), 'z;e' FROM DUAL \n),\nall_ids(id) AS (\n SELECT regexp_substr('a;b;d;e;g;z','[^;]+',1,LEVEL) FROM DUAL\n CONNECT BY regexp_substr('a;b;d;e;g;z','[^;]+',1,LEVEL) IS NOT NULL\n),\nexpanded_ids AS (\n SELECT id, MAX(transaction_date) AS latest_transaction FROM (\n SELECT transaction_date, regexp_substr(item_ids,'[^;]+',1,LEVEL) AS id FROM data\n CONNECT BY regexp_substr(item_ids,'[^;]+',1,LEVEL) IS NOT NULL\n AND PRIOR transaction_date = transaction_date AND PRIOR sys_guid() IS NOT NULL\n )\n GROUP BY id\n)\nSELECT a.id, e.latest_transaction \nFROM all_ids a \nLEFT JOIN expanded_ids e ON e.id = a.id\nORDER BY id\n;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15772700/" ]
74,304,992
<p>I read various articles and found that the latest versions of Windows support the <code>cURL</code> command via the <code>command prompt</code> right out of the box without any installation. So I am trying to make a simple <code>cURL</code> request to my local web server, but it is unable to make the request and get the response. It may be because the cURL request consists of the request body.</p> <p>If I try to make the same request via <code>Windows Power Shell</code>, then it's also not working as expected. So I want to know why I cannot make the cURL request via Command Prompt and Power Shell.</p> <p>Following is a sample cURL request that I am trying to make:</p> <pre><code>curl -X 'POST' \ 'http://localhost:9010/api/generatePersons?pretty=false' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ &quot;persons&quot;: [{ &quot;nodeId&quot;: 1, &quot;eventType&quot;: &quot;persons&quot;, &quot;personID&quot;: false, &quot;refPersons&quot;: [], &quot;parent&quot;: {}, &quot;child&quot;: [] }] }' </code></pre>
[ { "answer_id": 74305225, "author": "Austin", "author_id": 12571241, "author_profile": "https://Stackoverflow.com/users/12571241", "pm_score": 1, "selected": false, "text": "regexp_substr" }, { "answer_id": 74306212, "author": "p3consulting", "author_id": 4956336, "author_profile": "https://Stackoverflow.com/users/4956336", "pm_score": 2, "selected": false, "text": "WITH data(transaction_date, item_ids) AS (\n SELECT TO_DATE('10/11/2022','MM/DD/YYYY'), 'a;b;z' FROM DUAL UNION ALL\n SELECT TO_DATE('10/10/2022','MM/DD/YYYY'), 'a;d' FROM DUAL UNION ALL \n SELECT TO_DATE('10/9/2022','MM/DD/YYYY'), 'a;b;d;z' FROM DUAL UNION ALL \n SELECT TO_DATE('10/8/2022','MM/DD/YYYY'), 'z;e' FROM DUAL \n),\nall_ids(id) AS (\n SELECT regexp_substr('a;b;d;e;g;z','[^;]+',1,LEVEL) FROM DUAL\n CONNECT BY regexp_substr('a;b;d;e;g;z','[^;]+',1,LEVEL) IS NOT NULL\n),\nexpanded_ids AS (\n SELECT id, MAX(transaction_date) AS latest_transaction FROM (\n SELECT transaction_date, regexp_substr(item_ids,'[^;]+',1,LEVEL) AS id FROM data\n CONNECT BY regexp_substr(item_ids,'[^;]+',1,LEVEL) IS NOT NULL\n AND PRIOR transaction_date = transaction_date AND PRIOR sys_guid() IS NOT NULL\n )\n GROUP BY id\n)\nSELECT a.id, e.latest_transaction \nFROM all_ids a \nLEFT JOIN expanded_ids e ON e.id = a.id\nORDER BY id\n;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7584240/" ]
74,304,996
<p>I'm trying to create a slider but the cards inside it have no spaces at all. I've tried to add margins between them but this doesn't work.</p> <p>Would you help me to discover where I messed up? Thanks in advance.</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 cards = document.querySelectorAll(".card"); const btnLeft = document.querySelector(".slider__btn--left"); const btnRight = document.querySelector(".slider__btn--right"); let currentCard = 0; const lastCard = cards.length; const goToCard = function(currCard) { cards.forEach( (card, index) =&gt; (card.style.transform = `translateX(${100 * (index - currCard)}%)`) ); }; goToCard(0); const nextCard = function() { if (currentCard === lastCard - 1) currentCard = 0; else currentCard++; goToCard(currentCard); }; const previousCard = function() { if (currentCard === 0) currentCard = lastCard - 1; else currentCard--; goToCard(currentCard); }; btnLeft.addEventListener("click", previousCard); btnRight.addEventListener("click", nextCard);</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.slider { display: flex; align-items: center; justify-content: center; position: relative; } .card { position: absolute; top: 6rem; height: 10rem; width: 10rem; display: flex; flex-direction: column; justify-content: space-between; background-color: #634133; transition: all 1s; } .slider__btn { font-size: 3.25rem; color: #fff; background-color: #634133; font-family: sans-serif; border: none; border-radius: 100%; box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.1); position: absolute; top: 50%; z-index: 10; height: 5.5rem; width: 5.5rem; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2 ease; } .slider__btn--left { left: 15%; transform: translate(-50%, 150%); } .slider__btn--right { right: 15%; transform: translate(50%, 140%); } .slider__btn:hover { background-color: rgba(216, 123, 91, 0.85); } .photo__photo { height: 23rem; } .photo__photo--1 { background-color: yellow; } .photo__photo--2 { background-color: red; } .photo__photo--3 { background-color: purple; } .photo__photo--4 { background-color: green; } .photo__photo--5 { background-color: blue; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="slider"&gt; &lt;div class="card"&gt; &lt;div class="photo photo__photo--1"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;div class="card"&gt; &lt;div class="photo photo__photo--2"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;div class="card"&gt; &lt;div class="photo photo__photo--3"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;div class="card"&gt; &lt;div class="photo photo__photo--4"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;div class="card"&gt; &lt;div class="photo photo__photo--5"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;button class="slider__btn slider__btn--left"&gt;&amp;larr;&lt;/button&gt; &lt;button class="slider__btn slider__btn--right"&gt;&amp;rarr;&lt;/button&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74305692, "author": "Igli", "author_id": 15113957, "author_profile": "https://Stackoverflow.com/users/15113957", "pm_score": 1, "selected": false, "text": "border-left: 11px solid white;" }, { "answer_id": 74305914, "author": "johannes", "author_id": 7178191, "author_profile": "https://Stackoverflow.com/users/7178191", "pm_score": 0, "selected": false, "text": "justify-content" }, { "answer_id": 74306164, "author": "isherwood", "author_id": 1264804, "author_profile": "https://Stackoverflow.com/users/1264804", "pm_score": 2, "selected": false, "text": "const cardGap = 8; \ncard.style.transform = `translateX(${100 * (index - currCard) + cardGap * index}%)`\n" }, { "answer_id": 74309551, "author": "Mark Schultheiss", "author_id": 125981, "author_profile": "https://Stackoverflow.com/users/125981", "pm_score": 1, "selected": false, "text": "lastCard" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74304996", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4819856/" ]
74,305,007
<p>I have these two tables:</p> <pre><code>Staff (staffNo(PK), fName, lname, gender, DOB, salary, intTelNo) </code></pre> <pre><code>CarPurchase (purchaseNo(PK), registrationNo(FK), customerNo(FK), amount, date, staffNo(FK)). </code></pre> <p>I need an SQL query to list the names of all male staff who have sold more than 10 vehicles.</p> <p>I tried this:</p> <pre><code>SELECT S.f.Name, S.l.Name FROM Staff AS S.InnerJoin Car Purchase AS P ON S.staffNo = P.staffNo WHERE S.gender= “Male” HAVING COUNT(DISTINCT P.staffNo) \&gt; 10; </code></pre> <p>But the query gave me this error:</p> <blockquote> <p>Oops, the OP forgot to include the error message. Maybe they'll edit the question to fix it.</p> </blockquote>
[ { "answer_id": 74305692, "author": "Igli", "author_id": 15113957, "author_profile": "https://Stackoverflow.com/users/15113957", "pm_score": 1, "selected": false, "text": "border-left: 11px solid white;" }, { "answer_id": 74305914, "author": "johannes", "author_id": 7178191, "author_profile": "https://Stackoverflow.com/users/7178191", "pm_score": 0, "selected": false, "text": "justify-content" }, { "answer_id": 74306164, "author": "isherwood", "author_id": 1264804, "author_profile": "https://Stackoverflow.com/users/1264804", "pm_score": 2, "selected": false, "text": "const cardGap = 8; \ncard.style.transform = `translateX(${100 * (index - currCard) + cardGap * index}%)`\n" }, { "answer_id": 74309551, "author": "Mark Schultheiss", "author_id": 125981, "author_profile": "https://Stackoverflow.com/users/125981", "pm_score": 1, "selected": false, "text": "lastCard" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408888/" ]
74,305,030
<p>I've update my Strapi version from 4.3.6 to 4.4.5 and got this error when I start appliation with production environment with command <code>npm run start</code></p> <pre><code>This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: /home/megapolisgit/megapolis-platform/node_modules/@strapi/database/lib/entity-manager/morph-relations.js:15 targetAttribute?.target === uid &amp;&amp; ^ SyntaxError: Unexpected token '.' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.&lt;anonymous&gt; (/home/megapolisgit/megapolis-platform/node_modules/@strapi/database/lib/entity-manager/index.js:21:66) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) </code></pre> <p>node version is 17.9.1 db: PostgreSQL 14.2</p> <p>I've checked github repository for answer but haven't found the same issues</p>
[ { "answer_id": 74423597, "author": "Kirill Novikov", "author_id": 2791142, "author_profile": "https://Stackoverflow.com/users/2791142", "pm_score": 2, "selected": true, "text": "/usr/bin/node" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2791142/" ]
74,305,044
<p>I downloaded a file using curl and I am tyring to make batch find the highest value &quot;paper-1.19.2-x&quot; of x. I wrote this code `</p> <pre><code>@ECHO off curl &quot;https://api.papermc.io/v2/projects/paper/versions/1.19.2/builds/&quot; --output builds.txt setlocal enabledelayedexpansion For /f %%i in (builds.txt) do ( for %%x in (paper-1.19.2-*.jar) do ( set &quot;line=%%~nx&quot; set &quot;line=!FN:paper-1.19.2-=!&quot; if !line! GTR !max! set max=!line! )) Echo paper-1.19.2-%max%.jar </code></pre> <p>I download the file and name it builds.txt then I try to read the file and look for the highest x value. but the output of this is simply <code>paper-1.19.2-.jar</code></p> <p>I think what I am doing incorrectly is not reading the file correctly. Any help?</p> <p><strong>edit</strong></p> <p>the builds.txt that is downloaded by curl is just a json file that i convert into txt, so it basically converts to 1 line txt file and part of the code from it looks like this</p> <p>`</p> <pre><code>{&quot;project_id&quot;:&quot;paper&quot;,&quot;project_name&quot;:&quot;Paper&quot;,&quot;version&quot;:&quot;1.19.2&quot;,&quot;builds&quot;:[{&quot;build&quot;:112,&quot;time&quot;:&quot;2022-08-05T23:08:28.926Z&quot;,&quot;channel&quot;:&quot;default&quot;,&quot;promoted&quot;:false,&quot;changes&quot;:[{&quot;commit&quot;:&quot;bef2c9d005bdd039f188ee53094a928e76bd8e59&quot;,&quot;summary&quot;:&quot;1.19.2 (#8250)&quot;,&quot;message&quot;:&quot;1.19.2 (#8250)\n\n&quot;}],&quot;downloads&quot;:{&quot;application&quot;:{&quot;name&quot;:&quot;paper-1.19.2-112.jar&quot;,&quot;sha256&quot;:&quot;59e5b07dbffcbceeef15ebbe77ffcc8a56f58fdfcb2d3092be256c32a5c9588d&quot;},&quot;mojang-mappings&quot;:{&quot;name&quot;:&quot;paper-mojmap-1.19.2-112.jar&quot;,&quot;sha256&quot;:&quot;f743f109522b2a21b290e9e9e8015e2e630ec74d6e7496a6bc31e5af34f2a4bd&quot;}}},{&quot;build&quot;:113,&quot;time&quot;:&quot;2022-08-06T23:30:43.315Z&quot;,&quot;channel&quot;:&quot;default&quot;,&quot;promoted&quot;:false,&quot;changes&quot;:[{&quot;commit&quot;:&quot;a15152e96a0c1f8b8f6792f4308e8077e01614d2&quot; </code></pre> <p>the new batch code is `</p> <pre><code>@ECHO off setlocal EnableExtensions setlocal EnableDelayedExpansion curl &quot;https://api.papermc.io/v2/projects/paper/versions/1.19.2/builds/&quot; --output builds.txt set &quot;MaxNumber=0&quot; if exist &quot;builds.txt&quot; for /F &quot;tokens=5 delims=-.&quot; %%I in ('%SystemRoot%\System32\findstr.exe /R &quot;paper-.*\.jar&quot; &quot;builds.txt&quot;') do if %%I GTR !MaxNumber! set &quot;MaxNumber=%%I&quot; Echo %MaxNumber% </code></pre> <p>and it just out puts this `</p> <pre><code>05T23:08:28 </code></pre>
[ { "answer_id": 74306493, "author": "Stephan", "author_id": 2152082, "author_profile": "https://Stackoverflow.com/users/2152082", "pm_score": 2, "selected": true, "text": "build.txt" }, { "answer_id": 74307789, "author": "Aacini", "author_id": 778560, "author_profile": "https://Stackoverflow.com/users/778560", "pm_score": 2, "selected": false, "text": "@echo off\nsetlocal EnableDelayedExpansion\n\ncurl \"https://api.papermc.io/v2/projects/paper/versions/1.19.2/builds/\" --output builds.txt\ncall :readFile < builds.txt\nfor /F \"delims=.\" %%a in (\"!last:*paper-1.19.2-=!\") do echo paper-1.19.2-%%a.jar\ngoto :EOF\n\n:readFile\nset \"last=%line%\"\nset /P \"line=\"\nif not errorlevel 1 goto readFile\nexit /B\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17815509/" ]
74,305,047
<p>Is there any way to write anything to conandata.yml file? I want calculate execution time of code and populate my conandata.yml with it.</p>
[ { "answer_id": 74305224, "author": "Adam Jaamour", "author_id": 5609328, "author_profile": "https://Stackoverflow.com/users/5609328", "pm_score": 0, "selected": false, "text": "pip" }, { "answer_id": 74306189, "author": "drodri", "author_id": 3215383, "author_profile": "https://Stackoverflow.com/users/3215383", "pm_score": 2, "selected": true, "text": "update_conandata()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15436709/" ]
74,305,077
<p>I'm facing an issue with the following :</p> <p>1- I don't know how to control the size of the circle, so the size should get larger when the number of groups in percent is large. For example, group1_north's first point is 97%(0.97) I want that to be a larger circle than 8.6%(0.086).</p> <p>2- I don't know how to make each circle in a different color.</p> <p>3- The label on the figure is very difficult to control, especially with long text. How to control the size and the wrap so it can be readable.</p> <pre><code>df=data.frame(names_of_dissess=c(&quot;Hib Disease_type1&quot;,&quot;Hepatitis_type1&quot;,&quot;Flu (Influenza)_type1&quot;,&quot;Ebola_type1&quot;, &quot;Coronaviruses_type1&quot;,&quot;Japanese Encephalitis_type1&quot;), algorithm1=c(0.00,0.29,0.11,0.21,0.25,0.29) ,group1_north=c(0.97,0.086,0.34,0.11,0.086,0.11) ) par( mar=c(6, 6, 4, 4),xpd = TRUE ) plot(group1_north ~algorithm1, col=&quot;lightblue&quot;, pch=19, cex=2, data=df, xlab = &quot;algorithm1&quot;, ylab = &quot;group1_north %&quot;, xlim=c(0.0,0.3), ylim=c(0.0,1), main = &quot;algorithm1 behavior&quot;, font.main=10, family = &quot;A&quot;, cex.main=1.1, cex.lab=0.9 ) text(group1_north -0.02 ~algorithm1, labels=names_of_dissess,data=df, cex.main =.9, font=8) </code></pre>
[ { "answer_id": 74305224, "author": "Adam Jaamour", "author_id": 5609328, "author_profile": "https://Stackoverflow.com/users/5609328", "pm_score": 0, "selected": false, "text": "pip" }, { "answer_id": 74306189, "author": "drodri", "author_id": 3215383, "author_profile": "https://Stackoverflow.com/users/3215383", "pm_score": 2, "selected": true, "text": "update_conandata()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12096959/" ]
74,305,111
<p>I have a Dataframe that have some null values, but also other entries that I should count as missing. The forms of missing that I want to take into account are:</p> <ul> <li>The normal null value from pandas</li> <li>The string N/A</li> <li>0.0</li> <li>&quot;-&quot;</li> </ul> <p>I want to identify the percentage of missing values per column.</p> <p>I tried this</p> <pre><code> # Total null values mis_val = df.isnull().sum() # N/A values mis_val = mis_val+(df=='N/A').sum() # Percentage of total data mis_val_percent = 100 * mis_val / len(df) </code></pre> <p>But the second line of code doesn't seem to do what I expected. I wanted it to count the number of 'N/A' per column</p>
[ { "answer_id": 74305242, "author": "Mato", "author_id": 20390882, "author_profile": "https://Stackoverflow.com/users/20390882", "pm_score": -1, "selected": false, "text": "df[\"Col_name\"].isna().sum()\n" }, { "answer_id": 74305329, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# define regex pattern on values that you like treated as null\n# remember to escape the regex character\n\n# defined N/A, 0.0, and - : /, . and - are all escaped with \\\n# each patter is separated with |\npat = 'N\\/A|0\\.0|\\-'\n\n# replace values defined in pat with np.nan\n# check if its null and take the sum\n\ndf['col'].replace(pat, np.nan, regex=True).isna().sum()\n\n" }, { "answer_id": 74305468, "author": "Mat.B", "author_id": 14649447, "author_profile": "https://Stackoverflow.com/users/14649447", "pm_score": 0, "selected": false, "text": "import pandas as pd\nimport numpy as np\n\ndata = {'col1':[10.0,20.0,np.nan,'N/A',0,25],\n 'col2':[0,np.nan,'N/A','N/A','','-']}\ndf = pd.DataFrame(data)\n\n# The 4 \"forms of missing\": \nmissing_1 = (df=='N/A').sum()\nmissing_2 = df.isna().sum()\nmissing_3 = df.isnull().sum()\nmissing_4 = (df=='-').sum()\n\nmis_val_percent =100*(missing_1+missing_2+missing_3+missing_4)/len(df)\nprint(mis_val_percent)\n" }, { "answer_id": 74305512, "author": "Алексей Р", "author_id": 15035314, "author_profile": "https://Stackoverflow.com/users/15035314", "pm_score": 1, "selected": false, "text": "isin([])" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19768301/" ]
74,305,132
<p>This is the JSON im receiving, already filtered. (its coming from the google places autocomplete API)</p> <pre><code>{ &quot;predictions&quot;: [ { &quot;description&quot;: &quot;Frankfurt am Main, Deutschland&quot;, &quot;place_id&quot;: &quot;ChIJxZZwR28JvUcRAMawKVBDIgQ&quot;, }, { &quot;description&quot;: &quot;Frankfurt (Oder), Deutschland&quot;, &quot;place_id&quot;: &quot;ChIJb_u1AiqYB0cRwDteW0YgIQQ&quot;, }, { &quot;description&quot;: &quot;Frankfurt Hahn Flughafen (HHN), Lautzenhausen, Deutschland&quot;, &quot;place_id&quot;: &quot;ChIJX3W0JgQYvkcRWBxGlm6csj0&quot;, } ], &quot;status&quot;: &quot;OK&quot; } </code></pre> <p>And I need to get this JSON into this format:</p> <pre><code>{ &quot;success&quot;:true, &quot;message&quot;:&quot;OK&quot;, &quot;data&quot;:[ { &quot;description&quot;:&quot;Frankfurt Hahn Flughafen (HHN), Lautzenhausen, Deutschland&quot;, &quot;id&quot;:&quot;ChIJX3W0JgQYvkcRWBxGlm6csj0&quot; }, { &quot;description&quot;:&quot;Frankfurt Airport (FRA), Frankfurt am Main, Deutschland&quot;, &quot;id&quot;:&quot;ChIJeflCVHQLvUcRMfP4IU3YdIo&quot; }, { &quot;description&quot;:&quot;Frankfurt Marriott Hotel, Hamburger Allee, Frankfurt am Main, Deutschland&quot;, &quot;id&quot;:&quot;ChIJdag3xFsJvUcRZtfKqZkzBAM&quot; } ] } I would be very g </code></pre> <p>So predictions is just renamed to &quot;data&quot;, we change rename status to message, move it up and add a success if the http-request that happened earlier was a success or not. This does not seem so hard on the first catch, but I can't seem to find resources to transform or rearrange JSON in C#.</p> <p>I would be very grateful for any tips or resources, so I can get unstuck on this probably not so difficult task. I should mention I'm fairly new to all of this.</p> <p>Thank you all in advance!</p>
[ { "answer_id": 74305242, "author": "Mato", "author_id": 20390882, "author_profile": "https://Stackoverflow.com/users/20390882", "pm_score": -1, "selected": false, "text": "df[\"Col_name\"].isna().sum()\n" }, { "answer_id": 74305329, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# define regex pattern on values that you like treated as null\n# remember to escape the regex character\n\n# defined N/A, 0.0, and - : /, . and - are all escaped with \\\n# each patter is separated with |\npat = 'N\\/A|0\\.0|\\-'\n\n# replace values defined in pat with np.nan\n# check if its null and take the sum\n\ndf['col'].replace(pat, np.nan, regex=True).isna().sum()\n\n" }, { "answer_id": 74305468, "author": "Mat.B", "author_id": 14649447, "author_profile": "https://Stackoverflow.com/users/14649447", "pm_score": 0, "selected": false, "text": "import pandas as pd\nimport numpy as np\n\ndata = {'col1':[10.0,20.0,np.nan,'N/A',0,25],\n 'col2':[0,np.nan,'N/A','N/A','','-']}\ndf = pd.DataFrame(data)\n\n# The 4 \"forms of missing\": \nmissing_1 = (df=='N/A').sum()\nmissing_2 = df.isna().sum()\nmissing_3 = df.isnull().sum()\nmissing_4 = (df=='-').sum()\n\nmis_val_percent =100*(missing_1+missing_2+missing_3+missing_4)/len(df)\nprint(mis_val_percent)\n" }, { "answer_id": 74305512, "author": "Алексей Р", "author_id": 15035314, "author_profile": "https://Stackoverflow.com/users/15035314", "pm_score": 1, "selected": false, "text": "isin([])" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20002417/" ]
74,305,151
<p>I'm trying to open SVG file first in PHP and then return this data:</p> <pre class="lang-php prettyprint-override"><code>$file = dirname(__FILE__) . $_GET[&quot;file&quot;] . &quot;.svg&quot;; if (!file_exists($file)) { $file = dirname(__FILE__) . $_GET[&quot;file&quot;] . &quot;.png&quot;; if (!file_exists($file)) { throw new NotFoundHttpException(); } else header('Content-Type: image/png'); } else header('Content-Type: image/svg+xml'); $content = file_get_contents($file); return $content; </code></pre> <p>And in HTML:</p> <pre class="lang-html prettyprint-override"><code>&lt;img src=&quot;script.php?file=someimage&quot;&gt; </code></pre> <p>Problem is that its not showing SVG images in the tag. It works, if I set <code>script.php?file=someimage</code> to the URL string of my browser, but not inside the tag. PNG works fine. If i set just</p> <pre class="lang-html prettyprint-override"><code>&lt;img src=&quot;someimage.svg&quot;&gt; </code></pre> <p>it also works perfect.</p> <p>embed and object tags works, but I need img.</p> <p><strong>UPDATE:</strong></p> <p>The problem was in Yii2, I send headers wrong way. In some reason it works for PNG, but not for SVG.</p> <p>It should be done like that:</p> <pre class="lang-php prettyprint-override"><code>Yii::$app-&gt;response-&gt;format = \yii\web\Response::FORMAT_RAW; Yii::$app-&gt;response-&gt;headers-&gt;add('Content-Type', 'image/svg+xml'); </code></pre>
[ { "answer_id": 74305242, "author": "Mato", "author_id": 20390882, "author_profile": "https://Stackoverflow.com/users/20390882", "pm_score": -1, "selected": false, "text": "df[\"Col_name\"].isna().sum()\n" }, { "answer_id": 74305329, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# define regex pattern on values that you like treated as null\n# remember to escape the regex character\n\n# defined N/A, 0.0, and - : /, . and - are all escaped with \\\n# each patter is separated with |\npat = 'N\\/A|0\\.0|\\-'\n\n# replace values defined in pat with np.nan\n# check if its null and take the sum\n\ndf['col'].replace(pat, np.nan, regex=True).isna().sum()\n\n" }, { "answer_id": 74305468, "author": "Mat.B", "author_id": 14649447, "author_profile": "https://Stackoverflow.com/users/14649447", "pm_score": 0, "selected": false, "text": "import pandas as pd\nimport numpy as np\n\ndata = {'col1':[10.0,20.0,np.nan,'N/A',0,25],\n 'col2':[0,np.nan,'N/A','N/A','','-']}\ndf = pd.DataFrame(data)\n\n# The 4 \"forms of missing\": \nmissing_1 = (df=='N/A').sum()\nmissing_2 = df.isna().sum()\nmissing_3 = df.isnull().sum()\nmissing_4 = (df=='-').sum()\n\nmis_val_percent =100*(missing_1+missing_2+missing_3+missing_4)/len(df)\nprint(mis_val_percent)\n" }, { "answer_id": 74305512, "author": "Алексей Р", "author_id": 15035314, "author_profile": "https://Stackoverflow.com/users/15035314", "pm_score": 1, "selected": false, "text": "isin([])" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20387415/" ]
74,305,171
<p>I am creating a spark dataframe using the below query:</p> <pre><code>select distinct adr.ProductionDate,adr.CostCenterKey,adr.AEMainCategoryKey, Sum(adr.DurationDayFrac*adr.FixedCashCostAE)*100 / (select sum(adr_sub.DurationDayFrac*adr_sub.FixedCashCostAE) from hive_metastore.oth_opsdbconf.operations_db___asset_effectiveness_daily_reporting adr_sub where adr_sub.costcenterkey=adr.costcenterkey and adr_sub.ProductionDate=adr.ProductionDate ) as AELossMagnitude FROM hive_metastore.oth_opsdbconf.operations_db___asset_effectiveness_daily_reporting adr WHERE adr.DurationDayFrac != 0 AND adr.ProductionDate &lt;= Current_Date() AND adr.ProductionDate &gt;= '2017-01-01' AND adr.SiteName in ('Ludwigshafen','Schwarzheide','Antwerpen') AND AreaIsCurrent = 'true' group by adr.ProductionDate,adr.CostCenterKey,adr.AEMainCategoryKey order by adr.ProductionDate,adr.CostCenterKey,adr.AEMainCategoryKey </code></pre> <p>But i am getting the below error:</p> <p>AnalysisException: Correlated scalar subquery 'scalarsubquery(adr.costcenterkey, adr.ProductionDate)' is neither present in the group by, nor in an aggregate function. Add it to group by using ordinal position or wrap it in first() (or first_value) if you don't care which value you get.;</p> <p>Request you to please help me with the correct syntax.</p> <p>I am expecting the correct syntax to remove the error.z Its asking for group by in the sub query which is not possible.</p>
[ { "answer_id": 74305242, "author": "Mato", "author_id": 20390882, "author_profile": "https://Stackoverflow.com/users/20390882", "pm_score": -1, "selected": false, "text": "df[\"Col_name\"].isna().sum()\n" }, { "answer_id": 74305329, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# define regex pattern on values that you like treated as null\n# remember to escape the regex character\n\n# defined N/A, 0.0, and - : /, . and - are all escaped with \\\n# each patter is separated with |\npat = 'N\\/A|0\\.0|\\-'\n\n# replace values defined in pat with np.nan\n# check if its null and take the sum\n\ndf['col'].replace(pat, np.nan, regex=True).isna().sum()\n\n" }, { "answer_id": 74305468, "author": "Mat.B", "author_id": 14649447, "author_profile": "https://Stackoverflow.com/users/14649447", "pm_score": 0, "selected": false, "text": "import pandas as pd\nimport numpy as np\n\ndata = {'col1':[10.0,20.0,np.nan,'N/A',0,25],\n 'col2':[0,np.nan,'N/A','N/A','','-']}\ndf = pd.DataFrame(data)\n\n# The 4 \"forms of missing\": \nmissing_1 = (df=='N/A').sum()\nmissing_2 = df.isna().sum()\nmissing_3 = df.isnull().sum()\nmissing_4 = (df=='-').sum()\n\nmis_val_percent =100*(missing_1+missing_2+missing_3+missing_4)/len(df)\nprint(mis_val_percent)\n" }, { "answer_id": 74305512, "author": "Алексей Р", "author_id": 15035314, "author_profile": "https://Stackoverflow.com/users/15035314", "pm_score": 1, "selected": false, "text": "isin([])" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20282454/" ]
74,305,182
<p>Sorry if I type something wrong, I am new. I want to create a method that takes an array, and gives back an array with the numbers that have the same first and last digits in the previous array.Example: 12 is equal to 1342.</p> <p>I have created this for loop to go through the numbers, but I don't know how to compare them.</p> <pre><code>public int[] findDuplicates(int[] a) { List&lt;Integer&gt; result = new ArrayList&lt;&gt;(); for (int i = 0; i &lt; a.length; i++) { for (int j = i + 1; j &lt; a.length; j++) { if ((//what do I write here) ) { //and here } } } return result.stream() .mapToInt(Integer::intValue) .toArray(); } </code></pre>
[ { "answer_id": 74305570, "author": "YOUSSEF.R", "author_id": 20231479, "author_profile": "https://Stackoverflow.com/users/20231479", "pm_score": 1, "selected": false, "text": "public List<Integer> findDuplicates(int[] array){\n List<Integer> result = new ArrayList<>();\n for (int i = 0; i < array.length; i++) {\n int firstDigit = array[i];\n int lastDigit = array[i] % 10;\n while (firstDigit >= 10)\n firstDigit /= 10;\n if (firstDigit == lastDigit)\n result.add(array[i]);\n }\n return result;\n}\n" }, { "answer_id": 74305728, "author": "Coline MIGNOT", "author_id": 19103327, "author_profile": "https://Stackoverflow.com/users/19103327", "pm_score": 2, "selected": true, "text": "public int[] findDuplicates(int[] a) {\n List<Integer> result = new ArrayList<>();\n boolean[] numbersThatHaveBeenAdded = new boolean[a.length];\n\n for (int i = 0; i < a.length; i++) {\n for (int j = i + 1; j < a.length; j++) {\n\n String iNumber = String.valueOf(a[i]);\n String jNumber = String.valueOf(a[j]);\n if (iNumber.charAt(0) == jNumber.charAt(0)\n && iNumber.charAt(iNumber.length()-1) == jNumber.charAt(jNumber.length()-1)) {\n\n if (!numbersThatHaveBeenAdded[i]) {\n result.add(a[i]);\n numbersThatHaveBeenAdded[i] = true;\n }\n if (!numbersThatHaveBeenAdded[j]) {\n result.add(a[j]);\n numbersThatHaveBeenAdded[j] = true;\n }\n }\n\n }\n }\n\n return result.stream()\n .mapToInt(Integer::intValue)\n .toArray();\n}\n" }, { "answer_id": 74308022, "author": "WJS", "author_id": 1552534, "author_profile": "https://Stackoverflow.com/users/1552534", "pm_score": 0, "selected": false, "text": "log" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13689270/" ]
74,305,213
<p>I am using postgresql.</p> <p>Let's suppose I have this table name <code>my_table</code>:</p> <pre><code> id | idcm | stores | du | au | dtc | ---------------------------------------------------------------------------------- 1 | 20447 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-11-03 11:12:19.213799+01 | 2 | 20456 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-11-03 11:12:19.213799+01 | 3 | 20478 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-11-03 11:12:19.213799+01 | 4 | 20482 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-11-03 11:12:19.213799+01 | 5 | 20485 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | 6 | 20497 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | 7 | 20499 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | </code></pre> <p>I want to select only the rows having the value of <code>id</code> equal to one of the elements of the array in <code>stores</code> (of that line).<br> However, the type of <code>stores</code> is not array, it is jsonb.</p> <p>So I want to get something like this:</p> <pre><code> id | idcm | stores | du | au | dtc | ---------------------------------------------------------------------------------- 2 | 20456 | [2, 5] | 2022-11-02 | 2022-11-15 | 2022-11-03 11:12:19.213799+01 | 5 | 20485 | [7, 5] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | 6 | 20497 | [2, 6] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | 7 | 20499 | [5, 7] | 2022-11-02 | 2022-11-15 | 2022-10-25 20:25:08.949996+02 | </code></pre> <p>I have tryed with</p> <pre><code>select * from my_table where stores::text ilike id::text; </code></pre> <p>but it returns zero rows because I would need to put wildcard character <code>%</code> before and after <code>id</code>, <br>so I have tryed with</p> <pre><code>select * from my_table where stores::text ilike %id%::text; </code></pre> <p>but I get a syntax error.</p>
[ { "answer_id": 74305294, "author": "a_horse_with_no_name", "author_id": 330315, "author_profile": "https://Stackoverflow.com/users/330315", "pm_score": 2, "selected": true, "text": "select *\nfrom the_table\nwhere stores @> to_jsonb(id)\n" }, { "answer_id": 74305351, "author": "Volodymyr Sichka", "author_id": 5333324, "author_profile": "https://Stackoverflow.com/users/5333324", "pm_score": 0, "selected": false, "text": "select * from my_table where id = any(stores);\n" }, { "answer_id": 74305559, "author": "Hervé Piedvache", "author_id": 6757797, "author_profile": "https://Stackoverflow.com/users/6757797", "pm_score": 0, "selected": false, "text": "create table stores_table (id serial, stores jsonb);\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7658051/" ]
74,305,233
<p>My flutter web app won't start, I see the following errors in the browser console:</p> <p><a href="https://i.stack.imgur.com/pGZpP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pGZpP.png" alt="enter image description here" /></a></p> <p>This behavior only occurs when deployed on vercel. I don't get this error when deploying on firebase hosting.</p> <p>Furthermore, this error only occurs for nested routes. It works when I open my deployed app without a subpath in the URL.</p> <p>The error must occur somewhere in the <code>loadEntrypoint</code> function</p> <pre><code>&lt;script&gt; window.addEventListener('load', function (ev) { console.log(&quot;LOAD!&quot;); // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, } }).then(function (engineInitializer) { console.log(&quot;INIT&quot;); return engineInitializer.initializeEngine(); }).then(function (appRunner) { console.log(&quot;RUN&quot;); return appRunner.runApp(); }); }); &lt;/script&gt; </code></pre> <p>Interesting here is that it says <code>Failed to register a ServiceWorker for scope ('https://domainname.net/home/')</code> even though I load the page <code>https://domainname.net/home/questionnaire</code>. In general I expect it would register the ServiceWorker at <code>https://domainname.net</code> but I don't know much about ServiceWorkers anyways...</p> <p>I'm especially puzzled about this because this only happens on vercel but as the error occurs somewhere in <code>web/index.js</code>, it assume my hosting provider should have not influence on this behavior?</p> <p>Any ideas?</p>
[ { "answer_id": 74345472, "author": "egonzal", "author_id": 1243052, "author_profile": "https://Stackoverflow.com/users/1243052", "pm_score": 0, "selected": false, "text": "flutter build web\n" }, { "answer_id": 74350697, "author": "Jonas", "author_id": 9547658, "author_profile": "https://Stackoverflow.com/users/9547658", "pm_score": 2, "selected": true, "text": " var serviceWorkerVersion = null;\n var scriptLoaded = false;\n function loadMainDartJs() {\n if (scriptLoaded) {\n return;\n }\n scriptLoaded = true;\n var scriptTag = document.createElement('script');\n scriptTag.src = 'main.dart.js';\n scriptTag.type = 'application/javascript';\n document.body.append(scriptTag);\n }\n\n if ('serviceWorker' in navigator) {\n // Service workers are supported. Use them.\n window.addEventListener('load', function () {\n // Wait for registration to finish before dropping the <script> tag.\n // Otherwise, the browser will load the script multiple times,\n // potentially different versions.\n var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;\n navigator.serviceWorker.register(serviceWorkerUrl)\n .then((reg) => {\n function waitForActivation(serviceWorker) {\n serviceWorker.addEventListener('statechange', () => {\n if (serviceWorker.state == 'activated') {\n console.log('Installed new service worker.');\n loadMainDartJs();\n }\n });\n }\n if (!reg.active && (reg.installing || reg.waiting)) {\n // No active web worker and we have installed or are installing\n // one for the first time. Simply wait for it to activate.\n waitForActivation(reg.installing ?? reg.waiting);\n } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {\n // When the app updates the serviceWorkerVersion changes, so we\n // need to ask the service worker to update.\n console.log('New service worker available.');\n reg.update();\n waitForActivation(reg.installing);\n } else {\n // Existing service worker is still good.\n console.log('Loading app from service worker.');\n loadMainDartJs();\n }\n });\n\n // If service worker doesn't succeed in a reasonable amount of time,\n // fallback to plaint <script> tag.\n setTimeout(() => {\n if (!scriptLoaded) {\n console.warn(\n 'Failed to load app from service worker. Falling back to plain <script> tag.',\n );\n loadMainDartJs();\n }\n }, 4000);\n });\n } else {\n // Service workers not supported. Just drop the <script> tag.\n loadMainDartJs();\n }\n </script>\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9547658/" ]
74,305,246
<p>I have this CommandLineRunner in my Main class (ReservationprojectApplication)</p> <pre><code>@Bean CommandLineRunner run(UserService userService) { return args -&gt; { userService.saveRole(new Role(null, &quot;ROLE_ADMIN&quot;)); userService.saveRole(new Role(null, &quot;ROLE_STUDENT&quot;)); userService.saveUser(new User(&quot;administrator&quot;, &quot;admin@gmail.com&quot;, &quot;t&quot;, new ArrayList&lt;&gt;(), Instant.now(), true)); userService.saveUser(new User(&quot;elias&quot;, &quot;elias@gmail.com&quot;, &quot;t&quot;, new ArrayList&lt;&gt;(), Instant.now(), true)); userService.addRoleToUser(&quot;administrator&quot;, &quot;ROLE_ADMIN&quot;); userService.addRoleToUser(&quot;elias&quot;, &quot;ROLE_STUDENT&quot;); }; } </code></pre> <p>Is there a way to only run this code once the ddl-auto is set to create? I don't want to comment this code each time my ddl-auto is set to update.</p> <pre><code>spring: # Database properties datasource: password: blabla url: jdbc:postgresql://localhost:5432/cegeka_reservation username: postgres jpa: hibernate: **ddl-auto: update** properties: hibernate: dialect: org.hibernate.dialect.PostgreSQLDialect format_sql: true show_sql: true </code></pre> <p>Thanks in advance!</p>
[ { "answer_id": 74345472, "author": "egonzal", "author_id": 1243052, "author_profile": "https://Stackoverflow.com/users/1243052", "pm_score": 0, "selected": false, "text": "flutter build web\n" }, { "answer_id": 74350697, "author": "Jonas", "author_id": 9547658, "author_profile": "https://Stackoverflow.com/users/9547658", "pm_score": 2, "selected": true, "text": " var serviceWorkerVersion = null;\n var scriptLoaded = false;\n function loadMainDartJs() {\n if (scriptLoaded) {\n return;\n }\n scriptLoaded = true;\n var scriptTag = document.createElement('script');\n scriptTag.src = 'main.dart.js';\n scriptTag.type = 'application/javascript';\n document.body.append(scriptTag);\n }\n\n if ('serviceWorker' in navigator) {\n // Service workers are supported. Use them.\n window.addEventListener('load', function () {\n // Wait for registration to finish before dropping the <script> tag.\n // Otherwise, the browser will load the script multiple times,\n // potentially different versions.\n var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;\n navigator.serviceWorker.register(serviceWorkerUrl)\n .then((reg) => {\n function waitForActivation(serviceWorker) {\n serviceWorker.addEventListener('statechange', () => {\n if (serviceWorker.state == 'activated') {\n console.log('Installed new service worker.');\n loadMainDartJs();\n }\n });\n }\n if (!reg.active && (reg.installing || reg.waiting)) {\n // No active web worker and we have installed or are installing\n // one for the first time. Simply wait for it to activate.\n waitForActivation(reg.installing ?? reg.waiting);\n } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {\n // When the app updates the serviceWorkerVersion changes, so we\n // need to ask the service worker to update.\n console.log('New service worker available.');\n reg.update();\n waitForActivation(reg.installing);\n } else {\n // Existing service worker is still good.\n console.log('Loading app from service worker.');\n loadMainDartJs();\n }\n });\n\n // If service worker doesn't succeed in a reasonable amount of time,\n // fallback to plaint <script> tag.\n setTimeout(() => {\n if (!scriptLoaded) {\n console.warn(\n 'Failed to load app from service worker. Falling back to plain <script> tag.',\n );\n loadMainDartJs();\n }\n }, 4000);\n });\n } else {\n // Service workers not supported. Just drop the <script> tag.\n loadMainDartJs();\n }\n </script>\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17565149/" ]
74,305,253
<p>I try to make parent div - background color, rounded corners and overflow hidden, put inside child div with background color, but I see small gap of parent color. How can it be and how to fix this? the main task is not to change the HTML</p> <p><a href="https://i.stack.imgur.com/V8xK5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V8xK5.jpg" alt="enter image description here" /></a></p> <p>here code <a href="https://codepen.io/batareika007/pen/ZERWmBM" rel="nofollow noreferrer">https://codepen.io/batareika007/pen/ZERWmBM</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-css lang-css prettyprint-override"><code>.container { max-width: 300px; margin: 0 auto; } .parent { width: 100%; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; border-radius: 1rem; height: 100px; background: red; } .child { padding: 1rem; height: 50px; background: rgb(230, 230, 230); /* if you make background white, you see the gap more clearly */ /* background: white; */ }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt; &lt;div class="parent"&gt; &lt;div class="child"&gt;some content here&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>tried position, z-index, play with the borders...</p>
[ { "answer_id": 74345472, "author": "egonzal", "author_id": 1243052, "author_profile": "https://Stackoverflow.com/users/1243052", "pm_score": 0, "selected": false, "text": "flutter build web\n" }, { "answer_id": 74350697, "author": "Jonas", "author_id": 9547658, "author_profile": "https://Stackoverflow.com/users/9547658", "pm_score": 2, "selected": true, "text": " var serviceWorkerVersion = null;\n var scriptLoaded = false;\n function loadMainDartJs() {\n if (scriptLoaded) {\n return;\n }\n scriptLoaded = true;\n var scriptTag = document.createElement('script');\n scriptTag.src = 'main.dart.js';\n scriptTag.type = 'application/javascript';\n document.body.append(scriptTag);\n }\n\n if ('serviceWorker' in navigator) {\n // Service workers are supported. Use them.\n window.addEventListener('load', function () {\n // Wait for registration to finish before dropping the <script> tag.\n // Otherwise, the browser will load the script multiple times,\n // potentially different versions.\n var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;\n navigator.serviceWorker.register(serviceWorkerUrl)\n .then((reg) => {\n function waitForActivation(serviceWorker) {\n serviceWorker.addEventListener('statechange', () => {\n if (serviceWorker.state == 'activated') {\n console.log('Installed new service worker.');\n loadMainDartJs();\n }\n });\n }\n if (!reg.active && (reg.installing || reg.waiting)) {\n // No active web worker and we have installed or are installing\n // one for the first time. Simply wait for it to activate.\n waitForActivation(reg.installing ?? reg.waiting);\n } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {\n // When the app updates the serviceWorkerVersion changes, so we\n // need to ask the service worker to update.\n console.log('New service worker available.');\n reg.update();\n waitForActivation(reg.installing);\n } else {\n // Existing service worker is still good.\n console.log('Loading app from service worker.');\n loadMainDartJs();\n }\n });\n\n // If service worker doesn't succeed in a reasonable amount of time,\n // fallback to plaint <script> tag.\n setTimeout(() => {\n if (!scriptLoaded) {\n console.warn(\n 'Failed to load app from service worker. Falling back to plain <script> tag.',\n );\n loadMainDartJs();\n }\n }, 4000);\n });\n } else {\n // Service workers not supported. Just drop the <script> tag.\n loadMainDartJs();\n }\n </script>\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12063691/" ]
74,305,266
<p>I am trying to change odd elements in a list of int to negative using slicing</p> <pre><code>l[1::2] = -1 * l[1::2] </code></pre> <p>However, I encounter the following error:</p> <pre class="lang-none prettyprint-override"><code>ValueError: attempt to assign sequence of size 0 to extended slice of size 2 </code></pre>
[ { "answer_id": 74305331, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": -1, "selected": false, "text": "import numpy as np\n\n# vectorized\na = np.arange(10)\na[1::2] *= -1\nprint(a)\n# >>> [ 0 -1 2 -3 4 -5 6 -7 8 -9]\n\na = [i for i in range(10)]\na = [i if i%2==0 else i*-1 for i in a] # need to loop through list again..\nprint(a)\n# >>> [0, -1, 2, -3, 4, -5, 6, -7, 8, -9]\n" }, { "answer_id": 74305345, "author": "Chris", "author_id": 15261315, "author_profile": "https://Stackoverflow.com/users/15261315", "pm_score": 3, "selected": true, "text": ">>> a = [1,4,7,8,2]\n>>> a[1::2] = [-x for x in a[1::2]]\n>>> a\n[1, -4, 7, -8, 2]\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20250841/" ]
74,305,328
<p>I have create two JSP page one opens in IE and another opens in EDGE within same application.</p> <p>How can i share data from One JSP page to another i have tried below but when i try to <code>getAttribute()</code> it return null.</p> <p><strong>JSP A:</strong></p> <pre><code>&lt;% HttpSession sess = request.getSession(true); sess.setAttribute(&quot;firstName&quot;, 100); %&gt; </code></pre> <p><strong>JSP B:</strong></p> <pre><code>var firstName = &lt;%=session.getAttribute(&quot;firstName&quot;)%&gt; </code></pre>
[ { "answer_id": 74305724, "author": "Big Zed", "author_id": 10865170, "author_profile": "https://Stackoverflow.com/users/10865170", "pm_score": 2, "selected": true, "text": "application scope" }, { "answer_id": 74316613, "author": "Roman C", "author_id": 573032, "author_profile": "https://Stackoverflow.com/users/573032", "pm_score": 0, "selected": false, "text": "session" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14688156/" ]
74,305,358
<p>Why is it that the following does not work</p> <pre><code> whichLibrary == undefined || &quot;&quot; ? whichLibrary = bookData : continue; </code></pre> <p>but the following does?</p> <pre><code> whichLibrary == undefined || &quot;&quot; ? whichLibrary = bookData : console.log(`Do nothing.`); </code></pre> <p>Don't they effectively do the same thing? Is there something special about the Ternary operator, or the 'continue' keyword that I don't understand?</p>
[ { "answer_id": 74305724, "author": "Big Zed", "author_id": 10865170, "author_profile": "https://Stackoverflow.com/users/10865170", "pm_score": 2, "selected": true, "text": "application scope" }, { "answer_id": 74316613, "author": "Roman C", "author_id": 573032, "author_profile": "https://Stackoverflow.com/users/573032", "pm_score": 0, "selected": false, "text": "session" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18206695/" ]
74,305,385
<p>this is my first question in stackoverflow. I am making my very first page, where I apply Javascript. I have a little score keeper. Every player has their own score counting and button. Before beginning you can select what you want to play up to. My problem is when counting is over (one player won) buttons has to be disabled, but they disable only after extra one click on them. I don`t understand why. This is my HTML:</p> <pre><code>&lt;div class=&quot;main-info&quot;&gt; &lt;div class=&quot;text&quot;&gt; &lt;h1&gt; &lt;span id=&quot;firstScore&quot;&gt;0&lt;/span&gt; to &lt;span id=&quot;secondScore&quot;&gt;0&lt;/span&gt;&lt;/h1&gt; &lt;/div&gt; &lt;div class=&quot;choose&quot;&gt; &lt;label for=&quot;choose-score&quot;&gt;Playing to&lt;/label&gt; &lt;select name=&quot;score&quot; id=&quot;score&quot;&gt; &lt;option value=&quot;5&quot;&gt;5&lt;/option&gt; &lt;option value=&quot;6&quot;&gt;6&lt;/option&gt; &lt;option value=&quot;7&quot;&gt;7&lt;/option&gt; &lt;option value=&quot;8&quot;&gt;8&lt;/option&gt; &lt;option value=&quot;9&quot;&gt;9&lt;/option&gt; &lt;option value=&quot;10&quot;&gt;10&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;button class=&quot;buttonOne&quot; role=&quot;button&quot;&quot;&gt;+1 Player One&lt;/button&gt; &lt;button class=&quot;buttonTwo&quot;&gt;+1 Player Two&lt;/button&gt; &lt;button class=&quot;reset&quot;&gt;Reset&lt;/button&gt; &lt;/div&gt; </code></pre> <p>This is my Javascript:</p> <pre><code>const firstPlayer = document.querySelector(&quot;.buttonOne&quot;); const firstScore = document.querySelector(&quot;#firstScore&quot;); const secondButton = document.querySelector(&quot;.buttonTwo&quot;); const chooseScore = document.querySelector(&quot;#score&quot;); const secondScore = document.querySelector(&quot;#secondScore&quot;); let scoreOne = 0; firstPlayer.addEventListener(&quot;click&quot;, function (e) { if (scoreOne &lt; chooseScore.value) { scoreOne = scoreOne + 1; } else { firstPlayer.disabled = true; secondButton.disabled = true; } firstScore.innerText = `${scoreOne}`; console.log(`this is score of First Player ${scoreOne}`); }); let scoreTwo = 0; secondButton.addEventListener(&quot;click&quot;, function (e) { if (scoreTwo &lt; chooseScore.value) { scoreTwo = scoreTwo + 1; } else { firstPlayer.disabled = true; secondButton.disabled = true; } secondScore.innerText = `${scoreTwo}`; }); </code></pre> <p>I tried to write conditions in another ways: without else, make new one, tried switch, starting count from 1 or -1, and in condition written</p> <pre><code>if (scoreTwo &lt; chooseScore.value - 1) </code></pre> <p>or chooseScore.value +1 But it doesn`t work. This is my first try and I hope you will help me with my issue. Thank you very much.</p>
[ { "answer_id": 74305724, "author": "Big Zed", "author_id": 10865170, "author_profile": "https://Stackoverflow.com/users/10865170", "pm_score": 2, "selected": true, "text": "application scope" }, { "answer_id": 74316613, "author": "Roman C", "author_id": 573032, "author_profile": "https://Stackoverflow.com/users/573032", "pm_score": 0, "selected": false, "text": "session" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408980/" ]
74,305,406
<p>I have a computationally expensive vector I want to index into inside a function, but since the table is never used anywhere else, I don't want to pass the vector around, but access the precomputed values like a memoized function.</p> <p>The idea is:</p> <pre><code>cachedFunction :: Int -&gt; Int cachedFunction ix = table ! ix where table = &lt;vector creation&gt; </code></pre> <p>One aspect I've noticed is that all memoization examples I've seen deal with recursion, where even if a table is used to memoize, values in the table depend on other values in the table. This is not in my case, where computed values are found using a trial-and-error approach but each element is independent from another.</p> <p>How do I achieve the cached table in the function?</p>
[ { "answer_id": 74305621, "author": "Silvio Mayolo", "author_id": 2288659, "author_profile": "https://Stackoverflow.com/users/2288659", "pm_score": 2, "selected": false, "text": "table" }, { "answer_id": 74307489, "author": "leftaroundabout", "author_id": 745903, "author_profile": "https://Stackoverflow.com/users/745903", "pm_score": 4, "selected": true, "text": " ┌────────────────────────────────┐\ncachedFunction ix = │ table ! ix │\n │where table = <vector creation> │\n └────────────────────────────────┘\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
74,305,423
<p>I am trying to do this without else in dart <code>isUser == true &amp;&amp; Text(&quot;hello&quot;) </code> but this gives me an error while if I do that in react native it works any help</p>
[ { "answer_id": 74305621, "author": "Silvio Mayolo", "author_id": 2288659, "author_profile": "https://Stackoverflow.com/users/2288659", "pm_score": 2, "selected": false, "text": "table" }, { "answer_id": 74307489, "author": "leftaroundabout", "author_id": 745903, "author_profile": "https://Stackoverflow.com/users/745903", "pm_score": 4, "selected": true, "text": " ┌────────────────────────────────┐\ncachedFunction ix = │ table ! ix │\n │where table = <vector creation> │\n └────────────────────────────────┘\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20059879/" ]
74,305,437
<p>I have a structure that consists of a list of lists. I would like to convert it to a dictionary where the array of size one are the keys and the subsequent items in the array where array are size 2 are the key - value of the key. Every item in the array of size 1 will be a new key.</p> <p>For example:</p> <p>list of lists:</p> <pre class="lang-json prettyprint-override"><code>[ [ &quot;key1&quot; ], [ &quot;name1&quot;, &quot;value1&quot; ], [ &quot;name2&quot;, &quot;value2&quot; ], [ &quot;key2&quot; ], [ &quot;name1&quot;, &quot;value1&quot; ], [ &quot;name2&quot;, &quot;value2&quot; ], [ &quot;key3&quot; ], [ &quot;name1&quot;, &quot;value1&quot; ], [ &quot;name2&quot;, &quot;value2&quot; ], [ &quot;key4&quot; ], [ &quot;name1&quot;, &quot;value1&quot; ], [ &quot;name2&quot;, &quot;value2&quot; ] ] </code></pre> <p>desired dictionary conversion:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;key1&quot;: { &quot;name1&quot;: &quot;value1&quot;, &quot;name2&quot;: &quot;value2&quot; }, &quot;key2&quot;: { &quot;name1&quot;: &quot;value1&quot;, &quot;name2&quot;: &quot;value2&quot; }, &quot;key3&quot;: { &quot;name1&quot;: &quot;value1&quot;, &quot;name2&quot;: &quot;value2&quot; }, &quot;key4&quot;: { &quot;name1&quot;: &quot;value1&quot;, &quot;name2&quot;: &quot;value2&quot; } } </code></pre>
[ { "answer_id": 74305621, "author": "Silvio Mayolo", "author_id": 2288659, "author_profile": "https://Stackoverflow.com/users/2288659", "pm_score": 2, "selected": false, "text": "table" }, { "answer_id": 74307489, "author": "leftaroundabout", "author_id": 745903, "author_profile": "https://Stackoverflow.com/users/745903", "pm_score": 4, "selected": true, "text": " ┌────────────────────────────────┐\ncachedFunction ix = │ table ! ix │\n │where table = <vector creation> │\n └────────────────────────────────┘\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/843796/" ]
74,305,444
<p>While trying to run the <code>corr()</code> method in python using pandas module, I get the following error:</p> <pre><code>FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning. print(df.corr()) </code></pre> <p><strong>Note</strong> (Just for clarification) :- <code>df</code> is the name of the dataframe read from a <code>csv</code>file.</p> <p>For eg:-</p> <pre><code>import pandas as pd df = pd.read_csv('Data.csv') print(df.corr()) </code></pre> <p>The problem <strong>only</strong> lies in the <code>corr()</code> method which raises the aforementioned error:</p> <pre><code>FutureWarning: The default value of numeric_only in DataFrame.corr is deprecated. In a future version, it will default to False. Select only valid columns or specify the value of numeric_only to silence this warning. </code></pre> <p>I partially understand the error, however I would like to know:</p> <blockquote> <p>Are there any other alternative methods to do the same function of <code>corr()</code> to identify the relationship between each column in a data set? Like is there a way to replicate the function without using <code>corr()</code> method?</p> </blockquote> <p>Sorry If my question is wrong or improper in anyway, I'm open to feedbacks.</p> <p>Thanks in advance.</p>
[ { "answer_id": 74305621, "author": "Silvio Mayolo", "author_id": 2288659, "author_profile": "https://Stackoverflow.com/users/2288659", "pm_score": 2, "selected": false, "text": "table" }, { "answer_id": 74307489, "author": "leftaroundabout", "author_id": 745903, "author_profile": "https://Stackoverflow.com/users/745903", "pm_score": 4, "selected": true, "text": " ┌────────────────────────────────┐\ncachedFunction ix = │ table ! ix │\n │where table = <vector creation> │\n └────────────────────────────────┘\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20177248/" ]
74,305,463
<p>I want to write a file to a GCS bucket. The bucket path and file name are dynamically provided in two different pipeline options. How can I concatenate those in TextIO to write the file to the GCS bucket.</p> <p>I tried doing this but no luck.</p> <pre><code>o.apply(&quot;Test:&quot;,TextIO.write() .to(options.getBucktName().toString()+options.getOutName().toString())); </code></pre> <p>where getOutName = test.txt and getBucktName = gs://bucket</p> <p>Edit: Options are ValueProvider</p>
[ { "answer_id": 74305928, "author": "Jeff Klukas", "author_id": 1260237, "author_profile": "https://Stackoverflow.com/users/1260237", "pm_score": 1, "selected": false, "text": "ValueProvider" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4276579/" ]
74,305,491
<p>I'm trying to create an array that repeats a sequence of numbers 'X' times. Here's what I have so far. (Avoiding VBA).</p> <p><code>=VSTACK(SEQUENCE(C1,1), SEQUENCE(C1,1))</code></p> <p>To which I get:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Column A</th> <th>B (times)</th> <th>C (rows)</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>2</td> <td></td> <td></td> </tr> <tr> <td>3</td> <td></td> <td></td> </tr> <tr> <td>1</td> <td></td> <td></td> </tr> <tr> <td>2</td> <td></td> <td></td> </tr> <tr> <td>3</td> <td></td> <td></td> </tr> </tbody> </table> </div> <p>But how do I repeat <code>SEQUENCE(C1,1) </code> 'X' times inside <code>VSTACK</code> based on what is inside B2?</p> <p>I've thought about <code>REPT</code>, but that only works for strings</p> <p>Thank you!</p>
[ { "answer_id": 74305799, "author": "Rory", "author_id": 3611989, "author_profile": "https://Stackoverflow.com/users/3611989", "pm_score": 4, "selected": true, "text": "=tocol(mod(sequence(c1,b1)-1,c1)+1)\n" }, { "answer_id": 74305839, "author": "Ike", "author_id": 16578424, "author_profile": "https://Stackoverflow.com/users/16578424", "pm_score": 2, "selected": false, "text": "=MAP(SEQUENCE(B1*C1,1,0,1),LAMBDA(a,MOD(a,C1)+1))" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19679063/" ]
74,305,551
<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>let temp = null let str = `${temp} === null ? null : "${temp}" ` console.log(str)</code></pre> </div> </div> </p> <p>my requirement is , i want to print just null with out double quotes if the temp value is null. where as i want to print the string with double quotes if there is any value assigned to temp</p> <h2>updated question:</h2> <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>let name = null let age = 20 let str = ` name : ${name === null ? null : name}, age : "${age}"` ` console.log(str)</code></pre> </div> </div> </p> <p>I have a 20 values like these to copmare and insert in the string literal ,so instead of comparing outside , am looking for a solution with in the string literal</p>
[ { "answer_id": 74305610, "author": "hackape", "author_id": 3617380, "author_profile": "https://Stackoverflow.com/users/3617380", "pm_score": 2, "selected": true, "text": "let temp = null\n\nlet str = `${temp === null ? null : `\"${temp}\"`}`\n\nconsole.log(str)" }, { "answer_id": 74305631, "author": "Ashish S", "author_id": 6012711, "author_profile": "https://Stackoverflow.com/users/6012711", "pm_score": 0, "selected": false, "text": "let temp = 'a'\n\nlet str = `${temp === null ? \"null\" : temp}`\n\nconsole.log(str)\n" }, { "answer_id": 74305940, "author": "Aardvark Pepper", "author_id": 19894082, "author_profile": "https://Stackoverflow.com/users/19894082", "pm_score": 0, "selected": false, "text": "let name = null;\nlet age = 20;\n\nlet str = ` name : \"${name === null ? null : name}\", age : \"${age}\"``;\n\nconsole.log(str);\n" }, { "answer_id": 74306593, "author": "Mulan", "author_id": 633183, "author_profile": "https://Stackoverflow.com/users/633183", "pm_score": 1, "selected": false, "text": "JSON.stringify" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8208248/" ]
74,305,574
<p>I want to check the relation between two columns in my data frame and extract the last element that satisfy a certain relation.</p> <pre><code>t x y 1.5 875 450 1.3 460 232 1.1 225 125 1.7 1725 900 1.6 720 460 2.0 22 14 1.7 775 450 1.5 880 450 2.4 870 455 1.1 425 220 1.8 1750 910 1.3 560 320 1.3 430 232 2.1 3090 1840 2.0 1750 7950 1.7 170 895 1.1 350 220 1.2 80 45 1.8 169 880 1.7 1700 900 1.9 230 130 2.1 540 237 0.8 50 28 </code></pre> <p>so i am looking to extract the last y point that satisfy: <code>y &gt;= 0.45 x </code>. The problem is that <code>y</code>will keep taking different values and i want to extract only the last y value higher or equal to 0.45 x.</p> <p>Thank you for your help</p>
[ { "answer_id": 74305610, "author": "hackape", "author_id": 3617380, "author_profile": "https://Stackoverflow.com/users/3617380", "pm_score": 2, "selected": true, "text": "let temp = null\n\nlet str = `${temp === null ? null : `\"${temp}\"`}`\n\nconsole.log(str)" }, { "answer_id": 74305631, "author": "Ashish S", "author_id": 6012711, "author_profile": "https://Stackoverflow.com/users/6012711", "pm_score": 0, "selected": false, "text": "let temp = 'a'\n\nlet str = `${temp === null ? \"null\" : temp}`\n\nconsole.log(str)\n" }, { "answer_id": 74305940, "author": "Aardvark Pepper", "author_id": 19894082, "author_profile": "https://Stackoverflow.com/users/19894082", "pm_score": 0, "selected": false, "text": "let name = null;\nlet age = 20;\n\nlet str = ` name : \"${name === null ? null : name}\", age : \"${age}\"``;\n\nconsole.log(str);\n" }, { "answer_id": 74306593, "author": "Mulan", "author_id": 633183, "author_profile": "https://Stackoverflow.com/users/633183", "pm_score": 1, "selected": false, "text": "JSON.stringify" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17220976/" ]
74,305,598
<p>In a browser there's often arrow buttons that go forward and backward in history:</p> <p><a href="https://i.stack.imgur.com/8Nn3H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Nn3H.png" alt="enter image description here" /></a></p> <p>Can these buttons be clicked on via playwright?</p> <p>There's no elements for them so I was wondering if this is possible...</p> <pre class="lang-js prettyprint-override"><code>await navigationObject(page).backButton.click(); </code></pre>
[ { "answer_id": 74305815, "author": "joshua miller", "author_id": 7739392, "author_profile": "https://Stackoverflow.com/users/7739392", "pm_score": 0, "selected": false, "text": "window.history.back()\n" }, { "answer_id": 74307847, "author": "Jaky Ruby", "author_id": 10050775, "author_profile": "https://Stackoverflow.com/users/10050775", "pm_score": 2, "selected": false, "text": "await page.goBack()\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305598", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20409332/" ]
74,305,611
<p>I have produced a table which shows the number of different people in each income group form a data table, I would like to produce a column which shows this as a percentage.</p> <p>This is my current code that produces a table with a column with the number of people in each income group</p> <pre><code>ind_and_countries %&gt;% group_by(Income_Group)%&gt;% summarise(Number = n())%&gt;% arrange(desc(Number)) </code></pre> <p>I have tried using mutate(Percentage = Number/colSums(Number)*100) I think the issue is when I need to divide by the total number and can't seem to get this to work.</p>
[ { "answer_id": 74305815, "author": "joshua miller", "author_id": 7739392, "author_profile": "https://Stackoverflow.com/users/7739392", "pm_score": 0, "selected": false, "text": "window.history.back()\n" }, { "answer_id": 74307847, "author": "Jaky Ruby", "author_id": 10050775, "author_profile": "https://Stackoverflow.com/users/10050775", "pm_score": 2, "selected": false, "text": "await page.goBack()\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20294969/" ]
74,305,636
<p>I am trying to run a script (unitest) that uses docker behind the scenes on a CI. The script works as expected on droneci but switching to CloudBuild it is not clear how to setup DinD.</p> <p>For the droneci I basically use the DinD as shown <a href="https://docs.drone.io/pipeline/docker/examples/services/docker_dind/" rel="nofollow noreferrer">here</a> my question is, how do I translate the code to Google CloudBuild. Is it even possible?</p> <p>I searched the internet for the syntax of CloudBuild wrt DinD and couldn't find something.</p>
[ { "answer_id": 74305815, "author": "joshua miller", "author_id": 7739392, "author_profile": "https://Stackoverflow.com/users/7739392", "pm_score": 0, "selected": false, "text": "window.history.back()\n" }, { "answer_id": 74307847, "author": "Jaky Ruby", "author_id": 10050775, "author_profile": "https://Stackoverflow.com/users/10050775", "pm_score": 2, "selected": false, "text": "await page.goBack()\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3210972/" ]
74,305,646
<p>I am getting an error like this:</p> <blockquote> <p>Because every version of flutter from sdk depends on collection 1.16.0 and syncfusion_flutter_datagrid &gt;=19.1.54-beta &lt;20.1.48 depends on collection &gt;=1.9.0 &lt;=1.15.0, flutter from sdk is incompatible with syncfusion_flutter_datagrid &gt;=19.1.54-beta &lt;20.1.48. So, because datagrid_json_datasource depends on both flutter from sdk and syncfusion_flutter_datagrid ^19.1.65-beta, version solving failed.</p> </blockquote> <pre><code>pubspec.yaml: </code></pre> <pre><code>name: datagrid_json_datasource description: A new Flutter project. publish_to: 'none' version: 1.0.0+1 environment: sdk: &quot;&gt;=2.7.0 &lt;3.0.0&quot; dependencies: http: ^0.12.0 flutter: sdk: flutter intl: ^0.17.0 cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter syncfusion_flutter_datagrid: ^19.1.65-beta flutter: uses-material-design: true </code></pre> <p><a href="https://i.stack.imgur.com/skvSP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/skvSP.png" alt="i can not slove this error" /></a></p> <p>i try too chenge sdk version when i change to sdk version and also try flutter clean and flutter pub get.</p>
[ { "answer_id": 74305768, "author": "LacticWhale", "author_id": 11962301, "author_profile": "https://Stackoverflow.com/users/11962301", "pm_score": 3, "selected": true, "text": "syncfusion_flutter_datagrid" }, { "answer_id": 74306208, "author": "driosn", "author_id": 11405196, "author_profile": "https://Stackoverflow.com/users/11405196", "pm_score": 0, "selected": false, "text": "name: test_datasourcee\ndescription: A new Flutter project.\n\nversion: 1.0.0+1\n\nenvironment:\n sdk: \">=2.12.0 <3.0.0\"\n\ndependencies:\n flutter:\n sdk: flutter\n\n cupertino_icons: ^1.0.2\n\ndev_dependencies:\n flutter_test:\n sdk: flutter\n syncfusion_flutter_datagrid: ^19.1.65-beta\n\nflutter:\n uses-material-design: true\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16320782/" ]
74,305,690
<p>I have the next foreach:</p> <pre><code>foreach(json_decode($result[$k], &quot;true&quot;) as $result) { fputcsv($fp, $result); } </code></pre> <p>and if I put a var_dump of that result it will return a list of arrays like:</p> <pre><code> [&quot;Id&quot;]=&gt; string(7) &quot;1&quot; [&quot;Name&quot;]=&gt; string(29) &quot;Name&quot; [&quot;Description&quot;]=&gt; string(19) &quot;Description&quot; [&quot;Address&quot;]=&gt; string(27) &quot;Address&quot; [&quot;Schedule&quot;]=&gt; array(7) { [0]=&gt; array(2) { [&quot;startHour&quot;]=&gt; string(5) &quot;00:00&quot; [&quot;stopHour&quot;]=&gt; string(5) &quot;23:59&quot; } [1]=&gt; array(2) { [&quot;startHour&quot;]=&gt; string(5) &quot;00:00&quot; [&quot;stopHour&quot;]=&gt; string(5) &quot;23:59&quot; } [2]=&gt; array(2) { [&quot;startHour&quot;]=&gt; string(5) &quot;00:00&quot; [&quot;stopHour&quot;]=&gt; string(5) &quot;23:59&quot; } . . . } </code></pre> <p>If I put <code>fputcsv($fp, $result)</code> in that foreach loop, everything works good until Schedule. The line from csv looks like:</p> <pre><code>1, Name, Description, Address, Array. </code></pre> <p>But, what I want instead of &quot;Array&quot; I want something like</p> <pre><code>00:00-23:59. </code></pre> <p>Like:</p> <pre><code>1, Name, Description, Address, 00:00-23:59, 00:00-23:59, 00:00-23:59 </code></pre> <p>(for each day of the week). Can anyone help me with this? Thank you!</p>
[ { "answer_id": 74305889, "author": "Foobar", "author_id": 19625365, "author_profile": "https://Stackoverflow.com/users/19625365", "pm_score": 2, "selected": true, "text": "foreach" }, { "answer_id": 74306242, "author": "RiggsFolly", "author_id": 2310830, "author_profile": "https://Stackoverflow.com/users/2310830", "pm_score": 0, "selected": false, "text": "$json = \n[\n [\"Id\"=>\"1\", \"Name\"=>\"Name\", \"Description\"=>\"Description\",\"Address\"=> \"Address\",\n \"Schedule\" => [ [\"startHour\"=> \"00:00\", \"stopHour\"=> \"23:59\"],\n [\"startHour\"=> \"00:00\", \"stopHour\"=> \"23:59\"],\n [\"startHour\"=> \"00:00\", \"stopHour\"=> \"23:59\"]\n ]\n ],\n [\"Id\"=>\"2\", \"Name\"=>\"Fred\", \"Description\"=>\"Bloke\",\"Address\"=> \"1 main st\",\n \"Schedule\" => [ [\"startHour\"=> \"02:00\", \"stopHour\"=> \"20:59\"],\n [\"startHour\"=> \"03:00\", \"stopHour\"=> \"21:59\"],\n [\"startHour\"=> \"04:00\", \"stopHour\"=> \"22:59\"]\n ]\n ] \n];\n\n$fp = fopen('tst.csv', 'w');\nforeach($json as $result) {\n $t1 = [ $result['Id'], $result['Name'], $result['Description'], $result['Address'] ];\n // process the schedule array now seperately\n $t2 = [];\n foreach($result['Schedule'] as $sch){\n $t2[] = $sch['startHour'] . '-' . $sch['stopHour'];\n }\n fputcsv($fp, array_merge($t1,$t2));\n}\nfclose($fp);\n" }, { "answer_id": 74335813, "author": "Javohir Xoldorov", "author_id": 16870814, "author_profile": "https://Stackoverflow.com/users/16870814", "pm_score": 1, "selected": false, "text": "$result = [\n [\n \"Id\" => \"1\",\n \"Name\" => \"Name\",\n \"Description\" => \"Description\",\n \"Address\" => \"Address\",\n \"Schedule\" =>\n [\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\"\n ],\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\"\n ],\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\",\n ]\n ]\n ,\n\n ],\n [\n \"Id\" => \"2\",\n \"Name\" => \"Name2\",\n \"Description\" => \"Description\",\n \"Address\" => \"Address\",\n \"Schedule\" =>\n [\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\"\n ],\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\"\n ],\n [\n \"startHour\" => \"00:00\", \"stopHour\" => \"23:59\",\n ]\n ]\n ,\n\n ]\n ];\n $header = array('Tr', 'Name', 'Description', 'Address', 'Array.');\n\n\n $fp = fopen('test.csv', 'w');\n fputcsv($fp, $header);\n foreach ($result as $item) {\n $row = [];\n $row[] = $item['Id'];\n $row[] = $item['Name'];\n $row[] = $item['Description'];\n $row[] = $item['Address'];\n foreach ($item['Schedule'] as $value) {\n $row[] = $value['startHour'] . '-' . $value['stopHour'];\n }\n fputcsv($fp, $row);\n }\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19335780/" ]
74,305,694
<p>I have this question for a practice test in C that I don't understand. Show the output of the following program</p> <pre><code>x = y = 3; y = x++, x++; printf(&quot;x = %d, y = %d\n&quot;, x, y); </code></pre> <p>Answer: 1 x = 5, y = 3</p> <p>I dont understand what</p> <pre><code>x++, x++ </code></pre> <p>Does <code>x++</code> mean to implement the value of <code>x</code> into <code>y</code> then add one to it, but why is there a comma ? Would it just first add the value of <code>x</code> in <code>y</code>, and do <code>x=x+1</code> twice?</p> <p>I tried putting it in a compiler, found some struggles.</p>
[ { "answer_id": 74305962, "author": "EnMag", "author_id": 6134279, "author_profile": "https://Stackoverflow.com/users/6134279", "pm_score": 1, "selected": false, "text": "x" }, { "answer_id": 74306084, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 3, "selected": true, "text": "y = x++, x++;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20266245/" ]
74,305,702
<p>I have created a lambda function, that is extracting the audio stream from a video file using <code>ffmpeg</code>. I have also configured API gateway as a trigger, where I am passing the file to the lambda function in the request body.</p> <p>The lambda function is working perfectly well with small files, but with bigger files, it needs a bit more time and then I am running into the API gateway timeout, which according to my understanding is set to 29 seconds max.</p> <p>So when I trigger audio extraction from a bigger file, I am hitting this timeout and my API request fails to return any result even though the transcoding still runs in the background and the file is extracted, so I was wondering what is the best approach to handle those cases, where the execution of the lambda function is taking longer?</p> <p>I was thinking to start the transcoding in the background and simply return a JSON with a message that the transcoding might take a couple of minutes, depending on the input file duration, but if I try to push the <code>ffmpeg</code> to the background I am being presented with an error, that the destination file doesn't exist.</p> <pre class="lang-py prettyprint-override"><code>os.system(f&quot;{ffmpeg} -loglevel panic -nostdin -i {in_video} -vn -c:a aac -ar 48000 -b:a 192K {out_audio} 2&gt; /dev/null &amp;&quot;) </code></pre> <p>This is the <code>ffmpeg</code> command extracting the audio and transcoding it to AAC.</p> <p>If I remove the <code>2&gt; /dev/null &amp;</code> part of the command, it runs just fine, but if I keep it, I get an error:</p> <blockquote> <p>&quot;errorMessage&quot;: &quot;[Errno 2] No such file or directory: 'output_audio.aac'&quot;</p> </blockquote> <blockquote> <p>&quot;errorType&quot;: &quot;FileNotFoundError&quot;</p> </blockquote> <p>So I was wondering what is the preferred way to run processes in the background.</p>
[ { "answer_id": 74305962, "author": "EnMag", "author_id": 6134279, "author_profile": "https://Stackoverflow.com/users/6134279", "pm_score": 1, "selected": false, "text": "x" }, { "answer_id": 74306084, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 3, "selected": true, "text": "y = x++, x++;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7510925/" ]
74,305,714
<p>I have created model and using that model Im modify variable data at multiple places I can modify and enter data succesfully in FirstView. I could able to modify data in the SecondView. In SecondView, Whatever content I type in the textfield it goes away instanly (in short not allowing to enter data and ofc no error shown)</p> <p>I want to know am i using proper object variable to call model every time</p> <pre><code>class MainViewModel: ObservableObject { @Published var name = &quot;&quot; @Published var age = &quot;&quot; } // Using at one place struct FirstView : View { @StateObject var mainViewModel = MainViewModel() var body: some View { Form { TextField(&quot;&quot;, text: self.$MainViewModel.name) TextField(&quot;&quot;, text: self.$MainViewModel.age) } } } // ReUsing same at another place struct SecondView : View { @EnvironmentObject var mainViewModel = MainViewModel() var body: some View { Form { TextField(&quot;&quot;, text: self.$MainViewModel.name) TextField(&quot;&quot;, text: self.$MainViewModel.age) } } } </code></pre> <p>I have tried using @EnvironmentObject using at both view but doesnt work either here</p>
[ { "answer_id": 74305962, "author": "EnMag", "author_id": 6134279, "author_profile": "https://Stackoverflow.com/users/6134279", "pm_score": 1, "selected": false, "text": "x" }, { "answer_id": 74306084, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 3, "selected": true, "text": "y = x++, x++;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17138075/" ]
74,305,718
<p>I've browsed a few answers but haven't found the exact thing i'm looking for yet.</p> <p>I have a pandas dataframe with a single column structured as follows (example)</p> <pre><code>0 alex 1 7 2 female 3 nora 4 3 5 female ... 999 fred 1000 15 1001 male </code></pre> <p>i want to split that single column into 3 columns holding name, age, and gender. to look something like this:</p> <pre><code> name age gender 0 alex 7 female 1 nora 3 female ... 100 fred 15 male </code></pre> <p>is there a way to do this? i was thinking about using the index but not sure how to actually do it</p>
[ { "answer_id": 74305874, "author": "Vincent Rupp", "author_id": 4024409, "author_profile": "https://Stackoverflow.com/users/4024409", "pm_score": 3, "selected": true, "text": "pd.concat()" }, { "answer_id": 74306028, "author": "Chrysophylaxs", "author_id": 9499196, "author_profile": "https://Stackoverflow.com/users/9499196", "pm_score": 0, "selected": false, "text": "unstack" }, { "answer_id": 74306081, "author": "batelme", "author_id": 7916316, "author_profile": "https://Stackoverflow.com/users/7916316", "pm_score": 2, "selected": false, "text": "list_a = list(df[0])\na = np.array(list_a).reshape(-1, 3).tolist()\ndf2= pd.DataFrame(a,columns = [\"name\", \"age\",\"gender\"])\n" }, { "answer_id": 74306085, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# step through the DF and get values for name, age and gender as series\n# each starts from 0, 1 and 3\n\nname=df['Value'][::3].values\nage=df['Value'][1::3].values\ngender=df['Value'][2::3].values\n\n# create a DF based on the values\nout=pd.DataFrame({'name': name,\n 'age' : age,\n 'gender': gender})\nout\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17555222/" ]
74,305,720
<blockquote> <p>I am trying to create AWS API gateway with AWS service integration with cloudwatch using AWS cdk/ cloudformation. But I am getting errors like &quot;AWS service of type cloudwatch not supported&quot;. When I try to use Cloud watch log then it works but not for only cloudwatch.</p> </blockquote> <pre><code>Code new AwsIntegrationProps { Region = copilotFoundationalInfrastructure.Region, Options = new IntegrationOptions { PassthroughBehavior = PassthroughBehavior.WHEN_NO_TEMPLATES, CredentialsRole = Role.FromRoleArn(this,&quot;CloudWatchAccessRole&quot;, &quot;arn:aws:iam::800524210815:role/APIGatewayCloudWatchRole&quot;), RequestParameters = new Dictionary\&lt;string, string\&gt;() { { &quot;integration.request.header.Content-Encoding&quot;, &quot;'amz-1.0'&quot; }, { &quot;integration.request.header.Content-Type&quot;, &quot;'application/json'&quot; }, { &quot;integration.request.header.X-Amz-Target&quot;, &quot;'GraniteServiceVersion20100801.PutMetricData'&quot; }, }, }, IntegrationHttpMethod = &quot;POST&quot;, Service = &quot;cloudwatch&quot;, // this is working with s3 and logs Action = &quot;PutMetricData&quot; } </code></pre> <p>What is the correct service name for cloudwatch to putmetricsdata?</p> <pre><code>new AwsIntegrationProps { Region = copilotFoundationalInfrastructure.Region, Options = new IntegrationOptions { PassthroughBehavior = PassthroughBehavior.WHEN_NO_TEMPLATES, CredentialsRole = Role.FromRoleArn(this,&quot;CloudWatchAccessRole&quot;, &quot;arn:aws:iam::800524210815:role/APIGatewayCloudWatchRole&quot;), RequestParameters = new Dictionary&lt;string, string&gt;() { { &quot;integration.request.header.Content-Encoding&quot;, &quot;'amz-1.0'&quot; }, { &quot;integration.request.header.Content-Type&quot;, &quot;'application/json'&quot; }, { &quot;integration.request.header.X-Amz-Target&quot;, &quot;'GraniteServiceVersion20100801.PutMetricData'&quot; }, }, }, IntegrationHttpMethod = &quot;POST&quot;, Service = &quot;&quot;, // What will be the correct value for cloudwatch Action = &quot;PutMetricData&quot; } </code></pre> <p>What will be the correct value for cloudwatch</p>
[ { "answer_id": 74305874, "author": "Vincent Rupp", "author_id": 4024409, "author_profile": "https://Stackoverflow.com/users/4024409", "pm_score": 3, "selected": true, "text": "pd.concat()" }, { "answer_id": 74306028, "author": "Chrysophylaxs", "author_id": 9499196, "author_profile": "https://Stackoverflow.com/users/9499196", "pm_score": 0, "selected": false, "text": "unstack" }, { "answer_id": 74306081, "author": "batelme", "author_id": 7916316, "author_profile": "https://Stackoverflow.com/users/7916316", "pm_score": 2, "selected": false, "text": "list_a = list(df[0])\na = np.array(list_a).reshape(-1, 3).tolist()\ndf2= pd.DataFrame(a,columns = [\"name\", \"age\",\"gender\"])\n" }, { "answer_id": 74306085, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# step through the DF and get values for name, age and gender as series\n# each starts from 0, 1 and 3\n\nname=df['Value'][::3].values\nage=df['Value'][1::3].values\ngender=df['Value'][2::3].values\n\n# create a DF based on the values\nout=pd.DataFrame({'name': name,\n 'age' : age,\n 'gender': gender})\nout\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20409333/" ]
74,305,758
<p>I'm trying to pull docker image from ECR and deploy it on ec2 instance. However it's throwing an error like</p> <pre><code>docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ======END====== err: invalid reference format 2022/11/03 15:31:54 Process exited with status 1 </code></pre> <p>My yml file is:</p> <pre><code>name: Docker Image CI on: push: branches: [ &quot;main&quot; ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.TF_USER_AWS_KEY }} aws-secret-access-key: ${{ secrets.TF_USER_AWS_SECRET }} aws-region: us-east-1 - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - name: Build, tag, and push image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: githubactions IMAGE_TAG: githubactions_image run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - name: Docker pull &amp; run from github uses: appleboy/ssh-action@master with: host: ec2-3-86-102-151.compute-1.amazonaws.com username: ec2-user key: ${{ secrets.ACTIONS_PRIVATE_KEY }} envs: GITHUB_SHA script: | docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG </code></pre> <p>I spent a lot of time and I can't really understand what's wrong. Any idea really appreciated.</p>
[ { "answer_id": 74305874, "author": "Vincent Rupp", "author_id": 4024409, "author_profile": "https://Stackoverflow.com/users/4024409", "pm_score": 3, "selected": true, "text": "pd.concat()" }, { "answer_id": 74306028, "author": "Chrysophylaxs", "author_id": 9499196, "author_profile": "https://Stackoverflow.com/users/9499196", "pm_score": 0, "selected": false, "text": "unstack" }, { "answer_id": 74306081, "author": "batelme", "author_id": 7916316, "author_profile": "https://Stackoverflow.com/users/7916316", "pm_score": 2, "selected": false, "text": "list_a = list(df[0])\na = np.array(list_a).reshape(-1, 3).tolist()\ndf2= pd.DataFrame(a,columns = [\"name\", \"age\",\"gender\"])\n" }, { "answer_id": 74306085, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 0, "selected": false, "text": "# step through the DF and get values for name, age and gender as series\n# each starts from 0, 1 and 3\n\nname=df['Value'][::3].values\nage=df['Value'][1::3].values\ngender=df['Value'][2::3].values\n\n# create a DF based on the values\nout=pd.DataFrame({'name': name,\n 'age' : age,\n 'gender': gender})\nout\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20087946/" ]
74,305,774
<p>I have the following vector:</p> <pre><code>c(&quot;c(`Kruskal-Wallis chi-squared` = 201.760850624131)&quot;, &quot;c(df = 17)&quot;, &quot;1.26686891197831e-33&quot;, &quot;Kruskal-Wallis rank sum test&quot;, &quot;delta_Z by criteria&quot; ) </code></pre> <p>I desired this output:</p> <pre><code>c(&quot;201.760850624131&quot;, &quot;17&quot;, &quot;1.26686891197831e-33&quot;) </code></pre> <p>Thanks for any help</p>
[ { "answer_id": 74305790, "author": "akrun", "author_id": 3732271, "author_profile": "https://Stackoverflow.com/users/3732271", "pm_score": 3, "selected": true, "text": "str_extract" }, { "answer_id": 74305849, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 2, "selected": false, "text": "str_extract" }, { "answer_id": 74306002, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 2, "selected": false, "text": "x <- c(\"c(`Kruskal-Wallis chi-squared` = 201.760850624131)\", \"c(df = 17)\", \n\"1.26686891197831e-33\", \"Kruskal-Wallis rank sum test\", \"delta_Z by criteria\")\n\nas.character(sapply(sapply(x[1:3], str2lang, USE.NAMES = F), eval))\n\n#> [1] \"201.760850624131\" \"17\" \"1.26686891197831e-33\"\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9421846/" ]
74,305,786
<p>I would like to optimize the process when I match the elements between two arrays (each contains several thousand elements). If the match is found then we move on to the next element instead of continuing to search for another match (which does not exist because each element is unique).</p> <pre><code>$array1 = @(thousandItemsForExample) $array2 = @(thousandItemsForExample) foreach ($array1item in $array1) { $object = [PSCustomObject]@{ property1 = $array1item.property1 property2 = ($array1 | Where-Object { $_.property1 -eq $array2.property1 } | Select-Object property2).property2 } </code></pre> <p>I tried to find out if any of the comparison operators had this kind of option but I couldn't find anything.</p> <p>Thank you! :)</p> <p>PS : Sorry for my English, it's not my native language...</p>
[ { "answer_id": 74305843, "author": "Santiago Squarzon", "author_id": 15339544, "author_profile": "https://Stackoverflow.com/users/15339544", "pm_score": 2, "selected": false, "text": "Group-Object -AsHashtable" }, { "answer_id": 74305856, "author": "Mathias R. Jessen", "author_id": 712649, "author_profile": "https://Stackoverflow.com/users/712649", "pm_score": 1, "selected": false, "text": "$array2" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17862324/" ]
74,305,792
<p>So I'm looking to use a custom row cell to label my data.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Basketball</th> <th>Baseball</th> <th>Golf</th> <th>Cost</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>0</td> <td>0</td> <td>$50</td> </tr> <tr> <td>0</td> <td>1</td> <td>0</td> <td>$75</td> </tr> <tr> <td>1</td> <td>0</td> <td>1</td> <td>$150</td> </tr> <tr> <td>0</td> <td>1</td> <td>1</td> <td>$225</td> </tr> </tbody> </table> </div> <p>The table I have is above. What I'm trying to do is below:</p> <p>OUTPUT:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Sport</th> <th>Cost</th> </tr> </thead> <tbody> <tr> <td>Basketball</td> <td>200</td> </tr> <tr> <td>Baseball</td> <td>300</td> </tr> <tr> <td>Golf</td> <td>375</td> </tr> </tbody> </table> </div> <p>I can get the sum of each sport but I'm having trouble making an alias for each sport on the output table (The first column)</p> <p>How would I go about that? I've done an alias for a column header, but never for a row cell.</p> <p>Thanks in advance!</p>
[ { "answer_id": 74305867, "author": "a_horse_with_no_name", "author_id": 330315, "author_profile": "https://Stackoverflow.com/users/330315", "pm_score": 0, "selected": false, "text": "select sport, sum(cost)\nfrom \n( \n select 'Basketball' as sport, cost\n from the_table \n where basketball = 1\n union all\n select 'Baseball', cost\n from the_table \n where baseball = 1\n union all\n select 'Golf', cost\n from the_table \n where golf = 1\n) t\ngroup by sport;\n" }, { "answer_id": 74305999, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "select game\n ,sum(cost*flg) as cost\n \nfrom t \n cross join lateral (\n values \n (basketball, 'basketball')\n ,(baseball, 'baseball')\n ,(golf, 'golf')\n ) t2(flg, game)\ngroup by game\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74305792", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19621725/" ]