qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,326,439
<p>I have a table which shows the simulated daily returns of different stocks. The variable date_simul is the date where the simulation was done, stock is the name of the stock simulated, N simul is the number of simulations for each stock (depending on the stock might be 1000, 5000 or 10000), simul is nth value simulated of the stock, FutureDate is the date where the stock is being simulated and Return, the daily return of the stock simulated in the future date.</p> <p>SQL so far:</p> <pre><code>select date_simul, Stock, N Simu, FutureDate, Return exp(sum(ln(1+Return)) over (order by FutureDate asc)) - 1 as cumul from portfolio order by Stock, FutureDate; </code></pre> <p>I would like to get the cumulative return, day 1, (1 + r1) - 1, day 2, (1 + r1)*(1 + r2) - 1 and so on. Likewise, I wanted to use the fact that:</p> <pre><code>(1+r1)*(1+r2)*(1+r3) - 1 = exp(log(1+r1) + log(1+r2) + log(1+r3)) - 1, </code></pre> <p>since a sum should be easier than a product. I have tried using the query above, but with no success.</p> <p>Data:</p> <pre><code>date_simul|Stock|N Simu|FutureDate| Return 30/09/22 | A | 1000 | 01/10/22 | -0,0073 30/09/22 | A | 1000 | 02/09/22 | 0,0078 30/09/22 | A | 1000 | 03/09/22 | 0,0296 30/09/22 | A | 1000 | 04/09/22 | 0,0602 30/09/22 | A | 1000 | 05/10/22 | -0,0177 </code></pre> <p>Desired results:</p> <pre><code>date_simul|Stock|N Simu|FutureDate| Return | Cumul 30/09/22 | A | 1000 | 01/10/22 | -0,0073| -0,0073 30/09/22 | A | 1000 | 02/09/22 | 0,0078 | 0,0004 30/09/22 | A | 1000 | 03/09/22 | 0,0296 | 0,0301 30/09/22 | A | 1000 | 04/09/22 | 0,0602 | 0,0921 30/09/22 | A | 1000 | 05/10/22 | -0,0177| 0,0727 </code></pre>
[ { "answer_id": 74326891, "author": "d r", "author_id": 19023353, "author_profile": "https://Stackoverflow.com/users/19023353", "pm_score": 3, "selected": true, "text": "WITH\n tbl AS\n (\n Select To_Date('30/09/22', 'dd/mm/yy') \"DATE_SIMUL\", 'A' \"STOCK\", To_Date('01/10/22', 'dd/mm/yy') \"FUTURE_DATE\", -0.0073 \"RETURN\" From Dual Union All\n Select To_Date('30/09/22', 'dd/mm/yy') \"DATE_SIMUL\", 'A' \"STOCK\", To_Date('02/09/22', 'dd/mm/yy') \"FUTURE_DATE\", 0.0078 \"RETURN\" From Dual Union All\n Select To_Date('30/09/22', 'dd/mm/yy') \"DATE_SIMUL\", 'A' \"STOCK\", To_Date('03/09/22', 'dd/mm/yy') \"FUTURE_DATE\", 0.0296 \"RETURN\" From Dual Union All\n Select To_Date('30/09/22', 'dd/mm/yy') \"DATE_SIMUL\", 'A' \"STOCK\", To_Date('04/09/22', 'dd/mm/yy') \"FUTURE_DATE\", 0.0602 \"RETURN\" From Dual Union All\n Select To_Date('30/09/22', 'dd/mm/yy') \"DATE_SIMUL\", 'A' \"STOCK\", To_Date('05/10/22', 'dd/mm/yy') \"FUTURE_DATE\", -0.0177 \"RETURN\" From Dual \n )\n\nSelect \n t.*,\n Sum(t.RETURN) OVER(PARTITION BY t.STOCK ORDER BY t.STOCK, t.RN ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) \"CUMUL\"\nFrom\n (SELECT ROW_NUMBER() OVER(Order By 1) \"RN\", tbl.* From tbl) t\nOrder By t.RN\n/* R e s u l t :\n RN DATE_SIMUL STOCK FUTURE_DATE RETURN CUMUL\n---------- ---------- ----- ----------- ---------- ----------\n 1 30-SEP-22 A 01-OCT-22 -0.0073 -0.0073 \n 2 30-SEP-22 A 02-SEP-22 .0078 .0005 \n 3 30-SEP-22 A 03-SEP-22 .0296 .0301 \n 4 30-SEP-22 A 04-SEP-22 .0602 .0903 \n 5 30-SEP-22 A 05-OCT-22 -0.0177 .0726\n*/\n" }, { "answer_id": 74331623, "author": "MT0", "author_id": 1509264, "author_profile": "https://Stackoverflow.com/users/1509264", "pm_score": 1, "selected": false, "text": "date_simul" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20347245/" ]
74,326,451
<p>hi I have Row in flutter and I want add some widget on row with listview.builder, listview sort all item vertically. but I want show them horizontally. in the image below you can see my code and the result.so how can i change the listview.builder to horizontal? <a href="https://i.stack.imgur.com/qrpTD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qrpTD.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74326477, "author": "Madhusudhan Sahni", "author_id": 8340663, "author_profile": "https://Stackoverflow.com/users/8340663", "pm_score": 0, "selected": false, "text": "Widget build(BuildContext context) {\nWidget horizontalList = new Container(\n margin: EdgeInsets.symmetric(vertical: 20.0),\n height: 200.0,\n child: new ListView(\n scrollDirection: Axis.horizontal,\n children: <Widget>[\n Container(width: 160.0, color: Colors.red,),\n Container(width: 160.0, color: Colors.orange,),\n Container(width: 160.0, color: Colors.pink,),\n Container(width: 160.0, color: Colors.yellow,),\n ],\n)\n);\n);\nreturn new Scaffold(\n appBar: new AppBar(\n title: new Text(widget.title),\n ),\n body: new Center(\n child: horizontalList,\n ), \n);\n" }, { "answer_id": 74326496, "author": "Pankti Shah", "author_id": 12364626, "author_profile": "https://Stackoverflow.com/users/12364626", "pm_score": 1, "selected": false, "text": " scrollDirection: Axis.horizontal,\n \n" }, { "answer_id": 74326507, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 3, "selected": true, "text": "height" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14392462/" ]
74,326,457
<p>I have a list of objects, these are blue stickmen on the video, I need to make the camera move away by itself and all objects (blue stickmen) always fit into it, you need to take into account that there will be more and more objects each time, so the camera should be dynamic and adapt itself to all objects</p> <p><a href="https://youtube.com/shorts/x3uSO2L22Kc?feature=share" rel="nofollow noreferrer">https://youtube.com/shorts/x3uSO2L22Kc?feature=share</a></p>
[ { "answer_id": 74326477, "author": "Madhusudhan Sahni", "author_id": 8340663, "author_profile": "https://Stackoverflow.com/users/8340663", "pm_score": 0, "selected": false, "text": "Widget build(BuildContext context) {\nWidget horizontalList = new Container(\n margin: EdgeInsets.symmetric(vertical: 20.0),\n height: 200.0,\n child: new ListView(\n scrollDirection: Axis.horizontal,\n children: <Widget>[\n Container(width: 160.0, color: Colors.red,),\n Container(width: 160.0, color: Colors.orange,),\n Container(width: 160.0, color: Colors.pink,),\n Container(width: 160.0, color: Colors.yellow,),\n ],\n)\n);\n);\nreturn new Scaffold(\n appBar: new AppBar(\n title: new Text(widget.title),\n ),\n body: new Center(\n child: horizontalList,\n ), \n);\n" }, { "answer_id": 74326496, "author": "Pankti Shah", "author_id": 12364626, "author_profile": "https://Stackoverflow.com/users/12364626", "pm_score": 1, "selected": false, "text": " scrollDirection: Axis.horizontal,\n \n" }, { "answer_id": 74326507, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 3, "selected": true, "text": "height" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13383951/" ]
74,326,468
<p>Below is my code:</p> <pre><code>import win32com.client import os outlook = win32com.client.Dispatch(&quot;Outlook.Application&quot;).GetNamespace(&quot;MAPI&quot;) inbox = outlook.GetDefaultFolder(6) # &quot;6&quot; refers to the index of a folder - in this case the inbox. You can change that number to reference messages = inbox.Items message = messages.GetFirst() subject = message.Subject body = message.body # get_path = 'C:\\Users\\username\\Downloads' for m in messages: if m.Subject == &quot;Dummy report&quot;: attachments = message.Attachments num_attach = len([x for x in attachments]) for x in range(1, num_attach): attachment = attachments.Item(x) attachment.SaveAsFile(os.path.join(get_path,attachment.FileName)) print (attachment.FileName) break else: message = messages.GetNext() </code></pre> <p>Please let me know what is wrong with this code. I was able to find the specific mail but I was not able to download the attachment associated with that mail.</p>
[ { "answer_id": 74328760, "author": "Eugene Astafiev", "author_id": 1603351, "author_profile": "https://Stackoverflow.com/users/1603351", "pm_score": 1, "selected": false, "text": "OlAttachmentType" }, { "answer_id": 74330090, "author": "DS_London", "author_id": 13812982, "author_profile": "https://Stackoverflow.com/users/13812982", "pm_score": 0, "selected": false, "text": "import win32com.client as wc\nfrom os.path import join\n\nol = wc.gencache.EnsureDispatch('Outlook.Application')\nns = ol.GetNamespace('MAPI')\n\ninbox = ns.GetDefaultFolder(wc.constants.olFolderInbox)\n\nitems = inbox.Items\npattern = 'Dummy report'\n\ncriteria = '@SQL=\"urn:schemas:httpmail:subject\" like \\'%' + pattern + '%\\''\n \nmsg = items.Find(criteria)\n\nwhile msg is not None:\n for att in msg.Attachments:\n if att.Type == wc.constants.olByValue:\n att.SaveAsFile(join('c:\\\\temp',att.FileName))\n print(att.FileName)\n \n msg = items.FindNext()\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19791187/" ]
74,326,473
<p>I have a data frame include two groups, each group with four points, and I want to plot them using smooth line in r. The dataframe is:</p> <pre><code>df &lt;- data.frame(x=c(12,25,50,85,12,25,50,85), y=c(1.02, 1.05, 0.99, 1.07, 1.03, 1.06, 1.09, 1.10), Type=c(&quot;AD&quot;,&quot;AD&quot;,&quot;AD&quot;,&quot;AD&quot;,&quot;WT&quot;,&quot;WT&quot;,&quot;WT&quot;,&quot;WT&quot;)) </code></pre> <p>I used the code:</p> <pre><code>ggplot(df) + geom_point(aes(x=x, y=y, color=Type, group=Type), size = 3) + geom_line(aes(y=y, x=x, group = Type, color=Type)) + stat_smooth(aes(y=y, x=x), method = &quot;loose&quot;, formula = y~ poly(x, 21), se = FALSE) </code></pre> <p>However the plot I got is not smooth as I expected. How could I change on code? Is it because the limited point number? Thanks a lot in advance! <a href="https://i.stack.imgur.com/YxnhM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YxnhM.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74326665, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "\"loose\"" }, { "answer_id": 74326744, "author": "ecl", "author_id": 10293541, "author_profile": "https://Stackoverflow.com/users/10293541", "pm_score": 0, "selected": false, "text": " geom_point(size = 3) + \n geom_smooth(method = \"loess\", span = 0.75, se = FALSE)\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18216205/" ]
74,326,484
<p>I'm trying to set a linear gradient color as background of my HTML page, but when I apply the CSS style instead to stretch to the all page it repeat as you can see in the picture below.</p> <p>How can I solve this issue and why?</p> <p><a href="https://i.stack.imgur.com/L890b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L890b.png" alt="pic" /></a></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;title&gt;Test BootStrap&lt;/title&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;index.css&quot;&gt; &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi&quot; crossorigin=&quot;anonymous&quot;&gt; &lt;/head&gt; &lt;body class=&quot;body-page&quot;&gt; Hello &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <pre><code>.body-page{ background-image: linear-gradient(blue,red); } </code></pre>
[ { "answer_id": 74326665, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "\"loose\"" }, { "answer_id": 74326744, "author": "ecl", "author_id": 10293541, "author_profile": "https://Stackoverflow.com/users/10293541", "pm_score": 0, "selected": false, "text": " geom_point(size = 3) + \n geom_smooth(method = \"loess\", span = 0.75, se = FALSE)\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9962676/" ]
74,326,499
<p>How to type my useState hook correctly?</p> <p>I have this <code>enum</code> type:</p> <pre><code>export enum Status { PENDING = 'pending', SUCCESS = 'success', ERROR = 'error', } </code></pre> <p>And the <code>useState</code> hook: <code>const [isValid, setIsValid] = useState&lt;// What to add here&gt;(ApiStatus.PENDING);</code></p> <p>So that the value of the useState hook can only be one of the <code>Status</code> values?</p>
[ { "answer_id": 74326516, "author": "Tobias S.", "author_id": 8613630, "author_profile": "https://Stackoverflow.com/users/8613630", "pm_score": 3, "selected": true, "text": "Status" }, { "answer_id": 74326565, "author": "Tushar Shahi", "author_id": 10140124, "author_profile": "https://Stackoverflow.com/users/10140124", "pm_score": 0, "selected": false, "text": "keyof" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4822666/" ]
74,326,520
<p>I have a YAML file which also has lists.</p> <p>YAML File -</p> <pre><code>configuration: account: account1 warehouse: warehouse1 database: database1 object_type: schema: schema1 functions: funtion1 tables: - table: table1 sql_file_loc: some_path/some_file.sql - table: table2 sql_file_loc: some_path/some_file.sql </code></pre> <p>I want to store the key-pair values to shell variable and loop it through. For example, the value for account/warehouse/database should go to variables which I can use later on. Also, the values for tables(table1 and table2) and sql_file_loc should go to shell variable which I can use for looping like below -</p> <pre><code>for i in $table ;do echo $i done </code></pre> <p>I have tried this code below -</p> <pre><code>function parse_yaml { local prefix=$2 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') sed -ne &quot;s|^\($s\):|\1|&quot; \ -e &quot;s|^\($s\)\($w\)$s:$s[\&quot;']\(.*\)[\&quot;']$s\$|\1$fs\2$fs\3|p&quot; \ -e &quot;s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p&quot; $1 | awk -F$fs '{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i &gt; indent) {delete vname[i]}} if (length($3) &gt; 0) { vn=&quot;&quot;; for (i=0; i&lt;indent; i++) {vn=(vn)(vname[i])(&quot;_&quot;)} printf(&quot;%s%s%s=\&quot;%s\&quot;\n&quot;, &quot;'$prefix'&quot;,vn, $2, $3); } }' } </code></pre> <p>And this is the output I get -</p> <pre><code>configuration_account=&quot;account_name&quot; configuration_warehouse=&quot;warehouse_name&quot; configuration_database=&quot;database_name&quot; configuration_object_type_schema=&quot;schema1&quot; configuration_object_type_functions=&quot;funtion1&quot; configuration_object_type_tables__sql_file_loc=&quot;some_path/some_file.sql&quot; configuration_object_type_tables__sql_file_loc=&quot;some_path/some_file.sql&quot; </code></pre> <p>It doesn't print - configuration_object_type_tables__table=&quot;table1&quot; and configuration_object_type_tables__table=&quot;table2&quot;</p> <p>Also for a list, it prints two underscores(__) unlike other objects. And I want to loop the values stored in configuration_object_type_tables__table and configuration_object_type_tables__sql_file_loc.</p> <p>Any help would be appreciated!</p>
[ { "answer_id": 74327405, "author": "jpseng", "author_id": 16332641, "author_profile": "https://Stackoverflow.com/users/16332641", "pm_score": 3, "selected": true, "text": "yq e '.. | select(type == \"!!str\") | (path | join(\"_\")) + \"=\\\"\" + . + \"\\\"\"' \"$INPUT\"\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18140360/" ]
74,326,562
<p>I have an implicit function, say <code>x**2 - y = 0</code> (to simplify), of which I want to obtain a plot for a certain range of <code>x</code> values.</p> <p><code>sympy.plot_implicit</code> usually gives some spreading of the lines that I am not happy with.</p> <p>I would like to have access to the plotted values, and so <code>pyplot.plot</code> is preferable to me. Usually I use the following piece of code to get my explicit Sympy functions plotted, but I am unsure how to use something similar for <code>exp = sym.Eq(x**2 - y, 0)</code>. Does anyone have a solutions for this?</p> <pre><code>import sympy as sym import numpy as np from matplotlib import pyplot as plt x, y = sym.symbols('x y', nonnegative=True) exp = x**2 # Plot using a numpy-ready function x_arr = np.linspace(-2, 2, 100) exp_func = sym.lambdify(x, exp, 'numpy') exp_arr = exp_func(x_arr) plt.plot(x_arr, exp_arr) </code></pre> <p>PS: my real expression is <code>b_sim</code> (see below) and I want the plot for the equation <strong>b_sim = -1</strong>. With <code>sym.plot_implicit(b_sim + 1, (n,0.225,1.5), (h, -1.1, 1.1))</code> one can see the lines spreading I dislike. Following Oscar Benjami's tips <a href="https://stackoverflow.com/questions/68279077/i-have-plotted-an-implicit-function-using-sympy-however-the-plot-doesnt-seem">here</a>, I attempted the following piece of code that is giving an error for <code>roots</code>.</p> <pre><code>from sympy import * h, nu = symbols('h nu', nonnegative=True) b_sim = 1.0*cos(pi*sqrt(1 - h)/(2*nu))*cos(pi*sqrt(h + 1)/(2*nu)) - 1.0*sin(pi*sqrt(1 - h)/(2*nu))*sin(pi*sqrt(h + 1)/(2*nu))/sqrt(1 - h**2) eq = Eq(b_sim + 1, 0) sols = roots(eq, h) sym.plot(*sols, (nu, 0.225, 1.5), ylim=(-1.1, 1.1)) </code></pre>
[ { "answer_id": 74326986, "author": "Davide_sd", "author_id": 2329968, "author_profile": "https://Stackoverflow.com/users/2329968", "pm_score": 3, "selected": true, "text": "plot_implicit" }, { "answer_id": 74327243, "author": "swatchai", "author_id": 2177413, "author_profile": "https://Stackoverflow.com/users/2177413", "pm_score": -1, "selected": false, "text": "lines2d" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9202251/" ]
74,326,566
<p>I cannot access Jupyterlab by web interface (error 524). It still works by ssh. I've followed the support documentations, but nothing works.</p> <p>My best guess is that the main issue is with the opened ports of docker.<br /> The key problem is probably below:</p> <pre><code>curl http://127.0.0.1:8080/api/kernelspecs curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused </code></pre> <p>And the following command simply restarts the service without error (but still inaccessible through web interface)</p> <pre><code>sudo service jupyter restart </code></pre> <p>Thanks!</p> <p>EDIT: to clarify, all help from <a href="https://cloud.google.com/vertex-ai/docs/general/troubleshooting-workbench#opening_a_notebook_results_in_a_524_a_timeout_occurred_error_2" rel="nofollow noreferrer">this article</a> which specifically is supposed to fix error 524, doesn't work at all.<br /> The diagnostic tool give this result, and the <code>--repair</code> doesn't work:</p> <p><a href="https://i.stack.imgur.com/9PWnO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9PWnO.png" alt="diagnostic tool" /></a></p> <p>And <a href="https://cloud.google.com/vertex-ai/docs/general/troubleshooting-workbench#verify_that_the_jupyter_internal_api_is_active" rel="nofollow noreferrer">&quot;Verify that the Jupyter internal API is active&quot;</a> is completely useless as it doesn't explain how to fix the error!!</p> <p>So I know there is a problem with the <strong>Jupyter internal API</strong> but no idea how to fix that.</p> <p>EDIT 2: On the web console, here is a screenshot: <a href="https://i.stack.imgur.com/MHLqm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MHLqm.png" alt="console gcp" /></a></p>
[ { "answer_id": 74491116, "author": "kiran mathew", "author_id": 17258510, "author_profile": "https://Stackoverflow.com/users/17258510", "pm_score": 0, "selected": false, "text": "Step 1:" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9093935/" ]
74,326,579
<p>I use SQL Server, and I created view and added new column which contain mathematical equation</p> <p>Let's say I have this:</p> <pre><code>create view as select a.date, a.sale, a.buy, profit = a.sale - a.buy, profit_prs = (a.sale - a.buy) / a.sale from tableA a </code></pre> <p>In line 5 how can I use <code>[profit]</code> column in <code>[profit_prs]</code> expression to be like this:</p> <pre><code>profit_prs = profit / a.sale </code></pre>
[ { "answer_id": 74326666, "author": "Dai", "author_id": 159145, "author_profile": "https://Stackoverflow.com/users/159145", "pm_score": 1, "selected": false, "text": "(a.sale - a.buy) / a.sale" }, { "answer_id": 74327466, "author": "GMB", "author_id": 10676716, "author_profile": "https://Stackoverflow.com/users/10676716", "pm_score": 0, "selected": false, "text": "cross apply" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20256446/" ]
74,326,610
<p>I don't know how to use iterator with erase.</p> <p>I wanna use iterator to erase some elements. But my code has some problem.</p> <p>I guess value 'end' and code 'v.erase(it++)' doesn't work. I don't know why. Is it right?</p> <p>Please fix my code.</p> <pre><code> vector&lt;int&gt; v = { 1,2,5,3,4 }; auto it = v.begin(); auto end = v.end(); int erase_number = 5; while (it != end) { if (*it == erase_number) { v.erase(it++); } else { ++it; } } </code></pre>
[ { "answer_id": 74326671, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 1, "selected": false, "text": "while (it != end)\n{\n if (*it == erase_number)\n {\n \n v.erase(it++);\n }\n else\n {\n ++it;\n }\n}\n" }, { "answer_id": 74326677, "author": "Ayxan Haqverdili", "author_id": 10147399, "author_profile": "https://Stackoverflow.com/users/10147399", "pm_score": 0, "selected": false, "text": "vec.erase(std::remove(vec.begin(), vec.end(), erase_number), vec.end());\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326610", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11548242/" ]
74,326,645
<p>I 'm trying to find a workable solution for my problem. I have found two similar questions answered before, but still I can't solve it. If we have a class like this:</p> <pre><code> from django.db import models class Consumer(models.Model): SIZES = ( ('S', 'Small'), ('M', 'Medium'), ('L', 'Large'), ) name = models.CharField(max_length=60) size = models.CharField(max_length=2, choices=SIZES) </code></pre> <p>And I did in my view and template like this (Learned from one tutorial)</p> <pre><code> ***view with combined queries*** def staff_filter(request): qs = Consumer.objects.all() size= request.GET.get('size') # I have some other queries in between .... if is_valid_queryparam(size) and size!='Choose...': qs = qs.filter(size=consumer.get_size.display()) return qs def filter(request): qs=staff_filter(request) context={ 'queryset':qs, 'consumer':consumer.objects.all() } return render(request, 'filter.html',context) </code></pre> <pre><code> **template*** &lt;div class=&quot;form-group col-md-4&quot;&gt; &lt;label for=&quot;size&quot;&gt;size&lt;/label&gt; &lt;select id=&quot;size&quot; class=&quot;form-control&quot; name=&quot;size&quot;&gt; &lt;option selected&gt;Choose...&lt;/option&gt; {% for size in consumer.get_size.display %} &lt;option value=&quot;{{ size }}&quot;&gt;{{size}}&lt;/option&gt; {% endfor %} &lt;/select&gt; &lt;/div&gt; </code></pre> <p>How should I correct it? Thanks!</p> <p>Display selection field in Django template</p>
[ { "answer_id": 74326671, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 1, "selected": false, "text": "while (it != end)\n{\n if (*it == erase_number)\n {\n \n v.erase(it++);\n }\n else\n {\n ++it;\n }\n}\n" }, { "answer_id": 74326677, "author": "Ayxan Haqverdili", "author_id": 10147399, "author_profile": "https://Stackoverflow.com/users/10147399", "pm_score": 0, "selected": false, "text": "vec.erase(std::remove(vec.begin(), vec.end(), erase_number), vec.end());\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20310294/" ]
74,326,652
<pre><code>func move(motion): if motion != Vector2(): target_angle = atan2(motion.x, motion.y) - PI/2 Skin.set_rot(target_angle) </code></pre> <p>I tried converting vectors to ints. I looked up this error and didnt understand fixes.</p>
[ { "answer_id": 74326671, "author": "Vlad from Moscow", "author_id": 2877241, "author_profile": "https://Stackoverflow.com/users/2877241", "pm_score": 1, "selected": false, "text": "while (it != end)\n{\n if (*it == erase_number)\n {\n \n v.erase(it++);\n }\n else\n {\n ++it;\n }\n}\n" }, { "answer_id": 74326677, "author": "Ayxan Haqverdili", "author_id": 10147399, "author_profile": "https://Stackoverflow.com/users/10147399", "pm_score": 0, "selected": false, "text": "vec.erase(std::remove(vec.begin(), vec.end(), erase_number), vec.end());\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20346379/" ]
74,326,672
<p>I have to validate strings with specific conditions using a regex statement. The condition is that every digit is different from each other. So, 123 works but not 112 or 131.</p> <p>So, I wrote a statement which filters a string according to the condition and prints true once a string fullfies everything, however it only seems to print &quot;true&quot; altough some strings do not meet the condition.</p> <pre><code>public class MyClass { public static void main(String args[]) { String[] value = {&quot;123&quot;,&quot;951&quot;,&quot;121&quot;,&quot;355&quot;,&quot;110&quot;}; for (String s : value){ System.out.println(&quot;\&quot;&quot; + s + &quot;\&quot;&quot; + &quot; -&gt; &quot; + validate(s)); } } public static boolean validate(String s){ return s.matches(&quot;([0-9])(?!\1)[0-9](?!\1)[0-9]&quot;); } } </code></pre>
[ { "answer_id": 74326700, "author": "Vinz", "author_id": 17173476, "author_profile": "https://Stackoverflow.com/users/17173476", "pm_score": 1, "selected": false, "text": "public static boolean validate(String s) {\n return s.chars().distinct().count() == s.length();\n}\n" }, { "answer_id": 74326745, "author": "YCF_L", "author_id": 5558072, "author_profile": "https://Stackoverflow.com/users/5558072", "pm_score": 3, "selected": true, "text": "public static boolean validate(String s) {\n return s.matches(\"(?!.*(.).*\\\\1)[0-9]+\");\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20186546/" ]
74,326,678
<p>I used to use Pyzo for Python coding and decided to give VS Code a try because it is more feature-rich. I came across one huge annoyance, however. In Pyzo, I am used to code „interactively“ as Pyzo executes code in an interactive shell (<a href="https://pyzo.org/features.html" rel="nofollow noreferrer">https://pyzo.org/features.html</a>).</p> <p>I would like to replicate that in VS Code, but so far had no luck. With the Microsoft Python extension installed, the closest I can come is to select the whole code, right click and then click on „Run Selection/Line in Python Terminal“. For long scripts, however, this is very, very slow as it first prints each line to the terminal and then executes it line by line. Pyzo seems to operate silently.</p> <p>Do you have a solution? I think, VS Code would be much faster if it did not print each line to the terminal first.</p> <p>Best</p>
[ { "answer_id": 74326700, "author": "Vinz", "author_id": 17173476, "author_profile": "https://Stackoverflow.com/users/17173476", "pm_score": 1, "selected": false, "text": "public static boolean validate(String s) {\n return s.chars().distinct().count() == s.length();\n}\n" }, { "answer_id": 74326745, "author": "YCF_L", "author_id": 5558072, "author_profile": "https://Stackoverflow.com/users/5558072", "pm_score": 3, "selected": true, "text": "public static boolean validate(String s) {\n return s.matches(\"(?!.*(.).*\\\\1)[0-9]+\");\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326678", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13905032/" ]
74,326,685
<p>I have this code:</p> <pre class="lang-rust prettyprint-override"><code>pub trait BytesToBits&lt;T&gt;: Iterator&lt;Item = u8&gt; where T: Iterator&lt;Item = bool&gt;, { fn bits(&amp;mut self) -&gt; T; } impl&lt;T&gt; BytesToBits&lt;T&gt; for dyn Iterator&lt;Item = u8&gt; where T: Iterator&lt;Item = bool&gt;, { fn bits(&amp;mut self) -&gt; T { self.flat_map(|byte| (0..8).map(move |offset| byte &amp; (1 &lt;&lt; offset) != 0)) } } </code></pre> <p>However, compiling it results in:</p> <pre><code>error[E0308]: mismatched types --&gt; src/bitstream.rs:13:9 | 8 | impl&lt;T&gt; BytesToBits&lt;T&gt; for dyn Iterator&lt;Item = u8&gt; | - this type parameter ... 12 | fn bits(&amp;mut self) -&gt; T { | - expected `T` because of return type 13 | self.flat_map(|byte| (0..8).map(move |offset| byte &amp; (1 &lt;&lt; offset) != 0)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found struct `FlatMap` | = note: expected type parameter `T` found struct `FlatMap&lt;&amp;mut (dyn Iterator&lt;Item = u8&gt; + 'static), Map&lt;std::ops::Range&lt;{integer}&gt;, [closure@src/bitstream.rs:13:41: 13:54]&gt;, [closure@src/bitstream.rs:13:23: 13:29]&gt;` </code></pre> <p>I am new to Rust and do not know what I exactly did wrong there and how to resolve the issue.</p> <p>My goal is to have a trait <code>BytesToBits</code> that extends all <code>Iterator&lt;Item = u8&gt;</code> by providing them with a method <code>bits()</code> that returns an <code>Iterator&lt;Item = bool&gt;</code>.</p>
[ { "answer_id": 74327004, "author": "complikator", "author_id": 17348751, "author_profile": "https://Stackoverflow.com/users/17348751", "pm_score": 1, "selected": false, "text": "pub trait BytesToBits<T>: Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_>;\n}\n\nimpl<T> BytesToBits<T> for dyn Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_> {\n Box::new(self.flat_map(|byte| (0..8).map(move |offset| byte & (1 << offset) != 0)))\n }\n}\n" }, { "answer_id": 74327155, "author": "Richard Neumann", "author_id": 3515670, "author_profile": "https://Stackoverflow.com/users/3515670", "pm_score": 1, "selected": true, "text": "pub trait BytesToBits<T>\nwhere\n T: Iterator<Item = bool>,\n{\n fn bits(self) -> T;\n}\n\nimpl<T> BytesToBits<BytesToBitsIterator<T>> for T\nwhere\n T: Iterator<Item = u8>,\n{\n fn bits(self) -> BytesToBitsIterator<T> {\n BytesToBitsIterator::from(self)\n }\n}\n\npub struct BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n bytes: T,\n current: Option<u8>,\n index: u8,\n}\n\nimpl<T> From<T> for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n fn from(bytes: T) -> Self {\n Self {\n bytes,\n current: None,\n index: 0,\n }\n }\n}\n\nimpl<T> Iterator for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n type Item = bool;\n\n fn next(&mut self) -> Option<Self::Item> {\n if self.index > 7 {\n self.current = None;\n self.index = 0;\n }\n\n let current = match self.current {\n None => match self.bytes.next() {\n None => {\n return None;\n }\n Some(byte) => {\n self.current = Some(byte);\n byte\n }\n },\n Some(byte) => byte,\n };\n\n let bit = current & (1 << self.index) != 0;\n self.index += 1;\n Some(bit)\n }\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3515670/" ]
74,326,705
<p>I recently found out about fira code and I was wondering how do I get it in neovim?</p> <p>I didnt find any tutorial</p>
[ { "answer_id": 74327004, "author": "complikator", "author_id": 17348751, "author_profile": "https://Stackoverflow.com/users/17348751", "pm_score": 1, "selected": false, "text": "pub trait BytesToBits<T>: Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_>;\n}\n\nimpl<T> BytesToBits<T> for dyn Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_> {\n Box::new(self.flat_map(|byte| (0..8).map(move |offset| byte & (1 << offset) != 0)))\n }\n}\n" }, { "answer_id": 74327155, "author": "Richard Neumann", "author_id": 3515670, "author_profile": "https://Stackoverflow.com/users/3515670", "pm_score": 1, "selected": true, "text": "pub trait BytesToBits<T>\nwhere\n T: Iterator<Item = bool>,\n{\n fn bits(self) -> T;\n}\n\nimpl<T> BytesToBits<BytesToBitsIterator<T>> for T\nwhere\n T: Iterator<Item = u8>,\n{\n fn bits(self) -> BytesToBitsIterator<T> {\n BytesToBitsIterator::from(self)\n }\n}\n\npub struct BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n bytes: T,\n current: Option<u8>,\n index: u8,\n}\n\nimpl<T> From<T> for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n fn from(bytes: T) -> Self {\n Self {\n bytes,\n current: None,\n index: 0,\n }\n }\n}\n\nimpl<T> Iterator for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n type Item = bool;\n\n fn next(&mut self) -> Option<Self::Item> {\n if self.index > 7 {\n self.current = None;\n self.index = 0;\n }\n\n let current = match self.current {\n None => match self.bytes.next() {\n None => {\n return None;\n }\n Some(byte) => {\n self.current = Some(byte);\n byte\n }\n },\n Some(byte) => byte,\n };\n\n let bit = current & (1 << self.index) != 0;\n self.index += 1;\n Some(bit)\n }\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19357762/" ]
74,326,732
<p>My goal is to sort and array depending on its defined position. It has to compare an id and if it exists, then return it in a new array with its component. So far I am very stuck with this algorithm</p> <pre><code> const forms: FormsToLocale = { [&quot;ja&quot;]: [ { componentId: &quot;email&quot;, position: 1 }, { componentId: &quot;title&quot;, position: 2 }, { componentId: &quot;japanName&quot;, position: 3 }, { componentId: &quot;phoneNumber&quot;, position: 4 }, ], [&quot;en-HK&quot; || &quot;en-MO&quot;]: [ { componentId: &quot;email&quot;, position: 1 }, { componentId: &quot;verificationCode&quot;, position: 2 }, { componentId: &quot;title&quot;, position: 3 }, { componentId: &quot;firstName&quot;, position: 4 }, { componentId: &quot;lastName&quot;, position: 5 }, ], default: [ { componentId: &quot;email&quot;, position: 1 }, { componentId: &quot;title&quot;, position: 2 }, { componentId: &quot;firstName&quot;, position: 3 }, { componentId: &quot;lastName&quot;, position: 4 }, { componentId: &quot;phoneNumber&quot;, position: 5 }, ], }; const componentsFormMapping: ComponentFormMapping[] = [ { componentId: &quot;email&quot;, component: &quot;EmailLightAccountComponent&quot; }, { componentId: &quot;title&quot;, component: &quot;TitleLightAccountComponent&quot; }, { componentId: &quot;firstName&quot;, component: &quot;FirstnameLightAccountComponent&quot; }, { componentId: &quot;lastName&quot;, component: &quot;LastnameLightAccountComponent&quot; }, { componentId: &quot;japanName&quot;, component: &quot;JapanNameLightAccountComponent&quot; }, { componentId: &quot;phoneNumber&quot;, component: &quot;PhoneLightAccountComponent&quot; }, { componentId: &quot;verificationCode&quot;, component: &quot;SendCodeComponent&quot; }, ]; const createForm = () =&gt; { const japanForm = forms[&quot;ja&quot;]; japanForm.map((componentF) =&gt; { console.log(componentsFormMapping.find((component) =&gt; componentF.componentId === component.componentId)!.component); }) } createForm(); </code></pre> <p>expected output: [&quot;EmailLightAccountComponent&quot;, &quot;TitleLightAccountComponent&quot;, &quot;JapanNameLightAccountComponent&quot;, &quot;PhoneLightAccountComponent&quot;]</p> <p>Thanks for your help</p>
[ { "answer_id": 74327004, "author": "complikator", "author_id": 17348751, "author_profile": "https://Stackoverflow.com/users/17348751", "pm_score": 1, "selected": false, "text": "pub trait BytesToBits<T>: Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_>;\n}\n\nimpl<T> BytesToBits<T> for dyn Iterator<Item=u8>\n where\n T: Iterator<Item=bool>,\n{\n fn bits(&mut self) -> Box<dyn Iterator<Item=bool> + '_> {\n Box::new(self.flat_map(|byte| (0..8).map(move |offset| byte & (1 << offset) != 0)))\n }\n}\n" }, { "answer_id": 74327155, "author": "Richard Neumann", "author_id": 3515670, "author_profile": "https://Stackoverflow.com/users/3515670", "pm_score": 1, "selected": true, "text": "pub trait BytesToBits<T>\nwhere\n T: Iterator<Item = bool>,\n{\n fn bits(self) -> T;\n}\n\nimpl<T> BytesToBits<BytesToBitsIterator<T>> for T\nwhere\n T: Iterator<Item = u8>,\n{\n fn bits(self) -> BytesToBitsIterator<T> {\n BytesToBitsIterator::from(self)\n }\n}\n\npub struct BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n bytes: T,\n current: Option<u8>,\n index: u8,\n}\n\nimpl<T> From<T> for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n fn from(bytes: T) -> Self {\n Self {\n bytes,\n current: None,\n index: 0,\n }\n }\n}\n\nimpl<T> Iterator for BytesToBitsIterator<T>\nwhere\n T: Iterator<Item = u8>,\n{\n type Item = bool;\n\n fn next(&mut self) -> Option<Self::Item> {\n if self.index > 7 {\n self.current = None;\n self.index = 0;\n }\n\n let current = match self.current {\n None => match self.bytes.next() {\n None => {\n return None;\n }\n Some(byte) => {\n self.current = Some(byte);\n byte\n }\n },\n Some(byte) => byte,\n };\n\n let bit = current & (1 << self.index) != 0;\n self.index += 1;\n Some(bit)\n }\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8276708/" ]
74,326,766
<p>I can't activate virtual enviroment and get 'cannot be loaded because running scripts is disabled on this system'</p> <p><a href="https://i.stack.imgur.com/c9a8N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c9a8N.png" alt="enter image description here" /></a></p> <p>I tried to write 'activate' and './activate' but both dont work</p>
[ { "answer_id": 74326801, "author": "Nabin Bhusal", "author_id": 5840204, "author_profile": "https://Stackoverflow.com/users/5840204", "pm_score": 0, "selected": false, "text": "venv bin/activate\n" }, { "answer_id": 74326871, "author": "Manoj Tolagekar", "author_id": 17808039, "author_profile": "https://Stackoverflow.com/users/17808039", "pm_score": 3, "selected": true, "text": "set-executionpolicy remotesigned\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20424560/" ]
74,326,839
<p>My react native app was running correctly, but suddenly I started getting error:</p> <p>error 1: <code>Execution failed for task ':react-native-webview:compileDebugKotlin'.</code></p> <p>so for this in android/build.gradle I added <code>kotlinVersion = &quot;1.5.31&quot;</code> and also dependencies added <code>classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31&quot;</code>.</p> <p>After this I got the following error:</p> <pre><code>* What went wrong: Execution failed for task ':app:mergeDebugNativeLibs'. &gt; A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade &gt; More than one file was found with OS independent path 'lib/arm64-v8a/libfbjni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake </code></pre> <p>for this, inside android/app/build.gradle under android{...} I added:</p> <pre><code>packagingOptions { pickFirst 'lib/x86/libc++_shared.so' pickFirst 'lib/x86_64/libjsc.so' pickFirst 'lib/arm64-v8a/libjsc.so' pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libfbjni.so' } </code></pre> <p>but even after this I am getting the same error again: <code>More than one file was found with OS independent path 'lib/arm64-v8a/libfbjni.so'</code></p>
[ { "answer_id": 74339638, "author": "Anass", "author_id": 9464846, "author_profile": "https://Stackoverflow.com/users/9464846", "pm_score": 0, "selected": false, "text": "app/build.gradle" }, { "answer_id": 74342256, "author": "Shivam", "author_id": 8709100, "author_profile": "https://Stackoverflow.com/users/8709100", "pm_score": 3, "selected": false, "text": "app/build.gradle" }, { "answer_id": 74342523, "author": "Ali Hasan", "author_id": 10638877, "author_profile": "https://Stackoverflow.com/users/10638877", "pm_score": 3, "selected": false, "text": "allprojects {\nrepositories {\n ...\n exclusiveContent {\n // We get React Native's Android binaries exclusively through npm,\n // from a local Maven repo inside node_modules/react-native/.\n // (The use of exclusiveContent prevents looking elsewhere like Maven Central\n // and potentially getting a wrong version.)\n filter {\n includeGroup \"com.facebook.react\"\n }\n forRepository {\n maven {\n url \"$rootDir/../node_modules/react-native/android\"\n }\n }\n }\n}\n" }, { "answer_id": 74345303, "author": "Rvind Jitta", "author_id": 13019576, "author_profile": "https://Stackoverflow.com/users/13019576", "pm_score": 0, "selected": false, "text": "android {\n\npackagingOptions {\n pickFirst 'lib/x86/libc++_shared.so'\n pickFirst 'lib/x86_64/libc++_shared.so'\n pickFirst 'lib/armeabi-v7a/libc++_shared.so'\n pickFirst 'lib/arm64-v8a/libc++_shared.so'\n pickFirst 'lib/x86/libfbjni.so'\n pickFirst 'lib/x86_64/libfbjni.so'\n pickFirst 'lib/armeabi-v7a/libfbjni.so'\n pickFirst 'lib/arm64-v8a/libfbjni.so' \n}\n//other code\n\n}\n" }, { "answer_id": 74346629, "author": "Sally Azulay", "author_id": 13765513, "author_profile": "https://Stackoverflow.com/users/13765513", "pm_score": 1, "selected": false, "text": " exclusiveContent {\n filter {\n includeGroup \"com.facebook.react\"\n }\n forRepository {\n maven {\n url \"$rootDir/../node_modules/react-native/android\"\n }\n }\n }" }, { "answer_id": 74354996, "author": "Manoj Alwis", "author_id": 6536166, "author_profile": "https://Stackoverflow.com/users/6536166", "pm_score": 0, "selected": false, "text": "def REACT_NATIVE_VERSION = new File(['node', '--print',\"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version\"].execute(null, rootDir).text.trim())\n\nallprojects {\n configurations.all {\n resolutionStrategy {\n // Remove this override in 0.65+, as a proper fix is included in react-native itself.\n force \"com.facebook.react:react-native:\" + REACT_NATIVE_VERSION\n }\n }\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7493971/" ]
74,326,851
<p>I want to check if one list contains all the elements of another list, for example:</p> <blockquote> <p>(a,b,c,d) contains (c, a, d) = true<br /> (a, b, c, d) contains (b, b, c, d) = false</p> </blockquote> <p>I tried things like this:</p> <pre><code>static bool ContainsOther&lt;T&gt;(IEnumerable&lt;T&gt; a, IEnumerable&lt;T&gt; b) { return new HashSet&lt;T&gt;(a).IsSupersetOf(new HashSet&lt;T&gt;(b)); } </code></pre> <p>But then it won't solve this correctly:<br /> <code>(a, b, c, d) contains (b, b, c, d) = false</code>, it would say <code>true</code>, but I would want to receive <code>false</code>.</p> <p>Same goes with nested loops.</p>
[ { "answer_id": 74326908, "author": "Guru Stron", "author_id": 2501279, "author_profile": "https://Stackoverflow.com/users/2501279", "pm_score": 2, "selected": false, "text": "HashSet" }, { "answer_id": 74326914, "author": "Dmitry Bychenko", "author_id": 2319407, "author_profile": "https://Stackoverflow.com/users/2319407", "pm_score": 1, "selected": false, "text": "HashSet<T>" }, { "answer_id": 74326965, "author": "Enigmativity", "author_id": 259769, "author_profile": "https://Stackoverflow.com/users/259769", "pm_score": 1, "selected": false, "text": "static bool ContainsOther<T>(IEnumerable<T> a, IEnumerable<T> b) =>\n(\n from x in a.ToLookup(_ => _)\n join y in b.ToLookup(_ => _) on x.Key equals y.Key\n from z in x.Zip(y)\n select z\n).Count() == b.Count();\n" }, { "answer_id": 74328428, "author": "vivek nuna", "author_id": 6527049, "author_profile": "https://Stackoverflow.com/users/6527049", "pm_score": 0, "selected": false, "text": "List<string> ls1 = new List<string>() { \"a\", \"b\", \"c\" , \"d\"};\nList<string> ls2 = new List<string>() { \"c\", \"a\", \"y\" };\n\nbool isSuperset1 = ls1.Intersect(ls2).Count() == ls2.Count;\nbool isSuperset2 = !ls2.Except(ls1).Any();\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20424619/" ]
74,326,880
<p>I want that every time a form is submitted, a new equipment with the equipment number as KEY is created in the local storage.</p> <p>E.g.</p> <blockquote> <p>LocalStorage:</p> </blockquote> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Key:</th> <th>Value:</th> </tr> </thead> <tbody> <tr> <td>E123456789</td> <td>ordernumber: 456, date: 05.11.2022</td> </tr> <tr> <td>E987654321</td> <td>ordernumber :654, date: 05.11.2022</td> </tr> </tbody> </table> </div> <p>This is my code:</p> <pre class="lang-js prettyprint-override"><code>class Equipment { constructor( equipmentnumber, ordernumber, date ) { this.equipmentnumber = equipmentnumber; this.ordernumber = ordernumber; this.date = date; } } function addProcess() { let equipment = new Equipment( equipmentnumber.value, ordernumber.value, date.value ); localStorage.setItem('equipment', JSON.stringify(equipment)); } </code></pre> <p>And this is what I get:</p> <blockquote> <p>LocalStorage:</p> </blockquote> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Key:</th> <th>Value:</th> </tr> </thead> <tbody> <tr> <td>Equipment</td> <td>equipmentnumber: 123, ordernumber: 456, date: 05.11.2022</td> </tr> </tbody> </table> </div>
[ { "answer_id": 74327051, "author": "vmank", "author_id": 6869922, "author_profile": "https://Stackoverflow.com/users/6869922", "pm_score": 1, "selected": false, "text": "setItem" }, { "answer_id": 74340690, "author": "Peter Seliger", "author_id": 2627243, "author_profile": "https://Stackoverflow.com/users/2627243", "pm_score": 0, "selected": false, "text": "class" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19126153/" ]
74,326,899
<p>I was making a scraper for my school website, which automatically gets the homework for today.</p> <pre><code>[ { &quot;id&quot;: &quot;1523958&quot;, &quot;studentId&quot;: &quot;8326&quot;, &quot;assignmentId&quot;: &quot;35074&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;35074&quot;, &quot;subject&quot;: &quot;URDU&quot;, &quot;title&quot;: &quot;اچھے آداب و اطوار&quot;, &quot;description&quot;: &quot;9F Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;1&quot;, &quot;date&quot;: &quot;Fri, 04/11/2022&quot;, }, { &quot;id&quot;: &quot;1520938&quot;, &quot;studentId&quot;: &quot;8426&quot;, &quot;assignmentId&quot;: &quot;35013&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;35013&quot;, &quot;subject&quot;: &quot;SOCIAL STUDIES&quot;, &quot;title&quot;: &quot;The Globe and Maps &quot;, &quot;description&quot;: &quot;5C Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;0&quot;, &quot;date&quot;: &quot;Fri, 04/11/2022&quot;, &quot;download&quot;: &quot;2bf0c7b51af0cfb1023261dd7b8b4f8f.jpg&quot;, }, { &quot;id&quot;: &quot;1520624&quot;, &quot;studentId&quot;: &quot;8426&quot;, &quot;assignmentId&quot;: &quot;35007&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;35007&quot;, &quot;subject&quot;: &quot;MATHEMATICS&quot;, &quot;title&quot;: &quot;Percentage &quot;, &quot;description&quot;: &quot;5C Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;0&quot;, &quot;date&quot;: &quot;Fri, 04/11/2022&quot;, }, { &quot;id&quot;: &quot;1520530&quot;, &quot;studentId&quot;: &quot;8426&quot;, &quot;assignmentId&quot;: &quot;35005&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;35005&quot;, &quot;subject&quot;: &quot;ENGLISH A&quot;, &quot;title&quot;: &quot;Paragraph writing &quot;, &quot;description&quot;: &quot;5C Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;0&quot;, &quot;date&quot;: &quot;Fri, 04/11/2022&quot;, }, { &quot;id&quot;: &quot;1517928&quot;, &quot;studentId&quot;: &quot;8326&quot;, &quot;assignmentId&quot;: &quot;34952&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;34952&quot;, &quot;subject&quot;: &quot;PHYSICS&quot;, &quot;title&quot;: &quot;Homework&quot;, &quot;description&quot;: &quot;9F Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;1&quot;, &quot;date&quot;: &quot;Fri, 04/11/2022&quot;, }, { &quot;id&quot;: &quot;1513747&quot;, &quot;studentId&quot;: &quot;8426&quot;, &quot;assignmentId&quot;: &quot;34887&quot;, &quot;diaryType&quot;: &quot;gn&quot;, &quot;diaryId&quot;: &quot;34887&quot;, &quot;subject&quot;: None, &quot;title&quot;: &quot;General notice &quot;, &quot;description&quot;: &quot;5C Maymaar - Notice posted&quot;, &quot;bRead&quot;: &quot;0&quot;, &quot;date&quot;: &quot;Thu, 03/11/2022&quot;, }, { &quot;id&quot;: &quot;1508998&quot;, &quot;studentId&quot;: &quot;8426&quot;, &quot;assignmentId&quot;: &quot;34787&quot;, &quot;diaryType&quot;: &quot;cw&quot;, &quot;diaryId&quot;: &quot;34787&quot;, &quot;subject&quot;: &quot;SOCIAL STUDIES&quot;, &quot;title&quot;: &quot;Map reading skills &quot;, &quot;description&quot;: &quot;5C Maymaar - Classwork posted&quot;, &quot;bRead&quot;: &quot;0&quot;, &quot;date&quot;: &quot;Thu, 03/11/2022&quot;, }, ] </code></pre> <p>what you see above is a list, what i want to do is: if studentId = 8426 and if date = something: SEND AssignmentiId TO DISPLAY</p> <p>i tried to do it my self but tbh i dont know how to approach this problem, how do i read every dictionary, check every key and it's value and then print out another key in the same dictionary?</p> <pre><code>for key, value in diary: if key == &quot;date&quot;: if value == &quot;Fri, 04/11/2022&quot;: print(key, value) </code></pre>
[ { "answer_id": 74326950, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 2, "selected": true, "text": "lst" }, { "answer_id": 74326975, "author": "Nbody", "author_id": 13957283, "author_profile": "https://Stackoverflow.com/users/13957283", "pm_score": 0, "selected": false, "text": "diaries = [\n{\n \"id\": \"1523958\",\n \"studentId\": \"8326\",\n \"assignmentId\": \"35074\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35074\",\n \"subject\": \"URDU\",\n \"title\": \"اچھے آداب و اطوار\",\n \"description\": \"9F Maymaar - Classwork posted\",\n \"bRead\": \"1\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1520938\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35013\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35013\",\n \"subject\": \"SOCIAL STUDIES\",\n \"title\": \"The Globe and Maps \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n \"download\": \"2bf0c7b51af0cfb1023261dd7b8b4f8f.jpg\",\n},\n{\n \"id\": \"1520624\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35007\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35007\",\n \"subject\": \"MATHEMATICS\",\n \"title\": \"Percentage \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1520530\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35005\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35005\",\n \"subject\": \"ENGLISH A\",\n \"title\": \"Paragraph writing \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1517928\",\n \"studentId\": \"8326\",\n \"assignmentId\": \"34952\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"34952\",\n \"subject\": \"PHYSICS\",\n \"title\": \"Homework\",\n \"description\": \"9F Maymaar - Classwork posted\",\n \"bRead\": \"1\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1513747\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"34887\",\n \"diaryType\": \"gn\",\n \"diaryId\": \"34887\",\n \"subject\": None,\n \"title\": \"General notice \",\n \"description\": \"5C Maymaar - Notice posted\",\n \"bRead\": \"0\",\n \"date\": \"Thu, 03/11/2022\",\n},\n{\n \"id\": \"1508998\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"34787\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"34787\",\n \"subject\": \"SOCIAL STUDIES\",\n \"title\": \"Map reading skills \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Thu, 03/11/2022\",\n},\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18967622/" ]
74,326,955
<p>I have one API in my webservice App that receives an empty model after the post.</p> <p>This is the code in my testclient that calls the API</p> <pre><code>private async void AddDriverPayment() { ModelPalmDriverPaymentRequest modelPalmDriverPaymentRequest = new ModelPalmDriverPaymentRequest() { SCS_ID = int.Parse(gttDXTextEditAddDriverPaymentSCS_ID.Text), DriverID = int.Parse(gttDXTextEditAddDriverPaymentDriverID.Text), Amount = decimal.Parse(gttDXTextEditAddDriverPaymentAmount.Text), Remark = gttDXTextEditAddDriverPaymentRemark.Text, PaymentType = gttDXTextEditAddDriverPaymentPaymentType.Text, PaymentYear = int.Parse(gttDXTextEditAddDriverPaymentPaymentYear.Text), PaymentWeek = int.Parse(gttDXTextEditAddDriverPaymentPaymentWeek.Text), DocumentPath = gttDXTextEditAddDriverPaymentDocumentPath.Text, DatePayment = dateTimePickerAddDriverPayment.Value }; string JsonData = JsonConvert.SerializeObject(modelPalmDriverPaymentRequest); System.Net.Http.StringContent restContent = new StringContent(JsonData, Encoding.UTF8, &quot;application/json&quot;); HttpClient client = new HttpClient(); try { var response = await client.PostAsync(comboBoxEditPalmAddDriverPayment.Text, restContent); if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStringAsync(); ModelPalmDriverPaymentResponse Result = JsonConvert.DeserializeObject&lt;ModelPalmDriverPaymentResponse&gt;(stream); textBoxAddDriverPaymentResult.Text = Result.SCS_ID.ToString() + &quot; &quot; + Result.PaymentID.ToString(); } else { textBoxAddDriverPaymentResult.Text = response.StatusCode + &quot; &quot; + response.ReasonPhrase; } } catch (Exception ex) { textBoxAddDriverPaymentResult.Text = ex.Message; } } </code></pre> <p>And this is the controller code in the webservice</p> <pre><code> [Route(&quot;palm/AddDriverPayment&quot;)] [ApiController] public class ControllerPalmDriverPayment : ControllerBase { private readonly RepositoryPalmDriverPayment _repositoryPalmDriverPayment = new(); [HttpPost] public IActionResult AddDriverPayment(ModelPalmDriverPaymentRequest modelPalmDriverPaymentRequest) { try { return base.Ok(_repositoryPalmDriverPayment.AddDriverPaymemnt(modelPalmDriverPaymentRequest)); } catch (System.Exception) { return base.BadRequest(&quot;Nope not working...&quot;); } } } </code></pre> <p>The model looks like this (I copied the model class from the service into the client, so I am sure they are exact the same)</p> <pre><code> public class ModelPalmDriverPaymentRequest { public int SCS_ID; public int DriverID; public decimal Amount; public string? Remark; public string? PaymentType; public int PaymentYear; public int PaymentWeek; public string? DocumentPath; public DateTime DatePayment; } </code></pre> <p>When I try the code, I can see in debug of the testclient that when I post the data, the model is correct filled,</p> <p><a href="https://i.stack.imgur.com/PnbDm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PnbDm.png" alt="enter image description here" /></a></p> <p>but then I can see in debug on the webservice that the received model is empty</p> <p><a href="https://i.stack.imgur.com/ckM51.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ckM51.png" alt="enter image description here" /></a></p> <p>I have other API's in this webservice that I test with the same client, they all do not have this problem.</p> <p>I found <a href="https://stackoverflow.com/questions/61552416/model-being-received-empty-in-the-controller-after-post">this question</a> but the answers don't help me</p> <p>Anybody has any idea what the problem here is ?</p> <p><strong>EDIT</strong></p> <p>I found the problem, and wrote it in an answer so anybody with the same problem can find it.</p>
[ { "answer_id": 74326950, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 2, "selected": true, "text": "lst" }, { "answer_id": 74326975, "author": "Nbody", "author_id": 13957283, "author_profile": "https://Stackoverflow.com/users/13957283", "pm_score": 0, "selected": false, "text": "diaries = [\n{\n \"id\": \"1523958\",\n \"studentId\": \"8326\",\n \"assignmentId\": \"35074\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35074\",\n \"subject\": \"URDU\",\n \"title\": \"اچھے آداب و اطوار\",\n \"description\": \"9F Maymaar - Classwork posted\",\n \"bRead\": \"1\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1520938\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35013\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35013\",\n \"subject\": \"SOCIAL STUDIES\",\n \"title\": \"The Globe and Maps \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n \"download\": \"2bf0c7b51af0cfb1023261dd7b8b4f8f.jpg\",\n},\n{\n \"id\": \"1520624\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35007\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35007\",\n \"subject\": \"MATHEMATICS\",\n \"title\": \"Percentage \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1520530\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"35005\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"35005\",\n \"subject\": \"ENGLISH A\",\n \"title\": \"Paragraph writing \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1517928\",\n \"studentId\": \"8326\",\n \"assignmentId\": \"34952\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"34952\",\n \"subject\": \"PHYSICS\",\n \"title\": \"Homework\",\n \"description\": \"9F Maymaar - Classwork posted\",\n \"bRead\": \"1\",\n \"date\": \"Fri, 04/11/2022\",\n},\n{\n \"id\": \"1513747\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"34887\",\n \"diaryType\": \"gn\",\n \"diaryId\": \"34887\",\n \"subject\": None,\n \"title\": \"General notice \",\n \"description\": \"5C Maymaar - Notice posted\",\n \"bRead\": \"0\",\n \"date\": \"Thu, 03/11/2022\",\n},\n{\n \"id\": \"1508998\",\n \"studentId\": \"8426\",\n \"assignmentId\": \"34787\",\n \"diaryType\": \"cw\",\n \"diaryId\": \"34787\",\n \"subject\": \"SOCIAL STUDIES\",\n \"title\": \"Map reading skills \",\n \"description\": \"5C Maymaar - Classwork posted\",\n \"bRead\": \"0\",\n \"date\": \"Thu, 03/11/2022\",\n},\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3611669/" ]
74,326,969
<p>how can I find <em>5th</em> or <em>7th</em>, or <em>15th</em> biggest element in multidimensional array without existing methods (like <code>list.Add</code>) I will be pleased if you write it in c#</p> <pre><code>int[,,,] x =new int[100, 20, 35, 200]; ... int indis = 0; int toplam = 0; int enss = 0; for (int i = 0; i &lt; 100; i++) { for (int j = 0; j &lt; 20; j++) { toplam = 0; for (int k = 0; k &lt; 35; k++) { for (int l = 0; l &lt; 200; l++) { toplam += x[i, j, k, l]; } } if (toplam &gt; enss) { enss = toplam; indis = j; } } } </code></pre>
[ { "answer_id": 74326990, "author": "Dmitry Bychenko", "author_id": 2319407, "author_profile": "https://Stackoverflow.com/users/2319407", "pm_score": 1, "selected": false, "text": "Add" }, { "answer_id": 74327076, "author": "jdweng", "author_id": 5015238, "author_profile": "https://Stackoverflow.com/users/5015238", "pm_score": 0, "selected": false, "text": " var table = Enumerable.Range(0, x.GetLength(0))\n .SelectMany((a, i) => Enumerable.Range(0, x.GetLength(1))\n .SelectMany((b, j) => Enumerable.Range(0, x.GetLength(2))\n .SelectMany((c, k) => Enumerable.Range(0, x.GetLength(3)\n .Select((d, l) => new { x = x[i, j, k, l], i = i, j = j, k = k, l = l }))))\n .OrderByDescending(x => x.x);\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16420414/" ]
74,326,978
<p>I am trying to get the bot to send an emoji when someone else sends one. I have managed to get this to work, but when I use @commands.check to make sure the bot is not responding to itself, it responds anyway and the bot gets stuck in a loop of replying to itself.</p> <pre><code>def is_it_me_event(message): if message.author.id == 1234567890: return False @commands.Cog.listener(&quot;on_message&quot;) @commands.check(is_it_me_event) async def on_message(self, message): if str(message.content) == &quot;:smile:&quot;: await message.channel.send(&quot;:smile:&quot;) </code></pre> <p>I know I can do this with an if statement inside the function itself, but is there a way of doing this with the commands.check decorator or is this not compatible with functions that aren't commands?</p>
[ { "answer_id": 74326990, "author": "Dmitry Bychenko", "author_id": 2319407, "author_profile": "https://Stackoverflow.com/users/2319407", "pm_score": 1, "selected": false, "text": "Add" }, { "answer_id": 74327076, "author": "jdweng", "author_id": 5015238, "author_profile": "https://Stackoverflow.com/users/5015238", "pm_score": 0, "selected": false, "text": " var table = Enumerable.Range(0, x.GetLength(0))\n .SelectMany((a, i) => Enumerable.Range(0, x.GetLength(1))\n .SelectMany((b, j) => Enumerable.Range(0, x.GetLength(2))\n .SelectMany((c, k) => Enumerable.Range(0, x.GetLength(3)\n .Select((d, l) => new { x = x[i, j, k, l], i = i, j = j, k = k, l = l }))))\n .OrderByDescending(x => x.x);\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74326978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18072345/" ]
74,327,003
<p>I have a list of array that is queried that needs to be merged with the same location_id based on the objects.</p> <p>**this are the code for generating array **</p> <pre><code> filled = Product.on_hand_location(pid).to_a empty = Product.on_hand_location_empty_cylinder(pid).to_a data = filled + empty result = data.map{ |k| { details: { location_id: k['location_id'], &quot;location_name&quot;=&gt;k['location_name'], &quot;onhandcylynder&quot;=&gt;k['onhand'] == nil ? 0 : k['onhand'], &quot;emptycylynder&quot;=&gt; k['emptyonhand'] == nil ? 0 : k['emptyonhand'] } , } } respond_with [ onhand: result ] </code></pre> <p>This JSON format below is the output of code above. which has location_id that needs to be merge</p> <pre><code>[{ &quot;onhand&quot;: [{ &quot;details&quot;: { &quot;location_id&quot;: 1, &quot;location_name&quot;: &quot;Capitol Drive&quot;, &quot;onhandcylynder&quot;: &quot;4.0&quot;, &quot;emptycylynder&quot;: 0 } }, { &quot;details&quot;: { &quot;location_id&quot;: 2, &quot;location_name&quot;: &quot;SM City Butuan&quot;, &quot;onhandcylynder&quot;: &quot;5.0&quot;, &quot;emptycylynder&quot;: 0 } }, { &quot;details&quot;: { &quot;location_id&quot;: 1, &quot;location_name&quot;: null, &quot;onhandcylynder&quot;: 0, &quot;emptycylynder&quot;: &quot;2.0&quot; } } ] }] </code></pre> <p><strong>My desired output</strong></p> <pre><code> [{ &quot;onhand&quot;: [{ &quot;details&quot;: { &quot;location_id&quot;: 1, &quot;location_name&quot;: &quot;Capitol Drive&quot;, &quot;onhandcylynder&quot;: &quot;4.0&quot;, &quot;emptycylynder&quot;: 0 } }, { &quot;details&quot;: { &quot;location_id&quot;: 2, &quot;location_name&quot;: &quot;SM City Butuan&quot;, &quot;onhandcylynder&quot;: &quot;5.0&quot;, &quot;emptycylynder&quot;: &quot;2.0&quot; } } ] }] </code></pre>
[ { "answer_id": 74326990, "author": "Dmitry Bychenko", "author_id": 2319407, "author_profile": "https://Stackoverflow.com/users/2319407", "pm_score": 1, "selected": false, "text": "Add" }, { "answer_id": 74327076, "author": "jdweng", "author_id": 5015238, "author_profile": "https://Stackoverflow.com/users/5015238", "pm_score": 0, "selected": false, "text": " var table = Enumerable.Range(0, x.GetLength(0))\n .SelectMany((a, i) => Enumerable.Range(0, x.GetLength(1))\n .SelectMany((b, j) => Enumerable.Range(0, x.GetLength(2))\n .SelectMany((c, k) => Enumerable.Range(0, x.GetLength(3)\n .Select((d, l) => new { x = x[i, j, k, l], i = i, j = j, k = k, l = l }))))\n .OrderByDescending(x => x.x);\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3810922/" ]
74,327,006
<p>I have a large array with several objects, where there are several duplicates for them. I got an unique array using array_unique(PHP). Now, I need to know how to get how manny times each object was there in the original array?</p> <p>I have tried array_search, and loops but nothing got the correct results. Some what similar array like here, but it's very large set, aroud 500K entries.</p> <pre><code> [{ &quot;manufacturer&quot;: &quot;KInd&quot;, &quot;brand&quot;: &quot;ABC&quot;, &quot;used&quot;: &quot;true&quot; }, { &quot;manufacturer&quot;: &quot;KInd&quot;, &quot;brand&quot;: &quot;ABC&quot;, &quot;used&quot;: &quot;true&quot; }, { &quot;manufacturer&quot;: &quot;KInd&quot;, &quot;brand&quot;: &quot;ABC&quot;, &quot;used&quot;: &quot;false&quot; }] </code></pre>
[ { "answer_id": 74326990, "author": "Dmitry Bychenko", "author_id": 2319407, "author_profile": "https://Stackoverflow.com/users/2319407", "pm_score": 1, "selected": false, "text": "Add" }, { "answer_id": 74327076, "author": "jdweng", "author_id": 5015238, "author_profile": "https://Stackoverflow.com/users/5015238", "pm_score": 0, "selected": false, "text": " var table = Enumerable.Range(0, x.GetLength(0))\n .SelectMany((a, i) => Enumerable.Range(0, x.GetLength(1))\n .SelectMany((b, j) => Enumerable.Range(0, x.GetLength(2))\n .SelectMany((c, k) => Enumerable.Range(0, x.GetLength(3)\n .Select((d, l) => new { x = x[i, j, k, l], i = i, j = j, k = k, l = l }))))\n .OrderByDescending(x => x.x);\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327006", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1583403/" ]
74,327,041
<p>To enable tail recursion, the ocaml batteries library uses a mutable accumulator in the <a href="https://github.com/ocaml-batteries-team/batteries-included/blob/d471e24712dd1c0adb90db6894c1c721078b3934/src/batList.mlv" rel="nofollow noreferrer">list module</a>:</p> <pre class="lang-ml prettyprint-override"><code>type 'a mut_list = { hd: 'a; mutable tl: 'a list } external inj : 'a mut_list -&gt; 'a list = &quot;%identity&quot; module Acc = struct let dummy () = { hd = Obj.magic (); tl = [] } let create x = { hd = x; tl = [] } let accum acc x = let cell = create x in acc.tl &lt;- inj cell; cell end </code></pre> <p>It seems like the mutable list is simply cast to the immutable list type, but <code>mut_list</code> and <code>list</code> do not have the same type definition.</p> <p>Is this safe? How and why does this code work?</p>
[ { "answer_id": 74327329, "author": "octachron", "author_id": 7369366, "author_profile": "https://Stackoverflow.com/users/7369366", "pm_score": 2, "selected": false, "text": "[@tail_mod_cons]" }, { "answer_id": 74369470, "author": "Aaron Dufour", "author_id": 593105, "author_profile": "https://Stackoverflow.com/users/593105", "pm_score": 2, "selected": true, "text": "::" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/809632/" ]
74,327,134
<p>I need to convert file in base64. At the moment it saves the files well but not in base 64</p> <p>My code in Controller is:</p> <pre><code>@PostMapping(&quot;/upload&quot;) public ResponseEntity &lt;Response&gt; uploadFiles(@RequestParam(&quot;files&quot;) List &lt;MultipartFile&gt; files) throws Exception { fileServiceAPI.save(files); return ResponseEntity.status(HttpStatus.OK) .body(new Response(&quot;The files were successfully uploaded to the server&quot;)); } </code></pre> <p>My code in service:</p> <pre><code>private final Path rootFolder = Paths.get(&quot;upload&quot;); @Override public void save(MultipartFile file) throws Exception { Files.copy(file.getInputStream(), this.rootFolder.resolve(file.getOriginalFilename())); } @Override public void save(List&lt;MultipartFile&gt; files) throws Exception { for(MultipartFile file: files){ this.save(file); } } </code></pre>
[ { "answer_id": 74327329, "author": "octachron", "author_id": 7369366, "author_profile": "https://Stackoverflow.com/users/7369366", "pm_score": 2, "selected": false, "text": "[@tail_mod_cons]" }, { "answer_id": 74369470, "author": "Aaron Dufour", "author_id": 593105, "author_profile": "https://Stackoverflow.com/users/593105", "pm_score": 2, "selected": true, "text": "::" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,327,140
<p>I am stuck on how to solve this problem.</p> <p>Given a set of lists in a list, if any two sets of lists contain a common element, the two lists would be combined into one.</p> <p>Suppose I have a set of lists in a list <code>[[0, 1], [3, 6], [3, 9]]</code>. Notice that <code>[3, 6]</code> and <code>[3, 9]</code> have a common element <code>3</code>, so they are combined into <code>[3, 6, 9]</code>, so how to convert this set of lists in a list into <code>[[0,1], [3, 6, 9]]</code>?</p> <p>This is my current code but I am stuck.</p> <pre><code>for i in connected: for j in connected: a_set = set(i) b_set = set(j) if (a_set &amp; b_set): i.extend(j) connected.remove(j) </code></pre>
[ { "answer_id": 74327341, "author": "Rihhard", "author_id": 19328457, "author_profile": "https://Stackoverflow.com/users/19328457", "pm_score": 0, "selected": false, "text": "connected = [[0, 1], [3, 6], [3, 9]]\nnew_list = []\nfor i, v in enumerate(connected):\n for j in v:\n try:\n if j in connected[i+1]:\n new_list.append(sorted(list(set(connected[i] + connected[i+1]))))\n connected.pop(i)\n connected.pop(i)\n break\n except IndexError:\n pass\nconnected += new_list\nprint(connected)\n" }, { "answer_id": 74327786, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 1, "selected": false, "text": "def combine_commons(input: list) -> list:\n combine_found = False\n for ct_current, item_current in enumerate(input):\n \n # try to find a element that shares item:\n combine_into = None\n for ct_search, item_search in enumerate(input):\n if ct_current==ct_search: continue # can skip if i==j\n if any(i in item_search for i in item_current):\n # if any elements match, combine them.\n combine_into = item_search\n combine_found = True\n break\n\n if isinstance(combine_into, list):\n input[ct_current] = list(set(item_current + combine_into)) # overwrite with new combined\n del input[ct_search]\n\n if combine_found: return combine_commons(input)\n return input\n\nprint(combine_commons([[0, 1], [3, 6], [3, 9]]))\nprint(combine_commons([[1,2],[2,3],[2,5],[5,1]]))\n# >>> [[0, 1], [9, 3, 6]]\n# >>> [[1, 2, 3, 5]]\n" }, { "answer_id": 74327791, "author": "Akshay Sehgal", "author_id": 4755954, "author_profile": "https://Stackoverflow.com/users/4755954", "pm_score": 1, "selected": false, "text": "networkx" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18497650/" ]
74,327,153
<p>I am on MacOS 11.6.1 and want to append a character to a string and copied the following from there: <a href="https://www.geeksforgeeks.org/how-to-append-a-character-to-a-string-in-c/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/how-to-append-a-character-to-a-string-in-c/</a></p> <p>I am supposed to have the following ouptut:</p> <pre><code>Original String: Geek Character to be appended: s Appended String: Geeks </code></pre> <p>but only got the following one (with the last line missing)</p> <pre><code>Original String: Geek Character to be appended: s </code></pre> <p>What am I doing wrong?</p> <p>Here is the code</p> <pre><code>// C program to Append a Character to a String #include &lt;stdio.h&gt; #include &lt;string.h&gt; int main() { // declare and initialize string char str[6] = &quot;Geek&quot;; // declare and initialize char char ch = 's'; // print string printf(&quot;Original String: %s\n&quot;, str); printf(&quot;Character to be appended: %c\n&quot;, ch); // append ch to str strncat(str, &amp;ch, 1); // print string printf(&quot;Appended String: %s\n&quot;, str); return 0; } </code></pre>
[ { "answer_id": 74327615, "author": "ecjb", "author_id": 9381746, "author_profile": "https://Stackoverflow.com/users/9381746", "pm_score": 0, "selected": false, "text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nint main()\n{\n\n char str[6] = \"Geek\";\n char ch = 's';\n\n size_t lenstr = strlen(str);\n char *str2 = malloc(lenstr + 1 + 1);\n \n strcpy(str2, str);\n str2[lenstr] = ch;\n str2[lenstr + 1] = '\\0';\n\n printf(\"Original String: %s\\n\", str);\n printf(\"Character to be appended: %c\\n\", ch);\n\n printf(\"Appended String: %s\\n\", str2);\n\n return 0;\n}\n\n\n" }, { "answer_id": 74328095, "author": "Eric Postpischil", "author_id": 298225, "author_profile": "https://Stackoverflow.com/users/298225", "pm_score": 3, "selected": true, "text": "strncat" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9381746/" ]
74,327,176
<p>How do you get the random intercept effects estimators from a lme4 result object?</p> <pre><code>set.seed(247) # Create Data n=1000 x = runif(n) id = rep(NA,n) for (i in 1:10) { id_s = (i-1)*100+1 id_e = i*100 id[id_s:id_e] = i } effects = rnorm(10) lp = -0.5+0.5*x + effects[id] probs = exp(lp)/(1+exp(lp)) Y2 = rbinom(n, 1, probs) library(lme4) fit_glmm2 = glmer(Y2 ~ x + (1|id), family = &quot;binomial&quot;,control = glmerControl(calc.derivs = FALSE)) </code></pre> <p>I thought maybe they are the <code>u</code>'s but there's a slight difference between them:</p> <pre><code>yy = coef(fit_glmm2) # looking only at the intercept fit_glmm2@u + fit_glmm2@beta[1] </code></pre>
[ { "answer_id": 74329734, "author": "Maverick Meerkat", "author_id": 6296435, "author_profile": "https://Stackoverflow.com/users/6296435", "pm_score": 0, "selected": false, "text": "u" }, { "answer_id": 74446843, "author": "Ben Bolker", "author_id": 190277, "author_profile": "https://Stackoverflow.com/users/190277", "pm_score": 3, "selected": true, "text": "ranef()" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6296435/" ]
74,327,206
<p>How can I print only .jpg/.png urls from API using json?</p> <p>`</p> <pre><code>import requests import json r = requests.get(&quot;https://random.dog/woof.json&quot;) print(&quot;Kod:&quot;, r.status_code) def jprint(obj): text = json.dumps(obj, sort_keys=True, indent=4) print(text) jprint(r.json()) </code></pre> <p>`</p> <p>Results:</p> <p>`</p> <pre><code>{ &quot;fileSizeBytes&quot;: 78208, &quot;url&quot;: &quot;https://random.dog/24141-29115-27188.jpg&quot; } </code></pre> <p>`</p> <p>I tried .endswith() but without any success. I'm beginner.</p>
[ { "answer_id": 74329734, "author": "Maverick Meerkat", "author_id": 6296435, "author_profile": "https://Stackoverflow.com/users/6296435", "pm_score": 0, "selected": false, "text": "u" }, { "answer_id": 74446843, "author": "Ben Bolker", "author_id": 190277, "author_profile": "https://Stackoverflow.com/users/190277", "pm_score": 3, "selected": true, "text": "ranef()" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17228839/" ]
74,327,257
<p>I have search a way to improve the efficacity of my code. This is my data : Data =</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Type</th> <th style="text-align: center;">District</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">A</td> <td style="text-align: center;">1</td> </tr> <tr> <td style="text-align: center;">B</td> <td style="text-align: center;">1</td> </tr> <tr> <td style="text-align: center;">A</td> <td style="text-align: center;">2</td> </tr> <tr> <td style="text-align: center;">C</td> <td style="text-align: center;">1</td> </tr> <tr> <td style="text-align: center;">B</td> <td style="text-align: center;">1</td> </tr> <tr> <td style="text-align: center;">C</td> <td style="text-align: center;">2</td> </tr> <tr> <td style="text-align: center;">A</td> <td style="text-align: center;">2</td> </tr> </tbody> </table> </div> <p>I want to obtain a table like this :</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;"></th> <th style="text-align: center;">1</th> <th style="text-align: center;">2</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">A</td> <td style="text-align: center;">Freq</td> <td style="text-align: center;">Freq</td> </tr> <tr> <td style="text-align: center;">B</td> <td style="text-align: center;">Freq</td> <td style="text-align: center;">Freq</td> </tr> <tr> <td style="text-align: center;">C</td> <td style="text-align: center;">Freq</td> <td style="text-align: center;">Freq</td> </tr> </tbody> </table> </div> <p>With Freq the frequency of type (i.e A) for each District 1 and 2 (so the (1,1) case should be =1). My code is very &quot;manual&quot; now :</p> <pre><code>test1&lt;-as.data.frame(table(Data[which(Data$Type==&quot;A&quot;),2])) test2&lt;-as.data.frame(table(Data[which(Data$Type==&quot;B&quot;),2])) test3&lt;-as.data.frame(table(Data[which(Data$Type==&quot;C&quot;),2])) library(plyr) test&lt;-join_all(list(test1,test2,test3),by=&quot;Var1&quot;,type=&quot;left&quot;) #Var1 is created by R and corresponds to the districts test &lt;- data.frame(test[,-1], row.names = test[,1]) </code></pre> <p>What I want to be able to do, is to find a function that can do this without having to create manually all these tes1/2/3 dataframes (because in this example I have 3 modalities, but for my real problem I have 9 Types for 31 districts so it is very inefficient). I imagine that whith maybe sapply or a function like that that would be good, but I don't know how to formulate the code. Can someone help me ?</p> <p>Thanks you !</p>
[ { "answer_id": 74327324, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 0, "selected": false, "text": "test <- as.data.frame(unclass(table(Data)))\n" }, { "answer_id": 74327394, "author": "Tom Hoel", "author_id": 17213355, "author_profile": "https://Stackoverflow.com/users/17213355", "pm_score": 1, "selected": false, "text": "library(tidyverse) \n\ndf %>% \n count(Type, District) %>% \n pivot_wider(names_from = District, \n values_from = n)\n\n# A tibble: 3 x 3\n Type `1` `2`\n <chr> <int> <int>\n1 A 1 2\n2 B 2 NA\n3 C 1 1\n" }, { "answer_id": 74327416, "author": "B. Christian Kamgang", "author_id": 10848898, "author_profile": "https://Stackoverflow.com/users/10848898", "pm_score": 1, "selected": false, "text": "library(data.table)\n\ndcast(as.data.table(df), Type ~ District, fun=length)\n\n Type 1 2\n1: A 1 2\n2: B 2 0\n3: C 1 1\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20390933/" ]
74,327,265
<p>How can I update and change only the time-section of a CURRENT_TIMESTAMP in postgres SQL?</p> <p>I have to INSERT INTO a TABLE a new VALUE with the CURRENT_TIMESTAMP to get the correct year, month and day. The Time needs always to be 10 PM.</p> <p>I tried to find a function where I eventually just get a TIMESTAMP with the current Year,month, day and the default time of 00:00:00. Later I tried to DATEADD 22:00:00 Into it. Doesn't seem to work.</p>
[ { "answer_id": 74327324, "author": "Ric Villalba", "author_id": 6912817, "author_profile": "https://Stackoverflow.com/users/6912817", "pm_score": 0, "selected": false, "text": "test <- as.data.frame(unclass(table(Data)))\n" }, { "answer_id": 74327394, "author": "Tom Hoel", "author_id": 17213355, "author_profile": "https://Stackoverflow.com/users/17213355", "pm_score": 1, "selected": false, "text": "library(tidyverse) \n\ndf %>% \n count(Type, District) %>% \n pivot_wider(names_from = District, \n values_from = n)\n\n# A tibble: 3 x 3\n Type `1` `2`\n <chr> <int> <int>\n1 A 1 2\n2 B 2 NA\n3 C 1 1\n" }, { "answer_id": 74327416, "author": "B. Christian Kamgang", "author_id": 10848898, "author_profile": "https://Stackoverflow.com/users/10848898", "pm_score": 1, "selected": false, "text": "library(data.table)\n\ndcast(as.data.table(df), Type ~ District, fun=length)\n\n Type 1 2\n1: A 1 2\n2: B 2 0\n3: C 1 1\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20424991/" ]
74,327,301
<pre><code>* What went wrong: Execution failed for task ':app:mergeDebugNativeLibs'. &gt; A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade &gt; More than one file was found with OS independent path 'lib/armeabi-v7a/libfbjni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake </code></pre> <p>In app/build.gradle file</p> <pre><code>packagingOptions { pickFirst 'lib/x86/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libc++_shared.so' } </code></pre> <p>still giving error....</p> <p>Tried</p> <pre><code>In app/build.gradle file packagingOptions { pickFirst 'lib/x86/libfbjni.so' pickFirst 'lib/x86_64/libfbjni.so' pickFirst 'lib/arm64-v8a/libfbjni.so' pickFirst 'lib/armeabi-v7a/libfbjni.so' } </code></pre> <p>but it giving following error</p> <pre><code>More than one file was found with OS independent path 'lib/armeabi-v7a/libc++_shared.so'. </code></pre>
[ { "answer_id": 74338062, "author": "RamaProg", "author_id": 13844309, "author_profile": "https://Stackoverflow.com/users/13844309", "pm_score": 6, "selected": false, "text": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n // ...\n}\n\n\nallprojects {\n repositories {\n+ exclusiveContent {\n+ // We get React Native's Android binaries exclusively through npm,\n+ // from a local Maven repo inside node_modules/react-native/.\n+ // (The use of exclusiveContent prevents looking elsewhere like Maven Central\n+ // and potentially getting a wrong version.)\n+ filter {\n+ includeGroup \"com.facebook.react\"\n+ }\n+ forRepository {\n+ maven {\n+ // NOTE: if you are in a monorepo, you may have \"$rootDir/../../../node_modules/react-native/android\"\n+ url \"$rootDir/../node_modules/react-native/android\"\n+ }\n+ }\n+ }\n // ...\n }\n}\n" }, { "answer_id": 74344272, "author": "Jimmy James", "author_id": 20438630, "author_profile": "https://Stackoverflow.com/users/20438630", "pm_score": 3, "selected": false, "text": " exclusiveContent {\n filter {\n includeGroup \"com.facebook.react\"\n }\n forRepository {\n maven {\n // NOTE: if you are in a monorepo, you may have \"$rootDir/../../../node_modules/react-native/android\"\n url \"$rootDir/../node_modules/react-native/android\"\n }\n }\n }\n" }, { "answer_id": 74395325, "author": "Ed of the Mountain", "author_id": 245646, "author_profile": "https://Stackoverflow.com/users/245646", "pm_score": 2, "selected": false, "text": "def REACT_NATIVE_VERSION = new File(['node', '--print',\"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version\"].execute(null, rootDir).text.trim())\n\nallprojects {\n configurations.all {\n resolutionStrategy {\n // Remove this override in 0.65+, as a proper fix is included in react-native itself.\n force \"com.facebook.react:react-native:\" + REACT_NATIVE_VERSION\n }\n }\n" }, { "answer_id": 74474596, "author": "Priyanka Gupta", "author_id": 16601279, "author_profile": "https://Stackoverflow.com/users/16601279", "pm_score": 0, "selected": false, "text": "def REACT_NATIVE_VERSION = new File(['node', '--print',\"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version\"].execute(null, rootDir).text.trim())\n\nallprojects {\n configurations.all {\n resolutionStrategy {\n // Remove this override in 0.65+, as a proper fix is included in react-native itself.\n force \"com.facebook.react:react-native:\" + REACT_NATIVE_VERSION\n }\n }\n}\n" }, { "answer_id": 74526307, "author": "hkniyi", "author_id": 11811906, "author_profile": "https://Stackoverflow.com/users/11811906", "pm_score": 0, "selected": false, "text": "android { \n packagingOptions { \n pickFirst 'lib/armeabi-v7a/libc++_shared.so' \n pickFirst 'lib/arm64-v8a/libc++_shared.so' \n pickFirst 'lib/x86/libc++_shared.so' \n pickFirst 'lib/x86_64/libc++_shared.so' \n } \n }\n" }, { "answer_id": 74666321, "author": "Sahaj Raj Malla", "author_id": 11773575, "author_profile": "https://Stackoverflow.com/users/11773575", "pm_score": 0, "selected": false, "text": "packagingOptions {\n pickFirst 'lib/x86/libc++_shared.so'\n pickFirst 'lib/x86_64/libc++_shared.so'\n pickFirst 'lib/arm64-v8a/libc++_shared.so'\n pickFirst 'lib/armeabi-v7a/libc++_shared.so'\n\n exclude 'lib/armeabi-v7a/libfbjni.so'\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327301", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19153194/" ]
74,327,317
<p>I've to check whether a package exists in the given index-url (authenticated) using python script.</p> <p>For example:</p> <p>I've to check if package <code>package-1</code> exists in index <a href="https://mytestdomain.com/" rel="nofollow noreferrer">https://mytestdomain.com/pypi/pypi/simple/</a></p> <p>Is there any method to achieve this?</p> <p><strong>What I've tried?</strong></p> <p>I've tried the cli method, like configuring <code>pip.conf</code> with the above index-url and using <code>pip download &lt;package_name&gt;</code></p>
[ { "answer_id": 74327433, "author": "pigrammer", "author_id": 19846219, "author_profile": "https://Stackoverflow.com/users/19846219", "pm_score": 3, "selected": true, "text": "subprocess.run" }, { "answer_id": 74343082, "author": "DilLip_Chowdary", "author_id": 17610082, "author_profile": "https://Stackoverflow.com/users/17610082", "pm_score": 0, "selected": false, "text": "def check_if_package_exists_in_given_index(package_name_with_version: str, index_url: str) -> bool:\n if \"==\" in package_name_with_version:\n package_name, version = package_name_with_version.split(\"==\")\n\n package_url = index_url.strip(\n \"/\") + f\"/{package_name.replace('_', '-')}/{version}/{package_name}-{version}.tar.gz\"\n else:\n package_name = package_name_with_version\n\n package_url = index_url.strip(\"/\") + f\"/{package_name.replace('_', '-')}\"\n\n response = requests.get(url=package_url)\n\n return response.status_code == 200\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17610082/" ]
74,327,351
<p>ANY ONE PLEASE HELP ME WITH THIS ERROR.</p> <p>FAILURE: Build failed with an exception.</p> <ul> <li><p>Where: Script '/Users/cit/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1159</p> </li> <li><p>What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.</p> </li> </ul> <blockquote> <p>Process 'command '/Users/cit/flutter/bin/flutter'' finished with non-zero exit value 1</p> </blockquote> <ul> <li><p>Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.</p> </li> <li><p>Get more help at <a href="https://help.gradle.org" rel="nofollow noreferrer">https://help.gradle.org</a></p> </li> </ul> <p>BUILD FAILED in 12s Exception: Gradle task assembleDebug failed with exit code 1</p>
[ { "answer_id": 74327399, "author": "john", "author_id": 16146701, "author_profile": "https://Stackoverflow.com/users/16146701", "pm_score": 1, "selected": false, "text": "flutter clean" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19025372/" ]
74,327,366
<p>Here's a sequence:</p> <pre><code> int auth_flag = 0; char password_buffer[16]; </code></pre> <p>According to my understanding, these are local variables and are supposedly stored on the stack, which is a LIFO structure, grows upwards towards lower memory addresses(towards the heap) and variables are placed in reverse order on it. So <em>password_buffer</em> will go first and <em>auth_flag</em> will go next. I examined their memory addresses with gdb and here are the results:</p> <pre><code>Thread 1 hit Breakpoint 1, check_authentication (password=0xd01760 'A' &lt;repeats 30 times&gt;) at main.c:10 10 strcpy(password_buffer, password); (gdb) x/s password_buffer 0x61fdd0: &quot;P\026@&quot; (gdb) p/d 0x61fdd0 $1 = 6421968 (gdb) x/s auth_flag 0x0: &lt;error: Cannot access memory at address 0x0&gt; (gdb) x/s &amp;auth_flag 0x61fdec: &quot;&quot; (gdb) p/d 0x61fdec $2 = 6421996 (gdb) print 0x61fdec - 0x61fdd0 $3 = 28 </code></pre> <p><em>auth_flag</em> is located 28 bytes past the start of <em>password_buffer</em>. This sequence places the <em>auth_flag</em> ahead of <em>password_buffer</em> and renders it vulnerable to an overflow(by which I mean overwriting the return address of <em>auth_flag</em>).</p> <p>So far so good. I was able to overwrite the return address and got access.</p> <p>Then I reversed the declarations, namely:</p> <pre><code>char password_buffer[16]; int auth_flag = 0; </code></pre> <p>Now, in theory the <em>auth_flag</em> should be placed before password_buffer leaving me unable to use the return address as a exploit. I checked the memory addresses and these were the results:</p> <pre><code>(gdb) x/s password_buffer 0x61fdd0: &quot;P\026@&quot; (gdb) p/d 0x61fdd0 $1 = 6421968 (gdb) x/s &amp;auth_flag 0x61fdec: &quot;&quot; (gdb) p/d 0x61fdec $2 = 6421996 (gdb) print 0x61fdec - 0x61fdd0 $5 = 28 </code></pre> <p>The memory addresses were still the same and I was able to overwrite the return address and gained access anyhow. Am I missing something here? Could anyone explain why the memory addresses remained the same regardless of the fact that I changed the sequence?</p>
[ { "answer_id": 74327845, "author": "0___________", "author_id": 6110094, "author_profile": "https://Stackoverflow.com/users/6110094", "pm_score": 1, "selected": false, "text": "struct" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20017547/" ]
74,327,407
<p>When reading an utf-8 text file in Python you may encounter an illegal utf character. Next you probably will try to find the line (number) containing the illegal character, but probably this will fail. This is illustrated by the code below.</p> <p>Step 1: Create a file containing an illegal utf-8 character (a1 hex = 161 decimal)</p> <pre><code>filename=r&quot;D:\wrong_utf8.txt&quot; longstring = &quot;test just_a_text&quot;*10 with open(filename, &quot;wb&quot;) as f: for lineno in range(1,100): if lineno==85: f.write(f&quot;{longstring}\terrrocharacter-&gt;&quot;.encode('utf-8')+bytes.fromhex('a1')+&quot;\r\n&quot;.encode('utf-8')) else: f.write(f&quot;{longstring}\t{lineno}\r\n&quot;.encode('utf-8')) </code></pre> <p>Step 2: Read the file and catch the error:</p> <pre><code>print(&quot;First pass, regular Python textline read.&quot;) with open(filename, &quot;r&quot;,encoding='utf8') as f: lineno=0 while True: try: lineno+=1 line=f.readline() if not line: break print(lineno) except UnicodeDecodeError: print (f&quot;UnicodeDecodeError at line {lineno}\n&quot;) break </code></pre> <p>It prints: UnicodeDecodeError at line 50</p> <p>I would expect the errorline to be line 85. However, lineno 50 is printed! So, the customer who send the file to us was unable to find the illegal character. I tried to find additional parameters to modify the open statement (including buffering) but was unable to get the right error line number.</p> <p>Note: if you sufficiently shorten the longstring, the problem goes away. So the problem probably has to do with python's internal buffering.</p> <p>I succeeded by using the following code to find the error line:</p> <pre><code>print(&quot;Second pass, Python byteline read.&quot;) with open(filename,'rb') as f: lineno=0 while True: try: lineno+=1 line = f.readline() if not line: break lineutf8=line.decode('utf8') print(lineno) except UnicodeDecodeError: #Exception as e: mybytelist=line.split(b'\t') for index,field in enumerate(mybytelist): try: fieldutf8=field.decode('utf8') except UnicodeDecodeError: print(f'UnicodeDecodeError in line {lineno}, field {index+1}, offending field: {field}!') break break </code></pre> <p>Now it prints the right lineno: UnicodeDecodeError in line 85, field 2, offending field: b'errrocharacter-&gt;\xa1\r\n'!</p> <p>Is this the pythonic way of finding the error line? It works all right but I somehow have the feeling that a better method should be available where it is not required to read the file twice and/or use a binary read.</p>
[ { "answer_id": 74328453, "author": "Serge Ballesta", "author_id": 3545273, "author_profile": "https://Stackoverflow.com/users/3545273", "pm_score": 1, "selected": false, "text": "readline" }, { "answer_id": 74335514, "author": "ukBaz", "author_id": 7721752, "author_profile": "https://Stackoverflow.com/users/7721752", "pm_score": 0, "selected": false, "text": "UnicodeDecodeError" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20347826/" ]
74,327,409
<p>The user can select a picture as a profile picture in my app. After that he can click on done and the picture gets uploaded. If the user does not select a picture my code still upload a blank picture by clicking on done.</p> <p>How can I check if the user selected a picture and then trigger the function? I need an if else statement but don't know how to get the status &quot;is a picture selected?&quot;</p> <p>I could maybe also use a default value. But that would mean to download the actual picture and reupload it again as default. That does not sound good.</p> <pre><code>@IBOutlet weak var tapToChangeProfileButton: UIButton! var imagePicker: UIImagePickerController! var ref: DatabaseReference! @IBAction func updateProfile(_ sender: UIButton) { uploadPic(arg: true, completion: { (success) -&gt; Void in if success { addUrlToFirebaseProfile() } else { } }) func uploadPic(arg: Bool, completion: @escaping (Bool) -&gt; ()) { guard let imageSelected = self.image else { completion(false); return } guard let imageData = imageSelected.jpegData(compressionQuality: 0.1) else { completion(false); return } let storageRef = Storage.storage().reference(forURL: &quot;gs://....e.appspot.com&quot;) let storageProfileRef = storageRef.child(&quot;profilePictures&quot;).child(Auth.auth().currentUser!.uid) let metadata = StorageMetadata() metadata.contentType = &quot;image/jpg&quot; storageProfileRef.putData(imageData, metadata: metadata, completion: { (storageMetadata, error) in if error != nil { //print(error?.localizedDescription) completion(false); return } storageProfileRef.downloadURL(completion: { (url, error) in if let metaImageURL = url?.absoluteString { print(metaImageURL) self.urltoPicture = metaImageURL completion(true) } else { completion(false); return } }) }) } func addUrlToFirebaseProfile(){ ref = Database.database().reference() let userID = Auth.auth().currentUser!.uid ref.child(&quot;user/\(userID)&quot;).updateChildValues([&quot;profileText&quot;: profileText.text!]) print(urltoPicture) ref.child(&quot;user/\(userID)&quot;).updateChildValues([&quot;picture&quot;: urltoPicture]) } self.navigationController?.popViewController(animated: true) } override func viewDidLoad() { super.viewDidLoad() let imageTap = UITapGestureRecognizer(target: self, action: #selector(openImagePicker)) profileImageView.isUserInteractionEnabled = true profileImageView.addGestureRecognizer(imageTap) tapToChangeProfileButton.addTarget(self, action: #selector(openImagePicker), for: .touchUpInside) imagePicker = UIImagePickerController() imagePicker.allowsEditing = true imagePicker.sourceType = .photoLibrary imagePicker.delegate = self } @objc func openImagePicker(_ sender:Any){ self.present(imagePicker, animated: true, completion: nil) } extension ImagePickerViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { func imagePickerControllerDidCancel(_ picker: UIImagePickerController){ picker.dismiss(animated: true, completion: nil) } internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage { self.profileImageView.image = pickedImage image = pickedImage } picker.dismiss(animated: true, completion: nil) } } </code></pre>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14159450/" ]
74,327,488
<p>I'm trying to return struct from shared library written in C. This is simple code, for testing of returning structure and simple int32, <code>libstruct.c</code>, compiled by <code>gcc -shared -Wl,-soname,libstruct.so.1 -o libstruct.so.1 libstruct.c</code>:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdint.h&gt; int32_t newint(int32_t arg) { return arg; } struct MyStruct { int32_t member; }; struct MyStruct newstruct(int32_t arg) { struct MyStruct myStruct; myStruct.member = arg; return(myStruct); } </code></pre> <p>I can use this library with simple C program, <code>usestruct.c</code>, compiled by <code>gcc -o usestruct usestruct.c ./libstruct.so.1</code>:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; struct MyStruct { int32_t member; }; extern struct MyStruct newstruct(int32_t); extern int32_t newint(int32_t); int main() { printf(&quot;%d\n&quot;, newint(42)); struct MyStruct myStruct; myStruct = newstruct(42); printf(&quot;%d\n&quot;, myStruct.member); return 0; } </code></pre> <p>I can launch it with <code>LD_LIBRARY_PATH=./ ./usestruct</code>, and it works correctly, prints two values. Now, let's to write analogous program in raku, <code>usestruct.raku</code>:</p> <pre class="lang-raku prettyprint-override"><code>#!/bin/env raku use NativeCall; sub newint(int32) returns int32 is native('./libstruct.so.1') { * } say newint(42); class MyStruct is repr('CStruct') { has int32 $.member; } sub newstruct(int32) returns MyStruct is native('./libstruct.so.1') { * } say newstruct(42).member; </code></pre> <p>This prints first <code>42</code>, but then terminates with segmentation fault.</p> <p>In C this example works, but I'm not expert in C, maybe I forgot something, some compile options? Or is this a bug of rakudo?</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425103/" ]
74,327,508
<p>I have to create a function that takes a dictionary containing the scores of different rounds as an argument. The function returns the average score for all rounds.</p> <p>Here's an example of how the function should work:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; find_average({'round 1': [1, 2, 3, 4], 'round 2': [3, 4, 2, 7], 'round 3': [2, 7, 5, 6]}) 4.8 </code></pre> <p>I tried this:</p> <pre><code>def find_average(dictionary): average = sum(dictionary.values())/len(dictionary) return average </code></pre> <p>But I received an error:</p> <pre><code>TypeError: unsupported operand type(s) for +: 'int' and 'list' </code></pre> <p>What should I do?</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425228/" ]
74,327,541
<p>FAST CGI IS NOT WORKING PROPERLY IN DJANGO DEPLOYMENT ON IIS WINDOW SERVER</p> <pre><code> HTTP Error 500.0 - Internal Server Error C:\Users\satish.pal\AppData\Local\Programs\Python\Python310\python.exe - The FastCGI process exited unexpectedly Most likely causes: •IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred. •IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly. •IIS was not able to process configuration for the Web site or application. •The authenticated user does not have permission to use this DLL. •The request is mapped to a managed handler but the .NET Extensibility Feature is not installed. Things you can try: •Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account. •Check the event logs to see if any additional information was logged. •Verify the permissions for the DLL. •Install the .NET Extensibility feature if the request is mapped to a managed handler. •Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here. Detailed Error Information: Module FastCgiModule Notification ExecuteRequestHandler Handler fastcgiModule Error Code 0x00000001 Requested URL http://10.0.0.5:8097/ Physical Path C:\inetpub\wwwroot\hcm.ariespro.com Logon Method Anonymous Logon User Anonymous More Information: This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error. View more information » Microsoft Knowledge Base Articles: •294807 </code></pre> <p>i HAVE TRIED EVERY THIN FROM GIVING APPpOOL PERMITTIONS TO CHANGING VERSIONS OF PYTHON AND WFASTCGI</p> <p>BUT NOTHING IS WORKING FOR ME</p> <p>PROJECT IS WORKING JUST FINE ON DJANGO SERVER</p> <p>I HAVE ALSO DEPLOYED IT USING NGINX AND WAITRESS FROM WINDOYS SERVER BUT I NEED IT TO WORK WITH IIS PLEASE hELP ME OUT-- AT ANY COST</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17904860/" ]
74,327,543
<pre><code>{ &quot;response_code&quot;: &quot;1&quot;, &quot;message&quot;: &quot;Workout Found&quot;, &quot;workout&quot;: { &quot;id&quot;: &quot;1&quot;, &quot;goalid&quot;: &quot;3&quot;, &quot;levelid&quot;: &quot;1&quot;, &quot;workname&quot;: &quot;At - Home Cardio for Fat Loss&quot;, &quot;dow&quot;: &quot;4&quot;, &quot;image&quot;: &quot;https://sparksapps.in/gym/uploads/6218a2c119f28.jpg&quot;, &quot;goal_name&quot;: &quot;Transform&quot;, &quot;level_name&quot;: &quot;Beginner&quot;, &quot;fav_status&quot;: &quot;1&quot; }, &quot;status&quot;: &quot;success&quot; } //code {data?.map((element, i) =&gt; { //data =&gt;response setData(resp.workout) return ( &lt;div className=&quot;col-md-4&quot; key={i}&gt; &lt;div className=&quot;card card-cascade wider&quot; style={{ display: &quot;flex&quot;, justifyContent: &quot;start&quot; }} &gt; &lt;div className=&quot;view view-cascade overlay&quot;&gt; &lt;img className=&quot;card-img-top&quot; src={element.image} alt=&quot;Card image cap&quot;/&gt; &lt;a href=&quot;#!&quot;&gt; &lt;div className=&quot;mask rgba-white-slight&quot;&gt;&lt;/div&gt; &lt;/a&gt; &lt;/div&gt; &lt;div className=&quot;card-body card-body-cascade text-center pb-0&quot;&gt; &lt;h5 className=&quot;card-title&quot;&gt;id:{element.id}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;goalid:{element.goalid}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;levelid:{element.levelid}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;workname:{element.workname}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;dow:{element.dow}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;goal_name:{element.goal_name}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;level_name:{element.level_name}&lt;/h5&gt; &lt;h5 className=&quot;card-title&quot;&gt;fav_status:{element.fav_status}&lt;/h5&gt; &lt;div className=&quot;card-footer text-muted text-center mt-4&quot;&gt; 2 days ago &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; ); })} </code></pre> <p>react mapping not working i've tried using Object.entries(resp.workout) it returns the no. of values notthe Actual Data from the Api ! Response is Completly Working but what mistake am i making in the creation of map method !! help me Out Thank You!!!</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20228171/" ]
74,327,559
<p>I need to count non-unique sequences going sequentially. For example: &quot;aabcccjaaa&quot; is &quot;21313&quot;. But my code do not count the last string. In checks, it goes to the last &quot;else&quot; and must add the last &quot;a&quot; as a unit to the result. What could be the problem? And maybe someone knows a solution instead of mine using standard libraries?</p> <pre><code>a = &quot;assdddfghttyuuujssa&quot; b = '' c = 1 d = [] for item in a: if item == b: c += 1 elif b == '': c = 1 else: d.append(c) c = 1 b = item print(d) </code></pre> <p>I tried to add output of unique words on each iteration of the loop, however it still doesn't show why the last &quot;append&quot; doesn't add &quot;1&quot; to the result.</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12718068/" ]
74,327,591
<p>I am trying to create a window, open it and be able to close it and the program should stop after I closed the window.</p> <p>The Code i wrote so far is mostly copied from this video: <a href="https://www.youtube.com/watch?v=OR4fNpBjmq8&amp;list=PLlrATfBNZ98foTJPJ_Ev03o2oq3-GGOS2&amp;index=2" rel="nofollow noreferrer">Setting Up OpenGL and creating a window</a></p> <p>Here is my code:</p> <p>Window.scala</p> <pre><code>// The Window displaying the rendered image with openGL package Main import org.lwjgl.*; import org.lwjgl.glfw.*; import org.lwjgl.opengl.*; import org.lwjgl.system.*; import java.nio.*; import org.lwjgl.glfw.Callbacks.*; import org.lwjgl.glfw.GLFW.*; import org.lwjgl.opengl.GL11.*; import org.lwjgl.system.MemoryStack.*; import org.lwjgl.system.MemoryUtil.*; class Window(width: Int, height: Int, name: CharSequence) { // Code from https://www.lwjgl.org/guide GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) { throw new IllegalStateException(&quot;Can't create window&quot;) } var window = glfwCreateWindow(width, height, name, 0, 0); glfwMakeContextCurrent(window); while (!glfwWindowShouldClose(window)) { // glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); } </code></pre> <p>Main.scala:</p> <pre><code>import Main._ @main def hello: Unit = { val window = Window(250,250, &quot;Test&quot;); } </code></pre> <p>I am using sbt version 1.7.2 to compile and run my code with the build.sbt:</p> <pre><code>import scala.collection.immutable.Seq val scala3Version = &quot;3.2.0&quot; lazy val root = project .in(file(&quot;.&quot;)) .settings( name := &quot;2DRenderer&quot;, version := &quot;0.1.0-SNAPSHOT&quot;, scalaVersion := scala3Version, libraryDependencies += &quot;org.scalameta&quot; %% &quot;munit&quot; % &quot;0.7.29&quot; % Test ) lazy val lwjglVersion = &quot;3.2.1&quot; lazy val os = Option(System.getProperty(&quot;os.name&quot;, &quot;&quot;)) .map(_.substring(0, 3).toLowerCase) match { case Some(&quot;win&quot;) =&gt; &quot;windows&quot; case Some(&quot;mac&quot;) =&gt; &quot;macos&quot; case _ =&gt; &quot;linux&quot; } libraryDependencies ++= Seq( &quot;org.lwjgl&quot; % &quot;lwjgl&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl-opengl&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl-glfw&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl-stb&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl-assimp&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl-nanovg&quot; % lwjglVersion, &quot;org.lwjgl&quot; % &quot;lwjgl&quot; % lwjglVersion classifier s&quot;natives-$os&quot;, &quot;org.lwjgl&quot; % &quot;lwjgl-opengl&quot; % lwjglVersion classifier s&quot;natives-$os&quot;, &quot;org.lwjgl&quot; % &quot;lwjgl-glfw&quot; % lwjglVersion classifier s&quot;natives-$os&quot;, &quot;org.lwjgl&quot; % &quot;lwjgl-stb&quot; % lwjglVersion classifier s&quot;natives-$os&quot;, &quot;org.lwjgl&quot; % &quot;lwjgl-assimp&quot; % lwjglVersion classifier s&quot;natives-$os&quot;, &quot;org.lwjgl&quot; % &quot;lwjgl-nanovg&quot; % lwjglVersion classifier s&quot;natives-$os&quot; ) fork := true </code></pre> <p>The code is running fine as long as I do not clear the Color Buffer with <code>glClear(GL_COLOR_BUFFER_BIT)</code>. Running the code with clearing the buffer the loop, i get the following error message from sbt:</p> <pre><code>[info] running (fork) hello [info] FATAL ERROR in native method: Thread[main,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution. [info] at org.lwjgl.opengl.GL11C.glClear(Native Method) [info] at org.lwjgl.opengl.GL11.glClear(GL11.java:1045) [info] at Main.Window.&lt;init&gt;(Window.scala:31) [info] at Main$package$.hello(Main.scala:3) [info] at hello.main(Main.scala:2) [error] Nonzero exit code returned from runner: 1 [error] (Compile / run) Nonzero exit code returned from runner: 1 [error] Total time: 1 s, completed 05.11.2022 12:58:36 </code></pre> <p>Does anybody know why clearing the color buffer is resulting in this runtime error?</p>
[ { "answer_id": 74327459, "author": "matt", "author_id": 341994, "author_profile": "https://Stackoverflow.com/users/341994", "pm_score": 0, "selected": false, "text": "self.image" }, { "answer_id": 74327482, "author": "Thang Phi", "author_id": 10650407, "author_profile": "https://Stackoverflow.com/users/10650407", "pm_score": 2, "selected": true, "text": "imagePickerController" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13728674/" ]
74,327,597
<p>Let's say I have a function with two generic parameters, one of them variadic:</p> <pre class="lang-golang prettyprint-override"><code>func Constructor[F any, Opt any](f F, opts ...Opt) {} </code></pre> <p>Calling this function works fine if I pass in a few options:</p> <pre class="lang-golang prettyprint-override"><code>Constructor(func() *myService { return ... }, 1, 2, 3) </code></pre> <p>However, calling it without any <code>Opt</code>s fails:</p> <pre class="lang-golang prettyprint-override"><code>Construtor(func() *myService { return ... }) </code></pre> <p>The compiler complains:</p> <blockquote> <p>Cannot use 'func() *myService' (type func() *myService) as the type (F, Opt) or F</p> </blockquote> <p>I assume that’s because the compiler can’t figure out the type of <code>Opt</code> in this case.</p> <p>While this makes sense, it’s annoying nevertheless. The compiler doesn't <em>need</em> the type of <code>Opt</code>, since it's empty.</p> <p>One way to work around this is to define two functions, <code>Constructor</code> and <code>ConstructorWithOpts</code>. It would be really nice to just have a single function though. Any ideas?</p>
[ { "answer_id": 74327763, "author": "icza", "author_id": 1705598, "author_profile": "https://Stackoverflow.com/users/1705598", "pm_score": 1, "selected": false, "text": "Constructor(func() *myService { return nil }, []int{}...)\n" }, { "answer_id": 74328227, "author": "blackgreen", "author_id": 4108803, "author_profile": "https://Stackoverflow.com/users/4108803", "pm_score": 2, "selected": false, "text": "Opt" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327597", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1003971/" ]
74,327,617
<p>Window Tortoisehg, realized I cannot use Bitbucket, is there free alternative for home use (with a cheap annual subscription) that is easy to setup. Many answer found here are outdated since Bitbucket no longer support Tortoisehg. I'm open for suggestion. I looked into GitHub but had no luck in making push works</p>
[ { "answer_id": 74327763, "author": "icza", "author_id": 1705598, "author_profile": "https://Stackoverflow.com/users/1705598", "pm_score": 1, "selected": false, "text": "Constructor(func() *myService { return nil }, []int{}...)\n" }, { "answer_id": 74328227, "author": "blackgreen", "author_id": 4108803, "author_profile": "https://Stackoverflow.com/users/4108803", "pm_score": 2, "selected": false, "text": "Opt" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/537629/" ]
74,327,618
<p>is there a way to determine the side of the rotation for the transform: rotateY, CSS property?</p> <p>I'm trying to rotate this h1 element from one side to the other, but regardless of the sign (+ or -) it always rotate in the same direction.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>h1 { display: inline-flex; font-size: 50px; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; letter-spacing: 4px; color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); white-space: nowrap; z-index: 3; transform-style: preserve-3d; animation: rotate 2s infinite; } @keyframes rotate { 0% { } 33% { transform: rotatey(40deg); } 66% { transform: rotateY(0); } 100% { transform: rotatey(-40deg); } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h1&gt;Example&lt;/h1&gt;</code></pre> </div> </div> </p> <p>Thanks for any insight</p>
[ { "answer_id": 74327763, "author": "icza", "author_id": 1705598, "author_profile": "https://Stackoverflow.com/users/1705598", "pm_score": 1, "selected": false, "text": "Constructor(func() *myService { return nil }, []int{}...)\n" }, { "answer_id": 74328227, "author": "blackgreen", "author_id": 4108803, "author_profile": "https://Stackoverflow.com/users/4108803", "pm_score": 2, "selected": false, "text": "Opt" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,327,620
<p>Given a string of the form &quot;3,9,13,4,42&quot;. It is necessary to convert it into a list and calculate its square for each element. Then join the squares of those elements back into a string and print it in the console. input</p> <p>input: string = &quot;3,9,13,4,42&quot;</p> <p>output: string= &quot;9,81,169,16,1764&quot;</p> <p>Managed to get it squared up, tried converting it to list fist, but when checked type at the end, always somehow getting it as tuple. Ty for help.</p>
[ { "answer_id": 74327691, "author": "Shreyansh Gupta", "author_id": 18046485, "author_profile": "https://Stackoverflow.com/users/18046485", "pm_score": 0, "selected": false, "text": "\n// First Approach\n\nstring = \"3,9,13,4,42\"\narray = string.split(',')\narray = map(lambda x: str(int(x)**2),array)\nresult = ','.join(list(array))\nprint(result) // \"9,81,169,16,1764\"\n\n// Second Approach\nstring = \"3,9,13,4,42\"\nresult = ','.join([str(int(x)**2) for x in string.split(',')])\nprint(result) // '9,81,169,16,1764'\n\n\n\n" }, { "answer_id": 74327701, "author": "Vladislav Korecký", "author_id": 16343968, "author_profile": "https://Stackoverflow.com/users/16343968", "pm_score": 1, "selected": false, "text": "# input\nstr_numbers = \"3,9,13,4,42\"\n\n# string to list\nstr_number_list = str_numbers.split(\",\")\n\n# list of strings to list of ints\nnumber_list = [int(x) for x in str_number_list]\n\n# square all numbers\nsquared_numbers = [x ** 2 for x in number_list]\n\n# squared numbers back to a list of strings\nstr_squared_numbers = [str(x) for x in squared_numbers]\n\n# joing the list items into one string\nresult = \",\".join(str_squared_numbers)\n\n# print it out\nprint(f\"Input: {str_numbers}\")\nprint(f\"Output: {result}\")\n" }, { "answer_id": 74327723, "author": "Rahul K P", "author_id": 4407666, "author_profile": "https://Stackoverflow.com/users/4407666", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74327739, "author": "Giuseppe La Gualano", "author_id": 20249888, "author_profile": "https://Stackoverflow.com/users/20249888", "pm_score": 0, "selected": false, "text": "input_string = \"3,9,13,4,42\"\n\nnum_list = [float(x) for x in input_string.split(\",\")] # split list by comma and cast each element to float\nsquares_list = [x**2 for x in num_list] # make square of each number in list\noutput_string = [str(x) for x in squares_list] # cast to string each element in list\n\nprint(output_string)\n" }, { "answer_id": 74327748, "author": "José Juan", "author_id": 20386708, "author_profile": "https://Stackoverflow.com/users/20386708", "pm_score": 0, "selected": false, "text": "string = \"3,9,13,4,42\"\n\ndef squares_string(string):\n output = \",\".join(tuple(map(lambda x: str(int(x)**2), \"3,9,13,4,42\".split(\",\"))))\n\n return output\n\noutput = squares_string(string)\nprint(output)\nprint(type(output))\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425306/" ]
74,327,634
<p>I want to fill in the login of this page with selenium: <a href="https://influence.co/go/location-search/top-nl-influencers/city/amsterdam" rel="nofollow noreferrer">https://influence.co/go/location-search/top-nl-influencers/city/amsterdam</a>. But it is not sending the keys.</p> <p>Send_keys</p> <pre><code>try: email = driver.find_element(By.CSS_SELECTOR, &quot;#user_email&quot;) self.assertTrue(email.is_enabled) driver.execute_script(&quot;arguments[0].click();&quot;, email) email.send_keys('email@gmail.com') except: print(&quot;Problem&quot;) </code></pre>
[ { "answer_id": 74327691, "author": "Shreyansh Gupta", "author_id": 18046485, "author_profile": "https://Stackoverflow.com/users/18046485", "pm_score": 0, "selected": false, "text": "\n// First Approach\n\nstring = \"3,9,13,4,42\"\narray = string.split(',')\narray = map(lambda x: str(int(x)**2),array)\nresult = ','.join(list(array))\nprint(result) // \"9,81,169,16,1764\"\n\n// Second Approach\nstring = \"3,9,13,4,42\"\nresult = ','.join([str(int(x)**2) for x in string.split(',')])\nprint(result) // '9,81,169,16,1764'\n\n\n\n" }, { "answer_id": 74327701, "author": "Vladislav Korecký", "author_id": 16343968, "author_profile": "https://Stackoverflow.com/users/16343968", "pm_score": 1, "selected": false, "text": "# input\nstr_numbers = \"3,9,13,4,42\"\n\n# string to list\nstr_number_list = str_numbers.split(\",\")\n\n# list of strings to list of ints\nnumber_list = [int(x) for x in str_number_list]\n\n# square all numbers\nsquared_numbers = [x ** 2 for x in number_list]\n\n# squared numbers back to a list of strings\nstr_squared_numbers = [str(x) for x in squared_numbers]\n\n# joing the list items into one string\nresult = \",\".join(str_squared_numbers)\n\n# print it out\nprint(f\"Input: {str_numbers}\")\nprint(f\"Output: {result}\")\n" }, { "answer_id": 74327723, "author": "Rahul K P", "author_id": 4407666, "author_profile": "https://Stackoverflow.com/users/4407666", "pm_score": 0, "selected": false, "text": "split" }, { "answer_id": 74327739, "author": "Giuseppe La Gualano", "author_id": 20249888, "author_profile": "https://Stackoverflow.com/users/20249888", "pm_score": 0, "selected": false, "text": "input_string = \"3,9,13,4,42\"\n\nnum_list = [float(x) for x in input_string.split(\",\")] # split list by comma and cast each element to float\nsquares_list = [x**2 for x in num_list] # make square of each number in list\noutput_string = [str(x) for x in squares_list] # cast to string each element in list\n\nprint(output_string)\n" }, { "answer_id": 74327748, "author": "José Juan", "author_id": 20386708, "author_profile": "https://Stackoverflow.com/users/20386708", "pm_score": 0, "selected": false, "text": "string = \"3,9,13,4,42\"\n\ndef squares_string(string):\n output = \",\".join(tuple(map(lambda x: str(int(x)**2), \"3,9,13,4,42\".split(\",\"))))\n\n return output\n\noutput = squares_string(string)\nprint(output)\nprint(type(output))\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18157382/" ]
74,327,645
<p>I have some panels for recipes which have a photo and a title, but the title is too long and I need it to be that size. But word-break: break-word; isn't working. This is what I mean:</p> <p><a href="https://i.stack.imgur.com/HbKuI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HbKuI.png" alt="enter image description here" /></a></p> <p>This is my code:</p> <pre><code> &lt;div class=&quot;recipe-container&quot;&gt; &lt;div class=&quot;recipe-window&quot;&gt; &lt;a href=&quot;https://www.bbcgoodfood.com/recipes/easy-millionaires-shortbread&quot;&gt;&lt;img src=&quot;https://images.immediate.co.uk/production/volatile/sites/30/2020/08/millionaires-shortbread-52587dd.jpg?quality=90&amp;webp=true&amp;resize=300,272&quot;&gt;&lt;/a&gt; &lt;p class=&quot;recipe-title&quot;&gt;Millionare's Shortbread&lt;/p&gt; &lt;/div&gt; &lt;div class=&quot;recipe-window&quot;&gt; &lt;a href=&quot;https://www.bbcgoodfood.com/recipes/classic-white-loaf&quot;&gt;&lt;img src=&quot;https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-559666_11-b53071d.jpg?quality=90&amp;webp=true&amp;resize=300,272&quot;&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; .recipe-container { margin: 0px; padding: 10px; display: inline-flex; } .recipe-window { margin: 10px; padding: 10px; border: 1px solid #ffffff; background-color: #ffffff; word-break: break-word; width: auto; } .recipe-title { color: black; margin-top: 5px; padding: 0px; font-size: 40px; } </code></pre> <p>How can I fix this?</p>
[ { "answer_id": 74327885, "author": "Ivan", "author_id": 16221113, "author_profile": "https://Stackoverflow.com/users/16221113", "pm_score": 0, "selected": false, "text": ".recipe-container {\n margin: 0px;\n padding: 10px;\n display: inline-flex;\n flex-wrap: wrap;\n}\n\n.recipe-window {\n margin: 10px;\n padding: 10px;\n border: 1px solid #ffffff;\n background-color: #ffffff;\n width: 300px;\n}\n\n.recipe-title {\n color: black;\n margin-top: 5px;\n padding: 0px;\n font-size: 40px;\n}" }, { "answer_id": 74327902, "author": "Sli4o", "author_id": 12185026, "author_profile": "https://Stackoverflow.com/users/12185026", "pm_score": 2, "selected": false, "text": ".recipe-container {\n margin: 0px;\n padding: 10px;\n display: inline-flex;\n}\n\n.recipe-window {\n margin: 10px;\n padding: 10px;\n border: 1px solid #ffffff;\n background-color: #ffffff;\n word-break: break-word;\n width: min-content;\n}\n\n.recipe-title {\n color: black;\n margin: 0;\n margin-top: 5px;\n font-size: 40px;\n}" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20197071/" ]
74,327,654
<p>So i tried making a rock paper scissors game but some if statements are not working. code was written in python.</p> <p>Is there something preventing the if statements ffrom running? or s there another problem</p> <p>I tried a bunch of little changes but none of them work</p> <p>code:</p> <pre><code>import random moves = ('rock', 'paper', 'scissors') while True: print(&quot;rock, paper, scissors. Go! &quot;) userInput = input(&quot;Choose your move: &quot;) botInput = random.choice(moves) if userInput == botInput: print(userInput + &quot; VS &quot; + botInput) print(&quot;DRAW&quot;) if userInput == &quot;paper&quot; and botInput == &quot;rock&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Player Wins!&quot;) if userInput == &quot;scissors&quot; and botInput == &quot;paper&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Player Wins!&quot;) if userInput == &quot;rock&quot; and botInput == &quot;scissors&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Player Wins!&quot;) if userInput == &quot;rock&quot; and botInput == &quot;paper&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Bot Wins!&quot;) if userInput == &quot;paper&quot; and botInput == &quot;scissors&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Bot Wins!&quot;) if userInput == &quot;scissors&quot; and botInput == &quot;rock&quot;: print(userInput + &quot; VS &quot; + botInput) print(&quot;Bot Wins!&quot;) print(&quot;Wanna Rematch?&quot;) decision = input(&quot;Yes or No? &quot;) if decision == &quot;Yes&quot;: pass elif decision == &quot;No&quot;: break </code></pre>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327654", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20371218/" ]
74,327,665
<p>I want to save the date of today in a string and have the following code with the following output:</p> <p>Code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; int main() { time_t t = time(NULL); struct tm tm = *localtime(&amp;t); printf(&quot;%02d-%02d&quot;, tm.tm_mday, tm.tm_mon + 1); printf(&quot;\n&quot;); } </code></pre> <p>Output (for today, November the 5th):</p> <pre><code>05-11 </code></pre> <p>What is the easiest way to save <code>05-11</code> in a string?</p>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9381746/" ]
74,327,753
<p><code>df &lt;- as.data.frame(matrix(1:5, rep(10), ncol = 10))</code></p> <p>This is my example data frame. I'd like to apply the following to all even values: take -6 and then compute the absolute value.</p> <p>The result should look like that:</p> <pre><code> V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1 1 1 1 1 1 1 1 1 1 1 2 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 4 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5 5 5 5 6 1 1 1 1 1 1 1 1 1 1 7 4 4 4 4 4 4 4 4 4 4 8 3 3 3 3 3 3 3 3 3 3 9 2 2 2 2 2 2 2 2 2 2 10 5 5 5 5 5 5 5 5 5 5 </code></pre> <p>You could also say replace all the 2s by 4s and vice versa....</p> <p>I tried to filter() out all the evens and then do -6 and abs(), tried a for loop as well and an if else function... It didn't work out the way I wanted and got far too complicated</p>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20229686/" ]
74,327,754
<p>I am trying to append to the container Path from my dockerfile however when I build the docker file and run the container the changes I have made are not reflected in the container Path</p> <pre><code>RUN echo &quot;export PATH=/go-dependencies:\$PATH:/home/skyctl/bin:/home/skyctl/.local/bin:/dependencies&quot; &gt;&gt; ~/.bashrc </code></pre> <p>I ran the command above however none of the Paths added are reflected once the container is running</p>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16499681/" ]
74,327,767
<p>I am trying to use a loop to create a new variable in an existing data frame that is conditional on the values of the variables included in the loop. The logic makes sense to me but I am getting unexpected results.</p> <p>Take the following data frame as an example:</p> <pre class="lang-none prettyprint-override"><code>&gt; df var1 var2 var3 var4 1 0 1 0 1 2 1 0 0 1 3 1 1 0 1 4 0 0 1 0 5 0 1 1 0 </code></pre> <p>I want to create a new variable (var5) that is equal to 0 if any of vars1-4 are equal to 1. Otherwise, I want this variable to be coded as a missing value. I wrote the following loop:</p> <pre><code>for (var in c(&quot;var1&quot;, &quot;var2&quot;, &quot;var3&quot;, &quot;var4&quot;)) { df$var5 &lt;- ifelse( df[, var] == 1, 0, NA ) } </code></pre> <p>This logic seems straightforward to me, as is similar to a &quot;foreach&quot; loop in Stata, but my results are unexpected:</p> <pre><code>&gt; for (var in c(&quot;var1&quot;, &quot;var2&quot;, &quot;var3&quot;, &quot;var4&quot;)) { + df$var5 &lt;- ifelse( + df[, var] == 1, 0, NA + ) + } &gt; df var1 var2 var3 var4 var5 1 0 1 0 1 0 2 1 0 0 1 0 3 1 1 0 1 0 4 0 0 1 0 NA 5 0 1 1 0 NA </code></pre> <p>For some reason, the loop seems to only be applying the conditional statement to the last element of &quot;var&quot;. Observations 4 and 5 should be be 0, given that those rows contain a one in the list of vars specified.</p> <p>I'm sure there is something simple I am missing, but does anyone know how to correct this?</p>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327767", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425428/" ]
74,327,782
<p>I have been trying to code a program that takes input from the user for scores and then calculated the average with an input validation. The only thing I am unable to figure out is how to tell the number of scores entered which are greater than 80. Also I have to do this without using arrays.</p> <p>Here's what I currently have but is not working and starts the counter from 5 instead of 1 and then incrementing it as the scores greater than 80 are entered.</p> <pre><code>int main() { int score, sum=0, greater=0; for(int i=1; i&lt;=5; i++) { cout&lt;&lt;&quot;Enter the score: &quot;; //take user input for scores cin&gt;&gt;score; if(score&gt;80) { for (int i=1; i&lt;=5; i++){ greater= greater+1; } cout&lt;&lt;&quot;There are &quot;&lt;&lt;greater&lt;&lt;&quot; number more than 80&quot;; } while (! (score &gt;=0 &amp;&amp; score &lt;= 100 )) //input validation { cout &lt;&lt; &quot;Invalid Input. Enter the score between the range 0 - 100&quot; &lt;&lt; endl; cout &lt;&lt; &quot;Enter the score: &quot;; cin &gt;&gt; score; } sum = sum + score; } float avg; avg = sum/5.0; //calculating the average cout&lt;&lt;&quot;Average of scores: &quot;&lt;&lt;avg&lt;&lt;endl; </code></pre> <p>Can anybody help me with this? It would be much appreciated. Thanks!</p> <p>I tried the above listed code and also tried to tweak it but it still shows the count as multiple of 5.</p>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425485/" ]
74,327,784
<p>I have three tables:</p> <pre><code>CREATE TABLE Playlist (`id` int, `name` varchar(90)) ; INSERT INTO Playlist (`id`, `name`) VALUES (1, 'Playlist_1'), (100, 'EmptyPlaylist'), (111, 'Playlist_222'), (1001, 'Playlist_4') ; CREATE TABLE PlaylistItem (`id` int, `trackID` int, `playlistID` int) ; INSERT INTO PlaylistItem (`id`, `trackID`, `playlistID`) VALUES (3, 2, 1), (32, 22, 1), (321, 222, 1), (333, 222, 3), (333, 2, 3), (303, 200, 1001) ; CREATE TABLE Track (`id` int, `title` varchar(300)) ; INSERT INTO Track (`id`, `title`) VALUES (2, 'Foo'), (22, 'Bar'), (200, 'Only_In_Playlist_4_Which_Is_Not_Included_In_the_Query'), (222, 'Byy'), (21, 'NotInAnyPlaylist'), (20000, 'NotInAnyPlaylist_2') ; </code></pre> <p><a href="http://sqlfiddle.com/#!9/068d3f" rel="nofollow noreferrer">Fiddle</a></p> <p>Each <code>Playlist</code> contains multiple <code>PlaylistItem</code> , which contain one <code>Track</code>. My goal is to provide an array of <code>Playlist IDs</code> and get all <code>Tracks</code> inside those playlist (not only their IDs).</p> <p>However, I do not know how to access subitems from a query. I used joins but they merge the keys and I only want to get the tracks without the keys from other tables. I could select just the keys from <code>Track</code> with a join, but my <code>Track</code> table has over 100 keys and they could change.</p> <p>Desired outcome :</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>id</th> <th>title</th> </tr> </thead> <tbody> <tr> <td>2</td> <td>Foo</td> </tr> <tr> <td>22</td> <td>Bar</td> </tr> <tr> <td>222</td> <td>Byy</td> </tr> </tbody> </table> </div> <p>I get track IDs now with this:</p> <pre><code>SELECT trackID FROM PlaylistItem WHERE playlistID in ('1', '4') -- Here comes the array of IDs, for the example I want '1' and '4' </code></pre>
[ { "answer_id": 74327909, "author": "ugo_capeto", "author_id": 20329094, "author_profile": "https://Stackoverflow.com/users/20329094", "pm_score": 0, "selected": false, "text": "import random\nmoves = ('rock', 'paper', 'scissors')\n\nwhile True:\n print(\"rock, paper, scissors. Go! \")\n\n userInput = input(\"Choose your move: \").lower()\n\n botInput = random.choice(moves)\n #check if input is valid\n if userInput not in moves:\n print(\"Choose a valid move! Wanna try again?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n # skips the remaining body of the loop\n else: break\n\n elif userInput == botInput:\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n elif userInput == \"paper\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif userInput == \"rock\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n\n elif userInput == \"rock\" and botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"paper\" and botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n elif userInput == \"scissors\" and botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n\n\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \").lower()\n if decision == \"yes\" or decision == 'y': continue\n else: break\n" }, { "answer_id": 74327950, "author": "Jack142", "author_id": 20417932, "author_profile": "https://Stackoverflow.com/users/20417932", "pm_score": 0, "selected": false, "text": "\nmoves = ('rock', 'paper', 'scissors')\ndecision = \"Nothing\"\n\nwhile decision != \"No\":\n decision = \"Nothing\"\n print(\"rock, paper, scissors. Go! \")\n \n userInput = input(\"Choose your move: \")\n \n botInput = random.choice(moves)\n\n if userInput == \"paper\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"paper\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n else:\n print(\"Invalid choice.\")\n\n if userInput == \"scissors\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\")\n\n if userInput == \"rock\":\n if botInput == \"rock\":\n print(userInput + \" VS \" + botInput)\n print(\"DRAW\") \n elif botInput == \"paper\": \n print(userInput + \" VS \" + botInput)\n print(\"Bot Wins!\")\n elif botInput == \"scissors\":\n print(userInput + \" VS \" + botInput)\n print(\"Player Wins!\") \n \n while decision != \"Yes\" and decision != \"No\":\n print(\"Wanna Rematch?\")\n decision = input(\"Yes or No? \")\n if decision == \"Yes\":\n pass\n elif decision == \"No\":\n break\n else:\n print(\"Invalid answer.\")\n" }, { "answer_id": 74327975, "author": "Steinn Hauser Magnusson", "author_id": 13819183, "author_profile": "https://Stackoverflow.com/users/13819183", "pm_score": 2, "selected": true, "text": "if-else" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9578667/" ]
74,327,808
<p>If my cluster is not active, and I have uploaded 50 files in storage location, then where this Auto Loader will list out these 50 files if cluster is not active. Will it use any checkpoint location, if yes, then how can I set the checkpoint location in Cloud Storage for these new files identification? Can anyone please tell me the backend process that is used to identifying these new files if my cluster is not active?</p>
[ { "answer_id": 74343955, "author": "Ramdev Sharma", "author_id": 10293253, "author_profile": "https://Stackoverflow.com/users/10293253", "pm_score": 0, "selected": false, "text": "two modes" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12837273/" ]
74,327,867
<p>How to read products array on getSales, for others uses?</p> <pre class="lang-js prettyprint-override"><code>document.addEventListener(&quot;alpine:init&quot;, () =&gt; { Alpine.store(&quot;getProducts&quot;, { url: &quot;http://localhost:3000/products&quot;, products: [], getAllProducts() { fetch(this.url) .then((response) =&gt; response.json()) .then((data) =&gt; (this.products = data)); }, }); }); const getSales = () =&gt; ({ products: $store.getProducts.products }) </code></pre>
[ { "answer_id": 74343955, "author": "Ramdev Sharma", "author_id": 10293253, "author_profile": "https://Stackoverflow.com/users/10293253", "pm_score": 0, "selected": false, "text": "two modes" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/802542/" ]
74,327,879
<p><strong>For example lets say the user needs to type 112.56,</strong></p> <p>So when <strong>user types 1</strong>, input field becomes <strong>1.00</strong><br /> Next when <strong>user types 1 again</strong>, input field becomes <strong>11.00</strong><br /> Next when <strong>user types 2</strong>, input field becomes <strong>112.00</strong><br /> Next when <strong>user types '.' (the decimal point)</strong>, input field still is <strong>112.00</strong><br /> Then <strong>user types 5</strong>, input field becomes <strong>112.50</strong><br /> Last <strong>user types 6</strong>, and input field becomes <strong>112.56</strong></p> <p>I've seen this achieved in my local atm machines, I'm wondering if this is achievable via html/javascript or requires a different language or a different technique</p> <p><strong>I want it to update while the user is still typing</strong></p>
[ { "answer_id": 74327915, "author": "tacoshy", "author_id": 14072420, "author_profile": "https://Stackoverflow.com/users/14072420", "pm_score": 0, "selected": false, "text": "Float" }, { "answer_id": 74328486, "author": "Andrew Parks", "author_id": 5898421, "author_profile": "https://Stackoverflow.com/users/5898421", "pm_score": 3, "selected": true, "text": "document.getElementById('n').onkeyup = e => {\n const process = i => {\n let v = i.value;\n const ss = i.selectionStart;\n const resetCursor = () => i.setSelectionRange(ss,ss);\n if(/^[0]*.00$/.test(v)) {\n i.value = '';\n }\n else if(/^[0-9.]+$/.test(v)) {\n let p = v.indexOf('..');\n if(p>=0) {\n i.value = v.replace('..','.');\n resetCursor();\n process(i);\n }\n else if([...v].filter(c=>c==='.').length>1) {\n let j = v.indexOf('.');\n i.value = [...v].filter((c,k)=>k<=j||c!=='.').join('');\n resetCursor();\n process(i);\n }\n else {\n i.value = (+v).toFixed(2); \n resetCursor();\n }\n }\n else {\n v = v.replace(/[^0-9.]/g, '');\n i.value = v;\n resetCursor();\n }\n }\n process(e.target);\n}" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18617343/" ]
74,327,880
<p>I have a button that html is below</p> <p><a href="https://i.stack.imgur.com/VRQXV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VRQXV.jpg" alt="enter image description here" /></a></p> <p>I tired the following code</p> <pre><code>Execute_Button = driver.find_element(&quot;xPath&quot;,'//button[text()=&quot;Execute &quot;]') </code></pre> <p>But Python comes up with this error message. How to solve?</p> <pre><code>InvalidArgumentException: Message: invalid argument: invalid locator </code></pre>
[ { "answer_id": 74327968, "author": "maciek97x", "author_id": 10626495, "author_profile": "https://Stackoverflow.com/users/10626495", "pm_score": 2, "selected": true, "text": "By.XPATH" }, { "answer_id": 74328170, "author": "eaglescofield", "author_id": 14102221, "author_profile": "https://Stackoverflow.com/users/14102221", "pm_score": 0, "selected": false, "text": "browser.find_element_by_xpath('//button[text()=\"Execute \"]').click()\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/647453/" ]
74,327,882
<p>So I've just started learning redux and in the process read their documentation on '<a href="https://redux.js.org/usage/structuring-reducers/normalizing-state-shape" rel="nofollow noreferrer">Normalizing State Shape</a>'.</p> <p>One of the key takeaway points is:</p> <blockquote> <p>&quot;Any references to individual items should be done by storing the item's ID.&quot;</p> </blockquote> <p>I've set up my state as they have advised. So in the example below each taskGroup holds a selection of tasks referenced by their ids and each task holds a selection of comments also referenced by their ids.</p> <pre><code>{ &quot;taskGroups&quot;: { &quot;byId&quot;: { &quot;taskGroup1&quot;: { &quot;taskGroupId&quot;: &quot;taskGroup1&quot;, &quot;tasks&quot;: [&quot;task1&quot;, &quot;task2&quot;] //etc etc }, &quot;taskGroup2&quot;: { &quot;taskGroupId&quot;: &quot;taskGroup2&quot;, &quot;tasks&quot;: [&quot;task2&quot;, &quot;task3&quot;] //etc etc } //etc etc }, &quot;allIds&quot;: [&quot;taskGroup1&quot;, &quot;taskGroup2&quot;, &quot;taskGroup3&quot;] }, &quot;tasks&quot;: { &quot;byId&quot;: { &quot;task1&quot;: { &quot;taskId&quot;: &quot;task1&quot;, &quot;description&quot;: &quot;......&quot;, &quot;comments&quot;: [&quot;comment1&quot;, &quot;comment2&quot;] //etc etc }, &quot;task2&quot;: { &quot;taskId&quot;: &quot;task2&quot;, &quot;description&quot;: &quot;......&quot;, &quot;comments&quot;: [&quot;comment3&quot;, &quot;comment4&quot;, &quot;comment5&quot;] //etc etc } //etc etc }, &quot;allIds&quot;: [&quot;task1&quot;, &quot;task2&quot;, &quot;task3&quot;, &quot;task4&quot;] }, &quot;comments&quot;: { &quot;byId&quot;: { &quot;comment1&quot;: { &quot;id&quot;: &quot;comment1&quot;, &quot;comment&quot;: &quot;.....&quot; //etc etc }, &quot;comment2&quot;: { &quot;id&quot;: &quot;comment2&quot;, &quot;comment&quot;: &quot;.....&quot; //etc etc } //etc etc }, &quot;allIds&quot;: [&quot;comment1&quot;, &quot;comment2&quot;, &quot;comment3&quot;, &quot;comment4&quot;, &quot;comment5&quot;] } } </code></pre> <p>I understand the theory and see the benefits of having my state structured like this. In practice though, I'm struggling to map over an array of references in an object and a bit lost of where I should be doing it.</p> <p>What and where is the most efficient way to map over the references to the item's Ids with the actual items?</p> <p>Should I be doing this on the parent component mapping over all the references before passing them down as props to child components? Or should I pass the references down to child components as props and then map over them there?</p> <p>Before switching to redux I was using useContext but with a normalised state. I used the following function to filter what tasks were needed for each taskGroup. <a href="https://stackoverflow.com/questions/38750705/filter-object-properties-by-key-in-es6">Thanks to ssube who posted this</a></p> <pre><code>export const filterObject = (objToFilter: any, valuesToFind: string) =&gt; { return Object.keys(objToFilter) .filter((key) =&gt; valuesToFind.includes(key)) .reduce((obj, key) =&gt; { return { ...obj, [key]: objToFilter[key], }; }, {}); }; </code></pre> <p>Which was then used like so (the same logic was then repeated in my Tasks component to map out comments)</p> <pre><code>{ Object.values(taskGroupsById) .sort((a, b) =&gt; a.sortOrder - b.sortOrder) .map((taskGroup) =&gt; { return ( &lt;TaskGroup key={taskGroup.taskGroupId} taskGroupTitle={taskGroup.taskGroupTitle} tasks={filterObject( tasksById, taskGroupsById[`${taskGroup.taskGroupId}`].tasks )} handleDrawer={handleDrawer} findTaskStatus={findTaskStatus} findAssignedToTask={findAssignedToTask} /&gt; ); }); } </code></pre> <p>This works ok but I'm not sure if its counter intuitive, as it's beeing calculated in multiple instances of the TaskGroup component instead of just once.</p> <p>Is there a better method to achieve this? I've tried to create a selector in my slices to recreate this but can't seem to work out how to map over multiple references in an array (as opposed to just one reference as a string).</p> <p>Any help would be much appreciated even if it is just a nudge in the right direction. Thanks!</p>
[ { "answer_id": 74327968, "author": "maciek97x", "author_id": 10626495, "author_profile": "https://Stackoverflow.com/users/10626495", "pm_score": 2, "selected": true, "text": "By.XPATH" }, { "answer_id": 74328170, "author": "eaglescofield", "author_id": 14102221, "author_profile": "https://Stackoverflow.com/users/14102221", "pm_score": 0, "selected": false, "text": "browser.find_element_by_xpath('//button[text()=\"Execute \"]').click()\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19100196/" ]
74,327,948
<p>I create a while loop to generate values and insert them into the existing table &quot;PLAYGROUND&quot;.&quot;BF_DEV&quot;.A5_DIMDATE_HUIQIONGWU</p> <p>But there always is syntax error:</p> <p>SQL compilation error: syntax error line 23 at position 10 unexpected '('. syntax error line 23 at position 20 unexpected '&lt;'.</p> <pre><code>execute immediate $$ declare crrday date default '2005-01-01'; datekey integer default 0; daynumberofweek integer default 0; endaynumberofweek varchar; daynumberofmonth integer default 0; daynumberofyear integer default 0; weeknumberofyear integer default 0; enmonth varchar; monthnumberofyear integer default 0; calquarter integer default 0; calyear integer default 0; calses integer default 0; fisyear integer default 0; fisquarter integer default 0; fisses integer default 0; begin let crrday date := '2005-01-01'; let lastday date := '2031-01-01'; let crryear integer := year(crrday); let lastyear integer := year(lastday); while (:crryear &lt; lastyear) then datekey := convert(integer, crrday, 112); daynumberofweek := DAYOFWEEK(crrday); endaynumberofweek := decode(extract ('dayofweek_iso',crrday); daynumberofmonth := DAYOFMONTH(crrday); daynumberofyear := DAYOFYEAR(crrday); weeknumberofyear := WEEKOFYEAR(crrday); enmonth := decode(monthname(crrday)); monthnumberofyear := MONTH(crrday); calquarter := QUARTER(crrday); calyear := year(crrday); calses := case when month(crrday) between 1 and 6 then 1 else 2 end; fisyear := case when month(crrday) between 1 and 6 then year(crrday) else dateadd(year, 1, crrday) end; fisquarter := case when month(crrday) between 7 and 9 then 1 case when month(crrday) between 10 and 12 then 2 case when month(crrday) between 1 and 3 then 3 else 4 end; fisses := case when month(crrday) between 7 and 12 then 1 else 2 end; insert into &quot;PLAYGROUND&quot;.&quot;BF_DEV&quot;.A5_DIMDATE_HUIQIONGWU values (datekey, crrday, daynumberofweek, endaynumberofweek, daynumberofmonth, endaynumberofweek, daynumberofmonth, daynumberofyear, weeknumberofyear, enmonth, monthnumberofyear, calquarter, calyear, calses, fisquarter, fisyear, fisses); crrday := dateadd(day, 1, crrday); crryear := year(crryear); end while; end; $$ ; </code></pre>
[ { "answer_id": 74328417, "author": "Tom Meacham", "author_id": 4139546, "author_profile": "https://Stackoverflow.com/users/4139546", "pm_score": 0, "selected": false, "text": "/*********************************************************************************************\nA WEEK_START session variable of 0 is the default Snowflake behavior and has weeks start on\nMonday and end of Sunday (ISO standard).\nWherever possible, this script uses the ISO standard for WEEKS and DAY_OF_WEEK.\nThe DATEDIFF function does not support WEEKISO and therefore the WEEK_START parameter is set \nfor the session in case this session parameter was set differently on the account or user. \nhttps://docs.snowflake.com/en/sql-reference/parameters.html#label-week-start\n*********************************************************************************************/\nalter session set week_start = 0;\n\n/*********************************************************************************************\nThe parameters below define the temporal boundaries of the calendar table. The values must be \nDATE type and can be hardcoded, the result of a query, or a combination of both.\nFor example, you could set date_start and date_end based on the MIN and MAX date of the table\nwith the finest date granularity in your data.\n*********************************************************************************************/\n\nSET date_start = TO_DATE('2018-12-18');\nSET date_end = current_date(); --TIP: for the current date use current_date();\n\n--This sets the num_days parameter to the number of days between start and end\n--this value is used for the generator\nset num_days = (select datediff(day, $date_start, $date_end+1));\n\n--CTE to hold generated date range\ncreate or replace transient table calendar as \nwith d as (\nselect\n dateadd(day,'-' || row_number() over (order by null), \n dateadd(day, '+1', $date_end)\n ) as date_key\nfrom table (generator(rowcount => ($num_days)))\norder by 1)\n-- calendar table expressions \nselect\n date_key,\n year(date_key) - (year(date_key) % 10) as decade,\n year(date_key) as year_,\n (year(date_key)::string || '-Q' || quarter(date_key)::string)::varchar(7) as year_qtr,\n (year(date_key)::string || '-' || lpad(month(date_key)::string, 2 ,'0'))::varchar(7) as year_month,\n (yearofweekiso(date_key)::string || '-' || lpad(weekiso(date_key)::string, 2 ,'0'))::varchar(7) as year_week_iso, --*see comments\n quarter(date_key) as qtr_of_year,\n month(date_key) as month_num,\n monthname(date_key) as month_name,\n time_slice(date_key, 1, 'month', 'start') as month_start_date,\n last_day(date_key, 'month') as month_end_date, \n weekiso(date_key) as week_iso_num, --*see comments\n yearofweekiso(date_key) as week_iso_year, --*see comments\n 'W'||lpad(weekiso(date_key)::string,2,0) as week_iso_string, \n iff(dayofweekiso(date_key) = 1, date_key, previous_day(date_key, 'mo')) as week_start_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, next_day(date_key, 'su')) as week_end_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, previous_day(date_key, 'su')) as week_start_sun, --week starts on sun, ends on sat\n iff(dayofweekiso(date_key) = 6, date_key, next_day(date_key, 'sa')) as week_end_sun, --week starts on sun, ends on sat\n dayofyear(date_key) as day_of_year,\n dayofmonth(date_key) as day_of_month,\n dayofweekiso(date_key) as day_of_week_iso,\n dayname(date_key) as day_name, \n ceil(dayofmonth(date_key) / 7) as day_instance_in_month, --used to identify 'floating' events such as \"fourth thursday of november\" \n iff(dayofweekiso(date_key) between 6 and 7, 1, 0) flag_day_is_weekend,\n iff(dayofweekiso(date_key) between 6 and 7, 0, 1) flag_day_is_weekday,\n iff(year(current_date())= year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_cytd, --current year to date, date falls within current year to day\n iff(year(current_date()) - 1 = year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_lytd, --last year to date, date falls within current year to day\n iff(dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_ytd, --year to date, date falls within the same days in the year, no matter which year\n iff(add_months(time_slice(date_key, 1, 'month', 'start'),1) = time_slice(current_date(), 1, 'month', 'start'),1 , 0) as flag_last_month,\n datediff(year, date_key, current_date()) as age_years_ago,\n datediff(month,date_key, current_date()) as age_months_ago,\n datediff(week,date_key, current_date()) as age_weeks_ago,\n datediff(day,date_key, current_date()) as age_days_ago\nFROM D;\n" }, { "answer_id": 74328738, "author": "Greg Pavlik", "author_id": 12756381, "author_profile": "https://Stackoverflow.com/users/12756381", "pm_score": 1, "selected": false, "text": "select row_number() over (order by null) - 1 DATEKEY\n ,dateadd('DAY', DATEKEY, '2005-01-01'::date)::date CRRDAY\n ,dayofweek(CRRDAY) DAYNUMBEROFWEEK\n ,extract('dayofweek_iso',CRRDAY) ENDDAYNUMBEROFWEEK -- What do you want here?\n ,dayofmonth(CRRDAY) DAYNUMBEROFMONTH\n ,dayofmonth(last_day(CRRDAY, 'WEEK')) ENDDAYNUMBEROFWEEK\n ,dayofyear(CRRDAY) DAYNUMBEROFYEAR\n ,weekofyear(CRRDAY) WEEKNUMBEROFYEAR\n ,monthname(CRRDAY) ENMONTH\n ,month(CRRDAY) MONTHNUMBEROFYEAR\n ,quarter(CRRDAY) CALQUARTER\n ,year(CRRDAY) CALYEAR\n ,iff(month(crrday) <= 6, 1, 2) CALSES\n ,case \n when month(crrday) between 7 and 9 then 1\n when month(crrday) between 10 and 12 then 2\n when month(crrday) between 1 and 3 then 3\n else 4\n end FISQUARTER\n ,iff(month(crrday) > 6, 1, 0) + year(crrday) FISYEAR\n ,iff(month(CRRDAY) > 6, 1, 2) FISSES\n \nfrom table(generator(rowcount => 10000))\nqualify CRRDAY < '2031-01-01'::date \norder by CRRDAY;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16443919/" ]
74,327,953
<p>Basically I am starting with Jest and I want to know with this tool if an API returns a response with status code 200. I have searched many ways to do it on the internet but none of them worked for me and I kept getting errors.</p> <p>Could someone give me a hand on that?</p> <p>For example, make a Rick &amp; Morty API call with either Axios or Fetch and see if it returns a 200 status code:</p> <p><a href="https://rickandmortyapi.com/api/character" rel="nofollow noreferrer">https://rickandmortyapi.com/api/character</a></p> <p>I tried something like this:</p> <br> <p><strong>File &quot;mock.js&quot;</strong></p> <pre><code>import axios from &quot;axios&quot;; const getMovies = async () =&gt; { try { let res = await axios.get('https://rickandmortyapi.com/api/character') } catch(error) { console.log('Error! D:') } } export default getMovies; </code></pre> <br> <p><strong>File &quot;mock.test.js&quot;</strong></p> <pre><code>import axios from 'axios'; import getMovies from './mock.js'; jest.mock('getMovies'); test('should return a 200 status code', () =&gt; { expect(getMovies.status).toBe(200) }) </code></pre> <br> <p><strong>And it shows me the following:</strong></p> <p><a href="https://i.stack.imgur.com/0KiVX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0KiVX.png" alt="Result" /></a></p>
[ { "answer_id": 74328417, "author": "Tom Meacham", "author_id": 4139546, "author_profile": "https://Stackoverflow.com/users/4139546", "pm_score": 0, "selected": false, "text": "/*********************************************************************************************\nA WEEK_START session variable of 0 is the default Snowflake behavior and has weeks start on\nMonday and end of Sunday (ISO standard).\nWherever possible, this script uses the ISO standard for WEEKS and DAY_OF_WEEK.\nThe DATEDIFF function does not support WEEKISO and therefore the WEEK_START parameter is set \nfor the session in case this session parameter was set differently on the account or user. \nhttps://docs.snowflake.com/en/sql-reference/parameters.html#label-week-start\n*********************************************************************************************/\nalter session set week_start = 0;\n\n/*********************************************************************************************\nThe parameters below define the temporal boundaries of the calendar table. The values must be \nDATE type and can be hardcoded, the result of a query, or a combination of both.\nFor example, you could set date_start and date_end based on the MIN and MAX date of the table\nwith the finest date granularity in your data.\n*********************************************************************************************/\n\nSET date_start = TO_DATE('2018-12-18');\nSET date_end = current_date(); --TIP: for the current date use current_date();\n\n--This sets the num_days parameter to the number of days between start and end\n--this value is used for the generator\nset num_days = (select datediff(day, $date_start, $date_end+1));\n\n--CTE to hold generated date range\ncreate or replace transient table calendar as \nwith d as (\nselect\n dateadd(day,'-' || row_number() over (order by null), \n dateadd(day, '+1', $date_end)\n ) as date_key\nfrom table (generator(rowcount => ($num_days)))\norder by 1)\n-- calendar table expressions \nselect\n date_key,\n year(date_key) - (year(date_key) % 10) as decade,\n year(date_key) as year_,\n (year(date_key)::string || '-Q' || quarter(date_key)::string)::varchar(7) as year_qtr,\n (year(date_key)::string || '-' || lpad(month(date_key)::string, 2 ,'0'))::varchar(7) as year_month,\n (yearofweekiso(date_key)::string || '-' || lpad(weekiso(date_key)::string, 2 ,'0'))::varchar(7) as year_week_iso, --*see comments\n quarter(date_key) as qtr_of_year,\n month(date_key) as month_num,\n monthname(date_key) as month_name,\n time_slice(date_key, 1, 'month', 'start') as month_start_date,\n last_day(date_key, 'month') as month_end_date, \n weekiso(date_key) as week_iso_num, --*see comments\n yearofweekiso(date_key) as week_iso_year, --*see comments\n 'W'||lpad(weekiso(date_key)::string,2,0) as week_iso_string, \n iff(dayofweekiso(date_key) = 1, date_key, previous_day(date_key, 'mo')) as week_start_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, next_day(date_key, 'su')) as week_end_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, previous_day(date_key, 'su')) as week_start_sun, --week starts on sun, ends on sat\n iff(dayofweekiso(date_key) = 6, date_key, next_day(date_key, 'sa')) as week_end_sun, --week starts on sun, ends on sat\n dayofyear(date_key) as day_of_year,\n dayofmonth(date_key) as day_of_month,\n dayofweekiso(date_key) as day_of_week_iso,\n dayname(date_key) as day_name, \n ceil(dayofmonth(date_key) / 7) as day_instance_in_month, --used to identify 'floating' events such as \"fourth thursday of november\" \n iff(dayofweekiso(date_key) between 6 and 7, 1, 0) flag_day_is_weekend,\n iff(dayofweekiso(date_key) between 6 and 7, 0, 1) flag_day_is_weekday,\n iff(year(current_date())= year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_cytd, --current year to date, date falls within current year to day\n iff(year(current_date()) - 1 = year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_lytd, --last year to date, date falls within current year to day\n iff(dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_ytd, --year to date, date falls within the same days in the year, no matter which year\n iff(add_months(time_slice(date_key, 1, 'month', 'start'),1) = time_slice(current_date(), 1, 'month', 'start'),1 , 0) as flag_last_month,\n datediff(year, date_key, current_date()) as age_years_ago,\n datediff(month,date_key, current_date()) as age_months_ago,\n datediff(week,date_key, current_date()) as age_weeks_ago,\n datediff(day,date_key, current_date()) as age_days_ago\nFROM D;\n" }, { "answer_id": 74328738, "author": "Greg Pavlik", "author_id": 12756381, "author_profile": "https://Stackoverflow.com/users/12756381", "pm_score": 1, "selected": false, "text": "select row_number() over (order by null) - 1 DATEKEY\n ,dateadd('DAY', DATEKEY, '2005-01-01'::date)::date CRRDAY\n ,dayofweek(CRRDAY) DAYNUMBEROFWEEK\n ,extract('dayofweek_iso',CRRDAY) ENDDAYNUMBEROFWEEK -- What do you want here?\n ,dayofmonth(CRRDAY) DAYNUMBEROFMONTH\n ,dayofmonth(last_day(CRRDAY, 'WEEK')) ENDDAYNUMBEROFWEEK\n ,dayofyear(CRRDAY) DAYNUMBEROFYEAR\n ,weekofyear(CRRDAY) WEEKNUMBEROFYEAR\n ,monthname(CRRDAY) ENMONTH\n ,month(CRRDAY) MONTHNUMBEROFYEAR\n ,quarter(CRRDAY) CALQUARTER\n ,year(CRRDAY) CALYEAR\n ,iff(month(crrday) <= 6, 1, 2) CALSES\n ,case \n when month(crrday) between 7 and 9 then 1\n when month(crrday) between 10 and 12 then 2\n when month(crrday) between 1 and 3 then 3\n else 4\n end FISQUARTER\n ,iff(month(crrday) > 6, 1, 0) + year(crrday) FISYEAR\n ,iff(month(CRRDAY) > 6, 1, 2) FISSES\n \nfrom table(generator(rowcount => 10000))\nqualify CRRDAY < '2031-01-01'::date \norder by CRRDAY;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74327953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16531753/" ]
74,328,017
<p>I'm having some issues implementing HeapSort in python. Input sequence does not get properly sorted... The</p> <p>implementation looks like this:</p> <pre><code>class Heap: def __init__(self, S, heapsize): self.S = S self.heapsize = heapsize def shiftdown(H, i): siftkey = H.S[i] parent = i spotfound = False while (2*parent &lt;= H.heapsize and not spotfound): if (2*parent &lt; H.heapsize and H.S[2*parent] &lt; H.S[2*parent - 1]): largerchild = 2*parent + 1 else: largerchild = 2*parent if(siftkey &lt; H.S[largerchild]): H.S[parent] = H.S[largerchild] parent = largerchild else: spotfound = True H.S[parent] = siftkey def makeheap(n, H): i = int(n/2) H.heapsize = n while i &gt;= 1: shiftdown(H, i) i -= 1 def root(H): keytype = H.S[1] H.S[1] = H.S[H.heapsize] H.heapsize = H.heapsize - 1 shiftdown(H, 1) return keytype def removekeys(n, H ,A): i = n while(i &gt;= 1): A[i] = root(H) i -= 1 def HeapSort(n, H): makeheap(n, H) removekeys(n, H, H.S) if __name__ == '__main__': A = [30, 25, 20, 18, 12, 19, 17, 16, 14, 11] n = len(A) - 1 H = Heap(A, n) print(H.heapsize) print(A) HeapSort(n, H) print(H.S) </code></pre> <p>The input A results in the output [30, 11, 16, 12, 14, 17, 18, 19, 20, 25]. The implementation is based on algorithm 7.5 from the book Foundations of Algorithms: Neapolitan, Richard fifth edition, and i've tried to do a direct conversion to python. Se pitchurs below.</p> <p>Any suggestions would be helpful!</p> <p>The algorithm from the book looks like this:</p> <p><a href="https://i.stack.imgur.com/F7TRT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F7TRT.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/96EDF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96EDF.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/Vmw2P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vmw2P.png" alt="enter image description here" /></a></p> <p>I've tried to go through the algorithm on pen and paper to find where the hiccup happens, but still can't seem to figure it out...</p>
[ { "answer_id": 74328417, "author": "Tom Meacham", "author_id": 4139546, "author_profile": "https://Stackoverflow.com/users/4139546", "pm_score": 0, "selected": false, "text": "/*********************************************************************************************\nA WEEK_START session variable of 0 is the default Snowflake behavior and has weeks start on\nMonday and end of Sunday (ISO standard).\nWherever possible, this script uses the ISO standard for WEEKS and DAY_OF_WEEK.\nThe DATEDIFF function does not support WEEKISO and therefore the WEEK_START parameter is set \nfor the session in case this session parameter was set differently on the account or user. \nhttps://docs.snowflake.com/en/sql-reference/parameters.html#label-week-start\n*********************************************************************************************/\nalter session set week_start = 0;\n\n/*********************************************************************************************\nThe parameters below define the temporal boundaries of the calendar table. The values must be \nDATE type and can be hardcoded, the result of a query, or a combination of both.\nFor example, you could set date_start and date_end based on the MIN and MAX date of the table\nwith the finest date granularity in your data.\n*********************************************************************************************/\n\nSET date_start = TO_DATE('2018-12-18');\nSET date_end = current_date(); --TIP: for the current date use current_date();\n\n--This sets the num_days parameter to the number of days between start and end\n--this value is used for the generator\nset num_days = (select datediff(day, $date_start, $date_end+1));\n\n--CTE to hold generated date range\ncreate or replace transient table calendar as \nwith d as (\nselect\n dateadd(day,'-' || row_number() over (order by null), \n dateadd(day, '+1', $date_end)\n ) as date_key\nfrom table (generator(rowcount => ($num_days)))\norder by 1)\n-- calendar table expressions \nselect\n date_key,\n year(date_key) - (year(date_key) % 10) as decade,\n year(date_key) as year_,\n (year(date_key)::string || '-Q' || quarter(date_key)::string)::varchar(7) as year_qtr,\n (year(date_key)::string || '-' || lpad(month(date_key)::string, 2 ,'0'))::varchar(7) as year_month,\n (yearofweekiso(date_key)::string || '-' || lpad(weekiso(date_key)::string, 2 ,'0'))::varchar(7) as year_week_iso, --*see comments\n quarter(date_key) as qtr_of_year,\n month(date_key) as month_num,\n monthname(date_key) as month_name,\n time_slice(date_key, 1, 'month', 'start') as month_start_date,\n last_day(date_key, 'month') as month_end_date, \n weekiso(date_key) as week_iso_num, --*see comments\n yearofweekiso(date_key) as week_iso_year, --*see comments\n 'W'||lpad(weekiso(date_key)::string,2,0) as week_iso_string, \n iff(dayofweekiso(date_key) = 1, date_key, previous_day(date_key, 'mo')) as week_start_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, next_day(date_key, 'su')) as week_end_mon, --week starts on mon, ends on sun\n iff(dayofweekiso(date_key) = 7, date_key, previous_day(date_key, 'su')) as week_start_sun, --week starts on sun, ends on sat\n iff(dayofweekiso(date_key) = 6, date_key, next_day(date_key, 'sa')) as week_end_sun, --week starts on sun, ends on sat\n dayofyear(date_key) as day_of_year,\n dayofmonth(date_key) as day_of_month,\n dayofweekiso(date_key) as day_of_week_iso,\n dayname(date_key) as day_name, \n ceil(dayofmonth(date_key) / 7) as day_instance_in_month, --used to identify 'floating' events such as \"fourth thursday of november\" \n iff(dayofweekiso(date_key) between 6 and 7, 1, 0) flag_day_is_weekend,\n iff(dayofweekiso(date_key) between 6 and 7, 0, 1) flag_day_is_weekday,\n iff(year(current_date())= year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_cytd, --current year to date, date falls within current year to day\n iff(year(current_date()) - 1 = year(date_key) and dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_lytd, --last year to date, date falls within current year to day\n iff(dayofyear(date_key) <= dayofyear(current_date()), 1, 0) as flag_ytd, --year to date, date falls within the same days in the year, no matter which year\n iff(add_months(time_slice(date_key, 1, 'month', 'start'),1) = time_slice(current_date(), 1, 'month', 'start'),1 , 0) as flag_last_month,\n datediff(year, date_key, current_date()) as age_years_ago,\n datediff(month,date_key, current_date()) as age_months_ago,\n datediff(week,date_key, current_date()) as age_weeks_ago,\n datediff(day,date_key, current_date()) as age_days_ago\nFROM D;\n" }, { "answer_id": 74328738, "author": "Greg Pavlik", "author_id": 12756381, "author_profile": "https://Stackoverflow.com/users/12756381", "pm_score": 1, "selected": false, "text": "select row_number() over (order by null) - 1 DATEKEY\n ,dateadd('DAY', DATEKEY, '2005-01-01'::date)::date CRRDAY\n ,dayofweek(CRRDAY) DAYNUMBEROFWEEK\n ,extract('dayofweek_iso',CRRDAY) ENDDAYNUMBEROFWEEK -- What do you want here?\n ,dayofmonth(CRRDAY) DAYNUMBEROFMONTH\n ,dayofmonth(last_day(CRRDAY, 'WEEK')) ENDDAYNUMBEROFWEEK\n ,dayofyear(CRRDAY) DAYNUMBEROFYEAR\n ,weekofyear(CRRDAY) WEEKNUMBEROFYEAR\n ,monthname(CRRDAY) ENMONTH\n ,month(CRRDAY) MONTHNUMBEROFYEAR\n ,quarter(CRRDAY) CALQUARTER\n ,year(CRRDAY) CALYEAR\n ,iff(month(crrday) <= 6, 1, 2) CALSES\n ,case \n when month(crrday) between 7 and 9 then 1\n when month(crrday) between 10 and 12 then 2\n when month(crrday) between 1 and 3 then 3\n else 4\n end FISQUARTER\n ,iff(month(crrday) > 6, 1, 0) + year(crrday) FISYEAR\n ,iff(month(CRRDAY) > 6, 1, 2) FISSES\n \nfrom table(generator(rowcount => 10000))\nqualify CRRDAY < '2031-01-01'::date \norder by CRRDAY;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20408076/" ]
74,328,018
<p>How to lowercase the first letter of the first word of each sentence in a paragraph? Also, nouns in the middle of sentences will remain capitalized.</p> <p>How can I do that in Python?</p> <p>For example: &quot;This is a example sentence. Please help me. I don't want this situation. In Berlin we have a great time.&quot; to &quot;this is a example sentence. please help me. i don't want this situation. in Berlin we have a great time.&quot;</p> <p><a href="https://i.stack.imgur.com/PJNmb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PJNmb.png" alt="enter image description here" /></a></p> <p>I tried this one but this is lower only one sentence.</p>
[ { "answer_id": 74328090, "author": "king juno", "author_id": 14781263, "author_profile": "https://Stackoverflow.com/users/14781263", "pm_score": 1, "selected": false, "text": "def first_lower(s):\n paragraph = ''\n _sentences = s.split('.') # split sentences from paragraph using .\n for sentence in _sentences:\n if sentence == '':\n continue\n paragraph += sentence[0].lower() + sentence[1:] + '.' # append converted string to paragraph\n \n return paragraph\n\nstring = \"\"\"this is a example sentence. please help me. i don't want this situation. in Berlin we have a great time.\"\"\"\nprint(first_lower(string))\n" }, { "answer_id": 74328150, "author": "mozway", "author_id": 16343464, "author_profile": "https://Stackoverflow.com/users/16343464", "pm_score": 2, "selected": false, "text": "import re\n\ns = \"This is a example sentence. Please help me. I don't want this situation. In Berlin we have a great time.\"\n\nout = re.sub(r'((?:^|\\.)\\s*\\w+)', lambda m: m.group().lower(), s)\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425664/" ]
74,328,020
<p>for a project im working on im checking if a user inputted string is one of 4 strings, it checks if the user inputed one of these 4 strings if not it asks the user again. although when i try to run it, if i enter str1 or any of the other ones it doesnt end the loop.</p> <pre><code>example = input('enter string') while example != 'str1' or example != 'str2' or example != 'str3' or example != 'str4': print('input str1, str2, str3 or str4') example = input('enter string') #do stuff </code></pre> <p>if i type str1</p> <pre><code>enter stringstr1 input str1, str2, str3 or str4 enter string </code></pre> <pre><code>example = input('enter string') while not example == 'str1' or not example == 'str2' or not example == 'str3' or not example == 'str4': print('input str1, str2, str3 or str4') example = input('enter string') #do stuff </code></pre> <p>ive tried doing this because i thought it could be something to do with the while loop, not suprisingly it didnt fix it</p>
[ { "answer_id": 74328080, "author": "0x0fba", "author_id": 20339407, "author_profile": "https://Stackoverflow.com/users/20339407", "pm_score": -1, "selected": false, "text": "or" }, { "answer_id": 74328120, "author": "Jasmijn", "author_id": 573255, "author_profile": "https://Stackoverflow.com/users/573255", "pm_score": 2, "selected": false, "text": "example == 'str1' or example == 'str2' or example == 'str3' or example == 'str4'" }, { "answer_id": 74328312, "author": "Shahan M", "author_id": 1560708, "author_profile": "https://Stackoverflow.com/users/1560708", "pm_score": 1, "selected": false, "text": "while" }, { "answer_id": 74331480, "author": "Arifa Chan", "author_id": 19574157, "author_profile": "https://Stackoverflow.com/users/19574157", "pm_score": 0, "selected": false, "text": "not in" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
74,328,035
<p>I'm new to Tkinter and as my first project I wanted to create a Tic Tac Toe. I want to create 9 buttons, that will change their background image when I click on them, the problem is that I dont want to create a function for every single button but one function that will take the button in argument and will change its background image.</p> <p>The code I wrote:</p> <pre><code> def play(bid): if player == &quot;X&quot;: bid.config(image=cross) if player == &quot;O&quot;: bid.config(image=circle) b1 = tk.Button(app, text=&quot;&quot;, image=white, command=lambda id=b1: play(id)) b1.grid(column=0, row=0) </code></pre> <p>How can I pass b1 as an argument to play() function? Thanks</p> <p>I tried to use b1 as an argument to play(), and use play() to change b1's image. When I try to run this code I get &quot;name b1 is not defined&quot;.</p>
[ { "answer_id": 74328054, "author": "Ahmed AEK", "author_id": 15649230, "author_profile": "https://Stackoverflow.com/users/15649230", "pm_score": 1, "selected": false, "text": ".config" }, { "answer_id": 74328203, "author": "chepner", "author_id": 1126841, "author_profile": "https://Stackoverflow.com/users/1126841", "pm_score": 1, "selected": false, "text": "def play(bid):\n if player == \"X\":\n bid.config(image=cross)\n if player == \"O\":\n bid.config(image=circle)\n\ndef add_button(app, r, c):\n b = tk.Button(app, text=\"\", image=white)\n b.config(command=lambda: play(b))\n b.grid(column=c, row=r)\n return b\n\nfor row in [0,1,2]:\n for col in [0,1,2]:\n # Save the return value somewhere if necessary\n addButton(app, row, col)\n" }, { "answer_id": 74330740, "author": "chikibamboni", "author_id": 19427338, "author_profile": "https://Stackoverflow.com/users/19427338", "pm_score": 0, "selected": false, "text": "from tkinter import *\nimport random\n\nclass Main:\n def __init__(self):\n self.root = Tk()\n #self.root.geometry('900x100')\n\n\n def run(self):\n self.variables()\n self.interface()\n self.root.mainloop()\n\n\n def variables(self):\n self.PHOTO_COUNTER = 0\n\n self.photo_list = [\n PhotoImage(file=\"icons/bublegum.png\"),\n PhotoImage(file=\"icons/fin.png\"),\n PhotoImage(file=\"icons/jake.png\"),\n PhotoImage(file=\"icons/marcelin.png\"),\n PhotoImage(file=\"icons/navel.png\"),\n PhotoImage(file=\"icons/winter_king.png\"),\n ]\n\n\n\n def interface(self):\n self.Buttons = []\n for i in range(10):\n item = random.choice(self.photo_list)\n self.btn = Button(self.root, image=item, command=lambda c=i: self.click(c))\n self.btn.pack(fill=BOTH, expand=1, side=LEFT)\n self.Buttons.append(self.btn)\n \n\n\n def click(self, i):\n btn = self.Buttons[i]\n item = random.choice(self.photo_list)\n btn.config(image=item)\n\n\nA = Main()\nA.run()\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425693/" ]
74,328,050
<p>Error response from daemon: conflict: unable to delete 529072250ccc (cannot be forced) - image is being used by running container 5da200b36c1e</p> <p>How I delete docker image ?</p> <p>docker ps is Nothing.</p> <p>CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES</p> <p>But I can't delete image. Commands I have tried</p> <pre><code>docker kill 5da200b36c1e docker rmi -f 529072250ccc </code></pre> <p>After doing this, the image disappears once but comes back again.</p> <p>Or sometimes the IMAGE does not disappear.</p> <p><a href="https://i.stack.imgur.com/jK7Gw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jK7Gw.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74328127, "author": "Sahan Gunathilaka", "author_id": 10031128, "author_profile": "https://Stackoverflow.com/users/10031128", "pm_score": 2, "selected": false, "text": "docker ps -a" }, { "answer_id": 74328148, "author": "Alez", "author_id": 5317332, "author_profile": "https://Stackoverflow.com/users/5317332", "pm_score": 0, "selected": false, "text": "docker stop 5da200b36c1e\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20396543/" ]
74,328,055
<p>I have a list of map and I want to get the map of specific key for example : video of letter a</p> <pre><code>List&lt;Map&lt;String, String&gt;&gt; letters = const [ { 'letter': 'a', 'name' : 'ddd', 'video' : 'ss', }, { 'letter': 'b', 'name' : 'ddd', 'video' : 'ss', }, { 'letter': 'c, 'name' : 'ddd', 'video' : 'ss', }, ] </code></pre>
[ { "answer_id": 74328171, "author": "Krish Bhanushali", "author_id": 13220817, "author_profile": "https://Stackoverflow.com/users/13220817", "pm_score": 3, "selected": true, "text": "List listWithVideo = letters.where((element) => element['letter'] == 'a').toList();\n" }, { "answer_id": 74328214, "author": "Terminator", "author_id": 17563478, "author_profile": "https://Stackoverflow.com/users/17563478", "pm_score": 0, "selected": false, "text": "int search (String letter){\n int index=0;\n for ( var i=0 ; i<list.length;i++ )\n {\n if (list[i]['letter']==letter){\n index=i;\n }\n }\n return index;\n}\n" }, { "answer_id": 74328240, "author": "Irfan Ganatra", "author_id": 18817235, "author_profile": "https://Stackoverflow.com/users/18817235", "pm_score": 1, "selected": false, "text": "\nvoid main() {\n List<Map<String, String>> letters = const [\n {\n 'letter': 'a',\n 'name': 'ddd',\n 'video': 'ss',\n\n }\n ,\n{\n 'letter': 'b',\n 'name' : 'ddd',\n 'video' : 'ss',\n\n },\n {\n 'letter': 'c',\n 'name' : 'ddd',\n 'video' : 'ss',\n\n },\n ];\n\n\n\n Map<String,dynamic> lst=letters.firstWhere((element) {\n\n return element['letter']=='a';\n });\n\n print(lst['video']);\n\n\n\n}\n" }, { "answer_id": 74328253, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 1, "selected": false, "text": "Map<String, dynamic> getAMap() {\n var list = letters.where((element) => element[\"letter\"] == \"a\").toList();\n return list.isNotEmpty ? list.first : {};\n }\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17563478/" ]
74,328,078
<p>So, I have been trying to implement the following:</p> <pre><code>from abc import ABC from abc import abstractmethod class parent(ABC): @property @abstractmethod def example_variable(self)-&gt;str: ... @abstractmethod def example_method(self)-&gt;int: ... def __init__(self, foo: int): self.foo = foo class child(parent): def example_method(self)-&gt;int: return self.foo + 10 example_variable = f&quot;This is example variable of value {self.example_method()}&quot; if __name__ == &quot;__main__&quot;: example_object = child(59) print(example_object.example_variable) </code></pre> <p>As you can see, I have created an abstract class with an abstract property and method, and I have tried to implement the child class by using the value of an instance variable to compute a simple value and using that value to set the value of a property using an F string.</p> <p>But the difficulty is that the interpreter for some reason does not recognise the self reference for the <code>example_method()</code>:</p> <pre><code>--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [7], line 17 14 def __init__(self, foo: int): 15 self.foo = foo ---&gt; 17 class child(parent): 18 def example_method(self)-&gt;int: 19 return self.foo + 10 Cell In [7], line 21, in child() 18 def example_method(self)-&gt;int: 19 return self.foo + 10 ---&gt; 21 example_variable = f&quot;This is example variable of value {self.example_method()}&quot; NameError: name 'self' is not defined </code></pre> <p>And I have been trying to figure this out, without success.</p> <p>I tried removing the <code>self</code> reference:</p> <pre><code>example_variable = f&quot;This is example variable of value {example_method()}&quot; </code></pre> <p>But then it throws the error:</p> <pre><code>--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [10], line 17 14 def __init__(self, foo: int): 15 self.foo = foo ---&gt; 17 class child(parent): 18 def example_variable(self)-&gt;int: 19 return self.foo + 10 Cell In [10], line 21, in child() 18 def example_variable(self)-&gt;int: 19 return self.foo + 10 ---&gt; 21 example_variable = f&quot;This is example variable of value {example_method()}&quot; NameError: name 'example_method' is not defined </code></pre> <p>My question is, why doesn't the python interpreter evaluate the self reference correctly? Has the method been not instantiated yet? If so, then what is the correct way to instantiate the <code>example_method()</code>?</p>
[ { "answer_id": 74328171, "author": "Krish Bhanushali", "author_id": 13220817, "author_profile": "https://Stackoverflow.com/users/13220817", "pm_score": 3, "selected": true, "text": "List listWithVideo = letters.where((element) => element['letter'] == 'a').toList();\n" }, { "answer_id": 74328214, "author": "Terminator", "author_id": 17563478, "author_profile": "https://Stackoverflow.com/users/17563478", "pm_score": 0, "selected": false, "text": "int search (String letter){\n int index=0;\n for ( var i=0 ; i<list.length;i++ )\n {\n if (list[i]['letter']==letter){\n index=i;\n }\n }\n return index;\n}\n" }, { "answer_id": 74328240, "author": "Irfan Ganatra", "author_id": 18817235, "author_profile": "https://Stackoverflow.com/users/18817235", "pm_score": 1, "selected": false, "text": "\nvoid main() {\n List<Map<String, String>> letters = const [\n {\n 'letter': 'a',\n 'name': 'ddd',\n 'video': 'ss',\n\n }\n ,\n{\n 'letter': 'b',\n 'name' : 'ddd',\n 'video' : 'ss',\n\n },\n {\n 'letter': 'c',\n 'name' : 'ddd',\n 'video' : 'ss',\n\n },\n ];\n\n\n\n Map<String,dynamic> lst=letters.firstWhere((element) {\n\n return element['letter']=='a';\n });\n\n print(lst['video']);\n\n\n\n}\n" }, { "answer_id": 74328253, "author": "eamirho3ein", "author_id": 10306997, "author_profile": "https://Stackoverflow.com/users/10306997", "pm_score": 1, "selected": false, "text": "Map<String, dynamic> getAMap() {\n var list = letters.where((element) => element[\"letter\"] == \"a\").toList();\n return list.isNotEmpty ? list.first : {};\n }\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19528536/" ]
74,328,096
<p>I have an ASP.NET web app running in an Azure app service.</p> <p>After doing a profiler trace, I noticed these three .NET exceptions:</p> <pre><code>Requested value 'Asc' was not found. Asc is not a valid value for SortOrder. The parameter conversion from type 'System.String' to type 'Enums.SortOrder' failed. See the inner exception for more information. </code></pre> <p>They all have this stack trace:</p> <pre><code>mscorlib.ni![COLD] System.Enum+EnumResult.SetFailure mscorlib.ni!System.Enum.Parse system.ni! system.web.http!System.Web.Http.ValueProviders.ValueProviderResult.ConvertSimpleType system.web.http!System.Web.Http.ValueProviders.ValueProviderResult.UnwrapPossibleListType system.web.http!System.Web.Http.ValueProviders.ValueProviderResult.ConvertTo system.web.http!System.Web.Http.ModelBinding.Binders.TypeConverterModelBinder.BindModel system.web.http!System.Web.Http.Controllers.HttpActionContextExtensions.Bind system.web.http!System.Web.Http.ModelBinding.Binders.CompositeModelBinder.BindModel system.web.http!System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync system.web.http!System.Web.Http.Controllers.HttpActionBinding+&lt;ExecuteBindingAsyncCore&gt;d__12.MoveNext mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start system.web.http!System.Web.Http.Controllers.HttpActionBinding.ExecuteBindingAsyncCore system.web.http!System.Web.Http.Controllers.HttpActionBinding.ExecuteBindingAsync system.web.http!System.Web.Http.Controllers.ActionFilterResult+&lt;ExecuteAsync&gt;d__5.MoveNext mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[System.__Canon].Start system.web.http!System.Web.Http.Controllers.ActionFilterResult.ExecuteAsync system.web.http!System.Web.Http.ApiController.ExecuteAsync system.web.http!System.Web.Http.Dispatcher.HttpControllerDispatcher+&lt;SendAsync&gt;d__15.MoveNext mscorlib!System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[System.__Canon].Start system.web.http!System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync system.net.http.ni! system.web.http!System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync system.net.http.ni! autofac.integration.webapi!Autofac.Integration.WebApi.CurrentRequestHandler.SendAsync system.net.http.ni! Rend.invgen.invoicegateway.api!Rend.invgen.InvoiceGateway.Api.Handlers.RequestResponseLogHandler.SendNextAsync Rend.invgen.invoicegateway.api!Rend.invgen.InvoiceGateway.Api.Handlers.RequestResponseLogHandler+&lt;&gt;c__DisplayClass0_0.&lt;SendAsync&gt;b__0 mscorlib.ni!System.Threading.Tasks.Task.Execute mscorlib.ni!System.Threading.Tasks.Task.ExecutionContextCallback mscorlib.ni!System.Threading.ExecutionContext.Run mscorlib.ni!System.Threading.Tasks.Task.ExecuteWithThreadLocal mscorlib.ni!System.Threading.Tasks.Task.ExecuteEntry mscorlib.ni!System.Threading.Tasks.SynchronizationContextTaskScheduler.PostCallback system.web.ni! mscorlib.ni!System.Threading.Tasks.Task.Execute mscorlib.ni!System.Threading.Tasks.Task.ExecutionContextCallback mscorlib.ni!System.Threading.ExecutionContext.Run mscorlib.ni!System.Threading.Tasks.Task.ExecuteWithThreadLocal mscorlib.ni!System.Threading.Tasks.Task.ExecuteEntry mscorlib.ni!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem mscorlib.ni!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback </code></pre> <p>My action method which is causing this issue looks like this:</p> <pre><code>public async Task&lt;IHttpActionResult&gt; GetAsync(SortOrder sort = SortOrder.Ascending) { // sort something } </code></pre> <p>This action method is called using arguments such as <code>Asc</code>.</p> <p>Even though this seems to cause .NET exceptions, the default value of <code>Ascending</code> gets used if it can't bind a value.</p> <p>My question is, why am I unable to view the <code>Requested value Asc was not found</code> exceptions locally?</p> <p>When I run the app locally and pass <code>Asc</code> and <code>Desc</code>, no Exceptions are thrown, and I can't see any Exceptions in the Debug window either.</p>
[ { "answer_id": 74346795, "author": "Tarun Krishna", "author_id": 19931028, "author_profile": "https://Stackoverflow.com/users/19931028", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Data.SqlClient;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Web.Http;\nusing System.Web.Mvc;\n\nnamespace MVC_Sort\n{\n public class ActionModel\n {\n public ActionModel()\n {\n ActionsList = new List<SelectListItem>();\n }\n [Display(Name=\"Names\")]\n public int ActionId { get; set; }\n\n public IEnumerable<SelectListItem> ActionsList { get; set; } \n }\n}\n" }, { "answer_id": 74347073, "author": "Poul Bak", "author_id": 5741643, "author_profile": "https://Stackoverflow.com/users/5741643", "pm_score": 2, "selected": true, "text": "Enum" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2063755/" ]
74,328,101
<p>The table function takes vectors as arguments. For example:</p> <pre><code>table(mtcars$cyl, mtcars$am) 0 1 4 3 8 6 4 3 8 12 2 </code></pre> <p>I tried converting this into a pipeable function by passing data as the first argument and using that inside my function within the table function.</p> <pre><code>tab_fun &lt;- function(data, x, y) { table(data$x, data$y) } </code></pre> <p>But when I run my function, I get this error...</p> <pre><code>tab_fun(mtcars, cyl, am) &lt; table of extent 0 x 0 &gt; </code></pre> <p>I'm trying to figure out what's happening. Is there a way to create a function like this, or are there already functions that do this same thing?</p>
[ { "answer_id": 74346795, "author": "Tarun Krishna", "author_id": 19931028, "author_profile": "https://Stackoverflow.com/users/19931028", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Data.SqlClient;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Web.Http;\nusing System.Web.Mvc;\n\nnamespace MVC_Sort\n{\n public class ActionModel\n {\n public ActionModel()\n {\n ActionsList = new List<SelectListItem>();\n }\n [Display(Name=\"Names\")]\n public int ActionId { get; set; }\n\n public IEnumerable<SelectListItem> ActionsList { get; set; } \n }\n}\n" }, { "answer_id": 74347073, "author": "Poul Bak", "author_id": 5741643, "author_profile": "https://Stackoverflow.com/users/5741643", "pm_score": 2, "selected": true, "text": "Enum" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13874036/" ]
74,328,122
<p>Here from the text of the file I wanted to print the details of the footballer</p> <pre class="lang-py prettyprint-override"><code>from re import findall f = open('soccer_player.txt', &quot;r&quot;) mathces = 0 textin = f.readlines() for line in textin: mathces= int(('').join(findall(r'\d+', line))) if(mathces&gt;50) print (mathces) f.close() </code></pre> <p>How to do?</p> <p>This is the txt file:</p> <pre><code>Brad Ebert,47 Brodie Smith,46 Kade Simpson,46 Luke Shuey,46 Justin Westhoff,46 Nic Naitanui,46 Chad Wingard,462 Jordan Lewis,459 Michael Johnson,459 Hamish Hartlett,458 Steven Motlop,457 Jaeger O'Meara,457 </code></pre>
[ { "answer_id": 74346795, "author": "Tarun Krishna", "author_id": 19931028, "author_profile": "https://Stackoverflow.com/users/19931028", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Data.SqlClient;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Web.Http;\nusing System.Web.Mvc;\n\nnamespace MVC_Sort\n{\n public class ActionModel\n {\n public ActionModel()\n {\n ActionsList = new List<SelectListItem>();\n }\n [Display(Name=\"Names\")]\n public int ActionId { get; set; }\n\n public IEnumerable<SelectListItem> ActionsList { get; set; } \n }\n}\n" }, { "answer_id": 74347073, "author": "Poul Bak", "author_id": 5741643, "author_profile": "https://Stackoverflow.com/users/5741643", "pm_score": 2, "selected": true, "text": "Enum" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20425823/" ]
74,328,163
<p>I am trying to access my image files stored inside <code>storage/app/public/subfolder/</code> using symlink inside <code>/public</code> folder in my Laravel app. Everything works fine in my local setup and also in Jelastic Apache deployment, but it doesn't seem to work in CPanel with LiteSpeed. I am trying to access the files using the link <code>/storage/subfolder/image.png</code> but it is not accessible on CPanel deployment.</p> <p>I tried creating and deleting storage symlink hundreds of times, but it didn't work. Below are few things I tried:</p> <ol> <li>Deleting and creating symlink again and again using <code>php artisan storage:link</code> command.</li> <li>Creating symlink using linux command <code>ln -s ../storage/app/public storage</code> inside public folder.</li> <li>Running <code>Artisan::call('storage:link')</code> using a web route entry.</li> <li>Redeploying and reconfiguring the app several times and creating storage symlink.</li> </ol> <p>In all of these failed attempts I can verify that storage symlink is created every time inside public folder. I can navigate and view files from <code>public/storage/</code> folder using CPanel terminal without any issues but can't access them in the deployed app.</p> <p>I have exact same configuration in Jelastic Apache deployment and in my local deployment and there it is working without any issues.</p> <p><strong>UPDATE:</strong></p> <p>Additionally, I tried creating a <code>storage</code> directly manually inside <code>public</code> folder with the same structure and it worked. But symlink doesn't work.</p> <p><strong>UPDATE 2:</strong> I found below error log while checking error logs from CPanel.</p> <pre><code>2022-11-06 05:07:07.342556 [ERROR] [1669834] [T0] [HTAccess] Failed to open [/home/user/my-project/public/storage/subfolder/.htaccess]: Permission denied </code></pre> <p>There is no <code>.htaccess</code> inside <code>subfolder</code> but it is there in my public folder.</p> <p>What might be the issue?</p>
[ { "answer_id": 74346795, "author": "Tarun Krishna", "author_id": 19931028, "author_profile": "https://Stackoverflow.com/users/19931028", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Data.SqlClient;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Web.Http;\nusing System.Web.Mvc;\n\nnamespace MVC_Sort\n{\n public class ActionModel\n {\n public ActionModel()\n {\n ActionsList = new List<SelectListItem>();\n }\n [Display(Name=\"Names\")]\n public int ActionId { get; set; }\n\n public IEnumerable<SelectListItem> ActionsList { get; set; } \n }\n}\n" }, { "answer_id": 74347073, "author": "Poul Bak", "author_id": 5741643, "author_profile": "https://Stackoverflow.com/users/5741643", "pm_score": 2, "selected": true, "text": "Enum" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10875215/" ]
74,328,175
<p>I'm running Android Studio Dolphin | 2021.3.1 Patch 1 and I get weird artifacts on the emulator's screen, as you can see in the image provided (see bottom righ hand corner).</p> <p>This is just an example. Sometimes, the display is correct, and sometimes it shows black areas, usually in the bottom of the screen, as in the image below.</p> <p>Does anybody know how to fix this?</p> <p><a href="https://i.stack.imgur.com/3Gt9y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Gt9y.png" alt="emulator's screen" /></a></p>
[ { "answer_id": 74346795, "author": "Tarun Krishna", "author_id": 19931028, "author_profile": "https://Stackoverflow.com/users/19931028", "pm_score": 0, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.Data.SqlClient;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing System.Web.Http;\nusing System.Web.Mvc;\n\nnamespace MVC_Sort\n{\n public class ActionModel\n {\n public ActionModel()\n {\n ActionsList = new List<SelectListItem>();\n }\n [Display(Name=\"Names\")]\n public int ActionId { get; set; }\n\n public IEnumerable<SelectListItem> ActionsList { get; set; } \n }\n}\n" }, { "answer_id": 74347073, "author": "Poul Bak", "author_id": 5741643, "author_profile": "https://Stackoverflow.com/users/5741643", "pm_score": 2, "selected": true, "text": "Enum" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298744/" ]
74,328,194
<p>I am fetching YouTube video details based on ID using YouTube API. In the VIDEO details page I want to show the iframe and run the video on my specific page.</p> <p>How can I change the ID in src?</p> <p><strong>src=&quot;https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&quot;</strong></p> <pre><code>&lt;iframe id=&quot;existing-iframe-example&quot; width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&quot; frameborder=&quot;0&quot; style=&quot;border: solid 4px #37474f&quot; &gt;&lt;/iframe&gt; &lt;script type=&quot;text/javascript&quot;&gt; var tag = document.createElement(&quot;script&quot;); tag.id = &quot;iframe-demo&quot;; tag.src = &quot;https://www.youtube.com/iframe_api&quot;; var firstScriptTag = document.getElementsByTagName(&quot;script&quot;)[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubeIframeAPIReady() { player = new YT.Player(&quot;existing-iframe-example&quot;, { events: { onReady: onPlayerReady, onStateChange: onPlayerStateChange, }, }); } function onPlayerReady(event) { document.getElementById(&quot;existing-iframe-example&quot;).style.borderColor = &quot;#FF6D00&quot;; } function changeBorderColor(playerStatus) { var color; if (playerStatus == -1) { color = &quot;#37474F&quot;; // unstarted = gray } else if (playerStatus == 0) { color = &quot;#FFFF00&quot;; // ended = yellow } else if (playerStatus == 1) { color = &quot;#33691E&quot;; // playing = green } else if (playerStatus == 2) { color = &quot;#DD2C00&quot;; // paused = red } else if (playerStatus == 3) { color = &quot;#AA00FF&quot;; // buffering = purple } else if (playerStatus == 5) { color = &quot;#FF6DOO&quot;; // video cued = orange } if (color) { document.getElementById(&quot;existing-iframe-example&quot;).style.borderColor = color; } } function onPlayerStateChange(event) { changeBorderColor(event.data); } &lt;/script&gt; </code></pre>
[ { "answer_id": 74328284, "author": "Mohammad Ali Rony", "author_id": 2773184, "author_profile": "https://Stackoverflow.com/users/2773184", "pm_score": 2, "selected": true, "text": "let id =\"w8LcxY43N5Y\";\n\ndocument.getElementById(\"existing-iframe-example\").src = \"https://www.youtube.com/embed/\"+id;" }, { "answer_id": 74328295, "author": "stephenlcurtis", "author_id": 7518286, "author_profile": "https://Stackoverflow.com/users/7518286", "pm_score": 0, "selected": false, "text": "loadVideoById" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17553216/" ]
74,328,221
<p>It seems a bit like a trivial question, but I am stuck on parsing the end of file EOF using my own island grammar. I am using the new VScode extension btw.</p> <p>I've mostly been using the examples from the basic recipes and have a simple grammar with the following layout rules:</p> <pre><code>layout Whitespace = [\t-\n\r\ ]*; lexical IntegerLiteral = [0-9]+ !&gt;&gt; [0-9]; lexical Comment = &quot;%%&quot; ![\n]* $; </code></pre> <p>Using this, and some rules it parses some simple files, but will give a parse error anytime a file ends in a newline. (newlines in between lines are no problem).</p> <p>Am is missing something obvious?</p> <p>Thanks!</p>
[ { "answer_id": 74328874, "author": "Davy Landman", "author_id": 11098, "author_profile": "https://Stackoverflow.com/users/11098", "pm_score": 2, "selected": false, "text": "lexical A = \"a\";\nlexical B = \"b\";\nlexical C = \"c\";\nsyntax A = A? B? C;\n" }, { "answer_id": 74335313, "author": "Jurgen Vinju", "author_id": 1768565, "author_profile": "https://Stackoverflow.com/users/1768565", "pm_score": 3, "selected": true, "text": "start syntax Islands = Island+;\n\nIslands parseIslands(loc input)\n = parse(#start[Islands], input).top;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11247099/" ]
74,328,237
<p>I'm trying to make a QnA game that will take 5 random questions from a pool of 10 and print them to let the user answer. I have a 2D array to save 10 strings that will be the questions. My work so far:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; void qna(){ int i; char er[10][13]; //10 questions er[0][]=&quot;2+2&quot;; //ans 4 er[1][]=&quot;4-5&quot;; //ans -1 er[2][]=&quot;10*10&quot;; //ans 100 er[3][]=&quot;17*3&quot;; //ans 51 er[4][]=&quot;9/3&quot;; //ans 3 er[5][]=&quot;45+24+35-68&quot;; //ans 36 er[6][]=&quot;4-2&quot;; //ans 2 er[7][]=&quot;592-591&quot;; //ans 1 er[8][]=&quot;8+3&quot;; //ans 11 er[9][]=&quot;9*9&quot;; //answer 81 for(i = 0; i &lt; 10; i++){ //test to see if strings save correctly printf(&quot;%s\n&quot;, er[i]); } } int main() { qna(); return 0; } </code></pre> <p>When I compile the program, I get an error &quot;[Error] expected expression before ']' token&quot; for every line that assigns a string to er. Then I tried this:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; void qna(){ int i; char er[10][13]; //10 questions er[0][13]=&quot;2+2&quot;; //ans 4 er[1][13]=&quot;4-5&quot;; //ans -1 er[2][13]=&quot;10*10&quot;; //ans 100 er[3][13]=&quot;17*3&quot;; //ans 51 er[4][13]=&quot;9/3&quot;; //ans 3 er[5][13]=&quot;45+24+35-68&quot;; //ans 36 er[6][13]=&quot;4-2&quot;; //ans 2 er[7][13]=&quot;592-591&quot;; //ans 1 er[8][13]=&quot;8+3&quot;; //ans 11 er[9][13]=&quot;9*9&quot;; //answer 81 for(i = 0; i &lt; 10; i++){ //test to see if strings save correctly printf(&quot;%s\n&quot;, er[i]); } } int main() { qna(); return 0; } </code></pre> <p>When I run this I get a warning &quot;[Warning] assignment makes integer from pointer without a cast&quot; instead of an error on the same lines as before. The command line window prints weird symbols instead of the strings, and some lines are blank entirely. How do I fix this?</p>
[ { "answer_id": 74328307, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "char* er[] = {\n \"2+2\", //ans 4\n \"4-5\", //ans -1\n \"10*10\", //ans 100\n \"17*3\", //ans 51\n \"9/3\", //ans 3\n \"45+24+35-68\", //ans 36\n \"4-2\", //ans 2\n \"592-591\", //ans 1\n \"8+3\", //ans 11\n \"9*9\" //answer 81\n};\n" }, { "answer_id": 74328318, "author": "azhen7", "author_id": 20341797, "author_profile": "https://Stackoverflow.com/users/20341797", "pm_score": 0, "selected": false, "text": "strcpy(er[0], \"2+2\");\nstrcpy(er[1], \"4-5\");\n//etc.\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15207869/" ]
74,328,254
<p>How do i create an array where deconstructed or deleted objects are saved in. I wrote the code below but it doesnt work.The goal is to add usernames of deconstructed users into the array deletedUsers.</p> <pre><code>//Class User class User { //User attributes public $firstname; public $lastname; protected $username; protected $registerdate; public $deletedUsers = array(); //Constructor public function __construct($firstname, $lastname) { $this-&gt;firstname = $firstname; $this-&gt;lastname = $lastname; $this-&gt;username = &quot;$firstname.$lastname&quot; . rand(1, 100); $this-&gt;registrdate = date(&quot;d.m.Y&quot;); } public function __destruct() { $this-&gt;deletedUsers[] = $this-&gt;username; return implode(&quot;, &quot;, $this-&gt;deletedUsers); echo &quot;User has been deleted&quot;; } public function getInfo() { return $this-&gt;firstname . &quot; &quot; . $this-&gt;lastname . &quot; &quot; . $this-&gt;username . &quot; &quot; . $this-&gt;registredate; } public function getDeletedUsers() { $dUsers = implode(&quot;, &quot;, $this-&gt;deletedUsers); return $dUsers; } } $user1 = new User(&quot;John&quot;, &quot;Smith&quot;); echo $iser1-&gt;getInfo(); echo &quot;&lt;br&gt;&quot;; unset($user1); echo $user1-&gt;getDeletedUsers(); </code></pre>
[ { "answer_id": 74328307, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "char* er[] = {\n \"2+2\", //ans 4\n \"4-5\", //ans -1\n \"10*10\", //ans 100\n \"17*3\", //ans 51\n \"9/3\", //ans 3\n \"45+24+35-68\", //ans 36\n \"4-2\", //ans 2\n \"592-591\", //ans 1\n \"8+3\", //ans 11\n \"9*9\" //answer 81\n};\n" }, { "answer_id": 74328318, "author": "azhen7", "author_id": 20341797, "author_profile": "https://Stackoverflow.com/users/20341797", "pm_score": 0, "selected": false, "text": "strcpy(er[0], \"2+2\");\nstrcpy(er[1], \"4-5\");\n//etc.\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17352121/" ]
74,328,260
<p>I want the red border line to fit around the canvas the way it is. Currently there is all that white space that is preventing that from occurring.</p> <p>What part of the code is responsible for that?</p> <p>That is all I am trying to do, remove the white space from around the canvas.</p> <p>code <a href="https://jsfiddle.net/c1bqhde2/" rel="nofollow noreferrer">https://jsfiddle.net/c1bqhde2/</a></p> <p>I don't know how to do this</p> <p>How do you get rid of all that white space that is inside the red border box?</p> <p>I am trying to do this: <a href="https://i.stack.imgur.com/SAX47.png" rel="nofollow noreferrer">Image</a></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>let s = document.createElement("canvas"); s.width = s.height = 512; let sun = s.getContext("2d"); let canvas = document.getElementById("c"); canvas.width = canvas.height = 512; let ctx = canvas.getContext("2d"); let gradient = sun.createLinearGradient(0, 50, 0, canvas.height - 50); gradient.addColorStop(0, '#fbf120ff'); gradient.addColorStop(0.355, "#fd8227ff"); gradient.addColorStop(0.356, "#fd822700"); gradient.addColorStop(0.364, "#fd822700"); gradient.addColorStop(0.365, "#fd8227ff"); gradient.addColorStop(0.42, "#fe6828ff"); gradient.addColorStop(0.421, "#fe682800"); gradient.addColorStop(0.434, "#fe682800"); gradient.addColorStop(0.435, "#fe6828ff"); gradient.addColorStop(0.49, "#fe5430ff"); gradient.addColorStop(0.491, "#fe543000"); gradient.addColorStop(0.509, "#fe543000"); gradient.addColorStop(0.51, "#fe5430ff"); gradient.addColorStop(0.562, "#fe4b38ff"); gradient.addColorStop(0.563, "#fe4b3800"); gradient.addColorStop(0.582, "#fe4b3800"); gradient.addColorStop(0.584, "#fe4b38ff"); //64 -- fe3446 gradient.addColorStop(0.63, "#fe3446ff"); gradient.addColorStop(0.631, "#fe344600"); gradient.addColorStop(0.657, "#fe344600"); gradient.addColorStop(0.658, "#fe3446ff"); //73 -- fe2558 gradient.addColorStop(0.710, "#fe2558ff"); gradient.addColorStop(0.711, "#fe255800"); gradient.addColorStop(0.739, "#fe255800"); gradient.addColorStop(0.74, "#fe2558ff"); //80 -- fe1f5f gradient.addColorStop(0.785, "#fe1f5fff"); gradient.addColorStop(0.786, "#fe1f5f00"); gradient.addColorStop(0.825, "#fe1f5f00"); gradient.addColorStop(0.826, "#fe1f5fff"); //87 -- fe1967 gradient.addColorStop(0.860, "#fe1967ff"); gradient.addColorStop(0.861, "#fe196700"); gradient.addColorStop(0.905, "#fe196700"); gradient.addColorStop(0.906, "#fe1967ff"); //94 -- ff1270 gradient.addColorStop(.940, '#ff1270ff'); gradient.addColorStop(.941, '#ff127000'); sun.fillStyle = gradient; sun.beginPath(); sun.arc(canvas.height / 2, canvas.height / 2, 206, 0, 2 * Math.PI); sun.fill(); //ctx.shadowColor = '#ff0d77af'; //ctx.shadowBlur = 50; ctx.drawImage(s, 0, 0);</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { background-color: white; } #c { border: 1px solid red; } .container { display: flex; align-items: center; justify-content: center; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt; &lt;canvas width="512" height="512" id=c&gt;&lt;/canvas&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74328307, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "char* er[] = {\n \"2+2\", //ans 4\n \"4-5\", //ans -1\n \"10*10\", //ans 100\n \"17*3\", //ans 51\n \"9/3\", //ans 3\n \"45+24+35-68\", //ans 36\n \"4-2\", //ans 2\n \"592-591\", //ans 1\n \"8+3\", //ans 11\n \"9*9\" //answer 81\n};\n" }, { "answer_id": 74328318, "author": "azhen7", "author_id": 20341797, "author_profile": "https://Stackoverflow.com/users/20341797", "pm_score": 0, "selected": false, "text": "strcpy(er[0], \"2+2\");\nstrcpy(er[1], \"4-5\");\n//etc.\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17631451/" ]
74,328,286
<p>recently, I'm working on the asp.net c# framework, I had a problem with the insert query but I can't see the parser error it shows a blank page. That's why I can't figure out the problem with my code. here it's my code and my web.config file.</p> <p>web.config file:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=169433 --&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation targetFramework=&quot;4.7.2&quot; /&gt; &lt;!-- ******************** --&gt; &lt;/system.web&gt; &lt;system.codedom&gt; &lt;compilers&gt; &lt;compiler extension=&quot;.cs&quot; language=&quot;c#;cs;csharp&quot; warningLevel=&quot;4&quot; compilerOptions=&quot;/langversion:7.3 /nowarn:1659;1699;1701;612;618&quot; type=&quot;Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; /&gt; &lt;compiler extension=&quot;.vb&quot; language=&quot;vb;vbs;visualbasic;vbscript&quot; warningLevel=&quot;4&quot; compilerOptions=&quot;/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&amp;quot;Web\&amp;quot; /optionInfer+&quot; type=&quot;Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; /&gt; &lt;/compilers&gt; &lt;/system.codedom&gt; &lt;/configuration&gt; </code></pre> <p>the code of insert query:</p> <pre><code>sql = &quot;INSERT INTO [transaction] (employeeName, receivedDate, recipient, senderParty, receivedParty, tranNum, email, status, userID)&quot; + &quot;values (@employName, @recDate, @recipientName, @sendName, @recName, @tranNumber, @employEmail, @stat, @id)&quot;; //Response.Write(reciveDate.Value); //Response.Write(empEmail); using (SqlCommand cmd = new SqlCommand(sql, conn)) { if (conn.State == ConnectionState.Closed) conn.Open(); cmd.Parameters.AddWithValue(&quot;@employName&quot;, employeeName); cmd.Parameters.AddWithValue(&quot;@recDate&quot;, reciveDate.Value); cmd.Parameters.AddWithValue(&quot;@recipientName&quot;, reciever.Value); ; cmd.Parameters.AddWithValue(&quot;@sendName&quot;, senderAdress.Value); cmd.Parameters.AddWithValue(&quot;@recName&quot;, recieverAdress.Value); cmd.Parameters.AddWithValue(&quot;@tranNumber&quot;, Convert.ToInt32(tranID.Value)); cmd.Parameters.AddWithValue(&quot;@employEmail&quot;, empEmail); cmd.Parameters.AddWithValue(&quot;@stat&quot;, &quot;p&quot;); cmd.Parameters.AddWithValue(&quot;@id&quot;, empID); a = cmd.ExecuteNonQuery(); } </code></pre> <p>I tried to insert data into the Microsoft SQL Management server, but it didn't work and I can't see the parser error.</p> <p>How I can display the parser error?</p> <p>please help me, thanks</p>
[ { "answer_id": 74328307, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "char* er[] = {\n \"2+2\", //ans 4\n \"4-5\", //ans -1\n \"10*10\", //ans 100\n \"17*3\", //ans 51\n \"9/3\", //ans 3\n \"45+24+35-68\", //ans 36\n \"4-2\", //ans 2\n \"592-591\", //ans 1\n \"8+3\", //ans 11\n \"9*9\" //answer 81\n};\n" }, { "answer_id": 74328318, "author": "azhen7", "author_id": 20341797, "author_profile": "https://Stackoverflow.com/users/20341797", "pm_score": 0, "selected": false, "text": "strcpy(er[0], \"2+2\");\nstrcpy(er[1], \"4-5\");\n//etc.\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12269856/" ]
74,328,311
<p>Filter dates that have not passed</p> <pre class="lang-py prettyprint-override"><code>class Distributor(models.Model): expire_at = models.DateTimeField() </code></pre> <p>I want to get the data that has not expired</p>
[ { "answer_id": 74328331, "author": "Faisal Nazik", "author_id": 13959139, "author_profile": "https://Stackoverflow.com/users/13959139", "pm_score": 0, "selected": false, "text": "expire_at" }, { "answer_id": 74328385, "author": "Javad", "author_id": 11833435, "author_profile": "https://Stackoverflow.com/users/11833435", "pm_score": 2, "selected": true, "text": "from datetime import datetime\n\n\ndesired_query = Distributor.objects.filter(expire_at__gt=datetime.now())\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14768266/" ]
74,328,317
<p>I wanna know is it possible to find element using xpath for part of class name value? I mean sometimes one element have many classes like below:</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;p class="SnippetBodyStyles__MainInfo-sc-1asbgpf-4 fBmSdW"&gt;bla bla bla&lt;/p&gt;</code></pre> </div> </div> </p> <p>and i want to find element by one of this class.</p> <p>So tag p relate to two classes:</p> <ol> <li>SnippetBodyStyles__MainInfo-sc-1asbgpf-4</li> <li>fBmSdW</li> </ol> <p>Is it possible to find p tag using this xpath like <a href="https://stackoverflow.com/a/5075279/15637940">text contains</a>:</p> <pre><code>p[@class[text(),[contains(,&quot;fBmSdW&quot;)]]] </code></pre> <p>?</p>
[ { "answer_id": 74328340, "author": "Fazlul", "author_id": 12848411, "author_profile": "https://Stackoverflow.com/users/12848411", "pm_score": 3, "selected": true, "text": "//p[contains(@class,\"fBmSdW\")]\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15637940/" ]
74,328,319
<p>For my assessment I have to obtain such result from mysql database:</p> <pre><code>+---------------------------------------+---------------------------------------+-------+ | name | name | item | +---------------------------------------+---------------------------------------+-------+ | Krispy Kreme - Edinburgh Lothian Road | 6 Assorted Doughnuts | 12.95 | | Krispy Kreme - Edinburgh Lothian Road | Original Glazed Dozen | 14.95 | | Krispy Kreme - Edinburgh Lothian Road | Original Glazed Double Dozen | 23.95 | | Krispy Kreme - Edinburgh Lothian Road | Sharer Dozen | 17.95 | | Krispy Kreme - Edinburgh Lothian Road | Original Glazed &amp; Sharer Double Dozen | 24.95 | | Krispy Kreme - Edinburgh Lothian Road | Sharer Double Dozen | 27.95 | +---------------------------------------+---------------------------------------+-------+ </code></pre> <p>Show the name and delivery menu item for the restaurant where everything costs more than £10.</p> <ul> <li>that's the question.</li> </ul> <p>I've tried this</p> <pre><code>SELECT restaurant.name AS &quot;restaurant name&quot;, food_item.name AS &quot;item name&quot;, food_item.price AS &quot;item price&quot; FROM restaurant JOIN food_item ON restaurant.id = food_item.restaurant_id AND food_item.price WHERE food_item.price &gt; 10; </code></pre> <p>but I receive all the items that cost more than 10, but I need to receive the answer mentioned above, without specifying the name. I have to exclude all the restaurants that has positions in their menu that cost less than 10.</p> <p>ERD is attached</p>
[ { "answer_id": 74328340, "author": "Fazlul", "author_id": 12848411, "author_profile": "https://Stackoverflow.com/users/12848411", "pm_score": 3, "selected": true, "text": "//p[contains(@class,\"fBmSdW\")]\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18734413/" ]
74,328,334
<p>I subtracted two dates in excel and forma the difference as hh:mm:ss and showing correctli in excel file , however while importing it changes to 1904-01-21 03:18:35 .</p> <p>how can get back time only from this in R</p> <p>needs accuaate time as needed</p>
[ { "answer_id": 74328340, "author": "Fazlul", "author_id": 12848411, "author_profile": "https://Stackoverflow.com/users/12848411", "pm_score": 3, "selected": true, "text": "//p[contains(@class,\"fBmSdW\")]\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19350328/" ]
74,328,343
<pre><code>const text = 'hey : &quot;bob &quot; Hey Hello' text.replace(' &quot;', '&quot;').replace('&quot; ', '&quot;') // expect result 'hey :&quot;bob&quot;Hey Hello' </code></pre> <p>how to replace this whitespace before and after (&quot;)</p>
[ { "answer_id": 74328340, "author": "Fazlul", "author_id": 12848411, "author_profile": "https://Stackoverflow.com/users/12848411", "pm_score": 3, "selected": true, "text": "//p[contains(@class,\"fBmSdW\")]\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5884995/" ]
74,328,349
<p>I have an array with child array and I want to concat items from <code>data</code> to new array like below. How I can do it?</p> <p>Example:</p> <pre><code>[ { &quot;title&quot;: &quot;Javascript 1&quot;, &quot;data&quot;: [ { &quot;text&quot;: &quot;hello world 1&quot; }, { &quot;text&quot;: &quot;hello world 2&quot; }, ] }, { &quot;title&quot;: &quot;Javascript 2&quot;, &quot;data&quot;: [ { &quot;text&quot;: &quot;hello world 3&quot; }, { &quot;text&quot;: &quot;hello world 4&quot; }, ] }, ] </code></pre> <p>The result as expected:</p> <pre><code>[ { &quot;text&quot;: &quot;hello world 1&quot; }, { &quot;text&quot;: &quot;hello world 2&quot; }, { &quot;text&quot;: &quot;hello world 3&quot; }, { &quot;text&quot;: &quot;hello world 4&quot; }, ] </code></pre>
[ { "answer_id": 74328431, "author": "caTS", "author_id": 18244921, "author_profile": "https://Stackoverflow.com/users/18244921", "pm_score": 3, "selected": true, "text": "flatMap" }, { "answer_id": 74328451, "author": "Simon Jacobs", "author_id": 10928439, "author_profile": "https://Stackoverflow.com/users/10928439", "pm_score": 1, "selected": false, "text": "flatMap" }, { "answer_id": 74328936, "author": "Sampat Aheer", "author_id": 10835518, "author_profile": "https://Stackoverflow.com/users/10835518", "pm_score": 0, "selected": false, "text": " let result = [];\n let myarr = [\n {\n \"title\": \"Javascript 1\",\n \"data\": [\n {\n \"text\": \"hello world 1\"\n },\n {\n \"text\": \"hello world 2\"\n },\n ]\n },\n {\n \"title\": \"Javascript 2\",\n \"data\": [\n {\n \"text\": \"hello world 3\"\n },\n {\n \"text\": \"hello world 4\"\n },\n ]\n },\n];\n\nfor(let i=0; i<myarr.length;i++)\n{\nmyarr[i].data.forEach(function(values) {\n result.push(values);\n\n});\n}\nconsole.log(result);\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20206220/" ]
74,328,351
<p>I need to show the results from this column where Product_name column contains 'Documentation' or 'documentation' in a result. The query must return a result regardless of whether the word is in lowercase or uppercase</p> <p><a href="https://i.stack.imgur.com/bjLuY.png" rel="nofollow noreferrer">https://i.stack.imgur.com/bjLuY.png</a></p> <pre><code>SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN FROM PRODUCTS WHERE (PROD_NAME like '%Documentation%' or PROD_NAME like '%DOCUMETATION%') and LENGTH(PROD_NAME) &lt;= 35 order by 2 DESC; </code></pre> <p>I found this solution, any suggestions</p>
[ { "answer_id": 74328398, "author": "OldProgrammer", "author_id": 1745544, "author_profile": "https://Stackoverflow.com/users/1745544", "pm_score": 3, "selected": true, "text": "SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE lower(PROD_NAME) like '%documentation%'\n and LENGTH(PROD_NAME) <= 35\n order by 2 DESC;\n" }, { "answer_id": 74328401, "author": "Ömer Yaman", "author_id": 20126776, "author_profile": "https://Stackoverflow.com/users/20126776", "pm_score": -1, "selected": false, "text": "$setgeneral=$db->prepare(\"SELECT * FROM general where general_id=:general_id\");\n$setgeneral->execute(array('general_id' => 0));\n$getgeneral=$setgeneral->fetch(PDO::FETCH_ASSOC);\n" }, { "answer_id": 74334982, "author": "d r", "author_id": 19023353, "author_profile": "https://Stackoverflow.com/users/19023353", "pm_score": 1, "selected": false, "text": "SELECT PROD_NAME as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE LOWER(PROD_NAME) like '%documentation%'\n -- UPPER(PROD_NAME) like '%DOCUMENTATION%' - instead of LOWER(), you can do it this way too - same result\n And LENGTH(PROD_NAME) <= 35\nORDER BY 2 DESC;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20090021/" ]
74,328,379
<p>i am trying to load yolov7 model ( for the weights which i am trained for my dataset ) but i am get error</p> <pre><code>model = torch.hub.load('yolov7','custom', path='/home/runs/train/yolov7x-custom/weights/best.pt',force_reload=True,source='local') </code></pre> <p><a href="https://i.stack.imgur.com/Uh1Tf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uh1Tf.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74328398, "author": "OldProgrammer", "author_id": 1745544, "author_profile": "https://Stackoverflow.com/users/1745544", "pm_score": 3, "selected": true, "text": "SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE lower(PROD_NAME) like '%documentation%'\n and LENGTH(PROD_NAME) <= 35\n order by 2 DESC;\n" }, { "answer_id": 74328401, "author": "Ömer Yaman", "author_id": 20126776, "author_profile": "https://Stackoverflow.com/users/20126776", "pm_score": -1, "selected": false, "text": "$setgeneral=$db->prepare(\"SELECT * FROM general where general_id=:general_id\");\n$setgeneral->execute(array('general_id' => 0));\n$getgeneral=$setgeneral->fetch(PDO::FETCH_ASSOC);\n" }, { "answer_id": 74334982, "author": "d r", "author_id": 19023353, "author_profile": "https://Stackoverflow.com/users/19023353", "pm_score": 1, "selected": false, "text": "SELECT PROD_NAME as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE LOWER(PROD_NAME) like '%documentation%'\n -- UPPER(PROD_NAME) like '%DOCUMENTATION%' - instead of LOWER(), you can do it this way too - same result\n And LENGTH(PROD_NAME) <= 35\nORDER BY 2 DESC;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20424266/" ]
74,328,400
<p>This belongs to the product landing page project on freecodecamp. I created the header with 'position: fixed', and also nested a navigation bar inside the header.</p> <pre><code>&lt;!--HEADER--&gt; &lt;header id=&quot;header&quot;&gt; &lt;img id=&quot;header-img&quot; src=&quot;https://cdn.freecodecamp.org/testable-projects-fcc/images/product-landing-page-logo.png&quot; alt=&quot;Trombones logo&quot;&gt; &lt;nav id=&quot;nav-bar&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;#features&quot;&gt;Features&lt;/a&gt; &lt;a class=&quot;nav-link&quot; href=&quot;#how-it-works&quot;&gt;How It Works&lt;/a&gt; &lt;a class=&quot;nav-link&quot; href=&quot;#pricing&quot;&gt;Pricing&lt;/a&gt; &lt;/nav&gt; &lt;/header&gt; </code></pre> <pre><code>/*HEADER*/ #header{ position: fixed; top: 0; width: 100%; height: 80px; display: flex; align-items: center; background-color: #f2f2ed; } </code></pre> <pre><code>#nav-bar{ font-family: Lato, sans-serif; display: flex; flex: 3 3 1px; justify-content: flex-end; margin-right: 30px; column-gap: 3%; white-space: nowrap; } </code></pre> <p>When I click the link in the navigation bar, the page would scroll to the corresponding section. The problem is the header would cover part of the section after the link is clicked.</p> <p><a href="https://i.stack.imgur.com/Ni6w3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ni6w3.png" alt="before the link is clicked" /></a></p> <p><a href="https://i.stack.imgur.com/zBry7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zBry7.png" alt="after the link is clicked, the 'Premium Materials' part is covered by the header " /></a></p> <p>How do I change the code so that after clicking the link, the 'Premium Materials' would also be visible on the page and not covered by the header?</p> <p><a href="https://i.stack.imgur.com/5t6Vt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5t6Vt.png" alt="this is what I want" /></a></p>
[ { "answer_id": 74328398, "author": "OldProgrammer", "author_id": 1745544, "author_profile": "https://Stackoverflow.com/users/1745544", "pm_score": 3, "selected": true, "text": "SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE lower(PROD_NAME) like '%documentation%'\n and LENGTH(PROD_NAME) <= 35\n order by 2 DESC;\n" }, { "answer_id": 74328401, "author": "Ömer Yaman", "author_id": 20126776, "author_profile": "https://Stackoverflow.com/users/20126776", "pm_score": -1, "selected": false, "text": "$setgeneral=$db->prepare(\"SELECT * FROM general where general_id=:general_id\");\n$setgeneral->execute(array('general_id' => 0));\n$getgeneral=$setgeneral->fetch(PDO::FETCH_ASSOC);\n" }, { "answer_id": 74334982, "author": "d r", "author_id": 19023353, "author_profile": "https://Stackoverflow.com/users/19023353", "pm_score": 1, "selected": false, "text": "SELECT PROD_NAME as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE LOWER(PROD_NAME) like '%documentation%'\n -- UPPER(PROD_NAME) like '%DOCUMENTATION%' - instead of LOWER(), you can do it this way too - same result\n And LENGTH(PROD_NAME) <= 35\nORDER BY 2 DESC;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19411886/" ]
74,328,402
<p>I'm trying to migrate existing code to try with resource, but not sure how to deal when the closable resources are passed to other methods.</p> <p><em><strong>My main concern</strong></em> is how to prevent the developers from touching the method <code>additionalMethod()</code> from <strong>closing</strong> the resource by mistake?</p> <p>Maybe passing around closeable resources is not a good idea at all.</p> <p><em>Example of the code:</em></p> <pre><code>class SomeClass { void readMethod() { try (Scanner scanner = new Scanner(new File(&quot;test.txt&quot;))) { additionalMethod(scanner); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } } void additionalMethod(Scanner scanner) { while (scanner.hasNext()) { System.out.println(scanner.nextLine()); } // scanner.close() how to ensure no one does this by mistake? } } </code></pre>
[ { "answer_id": 74328398, "author": "OldProgrammer", "author_id": 1745544, "author_profile": "https://Stackoverflow.com/users/1745544", "pm_score": 3, "selected": true, "text": "SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE lower(PROD_NAME) like '%documentation%'\n and LENGTH(PROD_NAME) <= 35\n order by 2 DESC;\n" }, { "answer_id": 74328401, "author": "Ömer Yaman", "author_id": 20126776, "author_profile": "https://Stackoverflow.com/users/20126776", "pm_score": -1, "selected": false, "text": "$setgeneral=$db->prepare(\"SELECT * FROM general where general_id=:general_id\");\n$setgeneral->execute(array('general_id' => 0));\n$getgeneral=$setgeneral->fetch(PDO::FETCH_ASSOC);\n" }, { "answer_id": 74334982, "author": "d r", "author_id": 19023353, "author_profile": "https://Stackoverflow.com/users/19023353", "pm_score": 1, "selected": false, "text": "SELECT PROD_NAME as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN\nFROM PRODUCTS \nWHERE LOWER(PROD_NAME) like '%documentation%'\n -- UPPER(PROD_NAME) like '%DOCUMENTATION%' - instead of LOWER(), you can do it this way too - same result\n And LENGTH(PROD_NAME) <= 35\nORDER BY 2 DESC;\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/838355/" ]
74,328,405
<p>I don't know if this exists but I would like to have the equivalent of <kbd>Shift</kbd>+ <kbd>Alt</kbd> + <kbd>Up</kbd>|<kbd>Down</kbd> which duplicates the line up or down, but horizontally with the text selected.</p> <p>For example, let's consider this program:</p> <pre class="lang-py prettyprint-override"><code>print(&quot;Hello world&quot;) </code></pre> <p>If the selected text is <code>Hello world</code> and I do the shortcut it will give something like:</p> <pre class="lang-py prettyprint-override"><code>print(&quot;Hello worldHello world&quot;) </code></pre> <p>Basically, it would ideally be <kbd>Shift</kbd>+ <kbd>Alt</kbd> + <kbd>Right</kbd>|<kbd>Left</kbd> but this shortcut doesn't do that.</p>
[ { "answer_id": 74329350, "author": "rioV8", "author_id": 9938317, "author_profile": "https://Stackoverflow.com/users/9938317", "pm_score": 0, "selected": false, "text": " {\n \"key\": \"shift+alt+left\",\n \"command\": \"extension.multiCommand.execute\",\n \"args\": { \n \"sequence\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorLeft\",\n \"editor.action.clipboardPasteAction\"\n ]\n }\n },\n {\n \"key\": \"shift+alt+right\",\n \"command\": \"extension.multiCommand.execute\",\n \"args\": { \n \"sequence\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorRight\",\n \"editor.action.clipboardPasteAction\"\n ]\n }\n }\n" }, { "answer_id": 74364917, "author": "Mark", "author_id": 836330, "author_profile": "https://Stackoverflow.com/users/836330", "pm_score": 2, "selected": true, "text": "{\n \"key\": \"shift+alt+right\",\n \"command\": \"findInCurrentFile\",\n \"args\": {\n \"preCommands\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorRight\",\n \"editor.action.clipboardPasteAction\",\n \"cursorHome\" // return cursor to beginning of line\n ],\n \"find\": \"${CLIPBOARD}\",\n \"restrictFind\": \"once\" // refind the clipboard text, use only the first find match\n }\n},\n\n{\n \"key\": \"shift+alt+left\",\n \"command\": \"findInCurrentFile\",\n \"args\": {\n \"preCommands\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorLeft\",\n \"editor.action.clipboardPasteAction\",\n \"cursorHome\"\n ],\n \"find\": \"${CLIPBOARD}\",\n \"restrictFind\": \"once\"\n }\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14300637/" ]
74,328,413
<p>I want to create a flag column that tells whether the values in a certain columns are identical when they are grouped by another column. For example, the data looks like this:</p> <pre><code>ID City Code AB123 London CA1 AB123 New York CA1 CD321 Paris CA1 CD321 Tokyo DW2 </code></pre> <p>I'd like to add a new column that tells whether the values of CODE vary within a group when the data is grouped by ID.</p> <pre><code>ID City Code Flag AB123 London CA1 0 AB123 New York CA1 0 CD321 Paris CA1 1 CD321 Tokyo DW2 1 </code></pre> <p>I tried to assign a row number by using partion by but it simply assins a row number by a group.</p> <pre><code>SELECT ID, City, Code, ROW_NUMBER() OVER (PARTITION BY CODE, ID ORDER BY ID) as Flag FROM table ORDER BY ID </code></pre>
[ { "answer_id": 74329350, "author": "rioV8", "author_id": 9938317, "author_profile": "https://Stackoverflow.com/users/9938317", "pm_score": 0, "selected": false, "text": " {\n \"key\": \"shift+alt+left\",\n \"command\": \"extension.multiCommand.execute\",\n \"args\": { \n \"sequence\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorLeft\",\n \"editor.action.clipboardPasteAction\"\n ]\n }\n },\n {\n \"key\": \"shift+alt+right\",\n \"command\": \"extension.multiCommand.execute\",\n \"args\": { \n \"sequence\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorRight\",\n \"editor.action.clipboardPasteAction\"\n ]\n }\n }\n" }, { "answer_id": 74364917, "author": "Mark", "author_id": 836330, "author_profile": "https://Stackoverflow.com/users/836330", "pm_score": 2, "selected": true, "text": "{\n \"key\": \"shift+alt+right\",\n \"command\": \"findInCurrentFile\",\n \"args\": {\n \"preCommands\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorRight\",\n \"editor.action.clipboardPasteAction\",\n \"cursorHome\" // return cursor to beginning of line\n ],\n \"find\": \"${CLIPBOARD}\",\n \"restrictFind\": \"once\" // refind the clipboard text, use only the first find match\n }\n},\n\n{\n \"key\": \"shift+alt+left\",\n \"command\": \"findInCurrentFile\",\n \"args\": {\n \"preCommands\": [\n \"editor.action.clipboardCopyAction\",\n \"cursorLeft\",\n \"editor.action.clipboardPasteAction\",\n \"cursorHome\"\n ],\n \"find\": \"${CLIPBOARD}\",\n \"restrictFind\": \"once\"\n }\n}\n" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17670715/" ]
74,328,469
<p>I have some recipe cards, and I want to make it so only 3 show on one line before it continues on the line below, and so that the container is centered to the page. Heres what I have:</p> <p><a href="https://i.stack.imgur.com/Jb9ho.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jb9ho.png" alt="enter image description here" /></a></p> <p>Here's my code:</p> <pre><code> &lt;div class=&quot;recipe-container&quot;&gt; &lt;div class=&quot;recipe-window&quot;&gt; &lt;a href=&quot;https://www.bbcgoodfood.com/recipes/easy-millionaires-shortbread&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://images.immediate.co.uk/production/volatile/sites/30/2020/08/millionaires-shortbread-52587dd.jpg?quality=90&amp;webp=true&amp;resize=300,272&quot;&gt;&lt;/a&gt; &lt;p class=&quot;recipe-title&quot;&gt;Millionare's Shortbread&lt;/p&gt; &lt;/div&gt; &lt;div class=&quot;recipe-window&quot;&gt; &lt;a href=&quot;https://www.bbcgoodfood.com/recipes/classic-white-loaf&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-559666_11-b53071d.jpg?quality=90&amp;webp=true&amp;resize=300,272&quot;&gt;&lt;/a&gt; &lt;p class=&quot;recipe-title&quot;&gt;Classic White Loaf&lt;/p&gt; &lt;/div&gt; &lt;div class=&quot;recipe-window&quot;&gt; &lt;a href=&quot;https://www.bbcgoodfood.com/recipes/classic-white-loaf&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-1043451_11-4713959.jpg?quality=90&amp;webp=true&amp;resize=300,272&quot;&gt;&lt;/a&gt; &lt;p class=&quot;recipe-title&quot;&gt;Ultimate Chocolate Cake&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; .recipe-container { margin: 0px; padding: 10px; display: inline-flex; } .recipe-window { margin: 10px; padding: 10px; border: 1px solid #ffffff; background-color: #ffffff; word-break: break-word; width: min-content; } .recipe-title { color: black; margin-top: 5px; padding: 0px; font-size: 25px; } </code></pre> <p>How can I achive this?</p>
[ { "answer_id": 74328548, "author": "Anh Le Hoang", "author_id": 16315750, "author_profile": "https://Stackoverflow.com/users/16315750", "pm_score": 1, "selected": false, "text": "display: flex;" }, { "answer_id": 74328600, "author": "Jericho", "author_id": 12033989, "author_profile": "https://Stackoverflow.com/users/12033989", "pm_score": 0, "selected": false, "text": "display: grid;" } ]
2022/11/05
[ "https://Stackoverflow.com/questions/74328469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20197071/" ]