qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,295,985
<p>I need to get nasapower data with use rpy. In documentation r code works in this way:</p> <pre><code>library(&quot;nasapower&quot;) daily_ag &lt;- get_power(community = &quot;ag&quot;, lonlat = c(151.81, -27.48), pars = c(&quot;RH2M&quot;, &quot;T2M&quot;, &quot;PRECTOTCORR&quot;), dates = &quot;1985-01-01&quot;, temporal_api = &quot;daily&quot; ) </code></pre> <p>I try to do this thing in rpy:</p> <pre><code>!pip3 install rpy2==3.5.1 import rpy2 import rpy2.robjects as robjects from rpy2.robjects.packages import importr, data utils = importr('utils') base = importr('base') utils.chooseCRANmirror(ind=1) utils.install_packages('nasapower') nasapower = importr('nasapower') nasapower.get_power(&quot;ag&quot;, lonlat=[151.81, -27.48], pars=[&quot;RH2M&quot;, &quot;T2M&quot;, &quot;PRECTOTCORR&quot;], dates=&quot;1985-01-01&quot;, temporal_api = &quot;daily&quot; ) </code></pre> <p>and I got the error:</p> <pre><code>RRuntimeError: Error: You have entered an invalid value for `lonlat`. Valid values are `global` with `climatology` or a string of lon and lat values. </code></pre> <p>How should I solve my problem?</p>
[ { "answer_id": 74296144, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 0, "selected": false, "text": "KeysOfType" }, { "answer_id": 74296203, "author": "Daniel Rodríguez Meza", "author_id": 6032155, "author_profile": "https://Stackoverflow.com/users/6032155", "pm_score": 3, "selected": true, "text": "type RemoveNonArrayKeys<T> = keyof {\n [K in keyof T as T[K] extends unknown[] ? K : never]: T[K];\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74295985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10337789/" ]
74,296,022
<p>I executed the following command in utop with Jane street Base library installed</p> <pre><code>open Base;; List.fold;; </code></pre> <p>It prints</p> <pre><code>- : 'a list -&gt; init:'accum -&gt; f:('accum -&gt; 'a -&gt; 'accum) -&gt; 'accum = &lt;fun&gt; </code></pre> <p>I interpret this as the fold function first parameter is a list of values. second is the initial value and 3rd is the fold function. The folder function whose first parameter is the accumulator and second parameter is the item from the list being folded.</p> <p>With this interpretation I write this code</p> <pre><code>List.fold [Some 1; None; None; Some 2] 0 (fun accm x -&gt; match x with | None -&gt; accum | Some x -&gt; accum + x) </code></pre> <p>This doesn't work and it prints something weird on the screen</p> <pre><code>- : init:(int -&gt; (int -&gt; int option -&gt; int) -&gt; '_weak2) -&gt; f:((int -&gt; (int -&gt; int option -&gt; int) -&gt; '_weak2) -&gt; int option -&gt; int -&gt; (int -&gt; int option -&gt; int) -&gt; '_weak2) -&gt; '_weak2 = &lt;fun&gt; </code></pre> <p>Now If I change my code in utop to use named parameters</p> <pre><code>List.fold [Some 1; None; Some 2] ~init:0 ~f:(fun accum x -&gt; match x with | None -&gt; accum | Some x -&gt; accum + x);; </code></pre> <p>Now it works. What's going on? I passed the parameters in the same order as the documented signature suggested? then why am I being forced to use named parameters?</p>
[ { "answer_id": 74296333, "author": "Chris", "author_id": 15261315, "author_profile": "https://Stackoverflow.com/users/15261315", "pm_score": 2, "selected": false, "text": "List.fold [Some 1; None; None; Some 2] 0 (fun accm x -> match x with | None -> accum | Some x -> accum + x)\n" }, { "answer_id": 74299588, "author": "octachron", "author_id": 7369366, "author_profile": "https://Stackoverflow.com/users/7369366", "pm_score": 3, "selected": true, "text": "fold" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296022", "https://Stackoverflow.com", "https://Stackoverflow.com/users/337134/" ]
74,296,047
<p>I know there are already questions about this, but my case is different and I don't know how to do it.</p> <p>In my tibble there are a column &quot;values&quot; with a value for each observation, &quot;ind&quot; that divides the observations in two groups of equal size, and &quot;average_time&quot; that contatins the average of the group to which the observation belongs.</p> <p>This is the code I wrote to get the graph:</p> <pre><code>my_data %&gt;% ggplot(aes(values, x=ind, fill=ind)) + geom_bar(stat=&quot;summary&quot;, fun=mean) + theme_minimal() + theme(legend.position=&quot;none&quot;) </code></pre> <p>And I get this graph: <a href="https://i.stack.imgur.com/NYn2g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NYn2g.png" alt="enter image description here" /></a></p> <p>Now I want to change the categories at the bottom of each bar from part1 and part2 to &quot;Group 1&quot; and &quot;Group 2&quot;, but I can't find a way to do it.</p> <p>Also, I want to add the average values in the bars. In other words, I want to display the value of each bar in white inside of the bar, something like this: <a href="https://i.stack.imgur.com/0H5fS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0H5fS.png" alt="enter image description here" /></a></p> <p>Can anyone help me with this?</p>
[ { "answer_id": 74296333, "author": "Chris", "author_id": 15261315, "author_profile": "https://Stackoverflow.com/users/15261315", "pm_score": 2, "selected": false, "text": "List.fold [Some 1; None; None; Some 2] 0 (fun accm x -> match x with | None -> accum | Some x -> accum + x)\n" }, { "answer_id": 74299588, "author": "octachron", "author_id": 7369366, "author_profile": "https://Stackoverflow.com/users/7369366", "pm_score": 3, "selected": true, "text": "fold" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20323895/" ]
74,296,049
<p>PROBLEM ::: I want to create a lazy column where I can select or deselect only one option at a time. Right now, whenever I click on row component inside lazy column, all the rows get selected.</p> <p>CODE :::</p> <pre><code>@Composable fun LazyColumnWithSelection() { var isSelected by remember { mutableStateOf(false) } var selectedIndex by remember { mutableStateOf(0) } val onItemClick = { index: Int -&gt; selectedIndex = index } LazyColumn( modifier = Modifier.fillMaxSize(), ) { items(100) { index -&gt; Row(modifier = Modifier .fillMaxWidth() .clickable { onItemClick.invoke(index) if (selectedIndex == index) { isSelected = !isSelected } } .padding(16.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Text(text = &quot;Item $index&quot;, modifier = Modifier.padding(12.dp), color = Color.White) if (isSelected) { Icon(imageVector = Icons.Default.Check, contentDescription = &quot;Selected&quot;, tint = Color.Green, modifier = Modifier.size(20.dp)) } } } } } </code></pre> <p>CURRENT RESULT :::</p> <p>Before Clicking -&gt;</p> <p><a href="https://i.stack.imgur.com/hYSkt.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hYSkt.jpg" alt="Before Clicking" /></a></p> <p>After Clicking -&gt;</p> <p><a href="https://i.stack.imgur.com/7fOKZ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/7fOKZ.jpg" alt="After Clicking" /></a></p> <p>You can see all the items are getting selected but I should be able to select or deselect one item at a time not all.</p> <p>I tried to use remember state for selection but I think I'm doing wrong something in the index selection or maybe if statement.</p>
[ { "answer_id": 74299123, "author": "z.y", "author_id": 19023745, "author_profile": "https://Stackoverflow.com/users/19023745", "pm_score": 4, "selected": true, "text": "4" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18476530/" ]
74,296,057
<p>I am new to coding. I would like to attend a course but there are assessments first in order to be chosen.</p> <p>The question I am stuck on is:</p> <blockquote> <p>Write a program that always asks the user to enter a number. When the user enters the negative number -1, the program should stop requesting the user to enter a number. The program must then calculate the average of the numbers entered excluding the -1.</p> </blockquote> <pre><code>num = 0 inputs = [] while True: num = int(input(&quot;Please enter a number between -1 and 5: &quot;)) if num &gt; -1: break else: inputs.append(int(num)) print (sum(inputs) / len(inputs)) </code></pre>
[ { "answer_id": 74296127, "author": "m2r105", "author_id": 18164421, "author_profile": "https://Stackoverflow.com/users/18164421", "pm_score": 1, "selected": false, "text": "if num > -1" }, { "answer_id": 74296198, "author": "Devin Sag", "author_id": 20388932, "author_profile": "https://Stackoverflow.com/users/20388932", "pm_score": 2, "selected": false, "text": "num = 0\ninputs = []\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402016/" ]
74,296,072
<p>This might be a dumb and simple question, but since I am a completely newbie I could not find a workaround.</p> <p>Lets say I have these users in the DB :</p> <p>Me with maxScore : 4 John with maxScore: 3 Doe with maxScore: 9 Ana with maxScore: 12 Bob with maxScore: 1</p> <p>I would like to get &quot;3&quot; as a result since after ordering the users, &quot;Me&quot; is the third one with 4 maxScore. BUT if the app has lets say 2000 users, I want to get the ranking of &quot;Me&quot;, for example 1375.</p> <p>How can I achieve this?</p> <p>thanks in advance</p> <p>I have been able to sort my DB with</p> <pre><code> const usersAround = await prisma.user.findMany({ orderBy: { maxScore: &quot;desc&quot;, }, cursor: { id: myUser.id, }, take: 5, }); </code></pre> <p>But I want to get the index (or the rank) of my user in the ranking of the scores.</p>
[ { "answer_id": 74297659, "author": "Hoàng Huy Khánh", "author_id": 9711476, "author_profile": "https://Stackoverflow.com/users/9711476", "pm_score": 0, "selected": false, "text": "const users = await prisma.user.findMany({\n orderBy: {\n maxScore: \"desc\",\n },\n take: 5,\n});\n\nconst ranking = users.findIndex(user => user.id === myUser.id) + 1\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16692198/" ]
74,296,077
<p>Are there other special literal values besides NULL in SQL / PostgresQL?</p> <p>NULL is nice in that we can interpret NULL as the concept of &quot;nothing&quot; (i.e. missing, not available, not asked, not answered, etc.), and data columns of any type can have NULL values.</p> <p>I would like another value that I can interpret as representing another concept (here the idea of &quot;everything&quot;), in the same result set.</p> <p>Is there another special value that I can return in a query, which like NULL doesn't type conflict?</p> <p>Basically anything that doesn't throw <code> ERROR: For 'UNION', types varchar and numeric are inconsistent</code> in this toy query:</p> <pre class="lang-sql prettyprint-override"><code>select 1 as numeral, 'one' as name UNION ALL select 2 as numeral, 'two' as name UNION ALL select NULL as numeral, NULL as name UNION ALL select -999 as numeral, -999 as name UNION ALL -- type conflict select '?' as numeral, 'x' as name -- type conflict </code></pre> <p>Here,</p> <ul> <li><code>-999</code> doesn't work as its type conflicts with varchar columns</li> <li><code>'~'</code> doesn't work as its type conflicts with numeric columns</li> <li><code>NULL</code> doesn't work as it needs</li> </ul> <p>More specifically here's my actual case, counting combinations of values and also include &quot;Overall&quot; rows in the same query. Generally I won't know or control the types of columns A, B, C in advance. And A, B, or C might also have NULL values which I would would still want to count separately.</p> <pre><code>SELECT A, COUNT(*) FROM table GROUP BY 1 UNION ALL SELECT ?, COUNT(*) FROM table GROUP BY 1 </code></pre> <p>and get a result set like:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>A</th> <th>COUNT</th> </tr> </thead> <tbody> <tr> <td>NULL</td> <td>2</td> </tr> <tr> <td>1</td> <td>3</td> </tr> <tr> <td>2</td> <td>5</td> </tr> <tr> <td>3</td> <td>10</td> </tr> <tr> <td>(all)</td> <td>20</td> </tr> </tbody> </table> </div> <pre><code>SELECT B, COUNT(*) FROM table GROUP BY 1 UNION ALL SELECT ?, COUNT(*) FROM table GROUP BY 1 </code></pre> <p>and get a result set like:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>B</th> <th>COUNT</th> </tr> </thead> <tbody> <tr> <td>NULL</td> <td>2</td> </tr> <tr> <td>'Circle'</td> <td>3</td> </tr> <tr> <td>'Line'</td> <td>5</td> </tr> <tr> <td>'Triangle'</td> <td>10</td> </tr> <tr> <td>(all)</td> <td>20</td> </tr> </tbody> </table> </div>
[ { "answer_id": 74296276, "author": "Ihabe Kaine", "author_id": 20392804, "author_profile": "https://Stackoverflow.com/users/20392804", "pm_score": 2, "selected": true, "text": "CAST" }, { "answer_id": 74312415, "author": "prototype", "author_id": 645715, "author_profile": "https://Stackoverflow.com/users/645715", "pm_score": 0, "selected": false, "text": "ROLLUP" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/645715/" ]
74,296,090
<p>how can i get Arrival Date and Departure Date from string?</p> <p>Guest Name :WOLAK, KAMIL - Arrival Date: 2022-09-29 - Departure Date: 2022-10-06 - Ref: H242806</p> <p>using php</p>
[ { "answer_id": 74296276, "author": "Ihabe Kaine", "author_id": 20392804, "author_profile": "https://Stackoverflow.com/users/20392804", "pm_score": 2, "selected": true, "text": "CAST" }, { "answer_id": 74312415, "author": "prototype", "author_id": 645715, "author_profile": "https://Stackoverflow.com/users/645715", "pm_score": 0, "selected": false, "text": "ROLLUP" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2374735/" ]
74,296,105
<p>This seems like it should be very simple but am not sure the proper syntax in Python. To streamline my code I want a while loop (or for loop if better) to cycle through 9 datasets and use the counter to call each file out using the counter as a way to call on correct file.</p> <p>I would like to use the &quot;i&quot; variable within the while loop so that for each file with sequential names I can get the average of 2 arrays, the max-min of this delta, and the max-min of another array.</p> <p>Example code of what I am trying to do but the avg(i) and calling out temp(i) in loop does not seem proper. Thank you very much for any help and I will continue to look for solutions but am unsure how to best phrase this to search for them.</p> <pre><code>temp1 = pd.read_excel(&quot;/content/113VW.xlsx&quot;) temp2 = pd.read_excel(&quot;/content/113W6.xlsx&quot;) ..-&gt; temp9 i=1 while i&lt;=9 avg(i) =np.mean(np.array([temp(i)['CC_H='],temp(i)['CC_V=']]),axis=0) Delta(i)=(np.max(avg(i)))-(np.min(avg(i))) deltaT(i)=(np.max(temp(i)['temperature='])-np.min(temp(i)['temperature='])) i+= 1 </code></pre> <p>EG: The slow method would be repeating code this for each file</p> <pre><code>avg1 =np.mean(np.array([temp1['CC_H='],temp1['CC_V=']]),axis=0) Delta1=(np.max(avg1))-(np.min(avg1)) deltaT1=(np.max(temp1['temperature='])-np.min(temp1['temperature='])) avg2 =np.mean(np.array([temp2['CC_H='],temp2['CC_V=']]),axis=0) Delta2=(np.max(avg2))-(np.min(avg2)) deltaT2=(np.max(temp2['temperature='])-np.min(temp2['temperature='])) </code></pre> <p>......</p>
[ { "answer_id": 74296170, "author": "Tim Roberts", "author_id": 1883316, "author_profile": "https://Stackoverflow.com/users/1883316", "pm_score": 2, "selected": true, "text": "temps = []\nfor name in ('113VW','113W6',...):\n temps.append( pd.read_excel(f\"/content/{name}.xlsx\") )\n\navg = []\nDelta = []\ndeltaT = []\nfor data in temps:\n avg.append(np.mean(np.array([data['CC_H='],data['CC_V=']]),axis=0) \n Delta.append(np.max(avg[-1]))-(np.min(avg[-1]))\n deltaT.append((np.max(data['temperature='])-np.min(data['temperature=']))\n" }, { "answer_id": 74296320, "author": "Vini", "author_id": 98044, "author_profile": "https://Stackoverflow.com/users/98044", "pm_score": 0, "selected": false, "text": "i" }, { "answer_id": 74296346, "author": "ScottC", "author_id": 20174226, "author_profile": "https://Stackoverflow.com/users/20174226", "pm_score": 1, "selected": false, "text": "import pandas as pd\n\n# Place the files to read into this list\nfiles_to_read = [\"/content/113VW.xlsx\", \"/content/113W6.xlsx\"]\n\nresults = []\nfor i, filename in enumerate(files_to_read):\n temp = pd.read_excel(filename)\n avg_val =np.mean(np.array([temp(i)['CC_H='],temp['CC_V=']]),axis=0) \n Delta=(np.max(avg_val))-(np.min(avg_val))\n deltaT=(np.max(temp['temperature='])-np.min(temp['temperature=']))\n results.append({\"avg\":avg_val, \"Delta\":Delta, \"deltaT\":deltaT})\n\n# Create a dataframe to show the results \ndf = pd.DataFrame(results)\nprint(df)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402013/" ]
74,296,120
<p>from an accessibility point of view: is it o.k to close a cite tag with a footer tag inside the blockquote like it is shown in this example <a href="https://www.thewebmaster.com/html/tags/examples/blockquote/blockquote-tag-footer-element/" rel="nofollow noreferrer">https://www.thewebmaster.com/html/tags/examples/blockquote/blockquote-tag-footer-element/</a> or maybe 'figcaption' is more recommended? What way is the most suitable for accessibility and screen readers when creating blockquote?</p> <p>I've been looking at many articles and found them contradict each other and not clear enough</p>
[ { "answer_id": 74296170, "author": "Tim Roberts", "author_id": 1883316, "author_profile": "https://Stackoverflow.com/users/1883316", "pm_score": 2, "selected": true, "text": "temps = []\nfor name in ('113VW','113W6',...):\n temps.append( pd.read_excel(f\"/content/{name}.xlsx\") )\n\navg = []\nDelta = []\ndeltaT = []\nfor data in temps:\n avg.append(np.mean(np.array([data['CC_H='],data['CC_V=']]),axis=0) \n Delta.append(np.max(avg[-1]))-(np.min(avg[-1]))\n deltaT.append((np.max(data['temperature='])-np.min(data['temperature=']))\n" }, { "answer_id": 74296320, "author": "Vini", "author_id": 98044, "author_profile": "https://Stackoverflow.com/users/98044", "pm_score": 0, "selected": false, "text": "i" }, { "answer_id": 74296346, "author": "ScottC", "author_id": 20174226, "author_profile": "https://Stackoverflow.com/users/20174226", "pm_score": 1, "selected": false, "text": "import pandas as pd\n\n# Place the files to read into this list\nfiles_to_read = [\"/content/113VW.xlsx\", \"/content/113W6.xlsx\"]\n\nresults = []\nfor i, filename in enumerate(files_to_read):\n temp = pd.read_excel(filename)\n avg_val =np.mean(np.array([temp(i)['CC_H='],temp['CC_V=']]),axis=0) \n Delta=(np.max(avg_val))-(np.min(avg_val))\n deltaT=(np.max(temp['temperature='])-np.min(temp['temperature=']))\n results.append({\"avg\":avg_val, \"Delta\":Delta, \"deltaT\":deltaT})\n\n# Create a dataframe to show the results \ndf = pd.DataFrame(results)\nprint(df)\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2496394/" ]
74,296,157
<p>I have a data looks like below, I would like to skip 2 rows after max index of certain types (3 and 4). For example, I have two 4s in my table, but I only need to remove 2 rows after the second 4. Same for 3, I only need to remove 2 rows after the third 3.</p> <pre><code>----------------- | grade | type | ----------------- | 93 | 2 | ----------------- | 90 | 2 | ----------------- | 54 | 2 | ----------------- | 36 | 4 | ----------------- | 31 | 4 | ----------------- | 94 | 1 | ----------------- | 57 | 1 | ----------------- | 16 | 3 | ----------------- | 11 | 3 | ----------------- | 12 | 3 | ----------------- | 99 | 1 | ----------------- | 99 | 1 | ----------------- | 9 | 3 | ----------------- | 10 | 3 | ----------------- | 97 | 1 | ----------------- | 96 | 1 | ----------------- </code></pre> <p>The desired output would be:</p> <pre><code>----------------- | grade | type | ----------------- | 93 | 2 | ----------------- | 90 | 2 | ----------------- | 54 | 2 | ----------------- | 36 | 4 | ----------------- | 31 | 4 | ----------------- | 16 | 3 | ----------------- | 11 | 3 | ----------------- | 12 | 3 | ----------------- | 9 | 3 | ----------------- | 10 | 3 | ----------------- </code></pre> <p>Here is the code of my example:</p> <pre><code>data &lt;- data.frame(grade = c(93,90,54,36,31,94,57,16,11,12,99,99,9,10,97,96), type = c(2,2,2,4,4,1,1,3,3,3,1,1,3,3,1,1)) </code></pre> <p>Could anyone give me some hints on how to approach this in R? Thanks a bunch in advance for your help and your time!</p>
[ { "answer_id": 74296266, "author": "thelatemail", "author_id": 496803, "author_profile": "https://Stackoverflow.com/users/496803", "pm_score": 1, "selected": false, "text": "data[-(nrow(data) - match(c(3,4), rev(data$type)) + 1 + rep(1:2, each=2)),]\n# grade type\n#1 93 2\n#2 90 2\n#3 54 2\n#4 36 4\n#5 31 4\n#8 16 3\n#9 11 3\n#10 12 3\n" }, { "answer_id": 74296309, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 2, "selected": false, "text": "data[-c(max(which(data$type==3))+1:2,max(which(data$type==4))+1:2),]\n\n# grade type\n# 1 93 2\n# 2 90 2\n# 3 54 2\n# 4 36 4\n# 5 31 4\n# 8 16 3\n# 9 11 3\n# 10 12 3\n" }, { "answer_id": 74296376, "author": "Juan C", "author_id": 9462829, "author_profile": "https://Stackoverflow.com/users/9462829", "pm_score": 0, "selected": false, "text": "idx = data %>% mutate(id = row_number()) %>%\nfilter(type %in% 3:4) %>% group_by(type) %>% filter(id == max(id)) %>% pull(id)\ndata[-c(idx + 1, idx + 2),]\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11617008/" ]
74,296,159
<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).ready(function(){ var imgURLs = [ 'https://www.google.com.ua/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png', "https://s.yimg.com/rz/p/yahoo_frontpage_en-US_s_f_p_205x58_frontpage_2x.png" ]; var randomIndex = Math.floor(Math.random() * imgURLs.length); var imgURL = imgURLs[randomIndex]; setTimeout(function(){ lightcase.start({ href: imgURL, // more options like width, height, etc. }); },1000); // 1000 to load it after 1 second from page load });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en" &gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/css/lightcase.css'&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- partial:index.partial.html --&gt; &lt;!-- partial --&gt; &lt;script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'&gt;&lt;/script&gt; &lt;script src='https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/js/lightcase.js'&gt;&lt;/script&gt;&lt;script src="./script.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> </p> <p><a href="https://codepen.io/srga/pen/bMmrOR" rel="nofollow noreferrer">example</a></p> <p>I will add a popup to my website as in the example, but I want to add hyperlinks to the images opened in the js code. For example, when the google image opens, when I click on the image, I want to go to the google.com web page. Please help.</p> <pre><code>I haven't tried yet </code></pre>
[ { "answer_id": 74296381, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": -1, "selected": false, "text": "// Create the container element\nlet container = document.createElement('div');\n// Add your class styles\ncontainer.classList.add('popup-container');\n// Create the link element\nlet link = document.createElement('a');\nlink.src = 'https://example.com';\n// Create the image element\nlet image = document.createElement('img');\nimage.src = './path/to/image.png';\n// Add to DOM\ndocument.body.appendChild(container);\ncontainer.appendChild(link);\nlink.appendChild(image);\n" }, { "answer_id": 74297739, "author": "Markus Lau", "author_id": 13501723, "author_profile": "https://Stackoverflow.com/users/13501723", "pm_score": 0, "selected": false, "text": "<a>" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402070/" ]
74,296,193
<p>I have a ConstraintLayout with an onClickListener so users can tap anywhere on the layout for it to perform its onClickListener action.</p> <p>The problem is, Android does not flag this item as a button. It will say &quot;double tap to activate&quot; but our accessibility team has flagged this as incorrect because screen-reader users need to know the item is a &quot;button&quot; (from the Android tag) to know an item is actionable.</p> <p>In the past, my work-around was to change views to be a button that looks exactly alike. However, this is a lot more difficult in this case because it's a ConstraintView.</p> <p>Does anyone know how to set Accessibility's 'button' flag to 'true' on a ConstraintView? Or on any view?</p> <p><a href="https://i.stack.imgur.com/0LPYJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0LPYJ.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74296381, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": -1, "selected": false, "text": "// Create the container element\nlet container = document.createElement('div');\n// Add your class styles\ncontainer.classList.add('popup-container');\n// Create the link element\nlet link = document.createElement('a');\nlink.src = 'https://example.com';\n// Create the image element\nlet image = document.createElement('img');\nimage.src = './path/to/image.png';\n// Add to DOM\ndocument.body.appendChild(container);\ncontainer.appendChild(link);\nlink.appendChild(image);\n" }, { "answer_id": 74297739, "author": "Markus Lau", "author_id": 13501723, "author_profile": "https://Stackoverflow.com/users/13501723", "pm_score": 0, "selected": false, "text": "<a>" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5526322/" ]
74,296,243
<p>Trying to fetch from the <code>kanye</code> api and I keep getting this error</p> <blockquote> <p>Property &quot;quote&quot; was accessed during render but is not defined on instance.</p> </blockquote> <p>Here's my code <strong>:</strong></p> <pre><code>&lt;template&gt; &lt;div&gt; &lt;i&gt;{{quote}}&lt;/i&gt; &lt;p&gt;Kanye West&lt;/p&gt; &lt;/div&gt; &lt;/template&gt; &lt;script&gt; import axios from 'axios' import { ref } from 'vue' export default { setup() { const quote = ref('') const getQuote = async () =&gt; { const response = await axios.get('https://api.kanye.rest/') quote.value = response.data.quote } getQuote() </code></pre> <p>`</p>
[ { "answer_id": 74296381, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": -1, "selected": false, "text": "// Create the container element\nlet container = document.createElement('div');\n// Add your class styles\ncontainer.classList.add('popup-container');\n// Create the link element\nlet link = document.createElement('a');\nlink.src = 'https://example.com';\n// Create the image element\nlet image = document.createElement('img');\nimage.src = './path/to/image.png';\n// Add to DOM\ndocument.body.appendChild(container);\ncontainer.appendChild(link);\nlink.appendChild(image);\n" }, { "answer_id": 74297739, "author": "Markus Lau", "author_id": 13501723, "author_profile": "https://Stackoverflow.com/users/13501723", "pm_score": 0, "selected": false, "text": "<a>" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17804718/" ]
74,296,295
<p>I receive the above error message in the following code.</p> <pre><code>import 'package:flutter/services.dart'; import 'dart:io'; // for File import 'package:file_picker/file_picker.dart'; // for FilePickerResultfile_picker: ^5.2.2 typedef OnRewardListener = void Function(num quantity, String? uid); typedef SurveyAvailableListener = void Function(int? survey); typedef RewardCenterOpenedListener = void Function(); typedef RewardCenterClosedListener = void Function(); class RapidoReach { static RapidoReach get instance =&gt; _instance; final MethodChannel _channel; static final RapidoReach _instance = RapidoReach.private( const MethodChannel('rapidoreach'), ); RapidoReach.private(MethodChannel channel) : _channel = channel { _channel.setMethodCallHandler(_platformCallHandler); } static OnRewardListener? _onRewardListener; static SurveyAvailableListener? _surveyAvailableListener; static RewardCenterOpenedListener? _rewardCenterOpenedListener; static RewardCenterClosedListener? _rewardCenterClosedListener; Future&lt;void&gt; init({String? apiToken, String? userId}) async { assert(apiToken != null &amp;&amp; apiToken.isNotEmpty); return _channel.invokeMethod( &quot;init&quot;, &lt;String, dynamic&gt;{&quot;api_token&quot;: apiToken, &quot;user_id&quot;: userId}); } Future&lt;void&gt; show({String? placementID}) { return _channel .invokeMethod(&quot;show&quot;, &lt;String, dynamic&gt;{&quot;placementID&quot;: placementID}); } Future _platformCallHandler(MethodCall call) async { debugPrint( &quot;RapidoReach _platformCallHandler call ${call.method} ${call.arguments}&quot;); switch (call.method) { case &quot;onReward&quot;: _onRewardListener!(call.arguments); //Here is the error, in call.arguments break; case &quot;rapidoReachSurveyAvailable&quot;: _surveyAvailableListener!(call.arguments); break; case &quot;onRewardCenterOpened&quot;: _rewardCenterOpenedListener!(); break; case &quot;onRewardCenterClosed&quot;: _rewardCenterClosedListener!(); break; default: debugPrint('Unknown method ${call.method}'); } } void setOnRewardListener(OnRewardListener? onRewardListener) =&gt; _onRewardListener = onRewardListener; void setSurveyAvaiableListener( SurveyAvailableListener? surveyAvailableListener) =&gt; _surveyAvailableListener = surveyAvailableListener; void setRewardCenterOpened( RewardCenterOpenedListener? rewardCenterOpenedListener) =&gt; _rewardCenterOpenedListener = rewardCenterOpenedListener; void setRewardCenterClosed( RewardCenterClosedListener? rewardCenterClosedListener) =&gt; _rewardCenterClosedListener = rewardCenterClosedListener; } </code></pre> <p>What can I do about it?</p>
[ { "answer_id": 74296381, "author": "akpi", "author_id": 20226290, "author_profile": "https://Stackoverflow.com/users/20226290", "pm_score": -1, "selected": false, "text": "// Create the container element\nlet container = document.createElement('div');\n// Add your class styles\ncontainer.classList.add('popup-container');\n// Create the link element\nlet link = document.createElement('a');\nlink.src = 'https://example.com';\n// Create the image element\nlet image = document.createElement('img');\nimage.src = './path/to/image.png';\n// Add to DOM\ndocument.body.appendChild(container);\ncontainer.appendChild(link);\nlink.appendChild(image);\n" }, { "answer_id": 74297739, "author": "Markus Lau", "author_id": 13501723, "author_profile": "https://Stackoverflow.com/users/13501723", "pm_score": 0, "selected": false, "text": "<a>" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20363272/" ]
74,296,316
<p>In Android emulator, entering input using Computer Keyboard, but the &quot;Enter&quot; key on my keyboard should take the input and do the action. Instead, the input is allowing me in the next line, and keep on continuing to the next line (as a new line character). Please suggest me your answers in Android Jetpack Composable of TextField element.</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402168/" ]
74,296,331
<p>I need to assign populations (denominators) to a data frame in R. For each age group and each year, the populations are different. My data frame is</p> <pre><code>Year agegroup count 2000 0-4 24 2000 5-9 36 .... 2021 0-4 42 2021 95+ 132 </code></pre> <p>How can I assign each year and age group (row) a different population?</p> <p>I don't know how to do it, can someone help me? Thanks</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402179/" ]
74,296,385
<p>I have a dataframe that looks something like this:</p> <pre><code> wavelength normalized flux lof 0 5100.00 0.948305 1 1 5100.07 0.796783 1 2 5100.14 0.696425 1 3 5100.21 0.880586 1 4 5100.28 0.836257 1 ... ... ... ... 4281 5399.67 1.076449 1 4282 5399.74 1.038198 1 4283 5399.81 1.004292 1 4284 5399.88 0.946977 1 4285 5399.95 0.894559 1 </code></pre> <p>If <code>lof = -1</code>, I want to replace the normalized flux value with <code>np.nan</code>. Otherwise, just leave the normalized flux value as is. Is there a simple way to do this?</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17163556/" ]
74,296,386
<p>I have set of buttons getting live probability odds of an event for the user to select. The buttons get data from an api every minutes.</p> <p><a href="https://i.stack.imgur.com/uGdld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uGdld.png" alt="Here's how it looks" /></a></p> <p>I want to disable the button if the probability is zero, I have a class <code>suspended</code>, I want to add that class to the button.</p> <p>This is the code I have so far.</p> <p><strong>event.vue</strong></p> <pre><code>&lt;div class=&quot;inply-coupon-odds-column&quot;&gt; &lt;span data-id=&quot;118584087800&quot; class=&quot;bvs-button-multi-sport &quot; clicksource=&quot;in-play&quot;&gt;{{tgames.home_odd }}&lt;/span&gt; &lt;span data-id=&quot;118584088300&quot; class=&quot;bvs-button-multi-sport &quot; clicksource=&quot;in-play&quot;&gt;{{tgames.neutral_odd }}&lt;/span&gt; &lt;span data-id=&quot;118584088000&quot; class=&quot;bvs-button-multi-sport&quot; clicksource=&quot;in-play&quot;&gt;{{tgames.away_odd }}&lt;/span&gt; &lt;/div&gt; </code></pre> <p>This the json response from the api call.</p> <p><code>{&quot;neutral_odd&quot;:&quot;0.00&quot;,&quot;home_odd&quot;:&quot;1.38&quot;,&quot;away_odd&quot;:&quot;2.75&quot;}</code></p> <p>Will appreciate any solutions.</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17985119/" ]
74,296,394
<p>Is there a way to list all instances of tinyMCE on a page?</p> <p>I add tinyMCE dynamically to a page. I would like to run a command to list of all of the instances that have been created on a page.</p> <pre><code> tinyMCE.init({ elements: &quot;field1&quot;, ...tinyMCE_init}); &lt;/script&gt; &lt;textarea name=&quot;field1&quot; id=&quot;field1&quot; cols=&quot;75&quot; rows=&quot;15&quot;&gt;&lt;/textarea&gt; </code></pre> <pre><code> tinyMCE.init({ elements: &quot;familyConsent&quot;, ...tinyMCE_init}); &lt;/script&gt; &lt;textarea name=&quot;field2&quot; id=&quot;field2&quot; cols=&quot;75&quot; rows=&quot;15&quot;&gt;&lt;/textarea&gt; </code></pre> <pre><code> var tinyMCEElementIDs = ????; alert(&quot;tinyMCE Element ID's on page are: &quot; + tinyMCEElementIDs.join()); &lt;/script&gt; </code></pre> <p>I started by collecting the element ID's in an array but I want to dynamically create that array.</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20361510/" ]
74,296,410
<p>I would like to know how I can access only the very first element of an array at my angular template?</p> <p>Currently, this is my situation:</p> <pre><code> &lt;div *ngFor=&quot;let machine of machines&quot;&gt; &lt;span&gt;Released &lt;small&gt;{{ machine.release_date }}&lt;/small&gt;&lt;/span&gt; &lt;/div&gt; </code></pre> <p>this will print the release date 3x times, or the number of element I have in the array, where I only want the first.</p> <p>Thanks in advance</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20334066/" ]
74,296,419
<p>In a typical &quot;regular&quot; git clone, one ends up with <code>.git/config</code> as follows:</p> <pre><code>[remote &quot;origin&quot;] url = git@github.com:orgname/reponame.git fetch = +refs/heads/*:refs/remotes/origin/* </code></pre> <p>and then <code>git show origin/HEAD</code> works fine.</p> <p>However, I don't want all branches to be fetched, only <code>prod</code> and ones prefixed with <code>jakub/</code>, so my <code>.git/config</code> is as follows:</p> <pre><code>[remote &quot;origin&quot;] url = git@github.com:orgname/reponame.git fetch = +refs/heads/prod:refs/remotes/origin/prod fetch = +refs/heads/jakub/*:refs/remotes/origin/jakub/* </code></pre> <p>(I didn't do a <code>git clone</code>, but created a <code>.git/config</code> like above, and then did <code>git fetch</code>).</p> <p>However, with that setup, <code>git show origin/HEAD</code> no longer works:</p> <pre><code>fatal: ambiguous argument 'origin/HEAD': unknown revision or path not in the working tree. </code></pre> <p>I tried to add the following to <code>.git/config</code> but it doesn't work:</p> <pre><code> fetch = +refs/heads/HEAD:refs/remotes/origin/HEAD </code></pre> <pre><code>$ git fetch fatal: couldn't find remote ref refs/heads/HEAD </code></pre> <p>What's the proper way to make <code>origin/HEAD</code> work with partial fetching?</p>
[ { "answer_id": 74296464, "author": "Gabriele Mariotti", "author_id": 2016562, "author_profile": "https://Stackoverflow.com/users/2016562", "pm_score": 2, "selected": false, "text": "singleLine = true" }, { "answer_id": 74304209, "author": "Nikhil Dupally", "author_id": 11692985, "author_profile": "https://Stackoverflow.com/users/11692985", "pm_score": 3, "selected": true, "text": "singleLine = true" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/245966/" ]
74,296,469
<p>I have the following</p> <pre><code>protocol FooPresentable { var bar: BarPresentable { get } } protocol BarPresentable { } class Foo { let bar: Bar } extension Bar: BarPresentable { } extension Foo: FooPresentable { } </code></pre> <p>And I get the error <code>Foo</code> does not conform to <code>FooPresentable</code>. Is it possible to have <code>Foo</code> conform to <code>FooPresentable</code> by just letting the compiler know that all <code>Bar</code>s conform to <code>BarPresentable</code></p>
[ { "answer_id": 74296522, "author": "Jessy", "author_id": 652038, "author_profile": "https://Stackoverflow.com/users/652038", "pm_score": 0, "selected": false, "text": "FooPresentable" }, { "answer_id": 74296524, "author": "lorem ipsum", "author_id": 12738750, "author_profile": "https://Stackoverflow.com/users/12738750", "pm_score": 0, "selected": false, "text": "associatedtype" }, { "answer_id": 74296534, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 2, "selected": false, "text": "bar" }, { "answer_id": 74296570, "author": "cherryblossom", "author_id": 8289918, "author_profile": "https://Stackoverflow.com/users/8289918", "pm_score": 2, "selected": false, "text": "protocol FooPresentable {\n var bar: BarPresentable { get }\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1327778/" ]
74,296,474
<p>I try to use PCA to reduce the dimension of my data before applying K-means clustering.</p> <p>In the below dataset, I have points, assists and rebounds columns. According to the plot, the first three principal component contains the highest % of the variance.</p> <p>Is there a way to tell what each of the first 3 components correspond to? For example, if it corresponds to the column &quot;points&quot; in the year of 2021 or so. Or, what should be the correct way to interpret this plot?</p> <pre><code>import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import KMeans from sklearn.preprocessing import StandardScaler from sklearn.decomposition import PCA df_full = pd.DataFrame({'year':[2021,2021,2021,2021,2021,2021,2021,2021,2021,2021, 2022,2022,2022,2022,2022,2022,2022,2022,2022,2022], 'store':['store1','store2','store3','store4','store5','store6','store7','store8','store9','store10', 'store1','store2','store3','store4','store5','store6','store7','store8','store9','store10'], 'points': [18, 33, 19, 14, 14, 11, 20, 28, 30, 31, 35, 33, 29, 25, 25, 27, 29, 30, 19, 23], 'assists': [3, 3, 4, 5, 4, 7, 8, 7, 6, 9, 12, 14, 5, 9, 4, 3, 4, 12, 15, 11], 'rebounds': [15, 14, 14, 10, 8, 14, 13, 9, 5, 4, 11, 6, 5, 5, 3, 8, 12, 7, 6, 5]}) # create pivot table for clustering analysis df = df_full.pivot(index=['store'],columns=['year']).reset_index() # set index for clustering analysis df.set_index(['store'], inplace=True) # standarized df scaled_df = StandardScaler().fit_transform(df) # check what is the best n components pca = PCA(n_components=6) pca.fit(scaled_df) var = pca.explained_variance_ratio_ plt.bar(list(range(var.shape[0])),var) feature = range(pca.n_components_) plt.xlabel('PCA features') plt.ylabel('variance %') plt.xticks(feature) # use optimized number for n componets which is 3 in this case pca = PCA(n_components=3) pca.fit(scaled_df) df_transform = pca.transform(scaled_df) # apply kmean cluster kmeans = KMeans(init=&quot;random&quot;, n_clusters=3, n_init=10, random_state=1) </code></pre> <p><a href="https://i.stack.imgur.com/6hopx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6hopx.png" alt="enter image description here" /></a></p> <pre><code>pca.components_ array([[ 0.35130535, -0.50070859, 0.29700875, 0.26964774, -0.59032958, -0.34126579], [ 0.56248993, 0.3654443 , -0.30040924, 0.65744874, 0.09535234, 0.13593718], [ 0.18181155, 0.05593549, 0.69079082, -0.0149547 , -0.00170045, 0.69742189]]) </code></pre>
[ { "answer_id": 74296802, "author": "tierriminator", "author_id": 7531433, "author_profile": "https://Stackoverflow.com/users/7531433", "pm_score": 3, "selected": true, "text": "pca.components_" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296474", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13046093/" ]
74,296,490
<p>This seems to be a very simple question, but I haven't got a clue from the documentation. The code creates a <code>PathBuf</code> from <code>&amp;PathBuf</code>. I wonder what makes this possible. The documentation has an <a href="https://doc.rust-lang.org/std/string/struct.String.html#impl-From%3C%26String%3E-for-String" rel="nofollow noreferrer">implementation</a> that creates a <code>String</code> from <code>&amp;String</code>, but doesn't have one such implementation for <code>PathBuf</code>? What's happening behind the scene? And what tools/methods can help me debug/investigate?</p> <pre><code>fn main() { let a = std::path::PathBuf::from(&quot;&quot;); let b = std::path::PathBuf::from(&amp;a); } </code></pre>
[ { "answer_id": 74296802, "author": "tierriminator", "author_id": 7531433, "author_profile": "https://Stackoverflow.com/users/7531433", "pm_score": 3, "selected": true, "text": "pca.components_" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20312298/" ]
74,296,600
<p>Im attempting to add the number 128 to each line in column 6 of my file below_zn.pdb that contains 128 lines, and 12 columns separated by spaces, not tab delimited. When I use</p> <pre><code>awk '{ $6+=128; print }' below_zn.pdb </code></pre> <p>I am able to add 128 to column 6, but the formatting of my file changes. My output looks as follows:</p> <pre><code>ATOM 1 ZN ZN2 H 129 -13.264 34.400 10.700 1.00 0.00 HETA ATOM 2 ZN ZN2 H 130 -13.264 25.273 10.700 1.00 0.00 HETA ATOM 3 ZN ZN2 H 131 -13.264 43.527 10.700 1.00 0.00 HETA ATOM 4 ZN ZN2 H 132 -13.264 52.654 10.700 1.00 0.00 HETA ATOM 5 ZN ZN2 H 133 -13.175 29.836 14.467 1.00 0.00 HETA ATOM 6 ZN ZN2 H 134 -13.175 38.963 14.467 1.00 0.00 HETA ATOM 7 ZN ZN2 H 135 -13.175 48.090 14.467 1.00 0.00 HETA ATOM 8 ZN ZN2 H 136 -13.175 57.217 14.467 1.00 0.00 HETA ATOM 9 ZN ZN2 H 137 -10.679 34.400 -15.527 1.00 0.00 HETA ATOM 10 ZN ZN2 H 138 -10.679 25.273 -15.527 1.00 0.00 HETA ATOM 11 ZN ZN2 H 139 -10.679 43.527 -15.527 1.00 0.00 HETA ATOM 12 ZN ZN2 H 140 -10.679 52.654 -15.527 1.00 0.00 HETA ATOM 13 ZN ZN2 H 141 -10.590 29.836 -11.760 1.00 0.00 HETA ATOM 14 ZN ZN2 H 142 -10.590 38.963 -11.760 1.00 0.00 HETA ATOM 15 ZN ZN2 H 143 -10.590 48.090 -11.760 1.00 0.00 HETA ATOM 16 ZN ZN2 H 144 -10.590 57.217 -11.760 1.00 0.00 HETA ATOM 17 ZN ZN2 H 145 -9.288 34.400 1.958 1.00 0.00 HETA ATOM 18 ZN ZN2 H 146 -9.288 25.273 1.958 1.00 0.00 HETA ATOM 19 ZN ZN2 H 147 -9.288 43.527 1.958 1.00 0.00 HETA ATOM 20 ZN ZN2 H 148 -9.288 52.654 1.958 1.00 0.00 HETA </code></pre> <p>I need to keep the formatting for my file to be useful. I have tried</p> <pre><code>awk -F'()' '{ $6+=128; print }' below_zn.pdb </code></pre> <p>but instead of adding the number 128 to all lines of column 6, I am seeing a new column at the farthest right made of the number 128 repeatedly. As seen below:</p> <pre><code>ATOM 1 ZN ZN2 H 1 -13.264 34.400 10.700 1.00 0.00 HETA 128 ATOM 2 ZN ZN2 H 2 -13.264 25.273 10.700 1.00 0.00 HETA 128 ATOM 3 ZN ZN2 H 3 -13.264 43.527 10.700 1.00 0.00 HETA 128 ATOM 4 ZN ZN2 H 4 -13.264 52.654 10.700 1.00 0.00 HETA 128 ATOM 5 ZN ZN2 H 5 -13.175 29.836 14.467 1.00 0.00 HETA 128 ATOM 6 ZN ZN2 H 6 -13.175 38.963 14.467 1.00 0.00 HETA 128 </code></pre> <p>Is there a way I can use <code>awk/sed/grep</code> or any other command in linux to add 128 to my numbers in column 6 while keeping the formatting as follows:</p> <pre><code>ATOM 1 ZN ZN2 H 1 -13.264 34.400 10.700 1.00 0.00 HETA ATOM 2 ZN ZN2 H 2 -13.264 25.273 10.700 1.00 0.00 HETA ATOM 3 ZN ZN2 H 3 -13.264 43.527 10.700 1.00 0.00 HETA ATOM 4 ZN ZN2 H 4 -13.264 52.654 10.700 1.00 0.00 HETA ATOM 5 ZN ZN2 H 5 -13.175 29.836 14.467 1.00 0.00 HETA ATOM 6 ZN ZN2 H 6 -13.175 38.963 14.467 1.00 0.00 HETA ATOM 7 ZN ZN2 H 7 -13.175 48.090 14.467 1.00 0.00 HETA ATOM 8 ZN ZN2 H 8 -13.175 57.217 14.467 1.00 0.00 HETA ATOM 9 ZN ZN2 H 9 -10.679 34.400 -15.527 1.00 0.00 HETA ATOM 10 ZN ZN2 H 10 -10.679 25.273 -15.527 1.00 0.00 HETA ATOM 11 ZN ZN2 H 11 -10.679 43.527 -15.527 1.00 0.00 HETA ATOM 12 ZN ZN2 H 12 -10.679 52.654 -15.527 1.00 0.00 HETA ATOM 13 ZN ZN2 H 13 -10.590 29.836 -11.760 1.00 0.00 HETA ATOM 14 ZN ZN2 H 14 -10.590 38.963 -11.760 1.00 0.00 HETA ATOM 15 ZN ZN2 H 15 -10.590 48.090 -11.760 1.00 0.00 HETA ATOM 16 ZN ZN2 H 16 -10.590 57.217 -11.760 1.00 0.00 HETA ATOM 17 ZN ZN2 H 17 -9.288 34.400 1.958 1.00 0.00 HETA ATOM 18 ZN ZN2 H 18 -9.288 25.273 1.958 1.00 0.00 HETA ATOM 19 ZN ZN2 H 19 -9.288 43.527 1.958 1.00 0.00 HETA ATOM 20 ZN ZN2 H 20 -9.288 52.654 1.958 1.00 0.00 HETA . . . </code></pre> <p>An important note is that column 7 through 9 can have up to 7 characters (whole number with a period followed by the decimal), and there is one space separating the columns. My file has the following format column 1 - 4 characters 1 space column 2 - 1 character 1 space column 3 - 2 characters 1 space column 4 - 1 character 1 space column 5 - 3 characters 1 space column 6 - 1,2,or 3 characters 5 spaces column 7 - up to 7 characters 1 space column 8 - up to 7 characters 1 space column 9 - up to 7 characters 2 spaces column 10 - 4 characters 2 spaces column 11 - 4 characters 6 spaces column 12 - 4 characters end of file</p> <p>Thank you!</p>
[ { "answer_id": 74296968, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 1, "selected": false, "text": "$ cat below_zn.pdb\nATOM 1 ZN ZN2 H 1 -13.264 34.400 10.700 1.00 0.00 HETA\nATOM 2 ZN ZN2 H 2 -13.264 25.273 10.700 1.00 0.00 HETA\nATOM 3 ZN ZN2 H 3 -13.264 43.527 10.700 1.00 0.00 HETA\nATOM 4 ZN ZN2 H 4 -13.264 52.654 10.700 1.00 0.00 HETA\nATOM 5 ZN ZN2 H 5 -13.175 29.836 14.467 1.00 0.00 HETA\nBUBBLE 206 ZN ZN2 H 7000 -13.175 29.836 14.467 1.00 0.00 HETA-HETA\n" }, { "answer_id": 74300918, "author": "Daweo", "author_id": 10785975, "author_profile": "https://Stackoverflow.com/users/10785975", "pm_score": 0, "selected": false, "text": "AWK" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19619903/" ]
74,296,626
<p>I would like to extract everything that comes before a number using regex.</p> <p>The dataframe below shows an example of what I want to do.</p> <p>I want to extract everything that comes before the first number in the <code>product_name</code> column. The <code>output</code> column is what I want to get.</p> <p>Thank you in advance!</p> <pre><code>product_name = ['Cashew Alm Classic 6/200g', 'Cashew Buttery Sprd 8/227g', 'Chives&amp;Garlic 6/98g'] output = ['Cashew Alm Classic', 'Cashew Butter Sprd', 'Chives&amp;Garlic'] data = pd.DataFrame(list(zip(product_name, output)), columns=['product_name', 'output']) data </code></pre> <p><a href="https://i.stack.imgur.com/YAEwY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YAEwY.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74296654, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": true, "text": "\ndf['output2']=df['product_name'].str.extract(r'(.*?)\\s(?=\\d)')\ndf\n\n#(.*?) : non-greedy capture everything\n# \\s: prior to space\n# (?=\\d) prior to a digit - positive lookahead\n" }, { "answer_id": 74296662, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 0, "selected": false, "text": "data[\"output_new\"] = data[\"product_name\"].str.extract(r\"^(\\D+)\\s+\")\nprint(data)\n" }, { "answer_id": 74296696, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 2, "selected": false, "text": "str.replace" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14294794/" ]
74,296,688
<p>Suppose I have this tibble with an arbitrary number of variable pairs x and x_var, y and y_var, etc.</p> <pre><code>dt &lt;- tibble(x = 1:3, y = 2:4, z = 3:5, x_var = rep(0.1, 3), y_var = rep(0.2, 3), z_var = rep(0.3, 3)) </code></pre> <p>I was attempting to calculate x + x_var, y + y_var, etc all in one go, using mutate-across.</p> <p>I tried</p> <pre><code>tb %&gt;% mutate(across(.cols = all_of(c(&quot;x&quot;, &quot;y&quot;, &quot;z&quot;)), .names = &quot;{col}_sum&quot;, function(x) x + !!rlang::sym(paste0(cur_column(), &quot;_var&quot;)))) </code></pre> <p>but this does not seem to work. I do not want to hard-code variable names and see that it can be done via pivoting, however I'm curious if mutate-across will do the trick somehow.</p>
[ { "answer_id": 74296654, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": true, "text": "\ndf['output2']=df['product_name'].str.extract(r'(.*?)\\s(?=\\d)')\ndf\n\n#(.*?) : non-greedy capture everything\n# \\s: prior to space\n# (?=\\d) prior to a digit - positive lookahead\n" }, { "answer_id": 74296662, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 0, "selected": false, "text": "data[\"output_new\"] = data[\"product_name\"].str.extract(r\"^(\\D+)\\s+\")\nprint(data)\n" }, { "answer_id": 74296696, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 2, "selected": false, "text": "str.replace" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12431771/" ]
74,296,700
<p>I am following a tutorial on breakout game written in rust and I have simple data structure representing balls on the screen:</p> <pre><code>pub struct Ball { rect: Rect, vel: Vec2, } </code></pre> <p>It is stored in vector</p> <pre><code>let mut balls: Vec&lt;Ball&gt; = Vec::new(); </code></pre> <p>However when I try to calculate ball to ball collision I encounter error:</p> <pre><code> --&gt; src/main.rs:193:31 | 192 | for ball in balls.iter_mut() { | ---------------- | | | first mutable borrow occurs here | first borrow later used here 193 | for other_ball in balls.iter_mut() { | ^^^^^^^^^^^^^^^^ second mutable borrow occurs here </code></pre> <pre><code>// ball collision with balls for ball in balls.iter_mut() { for other_ball in balls.iter_mut() { if ball != other_ball { resolve_collision(&amp;mut ball.rect, &amp;mut ball.vel, &amp;other_ball.rect); } } } </code></pre> <p>My initial approach was to use double iteration, now I know that borrow checker wont allow me to modify vector as it is considered unsafe. Is there a common pattern that I could use to solve this kind of issues?</p>
[ { "answer_id": 74296654, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": true, "text": "\ndf['output2']=df['product_name'].str.extract(r'(.*?)\\s(?=\\d)')\ndf\n\n#(.*?) : non-greedy capture everything\n# \\s: prior to space\n# (?=\\d) prior to a digit - positive lookahead\n" }, { "answer_id": 74296662, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 0, "selected": false, "text": "data[\"output_new\"] = data[\"product_name\"].str.extract(r\"^(\\D+)\\s+\")\nprint(data)\n" }, { "answer_id": 74296696, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 2, "selected": false, "text": "str.replace" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296700", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5904368/" ]
74,296,722
<p>Here is my code:</p> <pre><code>def del_rep_vow(s): ''' &gt;&gt;&gt; del_rep_vow('adaptation') 'adpttion' &gt;&gt;&gt; del_rep_vow('repetitions') 'reptitons' &gt;&gt;&gt; del_rep_vow('kingkong') 'kingkong' &gt;&gt;&gt; del_rep_vow('aeiouaeiou') 'aeiou' ''' final_list = [] for i in s: if i not in final_list: final_list.append(i) return ''.join(final_list) if __name__ == &quot;__main__&quot;: import doctest doctest.testmod(verbose=True) </code></pre> <p>I don't know how to make the restriction that only repeated vowels have to be deleted once they are in the list. Any help will be very welcome.</p> <p>Output of 'adaptation' must be 'adpttion', for example.</p>
[ { "answer_id": 74296768, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 3, "selected": true, "text": "def del_rep_vow(s):\n vowels_seen = set()\n final_list = []\n for i in s:\n if i in ['a', 'e', 'i', 'o', 'u']:\n if i not in vowels_seen:\n final_list.append(i)\n vowels_seen.add(i)\n else:\n final_list.append(i)\n\n return ''.join(final_list)\n\nprint(del_rep_vow('adaptation')) # 'adpttion'\nprint(del_rep_vow('repetitions')) # 'reptitons'\nprint(del_rep_vow('kingkong')) # 'kingkong'\nprint(del_rep_vow('aeiouaeiou')) # 'aeiou'\n" }, { "answer_id": 74296776, "author": "Rodrigo Rodrigues", "author_id": 2938526, "author_profile": "https://Stackoverflow.com/users/2938526", "pm_score": 0, "selected": false, "text": "vowels = []\nremaining = []\nfor c in s:\n if c in 'aeiou':\n if c in vowels:\n continue\n vowels.append(c)\n remaining.append(c)\n" }, { "answer_id": 74296806, "author": "itprorh66", "author_id": 14249087, "author_profile": "https://Stackoverflow.com/users/14249087", "pm_score": 0, "selected": false, "text": "def del_repts(x):\n vowels = 'aeiou'\n foundVowels = ''\n rslt = ''\n for c in x:\n if c in vowels:\n if c not in foundVowels:\n rslt += c\n foundVowels += c\n else:\n rslt += c\n return rslt \n\ninl = ['adaptation', 'repetitions', 'kingkong', 'aeiouaeiou']\nfor itm in inl:\n print(f'{itm}\\t->\\t{del_repts(itm)}' ) \n" }, { "answer_id": 74296828, "author": "Grismar", "author_id": 4390160, "author_profile": "https://Stackoverflow.com/users/4390160", "pm_score": 2, "selected": false, "text": "def del_rep_vow(s):\n for ch in 'eaiou':\n if ch in s:\n i = s.index(ch) + 1\n s = s[:i] + s[i:].replace(ch, '')\n return s\n\n\nprint(del_rep_vow('adaptation'))\nprint(del_rep_vow('repetitions'))\nprint(del_rep_vow('kingkong'))\nprint(del_rep_vow('aeiouaeiou'))\n" }, { "answer_id": 74296907, "author": "Olivier Melançon", "author_id": 5079316, "author_profile": "https://Stackoverflow.com/users/5079316", "pm_score": 2, "selected": false, "text": "str.partition" }, { "answer_id": 74296947, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 2, "selected": false, "text": "def del_rep_vow(s):\n final_list = []\n vowels = 'aeiou'\n for i in s:\n if i not in vowels or i not in final_list: # allowed consonants to be added every time\n final_list.append(i)\n return ''.join(final_list)\n" }, { "answer_id": 74302744, "author": "SergFSM", "author_id": 18344512, "author_profile": "https://Stackoverflow.com/users/18344512", "pm_score": 0, "selected": false, "text": "def del_rep_vow(s):\n return del_rep_vow(s[:-1]) + ('' if s[-1] in 'aeiou' and s[-1] in s[:-1] else s[-1]) if s else ''\n\ndel_rep_vow('repetitions') # reptitons'\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20323813/" ]
74,296,730
<p>I was answering <a href="https://stackoverflow.com/questions/74283906/overlaying-geom-bar-and-missing-values">this question</a> where @Léo wanted a barplot with <code>stat = &quot;identity&quot;</code> and <code>position = &quot;identity&quot;</code>. This causes the bars (one for every value of the <code>fill</code> aesthetic) to get on top of eachother, making some to get hidden:</p> <img src="https://i.stack.imgur.com/GmOCU.png" width="500" /> <p>His solution was to set <code>alpha = 0.5</code>, but he didn't liked the result as the colors mixed in different ways in each x-axis tick. Thus, i figured that the solution would be to have a different color ordering for each x-axis tick, but i don't know how to do it in ggplot.</p> <h2>What I've tried:</h2> <p>Dummy data:</p> <pre><code>library(tidyverse) set.seed(7) df = tibble( categories = rep(c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;), each = 3) %&gt;% factor(), xaxis = rep(1:3, 3) %&gt;% factor(), yaxis = runif(9)) </code></pre> <p>What plotted the &quot;original&quot; graph, shown above:</p> <pre><code>ggplot() + geom_bar(aes(xaxis, yaxis, fill = categories), df, stat = &quot;identity&quot;, position = &quot;identity&quot;) </code></pre> <p>My attempt: changing the <code>categories</code> levels order and creating a different <code>geom_bar</code> for each x-axis value with a for loop:</p> <pre><code>g = ggplot() for(x in unique(df$xaxis)){ df.x = df %&gt;% filter(xaxis == x) %&gt;% mutate(categories = fct_reorder(categories, yaxis)) g = g + geom_bar(aes(xaxis, yaxis, fill = categories), df.x, stat = &quot;identity&quot;, position = &quot;identity&quot;)} plot(g) </code></pre> <p>The levels on df.x actually change to the correct order for every iteration, but the same graph as before gets produced.</p>
[ { "answer_id": 74296768, "author": "Tim Biegeleisen", "author_id": 1863229, "author_profile": "https://Stackoverflow.com/users/1863229", "pm_score": 3, "selected": true, "text": "def del_rep_vow(s):\n vowels_seen = set()\n final_list = []\n for i in s:\n if i in ['a', 'e', 'i', 'o', 'u']:\n if i not in vowels_seen:\n final_list.append(i)\n vowels_seen.add(i)\n else:\n final_list.append(i)\n\n return ''.join(final_list)\n\nprint(del_rep_vow('adaptation')) # 'adpttion'\nprint(del_rep_vow('repetitions')) # 'reptitons'\nprint(del_rep_vow('kingkong')) # 'kingkong'\nprint(del_rep_vow('aeiouaeiou')) # 'aeiou'\n" }, { "answer_id": 74296776, "author": "Rodrigo Rodrigues", "author_id": 2938526, "author_profile": "https://Stackoverflow.com/users/2938526", "pm_score": 0, "selected": false, "text": "vowels = []\nremaining = []\nfor c in s:\n if c in 'aeiou':\n if c in vowels:\n continue\n vowels.append(c)\n remaining.append(c)\n" }, { "answer_id": 74296806, "author": "itprorh66", "author_id": 14249087, "author_profile": "https://Stackoverflow.com/users/14249087", "pm_score": 0, "selected": false, "text": "def del_repts(x):\n vowels = 'aeiou'\n foundVowels = ''\n rslt = ''\n for c in x:\n if c in vowels:\n if c not in foundVowels:\n rslt += c\n foundVowels += c\n else:\n rslt += c\n return rslt \n\ninl = ['adaptation', 'repetitions', 'kingkong', 'aeiouaeiou']\nfor itm in inl:\n print(f'{itm}\\t->\\t{del_repts(itm)}' ) \n" }, { "answer_id": 74296828, "author": "Grismar", "author_id": 4390160, "author_profile": "https://Stackoverflow.com/users/4390160", "pm_score": 2, "selected": false, "text": "def del_rep_vow(s):\n for ch in 'eaiou':\n if ch in s:\n i = s.index(ch) + 1\n s = s[:i] + s[i:].replace(ch, '')\n return s\n\n\nprint(del_rep_vow('adaptation'))\nprint(del_rep_vow('repetitions'))\nprint(del_rep_vow('kingkong'))\nprint(del_rep_vow('aeiouaeiou'))\n" }, { "answer_id": 74296907, "author": "Olivier Melançon", "author_id": 5079316, "author_profile": "https://Stackoverflow.com/users/5079316", "pm_score": 2, "selected": false, "text": "str.partition" }, { "answer_id": 74296947, "author": "Swifty", "author_id": 20267366, "author_profile": "https://Stackoverflow.com/users/20267366", "pm_score": 2, "selected": false, "text": "def del_rep_vow(s):\n final_list = []\n vowels = 'aeiou'\n for i in s:\n if i not in vowels or i not in final_list: # allowed consonants to be added every time\n final_list.append(i)\n return ''.join(final_list)\n" }, { "answer_id": 74302744, "author": "SergFSM", "author_id": 18344512, "author_profile": "https://Stackoverflow.com/users/18344512", "pm_score": 0, "selected": false, "text": "def del_rep_vow(s):\n return del_rep_vow(s[:-1]) + ('' if s[-1] in 'aeiou' and s[-1] in s[:-1] else s[-1]) if s else ''\n\ndel_rep_vow('repetitions') # reptitons'\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13048728/" ]
74,296,765
<p>While using Jupyter notebook I never had this problem with the <code>fit()</code> function. But with this code I do:</p> <pre><code>import pandas as pd from sklearn.tree import DecisionTreeClassifier data = pd.read_csv('train.csv') test_data = pd.read_csv('test.csv') X = data.drop(columns=['Survived']) y = data['Survived'] model = DecisionTreeClassifier model.fit(X, y) prediction = model.predict(test_data) prediction </code></pre> <p>The train.csv and test.csv files were successfully read by pandas (I visualized X and Y in Jupyter).</p> <p>The output:</p> <pre><code>--------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_23200\3416706318.py in &lt;module&gt; 9 10 model = DecisionTreeClassifier ---&gt; 11 model.fit(X, y) 12 prediction = model.predict(test_data) 13 prediction TypeError: fit() missing 1 required positional argument: 'y' </code></pre> <p>How do I fix this bug?</p> <p>The data used: <a href="https://www.kaggle.com/competitions/titanic/data?select=train.csv" rel="nofollow noreferrer">https://www.kaggle.com/competitions/titanic/data?select=train.csv</a></p>
[ { "answer_id": 74297393, "author": "George", "author_id": 20345563, "author_profile": "https://Stackoverflow.com/users/20345563", "pm_score": 2, "selected": true, "text": "model = DecisionTreeClassifier()" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19792620/" ]
74,296,772
<p>I want to create a banner area with an icon on the left. In the middle is two lines (title and sub-title) with text. However, all three of these are showing up on separate lines.</p> <p>You can see the problem here: <a href="https://codesandbox.io/s/bold-brook-71ucup?file=/src/App.js:366-402" rel="nofollow noreferrer">https://codesandbox.io/s/bold-brook-71ucup?file=/src/App.js:366-402</a>. For the sake of simplicity, I have replaced the area where an icon should appear with text.</p> <pre><code>import { Grid, Stack, Typography } from &quot;@mui/material&quot;; export default function App() { return ( &lt;&gt; &lt;Grid container&gt; &lt;Grid item xs={12} direction=&quot;row&quot;&gt; &lt;Stack xs={3}&gt; &lt;Typography&gt;Icon&lt;/Typography&gt; &lt;/Stack&gt; &lt;Stack sx={{ borderBottom: 1, borderColor: &quot;grey.500&quot;, alignItems: &quot;center&quot;, xs: 9, direction: &quot;column&quot; }} &gt; &lt;Typography variant=&quot;h5&quot;&gt;My-Title&lt;/Typography&gt; &lt;Typography variant=&quot;h7&quot; sx={{ fontStyle: &quot;italic&quot; }}&gt; My-Subtitle &lt;/Typography&gt; &lt;/Stack&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/&gt; ); } </code></pre> <p>I have trouble with MUI because I don't know when to use Grid, Box or Stack and what properties apply to them. What is most puzzling to me is that even specifying the columns for each item isn't working. Any help on how I can debug these kinds of problems will also be most appreciated.</p> <p><strong>Update:</strong> I solved it by changing the &lt;Grid item ...&gt; to be a container as well &lt;Grid item container ...&gt;. The direction property is honored by the container, thereby allowing me to lay out the stacks side by side. The updated solution is in the sandbox.</p>
[ { "answer_id": 74297129, "author": "Sheryar Ahmed", "author_id": 19575084, "author_profile": "https://Stackoverflow.com/users/19575084", "pm_score": 1, "selected": false, "text": "<Stack sx={{ width: '100% }} spacing={2} >\n <Alert \n severity=\"info\" \n sx={{ \n fontSize: '14px'\n }}\n >\n \"Title and Subtitle will be here\"\n </Alert>\n</Stack>\n" }, { "answer_id": 74308091, "author": "NRS2000", "author_id": 12990786, "author_profile": "https://Stackoverflow.com/users/12990786", "pm_score": 0, "selected": false, "text": "import { Grid, Stack, Typography } from \"@mui/material\";\n\nexport default function App() {\n return (\n <>\n <Grid container>\n <Grid\n item\n container\n xs={12}\n direction=\"row\"\n sx={{ borderBottom: 1, borderColor: \"grey.500\" }}\n >\n <Stack sx={{ alignItems: \"center\" }}>\n <Typography>Icon</Typography>\n </Stack>\n <Stack\n sx={{\n alignItems: \"center\",\n direction: \"column\",\n flexGrow: 1\n }}\n >\n <Typography variant=\"h5\">My-Title</Typography>\n <Typography variant=\"h7\" sx={{ fontStyle: \"italic\" }}>\n My-Subtitle\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n </>\n );\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12990786/" ]
74,296,811
<p>So i don't think i can be more clrear on the tittle.</p> <p>My problem is i'm making a google extension to copy the name that it is in the cell of a every row to clipboard.</p> <p>I already saw this <a href="https://stackoverflow.com/questions/63550272/copy-to-clipboard-from-table-cell">post</a> but didn't help.</p> <p>This is my loop to go by all of the table:</p> <pre><code>while(row=table.rows[r++]){ var c=0; //start counting columns in row while(cell=row.cells[c++]){ if(r&gt;=2){ if(c==2){//Cell that contains the name of the item let text = cell.innerHTML; cell.innerHTML = `&lt;b onclick=&quot;${copy2Clipboard(text)}&quot;&gt;` + text; } } } } </code></pre> <p>And this is my function to copy the name to clipboard</p> <pre><code>function copy2Clipboard(itemName){ //Put in clipboard navigator.clipboard.writeText(itemName.innerHTML); //if don't return this, it will not appear on page idkwhy return `copy2Clipboard(${itemName})`; } </code></pre> <p>Problem I'm getting the always the value of the last item and not each individual item of the table on the clipboard.</p> <p>If you got any idea to try to make this, i would like to hear And thanks in advance :)</p>
[ { "answer_id": 74297129, "author": "Sheryar Ahmed", "author_id": 19575084, "author_profile": "https://Stackoverflow.com/users/19575084", "pm_score": 1, "selected": false, "text": "<Stack sx={{ width: '100% }} spacing={2} >\n <Alert \n severity=\"info\" \n sx={{ \n fontSize: '14px'\n }}\n >\n \"Title and Subtitle will be here\"\n </Alert>\n</Stack>\n" }, { "answer_id": 74308091, "author": "NRS2000", "author_id": 12990786, "author_profile": "https://Stackoverflow.com/users/12990786", "pm_score": 0, "selected": false, "text": "import { Grid, Stack, Typography } from \"@mui/material\";\n\nexport default function App() {\n return (\n <>\n <Grid container>\n <Grid\n item\n container\n xs={12}\n direction=\"row\"\n sx={{ borderBottom: 1, borderColor: \"grey.500\" }}\n >\n <Stack sx={{ alignItems: \"center\" }}>\n <Typography>Icon</Typography>\n </Stack>\n <Stack\n sx={{\n alignItems: \"center\",\n direction: \"column\",\n flexGrow: 1\n }}\n >\n <Typography variant=\"h5\">My-Title</Typography>\n <Typography variant=\"h7\" sx={{ fontStyle: \"italic\" }}>\n My-Subtitle\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n </>\n );\n}\n" } ]
2022/11/02
[ "https://Stackoverflow.com/questions/74296811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18940862/" ]
74,296,861
<p>I am reading a code that has two files like below:</p> <p>first file that uses the <code>currentuser</code> middleware:</p> <pre><code>const router = express.Router(); router.get(&quot;/api/users/currentuser&quot;, currentUser, (req, res) =&gt; { res.send({ currentUser: req.currentUser || null }); }); export { router as currentUserRouter }; </code></pre> <p>Second file that defines the middleware:</p> <pre><code>interface UserPayload { id: string; email: string; } declare global { namespace Express { interface Request { currentUser?: UserPayload; } } } export const currentUser = ( req: Request, res: Response, next: NextFunction ) =&gt; { if (!req.session?.jwt) { return next(); } try { const payload = jwt.verify( req.session.jwt, process.env.JWT_KEY! ) as UserPayload; req.currentUser = payload; } catch (err) {} next(); }; </code></pre> <p>I understand that if there is a verified <code>jwt</code> token, the middleware will take the the payload out of it and add it to the <code>req</code> object. But what if it fails and it can't add the payload/current user to the <code>req</code>? What would happen for the following request and what will the <code>res</code> object look like?</p> <pre><code>router.get(&quot;/api/users/currentuser&quot;, currentUser, (req, res) =&gt; { res.send({ currentUser: req.currentUser || null }); }); </code></pre> <p>Could you edit this <code>get</code> request to show how can I catch the probable error if I am not the writer of the middleware?</p>
[ { "answer_id": 74296882, "author": "inf3rno", "author_id": 607033, "author_profile": "https://Stackoverflow.com/users/607033", "pm_score": 2, "selected": false, "text": "req.currentUser = payload;" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74296861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17100762/" ]
74,296,870
<p>I'm trying to open a text file and print it as a string. I've made sure there is text in the .txt file but when I run the code it just prints an empty space, I don't know what to do at this point since I couldn't find anything that could help me with my problem.</p> <pre><code>with open('test.txt', 'r') as file: data = file.read().rstrip() print(data) </code></pre>
[ { "answer_id": 74296922, "author": "Beronicous", "author_id": 17802583, "author_profile": "https://Stackoverflow.com/users/17802583", "pm_score": -1, "selected": false, "text": "open(\"file.txt\",\"r\")" }, { "answer_id": 74296998, "author": "paaoogh", "author_id": 13544772, "author_profile": "https://Stackoverflow.com/users/13544772", "pm_score": 0, "selected": false, "text": "with open(path_to_file) as f:\n contents = f.readlines()\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74296870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402548/" ]
74,296,943
<p>I have a POST table, a CATEGORY table, a TAG table and a MIGTATION_TAG table, I explain the MIGTATION_TAG table contains the movement of the tags between the categories, for example the tag whose ID = 1 belongs to the category whose l 'ID = 10 if I change its category to 12 a line will be added to the MIGTATION_TAG table as follows: ID 1 TAG_ID 1 CATEGOTY_ID 12</p> <p>the POST table</p> <pre><code> id title content tag_id ---------- ---------- ---------- ---------- 1 title1 Text... 1 2 title2 Text... 3 3 title3 Text... 1 4 title4 Text... 2 5 title5 Text... 5 6 title6 Text... 4 </code></pre> <p>the CATEGORY table</p> <pre><code> id name ---------- ---------- 1 category_1 2 category_2 3 category_3 </code></pre> <p>the TAG table</p> <pre><code> id name fist_category_id ---------- ---------- ---------------- 1 tag_1 1 2 tag_2 1 3 tag_3 3 4 tag_4 1 5 tag_5 2 </code></pre> <p>the MIGTATION_TAG table</p> <pre><code> id tag_id category_id ---------- ---------- ---------------- 9 1 3 8 5 1 7 1 2 5 3 1 4 2 2 3 5 3 2 3 3 1 1 3 </code></pre> <p>so i would like to know how many posts are registered for each category.</p> <p>in some cases if there has been no change of category for a tag then it keeps its first category, I manage to join the TAG table to the POST table via LEFT JOIN but the problem is that the join must depend on the MIGTATION_TAG table which must check if there has been a migration, if so then it must bring me back the last MAX (tag_id ) for each tag ,</p> <p>here is my query</p> <pre><code>select category, COUNT(*) AS numer_of_posts from( select CATEGORY.name, case when POST.tag_id is not null then CATEGORY.name end as category from POST left join TAG ON POST.tag_id = TAG.id left join ( select id, MAX(tag_id) tag_id from MIGTATION_TAG group by id, tag_id ) MIGTATION_TAG ON TAG.id = MIGTATION_TAG.tag_id left join CATEGORY on MIGTATION_TAG.category_id = CATEGORY.id ) GROUP BY category ; </code></pre> <p>here is the result i want to display with my query</p> <p>Important ! for the post with id = 6 the tag_id = 4 whish was not changed so it will be using the fist_category_id in TAG table</p> <pre><code> category numer_of_posts ---------- -------------- category_1 3 category_2 1 category_3 2 </code></pre> <p>Best regards</p>
[ { "answer_id": 74296922, "author": "Beronicous", "author_id": 17802583, "author_profile": "https://Stackoverflow.com/users/17802583", "pm_score": -1, "selected": false, "text": "open(\"file.txt\",\"r\")" }, { "answer_id": 74296998, "author": "paaoogh", "author_id": 13544772, "author_profile": "https://Stackoverflow.com/users/13544772", "pm_score": 0, "selected": false, "text": "with open(path_to_file) as f:\n contents = f.readlines()\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74296943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19974817/" ]
74,296,949
<pre><code>Select TimeFromParts(FieldName/ 10000,(FieldName / 100 % 100, % 100, 0, 0) </code></pre> <p>Could someone explain this select statement and what exactly each argument is doing? I see this is used to change an integer to time but I'm curious as to what exactly is going on and why those numbers were chosen.</p> <p>I somewhat understand the last 2 zeros are for the fraction and precision.</p>
[ { "answer_id": 74296999, "author": "Amikot40", "author_id": 10756331, "author_profile": "https://Stackoverflow.com/users/10756331", "pm_score": 1, "selected": false, "text": "TIMEFROMPARTS ( hour, minute, seconds, fractions, precision ) \n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74296949", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20336284/" ]
74,296,987
<p>I am having problems with a code created in python, and it is that when I generate some texts in json the accents are not appreciated</p> <p>This is my code that I am using...</p> <pre><code>import requests url = requests.get(f&quot;https://images.habbo.com/habbo-web-news/es/production/front.json&quot;) resumen = url.json()[0]['summary'] print(resumen) </code></pre> <p>I get these weird characters &quot;&amp; # x E D;&quot;</p>
[ { "answer_id": 74297023, "author": "PCDSandwichMan", "author_id": 12007307, "author_profile": "https://Stackoverflow.com/users/12007307", "pm_score": 1, "selected": true, "text": "import html\nimport requests\n\nurl = requests.get(\n f\"https://images.habbo.com/habbo-web-news/es/production/front.json\")\n\ncontent = url.json()\n\nsummary = content[0][\"summary\"]\n\ndecoded = html.unescape(summary)\n\nprint (decoded)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74296987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20312881/" ]
74,297,018
<p>I am trying to write a query that shows only the 1st rows for each name, but those rows have a null for the title, so I want to pull in their titles from the immediate next row.</p> <p>table1</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Title</th> <th>Row</th> </tr> </thead> <tbody> <tr> <td>Dan</td> <td>NULL</td> <td>1</td> </tr> <tr> <td>Dan</td> <td>Engineer</td> <td>2</td> </tr> <tr> <td>Dan</td> <td>Developer</td> <td>3</td> </tr> <tr> <td>Jay</td> <td>NULL</td> <td>1</td> </tr> <tr> <td>Jay</td> <td>Lawyer</td> <td>2</td> </tr> </tbody> </table> </div> <p>The final result should look like the following:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Title</th> <th>Row</th> </tr> </thead> <tbody> <tr> <td>Dan</td> <td>Engineer</td> <td>1</td> </tr> <tr> <td>Jay</td> <td>Lawyer</td> <td>1</td> </tr> </tbody> </table> </div> <p>I've only written this so far, I don't know how to pull in the titles from the previous row. Any help would be greatly appreciated.</p> <pre><code>select * from table1 where Row = 1 </code></pre>
[ { "answer_id": 74297063, "author": "Amikot40", "author_id": 10756331, "author_profile": "https://Stackoverflow.com/users/10756331", "pm_score": 0, "selected": false, "text": "SELECT \n T1.Name, \n (CASE WHEN T1.Title IS NULL \n THEN (SELECT TOP(1) T2.Title FROM table1 T2 WHERE T2.Name = T1.Name AND T2.Title IS NOT NULL ORDER BY T2.Row ASC) ELSE T1.Title END) AS 'Title', \n T1.Row\nFROM table1 T1\nWHERE T1.Row = 1\n" }, { "answer_id": 74297097, "author": "Breezer", "author_id": 260640, "author_profile": "https://Stackoverflow.com/users/260640", "pm_score": 0, "selected": false, "text": "select * from table1 where Title IS NOT NULL GROUP BY Name " }, { "answer_id": 74297881, "author": "Mikhail Berlyant", "author_id": 5221944, "author_profile": "https://Stackoverflow.com/users/5221944", "pm_score": 0, "selected": false, "text": "select name, lead(title) over win as title, row\nfrom your_table\nqualify 1 = row_number() over win\nwindow win as (partition by name order by row) \n" }, { "answer_id": 74300533, "author": "Shivani", "author_id": 11189352, "author_profile": "https://Stackoverflow.com/users/11189352", "pm_score": 2, "selected": true, "text": "SELECT Name, IFNULL(Title, LeadTitle), Row\nFROM (\n SELECT Name, Title, LEAD(Title) OVER(PARTITION BY Name ORDER BY ROW) AS LeadTitle, Row\n FROM `dataset.tablename` )\nWHERE Row = 1\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19105904/" ]
74,297,051
<p>I am using MUI data grid. To show checkboxes for row selection, I have added checkboxSelection attribute to the data grid. Works very well.</p> <pre><code>&lt;DataGridPro sortingOrder={['asc', 'desc']} checkboxSelection disableColumnMenu disableSelectionOnClick columnBuffer={Number.MAX_SAFE_INTEGER} components={{ Toolbar: GridToolbar, }} /&gt; </code></pre> <p>Is there any way to disable checkbox selection toggle?</p> <p><a href="https://i.stack.imgur.com/J3Ck3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J3Ck3.png" alt="enter image description here" /></a></p> <p>I can disable other column toggles by adding hideable: false property. However, can't disable checkboxSelection as it's not a custom column.</p>
[ { "answer_id": 74297063, "author": "Amikot40", "author_id": 10756331, "author_profile": "https://Stackoverflow.com/users/10756331", "pm_score": 0, "selected": false, "text": "SELECT \n T1.Name, \n (CASE WHEN T1.Title IS NULL \n THEN (SELECT TOP(1) T2.Title FROM table1 T2 WHERE T2.Name = T1.Name AND T2.Title IS NOT NULL ORDER BY T2.Row ASC) ELSE T1.Title END) AS 'Title', \n T1.Row\nFROM table1 T1\nWHERE T1.Row = 1\n" }, { "answer_id": 74297097, "author": "Breezer", "author_id": 260640, "author_profile": "https://Stackoverflow.com/users/260640", "pm_score": 0, "selected": false, "text": "select * from table1 where Title IS NOT NULL GROUP BY Name " }, { "answer_id": 74297881, "author": "Mikhail Berlyant", "author_id": 5221944, "author_profile": "https://Stackoverflow.com/users/5221944", "pm_score": 0, "selected": false, "text": "select name, lead(title) over win as title, row\nfrom your_table\nqualify 1 = row_number() over win\nwindow win as (partition by name order by row) \n" }, { "answer_id": 74300533, "author": "Shivani", "author_id": 11189352, "author_profile": "https://Stackoverflow.com/users/11189352", "pm_score": 2, "selected": true, "text": "SELECT Name, IFNULL(Title, LeadTitle), Row\nFROM (\n SELECT Name, Title, LEAD(Title) OVER(PARTITION BY Name ORDER BY ROW) AS LeadTitle, Row\n FROM `dataset.tablename` )\nWHERE Row = 1\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/988864/" ]
74,297,060
<p><strong>The schema</strong></p> <p>Date table with the standard fields such as date, week number etc.</p> <p>Data table with the relevant fields being id no, created date and closed date.</p> <p><strong>The set-up</strong> <a href="https://i.stack.imgur.com/SWwCc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SWwCc.png" alt="enter image description here" /></a></p> <p>I have two measures for calculating the number of tasks opened each week:</p> <pre><code> Created on Date = CALCULATE( DISTINCTCOUNT('Data table'[number]), USERELATIONSHIP('Data table'[Created Date],'Date'[Date])) + 0 Closed on Date = CALCULATE( DISTINCTCOUNT('Data table'[number]), USERELATIONSHIP('Data table'[Closed Date],'Date'[Date])) + 0 </code></pre> <p>Each number is shown on the relevant column chart.</p> <p><strong>The task</strong></p> <p>In the table below the column charts, I would like to list ONLY the tasks related to a selected column from any table. So for example if week 41 is selected from the &quot;Created&quot; table, I would like to see only the relevant eight record which were created that week without any which happened to be closed on that week.</p> <p>What's the best way of doing this?</p>
[ { "answer_id": 74371984, "author": "Kevin", "author_id": 20443243, "author_profile": "https://Stackoverflow.com/users/20443243", "pm_score": 2, "selected": true, "text": "'Data table'[Created Date]" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4017932/" ]
74,297,117
<p>I have a function like this to implement <a href="https://stackoverflow.com/a/13137359/1505451"><code>fmap</code></a> for C++:</p> <pre class="lang-cpp prettyprint-override"><code>// Given a mapping F from T to U and a container of T, return a container of U // whose elements are created by the mapping from the original container's // elements. template &lt;typename F, template &lt;typename...&gt; typename Container, typename T&gt; Container&lt;std::invoke_result_t&lt;F&amp;, const T&amp;&gt;&gt; Fmap(F&amp;&amp; f, const Container&lt;T&gt;&amp; input); </code></pre> <p>The idea is to use a template template parameter (<code>Container</code>) to allow accepting any STL-like container. All of the ones in the actual STL I've tried work fine, but a custom container in our codebase doesn't work because it accepts a non-type template parameter</p> <pre class="lang-cpp prettyprint-override"><code>template &lt;typename Key, int Foo = 256&gt; class MyContainer; </code></pre> <p>This causes a substitution failure from clang:</p> <pre><code>template template argument has different template parameters than its corresponding template template parameter </code></pre> <p><strong>Is there a way to abstract over <em>all</em> template parameters, not just types?</strong> If not, is there a better way to structure my code to allow doing what I want without specializing for <code>MyContainer</code> and all others like it in particular?</p>
[ { "answer_id": 74297300, "author": "Nelfeal", "author_id": 3854570, "author_profile": "https://Stackoverflow.com/users/3854570", "pm_score": 2, "selected": false, "text": "Fmap" }, { "answer_id": 74298984, "author": "n. m.", "author_id": 775806, "author_profile": "https://Stackoverflow.com/users/775806", "pm_score": 0, "selected": false, "text": "template <typename F, template <typename /* no pack */> typename Container, typename T>\nContainer<std::invoke_result_t<F&, const T&>> Fmap(F&& f,\n const Container<T>& input);\n\ntemplate <typename X> using MyContainerDefault = MyContainer<X>;\n\nsomething = Fmap(someFunction, MyContainerDefault);\n" }, { "answer_id": 74299196, "author": "Enlico", "author_id": 5825294, "author_profile": "https://Stackoverflow.com/users/5825294", "pm_score": 1, "selected": false, "text": "Functor" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1505451/" ]
74,297,121
<p>I'm working on a React project that uses MUI and Sass. Currently there are multiple scss-files full of <code>!important</code> to overwrite the MUI styles with sass. I tried to fix this by removing the <code>!important</code>'s and adding:</p> <pre><code>import { StyledEngineProvider } from '@mui/material/styles'; import CssBaseline from '@mui/material/CssBaseline' &lt;CssBaseline /&gt; &lt;StyledEngineProvider injectFirst&gt; *** component tree here *** &lt;/StyledEngineProvider&gt; </code></pre> <p>as suggested here: <a href="https://stackoverflow.com/questions/70842773/issue-with-mui-and-modularized-scss-competing-intermittently-how-to-consistent">Issue with @Mui and modularized scss competing intermittently. How to consistently override @mui default styling with scss modules?</a></p> <p>Which seemed to work at first but stops working when you focus on a component. For example this button turns white with a blue border when hovered over:</p> <p>scss</p> <pre><code>.button { width: 250px; height: 50px; border: 1px solid grey; border-radius: 15px; text-transform: none; } .go-button { @extend .button; background-color: grey; color: whitesmoke; } </code></pre> <p>reactjs</p> <pre><code>&lt;Button className=&quot;go-button&quot; variant=&quot;outlined&quot; onClick={handleClick} &gt; Go &lt;/Button&gt; </code></pre> <p>We are not using modules or makeStyles. What would be the best way to overwrite MUI without the <code>!important</code>'s?</p>
[ { "answer_id": 74297937, "author": "Ryan Cogswell", "author_id": 7495930, "author_profile": "https://Stackoverflow.com/users/7495930", "pm_score": 2, "selected": true, "text": ":hover" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12474420/" ]
74,297,139
<pre class="lang-dart prettyprint-override"><code>class Rapidoreach extends StatefulWidget { const Rapidoreach({ Key? key, this.width, this.height, this.uid, }) : super(key: key); final double? width; final double? height; final String? uid; @override _RapidoreachState createState() =&gt; _RapidoreachState(); } class _RapidoreachState extends State&lt;Rapidoreach&gt; { @override void initState() { RapidoReach.instance.init(apiToken: 'api-key', userId: 'userid'); RapidoReach.instance.setOnRewardListener(onRapidoReachReward); RapidoReach.instance.setRewardCenterClosed(onRapidoReachRewardCenterClosed); RapidoReach.instance.setRewardCenterOpened(onRapidoReachRewardCenterOpened); RapidoReach.instance .setSurveyAvaiableListener(onRapidoReachSurveyAvailable); super.initState(); } void onRapidoReachReward(num quantity) { final DocumentReference docRef = FirebaseFirestore.instance.collection(&quot;users&quot;).doc(uid); //Here is the error (uid) docRef.update({&quot;prizecoins&quot;: FieldValue.increment(quantity)}); } void onRapidoReachSurveyAvailable(int? survey) { debugPrint('ROR: $survey'); } void onRapidoReachRewardCenterClosed() { debugPrint('ROR: closed'); } void onRapidoReachRewardCenterOpened() { debugPrint('ROR: opened'); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: &lt;Widget&gt;[ ElevatedButton( child: const Text(&quot;Launch RapidoReach&quot;), onPressed: () =&gt; RapidoReach.instance.show(), ), ], )), ), ); } } </code></pre> <p>Why do I have an issue saying that <code>uid</code> is not defined when is already defined in <code>StatefulWidget</code>?</p> <p>Can someone help me?</p>
[ { "answer_id": 74297937, "author": "Ryan Cogswell", "author_id": 7495930, "author_profile": "https://Stackoverflow.com/users/7495930", "pm_score": 2, "selected": true, "text": ":hover" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20363272/" ]
74,297,145
<p>I want to display words that have the required character in a dictionary. For example :</p> <pre><code>Write a sentence: Mister Jack, you are a good coder {'a': ['are', 'jack,'], 'b': [], 'c': ['coder', 'jack,'], 'd': ['coder'], 'e': ['coder', 'mister',], 'f': [], 'g': [], 'h': [], 'i': ['mister'], 'j': ['jack,'], 'k': ['jack,'], 'l': [], 'm': ['mister', ], 'n': [], 'o': ['coder', 'you', 'good'], 'p': [], 'q': [], 'r': ['coder', 'mister'], 's': ['mister', ], 't': ['mister'], 'u': ['you'], 'v': [], 'w': [], 'x': [], 'y': ['you'], 'z': []} </code></pre> <p>Here is my code :</p> <pre class="lang-py prettyprint-override"><code>import string alphabet = string.ascii_lowercase sentence= (input(&quot;Write your sentence: &quot; )).lower() letter_notfound=(sorted(list((set(string.ascii_lowercase) - set(&quot;&quot;.join(sentence.split())))))) print (letter_notfound) letter_list=list(alphabet) unique_letter = (sorted(list((set(letter_list)-set(letter_notfound))))) dico={} for key in (letter_list): for char in sentence: if char in unique_letter: dico[char] = [sentence] for char in letter_notfound: dico[char] = [] print(dict(sorted(dico.items()))) </code></pre> <p>Input: Mister Jack, you are a good coder</p> <p>Output:</p> <pre class="lang-json prettyprint-override"><code>{'a': ['mister jack, you are a good coder'], 'b': [], 'c': ['mister jack, you are a good coder'], 'd': ['mister jack, you are a good coder'], 'e': ['mister jack, you are a good coder'], 'f': [], 'g': ['mister jack, you are a good coder'], 'h': [], 'i': ['mister jack, you are a good coder'], 'j': ['mister jack, you are a good coder'], 'k': ['mister jack, you are a good coder'], 'l': [], 'm': ['mister jack, you are a good coder'], 'n': [], 'o': ['mister jack, you are a good coder'], 'p': [], 'q': [], 'r': ['mister jack, you are a good coder'], 's': ['mister jack, you are a good coder'], 't': ['mister jack, you are a good coder'], 'u': ['mister jack, you are a good coder'], 'v': [], 'w': [], 'x': [], 'y': ['mister jack, you are a good coder'], 'z': []} </code></pre> <p>Desired output:</p> <pre class="lang-json prettyprint-override"><code>{'a': ['are', 'jack,'], 'b': [], 'c': ['coder', 'jack,'], 'd': ['coder'], 'e': ['coder', 'mister',], 'f': [], 'g': [], 'h': [], 'i': ['mister'], 'j': ['jack,'], 'k': ['jack,'], 'l': [], 'm': ['mister', ], 'n': [], 'o': ['coder', 'you', 'good'], 'p': [], 'q': [], 'r': ['coder', 'mister'], 's': ['mister', ], 't': ['mister'], 'u': ['you'], 'v': [], 'w': [], 'x': [], 'y': ['you'], 'z': []} </code></pre>
[ { "answer_id": 74297210, "author": "Flow", "author_id": 14121161, "author_profile": "https://Stackoverflow.com/users/14121161", "pm_score": 0, "selected": false, "text": "import string\n\nalphabet = string.ascii_lowercase\nalphabet_dict = {alphabet[i]: [] for i in range(len(alphabet))}\ninput_list = input(\"Enter a string: \").split(\" \")\nfor word in input_list:\n for letter in word:\n if letter in alphabet_dict:\n alphabet_dict[letter].append(word)\nalphabet_dict = dict(sorted(alphabet_dict.items(), key=lambda item: item[0]))\nprint(alphabet_dict)\n" }, { "answer_id": 74297215, "author": "kosciej16", "author_id": 3361462, "author_profile": "https://Stackoverflow.com/users/3361462", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74297256, "author": "xlm", "author_id": 885922, "author_profile": "https://Stackoverflow.com/users/885922", "pm_score": 1, "selected": false, "text": "words = sentence.split(' ') # Assuming already lowercase\nalphabet_dict = {x: [w for w in words if x in w] for x in ascii_lowercase}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402809/" ]
74,297,149
<p>Current</p> <pre><code>+-------+---------------------------------------------------------------------------+ |ID |map | +-------+---------------------------------------------------------------------------+ |105 |[{bia, {4 -&gt; 1}}, {compton, {5 -&gt; 1}}, {alcatraz, {3 -&gt; 6}}] | |106 |[{compton, {4 -&gt; 5}}] | |107 |[{compton, {5 -&gt; 99}}] | |108 |[{bia, {1 -&gt; 5}}, {compton, {1 -&gt; 1}}] | |101 |[{alcatraz, {1 -&gt; 2}}] | |102 |[{alcatraz, {1 -&gt; 2}}] | |103 |[{alcatraz, {1 -&gt; 2}}, {alcatraz, {2 -&gt; 2}}, {alcatraz, {3 -&gt; 2}}] | |104 |[{alcatraz, {1 -&gt; 4}}, {alcatraz, {2 -&gt; 2}}, {alcatraz, {3 -&gt; 2}}] | +-------+---------------------------------------------------------------------------+ </code></pre> <p>Desired</p> <pre><code> +-------+---------------------------------------------------------------------------+ |ID |map | +-------+---------------------------------------------------------------------------+ |105 |{bia, {4 -&gt; 1}}, {compton, {5 -&gt; 1}}, {alcatraz, {3 -&gt; 6}} | |106 |{compton, {4 -&gt; 5}} | |107 |{compton, {5 -&gt; 99}} | |108 |{bia, {1 -&gt; 5}}, {compton, {1 -&gt; 1}} | |101 |{alcatraz, {1 -&gt; 2}} | |102 |{alcatraz, {1 -&gt; 2}} | |103 |{alcatraz, {1 -&gt; 2, 2 -&gt; 2, 3 -&gt; 2} | |104 |{alcatraz, {1 -&gt; 4, 2 -&gt; 2, 3 -&gt; 2} | +-------+---------------------------------------------------------------------------+ </code></pre> <p>I want the final map to be that the first map level is the key for a location (e.g. <code>alcatraz</code>, <code>bia</code>, <code>compton</code>) and the second level is a number representing a group and the ultimate value is a count.</p> <p>I got the current table by doing something like:</p> <pre><code>.groupBy(col(&quot;ID&quot;)).agg(collect_list(map($&quot;LOCATION&quot;, map($&quot;GROUP&quot;, $&quot;COUNT&quot;))) as &quot;map&quot;) </code></pre> <p>JSON representation of desired format for more clarity</p> <pre><code>{ &quot;alcatraz&quot;: { &quot;1&quot;: 100, &quot;2&quot;: 300 }, &quot;bia&quot;: { &quot;2&quot;: 767 }, &quot;compton&quot;: { &quot;1&quot;: 888, &quot;2&quot;: 999, &quot;3&quot;: 1000 }, } </code></pre> <p>I've seen some other stackoverflow posts for merging simple maps but since it's a map of a map those solutions didn't work.</p> <p>I've been playing with <code>udf</code> but haven't had luck. Is there an easy way to acomplish my goal in scala?</p>
[ { "answer_id": 74297210, "author": "Flow", "author_id": 14121161, "author_profile": "https://Stackoverflow.com/users/14121161", "pm_score": 0, "selected": false, "text": "import string\n\nalphabet = string.ascii_lowercase\nalphabet_dict = {alphabet[i]: [] for i in range(len(alphabet))}\ninput_list = input(\"Enter a string: \").split(\" \")\nfor word in input_list:\n for letter in word:\n if letter in alphabet_dict:\n alphabet_dict[letter].append(word)\nalphabet_dict = dict(sorted(alphabet_dict.items(), key=lambda item: item[0]))\nprint(alphabet_dict)\n" }, { "answer_id": 74297215, "author": "kosciej16", "author_id": 3361462, "author_profile": "https://Stackoverflow.com/users/3361462", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74297256, "author": "xlm", "author_id": 885922, "author_profile": "https://Stackoverflow.com/users/885922", "pm_score": 1, "selected": false, "text": "words = sentence.split(' ') # Assuming already lowercase\nalphabet_dict = {x: [w for w in words if x in w] for x in ascii_lowercase}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5641538/" ]
74,297,154
<p>I am trying to skip a certain number of rows after a max index of each class section. My dataset looks like as following, I would like to skip 2 rows after the max index of class section where class = 4 or 2. As we can see from the dataset that there are two sections of 4s, I would like to remove 2 rows after max index in both sections. As well, there is one section of 2s so I would like to remove 2 rows after max index. However, this is just an example, there could be multiple sections of 4s or 2s.</p> <pre><code>------------------ | rate | class | ------------------ | 0.5 | 9 | ------------------ | 0.7 | 9 | ------------------ | 0.6 | 4 | ------------------ | 0.5 | 4 | ------------------ | 0.3 | 4 | ------------------ | 0.9 | 4 | ------------------ | 0.8 | 1 | ------------------ | 0.6 | 1 | ------------------ | 0.3 | 1 | ------------------ | 0.3 | 1 | ------------------ | 0.2 | 4 | ------------------ | 0.1 | 4 | ------------------ | 0.2 | 3 | ------------------ | 0.4 | 3 | ------------------ | 0.9 | 3 | ------------------ | 1.0 | 2 | ------------------ | 0.7 | 2 | ------------------ | 0.8 | 1 | ------------------ | 0.9 | 1 | ------------------ | 0.6 | 9 | ------------------ </code></pre> <p>The desired output would look like as below:</p> <pre><code>------------------ | rate | class | ------------------ | 0.5 | 9 | ------------------ | 0.7 | 9 | ------------------ | 0.6 | 4 | ------------------ | 0.5 | 4 | ------------------ | 0.3 | 4 | ------------------ | 0.9 | 4 | ------------------ | 0.8 | 1 | ------------------ | 0.6 | 1 | ------------------ | 0.2 | 4 | ------------------ | 0.1 | 4 | ------------------ | 0.2 | 3 | ------------------ | 1.0 | 2 | ------------------ | 0.7 | 2 | ------------------ | 0.6 | 9 | ------------------ </code></pre> <p>Here is the code for my dataset:</p> <pre><code>dd &lt;- data.frame(rate = c(0.5,0.7,0.6,0.5,0.3,0.9,0.8,0.6,0.3,0.3,0.2,0.1,0.2,0.4,0.9,1.0,0.7,0.8,0.9,0.6), class = c(9,9,4,4,4,4,1,1,1,1,4,4,3,3,3,2,2,1,1,9)) </code></pre> <p>I really appreciate your time and effort!</p>
[ { "answer_id": 74297210, "author": "Flow", "author_id": 14121161, "author_profile": "https://Stackoverflow.com/users/14121161", "pm_score": 0, "selected": false, "text": "import string\n\nalphabet = string.ascii_lowercase\nalphabet_dict = {alphabet[i]: [] for i in range(len(alphabet))}\ninput_list = input(\"Enter a string: \").split(\" \")\nfor word in input_list:\n for letter in word:\n if letter in alphabet_dict:\n alphabet_dict[letter].append(word)\nalphabet_dict = dict(sorted(alphabet_dict.items(), key=lambda item: item[0]))\nprint(alphabet_dict)\n" }, { "answer_id": 74297215, "author": "kosciej16", "author_id": 3361462, "author_profile": "https://Stackoverflow.com/users/3361462", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74297256, "author": "xlm", "author_id": 885922, "author_profile": "https://Stackoverflow.com/users/885922", "pm_score": 1, "selected": false, "text": "words = sentence.split(' ') # Assuming already lowercase\nalphabet_dict = {x: [w for w in words if x in w] for x in ascii_lowercase}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11617008/" ]
74,297,155
<p>I'm trying to write up an expression that starts with a '#&quot; and takes in the following types of paths and only takes in a character A-z/a-z and doesn't accept digits or special characters: Example valid paths:</p> <pre><code>#/ #/word/word #/word #/word/word/word </code></pre> <p>This is what I have currently:</p> <pre><code>#\/\D+|\/\D+ </code></pre> <p>I have also tried:</p> <pre><code>#\/\D+|\s\/^[A-Za-z\s]*$ </code></pre> <p>It filters 85% of the paths correctly but it still accepts paths with special characters as valid such as &quot;#/word/word?test=word&quot; &quot;#/word/word=%&quot;</p> <p>I'm not quite sure what I am missing.</p>
[ { "answer_id": 74297210, "author": "Flow", "author_id": 14121161, "author_profile": "https://Stackoverflow.com/users/14121161", "pm_score": 0, "selected": false, "text": "import string\n\nalphabet = string.ascii_lowercase\nalphabet_dict = {alphabet[i]: [] for i in range(len(alphabet))}\ninput_list = input(\"Enter a string: \").split(\" \")\nfor word in input_list:\n for letter in word:\n if letter in alphabet_dict:\n alphabet_dict[letter].append(word)\nalphabet_dict = dict(sorted(alphabet_dict.items(), key=lambda item: item[0]))\nprint(alphabet_dict)\n" }, { "answer_id": 74297215, "author": "kosciej16", "author_id": 3361462, "author_profile": "https://Stackoverflow.com/users/3361462", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74297256, "author": "xlm", "author_id": 885922, "author_profile": "https://Stackoverflow.com/users/885922", "pm_score": 1, "selected": false, "text": "words = sentence.split(' ') # Assuming already lowercase\nalphabet_dict = {x: [w for w in words if x in w] for x in ascii_lowercase}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402826/" ]
74,297,170
<p>I am attempting to create a subscription to a product in Stripe in the same step as the user registration. I'm ultimately trying to avoid having them first create an account, and then entering their payment details once an account has been created.</p> <p>However, this process is proving to be tricky. It seems that in order to create a subscription, it needs me to set up a User Intent, which provides a client_secret, which I need to pass along to Stripe in order to create a subscription on the Stripe side of things. That's where I am getting hung up.</p> <p>Right now, the payment information form looks like this:</p> <pre><code>&lt;form id=&quot;payment-form&quot; action=&quot;{{ route('subscription.create') }}&quot; method=&quot;POST&quot;&gt; @csrf &lt;input type=&quot;hidden&quot; name=&quot;plan&quot; id=&quot;plan&quot; value=&quot;{{ $plan-&gt;id }}&quot;&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-xl-4 col-lg-4&quot;&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;label for=&quot;&quot;&gt;Name&lt;/label&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;card-holder-name&quot; class=&quot;form-control&quot; value=&quot;&quot; placeholder=&quot;Name on the card&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-xl-4 col-lg-4&quot;&gt; &lt;div class=&quot;form-group&quot;&gt; &lt;label for=&quot;&quot;&gt;Card details&lt;/label&gt; &lt;div id=&quot;card-element&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&quot;col-xl-12 col-lg-12&quot;&gt; &lt;hr&gt; &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; id=&quot;card-button&quot; data-secret=&quot;{{ $intent-&gt;client_secret }}&quot;&gt;Purchase&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>In that markup, if you look at the data-secret attribute of the submit button – that seems to be the hangup point for me. I need to basically take the client_secret in the intent that is created, and pass it along in my registration method – but I'm not sure how to do that.</p> <p>Basically, I have the default Laravel Auth form, and am operating inside of the <strong>App/Http/Controllers/Auth/RegisteredUserController.php</strong> file, which is where the store method is that creates the user inside of the database.</p> <p>Here is my code for that method:</p> <pre><code>public function store(Request $request) { $userID = uniqid('u-'); $plan = Plan::find($request-&gt;plan); $request-&gt;validate([ 'first_name' =&gt; ['required', 'string', 'max:255'], 'last_name' =&gt; ['required', 'string', 'max:255'], 'email' =&gt; ['required', 'string', 'email', 'max:255', 'unique:users'], ]); $user = User::create([ 'unique_id' =&gt; $userID, 'first_name' =&gt; $request-&gt;first_name, 'last_name' =&gt; $request-&gt;last_name, 'name' =&gt; $request-&gt;first_name.&quot; &quot;.$request-&gt;last_name, 'email' =&gt; $request-&gt;email, 'password' =&gt; Hash::make(&quot;abcd1234&quot;), 'user_role' =&gt; 'customer', 'status' =&gt; 'pending', 'show_in_directory' =&gt; 'on', ]); event(new Registered($user)); Auth::login($user); /* The following lines are where I am passing data to Stripe to create the subscription */ $intent = $user-&gt;createSetupIntent(); $clientSecret = $intent-&gt;client_secret; /* How do I pass $clientSecret to the subscription request from here??? */ $subscription = $user-&gt;newSubscription($request-&gt;plan, $plan-&gt;stripe_plan)-&gt;create($request-&gt;token); return view(&quot;subscription_success&quot;); </code></pre> <p>As I am looking at the sample code, it seems to want to create the user first so that it can create an Intent, and then pass a client_secret string into a hidden field inside of the payment forms submit button.</p> <p>So, I guess what I am ultimately asking is, how can I create that client_secret, pull it out of the Intent that was created, and pass that along to Stripe, so that it knows it's kosher?</p>
[ { "answer_id": 74297210, "author": "Flow", "author_id": 14121161, "author_profile": "https://Stackoverflow.com/users/14121161", "pm_score": 0, "selected": false, "text": "import string\n\nalphabet = string.ascii_lowercase\nalphabet_dict = {alphabet[i]: [] for i in range(len(alphabet))}\ninput_list = input(\"Enter a string: \").split(\" \")\nfor word in input_list:\n for letter in word:\n if letter in alphabet_dict:\n alphabet_dict[letter].append(word)\nalphabet_dict = dict(sorted(alphabet_dict.items(), key=lambda item: item[0]))\nprint(alphabet_dict)\n" }, { "answer_id": 74297215, "author": "kosciej16", "author_id": 3361462, "author_profile": "https://Stackoverflow.com/users/3361462", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74297256, "author": "xlm", "author_id": 885922, "author_profile": "https://Stackoverflow.com/users/885922", "pm_score": 1, "selected": false, "text": "words = sentence.split(' ') # Assuming already lowercase\nalphabet_dict = {x: [w for w in words if x in w] for x in ascii_lowercase}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/965136/" ]
74,297,172
<p>I'm very new to Unity and I'm developing a game were the player gets bigger every time they eat a food pellet.</p> <p>I've already implemented the food mechanic but the player doesn't become bigger yet. What would be the best way of going about this? I know I might have to increase the scale of the Collison sphere and game object (duh) and I will have to increase the hight of the camera since it is a top down perspective that's very close to the player character. I know this I just don't know how.</p> <p>I've tried directly setting the scale inside the if statement that controls the eating of the food, no luck.</p> <p>my if statement if that helps:</p> <pre><code>private void OnTriggerEnter(Collider collision) { if (collision.tag == &quot;Food Particle&quot;) { growth += 1; Debug.Log(growth); collision.gameObject.SetActive(false); } } </code></pre> <p>Help would be appreciated!</p>
[ { "answer_id": 74297394, "author": "CS1061", "author_id": 20378590, "author_profile": "https://Stackoverflow.com/users/20378590", "pm_score": 1, "selected": false, "text": "private float scale_min = 1.0f;\nprivate float scale_max = 2.0f;\nprivate float energy_max = 1.0f;\nprivate float energy_current = 0.0f;\n\n// grow the game object\nprivate void UpdateScale()\n{\n\n Vector3 scale = transform.localScale;\n scale.y = scale_min + (scale_max - scale_min) * energy_current;\n transform.localScale = scale;\n\n}\n\n// a method which consumes the food\n// return true when consumed, otherwise false\nprivate bool Feeding(float growth)\n{\n\n if(energy_current >= energy_max)\n return false;\n\n energy_current += growth;\n if (energy_current > energy_max)\n energy_current = energy_max;\n\n return true;\n\n}\n\nprivate void OnTriggerEnter(Collider collision)\n{\n\n if (collision.tag == \"Food Particle\")\n {\n\n // if the food is consumed, remove the food game object\n if(Feeding(0.1f))\n {\n\n collision.gameObject.SetActive(false);\n\n }\n\n }\n\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19153501/" ]
74,297,179
<pre><code>public static int [] makeArray(int n){ int arr[] = new int[n]; for (int i = 0; i &lt; arr.length; i++) { arr[i] = i + 1; } return arr; } public static int hireAssistant1(int[] arr, int n) { ArrayList&lt;Integer&gt; hired = new ArrayList&lt;Integer&gt;(); int best = arr[0]; hired.add(best); for (int i = 1; i &lt; n; i++) { if (arr[i] &lt; best) { best = arr[i]; hired.add(best); } } return hired.size(); } public static void methodThreePerm(List&lt;Integer&gt; list, int n) { int size = factorial(n); int [] arr = new int [list.size()]; arr = toIntArray(list); double sum = 0; for (int i = 0; i &lt; size; i++) { int hires = hireAssistant1(arr, n); if (hires == 2) sum = sum + 1; } System.out.println(&quot;Method 3: s/n! = &quot; + sum /size); } public static int factorial(int n) { if (n == 1) return 1; if (n == 0) return 1; if (n == 2) return 2; return n * factorial(n - 1); } static int[] toIntArray(List&lt;Integer&gt; list) { int[] ret = new int[list.size()]; for(int i = 0; i &lt; ret.length; i++) ret[i] = list.get(i); return ret; } static List&lt;Integer&gt; listToList(List&lt;List&lt;Integer&gt;&gt; list) { List&lt;Integer&gt; flat = list.stream() .flatMap(List::stream) .collect(Collectors.toList()); return flat; } public List&lt;List&lt;Integer&gt;&gt; permute(int[] arr) { List&lt;List&lt;Integer&gt;&gt; list = new ArrayList&lt;&gt;(); permuteHelper(list, new ArrayList&lt;&gt;(), arr); return list; } private void permuteHelper(List&lt;List&lt;Integer&gt;&gt; list, List&lt;Integer&gt; resultList, int[] arr) { if (resultList.size() == arr.length) { list.add(new ArrayList&lt;&gt;(resultList)); } else { for (int i = 0; i &lt; arr.length; i++) { if (resultList.contains(arr[i])) { continue; } resultList.add(arr[i]); permuteHelper(list, resultList, arr); resultList.remove(resultList.size() - 1); } } } public static void main(String[] args) { Assignment8 pa = new Assignment8(); int n = 6; List&lt;List&lt;Integer&gt;&gt; p = pa.permute(makeArray(n)); List&lt;Integer&gt; list = listToList(p); System.out.println(&quot;N = 6&quot;); methodThreePerm(list, n); </code></pre> <p>The expectation is to enumerate all the n! permutations of the arrays of ranks, check - the number of arrays where we hire exactly twice, and output the probability: /!. I have added the base methods needed to check any array, but cant seem to figure out how to send an array of permutations to my hire Assistant method to check for each hire</p>
[ { "answer_id": 74297394, "author": "CS1061", "author_id": 20378590, "author_profile": "https://Stackoverflow.com/users/20378590", "pm_score": 1, "selected": false, "text": "private float scale_min = 1.0f;\nprivate float scale_max = 2.0f;\nprivate float energy_max = 1.0f;\nprivate float energy_current = 0.0f;\n\n// grow the game object\nprivate void UpdateScale()\n{\n\n Vector3 scale = transform.localScale;\n scale.y = scale_min + (scale_max - scale_min) * energy_current;\n transform.localScale = scale;\n\n}\n\n// a method which consumes the food\n// return true when consumed, otherwise false\nprivate bool Feeding(float growth)\n{\n\n if(energy_current >= energy_max)\n return false;\n\n energy_current += growth;\n if (energy_current > energy_max)\n energy_current = energy_max;\n\n return true;\n\n}\n\nprivate void OnTriggerEnter(Collider collision)\n{\n\n if (collision.tag == \"Food Particle\")\n {\n\n // if the food is consumed, remove the food game object\n if(Feeding(0.1f))\n {\n\n collision.gameObject.SetActive(false);\n\n }\n\n }\n\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297179", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402763/" ]
74,297,201
<p>I am stuck with a problem where I have a table with JSON column like this:</p> <pre><code>ID|VALUE 1 |{&quot;a&quot;:&quot;text1234&quot;,&quot;b&quot;:&quot;default&quot;} 2 |{&quot;a&quot;:&quot;text1234&quot;,&quot;b&quot;:&quot;default&quot;} 3 |{&quot;a&quot;:&quot;text1234&quot;,&quot;b&quot;:&quot;text234&quot;} 4 |{&quot;a&quot;:&quot;text1234&quot;,&quot;b&quot;:&quot;default2&quot;} 5 |{&quot;a&quot;:&quot;text1234&quot;,&quot;b&quot;:&quot;default2&quot;} </code></pre> <p>I would like to get all rows where value &quot;b&quot; is duplicate, so with the table above I would get rows 1,2,4,5.</p> <p>I tried to group rows by value-&gt;b</p> <pre><code>$value_ids = ProductsAttributesValues::groupBy(&quot;value-&gt;b&quot;)-&gt;get(); </code></pre> <p>but when i dd($value_ids) rows are not grouped by value-&gt;default. And I can't find a way to group them, so I can then count them. Or would there be a better way with doing this?</p>
[ { "answer_id": 74297394, "author": "CS1061", "author_id": 20378590, "author_profile": "https://Stackoverflow.com/users/20378590", "pm_score": 1, "selected": false, "text": "private float scale_min = 1.0f;\nprivate float scale_max = 2.0f;\nprivate float energy_max = 1.0f;\nprivate float energy_current = 0.0f;\n\n// grow the game object\nprivate void UpdateScale()\n{\n\n Vector3 scale = transform.localScale;\n scale.y = scale_min + (scale_max - scale_min) * energy_current;\n transform.localScale = scale;\n\n}\n\n// a method which consumes the food\n// return true when consumed, otherwise false\nprivate bool Feeding(float growth)\n{\n\n if(energy_current >= energy_max)\n return false;\n\n energy_current += growth;\n if (energy_current > energy_max)\n energy_current = energy_max;\n\n return true;\n\n}\n\nprivate void OnTriggerEnter(Collider collision)\n{\n\n if (collision.tag == \"Food Particle\")\n {\n\n // if the food is consumed, remove the food game object\n if(Feeding(0.1f))\n {\n\n collision.gameObject.SetActive(false);\n\n }\n\n }\n\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12251039/" ]
74,297,326
<p>I am trying to figure out a way to &quot;automate&quot; a task in google sheets. I have a data model that lists all the data on one sheet of all the 'hit percentages' of sports props. The data changes as games complete. I'd like to have check boxes(or something similar) next to the rows that when it's checked it copies that row and then adds it into a sheet called 'Logs&quot; after the last row.</p> <p>I put this sheet together as an example:</p> <p><a href="https://docs.google.com/spreadsheets/d/1KocfnKXK1sPmBr3uQfcn8dC6MYV0JUWDz5Ql3AgTMEI/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1KocfnKXK1sPmBr3uQfcn8dC6MYV0JUWDz5Ql3AgTMEI/edit?usp=sharing</a></p>
[ { "answer_id": 74297476, "author": "Tanaike", "author_id": 7108653, "author_profile": "https://Stackoverflow.com/users/7108653", "pm_score": 2, "selected": false, "text": "function onEdit(e) {\n const srcSheetName = \"Changing Data\"; // This is from your sample Spreadsheet.\n const dstSheetName = \"Log\"; // This is from your sample Spreadsheet.\n\n const { range, source } = e;\n const sheet = range.getSheet();\n if (sheet.getSheetName() != srcSheetName || range.columnStart != 2 || !range.isChecked()) return;\n const dstSheet = source.getSheetByName(dstSheetName);\n range.offset(0, -1, 1, 2).copyTo(dstSheet.getRange(dstSheet.getLastRow() + 1, 1));\n}\n" }, { "answer_id": 74297527, "author": "Cooper", "author_id": 7215091, "author_profile": "https://Stackoverflow.com/users/7215091", "pm_score": 2, "selected": false, "text": "function onEdit(e) {\n //e.source.toast(\"Entry\");\n const sh = e.range.getSheet();\n if(sh.getName() == \"Sheet0\" && e.range.columnStart == 7 && e.range.rowStart > 1 && e.value == \"TRUE\") {\n //e.source.toast(\"Gate1\");\n e.source.toast(\"Gate1\"); \n const lsh = e.source.getSheetByName(\"Log\");\n const vs = sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).getValues();\n lsh.getRange(lsh.getLastRow() + 1, 1,vs.length,vs[0].length).setValues(vs);\n }\n}\n" }, { "answer_id": 74297724, "author": "SputnikDrunk2", "author_id": 15384825, "author_profile": "https://Stackoverflow.com/users/15384825", "pm_score": 1, "selected": false, "text": "onEdit()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19823260/" ]
74,297,331
<p>I am looping over the people array and getting the first array. My screen should say &quot;person 1&quot;. but it is blank and nothing is being returned.</p> <pre><code>const people = [ [ { name: 'person 1' } ], [ { name: 'person 2' } ], ] export default function Index() { return ( &lt;&gt; {people.slice(0,1).map((person) =&gt; { return &lt;h1&gt;{person.name}&lt;/h1&gt; })} &lt;/&gt; ) } </code></pre> <p>the code works when i do this, but I need to use slice</p> <pre><code>export default function Index() { return ( &lt;&gt; {people[0].map((person) =&gt; { return &lt;h1&gt;{person.name}&lt;/h1&gt; })} &lt;/&gt; ) } </code></pre>
[ { "answer_id": 74297374, "author": "Caio Amorim", "author_id": 17854639, "author_profile": "https://Stackoverflow.com/users/17854639", "pm_score": 1, "selected": false, "text": " return (\n <>\n {people.slice(0,1).map((person) => {\n return <h1>{person[0].name}</h1>\n })} \n </>\n )\n" }, { "answer_id": 74297419, "author": "ChanHyeok-Im", "author_id": 6329353, "author_profile": "https://Stackoverflow.com/users/6329353", "pm_score": 1, "selected": false, "text": "people" }, { "answer_id": 74297471, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 2, "selected": false, "text": "people.slice(0, 1)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19666029/" ]
74,297,332
<p>I have custom array-like object, with all the array methods, which acts as an array, but <code>Object.prototype.toString.call(myArrayLikeObj)</code> returns <code>[object Object]</code> not <code>[object Array]</code></p> <p>How to prepare my object to return <code>[object Array]</code>?</p> <p>Can I see somewhere <code>Object.toString</code> source code?</p>
[ { "answer_id": 74297374, "author": "Caio Amorim", "author_id": 17854639, "author_profile": "https://Stackoverflow.com/users/17854639", "pm_score": 1, "selected": false, "text": " return (\n <>\n {people.slice(0,1).map((person) => {\n return <h1>{person[0].name}</h1>\n })} \n </>\n )\n" }, { "answer_id": 74297419, "author": "ChanHyeok-Im", "author_id": 6329353, "author_profile": "https://Stackoverflow.com/users/6329353", "pm_score": 1, "selected": false, "text": "people" }, { "answer_id": 74297471, "author": "code", "author_id": 15359157, "author_profile": "https://Stackoverflow.com/users/15359157", "pm_score": 2, "selected": false, "text": "people.slice(0, 1)" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/447952/" ]
74,297,334
<p>I recently made the transition from using a Mac with an Intel processor, to one with an M1 processor.</p> <p>Being a Windows Developer, this forced me to recreate my Virtual Machines (1 have 1 per Visual Studio version), until recently each VM had 1 shared issue: a lack of a working IIS.</p> <p>A rather annoying problem, but most of the stuff I do at the moment is in the desktop world, where I don't need a working IIS.</p> <p>Recently I accepted a project where I would need IIS, and I was consequently very happy when I noticed Windows 11 for ARM finally does support IIS.</p> <p>I decided to start from scratch and created a new VM with windows 11 pro. After installing I joined it to my Windows domain and attempted to install IIS on it.</p> <p>1st attempt failed, 2nd worked flawlessly... but IIS does not want to run.</p> <p>Whenever I try to start the service I get the following error:</p> <p><a href="https://i.stack.imgur.com/u1Fww.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u1Fww.jpg" alt="enter image description here" /></a></p> <p>Does anyone here have any idea what this is caused by, and what I can do to fix this?</p>
[ { "answer_id": 74300842, "author": "YurongDai", "author_id": 19696445, "author_profile": "https://Stackoverflow.com/users/19696445", "pm_score": 1, "selected": true, "text": "c:/> ​​iisreset /restart\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/975748/" ]
74,297,346
<p>I use DAX to add two new columns &quot;netWeight_Shipped&quot; and &quot;NetWeight_notShipped&quot; based on existing column &quot;NetWeight_Total&quot; and groupped by &quot;BatchNo&quot; and filtered by OutStockTransactionID as below:</p> <p>--New column</p> <pre><code> NetWeight_Shipped = CALCULATE( SUM(Fact_ShippingKPI[NetWeight_Total]) ,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo]) ,Fact_ShippingKPI[OutStockTransactionID] &lt;&gt; 0 ) </code></pre> <p>--New column</p> <pre><code>NetWeight_notShipped = CALCULATE( SUM(Fact_ShippingKPI[NetWeight_Total]) ,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo]) ,Fact_ShippingKPI[OutStockTransactionID] = 0 ) </code></pre> <p>Then put those columns on table as the screenshot. However, two new columns not showing total values in table.</p> <p><a href="https://i.stack.imgur.com/oq4eq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oq4eq.png" alt="enter image description here" /></a> What should I change to have total values for those new columns?</p>
[ { "answer_id": 74299919, "author": "M. P.", "author_id": 20396112, "author_profile": "https://Stackoverflow.com/users/20396112", "pm_score": 2, "selected": true, "text": "NetWeight_Shipped = CALCULATE(\n SUM(Fact_ShippingKPI[NetWeight_Total])\n ,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])\n ,Fact_ShippingKPI[OutStockTransactionID] <> 0\n )\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14142514/" ]
74,297,382
<p>I am trying to write a piece of code that instead of checking file extensions for the many different types of image files, but instead looking at the file attributes. What I can’t figure out from searching the docs is if <code>KIND:Image</code> is really a file attribute or simply a construct Apple created in the FinderApp to make things easier for the user.</p> <p>I wrote a snippet that pulls the attributes for files with an extension of jpeg and for each file the fileType is returned as <code>NSFileTypeRegular</code>.</p> <pre><code>let attr = try filemanager.attributesOfItem(atPath: pathConfig+&quot;/&quot;+file) as NSDictionary if file.hasSuffix(ext) {    print (&quot;Adding \(file) [ \(attr.fileSize()) \(attr.fileType())]&quot;)    print ( attr.fileModificationDate() ) } </code></pre> <p>Does anybody know if MacOS retains an attribute for the category a file falls in to. e.g. <code>IMAGE</code>, <code>DOCUMENT</code> etc.</p>
[ { "answer_id": 74297549, "author": "EmilioPelaez", "author_id": 725628, "author_profile": "https://Stackoverflow.com/users/725628", "pm_score": 3, "selected": true, "text": "UTType" }, { "answer_id": 74309237, "author": "JobbingCoder", "author_id": 20402989, "author_profile": "https://Stackoverflow.com/users/20402989", "pm_score": 0, "selected": false, "text": "func imagesInDir(path: String?) -> [String] {\n if let path {\n let filemanager: FileManager = FileManager()\n let files = filemanager.enumerator(atPath: path)\n var array = [String]()\n var urlFile: NSURL\n \n while let file = files?.nextObject() as? String {\n urlFile = NSURL(fileURLWithPath: file, isDirectory: false)\n if (urlFile.isFileURL) {\n if let pathExt = urlFile.pathExtension {\n if let fileType = UTType(filenameExtension: pathExt) {\n let isImage = fileType.conforms(to: .image)\n if (isImage){\n array.append(file)\n print (\"\\(array.count) \\(fileType)\")\n }\n }\n }\n }\n }\n }\n return array\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297382", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20402989/" ]
74,297,467
<p>First of all, I am aware of several similar (<a href="https://stackoverflow.com/questions/53998845">53998845</a>, <a href="https://stackoverflow.com/questions/71087512">71087512</a>, <a href="https://stackoverflow.com/questions/71269113">71269113</a>) and related (<a href="https://stackoverflow.com/questions/28840047">28840047</a>, <a href="https://stackoverflow.com/questions/44224952">44224952</a>) questions, but I believe that none of them exactly captures the same situation that I am encountering.</p> <p>I am using a <code>ConcurrentHashMap</code> as a cache for some runtime-generated Java classes. Specifically, I use <code>computeIfAbsent</code> to either return a previously generated class, or generate the class on the fly. In some circumstances, this call throws an <code>IllegalStateException: Recursive update</code>. An example stack trace looks like this:</p> <pre><code>java.lang.IllegalStateException: Recursive update at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1742) at pro.projo.internal.rcg.RuntimeCodeGenerationHandler.getImplementationOf(RuntimeCodeGenerationHandler.java:151) at pro.projo.Projo.getImplementationClass(Projo.java:451) at pro.projo.Projo.getImplementationClass(Projo.java:438) at fxxx.natives.bootstrap.Bootstrap$1.lambda$configure$2(Bootstrap.java:63) at java.base/java.util.ArrayList.forEach(ArrayList.java:1510) at fxxx.natives.bootstrap.Bootstrap$1.configure(Bootstrap.java:76) at com.google.inject.AbstractModule.configure(AbstractModule.java:66) at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:409) at com.google.inject.spi.Elements.getElements(Elements.java:108) at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:160) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) at com.google.inject.Guice.createInjector(Guice.java:87) at com.google.inject.Guice.createInjector(Guice.java:69) at com.google.inject.Guice.createInjector(Guice.java:59) at fxxx.natives.bootstrap.Bootstrap.&lt;init&gt;(Bootstrap.java:89) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:782) at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:724) at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1396) at java.base/java.util.ServiceLoader.findFirst(ServiceLoader.java:1811) at fxxx.bootstrap.Bootstrap.load(Bootstrap.java:34) at fxxx.test.junit.FxxxTestClassTestDescriptor.instantiateTestClass(FxxxTestClassTestDescriptor.java:27) </code></pre> <p>As far as I am aware, I am not violating <code>ConcurrentHashMap.computeIfAbsent</code>'s requirement that &quot;<em>The mapping function must not modify this map during computation</em>&quot;, as that function is a pure function without side effects. For the other requirement, that &quot;<em>the computation should be short and simple</em>&quot;, my code's compliance is not as clear cut, since generating the classes on the fly is definitely an involved and expensive process (hence the caching).</p> <p>I do, however, believe that the exception's claimed &quot;<em>Recursive update</em>&quot; is an incorrect assessment of what is actually going on here. If that were indeed the case, I would expect to see multiple occurrences of my code's call to <code>CHM.computeIfAbsent</code> in the stack trace, but this is not what I see (not in the example stack trace, or any other stack trace that I've seen with this problem).</p> <p>The code in <code>CHM</code> is as follows:</p> <pre><code>1738 Node&lt;K,V&gt; pred = e; 1739 if ((e = e.next) == null) { 1740 if ((val = mappingFunction.apply(key)) != null) { 1741 if (pred.next != null) 1742 throw new IllegalStateException(&quot;Recursive update&quot;); 1743 added = true; 1744 pred.next = new Node&lt;K,V&gt;(h, key, val); 1745 } 1746 break; 1747 } </code></pre> <p>From the stack trace, I already know that this is not a recursive call to <code>computeIfAbsent</code> from within another <code>computeIfAbsent</code> invocation. The code saves a reference to the previous node as <code>pred</code> (line 1738) and then updates <code>e</code> to the next node (line 1739). Since we made it past the <code>if</code> check, we know that the original <code>e</code>'s <code>next</code> value was <code>null</code>, therefore <code>pred.next</code> should at this point also be <code>null</code>. However, a subsequent check (line 1741) reveals that <code>pred</code> next is no longer <code>null</code> (which triggers the exception). As a <em>recursive</em> update is not corroborated by the stack trace, I am assuming that this must actually be a <em>concurrent</em> update instead. It appears that the original <code>e</code> object, now known as <code>pred</code>, has its <code>next</code> pointer changed by another thread (<code>java.util.concurrent.ConcurrentHashMap.Node</code> produces mutable objects, unfortunately).</p> <p>I am using <code>CHM</code> for the one reason that this caching mechanism must be thread-safe and have low overhead (i.e., no blanket locking). I would expect concurrent update of the cache to work. However, in this particular scenario, <em>concurrent</em> access does <em>not</em> work, and seems to be incorrectly classified as a <em>recursive</em> update instead.</p> <p>For further context, my own code that invokes <code>computeIfAbsent</code> looks like this:</p> <pre><code>public Class&lt;? extends _Artifact_&gt; getImplementationOf(Class&lt;_Artifact_&gt; type, boolean defaultPackage) { return implementationClassCache.computeIfAbsent(type, it -&gt; generateImplementation(it, defaultPackage)); } </code></pre> <p>This code is from a utility library that needs to work on Java 8, but I've only ever seen the exception happen when the code is used from another project that's running on Java 11.</p> <p>Is this another bug in <code>ConcurrentHashMap</code> or am I overlooking something regarding the proper use of this class?</p>
[ { "answer_id": 74297549, "author": "EmilioPelaez", "author_id": 725628, "author_profile": "https://Stackoverflow.com/users/725628", "pm_score": 3, "selected": true, "text": "UTType" }, { "answer_id": 74309237, "author": "JobbingCoder", "author_id": 20402989, "author_profile": "https://Stackoverflow.com/users/20402989", "pm_score": 0, "selected": false, "text": "func imagesInDir(path: String?) -> [String] {\n if let path {\n let filemanager: FileManager = FileManager()\n let files = filemanager.enumerator(atPath: path)\n var array = [String]()\n var urlFile: NSURL\n \n while let file = files?.nextObject() as? String {\n urlFile = NSURL(fileURLWithPath: file, isDirectory: false)\n if (urlFile.isFileURL) {\n if let pathExt = urlFile.pathExtension {\n if let fileType = UTType(filenameExtension: pathExt) {\n let isImage = fileType.conforms(to: .image)\n if (isImage){\n array.append(file)\n print (\"\\(array.count) \\(fileType)\")\n }\n }\n }\n }\n }\n }\n return array\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1932890/" ]
74,297,497
<p>Work asked me to do some work on this older app that no one really manages anymore. One thing that the client had asked for was to remove this black dot in the top right of the header: <a href="https://i.stack.imgur.com/9rWrr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9rWrr.jpg" alt="enter image description here" /></a></p> <p>Here is the code for that:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt; &lt;div class="col-md-1" style="background-color: #F6861F"&gt;&lt;/div&gt; &lt;div class="col-md-1" style="background-color: #DD1372"&gt;&lt;/div&gt; &lt;div class="col-md-2" style="background-color: #41AD49"&gt;&lt;/div&gt; &lt;div class="col-md-2" style="background-color: #00AAC0"&gt;&lt;/div&gt; &lt;div class="col-md-2" style="background-color: #D32027"&gt;&lt;/div&gt; &lt;div class="col-md-2" style="background-color: #F49AC1"&gt;&lt;/div&gt; &lt;div class="col-md-1" style="background-color: #EBB700"&gt;&lt;/div&gt; &lt;div class="col-md-1" style="background-color: #00ADE4"&gt;&amp;#9632;&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>First of all, what even is this in the last col? <code>&amp;#9632;</code> If I remove that the entire colored row there disappears all together. How can I get rid of that black dot? Is there not a cleaner way to do this in the first place?</p>
[ { "answer_id": 74300390, "author": "Nensi Gondaliya", "author_id": 18952547, "author_profile": "https://Stackoverflow.com/users/18952547", "pm_score": 1, "selected": false, "text": "<div class=\"row\">\n <div class=\"col-md-1\" style=\"background-color: #F6861F\"></div>\n <div class=\"col-md-1\" style=\"background-color: #DD1372\"></div>\n <div class=\"col-md-2\" style=\"background-color: #41AD49\"></div>\n <div class=\"col-md-2\" style=\"background-color: #00AAC0\"></div>\n <div class=\"col-md-2\" style=\"background-color: #D32027\"></div>\n <div class=\"col-md-2\" style=\"background-color: #F49AC1\"></div>\n <div class=\"col-md-1\" style=\"background-color: #EBB700\"></div>\n <div class=\"col-md-1\" style=\"background-color: #00ADE4\">&nbsp;</div>\n</div>\n" }, { "answer_id": 74312062, "author": "ChanHyeok-Im", "author_id": 6329353, "author_profile": "https://Stackoverflow.com/users/6329353", "pm_score": 3, "selected": true, "text": "&nbsp;" }, { "answer_id": 74312160, "author": "ethry", "author_id": 16030830, "author_profile": "https://Stackoverflow.com/users/16030830", "pm_score": 1, "selected": false, "text": "&#9632;" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14108804/" ]
74,297,513
<p>So when I pass a data type like a struct to assign some memory to it I find that the pointer doesn't change within the main scope. This further becomes a problem when I try to free the memory but obviously if its using the original pointer it will be pointing at the stack address.</p> <pre><code>void allocate(int *value){ value = malloc(10 * sizeof(int)); } int main(){ int val2; allocate(&amp;val2); free(&amp;val2); return 0; } </code></pre> <p>I can fix this by using a double pointer to be passed into the allocate function but some course work I'm doing requires to only pass a pointer and I cant get it to update the pointer when it returns to main. I have looked around for a while but cant find a straight forward answer, I feel like my coursework is wrong but that might be my lack of understanding.</p>
[ { "answer_id": 74300390, "author": "Nensi Gondaliya", "author_id": 18952547, "author_profile": "https://Stackoverflow.com/users/18952547", "pm_score": 1, "selected": false, "text": "<div class=\"row\">\n <div class=\"col-md-1\" style=\"background-color: #F6861F\"></div>\n <div class=\"col-md-1\" style=\"background-color: #DD1372\"></div>\n <div class=\"col-md-2\" style=\"background-color: #41AD49\"></div>\n <div class=\"col-md-2\" style=\"background-color: #00AAC0\"></div>\n <div class=\"col-md-2\" style=\"background-color: #D32027\"></div>\n <div class=\"col-md-2\" style=\"background-color: #F49AC1\"></div>\n <div class=\"col-md-1\" style=\"background-color: #EBB700\"></div>\n <div class=\"col-md-1\" style=\"background-color: #00ADE4\">&nbsp;</div>\n</div>\n" }, { "answer_id": 74312062, "author": "ChanHyeok-Im", "author_id": 6329353, "author_profile": "https://Stackoverflow.com/users/6329353", "pm_score": 3, "selected": true, "text": "&nbsp;" }, { "answer_id": 74312160, "author": "ethry", "author_id": 16030830, "author_profile": "https://Stackoverflow.com/users/16030830", "pm_score": 1, "selected": false, "text": "&#9632;" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12493959/" ]
74,297,521
<p>I am looping through a list and would like to reference the loop index number in the key of a hash.</p> <p>Example:</p> <pre><code> unit_type = Hash.new index = 5 list.each do |x| unit_type[:loop_[index]] = x index = index + 1 end </code></pre> <p>The resulting key hash value should be:</p> <pre><code> unit_type = {:loop_5 #&gt; &quot;test result&quot;} </code></pre> <p>How can I pass the index number in the key title together with other text as shown above?</p>
[ { "answer_id": 74300390, "author": "Nensi Gondaliya", "author_id": 18952547, "author_profile": "https://Stackoverflow.com/users/18952547", "pm_score": 1, "selected": false, "text": "<div class=\"row\">\n <div class=\"col-md-1\" style=\"background-color: #F6861F\"></div>\n <div class=\"col-md-1\" style=\"background-color: #DD1372\"></div>\n <div class=\"col-md-2\" style=\"background-color: #41AD49\"></div>\n <div class=\"col-md-2\" style=\"background-color: #00AAC0\"></div>\n <div class=\"col-md-2\" style=\"background-color: #D32027\"></div>\n <div class=\"col-md-2\" style=\"background-color: #F49AC1\"></div>\n <div class=\"col-md-1\" style=\"background-color: #EBB700\"></div>\n <div class=\"col-md-1\" style=\"background-color: #00ADE4\">&nbsp;</div>\n</div>\n" }, { "answer_id": 74312062, "author": "ChanHyeok-Im", "author_id": 6329353, "author_profile": "https://Stackoverflow.com/users/6329353", "pm_score": 3, "selected": true, "text": "&nbsp;" }, { "answer_id": 74312160, "author": "ethry", "author_id": 16030830, "author_profile": "https://Stackoverflow.com/users/16030830", "pm_score": 1, "selected": false, "text": "&#9632;" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14809518/" ]
74,297,600
<blockquote> <p>Hi guys, I'm newbie in node.js. I have function, that leads the dialogue with user in console. In newSwagger function I call the bumpDiff function, that shows changes between 2 files.</p> </blockquote> <pre><code>async function bumpDiff = () =&gt; { exec('bump diff swagger.json newSwagger.json', (err, output) =&gt; { // once the command has completed, the callback function is called if (err) { // log and return if we encounter an error console.error(&quot;could not execute command: &quot;, err) return } // log the output received from the command console.log(&quot;Output: \n&quot;, output) }) }; const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const question = (str) =&gt; new Promise(resolve =&gt; rl.question(str, resolve)); const steps = { start: async () =&gt; { return steps.changeSwagger(); }, changeSwagger: async () =&gt; { const addSwagger = await request(); console.log('success'); const changeSwagger = await question(&quot;Would you like to check changes in swagger? Please type yes/no: &quot;); if (changeSwagger === 'yes') { return steps.newSwagger(); } if (changeSwagger === 'no') { return steps.oldSwagger(); } return steps.end(); }, newSwagger: async () =&gt; { console.log('showing changes'); const diff = await bumpDiff(); const ask = await question('Would you like to change swagger? Please type yes/no: '); if (ask === 'yes') { return steps.changing(); } if (ask === 'no') { return steps.end(); } }, changing: async () =&gt; { const rebuildSwagger = await SwaggerNew(); console.log('swagger changed successfully'); return steps.end(); }, oldSwagger: async () =&gt; { console.log('No worries, have a nice day'); return steps.end(); }, end: async () =&gt; { rl.close(); }, }; steps.start(); </code></pre> <p>The problems is: when bumpDiff is starting, next readline</p> <pre><code>'Would you like to change swagger? Please type yes/no: ' </code></pre> <p>come faster, then changes appeares. I guess I'm missing something about promises, can you help me find the mistake please. P.S. all other functions, like 'request' and 'SwaggerNew' are async.</p>
[ { "answer_id": 74297669, "author": "JuanDM", "author_id": 2860519, "author_profile": "https://Stackoverflow.com/users/2860519", "pm_score": 1, "selected": false, "text": "bumpDiff" }, { "answer_id": 74297675, "author": "hackape", "author_id": 3617380, "author_profile": "https://Stackoverflow.com/users/3617380", "pm_score": 1, "selected": true, "text": "exec" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20375120/" ]
74,297,627
<p>I'm in the process of transitioning my single site WordPress installation into a multi-site. I'm trying to fix the broken CSS/JS from my main site.</p> <p>I currently have two sites on my network:</p> <ul> <li><a href="http://www.example.com" rel="noreferrer">http://www.example.com</a> (primary)</li> <li><a href="http://dev.example.com" rel="noreferrer">http://dev.example.com</a> (secondary)</li> </ul> <p>My multi-site installation is inside of a subdirectory we will call &quot;<strong>wordpress</strong>&quot;. So the file path looks like <code>public_html/wordpress</code>.</p> <p><strong>My goal is for neither site to have the &quot;wordpress&quot; subdirectory in the URL. Everything seems to be working except for broken CSS and JS on the primary site (the secondary site looks fine).</strong></p> <p>When inspecting the code, all of the CSS and JS calls point to <a href="http://www.example.com/wp-content/" rel="noreferrer">http://www.example.com/wp-content/</a> but the files are not found there. The files will be found if I go to <a href="http://www.example.com/wordpress/wp-content" rel="noreferrer">http://www.example.com/wordpress/wp-content</a> in my browser. I want to hide the wordpress folder and still be able to retrieve the files.</p> <p>I'm confused on how to setup the HTACCESS file. I already made some initial changes to it in order to get the multi-site within the subdirectory working. These were all following guides I found on StackOverflow and elsewhere online in regard to how to move your site into a multi-site with subdirectory and hiding the subdirectory. I haven't found anything about addressing the broken CSS/JS issue.</p> <p>I figured I need to make updates to one or more of 3 HTACCESS files.</p> <p><strong>1.) public_html/.htaccess</strong></p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteCond %{REQUEST_URI} !^/wordpress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /wordpress/$1 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteRule ^(/)?$ /wordpress/index.php [L] &lt;/IfModule&gt; </code></pre> <p><strong>2.) public_html/wordpress/.htaccess</strong></p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] &lt;/IfModule&gt; </code></pre> <p><strong>3.) public_html/wordpress/wp-content/.htaccess</strong> This file didn't exist but I created it. My thinking was that files are being called without the wordpress subdirectory but they need to act like they have the subdirectory included in them. For example, currently <a href="http://www.example.com/wp-content/uploads/image.jpg" rel="noreferrer">http://www.example.com/wp-content/uploads/image.jpg</a> is broken but <a href="http://www.example.com/wordpress/wp-content/uploads/image.jpg" rel="noreferrer">http://www.example.com/wordpress/wp-content/uploads/image.jpg</a> works. I want it to be the other way around or I want both paths to work.</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine on # ADD WORDPRESS IF URL DOES NOT HAVE IT RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteCond %{REQUEST_URI} !^/wordpress/ RewriteRule ^(.*)$ /wordpress/$1 &lt;/IfModule&gt; </code></pre> <p>I've tried adding different lines to the various HTACCESS files but none of them worked. I also not sure what line number I should insert a new rule. It's possible that one of my new rules is correct but it is in the wrong place. Below is one that I really thought would work but didn't.</p> <pre><code>RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L] </code></pre>
[ { "answer_id": 74341687, "author": "mlegrix", "author_id": 2561548, "author_profile": "https://Stackoverflow.com/users/2561548", "pm_score": 1, "selected": false, "text": ".htaccess" }, { "answer_id": 74382722, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 2, "selected": false, "text": ".htaccess" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1102591/" ]
74,297,631
<p>I am trying to get data from a jsonb column and need to cast an attribute from the payload to timestamp. But the query aborts when the value is null or invalid.</p> <p>This is my select statement.</p> <pre><code>Select (jsonb_path_query(AnchorNode, '$.TestDate')#&gt;&gt; '{}')::timestamp as TestDate From ( Select jsonb_path_query_first(payload, '$.node1[*].node2[*]') as AnchorNode From TestTable ) subq1 </code></pre> <p>The invalid values could be only the Date or null.</p> <p>How can I change the query to handle this. There are about 7 or 8 date fields where I would need to do this</p> <p>Thank you</p>
[ { "answer_id": 74341687, "author": "mlegrix", "author_id": 2561548, "author_profile": "https://Stackoverflow.com/users/2561548", "pm_score": 1, "selected": false, "text": ".htaccess" }, { "answer_id": 74382722, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 2, "selected": false, "text": ".htaccess" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/913749/" ]
74,297,655
<p>This problem requires me to find the frequency analysis of a .txt file.</p> <p>This is my code so far: This finds the frequency of the words, but how would I get the frequency of the actual letters?</p> <pre><code>f = open('cipher.txt', 'r') word_count = [] for c in f: word_count.append(c) word_count.sort() decoding = {} for i in word_count: decoding[i] = word_count.count(i) for n in decoding: print(decoding) </code></pre> <p>This outputs (as a short example, since the txt file is pretty long):</p> <pre><code>{'\n': 12, 'vlvf zev jvg jrgs gvzef\n': 1, 'z uvfgriv sbhfv bu wboof!\n': 1, &quot;gsv yrewf zoo nbhea zaw urfsvf'\n&quot;: 1, 'xbhow ube gsv avj bjave yv\n': 1, ' gsv fcerat rf czffrat -\n': 1, 'viva gsrf tezff shg\n': 1, 'bph ab sbfbnrxsr (azeebj ebzw gb gsv wvvc abegs)\n': 1, 'cbfg rafrwv gsv shg.\n': 1, 'fb gszg lvze -- gsv fvxbaw lvze bu tvaebph [1689] -- r szw fhwwvaol gzpva\n': 1, 'fb r czgxsvw hc nl gebhfvef, chg avj xbewf ra nl fgezj szg, zaw\n': 1, 'fcrergf bu gsv ebzw yvxpbavw nv, zaw r xbhow abg xbaxvagezgv ba zalgsrat.\n': 1, 'fgbbw zg gsv xebffebzwf bu czegrat, r jvcg tbbwylv.\n': 1, </code></pre> <p>It gives me the words, but how would I get the letters, such as how many &quot;a&quot;'s there are, or how many &quot;b&quot;'s there are?</p>
[ { "answer_id": 74341687, "author": "mlegrix", "author_id": 2561548, "author_profile": "https://Stackoverflow.com/users/2561548", "pm_score": 1, "selected": false, "text": ".htaccess" }, { "answer_id": 74382722, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 2, "selected": false, "text": ".htaccess" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20335327/" ]
74,297,707
<p>I want to write a PySpark snippet of code that first reads some data in the form of a text file from a Cloud Storage bucket. The text file contains paragraphs of text separated by newline characters, words are also separated using space characters.</p> <p>I need to calculate the 10 highest-frequency words in the given text file.</p> <pre class="lang-py prettyprint-override"><code>import pyspark from pyspark import SparkConf, SparkContext from google.cloud import storage import sys conf = SparkConf().setMaster(&quot;local&quot;).setAppName(&quot;some paragraph&quot;) sc = SparkContext(conf=conf) bucket_name = (sys.argv[1]) destination_blob_name = (sys.argv[2]) storage_client = storage.Client() bucket = storage_client.bucket(bucket_name) blob = bucket.blob(destination_blob_name) downloaded_blob = blob.download_as_string() print(downloaded_blob) print(blob) def words(): alist = {} for line in blob: fields = line.split(&quot;|&quot;) print(fields) movies[int(fields[0])]=fields[1] return movies myline = words() myRDD = sc.parallelize([myline]) print(myRDD.collect()) </code></pre>
[ { "answer_id": 74341687, "author": "mlegrix", "author_id": 2561548, "author_profile": "https://Stackoverflow.com/users/2561548", "pm_score": 1, "selected": false, "text": ".htaccess" }, { "answer_id": 74382722, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 2, "selected": false, "text": ".htaccess" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15651317/" ]
74,297,709
<p>For the <code>DataFrame df</code> below</p> <pre><code>df = pd.DataFrame([('Tesla','Model3', '-', 'Motor'), ('Tesla', 'ModelS', '-', 'MotorMD3'), ('Tesla', 'ModelX', '-', 'MotorMD3'), ('Tesla', 'ModelY', '-', 'Motor'), ('Jeep', 'Wrangler','Grouped','Engine'), ('Jeep', 'Compass', 'Grouped','EngineMD3'), ('Jeep', 'Patriot', 'Grouped','Engine'), ('Jeep', 'Cherokee','Grouped','Engine'), ('Ford', 'Mustang', 'Grouped','Engine'), ('Ford', 'F150', 'Grouped','Engine') ],columns=['Make','Model','Status','Type']) df Make Model Status Type 0 Tesla Model3 - Motor 1 Tesla ModelS - MotorMD3 2 Tesla ModelX - MotorMD3 3 Tesla ModelY - Motor 4 Jeep Wrangler Grouped Engine 5 Jeep Compass Grouped EngineMD3 6 Jeep Patriot Grouped Engine 7 Jeep Cherokee Grouped Engine 8 Ford Mustang Grouped Engine 9 Ford F150 Grouped Engine </code></pre> <p>I am trying to update the column <code>Type</code> with <code>EngineMD3</code> for all same <code>Make</code>, if <code>EngineMD3</code> is present in any of the <code>Models</code> in that <code>Make</code>, and if the <code>Status</code> is <code>Grouped</code> for that <code>Make</code>. But if the <code>Status</code> is not <code>Grouped</code>, <code>Type</code> should be kept as such for each <code>Models</code>. If 'EngineMD3' is not present the <code>Type</code> should be maintained as <code>Engine</code>.</p> <p>For instance, <code>Tesla</code> is not <code>Grouped</code>, so each model keeps their <code>Type</code> the same. But <code>Jeep</code> is <code>Grouped</code>, and <code>Compass</code> is having its <code>Type</code> as <code>EngineMD3</code>, so <code>EngineMD3</code> is updated as the <code>Type</code> for all <code>Jeep</code> <code>Models</code>. <code>Ford</code> is <code>Grouped</code> but none of the <code>Models</code> have type <code>EngineMD3</code> so <code>Type</code> is kept as <code>Engine</code></p> <p>Expected output</p> <pre><code> Make Model Status Type 0 Tesla Model3 - Motor #For Tesla Type is maintained for each model seperately since it is not grouped 1 Tesla ModelS - MotorMD3 2 Tesla ModelX - MotorMD3 3 Tesla ModelY - Motor 4 Jeep Wrangler Grouped EngineMD3 #Since Jeep is grouped, all its Type is changed to EngineMD3 since one of the model had EngineMD3 5 Jeep Compass Grouped EngineMD3 6 Jeep Patriot Grouped EngineMD3 7 Jeep Cherokee Grouped EngineMD3 8 Ford Mustang Grouped Engine #Even though Ford is grouped, since there is no EngineMD3 the Type is maintained as Engine. 9 Ford F150 Grouped Engine </code></pre> <p>In other words, The conditions are for all the <code>makes</code>(eg. Jeeps) If the <code>make</code> is grouped and if <code>FD3</code> is appended to any of the model <code>types</code>, then all the grouped models in the same <code>make</code> will have the FD3 appended to them</p> <p>I tried to use <code>np.select</code> to update the <code>Type</code> column with multiple conditions but I couldn't give a condition to select all same <code>Make</code> at once and update the <code>Type</code>. Please do help I am running out of options here.</p>
[ { "answer_id": 74341687, "author": "mlegrix", "author_id": 2561548, "author_profile": "https://Stackoverflow.com/users/2561548", "pm_score": 1, "selected": false, "text": ".htaccess" }, { "answer_id": 74382722, "author": "Valeriu Ciuca", "author_id": 4527645, "author_profile": "https://Stackoverflow.com/users/4527645", "pm_score": 2, "selected": false, "text": ".htaccess" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,297,721
<p>I have this google sheets input.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Players</th> <th>Loot</th> </tr> </thead> <tbody> <tr> <td>Player1</td> <td>4</td> </tr> <tr> <td>Player2</td> <td>4</td> </tr> <tr> <td>Player3</td> <td>5</td> </tr> <tr> <td>Player4</td> <td>2</td> </tr> </tbody> </table> </div> <p>What I'm attempting to do is simplify this formula in order to get <code>TRUE</code> in a single cell.</p> <pre><code>=OR(B2&gt;=5,B3&gt;=5,B4&gt;=5,B5&gt;=5) </code></pre> <p>This is what i did so far.</p> <pre><code>=ArrayFormula(SUM((B2:B5*1&gt;=5)*1))&gt;0 </code></pre> <p>Can this formula be simplied further and still get <code>TRUE</code> <strong>in a single cell</strong> when one of Loot values is <code>&gt;=</code> 5?</p>
[ { "answer_id": 74298224, "author": "Harun24hr", "author_id": 5514747, "author_profile": "https://Stackoverflow.com/users/5514747", "pm_score": 2, "selected": false, "text": "COUNTIFS()" }, { "answer_id": 74299352, "author": "TheMaster", "author_id": 8404453, "author_profile": "https://Stackoverflow.com/users/8404453", "pm_score": 1, "selected": true, "text": "B2:B5" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19529694/" ]
74,297,725
<p>I have the following code:</p> <pre><code>url = requests.get(&quot;http://www.ucdenver.edu/pages/ucdwelcomepage.aspx&quot;) soup = BeautifulSoup(res.content, 'html5lib') scripts = soup.select('script', {&quot;type&quot;:&quot;application/ld+json&quot;}) scripts = [script for script in scripts] #for each script in the script, from all scripts found &gt;! print(scripts) for script in scripts: script.get(res) print(script) </code></pre> <p>and from this code I got the result(s):</p> <p>I want to get into the departments array to capture two elements,</p> <p>(there are multiple departments in &quot;departments&quot;)</p> <pre><code> { &quot;@context&quot;: &quot;https://schema.org/&quot;, &quot;@type&quot;: &quot;Organization&quot;, &quot;url&quot;: &quot;https://www.ucdenver.edu&quot;, &quot;logo&quot;: &quot;https://www.ucdenver.edu/images/default-source/global-theme-images/cu_logo.png&quot;, &quot;name&quot;: &quot;University of Colorado Denver&quot;, &quot;alternateName&quot;: &quot;CU Denver&quot;, &quot;telephone&quot;: &quot;1+ 303-315-5969&quot;, &quot;address&quot;: { &quot;@type&quot;: &quot;PostalAddress&quot;, &quot;streetAddress&quot;: &quot;1201 Larimer Street&quot;, &quot;addressLocality&quot;: &quot;Denver&quot;, &quot;addressRegion&quot;: &quot;CO&quot;, &quot;postalCode&quot;: &quot;80204&quot;, &quot;addressCountry&quot;: &quot;US&quot; }, &quot;department&quot;: [{ &quot;name&quot;: &quot;Center for Undergraduate Exploration and Advising&quot;, &quot;email&quot;: &quot;mailto:CUEA@ucdenver.edu&quot;, &quot;telephone&quot;: &quot;1+ 303-315-1940&quot;, &quot;url&quot;: &quot;https://www.ucdenver.edu/center-for-undergraduate-exploration-and-advising&quot;, &quot;address&quot;: [{ &quot;@type&quot;: &quot;PostalAddress&quot;, &quot;streetAddress&quot;: &quot;1201 Larimer Street #1113&quot;, &quot;addressLocality&quot;: &quot;Denver&quot;, &quot;addressRegion&quot;: &quot;CO&quot;, &quot;postalCode&quot;: &quot;80204&quot;, &quot;addressCountry&quot;: &quot;US&quot; }] }, </code></pre> <p>from the object I only want to capture &quot;name&quot; and &quot;url&quot;.</p> <p>This is my first time playing with web scraping, but i'm not too sure how you get into <code>&quot;department&quot;: [{</code> to then capture the two elements I want.</p>
[ { "answer_id": 74297821, "author": "Safwan Samsudeen", "author_id": 13981530, "author_profile": "https://Stackoverflow.com/users/13981530", "pm_score": 1, "selected": false, "text": "dict" }, { "answer_id": 74297900, "author": "ErikR", "author_id": 866915, "author_profile": "https://Stackoverflow.com/users/866915", "pm_score": 1, "selected": true, "text": "from bs4 import BeautifulSoup\nimport requests\nimport json\n\nres = requests.get(\"http://www.ucdenver.edu/pages/ucdwelcomepage.aspx\")\nsoup = BeautifulSoup(res.content, 'html5lib')\nscripts = soup.find_all(attrs={\"type\":\"application/ld+json\"})\n\nfor s in scripts:\n content = s.contents[0] # get the text of the script node\n j = json.loads(content) # parse it as JSON into a Python data structure\n for dept in j[\"department\"]:\n print(\">>>\", dept[\"name\"], dept[\"url\"])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18799324/" ]
74,297,746
<p>I'm having a hard time thinking about how should I implement the checking for duplicates while the string array with length of 5 is initially empty. Before adding an element in the array, I have to check first if it already exists in the array but because the array is initially empty (which means the five elements are null) it prompts an error, I think that is because I'm trying to compare the element (that I'm trying to add in the array) to null.</p> <p>What I want to do is check if the the length of the array is less than the limit, check if the element that I want to add has no duplicate in the array. If it doesn't have a duplicate, then I'll add it in array, if it has a duplicate then I won't add it then I'll print a prompt message.</p> <p>I am working on a project with multiple classes, here's the snippet of my code:</p> <pre><code>public class Collections { Guardian[] guardians; int count; final static int MAX_GUARDIANS = 5; public Collection () { guardians = new Guardian[Collection.MAX_GUARDIANS]; } public void addGuardians (Guardian guardian) { if (this.count &lt; MAX_GUARDIANS) { for (int i = 0; i &lt; guardians.length; i++) { if (guardians[i].equals(guardian)) { System.out.println(&quot;The guardian is already in the list!\n&quot;); } else { this.guardians[this.count++] = guardian; System.out.println(&quot;Guardian &quot;+guardian.getName()+&quot; was added to the list!&quot;); } } } else { System.out.println(&quot;Maximum number of guardians in the list has been reached!\n&quot;); } } } </code></pre> <p>Is it possible to compare the element that I'm planning to add to null?</p>
[ { "answer_id": 74297821, "author": "Safwan Samsudeen", "author_id": 13981530, "author_profile": "https://Stackoverflow.com/users/13981530", "pm_score": 1, "selected": false, "text": "dict" }, { "answer_id": 74297900, "author": "ErikR", "author_id": 866915, "author_profile": "https://Stackoverflow.com/users/866915", "pm_score": 1, "selected": true, "text": "from bs4 import BeautifulSoup\nimport requests\nimport json\n\nres = requests.get(\"http://www.ucdenver.edu/pages/ucdwelcomepage.aspx\")\nsoup = BeautifulSoup(res.content, 'html5lib')\nscripts = soup.find_all(attrs={\"type\":\"application/ld+json\"})\n\nfor s in scripts:\n content = s.contents[0] # get the text of the script node\n j = json.loads(content) # parse it as JSON into a Python data structure\n for dept in j[\"department\"]:\n print(\">>>\", dept[\"name\"], dept[\"url\"])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17118303/" ]
74,297,769
<p>I have a Main page that contains 4 section ** #home, #collection, #products and #contact** and I have 2 different page for /cart and /login <em>Navbar Code is Here</em></p> <pre><code>`&lt;nav&gt; &lt;div className='wrap-nav'&gt; &lt;NavLink href=&quot;&quot; className='logo'&gt;NILESTORE&lt;/NavLink&gt; &lt;div className='wrap-ul'&gt; &lt;ul className='nav-links' &gt; &lt;li&gt;&lt;NavLink to=&quot;#home&quot;&gt;Home&lt;/NavLink&gt;&lt;/li&gt; &lt;li&gt;&lt;NavLink to=&quot;#collection&quot;&gt;Collection&lt;/NavLink&gt;&lt;/li&gt; &lt;li&gt;&lt;NavLink to=&quot;#products&quot;&gt;Products&lt;/NavLink&gt;&lt;/li&gt; &lt;li&gt;&lt;NavLink to=&quot;#contact&quot;&gt;Contact&lt;/NavLink&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul className='nav-items'&gt; &lt;li&gt;&lt;NavLink to=&quot;/cart&quot; className='cart' data-item={data.cartItems.length}&gt;&lt;BsBag /&gt;&lt;/NavLink&gt;&lt;/li&gt; &lt;li&gt;&lt;NavLink to=&quot;/login&quot; className='login'&gt;Login&lt;/NavLink&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/nav&gt;` </code></pre> <p><em>App.js code is here</em></p> <pre><code>import React from 'react' import { BrowserRouter as Router, Routes, Route } from &quot;react-router-dom&quot;; import &quot;./App.css&quot; import Navbar from './components/Navbar' import Cart from './pages/Cart'; import Main from './pages/Main'; function App() { return ( &lt;&gt; &lt;Router&gt; &lt;Navbar /&gt; &lt;Routes&gt; &lt;Route path=&quot;/&quot; element={&lt;Main /&gt;} /&gt; &lt;Route path=&quot;/cart&quot; element={&lt;Cart /&gt;} /&gt; &lt;/Routes&gt; &lt;/Router&gt; &lt;/&gt; ) } export default App </code></pre> <p>SO when I am in main page that works fine and I can reach that section when clicking the section like when i click on products i can reach on #products After that when I click on <strong>/cart</strong> and <strong>/login</strong> page I can reach on that page but myNavbar is same for all pages so when I click on Products, it doesn't work</p> <p>I have tried all the possibilities on changing the NavLink like I have changed #products to /#products but also It doesn't work</p> <p>Is there any solution for that</p>
[ { "answer_id": 74297821, "author": "Safwan Samsudeen", "author_id": 13981530, "author_profile": "https://Stackoverflow.com/users/13981530", "pm_score": 1, "selected": false, "text": "dict" }, { "answer_id": 74297900, "author": "ErikR", "author_id": 866915, "author_profile": "https://Stackoverflow.com/users/866915", "pm_score": 1, "selected": true, "text": "from bs4 import BeautifulSoup\nimport requests\nimport json\n\nres = requests.get(\"http://www.ucdenver.edu/pages/ucdwelcomepage.aspx\")\nsoup = BeautifulSoup(res.content, 'html5lib')\nscripts = soup.find_all(attrs={\"type\":\"application/ld+json\"})\n\nfor s in scripts:\n content = s.contents[0] # get the text of the script node\n j = json.loads(content) # parse it as JSON into a Python data structure\n for dept in j[\"department\"]:\n print(\">>>\", dept[\"name\"], dept[\"url\"])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16655390/" ]
74,297,775
<p>I am a starter and I am trying to make a simple unity top-down game in 2d, so i made a player controller script and tried to make my character walk, run, and crawl. But while executing it I can't make my character run speed change while everything else works.</p> <pre><code>using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { SpriteRenderer rend; public float movementSpeed = 3.0f; Vector2 movement = new Vector2(); Rigidbody2D rigidbody2D; [SerializeField] float normalSpeed, runSpeed, crouchSpeed; Animator animator; void Start() { rend = GetComponent&lt;SpriteRenderer&gt;(); animator = GetComponent&lt;Animator&gt;(); rigidbody2D = GetComponent&lt;Rigidbody2D&gt;(); } void Update() { UpdateState(); } private void FixedUpdate() { MoveCharacter(); } private void MoveCharacter() { movement.x = Input.GetAxisRaw(&quot;Horizontal&quot;); movement.y = Input.GetAxisRaw(&quot;Vertical&quot;); if (movement.x &gt; 0) { rend.flipX = true; } else if (movement.x &lt; 0) { rend.flipX = false; } rigidbody2D.velocity = movement * movementSpeed; } private void UpdateState() { //걷기 if (Mathf.Approximately(movement.x, 0) &amp;&amp; Mathf.Approximately(movement.y, 0)) { animator.SetBool(&quot;isMove&quot;, false); } else { animator.SetBool(&quot;isMove&quot;, true); } //달리기 if (Input.GetKey(KeyCode.LeftShift)){ movementSpeed = runSpeed; animator.SetBool(&quot;isRun&quot;, true); } else{ movementSpeed = normalSpeed; animator.SetBool(&quot;isRun&quot;, false); } //웅크리기 if (Input.GetKey(KeyCode.LeftControl)) { movementSpeed = crouchSpeed; animator.SetBool(&quot;isCrouch&quot;, true); } else { movementSpeed = normalSpeed; animator.SetBool(&quot;isCrouch&quot;, false); } //대기상태 x방향 설정 if (movement.x &gt; 0) { animator.SetFloat(&quot;horIdle&quot;, 1); animator.SetFloat(&quot;verIdle&quot;, 0); } else if (movement.x &lt; 0) { animator.SetFloat(&quot;horIdle&quot;, -1); animator.SetFloat(&quot;verIdle&quot;, 0); } //대기상태 y방향 설정 if (movement.y &gt; 0) { animator.SetFloat(&quot;verIdle&quot;, 1); animator.SetFloat(&quot;horIdle&quot;, 0); } else if (movement.y &lt; 0) { animator.SetFloat(&quot;verIdle&quot;, -1); animator.SetFloat(&quot;horIdle&quot;, 0); } animator.SetFloat(&quot;horizontal&quot;, movement.x); animator.SetFloat(&quot;vertical&quot;, movement.y); } } </code></pre> <p>This is the code I wrote for the Player's momvement and I can't find any problems here.</p>
[ { "answer_id": 74297821, "author": "Safwan Samsudeen", "author_id": 13981530, "author_profile": "https://Stackoverflow.com/users/13981530", "pm_score": 1, "selected": false, "text": "dict" }, { "answer_id": 74297900, "author": "ErikR", "author_id": 866915, "author_profile": "https://Stackoverflow.com/users/866915", "pm_score": 1, "selected": true, "text": "from bs4 import BeautifulSoup\nimport requests\nimport json\n\nres = requests.get(\"http://www.ucdenver.edu/pages/ucdwelcomepage.aspx\")\nsoup = BeautifulSoup(res.content, 'html5lib')\nscripts = soup.find_all(attrs={\"type\":\"application/ld+json\"})\n\nfor s in scripts:\n content = s.contents[0] # get the text of the script node\n j = json.loads(content) # parse it as JSON into a Python data structure\n for dept in j[\"department\"]:\n print(\">>>\", dept[\"name\"], dept[\"url\"])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403455/" ]
74,297,815
<p>I'm creating a group sorting function for my first major project - a schedule maker for my partner's lesson groups at her job (teacher). There are 20 letters. 4 letters can go per day, so all 20 letters should go every 5 days. I created 5 smaller groups (lists) of 4 letters nested inside a list titled &quot;all_groups&quot;. Every 5 days (a week or so) the order of the groups is rotated by one by insert(0, group.pop()). This works without a problem. However, I also want to rotate the 5 nested lists themselves and have that persist. This is the part that isn't working.</p> <p>I have a couple helper global counters to make this work.</p> <p>I add 1 to each counter every time the function is called. Counter 1 - randomizer. If randomizer == 21, then rotate the 5 main groups.</p> <p>Counter 2 - Total changes. This counts the total amount of times the function has been called. I use this to avoid rotating any nested lists the first go-around using a conditional.</p> <p>Counter 3 - group_index - this counter goes from 0-4 and lets the function choose which of the 5 groups should be called before resetting back to 0.</p> <p>Counter 4 - group_changes. This counter goes counts from 0-3 since there are 4 letters in each list. Once all 4 letters have been rotated, it should reset to 0 if group_changes == 4, and increase the group_index by 1.</p> <p>The rotating of the 5 subgroups in the main list and changing of index seems to work, and each individual letter is rotated once and prints correctly, but any further loops tends to reset the inner lists back to their original state rather than keeping them modified. I'm stumped as to how to fix this.</p> <p>In addition: If I use the randomize_group function rather than the rotate_group function every time all 20 letters have gone if group_ranzomier == 21), the nested lists SOMETIMES rotate inside. I would like to randomize rather than rotate the 5 lists for scheduling purposes. I have no clue why randomizing the 5 lists changes the behavior of the inner rotating function.</p> <p>The code I have for this portion of the project is as follows, and I commented on the code to describe what it's doing temporarily:</p> <pre><code> group_randomizer = 0 #this is for randomizing the subgroup order each loop of 20 groups group_change = 0 #tracks individual swaps group_index = 0 #tracks each subgroup of 5 groups of 4 total_changes = 0 #tracks total group swaps all_groups = [['A', 'B', 'C', 'D'], ['E', 'F', 'G', 'H'], ['I', 'J', 'K', 'L'], ['M', 'N', 'O', 'P'], ['Q', 'R', 'S', 'T']] def main(): #this entire block of code is for testing purposes to see what the output is print(all_groups[group_index]) for i in range(20): print(find_group(all_groups), end='') print(&quot;&quot;) print(tabulate(all_groups)) for i in range(8): for i in range(20): print(find_group(all_groups), end='') #printing the entire 20 group loop in one line print(all_groups[group_index]) #to see what the first line is print(tabulate(all_groups)) #for testing purposes, to read table print(&quot;&quot;) def rotate_group(group): group.insert(0, group.pop()) return group # def randomize_group(group): # random.shuffle(group) # return group def find_group(all_groups): global group_randomizer global group_change global group_index global total_changes group_randomizer += 1 if group_randomizer == 21: rotate_group(all_groups) #rotates the 5 subgroups of 4 after each letter has gone through group_randomizer = 0 if total_changes &lt; 19: #to keep groups un-randomized the first loop of 20 groups. base case rotated = all_groups[group_index][group_change] else: #begin rotating the letters in the subgroups. ABCD -&gt; DABC -&gt; CDAB -&gt; BCDA -&gt; ABCD all_groups = rotate_group(all_groups[group_index]) rotated = all_groups total_changes += 1 #increment total changes group_change += 1 #increment a rotation counter. if group_change == 4: #if the rotation counter reaches 4, reset it and increment the subgroup index group_index += 1 group_change = 0 if group_index == 5: #if the subgroup index reaches 5, reset it to return back to the first subgroup group_index = 0 return rotated[0] #return the current rotated letter </code></pre>
[ { "answer_id": 74297821, "author": "Safwan Samsudeen", "author_id": 13981530, "author_profile": "https://Stackoverflow.com/users/13981530", "pm_score": 1, "selected": false, "text": "dict" }, { "answer_id": 74297900, "author": "ErikR", "author_id": 866915, "author_profile": "https://Stackoverflow.com/users/866915", "pm_score": 1, "selected": true, "text": "from bs4 import BeautifulSoup\nimport requests\nimport json\n\nres = requests.get(\"http://www.ucdenver.edu/pages/ucdwelcomepage.aspx\")\nsoup = BeautifulSoup(res.content, 'html5lib')\nscripts = soup.find_all(attrs={\"type\":\"application/ld+json\"})\n\nfor s in scripts:\n content = s.contents[0] # get the text of the script node\n j = json.loads(content) # parse it as JSON into a Python data structure\n for dept in j[\"department\"]:\n print(\">>>\", dept[\"name\"], dept[\"url\"])\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403425/" ]
74,297,820
<p>I am using Java and spring boot. I have 2 files, an @configuration file and a @Service file.</p> <p>Configuration file:</p> <pre><code> </code></pre> <pre><code>@Configuration public class OpenSearchRestClientConfiguration { @Value(&quot;${aws.opensearch.domain.endpoint}&quot;) private String endpoint; @Value(&quot;${aws.region}&quot;) private String region; @Value(&quot;${aws.serviceName}&quot;) private String myServiceName; @Bean //I get an error when I add @Bean, but when I remove @Bean, I get no errors. public OpenSearchClient OpensearchClient(){ SdkHttpClient myHttpClient = ApacheHttpClient.builder().build(); AWS4Signer mySigner = new AWS4Signer(); mySigner.setServiceName(myServiceName); mySigner.setRegionName(region); return new OpenSearchClient( new AwsSdk2Transport(myHttpClient, endpoint, Region.of(region), AwsSdk2TransportOptions.builder().build())); } } </code></pre> <pre><code> </code></pre> <p>Service file:</p> <pre><code>@Service public class PostsSearchService { private final OpenSearchRestClientConfiguration myOpenSearchClient; public PostsSearchService(OpenSearchRestClientConfiguration openSearchClient){ this.myOpenSearchClient = openSearchClient; } } </code></pre> <p>I get an error when I add @Bean at the top of the OpensearchClient method in OpenSearchRestClientConfiguration class, but when I remove @Bean, I get no errors.</p> <p>Here is the error I'm getting:</p> <blockquote> </blockquote> <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'OpensearchClient' defined in class path resource [com/search_engine_microservice_group/search_engine_microservice/Configuration/OpenSearchRestClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.opensearch.client.opensearch.OpenSearchClient]: Factory method 'OpensearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: jakarta/json/spi/JsonProvider at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.5.jar:2.7.5] at com.search_engine_microservice_group.search_engine_microservice.SearchEngineMicroserviceApplication.main(SearchEngineMicroserviceApplication.java:10) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.7.5.jar:2.7.5] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.opensearch.client.opensearch.OpenSearchClient]: Factory method 'OpensearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: jakarta/json/spi/JsonProvider at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.23.jar:5.3.23] ... 24 common frames omitted Caused by: java.lang.NoClassDefFoundError: jakarta/json/spi/JsonProvider at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na] at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na] at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na] at org.opensearch.client.json.jackson.JacksonJsonpMapper.&lt;init&gt;(JacksonJsonpMapper.java:61) ~[opensearch-java-2.1.0.jar:na] at org.opensearch.client.json.jackson.JacksonJsonpMapper.&lt;init&gt;(JacksonJsonpMapper.java:57) ~[opensearch-java-2.1.0.jar:na] at org.opensearch.client.json.jackson.JacksonJsonpMapper.&lt;init&gt;(JacksonJsonpMapper.java:68) ~[opensearch-java-2.1.0.jar:na] at org.opensearch.client.transport.aws.AwsSdk2Transport.&lt;init&gt;(AwsSdk2Transport.java:156) ~[opensearch-java-2.1.0.jar:na] at org.opensearch.client.transport.aws.AwsSdk2Transport.&lt;init&gt;(AwsSdk2Transport.java:99) ~[opensearch-java-2.1.0.jar:na] at com.search_engine_microservice_group.search_engine_microservice.Configuration.OpenSearchRestClientConfiguration.OpensearchClient(OpenSearchRestClientConfiguration.java:38) ~[classes/:na] at com.search_engine_microservice_group.search_engine_microservice.Configuration.OpenSearchRestClientConfiguration$$EnhancerBySpringCGLIB$$606bb8d1.CGLIB$OpensearchClient$0(&lt;generated&gt;) ~[classes/:na] at com.search_engine_microservice_group.search_engine_microservice.Configuration.OpenSearchRestClientConfiguration$$EnhancerBySpringCGLIB$$606bb8d1$$FastClassBySpringCGLIB$$549e6b4b.invoke(&lt;generated&gt;) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.23.jar:5.3.23] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.23.jar:5.3.23] at com.search_engine_microservice_group.search_engine_microservice.Configuration.OpenSearchRestClientConfiguration$$EnhancerBySpringCGLIB$$606bb8d1.OpensearchClient(&lt;generated&gt;) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.23.jar:5.3.23] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: jakarta.json.spi.JsonProvider at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na] ... 50 common frames omitted </code></pre> <p>I get an error when I add <strong>@Bean</strong> at the top of the <strong>OpensearchClient</strong> *method *in **OpenSearchRestClientConfiguration **class, but when I remove the <strong>@Bean</strong> annotation, I get no errors.</p> <p>What is the reason behind such error ?</p>
[ { "answer_id": 74297911, "author": "刷题养家", "author_id": 17953108, "author_profile": "https://Stackoverflow.com/users/17953108", "pm_score": 0, "selected": false, "text": " //private final OpenSearchRestClientConfiguration myOpenSearchClient; \n\n private final OpenSearchClient myOpenSearchClient;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20383836/" ]
74,297,870
<p>I'm trying to expand and collapse a container dynamically based on the data received. Currently I'm doing it like this:</p> <pre><code> AnimatedContainer( duration: const Duration(milliseconds: 550), margin: EdgeInsets.symmetric(horizontal: 16), constraints: !isExpanded ? BoxConstraints( maxHeight: MyUtils.height(221), minHeight: MyUtils.height(221)) : BoxConstraints( minHeight: MyUtils.height(321), maxHeight: MyUtils.height(1000)), decoration: BoxDecoration( color: containerColor, borderRadius: const BorderRadius.all(Radius.circular(8))), child: Column(children: [ Container( margin: EdgeInsets.fromLTRB(8, 10, 8, 20), height: MyUtils.height(36), width: double.infinity, decoration: BoxDecoration( color: containerColor3, borderRadius: BorderRadius.all(Radius.circular(6))), ), InkWell( onTap: () =&gt; expand(), child: Text( 'Show', style: TextStyle(color: Colors.white), ), ) ]), ), </code></pre> <p>The function expand() is as simple as changing the bool of isExpanded. I managed to collapse/expand the Container, but the problem is that the Container expanded until maxHeight, I want to make the expanded height dynamic based on the items inside. So I tried to set only minHeight and hoping that maxHeight will follow the items, but I got an error because maxHeight is not set.</p> <p>Is there any way I can achieve this?</p>
[ { "answer_id": 74297911, "author": "刷题养家", "author_id": 17953108, "author_profile": "https://Stackoverflow.com/users/17953108", "pm_score": 0, "selected": false, "text": " //private final OpenSearchRestClientConfiguration myOpenSearchClient; \n\n private final OpenSearchClient myOpenSearchClient;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18722356/" ]
74,297,880
<p>I'm taking Harvard's CS50-Web course and I'm trying to turn in my Capstone project. It is required that we push our project to the following exact branch:</p> <p>web50/projects/2020/x/capstone</p> <p>I have been pushing my code to this branch whenever I make changes to it. Recently, I realized I have been pushing my venv folder when I shouldn't be, so I added this to .gitignore, but the folder wasn't removed from the branch. So, I deleted the folder manually via GitHub's web interface. Now, whenever I try to push my project to this branch, it gets rejected because my local files are out of sync with the remote ones.</p> <p>I thought I would just delete the branch and start anew, but it turns out web50/projects/2020/x/capstone is the default branch (I'm not sure how it got to be that way) and I am only able to delete branches that are not default. I see no way on GitHub to change the default branch. I can't access settings for the repo since it's not my repo.</p> <p>I could just push all my files to a different branch, but the assignment has to be turned in at that exact branch (web50/projects/2020/x/capstone), otherwise it will not be graded.</p> <p>I am new to git, if it's not obvious. Is there a way to change the default branch of a repo that isn't mine?</p>
[ { "answer_id": 74297911, "author": "刷题养家", "author_id": 17953108, "author_profile": "https://Stackoverflow.com/users/17953108", "pm_score": 0, "selected": false, "text": " //private final OpenSearchRestClientConfiguration myOpenSearchClient; \n\n private final OpenSearchClient myOpenSearchClient;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17072084/" ]
74,297,897
<p>Is it possible for my Google sheet to automatically append a new formatted row to the end of a column when it fills up?</p> <p><a href="https://i.stack.imgur.com/rvIZV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rvIZV.png" alt="enter image description here" /></a></p> <p>I would like to avoid having to manually create, say, 1000 pre-formatted empty rows in my sheet.</p>
[ { "answer_id": 74297911, "author": "刷题养家", "author_id": 17953108, "author_profile": "https://Stackoverflow.com/users/17953108", "pm_score": 0, "selected": false, "text": " //private final OpenSearchRestClientConfiguration myOpenSearchClient; \n\n private final OpenSearchClient myOpenSearchClient;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12191708/" ]
74,297,907
<p>I want to print variable value inside string quote</p> <p>this is my variable</p> <pre><code>var id = $(this).val(); </code></pre> <p>how can i print this variable to this string</p> <pre><code> $('#button_cetak').html('&lt;a href=&quot;{{route('report.pdf',[$user-&gt;nip,'//this is place i wanna print'])}}&quot; class=&quot;btn btn-warning btn-block&quot;&gt;&lt;i class=&quot;fas fa-print&quot;&gt;&lt;/i&gt; Cetak&lt;/a&gt;'); </code></pre> <p>thanks</p>
[ { "answer_id": 74297911, "author": "刷题养家", "author_id": 17953108, "author_profile": "https://Stackoverflow.com/users/17953108", "pm_score": 0, "selected": false, "text": " //private final OpenSearchRestClientConfiguration myOpenSearchClient; \n\n private final OpenSearchClient myOpenSearchClient;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12193956/" ]
74,297,912
<p>I am new in programming world. I tried use http://localhost:8080/swagger-ui.html but logs return 2022-11-03 04:27:28.476 WARN 13844 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound : No mapping for GET /swagger-ui.html</p> <p>{</p> <pre><code>implementation 'io.springfox:springfox-swagger2:3.0.0' implementation 'io.springfox:springfox-swagger-ui:3.0.0' </code></pre> <p>}</p> <p>(sorry, for my english language)</p> <pre><code>package com.crud.tasks.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @EnableSwagger2 @Configuration public class CoreConfiguration { @Bean public RestTemplate restTemplate() { return new RestTemplate(); } @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } } </code></pre> <pre><code>package com.crud.tasks; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @SpringBootApplication @EnableWebMvc public class TasksApplication { public static void main(String[] args) { SpringApplication.run(TasksApplication.class, args); } } </code></pre>
[ { "answer_id": 74298488, "author": "Harsh", "author_id": 5892518, "author_profile": "https://Stackoverflow.com/users/5892518", "pm_score": 1, "selected": true, "text": "Swagger" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403560/" ]
74,297,926
<p>I'm trying to make a &quot;Like&quot; button for a post which was fetched by AJAX using jQuery. Here, I want to change button text while clicked. But it's not changing.</p> <p>Here is my Like button codes:</p> <pre><code>$('.posted-area').append('\ &lt;div class=&quot;posted-footer&quot;&gt;\ &lt;ul&gt;\ &lt;li&gt;\ &lt;button class=&quot;btnLike btn-danger&quot; id=&quot;btnLike&quot; onclick=&quot;btnLikefunction()&quot;&gt; Like &lt;/button&gt;\ &lt;/li&gt;\ &lt;li&gt;\ &lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa fa-comments-o&quot;&gt;&lt;/i&gt; &lt;/a&gt;\ &lt;span&gt;15 comments&lt;/span&gt;\ &lt;/li&gt;\ &lt;/ul&gt;\ &lt;/div&gt;\ '); </code></pre> <p>Here is my <code>onClick</code> event for the &quot;Like&quot; button:</p> <pre><code>function btnLikefunction(){ var btnTextChange = document.getElementById(&quot;.btnLike&quot;); btnTextChange.innerHTML= &quot;Liked!&quot;; } </code></pre>
[ { "answer_id": 74298488, "author": "Harsh", "author_id": 5892518, "author_profile": "https://Stackoverflow.com/users/5892518", "pm_score": 1, "selected": true, "text": "Swagger" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19270776/" ]
74,297,952
<pre><code>_id:&quot;63624b321e78f38a3d6baf3e&quot; Taxes [0] TaxName:CGST Amount:9.0 [1] TaxName:SGST Amount:8.0 _id:&quot;63624b321e78f38a3d6baf3e&quot; Taxes [1] TaxName:SGST Amount:8.0 </code></pre> <p>I need to group by tax name and calculate Total CGST, SGST like below</p> <pre><code>CGST:9.0 SGST:16.0 </code></pre> <p>I have tried to get the grouping as below. I have an object like movie summary where I added the <code>taxes[]</code> and tried to group by tax name. Please let me know how to do this grouping correctly.</p> <pre class="lang-cs prettyprint-override"><code>movieSummary.Add(new DSMovieSummaryReport { MovieId = orderTicket.MovieId, Taxes= orderTicket.Taxes, }); var groupByTaxNamesQuery = from tax in movieSummary group tax by tax.Taxes into newGroup orderby newGroup.Key select newGroup; </code></pre>
[ { "answer_id": 74298012, "author": "Yong Shun", "author_id": 8017690, "author_profile": "https://Stackoverflow.com/users/8017690", "pm_score": 2, "selected": false, "text": "Taxes" }, { "answer_id": 74298609, "author": "Flywings", "author_id": 9988501, "author_profile": "https://Stackoverflow.com/users/9988501", "pm_score": 0, "selected": false, "text": "movieSummary\n .SelectMany(m => m.Taxes)\n .GroupBy(t=>t.TaxeName)\n .Select(g=> new Taxe\n {\n TaxeName = g.Key,\n Amount = g.Sum(t => t.Amount)\n });\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19662989/" ]
74,297,959
<p>I have this google sheets input.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Players</th> <th>Loot</th> </tr> </thead> <tbody> <tr> <td>Player1</td> <td>4</td> </tr> <tr> <td>Player2</td> <td>1</td> </tr> <tr> <td>Player3</td> <td>4</td> </tr> <tr> <td>Player4</td> <td>2</td> </tr> </tbody> </table> </div> <p>What I'm seeking to do is to <strong>simplify</strong> this formula.</p> <pre><code>=AND(B2&gt;=3,B3&gt;=3,B4&gt;=3,B5&gt;=3) </code></pre> <p><a href="https://i.stack.imgur.com/XVYWb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XVYWb.png" alt="enter image description here" /></a></p> <p>This is what i did so far. as suggested by <a href="https://stackoverflow.com/users/5514747/harun24hr">@Harun24hr</a> in this <a href="https://stackoverflow.com/posts/74297721/timeline#comment_131170574">comment</a>.</p> <pre><code>=ArrayFormula(COUNTIF(B2:B5&gt;=3,&quot;TRUE&quot;))=COUNTA(B2:B5) </code></pre> <p>Can this formula be simplified further and still get <code>TRUE</code> in a <strong>single cell</strong> when all of Loot values is <code>&gt;=</code> 3?</p>
[ { "answer_id": 74298170, "author": "pgSystemTester", "author_id": 11732320, "author_profile": "https://Stackoverflow.com/users/11732320", "pm_score": 2, "selected": false, "text": "=Count(filter(B2:B,B2:B>=3))=Count(B2:B)\n" }, { "answer_id": 74299368, "author": "TheMaster", "author_id": 8404453, "author_profile": "https://Stackoverflow.com/users/8404453", "pm_score": 2, "selected": true, "text": "B2:B5" }, { "answer_id": 74302461, "author": "player0", "author_id": 5632629, "author_profile": "https://Stackoverflow.com/users/5632629", "pm_score": 1, "selected": false, "text": "=SUMPRODUCT(B2:B>=3)=COUNTA(B2:B)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19529694/" ]
74,297,969
<p>I want to create new column in a df that shows two options when executing a function.</p> <p>I have two lists:</p> <pre><code>lista = [A, B, C, D] listb = [would not, use to, manage to, when, did not] </code></pre> <p>I want to find the first word that can appear from <code>lista</code> and return it in a new column called &quot;Effect&quot;. If this is not found, then search for values from <code>listb</code>and print the first encountered from <code>listb</code> along with it next 2 strings.</p> <p>Example:</p> <p><a href="https://i.stack.imgur.com/Rdtic.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rdtic.png" alt="enter image description here" /></a></p> <p>I have tried something like this:</p> <pre><code>def matcher(Description): for i in lista: if i in Description: return i return &quot;Not found&quot; def matcher(Description): for j in listb: if j in Description: return j + 1 return &quot;Not found&quot; df[&quot;Effect&quot;] = df.apply(lambda i: matcher(i[&quot;Description&quot;]), axis=1) df[&quot;Effect&quot;] = df.apply(lambda j: matcher(j[&quot;Description&quot;]), axis=1) </code></pre>
[ { "answer_id": 74298078, "author": "Tim Roberts", "author_id": 1883316, "author_profile": "https://Stackoverflow.com/users/1883316", "pm_score": 0, "selected": false, "text": "def matcher(Description):\n w = [i for i in lista if i in Description]\n w.extend( [i for i in listb if i in Description] )\n if not w:\n return \"Not found\"\n else:\n return ' '.join(w)\n\ndf[\"Effect\"] = df.apply(lambda i: matcher(i[\"Description\"]), axis=1)\n" }, { "answer_id": 74298297, "author": "Claudio", "author_id": 7711283, "author_profile": "https://Stackoverflow.com/users/7711283", "pm_score": 2, "selected": true, "text": "def matcher(sentence):\n match_list = [substr for substr in lista \n if substr in [ word \n for word in sentence.replace(',',' ').split(\" \")]]\n if match_list: # list with items evaluates to True, empty list to False\n return match_list[0]\n match_list = [substr for substr in listb if ' '+substr+' ' in sentence]\n if match_list:\n substr = match_list[0]\n return substr + \" \" + sentence.split(substr)[-1].replace(',',' ').strip().split(\" \")[0]\n return \"Not found\"\n\ndf[\"Effect\"] = df.Description.apply(matcher)\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74297969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20375474/" ]
74,298,007
<p>In the code below, I'm computing the second derivative (<code>y_xx_lin</code>) of a linear network <code>modelLinear</code> which has linear activation functions throughout, and the second derivative (<code>y_xx_tanh</code>) of a tanh network <code>modelTanh</code> which has <code>tanh</code> activations for all its layers except the last layer which is linear.</p> <p>My question is: <code>y_xx_lin</code> is <code>None</code> but <code>y_xx_tanh</code> shows some values. Following <a href="https://stackoverflow.com/questions/65681820/second-derivative-in-tensorflow-2-0">this Stackoverflow question</a> I'm guessing that <code>y_xx_lin</code> is <code>None</code> because the second derivative of a linear function is zero for all input values and thus in some sense not linked to the input. Is this the case?</p> <p>Even if this is so, I would like TensorFlow to calculate the derivative and return it, instead of returning <code>None</code>. Is this possible?</p> <pre><code># Second derivative of a linear network appears to be None import tensorflow as tf from tensorflow.keras.models import Model from tensorflow.keras.layers import Dense, Input from tensorflow.keras.optimizers import Adam from tensorflow.keras.losses import MeanSquaredError import tensorflow.keras.backend as K import numpy as np import matplotlib.pyplot as plt def build_network(activation='linear'): input_layer = Input(1) inner_layer = Dense(6, activation=activation)(input_layer) inner_layer1 = Dense(6, activation=activation)(inner_layer) inner_layer2 = Dense(6, activation=activation)(inner_layer1) output_layer = Dense(1, activation='linear')(inner_layer2) model = Model(input_layer, output_layer) return model def get_first_second_derivative(X_train,y_train,model): with tf.GradientTape(persistent=True) as tape_second: tape_second.watch(X_train) with tf.GradientTape(persistent=True) as tape_first: # Watch the variables with who/whom we want to compute gradients tape_first.watch(X_train) # get the output of the NN output = model(X_train) y_x = tape_first.gradient(output,X_train) y_xx = tape_second.gradient(y_x,X_train) return y_x,y_xx modelLinear = build_network(activation='linear') modelLinear.compile(optimizer=Adam(learning_rate=0.1),loss='mse') modelTanh = build_network(activation='tanh') modelTanh.compile(optimizer=Adam(learning_rate=0.1),loss='mse') X_train = np.linspace(-1,1,10).reshape((-1,1)) y_train = X_train*X_train X_train = tf.convert_to_tensor(X_train,dtype=tf.float64) y_train = tf.convert_to_tensor(y_train,dtype=tf.float64) y_x_lin,y_xx_lin = get_first_second_derivative(X_train,y_train,modelLinear) y_x_tanh,y_xx_tanh = get_first_second_derivative(X_train,y_train,modelTanh) print('Type of y_xx_lin = ',type(y_xx_lin)) </code></pre>
[ { "answer_id": 74298568, "author": "Jirayu Kaewprateep", "author_id": 7848579, "author_profile": "https://Stackoverflow.com/users/7848579", "pm_score": -1, "selected": false, "text": "import tensorflow as tf\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Class / Definition\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nclass MyLSTMLayer( tf.keras.layers.LSTM ):\n def __init__(self, units, return_sequences, return_state):\n super(MyLSTMLayer, self).__init__( units, return_sequences=True, return_state=False )\n self.num_units = units\n\n def build(self, input_shape):\n self.kernel = self.add_weight(\"kernel\",\n shape=[int(input_shape[-1]),\n self.num_units])\n\n def call(self, inputs):\n derivative_number = tf.constant([ 2.0 ])\n \n ZeroPadding1D_front = tf.keras.layers.ZeroPadding1D(padding=( 1, 0 ))\n ZeroPadding1D_back = tf.keras.layers.ZeroPadding1D(padding=( 0, 1 ))\n\n reshape = tf.reshape( inputs, shape=(1, 1024, 1), name=\"Reshape\" )\n subtract = tf.math.subtract( ZeroPadding1D_front( reshape ), ZeroPadding1D_back( reshape ), name=\"Subtract\" )\n devide = tf.math.divide_no_nan( subtract, derivative_number, name=\"Devide\" )\n\n # X = [ 1, 2, 3, 4, 5 ]\n # Y = 2\n # X/Y = [ ( 2 - 1 / 2 ), ( 3 - 2 / 2 ), ( 4 - 3 / 2 ), ( 5 - 4 / 2 ) ]\n # X/Y = [ 0.5, 0.5, 0.5, 0.5 ]\n\n return devide\n \n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Variables\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nstart = 3\nlimit = 3075\ndelta = 3\nsample = tf.range( start, limit, delta )\nsample = tf.cast( sample, dtype=tf.float32 )\nsample = tf.constant( sample, shape=( 1, 1, 1024 ), dtype=tf.float32 )\nlayer = MyLSTMLayer( 1024, True, False )\n\nmodel = tf.keras.Sequential([\n tf.keras.Input(shape=(1, 1024)),\n layer,\n])\n\nmodel.summary()\n\nprint( \"Sample: \" )\nprint( sample )\nprint( \"Predict: \" )\nprint( model.predict(sample) )\n" }, { "answer_id": 74306530, "author": "Alexey Tochin", "author_id": 8270312, "author_profile": "https://Stackoverflow.com/users/8270312", "pm_score": 2, "selected": true, "text": "lambda x: x ** 1" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13560598/" ]
74,298,047
<p>I have set the below logic to validate the form input but no alert box is being displayed on submit. Please note that the issue is not related to the setCustomvalidity function. Rather is it related to the alert box not being displayed.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function validateform() { var x = document.getElementByid("fname").value; if (x.length &lt; 1) { alert("Name can't be blank"); return false; } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt; &lt;div class="col-25"&gt; &lt;label for="fname"&gt;First Name *&lt;/label&gt; &lt;/div&gt; &lt;div class="col-75"&gt; &lt;input type="text" id="fname" name="firstname" required oninvalid="this.setCustomValidity('This field cannot be left blank')" oninput="this.setCustomValidity('')"&gt; &lt;/div&gt; &lt;/div&gt; &lt;form name="bookingform" action="bookingform.php" method="post" onsubmit="return validateform()"&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74298568, "author": "Jirayu Kaewprateep", "author_id": 7848579, "author_profile": "https://Stackoverflow.com/users/7848579", "pm_score": -1, "selected": false, "text": "import tensorflow as tf\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Class / Definition\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nclass MyLSTMLayer( tf.keras.layers.LSTM ):\n def __init__(self, units, return_sequences, return_state):\n super(MyLSTMLayer, self).__init__( units, return_sequences=True, return_state=False )\n self.num_units = units\n\n def build(self, input_shape):\n self.kernel = self.add_weight(\"kernel\",\n shape=[int(input_shape[-1]),\n self.num_units])\n\n def call(self, inputs):\n derivative_number = tf.constant([ 2.0 ])\n \n ZeroPadding1D_front = tf.keras.layers.ZeroPadding1D(padding=( 1, 0 ))\n ZeroPadding1D_back = tf.keras.layers.ZeroPadding1D(padding=( 0, 1 ))\n\n reshape = tf.reshape( inputs, shape=(1, 1024, 1), name=\"Reshape\" )\n subtract = tf.math.subtract( ZeroPadding1D_front( reshape ), ZeroPadding1D_back( reshape ), name=\"Subtract\" )\n devide = tf.math.divide_no_nan( subtract, derivative_number, name=\"Devide\" )\n\n # X = [ 1, 2, 3, 4, 5 ]\n # Y = 2\n # X/Y = [ ( 2 - 1 / 2 ), ( 3 - 2 / 2 ), ( 4 - 3 / 2 ), ( 5 - 4 / 2 ) ]\n # X/Y = [ 0.5, 0.5, 0.5, 0.5 ]\n\n return devide\n \n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Variables\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nstart = 3\nlimit = 3075\ndelta = 3\nsample = tf.range( start, limit, delta )\nsample = tf.cast( sample, dtype=tf.float32 )\nsample = tf.constant( sample, shape=( 1, 1, 1024 ), dtype=tf.float32 )\nlayer = MyLSTMLayer( 1024, True, False )\n\nmodel = tf.keras.Sequential([\n tf.keras.Input(shape=(1, 1024)),\n layer,\n])\n\nmodel.summary()\n\nprint( \"Sample: \" )\nprint( sample )\nprint( \"Predict: \" )\nprint( model.predict(sample) )\n" }, { "answer_id": 74306530, "author": "Alexey Tochin", "author_id": 8270312, "author_profile": "https://Stackoverflow.com/users/8270312", "pm_score": 2, "selected": true, "text": "lambda x: x ** 1" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403674/" ]
74,298,069
<p>How to regenerate whole list to convert string(list) inside of the list into list format</p> <pre><code> List&lt;Map&lt;String, dynamic&gt;&gt; category = [ { &quot;name&quot;: &quot;One&quot;, &quot;detail&quot;: &quot;['1', '1', '1', '1', '1', '1']&quot; }, { &quot;name&quot;: &quot;two&quot;, &quot;detail&quot;: &quot;['2', '2', '2', '2', '2', '2']&quot; }, { &quot;name&quot;: &quot;three&quot;, &quot;detail&quot;: &quot;['3', '3', '3', '3', '3', '3']&quot; }, ]; Become List&lt;Map&lt;String, dynamic&gt;&gt; category = [ { &quot;name&quot;: &quot;One&quot;, &quot;detail&quot;: ['1', '1', '1', '1', '1', '1'] }, { &quot;name&quot;: &quot;two&quot;, &quot;detail&quot;: ['2', '2', '2', '2', '2', '2'] }, { &quot;name&quot;: &quot;three&quot;, &quot;detail&quot;: ['3', '3', '3', '3', '3', '3'] }, ]; </code></pre> <p>How to regenerate whole list to convert string(list) inside of the list into list format</p>
[ { "answer_id": 74298568, "author": "Jirayu Kaewprateep", "author_id": 7848579, "author_profile": "https://Stackoverflow.com/users/7848579", "pm_score": -1, "selected": false, "text": "import tensorflow as tf\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Class / Definition\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nclass MyLSTMLayer( tf.keras.layers.LSTM ):\n def __init__(self, units, return_sequences, return_state):\n super(MyLSTMLayer, self).__init__( units, return_sequences=True, return_state=False )\n self.num_units = units\n\n def build(self, input_shape):\n self.kernel = self.add_weight(\"kernel\",\n shape=[int(input_shape[-1]),\n self.num_units])\n\n def call(self, inputs):\n derivative_number = tf.constant([ 2.0 ])\n \n ZeroPadding1D_front = tf.keras.layers.ZeroPadding1D(padding=( 1, 0 ))\n ZeroPadding1D_back = tf.keras.layers.ZeroPadding1D(padding=( 0, 1 ))\n\n reshape = tf.reshape( inputs, shape=(1, 1024, 1), name=\"Reshape\" )\n subtract = tf.math.subtract( ZeroPadding1D_front( reshape ), ZeroPadding1D_back( reshape ), name=\"Subtract\" )\n devide = tf.math.divide_no_nan( subtract, derivative_number, name=\"Devide\" )\n\n # X = [ 1, 2, 3, 4, 5 ]\n # Y = 2\n # X/Y = [ ( 2 - 1 / 2 ), ( 3 - 2 / 2 ), ( 4 - 3 / 2 ), ( 5 - 4 / 2 ) ]\n # X/Y = [ 0.5, 0.5, 0.5, 0.5 ]\n\n return devide\n \n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Variables\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nstart = 3\nlimit = 3075\ndelta = 3\nsample = tf.range( start, limit, delta )\nsample = tf.cast( sample, dtype=tf.float32 )\nsample = tf.constant( sample, shape=( 1, 1, 1024 ), dtype=tf.float32 )\nlayer = MyLSTMLayer( 1024, True, False )\n\nmodel = tf.keras.Sequential([\n tf.keras.Input(shape=(1, 1024)),\n layer,\n])\n\nmodel.summary()\n\nprint( \"Sample: \" )\nprint( sample )\nprint( \"Predict: \" )\nprint( model.predict(sample) )\n" }, { "answer_id": 74306530, "author": "Alexey Tochin", "author_id": 8270312, "author_profile": "https://Stackoverflow.com/users/8270312", "pm_score": 2, "selected": true, "text": "lambda x: x ** 1" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20385519/" ]
74,298,095
<p>I want to left align the item name and its description whereas right align the action dropdown. Also, the spacing between list item and secondary text has to be reduced,</p> <p>The incorrect output I see now is <a href="https://i.stack.imgur.com/6LNr0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6LNr0.png" alt="enter image description here" /></a></p> <p>The expected output should be something like this <a href="https://i.stack.imgur.com/gbKuO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gbKuO.png" alt="enter image description here" /></a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"&gt; &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;ul class="list-group"&gt; &lt;li class="list-group-item"&gt; A First item&lt;br/&gt; &lt;small class="text-secondary"&gt;This is a first item description&lt;/small&gt; &lt;div class="btn-group"&gt; &lt;button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false"&gt; Action &lt;/button&gt; &lt;ul class="dropdown-menu dropdown-menu-lg-end"&gt; &lt;li&gt;&lt;a data-bs-toggle="modal" href="#exampleModalToggle" role="button" class="dropdown-item" href="#"&gt;Edit&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Delete&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Run&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="modal fade" id="exampleModalToggle" aria-hidden="true" aria-labelledby="exampleModalToggleLabel" tabindex="-1"&gt; &lt;div class="modal-dialog modal-fullscreen"&gt; &lt;div class="modal-content"&gt; &lt;div class="modal-header"&gt; &lt;h1 class="modal-title fs-5" id="exampleModalToggleLabel"&gt;Create a file&lt;/h1&gt; &lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; What is Lorem Ipsum? &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn btn-primary" data-bs-target="#exampleModalToggle2" data-bs-toggle="modal"&gt;Save&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class="list-group-item"&gt;A second item&lt;/li&gt; &lt;li class="list-group-item"&gt;A third item&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74298120, "author": "kmoser", "author_id": 378779, "author_profile": "https://Stackoverflow.com/users/378779", "pm_score": 2, "selected": true, "text": "float-end" }, { "answer_id": 74298153, "author": "Deshan Dissanayake", "author_id": 19749950, "author_profile": "https://Stackoverflow.com/users/19749950", "pm_score": 0, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n</head>\n\n<body>\n <ul class=\"list-group\">\n <li class=\"list-group-item d-flex justify-content-between\">\n <div>\n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"btn-group\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n</body>\n\n</html>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5549354/" ]
74,298,106
<p>we already created sqlite database. this database we stored 500 000 up data but now we want to convert those data on room database. How to stored those all data in room database?</p>
[ { "answer_id": 74298120, "author": "kmoser", "author_id": 378779, "author_profile": "https://Stackoverflow.com/users/378779", "pm_score": 2, "selected": true, "text": "float-end" }, { "answer_id": 74298153, "author": "Deshan Dissanayake", "author_id": 19749950, "author_profile": "https://Stackoverflow.com/users/19749950", "pm_score": 0, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n</head>\n\n<body>\n <ul class=\"list-group\">\n <li class=\"list-group-item d-flex justify-content-between\">\n <div>\n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"btn-group\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n</body>\n\n</html>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11910375/" ]
74,298,122
<p>I am running a regional GKE kubernetes cluster in is-central1-b us-central-1-c and us-central1-f. I am running 1.21.14-gke.700. I am adding a confidential node pool to the cluster with this command.</p> <pre><code>gcloud container node-pools create card-decrpyt-confidential-pool-1 \ --cluster=svcs-dev-1 \ --disk-size=100GB \ --disk-type=pd-standard \ --enable-autorepair \ --enable-autoupgrade \ --enable-gvnic \ --image-type=COS_CONTAINERD \ --machine-type=&quot;n2d-standard-2&quot; \ --max-pods-per-node=8 \ --max-surge-upgrade=1 \ --max-unavailable-upgrade=1 \ --min-nodes=4 \ --node-locations=us-central1-b,us-central1-c,us-central1-f \ --node-taints=dedicatednode=card-decrypt:NoSchedule \ --node-version=1.21.14-gke.700 \ --num-nodes=4 \ --region=us-central1 \ --sandbox=&quot;type=gvisor&quot; \ --scopes=https://www.googleapis.com/auth/cloud-platform \ --service-account=&quot;card-decrpyt-confidential@corp-dev-project.iam.gserviceaccount.com&quot; \ --shielded-integrity-monitoring \ --shielded-secure-boot \ --tags=testingdonotuse \ --workload-metadata=GKE_METADATA \ --enable-confidential-nodes </code></pre> <p>This creates a node pool but there is one problem... I can still SSH to the instances that the node pool creates. This is unacceptable for my use case as these node pools need to be as secure as possible. I went into my node pool and created a new machine template with ssh turned off using an instance template based off the one created for my node pool.</p> <pre><code>gcloud compute instance-templates create card-decrypt-instance-template \ --project=corp-dev-project --machine-type=n2d-standard-2 --network-interface=aliases=gke-svcs-dev-1-pods-10a0a3cd:/28,nic-type=GVNIC,subnet=corp-dev-project-private-subnet,no-address --metadata=block-project-ssh-keys=true,enable-oslogin=true --maintenance-policy=TERMINATE --provisioning-model=STANDARD --service-account=card-decrpyt-confidential@corp-dev-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --region=us-central1 --min-cpu-platform=AMD\ Milan --tags=testingdonotuse,gke-svcs-dev-1-10a0a3cd-node --create-disk=auto-delete=yes,boot=yes,device-name=card-decrpy-instance-template,image=projects/confidential-vm-images/global/images/cos-89-16108-766-5,mode=rw,size=100,type=pd-standard --shielded-secure-boot --shielded-vtpm - -shielded-integrity-monitoring --labels=component=gke,goog-gke-node=,team=platform --reservation-affinity=any </code></pre> <p>When I change the instance templates of the nodes in the node pool the new instances come online but they do not attach to the node pool. The cluster is always trying to repair itself and I can't change any settings until I delete all the nodes in the pool. I don't receive any errors.</p> <p>What do I need to do to disable ssh into the node pool nodes with the original node pool I created or with the new instance template I created. I have tried a bunch of different configurations with a new node pool and the cluster and have not had any luck. I've tried different tags network configs and images. None of these have worked.</p> <p>Other info: The cluster was not originally a confidential cluster. The confidential nodes are the first of its kind added to the cluster.</p>
[ { "answer_id": 74298459, "author": "tomasgotchi", "author_id": 15489474, "author_profile": "https://Stackoverflow.com/users/15489474", "pm_score": 1, "selected": false, "text": "--enable-private-nodes" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17466473/" ]
74,298,127
<p>I am instructed to skip a value if it has been guessed correctly so that it can proceed to ask for the other value without being repeated. I am only beginning to learn Java and have yet to learn how to do this. I tried to search up how to skip the correct guessed value but could not find anything. Is there a way to do this? Thank you in advance.</p> <pre class="lang-java prettyprint-override"><code>while (guessX != randomX || guessY != randomY) { System.out.print(&quot;Enter a guess for the X position of Mr. Yertle: &quot;); guessX = scan.nextInt(); if (guessX &lt; randomX) { System.out.println(&quot;Too low! Guess higher.&quot;); } else if (guessX &gt; randomX) { System.out.println(&quot;Too high! Guess lower.&quot;); } else { System.out.println(&quot;Ding, ding! You are correct!&quot;); } System.out.print(&quot;Enter a guess for the Y position of Mr. Yertle: &quot;); guessY = scan.nextInt(); if (guessY &lt; randomY) { System.out.println(&quot;Too low! Guess higher.&quot;); } else if (guessY &gt; randomY) { System.out.println(&quot;Too high! Guess lower.&quot;); } else { System.out.println(&quot;Ding, ding! You are correct!&quot;); } </code></pre>
[ { "answer_id": 74298459, "author": "tomasgotchi", "author_id": 15489474, "author_profile": "https://Stackoverflow.com/users/15489474", "pm_score": 1, "selected": false, "text": "--enable-private-nodes" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403823/" ]
74,298,169
<p>I am basically trying to return a Function, used for a Stream, where any parameter can be either a Float or a Function. I was looking to make the input of dynamic values simpler for creative coding applications and feel I'm in over my head with streams and generics.</p> <p>Is there a more elegant way of doing this? Overloading the method would create a lot of duplicate code since I want any parameter to be either type. Also I looked at trying to create an interface, but couldn't do it without creating new class instances just to input a float as a parameter.</p> <pre><code>class A{ Function&lt;PVector, Float&gt; range( Object scale, Object min, Object max ){ FObj&lt;PVector&gt; fScale = getFO( scale ); FObj&lt;PVector&gt; fMin = getFO( min ); FObj&lt;PVector&gt; fMax = getFO( max ); return pv -&gt; map(noise(pv.x * fScale.getValue( pv ), pv.y * fScale.getValue( pv ) ), 0, 1, fMin.getValue( pv ), fMax.getValue( pv ) ); } &lt;T&gt; FObj&lt;T&gt; getFO ( Object input ) { if( input instanceof Float ) return new FObj&lt;T&gt;( (Float) input ); else if( input instanceof Function ) return new FObj&lt;T&gt;( (Function&lt;T,Float&gt;)input ); else throw new java.lang.RuntimeException(&quot;error&quot;); } } class FObj&lt;T&gt;{ Function&lt;T, Float&gt; fn; float val; FObj( Function&lt;T, Float&gt; fn ){ this.fn = fn; } FObj( float val ){ this.val = val; } float getValue( T input ){ return fn != null ? fn.apply( input ) : val; } } </code></pre> <p>Two use cases for range method at s and s2:</p> <pre><code>A a; List&lt;PVector&gt; pvs = new ArrayList&lt;&gt;(); pvs.add( new PVector( 0, 0 ) ); Stream s = pvs.stream().map( a.range( 0.02f, 0f, 255f )::apply ); Stream s2 = pvs.stream().map( a.range( a.range( 0.02f, 0.1f, 0.002f ), 0f, 255f )::apply ); </code></pre>
[ { "answer_id": 74298585, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "FObj<T>" }, { "answer_id": 74299293, "author": "oleg.cherednik", "author_id": 3461397, "author_profile": "https://Stackoverflow.com/users/3461397", "pm_score": 2, "selected": true, "text": "public static void main(String... args) throws IOException {\n List<PVector> pvs = List.of(new PVector(0, 0));\n\n Stream<Double> s = pvs.stream().map(new RangeBuilder().scale(.02)\n .min(0)\n .max(255)\n .build());\n Stream<Double> s2 = pvs.stream().map(new RangeBuilder().scale(new RangeBuilder().scale(.02)\n .min(.1)\n .max(.002)\n .build())\n .min(0)\n .max(255)\n .build());\n\n}\n\npublic static final class RangeBuilder {\n\n private Function<PVector, Double> scale;\n private Function<PVector, Double> min;\n private Function<PVector, Double> max;\n\n public RangeBuilder scale(Function<PVector, Double> scale) {\n this.scale = scale;\n return this;\n }\n\n public RangeBuilder scale(double scale) {\n return scale(in -> scale);\n }\n\n public RangeBuilder min(Function<PVector, Double> min) {\n this.min = min;\n return this;\n }\n\n public RangeBuilder min(double min) {\n return min(in -> min);\n }\n\n public RangeBuilder max(Function<PVector, Double> max) {\n this.max = max;\n return this;\n }\n\n public RangeBuilder max(double scale) {\n return scale(in -> scale);\n }\n\n public Function<PVector, Double> build() {\n return pv -> map(noise(pv.x * scale.apply(pv), pv.y * scale.apply(pv)), 0, 1, min.apply(pv), max.apply(pv));\n }\n\n}\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8715931/" ]
74,298,177
<p>I have a list where it has title and secondary description besides an image icon. I want to middle align the text and image icon as</p> <p><a href="https://i.stack.imgur.com/Gmvtw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gmvtw.png" alt="enter image description here" /></a></p> <p>as</p> <p><a href="https://i.stack.imgur.com/9RBrM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9RBrM.png" alt="enter image description here" /></a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"&gt; &lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;ul class="list-group"&gt; &lt;li class="list-group-item"&gt; &lt;div class="btn-group float-end"&gt; &lt;button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false"&gt; Action &lt;/button&gt; &lt;ul class="dropdown-menu dropdown-menu-lg-end"&gt; &lt;li&gt;&lt;a data-bs-toggle="modal" href="#exampleModalToggle" role="button" class="dropdown-item" href="#"&gt;Edit&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Delete&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Run&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;img src="https://img.icons8.com/color/48/000000/networking-manager.png"/&gt; A First item&lt;br/&gt; &lt;small class="text-secondary"&gt;This is a first item description&lt;/small&gt; &lt;div class="modal fade" id="exampleModalToggle" aria-hidden="true" aria-labelledby="exampleModalToggleLabel" tabindex="-1"&gt; &lt;div class="modal-dialog modal-fullscreen"&gt; &lt;div class="modal-content"&gt; &lt;div class="modal-header"&gt; &lt;h1 class="modal-title fs-5" id="exampleModalToggleLabel"&gt;Create a file&lt;/h1&gt; &lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"&gt;&lt;/button&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; What is Lorem Ipsum? &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;button class="btn btn-primary" data-bs-target="#exampleModalToggle2" data-bs-toggle="modal"&gt;Save&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li class="list-group-item"&gt;A second item&lt;/li&gt; &lt;li class="list-group-item"&gt;A third item&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74298217, "author": "Delowar Hossen", "author_id": 6602096, "author_profile": "https://Stackoverflow.com/users/6602096", "pm_score": 1, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n \n <style>\n .header-intro-section {\n /* display: flex; if you want to show full width, please use it */\n display: inline-flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n }\n </style>\n</head>\n\n<body>\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"btn-group float-end\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n <div class=\"header-intro-section\">\n <img src=\"https://img.icons8.com/color/48/000000/networking-manager.png\"/> \n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n</body>\n\n</html>\n" }, { "answer_id": 74298316, "author": "kmoser", "author_id": 378779, "author_profile": "https://Stackoverflow.com/users/378779", "pm_score": 2, "selected": true, "text": "<img>" }, { "answer_id": 74298352, "author": "Diksha", "author_id": 8580855, "author_profile": "https://Stackoverflow.com/users/8580855", "pm_score": 1, "selected": false, "text": " <hello name=\"{{ name }}\"></hello>\n <p>\n Start editing to see some magic happen :)\n </p>\n \n <!doctype html>\n <html lang=\"en\">\n \n <head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n </head>\n \n <body>\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"btn-group float-end\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n \n <img style=\"float:left;\" src=\"https://img.icons8.com/color/48/000000/networking-manager.png\"/> \n /*DIV for title and description*/ \n <div style=\"float:left;\" >\n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n </body>\n \n </html>\n\nThe main part of solution is putting title and secondary description into div and assigning this image and div as `\"float:left\"`\n" }, { "answer_id": 74312213, "author": "Patel Harsh", "author_id": 16833415, "author_profile": "https://Stackoverflow.com/users/16833415", "pm_score": 0, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\"\n integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\"\n integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\"\n crossorigin=\"anonymous\"></script>\n</head>\n\n<body>\n\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"d-flex flex-wrap align-items-center justify-content-between\">\n <div class=\"d-flex align-items-center gap-3\">\n <img class=\"img-fluid\" src=\"https://img.icons8.com/color/48/000000/networking-manager.png\" alt=\"img\" />\n <div class=\"d-flex flex-column\">\n <div>A First item</div>\n <div><small class=\"text-secondary\">This is a first item description</small></div>\n </div>\n </div>\n <div class=\"dropdown\">\n <button class=\"btn dropdown-toggle\" type=\"button\" data-bs-toggle=\"dropdown\" aria-expanded=\"false\">\n Action\n </button>\n <ul class=\"dropdown-menu\">\n <li><a class=\"dropdown-item\" data-bs-toggle=\"modal\" href=\"#exampleModalToggle\"\n role=\"button\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n\n <!-- Edit Modal -->\n\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\"\n tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\"\n data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n\n</body>\n\n</html>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5549354/" ]
74,298,195
<p>I'm an undergrad and in one of my classes, we have this assignment to make the Asteroids game (you know, the retro one!) on Processing (which is basically a simplified Javascript program). I have the code for a button:</p> <pre><code>void setup() { size(1280, 720); } void draw() { background(0,0,0); drawButton(); } Boolean pointIsInRectangle(int left, int top, int right, int bottom, int pointX, int pointY) { if (pointX &gt;= left &amp;&amp; pointX &lt;= right &amp;&amp; pointY &lt;= bottom &amp;&amp; pointY &gt;= top ) return true; else return false; } void drawButton() { int left = 350; int top = 145; int right = 860; int bottom = 220; rectMode(CORNERS); color background = color(0,0,0); if (pointIsInRectangle(left,top,right,bottom,mouseX,mouseY)) { background = color(255); } // draw outer rectangle stroke(255); fill(background); rect(left,top,right,bottom); // draw caption fill(255); textSize(100); text(&quot; ASTEROIDS&quot;, left,bottom); } </code></pre> <p>and I have the preliminary code for the ship for the game, but I need the button to get to an &quot;in between&quot; page so that when the button is clicked, it leads to a new screen that says &quot;click anywhere to play game&quot; and when any point in the screen is clicked, the ship appears and asteroids begin appearing and the game begins. HOW DO I GET THE BUTTON TO LEAD TO A NEW PAGE, AND HOW DO I CREATE THAT PAGE? I really cannot figure it out. Crossing my fingers that someone will be able to give me some guidance!!!!!</p> <p>The actual result I'm seeing is that nothing is happening when the button is clicked. This makes sense because I don't know how to add the next page that says Click to Play Game, so this is the issue I'm facing. The code I have so far can be found above.</p>
[ { "answer_id": 74298217, "author": "Delowar Hossen", "author_id": 6602096, "author_profile": "https://Stackoverflow.com/users/6602096", "pm_score": 1, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n \n <style>\n .header-intro-section {\n /* display: flex; if you want to show full width, please use it */\n display: inline-flex;\n justify-content: center;\n align-items: center;\n flex-direction: column;\n }\n </style>\n</head>\n\n<body>\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"btn-group float-end\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n <div class=\"header-intro-section\">\n <img src=\"https://img.icons8.com/color/48/000000/networking-manager.png\"/> \n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n</body>\n\n</html>\n" }, { "answer_id": 74298316, "author": "kmoser", "author_id": 378779, "author_profile": "https://Stackoverflow.com/users/378779", "pm_score": 2, "selected": true, "text": "<img>" }, { "answer_id": 74298352, "author": "Diksha", "author_id": 8580855, "author_profile": "https://Stackoverflow.com/users/8580855", "pm_score": 1, "selected": false, "text": " <hello name=\"{{ name }}\"></hello>\n <p>\n Start editing to see some magic happen :)\n </p>\n \n <!doctype html>\n <html lang=\"en\">\n \n <head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\" crossorigin=\"anonymous\"></script>\n </head>\n \n <body>\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"btn-group float-end\">\n <button type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" data-bs-display=\"static\" aria-expanded=\"false\"> Action </button>\n <ul class=\"dropdown-menu dropdown-menu-lg-end\">\n <li><a data-bs-toggle=\"modal\" href=\"#exampleModalToggle\" role=\"button\" class=\"dropdown-item\" href=\"#\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n \n <img style=\"float:left;\" src=\"https://img.icons8.com/color/48/000000/networking-manager.png\"/> \n /*DIV for title and description*/ \n <div style=\"float:left;\" >\n A First item<br/>\n <small class=\"text-secondary\">This is a first item description</small>\n </div>\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\" tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\" data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n \n </body>\n \n </html>\n\nThe main part of solution is putting title and secondary description into div and assigning this image and div as `\"float:left\"`\n" }, { "answer_id": 74312213, "author": "Patel Harsh", "author_id": 16833415, "author_profile": "https://Stackoverflow.com/users/16833415", "pm_score": 0, "selected": false, "text": "<!doctype html>\n<html lang=\"en\">\n\n<head>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\"\n integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\"\n integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\"\n crossorigin=\"anonymous\"></script>\n</head>\n\n<body>\n\n <ul class=\"list-group\">\n <li class=\"list-group-item\">\n <div class=\"d-flex flex-wrap align-items-center justify-content-between\">\n <div class=\"d-flex align-items-center gap-3\">\n <img class=\"img-fluid\" src=\"https://img.icons8.com/color/48/000000/networking-manager.png\" alt=\"img\" />\n <div class=\"d-flex flex-column\">\n <div>A First item</div>\n <div><small class=\"text-secondary\">This is a first item description</small></div>\n </div>\n </div>\n <div class=\"dropdown\">\n <button class=\"btn dropdown-toggle\" type=\"button\" data-bs-toggle=\"dropdown\" aria-expanded=\"false\">\n Action\n </button>\n <ul class=\"dropdown-menu\">\n <li><a class=\"dropdown-item\" data-bs-toggle=\"modal\" href=\"#exampleModalToggle\"\n role=\"button\">Edit</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Delete</a></li>\n <li><a class=\"dropdown-item\" href=\"#\">Run</a></li>\n </ul>\n </div>\n </div>\n </li>\n <li class=\"list-group-item\">A second item</li>\n <li class=\"list-group-item\">A third item</li>\n </ul>\n\n <!-- Edit Modal -->\n\n <div class=\"modal fade\" id=\"exampleModalToggle\" aria-hidden=\"true\" aria-labelledby=\"exampleModalToggleLabel\"\n tabindex=\"-1\">\n <div class=\"modal-dialog modal-fullscreen\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h1 class=\"modal-title fs-5\" id=\"exampleModalToggleLabel\">Create a file</h1>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n </div>\n <div class=\"modal-body\"> What is Lorem Ipsum? </div>\n <div class=\"modal-footer\">\n <button class=\"btn btn-primary\" data-bs-target=\"#exampleModalToggle2\"\n data-bs-toggle=\"modal\">Save</button>\n </div>\n </div>\n </div>\n </div>\n\n</body>\n\n</html>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403848/" ]
74,298,201
<p>How to add small letter (sub) under a word in html and css? I am attaching the screenshot. Want to write &quot;Max 100, Min 1 just like the picture below. my code is here:</p> <pre class="lang-html prettyprint-override"><code>&lt;input type=&quot;text&quot; class=&quot;textarea&quot; alt=&quot;&quot; value=&quot;&quot; style=&quot;color: #1c91df; height: 50px; width: 100%; margin-top: 0px; margin-bottom: 0px; border-color: #1c91df; box-shadow: none; border-width: 1px;&quot;&gt; &lt;input type=&quot;number&quot; class=&quot;textarea&quot; alt=&quot;height&quot; value=&quot;10&quot; style=&quot;color:#30a2ee;&quot;/&gt; Height &lt;sub&gt;Max 100&lt;/sub&gt; &lt;sub&gt;Min 1&lt;/sub&gt; &lt;input type=&quot;number&quot; class=&quot;textarea1&quot; alt=&quot;depth&quot; value=&quot;10&quot; style=&quot;color:#30a2ee;&quot;/&gt; Depth &lt;sub&gt;Max 100&lt;/sub&gt; &lt;sub&gt;Min 1&lt;/sub&gt; </code></pre> <p><a href="https://i.stack.imgur.com/LS96T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LS96T.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74298243, "author": "Delowar Hossen", "author_id": 6602096, "author_profile": "https://Stackoverflow.com/users/6602096", "pm_score": 0, "selected": false, "text": "sub {\n text-transform: lowercase;\n}\n" }, { "answer_id": 74298280, "author": "SwAn", "author_id": 6357309, "author_profile": "https://Stackoverflow.com/users/6357309", "pm_score": 1, "selected": false, "text": "sub {\n text-transform: lowercase; \n}\n" }, { "answer_id": 74299724, "author": "Choose Goose", "author_id": 19829483, "author_profile": "https://Stackoverflow.com/users/19829483", "pm_score": 1, "selected": false, "text": "<div class=\"mygroup\">\n <input type=\"number\" class=\"textarea\" alt=\"height\" value=\"10\" style=\"color:#30a2ee;\"/>\n <div class=\"mystyle\">\n <span>Height</span>\n <sub>Max 100</sub> \n <sub>Min 1</sub>\n </div>\n \n <input type=\"number\" class=\"textarea1\" alt=\"width\" value=\"10\" style=\"color:#30a2ee;\"/>\n <div class=\"mystyle\">\n <span>Width</span>\n <sub>Max 100</sub>\n <sub>Min 1</sub>\n </div>\n</div>\n" }, { "answer_id": 74308990, "author": "JShobbyist", "author_id": 14912225, "author_profile": "https://Stackoverflow.com/users/14912225", "pm_score": 1, "selected": false, "text": "<div class=\"demention\">\n <input type=\"number\" class=\"textarea\" alt=\"height\" value=\"10\" style=\"color:#30a2ee;\"/>\n <p class=\"big_text\">Height</p>\n \n <input type=\"number\" class=\"textarea\" alt=\"depth\" value=\"100\" style=\"color:#30a2ee;\"/>\n <p class=\"big_text\">Depth</p>\n</div>\n\n<style>\n .demention {\n display: flex;\n flex-direction: row;\n align-content: center;\n min-height: 50px;\n }\n .demention .textarea {\n margin-right: 10px;\n padding: 10px;\n width: 100px;\n border: 1px solid #30a2ee;\n }\n .demention .big_text {\n position: relative;\n padding-right: 30px;\n color: #30a2ee;\n }\n p.big_text:before {\n content: \"Max. 100\";\n position: absolute;\n left: 0;\n top: 25px;\n opacity: 0.5;\n }\n p.big_text:after {\n content: \"Min. 1\";\n position: absolute;\n left: 0;\n top: 40px;\n opacity: 0.5;\n }\n</style>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6853209/" ]
74,298,204
<ol> <li>convert uppercase to lowercase</li> <li>add below it.</li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>en</th> <th>ko</th> </tr> </thead> <tbody> <tr> <td>Acceptive</td> <td>Acceptive koean mean</td> </tr> <tr> <td>Access</td> <td>Access koean mean</td> </tr> </tbody> </table> </div> <p>=&gt;</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>en</th> <th>ko</th> </tr> </thead> <tbody> <tr> <td>Acceptive</td> <td>Acceptive koean</td> </tr> <tr> <td>acceptive</td> <td>Acctptive koean</td> </tr> <tr> <td>Access</td> <td>Access koean</td> </tr> <tr> <td>access</td> <td>Accesskoean</td> </tr> </tbody> </table> </div> <p>please help !!!!!!!</p>
[ { "answer_id": 74298243, "author": "Delowar Hossen", "author_id": 6602096, "author_profile": "https://Stackoverflow.com/users/6602096", "pm_score": 0, "selected": false, "text": "sub {\n text-transform: lowercase;\n}\n" }, { "answer_id": 74298280, "author": "SwAn", "author_id": 6357309, "author_profile": "https://Stackoverflow.com/users/6357309", "pm_score": 1, "selected": false, "text": "sub {\n text-transform: lowercase; \n}\n" }, { "answer_id": 74299724, "author": "Choose Goose", "author_id": 19829483, "author_profile": "https://Stackoverflow.com/users/19829483", "pm_score": 1, "selected": false, "text": "<div class=\"mygroup\">\n <input type=\"number\" class=\"textarea\" alt=\"height\" value=\"10\" style=\"color:#30a2ee;\"/>\n <div class=\"mystyle\">\n <span>Height</span>\n <sub>Max 100</sub> \n <sub>Min 1</sub>\n </div>\n \n <input type=\"number\" class=\"textarea1\" alt=\"width\" value=\"10\" style=\"color:#30a2ee;\"/>\n <div class=\"mystyle\">\n <span>Width</span>\n <sub>Max 100</sub>\n <sub>Min 1</sub>\n </div>\n</div>\n" }, { "answer_id": 74308990, "author": "JShobbyist", "author_id": 14912225, "author_profile": "https://Stackoverflow.com/users/14912225", "pm_score": 1, "selected": false, "text": "<div class=\"demention\">\n <input type=\"number\" class=\"textarea\" alt=\"height\" value=\"10\" style=\"color:#30a2ee;\"/>\n <p class=\"big_text\">Height</p>\n \n <input type=\"number\" class=\"textarea\" alt=\"depth\" value=\"100\" style=\"color:#30a2ee;\"/>\n <p class=\"big_text\">Depth</p>\n</div>\n\n<style>\n .demention {\n display: flex;\n flex-direction: row;\n align-content: center;\n min-height: 50px;\n }\n .demention .textarea {\n margin-right: 10px;\n padding: 10px;\n width: 100px;\n border: 1px solid #30a2ee;\n }\n .demention .big_text {\n position: relative;\n padding-right: 30px;\n color: #30a2ee;\n }\n p.big_text:before {\n content: \"Max. 100\";\n position: absolute;\n left: 0;\n top: 25px;\n opacity: 0.5;\n }\n p.big_text:after {\n content: \"Min. 1\";\n position: absolute;\n left: 0;\n top: 40px;\n opacity: 0.5;\n }\n</style>" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19833416/" ]
74,298,283
<p>hopefully someone has an idea for a more performant Oracle SQL.</p> <p>Following Oracle PERSON-Table:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>PERSON_ID</th> <th>REFERENCE_ID</th> <th>COMMENT</th> <th>CREATION_DATE</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>10066</td> <td>666</td> <td>comment 2 days ago</td> <td>01-11-2022 09:16:00.00000</td> </tr> <tr> <td>2</td> <td>10066</td> <td>111</td> <td>single comment</td> <td>01-11-2022 11:44:00.00000</td> </tr> <tr> <td>3</td> <td>10066</td> <td>666</td> <td>comment 1 day ago</td> <td>02-11-2022 07:37:00.00000</td> </tr> <tr> <td>4</td> <td>33444</td> <td>666</td> <td>comment of different person</td> <td>02-11-2022 09:54:00.00000</td> </tr> <tr> <td>5</td> <td>10066</td> <td>666</td> <td>comment today</td> <td>03-11-2022 08:46:00.00000</td> </tr> <tr> <td>6</td> <td>10066</td> <td>987</td> <td>another comment</td> <td>03-11-2022 09:02:00.00000</td> </tr> <tr> <td>7</td> <td>10066</td> <td>987</td> <td>another comment same day</td> <td>03-11-2022 09:44:22.123456</td> </tr> </tbody> </table> </div> <p>I want to have only the recent timestamps of identical REFERENCE_ID results from a specific PERSON_ID.</p> <p>So I expect 3 rows should be in the result list for PERSON_ID 10066:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>PERSON_ID</th> <th>REFERENCE_ID</th> <th>COMMENT</th> <th>CREATION_DATE</th> </tr> </thead> <tbody> <tr> <td>10066</td> <td>111</td> <td>single comment</td> <td>01-11-2022 11:44:00.00000</td> </tr> <tr> <td>10066</td> <td>666</td> <td>comment today</td> <td>03-11-2022 08:46:00.00000</td> </tr> <tr> <td>10066</td> <td>987</td> <td>another comment same day</td> <td>03-11-2022 09:44:22.123456</td> </tr> </tbody> </table> </div> <p>I came up with a subselect idea which works, but is possibly not the best / most performant solution:</p> <pre class="lang-sql prettyprint-override"><code>SELECT * FROM PERSON_TABLE p WHERE CREATION_DATE = ( SELECT MAX(CREATION_DATE) FROM PERSON_TABLE WHERE REFERENCE_ID = p.REFERENCE_ID AND PERSON_ID = 10066 ); </code></pre> <p>Has someone a better idea? Or is my approach ok performance wise? I have the feeling there are more optimized statements / queries possible, maybe without subselect.</p> <p>Thanks in advance, have a nice day!</p>
[ { "answer_id": 74298347, "author": "mio123", "author_id": 20404036, "author_profile": "https://Stackoverflow.com/users/20404036", "pm_score": -1, "selected": false, "text": "DISTINCT" }, { "answer_id": 74298773, "author": "Littlefoot", "author_id": 9097906, "author_profile": "https://Stackoverflow.com/users/9097906", "pm_score": 1, "selected": false, "text": "SQL> with person (id, person_id, reference_id, creation_date) as\n 2 (select 1, 1066, 666, to_date('01.11.2022 09:16', 'dd.mm.yyyy hh24:mi') from dual union all\n 3 select 2, 1066, 111, to_date('01.11.2022 11:44', 'dd.mm.yyyy hh24:mi') from dual union all\n 4 select 3, 1066, 666, to_date('02.11.2022 07:37', 'dd.mm.yyyy hh24:mi') from dual union all\n 5 select 5, 1066, 666, to_date('03.11.2022 08:46', 'dd.mm.yyyy hh24:mi') from dual union all\n 6 select 6, 1066, 987, to_date('03.11.2022 09:02', 'dd.mm.yyyy hh24:mi') from dual union all\n 7 select 7, 1066, 987, to_date('03.11.2022 09:44', 'dd.mm.yyyy hh24:mi') from dual\n 8 ),\n" }, { "answer_id": 74304629, "author": "Wernfried Domscheit", "author_id": 3027266, "author_profile": "https://Stackoverflow.com/users/3027266", "pm_score": 2, "selected": false, "text": "WITH t (ID, person_id, reference_id, \"COMMENT\", creation_date) AS (\n SELECT 1, 1066, 666, 'comment 2 days ago', TO_DATE('01.11.2022 09:16', 'dd.mm.yyyy hh24:mi') FROM dual UNION ALL\n SELECT 2, 1066, 111, 'single comment', TO_DATE('01.11.2022 11:44', 'dd.mm.yyyy hh24:mi') FROM dual UNION ALL\n SELECT 3, 1066, 666, 'comment 1 day ago', TO_DATE('02.11.2022 07:37', 'dd.mm.yyyy hh24:mi') FROM dual UNION ALL\n SELECT 5, 1066, 666, 'comment of different person', TO_DATE('03.11.2022 08:46', 'dd.mm.yyyy hh24:mi') FROM dual UNION ALL\n SELECT 6, 1066, 987, 'comment today', TO_DATE('03.11.2022 09:02', 'dd.mm.yyyy hh24:mi') FROM dual UNION ALL\n SELECT 7, 1066, 987, 'another comment', TO_DATE('03.11.2022 09:44', 'dd.mm.yyyy hh24:mi') FROM dual\n)\nSELECT PERSON_ID, REFERENCE_ID,\n MIN(\"COMMENT\") KEEP (DENSE_RANK LAST ORDER BY creation_date) AS \"COMMENT\",\n MIN(creation_date) KEEP (DENSE_RANK last ORDER BY creation_date) AS creation_date\nFROM t\nGROUP BY PERSON_ID, REFERENCE_ID;\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298283", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403542/" ]
74,298,299
<p>Tried to compile following code, can't understand error message.</p> <pre><code>#include&lt;iostream&gt; #include&lt;string&gt; using namespace std; struct S { string a{&quot;abc&quot;}; const string&amp; data() { return a; } }; int main() { S s; int a = s.data(); // error: no viable conversion from 'const std::string' to 'int' return 0; } </code></pre> <p>Question: why does compiler say 'const std::string' instead of 'const std::string&amp;'?</p> <p>Tried with Apple clang 14.0.0 and g++ 12, same error message.</p>
[ { "answer_id": 74298323, "author": "Remy Lebeau", "author_id": 65863, "author_profile": "https://Stackoverflow.com/users/65863", "pm_score": 4, "selected": true, "text": "data()" }, { "answer_id": 74298433, "author": "HolyBlackCat", "author_id": 2752075, "author_profile": "https://Stackoverflow.com/users/2752075", "pm_score": 2, "selected": false, "text": "s.data()" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298299", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3700927/" ]
74,298,336
<p>This code:</p> <pre><code>user_data_list = [['Full Name', ' Email Address'],['Blossom Gill', ' blossom@abc.edu'], ['Hayes Delgado', ' nonummy@utnisia.com'], ['Petra Jones', ' ac@abc.edu'], ['Oleg Noel', ' noel@liberomauris.ca']] old_domain_email_list = ['blossom@abc.edu','ac@abc.edu'] new_domain_email_list = ['blossom@xyz.edu','ac@xyz.edu'] for user in user_data_list[1:]: for old_domain, new_domain in zip(old_domain_email_list, new_domain_email_list): if user[1] == ' ' + old_domain: user[1] = ' ' + new_domain print(user_data_list) </code></pre> <p>The result:</p> <pre><code>[['Full Name', ' Email Address'], ['Blossom Gill', ' blossom@xyz.edu'], ['Hayes Delgado', ' nonummy@utnisia.com'], ['Petra Jones', ' ac@xyz.edu'], ['Oleg Noel', ' noel@liberomauris.ca']] </code></pre> <p>I really don't understand why the value of <code>user_data_list</code> list changed in this code. As i can see, just the user variable that was unpacked in the for loop is changed when the if statement is true.</p> <p>i have tried the same code and i adjust my_list list a bit differently. But the result is different than above code, my_list list did't changed</p> <pre><code>my_list = ['a','b','c','d'] old_my_list = ['b','d'] new_my_list = ['repalce_1','repalce_2'] for i in my_list: for old_, new_ in zip(old_my_list,new_my_list): if i == old_: i= new_ print(my_list) </code></pre> <p>The result:</p> <pre><code>['a', 'b', 'c', 'd'] </code></pre>
[ { "answer_id": 74298370, "author": "Abhi", "author_id": 7430727, "author_profile": "https://Stackoverflow.com/users/7430727", "pm_score": 1, "selected": false, "text": "memory address" }, { "answer_id": 74298418, "author": "annes", "author_id": 16812850, "author_profile": "https://Stackoverflow.com/users/16812850", "pm_score": 0, "selected": false, "text": "from copy import deepcopy\n\nuser_data_list = [['Full Name', ' Email Address'],['Blossom Gill', ' blossom@abc.edu'],\n ['Hayes Delgado', ' nonummy@utnisia.com'], ['Petra Jones', ' ac@abc.edu'],\n ['Oleg Noel', ' noel@liberomauris.ca']]\noriginal = deepcopy(user_data_list) # 140007211377088 \n# OR use the one below.\noriginal = user_data_list[:] # 140007211479424\nprint(id(user_data_list))\nprint(id(original))\nold_domain_email_list = ['blossom@abc.edu','ac@abc.edu']\nnew_domain_email_list = ['blossom@xyz.edu','ac@xyz.edu']\nfor user in user_data_list[1:]:\n for old_domain, new_domain in zip(old_domain_email_list, new_domain_email_list):\n if user[1] == ' ' + old_domain:\n user[1] = ' ' + new_domain\n" } ]
2022/11/03
[ "https://Stackoverflow.com/questions/74298336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20270687/" ]