qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,447,805
<p>I'm trying to retrive a <strong>float value</strong> from a SQL Server database <strong>into a double variable</strong>, I'm using this code:</p> <pre><code>bool CDataAccess::GetValue(UINT col, double&amp; value) { int retCode = SQLGetData(m_hstmt, col, SQL_C_DOUBLE, &amp;value, 0, &amp;m_cbValue); ... } </code></pre> <p>That code was working fine until last week when Windows update KB5019959 was installed; if I uninstall this update everything works fine again.</p> <p>If I use SQL_C_FLOAT as parameter or change column type to double, it works, but that change will carry a hugh refactor...</p>
[ { "answer_id": 74448071, "author": "Julio César Estravis", "author_id": 20121447, "author_profile": "https://Stackoverflow.com/users/20121447", "pm_score": 0, "selected": false, "text": "http\n .authorizeExchange((exchanges) ->\n exchanges\n .pathMatchers(\"/openapi/openapi.yml\").permitAll()\n .anyExchange().authenticated())\n .httpBasic();\n\nreturn http.build();\n" }, { "answer_id": 74674241, "author": "Sharofiddin", "author_id": 5862485, "author_profile": "https://Stackoverflow.com/users/5862485", "pm_score": 0, "selected": false, "text": " http.securityMatcher(\"<patterns>\")...\n" }, { "answer_id": 74674354, "author": "James Grey", "author_id": 3728901, "author_profile": "https://Stackoverflow.com/users/3728901", "pm_score": 0, "selected": false, "text": " @Bean\n public SecurityFilterChain configure(HttpSecurity http) throws Exception {\n http\n .authorizeHttpRequests((requests) -> requests\n .requestMatchers(new AntPathRequestMatcher(\"/openapi/openapi.yml\")).permitAll()\n .anyRequest().authenticated())\n .httpBasic();\n return http.build();\n }\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20510540/" ]
74,447,822
<p>I'm trying to print all maximum values</p> <p>so, if the text looks like</p> <p>'''</p> <p>name1 job1 9500.<br /> name2 job2 9500.<br /> name3 job3 4500.</p> <p>'''</p> <p>I want to print it like</p> <p>'''</p> <pre><code>job: job1, sal: 9500 job: job2, sal: 9500 </code></pre> <p>''''</p> <p>so far, my code is</p> <p>'''</p> <pre><code> BEGIN {a=0} {if ($3&gt; a) max=$3; output=$2 } END{ print &quot;job: &quot;, output, &quot;sal:&quot;, max} </code></pre> <p>'''</p> <p>and the output I'm getting is</p> <p>'''</p> <pre><code>job: job2, sal: 9500 </code></pre> <p>'''</p>
[ { "answer_id": 74448071, "author": "Julio César Estravis", "author_id": 20121447, "author_profile": "https://Stackoverflow.com/users/20121447", "pm_score": 0, "selected": false, "text": "http\n .authorizeExchange((exchanges) ->\n exchanges\n .pathMatchers(\"/openapi/openapi.yml\").permitAll()\n .anyExchange().authenticated())\n .httpBasic();\n\nreturn http.build();\n" }, { "answer_id": 74674241, "author": "Sharofiddin", "author_id": 5862485, "author_profile": "https://Stackoverflow.com/users/5862485", "pm_score": 0, "selected": false, "text": " http.securityMatcher(\"<patterns>\")...\n" }, { "answer_id": 74674354, "author": "James Grey", "author_id": 3728901, "author_profile": "https://Stackoverflow.com/users/3728901", "pm_score": 0, "selected": false, "text": " @Bean\n public SecurityFilterChain configure(HttpSecurity http) throws Exception {\n http\n .authorizeHttpRequests((requests) -> requests\n .requestMatchers(new AntPathRequestMatcher(\"/openapi/openapi.yml\")).permitAll()\n .anyRequest().authenticated())\n .httpBasic();\n return http.build();\n }\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17522303/" ]
74,447,848
<p>Hi I'm creating a Teams App and im having trouble implementing a DatePicker in one of my screen. My basic test screen:</p> <pre><code>import React from &quot;react&quot;; import DatePicker from &quot;react-datepicker&quot;; import &quot;react-datepicker/dist/react-datepicker.css&quot;; export default function TestScreen() { let [selectedDate, setSelectedDate] = useState(&quot;&quot;); return( &lt;div&gt; &lt;h1&gt;TEST SCREEN&lt;/h1&gt; &lt;div&gt; &lt;DatePicker selected={selectedDate} onChange={date =&gt; setSelectedDate(date)} /&gt; &lt;/div&gt; &lt;/div&gt; ) } </code></pre> <p>the tab component:</p> <pre><code>import React from &quot;react&quot;; // https://fluentsite.z22.web.core.windows.net/quick-start import { Provider, teamsTheme } from &quot;@fluentui/react-northstar&quot;; import { HashRouter as Router, Redirect, Route } from &quot;react-router-dom&quot;; import Tab from &quot;./Tab&quot;; import &quot;./App.css&quot;; import { useTeams } from &quot;@microsoft/teamsfx-react&quot;; import &quot;bootstrap/dist/css/bootstrap.min.css&quot; import TestScreen from &quot;./screens/test&quot;; export default function App() { const { theme } = useTeams({})[0]; return ( &lt;Provider theme={theme || teamsTheme} styles={{ backgroundColor: &quot;#eeeeee&quot; }}&gt; &lt;Router&gt; &lt;TestScreen /&gt; &lt;/Router&gt; &lt;/Provider&gt; ); } </code></pre> <p>[The error I get][1] [1]: https://i.stack.imgur.com/Sc7cX.png</p>
[ { "answer_id": 74448392, "author": "arp", "author_id": 10841628, "author_profile": "https://Stackoverflow.com/users/10841628", "pm_score": 0, "selected": false, "text": "import React, { useState } from \"react\";\nimport DatePicker from \"react-datepicker\";\nimport \"react-datepicker/dist/react-datepicker.css\";\n\nexport default function TestScreen() {\n let [selectedDate, setSelectedDate] = useState(new Date()); \n\n return(\n <div>\n <h1>TEST SCREEN</h1>\n <div>\n <DatePicker \n selected={selectedDate}\n onChange={date => setSelectedDate(date)}\n />\n </div>\n </div> \n )\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14543939/" ]
74,447,890
<p>I have a nice piece of C# code which allows me to import data into a table with less columns than in the SQL table (as the file format is consistently bad).</p> <p>My problem comes when I have a blank entry in a column. The values statement does not pickup an empty column from the csv. And so I receive the error</p> <blockquote> <p>You have more insert columns than values</p> </blockquote> <p>Here is the query printed to a message box...</p> <p><a href="https://i.stack.imgur.com/YmF0a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YmF0a.png" alt="enter image description here" /></a></p> <p>As you can see there is nothing for Crew members 4 to 11, below is the file...</p> <p><a href="https://i.stack.imgur.com/yzgJV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yzgJV.png" alt="enter image description here" /></a></p> <p>Please see my code:</p> <pre><code>SqlConnection ADO_DB_Connection = new SqlConnection(); ADO_DB_Connection = (SqlConnection) (Dts.Connections[&quot;ADO_DB_Connection&quot;].AcquireConnection(Dts.Transaction) as SqlConnection); // Inserting data of file into table int counter = 0; string line; string ColumnList = &quot;&quot;; // MessageBox.Show(fileName); System.IO.StreamReader SourceFile = new System.IO.StreamReader(fileName); while ((line = SourceFile.ReadLine()) != null) { if (counter == 0) { ColumnList = &quot;[&quot; + line.Replace(FileDelimiter, &quot;],[&quot;) + &quot;]&quot;; } else { string query = &quot;Insert into &quot; + TableName + &quot; (&quot; + ColumnList + &quot;) &quot;; query += &quot;VALUES('&quot; + line.Replace(FileDelimiter, &quot;','&quot;) + &quot;')&quot;; // MessageBox.Show(query.ToString()); SqlCommand myCommand1 = new SqlCommand(query, ADO_DB_Connection); myCommand1.ExecuteNonQuery(); } counter++; } </code></pre> <p>If you could advise how to include those fields in the insert that would be great.</p> <p>Here is the same file but opened with a text editor and not given in picture format...</p> <pre><code>Date,Flight_Number,Origin,Destination,STD_Local,STA_Local,STD_UTC,STA_UTC,BLOC,AC_Reg,AC_Type,AdultsPAX,ChildrenPAX,InfantsPAX,TotalPAX,AOC,Crew 1,Crew 2,Crew 3,Crew 4,Crew 5,Crew 6,Crew 7,Crew 8,Crew 9,Crew 10,Crew 11 05/11/2022,241,BOG,SCL,15:34,22:47,20:34,02:47,06:13,N726AV,&quot;AIRBUS A-319 &quot;,0,0,0,36,AV,100612,161910,323227 </code></pre>
[ { "answer_id": 74448392, "author": "arp", "author_id": 10841628, "author_profile": "https://Stackoverflow.com/users/10841628", "pm_score": 0, "selected": false, "text": "import React, { useState } from \"react\";\nimport DatePicker from \"react-datepicker\";\nimport \"react-datepicker/dist/react-datepicker.css\";\n\nexport default function TestScreen() {\n let [selectedDate, setSelectedDate] = useState(new Date()); \n\n return(\n <div>\n <h1>TEST SCREEN</h1>\n <div>\n <DatePicker \n selected={selectedDate}\n onChange={date => setSelectedDate(date)}\n />\n </div>\n </div> \n )\n}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5748138/" ]
74,447,901
<p>I have a Blazor Wasm app with two components:</p> <p>BaseComp.razor:</p> <pre><code>&lt;h1&gt;I'm base - @Text&lt;/h1&gt; @code{ protected string Text {get; set;} = &quot;Default&quot;; } </code></pre> <p>ChildComponent.razor</p> <pre><code>@inherits BaseComp &lt;BaseComp/&gt; &lt;h1&gt;Hello, only child text!&lt;/h1&gt; @code { protected override void OnInitialized() { Text = &quot;new&quot;; } } </code></pre> <p>and on the page the following will be displayed:</p> <pre><code>I'm base - Default Hello, only child text! </code></pre> <p>How could I update the <code>Text</code> property of the baseComponent from the childComponent?</p>
[ { "answer_id": 74448117, "author": "Marvin Klein", "author_id": 13440841, "author_profile": "https://Stackoverflow.com/users/13440841", "pm_score": 1, "selected": false, "text": "<h1>I'm base - @Text</h1>\n\n@code{\n [Parameter] public string Text {get; set;} = \"Default\";\n}\n" }, { "answer_id": 74448329, "author": "Henk", "author_id": 60761, "author_profile": "https://Stackoverflow.com/users/60761", "pm_score": 2, "selected": true, "text": "@inherits BaseComp\n<BaseComp/> @* a new instance, not inheritance *@\n" }, { "answer_id": 74450734, "author": "MrC aka Shaun Curtis", "author_id": 13065781, "author_profile": "https://Stackoverflow.com/users/13065781", "pm_score": 2, "selected": false, "text": "ComponentBase" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11175348/" ]
74,447,926
<p>I'm trying to make my Discord bot kick a member, and send that &quot;user banned because reason&quot; to a specific channel and not the channel the command was used. The code I'm using:</p> <pre><code>@bot.slash_command(description = &quot;Kick someone&quot;, guild_ids=[1041057700823449682]) @commands.has_permissions(kick_members=True) @option(&quot;member&quot;,description = &quot;Select member&quot;) @option(&quot;reason&quot;,description = &quot;Reason for kick (you can leave this empty)&quot;) async def kick( ctx, member: discord.Member, channel: bot.get_channel(1042042492020863037), *, reason=None): if reason==None: reason=&quot;(no reason)&quot; await ctx.guild.kick(member) await ctx.respond(&quot;Done :)&quot;) await ctx.channel.send(f'User {member.mention} was kicked because {reason}') </code></pre> <p>When I try using this code I get a few errors:</p> <pre><code>Traceback (most recent call last): File &quot;c:\Users\fonti\Documents\Projetos Python\Bot do Discord\Iniciar Bot.py&quot;, line 152, in &lt;module&gt; async def kick( File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py&quot;, line 905, in decorator self.add_application_command(result) File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py&quot;, line 127, in add_application_command command._set_cog(None) File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py&quot;, line 603, in _set_cog self.cog = cog File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py&quot;, line 827, in cog self._validate_parameters() File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py&quot;, line 705, in _validate_parameters self.options: list[Option] = self._parse_options(params) File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py&quot;, line 745, in _parse_options option = Option(option) File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\options.py&quot;, line 210, in __init__ self.input_type = SlashCommandOptionType.from_datatype(input_type) File &quot;C:\Users\fonti\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\enums.py&quot;, line 707, in from_datatype if datatype.__name__ in [&quot;Member&quot;, &quot;User&quot;]: AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'? </code></pre> <p>I was trying to send the message...</p> <pre><code>(f'User {member.mention} was kicked because {reason}') </code></pre> <p>to a specific channel. If I remove the channel condition, the bot works, but sends this message to the channel the command was used.</p>
[ { "answer_id": 74448355, "author": "Sam Shields", "author_id": 19261069, "author_profile": "https://Stackoverflow.com/users/19261069", "pm_score": 0, "selected": false, "text": "ctx.channel.send" }, { "answer_id": 74451765, "author": "Im2Slothy", "author_id": 18583851, "author_profile": "https://Stackoverflow.com/users/18583851", "pm_score": 0, "selected": false, "text": "@discord.default_permissions(kick_members = True)\nasync def kick(ctx, member : discord.Member, *, reason=None):\n await member.kick(reason=reason)\n await ctx.respond(f'{member.mention} has been kicked!')\n" }, { "answer_id": 74460356, "author": "Kejax", "author_id": 20059231, "author_profile": "https://Stackoverflow.com/users/20059231", "pm_score": 0, "selected": false, "text": "bot.get_channel()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20417932/" ]
74,447,931
<p>I tried to use sticky to make b_frame take half of a_frame , and c_frame also take half of a_frame. Each frame use half of a_frame. Sum of c_frame and b_frame will use the whole width of a_frame. But it does not work as I expected.</p> <pre><code>a_frame=tk.Frame(frame, highlightbackground=&quot;red&quot;, highlightthickness=2) a_frame.grid(row=3, column=0, sticky=&quot;nsew&quot;, columnspan=2) b_frame = tk.LabelFrame(a_frame, text=&quot;b&quot;) b_frame.grid(row=0, column=0, sticky=&quot;nsw&quot;) c_frame = tk.LabelFrame(a_frame, text=&quot;c&quot;) c_frame.grid(row=0, column=0, sticky=&quot;nse&quot;) d = tk.Entry(b_frame) d.grid(row=0, column=0) e = tk.Entry(e_frame) d.grid(row=0, column=0) </code></pre> <p><a href="https://i.stack.imgur.com/pT6ts.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pT6ts.png" alt="The result" /></a></p>
[ { "answer_id": 74448638, "author": "toyota Supra", "author_id": 4136999, "author_profile": "https://Stackoverflow.com/users/4136999", "pm_score": 0, "selected": false, "text": "import tkinter as tk\nroot= tk.Tk()\n\na_frame=tk.Frame(root, highlightbackground=\"red\",\n highlightthickness=2)\na_frame.grid(row=0, column=0, sticky=\"nw\", columnspan=3)\n\n\nb_frame = tk.LabelFrame(a_frame, text=\"b\")\nb_frame.grid(row=0, column=0, sticky=\"nw\")\n\nc_frame = tk.LabelFrame(a_frame, text=\"c\")\nc_frame.grid(row=0, column=1,sticky=\"nw\")\n\nd = tk.Entry(b_frame)\nd.grid(row=0, column=0, sticky=\"nw\")\n\ne = tk.Entry(c_frame)\ne.grid(row=0, column=1, sticky=\"nw\")\n\nroot.mainloop()\n" }, { "answer_id": 74448907, "author": "acw1668", "author_id": 5317403, "author_profile": "https://Stackoverflow.com/users/5317403", "pm_score": 3, "selected": true, "text": "a_frame.columnconfigure((0,1), weight=1)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10688444/" ]
74,447,936
<p>I made a row and I need to separate its children with space between, but it's not separating. This is the code:</p> <pre><code>Container( height: 51, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container(width: 56, height: 51, child: ImageIcon(AssetImage(&quot;assets/images/treadmill.png&quot;))), SizedBox(width: 20), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: const [ Text( &quot;EQUIPMENT&quot;, style: TextStyle( fontSize: 16, fontFamily: &quot;OpenSans&quot;, fontWeight: FontWeight.w600 ), ), ImageIcon(AssetImage(&quot;assets/icons/delete.png&quot;), color: Colors.red) ], ), Text( &quot;1234567891235896211234E&quot;, style: TextStyle( fontSize: 14, fontFamily: &quot;OpenSans&quot;, fontWeight: FontWeight.normal ), ), ], ) ], ), ), </code></pre> <p>And this is the result: (ignore the &quot;A&quot; in the word) <a href="https://i.stack.imgur.com/zm43L.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zm43L.jpg" alt="imageFront" /></a></p> <p>I tried to put expanded, spacer, but all the attempts gave an error.</p> <p>(I don't want to put SizedBox to make this space because there are several types of cell phone screens)</p> <p>Why does this happen and what to do?</p>
[ { "answer_id": 74448056, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "IntrinsicWidth" }, { "answer_id": 74448191, "author": "jbryanh", "author_id": 13590970, "author_profile": "https://Stackoverflow.com/users/13590970", "pm_score": 0, "selected": false, "text": "Container(\n height: 51,\n child: Row(\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n children: [\n Container(width: 56, height: 51, child: ImageIcon(AssetImage(\"assets/images/treadmill.png\"))),\n SizedBox(width: 20),\n Expanded( \n child: Column(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n Row(\n mainAxisSize: MainAxisSize.max,\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n children: const [\n Expanded(\n child: Text(\n \"EQUIPMENT\",\n style: TextStyle(\n fontSize: 16,\n fontFamily: \"OpenSans\",\n fontWeight: FontWeight.w600\n ),\n ),\n ),\n ImageIcon(AssetImage(\"assets/icons/delete.png\"), color: Colors.red)\n ],\n ),\n Text(\n \"1234567891235896211234E\",\n style: TextStyle(\n fontSize: 14,\n fontFamily: \"OpenSans\",\n fontWeight: FontWeight.normal\n ),\n ),\n ],\n ),\n )\n ],\n ),\n),\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74447936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17863939/" ]
74,448,042
<p>I am a contributor to Wikipedia and I would like to make a script with AutoHotKey that could format the wikicode of infoboxes and other similar templates.</p> <p>Infoboxes are templates that displays a box on the side of articles and shows the values of the parameters entered (they are numerous and they differ in number, lenght and type of characters used depending on the infobox).</p> <p>Parameters are always preceded by a pipe (<code>|</code>) and end with an equal sign (<code>=</code>). On rare occasions, multiple parameters can be put on the same line, but I can sort this manually before running the script.</p> <p>A typical infobox will be like this:</p> <pre><code>{{Infobox XYZ | first parameter = foo | second_parameter = | 3rd parameter = bar | 4th = bazzzzz | 5th = | etc. = }} </code></pre> <p>But sometime, (lazy) contributors put them like this:</p> <pre><code>{{Infobox XYZ |first parameter=foo |second_parameter= |3rd parameter=bar |4th=bazzzzz |5th= |etc.= }} </code></pre> <p>Which isn't very easy to read and modify.</p> <p>I would like to know if it is possible to make a regex (or a serie of regexes) that would transform the second example into the first.</p> <p>The lines should start with a space, then a pipe, then another space, then the parameter name, then <strong>any number of spaces</strong> (to match the other lines lenght), then an equal sign, then another space, and if present, the parameter value.</p> <p>I try some things using multiple capturing groups, but I'm going nowhere... (I'm even ashamed to show my tries as they really don't work).</p> <p>Would someone have an idea on how to make it work?</p> <p>Thank you for your time.</p>
[ { "answer_id": 74448056, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 3, "selected": true, "text": "IntrinsicWidth" }, { "answer_id": 74448191, "author": "jbryanh", "author_id": 13590970, "author_profile": "https://Stackoverflow.com/users/13590970", "pm_score": 0, "selected": false, "text": "Container(\n height: 51,\n child: Row(\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n children: [\n Container(width: 56, height: 51, child: ImageIcon(AssetImage(\"assets/images/treadmill.png\"))),\n SizedBox(width: 20),\n Expanded( \n child: Column(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n Row(\n mainAxisSize: MainAxisSize.max,\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n children: const [\n Expanded(\n child: Text(\n \"EQUIPMENT\",\n style: TextStyle(\n fontSize: 16,\n fontFamily: \"OpenSans\",\n fontWeight: FontWeight.w600\n ),\n ),\n ),\n ImageIcon(AssetImage(\"assets/icons/delete.png\"), color: Colors.red)\n ],\n ),\n Text(\n \"1234567891235896211234E\",\n style: TextStyle(\n fontSize: 14,\n fontFamily: \"OpenSans\",\n fontWeight: FontWeight.normal\n ),\n ),\n ],\n ),\n )\n ],\n ),\n),\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16593368/" ]
74,448,095
<p>I'm developing a tab based application with Ionic Framework (version 5). The following error occurs only when I modify the code and the application is automatically reloaded on a page other than the &quot;home page&quot;.</p> <p><a href="https://i.stack.imgur.com/Wu0fH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wu0fH.png" alt="enter image description here" /></a></p> <p>I have already tried to import the modules <code>CommonModule</code>, <code>FormsModule</code> and <code>IonicModule</code> into the module class of each page but doesn't work, the workaround that makes directives like <code>ngFor</code> work is to reload the application on the home page.</p> <hr /> <p>Specifically this error occurs in the pages <code>new-article</code>:</p> <p><code>src/app/pages/new-article/new-article.page.html</code></p> <pre class="lang-html prettyprint-override"><code> &lt;ion-grid&gt; &lt;ion-row&gt; &lt;ion-col *ngFor=&quot;let url of artcile.photos&quot;&gt;&lt;img [src]=&quot;url&quot;/&gt;&lt;/ion-col&gt; &lt;/ion-row&gt; &lt;/ion-grid&gt; </code></pre> <p><code>src/app/pages/new-article/new-article.module.ts</code></p> <pre class="lang-js prettyprint-override"><code>@NgModule({ imports: [ CommonModule, FormsModule, IonicModule, NewArticlePageRoutingModule ], declarations: [NewArticlePage] }) export class NewArticlePageModule {} </code></pre> <p>As I said before, it's a tab based application, all pages are handled through the routing module: <code>src/app/tabs/tabs-routing.module.ts</code></p> <pre class="lang-js prettyprint-override"><code>const routes: Routes = [ { path: 'tabs', component: TabsPage, children: [ { path: 'home', loadChildren: () =&gt; import('../pages/home/home.module').then(m =&gt; m.HomePageModule) }, ... { path: 'new-article', loadChildren: () =&gt; import('../pages/new-article/new-article-routing.module').then(m =&gt; m.NewArticlePageRoutingModule) }, { path: '', redirectTo: '/tabs/home', pathMatch: 'full' } ] }, { path: '', redirectTo: '/tabs/home', pathMatch: 'full' } ]; </code></pre> <p>If anyone has any suggestions on this I would be grateful.</p> <hr /> <p><strong>UPDATES</strong></p> <p>This error can occur when you import <code>component-routing.module</code> instead of <code>component.module</code> into <code>tabs-routing.module.ts</code>.</p>
[ { "answer_id": 74449298, "author": "James Griffin", "author_id": 8661238, "author_profile": "https://Stackoverflow.com/users/8661238", "pm_score": 0, "selected": false, "text": "tabs-routing.module.ts" }, { "answer_id": 74451512, "author": "Anton Marinenko", "author_id": 11248646, "author_profile": "https://Stackoverflow.com/users/11248646", "pm_score": 1, "selected": false, "text": " {\n path: 'new-article',\n loadChildren: () => import('../pages/new-article/new-article.module').then(m => m.NewArticlePageModule)\n },\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3422795/" ]
74,448,100
<p>I'm confused as to how exactly I would make 9 random numbers add to whatever number the user may input. Let's say the user inputs &quot;200&quot; as the number, how do I make it so that I could get 9 random numbers add up exactly to 200?</p> <p>Obviously, the code below doesn't work the way I want it to because it's literally just 9 random numbers that don't add up to a specific number. I just have no idea how to get this built properly.</p> <pre><code>public static void RandomStats() { Random RandomClass = new Random(); int[] intRandomStats = { RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101), RandomClass.Next(0, 101) }; // ... } </code></pre>
[ { "answer_id": 74448235, "author": "MakePeaceGreatAgain", "author_id": 2528063, "author_profile": "https://Stackoverflow.com/users/2528063", "pm_score": 1, "selected": false, "text": "int theSum = 200;\nvar randomNumbers = new int[9];\nfor(int i = 0; i < 8; i)\n{\n randomNumbers[i] = random.Next(0, theSum);\n}\n\nrandomNumbers[8] = theSum - randomNumbers.Sum();\n" }, { "answer_id": 74448350, "author": "gunr2171", "author_id": 1043380, "author_profile": "https://Stackoverflow.com/users/1043380", "pm_score": 2, "selected": false, "text": "var rand = new Random();\nvar amount = 200;\nvar targetOutputValueCount = 9;\nvar outputValues = new List<int>();\nfor (int i = 1; i < targetOutputValueCount; i++) // 1 less than all groups\n{\n var groupAmount = rand.Next(0, amount);\n amount -= groupAmount;\n outputValues.Add(groupAmount);\n}\n\n// for the last group, it's whatever is left over\noutputValues.Add(amount);\n\nforeach (var outputValue in outputValues)\n{\n Console.WriteLine(outputValue);\n}\n" }, { "answer_id": 74448930, "author": "Olivier Jacot-Descombes", "author_id": 880990, "author_profile": "https://Stackoverflow.com/users/880990", "pm_score": 1, "selected": false, "text": "var random = new Random();\nvar randomNumbers = new int[9];\nint input = 200;\nint optimalRange = 2 * input / randomNumbers.Length;\nint iterations = 0;\ndo {\n for (int i = 0; i < randomNumbers.Length; i++) {\n randomNumbers[i] = random.Next(optimalRange);\n }\n iterations++;\n} while (randomNumbers.Sum() != input);\n\nConsole.WriteLine($\"iterations = {iterations}\");\nConsole.WriteLine($\"numbers = {String.Join(\", \", randomNumbers)}\");\n" }, { "answer_id": 74449280, "author": "DrPhil", "author_id": 4527934, "author_profile": "https://Stackoverflow.com/users/4527934", "pm_score": 3, "selected": false, "text": "Sample" }, { "answer_id": 74449418, "author": "r3mainer", "author_id": 1679849, "author_profile": "https://Stackoverflow.com/users/1679849", "pm_score": 1, "selected": false, "text": "n" }, { "answer_id": 74450471, "author": "Barreto Freekhealer", "author_id": 14694660, "author_profile": "https://Stackoverflow.com/users/14694660", "pm_score": 0, "selected": false, "text": "//run: RandomStats(0,101,200) for your particular example.\npublic static void RandomStats(int min, int max, int total)\n{\n Random randomClass = new Random();\n\n int[] randomStats = new int[9];\n\n int value = 0;\n int totalValue = total;\n bool parsed = false;\n while (!parsed)\n {\n Console.WriteLine(\"Please enter a number:\");\n if (int.TryParse(Console.ReadLine(), out value))\n {\n parsed = true;\n totalValue -= value;\n\n for (int i = 0; i < randomStats.Length-1; i++)\n {\n //option 1\n int remainMax = (int) Math.Floor((float) totalValue / (randomStats.Length - 1 - i));\n int randomValue = randomClass.Next(min, totalValue < max ? remainMax : max); \n //option 2\n //max = (int) Math.Floor((float) totalValue / (randomStats.Length - 1 - i));\n //int randomValue = randomClass.Next(min, max); \n totalValue -= randomValue;\n randomStats[i] = randomValue;\n }\n randomStats[8] = totalValue;\n }\n else\n {\n Console.WriteLine(\"Not a valid input\");\n }\n }\n\n Console.WriteLine($\"min value: {min}\\tmax value: {max}\\ttotal value: {total}\");\n int testValue = value;\n Console.WriteLine(\"Input value - \" + value);\n for (int i = 0; i < randomStats.Length; i++)\n {\n testValue += randomStats[i];\n int randomIndex = i + 1;\n Console.WriteLine(randomIndex + \" Random value - \" + randomStats[i]);\n }\n Console.WriteLine(\"test value - \" + testValue);\n Console.ReadKey();\n}\n" }, { "answer_id": 74453713, "author": "thewallrus", "author_id": 2528735, "author_profile": "https://Stackoverflow.com/users/2528735", "pm_score": 1, "selected": false, "text": "Random rnd = new Random();\nint[] dice = new int[200];\nvar sidesUp = dice.Select(x => rnd.Next(1, 10));\nList<int> randomNumbers = sidesUp.GroupBy(p => p).Select(x => x.Count()).ToList();\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511555/" ]
74,448,113
<p>I need to check the sequence of calling of some methods of a class.</p> <p>I suppose that my production <code>class A</code> is stored in the following file <em>class_a.py</em>:</p> <pre class="lang-py prettyprint-override"><code>class A: __lock = None def __init__(self, lock): self.__lock = lock def method_1(self): self.__lock.acquire() self.__atomic_method_1() self.__lock.release() def __atomic_method_1(self): pass </code></pre> <p>I need to write a unit test that checks the sequence of calling of the methods of the <code>class A</code> when it is invoked the <code>method_1()</code>.</p> <p>The check must verify that <code>method_1()</code> calls:</p> <ol> <li>as first method: <code>self.__lock.acquire()</code></li> <li>after that it calls <code>self.__atomic_method_1()</code></li> <li>and that the last method called is <code>self.__lock.release()</code></li> </ol> <h2>A useful hint but not enough</h2> <p><a href="https://stackoverflow.com/questions/31913232/how-to-unittest-the-sequence-of-function-calls-made-insde-a-fuction-python">This is</a> a very useful link, but it doesn't solve my problem. The solution provided by the link is perfect to verify the calling order of a sequence of functions invoked by an other function. The link shows an example where the function under test and the functions called are all contained in a file called <code>module_under_test</code>.<br /> In my case, however, I have to verify the calling sequence of methods of a class and this difference prevents to use the solution provided by the link.</p> <h2>A trace that starts from the suggestion</h2> <p>However I have tried to develop the unit test referring to <a href="https://stackoverflow.com/questions/31913232/how-to-unittest-the-sequence-of-function-calls-made-insde-a-fuction-python">the link</a> and in this way I have prepared a trace of the test file that I can show below:</p> <pre class="lang-py prettyprint-override"><code>import unittest from unittest import mock from class_a import A import threading class TestCallOrder(unittest.TestCase): def test_call_order(self): # create an instance of the SUT sut = A(threading.Lock()) # prepare the MOCK object source_mock = ... with patch(...) # prepare the expected values expected = [...] # run the code-under-test (method_1()). sut.method_1() # Check the order calling self.assertEqual(expected, source_mock.mock_calls) if __name__ == '__main__': unittest.main() </code></pre> <p>But obviously I'm not able to complete the method <code>test_call_order()</code>.</p> <p>I hope I was clear, but don't hesitate to ask other info about the problem.</p> <p>Thanks</p>
[ { "answer_id": 74448235, "author": "MakePeaceGreatAgain", "author_id": 2528063, "author_profile": "https://Stackoverflow.com/users/2528063", "pm_score": 1, "selected": false, "text": "int theSum = 200;\nvar randomNumbers = new int[9];\nfor(int i = 0; i < 8; i)\n{\n randomNumbers[i] = random.Next(0, theSum);\n}\n\nrandomNumbers[8] = theSum - randomNumbers.Sum();\n" }, { "answer_id": 74448350, "author": "gunr2171", "author_id": 1043380, "author_profile": "https://Stackoverflow.com/users/1043380", "pm_score": 2, "selected": false, "text": "var rand = new Random();\nvar amount = 200;\nvar targetOutputValueCount = 9;\nvar outputValues = new List<int>();\nfor (int i = 1; i < targetOutputValueCount; i++) // 1 less than all groups\n{\n var groupAmount = rand.Next(0, amount);\n amount -= groupAmount;\n outputValues.Add(groupAmount);\n}\n\n// for the last group, it's whatever is left over\noutputValues.Add(amount);\n\nforeach (var outputValue in outputValues)\n{\n Console.WriteLine(outputValue);\n}\n" }, { "answer_id": 74448930, "author": "Olivier Jacot-Descombes", "author_id": 880990, "author_profile": "https://Stackoverflow.com/users/880990", "pm_score": 1, "selected": false, "text": "var random = new Random();\nvar randomNumbers = new int[9];\nint input = 200;\nint optimalRange = 2 * input / randomNumbers.Length;\nint iterations = 0;\ndo {\n for (int i = 0; i < randomNumbers.Length; i++) {\n randomNumbers[i] = random.Next(optimalRange);\n }\n iterations++;\n} while (randomNumbers.Sum() != input);\n\nConsole.WriteLine($\"iterations = {iterations}\");\nConsole.WriteLine($\"numbers = {String.Join(\", \", randomNumbers)}\");\n" }, { "answer_id": 74449280, "author": "DrPhil", "author_id": 4527934, "author_profile": "https://Stackoverflow.com/users/4527934", "pm_score": 3, "selected": false, "text": "Sample" }, { "answer_id": 74449418, "author": "r3mainer", "author_id": 1679849, "author_profile": "https://Stackoverflow.com/users/1679849", "pm_score": 1, "selected": false, "text": "n" }, { "answer_id": 74450471, "author": "Barreto Freekhealer", "author_id": 14694660, "author_profile": "https://Stackoverflow.com/users/14694660", "pm_score": 0, "selected": false, "text": "//run: RandomStats(0,101,200) for your particular example.\npublic static void RandomStats(int min, int max, int total)\n{\n Random randomClass = new Random();\n\n int[] randomStats = new int[9];\n\n int value = 0;\n int totalValue = total;\n bool parsed = false;\n while (!parsed)\n {\n Console.WriteLine(\"Please enter a number:\");\n if (int.TryParse(Console.ReadLine(), out value))\n {\n parsed = true;\n totalValue -= value;\n\n for (int i = 0; i < randomStats.Length-1; i++)\n {\n //option 1\n int remainMax = (int) Math.Floor((float) totalValue / (randomStats.Length - 1 - i));\n int randomValue = randomClass.Next(min, totalValue < max ? remainMax : max); \n //option 2\n //max = (int) Math.Floor((float) totalValue / (randomStats.Length - 1 - i));\n //int randomValue = randomClass.Next(min, max); \n totalValue -= randomValue;\n randomStats[i] = randomValue;\n }\n randomStats[8] = totalValue;\n }\n else\n {\n Console.WriteLine(\"Not a valid input\");\n }\n }\n\n Console.WriteLine($\"min value: {min}\\tmax value: {max}\\ttotal value: {total}\");\n int testValue = value;\n Console.WriteLine(\"Input value - \" + value);\n for (int i = 0; i < randomStats.Length; i++)\n {\n testValue += randomStats[i];\n int randomIndex = i + 1;\n Console.WriteLine(randomIndex + \" Random value - \" + randomStats[i]);\n }\n Console.WriteLine(\"test value - \" + testValue);\n Console.ReadKey();\n}\n" }, { "answer_id": 74453713, "author": "thewallrus", "author_id": 2528735, "author_profile": "https://Stackoverflow.com/users/2528735", "pm_score": 1, "selected": false, "text": "Random rnd = new Random();\nint[] dice = new int[200];\nvar sidesUp = dice.Select(x => rnd.Next(1, 10));\nList<int> randomNumbers = sidesUp.GroupBy(p => p).Select(x => x.Count()).ToList();\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18108367/" ]
74,448,127
<p>I have been trying to get a query output formatted in a specific way but I am surely doing something wrong. Could anyone that knows what I am doing wrong give me a hand? Thanks a lot.</p> <p>I have the following db call:</p> <pre><code> $sql = &quot;SELECT tbl1.spec_num As spec_num, IF(tbl1.spec_fld, 'TRUE', 'FALSE') As spec_fld, tbl2.auth_id As auth_id FROM spec_table tbl1 JOIN spec_auth tbl2 ON tbl1.id=tbl2.spec_table_id WHERE tbl1.spec_fld=1 AND tbl2.enb=1;&quot;; </code></pre> <p>If I run this query in the db (mysql) I get this:</p> <pre><code>spec_num spec_fld auth_id 123413253242135234213432112345DDDDDDDG TRUE 1234567 123413253242135234213432112345DDDDDDDG TRUE 3423435 123413253242135234213432112345DDDDDDDG TRUE 9234245 </code></pre> <p>When I make a call to the DB in PHP using PDO I do the following:</p> <pre><code> $stmt = $connection-&gt;prepare($sql); $stmt-&gt;execute(); while ($result = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) { $result_json = json_encode($result); echo $result_json; } </code></pre> <p>My echo inside the loop shows this:</p> <pre><code>{&quot;spec_num&quot;:&quot;123413253242135234213432112345DDDDDDDG&quot;,&quot;spec_fld&quot;:&quot;TRUE&quot;,&quot;auth_id&quot;:&quot;3423435&quot;} {&quot;spec_num&quot;:&quot;123413253242135234213432112345DDDDDDDG&quot;,&quot;spec_fld&quot;:&quot;TRUE&quot;,&quot;auth_id&quot;:&quot;9234245&quot;} </code></pre> <p>But what I need now is to create a variable ($dtp) outside the while loop that looks like this:</p> <pre><code>$dtp = [ 'spec_num' =&gt; '123413253242135234213432112345DDDDDDDG', 'spec_fld' =&gt; TRUE, 'auth_ids' =&gt; [ '1234567', '3423435', '9234245', ], ]; </code></pre> <p>Any ideas on the best way to do this? Thanks again in advance.</p>
[ { "answer_id": 74448205, "author": "RiggsFolly", "author_id": 2310830, "author_profile": "https://Stackoverflow.com/users/2310830", "pm_score": 0, "selected": false, "text": "$stmt = $connection->prepare($sql); \n$stmt->execute();\nwhile ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {\n $rows[] = $result;\n} \necho json_encode($rows);\n" }, { "answer_id": 74456779, "author": "jspit", "author_id": 7271221, "author_profile": "https://Stackoverflow.com/users/7271221", "pm_score": 2, "selected": true, "text": "$arr = $stmt->fetchAll(PDO::FETCH_ASSOC);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1314786/" ]
74,448,142
<p>A lambda can be easily converted to std::function though this seems to be impossible when the lambda uses generalized capture with a unique_ptr. Likely an underlying std::move is missing. Is there a workaround for this or is this a known issue?</p> <pre><code>#include &lt;iostream&gt; #include &lt;memory&gt; #include &lt;functional&gt; using namespace std; int main() { auto lambdaGeneralizedCaptureOk = [t = std::make_unique&lt;int&gt;(1)]() { std::cout &lt;&lt; *t &lt;&lt; std::endl; }; lambdaGeneralizedCaptureOk(); // error: use of deleted function ‘std::unique_ptr&lt;_Tp, _Dp&gt;::unique_ptr(const std::unique_ptr&lt;_Tp, _Dp&gt;&amp;) [with _Tp = int; _Dp = std::default_delete]’ std::function&lt;void()&gt; lambdaToFunctionGeneralizedCaptureNok = [t = std::make_unique&lt;int&gt;(2)]() { std::cout &lt;&lt; *t &lt;&lt; std::endl; }; lambdaToFunctionGeneralizedCaptureNok(); return 0; } </code></pre>
[ { "answer_id": 74448248, "author": "doron", "author_id": 232918, "author_profile": "https://Stackoverflow.com/users/232918", "pm_score": 2, "selected": false, "text": "std::shared_ptr" }, { "answer_id": 74448328, "author": "康桓瑋", "author_id": 11638718, "author_profile": "https://Stackoverflow.com/users/11638718", "pm_score": 5, "selected": true, "text": "std::function" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5853141/" ]
74,448,144
<p>Having the nested list like this:</p> <pre><code>lst = [[1,3], [], [2,2,4], [], [3,5]] </code></pre> <p>I'm trying to fill in the empty lists with a value (let's say 0). I know how can do it if we are flatting the list - so then we can use either list comprehension or some pandas solution, but how is it possible to do not to change the structure of nested list and just fill the values inside <code>lst</code>.</p> <p>Thank you.</p>
[ { "answer_id": 74448202, "author": "Rafaó", "author_id": 4034593, "author_profile": "https://Stackoverflow.com/users/4034593", "pm_score": 0, "selected": false, "text": "for i, l in enumerate(lst):\n if not l:\n lst[i] = [0]\n\nprint(lst)\n# [[1, 3], [0], [2, 2, 4], [0], [3, 5]]\n" }, { "answer_id": 74448222, "author": "Will", "author_id": 12829151, "author_profile": "https://Stackoverflow.com/users/12829151", "pm_score": 2, "selected": true, "text": "i" }, { "answer_id": 74448287, "author": "mudi loodi", "author_id": 11962536, "author_profile": "https://Stackoverflow.com/users/11962536", "pm_score": 1, "selected": false, "text": "append" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3079439/" ]
74,448,168
<p>Whenever I try to make a few divs to make a navigation panel at the top of my page it ends up looking like this <a href="https://i.stack.imgur.com/Gafio.png" rel="nofollow noreferrer">Current</a> But I would like those div's side by side, along with that I am unable to put text I got it side by side at one part but the text would be on the same line as the div and it would push the div's to the left and using <br> wouldn't work Heres the HTML:</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>#topDivs { width: 100%; height: 50px; display: table; clear: both; } .myDiv { border: 2px outset black; text-align: center; height: 50px; margin: auto; width: 25%; box-sizing: border-box; color: white; display: block; } .fill-div { height: 100%; width: 100%; text-decoration: none; background-color: transparent; } #sec1 { background-color: darkred; } #sec2 { background-color: rgb(112, 172, 76); } #sec3 { background-color: rgb(252, 209, 42); } #sec4 { background-color: skyblue; } #mainText { border: 2px outset black; text-align: center; height: 50px; margin: auto; color: white; } a:link, a:visited { color: white; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="script.js"&gt;&lt;/script&gt; &lt;div id="maindiv"&gt; &lt;!-- BOXES AT THE TOP --&gt; &lt;div id="topDivs"&gt; &lt;div class="myDiv" id="sec1"&gt; &lt;a href="index.html" class="fill-div"&gt; &lt;p&gt; &lt;strong&gt;Index&lt;/strong&gt; &lt;/p&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="myDiv" id="sec2"&gt; &lt;a href="interests.html" class="fill-div"&gt; &lt;p&gt; &lt;strong&gt;Interests&lt;/strong&gt; &lt;/p&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="myDiv" id="sec3"&gt; &lt;a href="education.html" class="fill-div"&gt; &lt;p&gt; &lt;strong&gt;Education&lt;/strong&gt; &lt;/p&gt; &lt;/a&gt; &lt;/div&gt; &lt;div class="myDiv" id="sec4"&gt; &lt;a href="contactme.html" class="fill-div" &lt;style "text-decoration:none;" "color: white;"&gt; &lt;p&gt; &lt;strong&gt;Contact me&lt;/strong&gt; &lt;/p&gt; &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src="https://replit.com/public/js/replit-badge.js" theme="blue" defer&gt;&lt;/script&gt;</code></pre> </div> </div> </p> <p>All help would be greatly appreciated</p>
[ { "answer_id": 74448202, "author": "Rafaó", "author_id": 4034593, "author_profile": "https://Stackoverflow.com/users/4034593", "pm_score": 0, "selected": false, "text": "for i, l in enumerate(lst):\n if not l:\n lst[i] = [0]\n\nprint(lst)\n# [[1, 3], [0], [2, 2, 4], [0], [3, 5]]\n" }, { "answer_id": 74448222, "author": "Will", "author_id": 12829151, "author_profile": "https://Stackoverflow.com/users/12829151", "pm_score": 2, "selected": true, "text": "i" }, { "answer_id": 74448287, "author": "mudi loodi", "author_id": 11962536, "author_profile": "https://Stackoverflow.com/users/11962536", "pm_score": 1, "selected": false, "text": "append" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448168", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511579/" ]
74,448,184
<p>Imagine a data set with some time gaps between the records:</p> <pre><code>datatable(t:datetime , v: int) [ datetime(2022-01-01 07:00), 3, datetime(2022-01-01 07:15), 2, datetime(2022-01-01 07:30), 4, datetime(2022-01-01 07:45), 1, datetime(2022-01-01 08:00), 5, // GAP! datetime(2022-01-01 10:15), 8, datetime(2022-01-01 10:30), 3, datetime(2022-01-01 10:45), 2, // ALSO GAP! datetime(2022-01-01 11:30), 1, ] </code></pre> <p>I'm trying to find a max value for each record within previous hour, excluding the current iteration hour. To visualize it, I want to achieve something like that:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>t</th> <th>v</th> <th>prev_hr</th> <th>max_v</th> </tr> </thead> <tbody> <tr> <td>2022-01-01 07:00</td> <td>3</td> <td>2022-01-01 06:00</td> <td>null</td> </tr> <tr> <td>2022-01-01 07:15</td> <td>2</td> <td>2022-01-01 06:15</td> <td>3</td> </tr> <tr> <td>2022-01-01 07:30</td> <td>4</td> <td>2022-01-01 06:30</td> <td>3</td> </tr> <tr> <td>2022-01-01 07:45</td> <td>1</td> <td>2022-01-01 06:45</td> <td>4</td> </tr> <tr> <td>2022-01-01 08:00</td> <td>5</td> <td>2022-01-01 07:00</td> <td>4</td> </tr> <tr> <td>2022-01-01 10:15</td> <td>8</td> <td>2022-01-01 09:15</td> <td>null</td> </tr> <tr> <td>2022-01-01 10:30</td> <td>3</td> <td>2022-01-01 09:30</td> <td>8</td> </tr> <tr> <td>2022-01-01 10:45</td> <td>2</td> <td>2022-01-01 09:45</td> <td>8</td> </tr> <tr> <td>2022-01-01 11:30</td> <td>1</td> <td>2022-01-01 10:30</td> <td>3</td> </tr> </tbody> </table> </div> <p>I've tried modifying the approach suggested in <a href="https://stackoverflow.com/questions/72580497/how-to-create-a-window-of-arbitrary-size-in-kusto">How to create a window of arbitrary size in Kusto?</a> (so using <a href="https://www.stackoverflow.com/">scan()</a> operator) but had problems applying it to the above. Also, I feel like something like <a href="https://learn.microsoft.com/en-us/azure/data-explorer/kusto/functions-library/time-window-rolling-avg-fl?tabs=adhoc" rel="nofollow noreferrer">time_window_rolling_avg_fl()</a> might be useful here, but it seems complex for a simple use-case like above.</p> <p>I feel like what I want to achieve is relatively simple and obvious, but I am just missing it.</p>
[ { "answer_id": 74449319, "author": "yifats", "author_id": 10372153, "author_profile": "https://Stackoverflow.com/users/10372153", "pm_score": 3, "selected": true, "text": "datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend bin_t = bin(t, 1m)\n| extend _range = range(bin_t, bin_t+1h, 1m)\n| mv-expand _range to typeof(datetime)\n| as T | join kind=inner T on $left.bin_t == $right._range\n| project t, t1, v, v1\n| summarize max_v = maxif(v1, t1 < t) by t, v\n| project t, v, prev_h = t-1h, max_v\n" }, { "answer_id": 74451235, "author": "David דודו Markovitz", "author_id": 6336479, "author_profile": "https://Stackoverflow.com/users/6336479", "pm_score": 1, "selected": false, "text": "let MyTable = datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend dummy = 1;\nMyTable\n| join kind=inner MyTable on dummy\n| where t - t1 between (0h .. 1h)\n| summarize x = maxif(v1, t1 != t) by t, v\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19649333/" ]
74,448,186
<p>im new to python and to working with datasets, i'm using a data set that has certain stocks and stuff about them since the 1980's till the late 2010's, i dont want to use any of the stocks in the data set when i use the knn prediction, what can i do?</p> <pre><code>for i in df[&quot;Date&quot;]: if(i.startswith(&quot;19&quot;)): f=df.drop(['Adj Close','Volume','High','Date','Low','Open', 'Close'], axis=1) </code></pre> <p>then i just get a copy of an empy dataset</p> <pre><code>print(f) </code></pre> <p>Empty DataFrame</p>
[ { "answer_id": 74449319, "author": "yifats", "author_id": 10372153, "author_profile": "https://Stackoverflow.com/users/10372153", "pm_score": 3, "selected": true, "text": "datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend bin_t = bin(t, 1m)\n| extend _range = range(bin_t, bin_t+1h, 1m)\n| mv-expand _range to typeof(datetime)\n| as T | join kind=inner T on $left.bin_t == $right._range\n| project t, t1, v, v1\n| summarize max_v = maxif(v1, t1 < t) by t, v\n| project t, v, prev_h = t-1h, max_v\n" }, { "answer_id": 74451235, "author": "David דודו Markovitz", "author_id": 6336479, "author_profile": "https://Stackoverflow.com/users/6336479", "pm_score": 1, "selected": false, "text": "let MyTable = datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend dummy = 1;\nMyTable\n| join kind=inner MyTable on dummy\n| where t - t1 between (0h .. 1h)\n| summarize x = maxif(v1, t1 != t) by t, v\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13859338/" ]
74,448,227
<p><a href="https://i.stack.imgur.com/Jweqo.png" rel="nofollow noreferrer">enter image description here</a></p> <pre><code>Failed to convert property value of type java.lang.String[] to required type java.util.List for property tags; nested exception is java.lang.IllegalStateException: Cannot convert value of type java.lang.String to required type edu.pxu.ri.MVCvaJPA.entity.Tag for property tags[0]: no matching editors or conversion strategy found </code></pre> <p>ManyToMany ORM</p> <p>Solution: <a href="https://i.stack.imgur.com/D0Uc5.png" rel="nofollow noreferrer">enter image description here</a></p> <p>AppConfig: <a href="https://i.stack.imgur.com/nV8L8.png" rel="nofollow noreferrer">enter image description here</a></p> <p>Happy to help you solve the problem.</p>
[ { "answer_id": 74449319, "author": "yifats", "author_id": 10372153, "author_profile": "https://Stackoverflow.com/users/10372153", "pm_score": 3, "selected": true, "text": "datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend bin_t = bin(t, 1m)\n| extend _range = range(bin_t, bin_t+1h, 1m)\n| mv-expand _range to typeof(datetime)\n| as T | join kind=inner T on $left.bin_t == $right._range\n| project t, t1, v, v1\n| summarize max_v = maxif(v1, t1 < t) by t, v\n| project t, v, prev_h = t-1h, max_v\n" }, { "answer_id": 74451235, "author": "David דודו Markovitz", "author_id": 6336479, "author_profile": "https://Stackoverflow.com/users/6336479", "pm_score": 1, "selected": false, "text": "let MyTable = datatable(t:datetime , v: int)\n[\n datetime(2022-01-01 07:00), 3,\n datetime(2022-01-01 07:15), 2,\n datetime(2022-01-01 07:30), 4,\n datetime(2022-01-01 07:45), 1,\n datetime(2022-01-01 08:00), 5,\n // GAP!\n datetime(2022-01-01 10:15), 8,\n datetime(2022-01-01 10:30), 3,\n datetime(2022-01-01 10:45), 2,\n // ALSO GAP!\n datetime(2022-01-01 11:30), 1,\n]\n| extend dummy = 1;\nMyTable\n| join kind=inner MyTable on dummy\n| where t - t1 between (0h .. 1h)\n| summarize x = maxif(v1, t1 != t) by t, v\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20311174/" ]
74,448,232
<p>I have data as follows:</p> <pre><code>library(data.table) dat &lt;- fread(&quot;total women young 1 0 0 1 1 1 1 0 1 2 1 1 2 2 1 2 2 1 3 1 2 3 2 3 3 2 3 4 4 2 4 4 3 4 3 3 5 5 2 5 2 3 5 5 3 10 4 2 10 4 3 20 5 3 100 10 20&quot;) </code></pre> <p>I would like to create six categories for the variable <code>tot_num</code>:</p> <pre><code>1,2,3,4,5 and over 5. </code></pre> <p>I would like to count the observations per category <code>total</code> in <code>count</code>. <code>sum_tot</code> would simply be these multiplied. And <code>women</code>and <code>young</code> are the average amount of women and young people in that group.</p> <p>Desired output</p> <pre><code> total count sum_tot_count women young 1 3 3 0.33 0.66 2 3 6 5/6 0.5 3 3 9 5/9 8/9 4 3 12 11/12 10/12 5 3 15 12/15 8/15 over 5 4 140 23/140 28/140 </code></pre> <p>I am having some trouble figuring out where to start.</p> <p>Could someone lead me on the right track?</p>
[ { "answer_id": 74448342, "author": "Karthik S", "author_id": 10722752, "author_profile": "https://Stackoverflow.com/users/10722752", "pm_score": 2, "selected": false, "text": "library(dplyr)\ndat %>% mutate(tot = if_else(total > 5, 'over 5', as.character(total))) %>% \n group_by(tot) %>% summarise(count = n(), sum_tot_count = sum(total), women = sum(women)/sum(total), young = sum(young)/sum(total))\n# A tibble: 6 × 5\n tot count sum_tot_count women young\n <chr> <int> <int> <dbl> <dbl>\n1 1 3 3 0.333 0.667\n2 2 3 6 0.833 0.5 \n3 3 3 9 0.556 0.889\n4 4 3 12 0.917 0.667\n5 5 3 15 0.8 0.533\n6 over 5 4 140 0.164 0.2 \n" }, { "answer_id": 74448377, "author": "Maël", "author_id": 13460602, "author_profile": "https://Stackoverflow.com/users/13460602", "pm_score": 2, "selected": false, "text": "cut" }, { "answer_id": 74448458, "author": "Ben Bolker", "author_id": 190277, "author_profile": "https://Stackoverflow.com/users/190277", "pm_score": 2, "selected": false, "text": "data.table" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8071608/" ]
74,448,240
<p>I have two list, i wanted to merge both the list in next to the same index with the delimiter.</p> <pre><code>list1 = ['1', '2', '3', '4'] list2 = ['A', 'B', 'C', 'D'] </code></pre> <p>Expected result,</p> <pre><code>['1 - A', '2 - B', '3 - C', '4 - D'] </code></pre> <p>I can merge both the lists using <code>Concatenate, append or extend</code> methods. But not sure to concatenate with the delimiter of every equivalent record.</p>
[ { "answer_id": 74448271, "author": "Mehrdad Pedramfar", "author_id": 3744747, "author_profile": "https://Stackoverflow.com/users/3744747", "pm_score": 3, "selected": true, "text": "zip()" }, { "answer_id": 74448804, "author": "Arifa Chan", "author_id": 19574157, "author_profile": "https://Stackoverflow.com/users/19574157", "pm_score": 0, "selected": false, "text": "zip()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4473615/" ]
74,448,247
<p>I have a dataframe with article texts. One row, among others, has several sentences with the copyright symbol, &quot;©&quot;.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>article_texts</th> </tr> </thead> <tbody> <tr> <td>© Aaron Davidson/Getty Images Aaron Davidson/Getty Images Beyond Meat cuts 19% of workforce including disgraced COO, according to a release from the company. CEO Ethan Brown says the plant-based company is 'significantly reducing expenses' in an effort to focus on growth. It was one of the best fast food meals I've ever had. 6/25 SLIDES © Mary Meisenzahl/Insider The plant-based protein wasn't meant to be indistinguishable from Taco Bell's signature beef, but &quot;equally cravable,&quot; according to Taco Bell's director of global nutrition &amp; sustainability Missy Schaaphok. 22/25 SLIDES © Diana G./Yelp In 2019, Taco Bell North America president Julie Felss Masino publicly said that the chain was relying on its own vegetarian options instead of creating new plant-based meat substitutes. Although it remains unclear exactly how many employees were let go, the company ended 2021 with about 1,100 employees.</td> </tr> </tbody> </table> </div> <p>I want to remove the sentences in the row only with the copyright symbol and I want to do this for every row in the dataset. This is what I want it to look like:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>article_texts</th> </tr> </thead> <tbody> <tr> <td>CEO Ethan Brown says the plant-based company is 'significantly reducing expenses' in an effort to focus on growth. It was one of the best fast food meals I've ever had. /Yelp In 2019, Taco Bell North America president Julie Felss Masino publicly said that the chain was relying on its own vegetarian options instead of creating new plant-based meat substitutes. Although it remains unclear exactly how many employees were let go, the company ended 2021 with about 1,100 employees.</td> </tr> </tbody> </table> </div> <p>This is what I tried:</p> <pre><code>for i in df['article_texts']: try: paragraph = i tokens = paragraph.split(&quot;.&quot;) for sentence in tokens: if &quot;©&quot; in sentence: tokens.remove(sentence) final = (&quot;.&quot;).join(tokens) df['summaries'].loc[(df['summaries'] == i)] = final except: print(&quot;Yeah, we good.&quot;) </code></pre> <p>Yet, I still get this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>article_texts</th> </tr> </thead> <tbody> <tr> <td>CEO Ethan Brown says the plant-based company is 'significantly reducing expenses' in an effort to focus on growth. It was one of the best fast food meals I've ever had. 6/25 SLIDES © Mary Meisenzahl/Insider The plant-based protein wasn't meant to be indistinguishable from Taco Bell's signature beef, but &quot;equally cravable,&quot; according to Taco Bell's director of global nutrition &amp; sustainability Missy Schaaphok. 22/25 SLIDES © Diana G./Yelp In 2019, Taco Bell North America president Julie Felss Masino publicly said that the chain was relying on its own vegetarian options instead of creating new plant-based meat substitutes. Although it remains unclear exactly how many employees were let go, the company ended 2021 with about 1,100 employees.</td> </tr> </tbody> </table> </div> <p>What am I doing wrong?</p>
[ { "answer_id": 74448271, "author": "Mehrdad Pedramfar", "author_id": 3744747, "author_profile": "https://Stackoverflow.com/users/3744747", "pm_score": 3, "selected": true, "text": "zip()" }, { "answer_id": 74448804, "author": "Arifa Chan", "author_id": 19574157, "author_profile": "https://Stackoverflow.com/users/19574157", "pm_score": 0, "selected": false, "text": "zip()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15073544/" ]
74,448,255
<p>I want to find a value in the following nested array <strong>without using loops</strong>:</p> <pre><code>let children = [ { name: 'grand 1', children: [ { name: 'parent 1.1', children: [ { name: 'child 1.1.1', children: [ // more... ] }, // more... ], }, // more... ], }, // more... ]; </code></pre> <p>This is what I'd do if I was only searching in the horizontal axis:</p> <pre><code>let childrenHorizontal = [ { name: 'grand 1' }, { name: 'grand 2' }, { name: 'grand 3' }, // more ]; function findHorizontal(name, childrenHorizontal) { let [head, ...tail] = childrenHorizontal; if (head.name === name) return head; else if (tail.length) return findHorizontal(name, tail); } </code></pre> <p>But how do I search the nested array both horizontally and vertically?</p>
[ { "answer_id": 74448910, "author": "Thore", "author_id": 20010246, "author_profile": "https://Stackoverflow.com/users/20010246", "pm_score": 1, "selected": false, "text": "function find(name, children) {\n let [head, ...tail] = children;\n if (head.name === name)\n return head;\n return find(name, [...head.children, ...tail]);\n}\n" }, { "answer_id": 74449193, "author": "Lucasbk38", "author_id": 20480528, "author_profile": "https://Stackoverflow.com/users/20480528", "pm_score": 0, "selected": false, "text": "const data = [{\n name: 'grand 1',\n children: [{\n name: 'parent 1.1',\n children: [{\n name: 'child 1.1.1',\n children: []\n },\n // more...\n ],\n },\n // more...\n ],\n },\n // more...\n];\n\nconst find = (name, children) => {\n for (const child of children) {\n // if the chidren's name corresopnds to the one provided, return it\n if (child.name === name) return child\n\n // here is the recursion\n const e = find(name, child.children)\n\n // if we found it on the child, we return the one found, else we keep going\n if (e) return e\n }\n\n // if none of the children or grand-children ... found, return null\n return null\n}\n\nconsole.log(find('parent 1.1', data))" }, { "answer_id": 74451728, "author": "Scott Sauyet", "author_id": 1243641, "author_profile": "https://Stackoverflow.com/users/1243641", "pm_score": 3, "selected": true, "text": "deepFind" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20010246/" ]
74,448,292
<p>I have created a branch called &quot;multiple_fixes&quot; off my Dev branch and have been working there for a couple weeks. While I was working on my branch, several other people have created branches after I created mine, and have since made pull requests into the Dev branch.</p> <p>Now, I am ready to merge my changes into Dev, but I have many files that are down-level from the current Dev branch. If I do a Pull Request, I will undo all the other changes that people have checked in.</p> <p>How do I pull the current changes of Dev into my branch, without over-writing my work?</p>
[ { "answer_id": 74448910, "author": "Thore", "author_id": 20010246, "author_profile": "https://Stackoverflow.com/users/20010246", "pm_score": 1, "selected": false, "text": "function find(name, children) {\n let [head, ...tail] = children;\n if (head.name === name)\n return head;\n return find(name, [...head.children, ...tail]);\n}\n" }, { "answer_id": 74449193, "author": "Lucasbk38", "author_id": 20480528, "author_profile": "https://Stackoverflow.com/users/20480528", "pm_score": 0, "selected": false, "text": "const data = [{\n name: 'grand 1',\n children: [{\n name: 'parent 1.1',\n children: [{\n name: 'child 1.1.1',\n children: []\n },\n // more...\n ],\n },\n // more...\n ],\n },\n // more...\n];\n\nconst find = (name, children) => {\n for (const child of children) {\n // if the chidren's name corresopnds to the one provided, return it\n if (child.name === name) return child\n\n // here is the recursion\n const e = find(name, child.children)\n\n // if we found it on the child, we return the one found, else we keep going\n if (e) return e\n }\n\n // if none of the children or grand-children ... found, return null\n return null\n}\n\nconsole.log(find('parent 1.1', data))" }, { "answer_id": 74451728, "author": "Scott Sauyet", "author_id": 1243641, "author_profile": "https://Stackoverflow.com/users/1243641", "pm_score": 3, "selected": true, "text": "deepFind" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15995125/" ]
74,448,304
<p>I have a list of terms that I've accomplished through a split (<code>split = str_split(terms, &quot;//&quot;)</code>), where each element would be a row, and within each element the values of three different columns appear sequentially:</p> <pre><code>split [[1]] [1] &quot;value_col_1_1&quot; &quot;value_col_2_1&quot; &quot;value_col_3_1&quot; [[2]] [1] &quot;value_col_1_2&quot; &quot;value_col_2_2&quot; &quot;value_col_3_2&quot; </code></pre> <p>I would like to assign each of the values to columns in a dataframe. My first idea was a for loop, but it looks like it is quite inefficient, since it is taking longer than a similar code to accomplish the same task. The loop is the following:</p> <pre><code>for (row in 1:length(new_categorization)){ df[row, &quot;first_col&quot;] &lt;- split[[row]][1] df[row, &quot;second_col&quot;] &lt;- split[[row]][2] df[row, &quot;third_col&quot;] &lt;- split[[row]][3] } </code></pre> <p>What is the most time efficient way to do this?</p>
[ { "answer_id": 74448352, "author": "Alberto Agudo Dominguez", "author_id": 15459665, "author_profile": "https://Stackoverflow.com/users/15459665", "pm_score": 0, "selected": false, "text": "df[\"first_col\"] <- sapply(split, function(x) x[1])\ndf[\"second_col\"] <- sapply(split, function(x) x[2])\ndf[\"third_col\"] <- sapply(split, function(x) x[3]) \n" }, { "answer_id": 74448529, "author": "Allan Cameron", "author_id": 12500315, "author_profile": "https://Stackoverflow.com/users/12500315", "pm_score": 2, "selected": false, "text": "do.call(rbind, split)" }, { "answer_id": 74449041, "author": "TimTeaFan", "author_id": 9349302, "author_profile": "https://Stackoverflow.com/users/9349302", "pm_score": 1, "selected": false, "text": "transpose()" }, { "answer_id": 74449417, "author": "B. Christian Kamgang", "author_id": 10848898, "author_profile": "https://Stackoverflow.com/users/10848898", "pm_score": 0, "selected": false, "text": "transpose" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15459665/" ]
74,448,326
<p>My vscode can't run any code.I've been trying to fix it for 2-3 days now but that doesn't work.I don't know it about I try to setup c/c++ in vscode about 15 days ago that time it work it can c c++ python however this few day I back to code something and have found can't run any code.</p> <p>can anyone please suggested solutions.I read previous post about this before but it not the same when I try to run code noting happening and no error.</p> <p>and about python files must call file like this for run and that file must in Drive C.It unlike normal just press F5 or click runcode then it run.</p> <p><img src="https://i.stack.imgur.com/eJJS1.png" alt="" /></p> <p>I want to fix it like before.It mean make it to show the result of my code in visual studio.</p>
[ { "answer_id": 74448899, "author": "Anonymous", "author_id": 20510770, "author_profile": "https://Stackoverflow.com/users/20510770", "pm_score": 1, "selected": false, "text": "ctrl + shift + x" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20506941/" ]
74,448,333
<p>There is a use case in which I have a long <code>String</code> which can contain many <code>&lt;img&gt;</code> tags. I need to collect the entire image tag from start(<code>&lt;img src=&quot;</code>) to close(<code>&quot;&gt;</code>) in a List.</p> <p>I wrote a regex(<code>&quot;&lt;img.*?\&quot;&gt;&quot;gm</code>) for seleting these but don't know how to collect them all in a List.</p> <p>eg:</p> <pre class="lang-java prettyprint-override"><code>final String regex = &quot;&lt;img.*?\\\&quot;&gt;&quot;; final String string = &quot;Hello World &lt;img src=\&quot;https://dummyimage.com/300.png/09f/777\&quot;&gt; \nMy Name &lt;img src=\&quot;https://dummyimage.com/300.png/09f/ff2\&quot;&gt; Random Text\nHello\nHello Random &lt;img src=\&quot;https://dummyimage.com/300.png/09f/888\&quot;&gt; \nMy Name &lt;img src=\&quot;https://dummyimage.com/300.png/09f/2ff\&quot;&gt;adaad\n&quot;; final String replace = &quot;&quot;; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); final String result = matcher.replaceAll(replace); // Here, how can I collect all the image tags in a list </code></pre>
[ { "answer_id": 74448446, "author": "Vinz", "author_id": 17173476, "author_profile": "https://Stackoverflow.com/users/17173476", "pm_score": 2, "selected": false, "text": "final List<String> result = new ArrayList<>();\nwhile (matcher.find()) {\n result.add(matcher.group());\n}\n" }, { "answer_id": 74448589, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 3, "selected": true, "text": "Pattern.splitAsStream()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16696520/" ]
74,448,344
<p>I have trained a BERTopic model on a dataframe of length of 400k. I want to map the topics of each document in a new column inside the dataframe. I could do that by running a for loop on all the documents and do <code>topic_model.transform(doc)</code> on them. The only problem is, it takes more than a second to transform each document into its topic and it would take days for the whole dataset.</p> <p>Is there a way to achieve this faster since I want to map the topics on the training data.</p> <p>I tried:</p> <pre><code>topic_model = BERTopic() topics, probs = topic_model.fit_transform(docs) topic_model.reduce_topics(docs, nr_topics=200) topics = [] for text in df.texts: tops = topic_model.transform(text) topics.append(tops) df['topics'] = topics </code></pre>
[ { "answer_id": 74448446, "author": "Vinz", "author_id": 17173476, "author_profile": "https://Stackoverflow.com/users/17173476", "pm_score": 2, "selected": false, "text": "final List<String> result = new ArrayList<>();\nwhile (matcher.find()) {\n result.add(matcher.group());\n}\n" }, { "answer_id": 74448589, "author": "Alexander Ivanchenko", "author_id": 17949945, "author_profile": "https://Stackoverflow.com/users/17949945", "pm_score": 3, "selected": true, "text": "Pattern.splitAsStream()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19924026/" ]
74,448,347
<p>I`m trying to extract the src URL/path without the quotes, only in the case it is an image:</p> <blockquote> <ol> <li>src=&quot;/path/image.png&quot; // should capture =&gt; /path/image.png</li> <li>src=&quot;/path/image.bmp&quot; // should capture =&gt; /path/image.bmp</li> <li>src=&quot;/path/image.jpg&quot; // should capture =&gt; /path/image.jpg</li> <li>src=&quot;https://www.site1.com&quot; // should NOT capture</li> </ol> </blockquote> <p>So far I have <code>/src=&quot;(.*)&quot;/g</code>, but that obviously captures both, I have been looking at look behind and look ahead but just can`t put it together.</p>
[ { "answer_id": 74448367, "author": "pzelenovic", "author_id": 717683, "author_profile": "https://Stackoverflow.com/users/717683", "pm_score": -1, "selected": false, "text": "src=\"(.*image.*)\"" }, { "answer_id": 74448410, "author": "Eterm", "author_id": 1635976, "author_profile": "https://Stackoverflow.com/users/1635976", "pm_score": 2, "selected": false, "text": "/src=\"(.*(?:jpg|bmp|png))\"/g" }, { "answer_id": 74448548, "author": "VvdL", "author_id": 15589010, "author_profile": "https://Stackoverflow.com/users/15589010", "pm_score": 1, "selected": false, "text": "png|bmp|jpg" }, { "answer_id": 74449590, "author": "The fourth bird", "author_id": 5424988, "author_profile": "https://Stackoverflow.com/users/5424988", "pm_score": 3, "selected": true, "text": "\"" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448347", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11276458/" ]
74,448,353
<p>Unlike <a href="https://stackoverflow.com/questions/47860772/gitlab-remote-http-basic-access-denied-and-fatal-authentication">this post</a> im authorized in gitLab via GitHub</p> <p>I am authorized in gitLab via gitHub and I trying to clone project with URL.</p> <p>So when I trying to do steps below for a new project I am prompted to enter my gitlab account login and password</p> <pre><code>git init git remote add origin https://gitlab.com/Egas88/web_lab_2.git git fetch </code></pre> <p>after data is entered for both gitLab and GitHub I get the following error</p> <blockquote> <p>Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See <a href="https://gitlab.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied" rel="nofollow noreferrer">https://gitlab.com/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied</a> fatal: Authentication failed for 'https://gitlab.com/Egas88/web_lab_2.git/'</p> </blockquote> <p>I tried to change rights from developer to maintainer and I still get this problem</p>
[ { "answer_id": 74448367, "author": "pzelenovic", "author_id": 717683, "author_profile": "https://Stackoverflow.com/users/717683", "pm_score": -1, "selected": false, "text": "src=\"(.*image.*)\"" }, { "answer_id": 74448410, "author": "Eterm", "author_id": 1635976, "author_profile": "https://Stackoverflow.com/users/1635976", "pm_score": 2, "selected": false, "text": "/src=\"(.*(?:jpg|bmp|png))\"/g" }, { "answer_id": 74448548, "author": "VvdL", "author_id": 15589010, "author_profile": "https://Stackoverflow.com/users/15589010", "pm_score": 1, "selected": false, "text": "png|bmp|jpg" }, { "answer_id": 74449590, "author": "The fourth bird", "author_id": 5424988, "author_profile": "https://Stackoverflow.com/users/5424988", "pm_score": 3, "selected": true, "text": "\"" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20501796/" ]
74,448,363
<p>I am trying to find out if a hex color is &quot;blue&quot;. This might be a very subjective thing when comparing different (lighter/ darker) shades of blue or close to blue colors but in my case it does not have to be very precise. I just want to determine if a color is blue or not.</p> <p>The more generalized question would be, is there a way to calculate which of the &quot;basic colors&quot; is closest to a given hex value? Basic colors being red, blue ,green, yellow, purple, etc. without being too specific.</p> <p>I am looking for an implementation or library in python but a general solution would also suffice.</p>
[ { "answer_id": 74448594, "author": "Tyler Aldrich", "author_id": 1580425, "author_profile": "https://Stackoverflow.com/users/1580425", "pm_score": 2, "selected": true, "text": " Black #000000 (0,0,0)\n White #FFFFFF (255,255,255)\n Red #FF0000 (255,0,0)\n Lime #00FF00 (0,255,0)\n Blue #0000FF (0,0,255)\n Yellow #FFFF00 (255,255,0)\n Cyan / Aqua #00FFFF (0,255,255)\n Magenta / Fuchsia #FF00FF (255,0,255)\n Silver #C0C0C0 (192,192,192)\n Gray #808080 (128,128,128)\n Maroon #800000 (128,0,0)\n Olive #808000 (128,128,0)\n Green #008000 (0,128,0)\n Purple #800080 (128,0,128)\n Teal #008080 (0,128,128)\n Navy #000080 (0,0,128)\n" }, { "answer_id": 74448650, "author": "Code Freak", "author_id": 20511732, "author_profile": "https://Stackoverflow.com/users/20511732", "pm_score": -1, "selected": false, "text": "hex = input() \n\nif hex == '#0000FF':\n print('Blue')\n\nelse:\n print('Not blue') \n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4644897/" ]
74,448,371
<p>I have below code which writes data into AWS s3 location using Glue job, but at the end it is saving in part file, but my requirement is to save filename as filename.json or filename.parquet</p> <pre><code>s3_loc = &quot;s3a://s3_location/path&quot; ##this is the default part of the glue script job = Job(glueContext) job.init(args['JOB_NAME'], args) datasource0 = glueContext.create_dynamic_frame.from_catalog(database = &quot;dbname&quot;, table_name = &quot;tableName&quot;, transformation_ctx = &quot;datasource0&quot;) applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [(&quot;user id&quot;, &quot;string&quot;, &quot;user id&quot;, &quot;string&quot;), (&quot;e-mail&quot;, &quot;string&quot;, &quot;e-mail&quot;, &quot;string&quot;), (&quot;e-mail 2&quot;, &quot;string&quot;, &quot;e-mail 2&quot;, &quot;string&quot;)], transformation_ctx = &quot;applymapping1&quot;) timestampedDf = applymapping1.toDF().withColumn(&quot;export_timestamp&quot;, current_timestamp()) df = timestampedDf.withColumn(&quot;client&quot;, lit(&quot;122&quot;)).withColumn(&quot;partition_date&quot;, current_date()).coalesce(1) dyf = DynamicFrame.fromDF(df, glueContext, &quot;dyf&quot;) print(&quot;---------&gt; Let's go &lt;---------&quot;) datasink2 = glueContext.write_dynamic_frame.from_options(frame = dyf, connection_type = &quot;s3&quot;, connection_options = {&quot;path&quot;: s3_loc , &quot;partitionKeys&quot;: [&quot;client&quot;,&quot;partition_date&quot;]}, format = &quot;json&quot;, transformation_ctx = &quot;datasink2&quot;) print(&quot;---------&gt; Let's finish &lt;---------&quot;) job.commit() </code></pre> <p>anyone can help to save data in correct fileformat with extenstion as .json or .parquet ?</p> <p>I have below code which writes data into AWS s3 location using Glue job, but at the end it is saving in part file, but my requirement is to save filename as filename.json or filename.parquet</p> <pre><code>s3_loc = &quot;s3a://s3_location/path&quot; ##this is the default part of the glue script job = Job(glueContext) job.init(args['JOB_NAME'], args) datasource0 = glueContext.create_dynamic_frame.from_catalog(database = &quot;dbname&quot;, table_name = &quot;tableName&quot;, transformation_ctx = &quot;datasource0&quot;) applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [(&quot;user id&quot;, &quot;string&quot;, &quot;user id&quot;, &quot;string&quot;), (&quot;e-mail&quot;, &quot;string&quot;, &quot;e-mail&quot;, &quot;string&quot;), (&quot;e-mail 2&quot;, &quot;string&quot;, &quot;e-mail 2&quot;, &quot;string&quot;)], transformation_ctx = &quot;applymapping1&quot;) timestampedDf = applymapping1.toDF().withColumn(&quot;export_timestamp&quot;, current_timestamp()) df = timestampedDf.withColumn(&quot;client&quot;, lit(&quot;122&quot;)).withColumn(&quot;partition_date&quot;, current_date()).coalesce(1) dyf = DynamicFrame.fromDF(df, glueContext, &quot;dyf&quot;) print(&quot;---------&gt; Let's go &lt;---------&quot;) datasink2 = glueContext.write_dynamic_frame.from_options(frame = dyf, connection_type = &quot;s3&quot;, connection_options = {&quot;path&quot;: s3_loc , &quot;partitionKeys&quot;: [&quot;client&quot;,&quot;partition_date&quot;]}, format = &quot;json&quot;, transformation_ctx = &quot;datasink2&quot;) print(&quot;---------&gt; Let's finish &lt;---------&quot;) job.commit() </code></pre> <p>anyone can help to save data in correct fileformat with extenstion as .json or .parquet ?</p>
[ { "answer_id": 74448594, "author": "Tyler Aldrich", "author_id": 1580425, "author_profile": "https://Stackoverflow.com/users/1580425", "pm_score": 2, "selected": true, "text": " Black #000000 (0,0,0)\n White #FFFFFF (255,255,255)\n Red #FF0000 (255,0,0)\n Lime #00FF00 (0,255,0)\n Blue #0000FF (0,0,255)\n Yellow #FFFF00 (255,255,0)\n Cyan / Aqua #00FFFF (0,255,255)\n Magenta / Fuchsia #FF00FF (255,0,255)\n Silver #C0C0C0 (192,192,192)\n Gray #808080 (128,128,128)\n Maroon #800000 (128,0,0)\n Olive #808000 (128,128,0)\n Green #008000 (0,128,0)\n Purple #800080 (128,0,128)\n Teal #008080 (0,128,128)\n Navy #000080 (0,0,128)\n" }, { "answer_id": 74448650, "author": "Code Freak", "author_id": 20511732, "author_profile": "https://Stackoverflow.com/users/20511732", "pm_score": -1, "selected": false, "text": "hex = input() \n\nif hex == '#0000FF':\n print('Blue')\n\nelse:\n print('Not blue') \n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511658/" ]
74,448,382
<p>I've got a group of files with <strong>only one</strong> specific extension under one specific directory. How do I check whether I've got at least one of those files. If at least one file with that specific extension is present, then print <em>at least one file matching your extension is present in your directory</em>. If not, then print <em>no files of that specific extension exist in your directory</em>.</p> <p>Also, when no file of a specific extension is present, I've got the following error message that I'm not able to get rid of, even if I use <code>2&gt;/dev/null</code> redirection: <code>zsh: no matches found: *.mkv</code> (and hence, behaving differently from Bash)</p>
[ { "answer_id": 74448594, "author": "Tyler Aldrich", "author_id": 1580425, "author_profile": "https://Stackoverflow.com/users/1580425", "pm_score": 2, "selected": true, "text": " Black #000000 (0,0,0)\n White #FFFFFF (255,255,255)\n Red #FF0000 (255,0,0)\n Lime #00FF00 (0,255,0)\n Blue #0000FF (0,0,255)\n Yellow #FFFF00 (255,255,0)\n Cyan / Aqua #00FFFF (0,255,255)\n Magenta / Fuchsia #FF00FF (255,0,255)\n Silver #C0C0C0 (192,192,192)\n Gray #808080 (128,128,128)\n Maroon #800000 (128,0,0)\n Olive #808000 (128,128,0)\n Green #008000 (0,128,0)\n Purple #800080 (128,0,128)\n Teal #008080 (0,128,128)\n Navy #000080 (0,0,128)\n" }, { "answer_id": 74448650, "author": "Code Freak", "author_id": 20511732, "author_profile": "https://Stackoverflow.com/users/20511732", "pm_score": -1, "selected": false, "text": "hex = input() \n\nif hex == '#0000FF':\n print('Blue')\n\nelse:\n print('Not blue') \n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448382", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3585282/" ]
74,448,405
<p>As mentioned in cppreference: <a href="https://en.cppreference.com/w/cpp/language/copy_elision" rel="nofollow noreferrer">https://en.cppreference.com/w/cpp/language/copy_elision</a></p> <p>it is guaranteed in c++17 that copy elision must be applied for some cases like</p> <pre><code>SomeBigObject SomeBigObject::Factory(...) { SomeBigObject local; ... return local; } </code></pre> <p>(example taken from <a href="https://abseil.io/tips/11" rel="nofollow noreferrer">https://abseil.io/tips/11</a> )</p> <p>but not for cases like</p> <pre><code>SomeBigObject SomeBigObject::Factory(...) { SomeBigObject local1; SomeBigObject local2; ... if (cond_1) { return local1; } else { return local2; } } </code></pre> <p>For a c++ user, it is somewhat difficult to be 100% sure that copy elision / NVO is applied to the functions' return value above.</p> <p>So, to be sure that a object would not be copied, we usually write something like</p> <pre><code> SomeBigObject obj; func(&amp;obj); </code></pre> <p>whereas in most cases a one-liner like</p> <pre><code> SomeBigObject obj = func(); </code></pre> <p>would suffice.</p> <p>Is there any language/compiler facility to help us guarantee that at compile time (maybe some kind of static_assert()) so that we can be confident writing those one-liners ?</p> <p>I know that marking the copy constructor deleted would do the good, but copy is needed in some cases.</p>
[ { "answer_id": 74448594, "author": "Tyler Aldrich", "author_id": 1580425, "author_profile": "https://Stackoverflow.com/users/1580425", "pm_score": 2, "selected": true, "text": " Black #000000 (0,0,0)\n White #FFFFFF (255,255,255)\n Red #FF0000 (255,0,0)\n Lime #00FF00 (0,255,0)\n Blue #0000FF (0,0,255)\n Yellow #FFFF00 (255,255,0)\n Cyan / Aqua #00FFFF (0,255,255)\n Magenta / Fuchsia #FF00FF (255,0,255)\n Silver #C0C0C0 (192,192,192)\n Gray #808080 (128,128,128)\n Maroon #800000 (128,0,0)\n Olive #808000 (128,128,0)\n Green #008000 (0,128,0)\n Purple #800080 (128,0,128)\n Teal #008080 (0,128,128)\n Navy #000080 (0,0,128)\n" }, { "answer_id": 74448650, "author": "Code Freak", "author_id": 20511732, "author_profile": "https://Stackoverflow.com/users/20511732", "pm_score": -1, "selected": false, "text": "hex = input() \n\nif hex == '#0000FF':\n print('Blue')\n\nelse:\n print('Not blue') \n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4845608/" ]
74,448,412
<p>I hope you are able to help me.</p> <p>My question is:</p> <p>When passing an instance of an object that is in an arraylist, and I pass that arraylist to another class, how do I access it's atributes?</p> <p>I can access the attributes before passing it to another class.</p> <p>The &quot;Main&quot; class, passes on the data, to the &quot;Employees&quot; class.</p> <pre><code>Employees employees = new Employees(); employees.addEmployee(&quot;Orlando&quot;, &quot;Silva&quot;, 111111111, &quot;St. King's Street&quot;, 111111111, 11111111111111L, employees.getMinimumWage(), employees.getDayShift()); employees.addEmployee(&quot;Rui&quot;, &quot;Guilherme&quot;, 111111111, &quot;St. King's Street&quot;, 111111111, 11111111111111L, employees.getMinimumWage(), employees.getNightShift()); employees.addEmployee(&quot;Marco&quot;, &quot;Alberto&quot;, 111111111, &quot;St. King's Street&quot;, 111111111, 11111111111111L, employees.getMinimumWage(), employees.getNightShift()); </code></pre> <p>The &quot;Employees&quot; class receives the data, adds it to an array, and from that array goes to the &quot;AllStaff&quot; class</p> <p>Notice, that I have access to the atributes, in the method &quot;addToAllStaff()&quot;</p> <pre><code>public class Employees { // Atributes public String name; private String lName; private int nID; private String address; private int phNum; private long nSocialSecNum; private double minimumWage = 740.83; private double employeeWage; private String dayShift = &quot;Day shift&quot;, afternoonShift = &quot;Afternoon shift&quot;, nightShift = &quot;Night shift&quot;; private String shift; private ArrayList&lt;Employees&gt; employeesArrayList = new ArrayList&lt;Employees&gt;(); private AllStaff allStaff = new AllStaff(); //--------------------- // Constructors public Employees(){ } public Employees(String name, String lName, int nID, String address, int phNum, long nSocialSecNum, double minimumWage, String shift){ this.name = name; this.lName = lName; this.nID = nID; this.address = address; this.phNum = phNum; this.nSocialSecNum = nSocialSecNum; this.employeeWage = minimumWage; this.shift = shift; //---------------- extraWage(); } //--------------------- public void addEmployee(String name, String lName, int nID, String address, int phNum, long nSocialSecNum, double minimumWage, String shift){ Employees employee = new Employees(name, lName, nID, address, phNum, nSocialSecNum, minimumWage, shift); employeesArrayList.add(employee); addToAllStaff(); } void addToAllStaff(){ System.out.println(&quot;(Class Employees) employees size: &quot; + employeesArrayList.size()); for (int i = 0; i &lt; employeesArrayList.size(); i++){ System.out.println(&quot;Employee names: &quot; + employeesArrayList.get(i).getName()); System.out.println(&quot;Employee names: &quot; + employeesArrayList.get(i).name); } allStaff.addEmployees(employeesArrayList); } } </code></pre> <p>In the class &quot;AllStaff&quot;, is where I don't have access to the attributes</p> <pre><code>public class AllStaff { static ArrayList &lt;AllStaff&gt; employeesArrayList; public AllStaff(){ } public void addEmployees(ArrayList listOfEmployees){ System.out.println(&quot;List of employees size: &quot; + listOfEmployees.size()); for (int i = 0; i &lt; listOfEmployees.size(); i++){ System.out.println(&quot;Employee names: &quot; + listOfEmployees.get(i).getName()); System.out.println(&quot;Employee names: &quot; + listOfEmployees.get(i).name); } this.employeesArrayList = listOfEmployees; } </code></pre> <p>For the whole code, please visit this link: <a href="https://github.com/OrlandoVSilva/test-to-github/tree/master/test-to-github/src/mercado" rel="nofollow noreferrer">https://github.com/OrlandoVSilva/test-to-github/tree/master/test-to-github/src/mercado</a></p> <p>I hope this question has everything you need. Thanks</p>
[ { "answer_id": 74448567, "author": "aatwork", "author_id": 14263933, "author_profile": "https://Stackoverflow.com/users/14263933", "pm_score": 1, "selected": false, "text": "public void addEmployees(ArrayList<Employees> listOfEmployees){\n" }, { "answer_id": 74448789, "author": "Ruendan", "author_id": 13713476, "author_profile": "https://Stackoverflow.com/users/13713476", "pm_score": 3, "selected": true, "text": "addEmployees(ArrayList listOfEmployees)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17703613/" ]
74,448,466
<p>how could I know which domain are used for the download of my docker image ?</p> <p>I need it cause the server I'm using only a allow a specific list of domain name for outside traffic.</p>
[ { "answer_id": 74448567, "author": "aatwork", "author_id": 14263933, "author_profile": "https://Stackoverflow.com/users/14263933", "pm_score": 1, "selected": false, "text": "public void addEmployees(ArrayList<Employees> listOfEmployees){\n" }, { "answer_id": 74448789, "author": "Ruendan", "author_id": 13713476, "author_profile": "https://Stackoverflow.com/users/13713476", "pm_score": 3, "selected": true, "text": "addEmployees(ArrayList listOfEmployees)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448466", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15249330/" ]
74,448,485
<p>I need to change the following field to text like this:</p> <p>0-250000 to '$0 to $250,000'</p> <p>I have to do it multiple times. Is there a way to automate this? For a variety of numbers..</p> <p>I have been doing it manually and it takes a long time</p>
[ { "answer_id": 74448623, "author": "Warcupine", "author_id": 11643528, "author_profile": "https://Stackoverflow.com/users/11643528", "pm_score": 2, "selected": false, "text": "Find" }, { "answer_id": 74448690, "author": "Pᴇʜ", "author_id": 3219613, "author_profile": "https://Stackoverflow.com/users/3219613", "pm_score": 2, "selected": false, "text": "0-250000" }, { "answer_id": 74448732, "author": "Scott Craner", "author_id": 4851590, "author_profile": "https://Stackoverflow.com/users/4851590", "pm_score": 3, "selected": false, "text": "=TEXTJOIN(\" to \",,DOLLAR(TEXTSPLIT(A1,\"-\"),0))\n" }, { "answer_id": 74448994, "author": "Mahboob Alam", "author_id": 6346918, "author_profile": "https://Stackoverflow.com/users/6346918", "pm_score": 0, "selected": false, "text": "import pandas as pd\n\ndata = pd.read_excel('split.xlsx')\n\ndata1 = data['ColumnA'].str.split('-', expand=True)\n\nmerge_value = \"$\" + data1[0] + \" to \" + \"$\" + data1[[1]]\n\ndata['Final'] = merge_value\n\ndata = data[['ColumnA','Final']]\n\ndata.to_excel(\"split_final.xlsx\", index=False)\n" }, { "answer_id": 74449922, "author": "JvdV", "author_id": 9758194, "author_profile": "https://Stackoverflow.com/users/9758194", "pm_score": 2, "selected": false, "text": "=SUBSTITUTE(\"$\"&A1,\"-\",\" to $\")\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511781/" ]
74,448,486
<p>I have the following 4 components:</p> <pre><code>&lt;app-game-control (intervalFired)=&quot;onEmittedCount($event)&quot;&gt;&lt;/app-game-control&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-xs-2&quot;&gt; &lt;app-odd *ngFor=&quot;let evenNumber of arrEvenNumber;index as i&quot; [number]=&quot;evenNumber&quot; &gt; &lt;/app-odd&gt; &lt;/div&gt; &lt;div class=&quot;col-xs-2&quot;&gt; &lt;app-even *ngFor=&quot;let oddNumber of arrOddNumber&quot; [number]=&quot;oddNumber&quot;&gt; &lt;/app-even&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>the fourth component would be app.module, which is the parent component</p> <p>here is the odd component::</p> <pre><code>&lt;p class=&quot;odd&quot;&gt;odd - {{number}}&lt;/p&gt; </code></pre> <p>I want to make the class 'odd' have a red background. I can achieve that by adding the style to odd.component.css</p> <p>I want to add the styling to the parent component at 'app.component.css'</p> <p>how do I do that?</p> <p>I tried the following aswell but no luck::</p> <pre><code>&lt;app-game-control (intervalFired)=&quot;onEmittedCount($event)&quot;&gt;&lt;/app-game-control&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-xs-2&quot;&gt; &lt;app-odd *ngFor=&quot;let evenNumber of arrEvenNumber;index as i&quot; [number]=&quot;evenNumber&quot; &gt; &lt;/app-odd&gt; &lt;/div&gt; &lt;div class=&quot;col-xs-2&quot;&gt; &lt;app-even class=&quot;even&quot; *ngFor=&quot;let oddNumber of arrOddNumber&quot; [number]=&quot;oddNumber&quot;&gt; &lt;/app-even&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>app.module.css::</p> <pre><code>.even { background-color: red; } </code></pre>
[ { "answer_id": 74448685, "author": "Rajat", "author_id": 3266218, "author_profile": "https://Stackoverflow.com/users/3266218", "pm_score": 0, "selected": false, "text": ":host ::ng-deep .odd {\n background: red;\n}\n" }, { "answer_id": 74448745, "author": "Sachila Ranawaka", "author_id": 6428638, "author_profile": "https://Stackoverflow.com/users/6428638", "pm_score": 0, "selected": false, "text": "@Component({\n selector: 'app-odd',\n templateUrl: './odd.component.html',\n styleUrls: ['./odd.component.scss'], \n encapsulation: ViewEncapsulation.None,\n" }, { "answer_id": 74449002, "author": "James Griffin", "author_id": 8661238, "author_profile": "https://Stackoverflow.com/users/8661238", "pm_score": 3, "selected": true, "text": "ViewEncapsulation.None" }, { "answer_id": 74450756, "author": "Nehal", "author_id": 5556177, "author_profile": "https://Stackoverflow.com/users/5556177", "pm_score": 1, "selected": false, "text": "styles.scss" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17281101/" ]
74,448,527
<p>I would like to filter out rows based on two column, one column is the ID and the other is a string of IDs (collapses by &quot;,&quot;) that should be kept.</p> <p>Example:</p> <pre><code> library(dplyr) mtcars2 &lt;- mtcars%&gt;% mutate(carb_l=letters[carb], # This is the ID carb_list=&quot;c,f,h&quot;)%&gt;% #IDs to keep select(-mpg,-cyl,-disp)# for clarity head(mtcars2) hp drat wt qsec vs am gear carb carb_l carb_list 1 110 3.90 2.620 16.46 0 1 4 4 d c,f,h 2 110 3.90 2.875 17.02 0 1 4 4 d c,f,h 3 93 3.85 2.320 18.61 1 1 4 1 a c,f,h 4 110 3.08 3.215 19.44 1 0 3 1 a c,f,h 5 175 3.15 3.440 17.02 0 0 3 2 b c,f,h 6 105 2.76 3.460 20.22 1 0 3 1 a c,f,h </code></pre> <p>Expected output:</p> <pre><code>&gt; mtcars2%&gt;%filter((carb_l %in%c(&quot;c&quot;,&quot;f&quot;,&quot;h&quot;))) hp drat wt qsec vs am gear carb carb_l carb_list 1 180 3.07 4.07 17.4 0 0 3 3 c c,f,h 2 180 3.07 3.73 17.6 0 0 3 3 c c,f,h 3 180 3.07 3.78 18.0 0 0 3 3 c c,f,h 4 175 3.62 2.77 15.5 0 1 5 6 f c,f,h 5 335 3.54 3.57 14.6 0 1 5 8 h c,f,h </code></pre>
[ { "answer_id": 74448584, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": false, "text": "mtcars2 %>% \n filter(carb_l %in% strsplit(mtcars2$carb_list[1], \",\")[[1]])\n hp drat wt qsec vs am gear carb carb_l carb_list\nMerc 450SE 180 3.07 4.07 17.4 0 0 3 3 c c,f,h\nMerc 450SL 180 3.07 3.73 17.6 0 0 3 3 c c,f,h\nMerc 450SLC 180 3.07 3.78 18.0 0 0 3 3 c c,f,h\nFerrari Dino 175 3.62 2.77 15.5 0 1 5 6 f c,f,h\nMaserati Bora 335 3.54 3.57 14.6 0 1 5 8 h c,f,h\n" }, { "answer_id": 74448618, "author": "Sotos", "author_id": 5635580, "author_profile": "https://Stackoverflow.com/users/5635580", "pm_score": 3, "selected": true, "text": "rowwise()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17918739/" ]
74,448,563
<p>I am creating react context that requires an initial value like these</p> <pre><code>export const HotelSearchContext = createContext&lt;HotelSearch&gt;({ checkInDate: null, checkOutDate: null, setCheckInDate: null, setCheckOutDate: null, }); </code></pre> <p>Type <strong>HotelSearch</strong></p> <pre><code>export interface HotelSearch { checkInDate: Date | null; checkOutDate: Date | null; setCheckInDate: React.Dispatch&lt;React.SetStateAction&lt;Date | null&gt;&gt;; setCheckOutDate: React.Dispatch&lt;React.SetStateAction&lt;Date | null&gt;&gt;; } </code></pre> <p>I want to use the setter function of a state in a child component that is way down in the component tree.</p> <pre><code> &lt;HotelSearchContext.Provider value={{ checkInDate, checkOutDate, setCheckInDate, setCheckOutDate, }} &gt; {menuWide ? renderTab() : renderResults()} &lt;/HotelSearchContext.Provider&gt; </code></pre> <p><strong><strong>Question</strong> When writing the default value for the createContext function I have to write a &quot;default&quot; value for the function. <strong>Remember</strong> context is created <strong>Outside</strong> the parent component so I can't access the actual set state function.</strong></p> <p>My first option was writing null for the function key but I got an error <strong>Type 'null' is not assignable to type 'Dispatch&lt;SetStateAction&lt;Date | null&gt;&gt;'</strong>.</p> <p>For other properties, I can safely write null and be done with it. For functions it's tricky. Please help.</p>
[ { "answer_id": 74448584, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": false, "text": "mtcars2 %>% \n filter(carb_l %in% strsplit(mtcars2$carb_list[1], \",\")[[1]])\n hp drat wt qsec vs am gear carb carb_l carb_list\nMerc 450SE 180 3.07 4.07 17.4 0 0 3 3 c c,f,h\nMerc 450SL 180 3.07 3.73 17.6 0 0 3 3 c c,f,h\nMerc 450SLC 180 3.07 3.78 18.0 0 0 3 3 c c,f,h\nFerrari Dino 175 3.62 2.77 15.5 0 1 5 6 f c,f,h\nMaserati Bora 335 3.54 3.57 14.6 0 1 5 8 h c,f,h\n" }, { "answer_id": 74448618, "author": "Sotos", "author_id": 5635580, "author_profile": "https://Stackoverflow.com/users/5635580", "pm_score": 3, "selected": true, "text": "rowwise()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19124826/" ]
74,448,566
<p>This is the workflow I need to accomplish:</p> <ol> <li>Validate the date format of all dates in column_1 and column_2.</li> <li>If date is not in either format: mm/dd/yy hh:mm or mm/dd/yyyy hh:mm</li> <li><em>Need assistance</em> - Print the non-matching values.</li> </ol> <p><strong>Note:</strong> I do not know what format the dates will be in and some will not be dates at all.</p> <p>Sample input data CSV:</p> <pre><code>column_1 column_2 8/22/22 15:27 8/24/22 15:27 8/23/22 15:27 Tuesday, August 23, 2022 8/24/22 15:27 abc123 8/25/22 15:27 8/25/2022 15:27 8/26/22 15:27 8/26/2022 18:27 8/26/22 15:27 8/22/22 </code></pre> <p>The following method always throws an exception, as designed, when the <code>to_datetime()</code> function returns a ValueError. How can I validate the date and then capture the values that <strong>do not</strong> match <strong>format_one</strong> or <strong>format_two</strong>?</p> <pre><code>df = pd.read_csv('input.csv', encoding='ISO-8859-1', dtype=str) date_columns = ['column_1', 'column_2'] format_one = '%m/%d/%y %H:%M' format_two = '%m/%d/%Y %H:%M' for column in date_columns: for item in df[column]: try: if pd.to_datetime(df[item], format=format_one): print('format 1: ' + item) elif pd.to_datetime(df[item], format=format_two): print('format 2: ' + item) else: print('unknown format: ' + item) except Exception as e: print('Exception:' ) print(e) </code></pre> <p>Output:</p> <pre><code>Exception: '8/22/22 15:27' Exception: '8/23/22 15:27' Exception: '8/24/22 15:27' Exception: '8/25/22 15:27' Exception: '8/26/22 15:27' Exception: '8/26/22 15:27' Exception: '8/24/22 15:27' Exception: 'Tuesday, August 23, 2022' Exception: 'abc123' Exception: '8/25/2022 15:27' Exception: '8/26/2022 18:27' Exception: '8/22/22' </code></pre> <p>Desired output:</p> <pre><code>Exception: 'Tuesday, August 23, 2022' Exception: 'abc123' Exception: '8/22/22' </code></pre> <p><em>Thank you.</em></p>
[ { "answer_id": 74448584, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": false, "text": "mtcars2 %>% \n filter(carb_l %in% strsplit(mtcars2$carb_list[1], \",\")[[1]])\n hp drat wt qsec vs am gear carb carb_l carb_list\nMerc 450SE 180 3.07 4.07 17.4 0 0 3 3 c c,f,h\nMerc 450SL 180 3.07 3.73 17.6 0 0 3 3 c c,f,h\nMerc 450SLC 180 3.07 3.78 18.0 0 0 3 3 c c,f,h\nFerrari Dino 175 3.62 2.77 15.5 0 1 5 6 f c,f,h\nMaserati Bora 335 3.54 3.57 14.6 0 1 5 8 h c,f,h\n" }, { "answer_id": 74448618, "author": "Sotos", "author_id": 5635580, "author_profile": "https://Stackoverflow.com/users/5635580", "pm_score": 3, "selected": true, "text": "rowwise()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2325014/" ]
74,448,602
<p>I have a multiple tag in my webpage with the same class called price. Each tag is of that form</p> <pre><code>&lt;p class=&quot;price&quot;&gt;Price: 45$&lt;/p&gt; &lt;p class=&quot;price&quot;&gt;Price: 32$&lt;/p&gt; </code></pre> <p>What I need at the end is to separate the price text in a span and the price in another so that it will be like that</p> <pre><code>&lt;p class=&quot;price&quot;&gt;&lt;span class='h1'&gt;Price:&lt;/span&gt; &lt;span class=&quot;h2&quot;&gt;45$&lt;/span&gt;&lt;/p&gt; </code></pre> <p>This is what I do until now but problem is that the span is not a tag but is insert as a simple string</p> <p><a href="https://i.stack.imgur.com/XOVEU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XOVEU.png" alt="enter image description here" /></a></p> <pre><code>let price = $(&quot;.price&quot;); for (let i = 0; i &lt; price.length; i++) { let priceTitle = price[i].innerText.split(&quot;:&quot;)[0]; let priceToPay = price[i].innerText.split(&quot;:&quot;)[1]; price[i].innerText = ''; //Delete content of price $(&quot;.price&quot;)[i].append(&quot;&lt;span class='h1'&gt;&quot;+ priceTitle+&quot;&lt;/span&gt; &lt;span class='h2'&gt;&quot;+ priceToPay +&quot;&lt;/span&gt;&quot;); } } </code></pre> <p>Can you help me fix this issue and perhaps optimize the code I already do.</p>
[ { "answer_id": 74448584, "author": "Jilber Urbina", "author_id": 1315767, "author_profile": "https://Stackoverflow.com/users/1315767", "pm_score": 2, "selected": false, "text": "mtcars2 %>% \n filter(carb_l %in% strsplit(mtcars2$carb_list[1], \",\")[[1]])\n hp drat wt qsec vs am gear carb carb_l carb_list\nMerc 450SE 180 3.07 4.07 17.4 0 0 3 3 c c,f,h\nMerc 450SL 180 3.07 3.73 17.6 0 0 3 3 c c,f,h\nMerc 450SLC 180 3.07 3.78 18.0 0 0 3 3 c c,f,h\nFerrari Dino 175 3.62 2.77 15.5 0 1 5 6 f c,f,h\nMaserati Bora 335 3.54 3.57 14.6 0 1 5 8 h c,f,h\n" }, { "answer_id": 74448618, "author": "Sotos", "author_id": 5635580, "author_profile": "https://Stackoverflow.com/users/5635580", "pm_score": 3, "selected": true, "text": "rowwise()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19533023/" ]
74,448,608
<p>I don't understand why is not working on my code</p> <pre><code>def random_calculation(num): return((num*77 + (90+2-9+3))) while random_calculation: num = int(input(&quot;Pleace enter number: &quot;)) if num == &quot;0&quot;: break else: print(random_calculation(num)) </code></pre> <p>Can you guide me what is wrong here, i really dont understand</p>
[ { "answer_id": 74448765, "author": "Sembei Norimaki", "author_id": 20396240, "author_profile": "https://Stackoverflow.com/users/20396240", "pm_score": 2, "selected": true, "text": "while random_calculation" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511870/" ]
74,448,666
<p>In Docker compose, is it possible for a container A to wait for a container B to finish (aka, stop running) before starting?</p> <p>I have 3 containers in my docker compose:</p> <ul> <li>Container A is a MySQL database</li> <li>Container B is a Flyway container that has some SQL migrations on a certain schema1. After running the migrations, it stops.</li> <li>Container C is a Flyway container that has some SQL migrations on a certain schema2 and adds some data to both schema1 and schema2. It does also stop after running the migrations.</li> </ul> <p>I need container C to wait for B to finish otherwise the migrations are going to fail.</p>
[ { "answer_id": 74462587, "author": "RabidTunes", "author_id": 3730586, "author_profile": "https://Stackoverflow.com/users/3730586", "pm_score": 0, "selected": false, "text": "restart" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3730586/" ]
74,448,683
<p>I have some data taken at different time points in wide format, and need to convert it to long format to aid with analysis and to merge it with another dataset.</p> <p>The format of the data is (where A_0 means value of A at time 0, A_15 means value at time 15):</p> <pre><code>import pandas as pd df_wide = pd.DataFrame({'Subject': ['AA', 'BB', 'CC', 'DD'], 'A_0': [1, 2, 3, 4], 'A_15': [2, 3, 4, 5], 'A_30': [3, 4, 5, 6], 'B_0': [1, 2, 3, 4], 'B_15': [2, 3, 4, 5], 'B_30': [3, 4, 5, 6], 'C_0': [1, 2, 3, 4], 'C_15': [2, 3, 4, 5], 'C_30': [3, 4, 5, 6] } ) df_wide </code></pre> <pre><code> Subject A_0 A_15 A_30 B_0 B_15 B_30 C_0 C_15 C_30 0 AA 1 2 3 1 2 3 1 2 3 1 BB 2 3 4 2 3 4 2 3 4 2 CC 3 4 5 3 4 5 3 4 5 3 DD 4 5 6 4 5 6 4 5 6 </code></pre> <p>I wish to convert this to long format and generate the variable time as follow:</p> <pre><code>df_long = pd.DataFrame({'Subject': ['AA', 'AA', 'AA', 'BB', 'BB', 'BB', 'CC', 'CC', 'CC', 'DD', 'DD', 'DD'], 'Time': [0, 15, 30, 0, 15, 30, 0, 15, 30, 0, 15, 30], 'A': [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6], 'B': [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6], 'C': [1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6], }) df_long </code></pre> <pre><code> Subject Time A B C 0 AA 0 1 1 1 1 AA 15 2 2 2 2 AA 30 3 3 3 3 BB 0 2 2 2 4 BB 15 3 3 3 5 BB 30 4 4 4 6 CC 0 3 3 3 7 CC 15 4 4 4 8 CC 30 5 5 5 9 DD 0 4 4 4 10 DD 15 5 5 5 11 DD 30 6 6 6 </code></pre> <p>I've read the pivot and melt functions but can't quite get my head around it - any assistance would be greatly appreciated.</p> <p>Have tired pivot and melt but unsure how to generate the time variable.</p>
[ { "answer_id": 74449215, "author": "Andrej Kesely", "author_id": 10035985, "author_profile": "https://Stackoverflow.com/users/10035985", "pm_score": 2, "selected": false, "text": "pd.wide_to_long" }, { "answer_id": 74449337, "author": "Liutprand", "author_id": 11052072, "author_profile": "https://Stackoverflow.com/users/11052072", "pm_score": 1, "selected": true, "text": "df_long=pd.melt (df_wide, id_vars=[\"Subject\"], var_name=\"Time\")\ndf_long[[\"Time_letter\", \"Time\"]]=df_long[\"Time\"].str.split(\"_\", expand=True)\ndf_final=pd.pivot(df_long, index=[\"Subject\", \"Time\"], columns=\"Time_letter\", values=\"value\")\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20510070/" ]
74,448,687
<p>I have this custom component in vue callled &quot;dm-vehicle-spec&quot;</p> <pre><code> &lt;dm-vehicle-spec @_handleRemoveSpec=&quot;_handleRemoveSpec&quot; v-for=&quot;spec, index in vehicleSpecs&quot; :key=&quot;index&quot; :index=&quot;index&quot; :spec=&quot;spec&quot;&gt;&lt;/dm-vehicle-spec&gt; </code></pre> <p>which looks like the following</p> <pre><code>&lt;script&gt; export default { props: [&quot;spec&quot;], data() { return { specName: null, specValue: null, } }, mounted() { if (this.spec.detail_name &amp;&amp; this.spec.detail_value) { this.specName = this.spec.detail_name; this.specValue = this.spec.detail_value; } }, computed: { getSpecNameInputName() { return `spec_${this.spec.id}_name`; }, getSpecValueInputName() { return `spec_${this.spec.id}_value`; }, }, methods: { _handleRemoveSpec() { this.$emit(&quot;_handleRemoveSpec&quot;, this.spec.id); } }, } &lt;/script&gt; &lt;template&gt; &lt;div class=&quot;specs-row flex gap-2 w-full items-center&quot;&gt; &lt;div class=&quot;col-1 w-5/12&quot;&gt; &lt;input placeholder=&quot;Naam&quot; type=&quot;text&quot; :id=&quot;getSpecNameInputName&quot; class=&quot;w-full h-12 spec_name rounded-lg border-2 border-primary pl-2&quot; v-model=&quot;specName&quot;&gt; &lt;/div&gt; &lt;div class=&quot;col-2 w-5/12&quot;&gt; &lt;input placeholder=&quot;Waarde&quot; type=&quot;text&quot; :id=&quot;getSpecValueInputName&quot; class=&quot;w-full h-12 spec_name rounded-lg border-2 border-primary pl-2&quot; v-model=&quot;specValue&quot;&gt; &lt;/div&gt; &lt;div @click=&quot;_handleRemoveSpec&quot; class=&quot;col-3 w-2/12 flex items-center justify-center&quot;&gt; &lt;i class=&quot;fas fa-trash text-lg&quot;&gt;&lt;/i&gt; &lt;/div&gt; &lt;/div&gt; &lt;/template&gt; </code></pre> <p>so when i have 3 specs, 1 from the database and 2 customs i have the following array <strong>vehicleSpecs</strong> (Which i loop over)</p> <pre><code>[ {&quot;id&quot;:23,&quot;vehicle_id&quot;:&quot;1&quot;,&quot;detail_name&quot;:&quot;Type&quot;,&quot;detail_value&quot;:&quot;Snel&quot;,&quot;created_at&quot;:&quot;2022-11-07T19:06:26.000000Z&quot;,&quot;updated_at&quot;:&quot;2022-11-07T19:06:26.000000Z&quot;,&quot;deleted_at&quot;:null}, {&quot;id&quot;:24}, {&quot;id&quot;:25} ] </code></pre> <p><a href="https://i.stack.imgur.com/ezLWz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ezLWz.png" alt="enter image description here" /></a></p> <p>so lets say i want to remove the second item from the list so the one with test1 as values, then the array looks like</p> <pre><code>[{&quot;id&quot;:23,&quot;vehicle_id&quot;:&quot;1&quot;,&quot;detail_name&quot;:&quot;Type&quot;,&quot;detail_value&quot;:&quot;Snel&quot;,&quot;created_at&quot;:&quot;2022-11-07T19:06:26.000000Z&quot;,&quot;updated_at&quot;:&quot;2022-11-07T19:06:26.000000Z&quot;,&quot;deleted_at&quot;:null},{&quot;id&quot;:25}] </code></pre> <p>So the second array item is removed and thats correct because object with id 24 no longer exsist but my html shows</p> <p><a href="https://i.stack.imgur.com/1qPBW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1qPBW.png" alt="enter image description here" /></a></p> <p>that the value for object with id 24 still exists but the value for object with id 25 is removed, how is that possible?</p> <p>If u need any more code or explaination, let me know</p> <p>Any help or suggestions are welcome!</p>
[ { "answer_id": 74449316, "author": "Nikola Pavicevic", "author_id": 11989189, "author_profile": "https://Stackoverflow.com/users/11989189", "pm_score": 0, "selected": false, "text": "Vue.component('dmVehicleSpec', {\n template: `\n <div class=\"specs-row flex gap-2 w-full items-center\">\n <div class=\"col-1 w-5/12\">\n <input placeholder=\"Naam\" type=\"text\" :id=\"getSpecNameInputName\" class=\"w-full h-12 spec_name rounded-lg border-2 border-primary pl-2\" v-model=\"specName\">\n </div>\n <div class=\"col-2 w-5/12\">\n <input placeholder=\"Waarde\" type=\"text\" :id=\"getSpecValueInputName\" class=\"w-full h-12 spec_name rounded-lg border-2 border-primary pl-2\" v-model=\"specValue\">\n </div>\n <div @click=\"handleRemoveSpec\" class=\"col-3 w-2/12 flex items-center justify-center\">del\n <i class=\"fas fa-trash text-lg\"></i>\n </div>\n </div>\n `,\n props: [\"spec\"],\n data() {\n return {\n specName: null,\n specValue: null,\n }\n },\n watch: {\n spec(val) {\n this.setSpec(val)\n }\n }, \n mounted() {\n this.setSpec(this.spec)\n }, \n computed: {\n getSpecNameInputName() {\n return `spec_${this.spec.id}_name`;\n },\n getSpecValueInputName() {\n return `spec_${this.spec.id}_value`;\n },\n },\n methods: {\n handleRemoveSpec() {\n this.$emit(\"handleremovespec\", this.spec.id);\n },\n setSpec(val) {\n if (val.detail_name && val.detail_value) {\n this.specName = val.detail_name;\n this.specValue = val.detail_value;\n }\n }\n },\n})\nnew Vue({\n el: \"#demo\",\n data() {\n return {\n vehicleSpecs: [{\"id\":23, \"vehicle_id\":\"1\" ,\"detail_name\":\"Type\", \"detail_value\":\"Snel\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}, {\"id\":24, \"vehicle_id\":\"1\", \"detail_name\":\"Type1\", \"detail_value\":\"Snel1\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}, {\"id\":25, \"vehicle_id\":\"1\", \"detail_name\":\"Type2\", \"detail_value\":\"Snel2\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}]\n }\n },\n methods: {\n handleRemoveSpec(id) {\n this.vehicleSpecs = this.vehicleSpecs.filter(v => v.id !== id)\n }\n }\n})" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15664021/" ]
74,448,701
<p>I am currently working on a task where I need to synchronize the data, example:</p> <p>Client makes a request to get data to the API (API has access to the database), client received the data and saves it to the list. That list is used for some time etc..... Then in the meanwhile another client accesses the same API and database and makes some changes... to the same table... After a while the first client want's to update his current data, since the table is quite big let's say 10 thousand records, grabbing the entire table again is inefficient. I would like to grab only the records that have been modified,deleted, or newly created. And then update the current list the client 1 has. if the client has no records, he classifies all of them as newly created (at start up) and just grabs them all. I would like to do as much checking on the client's side.</p> <p>How would I go about this ? I do have fields such as Modified, LastSync, IsDeleted. So I can find the records I need but main issue is how to do it efficiently with minimal repetition.</p> <p>At the moment I tried to get all the rows at first, then after I want to update (Synchronize) I get the minimal required info LastSync Modified IsDeleted Key, from the API, which I compare with what I have on the client and then send only keys of the rows that don't match to the server to get the entire values that match the keys. But I am not sure about efficiency of this also... not sure how to update the current list with those values efficiently the only way I can think of is using loop in loop to compare keys and update the list, but I know it's not a good approach.</p>
[ { "answer_id": 74449316, "author": "Nikola Pavicevic", "author_id": 11989189, "author_profile": "https://Stackoverflow.com/users/11989189", "pm_score": 0, "selected": false, "text": "Vue.component('dmVehicleSpec', {\n template: `\n <div class=\"specs-row flex gap-2 w-full items-center\">\n <div class=\"col-1 w-5/12\">\n <input placeholder=\"Naam\" type=\"text\" :id=\"getSpecNameInputName\" class=\"w-full h-12 spec_name rounded-lg border-2 border-primary pl-2\" v-model=\"specName\">\n </div>\n <div class=\"col-2 w-5/12\">\n <input placeholder=\"Waarde\" type=\"text\" :id=\"getSpecValueInputName\" class=\"w-full h-12 spec_name rounded-lg border-2 border-primary pl-2\" v-model=\"specValue\">\n </div>\n <div @click=\"handleRemoveSpec\" class=\"col-3 w-2/12 flex items-center justify-center\">del\n <i class=\"fas fa-trash text-lg\"></i>\n </div>\n </div>\n `,\n props: [\"spec\"],\n data() {\n return {\n specName: null,\n specValue: null,\n }\n },\n watch: {\n spec(val) {\n this.setSpec(val)\n }\n }, \n mounted() {\n this.setSpec(this.spec)\n }, \n computed: {\n getSpecNameInputName() {\n return `spec_${this.spec.id}_name`;\n },\n getSpecValueInputName() {\n return `spec_${this.spec.id}_value`;\n },\n },\n methods: {\n handleRemoveSpec() {\n this.$emit(\"handleremovespec\", this.spec.id);\n },\n setSpec(val) {\n if (val.detail_name && val.detail_value) {\n this.specName = val.detail_name;\n this.specValue = val.detail_value;\n }\n }\n },\n})\nnew Vue({\n el: \"#demo\",\n data() {\n return {\n vehicleSpecs: [{\"id\":23, \"vehicle_id\":\"1\" ,\"detail_name\":\"Type\", \"detail_value\":\"Snel\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}, {\"id\":24, \"vehicle_id\":\"1\", \"detail_name\":\"Type1\", \"detail_value\":\"Snel1\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}, {\"id\":25, \"vehicle_id\":\"1\", \"detail_name\":\"Type2\", \"detail_value\":\"Snel2\", \"created_at\":\"2022-11-07T19:06:26.000000Z\", \"updated_at\":\"2022-11-07T19:06:26.000000Z\", \"deleted_at\":null}]\n }\n },\n methods: {\n handleRemoveSpec(id) {\n this.vehicleSpecs = this.vehicleSpecs.filter(v => v.id !== id)\n }\n }\n})" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13628517/" ]
74,448,716
<p>So I have this huge line-by-line std::string variable which is about 58 thousand lines.<br /> How could I select my entire variable? By clicking and dragging I think it takes about 5 minutes :)</p> <p>This is how I stored my string:</p> <pre><code>std::string str = &quot;504b0304140000000800b3ab584fd82c4d1ec01b00002a45000007000000&quot; &quot;4348414e474553955bfb73db4872fed95775ffc364cf1593673e44ca92bd&quot; &quot;aa3b27b6a4f5ea4eaf58f2de6ea5121c080c499cf03a0c2089fbd7a7bfee&quot; &quot;...&quot;; </code></pre> <p>It goes for about 58 thousand lines, how could I select it?</p>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17111457/" ]
74,448,721
<p>I have a problem with creating a matrix with user input and rotate it 90 degrees. Anyone knows why there is a problem with the range of the matrix?</p> <p>The problem is when the elements are entered and it only shows up like 2 or 3 elements even if i write that I want 16..</p> <pre><code>public static void main(String args[]) { int m, n, i, j; Scanner sc = new Scanner(System.in); System.out.print(&quot;Enter the number of rows: &quot;); //taking row as input m = sc.nextInt(); System.out.print(&quot;Enter the number of columns: &quot;); //taking column as input n = sc.nextInt(); // Declaring the two-dimensional matrix int[][] array = new int[m][n]; // Read the matrix values System.out.println(&quot;Enter the elements of the array: &quot;); //loop for row for (i = 0; i &lt; m; i++) //inner for loop for column for (j = 0; j &lt; n; j++) array[i][j] = sc.nextInt(); //accessing array elements System.out.println(&quot;Elements of the array are: &quot;); for (i = 0; i &lt; m; i++) { for (j = 0; j &lt; n; j++) //prints the array elements System.out.print(array[i][j] + &quot; &quot;); //throws the cursor to the next line System.out.println(); System.out.println(&quot;The matrix after being rotated 90 degrees clockwise: &quot;); rotate(array); } } static int M = 4; // Method to rotate the matrix 90 degree clockwise static void rotate(int[][] arr) { // printing the matrix on the basis of the index for (int j = 0; j &lt; M; j++) { for (int i = M - 4; i &gt;= 0; i--) System.out.print(arr[i][j] + &quot; &quot;); System.out.println(); } } } </code></pre>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20313901/" ]
74,448,730
<p>I have this array of objects</p> <pre><code>const data = [ { id: 0, ALT_VALUE: 11, DLT_VALUE: 76 }, { id: 1, ALT_VALUE: 80, DLT_VALUE: 48 }, { id: 2, ALT_VALUE: 90, DLT_VALUE: 100 }, { id: 3, ALT_VALUE: 12, DLT_VALUE: 70 }, { id: 4, ALT_VALUE: 90, DLT_VALUE: 100 }, { id: 5, ALT_VALUE: 13, DLT_VALUE: 49 }, { id: 6, ALT_VALUE: 76, DLT_VALUE: 70 }, { id: 7, ALT_VALUE: 9, DLT_VALUE: 15 }, ]; </code></pre> <p>and I would like to filter it dynamically based on this array of objects</p> <pre><code>const filters = [ { parameter: &quot;ALT_VALUE&quot;, min: 8, max: 100 }, { parameter: &quot;DLT_VALUE&quot;, min: 30, max: 50 }, ]; </code></pre> <p>based on the filters, the final result supposed to be</p> <pre><code>[ { id: 5, ALT_VALUE: 13, DLT_VALUE: 49 }, { id: 1, ALT_VALUE: 80, DLT_VALUE: 48 }, ] </code></pre> <p>I tried with this</p> <pre><code>const result = data.filter((el) =&gt; { return filters.filter((f) =&gt; { if (el[f.parameter] &gt; f.min &amp;&amp; el[f.parameter] &lt; f.max) { return el; } }); }); </code></pre> <p>But I get all of the data</p> <pre><code>[ { id: 0, ALT_VALUE: 11, DLT_VALUE: 76 }, { id: 1, ALT_VALUE: 80, DLT_VALUE: 48 }, { id: 2, ALT_VALUE: 90, DLT_VALUE: 100 }, { id: 3, ALT_VALUE: 12, DLT_VALUE: 70 }, { id: 4, ALT_VALUE: 90, DLT_VALUE: 100 }, { id: 5, ALT_VALUE: 13, DLT_VALUE: 49 }, { id: 6, ALT_VALUE: 76, DLT_VALUE: 70 }, { id: 7, ALT_VALUE: 9, DLT_VALUE: 15 } ] </code></pre>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12262686/" ]
74,448,734
<p>what is the best way to check the false &amp; true condition in this case, i have a state set to false initially</p> <pre><code>status: false, </code></pre> <p>The status changes to true if a certain props is present (data-widget) do i need to add the =&quot;true&quot; to the attribut?</p> <pre><code>&lt;div id=&quot;app&quot; data-widget&gt;&lt;/div&gt; // Is it the same thing or i don't need to add the =&quot;true&quot; to the attribut &lt;div id=&quot;app&quot; data-widget=&quot;true&quot;&gt;&lt;/div&gt; </code></pre> <p>Here is how i check a condition, i am confused which one i should use :</p> <pre><code>//Option 1 newData.status = this.props.widget ? true : false //Option 2 newData.status = (typeof this.props.widget !== &quot;undefined&quot;) ? true : false </code></pre> <p>Is there a better/correct way to handle the false &amp; true condition?</p>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9179833/" ]
74,448,753
<p>I have a (somewhat long) list of words. And a function 1 (linsok(lista, elem)) which asks the user for a word, and if the user-inputted word exists in the list, we get a confirmation in the form of exists/does not exist.</p> <p>I then have a 2nd function which for any word in the list will create 4 variations of it (creating 4 concatenations of each word) and append these new words to another list. This function will come in handy in my third function, which I am having trouble constructing.</p> <p>My third function will compare the words in my original list, to the list of my concatenated words. If any word in the concatenated list exists in my orginal list, the function should yield these matches in a list (in the form of [original word, concatenated word] where both are present in the original list). All with the caveat that this third function is to include a function call for the 1st function which asks for user input of a word and produces a confirmation of the word's existence.</p> <p>I have tried to write the function in the form of for item1 in list 2 and for item2 in list 2 but honestly in pretty lost as to how to construct the function. Especially how/where I am to insert my function call to the first function.</p> <p>This is the code as it stands now:</p> <p>`</p> <pre><code>########## UPPGIFT 1 ########## #fil = open('ordlista.txt') lista = open('ordlista.txt').read().split() #print(lista[::100]) ########## UPPGIFT 2 ######### def linsok(lista, elem): #function 1 which returns whether or not a word is present in list if elem in lista: print(elem + ' exists') return True else: print(elem + ' exists not') return False ########## UPPGIFT 3 ########## def kupering(ord): #function which concatenates the words in question nylista = [] if ord in lista: for i in range(len(ord)): nylista.append((ord[i:len(ord)] + ord[:i])) #nylista=nylista[1:] #print(nylista) return nylista #def linsok_kup(lista): #funtion 3 which i have trouble with # def main(): # while elem := input('Ditt ord: '): # linsok(lista,elem) #u2 # # #where i would insert my 3rd function # # if __name__ == '__main__': # main() </code></pre> <p>`</p>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448753", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511891/" ]
74,448,782
<p>I was creating an if-else loop based on the type of variable, to either convert a list of numbers to kilograms, or simply one number, and for some reason I cannot call the variable I created into my main() function. I am a beginner to python and any help would be appreciated. Here is my code:</p> <pre><code># Testing Code def kgToLb(weight): # Return the converted weight (kg) newWeight = [] if type(weight) == list: for w in range(len(weight)): return newWeight.append(weight[w] * 2.20462) return newWeight == weight * 2.20462 def main(): weightList = [-22, 11, 0, 8.2, -8.2] answerKgsList = [-9.979044, 4.989522, 0, 3.71946186, -3.71946186] # Test data for w in range(0, len(weightList)): kgToLb(weightList) correctWeight = weightList == answerKgsList[w] print(correctWeight) print(newWeight) print(&quot;The converted weight is &quot; + str(newWeight[w]) + &quot;. &quot; + str(correctWeight)) main() </code></pre> <p>I tried to change the if-else format to see if it would change anything to no avail.</p>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20511974/" ]
74,448,790
<p>I've created an azure **serverless ** sql database. It seems there is no way to backup/restore this type of databases. I know there is restore to a point in time feature, But I what to download and save database backups my self.</p> <p>Is there a way to backup serverless azure sql databases?</p> <p>1-) There is no Backup/restore option on the database right click 2-) I've tried to use BACKUP T-SQL with azure storage account and storage url from SSMS but this is not supported.</p>
[ { "answer_id": 74449141, "author": "tomiis", "author_id": 16413572, "author_profile": "https://Stackoverflow.com/users/16413572", "pm_score": 0, "selected": false, "text": "Ctrl + Alt + right arrow/arrow" }, { "answer_id": 74449294, "author": "Michael_313", "author_id": 17111457, "author_profile": "https://Stackoverflow.com/users/17111457", "pm_score": 3, "selected": true, "text": "Shift+click" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8744886/" ]
74,448,793
<p>Still learning sql, but I'm not understanding how all the data I'm putting in my tables are set to 0 or NULL ?</p> <p><a href="https://i.stack.imgur.com/VPLIU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VPLIU.png" alt="MySql commands" /></a></p>
[ { "answer_id": 74448869, "author": "Noscere", "author_id": 10728583, "author_profile": "https://Stackoverflow.com/users/10728583", "pm_score": 1, "selected": false, "text": "INSERT INTO users (email, name, forename, pwdssh)\n VALUES ('email', 'name', 'blaa', 'befbf');\n" }, { "answer_id": 74448873, "author": "aatwork", "author_id": 14263933, "author_profile": "https://Stackoverflow.com/users/14263933", "pm_score": 1, "selected": false, "text": "insert into users (email, name, forename, pwhash) values ('mail', name, 'blaa', 'befbf')\n" }, { "answer_id": 74448884, "author": "chrisbyte", "author_id": 8678978, "author_profile": "https://Stackoverflow.com/users/8678978", "pm_score": 2, "selected": true, "text": "VALUES" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16092107/" ]
74,448,821
<p>I am writing a C function <code>GetDeviceList()</code> which must return a list of device names found as strings somehow. The number of devices found and of course the device names themselves will vary each time the function is called.</p> <p>How the function gets the device names is not the scope of this question, but inside the <code>GetDeviceList()</code> function, a <code>char*</code> gets updated in a loop with each new device name found. This <code>char*</code> must then be copied to a list which can be read by the caller.</p> <p>The function, nor the calling function cannot use dynamic memory.</p> <p>What would be the best way to get a list of those strings returned from the function. I am thinking of a 2-dimensional char array passed as an output paramater, but not sure.</p>
[ { "answer_id": 74449359, "author": "Jabberwocky", "author_id": 898348, "author_profile": "https://Stackoverflow.com/users/898348", "pm_score": 2, "selected": false, "text": "GetDeviceList()" }, { "answer_id": 74450159, "author": "chux - Reinstate Monica", "author_id": 2410359, "author_profile": "https://Stackoverflow.com/users/2410359", "pm_score": 0, "selected": false, "text": "int GetDeviceList(size_t size, char **dest)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4768946/" ]
74,448,831
<p><a href="https://i.stack.imgur.com/d2KAv.png" rel="nofollow noreferrer">How to target an element with random id</a></p> <p>I tried to use xpath, but doesn't worked</p>
[ { "answer_id": 74449359, "author": "Jabberwocky", "author_id": 898348, "author_profile": "https://Stackoverflow.com/users/898348", "pm_score": 2, "selected": false, "text": "GetDeviceList()" }, { "answer_id": 74450159, "author": "chux - Reinstate Monica", "author_id": 2410359, "author_profile": "https://Stackoverflow.com/users/2410359", "pm_score": 0, "selected": false, "text": "int GetDeviceList(size_t size, char **dest)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17642160/" ]
74,448,842
<p>My (first) web app uses pydub, which depends on ffmpeg. On my local windows environment, I installed ffmpeg and added the path to the ffmpeg executables to the windows &quot;path&quot; environment variables.</p> <p>It all works locally, but bow that I have deployed my app to PythonAnywhere, the following line in my code is causing an error:</p> <pre><code> sound.export(export_path, format=&quot;mp3&quot;, bitrate=&quot;128k&quot;) </code></pre> <p>I believe the error is because this code relies on ffmpeg.</p> <p>I have read on their forums that ffmpeg is installed for all users on PythonAnywhere. Is there something I need to do to get it to work? Do I need to add the path of the ffmpeg files to the environment variables? I have a .env file with other env variables -- would I need to add something to this?</p>
[ { "answer_id": 74449359, "author": "Jabberwocky", "author_id": 898348, "author_profile": "https://Stackoverflow.com/users/898348", "pm_score": 2, "selected": false, "text": "GetDeviceList()" }, { "answer_id": 74450159, "author": "chux - Reinstate Monica", "author_id": 2410359, "author_profile": "https://Stackoverflow.com/users/2410359", "pm_score": 0, "selected": false, "text": "int GetDeviceList(size_t size, char **dest)" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17072084/" ]
74,448,850
<p>I have a grid, inside which is four divs. The four divs are also <code>display: grid</code>. Inside each of the four divs is a link. One of the links contains text that goes on to an extra line. This makes all the divs in the grid taller. But link <code>hover</code> on the shorter links does not stretch to the bottom of the div. How do I get the links to stretch the full height of the div? So that the full height is clickable and background colour changes?</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>.block-intro { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-column-gap: 3.6rem; } .button { display: grid; align-items: center; font-size: 2.4rem; line-height: 2.8rem; text-align: center; border: 1px solid; } .button a:link { display: block; color: black; padding: 2.1rem; } .button a:visited { display: block; color: black; padding: 2.1rem; } .button a:hover { display: block; color: black; padding: 2.1rem; background-color: rgba(0, 0, 0, 0.1); } .button a:active { display: block; color: black; padding: 2.1rem; background-color: rgba(0, 0, 0, 0.1); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="block-intro"&gt; &lt;div class="button"&gt; &lt;a href="case-studies.php"&gt;One line link&lt;/a&gt; &lt;/div&gt; &lt;div class="button"&gt; &lt;a href="case-studies.php"&gt;One line link&lt;/a&gt; &lt;/div&gt; &lt;div class="button"&gt; &lt;a href="case-studies.php"&gt;Two lines&lt;br&gt;longer link&lt;/a&gt; &lt;/div&gt; &lt;div class="button"&gt; &lt;a href="case-studies.php"&gt;One line link&lt;/a&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74448932, "author": "Boguz", "author_id": 5509709, "author_profile": "https://Stackoverflow.com/users/5509709", "pm_score": 0, "selected": false, "text": "height: 100%" }, { "answer_id": 74448983, "author": "Savado", "author_id": 2482249, "author_profile": "https://Stackoverflow.com/users/2482249", "pm_score": 3, "selected": true, "text": "flex" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2991837/" ]
74,448,864
<p>How do I enable an arm64 extensions such as FEAT_XNX ?</p> <p>I'm working on stage 2 page table execution permission on arm64, currently looking into D5.4.6 section of the manual.</p> <p>It mentions that the XN pair only describe stage 2 controle only when FEAT_XNX is implemented. In my systems it seems that FEAT_XNX is not implemented.</p> <p>I looked in to MMFR4 and other register to perform the check as mentionned in the manual.</p> <p>My question would be, how do I &quot;implement&quot; it ? Is it even up to me or it's a feature only available on certain HW ? Can I add this to Qemu ? Could someone explain to me those FEAT_****** things, what is that exactly ? I can't find ressources that talks about it online.</p> <p>Thanks all</p>
[ { "answer_id": 74449204, "author": "Peter Maydell", "author_id": 4499941, "author_profile": "https://Stackoverflow.com/users/4499941", "pm_score": 3, "selected": true, "text": "cortex-a76" }, { "answer_id": 74449224, "author": "Nate Eldredge", "author_id": 634919, "author_profile": "https://Stackoverflow.com/users/634919", "pm_score": 0, "selected": false, "text": "FEAT_XXX" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18940368/" ]
74,448,871
<p>In a custom function, I want to run an <code>if</code> condition if my vector only has one unique value. I can use <code>length(unique(x)) == 1</code>. However, I think that this could be more efficient: instead of getting all the unique values in the vector and then count them, I could just stop after having found one value that is different from the first one:</p> <pre class="lang-r prettyprint-override"><code># Should be TRUE test &lt;- rep(1, 1e7) bench::mark( length(unique(test)) == 1, all(test == test[1]) ) #&gt; Warning: Some expressions had a GC in every iteration; so filtering is disabled. #&gt; # A tibble: 2 × 6 #&gt; expression min median `itr/sec` mem_alloc `gc/sec` #&gt; &lt;bch:expr&gt; &lt;bch:tm&gt; &lt;bch:tm&gt; &lt;dbl&gt; &lt;bch:byt&gt; &lt;dbl&gt; #&gt; 1 length(unique(test)) == 1 154.1ms 158.6ms 6.31 166.1MB 6.31 #&gt; 2 all(test == test[1]) 38.1ms 49.2ms 19.6 38.1MB 3.92 # Should be FALSE test2 &lt;- rep(c(1, 2), 1e7) bench::mark( length(unique(test2)) == 1, all(test2 == test2[1]) ) #&gt; Warning: Some expressions had a GC in every iteration; so filtering is disabled. #&gt; # A tibble: 2 × 6 #&gt; expression min median `itr/sec` mem_alloc `gc/sec` #&gt; &lt;bch:expr&gt; &lt;bch:tm&gt; &lt;bch:tm&gt; &lt;dbl&gt; &lt;bch:byt&gt; &lt;dbl&gt; #&gt; 1 length(unique(test2)) == 1 341.2ms 386.1ms 2.59 332.3MB 2.59 #&gt; 2 all(test2 == test2[1]) 59.5ms 81.1ms 11.5 76.3MB 1.92 </code></pre> <p>It is indeed more efficient.</p> <p>Now, suppose that I want to replace <code>length(unique(x)) == 2</code>. I could probably do something similar to stop as soon as I find 3 different values but I don't see how can I generalize this to replace <code>length(unique(x)) == n</code> where <code>n</code> can be any positive integer.</p> <p><strong>Is there an efficient and general way to do this?</strong></p> <p>(I'm looking for a solution in base R, and if you can improve the benchmark for <code>n = 1</code>, feel free to suggest).</p>
[ { "answer_id": 74449034, "author": "Carl Witthoft", "author_id": 884372, "author_profile": "https://Stackoverflow.com/users/884372", "pm_score": 0, "selected": false, "text": "if(mean(x) == x[1])" }, { "answer_id": 74449931, "author": "jblood94", "author_id": 9463489, "author_profile": "https://Stackoverflow.com/users/9463489", "pm_score": 1, "selected": false, "text": "n = 1" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11598948/" ]
74,448,872
<p>I have this:</p> <pre><code>class PageService { static int CurrentPage = 0; } </code></pre> <p>And I have this:</p> <pre><code>import 'package:flutter/material.dart'; import '../services/page_service.dart'; class NavigationMenu extends StatefulWidget { const NavigationMenu({super.key}); @override State&lt;NavigationMenu&gt; createState() =&gt; _NavigationMenuState(); } class _NavigationMenuState extends State&lt;NavigationMenu&gt; { @override Widget build(BuildContext context) { return NavigationBar( destinations: const [ NavigationDestination( icon: Icon( Icons.home, color: Colors.white, ), label: &quot;Home&quot;), NavigationDestination(icon: Icon(Icons.forum), label: &quot;Forums&quot;), ], backgroundColor: const Color.fromARGB(255, 154, 15, 5), onDestinationSelected: (int index) { setState(() { PageService.CurrentPage = index; int test = PageService.CurrentPage; print(&quot;SETTING $test&quot;); }); }, selectedIndex: PageService.CurrentPage, ); } } </code></pre> <p>Then in my main, I have this:</p> <pre><code>void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'BeastBurst', theme: ThemeData( // This is the theme of your application. // // Try running your application with &quot;flutter run&quot;. You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // &quot;hot reload&quot; (press &quot;r&quot; in the console where you ran &quot;flutter run&quot;, // or simply save your changes to &quot;hot reload&quot; in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.red, ), home: const BeastBurst(title: 'BeastBurst'), ); } } class BeastBurst extends StatefulWidget { const BeastBurst({super.key, required this.title}); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked &quot;final&quot;. final String title; @override State&lt;BeastBurst&gt; createState() =&gt; _BeastBurstState(); } class _BeastBurstState extends State&lt;BeastBurst&gt; { int _counter = 0; bool _loggedIn = false; List&lt;Widget&gt; pages = const [HomePage(), Forums()]; @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( body: pages[PageService.CurrentPage], // This trailing comma makes auto-formatting nicer for build methods. ); } } </code></pre> <p>When I navigate over the navigation menu I see the output of print like:</p> <pre><code>SETTING 1 SETTING 0 SETTING 1 SETTING 1 </code></pre> <p>However, page switching does not happen unless I press <code>CRTL+S</code> on the VSCode editor. Looks like it reads the value of <code>PageService.CurrentPage</code> only on the editor save.</p> <p>This issue happened once I made <code>PageService.CurrentPage</code> static. Any idea why is that and how can I fix it?</p>
[ { "answer_id": 74449034, "author": "Carl Witthoft", "author_id": 884372, "author_profile": "https://Stackoverflow.com/users/884372", "pm_score": 0, "selected": false, "text": "if(mean(x) == x[1])" }, { "answer_id": 74449931, "author": "jblood94", "author_id": 9463489, "author_profile": "https://Stackoverflow.com/users/9463489", "pm_score": 1, "selected": false, "text": "n = 1" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2661419/" ]
74,448,889
<p>I'm at a loss here, and I realise I may be going the long way around, but I can't figure it out. I have a datetime in UTC, curr. It is not being saved in 24 hr time, so I can convert it to a string s, which is indeed a string in 24 hr time. Now I want to save it back as a datetime still retaining the 24 hr time, but when I write foo out it is still being displayed in 24 hr time. How do I get the current Utc time in not just a DateTime, but a 24 hr DateTime?</p> <pre><code>var curr = DateTime.UtcNow; String s = curr.ToString(&quot;yyyy-MM-dd HH:mm:ss&quot;); DateTime foo = DateTime.Parse(s); Console.WriteLine(foo); Console.ReadLine(); </code></pre>
[ { "answer_id": 74449049, "author": "Tim Schmelter", "author_id": 284240, "author_profile": "https://Stackoverflow.com/users/284240", "pm_score": 2, "selected": false, "text": "DateTime" }, { "answer_id": 74449087, "author": "JBrown521", "author_id": 10429786, "author_profile": "https://Stackoverflow.com/users/10429786", "pm_score": 2, "selected": true, "text": "DateTime" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1144431/" ]
74,448,892
<p>I'm trying to create a worker that listens to http requests and adds jobs IDs to a queue. I'm using Python's built-in multiprocessing module for that.</p> <p>I need a Pool with a few processes that will process the job from queue and respawn. Processes have to restart, bacause for some cases job processing can cause memory leak. Pool should run forever as the items will be added to the queue dynamically.</p> <p>The problem is that my pool does not respawn workers after they complete.</p> <p>How can I use pool to achieve this? I want it to run forever, consume item from queue and respawn child after every task.</p> <pre class="lang-py prettyprint-override"><code>from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from multiprocessing import Pool, SimpleQueue, current_process queue = SimpleQueue() def do_something(q): worker_id = current_process().pid print(f&quot;Worker {worker_id} spawned&quot;) item_id = q.get() print(f&quot;Worker {worker_id} received id: {item_id}&quot;) # long_term_operation_that_leaks_memory(item_id) # print(f&quot;Worker {worker_id} completed id: {item_id}&quot;) def main(): with Pool( processes=2, initializer=do_something, initargs=(queue,), maxtasksperchild=1 ): queue.put(&quot;a&quot;) queue.put(&quot;b&quot;) queue.put(&quot;c&quot;) server_address = (&quot;&quot;, 8000) httpd = ThreadingHTTPServer(server_address, BaseHTTPRequestHandler) try: httpd.serve_forever() except (KeyboardInterrupt, SystemExit): pass if __name__ == &quot;__main__&quot;: main() </code></pre> <p>I tried with <code>initializer</code> and <code>maxtasksperchild</code> but it does not work.</p> <p>I know I can add new processes to a pool using map, but I don't have a map of an infinite possible tasks from the future. I think <code>initializer</code> should be responsible for all new tasks. But I don't know how to force it to run forever and respawn.</p> <p>In my code example &quot;c&quot; item is never processed. Therefore if I add http logic to put more items it will not work either. Adding http logic to this code is not necessary part of my question, but any tips will be welcomed.</p> <p>Thanks!</p> <p>Edit:</p> <p>The reason I decided to use Pool in this case, is that official <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow noreferrer">documentation</a> says:</p> <blockquote> <p>Worker processes within a Pool typically live for the complete duration of the Pool’s work queue. A frequent pattern found in other systems (such as Apache, mod_wsgi, etc) to free resources held by workers is to allow a worker within a pool to complete only a set amount of work before being exiting, being cleaned up and a new process spawned to replace the old one. The maxtasksperchild argument to the Pool exposes this ability to the end user.</p> </blockquote> <p>My goals:</p> <ul> <li>Items will be added dynamically to the queue by http requests</li> <li>Pool will live forever</li> <li>Worker process will perform only one task from queue and will be respawned</li> </ul> <p>Why I used only 2 processes?</p> <p>Processes number will not be infinite and it is easy to test my example with 2 processes rather that 5 or 10.</p> <p>Why I put 3 items manually? It is for example purpose, in real solution all items will be added dynamically, so there is no way to loop over them or to use map on them.</p>
[ { "answer_id": 74449049, "author": "Tim Schmelter", "author_id": 284240, "author_profile": "https://Stackoverflow.com/users/284240", "pm_score": 2, "selected": false, "text": "DateTime" }, { "answer_id": 74449087, "author": "JBrown521", "author_id": 10429786, "author_profile": "https://Stackoverflow.com/users/10429786", "pm_score": 2, "selected": true, "text": "DateTime" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9737275/" ]
74,448,900
<p>I have a static HTML page at the address <code>https://MyPage/index.html</code></p> <p>The page contains several images, which are located at <code>https://MyPage/MyImages</code></p> <p>The images are linked in the HTML source code like this:</p> <p><code>…&lt;span&gt;&lt;img width=x height=y src=&quot;MyImages/imageXYZ.png&quot;&lt;/span&gt;…</code></p> <p>When a button is clicked or, even better, when the page is loaded, all image links should be rewritten by appending a random number or, for example, the current time in milliseconds, so that the links look like this afterwards:</p> <p><code>…&lt;span&gt;&lt;img width=x height=y src=&quot;MyImages/imageXYZ.png?1587624427&quot;&lt;/span&gt;…</code></p> <p>I believe that possible starting points can be found here:</p> <p><a href="https://stackoverflow.com/questions/15884910/changing-all-links-on-page">Changing all links on page</a></p> <p><a href="https://stackoverflow.com/questions/13291272/how-to-change-all-links-with-javascript">How to Change All Links with javascript</a></p> <p><a href="https://lab.artlung.com/change-all-links/" rel="nofollow noreferrer">How can I change every link on a page to something new?</a></p> <p>Starting from there, how can I add to the examples given such that (instead of a constant redirect) a random number or the time in milliseconds is appended to all image links?</p>
[ { "answer_id": 74449180, "author": "pier farrugia", "author_id": 19996700, "author_profile": "https://Stackoverflow.com/users/19996700", "pm_score": 2, "selected": false, "text": "const time_to_img = () => {\n document.querySelectorAll('img').forEach(e => {\n const dateStr = Date.now();\n const date = new Date(dateStr);\n e.src = e.src + '?' + date.getTime();\n })\n}\nwindow.addEventListener('load', time_to_img);" }, { "answer_id": 74449620, "author": "David.P", "author_id": 1388921, "author_profile": "https://Stackoverflow.com/users/1388921", "pm_score": 0, "selected": false, "text": "<body onload=\"CacheBuster()\";>\n\n<script>\nfunction CacheBuster() {\n document.querySelectorAll('img').forEach(e => {\n const dateStr = Date.now();\n const date = new Date(dateStr);\n e.src = e.src + '?' + date.getTime();\n })\n }\n</script>\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1388921/" ]
74,448,921
<p>I have build a result page for a calculation. It's basically a CSS-grid in a DIV. The grid has three columns. In each column there are tiles (divs) which contain tables (which show the results).</p> <p>In JavaScript I calculate the result tables and assign them to the tables. There is an outermost div where I set display to &quot;table&quot;.</p> <p>Here is the problem: Some browsers on some computers present a long empty page. At the very end I can see a bit of tables, the rest is clipped.</p> <p>This may happen at the beginning where build the page or when I replace a table by a newly calculated table.</p> <p>For now I found an unsatisfying work around: Before any assignments to div.innerHtml I set display of the outermost div to none. After the assignments I set it back to table after a setTimeout of 0.5 sec. Then the page is built properly.</p> <p>It looks like that after the assignments some time is needed to build the internal DOM structure but I don't know any event to wait for.</p> <p>Here is the essence of the html structure:</p> <pre><code>&lt;div style=&quot;display: table&quot;&gt; &lt;div style=&quot;display: grid; grid-template-areas: 'left center right';&quot;&gt; &lt;div style=&quot;grid-area: left&quot;&gt; &lt;div id=&quot;result_table0&quot;&gt;&lt;/div&gt; &lt;div id=&quot;result_table1&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;div style=&quot;grid-area: center&quot;&gt; &lt;div id=&quot;result_table2&quot;&gt;&lt;/div&gt; &lt;div id=&quot;result_table3&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;div style=&quot;grid-area: right&quot;&gt; &lt;div id=&quot;result_table4&quot;&gt;&lt;/div&gt; &lt;div id=&quot;result_table5&quot;&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The Javascript assignments of the tables looks similar like that:</p> <pre><code>// calculation of the table let my_result_table = '&lt;table&gt;&lt;tr&gt;&lt;td&gt;xxx&lt;/td&gt;&lt;td&gt;yyy&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'; // assignment to the div document.getElementById('result_table0').innerHTML = my_result_table; </code></pre> <p>Any ideas what's going wrong here?</p>
[ { "answer_id": 74453022, "author": "Dave Pritlove", "author_id": 2005666, "author_profile": "https://Stackoverflow.com/users/2005666", "pm_score": 1, "selected": false, "text": "display: table/table-row/table-cell" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12270886/" ]
74,448,945
<p>Is there a way to execute <code>DateTime.Parse</code> on a tuple in C#.</p> <p>I am using Specflow and part of the tests I am executing involve testing a list of <code>DateTime</code> tuples (e.g. <code>List&lt;(DateTime, DateTime)&gt;</code>). In this step I am taking in a string, parsing it into a list of strings, where each string represents a <code>DateTime</code> pair separated by <code>=</code>.</p> <p>The plan was to create a tuple store the value by splitting the string, creating a string tuple, then parsing that tuple using <code>DateTime.Parse</code>.</p> <p>This doesn't work, giving me a CS1503 error (<em>Argument n: cannot convert from 'type x' to 'type y'</em>), and I cannot find any other information online about using <code>DateTime.Parse</code> on tuples. Is there another way of changing these values into <code>DateTime</code>?</p> <p>Below is an extract of my code for reference:</p> <pre class="lang-cs prettyprint-override"><code>public class TimeModeServiceStepDefinitions { List&lt;(DateTime, DateTime)&gt; expectedResult = new List&lt;(DateTime, DateTime)&gt;(); [Given(@&quot;I have the following list of expected results: '([^']*)'&quot;)] public void GivenIHaveTheFollowingListOfExpectedResults(string p0) { List&lt;string&gt; tuples = p0.Split('|').ToList(); foreach (var tuple in tuples) { var timeTuple = (first: &quot;first&quot;, second: &quot;second&quot;); timeTuple = tuple.Split('=') switch { var a =&gt; (a[0], a[1]) }; expectedResult.Add(DateTime.Parse(timeTuple)); } } } </code></pre>
[ { "answer_id": 74449441, "author": "Olivier Jacot-Descombes", "author_id": 880990, "author_profile": "https://Stackoverflow.com/users/880990", "pm_score": 2, "selected": false, "text": "DateTime.Parse" }, { "answer_id": 74449920, "author": "Alexei Levenkov", "author_id": 477420, "author_profile": "https://Stackoverflow.com/users/477420", "pm_score": 0, "selected": false, "text": "DateTime.Parse" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5571692/" ]
74,448,946
<p>I have the following code segment in python</p> <pre><code> if mask &amp; selectors.EVENT_READ: recv_data = sock.recv(1024) if recv_data: data.outb += recv_data else: print(f&quot;Closing connection to {data.addr}&quot;) </code></pre> <p>Would I read this as: 'if mask and selectos.EVENT_READ are equivalent:' And similarly: 'if recv_data is equivalent to true:'</p> <p>Help is greatly appreciated!</p>
[ { "answer_id": 74449031, "author": "chepner", "author_id": 1126841, "author_profile": "https://Stackoverflow.com/users/1126841", "pm_score": 1, "selected": true, "text": "bytes" }, { "answer_id": 74449035, "author": "Noscere", "author_id": 10728583, "author_profile": "https://Stackoverflow.com/users/10728583", "pm_score": 1, "selected": false, "text": "if var_name:" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20462841/" ]
74,448,964
<p>I have a long config file which looks like:</p> <pre><code>&lt;some stuff before our example&gt; 'Realtime' =&gt; [ 'foo' =&gt; 'bar', 'enabled' =&gt; true, 'lorem' =&gt; 'ipsum' ], &lt;some stuff after our example&gt; </code></pre> <p>The above is a large config php file and I was asked to mine the <code>enabled</code> value of 'Realtime` with bash. I could do it with PHP, but I was specifically asked to do it with bash.</p> <p>I tried the following:</p> <pre><code>echo $(tr '\n' ' ' &lt; myconfig.php | sed '$s/ $/\n/') | grep -o -P '(?&lt;=Realtime).*(?=\])' </code></pre> <p>and this mines the text from the file between <code>Realtime</code> <strong>and the last</strong> <code>]</code>. But I would like to mine the content between <code>Realtime</code> and the first <code>]</code>. For the time being I have implemented a simplistic bash and accompanied that with PHP parser, as follows:</p> <pre><code> public function getConfig($name) { $path = Paths::CONFIG_FILE; if (!$this-&gt;config) { $this-&gt;config = Command_ShellFactory::makeForServer('zl', &quot;cat {$path}&quot;)-&gt;execute(true, true); } $splitName = explode('.', $name); $lastPosition = 0; $tempConfig = $this-&gt;config; foreach ($splitName as $currentName) { if (($position = strpos($tempConfig, $currentName)) === false) { throw new RuntimeException('Setting was not found'); } $tempConfig = substr($tempConfig, $position); } return trim(explode(&quot;=&gt;&quot;, explode(&quot;\n&quot;, $tempConfig)[0])[1], &quot;, \n\r\t\v\x00&quot;); } </code></pre> <p>and this works, but I'm not satisfied with it, because it loads the whole file into memory via the shell command and then searches for the nested key (<code>Realtime.enabled</code> is passed to it). Is it possible to improve this code in such a way that all the logic would happen via bash, rather than helping it with PHP?</p> <p>EDIT</p> <p>The possible settings to mine could be of any depth. Examples:</p> <pre><code>[ /*...*/ 'a' =&gt; 'b', //Depth of 1 'c' =&gt; [ 'a' =&gt; 'd' //Depth of 2 ], 'e' =&gt; [ 'f' =&gt; [ 'g' =&gt;'h' //Depth of 3 ] ] /*...*/ ] </code></pre> <p>Theoretically any amount of depth is possible, in the example we have a depth of 1, a depth of 2 and a depth of 3.</p> <p>EDIT</p> <p>I have created foo.sh (some fantasy name of no importance):</p> <pre><code>[ 'Realtime' =&gt; [ 'enabled' =&gt; [ 'd' =&gt; [ 'e' =&gt; 'f' ], ], 'a' =&gt; [ 'b' =&gt; 'c' ], ] 'g' =&gt; [ 'h' =&gt; 'i' ], 'Unrealtime' =&gt; 'abc' ] </code></pre> <p>Working one-dimensional command:</p> <pre><code>sed -Ez &quot;:a;s/.*Unrealtime' =&gt; +([^,]*).*/\1\n/&quot; foo.sh | head -1 </code></pre> <p>The result is</p> <blockquote> <p>'abc'</p> </blockquote> <p>Working two-dimensional command:</p> <pre><code>sed -Ez &quot;:a;s/.*g[^]]*h' =&gt; +([^,]*).*/\1\n/&quot; foo.sh | head -1 </code></pre> <p>The result is</p> <blockquote> <p>'i'</p> </blockquote> <p>Three-dimensional command:</p> <pre><code>sed -Ez &quot;:a;s/.*Realtime*[^]]*a[^]]*b' =&gt; +([^,]*).*/\1\n/&quot; foo.sh | head -1 </code></pre> <p>It is working if and only if the</p> <pre><code> 'a' =&gt; [ 'b' =&gt; 'c' ] </code></pre> <p>is the first child of <code>Realtime</code>. So, something is missing, as I need to avoid assuming that the element I search for is the first child.</p> <p>Working four-dimensional command:</p> <pre><code>sed -Ez &quot;:a;s/.*Realtime[^]]*enabled[^]]*d[^]]*e' =&gt; +([^,]*).*/\1\n/&quot; foo.sh | head -1 </code></pre> <p>Again, it only works if <code>enabled</code> is the first child of <code>Realtime</code>. I was modifying my test case above, changing the order of the children of <code>Realtime</code>. So, it seems that the only thing missing from this expression is something that would specify that we are not necessarily looking for the first child.</p>
[ { "answer_id": 74449220, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "awk" }, { "answer_id": 74449380, "author": "HatLess", "author_id": 16372109, "author_profile": "https://Stackoverflow.com/users/16372109", "pm_score": 2, "selected": true, "text": "Realtime" }, { "answer_id": 74449433, "author": "Arnaud Valmary", "author_id": 6255757, "author_profile": "https://Stackoverflow.com/users/6255757", "pm_score": 1, "selected": false, "text": "tr" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/436560/" ]
74,448,975
<p>Let's say I have a dataframe like this:</p> <pre><code>import pandas as pd df = pd.DataFrame([[1,2,3,&quot;P&quot;, 1, &quot;A&quot;, &quot;SOMETHING&quot;], [1,2,3,&quot;C&quot;, 0, &quot;B&quot;, &quot;NOTHING&quot;], [1,2,3,&quot;C&quot;, 0, &quot;B&quot;, &quot;SOMETHING&quot;], [4,5,6,&quot;P&quot;, 1, &quot;A&quot;, &quot;SOMETHING&quot;], [4,5,6,&quot;C&quot;, 1, &quot;A&quot;, &quot;NOTHING&quot;]], columns=[&quot;ID1&quot;, &quot;ID2&quot;, &quot;ID3&quot;, &quot;FLAG&quot;, &quot;CONDITION_1&quot;, &quot;CONDITION_2&quot;, &quot;DATA_FIELD&quot;]) </code></pre> <pre><code> ID1 ID2 ID3 FLAG CONDITION_1 CONDITION_2 DATA_FIELD 0 1 2 3 P 1 A SOMETHING 1 1 2 3 C 0 B NOTHING 2 1 2 3 C 0 B SOMETHING 3 4 5 6 P 1 A SOMETHING 4 4 5 6 C 1 A NOTHING </code></pre> <p>There is a FLAG column which has 2 types of values:</p> <ul> <li>P: Parent</li> <li>C: Child</li> </ul> <p>When the ID1, ID2, ID3 values are repeated, this means those records are connected. There is always one P and can be any number of C in the FLAG column.</p> <p>What I want to achieve is to update the all child record's DATA_FIELD value to the parent record's value if the following conditions met: CONDITION_1 == 0 AND CONDITION_2 == &quot;B&quot;</p> <p>This would give the following result:</p> <pre><code> ID1 ID2 ID3 FLAG CONDITION_1 CONDITION_2 DATA_FIELD 0 1 2 3 P 1 A SOMETHING 1 1 2 3 C 0 B SOMETHING 2 1 2 3 C 0 B SOMETHING 3 4 5 6 P 1 A SOMETHING 4 4 5 6 C 1 A NOTHING </code></pre> <p>What I had in mind is to sort the values in an ascending order by ID1,ID2,ID3 and descending by FLAG. After that I could loop through the dataframe line by line, check if the FLAG is a P and store the 3 IDs and the DATA_FIELD value in a dictionary or something. On the next line I need to check if the keys are the same, then if the conditions are True, then update the DATA_FIELD. Not sure however if this is the best solution:</p> <pre><code>df.sort_values([&quot;ID1&quot;, &quot;ID2&quot;, &quot;ID3&quot;, &quot;FLAG&quot;], ascending=[True, True, True, False], inplace=True) df.reset_index(drop=True, inplace=True) parent_keys = None for index, row in df.iterrows(): if row[&quot;FLAG&quot;] == &quot;P&quot;: parent_keys = f&quot;{row['ID1']}{row['ID2']}{row['ID3']}&quot; parent_data_field_value = row[&quot;DATA_FIELD&quot;] if row[&quot;FLAG&quot;] == &quot;C&quot;: if parent_keys: child_keys = f&quot;{row['ID1']}{row['ID2']}{row['ID3']}&quot; if child_keys == parent_keys: if row[&quot;CONDITION_1&quot;] == 0 and row[&quot;CONDITION_2&quot;] == &quot;B&quot;: df.loc[index, &quot;DATA_FIELD&quot;] = parent_data_field_value </code></pre>
[ { "answer_id": 74449220, "author": "markp-fuso", "author_id": 7366100, "author_profile": "https://Stackoverflow.com/users/7366100", "pm_score": 2, "selected": false, "text": "awk" }, { "answer_id": 74449380, "author": "HatLess", "author_id": 16372109, "author_profile": "https://Stackoverflow.com/users/16372109", "pm_score": 2, "selected": true, "text": "Realtime" }, { "answer_id": 74449433, "author": "Arnaud Valmary", "author_id": 6255757, "author_profile": "https://Stackoverflow.com/users/6255757", "pm_score": 1, "selected": false, "text": "tr" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74448975", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7497912/" ]
74,449,024
<p>Right now I have two functions:</p> <pre><code>public void func(Unity.Collections.NativeArray&lt;ushort&gt; a){} public void func(Unity.Collections.NativeArray&lt;short&gt; a){} </code></pre> <p>The functions are the exact same besides the object datatype input. I am also not writing to these NativeArrays, so the code functions identically whether it is reading the array as &lt;ushort&gt; or &lt;short&gt;. Is there a way to combine these into one function that can accept both types of objects? NativeArrays are a managed type, so I can't use pointers. Any other ways to avoid duplicating the whole function or duplicating the objects?</p>
[ { "answer_id": 74449058, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "public void func<T>(Unity.Collections.NativeArray<T> a) where T : struct\n{}\n" }, { "answer_id": 74449157, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "public void func(Unity.Collections.NativeArray<ushort> a)\n => func(MemoryMarshal.Cast<ushort, short>(a.AsSpan()));\n\npublic void func(Unity.Collections.NativeArray<short> a)\n => func(a.AsSpan());\n\nprivate void func(Span<short> a)\n{ ... real code here ...}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15939414/" ]
74,449,077
<p>Can You give me tips how I can add to copied files name the prefix comes from name of sub-directory for example</p> <p>this is my source dir <code>'/home/ip/input/IP10/STAT-IP_202211151610_7428/some_files'</code></p> <pre><code>import os import glob import shutil for f in glob.glob('/opt/data/input/IP10/**/*.*', recursive=True): shutil.copy(f, '/opt/data/input/IP10_for_decoder/copy/') </code></pre> <p>then I need to get file name after it copied: STAT-IP_202211151610_7428_some_files ?</p>
[ { "answer_id": 74449058, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "public void func<T>(Unity.Collections.NativeArray<T> a) where T : struct\n{}\n" }, { "answer_id": 74449157, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "public void func(Unity.Collections.NativeArray<ushort> a)\n => func(MemoryMarshal.Cast<ushort, short>(a.AsSpan()));\n\npublic void func(Unity.Collections.NativeArray<short> a)\n => func(a.AsSpan());\n\nprivate void func(Span<short> a)\n{ ... real code here ...}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17183340/" ]
74,449,116
<p>I’m having re-rendering issues, any help is greatly appreciated. I tried useMemo and useCallback and it broke the checkbox. I have a component, and inside that component, I display some info in my object. I have let's say an object as such:</p> <pre><code>fakeObject = { name: &quot;rectangle&quot; width: 10 height: 20 visible: true } const fakeComponent = () =&gt; { const [checked, setChecked] = React.useState(true); const handleChange = (event: React.ChangeEvent&lt;HTMLInputElement&gt;) =&gt; { setChecked(event.target.checked); fakeObject[&quot;visible&quot;] = event.target.checked; }; return( &lt;div&gt; &lt;h2&gt; {fakeObject.name} &lt;/h2&gt; &lt;p&gt; The height is {fakeObject.height} &lt;/p&gt; &lt;Checkbox checked={checked} onChange={handleChange} inputProps={{ 'aria-label': 'controlled' }} /&gt; &lt;/div&gt; ) }; </code></pre> <p>The issue is that every time I click my checkbox it rerenders the whole component. This is a simplified version of my issue but I see that the component uses my fakeObject and that the checkbox changes that but how do I make it so that my whole component doesn't re-render? Thanks for any help</p>
[ { "answer_id": 74449677, "author": "kind user", "author_id": 6695924, "author_profile": "https://Stackoverflow.com/users/6695924", "pm_score": 2, "selected": true, "text": "Child" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14764973/" ]
74,449,178
<p>I'm new to using axios and stripe and I'm encountering some issues. When I try to make a post request with axios I receive this error:</p> <p><a href="https://i.stack.imgur.com/4rFrb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4rFrb.png" alt="This is the error I receive when making a post request" /></a></p> <p>Perhaps my endpoint is incorrect. I'm not sure. Here is my code in Payments.js:</p> <pre><code> import React,{useState, useEffect} from 'react' import CheckoutProduct from './CheckoutProduct'; import './Payment.css'; import {useStateValue} from './StateProvider'; import {Link, useHistory} from 'react-router-dom'; import {CardElement, useStripe, useElements} from &quot;@stripe/react-stripe-js&quot;; import CurrencyFormat from &quot;react-currency-format&quot;; import {getBasketTotal} from &quot;./reducer&quot;; import axios from './axios'; function Payment() { const [{basket,user}, dispatch] = useStateValue(); const history = useHistory(); const stripe = useStripe(); const elements = useElements(); const [succeeded, setSucceeded] = useState(false); const [processing, setProcessing] = useState(&quot;&quot;); const [error,setError] = useState(null); const [disabled,setDisabled] = useState(true); const [clientSecret,setClientSecret] = useState(true); useEffect(() =&gt; { const getClientSecret = async () =&gt; { try { const response = await axios({ method: 'post', url: `/payments/create?total=${getBasketTotal(basket)*100}` }); console.log(&quot;THIS IS THE RESPONSE&quot;, response); setClientSecret(response.data.clientSecret); } catch (error) { console.log(&quot;THIS IS THE ERROR&quot;, error); } } getClientSecret(); },[basket]); console.log('THE CLIENT SECRET &gt;&gt;&gt;', clientSecret); </code></pre> <p>And here is my middleware code in index.js:</p> <pre><code>const functions = require(&quot;firebase-functions&quot;); const express = require(&quot;express&quot;); const cors = require(&quot;cors&quot;); const stripe = require(&quot;stripe&quot;)(&quot;/* my secret stripe api key is here */&quot;); const app = express(); app.use(cors({origin: true})); app.use(express.json()); app.get(&quot;/&quot;, (request, response) =&gt; response.status(200).send (&quot;hello world&quot;)); app.post(&quot;/payments/create/&quot;, async (request, response) =&gt; { const total = request.params.total; console.log(&quot;Payment Request Received &gt;&gt;&gt;&quot;, total); const paymentIntent = await stripe.paymentIntents.create({ amount:total, currency:&quot;usd&quot;, }); response.status(201).send({ clientSecret: paymentIntent.client_secret, }) }); exports.api = functions.https.onRequest(app); </code></pre> <p>Here is my axios.js file:</p> <pre><code>import axios from &quot;axios&quot;; const instance = axios.create({ baseURL: 'http://127.0.0.1:5001/clone-bfd8a/us-central1/api' }); export default instance; </code></pre> <p>I was reviewing the post endpoint in my Payments.js file to see if it was correct. Then I checked my middleware in index.js to see if it coincided with my endpoint in Payment.js. To me, the endpoints seem correct. I was expecting that the application show the <code>clientSecret</code> but instead I got the axios Network Error.</p> <p>I also received this error in my terminal: <a href="https://i.stack.imgur.com/xFNDS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xFNDS.png" alt="It states that the 'amount' parameter is missing" /></a></p> <p>It says the 'amount' parameter is missing but I'm not sure why it says that because I included it in the post middleware route.</p> <p>I think the error may be in Payments.js where it says:</p> <pre><code>setClientSecret(response.data.clientSecret); </code></pre> <p>Maybe <code>response.data.clientSecret</code> doesn't exist.</p> <p>I'm also thinking the error is in index.js where it says:</p> <pre><code> clientSecret: paymentIntent.client_secret, </code></pre> <p>Perhaps <code>client_secret</code> is not defined by stripe. I'm not sure. Any ideas why I'm receiving this Axios network error? Any help is appreciated! Thanks in advance :)</p> <p>UPDATE:</p> <p>So it seems to be kind of working now. I changed <code>req.params.total</code> to <code>req.query.total</code> in my middleware post route in index.js:</p> <p><a href="https://i.stack.imgur.com/umncH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/umncH.png" alt="enter image description here" /></a></p> <p>But it still seems to be acting kind of weird: When I first start the application, I get the error as mentioned above. However, after waiting a couple of minutes, I am able to successfully make a post request with axios. Is it possible that the frontend and backend need to take some time to be synchronized? Could it be that the error is happening because the <code>basket</code> variable is empty at first and then axios tries to make the post request? Thanks in advance!</p>
[ { "answer_id": 74449348, "author": "ymz", "author_id": 4062197, "author_profile": "https://Stackoverflow.com/users/4062197", "pm_score": 1, "selected": false, "text": "app.post(\"/payments/create\", ...\n" }, { "answer_id": 74449431, "author": "Camilo Gomez", "author_id": 17717225, "author_profile": "https://Stackoverflow.com/users/17717225", "pm_score": 0, "selected": false, "text": "\nconst paymentIntent = await stripe.paymentIntents.create({\n amount: total,\n currency: \"usd\",\n payment_method_types: [\"card\"],\n description: \"Buy a xxxx\"\n confirm: true,\n });\n\n if (paymentIntent) {\n if (\n paymentIntent.status === \"requires_action\" &&\n paymentIntent.next_action.type === \"use_stripe_sdk\"\n ) {\n\n response.status(201).send({\n clientSecret: paymentIntent.client_secret,\n })\n\n } else if (paymentIntent.status === \"succeeded\") {\n \n response.status(200).send({\n message: \"success\"\n })\n \n } else {\n console.log(\"Invalid PaymentIntent status\");\n }\n } else {\n console.log(\"Invalid PaymentIntent status\");\n }\n\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18076768/" ]
74,449,198
<p>I'm trying to pass an array into a method. The idea is a random number is generated, <code>i</code>, and the value of <code>xArray[i]</code> is copied into <code>yArray[x]</code>, where <code>x = 0</code> is increased with each run.</p> <p>What I don't understand is the array I pass into the method is modified as well. For example:</p> <pre class="lang-rb prettyprint-override"><code># inputArray is populated by the capital letters of the alphabet, e.g. &quot;A&quot;, &quot;B&quot;, ... &quot;Z&quot; def populateArray inputArray xArray = inputArray yArray = Array.new i = 0 while yArray.length &lt; 26 # Subtract i to take into account decreasing array size x = rand(26-i) yArray[i] = xArray[x] # Delete entry so I don't get duplicate letters xArray.delete_at(x) i = i + 1 end end puts &quot;inputArray length: #{inputArray.length.to_s}&quot; puts &quot;xArray length: #{xArray.length.to_s}&quot; puts &quot;yArray length: #{yArray.length.to_s}&quot; </code></pre> <p>I can understand why xArray.length is 0, because that is the one I have been removed entries from. But why is it also affecting inputArray?</p> <p>I have tried creating a copy by doing this: <code>xArray = inputArray</code>, but it doesn't seem to make a difference.</p> <p>I'm expecting the inputArray to maintain its length, and have the values inside untouched.</p> <p><strong>NOTE:</strong> <em>I am entirely new to Ruby, and have only covered the &quot;Learn to Program&quot; section recommended on the Ruby website. Any suggestions about formatting and easier ways to do things are always welcome.</em></p>
[ { "answer_id": 74449768, "author": "Bustikiller", "author_id": 3607039, "author_profile": "https://Stackoverflow.com/users/3607039", "pm_score": 2, "selected": true, "text": "xArray = inputArray" }, { "answer_id": 74449809, "author": "Muteeb Zafar", "author_id": 12874094, "author_profile": "https://Stackoverflow.com/users/12874094", "pm_score": 0, "selected": false, "text": "xArray = inputArray.dup\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12240884/" ]
74,449,226
<p>I'nm new to the tensorflow and I'm trying to train a CNN for image classification. Here is the error I got:</p> <pre><code>2022-11-15 11:18:50.087877: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2022-11-15 11:18:50.088548: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. nd 2022-11-15 11:19:04.824435: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found2022-11-15 11:19:04.824617: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found2022-11-15 11:19:04.824783: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found 2022-11-15 11:19:04.825030: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found2022-11-15 11:19:04.825218: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found2022-11-15 11:19:04.825408: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found 2022-11-15 11:19:04.825483: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.Skipping registering GPU devices... </code></pre> <p>I do have GPU available and CUDA version is 11.2<a href="https://i.stack.imgur.com/gWoBT.png" rel="nofollow noreferrer">Here is what I got when I checking the CUDA version</a> <a href="https://i.stack.imgur.com/QRVu2.png" rel="nofollow noreferrer">Here is my tf version</a></p> <p>Tried to many methods but still not working, no idea waht's going on. Really appreciate for your help.</p> <p>Followed the instruction on <a href="https://www.tensorflow.org/install/pip" rel="nofollow noreferrer">https://www.tensorflow.org/install/pip</a> couple times.</p>
[ { "answer_id": 74452536, "author": "YiSan", "author_id": 9282082, "author_profile": "https://Stackoverflow.com/users/9282082", "pm_score": 1, "selected": false, "text": "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\bin" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9282082/" ]
74,449,237
<p>The question is asking to create a nested loop to append and increase multiple index in a 2D list,for somehow I can't print the element in the list and i tried to print the length of the list it just return 0.</p> <p>the expect value in the list is:</p> <p>If duration of the music sequence is 1s, starting pitch is 60 and ending pitch is 64, then the content of the music list for one sequence will be:</p> <pre><code>[ [0.0, 60, 0.2], [0.2, 61, 0.2], [0.4, 62, 0.2], [0.6, 63, 0.2], [0.8, 64, 0.2] ] </code></pre> <p>There are 5 music notes because the pitch number starts from 60 and goes up to 64, i.e. number of notes = 64 - 60 + 1</p> <p>The duration of each music note is 0.2s, which is just the duration of the music sequence divided by 5</p> <p>so the list is</p> <pre class="lang-py prettyprint-override"><code>music_data=[time,pitch,duration] </code></pre> <p>here are more examples if the music sequence is repeated twice, an example music data with five notes (from 60 to 64 and a music sequence duration of 1 second) will look like this:</p> <pre><code>[ [0.0, 60, 0.2], [0.2, 61, 0.2], [0.4, 62, 0.2], [0.6, 63, 0.2], [0.8, 64, 0.2], [1.0, 60, 0.2], [1.2, 61, 0.2], [1.4, 62, 0.2], [1.6, 63, 0.2], [1.8, 64, 0.2] ] </code></pre> <p>You need to be careful that the range of pitch numbers works quite differently for increasing pitch numbers (step = 1) and decreasing pitch numbers (step = -1) You also need to make sure that the range of pitch numbers is inclusive of the starting pitch and the ending pitch values</p> <p>For example, if the starting pitch and ending pitch are 60 and 72 respectively, you will need write range(60, 73) to generate the correct range of pitch numbers</p> <p>The function template provided by task:</p> <pre class="lang-py prettyprint-override"><code># This function makes a piece of crazy music in the music list def makeCrazyMusic(): global music_data ##### # # TODO: # - Ask for the crazy music parameters # - Clear the music list # - Use a nested loop to generate the crazy music in the music list # - Update the music summary # ##### </code></pre> <p>After refer to the instruction, i ve tried :</p> <pre class="lang-py prettyprint-override"><code>def makeCrazyMusic(): global music_data ##### # # TODO: # - Ask for the crazy music parameters # - Clear the music list # - Use a nested loop to generate the crazy music in the music list # - Update the music summary # ##### #time = start time of note #pitch the pitch of note #durantion the length of the note #duration = duration / note --constant # = duration / startpitch -endpitch+1) #note = start pitch - end pitch +1 #time = time + duration #pitch = from start to end # try: times_input = int(turtle.numinput(&quot;Times to play&quot;,\ &quot;Please enter number of times to play the sequence:&quot;)) dura_input = float(turtle.numinput(&quot;Duration&quot;,\ &quot;Please enter duration to play the sequence:&quot;)) start_pitch = int(turtle.numinput(&quot;Start pitch&quot;,\ &quot;Please enter Start pitch to play the sequence:&quot;)) end_pitch = int(turtle.numinput(&quot;End Pitch&quot;,\ &quot;Please enter end pitch of the sequence:&quot;)) except TypeError: return music_data=[] #[time(+duration),pitch(nonc),duration(const)] index=0 for index in range(times_input): for pitch in (start_pitch,end_pitch+1): music_data.append([index,start_pitch,dura_input/times_input]) index= index+(dura_input/times_input) start_pitch= start_pitch+1 for x in range(len(music_data)): print(music_data[x]) </code></pre> <p>The expected OUTPUT is: if the music sequence is repeated twice, an example music data with five notes (from 60 to 64 and a music sequence duration of 1 second) will look like this:</p> <pre class="lang-py prettyprint-override"><code>#times_input =2 #dura_input = 1 #start_pitch =60 #end_pitch =64 [ [0.0, 60, 0.2], [0.2, 61, 0.2], [0.4, 62, 0.2], [0.6, 63, 0.2], [0.8, 64, 0.2], [1.0, 60, 0.2], [1.2, 61, 0.2], [1.4, 62, 0.2], [1.6, 63, 0.2], [1.8, 64, 0.2] ] </code></pre> <p>The ACTUAL OUTPUT:</p> <pre class="lang-py prettyprint-override"><code>[0, 60, 0.5] [0.5, 61, 0.5] [1, 62, 0.5] [1.5, 63, 0.5] </code></pre>
[ { "answer_id": 74452536, "author": "YiSan", "author_id": 9282082, "author_profile": "https://Stackoverflow.com/users/9282082", "pm_score": 1, "selected": false, "text": "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.8\\bin" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19761006/" ]
74,449,250
<p>For the following array</p> <pre><code>[ { name: '4K UHD', commentator: 'Ali' }, { name: 'English 1 HD', commentator: 'Ahmed' }, { name: 'English 3 HD', commentator: 'Ahmed' }, { name: 'Premium 1 HD', commentator: 'Ali' }, { name: 'Premium 2 HD', commentator: 'Ahmed' }, ] </code></pre> <p>I want to sort it so that objects with a <code>name</code> of <strong>Premium</strong> (as the last two objects) comes first but also in ascending order.</p> <p>The desired result is this</p> <pre><code>[ { name: 'Premium 1 HD', commentator: 'Ali' }, { name: 'Premium 2 HD', commentator: 'Ahmed' }, { name: '4K UHD', commentator: 'Ali' }, { name: 'English 1 HD', commentator: 'Ahmed' }, { name: 'English 3 HD', commentator: 'Ahmed' }, ] // or like this [ { name: 'Premium 1 HD', commentator: 'Ali' }, { name: 'Premium 2 HD', commentator: 'Ahmed' }, { name: 'English 1 HD', commentator: 'Ahmed' }, { name: 'English 3 HD', commentator: 'Ahmed' }, { name: '4K UHD', commentator: 'Ali' }, ] </code></pre>
[ { "answer_id": 74449391, "author": "Dreamy Player", "author_id": 15319747, "author_profile": "https://Stackoverflow.com/users/15319747", "pm_score": 0, "selected": false, "text": "array.sort((a, b) => a.name < b.name ? 1 : -1)\n" }, { "answer_id": 74449504, "author": "spender", "author_id": 14357, "author_profile": "https://Stackoverflow.com/users/14357", "pm_score": 2, "selected": true, "text": "const cmp = (a, b) => {\n const pa = a.name.startsWith(\"Premium\");\n const pb = b.name.startsWith(\"Premium\");\n return \n pa !== pb \n // comparing Premium vs non-Premium, Premium \"wins\"\n ? (pa ? -1 : 1) \n // everything else (i.e. Prem vs Prem or non-Prem vs non-Prem)\n : a.name.localeCompare(b.name); \n};\n\ndataArray.sort(cmp);\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17700794/" ]
74,449,262
<p>I have a text file as follows:</p> <p>myfile.txt</p> <pre><code>[items] colors = red, purple, orange, blue [eat] food = burgers, pizza, hotdogs [furry] animals = birds, dogs, cats </code></pre> <p>I have a dictionary:</p> <pre><code>my_dict = {'colors':'green, black','animals':'donkey, tigers'} </code></pre> <p>I want to open the file <em>myfile.txt</em> and search for the keys inside the file and replace the lines with the values of my_dict so that myfile.txt should look like:</p> <p>myfile.txt</p> <pre><code>[items] colors = green, black [eat] food = burgers, pizza, hotdogs [furry] animals = donkey, tigers </code></pre> <p>I've tried doing something like:</p> <pre><code>def func(my_dict): # Read in the file with open('myfile.txt', 'r') as file : filedata = file.read() # Replace the target string filedata = filedata.replace('colors', my_dict) # Write the file out again with open('myfile.txt', 'w') as file: file.write(filedata) </code></pre> <p>The problem is that I get an output like:</p> <pre><code>myfile.txt green, black = red, purple, orange, blue </code></pre>
[ { "answer_id": 74449456, "author": "StonedTensor", "author_id": 6023918, "author_profile": "https://Stackoverflow.com/users/6023918", "pm_score": -1, "selected": false, "text": "with open(\"myfile.txt\") as file:\n for line in file.readlines():\n if \"colors\" in line:\n filedata = line.replace(line.split(\" = \")[1], my_dict[\"colors\"])\n" }, { "answer_id": 74449581, "author": "Mustafa KÜÇÜKDEMİRCİ", "author_id": 15833253, "author_profile": "https://Stackoverflow.com/users/15833253", "pm_score": 0, "selected": false, "text": "my_dict = {'colors':'green, black','animals':'donkey, tigers'}\n\n\ndef func(my_dict):\n filedata = \"\"\"colors = red, purple, orange, blue\\nfood = burgers, pizza, hotdogs \\nanimals = birds, dogs, cats\"\"\"\n #get lines of line\n lines = filedata.split(\"\\n\")\n #this will store our final text\n fileDict = {}\n for line in lines:\n #get key from file/source\n key = line.split(\" = \")[0]\n if(key in my_dict.keys()):\n #if key exist in your dict, change it with your my_dict value\n newValues = my_dict[key]\n fileDict[key] = newValues\n else:\n #if key not exist in your my_dict, use file/source values\n fileDict[key] = line.split(\" =\")[1]\n\n #stringify dictionary\n text = \"\"\n for key,value in fileDict.items():\n text += f\"{key} = {value}\\n\" \n\n #write to file\n with open('myfile.txt', 'w') as file:\n file.write(filedata) \n\nfunc(my_dict)\n" }, { "answer_id": 74449640, "author": "David", "author_id": 19872860, "author_profile": "https://Stackoverflow.com/users/19872860", "pm_score": 2, "selected": true, "text": "my_dict = {'colors': 'green, black', 'animals': 'donkey, tigers'}\n\ndef func(my_dict):\n # Get the file contents like you were already doing\n with open('myfile.txt', 'r') as file:\n filedata = file.read()\n\n\n # Now split the rows on newline\n lines = filedata.split('\\n')\n # create a new list\n new_lines = []\n # Process each line of the file's contents\n for line in lines:\n # If it doesn't have an '=', just add it and continue iteration\n if \"=\" not in line: \n new_lines.append(line)\n continue\n\n key, value = line.split(\"=\")\n\n # if the key is in replacement dictionary, append a line with the new value\n if key.strip() in my_dict.keys():\n new_lines.append(f'{key.strip()} = {my_dict[key.strip()]}')\n # else just add the old line\n else:\n new_lines.append(line)\n\n with open('myfile.txt', 'w') as file:\n # join the new lines for the file with a newline character\n file.write('\\n'.join(new_lines))\n\nfunc(my_dict)\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7617510/" ]
74,449,331
<p>Iv'e tried using my folder that I made in school in my own pc but I can't seem to start it as I am assuming that the path to my python3.9 in school and in my house is not the same place. I write these 2 commands:</p> <p><code>.\env\Scripts\activate</code></p> <p><code>python app.py</code></p> <p>And then I get this back: <code>No Python at 'C:\Python\Python39\python.exe</code></p> <p>I don't understand much in this field because its new to me. If you need another file or something to help me just tell me and I will add it. Thank you for the help.</p>
[ { "answer_id": 74454483, "author": "JialeDu", "author_id": 19133920, "author_profile": "https://Stackoverflow.com/users/19133920", "pm_score": 0, "selected": false, "text": "Python:Select Interpreter" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15025935/" ]
74,449,343
<pre><code>document.getElementById(&quot;cards&quot;).onmousemove = e =&gt; { for(const card of document.getElementsByClassName(&quot;card&quot;)) { const rect = card.getBoundingClientRect(), x = e.clientX - rect.left, y = e.clientY - rect.top; card.style.setProperty(&quot;--mouse-x&quot;, `${x}px`); card.style.setProperty(&quot;--mouse-y&quot;, `${y}px`); }; } </code></pre> <p>I actually don't know how to use the above code in react js. so, if anyone knows please respond!</p> <p>full source code link:</p> <p><a href="https://codepen.io/Hyperplexed/pen/MWQeYLW" rel="nofollow noreferrer">https://codepen.io/Hyperplexed/pen/MWQeYLW</a></p>
[ { "answer_id": 74449579, "author": "AdmiJW", "author_id": 14033758, "author_profile": "https://Stackoverflow.com/users/14033758", "pm_score": 0, "selected": false, "text": "onmousemove" }, { "answer_id": 74449691, "author": "Black Hole", "author_id": 9334796, "author_profile": "https://Stackoverflow.com/users/9334796", "pm_score": 2, "selected": true, "text": " const CardRef = React.useRef(null);\n useShadow(CardRef);\n\n return <div ref={CardRef} className=\"card\" ></div>\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512337/" ]
74,449,345
<p>How can I remove the None values from this dataframe df and convert the columns from a to f as a list</p> <pre><code> emp_no a b c d e f id 0 11390 [1, 28.4] [7, 32.2] [7, 31.3] [28, 40.7] [28, 40.0] [28, 39.6] nhvm657mjhgmjhm 1 11395 [1, 31.4] [7, 32.8] [7, None] [28, 37.3] [28, 39.2] [28, None] hjgj6hgjgghjjh 2 11397 [1, 33.0] [7, 33.1] [7, 31.5] [28, None] [28, 40.4] [28, 41.0] fjyj676hjhjhg 3 11522 [1, 34.0] [7, 32.4] [7, 32.6] [28, 45.4] [28, 45.9] [28, 46.9] 65hjhgjghj766 4 11525 [1, 32.7] [7, 31.9] [7, 32.0] [28, None] [28, 44.4] [28, 46.1] ftghjy6757hjh </code></pre> <p>The output should be:</p> <pre><code>df[0] = [[1, 28.4],[7, 32.2],[7, 31.3],[28, 40.7],[28, 40.0],[28, 39.6]] df[1] = [[1, 31.4],[7, 32.8],[28, 37.3],[28, 39.2]] df[2] = [[1, 33.0],[7, 33.1],[7, 31.5],[28, 40.4],[28, 41.0]] df[3] = [[1, 34.0],[7, 32.4],[7, 32.6],[28, 45.4],[28, 45.9],[28, 46.9]] df[4] = [[1, 32.7] [7, 31.9],[7, 32.0],[28, 44.4],[28, 46.1]] </code></pre>
[ { "answer_id": 74450437, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:, 1:].to_dict('list').values()]\nprint(out)\n" }, { "answer_id": 74450536, "author": "pank", "author_id": 8022007, "author_profile": "https://Stackoverflow.com/users/8022007", "pm_score": 0, "selected": false, "text": "data = []\nfor idx, r in df.iterrows():\n row = []\n for col in r:\n if None not in col:\n row.append(col)\n data.append(row)\n" }, { "answer_id": 74450949, "author": "Ben", "author_id": 20418639, "author_profile": "https://Stackoverflow.com/users/20418639", "pm_score": 0, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:,1:6].values.tolist()]\n \nout\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20418639/" ]
74,449,361
<p>here is the normal typoscript code for the Example like the Description:</p> <pre><code>page { meta { description = TEXT description { field = og_description // description crop = 160| |1 } } } </code></pre> <p>How can i add a crop for the description Text?</p> <p>Thanks all</p>
[ { "answer_id": 74450437, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:, 1:].to_dict('list').values()]\nprint(out)\n" }, { "answer_id": 74450536, "author": "pank", "author_id": 8022007, "author_profile": "https://Stackoverflow.com/users/8022007", "pm_score": 0, "selected": false, "text": "data = []\nfor idx, r in df.iterrows():\n row = []\n for col in r:\n if None not in col:\n row.append(col)\n data.append(row)\n" }, { "answer_id": 74450949, "author": "Ben", "author_id": 20418639, "author_profile": "https://Stackoverflow.com/users/20418639", "pm_score": 0, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:,1:6].values.tolist()]\n \nout\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3923134/" ]
74,449,377
<p><a href="https://i.stack.imgur.com/H9Pw3.png" rel="nofollow noreferrer">enter image description here</a></p> <p>I'm developing a quiz game for college.</p> <p>What I want is to stock all of the 8 label.Text values into an array , or in anything that I can iterate over.</p> <pre><code>string[] raspunsuri = new string[8] { label2.Text , label3.Text , etc ...}; </code></pre> <p>Error code is: CS0236.</p> <p>I'm new to C# and even googling things up didn't help me much .</p> <p>I tried declaring a single value at a time</p> <pre><code>string test = label.text; </code></pre> <p>but I get the same error.</p> <p>Tried declaring inside a public method I created but it doesn't work either.</p>
[ { "answer_id": 74450437, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 1, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:, 1:].to_dict('list').values()]\nprint(out)\n" }, { "answer_id": 74450536, "author": "pank", "author_id": 8022007, "author_profile": "https://Stackoverflow.com/users/8022007", "pm_score": 0, "selected": false, "text": "data = []\nfor idx, r in df.iterrows():\n row = []\n for col in r:\n if None not in col:\n row.append(col)\n data.append(row)\n" }, { "answer_id": 74450949, "author": "Ben", "author_id": 20418639, "author_profile": "https://Stackoverflow.com/users/20418639", "pm_score": 0, "selected": false, "text": "out = [[y for y in x if None not in y] for x in df.iloc[:,1:6].values.tolist()]\n \nout\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512273/" ]
74,449,397
<p>I have an object called headers. Inside which I want to add certain headers with some random value like:</p> <pre class="lang-js prettyprint-override"><code>configs = { header : { 'x-some-id': Math.random().toString() } } </code></pre> <p>The config paramter is used to client which is used to send http requests. And the randomid is some id generated by a load balancer. So it will we different for every request. We dont want to create a new client for every client, hence I want to use getter function in header so that everytime a request is made, the header is automatically populated with a new id. How do I implement this using getters. ideally this is what I what to achieve:</p> <pre class="lang-js prettyprint-override"><code>configs = { header : { 'x-some-id': get() { return Math.random().toString()} } } </code></pre>
[ { "answer_id": 74449479, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 1, "selected": false, "text": "Proxy" }, { "answer_id": 74449790, "author": "Bergi", "author_id": 1048572, "author_profile": "https://Stackoverflow.com/users/1048572", "pm_score": 3, "selected": true, "text": "configs = {\n header: {\n get 'x-some-id'() { return Math.random().toString(); },\n },\n};\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13186127/" ]
74,449,437
<p>Hello I'm trying to create a program that takes input and prints out the initials all uppercase but I can't figure out why my program is only printing the first letter of the last item of the list after string is split</p> <p>this is my code:</p> <pre><code>full_name = input(&quot;Please enter your full name: &quot;) name = full_name.split() for item in name: new_name = item[0].upper() print(new_name) </code></pre>
[ { "answer_id": 74449479, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 1, "selected": false, "text": "Proxy" }, { "answer_id": 74449790, "author": "Bergi", "author_id": 1048572, "author_profile": "https://Stackoverflow.com/users/1048572", "pm_score": 3, "selected": true, "text": "configs = {\n header: {\n get 'x-some-id'() { return Math.random().toString(); },\n },\n};\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20473614/" ]
74,449,447
<p>In reactive form, I am using mat-select in a FormArray, for reason that I didn't understand the valueChange response only in the second touch.</p> <p>this is the method that I am using:</p> <pre><code> doSomething(i) { this.form.at(i).valueChanges.pipe(switchMap((categoryId: any) =&gt; { return this.service.getDataByCategoryTypeAndProperty(categoryId, this.propertyId) })).subscribe(data =&gt;{ this.gatData = data }) } &lt;mat-form-field &gt; &lt;mat-label&gt;Service &lt;/mat-label&gt; &lt;mat-select formControlName=&quot;categoryId&quot; (selectionChange)=&quot;doSomething(i)&quot; &gt; &lt;mat-option *ngFor=&quot;let category of Categories&quot; [value]=&quot;category.categoryId&quot;&gt;{{category.categoryName}}&lt;/mat-option&gt; &lt;/mat-select&gt; &lt;/mat-form-field&gt; </code></pre> <p>my question is how valueChanges will respond from the first touch, Thanks</p>
[ { "answer_id": 74449479, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 1, "selected": false, "text": "Proxy" }, { "answer_id": 74449790, "author": "Bergi", "author_id": 1048572, "author_profile": "https://Stackoverflow.com/users/1048572", "pm_score": 3, "selected": true, "text": "configs = {\n header: {\n get 'x-some-id'() { return Math.random().toString(); },\n },\n};\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9088906/" ]
74,449,457
<p>I have tried</p> <ol> <li>subset(df,df$date &gt;= as.Date('2008-01-01'),na.rm = FALSE)</li> <li>subset(df,df$date &gt;= as.Date('2008-01-01'),na.omit = FALSE)</li> </ol> <p>I'm losing all the people who have NAs too. Please suggest a way to sort it out</p> <p>I tried subset(df,df$date &gt;= as.Date('2008-01-01'),na.rm = FALSE)</p>
[ { "answer_id": 74449629, "author": "Gregor Thomas", "author_id": 903061, "author_profile": "https://Stackoverflow.com/users/903061", "pm_score": 1, "selected": false, "text": "?subset" }, { "answer_id": 74449648, "author": "TarJae", "author_id": 13321647, "author_profile": "https://Stackoverflow.com/users/13321647", "pm_score": 0, "selected": false, "text": "filter" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512348/" ]
74,449,462
<p>Let's say we have a class that has a function foo() that counts to 3 and we want from another class to be able to modify this function and after modifying it counts to 3 that was previously declared but also executes the new code too. The function foo() would only be called by class1 and i dont want to use inheritance. The new code that im supposed to add lets say it doesnt have any relationship with class1.</p> <p>For Example:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt; using namespace std; class class1 { public: class1() { } void foo() { for(int i =0;i&lt;2;i++) {cout &lt;&lt; i &lt;&lt; endl;} } }; class class2 { public: class2() { } void foo() override { Super::foo(); cout &lt;&lt; &quot;Jump from a cliff&quot; &lt;&lt; endl; } }; int main() { class1 c1 = class1(); class2 c2 = class2(); c1.foo(); return 0; } </code></pre> <p>Result:</p> <pre><code>0 1 2 Jump From a cliff </code></pre>
[ { "answer_id": 74449629, "author": "Gregor Thomas", "author_id": 903061, "author_profile": "https://Stackoverflow.com/users/903061", "pm_score": 1, "selected": false, "text": "?subset" }, { "answer_id": 74449648, "author": "TarJae", "author_id": 13321647, "author_profile": "https://Stackoverflow.com/users/13321647", "pm_score": 0, "selected": false, "text": "filter" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17457445/" ]
74,449,475
<p>I have a dataset that looks like that:</p> <p><a href="https://i.stack.imgur.com/lFczO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lFczO.png" alt="enter image description here" /></a></p> <p>There are 15 unique values in the column 'query id', so I am trying to create new dataframes for each unique value. I thought of having a loop for every unique value in column 'query id' with a code like this:</p> <pre><code>df_list = [] i = 0 for x in df['query id'].unique(): df{i} = pd.DataFrame(columns=df.columns) df_list.append() i+=1 </code></pre> <p>But I am definitely doing something wrong there and got stuck. Do you have any ideas of how to do that?</p> <p>Sample dataset:</p> <pre><code>relevance query id 1 2 3 1 WT04-170 10 40 80 1 WT04-170 20 60 70 1 WT04-176 30 70 50 1 WT04-176 40 90 20 1 WT04-173 50 100 10 </code></pre>
[ { "answer_id": 74449560, "author": "KJDII", "author_id": 14898697, "author_profile": "https://Stackoverflow.com/users/14898697", "pm_score": 0, "selected": false, "text": "\ndf_list = []\n\nfor x in set(df['query id'].to_list()):\n df = df[df['query id'] == x].copy() \n df_list.append(df)\n\n\n\n" }, { "answer_id": 74449643, "author": "markd227", "author_id": 13650733, "author_profile": "https://Stackoverflow.com/users/13650733", "pm_score": 0, "selected": false, "text": "df_dict = {}\nfor (i,x) in enumerate(df['query id'].unique()):\n df_dict[i] = df[df['query id']==x].copy()\n" }, { "answer_id": 74450373, "author": "SNygard", "author_id": 5037133, "author_profile": "https://Stackoverflow.com/users/5037133", "pm_score": 3, "selected": true, "text": "dfs = {query_id: grp.copy() for query_id, grp in df.groupby(\"query id\")}\n" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18134832/" ]
74,449,478
<p>I read that <code>stdint.h</code> is used for portability, but I'm confused.</p> <p>If I wrote a program on a 32-bit system, uint32_t (unsigned int) is 4-bytes.</p> <p>But when this program is run on 16-bit system, int is 2bytes and uint32_t (unsigned int) is 2bytes.</p> <p>I think portability is not guaranteed in this case. Is there anything I am understanding wrong?</p>
[ { "answer_id": 74449509, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 1, "selected": false, "text": "uint32_t" }, { "answer_id": 74449573, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 3, "selected": false, "text": "uint32_t" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14561051/" ]
74,449,488
<p>Well I'm trying to create user addition form from frontend that creates user and additional info based on custom user model.But I'm getting <code>duplicate key value violates unique constraint &quot;users_driver_email_key&quot; DETAIL: Key (email)=() already exists.</code> here is my code:</p> <p><strong>Models.py</strong></p> <pre><code>class CustomUser(AbstractUser): is_driver = models.BooleanField(default=False) is_accountant = models.BooleanField(default=False) is_dispatcher = models.BooleanField(default=False) class Driver(models.Model): driver_user = models.OneToOneField(CustomUser, on_delete = models.CASCADE, primary_key = True) full_name = models.CharField(max_length=50, default=None) phone_number = models.CharField(max_length=50, default=None) email = models.EmailField(unique=True,max_length=255, default=None) address = models.CharField(max_length=70, default=None) country = models.CharField(max_length=50, default=None) state = models.CharField(choices=US_STATES,max_length=50, default=None) city = models.CharField(max_length=50, default=None) zipp = models.CharField(max_length=50, default=None) birth_date = models.DateField(default=None) license_no = models.IntegerField(default=None) license_exp_date = models.DateField(default=None) last_medical = models.DateField(default='', blank=True, null=True) next_medical = models.DateField(default='', blank=True, null=True) last_drug_test = models.DateField(default='', blank=True, null=True) next_drug_test = models.DateField(default='', blank=True, null=True) date_created = models.DateTimeField(auto_now_add=True) date_edited = models.DateTimeField(auto_now=True) status = models.IntegerField(choices=STATUS, default=1) class DriversFiles(models.Model): file = models.FileField(upload_to=&quot;media/&quot;, blank=True, null=True) driver_files = models.ForeignKey('Driver', on_delete=models.CASCADE, default=None, null=True) @receiver(post_save, sender=CustomUser) def create_user_profile(sender, instance, created, **kwargs): # if Created is true (Means Data Inserted) if created: # Check the user_type and insert the data in respective tables if instance.is_driver: Driver.objects.create( driver_user=instance, full_name = &quot;123&quot;, phone_number = &quot;123&quot;, email = &quot;&quot;, address = &quot;123&quot;, country = &quot;123&quot;, state = &quot;123&quot;, city = &quot;123&quot;, zipp = &quot;213&quot;, birth_date = '2022-01-01', license_no = '1234', license_exp_date = '2022-01-01', last_medical= '2022-01-01', next_medical = '2022-01-01', last_drug_test = '2022-01-01', next_drug_test = '2022-01-01', ) </code></pre> <p><strong>Views.py</strong></p> <pre><code>def create_driver_view(request): if request.method == &quot;POST&quot;: add_driver = DriverForm(request.POST) add_driver_file = request.FILES.getlist(&quot;file&quot;) if add_driver.is_valid(): #For Custom User password = 'Ga20224$5%' full_name = add_driver.cleaned_data['full_name'] email = add_driver.cleaned_data['email'] phone_number = add_driver.cleaned_data['phone_number'] address = add_driver.cleaned_data['address'] country = add_driver.cleaned_data['country'] state = add_driver.cleaned_data['state'] city = add_driver.cleaned_data['city'] zipp = add_driver.cleaned_data['zipp'] birth_date = add_driver.cleaned_data['birth_date'] license_no = add_driver.cleaned_data['license_no'] license_exp_date = add_driver.cleaned_data['license_exp_date'] last_medical = add_driver.cleaned_data['last_medical'] next_medical = add_driver.cleaned_data['next_medical'] last_drug_test = add_driver.cleaned_data['last_drug_test'] next_drug_test = add_driver.cleaned_data['next_drug_test'] print(email) username = email.split('@')[0] + uuid.uuid4().hex[:2] user = CustomUser.objects.create_user( username = username, password = password, is_driver = True, email = email ) #For Driver Profile user.driver.full_name = full_name user.driver.email = email user.save() # for i in add_driver_file: # DriversFiles.objects.create(driver_files=user, file=i) return redirect('drivers:list_driver') else: print(add_driver.errors) else: add_driver = DriverForm() add_driver_files = DriverFormUpload() return render(request, &quot;drivers/add.html&quot;, {&quot;add_driver&quot;: add_driver, &quot;add_driver_files&quot;: add_driver_files}) </code></pre> <p>I was getting eror {{message}} that username or email is already taken but now it opens debugger. In addition it creates user account with the same emails but then dont creates Driver table cause email is not unique.</p> <p>I'm new in django and Just wanted to create custom user models, but there is so many headaches. What should I do here. or how can I create custom user models correctly</p>
[ { "answer_id": 74449509, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 1, "selected": false, "text": "uint32_t" }, { "answer_id": 74449573, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 3, "selected": false, "text": "uint32_t" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17933458/" ]
74,449,510
<p>I have a question to make the environment of <code>if true then x else y</code> not closed, closed but not well typed, and closed and well typed. How can I do this in OCaml?</p> <p>All I know is that not closed means that there is a variable that is not bound. So x and y will not be bound in this case. Additionally, well typed means that the expression satisfies the grammar.</p> <p>Im not sure how to apply that here however and I only have very wrong answers. Maybe something like:</p> <pre><code>if (x:int, y:int) then (true) else (false) if (x:int, y: int) then (x: bool) else (y: bool) if (true) then (x: int) else (y: int) </code></pre> <p>for the 3 conditional respectively</p>
[ { "answer_id": 74449509, "author": "dbush", "author_id": 1687119, "author_profile": "https://Stackoverflow.com/users/1687119", "pm_score": 1, "selected": false, "text": "uint32_t" }, { "answer_id": 74449573, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 3, "selected": false, "text": "uint32_t" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20454562/" ]
74,449,523
<p>I have a number of checkboxes that return an array of data to PHP. They are all named 'Plans[]' but with different IDs.</p> <p>I have a CSS checkbox styler that replaces the usual HTML checkbox with something more fancy...</p> <p>When the page is displayed, there is one (or several) that are 'checked', but they don't display as checked (I think one does but that is hidden usually).</p> <p>I am assuming that the problem is caused by them all having the same name and so somehow they are the checked attribute is not getting acted on for all of them for this reason. I have tried wrapping each of them in their own forms (as I saw this suggested elsewhere) but to no avail.</p> <p>Here's an example of what it looks like:</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;style type="text/css"&gt; .checkOpt input { position: absolute; opacity: 0; cursor: pointer; } /* Create a custom radio button */ .checkmark { position: absolute; top: -.3em; right: 5%; height: 25px; width: 25px; background-color: #fff; border-radius: 20%; border: 1px; border-color: #1e62d0; border-style: dashed; } /* Create the indicator (the dot/circle - hidden when not checked) */ .checkmark:after { font-weight: 900; color: blue; margin-top: -11px; margin-left: -3px; font-family: Arial, Helvetica, sans-serif; font-size: 28px; content: "\2714"; position: absolute; display: none; } /* Style the indicator (dot/circle) */ .checkOpt .checkmark:after { top: 8px; left: 9px; width: 8px; height: 8px; border-radius: 50%; /* background: white; */ text-shadow: -1px -1px 0 #7f7f7f, 1px -1px 0 #7f7f7f, -1px 1px 0 #7f7f7f, 1px 1px 0 #7f7f7f; } /* Show the indicator (dot/circle) when checked */ .checkOpt input:checked~.checkmark:after { display: block; } /* On mouse-over, add a grey background color */ .checkOpt:hover input ~ .checkmark { background-color: #97c4fe; } /* When the radio button is checked, add a blue background */ .checkOpt input:checked ~ .checkmark { background-color: #2196F3; } .checkOpt input:disabled ~ .checkmark { background-color:#b0c7df; pointer:default; } .test { position: relative; height:60px; } &lt;/style&gt; &lt;div class="test"&gt; &lt;div class="checkOpt" style="top:20px;"&gt; &lt;label class="labelopt"&gt; &lt;input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line - OFNL" id="12" value="0.00" checked="checked" &gt; &lt;span class="checkmark"&gt;&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="test"&gt; &lt;div class="checkOpt" &gt; &lt;label class="labelopt"&gt; &lt;input type="checkbox" name="plans[]" class="checkb " title="Paper Bill" id="35" value="2.00" &gt; &lt;span class="checkmark"&gt;&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="test"&gt; &lt;div class="checkOpt"&gt; &lt;label class="labelopt"&gt; &lt;input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line " id="12" value="0.00" checked="checked" disabled="disabled"&gt; &lt;span class="checkmark"&gt;&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>...only one of these (the first) is showing as checked - the rest are not. Does anyone have any ideas what I might do to get round this (without coding changes to the subsequent data collection if possible!)</p> <p>tried everything I can think of and would welcome any suggestions....</p> <p>UPDATE - I tried updating the page so that the checkboxes have different names ('Plans[0]', 'Plans[1]' etc.) and the checkmarks suddenly started to appear in the right places.</p> <p>The issue is now that there is (legacy) JQuery code that doesn't work, i.e.</p> <pre><code>$(&quot;input[name='plans[]']:checked&quot;).each(function(){ var thisPlan= $(this).attr('id'); var thisVal = $(this).attr('value'); plans.push(thisPlan); planValues.push(thisVal); // .... // .... } </code></pre> <p>I guess this would work if the Plans list were just POSTed and picked up by PHP, but in fact it is intercepted by Javascript, processed and re-posted via Ajax to the next (PHP) page (where it is picked up quite simply by $_POST['plans']). It's a real mess, but Ihave inherited it...</p> <p>Anyone have any idea how I could work round this without breaking all the legacy (Javascript/JQuery) code?</p>
[ { "answer_id": 74450096, "author": "Adam", "author_id": 12571484, "author_profile": "https://Stackoverflow.com/users/12571484", "pm_score": -1, "selected": false, "text": ".checkOpt {\n /* added this so the container has some size */\n height: fit-content;\n display: inline-block;\n}\n\n.checkOpt input {\n /* added this, you're looking to make your checkbox invisible so just use display:none */\n display:none;\n /* removed this \n position: absolute;\n opacity: 0;\n cursor: pointer;\n */\n}\n\n/* Create a custom radio button */\n.checkmark {\n /* removed this\n position: absolute;\n top: 0em;\n /*\n right: 5%;*/\n \n /* added this so that the tick marks are positioned in the middle so you don't have to use\n absolute positioning on them */\n display: inline-flex;\n align-items:center;\n justify-content:center;\n \n height: 25px;\n width: 25px;\n background-color: #fff;\n border-radius: 20%;\n border: 1px;\n border-color: #1e62d0;\n border-style: dashed;\n cursor:pointer;\n}\n\n.checkb:checked ~ .checkmark:after {\n /*if the checkbox is checked then make the tick appear by making it opaque */\n opacity:1;\n}\n\n/* Create the indicator (the dot/circle - hidden when not checked) */\n.checkmark:after {\n font-weight: 900;\n /*color: white;\n margin-top: -11px;\n margin-left: -3px;*/\n font-family: Arial, Helvetica, sans-serif;\n font-size: 28px;\n content: \"\\2714\";\n \n /* added this - makes the tick mark transparent when it's not checked */\n opacity: 0;\n /*position: absolute;*/\n /*display: none;*/\n}\n\n.checkb:disabled ~ .checkmark:after {\n /* I noticed that you had the disabled attribute set in your HTML so I've styled this gray so you know it's \n not click-able */\n color:lightgray;\n}" }, { "answer_id": 74459286, "author": "theWoosh", "author_id": 12475071, "author_profile": "https://Stackoverflow.com/users/12475071", "pm_score": 1, "selected": false, "text": "$('input[name=\"plans[]\"]').each(function ()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12475071/" ]
74,449,533
<p>I've decided to write a custom AuthorizationHandler for a custom Policy I'm using :</p> <pre><code>// I pass this to AddPolicy in startup.cs public class MyRequirement : IAuthorizationRequirement { public MyRequirement () { ... } } public class MyAuthorizationHandler : AuthorizationHandler&lt;MyRequirement&gt; { public MyAuthorizationHandler() { } protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, MyRequirement requirement) { if (context.Resource is HttpContext httpContext) { var endpoint = httpContext.GetEndpoint(); if ( /* conditions for hard failure */ ) { context.Fail(); return; } if ( /* conditions for success */) { context.Succeed(requirement); return; } // Neither a success nor a failure, simply a different response. httpContext.Response.StatusCode = 404; httpContext.Response.ContentType = &quot;application/json&quot;; await httpContext.Response.WriteAsync(&quot;Blah blah NotFound&quot;).ConfigureAwait(false); return; } context.Fail(); } } </code></pre> <p><strong>I've seen similar code snippets in other StackOverlflow answers.</strong> (e.g. here : <a href="https://stackoverflow.com/questions/48889688/how-to-change-status-code-add-message-from-failed-authorizationhandler-policy">How to change status code &amp; add message from failed AuthorizationHandler policy</a> )</p> <p><strong>Problem : this doesn't seem to generate a &quot;valid&quot; 404 response.</strong> I think so for two reasons:</p> <ul> <li>When I look at Chrome's network tab, the response is NOT &quot;404&quot;, instead it's <strong>net::ERR_HTTP2_PROTOCOL_ERROR 404</strong></li> <li>When I look at the response data, there's only headers. <strong>My custom error text (&quot;Blah blah NotFound&quot;) does not appear anywhere.</strong></li> </ul> <p>What am I doing wrong?</p> <p><em>Note : I've tried returning immediately after setting the 404, without doing context.Fail() but I get the same result.</em></p>
[ { "answer_id": 74450096, "author": "Adam", "author_id": 12571484, "author_profile": "https://Stackoverflow.com/users/12571484", "pm_score": -1, "selected": false, "text": ".checkOpt {\n /* added this so the container has some size */\n height: fit-content;\n display: inline-block;\n}\n\n.checkOpt input {\n /* added this, you're looking to make your checkbox invisible so just use display:none */\n display:none;\n /* removed this \n position: absolute;\n opacity: 0;\n cursor: pointer;\n */\n}\n\n/* Create a custom radio button */\n.checkmark {\n /* removed this\n position: absolute;\n top: 0em;\n /*\n right: 5%;*/\n \n /* added this so that the tick marks are positioned in the middle so you don't have to use\n absolute positioning on them */\n display: inline-flex;\n align-items:center;\n justify-content:center;\n \n height: 25px;\n width: 25px;\n background-color: #fff;\n border-radius: 20%;\n border: 1px;\n border-color: #1e62d0;\n border-style: dashed;\n cursor:pointer;\n}\n\n.checkb:checked ~ .checkmark:after {\n /*if the checkbox is checked then make the tick appear by making it opaque */\n opacity:1;\n}\n\n/* Create the indicator (the dot/circle - hidden when not checked) */\n.checkmark:after {\n font-weight: 900;\n /*color: white;\n margin-top: -11px;\n margin-left: -3px;*/\n font-family: Arial, Helvetica, sans-serif;\n font-size: 28px;\n content: \"\\2714\";\n \n /* added this - makes the tick mark transparent when it's not checked */\n opacity: 0;\n /*position: absolute;*/\n /*display: none;*/\n}\n\n.checkb:disabled ~ .checkmark:after {\n /* I noticed that you had the disabled attribute set in your HTML so I've styled this gray so you know it's \n not click-able */\n color:lightgray;\n}" }, { "answer_id": 74459286, "author": "theWoosh", "author_id": 12475071, "author_profile": "https://Stackoverflow.com/users/12475071", "pm_score": 1, "selected": false, "text": "$('input[name=\"plans[]\"]').each(function ()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9359785/" ]
74,449,538
<p>On running the following MySQL (5.7.12) UPDATE statement, I get the error <em>&quot;Error Code: 1054. Unknown column 't1.col2' in 'where clause'&quot;</em>.</p> <p>How can I rephrase this query such that the columns of t1 are accessible in the subquery?</p> <pre><code>UPDATE MyFirstTable AS t1 INNER JOIN ( SELECT col1, col2 FROM MySecondTable WHERE col2 &gt; t1.col2 ) AS t2 ON t1.col1 = t2.col1 INNER JOIN ( SELECT col1, col2 FROM MySecondTable WHERE col2 &lt; t1.col2 ) AS t3 ON t1.col1 = t3.col1 AND t3.col2 = t2.col2 SET t2.col3 = t1.col3; </code></pre> <p>The objective here is to update MyFirstTable with rows from MySecondTable where, for a given col1 value, col2 was both less than and more than t1.col2 (on different rows, of course).</p>
[ { "answer_id": 74450096, "author": "Adam", "author_id": 12571484, "author_profile": "https://Stackoverflow.com/users/12571484", "pm_score": -1, "selected": false, "text": ".checkOpt {\n /* added this so the container has some size */\n height: fit-content;\n display: inline-block;\n}\n\n.checkOpt input {\n /* added this, you're looking to make your checkbox invisible so just use display:none */\n display:none;\n /* removed this \n position: absolute;\n opacity: 0;\n cursor: pointer;\n */\n}\n\n/* Create a custom radio button */\n.checkmark {\n /* removed this\n position: absolute;\n top: 0em;\n /*\n right: 5%;*/\n \n /* added this so that the tick marks are positioned in the middle so you don't have to use\n absolute positioning on them */\n display: inline-flex;\n align-items:center;\n justify-content:center;\n \n height: 25px;\n width: 25px;\n background-color: #fff;\n border-radius: 20%;\n border: 1px;\n border-color: #1e62d0;\n border-style: dashed;\n cursor:pointer;\n}\n\n.checkb:checked ~ .checkmark:after {\n /*if the checkbox is checked then make the tick appear by making it opaque */\n opacity:1;\n}\n\n/* Create the indicator (the dot/circle - hidden when not checked) */\n.checkmark:after {\n font-weight: 900;\n /*color: white;\n margin-top: -11px;\n margin-left: -3px;*/\n font-family: Arial, Helvetica, sans-serif;\n font-size: 28px;\n content: \"\\2714\";\n \n /* added this - makes the tick mark transparent when it's not checked */\n opacity: 0;\n /*position: absolute;*/\n /*display: none;*/\n}\n\n.checkb:disabled ~ .checkmark:after {\n /* I noticed that you had the disabled attribute set in your HTML so I've styled this gray so you know it's \n not click-able */\n color:lightgray;\n}" }, { "answer_id": 74459286, "author": "theWoosh", "author_id": 12475071, "author_profile": "https://Stackoverflow.com/users/12475071", "pm_score": 1, "selected": false, "text": "$('input[name=\"plans[]\"]').each(function ()" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10875689/" ]
74,449,578
<p>I wonder if we can extend the logic of <a href="https://stackoverflow.com/questions/35584085/how-to-count-duplicate-rows-in-pandas-dataframe">How to count duplicate rows in pandas dataframe?</a>, so that we also consider rows which have similar values on the columns with other rows, but the values are unordered.</p> <p>Imagine a dataframe like this:</p> <pre><code> fruit1 fruit2 0 apple banana 1 cherry orange 3 apple banana 4 banana apple </code></pre> <p>we want to produce an output like this:</p> <pre><code> fruit1 fruit2 occurences 0 apple banana 3 1 cherry orange 1 </code></pre> <p>Is this possible?</p>
[ { "answer_id": 74449825, "author": "sophocles", "author_id": 9167382, "author_profile": "https://Stackoverflow.com/users/9167382", "pm_score": 1, "selected": false, "text": "np.sort" }, { "answer_id": 74449986, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 2, "selected": false, "text": "np.sort" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6214474/" ]
74,449,591
<p>I've got everything working correctly except this one problem - with the third output it says the max pair sum is 13 due to taking sum of the first and last number. It should be 11 (as 9+2 or 4+7). I can't figure it out how I fix this problem - ending the loop with the first and last position.</p> <p>Thank you for all advice.</p> <pre><code>def _sum(num_list): maxSum = -9999999 for i in range(len(num_list)): for j in range(i-1, i+1): if not num_list[i] == num_list[j]: maxSum = max(maxSum, num_list[i] + num_list[j]) return maxSum print(_sum([1, 8, 7, 3, 5, 2])) # correct answer: 15 print(_sum([1, 2, 45, 4, 5, 6, 7, 3, 2])) # correct answer: 49 print(_sum([9, 2, 3, 4, 7, 1, 2, 3, 4])) # correct answer: 11 </code></pre> <p>I have tried write some if conditions into for j loop but it ended up with many errors. I'm truly out of ideas and I can't even imagine how it could be right.</p>
[ { "answer_id": 74449825, "author": "sophocles", "author_id": 9167382, "author_profile": "https://Stackoverflow.com/users/9167382", "pm_score": 1, "selected": false, "text": "np.sort" }, { "answer_id": 74449986, "author": "BeRT2me", "author_id": 11865956, "author_profile": "https://Stackoverflow.com/users/11865956", "pm_score": 2, "selected": false, "text": "np.sort" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20512417/" ]
74,449,599
<p>So i was working on some python code so i could get a better understanding of dictionaries. I have only been learning python 2 weeks and its my first language, so there is definitely a lack of knowledge on my end. I started the program originally to have a user input the section number they were on in a video series and it would output how much time they have left in the entire series. I think expanded on the code to add more output of things like % complete, etc. One of the outputs I added last to the program is to take the section that the user had entered as input and display how long that section is. There are 23 total sections and if the users enters 1-14 then it displays the information accurately. However, if they enter 15-23 then that display line is completely ignored on output. I won't post the whole code as its too long, but here is some of the relevant info.</p> <p>Here is the dictionary at the top of the code. The key is the section and the value is the number of minutes in that section. Then you have the only input in the program, followed by the code for showing the length of the selected section.</p> <pre><code>video_dict = { 1 : 19, 2 : 54, 3 : 122, 4 : 9, 5 : 75, 6 : 174, 7 : 100, 8 : 81, 9 : 29, 10 : 46, 11 : 138, 12 : 23, 13 : 17, 14 : 143, 15 : 143, 16 : 24, 17 : 45, 18 : 28, 19 : 3, 20 : 41, 21 : 45, 22 : 15, 23 : 1 } current_section = int(input('What section are you currently on? (1-23)\n')) # Show how long the selected section is current_total_time = int(video_dict[current_section]) current_total_minutes = 0 current_total_hours = 0 if current_total_time &gt;= 60: current_total_minutes = int(current_total_time % 60) current_total_hours = int((current_total_time - current_total_minutes) / 60) if current_total_hours == 1: if current_total_minutes == 1: print(f'Section {current_section} is {current_total_hours} hour and {current_total_minutes} minute long.\n') elif current_total_minutes &gt;= 2: print(f'Section {current_section} is {current_total_hours} hour and {current_total_minutes} minutes long.\n') elif current_total_minutes == 0: print(f'Section {current_section} is {current_total_hours} hour long.\n') elif current_total_hours &gt;= 2: if current_total_minutes == 1: print(f'Section {current_section} is {current_total_hours} hours and {current_total_minutes} minute long.\n') elif current_total_minutes &gt;= 2: print(f'Section {current_section} is {current_total_hours} hours and {current_total_minutes} minutes long.\n') elif current_total_minutes == 0: print(f'Section {current_section} is {current_total_hours} hours long.\n') elif (current_total_time &gt; 0) and (current_total_time &lt; 60): if current_total_minutes == 1: print(f'Section {current_section} is {current_total_minutes} minute long.\n') elif current_total_minutes &gt;= 2: print(f'Section {current_section} is {current_total_minutes} minutes long.\n') </code></pre> <p>As a side note, I know this code is probably a little too verbose but at my current stage in learning this is where i'm at. Would there be a shorter way to type this code so that I could clean it up a little? You don't have to type an example, unless you want to, you can just say what commands i should be looking at in python and learning to accomplish this. Thank you for your input.</p>
[ { "answer_id": 74449845, "author": "mudi loodi", "author_id": 11962536, "author_profile": "https://Stackoverflow.com/users/11962536", "pm_score": 3, "selected": true, "text": "video_dict = {\n 1 : 19, 2 : 54, 3 : 122, 4 : 9, 5 : 75, 6 : 174, 7 : 100, 8 : 81, 9 : 29, 10 : 46, 11 : 138, 12 : 23, 13 : 17, 14 : 143, 15 : 143,\n 16 : 24, 17 : 45, 18 : 28, 19 : 3, 20 : 41, 21 : 45, 22 : 15, 23 : 1\n}\n\ncurrent_section = int(input('What section are you currently on? (1-23)\\n'))\n\n# Show how long the selected section is\ncurrent_total_time = int(video_dict[current_section])\ncurrent_total_minutes = 0\ncurrent_total_hours = 0\n\ncurrent_total_minutes = int(current_total_time % 60)\ncurrent_total_hours = int((current_total_time - current_total_minutes) / 60)\nif current_total_time >= 60:\n print(f'Section {current_section} is {current_total_hours} hour and {current_total_minutes} minute long.\\n')\nelse:\n print(f'Section {current_section} is {current_total_minutes} minute long.\\n')\n" }, { "answer_id": 74450817, "author": "Joshua Voskamp", "author_id": 4871001, "author_profile": "https://Stackoverflow.com/users/4871001", "pm_score": 0, "selected": false, "text": "0" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9221493/" ]
74,449,630
<p>My question is similar to <a href="https://stackoverflow.com/questions/13744620/create-a-matrix-out-of-row-column-value-triplets-in-numpy">this one</a>, but still different. I have a list of triplets like the following, representing rows and columns of a matrix with their cell value:</p> <pre><code>a = [(&quot;g1&quot;,&quot;g2&quot;,7),(&quot;g1&quot;,&quot;g3&quot;,5)] </code></pre> <p>The matrix is symmetrical, so the elements can be provided in any order - meaning that <code>(&quot;g1&quot;,&quot;g2&quot;,7)</code> would imply <code>(&quot;g2&quot;,&quot;g1&quot;,7)</code>.</p> <p>I would like to obtain a pandas df from this list, representing a matrix that has element names on the rows and columns, with missing values if a triplet is not listed in <code>a</code>:</p> <pre><code> g1 g2 g3 g1 NaN 7 5 g2 7 NaN Nan g3 5 NaN Nan </code></pre> <p>can you help me achieve this task in the most efficient way for huge lists?</p>
[ { "answer_id": 74449845, "author": "mudi loodi", "author_id": 11962536, "author_profile": "https://Stackoverflow.com/users/11962536", "pm_score": 3, "selected": true, "text": "video_dict = {\n 1 : 19, 2 : 54, 3 : 122, 4 : 9, 5 : 75, 6 : 174, 7 : 100, 8 : 81, 9 : 29, 10 : 46, 11 : 138, 12 : 23, 13 : 17, 14 : 143, 15 : 143,\n 16 : 24, 17 : 45, 18 : 28, 19 : 3, 20 : 41, 21 : 45, 22 : 15, 23 : 1\n}\n\ncurrent_section = int(input('What section are you currently on? (1-23)\\n'))\n\n# Show how long the selected section is\ncurrent_total_time = int(video_dict[current_section])\ncurrent_total_minutes = 0\ncurrent_total_hours = 0\n\ncurrent_total_minutes = int(current_total_time % 60)\ncurrent_total_hours = int((current_total_time - current_total_minutes) / 60)\nif current_total_time >= 60:\n print(f'Section {current_section} is {current_total_hours} hour and {current_total_minutes} minute long.\\n')\nelse:\n print(f'Section {current_section} is {current_total_minutes} minute long.\\n')\n" }, { "answer_id": 74450817, "author": "Joshua Voskamp", "author_id": 4871001, "author_profile": "https://Stackoverflow.com/users/4871001", "pm_score": 0, "selected": false, "text": "0" } ]
2022/11/15
[ "https://Stackoverflow.com/questions/74449630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146365/" ]