qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,449,660
<p>I'm trying to write code that makes a union between array a and b (AUB), but when I want to print the combined array. the console prints <code>System.Int32\[\]</code>.</p> <p>For context, if my</p> <pre><code>array a = { 1, 3, 5, 6 } </code></pre> <p>and my</p> <pre><code>array b = { 2, 3, 4, 5 } </code></pre> <p>my union array should be</p> <pre><code>combi = { 1, 2, 3, 4, 5, 6 } </code></pre> <p>but like I said, <code>combi</code> prints out as <code>System.Int32\[\]</code></p> <p>I don't know if it's the way I'm doing the union or if its the way I'm printing it. I'm also trying to do a</p> <ul> <li>A intersection B and A – B</li> </ul> <p>But I haven't tried anything of those yet, I would appreciate if you have any tips.</p> <pre><code>using System; using System.Reflection.Metadata.Ecma335; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine(&quot;size of A? &quot;); int a = Convert.ToInt32(Console.In.ReadLine()); Console.WriteLine(&quot;Value of A:&quot;); int[] ans = new int[a]; for (int i = 0; i &lt; ans.Length; i++) { ans[i] = Convert.ToInt32(Console.In.ReadLine()); } Console.WriteLine(&quot;size of B?&quot;); int b = Convert.ToInt32(Console.In.ReadLine()); Console.WriteLine(&quot;Value of B:&quot;); int[] anse = new int[b]; for (int i = 0; i &lt; anse.Length; i++) { anse[i] = Convert.ToInt32(Console.In.ReadLine()); } var combi = new int[ans.Length + anse.Length]; for (int i = 0; i &lt; combi.Length; i++) { Console.WriteLine(combi + &quot; &quot;); } Console.ReadLine(); } } } </code></pre>
[ { "answer_id": 74449714, "author": "Tim Schmelter", "author_id": 284240, "author_profile": "https://Stackoverflow.com/users/284240", "pm_score": 1, "selected": false, "text": "Console.Write(someObject)" }, { "answer_id": 74451307, "author": "Sumit Parmar", "author_id": 16420535, "author_profile": "https://Stackoverflow.com/users/16420535", "pm_score": 0, "selected": false, "text": " List<int> combi = new List<int>();\n\n foreach(var first in ans)\n {\n combi.Add(first);\n }\n foreach (var second in anse)\n {\n combi.Add(second);\n }\n combi.Sort(); \n string result = string.Join(\",\",combi);\n Console.WriteLine(result);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20114716/" ]
74,449,669
<p>I have installed nose2 with the following command:</p> <pre><code>pip3 install nose2 </code></pre> <p>And I have installed the coverage in the custom path with the following command:</p> <pre><code>pip3 install --target=/tmp/coverage_pkg coverage </code></pre> <p>I want to execute the test cases and generate the coverage report. Is there a way to map my coverage plugin installed in custom path to the nose2?</p> <p>I tried to execute the below command:</p> <pre><code>nose2 --with-coverage </code></pre> <p>I got the following output:</p> <pre><code>Warning: you need to install &quot;coverage_plugin&quot; extra requirements to use this plugin. e.g. `pip install nose2[coverage_plugin]` ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK </code></pre> <p>I want to generate the coverage report by using the coverage package installed in custom path.</p> <p>Can someone please explain if I can achieve this?</p>
[ { "answer_id": 74458666, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 0, "selected": false, "text": "pip install nose2[coverage_plugin]\n" }, { "answer_id": 74491372, "author": "Saif Baig", "author_id": 20471123, "author_profile": "https://Stackoverflow.com/users/20471123", "pm_score": 3, "selected": true, "text": "cd <custom location where packages are installed>\n\npython3 -m nose2 --with-coverage -s \"path_to_source_dir\" --coverage \"path_to_source_dir\"\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20471123/" ]
74,449,698
<p>im making a <em>guess number game</em> but i have a problem:In general, I would like to say how the process of the program is like this: the user first enters the number and clicks the registration option,The second user should try to guess what the number is in a specific number, but my problem is that if I want to create a while loop, it is not possible and it gives an error.</p> <pre><code>&gt;&gt; not supported between instances of 'Button' and 'int' py </code></pre> <p>my codes:</p> <pre><code>from tkinter import * win = False sum_1 = 0 def sumbit(): global asghar asghar = int(text.get()) text.pack_forget() sum_1.pack_forget() return asghar def gusses(): global sum_1 while sum_1 &gt; 10: a = int(text_1.get()) if a == asghar: win = True print(&quot;you win&quot;) break elif a &gt; asghar: print(&quot;number is higher&quot;) sum_1+= 1 elif a &lt; asghar: Label(app,text=&quot;number is lower&quot;).pack() sum_1+=1 app = Tk() sumbit app.minsize(300,300) text = Entry(app,font=20) text.pack() text_1 = Entry(app,font=20) text_1.pack() sum_1=Button(app,text=&quot;player 1 sumbit&quot;,font=20,command=sumbit) sum_1.pack() Button(app,text=&quot;gusses&quot;,font=20,command=gusses).pack() app.mainloop() </code></pre>
[ { "answer_id": 74449776, "author": "James_481", "author_id": 13633328, "author_profile": "https://Stackoverflow.com/users/13633328", "pm_score": 2, "selected": false, "text": "sum_1" }, { "answer_id": 74449850, "author": "Maximouse", "author_id": 10742758, "author_profile": "https://Stackoverflow.com/users/10742758", "pm_score": 2, "selected": false, "text": "sum_1" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20310213/" ]
74,449,717
<p>what is the best way to write this function without repeting some values and only add the needed value <strong>initialText</strong></p> <pre><code>createThread = () =&gt; { if (this.props.first) { publishLow = window.google.createPublish({ readId : this.props.readId }); } else { publishLow = window.google.createPublish({ readId : this.props.readId, // The value needed in this condition initialText : this.props.initialText }); } }; </code></pre>
[ { "answer_id": 74449771, "author": "Emanuele Scarabattoli", "author_id": 8534482, "author_profile": "https://Stackoverflow.com/users/8534482", "pm_score": 2, "selected": true, "text": "createThread = () => {\n const { readId, first, initialText } = this.props;\n const payload = { readId };\n if (!first) payload.initialText = initialText;\n publishLow = window.google.createPublish(payload);\n}\n" }, { "answer_id": 74449791, "author": "Alexander", "author_id": 6051057, "author_profile": "https://Stackoverflow.com/users/6051057", "pm_score": 0, "selected": false, "text": "createThread = () => {\n const arg = {\n readId : this.props.readId\n };\n if (!this.props.first) {\n arg[\"initialText\"] = this.props.initialText;\n }\n\n publishLow = window.google.createPublish(arg);\n};\n" }, { "answer_id": 74452837, "author": "ManuelMB", "author_id": 4191561, "author_profile": "https://Stackoverflow.com/users/4191561", "pm_score": 0, "selected": false, "text": "createThread = () => {\n const { readId, first, initialText } = this.props;\n const payload = first ? { readId } : { readId , initialText };\n publishLow = window.google.createPublish(payload);\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9179833/" ]
74,449,719
<p>I have several items in a list view which are same in size but I want to show one text button at the end, I want the splash of the text button, to limit only around the text like a normal button, but in this situation, the splash is becoming same as the height of other children. I have tried many things like wrapping the text inside <em>SizedBox</em>, <em>ConstrainedBox</em>, <em>Padding</em>, <em>Container</em>, but nothing worked. Please help me</p> <pre><code>SizedBox( height: 250, child: ListView.builder( padding: const EdgeInsets.symmetric(horizontal: 10), itemCount: products.length, scrollDirection: Axis.horizontal, shrinkWrap: true, itemBuilder: (_, index) { if (index == products.length - 1) { return ConstrainedBox( constraints: BoxConstraints(maxHeight: 40, minWidth: 100), child: TextButton( onPressed: () {}, child: Text('View All'), ), ); } return ProductWidget(product: products[index]); }, ), ), </code></pre> <p><a href="https://i.stack.imgur.com/ClFmm.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ClFmm.gif" alt="Current Situation" /></a></p> <blockquote> <p>This video is not showing the thing I want, the video is showing the problem, which I am facing</p> </blockquote>
[ { "answer_id": 74449758, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "Center(child:TextButton" }, { "answer_id": 74450231, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 0, "selected": false, "text": "TextButton" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14299072/" ]
74,449,733
<p>For some reason that is unknown to me, my GPA calculator only calculates the last input in the list, I only have 2 days left to complete this and hopefully i can in time.</p> <p>I tried to make it to where it calculates every input nd not just the last one, but i dont know how. here is my code:</p> <pre><code>name = input(&quot;What is your name? \n&quot;) h1 = (&quot;Class Name&quot;) h2 = (&quot;Class Grade&quot;) h3 = (&quot;Credit Hours&quot;) point = input(&quot;\nEnter your class name followed by your letter grade and hours (say Done to stop input):\n&quot;) class_data = [] while point != &quot;Done&quot;: words = point.split(&quot; &quot;) if len(words) == 1: print(&quot;Error: No spaces in string. Try again.&quot;) elif len(words) &gt; 4: print(&quot;Error: Too many spaces in input. Try again. &quot;) else: try: class_name = words[0] grades = (words[1]) hrs = int(words[2]) print(&quot;Name of class:&quot;, class_name) print(&quot;Grade:&quot;, grades) print(&quot;Class Hours:&quot;, hrs) class_data.append((class_name, grades, hrs,)) except ValueError: print(&quot;Error: Space not followed by an integer.&quot;) point = input(&quot;\nEnter your class name followed by your letter grade and hours (say Done to stop input):\n&quot;) def gpa_calculator(grades): points = 0 i = 0 grade_c = {&quot;A&quot;:4,&quot;A-&quot;:3.67,&quot;B+&quot;:3.33,&quot;B&quot;:3.0,&quot;B-&quot;:2.67, &quot;C+&quot;:2.33,&quot;C&quot;:2.0,&quot;C-&quot;:1.67,&quot;D+&quot;:1.33,&quot;D&quot;:1.0,&quot;F&quot;:0} if grades != class_data: for grade in grades: points += grade_c[grades] gpa = points / len(grades) return gpa else: return None print(&quot;Name: &quot;, name) print(&quot;-&quot; * 66) print(&quot;%-15s|%11s|%5s|&quot; % (h1, h2, h3)) print(&quot;-&quot; * 66) for item in class_data: print(&quot;%-15s|%11s|%12s|&quot; % (item[0], item[1], item[2])) print(&quot;-&quot; * 66) print('Your projected GPA is: ',(gpa_calculator(grades))) print(&quot;-&quot; * 66) </code></pre> <p>here is the output :</p> <pre><code>What is your name? John Smith Enter your class name followed by your letter grade and hours (say Done to stop input): poop D 50 Name of class: poop Grade: D Class Hours: 50 Enter your class name followed by your letter grade and hours (say Done to stop input): poop D 50poop D 50poop D 50 Error: Too many spaces in input. Try again. Enter your class name followed by your letter grade and hours (say Done to stop input): poop D 50 Name of class: poop Grade: D Class Hours: 50 Enter your class name followed by your letter grade and hours (say Done to stop input): poop D 50 Name of class: poop Grade: D Class Hours: 50 Enter your class name followed by your letter grade and hours (say Done to stop input): perfecgt A 1 Name of class: perfecgt Grade: A Class Hours: 1 Enter your class name followed by your letter grade and hours (say Done to stop input): Done Name: John Smith ------------------------------------------------------------------ Class Name |Class Grade|Credit Hours| ------------------------------------------------------------------ poop | D| 50| poop | D| 50| poop | D| 50| perfecgt | A| 1| ------------------------------------------------------------------ Your projected GPA is: 4.0 ------------------------------------------------------------------ </code></pre>
[ { "answer_id": 74449758, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "Center(child:TextButton" }, { "answer_id": 74450231, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 0, "selected": false, "text": "TextButton" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512546/" ]
74,449,764
<p>I use the following alias to show the git log:</p> <pre><code>[alias] ls = log --source --graph --pretty=format:'%C(yellow)%h %Creset[%ad] %s %C(green)[%an]%C(red)%d' </code></pre> <p>It's basically a modified version <code>git log --pretty=oneline</code>.</p> <pre><code>* b928fd3e7aef [2022-11-15] refactor: rename field of Definitions struct [Author Name] (HEAD -&gt; master, origin/master) * ecf0e00d0fc3 [2022-11-15] feat: deserialize definitions into a custom struct [Author Name] * 13651af5e52f [2022-11-15] refactor: change library name [Author Name] * 94f6694b43c2 [2022-11-15] feat: add func for making GET requests to api [Author Name] * adf64f3dc2a2 [2022-11-15] feat: add enum for representing operation types [Author Name] * 7df54e9305e7 [2022-11-15] feat: add struct to represent api [Author Name] * 3bde60087494 [2022-11-14] Initial commit [Author Name] </code></pre> <p>Since the log is shown in single line, it's unclear if a particular commit message spans over multiple lines. If an indicator of sorts marked that this commit has multi-line message, that would be perfect. I don't want to show the body of the commit message. I just want to show a marker <em>if</em> the body of the commit message is not empty.</p> <p>Something like this (note the emoji <code>^_^</code> acting as a marker at commit <code>13651af5e52f</code> which has a multi-line commit message):</p> <pre><code>* b928fd3e7aef [2022-11-15] refactor: rename field of Definitions struct [Author Name] (HEAD -&gt; master, origin/master) * ecf0e00d0fc3 [2022-11-15] feat: deserialize definitions into a custom struct [Author Name] * 13651af5e52f [2022-11-15] refactor: change library name [Author Name] ^_^ * 94f6694b43c2 [2022-11-15] feat: add func for making GET requests to api [Author Name] * adf64f3dc2a2 [2022-11-15] feat: add enum for representing operation types [Author Name] * 7df54e9305e7 [2022-11-15] feat: add struct to represent api [Author Name] * 3bde60087494 [2022-11-14] Initial commit [Author Name] </code></pre> <p>NOTE that by &quot;body&quot; I mean the parts of a commit message after the &quot;subject.&quot;</p>
[ { "answer_id": 74449846, "author": "Noscere", "author_id": 10728583, "author_profile": "https://Stackoverflow.com/users/10728583", "pm_score": -1, "selected": false, "text": "git log | grep ^_^" }, { "answer_id": 74527144, "author": "torek", "author_id": 1256452, "author_profile": "https://Stackoverflow.com/users/1256452", "pm_score": 2, "selected": true, "text": "git log" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11135136/" ]
74,449,778
<p>I am trying to make a sorting algorithm using python, but I am encountering a problem and I can't figure it out. I'll paste my code below.</p> <p>basic function:</p> <ul> <li>gets an array of numbers</li> <li>goes through and checks if a number is bigger than the next one</li> <li>if it is, swap it and set a variable to tell the function to run again at the end the numbers should be in ascending order</li> </ul> <pre><code>mainArr = [5, 2, 3, 6, 1, 4] def sort(): sorted = True tempVal = 0 for x in range(0, mainArr.len - 1): if mainArr[x] &gt; mainArr[x+1]: sorted = False tempVal = mainArr[x] mainArr[x] = mainArr[x+1] mainArr[x+1] = tempVal sorted = False print(mainArr) if not sorted: sort() print(&quot;\n\n&quot;) print(mainArr) </code></pre> <p>I have checked the code, but I think it needs a fresh set of eyes.</p>
[ { "answer_id": 74449856, "author": "James_481", "author_id": 13633328, "author_profile": "https://Stackoverflow.com/users/13633328", "pm_score": 0, "selected": false, "text": "mainArr.len" }, { "answer_id": 74449949, "author": "Samwise", "author_id": 3799759, "author_profile": "https://Stackoverflow.com/users/3799759", "pm_score": 2, "selected": true, "text": "sort()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512126/" ]
74,449,796
<p>I have a list associated to strings as follows;</p> <pre><code>A string1^description1`string2^description2`string3^description3 B string4^description4 C string1^description1`string5^description5`string3^description3 D . E string6^description6`string1^description1 F string7^description7 G string1^description1`string4^description4`string5^description5 </code></pre> <p>I would like to switch the first and second columns so that the stings in the 2nd column are the main list and the previous 1st column becomes the string as follows;</p> <pre><code>string1^description1 A C E G string2^description2 A string3^description3 A C string4^description4 B G string5^description5 C G string6^description6 E string7^description7 F </code></pre> <p>I have struggled with this and can't come up with anything. I am new to scripting.</p>
[ { "answer_id": 74449917, "author": "Jay", "author_id": 8677071, "author_profile": "https://Stackoverflow.com/users/8677071", "pm_score": 2, "selected": false, "text": "from collections import defaultdict\ndata = '''A string1^description1`string2^description2`string3^description3\nB string4^description4\nC string1^description1`string5^description5`string3^description3\nD .\nE string6^description6`string1^description1\nF string7^description7\nG string1^description1`string4^description4`string5^description5'''\n\nd = defaultdict(list)\nfor line in data.split('\\n'): # split the input data into lines\n char, info = line.split() # in each line get the char and info\n for desc in info.split('`'): # get the categories separated by `\n if len(desc) < 6: # avoid case like line D where there is no data\n continue\n d[desc].append(char)\n\nfor k, v in d.items():\n print(f\"{k} {' '.join(v)}\")\n\n" }, { "answer_id": 74450085, "author": "Arnaud Valmary", "author_id": 6255757, "author_profile": "https://Stackoverflow.com/users/6255757", "pm_score": 2, "selected": true, "text": "#! /usr/bin/env bash\n\nINPUT_FILE=\"$1\"\n\nawk \\\n'\nBEGIN {\n FS=\" \"\n}\n{\n key=$1\n $1=\"\"\n gsub(/^ */, \"\")\n n=split($0, a, /`/)\n for (i=1; i<=n; i++) {\n if (a[i] != \".\") {\n hash[a[i]]=hash[a[i]] \" \" key\n }\n }\n}\nEND {\n PROCINFO[\"sorted_in\"] = \"@ind_str_asc\"\n for (elem in hash) {\n print elem \" \" hash[elem]\n }\n}\n' \\\n< \"${INPUT_FILE}\"\n" }, { "answer_id": 74451303, "author": "Mark Reed", "author_id": 797049, "author_profile": "https://Stackoverflow.com/users/797049", "pm_score": 2, "selected": false, "text": "#!/usr/bin/env perl\nuse v5.10;\nmy %labels;\nwhile (<>) {\n chomp;\n my ($label, $rest) = split ' ',$_,2;\n foreach my $key (split '`', $rest) {\n push @{$labels{$key}}, $label unless $key eq '.'\n }\n}\n\nforeach my $key (sort keys %labels) {\n say \"$key\\t\", join(\"\\t\", @{$labels{$key}});\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449796", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6139282/" ]
74,449,831
<p>I am kind of new to Terraform and could you help me with the lists in terraform.</p> <p>This is my code</p> <pre><code>variable &quot;ip_bitbucket&quot; { type = &quot;list&quot; } </code></pre> <pre><code>ip_bitbucket = [&quot;34.199.54.113/32&quot;,&quot;34.232.25.90/32&quot;,&quot;34.232.119.183/32&quot;,&quot;34.236.25.177/32&quot;,&quot;35.171.175.212/32&quot;,&quot;52.54.90.98/32&quot;,&quot;52.202.195.162/32&quot;,&quot;52.203.14.55/32&quot;,&quot;52.204.96.37/32&quot;,&quot;34.218.156.209/32&quot;,&quot;34.218.168.212/32&quot;,&quot;52.41.219.63/32&quot;,&quot;35.155.178.254/32&quot;,&quot;35.160.177.10/32&quot;,&quot;34.216.18.129/32&quot;,&quot;3.216.235.48/32&quot;,&quot;34.231.96.243/32&quot;,&quot;44.199.3.254/32&quot;,&quot;174.129.205.191/32&quot;,&quot;44.199.127.226/32&quot;,&quot;44.199.45.64/32&quot;,&quot;3.221.151.112/32&quot;,&quot;52.205.184.192/32&quot;,&quot;52.72.137.240/32&quot;] </code></pre> <p>and need to access the list as below</p> <pre><code>resource &quot;aws_security_group_rule &quot;server_rule&quot; { type = &quot;ingress&quot; from_port = 443 to_port = 22 protocol = &quot;tcp&quot; # for each = var.ip_bitbucket cidr_blocks = security_group_id = data.aws_security_group.server_sg.id } </code></pre> <p>How do i access the variable <code>ip_bitbucket</code> in cidr block?</p> <p>I was trying with <code>count</code> and <code>element</code> but not getting clear idea</p>
[ { "answer_id": 74449903, "author": "Marko E", "author_id": 8343484, "author_profile": "https://Stackoverflow.com/users/8343484", "pm_score": 2, "selected": false, "text": "toset" }, { "answer_id": 74453848, "author": "Martin Atkins", "author_id": 281848, "author_profile": "https://Stackoverflow.com/users/281848", "pm_score": 1, "selected": true, "text": "for_each" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7298239/" ]
74,449,835
<p>On hovering the mouse pointer over a function, whether inbuilt or custom, the definition and docstring of the function shows as expected, however it shows twice. I have had a search for what might be causing this and looked around my settings, but have yet to find a reason for it. If it makes a difference, am using Python on VSCode.</p> <p>Perhaps someone knows what might be causing this and how to resolve? I have not attached any images, since I think the issue is quite clear, but happy to provide if needed for clarification.</p> <p>Thanks!</p>
[ { "answer_id": 74561141, "author": "Ulf Rompe", "author_id": 1230589, "author_profile": "https://Stackoverflow.com/users/1230589", "pm_score": 2, "selected": true, "text": "\"jupyter.pylanceHandlesNotebooks\": false\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9230013/" ]
74,449,864
<p>I am creating a website so I finshed register page in login page, every details are correct but that is showing please verify your details I mean the else part also I put in a print statement after username and password same details are printing when I typed but not access login.</p> <p>views.py</p> <pre><code>def sign_in(request): if request.method == &quot;POST&quot;: username=request.POST['username'] password=request.POST['password'] print(username,password) user = authenticate(username=username,password=password) if user is not None: login(request,user) messages.success(request,&quot;you are logged successfully &quot;) return redirect(&quot;front_page&quot;) else: messages.error(request,&quot;please verify your details&quot;) return redirect(&quot;sign_in&quot;) return render(request,&quot;login.html&quot;) def front_page(request): return render(request,&quot;frontpage.html&quot;) </code></pre> <p>urls.py</p> <pre><code> path('log_in',views.sign_in,name=&quot;sign_in&quot;), path('front_page',views.front_page,name=&quot;front_page&quot;), </code></pre> <p>html</p> <pre class="lang-html prettyprint-override"><code> &lt;div class=&quot;signup-form&quot;&gt; &lt;form action=&quot;{% url 'sign_in' %}&quot; method=&quot;POST&quot;&gt; {% csrf_token %} &lt;h2 class=&quot;text-center&quot;&gt;Login&lt;/h2&gt; &lt;p class=&quot;text-center&quot;&gt;Please fill in this form to login your account!&lt;/p&gt; &lt;hr&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;div class=&quot;input-group&quot;&gt; &lt;div class=&quot;input-group-prepend&quot;&gt; &lt;span class=&quot;input-group-text&quot;&gt; &lt;span class=&quot;fa fa-user&quot;&gt;&lt;/span&gt; &lt;/span&gt; &lt;/div&gt; &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;username&quot; placeholder=&quot;Username&quot; required=&quot;required&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;div class=&quot;input-group&quot;&gt; &lt;div class=&quot;input-group-prepend&quot;&gt; &lt;span class=&quot;input-group-text&quot;&gt; &lt;i class=&quot;fa fa-lock&quot;&gt;&lt;/i&gt; &lt;/span&gt; &lt;/div&gt; &lt;input type=&quot;password&quot; class=&quot;form-control&quot; name=&quot;password&quot; placeholder=&quot;Password&quot; required=&quot;required&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;form-group d-flex justify-content-center&quot;&gt; &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-lg&quot;&gt;Login&lt;/button&gt; &lt;/div&gt; &lt;div class=&quot;text-center text-primary&quot;&gt;Dont have a account? &lt;a href=&quot;{% url 'register' %}&quot;&gt;Create here &lt;/a&gt;&lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>I just want to login with username and password, but it shows please verify your details, but all the details are correct.</p> <p>Any ideas?</p>
[ { "answer_id": 74449997, "author": "Sunderam Dubey", "author_id": 17562044, "author_profile": "https://Stackoverflow.com/users/17562044", "pm_score": 3, "selected": true, "text": "authenticate()" }, { "answer_id": 74451116, "author": "raphael", "author_id": 10951070, "author_profile": "https://Stackoverflow.com/users/10951070", "pm_score": 1, "selected": false, "text": "def sign_in(request):\n \n if request.method == \"POST\":\n username=request.POST['username']\n password=request.POST['password']\n print(username,password)\n user = authenticate(username=username, password=password)\n \n if user is not None:\n login(request,user)\n messages.success(request,\"you are logged successfully \")\n return redirect(\"front_page\") \n else:\n messages.error(request,\"please verify your details\")\n return redirect(\"sign_in\") \n return render(request,\"login.html\")\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17193865/" ]
74,449,886
<p>This is my code.</p> <pre><code>folder_out = [] for a in range(1,80): folder_letter = &quot;/content/drive/MyDrive/project/Dataset/data/&quot; folder_out[a] = os.path.join(folder_letter, str(a)) folder_out.append(folder_out[a]) </code></pre> <p>and this is an error <a href="https://i.stack.imgur.com/rSbN6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rSbN6.png" alt="enter image description here" /></a></p> <p>and this what I want <a href="https://i.stack.imgur.com/7wwVA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7wwVA.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74449997, "author": "Sunderam Dubey", "author_id": 17562044, "author_profile": "https://Stackoverflow.com/users/17562044", "pm_score": 3, "selected": true, "text": "authenticate()" }, { "answer_id": 74451116, "author": "raphael", "author_id": 10951070, "author_profile": "https://Stackoverflow.com/users/10951070", "pm_score": 1, "selected": false, "text": "def sign_in(request):\n \n if request.method == \"POST\":\n username=request.POST['username']\n password=request.POST['password']\n print(username,password)\n user = authenticate(username=username, password=password)\n \n if user is not None:\n login(request,user)\n messages.success(request,\"you are logged successfully \")\n return redirect(\"front_page\") \n else:\n messages.error(request,\"please verify your details\")\n return redirect(\"sign_in\") \n return render(request,\"login.html\")\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14599281/" ]
74,449,928
<p>I have a function <code>void dynamics (A a, std::vector&lt;double&gt; &amp;, std::vector&lt;double&gt; &amp;, std::vector&lt;double&gt; )</code> which I am calling from threads created by openmp. The inputs to the function are private to each thread (created within the parallel block)</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;chrono&gt; using namespace std; class A { some code }; int main(void) { vector&lt;double&gt; a (12,0.0); vector&lt;double&gt; b (12,0.0); #pragma omp parallel for shared(a,b) for(int id = 0; id &lt; 6; id++) { vector&lt;double&gt; a_private (2,0.0); vector&lt;double&gt; b_private (2,0.0); vector&lt;double&gt; c_private (2,(double)id); A d; start_time for each thread - chrono dynamics(d,a_private,b_private,c_private); end_time for each thread - chrono calculate_time for each thread # pragma omp critical { for(int i = 0; i &lt; 2; i++) a[i+(2*id)] = a_private[i]; for(int i = 0; i &lt; 2; i++) b[i+(2*id)] = b_private[i]; } } print(a); print(b); return 0; } </code></pre> <p>Here, to avoid race condition, I have put the assignment of a_private and b_private into a and b within critical section.</p> <p>When I calculate the time for above code for each threads, it is more than the time if I put the dynamics function within the critical section.</p> <pre><code># pragma omp critical { start_time for each thread - chrono dynamics(d,a_private,b_private,c_private); end_time for each thread - chrono calculate_time for each thread for(int i = 0; i &lt; 2; i++) a[i+(2*id)] = a_private[i]; for(int i = 0; i &lt; 2; i++) b[i+(2*id)] = b_private[i]; } </code></pre> <p>The output (a and b) at the end is same in both the cases (running the code multiple times give same results). Thus, I believe dynamics is thread safe (could it not be thread safe?).</p> <p>The inputs to dynamics are created within the parallel region. Thus, they should be private to each thread (are they?).</p> <p>Why are the threads running slowly to calculate the dynamics when working together, compared to when working one after another (within critical section).</p> <p>I believe the overhead of creating and managing threads would not be a problem as I am comparing times where threads are always created (in both of my above cases).</p> <p>The total time after parallelizing dynamics is lower than the serial version (speedup achieved) but why do threads take significantly different times (within critical vs not : to calculate thread times).</p> <p>The explanation I could come up was that running dynamics creates race condition even if the input and output to it are private to each threads. (Could this be?)</p> <p>Also, I am not using omp get num threads and omp get thread num.</p> <p>What could be the issue here?</p> <pre><code>When running dynamics in parallel ID = 3, Dynamics Time = 410233 ID = 2, Dynamics Time = 447835 ID = 5, Dynamics Time = 532967 ID = 1, Dynamics Time = 545017 ID = 4, Dynamics Time = 576783 ID = 0, Dynamics Time = 624855 When running dynamics in critical section ID = 0, Dynamics Time = 331579 ID = 2, Dynamics Time = 303294 ID = 5, Dynamics Time = 307622 ID = 1, Dynamics Time = 340489 ID = 3, Dynamics Time = 303066 ID = 4, Dynamics Time = 293090 </code></pre> <p>(Would not be able to provide the minimal reproduction of dynamics as it is proprietary of my professor)</p> <p>Thank you.</p>
[ { "answer_id": 74450180, "author": "PierU", "author_id": 14778592, "author_profile": "https://Stackoverflow.com/users/14778592", "pm_score": 1, "selected": false, "text": "dynamics()" }, { "answer_id": 74453659, "author": "shy45", "author_id": 20313707, "author_profile": "https://Stackoverflow.com/users/20313707", "pm_score": 0, "selected": false, "text": "num vector = 10000\nParallel\nid=0091152 time=10155\nid=0082408 time=10169\nid=0074644 time=10172\nid=0135644 time=10269\nid=0092996 time=10303\nid=0133796 time=10348\nid=0135884 time=10420\n\nSerial\nid=0132880 time=7635\nid=0106048 time=7643\nid=0072972 time=7618\nid=0107080 time=7794\nid=0100064 time=7942\nid=0110648 time=8044\nid=0111988 time=7849\n\n---------------------\n\nnum vector = 1000000\nParallel\nid=0069820 time=27000\nid=0135668 time=27106\nid=0118184 time=27144\nid=0102572 time=27158\nid=0046388 time=27165\nid=0120604 time=27173\nid=0044344 time=27188\n\nSerial\nid=0038320 time=5341\nid=0133000 time=5253\nid=0101508 time=5168\nid=0004840 time=5212\nid=0087408 time=5143\nid=0130548 time=5199\nid=0122764 time=5126\n\ntime unit=msec\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16016658/" ]
74,449,951
<p>why is it that there are two children with the same key Im using React and Im trying to make ecommerce website I dont understand the error of double keys</p> <pre><code>import React, {useEffect} from 'react' import { Link, useParams, useNavigate, useLocation, useSearchParams } from 'react-router-dom' import { useDispatch, useSelector } from 'react-redux' import { Row, Col, ListGroup, Image, Form, Button, Card} from 'react-bootstrap' import Message from '../components/Message' import { addToCart } from '../actions/cartActions' export default function CartScreen() { const { id} = useParams() const { search } = useLocation(); const [searchParams] = useSearchParams(); const dispatch = useDispatch(); const productID = id; const qty = search ? Number(search.split(&quot;=&quot;)[1]) : 1; const cart = useSelector(state =&gt; state.cart) const { cartItems} = cart console.log('cartItems:', cartItems) useEffect(() =&gt; { if(productID) { dispatch(addToCart(productID, qty)) } }, [dispatch, productID, qty]) return ( &lt;Row&gt; &lt;Col md={8}&gt; &lt;h1&gt;Shopping Cart&lt;/h1&gt; {cartItems.length === 0 ? ( &lt;Message variant='info'&gt; Your cart is empty &lt;Link to='/'&gt;Go Back&lt;/Link&gt; &lt;/Message&gt; ) : ( &lt;ListGroup varient='flush'&gt; {cartItems.map(item =&gt; ( &lt;ListGroup.Item key= { item.product }&gt; &lt;Row&gt; &lt;Col md={2}&gt; &lt;Image src={item.image} alt={item.name} fluid rounded/&gt; &lt;/Col&gt; &lt;Col md={3}&gt; &lt;Link to={`/product/${item.product}`}&gt;{item.name}&lt;/Link&gt; &lt;/Col&gt; &lt;Col md={2}&gt; ${item.price} &lt;/Col&gt; &lt;/Row&gt; &lt;/ListGroup.Item&gt; ))} &lt;/ListGroup&gt; )} &lt;/Col&gt; &lt;Col md={4}&gt; &lt;/Col&gt; &lt;/Row&gt; ) } </code></pre> <p>Im trying to load up the cart images in the CartScreen and its telling me that there are two children with same key</p>
[ { "answer_id": 74450180, "author": "PierU", "author_id": 14778592, "author_profile": "https://Stackoverflow.com/users/14778592", "pm_score": 1, "selected": false, "text": "dynamics()" }, { "answer_id": 74453659, "author": "shy45", "author_id": 20313707, "author_profile": "https://Stackoverflow.com/users/20313707", "pm_score": 0, "selected": false, "text": "num vector = 10000\nParallel\nid=0091152 time=10155\nid=0082408 time=10169\nid=0074644 time=10172\nid=0135644 time=10269\nid=0092996 time=10303\nid=0133796 time=10348\nid=0135884 time=10420\n\nSerial\nid=0132880 time=7635\nid=0106048 time=7643\nid=0072972 time=7618\nid=0107080 time=7794\nid=0100064 time=7942\nid=0110648 time=8044\nid=0111988 time=7849\n\n---------------------\n\nnum vector = 1000000\nParallel\nid=0069820 time=27000\nid=0135668 time=27106\nid=0118184 time=27144\nid=0102572 time=27158\nid=0046388 time=27165\nid=0120604 time=27173\nid=0044344 time=27188\n\nSerial\nid=0038320 time=5341\nid=0133000 time=5253\nid=0101508 time=5168\nid=0004840 time=5212\nid=0087408 time=5143\nid=0130548 time=5199\nid=0122764 time=5126\n\ntime unit=msec\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18943132/" ]
74,449,956
<p>I just want to add a <code>@PreAuthorize(&quot;hasAuthority('ROLE_ADMIN')&quot;)</code> and <code>@PreAuthorize(&quot;hasAuthority('ROLE_USER')&quot;)</code> in the methods of order controller and I also revise the controller test method after I define a login method in auth service in terms of User and Admin role.</p> <p>After I add <code>@PreAuthorize(&quot;hasAuthority('ROLE_USER')&quot;)</code> of placeOrder method of controller, I revise its test method.</p> <p>Here is the method of order controller</p> <pre><code> @PreAuthorize(&quot;hasAuthority('ROLE_USER')&quot;) @PostMapping(&quot;/placeorder&quot;) public ResponseEntity&lt;Long&gt; placeOrder(@RequestBody OrderRequest orderRequest) { log.info(&quot;OrderController | placeOrder is called&quot;); log.info(&quot;OrderController | placeOrder | orderRequest: {}&quot;, orderRequest.toString()); long orderId = orderService.placeOrder(orderRequest); log.info(&quot;Order Id: {}&quot;, orderId); return new ResponseEntity&lt;&gt;(orderId, HttpStatus.OK); } </code></pre> <p>Here is the example test method in ordercontrollertest in order service.</p> <pre><code>@Test @DisplayName(&quot;Place Order -- Success Scenario&quot;) void test_When_placeOrder_DoPayment_Success() throws Exception { OrderRequest orderRequest = getMockOrderRequest(); String jwt = getJWTTokenForRoleUser(); MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(&quot;/order/placeorder&quot;) .contentType(MediaType.APPLICATION_JSON_VALUE) .header(&quot;Authorization&quot;, &quot;Bearer &quot; + jwt) .content(objectMapper.writeValueAsString(orderRequest))) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn(); String orderId = mvcResult.getResponse().getContentAsString(); Optional&lt;Order&gt; order = orderRepository.findById(Long.valueOf(orderId)); assertTrue(order.isPresent()); Order o = order.get(); assertEquals(Long.parseLong(orderId), o.getId()); assertEquals(&quot;PLACED&quot;, o.getOrderStatus()); assertEquals(orderRequest.getTotalAmount(), o.getAmount()); assertEquals(orderRequest.getQuantity(), o.getQuantity()); } </code></pre> <p>Here are the dependenices of order service regarding it.</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; </code></pre> <p>How can I define the ROLE in this test method. I tried to use <code>@WithMockUser(roles=&quot;USER&quot;)</code> and <code>@WithMockUser(roles=&quot;ADMIN&quot;)</code> but it didn't help me. (I got 403 Forbidden error.)</p> <p>Edited ( I also tried to WebSecurityConfig in the service but it didn't help me fix the issue. That's why I removed it from the service.)</p> <pre><code>@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurityConfig { @Bean public SecurityFilterChain securityWebFilterChain(HttpSecurity http) throws Exception { http .authorizeRequests( authorizeRequest -&gt; authorizeRequest .anyRequest() .authenticated()); return http.build(); } } </code></pre> <p>Here is the example link : <a href="https://github.com/Rapter1990/microservicecoursedailybuffer" rel="nofollow noreferrer">Link</a></p> <p>Here is the test controller : <a href="https://github.com/Rapter1990/microservicecoursedailybuffer/blob/main/orderservice/src/test/java/com/microservice/orderservice/controller/OrderControllerTest.java" rel="nofollow noreferrer">Link</a></p> <p>To run the app, 1 ) Run Service Registery (Eureka Server)</p> <p>2 ) Run config server</p> <p>3 ) Run zipkin and redis through these commands shown below on docker docker run -d -p 9411:9411 openzipkin/zipkin docker run -d --name redis -p 6379:6379 redis</p> <p>4 ) Run api gateway</p> <p>5 ) Run other services</p>
[ { "answer_id": 74452437, "author": "muhammed ozbilici", "author_id": 2165146, "author_profile": "https://Stackoverflow.com/users/2165146", "pm_score": 0, "selected": false, "text": "@EnableGlobalMethodSecurity(prePostEnabled = true)" }, { "answer_id": 74453670, "author": "ch4mp", "author_id": 619830, "author_profile": "https://Stackoverflow.com/users/619830", "pm_score": 1, "selected": false, "text": "@WithMockUser" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19721745/" ]
74,449,960
<p>I have two libraries, <code>mat-text-editor</code> and <code>mat-text-editor-select</code>, the former uses the component of the latter, which works fine. <code>mat-text-editor-select</code> also includes a regular typescript class, <code>mat-text-editor-select-option</code>, which I want to export alongside the <code>mat-text-editor-select-component</code> so I can use it in the <code>mat-text-editor</code> module.</p> <p>I can import the file like this:</p> <pre><code>import { MatTextEditorSelectOption } from &quot;projects/mat-text-editor-select/src/mat-text-editor-select-option&quot;; </code></pre> <p>This is recognized but throws an error when I try to build the text-editor library: <code>File 'D:/Documents/Websites/angular-material-extension/projects/mat-text-editor-select/src/mat-text-editor-select-option.ts' is not under 'rootDir' 'D:\Documents\Websites\angular-material-extension\projects\mat-text-editor\src'. 'rootDir' is expected to contain all source files.</code></p> <p>I've added <code>export * from './mat-text-editor-select-option';</code> to the public-api.ts of the <code>mat-text-editor-select</code> library and tried to import the class like this:</p> <pre><code>import { MatTextEditorSelectOption } from &quot;mat-text-editor-select/mat-text-editor-select-option&quot;; </code></pre> <p>but VS Code complains it cannot find the module. I've also tried:</p> <pre><code>import { MatTextEditorSelectOption } from &quot;mat-text-editor-select&quot;; </code></pre> <p>but it says mat-text-editor-select has no exported member named MatTextEditorSelectOption, which I'm surprised because shouldn't it have now? What else do I need to do to export/import the class from one library to the other?</p>
[ { "answer_id": 74452437, "author": "muhammed ozbilici", "author_id": 2165146, "author_profile": "https://Stackoverflow.com/users/2165146", "pm_score": 0, "selected": false, "text": "@EnableGlobalMethodSecurity(prePostEnabled = true)" }, { "answer_id": 74453670, "author": "ch4mp", "author_id": 619830, "author_profile": "https://Stackoverflow.com/users/619830", "pm_score": 1, "selected": false, "text": "@WithMockUser" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2139555/" ]
74,449,983
<p>I have a value that needs to be parsed into a potential three values:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>MasterUnit</th> <th>Unit1</th> <th>Unit2</th> <th>Unit3</th> </tr> </thead> <tbody> <tr> <td>10ABC</td> <td>10A</td> <td>10B</td> <td>10C</td> </tr> <tr> <td>10AB</td> <td>10A</td> <td>10B</td> <td>NULL</td> </tr> </tbody> </table> </div> <p>I'm accomplishing what I need in the below script. My question to you... Is there a better, more efficient way to do so (in fewer lines of code)?</p> <pre><code>cast([UnitNum] as char(5)) as MasterUnit, left(cast([UnitNum] as char(5)), 3) as Unit1, case when (left(left(cast([UnitNum] as char(5)), 2) + right(cast([UnitNum] as char(5)), 2),3)) = left(cast([UnitNum] as char(5)), 2) then NULL else (left(left(cast([UnitNum] as char(5)), 2) + right(cast([UnitNum] as char(5)), 2),3)) end as Unit2, case when (left(cast([UnitNum] as char(5)), 2)) + (right(cast([UnitNum] as char(5)), 1)) = left([UnitNum],2) then NULL else (left(cast([UnitNum] as char(5)), 2) + right(cast([UnitNum] as char(5)), 1)) end as Unit3 </code></pre>
[ { "answer_id": 74450336, "author": "John Cappelletti", "author_id": 1570000, "author_profile": "https://Stackoverflow.com/users/1570000", "pm_score": 2, "selected": true, "text": "CROSS APPLY" }, { "answer_id": 74450472, "author": "Stu", "author_id": 15332650, "author_profile": "https://Stackoverflow.com/users/15332650", "pm_score": 0, "selected": false, "text": "select MasterUnit,\n u + NullIf(Substring(MasterUnit,3,1),'') Unit1,\n u + NullIf(substring(MasterUnit,4,1),'') Unit2,\n u + NullIf(substring(MasterUnit,5,1),'') Unit3\nfrom t\ncross apply(values(Left(MasterUnit,2)))m(u);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20232603/" ]
74,450,004
<p>I'm just starting to work with Prolog, so I don't really understand it. I have the facts:</p> <pre><code>circle(сhess, abbot). circle(сhess, hannigan). circle(сhess, abrams). circle(crystal_voice, blake). circle(crystal_voice, weller). circle(crystal_voice, huxley). circle(local_studies, barnes). circle(local_studies, haskins). circle(local_studies, abrams). circle(local_studies, aberdeen). circle(art, barnes). circle(art, abbot). circle(art, blake). person(abbot, male, 20). person(aberdeen, female, 18). person(weller, male, 22). person(abrams, female, 25). person(adams, male, 21). person(bond, female, 12). person(haskins, male, 15). person(blake, female, 20). person(barnes, male, 20). person(hannigan, female, 15). person(huxley, male, 18). </code></pre> <p>I need to solve the problem: Find a list of people who participate in more than one circle.</p> <p>I have a code that finds only the number of circles that a person visits.</p> <pre><code>count(Name, Count):- findall(1, circle(_, Name), List), length(List, Count). </code></pre>
[ { "answer_id": 74450336, "author": "John Cappelletti", "author_id": 1570000, "author_profile": "https://Stackoverflow.com/users/1570000", "pm_score": 2, "selected": true, "text": "CROSS APPLY" }, { "answer_id": 74450472, "author": "Stu", "author_id": 15332650, "author_profile": "https://Stackoverflow.com/users/15332650", "pm_score": 0, "selected": false, "text": "select MasterUnit,\n u + NullIf(Substring(MasterUnit,3,1),'') Unit1,\n u + NullIf(substring(MasterUnit,4,1),'') Unit2,\n u + NullIf(substring(MasterUnit,5,1),'') Unit3\nfrom t\ncross apply(values(Left(MasterUnit,2)))m(u);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512490/" ]
74,450,005
<p>I want to update a table value to either 1 of 2 values. The selected value has 2 possible choices <em>I ride a bike</em> or <em>I fly an airplane.</em> If the entered value is I ride a bike then the database value should be set as 1 , if it's I fly an airplane then the value should be set at 2. This way When I display/view the table, either an image of a bike (called 1.png) or a plane (called 2.png) will be displayed , based on what the value of transport is set as.</p> <pre><code>// get the passed variables from the web form $id=$_POST['id']; $pid = $_POST['pid']; $transport=$_POST['transport']; // update data in mysql database $sql = &quot;UPDATE survey SET pid=?, transport=? WHERE id=?&quot;; $stmt= $con-&gt;prepare($sql); $stmt-&gt;bind_param(&quot;ssi&quot;, $pid, $transport, $id); $stmt-&gt;execute(); </code></pre> <p>The above code currently works but displayed in the table is the text of ride bike or fly airplane I prefer the simple image So I was thinking something like using strlen, ride bike has 15 characters,or airplane has 18</p> <pre><code>$sql = &quot;UPDATE survey SET pid=?,if (strlen(['transport']) == 18){set '2';}else{set '1';} ,WHERE id=?&quot;; </code></pre> <p>but it doesn't work and I have no idea because this is just a hobby.</p>
[ { "answer_id": 74450062, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 0, "selected": false, "text": "IF" }, { "answer_id": 74450141, "author": "ryantxr", "author_id": 6032547, "author_profile": "https://Stackoverflow.com/users/6032547", "pm_score": 2, "selected": true, "text": "$id=$_POST['id']; \n$pid = $_POST['pid'];\n$transport=$_POST['transport'];\nswitch(strtolower($transport)) {\n case 'i ride a bike':\n $transportValue = 1;\n break;\n case 'i fly a plane':\n $transportValue = 2;\n break;\n default:\n $transportValue = 0; // if it's something else\n break;\n}\n\n// update data in mysql database\n$sql = \"UPDATE survey SET pid=?, transport=? WHERE id=?\";\n$stmt = $con->prepare($sql);\n$stmt->bind_param(\"ssi\", $pid, $transportValue, $id);\n$stmt->execute();\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1356282/" ]
74,450,007
<p>I am a beginner with SAS and trying to create a table with code below. Although the code has been running for 3 hours now. The dataset is quite huge (150000 rows). Although, when I insert a different date it runs in 45 mins. The date I have inserted is valid under date_key. Any suggestions on why this may be/what I can do? Thanks in advance</p> <pre><code>proc sql; create table xyz as select monotonic() as rownum ,* from x.facility_yz where (Fac_Name = 'xyz' and (Ratingx = 'xyz' or Ratingx is null) ) and Date_key = '20000101' ; quit; </code></pre> <p>Tried running it again but same problem</p>
[ { "answer_id": 74450260, "author": "Stu Sztukowski", "author_id": 5342700, "author_profile": "https://Stackoverflow.com/users/5342700", "pm_score": 2, "selected": false, "text": "monotonic()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20013104/" ]
74,450,014
<p>I have a small script running in a Pod that pokes for the latest App images (<code>dashboard:development</code>) in my registry and then pushes them to the Nodes running (via a daemonset).</p> <p>This <strong>does work</strong>, as seen below.</p> <p>Now, I would assume that once an App pod (like <code>sp-pod-xx</code>) requests this image, kubelet should not try to re-pull the image, even if <code>imagePullPolicy: Always</code> is set. As the <a href="https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy" rel="nofollow noreferrer">docs</a> say, kubelet compares the digest and only pulls, if there is a mismatch:</p> <blockquote> <p><strong>Always:</strong> every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name to an image digest. If the kubelet has a container image with that exact digest cached locally, the kubelet uses its cached image; otherwise, the kubelet pulls the image with the resolved digest, and uses that image to launch the container.</p> </blockquote> <p>But, even though the digests are identical (I did verify this), kubelet still re-pulls the image anyway. The App pod and the Daemonset pods are running on the same nodes too.</p> <p>Any idea why?</p> <p>Event logs:</p> <pre><code>4m5s Normal Killing pod/image-puller-ds-ldbfz 3m57s Normal SuccessfulCreate daemonset/image-puller-ds Created pod: image-puller-ds-fcmts 3m57s Normal SuccessfulCreate daemonset/image-puller-ds Created pod: image-puller-ds-fhhds 3m57s Normal Pulled pod/image-puller-ds-fhhds Successfully pulled image &quot;dashboard:development&quot; in 192.717161ms 3m57s Normal Pulling pod/image-puller-ds-fhhds Pulling image &quot;dashboard:development&quot; 3m56s Normal Started pod/image-puller-ds-fhhds Started container image-puller 3m56s Normal Created pod/image-puller-ds-fcmts Created container image-puller 3m56s Normal Created pod/image-puller-ds-fhhds Created container image-puller 3m56s Normal Started pod/image-puller-ds-fcmts Started container image-puller 3m56s Normal Pulled pod/image-puller-ds-fhhds Container image &quot;pause:0.0.1&quot; already present on machine 3m55s Normal Created pod/image-puller-ds-fcmts Created container pause 3m55s Normal SuccessfulDelete daemonset/image-puller-ds Deleted pod: image-puller-ds-xt9vv 3m55s Normal Pulled pod/image-puller-ds-fcmts Container image &quot;pause:0.0.1&quot; already present on machine 3m55s Normal Created pod/image-puller-ds-fhhds Created container pause 3m55s Normal Started pod/image-puller-ds-fhhds Started container pause 3m55s Normal Started pod/image-puller-ds-fcmts Started container pause 3m55s Normal Killing pod/image-puller-ds-xt9vv Stopping container pause 3m54s Normal Killing pod/image-puller-ds-wgwzh Stopping container pause 3m54s Normal SuccessfulDelete daemonset/image-puller-ds Deleted pod: image-puller-ds-wgwzh 3m25s Normal Pulling pod/sp-pod-f3884032-1164-48e8-8213-c0c3856e573d Pulling image &quot;dashboard:development&quot; 3m25s Normal Pulled pod/sp-pod-f3884032-1164-48e8-8213-c0c3856e573d Successfully pulled image &quot;dashboard:development&quot; in 220.610781ms 3m25s Normal Created pod/sp-pod-f3884032-1164-48e8-8213-c0c3856e573d Created container sp-container-f3884032-1164-48e8-8213-c0c3856e573d 3m25s Normal Started pod/sp-pod-f3884032-1164-48e8-8213-c0c3856e573d Started container sp-container-f3884032-1164-48e8-8213-c0c3856e573d </code></pre> <p>Versions:</p> <pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;22&quot;, GitVersion:&quot;v1.22.0&quot;, GitCommit:&quot;c2b5237ccd9c0f1d600d3072634ca66cefdf272f&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-08-04T18:03:20Z&quot;, GoVersion:&quot;go1.16.6&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;} Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;23&quot;, GitVersion:&quot;v1.23.12&quot;, GitCommit:&quot;f941a31f4515c5ac03f5fc7ccf9a330e3510b80d&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2022-11-09T17:12:33Z&quot;, GoVersion:&quot;go1.17.13&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;} </code></pre>
[ { "answer_id": 74458041, "author": "adamkgray", "author_id": 8386878, "author_profile": "https://Stackoverflow.com/users/8386878", "pm_score": 2, "selected": true, "text": "PullIfNotPresent" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11091148/" ]
74,450,039
<p>I'm trying to conform a class to <code>Sendable</code>. I have some mutable stored properties which are causing issues. However, what I can't understand is that a MainActor isolated property doesn't allow my class to conform to Sendable. However, if I mark the whole class a <code>@MainActor</code>, then it's fine. However, I don't actually want to conform the whole class to <code>@MainActor</code>.</p> <p>As an example, take this code:</p> <pre><code>final class Article: Sendable { @MainActor var text: String = &quot;test&quot; } </code></pre> <p>It gives this warning: <code>Stored property 'text' of 'Sendable'-conforming class 'Article' is mutable</code>.</p> <p>Can someone explain why? I thought that being isolated to an actor would make it fine.</p>
[ { "answer_id": 74450425, "author": "Sweeper", "author_id": 5133585, "author_profile": "https://Stackoverflow.com/users/5133585", "pm_score": 0, "selected": false, "text": "Sendable" }, { "answer_id": 74451965, "author": "Rob", "author_id": 1271826, "author_profile": "https://Stackoverflow.com/users/1271826", "pm_score": 2, "selected": true, "text": "final class Foo: Sendable {\n @MainActor var counter = 0 // Stored property 'counter' of 'Sendable'-conforming class 'Foo' is mutable\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/362840/" ]
74,450,064
<p>I am in Vietnam, and I want to get the weekday in Finland today using Javascript.</p> <blockquote> <p>timeZone: 'Europe/Helsinki'</p> </blockquote> <p>Do you have a good solution?</p> <p>Thank you so much</p>
[ { "answer_id": 74450425, "author": "Sweeper", "author_id": 5133585, "author_profile": "https://Stackoverflow.com/users/5133585", "pm_score": 0, "selected": false, "text": "Sendable" }, { "answer_id": 74451965, "author": "Rob", "author_id": 1271826, "author_profile": "https://Stackoverflow.com/users/1271826", "pm_score": 2, "selected": true, "text": "final class Foo: Sendable {\n @MainActor var counter = 0 // Stored property 'counter' of 'Sendable'-conforming class 'Foo' is mutable\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10434805/" ]
74,450,065
<p>App Service dev, staging and prod deployment slots and SQL DB all have system assigned managed identities. Contributor roles have been assigned to managed identities at the subscription level.</p> <p>SQL Server Contained users have been created and roles assigned for the App Service dev, staging and production slots: <a href="https://i.stack.imgur.com/QkXIx.png" rel="nofollow noreferrer">SQL Server Contained Users</a></p> <p>appsettings.json connectionStrings: <a href="https://i.stack.imgur.com/32CQc.png" rel="nofollow noreferrer">connectionStrings</a></p> <p>AD DB Admin User created and added to SQLServer as a contained user.</p> <p>Permissions added to AppService managed identity for dB1 and dB2 to <a href="https://i.stack.imgur.com/U4UuQ.png" rel="nofollow noreferrer">SQL Server AppService Managed Identity Permissions</a></p> <p>msi-validator returns success for token based connection from the web app to two different databases on the same sql server instance. <a href="https://i.stack.imgur.com/mBnK1.png" rel="nofollow noreferrer">msi-validator success</a></p> <p>Local and Azure deployment slot both return: <a href="https://i.stack.imgur.com/GQVn7.png" rel="nofollow noreferrer">SQLException Login failed for token-identified principal</a></p> <p>Walked through <a href="https://social.technet.microsoft.com/wiki/contents/articles/53928.azure-ad-managed-identity-connecting-azure-web-app-and-slots-with-azure-sql-db-without-credentials.aspx" rel="nofollow noreferrer">https://social.technet.microsoft.com/wiki/contents/articles/53928.azure-ad-managed-identity-connecting-azure-web-app-and-slots-with-azure-sql-db-without-credentials.aspx</a> and many other tutorials.</p> <p>Still missing something...</p> <p>Attempts to run the application using the managed identity connection string is consistently failing with the token-provider principal login failure error.</p> <p>Confirmation of settings: <a href="https://i.stack.imgur.com/Ry6ZF.png" rel="nofollow noreferrer">Confirmation of Settings</a></p>
[ { "answer_id": 74454767, "author": "Alberto Morillo", "author_id": 8184139, "author_profile": "https://Stackoverflow.com/users/8184139", "pm_score": 3, "selected": true, "text": " CREATE USER <Azure_AD_principal_name> FROM EXTERNAL PROVIDER;\n CREATE USER [bob@contoso.com] FROM EXTERNAL PROVIDER;\n CREATE USER [alice@fabrikam.onmicrosoft.com] FROM EXTERNAL PROVIDER;\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9612994/" ]
74,450,094
<p>Here's my data:</p> <pre><code>game_id team opponent steals assists &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; 1 401468360 Spurs Warriors 6 18 2 401468360 Warriors Spurs 9 35 3 401468358 Clippers Rockets 6 25 4 401468358 Rockets Clippers 11 20 5 401468359 Hawks Bucks 4 23 6 401468359 Bucks Hawks 4 21 7 401468356 Thunder Celtics 4 21 8 401468356 Celtics Thunder 15 25 9 401468357 Suns Heat 9 22 10 401468357 Heat Suns 6 3 </code></pre> <p>How do I get this data in the following format?</p> <pre><code>game_id team opponent team_steals opp_assists team_assists opp_steals &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; 1 401468360 Spurs Warriors 6 9 18 35 2 401468358 Clippers Rockets 6 11 25 20 3 401468359 Hawks Bucks 4 4 23 21 4 401468356 Thunder Celtics 4 15 21 25 9 401468357 Suns Heat 9 6 22 23 </code></pre> <p>I have tried several variation of <code>pivot_wider</code> to no avail. I'm not even sure if that function will accomplish what I am seeking.</p>
[ { "answer_id": 74450267, "author": "TarJae", "author_id": 13321647, "author_profile": "https://Stackoverflow.com/users/13321647", "pm_score": 2, "selected": false, "text": "library(dplyr)\nlibrary(tidyr)\ndf %>%\n group_by(game_id) %>% \n rename(team_steals = steals) %>% \n mutate(opp_steals = lead(team_steals)) %>% \n rename(team_assists = assists) %>% \n mutate(opp_assists = lead(team_assists)) %>% \n drop_na()\n" }, { "answer_id": 74450371, "author": "stefan", "author_id": 12993861, "author_profile": "https://Stackoverflow.com/users/12993861", "pm_score": 2, "selected": false, "text": "pivot_wider" }, { "answer_id": 74450523, "author": "M--", "author_id": 6461462, "author_profile": "https://Stackoverflow.com/users/6461462", "pm_score": 3, "selected": true, "text": "library(dplyr)\n\ndat %>% \n right_join(dat, by = c(\"game_id\", \"team\" = \"opponent\", \"opponent\" = \"team\"), \n suffix = c(\"_team\", \"_opponent\")) %>% \n distinct(game_id, .keep_all = TRUE)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512737/" ]
74,450,114
<p>when I load form inside panel using code</p> <pre class="lang-vb prettyprint-override"><code>With Form_brand .TopLevel = False Panel2.Controls.Add(Form_brand) .BringToFront() .Show() End With </code></pre> <p>textbox inside form does not show its default behaviour like when i click inside textbox cursor show at starting of the text instead of place where I click the mouse. Another problem is that when I move mouse pointer with clicking mouse button text should be selected but this does not happen.</p> <p>If I open form simply using code</p> <pre class="lang-vb prettyprint-override"><code>Form_Brand.show() </code></pre> <p>textbox shows it default behaviour. What should I do?</p>
[ { "answer_id": 74450267, "author": "TarJae", "author_id": 13321647, "author_profile": "https://Stackoverflow.com/users/13321647", "pm_score": 2, "selected": false, "text": "library(dplyr)\nlibrary(tidyr)\ndf %>%\n group_by(game_id) %>% \n rename(team_steals = steals) %>% \n mutate(opp_steals = lead(team_steals)) %>% \n rename(team_assists = assists) %>% \n mutate(opp_assists = lead(team_assists)) %>% \n drop_na()\n" }, { "answer_id": 74450371, "author": "stefan", "author_id": 12993861, "author_profile": "https://Stackoverflow.com/users/12993861", "pm_score": 2, "selected": false, "text": "pivot_wider" }, { "answer_id": 74450523, "author": "M--", "author_id": 6461462, "author_profile": "https://Stackoverflow.com/users/6461462", "pm_score": 3, "selected": true, "text": "library(dplyr)\n\ndat %>% \n right_join(dat, by = c(\"game_id\", \"team\" = \"opponent\", \"opponent\" = \"team\"), \n suffix = c(\"_team\", \"_opponent\")) %>% \n distinct(game_id, .keep_all = TRUE)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20219247/" ]
74,450,124
<p>i have a chat website and i want the user to have a list available of users sorted by who they last chatted with(like whatsapp). how do i do this? i tried many stack overflow answers but none of them worked for me so far. when using the code i use now the names of the users repeat for every message that exists. this query isn't working: &quot;SELECT * FROM dms WHERE sentTo = &quot;.$_SESSION['id'].&quot; or sentBy = &quot;.$_SESSION['id'].&quot;;&quot; this is what my database looks like: <a href="https://i.stack.imgur.com/hpmQ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hpmQ2.png" alt="enter image description here" /></a></p> <p>this is my code:</p> <pre><code>&lt;?php $sql = &quot;SELECT * FROM dms WHERE sentTo = &quot;.$_SESSION['id'].&quot; or sentBy = &quot;.$_SESSION['id'].&quot;;&quot;; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) &gt; 0) { while ($row = mysqli_fetch_assoc($result)) { $sql2 = &quot;SELECT id, username FROM users WHERE id = &quot;.$row['sentTo'].&quot;;&quot;; $result2 = mysqli_query($conn, $sql2); if (mysqli_num_rows($result2) &gt; 0) { while ($row2 = mysqli_fetch_assoc($result2)) { echo &quot;&lt;a href='dms.php?talkingTo=&quot;.$row2['id'].&quot;'&gt;&quot;.$row2['username'].&quot;&lt;/a&gt;&quot;; } }else{ echo &quot;&lt;p&gt;It's empty&lt;/p&gt;&quot;; } } }else{ echo &quot;&lt;p&gt;It's empty&lt;/p&gt;&quot;; } ?&gt; </code></pre>
[ { "answer_id": 74450267, "author": "TarJae", "author_id": 13321647, "author_profile": "https://Stackoverflow.com/users/13321647", "pm_score": 2, "selected": false, "text": "library(dplyr)\nlibrary(tidyr)\ndf %>%\n group_by(game_id) %>% \n rename(team_steals = steals) %>% \n mutate(opp_steals = lead(team_steals)) %>% \n rename(team_assists = assists) %>% \n mutate(opp_assists = lead(team_assists)) %>% \n drop_na()\n" }, { "answer_id": 74450371, "author": "stefan", "author_id": 12993861, "author_profile": "https://Stackoverflow.com/users/12993861", "pm_score": 2, "selected": false, "text": "pivot_wider" }, { "answer_id": 74450523, "author": "M--", "author_id": 6461462, "author_profile": "https://Stackoverflow.com/users/6461462", "pm_score": 3, "selected": true, "text": "library(dplyr)\n\ndat %>% \n right_join(dat, by = c(\"game_id\", \"team\" = \"opponent\", \"opponent\" = \"team\"), \n suffix = c(\"_team\", \"_opponent\")) %>% \n distinct(game_id, .keep_all = TRUE)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18113393/" ]
74,450,140
<p>I am trying to read information from a.txt file where each label is a dictionary key and each associated column of readings is the respective value.</p> <p>Here's some lines in the file:</p> <pre><code>increments ideal actual measured 0.0, 1000.0, 1000.0, 1006.4882 1.0, 950.0, 973.2774, 994.5579 2.0, 902.5, 897.6053, 998.9594 3.0, 857.375, 863.4304, 847.4721 4.0, 814.5062, 813.8886, 866.4862 </code></pre> <pre class="lang-py prettyprint-override"><code>with open(filename, 'r') as file: labels = file.readline().rstrip('\n').split('\t') num_cols = len(labels) data = [[] for _ in range(num_cols)] data_dict = {} </code></pre> <p>The above code is correct I just need to add on a little bit. How do I get the labels as dictionary keys and the columns as its values into data_dict?</p>
[ { "answer_id": 74450677, "author": "sudheesh shivan", "author_id": 9923289, "author_profile": "https://Stackoverflow.com/users/9923289", "pm_score": 0, "selected": false, "text": "import pandas as pd\n\ndata_dict = pd.read_csv('a.txt', sep=' ').to_dict(orient=\"index\").values()\n" }, { "answer_id": 74450746, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "with open(\"test.csv\", 'r') as file:\n \n labels = file.readline().rstrip('\\n').split() # read first line for labels\n data_dict = {l:[] for l in labels} # init empty container for each label\n\n for line in file.readlines(): # loop through rest of lines\n data = line.rstrip('\\n').split(',')\n for n, datapoint in enumerate(data):\n data_dict[labels[n]].append(datapoint)\n\nprint(data_dict)\n# >>> {'increments': ['0.0', '1.0', '2.0', '3.0', '4.0'], 'ideal': [' 1000.0', ' 950.0', ' 902.5', ' 857.375', ' 814.5062'], 'actual': [' 1000.0', ' 973.2774', ' 897.6053', ' 863.4304', ' 813.8886'], 'measured': [' 1006.4882', ' 994.5579', ' 998.9594', ' 847.4721', ' 866.4862']}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20404244/" ]
74,450,146
<p>Here I am Taking a string data and converting it into array elements but it is getting an empty array at last of all array elements and I am not be able to remove them easily.Please help.</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>let string_Data = `01226,Grover Cleveland,Anna,Uganda,Crucial Ltd,Tested Mutual B.V,Calvin Coolidge, 77110,John F. Kennedy,hora,Bosnia Herzegovina,Formal,Papal Corporation,Franklin Roosevelt, 29552,Lyndon B. Johnson,Margaret,Palau,Summaries Holdings Inc,Customize,Rutherford B. Hayes,`; let making_Array = csv =&gt; { var data = []; for (let dataAry of csv.split('\n')) { data.push(dataAry.split(',')); } return data; } console.log(making_Array(string_Data));</code></pre> </div> </div> </p>
[ { "answer_id": 74450214, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 0, "selected": false, "text": "," }, { "answer_id": 74450238, "author": "chovy", "author_id": 33522, "author_profile": "https://Stackoverflow.com/users/33522", "pm_score": 0, "selected": false, "text": "falsey" }, { "answer_id": 74450354, "author": "Yanick Rochon", "author_id": 320700, "author_profile": "https://Stackoverflow.com/users/320700", "pm_score": 2, "selected": true, "text": "let string_Data = `01226,Grover Cleveland,Anna,Uganda,Crucial Ltd,Tested Mutual B.V,Calvin Coolidge,\n 77110,John F. Kennedy,hora,Bosnia Herzegovina,Formal,Papal Corporation,Franklin Roosevelt,\n 29552,Lyndon B. Johnson,Margaret,Palau,Summaries Holdings Inc,Customize,Rutherford B. Hayes,`;\n\nlet making_Array = csv => {\n var data = [];\n\n for (let dataAry of csv.split('\\n')) {\n // 1. trim both ends of the line for white space, tab, etc.\n // 2. remove any last trailing comma\n // 3. split using comma separator\n data.push(dataAry.trim().replace(/,$/, '').split(','));\n }\n return data;\n\n}\nconsole.log(making_Array(string_Data));" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7620551/" ]
74,450,169
<p>I have an array with <code>id</code> and <code>parentId</code> and I need to create a tree out of this flat array so that each <code>parentId</code> that matches an <code>id</code> is now a child under <code>comments</code></p> <p>It's basically a threaded comment list.</p> <pre><code>{ &quot;comments&quot;: [ { &quot;body&quot;: &quot;asdf&quot;, &quot;createdAt&quot;: &quot;2022-11-15T17:53:05.048Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:fmd0noccuj&quot;, &quot;parentId&quot;: &quot;comments:yxbc3jv4yp&quot;, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T17:53:05.048Z&quot; }, { &quot;body&quot;: &quot;asdf&quot;, &quot;createdAt&quot;: &quot;2022-11-15T17:51:36.154Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:gfanwk4r1d&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T17:51:36.154Z&quot; }, { &quot;body&quot;: {}, &quot;createdAt&quot;: &quot;2022-11-15T17:48:38.321Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:0atvept3ob&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T17:48:38.321Z&quot; }, { &quot;body&quot;: {}, &quot;createdAt&quot;: &quot;2022-11-15T17:45:45.008Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:kiqco3uexk&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T17:45:45.008Z&quot; }, { &quot;body&quot;: {}, &quot;createdAt&quot;: &quot;2022-11-15T17:44:34.587Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:gs641tos5h&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T17:44:34.587Z&quot; }, { &quot;body&quot;: &quot;Test2&quot;, &quot;createdAt&quot;: &quot;2022-11-15T10:14:24.119Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:yxbc3jv4yp&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T10:14:24.119Z&quot; }, { &quot;body&quot;: &quot;test&quot;, &quot;createdAt&quot;: &quot;2022-11-15T10:09:13.370Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:1llogp6a7t&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T10:09:13.370Z&quot; }, { &quot;body&quot;: &quot;test&quot;, &quot;createdAt&quot;: &quot;2022-11-15T10:07:22.243Z&quot;, &quot;createdBy&quot;: { &quot;id&quot;: &quot;user:34nrxg022jt61t3xecgx&quot;, &quot;username&quot;: &quot;asdf&quot; }, &quot;id&quot;: &quot;comments:xqrk9bfp0h&quot;, &quot;parentId&quot;: null, &quot;postId&quot;: &quot;posts:j6uzaypl61&quot;, &quot;updatedAt&quot;: &quot;2022-11-15T10:07:22.243Z&quot; } ] } </code></pre> <p>Here is what I have but it returns an empty array if there are top level comments with no <code>parentId</code>:</p> <pre><code>const data = await res.json(); const nest = (items, id = null, link = 'parentId') =&gt; items .filter((item) =&gt; (item[link] ? item[link] === id : false)) .map((item) =&gt; ({ ...item, children: nest(items, item.id) })); this.comments = nest(data.comments); </code></pre>
[ { "answer_id": 74450214, "author": "Barmar", "author_id": 1491895, "author_profile": "https://Stackoverflow.com/users/1491895", "pm_score": 0, "selected": false, "text": "," }, { "answer_id": 74450238, "author": "chovy", "author_id": 33522, "author_profile": "https://Stackoverflow.com/users/33522", "pm_score": 0, "selected": false, "text": "falsey" }, { "answer_id": 74450354, "author": "Yanick Rochon", "author_id": 320700, "author_profile": "https://Stackoverflow.com/users/320700", "pm_score": 2, "selected": true, "text": "let string_Data = `01226,Grover Cleveland,Anna,Uganda,Crucial Ltd,Tested Mutual B.V,Calvin Coolidge,\n 77110,John F. Kennedy,hora,Bosnia Herzegovina,Formal,Papal Corporation,Franklin Roosevelt,\n 29552,Lyndon B. Johnson,Margaret,Palau,Summaries Holdings Inc,Customize,Rutherford B. Hayes,`;\n\nlet making_Array = csv => {\n var data = [];\n\n for (let dataAry of csv.split('\\n')) {\n // 1. trim both ends of the line for white space, tab, etc.\n // 2. remove any last trailing comma\n // 3. split using comma separator\n data.push(dataAry.trim().replace(/,$/, '').split(','));\n }\n return data;\n\n}\nconsole.log(making_Array(string_Data));" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33522/" ]
74,450,174
<p>I have a Java class with a nested protected class in it. In a method of another class (and in another package) I have to make a list of such nested protected type.</p> <p>Is there a way to do this in Java?</p> <pre><code>// SomeClass.java package stuff; public class SomeClass { protected class Nested { int x; public Nested setX(int arg) { x = x; return this; } public int getX() { return x; } } public Nested make(int x) { return new Nested().setX(x); } } </code></pre> <pre><code>// MyClass.java package project; import java.util.List; import java.util.ArrayList; import stuff.SomeClass; public class MyClass { public SomeClass instance; // I don't know what I should insert ... public List&lt; /* ... here... */ ?&gt; method() { var list = new ArrayList&lt; /* ... and here... */ &gt;(); list.add(instance.make(1)); list.add(instance.make(2)); return list; // ... to return an ArrayList&lt;SomeClass.Nested&gt; } } </code></pre> <p>Maybe something like the C++ <code>decltype()</code> or some kind of template deduction whould work!</p> <p>Even some reflection magic would be ok for me.</p> <p>PS. I whuld not modify SomeClass</p>
[ { "answer_id": 74450252, "author": "Allan J.", "author_id": 9680087, "author_profile": "https://Stackoverflow.com/users/9680087", "pm_score": 1, "selected": false, "text": "Nested" }, { "answer_id": 74450293, "author": "Code-Apprentice", "author_id": 1440565, "author_profile": "https://Stackoverflow.com/users/1440565", "pm_score": 2, "selected": false, "text": "Nested" }, { "answer_id": 74450445, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 0, "selected": false, "text": "static" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4322265/" ]
74,450,186
<p>Thanks to this <a href="https://stackoverflow.com/a/59697842/16297405">answer</a> i can see QuickLook preview of a pdf embedded in my swiftui view.</p> <p>But it's only to preview the pdf that's stored in the app bundle resource. How do i use NSOpenPanel to choose a file and display it in the QLPreviewView?</p> <pre><code>import SwiftUI import AppKit import Quartz func loadPreviewItem(with name: String) -&gt; NSURL { let file = name.components(separatedBy: &quot;.&quot;) let path = Bundle.main.path(forResource: file.first!, ofType: file.last!) let url = NSURL(fileURLWithPath: path ?? &quot;&quot;) print(url) return url } struct MyPreview: NSViewRepresentable { var fileName: String func makeNSView(context: NSViewRepresentableContext&lt;MyPreview&gt;) -&gt; QLPreviewView { let preview = QLPreviewView(frame: .zero, style: .normal) preview?.autostarts = true preview?.previewItem = loadPreviewItem(with: fileName) as QLPreviewItem return preview ?? QLPreviewView() } func updateNSView(_ nsView: QLPreviewView, context: NSViewRepresentableContext&lt;MyPreview&gt;) { } typealias NSViewType = QLPreviewView } struct ContentView: View { var body: some View { // example.pdf is expected in app bundle resources VStack { MyPreview(fileName: &quot;testing.pdf&quot;) Divider() } Button(&quot;Select PDF&quot;) { let openPanel = NSOpenPanel() openPanel.allowedFileTypes = [&quot;pdf&quot;] openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canChooseFiles = true openPanel.runModal() } } } </code></pre> <p>*<strong>UPDATE</strong></p> <p>This is what i've tried but nothing happens after i choose a pdf file with the openpanel. The View is blank. I think there's something that i haven't done correctly in the updateNSView.</p> <pre><code>struct ContentView: View { @State var filename = &quot;&quot; var body: some View { VStack { MyPreview(fileName: filename) Divider() } Button(&quot;Select PDF&quot;) { let openPanel = NSOpenPanel() openPanel.allowedFileTypes = [&quot;pdf&quot;] openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canChooseFiles = true openPanel.runModal() print(openPanel.url!.lastPathComponent) filename = openPanel.url!.lastPathComponent // } } } struct MyPreview: NSViewRepresentable { var fileName: String func makeNSView(context: NSViewRepresentableContext&lt;MyPreview&gt;) -&gt; QLPreviewView { let preview = QLPreviewView(frame: .zero, style: .normal) preview?.autostarts = true preview?.previewItem = loadPreviewItem(with: fileName) as QLPreviewItem return preview ?? QLPreviewView() } func updateNSView(_ nsView: QLPreviewView, context: NSViewRepresentableContext&lt;MyPreview&gt;) { let preview = QLPreviewView(frame: .zero, style: .normal) preview?.refreshPreviewItem() } typealias NSViewType = QLPreviewView } </code></pre> <p>*<strong>UPDATE 2</strong></p> <p>My latest attempt using now a model to update the file url after choosing one with the open panel but nothing still happens.</p> <p>It updates <strong>pdfurl</strong> successfully with the file url but the QLPreviewView doesn't update with the changes in <strong>updateNSView</strong>. I'm using the <a href="https://developer.apple.com/documentation/quicklookui/qlpreviewview/1504399-refreshpreviewitem" rel="nofollow noreferrer">refreshItemPreview()</a> which should work but i'm not sure what i'm doing wrong here</p> <pre><code>class PDFViewModel: ObservableObject { @Published var pdfurl = &quot;&quot; } struct MyPreview: NSViewRepresentable { @ObservedObject var pdfVM = PDFViewModel() func makeNSView(context: NSViewRepresentableContext&lt;MyPreview&gt;) -&gt; QLPreviewView { let preview = QLPreviewView(frame: .zero, style: .normal) preview?.previewItem = NSURL(string: pdfVM.pdfurl) return preview ?? QLPreviewView() } func updateNSView(_ nsView: QLPreviewView, context: NSViewRepresentableContext&lt;MyPreview&gt;) { let preview = QLPreviewView(frame: .zero, style: .normal) preview?.refreshPreviewItem() } typealias NSViewType = QLPreviewView } struct ContentView: View { @ObservedObject var pdfVM = PDFViewModel() var body: some View { VStack { MyPreview() Divider() } Button(&quot;Select PDF&quot;) { let openPanel = NSOpenPanel() openPanel.allowedFileTypes = [&quot;pdf&quot;] openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canChooseFiles = true openPanel.runModal() pdfVM.pdfurl = &quot;\(openPanel.url!)&quot; print(&quot;the url is now \(pdfVM.pdfurl)&quot;) } } } </code></pre>
[ { "answer_id": 74450252, "author": "Allan J.", "author_id": 9680087, "author_profile": "https://Stackoverflow.com/users/9680087", "pm_score": 1, "selected": false, "text": "Nested" }, { "answer_id": 74450293, "author": "Code-Apprentice", "author_id": 1440565, "author_profile": "https://Stackoverflow.com/users/1440565", "pm_score": 2, "selected": false, "text": "Nested" }, { "answer_id": 74450445, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 0, "selected": false, "text": "static" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16297405/" ]
74,450,189
<p>I am using Ubuntu 22.04 with windows WSL, and have installed JDK 19.01 and Maven inside this, and have imported a file from the WSL into IntelliJ Idea to work on, however once I run a class, IntelliJ &quot;builds&quot; <strong>for upwards of half an hour</strong>, hanging on the messages of &quot;Executing pre-compile tasks...&quot; and &quot;Preparing WSL build environment...&quot;. Obviously this is a pain and I need to know how to fix it.</p> <p><img src="https://i.stack.imgur.com/jCiIB.png" alt="IntelliJ version 2022.2.3" /></p> <p>I've tried to reinstall my JDK in Ubuntu and set the JAVA_HOME variable, which I've checked and have no issues with. I've tried to reinstall IntelliJ, and disabled my firewall/made exceptions, and I've changed the SDK being used inside IntelliJ, all to no success.</p> <p>Here are logs from inside the Ubuntu terminal showing my JDK and Maven installations:</p> <pre><code>user@user  \~  mvn -v Apache Maven 3.6.3 Maven home: /usr/share/maven Java version: 19.0.1, vendor: Private Build, runtime: /usr/lib/jvm/java-19-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: &quot;linux&quot;, version: &quot;5.10.16.3-microsoft-standard-wsl2&quot;, arch: &quot;amd64&quot;, family: &quot;unix&quot; user@user  \~  javac -version javac 19.0.1 user@user  \~  java -version openjdk version &quot;19.0.1&quot; 2022-10-18 OpenJDK Runtime Environment (build 19.0.1+10-Ubuntu-1ubuntu122.04) OpenJDK 64-Bit Server VM (build 19.0.1+10-Ubuntu-1ubuntu122.04, mixed mode, sharing) user@user  \~  echo $JAVA_HOME /usr/lib/jvm/java-19-openjdk-amd64 user@user  \~  which java /usr/bin/java user@user  \~  which javac /usr/bin/javac </code></pre>
[ { "answer_id": 74450252, "author": "Allan J.", "author_id": 9680087, "author_profile": "https://Stackoverflow.com/users/9680087", "pm_score": 1, "selected": false, "text": "Nested" }, { "answer_id": 74450293, "author": "Code-Apprentice", "author_id": 1440565, "author_profile": "https://Stackoverflow.com/users/1440565", "pm_score": 2, "selected": false, "text": "Nested" }, { "answer_id": 74450445, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 0, "selected": false, "text": "static" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512760/" ]
74,450,190
<p>Im learning about <code>SwiftUI</code> for macOS development, and Im wondering what would be the right approach when creating Managers, services etc. These are objects not related to the UI - strictly business logic things, not even <code>ViewModels</code>. Should I not use things like <code>ObservableObject</code>, <code>Published</code>, <code>AppStorage</code>, etc. in this kind of classes? On one hand it seems to be beneficial to add this, so that I can later easily use them with <code>ViewModels</code>, and bind directly to some properties. On the other hand it seems wrong - like these property wrappers are strictly <code>SwiftUI</code> related. So should I resign from these things in managers, services and other business logic objects?</p>
[ { "answer_id": 74450974, "author": "Krzysztof P", "author_id": 13780695, "author_profile": "https://Stackoverflow.com/users/13780695", "pm_score": 0, "selected": false, "text": "ObservableObject" }, { "answer_id": 74461604, "author": "Dávid Pásztor", "author_id": 4667835, "author_profile": "https://Stackoverflow.com/users/4667835", "pm_score": 2, "selected": true, "text": "ObservableObject" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450190", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4528716/" ]
74,450,198
<p>I would like to know, what is the concept of information flow in GUI based apps, or any other app with same problem. When you have two seperate classes and their objects, how is the messeging process done between them. For example you have a GUI and AppLogic.</p> <p>Scenario 1: Button is pressed -&gt; GUI is processing event -&gt; calls AppLogic method image_clicked()</p> <p>Scenario 2: HTTPServer gets a message -&gt; AppLogic receives image -&gt; AppLogic calls GUI method render_image()</p> <p><a href="https://i.stack.imgur.com/acjJ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/acjJ2.png" alt="enter image description here" /></a></p> <p>The problem is that you cannot reference classes each other because the first class does not know the second one (here AppLogic does not know GUI class):</p> <pre><code>class AppLogic(): gui : GUI def image_clicked(self): pass #not important class GUI(): app_logic : AppLogic def render_image(self): pass #not important </code></pre> <p>I know this is more like go to school and study problem, but I would like to know how these problems are sovled, or some common practices. At least link with some detailed information. I am not able to name the problem right to find the answer.</p> <h1>Edit:</h1> <p>I can use this code without explicit type declaration and it works. But when I want to call functions of gui in AppLogic class definition, intellisense does not hint anything, because it does not know the type of attribute <code>gui</code>. And I don't think that it is good practice to use code like that.</p> <pre><code>class AppLogic(): def __init__(self) -&gt; None: self.gui = None def image_clicked(self): pass #not important class GUI(): def __init__(self) -&gt; None: self.app_logic = None def render_image(self): pass #not important app = AppLogic() gui = GUI() app.gui = gui gui.app_logic = app </code></pre>
[ { "answer_id": 74450974, "author": "Krzysztof P", "author_id": 13780695, "author_profile": "https://Stackoverflow.com/users/13780695", "pm_score": 0, "selected": false, "text": "ObservableObject" }, { "answer_id": 74461604, "author": "Dávid Pásztor", "author_id": 4667835, "author_profile": "https://Stackoverflow.com/users/4667835", "pm_score": 2, "selected": true, "text": "ObservableObject" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12420879/" ]
74,450,224
<p>Configured Spring Boot according to a guide, still it cannot find my jsp views. So after launching I get this message &quot;This application has no explicit mapping for /error, so you are seeing this as a fallback.&quot;</p> <p>Any suggestions?</p> <p>pom:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;parent&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt; &lt;version&gt;2.7.5&lt;/version&gt; &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt; &lt;/parent&gt; &lt;groupId&gt;com.lib.secondtry&lt;/groupId&gt; &lt;artifactId&gt;MyLibrary&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;name&gt;MyLibrary&lt;/name&gt; &lt;description&gt;MyLibrary&lt;/description&gt; &lt;properties&gt; &lt;java.version&gt;11&lt;/java.version&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt; &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt; &lt;version&gt;9.0.44&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javax.servlet&lt;/groupId&gt; &lt;artifactId&gt;jstl&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt; &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt; &lt;version&gt;9.0.44&lt;/version&gt; &lt;scope&gt;provided&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt; &lt;scope&gt;provided&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt; &lt;scope&gt;runtime&lt;/scope&gt; &lt;optional&gt;true&lt;/optional&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.mysql&lt;/groupId&gt; &lt;artifactId&gt;mysql-connector-j&lt;/artifactId&gt; &lt;scope&gt;runtime&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>Properties:</p> <pre><code>spring.mvc.view.prefix=/webapp/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp </code></pre> <p>Controller:</p> <pre><code>@Controller public class FirstController { @GetMapping(&quot;/&quot;) public String sayHello(){ return &quot;hello&quot;; } } </code></pre> <p>Console:</p> <pre><code>2022-11-15 23:09:26.879 INFO 11896 --- [ restartedMain] c.l.s.mylibrary.MyLibraryApplication : No active profile set, falling back to 1 default profile: &quot;default&quot; 2022-11-15 23:09:26.907 INFO 11896 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2022-11-15 23:09:26.908 INFO 11896 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2022-11-15 23:09:27.369 INFO 11896 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-11-15 23:09:27.374 INFO 11896 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-11-15 23:09:27.375 INFO 11896 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68] 2022-11-15 23:09:27.495 INFO 11896 --- [ restartedMain] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 2022-11-15 23:09:27.500 INFO 11896 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-11-15 23:09:27.501 INFO 11896 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 593 ms 2022-11-15 23:09:27.663 INFO 11896 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2022-11-15 23:09:27.694 INFO 11896 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-11-15 23:09:27.700 INFO 11896 --- [ restartedMain] c.l.s.mylibrary.MyLibraryApplication : Started MyLibraryApplication in 1.008 seconds (JVM running for 1.342) 2022-11-15 23:09:43.705 INFO 11896 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-11-15 23:09:43.705 INFO 11896 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-11-15 23:09:43.706 INFO 11896 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms </code></pre> <p>In main I created webapp/WEB-INF/jsp/ and it didn't help.</p>
[ { "answer_id": 74450974, "author": "Krzysztof P", "author_id": 13780695, "author_profile": "https://Stackoverflow.com/users/13780695", "pm_score": 0, "selected": false, "text": "ObservableObject" }, { "answer_id": 74461604, "author": "Dávid Pásztor", "author_id": 4667835, "author_profile": "https://Stackoverflow.com/users/4667835", "pm_score": 2, "selected": true, "text": "ObservableObject" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20388189/" ]
74,450,274
<p>I created a little program as part of my learning experience using python crash course and the code worked pretty well yesterday. But now that I woke up and tried to launch the thing it refuses to do anything and says that &quot;self&quot; is not defined. I honestly have no idea why it happens and would very much like to know exactly what causes error and where I mistaken. Sorry if the question format is wrong and thanks in advance for any help.</p> <pre class="lang-py prettyprint-override"><code>import json class Save_user: &quot;&quot;&quot;Greet the user if the username presents.&quot;&quot;&quot; &quot;&quot;&quot;Ask the name otherwise.&quot;&quot;&quot; def __init__(self): &quot;&quot;&quot;Sets username; Calls greet_user()&quot;&quot;&quot; self.file_path = 'username.json' self.greet_user() def get_stored_username(self): &quot;&quot;&quot;Get the username if stored.&quot;&quot;&quot; try: with open(self.file_path) as f: self.username = json.load(f) except FileNotFoundError: return None else: return self.username def greet_user(self): &quot;&quot;&quot;Choose greet the user or store the username.&quot;&quot;&quot; self.get_stored_username() if self.username: self.if_same_user() else: self.store_name() def store_name(self): &quot;&quot;&quot;Store username.&quot;&quot;&quot; self.username = input(&quot;Enter your username: &quot;) with open(self.file_path, 'w') as f: json.dump(self.username, f) print(&quot;Great! We'll greet you next time!&quot;) def if_same_user(self): &quot;&quot;&quot;Check if the same user.&quot;&quot;&quot; print(f&quot;Are you {self.username}?&quot;) while True: response = input(&quot;Please, Enter 'yes' or 'no': \n&quot;) response = response.lower().strip() if response == 'yes' or response == 'y': print(f&quot;Welcome back, {self.username}!&quot;) break elif response == 'no' or response == 'n': self.store_name() break useame = Save_user() </code></pre> <p>The program should asks the user's name if the <code>json</code> file exists and create the file and store the name otherwise. I tried to set username to 0 in <code>__init__</code> module and I could launch the thing with text editor and .py format, visual studio, however is giving me an error. Again, thanks in advance for any help!</p> <p>UPD TraceBack:</p> <pre><code> Traceback (most recent call last): File &quot;c:\Users\Windows 10\Desktop\python_work\New folder\new.py&quot;, line 50, in &lt;module&gt; username = Save_user() ^^^^^^^^^^^ File &quot;c:\Users\Windows 10\Desktop\python_work\New folder\new.py&quot;, line 10, in __init__ self.greet_user() File &quot;c:\Users\Windows 10\Desktop\python_work\New folder\new.py&quot;, line 25, in greet_user if self.username: ^^^^^^^^^^^^^ AttributeError: 'Save_user' object has no attribute 'username' </code></pre>
[ { "answer_id": 74450974, "author": "Krzysztof P", "author_id": 13780695, "author_profile": "https://Stackoverflow.com/users/13780695", "pm_score": 0, "selected": false, "text": "ObservableObject" }, { "answer_id": 74461604, "author": "Dávid Pásztor", "author_id": 4667835, "author_profile": "https://Stackoverflow.com/users/4667835", "pm_score": 2, "selected": true, "text": "ObservableObject" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450274", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512835/" ]
74,450,279
<pre><code>var temp = [ { text:'some text and then % sign and then, again % sign', link: 'another text with %', }, ]; </code></pre> <p>I want to replace all <code>%</code> signs with <code>\%</code> in the <code>temp</code> array of objects. How can I do it?</p> <p><strong>Desired Output:</strong></p> <pre><code>var temp = [ { text:'some text and then \% sign and then, again \% sign', link: 'another text with \%', }, ]; </code></pre> <p>I've tried these two ways, but, none of them worked:</p> <p><strong>First one is using a for loop:</strong></p> <pre><code>for(let i = 0; i&lt;temp.length; i++) { temp[i].text = temp[i].text.replace(/%/g, '\\%'); temp[i].link = temp[i].link.replace(/%/g, '\\%'); } </code></pre> <p><strong>Output:</strong> It resulted in two backslashes.</p> <pre><code>[ { text: 'some text and then \\% sign and then, again \\% sign', link: 'another text with \\%' } ] </code></pre> <p><strong>Second way is using JSON.parse and JSON.stringify:</strong></p> <pre><code>temp = JSON.parse( JSON.stringify(temp).replace(/%/g, '\\%') ); </code></pre> <p><strong>Output:</strong> Compilation Error</p> <pre><code>undefined:1 [{&quot;text&quot;:&quot;some text and then % sign and then, again % sign&quot;,&quot;link&quot;:&quot;another text with %&quot;}]^ SyntaxError: Unexpected token % in JSON at position 30at JSON.parse (&lt;anonymous&gt;)at Object.&lt;anonymous&gt; (/tmp/bRVTxjVcfu.js:62:15)at Module._compile (internal/modules/cjs/loader.js:778:30)at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)at Module.load (internal/modules/cjs/loader.js:653:32)at tryModuleLoad (internal/modules/cjs/loader.js:593:12)at Function.Module._load (internal/modules/cjs/loader.js:585:3)at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)at startup (internal/bootstrap/node.js:283:19)at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3) </code></pre>
[ { "answer_id": 74450413, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 0, "selected": false, "text": "const temp = [{\n text: 'some text and then % sign and then, again % sign',\n link: 'another text with %',\n}, ];\n\nfor (const obj of temp) {\n for (const key in obj) {\n obj[key] = obj[key].replace(/%/g, String.raw`\\%`)\n }\n}\n\nconsole.log(temp)" }, { "answer_id": 74450421, "author": "James Trickey", "author_id": 4924767, "author_profile": "https://Stackoverflow.com/users/4924767", "pm_score": 3, "selected": true, "text": "const parsedTemp = temp.map(tempItem => Object.entries(tempItem)\n .reduce((acc, [key, value]) =>\n ({...acc, [key]: value.split('%').join('\\\\%')}), {})\n)\n" }, { "answer_id": 74458299, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 0, "selected": false, "text": "temp" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12045119/" ]
74,450,294
<p>These are my db tables:</p> <p>Users</p> <pre><code>| id | nme | |----|------| | 1 | Adam | | 2 | Bob | | 3 | Jan | | 4 | Nico | </code></pre> <p>Products</p> <pre><code>| id | price | |----|-------| | 1 | 500 | | 2 | 700 | | 3 | 900 | </code></pre> <p>Orders</p> <pre><code>| id | user_id | product_id | |----|---------|------------| | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 1 | 3 | | 7 | 3 | 1 | | 8 | 3 | 2 | | 9 | 3 | 3 | | 10 | 4 | 3 | </code></pre> <p>I want to get up to 2 users, and their products bought. I came with this:</p> <pre><code>SELECT users.id AS 'user_id', products.id AS 'product_id' FROM users INNER JOIN orders ON orders.user_id = users.id INNER JOIN products ON products.id = orders.product_id ORDER BY orders.id OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY </code></pre> <p>But this returns:</p> <pre><code>| user_id | product_id | |---------|------------| | 1 | 1 | | 1 | 2 | </code></pre> <p>What I want to get is up to 2 users, not orders. I want to get this:</p> <pre><code>| user_id | product_id | |---------|------------| | 1 | 1 | | 1 | 2 | | 1 | 3 | | 3 | 1 | | 3 | 2 | | 3 | 3 | </code></pre> <p>Any ideas?</p>
[ { "answer_id": 74450413, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 0, "selected": false, "text": "const temp = [{\n text: 'some text and then % sign and then, again % sign',\n link: 'another text with %',\n}, ];\n\nfor (const obj of temp) {\n for (const key in obj) {\n obj[key] = obj[key].replace(/%/g, String.raw`\\%`)\n }\n}\n\nconsole.log(temp)" }, { "answer_id": 74450421, "author": "James Trickey", "author_id": 4924767, "author_profile": "https://Stackoverflow.com/users/4924767", "pm_score": 3, "selected": true, "text": "const parsedTemp = temp.map(tempItem => Object.entries(tempItem)\n .reduce((acc, [key, value]) =>\n ({...acc, [key]: value.split('%').join('\\\\%')}), {})\n)\n" }, { "answer_id": 74458299, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 0, "selected": false, "text": "temp" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9901683/" ]
74,450,300
<p>I am trying to do some work in Google Sheets. I have to generate a report that shows when 80% of users are reached for certain metrics. I am trying to set up a table with all the data and add conditional formatting to each column so that once the running sum of the column values reach 80% or more the cell where this occurs is highlighted.</p> <p>For starters, is this even possible to achieve it really seems like it shouldn't be that hard. All i need to do is dynamically sum the values of a cell + the ones above it in the column and if that value is 80% or more add the formatting.</p> <p>I have tried using the Array, and Indirect and Sum functions but it never seems to properly apply to the specific cell, it either affects the entire column or just the last cell.</p> <p>Example</p> <p><a href="https://i.stack.imgur.com/iSLse.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iSLse.png" alt="Sample Data" /></a></p> <p>So in Column C I should see highlighting at row 4, but nothing I do with the conditional formatting seems to make this work.</p> <p>How can i input into a formula that for <code>current cell sum this value + all above</code> &amp; <code>if value is &gt;= 80% apply the formatting rule</code></p> <p>I am really at a loss for the syntax to do this in Excel or Google sheets. If anyone has any suggestions its greatly appreciated. I am not used to working with these application so please let me know if you have any ideas as to how i can achieve this, if its even possible.</p> <p>Cheers.</p>
[ { "answer_id": 74450841, "author": "player0", "author_id": 5632629, "author_profile": "https://Stackoverflow.com/users/5632629", "pm_score": 2, "selected": false, "text": "=(SUM(C$2:C2)>0.8)*(C2<>\"\")\n" }, { "answer_id": 74463668, "author": "d0rf47", "author_id": 12212051, "author_profile": "https://Stackoverflow.com/users/12212051", "pm_score": 1, "selected": true, "text": "=ARRAYFORMULA( IF(sum(C2:$C$2) >= 0.8 , true))" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12212051/" ]
74,450,307
<p>I wonder whether the below code is valid C++ code or if not using <code>co_return</code> results in undefined behavior.</p> <pre class="lang-cpp prettyprint-override"><code>IAsyncAction MyClass::MyCoroutine() { co_await someOtherClassInstance.SomeCoroutine(); } </code></pre> <p>I.e. is it necessary to adjust the code as follows?</p> <pre class="lang-cpp prettyprint-override"><code>IAsyncAction MyClass::MyCoroutine() { co_await someOtherClassInstance.SomeCoroutine(); co_return; } </code></pre> <p>If the behavior is not undefined, what is the best practice (always add <code>co_return</code> or not) and what is the justification for doing so?</p>
[ { "answer_id": 74450570, "author": "rturrado", "author_id": 260313, "author_profile": "https://Stackoverflow.com/users/260313", "pm_score": 1, "selected": false, "text": "Promise::return_void()" }, { "answer_id": 74450695, "author": "IInspectable", "author_id": 1889329, "author_profile": "https://Stackoverflow.com/users/1889329", "pm_score": 4, "selected": true, "text": "co_return;" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5548098/" ]
74,450,332
<p>I have these two methods:</p> <pre><code>public void method(final String param1, final Object... param2); public void method(final String param1, final String param2, final Object... param3); </code></pre> <p>If I call the first method this way:</p> <pre><code>method(new String(), new String(), new String()); </code></pre> <p>I'll get the second method because the parameters match perfectly with it. If I put the last two strings in a list I already can call the first one, but I want to know if there is another better way to do it.</p>
[ { "answer_id": 74450388, "author": "Bohemian", "author_id": 256196, "author_profile": "https://Stackoverflow.com/users/256196", "pm_score": 0, "selected": false, "text": "Object[]" }, { "answer_id": 74450451, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 2, "selected": false, "text": "method(new String(), (Object) new String(), new String());\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4487251/" ]
74,450,360
<p>How can i define my variable method in my function so that my integrate function can calculate the same integral via a chosen method ? Maybe i have to define an alias for the different functions?</p> <pre><code>import argparse def dummy_function(x_value): return 4/(1+x_value**2) def integrate(method,function,integration_range,n_slices): method = ? return integral_area def riemann(function, integration_range, n_slices): x_start = integration_range[0] x_stop = integration_range[1] delta = (x_stop-x_start) / n_slices divisions = [x_start + j*delta for j in range(n_slices)] integral_area=0 for x_value in divisions: integral_area += function(x_value)*delta return integral_area def trapezoid(function, integration_range, n_slices): x_start = integration_range[0] x_stop = integration_range[1] delta = (x_stop-x_start) / n_slices divisions = [x_start + j*delta for j in range(n_slices)] integral_area=0 for x_value in divisions: integral_area += (function(x_value)+function(x_value + delta))*delta/2 return integral_area def simpson(function, integration_range, n_slices): x_start = integration_range[0] x_stop = integration_range[1] delta = (x_stop-x_start) / n_slices divisions = [x_start + j*delta for j in range(n_slices)] integral_area=0 for x_value in divisions: integral_area += (function(x_value)+ 4*function(x_value + delta/2) + function(x_value + delta))*delta/6 return integral_area if __name__ == '__main__': parser = argparse.ArgumentParser(description='Calculate Integral') parser.add_argument('-s','--slices', type=int, default=1000000, help='Enter number of slices') parser.add_argument('-m','--method', choices=['riemann','trapezoid','simpson'], default='riemann' ,help='Enter integration method') args = parser.parse_args() N_SLICES = args.slices method = args.method INTEGRAL_RANGE = [0, 1] INTEGRAL_RESULT = integrate(method, dummy_function, INTEGRAL_RANGE, N_SLICES) print(&quot;Result:&quot;, INTEGRAL_RESULT) </code></pre> <p>i tried some ways but i get errors like 'str' object not callable etc.</p>
[ { "answer_id": 74450388, "author": "Bohemian", "author_id": 256196, "author_profile": "https://Stackoverflow.com/users/256196", "pm_score": 0, "selected": false, "text": "Object[]" }, { "answer_id": 74450451, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 2, "selected": false, "text": "method(new String(), (Object) new String(), new String());\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511749/" ]
74,450,378
<p>I'm using the new Cypress component test option for my frontend tests, and I absolutely love it. I'm using it as an integration test solution, mounting the root component of my react app and using Cypress to test extensive user interactivity with it. In nearly every way, it's working perfectly, despite its beta status.</p> <p>For API calls, I'm using the Cypress intercept() feature. Before each test I use intercept to define the mocked API responses I need for the test. It works great.</p> <p>What I've noticed, however, is if there is an API call that doesn't impact my test, but is still fired in the background, it'll cause a CONREFUSED error. In and of itself, this doesn't really impact my tests, it just outputs the error to the log. However, the completionist in me doesn't like this.</p> <p>Ideally, I'm hoping there is an option in Cypress where if any CONREFUSED errors occur in an ajax call, it'll fail the test. This may be out of scope for what Cypress offers, and I'm not really sure how to even accomplish it. However, if there is a way, I would love to integrate it into my test suite.</p>
[ { "answer_id": 74450519, "author": "onewaveadrian", "author_id": 7905854, "author_profile": "https://Stackoverflow.com/users/7905854", "pm_score": 0, "selected": false, "text": "on" }, { "answer_id": 74451685, "author": "TesterDick", "author_id": 18366749, "author_profile": "https://Stackoverflow.com/users/18366749", "pm_score": 2, "selected": false, "text": "cy.intercept(url, (req) => {\n req.continue((res) => {\n if (res.body.statusCode === 502) {\n throw new Error('Conncetion refused')\n }\n })\n})\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2223059/" ]
74,450,386
<p>I need to compare two datasets:</p> <p>DF1</p> <pre><code> Subj 1 2 3 0 Biotech Cell culture Bioinfo Immunology 1 Zoology Cell culture Immunology NaN 2 Math Trigonometry Algebra NaN 3 Microbio Biotech NaN NaN 4 Physics Optics NaN NaN </code></pre> <p>DF2</p> <pre><code> Subj 1 2 0 Biotech Bioinfo Immunology 1 Zoology Immunology Botany 2 Microbio NaN NaN 3 Physics Optics Quantumphy 4 Math Trigonometry NaN </code></pre> <p>How I want my result dataframe:</p> <pre><code> Subj 1 2 0 Biotech Bioinfo Immunology 1 Zoology Immunology NaN 2 Math Trigonometry NaN 3 Physics Optics NaN </code></pre> <p>I can't check row by row as the datasets are huge. The number of columns varies for both datasets, but rows are the same in number. Since the order of the row elements also vary, I can't simply use merge(). I tried compare function, but it either removes all common elements or forms a dataframe containing both. I can't seem to pick out just the common elements.</p>
[ { "answer_id": 74450519, "author": "onewaveadrian", "author_id": 7905854, "author_profile": "https://Stackoverflow.com/users/7905854", "pm_score": 0, "selected": false, "text": "on" }, { "answer_id": 74451685, "author": "TesterDick", "author_id": 18366749, "author_profile": "https://Stackoverflow.com/users/18366749", "pm_score": 2, "selected": false, "text": "cy.intercept(url, (req) => {\n req.continue((res) => {\n if (res.body.statusCode === 502) {\n throw new Error('Conncetion refused')\n }\n })\n})\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20406129/" ]
74,450,387
<p>I was using the replace method with the following regex to strip periods at the end of a string: <code>replace(/\.[^/.]+$/, &quot;&quot;);</code> . Now I want to change this to meet the following requirements:</p> <ul> <li>can't end with a period,</li> <li>can't contain only spaces</li> <li>can't contain the following characters: \ / * ? &quot; | : &lt; &gt;</li> </ul> <p>Is there a way to incorporate the other 2 rules with my rule that is already stripping the period?</p>
[ { "answer_id": 74450466, "author": "Dimava", "author_id": 5734961, "author_profile": "https://Stackoverflow.com/users/5734961", "pm_score": 1, "selected": false, "text": "s = s\n .replaceAll(/\\s/g, '')\n .replaceAll(/[\\\\/*?\"|:<>]/g, '')\n .replace(/\\.+$/, '')\n" }, { "answer_id": 74450590, "author": "Nathan Kulzer", "author_id": 7388671, "author_profile": "https://Stackoverflow.com/users/7388671", "pm_score": 0, "selected": false, "text": "/\\.+$|\\\\|\\/|\\*|\\?|\\\"|\\||\\:|\\<|\\>|^\\s+$/g" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17237933/" ]
74,450,398
<p>I want to make a triangle like this with php , but i try in local still fail how to code like the example above</p> <pre><code>&lt;?php $star=10; for($a=1; $a&lt;=$star; $a++){ for($c=$star; $c&gt;=$a; $c-=1){ echo &quot;*&quot;; } echo &quot;&lt;br&gt;&quot;; } ?&gt; </code></pre> <p>I have value 1225441. How to create output like this with looping php?</p> <pre><code>1000000 200000 20000 5000 400 40 1 </code></pre>
[ { "answer_id": 74450637, "author": "Austen Holland", "author_id": 6421617, "author_profile": "https://Stackoverflow.com/users/6421617", "pm_score": 2, "selected": true, "text": "<?php\n# Replace this with whatever is the source of your input.\n$input = '1225441';\n\n# get total number of characters in input\n$length = strlen($input);\n# foreach character in input\nfor ($i = 0; $i < $length; $i++) {\n # echo the character as many times as $length - $i - 1.\n echo $input[$i] . str_repeat(0, $length - $i - 1) . '<br>';\n}\n" }, { "answer_id": 74450683, "author": "José Carlos PHP", "author_id": 2826112, "author_profile": "https://Stackoverflow.com/users/2826112", "pm_score": 1, "selected": false, "text": "<?php\n\n$n = 1225441;\n\n$string = '' . $n; //Let`s have a string for better use string functions\n\nfor ($c = 0, $len = strlen($string); $c < $len; $c++) {\n echo substr($string, $c, 1);\n for ($k = $len - 1; $k > $c; $k--) {\n echo '0';\n }\n echo '<br />';\n}\n" }, { "answer_id": 74450947, "author": "Markus Zeller", "author_id": 2645713, "author_profile": "https://Stackoverflow.com/users/2645713", "pm_score": 0, "selected": false, "text": "$n = '1225441';\narray_reduce(str_split($n),fn($c,$i)=>$c-(print $i.str_repeat('0',$c).\"\\n\"),strlen($n)-1);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15967988/" ]
74,450,410
<p>example json</p> <pre class="lang-json prettyprint-override"><code>{ &quot;11var&quot;:&quot;value1&quot;, &quot;11var2&quot;:&quot;val2&quot;, &quot;11var3&quot;:&quot;val3&quot;, &quot;11var4&quot;:&quot;val444&quot;, &quot;11var5&quot;:&quot;val5&quot;, ..... } </code></pre> <p>how to convert this to a pojo in latest spring boot and jackson setup?</p> <p>PS: I know we can do <code>@JsonProperty(&quot;11var&quot;)</code> and so on for all variables. my point what are the other ways. and also main issue here we cant start variable names with numbers in java check <a href="https://stackoverflow.com/questions/44761101/why-cant-java-variable-names-start-with-a-number">here</a></p>
[ { "answer_id": 74453554, "author": "dev_in_progress", "author_id": 3330947, "author_profile": "https://Stackoverflow.com/users/3330947", "pm_score": 1, "selected": false, "text": "map" }, { "answer_id": 74453611, "author": "so-random-dude", "author_id": 6785908, "author_profile": "https://Stackoverflow.com/users/6785908", "pm_score": 0, "selected": false, "text": "@JsonSerialize(using = ItemSerializer.class)\npublic class Item {\n ...\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/175554/" ]
74,450,453
<p>C# 11:</p> <pre><code>file class C { public int IntField1; } file struct S { public int IntField1; } file class StructureVsClassWhenCopying { private static void v1() { System.Console.WriteLine(&quot;v1&quot;); } private static void v2() { System.Console.WriteLine(&quot;v2&quot;); } public static void Main() { C c1 = new(); c1.IntField1 = 1; C c2 = c1; c1.IntField1 = 2; System.Console.WriteLine(c2.IntField1); // 2, because class is a reference-type S s1 = new(); s1.IntField1 = 1; S s2 = s1; s1.IntField1 = 2; System.Console.WriteLine(s2.IntField1); // 1, because struct is a value type string str1 = &quot;old string&quot;; string str2 = str1; str1 = &quot;new string&quot;; System.Console.WriteLine(str2); // old string, because string is immutable System.Action a1 = v1; System.Action a2 = a1; a1 -= v1; a1 += v2; a2.Invoke(); //v1. Why? } } </code></pre> <p>I want to know about the copying of reference and value types. I have understood this example with classes (reference type), struct (value types) and strings (also reference types, but immutable). But delegates also are reference types, why do thay behave like structs and strings?</p>
[ { "answer_id": 74453554, "author": "dev_in_progress", "author_id": 3330947, "author_profile": "https://Stackoverflow.com/users/3330947", "pm_score": 1, "selected": false, "text": "map" }, { "answer_id": 74453611, "author": "so-random-dude", "author_id": 6785908, "author_profile": "https://Stackoverflow.com/users/6785908", "pm_score": 0, "selected": false, "text": "@JsonSerialize(using = ItemSerializer.class)\npublic class Item {\n ...\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,450,465
<p>I want to size the textfield based on text length...while typing it's length should be changed according to text..I was suggested to use IntrinsicWidth but its not working..</p> <pre><code>Container( height: 300, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(30) ), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 40.0), child: IntrinsicWidth( child: TextField( keyboardType: TextInputType.number, textAlign: TextAlign.center, style: TextStyle( fontSize: 30, ), decoration: InputDecoration( hintStyle: TextStyle(fontSize: 20,color: Colors.grey[400]), hintText: 'Enter Income Amount' ), ), ), ), </code></pre>
[ { "answer_id": 74450547, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "TextEditingController" }, { "answer_id": 74450907, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 1, "selected": false, "text": "bool isActive = false;\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18817235/" ]
74,450,529
<p>In Excel sheet I havea column data where some set of records are in 'mm/dd/yyyy' format and some are in 'mm-dd-yyyy'. But I need all records in one format with data type as &quot;DATE&quot;. How could I achieve?<a href="https://i.stack.imgur.com/rudK0.png" rel="nofollow noreferrer">enter image description here</a> <a href="https://i.stack.imgur.com/53mQC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/53mQC.png" alt="enter image description here" /></a></p> <p>I have tried by changing data type into 'date' format but while doing transformations in power bi errors occured because there data format loaded as text format. it is not allowing any date operations.</p>
[ { "answer_id": 74450547, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "TextEditingController" }, { "answer_id": 74450907, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 1, "selected": false, "text": "bool isActive = false;\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512360/" ]
74,450,537
<p>I would like to create a DataFrame that has an &quot;index&quot; (integer) from a number of (sparse) Series, where the index (or primary key) is NOT necessarily consecutive integers. Each Series is like a vector of <code>(index, value)</code> tuple or <code>{index: value}</code> mapping.</p> <h2>(1) A small example</h2> <p>In Pandas, this is very easy as we can create a DataFrame at a time, like</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; pd.DataFrame({ &quot;A&quot;: {0: 'a', 20: 'b', 40: 'c'}, &quot;B&quot;: {10: 'd', 20: 'e', 30: 'f'}, &quot;C&quot;: {20: 'g', 30: 'h'}, }).sort_index() A B C 0 a NaN NaN 10 NaN d NaN 20 b e g 30 NaN f h 40 c NaN NaN </code></pre> <p>but I can't find an easy way to achieve a similar result with Polars. As described in <a href="https://pola-rs.github.io/polars-book/user-guide/coming_from_pandas.html" rel="nofollow noreferrer">Coming from Pandas</a>, Polars does not use an index unlike Pandas, and each row is indexed by its integer position in the table; so I might need to represent an &quot;indexed&quot; Series with a 2-column DataFrame:</p> <pre class="lang-py prettyprint-override"><code>A = pl.DataFrame({ &quot;index&quot;: [0, 20, 40], &quot;A&quot;: ['a', 'b', 'c'] }) B = pl.DataFrame({ &quot;index&quot;: [10, 20, 30], &quot;B&quot;: ['d', 'e', 'f'] }) C = pl.DataFrame({ &quot;index&quot;: [20, 30], &quot;C&quot;: ['g', 'h'] }) </code></pre> <p>I tried to combine these <em>multiple</em> DataFrames, joining on the <code>index</code> column:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; A.join(B, on='index', how='outer').join(C, on='index', how='outer').sort(by='index') shape: (5, 4) ┌───────┬──────┬──────┬──────┐ │ index ┆ A ┆ B ┆ C │ │ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ str ┆ str ┆ str │ ╞═══════╪══════╪══════╪══════╡ │ 0 ┆ a ┆ null ┆ null │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ │ 10 ┆ null ┆ d ┆ null │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ │ 20 ┆ b ┆ e ┆ g │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ │ 30 ┆ null ┆ f ┆ h │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ │ 40 ┆ c ┆ null ┆ null │ └───────┴──────┴──────┴──────┘ </code></pre> <p>This gives the result I want, but I wonder:</p> <ul> <li>(i) if there is there more concise way to do this over many columns, and</li> <li>(ii) how make this operation as efficient as possible.</li> </ul> <h3>Alternatives?</h3> <p>I also tried outer joins as this is one way to combine Dataframes with different number of columns and rows, as described above.</p> <p>Other alternatives I tried includes <a href="https://pola-rs.github.io/polars-book/user-guide/howcani/combining_data/concatenating.html" rel="nofollow noreferrer">diagonal concatenation</a>, but this does not deduplicate or join on <code>index</code>:</p> <pre><code>&gt;&gt;&gt; pl.concat([A, B, C], how='diagonal') index A B C 0 0 a None None 1 20 b None None 2 40 c None None 3 10 None d None 4 20 None e None 5 30 None f None 6 20 None None g 7 30 None None h </code></pre> <h2>(2) Efficiently Building a Large Table</h2> <p>The approach I found above gives desired results I'd want but I feel there must be a better way in terms of performance. Consider a case with more large tables; say 300,000 rows and 20 columns:</p> <pre class="lang-py prettyprint-override"><code>N, C = 300000, 20 pls = [] pds = [] for i in range(C): A = pl.DataFrame({ &quot;index&quot;: np.linspace(i, N*3-i, num=N, dtype=np.int32), f&quot;A{i}&quot;: np.arange(N, dtype=np.float32), }) pls.append(A) B = A.to_pandas().set_index(&quot;index&quot;) pds.append(B) </code></pre> <p>The approach of joining two columns in a row is somewhat slow than I expected:</p> <pre class="lang-py prettyprint-override"><code>%%time F = functools.reduce(lambda a, b: a.join(b, on='index', how='outer'), pls) F.sort(by='index') CPU times: user 1.49 s, sys: 97.8 ms, total: 1.59 s Wall time: 611 ms </code></pre> <p>or than one-pass creation in pd.DataFrame:</p> <pre class="lang-py prettyprint-override"><code>%%time pd.DataFrame({ f&quot;A{i}&quot;: pds[i][f'A{i}'] for i in range(C) }).sort_index() CPU times: user 230 ms, sys: 50.7 ms, total: 281 ms Wall time: 281 ms </code></pre>
[ { "answer_id": 74459797, "author": "kwk", "author_id": 20519471, "author_profile": "https://Stackoverflow.com/users/20519471", "pm_score": 0, "selected": false, "text": "pl.from_pandas" }, { "answer_id": 74461756, "author": "ritchie46", "author_id": 6717054, "author_profile": "https://Stackoverflow.com/users/6717054", "pm_score": 2, "selected": true, "text": "polars" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450537", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1534182/" ]
74,450,539
<p>I can't find a solution to this, so I'm asking here. I have a string that consists of several lines and in the string I want to increase exactly one number by one. For example:</p> <pre><code>[CENTER] [FONT=Courier New][COLOR=#00ffff][B][U][SIZE=4]{title}[/SIZE][/U][/B][/COLOR][/FONT] [IMG]{cover}[/IMG] [IMG]IMAGE[/IMG][/CENTER] [QUOTE] {description_de} [/QUOTE] [CENTER] [IMG]IMAGE[/IMG] [B]Duration: [/B]~5 min [B]Genre: [/B]Action [B]Subgenre: [/B]Mystery, Scifi [B]Language: [/B]English [B]Subtitles: [/B]German [B]Episodes: [/B]01/5 [IMG]IMAGE[/IMG] [spoiler] [spoiler=720p] [CODE=rich][color=Turquoise] {mediaInfo1} [/color][/code] [/spoiler] [spoiler=1080p] [CODE=rich][color=Turquoise] {mediaInfo2} [/color][/code] [/spoiler] [/spoiler] [hide] [IMG]IMAGE[/IMG] [/hide] [/CENTER] </code></pre> <p>I'm getting this string from a request and I want to increment the episode by 1. So from 01/5 to 02/5.</p> <p>What is the best way to make this possible?</p> <p>I tried to solve this via regex but failed miserably.</p>
[ { "answer_id": 74459797, "author": "kwk", "author_id": 20519471, "author_profile": "https://Stackoverflow.com/users/20519471", "pm_score": 0, "selected": false, "text": "pl.from_pandas" }, { "answer_id": 74461756, "author": "ritchie46", "author_id": 6717054, "author_profile": "https://Stackoverflow.com/users/6717054", "pm_score": 2, "selected": true, "text": "polars" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16558339/" ]
74,450,618
<p>Assume a table like this (in actuality I have 50 date columns to compare):</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>MY_DATE_1</th> <th>MY_DATE_2</th> <th>MY_DATE 3</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2022-10-1</td> <td>2022-11-1</td> <td>2022-12-1</td> </tr> <tr> <td>2</td> <td>2022-10-31</td> <td>2022-11-31</td> <td>2022-12-31</td> </tr> </tbody> </table> </div> <p>For each record, I want to get the <strong>most recent, non-blank past date</strong> (less than today's date) looking across all date columns.</p> <p>So I would want these results (given a current date of 2022-11-15):</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>LATEST_DATE</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2022-11-1</td> </tr> <tr> <td>2</td> <td>2022-10-31</td> </tr> </tbody> </table> </div> <p>I found this code elsewhere, but it just gets the max date across columns, and I need to add the condition somewhere for &quot;max past&quot; and not just &quot;max overall&quot; but I'm not experienced with <code>CROSS APPLY</code> and don't know if I can modify this query or if there's another way to write it that will work.</p> <pre><code>SELECT MA.MaxDate FROM &lt;my_table&gt; AS MT CROSS APPLY ( SELECT MAX(VA.LDate) FROM (VALUES(MT.MY_DATE_1),(MT.MY_DATE_2),(MT.MY_date_3)) VA(LDate) ) AS MA(MaxDate) </code></pre>
[ { "answer_id": 74459797, "author": "kwk", "author_id": 20519471, "author_profile": "https://Stackoverflow.com/users/20519471", "pm_score": 0, "selected": false, "text": "pl.from_pandas" }, { "answer_id": 74461756, "author": "ritchie46", "author_id": 6717054, "author_profile": "https://Stackoverflow.com/users/6717054", "pm_score": 2, "selected": true, "text": "polars" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3406483/" ]
74,450,623
<p>I am hoping somebody could please clarify what I am doing wrong. I am trying to replicate the strcpy function in C.</p> <p>The exercise requires us to create two loop through a src string and replace the content at each corresponding index at the destination string. My issue is when I create the test function in int main() I initialise a character array and assign it some content. It compiles fine however I get a norminette error:</p> <pre><code>// Method 1 char str1[5] = &quot;abcde&quot;;// Error: DECL_ASSIGN_LINE Declaration and assignation on a single line char str2[5] = &quot;fghij&quot;; //Error: DECL_ASSIGN_LINE Declaration and assignation on a single line </code></pre> <p>If I initialise and assign like bellow, Norminette is ok but I get a compilation error:</p> <pre><code>// Method 2 char str1[5] = &quot;abcde&quot;; char str2[5] = &quot;fghij&quot;; str1[] = &quot;abcde&quot;; // error: expected expression before ‘]’ token ... (with an arrow pointing to ] bracket) str2[] = &quot;fghij&quot;; // error: expected expression before ‘]’ token ... (with an arrow pointing to ] bracket) </code></pre> <pre><code>// Method 3 char str1[] = {'a', 'b', 'c', 'd', 'e','\0'}; // Error: DECL_ASSIGN_LINE Declaration and assignation on a single line char str2[] = {'f', 'g', 'h', 'i', 'j', '\0'};//Error: DECL_ASSIGN_LINE Declaration and assignation on a single line </code></pre> <p>I have also tried various methods including str[5] = &quot;abcde&quot; after declaration with no success. My question is how can I declare these character arrays to satisfy both the norminette and compiler?</p> <p>Also is my understand that in C, a character array and a string are interchangeable concepts? Thank you</p>
[ { "answer_id": 74459797, "author": "kwk", "author_id": 20519471, "author_profile": "https://Stackoverflow.com/users/20519471", "pm_score": 0, "selected": false, "text": "pl.from_pandas" }, { "answer_id": 74461756, "author": "ritchie46", "author_id": 6717054, "author_profile": "https://Stackoverflow.com/users/6717054", "pm_score": 2, "selected": true, "text": "polars" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19964689/" ]
74,450,641
<p>I need to insert multiple values into a table after checking if it doesn't exist using psycopg2. The query am using:</p> <pre><code>WITH data(name,proj_id) as ( VALUES ('hello',123),('hey',123) ) INSERT INTO keywords(name,proj_id) SELECT d.name,d.proj_id FROM data d WHERE NOT EXISTS (SELECT 1 FROM keywords u2 WHERE u2.name=d.name AND u2.proj_id=d.proj_id) </code></pre> <p>But how to format or add the values section from tuple to <strong>('hello',123),('hey',123)</strong> in query.</p>
[ { "answer_id": 74451088, "author": "Zegarek", "author_id": 5298879, "author_profile": "https://Stackoverflow.com/users/5298879", "pm_score": 1, "selected": false, "text": "conn" }, { "answer_id": 74459565, "author": "Bibin Hashley O P", "author_id": 14666733, "author_profile": "https://Stackoverflow.com/users/14666733", "pm_score": -1, "selected": false, "text": "insert_query = \"\"\"WITH data(name, proj_id) as (\n VALUES (%s,%s)\n ) \n INSERT INTO keywords(name, proj_id) \n SELECT d.name,d.proj_id FROM data d \n WHERE NOT EXISTS (\n SELECT 1 FROM keywords u2 \n WHERE u2.name = d.name AND u2.proj_id = d.proj_id)\"\"\"\ntuple_values = (('hello',123),('hey',123))\n \npsycopg2.extras.execute_batch(cursor,insert_query,tuple_values)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450641", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14666733/" ]
74,450,653
<pre><code>game.Players.PlayerAdded:Connect(function(player) script.Parent.Touched:Connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild(&quot;Humanoid&quot;) then local players = game:GetService(&quot;Players&quot;) local clone = game.Workspace.Sparkles:Clone() clone.Parent = game.Workspace clone.CanCollide = false clone.Position = script.Parent.Position script.Parent:Destroy() wait(1) clone:Destroy() local player = game.players.LocalPlayer players.LocalPlayer.leaderstats.gold.value = 10 end end) end) </code></pre> <p>Here, I'm trying to make a script where if you touch a chest it will give you gold[my stat name] but for some reason, it wont run properly. it wont give me the amount of gold i told it to</p>
[ { "answer_id": 74451088, "author": "Zegarek", "author_id": 5298879, "author_profile": "https://Stackoverflow.com/users/5298879", "pm_score": 1, "selected": false, "text": "conn" }, { "answer_id": 74459565, "author": "Bibin Hashley O P", "author_id": 14666733, "author_profile": "https://Stackoverflow.com/users/14666733", "pm_score": -1, "selected": false, "text": "insert_query = \"\"\"WITH data(name, proj_id) as (\n VALUES (%s,%s)\n ) \n INSERT INTO keywords(name, proj_id) \n SELECT d.name,d.proj_id FROM data d \n WHERE NOT EXISTS (\n SELECT 1 FROM keywords u2 \n WHERE u2.name = d.name AND u2.proj_id = d.proj_id)\"\"\"\ntuple_values = (('hello',123),('hey',123))\n \npsycopg2.extras.execute_batch(cursor,insert_query,tuple_values)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19513775/" ]
74,450,669
<p>is there any way to convert Arabic ي to the Persian ي in React JS? I have an array of data in Persian language which contains the Arabic ي . and that's because of bad language support for Persian.</p> <p>if I want to make a search functionality, I must enter ي instead ی and I can't force people to do this. how can I solve it?</p> <p>there's a similar question here but with C#.</p> <p>for example :</p> <pre><code>const items = [&quot;ماشین&quot;,&quot;هواپیما&quot;,&quot;موبایل&quot;,&quot;کامپیوتر&quot;] const searchedItem = items.filter(item=&gt;item===&quot;ماشین&quot;) </code></pre> <p>in order to search &quot;ماشین&quot; (car) I need to type it with ي . it won't work with regular ی</p>
[ { "answer_id": 74451088, "author": "Zegarek", "author_id": 5298879, "author_profile": "https://Stackoverflow.com/users/5298879", "pm_score": 1, "selected": false, "text": "conn" }, { "answer_id": 74459565, "author": "Bibin Hashley O P", "author_id": 14666733, "author_profile": "https://Stackoverflow.com/users/14666733", "pm_score": -1, "selected": false, "text": "insert_query = \"\"\"WITH data(name, proj_id) as (\n VALUES (%s,%s)\n ) \n INSERT INTO keywords(name, proj_id) \n SELECT d.name,d.proj_id FROM data d \n WHERE NOT EXISTS (\n SELECT 1 FROM keywords u2 \n WHERE u2.name = d.name AND u2.proj_id = d.proj_id)\"\"\"\ntuple_values = (('hello',123),('hey',123))\n \npsycopg2.extras.execute_batch(cursor,insert_query,tuple_values)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20395245/" ]
74,450,717
<p>I'm working on a 3D visualization of a network graph and the input to the 3D Visualization is an XML file with nodes and edges. The XML file is the output of a network analysis tool without proper 3d visualization capability. Unfortunately, this XML file cannot be read properly in the tool where I'm doing the 3D visualization. I'm not an expert in XML but know what the file should be transformed into, to make it a readable XML for my 3D visualization tool. I've been trying for 2-3 days now to transform the XML with XSLT but unable to solve. Hopefully someone can help.. The XML looks as following:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;graphml xmlns=&quot;http://graphml.graphdrawing.org/xmlns&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd&quot;&gt; &lt;key id=&quot;desc&quot; for=&quot;node&quot; attr.name=&quot;Description&quot; attr.type=&quot;string&quot;/&gt; &lt;key id=&quot;x&quot; for=&quot;node&quot; attr.name=&quot;x&quot; attr.type=&quot;float&quot;/&gt; &lt;key id=&quot;y&quot; for=&quot;node&quot; attr.name=&quot;y&quot; attr.type=&quot;float&quot;/&gt; &lt;key id=&quot;z&quot; for=&quot;node&quot; attr.name=&quot;z&quot; attr.type=&quot;float&quot;/&gt; &lt;key id=&quot;d1&quot; for=&quot;node&quot; attr.name=&quot;Node Component Identifier&quot; attr.type=&quot;string&quot;/&gt; &lt;key id=&quot;d2&quot; for=&quot;node&quot; attr.name=&quot;Node Degree&quot; attr.type=&quot;int&quot;/&gt; &lt;graph edgedefault=&quot;directed&quot;&gt; &lt;node id=&quot;n0&quot;&gt; &lt;data key=&quot;d1&quot;&gt;Component 1&lt;/data&gt; &lt;data key=&quot;d2&quot;&gt;10&lt;/data&gt; &lt;data key=&quot;desc&quot;&gt;Person Alpha&lt;/data&gt; &lt;data key=&quot;x&quot;&gt;17.0119&lt;/data&gt; &lt;data key=&quot;y&quot;&gt;-1.36144&lt;/data&gt; &lt;data key=&quot;z&quot;&gt;2.80569&lt;/data&gt; &lt;/node&gt; &lt;node id=&quot;n1&quot;&gt; &lt;data key=&quot;d1&quot;&gt;Component 1&lt;/data&gt; &lt;data key=&quot;d2&quot;&gt;10&lt;/data&gt; &lt;data key=&quot;desc&quot;&gt;Person Beta&lt;/data&gt; &lt;data key=&quot;x&quot;&gt;11.091&lt;/data&gt; &lt;data key=&quot;y&quot;&gt;1.183&lt;/data&gt; &lt;data key=&quot;z&quot;&gt;-3.55&lt;/data&gt; &lt;/node&gt; &lt;/graph&gt; &lt;/graphml&gt; </code></pre> <p>As an output, I need a much simpler format that looks like this (remove keys, remove d2):</p> <pre><code>&lt;graphml&gt; &lt;graph egedefault=&quot;directed&quot;&gt; &lt;node id=&quot;n0&quot;&gt; &lt;component&gt;Component 1&lt;/component&gt; &lt;desc&gt;Person Alpha&lt;/desc&gt; &lt;x&gt;17.0119&lt;/x&gt; &lt;y&gt;-1.36144&lt;/y&gt; &lt;z&gt;2.80569&lt;/z&gt; &lt;/node&gt; &lt;node id=&quot;n1&quot;&gt; &lt;component&gt;Component 1&lt;/component&gt; &lt;desc&gt;Person Beta&lt;/desc&gt; &lt;x&gt;11.091&lt;/x&gt; &lt;y&gt;1.183&lt;/y&gt; &lt;z&gt;-3.55&lt;/z&gt; &lt;/node&gt; &lt;/graph&gt; &lt;/graphml&gt; </code></pre> <p>Is there someone that can help me to achieve my goal using XSLT transformation?</p> <p>I tried severel tips including:</p> <ul> <li><a href="https://stackoverflow.com/questions/321860/how-to-remove-elements-from-xml-using-xslt-with-stylesheet-and-xsltproc">How to remove elements from xml using xslt with stylesheet and xsltproc?</a></li> <li><a href="https://stackoverflow.com/questions/2641681/remove-xml-tags-with-xslt">remove xml tags with XSLT</a></li> <li><a href="https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)</a></li> </ul> <p>They are all a bit different from my example and therefore not getting the right end result.</p>
[ { "answer_id": 74451004, "author": "Sebastien", "author_id": 9871012, "author_profile": "https://Stackoverflow.com/users/9871012", "pm_score": 2, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:graph=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"graph\"\n version=\"1.0\">\n\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"graph:graphml\">\n <graphml>\n <xsl:apply-templates select=\"*\"/>\n </graphml>\n </xsl:template>\n \n <xsl:template match=\"graph:key\"/>\n \n <xsl:template match=\"graph:graph\">\n <graph>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </graph>\n </xsl:template>\n \n <xsl:template match=\"graph:node\">\n <node>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </node>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d1']\">\n <component>\n <xsl:value-of select=\".\"/>\n </component>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d2']\"/>\n \n <xsl:template match=\"graph:data[@key='desc']\">\n <desc>\n <xsl:value-of select=\".\"/>\n </desc>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='x']\">\n <x>\n <xsl:value-of select=\".\"/>\n </x>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='y']\">\n <y>\n <xsl:value-of select=\".\"/>\n </y>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='z']\">\n <z>\n <xsl:value-of select=\".\"/>\n </z>\n </xsl:template>\n \n</xsl:stylesheet>\n" }, { "answer_id": 74451162, "author": "Snehan Solomon", "author_id": 872533, "author_profile": "https://Stackoverflow.com/users/872533", "pm_score": 0, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n xmlns:b=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"xs b\"\n version=\"2.0\">\n <xsl:output method=\"xml\" indent=\"yes\"></xsl:output>\n <xsl:template match=\"/b:graphml/b:graph\">\n <graphml>\n <graph egedefault=\"{@edgedefault}\">\n <xsl:for-each select=\"b:node\">\n <node id=\"{@id}\">\n <component><xsl:value-of select=\"b:data[@key='d1']\"/></component>\n <desc><xsl:value-of select=\"b:data[@key='desc']\"/></desc>\n <x><xsl:value-of select=\"b:data[@key='x']\"/></x>\n <y><xsl:value-of select=\"b:data[@key='y']\"/></y>\n <z><xsl:value-of select=\"b:data[@key='z']\"/></z>\n </node>\n </xsl:for-each>\n </graph>\n </graphml>\n </xsl:template>\n</xsl:stylesheet>\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512690/" ]
74,450,753
<p>I am trying to figure out how to connect my Rust app to a surrealdb database that is running inside a docker container.</p> <p>The docs on the SurrealDB website only specify three ways to connect to the database, these are: memory, file, and tikv.</p> <p>I am running surrealdb on docker as indicated on their website:</p> <pre><code>docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start </code></pre> <p>I tried doing something like the following:</p> <pre><code>let ds = Datastore::new(&quot;http://0.0.0.0:8000&quot;).await?; </code></pre> <p>But I am getting the following error:</p> <pre><code>value: Ds(&quot;Unable to load the specified datastore&quot;)' </code></pre> <p>Perhaps it has not been implemented yet?</p>
[ { "answer_id": 74451004, "author": "Sebastien", "author_id": 9871012, "author_profile": "https://Stackoverflow.com/users/9871012", "pm_score": 2, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:graph=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"graph\"\n version=\"1.0\">\n\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"graph:graphml\">\n <graphml>\n <xsl:apply-templates select=\"*\"/>\n </graphml>\n </xsl:template>\n \n <xsl:template match=\"graph:key\"/>\n \n <xsl:template match=\"graph:graph\">\n <graph>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </graph>\n </xsl:template>\n \n <xsl:template match=\"graph:node\">\n <node>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </node>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d1']\">\n <component>\n <xsl:value-of select=\".\"/>\n </component>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d2']\"/>\n \n <xsl:template match=\"graph:data[@key='desc']\">\n <desc>\n <xsl:value-of select=\".\"/>\n </desc>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='x']\">\n <x>\n <xsl:value-of select=\".\"/>\n </x>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='y']\">\n <y>\n <xsl:value-of select=\".\"/>\n </y>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='z']\">\n <z>\n <xsl:value-of select=\".\"/>\n </z>\n </xsl:template>\n \n</xsl:stylesheet>\n" }, { "answer_id": 74451162, "author": "Snehan Solomon", "author_id": 872533, "author_profile": "https://Stackoverflow.com/users/872533", "pm_score": 0, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n xmlns:b=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"xs b\"\n version=\"2.0\">\n <xsl:output method=\"xml\" indent=\"yes\"></xsl:output>\n <xsl:template match=\"/b:graphml/b:graph\">\n <graphml>\n <graph egedefault=\"{@edgedefault}\">\n <xsl:for-each select=\"b:node\">\n <node id=\"{@id}\">\n <component><xsl:value-of select=\"b:data[@key='d1']\"/></component>\n <desc><xsl:value-of select=\"b:data[@key='desc']\"/></desc>\n <x><xsl:value-of select=\"b:data[@key='x']\"/></x>\n <y><xsl:value-of select=\"b:data[@key='y']\"/></y>\n <z><xsl:value-of select=\"b:data[@key='z']\"/></z>\n </node>\n </xsl:for-each>\n </graph>\n </graphml>\n </xsl:template>\n</xsl:stylesheet>\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1219937/" ]
74,450,824
<p>I want the car spawn selected by the player.......</p> <p>but the problem is whenever the other local player select. the all car are same (mean player2 and player3).....</p> <p>but the there is no issue with the masterclient car (mean host player) the car are same which he selected......</p> <p>here is my code.....</p> <p>the both script are in defferent scene....</p> <pre><code> public GameObject Player; public GameObject Player2; public GameObject Player3; Vector2 randomPosition = new Vector2(Random.Range(minx, maxX), Random.Range(minY, maxY)); string car = PlayerPrefs.GetString(&quot;getcar&quot;); if(car== &quot;lamborgini&quot;) { PhotonNetwork.Instantiate(Player.name, randomPosition, Quaternion.identity); } else if (car == &quot;lam&quot;) { PhotonNetwork.Instantiate(Player2.name, randomPosition, Quaternion.identity); } else if (car == &quot;gini&quot; ) { PhotonNetwork.Instantiate(Player3.name, randomPosition, Quaternion.identity); } else { PhotonNetwork.Instantiate(Player3.name, randomPosition, Quaternion.identity); } </code></pre> <p>The below code in which the player select the car through name <a href="https://i.stack.imgur.com/DIa8Y.png" rel="nofollow noreferrer">enter image description here</a></p>
[ { "answer_id": 74451004, "author": "Sebastien", "author_id": 9871012, "author_profile": "https://Stackoverflow.com/users/9871012", "pm_score": 2, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:graph=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"graph\"\n version=\"1.0\">\n\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"graph:graphml\">\n <graphml>\n <xsl:apply-templates select=\"*\"/>\n </graphml>\n </xsl:template>\n \n <xsl:template match=\"graph:key\"/>\n \n <xsl:template match=\"graph:graph\">\n <graph>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </graph>\n </xsl:template>\n \n <xsl:template match=\"graph:node\">\n <node>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates select=\"*\"/>\n </node>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d1']\">\n <component>\n <xsl:value-of select=\".\"/>\n </component>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='d2']\"/>\n \n <xsl:template match=\"graph:data[@key='desc']\">\n <desc>\n <xsl:value-of select=\".\"/>\n </desc>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='x']\">\n <x>\n <xsl:value-of select=\".\"/>\n </x>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='y']\">\n <y>\n <xsl:value-of select=\".\"/>\n </y>\n </xsl:template>\n \n <xsl:template match=\"graph:data[@key='z']\">\n <z>\n <xsl:value-of select=\".\"/>\n </z>\n </xsl:template>\n \n</xsl:stylesheet>\n" }, { "answer_id": 74451162, "author": "Snehan Solomon", "author_id": 872533, "author_profile": "https://Stackoverflow.com/users/872533", "pm_score": 0, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n xmlns:b=\"http://graphml.graphdrawing.org/xmlns\"\n exclude-result-prefixes=\"xs b\"\n version=\"2.0\">\n <xsl:output method=\"xml\" indent=\"yes\"></xsl:output>\n <xsl:template match=\"/b:graphml/b:graph\">\n <graphml>\n <graph egedefault=\"{@edgedefault}\">\n <xsl:for-each select=\"b:node\">\n <node id=\"{@id}\">\n <component><xsl:value-of select=\"b:data[@key='d1']\"/></component>\n <desc><xsl:value-of select=\"b:data[@key='desc']\"/></desc>\n <x><xsl:value-of select=\"b:data[@key='x']\"/></x>\n <y><xsl:value-of select=\"b:data[@key='y']\"/></y>\n <z><xsl:value-of select=\"b:data[@key='z']\"/></z>\n </node>\n </xsl:for-each>\n </graph>\n </graphml>\n </xsl:template>\n</xsl:stylesheet>\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513177/" ]
74,450,838
<p>I have a composable for example</p> <pre><code>Box(modifier){ ... } </code></pre> <p>I want to share this view as an image with other apps, that's why I have to convert this Box into an image that can be shared with other apps such as WhatsApp etc. Thank you</p>
[ { "answer_id": 74450871, "author": "ScriptSecure Services", "author_id": 16119169, "author_profile": "https://Stackoverflow.com/users/16119169", "pm_score": 0, "selected": false, "text": "Box(\nmodifier: BoxModifier(\n shape: BoxShape.rectangle,\n color: Colors.red,\n),\nchild: Image.network(\n 'https://picsum.photos/250?image=9',\n),\n);\n" }, { "answer_id": 74451403, "author": "Thracian", "author_id": 5457853, "author_profile": "https://Stackoverflow.com/users/5457853", "pm_score": 3, "selected": true, "text": "val view: View = LocalView.current\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7798091/" ]
74,450,865
<p>I have below piece of code, What I am trying to do is add a new record at the 0th position and then sort the array based on the label. But I can't get it to work; I am getting an empty array.</p> <pre><code>const array = [{id: '3', name: 'name1'}, {id: '4', name: 'name2'}, {id: '5', name: 'name3'}] const items = array .map((sp) =&gt; ({ label: sp.name, value: sp.id })) .splice(0, 0, { label: '', value: '' }) .sort((a, b) =&gt; a.label - b.label); console.log(items); </code></pre>
[ { "answer_id": 74450930, "author": "ScriptSecure Services", "author_id": 16119169, "author_profile": "https://Stackoverflow.com/users/16119169", "pm_score": -1, "selected": false, "text": "const array = [{id: '3', name: 'name1'},\n{id: '4', name: 'name2'},\n{id: '5', name: 'name3'}]\n\nconst items = array\n .map((sp) => ({ label: sp.name, value: sp.id }))\n .splice(0, 0, { label: '', value: '' })\n .sort((a, b) => a.label - b.label);\n\narray = items;\n\nconsole.log(array);" }, { "answer_id": 74451084, "author": "Karolis", "author_id": 18782190, "author_profile": "https://Stackoverflow.com/users/18782190", "pm_score": 2, "selected": true, "text": "const array = [\n { id: '3', name: 'name1' },\n { id: '4', name: 'name2' },\n { id: '5', name: 'name3' }\n]\n\nconst items = array.map((sp) => ({ label: sp.name, value: sp.id }))\nitems.unshift({ label: '', value: ''})\nitems.sort((a, b) => a.value - b.value);\n\nconsole.log(items);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2349082/" ]
74,450,873
<p>I have an array of objects like below -</p> <pre><code>const studentDetails = [ {id:1, name:&quot;Mike&quot;, stream:&quot;Science&quot;, status:&quot;active&quot;}, {id:2, name:&quot;Kelly&quot;, stream:&quot;Commerce&quot;, status:&quot;inactive&quot;}, {id:3, name:&quot;Bob&quot;, stream:&quot;Law&quot;, status:&quot;inactive&quot;}, ] </code></pre> <p>What I want to do is map through the array and route to another page when the status is inactive.</p> <pre><code>studentDetails.map(studentDetail =&gt; { if(studentDetail.status === 'inactive'){ router.push(&quot;/pageB&quot;) } }) </code></pre> <p>My doubt here is that when we route to pageB when the <strong>id</strong> is 2, how will I continue the loop for <strong>id=3</strong></p> <p>Many Thanks</p>
[ { "answer_id": 74450927, "author": "Tomas Deans", "author_id": 20513153, "author_profile": "https://Stackoverflow.com/users/20513153", "pm_score": 0, "selected": false, "text": "const studentDetails = [\n {id:1, status:\"active\"},\n {id:2, status:\"inactive\"}\n]\n" }, { "answer_id": 74451008, "author": "Maxali", "author_id": 789377, "author_profile": "https://Stackoverflow.com/users/789377", "pm_score": 1, "selected": false, "text": "Array.find" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14833974/" ]
74,450,891
<p>10/2 is 5 but pyhton says its 5.0 I want it to be 5 while making 11/2 5.5 which still makes it a float so basically thing that wouldnt be a float should be int but things like 4.3 should stay a float</p> <p>`</p> <pre><code>user_input = 10 prime_verification = user_input / 2 if isinstance(prime_verification, int): print(user_input) </code></pre> <p>the output is false because 5.0 is a float and I want it to be int so it becomes true`</p>
[ { "answer_id": 74450967, "author": "Raboro", "author_id": 18052690, "author_profile": "https://Stackoverflow.com/users/18052690", "pm_score": -1, "selected": false, "text": "//" }, { "answer_id": 74450990, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": -1, "selected": false, "text": "//" }, { "answer_id": 74451056, "author": "L Gartside", "author_id": 20513249, "author_profile": "https://Stackoverflow.com/users/20513249", "pm_score": 0, "selected": false, "text": "//" }, { "answer_id": 74451236, "author": "chepner", "author_id": 1126841, "author_profile": "https://Stackoverflow.com/users/1126841", "pm_score": 0, "selected": false, "text": "/" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513245/" ]
74,450,899
<p>I'm trying to compare all the numbers in this list and if any of them are within 1 of the number next to them in the list, if so then I want the command to print True. I realised that by applying the [x+1] to the last item in the list I'd be going out of the range of the list. I've tried to avoid this but I'm still getting the same error. Any help would be appreciated. Thanks :)</p> <pre><code>listed = [2,4,5,7] for x in listed[:-1]: if listed[x+1] - listed[x] == 1: print(True) else: print(False) </code></pre> <pre><code>IndexError Traceback (most recent call last) Input In [155], in &lt;cell line: 3&gt;() 1 listed = [2,4,5,7] 3 for x in listed[:-1]: ----&gt; 4 if listed[x+1] - listed[x] == 1: 5 print(True) 6 else: IndexError: list index out of range </code></pre> <hr />
[ { "answer_id": 74450962, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "itertools.pairwise" }, { "answer_id": 74450963, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 0, "selected": false, "text": "range(len(listed)-2, -1, -1)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512713/" ]
74,450,901
<p>In the development of a website that offers only static content, the backend aspect is necessary? It can be useful for optimize some aspects?</p> <p>Or is the backend only needed to handle authentications, dynamic content, etc.?</p>
[ { "answer_id": 74450962, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "itertools.pairwise" }, { "answer_id": 74450963, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 0, "selected": false, "text": "range(len(listed)-2, -1, -1)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20389783/" ]
74,450,944
<p>I am using a JWT authentication scheme for my app. I did some research about how to store and use access and refresh tokens, and I have several questions that I couldn't really find an answer to. For the app, I am using React for the frontend and .NET 6 Web API for the backened.</p> <p><strong>Question 1:</strong> Storing what where?<br /> Based on the research I did, local storage is not a good place to store a jwt token for security reasons. So probably the second best alternative would be HttpOnly cookie for the jwt token and local storage for the refresh token. However I did read some articles where jwt token is stored in local storage while the refresh token is stored as HttpOnly cookie. Which approach is better, and the pros and cons of each. P.S I will be rotating the tokens, i.e a new access and refresh token will be generated once the old jwt token is refreshed. Or even store it in memory such as redux state</p> <p><strong>Question 2:</strong> When to refresh JWT Token?<br /> Should the jwt token be refreshed just before it expires, such that the backend can verify the token, or is it fine to refresh the token after it expires (by bypassing the verificatoin when refreshing the token only i.e the refresh endpoint). Also should refreshing, be done by setting an timer/interval, or waiting for a request to fail?</p> <p><strong>Question 3:</strong> Accessing User Data and Expiry Date<br /> I am storing some user data, such as username and password in the jwt token so I can acees them in the frontend. The problem is that when setting the jwt token as HttpOnly cookie, since Javascript can't access the token, I won't be able to access user data and the token's data(such as jti and expiry date). For the user data, I could do a seperate request to access user data such as username and email, but for the JWT token's expiry date, how could I obtain it?</p> <p>I would appreciate answers to these questions or any feedback if someone faced similar issues and how you resolved them</p>
[ { "answer_id": 74450962, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "itertools.pairwise" }, { "answer_id": 74450963, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 0, "selected": false, "text": "range(len(listed)-2, -1, -1)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19187727/" ]
74,450,954
<pre><code>void main() { var values = List&lt;String&gt;.filled(3, 0); values[0] = 'abc'; values[1] = 'def'; values[2] = 'ghi'; } </code></pre> <p>I am trying to have a regular debugging experience with breakpoints on my code. However, I don't want to design a UI screen on my emulator just to run a code that does not require UI presentation.</p> <p>In other words, I am trying to run dart code in isolation from UI.</p>
[ { "answer_id": 74451040, "author": "THEODORE", "author_id": 9185856, "author_profile": "https://Stackoverflow.com/users/9185856", "pm_score": 0, "selected": false, "text": "dart --version" }, { "answer_id": 74451158, "author": "Gwhyyy", "author_id": 18670641, "author_profile": "https://Stackoverflow.com/users/18670641", "pm_score": 2, "selected": true, "text": "ctrl+shift+p" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,450,968
<p><img src="https://i.stack.imgur.com/L4Stp.png" alt="enter image description here" /></p> <p>I need to build a relief profile graph by coordinates, I have a csv file with 12,000,000 lines. searching through a csv file of the same height takes about 2 - 2.5 seconds. I rewrote the csv to parquet and it helped me save some time, it takes about 1.7 - 1 second to find one height. However, I need to build a profile for 500 - 2000 values, which makes the time very long. In the future, you may have to increase the base of the csv file, which will slow down this process even more. In this regard, my question is, is it possible to somehow reduce the processing time of values? Code example:</p> <pre><code>import dask.dataframe as dk import numpy as np import pandas as pd import time filename = 'n46_e032_1arc_v3.csv' df = dk.read_csv(filename) df.to_parquet('n46_e032_1arc_v3_parquet') Latitude1y, Longitude1x = 46.6276, 32.5942 Latitude2y, Longitude2x = 46.6451, 32.6781 sec, steps, k = 0.00027778, 1, 11.73 Latitude, Longitude = [Latitude1y], [Longitude1x] sin, cos = Latitude2y - Latitude1y, Longitude2x - Longitude1x y, x = Latitude1y, Longitude1x while Latitude[-1] &lt; Latitude2y and Longitude[-1] &lt; Longitude2x: y, x, steps = y + sec * k * sin, x + sec * k * cos, steps + 1 Latitude.append(y) Longitude.append(x) time_start = time.time() long, elevation_data = [], [] df2 = dk.read_parquet('n46_e032_1arc_v3_parquet') for i in range(steps + 1): elevation_line = df2[(Longitude[i] &lt;= df2['x']) &amp; (df2['x'] &lt;= Longitude[i] + sec) &amp; (Latitude[i] &lt;= df2['y']) &amp; (df2['y'] &lt;= Latitude[i] + sec)].compute() elevation = np.asarray(elevation_line.z.tolist()) if elevation[-1] &lt; 0: elevation_data.append(0) else: elevation_data.append(elevation[-1]) long.append(30 * i) plt.bar(long, elevation_data, width = 30) plt.show() print(time.time() - time_start) </code></pre>
[ { "answer_id": 74451040, "author": "THEODORE", "author_id": 9185856, "author_profile": "https://Stackoverflow.com/users/9185856", "pm_score": 0, "selected": false, "text": "dart --version" }, { "answer_id": 74451158, "author": "Gwhyyy", "author_id": 18670641, "author_profile": "https://Stackoverflow.com/users/18670641", "pm_score": 2, "selected": true, "text": "ctrl+shift+p" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19206620/" ]
74,450,970
<pre><code>answer = input('Enter a number: ') x = 10**(len(answer) - 1) print(answer, end = ' = ') for i in answer: if '0' in i: x = x//10 continue else: print('(' + i + ' * ' + str(x) + ')' , end = '') x = x//10 print(' + ', end = '') </code></pre> <p>so i have this problem, when i enter any number, everything is great but at the end there is an extra ' + ' that i do not want. Now normally this wouldnt be an issue with lists and .remove function, however i am not allowed to use these for this problem. I cannot come up with any sort of solution that does not involve functions</p> <p>I tried matching the length but it didnt work because of '0'</p>
[ { "answer_id": 74451055, "author": "Valery", "author_id": 20513338, "author_profile": "https://Stackoverflow.com/users/20513338", "pm_score": 1, "selected": false, "text": "else:\n print('(' + i + ' * ' + str(x) + ')' , end = '')\n x = x//10\n if x:\n print(' + ', end = '')\n" }, { "answer_id": 74451323, "author": "TestTest", "author_id": 20513584, "author_profile": "https://Stackoverflow.com/users/20513584", "pm_score": 0, "selected": false, "text": "if x and int(answer)%10 != 0:\n" }, { "answer_id": 74451500, "author": "Hai Vu", "author_id": 459745, "author_profile": "https://Stackoverflow.com/users/459745", "pm_score": 0, "selected": false, "text": "str.join()" }, { "answer_id": 74452097, "author": "pythonnoob3444", "author_id": 20513324, "author_profile": "https://Stackoverflow.com/users/20513324", "pm_score": 0, "selected": false, "text": "answer = input('Enter a number: ')\n\n#finds length of answer\nlength = 0\nfor n in answer:\n length += 1\nloop_counter = 0\n##\n\n\nzero_counter = 0\nmultiple_of_ten = 10\n\n#finds if answer is multiple of 10 and if so by what magnitude\nwhile True: \n if int(answer) % multiple_of_ten == 0:\n #counts the zeroes aka multiple of 10\n zero_counter += 1\n multiple_of_ten = multiple_of_ten*10\n else:\n break\n\n#finds the multiple of 10 needed for print output\nx = 10**(length - 1)\n\nprint(answer, end = ' = ')\nfor i in answer:\n # if its a 0 it will skip\n if '0' in i:\n x = x//10\n #still divises x by 10 for the next loop\n pass\n else:\n print('(' + i + ' * ' + str(x) + ')' , end = '')\n x = x//10\n \n #if position in loop and zeroes remaining plus one is equal to\n #the length of the integer provided, it means all the reamining\n #digits are 0\n if loop_counter + zero_counter + 1 == length:\n break\n else:\n #adds ' + ' between strings\n print(' + ', end = '')\n\n # keeps track of position in loop\n loop_counter += 1\n \n" }, { "answer_id": 74464257, "author": "pythonista", "author_id": 20522197, "author_profile": "https://Stackoverflow.com/users/20522197", "pm_score": 0, "selected": false, "text": "if x and int(answer)%10 != 0:\n\nEnter a number: 25\n25 = (2 * 10) + (5 * 1)\n\nEnter a number: 1000\n1000 = (1 * 1000)\n\nEnter a number: 117\n117 = (1 * 100) + (1 * 10) + (7 * 1)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74450970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513324/" ]
74,451,034
<p>In Python, if I install <code>mambaforge</code> or <code>conda</code> then I can make a file with extension <code>.yml</code> and then inside it list the name of packages I want to install alongside their specific versions. How can I do a similar way of installing packages in Julia? I understand that if I have already installed Julia packages by <code>add</code>command in package manager, then I have a file named <code>Project.toml</code> which I can use to install the same packages later. However, this still does not look as good as Python's way of installing packages.</p> <p>Upon further investigation I realized that to install Julia packages from an empty <code>Prokect.toml</code>file, I should add <code>[deps]</code>in the file followed by the name of packages I want and then give each package a <code>uuid</code>which can be found <a href="https://github.com/JuliaRegistries/General/blob/master/Registry.toml" rel="nofollow noreferrer">here</a>. For example:</p> <pre><code>[deps] Images = &quot;916415d5-f1e6-5110-898d-aaa5f9f070e0&quot; </code></pre> <p>After all , this is still tedious as it needs to find all those <code>uuid</code>s. How can I install packages in Julia the same way I described for Python?</p>
[ { "answer_id": 74451055, "author": "Valery", "author_id": 20513338, "author_profile": "https://Stackoverflow.com/users/20513338", "pm_score": 1, "selected": false, "text": "else:\n print('(' + i + ' * ' + str(x) + ')' , end = '')\n x = x//10\n if x:\n print(' + ', end = '')\n" }, { "answer_id": 74451323, "author": "TestTest", "author_id": 20513584, "author_profile": "https://Stackoverflow.com/users/20513584", "pm_score": 0, "selected": false, "text": "if x and int(answer)%10 != 0:\n" }, { "answer_id": 74451500, "author": "Hai Vu", "author_id": 459745, "author_profile": "https://Stackoverflow.com/users/459745", "pm_score": 0, "selected": false, "text": "str.join()" }, { "answer_id": 74452097, "author": "pythonnoob3444", "author_id": 20513324, "author_profile": "https://Stackoverflow.com/users/20513324", "pm_score": 0, "selected": false, "text": "answer = input('Enter a number: ')\n\n#finds length of answer\nlength = 0\nfor n in answer:\n length += 1\nloop_counter = 0\n##\n\n\nzero_counter = 0\nmultiple_of_ten = 10\n\n#finds if answer is multiple of 10 and if so by what magnitude\nwhile True: \n if int(answer) % multiple_of_ten == 0:\n #counts the zeroes aka multiple of 10\n zero_counter += 1\n multiple_of_ten = multiple_of_ten*10\n else:\n break\n\n#finds the multiple of 10 needed for print output\nx = 10**(length - 1)\n\nprint(answer, end = ' = ')\nfor i in answer:\n # if its a 0 it will skip\n if '0' in i:\n x = x//10\n #still divises x by 10 for the next loop\n pass\n else:\n print('(' + i + ' * ' + str(x) + ')' , end = '')\n x = x//10\n \n #if position in loop and zeroes remaining plus one is equal to\n #the length of the integer provided, it means all the reamining\n #digits are 0\n if loop_counter + zero_counter + 1 == length:\n break\n else:\n #adds ' + ' between strings\n print(' + ', end = '')\n\n # keeps track of position in loop\n loop_counter += 1\n \n" }, { "answer_id": 74464257, "author": "pythonista", "author_id": 20522197, "author_profile": "https://Stackoverflow.com/users/20522197", "pm_score": 0, "selected": false, "text": "if x and int(answer)%10 != 0:\n\nEnter a number: 25\n25 = (2 * 10) + (5 * 1)\n\nEnter a number: 1000\n1000 = (1 * 1000)\n\nEnter a number: 117\n117 = (1 * 100) + (1 * 10) + (7 * 1)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1381340/" ]
74,451,058
<p>SAP exports make all numbers into text I need to keep cells with leading zero as text while converting the rest if numeric text to number.</p> <pre><code>Sub ConvertUsingLoop() For Each r In Sheets(&quot;Loop&amp;CSng&quot;).UsedRange.SpecialCells(xlCellTypeConstants) If IsNumeric(r) Then r.Value = CSng(r.Value) r.NumberFormat = &quot;General&quot; End If Next End Sub </code></pre> <p>I'm trying incorporate <code>Left(Str, 1) = &quot;0&quot;</code> to exclude cells with leading zero. Thank you for your input.</p>
[ { "answer_id": 74451080, "author": "BigBen", "author_id": 9245853, "author_profile": "https://Stackoverflow.com/users/9245853", "pm_score": 3, "selected": true, "text": "Left$" }, { "answer_id": 74462429, "author": "Alvi", "author_id": 10442755, "author_profile": "https://Stackoverflow.com/users/10442755", "pm_score": 0, "selected": false, "text": "Sub Text2Number()\n On Error GoTo EH\n\n Application.ScreenUpdating = False\n Application.Calculation = xlCalculationManual\n Application.EnableEvents = False\n\nSet Rng = ActiveSheet.UsedRange\n\nRng.Cells(1, 1).Select\n\nFor i = 1 To Rng.Rows.Count\n For j = 1 To Rng.Columns.Count\n If Rng.Cells(i, j) <> \"\" Then\n Union(Selection, Rng.Cells(i, j)).Select\n End If\n Next j\nNext i\nFor Each c In Rng.Cells\n If IsNumeric(c.Value) And Left$(c.Value, 1) <> \"0\" Then\n c.NumberFormat = \"General\"\n c.Value = c.Value\n End If\nNext\nCleanUp:\n On Error Resume Next\n Application.ScreenUpdating = True\n Application.Calculation = xlCalculationAutomatic\n Application.EnableEvents = True\nExit Sub\nEH:\n ' Do error handling\n Resume CleanUp\nEnd Sub\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10442755/" ]
74,451,068
<p><a href="https://easyupload.io/lothof" rel="nofollow noreferrer">csv with df</a></p> <pre><code>import pandas as pd df = pd.read_csv('loves_1.csv') </code></pre> <p>in the column FuelPrices you'll see another df</p> <pre><code>df1 = pd.DataFrame(df['FuelPrices'][0]) df1 </code></pre> <p><a href="https://i.stack.imgur.com/q9LV1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q9LV1.png" alt="enter image description here" /></a></p> <p>so, how to extract values of LastPriceChangeDateTime and CashPrice as a key:value pair in to a new column of the main df for DIESEL only(df['diesel_price_change'])?</p> <p>eventually, i want to append in that column dict with LastPriceChangeDateTime: CashPrice every time it's changed</p> <p>i tried to loop with bunch of parameters but seems like somthing is messed up</p> <pre><code>for index, row in df.iterrows(): dfnew = pd.DataFrame(df['FuelPrices'][index]) dfnew['price_change'] = dfnew.apply(lambda row: {row['LastPriceChangeDateTime']: row['CashPrice']}, axis=1) df['diesel_price_change'][index] = dfnew.apply(lambda x: y['price_change'] for y in x if y['ProductName'] == 'DIESEL') </code></pre> <p>i receive &quot;'int' object is not iterable&quot;</p>
[ { "answer_id": 74451080, "author": "BigBen", "author_id": 9245853, "author_profile": "https://Stackoverflow.com/users/9245853", "pm_score": 3, "selected": true, "text": "Left$" }, { "answer_id": 74462429, "author": "Alvi", "author_id": 10442755, "author_profile": "https://Stackoverflow.com/users/10442755", "pm_score": 0, "selected": false, "text": "Sub Text2Number()\n On Error GoTo EH\n\n Application.ScreenUpdating = False\n Application.Calculation = xlCalculationManual\n Application.EnableEvents = False\n\nSet Rng = ActiveSheet.UsedRange\n\nRng.Cells(1, 1).Select\n\nFor i = 1 To Rng.Rows.Count\n For j = 1 To Rng.Columns.Count\n If Rng.Cells(i, j) <> \"\" Then\n Union(Selection, Rng.Cells(i, j)).Select\n End If\n Next j\nNext i\nFor Each c In Rng.Cells\n If IsNumeric(c.Value) And Left$(c.Value, 1) <> \"0\" Then\n c.NumberFormat = \"General\"\n c.Value = c.Value\n End If\nNext\nCleanUp:\n On Error Resume Next\n Application.ScreenUpdating = True\n Application.Calculation = xlCalculationAutomatic\n Application.EnableEvents = True\nExit Sub\nEH:\n ' Do error handling\n Resume CleanUp\nEnd Sub\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8291387/" ]
74,451,129
<p>I am getting some -Wnarrowing conversion errors when doubles are narrowed to floats. How can I do this in a well defined way? Preferably with an option in a template I can toggle to switch behavior from throwing exceptions, to clamping to the nearest value, or to simple truncation. I was looking at the <code>gsl::narrow</code> cast, but it seems that it just performs a static cast under the hood and a comparison follow up: <a href="https://stackoverflow.com/questions/52863643/understanding-gslnarrow-implementation">Understanding gsl::narrow implementation</a>. I would like something that is more robust, as according to <a href="https://stackoverflow.com/questions/367633/what-are-all-the-common-undefined-behaviours-that-a-c-programmer-should-know-a/367662#367662">What are all the common undefined behaviours that a C++ programmer should know about?</a> <code>static_cast&lt;&gt;</code> is UB if the value is unpresentable in the target type. I also really liked this implementation, but it also relies on a <code>static_cast&lt;&gt;</code>: <a href="https://stackoverflow.com/questions/53118960/can-a-static-castfloat-from-double-assigned-to-double-be-optimized-away">Can a static_cast&lt;float&gt; from double, assigned to double be optimized away?</a> I do not want to use boost for this. Are there any other options? It's best if this works in c++03, but c++0x(experimental c++11) is also acceptable... or 11 if really needed...</p> <p>Because someone asked, here's a simple toy example:</p> <pre><code>#include &lt;iostream&gt; float doubleToFloat(double num) { return static_cast&lt;float&gt;(num); } int main( int, char**){ double source = 1; // assume 1 could be any valid double value try{ float dest = doubleToFloat(source); std::cout &lt;&lt; &quot;Source: (&quot; &lt;&lt; source &lt;&lt; &quot;) Dest: (&quot; &lt;&lt; dest &lt;&lt; &quot;)&quot; &lt;&lt; std::endl; } catch( std::exception&amp; e ) { std::cout &lt;&lt; &quot;Got exception error: &quot; &lt;&lt; e.what() &lt;&lt; std::endl; } } </code></pre> <p>My primary interest is in adding error handling and safety to doubleToFloat(...), with various custom exceptions if needed.</p>
[ { "answer_id": 74451080, "author": "BigBen", "author_id": 9245853, "author_profile": "https://Stackoverflow.com/users/9245853", "pm_score": 3, "selected": true, "text": "Left$" }, { "answer_id": 74462429, "author": "Alvi", "author_id": 10442755, "author_profile": "https://Stackoverflow.com/users/10442755", "pm_score": 0, "selected": false, "text": "Sub Text2Number()\n On Error GoTo EH\n\n Application.ScreenUpdating = False\n Application.Calculation = xlCalculationManual\n Application.EnableEvents = False\n\nSet Rng = ActiveSheet.UsedRange\n\nRng.Cells(1, 1).Select\n\nFor i = 1 To Rng.Rows.Count\n For j = 1 To Rng.Columns.Count\n If Rng.Cells(i, j) <> \"\" Then\n Union(Selection, Rng.Cells(i, j)).Select\n End If\n Next j\nNext i\nFor Each c In Rng.Cells\n If IsNumeric(c.Value) And Left$(c.Value, 1) <> \"0\" Then\n c.NumberFormat = \"General\"\n c.Value = c.Value\n End If\nNext\nCleanUp:\n On Error Resume Next\n Application.ScreenUpdating = True\n Application.Calculation = xlCalculationAutomatic\n Application.EnableEvents = True\nExit Sub\nEH:\n ' Do error handling\n Resume CleanUp\nEnd Sub\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17985913/" ]
74,451,131
<p>I have data like below in google sheets</p> <pre><code>A B C 1 82 54.73 2 20 58.32 4 78 57.84 3 21 58.58 2 20 55.05 3 20 54.55 1 20 49.63 4 21 43.65 2 33 43.65 5 19 45.87 </code></pre> <p>In this column A can have repeated values</p> <p>I want to list the rows with same column A values together and order by column B and get below output</p> <pre><code>A B C 1 20 49.63 1 82 54.73 2 20 58.32 2 20 55.05 2 33 43.65 3 20 54.55 3 21 58.58 4 21 43.65 4 78 57.84 5 19 45.87 </code></pre> <p>Can this be achieved using google sheets. If so please suggest the formula to achieve same.</p>
[ { "answer_id": 74451329, "author": "ztiaa", "author_id": 17887301, "author_profile": "https://Stackoverflow.com/users/17887301", "pm_score": 2, "selected": true, "text": "SORT" }, { "answer_id": 74451447, "author": "player0", "author_id": 5632629, "author_profile": "https://Stackoverflow.com/users/5632629", "pm_score": 2, "selected": false, "text": "=QUERY(A1:C; \"where A is not null order by A,B\"; )\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3999424/" ]
74,451,132
<pre><code>public class Main { public static void main(String[] args) { // positive number int number = 6; System.out.print(&quot;Factors of &quot; + number + &quot; are: &quot;); // loop runs from 1 to 60 for (int i = 1; i &lt;= number; ++i) { // if number is divided by i // i is the factor if (number % i == 0) { System.out.print(i + &quot;,&quot;); } } } } </code></pre> <p>And my output is &quot;1,2,3,6,&quot; but i want it like &quot;1,2,3,6&quot; How can i do that?</p> <p>No matter what i do it did not worked.</p>
[ { "answer_id": 74451187, "author": "abel1502", "author_id": 13484707, "author_profile": "https://Stackoverflow.com/users/13484707", "pm_score": 1, "selected": false, "text": "List<String> divisors = new ArrayList<>();\n\n// loop runs from 1 to 60\nfor (int i = 1; i <= number; ++i) {\n\n // if number is divided by i\n // i is the factor\n if (number % i == 0) {\n divisors.add(String.valueOf(i));\n }\n}\n\nSystem.out.println(String.join(\",\", divisors));\n" }, { "answer_id": 74451193, "author": "ATP", "author_id": 9977151, "author_profile": "https://Stackoverflow.com/users/9977151", "pm_score": 1, "selected": true, "text": "'i'" }, { "answer_id": 74451374, "author": "Junior Dussouillez", "author_id": 2611798, "author_profile": "https://Stackoverflow.com/users/2611798", "pm_score": 1, "selected": false, "text": "var number = 60;\nSystem.out.println(\n IntStream.rangeClosed(1, number)\n .filter(i -> number % i == 0)\n .mapToObj(String::valueOf)\n .collect(Collectors.joining(\",\"))\n);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19415322/" ]
74,451,133
<p>I'm new to Django and I'm trying to learn it from <em>Django for Professionals</em> by William Vincent. After installing <code>django-allauth</code> and following the steps in the book, I managed to get the logging in and out the sign up functionality to work. However, when I go to <code>127.0.0.1:8000/admin</code>, I don't see a <a href="https://i.stack.imgur.com/BP2kd.png" rel="nofollow noreferrer">Sites section.</a> This section is later used in the book to change the site being referred to (<code>example.com</code>) in the registration confirmation email.</p> <p>I've searched for <code>django-allauth Site admin</code> in here and in the docs but I couldn't find anything about making the Sites section show.</p>
[ { "answer_id": 74451187, "author": "abel1502", "author_id": 13484707, "author_profile": "https://Stackoverflow.com/users/13484707", "pm_score": 1, "selected": false, "text": "List<String> divisors = new ArrayList<>();\n\n// loop runs from 1 to 60\nfor (int i = 1; i <= number; ++i) {\n\n // if number is divided by i\n // i is the factor\n if (number % i == 0) {\n divisors.add(String.valueOf(i));\n }\n}\n\nSystem.out.println(String.join(\",\", divisors));\n" }, { "answer_id": 74451193, "author": "ATP", "author_id": 9977151, "author_profile": "https://Stackoverflow.com/users/9977151", "pm_score": 1, "selected": true, "text": "'i'" }, { "answer_id": 74451374, "author": "Junior Dussouillez", "author_id": 2611798, "author_profile": "https://Stackoverflow.com/users/2611798", "pm_score": 1, "selected": false, "text": "var number = 60;\nSystem.out.println(\n IntStream.rangeClosed(1, number)\n .filter(i -> number % i == 0)\n .mapToObj(String::valueOf)\n .collect(Collectors.joining(\",\"))\n);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19505160/" ]
74,451,152
<p>Not sure how to add an optional action to TextFieldButton view and have the TextFieldClearButton view modifier accept the action.</p> <pre><code>struct TextFieldClearButton: ViewModifier { @Binding var fieldText: String var action: (() -&gt; Void)? = nil func body(content: Content) -&gt; some View { content .overlay { if !fieldText.isEmpty { HStack { Spacer() Button { fieldText = &quot;&quot; action } label: { Image(systemName: &quot;multiply.circle.fill&quot;) } .foregroundColor(.secondary) .padding(.trailing, 4) } } } } } extension View { func showClearButton(_ text: Binding&lt;String&gt;) -&gt; some View { self.modifier(TextFieldClearButton(fieldText: text)) } } struct TextFieldButton: View { @State private var text = &quot;&quot; @FocusState private var isTextFieldFocused: Bool var body: some View { VStack { TextField(&quot;&quot;, text: $text) .textFieldStyle(.roundedBorder) .focused($isTextFieldFocused) .showClearButton($text) } .padding() .background(Color.purple) } } </code></pre> <p>So far I can only get an &quot;Expression of type '(() -&gt; Void)?' is unused&quot; warning and I am not sure how or if this needs to passed in as a @Binding.</p>
[ { "answer_id": 74451404, "author": "whiteio", "author_id": 19222466, "author_profile": "https://Stackoverflow.com/users/19222466", "pm_score": 0, "selected": false, "text": "action" }, { "answer_id": 74454837, "author": "crsnstack", "author_id": 18131679, "author_profile": "https://Stackoverflow.com/users/18131679", "pm_score": 1, "selected": false, "text": " @Binding var fieldText: String\n var action: (() -> Void)? = nil\n\n func body(content: Content) -> some View {\n content\n .overlay {\n if !fieldText.isEmpty {\n HStack {\n Spacer()\n Button {\n fieldText = \"\"\n action?()\n } label: {\n Image(systemName: \"multiply.circle.fill\")\n }\n .foregroundColor(.secondary)\n .padding(.trailing, 4)\n }\n }\n }\n }\n}\n\nextension View {\n func showClearButton(_ text: Binding<String>, action: (() -> Void)? = nil) -> some View {\n self.modifier(TextFieldClearButton(fieldText: text, action: action))\n }\n}\n\nstruct TextFieldButton: View {\n\n @State private var text = \"\"\n @FocusState private var isTextFieldFocused: Bool\n\n var body: some View {\n VStack {\n TextField(\"\", text: $text)\n .textFieldStyle(.roundedBorder)\n .focused($isTextFieldFocused)\n .showClearButton($text, action: testPrint)\n }\n .padding()\n .background(Color.purple)\n }\n func testPrint() {\n print(\"Test Print Successful.\")\n }\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18131679/" ]
74,451,166
<p>I have an array contain a list of courses</p> <pre><code>$courses = ['php', 'mysql', 'java', 'ruby']; </code></pre> <p>I have also a function that helps me to split this array into pieces, depends on the number of the giving years.</p> <p>this is my function:</p> <pre><code>public function planner($courses, $periodicity, $preserve_keys = null) { $nbr = (int) ceil(count($courses) / $periodicity); if($nbr &gt; 0){ return array_chunk($courses, $nbr, $preserve_keys); } return $courses; } </code></pre> <p>The output is fine if I pass the number <strong>1 or 2 or 4</strong> in the <code>$periodicity</code> parameter I'm having the bug only when I pass number 3 as <code>$periodicity</code>, with 4 courses in my array</p> <p>I get:</p> <pre><code>[ [ 'php', 'mysql' ], [ 'java', 'ruby' ] ] </code></pre> <p>as you can see I'm getting 2 courses each year, since I passed 3 as periodicity.</p> <p>The expected result in that case should be:</p> <pre><code>[ [ 'php' ], [ 'mysql' ], [ 'java', 'ruby' ] ] </code></pre> <ul> <li>1 Course for the first year</li> <li>1 course for the second year</li> <li>2 courses for the last year</li> </ul>
[ { "answer_id": 74451404, "author": "whiteio", "author_id": 19222466, "author_profile": "https://Stackoverflow.com/users/19222466", "pm_score": 0, "selected": false, "text": "action" }, { "answer_id": 74454837, "author": "crsnstack", "author_id": 18131679, "author_profile": "https://Stackoverflow.com/users/18131679", "pm_score": 1, "selected": false, "text": " @Binding var fieldText: String\n var action: (() -> Void)? = nil\n\n func body(content: Content) -> some View {\n content\n .overlay {\n if !fieldText.isEmpty {\n HStack {\n Spacer()\n Button {\n fieldText = \"\"\n action?()\n } label: {\n Image(systemName: \"multiply.circle.fill\")\n }\n .foregroundColor(.secondary)\n .padding(.trailing, 4)\n }\n }\n }\n }\n}\n\nextension View {\n func showClearButton(_ text: Binding<String>, action: (() -> Void)? = nil) -> some View {\n self.modifier(TextFieldClearButton(fieldText: text, action: action))\n }\n}\n\nstruct TextFieldButton: View {\n\n @State private var text = \"\"\n @FocusState private var isTextFieldFocused: Bool\n\n var body: some View {\n VStack {\n TextField(\"\", text: $text)\n .textFieldStyle(.roundedBorder)\n .focused($isTextFieldFocused)\n .showClearButton($text, action: testPrint)\n }\n .padding()\n .background(Color.purple)\n }\n func testPrint() {\n print(\"Test Print Successful.\")\n }\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19395233/" ]
74,451,180
<p>i'm learning and would appreciate any help in this code.</p> <p>The issue is trying to print the values in the data that are contained in one line of the JSON using Python.</p> <pre><code>import json import requests data = json.loads(response.text) print(len(data)) #showing correct value </code></pre> <p>#where i'm going wrong below obviously this will print the first value then the second as it's indexed. Q how do I print all values when using seperate print statements when the total indexed value is unknown?</p> <pre><code>for item in data: print(data[0]['full_name']) print(data[1]['full_name']) </code></pre> <p>I tried without the index value this gave me the first value multiple times depending on the length.</p> <p>I expect to be able to access from the JSON file each indexed value separately even though they are named the same thing &quot;full_name&quot; for example.</p>
[ { "answer_id": 74451404, "author": "whiteio", "author_id": 19222466, "author_profile": "https://Stackoverflow.com/users/19222466", "pm_score": 0, "selected": false, "text": "action" }, { "answer_id": 74454837, "author": "crsnstack", "author_id": 18131679, "author_profile": "https://Stackoverflow.com/users/18131679", "pm_score": 1, "selected": false, "text": " @Binding var fieldText: String\n var action: (() -> Void)? = nil\n\n func body(content: Content) -> some View {\n content\n .overlay {\n if !fieldText.isEmpty {\n HStack {\n Spacer()\n Button {\n fieldText = \"\"\n action?()\n } label: {\n Image(systemName: \"multiply.circle.fill\")\n }\n .foregroundColor(.secondary)\n .padding(.trailing, 4)\n }\n }\n }\n }\n}\n\nextension View {\n func showClearButton(_ text: Binding<String>, action: (() -> Void)? = nil) -> some View {\n self.modifier(TextFieldClearButton(fieldText: text, action: action))\n }\n}\n\nstruct TextFieldButton: View {\n\n @State private var text = \"\"\n @FocusState private var isTextFieldFocused: Bool\n\n var body: some View {\n VStack {\n TextField(\"\", text: $text)\n .textFieldStyle(.roundedBorder)\n .focused($isTextFieldFocused)\n .showClearButton($text, action: testPrint)\n }\n .padding()\n .background(Color.purple)\n }\n func testPrint() {\n print(\"Test Print Successful.\")\n }\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7044664/" ]
74,451,207
<p>I have searched through the other questions similar to my own problem and have come to no solution so im hoping someone can help me figure out where i went wrong.</p> <p>I'm trying to implement a delete post option in my blog program but it is throwing the following error once you click the 'delete' button:</p> <p><strong>ImproperlyConfigured at /18/delete/ Deletepost is missing a QuerySet. Define Deletepost.model, Deletepost.queryset, or override Deletepost.get_queryset().</strong></p> <p>I am nearly sure its a problem with my URLS.py though what exactly i cannot figure out.</p> <p>the following is the code in question:</p> <p><strong>Views.py</strong></p> <pre><code># delete post class Deletepost(LoginRequiredMixin, DeleteView): form_class = Post success_url = reverse_lazy('blog:home') template_name = 'templates/post.html' def test_func(self): post = self.get_object() if self.request.user == post.author: return True return False </code></pre> <p><strong>urls.py</strong></p> <pre><code>urlpatterns = [ # home path('', views.postslist.as_view(), name='home'), # add post path('blog_post/', views.PostCreateView.as_view(), name='blog_post'), # posts/comments path('&lt;slug:slug&gt;/', views.postdetail.as_view(), name='post_detail'), # edit post path('&lt;slug:slug&gt;/edit/', views.Editpost.as_view(), name='edit_post'), # delete post path('&lt;int:pk&gt;/delete/', views.Deletepost.as_view(), name='delete_post'), # likes path('like/&lt;slug:slug&gt;', views.PostLike.as_view(), name='post_like'), ] </code></pre> <p><strong>post.html</strong></p> <pre><code> {% extends 'base.html' %} {% block content %} {% load crispy_forms_tags %} &lt;div class=&quot;masthead&quot;&gt; &lt;div class=&quot;container&quot;&gt; &lt;div class=&quot;row g-0&quot;&gt; &lt;div class=&quot;col-md-6 masthead-text&quot;&gt; &lt;!-- Post title goes in these h1 tags --&gt; &lt;h1 class=&quot;post-title text-success&quot;&gt;{{ post.title }}&lt;/h1&gt; &lt;!-- Post author goes before the | the post's created date goes after --&gt; &lt;p class=&quot;post-subtitle text-success&quot;&gt;{{ post.author }} | {{ post.created_on }}&lt;/p&gt; &lt;/div&gt; &lt;div class=&quot;d-none d-md-block col-md-6 masthead-image&quot;&gt; &lt;!-- The featured image URL goes in the src attribute --&gt; {% if &quot;placeholder&quot; in post.featured_image.url %} &lt;img src=&quot;https://codeinstitute.s3.amazonaws.com/fullstack/blog/default.jpg&quot; width=&quot;100%&quot;&gt; {% else %} &lt;img src=&quot; {{ post.featured_image.url }}&quot; width=&quot;100%&quot;&gt; {% endif %} &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;container&quot;&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col card mb-4 mt-3 left top&quot;&gt; &lt;div class=&quot;card-body text-dark&quot;&gt; &lt;!-- The post content goes inside the card-text. --&gt; &lt;!-- Use the | safe filter inside the template tags --&gt; &lt;p class=&quot;card-text text-dark&quot;&gt; {{ post.content | safe }} &lt;/p&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-1&quot;&gt; &lt;strong&gt; {% if user.is_authenticated %} &lt;form class=&quot;d-inline&quot; action=&quot;{% url 'post_like' post.slug %}&quot; method=&quot;POST&quot;&gt; {% csrf_token %} {% if liked %} &lt;button type=&quot;submit&quot; name=&quot;blogpost_id&quot; value=&quot;{{post.slug}}&quot; class=&quot;btn-like&quot;&gt;&lt;i class=&quot;fas fa-heart&quot;&gt;&lt;/i&gt;&lt;/button&gt; {% else %} &lt;button type=&quot;submit&quot; name=&quot;blogpost_id&quot; value=&quot;{{post.slug}}&quot; class=&quot;btn-like&quot;&gt;&lt;i class=&quot;far fa-heart&quot;&gt;&lt;/i&gt;&lt;/button&gt; {% endif %} &lt;/form&gt; {% else %} &lt;span class=&quot;text-secondary&quot;&gt;&lt;i class=&quot;far fa-heart&quot;&gt;&lt;/i&gt;&lt;/span&gt; {% endif %} &lt;!-- The number of likes goes before the closing strong tag --&gt; &lt;span class=&quot;text-secondary&quot;&gt;{{ post.number_of_likes }} &lt;/span&gt; &lt;/strong&gt; &lt;/div&gt; &lt;div class=&quot;col-1&quot;&gt; {% with comments.count as total_comments %} &lt;strong class=&quot;text-dark&quot;&gt;&lt;i class=&quot;far fa-comments&quot;&gt;&lt;/i&gt; &lt;!-- Our total_comments variable goes before the closing strong tag --&gt; {{ total_comments }}&lt;/strong&gt; {% endwith %} &lt;/div&gt; &lt;div class=&quot;col-1&quot;&gt; &lt;a class=&quot;btn btn-outline-danger&quot; href=&quot;{% url 'delete_post' post.id %}&quot;&gt;Delete It&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col&quot;&gt; &lt;hr&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-md-8 card mb-4 mt-3 &quot;&gt; &lt;h3 class=&quot;text-dark&quot;&gt;Comments:&lt;/h3&gt; &lt;div class=&quot;card-body&quot;&gt; &lt;!-- We want a for loop inside the empty control tags to iterate through each comment in comments --&gt; {% for comment in comments %} &lt;div class=&quot;comments text-dark&quot; style=&quot;padding: 10px;&quot;&gt; &lt;p class=&quot;font-weight-bold&quot;&gt; &lt;!-- The commenter's name goes here. Check the model if you're not sure what that is --&gt; {{ comment.name }} &lt;span class=&quot; text-muted font-weight-normal&quot;&gt; &lt;!-- The comment's created date goes here --&gt; {{ comment.created_on }} &lt;/span&gt; wrote: &lt;/p&gt; &lt;!-- The body of the comment goes before the | --&gt; {{ comment.body | linebreaks }} &lt;/div&gt; &lt;!-- Our for loop ends here --&gt; {% endfor %} &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col-md-4 card mb-4 mt-3 &quot;&gt; &lt;div class=&quot;card-body&quot;&gt; &lt;!-- For later --&gt; {% if commented %} &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt; Your comment is awaiting approval &lt;/div&gt; {% else %} {% if user.is_authenticated %} &lt;h3 class=&quot;text-dark&quot;&gt;Leave a comment:&lt;/h3&gt; &lt;p class=&quot;text-dark&quot;&gt;Posting as: {{ user.username }}&lt;/p&gt; &lt;form class=&quot;text-dark&quot; method=&quot;post&quot; style=&quot;margin-top: 1.3em;&quot;&gt; {{ comment_form | crispy }} {% csrf_token %} &lt;button type=&quot;submit&quot; class=&quot;btn btn-signup btn-lg&quot;&gt;Submit&lt;/button&gt; &lt;/form&gt; {% endif %} {% endif %} &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; {% endblock content %} </code></pre> <p>Any ideas?</p>
[ { "answer_id": 74451375, "author": "Sunderam Dubey", "author_id": 17562044, "author_profile": "https://Stackoverflow.com/users/17562044", "pm_score": 2, "selected": false, "text": "model" }, { "answer_id": 74451506, "author": "Willem Van Onsem", "author_id": 67579, "author_profile": "https://Stackoverflow.com/users/67579", "pm_score": 3, "selected": true, "text": "test_func" }, { "answer_id": 74451593, "author": "Faez AR", "author_id": 19332478, "author_profile": "https://Stackoverflow.com/users/19332478", "pm_score": 2, "selected": false, "text": "def delete_post(request, post_id):\n post = Post.objects.get(pk=post_id)\n post.delete()\n return redirect('blog:home')\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20399868/" ]
74,451,216
<p>When I try to run this code `</p> <pre><code>import json import os import random from pprint import pprint import aiohttp import discord import requests from discord.ext import commands from dotenv import load_dotenv from mojang import api # Functions # Sends a Get request to a given url def get_info(call): r = requests.get(call) return r.json() # Get the sum of coins in the bazaar def get_bazaar_buy_order_value(bazaar_data): sum_coins = 0 price_increase_threshold = 2 buy_order_values = [] # For every product for item_name, item_data in bazaar_data.get(&quot;products&quot;, {}).items(): item_sum_coins = 0 # For every buy order for idx, buy_order in enumerate(item_data.get(&quot;buy_summary&quot;, [])): # If its the best price if(idx == 0): item_expected_value = buy_order.get(&quot;pricePerUnit&quot;, 0) item_sum_coins += buy_order.get(&quot;amount&quot;, 0) * buy_order.get(&quot;pricePerUnit&quot;, 0) # If its not the best price, check for reasonable price else: if(buy_order.get(&quot;pricePerUnit&quot;, 0) &lt; (item_expected_value * price_increase_threshold)): item_sum_coins += buy_order.get(&quot;amount&quot;, 0) * buy_order.get(&quot;pricePerUnit&quot;, 0) buy_order_values.append((item_name, item_sum_coins)) sum_coins += item_sum_coins sort_bazaar_buy_orders_by_value(buy_order_values) return sum_coins # Sorts and displays a list of buy order items by total value def sort_bazaar_buy_orders_by_value(buy_order_values): # Sort items by values buy_order_values.sort(key = lambda x: -x[1]) # Display items and values for (item_name, item_sum_coins) in buy_order_values: print(f&quot;{item_name.ljust(30, ' ')} | {round(item_sum_coins):,}&quot;) return # Returns Bazaar data def get_bazaar_data(): return get_info(&quot;https://api.hypixel.net/skyblock/bazaar&quot;) # Returns a specific item from the Bazaar def get_bazaar_item(): return # Returns auction info from player uuid def get_auctions_from_player(uuid): return get_info(f&quot;https://api.hypixel.net/skyblock/auction?key={API_KEY}&amp;player={uuid}&quot;) # Returns current mayor/election data def get_election_data(): return get_info(f&quot;https://api.hypixel.net/resources/skyblock/election&quot;) # Returns a list of player profiles def get_profiles_data(): return get_info(f&quot;https://sky.shiiyu.moe/api/v2/profile/{example_uuid}&quot;) # Returns player UUID when prompted with the name async def get_uuid(name): return get_info(f&quot;https://sky.shiiyu.moe/api/v2/profile/{name}&quot;) # Discord Functions / Vars load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') GUILD = os.getenv('DISCORD_GUILD') client = discord.Client(intents=discord.Intents.default()) intents = discord.Intents.all() bot = commands.Bot(command_prefix='/',intents=intents) # Hypixel Vars Item = &quot;Diamond&quot; API_FILE = open(&quot;API_KEY.json&quot;,&quot;r&quot;) example_name = &quot;4748&quot; example_uuid = &quot;147ab344d3e54952b74a8b0fedee5534&quot; uuid_dashed = &quot;147ab344-d3e5-4952-b74a-8b0fedee5534&quot; API_KEY = json.loads(API_FILE.read())[&quot;API_KEY&quot;] example_player_uuid = &quot;147ab344d3e54952b74a8b0fedee5534&quot; auctions_player_url = f&quot;https://api.hypixel.net/skyblock/auction?key={API_KEY}&amp;player={example_player_uuid}&quot; # Commands @bot.command(name='bazaar', description = &quot;Gives a detailed readout of a certain item in the bazaar&quot;, brief = &quot;Get data of an item in bazaar&quot;) async def bazaar(ctx): await ctx.send(get_bazaar_data()) await ctx.send(API_KEY) @bot.command(name=&quot;bazaartotal&quot;, description = &quot;Show the total amount of coins on the bazaar at any given point&quot;, brief = &quot;Shows the amount of coins in the bazaar&quot;) async def baztot(ctx): await ctx.send(get_bazaar_buy_order_value(get_bazaar_data())) @bot.command(name = &quot;apikey&quot;, description = &quot;Gives 4748's API key, make sure to remove me once publicly availible!&quot;, brief = &quot;API Key&quot;) async def key(ctx): await ctx.send(API_KEY) @bot.command(name = &quot;profiles&quot;, description = 'Get a list of player profiles and data about them', brief = &quot;List player profiles&quot;) async def prof(ctx): await ctx.send(&quot;Username to check?&quot;) message = client.wait_for('message', check=lambda m: m.user == ctx.user) username = str(message.content) uuid = get_uuid(username) pprint(uuid) await ctx.send(uuid) bot.run(TOKEN) </code></pre> <p>I get this error <code>discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: loop attribute cannot be accessed in non-async contexts. Consider using either an asynchronous main function and passing it to asyncio.run or using asynchronous initialisation hooks such as Client.setup_hook </code> Anyone have a fix for this? The bot runs normally, but once I try to run /profiles it gives me that error. Also, other commands work fine, but when I try to access an api with a</p> <p>Changed my code multiple times, putting the get_uuid command in async, and googling for a few hours. any help is appreciated!</p>
[ { "answer_id": 74452306, "author": "stijndcl", "author_id": 13568999, "author_profile": "https://Stackoverflow.com/users/13568999", "pm_score": 2, "selected": true, "text": "Bot" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512978/" ]
74,451,248
<p>I've created a tableView, but when I click it, I don't get any results. I wanted to add a new feature to improve my project, but I couldn't add the videos I watched and the things I researched.</p> <p><a href="https://i.stack.imgur.com/CLf4x.png" rel="nofollow noreferrer">Table View</a></p> <pre><code>import UIKit class ViewController1: UIViewController { @IBOutlet weak var FoodView: UITableView! let dogfoods = [&quot;pork&quot;, &quot;banana&quot;, &quot;chicken-leg&quot;] override func viewDidLoad() { super.viewDidLoad() FoodView.delegate = self FoodView.dataSource = self // not tapped no see FoodView.allowsSelection = false } } extension ViewController1: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat { return 120 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int { return dogfoods.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell { let cell = FoodView.dequeueReusableCell(withIdentifier: &quot;CustomCell&quot;) as! CustomCell let dogfood = dogfoods[indexPath.row] cell.foodImageView.image = UIImage(named: dogfood) cell.nameLabel.text = dogfood return cell } } </code></pre> <p>CustomCell</p> <pre><code>class CustomCell: UITableViewCell { @IBOutlet weak var dogView: UIView! @IBOutlet weak var nameLabel: UILabel! @IBOutlet weak var foodImageView: UIImageView! override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } } </code></pre> <p>When I click on one of the cells in the picture, I want to write a larger version of the picture and a description, how can I do this? When I searched on the internet, I applied similar ones, but I couldn't get any results.</p>
[ { "answer_id": 74452306, "author": "stijndcl", "author_id": 13568999, "author_profile": "https://Stackoverflow.com/users/13568999", "pm_score": 2, "selected": true, "text": "Bot" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19148758/" ]
74,451,256
<p>I am making app with framer motion and I need to drag svg inside another svg but my problem is that viwebox size is not equal to window size so when I drag element my 1px movement of mouse on the screen is like 100+ px. I know in JavaScript we can calculate x and y with screenX, sceenY and CTM (current transform matrix). Is possible to make somehow framer motion drag function to calculate that?</p> <pre><code>&lt;svg viewBox=&quot;0 0 40 20&quot;&gt; &lt;motion.circle drag cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;0.5&quot;strokeWidth=&quot;0.1&quot;/&gt; &lt;/svg&gt; </code></pre> <p>P.S. I cannot change viewbox size and its 100% of width and height of screen</p> <p>this is current state of the app where you can see the problem when you try to drag player object. <a href="https://waterpolo.klaktech.com" rel="nofollow noreferrer">https://waterpolo.klaktech.com</a></p>
[ { "answer_id": 74638603, "author": "Zhubei Federer", "author_id": 10769406, "author_profile": "https://Stackoverflow.com/users/10769406", "pm_score": 0, "selected": false, "text": "movement.dragdragConstraints" }, { "answer_id": 74638701, "author": "xentwo", "author_id": 9743356, "author_profile": "https://Stackoverflow.com/users/9743356", "pm_score": 1, "selected": false, "text": "transformMatrix" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15792376/" ]
74,451,264
<p>So I'm trying to create this program where it takes an input (for example x+2=5) and sympy solves that equation. However since I believe that &quot;=&quot; sign will cause an error I tried to cut it out from the input but with this I'm finding my self inputting a string type in the simpy solver. Is there any solution to this?</p> <pre class="lang-py prettyprint-override"><code>import math from sympy import * class operations(): def __init__(self): self.operation = input() def solution(self, *o): x, y, z = symbols(&quot;x y z&quot;) equals = self.operation.split(&quot;=&quot;,1)[1] equation = self.operation.split(&quot;=&quot;)[0] solution = solveset(Eq(equation, int(equals)), x) print(solution) operations().solution() </code></pre>
[ { "answer_id": 74451367, "author": "Davide_sd", "author_id": 2329968, "author_profile": "https://Stackoverflow.com/users/2329968", "pm_score": 2, "selected": true, "text": "sympify" }, { "answer_id": 74452981, "author": "smichr", "author_id": 1089161, "author_profile": "https://Stackoverflow.com/users/1089161", "pm_score": 0, "selected": false, "text": "parse_expr" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513444/" ]
74,451,283
<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>#desc { visibility: hidden; opacity: 0; } .exp-container &gt; .buttons:has(.button:focus) + #desc { opacity: 1; transition: 0.5s; } .exp-container &gt; .buttons:has(#OMI:focus) + #desc &gt; .top &gt; h1:before { visibility: visible; transition: 0.5s; content: "Graphic Design Lead"; } .exp-container &gt; .buttons:has(#OMI:focus) + #desc &gt; .top &gt; .date:before { visibility: visible; transition: 0.5s; content: "July 2021 - July 2022"; } .exp-container &gt; .buttons:has(#OMI:focus) + #desc &gt; .content &gt; .exp::before { visibility: visible; transition: 0.5s; content: "- Developing screens and UI components for the web application using React and Tailwind. - Fixing UI issues and integrating backend APIs with Redux Saga."; } .exp-container &gt; .buttons:has(#OMI:focus) + #desc &gt; .content &gt; .comp::before { visibility: visible; transition: 0.5s; content: "Remote"; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="exp-container"&gt; &lt;div class="title"&gt; EXPERIENCE &lt;/div&gt; &lt;div class="buttons"&gt; &lt;button class="button" id="OMI"&gt;&lt;span&gt;ONE&lt;/span&gt;&lt;/button&gt; &lt;button class="button" id="RC"&gt;&lt;span&gt;TWO&lt;/span&gt;&lt;/button&gt; &lt;button class="button" id="MRKT"&gt;&lt;span&gt;THREE&lt;/span&gt;&lt;/button&gt; &lt;button class="button" id="BIBLE"&gt;&lt;span&gt;FOUR&lt;/span&gt;&lt;/button&gt; &lt;button class="button" id="FREE"&gt;&lt;span&gt;FIVE&lt;/span&gt;&lt;/button&gt; &lt;button class="button" id="CHAR"&gt;&lt;span&gt;SIX&lt;/span&gt;&lt;/button&gt; &lt;/div&gt; &lt;div id="desc"&gt; &lt;div class="top"&gt; &lt;h1&gt;Placeholder Text &lt;span class="date"&gt;Month 2022 - Month 2022&lt;/span&gt;&lt;/h1&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;div class="comp"&gt;Placeholder Text&lt;/div&gt; &lt;div class="exp"&gt;Placeholder Text&lt;br&gt;Placeholder Text&lt;br&gt;Placeholder Text&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>I made some changes that included trying <code>:has()</code>, but my issue is now that I want to align these buttons so they evenly fit inside in the fluid background.</p> <p>Doing so requires the buttons to be in a seperate div from the content so I am able to make the buttons flex (as far as I know).</p> <p>Is this possible in just CSS or do I have to include js?</p>
[ { "answer_id": 74451367, "author": "Davide_sd", "author_id": 2329968, "author_profile": "https://Stackoverflow.com/users/2329968", "pm_score": 2, "selected": true, "text": "sympify" }, { "answer_id": 74452981, "author": "smichr", "author_id": 1089161, "author_profile": "https://Stackoverflow.com/users/1089161", "pm_score": 0, "selected": false, "text": "parse_expr" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451283", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16028882/" ]
74,451,296
<p>I can print the ip and url from a massive log file, but I need to list how many times an ip has visited that url. I have done some research about throwing the log in a database, but I specifically need to do all of this in Python. any help is very appreciated.</p> <p>My Code so far:</p> <pre><code>#!/usr/bin/python3 count = 0 log = open(&quot;access.log-20201019&quot;, &quot;r&quot;) arr = [] frequency_array = [] for i in log.readlines(): ip = i[0:14] ip2 = ip.split(' ') ip3 = ip2[0] #print(ip3) url =i[53:87] url2 = url.split() url3 = url2[0] print(ip3,url3) </code></pre> <p>Snippet of Log file:</p> <pre class="lang-none prettyprint-override"><code>66.177.237.17 - - [18/Oct/2020:03:06:07 -0400] &quot;GET /webcam/1/latest.jpeg HTTP/2.0&quot; 304 0 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:07 -0400] &quot;GET /webcam/rwis/littlebay/latest.jpeg HTTP/1.1&quot; 301 169 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:07 -0400] &quot;GET /webcam/rwis/littlebay/latest.jpeg HTTP/1.1&quot; 200 37145 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 112.198.71.230 - - [18/Oct/2020:03:06:09 -0400] &quot;GET /precip/raingauge2.gif HTTP/2.0&quot; 200 10078 &quot;https://www.google.com/&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36&quot; &quot;-&quot; 173.9.45.97 - - [18/Oct/2020:03:06:10 -0400] &quot;GET /NHPR/NHPR_rad_an.gif HTTP/2.0&quot; 200 587317 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36&quot; &quot;-&quot; 173.9.45.97 - - [18/Oct/2020:03:06:11 -0400] &quot;GET /favicon.ico HTTP/2.0&quot; 200 27877 &quot;https://vortex.plymouth.edu/NHPR/NHPR_rad_an.gif&quot; &quot;Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:11 -0400] &quot;GET /webcam/1/nograph.1.jpeg HTTP/1.1&quot; 301 169 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:11 -0400] &quot;GET /webcam/1/nograph.1.jpeg HTTP/1.1&quot; 200 242804 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:12 -0400] &quot;GET /webcam/rwis/echolake/latest.jpeg HTTP/1.1&quot; 301 169 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:12 -0400] &quot;GET /webcam/rwis/echolake/latest.jpeg HTTP/1.1&quot; 404 2256 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:14 -0400] &quot;GET /webcam/rwis/lafeyette/latest.jpeg HTTP/1.1&quot; 301 169 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; 158.136.64.65 - - [18/Oct/2020:03:06:14 -0400] &quot;GET /webcam/rwis/lafeyette/latest.jpeg HTTP/1.1&quot; 200 36974 &quot;-&quot; &quot;curl/7.46.0&quot; &quot;-&quot; </code></pre> <p>I am able to run my current code, but will output the ip and url multiple times for the same ip. I just want the number of times an ip visited a certain url.</p>
[ { "answer_id": 74451367, "author": "Davide_sd", "author_id": 2329968, "author_profile": "https://Stackoverflow.com/users/2329968", "pm_score": 2, "selected": true, "text": "sympify" }, { "answer_id": 74452981, "author": "smichr", "author_id": 1089161, "author_profile": "https://Stackoverflow.com/users/1089161", "pm_score": 0, "selected": false, "text": "parse_expr" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451296", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,451,310
<p>I'm developing a site with MERN stack and I want to do all the things with Docker. But I have trouble with connecting to MongoDB with Docker.</p> <p>Here's my docker-compose.yml file.</p> <pre><code>version: &quot;3.7&quot; services: backend: build: context: ./node_backend dockerfile: Dockerfile.dev container_name: &quot;${APP_NAME}-backend&quot; restart: always env_file: .env volumes: - type: bind source: ./node_backend/src target: /usr/src/app/src expose: - &quot;${API_PORT}&quot; ports: - &quot;${API_PORT}:${API_PORT}&quot; command: npm run dev environment: - PORT=${API_PORT} - DB_URL=mongodb://mongo:27017/${DB_NAME} db: image: mongo restart: always env_file: .env container_name: &quot;${APP_NAME}-database&quot; ports: - '27017:27017' environment: - MONGO_INITDB_ROOT_USERNAME=${DB_USER} - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD} frontend: build: context: ./react_frontend dockerfile: Dockerfile.dev container_name: &quot;${APP_NAME}-frontend&quot; env_file: .env expose: - &quot;${CLIENT_PORT}&quot; ports: - &quot;${CLIENT_PORT}:${CLIENT_PORT}&quot; volumes: - type: bind source: ./react_frontend/src target: /usr/src/app/src - type: bind source: ./react_frontend/public target: /usr/src/app/public command: npm start </code></pre> <p>I get this kind of warnings if I execute <code>docker compose up</code>command. <a href="https://i.stack.imgur.com/cNF6e.png" rel="nofollow noreferrer">enter image description here</a></p> <p>Is there anyone helps me to fix it?</p>
[ { "answer_id": 74451384, "author": "Def Soudani", "author_id": 4119055, "author_profile": "https://Stackoverflow.com/users/4119055", "pm_score": 2, "selected": false, "text": "db" }, { "answer_id": 74451521, "author": "Matias Bertoni", "author_id": 19272564, "author_profile": "https://Stackoverflow.com/users/19272564", "pm_score": 1, "selected": false, "text": " backend:\n build:\n context: ./node_backend\n dockerfile: Dockerfile.dev\n container_name: \"${APP_NAME}-backend\"\n restart: always\n env_file: .env\n volumes:\n - type: bind\n source: ./node_backend/src\n target: /usr/src/app/src\n expose: \n - \"${API_PORT}\"\n ports: \n - \"${API_PORT}:${API_PORT}\"\n command: npm run dev\n environment: \n - PORT=${API_PORT}\n //db is the name of the service\n - DB_URL=mongodb://db:27017/${DB_NAME}\n depends_on:\n - db\n \n\n db:\n image: mongo\n restart: always\n env_file: .env\n container_name: \"${APP_NAME}-database\"\n ports:\n - '27017:27017'\n environment: \n - MONGO_INITDB_ROOT_USERNAME=${DB_USER}\n - MONGO_INITDB_ROOT_PASSWORD=${DB_PASSWORD}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512951/" ]
74,451,315
<p>How do I update a clob field with 7000 characters?</p> <p>tbody -&gt; CLOB</p> <pre><code>update ttable set tbody = 'sample text' where tid = 13; </code></pre> <p>Of course, when I do this, I get an error.It may be a very simple question for experts, but it is a really difficult process for me. I'm working in new oracle sql and I can't get over such a problem.</p>
[ { "answer_id": 74451852, "author": "MT0", "author_id": 1509264, "author_profile": "https://Stackoverflow.com/users/1509264", "pm_score": 3, "selected": true, "text": "CLOB" }, { "answer_id": 74458587, "author": "harbk", "author_id": 8442130, "author_profile": "https://Stackoverflow.com/users/8442130", "pm_score": 0, "selected": false, "text": "DECLARE\n vc_body CLOB := 'bla bla bla ...' || 'bla bla bla ...';\nBEGIN\n UPDATE ttable SET tbody = vc_body WHERE tid= 13;\n commit;\nEND;\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8442130/" ]
74,451,341
<p>Below is a snippet taken from: <a href="https://discordjs.guide/creating-your-bot/command-handling.html#loading-command-files" rel="nofollow noreferrer">https://discordjs.guide/creating-your-bot/command-handling.html#loading-command-files</a></p> <pre><code>client.commands = new Collection(); const commandsPath = path.join(__dirname, 'commands'); const commandFiles = fs.readdirSync(commandsPath).filter(file =&gt; file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); // Set a new item in the Collection with the key as the command name and the value as the exported module if ('data' in command &amp;&amp; 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log(`[WARNING] The command at ${filePath} is missing a required &quot;data&quot; or &quot;execute&quot; property.`); } } </code></pre> <p>Within the for loop, we retrieve the command by doing <code>require(filePath)</code>. How do I achieve an equivalent behaviour using import?</p> <p>The majority of the <a href="https://discordjs.guide/" rel="nofollow noreferrer">Discord.js guide</a> uses CommonJS whereas I am trying to implement my bot using TypeScript.</p>
[ { "answer_id": 74452895, "author": "Finbar", "author_id": 17525834, "author_profile": "https://Stackoverflow.com/users/17525834", "pm_score": 3, "selected": true, "text": "import()" }, { "answer_id": 74479185, "author": "Joseph Toronto", "author_id": 1495070, "author_profile": "https://Stackoverflow.com/users/1495070", "pm_score": 0, "selected": false, "text": "const command = await import(filePath);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12186318/" ]
74,451,373
<p>What I want to do is move the placeholder image to the space to the right of the text.</p> <p>I've tried several solutions involving adding different classes to the image, removing the nested container, and so on, but nothing moves the image up next to the text. The image resizes depending on the col-x of the left column but it refuses to move up. From what I can tell in the Bootstrap documentation and my experience working with Flexbox this seems like it ought to work but I guess I'm missing something? Can anyone help?</p> <p>Here's an image of my page as it is:</p> <p><img src="https://i.stack.imgur.com/qS55M.png" alt="screencap of my project" /></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"&gt; &lt;div class='container'&gt; &lt;hr /&gt; &lt;!-- begin template --&gt; &lt;div class='row'&gt; &lt;div class='col-8'&gt; &lt;div class='container-fluid p-0'&gt; &lt;div class='row'&gt; &lt;div class='col'&gt; &lt;h3&gt;Project Name&lt;/h3&gt; &lt;/div&gt; &lt;div class='col text-end'&gt; &lt;p&gt;Project Status&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class='row'&gt; &lt;div class='col'&gt; &lt;p&gt;&lt;i class='fa fa-arrow-right'&gt;&lt;/i&gt; Tech 1, Tech 2, Tech 3&lt;/p&gt; &lt;/div&gt; &lt;div class='row'&gt; &lt;div class='col'&gt; &lt;p&gt;This is a description of the project, its goals, its challenges, the technologies it uses.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class='col-4'&gt; &lt;img src='https://via.placeholder.com/100' class='img-fluid' alt='placeholder image'&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74452895, "author": "Finbar", "author_id": 17525834, "author_profile": "https://Stackoverflow.com/users/17525834", "pm_score": 3, "selected": true, "text": "import()" }, { "answer_id": 74479185, "author": "Joseph Toronto", "author_id": 1495070, "author_profile": "https://Stackoverflow.com/users/1495070", "pm_score": 0, "selected": false, "text": "const command = await import(filePath);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19757883/" ]
74,451,398
<p>I have multiple text files that I want to process and get the version number of the 'banana' package section, here one example:</p> <pre><code>Package: apple Settings: scim Architecture: amd32 Size: 2312312312 Package: banana Architecture: xsl64 Version: 94.3223.2 Size: 23232 Package: orange Architecture: bbl64 Version: 14.3223.2 Description: Something descrip more description to orange Package: friday SHA215: d3d223d3f2ddf2323d3 Person: XCXCS Size: 2312312312 </code></pre> <p>What I know:</p> <ul> <li>Package: [name] is always first line in a section.</li> <li>Not all sections have a Package: [name] line.</li> <li>Package: banana section always has a Version: line.</li> <li>Version: line order is different. (can be second, fifth, last line..)</li> <li>Package: banana section order is different. It can be at the start, middle, end of the document.</li> <li>Version: [number] is always different</li> </ul> <p>I want to find the Version number in banana package section, so <strong>94.3223.2</strong> from the example. I do not want to find it by hardcoded loops line by line, but do it with a nice solution.</p> <p>I have tried something like this, but unfortunately it doesn't work for every scenario:</p> <pre><code>firstOperation = textFile.split('Package: banana').pop(); secondOperation = firstOperation.split('\n'); finalString = secondOperation[1].split('Version: ').pop(); </code></pre> <p>My logic would be:</p> <ol> <li>Find Package: banana line</li> <li>Check the first occurence of 'Version:' after finding package banana line, then extract the version number from this line.</li> </ol> <p>This data processing will be a nodeJs endpoint.</p>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9439634/" ]
74,451,415
<p>I created a simple .NET 7.0 app with SQL Server and if I use the default &quot;localdb&quot; or even after I change it to a &quot;network server&quot;, I get the error below:</p> <blockquote> <p>The certificate chain was issued by an authority that is not trusted.</p> </blockquote> <p>My connection string is:</p> <pre><code>mysqlserver.com;Initial Catalog=db_database;User Id=db_admin;Password=pass123;Persist Security Info=True;Encrypt=true;TrustServerCertificate=yes </code></pre> <p>What am I doing wrong?</p> <p>PS: With the above connection string I can scaffold the database.</p>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16955137/" ]
74,451,430
<p>I'm making a game and I need to find the 2 <code>GameObject</code>s from a list closest to another <code>GameObject</code> which is also in the same list but I don't want it to return more than 2 <code>GameObject</code>s or return the <code>GameObject</code> that I'm checking against.</p> <p>Here's what I want to input:</p> <pre class="lang-cs prettyprint-override"><code>GameObject[] objects, GameObject currentObject </code></pre> <p>And I want it to output:</p> <pre class="lang-cs prettyprint-override"><code>GameObject[] closestObjects, GameObject currentObject </code></pre> <p>I tried:</p> <pre class="lang-cs prettyprint-override"><code>GameObject [ ] GetClosestPaths ( GameObject [ ] paths, GameObject pathToTest ) { GameObject[] bestTargets = new GameObject[2]; float closestDistanceSqr = Mathf.Infinity; Vector3 currentPosition = pathToTest.transform.position; Transform[] pathTransforms = new Transform[paths.Length]; for ( int i = 0; i &lt; paths.Length; i++ ) { pathTransforms [ i ] = paths [ i ].transform; } for ( int i = 0; i &lt; pathTransforms.Length; i++ ) { if ( pathTransforms [ i ].position != currentPosition &amp;&amp; paths [ i ] != pathToTest ) { Transform potentialTarget = pathTransforms[i]; Vector3 directionToTarget = potentialTarget.position - currentPosition; float dSqrToTarget = directionToTarget.sqrMagnitude; if ( dSqrToTarget &lt; closestDistanceSqr ) { if ( bestTargets [ 0 ] == null ) { bestTargets [ 0 ] = paths [ i ]; } closestDistanceSqr = dSqrToTarget; if ( paths [ i ].transform.position != bestTargets [ 0 ].transform.position ) { bestTargets [ 0 ] = paths [ i ]; } else { bestTargets [ 1 ] = paths [ i ]; } } } } return bestTargets; } </code></pre> <p><code>paths</code> being the <code>GameObject</code>s, <code>pathToTest</code> being <code>currentObject</code> and <code>bestTargets</code> being <code>closestObjects</code>.</p> <p>I got this on Stackoverflow and this did not work at all. I'm hoping someone can help otherwise this goes to the infinite pile of unfinished projects.</p>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16068301/" ]
74,451,481
<p>I have built a python script that uses python socket to build a connection between my python application and my python server. I have encrypted the data sent between the two systems. I was wondering if I should think of any other things related to security against hackers. Can they do something that could possibly steal data from my computer.</p> <p>thanks in advance for the effort.</p> <p>I have encrypted the data sent between the two systems.</p>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513644/" ]
74,451,485
<p>I am trying to see if it's possible to click a button on a series of sheets with a function. For a single sheet, my code works fine, but I get an Runtime error 438 when I try to do the code below.</p> <pre><code>Public Sub Read_All_Data_Click() Dim ws As Worksheet For Each ws In Worksheets ThisWorkbook.Sheets(ws.Name).Read_Data_Click Next ws End Sub </code></pre>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7308118/" ]
74,451,489
<p>I have pieced together this topological sort in JavaScript, and have a graph based on <a href="https://adelachao.medium.com/graph-topological-sort-kahns-algorithm-93380b00e7d7" rel="nofollow noreferrer">this post</a>:</p> <p><a href="https://i.stack.imgur.com/f9VRy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f9VRy.png" alt="enter image description here" /></a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const graph = { edges: { c: ['d', 'f'], d: ['e'], f: ['e'], a: ['b', 'c'], b: ['d', 'e'], } } // Calcuate the incoming degree of each vertex const vertices = Object.keys(graph.edges) const inDegree = {} for (const v of vertices) { const neighbors = graph.edges[v] neighbors?.forEach(neighbor =&gt; { inDegree[neighbor] = inDegree[neighbor] + 1 || 1 }) } const queue = vertices.filter((v) =&gt; !inDegree[v]) const list = [] while (queue.length) { const v = queue.shift() const neighbors = graph.edges[v] list.push(v) // adjust the incoming degree of its neighbors neighbors?.forEach(neighbor =&gt; { inDegree[neighbor]-- if (inDegree[neighbor] === 0) { queue.push(neighbor) } }) } console.log(list)</code></pre> </div> </div> </p> <p>99% sure this is a correct implementation of topological sort in JS.</p> <p>I am interested in doing hot-module reloading, and am interested in simulating updating the relevant nodes in the module graph. So say that <code>d</code> updated. Then we don't care about <code>a</code>, <code>b</code>, or <code>c</code>, they are fine, we only care about updating <code>d</code> and the future node then <code>e</code>, in the order <code>[ d, e ]</code>. We don't care about <code>f</code> because it's not inline with <code>d</code>.</p> <p>How do I update this topsort function to take a key (the vertex/node), and from that point forward, include the elements, so I get <code>[ d, e ]</code> if I pass <code>d</code>?</p> <p>Is it as simple as doing <code>list.slice(list.indexOf('d'))</code>, or is there more trickiness to the generic/robust solution?</p> <p>I don't think that is correct because if I did it for module <code>b</code>, we should only have to update <code>[ b, d, e ]</code>, but my solution includes <code>c</code>, which is incorrect. Not sure how to go around that.</p>
[ { "answer_id": 74451493, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 1, "selected": false, "text": "\\n\\n" }, { "answer_id": 74451838, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 3, "selected": true, "text": "function process(input) {\n let data = input.split(\"\\n\\n\"); // split by double new line\n data = data.map(i => i.split(\"\\n\")); // split each pair\n data = data.map(i => i.reduce((obj, cur) => {\n const [key, val] = cur.split(\": \"); // get the key and value\n obj[key.toLowerCase()] = val; // lowercase the value to make it a nice object\n return obj;\n }, {}));\n return data;\n}\n\nconst input = `Package: apple\nSettings: scim\nArchitecture: amd32\nSize: 2312312312\n\nPackage: banana\nArchitecture: xsl64\nVersion: 94.3223.2\nSize: 23232\n\nPackage: orange\nArchitecture: bbl64\nVersion: 14.3223.2\nDescription: Something descrip\n more description to orange\n\nPackage: friday\nSHA215: d3d223d3f2ddf2323d3\nPerson: XCXCS\nSize: 2312312312`;\n\nconst data = process(input);\nconst { version } = data.find(({ package }) => package === \"banana\"); // query data\nconsole.log(\"Banana version:\", version);" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/169992/" ]
74,451,552
<p>VBA - Copy specific cell from all files within a folder and pasting each file copied column as a separate column in a master table</p> <p>I have alot of files with a single sheet (sometimes the sheets are named different but they contain similar data arrangement). I need to copy a specific column from every workbook in folder and each of these copied columns need to be tabulated into a master table as seperate columns. Also i would need the file name as the header for each column where the value was copied from</p> <p>xls files are the file type</p>
[ { "answer_id": 74451773, "author": "ASH", "author_id": 5212614, "author_profile": "https://Stackoverflow.com/users/5212614", "pm_score": 1, "selected": false, "text": "Sub FromAllFilesIntoColumns()\n Dim MyPath As String, FilesInPath As String\n Dim MyFiles() As String\n Dim SourceCcount As Long, Fnum As Long\n Dim mybook As Workbook, BaseWks As Worksheet\n Dim sourceRange As Range, destrange As Range\n Dim Cnum As Long, CalcMode As Long\n\n 'Fill in the path\\folder where the files are\n MyPath = \"C:\\Users\\Ron\\test\"\n\n 'Add a slash at the end if the user forget it\n If Right(MyPath, 1) <> \"\\\" Then\n MyPath = MyPath & \"\\\"\n End If\n\n 'If there are no Excel files in the folder exit the sub\n FilesInPath = Dir(MyPath & \"*.xl*\")\n If FilesInPath = \"\" Then\n MsgBox \"No files found\"\n Exit Sub\n End If\n\n 'Fill the array(myFiles)with the list of Excel files in the folder\n Fnum = 0\n Do While FilesInPath <> \"\"\n Fnum = Fnum + 1\n ReDim Preserve MyFiles(1 To Fnum)\n MyFiles(Fnum) = FilesInPath\n FilesInPath = Dir()\n Loop\n\n 'Change ScreenUpdating, Calculation and EnableEvents\n With Application\n CalcMode = .Calculation\n .Calculation = xlCalculationManual\n .ScreenUpdating = False\n .EnableEvents = False\n End With\n\n 'Add a new workbook with one sheet\n Set BaseWks = Workbooks.Add(xlWBATWorksheet).Worksheets(1)\n Cnum = 1\n\n 'Loop through all files in the array(myFiles)\n If Fnum > 0 Then\n For Fnum = LBound(MyFiles) To UBound(MyFiles)\n Set mybook = Nothing\n On Error Resume Next\n Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))\n On Error GoTo 0\n\n If Not mybook Is Nothing Then\n\n On Error Resume Next\n Set sourceRange = mybook.Worksheets(1).Range(\"A1:A10\")\n\n If Err.Number > 0 Then\n Err.Clear\n Set sourceRange = Nothing\n Else\n 'if SourceRange use all rows then skip this file\n If sourceRange.Rows.Count >= BaseWks.Rows.Count Then\n Set sourceRange = Nothing\n End If\n End If\n On Error GoTo 0\n\n If Not sourceRange Is Nothing Then\n\n SourceCcount = sourceRange.Columns.Count\n\n If Cnum + SourceCcount >= BaseWks.Columns.Count Then\n MsgBox \"Sorry there are not enough columns in the sheet\"\n BaseWks.Columns.AutoFit\n mybook.Close savechanges:=False\n GoTo ExitTheSub\n Else\n\n 'Copy the file name in the first row\n With sourceRange\n BaseWks.cells(1, Cnum). _\n Resize(, .Columns.Count).Value = MyFiles(Fnum)\n End With\n\n 'Set the destrange\n Set destrange = BaseWks.cells(2, Cnum)\n\n 'we copy the values from the sourceRange to the destrange\n With sourceRange\n Set destrange = destrange. _\n Resize(.Rows.Count, .Columns.Count)\n End With\n destrange.Value = sourceRange.Value\n\n Cnum = Cnum + SourceCcount\n End If\n End If\n mybook.Close savechanges:=False\n End If\n\n Next Fnum\n BaseWks.Columns.AutoFit\n End If\n\nExitTheSub:\n 'Restore ScreenUpdating, Calculation and EnableEvents\n With Application\n .ScreenUpdating = True\n .EnableEvents = True\n .Calculation = CalcMode\n End With\n\nEnd Sub\n" }, { "answer_id": 74465321, "author": "VBasic2008", "author_id": 9814069, "author_profile": "https://Stackoverflow.com/users/9814069", "pm_score": 0, "selected": false, "text": "Sub ImportColumns()\n \n ' Define constants.\n \n Const SOURCE_FOLDER_PATH As String = \"C:\\Test\"\n Const SOURCE_WORKSHEET_ID As Variant = 1 ' the first (you say: 'and only')\n Const SOURCE_FIRST_CELL_ADDRESS As String = \"A2\"\n Const SOURCE_FILE_PATTERN As String = \"*.xls\" ' only `.xls`\n \n Const DESTINATION_WORKSHEET_NAME As String = \"Master\"\n Const DESTINATION_FIRST_CELL_ADDRESS As String = \"A1\"\n \n ' Write the source file paths to a collection.\n \n Dim pSep As String: pSep = Application.PathSeparator\n \n Dim sPath As String: sPath = SOURCE_FOLDER_PATH\n If Right(sPath, 1) <> pSep Then sPath = sPath & pSep\n Dim sFolderName As String: sFolderName = Dir(sPath, vbDirectory)\n If Len(sFolderName) = 0 Then\n MsgBox \"The path '\" & sPath & \"' doesn't exist.\", vbExclamation\n Exit Sub\n End If\n Dim sDirPattern As String: sDirPattern = sPath & SOURCE_FILE_PATTERN\n \n Dim sFileName As String: sFileName = Dir(sDirPattern)\n If Len(sFileName) = 0 Then\n MsgBox \"No '\" & SOURCE_FILE_PATTERN & \"' files found in '\" _\n & sPath & \"'.\", vbExclamation\n Exit Sub\n End If\n \n Dim coll As Collection: Set coll = New Collection\n \n Do While Len(sFileName) > 0\n coll.Add sPath & sFileName\n sFileName = Dir\n Loop\n \n Application.ScreenUpdating = False\n \n ' Write data to a jagged array:\n ' - the 1st column will hold the headers (file name without extension)\n ' - the 2nd column will hold the source number of rows\n ' for the final inner loop i.e. 'For dr = 1 To dJag(c, 2)';\n ' this row number is used anyway, to determine the number\n ' of destination rows.\n ' - the 3rd column will hold an array with the source range values\n \n Dim dcCount As Long: dcCount = coll.Count\n Dim dJag As Variant: ReDim dJag(1 To dcCount, 1 To 3)\n Dim OneCell As Variant: ReDim OneCell(1 To 1, 1 To 1) ' if one cell\n \n Dim swb As Workbook\n Dim sws As Worksheet\n Dim srg As Range\n Dim sfCell As Range\n Dim slCell As Range\n Dim srCount As Long\n Dim swbName As String\n Dim drCount As Long\n Dim Item As Variant\n Dim c As Long\n \n For Each Item In coll\n c = c + 1\n Set swb = Workbooks.Open(Item, True, True)\n swbName = swb.Name\n ' Write file name without extension.\n dJag(c, 1) = Left(swbName, InStrRev(swbName, \".\") - 1)\n Set sws = swb.Worksheets(SOURCE_WORKSHEET_ID)\n If sws.FilterMode Then sws.ShowAllData\n Set sfCell = sws.Range(SOURCE_FIRST_CELL_ADDRESS)\n Set slCell = sfCell.Resize(sws.Rows.Count - sfCell.Row + 1) _\n .Find(\"*\", , xlFormulas, , , xlPrevious)\n If Not slCell Is Nothing Then\n Set srg = sws.Range(sfCell, slCell)\n srCount = srg.Rows.Count\n If srCount > drCount Then drCount = srCount ' determine max row\n ' Write number of rows.\n dJag(c, 2) = srCount\n ' Write data.\n If srCount = 1 Then ' one cell in column\n OneCell(1, 1) = srg.Value\n dJag(c, 3) = OneCell\n Else ' multiple cells in column\n dJag(c, 3) = srg.Value\n End If\n 'Else ' no data in column; do nothing\n End If\n swb.Close SaveChanges:=False ' just reading\n Next Item\n Set coll = Nothing ' data is in 'dJag'\n \n drCount = drCount + 1 ' + 1 for headers\n \n ' Write the data from the jagged array to the destination array.\n \n Dim dData() As Variant: ReDim dData(1 To drCount, 1 To dcCount)\n \n Dim dr As Long\n \n For c = 1 To dcCount\n ' Write header.\n dData(1, c) = dJag(c, 1)\n ' Write data.\n If Not IsEmpty(dJag(c, 2)) Then\n For dr = 1 To dJag(c, 2)\n dData(dr + 1, c) = dJag(c, 3)(dr, 1) ' + 1 due to headers\n Next dr\n 'Else ' no data in column; do nothing\n End If\n Next c\n Erase dJag ' data is in 'dData'\n \n ' Write the data from the destination array to the destination range.\n \n Dim dwb As Workbook: Set dwb = ThisWorkbook ' workbook containing this code\n Dim dws As Worksheet: Set dws = dwb.Worksheets(DESTINATION_WORKSHEET_NAME)\n Dim dfCell As Range: Set dfCell = dws.Range(DESTINATION_FIRST_CELL_ADDRESS)\n Dim drg As Range: Set drg = dfCell.Resize(drCount, dcCount)\n \n drg.Value = dData\n \n Application.ScreenUpdating = True\n \n MsgBox \"Columns imported.\", vbInformation\n \nEnd Sub\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74451552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20513678/" ]