qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,236,523 | <p>Given following list:</p>
<pre><code>['21,*,1', '21,stuff,1', '21,*,10', '21,stuff,4', '21,*,1', '21,*,114', '21,stuff,1',
'28,*,37', '28,stuff,1', '28,*,4', '28,stuff,4', '28,*,4', '28,XXX,3', '28,stuff,1', '28,XXX,23', '28,XXX,87',
'38,*,72', '38,stuff,9', '38,*,6', '38,stuff,32', '38,stuff,3', '38,stuff,3', '38,XXX,1', '38,*,23',
'42,*,37', '42,XXX,1', '42,stuff,4']
</code></pre>
<p>I'd like to produce an array showing how many elements are contained in sub-lists (with first element in each sub-list being an id that'll always appear in ascending order: here 21, 28, 38 and 42): here we have 4 sub-lists starting respectively with 21, 28, 38 and 44, that contain 7, 9, 8 and 3 elements, so in this case a print of resulting array would be:<br />
<code>[['21', 7], ['28', 9], ['38', 8], ['42', 3]]</code></p>
<p>A beginner in Python, I'm looking for a simple and elegant way of doing this count...</p>
<p>Thanks a lot.<br />
Sebino</p>
| [
{
"answer_id": 74236554,
"author": "T C Molenaar",
"author_id": 8814131,
"author_profile": "https://Stackoverflow.com/users/8814131",
"pm_score": 0,
"selected": false,
"text": "for i in range(10):\n print(i)\n"
},
{
"answer_id": 74236665,
"author": "Cobra",
"author_id"... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253075/"
] |
74,236,524 | <p>It's for our class hangman game project, it's divided in many steps and the fourth one is :
<strong>Objective :</strong></p>
<ol>
<li><p>As in the previous stage, you should use the following word list: 'python', 'java', 'kotlin', 'javascript'</p>
</li>
<li><p>Once the computer has chosen a word from the list, show its first 3 letters. Hidden letters should be replaced with hyphens ("-").</p>
</li>
</ol>
<p><strong>Examples:</strong></p>
<p>Example 1</p>
<pre><code>H A N G M A N Guess the word jav-: > java
You survived!
</code></pre>
<p>Example 2</p>
<pre><code>H A N G M A N Guess the word pyt---: > pythia
You lost!
</code></pre>
<p><strong>My problem</strong></p>
<p>Here is my hint function witch is suppose to mask the characters after the third first one :</p>
<pre><code>
def hint(word: str) -> str:
print(word)
print(len(word))
# for the debugging the replace function seem to replace an identified 'string' by another
replaced = word.replace(word[3:], "-" * (len(word)-3))
print(replaced)
return replaced
</code></pre>
<p>It works with the other words (python, kotlin...) but when the word to guess is 'Java', it gives me as output "J-v-"</p>
| [
{
"answer_id": 74236615,
"author": "en3rgizer",
"author_id": 18420456,
"author_profile": "https://Stackoverflow.com/users/18420456",
"pm_score": 1,
"selected": false,
"text": "word = \"Java\"\nhiddenWord = word[:3]\nhiddenWord += '-' * (len(word)-3)\n"
},
{
"answer_id": 74236660,... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20137269/"
] |
74,236,531 | <p>I have 2 arrays:</p>
<p>First array is array of strings:</p>
<pre><code>let array1 = ['value1', 'value2', 'value3', 'value4', 'value5']
</code></pre>
<p>second is array of objects that can vary, meaning sometimes I will have all the values sometimes only some and they will not be sorted. Something like this:</p>
<pre><code>array2 = [
{
property1: 'value1',
property2: 42,
property3: 'some other value'
},
{
property1: 'value3',
property2: 342,
property3: 'some other value'
},
{
property1: 'value5',
property2: 422,
property3: 'some other value'
}
]
</code></pre>
<p>I need to make another array. If there is value1 from first array inside array2 I need to push to newly created array property2, if not I need to push 0. Order of the items needs to be the same as the array 1 meaning that in the end I will have an array that looks like this:</p>
<pre><code>array3 = [42, 0, 342, 0, 422]
</code></pre>
<p>Thanks</p>
<p>I have looked up on stackoverflow but no solution worked for me</p>
| [
{
"answer_id": 74236633,
"author": "Majed Badawi",
"author_id": 7486313,
"author_profile": "https://Stackoverflow.com/users/7486313",
"pm_score": 3,
"selected": true,
"text": "Array#reduce"
},
{
"answer_id": 74236634,
"author": "Harrison",
"author_id": 15291770,
"auth... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20358975/"
] |
74,236,541 | <p>I know that the name of an array is a constant pointer. I am wondering what is the case for the pointer returned by <code>malloc()</code>? Is it a constant pointer?</p>
| [
{
"answer_id": 74236674,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 3,
"selected": true,
"text": "@John Bollinger"
}
] | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18701489/"
] |
74,236,574 | <p>The default behaviour of <code>Ctrl+X</code> in VSCode in the absence of selected text is to cut the current line. I would like to configure VSCode so that <code>Ctrl+X</code> only works if text is selected. I have tried adding the following to my <code>keybindings.json</code> file</p>
<pre><code>[
// Cut only when selection
{
"key": "ctrl+x",
"command": "-editor.action.clipboardCutAction"
},
{
"key": "ctrl+x",
"command": "editor.action.clipboardCutAction",
"when": "editorHasSelection",
},
]
</code></pre>
<p>but it does not seem to take effect. What is the correct way to make <code>Ctrl+X</code> work only if text is selected?</p>
| [
{
"answer_id": 74237548,
"author": "mgarort",
"author_id": 7998725,
"author_profile": "https://Stackoverflow.com/users/7998725",
"pm_score": 1,
"selected": false,
"text": "Ctrl+X"
},
{
"answer_id": 74238761,
"author": "Mark",
"author_id": 836330,
"author_profile": "ht... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7998725/"
] |
74,236,584 | <p>I seem to hit a roadblock when it comes to joi's .or() function as it doesn't seem to implement as I'd expect.</p>
<p>I have 2 text input fields, both have their own way of validating, though only at least one is required.</p>
<pre class="lang-js prettyprint-override"><code> const schema = joi
.object({
"either-this-field": joi.string().trim().max(26),
"or-this-field": joi
.string()
.trim()
.regex(/^\d+$/)
.max(26)
"other-field-1": joi.string().required(),
"other-field-2": joi.string().max(40).required(),
})
.or("either-this-field", "or-this-field");
</code></pre>
<p>it just seems that this or doesn't do as I'd expect and each field from the or is just validated as per it's own validation rules</p>
<p>if neither field has values, then I'll display error for both fields until at least one is completed</p>
| [
{
"answer_id": 74237548,
"author": "mgarort",
"author_id": 7998725,
"author_profile": "https://Stackoverflow.com/users/7998725",
"pm_score": 1,
"selected": false,
"text": "Ctrl+X"
},
{
"answer_id": 74238761,
"author": "Mark",
"author_id": 836330,
"author_profile": "ht... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7696704/"
] |
74,236,629 | <p>How can I check if an <code>input_date</code> falls between two dates (a date range) in excel, where the date range exists in a list of date ranges?</p>
<p>So I need to check if input_date falls between <strong>any</strong> date range, and then if it does, return the value of the date ranged it matched with. See the below table for an example.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Month</th>
<th>Start Date</th>
<th>End Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>Month 1</td>
<td>1/1/2022</td>
<td>1/31/2022</td>
</tr>
<tr>
<td>Month 2</td>
<td>2/1/2022</td>
<td>2/27/2022</td>
</tr>
<tr>
<td>Month 3</td>
<td>3/1/2022</td>
<td>3/31/2022</td>
</tr>
</tbody>
</table>
</div>
<p>Input vs Expected Result</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>input_date</th>
<th>Expected Result = Month</th>
</tr>
</thead>
<tbody>
<tr>
<td>1/25/2022</td>
<td>Month 1</td>
</tr>
<tr>
<td>2/3/2022</td>
<td>Month 2</td>
</tr>
</tbody>
</table>
</div>
<p>I've tried using <code>=IF(AND(A2>StartDate,A2<EndDate),TRUE, FALSE)</code> but how can I check A2 against all date ranges in a list, and output the corresponding Month value? Is the best way really just nesting if statements for a fixed number of ranges? Any dynamic approach?</p>
| [
{
"answer_id": 74237548,
"author": "mgarort",
"author_id": 7998725,
"author_profile": "https://Stackoverflow.com/users/7998725",
"pm_score": 1,
"selected": false,
"text": "Ctrl+X"
},
{
"answer_id": 74238761,
"author": "Mark",
"author_id": 836330,
"author_profile": "ht... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7360071/"
] |
74,236,671 | <p>I currently need to add to tables that update each time the user clicks the "Save" button on a program that updates any of their information.
When any of the fields are amended, in order that we have a log of the changes, I need to create a record on a "slinfo" table including things like:</p>
<pre><code>Customer name (slinfo.name)
Customer account (slinfo.acode)
The date (slinfo.date)
And slinfo.seq, which is the sequence number for each change.
</code></pre>
<p>How would I go about doing something like this?</p>
| [
{
"answer_id": 74236860,
"author": "Tom Bascom",
"author_id": 123238,
"author_profile": "https://Stackoverflow.com/users/123238",
"pm_score": 0,
"selected": false,
"text": "/* presumably you already have a save trigger to save the amended values\n * this code should go in that trigger, p... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19557029/"
] |
74,236,677 | <p>I tried to make 'long' greater than 'longest'. This obviously should be reported as an error, but it was not reported. Why?</p>
<pre><code>fn test_lifetime<'long, 'longer, 'longest>(a: &'long str, b: &'longer str, c: &'longest str) where
'long: 'longest
{
println!("{}, {}, {}", a, b, c);
}
fn main() {
let longest = String::from("longest");
{
let longer = String::from("longer");
{
let long = String::from("long");
test_lifetime(long.as_str(), longer.as_str(), longest.as_str());
}
}
}
</code></pre>
| [
{
"answer_id": 74236831,
"author": "jthulhu",
"author_id": 5956261,
"author_profile": "https://Stackoverflow.com/users/5956261",
"pm_score": 3,
"selected": true,
"text": "'long"
},
{
"answer_id": 74239242,
"author": "fred xia",
"author_id": 16323026,
"author_profile":... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13482951/"
] |
74,236,697 | <p>I am making a <strong>Pong game program</strong> using <strong>Python</strong>. There is a <strong>white line in the middle of the screen</strong>, which I can't figure out why is there.
I am pasting my code and the output (the issue) below.</p>
<pre class="lang-py prettyprint-override"><code>import turtle
wm = turtle.Screen()
wm.title("Pong by Tharv")
wm.bgcolor("black")
# wm.setup(width=800, hieght=300)
wm.tracer(0)
# Bat A
batA = turtle.Turtle()
batA.speed(0)
batA.shape("square")
batA.shapesize(stretch_wid=5, stretch_len=1)
batA.color("white")
batA.penup()
batA.goto(-350, 0)
# Bat B
batB = turtle.Turtle()
batB.speed(0)
batB.shape("square")
batB.color("white")
batB.shapesize(stretch_wid=5, stretch_len=1)
batB.penup
batB.goto(350, 0)
# Ball
ball = turtle.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("white")
ball.penup()
ball.goto(0, 0)
# maingameloop
while True:
wm.update()
</code></pre>
<p><a href="https://i.stack.imgur.com/BYw4K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BYw4K.png" alt="The Issue" /></a></p>
<p>I have tried commenting out each line of code for the 'batB' (refer to the code please.) , but still can't understand why is there a white line in the middle.</p>
| [
{
"answer_id": 74236831,
"author": "jthulhu",
"author_id": 5956261,
"author_profile": "https://Stackoverflow.com/users/5956261",
"pm_score": 3,
"selected": true,
"text": "'long"
},
{
"answer_id": 74239242,
"author": "fred xia",
"author_id": 16323026,
"author_profile":... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20358930/"
] |
74,236,711 | <p>I'm contemplating making decisions on outliers on a dataset with over 300 features. I'd like to analyse the frame without removing the data hastingly. I have a frame:</p>
<pre><code> | | A | B | C | D | E |
|---:|----:|----:|-----:|----:|----:|
| 0 | 100 | 99 | 1000 | 300 | 250 |
| 1 | 665 | 6 | 9 | 1 | 9 |
| 2 | 7 | 665 | 4 | 9 | 1 |
| 3 | 1 | 3 | 4 | 3 | 6 |
| 4 | 1 | 9 | 1 | 665 | 5 |
| 5 | 3 | 4 | 6 | 1 | 9 |
| 6 | 5 | 9 | 1 | 3 | 2 |
| 7 | 1 | 665 | 3 | 2 | 3 |
| 8 | 2 | 665 | 9 | 1 | 0 |
| 9 | 5 | 0 | 7 | 6 | 5 |
| 10 | 0 | 3 | 3 | 7 | 3 |
| 11 | 6 | 3 | 0 | 3 | 6 |
| 12 | 6 | 6 | 5 | 1 | 5 |
</code></pre>
<p>I have coded some introspection to be saved in another frame called _outliers:</p>
<pre><code>Q1 = df.quantile(0.25)
Q3 = df.quantile(0.75)
IQR = (Q3 - Q1)
min_ = (Q1 - (1.5 * IQR))
max_ = (Q3 + (1.5 * IQR))
# Counts outliers in columns
_outliers = ((df.le (min_)) | (df.ge (max_))).sum().to_frame(name="outliers")
# Gives percentage of data that outliers represent in the column
_outliers["percent"] = (_outliers['outliers'] / _outliers['outliers'].sum()) * 100
# Shows max value in the column
_outliers["max_val"] = df[_outliers.index].max()
# Shows min value in the column
_outliers["min_val"] = df[_outliers.index].min()
# Shows median value in the column
_outliers["median"] = df[_outliers.index].median()
# Shows mean value in the column
_outliers["mean"] = df[_outliers.index].mean()
</code></pre>
<p>That yields:</p>
<pre><code>| | outliers | percent | max_val | min_val | median | mean |
|:---|-----------:|----------:|----------:|----------:|---------:|---------:|
| A | 2 | 22.2222 | 665 | 0 | 5 | 61.6923 |
| B | 3 | 33.3333 | 665 | 0 | 6 | 164.385 |
| C | 1 | 11.1111 | 1000 | 0 | 4 | 80.9231 |
| D | 2 | 22.2222 | 665 | 1 | 3 | 77.0769 |
| E | 1 | 11.1111 | 250 | 0 | 5 | 23.3846 |
</code></pre>
<p>I would like to calculate the impact of the outliers on the column by calculating the mean and the median without them. I don't want to remove them to do this calculation. I suppose the best way is to add "~" to the outlier filter but I get lost in the code... This will benefit a lot of people as a search on removing outliers yields a lot of results. Other than the why they sneaked in the data in the first place, I just don't think the removal decision should be made without consideration on the potential impact. Feel free to add other considerations (skewness, sigma, n, etc.)</p>
<p>As always, I'm grateful to this community!</p>
<p>EDIT: I added variance and its square root standard deviation with and without outliers. In some fields you might want to keep outliers and go into ML directly. At least, by inspecting your data beforehand, you'll know how much they are contributing to your results. Used with nlargest() in the outliers column you get a quick view of which features contain the most. You could use this as a basis for filtering features by setting up thresholds on variance or mean. Thanks to the contributors, I have a powerful analytics tool now. Hope it can be useful to others.</p>
| [
{
"answer_id": 74236831,
"author": "jthulhu",
"author_id": 5956261,
"author_profile": "https://Stackoverflow.com/users/5956261",
"pm_score": 3,
"selected": true,
"text": "'long"
},
{
"answer_id": 74239242,
"author": "fred xia",
"author_id": 16323026,
"author_profile":... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5250645/"
] |
74,236,728 | <p>Im using Firebase to store some data in my React app. Its working fine on my local emulator with the same settings, but when i publish the app, i get this error:
@firebase/firestore: Firestore (9.12.1): Uncaught Error in snapshot listener: {"code":"failed-precondition","name":"FirebaseError"}</p>
<p>Im using the where() clause, and i red i need to add some sort of index in my firebase rules.</p>
<pre><code>useEffect(() => {
if (activeList === 'null') {
} else {
const userRef = collection(database, activeList.id);
const sort = query(userRef, where("checked", "==", showDoneTodos), orderBy('title', 'asc'))
const unsubsctibeAllTodos = onSnapshot(sort, (snapshot) => {
setAllTodos(snapshot.docs.map(doc => ({
id: doc.data().id,
title: doc.data().title,
desc: doc.data().desc,
checked: doc.data().checked
})
))
})
return () => {
unsubsctibeAllTodos()
}
}
}, [activeList, showDoneTodos])
</code></pre>
<p>Some info:
activeList is an object with and ID. The problem is that this is generated live so i cant preconfigure any collection ID before i publish.</p>
<p>showDoneTodos is a boolean.</p>
<p>Any guidance would be very welcome!</p>
<h2>Thanks!</h2>
| [
{
"answer_id": 74255350,
"author": "Latent-code",
"author_id": 2765075,
"author_profile": "https://Stackoverflow.com/users/2765075",
"pm_score": 1,
"selected": true,
"text": "{\"code\":\"failed-precondition\",\"name\":\"FirebaseError\"}"
}
] | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2765075/"
] |
74,236,738 | <p>this is an example list:</p>
<pre><code>mylist = [0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1]
</code></pre>
<p>I need to search the list for adjacent 0 until no zeros are adjacent. My needed output-</p>
<pre><code>newlist = [0,x,1,0,1,0,x,x,1,0,x,x,x,1,0,x,x,1,0,1,0,x,1]
</code></pre>
<p>so I retain a single zero at its correct index, but replace its adjacents with "x". I am new to python and have take some very unsuccessful stabs at it.</p>
<p>I tried creating a while loop but I'm sad cuz bad.</p>
| [
{
"answer_id": 74236806,
"author": "Stuart",
"author_id": 567595,
"author_profile": "https://Stackoverflow.com/users/567595",
"pm_score": 1,
"selected": false,
"text": "newlist = [\"x\" if a == b == 0 else b for a, b in zip([None] + mylist, mylist)]\n"
},
{
"answer_id": 74236857,... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359114/"
] |
74,236,764 | <p>Like we have string = "Cow eat Grass/Cat eat mouse/Dog eat meat/Fish eat worm/Snake eat mouse"
I try to make function like:</p>
<pre><code>std::string getTheLastAnimalText(const std::string& source)
{
// .... Can you help here :)
return "Snake eat mouse";
</code></pre>
<p>I try to make this function but i can't ;(</p>
| [
{
"answer_id": 74236806,
"author": "Stuart",
"author_id": 567595,
"author_profile": "https://Stackoverflow.com/users/567595",
"pm_score": 1,
"selected": false,
"text": "newlist = [\"x\" if a == b == 0 else b for a, b in zip([None] + mylist, mylist)]\n"
},
{
"answer_id": 74236857,... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359096/"
] |
74,236,808 | <p>I am trying to get classes to inherit attributes of the parent class.</p>
<p>The main class is Country and has two attributes that're the country's capital and president.</p>
<p>The class State is derived from Country, and should have the attributes of the state's capital and the governor.</p>
<p>The class County is derived from State, and should have the attribute of the county's name.</p>
<p>I have a pretty basic understanding of classes, any help would be greatly appreciated.</p>
<p>Here is the code I have:
Note: Nothing underneath if <strong>name</strong> = 'main': can change</p>
<pre><code>class Country:
def __init__(self, country_capital, president):
self.country_capital = country_capital
self.president = president
class State(Country):
def __init__(self, state_capital, governor, c):
self.state_capital = state_capital
self.governor = governor
c = Country()
class County(State):
def __init__(self, county_seat, c):
self.county_seat = county_seat
c = State()
self.governor = super().__init__(self, state_capital)
if __name__ == '__main__':
United_States = Country("Washington, DC", "Joe Biden")
Kentucky = State("Frankfort", "Andy Beshear", United_States)
Jefferson = County("Louisville", Kentucky)
print("County seat: ", Jefferson.county_seat)
print(" Governor: ", Jefferson.governor)
print("State capital: ", Jefferson.state_capital)
print("Country capital: ", Jefferson.country_capital)
print("President:", Jefferson.president)
</code></pre>
| [
{
"answer_id": 74236906,
"author": "jprebys",
"author_id": 3268228,
"author_profile": "https://Stackoverflow.com/users/3268228",
"pm_score": 0,
"selected": false,
"text": "class Country:\n def __init__(self, country_capital, president):\n self.country_capital = country_capital\... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359147/"
] |
74,236,830 | <p>I have a NumPy list (Distances). When I print it, the result is:</p>
<pre><code>array([[ 1. ],
[600. ],
[456.03971033],
[294.94188261],
[286.47232436],
[ 92.08606785]])
</code></pre>
<p>However, I want to get any specific element of this list as a float number without any brackets, array, and '' sign. Note that I don't want to print it, I need to have the number in another variable like this:</p>
<pre><code>element1 = Distance[0]
</code></pre>
<p>Result is: array([1.])</p>
<p>But I want it to be just: 1.</p>
| [
{
"answer_id": 74236861,
"author": "someone",
"author_id": 20343209,
"author_profile": "https://Stackoverflow.com/users/20343209",
"pm_score": 1,
"selected": false,
"text": "element1 = Distance[0][0]\n"
},
{
"answer_id": 74236927,
"author": "Matt Pitkin",
"author_id": 186... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12120831/"
] |
74,236,851 | <p>I want to change the below 1D array having dictionaries as its value into 2D array. I don't want to use numpy or pandas.</p>
<pre><code>array = [{"id": "123", 'name-code': 'user-1666935009', 'r.no.': '1', 'start_time': '1666955702', 'state_msg': 'Finished', 'state_details': '', 'setup_time': '2371'}]
</code></pre>
<p>I am expecting the output as</p>
<pre><code>array = [['id','name-code','r.no.','start_time','state_msg','state_details','setup_time'],['123','user-1666935009', '1','1666955702','Finished','','2371']]
</code></pre>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20230857/"
] |
74,236,873 | <p>I have some divs that render this way:</p>
<pre><code><div class="customer-data-column">
<h3>Title:</h3>
<div>Name Lastname</div>
<div>123 Address xxx yyy</div>
<div>Chicago XY 33056</div>
<div>Country name</div>
</div>
</code></pre>
<p>This content is generated by:</p>
<pre><code>{customerData.replaceAll("/r", "").split("\n").map(item => <div key={item}>{item}</div>)}
</code></pre>
<p>This data is coming from redux.
In console log (from redux data) the address appears this way:</p>
<pre><code>Name Lastname\n123 Address xxx yyy\nChicago XY 33056\nCountry name
</code></pre>
<p>I want to check in Cypress if this address is correct, the same that is in redux.
I need some way that merges the content of the divs into one string, and adds the <code>\n</code> between each div.</p>
<p>I thought I could start this way:</p>
<pre><code> cy.get('.customer-data-column').should($title => {
const store = Cypress.store.getState();
const reduxPath = store.customerData;
expect("not sure what to put here... how to merge").to.equals(reduxPath)
</code></pre>
<p>Can anyone please help?</p>
<p>===
<strong>EDIT</strong></p>
<p>I made it almost work this way:
I added a class to the inner divs, so they render this way:</p>
<pre><code><div class="customer-data-column">
<h3>Title:</h3>
<div class="address-row">Name Lastname</div>
<div class="address-row">123 Address xxx yyy</div>
<div class="address-row">Chicago XY 33056</div>
<div class="address-row">Country name</div>
</div>
</code></pre>
<p>And the test:</p>
<pre><code> cy.get('.address-row').then($divList => {
const textArray = Cypress.$.makeArray($divList).map(el => el.innerText)
const actual = textArray.join(textArray, '\n') // use join to array of strings into single string
expect(actual).to.eql(billToAddress)
})
</code></pre>
<p>However it still fails with such message:</p>
<blockquote>
<p>assert expected Name LastnameName Lastname,23 Address xxx yyy,Chicago
XY 33056,Country name23 Address xxx yyyName Lastname,23 Address xxx
yyy,Chicago XY 33056,Country name7th FloorName Lastname,23 Address xxx
yyy,Chicago XY 33056,Country nameBrooklyn NY 11210Name Lastname,23
Address xxx yyy,Chicago XY 33056,Country nameCountry name to deeply
equal Name Lastname\n23 Address xxx yyy\n7th Floor\nBrooklyn NY
11210\nCountry name</p>
</blockquote>
<p>Edit 2:
The solution that I found and works is this one:</p>
<pre><code>.then(users => {
const billToAddress = users.response.body.filter(el => el.orderNumber === '3-331877')[0]
.billTo
cy.get('.address-row').each((item, index) => {
cy.log(cy.wrap(item).should('contain.text', billToAddress.split('\n')[index]))
})
})
</code></pre>
<p>Of course if somebody has a better way for achieving this test, I am open to learn more and code better.</p>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1580094/"
] |
74,236,891 | <p>I have a data.table that is supposed to remove all rows per <code>group</code> until a negative number is met in <code>value</code> (including the row with the negative number itself). However, if there is no negative number in <code>value</code> I would like to keep all rows from that group.</p>
<pre><code># Example data
group = rep(1:4,each=3)
value = c(1,2,3,1,-2,3,1,2,-3,-1,2,3)
DT = data.table(group,value)
> DT
group value row_idx
1: 1 1 1
2: 1 2 2
3: 1 3 3
4: 2 1 1
5: 2 -2 2
6: 2 3 3
7: 3 1 1
8: 3 2 2
9: 3 -3 3
10: 4 -1 1
11: 4 2 2
12: 4 3 3
</code></pre>
<p>My attempt so far:</p>
<pre><code>DT[,row_idx := seq_len(.N), by = "group"] #append row index per group
DT[,.SD[row_idx > (which(sign(value) == -1))], by = "group"]
group value row_idx
1: 2 3 3
2: 4 2 2
3: 4 3 3
</code></pre>
<p>In this example <code>group 1</code> is being deleted although I would like to keep it as no negative number is present in this group. I can check for the presence/absence of negative signs in <code>value</code> by <code>DT[,(-1) %in% sign(value), by = "group"]</code> but I do not know how to use this to achieve what I want.</p>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11738400/"
] |
74,236,926 | <p>I am trying to <strong>download images using beautiful soup While Importing a list of URLs from .CSV file</strong>. Now I am getting results like below,</p>
<pre><code><img class="pick" src="backup/remote_2109image/008f3ef7-1da9-11ec-abad-88ae1db4aa6901.jpg" width="350height=616\"/>
</code></pre>
<p>In the below code, I am <strong>trying to get an image from URL that has the class 'pick'</strong></p>
<p>Now, How Will I download this in a folder?</p>
<pre><code>import csv
import requests
import os
import urllib
from bs4 import BeautifulSoup as bs
with open('cat.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
imagesname = ' '.join(row)
r = requests.get(imagesname)
soup = bs(r.content, 'html.parser')
tables = soup.find_all('img', class_='pick')
for image in tables:
print(image)
</code></pre>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10825522/"
] |
74,236,953 | <p>I have file with multiple columns. each column onwards 4th column,has 2 parts a part before # and a part after #. If the number after # is >20, then I want to replace the # and the followed the number with null like 0|0#99 is becoming 0|0 as 99 > 20. If number followed by # is <20, then I want to replace the entire cell value with "./." like 0|0#14 is becoming "./.". If there isa dot after #, then it the value as it is like 0|0#. will be 0|0#. as it it.</p>
<p>input_file.txt. tab separated file I have</p>
<pre><code>1 12345 A T 0|0#. 0|0#. 0|0#14 0|0#. 0|0#. 0|0#20 0|0#15 0|0#40 0|0#99
1 78906 C T 0|0#99 0|0#. 0|0#10 0|0#. 0|0#45 0|0#20 0|0#95 0|0#78 0|0#99
</code></pre>
<p>Output > 20</p>
<pre><code>1 12345 A T 0|0#. 0|0#. ./. 0|0#. 0|0#. ./. ./. 0|0 0|0
1 78906 C T 0|0 0|0#. ./ 0|0#. 0|0 ./. 0|0 0|0 0|0
</code></pre>
<p>I tried following code but not getting desired output. Kindly help me to resolve this</p>
<pre><code>awk -v FS="\t" -v OFS="\t" '{ for(i=1;i<=NF;i++) if ( $1 ~ /\#[>20]/ ) {print $0} else; {print"./."}}' input_file.txt
</code></pre>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16423872/"
] |
74,236,966 | <p>Here are my custom objects:</p>
<pre><code>typedef struct sem_holder
{
sem_t *writer_sem;
sem_t *reader_sem;
} sem_holder;
typedef struct worker_arg
{
unsigned int nsegments;
size_t segsize;
sem_holder *sems;
} worker_arg;
</code></pre>
<p>Here is my code, where I pass a &sems argument to the custom objects above:</p>
<pre><code> sem_holder *sems[nsegments];
sem_holder sems_obj;
char sem_write_name[21];
char sem_read_name[21];
sem_t *writer_sem;
sem_t *reader_sem;
ftruncate(DATA_CHANNEL_ID, segsize * nsegments);
for (int i = 0; i < nsegments; i++)
{
// Map subsection of data-channel to an array in proxy's virtual memory
// processes[i] = mmap(NULL, sizeof(segsize), PROT_READ | PROT_WRITE, MAP_SHARED,
DATA_CHANNEL_ID, i * segsize);
// Dynamically create reader and writer names
snprintf(sem_write_name, 21, "%dw", i);
snprintf(sem_read_name, 21, "%dr", i);
// Create a likewise array for semaphores
writer_sem = sem_open(sem_write_name, O_CREAT, 0660, 0);
if (writer_sem == SEM_FAILED)
printf("FAILED\n");
sems_obj.writer_sem = writer_sem;
reader_sem = sem_open(sem_read_name, O_CREAT, 0660, 0);
if (reader_sem == SEM_FAILED)
printf("FAILED\n");
sems_obj.reader_sem = reader_sem;
sems[i] = &sems_obj;
}
// Initialize worker arg
worker_arg worker_arg = {.nsegments = nsegments, .segsize = segsize, .sems = &sems};
</code></pre>
<p>When I do &sems, I get this error:</p>
<pre><code>webproxy.c: In function ‘main’:
webproxy.c:209:80: error: initialization of ‘sem_holder *’ {aka ‘struct sem_holder *’} from incompatible pointer type ‘sem_holder * (*)[(sizetype)(nsegments)]’ [-Werror=incompatible-pointer-types]
209 | egments, .segsize = segsize, .sems = &sems};
|
</code></pre>
<p>When I do just sems, I get this error:</p>
<pre><code>webproxy.c: In function ‘main’:
webproxy.c:209:80: error: initialization of ‘sem_holder *’ {aka ‘struct sem_holder *’} from incompatible pointer type ‘sem_holder **’ {aka ‘struct sem_holder **’} [-Werror=incompatible-pointer-types]
209 | segsize = segsize, .sems = sems};
|
</code></pre>
<p>Seems it is likely an issue with the way I declare my worker_arg sems parameter. I am just uncertain how I would store this sem_holder array in my worker_arg object. I figured passing a pointer to the object would work but it does not seem to. Any ideas or thought processes that could help?</p>
<hr />
<p>edit, here is my updated code. I am able to pass the sems object now which is good. The value of these semaphores is always 0 though, which is not what I declared it as in sem_open. Clearly I am a novice in C</p>
<pre><code> // char *processes[nsegments];
sem_holder sems[nsegments];
char sem_write_name[21];
char sem_read_name[21];
sem_t *writer_sem;
sem_t *reader_sem;
ftruncate(DATA_CHANNEL_ID, segsize * nsegments);
for (int i = 0; i < nsegments; i++)
{
// Map subsection of data-channel to an array in proxy's virtual memory
// processes[i] = mmap(NULL, sizeof(segsize), PROT_READ | PROT_WRITE, MAP_SHARED, DATA_CHANNEL_ID, i * segsize);
// Dynamically create reader and writer names
snprintf(sem_write_name, 21, "%dw", i);
snprintf(sem_read_name, 21, "%dr", i);
// Create a likewise array for semaphores
writer_sem = sem_open(sem_write_name, O_CREAT, 0660, 10);
if (writer_sem == SEM_FAILED)
printf("FAILED\n");
sems[i].writer_sem = writer_sem;
reader_sem = sem_open(sem_read_name, O_CREAT, 0660, 10);
if (reader_sem == SEM_FAILED)
printf("FAILED\n");
sems[i].reader_sem = reader_sem;
}
// Initialize worker arg
worker_arg worker_arg = {.nsegments = nsegments, .segsize = segsize, .sems = sems};
</code></pre>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14910097/"
] |
74,236,975 | <p>I am sending a token to user email like below and using bcrypt for this as an encrypt/decrypt mechanism.</p>
<pre><code> const token = await bcrypt.hash(joinDate, 10);
</code></pre>
<p>When the user clicks on the link in email, I get the above token back as that token is a part of
<code>/api/unsubscribe?userId="abcd"&token="token_that_was_generated_using_bcrypt_and_sent_to_user"</code></p>
<pre><code>const {userId, token} = req.query;
</code></pre>
<p>In the api, I am comparing joinDate obtained from database vs token sent by req.query but it never matches.</p>
<pre><code>const joinDate = user.joinDate.toString();
const tokenValidated = await bcrypt.compare(joinDate, token)//this is always false although us generated from same joinDate field
</code></pre>
<p>Why is <code>tokenValidated</code> always false although it was generated using the same field joinDate?</p>
| [
{
"answer_id": 74236954,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 0,
"selected": false,
"text": "array2 = [[],[]]\nfor key,value in array[0].items():\n array2[0].append(key)\n array2[1].append(value)\n... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3717114/"
] |
74,236,979 | <p>I have created a login page with a login button. Now I want to make it such that whenever login button is clicked, it calls the authentication system of firebase and checks if the user exists, and if yes, navigate to the homepage. How can I make that?</p>
<p>I have set up the firestore, I just want to make it such that it navigates to another page only if the user exists, otherwise throw an error.</p>
<p>The login function of firebase looks like this</p>
<pre><code>const logInWithEmailAndPassword = async (email, password) => {
try {
await signInWithEmailAndPassword(auth, email, password);
} catch (err) {
console.error(err);
alert("Email or Password not Registered!");
}
};
</code></pre>
<p>This is the login button</p>
<pre><code><button
onClick={async () => {
await logInWithEmailAndPassword(email, password);
navigate('/Login/HomePage)};
}}
>
Login
</button>
</code></pre>
<p>Now no matter what the email and password is, it still navigates to the homepage.
How to do this setup so that it only navigates if and only if the user exists in firestore?</p>
| [
{
"answer_id": 74237041,
"author": "ArtemKh",
"author_id": 4357197,
"author_profile": "https://Stackoverflow.com/users/4357197",
"pm_score": 0,
"selected": false,
"text": "const logInWithEmailAndPassword = async (email, password) => {\n try { \n await signInWithEmailAndPassword(auth, e... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74236979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359012/"
] |
74,237,003 | <p>I want to detect ONE mouse down and ONE mouse up event on my view (a simple Rectangle). Here is the code I already made. Unfortunately I got a lot of 'mouse down' and 'mouse up' on the console. This not what I want. I want just one 'mouse down' when the mouse is pressed on my rectangle and one 'mouse up' when the mouse is released.</p>
<pre><code>
var body: some View {
Rectangle()
.onAppear(perform: {
NSEvent.addLocalMonitorForEvents(matching: [.leftMouseDown]) { event in
print ("mouse down")
return event
}
NSEvent.addLocalMonitorForEvents(matching: [.leftMouseUp]) { event in
print ("mouse up")
return event
}
})
}
</code></pre>
| [
{
"answer_id": 74237443,
"author": "MaxAuMax",
"author_id": 19843651,
"author_profile": "https://Stackoverflow.com/users/19843651",
"pm_score": -1,
"selected": false,
"text": "struct ContentView: View {\n @State var dragGestureValue: DragGesture.Value?\n \n var body: some View {... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3405792/"
] |
74,237,025 | <p>I'm being asked to write a function which will accept a list of dictionary objects as input, and will return a list of values pertaining to a specific key in the dictionaries. An example of the function call:</p>
<pre><code>titles = getKeys( [book1, book2, book3] )
</code></pre>
<p><a href="https://i.stack.imgur.com/hGkfb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hGkfb.png" alt="enter image description here" /></a></p>
<p>I made 3 dictionaries and then defined the function and passed a list of the dictionaries as arguments. I know that I need a for loop to parse through the list but don't know how exactly that is done.</p>
<pre><code> book1 = {
"Title": "ShowYourWork",
"Price": 2.99,
"Edition": "5th",
"in_stock": False
}
book2 = {
"Title": "HowToNotDieALone",
"Price": 10.00,
"Edition": "2nd",
"in_stock": True
}
book3 = {
"Title": "TheSecondBrain",
"Price": 9.99,
"Edition": "8th",
"in_stock": False
}
books = [book1, book2, book3]
def getKeys(books):
for book in books:
print(f"{book['Price']}")
</code></pre>
| [
{
"answer_id": 74237443,
"author": "MaxAuMax",
"author_id": 19843651,
"author_profile": "https://Stackoverflow.com/users/19843651",
"pm_score": -1,
"selected": false,
"text": "struct ContentView: View {\n @State var dragGestureValue: DragGesture.Value?\n \n var body: some View {... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15814523/"
] |
74,237,035 | <p><a href="https://i.stack.imgur.com/WPsmN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WPsmN.png" alt="enter image description here" /></a></p>
<p>How can I get the value of <code>coursestatus</code> from all of the collections?</p>
| [
{
"answer_id": 74237443,
"author": "MaxAuMax",
"author_id": 19843651,
"author_profile": "https://Stackoverflow.com/users/19843651",
"pm_score": -1,
"selected": false,
"text": "struct ContentView: View {\n @State var dragGestureValue: DragGesture.Value?\n \n var body: some View {... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20155480/"
] |
74,237,036 | <p>I am using Vue JS and html2pdf to download dynamic content. When i am trying to link to a div inside my component with an anchor tag it's working perfectly on my local.</p>
<p>But when i download the document there is a link in the document but it's not scrolling to my supposing div.</p>
<p>I would like to know to if it's possible to do this?</p>
<pre><code><div id="app" ref="document">
<a href="#test">
Jump to the part of the page with the “test” id
</a>
<div class="card" id="preview">
<div class="card-block">
<p id="test">blablabla.....</p>
</div>
</div>
</div>
</code></pre>
<p>My function to export the pdf:</p>
<pre><code> async exportToPDF() {
await html2pdf(this.$refs.document, {
margin: 1,
filename: "document.pdf",
image: { type: "jpeg", quality: 0.98 },
html2canvas: { dpi: 192, letterRendering: true },
jsPDF: { unit: "in", format: "letter", orientation: "landscape" }
});
},
</code></pre>
<p>It is possible still have the same link who is going here the the div with the id="test"?</p>
<p>At the end i would like to make a table of content in a dynamic way.</p>
<p>Thank you for reading :)</p>
<p>Have a nice day!</p>
| [
{
"answer_id": 74237443,
"author": "MaxAuMax",
"author_id": 19843651,
"author_profile": "https://Stackoverflow.com/users/19843651",
"pm_score": -1,
"selected": false,
"text": "struct ContentView: View {\n @State var dragGestureValue: DragGesture.Value?\n \n var body: some View {... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13597186/"
] |
74,237,051 | <p>I have a dataframe that looks like this, with many more date columns</p>
<pre><code> AUTHOR 2022-07-01 2022-10-14 2022-10-15 .....
0 Kathrine 0.0 7.0 0.0
1 Catherine 0.0 13.0 17.0
2 Amanda Jane 0.0 0.0 0.0
3 Jaqueline 0.0 3.0 0.0
4 Christine 0.0 0.0 0.0
</code></pre>
<p>I would like to set values in each column after the <code>AUTHOR</code> to 1 when the value is greater than 0, so the resulting table would look like this:</p>
<pre><code> AUTHOR 2022-07-01 2022-10-14 2022-10-15 .....
0 Kathrine 0.0 1.0 0.0
1 Catherine 0.0 1.0 1.0
2 Amanda Jane 0.0 0.0 0.0
3 Jaqueline 0.0 1.0 0.0
4 Christine 0.0 0.0 0.0
</code></pre>
<p>I tried the following line of code but got an error, which makes sense. As I need to figure out how to apply this code just to the date columns while also keeping the <code>AUTHOR</code> column in my table.</p>
<pre><code>Counts[Counts != 0] = 1
TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value
</code></pre>
| [
{
"answer_id": 74237176,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile": "https://Stackoverflow.com/users/10315163",
"pm_score": 3,
"selected": true,
"text": "cols = df.drop(columns='AUTHOR').columns\n# or\ncols = df.filter(regex='\\d{4}-\\d{2}-\\d{2}').columns\n# or\ncols... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10687615/"
] |
74,237,056 | <p>I have a object that has the result of a query, this object has date´s fields and i need to deal where the field has the date '01-01-1991'change to null. How can i simplify this if statement?</p>
<pre><code>if(item.date01 == '01-01-1991')
item.date01 = null;
if(item.date02 == '01-01-1991')
item.date02 = null;
if(item.date03 == '01-01-1991')
item.date03 = null;
if(item.date04 == '01-01-1991')
item.date04 = null;
</code></pre>
<p>i tried to use foreach, but i didnt know how...</p>
<pre><code>foreach(var item in itens)
{
if(item.obj == '01-01-1991')
item.obj = null;
}
</code></pre>
| [
{
"answer_id": 74237138,
"author": "Maarten",
"author_id": 261050,
"author_profile": "https://Stackoverflow.com/users/261050",
"pm_score": 2,
"selected": false,
"text": "var item = new DataItem();\n\nvoid CheckAndSet(ref string? date)\n{\n if (date == \"01-01-1900\")\n {\n d... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19371456/"
] |
74,237,059 | <p>I'm new to Haskell and have been given a worksheet question which has me stumped. The question is asking me to define a function that takes a list and returns a list of tuples, each of which contains a sub list of the original list.</p>
<p><a href="https://i.stack.imgur.com/f7oHe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f7oHe.png" alt="enter image description here" /></a></p>
<p>I have tried the below. However, as expected, on each recursion the the previous head gets dropped.</p>
<pre><code>splits :: [Int] -> [([Int],[Int])]
splits []
= [([],[])]
splits (l:ls)
= ([] ++ [l], ls) : splits ls
</code></pre>
<p>Here is the result I get.</p>
<pre><code>[([1],[2,3,4]),([2],[3,4]),([3],[4]),([4],[]),([],[])]
</code></pre>
<p>Any advice on how to do this would be appreciated!</p>
| [
{
"answer_id": 74237372,
"author": "Willem Van Onsem",
"author_id": 67579,
"author_profile": "https://Stackoverflow.com/users/67579",
"pm_score": 1,
"selected": false,
"text": "l"
},
{
"answer_id": 74244180,
"author": "Kaloyan Gadarov",
"author_id": 20364651,
"author_... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7699172/"
] |
74,237,065 | <p>Just started working with Ansible and JSON dictionary data. I am trying to process the following dictionary using a jmesquery:</p>
<pre class="lang-json prettyprint-override"><code>{
"Entities": [
{
"MetaData": {
"NumDiscoveredWorkloads": 20,
"NumMigratedWorkloads": 1,
"UUID": "uuid1234567890"
},
"Spec": {
"Type": "VMWARE_ESXI_VCENTER",
"UUID": "uuid1234567890"
}
},
{
"MetaData": {
"NumDiscoveredWorkloads": 40,
"UUID": "uuid1234567891"
},
"Spec": {
"Type": "AOS_PC",
"UUID": "uuid1234567891"
}
}
],
"MetaData": {
"Count": 2
}
}
</code></pre>
<p>I want to find the value for the UUID of the ESXi item. I created the following Ansible code:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: "Get ESXiUUID"
var:
jmesquery: "Entities[*].Spec[?Type==`VMWARE_ESXI_VCENTER`].UUID"
set_fact:
move_providers_filtered: "{{ move_providers_details_content | json_query(jmesquery) }}"
</code></pre>
<p>But this does not work. I get strange errors from Ansible. Been checking the web for a day now, but nothing I tried solves the error. Can anybody tell me what I am doing wrong and how to solve this? Thanks for any support</p>
| [
{
"answer_id": 74237372,
"author": "Willem Van Onsem",
"author_id": 67579,
"author_profile": "https://Stackoverflow.com/users/67579",
"pm_score": 1,
"selected": false,
"text": "l"
},
{
"answer_id": 74244180,
"author": "Kaloyan Gadarov",
"author_id": 20364651,
"author_... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359148/"
] |
74,237,096 | <p>I'm trying to build a product landing page as a certificate project for freeCodeCamp.</p>
<p>I can't understand how to fix the icons to the left, while fixing the feature and price to the center. And I can't understand why my <code>li</code> items are overflowing over their container.</p>
<p>I tried all the overflow and wrap tags I know but I can't work it out.</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>* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-family: 'Montserrat', sans-serif;
}
#logo {
position: absolute;
width: 25%;
left: 0;
height: auto;
image-resolution: 100%;
}
header {
width: 100%;
display: flex;
justify-content: space-evenly;
}
.navspace {
justify-content: end;
position: relative;
right: -15%;
}
nav {
positio: relative;
}
ul {
display: flex;
list-style: none;
}
li {
margin: 40px;
}
.product {
position: absolute;
top: 15%;
}
#leads {
width: 100vw;
display: flex;
flex-direction: column;
text-align: center;
justify-content: center;
align-items: center;
}
.title {
padding: 2%;
}
#logo-green {
width: 5vw;
height: auto;
margin-right: 5vw;
}
#Features {
margin-left: 27%;
display: flex;
align-items: left;
justify-content: left;
text-align: left;
padding: 5%;
}
#Price {
display: flex;
align-items: center;
justify-content: left;
text-align: center;
padding: 3%;
margin-left: 27%;
}
.price {
display: flex;
flex-direction: column;
text-align: left;
}
.pricelist {
width: 100%;
max-height: 400px;
text-align: center;
position: absolute;
display: inline-flex;
justify-content: center;
}
.class {
width: 300px;
height: 300px;
border: 1px solid black;
margin: 20px;
}
.class>h1 {
width: 100%;
height: 10%;
background-color: blanchedalmond;
padding: 2%;
font-size: large;
}
#medium,
#pika,
#base {
display: flex;
flex-direction: column;
}
.class>h2 {
margin: 5% 0 5% 0;
}
.class>ul {
display: grid;
display: flex;
justify-content: center;
flex-direction: column;
gap: 2px;
}
.class>li {
position: relative;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<!-- tabella nav -->
<header>
<div>
<img id="logo" src="img/LIGHTSPEED.png" alt="" />
</div>
<!-- bhr -->
<div class="navspace">
<nav id="nav-link">
<ul>
<li>Features</li>
<li>Price</li>
<li>Contacts</li>
</ul>
</nav>
</div>
</header>
<main class="product">
<!-- form -->
<section id="leads">
<h2 class="title">Most efficient way to light your life</h2>
<form action="">
<input class="email" type="email" required placeholder="Enter your email" columns="10">
<input class="submit" type="submit" value="Get Shocked">
</form>
</section>
<!-- features -->
<section>
<div id="Features">
<div id="green">
<img id="logo-green" src="img/294432.png" alt="">
</div>
<div class="feature">
<h2>Only from renovable energy</h2>
<p>Coming from water and earth termal energy</p>
</div>
</div>
</section>
<!-- price -->
<section>
<div id="Price">
<div id="cheap">
<img id="logo-green" src="img/low-price.png" alt="">
</div>
<div class="price">
<h2>Prices you have never seen</h2>
<p>With our funding system you might get some solar panels</p>
<p>and who knows... we might pay you your energy.</p>
</div>
</div>
</section>
<div class="pricelist">
<div class="class" id="base">
<h1>BASE LEVEL</h1>
<h2>49€</h2>
<ul>
<li>Standart power transmission</li>
<li>Change power output by your personal profile</li>
<li>Client Support 10am-20am</li>
</ul>
</div>
<div class="class" id="medium">
<h1>MEDIUM LEVEL</h1>
<h2>59€</h2>
</div>
<div class="class" id="pika">
<h1>PIKACHU LEVEL</h1>
<h2>149€</h2>
</div>
</div>
</main></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74237501,
"author": "Tafhimul kabir",
"author_id": 6769883,
"author_profile": "https://Stackoverflow.com/users/6769883",
"pm_score": 0,
"selected": false,
"text": "li"
},
{
"answer_id": 74237618,
"author": "Sling",
"author_id": 19881049,
"author_profile... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359151/"
] |
74,237,099 | <p>I am trying to see how to test short circuit evaluation in Pascal but not sure if doing it correctly. This is what I have so far.</p>
<pre class="lang-pascal prettyprint-override"><code>program shortcircuit;
var
{ local variable definition }
a : integer;
b : integer;
begin
a := 8;
b := 0;
if( (b <> 0) and (a / b) ) then
(* if condition is true then print the following *)
writeln('...' )
end.
</code></pre>
| [
{
"answer_id": 74237279,
"author": "Dúthomhas",
"author_id": 2706707,
"author_profile": "https://Stackoverflow.com/users/2706707",
"pm_score": 3,
"selected": true,
"text": "else"
},
{
"answer_id": 74238845,
"author": "Kai Burghardt",
"author_id": 9636977,
"author_prof... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14337036/"
] |
74,237,125 | <p>I want to use window function to partition by ID and have the last row of each group to be subtracted from the first row and create a separate column with the output. What is the cleanest way to achieve that result?</p>
<pre><code>ID col1
1 1
1 2
1 4
2 1
2 1
2 6
3 5
3 5
3 7
</code></pre>
<p>Desired output:</p>
<pre><code>ID col1 col2
1 1 3
1 2 3
1 4 3
2 1 5
2 1 5
2 6 5
3 5 2
3 5 2
3 7 2
</code></pre>
| [
{
"answer_id": 74237279,
"author": "Dúthomhas",
"author_id": 2706707,
"author_profile": "https://Stackoverflow.com/users/2706707",
"pm_score": 3,
"selected": true,
"text": "else"
},
{
"answer_id": 74238845,
"author": "Kai Burghardt",
"author_id": 9636977,
"author_prof... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12988537/"
] |
74,237,146 | <p>How many times can you divide 24**36 by 2 until it becomes imprecise? I had this question on one of my quizzes in a python course, and I'm curious as to what the correct answer is. (It's already submitted so no cheating here)</p>
<p>I wrote this small bit of code in python to calculate how many times you can evenly divide the number by two until it becomes a decimal number.</p>
<pre><code>count = 0
remainder = 0
num = 24**36
while remainder == 0:
remainder = num % 2
if remainder == 0:
num /= 2
count += 1
print(count)
</code></pre>
<p>I assumed the answer had something to do with floating point imprecision, but I'm not sure what is classified as "imprecise" here. The code above prints 113, since by the 113th division it will become a decimal number with .5 at the end, and I claimed that number is imprecise. Is this approach correct?</p>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15437438/"
] |
74,237,151 | <p>I have list of products which has id, name and price. I want to show it in console using prices such as</p>
<p>Price 1 to 100
--list of products</p>
<p>price 101 to 200
--list of products
and it so on till last highest price.
I need to determine at runtime how many segments I need to create based upon highest price.</p>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19749146/"
] |
74,237,175 | <p>I need to remap a column of strings with other strings, but some strings are related to more than one other string, so I need to fit multiple values in to some elements in the resulting column. I assumed I would do that with a list, so the column of strings would be converted into a column of lists of strings of length 1 or more, like this:</p>
<pre><code> embark_town mapped_column
0 Southampton [A, B]
1 Cherbourg [C]
2 Southampton [A, B]
3 Southampton [A, B]
4 Southampton [A, B]
</code></pre>
<p>I tried to do this a typical way with a dictionary and <code>pandas.Series.replace</code>, but got a value error, I'm assuming because pandas is not assuming that the lists of two elements are supposed to be a single element in the resulting Series.</p>
<pre><code>import seaborn as sns
df = sns.load_dataset('titanic').iloc[:5]
mapping = {
'Southampton': ['A', 'B'],
'Cherbourg': ['C']
}
df.embark_town.replace(mapping)
</code></pre>
<pre><code>---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [42], in <cell line: 10>()
3 df = sns.load_dataset('titanic').iloc[:5]
5 mapping = {
6 'Southampton': ['A', 'B'],
7 'Cherbourg': ['C']
8 }
---> 10 df.embark_town.replace(mapping)
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/series.py:4960, in Series.replace(self, to_replace, value, inplace, limit, regex, method)
4945 @doc(
4946 NDFrame.replace, # type: ignore[has-type]
4947 klass=_shared_doc_kwargs["klass"],
(...)
4958 method: str | lib.NoDefault = lib.no_default,
4959 ):
-> 4960 return super().replace(
4961 to_replace=to_replace,
4962 value=value,
4963 inplace=inplace,
4964 limit=limit,
4965 regex=regex,
4966 method=method,
4967 )
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/generic.py:6660, in NDFrame.replace(self, to_replace, value, inplace, limit, regex, method)
6657 else:
6658 to_replace, value = keys, values
-> 6660 return self.replace(
6661 to_replace, value, inplace=inplace, limit=limit, regex=regex
6662 )
6663 else:
6664
6665 # need a non-zero len on all axes
6666 if not self.size:
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/series.py:4960, in Series.replace(self, to_replace, value, inplace, limit, regex, method)
4945 @doc(
4946 NDFrame.replace, # type: ignore[has-type]
4947 klass=_shared_doc_kwargs["klass"],
(...)
4958 method: str | lib.NoDefault = lib.no_default,
4959 ):
-> 4960 return super().replace(
4961 to_replace=to_replace,
4962 value=value,
4963 inplace=inplace,
4964 limit=limit,
4965 regex=regex,
4966 method=method,
4967 )
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/generic.py:6709, in NDFrame.replace(self, to_replace, value, inplace, limit, regex, method)
6704 if len(to_replace) != len(value):
6705 raise ValueError(
6706 f"Replacement lists must match in length. "
6707 f"Expecting {len(to_replace)} got {len(value)} "
6708 )
-> 6709 new_data = self._mgr.replace_list(
6710 src_list=to_replace,
6711 dest_list=value,
6712 inplace=inplace,
6713 regex=regex,
6714 )
6716 elif to_replace is None:
6717 if not (
6718 is_re_compilable(regex)
6719 or is_list_like(regex)
6720 or is_dict_like(regex)
6721 ):
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/internals/managers.py:458, in BaseBlockManager.replace_list(self, src_list, dest_list, inplace, regex)
455 """do a list replace"""
456 inplace = validate_bool_kwarg(inplace, "inplace")
--> 458 bm = self.apply(
459 "replace_list",
460 src_list=src_list,
461 dest_list=dest_list,
462 inplace=inplace,
463 regex=regex,
464 )
465 bm._consolidate_inplace()
466 return bm
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/internals/managers.py:304, in BaseBlockManager.apply(self, f, align_keys, ignore_failures, **kwargs)
302 applied = b.apply(f, **kwargs)
303 else:
--> 304 applied = getattr(b, f)(**kwargs)
305 except (TypeError, NotImplementedError):
306 if not ignore_failures:
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/internals/blocks.py:822, in Block.replace_list(self, src_list, dest_list, inplace, regex)
819 assert not isinstance(mib, bool)
820 m = mib[blk_num : blk_num + 1]
--> 822 result = blk._replace_coerce(
823 to_replace=src,
824 value=dest,
825 mask=m,
826 inplace=inplace,
827 regex=regex,
828 )
829 if convert and blk.is_object and not all(x is None for x in dest_list):
830 # GH#44498 avoid unwanted cast-back
831 result = extend_blocks(
832 [b.convert(numeric=False, copy=True) for b in result]
833 )
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/internals/blocks.py:886, in Block._replace_coerce(self, to_replace, value, mask, inplace, regex)
884 return [nb]
885 return [self] if inplace else [self.copy()]
--> 886 return self.replace(
887 to_replace=to_replace, value=value, inplace=inplace, mask=mask
888 )
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/internals/blocks.py:691, in Block.replace(self, to_replace, value, inplace, mask)
689 elif self._can_hold_element(value):
690 blk = self if inplace else self.copy()
--> 691 putmask_inplace(blk.values, mask, value)
692 if not (self.is_object and value is None):
693 # if the user *explicitly* gave None, we keep None, otherwise
694 # may downcast to NaN
695 blocks = blk.convert(numeric=False, copy=False)
File /rproject/ist-as-ir/envs/conda_environment/lib/python3.8/site-packages/pandas/core/array_algos/putmask.py:57, in putmask_inplace(values, mask, value)
55 values[mask] = value[mask]
56 else:
---> 57 values[mask] = value
58 else:
59 # GH#37833 np.putmask is more performant than __setitem__
60 np.putmask(values, mask, value)
ValueError: NumPy boolean array indexing assignment cannot assign 2 input values to the 4 output values where the mask is true
</code></pre>
<p>Edit: When I do the same thing with <code>pandas.Series.apply</code>, there's no error. The desired result is achieved in this case, but if there were a value in the Series that's not in the dictionary there would be an error, whereas I would want the same behavior as <code>.replace</code> where strings that aren't in the dictionary would just be left as is.</p>
<pre><code>df.embark_town.apply(lambda x: mapping[x])
</code></pre>
<p>What does <code>.apply</code> work and <code>.replace</code> doesn't? Is there a solution that works in effect the same way as <code>.replace</code>? What's the most efficient way of doing this transformation?</p>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12399409/"
] |
74,237,193 | <p>I working on an exercise where I need to use .reject to sort some items in an array.
Here is the code I'm trying:</p>
<pre><code>def short_words(array, max_length)
array.reject { |words, value| words if value > max_length }
end
</code></pre>
<blockquote>
<p>TODO: Take an array of words, return the array of words not exceeding max_length characters. You should use Enumerable#reject.</p>
</blockquote>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359354/"
] |
74,237,202 | <p>Is there a way to evaluate an expression in python and break from a loop in the same time?</p>
<p>Easiest example to explain what I have in mind:</p>
<pre><code>while True:
if bar == 'baz':
foo = bar == 'baz'
break
</code></pre>
<p>But that's programmerhorror and I wanted to do something along the lines (maybe with lambda function?):</p>
<pre><code>while True:
foo = bar == 'baz' # and in the same line call break, but only if bar equals baz
</code></pre>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13685331/"
] |
74,237,208 | <p>I am currently making a mobile app in flutter, which has a boomMenu, I would like to add a 'FutureBuilder' within this menu, this is possible, when I try to do it I get the following error:</p>
<blockquote>
<p>The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type</p>
</blockquote>
<p>**This is my code: **</p>
<pre><code>BoomMenu buildBoomMenu() {
Expanded(child:
FutureBuilder(
future: stationSvc.getStations4(http.Client()),
builder: (BuildContext context, AsyncSnapshot snapshot) {
try {
if (!snapshot.hasData) {
return SizedBox(
height: MediaQuery
.of(context)
.size
.height / 1.3,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
" Cargando....",
style: TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.normal),
),
SizedBox(
height: 25,
),
SpinKitCubeGrid(
color: Color.fromRGBO(16, 71, 115, 1)
),
],
),
),
);
}
return snapshot.data.length > 0
? ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return BoomMenu(
animatedIcon: AnimatedIcons.menu_close,
animatedIconTheme: IconThemeData(size: 152.0),
//child: Icon(Icons.add),
onOpen: () => print('OPENING DIAL'),
onClose: () => print('DIAL CLOSED'),
scrollVisible: scrollVisible,
overlayColor: Colors.black,
elevation: 10,
overlayOpacity: 0.7,
children: [
MenuItemModel(
title: snapshot.data[index].devicename!,
titleColor: Colors.grey[850]!,
subtitle: snapshot.data[index].devicename!,
subTitleColor: Colors.grey[850]!,
backgroundColor: Colors.grey[50]!,
onTap: () => print('THIRD CHILD'),
elevation: 10,
),
MenuItemModel(
title: "List",
titleColor: Colors.white,
subtitle: "Lorem ipsum dolor sit amet, consectetur",
subTitleColor: Colors.white,
backgroundColor: Colors.pinkAccent,
onTap: () => print('FOURTH CHILD'),
elevation: 10,
),
MenuItemModel(
title: "Team",
titleColor: Colors.grey[850]!,
subtitle: "Lorem ipsum dolor sit amet, consectetur",
subTitleColor: Colors.grey[850]!,
backgroundColor: Colors.grey[50]!,
onTap: () => print('THIRD CHILD'),
elevation: 10,
),
]);
})
: Center(
child: Text('No hay datos, registra un grupo primero'));
} catch (Exc) {
print(Exc);
rethrow;
}
}),
);
}
</code></pre>
<p>This is my service 'getStations4()':</p>
<pre><code>Future<List<Stations>> getStations4(http.Client client) async {
final response = await client
.get(Uri.parse('URL'));
// Use the compute function to run parsePhotos in a separate isolate.
print(compute(parseStations, response.body));
return compute(parseStations, response.body);
}
List<Stations> parseStations(String responseBody) {
final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>
();
return parsed.map<Stations>((json) =>
Stations.fromJson(json)).toList();
}
</code></pre>
<p>Images of the boomMenu:</p>
<p><a href="https://i.stack.imgur.com/5RU2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5RU2E.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/gBaav.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gBaav.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11156021/"
] |
74,237,213 | <p>I am trying to fill NaN values on a data frame with the values from another data frame. The source data frame as:</p>
<pre><code> price
timestamp
2021-10 2.60
2021-11 1.85
2022-01 12.20
2022-02 15.50
2022-03 16.00
2022-04 22.05
2022-05 16.80
2022-06 21.55
2022-07 65.45
2022-08 30.80
2022-09 5.10
2022-10 21.40
</code></pre>
<p>As you see, <strong>2021-12</strong> is missed!</p>
<p>And here is the other data frame, that I want to use in <em>fillna()</em> operation:</p>
<pre><code> price
timestamp
2021-10 NaN
2021-11 NaN
2021-12 NaN
2022-01 NaN
2022-02 NaN
2022-03 NaN
2022-04 NaN
2022-05 NaN
2022-06 NaN
2022-07 NaN
2022-08 NaN
2022-09 NaN
2022-10 NaN
</code></pre>
<p>I want to fill missing month, 2021-12, from the dataframe is only have NaN values. Here is the code I have used to do it:</p>
<pre><code>creator_primary_sales_dataFrame=creator_primary_sales_dataFrame.reset_index()
creator_primary_sales=creator_primary_sales.reset_index()
creator_primary_sales_dataFrame=creator_primary_sales.fillna(creator_primary_sales_dataFrame)
</code></pre>
<pre><code>and result:
timestamp price
0 2021-10 2.60
1 2021-11 1.85
2 2021-12 12.20
3 2022-01 15.50
4 2022-02 16.00
5 2022-03 22.05
6 2022-04 16.80
7 2022-05 21.55
8 2022-06 65.45
9 2022-07 30.80
10 2022-08 5.10
11 2022-09 21.40
12 2022-10 NaN
</code></pre>
<p>expected output:</p>
<pre><code>timestamp price
0 2021-10 2.60
1 2021-11 1.85
2 2021-12 NaN
3 2022-01 12.20
4 2022-02 15.50
5 2022-03 16.00
6 2022-04 22.05
7 2022-05 16.80
8 2022-06 21.55
9 2022-07 65.45
10 2022-08 30.80
11 2022-09 5.10
12 2022-10 21.40
</code></pre>
| [
{
"answer_id": 74237286,
"author": "Gábor Fekete",
"author_id": 6464041,
"author_profile": "https://Stackoverflow.com/users/6464041",
"pm_score": 0,
"selected": false,
"text": "n = 24**36\ni = 0\nwhile True:\n a,b = divmod(n,2)\n if a == 1:\n break\n if b > 0:\n br... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14611442/"
] |
74,237,228 | <p>I'm using <a href="https://django-simple-history.readthedocs.io/en/latest/" rel="nofollow noreferrer">django-simple-history</a> to track model changes.</p>
<p>It's easy enough to get all history records for a model class or a model instance:</p>
<pre class="lang-py prettyprint-override"><code>poll = Poll.objects.create(question="what's up?", pub_date=datetime.now())
poll.history.all()
# and
Choice.history.all()
</code></pre>
<p>But what I'm looking to do is to have endpoints like <code>/history/model</code> and <code>/history/model/1</code> that returns paginated history records for either the class or class instance.</p>
<p>Now I've already got Django REST Framework (DRF) set up with pagination, and have all my views paginated, something like:</p>
<pre class="lang-py prettyprint-override"><code>class MyModelViewSet(viewsets.ModelViewSet):
serializer_class = MyModelSerializer
permission_classes = [permissions.IsAuthenticated]
queryset = MyModel.objects.all()
class MyModelSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = MyModel
fields = ["name"]
class MyModel(models.Model):
name = models.CharField(max_length=100, unique=True)
</code></pre>
<p>That all works fine.</p>
<p>How can I paginate the <code>django-simple-history</code> records?</p>
<p>Can I create a simple history serializer? Because there's not exactly a simple history model I can use (I think).</p>
| [
{
"answer_id": 74239699,
"author": "ocobacho",
"author_id": 10297128,
"author_profile": "https://Stackoverflow.com/users/10297128",
"pm_score": 3,
"selected": true,
"text": "class Poll(models.Model):\n question = models.CharField(max_length=200)\n pub_date = models.DateTimeField('dat... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2030026/"
] |
74,237,291 | <p>I am working with RNA-seq data. I want to filter out genes where there are fewer than N counts in both replicates in at least one of my treatment groups.</p>
<p>My data is in a DESeq object, and the count data is structured like this, where each row is the gene, and each column a different sample. Sample names have the structure X|N|A|1/2 (where X is the cell line used, N is a 1 or 2 digit number reflecting treatment length, A is a letter representing the treatment group, and 1 or 2 indicates which replicate.</p>
<pre><code>X1A1 <- c(117, 24, 45, 146, 1)
X1A2 <- c(129, 31, 58, 159, 0)
X1B1 <- c(136, 25, 50, 1293, 0)
X1B2 <- c(131, 24, 50, 1073, 4)
X1C1 <- c(113, 23, 43, 132, 0)
X1C2 <- c(117, 18, 43, 126, 0)
X1D1 <- c(101, 20, 0, 875, 1)
X1D2 <- c(99, 21, 38 , 844, 0)
X24A1 <- c(109, 17, 60, 95, 0)
X24A2 <- c(122, 14, 611, 90, 0)
df <- data.frame(X1A1, X1A2, X1B1, X1B2, X1C1, X1C2, X1D1, X1D2, X24A1, X24A2)
rownames(df) <- c("geneA", "geneB", "geneC", "geneD", "geneE")
df
</code></pre>
<p>Maybe I'm just not using the right search terms, but I can't figure out how to get what I need.</p>
<p>Right now I only know how to filter out genes that are not expressed below some threshold in all samples. For example, filtering out genes which are not expressed at all.</p>
<pre><code>keep1 <- rowSums(df) > 1
df1 <- df[keep1,]
</code></pre>
<p>What I want is to refine this so that I would end up discarding geneE in my example set, because no group has counts above 0 for both replicates.</p>
<pre><code>df2 <- df[1:4,]
df2
</code></pre>
| [
{
"answer_id": 74237320,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "rowSums"
},
{
"answer_id": 74237900,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "h... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237291",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359032/"
] |
74,237,292 | <p>The below query is taking time to execute. does this have any rewrite possibilities?</p>
<pre><code> Query;
SELECT t_product.a_productid,
t_product.a_mpactive,
t_product.a_active,
trim( substring_index(a_reference, '_',-1)) as a_reference,
t_product.a_shopid,
t_productlang.a_name,
t_deactivatedproduct.a_reason
FROM t_deactivatedproduct
inner join ( SELECT max(a_deactivatedproductid) as a_deactivatedproductid
FROM t_deactivatedproduct
GROUP by t_deactivatedproduct.a_productid
) as a on a.a_deactivatedproductid = t_deactivatedproduct.a_deactivatedproductid
INNER JOIN t_product ON t_product.a_productid = t_deactivatedproduct.a_productid
INNER JOIN t_productlang ON t_product.a_productid = t_productlang.a_productid
AND t_product.a_shopid IN( 2, 3, 5, 6, 7, 10, 8, 15, 12, 16, 17, 26, 27, 28)
WHERE t_product.a_ispublished = 1
AND ( ( t_product.a_active = 1 AND t_product.a_mpactive = 0) OR (t_product.a_active = 0 AND t_product.a_mpactive = 1)
OR ( t_product.a_active = 0 AND t_product.a_mpactive = 0 ) )
ORDER BY t_deactivatedproduct.a_deactivatedproductid DESC
limit 700
</code></pre>
<p>can someone please tell me where has a problem with it and how to change it?</p>
| [
{
"answer_id": 74237320,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "rowSums"
},
{
"answer_id": 74237900,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "h... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20051145/"
] |
74,237,295 | <p>I have a table in mysql called <code>trans</code> with the following structure:</p>
<pre><code>trans (
id number
date date
amount number
)
</code></pre>
<p>The date is stored in the following format: <code>2021-09-21</code></p>
<p>I am trying to make a selection out of this table that will give me a daily average of the <code>amount</code> column.</p>
<p>But not just as simple as <code>select avg(amount)</code>, because i'm trying to get the total average even tough there are days in which i don't have any amount.</p>
<p>For example, let's take 5 pairs (date - amount):</p>
<pre><code>2021-09-21 - 100
2021-09-22 - 120
2021-09-24 - 140
2021-09-25 - 300
2021-09-28 - 450
</code></pre>
<p>If i have these values in the table, and do the AVG() i would get 1110 : 5 = 222. However, in between these dates there are dates that are empty (23,26,27 th of 09). So the daily avg is not correct, because those days are not take into account, right?</p>
<p>The daily avg should be</p>
<pre><code>2021-09-21 - 100
2021-09-22 - 120
2021-09-23 - 0
2021-09-24 - 140
2021-09-25 - 300
2021-09-26 - 0
2021-09-27 - 0
2021-09-28 - 450
</code></pre>
<p>Meaning 1110 / 8 = 138.75.</p>
<p>So i want to select this 138.75 value. Does anyone know a solution for this?
I don't want to alter the entries in any way, so I don't want to insert 0 values in between the non empty dates.</p>
<p>Thank you!</p>
| [
{
"answer_id": 74237498,
"author": "Aman Mehta",
"author_id": 13378772,
"author_profile": "https://Stackoverflow.com/users/13378772",
"pm_score": 1,
"selected": false,
"text": "Sum()"
},
{
"answer_id": 74237923,
"author": "Ozan Sen",
"author_id": 19469088,
"author_pro... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4846929/"
] |
74,237,325 | <p>Several projects we've written in Flutter are broken this morning due to failing to download <a href="https://unpkg.com/canvaskit-wasm@0.35.0/bin/canvaskit.js" rel="nofollow noreferrer">https://unpkg.com/canvaskit-wasm@0.35.0/bin/canvaskit.js</a>. Production sites aren't getting paste their splash screens.</p>
| [
{
"answer_id": 74237498,
"author": "Aman Mehta",
"author_id": 13378772,
"author_profile": "https://Stackoverflow.com/users/13378772",
"pm_score": 1,
"selected": false,
"text": "Sum()"
},
{
"answer_id": 74237923,
"author": "Ozan Sen",
"author_id": 19469088,
"author_pro... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3396908/"
] |
74,237,330 | <p>Please see this illustration:</p>
<p><a href="https://i.stack.imgur.com/Hmc02.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hmc02.png" alt="Illustration" /></a></p>
<p>I have a left 16x9 area for videos that resizes its width and height automatically for videos. This works. It's about 75% of the width of the container of both the left and right elements. (This container is somewhere on the page but is not the full width of the page.)</p>
<p>To the right of that, I want a sidebar that scrolls. The sidebar should never exceed the height of the left side. It should just scroll.</p>
<p>Here's a basic reproduction snippet. When running the snippet, you might want to use the "Full Page" option.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
<style>
.container {
display: flex;
border: 1px solid black;
padding: 5px;
}
.videoOuter {
width: 75%;
flex: 1 0 auto;
border: 1px solid red;
padding: 5px;
}
.responsiveRatioOuter {
position: relative;
padding-top: 56.25%;
border: 1px solid lime;
}
.sidebar {
border: 1px solid blue;
overflow: auto;
min-height: min-content;
}
.sidebarStatement {
font-size: 50px;
}
.sidebarFakeContent {
font-size: 30px;
}
</style>
</head>
<body>
<div class="container">
<div class="videoOuter">
<div class="responsiveRatioOuter">
Video 16x9 &lt;iframe&gt; goes here. This part works.
</div>
</div>
<div class="sidebar">
<div class="sidebarStatement">I want this to scroll while matching the height of the left video area (lime border), but this doesn't scroll. It just makes .videoOuter (red border) and .container (black border) expand.</div>
<div class="sidebarFakeContent">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</div>
</body>
</html></code></pre>
</div>
</div>
</p>
<p>To accomplish what I want, I've tried <code>display: flex</code> and <code>display: grid</code>. I haven't gotten the sidebar to scroll properly. Can someone advise me on how to make the right item no taller than the left one and allow scrolling? Thank you.</p>
| [
{
"answer_id": 74237677,
"author": "Harrison",
"author_id": 15291770,
"author_profile": "https://Stackoverflow.com/users/15291770",
"pm_score": 0,
"selected": false,
"text": "max-height"
},
{
"answer_id": 74312095,
"author": "Brandon Zhang",
"author_id": 15660890,
"au... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1325179/"
] |
74,237,339 | <p>I have upgraded mac to macOS Ventura V13</p>
<p>XCode Version 14.0.1</p>
<p>Until today everything worked perfectly on my mac for React Native, it had been days since I started anything new</p>
<p>Today I wanted to start a new project and I got some errors.</p>
<p>It's been several days looking for a solution to this problem and of course I'm not giving up, but I think trying things randomly will only mess up my configuration a lot more</p>
<p>Can you help me with this ?</p>
<p>Would it be wise to remove all my React Native Development setup and environment and start over?</p>
<p>I have started like this:</p>
<pre><code>npx react-native init MyProject
</code></pre>
<p>I EDIT THE QUESTION AFTER MAKING CHANGES</p>
<p>I have updated my version of ruby following the steps of user @Janaka-Steph, and the project builds perfectly, but when I run the app in terminal with nxp react-native run-ios , it doesn't compile and I keep getting the following errors:</p>
<pre><code>warn Multiple Podfiles were found: ios/Podfile,vendor/bundle/ruby/2.7.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/Podfile. Choosing ios/Podfile automatically. If you would like to select a different one, you can configure it via "project.ios.sourceDir". You can learn more about it here: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
info Found Xcode workspace "myProject.xcworkspace"
info Building (using "xcodebuild -workspace myProject.xcworkspace -configuration Debug -scheme myProject -destination id=")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening myProject.xcworkspace.
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace myProject.xcworkspace -configuration Debug -scheme myProject -destination id=
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
Prepare packages
Computing target dependency graph and provisioning inputs
Create build description
Build description signature:
Build description path: /Users/miguelito/Library/Developer/Xcode/DerivedData/myProject-cgujjydukqoyfycbyxyuqiquehll/Build/Intermediates.noindex/XCBuildData/fb-desc.xcbuild
note: Building targets in dependency order
CreateBuildDirectory /Users/miguelito/Library/Developer/Xcode/DerivedData/myProject-cgujjydukqoyfycbyxyuqiquehll/Build/Intermediates.noindex
cd /Volumes/DeTodo/REACT\ NATIVE/myProject/ios
builtin-create-build-directory /Users/miguelito/Library/Developer/Xcode/DerivedData/myProject-cgujjydukqoyfycbyxyuqiquehll/Build/Intermediates.noindex
</code></pre>
<p>I don't add all the console output because it's a lot and always repeated, but this is also shown in the console errors at the end:</p>
<pre><code>In file included from /Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/event-internal.h:43:
/Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/defer-internal.h:44:11: warning: parameter 'deferred' not found in the function declaration [-Wdocumentation]
@param deferred The struct event_callback structure to initialize.
^~~~~~~~
/Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/defer-internal.h:45:11: warning: parameter 'priority' not found in the function declaration [-Wdocumentation]
@param priority The priority that the callback should run at.
^~~~~~~~
/Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/defer-internal.h:46:11: warning: parameter 'cb' not found in the function declaration [-Wdocumentation]
@param cb The function to run when the struct event_callback executes.
^~
/Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/defer-internal.h:47:11: warning: parameter 'arg' not found in the function declaration [-Wdocumentation]
@param arg The function's second argument.
^~~
In file included from /Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/select.c:57:
/Volumes/DeTodo/REACT NATIVE/myProject/ios/Pods/libevent/include/event2/thread.h:187:11: warning: parameter 'base' not found in the function declaration [-Wdocumentation]
@param base the event base for which to set the id function
^~~~
52 warnings generated.
</code></pre>
<p>I have tried to run the application in XCode, but I also get errors:</p>
<pre><code>**'CLOCK_REALTIME' macro redefined**
in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:
previous definition is here
**'CLOCK_MONOTONIC' macro redefined**
in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:
in file included from /myProject/ios/Pods/Headers/Private/RCT-Folly/folly/Chrono.h:26:
previous definition is here
**'CLOCK_PROCESS_CPUTIME_ID' macro redefined**
in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:
in file included from /myProject/ios/Pods/Headers/Private/RCT-Folly/folly/Chrono.h:26:
previous definition is here
**'CLOCK_THREAD_CPUTIME_ID' macro redefined**
in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:
in file included from /myProject/ios/Pods/Headers/Private/RCT-Folly/folly/Chrono.h:26:
previous definition is here
.../ios/Pods/Headers/Private/RCT-Folly/folly/portability/Time.h:52:17: ***Typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')***
</code></pre>
<p>And of course the following:</p>
<p><em><strong>Typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')</strong></em></p>
<p>in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:
in file included from /myProject/ios/Pods/Headers/Private/RCT-Folly/folly/Chrono.h:26:
previous definition is here</p>
<blockquote>
<ul>
<li>in file included from /myProject/ios/Pods/RCT-Folly/folly/io/async/TimeoutManager.cpp:22:</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>in file included from /myProject/ios/Pods/Headers/Private/RCT-Folly/folly/Chrono.h:26: previous definition is here</li>
</ul>
<p>Run script build phase 'Bundle React Native code and images' will be
run during every build because it does not specify any outputs. To
address this warning, either add output dependencies to the script
phase, or configure it to run in every build by unchecking "Based on
dependency analysis" in the script phase.</p>
</blockquote>
<p>When I try to run the project for Android ( <code>npx react-native run-android</code>), it doesn't work either, I get a lot of errors, but when I run the project in Android Studio, everything works</p>
<p>I must say that I have put into practice some of the solutions proposed in <a href="https://www.google.com/search?q=Folly/folly/portability/Time.h:52:17:%20Typedef%20redefinition%20with%20different%20types%20(%27uint8_t%27%20(aka%20%27unsigned%20char%27)%20vs%20%27enum%20clockid_t%27)%20site:stackoverflow.com&sxsrf=ALiCzsbi1K7xHnCgo2TCf_dBt-hd2Pf1kA:1667205804783&sa=X&ved=2ahUKEwiju4vOiYr7AhXN44UKHUHXCyMQrQIoBHoECBIQBQ&biw=1105&bih=978&dpr=2" rel="nofollow noreferrer">questions similar to mine</a>, but I can't find a solution.</p>
<p>I've googled, Forums, Stack for solutions and found stuff, made changes to my React Native install, install Node again, Brew again, made a lot of changes and now nothing works.</p>
| [
{
"answer_id": 74262330,
"author": "Ranjith Varma",
"author_id": 1993274,
"author_profile": "https://Stackoverflow.com/users/1993274",
"pm_score": 1,
"selected": false,
"text": "error Your Ruby version is 2.6.10, but your Gemfile specified 2.7.5\n"
},
{
"answer_id": 74305745,
... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8083257/"
] |
74,237,354 | <p>I'm trying to set an object property using a function that returns and object.</p>
<p>The problem is when setting the property I'm getting back an array as a value instead of the object.</p>
<pre class="lang-js prettyprint-override"><code>const newUserRights = {
A: { id: '1'},
B: { id: '2'},
C: { id: '3'},
D: { id: '4'},
E: { id: '5'},
F: { id: '6'},
G: { id: '7'},
};
var Post = {
name: '',
rs: function r(rights = []) {
let r = {};
for (let [k, v] of Object.entries(newUserRights)) {
r[v.id] = false;
}
if (rights.length > 0) {
for (ri of rights) {
r[ri] = true;
}
}
return r;
},
};
// trying to set the property
Post.rs = ['1', '2'];
</code></pre>
<p>Desired output:</p>
<pre class="lang-js prettyprint-override"><code>Post: {
name:'',
rs:{
1: true,
2: true,
3: false,
4: false,
5: false,
6: false,
7: false
}
}
</code></pre>
<p>But getting:</p>
<pre class="lang-js prettyprint-override"><code>Post: {
name:'',
rs:['1', '2']
}
</code></pre>
<p>I want to know</p>
<ul>
<li>what I'm doing wrong</li>
<li>How to return the Object</li>
<li>Is this a good practice</li>
</ul>
<p>Thank you</p>
| [
{
"answer_id": 74237546,
"author": "Asraf",
"author_id": 5887988,
"author_profile": "https://Stackoverflow.com/users/5887988",
"pm_score": 0,
"selected": false,
"text": "Post.rs(['1', '2'])"
},
{
"answer_id": 74237574,
"author": "Ben Aston",
"author_id": 38522,
"autho... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9176212/"
] |
74,237,370 | <p>I'm working on a little game to learn java.
Currently I created a Sphere, a Player and a Game class ( + Main class to run).
I want the shpere to know, whether it collides with the player or not.</p>
<p>First thing I tried was the Get and Set thing, but the problem is, that I have to create a Player-Object
in the Sphere-class to acces the Get-Method of the Players Position.</p>
<p>As it's a new object, it's not the same as the Object in my Game-Class, so it doesn't change when moving.</p>
| [
{
"answer_id": 74237546,
"author": "Asraf",
"author_id": 5887988,
"author_profile": "https://Stackoverflow.com/users/5887988",
"pm_score": 0,
"selected": false,
"text": "Post.rs(['1', '2'])"
},
{
"answer_id": 74237574,
"author": "Ben Aston",
"author_id": 38522,
"autho... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20168570/"
] |
74,237,380 | <p>I came across the following code:</p>
<pre><code>auto x = new int[10][10];
</code></pre>
<p>Which compiles and runs correctly but I can't figure out what would be the type for defining <code>x</code> separately from the assignment.</p>
<p>When debugging the type shown is <code>int(*)[10]</code> for <code>x</code> but <code>int (*) x[10];</code> (or any other combination I tried) is illegal.</p>
<p>So are there cases where <code>auto</code> can't be replaced by an explicit type...? (and is this such a case?)</p>
| [
{
"answer_id": 74237458,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 4,
"selected": true,
"text": "x"
},
{
"answer_id": 74237626,
"author": "alfC",
"author_id": 225186,
"author_profile": "htt... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2375105/"
] |
74,237,382 | <p>I have the problem that I can't manage to convert this if statment into a switch case function. The function gets a value either SEND,LIST,READ,DEL,Quit and after that something else should happen with it.</p>
<p>int getCommand(char *buffer){</p>
<pre><code>int action = 0;
if((buffer[0] == 's' && buffer[1] == 'e' && buffer[2] == 'n' && buffer[3] == 'd')
|| (buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'D')){
action = 1;
}
else if((buffer[0] == 'l' && buffer[1] == 'i' && buffer[2] == 's' && buffer[3] == 't')
|| (buffer[0] == 'L' && buffer[1] == 'I' && buffer[2] == 'S' && buffer[3] == 'T')){
action = 2;
}
else if((buffer[0] == 'r' && buffer[1] == 'e' && buffer[2] == 'a' && buffer[3] == 'd')
|| (buffer[0] == 'R' && buffer[1] == 'E' && buffer[2] == 'A' && buffer[3] == 'D')){
action = 3;
}
else if((buffer[0] == 'd' && buffer[1] == 'e' && buffer[2] == 'l')
|| (buffer[0] == 'D' && buffer[1] == 'E' && buffer[2] == 'L')){
action = 4;
}
else if((buffer[0] == 'q' && buffer[1] == 'u' && buffer[2] == 'i' && buffer[3] == 't')
|| (buffer[0] == 'Q' && buffer[1] == 'U' && buffer[2] == 'I' && buffer[3] == 'T')){
action = 5;
}
</code></pre>
<p>return action;
}</p>
<p>Is there maybe also a way to write this better?</p>
<p>Is there maybe also a way to write this better?</p>
| [
{
"answer_id": 74237619,
"author": "Sven Nilsson",
"author_id": 4847311,
"author_profile": "https://Stackoverflow.com/users/4847311",
"pm_score": 3,
"selected": true,
"text": "if (!strncmp(buffer, \"send\", 4) || !strncmp(buffer, \"SEND\", 4))\n action = 1;\nelse if (!strncmp(buffer, ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359510/"
] |
74,237,407 | <p>For instance, this is the list:</p>
<pre><code>exchange_list = ['coin', 'quarter', 'dime', 'penny', 'buck', 'bitcoin']
exchanger = input("Please give the input of a money currency that you'd like to exchange")
</code></pre>
<p>How do I make it so that if my input for instance is 'penny' that it selects the next item in the list (in this case 'buck'), and if the input is the same as the last item in the list (in this case 'bitcoin'), that it selects the first (in this case 'coin') ?</p>
| [
{
"answer_id": 74237619,
"author": "Sven Nilsson",
"author_id": 4847311,
"author_profile": "https://Stackoverflow.com/users/4847311",
"pm_score": 3,
"selected": true,
"text": "if (!strncmp(buffer, \"send\", 4) || !strncmp(buffer, \"SEND\", 4))\n action = 1;\nelse if (!strncmp(buffer, ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20231159/"
] |
74,237,495 | <p>I am parsing Elastic logs that look like</p>
<pre><code>$ cat my_log_file.txt:
{"level": "INFO", "message": "foo"}
{"level": "WARN", "message": "bar"}
{"level": "WARN", "message": "baz"}
</code></pre>
<p>Because they're one per line, formerly I have used <code>jq -s</code> to slurp them into an actual array that I can run <code>map</code> on:</p>
<pre><code>jq -s 'map(.message) | unique' my_log_file.txt
</code></pre>
<p>Now I want to select out only lines that have level != "INFO". I should be able to just use <a href="https://github.com/stedolan/jq/wiki/Cookbook#filter-objects-based-on-the-contents-of-a-key" rel="nofollow noreferrer">this cookbook recipe</a>, but again <code>jq</code> is having trouble with each line being a separate object and not in an array.</p>
<p>I can't use slurp, because it doesn't work with this command:</p>
<pre><code>jq 'select(."level" != "INFO")' my_log_file.txt
</code></pre>
<p>But when I want to map to .message again, I get the same error I got before when I wasn't using slurp:</p>
<pre><code>$ jq 'select(."level" != "INFO") | map(.message) | unique' my_log_file.txt
jq: error (at <stdin>:90): Cannot index string with string "message"
</code></pre>
<p>How can I convert my records midstream -- after the select is done, to convert the result from</p>
<pre><code>{"level": "WARN", "message": "bar"}
{"level": "WARN", "message": "bar"}
</code></pre>
<p>to</p>
<pre><code>[
{"level": "WARN", "message": "bar"},
{"level": "WARN", "message": "bar"}
]
</code></pre>
<p>I heard that <code>inputs</code> was designed to replace slurp, but when I tried</p>
<pre><code>$ jq 'select(."level" != "INFO") | [inputs]' my_log_file.txt
</code></pre>
<p>that ignored my <code>select</code> and I had a list of every message again.</p>
| [
{
"answer_id": 74237619,
"author": "Sven Nilsson",
"author_id": 4847311,
"author_profile": "https://Stackoverflow.com/users/4847311",
"pm_score": 3,
"selected": true,
"text": "if (!strncmp(buffer, \"send\", 4) || !strncmp(buffer, \"SEND\", 4))\n action = 1;\nelse if (!strncmp(buffer, ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/733092/"
] |
74,237,521 | <p>i want to numbers in the text entered by the user are converted into text and printed on the screen. Example:</p>
<p>cin>> My School Number is 5674
and i want to "my school number is five six seven four" output like this. I make only Convert to number to text but i cant put together text and numbers please help me</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
using namespace std;
void NumbertoCharacter(int n)
{
int rev = 0, r = 0;
while (n > 0) {
r = n % 10;
rev = rev * 10 + r;
n = n / 10;
}
while (rev > 0) {
r = rev % 10;
switch (r) {
case 1:
cout << "one ";
break;
case 2:
cout << "two ";
break;
case 3:
cout << "three ";
break;
case 4:
cout << "four ";
break;
case 5:
cout << "five ";
break;
case 6:
cout << "six ";
break;
case 7:
cout << "seven ";
break;
case 8:
cout << "eight ";
break;
case 9:
cout << "nine ";
break;
case 0:
cout << "zero ";
break;
default:
cout << "invalid ";
break;
}
rev = rev / 10;
}
}
int main()
{
int n;
cin >> n;
NumbertoCharacter(n);
return 0;
}
</code></pre>
| [
{
"answer_id": 74237751,
"author": "chill389cc",
"author_id": 6901706,
"author_profile": "https://Stackoverflow.com/users/6901706",
"pm_score": -1,
"selected": true,
"text": "int charToInt = a - '0';"
},
{
"answer_id": 74237955,
"author": "PaulMcKenzie",
"author_id": 3133... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17998759/"
] |
74,237,542 | <p>I have a FastAPI app with some routes working fine if I move around them manually (by changing the <code>/<path></code> in the browser's address bar). For example, this is one of them:</p>
<pre class="lang-py prettyprint-override"><code>@task.get('/tasks', response_model=list[Task], tags=["Tasks"])
def find_all_tasks():
print("\n[*] Showing all Tasks\n")
return tasksEntity(conn.local.task.find())
</code></pre>
<p>My <code>/<root></code> route loads an <code>index.html</code> file that displays a button. What I want to do is whenever I click the button to have the above route, for instance, added to the url (i.e., <code>127.0.0.1/tasks</code>).</p>
<p>I use <code>Jinja2Templates</code> to render data in the HTML from different routes of the API, but I dont know how to move around them from the frontend HTML buttons.</p>
| [
{
"answer_id": 74237623,
"author": "Taek",
"author_id": 4047185,
"author_profile": "https://Stackoverflow.com/users/4047185",
"pm_score": 0,
"selected": false,
"text": "app.url_path_for('find_all_tasks')"
},
{
"answer_id": 74237972,
"author": "Chris",
"author_id": 1786580... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14855493/"
] |
74,237,584 | <p>I have a table that I unfortunately can't alter, but I can use to create a view. The issue is that the data in one column is spread across multiple rows. Here's a sample of what that looks like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Customer</th>
<th>Activity</th>
<th>Note</th>
<th>Sequence</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Note</td>
<td>The custo</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>Note</td>
<td>mer calle</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>Note</td>
<td>d and lef</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>Note</td>
<td>t a messa</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>Note</td>
<td>ge.</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>Charge</td>
<td>$39.95</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>Charge</td>
<td>$14.47</td>
<td>7</td>
</tr>
</tbody>
</table>
</div>
<p>I need the data to look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Customer</th>
<th>Activity</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Note</td>
<td>The customer called and left a message.</td>
</tr>
<tr>
<td>1</td>
<td>Charge</td>
<td>$39.95</td>
</tr>
<tr>
<td>2</td>
<td>Charge</td>
<td>$14.47</td>
</tr>
</tbody>
</table>
</div>
<p>Any ideas on how to do it?</p>
| [
{
"answer_id": 74240734,
"author": "DannySlor",
"author_id": 19174570,
"author_profile": "https://Stackoverflow.com/users/19174570",
"pm_score": 1,
"selected": false,
"text": "select customer\n ,Activity\n ,string_agg(note, '') within group (order by Sequence) as note\nfr... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19455250/"
] |
74,237,591 | <p>My function :</p>
<pre><code>def check(list,num):
check if there is list[x] > list[0]+num # in case num is positive
OR if there is list[x] < list[0]+num # in case num is negative
</code></pre>
<p>So I can send 50 to check if we are up 50, or -50 to check if we are down 50.</p>
<p>The only way I see to do this is ugly :</p>
<pre><code> for x in list:
if num > 0 :
if x > list[0] + num : do something
if num < 0 :
if x < list[0] + num : do something
</code></pre>
<p>Since i can not send <code>></code> as an argument and use a single line, I am looking for a more <strong>elegant</strong> way.</p>
| [
{
"answer_id": 74240734,
"author": "DannySlor",
"author_id": 19174570,
"author_profile": "https://Stackoverflow.com/users/19174570",
"pm_score": 1,
"selected": false,
"text": "select customer\n ,Activity\n ,string_agg(note, '') within group (order by Sequence) as note\nfr... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18813761/"
] |
74,237,600 | <p>I'm trying to change someone's name in a Pandas data frame.</p>
<p>I've tried using this code, but it just adds to the current name:</p>
<pre class="lang-py prettyprint-override"><code>def rename(self):
id = '1'
person = (df.loc[df['id'] == id])
print(person)
newName = 'tom'
df.loc[df['id'] == id, ['name']] = df['name'] - df['name'] + newName
</code></pre>
<p>Input:</p>
<pre class="lang-py prettyprint-override"><code>id name age
1 bob 40
</code></pre>
<p>Expected output:</p>
<pre class="lang-py prettyprint-override"><code>id name age
1 tom 40
</code></pre>
| [
{
"answer_id": 74237678,
"author": "Gerard",
"author_id": 5760497,
"author_profile": "https://Stackoverflow.com/users/5760497",
"pm_score": 2,
"selected": false,
"text": "df.loc[df.id == 1, 'name'] = 'tom'\n"
},
{
"answer_id": 74237695,
"author": "Rodrigo Guzman",
"author... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20149563/"
] |
74,237,639 | <p>I would like to ask you why usage <code>@Override</code> in this case produces an error "<code>Method does not override method from its superclass</code>"? Why I cannot use instance of the class implemented an interface as a parameter and return type of the metod defined by same interface?</p>
<pre><code> public interface Request {
//....
}
public interface Response {
//....
}
public class MyRequest implements Request {
//....
}
public class MyResponse implements Response {
//....
}
public interface Order {
Response cancel(Request request);
}
public class MyOrder implements Order {
@Override
public MyResponse cancel(MyRequest request) {
return null;
}
}
</code></pre>
| [
{
"answer_id": 74237673,
"author": "Louis Wasserman",
"author_id": 869736,
"author_profile": "https://Stackoverflow.com/users/869736",
"pm_score": 2,
"selected": true,
"text": "class MyOtherRequest implements Request { ... }\n\nMyOrder myOrder = new MyOrder();\nOrder order = myOrder; // ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1315357/"
] |
74,237,685 | <p>I am trying to perform a linear search on an ordered array for a specific number. If the number is found, the algorithm must return its index. If we reach an element that is greater than the number, the algorithm should break. Lastly, if the number is not in the array print <code>None</code>. When I run the code, it returns no output. I have tried different variations of even including the number I am looking for in the array but the code still produces no output.</p>
<pre><code>def linear_search(array, number):
for el in range(len(array)):
if el == number:
return array[el]
elif el > number:
break
else:
return None
print(linear_search([10,11,12,22],22))
</code></pre>
| [
{
"answer_id": 74237735,
"author": "Rodrigo Guzman",
"author_id": 13315525,
"author_profile": "https://Stackoverflow.com/users/13315525",
"pm_score": -1,
"selected": false,
"text": "def linear_search(array, number):\n for el in range(len(array)):\n if array[el] == number:\n ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359434/"
] |
74,237,686 | <p>Both the images and their paragraphs are arranged neatly when being faced vertically, but I'm not sure how to make them face horizontally without messing it up. When I try to do it, the content messes up horribly.</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> body {
font-family: Arial, Helvetica, sans-serif;
}
header {
background-color: rgb(255, 255, 255);
height: 600px;
}
.navbar {
width: 98.5%;
margin: auto;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
outline: none;
}
.logo {
width: 160px;
cursor: pointer;
margin-right: auto;
}
.navbar .dropdown {
display: none;
box-shadow: 0px 0px 2px #000;
border-radius: 5px;
left: -30%;
outline: none;
}
.navbar ul li:hover .dropdown {
display: block;
}
.navbar>ul>li {
position: relative;
}
.navbar>ul>li>.dropdown {
position: absolute;
top: 1.4em;
}
.navbar .dropdown li {
display: block;
margin: 15px;
text-align: center;
}
.navbar ul li {
list-style: none;
display: inline-block;
margin: 0 20px;
position: relative;
}
.navbar ul li a {
text-decoration: none;
color: black;
border-bottom: 0px;
}
.navbar ul li a:hover {
color: teal;
}
.navbar>ul>li::after {
content: '';
height: 3px;
width: 0;
background: teal;
position: absolute;
left: 0;
bottom: 0px;
transition: 0.5s;
}
.navbar>ul>li:hover::after {
width: 100%;
}
button1 {
list-style: none;
border: none;
background: teal;
padding: 10px 20px;
border-radius: 20px;
color: white;
font-size: 15px;
transition: 0.4s;
}
footer {
height: auto;
background-color: rgb(255, 255, 255);
padding-top: 0px;
margin-top: 150px;
}
.socials {
display: flex;
align-it</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="banner-home">
<div class="navbar">
<img src="icon.png" class="logo">
<ul>
<li><a href="http://127.0.0.1:3000/Project/Home.html">Home</a></li>
<li><a href="#">Products</a>
<ul class="dropdown">
<li><a href="#">Healthcare</a></li>
<li><a href="#">Cosmetic</a></li>
<li><a href="#">Misc.</a></li>
</ul>
</li>
<li><a href="http://127.0.0.1:3000/Project/AboutUs.html">About Us</a></li>
<li><a href="#">Register</a></li>
</ul>
<a href="#" style="text-decoration:none;">
<button1>Login</button1>
</a>
</div>
<div class="cosmetics-header">
<h1>Cosmetics</h1>
<p> Choose from a wide variety of cosmetics, made to spark the beauty inside you.</p>
</div>
<div class="cosmetics-content">
<div class="nail-polish">
<p>Best Selling!</p>
<img src="nail_polish.jpg" width="200" height="200">
</div>
<div>
<p><b>Nail Polish</b></p>
<p>Choose from a wide variety of colors, guaranteed to last long and easily removable.<br>
</p>
</div>
<div>
<img src="lipstick.jpg">
<div>
<p><b>Lipstick</b></p>
<p> Highly pigmented lip color with a creamy smooth glide during application that leaves lips feeling hydrated, nurtured, and conditioned.<br>
</p>
</div>
</div>
<img src="brush.jpg" alt="" data-image-width="500" data-image-height="500">
<div>
<p><b>12pcs Brush Set</b></p>
<p> Containing 12 high quality and durable make-up brushes.<br>
</p>
</div>
</div>
</div>
<footer>
<div>
<ul class="socials">
<li><a href="https://twitter.com/Clownehara" target="_blank"><i class="fa fa-twitter"></i></a></li>
<li><a href="https://www.facebook.com/profile.php?id=100012662688022" target="_blank"><i class="fa fa-facebook"></i></a></li>
<li><a href="https://www.instagram.com/satrianavito/" target="_blank"><i class="fa fa-instagram"></i></a></li>
</ul>
<div class="footer-content">
<p>Copyright Ⓒ 2022 [Muhammad Vito Ananda Satriana]. All Rights Reserved.</p>
</div>
</footer></code></pre>
</div>
</div>
</p>
<p>I tried using display flex but the result is messy like the pictures and paragraphs are merged.</p>
| [
{
"answer_id": 74237916,
"author": "Asmoth",
"author_id": 20185425,
"author_profile": "https://Stackoverflow.com/users/20185425",
"pm_score": -1,
"selected": false,
"text": "nail-polish"
},
{
"answer_id": 74238401,
"author": "Glen tea.",
"author_id": 10243873,
"author... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20333204/"
] |
74,237,688 | <p>I am trying to import data from the following website to google sheets. I want to import all the matches for the day.</p>
<p><a href="https://www.tournamentsoftware.com/tournament/b731fdcd-a0c8-4558-9344-2a14c267ee8b/Matches" rel="nofollow noreferrer">https://www.tournamentsoftware.com/tournament/b731fdcd-a0c8-4558-9344-2a14c267ee8b/Matches</a></p>
<p>I have tried <code>importxml</code> and <code>importhtml</code> but it seems this does not work as the website uses JavaScript. I have also tried to use Aphipheny with no success.</p>
<p>When using Apipheny the error message is</p>
<blockquote>
<p>'Failed to fetch data - please verify your API Request: {DNS error'</p>
</blockquote>
| [
{
"answer_id": 74245749,
"author": "Rubén",
"author_id": 1595451,
"author_profile": "https://Stackoverflow.com/users/1595451",
"pm_score": 2,
"selected": false,
"text": "<script>"
},
{
"answer_id": 74528162,
"author": "Anthony S",
"author_id": 19917207,
"author_profil... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18244192/"
] |
74,237,742 | <p>I am trying to run the WebApp B2C sample:
<a href="https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-5-B2C" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-5-B2C</a></p>
<p>When I try to login, I get the following error:</p>
<p><code>IDX40002: Microsoft.IdentityModel does not support a B2C issuer with 'tfp' in the URI. See https://aka.ms/ms-id-web/b2c-issuer for details.</code></p>
<p>If I edit the <code>Instance</code> to <code>https://myHost.b2clogin.com</code> I get:</p>
<p><code> AADSTS50011: The redirect URI 'https://myHost.b2clogin.com/1c2009bb-7e35-4a0e-9f22-xxxxxxxxx/oauth2/authresp' specified in the request does not match the redirect URIs configured for the application 'c24b0337-0bd9-45ee-8376-xxxxxxxxx'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal. Navigate to https://aka.ms/redirectUriMismatchError to learn more about how to fix this.</code></p>
<p><strong>Edit:</strong>
These are my redirects:
<a href="https://i.stack.imgur.com/oj1YT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oj1YT.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74275800,
"author": "Sridevi",
"author_id": 18043665,
"author_profile": "https://Stackoverflow.com/users/18043665",
"pm_score": 1,
"selected": false,
"text": "webapp1"
},
{
"answer_id": 74359555,
"author": "Emaborsa",
"author_id": 754587,
"author_profil... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/754587/"
] |
74,237,761 | <p>Is there a class in standard library that will invoke provided function in its destructor?
Something like this</p>
<pre><code>class Foo
{
public:
template<typename T>
Foo(T callback)
{
_callback = callback;
}
~Foo()
{
_callback();
}
private:
std::function<void()> _callback;
};
auto rai = Foo([](){ cout << "dtor";});
</code></pre>
| [
{
"answer_id": 74237982,
"author": "apple apple",
"author_id": 5980430,
"author_profile": "https://Stackoverflow.com/users/5980430",
"pm_score": 4,
"selected": true,
"text": "scope_exit"
},
{
"answer_id": 74238075,
"author": "Yksisarvinen",
"author_id": 7976805,
"auth... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14780687/"
] |
74,237,764 | <p>I have the following example:</p>
<pre><code><h1>{errors.email?.message || ' '}</h1>
</code></pre>
<p>Which means: If there is an error message, display it, else display a normal space.<br />
The problem I faced is that react shows the error if it's available, else it doesn't show anything, in other words, the space string is always ignored and will be never displayed.</p>
<p>Why is this happening and how can I show a string that contains only a whitespace</p>
| [
{
"answer_id": 74237827,
"author": "David",
"author_id": 13019276,
"author_profile": "https://Stackoverflow.com/users/13019276",
"pm_score": 0,
"selected": false,
"text": "errors.email?.message"
},
{
"answer_id": 74238112,
"author": "caTS",
"author_id": 18244921,
"aut... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15368012/"
] |
74,237,781 | <p>The user can search for products if any product shown in the result exists in the <code>user_favorites</code> table so the show flag tells the front-end this product was added for this user by user_id and product_id. with spring boot and spring data.</p>
<p>My Entity :</p>
<pre><code>@Id
@Column(name = "catId")
private Integer catId;
@Column(name = "cat_no")
private String catNo;
@Column(name = "cat_sn")
private String catSn;
@Column(name = "doc_ref")
private String docRef;
@Column(name = "user_id")
private Integer userId;
@Column(name = "updated_at")
private String updatedAt;
@Column(name = "created_at")
private String createdAt;
</code></pre>
<p>I tried that using <code>@Formula</code> but nothing happing always returns null. and if it's done by <code>@Formula</code> how can i add parameters to <code>@Formula</code></p>
<pre><code>@Formula(value = "SELECT count(*) as checker FROM fb_user_favorites WHERE cat_id = 34699 AND user_id = '52') ")
@Transient
private String checker;
</code></pre>
| [
{
"answer_id": 74237827,
"author": "David",
"author_id": 13019276,
"author_profile": "https://Stackoverflow.com/users/13019276",
"pm_score": 0,
"selected": false,
"text": "errors.email?.message"
},
{
"answer_id": 74238112,
"author": "caTS",
"author_id": 18244921,
"aut... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8370334/"
] |
74,237,800 | <p>I have written a code to get list from tuple and append a number to it. I have read other posts about this, and know that list.append returns None, and None would be printed. But in my code, how can I append the new value? Thank you.</p>
<pre><code>from itertools import combinations
steps = [1,2,3,4,5,6,7,8]
for i in range(7, 8):
for subset in combinations(steps, i):
tmp_subset = list(subset).append(1)
print(tmp_subset)
</code></pre>
| [
{
"answer_id": 74237851,
"author": "Nathan Roberts",
"author_id": 17135653,
"author_profile": "https://Stackoverflow.com/users/17135653",
"pm_score": 1,
"selected": false,
"text": "list.append()"
},
{
"answer_id": 74237898,
"author": "Johnny",
"author_id": 11151965,
"... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11151965/"
] |
74,237,810 | <p>I have collection with documents, for example:</p>
<pre class="lang-json prettyprint-override"><code> [
{
'id':'1'
'some_field':'test',
'rates':[
{'user_id':'12','rate':'very_good'},
{'user_id':'13','rate':'very_good'}
{'user_id':'14','rate':'bad'},
{'user_id':'15','rate':'normal'}
]
}
]
</code></pre>
<p>And i have collection with values of rates in string:</p>
<pre class="lang-json prettyprint-override"><code> [
{
"rate_name" : "bad",
"rate_value" : 1
},
{
"rate_name" : "normal",
"rate_value" : 2
},
{
"rate_name" : "very_good",
"rate_value" : 3
},
]
</code></pre>
<p>I need map data from first collection from array rates with value from second collection and group this values to new field.</p>
<p>For example:</p>
<pre class="lang-json prettyprint-override"><code> [
{
'id':'1'
'some_field':'test',
'rates':[3,3,1,2]
]
}
]
</code></pre>
<p>How i can do this?</p>
| [
{
"answer_id": 74238029,
"author": "rickhg12hs",
"author_id": 1409374,
"author_profile": "https://Stackoverflow.com/users/1409374",
"pm_score": 3,
"selected": true,
"text": "\"$getField\""
},
{
"answer_id": 74238775,
"author": "ray",
"author_id": 14732669,
"author_pro... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9905185/"
] |
74,237,819 | <p>This is web scrapping proyect using puppeteer.
I have multiples <code>li</code> html elements inside <code>ul</code> tag. I don't want to make the question longer so I only write one <code>li</code> tag, the others <code>li</code> are the same only change the parameter <code>productId</code> number that is contained in <code>document.location.href</code>
Of course when I click the li tag this navigate to the full url.</p>
<pre><code><ul class="performances_sub_group_container">
<li onclick="
document.location.href = '/secured/selection/resale/item?performanceId=101437163856&amp;productId=101397570845&amp;lang=es';"
aria-labelledby="event_code_M2
dtm_M2
venue_M2
teams_M2
availability_M2"
style="height: fit-content; cursor: pointer; display: flex;"
data-opposing-team-id="783565623"
data-host-team-id="783565809"
class="
resale_item
add_keyboard_support
performance
available
performance_SPORTING_EVENT
performance-1
with_location"
data-venue-id="101395257340"
id="101437163856">
</li>
</ul>
</code></pre>
<p>I need to get the url from the <code>onclick</code> attribute locate in <code>li</code> tag</p>
<pre><code>onclick="document.location.href = '/secured/selection/resale/item?performanceId=101437163856&amp;productId=101397570845&amp;lang=es';"
</code></pre>
<p>What I have so far is I can accesss to onclick attribute converting it to string with the following code</p>
<pre><code>const getPartidos = await newPage.$$("ul.performances_group_container > li > ul > li.available")
for (const partido of getPartidos) {
const urlPartidos = await newPage.evaluate((element) => {
return element.onclick.toString()
}, partido)
console.log(urlPartidos)
}
</code></pre>
<p>The result of <code>console.log(urlPartidos)</code> is:</p>
<pre><code>function onclick(event) {
document.location.href = '/secured/selection/resale/item?performanceId=101437163899&productId=101397570845&lang=es';
}
function onclick(event) {
document.location.href = '/secured/selection/resale/item?performanceId=101437163910&productId=101397570845&lang=es';
}
function onclick(event) {
document.location.href = '/secured/selection/resale/item?performanceId=101437163911&productId=101397570845&lang=es';
}
</code></pre>
<h3>1. How can I get the url from the onclick function?</h3>
<h3>2. How can I save the url into an array of objects, where every object contain the url like this:</h3>
<pre><code>[
{
url:"https://example.com/secured/selection/resale/item?performanceId=101437163899&productId=101397570845&lang=es
},
{
url:"https://example.com/secured/selection/resale/item?performanceId=101437163910&productId=101397570845&lang=es
},
{
url:"https://example.com/secured/selection/resale/item?performanceId=101437163911&productId=101397570845&lang=es
}
]
</code></pre>
<h3>There is a way to get this final result?</h3>
| [
{
"answer_id": 74238029,
"author": "rickhg12hs",
"author_id": 1409374,
"author_profile": "https://Stackoverflow.com/users/1409374",
"pm_score": 3,
"selected": true,
"text": "\"$getField\""
},
{
"answer_id": 74238775,
"author": "ray",
"author_id": 14732669,
"author_pro... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12162472/"
] |
74,237,841 | <p>I will need to parse thousands upon thousands of simple entries in C++. I've only ever programmed in C, so I might be missing some higher functions to make this task easier.</p>
<p>An entry consists of 4 separate values: a <code>sender</code>, a <code>receiver</code>, a <code>date</code>, and a <code>type of mail</code>. Three of these are <code>string</code> values, the last one is an <code>integer</code>. My goal (after all entries are processed) is to print out all different entries that were received on the input and how many times each of these entries were received.</p>
<p>That means that if there was the same sender, receiver, date, and type of mail, multiple times on the input, the output would say that this entry was received e.g 5 times.</p>
<p>What would be the best way to do this? I tried C++ <code>map</code> but was unable to make it work.</p>
| [
{
"answer_id": 74238061,
"author": "lorro",
"author_id": 6292621,
"author_profile": "https://Stackoverflow.com/users/6292621",
"pm_score": 0,
"selected": false,
"text": "struct Entry {\n friend bool operator<(const Entry& lhs, const Entry& rhs) {\n if (lhs.sender < rhs.sender) ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7147508/"
] |
74,237,861 | <p>In a Svelte project I need to create an element programmatically and I wish to set events for it. In this sample the html item 'old text' works correctly, but if I try to create an element programmatically ('new text'), it does not seem to recognise the events.</p>
<p><a href="https://svelte.dev/repl/aaee471c2b034439be652a846558be31?version=3.52.0" rel="nofollow noreferrer">REPL</a></p>
<p><strong>App.svelte</strong></p>
<pre><code><script>
let image_holder_id
let colour = 'red';
function refresh() {
let new_text = document.getElementById('new-text')
new_text.innerHTML = '<p on:mouseover={handleMouseOver} on:mouseout={handleMouseOut}>new text</p>'
}
function handleMouseOver(e) {
colour = 'green';
}
function handleMouseOut(e) {
colour = 'red';
}
</script>
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill={colour}>
</svg>
<div><p on:mouseover={handleMouseOver} on:mouseout={handleMouseOut}>old text</p></div>
<button on:click={refresh}>Click</button>
<div id="new-text"></div>
</code></pre>
<p>What can I do?</p>
| [
{
"answer_id": 74237910,
"author": "H.B.",
"author_id": 546730,
"author_profile": "https://Stackoverflow.com/users/546730",
"pm_score": 0,
"selected": false,
"text": "addEventListener"
},
{
"answer_id": 74237998,
"author": "Zachiah",
"author_id": 10892722,
"author_pro... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237861",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3070181/"
] |
74,237,904 | <p>I want to count the number of occurrences that a specific factor level occurs across multiple factor varaibles per row.</p>
<p>Simplified, I want to know how many times each factor level is chosen across specific variables per row (memberID).</p>
<p>Example data:</p>
<pre><code>results=data.frame(MemID=c('A','B','C','D','E','F','G','H'),
value_a = c(1,2,1,4,5,1,4,0),
value_b = c(1,5,2,3,4,1,0,3),
value_c = c(3,5,2,1,1,1,2,1)
)
</code></pre>
<p>In this example, I want to know the frequency of each factor level for value_a and value_b for each MemID. How many times does A respond 1? How many times does A respond 2? Etc...for each level and for each MemID but only for value_a and value_b.</p>
<p>I would like the output to look something like this:</p>
<pre><code>counts_by_level = data.frame(MemID=c('A','B','C','D','E','F','G','H'),
count_1 = c(2, 0, 1, 0, 0, 2, 0, 0),
count_2 = c(0, 1, 1, 0, 0, 0, 0, 0),
count_3 = c(0, 0, 0, 1, 0, 0, 0, 1),
count_4 = c(0, 0, 0, 1, 1, 0, 1, 0),
count_5 = c(0, 1, 0, 0, 1, 0, 0, 0))
</code></pre>
<p>I have been trying to use add_count or add_tally as well as table and searching other ways to answer this question. However, I am struggling to identify specific factor levels across multiple variables and then output new columns for the counts of those levels for each row.</p>
| [
{
"answer_id": 74238054,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 2,
"selected": false,
"text": "library(tidyverse)\n\nresults |>\n select(-value_c) |>\n pivot_longer(cols = starts_with(\"value\"), \n ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14769283/"
] |
74,237,949 | <p>I have a two part question</p>
<p>We have a PostgreSQL table with a jsonb column. The values in jsonb are valid jsons, but they are such that for some rows a node would come in as an array whereas for others it will come as an object.</p>
<p>for example, the json we receive could either be like this ( <em>node4</em> I just an object )</p>
<pre><code>"node1": {
"node2": {
"node3": {
"node4": {
"attr1": "7d181b05-9c9b-4759-9368-aa7a38b0dc69",
"attr2": "S1",
"UserID": "WebServices",
"attr3": "S&P 500*",
"attr4": "EI",
"attr5": "0"
}
}
}
}
</code></pre>
<p>Or like this ( <em>node4</em> is an array )</p>
<pre><code>"node1": {
"node2": {
"node3": {
"node4": [
{
"attr1": "7d181b05-9c9b-4759-9368-aa7a38b0dc69",
"attr2": "S1",
"UserID": "WebServices",
"attr3": "S&P 500*",
"attr4": "EI",
"attr5": "0"
},
{
"attr1": "7d181b05-9c9b-4759-9368-aa7a38b0dc69",
"attr2": "S1",
"UserID": "WebServices",
"attr3": "S&P 500*",
"attr4": "EI",
"attr5": "0"
}
]
}
}
}
</code></pre>
<p>And I have to write a jsonpath query to extract, for example, attr1, for each PostgreSQL row containing this json. I would like to have just one jsonpath query that would always work irrespective of whether the node is object or array. So, I want to use a path like below, assuming, if it is an array, it will return the value for all indices in that array.</p>
<pre><code>jsonb_path_query(payload, '$.node1.node2.node3.node4[*].attr1')#>> '{}' AS "ATTR1"
</code></pre>
<p>I would like to avoid checking whether the type in array or object and then run a separate query for each and do a union.</p>
<p>Is it possible?</p>
<p>A sub-question related to above - Since I needed the output as text without the quotes, and somewhere I saw to use <code>#>> '{}'</code> - so I tried that and it is working, but can someone explain, how that works?</p>
<p>The second part of the question is - the incoming json can have multiple sets of nested arrays and the json and the number of nodes is huge. So other part I would like to do is flatten the json into multiple rows. The examples I found were one has to identify each level and either use cross join or unnest. What I was hoping is there is a way to flatten a node that is an array, including all of the parent information, without knowing which, if any, if its parents are arrays or simple object. Is this possible as well?</p>
<p><strong>Update</strong></p>
<p>I tried to look at the documentation and tried to understand the <code>#>> '{}'</code> construct, and then I came to realise that '{}' is the right hand operand for the #>> operator which takes a path and in my case the path is the current attribute value hence {}. Looking at examples that had non-empty single attribute path helped me realise that.</p>
<p>Thank you</p>
| [
{
"answer_id": 74238054,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 2,
"selected": false,
"text": "library(tidyverse)\n\nresults |>\n select(-value_c) |>\n pivot_longer(cols = starts_with(\"value\"), \n ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/913749/"
] |
74,237,965 | <p>**Here is the code I'm trying to execute to encode the values of the first column of my data set using dummy values
**</p>
<pre><code>
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('Data.csv')
# divide dataset to dependent variable(features) and independent variable(output)
X = dataset.iloc[: , :-1].values
y = dataset.iloc[: ,3].values
# taking care of missing data
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
# apply the simpleImputer on the x from column[age to salary]
imputer = imputer.fit(X[: , 1:3 ])
# replace the missing data by the processed data
X[: , 1:3 ] = imputer.transform(X[: , 1:3 ])
# Encoding categorical data [country]
from sklearn.preprocessing import LabelEncoder , OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[: ,0])
# creates a binary column for each category
onehotencoder_X = OneHotEncoder(categories=['France','Germany','Spain'])
X_1 = onehotencoder_X.fit_transform(X[: ,0].reshape(-1,1)).toarray()
X = np.concatenate([X_1,X[: , 1:]],axis = 1)
</code></pre>
<pre><code> the data that i work on
</code></pre>
<p><a href="https://i.stack.imgur.com/jH5U8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jH5U8.png" alt="the data that i work on " /></a></p>
<pre><code> i'm getting an error
</code></pre>
<p><a href="https://i.stack.imgur.com/8reuu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8reuu.png" alt="i'm getting an error" /></a></p>
<p>Can anyone help me fix this?</p>
<p>Can anyone help me fix this?</p>
| [
{
"answer_id": 74238054,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 2,
"selected": false,
"text": "library(tidyverse)\n\nresults |>\n select(-value_c) |>\n pivot_longer(cols = starts_with(\"value\"), \n ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359777/"
] |
74,237,967 | <p>I have the following list:</p>
<pre><code>my_list = [ '[2,2]', '[0,3]' ]
</code></pre>
<p>I want to convert it into</p>
<pre><code>my_list = [ [2,2], [0,3] ]
</code></pre>
<p>Is there any easy way to do this in Python?</p>
| [
{
"answer_id": 74238054,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 2,
"selected": false,
"text": "library(tidyverse)\n\nresults |>\n select(-value_c) |>\n pivot_longer(cols = starts_with(\"value\"), \n ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5565575/"
] |
74,237,985 | <p>I am learning closure and have basic doubt.</p>
<pre><code>function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
</code></pre>
<p>Here when we are returning function it has closure with outer scope. so it has a closure with count.</p>
<pre><code>var x = 1;
function func() {
console.log(x); // does func has closure with x ??
}
func();
</code></pre>
<p>So my question is , only nested function makes closure ??
or top level func has also closure with x ??</p>
| [
{
"answer_id": 74238201,
"author": "bloodyKnuckles",
"author_id": 2743458,
"author_profile": "https://Stackoverflow.com/users/2743458",
"pm_score": -1,
"selected": false,
"text": "window"
},
{
"answer_id": 74238313,
"author": "Ben Aston",
"author_id": 38522,
"author_p... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4122326/"
] |
74,237,994 | <p>I would like to create an array and access it in the following way for read and write slice operations (i.e. more than one element at once):</p>
<ul>
<li>If the indices are within range access them as usual</li>
<li>If the second index is smaller than the first index, access the data as follows:
<code>First .. A'Last & A'First .. (First + 5)</code> (turns out this doesn't work as-is due to <em>concatenation result upper bound out of range</em>)</li>
</ul>
<p>I have come up with the following example to demonstrate the issue:</p>
<pre><code>with Ada.Text_IO;
use Ada.Text_IO;
procedure Test_Modular is
type Idx is mod 10;
type My_Array is array (Idx range <>) of Integer;
A: My_Array(Idx) := (
0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
6 => 6, 7 => 7, 8 => 8, 9 => 9
);
First: constant Idx := 7;
S: constant My_Array := A(First .. First + 5);
begin
for I in S'range loop
Put_Line(Idx'Image(I) & " --> " & Integer'Image(S(I)));
end loop;
end Test_Modular;
</code></pre>
<p>As in the example, the <code>5</code> is static, the compiler warns me as follows:</p>
<pre><code>$ gnatmake -o test_modular test_modular.adb
x86_64-linux-gnu-gcc-10 -c test_modular.adb
test_modular.adb:18:19: warning: loop range is null, loop will not execute
x86_64-linux-gnu-gnatbind-10 -x test_modular.ali
x86_64-linux-gnu-gnatlink-10 test_modular.ali -o test_modular
</code></pre>
<p>When running the program, I observe the following:</p>
<pre><code>$ ./test_modular
</code></pre>
<p>i.e. no output as predicted by the compiler warning.</p>
<p>Now I wonder: <strong>Is there a way to write the slice like <code>A(First .. First + 5)</code> and make it “wrap around” such that the data accessed will be the same as in this modified example program except without having to distinguish the two cases in the code explicitly?</strong></p>
<pre><code>with Ada.Text_IO;
use Ada.Text_IO;
procedure Test_Modular_2 is
type Idx is mod 10;
type My_Array is array (Idx range <>) of Integer;
A: My_Array(Idx) := (
0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
6 => 6, 7 => 7, 8 => 8, 9 => 9
);
First: constant Idx := 7;
S1: constant My_Array := A(First .. A'Last);
S2: constant My_Array := A(A'First .. (First + 5));
begin
for I in S1'range loop
Put_Line(Idx'Image(I) & " --> " & Integer'Image(S1(I)));
end loop;
for I in S2'range loop
Put_Line(Idx'Image(I) & " --> " & Integer'Image(S2(I)));
end loop;
end Test_Modular_2;
</code></pre>
| [
{
"answer_id": 74238686,
"author": "Jim Rogers",
"author_id": 6854407,
"author_profile": "https://Stackoverflow.com/users/6854407",
"pm_score": 3,
"selected": true,
"text": "with Ada.Text_IO; use Ada.Text_IO;\n\nprocedure Main is\n type Idx is mod 10;\n type My_Array is array (Idx ra... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74237994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11959417/"
] |
74,238,008 | <p>where Sparrow and bird both are different classes and Sparrow class is an extended class of Bird class.</p>
<p>I just wanna see if i create an instance of Class Sparrow does it can implement the property of the Bird object.</p>
| [
{
"answer_id": 74238053,
"author": "Louis Wasserman",
"author_id": 869736,
"author_profile": "https://Stackoverflow.com/users/869736",
"pm_score": 1,
"selected": false,
"text": "throw new ClassCastException();\n"
}
] | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17599809/"
] |
74,238,014 | <p>i am preparing a function to user to guess a random number generated by computer.</p>
<p>The output should be the number of guesses, and if the guess is correct, lower or higher than the generated number.</p>
<p>In the end the, the user should be asked if he wants to play again or not.</p>
<p>Everything is working excepts this last part, because i can't break the loop to stop the game.</p>
<p>Here's my code:</p>
<pre><code>#random number guessing game
import random
def generate_random (min,max):
return random.randint (min,max)
#generate_random (1,100)
star_range=1
end_range=100
#targetnumber=generate_random(start_range,end_range)
#print (targetnumber)
def main():
targetnumber=generate_random(star_range,end_range)
number_of_guesses =0 #guarda o numero de tentativas do jogador
print ("Guess a number between 0 e 100.\n")
while True:
number_of_guesses +=1
guess = int(input("Guess #" + str(number_of_guesses) + ": "))
if guess > targetnumber:
print("\t Too High, try again.")
elif guess < targetnumber:
print ("\t Too low, try aain")
else:
print ("\t Correct")
print ("\t Congratulations. you got it in",number_of_guesses,"guesses.")
break
playagain=input("\n whould you like to play again? (y/n): ").lower()
while playagain != "y" or playagain != "n":
print ("Please print y to continue or n to exit")
playagain=input("\n whould you like to play again? (y/n): ").lower()
if playagain == "y":
continue
else:
break
</code></pre>
<p>My final output is always this one:</p>
<p>whould you like to play again? (y/n): n
Please print y to continue or n to exit</p>
<p>whould you like to play again? (y/n):</p>
<p>Can you please help me, letting me know what i am doing wrong?</p>
<p>Thank you very much</p>
| [
{
"answer_id": 74238053,
"author": "Louis Wasserman",
"author_id": 869736,
"author_profile": "https://Stackoverflow.com/users/869736",
"pm_score": 1,
"selected": false,
"text": "throw new ClassCastException();\n"
}
] | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20333293/"
] |
74,238,062 | <p>I am trying to create a nested while loop which should be working in hours 02:20 - 21:50, butI can't figure out the boolean expression which would fulfill the condition.</p>
<pre><code>while True:
now = datetime.datetime.now()
print((now.hour >= 2 and now.minute >= 20), (now.hour <= 21 and now.minute <= 49))
while (now.hour >= 2 and now.minute >= 20) and (now.hour <= 21 and now.minute <= 49):
now = datetime.datetime.now()
</code></pre>
<p>This is my code, unfortunately it doesn't work.
For example if the current hour is 17:50 the nested while loop will stop working because <code>now.minute = 50</code> and is greater than <code>49</code>. This is what I've realised while testing it rn.
Perhaps the first part of the condition is also flawled in the same way.</p>
<p>How can I make the loop work between 02:20:00(a.m.) till 21:49:59(9:49:59 p.m.)?</p>
<p>Thank you for your help in advance :)</p>
| [
{
"answer_id": 74238123,
"author": "Rodrigo Guzman",
"author_id": 13315525,
"author_profile": "https://Stackoverflow.com/users/13315525",
"pm_score": 1,
"selected": false,
"text": "now = datetime.datetime.now()\nswitch = !(2 <= now.hour <= 21) : True ? (20 <= now.minute <= 49)\nwhile (2 ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19797660/"
] |
74,238,080 | <p>good day,
what is the best way to implement the below function in java:
mod11(x) which calculates x mod 11, we assume x is either an integer or a formula. For example, mod11(14) returns 3, and mod11(3*7-30) returns 2.
I tried the below but it didn't work:
`</p>
<pre><code>public static int PositiveMod(int value, int mod)
{
return ((value % mod + mod) % mod);
}
</code></pre>
<p>`</p>
<p>`</p>
<pre><code>public static double PositiveMod(double value, double mod)
{
return ((value % mod + mod) % mod);
}
</code></pre>
<p>`
for example, i expect ((-7+1)/20) mod 11 to give out 3 but instead it gave me 10.7
like below
i = ((-7+1)/20) mod 11 = -6/9 mod 11 = 5*5 mod 11 = 3</p>
| [
{
"answer_id": 74238186,
"author": "Level_Up",
"author_id": 6068297,
"author_profile": "https://Stackoverflow.com/users/6068297",
"pm_score": 2,
"selected": false,
"text": "public class MainClass2 {\n\n public static void main(String[] args) {\n System.out.println(\"Math mod:\"... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17509682/"
] |
74,238,081 | <p>TL;DR: Python; I have Parent, Child classes. I have an <em>instance</em> of Parent class, <code>parent</code>. Can I make a Child class instance whose <code>super()</code> is <code>parent</code>?</p>
<p>Somewhat specific use case (workaround available) is as follows: I'd like to make an instance of Logger class (from Python <code>logging</code> module), with <code>_log</code> method overloaded. Methods like <code>logger.info</code> or <code>logger.error</code> call this method with a <code>level</code> specified as either <code>INFO</code> or <code>ERROR</code> etc., I'd like to replace this one method, touch nothing else, and make it all work seamlessly.</p>
<p>Here's some things that don't work (well):</p>
<ul>
<li>I can't <em>just</em> inherit from <code>logging.Logger</code> instance and overload this one method and constructor, because <code>Logger</code> instances tend to be created via a factory method, <code>logging.getLogger(name)</code>. So I can't just overload the constructor of the wrapper like:</li>
</ul>
<pre><code>class WrappedLogger(logging.Logger):
def __init__(self, ...):
super().__init__(...)
def _log(self, ...):
</code></pre>
<p>and expect it to all work OK.</p>
<ul>
<li>I could make a wrapper class, which provides the methods I'd like to call on the resulting instance, like <code>.info</code> or <code>.error</code> - but then I have to manually come up with all the cases. It also doesn't work well when the <code>_log</code> method is buried a few calls down the stack - there is basically no way to guarantee that any use of the <em>wrapped</em> class will call my desired <code>_log</code> method</li>
<li>I can make a little kludge like so:</li>
</ul>
<pre class="lang-py prettyprint-override"><code>class WrappedLogger(logging.Logger):
def __init__(self, parent):
self._parent = parent
def _log(...): # overload
def __getattr__(self, method_name):
return getattr(self._parent, method_name)
</code></pre>
<p>now whenever I have an instance of this class, and call, say, <code>wrapped.info(...)</code>, it will retrieve the <em>parent</em> method of <code>info</code>, call it, which will then call <code>self._log</code> which in turn points to my wrapped instance. But this feels very ugly.</p>
<ul>
<li>Similarly, I could take a regular instance of <code>Logger</code> and manually swap out the method; this is maybe a bit less "clever", and less ugly than the above, but similarly underwhelming.</li>
</ul>
<p>This question has been asked a few times, but in slightly different contexts, where other solutions were proposed. Rather than looking for a workaround, I'm interested in whether there is a native way of constructing a child class instance with the parent <em>instance</em> specified.</p>
<p>Related questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/67943693/create-child-class-instances-from-parent-class-instance-and-call-parent-methods">Create child class instances from parent class instance, and call parent methods from child class instance</a> - here effectively a workaround is suggested</li>
<li><a href="https://stackoverflow.com/questions/24921258/python-construct-child-class-from-parent">Python construct child class from parent</a> - here the parent <em>can</em> be created in the child's constructor</li>
</ul>
| [
{
"answer_id": 74238346,
"author": "Wombatz",
"author_id": 4759726,
"author_profile": "https://Stackoverflow.com/users/4759726",
"pm_score": 1,
"selected": false,
"text": "getLogger"
},
{
"answer_id": 74239543,
"author": "Abhilash Kar",
"author_id": 20254308,
"author_... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2987878/"
] |
74,238,083 | <pre><code>a = 5
id(a)
</code></pre>
<p>As you know,output is;</p>
<pre><code>1936111069616
</code></pre>
<p>I know that this is a memory address reference of "a" variable linked between variable name and object heap and stack memory on ram in decimal format but i haven't found anything about the detailed definition of this address. If we wanted to write a user-defined function for this, how would we implement? I wonder the address structure and how we know unique format. What is the meaning of length of 13 numbers?</p>
<p>I searched this a lot. I haven't found exact definition for 64 bit system.</p>
| [
{
"answer_id": 74238470,
"author": "chepner",
"author_id": 1126841,
"author_profile": "https://Stackoverflow.com/users/1126841",
"pm_score": 1,
"selected": false,
"text": "id"
},
{
"answer_id": 74238777,
"author": "D.L",
"author_id": 7318120,
"author_profile": "https:... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19145738/"
] |
74,238,088 | <p>I am trying to get all of the GameObjects with the tag of <code>Player</code> but it comes up with the error <em>"Cannot implicitly convert type int to UnityEngine.GameObject[]"</em>. My code is:</p>
<pre><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class mymanager : MonoBehaviour
{
GameObject[] amount;
public GameObject winPanel;
void Start()
{
winPanel.SetActive(false);
}
// Update is called once per frame
void Update()
{
amount = GameObject.FindGameObjectsWithTag("Player").Length;
if(amount <= 1)
{
winPanel.SetActive(true);
}
else
{
winPanel.SetActive(false);
}
}
public void OnClickJoinLobby()
{
PhotonNetwork.LoadLevel("Lobby");
}
}
</code></pre>
<p>I wanted to count the amount of players and open a UI panel if there was a maximum of 1 player left.</p>
| [
{
"answer_id": 74238371,
"author": "Yugerten",
"author_id": 11228377,
"author_profile": "https://Stackoverflow.com/users/11228377",
"pm_score": 2,
"selected": false,
"text": "amount"
},
{
"answer_id": 74238375,
"author": "h4ri",
"author_id": 4819135,
"author_profile":... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19797009/"
] |
74,238,095 | <p>I would like to help someone solve their problem with installing a particular <code>mamba</code> environment: <a href="https://stackoverflow.com/questions/74234628/new-environment-force-torch-cpu-and-i-dont-know-why">New mamba environment force torch CPU and I don't know why</a></p>
<p>However, they use Windows, and I am on macOS.</p>
<p>How can I tell <code>mamba</code> to use <code>pytorch/win-64</code> and <code>conda-forge/win-64</code> channels instead of <code>osx-arm</code> subchannels?</p>
<p>I know I can specify channels using <code>-c</code> but how do I specify the system subdirectory?</p>
| [
{
"answer_id": 74238134,
"author": "Cornelius Roemer",
"author_id": 7483211,
"author_profile": "https://Stackoverflow.com/users/7483211",
"pm_score": 0,
"selected": false,
"text": "-c conda-forge/win-64"
},
{
"answer_id": 74273014,
"author": "merv",
"author_id": 570918,
... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7483211/"
] |
74,238,114 | <p>I have a empty graph and need to plot the graph based on the convex hull with inner verticies.</p>
<p>My attemp is:</p>
<pre><code>library(igraph)
set.seed(45)
n = 10
g <- graph.empty(n)
xy <- cbind(runif(n), runif(n))
vp <- convex_hull(xy)$resverts + 1
#[1] 8 10 7 2 1
## convert node_list to edge_list
plot(g, layout=xy)
</code></pre>
<p>Expected result in right figure.</p>
<p><a href="https://i.stack.imgur.com/6DkNS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6DkNS.png" alt="enter image description here" /></a></p>
<p>Question. How to convert a node list to an edge list in igraph??</p>
| [
{
"answer_id": 74238134,
"author": "Cornelius Roemer",
"author_id": 7483211,
"author_profile": "https://Stackoverflow.com/users/7483211",
"pm_score": 0,
"selected": false,
"text": "-c conda-forge/win-64"
},
{
"answer_id": 74273014,
"author": "merv",
"author_id": 570918,
... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5692005/"
] |
74,238,137 | <p>I have this dataset (104x182) and for each column, I want to find the row index for the max value within that column.</p>
<p>This is what I have so far:</p>
<pre><code>library(tibble)
p=1:182
DF <- tibble(i=as.numeric(), max=as.numeric())
for (i in p){
max <- which.max(Z0[, p])
DF <- DF %>%
add_row(i=i, max=max)
}
DF %>%
filter(max != 1) %>%
distinct(max, .keep_all=TRUE)
</code></pre>
<p>When I try run the for loop, I get the following error:</p>
<pre><code>Error in which.max(Z0[, p]) :
'list' object cannot be coerced to type 'double'
</code></pre>
<p>How can I change the above code so that it works.</p>
| [
{
"answer_id": 74238134,
"author": "Cornelius Roemer",
"author_id": 7483211,
"author_profile": "https://Stackoverflow.com/users/7483211",
"pm_score": 0,
"selected": false,
"text": "-c conda-forge/win-64"
},
{
"answer_id": 74273014,
"author": "merv",
"author_id": 570918,
... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15198024/"
] |
74,238,141 | <p>react-dom.development.js:14887 Uncaught Error: Objects are not valid as a React child (found: object with keys {name, img, author, price}). If you meant to render a collection of children, use an array instead.</p>
<pre><code>import React from "react";
const books = [
{
name: "The Psychology of Money",
img: "https://m.media-amazon.com/images/I/71g2ednj0JL._AC_UY218_.jpg",
author: "morgan hussel",
price: "239",
},
{
name: "The Psychology of Money",
img: "https://m.media-amazon.com/images/I/71g2ednj0JL._AC_UY218_.jpg",
author: "morgan hussel",
price: "239",
},
];
function BookList() {
return <div>
<h1>{books.map((book) => {return book})}</h1>
</div>;
};
export default BookList;
</code></pre>
| [
{
"answer_id": 74238134,
"author": "Cornelius Roemer",
"author_id": 7483211,
"author_profile": "https://Stackoverflow.com/users/7483211",
"pm_score": 0,
"selected": false,
"text": "-c conda-forge/win-64"
},
{
"answer_id": 74273014,
"author": "merv",
"author_id": 570918,
... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20359953/"
] |
74,238,179 | <p>I'm trying to learn how to compose monads using functions like <code>bind</code> or <code>map</code>, and so far my code works but it's really verbose. Here's a tiny script I just wrote to illustrate what I mean, it casts a <code>string</code> into an <code>int option</code> and double the number if there is one.</p>
<pre class="lang-ml prettyprint-override"><code>open Base
open Stdio
let is_number str = String.for_all ~f:(Char.is_digit) str
let str_to_num_opt (str: string) : int option =
if is_number str then Some (Int.of_string str)
else None
let double n = n * 2
let () =
let maybe_num = Option.map (str_to_num_opt "e123") ~f:double in
match maybe_num with
| Some n -> printf "Number found in string : %d\n" n
| None -> printf "No number found in string.\n"
</code></pre>
<p>The definition of <code>maybe_num</code> is quite verbose, and it's going to be exponentially worse the longer the composition chain is, so I tried using the <code>>>|</code> operator, but due to it being attached to the <code>Option</code> module, I can't directly use it as an infix function, instead calling it as <code>Option.(>>|)</code> (which is basically the same as using <code>Option.map</code> but I lose the named argument).</p>
<p>What I did was add <code>open Option</code> at the top of the file, then rewrite my <code>()</code> function as so :</p>
<pre class="lang-ml prettyprint-override"><code>let () =
let maybe_num =
str_to_num_opt "123"
>>| double
in match maybe_num with
| Some n -> printf "Number found in string : %d\n" n
| None -> printf "No number found in string.\n"
</code></pre>
<p>The code is now a lot cleaner, but I can only use this trick for one module per file, since if I add <code>open List</code> (for instance) after <code>open Option</code> at the top of the file, it's going to shadow the definition of <code>>>|</code> and the operator will only work on lists, thus breaking my code.</p>
<p>What I was hopping for, was the two definitions of <code>>>|</code> coexisting together at the same time, and have the compiler / interpreter choose the one with the correct signature when running the code (similar to a <code>trait</code> being implemented for different types in Rust), but I couldn't make it work. Is it even possible ?</p>
| [
{
"answer_id": 74241426,
"author": "Chris Vine",
"author_id": 2615801,
"author_profile": "https://Stackoverflow.com/users/2615801",
"pm_score": 2,
"selected": true,
"text": "let"
},
{
"answer_id": 74243266,
"author": "jthulhu",
"author_id": 5956261,
"author_profile": ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18121016/"
] |
74,238,196 | <p>I'm new with React and I want to move an object data from one child component to another, this is my code:</p>
<pre><code>import React from "react";
import SiteRow from "./SiteRow";
import AlertList from "../Alerts/AlertList";
import data from "../../static/fixtures/data.json";
const SiteList = () => {
return (
<div className="row">
<div className="col-8">
<table className="table table-bordered">
<thead>
<tr>
<th scope="col">Site</th>
<th scope="col">Alerts</th>
<th scope="col">Savings</th>
<th scope="col">Uptime</th>
<th scope="col">Power</th>
</tr>
</thead>
<SiteRow sites={data.sites} />
</table>
</div>
<AlertList />
</div>
);
};
export default SiteList;
</code></pre>
<p>When I click in a row in the <code>SiteRow</code> component must show data in a child component <code>AlertRow</code> from <code>AlertList</code>, I've been looking for this but I'm stuck, any idea?</p>
<p>Thanks.</p>
<p>I was reading about React Context, but I don't got the idea for sharing the data.</p>
| [
{
"answer_id": 74238381,
"author": "acdcjunior",
"author_id": 1850609,
"author_profile": "https://Stackoverflow.com/users/1850609",
"pm_score": 0,
"selected": false,
"text": "SiteList"
}
] | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6321343/"
] |
74,238,197 | <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>.fm-bubbles {
display: flex;
flex-wrap: wrap;
width: 100%;
height: 100px;
}
.fm-bubble {
flex: 1 1 10%;
height: max-content;
border: 1px solid royalblue;
border-radius: 5px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code> <div class="fm-content">
<div class="fm-bubbles">
<p class="fm-bubble">Lorem, ipsum.</p>
<p class="fm-bubble">lorem</p>
<p class="fm-bubble">adsadad</p>
<p class="fm-bubble">sss</p>
<p class="fm-bubble">asdasda asdasda</p>
<p class="fm-bubble">asss</p>
<p class="fm-bubble">sss</p>
<p class="fm-bubble">asdas asd</p>
<p class="fm-bubble">adadaddd</p>
<p class="fm-bubble">adadasd</p>
<p class="fm-bubble">addd</p>
<p class="fm-bubble">adadd</p>
<p class="fm-bubble">ss</p>
</div></code></pre>
</div>
</div>
</p>
<p>At the moment my boxes are only touching each other horizontally, but i also want them to be touching vertically. I have tried to search for information about this, but when I do find something that works, it gives them more height than they need.</p>
| [
{
"answer_id": 74238287,
"author": "disinfor",
"author_id": 1172189,
"author_profile": "https://Stackoverflow.com/users/1172189",
"pm_score": 1,
"selected": false,
"text": "p"
},
{
"answer_id": 74238498,
"author": "Azmeer",
"author_id": 20161645,
"author_profile": "ht... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16306716/"
] |
74,238,232 | <p>I'm upgrading Cypress from 10.2.0 to 10.11.0 and I'm encountering some behaviour I'm trying to understand.</p>
<p>In the second <code>.then</code>, the <code>response</code> is undefined. This had previously worked on 10.2.0.</p>
<pre><code>public makeRequest(params) {
return cy.request({
...params
})
.then((response) => {
// do something with response
});
}
this.makeRequest(params)
.then((response) => {
// response is undefined
});
</code></pre>
<p>Can anyone point me in the right direction, I have checked the changelogs for every version since 10.3.0 and cannot find anything to explain this behaviour.</p>
<p>Thanks!</p>
| [
{
"answer_id": 74238934,
"author": "kenwilde",
"author_id": 14625822,
"author_profile": "https://Stackoverflow.com/users/14625822",
"pm_score": 1,
"selected": false,
"text": "public makeRequest(params) {\n return cy.request({\n ...params\n })\n .then((response) => {\n // ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14625822/"
] |
74,238,254 | <p>I have used <code>lodash</code> to create chunks of arrays (batches).</p>
<pre><code>let values = {
'key1' : [lotsOfValues1],
'key2' : [lotsOfValues2]
};
let keys = ['key1', 'key2'];
let arrObj = [];
keys.forEach((key) => {
arrObj.push([key] : lodash.chunk(values[key], 20)) // it will break lotsOfValues arrays into chunks of size 20
});
/* Now arrObj = [
{
key1: [[someVals1], [someVals2], [someVals3]],
},
{
key2: [[someVals4], [someVals5]],
},
];
*/
</code></pre>
<p>Is there a way we can efficiently change an array of Objects -</p>
<pre><code>const arrObj = [
{
key1: [[someVals1], [someVals2], [someVals3]],
},
{
key2: [[someVals4], [someVals5]],
},
];
</code></pre>
<p>into an array of Objects with instead of array of object as value just individual array elements. Something like this -</p>
<pre><code>const arrObjTransformed = [
{ key1: [someVals1] },
{ key1: [someVals2] },
{ key1: [someVals3] },
{ key2: [someVals4] },
{ key2: [someVals5] },
];
</code></pre>
<p>any help would be highly appreciated.</p>
<p>I tried looping through arrObj and for each element I had another loop which will form a new object with each value and keep updating the final output array.</p>
<p>But I somehow feel there can be a cleaner way to achieve it.</p>
| [
{
"answer_id": 74238934,
"author": "kenwilde",
"author_id": 14625822,
"author_profile": "https://Stackoverflow.com/users/14625822",
"pm_score": 1,
"selected": false,
"text": "public makeRequest(params) {\n return cy.request({\n ...params\n })\n .then((response) => {\n // ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12129049/"
] |
74,238,257 | <p>Is there a way to tie or bind the <code>Navigator.pop()</code> method to a specific route?</p>
<p>In my case, <code>Navigator.pop()</code> is called from an async function in a widget which takes some time to complete, such as:</p>
<pre><code>ElevatedButton(
onPressed: () async {
await doSomethingAsync();
if (mounted) {
Navigator.pop(context);
}
},
child: const Text("Do something async then pop")),
)
</code></pre>
<p>While that function is ongoing, it could happen however that:</p>
<ul>
<li>The route could be popped ahead of time by the user pressing the Android back button (similarly to <a href="https://stackoverflow.com/questions/72620608/how-to-prevent-a-navigator-pop-in-an-async-function-from-popping-a-route-which">a previous question I made</a>)</li>
<li>Another route could be pushed on top of the existing one by the user performing another action</li>
</ul>
<p>In both cases, I'd like the navigator to "tie" to the specific route onto which the widget is displayed, and only pop it if it isn't yet.</p>
<p>What's the best way to do that? If that's not possible (or overly complicated) I am also open to solutions using the go_router package, for which the same question applies.</p>
| [
{
"answer_id": 74238934,
"author": "kenwilde",
"author_id": 14625822,
"author_profile": "https://Stackoverflow.com/users/14625822",
"pm_score": 1,
"selected": false,
"text": "public makeRequest(params) {\n return cy.request({\n ...params\n })\n .then((response) => {\n // ... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8965508/"
] |
74,238,258 | <p>I have these two methods where I want to remove specific elements.</p>
<p>The first one should return the following sequence of numbers: 4 5 7 8 10 11 13 14 ... The sequence contains no terms divisible by three. The sequence always starts at "4". But in my case it always just prints the paramter from the method.</p>
<p>The second one should delete all spaces from the passed string s1 and outputs the result. (“Hello world, how are you” becomes “Helloworld,howareyou?”). But it in my case it doesn't delete the blanks.</p>
<pre><code>static void printFolgenOhne3(int anz) {
List<Integer> item = new ArrayList<>();
List<Integer> remove;
item.add(anz);
remove = item.stream()
.filter(i -> anz % 3 == 0)
.collect(Collectors.toList());
item.removeAll(remove);
item.forEach(System.out::println);
}
static void deleteBlanks(String s1) {
List<String> elements = new ArrayList<>();
elements.add(s1);
List<String> deleted = elements
.stream()
.filter(x -> !x.isBlank())
.collect(Collectors.toList());
System.out.println(deleted);
}
</code></pre>
| [
{
"answer_id": 74238467,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 3,
"selected": true,
"text": "List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\nlist.removeIf(element -> element % 3... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19971974/"
] |
74,238,298 | <p>I was working on my flutter app and everything worked fine for me but now when I'm deleting notes by swipe after reload they come back and I can't do anything about it.</p>
<pre><code>import 'dart:convert';
import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Home extends StatefulWidget {
const Home ({key}): super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
final myController = TextEditingController();
bool submit = false;
Color mainColor = Color(0xFFEEEFF5);
Color secColor = Color(0xFF3A3A3A);
Color tdBlue = Color(0xFF5F52EE);
String temp = "";
List<String> todoList = [];
@override
void initState() {
super.initState();
myController.addListener(() {
setState(() {
submit = myController.text.isNotEmpty;
});
});
omLoadData();
}
submitData() async {
setState(() {
todoList.add(temp);
clearText();
});
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setStringList('todo_list', todoList);
}
omLoadData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final data = prefs.getStringList("todo_list");
todoList.addAll(data!);
}
@override
void dispose() {
// Clean up the controller when the widget is disposed.
myController.dispose();
super.dispose();
}
void clearText() {
myController.clear();
}
@override
Widget build(BuildContext context){
return Scaffold(
backgroundColor: mainColor,
appBar: AppBar(
elevation: 0.0,
backgroundColor: secColor,
title: Text ('ToDo - List', style: TextStyle(fontSize: 26.5, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),),
),
body: Column(
children: [
Container(
margin: EdgeInsets.only(
top: 15.0,
left: 13.0,
right: 8.0,
),
child: Row(
children: [
Expanded(
child: TextField(
onChanged: (String value) {
temp = value;
},
controller: myController,
decoration:
InputDecoration(
prefixIcon: Icon(Icons.notes, color: Colors.orangeAccent,),
labelText: 'Замітка',
hintText: 'Введіть замітку',
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(),
contentPadding: EdgeInsets.all(10.0),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30.0),),
),
),
),
),
SizedBox(
width: 10.0,
),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: tdBlue),
onPressed:
submit ? () => submitData() : null,
child:
Text('+', style: TextStyle(fontSize: 35),),
),
], // Закривається 2-ий чілдрен
), //Row 1-ий
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
top: 5.0,
),
child: ListView.builder(
itemCount: todoList.length,
itemBuilder: (BuildContext context, int index){
return Dismissible(
direction: DismissDirection.endToStart,
background: const Card(color: Colors.red,
child: Icon(Icons.delete_sweep,size: 30, color: Colors.white,)
),
key: Key(todoList[index]),
onDismissed: (direction){
setState(() async {
todoList.removeAt(index);
});
},
child: Card(
margin: EdgeInsets.only(
top: 8.5,
left: 25.0,
right: 25.0,
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25.0)),
elevation: 0.0,
child:
ListTile(
title: Text(todoList[index],
),),
),
);
},
),
)
),
], // Закривається 1-ий чілдрен
),
);
}
}
</code></pre>
<p>When deleting a list item with a swipe, it is deleted until I do a Hot restart. When I do a Hot restart the item reappears.Maybe I have a bug in the code. Help me, please.</p>
| [
{
"answer_id": 74238467,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 3,
"selected": true,
"text": "List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\nlist.removeIf(element -> element % 3... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20350574/"
] |
74,238,301 | <p>I want to check if a log file has any instance where two or more consecutive lines contains the same text using bash. The text will be specified. The timestamp and any other text after the third field are to be ignored in the comparison.</p>
<p>i.e grep... "error" /tmp/file.txt</p>
<p>this file will match:</p>
<pre><code>2020-01-01 05:05 text1
2020-01-01 05:07 error
2020-01-01 05:15 error
2020-01-01 05:25 error
2020-01-01 05:45 text2
</code></pre>
<p>this won't</p>
<pre><code>2020-01-01 05:05 text1
2020-01-01 05:15 error
2020-01-01 05:25 text2
2020-01-01 05:45 error
2020-01-01 05:05 text3
</code></pre>
<p>Any ideas using grep, sed or awk? Ideally I'd like to have an exit value 0 for match and 1 for not match.</p>
| [
{
"answer_id": 74238467,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 3,
"selected": true,
"text": "List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\nlist.removeIf(element -> element % 3... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4097890/"
] |
74,238,314 | <p>I am trying to update my .bash_profile but the changes are not being reflected.</p>
<p>When I type ~/.bash_profile in command line, i get the error "zsh: No such file or directory: Users/My.Name/.bash_profile".</p>
<p>Why can't terminal find it? How do I help it locate the file? When I go to Users/My.Name directory and show hidden files, the .bash_profile is there.</p>
| [
{
"answer_id": 74238467,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 3,
"selected": true,
"text": "List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));\nlist.removeIf(element -> element % 3... | 2022/10/28 | [
"https://Stackoverflow.com/questions/74238314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6710438/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.