qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,208,833 | <p>I have a table called relationships:
<a href="https://i.stack.imgur.com/ves46.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ves46.png" alt="relationships" /></a></p>
<p>And another called relationship_type:
<a href="https://i.stack.imgur.com/aZPAK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aZPAK.png" alt="relationship type" /></a></p>
<p>A person can have a social worker assigned to them on a specified time period (has start and end time), or specified to them with a start time only. I am writing a query to retieve records of a social worker assigned to someone during a filtered time.
My query looks like this :</p>
<pre><code>SELECT r.person_a AS patient_id, greatest((r.start_date), (r.end_date)) as relationship_date,
concat_ws( ' ', pn.family_name, pn.given_name, pn.middle_name ) AS NAME
FROM
relationship r
INNER JOIN relationship_type t ON r.relationship = t.relationship_type_id
INNER JOIN person_name pn ON r.person_b = pn.person_id
WHERE
t.uuid = '9065e3c6-b2f5-4f99-9cbf-f67fd9f82ec5'
AND (
r.end_date IS NULL
OR r.end_date <= date("2022-10-26"));
</code></pre>
<p>I only want to retrieve the patient_id of the user and name of case worker whose relationship is valid during the filtered time. In an instance where a relationship has no end date, i use the start date. Any advice/recommendation on what i am doing wrong will be appreciated.</p>
<p>My current output :
<a href="https://i.stack.imgur.com/aiU9B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aiU9B.png" alt="output" /></a></p>
| [
{
"answer_id": 74209746,
"author": "Eugene Astafiev",
"author_id": 1603351,
"author_profile": "https://Stackoverflow.com/users/1603351",
"pm_score": 0,
"selected": false,
"text": "MailItem"
},
{
"answer_id": 74210161,
"author": "niton",
"author_id": 1571407,
"author_p... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6480460/"
] |
74,208,906 | <p>I want to search inside a JSON file with the following format:</p>
<pre><code>{
"success": true,
"msg": "",
"obj": [
{
"id": 1,
"up": 546636462,
"down": 4172830061,
"total": 53687091200,
"name": "حامد ",
"enable": true,
"expiryTime": 1667049201686,
"listen": "",
"dork": 23050,
"net": "girltik",
"settings": "{\n \"clients\": [\n {\n \"id\": \"f8c36812-11e0-47c4-9880-2c8ff9310c49\",\n \"alterId\": 0\n }\n ],\n \"disableInsecureEncryption\": false\n}",
"streamSettings": "{\n \"network\": \"ws\",\n \"security\": \"none\",\n \"wsSettings\": {\n \"path\": \"/\",\n \"headers\": {}\n }\n}",
"tag": "inbound-23050",
"sniffing": "{\n \"enabled\": true,\n \"destOverride\": [\n \"http\",\n \"tls\"\n ]\n}"
},
{
"id": 2,
"up": 25559864,
"down": 630133850,
"total": 5368709120,
"remark": "احمد ",
"enable": true,
"expiryTime": 1667051159682,
"listen": "",
"dork": 36606,
"net": "girltik",
"settings": "{\n \"clients\": [\n {\n \"id\": \"902b0800-6bbd-4874-f7f8-980deb8d37e8\",\n \"alterId\": 0\n }\n ],\n \"disableInsecureEncryption\": false\n}",
"streamSettings": "{\n \"network\": \"ws\",\n \"security\": \"none\",\n \"wsSettings\": {\n \"path\": \"/\",\n \"headers\": {}\n }\n}",
"tag": "inbound-36606",
"sniffing": "{\n \"enabled\": true,\n \"destOverride\": [\n \"http\",\n \"tls\"\n ]\n}"
}
]
}
</code></pre>
<p>I want to filter it by word <code>f8c36812-11e0-47c4-9880-2c8ff9310c49</code> in <code>settings</code> property, so that the result array contains only the matching objects:</p>
<pre><code>{
"success": true,
"msg": "",
"obj": [
{
"id": 1,
"up": 546636462,
"down": 4172830061,
"total": 53687091200,
"remark": "حامد پاشائی",
"enable": true,
"expiryTime": 1667049201686,
"listen": "",
"port": 23050,
"protocol": "vmess",
"settings": "{\n \"clients\": [\n {\n \"id\": \"f8c36812-11e0-47c4-9880-2c8ff9310c49\",\n \"alterId\": 0\n }\n ],\n \"disableInsecureEncryption\": false\n}",
"streamSettings": "{\n \"network\": \"ws\",\n \"security\": \"none\",\n \"wsSettings\": {\n \"path\": \"/\",\n \"headers\": {}\n }\n}",
"tag": "inbound-23050",
"sniffing": "{\n \"enabled\": true,\n \"destOverride\": [\n \"http\",\n \"tls\"\n ]\n}"
}
]
}
</code></pre>
<p>How can I filter an array from a JSON file using PHP?</p>
| [
{
"answer_id": 74209286,
"author": "Ramil Huseynov",
"author_id": 6711823,
"author_profile": "https://Stackoverflow.com/users/6711823",
"pm_score": 1,
"selected": false,
"text": "$str = '{\n \"success\": true,\n \"msg\": \"\",\n \"obj\": [\n {\n \"id\": 1,\n \"up\": 54663... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340007/"
] |
74,208,908 | <p>I'm a noob when it comes to Powershell so i'm wondering how to solve this. Essentially, I have a script where I obtain details for a person using a foreach loop. The problem is, I want to put this into a table of columns and rows that looks like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Age</th>
<th>eyecolour</th>
<th>gender</th>
</tr>
</thead>
<tbody>
<tr>
<td>46</td>
<td>green</td>
<td>male</td>
</tr>
</tbody>
</table>
</div>
<p>As it stands, I have a script which creates an object, but it's not right. The object is getting created per person and I don't want that. I need rows to be added per person. Also it's not in table format and needs to be exported to Excel. Any ideas on the best approach?</p>
<p>Thanks.</p>
<pre><code>$people = #variable containing multiple people
foreach ($person in $people){
$age = #some get command
$eyecolour = #some get command
$gender = #some get command
$object = new-object psobject -Property @{
age = $age
eyecolour = $eyecolour
gender = $gender
}
Write-Host $object
}
</code></pre>
| [
{
"answer_id": 74209286,
"author": "Ramil Huseynov",
"author_id": 6711823,
"author_profile": "https://Stackoverflow.com/users/6711823",
"pm_score": 1,
"selected": false,
"text": "$str = '{\n \"success\": true,\n \"msg\": \"\",\n \"obj\": [\n {\n \"id\": 1,\n \"up\": 54663... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7370085/"
] |
74,208,922 | <p>I make a vue project using this documentation: <a href="https://vuejs.org/guide/quick-start.html#creating-a-vue-application" rel="nofollow noreferrer">https://vuejs.org/guide/quick-start.html#creating-a-vue-application</a></p>
<p>And I wanted to added tailwind css to this project. So I used this guide (from point 2 <code>Install Tailwind CSS</code>): <a href="https://tailwindcss.com/docs/guides/vite#vue" rel="nofollow noreferrer">https://tailwindcss.com/docs/guides/vite#vue</a></p>
<p>But, I see no changes and get this warning:</p>
<pre><code>warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
</code></pre>
<p>I followed the instuction as it is.
I tried following the content-configuration and I double checked it to see all files in place.</p>
<p>I was expecting <code>tailwind.config.cjs</code> file should be generated but instead <code>tailwind.config.js</code> is generated.</p>
<p><strong>Updates</strong>:
On repeating all the steps using this link: <a href="https://tailwindcss.com/docs/guides/vite#vue" rel="nofollow noreferrer">https://tailwindcss.com/docs/guides/vite#vue</a></p>
<p>At step 4:
<code>Add the Tailwind directives to your CSS</code>, When I replace the content for <code>style.css</code> as asked in the step.. Exactly after this point, the error is shown.</p>
| [
{
"answer_id": 74209286,
"author": "Ramil Huseynov",
"author_id": 6711823,
"author_profile": "https://Stackoverflow.com/users/6711823",
"pm_score": 1,
"selected": false,
"text": "$str = '{\n \"success\": true,\n \"msg\": \"\",\n \"obj\": [\n {\n \"id\": 1,\n \"up\": 54663... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11626015/"
] |
74,208,960 | <p>Using XSLT, I need to create a CSV report while processing an XML document.
During the procedure, I check if one of the column will contain a comma (,); if yes I put quotes around the value. My problem is that the value may already contains " ("), which will confuse the CSV format.</p>
<p>In XSLT, how can I replace all the " (") in a string with ' (')
I tried using fn:translate:</p>
<pre><code><xsl:value-of select="**fn:translate(., '&quot;', '@apos;')**"/>
</code></pre>
<p>is rejected because it sees it as</p>
<pre><code><xsl:value-of select="fn:translate(., '"', **'''**)"/>
</code></pre>
<p>Any suggestion?</p>
<p>Current XSLT</p>
<pre><code><xsl:function name="cm:forCSV">
<xsl:param name="node" as="item()*"/>
<xsl:if test="contains($node, ',')">
<xsl:text>&quot;</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$node instance of xs:string">
<xsl:value-of select="fn:normalize-space(**fn:translate($node, '&quot;', '&apos;')**)"/>
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
<xsl:if test="contains($node, ',')">
<xsl:text>&quot;</xsl:text>
</xsl:if>
</xsl:function>
</code></pre>
<p>Sample data:
<sample value=<strong>"test"</strong>>an example**,** to be saved in a column</p>
<p>Expected:
<sample value=<strong>'test'</strong>>an example**,** to be saved in a column</p>
<p>To have in my CSV</p>
<p>..., "<sample value=<strong>'test'</strong>>an example**,** to be saved in a column", ...</p>
| [
{
"answer_id": 74209155,
"author": "Heiko Theißen",
"author_id": 16462950,
"author_profile": "https://Stackoverflow.com/users/16462950",
"pm_score": -1,
"selected": false,
"text": "fn:translate(., '\"', \"'\")\n"
},
{
"answer_id": 74209823,
"author": "michael.hor257k",
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9760824/"
] |
74,208,977 | <p>I have a vector of nondecreasing data. Here is a sample:</p>
<pre><code> 1
1
1
2
2
2
2
2
2
2
2
3
3
4
4
6
</code></pre>
<p>Clearly there are duplicates <em>and missing numbers</em>. I can remove the duplicates using <code>unique</code>, so my unique values are:</p>
<p><code>uniqueVals = unique(sortedData);</code></p>
<p>So far, so good. Now, I want to change the data so that the values in <code>sortedData</code> are replaced with their index number in <code>uniqueVals</code>. For instance, <code>uniqueVals</code> first 5 elements would be <code>1,2,3,4,6</code>, with indices <code>1,2,3,4,5</code>. I want to change <code>sortedData</code> so that 1 maps to 1, 2 maps to 2, 3 to 3, 4 to 4, <strong>6 to 5</strong> and so on.</p>
<p>I know I can create a "map" object, but that seems to just be used to map <code>uniqueVals</code> to its index. How do I apply that mapping so that the entries in <code>sortedData</code> are changed?</p>
<p>I have no need for this to be a particularly fast operation. <code>sortedData</code> contains only a few hundred thousand rows and it only needs to be done once.</p>
| [
{
"answer_id": 74209155,
"author": "Heiko Theißen",
"author_id": 16462950,
"author_profile": "https://Stackoverflow.com/users/16462950",
"pm_score": -1,
"selected": false,
"text": "fn:translate(., '\"', \"'\")\n"
},
{
"answer_id": 74209823,
"author": "michael.hor257k",
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74208977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5941157/"
] |
74,209,003 | <p>I have a catalog of the sky coordinates (for example for 12 million galaxies), ra, dec (perpendicular to the line of sight) and redshift (along the line of sight) and I made a grid on the sky and then I compute different physical properties in each cell of this grid.</p>
<p>For the pixelization perpendicular to the line of sight I used <a href="https://healpy.readthedocs.io/en/latest/" rel="nofollow noreferrer">healpy</a> and I got an array named <code>res</code>, in which it contains the indices of each cell perpendicular to the line of sight. For example <code>ra[res[1]]</code> gives me the ra of all the galaxies in the perpendicular cell number 1.</p>
<p>I also binned the distance along the line of sight (<code>chi</code>) as follows:</p>
<pre><code>bins = np.linspace(np.min(chi),np.max(chi),nzbin)
hist, edges = np.histogram(chi, bins=bins)
</code></pre>
<p>I want to create a large mask boolian array that contains all the components of my catalog in each cell, then later I use it to compute different properties in each cell. I made it as follows, by sing two loops:</p>
<pre><code>mask_list = []
for i in range(nzbin-1):
for j in range(len(res)):
mask = (np.min(ra[res[j]]) <= ra ) & ( ra <= np.max(ra[res[j]])) & (np.min(dec[res[j]]) <= dec) & (dec <= np.max(dec[res[j]])) & (chi >= edges[i]) & (chi < edges[i+1])
mask_list += [mask]
mask_grid = np.vstack(mask_list)
</code></pre>
<p>And then later to compute different properties in each cell I call my <code>mask_grid</code> as follows:</p>
<pre><code>cell = len(res)*len(bin_centers)
for i in range(cell):
ra_masked = ra[mask_grid[i]]
</code></pre>
<p>For a small values of <code>nzbins</code> (for instance 500), this works well, but when I increase it to 5000 I do have memory issues.</p>
<p>I was wondering if there is an efficient way to create this <code>mask_grid</code>.</p>
| [
{
"answer_id": 74209155,
"author": "Heiko Theißen",
"author_id": 16462950,
"author_profile": "https://Stackoverflow.com/users/16462950",
"pm_score": -1,
"selected": false,
"text": "fn:translate(., '\"', \"'\")\n"
},
{
"answer_id": 74209823,
"author": "michael.hor257k",
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20339550/"
] |
74,209,005 | <p>how i select row in dataframe based on the last position for every user id. Is there any idea?</p>
<pre><code>data=pd.DataFrame({'User_ID':['122','122','122','233','233','233','233','366','366','366'],'Age':[23,23,np.nan,24,24,24,24,21,21,np.nan]})
</code></pre>
<p>data</p>
<p>and the outcomes should be like this</p>
<pre><code>data_new=pd.DataFrame({'User_ID':['122','233','366'],'Age':[np.nan,24,np.nan]})
</code></pre>
<p>so i just try to take the last row for every user_id. I'm totally beginner, is there any idea?</p>
| [
{
"answer_id": 74209155,
"author": "Heiko Theißen",
"author_id": 16462950,
"author_profile": "https://Stackoverflow.com/users/16462950",
"pm_score": -1,
"selected": false,
"text": "fn:translate(., '\"', \"'\")\n"
},
{
"answer_id": 74209823,
"author": "michael.hor257k",
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17572223/"
] |
74,209,023 | <p>I have got:</p>
<pre><code>string pattern = "ABCDEFGH!";
</code></pre>
<p>and i want to get it into array (pattern can be longer or shorter):</p>
<pre><code>array[0] = A
array[1] = B
array[2] = C
//etc.
</code></pre>
<p>I have tried something like this:</p>
<pre><code>help = "ABCDEFGH!"
string[] pattern = help.Split("");
</code></pre>
<p>First i wanted to add space between all signs and than split and add them to my array but maybe there is better idea.</p>
| [
{
"answer_id": 74209041,
"author": "Chris",
"author_id": 13280555,
"author_profile": "https://Stackoverflow.com/users/13280555",
"pm_score": 2,
"selected": false,
"text": "string pattern = \"ABCDEFGH!\";\nchar[] patternArray = pattern.ToCharArray();\n"
},
{
"answer_id": 74209328,... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20339854/"
] |
74,209,029 | <p>I have some inputs in the following div</p>
<pre class="lang-js prettyprint-override"><code>cy.get("div[data-test-letterinputcontainer='0']")
</code></pre>
<p>One of them have a value, but it is not known which. It could for example look like this</p>
<pre class="lang-html prettyprint-override"><code><div data-test-letterinputcontainer="0">
<input value="" type="text">
<input value="" type="text">
<input value="f" type="text">
<input value="" type="text">
<input value="" type="text">
<input value="" type="text">
</div>
</code></pre>
<p>or this</p>
<pre class="lang-html prettyprint-override"><code><div data-test-letterinputcontainer="0">
<input value="g" type="text">
<input value="" type="text">
<input value="" type="text">
<input value="" type="text">
<input value="" type="text">
<input value="" type="text">
</div>
</code></pre>
<p>How can I check that</p>
<ul>
<li>One <code>input</code> has a value</li>
<li>The other <code>input</code>'s are empty?</li>
</ul>
| [
{
"answer_id": 74211057,
"author": "Amit Kahlon",
"author_id": 13508689,
"author_profile": "https://Stackoverflow.com/users/13508689",
"pm_score": 1,
"selected": true,
"text": "cy.get(\"div[data-test-letterinputcontainer='0'] input\")\n .then(($ele) => {\n let flag = false;\n for ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6193913/"
] |
74,209,081 | <p>I'm stumped. I'm working on building an Adobe Illustrator panel (based on Adobe CEP) and I cannot figure out why I'm getting an uncaught reference error: $ is not defined. I have my jQuery script linked before my .js file. To my knowledge, I need to use a local copy of jQuery so that it can be bundled with the other files to be deployed as an extension.</p>
<p>Here is an excerpt of my index.html and panel.js files:</p>
<p>I have my script links at the footer of my html (no script is being called within the HTML).</p>
<pre><code></div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/CSInterface.js"></script>
<script src="assets/js/panel.js"></script>
</body>
</html>
</code></pre>
<pre><code>// panel.js
var csi = new CSInterface(); // Adobe CEP
$(btnAddRegistration).on("click", function (e) { // Errors here
// more code here
}
</code></pre>
<p>Console: Uncaught ReferenceError: $ is not defined (panel.js:10) (It says line 10 because there are additional lines of comments at the top of the document).</p>
<p>I appreciate any advice or help figuring this one out. Thank you for your time!</p>
<p>I've tried moving my jQuery code into a document ready and window onload block, but no luck.</p>
<pre><code>"window.onload = function() {
//code here
};
</code></pre>
<pre><code>$(document).ready(function () {
//your code here
});
</code></pre>
<p>I re-downloaded my jquery.min.js file to make sure it wasn't corrupted. I've also tried moving the script src to the header section of my HTML and no change.</p>
| [
{
"answer_id": 74212040,
"author": "oniicc",
"author_id": 20339951,
"author_profile": "https://Stackoverflow.com/users/20339951",
"pm_score": 2,
"selected": false,
"text": "<script>if (typeof module === 'object') { window.module = module; module = undefined; }</script>\n<script>if (typeo... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20339951/"
] |
74,209,083 | <p>I am trying to show 2 different recipes depending on what recipe button I am clicking and unsure how to get that to stop and only show individual recipes.</p>
<pre><code>\\First Card
<Card style={{ width: '18rem' }} className="Chicken">
<Card.Img variant="top" src={chicken} className="Fav_image" />
<Card.Body>
<Card.Title className="Fav_title">Chicken Paprakash</Card.Title>
<Card.Text className="Fav_text">
This is one of my favourite fall/winter recipes to make.
</Card.Text>
<Button variant="outlined" onClick={handleOpen} className="button">Recipe</Button>
</Card.Body> <Card>
</code></pre>
<pre><code>\\Second Card
<Card style={{ width: '18rem' }} className="Fajita">
<Card.Img variant="top" src={fajita} className="Fav_image" />
<Card.Body>
<Card.Title className="Fav_title">Chicken Fajitas</Card.Title>
<Card.Text className="Fav_text">
Great for when you only have a few minutes to cook dinner.
</Card.Text>
<Button variant="outlined" onClick={handleOpen} className="button">Recipe</Button>
</Card.Body> <Card>
</code></pre>
<p>Here is the issue:<br />
<a href="https://i.stack.imgur.com/jruhr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jruhr.jpg" alt="enter image description here" /></a></p>
<p>I tried multiple different fixes on Stack overflow but not luck</p>
| [
{
"answer_id": 74212040,
"author": "oniicc",
"author_id": 20339951,
"author_profile": "https://Stackoverflow.com/users/20339951",
"pm_score": 2,
"selected": false,
"text": "<script>if (typeof module === 'object') { window.module = module; module = undefined; }</script>\n<script>if (typeo... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20296795/"
] |
74,209,091 | <p><a href="https://i.stack.imgur.com/DYBJa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DYBJa.png" alt="enter image description here" /></a></p>
<p>I want to create a new column where If my Rom Indicator is 'Y', then pick the Account ID value and swap it for all the IDs as shown below</p>
<p><a href="https://i.stack.imgur.com/0MR0B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0MR0B.png" alt="enter image description here" /></a></p>
<p>I tried using Case statments like this
<code>CASE WHEN PRIM_IND = 'Y' THEN ACT_ID ELSE ACT_ID END</code></p>
| [
{
"answer_id": 74209273,
"author": "DannySlor",
"author_id": 19174570,
"author_profile": "https://Stackoverflow.com/users/19174570",
"pm_score": 2,
"selected": false,
"text": "select t.*\n ,max(case when PRI_IND = 'Y' then ACT_ID end) over(partition by ID) as ACT_ID_NEW\nfrom t... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7777002/"
] |
74,209,109 | <p>I have an array of objects:</p>
<pre><code>[{name: "Mary", "salary": "22k", "category": "A", "dob": 1992},
{name: "Bob", "salary": "22k", "category": "A", "dob": 1994},
{name: "Paul", "salary": "22k", "category": "A", "dob": 1994},
{name: "Christy", "salary": "22k", "category": "A", "dob": 1993},
{name: "John", "salary": "22k", "category": "A", "dob": 1993},
{name: "Kenny", "salary": "22k", "category": "A", "dob": 1993},
}]
</code></pre>
<p>I am displaying these from the template using *ngFor. But now I need to categorize based on dob (it will be grouped in order as shown) and display them under 1 title.</p>
<p>Ex:</p>
<blockquote>
<p><strong>Year 1992</strong> Mary</p>
<p><strong>Year 1994</strong> Bob Paul</p>
<p><strong>Year 1993</strong> Christy John Kenny</p>
</blockquote>
<p>I can achieve this by matching the index value or some other logic in a function. But let's just say we need to handle this only through *ngIf and *ngFor (or any other template changes). Is there a way?</p>
| [
{
"answer_id": 74212774,
"author": "Ali Adravi",
"author_id": 586227,
"author_profile": "https://Stackoverflow.com/users/586227",
"pm_score": 1,
"selected": false,
"text": "let arr = [{name: \"Mary\", \"salary\": \"22k\", \"category\": \"A\", \"dob\": 1992},\n{name: \"Bob\", \"salary\": ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4567978/"
] |
74,209,117 | <p>I have an error trying to install <strong>CocoaPods</strong> for flutter iOS development on an Intel MacBook Pro running with <strong>macOS Ventura(13.0)</strong>.</p>
<p><strong>Someone now how I can fix this error issue ?</strong></p>
<p><code>sudo gem install cocoapods</code></p>
<p>(This is the error that I've, is it because I'm running on macOS 13.0 or do you think I can fix it ?)</p>
<pre><code>Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20221026-9237-4mv2z6.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
from extconf.rb:10:in `system_libffi_usable?'
from extconf.rb:42:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/gem_make.out
</code></pre>
<p>`</p>
<pre><code></code></pre>
| [
{
"answer_id": 74211418,
"author": "john",
"author_id": 16146701,
"author_profile": "https://Stackoverflow.com/users/16146701",
"pm_score": 0,
"selected": false,
"text": "Pods"
},
{
"answer_id": 74223086,
"author": "Onkar Kulkarni",
"author_id": 20349566,
"author_prof... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17429017/"
] |
74,209,124 | <p>How to achieve that the radio button switches in each menu separately and not globally in all? The moment I switch the radio button in the Family menu, for example, it is unchecked in the Size menu and vice versa.</p>
<p>I also want to set a default checked radio button for each menu, but I don't know how to do that.</p>
<p>This is my code:</p>
<pre><code>#!/usr/bin/env python3
from tkinter import *
root = Tk ()
root.geometry ("500x500")
root.title ("Program")
menu_bar = Menu (
master = root
)
root.config (
menu = menu_bar
)
fami_menu = Menu (
master = menu_bar,
tearoff = False,
)
fami_menu.add_radiobutton (
label = "Sans Serif",
)
fami_menu.add_radiobutton (
label = "Serif",
)
menu_bar.add_cascade (
label = "Family",
menu = fami_menu,
)
size_menu = Menu (
master = menu_bar,
tearoff = False,
)
size_menu.add_radiobutton (
label = "11",
)
size_menu.add_radiobutton (
label = "12",
)
menu_bar.add_cascade (
label = "Size",
menu = size_menu,
)
root.mainloop ()
</code></pre>
| [
{
"answer_id": 74211418,
"author": "john",
"author_id": 16146701,
"author_profile": "https://Stackoverflow.com/users/16146701",
"pm_score": 0,
"selected": false,
"text": "Pods"
},
{
"answer_id": 74223086,
"author": "Onkar Kulkarni",
"author_id": 20349566,
"author_prof... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209124",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20199325/"
] |
74,209,153 | <p>I want to split a column. If it has a letter (any letter) at the end, this will be the value for the second column. Otherwise, the second column should be null</p>
<pre><code>import pandas as pd
data = pd.DataFrame({"data": ["0.00I", "0.01E", "99.99", "0.14F"]})
</code></pre>
<p>desired result:</p>
<pre><code> a b
0 0.00 I
1 0.01 E
2 99.99 None
3 0.14 F
</code></pre>
| [
{
"answer_id": 74209243,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "str.extract"
},
{
"answer_id": 74212050,
"author": "Golden Lion",
"author_id": 4001177,
"author_... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3561143/"
] |
74,209,174 | <p>I am fairly new to VHDL and am following <a href="https://www.youtube.com/watch?v=NObt7r7zUoQ" rel="nofollow noreferrer">this tutorial</a> to implement the following Mealy Finite State Machine:</p>
<p><a href="https://i.stack.imgur.com/QAUu1l.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QAUu1l.jpg" alt="enter image description here" /></a></p>
<p>and have written the following code in VHDL:</p>
<pre class="lang-vhdl prettyprint-override"><code>library ieee;
use ieee.std_logic_1164.all;
entity fsm is
port(clk, rst, in1 : in std_logic; o1 : out std_logic);
end fsm;
architecture mealy of fsm is
type state is (state1, state2);
signal current_state, next_state : state;
begin
comb: process(current_state, in1) begin
next_state <= current_state; -- default case
case current_state is
when state1 =>
o1 <= '0';
if in1 = '1' then
o1 <= '1';
next_state <= state2;
end if;
when state2 =>
o1 <= '1';
if in1 = '0' then
o1 <= '0';
next_state <= state1;
end if;
end case;
end process;
mem: process(clk, rst) begin
if rst = '1' then
current_state <= state1;
else
current_state <= next_state;
end if;
end process;
end mealy;
</code></pre>
<p>However on applying the following testbench:</p>
<pre><code>library ieee;
use ieee.std_logic_1164.all;
entity fsm_tb is
end fsm_tb;
architecture sim of fsm_tb is
constant clockperiod : time := 10 ns; -- 100 Mhz clock
signal clk : std_logic := '0';
signal rst : std_logic;
signal in1, o_mealy : std_logic;
begin
uut_mealy : entity work.fsm(mealy) port map( clk => clk, rst => rst, in1 => in1, o1 => o_mealy);
clk <= not clk after clockperiod/2;
process begin
-- initial reset
in1 <= '0';
rst <= '1';
wait until rising_edge(clk);
-- take device out of reset
rst <= '0';
-- apply same inputs to both the devices
in1 <= '0'; wait for 23 ns;
in1 <= '1'; wait for 32 ns;
in1 <= '0'; wait for 7 ns;
in1 <= '1'; wait for 15 ns;
wait;
end process;
end sim;
</code></pre>
<p>the waveforms that I have obtained do not make sense to me:</p>
<p><a href="https://i.stack.imgur.com/7j6LG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7j6LG.png" alt="enter image description here" /></a></p>
<p>As you can see the output <code>o_mealy</code> changes even without clock edge. It simply seems to only be following the input. By contrast, I have implemented the equivalent Moore machine and it seems to be working just fine:</p>
<p><a href="https://i.stack.imgur.com/QwMyJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QwMyJ.png" alt="enter image description here" /></a></p>
<p>If anyone can point out what I am doing wrong, it would be highly appreciated. Again, I have used <a href="https://www.youtube.com/watch?v=NObt7r7zUoQ" rel="nofollow noreferrer">this video</a> for reference. I am using GHDL with GTKWave.</p>
| [
{
"answer_id": 74209243,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "str.extract"
},
{
"answer_id": 74212050,
"author": "Golden Lion",
"author_id": 4001177,
"author_... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13709317/"
] |
74,209,238 | <p>I need to url encode parts of the string that do not match a regex. Current solution (below) is:</p>
<ol>
<li>to select what regex I match (##.*##)</li>
<li>put found substrings in a list and replace them with some not encodable indexes ~~1~~</li>
<li>encode everything (entire url)</li>
<li>put back the elements I found</li>
</ol>
<p>I have this code that works. But I'm sure it could be done better, with a single parse looking for parts of the strings not matching my regex. It adds a huge overhead doing this everytime.</p>
<pre><code>import re
from itertools import count
import urllib.parse
def replace_parts(url):
parts = []
counter = count(0)
def replace_to(match):
match = match.group(0)
parts.append(match)
return '~~' + str(next(counter)) + '~~'
def replace_from(match):
return parts[next(counter)]
url = re.sub(r'##(.*?)##', replace_to, url)
url = urllib.parse.quote(url)
counter = count(0)
url = re.sub(r'~~([0-9]+)~~', replace_from, url)
print (url)
url1 = "http://google.com?this_is_my_encodedurl##somethin##&email=##other##tr"
url = replace_parts(url1)
# this becomes http%3A%2F%2Fgoogle.com%3Fthis_is_my_encodedurl##somethin##%0A%26email%3D##other##tr
</code></pre>
| [
{
"answer_id": 74209757,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 1,
"selected": false,
"text": "re.sub"
},
{
"answer_id": 74210583,
"author": "The fourth bird",
"author_id": 5424988,
"author_p... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/509263/"
] |
74,209,264 | <p>trying to make a 1:1 video meeting with agora with flutter and after following the docs i got
<code>AgoraRtcException(20, Make sure you call RtcEngine.initialize first)</code> exception although I am sure I am initializing it first however this the initialize code</p>
<pre class="lang-dart prettyprint-override"><code>void initState() {
super.initState();
setupVideoSDKEngine();
join();
</code></pre>
<p>the setupVideoSDKEngine() method code is</p>
<pre class="lang-dart prettyprint-override"><code>Future<void> setupVideoSDKEngine() async {
// retrieve or request camera and microphone permissions
await [Permission.microphone, Permission.camera].request();
//create an instance of the Agora engine
agoraEngine = createAgoraRtcEngine();
await agoraEngine
.initialize(RtcEngineContext(appId: Environment.agoraAppId));
await agoraEngine.enableVideo();
// Register the event handler
agoraEngine.registerEventHandler(
RtcEngineEventHandler(
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
showMessage(
"Local user uid:${connection.localUid} joined the channel");
setState(() {
_isJoined = true;
});
},
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
showMessage("Remote user uid:$remoteUid joined the channel");
setState(() {
_remoteUid = uid;
player.stop();
customTimer!.resetAndStart();
});
},
onUserOffline: (RtcConnection connection, int remoteUid,
UserOfflineReasonType reason) {
showMessage("Remote user uid:$remoteUid left the channel");
callEnded = true;
setState(() {
_remoteUid = null;
});
print('stats ${reason.name}');
if (!userOffline) {
Future.delayed(Duration(seconds: 1), () => Navigator.pop(context));
}
userOffline = true;
},
),
);
}
</code></pre>
<p>I am expecting to join the channel but nothing happens and it throws this error
I tried to delete the app and reinstall it but nothing happens</p>
<p>and got this exception too AgoraRtcException(-17, null)</p>
| [
{
"answer_id": 74209757,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 1,
"selected": false,
"text": "re.sub"
},
{
"answer_id": 74210583,
"author": "The fourth bird",
"author_id": 5424988,
"author_p... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11614768/"
] |
74,209,292 | <p>I have a problem and trying to solve by searching did not succeed. So I try it here with specific help:
I have a MainWindow Application with different Tabs. One Tab should have a DataGrid with 4 columns. I want to fill them with a List of objects.
My implementation in MainWindow.xaml.cs:</p>
<pre><code>// 4 times this kind of Code
private ObservableCollection<bool> _StatusBitsSimulateActiveList = null;
private ObservableCollection<string> _StatusBitsNameList = null;
private ObservableCollection<bool> _ActualStatusBitsList = null;
private ObservableCollection<bool> _SimulatedStatusBitsList = null;
public ObservableCollection<bool> StatusBitsSimulateActiveList
{
get
{
List<bool> list = Manager._StatusBits.GetSimulatedStatusBitsList();
_StatusBitsSimulateActiveList = new ObservableCollection<bool>(list);
return _StatusBitsSimulateActiveList;
}
set
{
_StatusBitsSimulateActiveList = value;
OnPropertyChanged();
}
}
</code></pre>
<p>The MainWindow.xaml file contains:</p>
<pre><code><DataGrid x:Name="SimulatedBitsDataGrid" MinRowHeight="25" AutoGenerateColumns="False"
Margin="5" AlternatingRowBackground="LightBlue" AlternationCount="2" Grid.Row="3" Grid.Column="0" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding StatusBitsSimulateActiveList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Simulation Active"/>
<DataGridTemplateColumn Width="*" Header="Status Bits Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<Binding Mode="TwoWay" Path="StatusBitsNameList"></Binding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridCheckBoxColumn Binding="{Binding ActualStatusBitsList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Status Bit SPS"/>
<DataGridCheckBoxColumn Binding="{Binding SimulatedStatusBitsList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Simulated Value"/>
</DataGrid.Columns>
</DataGrid>
</code></pre>
<p>I have a class, where the Data is stored and retrieved (see Manager._StatusBits) with some methods to get and set data.
The DataGrid is not filling with data. can someone help?</p>
<p>I tried through ItemsSource="Binding" and then Binding to the Lists. Not working.
Looked through the internet and found no solution, maybe I do not understand the mechanics. I am quite new to wpf, only worked on C++ and mfc.</p>
<p><em><strong>Edit:</strong></em>
So I tried some of the answers and now understand a little bit more. But one issue I cannot resolve. I do not tried with those kinds of ViewModels (maybe this could help, won't try now).
Here is my code, which is working oneWay, but not TwoWay, because no GUI interaction with the Grid is noticed. What is Missing?
Notice, this code was partly written from someone else, I trying to resolve some issues and add some features:</p>
<p>MainWindow.xaml.cs</p>
<pre><code>InitializeComponent();
this.DataContext = this; // Why do someone need to do this? Because of relativeSource Binding? see .xaml file
StatusBitDataGrid.DataContext = Manager._StatusBits.dataList; // there is a manager, which manages the objects, the Manager is created in the MainWindow
</code></pre>
<p>MainWindow.xaml</p>
<pre><code><Window x:Class="APP.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="EFEM-Client Plus+" Height="900" Width="1200"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
WindowStartupLocation="CenterScreen"
Closing="OnWindowClosing"
x:Name="window1"
>
<DataGrid x:Name="StatusBitDataGrid" Grid.Row="2" Grid.RowSpan="3" Grid.Column="0" Grid.ColumnSpan="4"
ItemsSource="{Binding}" CanUserAddRows="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridCheckBoxColumn CanUserSort="False" Binding="{Binding SimulateActive, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Simulation Active"/>
<DataGridTemplateColumn Width="*" Header="Status Bits Name" CanUserSort="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<Binding Mode="TwoWay" Path="StatusBitsName"></Binding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridCheckBoxColumn Binding="{Binding ActualBitValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Status Bit SPS" CanUserSort="False" IsReadOnly="True"/>
<DataGridCheckBoxColumn Binding="{Binding SimulatedBitValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Header="Simulated Value" CanUserSort="False"/>
</DataGrid.Columns>
</DataGrid>
</code></pre>
<p>StatusBits.cs</p>
<pre><code>public class StatusBits {
[...]
public StatusBits()
{
[...]
PopulateObservable();
}
[...]
private ObservableCollection<StatusBitsSingleData> _dataList = new ObservableCollection<StatusBitsSingleData>();
public ObservableCollection<StatusBitsSingleData> dataList
{
get { return _dataList; }
set { _dataList = value; } // Code and Style never enters the setter...
}
private void PopulateObservable()
{
dataList.Clear();
for (int i = 0; i < maxSemDexStatus; i++)
{
dataList.Add(new StatusBitsSingleData(StatusBitsSimulateActive[i], StatusBitsName[i], ActualStatusBits[i], SimulatedStatusBits[i]));
}
}
[...]
// The SingleData Class, here the setter is used by the program
public class StatusBitsSingleData
{
public bool SimulateActive { get; set; }
public string StatusBitsName { get; set; }
public bool ActualBitValue { get; set; }
public bool SimulatedBitValue { get; set; }
public StatusBitsSingleData(bool simA, string name, bool actu, bool sim)
{
SimulateActive = simA; StatusBitsName = name; ActualBitValue = actu; SimulatedBitValue = sim;
}
}
}
</code></pre>
<p>Because the setter is used in public class StatusBitsSingleData, I tried to make a custom Notifier, but failed ...</p>
| [
{
"answer_id": 74209757,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 1,
"selected": false,
"text": "re.sub"
},
{
"answer_id": 74210583,
"author": "The fourth bird",
"author_id": 5424988,
"author_p... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340259/"
] |
74,209,324 | <p>I have two different DataFrames that look something like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Lat</th>
<th>Lon</th>
</tr>
</thead>
<tbody>
<tr>
<td>28.13</td>
<td>-87.62</td>
</tr>
<tr>
<td>28.12</td>
<td>-87.65</td>
</tr>
<tr>
<td>......</td>
<td>......</td>
</tr>
</tbody>
</table>
</div><div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Calculated_Dist_m</th>
</tr>
</thead>
<tbody>
<tr>
<td>34.5</td>
</tr>
<tr>
<td>101.7</td>
</tr>
<tr>
<td>..............</td>
</tr>
</tbody>
</table>
</div>
<p>The first DataFrame (name=<code>df</code>) (consisting of the <code>Lat</code> and <code>Lon</code> columns) has just over 1000 rows (values) in it. The second DataFrame (name=<code>new_calc_dist</code>) (consisting of the <code>Calculated_Dist_m</code> column) has over 30000 rows (values) in it. I want to determine the new longitude and latitude coordinates using the <code>Lat</code>, <code>Lon</code>, and <code>Calculated_Dist_m</code> columns. Here is the code I've tried:</p>
<pre><code>r_earth = 6371000
new_lat = df['Lat'] + (new_calc_dist['Calculated_Dist_m'] / r_earth) * (180/np.pi)
new_lon = df['Lon'] + (new_calc_dist['Calculated_Dist_m'] / r_earth) * (180/np.pi) / np.cos(df['Lat'] * np.pi/180)
</code></pre>
<p>When I run the code, however, it only gives me new calculations for certain index values, and gives me NaNs for the rest. I'm not entirely sure how I should go about writing the code so that new longitude and latitude points are calculated for each of over 30000 row values based on the initial 1000 longitude and latitude points. Any suggestions?</p>
<p><em>EDIT</em></p>
<p>Here would be some sample outputs. Note that these are not exact figures, but give the idea.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Lat</th>
<th>Lon</th>
</tr>
</thead>
<tbody>
<tr>
<td>28.13</td>
<td>-87.62</td>
</tr>
<tr>
<td>28.12</td>
<td>-87.65</td>
</tr>
<tr>
<td>28.12</td>
<td>-87.63</td>
</tr>
<tr>
<td>.....</td>
<td>......</td>
</tr>
</tbody>
</table>
</div><div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Calculated_Dist_m</th>
</tr>
</thead>
<tbody>
<tr>
<td>34.5</td>
</tr>
<tr>
<td>101.7</td>
</tr>
<tr>
<td>28.6</td>
</tr>
<tr>
<td>30.8</td>
</tr>
<tr>
<td>76.5</td>
</tr>
<tr>
<td>.................</td>
</tr>
</tbody>
</table>
</div>
<p>And so the sample out put would be:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Lat</th>
<th>Lon</th>
</tr>
</thead>
<tbody>
<tr>
<td>28.125</td>
<td>-87.625</td>
</tr>
<tr>
<td>28.15</td>
<td>-87.61</td>
</tr>
<tr>
<td>28.127</td>
<td>-87.623</td>
</tr>
<tr>
<td>28.128</td>
<td>-87.623</td>
</tr>
<tr>
<td>28.14</td>
<td>-87.615</td>
</tr>
<tr>
<td>28.115</td>
<td>-87.655</td>
</tr>
<tr>
<td>28.14</td>
<td>-87.64</td>
</tr>
<tr>
<td>28.117</td>
<td>-87.653</td>
</tr>
<tr>
<td>28.118</td>
<td>-87.653</td>
</tr>
<tr>
<td>28.15</td>
<td>-87.645</td>
</tr>
<tr>
<td>28.115</td>
<td>-87.635</td>
</tr>
<tr>
<td>28.14</td>
<td>-87.62</td>
</tr>
<tr>
<td>28.115</td>
<td>-87.613</td>
</tr>
<tr>
<td>28.117</td>
<td>-87.633</td>
</tr>
<tr>
<td>28.118</td>
<td>-87.633</td>
</tr>
<tr>
<td>......</td>
<td>.......</td>
</tr>
</tbody>
</table>
</div>
<p>Again, these are just random outputs (I tried getting the exact calculations, but could not get it to work). But overall, this gives an idea of what would be wanted: taking the coordinates from the first dataframe and calculating new coordinates based on each of the calculated distances from the second dataframe.</p>
| [
{
"answer_id": 74210101,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "df1"
},
{
"answer_id": 74210717,
"author": "Pierre D",
"author_id": 758174,
"author_profile": "h... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18293338/"
] |
74,209,332 | <p>For a simple design I wanted quickly implement a ElevatedButton in a Flutter project but Flutter does not find the ElevatedButton at all. The only thing I find is the ElevatedButtonTheme and if I type in the ElevatedButton manually (incl. the child and onPressed) the name is maked as an error.</p>
<p><a href="https://i.stack.imgur.com/tRkwv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tRkwv.png" alt="enter image description here" /></a></p>
<p>Do I do something wrong? Do I need to include something extra other than the <code>import 'package:flutter/material.dart';"</code></p>
<p>Here the source code:</p>
<pre><code>import 'package:flutter/material.dart';
class LandingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
appBar: AppBar(
backgroundColor: Colors.grey[300],
title: Image.asset(
'assets/images/logo.png',
fit: BoxFit.contain,
height: 40,
),
centerTitle: true,
elevation: 0,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(50.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Quest 01 | 2022',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.normal
),
),
ElevatedButton(
onPressed: () {},
child: const Text('Example'),
),
],
),
),
),
);
}
}
</code></pre>
<p>The error message is:</p>
<blockquote>
<p>lib/pages/landingpage.dart:33:15: Error: The method 'ElevatedButton'
isn't defined for the class 'LandingPage'.</p>
<ul>
<li>'LandingPage' is from 'package:eumood/pages/landingpage.dart' ('lib/pages/landingpage.dart'). Try correcting the name to the name of
an existing method, or defining a method named 'ElevatedButton'.
ElevatedButton(
^^^^^^^^^^^^^^</li>
</ul>
</blockquote>
<p>Thanks for you help
Best,
Chris</p>
| [
{
"answer_id": 74209805,
"author": "Mohamed Gawdat",
"author_id": 15586963,
"author_profile": "https://Stackoverflow.com/users/15586963",
"pm_score": 0,
"selected": false,
"text": "ElevatedButton(\n onPressed: () {},\n child: const Text('Example'),\n ),\n"
},
{
"answer_id"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14143776/"
] |
74,209,338 | <p>I am currently trying to import some python files inside of a folder named "modules". My file structure is as follows:</p>
<pre><code>src
- classes
- modules
- image generator ( the file where I am trying to import modules)
</code></pre>
<p>Error:</p>
<pre class="lang-py prettyprint-override"><code> from modules.processing import StableDiffusionProcessingTxt2Img, process_images
ModuleNotFoundError: No module named 'modules'
</code></pre>
<pre class="lang-py prettyprint-override"><code>from modules.processing import StableDiffusionProcessingTxt2Img, process_images
</code></pre>
<p>I have attempted to add both an <code>__init__.py</code> in my <code>classes</code> folder, as well as my <code>modules</code> folder, but unfortunately that did not resolve any of my problems.</p>
<p>I have verified that the files I am trying to import are infact in my <code>modules</code> folder.</p>
| [
{
"answer_id": 74209805,
"author": "Mohamed Gawdat",
"author_id": 15586963,
"author_profile": "https://Stackoverflow.com/users/15586963",
"pm_score": 0,
"selected": false,
"text": "ElevatedButton(\n onPressed: () {},\n child: const Text('Example'),\n ),\n"
},
{
"answer_id"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16790110/"
] |
74,209,342 | <p>1)Check [image one] if the user clicks on that tile we are showing full view page [image 2] to him</p>
<p>2)After clicking the left-side blue color back icon we need to redirect him to the back page where he stayed last time means (same tab and same position).</p>
<p>3)I have passed query params in the URL and stored the query params in local storage.</p>
<p>4)After clicking on the back button I am getting params from local storage and passing
in the navigate URL but after clicking back it is not working properly every time it is going
to the 1st tab only
<a href="https://i.stack.imgur.com/hldZW.png" rel="nofollow noreferrer">one</a>, <a href="https://i.stack.imgur.com/1EPE0.png" rel="nofollow noreferrer">two</a>, <a href="https://i.stack.imgur.com/ic2QS.png" rel="nofollow noreferrer">three</a></p>
<pre><code>->Here in the first image after clicking on the tile second image will be shown
->In the second image after clicking left side back icon I need to get 1st image URL and page also should be same but it is going to other URL and other page.
</code></pre>
<p>please check the code and help me</p>
<pre><code>enter code here
getUrl() {
this.router.navigate(['/app/my-transactions'], { queryParams: { 'tab': this.currentTab, 'type': this.type } });
localStorage.setItem('tab' , this.currentTab);
localStorage.setItem('type' ,this.type);
}
showData(type) {
this.type = type
if (type === 'shift') {
this.isStock = true;
this.isShift = true;
this.addParams;
this.dataSource=[];
if (this.transactionData && this.transactionData.stockShift) {
this.dataSource = (this.transactionData.stockShift).reverse() || [];
}
} else if (type === 'transaction') {
this.isStock = false;
this.addParams;
this.dataSource=[];
if (this.transactionData && this.transactionData.transactions) {
this.dataSource = (this.transactionData.transactions).reverse() || [];
}
}
else if (type === 'returns') {
this.isReturns = true;
// this.isStock = false;
this.addParams;
this.dataSource=[];
if (this.transactionData && this.transactionData.returns) {
this.dataSource = (this.transactionData.returns).reverse() || [];
}
}
else if (type === 'processing') {
this.isStock = true;
this.isShift = false;
this.addParams;
this.dataSource=[];
if (this.stockTransactions && this.stockTransactions.stockProcessing) {
this.dataSource = (this.stockTransactions.stockProcessing).reverse() || [];
}
} else if (type === 'adjustment') {
this.isStock = true;
this.isShift = false;
this.addParams;
this.dataSource=[];
if (this.stockTransactions && this.stockTransactions.stockAdjustment) {
this.dataSource = (this.stockTransactions.stockAdjustment).reverse() || [];
}
}
this.getUrl();
}
backbtn() {
let currentTab = localStorage.getItem('tab');
let type = localStorage.getItem('type');
this.router.navigate(['app/my-transactions'], {queryParams: {'tab': currentTab, 'type': type }, queryParamsHandling: 'merge'});
}
</code></pre>
| [
{
"answer_id": 74209805,
"author": "Mohamed Gawdat",
"author_id": 15586963,
"author_profile": "https://Stackoverflow.com/users/15586963",
"pm_score": 0,
"selected": false,
"text": "ElevatedButton(\n onPressed: () {},\n child: const Text('Example'),\n ),\n"
},
{
"answer_id"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14234491/"
] |
74,209,355 | <p>I want acess the keys of a object but those keys are objects too.</p>
<pre><code>const caio = new Person("Caio")
const rafael = new Person("Rafael")
const expense = {caio: 10, rafael: 0}
console.log(Object.keys(expense))
#result ['caio', 'rafael']
</code></pre>
<p>I would want to acess the objects caio/rafael (Person objects). Is it possible?</p>
| [
{
"answer_id": 74209805,
"author": "Mohamed Gawdat",
"author_id": 15586963,
"author_profile": "https://Stackoverflow.com/users/15586963",
"pm_score": 0,
"selected": false,
"text": "ElevatedButton(\n onPressed: () {},\n child: const Text('Example'),\n ),\n"
},
{
"answer_id"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340252/"
] |
74,209,361 | <p>I have been running into this very weird issue with Laravel.</p>
<p>I had a problem where one of my component views was not able to read the variables defined in its class. It was kind of strange because I have several components running in my project and they all worked fine, except for this one.</p>
<p>So I created a fresh Laravel project to test some things out (Wanted to check if the problem was on my end, maybe I somehow messed up the project files).</p>
<p>I created a new component on a blank project using php artisan make:component top_nav
pre function basically is used as print_r which is in helper.php
Then I simply added a sql_data variable to the class component like so:<a href="https://i.stack.imgur.com/5DHVW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5DHVW.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/JMBA7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JMBA7.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/ZfEir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZfEir.png" alt="error image also is in there kindly help me" /></a></p>
<p>i tried many thing as much as i can do but still i can't access that variable
also clear cache of view
of laravel
change name of components but still can't work</p>
<p>kindly help me..........</p>
| [
{
"answer_id": 74209461,
"author": "Delano van londen",
"author_id": 19923550,
"author_profile": "https://Stackoverflow.com/users/19923550",
"pm_score": 1,
"selected": false,
"text": "return view('components.top_nav', ['sql_data' => $sql_data]);\n"
},
{
"answer_id": 74227335,
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340328/"
] |
74,209,362 | <p>I'm writing a chrome extension that displays the content of an "https" web page in the popup window.
So far I have been able to see the default popup window that I place in the <code>manifest.json</code> file.
I am doing something like this in my manifest:</p>
<pre><code>{
"manifest_version": 3,
"name": "My Rewards",
"description": "Validate Identify",
"version": "1.1",
"permissions": [
"identity", "identity.email"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16":"/images/icons/myRewards16.png",
"32":"/images/icons/myRewards32.png",
"48":"/images/icons/myRewards48.png",
"128":"/images/icons/myRewards128.png"
}
},
"icons":{
"16":"/images/icons/myRewards16.png",
"32":"/images/icons/myRewards32.png",
"48":"/images/icons/myRewards48.png",
"128":"/images/icons/myRewards128.png"
}
</code></pre>
<p>I was looking at the chrome extensions documentation and it says that it could be done using the <code>action.setPopup()</code> method.
I'm a bit of a novice on the subject
and I do not know the correct way to add the method, could you please guide me.</p>
| [
{
"answer_id": 74213946,
"author": "Norio Yamamoto",
"author_id": 20074043,
"author_profile": "https://Stackoverflow.com/users/20074043",
"pm_score": 0,
"selected": false,
"text": "const url = \"https://developer.chrome.com/docs/extensions/\";\n\nchrome.tabs.create({ url: url }, () => {\... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20334739/"
] |
74,209,379 | <p>I have a model called <code>RealEstate</code>, this model has a relation with another model called <code>TokenPrice</code>, I needed to access the oldest records of <code>token_prices</code> table using by a simple <code>hasOne</code> relation, So I did it and now my relation method is like following:</p>
<pre class="lang-php prettyprint-override"><code>
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
class RealEstate extends Model
{
public function firstTokenPrice(): HasOne
{
return $this->hasOne(TokenPrice::class)->oldestOfMany();
}
}
</code></pre>
<p>By far it's fine and no complexity. But now, I need to involve another relation into <code>firstTokenPrice</code>.</p>
<p>Let me explain a bit more:</p>
<p>As my project grown, the more complexity was added it, like changing <code>firstTokenPrice</code> using by a third table called <code>opening_prices</code>, so I added a new relation to <code>RealEstate</code> called <code>lastOpeningPrice</code>:</p>
<pre class="lang-php prettyprint-override"><code>public function lastOpeningPrice(): HasOne
{
return $this->hasOne(OpeningPrice::class)->latestOfMany();
}
</code></pre>
<p>So the deal with simplicity of <code>firstTokenPrice</code> relation is now off the table, I want to do something like following every time a <code>RealEstate</code> object calls for its <code>firstTokenPrice</code>:</p>
<blockquote>
<p>Check for <code>lastOpeningPrice</code>, if it was exists, then <code>firstTokenPrice</code> must returns a different record of <code>token_price</code> table, otherwise the <code>firstTokenPrice</code> must returns <code>oldestOfMany</code> of <code>TokenPrice</code> model.</p>
</blockquote>
<p>I did something like following but it's not working:</p>
<pre class="lang-php prettyprint-override"><code>
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
class RealEstate extends Model
{
public function lastOpeningPrice(): HasOne
{
return $this->hasOne(OpeningPrice::class)->latestOfMany();
}
public function firstTokenPrice(): HasOne
{
$lop = $this->lastOpeningPrice;
if ($lop) {
TokenPriceHelper::getOrCreateFirstToken($this, $lop->amount); // this is just a helper function that inserts a new token price into `token_prices` table, if there was none exists already with selected amount
return $this->hasOne(TokenPrice::class)->where('amount', $lop->amount)->oldestOfMany();
}
return $this->hasOne(TokenPrice::class)->oldestOfMany();
}
}
</code></pre>
<p>I have checked the <code>$this->hasOne(TokenPrice::class)->where('amount', $lop->amount)->oldestOfMany()</code> using by <code>->toSql()</code> method and it returns something unusual.</p>
<p><strong>I need to return a <code>HasOne</code> object inside of <code>firstTokenPrice</code> method.</strong></p>
| [
{
"answer_id": 74213946,
"author": "Norio Yamamoto",
"author_id": 20074043,
"author_profile": "https://Stackoverflow.com/users/20074043",
"pm_score": 0,
"selected": false,
"text": "const url = \"https://developer.chrome.com/docs/extensions/\";\n\nchrome.tabs.create({ url: url }, () => {\... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/836979/"
] |
74,209,389 | <p>I don't know how to make the random numbers print only the ones that are divisible by 5</p>
<p>PS: I am a newbie</p>
<pre><code>const min = 100;
const max = 999;
const a = Math.floor(Math.random() * (max - min + 1)) + min;
const b = Math.floor(Math.random() * (max - min + 1)) + min;
const c = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(`${a} ${b} ${c}`);
// Sample output should be: 145 570 865
</code></pre>
| [
{
"answer_id": 74209639,
"author": "QueueHammer",
"author_id": 46810,
"author_profile": "https://Stackoverflow.com/users/46810",
"pm_score": 0,
"selected": false,
"text": "rangedRandFactory = (multiple, min, max) => {\n const ceil = Math.floor(max/multiple);\n const floor = Math.ceil(m... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19472049/"
] |
74,209,391 | <p>I'm trying to make a nav scrollable but horizontally and with buttons when media queries kicks in. I can't find any solution and it's becoming overwhelming. My team used bootstrap 5.2 and then used scss for styling the project. I think it was the worst mistake we did. We have to replicate EA site and it is starting to look pretty complicated.</p>
<p>I am trying to replicate the same behavior of the "lastest updates" nav when resized.
If you scroll down to "latest updates" in this link you can see it: <a href="https://www.ea.com/" rel="nofollow noreferrer">https://www.ea.com/</a></p>
<p>What I've tried so far:</p>
<p>my HTML with script at the end of the body:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bootstrap demo</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="../css/main.css" />
</head>
<body>
<nav class="container">
<div class="scroll-horizontal">
<button class="btn-scroll" id="btn-scroll-left" onclick="scrollHorizontally(1)">I</button>
<button class="btn-scroll" id="btn-scroll-right" onclick="scrollHorizontally(-1)">I</button>
</div>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<button
class="nav-link h6 active"
id="nav-notizie-ea-tab"
data-bs-toggle="tab"
data-bs-target="#nav-notizie-ea"
type="button"
role="tab"
aria-controls="nav-notizie-ea"
aria-selected="true"
>
<p>Notizie EA</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-ea-play-tab"
data-bs-toggle="tab"
data-bs-target="#nav-ea-play"
type="button"
role="tab"
aria-controls="nav-ea-play"
aria-selected="false"
>
<p>EA Play</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-fifa-tab"
data-bs-toggle="tab"
data-bs-target="#nav-fifa"
type="button"
role="tab"
aria-controls="nav-fifa"
aria-selected="false"
>
<p>FIFA</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-f1-tab"
data-bs-toggle="tab"
data-bs-target="#nav-f1"
type="button"
role="tab"
aria-controls="nav-f1"
aria-selected="false"
>
<p>F1</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-apex-legends-tab"
data-bs-toggle="tab"
data-bs-target="#nav-apex-legends"
type="button"
role="tab"
aria-controls="nav-apex-legends"
aria-selected="false"
>
<p>Apex Legends</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-the-sims-4-tab"
data-bs-toggle="tab"
data-bs-target="#nav-the-sims-4"
type="button"
role="tab"
aria-controls="nav-the-sims-4"
aria-selected="false"
>
<p>The Sims <sup>tm</sup>4</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-battlefield-tab"
data-bs-toggle="tab"
data-bs-target="#nav-battlefield"
type="button"
role="tab"
aria-controls="nav-battlefield"
aria-selected="false"
>
<p>Battlefield</p>
<hr class="button-hr" />
</button>
<button
class="nav-link h6"
id="nav-inside-ea-tab"
data-bs-toggle="tab"
data-bs-target="#nav-inside-ea"
type="button"
role="tab"
aria-controls="nav-inside-ea"
aria-selected="false"
>
<p>Inside EA</p>
<hr class="button-hr" />
</button>
</div>
</nav>
<hr class="nav-hr" />
<div class="tab-content" id="nav-tabContent">
<div
class="tab-pane fade show active"
id="nav-notizie-ea"
role="tabpanel"
aria-labelledby="nav-notizie-ea-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-ea-play"
role="tabpanel"
aria-labelledby="nav-ea-play-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-fifa"
role="tabpanel"
aria-labelledby="nav-fifa-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-f1"
role="tabpanel"
aria-labelledby="nav-f1-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-apex-legends"
role="tabpanel"
aria-labelledby="nav-apex-legends-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-the-sims-4"
role="tabpanel"
aria-labelledby="nav-the-sims-4-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-battlefield"
role="tabpanel"
aria-labelledby="nav-battlefield-tab"
tabindex="0"
>
...
</div>
<div
class="tab-pane fade"
id="nav-inside-ea"
role="tabpanel"
aria-labelledby="nav-inside-ea-tab"
tabindex="0"
>
...
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"
></script>
<script>
let currentScrollPosition = 0;
let scrollAmount = 50;
const navCont = document.querySelector(".nav");
const horizontalScroll = document.querySelector(".scroll-horizontal");
const btnScrollLeft = document.querySelector("#btn-scroll-left");
const btnScrollRight = document.querySelector("#btn-scroll-right");
let maxScroll= -navCont.offsetWidth + horizontalScroll.offsetWidth;
function scrollHorizontally(val){
currentScrollPosition += (val * scrollAmount);
if(currentScrollPosition > 0){
currentScrollPosition = 0;
}
// if(currentScrollPosition < maxScroll){
// currentScrollPosition = maxScroll;
// }
navCont.style.left = currentScrollPosition + "px";
}
</script>
</body>
</html>
</code></pre>
<p>My SCSS:</p>
<pre><code>@import "../abstracts/colors";
.scroll-horizontal {
width: 100%;
display: none;
z-index: 1;
justify-content: space-between;
}
.nav::-webkit-scrollbar {
display: none;
}
.nav {
flex-wrap: nowrap;
border-bottom: 0px solid var(--gray);
flex-shrink: 0;
// overflow: hidden;
position: relative;
transition: 0.1s all ease-out;
#nav-tab {
position: relative;
}
.nav-link {
height: 3.5rem;
position: relative;
color: black;
border-radius: 0%;
padding-left: 0px;
padding-right: 0px;
border: 0px;
flex-shrink: 0;
transition: 1s all ease-out;
.button-hr {
border: 0px;
width: 85%;
height: 2px;
opacity: 1;
background-color: var(--orange);
position: absolute;
bottom: -27%;
left: 7%;
visibility: hidden;
flex-shrink: 0;
}
p {
width: 100%;
padding-inline: 1rem;
margin-bottom: 0px;
border-left: 1px solid var(--gray-focus);
border-right: 1px solid var(--gray-focus);
flex-shrink: 0;
}
&:nth-of-type(1) p {
border-left: none;
}
&:last-of-type p {
border-right: none;
}
&:hover {
background-color: transparentize(($gray-focus), 0.5);
}
}
.nav-link.active {
color: black, 0.5;
background-color: transparentize(($gray-focus), 0.5);
border-radius: 0%;
.button-hr {
visibility: visible;
animation: myanimation 0.1s;
}
}
}
.nav-hr {
opacity: 1;
margin: 0px;
border-top: 2px solid var(--gray-focus);
flex-shrink: 0;
margin-bottom: 3rem;
}
@keyframes myanimation {
from {
width: 1%;
left: 50%;
}
to {
width: 85%;
left: 7%;
}
}
@media screen and (max-width:808px) {
.scroll-horizontal {
width: 100%;
display: flex;
z-index: 1;
justify-content: space-between;
}
}
</code></pre>
| [
{
"answer_id": 74209639,
"author": "QueueHammer",
"author_id": 46810,
"author_profile": "https://Stackoverflow.com/users/46810",
"pm_score": 0,
"selected": false,
"text": "rangedRandFactory = (multiple, min, max) => {\n const ceil = Math.floor(max/multiple);\n const floor = Math.ceil(m... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20129419/"
] |
74,209,395 | <p>How do I avoid using <code>position: absolute</code> for the "Hello There" button?
The layout should stay the same. I just want to get rid of that css property.
Is better approach? Pls fork my codesandbox below:</p>
<p>CODESANDBOX -----> <a href="https://codesandbox.io/s/reverent-wright-w4hs8u?file=/demo.js" rel="nofollow noreferrer">CLICK HERE</a></p>
<pre><code><MainContainer>
<Stack spacing={1}>
{products?.map((product) => (
<ProductItem
key={product.id}
name={product.name}
description={product.description}
/>
))}
</Stack>
<Stack
alignItems={"center"}
sx={{
marginTop: 2,
position: "absolute",
display: "flex",
left: 0,
right: 0
}}
>
<Button variant="outlined" sx={{ bgcolor: "white" }}>
Hello There
</Button>
</Stack>
</MainContainer>
</code></pre>
| [
{
"answer_id": 74209639,
"author": "QueueHammer",
"author_id": 46810,
"author_profile": "https://Stackoverflow.com/users/46810",
"pm_score": 0,
"selected": false,
"text": "rangedRandFactory = (multiple, min, max) => {\n const ceil = Math.floor(max/multiple);\n const floor = Math.ceil(m... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8305219/"
] |
74,209,396 | <p>I know this isn't totally SwiftUI related but please bear with me.</p>
<p>Using this excellent video by Karin Prater <a href="https://www.youtube.com/watch?v=ZHK5TwKwcE4" rel="nofollow noreferrer">https://www.youtube.com/watch?v=ZHK5TwKwcE4</a></p>
<p>I have built an app using the spaceX API here : <a href="https://api.spacexdata.com/v4/launches" rel="nofollow noreferrer">https://api.spacexdata.com/v4/launches</a> using the same techniques as Karin.</p>
<p>I want to mock some data for previews. But I am stuck by the complexity of the returned data.</p>
<pre><code>struct Launch: Codable, Identifiable {
let links: Links?
let success: Bool?
let details: String?
let name, dateUTC: String?
let dateUnix: Int?
let dateLocal: String?
let launchLibraryID: String?
let id: String
enum CodingKeys: String, CodingKey {
case links
case success,details
case name
case dateUTC = "date_utc"
case dateUnix = "date_unix"
case dateLocal = "date_local"
case launchLibraryID = "launch_library_id"
case id
}
struct Links: Codable {
let patch: Patch
enum CodingKeys: String, CodingKey {
case patch
}
}
// MARK: - Patch
struct Patch: Codable {
let small, large: String?
}
</code></pre>
<p>Some example data returned with debug/print</p>
<pre><code>SpaceX_API_Demo.Launch(links: Optional(SpaceX_API_Demo.Links(patch: SpaceX_API_Demo.Patch(small: Optional("https://images2.imgbox.com/94/f2/NN6Ph45r_o.png"), large: Optional("https://images2.imgbox.com/5b/02/QcxHUb5V_o.png")))), success: Optional(false), details: Optional("Engine failure at 33 seconds and loss of vehicle"), name: Optional("FalconSat"), dateUTC: Optional("2006-03-24T22:30:00.000Z"), dateUnix: Optional(1143239400), dateLocal: Optional("2006-03-25T10:30:00+12:00"), launchLibraryID: nil, id: "5eb87cd9ffd86e000604b32a"), SpaceX_API_Demo.Launch(links:
</code></pre>
<hr />
<pre><code>func successState() -> Launch {
let launch = Launch(links: <#T##Links?#>, success: true, details: "", name: "", dateUTC: "", dateUnix: 1234567, dateLocal: "", launchLibraryID: "", id: "")
}
</code></pre>
<p>I have no idea how to fill the initializer for Links ...</p>
<p>Thanks for any help!</p>
| [
{
"answer_id": 74210925,
"author": "grandsirr",
"author_id": 14865215,
"author_profile": "https://Stackoverflow.com/users/14865215",
"pm_score": 1,
"selected": false,
"text": "JSON"
},
{
"answer_id": 74218822,
"author": "jat",
"author_id": 14163130,
"author_profile": ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14163130/"
] |
74,209,430 | <p>Good day, SO community!
I am new to C++ and I've ran into a situation in my project, where I have 2 vectors of similar paired data types:</p>
<pre><code>std::vector<std::pair<int, std::string> firstDataVector
std::vector<std::pair<int, std::string> secondDataVector
</code></pre>
<p>and in one part of the code I need to select and process the vector depending on the external string value. So my question is - is it possible to create a pointer to vector outside of the conditions</p>
<pre><code>if (stringValue.find("firstStringCondition"))
{
//use firstDataVector
}
if (stringValue.find("secondStringCondition"))
{
//use secondDataVector
}
</code></pre>
<p>some kind of pDataVector pointer, to which could be assigned the existing vectors (because now project has only two of them, but the vectors count might be increased)</p>
<p>I've tried to create<code>std::vector<std::string> &pDataVector </code> pointer, but it will not work because reference variable must be initialized. So summarizing the question - is it possible to have universal pointer to vector?</p>
| [
{
"answer_id": 74210218,
"author": "Ted Lyngmo",
"author_id": 7582247,
"author_profile": "https://Stackoverflow.com/users/7582247",
"pm_score": 3,
"selected": true,
"text": "vector"
},
{
"answer_id": 74210276,
"author": "Sven Nilsson",
"author_id": 4847311,
"author_pr... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340294/"
] |
74,209,444 | <p>I have a CSV file <code>my_table.csv</code> that looks like the following:</p>
<pre><code>"dt_start","my_int_value","my_double_value","dt_version"
"2022-01-02 00:00:00",2,2.2,"2022-01-02 00:00:00"
"2022-01-03 00:00:00",3,3.3,"2022-01-03 00:00:00"
</code></pre>
<p>Now I simply want to import this file into a table <code>my_table</code> of my PostgreSQL database from Python using the <a href="https://www.psycopg.org/psycopg3/docs/basic/copy.html" rel="nofollow noreferrer">instructions</a> from the <code>psycopg3</code> package (using <code>psycopg==3.1.3</code> and <code>psycopg-binary==3.1.3</code>).</p>
<p>My code looks as follows:</p>
<pre><code>import os
import psycopg
table_name = "my_table"
conn = psycopg.connect(
dbname="MY_DB",
user="MY_USER",
password="MY_PW",
host="MY_HOST",
port="MY_PORT",
)
with conn:
with conn.cursor() as cur:
# create table
cur.execute(
f"""
CREATE TABLE IF NOT EXISTS {table_name} (
dt_start TIMESTAMP NOT NULL,
my_int_value INT NOT NULL,
my_double_value DOUBLE PRECISION NOT NULL,
dt_version TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(dt_start, my_int_value, my_double_value, dt_version)
)
"""
)
# clear table
cur.execute(f"TRUNCATE {table_name}")
conn.commit()
# insert one row
cur.execute(
f"""INSERT INTO {table_name}"""
+ f""" (dt_start, my_int_value, my_double_value, dt_version)"""
+ f""" VALUES (%s, %s, %s, %s)""",
("2022-01-01 00:00:00", 1, 1.1, "2022-01-01 00:00:00"),
)
conn.commit()
# fetch it
cur.execute(f"""SELECT * FROM {table_name}""")
print(cur.fetchall())
# this breaks with "psycopg.errors.InvalidDatetimeFormat"
with open(f"""{table_name}.csv""", "r") as f:
with cur.copy(f"COPY {table_name} FROM STDIN") as copy:
while data := f.read(100):
copy.write(data)
conn.commit()
</code></pre>
<p>The first steps with some sample data work perfectly, but the CSV import breaks with an error such as:</p>
<pre><code>psycopg.errors.InvalidDatetimeFormat: invalid syntax for type timestamp without time zone: »"dt_start","my_int_value","my_double_value","dt_version"«
CONTEXT: COPY my_table, Row 1, Column dt_start: »"dt_start","my_int_value","my_double_value","dt_version"«
</code></pre>
<p>Meanwhile, I have also tried different import variants from the docs and different datetime formats, but all result in the same error.</p>
<p>Any hints on how to fix this problem?</p>
| [
{
"answer_id": 74209663,
"author": "klin",
"author_id": 1995738,
"author_profile": "https://Stackoverflow.com/users/1995738",
"pm_score": 1,
"selected": false,
"text": "COPY my_table FROM STDIN (FORMAT csv, HEADER true)\n"
},
{
"answer_id": 74211966,
"author": "Adrian Klaver"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3734059/"
] |
74,209,447 | <p>I have simple Kotlin code in an existing Java project</p>
<pre class="lang-kotlin prettyprint-override"><code>class A(val p: Int)
fun main() {
println("Hello World")
println(A::javaClass)
println(A::p)
}
</code></pre>
<p>However, this throws an exception</p>
<pre><code>Exception in thread "main" java.lang.NoSuchMethodError: 'void kotlin.jvm.internal.PropertyReference1Impl.<init>(java.lang.Class, java.lang.String, java.lang.String, int)'
at mloop.kt.graphql.TestKt$main$1.<init>(Test.kt)
at mloop.kt.graphql.TestKt$main$1.<clinit>(Test.kt)
at mloop.kt.graphql.TestKt.main(Test.kt:10)
at mloop.kt.graphql.TestKt.main(Test.kt)
</code></pre>
<p>build.gradle.kts is also simple</p>
<pre><code>import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.20"
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.20")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
</code></pre>
<p>Verified that kotlin-reflect is also listed in runtimeClassPath. However, the same code works in a Kotlin-only project.</p>
<pre><code>compileClasspath - Compile classpath for compilation 'main' (target (jvm)).
+--- org.slf4j:slf4j-api -> 2.0.3
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20
+--- org.jetbrains.kotlin:kotlin-reflect:1.7.20
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
\--- org.projectlombok:lombok:1.18.24
runtimeClasspath - Runtime classpath of compilation 'main' (target (jvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20
+--- org.jetbrains.kotlin:kotlin-reflect:1.7.20
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
+--- org.jetbrains.kotlin:kotlin-reflect:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:{strictly 1.7.20} -> 1.7.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-common:{strictly 1.7.20} -> 1.7.20 (c)
</code></pre>
| [
{
"answer_id": 74210087,
"author": "somethingsomething",
"author_id": 9936828,
"author_profile": "https://Stackoverflow.com/users/9936828",
"pm_score": 0,
"selected": false,
"text": "PropertyReference1Impl(java.lang.Class, java.lang.String, java.lang.String, int)\n"
},
{
"answer_... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1064504/"
] |
74,209,449 | <p>How to config <strong>Moshi</strong> so that below <code>field2</code> from JSON<br />
will be converted to String <code>"{"subfield21":"asdf","subfield22":"1234"}"</code><br />
in code <code>MyData.field2</code></p>
<p>JSON:</p>
<pre><code>{
"field1":"someValue1",
"field2":{
"subfield21":"asdf",
"subfield22":"1234",
}
}
</code></pre>
<p>Kotlin class:</p>
<pre><code>data class MyData(
val field1: String, val field2: String
)
</code></pre>
<p>Whan I try std Moshi config I get an exception:</p>
<pre><code>moshi Expected a string but was BEGIN_OBJECT at path
</code></pre>
<p>Note: I'm using standalone Moshi, without retrofit.</p>
| [
{
"answer_id": 74209521,
"author": "talex",
"author_id": 3656904,
"author_profile": "https://Stackoverflow.com/users/3656904",
"pm_score": 0,
"selected": false,
"text": "data class MyData(\n val field1: String, val field2: SubMyData\n)\ndata class SubMyData(\n val subfield21: String, v... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1367449/"
] |
74,209,453 | <p>I'm new to flutter and I encountered this error. It says "The return type 'int' isn't a 'Null', as required by the closure's context.dartreturn_of_invalid_type_from_closure"</p>
<p>I tried troubleshooting however I can't get to fix the error</p>
<p>`</p>
<pre><code>`class _SelectButton extends StatelessWidget {
int _value = 0;
@override
Widget build(BuildContext context) {
return BlocBuilder<SignUpCubit, SignUpState>(
buildWhen: (previous, current) => previous.email != current.email,
builder: (context, state) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: <Widget>[
GestureDetector(
onTap: () => setState(() => _value = 0),
child: Container(
height: 56,
width: 56,
color: _value == 0 ? Colors.grey : Colors.transparent,
child: Icon(Icons.call),
),
),
SizedBox(width: 4),
GestureDetector(
onTap: () => setState(() => _value = 1),
child: Container(
height: 56,
width: 56,
color: _value == 1 ? Colors.grey : Colors.transparent,
child: Icon(Icons.message),
),
),
],
),
);
},
);
}
void setState(Null Function() param0) {}
}
</code></pre>
<p>`</p>
| [
{
"answer_id": 74209521,
"author": "talex",
"author_id": 3656904,
"author_profile": "https://Stackoverflow.com/users/3656904",
"pm_score": 0,
"selected": false,
"text": "data class MyData(\n val field1: String, val field2: SubMyData\n)\ndata class SubMyData(\n val subfield21: String, v... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9869399/"
] |
74,209,466 | <p>I'm new to TS and I'm not sure if i understand it correctly.
From my BackEnd I get data, that's looking like this:</p>
<pre><code>{
"A": [
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 123,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 111,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 99,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 24,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 21,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 11,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 75,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 76,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 13,
"fieldD": 0,
}
],
</code></pre>
<p>And my TypeScript class for this response is looking like this:</p>
<pre><code>export class someDataFromBackend{
public data: {
[key: string]: {
fieldA: string;
fieldB: number;
fieldC: string;
fieldD: number;
};
}[];
constructor(data: any) {
this.data = data;
}
}
</code></pre>
<p>My problem is that I don't really know how can I call to any of this elements right now. I'd like for example create new Array containing values from all fieldC. Or even something that simple like to print fieldC from 2nd array inside "A" (the one that has value 111).</p>
<p>Even when I try to <code>console.log(someDataFB.data)</code> but it shows that it's undefined.</p>
| [
{
"answer_id": 74209589,
"author": "AhmedSHA256",
"author_id": 17343501,
"author_profile": "https://Stackoverflow.com/users/17343501",
"pm_score": 2,
"selected": false,
"text": "export interface someObject {\n fieldA: type,\n fieldB: type,\n fieldC: type,\n fieldD: type\n}\n"
},
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18036911/"
] |
74,209,480 | <p>I'm trying to make a path element in SVG icon inherit fill property from the parent.</p>
<p>When I try set : SVG path { fill: inherit} in CSS it not inherit it but choose his inner fill property. But I don't want delete his inner fill attribute because icon become black and I need set color for every icon. Is there is something wrong I do?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.contact__email-image {
fill: red;
path {
all: inherit;
}
&:hover {
fill: green;
}
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><svg fill="none" viewBox="0 0 16 12" id="mail-black-envelope-symbol" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.953.252L8 6.336 1.047.252C1.332.096 1.653 0 2 0h12c.347 0 .668.096.953.252zm.79 10.71c.158-.286.257-.611.257-.962V2c0-.391-.117-.754-.312-1.062L10.691 5.31l5.052 5.652zM9.94 5.968l-1.61 1.409a.5.5 0 01-.658 0l-1.61-1.41-5.116 5.725c.307.193.666.308 1.055.308h12c.389 0 .748-.115 1.055-.308L9.939 5.968zM0 2c0-.392.117-.754.312-1.062l4.996 4.37-5.051 5.654A1.976 1.976 0 010 10V2z" fill="#87B0EE"/>
</svg></code></pre>
</div>
</div>
</p>
<p>my html:</p>
<p><code><svg class="contact__email-image" viewBox="0 0 16 12" width="16" height="12"> <use xlink:href="img/icons/icons.svg#mail-black-envelope-symbol"></use> </svg></code></p>
| [
{
"answer_id": 74209702,
"author": "Marc",
"author_id": 1024832,
"author_profile": "https://Stackoverflow.com/users/1024832",
"pm_score": 0,
"selected": false,
"text": ".contact__email-image svg {\n fill: red; \n}\n.contact__email-image svg:hover {\n fill: green;\n}\n.contact__email-im... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16555689/"
] |
74,209,484 | <p>I'm trying to make a program that asks for user input and the for loop should check if the input of both user id and pin matches any of the ten pre-made account's user id and pin, like an authorization system</p>
<pre><code>#include <stdio.h>
#include <string.h>
#include <stdbool.h>
struct account{
int uid;
int pin;
int user_bal;
};
int main()
{
int scan_uid, scan_pin;
int att = 3;
bool loop = true;
struct account user[10];
user[0].uid = 1234;
user[0].pin = 123456;
user[1].uid = 4181;
user[1].pin = 308592;
user[2].uid =1111;
user[2].pin =111111;
user[3].uid =2222;
user[3].pin =222222;
user[4].uid =4444;
user[4].pin =444444;
user[5].uid =5555;
user[5].pin =555555;
user[6].uid =6666;
user[6].pin =666666;
user[7].uid =7777;
user[7].pin =777777;
user[8].uid =8888;
user[8].pin =888888;
user[9].uid =9999;
user[9].pin =999999;
for (int i; i <= 9; i++){
user[i].user_bal = 1000;
}
do{
printf("\nEnter your user ID: ");
scanf("%d", &scan_uid);
printf("Enter your pin: ");
scanf("%d", &scan_pin);
printf("\n--------------------------------------------\n");
att--;
for (int i; i <= 9; ++i){
//printf("\n%d", i);
//printf("\n%d", user[i].uid);
//printf("\n%d", user[i].pin);
//printf("\n%d", scan_uid);
//printf("\n%d", scan_pin);
if (user[i].uid == scan_uid && user[i].pin == scan_pin){
loop = false;
}
else{
printf("\nThe username or password is incorrect!");
printf("\nYou have %d attempt(s) left.", att);
if (att > 0)
{
printf("\nPlease try again.\n");
}
else if (att == 0)
{
printf("\nUnauthorized Access.");
printf("\nReport for stolen credit card uploaded.");
}
}
}
}while (att > 0 || loop == false);
return 0;
}
</code></pre>
<p>I tried the relatively same code in python and it works perfectly there. I also checked if the "i" is correct and incremented and if it scanned the user input correctly. all ok. But i've hit a brick wall trying to solve why it just skips the 'if/else' and just scans input again.</p>
<p>I also tried an 'else if ' that does the opposite(!=) of the initial 'if' statement, with no luck.</p>
<p>Thanks.</p>
| [
{
"answer_id": 74210620,
"author": "EJoshuaS - Stand with Ukraine",
"author_id": 4032703,
"author_profile": "https://Stackoverflow.com/users/4032703",
"pm_score": 1,
"selected": false,
"text": "int i"
},
{
"answer_id": 74210636,
"author": "Craig Estey",
"author_id": 53826... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340332/"
] |
74,209,525 | <p>i'm new in making website and I wanted to know how i can go to another page and a specific part of this page simultaneously.</p>
<p>i.e: I'm in page B, and I want to go to page A at the third part with an hyperlink <em>(anchored with #three in html and css)</em> how do i have to write this please ?
I tried</p>
<pre><code><a href="page_a.html#a>PAGE A</a>
</code></pre>
<p>and</p>
<pre><code><a href="page_a.html" href="#a">PAGE A</a>
</code></pre>
<p>But it only take me to the page A and I have to click again on the hyperlink while I'm on the page A to go to the third part.</p>
| [
{
"answer_id": 74210620,
"author": "EJoshuaS - Stand with Ukraine",
"author_id": 4032703,
"author_profile": "https://Stackoverflow.com/users/4032703",
"pm_score": 1,
"selected": false,
"text": "int i"
},
{
"answer_id": 74210636,
"author": "Craig Estey",
"author_id": 53826... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340160/"
] |
74,209,564 | <p>I'm very new to react native and am trying to pass two inputs between two pages by pressing a button but i'm not sure where i'm going wrong. My intention is to have one variable be "Book name" and the second be "number of pages". Any help would be very appreciated.</p>
<p>Page 1</p>
<pre><code>const FirstPage = ({navigation}) => {
const [userName, setUserName] = useState('');
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<Text style={styles.heading}>
React Native Pass Value From One Screen to Another
Using React Navigation
</Text>
<Text style={styles.textStyle}>
Please insert your name to pass it to second screen
</Text>
{/*Input to get the value from the user*/}
<TextInput
value={String}
onChangeText={(bookname) => setUserName(bookname)}
placeholder={'Enter Any value'}
style={styles.inputStyle}
/>
<TextInput
value={String}
onChangeText={(pagenum) => setUserName(pagenum)}
placeholder={'Enter Any value'}
style={styles.inputStyle}
/>
<Button
title="Go Next"
//Button Title
onPress={() =>
navigation.navigate('SecondPage', {
paramKey: pageNum,
paramKey: bookName,
})
}
/>
</code></pre>
<p>Page 2</p>
<pre><code>const SecondPage = ({route}) => {
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<Text style={styles.heading}>
React Native Pass Value From One Screen to Another
Using React Navigation
</Text>
<Text style={styles.textStyle}>
Values passed from First page: {route.params.paramKey}
</Text>
</View>
</SafeAreaView>
);
};
</code></pre>
| [
{
"answer_id": 74210620,
"author": "EJoshuaS - Stand with Ukraine",
"author_id": 4032703,
"author_profile": "https://Stackoverflow.com/users/4032703",
"pm_score": 1,
"selected": false,
"text": "int i"
},
{
"answer_id": 74210636,
"author": "Craig Estey",
"author_id": 53826... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19506039/"
] |
74,209,572 | <pre><code>private void btn_Update_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update MyWeight set Weight='" + txt_Weight.Text + "'where Name='" + txt_Name.Text + "'";
string a = (string)cmd.ExecuteScalar();
con.Close();
if (a != null)
{
cmd.ExecuteNonQuery();
con.Close();
display_data();
MessageBox.Show("Weight updated successfuly!!!");
}
else
{
con.Close();
display_data();
MessageBox.Show("Not updated!!!");
}
}
</code></pre>
<p>I tried to update the weight into the database, but the database keeps saying that it is not updated.</p>
| [
{
"answer_id": 74209804,
"author": "n-azad",
"author_id": 5997281,
"author_profile": "https://Stackoverflow.com/users/5997281",
"pm_score": 0,
"selected": false,
"text": "ExecuteNonQuery"
},
{
"answer_id": 74210008,
"author": "Anderson Constantino",
"author_id": 12081337,... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20210514/"
] |
74,209,577 | <p>Is there a general method to convert a matrix transformation from one coordinate system to another, so that the resulting transformation looks the same on screen?</p>
<p>For example, there are some transformations in a coordinate system with X right, Y up, and Z toward the viewer. And they need to be converted to a coordinate system with X right, Y away from the viewer, and Z up.</p>
<p><a href="https://i.stack.imgur.com/yB5le.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yB5le.png" alt="enter image description here" /></a></p>
<p>What would be the operation that needs to be performed for each matrix so that the transformations look the same in the other coordinate system? And is there a general way to construct this operation given the source and destination basis vectors?</p>
| [
{
"answer_id": 74209835,
"author": "Olivier Jacot-Descombes",
"author_id": 880990,
"author_profile": "https://Stackoverflow.com/users/880990",
"pm_score": 1,
"selected": true,
"text": "┌ ┐\n│ 1 0 0 0 │\n│ 0 cos(θ) -sin(θ) 0 │\n│ 0 sin(θ) cos(θ) 0 │\... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/355485/"
] |
74,209,578 | <pre><code>my_array = np.concatenate((np.arange(10**6), np.array([4])))
my_array
array([ 0, 1, 2, ..., 999998, 999999, 4])
print(sum(4 >= my_array))
</code></pre>
<p>Output: <code>6</code></p>
<p>This print statement will print 6 instead of 10 which from what I understand should be (0+1+2+3+4)</p>
<p>I assume that sum(4>=my_array) does not sum the first the elements up to or equal to 4 and it works in another way?</p>
| [
{
"answer_id": 74209697,
"author": "Niek de Klein",
"author_id": 651779,
"author_profile": "https://Stackoverflow.com/users/651779",
"pm_score": 2,
"selected": true,
"text": "4 >= my_array"
},
{
"answer_id": 74209701,
"author": "mozway",
"author_id": 16343464,
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19489151/"
] |
74,209,603 | <p>I have a middleware to authenticate user via access & refresh token (JWT).</p>
<p>Everything was working fine until I put <strong>typescript</strong> into my project.</p>
<p>Here's my code:</p>
<pre><code>import { UserJWTPayload } from '../interfaces/UserJWTPayload'
import { NextFunction, Request, Response } from 'express'
import { ResponseObject } from '../api/classes/ResponseObject'
import SequelizeApi from '../sequelize/sequelize-api'
import * as jwt from 'jsonwebtoken'
const authenticateUserTokens = async (req: Request, res: Response, next: NextFunction) => {
try {
const accessToken: string = req.cookies.access_token
const refreshToken: string = req.cookies.refresh_token
if (!accessToken || !refreshToken) return res.status(401).json(new ResponseObject(false, 'not authenticated', null))
console.log(jwt)
/*
[Module: null prototype] {
decode: [Function (anonymous)],
default: {
decode: [Function (anonymous)],
verify: [Function (anonymous)],
sign: [Function (anonymous)],
JsonWebTokenError: [Function: JsonWebTokenError],
NotBeforeError: [Function: NotBeforeError],
TokenExpiredError: [Function: TokenExpiredError]
}
}
*/
console.log(jwt.verify())
/*
export function verify(token: string, secretOrPublicKey: Secret, options?: VerifyOptions & { complete?: false }): JwtPayload | string;
An argument for 'token' was not provided
*/
console.log(jwt.verify(accessToken, process.env.JWT_ACCESS_TOKEN_PRIVATE_KEY))
/*
TypeError: jwt.verify is not a function
at file:///C:/Users/Jakub/Desktop/Projekty/StoriesBatchApi/src/middlewares/authenticate-user-tokens.ts:16:25
at Generator.next (<anonymous>)
at file:///C:/Users/Jakub/Desktop/Projekty/StoriesBatchApi/src/middlewares/authenticate-user-tokens.ts:7:71
at new Promise (<anonymous>)
at __awaiter (file:///C:/Users/Jakub/Desktop/Projekty/StoriesBatchApi/src/middlewares/authenticate-user-tokens.ts:3:12)
at file:///C:/Users/Jakub/Desktop/Projekty/StoriesBatchApi/src/middlewares/authenticate-user-tokens.ts:7:96
at Layer.handle [as handle_request] (C:\Users\Jakub\Desktop\Projekty\StoriesBatchApi\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Jakub\Desktop\Projekty\StoriesBatchApi\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\Users\Jakub\Desktop\Projekty\StoriesBatchApi\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\Users\Jakub\Desktop\Projekty\StoriesBatchApi\node_modules\express\lib\router\layer.js:95:5)
*/
const accessTokenData = jwt.verify(accessToken, process.env.JWT_ACCESS_TOKEN_PRIVATE_KEY) as UserJWTPayload
const refreshTokenFromDatabase = await SequelizeApi.getModel('user_token').findOne({ where: { refresh_token: refreshToken } })
if (!refreshTokenFromDatabase) return res.status(401).json(new ResponseObject(false, 'invalid refresh token', null))
jwt.verify(refreshToken, process.env.JWT_REFRESH_TOKEN_PRIVATE_KEY)
res.locals.id_user = accessTokenData.id_user
return next()
} catch (e) {
console.error(e)
return res.status(401).json(new ResponseObject(false, 'server error | not authenticated', e.message))
}
};
export default authenticateUserTokens
</code></pre>
<p>I console logged JWT object as well, but it didn't help to understand what's going on.</p>
<p>I will provide protected route too:</p>
<pre><code>userRouter.delete('/:id', authenticateUserTokens(), async (req, res) => {
try {
const deletedUserId = parseInt(req.params.id)
const actionByUserId = parseInt(res.locals.id_user)
if (actionByUserId !== deletedUserId)
return res.status(403).json(new ResponseObject(false, 'not authorized', null))
const arrayOfAffectedRows = await userModel.update({ status: 'deleted' }, {
where: {
id: deletedUserId
}
})
if (arrayOfAffectedRows[0] === 1)
return res.status(200).json(new ResponseObject(true, 'user deleted', null))
else
return res.status(404).json(new ResponseObject(false, 'user not found', null))
} catch(e) {
return res.status(500).json(new ResponseObject(false, 'server error', e))
}
})
</code></pre>
<p>Here's my tsconfig.ts file:</p>
<pre><code>{
"compilerOptions": {
"module": "ES6",
"removeComments": true,
"target": "es6",
"rootDir": "./",
"esModuleInterop": true,
"moduleResolution":"node",
},
"include": [ "src/**/*" ],
"exclude": [ "node_modules" ]
}
</code></pre>
<p>I use nodemon to run app in development:</p>
<p><code>nodemon -r dotenv/config --experimental-specifier-resolution=node --esm src/server.ts</code></p>
<p>I tried removing brackets in protected route:</p>
<p><code>authenticateUserTokens()</code> ---> <code>authenticateUserTokens</code></p>
<p>But it throwed error.</p>
| [
{
"answer_id": 74209697,
"author": "Niek de Klein",
"author_id": 651779,
"author_profile": "https://Stackoverflow.com/users/651779",
"pm_score": 2,
"selected": true,
"text": "4 >= my_array"
},
{
"answer_id": 74209701,
"author": "mozway",
"author_id": 16343464,
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12447164/"
] |
74,209,649 | <p>Hi I have a foreach loop which lists out all the articles in a service layer, all the articles have a public system namespace DateTime attached to them. I want to edit the foreach loop so i can add a condition to sort the articles descending using the time they where created.</p>
<p>This is what I have at the moment below</p>
<pre><code>@foreach (var Article in _Articles)
{}
</code></pre>
<p>This is what I want but obviously this doesn't work</p>
<pre><code>@foreach (var Article in _Articles.OrderByDescending where _article.CreatedOn )
{}
</code></pre>
| [
{
"answer_id": 74209688,
"author": "JuanR",
"author_id": 4190402,
"author_profile": "https://Stackoverflow.com/users/4190402",
"pm_score": 3,
"selected": true,
"text": "@foreach (var Article in _Articles.OrderByDescending(a => a.CreatedOn))\n{\n //Your code here.\n}\n"
},
{
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17118943/"
] |
74,209,652 | <p>So I think this is probably me mixing up sync/async code (Mainly because Cypress has told me so) but I have a function within a page object within Cypress that is searching for customer data. I need to use this data later on in my test case to confirm the values.</p>
<p>Here is my function:</p>
<pre class="lang-js prettyprint-override"><code>searchCustomer(searchText: string) {
this.customerInput.type(searchText)
this.searchButton.click()
cy.wait('@{AliasedCustomerRequest}').then(intercept => {
const data = intercept.response.body.data
console.log('Response Data: \n')
console.log(data)
if (data.length > 0) {
{Click some drop downdowns }
return data < ----I think here is the problem
} else {
{Do other stuff }
}
})
}
</code></pre>
<p>and in my test case itself:</p>
<pre class="lang-js prettyprint-override"><code>let customerData = searchAndSelectCustomerIfExist('Joe Schmoe')
//Do some stuff with customerData (Probably fill in some form fields and confirm values)
</code></pre>
<p>So You can see what I am trying to do, if we search and find a customer I need to store that data for my test case (so I can then run some cy.validate commands and check if the values exist/etc....)</p>
<p>Cypress basically told me I was wrong via the error message:</p>
<blockquote>
<p>cy.then() failed because you are mixing up async and sync code.</p>
<p>In your callback function you invoked 1 or more cy commands but then
returned a synchronous value.</p>
<p>Cypress commands are asynchronous and it doesn't make sense to queue
cy commands and yet return a synchronous value.</p>
<p>You likely forgot to properly chain the cy commands using another
cy.then().</p>
</blockquote>
<p>So obviously I am mixing up async/sync code. But since the <code>return</code> was within the <code>.then()</code> I was thinking this would work. But I assume in my test case that doesn't work since the commands run synchronously I assume?</p>
| [
{
"answer_id": 74211527,
"author": "Daniel",
"author_id": 197546,
"author_profile": "https://Stackoverflow.com/users/197546",
"pm_score": 0,
"selected": false,
"text": "return"
},
{
"answer_id": 74213356,
"author": "Fody",
"author_id": 16997707,
"author_profile": "htt... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5065860/"
] |
74,209,653 | <p>I followed <a href="https://www.christianfrohn.dk/2022/04/23/connect-to-microsoft-graph-with-powershell-using-a-certificate-and-an-azure-service-principal/" rel="nofollow noreferrer">https://www.christianfrohn.dk/2022/04/23/connect-to-microsoft-graph-with-powershell-using-a-certificate-and-an-azure-service-principal/</a> to connect to Microsoft Graph but I'm getting the following error.</p>
<pre><code>Get-MgUser -Top 1
> Get-MgUser : Insufficient privileges to complete the operation.
> At line:1 char:1
> + Get-MgUser -Top 1
> + ~~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidOperation: ({ ConsistencyLe...ndProperty = }: <>f__AnonymousType62`9) [Get-MgUser
> _List1], RestException`1
> + FullyQualifiedErrorId : > Authorization_RequestDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_List1
</code></pre>
<p>From what I can tell I need to consent to the permissions. I found numerous sources for how to do this for interactive sessions but nothing said how to do this for non-interactive sessions.</p>
<p>I tried adding -Scopes to the connection string but got this error</p>
<pre><code>Connect-MgGraph -ClientID [snip] -TenantId [snip] -CertificateThumbprint [snip] -Scopes 'User.Read.All'
> Connect-MgGraph : Parameter set cannot be resolved using the specified named parameters.
> At line:1 char:1
> + Connect-MgGraph -ClientID 19cb80c5-b355-42bc-a892-e73d11f57ef4 -Tenan ...
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : InvalidArgument: (:) [Connect-MgGraph], ParameterBindingException
> + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph
</code></pre>
<p>How do I do this?</p>
<p><strong>EDIT</strong></p>
<p>This is how I'm connecting</p>
<pre><code>Connect-MgGraph -ClientId $clientId -TenantId $tenantId -CertificateThumbprint $thumbPrint
Welcome To Microsoft Graph!
</code></pre>
<p>API Permissions</p>
<p><a href="https://i.stack.imgur.com/Qdedr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qdedr.png" alt="enter image description here" /></a></p>
<p>Thanks</p>
| [
{
"answer_id": 74211527,
"author": "Daniel",
"author_id": 197546,
"author_profile": "https://Stackoverflow.com/users/197546",
"pm_score": 0,
"selected": false,
"text": "return"
},
{
"answer_id": 74213356,
"author": "Fody",
"author_id": 16997707,
"author_profile": "htt... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2258605/"
] |
74,209,659 | <p>My following program doesn't modify the original value of the variable <code>myMatrix</code>:</p>
<pre><code>def transpos(matrixx: list):
newMatrix = [[matrixx[j][i] for j in range(len(matrixx))] for i in range(len(matrixx[0]))]
myMatrix = newMatrix
myMatrix = [[1, 2], [3, 4]]
transpos(myMatrix)
print(myMatrix)
</code></pre>
<p>What is the correct way to fix this problem?</p>
| [
{
"answer_id": 74211527,
"author": "Daniel",
"author_id": 197546,
"author_profile": "https://Stackoverflow.com/users/197546",
"pm_score": 0,
"selected": false,
"text": "return"
},
{
"answer_id": 74213356,
"author": "Fody",
"author_id": 16997707,
"author_profile": "htt... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16834984/"
] |
74,209,666 | <p>I'm having a problem in a jinja template. If I have an object 'jsonobj' like so:</p>
<pre><code>{
"type": "test",
"people": [{"name": "bill", "age": 43}]
}
</code></pre>
<p>in my template I'm trying to do an if like</p>
<pre><code> {% if 'test' is jsonobj.type %}
<!-- some html here -->
{% else %}
<!-- some other html here -->
{% endif %}
</code></pre>
<p>but I get an error:
<code>jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endfor'. You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'.</code></p>
<p>when I add curlies around <code>jsonobj.type</code> I get</p>
<pre><code>jinja2.exceptions.TemplateSyntaxError: expected token 'name', got '{'
</code></pre>
<p>Was looking at the docs <a href="https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-tests.string" rel="nofollow noreferrer">here</a> and I thought it should work...any ideas?
thanks</p>
<p>I tried any variation I could think of; ==, is, isin and so on. Tried wrapping json obj in one and two sets of curlies. Did lots of googling</p>
| [
{
"answer_id": 74211527,
"author": "Daniel",
"author_id": 197546,
"author_profile": "https://Stackoverflow.com/users/197546",
"pm_score": 0,
"selected": false,
"text": "return"
},
{
"answer_id": 74213356,
"author": "Fody",
"author_id": 16997707,
"author_profile": "htt... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19898204/"
] |
74,209,681 | <p>You are given a large integer represented as an integer array digits, where each <code>digits[i]</code> is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.</p>
<p>Increment the large integer by one and return the resulting array of digits.</p>
<p>My solution:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/**
* @param {number[]} digits
* @return {number[]}
*/
var plusOne = function(digits) {
let num = Number(digits.join('')) + 1
const myFunc = x => Number(x);
digits = Array.from(String(num), myFunc)
return digits
};
console.log(plusOne([1,2,3,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]));</code></pre>
</div>
</div>
</p>
<p>Why does the above code not work given the following argument:</p>
<pre><code>[1,2,3,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]
</code></pre>
<p>my output:</p>
<pre><code>[1,NaN,2,3,5,6,7,7,7,7,7,7,7,7,7,7,7,7,NaN,NaN,2,1]
</code></pre>
<p>expected output:</p>
<pre><code>[1,2,3,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8]
</code></pre>
| [
{
"answer_id": 74210009,
"author": "Praveen Kumar",
"author_id": 1414539,
"author_profile": "https://Stackoverflow.com/users/1414539",
"pm_score": 0,
"selected": false,
"text": "var plusOne = function (digits) {\n\n let carry = 0;\n let arr = [];\n\n for (let i = digits.length -... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340542/"
] |
74,209,719 | <p>In JavaScript, using the <code>switch</code> statement, I can do the following code:</p>
<pre class="lang-js prettyprint-override"><code>switch(true){
case 1 === 1:
console.log(1)
break
case 1 > 1:
console.log(2)
break
default:
console.log(3)
break
}
</code></pre>
<p>And it's going to return <code>1</code>, since JavaScript <code>switch</code> is comparing <code>true === (1 === 1)</code></p>
<p>But the same does not happen when I try it with Python <code>Match</code> statement, like as follows:</p>
<pre class="lang-py prettyprint-override"><code>match True:
case 1 = 1:
print(1)
case 1 > 1:
print(2)
case _:
print(3)
</code></pre>
<p>It returns:</p>
<pre><code>File "<stdin>", line 2
case 1 = 1:
^
SyntaxError: invalid syntax
</code></pre>
<p>And another error is returned if I try it this way:</p>
<pre class="lang-py prettyprint-override"><code>Check1 = 1 == 1
Check2 = 1 > 1
match True:
case Check1:
print(1)
case Check2:
print(2)
case _:
print(3)
</code></pre>
<p>It returns:</p>
<pre><code>case Check1:
^^^^^^
SyntaxError: name capture 'Check1' makes remaining patterns unreachable
</code></pre>
<p>What would be the <strong>cleanest/fastest</strong> way to do many different checks without using a lot of <strong>if's</strong> and <strong>elif's</strong>?</p>
| [
{
"answer_id": 74210147,
"author": "OneMadGypsy",
"author_id": 10292330,
"author_profile": "https://Stackoverflow.com/users/10292330",
"pm_score": 2,
"selected": true,
"text": "1==1"
},
{
"answer_id": 74210426,
"author": "sascha",
"author_id": 19844127,
"author_profil... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12368797/"
] |
74,209,721 | <p>I have an .sh script on my Linux server.</p>
<p>I need the date in milliseconds in Java, but everything I find on the net is giving me Unix Timestamp.</p>
<p>Like this: <code>date=$(date -d 'today 00:00:00' "+%s")</code></p>
<p>I need java milliseconds, like here: <a href="https://www.fileformat.info/tip/java/date2millis.htm" rel="nofollow noreferrer">https://www.fileformat.info/tip/java/date2millis.htm</a>.</p>
<p>How do I get that easily without writing a long java code?
There has to be an easy solution.</p>
| [
{
"answer_id": 74210147,
"author": "OneMadGypsy",
"author_id": 10292330,
"author_profile": "https://Stackoverflow.com/users/10292330",
"pm_score": 2,
"selected": true,
"text": "1==1"
},
{
"answer_id": 74210426,
"author": "sascha",
"author_id": 19844127,
"author_profil... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2014088/"
] |
74,209,727 | <pre><code>this.form = this.formBuilder.group({
value: ['', [Validators.required, Validators.minLength(4)]]
});
</code></pre>
<p>I want to get the <strong>4</strong> from <strong>Validators.minLength(4)</strong>.</p>
<p>How can I get this?</p>
| [
{
"answer_id": 74210937,
"author": "Eliseo",
"author_id": 8558186,
"author_profile": "https://Stackoverflow.com/users/8558186",
"pm_score": -1,
"selected": false,
"text": "const error=this.form.get('value').validator(\n new FormControl('1')\n)\nif (error && error.minlength)\n consol... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11062476/"
] |
74,209,731 | <p>Im want make a scrape of this node. In one page run well but I need the other 342 pages. About pages only change the final number, like 1, 2 , 3 to 342.</p>
<pre><code>library(rvest)
library(xml2)
library(httr)
# For page 1
website<-'https://cgspace.cgiar.org/discover?
rpp=10&etal=0&query=cassava&scope=10568/35697&group_by=none&page=1'
link <- vector()
#loop through nodes
for (i in 1:10){
link[i] <-website %>%
read_html() %>%
html_nodes(xpath=paste0('//*[@id="aspect_discovery_SimpleSearch_div_search-
results"]/div[',i,']/div[2]/div/div[1]/a')) %>%
html_attr('href')
}
pag <- data.frame(link)
pag$link2 <- paste0('https://cgspace.cgiar.org', pag$link)
pag
# link link2
# 1 /handle/10568/71370 https://cgspace.cgiar.org/handle/10568/71370
# 2 /handle/10568/43831 https://cgspace.cgiar.org/handle/10568/43831
# 3 /handle/10568/56285 https://cgspace.cgiar.org/handle/10568/56285
# For page 2
website<-'https://cgspace.cgiar.org/discover?
rpp=10&etal=0&query=cassava&scope=10568/35697&group_by=none&page=2'
link <- vector()
#loop through nodes
for (i in 1:10){
link[i] <-website %>%
read_html() %>%
html_nodes(xpath=paste0('//*[@id="aspect_discovery_SimpleSearch_div_search-
results"]/div[',i,']/div[2]/div/div[1]/a')) %>%
html_attr('href')
}
pag2 <- data.frame(link)
pag2$link2 <- paste0('https://cgspace.cgiar.org', pag2$link)
pag2
# link link2
# 1 /handle/10568/90626 https://cgspace.cgiar.org/handle/10568/90626
# 2 /handle/10568/71796 https://cgspace.cgiar.org/handle/10568/71796
# 3 /handle/10568/68788 https://cgspace.cgiar.org/handle/10568/68788
</code></pre>
<p>The idea is make this in a single loop and have a data frame.</p>
<p>Update question:
Im add in the second for loop this: but show error</p>
<pre><code> all_pags <- data.frame()
startTime <- Sys.time()
for( i in 1:1){
website<-paste0('https://cgspace.cgiar.org/discover?
rpp=10&etal=0&query=cassava&scope=10568/35697&group_by=none&page=',i)
link <- vector()
Title <- vector()
#loop through nodes
for (i in 1:10){
link[i] <-website %>%
read_html() %>%
html_nodes(xpath=paste0('//*
[@id="aspect_discovery_SimpleSearch_div_search-
results"]/div[',i,']/div[2]/div/div[1]/a')) %>%
html_attr('href')
Title[i]<-website %>%
read_html() %>%
html_nodes(xpath=paste0('//*
[@id="resultsTable"]/tbody/tr[',i,']/td/div/div[1]/a/span')) %>%
html_text(trim = T)
}
pag <- data.frame(link,Title)
pag$link2 <- paste0('https://cgspace.cgiar.org', pag$link)
all_pags <- rbind(all_pags, pag, Title)
}
endTime <- Sys.time()
print(endTime - startTime)
all_pags
# Error in Title[i] <- website %>% read_html() %>% html_nodes(xpath = #paste0("//*[@id=\"resultsTable\"]/tbody/tr[", :
# replacement has length zero
</code></pre>
<p>Im try to obtaind the names of each document and the link in the same loop</p>
| [
{
"answer_id": 74210937,
"author": "Eliseo",
"author_id": 8558186,
"author_profile": "https://Stackoverflow.com/users/8558186",
"pm_score": -1,
"selected": false,
"text": "const error=this.form.get('value').validator(\n new FormControl('1')\n)\nif (error && error.minlength)\n consol... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15449339/"
] |
74,209,750 | <p>I was tasked with building a relatively simple module for a new client test experience, but I feel like I can optimize the code. Important: I do not have access to the client's site, I am just supposed to build this module using HTML and CSS manipulation.</p>
<p>Currently, the relevant page contains a card image with some text underneath. I must introduce a new image of a badge which is meant to sit right to the left of the card. Here's what it is meant to look like:</p>
<p><a href="https://i.stack.imgur.com/ZMIdB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZMIdB.png" alt="enter image description here" /></a></p>
<p>This is the code block I currently have set up for that particular configuration:</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>.Card_Badge {
box-sizing: border-box;
max-height: 350px;
overflow: hidden;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="Card_Badge">
<img alt="Badge Background" src="https://via.placeholder.com/100" style="max-width: 100px;max-height: 146px;display: flex;z-index: 1;">
<img alt="Secured Card" src="https://via.placeholder.com/100" style="transform: translate(65px,-150px);">
</div></code></pre>
</div>
</div>
</p>
<p>Without the <code>transform: translate()</code> the images simple stack onto one another. There has to be a better way to accomplish the desired effect of the images being right next to one another without manipulating the positioning so excessively, right? Maybe with some kind of <code>position:</code> or <code>display:</code> component, but I admit that I am still not incredibly well-versed with how those work.</p>
<p>Any help would be greatly appreciated.</p>
<p>UPDATE: Here is the adjusted code that I have. The only issue I'm still having is that the shadow underneath the card element gets clipped to the right of one of the <code><div></code> containers. Not sure how to get around that.</p>
<p>`
</p>
`
| [
{
"answer_id": 74209856,
"author": "Glen tea.",
"author_id": 10243873,
"author_profile": "https://Stackoverflow.com/users/10243873",
"pm_score": -1,
"selected": false,
"text": " .Card_Badge {\n box-sizing: border-box;\n max-height: 350px;\n overflow: hidden;\n display: flex;... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209750",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340500/"
] |
74,209,759 | <p>I have a problem with my price regex which I'm trying to change. I want it to allow numbers like:</p>
<ul>
<li>11111,64</li>
<li>2 122,00</li>
<li>123,12</li>
<li>123 345,23</li>
</ul>
<p>For now I have something like this, but it won't accept numbers without spaces.</p>
<p><code> '^\d{1,3}( \d{3}){0,10}[,]*[.]*([0-9]{0,2'})?$'</code></p>
<p>I tried changing <code>( \d{3})</code> to <code>(\s{0,1}\d{3})</code> but it still doesn't work :(</p>
| [
{
"answer_id": 74209856,
"author": "Glen tea.",
"author_id": 10243873,
"author_profile": "https://Stackoverflow.com/users/10243873",
"pm_score": -1,
"selected": false,
"text": " .Card_Badge {\n box-sizing: border-box;\n max-height: 350px;\n overflow: hidden;\n display: flex;... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340538/"
] |
74,209,826 | <p>I'm trying to get folder and file permissions which is located in Shared Drive. All I can get is permissions list for root Shared Drive but trying to run below code on any ID of file or folder inside throw error.</p>
<p><strong>Relavant Facts</strong></p>
<ol>
<li>We are using Google Workspace Business Plus subscription</li>
<li>I am domain superadmin</li>
<li>I have access to this file in Shared Drive but I expect to have access to every file as an domain admin.</li>
<li>Right now I'm calling the below script from web IDE of Apps Script so it is working in my grant scope.</li>
<li>I am the script owner</li>
<li>Script is on My rive</li>
</ol>
<p><strong>Script</strong></p>
<pre><code>
function getPermissions_(driveFileID, sharedDriveSupport){
var thisDrivePermissions = Drive.Permissions.list(
driveFileID,
{
useDomainAdminAccess: USE_DOMAIN_ADMIN_ACCESS,
supportsAllDrives: sharedDriveSupport
}
);
return thisDrivePermissions;
}
</code></pre>
<p><strong>Errors</strong></p>
<pre class="lang-none prettyprint-override"><code>GoogleJsonResponseException: API call to drive.permissions.list failed with error: Shared drive not found: xxxxxxxx
</code></pre>
<pre class="lang-none prettyprint-override"><code>GoogleJsonResponseException: API call to drive.permissions.list failed with error: File not found:
</code></pre>
<p>How can I get the file permissions list in Google Shared Drive with Apps Script?</p>
| [
{
"answer_id": 74209856,
"author": "Glen tea.",
"author_id": 10243873,
"author_profile": "https://Stackoverflow.com/users/10243873",
"pm_score": -1,
"selected": false,
"text": " .Card_Badge {\n box-sizing: border-box;\n max-height: 350px;\n overflow: hidden;\n display: flex;... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2578137/"
] |
74,209,846 | <p>I'm very new to Unit Testing and trying to implement NUnit in a C# Dotnet Core 3.1 project.
I think the test is working, but I'd really like to debug (and single-step through) the test to make sure everything is working.</p>
<p>However, when I right-click on a test and select "debug", two things happen (or not):</p>
<ol>
<li>I get an error saying that "There were build errors. Would you like to continue and run tests from the last successful build?" (and when I look in the output window, there are no errors but two warnings saying that "ProjectData: Could not find project with GUID adf53ed2...".</li>
<li>Debugging doesn't happen (no breakpoints are hit) but the test "runs" and passes.</li>
</ol>
<p>I found a thread on Stackoverflow that said you had to set up an external program in the debug settings, but VS2022 does not have those screens or settings.</p>
<p>UPDATE: I created a stupid-simple dotnet core console project (and added NUnit in the same way) and debugging works just fine. So, it's something about the project I'm trying to add test to: it is a dotnet core 3.1 web project.</p>
<p>2nd UPDATE: so I created a stupid-simple dotnet core web project (and added NUnit) and debugging works just fine. So, it's something about my project (and probably related to that error message saying it can't find project guid: xxxxxxx (don't have it any longer).</p>
<p>3rd UPDATE: so I DELETED the NUnit test project (again) and re-created it and left it dirt-simple (just whatever VS2022 creates on open) and it debugs! Now to start adding code and find out what breaks it!</p>
<p>Thoughts?</p>
<p>TIA,</p>
| [
{
"answer_id": 74210032,
"author": "n-azad",
"author_id": 5997281,
"author_profile": "https://Stackoverflow.com/users/5997281",
"pm_score": 1,
"selected": false,
"text": "launchSettings.json"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5679516/"
] |
74,209,885 | <p>I want use a icon library in my react-native app but I am not able to find any library apart from <a href="https://www.npmjs.com/package/@ant-design/icons-react-native" rel="nofollow noreferrer">https://www.npmjs.com/package/@ant-design/icons-react-native</a></p>
| [
{
"answer_id": 74210032,
"author": "n-azad",
"author_id": 5997281,
"author_profile": "https://Stackoverflow.com/users/5997281",
"pm_score": 1,
"selected": false,
"text": "launchSettings.json"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15267060/"
] |
74,209,910 | <pre><code>const list = document.getElementById('generateList');
const listAdd = document.createElement('li');
listAdd.innerText = "Name"
list.appendChild(listAdd)
</code></pre>
<p>This code returns: Cannot read properties of null (reading 'appendChild')
Why and how do I fix it?</p>
<p>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-html lang-html prettyprint-override"><code><ul id="generateList">
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74209954,
"author": "Volodymyr Sichka",
"author_id": 5333324,
"author_profile": "https://Stackoverflow.com/users/5333324",
"pm_score": 0,
"selected": false,
"text": "list"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17008758/"
] |
74,209,914 | <p>I am trying to creating python dictionary keys dynamically in order to serve the data into csv file but not getting anywhere so far. Here is my code:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import csv
class ZiwiScraper:
results = []
headers = {
'authority': '99petshops.com.au',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-language': 'en,ru;q=0.9',
'cache-control': 'max-age=0',
# Requests sorts cookies= alphabetically
# 'cookie': 'TrackerGuid=f5419f8d-632a-46b1-aa04-eed027d03e89; _ga=GA1.3.1385392550.1666770065; _gid=GA1.3.1560927430.1666770065',
'referer': 'https://www.upwork.com/',
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Yandex";v="22"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Linux"',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'cross-site',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.114 YaBrowser/22.9.1.1110 (beta) Yowser/2.5 Safari/537.36',
}
def fetch(self, url):
print(f'HTTP GET request to URL: {url}', end='')
res = requests.get(url, headers=self.headers)
print(f' | Status Code: {res.status_code}')
return res
def parse(self, html):
soup = BeautifulSoup(html, 'lxml')
titles = [title.text.strip() for title in soup.find_all('h2')]
low_prices = [low_price.text.split(' ')[-1] for low_price in soup.find_all('span', {'class': 'hilighted'})]
store_names = []
stores = soup.find_all('p')
for store in stores:
store_name = store.find('img')
if store_name:
store_names.append(store_name['alt'])
shipping_prices = [shipping.text.strip() for shipping in soup.find_all('p', {'class': 'shipping'})]
price_per_hundered_kg = [unit_per_kg.text.strip() for unit_per_kg in soup.find_all('p', {'class': 'unit-price'})]
other_details = soup.find_all('div', {'class': 'pd-details'})
for index in range(0, len(titles)):
try:
price_per_100_kg = price_per_hundered_kg[index]
except:
price_per_100_kg = ''
try:
lowest_prices = low_prices[index]
except:
lowest_prices = ''
for detail in other_details:
detail_1 = [pr.text.strip() for pr in detail.find_all('span', {'class': 'sp-price'})]
for idx, price in enumerate(detail_1):
self.results.append({
'title': titles[index],
'lowest_prices': lowest_prices,
f'lowest_price_{idx}': detail_1[idx],
'store_names': store_names[index],
'shipping_prices': shipping_prices[index],
'price_per_100_kg': price_per_100_kg,
})
# json_object = json.dumps(self.results, indent=4)
# with open("ziwi_pets_2.json", "w") as outfile:
# outfile.write(json_object)
def to_csv(self):
with open('ziwi_pets_2.csv', 'w') as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=self.results[0].keys())
writer.writeheader()
for row in self.results:
writer.writerow(row)
print('Stored results to "ziwi_pets_2.csv"')
def run(self):
for page in range(1):
url = f'https://99petshops.com.au/Search?brandName=Ziwi%20Peak&animalCode=DOG&storeId=89%2F&page={page}'
response = self.fetch(url)
self.parse(response.text)
self.to_csv()
if __name__ == '__main__':
scraper = ZiwiScraper()
scraper.run()
</code></pre>
<p>Every time I run the script it gives me the above code I got <code>ValueError: dict contains fields not in fieldnames: 'lowest_price_1'</code>. csv file however generating with one entry only.</p>
<pre><code>title,lowest_prices,lowest_price_0,store_names,shipping_prices,price_per_100_kg
Ziwi Peak Dog Air-Dried Free Range Chicken Recipe 1Kg,$57.75,$64.60,Woofers World,+$9.95 shipping,$5.78 per 100g
</code></pre>
<p>I tried to output it as json just to see the data formation and it was also not as I expected.</p>
<pre><code>[
{
"title": "Ziwi Peak Dog Air-Dried Free Range Chicken Recipe 1Kg",
"lowest_prices": "$57.75",
"lowest_price_0": "$64.60",
"store_names": "Woofers World",
"shipping_prices": "+$9.95 shipping",
"price_per_100_kg": "$5.78 per 100g"
},
{
"title": "Ziwi Peak Dog Air-Dried Free Range Chicken Recipe 1Kg",
"lowest_prices": "$57.75",
"lowest_price_1": "$64.60",
"store_names": "Woofers World",
"shipping_prices": "+$9.95 shipping",
"price_per_100_kg": "$5.78 per 100g"
},
{
"title": "Ziwi Peak Dog Air-Dried Free Range Chicken Recipe 1Kg",
"lowest_prices": "$57.75",
"lowest_price_2": "$64.95",
"store_names": "Woofers World",
"shipping_prices": "+$9.95 shipping",
"price_per_100_kg": "$5.78 per 100g"
},
]
</code></pre>
<p>I expected something like this:</p>
<pre><code>[
{
"title": "Ziwi Peak Dog Air-Dried Free Range Chicken Recipe 1Kg",
"lowest_prices": "$57.75",
"lowest_price_0": "$64.60",
"lowest_price_1": "$64.60",
"lowest_price_2": "$64.95",
"store_names": "Woofers World",
"shipping_prices": "+$9.95 shipping",
"price_per_100_kg": "$5.78 per 100g"
},
]
</code></pre>
<p>Can anyone please help me out here? Thanks.</p>
| [
{
"answer_id": 74209954,
"author": "Volodymyr Sichka",
"author_id": 5333324,
"author_profile": "https://Stackoverflow.com/users/5333324",
"pm_score": 0,
"selected": false,
"text": "list"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18183763/"
] |
74,209,936 | <p>I have a vector or a matrix where I want to select rows.
The vector could look like this</p>
<pre><code>T{1} = 'A'
T{2} = 'B'
T{3} = 'A'
</code></pre>
<p>and I want to reduce it from ABA to AA using</p>
<pre><code>T([ 1 0 1])
</code></pre>
<p>but that does not compile, if I do</p>
<pre><code>T([ 1 2 3])
</code></pre>
<p>I get the original. However I select the rows using a strfind function like this</p>
<pre><code>indexlistM = cell2mat(strfind(T, 'A')) = [1 0 1];
</code></pre>
<p>How can I select rows using a true/false selector or using a different method?</p>
| [
{
"answer_id": 74210088,
"author": "Wolfie",
"author_id": 3978545,
"author_profile": "https://Stackoverflow.com/users/3978545",
"pm_score": 1,
"selected": false,
"text": "T([1 0 1])\n"
},
{
"answer_id": 74217312,
"author": "Matthias Pospiech",
"author_id": 843458,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/843458/"
] |
74,209,979 | <p>I'm just wondering, is following approach a good way to fetch data? If not, what would be the problems I will face?</p>
<pre><code>const Component = () => {
const [data, setData] = useState(undefined)
if (!data) {
fetchDataAPI('api/mock-data', (data) => setData(data))
}
}
</code></pre>
<p>The data fetching starts by the first render and once it is accomplished, following rerenders wouldn't trigger it anymore.</p>
| [
{
"answer_id": 74210088,
"author": "Wolfie",
"author_id": 3978545,
"author_profile": "https://Stackoverflow.com/users/3978545",
"pm_score": 1,
"selected": false,
"text": "T([1 0 1])\n"
},
{
"answer_id": 74217312,
"author": "Matthias Pospiech",
"author_id": 843458,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14407238/"
] |
74,209,994 | <p>I am trying to use python to compute an approximation of (pi) using unlimited series.</p>
<p>stopping condition is for <code>accuracy = 10**(-9)</code></p>
<p>accuracy is <code>abs(exact_pi-computed_pi) </code></p>
<p>my code:</p>
<pre class="lang-py prettyprint-override"><code>from math import sqrt
exact_pi=3.14159265358979323846
accuracy=10**(-9)
computed_pi=float(sqrt(12))
k=1
while abs(float(computed_pi)-float(exact_pi))>accuracy:
num1=float((-3)**(-k))
num2=float((2*k+1))
computed_pi=float(computed_pi)+ float(num1/num2)
k=k+1
</code></pre>
<p>The result of <code> float(num1/num2)</code> after some iterations for <code>k=100</code> for example it <code>outputs 0</code> so it gets into an infinite loop. can someone help?</p>
<p><a href="https://i.stack.imgur.com/HA4pJ.png" rel="nofollow noreferrer">PI FORMULA</a></p>
| [
{
"answer_id": 74210088,
"author": "Wolfie",
"author_id": 3978545,
"author_profile": "https://Stackoverflow.com/users/3978545",
"pm_score": 1,
"selected": false,
"text": "T([1 0 1])\n"
},
{
"answer_id": 74217312,
"author": "Matthias Pospiech",
"author_id": 843458,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74209994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19743392/"
] |
74,210,021 | <p>In my project I need to fetch data from multiple graphql endpoints.
I defined one in my application.properties file like so:
<code>graphql.client.url=https://api.foo.com/graphql-1</code>
and fetching data in code:</p>
<pre><code>public Foo getFooByid(String id) throws Exception {
final GraphQLRequest request =
GraphQLRequest.builder()
.query(orgByIdQuery)
.variables(Map.of("id", id))
.build();
final GraphQLResponse response = graphQLWebClient.post(request).block();
response.validateNoErrors();
return response.get("Foo", Foo.class);
}
</code></pre>
<p>So there is some magic that gets client url from application.properties file. Now, how can I have second client url <code>https://api.foo.com/graphql-2</code> defined and used in my code?
Dependency for gql:</p>
<pre><code> <dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-webclient-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
</code></pre>
| [
{
"answer_id": 74210401,
"author": "Vaclav Stengl",
"author_id": 7537048,
"author_profile": "https://Stackoverflow.com/users/7537048",
"pm_score": -1,
"selected": false,
"text": "WebClientAutoConfiguration"
},
{
"answer_id": 74220717,
"author": "Julio César Estravis",
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4635750/"
] |
74,210,029 | <p>I want to know if a function passed by the constructor is null or not, but when I check it, it doesn't recognize the function as null, even though I didn't pass anything as a parameter.</p>
<p>This is my widget:</p>
<pre class="lang-dart prettyprint-override"><code>const CropImageWidget({
this.navBack,
super.key,
});
final Function? navBack;
</code></pre>
<p>Here is where I check if <code>navBack</code> is <code>null</code> or not:</p>
<pre class="lang-dart prettyprint-override"><code>if (widget.navBack == null) {
Navigator.pop(context);
}
widget.navBack!();
</code></pre>
<p>The problem is that <code>widget.navBack</code> is never <code>null</code>.</p>
<p>I need to check if a function is or isn't passed in the constructor to execute function or to just pop the screen.</p>
<p>Solution:
I thought the Navigator.pop(context) would return and not execute the code after it, however it executes the pop and then executes the function, which gives me the error. So, to make the code work I just did an If/else like this:</p>
<pre class="lang-dart prettyprint-override"><code>if (widget.navBack == null) {
Navigator.pop(context);
} else {
widget.navBack!();
}
</code></pre>
| [
{
"answer_id": 74210164,
"author": "john",
"author_id": 16146701,
"author_profile": "https://Stackoverflow.com/users/16146701",
"pm_score": 0,
"selected": false,
"text": " final VoidCallback? navBack;\n\n onPressed: (){\n if(navBack == null){\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340706/"
] |
74,210,030 | <p>I'm trying to detect users first sessions.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">ID</th>
<th style="text-align: center;">event_server_date</th>
<th style="text-align: center;">Event</th>
<th style="text-align: center;">Row_number</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:43</td>
<td style="text-align: center;">abc</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:45</td>
<td style="text-align: center;">cde</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:47</td>
<td style="text-align: center;">ykz</td>
<td style="text-align: center;">3</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:48</td>
<td style="text-align: center;">fun</td>
<td style="text-align: center;">4</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:50</td>
<td style="text-align: center;">start_event</td>
<td style="text-align: center;">5</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:55</td>
<td style="text-align: center;">x</td>
<td style="text-align: center;">6</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:56</td>
<td style="text-align: center;">y</td>
<td style="text-align: center;">7</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:56</td>
<td style="text-align: center;">z</td>
<td style="text-align: center;">8</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:12</td>
<td style="text-align: center;">plz</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:15</td>
<td style="text-align: center;">rck</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:15</td>
<td style="text-align: center;">dsp</td>
<td style="text-align: center;">3</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:17</td>
<td style="text-align: center;">vnl</td>
<td style="text-align: center;">4</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:23</td>
<td style="text-align: center;">start_event</td>
<td style="text-align: center;">5</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:23</td>
<td style="text-align: center;">k</td>
<td style="text-align: center;">6</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:26</td>
<td style="text-align: center;">l</td>
<td style="text-align: center;">7</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Desired Output:</strong></p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">ID</th>
<th style="text-align: center;">Timestamp</th>
<th style="text-align: center;">Event</th>
<th style="text-align: center;">Row_number</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:50</td>
<td style="text-align: center;">start_event</td>
<td style="text-align: center;">5</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:55</td>
<td style="text-align: center;">x</td>
<td style="text-align: center;">6</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:56</td>
<td style="text-align: center;">y</td>
<td style="text-align: center;">7</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">2022-10-26 09:56</td>
<td style="text-align: center;">z</td>
<td style="text-align: center;">8</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:23</td>
<td style="text-align: center;">start_event</td>
<td style="text-align: center;">5</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:23</td>
<td style="text-align: center;">k</td>
<td style="text-align: center;">6</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">2022-10-26 09:26</td>
<td style="text-align: center;">l</td>
<td style="text-align: center;">7</td>
</tr>
</tbody>
</table>
</div>
<p>Real timestamp column looks like this: 1970-01-20 06:57:25.583738 UTC
I'm using event based data and my table is quite large.</p>
<p>Is there any way for me pick those desired rows only? And discard all events before start_event in every partition.</p>
<p>I've got this far but I have no idea how to discard unwanted events for every partition.</p>
<pre><code>SELECT ID, event_server_date , Event,
row_number() over(partition by ID ORDER BY event_server_date ASC) AS Row_number
FROM `my_table`
ORDER BY event_server_date ASC
</code></pre>
<p>Note: I have been using SQL for only two months so I might not know the concepts you're talking about.</p>
| [
{
"answer_id": 74210164,
"author": "john",
"author_id": 16146701,
"author_profile": "https://Stackoverflow.com/users/16146701",
"pm_score": 0,
"selected": false,
"text": " final VoidCallback? navBack;\n\n onPressed: (){\n if(navBack == null){\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18296671/"
] |
74,210,041 | <p>I am trying to read the keychain but the documentation warns me about the following:</p>
<blockquote>
<p>SecItemCopyMatching blocks the calling thread, so it can cause your app’s UI to hang if called from the main thread. Instead, call SecItemCopyMatching from a background dispatch queue or async function.</p>
</blockquote>
<p><a href="https://developer.apple.com/documentation/security/1398306-secitemcopymatching" rel="nofollow noreferrer">Source</a></p>
<p>So I want to write an asynchronous method that runs in the background.</p>
<pre><code>actor Keychain {
public static let standard = Keychain()
public enum Error: Swift.Error {
case failed(String)
}
public func get(_ key: String) async throws -> Data? {
let backgroundTask = Task(priority: .background) {
var query: [String: Any] = [
type(of: self).klass : kSecClassGenericPassword,
type(of: self).attrAccount : key,
type(of: self).matchLimit : kSecMatchLimitOne,
type(of: self).returnData : kCFBooleanTrue as CFBoolean
]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
guard status == errSecSuccess else {
if let errorMessage = SecCopyErrorMessageString(status, nil) {
throw Error.failed(String(errorMessage))
} else {
throw Error.failed("unsupported")
}
}
return item as? Data
}
return try await backgroundTask.value
}
}
</code></pre>
<p>My question is.. will the actor already make it thread safe?</p>
<p>Normally I would add a <code>NSLock</code> to be safe.</p>
<pre><code>public func get(_ key: String) async throws -> Data? {
lock.lock()
defer { lock.unlock() }
(...)
return try await task.value
}
</code></pre>
<p>However now I get a warning <code>Instance method 'lock' is unavailable from asynchronous contexts; Use async-safe scoped locking instead; this is an error in Swift 6</code>.</p>
<p>So how I am able to achieve this?</p>
| [
{
"answer_id": 74210398,
"author": "Rob",
"author_id": 1271826,
"author_profile": "https://Stackoverflow.com/users/1271826",
"pm_score": 3,
"selected": true,
"text": "get(_:)"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/174655/"
] |
74,210,058 | <p>I'd like to execute multiple async tasks sequentially.</p>
<pre><code>foreach (var msg in messages)
{
await smtp.SendAsync(msg);
}
</code></pre>
<p><strong>However, if one of the tasks fails, I'd like the rest of them to continue.</strong> And throw one exception at the end.</p>
<p>Think of it like <code>.WhenAll()</code> that executes all the tasks and throws an <code>AggregateException</code> at the end, if any of the tasks fails. However, I cannot find any <em>sequential</em> alternative.</p>
<p>I studied the docs and googled and stackoverflowed for a solution, and I found no built-in way to do this. I think the only way is to handle exceptions manually.</p>
<p>Something like this</p>
<pre><code>var exceptions = new List<Exception>();
foreach (var msg in messages)
{
try
{
await smtp.SendAsync(msg).ConfigureAwait(false);
}
catch (Exception ex)
{
exceptions.Add(ex);
}
}
if (exceptions.Count > 0)
{
throw new AggregateException(exceptions);
}
</code></pre>
<p>Questions:</p>
<ol>
<li>Is there a .NET built-in solution I'm missing?</li>
<li>If not, is this the right way? Maybe chaining multiple <code>.ContinueWith</code> calls and returning the resulting "chain-task" instead is considered a better practice? (thus eliding await/async and prevent unnecessary state-machine building)</li>
<li>Am I allowed to use the .NET built-in <code>AggregateException</code> here or this is bad practice?</li>
</ol>
| [
{
"answer_id": 74210485,
"author": "Stephen Cleary",
"author_id": 263693,
"author_profile": "https://Stackoverflow.com/users/263693",
"pm_score": 3,
"selected": true,
"text": "AggregateException"
},
{
"answer_id": 74211459,
"author": "Theodor Zoulias",
"author_id": 111785... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56621/"
] |
74,210,099 | <p>I am using 3rd party screen recording library which has foreground service and when screen recording is started new post-notification permission dialog is shown by the system automatically on Android 13. Is there any way to register a listener to get data on whether that permission is granted or not?</p>
<p>I've tried to request post notification permission manually before the screen record starts, but the permission dialog is not shown after the request.</p>
<pre><code>requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
</code></pre>
<p>Its all happening only on Android 13.</p>
| [
{
"answer_id": 74210485,
"author": "Stephen Cleary",
"author_id": 263693,
"author_profile": "https://Stackoverflow.com/users/263693",
"pm_score": 3,
"selected": true,
"text": "AggregateException"
},
{
"answer_id": 74211459,
"author": "Theodor Zoulias",
"author_id": 111785... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4975647/"
] |
74,210,102 | <p>My general workflow for going to another project is</p>
<ol>
<li><code>projectile-switch-project</code> which pops up a helm interface for picking a project</li>
<li>select a project</li>
<li>select a file within the project to open the file</li>
<li>then run <code>magit-status</code></li>
</ol>
<p>Is there a way to combine steps 2-4?</p>
| [
{
"answer_id": 74229940,
"author": "Tianshu Wang",
"author_id": 18118915,
"author_profile": "https://Stackoverflow.com/users/18118915",
"pm_score": 0,
"selected": false,
"text": "project"
},
{
"answer_id": 74232356,
"author": "ramsay",
"author_id": 5738112,
"author_pr... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2807904/"
] |
74,210,201 | <p>I have two queries that count the total of employees according to multiple conditions; the only thing that changes is the last two AND clauses; I don't know how I can return the results in the same query.
First Query</p>
<pre><code>SELECT
COUNT(*)
FROM
(
SELECT
E.NAME,
E.LAST_NAME,
E.BIRTH_DATE,
E.ID
FROM
EMPLOYEES E
WHERE E.BIRTH_DATE BETWEEN '2022-10-18 00:00:00' AND '2022-10-18 23:59:59'
AND E.NAME IS NOT NULL
AND E.LAST_NAME IS NOT NULL
GROUP BY E.NAME, E.LAST_NAME, E.BIRTH_DATE,E.ID
) AUX;
</code></pre>
<p>Second Query</p>
<pre><code>SELECT
COUNT(*)
FROM
(
SELECT
E.NAME,
E.LAST_NAME,
E.BIRTH_DATE,
E.ID
FROM
EMPLOYEES E
WHERE E.BIRTH_DATE BETWEEN '2022-10-18 00:00:00' AND '2022-10-18 23:59:59'
AND E.NAME IS NULL
AND E.LAST_NAME IS NULL
GROUP BY E.NAME, E.LAST_NAME, E.BIRTH_DATE,E.ID
) AUX;
</code></pre>
<p>Expected output:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>total</th>
</tr>
</thead>
<tbody>
<tr>
<td>3 --first row</td>
</tr>
<tr>
<td>5 --second row</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74210561,
"author": "Isolated",
"author_id": 13118009,
"author_profile": "https://Stackoverflow.com/users/13118009",
"pm_score": 1,
"selected": false,
"text": "UNION"
},
{
"answer_id": 74212546,
"author": "Miles Elam",
"author_id": 11471381,
"author_pro... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18797972/"
] |
74,210,212 | <p>I have text like this:</p>
<pre class="lang-none prettyprint-override"><code>#12222223334 x $32.97
</code></pre>
<p>I want to extract the last number of the number before the "x" for example in this case the number 4.</p>
<p>Another example: <code>#8885555889 x $33.33</code>. Here, the number I want is 9.</p>
<p>I tried <code>^(.+?) x</code>, but its all the number before the <code>x</code>.</p>
| [
{
"answer_id": 74210262,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 0,
"selected": false,
"text": "\\d(?=\\s*x\\s+\\$\\d+(?:\\.\\d+)?$)\n"
},
{
"answer_id": 74210313,
"author": "Naveed",
"aut... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5375210/"
] |
74,210,254 | <p>currently in my data I have a column that contains description of transaction. I want to use str.contains to identify which values/rows are AW (the fast food store) transaction. However, when I use <code>data['cat_desc'].str.contains('AW', case=False, na=False)</code>, it also identifies values that have string 'aw', for example 'awxxxx' but I don't want that. How can I just identify 'AW' as a word and not string? Thanks!</p>
| [
{
"answer_id": 74210262,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 0,
"selected": false,
"text": "\\d(?=\\s*x\\s+\\$\\d+(?:\\.\\d+)?$)\n"
},
{
"answer_id": 74210313,
"author": "Naveed",
"aut... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11985669/"
] |
74,210,257 | <p>I'm currently trying to use Cypress for the first time and turn off cypress uncaught:exception during a certain test but I would like to turn it on once the test finished.
How can I do that ? Thanks</p>
<p>PS: I disable it this way
`</p>
<pre><code>cy.on('uncaught:exception', () => false);
</code></pre>
| [
{
"answer_id": 74211693,
"author": "agoff",
"author_id": 11625850,
"author_profile": "https://Stackoverflow.com/users/11625850",
"pm_score": 1,
"selected": false,
"text": "cy.on()"
},
{
"answer_id": 74212443,
"author": "Amit Kahlon",
"author_id": 13508689,
"author_pro... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340866/"
] |
74,210,266 | <p>this is the portion of xml the file I am interested:</p>
<pre><code></Section>
<Section id="21" name="Event Strips" itemsCount="18">
<Event title="HR Min" start="10707646" end="10709446"/>
<Event title="HR Max" start="1043646" end="1045446"/>
<Event title="RR Min" start="12441170" end="12442970"/>
<Event title="RR Max" start="14690429" end="14692229"/>
</Section>
<Section id="99" name="TimeDomainHRV" itemsCount="4">
<Info id="100" name="RRMean" value="725.99 ms"/>
<Info id="101" name="SDNN" value="108.01 ms"/>
</Section>
</code></pre>
<p>I want a dataframe like below from the xml:</p>
<pre><code>Event start end
HR Min 10707646 10709446
HR Max 1043646 1045446
..........................
</code></pre>
| [
{
"answer_id": 74210408,
"author": "Andrew",
"author_id": 12814459,
"author_profile": "https://Stackoverflow.com/users/12814459",
"pm_score": 1,
"selected": false,
"text": "pip install lxml\n"
},
{
"answer_id": 74236429,
"author": "Shourov",
"author_id": 11191528,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11191528/"
] |
74,210,274 | <p>I'm new to c++, and am trying to make a fullscreen setting in SFML. But nothing I tried works.</p>
<p>Working code:</p>
<pre><code>sf::RenderWindow window(sf::VideoMode(1920, 1080, 32), "title", sf::Style::Fullscreen);
</code></pre>
<p>Code that would look like what I am looking for (but doesn't work):</p>
<pre><code>string str1 = "sf::Style::Fullscreen";
sf::RenderWindow window(sf::VideoMode(1920, 1080, 32), "title", str1);
</code></pre>
| [
{
"answer_id": 74210427,
"author": "Botond Horváth",
"author_id": 16825566,
"author_profile": "https://Stackoverflow.com/users/16825566",
"pm_score": 2,
"selected": false,
"text": "const map<string,enum>"
},
{
"answer_id": 74210562,
"author": "Jabberwocky",
"author_id": 8... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340822/"
] |
74,210,287 | <p>I am trying to make a what is a simple plot in excel but can't figure out how to do it in plotly.
<a href="https://i.stack.imgur.com/3WgPb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3WgPb.png" alt="enter image description here" /></a>
I've tried:</p>
<pre><code>px.bar(df, x=['A','B','D','E'], color='date')
</code></pre>
<p>but it gives a key error.</p>
| [
{
"answer_id": 74213288,
"author": "Kat",
"author_id": 5329073,
"author_profile": "https://Stackoverflow.com/users/5329073",
"pm_score": 2,
"selected": true,
"text": "import plotly.express as px\nimport pandas as pd\n\nd = [\"8-5-2022\", \"8-12-2022\"]\ndf1 = pd.DataFrame({\"dt\": d, \"A... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11771129/"
] |
74,210,300 | <p>I have a JS plugin, which I want to trigger for every instance of an element.</p>
<p>However, I want the options for the plugin to be different for different cases.</p>
<pre><code>if(something) {
var options = {
itemSelectText: 'Some text',
searchPlaceholderValue: 'Search for something'
}
} else {
var options = {
itemSelectText: 'Some other text',
searchPlaceholderValue: 'Search for something else'
}
}
const choices = new Choices(dropdown,
options
);
</code></pre>
<p>Is this possible?</p>
| [
{
"answer_id": 74213288,
"author": "Kat",
"author_id": 5329073,
"author_profile": "https://Stackoverflow.com/users/5329073",
"pm_score": 2,
"selected": true,
"text": "import plotly.express as px\nimport pandas as pd\n\nd = [\"8-5-2022\", \"8-12-2022\"]\ndf1 = pd.DataFrame({\"dt\": d, \"A... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15178594/"
] |
74,210,304 | <p>Say I have an element that is visually part of a container. This container can be very long in height.</p>
<p>Now when the user scrolls down, I want to position this element to remain at the bottom of the <em>screen</em>. But when the container ends at some point, I want the element to stay at the bottom of that container and no scroll down further.</p>
<p>So once again: When the container hasn't ended yet, the element is at the bottom of the screen:</p>
<p><a href="https://i.stack.imgur.com/7Awtn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Awtn.png" alt="enter image description here" /></a></p>
<p>... but when I continue scrolling, it stops inside the container:</p>
<p><a href="https://i.stack.imgur.com/Jzqw5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jzqw5.png" alt="enter image description here" /></a></p>
<p>I am a bit stuck here. I do know how to do this when the element is positioned at the top inside of the container. Scrolling down will then just make it stop at the bottom.</p>
<p>The problem seems to be that either the Element will be moved outside of the document flow, so it won't remain inside the container, OR it will be at the bottom of the container <em>all the time</em>, so the element won't scroll with the user and remain on the bottom of the <em>screen</em>.</p>
<p>Any ideas?</p>
<pre><code><div className="mx-20 my-36">
<div className="bg-slate-200 h-[1200px] w-full relative border-2 border-black relative">
<div className="fixed bottom-0 left-0 right-0 p-2 bg-white w-full border-2 border-red-600">Element</div>
</div>
<div className="my-12">
The page continues here but the element remains in the container ...
</div>
</div>
</code></pre>
<p>PS: Using tailwind & react here, but any vanilla CSS are welcome too! I would love to solve this without javascript.</p>
| [
{
"answer_id": 74210511,
"author": "Sling",
"author_id": 19881049,
"author_profile": "https://Stackoverflow.com/users/19881049",
"pm_score": 0,
"selected": false,
"text": ".sticky {\n position: -webkit-sticky;\n position: sticky;\n bottom: 0;\n height: 30px;\n width: 100vw;\n backg... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15093141/"
] |
74,210,309 | <p>Any Help please !!</p>
<p>I receive this error when I'm calling my endpoint which call Feign in the background :</p>
<pre><code>com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
`org.springframework.http.ResponseEntity` (no Creators, like default constructor, exist): cannot deserialize
from Object value (no delegate- or property-based Creator)
at [Source: (BufferedReader); line: 1, column: 2]
</code></pre>
<p>This is my endpoint inside Controller :</p>
<pre class="lang-java prettyprint-override"><code>@RestController
@RequestMapping(Routes.URI_PREFIX)
public class CartoController {
@Autowired
private ReadCartographyApiDelegate readCartographyApiDelegate;
@GetMapping(value = "/cartographies/{uid}", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseWrapper<ReadCartographyResponse> readCarto(HttpServletRequest request,
@PathVariable(name = "uid") String uid) {
ResponseEntity<ReadCartographyResponse> result ;
try {
result = readCartographyApiDelegate.readCartography(uid);
}catch (Exception e){
throw new TechnicalException("Error during read Carto");
}
return responseWrapperWithIdBuilder.of(result.getBody());
}
}
</code></pre>
<p>Interface ReadCartographyApiDelegate generated automatically by openApi from yaml file :</p>
<pre class="lang-java prettyprint-override"><code>@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "...")
public interface ReadCartographyApiDelegate {
default Optional<NativeWebRequest> getRequest() {
return Optional.empty();
}
default ResponseEntity<ReadCartographyResponse> readCartography(String uid) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "null";
ApiUtil.setExampleResponse(request, "application/json", exampleString);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
</code></pre>
<p>This my ReadCartoApiDelegateImpl which implements ReadCartographyApiDelegate interface :</p>
<pre class="lang-java prettyprint-override"><code>@Service
public class ReadCartographyApiDelegateImpl implements ReadCartographyApiDelegate {
private EcomGtmClient ecomGtmClient;
public ReadCartographyApiDelegateImpl(EcomGtmClient ecomGtmClient) {
this.ecomGtmClient = ecomGtmClient;
}
@Override
public ResponseEntity<ReadCartographyResponse> readCartography(String uid) {
ResponseEntity<ReadCartographyResponse> response = ecomGtmClient.readCartography(uid);
return response;
}
}
</code></pre>
<p>This is the feign client :</p>
<pre class="lang-java prettyprint-override"><code>@FeignClient(name = "ecomGtmSvc", url = "http://localhost/")
public interface EcomGtmClient {
@GetMapping(value = "/read-carto/{uid}")
ResponseEntity<ReadCartographyResponse> readCartography(@PathVariable("uid") String uid);
}
</code></pre>
<p>The problem is that ResponseEntity (spring class) class doesn't contain default constructor which is needed during creating of instance. is there Any config to resolve this issue ?</p>
| [
{
"answer_id": 74210511,
"author": "Sling",
"author_id": 19881049,
"author_profile": "https://Stackoverflow.com/users/19881049",
"pm_score": 0,
"selected": false,
"text": ".sticky {\n position: -webkit-sticky;\n position: sticky;\n bottom: 0;\n height: 30px;\n width: 100vw;\n backg... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7446167/"
] |
74,210,343 | <p>I want to change the color of the menu on text hover. But not when the menu text is hovered but another heading. I have a heading "Not a restaurant, but here for them." and when the user hovers the word "restaurant" the menu text color should change to white and the word "restaurant" to red and the rest of the heading to white. The second part (that "restaurant" changes to red and the rest of the heading to white) already works. But how can I make it that also the color of the menu 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>.headingRestaurant:hover {
color: red;
}
.headingRestaurant {
cursor: pointer;
}
.textb {
pointer-events: none;
}
.headingRestaurant {
pointer-events: initial;
}
.textb:hover {
color: white;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><nav>
<ul>
<li>
<a href="file:///C:/Users/.../index.html">Home</a>
</li>
<li>
<a href="file:///C:/Users/.../about.html">About</a>
</li>
</ul>
</nav>
<h1 class="textb">
Not a <span id="heading1" class="headingRestaurant">restaurant</span>,
<br> but here for them.
</h1></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74210479,
"author": "rs.wright",
"author_id": 20176752,
"author_profile": "https://Stackoverflow.com/users/20176752",
"pm_score": 0,
"selected": false,
"text": ".headingRestaurant:hover target {\n\n}"
},
{
"answer_id": 74210875,
"author": "Thomas",
"author_... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20332178/"
] |
74,210,384 | <pre><code>sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20221026-22941-v40jeb.rb extconf.rb
checking for ffi.h... \*\*\* extconf.rb failed \*\*\*
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in \`try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in \`block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in \`with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in \`try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in \`block in have_header'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in \`block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in \`block (2 levels) in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in \`open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in \`block in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in \`open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in \`postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in \`checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in \`have_header'
from extconf.rb:10:in \`system_libffi_usable?'
from extconf.rb:42:in \`\<main\>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/gem_make.out
</code></pre>
| [
{
"answer_id": 74216595,
"author": "Дима Савицкий",
"author_id": 20345076,
"author_profile": "https://Stackoverflow.com/users/20345076",
"pm_score": -1,
"selected": false,
"text": "brew install cocoapods \nbrew link cocoapods \n"
},
{
"answer_id": 74260261,
"author": "A... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17526165/"
] |
74,210,393 | <p>I'm busy with an ASP.NET Core MVC application, and I'm trying to populate a drop down list. I've created a view model and I have added a method to my <code>StoresController</code> that returns a list of stores that I want to display in a dropdown. I've been working off some online tutorials as I'm very new to asp.</p>
<p>View model:</p>
<pre><code>public class StoreListViewModel
{
public List<StoreList> StoreList { get; set; } = new List<StoreList>();
}
public class StoreList
{
public string StoreId { get; set; } = null!;
public string StoreName { get; set; } = null!;
}
</code></pre>
<p><code>StoresController</code>:</p>
<pre><code>public IActionResult LoadStoreList()
{
if (ModelState.IsValid)
{
var storeList = new StoreListViewModel().StoreList.Select
(x => new SelectListItem { Value = x.StoreId, Text = x.StoreName }).ToList();
ViewBag.Stores = storeList;
}
return NotFound();
}
</code></pre>
<p>I'm trying to use <code>ViewBag</code> to call my <code>LoadStoreList()</code> method.</p>
<pre><code><select name="storeList" class="form-control" asp-items="@(new SelectList(ViewBag.Stores, "Value", "Text"))"></select>
</code></pre>
<p>When I load my page I get the following error</p>
<blockquote>
<p>Value cannot be null. (Parameter 'items')</p>
</blockquote>
<p>The page I need the dropdown list on is my <code>CreateUser.cshtml</code> which is bound to my <code>UserModel</code> and has a <code>UsersController</code>. The method I have created for listing the stores is in my <code>StoresController</code> which is bound to my <code>StoresModel</code>. So I'm not sure if that's causing the issue.</p>
<p>I've been battling with this for days, if someone could help me get this working or show me a better method, that would be great.</p>
<p>*Edit</p>
<p>The <strong>UserIndex()</strong> method is the first method that fires when my users page opens, do I call the <strong>LoadStoreList()</strong> method from there ?</p>
<p><strong>UserController</strong></p>
<pre><code>public async Task<IActionResult> UsersIndex()
{
return _context.UsersView != null ?
View(await _context.UsersView.ToListAsync()) :
Problem("Entity set 'ApplicationDbContext.Users' is null.");
}
</code></pre>
| [
{
"answer_id": 74216595,
"author": "Дима Савицкий",
"author_id": 20345076,
"author_profile": "https://Stackoverflow.com/users/20345076",
"pm_score": -1,
"selected": false,
"text": "brew install cocoapods \nbrew link cocoapods \n"
},
{
"answer_id": 74260261,
"author": "A... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13082966/"
] |
74,210,397 | <p>When I launch my app I get the following message:</p>
<blockquote>
<p>An unhandled win32 exception occured in MauiApp.exe</p>
</blockquote>
<p>Unfortunately I am not able to get a detailed exception message, as the application crashes and "the debugger is not configured to debug this unhandled exception". I have isolated the issue and it occurs whenever I bound my View to a ViewModel like so:</p>
<pre><code>public partial class MainPage : ContentPage
{
public MainPage(MainViewModel mainViewModel)
{
BindingContext = mainViewModel;
InitializeComponent();
}
}
public sealed class MainViewModel
{
}
</code></pre>
<p>And in the MauiProgram.cs file:</p>
<pre><code>builder.Services.AddTransient<MainViewModel>();
</code></pre>
<p>How can I resolve this issue?</p>
| [
{
"answer_id": 74212605,
"author": "ΩmegaMan",
"author_id": 285795,
"author_profile": "https://Stackoverflow.com/users/285795",
"pm_score": 1,
"selected": false,
"text": " InitializeComponent();\n BindingContext = mainViewModel;\n"
},
{
"answer_id": 74219302,
"author": ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6015925/"
] |
74,210,400 | <p>I'm trying to crop a large multipolygon shapefile by a single, smaller polygon. It works using st_intersection, however this takes a very long time, so I'm instead trying to convert the multipolygon to a raster, and crop that raster by the smaller polygon.</p>
<pre><code>## packages - sorry if I've missed any!
library(raster)
library(rgdal)
library(fasterize)
library(sf)
</code></pre>
<pre><code>## load files
shp1 <- st_read("pathtoshp", crs = 27700) # a large multipolygon shapefile to crop
### image below created using ggplot- ignore the black boundaries!
</code></pre>
<p><a href="https://i.stack.imgur.com/1U87c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1U87c.png" alt="enter image description here" /></a></p>
<pre><code>shp2 <- st_read("pathtoshp", crs = 27700) # a single, smaller polygon shapefile, to crop shp1 by
plot(shp2)
</code></pre>
<p><a href="https://i.stack.imgur.com/9SgNU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9SgNU.png" alt="enter image description here" /></a></p>
<pre><code>## convert to raster (faster than st_intersection)
projection1 <- CRS('+init=EPSG:27700')
rst_template <- raster(ncols = 1000, nrows = 1000,
crs = projection1,
ext = extent(shp1))
rst_shp1 <- fasterize(shp1, rst_template)
plot(rst_shp1)
</code></pre>
<p><a href="https://i.stack.imgur.com/pRjP6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pRjP6.png" alt="enter image description here" /></a></p>
<pre><code>rst_shp2 <- crop(rst_shp1, shp2)
plot(rst_shp2)
</code></pre>
<p><a href="https://i.stack.imgur.com/2pcUR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2pcUR.png" alt="enter image description here" /></a></p>
<p>When I plot shp2, the upper boundary is flat, rather than fitting the true boundary of the shp2 polygon.
Any help would be greatly appreciated!</p>
| [
{
"answer_id": 74212605,
"author": "ΩmegaMan",
"author_id": 285795,
"author_profile": "https://Stackoverflow.com/users/285795",
"pm_score": 1,
"selected": false,
"text": " InitializeComponent();\n BindingContext = mainViewModel;\n"
},
{
"answer_id": 74219302,
"author": ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19777841/"
] |
74,210,413 | <p>I have this exercise and the goal is to solve it with complexity less than O(n^2).</p>
<p>You have an array with length N filled with event probabilities. Create another array in which for each element i calculate the probability of all event to happen until the position i.</p>
<p>I have coded this O(n^2) solution. Any ideas how to improve it?</p>
<pre><code>probabilityTable = [0.1, 0.54, 0.34, 0.11, 0.55, 0.75, 0.01, 0.06, 0.96]
finalTable = list()
for i in range(len(probabilityTable)):
finalTable.append(1)
for j in range(i):
finalTable[i] *= probabilityTable[j]
for item in finalTable:
print(item)
</code></pre>
| [
{
"answer_id": 74212605,
"author": "ΩmegaMan",
"author_id": 285795,
"author_profile": "https://Stackoverflow.com/users/285795",
"pm_score": 1,
"selected": false,
"text": " InitializeComponent();\n BindingContext = mainViewModel;\n"
},
{
"answer_id": 74219302,
"author": ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13695391/"
] |
74,210,421 | <p>I'm trying to write a program with Python to emulate an 'old' online game in which you drive a worm through the screen with some inputs from the keyboard.</p>
<pre class="lang-py prettyprint-override"><code>import turtle
# Set screen and background
wn = turtle.Screen()
wn.title("Turn with Left and Right buttons your keyboard. Click on screen to EXIT.")
wn.bgcolor("black")
# Snake settings
snake = turtle.Turtle()
snake.color("purple")
snake.shape("circle")
snake.shapesize(0.25,0.25)
snake.pensize(5)
snake.speed(10)
t = 0
# Define Go loop, turn Left and Right
def go():
t = 0
while t < 1000:
snake.forward(1)
t += 1
def left():
snake.circle(1,8)
go()
def right():
snake.circle(1,-8)
go()
# Inputs and Exit on click
wn.onkey(right, "Right")
wn.onkeypress(right, "Right")
wn.onkey(left, "Left")
wn.onkeypress(left, "Left")
wn.listen()
wn.exitonclick()
turtle.done()
</code></pre>
<p>The problem here is that, after some moves, the program crashes returning:</p>
<pre class="lang-none prettyprint-override"><code>RecursionError: maximum recursion depth exceeded while calling a Python object.
</code></pre>
<p>I'm still a beginner so i don't get what I'm doing wrong. How can I fix the error?</p>
| [
{
"answer_id": 74210781,
"author": "Random Davis",
"author_id": 6273251,
"author_profile": "https://Stackoverflow.com/users/6273251",
"pm_score": 0,
"selected": false,
"text": "go"
},
{
"answer_id": 74213118,
"author": "cdlane",
"author_id": 5771269,
"author_profile":... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340127/"
] |
74,210,424 | <p>I have the following text from a column called 'subject':</p>
<pre><code>Standard WiFi Install - (Broadband) by HS&S - Job No:VR041135037 on 2022-01-14
</code></pre>
<p>I need to extract the ID (<code>VR041135037</code>) and the date (<code>2022-01-14</code>) from the subject column.</p>
<p>What query can I write to go about doing this?</p>
<p>EDIT: This is the column from the table I have:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Subject</th>
</tr>
</thead>
<tbody>
<tr>
<td>OPALS INSTALL by HS&S - Job No:VR041613130 on 2022-03-17</td>
</tr>
<tr>
<td>OPALS INSTALL by HS&S - Job No:VR041613130 on 2022-03-17</td>
</tr>
<tr>
<td>Standard WiFi Install - (Broadband) by HS&S - Job No:VR041729247 on 2022-03-17</td>
</tr>
<tr>
<td>Standard WiFi Install - (Broadband) by HS&S - Job No:VR041729247 on 2022-03-17</td>
</tr>
<tr>
<td>OPALS INSTALL by HS&S - Job No:VR041665578 on 2022-03-18</td>
</tr>
<tr>
<td>OPALS INSTALL by HS&S - Job No:VR041665578 on 2022-03-18</td>
</tr>
</tbody>
</table>
</div>
<p>Thanks</p>
| [
{
"answer_id": 74210683,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "SUBSTRING()"
},
{
"answer_id": 74210771,
"author": "Isolated",
"author_id": 13118009,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16562053/"
] |
74,210,425 | <p>I need to check if some variable is an integer within quotes. So, naturally, I did the following:</p>
<pre><code>! pip install smartprint
def isIntStr(n):
# first, the item must be a string
if not isinstance(n, str):
return False
# second, we try to convert it to integer
try:
int(n)
return True
except:
return False
from smartprint import smartprint as sprint
sprint (isIntStr("123_dummy"))
sprint (isIntStr("123"))
sprint (isIntStr(123))
</code></pre>
<p>It works as expected with the following output:</p>
<pre><code>isIntStr("123_dummy") : False
isIntStr("123") : True
isIntStr(123) : False
</code></pre>
<p>Is there a cleaner way to do this check?</p>
| [
{
"answer_id": 74210641,
"author": "Andrew",
"author_id": 12814459,
"author_profile": "https://Stackoverflow.com/users/12814459",
"pm_score": 3,
"selected": true,
"text": "def is_int_or_str(x):\n if isinstance(x, str):\n return x.strip().isnumeric()\n else:\n return F... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3896008/"
] |
74,210,435 | <p>I want to assign the output of a mongo command (i.e database names) to a bash array variable but I am not sure how to go about it.</p>
<p>I am getting an error :</p>
<pre><code>dump.sh
Starting-BACKUP
dump.sh
./dump.sh: line 16: declare: `–a': not a valid identifier
./dump.sh: line 24: mongo: command not found
Database backup was successful
</code></pre>
<p>when I attempt using dump.sh below:</p>
<pre><code>#!/bin/bash
declare –a databases=()
databases=$(mongo --quiet --uri="mongodb://root:mypassword@mongodb-prom/admin" --authenticationDatabase admin --eval="show dbs;" | cut -d " " --field 1)
echo $databases
</code></pre>
<p>Ordinarily I am able to get a listing of the databases when I kubectl into the pod with following steps :</p>
<pre><code>$ kubectl exec -it mongodb-prom-xxxxxxxxx-dddx4 -- sh
$ mongo
> use admin
> db.auth('root','mypassword')
> show dbs
admin 0.000GB
platforms 0.000GB
users 0.000GB
</code></pre>
<p>I am not sure why the mongo command is not being recognized because the <strong>same script</strong> <em>is able to execute the mongodump command below</em> :</p>
<pre><code>mongodump --uri="<uri_here>" --authenticationDatabase admin --gzip --archive=/tmp/"<variable_here>".gz
</code></pre>
<p><strong>UPDATE</strong> : This is the associated Dockerfile. My expectation is that both mongo and mongodump should be working by default in a mongo container but it seems only mongodump is working for now</p>
<pre><code>FROM mongo
WORKDIR /opt/backup/
WORKDIR /usr/src/configs
COPY dump.sh .
RUN chmod +x dump.sh
</code></pre>
<p>My two issues :</p>
<ol>
<li>Is my syntax correct for the variable assignment (I suspect its not correct) ?</li>
<li>How should I properly declare the array variable to avoid the warnings ?</li>
</ol>
<p>NB : Mongo tooling is already installed on the container and is actually working for mongodump</p>
| [
{
"answer_id": 74210641,
"author": "Andrew",
"author_id": 12814459,
"author_profile": "https://Stackoverflow.com/users/12814459",
"pm_score": 3,
"selected": true,
"text": "def is_int_or_str(x):\n if isinstance(x, str):\n return x.strip().isnumeric()\n else:\n return F... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2960388/"
] |
74,210,447 | <p>I need to add a parameter to my search that filters results containing a specific word in a value. The query is searching for user history records and contains a <code>url</code> key. I need to filter out <code>/history</code> and any other url containing that string.</p>
<p>Here's my current query:</p>
<pre><code>GET /user_log/_search
{
"size" : 50,
"query": {
"match": {
"user_id": 56678
}
}
}
</code></pre>
<p>Here's an example of a record, boiled down to just the value we're looking at:</p>
<pre><code>"_source": {
"url": "/history?page=2&direction=desc",
},
</code></pre>
<p>How can the parameters of the search be changed to filter out this result.</p>
| [
{
"answer_id": 74210478,
"author": "Amit",
"author_id": 4039431,
"author_profile": "https://Stackoverflow.com/users/4039431",
"pm_score": 1,
"selected": false,
"text": "{\n \"query\": {\n \"bool\": {\n \"must\": {\n \"match\": {\n \"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12817213/"
] |
74,210,464 | <p>Suppose I have a dataset:</p>
<pre><code>Name <- c("Jon", "Bill", "Maria", "Ben", "Tina")
Age <- c(23, 41, 32, 58, 26)
datesurg<-c("2022-03-17","2022-02-20","2022-01-23","2022-03-18","2022-04-17")
dateevent<-c("2022-03-20","2022-02-21","2022-03-17","2022-03-18","2022-04-17")
datelookup<-c("2022-03-20","2022-02-20","2022-01-23","2022-03-18","2022-04-17")
df <- data.frame(Name, Age,datesurg,dateevent,datelookup)
</code></pre>
<p>I want to have a dataframe where for each row of "datesurg" if this variable matches any date in the "datelookup" column, keep the row.</p>
<pre><code> Name Age datesurg dateevent datelookup
2 Bill 41 2022-02-20 2022-02-21 2022-02-20
3 Maria 32 2022-01-23 2022-03-17 2022-01-23
4 Ben 58 2022-03-18 2022-03-18 2022-03-18
5 Tina 26 2022-04-17 2022-04-17 2022-04-17
</code></pre>
<p>Next I want to keep the rows where "datesurg" or "dateevent" are equal to "datelookup".</p>
<pre><code> Name Age datesurg dateevent datelookup
1 Jon 23 2022-03-17 2022-03-20 2022-03-20
2 Bill 41 2022-02-20 2022-02-21 2022-02-20
3 Maria 32 2022-01-23 2022-03-17 2022-01-23
4 Ben 58 2022-03-18 2022-03-18 2022-03-18
5 Tina 26 2022-04-17 2022-04-17 2022-04-17
</code></pre>
| [
{
"answer_id": 74210595,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 1,
"selected": false,
"text": "if_any"
},
{
"answer_id": 74211080,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_prof... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9074261/"
] |
74,210,503 | <p>I have a class <code>SimpleHistogram<DT></code> that takes in a generic array <code>DT[]</code> and I'm supposed to set the count, the number of times the element occurs in the array, of a specific <code>item</code> in the array to int <code>count</code>.</p>
<p>Here is what I have so far:</p>
<pre><code>public class SimpleHistogram<DT> implements Histogram<DT>, Iterable<DT> {
DT[] items;
int size;
public SimpleHistogram() {
}
public SimpleHistogram(DT[] items) {
this.items = items;
}
@Override
public void setCount(DT item, int count) {
int n = 0;
Iterator<DT> L = this.iterator();
while (L.hasNext()) {
DT dt = L.next();
if (dt == item) { // if dt equals to item, meaning item IS present, then
n+=count; // set the count of the item to count
} else
{this.add(dt, count)} // if its not equal, meaning its not there, then add the item and the count of the item
}
}
private class Iterate implements Iterator<DT> {
int index = 0;
boolean lastRemoved = false;
@Override
public boolean hasNext() {
return (index < items.length-1);
}
@Override
public DT next() {
if (index < (items.length) -1)
throw new NoSuchElementException("No element at index");
DT object = items[index];
index++;
lastRemoved = false;
return object;
}
}
</code></pre>
<p>I'm struggling to implement the function <code>setCount( DT item, int count)</code> which is supposed to set the count of <code>item</code> to <code>count</code>.</p>
<p>Aditionally, if <code>item</code> does not exist already in the list, then we are supposed to add the item in and then set the count of the item to <code>count</code>.</p>
<p>I have provided explanations for what I intended to do but due to the fact that I am new to this, I haven't found sources that can properly clear this doubt, so any help would be greatly appreciated</p>
<p><strong>Edit</strong> Here is the full code in case you may want to derive something from it. Test cases also presented below.</p>
<pre><code>package histogram;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
// TODO: Uncomment this and make sure to implement all the methods
public class SimpleHistogram<DT> implements Histogram<DT>, Iterable<DT> {
DT[] items;
int size;
public SimpleHistogram() {
}
public SimpleHistogram(DT[] items) {
this.items = items;
}
@Override
public void setCount(DT item, int count) {
int n = 0;
Iterator<DT> L = this.iterator();
while (L.hasNext()) {
DT dt = L.next();
if (dt == item) { // if dt equals to item, meaning item IS present, then
n+=count; // set the count of the item to count
} else
{this.add(dt, count)} // if its not equal, meaning its not there, then add the item and the count of the item
}
}
private class Iterate implements Iterator<DT> {
int index = 0;
boolean lastRemoved = false;
@Override
public boolean hasNext() {
return (index < items.length-1);
}
@Override
public DT next() {
if (index < (items.length) -1)
throw new NoSuchElementException("No element at index");
DT object = items[index];
index++;
lastRemoved = false;
return object;
}
}
public int getCount(DT item) {
int n = 0;
Iterator<DT> L = this.iterator();
while (L.hasNext()) {
DT dt = L.next();
if (dt == item) {
n++;
}
}
return n;
}
@Override
public Iterator<DT> iterator() {
return new Iterate();
}
@Override
public int getTotalCount() {
return items.length;
}
}
</code></pre>
<p>Test cases:</p>
<pre><code>public class SimpleHistogramTest {
@Test
public void testHistogram() {
Character[] target = {'a','b','c','a'};
Histogram<Character> h = new SimpleHistogram<>(target);
Iterator<Character> iter = h.iterator();
int elemCount = 0;
while(iter.hasNext()) {
iter.next();
elemCount++;
}
assertEquals(3, elemCount);
assertEquals(2, h.getCount('a'));
assertEquals(1, h.getCount('b'));
assertEquals(1, h.getCount('c'));
assertEquals(4, h.getTotalCount());
}
}
</code></pre>
| [
{
"answer_id": 74210833,
"author": "changuk",
"author_id": 15566000,
"author_profile": "https://Stackoverflow.com/users/15566000",
"pm_score": -1,
"selected": false,
"text": "=="
},
{
"answer_id": 74211377,
"author": "erickson",
"author_id": 3474,
"author_profile": "h... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18984687/"
] |
74,210,516 | <p>I have a Google Sheet with 5 named columns.
<br/>Under "Recursive_Requests" column, it's shown 1 of the 8 possible options (every_day , every_monday , every_tuesday , every_wednesday , every_thursday , every_friday , every_saturday , No).
The sheet is organized following the options' order under the "Department" column (flagged in <strong>bold</strong>).</p>
<p><br/>Every day at 9am, the sheet would check if the option under "Recursive_Requests" column matches with today's date. If it doesn't match, it'd hide the row until the requirement is met (adding or removing empty rows if they are useful or not to sort the sheet).
<br/>"every_day" and "no" are always showed.</p>
<p><br/>I've read and tried other threads, but none are completely similar (<a href="https://stackoverflow.com/questions/52088049/google-sheets-hide-rows-based-on-todays-date">this</a>, <a href="https://stackoverflow.com/questions/70535729/google-apps-script-that-hides-row-if-a-date-is-less-than-or-equal-to-todays-dat">this</a> or <a href="https://stackoverflow.com/questions/64069149/google-script-how-to-hide-a-row-if-a-cell-contains-a-date-10-days-older-than-to">this</a>, for example).</p>
<p><br/>I've tried also to filter and show rows (but this doesn't work with dates):</p>
<pre><code>//@OnlyCurrentDoc
function onOpen() {
SpreadsheetApp.getUi().createMenu("filter")
.addItem("rows_filter", "filter_rows")
.addItem("rows_show", "show_rows")
.addToUi();
}
function filter_rows() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Form responses 1");
var data = sheet.getDataRange().getValues();
for(var i = 2; i < data.length; i++) {
if(row_name[2] === "every_monday") {
sheet.hideRows(i + 1);
}
}
}
function show_rows() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Form responses 1");
sheet.show_rows(1, sheet.getMaxRows());
}
</code></pre>
<p><br/>e.g.:
<br/>Before any edit:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.05.38</td>
<td>Alexander</td>
<td><strong>second_department</strong></td>
<td>first_request</td>
<td>every_tuesday</td>
</tr>
<tr>
<td>26/10/2022 19.07.56</td>
<td>Wayne</td>
<td><strong>second_department</strong></td>
<td>third_request</td>
<td>every_monday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.09.36</td>
<td>Robert</td>
<td><strong>third_department</strong></td>
<td>first_request</td>
<td>every_tuesday</td>
</tr>
<tr>
<td>26/10/2022 19.11.19</td>
<td>Larry</td>
<td><strong>third_department</strong></td>
<td>second_request</td>
<td>every_thursday</td>
</tr>
<tr>
<td>26/10/2022 19.11.51</td>
<td>Jared</td>
<td><strong>third_department</strong></td>
<td>third_request</td>
<td>every_wednesday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.13.41</td>
<td>Peter</td>
<td><strong>fourth_department</strong></td>
<td>first_request</td>
<td>every_saturday</td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div><br/>
<br/>
If it's Monday (after editing):
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.07.56</td>
<td>Wayne</td>
<td><strong>second_department</strong></td>
<td>third_request</td>
<td>every_monday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div><br/>
If it's Tuesday (after editing):
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.05.38</td>
<td>Alexander</td>
<td><strong>second_department</strong></td>
<td>first_request</td>
<td>every_tuesday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.09.36</td>
<td>Robert</td>
<td><strong>third_department</strong></td>
<td>first_request</td>
<td>every_tuesday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p><br/>If it's Wednesday (after editing):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.11.51</td>
<td>Jared</td>
<td><strong>third_department</strong></td>
<td>third_request</td>
<td>every_wednesday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p><br/>If it's Thursday (after editing):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.11.19</td>
<td>Larry</td>
<td><strong>third_department</strong></td>
<td>second_request</td>
<td>every_thursday</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p><br/>If it's Friday (after editing):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p><br/>If it's Saturday (after editing):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.13.41</td>
<td>Peter</td>
<td><strong>fourth_department</strong></td>
<td>first_request</td>
<td>every_saturday</td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p><br/>If it's Sunday (after editing):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div><br/>
<br/>Instead the output I get with the current Query () is (if it's Monday):
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Timestamp</th>
<th>Name</th>
<th>Department</th>
<th>Request</th>
<th>Recursive_Requests</th>
</tr>
</thead>
<tbody>
<tr>
<td>26/10/2022 19.05.24</td>
<td>John</td>
<td><strong>first_department</strong></td>
<td>second_request</td>
<td>No</td>
</tr>
<tr>
<td>26/10/2022 19.07.56</td>
<td>Wayne</td>
<td><strong>second_department</strong></td>
<td>third_request</td>
<td>every_monday</td>
</tr>
<tr>
<td>26/10/2022 19.14.58</td>
<td>Tom</td>
<td><strong>fourth_department</strong></td>
<td>fourth_request</td>
<td>every_day</td>
</tr>
</tbody>
</table>
</div>
<p>Basically there aren't blank rows between differents departments to visually order the sheet.</p>
<br/>
<br/>Currently: it isn't able to discriminate between different days / hide rows accordingly / it can't add or remove empty rows to organize the sheet / check this condition every day at 9am.
| [
{
"answer_id": 74211544,
"author": "Cooper",
"author_id": 7215091,
"author_profile": "https://Stackoverflow.com/users/7215091",
"pm_score": 2,
"selected": false,
"text": "function showhide00() {\n const ss = SpreadsheetApp.getActive();\n const sh = ss.getSheetByName(\"Sheet0\");\n con... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20223165/"
] |
74,210,528 | <p>I'm new in django rest framework and i faced this problem
I have two tables Order,Payment I want to get all orders that didn't have payment in the view how can i do this</p>
<p>Models</p>
<pre><code>class Payment(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
amount = models.DecimalField(max_digits=7, decimal_places=2)
invoice = models.ImageField(upload_to='images')
is_approved = models.BooleanField()
order = models.ForeignKey(Order, on_delete=models.CASCADE)
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.CASCADE)
class Order (models.Model):
firstname = models.CharField(max_length = 20)
lastname = models.CharField(max_length = 20)
emailaddress = models.CharField(max_length = 20)
phone = models.CharField(max_length = 11)
discount = models.DecimalField(max_digits=5,blank = True ,null = True,decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
venture = models.ForeignKey(Venture ,related_name ='ventures' ,on_delete=models.CASCADE)
salesPerson = models.ForeignKey(SalesPerson,related_name ='salesPerson',blank = True,null = True ,on_delete=models.CASCADE)
applicationForm = models.OneToOneField(ApplicationForm,blank = True,null = True,on_delete=models.CASCADE)
</code></pre>
<p>serializers</p>
<pre><code>class OrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
fields = ['id','firstname','lastname','emailaddress','phone','','product','wave','venture']
class PaymentSerializer(serializers.ModelSerializer):
class Meta:
model = Payment
fields = ['created_at','updated_at','amount','is_approved','paymentMethod',"order","invoice"]
</code></pre>
<p>i try to get all orders that didn't have payments</p>
| [
{
"answer_id": 74211544,
"author": "Cooper",
"author_id": 7215091,
"author_profile": "https://Stackoverflow.com/users/7215091",
"pm_score": 2,
"selected": false,
"text": "function showhide00() {\n const ss = SpreadsheetApp.getActive();\n const sh = ss.getSheetByName(\"Sheet0\");\n con... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9549227/"
] |
74,210,529 | <p>I'm trying to use RxJs <code>expand</code> operator together with <code>delay</code> in order to reproduce a polling behavior to the server until the HTTP call returns success.</p>
<p>I use the <code>delay</code> operator as well because the HTTP call returns the following object:</p>
<pre><code>{
retryAfterInSeconds: 30,
status: 'Running'
}
</code></pre>
<p>and I want to skip unnecessary calls if I know when I should check the status again.</p>
<p>So, I implemented the behavior as follows:</p>
<pre><code>private pollExportStatus(entity: any): void {
let waitingTime = 0;
this.service
.getStatus(entity)
.pipe(
untilDestroyed(this),
expand((x: Status) => {
waitingTime += x.retryAfterInSeconds;
const shouldContinuePolling =
waitingTime < 300 &&
x.status !== StatusType.Succeeded &&
x.status !== StatusType.Failed;
if (!shouldContinuePolling) {
return EMPTY;
}
return this.service
.getStatus(entity)
.pipe(delay(x.retryAfterInSeconds * 1000));
}),
last()
)
.subscribe((x: Status) => {
if (waitingTime >= 300 || x.status !== StatusType.Succeeded
) {
console.log('Failed');
return;
}
console.log('Succeeded');
});
}
</code></pre>
<p>Everything works as expected except one thing: even if I return the next call (inside expand) with a <code>delay</code>:</p>
<pre><code>return this.service
.getStatus(entity)
.pipe(delay(x.retryAfterInSeconds * 1000));
</code></pre>
<p>the first call is not delayed and I don't understand why.</p>
<p>Finally, I found a solution that works as expected.</p>
<p>I replaced the <code>expand</code> return with the following one:</p>
<pre><code>return timer(x.retryAfterInSeconds * 1000).pipe(
concatMap(() => this.service.getStatus(entity))
);
</code></pre>
<p>but I want to understand why the first one is not working and the second one does.</p>
<p><em>Note: the first behavior is working if I use a simple observable (created with <code>of</code> operator), but not with an HTTP call</em></p>
| [
{
"answer_id": 74211544,
"author": "Cooper",
"author_id": 7215091,
"author_profile": "https://Stackoverflow.com/users/7215091",
"pm_score": 2,
"selected": false,
"text": "function showhide00() {\n const ss = SpreadsheetApp.getActive();\n const sh = ss.getSheetByName(\"Sheet0\");\n con... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74210529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8916057/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.