qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,359,651 | <p>I have developed an app that communicates with our machine via Wi-Fi. You can think of it like an app that is used at car gas stations, such as Shell, Fillibri or the ryd app. This means that the app can only be used when the customer is in front of our machine. If the customer is not directly in front of our machine, the app cannot be used and the customer only sees a message.</p>
<p>My question:
How can I implement an access for the app review in the app stores, since the app only works when the app is connected to or machine via Wi-Fi.</p>
<p>I didn't find something in google.</p>
| [
{
"answer_id": 74359671,
"author": "ask4you",
"author_id": 18309173,
"author_profile": "https://Stackoverflow.com/users/18309173",
"pm_score": 1,
"selected": false,
"text": "bind"
},
{
"answer_id": 74359815,
"author": "Boguz",
"author_id": 5509709,
"author_profile": "https://Stackoverflow.com/users/5509709",
"pm_score": 2,
"selected": true,
"text": "formSubmit"
},
{
"answer_id": 74359872,
"author": "scottwillmoore",
"author_id": 7349225,
"author_profile": "https://Stackoverflow.com/users/7349225",
"pm_score": 2,
"selected": false,
"text": "this"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20448726/"
] |
74,359,694 | <p>Can I check with oauth2 if the user has a verified email or telephone on the discord account?</p>
<p>I need this because I want to create a verification (ticket bot)
Please do not reply in a way that "you have this option in the server settings".</p>
<p>Information:
discord.js v14
javascript
node.js</p>
<p>I tried to search on the internet (I'm Polish so it's hard to search using the translator).</p>
| [
{
"answer_id": 74359671,
"author": "ask4you",
"author_id": 18309173,
"author_profile": "https://Stackoverflow.com/users/18309173",
"pm_score": 1,
"selected": false,
"text": "bind"
},
{
"answer_id": 74359815,
"author": "Boguz",
"author_id": 5509709,
"author_profile": "https://Stackoverflow.com/users/5509709",
"pm_score": 2,
"selected": true,
"text": "formSubmit"
},
{
"answer_id": 74359872,
"author": "scottwillmoore",
"author_id": 7349225,
"author_profile": "https://Stackoverflow.com/users/7349225",
"pm_score": 2,
"selected": false,
"text": "this"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19876949/"
] |
74,359,703 | <p>I have the following array of <code>POSIXct</code> dates</p>
<pre><code>>x
[1] "2003-12-01 UTC" "2003-12-02 UTC" "2003-12-03 UTC" "2003-12-04 UTC" "2003-12-05 UTC" "2003-12-08 UTC"
[7] "2003-12-09 UTC" "2003-12-10 UTC" "2003-12-11 UTC" "2003-12-12 UTC"
</code></pre>
<p>whose structure is:</p>
<pre><code>str(x)
POSIXct[1:10], format: "2003-12-01" "2003-12-02" "2003-12-03" "2003-12-04" "2003-12-05" "2003-12-08" "2003-12-09 ..."
</code></pre>
<p>Anyway, when I use <code>dput</code>, I obtain:</p>
<pre><code>structure(c(1070236800, 1070323200, 1070409600, 1070496000, 1070582400,
1070841600, 1070928000, 1071014400, 1071100800, 1071187200), class = c("POSIXct",
"POSIXt"), tzone = "UTC")
</code></pre>
| [
{
"answer_id": 74360102,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 3,
"selected": true,
"text": "POSIXct"
},
{
"answer_id": 74360111,
"author": "cgvoller",
"author_id": 17144974,
"author_profile": "https://Stackoverflow.com/users/17144974",
"pm_score": 2,
"selected": false,
"text": "POSIXct"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1306892/"
] |
74,359,758 | <p>I have two databases:</p>
<pre><code>DB1:
SCHEMA1:
-- TABLE1
-- TABLE2
DB2:
SCHEMA2:
</code></pre>
<p>I want to move <code>TABLE1</code> to <code>DB2::SCHEMA2</code></p>
<p>i.e</p>
<pre><code>DB1:
SCHEMA1:
-- TABLE2
DB2:
SCHEMA2:
-- TABLE1
</code></pre>
<p>also note in future i may delete <code>DB1</code></p>
| [
{
"answer_id": 74360102,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 3,
"selected": true,
"text": "POSIXct"
},
{
"answer_id": 74360111,
"author": "cgvoller",
"author_id": 17144974,
"author_profile": "https://Stackoverflow.com/users/17144974",
"pm_score": 2,
"selected": false,
"text": "POSIXct"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2897115/"
] |
74,359,760 | <p>I have a list of dictionaries (with multiple key, value pairs) in python, and I'm trying to make each dictionary into a list, where each key,value pair is also it's own list. For example:
<code>list = [{a: 1, b: 2, c: 3}, {d: 4, e: 5, f: 6}, {g: 7,h: 8,i: 9}]</code>
What i want it to output is:
<code>newlist = [[[a, 1], [b, 2], [c, 3]], [[d, 4][e, 5],[f, 6]], [[g, 7],[h, 8],[i, 9]]]</code></p>
<p>The only method i've found only lets me have a list where key, value pairs from different dictionaries are in one large list, but i need each dictionary to be a different list.</p>
| [
{
"answer_id": 74360102,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 3,
"selected": true,
"text": "POSIXct"
},
{
"answer_id": 74360111,
"author": "cgvoller",
"author_id": 17144974,
"author_profile": "https://Stackoverflow.com/users/17144974",
"pm_score": 2,
"selected": false,
"text": "POSIXct"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,359,778 | <p>How do I print the number of rows dropped while executing the following code in python:</p>
<pre><code>df.dropna(inplace = True)
</code></pre>
| [
{
"answer_id": 74360102,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 3,
"selected": true,
"text": "POSIXct"
},
{
"answer_id": 74360111,
"author": "cgvoller",
"author_id": 17144974,
"author_profile": "https://Stackoverflow.com/users/17144974",
"pm_score": 2,
"selected": false,
"text": "POSIXct"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19305713/"
] |
74,359,797 | <p>Hi I have a function that assigns values from 0 to the size of ELEMENT_COUNT
How can I improve the performance of this function?</p>
<pre><code>constexpr size_t ELEMENT_COUNT = 1000 * 10000;
std::vector<uint64_t> fill_vector(size_t elementCount) {
std::vector<uint64_t> vec(elementCount);
for (size_t i = 0; i < elementCount; i++) {
vec.push_back(i);
}
return vec;
}
</code></pre>
<p>I thought about using basic assigment instead of using push_back(i):</p>
<pre><code>std::vector<uint64_t> fill_vector(size_t elementCount) {
std::vector<uint64_t> vec(elementCount);
for (size_t i = 0; i < elementCount; i++) {
vec[i] = i;
}
return vec;
}
</code></pre>
<p>but does anyone have an idea for a better improvement?</p>
| [
{
"answer_id": 74360284,
"author": "Ayxan Haqverdili",
"author_id": 10147399,
"author_profile": "https://Stackoverflow.com/users/10147399",
"pm_score": 1,
"selected": false,
"text": "#include <cstdint>\n#include <numeric>\n#include <vector>\n\nauto fill_vector(std::uint64_t elementCount) {\n std::vector<std::uint64_t> vec(elementCount);\n\n std::iota(vec.begin(), vec.end(), std::uint64_t{});\n return vec;\n}\n"
},
{
"answer_id": 74360359,
"author": "Saiel",
"author_id": 20449189,
"author_profile": "https://Stackoverflow.com/users/20449189",
"pm_score": 0,
"selected": false,
"text": "elementCount"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20230337/"
] |
74,359,802 | <p>I am a newbie and I was just experimenting creating a table. I wanted to use different background colours on the table heading cells (one colour on each oh the the three). So I gave them different classes, but it does not seem to work? all I can get is the three of them the same colour by targeting </p>
<p>Can someone help me please? This is the HTML</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code> table {
font-family: sans-serif;
}
thead th {
text-align: center;
font-weight: bold;
font-size: 30px;
background-color: yellow;
}
table,
th,
td {
padding: 30px;
border: 1px solid black;
border-collapse: collapse;
width: 700px;
background-color: pink;
.name {
background-color: orange;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Merriweather:ital@0;1&family=Work+Sans:wght@400;500;800&display=swap" rel="stylesheet">
<h1>My cheatsheet</h1>
<p>Hope this is of help.</p>
<table>
<thead>
<th class="tag">tag</th>
<th class="name">name</th>
<th class="description">description</th>
</thead>
<tbody>
<tr>
<td> &lt;table&gt; </td>
<td>table</td>
<td>The wrapper element for all HTML tables.</td>
</tr>
<tr>
<td> &lt;thead&gt; </td>
<td>table head</td>
<td>The set of rows defining the column headers in a table.</td>
</tr>
</tbody>
</table></code></pre>
</div>
</div>
</p>
<p>Thanks :)</p>
| [
{
"answer_id": 74359877,
"author": "HmBloqued",
"author_id": 17183809,
"author_profile": "https://Stackoverflow.com/users/17183809",
"pm_score": 2,
"selected": false,
"text": "}"
},
{
"answer_id": 74359881,
"author": "Vinoth Manoharan",
"author_id": 18966068,
"author_profile": "https://Stackoverflow.com/users/18966068",
"pm_score": 0,
"selected": false,
"text": "<table style=\"background-color:#FFFFE0;\">\n<tr style=\"background-color:#BDB76B;color:#ffffff;\">\n<th>Table Header</th><th>Table Header</th>\n</tr>\n<tr>\n<td>Table cell 1</td><td>Table cell 2</td>\n</tr>\n<tr>\n<td>Table cell 3</td><td style=\"background-color:#ff0000;\">Table cell 4</td>\n</tr>\n</table>\n"
},
{
"answer_id": 74359903,
"author": "David Thomas",
"author_id": 82548,
"author_profile": "https://Stackoverflow.com/users/82548",
"pm_score": 1,
"selected": false,
"text": "<th>"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20448942/"
] |
74,359,816 | <p>I have a python list as follows:-</p>
<pre><code>['cat', 'doc_1.txt']
['cat', 'doc_4.txt']
['dog', 'doc_5.txt']
['mouse', 'doc_6.txt']
['horse', 'doc_7.txt']
</code></pre>
<p>I need to quickly find out boolean answer to queries like</p>
<pre><code> "Does cat exist in doc_1.txt" answer = yes
"Does mouse exist in doc_1.txt" answer = no
</code></pre>
<p>I have implemented it through nested loops which checks each document against each term and populate another list. It serves the purpose but thats very primitive way.</p>
| [
{
"answer_id": 74359971,
"author": "Claudio",
"author_id": 7711283,
"author_profile": "https://Stackoverflow.com/users/7711283",
"pm_score": 2,
"selected": true,
"text": "in"
},
{
"answer_id": 74360097,
"author": "umair mughal",
"author_id": 8092247,
"author_profile": "https://Stackoverflow.com/users/8092247",
"pm_score": -1,
"selected": false,
"text": "lst = [['cat', 'doc1.txt'], ['dog', 'doc2.txt']]\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1028289/"
] |
74,359,819 | <p>I'm converting a Memory steam to a byte array and encoding it <code>ToBase64String</code></p>
<pre><code> return Ok(Convert.ToBase64String(memoryStream.ToArray()));
</code></pre>
<p>On the client side i'm doing the following to display the image</p>
<pre><code> var response = await client.GetAsync(Navigator.BaseUri+ "upload/process");
if (response.IsSuccessStatusCode)
{
imagesrc = string.Format("data:image/jpeg;base64,{0}", response.Content.ToString());
StateHasChanged();
}
</code></pre>
<p>But the image is not getting displayed, it gives the following error</p>
<pre><code>Failed to load resource: net::ERR_INVALID_URL
</code></pre>
<p>Update:
This how the image is set</p>
<pre><code><img src="@imagesrc" width="300px" height="300px" style="border: 1px solid #4f4f50; border-radius: 1px" />
</code></pre>
| [
{
"answer_id": 74359971,
"author": "Claudio",
"author_id": 7711283,
"author_profile": "https://Stackoverflow.com/users/7711283",
"pm_score": 2,
"selected": true,
"text": "in"
},
{
"answer_id": 74360097,
"author": "umair mughal",
"author_id": 8092247,
"author_profile": "https://Stackoverflow.com/users/8092247",
"pm_score": -1,
"selected": false,
"text": "lst = [['cat', 'doc1.txt'], ['dog', 'doc2.txt']]\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/848968/"
] |
74,359,857 | <p>I want to set up a VBA so that for any document based on a template hidden bookmarks are deleted prior to the document closing. We publish documents on our website. They are written as Word and an API converts them to html. If there are hidden bookmarks they appear as links on the website (the hidden bookmarks convert to html anchors). Currently we remove the bookmarks manual prior to the API, but this is time consuming (we publish 1000s of documents a year) and ineffective (people forget).</p>
<p>I found VBA to remove hidden bookmarks which works and tried to add DocumentBeforeClose as the trigger. But it doesn't work:</p>
<pre><code>Private Sub DocumentBeforeClose(cancel As Boolean)
Dim nBK As Long
With ActiveDocument
For nBK = .Bookmarks.Count To 1 Step -1
If LCase(Left(.Bookmarks(nBK).Name, 3)) = "_hl" Then
.Bookmarks(nBK).Delete
End If
Next nBK
End With
ActiveDocument.Save
End Sub
</code></pre>
<p>I went through Visual Basic Window, Normal, Microsoft Word Objects, ThisDocument.</p>
<p>Nothing happens, the hidden bookmarks remain if I close and re-open the document.</p>
| [
{
"answer_id": 74359971,
"author": "Claudio",
"author_id": 7711283,
"author_profile": "https://Stackoverflow.com/users/7711283",
"pm_score": 2,
"selected": true,
"text": "in"
},
{
"answer_id": 74360097,
"author": "umair mughal",
"author_id": 8092247,
"author_profile": "https://Stackoverflow.com/users/8092247",
"pm_score": -1,
"selected": false,
"text": "lst = [['cat', 'doc1.txt'], ['dog', 'doc2.txt']]\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20448932/"
] |
74,359,858 | <p>This question is about Azure Pipelines, but let me start by contrasting it: In GitHub Actions, as long as a workflow uses the provided <code>$GITHUB_TOKEN</code> variable to authenticate and push changes back to the repository in which the workflow is running, <strong>this will not trigger more workflows</strong>.</p>
<p>This can be very important in some scenarios where part of the workflow functionality is to make changes to the repository in which it runs, and one workflow could otherwise set off a chain reaction of workflows, all triggering each other. Our scenario fits this description, and I assume GitHub built Actions this way for this very reason.</p>
<p>I have been trying to achieve the same thing in Azure Pipelines, but I cannot figure out how, so I would be thankful for any guidance.</p>
<p>Azure Pipelines has the equivalent of the <code>$GITHUB_TOKEN</code> variable — in Azure Pipelines it's called <code>$(System.AccessToken)</code>, and you can use this token at the Git level to authenticate against the repository, and interact with the repository subject to any permissions granted to the service account running your pipeline.</p>
<p>But using this provided token does not suppress CI triggers unfortunately.</p>
<p>I have enabled this setting in hopes that it would add this functionality to the job access token:</p>
<p><a href="https://i.stack.imgur.com/mqFK5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqFK5.png" alt="enter image description here" /></a></p>
<p>But unfortunately it has no effect on this aspect; pushing using the <code>$(System.AccessToken)</code> variable still triggers any CI triggers matching the contents of the push.</p>
<p>I know that one can opt out of CI triggers using certain "tags" in commit messages, but this is not a feasible option in our case because the commits are created by external tooling and we do not have full control over the commit message. (And besides those tags in every commit message would pollute the history.)</p>
<p>What am I missing? Is this really not possible to achieve with Azure Pipelines?</p>
| [
{
"answer_id": 74371335,
"author": "Dou Xu-MSFT",
"author_id": 20288521,
"author_profile": "https://Stackoverflow.com/users/20288521",
"pm_score": 0,
"selected": false,
"text": "#condition: and(succeeded(),ne(variables['Build.Reason'], 'ResourceTrigger'))\ncondition:and(failed(),in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'))\n"
},
{
"answer_id": 74376843,
"author": "Vince Bowdren",
"author_id": 174843,
"author_profile": "https://Stackoverflow.com/users/174843",
"pm_score": 1,
"selected": false,
"text": "[skip ci]"
},
{
"answer_id": 74599021,
"author": "jessehouwing",
"author_id": 736079,
"author_profile": "https://Stackoverflow.com/users/736079",
"pm_score": 0,
"selected": false,
"text": "stage"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6275530/"
] |
74,359,918 | <p>My question about the <code>OnResume()</code> method which is part of the Activity's lifecycle.</p>
<p>I know that after the <code>OnStart()</code> method the <code>OnResume()</code> will be called and also if the application goes in background and then comes on front again <code>OnResume()</code> will be executed, but is there any case that some OS system might call this method when the device is rotating or something like that or maybe when they put the device on sleep and then open it again?</p>
<p>I've tested it on some devices to rotate the screen while the application is running and it looks like the <code>OnResume()</code> is not executing but obviously I can't test all the devices out there.</p>
| [
{
"answer_id": 74370691,
"author": "Guangyu Bai - MSFT",
"author_id": 19335715,
"author_profile": "https://Stackoverflow.com/users/19335715",
"pm_score": 0,
"selected": false,
"text": "OnResume()"
},
{
"answer_id": 74443393,
"author": "David Wasser",
"author_id": 769265,
"author_profile": "https://Stackoverflow.com/users/769265",
"pm_score": 2,
"selected": true,
"text": "Activity"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16523060/"
] |
74,359,920 | <p>I am looking at the following video where they use the <code>..</code> operator inside initState()</p>
<p><a href="https://youtu.be/uz4xRnE-UIw?t=117" rel="nofollow noreferrer">https://youtu.be/uz4xRnE-UIw?t=117</a></p>
<p>in my code it does not work!</p>
<p>here is my code:</p>
<pre><code> void initState() {
super.initState();
// select where the video is coming from asset/file/network
_videoPlayerController = VideoPlayerController.asset(asset);
..setListener( ()=> setState(() {})); // error: expected an identifier
..setLooping(true); // error: expected an identifier
..initialize(); // error: expected an identifier
}
</code></pre>
<p><a href="https://i.stack.imgur.com/WVC6O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WVC6O.png" alt="broken operator" /></a></p>
<p><a href="https://i.stack.imgur.com/Fgi6U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fgi6U.png" alt="video image" /></a></p>
<p>what am i doing wrong?</p>
| [
{
"answer_id": 74359951,
"author": "Emre Faruk KOLAÇ",
"author_id": 12040178,
"author_profile": "https://Stackoverflow.com/users/12040178",
"pm_score": 2,
"selected": false,
"text": ";"
},
{
"answer_id": 74359953,
"author": "eamirho3ein",
"author_id": 10306997,
"author_profile": "https://Stackoverflow.com/users/10306997",
"pm_score": 3,
"selected": true,
"text": ";"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17281101/"
] |
74,359,926 | <p>I'm learning reactJS and I started to learn about the state. I did this :</p>
<pre><code>const famille = {
membre1: {
nom: "Steve",
age: 45
},
membre2: {
nom: "Bill",
age: 60
},
membre3: {
nom: "Mark",
age: 40
}
}
function App(props) {
const [membres, setMembres] = useState(famille);
function handleAgeChange(){
let newFamille = famille;
newFamille.membre1.age += 1;
newFamille.membre2.age += 1;
newFamille.membre3.age += 1;
setMembres(newFamille);
console.log(membres)
}
return (
<Fragment>
<div className="App">
<h1>{props.titre}</h1>
<ul>
<Membre name={membres.membre1.nom} age={membres.membre1.age}/>
<Membre name={membres.membre2.nom} age={membres.membre2.age}/>
<Membre name={membres.membre3.nom} age={membres.membre3.age}/>
</ul>
<button onClick={handleAgeChange}>Veillir</button>
</div>
</Fragment>
);
}
</code></pre>
<p>The <code><Member /></code> component only show <code>{name} : {age}</code>
My goal is to add 1 to everyone age when I click on the button. My state is correctly updating but the app isn't and I don't understand why.</p>
| [
{
"answer_id": 74360222,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 2,
"selected": true,
"text": "function handleAgeChange(){\n setMembres({\n membre1: {\n ...membres.membre1,\n age: membres.membre1.age + 1,\n },\n membre2: {\n ...membres.membre2,\n age: membres.membre2.age + 1,\n },\n membre3: {\n ...membres.membre3,\n age: membres.membre3.age + 1,\n }\n });\n console.log(membres)\n}\n"
},
{
"answer_id": 74360446,
"author": "Andy",
"author_id": 1377002,
"author_profile": "https://Stackoverflow.com/users/1377002",
"pm_score": 2,
"selected": false,
"text": "let newFamille = famille"
},
{
"answer_id": 74361635,
"author": "Wawan4137",
"author_id": 17397303,
"author_profile": "https://Stackoverflow.com/users/17397303",
"pm_score": 0,
"selected": false,
"text": "const famille = {...membres};\nfamille.membre1.age += 1;\nfamille.membre2.age += 1;\nfamille.membre3.age += 1;\nsetMembres(famille);\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17397303/"
] |
74,359,990 | <p>I have a problem with my background body image. When I put a color on my different sections, the background image disapear I suppose behind the color and I don't know why.</p>
<p>If I put a background-color on the body it works but I want a different color on each section of my page.</p>
<p>Here is the wireframe : [Wireframe][1] And for now I have this : [Project][2]</p>
<p>Here is a part of the code.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction(tag) {
$("#cssmenu a.active").removeClass("active"); //remove previous li active class
$(tag).closest("a").addClass("active");
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code> html, body {
height: 100%;
margin: 0;
}
body {
background-image: url("https://montaigne-energie.fr/wp-content/uploads/2022/11/phare_blan3.svg");
background-position: 50% 2%;
background-repeat: no-repeat;
background-size: 140% auto;
background-attachment: local;
}
#home {
background-color: rgba(182, 166, 128, 0.8);
height: 100%;
}
#services {
background-color: rgb(33, 59, 82,.8);
height: 100%;
}
#valeurs {
background-color: rgba(182, 166, 128, 0.8);
height: 100%;
}
#missions {
background-color: rgb(33, 59, 82,.8);
height: 100%;
}
#section5 {
background-color: rgba(182, 166, 128, 0.8);
height: 100%;
}
#footer {
background-color: rgb(33, 59, 82,.8);
height: 100%;
}
.section{
min-height: 100%;
}
nav {
position: fixed;
top: 35%;
right: 2%;
bottom: auto;
z-index: 10;
}
.lader ul {
list-style: none;
padding: 0;
}
.lader li {
padding: 15px 0;
}
.lader span {
display: inline-block;
position: relative;
}
.circle {
height: 13px;
width: 13px;
left: 0;
border-radius: 50%;
border: 2px solid white;
background-color: none;
}
.lader a.active span {
background-color: white;
}
nav a:hover span {
background-color: #fff;
transition: 300ms;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="section" id="home">
<nav class="lader" id="cssmenu">
<ul>
<li>
<a href="#home" class="active" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
<li>
<a href="#services" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
<li>
<a href="#valeurs" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
<li>
<a href="#missions" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
<li>
<a href="#section5" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
<li>
<a href="#footer" onclick="myFunction(this)">
<span class="circle"></span>
</a>
</li>
</ul>
</nav>
</div>
<div class="section" id="services"></div>
<div class="section" id="valeurs"></div>
<div class="section" id="missions"></div>
<div class="section" id="sections5"></div>
<div class="section" id="footer"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74360068,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 1,
"selected": false,
"text": "background-color: rgba(21, 45, 52, 0.3)"
},
{
"answer_id": 74360142,
"author": "Jason Tran",
"author_id": 18362279,
"author_profile": "https://Stackoverflow.com/users/18362279",
"pm_score": 0,
"selected": false,
"text": "div{\n min-height: 100px;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359990",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20442643/"
] |
74,359,996 | <p>I'm configuring an active-active WSO2 active-active cluster where everything works as expected. However it recently started logging this continuously without any change in its configuration:</p>
<pre><code>...
INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = / HEALTH CHECK URL = /
INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = / HEALTH CHECK URL = /
INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = / HEALTH CHECK URL = /
INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = / HEALTH CHECK URL = /
...
</code></pre>
<p>What could be the reason?</p>
| [
{
"answer_id": 74360068,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 1,
"selected": false,
"text": "background-color: rgba(21, 45, 52, 0.3)"
},
{
"answer_id": 74360142,
"author": "Jason Tran",
"author_id": 18362279,
"author_profile": "https://Stackoverflow.com/users/18362279",
"pm_score": 0,
"selected": false,
"text": "div{\n min-height: 100px;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74359996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1729795/"
] |
74,360,011 | <p>I have for example this future function:</p>
<pre><code>Future<void> sayHello() async {
await service.sayHello();
}
</code></pre>
<p>And I want to invoke it on button click</p>
<pre><code>ElevatedButton(
onPressed: () => sayHello(),
child: const Text("Click"),
)
</code></pre>
<p>My question is, should onPressed be async when I want to invoke future function on clicked? Could it be async anyway?</p>
| [
{
"answer_id": 74360068,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 1,
"selected": false,
"text": "background-color: rgba(21, 45, 52, 0.3)"
},
{
"answer_id": 74360142,
"author": "Jason Tran",
"author_id": 18362279,
"author_profile": "https://Stackoverflow.com/users/18362279",
"pm_score": 0,
"selected": false,
"text": "div{\n min-height: 100px;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19531945/"
] |
74,360,018 | <p>I'm trying to vlookup data from a sheet with two tabs. I know the vlookup will fetch the results from the first search. But desired output, it should look up the value and get the last result.</p>
<p>current vlookup results:
<a href="https://i.stack.imgur.com/hwFmW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hwFmW.png" alt="Current vlookup results" /></a></p>
<p><a href="https://i.stack.imgur.com/My4Vv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/My4Vv.png" alt="Expected output" /></a></p>
<p>Here is the trix for reference of sample data</p>
<p><a href="https://docs.google.com/spreadsheets/d/1WkokpBX59qz33oSbKIKNQ7kNkv4QbNlKUKeBYlK4vy8/edit#gid=0" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1WkokpBX59qz33oSbKIKNQ7kNkv4QbNlKUKeBYlK4vy8/edit#gid=0</a></p>
<p>Any inputs on this is much appreciated.</p>
<p>Thanks!</p>
| [
{
"answer_id": 74360068,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 1,
"selected": false,
"text": "background-color: rgba(21, 45, 52, 0.3)"
},
{
"answer_id": 74360142,
"author": "Jason Tran",
"author_id": 18362279,
"author_profile": "https://Stackoverflow.com/users/18362279",
"pm_score": 0,
"selected": false,
"text": "div{\n min-height: 100px;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19264018/"
] |
74,360,074 | <pre class="lang-java prettyprint-override"><code>import java.io.*;
class GFG {
public static void main (String[] args) {
int s=4;
int k=3;
int a=s^k;
int b=a & -a;
System.out.println(b);
}
}
</code></pre>
<ul>
<li></li>
</ul>
<p>I have compiled the above code it gives 1 as the output.
But I can't get that how it is compiling.
if I do XOR OPERATION between s and k it will give 111(7).
but don't know how <code>b=a & -a </code> working please explain.*</p>
| [
{
"answer_id": 74360068,
"author": "何聊生",
"author_id": 5978648,
"author_profile": "https://Stackoverflow.com/users/5978648",
"pm_score": 1,
"selected": false,
"text": "background-color: rgba(21, 45, 52, 0.3)"
},
{
"answer_id": 74360142,
"author": "Jason Tran",
"author_id": 18362279,
"author_profile": "https://Stackoverflow.com/users/18362279",
"pm_score": 0,
"selected": false,
"text": "div{\n min-height: 100px;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20424083/"
] |
74,360,110 | <p>I'm working on a hashing function for a map[string]interface{}</p>
<p>Most of the hashing libs required []byte as input to compute the hash.</p>
<p>I tried to Marshal using the json.Marshal for simple maps it works correct but when i add some complexity and shuffled the items then json.Marshal fails to give me a consistent byte array output</p>
<pre><code>package main
import (
"encoding/json"
"fmt"
)
func main() {
data := map[string]interface{}{
"id": "124",
"name": "name",
"count": 123456,
"sites": []map[string]interface{}{
{
"name": "123445",
"count": 234324,
"id": "wersfs",
},
{
"id": "sadcacasca",
"name": "sdvcscds",
"count": 22,
},
},
"list": []int{5, 324, 123, 123, 123, 14, 34, 52, 3},
}
data1 := map[string]interface{}{
"name": "name",
"id": "124",
"sites": []map[string]interface{}{
{
"id": "sadcacasca",
"count": 22,
"name": "sdvcscds",
},
{
"count": 234324,
"name": "123445",
"id": "wersfs",
},
},
"count": 123456,
"list": []int{123, 14, 34, 52, 3, 5, 324, 123, 123},
}
jsonStr, _ := json.Marshal(data)
jsonStr1, _ := json.Marshal(data1)
fmt.Println(jsonStr)
fmt.Println(jsonStr1)
for i := 0; i < len(jsonStr); i++ {
if jsonStr[i] != jsonStr1[i] {
fmt.Println("Byte arrays not equal")
}
}
}
</code></pre>
<p>This is what I have tried and it fails to give me a consistent output.<br />
Moreover i was thinking to write a function which will do the sorting of the map and values as well, but then got stuck on how do I sort the</p>
<pre><code>"sites": []map[string]interface{}
</code></pre>
<p>I tried json.Marshal and also sorting the map but got stuck</p>
| [
{
"answer_id": 74362260,
"author": "Pak Uula",
"author_id": 9047589,
"author_profile": "https://Stackoverflow.com/users/9047589",
"pm_score": 1,
"selected": false,
"text": "[123, 14, 34, 52, 3, 5, 324, 123, 123]"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20261665/"
] |
74,360,130 | <p>--for number divisible by 15 we can get it easily</p>
<pre><code>take 10 [x | x <- [1..] , x `mod` 15 == 0 ]
</code></pre>
<p>--but for all how do I use the all option</p>
<pre><code>take 10 [x | x <- [1..] , x `mod` [2..15] == 0 ]
take 10 [x | x <- [1..] , all x `mod` [2..15] == 0 ]
</code></pre>
<p>I want to understand how to use all in this particular case.</p>
<p>I have read Haskell documentation but I am new to this language coming from Python so I am unable to figure the logic.</p>
| [
{
"answer_id": 74362260,
"author": "Pak Uula",
"author_id": 9047589,
"author_profile": "https://Stackoverflow.com/users/9047589",
"pm_score": 1,
"selected": false,
"text": "[123, 14, 34, 52, 3, 5, 324, 123, 123]"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13353190/"
] |
74,360,169 | <p>Can someone give a simple case where we will immidiately appreciate the importance of disposing viewmodels and at the same time know the repercussions if we don't?
My App is running fine without all these disposing stuff, I really just don't understand the vague "prevent memory leak" stuff.</p>
| [
{
"answer_id": 74362260,
"author": "Pak Uula",
"author_id": 9047589,
"author_profile": "https://Stackoverflow.com/users/9047589",
"pm_score": 1,
"selected": false,
"text": "[123, 14, 34, 52, 3, 5, 324, 123, 123]"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10494346/"
] |
74,360,196 | <p>I have the following two tables:</p>
<pre class="lang-sql prettyprint-override"><code>CREATE TABLE segments(session_id INT, segment_id INT,
length DOUBLE PRECISION, movement BOOLEAN);
INSERT INTO segments (session_id, segment_id, length, movement)
VALUES (49,0,0,'f'),(49,1,180851,'t'),(49,2,1.31082,'f'),(49,3,1580.41,'t'),
(49,4,1.0059,'f'),(49,5,4.47451,'t'),(49,6,1.69973,'f'),(55,0,2.76848,'f'),
(55,1,2.60235,'t'),(55,2,3.807,'f'),(55,3,2.78887,'t'),(55,4,8.47029,'f');
CREATE TABLE trips (trip_id INT, session_ids INT[], distance DOUBLE PRECISION);
INSERT INTO trips (trip_id, session_ids, distance)
VALUES (153,'{49}', 183245.960),(155,'{55}',109.035),
(156,'{59,60}',909.870);
</code></pre>
<p>Representing user trips and corresponding trip segments.</p>
<p>In the <code>segments</code> table column <code>movement</code> shows whether the user is moving <code>t</code>; or stopped <code>f</code>. So I want to count the number of stops (not moving segments) for each trip in my database.</p>
<p>Expected results:</p>
<pre><code>trip_id | distance | stop_count
--------+----------+-----------
153 |183245.96 | 4
155 | 109.035 | 3
</code></pre>
<p><strong>NB:</strong> <a href="https://dbfiddle.uk/yMBPyvrW" rel="nofollow noreferrer">db<>fiddle</a></p>
| [
{
"answer_id": 74362260,
"author": "Pak Uula",
"author_id": 9047589,
"author_profile": "https://Stackoverflow.com/users/9047589",
"pm_score": 1,
"selected": false,
"text": "[123, 14, 34, 52, 3, 5, 324, 123, 123]"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17487457/"
] |
74,360,203 | <p>I'm currently in need for a better method for doing some calculations in a quite tedious fashion. And I'd like to change that, due to some of the dataframes that will be processed can have a large size.</p>
<p>I would like to do some comparisons for each row in one dataframe to each row in another dataframe. This by nature scales at x^2, but I was wondering if there were any good way of doing this?</p>
<pre class="lang-python prettyprint-override"><code>df1 = pd.DataFrame([
{"value": 1, "timestamp": "1970-01-01T00:00:00z"},
{"value": 2, "timestamp": "1970-01-01T00:00:00z"},
...
])
df2 = pd.DataFrame([
{"value": 3, "timestamp": "1970-01-01T00:00:03z"},
{"value": 4, "timestamp": "1970-01-01T00:00:04z"},
...
])
</code></pre>
<p>With these two dataframes, I would like to be able to make calculations for 1-3, 1-4, 2-3 and 2-4</p>
<p>The calculations that needs to take place, involve comparing the columns for each 'row-pair'.My first method of doing this was just with the use of itertools' module function product. I.E.</p>
<pre class="lang-python prettyprint-override"><code>for (_,x), (_,y) in product(X, Y):
func(x, y)
</code></pre>
<p>This of course doesn't scale so nicely. In desperation I've come up with a new 'solution' that I can't imagine is more scalable</p>
<pre class="lang-python prettyprint-override"><code>df1.apply(lambda x: df2.apply(lambda y: func(x, y), axis=1), axis=1)
</code></pre>
<p>This also doesn't scale well, in fact in the tests that I've done, it's actually slower.</p>
<p>This the main idea of what I'd like to do, and certainly not the optimal way of doing it..</p>
<pre class="lang-python prettyprint-override"><code>df1 = pd.DataFrame([
{"value": 1, "timestamp": "1970-01-01T00:00:01z"},
{"value": 2, "timestamp": "1970-01-01T00:00:02z"},
...
])
df2 = pd.DataFrame([
{"value": 3, "timestamp": "1970-01-01T00:00:03z"},
{"value": 4, "timestamp": "1970-01-01T00:00:04z"},
...
])
def func(x, y, lst):
lst.append(x["value"] + y["value"])
results = []
df1.apply(lambda x: df2.apply(lambda y: func(x, y, results), axis=1), axis=1)
print(results) # [4, 5, 5, 6, ...]
</code></pre>
<p>Edit:
In response to the comment Panda Kim came with. I've come up with a new method. Unfortunately it doesn't seem to be any faster though.</p>
<p><strong>'New method'</strong></p>
<pre class="lang-python prettyprint-override"><code>def apply_func(row, df_dict):
start = row["ts_min_x"] - row["ts_min_y"]
end = row["ts_max_x"] - row["ts_max_y"]
start_ts = max([row["ts_min_x"], row["ts_min_y"]])
end_ts = min([row["ts_max_x"], row["ts_max_y"]])
duration = (end_ts - start_ts).total_seconds()
if row["id_x"] not in df_dict:
df_dict[row["id_x"]] = {}
if row["id_y"] not in df_dict.get(row["id_x"]):
df_dict[row["id_x"]][row["id_y"]] = []
df_dict[row["id_x"]][row["id_y"]].append(
(start, end, start_ts, duration)
)
</code></pre>
<pre class="lang-python prettyprint-override"><code>df1 = pd.DataFrame([
{"id": 1, "active": True, "ts_min": 1, "ts_max": 10},
{"id": 2, "active": False, "ts_min": 10, "ts_max": 12},
{"id": 3, "active": True, "ts_min": 12, "ts_max": 19},
])
df2 = pd.DataFrame([
{"id": 4, "active": True, "ts_min": 4, "ts_max": 9},
{"id": 5, "active": True, "ts_min": 9, "ts_max": 16},
{"id": 6, "active": False, "ts_min": 16, "ts_max": 19},
])
df_dict = {}
merged = df1.merge(df2, how="cross")
merged.apply(lambda x: apply_func(x, df_dict), axis=1)
res_df = pd.DataFrame(df_dict)
res_df = res_df.dropna(axis=1, how="all").dropna(axis=0, how="all")
</code></pre>
<p>This is the method I came up with. Is it possible to do what's being done here, but in a faster way?</p>
| [
{
"answer_id": 74360431,
"author": "Raibek",
"author_id": 11040577,
"author_profile": "https://Stackoverflow.com/users/11040577",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nnp.add.outer(df1.values, df2.values).flatten()\n\narray([4, 5, 5, 6], dtype=int64)\n"
},
{
"answer_id": 74360436,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": true,
"text": "merge"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19887308/"
] |
74,360,214 | <p>Hi i have the following tables in a database</p>
<p><a href="https://i.stack.imgur.com/AO5bw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AO5bw.png" alt="enter image description here" /></a></p>
<p>i am trying to move table4 from schema1 to schema2</p>
<p>I am trying</p>
<pre><code>alter table if exists "SANTHOSH_TESTING"."SCHEMA1"."table4" RENAME TO "SANTHOSH_TESTING"."SCHEMA2"."table4";
</code></pre>
<p>it says</p>
<pre><code>Statement executed successfully.
</code></pre>
<p>but nothing happens (i mean the table4 is still in schema1.)</p>
| [
{
"answer_id": 74360431,
"author": "Raibek",
"author_id": 11040577,
"author_profile": "https://Stackoverflow.com/users/11040577",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nnp.add.outer(df1.values, df2.values).flatten()\n\narray([4, 5, 5, 6], dtype=int64)\n"
},
{
"answer_id": 74360436,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": true,
"text": "merge"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2897115/"
] |
74,360,228 | <p>*Here is my code *
I want get ühole number</p>
<pre><code>from time import time
import math
start=time()
total_time= 30
while time!=0:
move=input('Chess move:')
if move !='off':
print(start)
remaining_time=math.floor(total_time-start)
print('Remaninig time:',remaining_time)
else:
end=time()
break
</code></pre>
<p><em>Here is result</em></p>
<pre><code>Chess move:
>>> f2-f4
1667907784.8287
Remaninig time: -1667907755
Chess move:
>>> off
</code></pre>
<p>But I want result like this:</p>
<p><a href="https://i.stack.imgur.com/rqvDv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqvDv.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74360431,
"author": "Raibek",
"author_id": 11040577,
"author_profile": "https://Stackoverflow.com/users/11040577",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nnp.add.outer(df1.values, df2.values).flatten()\n\narray([4, 5, 5, 6], dtype=int64)\n"
},
{
"answer_id": 74360436,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": true,
"text": "merge"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20448356/"
] |
74,360,230 | <p>New to react/typescript. I am trying to create a function with a typscripted param.</p>
<p>example:</p>
<pre><code>export function get_prod(category: string) { ...}
</code></pre>
<p>The problem is I have 2 product scenarios. One can have an optional category, the other type requires a category to only load products from that category but otherwise the function is almost identical.</p>
<p>I wanted to do something like this:</p>
<pre><code>if category = 'ebook' {
arg = 'category: string'
} else
arg = 'category?: string'
}
export function get_prod(arg) { ...}
</code></pre>
<p>What's the best way to handle this?</p>
| [
{
"answer_id": 74360431,
"author": "Raibek",
"author_id": 11040577,
"author_profile": "https://Stackoverflow.com/users/11040577",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nnp.add.outer(df1.values, df2.values).flatten()\n\narray([4, 5, 5, 6], dtype=int64)\n"
},
{
"answer_id": 74360436,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": true,
"text": "merge"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1547410/"
] |
74,360,245 | <p>Good day to all!</p>
<p>Faced a problem. I’m not very good with mathematics, but nevertheless, it is necessary for the program to select 2 submatrices (subMatrixA, subMatrixB ) from the matrix (w) according to the following example:</p>
<pre><code> // main matrix
final w = [
[0, 0.6, 0.3, 0.3, 0.5, 0.5],
[0.9, 0, 0.7, 0.8, 0.2, 0.5],
[0.2, 0.8, 0, 0.4, 0.6, 0.3],
[0.1, 0.7, 0.6, 0, 0.7, 0.2],
[0.9, 0.8, 0.5, 0.3, 0, 0.7],
[0.8, 0.6, 0.3, 0.7, 0.7, 0],
];
// a - array of indexes in w matrix (rows and columns)
function selection(a) {...} // need an algorithm
// call function with algorithm
selection([0, 1]) // which means - 0 and 1 line
// result
subMatrixA =
[
[0, 0.6]
[0.9, 0 ]
]
subMatrixB =
[
[0.3, 0.3, 0.5, 0.5]
[0.7, 0.8, 0.2, 0.5]
]
</code></pre>
<p>How I can do it?
I hope for your help, thanks.</p>
<p>I tried to write code an algorithm, but i very bad in algorithms and math...</p>
| [
{
"answer_id": 74360431,
"author": "Raibek",
"author_id": 11040577,
"author_profile": "https://Stackoverflow.com/users/11040577",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nnp.add.outer(df1.values, df2.values).flatten()\n\narray([4, 5, 5, 6], dtype=int64)\n"
},
{
"answer_id": 74360436,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": true,
"text": "merge"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19773247/"
] |
74,360,246 | <p>Can we do that? Like</p>
<pre><code>example.add();
</code></pre>
| [
{
"answer_id": 74360292,
"author": "Quentin",
"author_id": 19068,
"author_profile": "https://Stackoverflow.com/users/19068",
"pm_score": 0,
"selected": false,
"text": "a == 3"
},
{
"answer_id": 74360306,
"author": "jessica-98",
"author_id": 20261328,
"author_profile": "https://Stackoverflow.com/users/20261328",
"pm_score": 1,
"selected": false,
"text": "const validate = (newVal) =>\n a === newVal ? a : a = newVal\n\nvar a = 2;\nvalidate(3); //It turns \"a\" into 3;\nconsole.log(a)"
},
{
"answer_id": 74360340,
"author": "M.Lima",
"author_id": 6400309,
"author_profile": "https://Stackoverflow.com/users/6400309",
"pm_score": 1,
"selected": true,
"text": "var a = 2;\nfunction validate(variable, conditional) {\n if (variable != conditional) return conditional\n}; \n\na = validate(a, 3)\nconsole.log(a)"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449169/"
] |
74,360,262 | <p>I get a disk full error while running a Model training job using Azure ML SDK launched from Azure DevOps. I created a custom environment inside the Azure ML Workspace and used it.</p>
<p>I am using azure CLI tasks in Azure DevOps to launch these training jobs. How can I resolve the disk full issue?</p>
<p>Error Message shown in the DevOps Training Task:</p>
<pre><code>"error": {
"code": "UserError",
"message": "{\"Compliant\":\"Disk full while running job. Please consider reducing amount of data accessed, or upgrading VM SKU. Total space: 14045 MB, available space: 1103 MB.\"}\n{\n \"code\": \"DiskFullError\",\n \"target\": \"\",\n \"category\": \"UserError\",\n \"error_details\": []\n}",
"messageParameters": {},
"details": []
},
</code></pre>
<p>The .runconfig file for the training job:</p>
<pre><code> framework: Python
script: cnn_training.py
communicator: None
autoPrepareEnvironment: true
maxRunDurationSeconds:
nodeCount: 1
environment:
name: cnn_training
python:
userManagedDependencies: true
interpreterPath: python
docker:
enabled: true
baseImage: 54646eeace594cf19143dad3c7f31661.azurecr.io/azureml/azureml_b17300b63a1c2abb86b2e774835153ee
sharedVolumes: true
gpuSupport: false
shmSize: 2g
arguments: []
history:
outputCollection: true
snapshotProject: true
directoriesToWatch:
- logs
dataReferences:
workspaceblobstore:
dataStoreName: workspaceblobstore
pathOnDataStore: dataname
mode: download
overwrite: true
pathOnCompute:
</code></pre>
<p>Is there an additional configuration to be done for the disk full issue? Any Changes to be made in the .runconfig file?</p>
| [
{
"answer_id": 74369287,
"author": "Ceeno Qi-MSFT",
"author_id": 18361074,
"author_profile": "https://Stackoverflow.com/users/18361074",
"pm_score": 1,
"selected": false,
"text": "Disk full while running job. Please consider reducing amount of data accessed, or upgrading VM SKU. Total space: 14045 MB, available space: 1103 MB."
},
{
"answer_id": 74511674,
"author": "i0x539",
"author_id": 1406532,
"author_profile": "https://Stackoverflow.com/users/1406532",
"pm_score": 0,
"selected": false,
"text": "shmSize: 2g"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8863398/"
] |
74,360,270 | <p>Currently I have a problem where I need to install all contents of a github repository (<a href="https://github.com/reversinglabs/reversinglabs-yara-rules" rel="nofollow noreferrer">https://github.com/reversinglabs/reversinglabs-yara-rules</a>) through code without using git bash or the like.
In this case I need to fully install the yara repository from said github.
Any one knows a way to do it in c,c++,c#,python?</p>
<p>Unfortunately till now I have yet to succeed in any way.</p>
| [
{
"answer_id": 74360528,
"author": "Lasersköld",
"author_id": 3748275,
"author_profile": "https://Stackoverflow.com/users/3748275",
"pm_score": 1,
"selected": false,
"text": "std::system()"
},
{
"answer_id": 74360721,
"author": "Botje",
"author_id": 1548468,
"author_profile": "https://Stackoverflow.com/users/1548468",
"pm_score": 1,
"selected": false,
"text": "curl -o yara-rules.zip https://github.com/reversinglabs/reversinglabs-yara-rules/archive/refs/heads/develop.zip \nunzip yara-rules.zip\n"
},
{
"answer_id": 74677169,
"author": "On3ForA11",
"author_id": 17468106,
"author_profile": "https://Stackoverflow.com/users/17468106",
"pm_score": 0,
"selected": false,
"text": "#Python \nimport os \nurl = input(\"Url: \")\nos.system(\"git clone \" + url)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19728112/"
] |
74,360,336 | <p>I'm struggling on how to generate a <strong>"Differences" Ordered-Dictionary</strong> containing the Different and also New values appearing on a <em>"Modified" Ordered-Dictionary</em> after comparing with a <em>"Reference" Ordered-Dictionary</em>.</p>
<p>EXAMPLE:</p>
<pre><code>#python
from collections import OrderedDict
ref_d = OrderedDict() # REFERENCE Ordered Dictionary
mod_d = OrderedDict() # MODIFIED Ordered Dictionary
dif_d = OrderedDict() # DIFFERENCES Ordered Dictionary (what I'm looking for)
# This is my REFERENCE ordered dictionary with default values
ref_d = {
'shape': 'square',
'color': 'white',
'posxy': '0,0',
'scale': 'small',
'rotxy': '0,0',
'modif': 'no',
'autom': 'no',
'lumin': 'min',
'backg': 'none',
'outpu': 'no'
}
# This is my MODIFIED ordered dictionary, with some different values, and even some NEW key/value pairs
mod_d = {
'shape': 'square',
'color': 'red', # Different <-
'posxy': '0,0',
'scale': 'small',
'rotxy': '0.5,0.5', # Different <-
'modif': 'no',
'autom': 'no',
'varia': 'true', # NEW <-
'lumin': 'max',
'backg': 'none',
'outpu': 'yes', # Different <-
'specm': 'true' # NEW <-
}
# THIS IS WHAT I NEED: a "DIFFERENCES ordered dictionary", where different values and NEW key/values are added in same order
dif_d = {
'color': 'red', # Different <-
'rotxy': '0.5,0.5', # Different <-
'varia': 'true', # NEW <-
'outpu': 'yes', # Different <-
'specm': 'true', # NEW <-
}
</code></pre>
<p>Using:</p>
<pre><code>set0 = set(ref_d.items())
set1 = set(mod_d.items())
dif_d = (set1 - set0)
</code></pre>
<p>I get a valid result, except that it's completely UNORDERED :-(</p>
<p>I suppose it could be something like this (using a dirt non-valid code):</p>
<pre><code>for key, value in mod_d.items():
if key, value != or not in ref_d: # Consider this as 'pseudo-code', it obviously fails...
dif_d.update({key: value})
</code></pre>
<p>But I constantly get an invalid code error...
Any help will be welcome!
THANKS!</p>
| [
{
"answer_id": 74360577,
"author": "milchmannverleih",
"author_id": 11373689,
"author_profile": "https://Stackoverflow.com/users/11373689",
"pm_score": 3,
"selected": true,
"text": "for key, value in mod_d.items():\n if key not in ref_d:\n dif_d.update({key: value})\n else:\n if value != ref_d[key]:\n dif_d.update({key: value})\n"
},
{
"answer_id": 74360602,
"author": "Remzinho",
"author_id": 2484591,
"author_profile": "https://Stackoverflow.com/users/2484591",
"pm_score": 0,
"selected": false,
"text": "$ python test.py\n{('outpu', 'yes'), ('color', 'red'), ('specm', 'true'), ('lumin', 'max'), ('rotxy', '0.5,0.5'), ('varia', 'true')}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449241/"
] |
74,360,355 | <p>Needs to find out the minimum maximum of all edges in all paths from source and destination.
<a href="https://i.stack.imgur.com/o8RD5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o8RD5.png" alt="enter image description here" /></a></p>
<p>Here two paths possible from 1 to 6. in the top path maximum weight of the edge is 4. In the bottom path maximum weight of the edge is 6. So 4 is the answer. Can anybody suggest an optimized algorithm?</p>
<p>What i currently doing is taking all paths and calculating their maximum edge. After exploring all paths using DFS. I calculate the minimum of all max. But time complexity is O(v^v) Exponential.</p>
| [
{
"answer_id": 74360577,
"author": "milchmannverleih",
"author_id": 11373689,
"author_profile": "https://Stackoverflow.com/users/11373689",
"pm_score": 3,
"selected": true,
"text": "for key, value in mod_d.items():\n if key not in ref_d:\n dif_d.update({key: value})\n else:\n if value != ref_d[key]:\n dif_d.update({key: value})\n"
},
{
"answer_id": 74360602,
"author": "Remzinho",
"author_id": 2484591,
"author_profile": "https://Stackoverflow.com/users/2484591",
"pm_score": 0,
"selected": false,
"text": "$ python test.py\n{('outpu', 'yes'), ('color', 'red'), ('specm', 'true'), ('lumin', 'max'), ('rotxy', '0.5,0.5'), ('varia', 'true')}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16928312/"
] |
74,360,358 | <pre class="lang-js prettyprint-override"><code>states = [{
name: telangana,
cities: [{
id: 1,
name: foo
}, {
id: 2,
name: joo
}, {
id: 3,
name: goo
}]
},
{
name: punjab,
cities: [{
id: 4,
name: tyu
}, {
id: 5,
name: ery
}, {
id: 6,
name: doo
}]
},
{
name: mumbai,
cities: [{
id: 7,
name: eee
}, {
id: 8,
name: qqq
}, {
id: 9,
name: www
}]
},
]
</code></pre>
<p>I want response like <code>[foo, joo, goo, tyu, ery,doo, eee,qqq,www]</code></p>
<p>Can someone help me ?</p>
| [
{
"answer_id": 74360577,
"author": "milchmannverleih",
"author_id": 11373689,
"author_profile": "https://Stackoverflow.com/users/11373689",
"pm_score": 3,
"selected": true,
"text": "for key, value in mod_d.items():\n if key not in ref_d:\n dif_d.update({key: value})\n else:\n if value != ref_d[key]:\n dif_d.update({key: value})\n"
},
{
"answer_id": 74360602,
"author": "Remzinho",
"author_id": 2484591,
"author_profile": "https://Stackoverflow.com/users/2484591",
"pm_score": 0,
"selected": false,
"text": "$ python test.py\n{('outpu', 'yes'), ('color', 'red'), ('specm', 'true'), ('lumin', 'max'), ('rotxy', '0.5,0.5'), ('varia', 'true')}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360358",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449288/"
] |
74,360,379 | <pre class="lang-py prettyprint-override"><code>import shutil
def create_dir(path):
if not os.path.exists(path):
os.mkdir(path)
else:
shutil.rmtree(path)
</code></pre>
<p>when I run this code it gives me permission error, even though I have access to that directory.</p>
<p>Also, I use Windows and I have tried running as administrator</p>
| [
{
"answer_id": 74360577,
"author": "milchmannverleih",
"author_id": 11373689,
"author_profile": "https://Stackoverflow.com/users/11373689",
"pm_score": 3,
"selected": true,
"text": "for key, value in mod_d.items():\n if key not in ref_d:\n dif_d.update({key: value})\n else:\n if value != ref_d[key]:\n dif_d.update({key: value})\n"
},
{
"answer_id": 74360602,
"author": "Remzinho",
"author_id": 2484591,
"author_profile": "https://Stackoverflow.com/users/2484591",
"pm_score": 0,
"selected": false,
"text": "$ python test.py\n{('outpu', 'yes'), ('color', 'red'), ('specm', 'true'), ('lumin', 'max'), ('rotxy', '0.5,0.5'), ('varia', 'true')}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20292818/"
] |
74,360,411 | <p>I have a page like this (a speech or a dialogue page organised like this, so speaker name in bold and then paragraphs of his speech):</p>
<pre><code><body>
<p>
<b>
speaker abc:
</b>
some wanted text here
</p>
<p>
some other text wanted, maybe containing speaker abc
</p>
<p>
some other text wanted, maybe containing speaker cde
</p>
<p>
some other text wanted
</p>
<p>
<b>
speaker cde (can be random):
</b>
</p>
<p>
some other text UNwanted, maybe containing speaker abc
</p>
<p>
some other text UNwanted, maybe containing speaker cde
</p>
<p>
some other text UNwanted
</p>
<p>
<b>
speaker abc:
</b>
</p>
<p>
some other text wanted
</p>
<p>
<b>
speaker fgh:
</b>
</p>
<p>
some other text UNwanted
</p>
</body>
</code></pre>
<p>I would like to select (using xpath) all text elements marked as wanted text in example (all phrases spoken by one particular speaker, say abc).</p>
<p>I am not very fluent with xpath and html, I suspect there should be some usage of axis but struggle to figure out how.</p>
| [
{
"answer_id": 74360600,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 0,
"selected": false,
"text": "\"//*[preceding-sibling::p[contains(.,'speaker abc')] and following-sibling::p[contains(.,'speaker cde')]]\"\n"
},
{
"answer_id": 74362340,
"author": "Michael Kay",
"author_id": 415448,
"author_profile": "https://Stackoverflow.com/users/415448",
"pm_score": 1,
"selected": false,
"text": "<xsl:for-each-group select=\"p\" group-starting-with=\"p[b]\">...</\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15227955/"
] |
74,360,438 | <p>I have a 2d array and was able to pass it from code.gs to JavaScript. The next thing I want to do is to sum all elements or numbers example in column 2.</p>
<p><a href="https://i.stack.imgur.com/zIEcX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zIEcX.png" alt="enter image description here" /></a></p>
<p>I've seen this code while searching online but it add all elements in the array. I don't know how to personalize it to meet my needs.</p>
<p>`</p>
<pre><code>var data=[
[1,2,3],
[4,5,6],
[7,8,9]
];
var sum=0;
for(var i=0;i<data.length;i++){
for(var j=0;j<data[i].length;j++){
sum+=data[i][j]
}
}
console.log(sum);
</code></pre>
<p>`</p>
<p>In my table, I only want to get the sum of Column B, and that would be 13. then alert the value or display it in div. Thank you so much!</p>
| [
{
"answer_id": 74360600,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 0,
"selected": false,
"text": "\"//*[preceding-sibling::p[contains(.,'speaker abc')] and following-sibling::p[contains(.,'speaker cde')]]\"\n"
},
{
"answer_id": 74362340,
"author": "Michael Kay",
"author_id": 415448,
"author_profile": "https://Stackoverflow.com/users/415448",
"pm_score": 1,
"selected": false,
"text": "<xsl:for-each-group select=\"p\" group-starting-with=\"p[b]\">...</\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19529245/"
] |
74,360,439 | <p>I have this dictionary:</p>
<pre><code>data=[{'first': '0', 'last': 'hg01', 'pay': 0},
{'first': '0', 'last': 'hg75', 'pay': 15},
{'first': '0', 'last': 'hg0', 'pay': 1},
{'first': '0', 'last': 'hg9', 'pay': 13},
{'first': '0', 'last': 'hg0', 'pay': 0},
{'first': '0', 'last': 'hg', 'pay': 13},
{'first': '0', 'last': 'hg76', 'pay': 0},
{'first': '0', 'last': 'hg1', 'pay': 9},
{'first': '0', 'last': 'hg81', 'pay': 13},
{'first': '0', 'last': 'hg12', 'pay': 1},
{'first': '0', 'last': 'hg03', 'pay': 15},
{'first': '0', 'last': 'hg11', 'pay': 9},
{'first': '0', 'last': 'hg1', 'pay': 1}]
</code></pre>
<p>and I want convert to this dictionary with dictionary or list comprehension:</p>
<pre><code>output={0: {'hg76':{'first': '0'},'hg0':{'first': '0'},'hg01':{'first': '0'}},
15: {'hg75':{'first': '0'},'hg03':{'first': '0'}},
1: {'hg1':{'first': '0'},'hg12':{'first': '0'},'hg0':{'first': '0'}},
13: {'hg81':{'first': '0'},'hg':{'first': '0'},'hg9':{'first': '0'}},
9: {'hg1':{'first': '0'},'hg11':{'first': '0'}}}
</code></pre>
<p>I don't have any ideas for this problem</p>
| [
{
"answer_id": 74360600,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 0,
"selected": false,
"text": "\"//*[preceding-sibling::p[contains(.,'speaker abc')] and following-sibling::p[contains(.,'speaker cde')]]\"\n"
},
{
"answer_id": 74362340,
"author": "Michael Kay",
"author_id": 415448,
"author_profile": "https://Stackoverflow.com/users/415448",
"pm_score": 1,
"selected": false,
"text": "<xsl:for-each-group select=\"p\" group-starting-with=\"p[b]\">...</\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17816076/"
] |
74,360,464 | <p>I'm trying to convert a list of lists of strings (that represents a tic-tac-toe game) to a list of lists of integers, so that I can perform calculations.</p>
<p>These are the possible inputs:</p>
<pre><code>A = ['X', 'O', '#']
</code></pre>
<p>And these the corresponding integers:</p>
<pre><code>B = [1, 0, 99]
</code></pre>
<p>So overall it would do the following:</p>
<pre><code>[['X', 'O', 'O'], ['O', 'X', 'O'], ['O', '#', 'X']] -> [[1, 0, 0], [0, 1, 0], [0, 99, 1]]
</code></pre>
<p>I have created the following functions to perform this translation, but I'm sure there must be a faster and more efficient way:</p>
<pre><code>def make_integer_matrix(inputs):
A = ['X', 'O', '#']
B = [1, 0, 99]
integer_matrix = []
#First translate to integers
for row in inputs:
row_new = [B[A.index(row[0])], B[A.index(row[1])], B[A.index(row[2])]]
integer_matrix.append(row_new)
return integer_matrix
</code></pre>
| [
{
"answer_id": 74360515,
"author": "Sash Sinha",
"author_id": 6328256,
"author_profile": "https://Stackoverflow.com/users/6328256",
"pm_score": 4,
"selected": true,
"text": ">>> mapping = {'X': 1, 'O': 0, '#': 99}\n>>> raw_board = [['X', 'O', 'O'], ['O', 'X', 'O'], ['O', '#', 'X']]\n>>> value_board = [[mapping[c] for c in row] for row in raw_board]\n>>> value_board\n[[1, 0, 0], [0, 1, 0], [0, 99, 1]]\n"
},
{
"answer_id": 74360516,
"author": "Mathias R. Jessen",
"author_id": 712649,
"author_profile": "https://Stackoverflow.com/users/712649",
"pm_score": 2,
"selected": false,
"text": "A = ['X', 'O', '#']\nB = [1, 0, 99]\n# create translation table from lists\ntranslations = dict(zip(A, B))\n\nfor row in inputs:\n row_new = [translations[v] for v in row]\n integer_matrix.append(row_new)\nreturn integer_matrix\n"
},
{
"answer_id": 74360579,
"author": "mlokos",
"author_id": 19570235,
"author_profile": "https://Stackoverflow.com/users/19570235",
"pm_score": 0,
"selected": false,
"text": "A = ['X', 'O', '#']\nB = [1, 0, 99]\n\ngame_map = [['X', 'O', 'O'], ['O', 'X', 'O'], ['O', '#', 'X']]\n\n\ndef map_values(A, B):\n result_dict = dict()\n for a, b in zip(A, B):\n result_dict[a] = b\n \n return result_dict\n\nchar_to_int_map = map_values(A, B)\n\ngame_map_int = [[char_to_int_map[x] for x in row] for row in game_map]\n\nprint(game_map_int)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449423/"
] |
74,360,493 | <p>I have a class which I use to handle three types of data structures.
In this class I have many plotting methods, which depends on which type of data is loaded into the class.
Is there a way for me to hide the methods not belonging to the data structure loaded, when looking at the class attributes?</p>
<p>Example:</p>
<pre><code>class data_reader():
def __init__(self):
self.load_data()
self.data_type()
self.common_method_1()
self.common_method_2()
def load_data(self):
# Loads the data
def data_type(self):
# Figures out which of the three data structures we have
def common_method_1(self):
# A method common for all data structures
def common_method_2(self):
# Another method common for all data structures
def plot_data_1(self):
# Plotting function for data structure 1
def plot_data_2(self):
# Plot function for data structure 2
def plot_data_3(self):
# Plot function for data structure 3
if __name__ == "__main__":
a = data_reader()
a.plot_data_1()
</code></pre>
<p>When I check the methods of the class I can see all plot functions. If I load data structure 1, can I then hide the other two plotting function?</p>
<p>I tried to do some inner functions, but then it did not become a callable method outside the class.</p>
<p>Thank you for any inputs.</p>
| [
{
"answer_id": 74360798,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": 0,
"selected": false,
"text": "class data_reader():\n def __init__(self, data):\n self.common_method_1()\n self.common_method_2()\n\n\n def common_method_1(self):\n pass\n\n def common_method_2(self):\n pass\n\n\nclass data_reader_1(data_reader):\n def plot_data_1(self):\n pass\n # Plotting function for data structure 1\nclass data_reader_2(data_reader):\n def plot_data_2(self):\n pass\n # Plot function for data structure 2\n\nclass data_reader_factory():\n \n def load_data(self):\n self.data = 42\n # Loads the data \n\n def data_type(self):\n self.type = \"1\"\n # Figures out which of the three data structures we have\n \n\n def create_reader(self):\n if self.type == \"1\":\n return data_reader_1(self.data)\n elif self.type == \"2\":\n return data_reader_2(self.data)\n # Creates an object of correct type\n\nif __name__ == \"__main__\":\n a = data_reader_factory().create_reader()\n a.plot_data_1()\n"
},
{
"answer_id": 74360803,
"author": "Nyps",
"author_id": 7890561,
"author_profile": "https://Stackoverflow.com/users/7890561",
"pm_score": 1,
"selected": false,
"text": "def load_list_data(self, data):\n # reads a list and converts it to a numpy array\n\ndef load_npy_array_data(self, data):\n # reads a numpy array which does not need to be converted\n\ndef plot_data(self):\n # plots a numpy array\n"
},
{
"answer_id": 74360804,
"author": "Booboo",
"author_id": 2823719,
"author_profile": "https://Stackoverflow.com/users/2823719",
"pm_score": 0,
"selected": false,
"text": "matszwecja"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16345365/"
] |
74,360,499 | <p>Hello fellow StackOverflow community,
I've encountred an error when trying to <code>.map()</code> a <code>getDoc()</code> constant in my Next.js app, saying the following: "TypeError: Cannot read properties of undefined (reading 'map')". I'm new to Next.js and I would appreciate a lot any kind of help from the community. I've been stuck on this error for a very long time trying to search for an answer on internet but nothing.</p>
<p>Here you can review the code of <code>[id].js</code>:</p>
<pre><code>import styled from "styled-components";
import Head from "next/head";
import Sidebar from "../components/Sidebar";
import ChatScreen from "../components/ChatScreen";
import { db } from "../../firebase";
import { collection, doc, orderBy, getDoc } from "firebase/firestore";
const Chat = () => {
return (
<Container className="bg-stone-900">
<Head></Head>
<Sidebar />
<ChatContainer>
<ChatScreen />
</ChatContainer>
</Container>
);
};
export default Chat;
export async function getServerSideProps(context) {
const ref = doc(collection(db, "chats"), context.query.id);
const messagesRes = await getDoc(
ref,
collection(db, "messages"),
orderBy("timestamp", "asc")
);
const messages = messagesRes.docs
.map((doc) => ({ //Here is the error line.
id: doc.id,
...doc.data(),
}))
.map((messages) => ({
...messages,
timestamp: messages.timestamp.toDate().getTime(),
}));
const chatRes = await getDoc();
const chat = {
id: chatRes.id,
...chatRes.data(),
};
return {
props: {
messages: JSON.stringify(messages),
chat: chat,
},
};
}
const Container = styled.div`
margin: 0 auto;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
`;
const ChatContainer = styled.div`
margin: 0 auto;
overflow: scrollbar;
`;
</code></pre>
<p>Again, thanks for any answers!</p>
| [
{
"answer_id": 74360798,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": 0,
"selected": false,
"text": "class data_reader():\n def __init__(self, data):\n self.common_method_1()\n self.common_method_2()\n\n\n def common_method_1(self):\n pass\n\n def common_method_2(self):\n pass\n\n\nclass data_reader_1(data_reader):\n def plot_data_1(self):\n pass\n # Plotting function for data structure 1\nclass data_reader_2(data_reader):\n def plot_data_2(self):\n pass\n # Plot function for data structure 2\n\nclass data_reader_factory():\n \n def load_data(self):\n self.data = 42\n # Loads the data \n\n def data_type(self):\n self.type = \"1\"\n # Figures out which of the three data structures we have\n \n\n def create_reader(self):\n if self.type == \"1\":\n return data_reader_1(self.data)\n elif self.type == \"2\":\n return data_reader_2(self.data)\n # Creates an object of correct type\n\nif __name__ == \"__main__\":\n a = data_reader_factory().create_reader()\n a.plot_data_1()\n"
},
{
"answer_id": 74360803,
"author": "Nyps",
"author_id": 7890561,
"author_profile": "https://Stackoverflow.com/users/7890561",
"pm_score": 1,
"selected": false,
"text": "def load_list_data(self, data):\n # reads a list and converts it to a numpy array\n\ndef load_npy_array_data(self, data):\n # reads a numpy array which does not need to be converted\n\ndef plot_data(self):\n # plots a numpy array\n"
},
{
"answer_id": 74360804,
"author": "Booboo",
"author_id": 2823719,
"author_profile": "https://Stackoverflow.com/users/2823719",
"pm_score": 0,
"selected": false,
"text": "matszwecja"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12541682/"
] |
74,360,537 | <pre><code>public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
}
var persons = new List<Person>
{
new Person { Id = 1, FirstName = "Fox", LastName = "Mulder", Age = 40 },
new Person { Id = 2, FirstName = "Dana", LastName = "Scully", Age = 35 }
};
List<Person> Search(List<Person> persons, Person person)
{
//Here I'd like create a predicate here it's a AND between each.
//If !string.IsNullOrEmpty(person.FirstName) add to predicate, same for LastName
//If person.Age.HasValue() add to predicate
return persons.Where(myPredicateHere);
}
</code></pre>
<p>As explained in the <code>Search</code> method I'd like combine with a AND, if <code>FirstName</code> is not null or empty it's part of the predicate, same for <code>LastName</code> and if the <code>Age</code> has a value add it to the predicate.</p>
<p>Any idea ?</p>
<p>Thanks,</p>
| [
{
"answer_id": 74360798,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": 0,
"selected": false,
"text": "class data_reader():\n def __init__(self, data):\n self.common_method_1()\n self.common_method_2()\n\n\n def common_method_1(self):\n pass\n\n def common_method_2(self):\n pass\n\n\nclass data_reader_1(data_reader):\n def plot_data_1(self):\n pass\n # Plotting function for data structure 1\nclass data_reader_2(data_reader):\n def plot_data_2(self):\n pass\n # Plot function for data structure 2\n\nclass data_reader_factory():\n \n def load_data(self):\n self.data = 42\n # Loads the data \n\n def data_type(self):\n self.type = \"1\"\n # Figures out which of the three data structures we have\n \n\n def create_reader(self):\n if self.type == \"1\":\n return data_reader_1(self.data)\n elif self.type == \"2\":\n return data_reader_2(self.data)\n # Creates an object of correct type\n\nif __name__ == \"__main__\":\n a = data_reader_factory().create_reader()\n a.plot_data_1()\n"
},
{
"answer_id": 74360803,
"author": "Nyps",
"author_id": 7890561,
"author_profile": "https://Stackoverflow.com/users/7890561",
"pm_score": 1,
"selected": false,
"text": "def load_list_data(self, data):\n # reads a list and converts it to a numpy array\n\ndef load_npy_array_data(self, data):\n # reads a numpy array which does not need to be converted\n\ndef plot_data(self):\n # plots a numpy array\n"
},
{
"answer_id": 74360804,
"author": "Booboo",
"author_id": 2823719,
"author_profile": "https://Stackoverflow.com/users/2823719",
"pm_score": 0,
"selected": false,
"text": "matszwecja"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/118584/"
] |
74,360,559 | <p>I have Ubuntu 22.04 newly installed on my laptop. I am trying to connect to a remote server and getting the following error:</p>
<pre><code>ssh: connect to host ********* port 22: Connection timed out
</code></pre>
<p>I tried some solutions which include,</p>
<ul>
<li>ping the IP address</li>
<li>adding the IP address to the firewall using sudo ufw</li>
<li>installing ssh and openssh</li>
</ul>
<p>However, nothing seems to work. I'd be thankful if someone can help me to solve this problem.</p>
| [
{
"answer_id": 74361104,
"author": "pouya shahrdami",
"author_id": 9858914,
"author_profile": "https://Stackoverflow.com/users/9858914",
"pm_score": -1,
"selected": false,
"text": "ssh: connect to host ********* port 22: Connection timed out\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13360556/"
] |
74,360,583 | <p>I would like to ask a question please regarding printing the number of different numbers in python.</p>
<p>for example:
Let us say that I have the following list:</p>
<pre><code>X = [5, 5, 5]
</code></pre>
<p>Since here we have only one number, I want to build a code that can recognize that we have only one number here so the output must be:</p>
<pre><code>1
The number is: 5
</code></pre>
<p>Let us say that I have the following list:</p>
<pre><code>X = [5,4,5]
</code></pre>
<p>Since here we have two numbers (5 and 4), I want to the code to recognize that we have only two numbers here so the output must be:</p>
<pre><code>2
The numbers are: 4, 5
</code></pre>
<p>Let us say that I have the following list:</p>
<pre><code>X = [24,24,24,24,24,24,24,24,26,26,26,26,26,26,26,26]
</code></pre>
<p>Since here we have two numbers (24 and 26), I want to the code to recognize that we have only two numbers here so the output must be:</p>
<pre><code>2
The numbers are: 24, 26
</code></pre>
| [
{
"answer_id": 74360664,
"author": "asena",
"author_id": 6063483,
"author_profile": "https://Stackoverflow.com/users/6063483",
"pm_score": 1,
"selected": false,
"text": "X = [1,2,3,3,3]\nS = set(X)\nn = len(S)\nprint(n, S) # 3 {1,2,3}\n"
},
{
"answer_id": 74360679,
"author": "Karthik Raja",
"author_id": 20449425,
"author_profile": "https://Stackoverflow.com/users/20449425",
"pm_score": 1,
"selected": false,
"text": "list(set(X))\n"
},
{
"answer_id": 74362243,
"author": "Mhmoud Khadija",
"author_id": 19585524,
"author_profile": "https://Stackoverflow.com/users/19585524",
"pm_score": 0,
"selected": false,
"text": "df1= [ 0 -10 2 5 \n 1 24 5 10 \n 2 30 3 6 \n 3 30 2 1 \n 4 30 4 5 ]\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19585524/"
] |
74,360,589 | <p>i`m trying to do something.... I have to insert some data in to a table but..... So here is where I end up...</p>
<pre><code>INSERT into HR.my_employees
(ID,LAST_NAME,FIRST_NAME,userid,SALARY)
SELECT
3 AS ID,
'Biri' AS LAST_NAME,
'Ben' AS FIRST_NAME,
substr(FIRST_NAME,1,1)||''||substr(LAST_NAME,1,7) AS userid,
1100 AS salary
FROM dual
UNION
SELECT
4 AS ID,
'Newman' AS LAST_NAME,
'Chad' AS FIRST_NAME,
substr(FIRST_NAME,1,1)||''||substr(LAST_NAME,1,7) AS userid,
750 AS salary
FROM dual;
</code></pre>
<p>any suggestion...</p>
| [
{
"answer_id": 74360795,
"author": "drdalle",
"author_id": 20207622,
"author_profile": "https://Stackoverflow.com/users/20207622",
"pm_score": 0,
"selected": false,
"text": "INSERT INTO table_name (column1, column2, column3, ..., columnXX)\nVALUES (value1, value2, value3, ..., valueXX);\n"
},
{
"answer_id": 74361441,
"author": "MT0",
"author_id": 1509264,
"author_profile": "https://Stackoverflow.com/users/1509264",
"pm_score": 2,
"selected": true,
"text": "SELECT"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360589",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20090021/"
] |
74,360,598 | <p>So, the task is the following:</p>
<p><em>Find the number of words in the text in which the first and last characters are the same.</em></p>
<p>In order to do this, I think I first should split the text and create the array of separate words.</p>
<p>For example, the string is:</p>
<p><em>"hello goodbye river dog level"</em></p>
<p>I want to split it and get the following array:</p>
<p><em>{"hello", "goodbye", "river", "dog", "level"}</em></p>
<p>I have the code that splits the string:</p>
<pre><code>#include<stdio.h>
#include <string.h>
int main() {
char string[100] = "hello goodbye river dog level";
// Extract the first token
char * token = strtok(string, " ");
// loop through the string to extract all other tokens
while( token != NULL ) {
printf( " %s\n", token ); //printing each token
token = strtok(NULL, " ");
}
return 0;
}
</code></pre>
<p>However, it just prints these words, and I need to append each word to some array. The array shouldn't be of fixed size, because potentially I could add as many elements as the text requires. How to do this?</p>
| [
{
"answer_id": 74360893,
"author": "Support Ukraine",
"author_id": 4386427,
"author_profile": "https://Stackoverflow.com/users/4386427",
"pm_score": 3,
"selected": true,
"text": "#include <stdio.h>\n\nint count(const char* s)\n{\n int res = 0;\n int in_word = 0;\n char first;\n char last;\n \n while(*s)\n {\n if (in_word)\n {\n if (*s == ' ')\n {\n // Found end of a word\n if (first == last) ++res;\n in_word = 0;\n }\n else\n {\n // Word continues so update last\n last = *s;\n }\n }\n else\n {\n if (*s != ' ')\n {\n // Found start of new word. Update first and last\n first = *s;\n last = *s;\n in_word = 1;\n }\n }\n ++s;\n }\n if (in_word && first == last) ++res;\n return res;\n}\n\nint main(void) \n{\n char string[100] = \"hello goodbye river dog level\";\n printf(\"found %d words\\n\", count(string));\n return 0;\n}\n"
},
{
"answer_id": 74361057,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 1,
"selected": false,
"text": "strtok"
},
{
"answer_id": 74361106,
"author": "CGi03",
"author_id": 18646208,
"author_profile": "https://Stackoverflow.com/users/18646208",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main(void)\n{\n char string[] = \"hello, goodbye; river, dog; level.\";\n char *token = strtok(string, \" ,;.\");\n int counter =0;\n while( token != NULL )\n {\n if(token[0]==token[strlen(token)-1]) counter++;\n token = strtok(NULL, \" ,;.\");\n }\n printf(\"found : %d\", counter);\n\n return 0;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18259372/"
] |
74,360,601 | <p>I have a list called <code>ListA</code>: <code>List<string> allStuffs = ...</code></p>
<p>I want to reference the list to <code>ListB</code> as <code>List<string> secondList = allStuffs;</code></p>
<p>If I do something like <code>secondList.Remove(someitem)</code>, would it also remove the same item on <code>allStuffs</code>?</p>
| [
{
"answer_id": 74360646,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "..."
},
{
"answer_id": 74361331,
"author": "vivek nuna",
"author_id": 6527049,
"author_profile": "https://Stackoverflow.com/users/6527049",
"pm_score": 1,
"selected": false,
"text": "List<int> ls1 = new List<int>() { 1, 2, 3 };\nList<int> ls2 = new List<int>(ls1);\nls2.Remove(1);\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18034508/"
] |
74,360,605 | <p>I have table:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>user_id</th>
<th>date</th>
<th>days_since_install</th>
</tr>
</thead>
<tbody>
<tr>
<td>001</td>
<td>01-01-2021</td>
<td>0</td>
</tr>
<tr>
<td>001</td>
<td>02-01-2021</td>
<td>1</td>
</tr>
<tr>
<td>001</td>
<td>02-01-2021</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
<p>It is necessary to check if there is "1" in the column "days_since_install" in grouping by use_id and if so, fill in True in the column "retention_1d" otherwise False.</p>
<p>The resulting table should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>user_id</th>
<th>retention_1d</th>
</tr>
</thead>
<tbody>
<tr>
<td>001</td>
<td>True</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74360625,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "Series.map"
},
{
"answer_id": 74360626,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "groupby.first"
},
{
"answer_id": 74360865,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 1,
"selected": false,
"text": "groupby"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14085367/"
] |
74,360,630 | <p>Is it possible to combine multiple <code>orWhere()</code> inside one <code>where()</code>?</p>
<p>E.g. The following:</p>
<pre><code>$query->where(function($query){
$query->where('text1', '=', $_GET['lorem'])
->orWhere('text2', '=', $_GET['lorem'])
->orWhere('text3', '=', $_GET['lorem'])
->orWhere('text4', '=', $_GET['lorem']);
});
</code></pre>
<p>Would look something like this:</p>
<pre><code>$query->where(function($query){
$query->where(['text1' || 'text2' || 'text3' || 'text4'], '=', $_GET['lorem']);
});
</code></pre>
<p><strong>P.S.</strong> In the above hypothetical example, the <code>[</code> <code>]</code> aren't really referring to an array but I'm just using the brackets to group <code>text1/2/3/4</code>.</p>
| [
{
"answer_id": 74360625,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "Series.map"
},
{
"answer_id": 74360626,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "groupby.first"
},
{
"answer_id": 74360865,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 1,
"selected": false,
"text": "groupby"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4114907/"
] |
74,360,686 | <p>I wanted to create a three dropdown selects category>subcategory>susubcategory
I have followed this method here <a href="https://www.youtube.com/watch?v=ap551f2a_d0" rel="nofollow noreferrer">https://www.youtube.com/watch?v=ap551f2a_d0</a> with some changes to suit my needs. everything seemed fine and each dropdown gets populated based on the selection of the dropdown before but when I select any value in the dropdowns it does not keep it selected it just goes back to the default -Please select-! I am not sure where I went wrong.
note: I only have one module (categories for the categories and using the parant_id for the subcategories)</p>
<p>I would really appreciate it if someone can point me in the right direction. Thank you
<a href="https://i.stack.imgur.com/6S6J2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6S6J2.png" alt="enter image description here" /></a></p>
<p>my categories table</p>
<pre><code>create_table :categories do |t|
t.string "name", limit: 255
t.text "description", limit: 65535
t.references "parent_id", limit: 4
t.boolean "important", default: false
t.integer "position", limit: 4, default: 0
t.timestamps
end
</code></pre>
<p>in modules category.rb</p>
<pre><code>class Category < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_many :jobs
belongs_to :parent_category, foreign_key: :parent_id, class_name: 'Category'
has_many :subcategories, foreign_key: :parent_id, class_name: 'Category'
has_many :subsubcategories, foreign_key: :parent_id, class_name: 'Category'
end
</code></pre>
<p>in modules job.rb</p>
<pre><code>class Job < ApplicationRecord
validates :title,:category_id, :description, presence: true
validates :category, :presence => true
belongs_to :user
belongs_to :category , -> { order("name") }
end
</code></pre>
<p>dropdown_controller.js</p>
<pre><code> import { Controller } from "@hotwired/stimulus";
// connect to data-controller="dropdown"
export default class extends Controller {
submit () {
this.element.requestSubmit();
}
}
</code></pre>
<p>in my jobs_controller.rb</p>
<pre><code> before_action :authenticate_user!, except: [:index, :show]
before_action :set_categories
def index
@jobs = Job.all
end
def new
@categories = Category.where(parent_id: nil)
@subcategory = @subcategory&.category || []
@subcategories = @subcategories&.subcategories || []
@subsubcategories = @subsubcategories&.subsubcategories || []
@job = Job.new
end
def create
@job = Job.new(job_params.merge({ user: current_user }))
if @job.save
format.html { redirect_to root_path, notice: "Job was successfully created." }
else
render :new, status: :unprocessable_entity
end
end
private
def job_params
params.require(:job).permit(:title, :description,:category_id).merge(user: current_user)
end
def set_categories
@category = Category.find_by(id: params[:category].presence)
@categories = Category.find_by(id: params[:category].presence)
@subcategories = Category.find_by(id: params[:category].presence)
@subsubcategories = Category.find_by(id: params[:subcategories].presence)
end
end
</code></pre>
<p>views/jobs/new.html.erb</p>
<pre><code><%= turbo_frame_tag "form" do %>
<%= form_tag new_job_path, method: :get, data: { controller: "dropdown", action: "change->dropdown#submit" } do %>
<%= select_tag :category, options_from_collection_for_select(@categories, "id", "name", @category&.id ), prompt: "Select a category" %>
<%= select_tag :subcategories, options_from_collection_for_select(@subcategories, "id" , "name", @category&.id), prompt: "Select a subcategories category" %>
<%= select_tag :subsubcategories, options_from_collection_for_select(@subsubcategories, "id" , "name", @category&.id), prompt: "Select a subsubcategories category" %>
<% end %>
<% end %>
</code></pre>
| [
{
"answer_id": 74360625,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "Series.map"
},
{
"answer_id": 74360626,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "groupby.first"
},
{
"answer_id": 74360865,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 1,
"selected": false,
"text": "groupby"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4965241/"
] |
74,360,690 | <p>I'm having an issue trying to pop a dialog that contains a circle loader. I actually pop fine once my data is loaded, but in debug mode it's showing an exception that I can't figure out how to fix.</p>
<p>I have a stateful screen that on init I use the following code:</p>
<pre><code>WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
showLoading();
});
</code></pre>
<p>The method <code>showLoading</code> is as follows:</p>
<pre><code>void showLoading() {
//let's show the loading bar
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
dialogContext = context;
return AppLoader();
},
);
}
</code></pre>
<p>Where AppLoader simply returns:</p>
<pre><code>class AppLoader extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
child: new CircularProgressIndicator(),
height: 80.0,
width: 80.0,
),
],
),
),
);
}
}
</code></pre>
<p>dialogContent is defined in the initial of the class as:</p>
<pre><code>late BuildContext dialogcontext;
</code></pre>
<p>The main bulk of my code looks like this:</p>
<pre><code>@override
Widget build(BuildContext context) {
return Container(
color: ColorConstant.gray100,
child: Scaffold(
backgroundColor: ColorConstant.gray100,
body: Stack(
children: <Widget>[
getMainListViewUI(),
SizedBox(
height: MediaQuery.of(context).padding.bottom,
)
],
),
),
);
}
Widget getMainListViewUI() {
return FutureBuilder<bool>(
future: getData(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
return ListView.builder(
itemCount: listViews.length,
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return listViews[index];
},
);
},
);
}
</code></pre>
<p>Basically, the issue that I have is that when I finish getting the data from (getData()), I use:</p>
<pre><code>Navigator.pop(dialogContext);
</code></pre>
<p>This works great: it removes the circle loader and I can see the screen behind it, no issues, no errors. However, if I run in debug mode, when I do a hotsync, it always shows me the error:
<code>Looking up a deactivated widget's ancestor on dialog pop</code></p>
<p>I understand that this is because of the Navigator.pop that I am doing, but I don't get it. I've defined the dialogContext, which is what I am passing to the showDialog, and that's what I am popping. I've also tried setting a scheduled navigator, but again, same issue.</p>
<p>Any advice please?</p>
| [
{
"answer_id": 74360625,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "Series.map"
},
{
"answer_id": 74360626,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "groupby.first"
},
{
"answer_id": 74360865,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 1,
"selected": false,
"text": "groupby"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449496/"
] |
74,360,715 | <p>According to <a href="https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-nmlistview" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-nmlistview</a> lParam is of <code>Type: LPARAM</code> and is a Application-defined value of the item. This member is undefined for notification messages that do not use it.</p>
<p>It does not say how an application can set its user defined lParam value.</p>
<p>You would have thought that as this is a specific Windows message, it would specify if it is a notification messages that do not use it.</p>
<p>So how does the lParam parameter within NMLISTVIEW get set?</p>
<p>Or is it always undefined?</p>
| [
{
"answer_id": 74365653,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "NMLISTVIEW::lParam"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/176690/"
] |
74,360,767 | <p>Best way to get high value of partition from oracle database?</p>
| [
{
"answer_id": 74365653,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "NMLISTVIEW::lParam"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19681391/"
] |
74,360,770 | <p>I'm trying to change CISCOASA word here using the output I got. I've tried using lineinfile module in ansible but the replacement is not in order.</p>
<p><strong>ORIG JSON FILE:</strong></p>
<pre><code>{ "servers": [
{
"ingress": "CISCOASA",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": 22
},
{
"ingress": "CISCOASA",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12346,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
}
]}
</code></pre>
<p><strong>REPLACE VALUES:</strong></p>
<pre><code>CISCOASA1
CISCOASA2
CISCOASA3
CISCOASA4
</code></pre>
<p><strong>CURRENT OUTPUT:</strong></p>
<pre><code>{ "servers": [
{
"ingress": "CISCOASA4",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA3",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA2",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": 22
},
{
"ingress": "CISCOASA1",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12346,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
}
]}
</code></pre>
<p><strong>DESIRED OUTPUT:</strong></p>
<pre><code>{ "servers": [
{
"ingress": "CISCOASA1",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA2",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
},
{
"ingress": "CISCOASA3",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12345,
"dest_ip": "IPADDRESS",
"dest_port": 22
},
{
"ingress": "CISCOASA4",
"protocol": "tcp",
"source_ip": "IPADDRESS",
"source_port": 12346,
"dest_ip": "IPADDRESS",
"dest_port": "ssh"
}
]}
</code></pre>
<p><strong>Below is my task:</strong></p>
<pre><code> - name: Adding extracted ingress in file
become: yes
become_user: root
lineinfile:
path: /filepath/valid.json
regexp: "CISCOASA"
line: "\"ingress\": \"{{ item[0] }}\","
state: present
with_items:
- "{{ foo }}"
</code></pre>
<p>Thank you</p>
| [
{
"answer_id": 74361937,
"author": "Mirco",
"author_id": 10916365,
"author_profile": "https://Stackoverflow.com/users/10916365",
"pm_score": 1,
"selected": false,
"text": " - replace:\n path: ./file.json\n regexp: '^(.*?)CISCOASA\\\"(.*)'\n replace: '\\1CISCOASA{{ servers_index + 1 }}\\\"\\2'\n loop: \"{{ vars_file_yml.servers }}\"\n loop_control:\n index_var: servers_index\n vars:\n vars_file_yml: \"{{ lookup('file', './file.json') | from_json }}\"\n"
},
{
"answer_id": 74362909,
"author": "RRRR",
"author_id": 18459325,
"author_profile": "https://Stackoverflow.com/users/18459325",
"pm_score": 0,
"selected": false,
"text": " - name: Adding extracted ingress in file\n become: yes\n become_user: root\n replace:\n path: filepath/valid.json\n regexp: 'CISCOASA{{ servers_index + 1 }}'\n replace: \"{{ item[0] }}\"\n loop_control:\n index_var: servers_index\n with_items:\n - \"{{ foo }}\"\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18459325/"
] |
74,360,787 | <p>I'm trying to get my head around OAuth from the context of having an API that I want to secure and a javascript based single page app made in Vue.js that will consume this API. I've been told that OAuth is the industry standard for this type of thing.</p>
<p>I want to let other clients like a mobile app also use the same API.</p>
<p>From what I can gather the right flow is Authorization Code Flow with Proof Key for Code Exchange (PKCE) <a href="https://oauth.net/2/pkce/" rel="nofollow noreferrer">https://oauth.net/2/pkce/</a></p>
<p>The bit I am confused over is how I seem to need to get users to approve access. For example you don't have Twitter saying "Would you like Twitter to use Twitter". If I was in the position of people using the account to create another account I wouldn't have any confusion but when the client is your own website what is supposed to happen?</p>
<p>I can sort of imagine that I could automatically approve the website or just bypass the part where the user approves but then I feel like I'm going off script. Then I think to myself, have I completely got the wrong end of the stick- is OAuth not designed for this?</p>
<p>If anyone can see where my ignorance is I'd be more than happy to be corrected!</p>
<p>Thanks!</p>
| [
{
"answer_id": 74361937,
"author": "Mirco",
"author_id": 10916365,
"author_profile": "https://Stackoverflow.com/users/10916365",
"pm_score": 1,
"selected": false,
"text": " - replace:\n path: ./file.json\n regexp: '^(.*?)CISCOASA\\\"(.*)'\n replace: '\\1CISCOASA{{ servers_index + 1 }}\\\"\\2'\n loop: \"{{ vars_file_yml.servers }}\"\n loop_control:\n index_var: servers_index\n vars:\n vars_file_yml: \"{{ lookup('file', './file.json') | from_json }}\"\n"
},
{
"answer_id": 74362909,
"author": "RRRR",
"author_id": 18459325,
"author_profile": "https://Stackoverflow.com/users/18459325",
"pm_score": 0,
"selected": false,
"text": " - name: Adding extracted ingress in file\n become: yes\n become_user: root\n replace:\n path: filepath/valid.json\n regexp: 'CISCOASA{{ servers_index + 1 }}'\n replace: \"{{ item[0] }}\"\n loop_control:\n index_var: servers_index\n with_items:\n - \"{{ foo }}\"\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3110658/"
] |
74,360,790 | <p>I have without success tried to figure out how to most efficiently fetch data with powershell from the below JSON that is returned to me by a REST API:</p>
<pre><code> {
"$schema": "api:standardResponse",
"links": [
{
"rel": "canonical",
"href": "http://localhost:8501/services/v2/replicats",
"mediaType": "application/json"
},
{
"rel": "self",
"href": "http://localhost:8501/services/v2/replicats",
"mediaType": "application/json"
},
{
"rel": "describedby",
"href": "http://localhost:8501/services/v2/metadata-catalog/replicats",
"mediaType": "application/schema+json"
}
],
"messages": [],
"response": {
"$schema": "ogg:collection",
"items": [
{
"links": [
{
"rel": "parent",
"href": "http://localhost:8501/services/v2/replicats",
"mediaType": "application/json"
},
{
"rel": "canonical",
"href": "http://localhost:8501/services/v2/replicats/RNIMDA00",
"mediaType": "application/json"
}
],
"$schema": "ogg:collectionItem",
"name": "RNIMDA00"
},
{
"links": [
{
"rel": "parent",
"href": "http://localhost:8501/services/v2/replicats",
"mediaType": "application/json"
},
{
"rel": "canonical",
"href": "http://localhost:8501/services/v2/replicats/RNIMDA01",
"mediaType": "application/json"
}
],
"$schema": "ogg:collectionItem",
"name": "RNIMDA01"
},
{
"links": [
{
"rel": "parent",
"href": "http://localhost:8501/services/v2/replicats",
"mediaType": "application/json"
},
{
"rel": "canonical",
"href": "http://localhost:8501/services/v2/replicats/RNIMDA02",
"mediaType": "application/json"
}
],
"$schema": "ogg:collectionItem",
"name": "RNIMDA02"
}
]
}
}
</code></pre>
<p>I only need the data from the "name": node, and the data from the "href": node.</p>
<p>I have done some searching and found som examples where the JSON is converted with <strong>ConvertFrom-Json</strong> and then iterated with a foreach like the pseudo code below:</p>
<pre><code>$users = $response | ConvertFrom-Json
foreach ($user in $users)
{
write-host "$($user.name) has the email: $($user.email)"
}
</code></pre>
<p>But I wonder if there is a better way of fetching data with powershell from a object that contains JSON.</p>
<p>Thanks :)</p>
| [
{
"answer_id": 74360967,
"author": "Paul-Marie",
"author_id": 9603417,
"author_profile": "https://Stackoverflow.com/users/9603417",
"pm_score": -1,
"selected": false,
"text": "PATH"
},
{
"answer_id": 74362174,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 0,
"selected": false,
"text": "$json = $response | ConvertFrom-Json"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10046570/"
] |
74,360,796 | <p>So I'm following this example, though it is an earlier version of Angular and ngrx.<a href="https://offering.solutions/blog/articles/2020/05/29/authentication-in-angular-with-ngrx-and-asp.net-core/" rel="nofollow noreferrer">NGRX Authentication in Angular with asp.net core</a></p>
<p>My Auth.action.ts file is:</p>
<pre><code>import { createAction, props } from '@ngrx/store';
export const checkAuth = createAction('[Auth] checkAuth');
export const checkAuthComplete = createAction(
'[Auth] checkAuthComplete',
props<{ isLoggedIn: boolean }>()
);
export const login = createAction('[Auth] login');
export const loginComplete = createAction(
'[Auth] loginComplete',
props<{ profile: any; isLoggedIn: boolean }>()
);
export const logout = createAction('[Auth] logout');
export const logoutComplete = createAction('[Auth] logoutComplete');
</code></pre>
<p>In my auth.service.ts file I have a method:</p>
<pre><code>checkAuth() {
return this.oidcSecurityService.checkAuth();
}
</code></pre>
<p>Then in mu auth.effects.ts file I have:</p>
<pre><code>import * as fromAuthActions from '../Actions/auth.actions';
.......
checkauth$ = createEffect(() =>
this.actions$.pipe(
ofType(fromAuthActions.checkAuth),
switchMap(() =>
this.authService
.checkAuth()
.pipe(
map((isLoggedIn) => fromAuthActions.checkAuthComplete({ isLoggedIn }))
)
)
)
);
</code></pre>
<p>It errors on isLoggedIn of fromAuthActions.checkAuthComplete({ isLoggedIn }))</p>
<p>stating that</p>
<blockquote>
<p>'LoginResponse' is not assignable to type boolean.</p>
</blockquote>
<p>I've been looking for a while now, but cannot figure out what I need to change.</p>
| [
{
"answer_id": 74360967,
"author": "Paul-Marie",
"author_id": 9603417,
"author_profile": "https://Stackoverflow.com/users/9603417",
"pm_score": -1,
"selected": false,
"text": "PATH"
},
{
"answer_id": 74362174,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 0,
"selected": false,
"text": "$json = $response | ConvertFrom-Json"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5135610/"
] |
74,360,838 | <p>I am using Azure Data Factory in which a data flow is used, I want to split my file in to two based on a condition. I am attaching an image with 2 lines, the first one is working but I want to use more programatic approach to achieve the same output:</p>
<p><a href="https://i.stack.imgur.com/9Weuu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Weuu.png" alt="enter image description here" /></a></p>
<p>I have a column named <code>indicator</code> inside my dataset, I want to use <code>contains</code> functionality to split the data, basically having 1 file where a string value inside <code>indicator</code> column has substring <code>Weekly</code> or does not.</p>
<p>Similar to what I would use in pandas:</p>
<pre><code>df1 = df[df.indicator.str.contains('Weekly')]
df2 = df[~df.indicator.str.contains('Weekly')]
</code></pre>
<p><a href="https://i.stack.imgur.com/O7n4D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O7n4D.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74360967,
"author": "Paul-Marie",
"author_id": 9603417,
"author_profile": "https://Stackoverflow.com/users/9603417",
"pm_score": -1,
"selected": false,
"text": "PATH"
},
{
"answer_id": 74362174,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 0,
"selected": false,
"text": "$json = $response | ConvertFrom-Json"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8913983/"
] |
74,360,839 | <p>I have a problem to solve. I need to create new columns from given <code>key_words</code> list and sum their occurrence in data frame.</p>
<p>key_words = ['apple', 'animal', 'everyone']</p>
<p>input data frame:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>description</th>
<th>xx</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Apple is a healthy fruit. Everyone should eat it.</td>
<td>..</td>
</tr>
<tr>
<td>2</td>
<td>Lion is a denagerous animal.</td>
<td>..</td>
</tr>
<tr>
<td>3</td>
<td>Everyone likes him.</td>
<td>..</td>
</tr>
</tbody>
</table>
</div>
<p>what I want to get:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>description</th>
<th>xx</th>
<th>apple</th>
<th>animal</th>
<th>everyone</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Apple is a healthy fruit. Everyone should eat it.</td>
<td>..</td>
<td>1</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>Lion is a dangerous animal.</td>
<td>..</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>3</td>
<td>Everyone likes him.</td>
<td>..</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>any help much appreciated.</p>
| [
{
"answer_id": 74360981,
"author": "assume_irrational_is_rational",
"author_id": 11622508,
"author_profile": "https://Stackoverflow.com/users/11622508",
"pm_score": 3,
"selected": true,
"text": "key_words = ['apple', 'animal', 'everyone']\nfor key in key_words:\n df[key] = df['description'].str.lower().str.count(key)\n"
},
{
"answer_id": 74361367,
"author": "amirhm",
"author_id": 4529589,
"author_profile": "https://Stackoverflow.com/users/4529589",
"pm_score": 0,
"selected": false,
"text": "keys = ['apple', 'animal', 'everyone']\ndf['apple'], df['animal'], df['everyone'] = (\n zip(*list([len(re.findall(f'(?i){k}', r)) for k in keys] for r in df['description']))\n)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17277677/"
] |
74,360,842 | <p>I've a list of data and want to get values after a matching keyword from another list and append it to a dictionary. it should run until the next keyword is matched and added to a new dictionary.</p>
<pre><code>a = ['Experience',
'Software Engineer',
'EY',
'Sep 2018 - Present',
'Education',
'xyz College',
'Bachelor of Technology - BTech, Computer Science',
'2014 - 2017',
'Licenses',
'The Joy of Computing using Python ',
'NPTEL',
'Issued Jan 2020']
b = ['Experience', 'Education', 'Licenses']
</code></pre>
<p>Expected result:</p>
<pre><code>c =
{'Experience':['Software Engineer','EY', 'Sep 2018 - Present']},
{'Education':['xyz College','Bachelor of Technology - BTech, Computer Science','2014 - 2017']},
{'Licenses':
['The Joy of Computing using Python ','NPTEL','Issued Jan 2020']}
</code></pre>
<pre><code>for i in a:
j = a.index(i)
k = 1
while i in b:
c[i].append(a[j+1])
if i == a[k]:
k+=1
break
else:
j+=1
</code></pre>
<p>but the logic is not correct and I'm stuck here.</p>
| [
{
"answer_id": 74360981,
"author": "assume_irrational_is_rational",
"author_id": 11622508,
"author_profile": "https://Stackoverflow.com/users/11622508",
"pm_score": 3,
"selected": true,
"text": "key_words = ['apple', 'animal', 'everyone']\nfor key in key_words:\n df[key] = df['description'].str.lower().str.count(key)\n"
},
{
"answer_id": 74361367,
"author": "amirhm",
"author_id": 4529589,
"author_profile": "https://Stackoverflow.com/users/4529589",
"pm_score": 0,
"selected": false,
"text": "keys = ['apple', 'animal', 'everyone']\ndf['apple'], df['animal'], df['everyone'] = (\n zip(*list([len(re.findall(f'(?i){k}', r)) for k in keys] for r in df['description']))\n)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20448752/"
] |
74,360,849 | <p>How can I show .dng file format in HTML</p>
<p>I need to show the .dng file on my HTML image view</p>
| [
{
"answer_id": 74360981,
"author": "assume_irrational_is_rational",
"author_id": 11622508,
"author_profile": "https://Stackoverflow.com/users/11622508",
"pm_score": 3,
"selected": true,
"text": "key_words = ['apple', 'animal', 'everyone']\nfor key in key_words:\n df[key] = df['description'].str.lower().str.count(key)\n"
},
{
"answer_id": 74361367,
"author": "amirhm",
"author_id": 4529589,
"author_profile": "https://Stackoverflow.com/users/4529589",
"pm_score": 0,
"selected": false,
"text": "keys = ['apple', 'animal', 'everyone']\ndf['apple'], df['animal'], df['everyone'] = (\n zip(*list([len(re.findall(f'(?i){k}', r)) for k in keys] for r in df['description']))\n)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10946381/"
] |
74,360,864 | <p>I am trying to deploy elasticsearch and kibana to kubernetes using <a href="https://github.com/elastic/helm-charts" rel="nofollow noreferrer">this chart</a> and getting this error inside the kibana container, therefore ingress returns 503 error and container is never ready.</p>
<p>Error:</p>
<pre><code>[2022-11-08T12:30:53.321+00:00][ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. socket hang up - Local: 10.112.130.148:42748, Remote: 10.96.237.95:9200
</code></pre>
<p>Ip adress 10.96.237.95 is a valid elasticsearch service address, and port is right.</p>
<p>When i am doing curl to elasticsearch from inside the kibana container, it successfully returns a response.</p>
<p>Am i missing something in my configurations?</p>
<p><strong>Chart version: 7.17.3</strong></p>
<p>Values for elasticsearch chart:</p>
<pre><code>clusterName: "elasticsearch"
nodeGroup: "master"
createCert: false
roles:
master: "true"
data: "true"
ingest: "true"
ml: "true"
transform: "true"
remote_cluster_client: "true"
protocol: https
replicas: 2
sysctlVmMaxMapCount: 262144
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 90
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
imageTag: "7.17.3"
extraEnvs:
- name: ELASTIC_PASSWORD
valueFrom:
secretKeyRef:
name: elasticsearch-creds
key: password
- name: ELASTIC_USERNAME
valueFrom:
secretKeyRef:
name: elasticsearch-creds
key: username
clusterHealthCheckParams: "wait_for_status=green&timeout=20s"
antiAffinity: "soft"
resources:
requests:
cpu: "100m"
memory: "1Gi"
limits:
cpu: "1000m"
memory: "1Gi"
esJavaOpts: "-Xms512m -Xmx512m"
volumeClaimTemplate:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 30Gi
esConfig:
elasticsearch.yml: |
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
secretMounts:
- name: elastic-certificates
secretName: elastic-certificates
path: /usr/share/elasticsearch/config/certs
</code></pre>
<p>Values for kibana chart:</p>
<pre><code>elasticSearchHosts: "https://elasticsearch-master:9200"
extraEnvs:
- name: ELASTICSEARCH_USERNAME
valueFrom:
secretKeyRef:
name: elasticsearch-creds
key: username
- name: ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
name: elasticsearch-creds
key: password
- name: KIBANA_ENCRYPTION_KEY
valueFrom:
secretKeyRef:
name: encryption-key
key: encryption_key
kibanaConfig:
kibana.yml: |
server.ssl:
enabled: true
key: /usr/share/kibana/config/certs/elastic-certificate.pem
certificate: /usr/share/kibana/config/certs/elastic-certificate.pem
xpack.security.encryptionKey: ${KIBANA_ENCRYPTION_KEY}
elasticsearch.ssl:
certificateAuthorities: /usr/share/kibana/config/certs/elastic-certificate.pem
verificationMode: certificate
protocol: https
secretMounts:
- name: elastic-certificate-pem
secretName: elastic-certificate-pem
path: /usr/share/kibana/config/certs
imageTag: "7.17.3"
ingress:
enabled: true
ingressClassName: nginx
annotations:
cert-manager.io/cluster-issuer: letsencrypt-issuer
kubernetes.io/ingress.allow-http: 'false'
paths:
- path: /
pathType: Prefix
backend:
serviceName: kibana
servicePort: 5601
hosts:
- host: mydomain.com
paths:
- path: /
pathType: Prefix
backend:
serviceName: kibana
servicePort: 5601
tls:
- hosts:
- mydomain.com
secretName: mydomain.com
</code></pre>
<p>UPD: tried it with other image version (8.4.1), nothing has changed, i am getting the same error. By the way, logstash is successfully shipping logs to this elasticsearch instance, so i think problem is in kibana.</p>
| [
{
"answer_id": 74361059,
"author": "Raihan Khan",
"author_id": 7360615,
"author_profile": "https://Stackoverflow.com/users/7360615",
"pm_score": 0,
"selected": false,
"text": "elasticsearch.ssl.certificateAuthorities: \"/path/cert.ca\"\n"
},
{
"answer_id": 74437675,
"author": "A735",
"author_id": 14138090,
"author_profile": "https://Stackoverflow.com/users/14138090",
"pm_score": 3,
"selected": true,
"text": "xpack.security.http.ssl.enabled"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14138090/"
] |
74,360,869 | <p>I am trying to make a tally dataframe. My starting dataframe is looking like:</p>
<pre><code> sample bike
1: 1 gazelle
2: 1 batavus
3: 2 cortina
4: 2 Cube
5: 3 Giant
</code></pre>
<p>And what I need is as follows:</p>
<pre><code> sample gazelle batavus cortina Cube Giant
1: 1 1 1 0 0 0
2: 2 0 0 1 1 0
3: 3 0 0 0 0 1
</code></pre>
<p>So make a 1 if the variable is present in a sample and 0 if not.</p>
<p>I thought:</p>
<pre><code>df %>% group_by(sample, bike) %>%
summarize(count = n(), .group = "drop" %>%
pivot_wider(names_from = "bike", values_from = "count", values_fill = 0)
</code></pre>
<p>but that did not do the trick.</p>
| [
{
"answer_id": 74360933,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 2,
"selected": false,
"text": "value"
},
{
"answer_id": 74360962,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 3,
"selected": true,
"text": "library(dplyr)\nlibrary(tidyr)\n\npivot_wider(\n df, \n names_from = bike, values_from = bike, values_fn = length, values_fill = 0L\n)\n\n# # A tibble: 3 × 6\n# sample gazelle batavus cortina cube giant\n# <int> <int> <int> <int> <int> <int>\n# 1 1 1 1 0 0 0\n# 2 2 0 0 1 1 0\n# 3 3 0 0 0 0 1\n"
},
{
"answer_id": 74361032,
"author": "harre",
"author_id": 4786466,
"author_profile": "https://Stackoverflow.com/users/4786466",
"pm_score": 2,
"selected": false,
"text": "table"
},
{
"answer_id": 74361056,
"author": "John Polo",
"author_id": 5063086,
"author_profile": "https://Stackoverflow.com/users/5063086",
"pm_score": 1,
"selected": false,
"text": "group"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19254600/"
] |
74,360,884 | <p>I deleted a category which is an f-key of the items table. Now the view has an error saying 'Attempt to read property "category_name" on null'. How do I render a null foreign key?</p>
<p>I tried if-else:</p>
<pre><code>@if({{$item->category->category_name}} === 'null')
<h2>no category</h2>
@else
{{ $item->category->category_name}}
@endif
</code></pre>
| [
{
"answer_id": 74361105,
"author": "Semih SAHIN",
"author_id": 10542740,
"author_profile": "https://Stackoverflow.com/users/10542740",
"pm_score": 2,
"selected": false,
"text": "@if ($item->category)\n {{ $item->category->category_name }}\n@else\n <h2>no category</h2>\n@endif\n"
},
{
"answer_id": 74366806,
"author": "Engr Talha",
"author_id": 12135529,
"author_profile": "https://Stackoverflow.com/users/12135529",
"pm_score": 1,
"selected": false,
"text": "<h2>{{ $item->category->category_name ? 'no category' }}</h2>\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17040377/"
] |
74,360,928 | <p>I have model class <code>Bid</code> in my auction app that stores bids placed on items:</p>
<pre><code>class Bid(models.Model):
title = models.CharField(max_length=64, blank=True)
date_time = models.DateTimeField(default=timezone.now, blank=True)
price = models.DecimalField(max_digits=4, decimal_places=2)
user = models.CharField(max_length=64)
</code></pre>
<p>I want to query all bid prices placed on a particular item:</p>
<pre><code>bids = Bid.objects.all().filter(title=title)
</code></pre>
<p>Returns all items with that title, but I just want the <code>price</code> column. I tried :</p>
<pre><code>bids = bids.price
</code></pre>
<p>But it didn't work.</p>
| [
{
"answer_id": 74361110,
"author": "Naser Fazal khan",
"author_id": 19313399,
"author_profile": "https://Stackoverflow.com/users/19313399",
"pm_score": 3,
"selected": true,
"text": "bids = Bid.objects.all().filter(title=title).values_list(\"price\", flat = True)\n"
},
{
"answer_id": 74361113,
"author": "Divya Prakash",
"author_id": 11983208,
"author_profile": "https://Stackoverflow.com/users/11983208",
"pm_score": 0,
"selected": false,
"text": "bids = Bid.objects.filter(title=title)\nfor bid in bids:\n print(bid.price)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19339870/"
] |
74,360,956 | <p>I have the following dataframe:</p>
<pre><code>
df = data.frame(date = c("2021-11-17", "2021-11-17", "2022-05-11", "2022-05-11", "2021-11-04", "2021-11-04", "2022-06-09", "2022-06-09"),
participant_id = rep(c("sub-x", "sub-y"), each = 4))
</code></pre>
<p>In that way, sub-x has 4 rows associated (2 different dates and 2 rows per date) and sub-y too (the 4 last dates).</p>
<p>I would like to create a new column called "session" in which there would be, for each participant, either 1 or 2 depending on whether we are dealing with the rows of the first date among the 2 associated with the participant, or the rows of the second date.</p>
<p>It would look like this :</p>
<pre><code>df = data.frame(date = c("2021-11-17", "2021-11-17", "2022-05-11", "2022-05-11", "2021-11-04", "2021-11-04", "2022-06-09", "2022-06-09"),
participant_id = rep(c("sub-x", "sub-y"), each = 4)),
session = c("1", "1", "2", "2", "1", "1", "2", "2"))
</code></pre>
<p>NB : this is only a sample of my data. In reality, there are 28 rows per date of session and more than 400 participants.</p>
<p>How can I do that?</p>
<p>Thanks a lot in advance!</p>
| [
{
"answer_id": 74361110,
"author": "Naser Fazal khan",
"author_id": 19313399,
"author_profile": "https://Stackoverflow.com/users/19313399",
"pm_score": 3,
"selected": true,
"text": "bids = Bid.objects.all().filter(title=title).values_list(\"price\", flat = True)\n"
},
{
"answer_id": 74361113,
"author": "Divya Prakash",
"author_id": 11983208,
"author_profile": "https://Stackoverflow.com/users/11983208",
"pm_score": 0,
"selected": false,
"text": "bids = Bid.objects.filter(title=title)\nfor bid in bids:\n print(bid.price)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74360956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18631221/"
] |
74,361,034 | <p>here are a few rows of my data :</p>
<p>dput result :</p>
<pre><code> structure(list(A= c("2", "1, 2", "2", "2"), B= c("2",
"none", "1", "1")), row.names = 10:13, class = "data.frame")
</code></pre>
<p>actual data :</p>
<pre><code> A B
10 2 2
11 1, 2 none
12 2 1
13 2 1
</code></pre>
<p>I'm trying to replace 1 and 2 by their other values depending on the column, for column A for instance, 1 would be replaced by 'currently' and 2 by 'in the past', so my new data would be :</p>
<pre><code> A B
10 in the past 2
11 currently, in the past none
12 in the past 1
13 in the past 1
</code></pre>
<p>I'm using mapvalues from plyr which works fine except for the cases where I have multiple values like (1,2) for the same row, in the case, (1,2) are unchanged . is there another way to solve this?</p>
<p>the mapvalues command :</p>
<pre><code>dt$A = mapvalues(dt$A , old_values, new_values)
</code></pre>
| [
{
"answer_id": 74361131,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "df %>% \n na_if(\"none\") %>% \n mutate(A = A %>% str_replace_all(\"1\", \"currently\") %>% \n str_replace_all(\"2\", \"in the past\"))\n\n# A tibble: 4 x 2\n A B \n <chr> <chr>\n1 in the past 2 \n2 currently, in the past NA \n3 in the past 1 \n4 in the past 1 \n"
},
{
"answer_id": 74361134,
"author": "det",
"author_id": 12148402,
"author_profile": "https://Stackoverflow.com/users/12148402",
"pm_score": 1,
"selected": false,
"text": "stringi"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19323944/"
] |
74,361,048 | <p>I am using a for loop to plot a curve for each parameter-value (k) - this works just fine for all the negative k-values, but when the loop reaches the k values = 0 or greater, the lambdify function seems to collapse and I get an error stating the dimensions of x and y are not equal.</p>
<p>This is my code:</p>
<pre><code>import sympy as sym
import numpy as np
import matplotlib.pyplot as plt
eta = np.logspace(-1,2,21) #defines eta values, 21 decades from 0.1 to 100
relrho = np.logspace(-2,2,25) #defines values of rho2/rho1, 25 values from 0.01 to 100
k = (relrho-1)/(relrho+1) #defines the reflection coefficient
#parameter of type curve is k
#rhoa/rho1 is the y-axis
#eta is the x-axis
#R is assigned as the ratio of rho_a to rho_1
#x is assigned to eta
#y is assigned to k
x = sym.symbols('x', real = True)
y = sym.symbols('y')
for y in k: #for-loop assumes k value before while-loop is run, then plots the curve, then new k value is assumed
n=1; R=1;
while n<=500:
Rnew = 2*x**3*y**n/(((2*n)**2+x**2)**(3/2))
R = R + Rnew
n = n + 1
R = sym.lambdify(x,R)
plt.loglog(eta, R(eta))
plt.show()
</code></pre>
<p>What is going wrong? I am completely at a dead end right now... clueless...</p>
<p>If I plot the curves individually I can plot them for any k-value just fine, but in the loop it collapses after 12 iterations.</p>
<pre><code>runfile('C:/Users/aslak/OneDrive/Desktop/Typecurves.py', wdir='C:/Users/aslak/OneDrive/Desktop')
Traceback (most recent call last):
File "C:\Users\aslak\OneDrive\Desktop\Typecurves.py", line 44, in <module>
plt.loglog(eta, R(eta))
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2750, in loglog
return gca().loglog(*args, **kwargs)
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1868, in loglog
return self.plot(
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1743, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 273, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 399, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (21,) and (1,)
runfile('C:/Users/aslak/OneDrive/Desktop/Typecurves.py', wdir='C:/Users/aslak/OneDrive/Desktop')
Traceback (most recent call last):
File "C:\Users\aslak\OneDrive\Desktop\Typecurves.py", line 34, in <module>
plt.loglog(eta, R(eta))
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2750, in loglog
return gca().loglog(*args, **kwargs)
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1868, in loglog
return self.plot(
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1743, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 273, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\aslak\anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 399, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (21,) and (1,)
</code></pre>
| [
{
"answer_id": 74361131,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "df %>% \n na_if(\"none\") %>% \n mutate(A = A %>% str_replace_all(\"1\", \"currently\") %>% \n str_replace_all(\"2\", \"in the past\"))\n\n# A tibble: 4 x 2\n A B \n <chr> <chr>\n1 in the past 2 \n2 currently, in the past NA \n3 in the past 1 \n4 in the past 1 \n"
},
{
"answer_id": 74361134,
"author": "det",
"author_id": 12148402,
"author_profile": "https://Stackoverflow.com/users/12148402",
"pm_score": 1,
"selected": false,
"text": "stringi"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449651/"
] |
74,361,070 | <p>I enjoyed using GitKraken (v8.9) until I updated my current Fedora 36 distribution.</p>
<p>After the update, I had the problem that GitKraken crashed every time I wanted to open a repository tab or when I wanted to open the "File/Settings..." view.</p>
<p>I've updated GitKraken to the latest version and also looked at what the Fedora update includes, which may have caused the problem.</p>
<p>Additionally, I collected the coredump of the crash (via <code>coredumpctl gdb</code> and the crash log via <code>journalctl -xf</code>)</p>
<pre><code> Command Line: $'/usr/share/gitkraken/gitkraken --type=renderer --enable-crashpad --crashpad-handler-pid=3178 --enable-crash-reporter=dde15cd3-eccc-4db0-abbf-4626ba853f5f,no_channel --user-data-dir=/home/hugo/.config/GitKraken --standard-schemes --secure-schemes --bypasscsp-schemes=sentry-ipc --cors-schemes=sentry-ipc --fetch-schemes=sentry-ipc --service-worker-schemes --streaming-schemes --app-path=/usr/share/gitkraken/resources/app.asar --no-sandbox --no-zygote --node-integration-in-worker --disable-gpu-compositing --lang=en-US --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=9 --launch-time-ticks=54958457852 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,890488252484140780,4810308880598401477,131072 --disable-features=PlzServiceWorker,SpareRendererForSitePerProcess --enable-crashpad'
Executable: /usr/share/gitkraken/gitkraken
Control Group: /user.slice/user-1000.slice/user@1000.service/app.slice/app-gnome-gitkraken-2553.scope
Unit: user@1000.service
User Unit: app-gnome-gitkraken-2553.scope
Slice: user-1000.slice
Owner UID: 1000 (hugo)
Boot ID: 8bdd7f9dd7194682b2286579c96c8ec7
Machine ID: 70b436a43d284e9f9e7f1073bc0cf15b
Hostname: tag009442760151
Storage: /var/lib/systemd/coredump/core.gitkraken.1000.8bdd7f9dd7194682b2286579c96c8ec7.56008.1667909034000000.zst (present)
Disk Size: 77.8M
Message: Process 56008 (gitkraken) of user 1000 dumped core.
Module linux-vdso.so.1 with build-id 28de22885e5a5f761e8b05fe6d610d65bb875b04
Module nsfw.node without build-id.
Module libxkbfile.so.1 with build-id e9e99444598d67ff8514b6adfb390156611311d6
Stack trace of thread 56072:
#0 0x00007f26c336cffc __strlen_evex (libc.so.6 + 0x16cffc)
#1 0x00007f26bf3d351e _ZN14FontDescriptorC2EPKcS1_S1_S1_10FontWeight9FontWidthbb (fontmanager.node + 0xb51e)
#2 0x00007f26bf3d8f19 _Z20createFontDescriptorP10_FcPattern (fontmanager.node + 0x10f19)
#3 0x00007f26bf3d8fb9 _Z12getResultSetP10_FcFontSet (fontmanager.node + 0x10fb9)
#4 0x00007f26bf3d9182 _ZN15FontManagerImpl17getAvailableFontsEPP9ResultSet (fontmanager.node + 0x11182)
#5 0x00007f26bf3d7c7e _ZN18PromiseAsyncWorkerI9ResultSetE7ExecuteEv (fontmanager.node + 0xfc7e)
#6 0x00005602f9af87c1 n/a (gitkraken + 0x20257c1)
#7 0x00007f26c328cded start_thread (libc.so.6 + 0x8cded)
#8 0x00007f26c3312370 __clone3 (libc.so.6 + 0x112370)
</code></pre>
<p>With this information I contacted GitKraken support. The information I got from them is that it's a known issue that GitKraken can't handle some custom fonts, and the most common culprit is JetBrains fonts.</p>
<p>I also got a list of certain fonts that are known to cause problems viz</p>
<ul>
<li>RedHatFont</li>
<li>JetBrains Mono font on Fedora 34 and Ubuntu 20.04 (see comments on this issue).</li>
<li>Vazir</li>
<li>Rubik</li>
</ul>
<p>I didn't have any of these fonts installed, so it wasn't applicable to me.</p>
<p>Does someone face the same problem and has a solution to that?</p>
| [
{
"answer_id": 74361316,
"author": "drhookson",
"author_id": 17152242,
"author_profile": "https://Stackoverflow.com/users/17152242",
"pm_score": 1,
"selected": false,
"text": "$ sudo dnf remove wine-\\*-fonts\nDependencies resolved.\n=====================================================================================================================================================\n Package Architecture Version Repository Size\n=====================================================================================================================================================\nRemoving:\n wine-arial-fonts noarch 7.19-1.fc36 @updates 157 k\n wine-courier-fonts noarch 7.19-1.fc36 @updates 170 k\n wine-fixedsys-fonts noarch 7.19-1.fc36 @updates 37 k\n wine-marlett-fonts noarch 7.19-1.fc36 @updates 32 k\n wine-ms-sans-serif-fonts noarch 7.19-1.fc36 @updates 4.6 M\n wine-small-fonts noarch 7.19-1.fc36 @updates 65 k\n wine-symbol-fonts noarch 7.19-1.fc36 @updates 51 k\n wine-system-fonts noarch 7.19-1.fc36 @updates 121 k\n wine-tahoma-fonts noarch 7.19-1.fc36 @updates 300 k\n wine-times-new-roman-fonts noarch 7.19-1.fc36 @updates 170 k\n wine-webdings-fonts noarch 7.19-1.fc36 @updates 30 k\n wine-wingdings-fonts noarch 7.19-1.fc36 @updates 35 k\nRemoving dependent packages:\n wine-fonts noarch 7.19-1.fc36 @updates 0 \nRemoving unused dependencies:\n liberation-narrow-fonts noarch 2:1.07.6-8.fc36 @fedora 504 k\n\nTransaction Summary\n=====================================================================================================================================================\nRemove 14 Packages\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17152242/"
] |
74,361,073 | <p>I have a widget developed with Jetpack Compose and with the Jetpack Glance library, this widget is a LazyColumn list, in which I pass the information after making a query to the Room Database database.</p>
<p><a href="https://i.stack.imgur.com/2VI77.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2VI77.png" alt="enter image description here" /></a></p>
<p>To try to load the image I used <strong>Image()</strong> with the <strong>provider</strong>, passing it a string (which is the url of the image I want to load)</p>
<pre><code>Image(
modifier = GlanceModifier.size(50.dp),
provider = ImageProvider(item.image),
contentDescription = null
)
</code></pre>
<p>This didn't load the image and I tried to pass that image url to a bitmap, to load it with BitmapImageProvider(), but it didn't work. Is there a way to load a remote image to a widget using Jetpack Glance?</p>
| [
{
"answer_id": 74584916,
"author": "mars8",
"author_id": 15597975,
"author_profile": "https://Stackoverflow.com/users/15597975",
"pm_score": 0,
"selected": false,
"text": "path"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11365133/"
] |
74,361,095 | <p>Currently I have some code that when selecting a value from a dropdown list will paint a specific path of a svg image.</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>var paths1 = {
"https://www.google.com": {
color: "#eb8c00",
selector: "#path1"
},
"https://www.yahoo.com": {
color: "#eb8c00",
selector: "#path2"
},
}
$('#path').on("change", function() {
$('#path1, #path2').css({
fill: "#FFFFFF"
});
var value = $(this).val()
if (!value) {
return;
}
var {
color,
selector
} = paths1[value]
$(selector).css({
fill: color
});
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div name="svg">
<svg id="Layer_1" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px" width="500px" height="500px"
viewBox="0 0 500 500"
enable-background="new 0 0 500 500"
xml:space="preserve">
<path id="path1"
fill="#FFFFFF"
stroke="#231F20"
stroke-miterlimit="10"
d="M291.451,51.919v202.54c0,0,164.521,119.846,140.146,0 C407.227,134.613,291.451,51.919,291.451,51.919z"/>
<path id="path2"
fill="#FFFFFF"
stroke="#231F20"
stroke-miterlimit="10"
d="M169.595,150.844c0,0-76.24,69.615-40.606,128.309 c35.634,58.695,155.798-51.867,151.654-85.993C276.498,159.034,177.054,89.42,169.595,150.844z"/>
</svg>
</div>
<select id="path" name="path" class="pathSelector">
<option value="">Select Path</option>
<option value="https://www.google.com">Google</option>
<option value="https://www.yahoo.com">Yahoo</option>
</select>
<div>
<input
type="button"
class="selectbutton"
value="Select"
onClick="window.open(path.value,'newtab'+path.value)">
</div></code></pre>
</div>
</div>
</p>
<p>It works fine, as the button will also redirect to a different page.Now I need to be able to the reverse. I want to click on a path and the dropdown selector will also change. Clicking on path1 will select Google and clicking on path2 will select Yahoo from my dropdown list.</p>
<p>How can I achieve this?</p>
| [
{
"answer_id": 74362415,
"author": "David NoHorizon",
"author_id": 19105712,
"author_profile": "https://Stackoverflow.com/users/19105712",
"pm_score": 1,
"selected": false,
"text": " function SelectADropdownItem(id, val) {\n var d = document.getElementById(id);\n for (var i = 0; i < d.length; i++) {\n if (d[i].value == val) {\n d[i].selected = true;\n } else {\n d[i].selected = false;\n }\n }\n }"
},
{
"answer_id": 74362437,
"author": "biberman",
"author_id": 15377355,
"author_profile": "https://Stackoverflow.com/users/15377355",
"pm_score": 3,
"selected": true,
"text": "$('#Layer_1 path').on(\"click\", function() {...});\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12662321/"
] |
74,361,120 | <p>Please help me with error 'Numeric value '' is not recognized'.</p>
<p>In Snowflake i am having a variable day_minus which holds a number, using this i want to return date value of current_date minus the value given in the variable.
If there is Null or empty passed in the variable i want to get current date minus 1.</p>
<p>For this i have written a code like below. But it throws me an error Numeric value '' is not recognized</p>
<p>But it throws an</p>
<p>set day_minus=7;</p>
<p>SELECT DATEADD(DAY, concat('-',nvl(nullif(try_to_number($day_minus) ,''),1)),current_date() );</p>
<p>Can you please correct me where i am doing mistake</p>
| [
{
"answer_id": 74361345,
"author": "NickW",
"author_id": 13658399,
"author_profile": "https://Stackoverflow.com/users/13658399",
"pm_score": 0,
"selected": false,
"text": "set day_minus='7';\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15488631/"
] |
74,361,127 | <pre><code>loginUsername = input("Enter Username: ")
loginPassword = input("Enter PASSWORD: ")
data=open('database.txt', 'r')
accounts = data.readlines()
for line in data:
accounts = line.split(",")
if (loginUsername == accounts[0] and loginPassword == accounts[1]):
print("LOGGED IN")
else:
print("Login FAILED")
print(accounts)
</code></pre>
<p>I want to make a text login system, which will ask for the username first. After checking the text file which stored username and password, the system will ask for password. But I don't know how to read the first column (which is username, the structure of the text file is "username, password"). If i use readlines() and split(","). But there is "n" at the end of the password.</p>
| [
{
"answer_id": 74361189,
"author": "psalt",
"author_id": 14234692,
"author_profile": "https://Stackoverflow.com/users/14234692",
"pm_score": 1,
"selected": false,
"text": "\\n"
},
{
"answer_id": 74362819,
"author": "Andreas Violaris",
"author_id": 19170534,
"author_profile": "https://Stackoverflow.com/users/19170534",
"pm_score": 2,
"selected": false,
"text": "# You should always use CamelCase for class names and snake_case\n# for everything else in Python as recommended in PEP8.\nusername = input(\"Enter Username: \")\npassword = input(\"Enter Password: \")\n\n# You can use a list to store the database's credentials.\ncredentials = []\n\n# You can use context manager that will automatically\n# close the file for you, when you are done with it.\nwith open(\"database.txt\") as data:\n for line in data:\n line = line.strip(\"\\n\")\n credentials.append(line.split(\",\"))\n\nauthorized = False\n\nfor credential in credentials:\n db_username = credential[0]\n db_password = credential[1]\n if username == db_username and password == db_password:\n authorized = True\n\nif authorized:\n print(\"Login Succeeded.\")\nelse:\n print(\"Login Failed.\")\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20424903/"
] |
74,361,130 | <p>I was trying to optimize code and wanted to use the <code>.Internal</code> implementation of <code>vapply</code> and got an Error I don't understand. (For now I'll take the warning of <code>?.Internal</code> seriously, that "Only true R wizards should even consider using this function" and use the user visible <code>vapply</code> but I'd like to understand the error better nontheless.)</p>
<pre><code>test <- rnorm(10000)
test_l <- as.list(test)
test_2 <- .Internal(vapply(test_l, \(x) x^2, numeric(1), FALSE))
# Error: '...' used in an incorrect context
</code></pre>
<p>Compare this to the code of the user visible <code>vapply</code>:</p>
<pre><code>function (X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)
{
FUN <- match.fun(FUN)
if (!is.vector(X) || is.object(X))
X <- as.list(X)
.Internal(vapply(X, FUN, FUN.VALUE, USE.NAMES))
}
</code></pre>
<p>Can someone explain to me why this does not work?</p>
<p>Some of my hypotheses:</p>
<p>Does it run in another namespace than the function body of the user visible <code>vapply</code> or do I call the user visible function instead of the <code>.Internal</code> for some other reason?</p>
<p>Is it because the internal <code>vapply</code> is a special internal, that works differently than other internals?</p>
<p>The R-ints manual [1] states:</p>
<blockquote>
<p>2.2 Special internals</p>
<p>There are also special .Internal functions: NextMethod, Recall, withVisible, cbind, rbind (to allow for the deparse.level argument), eapply, lapply and vapply.</p>
</blockquote>
<p>But does not give more detail.</p>
<p>Can someone give me more detail on those "Special internals"?</p>
<p>[1] <a href="https://cran.r-project.org/doc/manuals/R-ints.html#g_t_002eInternal-vs-_002ePrimitive" rel="nofollow noreferrer">https://cran.r-project.org/doc/manuals/R-ints.html#g_t_002eInternal-vs-_002ePrimitive</a></p>
| [
{
"answer_id": 74361550,
"author": "Roland",
"author_id": 1412059,
"author_profile": "https://Stackoverflow.com/users/1412059",
"pm_score": 3,
"selected": true,
"text": "R_DotsSymbol"
},
{
"answer_id": 74361939,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 1,
"selected": false,
"text": "vapply"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1999873/"
] |
74,361,145 | <p>I work currently on my todo list.</p>
<p>I manged to get the text value from my input but i dont now how to add and element with the text value inside the text area. I want to add the text from my input inside the textarea in the undordered list.</p>
<p>Green is the input field and i want to get it from there in the white field<a href="https://i.stack.imgur.com/U3rVN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U3rVN.png" alt="enter image description here" /></a></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>//query select to get button
let btn = document.querySelector('.add');
// selector to selct undorder list inside todotex
const ul = document.querySelector('.list');
//selector for input
const input = document.querySelector('input');
// eventlistner by button clicked
btn.addEventListener('click', function() {
var txt = input.value;
let li = document.createElement('li').innerHTML(txt);
ul.append(li);
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="card">
<div class="todoheader">TODO List</div>
<div class="todotext"></div>
<ul class="list">
</ul>
<div class="addtodo">
<button class="add" type="button"> + </button>
<input type="text" class="input" placeholder="add todo"></input>
</div>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74361550,
"author": "Roland",
"author_id": 1412059,
"author_profile": "https://Stackoverflow.com/users/1412059",
"pm_score": 3,
"selected": true,
"text": "R_DotsSymbol"
},
{
"answer_id": 74361939,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 1,
"selected": false,
"text": "vapply"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16850827/"
] |
74,361,146 | <p>I am new with the library mathplotlib on python.
I have a dataset containing french city with latitude and longitude and a mark between 0 and 10 for each of them. The higher the mark is, the better</p>
<p>I want to plot this coordinates on a map, and change the plotting color according to the mark (0 = red, 10 = green).</p>
<p>I managed to plot the French map but only with same color, and without taking into account the mark. I have no idea how to use the mark into the plot.</p>
<p>On my code, TMP is my dataset, containing:</p>
<ul>
<li>COM_LAT (latitude)</li>
<li>COM_LONG (longitude)</li>
<li>COM_MARK (double between 0 and 10)</li>
</ul>
<p>Can someone help me?</p>
<p>Thanks by advance</p>
<pre><code>import matplotlib
import matplotlib.pyplot as plt
import geopandas as gp
import plotly.express as px
tmp_geo = gp.GeoDataFrame(TMP,geometry = gp.points_from_xy(TMP.COM_LONG,TMP.COM_LAT))
axis = tmp_geo.plot(color = 'yellow', edgecolor = 'black')
tmp_geo.plot(ax = axis, color = 'blue')
</code></pre>
| [
{
"answer_id": 74361550,
"author": "Roland",
"author_id": 1412059,
"author_profile": "https://Stackoverflow.com/users/1412059",
"pm_score": 3,
"selected": true,
"text": "R_DotsSymbol"
},
{
"answer_id": 74361939,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 1,
"selected": false,
"text": "vapply"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5166034/"
] |
74,361,148 | <p>I'm in my early days of working with C# and threading and I'm in need of a data structure that can store key-value pairs like a dictionary, but after a certain time after being added I want the values to "expire", or get removed from the dictionary.</p>
<p>I have come up with an implementation that seems to work, but I was wondering if there might be any problems to it when used in a multi threaded environment.</p>
<ol>
<li>Are there any direct issues with my current implementation?</li>
<li>As all usage of the dictionary is protected by the semaphore, is this implementation to be considered thread-safe out of the box?</li>
</ol>
<pre><code>public class TokenCache<TKey, TValue>
where TKey : IEquatable<TKey>
where TValue : class
{
private readonly TimeSpan expirationTime;
private readonly SemaphoreSlim semaphore;
private readonly Dictionary<TKey, TValue> cache;
public TokenCache(TimeSpan expirationTime)
{
this.expirationTime = expirationTime;
this.semaphore = new SemaphoreSlim(1, 1);
this.cache = new Dictionary<TKey, TValue>();
}
public void Add(TKey key, TValue value)
{
this.semaphore.Wait();
try
{
this.cache[key] = value;
Task
.Run(() => Thread.Sleep(this.expirationTime))
.ContinueWith(t =>
{
this.Remove(key);
});
}
finally
{
this.semaphore.Release();
}
}
public void Remove(TKey key)
{
this.semaphore.Wait();
try
{
this.cache.Remove(key);
}
finally
{
this.semaphore.Release();
}
}
public TValue GetValueOrDefault(TKey key)
{
this.semaphore.Wait();
try
{
if (this.cache.TryGetValue(key, out var value))
{
return value;
}
return null;
}
finally
{
this.semaphore.Release();
}
}
}
</code></pre>
| [
{
"answer_id": 74361750,
"author": "Mo B.",
"author_id": 689923,
"author_profile": "https://Stackoverflow.com/users/689923",
"pm_score": -1,
"selected": false,
"text": "lock"
},
{
"answer_id": 74361753,
"author": "Petrusion",
"author_id": 14095739,
"author_profile": "https://Stackoverflow.com/users/14095739",
"pm_score": 2,
"selected": false,
"text": "Task.Run(() => Thread.Sleep(...))"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13034244/"
] |
74,361,165 | <p>I understand destructuring that it unpacks values from array into variables and using square brackets in useState means it is returning two values in that array, first one is value and second one is function that is used to change that value,
But I see [] when using custom hook, and It does not make any sense to me , Can anyone please explain me why variable [breeds] has square brackets around it. it is declared under useState.</p>
<pre><code> const ANIMALS = ["bird", "cat", "dog", "rabbit", "reptile"];
export const SearchParams = () => {
const [location, setLocation] = useState("");
const [animal, setAnimal] = useState('');
const [breed, setBreed] = useState('')
const [pets, setPets] = useState([]);
const [breeds] = useBreedList(animal);
useEffect(() => {
requestPets();
},[animal])
async function requestPets() {
const res = await fetch(
`http://pets-v2.dev-apis.com/pets?animal=${animal}&location=${location}&breed=${breed}`
);
const json = await res.json();
console.info('json is '+JSON.stringify(json))
setPets(json.pets);
console.warn("pets are " + JSON.stringify(pets));
}
return (
<div className="search-params">
<form>
<label htmlFor="location">
Location
<input
id="location"
value={location}
placeholder="Location"
onChange={(e) => setLocation(e.target.value)}
/>
</label>
<label htmlFor="animal">
Animal
<select
id="animal"
value={animal}
onChange={(e) => {
setAnimal(e.target.value);
setBreed("");
}}
onBlur={(e) => {
setAnimal(e.target.value);
setBreed("");
}}
>
<option />
{ANIMALS.map((animal) => (
<option key={animal}>{animal}</option>
))}
</select>
</label>
<label htmlFor="breed">
Breed
<select
id="breed"
value={breed}
onChange={(e) => setBreed(e.target.value)}
disabled={breeds.length === 0}
>
<option />
{breeds.map((breed) => (
<option key={breed}>{breed}</option>
))}
</select>
</label>
<button>Submit</button>
</form>
{pets.map((pet) => (
<Pet
name={pet.name}
animal={pet.animal}
breed={pet.breed}
key={pet.id}
/>
))}
</div>
);
}
</code></pre>
<p>This is custom hook</p>
<pre><code> const localCache = {};
export const useBreedList = (animal) => {
const [breedList, setBreedList] = useState([]);
const [status, setStatus] = useState("unloaded");
useEffect(() => {
if (!animal) {
setBreedList([])
} else if (localCache[animal]) {
setBreedList(localCache[animal])
} else {
requestBreedList();
}
async function requestBreedList() {
setBreedList([]);
setStatus("loading");
const res = await fetch(
`https://pets-v2.dev-apis.com/breeds?animal=${animal}`
)
const json = await res.json();
localCache[animal] = json.breeds || []
setBreedList(localCache[animal]);
setStatus("loaded");
}
}, [animal]);
return [breedList, status];
}
</code></pre>
| [
{
"answer_id": 74361250,
"author": "T.J. Crowder",
"author_id": 157247,
"author_profile": "https://Stackoverflow.com/users/157247",
"pm_score": 3,
"selected": true,
"text": "[breeds]"
},
{
"answer_id": 74548038,
"author": "web dev",
"author_id": 20530218,
"author_profile": "https://Stackoverflow.com/users/20530218",
"pm_score": 0,
"selected": false,
"text": "destructuring"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13100940/"
] |
74,361,171 | <p>I have an array list of <code>List<string></code> that contains values in the following order <code>["1m", "1cm", "4km","2cm"]</code> (Centimeters, meters and kilometers)</p>
<p>When I want to sort this array, I get a wrong answer. I use OrderBy:</p>
<pre><code>List<string> data = new List<string> { "1m", "1cm", "4km","2cm" };
var result= data.OrderBy(x => x).ToList();
</code></pre>
<p>the result is:</p>
<pre><code>{ "1cm", "1m", "2cm", "4km"}
</code></pre>
<p>But I want the answer to be this order-: <code>{ "1cm", "2cm", "1m", "4km"}</code></p>
| [
{
"answer_id": 74361573,
"author": "jdweng",
"author_id": 5015238,
"author_profile": "https://Stackoverflow.com/users/5015238",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nnamespace ConsoleApplication49\n{\n \n class Program\n {\n static void Main(string[] args)\n {\n List<string> data = new List<string> { \"1m\", \"1cm\", \"4km\", \"2cm\" };\n List<string> results = data.Select(x => new SortDistance(x)).OrderBy(x => x).Select(x => x.value).ToList();\n\n }\n }\n public class SortDistance : IComparable<SortDistance>\n {\n const string pattern = @\"(?'number'\\d+)(?'multiplier'.*)\";\n List<string> distanceOrder = new List<string>() { \"cm\", \"m\", \"km\" };\n public string value { get; set; }\n public int distance { get; set; }\n public string multiplier { get; set; }\n\n public SortDistance(string value)\n {\n this.value = value;\n Match match = Regex.Match(value, pattern);\n this.distance = int.Parse(match.Groups[\"number\"].Value);\n this.multiplier = match.Groups[\"multiplier\"].Value;\n }\n public int CompareTo(SortDistance other)\n {\n if (this.multiplier == other.multiplier)\n return this.distance.CompareTo(other.distance);\n else\n return distanceOrder.IndexOf(this.multiplier).CompareTo(distanceOrder.IndexOf(other.multiplier));\n }\n }\n}\n"
},
{
"answer_id": 74361736,
"author": "hossein sabziani",
"author_id": 4301195,
"author_profile": "https://Stackoverflow.com/users/4301195",
"pm_score": 3,
"selected": true,
"text": "first character"
},
{
"answer_id": 74361943,
"author": "Schmid",
"author_id": 5790966,
"author_profile": "https://Stackoverflow.com/users/5790966",
"pm_score": 1,
"selected": false,
"text": "enum Unit { cm, m, km }\n\nrecord Measurment(int Length, Unit Unit)\n{\n public override string ToString() => $\"{Length}{Enum.GetName(typeof(Unit), Unit)}\";\n\n public double NormalizedLength => Unit switch\n {\n Unit.cm => Length * 0.001,\n Unit.m => Length * 1.0,\n Unit.km => Length * 1000.0,\n _ => throw new NotImplementedException()\n };\n\n public static Measurment Parse(string source)\n {\n var digits = source.TakeWhile(char.IsDigit).Count();\n var length = int.Parse(source.AsSpan(0, digits));\n\n // switches with source.AsSpan(digits) in preview\n var measure = source[..digits] switch\n {\n \"cm\" => Unit.cm,\n \"m\" => Unit.m,\n \"km\" => Unit.km,\n _ => throw new NotImplementedException(),\n };\n return new Measurment(length, measure);\n }\n}\n"
},
{
"answer_id": 74362573,
"author": "Matthew Watson",
"author_id": 106159,
"author_profile": "https://Stackoverflow.com/users/106159",
"pm_score": 1,
"selected": false,
"text": "UnitsNet"
},
{
"answer_id": 74428157,
"author": "cooding",
"author_id": 20498170,
"author_profile": "https://Stackoverflow.com/users/20498170",
"pm_score": 2,
"selected": false,
"text": "private string[] normalaizeArray(string[] inputArray)\n{\n for (int i= 0 ; i < inputArray.Length; i++)\n {\n if(inputArray[i].Contains('m'))\n {\n inputArray[i] = (float.Parse(inputArray[i].Split('k')[0]) * 100).ToString();\n } else if(inputArray[i].Contains('km'))\n {\n inputArray[i] = (float.Parse(inputArray[i].Split('k')[0]) * 100*1000).ToString();\n }\n else\n {\n inputArray[i] = inputArray[i].Replace(\"cm\", \"\");\n }\n }\n inputArray = inputArray.OrderBy(x => int.Parse(x)).ToArray();\n for (int i = 0; i < inputArray.Length; i++)\n {\n if(int.Parse(inputArray[i])>1000*100)\n inputArray[i] = (float.Parse(inputArray[i])/1000).ToString() + \"km\"; \n else if(int.Parse(inputArray[i])>100)\n inputArray[i] = (float.Parse(inputArray[i])/100).ToString() + \"m\";\n else\n inputArray[i] = inputArray[i] + 'cm';\n }\n return inputArray;\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433637/"
] |
74,361,203 | <p>So I'm in the process of learning NestJs ways. I have a small NestJs backend with only a few routes. Some of them call postgreSQL. I don't want to use any ORM and directly use pg package.
So my next step is learning how to use ConfigService. I have successfully used it to configure all env vars in the backend, but I'm struggling to use it in a small file I use to configure postgreSQL. This is the configuration file (pgconnect.ts):</p>
<pre><code>import { Pool } from 'pg';
import configJson from './config/database.json';
import dotenv from 'dotenv';
dotenv.config();
const config = configJson[process.env.NODE_ENV];
const poolConfig = {
user: config.username,
host: config.host,
database: config.database,
password: config.password,
port: config.port,
max: config.maxClients
};
export const pool = new Pool(poolConfig)
</code></pre>
<p>database.json is a json file where I have all connect values divided by environment. Then in service classes I just:</p>
<pre><code>import { Injectable } from '@nestjs/common';
import { Response } from 'express';
import { pool } from 'src/database/pgconnect';
@Injectable()
export class MyService {
getDocumentByName(res: Response, name: string) {
pool.query(
<query, error treatment, etc>
});
}
<...> more queries for insert, update, other selects, etc
}
</code></pre>
<p>So how could I use ConfigService inside my configuration file ? I already tried to instance class like this:</p>
<pre><code>let configService = new ConfigService();
</code></pre>
<p>and what I would like to do is:</p>
<pre><code>const config = configJson[configService.get<string>('NODE_ENV')];
</code></pre>
<p>but it didn't work. You have to pass .env file path to <code>new ConfigService()</code>. And I need to use NODE_ENV var to get it, because it depends on environment. To get NODE_ENV without using ConfigService I would have to use dotenv, but if I'm going to use dotenv I don't need ConfigService in the first place.</p>
<p>So then I tried to create a class:</p>
<pre><code>import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'
const { Pool } = require('pg');
import configJson from './config/database.json';
@Injectable()
export class PgPool {
constructor(private configService: ConfigService) { };
config = configJson[this.configService.get<string>('NODE_ENV')];
poolConfig = {
user: this.config.username,
host: this.config.host,
database: this.config.database,
password: this.config.password,
port: this.config.port,
max: this.config.maxClients
};
static pool = new Pool(this.poolConfig);
}
export const PgPool.pool;
</code></pre>
<p>But this doesn't work in several ways. If I use non-static members, I can´t export pool member which is the only thing I need. If I use static members one can't access the other or at least I'm not understanding how one access the other.</p>
<p>So, the questions are: How do I use ConfigService outside of a class or how can I change pgconnect.ts file to do it's job ? If it's through a class the best would be to export only pool method.</p>
<p>Also if you think there's a better way to configure postgreSQL I would be glad to hear.</p>
| [
{
"answer_id": 74363264,
"author": "Jay McDoniel",
"author_id": 9576186,
"author_profile": "https://Stackoverflow.com/users/9576186",
"pm_score": 3,
"selected": true,
"text": "pg"
},
{
"answer_id": 74363462,
"author": "iLuvLogix",
"author_id": 9793532,
"author_profile": "https://Stackoverflow.com/users/9793532",
"pm_score": 1,
"selected": false,
"text": "/* INFO: Require json config file */\nconst fileNameConfigPGSQL = require('./config/pgconfig.json');\n\n/* INFO: Require file operations package */\nconst { Pool } = require('pg');\n\nconst pool = new Pool(fileNameConfigPGSQL);\n\nmodule.exports = {\n query: (text, params, callback) => {\n const start = Date.now()\n return pool.query(text, params, (err, res) => {\n const duration = Date.now() - start\n // console.log('executed query', { text, duration, rows: res.rowCount })\n callback(err, res)\n })\n },\n getClient: (callback) => {\n pool.connect((err, client, done) => {\n const query = client.query.bind(client)\n\n // monkey patch for the query method to track last queries\n client.query = () => {\n client.lastQuery = arguments\n client.query.apply(client, arguments)\n }\n\n // Timeout of 5 secs,then last query is logged\n const timeout = setTimeout(() => {\n // console.error('A client has been checked out for more than 5 seconds!')\n // console.error(`The last executed query on this client was: ${client.lastQuery}`)\n }, 5000)\n\n const release = (err) => {\n // calling 'done'-method to return client to pool\n done(err)\n\n // cleat timeout\n clearTimeout(timeout)\n\n // reset query-methode before the Monkey Patch\n client.query = query\n }\n\n callback(err, client, done)\n })\n }\n}\n\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2752520/"
] |
74,361,207 | <p>I have a case where I have a ViewModel that emits scroll values to a <code>StateFlow</code>. Now, my Composable view should scroll to the most recent value, but I can't figure out how to achieve that.</p>
<p>My view model looks something like this:</p>
<pre><code>class MyViewModel : ViewModel() {
private val scrollFlow = MutableStateFlow<Int>(0)
fun getScrollFlow(): StateFlow<Int> = scrollFlow.asStateFlow()
}
</code></pre>
<p>And my view is like this:</p>
<pre><code>@Composable
fun MyScrollingView() {
val viewModel = viewModel()
val scroll by viewModel.getScrollFlow().collectAsState()
val scrollState = rememberScrollState(0)
Column(modifier = Modifier.verticalScroll(scrollState)) {
// Content here
}
}
</code></pre>
<p>The thing here is, how do I make the scroll state to react to the values coming from the view model?</p>
| [
{
"answer_id": 74361971,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 0,
"selected": false,
"text": "LaunchedEffect"
},
{
"answer_id": 74362224,
"author": "zjmo",
"author_id": 14507326,
"author_profile": "https://Stackoverflow.com/users/14507326",
"pm_score": 3,
"selected": true,
"text": "val scrollState = rememberScrollState(0)\n\nrememberCoroutineScope().launch {\n viewModel.getScrollFlow()\n .flowOn(Dispatchers.Default)\n .onEach{scrollVal ->\n scrollState.animateScrollTo(scrollVal)\n }.collect()\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1755847/"
] |
74,361,213 | <p>I have a scenario where I need to edit very large files and the end result is rather simple, but achieving it has become a bit of a drag on my computer and memory. Due to downstream systems, I cannot load a duplicate file (according to a computed hash) twice. My workaround has been to move the first actual line/record to the end of the file without changing anything else. This method (shown below in Method 1) works great for files that are small enough, but now I have files that are extremely large. So I began working on Method 2 below, but I haven't quite figured out how to <em>stream</em> lines from an input file into an output file.</p>
<pre><code>#Method 1
$Prefix = Read-Host -Prompt "What do you want to use as the prefix for the updated file names? (The number 1 is the default)"
If ([string]::IsNullOrEmpty($Prefix)){$Prefix = '1_'}
If($Prefix[-1] -ne '_'){$Prefix = "$($Prefix)_"}
$files = (Get-ChildItem -LiteralPath $PWD -Filter '*.csv' -File)
Foreach ($inputFile in $files){
$A = Get-Content $inputFile
$Header = $A[0]
$Data = $A[2..($A.Count-1)]
$Footer = $A[1]
$Header, $Data, $Footer | Add-Content -LiteralPath "$($inputFile.DirectoryName)\$($Prefix)$($inputFile.BaseName).csv"
}
</code></pre>
<pre><code>#Work-in-progress Method 2
$inputFile = "\Input.csv"
$outputFile = "\Output.csv"
#Create StringReader
$sr = [System.IO.StringReader]::New((Get-Content $inputFile -Raw))
#Create StringWriter
$sw = [System.IO.StringWriter]::New()
#Write the Header
$sw.Write($sr.ReadLine())
#Get the first actual record as a string
$lastLine = $sr.ReadLine()
#Write the rest of the lines
$sw.Write($sr.ReadToEnd())
#Add the final line
$sw.Write($lastLine)
#Write everything to the outputFile
[System.IO.File]::WriteAllText($outputFile, $sw.ToString())
Get-Content:
Line |
5 | $sr = [System.IO.StringReader]::New((Get-Content $inputFile -Raw))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Insufficient memory to continue the execution of the program.
MethodInvocationException:
Line |
5 | $sr = [System.IO.StringReader]::New((Get-Content $inputFile -Raw))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling ".ctor" with "1" argument(s): "Value cannot be null. (Parameter 's')"
</code></pre>
<p>I'm having a bit of trouble comprehending the difference between a <code>StringWriter</code> itself and a <code>StringBuilder</code>, for example - why would I choose to use the <code>StringWriter</code> as I have rather than simply work with a <code>StringBuilder</code> directly? Most importantly though, the current iteration of Method 2 requires more memory than my system has and it isn't actually <em>streaming</em> the characters/lines/data from the input file to the output file. Are there built in methods for checking memory that I'm overlooking, or is there simply a better way to achieve my goal?</p>
| [
{
"answer_id": 74362413,
"author": "iRon",
"author_id": 1701026,
"author_profile": "https://Stackoverflow.com/users/1701026",
"pm_score": 1,
"selected": false,
"text": "$Prefix = Read-Host -Prompt \"What do you want to use as the prefix for the updated file names? (The number 1 is the default)\"\nIf ([string]::IsNullOrEmpty($Prefix)){$Prefix = '1_'}\nIf($Prefix[-1] -ne '_'){$Prefix = \"$($Prefix)_\"}\n\nGet-ChildItem -LiteralPath $PWD -Filter '*.csv' -File |\nImport-Csv |ForEach-Object -Begin { $Index = 0 } -Process {\n if ($Index++) { $_ } else { $Footer = $_ }\n} -End { $Footer } |\nExport-Csv -LiteralPath \"$($inputFile.DirectoryName)\\$($Prefix)$($inputFile.BaseName).csv\"\n"
},
{
"answer_id": 74362743,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 1,
"selected": true,
"text": "StreamReader"
},
{
"answer_id": 74370195,
"author": "Gregor y",
"author_id": 4496560,
"author_profile": "https://Stackoverflow.com/users/4496560",
"pm_score": 0,
"selected": false,
"text": "IO.FileStream"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15243610/"
] |
74,361,223 | <p>I have my footer built as a React component and I am trying to stick it to the bottom of the page. The website that I am building has dynamic content, meaning that some times the content will be 2 lines long and the footer will be in the middle of the page and some times it will be 5 paragraphs long making the footer finally go to the bottom.</p>
<p>I tried sticking the footer to the bottom with:</p>
<pre><code>position: absolute;
bottom: 0;
</code></pre>
<p>and similar solutions found on the web but none of the solutions helped me achieve my goal. It is important to be noted that I was styling the component with a stylesheet referred inside of the component's file. I also tried to wrap the component in a div and style the div to stick to the bottom when needed but I also failed there. And lastly I tried wrapping the content in a div and pushing away the footer component using <code>margin-bottom</code>.</p>
<p><b>Footer component code:</b></p>
<pre><code>import React, { Component } from 'react'
import './BottomBar.css'
class BottomBar extends Component {
render(){
return(
<>
<footer>
</footer>
</>
)
}
}
export default BottomBar
</code></pre>
<p><b>Footer component style code:</b></p>
<pre><code>footer{
padding: 0;
width: 100%;
background: #28282B;
color: white;
text-align: center;
}
.connection-links{
text-decoration: none;
color: white;
margin-left: 2vw;
}
#last-link{
margin-right: 2.5vw;
}
</code></pre>
<p>I removed all of the code that the previous solutions required to work (mainly because the solutions didn't work) to give you the idea of how the code is structured.</p>
| [
{
"answer_id": 74362413,
"author": "iRon",
"author_id": 1701026,
"author_profile": "https://Stackoverflow.com/users/1701026",
"pm_score": 1,
"selected": false,
"text": "$Prefix = Read-Host -Prompt \"What do you want to use as the prefix for the updated file names? (The number 1 is the default)\"\nIf ([string]::IsNullOrEmpty($Prefix)){$Prefix = '1_'}\nIf($Prefix[-1] -ne '_'){$Prefix = \"$($Prefix)_\"}\n\nGet-ChildItem -LiteralPath $PWD -Filter '*.csv' -File |\nImport-Csv |ForEach-Object -Begin { $Index = 0 } -Process {\n if ($Index++) { $_ } else { $Footer = $_ }\n} -End { $Footer } |\nExport-Csv -LiteralPath \"$($inputFile.DirectoryName)\\$($Prefix)$($inputFile.BaseName).csv\"\n"
},
{
"answer_id": 74362743,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 1,
"selected": true,
"text": "StreamReader"
},
{
"answer_id": 74370195,
"author": "Gregor y",
"author_id": 4496560,
"author_profile": "https://Stackoverflow.com/users/4496560",
"pm_score": 0,
"selected": false,
"text": "IO.FileStream"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20264406/"
] |
74,361,302 | <p>Hello guys I'm trying to write a program that generate a random password then cracks is it but I'm getting the error object of type 'NoneType' has no len()</p>
<pre class="lang-py prettyprint-override"><code>from random import choice
from string import ascii_lowercase
def nrndprint(n):
k=(''.join(choice(ascii_lowercase) for i in range(n))) #.join
print(k)
nrndprint(6)
</code></pre>
<pre><code>import itertools
def crack_pass(argpass):
alplist = list(map(chr,list(range(ord('a'),ord('z')+1))))
for combi in itertools.product(alplist,repeat=len(argpass)):
if "".join(combi)==argpass:
return combi
return '-1'
passwd = nrndprint(4)
print(passwd)
print(crack_pass(passwd))
</code></pre>
<p>I'm getting:</p>
<pre><code>#mqjz
#None
</code></pre>
<p>Expected:</p>
<pre><code>#mqjz
#('m','q','j','z')
</code></pre>
| [
{
"answer_id": 74361355,
"author": "Aymen",
"author_id": 5165980,
"author_profile": "https://Stackoverflow.com/users/5165980",
"pm_score": 3,
"selected": true,
"text": "NoneType"
},
{
"answer_id": 74361397,
"author": "Jimpsoni",
"author_id": 18195201,
"author_profile": "https://Stackoverflow.com/users/18195201",
"pm_score": 0,
"selected": false,
"text": "len()"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20155565/"
] |
74,361,334 | <p>whoever it may concerns</p>
<p>Hi, I am jake and I am new to azure cloud . I come from AWS background as part of my new assignments I am trying to connect azure Linux virtual machine using visual studio code as it is a allow connection only from using bastion. I have been establishing connections from weeks and never had problem . from yesterday having troubles connecting to it. it is taking ages to get error message in vs code where as when I try
<a href="https://i.stack.imgur.com/fmJo7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fmJo7.jpg" alt="enter image description here" /></a></p>
<p>logging through browser I am seeing internet connections issues. but when I checked my internet it has very good speed. I am attaching screenshot here for better understandings.</p>
<p>Thanks In Advance!</p>
<p>connectivity issue with azure linux virtual machine using vs-code</p>
| [
{
"answer_id": 74361355,
"author": "Aymen",
"author_id": 5165980,
"author_profile": "https://Stackoverflow.com/users/5165980",
"pm_score": 3,
"selected": true,
"text": "NoneType"
},
{
"answer_id": 74361397,
"author": "Jimpsoni",
"author_id": 18195201,
"author_profile": "https://Stackoverflow.com/users/18195201",
"pm_score": 0,
"selected": false,
"text": "len()"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361334",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20449785/"
] |
74,361,351 | <p>In pandas, it is possible to do the following:</p>
<pre><code><class 'pandas.core.frame.DataFrame'>
Int64Index: 99919 entries, 0 to 99918
Data columns (total 47 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 reason 99919 non-null object
</code></pre>
<p>Most of these entries contain <code>[]</code>, and some contain an actual object, e.g. <code>[{'a':'x', 'b':'y', 'c':'z'}]</code></p>
<p>I want to efficiently (<strong>without</strong> using <code>df.apply</code>) set all entries that contain only the empty list to e.g. <code>None</code>.</p>
<p>I thought that I might be able to do something like the following:</p>
<pre class="lang-py prettyprint-override"><code>df[df['reasons'].str.len() == 0]['reasons'] = None
</code></pre>
<p>but this does not work since it is setting it on a copy of the dataframe (see <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy</a>)</p>
<p>Usually in the case where I set something on <code>df[row][column]</code>, I can instead do:</p>
<pre class="lang-py prettyprint-override"><code>df.loc[:, (row, column)]
</code></pre>
<p>to set it on the actual dataframe, but that does not work in this case since <code>df['reasons'].str.len() == 0</code> returns a series which is unhashable and not a valid argument for <code>loc</code>.</p>
<p>Is there any way to do this without using <code>apply</code>?</p>
| [
{
"answer_id": 74361355,
"author": "Aymen",
"author_id": 5165980,
"author_profile": "https://Stackoverflow.com/users/5165980",
"pm_score": 3,
"selected": true,
"text": "NoneType"
},
{
"answer_id": 74361397,
"author": "Jimpsoni",
"author_id": 18195201,
"author_profile": "https://Stackoverflow.com/users/18195201",
"pm_score": 0,
"selected": false,
"text": "len()"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/991710/"
] |
74,361,363 | <p>I have this dataframe in R. It has the structure of a pedigree dataframe, with the <code>id</code>, <code>fid</code>, <code>mid</code> and <code>sex</code> columns.</p>
<pre><code>pedigree <- structure(list(id = c(212, 214, 263, 266, 273, 274, 275, 279,
280, 281, 286, 287, 312, 313, 314, 315, 316, 317, 318, 319, 320,
321, 322, 323, 324, 325, 326, 327, 332, 333, 334, 335, 336, 337,
338, 339, 340, 341, 346, 347, 348, 349, 389, 390, 391, 392, 413,
414, 415, 416, 466, 475, 476, 477, 478, 479, 480, 483, 486, 487,
491, 492, 493, 494, 498, 501, 502, 506, 507, 508, 509, 510, 511,
512, 513, 514, 518, 519, 542, 543, 544, 545, 546, 547, 551, 552,
553, 554, 555, 556, 564, 565, 568, 569, 570, 575, 576, 579, 580,
584, 585, 586, 589, 590, 593, 595, 596, 597, 598, 599, 614, 615,
616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 653, 654, 662,
663, 671, 672, 673, 674, 675, 676, 681, 682, 683, 684, 688, 689,
693, 694, 695, 696, 697, 698, 701, 702, 703, 704, 709, 710, 715,
716, 718, 720, 721, 722, 723, 724, 725, 726, 727, 730, 731, 736,
737, 738, 739, 740, 744, 745, 842, 843, 874, 875, 884, 885, 886,
887, 889, 890, 894, 895, 896, 897, 898, 903, 905, 906, 907, 908,
909, 910, 911, 912, 913, 914, 915, 917, 925, 926, 927, 928, 929,
931, 932, 936, 965, 999, 1000, 1006, 1007, 1041, 1043, 1044,
1046, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1099, 1100,
1101, 1321, 1322, 1368, 1551, 1552, 1553, 1554, 1555), fid = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 326, 326, 326, 326, 279, 320, 320, 320, 320, 320, 320,
320, 320, 320, 324, 324, 324, 324, 322, 322, 322, 324, 324, 324,
324, 324, 324, 324, 324, 324, 318, 318, 326, 326, 326, 326, 326,
326, 326, 326, 326, 326, 326, 326, 332, 332, 287, 287, 287, 287,
287, 286, 286, 346, 346, 346, 348, 348, 348, 326, 326, 326, 326,
326, 332, 332, 320, 320, 320, 320, 320, 287, 346, 346, 346, 346,
273, 273, 273, 273, 266, 334, 334, 334, 334, 334, 336, 336, 336,
336, 336, 336, 334, 334, 334, 334, 334, 334, 338, 338, 338, 338,
340, 340, 340, 338, 338, 334, 334, 334, 334, 334, 334, 334, 334,
314, 314, 314, 314, 314, 314, 314, 312, 312, 0, 0, 286, 286,
314, 314, 314, 314, 314, 314, 334, 334, 334, 334, 334, 389, 389,
389, 389, 389, 389, 389, 389, 389, 389, 389, 389, 338, 332, 332,
332, 332, 332, 332, 332, 346, 274, 391, 391, 391, 391, 0, 0,
0, 0, 316, 316, 316, 316, 316, 316, 316, 316, 842, 842, 842,
1041, 1041, 1041, 1043, 1043, 1043, 1043, 1043), mid = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 327, 327, 327, 327, 275, 321, 321, 321, 321, 321, 321,
321, 321, 321, 325, 325, 325, 325, 323, 323, 323, 325, 325, 325,
325, 325, 325, 325, 325, 325, 319, 319, 327, 327, 327, 327, 327,
327, 327, 327, 327, 327, 327, 327, 333, 333, 212, 212, 212, 212,
212, 214, 214, 347, 347, 347, 349, 349, 349, 327, 327, 327, 327,
327, 333, 333, 321, 321, 321, 321, 321, 212, 347, 347, 347, 347,
281, 281, 281, 281, 263, 335, 335, 335, 335, 335, 337, 337, 337,
337, 337, 337, 335, 335, 335, 335, 335, 335, 339, 339, 339, 339,
341, 341, 341, 339, 339, 335, 335, 335, 335, 335, 335, 335, 335,
315, 315, 315, 315, 315, 315, 315, 313, 313, 0, 0, 214, 214,
315, 315, 315, 315, 315, 315, 335, 335, 335, 335, 335, 390, 390,
390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 339, 333, 333,
333, 333, 333, 333, 333, 347, 280, 392, 392, 392, 392, 0, 0,
0, 0, 317, 317, 317, 317, 317, 317, 317, 317, 843, 843, 843,
1044, 1044, 1044, 1046, 1046, 1046, 1046, 1046), sex = structure(c(1L,
1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L), levels = c("1", "2"), class = "factor")), row.names = c(NA,
-234L), class = c("tbl_df", "tbl", "data.frame"))
</code></pre>
<p>I am trying to do a pedigree analysis by using <code>pedtools</code>.</p>
<p>In order to convert this dataframe into a ped object, I use this <code>as.ped(pedigree)</code> function.</p>
<p>However, I see this malformed pedigree information:</p>
<pre><code>as.ped(pedigree)
Error: Malformed pedigree.
Individual 287 is female, but appear as the father of 568
Individual 212 is male, but appear as the mother of 568
</code></pre>
<p>I checked the ids <code>568</code>, <code>287</code> and <code>212</code>, but everything is properly assigned. This means that <code>287</code>is the mother of <code>568</code> (it is included in <code>fid</code>) and similarly with <code>287</code>.</p>
<p>As a convention, <code>1</code> refers to males and <code>2</code> to females.</p>
<p>What might be happening?</p>
| [
{
"answer_id": 74361355,
"author": "Aymen",
"author_id": 5165980,
"author_profile": "https://Stackoverflow.com/users/5165980",
"pm_score": 3,
"selected": true,
"text": "NoneType"
},
{
"answer_id": 74361397,
"author": "Jimpsoni",
"author_id": 18195201,
"author_profile": "https://Stackoverflow.com/users/18195201",
"pm_score": 0,
"selected": false,
"text": "len()"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3751263/"
] |
74,361,396 | <p>I want to have a python application (app1) running that loads a bunch of data and functionality on start-up that I will use many many times. To avoid having to restart the application and re-load all that I would like to simply call a function inside that file whenever it is needed from another python application (app2). At the same time I would like to send arguments to said function from app2 and send the results back to it. What would I need to do in both files in order to make this request-response-type of interaction work?</p>
<p>I apologize if my phrasing is a bit confusing.</p>
<p>I tried letting the app that is supposed to send requests write to a csv file which the other app scans for entries, but I would like something more direct and efficient, that only does anything if a request is sent and stays dormant until the next request comes in.</p>
<p>Edit: App2 is only executed to send a new request, while App1 is running permanently. So App2 needs to trigger a function inside App1 which will calculate a result based on the information loaded by App1 and the arguments sent by App2.</p>
<p>Edit2: Image for clarification:
<a href="https://i.stack.imgur.com/I37Vr.png" rel="nofollow noreferrer">Image</a></p>
| [
{
"answer_id": 74361355,
"author": "Aymen",
"author_id": 5165980,
"author_profile": "https://Stackoverflow.com/users/5165980",
"pm_score": 3,
"selected": true,
"text": "NoneType"
},
{
"answer_id": 74361397,
"author": "Jimpsoni",
"author_id": 18195201,
"author_profile": "https://Stackoverflow.com/users/18195201",
"pm_score": 0,
"selected": false,
"text": "len()"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16660380/"
] |
74,361,400 | <p>I am extending the user model, and it works on my local server but does not work on Heroku, nor does it work on Python anywhere. I am using Postgres. It's a fresh database. I can't even run a makemigration due to this error. My setting file also have the</p>
<p>error:</p>
<pre><code>(mysite-virtualenv) 06:21 ~/go-all-nations-2-backend (main)$ python manage.py makemigrations
/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/environ/environ.py:784: UserWarning: Error reading /home/evolvingte
ch/go-all-nations-2-backend/.env - if you're not configuring your environment separately, check this.
warnings.warn(
Traceback (most recent call last):
File "/home/evolvingtech/go-all-nations-2-backend/manage.py", line 22, in <module>
main()
File "/home/evolvingtech/go-all-nations-2-backend/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_f
rom_command_line
utility.execute()
File "/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/evolvingtech/.virtualenvs/mysite-virtualenv/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/evolvingtech/go-all-nations-2-backend/app_backend_api/models.py", line 8, in <module>
from django.contrib.auth.models import User, AbstractBaseUser, _user_get_all_permissions, AbstractUser, AbstractBaseUser, Group, Permission,
UserManager, _user_has_module_perms,_user_has_perm
ImportError: cannot import name '_user_get_all_permissions' from 'django.contrib.auth.models' (/home/evolvingtech/.virtualenvs/mysite-virtualenv/
lib/python3.9/site-packages/django/contrib/auth/models.py)
</code></pre>
<p>models:</p>
<pre><code>from django.db import models
from django.contrib.gis.db import models
#geo-location
from django.core.validators import RegexValidator
from django.dispatch import receiver
from django.db.models.signals import post_save
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import AbstractUser
from django.utils.translation import ugettext_lazy as _
# needed for the custom based tokens
from django.contrib.auth.models import User
REGEX_PHONE_NUMBER = RegexValidator(regex=r'^\d{10}$', message="PHONE MUST BE 10 DIGITS: '4731234567'.")
class CustomUser(AbstractUser):
org = models.CharField(max_length=200, blank=True)
def __str__(self):
return self.username
</code></pre>
<p>Settings file:</p>
<pre><code>AUTH_USER_MODEL = "app_backend_api.CustomUser"
</code></pre>
<p>Any thoughts anyone?</p>
| [
{
"answer_id": 74362290,
"author": "Jovan Vuchkov",
"author_id": 13774703,
"author_profile": "https://Stackoverflow.com/users/13774703",
"pm_score": 0,
"selected": false,
"text": "INSTALLED_APPS"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10672167/"
] |
74,361,483 | <p>I am trying to implement a simple LDAP authentication in my Symfony application.</p>
<p>A user should first be authenticated against LDAP, whereby a custom user entity should be returned from the database.</p>
<p>If a user is not in the database but could be authenticated successfully, I want to create the user.</p>
<p>Except for the automatic creation of the user in the database, it works so far.</p>
<pre class="lang-php prettyprint-override"><code>providers:
users_db:
entity:
# the class of the entity that represents users
class: 'App\Entity\User'
# the property to query by - e.g. email, username, etc
property: 'username'
users_ldap:
ldap:
service: Symfony\Component\Ldap\Ldap
base_dn: '%env(LDAP_BASE_DN)%'
search_dn: '%env(LDAP_SEARCH_DN)%'
search_password: '%env(LDAP_SEARCH_PASSWORD)%'
default_roles: ROLE_USER
uid_key: uid
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: users_db
http_basic_ldap:
service: Symfony\Component\Ldap\Ldap
dn_string: '%env(LDAP_DN_STRING)%'
</code></pre>
<p>With the above configuration, the auth runs against LDAP but the user comes from the DB. So if I have not created a corresponding user, the login attempt won't work.</p>
<p>I have tried the automatic creation of users via a <a href="https://symfony.com/doc/current/security/user_checkers.html" rel="nofollow noreferrer">UserChecker</a>, a <a href="https://symfony.com/doc/current/security/user_providers.html" rel="nofollow noreferrer">UserProvider</a> and a <a href="https://symfony.com/doc/current/security/custom_authenticator.html" rel="nofollow noreferrer">LoginEventListener</a> (listens to event <code>onAuthenticationSuccess</code>), unfortunately without success.</p>
<p>The onAuthenticationSuccess event is only called after successful authentication and can therefore not be used in the configuration described above, because the users_db provider does not (yet) contain the user, even if the LDAP Basic auth works.</p>
<p>Then I tried it with a <a href="https://symfony.com/doc/current/security/user_checkers.html" rel="nofollow noreferrer">UserChecker</a> and chained provider <code>[users_ldap, users_db]</code>. This is also executed, but then I no longer get a user object but an LDAP user. So I tried to create my own UserProvider, unfortunately without success.</p>
<p>If anyone knows a good way to do this, I would appreciate an answer or a short comment. Thank you!</p>
| [
{
"answer_id": 74382061,
"author": "Lubna Altungi",
"author_id": 18530022,
"author_profile": "https://Stackoverflow.com/users/18530022",
"pm_score": 1,
"selected": false,
"text": " <div>\n {{ form_row(user_form.uid, { label: 'UID :*',\n required: 'true',\n attr: {\n value : app.user.uid,\n readonly: true\n } \n }) }}\n </div>\n"
},
{
"answer_id": 74403236,
"author": "pnine",
"author_id": 2117102,
"author_profile": "https://Stackoverflow.com/users/2117102",
"pm_score": 1,
"selected": true,
"text": "\nservices:\n\n App\\Security\\UserProvider:\n arguments:\n $em: '@Doctrine\\ORM\\EntityManagerInterface'\n $ldap: '@Symfony\\Component\\Ldap\\Ldap'\n $baseDn: \"%env(LDAP_BASE_DN)%\"\n $searchDn: \"%env(LDAP_SEARCH_DN)%\"\n $searchPassword: \"%env(LDAP_SEARCH_PASSWORD)%\"\n $defaultRoles: [\"ROLE_USER\"]\n $uidKey: \"uid\"\n $extraFields: []\n\n App\\EventListener\\LoginListener:\n arguments:\n - \"@doctrine.orm.entity_manager\"\n\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2117102/"
] |
74,361,502 | <p>I have been getting the error:</p>
<blockquote>
<p>Exception: Too many simultaneous invocations: Spreadsheets</p>
</blockquote>
<p>I have looked on the <a href="https://developers.google.com/apps-script/guides/services/quotas#exception_messages" rel="nofollow noreferrer">quota page</a> and it doesn't say anything about opening spreadsheets. I am assuming a simultaneous invocation is where something happens at the same time as something else, but I would assume my script, which is only run from a single trigger, would work through each process one by one and, therefore, should not have anything happening simultaneously. Am I completely mistaken? I looked at <a href="https://stackoverflow.com/questions/61060108/does-google-app-script-simultaneous-executions-quota-apply-for-the-script-in-que">Does google app script simultaneous executions quota apply for the script in question or for each users?</a> but I still don't know what it is about.</p>
<p>I have tried running the script manually and it seems to work through each record absolutely fine and then it just hangs at the end, after reaching the last row (which was processed correctly).</p>
<p>My code is below:</p>
<pre><code>function importDataFromSAN() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const data = sheet.getDataRange().getValues();
data.shift();
const formSheet = SpreadsheetApp.openById('MyID');
const formData = formSheet.getDataRange().getValues();
formData.shift();
data.forEach(row => {
const fileURL = row[41];
const studentNumber = row[10];
if (fileURL === '') {
console.log('No form');
}
else {
const file = SpreadsheetApp.openByUrl(fileURL);
const medConditions = file.getRange('B49');
const currentSituation = file.getRange('B54');
const matchNumber = formData.filter(a => a[4] === studentNumber);
matchNumber.forEach(a => {
const healthNeeds = a[10];
const learningDifficulty = a[18];
const riskAssessment = a[27] + ' ' + a[29] + ' ' + a[31] + ' ' + a[33] + ' ' + a[35] + ' ' + a[37] + ' ' + a[39] + ' ' + a[41] + ' ' + a[43] + ' ' + a[45] + ' ' + a[47] + ' ' + a[49];
const outsideAgencies = a[73] + ' ' + a[75] + ' ' + a[77] + ' ' + a[79] + ' ' + a[81];
medConditions.setValue('Health Needs - ' + healthNeeds + '\nLearning Difficulties - ' + learningDifficulty);
currentSituation.setValue('Risk Assessment Details - ' + riskAssessment + '\nOutside Agencies Details - ' + outsideAgencies);
});
}
});
}
</code></pre>
<p>I tired running the script manually. I was expecting it to fail after hitting a certain number but it made it through all rows and then got hung up at the very end.</p>
<p>EDIT: After a long wait, it completed on the manual run. I do run a different script from a different project at the same time as this one, could that cause the issue, or is the limit per project and other projects have no impact?</p>
| [
{
"answer_id": 74382061,
"author": "Lubna Altungi",
"author_id": 18530022,
"author_profile": "https://Stackoverflow.com/users/18530022",
"pm_score": 1,
"selected": false,
"text": " <div>\n {{ form_row(user_form.uid, { label: 'UID :*',\n required: 'true',\n attr: {\n value : app.user.uid,\n readonly: true\n } \n }) }}\n </div>\n"
},
{
"answer_id": 74403236,
"author": "pnine",
"author_id": 2117102,
"author_profile": "https://Stackoverflow.com/users/2117102",
"pm_score": 1,
"selected": true,
"text": "\nservices:\n\n App\\Security\\UserProvider:\n arguments:\n $em: '@Doctrine\\ORM\\EntityManagerInterface'\n $ldap: '@Symfony\\Component\\Ldap\\Ldap'\n $baseDn: \"%env(LDAP_BASE_DN)%\"\n $searchDn: \"%env(LDAP_SEARCH_DN)%\"\n $searchPassword: \"%env(LDAP_SEARCH_PASSWORD)%\"\n $defaultRoles: [\"ROLE_USER\"]\n $uidKey: \"uid\"\n $extraFields: []\n\n App\\EventListener\\LoginListener:\n arguments:\n - \"@doctrine.orm.entity_manager\"\n\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17386103/"
] |
74,361,506 | <p>I have data resembling the following structure, where the <code>when</code> variable denotes the day of measurement:</p>
<pre><code>## Generate data.
set.seed(1986)
n <- 1000
y <- rnorm(n)
when <- as.POSIXct(strftime(seq(as.POSIXct("2021-11-01 23:00:00 UTC", tryFormats = "%Y-%m-%d"),
as.POSIXct("2022-11-01 23:00:00 UTC", tryFormats = "%Y-%m-%d"),
length.out = n), format = "%Y-%m-%d"))
dta <- data.frame(y, when)
head(dta)
#> y when
#> 1 -0.04625141 2021-11-01
#> 2 0.28000082 2021-11-01
#> 3 0.25317063 2021-11-01
#> 4 -0.96411077 2021-11-02
#> 5 0.49222664 2021-11-02
#> 6 -0.69874551 2021-11-02
</code></pre>
<p>I need to compute averages of <code>y</code> over time. For instance, the following computes daily averages:</p>
<pre><code>## Compute daily averages of y.
library(dplyr)
daily_avg <- dta %>%
group_by(when) %>%
summarise(daily_mean = mean(y)) %>%
ungroup()
daily_avg
#> # A tibble: 366 × 2
#> when daily_mean
#> <dttm> <dbl>
#> 1 2021-11-01 00:00:00 0.162
#> 2 2021-11-02 00:00:00 -0.390
#> 3 2021-11-03 00:00:00 -0.485
#> 4 2021-11-04 00:00:00 -0.152
#> 5 2021-11-05 00:00:00 0.425
#> 6 2021-11-06 00:00:00 0.726
#> 7 2021-11-07 00:00:00 0.855
#> 8 2021-11-08 00:00:00 0.0608
#> 9 2021-11-09 00:00:00 -0.995
#> 10 2021-11-10 00:00:00 0.395
#> # … with 356 more rows
</code></pre>
<p>I am having a hard time computing weekly averages. Here is what I have tried so far:</p>
<pre><code>## Fail - compute weekly averages of y.
library(lubridate)
dta$week <- week(dta$when) # This is wrong.
dta[165: 171, ]
#> y when week
#> 165 0.9758333 2021-12-30 52
#> 166 -0.8630091 2021-12-31 53
#> 167 0.3054031 2021-12-31 53
#> 168 1.2814421 2022-01-01 1
#> 169 0.1025440 2022-01-01 1
#> 170 1.3665411 2022-01-01 1
#> 171 -0.5373058 2022-01-02 1
</code></pre>
<p>Using the <code>week</code> function from the <code>lubridate</code> package ignores the fact that my data spawn across years. So, if I were to use a code similar to the one I used for the daily averages, I would aggregate observations belonging to different years (but to the same week number). How can I solve this?</p>
| [
{
"answer_id": 74361561,
"author": "r2evans - GO NAVY BEAT ARMY",
"author_id": 3358272,
"author_profile": "https://Stackoverflow.com/users/3358272",
"pm_score": 3,
"selected": true,
"text": "%V"
},
{
"answer_id": 74361674,
"author": "Robert Hacken",
"author_id": 2094893,
"author_profile": "https://Stackoverflow.com/users/2094893",
"pm_score": 2,
"selected": false,
"text": "dta %>% \n mutate(year = year(when),\n week = week(when)) %>%\n group_by(year, week) %>%\n summarise(y_mean = mean(y)) %>%\n ungroup()\n\n# # A tibble: 54 x 3\n# # Groups: year, week [54]\n# year week y_mean\n# <dbl> <dbl> <dbl>\n# 1 2021 44 -0.222 \n# 2 2021 45 0.234 \n# 3 2021 46 0.0953\n# 4 2021 47 0.206 \n# 5 2021 48 0.192 \n# 6 2021 49 -0.0831\n# 7 2021 50 0.0282\n# 8 2021 51 0.196 \n# 9 2021 52 0.132 \n# 10 2021 53 -0.279 \n# # ... with 44 more rows\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17692083/"
] |
74,361,513 | <p>I have a relationship as follows:</p>
<pre class="lang-rb prettyprint-override"><code>class Trip < ApplicationRecord
has_many :trip_destinations, dependent: :destroy
end
class TripDestination < ApplicationRecord
belongs_to :trip
validates :start_date, presence: true
validates :end_date, presence: true
end
</code></pre>
<p>I want to write a query that returns <strong>all trips where the <code>MIN(trip_destinations.start_date)</code> is before <code>Date.today</code> but the <code>MAX(trip_destinations.end_date)</code> is after <code>Date.today</code></strong>; that is, <code>Trip</code> still has <code>TripDestination</code>s that start before today AND end after today.</p>
<h2>Debugging so far:</h2>
<p>Currently, what I have is:</p>
<pre class="lang-rb prettyprint-override"><code> Trip
.joins(:trip_destinations)
.where("
trip_destinations.start_date = (
SELECT MIN(trip_destinations.start_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.start_date <= ?", today
)
.where("
trip_destinations.end_date = (
SELECT MAX(trip_destinations.end_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.end_date > ?", today
)
.group("trips.id")
</code></pre>
<p>Outputed SQL:</p>
<pre><code> SELECT 1 AS one FROM "trips" INNER JOIN "trip_destinations" ON "trip_destinations"."trip_id" = "trips"."id" WHERE "trips"."published" = $1 AND (
trip_destinations.start_date = (
SELECT MIN(trip_destinations.start_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.start_date <= '2022-11-08') AND (
trip_destinations.end_date = (
SELECT MAX(trip_destinations.end_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.end_date > '2022-11-08') GROUP BY "trips"."id" LIMIT $2 [["published", true], ["LIMIT", 1]]
</code></pre>
<p>which returns an empty set <code>[]</code>, even though I've manually verified that a <code>Trip</code> exists of this nature.</p>
<p>What's more, I can <strong>break down the SQL query in to the component <code>WHERE</code> clauses and they both work independently</strong>.
i.e.</p>
<pre class="lang-rb prettyprint-override"><code> Trip
.joins(:trip_destinations)
.where("
trip_destinations.start_date = (
SELECT MIN(trip_destinations.start_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.start_date <= ?", today
)
</code></pre>
<p>Returns the trip, and also</p>
<pre class="lang-rb prettyprint-override"><code> Trip
.joins(:trip_destinations)
.where("
trip_destinations.end_date = (
SELECT MAX(trip_destinations.end_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
AND trip_destinations.end_date > ?", today
)
</code></pre>
<p>returns the trip. However, when I chain those <code>WHERE</code> together, for some reason <code>ActiveRecord</code> or <code>Postgres</code> don't like it.</p>
<p>It's probably worth noting too, that I don't need to include the <code>start_date <= ?</code> for this to break.</p>
<pre class="lang-rb prettyprint-override"><code> Trip
.joins(:trip_destinations)
.where("
trip_destinations.start_date = (
SELECT MIN(trip_destinations.start_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
)
.where("
trip_destinations.end_date = (
SELECT MAX(trip_destinations.end_date) FROM trip_destinations
WHERE trips.id = trip_destinations.trip_id
)
)
.group("trips.id")
</code></pre>
<p>also returns an empty set.</p>
<h2>Desired outcome</h2>
<p>A single query (subqueries are fine) which returns all <code>Trip</code> records that have at least one <code>TripDestination</code> with a <code>start_date <= Date.today</code> and <code>end_date > Date.today</code></p>
| [
{
"answer_id": 74362060,
"author": "Slth",
"author_id": 16907209,
"author_profile": "https://Stackoverflow.com/users/16907209",
"pm_score": 0,
"selected": false,
"text": "Trip.joins(:trip_destinations)\n .where(\n \"(\n trip_destinations.start_date = (\n SELECT MIN(trip_destinations.start_date) FROM trip_destinations WHERE trips.id = trip_destinations.trip_id\n )\n AND trip_destinations.start_date <= ?\n ) AND\n (\n trip_destinations.end_date = (\n SELECT MAX(trip_destinations.end_date) FROM trip_destinations WHERE trips.id = trip_destinations.trip_id\n )\n AND trip_destinations.end_date > ?\n )\", today, today\n )\n"
},
{
"answer_id": 74363093,
"author": "Mohamed Camara GUEYE",
"author_id": 9203715,
"author_profile": "https://Stackoverflow.com/users/9203715",
"pm_score": 0,
"selected": false,
"text": " scope :strict, -> {\n distinct\n .joins(:trip_destinations)\n .where(trip_destinations: {\n start_date: ..DateTime.now.beginning_of_day\n })\n .where('trip_destinations.end_date > ?', DateTime.now.end_of_day )\n }\n"
},
{
"answer_id": 74363801,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 2,
"selected": true,
"text": "Trip\n .joins(:trip_destinations)\n .where(trip_destinations: {start_date: ..Date.today, end_date: Date.today...})\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14716103/"
] |
74,361,523 | <p>hey guys i have a problem im making a timer in tkinter but i cant use <code>time.sleep()</code> so i use <code>.after()</code> and i have new problem,I made an entry that I want the entry number to be * 60 and after the set time, a text will be written that says <code>>> time is over!</code> ,but then, how should that 60 be converted into seconds? my code:</p>
<pre><code>from tkinter import *
from playsound import playsound
from time import sleep
import time
def jik():
a = int(text.get())
app.after(a * 600)
Label(app,text="time is over").pack()
app = Tk()
app.minsize(300,300)
app.maxsize(300,300)
text = Entry(app,font=20)
text.pack()
Button(app,text="start",command=jik).pack()
app.mainloop()
</code></pre>
<p>For example, if I press the number 1, it <code>>>time is over</code> in a fraction of a second</p>
| [
{
"answer_id": 74361591,
"author": "Ahmed AEK",
"author_id": 15649230,
"author_profile": "https://Stackoverflow.com/users/15649230",
"pm_score": 0,
"selected": false,
"text": ".after"
},
{
"answer_id": 74361677,
"author": "oskros",
"author_id": 9490769,
"author_profile": "https://Stackoverflow.com/users/9490769",
"pm_score": 3,
"selected": true,
"text": "after"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20310213/"
] |
74,361,544 | <p>I'm trying to load data from the ExactOnline API into a spark DataFrame. Data comes out of the API in a <em>very</em> ugly format. I have multiple lines of valid JSON objects in one JSON file. One line of JSON looks as follows:</p>
<pre class="lang-json prettyprint-override"><code>{
"d": {
"results": [
{
"__metadata": {
"uri": "https://start.exactonline.nl/api_endpoint",
"type": "Exact.Web.Api.Models.Account",
},
"Accountant": null,
"AccountManager": null,
"AccountManagerFullName": null,
"AccountManagerHID": null,
...
},
{
"__metadata": {
"uri": "https://start.exactonline.nl/api_endpoint",
"type": "Exact.Web.Api.Models.Account",
},
"Accountant": null,
"AccountManager": null,
"AccountManagerFullName": null,
"AccountManagerHID": null,
...
}
]
}
}
</code></pre>
<p>What I need is that the keys of the dictionary's in the results list become the dataframe columns, and the number of dictionary's in the results become my rows. In the example I provided above, that would result in a dataframe with the following columns:</p>
<pre><code>__metadata|Accountant|AccountManager|AccountManagerFullName|AccountManagerHID
</code></pre>
<p>And two rows, one for each entry in the "results" list.</p>
<p>In Python on my local machine, I am easily able to achieve this by using the following code snippet:</p>
<pre class="lang-py prettyprint-override"><code>import json
import pandas as pd
folder_path = "path_to_json_file"
def flatten(l):
return [item for sublist in l for item in sublist]
with open(folder_path) as f:
# Extract relevant data from each line in the JSON structure and create a nested list,
# Where the "inner" lists are lists with dicts
# (1 line of JSON in my file = 1 inner list, so if my JSON file has 6
# lines the nested list will have 6 lists with a number of dictionaries)
data = [json.loads(line)["d"]["results"] for line in f]
# Flatten the nested lists into one giant list
flat_data = flatten(data)
# Create a dataframe from that flat list.
df = pd.DataFrame(flat_data)
</code></pre>
<p>However, I'm using a Pyspark Notebook in Azure Synapse, and the JSON files reside in our Data Lake so I cannot use <code>with open</code> to open files. I am limited to using spark functions. I have tried to achieve what I described above using <code>spark.explode</code> and <code>spark.select</code>:</p>
<pre class="lang-py prettyprint-override"><code>from pyspark.sql import functions as sf
df = spark.read.json(path=path_to_json_file_in_data_lake)
df_subset = df.select("d.results")
df_exploded = df_subset.withColumn("results", sf.explode(sf.col("results")))
</code></pre>
<p>df_exploded has the right number of <em>rows</em>, but not the proper columns. I think I'm searching in the right direction but cannot wrap my head around it. Some assistance would be greatly appreciated.</p>
| [
{
"answer_id": 74361662,
"author": "samkart",
"author_id": 8279585,
"author_profile": "https://Stackoverflow.com/users/8279585",
"pm_score": 2,
"selected": false,
"text": "spark.read.json()"
},
{
"answer_id": 74361704,
"author": "Steven",
"author_id": 5013752,
"author_profile": "https://Stackoverflow.com/users/5013752",
"pm_score": 2,
"selected": true,
"text": "df_exploded = df_subset.withColumn(\"results\", sf.explode(sf.col('results')))\n\ndf_exploded.select(\"results.*\").show()\n\n+--------------+----------------------+-----------------+----------+--------------------+\n|AccountManager|AccountManagerFullName|AccountManagerHID|Accountant| __metadata|\n+--------------+----------------------+-----------------+----------+--------------------+\n| null| null| null| null|[Exact.Web.Api.Mo...|\n| null| null| null| null|[Exact.Web.Api.Mo...|\n+--------------+----------------------+-----------------+----------+--------------------+\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7253901/"
] |
74,361,580 | <p>We were trying to publish the Allure report generated as part of our AzureDevops build pipeline and it seems Azuredevops has some limitations to publish the report and get a tab to analyze as part of the build output. So as per the <a href="https://marketplace.visualstudio.com/items?itemName=Molecula.allure-test-reports#:%7E:text=Please%20note%20that,should%20support%20HTTPS." rel="nofollow noreferrer">Allure Extensions document site</a> saying, we tried alternate option to publish the report to Azure webapp and seems its working fine. We cant try the "FTP Upload" task to upload the artifact to the webapp as its restricted in our environment, so tried with direct "webap deployment" task. Below are the tasks which we tried as part o the pipeline.</p>
<ul>
<li><p>task: CmdLine@2
condition: always()
inputs:
script: |
mvn allure:report</p>
</li>
<li><p>task: AzureRmWebAppDeployment@4
condition: always()<br />
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxxxxxxxxxx'
appType: 'webAppLinux'
WebAppName: 'xxxxxxxxxxxxx'
packageForLinux: '$(System.DefaultWorkingDirectory)/target/allure-report'</p>
</li>
</ul>
<p>We need to publish the report for each pipeline build and by doing the above "AzureRmWebAppDeployment" task, this will replace the previous report artifact and will deploy new one. So we are not getting report for each build.</p>
<p>We dont have FTP connectivity enabled to publish the artifacts to the Appservices and its restricted as per the policy.</p>
<p>So looking for a way to achieve the below items</p>
<ul>
<li>Should be able to Publish the Allure report of each build separately. ( looking for a solution to deploy the Allure reports seperately to the "wwwrroot" directory of webapp with bildnubmer as directory name.</li>
<li>Without using "FTP Upload" task, can we achieve this?</li>
<li>can we integrate the published result in azure webapp to the Build output interface as same as other results are showing in Azuredevops?</li>
</ul>
| [
{
"answer_id": 74443268,
"author": "Vowneee",
"author_id": 16092023,
"author_profile": "https://Stackoverflow.com/users/16092023",
"pm_score": 2,
"selected": true,
"text": "az webapp deploy --resource-group 'rg' --name 'apss' --src-path '$(System.DefaultWorkingDirectory)/$(Build.BuildId)/$(Build.BuildId).zip' --type zip --clean false --target-path '$(Build.BuildId)\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16092023/"
] |
74,361,593 | <p>I do not understand why the <code>&</code> in <code>&x</code> in the following Rust syntax actually copies the value behind a reference, hence, makes an owned value. In some sort, the <code>&</code> performs an "upgrade" of the value here, surprisingly. I expected that <code>&</code> would only create a reference (similar to the <code>ref</code> keyword) but never a copied version from a reference. To better demonstrate it, I provide a small example where rustc tells the actual type with an error message:</p>
<pre class="lang-rust prettyprint-override"><code>let opt: Option<u8> = Option::from(42_u8);
opt.filter(|x| {
// compiler fails: says 'x' has type "&u8"
let _: () = x;
true
});
opt.filter(|&x| {
// compiler fails: says 'x' has type "u8"
let _: () = x;
true
});
</code></pre>
<p>What is going on here? Any reference to the language documentation? This looks weird to me and I never saw this in my past four years with Rust.. or am I missing something?</p>
| [
{
"answer_id": 74361761,
"author": "Chayim Friedman",
"author_id": 7884305,
"author_profile": "https://Stackoverflow.com/users/7884305",
"pm_score": 2,
"selected": false,
"text": "&"
},
{
"answer_id": 74361763,
"author": "phip1611",
"author_id": 2891595,
"author_profile": "https://Stackoverflow.com/users/2891595",
"pm_score": 0,
"selected": false,
"text": "fn main() {\n match &5 {\n &x => {\n // compiles\n let _: i32 = x;\n }\n }\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2891595/"
] |
74,361,612 | <p>I need to replace multiple literals by digits in a string like "FF432423FA112". "A"=0, "B"=1 etc. I've tried to do it in a loop like but it didn't work. Tried also with char array</p>
<pre><code>String test = "FF432423FA112";
String[] letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
for (int i=0; i<letters.length; i++) {
newStr = test.replace(letters[i],i);
}
</code></pre>
| [
{
"answer_id": 74361761,
"author": "Chayim Friedman",
"author_id": 7884305,
"author_profile": "https://Stackoverflow.com/users/7884305",
"pm_score": 2,
"selected": false,
"text": "&"
},
{
"answer_id": 74361763,
"author": "phip1611",
"author_id": 2891595,
"author_profile": "https://Stackoverflow.com/users/2891595",
"pm_score": 0,
"selected": false,
"text": "fn main() {\n match &5 {\n &x => {\n // compiles\n let _: i32 = x;\n }\n }\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,361,633 | <p>I have a stream and I would like to extract one value based on the condition :</p>
<ul>
<li>If any match condition A find first that match A</li>
<li>Else if any match condition B find first that match B</li>
<li>Else if any match condition C find first that match C</li>
<li>Else null</li>
</ul>
<p>For example :</p>
<pre><code>Stream<String> stream0 = Stream.of("a", "b", "c", "d");
Stream<String> stream1 = Stream.of("b", "c", "d", "a");
Stream<String> stream2 = Stream.of("b", "c", "d", "e");
Stream<String> stream3 = Stream.of("d", "e", "f", "g");
findBestValue(stream0); //should return "a"
findBestValue(stream1); //should return "a"
findBestValue(stream2); //should return "b"
findBestValue(stream3); //should return null
</code></pre>
<p>I tried the following, but that return a <code>java.lang.IllegalStateException: stream has already been operated upon or closed</code></p>
<pre><code>private static String findBestValue(Stream<String> stream) {
return stream.filter(str -> str.equals("a"))
.findFirst()
.orElse(stream.filter(str -> str.equals("b"))
.findFirst()
.orElse(stream.filter(str -> str.equals("c"))
.findFirst()
.orElse(null))
);
}
</code></pre>
<p>Any idea how I could archive that ?</p>
<p>Note : a, b, c are just for the example I can't use .sort()</p>
| [
{
"answer_id": 74361817,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 2,
"selected": true,
"text": "IllegalStateException"
},
{
"answer_id": 74361832,
"author": "Moe Singh",
"author_id": 3817061,
"author_profile": "https://Stackoverflow.com/users/3817061",
"pm_score": 0,
"selected": false,
"text": " private static String findBestValue(List<String> list) {\n return list.stream().filter(str -> str.equals(\"a\"))\n .findFirst()\n .orElse(list.stream().filter(str -> str.equals(\"b\"))\n .findFirst()\n .orElse(list.stream().filter(str -> str.equals(\"c\"))\n .findFirst()\n .orElse(null)));\n }\n"
},
{
"answer_id": 74362648,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "private static <T> T findBestValue(Stream<T> stream, T... keys) {\n Set<T> set = stream.collect(Collectors.toSet());\n return Stream.of(keys)\n .filter(set::contains)\n .findFirst()\n .orElse(null);\n}\n\npublic static void main(String[] args) {\n Stream<String> stream0 = Stream.of(\"a\", \"b\", \"c\", \"d\");\n Stream<String> stream1 = Stream.of(\"b\", \"c\", \"d\", \"a\");\n Stream<String> stream2 = Stream.of(\"b\", \"c\", \"d\", \"e\");\n Stream<String> stream3 = Stream.of(\"d\", \"e\", \"f\", \"g\");\n\n System.out.println(findBestValue(stream0, \"a\", \"b\", \"c\")); //should return \"a\"\n System.out.println(findBestValue(stream1, \"a\", \"b\", \"c\")); //should return \"a\"\n System.out.println(findBestValue(stream2, \"a\", \"b\", \"c\")); //should return \"b\"\n System.out.println(findBestValue(stream3, \"a\", \"b\", \"c\")); //should return null\n}\n"
}
] | 2022/11/08 | [
"https://Stackoverflow.com/questions/74361633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10038235/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.