qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,172,952
<p>I would like the a tag to change to span when the variable 'nav' is false. When I try to do this, the text literally changes to &quot; home &quot; and I wish it would become an icon. What can I do?</p> <pre><code>&lt;a href=&quot;/&quot;&gt;{nav ? 'HOME' : &quot;&lt;span class=&quot;material-symbols-outlined&quot;&gt; home &lt;/span&gt;&quot;}&lt;/a&gt; </code></pre>
[ { "answer_id": 74173013, "author": "Abdelhk", "author_id": 19675360, "author_profile": "https://Stackoverflow.com/users/19675360", "pm_score": -1, "selected": false, "text": "material-symbols-outlined" }, { "answer_id": 74173239, "author": "Konrad", "author_id": 5089567, ...
2022/10/23
[ "https://Stackoverflow.com/questions/74172952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18864189/" ]
74,173,079
<p>Trying to create a small program that takes in positive integers and converts it into reverse binary.</p> <p>I've gotten this far:</p> <pre><code>import math integer = int(input()) while integer &gt; 0: x = integer % 2 print(int(math.floor(x)), end='') integer = integer / 2 </code></pre> <p>The problem with this is that the output would have unnecessary trailing 0s. For example, if the input is 12, the output would be 0011000......</p> <p>I've tried the <strong>int</strong> function to remove floats, I also tried <strong>floor</strong> function to round up(albeit I might've done it wrong).</p> <p>Could the problem be a lack of sentinel value?</p>
[ { "answer_id": 74173142, "author": "Fares_Hassen", "author_id": 20310974, "author_profile": "https://Stackoverflow.com/users/20310974", "pm_score": -1, "selected": false, "text": "//" }, { "answer_id": 74173147, "author": "Tom McLean", "author_id": 14720380, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74173079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315929/" ]
74,173,089
<p>I am trying to set/read if a user is authenticated in my application. I have things working, but as I am learning more about RxJs, I am trying to refactor things to be more declarative.</p> <p>My code samples below are 98% working. When I log in, I am seeing my logging statement in my service as expected with the correct value(s):</p> <blockquote> <p>console.log('setting auth status...', status); // true</p> </blockquote> <p>However, I'm not seeing the logging in my component:</p> <blockquote> <p>console.log('reading isAuthenticated$ status... ', response) &lt;-- not seeing this when logging in</p> </blockquote> <p>If I refresh my page, I am seeing <code>Hello World</code> as expected. Since I am subscribing using the <code>async</code> pipe, I thought I would see the ui update without having to refresh.</p> <p>If I log out, (click a button). I am seeing <em>all</em> logging statements as expected every time--even without refreshing.</p> <blockquote> <p>console.log('setting auth status...', status); // false</p> </blockquote> <blockquote> <p>console.log('reading isAuthenticated$ status... ', response) // false</p> </blockquote> <p>This makes me think there is something wrong how I am emitting or reading <code>isAuthenticated$</code> observable.</p> <p>How can I read the <code>isAuthenticated$</code> observable in my template without refreshing?</p> <p>Here is my service:</p> <pre><code>// auth.service.ts export class AuthService { private readonly baseURL = environment.baseURL; private isAuthenticatedSubject = new BehaviorSubject&lt;boolean&gt;( this.hasAccessToken() ); isAuthenticated$ = this.isAuthenticatedSubject.asObservable(); ... signInWithEmailPassword( emailPasswordCredentials: EmailPasswordCredentials ) { return this.httpClient .post&lt;Response&gt;( `${this.baseURL}/v1/auth/signin`, emailPasswordCredentials ) .pipe( map((authResponse) =&gt; { // set auth cookie this.setAuthenticatedStatus(true); }) catchError((err) =&gt; { return throwError(err); }) ); } ... setAuthenticatedStatus(status: boolean): void { console.log('setting auth status...', status); this.isAuthenticatedSubject.next(status); // true|false } signOut(): void { this.router.navigate(['/signin']).then(() =&gt; { this.setAuthenticatedStatus(false); }); } } </code></pre> <p>Here is what my component looks like:</p> <pre><code>// app.component.ts isAuthenticated$ = this.authService.isAuthenticated$.pipe( tap((response) =&gt; console.log('reading isAuthenticated$ status... ', response) ), catchError((err) =&gt; { this.message = err; return EMPTY; }) ); </code></pre> <p>Finally, here is my template:</p> <pre><code>&lt;div *ngIf=&quot;isAuthenticated$ | async&quot;&gt;Hello World!&lt;/div&gt; </code></pre> <p><strong>EDIT</strong></p> <p>I have a <code>login.component</code> that handles the email/password button click. It looks like this:</p> <pre><code>signInWithEmailPassword(form: FormGroup): void { if (form.invalid) { return; } ... this.authService.signInWithEmailPassword(this.form.value).subscribe({ next: (response) =&gt; { this.router.navigate(['/dashboard']).then(() =&gt; { // this.authService.setAuthenticatedStatus(true); // This doesn't seem to impact anything }); }, error: (err) =&gt; { this.handleHttpError(err); }, complete: () =&gt; { //... }, }); } </code></pre> <p>I thought that by setting that in my <code>login.component</code> I could update that subject. It all works after I refresh the page. The nav shows...but if I just login... it's like I'm not &quot;watching&quot; on my <code>app.component</code> that observable or something.</p> <p><strong>EDIT/UPDATE</strong></p> <p>I have tried to set up a <a href="https://stackblitz.com/edit/angular-ivy-jhshqi?file=src%2Fapp%2Frouter%2Froutes.ts,src%2Fapp%2Fauthentication%2Fauth.service.ts,src%2Fapp%2Fapp.component.ts" rel="nofollow noreferrer">stackblitz</a> to help illustrate what I'm running into. I am not sure how to mock the auth part to return a dummy response, but hopefully this will help.</p>
[ { "answer_id": 74173142, "author": "Fares_Hassen", "author_id": 20310974, "author_profile": "https://Stackoverflow.com/users/20310974", "pm_score": -1, "selected": false, "text": "//" }, { "answer_id": 74173147, "author": "Tom McLean", "author_id": 14720380, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74173089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3357270/" ]
74,173,090
<p>I need to have in array with lat/lon points like that:</p> <pre><code>/* var polylinePoints = [ [37.781814, -122.404740], [37.781719, -122.404637], [37.781489, -122.404949], [37.780704, -122.403945], [37.780012, -122.404827] ]; */ </code></pre> <p><strong>But I need first to sort it by third parameter which is timestamp? How to do that? I know how to do that in PHP but not in JS</strong></p> <pre><code>var polylineTimestamp = [ [37.781814, -122.404740, 1666543938], [37.781719, -122.404637, 1666543938], [37.781489, -122.404949, 1666543938], [37.780704, -122.403945, 1666543938], [37.780012, -122.404827, 1666543938] ]; </code></pre> <p>Then I need to delete (trim) sorted array (delete timestamp) to have something like polylinePoints.</p> <p>Here is Jsfiddle: <a href="https://jsfiddle.net/qsdaLz7h/" rel="nofollow noreferrer">https://jsfiddle.net/qsdaLz7h/</a></p>
[ { "answer_id": 74173154, "author": "Bagus", "author_id": 19926941, "author_profile": "https://Stackoverflow.com/users/19926941", "pm_score": 0, "selected": false, "text": "let arr = []\npolylineTimestamp.forEach((el) => {\n arr.push([el[0],el[1]])\n})\nconsole.log(arr)\n//! expected out...
2022/10/23
[ "https://Stackoverflow.com/questions/74173090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3174901/" ]
74,173,106
<p>I am trying to figure out why I cannot get the number to change to a letter. There seems to be something I am missing when returning the char function to the main function, but I cannot figure it out. When I print it, it will not print out the letter. I would really appreciate some guidance.</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; char letter(int grade); int main() { int score; //taken as user input int grade; printf(&quot;\tEnter your numberical grade: &quot;); scanf(&quot;%i&quot;, score); letter(grade); printf(&quot;Your grade is a %i&quot;, grade); return 0; } char letter(int grade) { switch(grade/10) { case 10: { return 'A'; break; } case 9: { return 'A'; break; } case 8: { return 'B'; break; } case 7: { return 'C'; break; } case 6: { return 'D'; break; } case 5: { return 'D'; break; } return grade; } } </code></pre>
[ { "answer_id": 74173154, "author": "Bagus", "author_id": 19926941, "author_profile": "https://Stackoverflow.com/users/19926941", "pm_score": 0, "selected": false, "text": "let arr = []\npolylineTimestamp.forEach((el) => {\n arr.push([el[0],el[1]])\n})\nconsole.log(arr)\n//! expected out...
2022/10/23
[ "https://Stackoverflow.com/questions/74173106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20255820/" ]
74,173,137
<p>Its a easy starting project that I'm doing, but the main body would be accesing to the information on the Webpage , so , I don't know if i'm doing something wrong</p> <p>the starting code is: (to see if it works on Fotocasa Webpage)</p> <pre><code>import requests from bs4 import BeautifulSoup url = 'https://www.fotocasa.es/es/comprar/vivienda/valencia-capital/aire-acondicionado-trastero-ascensor-no-amueblado/161485852/d' # url = 'https://www.idealista.com/inmueble/97795476/' headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'es,es-ES;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'cache-control': 'max-age=0', 'dnt': '1', 'sec-ch-ua': '&quot;Chromium&quot;;v=&quot;106&quot;, &quot;Microsoft Edge&quot;;v=&quot;106&quot;, &quot;Not;A=Brand&quot;;v=&quot;99&quot;', 'sec-ch-ua-mobile': '?0', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'none', 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.47' } r = requests.get(url, headers=headers) print(r) req = requests.get(url, headers=headers).text # Now that the content is ready, iterate # through the content using BeautifulSoup: soup = BeautifulSoup(req, &quot;html.parser&quot;) # get the information of a given tag inm = soup.find(class_=&quot;re-DetailHeader-propertyTitle&quot;).text print(inm) </code></pre> <p>You can try and see that with the URL of Fotocasa , works perfectly (gets &lt;Response [200]&gt;) , but with the one from Idealista, doesn't work, (gets &lt;Response [403]&gt;)</p> <p>the code is:</p> <pre><code>import requests from bs4 import BeautifulSoup # url = 'https://www.fotocasa.es/es/comprar/vivienda/valencia-capital/aire-acondicionado-trastero-ascensor-no-amueblado/161485852/d' url = 'https://www.idealista.com/inmueble/97795476/' headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'es,es-ES;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 'cache-control': 'max-age=0', 'dnt': '1', 'sec-ch-ua': '&quot;Chromium&quot;;v=&quot;106&quot;, &quot;Microsoft Edge&quot;;v=&quot;106&quot;, &quot;Not;A=Brand&quot;;v=&quot;99&quot;', 'sec-ch-ua-mobile': '?0', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'none', 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.47' } r = requests.get(url, headers=headers) print(r) req = requests.get(url, headers=headers).text # Now that the content is ready, iterate # through the content using BeautifulSoup: soup = BeautifulSoup(req, &quot;html.parser&quot;) # get the information of a given tag inm = soup.find(class_=&quot;main-info__title-main&quot;).text print(inm) </code></pre>
[ { "answer_id": 74187673, "author": "Driftr95", "author_id": 6146136, "author_profile": "https://Stackoverflow.com/users/6146136", "pm_score": 1, "selected": false, "text": "soup = BeautifulSoup(response.content, \"html.parser\")\n" } ]
2022/10/23
[ "https://Stackoverflow.com/questions/74173137", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315236/" ]
74,173,166
<p>I am not getting price they give me empty output this is page link <a href="https://rads.stackoverflow.com/amzn/click/com/B00M0DWQYI" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/dp/B00M0DWQYI?th=1</a></p> <pre><code>from selenium import webdriver import time from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.select import Select from selenium.webdriver.support import expected_conditions as EC import pandas as pd url='https://www.amazon.com/dp/B00M0DWQYI?th=1' PATH=&quot;C:\Program Files (x86)\chromedriver.exe&quot; driver =webdriver.Chrome(PATH) driver.get(url) item=dict() try: item['price'] = driver.find_element(By.XPATH, &quot;//div[@id='corePrice_feature_div'] //span[@class='a-offscreen']&quot;).text except: item['price']='' print(item) </code></pre>
[ { "answer_id": 74173291, "author": "Barry the Platipus", "author_id": 19475185, "author_profile": "https://Stackoverflow.com/users/19475185", "pm_score": 1, "selected": false, "text": "[...]\nwait = WebDriverWait(driver, 10)\n\n\nitem['price'] = wait.until(EC.element_to_be_clickable((By....
2022/10/23
[ "https://Stackoverflow.com/questions/74173166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19847386/" ]
74,173,174
<p>For an assignement I have to write a Greedy Algorithm using a recursive function, but I can't seem to figure out how to do this.</p> <p>The assignement is to make a route to go from one city to another, each time going to the city with the lowest distance between them, but no visit cities multiple times.</p> <p>For now I have the following code, which is of course far from done as it doesnt even have any recursion and simply doesn't give the right result. I wouldn't be surprised if this code is not even slightly right. The result I get is [1,2,1,1], meaning the route would be from city 0 to 1, to 2, to 1, to 1. The answer should be [1, 2, 3].</p> <p>I've been trying this code for way too long now and I just can't seem to figure it out. I get the idea of what I have to do: take the index of the lowest distance, check if that index is already in list v, if it is, take the second lowest distance and check again. But I can't figure out how to put this into code and include recursion.</p> <p>Is anyone able to give me any tips to help me along or link me an example code?</p> <p>PS I am not allowed to use any import functions, this assignement is for a relatively simple (though not simple for me) programming course at my university</p> <pre><code>v = [] def append_list_with_nearest_unvisited(visited, distances): city = 0 for n in range(len(distances)): if city in v: i = min(j for j in distances[n] if j &gt; 0) #take lowest distance h = min(k for k in distances[n] if k &gt; i) #take second lowest distance because the true lowest distance is a visited city city = distances[n].index(h) #city visited is the index of the lowest distance v.append(city) else: i = min(j for j in distances[n] if j &gt; 0) #take lowest distance city = distances[n].index(i) v.append(city) print(v) append_list_with_nearest_unvisited(v, [[0,2,3,4],[2,0,4,5],[3,4,0,6],[4,5,6,0]]) </code></pre>
[ { "answer_id": 74173428, "author": "GOKARNA ADHIKARI", "author_id": 18089268, "author_profile": "https://Stackoverflow.com/users/18089268", "pm_score": 1, "selected": false, "text": "nodes = [0,1,2,3]\n\ndistanceMat = [\n [0,2,3,4],\n [2,0,4,5],\n [3,4,0,6],\n [4,5,6,0]\n ...
2022/10/23
[ "https://Stackoverflow.com/questions/74173174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20208525/" ]
74,173,183
<p>This is an exercise for electric circuits that I have to for uni and basically I have been given the frequency and the Voltage to generate a square graph. Frequency is 2kHz so the Period(T) is 0.0005s and the Voltage is 5V.</p> <p>The graph should look like that(i drew that in AutoCad for presentation purposes): <a href="https://i.stack.imgur.com/jkbi2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jkbi2.png" alt="enter image description here" /></a></p> <p>Any ideas on how I can draw this in excel?</p>
[ { "answer_id": 74173428, "author": "GOKARNA ADHIKARI", "author_id": 18089268, "author_profile": "https://Stackoverflow.com/users/18089268", "pm_score": 1, "selected": false, "text": "nodes = [0,1,2,3]\n\ndistanceMat = [\n [0,2,3,4],\n [2,0,4,5],\n [3,4,0,6],\n [4,5,6,0]\n ...
2022/10/23
[ "https://Stackoverflow.com/questions/74173183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19996843/" ]
74,173,213
<p>I'm a beginner at python, and have been given this task: Write a program that lets a user input numbers and have them multiplied. The user can use the program 5 times, then it should stop. Use at least a for loop and a function.</p> <p>I believe the code here will ask for the numbers, multiply and give the answer, but how do I get it to run 5 times then stop asking for more numbers?</p> <pre class="lang-py prettyprint-override"><code># get inputs num1 = int(input('Enter first number: ')) num2 = int(input('Enter second number: ')) # calculate product product = 0 for i in range(1,num2+1): product=product+num1` # give answer print(&quot;The Product of Number:&quot;, product) </code></pre>
[ { "answer_id": 74173249, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": true, "text": "for i in range(1,num2+1)" }, { "answer_id": 74210471, "author": "Chris Ze Third", "author_id": 19392385, ...
2022/10/23
[ "https://Stackoverflow.com/questions/74173213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315793/" ]
74,173,217
<p>Why was the last A <a href="https://postimg.cc/1gQYg63W" rel="nofollow noreferrer">picked</a> from ns1 namespace instead of ns2?<br /> (Bar is of <a href="https://postimg.cc/dhKzCgWm" rel="nofollow noreferrer">type</a> <code>ns1::A&lt;ns1::A&lt;ns2::A, ns2::B&gt;, ns2::B&gt;</code>)</p> <pre><code>namespace ns1 { template &lt;typename T, typename U&gt; struct A {}; } namespace ns2 { struct /*ns2*/ A : ns1::A&lt;int, /*ns2*/ A&gt; { typedef ns1::A&lt;int, /*ns2*/ A&gt; Foo; }; struct B : ns1::A&lt; /*ns2*/ A, B&gt; { typedef ns1::A&lt; /*ns1*/ A, B&gt; Bar; }; } </code></pre> <p>I'm using vscode with g++ 11.2.0</p>
[ { "answer_id": 74173592, "author": "interjay", "author_id": 189205, "author_profile": "https://Stackoverflow.com/users/189205", "pm_score": 3, "selected": true, "text": "ns1::A<T, U>" }, { "answer_id": 74173927, "author": "Jason Liam", "author_id": 12002570, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74173217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19612346/" ]
74,173,218
<p>I am using vue js with vuetify. Came across an interesting scenario . So i have three options (radio-buttons)</p> <ul> <li>Left</li> <li>Center</li> <li>Right</li> </ul> <p>And i have a v-text-field with a certain text as value and readonly . Now i want to change the position of that text inside v-text-field when option is changed/selected.</p> <p>So for instance, upon option 1(left) text should be at moved at left inside v-text-field. Upon option 2(centre) text should be moved at center. And goes on.</p> <p>Any suggestions for that. Also guide if you have a better approach</p>
[ { "answer_id": 74173592, "author": "interjay", "author_id": 189205, "author_profile": "https://Stackoverflow.com/users/189205", "pm_score": 3, "selected": true, "text": "ns1::A<T, U>" }, { "answer_id": 74173927, "author": "Jason Liam", "author_id": 12002570, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74173218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16986959/" ]
74,173,240
<p>I'm working on a small project where I would like to visualize a DataFrame using <code>python</code> + <code>streamlit</code>. The user should be able to filter on three different columns where the options which should be available depend on each other. A minimal example is given by the DataFrame below.</p> <pre><code>import pandas as pd df = pd.DataFrame( { &quot;continent&quot;: [&quot;Asia&quot;] * 2 + [&quot;Europe&quot;] * 2 + [&quot;North America&quot;] * 2, &quot;country&quot;: [&quot;China&quot;, &quot;Japan&quot;] + [&quot;United Kingdom&quot;, &quot;France&quot;] + [&quot;United States&quot;, &quot;Canada&quot;], &quot;language&quot;: [&quot;Chinese&quot;, &quot;Japanese&quot;] + [&quot;English&quot;, &quot;French&quot;] + [&quot;English&quot;, &quot;English&quot;], } ) </code></pre> <p>The user should be able to select <code>continent</code>, <code>country</code> and <code>language</code>.</p> <p>Example 1: The user selects <code>continent = North America</code> which should reduce the options for the country menu to <code>United States</code> and <code>Canada</code> and the languages to <code>English</code>. As a next step, if the user switches from <code>continent = America</code> to <code>continent = Europe</code>, the second menu should reduce to the countries in Europe and the languages spoken in these countries.</p> <p>Example 2: The user starts by selection <code>language = English</code>. As as a result the options for <code>continent</code> reduce to <code>North America</code> and <code>Europe</code> since the countries in which English is spoken are <code>Canada</code>, the <code>United States</code> and the <code>United Kingdom</code>.</p> <p>The problem is, that the values depend on each other in a non-linear fashion. I've tried to solve this problem with <code>streamlit</code> and <code>callback</code> but from reading other questions my impression is that <code>streamlit</code> is not designed for complex dependencies.</p> <p>I've not yet worked with <code>Dash</code>. Before I start working on this by copy-pasting code from the internet my question is whether it is possible to build these complex dependencies with <code>dash</code>?</p> <p><strong>Update</strong></p> <p>I was able to build an MVP with <code>streamlit</code> using the code at the end. The dropdown menus are dynamic which is what I was looking for (Image 1). But because the dropdown options depend on the filtered DataFrame, once a selection was made, the only way back is to use the <code>Refresh Data</code> button which is not very user friendly (Image 2).</p> <p>Image 1: Without selection <a href="https://i.stack.imgur.com/nobd0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nobd0.png" alt="enter image description here" /></a></p> <p>Image 2: After the first selection <a href="https://i.stack.imgur.com/PJxX3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PJxX3.png" alt="enter image description here" /></a></p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import streamlit as st st.set_page_config(page_title=&quot;Toy App&quot;, layout=&quot;wide&quot;) @st.cache def get_data(): df = pd.DataFrame( { &quot;Continent&quot;: [&quot;Asia&quot;] * 2 + [&quot;Europe&quot;] * 2 + [&quot;North America&quot;] * 2, &quot;Country&quot;: [&quot;China&quot;, &quot;Japan&quot;] + [&quot;United Kingdom&quot;, &quot;France&quot;] + [&quot;United States&quot;, &quot;Canada&quot;], &quot;Language&quot;: [&quot;Chinese&quot;, &quot;Japanese&quot;] + [&quot;English&quot;, &quot;French&quot;] + [&quot;English&quot;, &quot;English&quot;], } ) return df def update_df(df: pd.DataFrame) -&gt; pd.DataFrame: continent = st.session_state[&quot;Continent&quot;] country = st.session_state[&quot;Country&quot;] language = st.session_state[&quot;Language&quot;] if continent != &quot;all&quot;: df = df.query(f&quot;Continent == '{continent}'&quot;) if country != &quot;all&quot;: df = df.query(f&quot;Country == '{country}'&quot;) if language != &quot;all&quot;: df = df.query(f&quot;Language == '{language}'&quot;) st.session_state[&quot;df&quot;] = df st.session_state[&quot;fresh_data&quot;] = False df = get_data() if &quot;df&quot; not in st.session_state: st.session_state.df = df if &quot;fresh_data&quot; not in st.session_state: st.session_state.fresh_data = True with st.expander(&quot;Display&quot;, expanded=True): if st.button(&quot;Refresh data&quot;): df = get_data() st.session_state[&quot;df&quot;] = df st.session_state[&quot;fresh_data&quot;] = True df = st.session_state[&quot;df&quot;] col1, col2, col3 = st.columns(3) continent_options = df.Continent.unique().tolist() country_options = df.Country.unique().tolist() language_options = df.Language.unique().tolist() if st.session_state.fresh_data: country_options.insert(0, &quot;all&quot;) language_options.insert(0, &quot;all&quot;) continent_options.insert(0, &quot;all&quot;) continent = col1.selectbox( &quot;Continent&quot;, options=continent_options, on_change=update_df, kwargs={&quot;df&quot;: df}, key=&quot;Continent&quot;, ) countries = col2.selectbox( &quot;Country&quot;, options=country_options, on_change=update_df, kwargs={&quot;df&quot;: df}, key=&quot;Country&quot;, ) language = col3.selectbox( &quot;Language&quot;, options=language_options, on_change=update_df, kwargs={&quot;df&quot;: df}, key=&quot;Language&quot;, ) st.write(df.astype(&quot;object&quot;)) </code></pre>
[ { "answer_id": 74178949, "author": "LazyClown", "author_id": 3392461, "author_profile": "https://Stackoverflow.com/users/3392461", "pm_score": 0, "selected": false, "text": "import streamlit as st\nimport pandas as pd\n\ndef value_change(category):\n st.session_state.df = st.session_s...
2022/10/23
[ "https://Stackoverflow.com/questions/74173240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19542908/" ]
74,173,246
<p>I'm working with investment fund data taken from Morningstar, which provides them at share class level. For people who did not have exposure to finance/funds, no need to dive into detail, but mine is a panel data structured as following:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Fund ID</th> <th>Sec ID</th> <th>Net Assets</th> <th>Return</th> <th>Rating</th> </tr> </thead> <tbody> <tr> <td>A</td> <td>A1</td> <td>100</td> <td>1%</td> <td>4 stars</td> </tr> <tr> <td>A</td> <td>A2</td> <td>200</td> <td>1,2 %</td> <td>4 stars</td> </tr> <tr> <td>A</td> <td>A3</td> <td>150</td> <td>0,5 %</td> <td>3 stars</td> </tr> <tr> <td>B</td> <td>B1</td> <td>50</td> <td>1,1 %</td> <td>2 stars</td> </tr> <tr> <td>B</td> <td>B2</td> <td>120</td> <td>0,75%</td> <td>3 stars</td> </tr> <tr> <td>C</td> <td>C1</td> <td>300</td> <td>0,4%</td> <td>5 stars</td> </tr> <tr> <td>C</td> <td>C2</td> <td>500</td> <td>0,55%</td> <td>4 stars</td> </tr> </tbody> </table> </div> <p>What I need to achieve is to aggregate data at Fund level (Fund ID), so that the fund size will be the sum of the net assets of the different share classes (Sec ID). The return and the star rating at fund level will be the weighted average of both variables (star rating rounded). I'm using R and my dataset is made of over 8000 share classes therefore it's essential to get an easily scalable solution.</p> <p>i.e. Fund A return would be: (0.01 * 100 + 0.012 * 200 + 0.005 * 150) / (100 + 200 + 150) = 0,92%</p> <p>Fund B rating would be (2 * 50 + 3 * 120) / (50 + 120) = 2.70 rounded to 3</p> <p>Any help on how to achieve such a result? How could I apply that to a panel data (with daily observation over 3 months)?</p>
[ { "answer_id": 74178949, "author": "LazyClown", "author_id": 3392461, "author_profile": "https://Stackoverflow.com/users/3392461", "pm_score": 0, "selected": false, "text": "import streamlit as st\nimport pandas as pd\n\ndef value_change(category):\n st.session_state.df = st.session_s...
2022/10/23
[ "https://Stackoverflow.com/questions/74173246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20138442/" ]
74,173,255
<p>I am trying to come up with a script that will let the user read one line of the text file on each input of enter key until the file is done. What i tried so far:</p> <pre><code>while read -r line do read input if [[ -z $input ]]; then echo $line done &lt; file.txt </code></pre> <p>or</p> <pre><code>while read -r line echo | echo $line done &lt; file.txt </code></pre> <p>with the error:</p> <pre><code>sh: -c: line 3: syntax error near unexpected token `done' sh: -c: line 3: `done &lt; file.txt' </code></pre> <p>update: i forgot &quot;fi&quot; at the end of &quot;if&quot;. however,</p> <pre><code>while IFS= read -r line do read input if [[ -z $input ]] then echo $line fi done &lt; filename.txt </code></pre> <p>This time i am not getting any error, but it does not expect my enter input and does not print anything.</p>
[ { "answer_id": 74178949, "author": "LazyClown", "author_id": 3392461, "author_profile": "https://Stackoverflow.com/users/3392461", "pm_score": 0, "selected": false, "text": "import streamlit as st\nimport pandas as pd\n\ndef value_change(category):\n st.session_state.df = st.session_s...
2022/10/23
[ "https://Stackoverflow.com/questions/74173255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315980/" ]
74,173,313
<p>I am trying to understand memory allocations in Julia and was playing around with the following test code:</p> <pre><code>function f() function test(x,y) return x-1,y+1 end x1=5 y1=6 function stest(num_runs,x,y) for i in 1:num_runs x,y=test(x,y) end return x,y end x1,y1=stest(10,x1,y1) println(x1,' ',y1) end @time begin f() end @time begin f() end </code></pre> <p>When I run it, I get the following outputs:</p> <pre><code> -5 16 0.027611 seconds (20.59 k allocations: 1.039 MiB, 92.11% compilation time) -5 16 0.000077 seconds (18 allocations: 496 bytes) </code></pre> <p>Why is there a memory allocation at all? And why is that so much the first time around? I have been reading through the docs but having trouble figuring it out.</p>
[ { "answer_id": 74173994, "author": "Przemyslaw Szufel", "author_id": 9957710, "author_profile": "https://Stackoverflow.com/users/9957710", "pm_score": 2, "selected": false, "text": "BenchmarkTools" }, { "answer_id": 74176762, "author": "JustLearning", "author_id": 1996239...
2022/10/23
[ "https://Stackoverflow.com/questions/74173313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20246532/" ]
74,173,352
<p>I want to submit input details by clicking enter but in 5 sec here is the code please add timing in the code</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>document.addEventListener("DOMContentLoaded", () =&gt; { inputValue.addEventListener("keydown", (e) =&gt; { if (e.code === "Enter") { let input = inputValue.value; inputValue.value = ""; output(input); } }); });</code></pre> </div> </div> </p>
[ { "answer_id": 74173391, "author": "Vojin Purić", "author_id": 16547945, "author_profile": "https://Stackoverflow.com/users/16547945", "pm_score": 0, "selected": false, "text": "setTimeout(_=>{\n if (e.code === \"Enter\") \n {\n let input = inputValue.value;\n input...
2022/10/23
[ "https://Stackoverflow.com/questions/74173352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316159/" ]
74,173,364
<p>Given the following list: <code>list = [2,10,10,10,4,5]</code></p> <p>How can I write a function that returns the output: <code>output = 210AA:45</code></p> <p>I was working with this code so far, but don't know what else to add so that once a number between 10 and 15 is repeated, return the repeated number in its hexadecimal form as in the output</p> <pre><code>def int_to_string(data): string = &quot;&quot; for i in data: hexadecimal = hex(i) string += hexadecimal[2:] string[0] = 15 return string </code></pre>
[ { "answer_id": 74173391, "author": "Vojin Purić", "author_id": 16547945, "author_profile": "https://Stackoverflow.com/users/16547945", "pm_score": 0, "selected": false, "text": "setTimeout(_=>{\n if (e.code === \"Enter\") \n {\n let input = inputValue.value;\n input...
2022/10/23
[ "https://Stackoverflow.com/questions/74173364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20226699/" ]
74,173,370
<p>I'm new to programming. I'm supposed to make a function that reads only dates and temperatures from the file. I would really appreciate the help. Thanks in advance.</p> <pre><code>def read_data(text): data = open(text, 'r') for line in data: split_data = line.split(',') if line.isdigit(): date = split_data[1] temperature = split_data[2] full_data = date + temperature data.close return full_data max_dates, max_temps = read_data('DeBiltTempMax2022.txt') </code></pre> <p>this is the sample of the text file:</p> <pre><code> EUROPEAN CLIMATE ASSESSMENT &amp; DATASET (ECA&amp;D), file created on 23-05-2022 THESE DATA CAN BE USED FREELY PROVIDED THAT THE FOLLOWING SOURCE IS ACKNOWLEDGED: Klein Tank, A.M.G. and Coauthors, 2002. Daily dataset of 20th-century surface air temperature and precipitation series for the European Climate Assessment. Int. J. of Climatol., 22, 1441-1453. Data and metadata available at http://www.ecad.eu FILE FORMAT (MISSING VALUE CODE IS -9999): 01-06 SOUID: Source identifier 08-15 DATE : Date YYYYMMDD 17-21 TX : maximum temperature in 0.1 &amp;#176;C 23-27 Q_TX : Quality code for TX (0='valid'; 1='suspect'; 9='missing') This is the blended series of station NETHERLANDS, DE BILT (STAID: 162). Blended and updated with sources: 100522 906260 See file sources.txt and stations.txt for more info. SOUID, DATE, TX, Q_TX 100522,19010101, -24, 0 100522,19010102, -14, 0 100522,19010103, -6, 0 100522,19010104, -11, 0 100522,19010105, -20, 0 100522,19010106, -80, 0 100522,19010107, -68, 0 100522,19010108, -7, 0 100522,19010109, 44, 0 100522,19010110, 61, 0 100522,19010111, 51, 0 100522,19010112, -20, 0 100522,19010113, -20, 0 100522,19010114, 31, 0 100522,19010115, 54, 0 100522,19010116, 42, 0 100522,19010117, 65, 0 100522,19010118, 43, 0 100522,19010119, 64, 0 </code></pre>
[ { "answer_id": 74173431, "author": "Fares_Hassen", "author_id": 20310974, "author_profile": "https://Stackoverflow.com/users/20310974", "pm_score": -1, "selected": false, "text": "return full_data" }, { "answer_id": 74173593, "author": "linux.manifest", "author_id": 20229...
2022/10/23
[ "https://Stackoverflow.com/questions/74173370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316143/" ]
74,173,375
<p>I am using C to work on a program that manages structs in a binary file.</p> <p>I am having issues with my deleteData()function.</p> <p>The method gets file name from user, validates file name, asks for record id to be deleted, then it copies the records except the one to be deleted from a file it is reading to a temp file.</p> <p>The function should then close files, delete old file, and rename new file by the old file's name.</p> <p>Everything appears to work except I can't open the new renamed file. I have checked the outcome in every step and it all appears to be ok.</p> <p>Furthermore, when I look in my folder, I can see the renamed file and from it's byte size I can tell that a record has indeed been deleted.</p> <p>But I can't open the file.</p> <p>Please see my code below. I am working on a MAC, I have saved the folder that includes the code on my desktop. I am new to programming so any feedback or advise would be greatly appreciated.</p> <pre><code>void deleteData() { char studentID[10]; char fileName5[30]; char tmpFile[] = &quot;tmp.bin&quot;; FILE *file; FILE *tmpf; int erFlag = 0; int foFlag = 0; int t; struct Record tmp; do { printf(&quot; Enter file in which record is located:\n&quot;); scanf(&quot;%30s&quot;, fileName5); if (!valSuf(fileName5)) printf(&quot;Error wih file name.\n&quot;); } while (!valSuf(fileName5)); file = fopen(fileName5, &quot;rb&quot;); if (file == NULL) printf(&quot;Error opening file.&quot;); if (fread(&amp;t, sizeof(int), 1, file) != 1) printf(&quot;error reading total&quot;); tmpf = fopen(tmpFile, &quot;wb&quot;); if (tmpf == NULL) printf(&quot;Error opening temp file.&quot;); if (fwrite(&amp;t, sizeof(int), 1, tmpf) != 1) printf(&quot;Error writing total.&quot;); printf(&quot;Enter student ID you want to delete:&quot;); scanf(&quot;%30s&quot;, studentID); scanf(&quot;%*[^\n]&quot;); while (fread(&amp;tmp, sizeof(Record), 1, file) != 0) { printf(&quot;%s\n&quot;, tmp.studentId); if (strcmp(tmp.studentId, studentID) != 0) { fwrite(&amp;tmp, sizeof(Record), 1, tmpf); printf(&quot;written to file: %s\n&quot;, tmp.studentId); } else { foFlag = 1; } } if (foFlag == 1) { printf(&quot;Record not found.\n&quot;); fclose(tmpf); fclose(file); remove(tmpFile); } else { printf(&quot;in final stage.\n&quot;); printf(&quot;closing file:%d\n&quot;, fclose(file)); printf(&quot;closing tmp: %d\n&quot;, fclose(tmpf)); printf(&quot;removing old file:%d\n&quot;, remove(fileName5)); printf(&quot;renaming file: %d\n&quot;, rename(tmpFile, fileName5)); } } </code></pre>
[ { "answer_id": 74173637, "author": "Craig Estey", "author_id": 5382650, "author_profile": "https://Stackoverflow.com/users/5382650", "pm_score": 2, "selected": true, "text": "scanf(\"%30s\", studentID);" }, { "answer_id": 74174681, "author": "J. sva", "author_id": 1732207...
2022/10/23
[ "https://Stackoverflow.com/questions/74173375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17322074/" ]
74,173,402
<p>I use MongoDB to store user data. The user id goes incrementally, such as 1, 2, 3, 4 etc when new user register.</p> <p>I have the following code to generate the user id. &quot;users&quot; is the name of the collection where I store the user data.</p> <pre><code>// generate new user id let uid; const collections = await db.listCollections().toArray(); const collectionNames = collections.map(collection =&gt; collection.name); if(collectionNames.indexOf(&quot;users&quot;) == -1){ uid = 1; } else{ const newest_user = await db.collection(&quot;users&quot;).find({}).sort({&quot;_id&quot;:-1}).limit(1).toArray(); uid = newest_user[0][&quot;_id&quot;] + 1; } user._id = uid; // add and save user db.collection(&quot;users&quot;).insertOne(user).catch((error)=&gt;{ throw error; }); </code></pre> <p>One concern I have now is that when two users make a request to register at the same time, they will get same maximum user id, and create the same new user id. One way to prevent it is using a locked thread. But, I think Node.js and Next.js doesn't support multi-thread. What are some alternatives I have to solve this problem?</p> <p>In addition, _id will be the field for uid. Will it make a difference since _id can't be duplicated.</p>
[ { "answer_id": 74173637, "author": "Craig Estey", "author_id": 5382650, "author_profile": "https://Stackoverflow.com/users/5382650", "pm_score": 2, "selected": true, "text": "scanf(\"%30s\", studentID);" }, { "answer_id": 74174681, "author": "J. sva", "author_id": 1732207...
2022/10/23
[ "https://Stackoverflow.com/questions/74173402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6707111/" ]
74,173,405
<p>Below you can see my data frame.</p> <pre><code>df&lt;-data.frame( items=c(&quot;1 Food Item 1&quot;, &quot;1.1 Food Item 2&quot;, &quot;01.1.1 Food Item 3&quot;, &quot;01.1.2 Food Item 4&quot;, &quot;01.1.3 Food Item 5&quot;, &quot;2 Food Item 6&quot;, &quot;2.1 Food Item 7&quot;, &quot;02.1.1 Food Item 8&quot;, &quot;10 Food Item 9&quot;, &quot;10.1 Food Item 10&quot;, &quot;10.1.1 Food Item 11&quot;, &quot;10.1.2 Food Item 12&quot;) ) df </code></pre> <p>This <code>df</code> contains items that begin with different numbers with <strong>two</strong>, <strong>three</strong>, and <strong>four</strong> digits. Now I want to filter this <code>df</code>, and the final output should be items only with <strong>four digits</strong>:</p> <pre><code>&quot;01.1.1 Food Item 3&quot;, &quot;01.1.2 Food Item 4&quot;, &quot;01.1.3 Food Item 5&quot;, &quot;02.1.1 Food Item 8&quot;, &quot;10.1.1 Food Item 11&quot;, &quot;10.1.2 Food Item 12&quot; </code></pre> <p>So can anybody help me with how to solve this problem?</p>
[ { "answer_id": 74173637, "author": "Craig Estey", "author_id": 5382650, "author_profile": "https://Stackoverflow.com/users/5382650", "pm_score": 2, "selected": true, "text": "scanf(\"%30s\", studentID);" }, { "answer_id": 74174681, "author": "J. sva", "author_id": 1732207...
2022/10/23
[ "https://Stackoverflow.com/questions/74173405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10924836/" ]
74,173,422
<p>I am doing the following with two dataframes but it generates duplicates and does not get sorted as the first dataframe.</p> <pre><code>import pandas as pd dict1 = { &quot;time&quot;: [&quot;15:09.123&quot;, &quot;15:09.234&quot;, &quot;15:10.123&quot;, &quot;15:11.123&quot;, &quot;15:12.123&quot;, &quot;15:12.987&quot;], &quot;value&quot;: [10, 20, 30, 40, 50, 60] } dict2 = { &quot;time&quot;: [&quot;15:09&quot;, &quot;15:09&quot;, &quot;15:10&quot;], &quot;counts&quot;: [&quot;fg&quot;, &quot;mn&quot;, &quot;gl&quot;], &quot;growth&quot;: [1, 3, 6] } df1 = pd.DataFrame(dict1) df2 = pd.DataFrame(dict2) df1[&quot;time&quot;] = df1[&quot;time&quot;].str[:-4] result = pd.merge(df1, df2, on=&quot;time&quot;, how=&quot;left&quot;) </code></pre> <p>This generates the result of 8 rows! I am removing 3 digits from time column in <code>df1</code> to match the time in <code>df2</code>.</p> <pre><code> time value counts growth 0 15:09 10 fg 1.0 1 15:09 10 mn 3.0 2 15:09 20 fg 1.0 3 15:09 20 mn 3.0 4 15:10 30 gl 6.0 5 15:11 40 NaN NaN 6 15:12 50 NaN NaN 7 15:12 60 NaN NaN </code></pre> <p>There are duplicated columns due to join.</p> <p>Is it possible to join the dataframes based on <code>time</code> column in <code>df1</code> where events are sorted well with more time granularity? Is there a way to partially match the <code>time</code> column values of two dataframes and merge? Ideal result would look like the following</p> <pre><code> time value counts growth 0 15:09.123 10 fg 1.0 1 15:09.234 20 mn 3.0 2 15:10.123 30 gl 6.0 3 15:11.123 40 NaN NaN 4 15:12.123 50 NaN NaN 5 15:12.987 60 NaN NaN </code></pre>
[ { "answer_id": 74173637, "author": "Craig Estey", "author_id": 5382650, "author_profile": "https://Stackoverflow.com/users/5382650", "pm_score": 2, "selected": true, "text": "scanf(\"%30s\", studentID);" }, { "answer_id": 74174681, "author": "J. sva", "author_id": 1732207...
2022/10/23
[ "https://Stackoverflow.com/questions/74173422", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5405358/" ]
74,173,429
<p>is there a way to plot a bar graph in <code>ggplot</code> and group the bars accordingly using a horizontal line with label. It should look something like in the image below but for multiple groups and bars in one single graph only.</p> <p>For context, I'm planning to group three bars for each horizontal label in one graph. For example, the first 3 bars would represent my control, the next three bars would be for treatment 1, the next three would be for treatment 2, and so on.</p> <p>Let me know if you have a template for making such a graph. Thanks!</p> <p><a href="https://i.stack.imgur.com/rXnHI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rXnHI.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74173688, "author": "jrcalabrese", "author_id": 14992857, "author_profile": "https://Stackoverflow.com/users/14992857", "pm_score": 0, "selected": false, "text": "geom_bar()" }, { "answer_id": 74174133, "author": "stefan", "author_id": 12993861, "author...
2022/10/23
[ "https://Stackoverflow.com/questions/74173429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10003652/" ]
74,173,438
<p>My JSON has this information:</p> <pre class="lang-json prettyprint-override"><code>[ { &quot;era_1&quot;:{&quot;technology_cost&quot;:&quot;10000&quot;}, &quot;era_2&quot;:{&quot;technology_cost&quot;:&quot;15000&quot;}, &quot;era_3&quot;:{&quot;technology_cost&quot;:&quot;20000&quot;}, &quot;era_4&quot;:{&quot;technology_cost&quot;:&quot;25000&quot;}, &quot;era_5&quot;:{&quot;technology_cost&quot;:&quot;30000&quot;} } ] </code></pre> <p>I want to do:</p> <pre><code>EraData = JsonConvert.DeserializeObject&lt;List&lt;ClassEra&gt;&gt;(JSON); </code></pre> <p>Being ClassEra</p> <pre><code>public class ClassEra { public string name { get; set; } public string technology_cost { get; set; } } </code></pre> <p>And obviously it doesn't work.</p> <p>I don't understand the type of data that is coming out of the deserializer.</p> <p>By the way I'm using Newtonsoft.</p>
[ { "answer_id": 74173553, "author": "Pradeep Kumar", "author_id": 18704952, "author_profile": "https://Stackoverflow.com/users/18704952", "pm_score": 1, "selected": true, "text": "EraData = JsonConvert.DeserializeObject<List<Dictionary<string, ClassEra>>>(JSON);\n" }, { "answer_i...
2022/10/23
[ "https://Stackoverflow.com/questions/74173438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309644/" ]
74,173,443
<p>I created a long time ago a Discord bot using node discord.js. Since some weeks, it started to crash randomly between ten minutes and some hours after I start the node. In case of the discord.js API changed, I reduced the bot code to the minimal, but it still crashes with the same error (see code and error below).</p> <p>Does someone please have an idea of what my be the problem?</p> <p>I'm using node version 16.13.1 and discord.js 14.6.0, running on a Synology NAS 216+.</p> <p>Bot code:</p> <pre><code>const Discord = require(&quot;discord.js&quot;); const client = new Discord.Client(); var prefix = &quot;!&quot;; require('events').EventEmitter.defaultMaxListeners = 99; client.login(&quot;XXX&quot;); client.on(&quot;ready&quot;, () =&gt; { console.log(&quot;I'm on!&quot;); // this effectively prints in console when node starts }); </code></pre> <p>Error message:</p> <pre><code>/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/actions/MessageCreate.js:11 const existing = channel.messages.cache.get(data.id); TypeError: Cannot read property 'cache' of undefined at MessageCreateAction.handle (/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41) at Object.module.exports [as MESSAGE_CREATE] (/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/websocket/WebSoc ketManag er.js:384:31) at WebSocketShard.onPacket (/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22) at WebSocketShard.onMessage (/volume1/homes/bots/Bot discord/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) at WebSocket.onMessage (/volume1/homes/bots/Bot discord/node_modules/ws/lib/event-target.js:125:16) at WebSocket.emit (events.js:314:20) at Receiver.receiverOnMessage (/volume1/homes/bots/Bot discord/node_modules/ws/lib/websocket.js:797:20) at Receiver.emit (events.js:314:20) at Receiver.dataMessage (/volume1/homes/bots/Bot discord/node_modules/ws/lib/receiver.js:437:14) </code></pre> <p>Thanks a lot! Regards.</p>
[ { "answer_id": 74173553, "author": "Pradeep Kumar", "author_id": 18704952, "author_profile": "https://Stackoverflow.com/users/18704952", "pm_score": 1, "selected": true, "text": "EraData = JsonConvert.DeserializeObject<List<Dictionary<string, ClassEra>>>(JSON);\n" }, { "answer_i...
2022/10/23
[ "https://Stackoverflow.com/questions/74173443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315875/" ]
74,173,445
<p>I input age as 30 but its not printing my if statement. Can i know why ? Thanks</p> <pre><code>#include &lt;unistd.h&gt; #include &lt;sys/stat.h&gt; #include &lt;sys/types.h&gt; #define BUFFSIZE 512 int main() { int a; char *buffer[BUFFSIZE]; write(1,&quot;Please Enter your age: &quot;,23); a=read(0,*buffer,100); if(a&gt;21) write(1,&quot;You are an adult&quot;,16); return 0; } </code></pre>
[ { "answer_id": 74173495, "author": "David Grayson", "author_id": 28128, "author_profile": "https://Stackoverflow.com/users/28128", "pm_score": 0, "selected": false, "text": "read" }, { "answer_id": 74173498, "author": "Chris Dodd", "author_id": 16406, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74173445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316223/" ]
74,173,461
<p>I want to know if a method on a class gets redefined.</p> <p>use case: in version 1 of ruby-clock, defining a method on an object was part of the API. In version 2, doing so will break behavior, and a different API should be used.</p> <p>what I ended up doing: <a href="https://github.com/jjb/ruby-clock/pull/28/files" rel="nofollow noreferrer">https://github.com/jjb/ruby-clock/pull/28/files</a></p> <hr /> <p>The best would be if I could use some sort of metaprogramming to notice when it happens.:</p> <pre class="lang-rb prettyprint-override"><code># this is example code which does not work class MyClass def my_method puts &quot;hello&quot; end # this is not real! it's an example of what i hope is somehow possible def self.method_defined(m, *args, &amp;block) if :my_method == m raise &quot;you should not redefine my_method!&quot; end end end </code></pre> <p>Also acceptable would be if I could check back later and see if it has changed.</p> <pre class="lang-rb prettyprint-override"><code># this is example code which does not work class MyClass def my_method puts &quot;hello&quot; end @@my_method_object_id = get_method_object_id(:my_method) end # later, when app initialization is done, check if the user redefined the method # this is not real! it's an example of what i hope is somehow possible def self.method_defined(m, *args, &amp;block) if MyClass.get_method_object_id(:my_method) != MyClass.my_method_object_id raise &quot;you should not redefine my_method!&quot; end end </code></pre> <p>n.b. that <code>MyClass.method(:my_method)</code> is a real thing in ruby, but it always produces a new object.</p>
[ { "answer_id": 74174201, "author": "Konstantin Strukov", "author_id": 8008340, "author_profile": "https://Stackoverflow.com/users/8008340", "pm_score": 1, "selected": false, "text": "Module" }, { "answer_id": 74175387, "author": "Cary Swoveland", "author_id": 256970, ...
2022/10/23
[ "https://Stackoverflow.com/questions/74173461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/168143/" ]
74,173,462
<p>I would to parse a phone field in a pandas dataframe. My phone field is named <em><strong>Phone</strong></em> and my country code field <em><strong>CountryCode</strong></em>.</p> <p>It works but only when all the phones are filled:</p> <pre><code>df['Test phone'] = df.apply(lambda x:phonenumbers.parse(str(x['Phone']), str(x['CountryCode'])), axis='columns') </code></pre> <p>OK, but how to do it only if the phone, or even the country code, are filled? I tried a lot of <em><strong>if/else</strong></em> syntaxes in the <em><strong>lambda</strong></em> function, without success.</p> <p>Amazing, I also tried doing it in a <em><strong>df.loc</strong></em>, it does not work neither...</p> <p>Please, have you an idea?</p> <p>THX</p>
[ { "answer_id": 74174270, "author": "KarelZe", "author_id": 5755604, "author_profile": "https://Stackoverflow.com/users/5755604", "pm_score": 1, "selected": false, "text": "if" }, { "answer_id": 74181627, "author": "Georgie", "author_id": 2344075, "author_profile": "ht...
2022/10/23
[ "https://Stackoverflow.com/questions/74173462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2344075/" ]
74,173,467
<p>I have 4 points marked in an equirectangular image. [Red dots]</p> <p><a href="https://i.stack.imgur.com/sDS4R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/sDS4R.png" alt="enter image description here" /></a></p> <p>I also have the 4 corresponding points marked in an overhead image [ Red dots ]</p> <p><a href="https://i.stack.imgur.com/ilgmn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ilgmn.png" alt="enter image description here" /></a></p> <p>How do I calculate where on the overhead image the camera was positioned?</p> <p>So far I see there are 4 rays (<code>R1</code>, <code>R2</code>, <code>R3</code>, <code>R4</code>) extending from the unknown camera center <code>C = (Cx, Cy, Cz)</code> through the points in the equirectangular image and ending at the pixel coordinates of the overhead image (<code>P1</code>, <code>P2</code>, <code>P3</code>, <code>P4</code>). So 4 vector equations of the form:</p> <pre><code>[Cx, Cy, Cz] + [Rx, Ry, Rz]*t = [x, y, 0] </code></pre> <p>for each correspondence. So</p> <pre><code>C + R1*t1 = P1 = [x1, y1, 0] C + R2*t2 = P2 = [x2, y2, 0] C + R3*t3 = P3 = [x3, y3, 0] C + R4*t4 = P4 = [x4, y4, 0] </code></pre> <p>So 7 unknowns and 12 equations? This was my attempt but doesn't seem to give a reasonable answer:</p> <pre><code>import numpy as np def equi2sphere(x, y): width = 2000 height = 1000 theta = 2 * np.pi * x / width - np.pi phi = np.pi * y / height return theta, phi HEIGHT = 1000 MAP_HEIGHT = 788 # # HEIGHT = 0 # MAP_HEIGHT = 0 # Point in equirectangular image, bottom left = (0, 0) xs = [1190, 1325, 1178, 1333] ys = [HEIGHT - 730, HEIGHT - 730, HEIGHT - 756, HEIGHT - 760] # import cv2 # img = cv2.imread('equirectangular.jpg') # for x, y in zip(xs, ys): # img = cv2.circle(img, (x, y), 15, (255, 0, 0), -1) # cv2.imwrite(&quot;debug_equirectangular.png&quot;, img) # Corresponding points in overhead map, bottom left = (0, 0) px = [269, 382, 269, 383] py = [778, 778, 736, 737] # import cv2 # img = cv2.imread('map.png') # for x, y in zip(px, py): # img = cv2.circle(img, (x, y), 15, (255, 0, 0), -1) # cv2.imwrite(&quot;debug_map.png&quot;, img) As = [] bs = [] for i in range(4): x, y = xs[i], ys[i] theta, phi = equi2sphere(x, y) # convert to spherical p = 1 sx = p * np.sin(phi) * np.cos(theta) sy = p * np.sin(phi) * np.sin(theta) sz = p * np.cos(phi) print(x, y, '-&gt;', np.degrees(theta), np.degrees(phi), '-&gt;', round(sx, 2), round(sy, 2), round(sz, 2)) block = np.array([ [1, 0, 0, sx], [0, 1, 0, sy], [1, 0, 1, sz], ]) y = np.array([px[i], py[i], 0]) As.append(block) bs.append(y) A = np.vstack(As) b = np.hstack(bs).T solution = np.linalg.lstsq(A, b) Cx, Cy, Cz, t = solution[0] import cv2 img = cv2.imread('map_overhead.png') for i in range(4): x, y = xs[i], ys[i] theta, phi = equi2sphere(x, y) # convert to spherical p = 1 sx = p * np.sin(phi) * np.cos(theta) sy = p * np.sin(phi) * np.sin(theta) sz = p * np.cos(phi) pixel_x = Cx + sx * t pixel_y = Cy + sy * t pixel_z = Cz + sz * t print(pixel_x, pixel_y, pixel_z) img = cv2.circle(img, (int(pixel_x), img.shape[0] - int(pixel_y)), 15, (255,255, 0), -1) img = cv2.circle(img, (int(Cx), img.shape[0] - int(Cy)), 15, (0,255, 0), -1) cv2.imwrite(&quot;solution.png&quot;, img) # print(A.dot(solution[0])) # print(b) </code></pre> <p>Resulting camera position (Green) and projected points (Teal)</p> <p><a href="https://i.stack.imgur.com/l3lVN.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/l3lVN.jpg" alt="enter image description here" /></a></p> <p>EDIT: One bug fixed is that the longitude offset in the equirectangular images in PI/4 which fixes the rotation issue but the scale is still off somehow.</p>
[ { "answer_id": 74174270, "author": "KarelZe", "author_id": 5755604, "author_profile": "https://Stackoverflow.com/users/5755604", "pm_score": 1, "selected": false, "text": "if" }, { "answer_id": 74181627, "author": "Georgie", "author_id": 2344075, "author_profile": "ht...
2022/10/23
[ "https://Stackoverflow.com/questions/74173467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1185242/" ]
74,173,484
<p>I need to update some fields and do some login on <code>task</code> entity. Actually based on my requirement, when the task <code>record status</code> change to <code>complete</code>(user click on <code>Mark as Complete</code>.), my logic must start. For this reason and because of no <code>event</code> like <code>complete</code> in <code>task messages</code>, I check status of the record in <code>update message</code>. I would like to this via <code>CRM Plugin</code>. To achieve this I use <code>PostEntityImages</code> of task record. I check the status of <code>PostEntityImages</code> in the code and then do my logic. This is what happening :</p> <pre><code> if (context.InputParameters.Contains(&quot;Target&quot;) &amp;&amp; context.InputParameters[&quot;Target&quot;] is Entity) { currentTask = (Entity)context.InputParameters[&quot;Target&quot;]; if (currentTask.LogicalName == &quot;task&quot;) { afterUpdateTask = (Entity)context.PostEntityImages[&quot;updatedTask&quot;]; beforeUpdateTask = (Entity)context.PreEntityImages[&quot;updatedTask&quot;]; if (afterUpdateTask.Contains(&quot;statuscode&quot;)) { int statuscode = ((OptionSetValue)afterUpdateTask[&quot;statuscode&quot;]).Value; if (statuscode == 5) { </code></pre> <p>As you see I also get the <code>PreEntityImages</code> as well. After last if, the logic starts and some fields update; the fields of <code>PostEntityImages</code>(afterUpdateTask ). But <code>CRM</code> returns :</p> <pre><code>The object cannot be updated because it is read-only. If you contact support, please provide the technical details. </code></pre> <p>It seems CRM does not talk much off ! I also tried this with <code>PreEntityImages</code>(beforeUpdateTask), but it does not work for me. Because it updates the fields in <code>task entity</code>, but does not change the status of record to <code>complete</code>, however in my scenario I need the <code>modifiedon</code> and <code>statuscode</code> fields of PostEntityImages. Also tried with <code>currentTask</code> that is <code>(Entity)context.InputParameters[&quot;Target&quot;]</code>, but it just change the <code>stauts</code> of record to <code>complete</code> without running my logic.</p> <p>What should I do to update a task record after it change to complete? Is it possible to do this via Plugin?</p>
[ { "answer_id": 74174270, "author": "KarelZe", "author_id": 5755604, "author_profile": "https://Stackoverflow.com/users/5755604", "pm_score": 1, "selected": false, "text": "if" }, { "answer_id": 74181627, "author": "Georgie", "author_id": 2344075, "author_profile": "ht...
2022/10/23
[ "https://Stackoverflow.com/questions/74173484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2857832/" ]
74,173,508
<p>I'm trying to pass the output stream to a function but can't get it right. This sample code shows a couple of the things I've tried</p> <pre><code>// Attempts to pass stream or writer to a function const std = @import(&quot;std&quot;); pub fn main() !void { // #1 try print1(std.io.getStdOut(), &quot;Hello, &quot;); // #2 try print2(std.io.getStdOut().writer(), &quot;world!&quot;); } // error: 'File' is not marked 'pub' pub fn print1(file: std.io.File, str: []const u8) !void { try file.writer().print(&quot;{s}&quot;, .{str}); } // error: expected type 'type', found 'fn(comptime type, comptime type, comptime anytype) type' fn print2(writer: std.io.Writer, str: []const u8) !void { try writer.print(&quot;{s}&quot;, .{str}); } </code></pre> <p>I'm using Zig 0.10.0</p>
[ { "answer_id": 74174270, "author": "KarelZe", "author_id": 5755604, "author_profile": "https://Stackoverflow.com/users/5755604", "pm_score": 1, "selected": false, "text": "if" }, { "answer_id": 74181627, "author": "Georgie", "author_id": 2344075, "author_profile": "ht...
2022/10/23
[ "https://Stackoverflow.com/questions/74173508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10175645/" ]
74,173,525
<p>For a school project a need to make a website. I have a contact form page and to the right I want three images. See picture for how it looks now. The images float under the form and not on the right of it. <a href="https://i.stack.imgur.com/Ntpid.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ntpid.png" alt="enter image description here" /></a> Here is some html and css code:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#contact-img1, #contact-img2, #contact-img3 { width: 20%; height: auto; float: right; } #contactform { width: 70%; height: 500px; float: left; } .shoes { float: right; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;fieldset id="contactform"&gt; &lt;legend&gt;If you have a question you can ask it here:&lt;/legend&gt; &lt;p&gt; &lt;label for="name"&gt;Name:&lt;/label&gt; &lt;/p&gt; &lt;input type="text" name="name"&gt; &lt;p&gt; &lt;label for="email"&gt;Email:&lt;/label&gt; &lt;/p&gt; &lt;input type="text" value="placeholder@gmail.com" name="email"&gt; &lt;p&gt; &lt;label for="message"&gt;Message:&lt;/label&gt; &lt;/p&gt; &lt;input type="text" name="message"&gt; &lt;p&gt; &lt;form action="contact.html"&gt; &lt;/p&gt; &lt;input type="submit" value="send question!" /&gt; &lt;/form&gt; &lt;/fieldset&gt; &lt;section class="shoes"&gt; &lt;aside class="img-inno1"&gt; &lt;img id="contact-img1" src="images/inno-img1.webp" alt="first sport image"&gt; &lt;/aside&gt; &lt;aside class="img-inno2"&gt; &lt;img id="contact-img2" src="images/inno-img2.webp" alt="second sport image"&gt; &lt;/aside&gt; &lt;aside class="img-inno3"&gt; &lt;img id="contact-img3" src="images/inno-img3.webp" alt="third sport image"&gt; &lt;/aside&gt; &lt;/section&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74173581, "author": "Емил Цоков", "author_id": 4264994, "author_profile": "https://Stackoverflow.com/users/4264994", "pm_score": 0, "selected": false, "text": " .shoes {\nfloat:right; \nwidth:20%;\n}\n.shoes aside {\n display: inline-block:\n}\n.shoes img {\nmax-width: 100...
2022/10/23
[ "https://Stackoverflow.com/questions/74173525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20111693/" ]
74,173,541
<p>I tried to implement a multithreading cache in C++ 11. I tried to create threads in the main function and passed the putcache function and getcache function as parameter. And I passed class object c1 to the two functions as parameters. However, I found that the complier gave me a error like this: <code>In template: no matching constructor for initialization of '_Gp' (aka 'tuple&lt;unique_ptr&lt;std::__thread_struct&gt;, void (*)(LRUCache), LRUCache&gt;')</code> Here is my code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;unordered_map&gt; #include &lt;thread&gt; #include &lt;chrono&gt; #include &lt;mutex&gt; using namespace std; class LRUCache { public: class Node { public: int key,val; Node* left,*right; Node(int _key,int _val):key(_key),val(_val),left(NULL),right(NULL) {} }*L,*R; unordered_map&lt;int,Node*&gt; m; int n; mutex mtx; condition_variable cv; void insert(Node* node) { Node* next=L-&gt;right; L-&gt;right=node; node-&gt;right=next; node-&gt;left=L; next-&gt;left=node; } void erase(Node* node) { node-&gt;left-&gt;right=node-&gt;right; node-&gt;right-&gt;left=node-&gt;left; } LRUCache(int capacity) { n=capacity; L=new Node(-1,-1),R=new Node(-1,-1); L-&gt;right=R; R-&gt;left=L; } int get(int key) { if(m.count(key)==0) return -1; mtx.lock(); Node* node=m[key]; erase(node); insert(node); return node-&gt;val; mtx.unlock(); } void put(int key, int value) { mtx.lock(); if(m.count(key)) { m[key]-&gt;val=value; erase(m[key]); insert(m[key]); } else { Node* node=new Node(key,value); if(m.size()==n) { Node* tmp=R-&gt;left; erase(tmp); m.erase(tmp-&gt;key); } insert(node); m[key]=node; } mtx.unlock(); } }; void putcache(LRUCache c) { for(int i=1;i&lt;=10;i++) { c.put(i,i+10); this_thread::sleep_for(std::chrono::seconds(1)); } } void getcache(LRUCache c) { for(int i=1;i&lt;=10;i++) { c.get(i); this_thread::sleep_for(std::chrono::seconds(1)); } } int main() { LRUCache c1(100); std::thread t1(putcache,c1); std::thread t2(getcache,c1); } </code></pre>
[ { "answer_id": 74173581, "author": "Емил Цоков", "author_id": 4264994, "author_profile": "https://Stackoverflow.com/users/4264994", "pm_score": 0, "selected": false, "text": " .shoes {\nfloat:right; \nwidth:20%;\n}\n.shoes aside {\n display: inline-block:\n}\n.shoes img {\nmax-width: 100...
2022/10/23
[ "https://Stackoverflow.com/questions/74173541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20079379/" ]
74,173,568
<p>I am trying to refactor a Class component into a Function component in a react-redux app, but I am a bit stuck. When I try to convert this Component to a function Component, this line of code <strong>this.props.weather.map(this.renderWeather)</strong> no longer executes and it cannot read the <strong>list</strong> portion of code declared within the variables underneath the <strong>renderWeather()</strong> function</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>import React, {Component} from "react"; import { connect, useSelector } from "react-redux"; import Chart from "../containers/Chart"; class WeatherList extends Component { renderWeather(results) { const temp = results.list.map(weather =&gt; (weather.main.temp - 273.15) * 9/5 + 32); const pressure = results.list.map(weather =&gt; weather.main.pressure); const humidity = results.list.map(weather =&gt; weather.main.humidity); return ( &lt;tr key={results.city.id}&gt; &lt;td&gt;{results.city.name}&lt;/td&gt; &lt;td&gt; &lt;Chart color='yellow' data={temp} units='F'/&gt; &lt;/td&gt; &lt;td&gt; &lt;Chart color='green' data={pressure} units='hPa'/&gt; &lt;/td&gt; &lt;td&gt; &lt;Chart color='blue' data={humidity} units='%'/&gt; &lt;/td&gt; &lt;/tr&gt; ) } render() { return ( &lt;table className="table table-hover"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;City&lt;/th&gt; &lt;th&gt;Temperature&lt;/th&gt; &lt;th&gt;Pressure&lt;/th&gt; &lt;th&gt;Humidity&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; { this.props.weather.map(this.renderWeather) } &lt;/tbody&gt; &lt;/table&gt; ) } } function mapStateToProps({ weather }) { return { weather } } export default connect(mapStateToProps)(WeatherList);</code></pre> </div> </div> </p>
[ { "answer_id": 74173581, "author": "Емил Цоков", "author_id": 4264994, "author_profile": "https://Stackoverflow.com/users/4264994", "pm_score": 0, "selected": false, "text": " .shoes {\nfloat:right; \nwidth:20%;\n}\n.shoes aside {\n display: inline-block:\n}\n.shoes img {\nmax-width: 100...
2022/10/23
[ "https://Stackoverflow.com/questions/74173568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316307/" ]
74,173,569
<p>Is there any possibility to create a jar file, not for the entire project, but only for one class file in IntelliJ? In that file, I don't need all libraries and etc. I need only files with a specific class.</p>
[ { "answer_id": 74173581, "author": "Емил Цоков", "author_id": 4264994, "author_profile": "https://Stackoverflow.com/users/4264994", "pm_score": 0, "selected": false, "text": " .shoes {\nfloat:right; \nwidth:20%;\n}\n.shoes aside {\n display: inline-block:\n}\n.shoes img {\nmax-width: 100...
2022/10/23
[ "https://Stackoverflow.com/questions/74173569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15524880/" ]
74,173,628
<p>I want to write a <code>pipeline</code> function which takes an abritrary number of functions and forwards the input of the first to the second and so on up until the last. The output of <code>pipeline</code> is a <code>Callable</code>. The input of that <code>Callable</code> matches the first function given to <code>pipeline</code>. The output matches the last function given to <code>pipeline</code>. I would like to add type annotations to <code>pipeline</code>. This is what I came up with so far:</p> <pre class="lang-py prettyprint-override"><code>from typing import TypeVar from typing_extensions import ParamSpec, Concatenate P = ParamSpec(&quot;P&quot;) Output = TypeVar(&quot;Output&quot;) def pipeline(func: Callable[Concatenate[P], T], *funcs: Callable[..., Output]) -&gt; Callable[Concatenate[P], Output]: ... </code></pre> <p>But this gives a <code>Union</code> of all <code>Output</code> types of <code>*funcs</code>. Example:</p> <pre class="lang-py prettyprint-override"><code>def double(x: int) -&gt; Tuple[int, int]: return x, x*2 def add(x: int, y: int) -&gt; int: return x + y def to_string(x: int) -&gt; str: return str(x) new_func = pipeline(add, double, add, to_string) </code></pre> <p>With the type annotation shown above the type / signature of <code>new_func</code> results in</p> <pre class="lang-py prettyprint-override"><code>new_func: (x: int, y: int) -&gt; (Tuple[int, int] | int | str) </code></pre> <p>It's quite clear that pipeline should have the following signature:</p> <pre class="lang-py prettyprint-override"><code>new_func: (x: int, y: int) -&gt; str </code></pre> <p>Is there a way to achieve this with type annotations?</p>
[ { "answer_id": 74173702, "author": "ruohola", "author_id": 9835872, "author_profile": "https://Stackoverflow.com/users/9835872", "pm_score": 0, "selected": false, "text": "pipeline" }, { "answer_id": 74276290, "author": "Stoney", "author_id": 5585432, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74173628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5585432/" ]
74,173,630
<p>I am displaying multiple charts in a Grid. Every chart fetches different data from my server. When I resize the window the data is fetched again and the chart renders from scratch. I want to avoid the re-fetching.</p> <p>I use <code>highcharts</code> as chart library, <code>useQuery</code> to fetch data (tried with <code>useEffect</code> hook aswell) and a Grid from <code>material UI</code>.</p> <p>Update to my original question:</p> <p>I have wrapped my <code>app.js</code> in a dashboard layout. This layout uses a MUI <code>styled</code> component. I figured when I use a normal <code>div</code> instead, the re-fetching stops. But also the <code>Outlet</code> is not displayed correctly as it's hidden behind the sidebar.</p> <p>Here are my Components: dashboard-layout.js</p> <pre><code>import { useState } from 'react'; import { DashboardNavbar } from './dashboard-navbar'; import { DashboardSidebar } from './dashboard-sidebar'; import { DashboardContent } from './dashboard-content'; import { DrawerContextProvider } from &quot;../../contexts/drawer-context&quot;; export const DashboardLayout = (props) =&gt; { const [isSidebarOpen, setSidebarOpen] = useState(true); return ( &lt;&gt; &lt;DrawerContextProvider&gt; &lt;DashboardContent/&gt; &lt;DashboardNavbar onSidebarOpen={() =&gt; setSidebarOpen(true)} /&gt; &lt;DashboardSidebar onClose={() =&gt; setSidebarOpen(false)} open={isSidebarOpen} /&gt; &lt;/DrawerContextProvider&gt; &lt;/&gt; ); }; </code></pre> <p>DashboardContent.js</p> <pre><code>import { Box, useMediaQuery } from '@mui/material'; import { useTheme, styled } from '@mui/material/styles'; import { Outlet } from 'react-router-dom'; import { useDrawerContext } from &quot;../../contexts/drawer-context&quot;; import DashboardFooter from './dashboard-footer'; export const DashboardContent = () =&gt; { const { isOpened } = useDrawerContext(); const theme = useTheme(); const isLargeScreen = useMediaQuery(theme.breakpoints.up(&quot;md&quot;)); const DashboardContentRoot = styled('div')(({ theme }) =&gt; ({ display: 'flex', flex: '1 1 auto', maxWidth: '100%', paddingTop: 64, paddingLeft: isLargeScreen &amp;&amp; isOpened ? 280 : 0 })); return ( &lt;DashboardContentRoot &gt; &lt;Box sx={{ display: 'flex', flex: '1 1 auto', flexDirection: 'column', width: '100%', px: isLargeScreen ? 1.5 : 1, py: isLargeScreen ? 1.5 : 1 }} &gt; &lt;Outlet/&gt; &lt;DashboardFooter /&gt; &lt;/Box&gt; &lt;/DashboardContentRoot&gt; ); }; </code></pre> <p>The problem with re-rendering and therefore re-fetching persists even when I empty <code>DashboardContentRoot</code> like so:</p> <pre><code> const DashboardContentRoot = styled('div')(({ theme }) =&gt; ({ })); </code></pre> <p>but when I use <code>div</code> instead, no refetching happens:</p> <pre><code>&lt;div&gt; &lt;Box sx={{ display: 'flex', flex: '1 1 auto', flexDirection: 'column', width: '100%', px: isLargeScreen ? 1.5 : 1, py: isLargeScreen ? 1.5 : 1 }} &gt; &lt;Outlet/&gt; &lt;DashboardFooter /&gt; &lt;/Box&gt; &lt;/div&gt; </code></pre> <hr /> <p>Components for my original question:</p> <p>Chart.js</p> <pre><code>import React from &quot;react&quot;; import { useQuery } from &quot;react-query&quot;; import '../HighchartsStyle.css'; async function fetchData(){ const data = await ( await fetch(&quot;myserver/data&quot;) ).json() console.log(&quot;fetching again&quot;) return data } export default function Chart1(){ const {status, data, error, isLoading } = useQuery('data', fetchData); return ( &lt;div&gt; hohoho &lt;/div&gt; ); } </code></pre> <p>Grid.js</p> <pre><code>import React from &quot;react&quot;; import { Chart1 } from &quot;../components/charts/Chart1&quot;; export default function ChartOverviewView() { return ( &lt;div &gt; &lt;Chart1 /&gt; &lt;/div&gt; ); } </code></pre> <p><code>fetching again</code> is displayed every time I resize the window. I want to fetch the data once. Save it temporarily and use the already-fetched data every time I have to rerender the chart again.</p> <p>What is the best practice to do so?</p> <p>Thanks!</p>
[ { "answer_id": 74173702, "author": "ruohola", "author_id": 9835872, "author_profile": "https://Stackoverflow.com/users/9835872", "pm_score": 0, "selected": false, "text": "pipeline" }, { "answer_id": 74276290, "author": "Stoney", "author_id": 5585432, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74173630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3352254/" ]
74,173,658
<p>I'm following a React tutorial on youtube where I'm trying to convert the Project from JavaScript to TypeScript, and I'm having a lot of trouble with the useContext, I would appreciate it if someone were to help me here. If you're wondering which tutorial here it is <a href="https://www.youtube.com/watch?v=jx5hdo50a2M&amp;t=3065s&amp;ab_channel=JavaScriptMastery" rel="nofollow noreferrer" title="Tutorial">Tutorial</a></p> <pre><code> import React, {createContext, useContext, useState } from 'react'; const StateContext = createContext(); export const ContextProvider = ({ children }) =&gt; { const [activeMenu, setActiveMenu] = useState(true); return ( &lt;StateContext.Provider value={{activeMenu, setActiveMenu}}&gt; {children} &lt;/StateContext.Provider&gt; ) } export const useStateContext = () =&gt; useContext(StateContext) </code></pre>
[ { "answer_id": 74173702, "author": "ruohola", "author_id": 9835872, "author_profile": "https://Stackoverflow.com/users/9835872", "pm_score": 0, "selected": false, "text": "pipeline" }, { "answer_id": 74276290, "author": "Stoney", "author_id": 5585432, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74173658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19241748/" ]
74,173,667
<p>An examples of what im trying to do:</p> <pre><code>split('2.1 * -5 + 3 ^ 2 + 1 + -4.45') </code></pre> <p>should output</p> <pre><code>[2.1,'*',-5.0,'+',3.0,'^',2.0,'+',1.0,'+',-4.45] </code></pre> <p>my current code:</p> <pre><code>ops = ('+','-','*','/','^','(') def split(txt): final = [] temp = [] inp = &quot;&quot;.join(txt.split()) for x in inp: if x.isdigit(): temp.append(int(x)) elif x == '.': temp.append(x) elif x in ops: if x == '-': if len(temp) == 0: if isinstance(final[-1],float): final.append(float(&quot;&quot;.join(temp))) final.append(x) temp = [] else: temp.append(x) else: final.append(float(&quot;&quot;.join(temp))) final.append(x) temp = [] else: final.append(&quot;&quot;.join(temp)) final.append(x) temp = [] final.append(float(&quot;&quot;.join(temp))) print(final) </code></pre> <p>error, im not sure what im doing wrong here, and im not even sure if the code ive written is able to do what i want</p> <pre><code>Traceback (most recent call last): File &quot;C:\Users\Sahil Prusti\Desktop\cmpsc132\HW 3\hwtest.py&quot;, line 32, in &lt;module&gt; print(split('2* ( -5.2 + 3 ) ^2+ ( 1 +4 )')) File &quot;C:\Users\Sahil Prusti\Desktop\cmpsc132\HW 3\hwtest.py&quot;, line 26, in split final.append(&quot;&quot;.join(temp)) TypeError: sequence item 0: expected str instance, int found </code></pre>
[ { "answer_id": 74173702, "author": "ruohola", "author_id": 9835872, "author_profile": "https://Stackoverflow.com/users/9835872", "pm_score": 0, "selected": false, "text": "pipeline" }, { "answer_id": 74276290, "author": "Stoney", "author_id": 5585432, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74173667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15411399/" ]
74,173,686
<p>Shortly, when I try to use useState with useContext in one of my components, all pages just disappear. UseState in some reason block my Routers and I have no idea why... Can you tell me where is my mistake?</p> <p>Some code below: Index.js</p> <pre><code>export default function App() { const [value, setValue] = useState(false) -----&gt; here I set the state return ( &lt;BrowserRouter&gt; &lt;UserContext.Provider value={{ value, setValue }}&gt; &lt;Routes&gt; &lt;Route path='/' element={&lt;Layout /&gt;}&gt; &lt;Route index element={&lt;Home /&gt;} /&gt; &lt;Route path='Home' element={&lt;Home /&gt;} /&gt; &lt;Route path='Menu' element={&lt;Menu /&gt;} /&gt; &lt;Route path='Story' element={&lt;Story /&gt;} /&gt; &lt;Route path='Coffee' element={&lt;Coffee /&gt;} /&gt; &lt;Route path='Cart' element={&lt;Cart /&gt;} /&gt; &lt;/Route&gt; &lt;/Routes&gt; &lt;/UserContext.Provider&gt; &lt;/BrowserRouter&gt; ) } // ReactDOM.render(&lt;App /&gt;, document.getElementById(&quot;root&quot;)) const root = ReactDOM.createRoot(document.getElementById(&quot;root&quot;)) root.render(&lt;App /&gt;) </code></pre> <p>Buy.js component</p> <pre><code>import { useState } from &quot;react&quot; import { useContext } from &quot;react&quot; import { UserContext } from &quot;../../UserContext&quot; const Buy = () =&gt; { const [buttonText, setButtonText] = useState(&quot;Add to cart&quot;) const [isActive, setIsActive] = useState(false) // const [value, setValue] = useContext(UserContext) --&gt; after I declare state everything disappears const addToCart = () =&gt; { setIsActive((current) =&gt; !current) // setValue(true) if (isActive) { setButtonText(&quot;Add to cart&quot;) } } return ( &lt;div&gt; &lt;button class='buy' style={{ fontSize: isActive ? &quot;0.8rem&quot; : &quot;1rem&quot;, color: isActive ? &quot;lightgray&quot; : &quot;white&quot;, }} onClick={() =&gt; { addToCart() }} &gt; {buttonText} &lt;/button&gt; &lt;/div&gt; ) } export default Buy </code></pre> <p>UserContext.js</p> <pre><code>import { createContext } from &quot;react&quot; export const UserContext = createContext(null) </code></pre> <p>Actually, I need this Context only for routes &quot;Coffee&quot; and &quot;Cart&quot;, but if I wrap only this 2 routes will be the same problem and all is disappear. Should I maybe use Context in my Layout.jsx instead of Index.js? Thank you.</p> <pre><code>const Layout = () =&gt; { return ( &lt;&gt; &lt;Navbar /&gt; &lt;Outlet /&gt; &lt;Footer/&gt; &lt;/&gt; ); }; export default Layout; </code></pre> <p>The errors in console: <a href="https://i.stack.imgur.com/Kf7sH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kf7sH.png" alt="errors in console" /></a></p>
[ { "answer_id": 74173831, "author": "Arkellys", "author_id": 9718056, "author_profile": "https://Stackoverflow.com/users/9718056", "pm_score": 3, "selected": true, "text": "const { value, setValue } = useContext(UserContext);\n" }, { "answer_id": 74173912, "author": "Chùnky", ...
2022/10/23
[ "https://Stackoverflow.com/questions/74173686", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9225119/" ]
74,173,699
<p>I have a list <code>[1, 2, 3, 4, ..., n]</code>. In a one-liner list comprehension, how can I print the progression <code>[1]</code>, <code>[1, 2]</code>, <code>[1, 2, 3]</code>, <code>[1, 2, 3, 4]</code>, ..., <code>[1, 2, 3, 4, ..., n-1]</code>, where <code>n</code> represents an arbitrary natural number?</p>
[ { "answer_id": 74173726, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 0, "selected": false, "text": "n = 10\nres = [list(range(1,i)) for i in range(2,n+1)]\nprint(res)\n" }, { "answer_id": 74173778, "autho...
2022/10/23
[ "https://Stackoverflow.com/questions/74173699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18027603/" ]
74,173,735
<p>So I have this table:</p> <pre><code>&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style=&quot;width: 40%; text-align: center; vertical-align: center;&quot;&gt;Nr.&lt;br&gt; crt.&lt;/th&gt; &lt;th style=&quot;font-weight: bold; width: 210%; height: 25; text-align: center; vertical-align: center;&quot;&gt;Asistent&lt;/th&gt; &lt;th style=&quot;font-weight: bold; width: 210%; height: 25; text-align: center; vertical-align: center;&quot;&gt;Ambulantier&lt;/th&gt; &lt;th style=&quot;text-align: center; vertical-align: center;&quot;&gt;Ambulanta&lt;/th&gt; @foreach($dates as $date) @if($date['day_name'] == 'S' || $date['day_name'] == 'D') &lt;th style=&quot;width: 40%; text-align: center; vertical-align: center; font-weight: bold; color: red;&quot;&gt;{{$date['day']}}&lt;br&gt; {{$date['day_name']}}&lt;/th&gt; @else &lt;th style=&quot;width: 40%; text-align: center; vertical-align: center; font-weight: bold;&quot;&gt;{{$date['day']}}&lt;br&gt; {{$date['day_name']}}&lt;/th&gt; @endif @endforeach &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; @foreach($interventions as $intervention) &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;{{$intervention-&gt;employee_one-&gt;name}}&lt;/td&gt; &lt;td&gt;{{$intervention-&gt;employee_two-&gt;name}}&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; @endforeach &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>And this is what is generating: <a href="https://i.stack.imgur.com/4Hsun.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Hsun.png" alt="enter image description here" /></a></p> <p>As you can see, some numbers in the header have the red color. How can I color the WHOLE column with red if the respective <code>&lt;th&gt;</code> is also red?</p> <p>I was thinking to use js, and it would look something like this (just an idea, not the actual code lol):</p> <pre><code>if(header(current_td).hasProperty('color: red')) { apply(color.red); } </code></pre> <p>How can I do this?</p>
[ { "answer_id": 74173726, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 0, "selected": false, "text": "n = 10\nres = [list(range(1,i)) for i in range(2,n+1)]\nprint(res)\n" }, { "answer_id": 74173778, "autho...
2022/10/23
[ "https://Stackoverflow.com/questions/74173735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12975819/" ]
74,173,749
<p>How do I display the selected item from my <code>form2</code> groupbox radiobutton (3 radiobuttons and i can only display one) inside my <code>Form1</code> texbox.</p> <p>This is my problem as I only know the code to display 1. if statments didn't work.</p> <p><strong>Form1:</strong></p> <pre><code>public void button5_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(); textBox1.Text = fr2.receivet(textBox1.Text, fr2.radioButton1); } </code></pre> <p><strong>Form2:</strong></p> <pre><code>internal string receivet(string textBox1, RadioButton radio) { return textBox1 = radio.Text; } </code></pre>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19072364/" ]
74,173,781
<p>I am new to Java Programming and was trying the string examples, found that the below code, though prints the output also prints the exception. Please let know why is it throwing an ArrayIndexOutOfBoundsException. The length of commaSeparatedString is 37. How to limit it to the stringArrayLength than the commaSeparatedString length ?</p> <pre><code>package stringMethods; public class stringMethods { public static void main(String args[]) { String text = &quot;Hello&quot;; //System.out.println(text.charAt(2)); //System.out.println(text.equalsIgnoreCase(&quot;hello&quot;)); //System.out.println(text.contains(&quot;lo&quot;)); String commaSeparatedString = &quot;This, is, a, comma, separated, string&quot;; String[] stringArray = commaSeparatedString.split(&quot;,&quot;); for(int i=0; i &lt; commaSeparatedString.length(); i++){ System.out.println(stringArray[i]); } } } </code></pre> <p>Output :</p> <pre><code> D:\Android\Android_Books\ud851-Sunshine-student\lesson3\app\src\main\java&gt; java stringMe thods.stringMethods This is a comma separated string Exception in thread &quot;main&quot; java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 at stringMethods.stringMethods.main(stringMethods.java:12) PS D:\Android\Android_Books\ud851-Sunshine-student\lesson3\app\src\main\java&gt; </code></pre>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/713179/" ]
74,173,786
<p>I have a hash in ruby like below:</p> <pre class="lang-rb prettyprint-override"><code>{&quot;metric&quot;=&gt;&quot;Mean F-Score&quot;, &quot;columns&quot;=&gt; [{&quot;name&quot;=&gt;&quot;Id&quot;, &quot;type&quot;=&gt;&quot;String&quot;}, {&quot;name&quot;=&gt;&quot;Expected&quot;, &quot;type&quot;=&gt;&quot;String&quot;}], &quot;files&quot;=&gt; {&quot;expected&quot;=&gt;&quot;actual_output.csv&quot;}, &quot;submission_filename&quot;=&gt;&quot;/a/aa/submission.csv&quot;} </code></pre> <p>The json for this hash is</p> <pre class="lang-rb prettyprint-override"><code>irb(main):101:0&gt; json_string = JSON.generate(a) =&gt; &quot;{\&quot;metric\&quot;:\&quot;Mean F-Score\&quot;,\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;Id\&quot;,\&quot;type\&quot;:\&quot;String\&quot;},{\&quot;name\&quot;:\&quot;Expected\&quot;,\&quot;type\&quot;:\&quot;String\&quot;}],\&quot;files\&quot;:{\&quot;expected\&quot;:\&quot;actual_output.csv\&quot;},\&quot;submission_filename\&quot;:\&quot;/a/aa/submission.csv\&quot;}&quot; </code></pre> <p>I want to generate a bash command which can generate a json file using this json string:</p> <p>I tried</p> <pre class="lang-rb prettyprint-override"><code>irb(main):104:0&gt; &quot;echo \&quot;#{json_string}\&quot; &gt; data.json&quot; =&gt; &quot;echo \&quot;{\&quot;metric\&quot;:\&quot;Mean F-Score\&quot;,\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;Id\&quot;,\&quot;type\&quot;:\&quot;String\&quot;},{\&quot;name\&quot;:\&quot;Expected\&quot;,\&quot;type\&quot;:\&quot;String\&quot;}],\&quot;files\&quot;:{\&quot;expected\&quot;:\&quot;actual_output.csv\&quot;},\&quot;submission_filename\&quot;:\&quot;/a/aa/submission.csv\&quot;}\&quot; &gt; data.json&quot; </code></pre> <p>But on running this command on bash it is generating wrong json file.</p> <p>I am trying to learn ruby and want to generate command (to run on different servers) like this, but was unable to escape the backslash:</p> <pre class="lang-bash prettyprint-override"><code>echo &quot;{\&quot;metric\&quot;:\&quot;Mean F-Score\&quot;,\&quot;columns\&quot;:[{\&quot;name\&quot;:\&quot;Id\&quot;,\&quot;type\&quot;:\&quot;String\&quot;},{\&quot;name\&quot;:\&quot;Expected\&quot;,\&quot;type\&quot;:\&quot;String\&quot;}],\&quot;files\&quot;:{\&quot;expected\&quot;:\&quot;actual_output.csv\&quot;},\&quot;submission_filename\&quot;:\&quot;/a/aa/submission.csv\&quot;}&quot; &gt; data.json </code></pre>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13862912/" ]
74,173,822
<p>I have a Kafka Producer which is producing messages and couple of consumers(group) who are trying to consume them. I created a topic which has 3 partitions and started 2 consumers with <code>--group</code> parameter. The issue I am facing is that all the messages are being routed to a single consumer. Following are the commands which I ran to create the topic, start the producer and consumer.</p> <p>To create the kafka topic</p> <p><code>kafka-topics.sh --bootstrap-server localhost:9092 --create --topic logs --partitions 3</code></p> <p>When the I describe the topic this is what I get</p> <pre><code>Topic: logs TopicId: BtXbA3igQPmx5qsURAhq7Q PartitionCount: 3 ReplicationFactor: 1 Configs: Topic: logs Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: logs Partition: 1 Leader: 0 Replicas: 0 Isr: 0 Topic: logs Partition: 2 Leader: 0 Replicas: 0 Isr: 0 </code></pre> <p>Started the producer using the below command</p> <p><code>kafka-console-producer.sh --bootstrap-server localhost:9092 --topic logs</code></p> <p>and the both the consumers using this</p> <p><code>kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic logs --group my_group</code></p> <p>When I try to describe the group I am getting the following error.</p> <pre><code>kafka-consumer-groups.sh --bootstrap-server locahost:9092 --describe --group my-group [2022-10-23 14:21:07,711] WARN Couldn't resolve server locahost:9092 from bootstrap.servers as DNS resolution failed for locahost (org.apache.kafka.clients.ClientUtils) Exception in thread &quot;main&quot; org.apache.kafka.common.KafkaException: Failed to create new KafkaAdminClient at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:553) at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:485) at org.apache.kafka.clients.admin.Admin.create(Admin.java:134) at kafka.admin.ConsumerGroupCommand$ConsumerGroupService.createAdminClient(ConsumerGroupCommand.scala:696) at kafka.admin.ConsumerGroupCommand$ConsumerGroupService.&lt;init&gt;(ConsumerGroupCommand.scala:176) at kafka.admin.ConsumerGroupCommand$.run(ConsumerGroupCommand.scala:67) at kafka.admin.ConsumerGroupCommand$.main(ConsumerGroupCommand.scala:59) at kafka.admin.ConsumerGroupCommand.main(ConsumerGroupCommand.scala) Caused by: org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootstrap.servers at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:89) at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:48) at org.apache.kafka.clients.admin.KafkaAdminClient.createInternal(KafkaAdminClient.java:505) </code></pre> <p>I am using Kafka version 3.3.1 and running on Mac OS. This is a fresh installation of Kafka and I have not made any changes in the config dirs. Any idea what is going wrong?</p>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2463341/" ]
74,173,840
<p>Please check the gif below.</p> <p><a href="https://i.stack.imgur.com/fZaVV.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fZaVV.gif" alt="enter image description here" /></a></p> <p>I changed the language from English to French. It doesn't update realtime.</p> <p>But when I close the app and open it, it shows French (Meaning it was saved in the preference)</p> <p>I want it to change realtime as I update it.</p> <p><strong>SharedPrefence.dart</strong></p> <pre><code>static String selectedLanguageKey = &quot;language&quot;; static SharedPreferences? _prefs; static Future&lt;SharedPreferences?&gt; init() async { _prefs = await SharedPreferences.getInstance(); return _prefs; } static String? getSelectedLanguage() { return _prefs?.getString(selectedLanguageKey); } </code></pre> <p><strong>Home.dart</strong></p> <pre><code>class _HomeState extends State&lt;Home&gt; { String? _selectedLanguage; void getSelectedLanguage() { setState(() { _selectedLanguage = LocalPreference.getSelectedLanguage(); }); } @override void initState() { super.initState(); getSelectedLanguage(); } @override Widget build(BuildContext context) { ......... //there is a widget here that when tapped shows a modalbottomsheet where user selects a language onTap: () { showModalBottomSheet() } //now here I display the current selected language, but it doesn't update real time. Only when I close and open app Text( _selectedLanguage?? Strings.hindi, } } </code></pre>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9124515/" ]
74,173,847
<p>I have a hero image and I want the text in it to be like this: <a href="https://i.stack.imgur.com/gTbvR.jpg" rel="nofollow noreferrer">image</a></p> <p>but all I can do is put the text in center (while it's shifted to center): <a href="https://i.stack.imgur.com/QejwQ.jpg" rel="nofollow noreferrer">like this</a>, or put in the right side (shifted to the right).</p> <p>how do I combine? Hope I'm understood.</p>
[ { "answer_id": 74173962, "author": "MrMustafaDev22", "author_id": 19416044, "author_profile": "https://Stackoverflow.com/users/19416044", "pm_score": 2, "selected": true, "text": "public void button5_Click(object sender, EventArgs e)\n{ \n Form2 fr2 = new Form2();\n string radio...
2022/10/23
[ "https://Stackoverflow.com/questions/74173847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17207776/" ]
74,173,860
<p>What I am trying to do is to get the same column result twice with a single query.</p> <pre><code>SELECT appellation FROM persona WHERE character_id IN (853,12,853) ORDER BY FIELD(character_id,853,12,853) </code></pre> <p>This returns the result:</p> <pre><code>character_id | appellation --------------------------- 853 | John Cena 12 | Chris Brown </code></pre> <p>But what I am looking for to return is:</p> <pre><code>character_id | appellation --------------------------- 853 | John Cena 12 | Chris Brown 853 | John Cena </code></pre> <p>Is there a way in MySQL to get that result?</p>
[ { "answer_id": 74173958, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 0, "selected": false, "text": "UNION" }, { "answer_id": 74174000, "author": "ysth", "author_id": 17389, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74173860", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7707749/" ]
74,173,861
<p>I'm using react router dom v6. If I write routes like this:</p> <pre><code> &lt;Routes&gt; &lt;Route path='/posts' element={&lt;Posts/&gt;}/&gt; &lt;Route path='/posts/:id' element={&lt;PostDetails/&gt;}/&gt; &lt;Route path='/about' element={&lt;About/&gt;}/&gt; &lt;Route path='/' element={&lt;Main/&gt;}/&gt; &lt;Route path='*' element={&lt;NotFound/&gt;}/&gt; &lt;/Routes&gt; </code></pre> <p>it's okay, useParams returning { id: number } in the PostDetails component.</p> <p>However If I write routes like the following:</p> <pre><code> &lt;Routes&gt; {routes.map(({path, component}) =&gt; &lt;Route path={path} element={component()}/&gt; )} &lt;/Routes&gt; </code></pre> <p>useParams returns empty object. Why this happening?</p> <p>PS: <code>routes</code> is an array of objects containing path &amp; component values. The actual <code>routes</code> value is:</p> <pre><code>export const routes = [ { path: '/', component: Main, }, { path: '/about', component: About, }, { path: '/posts', component: Posts, }, { path: '/posts/:id', component: PostDetails, }, ] </code></pre>
[ { "answer_id": 74173913, "author": "dogukyilmaz", "author_id": 11729812, "author_profile": "https://Stackoverflow.com/users/11729812", "pm_score": 1, "selected": false, "text": "<Route key={path} path={path} element={<component />}/>\n" }, { "answer_id": 74174027, "author": "...
2022/10/23
[ "https://Stackoverflow.com/questions/74173861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10387066/" ]
74,173,918
<p>Hey all I am trying to add to a list of <code>map&lt;String, String&gt;</code> using the code below:</p> <pre><code>@NonNull public static List&lt;Map&lt;String, String&gt;&gt; mysqlSelect(@NonNull String select, String where) { Map&lt;String, String&gt; info = new HashMap&lt;String,String&gt;(); List&lt;Map&lt;String, String&gt;&gt; list = new ArrayList&lt;&gt;(); int selectCnt = select.replaceAll(&quot;[^,]&quot;,&quot;&quot;).length(); final boolean[] b = {true}; new Thread(new Runnable() { @Override public void run(){ try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD)) { String sql = &quot;SELECT fb_firstname, fb_lastname, fb_id FROM fbuser&quot;; PreparedStatement statement = connection.prepareStatement(sql); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { info.put(&quot;name&quot;, resultSet.getString(&quot;fb_firstname&quot;)); info.put(&quot;address&quot;, resultSet.getString(&quot;fb_lastname&quot;)); info.put(&quot;phone_number&quot;, resultSet.getString(&quot;fb_id&quot;)); list.add(info); } b[0] = false; } catch (Exception e) { Log.e(&quot;InfoAsyncTask&quot;, &quot;Error reading school information&quot;, e); b[0] = false; } } }).start(); while (b[0]) { } return list; //result.get(&quot;name&quot;) } </code></pre> <p>As it loops in the <code>while () {..</code> part it populates the list with the needed 3 string values. However, as it does loop over and over again it seems to populate all the previous values to what was last read instead of having new data each time?</p> <p>Example:</p> <p>1st loop:</p> <pre><code>name: bob barker address: something phone-number = 4235421212 </code></pre> <p>2nd loop:</p> <pre><code>name: steve jobs address: something again phone-number = 8546521111 </code></pre> <p>at this point the 1st loop data turns into</p> <p>1st loop:</p> <pre><code>name: steve jobs address: something again phone-number = 8546521111 </code></pre> <p>2nd loop:</p> <pre><code>name: steve jobs address: something again phone-number = 8546521111 </code></pre> <p>So, what am I missing here?</p> <p><strong>UPDATE 1</strong></p> <p>Originally I have the following:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new InfoAsyncTask().execute(); } @SuppressLint(&quot;StaticFieldLeak&quot;) public class InfoAsyncTask extends AsyncTask&lt;Void, Void, Map&lt;String, String&gt;&gt; { @Override protected Map&lt;String, String&gt; doInBackground(Void... voids) { Map&lt;String, String&gt; info = new HashMap&lt;&gt;(); try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD)) { String sql = &quot;SELECT fb_firstname, fb_lastname, fb_id FROM fbuser LIMIT 1&quot;; PreparedStatement statement = connection.prepareStatement(sql); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { info.put(&quot;name&quot;, resultSet.getString(&quot;fb_firstname&quot;)); info.put(&quot;address&quot;, resultSet.getString(&quot;fb_lastname&quot;)); info.put(&quot;phone_number&quot;, resultSet.getString(&quot;fb_id&quot;)); } } catch (Exception e) { Log.e(&quot;InfoAsyncTask&quot;, &quot;Error reading school information&quot;, e); } return info; } @Override protected void onPostExecute(Map&lt;String, String&gt; result) { if (!result.isEmpty()) { TextView textViewName = findViewById(R.id.textViewName); TextView textViewAddress = findViewById(R.id.textViewAddress); TextView textViewPhoneNumber = findViewById(R.id.textViewPhone); textViewName.setText(result.get(&quot;name&quot;)); textViewAddress.setText(result.get(&quot;address&quot;)); textViewPhoneNumber.setText(result.get(&quot;phone_number&quot;)); } } } </code></pre> <p>But I wanted to put it into its own class file and call it from the onCreate.</p>
[ { "answer_id": 74173913, "author": "dogukyilmaz", "author_id": 11729812, "author_profile": "https://Stackoverflow.com/users/11729812", "pm_score": 1, "selected": false, "text": "<Route key={path} path={path} element={<component />}/>\n" }, { "answer_id": 74174027, "author": "...
2022/10/23
[ "https://Stackoverflow.com/questions/74173918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/277480/" ]
74,173,970
<p>I am trying to signup the user but getting this error</p> <p><strong><code>type 'TextEditingController' is not a subtype of type 'String'</code></strong></p> <p>Here is my code:</p> <pre><code>import 'package:get/get.dart'; import 'package:get/get_core/src/get_main.dart'; import 'package:get/get_navigation/get_navigation.dart'; import 'package:shoppingmart/common_widget/app_logo_widget.dart'; import 'package:shoppingmart/common_widget/bg_widget.dart'; import 'package:shoppingmart/common_widget/custom_textfield.dart'; import 'package:shoppingmart/common_widget/our_button.dart'; import 'package:shoppingmart/const/consts.dart'; import 'package:shoppingmart/const/List.dart'; import 'package:shoppingmart/controller/auth_controller.dart'; import 'package:shoppingmart/screens/auth_screen/login_screen.dart'; import 'package:shoppingmart/screens/home/home.dart'; import 'package:status_alert/status_alert.dart'; class SignUp extends StatefulWidget { const SignUp({super.key}); @override State&lt;SignUp&gt; createState() =&gt; _SignUpState(); } class _SignUpState extends State&lt;SignUp&gt; { bool isCheck = false; var controller = Get.put(AuthController()); //text controllers TextEditingController nameController = TextEditingController(); TextEditingController emailController = TextEditingController(); TextEditingController passwordController = TextEditingController(); TextEditingController confirmPasswordController = TextEditingController(); @override Widget build(BuildContext context) { return bgWidget( child: Scaffold( resizeToAvoidBottomInset: false, body: Center( child: Column( children: [ (context.screenHeight * 0.1).heightBox, applogoWidget(), 10.heightBox, &quot;Signup to $appname&quot;.text.white.fontFamily(bold).make(), 20.heightBox, Column( children: [ CustomTextField( obsecuretext: false, title: name, hint: nameHint, controller: nameController), CustomTextField( obsecuretext: false, title: email, hint: emailHint, controller: emailController), CustomTextField( obsecuretext: true, title: password, hint: passwordHint, controller: passwordController), CustomTextField( obsecuretext: true, title: confirmPassword, hint: passwordHint, controller: confirmPasswordController), Align( alignment: Alignment.centerRight, child: TextButton( onPressed: () {}, child: forgetPass.text.size(15).make())), 5.heightBox, Row( children: [ Checkbox( activeColor: redColor, checkColor: whiteColor, value: isCheck, onChanged: (newValue) { setState(() { isCheck = newValue!; }); }, ), 5.widthBox, Expanded( child: RichText( text: const TextSpan(children: [ TextSpan( text: &quot;I agree to the &quot;, style: TextStyle( color: fontGrey, fontFamily: regular)), TextSpan( text: termsandCondition, style: TextStyle( color: redColor, fontFamily: regular)), TextSpan( text: &quot; &amp; &quot;, style: TextStyle( color: fontGrey, fontFamily: regular)), TextSpan( text: privacyPolicy, style: TextStyle( color: redColor, fontFamily: regular)), ])), ), ], ), ourButton( title: signup, color: redColor, textColor: whiteColor, onPress: () async { if (passwordController.text == confirmPasswordController.text) { if (isCheck != false) { try { await controller .signupMethod( context: context, email: emailController, password: passwordController, ) .then((value) { return controller .storeUserData( name: nameController, email: emailController, password: passwordController) .then((value) { VxToast.show(context, msg: 'Account Created Sucessfully'); Get.offAll(LoginScreen()); }); }); } catch (e) { VxToast.show(context, msg: e.toString()); FirebaseAuth.instance.signOut(); } } } else { VxToast.show(context, msg: 'Confirm password should be same'); } }).box.width(context.screenWidth - 50).make(), 5.heightBox, RichText( text: const TextSpan(children: [ TextSpan( text: alreadyhaveanAccount, style: TextStyle(color: fontGrey)), TextSpan( text: login, style: TextStyle(color: redColor, fontFamily: bold)), ])).onTap(() { Get.back(); }) ], ) .box .white .rounded .padding(const EdgeInsets.all(16)) .width(context.screenWidth - 60) .shadowSm .make(), ], ), ))); } } </code></pre> <p><strong>Error Log</strong></p> <pre><code>I/flutter ( 5199): type 'TextEditingController' is not a subtype of type 'String' D/FirebaseAuth( 5199): Notifying id token listeners about a sign-out event. D/FirebaseAuth( 5199): Notifying auth state listeners about a sign-out event. I/flutter ( 5199): Color(0xdd000000) </code></pre> <p>Appreciate your answer</p>
[ { "answer_id": 74173996, "author": "Mohammed Hamdan", "author_id": 16213673, "author_profile": "https://Stackoverflow.com/users/16213673", "pm_score": 3, "selected": true, "text": ".text" }, { "answer_id": 74174227, "author": "rasityilmaz", "author_id": 15812214, "aut...
2022/10/23
[ "https://Stackoverflow.com/questions/74173970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316542/" ]
74,173,980
<p>I have an issue of ' type 'Future' is not a subtype of type 'Widget' ' and I read a lot of solutions but I couldn't fix and don't understand what I have to do make it work</p> <p>I'd like to load and view pdf from firebase storage with pdf_viewer plugin</p> <p>here's my code</p> <blockquote> <p>Main.dart</p> </blockquote> <pre><code>void main() { WidgetsFlutterBinding.ensureInitialized(); runApp( MultiProvider( providers: [ ChangeNotifierProvider( create: (context) =&gt; DrawingProvider(), ) ], child: MyApp() ) ); } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override State&lt;MyApp&gt; createState() =&gt; _MyAppState(); } class _MyAppState extends State&lt;MyApp&gt; { final Future&lt;FirebaseApp&gt; _initialization = Firebase.initializeApp(); @override Widget build(BuildContext context) { return FutureBuilder&lt;dynamic&gt;( future: _initialization, builder: (context, snapshot) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(primaryColor: Colors.white), // Error causing widget home: WorkbookPage()); }, ); } } class WorkbookPage extends StatefulWidget { const WorkbookPage({Key? key}) : super(key: key); @override State&lt;WorkbookPage&gt; createState() =&gt; _WorkbookPageState(); } class _WorkbookPageState extends State&lt;WorkbookPage&gt; { GlobalKey _viewKey = GlobalKey(); bool isOverlayVisible = false; OverlayEntry? entry; @override Widget build(BuildContext context) { var p = Provider.of&lt;DrawingProvider&gt;(context); // slider Overlay 숨기기 void hideOverlay() { entry?.remove(); entry = null; isOverlayVisible = false; } return GestureDetector( child: Scaffold( appBar: AppBar(title: Text('Workbook Test')), body: GestureDetector( onTap: () { hideOverlay(); }, child: Column( children: [ buildPenFunctionWidget(p, hideOverlay, context), Expanded( child: Stack( children: [ buildPDFViewer(), GestureDetector( child: Listener( behavior: HitTestBehavior.opaque, onPointerHover: (s) { if (s.buttons == kPrimaryStylusButton) { // print(&quot;Hovering stylus and button is pressed!&quot;); } }, onPointerDown: (s) { // Stylus가 화면에 닿을 때 if (s.kind == PointerDeviceKind.stylus) { p.penMode ? p.penDrawStart(s.localPosition) : null; p.highlighterMode ? p.highlighterDrawStart(s.localPosition) : null; p.eraseMode ? p.erase(s.localPosition) : null; // Stylus 버튼이 눌린 상태에서 스크린에 닿을 때 } else if (s.buttons == kPrimaryStylusButton) { p.changeEraseModeButtonClicked = true; } }, onPointerMove: (s) { if (s.kind == PointerDeviceKind.stylus) { p.penMode ? p.penDrawing(s.localPosition) : null; p.highlighterMode ? p.highlighterDrawing(s.localPosition) : null; p.eraseMode ? p.erase(s.localPosition) : null; } else if (s.buttons == kPrimaryStylusButton) { p.changeEraseModeButtonClicked = true; } }, ), ), Positioned.fill( child: CustomPaint( painter: DrawingPainter(p.lines), ), ), ], ), ), ], ), )), ); } /// Pen, eraser , highlighter Container buildPenFunctionWidget(DrawingProvider p, void hideOverlay(), BuildContext context) { return Container( width: double.infinity, height: 50, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ penWidget(p: p), highlighterWidget(p: p), erasePenWidget(p: p), /// Overlay Slider (Pen Size 조절) Container( key: _viewKey, width: 60, child: FittedBox( fit: BoxFit.fitWidth, child: GestureDetector( behavior: HitTestBehavior.deferToChild, child: const Icon( Icons.horizontal_rule_rounded, color: Colors.black54, ), onTap: () { if (isOverlayVisible) { hideOverlay(); } isOverlayVisible = true; OverlayState? overlayState = Overlay.of(context); final renderBox = _viewKey.currentContext ?.findRenderObject() as RenderBox; final offset = renderBox.localToGlobal(Offset.zero); /// Build Overlay Widget entry = OverlayEntry( builder: (context) { return StatefulBuilder( builder: (context, setStateSB) { return Positioned( top: offset.dy + 60, left: offset.dx - 80, child: buildOverlaySliderWidget( p, setStateSB), ); }, ); }, ); overlayState?.insert(entry!); }, ), ), ), // SliderOverlayWidget(), colorWidget(context: context, color: Colors.black), colorWidget(context: context, color: Colors.red), colorWidget(context: context, color: Colors.yellow), colorWidget(context: context, color: Colors.green), colorWidget(context: context, color: Colors.blue), ], ), ); } ///Overlay Entry with Slider widget Material buildOverlaySliderWidget(DrawingProvider p, StateSetter setStateSB) { return Material( elevation: 2.5, child: Container( width: 250, child: FittedBox( fit: BoxFit.fill, child: Row( children: [ IconButton( onPressed: () { double penSize = p.penSize; if (penSize &lt; 2) { penSize = 2; } p.changePenSize = --penSize; setStateSB(() { print(&quot;버튼 클릭 후 penSize = ${penSize}&quot;); }); }, icon: FaIcon(FontAwesomeIcons.minus), ), Text(&quot;${p.penSize.toStringAsFixed(0)}&quot;), Slider( inactiveColor: Colors.black26, activeColor: Colors.black, value: p.penSize, onChanged: (size) { setStateSB(() { p.changePenSize = size; }); }, min: 1, max: 15, ), IconButton( onPressed: () { double penSize = p.penSize; if (penSize &gt; 14) { penSize = 14; } p.changePenSize = ++penSize; setStateSB(() { print(&quot;버튼 클릭 후 penSize = ${penSize}&quot;); }); }, icon: Icon(Icons.add), ) ], ), ), ), ); } /// PDF Open Method openPDF(BuildContext context, File file) { return Builder(builder: (context) =&gt; PdfViewer(file: file)); } buildPDFViewer() async { final url = '수특/2023_수능특강_수1.pdf'; final file = await PDFApi.loadFirebase(url); if (file == null) return; openPDF(context, file); } } /// Painter Class class DrawingPainter extends CustomPainter { DrawingPainter(this.lines); final List&lt;List&lt;DotInfo&gt;&gt; lines; @override void paint(Canvas canvas, Size size) { for (var oneLine in lines) { Color? color; double? size; var path = Path(); var l = &lt;Offset&gt;[]; for (var oneDot in oneLine) { color ??= oneDot.color; size ??= oneDot.size; l.add(oneDot.offset); } path.addPolygon(l, false); canvas.drawPath( path, Paint() ..color = color! ..strokeWidth = size! ..strokeCap = StrokeCap.round ..style = PaintingStyle.stroke ..isAntiAlias = true ..strokeJoin = StrokeJoin.round); } } @override bool shouldRepaint(covariant CustomPainter oldDelegate) =&gt; true; } </code></pre> <p>Im pretty sure there's some error in MyApp build method</p> <p>I tried to wrap the materialApp with Futurebilder and WorkbookPage with Futurebuilder but it shows the same error</p> <blockquote> <p>pdf_viewer.dart</p> </blockquote> <pre><code>class PdfViewer extends StatefulWidget { final File file; const PdfViewer({Key? key, required this.file}) : super(key: key); @override State&lt;PdfViewer&gt; createState() =&gt; _PdfViewerState(); } class _PdfViewerState extends State&lt;PdfViewer&gt; { late PDFViewController controller; int pages = 0; int indexPage = 0; @override Widget build(BuildContext context) { final name = basename(widget.file.path); final text = '${indexPage + 1} of $pages'; return Scaffold( body: PDFView( filePath: widget.file.path, swipeHorizontal: true, onRender: (pages) { setState(() { this.pages = pages!; }); }, onViewCreated: (controller) { setState(() { this.controller = controller; }); }, ), ); } } </code></pre> <blockquote> <p>Error code</p> </blockquote> <pre><code>The following _TypeError was thrown building WorkbookPage(dirty, dependencies: [_InheritedProviderScope&lt;DrawingProvider?&gt;], state: _WorkbookPageState#a99ca): type 'Future&lt;dynamic&gt;' is not a subtype of type 'Widget' The relevant error-causing widget was: WorkbookPage WorkbookPage:file:///C:/Users/park/AndroidStudioProjects/stylus_test2/lib/main.dart:54:19 </code></pre>
[ { "answer_id": 74174196, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 1, "selected": false, "text": "buildPDFViewer() async {\n final url = '수특/2023_수능특강_수1.pdf';\n final file = await PDFApi.loadFirebase(u...
2022/10/23
[ "https://Stackoverflow.com/questions/74173980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19220990/" ]
74,174,039
<p>I am fighting a bit with this problem. I want to write a code, which will find a duplicate word in a string from an input and print that word. Along with the word I also want to print the word positions in the given string.</p> <p>This is my code so far, but on the output I still get the word repeated. Any ideas how to fix it?</p> <p><strong>Input:</strong> <code>juice bread tea water apple tea carrot coconut</code></p> <p><strong>Output - desired:</strong> <code>tea 1 4</code></p> <pre><code>string = str(input()) string_list = string.split(' ') for j in range(len(string_list)): duplicate = string_list.count(string_list[j]) if duplicate &gt; 1: print((string_list[j]), (j), end=' ') </code></pre> <p><strong>Output - current:</strong> <code>tea 2 tea 5 </code></p>
[ { "answer_id": 74174179, "author": "mlokos", "author_id": 19570235, "author_profile": "https://Stackoverflow.com/users/19570235", "pm_score": 1, "selected": true, "text": "string = str(input())\n\nstring_list = string.split(' ')\nduplicates = [word for word in string_list if string_list....
2022/10/23
[ "https://Stackoverflow.com/questions/74174039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316629/" ]
74,174,075
<p>This my intended visualization<a href="https://i.stack.imgur.com/dac1v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dac1v.png" alt="fig" /></a></p> <p>But I'm getting something like this I'm not able to fix the bubble size as well as the asociateed color the way its shown in first figure</p> <p><a href="https://i.stack.imgur.com/5a2Q6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5a2Q6.png" alt="this image i get" /></a></p> <p>My code and the data used small subset is this</p> <p>My data</p> <pre><code>dput(aaa) structure(list(term_ID = structure(1:10, .Label = c(&quot;GO:0000902&quot;, &quot;GO:0000904&quot;, &quot;GO:0001501&quot;, &quot;GO:0001505&quot;, &quot;GO:0001934&quot;, &quot;GO:0001944&quot;, &quot;GO:0002250&quot;, &quot;GO:0002252&quot;, &quot;GO:0003002&quot;, &quot;GO:0003012&quot;, &quot;GO:0003013&quot;, &quot;GO:0006836&quot;, &quot;GO:0006897&quot;, &quot;GO:0006909&quot;, &quot;GO:0006910&quot;, &quot;GO:0006935&quot;, &quot;GO:0006941&quot;, &quot;GO:0006954&quot;, &quot;GO:0006958&quot;, &quot;GO:0006959&quot;, &quot;GO:0007160&quot;, &quot;GO:0007167&quot;, &quot;GO:0007169&quot;, &quot;GO:0007389&quot;, &quot;GO:0007599&quot;, &quot;GO:0008015&quot;, &quot;GO:0008037&quot;, &quot;GO:0009611&quot;, &quot;GO:0009617&quot;, &quot;GO:0010324&quot;, &quot;GO:0030048&quot;, &quot;GO:0030198&quot;, &quot;GO:0030574&quot;, &quot;GO:0031175&quot;, &quot;GO:0031344&quot;, &quot;GO:0032409&quot;, &quot;GO:0032940&quot;, &quot;GO:0032963&quot;, &quot;GO:0032989&quot;, &quot;GO:0034330&quot;, &quot;GO:0034762&quot;, &quot;GO:0034765&quot;, &quot;GO:0035150&quot;, &quot;GO:0035239&quot;, &quot;GO:0035637&quot;, &quot;GO:0035987&quot;, &quot;GO:0040011&quot;, &quot;GO:0042060&quot;, &quot;GO:0043062&quot;, &quot;GO:0043269&quot;, &quot;GO:0043408&quot;, &quot;GO:0043410&quot;, &quot;GO:0044057&quot;, &quot;GO:0045229&quot;, &quot;GO:0046903&quot;, &quot;GO:0048598&quot;, &quot;GO:0048705&quot;, &quot;GO:0050767&quot;, &quot;GO:0050808&quot;, &quot;GO:0050817&quot;, &quot;GO:0050865&quot;, &quot;GO:0050871&quot;, &quot;GO:0050878&quot;, &quot;GO:0050900&quot;, &quot;GO:0051282&quot;, &quot;GO:0051960&quot;, &quot;GO:0060284&quot;, &quot;GO:0060306&quot;, &quot;GO:0070252&quot;, &quot;GO:0071345&quot;, &quot;GO:0086001&quot;, &quot;GO:0098609&quot;, &quot;GO:0098900&quot;, &quot;GO:0098901&quot;, &quot;GO:0099003&quot;, &quot;GO:0099504&quot;, &quot;GO:0099537&quot;, &quot;GO:0120035&quot;, &quot;GO:0140352&quot;, &quot;GO:1903115&quot;, &quot;GO:1903522&quot; ), class = &quot;factor&quot;), description = structure(c(7L, 8L, 71L, 60L, 44L, 79L, 3L, 30L, 45L, 36L), .Label = c(&quot;actin filament-based movement&quot;, &quot;actin-mediated cell contraction&quot;, &quot;adaptive immune response&quot;, &quot;blood circulation&quot;, &quot;cardiac muscle cell action potential&quot;, &quot;cell junction organization&quot;, &quot;cell morphogenesis&quot;, &quot;cell morphogenesis involved in differentiation&quot;, &quot;cell recognition&quot;, &quot;cell-cell adhesion&quot;, &quot;cell-matrix adhesion&quot;, &quot;cellular component morphogenesis&quot;, &quot;cellular response to cytokine stimulus&quot;, &quot;chemotaxis&quot;, &quot;circulatory system process&quot;, &quot;coagulation&quot;, &quot;collagen catabolic process&quot;, &quot;collagen metabolic process&quot;, &quot;complement activation, classical pathway&quot;, &quot;embryonic morphogenesis&quot;, &quot;endocytosis&quot;, &quot;endodermal cell differentiation&quot;, &quot;enzyme-linked receptor protein signaling pathway&quot;, &quot;export from cell&quot;, &quot;external encapsulating structure organization&quot;, &quot;extracellular matrix organization&quot;, &quot;extracellular structure organization&quot;, &quot;hemostasis&quot;, &quot;humoral immune response&quot;, &quot;immune effector process&quot;, &quot;inflammatory response&quot;, &quot;leukocyte migration&quot;, &quot;locomotion&quot;, &quot;membrane invagination&quot;, &quot;multicellular organismal signaling&quot;, &quot;muscle system process&quot;, &quot;neuron projection development&quot;, &quot;neurotransmitter transport&quot;, &quot;pattern specification process&quot;, &quot;phagocytosis&quot;, &quot;phagocytosis, recognition&quot;, &quot;positive regulation of B cell activation&quot;, &quot;positive regulation of MAPK cascade&quot;, &quot;positive regulation of protein phosphorylation&quot;, &quot;regionalization&quot;, &quot;regulation of actin filament-based movement&quot;, &quot;regulation of action potential&quot;, &quot;regulation of blood circulation&quot;, &quot;regulation of body fluid levels&quot;, &quot;regulation of cardiac muscle cell action potential&quot;, &quot;regulation of cell activation&quot;, &quot;regulation of cell development&quot;, &quot;regulation of cell projection organization&quot;, &quot;regulation of ion transmembrane transport&quot;, &quot;regulation of ion transport&quot;, &quot;regulation of MAPK cascade&quot;, &quot;regulation of membrane repolarization&quot;, &quot;regulation of nervous system development&quot;, &quot;regulation of neurogenesis&quot;, &quot;regulation of neurotransmitter levels&quot;, &quot;regulation of plasma membrane bounded cell projection organization&quot;, &quot;regulation of sequestering of calcium ion&quot;, &quot;regulation of system process&quot;, &quot;regulation of transmembrane transport&quot;, &quot;regulation of transporter activity&quot;, &quot;regulation of tube size&quot;, &quot;response to bacterium&quot;, &quot;response to wounding&quot;, &quot;secretion&quot;, &quot;secretion by cell&quot;, &quot;skeletal system development&quot;, &quot;skeletal system morphogenesis&quot;, &quot;striated muscle contraction&quot;, &quot;synapse organization&quot;, &quot;synaptic vesicle cycle&quot;, &quot;trans-synaptic signaling&quot;, &quot;transmembrane receptor protein tyrosine kinase signaling pathway&quot;, &quot;tube morphogenesis&quot;, &quot;vasculature development&quot;, &quot;vesicle-mediated transport in synapse&quot;, &quot;wound healing&quot;), class = &quot;factor&quot;), frequency = c(3.90388708412681, 3.0469362607819, 2.85650274448303, 1.22101489862216, 4.17833538702812, 2.92371457376498, 3.67984765318696, 2.54284754116725, 1.89313319144169, 1.57387700235241), plot_X = c(6.92244115457684, 6.72491915133615, 5.75342433388847, -4.90486321695327, -4.34558231048815, 5.9436291821168, -0.331063511422281, -2.02986678951973, 6.27772046499967, 5.90846183785093 ), plot_Y = c(-0.441477421046203, -0.357893626091624, -1.89830400195803, 3.81175482612134, -4.96413463620965, -2.091036211506, -6.52348278338337, -6.97095859836097, -2.24397905128075, -3.82681903766349), log_size = c(2.84385542262316, 2.73639650227664, 2.70842090013471, 2.34044411484012, 2.8733206018154, 2.71850168886727, 2.81822589361396, 2.65801139665711, 2.53019969820308, 2.45024910831936), value = c(-9.8138097104, -9.3084572558, -7.983023664, -3.2017781871001, -6.0366705271, -8.4472753844, -21.0694271164, -9.0630211246, -3.94894435910093, -1.87037981820001), uniqueness = c(0.857575132627072, 0.816670053918386, 0.841547228295729, 0.886390429364808, 0.807466832663465, 0.830691169997519, 0.839912555176311, 0.892202047678151, 0.847227910985189, 0.868600113222042), dispensability = c(0, 0.69190667, 0.44917845, 0.379708, 0.14243226, 0.45070828, 0, 0.57560152, 0.40006623, 0.55626845)), row.names = c(NA, 10L), class = &quot;data.frame&quot;) </code></pre> <p>The code used, I tried to multiply a decimal into the <code>size</code> argument input which is log_size but still I was not able to make it proportional as well as the color</p> <pre><code>p1 &lt;- ggplot( data = aaa ); p1 &lt;- p1 + geom_point( aes( plot_X, plot_Y, colour = value, size = log_size), alpha = I(0.6) ); p1 &lt;- p1 + scale_colour_gradientn( colours = c(&quot;blue&quot;, &quot;green&quot;, &quot;yellow&quot;, &quot;red&quot;), limits = c( min(one.data$value), 0) ); p1 &lt;- p1 + geom_point( aes(plot_X, plot_Y, size = log_size), shape = 21, fill = &quot;transparent&quot;, colour = I (alpha (&quot;black&quot;, 0.6) )); p1 &lt;- p1 + scale_size( range=c(5, 30)) + theme_bw(); # + scale_fill_gradientn(colours = heat_hcl(7), limits = c(-300, 0) ); ex &lt;- one.data [ one.data$dispensability &lt; 0.15, ]; p1 &lt;- p1 + geom_text( data = ex, aes(plot_X, plot_Y, label = description), colour = I(alpha(&quot;black&quot;, 0.85)), size = 3 ); p1 &lt;- p1 + labs (y = &quot;semantic space x&quot;, x = &quot;semantic space y&quot;); p1 &lt;- p1 + theme(legend.key = element_blank()) ; one.x_range = max(one.data$plot_X) - min(one.data$plot_X); one.y_range = max(one.data$plot_Y) - min(one.data$plot_Y); p1 &lt;- p1 + xlim(min(one.data$plot_X)-one.x_range/10,max(one.data$plot_X)+one.x_range/10); p1 &lt;- p1 + ylim(min(one.data$plot_Y)-one.y_range/10,max(one.data$plot_Y)+one.y_range/10); # -------------------------------------------------------------------------- # Output the plot to screen p1; </code></pre> <p>Any suggestion or help would be really appreciated</p>
[ { "answer_id": 74174179, "author": "mlokos", "author_id": 19570235, "author_profile": "https://Stackoverflow.com/users/19570235", "pm_score": 1, "selected": true, "text": "string = str(input())\n\nstring_list = string.split(' ')\nduplicates = [word for word in string_list if string_list....
2022/10/23
[ "https://Stackoverflow.com/questions/74174075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14010653/" ]
74,174,119
<p>I have a controller class for the health of a GameObject. It is not a MonoBehavior but it will be used by MonoBehavior objects.</p> <pre class="lang-cs prettyprint-override"><code>using System; using UnityEngine; [Serializable] public class HealthController{ [SerializeField] private int max_health; private int health; public HealthController { this.health = this.max_health; // this doesnt work because its called before serialisation } } </code></pre> <p>so I want to be able to set the maximum health in the unity editor: thats why <code>max_health</code> is a SerializeField. But now i also want the variable <code>health</code> initally to be set to the the maximum health without introducing a second SerializeField for it. Thats why I tried to put the line <code>this.health = this.max_health</code> to the constructor: but this doesn#t work because the constructor seems to be called before the serialisation.</p> <p>The only solution i could think of is adding a <code>public void Initialize()</code> instead of the contructor to the HealthController and then explicitly calling this in the Start() method of the Monobehavior owning this controller.</p> <pre class="lang-cs prettyprint-override"><code>using System; using UnityEngine; [Serializable] public class HealthController{ [SerializeField] private int max_health; private int health; public void Initialize() { this.health = this.max_health; } } public class Player : MonoBehaviour { public HealthController health; public void Start() { health.Initialize(); } } </code></pre> <p>But this seems too complicated to me: Is there a better solution on how to do this?</p>
[ { "answer_id": 74174179, "author": "mlokos", "author_id": 19570235, "author_profile": "https://Stackoverflow.com/users/19570235", "pm_score": 1, "selected": true, "text": "string = str(input())\n\nstring_list = string.split(' ')\nduplicates = [word for word in string_list if string_list....
2022/10/23
[ "https://Stackoverflow.com/questions/74174119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7018093/" ]
74,174,166
<p>I have a table where one column has the genders (M,F,O) and I have another column for patient_weight, I need to get the average weight of the Females and then show a count of all the males that weigh less than the average female. Here is what I have so far:</p> <pre><code>SELECT top 50 * FROM dbo.patients SELECT AVG(patient_weight) FROM patients WHERE gender LIKE 'F'; SELECT COUNT (patient_weight) FROM patients WHERE gender LIKE 'M' AND patient_weight &lt; 77 </code></pre>
[ { "answer_id": 74174179, "author": "mlokos", "author_id": 19570235, "author_profile": "https://Stackoverflow.com/users/19570235", "pm_score": 1, "selected": true, "text": "string = str(input())\n\nstring_list = string.split(' ')\nduplicates = [word for word in string_list if string_list....
2022/10/23
[ "https://Stackoverflow.com/questions/74174166", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14297891/" ]
74,174,171
<p>How can I generate a list with regex in python for countries with 4 or 5 letters?</p> <pre><code>names = ['Azerbaijan', 'Zimbabwe', 'Cuba', 'Cambodia', 'Somalia','Mali', 'Belarus', &quot;Côte d'Ivoire&quot;, 'Venezuela', 'Syria', 'Kazakhstan', 'Austria', 'Malawi', 'Romania', 'Congo (Brazzaville)'] </code></pre> <p>I was trying to do this but it returns an empty list:</p> <pre><code>import re n = [w for w in names if re.findall(r'[A-Z]{4,6},', str(names))] print(n) Output: [] </code></pre> <p>It is an exercise that's why I can only do it with the module re. Any help will be appreciate.</p>
[ { "answer_id": 74174179, "author": "mlokos", "author_id": 19570235, "author_profile": "https://Stackoverflow.com/users/19570235", "pm_score": 1, "selected": true, "text": "string = str(input())\n\nstring_list = string.split(' ')\nduplicates = [word for word in string_list if string_list....
2022/10/23
[ "https://Stackoverflow.com/questions/74174171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15204667/" ]
74,174,246
<p>I have a folder with files like:</p> <pre><code>pe1_file1.txt pe1_file2.txt px1_file3.txt px1_file4.txt etc every file has lines such: 1123343 34 SDSD XV34 nameofdatabase 34 45455 4545 1145343 33 SD34 XT45 nameofdatabase 34 45455 4545 </code></pre> <p>I would like to parse all the files of that folder (actually there are a bunch of folders) and build up a single text file that includes all the lines of all those text files that comply with a particular condition. The resulting file should only contain the first 5 values (up to nameofdatabase) AND the 3 first letters of the name of the file.</p> <p>I tend to use the following code modified: The following passes all the filtered lines and with all the values. I want to omit the last three numbers and add &quot;pe1&quot; or &quot;px2&quot; as first value.</p> <pre><code>for FILE in files/*.txt; do firstchar=${FILE:0:4} # how do I modify the nest line in order to add $firstchar (&quot;pe1&quot;) and $1,$2,$3,$4,$5,$6 ??? awk '$3==&quot;SDSD&quot;&amp;&amp;$4==&quot;cardatabase&quot;' $FILE.txt &gt;&gt; TOTAL.txt done </code></pre>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7168098/" ]
74,174,252
<p>I am building a website with a container and a background image but is de client is a mobile device want to prevent the client from loading this image. For bigger screens would I like to use +-5 images with a different resolution for every device width. But I don't find a way to use this <code>&lt;img style=&quot;width: 100%;&quot; src=&quot;./img/normal.png&quot; srcset=&quot; img/lowres.png 700w, img/normal.jpg 900w, img/highres.jpg 1100w&quot; alt=&quot;test img&quot;&gt;</code></p> <p>in CSS, now I am using an regular high res image. (But it shouldn't load on mobile and be an appropriate size for every desktop)</p> <pre><code>max-width: 2560px; background-image: url(&quot;../img/test_image_2.jpg&quot;); background-repeat: no-repeat; background-attachment: fixed;}``` </code></pre>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18661959/" ]
74,174,258
<p>What's the best approach to store multiple images in database?</p> <p>Upon browsing and searching for solution and approaches I found 2 options</p> <p><code>first one is take the file name and concatenate and separate them using either comma or |</code> but I'm having doubts since I think that's messy and would produce errors later in the system</p> <p><code>second is I make another table for images and add foreign key (post_id) to know which post it belongs.</code></p> <p>Any suggestion will be appreciated.</p>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17799826/" ]
74,174,261
<p>When i run the bat file the command prompt appears even if i use <code>@echo off</code> some commands' prompts are visible so i need to make command prompt invisible while it is working</p>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316490/" ]
74,174,262
<p>I would like to have margin for my search input I mean I want write after the magnifying glass [image here] <a href="https://i.stack.imgur.com/JNlWE.png" rel="nofollow noreferrer">https://i.stack.imgur.com/JNlWE.png</a></p> <p>tk</p>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316788/" ]
74,174,294
<p>I want to make a simple function that collects the product ID and adds it to the user's shopping cart by clicking the &quot;add to cart&quot; button. I have the shopping cart table and product table created but am struggling to find the correct function to add the product to the cart. Anything helps I am very new to Python and Django and am looking for some help to get me on the right track.</p> <pre><code>class Cart(models.Model): cart_id = models.Charfield(primary_key=True) total = models.DecimalField(max_digits=9,decimal_places=2) quantity = models.IntegerField() products = models.ManyToManyField(Product) class Product(models.Model): prod_id = models.CharField(max_length=15, null=True) name = models.CharField(max_length=200) price = models.DecimalField(max_digits=10,decimal_places=2) description = models.TextField(max_length=1000) def cart_add(request, prod_id): item = Product.objects.get(pk=prod_id) </code></pre> <p>I know this isn't much to work with but anything helps, I am just looking for some help with creating the add to cart function</p>
[ { "answer_id": 74174477, "author": "knittl", "author_id": 112968, "author_profile": "https://Stackoverflow.com/users/112968", "pm_score": 1, "selected": false, "text": "awk" }, { "answer_id": 74174608, "author": "karakfa", "author_id": 1435869, "author_profile": "http...
2022/10/23
[ "https://Stackoverflow.com/questions/74174294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20055066/" ]
74,174,307
<pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;stdbool.h&gt; int main() { int c; while(true) { c = scanf(&quot;%d&quot;, &amp;c); if(c==12) { printf(&quot;goes in&quot;); break; } }     return 0; } </code></pre> <p>I am still learning C and I got stuck here. My code is pretty simple but I have no idea why it's not working. The while loop functions normally however I cannot access the if statement despite meeting the condition.</p> <p>Thank you!</p>
[ { "answer_id": 74174330, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 2, "selected": false, "text": "scanf" }, { "answer_id": 74174464, "author": "William Pursell", "author_id": 140750, "author_profi...
2022/10/23
[ "https://Stackoverflow.com/questions/74174307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316833/" ]
74,174,310
<p>I am writing a bash script that has 1) number of lines in a file matching a pattern and 2) total lines in a file.</p> <p>a) To get the number of lines in a file within a directory that had a specific pattern I used grep -c &quot;pattern&quot; f*</p> <p>b) For overall line count in each file within the directory I used wc -l f*</p> <p>I am trying to divide the output from 2 by 1. I have tried a for loop</p> <pre><code>for i in $a do printf &quot;%f\n&quot; $(($b/$a) echo i done </code></pre> <p>but that returns an error <code>syntax error in expression (error token is &quot;first file in directory&quot;)</code></p> <p>I also have tried</p> <pre><code>bc &quot;$b/$a&quot; </code></pre> <p>which does not work either</p> <p>I am not sure if this is possible to do -- any advice appreciated. thanks!</p> <p>Sample: grep -c *f generates a list like this</p> <pre><code>myfile1 500 myfile2 0 myfile3 14 myfile4 18 </code></pre> <p>and wc -l *f generates a list like this:</p> <pre><code>myfile1 500 myfile2 500 myfile3 500 myfile4 238 </code></pre> <p>I want my output to be the outcome of output for grep/wc divided so for example</p> <pre><code>myfile1 1 myfile2 0 myfile3 0.28 myfile4 0.07 </code></pre>
[ { "answer_id": 74174452, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "bash" }, { "answer_id": 74174579, "author": "Ivan", "author_id": 12607443, "author_profile": ...
2022/10/23
[ "https://Stackoverflow.com/questions/74174310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20084383/" ]
74,174,317
<p>I am trying to create rounded corners for a custom cell in my UITableView, I have tried the following.</p> <pre><code> let cell = tableView.dequeueReusableCell(withIdentifier: &quot;FriendCell&quot;, for: indexPath) let friend = friends[indexPath.row] cell.textLabel?.text = friend.value(forKey: &quot;name&quot;) as? String cell.textLabel?.textAlignment = .center cell.layer.cornerRadius = 12 cell.layer.borderColor = UIColor.red.cgColor </code></pre> <p>The result shows up like this, it is creating the border around the content view as opposed to the view for the cell. If anyone is able to help, it would be much appreciated. Thank you!</p> <p><a href="https://i.stack.imgur.com/mf1kk.png" rel="nofollow noreferrer">https://i.stack.imgur.com/mf1kk.png</a></p>
[ { "answer_id": 74174452, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "bash" }, { "answer_id": 74174579, "author": "Ivan", "author_id": 12607443, "author_profile": ...
2022/10/23
[ "https://Stackoverflow.com/questions/74174317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13865615/" ]
74,174,345
<p>So I have a discord.js bot. And I want moderators to be able to run a slash command and upload an image to the bot's directory (folder on my Raspberry Pi, where my bot is hosted). So I made a command,</p> <pre><code>const fs = require(&quot;fs&quot;); const path = require(&quot;path&quot;); const Discord = require(&quot;discord.js&quot;); module.exports = { data: new SlashCommandBuilder() .setName(&quot;addimg&quot;) .setDescription(&quot;Allows Moderators to add needed images.&quot;) .addAttachmentOption((option) =&gt; option .setName('image') .setDescription('The image you want to add.') .setRequired(true) ), async execute(interaction, client) { var image = interaction.options.getAttachment(&quot;image&quot;); console.log(image) if(path.parse(image.name).ext == &quot;.png&quot; || path.parse(image.name).ext == &quot;.jpg&quot;){ await fs.writeFileSync(`../../../imgs/${image.name}`, /*Data*/) const embed = new Discord.EmbedBuilder() .setTitle(`Image Added!`) .setColor(&quot;000000&quot;) .setDescription(`Check it out by using the /img command and choosing ${image}`) interaction.reply({ embeds: [embed] }); } else{ return interaction.reply({ embeds: [new Discord.EmbedBuilder() .setTitle(`Failed to Add Image.`) .setColor(&quot;000000&quot;) .setDescription(`This format of image is not allowed. Try again with a .png or .jpg image.`)] }) } } } </code></pre> <p>But I don't know how/where to start with converting the Discord Attachment to binary (raw image data). And I know that the Discord Attachments have a .url which maybe should be used? But still I don't know how I would do that.</p>
[ { "answer_id": 74174452, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "bash" }, { "answer_id": 74174579, "author": "Ivan", "author_id": 12607443, "author_profile": ...
2022/10/23
[ "https://Stackoverflow.com/questions/74174345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18272152/" ]
74,174,346
<p>I am creating a json file like this</p> <pre><code>[ {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;15194804&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;18264178&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;16225177&quot;, &quot;rating&quot;: 1}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;16445238&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;17233226&quot;, &quot;rating&quot;: 0}, ] </code></pre> <p>I want to remove the last comma so that output looks like</p> <pre><code>[ {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;15194804&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;18264178&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;16225177&quot;, &quot;rating&quot;: 1}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;16445238&quot;, &quot;rating&quot;: 0}, {&quot;_index&quot;: &quot;java&quot;, &quot;_id&quot;: &quot;17233226&quot;, &quot;rating&quot;: 0} ] </code></pre> <p>Here is my code</p> <pre><code>with open(folder + &quot;/&quot; + str(a[i]) + &quot;.json&quot;, 'w') as fp: fp.write(&quot;[\n&quot;) for i in range(len(ratings)): x = json.dumps(ratings[i]) fp.write(&quot;%s,\n&quot; % x) fp.write(&quot;]\n&quot;) fp.close() </code></pre>
[ { "answer_id": 74174452, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "bash" }, { "answer_id": 74174579, "author": "Ivan", "author_id": 12607443, "author_profile": ...
2022/10/23
[ "https://Stackoverflow.com/questions/74174346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18690536/" ]
74,174,359
<p>I have a sales table, where it shows the information below</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">ID_sale</th> <th style="text-align: center;">sales_person</th> <th style="text-align: center;">sale_date</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">7</td> <td style="text-align: center;">50</td> <td style="text-align: center;">19/10/2022</td> </tr> <tr> <td style="text-align: center;">6</td> <td style="text-align: center;">43</td> <td style="text-align: center;">17/9/2022</td> </tr> <tr> <td style="text-align: center;">5</td> <td style="text-align: center;">50</td> <td style="text-align: center;">15/3/2022</td> </tr> <tr> <td style="text-align: center;">4</td> <td style="text-align: center;">43</td> <td style="text-align: center;">13/2/2022</td> </tr> <tr> <td style="text-align: center;">2</td> <td style="text-align: center;">50</td> <td style="text-align: center;">22/1/2022</td> </tr> <tr> <td style="text-align: center;">3</td> <td style="text-align: center;">10</td> <td style="text-align: center;">05/2/2022</td> </tr> <tr> <td style="text-align: center;">1</td> <td style="text-align: center;">12</td> <td style="text-align: center;">07/1/2022</td> </tr> </tbody> </table> </div> <p>and I want to create a query where I get the following information, basically the most recent date of the sale and the last sale date they made</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">ID_sale</th> <th style="text-align: center;">sales_person</th> <th style="text-align: center;">recent_sale</th> <th style="text-align: center;">last_sale</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">7</td> <td style="text-align: center;">50</td> <td style="text-align: center;">19/10/2022</td> <td style="text-align: center;">15/3/2022</td> </tr> <tr> <td style="text-align: center;">6</td> <td style="text-align: center;">43</td> <td style="text-align: center;">17/9/2022</td> <td style="text-align: center;">13/2/2022</td> </tr> <tr> <td style="text-align: center;">3</td> <td style="text-align: center;">10</td> <td style="text-align: center;">05/2/2022</td> <td style="text-align: center;">05/2/2022</td> </tr> <tr> <td style="text-align: center;">1</td> <td style="text-align: center;">12</td> <td style="text-align: center;">07/1/2022</td> <td style="text-align: center;">07/1/2022</td> </tr> </tbody> </table> </div> <p>Thank you</p>
[ { "answer_id": 74174713, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "rank()" }, { "answer_id": 74174811, "author": "nbk", "author_id": 5193536, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74174359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20243283/" ]
74,174,377
<p>I am trying to create a column using UDF function in PySpark.</p> <p>The code I tried looks like this:</p> <pre class="lang-py prettyprint-override"><code># The function checks year and adds a multiplied value_column to the final column def new_column(row, year): if year == &quot;2020&quot;: return row * 0.856 elif year == &quot;2019&quot;: return row * 0.8566 else: return row final_udf = F.udf(lambda z: new_column(z), Double()) #How do I get - Double datatype here res = res.withColumn(&quot;final_value&quot;, final_udf(F.col('value_column'), F.col('year'))) </code></pre> <p>How can I write Double() in <code>final_udf</code>? I see that for string we can use <code>StringType()</code>. But what can I do to return double type in the &quot;final_value&quot; column?</p>
[ { "answer_id": 74174713, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "rank()" }, { "answer_id": 74174811, "author": "nbk", "author_id": 5193536, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74174377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19831970/" ]
74,174,385
<p>How can i make a text with html like in the screenshot below. I just need a simple text but it should be vertically.</p> <p><a href="https://i.stack.imgur.com/aQBFe.png" rel="nofollow noreferrer">screenshot</a></p>
[ { "answer_id": 74174713, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "rank()" }, { "answer_id": 74174811, "author": "nbk", "author_id": 5193536, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74174385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14370537/" ]
74,174,412
<p>I received the following error when trying to install geopandas in my environment after it failed in the terminal via the conda-forge command. Is there a way to get this updated and fixed?</p> <pre><code> Output in format: Requested package -&gt; Available versions Package geopandas-base conflicts for: geopandas -&gt; geopandas-base==0.9.0=py_1 geopandas-base Package ca-certificates conflicts for: python=3.9 -&gt; openssl[version='&gt;=1.1.1q,&lt;1.1.2a'] -&gt; ca-certificates geopandas -&gt; python -&gt; ca-certificates``` </code></pre>
[ { "answer_id": 74174713, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "rank()" }, { "answer_id": 74174811, "author": "nbk", "author_id": 5193536, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74174412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12868635/" ]
74,174,413
<p>I have the following data frame:</p> <pre class="lang-py prettyprint-override"><code> df_test = pd.DataFrame({&quot;f&quot;:['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], &quot;d&quot;:['x', 'x', 'y', 'y', 'x', 'x', 'y', 'y'], &quot;low&quot;: [0,5,2,4,5,10,4,8], &quot;up&quot;: [5,10,4,6,10,15,8,12], &quot;z&quot;: [1,3,6,2,3,7,5,10]}) </code></pre> <p>and what I first have to do is to convert the columns 'low', 'up' and 'z' to list for each (grouped by) 'f' and 'd'. so this is what I did:</p> <pre class="lang-py prettyprint-override"><code> dff = df_test.groupby(['f','d'])[['low', 'up', 'z']].agg(list).reset_index() </code></pre> <p>and this is what I get: <a href="https://i.stack.imgur.com/IXHtz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IXHtz.png" alt="enter image description here" /></a></p> <p>Now I want to extract the last value from the lists in column 'up' and add it to the lists in column 'low'. But this is unfortunately not working:</p> <pre class="lang-py prettyprint-override"><code> dff['last'] = (dff['up'].apply(lambda x: x[-1])).tolist() dff['new'] = dff['low'].append(dff['last']) </code></pre> <p>I get an error message &quot;ValueError: cannot reindex from a duplicate axis&quot;. The column 'new' should have these values: [0,5,10], [2,4,6], [5,10,15], [4,8,12]</p> <p>any help is very much appreciated!</p>
[ { "answer_id": 74174713, "author": "DannySlor", "author_id": 19174570, "author_profile": "https://Stackoverflow.com/users/19174570", "pm_score": 1, "selected": false, "text": "rank()" }, { "answer_id": 74174811, "author": "nbk", "author_id": 5193536, "author_profile":...
2022/10/23
[ "https://Stackoverflow.com/questions/74174413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14560284/" ]
74,174,426
<p>I am using temporarily a Mac (M1) with R but it runs only with one core. I am editing my question to include a reproducible example. I would like to run functions with big data using multiple core.</p> <p>this is the reproducible example:</p> <pre class="lang-r prettyprint-override"><code>library(eulerr) library(microbiome) #devtools::install_github('microsud/microbiomeutilities') library(microbiomeutilities) data(&quot;zackular2014&quot;) pseq &lt;- zackular2014 table(meta(pseq)$DiseaseState, useNA = &quot;always&quot;) pseq.rel &lt;- microbiome::transform(pseq, &quot;compositional&quot;) Make a list of DiseaseStates. disease_states &lt;- unique(as.character(meta(pseq.rel)$DiseaseState)) print(disease_states) list_core &lt;- c() # an empty object to store information for (n in disease_states){ # for each variable n in DiseaseState #print(paste0(&quot;Identifying Core Taxa for &quot;, n)) ps.sub &lt;- subset_samples(pseq.rel, DiseaseState == n) # Choose sample from DiseaseState by n core_m &lt;- core_members(ps.sub, # ps.sub is phyloseq selected with only samples from g detection = 0.001, # 0.001 in atleast 90% samples prevalence = 0.75) print(paste0(&quot;No. of core taxa in &quot;, n, &quot; : &quot;, length(core_m))) # print core taxa identified in each DiseaseState. list_core[[n]] &lt;- core_m mycols &lt;- c(nonCRC=&quot;#d6e2e9&quot;, CRC=&quot;#cbf3f0&quot;, H=&quot;#fcf5c7&quot;) plot(venn(list_core), fills = mycols) </code></pre> <p>I would like to run the first for loop using multiple cores but I don't know how to write the function including <code>mclapply</code>? thanks</p>
[ { "answer_id": 74174691, "author": "Ben Bolker", "author_id": 190277, "author_profile": "https://Stackoverflow.com/users/190277", "pm_score": 2, "selected": false, "text": "parallel" }, { "answer_id": 74188751, "author": "jared_mamrot", "author_id": 12957340, "author_...
2022/10/23
[ "https://Stackoverflow.com/questions/74174426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8682842/" ]
74,174,429
<p>I have been been reading a lot of about SwiftUI architecture. I read about MVVM, TCA, MVC etc. I am writing an app, where I have to get data from the JSON API and display it on the screen. I am following Apple's code samples and here is what I am doing.</p> <p>For that I created a NetworkModel.</p> <pre><code>class NetworkModel { func getPosts() async throws -&gt; [Post] { let (data, _) = try await URLSession.shared.data(from: URL(string: &quot;https://jsonplaceholder.typicode.com/posts&quot;)!) let posts = try JSONDecoder().decode([Post].self, from: data) return posts } } </code></pre> <p><strong>Post.swift</strong></p> <pre><code>struct Post: Decodable { let id: Int let title: String let body: String } </code></pre> <p><strong>PostListView</strong></p> <pre><code>struct PostListView: View { @State private var posts: [Post] = [] let networkModel = NetworkModel() var body: some View { List(posts, id: \.id) { post in Text(post.title) }.task { do { await networkModel.getPosts() } catch { print(error) } } } } </code></pre> <p>Everything works. Is this the right approach? I come from React background so in React if there is a component that is using state and that state will only be used for that component then we simply use private/local state.</p> <p>I did not create any View Models etc for this app. Are VM's going to benefit me in someway?</p>
[ { "answer_id": 74174691, "author": "Ben Bolker", "author_id": 190277, "author_profile": "https://Stackoverflow.com/users/190277", "pm_score": 2, "selected": false, "text": "parallel" }, { "answer_id": 74188751, "author": "jared_mamrot", "author_id": 12957340, "author_...
2022/10/23
[ "https://Stackoverflow.com/questions/74174429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19037628/" ]
74,174,444
<pre><code>// Generic Function but not work as expecting inline fun &lt;reified C : Collection&lt;T&gt;, T&gt; C.dropElements(word: T): C { return when (this) { is Set&lt;*&gt; -&gt; (this - word) as C is List&lt;*&gt; -&gt; filter { it != word } as C else -&gt; throw Exception(&quot;I can't implement all out of Collection types&quot;) } } fun main() { val originalList: List&lt;String&gt; = readln().split(&quot; &quot;) val originalSet: Set&lt;String&gt; = originalList.toSet() val word: String = readln() val dropElements1: List&lt;String&gt; = originalList.dropElements(word).also(::println) val dropElements2: Set&lt;String&gt; = originalSet.dropElements(word).also(::println) // Incorrect: Int and String are different types val dropElements3: List&lt;Int&gt; = listOf(1, 2, 3).dropElements(word).also(::println) } </code></pre>
[ { "answer_id": 74174988, "author": "AndrewL", "author_id": 1847378, "author_profile": "https://Stackoverflow.com/users/1847378", "pm_score": 1, "selected": false, "text": "dropElements3" }, { "answer_id": 74175062, "author": "gpunto", "author_id": 1292745, "author_pro...
2022/10/23
[ "https://Stackoverflow.com/questions/74174444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14253948/" ]
74,174,458
<p>I have a set of data from a <code>pd.DataFrame</code> which looks like this, with a 3rd-order polynomial fitted to it:</p> <p><a href="https://i.stack.imgur.com/vWivW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vWivW.png" alt="enter image description here" /></a> which is fit by</p> <pre><code># Find the 3rd-order polynomial which fits the SED coefs = poly.polyfit(x, y, 3) # find the coeffs x_new = np.linspace(lower, upper, num=len(x)*10) # space to plot the fit ffit = poly.Polynomial(coefs) # find the polynomial </code></pre> <p>How could I find the straight line that fits only part of the data, for example, just the downward slope within 9.5 &lt; x &lt; 15 ?</p> <p>I could slice the dataframe into pieces with</p> <pre><code>left = pks[pks[xvar] &lt; nu_to] right = pks[pks[xvar] &gt; nu_to] </code></pre> <p>but I'd like to avoid that, since I'll have to do the same thing with many datasets.</p> <p><a href="https://stackoverflow.com/questions/5763444/fit-a-line-to-a-part-of-a-plot">This question is about MatLab</a> This current question is a distillation of <a href="https://stackoverflow.com/questions/74147461/finding-two-linear-fits-on-different-domains-in-the-same-data">my previous one.</a></p>
[ { "answer_id": 74174988, "author": "AndrewL", "author_id": 1847378, "author_profile": "https://Stackoverflow.com/users/1847378", "pm_score": 1, "selected": false, "text": "dropElements3" }, { "answer_id": 74175062, "author": "gpunto", "author_id": 1292745, "author_pro...
2022/10/23
[ "https://Stackoverflow.com/questions/74174458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8322295/" ]
74,174,468
<p>I am new at python, probably as new as it gets. I am working on a simple python code for mpg and refactoring. I am not sure exactly what I am doing wrong. Its giving me a error on line 65, &quot;in goodbye print(&quot;your miles per gallon:&quot;, mpg) name error name 'mpg' is not defined. any help would be appreciated.</p> <pre><code>def main(): miles_driven = 0.0 gallons_of_gas_used = 0.0 mpg = 0.0 print_welcome() print_encouragement() goodbye() # imput miles_driven = your_miles_driven() gallons_of_gas_used = gas_used() # Calculation mpg = your_mpg(miles_driven, gallons_of_gas_used) print(&quot;Your miles per gallon:&quot;, mpg) print(&quot;\nThanks for using my mpg calculator, I will be adding additional &quot; &quot;functions soon!&quot;) def print_welcome(): print(&quot;Welcome to Ray's trip calculator!\n&quot;) def print_encouragement(): print(&quot;Let's figure out your miles per gallon!&quot;) def your_miles_driven(): your_miles_driven = 0.0 your_miles_driven = float(input(&quot;Enter number of miles driven:&quot;)) return your_miles_driven def gas_used(): gas_used = 0.0 gas_used = float(input(&quot;Enter the gallons of gas you used:&quot;)) return gas_used def your_mpg(your_miles_driven, gas_used): mpg = 0.0 your_mpg = your_miles_driven / gas_used return your_mpg def goodbye(): print(&quot;\nThanks for using my mpg calculator, I will be adding additional &quot; &quot;functions soon!&quot;) print(&quot;Your miles per gallon:&quot; , mpg) main() </code></pre>
[ { "answer_id": 74174492, "author": "Samwise", "author_id": 3799759, "author_profile": "https://Stackoverflow.com/users/3799759", "pm_score": 0, "selected": false, "text": "mpg" }, { "answer_id": 74174620, "author": "Omer Dagry", "author_id": 15010874, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74174468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316952/" ]
74,174,476
<p>Given the following inputs that simulate a grid with the respective dimensions:</p> <pre class="lang-py prettyprint-override"><code>totLines = int(input(&quot;Indicate the number os lines: &quot;)) totColunms = int(input(&quot;Indicate the number of columns: &quot;)) </code></pre> <p>I want to check whether the input is valid or not (every digit must be between 0 and 20). The code should check each line of the grid and tell the user if the input is valid and if not ask for another input. The problem is that my code only checks the first digit of line1, the second digit of the line2, and so on. For instance, in a 3x3 grid, if I input the following numbers for line1 (separated by spaces) - 21 10 10 - the code is gonna tell me that the input is not valid, but if I put the incorrect digit in position 2 - 10 21 10 - the code is not gonna find any problem. I know the problem must be related to how I´m doing the loop but I can´t understand how to solve this. This is something easy to do but It´s my first time learning a programming language and I still have a lot to learn. Thanks!</p> <pre class="lang-py prettyprint-override"><code>for lin in range (1, totLines+1): print(&quot;Line&quot;, str(lin)) while True: sMoves = input(&quot;Movement for this line: &quot;) listMoves = sMoves.split() listMovesINT = list(map(int, listMoves)) if listMovesINT[lin-1] &gt; 0 and listMovesINT[lin-1] &lt;= 20: break else: print (&quot;Not a valid integer&quot;) continue </code></pre>
[ { "answer_id": 74174492, "author": "Samwise", "author_id": 3799759, "author_profile": "https://Stackoverflow.com/users/3799759", "pm_score": 0, "selected": false, "text": "mpg" }, { "answer_id": 74174620, "author": "Omer Dagry", "author_id": 15010874, "author_profile"...
2022/10/23
[ "https://Stackoverflow.com/questions/74174476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20314957/" ]
74,174,490
<p>My component code has:</p> <pre><code>function aa() { this.component.grid = createItem(); this.component.grid.instance.options.addEventListener('eventAbc',() =&gt; { this.bbb (); }) } function bbb() { console.log(&quot;dummy func&quot;); } </code></pre> <p>in component.spec.ts file:</p> <pre><code>let content; setup() { content = jasmine.createSpyObj('content', ['createItem']); content.createItem.and.callFake(() =&gt; { return { grid: { instance: { options: { addEventListener: (event, action) =&gt; {} }}}}} it('testing method aa', () =&gt; { spyOn(component.grid.instance.gridOptions, 'addEventListener').andCallThrough(); spyOn(component, 'bbb').and.callThrough(); component.aa(); expect(component.grid.instance.gridOptions.addEventListener).toHaveBeenCalled(); expect(component.bbb).toHaveBeenCalled(); } </code></pre> <p>I want to understand how to mock triggering the 'abcEvent' so that the test goes inside the real callback of the event listener and bbb method gets called.</p>
[ { "answer_id": 74181787, "author": "AliF50", "author_id": 7365461, "author_profile": "https://Stackoverflow.com/users/7365461", "pm_score": 2, "selected": false, "text": "action" }, { "answer_id": 74281996, "author": "Saranya Garimella", "author_id": 8549551, "author_...
2022/10/23
[ "https://Stackoverflow.com/questions/74174490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8549551/" ]
74,174,512
<p><a href="https://i.stack.imgur.com/yJ2MO.png" rel="nofollow noreferrer">enter image description here</a>I have two columns 'Start Station' and 'End Station'</p> <pre><code>| Start Station | End Station | |:--------------|:------------| | A | C | | A | C | | B | D | | C | A | | A | D | | C | A | | C | B | </code></pre> <p>as you can see the most common combination is A &amp; C I'm trying to write a code in python using pandas so that the output is <strong>&quot;The most common combination is between A and C&quot;</strong> I found a lot of helpful codes for this but unfortunately couldn't find a code with the output that I need. I hope I clarified my question enough and thanks in advance</p> <p>I added an image because I'm new to stackoverflow and couldn't import the table example</p>
[ { "answer_id": 74174539, "author": "Nuri Taş", "author_id": 19255749, "author_profile": "https://Stackoverflow.com/users/19255749", "pm_score": 2, "selected": true, "text": "idxmax" }, { "answer_id": 74174558, "author": "mozway", "author_id": 16343464, "author_profile...
2022/10/23
[ "https://Stackoverflow.com/questions/74174512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20291352/" ]
74,174,515
<p>I have a list with values:</p> <pre><code>i_have = [1,1,1,4,4,4,4,4,4,4,1,1,1,1,4,4,4,4,3,3,4,3] </code></pre> <p>and I need to find the start and end indices for every chunk of the list with the value 4. If there's a 4 alone, like the second to last value of this list, its start and end indices should be the same.</p> <pre><code>i_need = [(3, 9), (14, 17), (20, 20)] </code></pre> <p>Can you help me with this?</p>
[ { "answer_id": 74174539, "author": "Nuri Taş", "author_id": 19255749, "author_profile": "https://Stackoverflow.com/users/19255749", "pm_score": 2, "selected": true, "text": "idxmax" }, { "answer_id": 74174558, "author": "mozway", "author_id": 16343464, "author_profile...
2022/10/23
[ "https://Stackoverflow.com/questions/74174515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3899295/" ]
74,174,540
<p>I am trying to write an install script in <code>babaska</code> for my other <code>babaska</code> script (for some fun homogeneity).</p> <p>Export doesn't seem to work using:</p> <pre><code>(shell &quot;export NAME=&quot; value) </code></pre> <p>Is there a canonical way to set environmental variables in Clojure / Babashka?</p>
[ { "answer_id": 74174539, "author": "Nuri Taş", "author_id": 19255749, "author_profile": "https://Stackoverflow.com/users/19255749", "pm_score": 2, "selected": true, "text": "idxmax" }, { "answer_id": 74174558, "author": "mozway", "author_id": 16343464, "author_profile...
2022/10/23
[ "https://Stackoverflow.com/questions/74174540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19582765/" ]
74,174,556
<p>I have a google sheet where I need to clear lines from rows 9 and down, the problem is my script is returning the following error;</p> <p>&quot;Exception: Those rows are out of bounds, delete rows @ Delete Rows.gs:4+ errors&quot;</p> <p>I'm assuming it's because I need to reverse the script to delete from the bottom up, can anyone provide an edit for my script so that it stops the out-of-bound errors?</p> <p>This is the script I have</p> <pre><code>function deleterows() { var ss = SpreadsheetApp.getActive().getSheetByName('Timesheet'); var lastrow= ss.getLastRow(); ss.deleteRows(10, lastrow-1); }; </code></pre>
[ { "answer_id": 74174756, "author": "Rubén", "author_id": 1595451, "author_profile": "https://Stackoverflow.com/users/1595451", "pm_score": 3, "selected": true, "text": "ss.deleteRows(10, lastrow-1);\n" }, { "answer_id": 74175670, "author": "Cooper", "author_id": 7215091, ...
2022/10/23
[ "https://Stackoverflow.com/questions/74174556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19722351/" ]
74,174,562
<p>If I have a list,</p> <pre><code>int[] ints = { 4, 2, 6, 5 }; </code></pre> <p>and I sort the list using <code>Array.Sort(ints)</code>, and I've got another array,</p> <pre><code>int[] i = { 1, 2, 4, 5, 6, 8, 12 }; </code></pre> <p>how do I check that the sorted array, <code>ints</code> is contained within <code>i</code>?</p> <p>If the array has extra elements,</p> <pre><code>int[] ints = { 4, 2, 6, 3, 5 }; </code></pre> <p>that are not part of <code>i</code> then this should return false, unlike with <a href="https://stackoverflow.com/questions/11139419/how-can-we-check-whether-one-array-contains-one-or-more-elements-of-another-arra">this solution</a>:</p> <blockquote> <p>Here is a Linq solution that should give you what you need:</p> <pre><code>names.Any(x =&gt; subnames.Contains(x)) </code></pre> </blockquote>
[ { "answer_id": 74174675, "author": "davidnatro", "author_id": 13100320, "author_profile": "https://Stackoverflow.com/users/13100320", "pm_score": 0, "selected": false, "text": "ints.All(num => i.Contains(num));\n" }, { "answer_id": 74174801, "author": "Tim Schmelter", "au...
2022/10/23
[ "https://Stackoverflow.com/questions/74174562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14903360/" ]
74,174,570
<p>I started to learn React. In wy <code>tsx</code> file I have a function, inside there is a <code>useState</code> method to watch some values. And also there is a <code>watch</code> method to watch another values.</p> <p>What is the difference between <a href="https://react-hook-form.com/api/useform/watch/" rel="nofollow noreferrer">watch</a> and <code>useState</code> in React? I mean, let's say I have to watch a value in a textbox or combobox and react to its changes. What method should I use, <code>watch</code> or <code>useState</code>?</p> <p>Here is the sandbox <a href="https://stackblitz.com/edit/watch-test?file=App.tsx" rel="nofollow noreferrer">StackBlitz</a></p> <pre><code>import * as React from 'react'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import './style.css'; export default function App() { const { watch } = useForm({ mode: 'all', reValidateMode: 'onBlur' }); // this ? const [city, setCity] = useState&lt;string&gt;('Moscow'); // or this ? const wcity = watch('city'); return ( &lt;div&gt; &lt;p&gt;Start editing &amp; look at the console how values changes :&lt;/p&gt; {/* is there a way to watch city changes witout onChange in input:? */} &lt;input value={wcity} defaultValue=&quot;any&quot; /&gt; &lt;br /&gt; &lt;label&gt;{wcity}&lt;/label&gt; &lt;/div&gt; ); } </code></pre> <p>How shoud I use <code>watch</code> or <code>useState</code> to log the changes of <code>city</code> (witout onChange method, if possible) ?</p>
[ { "answer_id": 74175139, "author": "Kartoos", "author_id": 7801965, "author_profile": "https://Stackoverflow.com/users/7801965", "pm_score": 2, "selected": true, "text": "<label>" }, { "answer_id": 74177762, "author": "Putin - The Hero", "author_id": 961631, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74174570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/961631/" ]
74,174,604
<p>Trying to take the odd positions from a vector and merge it with another vector in which I'm taking the even ones. (sorry if this is a bit wordy) This is what I've done so far</p> <pre><code>Numbers = c(10,20,30,40,50,60,70,80,90,100,110,120) x3=c(10,20,30,40,50,60,70,80,90) MV &lt;- function(x) { seq(1,length(x),2) } MV(x3) #[1] 1 3 5 7 9 MV2 &lt;- function(x) { seq(1,length(x),1) } MV2(x3) MV3 &lt;- function(x) { c(MV,MV2) } MV3(x3,Numbers) </code></pre> <p>I got a result I don't understand. I feel like I'm missing something here.</p> <p>I want the function to return the odd position from x3 and the even from Numbers.<br /> The goal would be</p> <pre><code>#[1] 10 20 30 40 50 60 70 80 90 100 120 </code></pre> <p>Sorry if confusing because Numbers and x3 are basically</p>
[ { "answer_id": 74174720, "author": "langtang", "author_id": 4447540, "author_profile": "https://Stackoverflow.com/users/4447540", "pm_score": 0, "selected": false, "text": "library(data.table)\n\nf <- function(o,e) {\n rbind(\n SJ(o)[seq(1,.N,2)][,i:=.I],\n SJ(e)[seq(2,.N,2)][,i:=...
2022/10/23
[ "https://Stackoverflow.com/questions/74174604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20316395/" ]
74,174,606
<p>I have a python dataframe (df) created from a csv. I want to take every column name that contains 'PHONE' (or 'phone' or 'Phone') and change all their rows to be in the format of 5555555555. So:</p> <p>(555) 555-5555 would be 5555555555,</p> <p>555-555-5555 would be 5555555555,</p> <p>and so on.</p> <p>I tried the following, but got a syntax error. Hopefully I was at least kinda-sorta close:</p> <pre><code>phone_format = df.loc[:, df.columns.str.contains('PHONE')] for col in phone_format: df['col'] = df.['col'].map(lambda x: x.replace('.', '').replace(' ', '').replace('-', '').replace('(', '').replace(')', '')) </code></pre>
[ { "answer_id": 74174720, "author": "langtang", "author_id": 4447540, "author_profile": "https://Stackoverflow.com/users/4447540", "pm_score": 0, "selected": false, "text": "library(data.table)\n\nf <- function(o,e) {\n rbind(\n SJ(o)[seq(1,.N,2)][,i:=.I],\n SJ(e)[seq(2,.N,2)][,i:=...
2022/10/23
[ "https://Stackoverflow.com/questions/74174606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7973902/" ]
74,174,622
<p>Is there any way to convert the resulting days into INT without pandas? Or use the number of days to do &quot;for&quot; loop?</p> <pre><code>from datetime import datetime, timedelta d = datetime.today() - timedelta(days=10) date = datetime.today() - d print(date) </code></pre> <p>Result:</p> <pre><code>10 days, 0:00:00 </code></pre> <p>If I try for loop, it doesn't work.</p> <pre><code>for days in range(date): print(&quot;■&quot;) </code></pre> <p>Error:</p> <pre><code>line 16, in &lt;module&gt; for i in range(date): TypeError: 'datetime.timedelta' object cannot be interpreted as an integer </code></pre> <p>Newb, thank you.</p>
[ { "answer_id": 74174687, "author": "29belgrade29", "author_id": 14090120, "author_profile": "https://Stackoverflow.com/users/14090120", "pm_score": -1, "selected": false, "text": "date = date.astype(int)\n" }, { "answer_id": 74174690, "author": "Michael Delgado", "author_...
2022/10/23
[ "https://Stackoverflow.com/questions/74174622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5659859/" ]
74,174,623
<p>i am a little confused on how to generate with the ramdom function in python a list of length 10000 that randomly repeats the same 2 variables. Suppose once the randomly generated list is [a,b,a,a,a,a,b,b....] and the next time it renders [b,a,b,b,a,a,b,b...]. Can anyone help me on this one?</p>
[ { "answer_id": 74174687, "author": "29belgrade29", "author_id": 14090120, "author_profile": "https://Stackoverflow.com/users/14090120", "pm_score": -1, "selected": false, "text": "date = date.astype(int)\n" }, { "answer_id": 74174690, "author": "Michael Delgado", "author_...
2022/10/23
[ "https://Stackoverflow.com/questions/74174623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317066/" ]
74,174,630
<p>In Node, how can I convert a time zone (e.g. <code>Europe/Stockholm</code>) to a UTC offset (e.g. <code>+1</code> or <code>+2</code>), given a specific point in time? <a href="https://tc39.es/proposal-temporal/docs/index.html#Temporal-TimeZone" rel="nofollow noreferrer"><code>Temporal</code></a> seems to be solving this in the future, but until then? Is this possible natively, or do I need something like <a href="https://www.npmjs.com/package/@vvo/tzdb" rel="nofollow noreferrer"><code>tzdb</code></a>?</p>
[ { "answer_id": 74174770, "author": "NeNaD", "author_id": 14389830, "author_profile": "https://Stackoverflow.com/users/14389830", "pm_score": 2, "selected": false, "text": "new Date().toISOString()" }, { "answer_id": 74175100, "author": "Bergi", "author_id": 1048572, "...
2022/10/23
[ "https://Stackoverflow.com/questions/74174630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/849076/" ]
74,174,637
<p>Basic python learning:</p> <p>I am asked to write a program that makes a list of 15 integer entries (size) the user inputs. For each input, the program should give the number of integers remaining to input. In the end, the program should list the 15 entries, and tell the user he is done. With the code below, I get the list and the final report, but can't really figure out how to count down, print the remaining entries, and tell the user he is done.</p> <pre><code>my_list = [] for _ in range(15): try: my_list.append(int(input('Enter size: '))) except ValueError: print('The provided value must be an integer') print(my_list) </code></pre>
[ { "answer_id": 74174682, "author": "Batselot", "author_id": 12277392, "author_profile": "https://Stackoverflow.com/users/12277392", "pm_score": 0, "selected": false, "text": "my_list=[]\nlen_val=15\nval=0\nwhile val<len_val:\n try:\n my_list.append(int(input(\"Enter size:\")))\...
2022/10/23
[ "https://Stackoverflow.com/questions/74174637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20315793/" ]
74,174,649
<p>I'm trying to swap keys and values, and append the keys if the values are duplicated. But When trying to append the result is None.</p> <pre><code>def swap_keys_and_values(d): new_d = {} for k, v in d.items(): if new_d.get(v): print(new_d.get(v), k) print(new_d.get(v).append(k)) new_d[v] = new_d.get(v) new_d[v] = list(k) return new_d print(swap_keys_and_values({'a': 1, 'b': 2, 'c': 1})) </code></pre> <p>['a'] c<br /> None<br /> {1: ['c'], 2: ['b']}</p>
[ { "answer_id": 74174682, "author": "Batselot", "author_id": 12277392, "author_profile": "https://Stackoverflow.com/users/12277392", "pm_score": 0, "selected": false, "text": "my_list=[]\nlen_val=15\nval=0\nwhile val<len_val:\n try:\n my_list.append(int(input(\"Enter size:\")))\...
2022/10/23
[ "https://Stackoverflow.com/questions/74174649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6157686/" ]
74,174,666
<p>I am trying to create an advanced regular expression search application to let me search for some content and replace it in other lines but I am struggling with a much easier task: Cannot delete the rules since the <code>rules</code> state seems to be empty:</p> <pre class="lang-js prettyprint-override"><code>export default function App() { const [displayNewRule, setDisplayNewRule] = useState(false); const [replaceType, setReplaceType] = useState(&quot;line&quot;); const [rules, setRules] = useState([]); function handleClick() { setDisplayNewRule(true); } function handleSubmit(e) { e.preventDefault(); const rule = { name: e.target.name.value, sourceSearchPattern: e.target.sourceSearchPattern.value, replaceType, value: e.target.value.value }; if (replaceType === &quot;occurrence&quot;) { rule.targetSearchPattern = e.target.targetSearchPattern.value; rule.location = e.location.value; } let $rules = rules; $rules.push(rule); setRules($rules); e.target.reset(); handleReset(); } function handleReset() { setDisplayNewRule(false); } function deleteRule(i) { let $rules = rules; $rules.splice(i, 1); setRules($rules); // this gets an empty rules } return ( &lt;div className=&quot;App&quot;&gt; &lt;form onSubmit={handleSubmit} onReset={handleReset} style={{ display: displayNewRule || &quot;none&quot; }} &gt; &lt;h3&gt;Create new rule&lt;/h3&gt; &lt;div className=&quot;input-group&quot;&gt; &lt;label htmlFor=&quot;name&quot;&gt;Name:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot; required /&gt; &lt;/div&gt; &lt;div className=&quot;input-group&quot;&gt; &lt;label htmlFor=&quot;sourceSearchPattern&quot;&gt;Source search pattern:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;sourceSearchPattern&quot; name=&quot;sourceSearchPattern&quot; required /&gt; &lt;/div&gt; &lt;div className=&quot;input-group&quot;&gt; &lt;label htmlFor=&quot;replaceType&quot;&gt;Replace type:&lt;/label&gt; &lt;select id=&quot;replaceType&quot; name=&quot;replaceType&quot; onChange={(e) =&gt; { setReplaceType(e.target.value); }} required &gt; &lt;option value=&quot;&quot;&gt;Select item&lt;/option&gt; &lt;option value=&quot;line&quot;&gt;Replace line&lt;/option&gt; &lt;option value=&quot;occurrence&quot;&gt;Replace occurrence&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; {replaceType === &quot;occurrence&quot; &amp;&amp; ( &lt;div className=&quot;input-group&quot;&gt; &lt;label htmlFor=&quot;targetSearchPattern&quot;&gt;Target search pattern:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;targetSearchPattern&quot; name=&quot;targetSearchPattern&quot; required /&gt; &lt;/div&gt; )} &lt;div className=&quot;input-group&quot;&gt; &lt;label htmlFor=&quot;value&quot;&gt;Value:&lt;/label&gt; &lt;input type=&quot;text&quot; id=&quot;value&quot; name=&quot;value&quot; required /&gt; &lt;/div&gt; {replaceType === &quot;occurrence&quot; &amp;&amp; ( &lt;div className=&quot;input-group&quot;&gt; Occurrence location: &lt;div className=&quot;option-group&quot;&gt; &lt;input type=&quot;radio&quot; id=&quot;next-occurrence&quot; name=&quot;location&quot; value=&quot;next&quot; required /&gt; &lt;label htmlFor=&quot;next-occurrence&quot;&gt;Next occurrence&lt;/label&gt; &lt;/div&gt; &lt;div className=&quot;option-group&quot;&gt; &lt;input type=&quot;radio&quot; id=&quot;previous-occurrence&quot; name=&quot;location&quot; value=&quot;previous&quot; /&gt; &lt;label htmlFor=&quot;previous-occurrence&quot;&gt;Previous occurrence&lt;/label&gt; &lt;/div&gt; &lt;/div&gt; )} &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt; &lt;button type=&quot;reset&quot;&gt;Cancel&lt;/button&gt; &lt;/form&gt; &lt;button onClick={handleClick}&gt;Add rule&lt;/button&gt; &lt;div className=&quot;rules&quot;&gt; &lt;h3&gt;Rules&lt;/h3&gt; {rules.map((rule, i) =&gt; ( // These rules are being displayed. &lt;div className=&quot;rule&quot; key={i + 1}&gt; &lt;h5&gt; {rule.name} &lt;button onClick={() =&gt; { deleteRule(i); }} &gt; Delete rule &lt;/button&gt; &lt;/h5&gt; &lt;p&gt;Replace type: {rule.replaceType}&lt;/p&gt; &lt;p&gt;Source search pattern: {rule.sourceSearchPattern}&lt;/p&gt; &lt;/div&gt; ))} &lt;/div&gt; &lt;/div&gt; ); } </code></pre> <p>Any clues?</p>
[ { "answer_id": 74174786, "author": "Nathan", "author_id": 954986, "author_profile": "https://Stackoverflow.com/users/954986", "pm_score": 3, "selected": true, "text": "let $rules = rules;\n$rules.push(rule);\nsetRules($rules);\n" }, { "answer_id": 74174920, "author": "kind us...
2022/10/23
[ "https://Stackoverflow.com/questions/74174666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6421288/" ]
74,174,701
<p>I am trying to check if the time the user enters is valid or not, so I am receiving the time as a string in this format hh: mm. However, I want to check if the hours and minutes are valid. I was thinking to convert it from string to int and check it but since it is in this format hh: mm I can't do it. Is there any solution for it?</p> <pre><code> // New Scanner to get the time from the user Scanner timeInput = new Scanner(System.in); // Get sunrise + sunset from the user System.out.println(&quot;Enter time of sunrise [hh: mm]&gt; &quot;); String sunrise = timeInput.next(); System.out.println(&quot;Enter time of sunset [hh: mm]&gt; &quot;); String sunset = timeInput.next(); try{ int number = Integer.parseInt(sunrise); System.out.println(number); } catch (NumberFormatException ex){ ex.printStackTrace(); } </code></pre>
[ { "answer_id": 74174918, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 1, "selected": false, "text": "try { LocalTime lt = LocalTime.parse( input ) ; } \ncatch ( DateTimeParseException e ) { … }\n" }, { "an...
2022/10/23
[ "https://Stackoverflow.com/questions/74174701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317121/" ]
74,174,709
<p>Im pretty independent when using oython since i wouldnt consider myself a beginner etc, but Iv been coding up a program that I want to sell. The problem is that I want the program to have a timer on it and when it runs out the program will no longer work. Giving the user a specified amount of time they have to use the program.</p>
[ { "answer_id": 74174918, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 1, "selected": false, "text": "try { LocalTime lt = LocalTime.parse( input ) ; } \ncatch ( DateTimeParseException e ) { … }\n" }, { "an...
2022/10/23
[ "https://Stackoverflow.com/questions/74174709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20317130/" ]
74,174,711
<p>I'm attempting to make the social logos on the same line as the &quot;APKHub&quot; text. I have tried aligning it properly and messed with positionings but nothing has been working. I am unsure why It is like this and I run into this issue a lot and haven't really found a fix. All the code is below and an image aswell. <a href="https://i.stack.imgur.com/hB5qj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hB5qj.png" alt="" /></a></p> <pre><code>&lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt; &lt;script src=&quot;https://kit.fontawesome.com/dd13dde450.js&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt; &lt;!-- Fonts --&gt; &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.googleapis.com&quot;&gt; &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot; crossorigin&gt; &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Roboto&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt; &lt;!-- --&gt; &lt;title&gt;APKHub - Free APK Downloads&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div class=&quot;navbar&quot;&gt; &lt;h1&gt;APKHub&lt;/h1&gt; &lt;div class=&quot;links&quot;&gt; &lt;i class=&quot;fa-brands fa-discord&quot;&gt;&lt;/i&gt; &lt;i class=&quot;fa-brands fa-twitter&quot;&gt;&lt;/i&gt; &lt;i class=&quot;fa-brands fa-telegram&quot;&gt;&lt;/i&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;style&gt; body { margin: 0; padding: 0; background-color: #141523; } .navbar { border-radius: 5px; padding: 10px; background-color: #1d1e31; } .navbar h1 { margin-left: 5px; font-family: 'Roboto', sans-serif; color: white; } .links { text-align:right; } .links i { font-size: 30px; } &lt;/style&gt; &lt;/html&gt;``` </code></pre>
[ { "answer_id": 74174759, "author": "Haim Abeles", "author_id": 15298697, "author_profile": "https://Stackoverflow.com/users/15298697", "pm_score": 1, "selected": true, "text": ".navbar" }, { "answer_id": 74174793, "author": "Artichoke", "author_id": 9966616, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74174711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15194269/" ]
74,174,712
<p>I found a formula for getting the angle between two 3D vectors (e.g. as shown in <a href="https://stackoverflow.com/a/12230083/6607497">https://stackoverflow.com/a/12230083/6607497</a>).</p> <p>However when trying to implement it in PostScript I realized that PostScript lacks the arcus cosinus function needed to get the angle.</p> <p>Why doesn't PostScript have that function and how would a work-around look like?</p> <p>In <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Relationships_between_trigonometric_functions_and_inverse_trigonometric_functions" rel="nofollow noreferrer">Wikipedia</a> I found the formula <code>$\arccos(x)={\frac {\pi }{2}}-\arctan \left({\frac {x}{\sqrt {1-x^{2}}}}\right)}$</code>, but that looks a bit complicated; and if it's not: Why didn't they add <code>acos</code> (arcus cosinus) using that definition?</p> <p>Did I miss something obvious?</p>
[ { "answer_id": 74174759, "author": "Haim Abeles", "author_id": 15298697, "author_profile": "https://Stackoverflow.com/users/15298697", "pm_score": 1, "selected": true, "text": ".navbar" }, { "answer_id": 74174793, "author": "Artichoke", "author_id": 9966616, "author_p...
2022/10/23
[ "https://Stackoverflow.com/questions/74174712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6607497/" ]