qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,319,146 | <p>I'm trying to do a local override of a function so that I can discard the first value returned, and only one value (normally returned as its second value) will be returned by the function.</p>
<pre><code>local r.functionName()
discardVar,keepVar = r.functionName()
return keepVar
end
</code></pre>
<p>However, when I run this script, I see an error:</p>
<p><code>'(' expected near '.'</code></p>
<p>I'm not sure how to make this work. I've only ever written functions without a "." in the function name. I'm not sure if its the right term for it, but I guess that, in this case, "r" would be the library (or maybe 'environment'?) containing the function that I want to locally override.</p>
<p>Basically, the desired outcome would be the function only returns one value instead of two; only the value normally returned as its <em>second</em> return value.</p>
<p>The closest I've gotten to succeeding with this is a legitimate stack overflow, so this seems like the right place to ask about it. :)</p>
<pre><code>r.functionName()
discardVar,keepVar = r.functionName()
return keepVar
end
</code></pre>
| [
{
"answer_id": 74319192,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 3,
"selected": false,
"text": "local f = r.functionName\n"
},
{
"answer_id": 74322920,
"author": "koyaanisqatsi",
"author_id": 11740758,
"author_profile": "https://Stackoverflow.com/users/11740758",
"pm_score": 2,
"selected": true,
"text": "> -- I need to construct r with an example function\n> r = {}\n> r.functionName = string.gsub\n> -- You start here ;-)\n> replaced = r\n> r = {}\n> -- Fill r with replaced key/value pairs one by one\n> -- So new references will be created\n> -- Means: Changing r not changing replaced ( r ~= replaced )\n> for k, v in pairs(replaced) do r[k] = v end\n> -- Now replace r.functionName() with a function that calls replaced.functionName()\n> r.functionName = function(...)\n>> local f, s = replaced.functionName(...)\n>> return(s) -- Syntax makes sure that only s will be returned\n>> end\n> r.functionName(_VERSION, '.', '')\n7\n> #{r.functionName(_VERSION, '.', '')} -- Number of return values\n1\n> -- r can than be replaced again (restored/cleanup)\n> r = replaced -- Descruct of above r.functionName\n> replaced = nil -- Destruct of replaced\n> collectgarbage('collect') -- Freeing unused memory\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7051766/"
] |
74,319,174 | <p>I'm having a little problem trying to create the database connection url.
I am using the AWS Secrets Manager service and with the returned data I create my connection URL.
The problem is that when I want to create the URL it gives me an error.
If someone can help me I would really appreciate it</p>
<p>I created a module with functions to create the URL but, the return is undefined. What seems to happen is that the execution does not wait for the promise to resolve. because the Secrets if I am receiving them but later</p>
<pre><code>import { Injectable } from '@nestjs/common'
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
@Injectable({})
export class SecretsService{
public final: string
async getSecret() {
const secret_name = 'Secret'
let lastURL
const client = new SecretsManagerClient({
region: 'us-east-1',
})
client.send(
new GetSecretValueCommand({
SecretId: secret_name,
VersionStage: 'AWSCURRENT'// VersionStage defaults to AWSCURRENT if unspecified
})
).then((response)=>{
const data = response.SecretString
const secret=JSON.parse(data)
lastURL= `${secret.engine}://${secret.username}:${secret.password}@${secret.host}:${secret.port}/dbname?schema=public`
this.final=lastURL
console.log(this.final)
}).catch((error)=>{
console.log(error)
})
}
}
</code></pre>
<pre><code>import { Injectable } from '@nestjs/common'
import { PrismaClient } from '@prisma/client'
import { SecretsService } from 'src/secrets/secrets.service'
const asd = new SecretsService()
asd.getSecret()
const urlFinal=asd.final
@Injectable()
export class PrismaService extends PrismaClient {
constructor(){
super({
datasources: {
db:{
url: asd.final
}
}
})
}
}
</code></pre>
| [
{
"answer_id": 74319192,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 3,
"selected": false,
"text": "local f = r.functionName\n"
},
{
"answer_id": 74322920,
"author": "koyaanisqatsi",
"author_id": 11740758,
"author_profile": "https://Stackoverflow.com/users/11740758",
"pm_score": 2,
"selected": true,
"text": "> -- I need to construct r with an example function\n> r = {}\n> r.functionName = string.gsub\n> -- You start here ;-)\n> replaced = r\n> r = {}\n> -- Fill r with replaced key/value pairs one by one\n> -- So new references will be created\n> -- Means: Changing r not changing replaced ( r ~= replaced )\n> for k, v in pairs(replaced) do r[k] = v end\n> -- Now replace r.functionName() with a function that calls replaced.functionName()\n> r.functionName = function(...)\n>> local f, s = replaced.functionName(...)\n>> return(s) -- Syntax makes sure that only s will be returned\n>> end\n> r.functionName(_VERSION, '.', '')\n7\n> #{r.functionName(_VERSION, '.', '')} -- Number of return values\n1\n> -- r can than be replaced again (restored/cleanup)\n> r = replaced -- Descruct of above r.functionName\n> replaced = nil -- Destruct of replaced\n> collectgarbage('collect') -- Freeing unused memory\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20349159/"
] |
74,319,177 | <p>I have object array now i need to convert it single array without key.</p>
<p>I need array like this:-</p>
<pre><code>["test","test"]
</code></pre>
<p>I also need to remove that value if I got <code>undefined</code> instead of other value.</p>
<p>My Code:-</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const list = [
{
"type": "undefined"
},
{
"type": "test"
},
{
"type": "test"
}
]
var findAndValue = list.map(Object.values);
console.log(findAndValue);</code></pre>
</div>
</div>
</p>
<p>Thanks for your efforts!</p>
| [
{
"answer_id": 74319192,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 3,
"selected": false,
"text": "local f = r.functionName\n"
},
{
"answer_id": 74322920,
"author": "koyaanisqatsi",
"author_id": 11740758,
"author_profile": "https://Stackoverflow.com/users/11740758",
"pm_score": 2,
"selected": true,
"text": "> -- I need to construct r with an example function\n> r = {}\n> r.functionName = string.gsub\n> -- You start here ;-)\n> replaced = r\n> r = {}\n> -- Fill r with replaced key/value pairs one by one\n> -- So new references will be created\n> -- Means: Changing r not changing replaced ( r ~= replaced )\n> for k, v in pairs(replaced) do r[k] = v end\n> -- Now replace r.functionName() with a function that calls replaced.functionName()\n> r.functionName = function(...)\n>> local f, s = replaced.functionName(...)\n>> return(s) -- Syntax makes sure that only s will be returned\n>> end\n> r.functionName(_VERSION, '.', '')\n7\n> #{r.functionName(_VERSION, '.', '')} -- Number of return values\n1\n> -- r can than be replaced again (restored/cleanup)\n> r = replaced -- Descruct of above r.functionName\n> replaced = nil -- Destruct of replaced\n> collectgarbage('collect') -- Freeing unused memory\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7333403/"
] |
74,319,195 | <p>I'm new to pandas and need help manipulating data per row and not the whole column based on a condition.</p>
<p>I have a DF that contains these columns:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Repository</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>DMZ Linux</td>
<td>65 days</td>
</tr>
<tr>
<td>Linux</td>
<td>3 days</td>
</tr>
<tr>
<td>Windows</td>
<td>95 days</td>
</tr>
</tbody>
</table>
</div>
<p>Condition is:</p>
<ul>
<li><p>if 'DMZ' in Repository and age > 60 - true</p>
</li>
<li><p>if 'DMZ' in repo and age < 60 - false</p>
</li>
<li><p>if 'DMZ' not in repo and age > 90 true</p>
</li>
<li><p>if 'DMZ' not in repo and age < 90 - false</p>
</li>
</ul>
<p>I need it to have an additional column named Outstanding and return string 'True' or 'False' depending on condition above.</p>
<p>My only problems is depending on whatever index the for loop is on, it applies to every row / whole column instead of different values per row.</p>
<p>It should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Repository</th>
<th>Age</th>
<th>Outstanding</th>
</tr>
</thead>
<tbody>
<tr>
<td>DMZ Linux</td>
<td>65 days</td>
<td>True</td>
</tr>
<tr>
<td>Linux</td>
<td>3 days</td>
<td>False</td>
</tr>
<tr>
<td>Windows</td>
<td>95 days</td>
<td>True</td>
</tr>
</tbody>
</table>
</div>
<p>But instead it looks like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Repository</th>
<th>Age</th>
<th>Outstanding</th>
</tr>
</thead>
<tbody>
<tr>
<td>DMZ Linux</td>
<td>65 days</td>
<td>True</td>
</tr>
<tr>
<td>Linux</td>
<td>3 days</td>
<td>True</td>
</tr>
<tr>
<td>Windows</td>
<td>95 days</td>
<td>True</td>
</tr>
</tbody>
</table>
</div>
<p>Since the last index is True, it applied True to the whole column.</p>
<p>I have this code snippet:</p>
<pre><code>for i in range(len(report_data)):
line = report_data.loc[i]
if str(line['Age'] != ''):
new_val = str(line['Age']).replace('days', '')
no_space = new_val.replace('', '')
int_val = int(no_space)
if int_val > 60 and 'DMZ' in line['Repository']:
report_data['Outstanding']: line['Outstanding'] = 'True'
elif int_val > 90 and 'DMZ' not in line['Repository']:
report_data['Outstanding']: line['Outstanding'] = 'True'
else:
report_data['Outstanding']: line['Outstanding'] = 'False'
</code></pre>
<p>I tried the lambda function but I can't proceed since I have 2 IFs. Any clue on how I should properly assign per row and not the whole column?</p>
<p>Thank you for helping!</p>
| [
{
"answer_id": 74319192,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 3,
"selected": false,
"text": "local f = r.functionName\n"
},
{
"answer_id": 74322920,
"author": "koyaanisqatsi",
"author_id": 11740758,
"author_profile": "https://Stackoverflow.com/users/11740758",
"pm_score": 2,
"selected": true,
"text": "> -- I need to construct r with an example function\n> r = {}\n> r.functionName = string.gsub\n> -- You start here ;-)\n> replaced = r\n> r = {}\n> -- Fill r with replaced key/value pairs one by one\n> -- So new references will be created\n> -- Means: Changing r not changing replaced ( r ~= replaced )\n> for k, v in pairs(replaced) do r[k] = v end\n> -- Now replace r.functionName() with a function that calls replaced.functionName()\n> r.functionName = function(...)\n>> local f, s = replaced.functionName(...)\n>> return(s) -- Syntax makes sure that only s will be returned\n>> end\n> r.functionName(_VERSION, '.', '')\n7\n> #{r.functionName(_VERSION, '.', '')} -- Number of return values\n1\n> -- r can than be replaced again (restored/cleanup)\n> r = replaced -- Descruct of above r.functionName\n> replaced = nil -- Destruct of replaced\n> collectgarbage('collect') -- Freeing unused memory\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14748404/"
] |
74,319,196 | <p>Consider collection with following documents:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"_id": "3981396a-9fcb-4c24-976f-d500f20c4fab",
"entries": [
{
"key": "var1"
"value": "value1"
},
{
"key": "var1"
"value": "value11"
}
{
"key": "var2"
"value": "value2"
}
]
}
]
</code></pre>
<p>What would be the appropriate approach to de-duplicate entries for each document in collection. Query should at least find all of the documents with duplicated entries then manual looping over would be acceptable. Even better if it can be all done in single aggregation pipline.</p>
<p>Expected result is following:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"_id": "3981396a-9fcb-4c24-976f-d500f20c4fab",
"entries": [
{
"key": "var1"
"value": "value1"
},
{
"key": "var2"
"value": "value2"
}
]
}
]
</code></pre>
| [
{
"answer_id": 74319287,
"author": "ray",
"author_id": 14732669,
"author_profile": "https://Stackoverflow.com/users/14732669",
"pm_score": 1,
"selected": false,
"text": "$reduce"
},
{
"answer_id": 74319642,
"author": "Takis",
"author_id": 4882692,
"author_profile": "https://Stackoverflow.com/users/4882692",
"pm_score": 0,
"selected": false,
"text": "col.aggregate(\n[{\"$lookup\": \n {\"from\": \"dummy_collection_with_1_empty_doc\",\n \"pipeline\": \n [{\"$set\": {\"entries\": \"$$entries\"}},\n {\"$unwind\": \"$entries\"},\n {\"$group\": \n {\"_id\": \"$entries.key\", \"value\": {\"$first\": \"$entries.value\"}}},\n {\"$project\": {\"_id\": 0, \"key\": \"$_id\", \"value\": 1}}],\n \"as\": \"entries\",\n \"let\": {\"entries\": \"$entries\"}}}])\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9177575/"
] |
74,319,198 | <pre><code>int operator++(int){
//relevant code
}
</code></pre>
<p>I dont seem to understand the workings of the code for overloading post increment operator given
above</p>
<p>I know that the int as a dummy parameter is given to differentiate between pre-increment and post increment operator overloading.</p>
<p>If <code>a</code> is a object of the class in which these operators are overloaded ,both <code>++a</code> and <code>a++</code> should have a equivalent representation as <code>a.operator++()</code>(as per my understanding ),how does the int parameter help in resolving it as a post increment operator?</p>
<p>-A c++ beginner</p>
| [
{
"answer_id": 74319287,
"author": "ray",
"author_id": 14732669,
"author_profile": "https://Stackoverflow.com/users/14732669",
"pm_score": 1,
"selected": false,
"text": "$reduce"
},
{
"answer_id": 74319642,
"author": "Takis",
"author_id": 4882692,
"author_profile": "https://Stackoverflow.com/users/4882692",
"pm_score": 0,
"selected": false,
"text": "col.aggregate(\n[{\"$lookup\": \n {\"from\": \"dummy_collection_with_1_empty_doc\",\n \"pipeline\": \n [{\"$set\": {\"entries\": \"$$entries\"}},\n {\"$unwind\": \"$entries\"},\n {\"$group\": \n {\"_id\": \"$entries.key\", \"value\": {\"$first\": \"$entries.value\"}}},\n {\"$project\": {\"_id\": 0, \"key\": \"$_id\", \"value\": 1}}],\n \"as\": \"entries\",\n \"let\": {\"entries\": \"$entries\"}}}])\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19550296/"
] |
74,319,213 | <p>I have a dataframe like the following.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>i</th>
<th>j</th>
<th>element</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>0</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>4</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>0</td>
<td>7</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>8</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>9</td>
</tr>
</tbody>
</table>
</div>
<p>How can I convert it to the 3*3 array below?</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74319247,
"author": "Gonçalo Peres",
"author_id": 7109869,
"author_profile": "https://Stackoverflow.com/users/7109869",
"pm_score": 2,
"selected": false,
"text": "df"
},
{
"answer_id": 74319321,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 0,
"selected": false,
"text": "i, j, v = zip(*[x for x in df.itertuples(index=False, name=None)])\narr = np.zeros(df.shape)\narr[i, j] = v\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4531208/"
] |
74,319,233 | <p>I've uploaded a <strong>.ipynb</strong> jupyter notebook in GitHub but it doesn't display the exact same output as I've written in jupyter notebook.</p>
<p>Here's the link to my repo: <a href="https://github.com/akashsb18/Analysing-Dataset-Using-Pandas" rel="nofollow noreferrer">ipynb file</a></p>
| [
{
"answer_id": 74319247,
"author": "Gonçalo Peres",
"author_id": 7109869,
"author_profile": "https://Stackoverflow.com/users/7109869",
"pm_score": 2,
"selected": false,
"text": "df"
},
{
"answer_id": 74319321,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 0,
"selected": false,
"text": "i, j, v = zip(*[x for x in df.itertuples(index=False, name=None)])\narr = np.zeros(df.shape)\narr[i, j] = v\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18142963/"
] |
74,319,258 | <p>I currently have a list of dictionaries that looks like that:</p>
<pre class="lang-py prettyprint-override"><code>total_list = [
{'email': 'usera@email.com', 'id': 1, 'country': 'UK'},
{'email': 'usera@email.com', 'id': 1, 'country': 'Germany'},
{'email': 'userb@email.com', 'id': 2, 'country': 'UK'}
{'email': 'userc@email.com', 'id': 3, 'country': 'Italy'},
{'email': 'userc@email.com', 'id': 3, 'country': 'Netherland'},
{'email': 'userd@email.com', 'id': 4, 'country': 'France'},
...
]
</code></pre>
<p>I want to split it primarily based on size, so let's say that the new size list is 3 items per list, But I also want to make sure that all the same users will be in the same new sublist.</p>
<p>So the result I am trying to create is:</p>
<pre class="lang-py prettyprint-override"><code>list_a = [
{'email': 'usera@email.com', 'id': 1, 'country': 'UK'},
{'email': 'userb@email.com', 'id': 2, 'country': 'UK'}
{'email': 'usera@email.com', 'id': 1, 'country': 'Germany'}
]
list_b = [
{'email': 'userc@email.com', 'id': 3, 'country': 'Italy'},
{'email': 'userd@email.com', 'id': 4, 'country': 'France'}
{'email': 'userc@email.com', 'id': 3, 'country': 'Netherland'},
...
]
</code></pre>
<p>Obviously in the example that I provided the users were located really close to each other in the list, but in reality, they could be spread way more.
I was considering sorting the list based on the email and then splitting them, but I am not sure what happens if the items that are supposed to be grouped together happen to be at the exact location that
the main list will be divided.</p>
<p>What I have tried so far is:</p>
<pre class="lang-py prettyprint-override"><code>def list_splitter(main_list, size):
for i in range(0, len(main_list), size):
yield main_list[i:i + size]
# calculating the needed number of sublists
max_per_batch = 3
number_of_sublists = ceil(len(total_list) / max_per_batch)
# sort the data by email
total_list.sort(key=lambda x: x['email'])
sublists = list(list_splitter(main_list=total_list, size=max_per_batch))
</code></pre>
<p>The issue is that with this logic I cannot 100% <em>ensure</em> that if there are any items with the same email value they will end up in the same sublist. Because of the sorting, chances are that this will happen, but it is not certain.</p>
<p>Basically, I need a method to make sure that items with the same <code>email</code> will always be in the same sublist, but the main condition of the split is the sublist size.</p>
| [
{
"answer_id": 74370019,
"author": "MrMattBusby",
"author_id": 8507777,
"author_profile": "https://Stackoverflow.com/users/8507777",
"pm_score": 0,
"selected": false,
"text": "total_list"
},
{
"answer_id": 74411949,
"author": "Sebastian Baltser",
"author_id": 11786068,
"author_profile": "https://Stackoverflow.com/users/11786068",
"pm_score": 2,
"selected": false,
"text": "limit"
},
{
"answer_id": 74494723,
"author": "imakappa",
"author_id": 11485839,
"author_profile": "https://Stackoverflow.com/users/11485839",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\nimport numpy as np\nfrom numberpartitioning import karmarkar_karp\n\ndef solution(data, groupby: str, partition_size: int):\n df = pd.DataFrame(data)\n groups = df.groupby([groupby]).count()\n groupby_counts = groups.iloc[:, 0].values\n num_parts = len(df) // partition_size\n result = karmarkar_karp(groupby_counts, num_parts=num_parts, return_indices=True)\n part_keys = groups.index.values[np.array(result.partition)]\n partitions = [df.loc[df[groupby].isin(key)].to_dict('records') for key in part_keys]\n return partitions\n\n\nsolution(total_list, groupby=\"email\", partition_size=3)\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11249098/"
] |
74,319,273 | <p>I am considering what the value of ca will be after these operations:</p>
<pre><code>int ca = -279;
char abb = ca;
int ca = /abb >> 6) ;
</code></pre>
<p>I am having trouble understanding what happens with ca because of the shifting.</p>
| [
{
"answer_id": 74319498,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 2,
"selected": false,
"text": "char"
},
{
"answer_id": 74319787,
"author": "53845714nF",
"author_id": 19719003,
"author_profile": "https://Stackoverflow.com/users/19719003",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <limits.h>\n\nint main(){\n\nprintf(\"Short Max: %hi \\n\", SHRT_MAX);\nprintf(\"Short Min: %hi \\n\", SHRT_MIN);\n\nprintf(\"Char Max: %i \\n\", CHAR_MAX);\nprintf(\"Char Min: %i \\n\", CHAR_MIN);\n\nshort sa = -275;\nprintf(\"Short: %hi Char: %c\\n\", sa, sa);\n\nchar cb = (char) sa;\nprintf(\"Short: %hi Char: %c\\n\", cb, cb );\n\nshort sg = (cb << 8) >> 2;\nprintf(\"Short: %hi Char: %c \\n\", sg, sg);\n\nreturn 0;\n\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,319,282 | <p>I have a table like below and I would like to show TotalSales based on Category column.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Category</th>
<th>Sub-Cate</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chairs</td>
<td>Paper</td>
<td>16.448</td>
</tr>
<tr>
<td>Suppliers</td>
<td>Binders</td>
<td>3.54</td>
</tr>
<tr>
<td>Chairs</td>
<td>Art</td>
<td>85</td>
</tr>
<tr>
<td>Suppliers</td>
<td>Binders</td>
<td>45.89</td>
</tr>
<tr>
<td>Furniture</td>
<td>Paper</td>
<td>75.235</td>
</tr>
</tbody>
</table>
</div>
<p>I'm trying to use this query:
select Category,sales,TotalSales from (
select Category,Sales,
case when Category='Office Supplies' then sum(sales)
when Category='Furniture' then sum(sales)
end as TotalSales
from Orders$
group by Category,Sales ) as tmp
order by Category desc</p>
<p>I would like to show as below.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Category</th>
<th>Sub-Cate</th>
<th>Sales</th>
<th>TotalSales</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chairs</td>
<td>Paper</td>
<td>16.448</td>
<td>101.448</td>
<td>%</td>
</tr>
<tr>
<td>Suppliers</td>
<td>Binders</td>
<td>3.54</td>
<td>49.43</td>
<td>%</td>
</tr>
<tr>
<td>Chairs</td>
<td>Art</td>
<td>85</td>
<td>101.448</td>
<td>%</td>
</tr>
<tr>
<td>Suppliers</td>
<td>Binders</td>
<td>45.89</td>
<td>49.43</td>
<td>%</td>
</tr>
<tr>
<td>Furniture</td>
<td>Paper</td>
<td>75.235</td>
<td>75.235</td>
<td>%</td>
</tr>
</tbody>
</table>
</div>
<p>can anyone help to get this query.</p>
<p>Note: Percentage= Sales/Sub-Cate Total Sales</p>
| [
{
"answer_id": 74319498,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 2,
"selected": false,
"text": "char"
},
{
"answer_id": 74319787,
"author": "53845714nF",
"author_id": 19719003,
"author_profile": "https://Stackoverflow.com/users/19719003",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <limits.h>\n\nint main(){\n\nprintf(\"Short Max: %hi \\n\", SHRT_MAX);\nprintf(\"Short Min: %hi \\n\", SHRT_MIN);\n\nprintf(\"Char Max: %i \\n\", CHAR_MAX);\nprintf(\"Char Min: %i \\n\", CHAR_MIN);\n\nshort sa = -275;\nprintf(\"Short: %hi Char: %c\\n\", sa, sa);\n\nchar cb = (char) sa;\nprintf(\"Short: %hi Char: %c\\n\", cb, cb );\n\nshort sg = (cb << 8) >> 2;\nprintf(\"Short: %hi Char: %c \\n\", sg, sg);\n\nreturn 0;\n\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20418435/"
] |
74,319,300 | <p>As the title says, ESLint is complaining with this error message:</p>
<pre><code>ESLint: Unable to resolve path to module '@vercel/analytics/react'.(import/no-unresolved)
</code></pre>
<p>In the line: <code>import { Analytics } from '@vercel/analytics/react';</code></p>
<p>When following the instructions from this <a href="https://vercel.com/docs/concepts/analytics/audiences/quickstart#add-the-%60analytics%60-component-to-your-app" rel="nofollow noreferrer">Vercel quickstart guide</a>, using Next.js.</p>
<p>To sum up, the instructions are:</p>
<p>1- install package via NPM</p>
<pre><code>npm install @vercel/analytics
</code></pre>
<p>2- in <code>/pages/_app.tsx</code> file, import it:</p>
<pre><code>import { Analytics } from '@vercel/analytics/react';
function MyApp({ Component, pageProps }) {
return (
<>
<Component {...pageProps} />
<Analytics />
</>
);
}
export default MyApp;
</code></pre>
<p>My packages used:</p>
<pre><code>
"next": "^12.1.0",
"react": "17.0.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"eslint-config-next": "^12.2.5",
"eslint-config-prettier": "^6.15.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^24.7.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-testing-library": "^3.10.2",
</code></pre>
<p>The NPM package installed, has this folder structure:</p>
<pre><code>/node_modules/@vercel
analytics/
dist/
react/
index.cjs
index.d.ts
index.js
index.cjs
index.d.ts
index.js
package.json
tsconfig.json
...
</code></pre>
<p>Notice how the path in node_modules <em>actually</em> is '@vercel/analytics/dist/react' rather than just '@vercel/anaylitics/react' as the instructions state to do in the code to use it.</p>
<p><strong>But</strong>, when CTRL+click'ing on the variable imported <code>Analytics</code>, my IDE properly navigates me to the definition in node_modules, to the file <code>@vercel/analytics/dist/react/index.d.ts</code>, which is defined like so:</p>
<pre><code>// ./node_modules/@vercel/analytics/dist/react/index.d.ts
// ...
declare function Analytics(props: AnalyticsProps): JSX.Element;
export { Analytics };
</code></pre>
<p>My ESLint config related to the <code>import/</code> module is</p>
<pre class="lang-js prettyprint-override"><code>settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
paths: ['src'],
},
},
},
</code></pre>
<p>If I import it as this instead:</p>
<pre><code>import { Analytics } from '@vercel/analytics/dist/react'
</code></pre>
<p><strong>then</strong> ESlint doesn't complain, <strong>but</strong> TSC does, with this error message:</p>
<pre><code>TS2305: Module '"@vercel/analytics/dist/react"' has no exported member 'Analytics'.
</code></pre>
<p>Which also doesn't seem to make sense as the IDE is still finding the definition, and I can also see how the <code>export { Analytics }</code> line is there, so it <em>should</em> work...</p>
<p>What ESlint config or steps should I take differently to make this work without any lint/compiler errors?</p>
| [
{
"answer_id": 74325835,
"author": "ZeW",
"author_id": 14190507,
"author_profile": "https://Stackoverflow.com/users/14190507",
"pm_score": 0,
"selected": false,
"text": "//tsconfig.json\n\"compilerOptions\": {\n \"baseUrl\": \"./\",\n \"paths\": {\n \"@vercel/analytics/react\": [\"./node_modules/@vercel/analytics/dist/react\"]\n }\n}\n\n"
},
{
"answer_id": 74453475,
"author": "Evan Marshall",
"author_id": 20514854,
"author_profile": "https://Stackoverflow.com/users/20514854",
"pm_score": 1,
"selected": false,
"text": "...\n// eslint-disable-next-line import/no-unresolved\nimport { Analytics } from \"@vercel/analytics/react\";\n...\n"
},
{
"answer_id": 74520299,
"author": "Tobias Lins",
"author_id": 2160595,
"author_profile": "https://Stackoverflow.com/users/2160595",
"pm_score": 2,
"selected": false,
"text": "eslint"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6279385/"
] |
74,319,314 | <p>Very simple code.</p>
<pre><code><div>
<v-app-bar
app
flat
>
<v-app-bar-title>
Page Title
</v-app-bar-title>
</v-app-bar>
<v-container fluid>
<v-card
height="400"
outlined
flat
>
<v-card-title>
Card Title
</v-card-title>
</v-card>
</v-container>
</div>
</code></pre>
<p><a href="https://i.stack.imgur.com/zTmwW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zTmwW.png" alt="enter image description here" /></a></p>
<p>Everything works as expected, but if I add <code>height="auto"</code> to my <code><v-app-bar></code> this happens.</p>
<p><a href="https://i.stack.imgur.com/KkRP1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KkRP1.png" alt="enter image description here" /></a></p>
<p>Looks like <code><v-main></code> is no more calculated correctly. How can I avoid this issue?</p>
| [
{
"answer_id": 74324685,
"author": "yoduh",
"author_id": 6225326,
"author_profile": "https://Stackoverflow.com/users/6225326",
"pm_score": 0,
"selected": false,
"text": "dense"
},
{
"answer_id": 74324778,
"author": "Alexander Shkirkov",
"author_id": 9275224,
"author_profile": "https://Stackoverflow.com/users/9275224",
"pm_score": 1,
"selected": false,
"text": "<v-app-bar>"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19271543/"
] |
74,319,341 | <p>I have a QML <code>TextField</code> and want to limit the length to 16 characters.</p>
<pre><code>TextField {
id: myTextField
maximumLength: 16
}
</code></pre>
<p>Say I enter a multibyte-character like "" at the end of a 15 character long string, the emoji gets trimmed and results as �, which is one byte (0x3f in this case). I'm not sure where the 0x3f comes from, because internally the <code>QString</code> works with UTF-16, so this might be the result of some back and forth conversion between UTF-8 and UTF-16.</p>
<p>The only way I see right now to avoid this trimming of multibyte-characters is to implement my own <code>QValidator</code> where I then need to check the length of my string with a Unicode aware library like ICU.</p>
<p>My Question now: Is there any other easier way to avoid the trimming, that I'm missing here?</p>
| [
{
"answer_id": 74319751,
"author": "easysaesch",
"author_id": 4012609,
"author_profile": "https://Stackoverflow.com/users/4012609",
"pm_score": 0,
"selected": false,
"text": "QValidator"
},
{
"answer_id": 74323160,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 2,
"selected": true,
"text": "import QtQuick\nimport QtQuick.Controls\nPage {\n Column {\n Text { text: \"\" } // \n Text { text: \"\\u{1f60a}\" } // \n Text { text: \"\\u{d83d}\\u{de0a}\" } // \n Text { text: \"\\u{d83d}\" } // �\n Text { text: \"\\u{de0a}\" } // �\n Text { text: \"�\" } // �\n Text { text: \"\\u{fffd}\" } // �\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4012609/"
] |
74,319,342 | <pre><code> game=input("enter student name to update report card: ")
nn=game.replace(" ", "_")
mycursor.execute("show tables")
klm = mycursor.fetchall()
if (nn,) in klm:
b=int(input("enter sno: "))
mycursor.execute("select * from {} where sno='{}'".format(nn,b))
xer=mycursor.fetchall()
else:
print("no student record found")
</code></pre>
<p>this does not execute the if statement it directly goes to the else even though i have table name some_one, it shows no record found</p>
<p><a href="https://i.stack.imgur.com/zUWQD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zUWQD.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74319751,
"author": "easysaesch",
"author_id": 4012609,
"author_profile": "https://Stackoverflow.com/users/4012609",
"pm_score": 0,
"selected": false,
"text": "QValidator"
},
{
"answer_id": 74323160,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 2,
"selected": true,
"text": "import QtQuick\nimport QtQuick.Controls\nPage {\n Column {\n Text { text: \"\" } // \n Text { text: \"\\u{1f60a}\" } // \n Text { text: \"\\u{d83d}\\u{de0a}\" } // \n Text { text: \"\\u{d83d}\" } // �\n Text { text: \"\\u{de0a}\" } // �\n Text { text: \"�\" } // �\n Text { text: \"\\u{fffd}\" } // �\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20416181/"
] |
74,319,350 | <p>I have the following query:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT distinct INCOME_LEVEL
FROM CUSTOMERS
where INCOME_LEVEL like '%-%'
</code></pre>
<p>Which returns:</p>
<p><img src="https://i.stack.imgur.com/QWfaT.png" alt="Query output" /></p>
<p>I need to Leave only those levels that are in the format "999,999 - 999,999", where the number "9" means that any of the digits 0-9 are possible.</p>
| [
{
"answer_id": 74319751,
"author": "easysaesch",
"author_id": 4012609,
"author_profile": "https://Stackoverflow.com/users/4012609",
"pm_score": 0,
"selected": false,
"text": "QValidator"
},
{
"answer_id": 74323160,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 2,
"selected": true,
"text": "import QtQuick\nimport QtQuick.Controls\nPage {\n Column {\n Text { text: \"\" } // \n Text { text: \"\\u{1f60a}\" } // \n Text { text: \"\\u{d83d}\\u{de0a}\" } // \n Text { text: \"\\u{d83d}\" } // �\n Text { text: \"\\u{de0a}\" } // �\n Text { text: \"�\" } // �\n Text { text: \"\\u{fffd}\" } // �\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20090021/"
] |
74,319,355 | <p>Ive been scrolling and scrolling and i dont seem to find any solution. I am making a simple java fx program where i draw different shapes. The problem is that i dont know how to implement an undo button. I have found that you can use stacks, command pattern, arraydeque and so on... But i cant fix it..</p>
<p>Here is some of the code.</p>
<pre><code>public class shapeModel {
//private final List<Shape> undoHistory = new ArrayList<>();
//private final Deque<Deque<Shape>> redoHistory;
private final ObservableList<Shape> shapeList;
private final ObjectProperty<Color> colorPickerSelect;
private final int historyIndex = -1;
private ShapeType currentShape;
public shapeModel() {
//this.redoHistory = new ArrayDeque<>();
this.colorPickerSelect = new SimpleObjectProperty<>(Color.GREEN);
this.shapeList = FXCollections.observableArrayList(shape -> new Observable[]{
shape.colorProperty()
});
}
public ShapeType getCurrentShape() {
return currentShape;
}
public void setCurrentShape(ShapeType currentShape) {
this.currentShape = currentShape;
}
public void addShapes(Shape shape) {
if (!(shape == null))
this.shapeList.add(shape);
}
public Color getColorPickerSelect() {
return colorPickerSelect.get();
}
public ObjectProperty<Color> colorPickerSelectProperty() {
return colorPickerSelect;
}
public ObservableList<Shape> getShapeObservableList() {
return shapeList;
}
public void undo() {
}
}
</code></pre>
<p>Controller class:</p>
<pre><code>public class HelloController {
public Button eraserButton;
public Button undoButton;
public BorderPane scenePane;
public ColorPicker myColorPicker;
public ChoiceBox<String> myChoiceBox;
public GraphicsContext context;
public Canvas canvas;
public shapeModel model;
public void initialize() {
context = canvas.getGraphicsContext2D();
model.getShapeObservableList().addListener((ListChangeListener<Shape>) e -> listChanged());
myColorPicker.valueProperty().bindBidirectional(model.colorPickerSelectProperty());
}
public HelloController() {
this.model = new shapeModel();
}
//
// private int count = 0;
//
// private final Shape[] shapes = new Shape[30];
public void canvasClicked(MouseEvent mouseEvent) {
Shape shape = Shape.creatingShapes(model.getCurrentShape(),mouseEvent.getX(),mouseEvent.getY(),50,50,myColorPicker.getValue());
model.addShapes(shape);
// redraw();
// shapes[count] = shape;
// count++;
// paintCanvas();
}
public void listChanged() {
var context = canvas.getGraphicsContext2D();
model.getShapeObservableList().forEach(s -> s.draw(context));
}
public void undoClicked() {
}
// public void redo() {
//
// if(historyIndex < model.getShapeObservableList().size()-1) {
// historyIndex++;
// model.getShapeObservableList(),(historyIndex).
// }
//
// }
public void handleClick() {
FileChooser chooser = new FileChooser();
File file = chooser.showSaveDialog(scenePane.getScene().getWindow());
}
public void onCircleClicked(ActionEvent e) {
model.setCurrentShape(ShapeType.CIRCLE);
}
public void onRectangleClicked(ActionEvent e) {
model.setCurrentShape(ShapeType.RECTANGLE);
}
public void exitAction(ActionEvent actionEvent) {
Platform.exit();
}
public void eraser() {
context.setFill(Color.WHITE);
context.fillRect(0,0,canvas.getWidth(), canvas.getHeight());
// context.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
}
}
</code></pre>
| [
{
"answer_id": 74319751,
"author": "easysaesch",
"author_id": 4012609,
"author_profile": "https://Stackoverflow.com/users/4012609",
"pm_score": 0,
"selected": false,
"text": "QValidator"
},
{
"answer_id": 74323160,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 2,
"selected": true,
"text": "import QtQuick\nimport QtQuick.Controls\nPage {\n Column {\n Text { text: \"\" } // \n Text { text: \"\\u{1f60a}\" } // \n Text { text: \"\\u{d83d}\\u{de0a}\" } // \n Text { text: \"\\u{d83d}\" } // �\n Text { text: \"\\u{de0a}\" } // �\n Text { text: \"�\" } // �\n Text { text: \"\\u{fffd}\" } // �\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19963735/"
] |
74,319,360 | <p>I have some data which I need to sort using the first column of each object.</p>
<p>The project uses Angular / Typescript but it's still JS.</p>
<p>Here's how the data looks:</p>
<pre><code>[
{
time: 1000.189,
other: 100
},
{
time: 1023.189 ,
other: 105
},
{
time: 999.189,
other: 100
}
]
</code></pre>
<p>So the above should look like this:</p>
<pre><code>[
{
time: 999.189,
other: 100
},
{
time: 1000.189,
other: 100
},
{
time: 1023.189,
other: "105
}
]
</code></pre>
<p>How can I do this?</p>
| [
{
"answer_id": 74319422,
"author": "Randy",
"author_id": 3561849,
"author_profile": "https://Stackoverflow.com/users/3561849",
"pm_score": 0,
"selected": false,
"text": "this.array.sort((a, b) => a['time'] - b['time']);\n"
},
{
"answer_id": 74319647,
"author": "LocoBE",
"author_id": 15799188,
"author_profile": "https://Stackoverflow.com/users/15799188",
"pm_score": 1,
"selected": true,
"text": "const array = [\n {\n time: 1000.189,\n other: 100\n },\n {\n time: 1023.189 ,\n other: 105\n },\n {\n time: 999.189,\n other: 100\n }\n]\n\nconst result = array.sort((a, b) => a.time - b.time);\n\nconsole.log(result);\n"
},
{
"answer_id": 74319737,
"author": "Shreyansh Gupta",
"author_id": 18046485,
"author_profile": "https://Stackoverflow.com/users/18046485",
"pm_score": 1,
"selected": false,
"text": "function sortByColumn(colname){\n return array.sort((a,b)=>a[colname]-b[colname])\n }\n\nconst array = [\n {\n time: 1000.189,\n other: 100 \n },\n {\n time: 1023.189 ,\n other: 105 \n },\n {\n time: 999.189,\n other: 100 \n }\n]\n\nconst orderSorted = sortByColumn('order')\nconst timeSorted = sortByColumn('time')\n\nconsole.log(orderSorted)\n\nconsole.log(timeSorted)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20357413/"
] |
74,319,380 | <p>For example, I have</p>
<pre><code><div class="stick active"></div>
<div class="stick"></div>
<div class="stick"></div>
<div class="stick"></div>
<div class="stick"></div>
</code></pre>
<p>I need to find out all the indexes from the stick classes so that I can refer to each of them further [0],[1],[2]...</p>
<p>I tried to convert them to an array via <strong>[...]</strong> and via <strong>Array.prototype.slice.call</strong>
but when I try to interact with them, I get "undefined"</p>
| [
{
"answer_id": 74319422,
"author": "Randy",
"author_id": 3561849,
"author_profile": "https://Stackoverflow.com/users/3561849",
"pm_score": 0,
"selected": false,
"text": "this.array.sort((a, b) => a['time'] - b['time']);\n"
},
{
"answer_id": 74319647,
"author": "LocoBE",
"author_id": 15799188,
"author_profile": "https://Stackoverflow.com/users/15799188",
"pm_score": 1,
"selected": true,
"text": "const array = [\n {\n time: 1000.189,\n other: 100\n },\n {\n time: 1023.189 ,\n other: 105\n },\n {\n time: 999.189,\n other: 100\n }\n]\n\nconst result = array.sort((a, b) => a.time - b.time);\n\nconsole.log(result);\n"
},
{
"answer_id": 74319737,
"author": "Shreyansh Gupta",
"author_id": 18046485,
"author_profile": "https://Stackoverflow.com/users/18046485",
"pm_score": 1,
"selected": false,
"text": "function sortByColumn(colname){\n return array.sort((a,b)=>a[colname]-b[colname])\n }\n\nconst array = [\n {\n time: 1000.189,\n other: 100 \n },\n {\n time: 1023.189 ,\n other: 105 \n },\n {\n time: 999.189,\n other: 100 \n }\n]\n\nconst orderSorted = sortByColumn('order')\nconst timeSorted = sortByColumn('time')\n\nconsole.log(orderSorted)\n\nconsole.log(timeSorted)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324239/"
] |
74,319,408 | <p>How do you "pipe" an expression in Polars?</p>
<p>Consider this code:</p>
<pre><code>def transformation(col:pl.Series)->pl.Series:
return col.tanh().suffix('_tanh')
</code></pre>
<p>It'd be nice to be able to do this:</p>
<pre><code>df.with_columns([
pl.col('colA').pipe(transformation),
pl.col('colB').pipe(transformation),
pl.col('colC').pipe(transformation),
pl.col('colD').pipe(transformation),
])
</code></pre>
<p>But I don't think Polars supports .pipe for Series / expressions.</p>
<p>The alternative is</p>
<pre><code>df.with_columns([
transformation(pl.col('colA')),
transformation(pl.col('colB')),
transformation(pl.col('colC')),
transformation(pl.col('colD')),
])
</code></pre>
<p>But this gets messy (IMO) when you have arguments to the <code>transformation</code> function</p>
<h1>Edit:</h1>
<p>I implemented this and it "works" for me</p>
<pre><code>def _pipe(self, func, *args, **kwargs):
return func(self, *args, **kwargs)
pl.Expr.pipe = _pipe
</code></pre>
| [
{
"answer_id": 74319422,
"author": "Randy",
"author_id": 3561849,
"author_profile": "https://Stackoverflow.com/users/3561849",
"pm_score": 0,
"selected": false,
"text": "this.array.sort((a, b) => a['time'] - b['time']);\n"
},
{
"answer_id": 74319647,
"author": "LocoBE",
"author_id": 15799188,
"author_profile": "https://Stackoverflow.com/users/15799188",
"pm_score": 1,
"selected": true,
"text": "const array = [\n {\n time: 1000.189,\n other: 100\n },\n {\n time: 1023.189 ,\n other: 105\n },\n {\n time: 999.189,\n other: 100\n }\n]\n\nconst result = array.sort((a, b) => a.time - b.time);\n\nconsole.log(result);\n"
},
{
"answer_id": 74319737,
"author": "Shreyansh Gupta",
"author_id": 18046485,
"author_profile": "https://Stackoverflow.com/users/18046485",
"pm_score": 1,
"selected": false,
"text": "function sortByColumn(colname){\n return array.sort((a,b)=>a[colname]-b[colname])\n }\n\nconst array = [\n {\n time: 1000.189,\n other: 100 \n },\n {\n time: 1023.189 ,\n other: 105 \n },\n {\n time: 999.189,\n other: 100 \n }\n]\n\nconst orderSorted = sortByColumn('order')\nconst timeSorted = sortByColumn('time')\n\nconsole.log(orderSorted)\n\nconsole.log(timeSorted)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17194313/"
] |
74,319,411 | <p>I have a json dictionary in a cell of my table. The keys of the dictionary can be varied and I don't know the full list of them in advance.</p>
<p>How can I unnest the key value pairs?</p>
<p><em>FWIW, I'm using Presto.</em></p>
<pre class="lang-sql prettyprint-override"><code>with example(json_info) as (
VALUES
('{"Key A": "ABC","Key B": "DEF", "Key C": "XYZ"}')
)
select
key
, value
from example
CROSS JOIN
UNNEST(
CAST(
JSON_PARSE(json_info)
as ARRAY(ROW(key VARCHAR, value VARCHAR))
)
) as x(key, value)
</code></pre>
<p>When I run the above code I get the following error which makes me think I'm on the wrong path.</p>
<blockquote>
<p>Cannot cast to array(row(type varchar,value varchar)). Expected a json array, but got { {"Key A": "123","Key B": "456", "Key C": "789"}</p>
</blockquote>
| [
{
"answer_id": 74319422,
"author": "Randy",
"author_id": 3561849,
"author_profile": "https://Stackoverflow.com/users/3561849",
"pm_score": 0,
"selected": false,
"text": "this.array.sort((a, b) => a['time'] - b['time']);\n"
},
{
"answer_id": 74319647,
"author": "LocoBE",
"author_id": 15799188,
"author_profile": "https://Stackoverflow.com/users/15799188",
"pm_score": 1,
"selected": true,
"text": "const array = [\n {\n time: 1000.189,\n other: 100\n },\n {\n time: 1023.189 ,\n other: 105\n },\n {\n time: 999.189,\n other: 100\n }\n]\n\nconst result = array.sort((a, b) => a.time - b.time);\n\nconsole.log(result);\n"
},
{
"answer_id": 74319737,
"author": "Shreyansh Gupta",
"author_id": 18046485,
"author_profile": "https://Stackoverflow.com/users/18046485",
"pm_score": 1,
"selected": false,
"text": "function sortByColumn(colname){\n return array.sort((a,b)=>a[colname]-b[colname])\n }\n\nconst array = [\n {\n time: 1000.189,\n other: 100 \n },\n {\n time: 1023.189 ,\n other: 105 \n },\n {\n time: 999.189,\n other: 100 \n }\n]\n\nconst orderSorted = sortByColumn('order')\nconst timeSorted = sortByColumn('time')\n\nconsole.log(orderSorted)\n\nconsole.log(timeSorted)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/99045/"
] |
74,319,413 | <p>I need to make my <code>Iterator< isConst = false></code> convert to <code>Iterator<isConst = true></code>. That is, I need a separate method <code>Iterator< true >(const Iterator< false > &)</code>.</p>
<p>My Iterator class:</p>
<pre><code>template < typename T >
template < bool isConst >
class ForwardList< T >::Iterator
{
using value_type = std::conditional_t< isConst, const T, T >;
using difference_type = ptrdiff_t;
using pointer = std::conditional_t< isConst, const T *, T * >;
using reference = std::conditional_t< isConst, const T &, T & >;
using iterator_category = std::forward_iterator_tag;
friend class ForwardList< T >;
private:
explicit Iterator(node_t *nodePtr): nodePtr_(nodePtr) {}
public:
Iterator() = default;
Iterator(const Iterator &other) = default;
~Iterator() = default;
reference operator*() const;
pointer operator->() const;
Iterator &operator++();
Iterator operator++(int) &;
bool operator==(const Iterator &other) const;
bool operator!=(const Iterator &other) const;
private:
node_t *nodePtr_;
};
</code></pre>
<p>I tried overloading the copy constructor and specializing the template. I understand that if you split the Iterator into two classes, it can be done, but I don't want to duplicate so much code.</p>
| [
{
"answer_id": 74319657,
"author": "Caleth",
"author_id": 2610810,
"author_profile": "https://Stackoverflow.com/users/2610810",
"pm_score": 3,
"selected": true,
"text": "Iterator<false>"
},
{
"answer_id": 74320123,
"author": "fabian",
"author_id": 2991525,
"author_profile": "https://Stackoverflow.com/users/2991525",
"pm_score": 0,
"selected": false,
"text": "template < typename T >\ntemplate < bool isConst >\nclass ForwardList< T >::Iterator\n{\n...\n\n friend class ForwardList<T>::Iterator<!isConst>;\npublic:\n Iterator() = default;\n\n template<bool otherIsConst, std::enable_if_t<isConst || !otherIsConst, int> = 0>\n Iterator(Iterator<otherIsConst> const& other)\n : nodePtr_(other.nodePtr_)\n {\n }\n\n ~Iterator() = default;\n ...\nprivate:\n node_t* nodePtr_ {nullptr}; // note: crash more likely for dereferencing the default-constructed object\n};\n\nstatic_assert(std::is_constructible_v<ForwardList<int>::Iterator<true>, ForwardList<int>::Iterator<true> const&>, \"expected constructor unavailable\");\nstatic_assert(std::is_constructible_v<ForwardList<int>::Iterator<true>, ForwardList<int>::Iterator<false> const&>, \"expected constructor unavailable\");\nstatic_assert(std::is_constructible_v<ForwardList<int>::Iterator<false>, ForwardList<int>::Iterator<false>const&>, \"expected constructor unavailable\");\nstatic_assert(!std::is_constructible_v<ForwardList<int>::Iterator<false>, ForwardList<int>::Iterator<true> const&>, \"unexpected constructor available\");\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13517983/"
] |
74,319,419 | <p>We have a Python Linux azure function that is connected to a custom oidc provider and azure ad to provide authentication to the HTTP triggered functions using Microsofts easyauth.</p>
<p>After the initial setup, the azure function was working and has been working for the last few months.</p>
<p>In the last 2 days, our application suddenly started to error out on our custom provider, the azure ad authentication is still working, after checking the easyauth logs, we see the error</p>
<pre><code>System.PlatformNotSupportedException: Windows Cryptography Next Generation (CNG) is not supported on this platform.
</code></pre>
<p>No changes were made on either the custom oidc provider or the azure function in the last 2 days.
We suspect that maybe the base easyauth docker image (mcr.microsoft.com/appsvc/middleware:stage2) got updated and that broke the authentication.</p>
<p>Any ideas or suggestions on possible fixes or even related problems?</p>
| [
{
"answer_id": 74358162,
"author": "Fabien Soulis",
"author_id": 20447914,
"author_profile": "https://Stackoverflow.com/users/20447914",
"pm_score": 0,
"selected": false,
"text": "2022-11-08T08:47:28.449645417Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[13]\n**2022-11-08T08:47:28.449692217Z Connection id \"0HMM1CIPP8I5M\", Request id \"0HMM1CIPP8I5M:00000004\": An unhandled exception was thrown by the application**.\n2022-11-08T08:47:28.450647224Z System.PlatformNotSupportedException: Windows Cryptography Next Generation (CNG) is not supported on this platform.\n2022-11-08T08:47:28.451187128Z at System.Security.Cryptography.RSACng..ctor()\n2022-11-08T08:47:28.451205328Z at Microsoft.Azure.AppService.Middleware.JsonWebKey.GetSecurityKeys() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/JsonWebKey.cs:line 100\n2022-11-08T08:47:28.451422129Z at Microsoft.Azure.AppService.Middleware.OpenIdConnectConfiguration.GetJwtValidationParameters(String siteName, String clientId, String authenticationType, String allowedAudiences) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/OpenIdConnectConfiguration.cs:line 114\n2022-11-08T08:47:28.457668471Z at Microsoft.Azure.AppService.Middleware.AzureActiveDirectoryProvider.GetOpenIdConnectValidationParameters(ConfigManager oidcConfigManager, Boolean forceRefresh) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/AzureActiveDirectoryProvider.cs:line 1131\n2022-11-08T08:47:28.457685071Z at Microsoft.Azure.AppService.Middleware.AzureActiveDirectoryProvider.HandleServerDirectedLoginAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/AzureActiveDirectoryProvider.cs:line 518\n2022-11-08T08:47:28.457689872Z at Microsoft.Azure.AppService.Middleware.IdentityProviderBase.OnCompleteServerDirectedLoginAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/IdentityProviderBase.cs:line 655\n2022-11-08T08:47:28.457693772Z at Microsoft.Azure.AppService.Middleware.IdentityProviderBase.TryHandleProtocolRequestAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/IdentityProviderBase.cs:line 185\n2022-11-08T08:47:28.457697572Z at Microsoft.Azure.AppService.Middleware.EasyAuthModule.OnBeginRequestAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/EasyAuthModule.cs:line 220\n2022-11-08T08:47:28.457818072Z at Microsoft.Azure.AppService.Middleware.NetCore.AppServiceMiddleware.InvokeAsync(HttpContext context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.NetCore/AppServiceMiddleware.cs:line 102\n2022-11-08T08:47:28.457928173Z at Microsoft.Azure.AppService.MiddlewareShim.AutoHealing.AutoHealingMiddleware.Invoke(HttpContext context) in /EasyAuth/Middleware.Host/AutoHealing/AutoHealingMiddleware.cs:line 55\n2022-11-08T08:47:28.457939473Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)\n"
},
{
"answer_id": 74359343,
"author": "Akseli Käppi",
"author_id": 19305159,
"author_profile": "https://Stackoverflow.com/users/19305159",
"pm_score": 2,
"selected": true,
"text": "az webapp auth update --name xxx --resource-group xxx --runtime-version \"1.5.1\""
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13222107/"
] |
74,319,435 | <p>I want to have my VB.NET program secure folder(s) which all contain a handful of different files so the files within cannot be edited unless the program "unlocks" the folder in Windows. Is this possible? I do not want the folder/files hidden just essentially in some Read-Only state or something or fake out windows into thinking they are already open. The goal is if someone opens the files without the program "unlocking" them, they cannot edit/save changes.</p>
| [
{
"answer_id": 74358162,
"author": "Fabien Soulis",
"author_id": 20447914,
"author_profile": "https://Stackoverflow.com/users/20447914",
"pm_score": 0,
"selected": false,
"text": "2022-11-08T08:47:28.449645417Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[13]\n**2022-11-08T08:47:28.449692217Z Connection id \"0HMM1CIPP8I5M\", Request id \"0HMM1CIPP8I5M:00000004\": An unhandled exception was thrown by the application**.\n2022-11-08T08:47:28.450647224Z System.PlatformNotSupportedException: Windows Cryptography Next Generation (CNG) is not supported on this platform.\n2022-11-08T08:47:28.451187128Z at System.Security.Cryptography.RSACng..ctor()\n2022-11-08T08:47:28.451205328Z at Microsoft.Azure.AppService.Middleware.JsonWebKey.GetSecurityKeys() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/JsonWebKey.cs:line 100\n2022-11-08T08:47:28.451422129Z at Microsoft.Azure.AppService.Middleware.OpenIdConnectConfiguration.GetJwtValidationParameters(String siteName, String clientId, String authenticationType, String allowedAudiences) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/OpenIdConnectConfiguration.cs:line 114\n2022-11-08T08:47:28.457668471Z at Microsoft.Azure.AppService.Middleware.AzureActiveDirectoryProvider.GetOpenIdConnectValidationParameters(ConfigManager oidcConfigManager, Boolean forceRefresh) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/AzureActiveDirectoryProvider.cs:line 1131\n2022-11-08T08:47:28.457685071Z at Microsoft.Azure.AppService.Middleware.AzureActiveDirectoryProvider.HandleServerDirectedLoginAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/AzureActiveDirectoryProvider.cs:line 518\n2022-11-08T08:47:28.457689872Z at Microsoft.Azure.AppService.Middleware.IdentityProviderBase.OnCompleteServerDirectedLoginAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/IdentityProviderBase.cs:line 655\n2022-11-08T08:47:28.457693772Z at Microsoft.Azure.AppService.Middleware.IdentityProviderBase.TryHandleProtocolRequestAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/IdentityProviders/IdentityProviderBase.cs:line 185\n2022-11-08T08:47:28.457697572Z at Microsoft.Azure.AppService.Middleware.EasyAuthModule.OnBeginRequestAsync(HttpContextBase context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/EasyAuthModule.cs:line 220\n2022-11-08T08:47:28.457818072Z at Microsoft.Azure.AppService.Middleware.NetCore.AppServiceMiddleware.InvokeAsync(HttpContext context) in /EasyAuth/Microsoft.Azure.AppService.Middleware.NetCore/AppServiceMiddleware.cs:line 102\n2022-11-08T08:47:28.457928173Z at Microsoft.Azure.AppService.MiddlewareShim.AutoHealing.AutoHealingMiddleware.Invoke(HttpContext context) in /EasyAuth/Middleware.Host/AutoHealing/AutoHealingMiddleware.cs:line 55\n2022-11-08T08:47:28.457939473Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)\n"
},
{
"answer_id": 74359343,
"author": "Akseli Käppi",
"author_id": 19305159,
"author_profile": "https://Stackoverflow.com/users/19305159",
"pm_score": 2,
"selected": true,
"text": "az webapp auth update --name xxx --resource-group xxx --runtime-version \"1.5.1\""
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6849894/"
] |
74,319,454 | <p>Sometimes you want to suppress a clippy warning for the time being and you let clippy ignore a specific rule for a specific code block by adding lines like the following:</p>
<pre><code>#[allow(dead_code)]
</code></pre>
<p>But as the project continues, it can actually happen that you remove the problem, without actually removing the allowing of the clippy lint. So is there a way to check for allowed clippy warnings that are actually not being used anymore? So in this example I'd like to be informed when I <code>#[allow(dead_code)]</code> but there is actually no dead code to be found in the given code block.</p>
| [
{
"answer_id": 74320142,
"author": "ordinaryduck",
"author_id": 14575901,
"author_profile": "https://Stackoverflow.com/users/14575901",
"pm_score": 0,
"selected": false,
"text": "_"
},
{
"answer_id": 74320946,
"author": "Kevin Reid",
"author_id": 99692,
"author_profile": "https://Stackoverflow.com/users/99692",
"pm_score": 2,
"selected": true,
"text": "lint_reasons"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20418889/"
] |
74,319,480 | <p>In a PHP web page, when flling the form and some of the fields are filled incorrectly, I need to return to the same page and auto-fill all the fields that were prefiously filled by the user. How do I set the values of the fields?</p>
<p>I tried using the $_POST method and echo but the error was that the key I used was undefined.</p>
| [
{
"answer_id": 74320142,
"author": "ordinaryduck",
"author_id": 14575901,
"author_profile": "https://Stackoverflow.com/users/14575901",
"pm_score": 0,
"selected": false,
"text": "_"
},
{
"answer_id": 74320946,
"author": "Kevin Reid",
"author_id": 99692,
"author_profile": "https://Stackoverflow.com/users/99692",
"pm_score": 2,
"selected": true,
"text": "lint_reasons"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20418900/"
] |
74,319,485 | <p>Is there a pythonic way to constrain the output of a method so that it can only be one of a set? Sort of like typing but for specific values only. I hope you can see what I'm trying to get at with this snippet:</p>
<pre><code>class Rule:
def evaluate(self, user_id: int) -> {"PASS", "FAIL", "ERROR"}:
...
</code></pre>
<p>In the above case I would be hoping for evaluate to only return "PASS", "FAIL" or "ERROR"</p>
| [
{
"answer_id": 74319542,
"author": "jprebys",
"author_id": 3268228,
"author_profile": "https://Stackoverflow.com/users/3268228",
"pm_score": 2,
"selected": false,
"text": "from typing import Literal\n\nclass Rule:\n def evaluate(self, user_id: int) -> Literal[\"PASS\", \"FAIL\", \"ERROR\"]:\n ...\n"
},
{
"answer_id": 74319582,
"author": "João Bonfim",
"author_id": 20381775,
"author_profile": "https://Stackoverflow.com/users/20381775",
"pm_score": 2,
"selected": true,
"text": "Enum"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18556111/"
] |
74,319,524 | <p>I'm reading <a href="https://cplusplus.com/doc/tutorial/classes/" rel="nofollow noreferrer">classes tutorial</a> in cplusplus.com.</p>
<p>I got confused by the following paragraph.</p>
<blockquote>
<p>Default-constructing all members of a class may or may always not be convenient: in some cases, this is a waste (when the member is then reinitialized otherwise in the constructor), but in some other cases, default-construction is not even possible (when the class does not have a default constructor). In these cases, members shall be initialized in the member initialization list.</p>
</blockquote>
<p>So, my question is what does the "when the member is then reinitialized otherwise in the constructor" mean? Why is a waste?</p>
<p>In the beginning, I think the "reinitialized` like following code.</p>
<pre class="lang-cpp prettyprint-override"><code>class Son
{
int age;
public:
// default constructor
Son()
{
age = 1;
}
Son(int age) : age(age) {}
};
class Father
{
Son son; // First, I think that it will call default constructor of class Son when the object of Father was created
int age;
public:
// Then object of Father will call this constructor, then initialize son again.
Father(int sonAge, int fatherAge) : son(sonAge), age(fatherAge)
{
}
};
</code></pre>
<p>Then, I found <code>Son son</code> wasn't to define son at all, it just waited the constructor of Father to initialized <code>son</code>. So this isn't waste, my idea is wrong!!! Maybe I lack the knowledge of object creation order? cplusplus.com provides tutorial seems incomplete for me...</p>
<p>Can you give me a few code examples?</p>
| [
{
"answer_id": 74319703,
"author": "user17732522",
"author_id": 17732522,
"author_profile": "https://Stackoverflow.com/users/17732522",
"pm_score": 2,
"selected": false,
"text": "Son()\n{\n age = 1;\n}\n"
},
{
"answer_id": 74319711,
"author": "user4581301",
"author_id": 4581301,
"author_profile": "https://Stackoverflow.com/users/4581301",
"pm_score": 3,
"selected": true,
"text": "int age;\nSon() // age initialized here (does nothing)\n{\n age = 1;// age assigned new value here\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14218416/"
] |
74,319,531 | <p>I have created a simple bash script to start capturing traffic from all interfaces I have in my Linux machine (ubuntu 22), but this script should stop capturing traffic 2 hours after the machine has reboot. Below is my bash script</p>
<pre><code>#!/bin/bash
cd /home/user/
tcpdump -U -i any -s 65535 -w output.pcap &
pid=$(ps -e | pgrep tcpdump)
echo $pid
sleep 7200
kill -2 $pid
</code></pre>
<p>The script works fine if I run it, but I need to have it running after every reboot.</p>
<p>Whenever I run the script, it works without problem</p>
<pre><code>user@linux:~$ sudo ./startup.sh
[sudo] password for user:
tcpdump: data link type LINUX_SLL2
tcpdump: listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 65535 bytes
1202
35 packets captured
35 packets received by filter
0 packets dropped by kernel
</code></pre>
<p>but when I set it in the crontab as</p>
<pre><code>@reboot /home/user/startup.sh
</code></pre>
<p>it does not start at reboot. I used ps -e | pgrep tcpdump to make sure if the script is running but there is not an output, it seems that it is not starting the script after the reboot. I don't know if I need to have root permissions for that. Also, I checked the file permission, and it has</p>
<pre><code>-rwxrwxr-x 1 user user 142 Nov 4 10:11 startup.sh
</code></pre>
<p>Any suggestion on why it is not starting the script at the reboot?</p>
| [
{
"answer_id": 74319703,
"author": "user17732522",
"author_id": 17732522,
"author_profile": "https://Stackoverflow.com/users/17732522",
"pm_score": 2,
"selected": false,
"text": "Son()\n{\n age = 1;\n}\n"
},
{
"answer_id": 74319711,
"author": "user4581301",
"author_id": 4581301,
"author_profile": "https://Stackoverflow.com/users/4581301",
"pm_score": 3,
"selected": true,
"text": "int age;\nSon() // age initialized here (does nothing)\n{\n age = 1;// age assigned new value here\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18920279/"
] |
74,319,536 | <p>I'm working in Apache OpenOffice calc (v4.1.13) and would like to search a row, find the last row with a non-empty cell and return the column header for that row. Note that the cells contain text and that some cells in the row are empty.</p>
<p>In <a href="https://stackoverflow.com/questions/44465752/return-the-column-header-of-last-cell-with-data">this post</a> they used <code>=LOOKUP(2,1/(H228:S228<>""), H1:S1)</code> to return the column header of the last row with data. I first changed the commas to semicolons to work with OpenOffice, then changed the row values to match my ranges to get the following: <code>=LOOKUP(2;1/(F4:I4<>"");F1:I1)</code> but I get a #DIV/0 error.</p>
<p>The #DIV/0 error goes away and the function works if I put dummy data in what were blank cells in F4:I4.</p>
<p>From what I understand, in Excel this formula will work if some of the cells in the row are empty. This seems not to be the case in OpenOffice Calc, as I get a #DIV/0 error. How do I make this work in Calc?</p>
| [
{
"answer_id": 74330886,
"author": "Jim K",
"author_id": 5100564,
"author_profile": "https://Stackoverflow.com/users/5100564",
"pm_score": 0,
"selected": false,
"text": "=LOOKUP(2;1/ISNUMBER(H228:S228);H228:S228)\n"
},
{
"answer_id": 74379782,
"author": "Mike",
"author_id": 10706115,
"author_profile": "https://Stackoverflow.com/users/10706115",
"pm_score": 2,
"selected": true,
"text": "=LOOKUP(\"ZZZ\";F9:ZZ9;F1:ZZ1)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10706115/"
] |
74,319,549 | <p>I have a multi-line textInput in my application that looks like this:</p>
<pre><code>TextFormField(
maxLines: 5,
minLines: 3,
initialValue: object.textValue
)
</code></pre>
<p>It works fine when the user inputs new values.<br />
However, when I need to load an existing value the input is not applying the line breaks.</p>
<p>This is an example of the text value I need to load:</p>
<pre><code>"line 1\nline 2\n\nline 4"
</code></pre>
<p>This is how it looks:</p>
<p><a href="https://i.stack.imgur.com/yv3lW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yv3lW.png" alt="enter image description here" /></a></p>
<p>How can I display the text respecting the line breaks?</p>
| [
{
"answer_id": 74330886,
"author": "Jim K",
"author_id": 5100564,
"author_profile": "https://Stackoverflow.com/users/5100564",
"pm_score": 0,
"selected": false,
"text": "=LOOKUP(2;1/ISNUMBER(H228:S228);H228:S228)\n"
},
{
"answer_id": 74379782,
"author": "Mike",
"author_id": 10706115,
"author_profile": "https://Stackoverflow.com/users/10706115",
"pm_score": 2,
"selected": true,
"text": "=LOOKUP(\"ZZZ\";F9:ZZ9;F1:ZZ1)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1286937/"
] |
74,319,595 | <p>I'm just learning the basics of powershell and have a task - create pwsh script which accepts 3 incoming parameters (all are mandatory):</p>
<ol>
<li>first parameter, value <em>address_1</em>, it's IP address with the format x.x.x.x</li>
<li>second parameter, value <em>address_2</em>, it's IP address with the format x.x.x.x</li>
<li>third parameter, value <em>mask</em>, value in the format x.x.x.x or xx (255.0.0.0 or 8)</li>
</ol>
<p>This script should check <em>address_1</em> and <em>address_2</em> belong to the same network or not. Results in output console, yes or no. As I mentioned before incoming parameters not allow to accept not valid arguments, it should show error.</p>
<p>Can someone explain, how I can do that. I will be very grateful for your help.</p>
| [
{
"answer_id": 74326743,
"author": "Keith Miller",
"author_id": 9406738,
"author_profile": "https://Stackoverflow.com/users/9406738",
"pm_score": 1,
"selected": false,
"text": "[ValidatePattern()]"
},
{
"answer_id": 74336969,
"author": "lunnyj",
"author_id": 10009512,
"author_profile": "https://Stackoverflow.com/users/10009512",
"pm_score": 0,
"selected": false,
"text": "param (\n [parameter(Mandatory = $true, Position = 0)]\n [Net.IPAddress]\n $ip1,\n \n [parameter(Mandatory = $true, Position = 1)]\n [Net.IPAddress]\n $ip2,\n \n [parameter(Mandatory = $true, Position = 2)]\n [alias(\"SubnetMask\")]\n [Net.IPAddress]\n $mask\n)\n \nif (($ip1.address -band $mask.address) -eq ($ip2.address -band $mask.address)) { $true } else { $false }\n"
},
{
"answer_id": 74339707,
"author": "postanote",
"author_id": 9132707,
"author_profile": "https://Stackoverflow.com/users/9132707",
"pm_score": 2,
"selected": true,
"text": "# IPv4 Range\nfunction New-IPRange ($start, $end)\n{\n # created by Dr. Tobias Weltner, MVP PowerShell\n $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()\n [Array]::Reverse($ip1)\n $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address\n $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()\n [Array]::Reverse($ip2)\n $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address\n \n for ($x=$ip1; $x -le $ip2; $x++)\n {\n $ip = ([System.Net.IPAddress]$x).GetAddressBytes()\n [Array]::Reverse($ip)\n $ip -join '.'\n }\n}\n\n\n# IPv4 Range - Example\nNew-IPRange 192.168.10.10 192.168.10.20\n\n# broadcast IPv4 address from a CIDR range\nfunction Get-Broadcast ($addressAndCidr)\n{\n $addressAndCidr = $addressAndCidr.Split(\"/\")\n $addressInBin = (New-IPv4toBin $addressAndCidr[0]).ToCharArray()\n for($i=0;$i -lt $addressInBin.length;$i++)\n {\n if($i -ge $addressAndCidr[1])\n {\n $addressInBin[$i] = \"1\"\n } \n }\n [string[]]$addressInInt32 = @()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i] \n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 Broadcast - Example\nGet-Broadcast 192.168.10.10/27\n\n\n# detect if a specified IPv4 address is in the range\n\nfunction Test-IPinIPRange ($Address,$Lower,$Mask)\n{\n [Char[]]$a = (New-IPv4toBin $Lower).ToCharArray()\n if($mask -like \"*.*\")\n {\n [Char[]]$b = (New-IPv4toBin $Mask).ToCharArray()\n }\n else\n {\n [Int[]]$array = (1..32)\n for($i=0;$i -lt $array.length;$i++)\n {\n if($array[$i] -gt $mask){$array[$i]=\"0\"}else{$array[$i]=\"1\"}\n }\n [string]$mask = $array -join \"\"\n [Char[]]$b = $mask.ToCharArray()\n }\n [Char[]]$c = (New-IPv4toBin $Address).ToCharArray()\n $res = $true\n for($i=0;$i -le $a.length;$i++)\n {\n if($a[$i] -ne $c[$i] -and $b[$i] -ne \"0\")\n {\n $res = $false\n } \n }\n return $res\n}\n\n# IPv4 In Range - Example\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.128/25\"\nTest-IPinIPRange \"192.168.23.200\" \"192.168.23.12\" \"255.255.255.128\"\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.127/24\"\nTest-IPinIPRange \"192.168.23.127\" \"192.168.23.12\" \"24\"\n\n# convert an IPv4 address to a Bin\nfunction New-IPv4toBin ($ipv4)\n{\n $BinNum = $ipv4 -split '\\.' | ForEach-Object {[System.Convert]::ToString($_,2).PadLeft(8,'0')}\n return $binNum -join \"\"\n}\n\n# IPv4 To Bin - Example\nWrite-Output \"`r`nIP To Bin\"\nNew-IPv4toBin 192.168.10.10\n\n# convert a Bin to an IPv4 address\nfunction New-IPv4fromBin($addressInBin)\n{\n [string[]]$addressInInt32 = @()\n $addressInBin = $addressInBin.ToCharArray()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i]\n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 From Bin - Example\nWrite-Output \"`r`nIP From Bin - 192.168.23.250\"\nNew-IPv4fromBin \"11000000101010000001011111111010\"\n \nWrite-Output \"`r`nIP From Bin - 192.168.10.10\"\nNew-IPv4fromBin \"11000000101010000000101000001010\"\n\n# CIDR To IPv4 Range - Example\nWrite-Output \"`r`nIP CIDR to Range\"\nNew-IPRange \"192.168.23.120\" (Get-Broadcast \"192.168.23.120/25\")\n"
},
{
"answer_id": 74340510,
"author": "Matt Holmes",
"author_id": 20415279,
"author_profile": "https://Stackoverflow.com/users/20415279",
"pm_score": 1,
"selected": false,
"text": "param (\n [Parameter(Mandatory, Position=0)][string] $ip1,\n [Parameter(Mandatory, Position=1)] [string] $ip2,\n [Parameter(Mandatory, Position=2)] [string] $mask\n)\n# you can use [Parameter(Mandatory, Position=0)][IPAddress] $ip1 as input instead of string\n# ipaddress param can accept partial ip's like 192.168 and will convert it to 192.0.0.168\n# string with test would probably be better\n\nfunction IsValidIPv4 ($ip) {\n return ($ip -match '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' -and [bool]($ip -as [ipaddress]))\n}\n\n# Validate IP's as actual IPv4\nif (isValidIPv4 $ip1){\n write-host \"$($ip1) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip1) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $ip2){\n write-host \"$($ip2) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip2) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $mask){\n write-host \"$($mask) IS a valid IPv4 Address\"\n} else {\n write-host \"$($mask) is not a valid netmask\" -ForegroundColor Red\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10009512/"
] |
74,319,605 | <p>I'm writing a bot in Python that uses Selenium to play a web-based of Tic Tac Toe. I want to loop through an array of XPATHs that represent the game grid and check each square for the presence of the 'O' character. If the square is marked by an O, the number of that square should be appended to another list of marked squares.</p>
<p>This is the section of code that I'm trying to fix:</p>
<pre><code> for i in Board.squares:
text = driver.find_element(By.XPATH, Board.squares[i]).text
if text == 'O':
LOGGER.info("Square " + str(i) + " marked by O.")
Board.markedSquares.append(i)
LOGGER.info("Appending marked squares list: " + str(Board.markedSquares))
</code></pre>
<p>But I get the following error in traceback:</p>
<pre><code>11/04/2022 10:32:49 AM–root– INFO:First move: clicking square 3
Traceback (most recent call last):
File "C:\Users\source\repos\React project_2\ttt_user_bot\RandomBot.py", line 97, in <module>
playTTT()
File "C:\Users\source\repos\React project_2\ttt_user_bot\RandomBot.py", line 72, in playTTT
text = driver.find_element(By.XPATH, Board.squares[i]).text
TypeError: list indices must be integers or slices, not str
</code></pre>
<p>Below is the full code for my bot. Everything works except for the for loop above, and I'm not sure how to fix it. Without this check, the bot can click on a square marked by an O, and the script will time out.</p>
<pre><code>class Tags():
square1 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[1]"
square2 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[2]"
square3 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[3]"
square4 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[4]"
square5 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[5]"
square6 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[6]"
square7 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[7]"
square8 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[8]"
square9 = "(//div[contains(@class, 'board-row')]//button[contains(@class, 'square')])[9]"
ohSquare = "//div[contains(@class, 'board-row')]//button[contains(text(), 'O')]"
winner = "//div[contains(@class, 'game-info')]//div[contains(text(), 'Winner:')]"
tie = "//div[contains(@class, 'game-info')]//div[contains(text(), 'tie')]"
class Board():
squares = [Tags.square1,Tags.square2,Tags.square3,
Tags.square4,Tags.square5,Tags.square6,
Tags.square7,Tags.square8,Tags.square9]
markedSquares = []
def firstMove():
random_square = randint(0,8)
time.sleep(5)
element = driver.find_element(By.XPATH, Board.squares[random_square])
element.click()
Board.markedSquares.append(random_square)
LOGGER.info("First move: clicking square " + str(random_square))
def playTTT():
random_square = randint(0,8)
time.sleep(5)
try:
driver.find_element(By.XPATH, Tags.winner).is_displayed()
text = driver.find_element(By.XPATH, Tags.winner).text
LOGGER.info(str(text))
driver.save_screenshot("screenshot.png")
driver.close()
except NoSuchElementException:
pass
try:
driver.find_element(By.XPATH, Tags.tie).is_displayed()
LOGGER.info("Tie")
driver.save_screenshot("screenshot.png")
driver.close()
except NoSuchElementException:
pass
for i in Board.squares:
text = driver.find_element(By.XPATH, Board.squares[i]).text
if text == 'O':
LOGGER.info("Square " + str(i) + " marked by O.")
Board.markedSquares.append(i)
LOGGER.info("Appending marked squares list: " + str(Board.markedSquares))
try:
for i in Board.markedSquares:
if i == random_square:
LOGGER.info("Square number " + str(i) + " already marked. Recomputing...")
break
else:
element = driver.find_element(By.XPATH, Board.squares[random_square])
element.click()
Board.markedSquares.append(random_square)
LOGGER.info("Clicking square:" + str(random_square))
break
LOGGER.info("Contents of markedSquares: " + str(Board.markedSquares))
playTTT()
except InvalidSessionIdException:
pass
if __name__=='__main__':
firstMove()
playTTT()
</code></pre>
| [
{
"answer_id": 74326743,
"author": "Keith Miller",
"author_id": 9406738,
"author_profile": "https://Stackoverflow.com/users/9406738",
"pm_score": 1,
"selected": false,
"text": "[ValidatePattern()]"
},
{
"answer_id": 74336969,
"author": "lunnyj",
"author_id": 10009512,
"author_profile": "https://Stackoverflow.com/users/10009512",
"pm_score": 0,
"selected": false,
"text": "param (\n [parameter(Mandatory = $true, Position = 0)]\n [Net.IPAddress]\n $ip1,\n \n [parameter(Mandatory = $true, Position = 1)]\n [Net.IPAddress]\n $ip2,\n \n [parameter(Mandatory = $true, Position = 2)]\n [alias(\"SubnetMask\")]\n [Net.IPAddress]\n $mask\n)\n \nif (($ip1.address -band $mask.address) -eq ($ip2.address -band $mask.address)) { $true } else { $false }\n"
},
{
"answer_id": 74339707,
"author": "postanote",
"author_id": 9132707,
"author_profile": "https://Stackoverflow.com/users/9132707",
"pm_score": 2,
"selected": true,
"text": "# IPv4 Range\nfunction New-IPRange ($start, $end)\n{\n # created by Dr. Tobias Weltner, MVP PowerShell\n $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()\n [Array]::Reverse($ip1)\n $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address\n $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()\n [Array]::Reverse($ip2)\n $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address\n \n for ($x=$ip1; $x -le $ip2; $x++)\n {\n $ip = ([System.Net.IPAddress]$x).GetAddressBytes()\n [Array]::Reverse($ip)\n $ip -join '.'\n }\n}\n\n\n# IPv4 Range - Example\nNew-IPRange 192.168.10.10 192.168.10.20\n\n# broadcast IPv4 address from a CIDR range\nfunction Get-Broadcast ($addressAndCidr)\n{\n $addressAndCidr = $addressAndCidr.Split(\"/\")\n $addressInBin = (New-IPv4toBin $addressAndCidr[0]).ToCharArray()\n for($i=0;$i -lt $addressInBin.length;$i++)\n {\n if($i -ge $addressAndCidr[1])\n {\n $addressInBin[$i] = \"1\"\n } \n }\n [string[]]$addressInInt32 = @()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i] \n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 Broadcast - Example\nGet-Broadcast 192.168.10.10/27\n\n\n# detect if a specified IPv4 address is in the range\n\nfunction Test-IPinIPRange ($Address,$Lower,$Mask)\n{\n [Char[]]$a = (New-IPv4toBin $Lower).ToCharArray()\n if($mask -like \"*.*\")\n {\n [Char[]]$b = (New-IPv4toBin $Mask).ToCharArray()\n }\n else\n {\n [Int[]]$array = (1..32)\n for($i=0;$i -lt $array.length;$i++)\n {\n if($array[$i] -gt $mask){$array[$i]=\"0\"}else{$array[$i]=\"1\"}\n }\n [string]$mask = $array -join \"\"\n [Char[]]$b = $mask.ToCharArray()\n }\n [Char[]]$c = (New-IPv4toBin $Address).ToCharArray()\n $res = $true\n for($i=0;$i -le $a.length;$i++)\n {\n if($a[$i] -ne $c[$i] -and $b[$i] -ne \"0\")\n {\n $res = $false\n } \n }\n return $res\n}\n\n# IPv4 In Range - Example\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.128/25\"\nTest-IPinIPRange \"192.168.23.200\" \"192.168.23.12\" \"255.255.255.128\"\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.127/24\"\nTest-IPinIPRange \"192.168.23.127\" \"192.168.23.12\" \"24\"\n\n# convert an IPv4 address to a Bin\nfunction New-IPv4toBin ($ipv4)\n{\n $BinNum = $ipv4 -split '\\.' | ForEach-Object {[System.Convert]::ToString($_,2).PadLeft(8,'0')}\n return $binNum -join \"\"\n}\n\n# IPv4 To Bin - Example\nWrite-Output \"`r`nIP To Bin\"\nNew-IPv4toBin 192.168.10.10\n\n# convert a Bin to an IPv4 address\nfunction New-IPv4fromBin($addressInBin)\n{\n [string[]]$addressInInt32 = @()\n $addressInBin = $addressInBin.ToCharArray()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i]\n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 From Bin - Example\nWrite-Output \"`r`nIP From Bin - 192.168.23.250\"\nNew-IPv4fromBin \"11000000101010000001011111111010\"\n \nWrite-Output \"`r`nIP From Bin - 192.168.10.10\"\nNew-IPv4fromBin \"11000000101010000000101000001010\"\n\n# CIDR To IPv4 Range - Example\nWrite-Output \"`r`nIP CIDR to Range\"\nNew-IPRange \"192.168.23.120\" (Get-Broadcast \"192.168.23.120/25\")\n"
},
{
"answer_id": 74340510,
"author": "Matt Holmes",
"author_id": 20415279,
"author_profile": "https://Stackoverflow.com/users/20415279",
"pm_score": 1,
"selected": false,
"text": "param (\n [Parameter(Mandatory, Position=0)][string] $ip1,\n [Parameter(Mandatory, Position=1)] [string] $ip2,\n [Parameter(Mandatory, Position=2)] [string] $mask\n)\n# you can use [Parameter(Mandatory, Position=0)][IPAddress] $ip1 as input instead of string\n# ipaddress param can accept partial ip's like 192.168 and will convert it to 192.0.0.168\n# string with test would probably be better\n\nfunction IsValidIPv4 ($ip) {\n return ($ip -match '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' -and [bool]($ip -as [ipaddress]))\n}\n\n# Validate IP's as actual IPv4\nif (isValidIPv4 $ip1){\n write-host \"$($ip1) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip1) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $ip2){\n write-host \"$($ip2) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip2) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $mask){\n write-host \"$($mask) IS a valid IPv4 Address\"\n} else {\n write-host \"$($mask) is not a valid netmask\" -ForegroundColor Red\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20168619/"
] |
74,319,612 | <p>How to generate a list from a pandas dataframe with column name and values as nested list?
this is my dataframe:</p>
<pre><code> a b c d
0 1 5 9 13
1 2 6 10 14
2 3 7 11 15
3 4 8 12 16
</code></pre>
<p>i would like to generate a list</p>
<pre><code>list1 = [[a,1], [a,2], [a,3],[a,4]]
list2 = [[b,5], [b,6], [b,7],[b,8]]
</code></pre>
| [
{
"answer_id": 74326743,
"author": "Keith Miller",
"author_id": 9406738,
"author_profile": "https://Stackoverflow.com/users/9406738",
"pm_score": 1,
"selected": false,
"text": "[ValidatePattern()]"
},
{
"answer_id": 74336969,
"author": "lunnyj",
"author_id": 10009512,
"author_profile": "https://Stackoverflow.com/users/10009512",
"pm_score": 0,
"selected": false,
"text": "param (\n [parameter(Mandatory = $true, Position = 0)]\n [Net.IPAddress]\n $ip1,\n \n [parameter(Mandatory = $true, Position = 1)]\n [Net.IPAddress]\n $ip2,\n \n [parameter(Mandatory = $true, Position = 2)]\n [alias(\"SubnetMask\")]\n [Net.IPAddress]\n $mask\n)\n \nif (($ip1.address -band $mask.address) -eq ($ip2.address -band $mask.address)) { $true } else { $false }\n"
},
{
"answer_id": 74339707,
"author": "postanote",
"author_id": 9132707,
"author_profile": "https://Stackoverflow.com/users/9132707",
"pm_score": 2,
"selected": true,
"text": "# IPv4 Range\nfunction New-IPRange ($start, $end)\n{\n # created by Dr. Tobias Weltner, MVP PowerShell\n $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()\n [Array]::Reverse($ip1)\n $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address\n $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()\n [Array]::Reverse($ip2)\n $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address\n \n for ($x=$ip1; $x -le $ip2; $x++)\n {\n $ip = ([System.Net.IPAddress]$x).GetAddressBytes()\n [Array]::Reverse($ip)\n $ip -join '.'\n }\n}\n\n\n# IPv4 Range - Example\nNew-IPRange 192.168.10.10 192.168.10.20\n\n# broadcast IPv4 address from a CIDR range\nfunction Get-Broadcast ($addressAndCidr)\n{\n $addressAndCidr = $addressAndCidr.Split(\"/\")\n $addressInBin = (New-IPv4toBin $addressAndCidr[0]).ToCharArray()\n for($i=0;$i -lt $addressInBin.length;$i++)\n {\n if($i -ge $addressAndCidr[1])\n {\n $addressInBin[$i] = \"1\"\n } \n }\n [string[]]$addressInInt32 = @()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i] \n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 Broadcast - Example\nGet-Broadcast 192.168.10.10/27\n\n\n# detect if a specified IPv4 address is in the range\n\nfunction Test-IPinIPRange ($Address,$Lower,$Mask)\n{\n [Char[]]$a = (New-IPv4toBin $Lower).ToCharArray()\n if($mask -like \"*.*\")\n {\n [Char[]]$b = (New-IPv4toBin $Mask).ToCharArray()\n }\n else\n {\n [Int[]]$array = (1..32)\n for($i=0;$i -lt $array.length;$i++)\n {\n if($array[$i] -gt $mask){$array[$i]=\"0\"}else{$array[$i]=\"1\"}\n }\n [string]$mask = $array -join \"\"\n [Char[]]$b = $mask.ToCharArray()\n }\n [Char[]]$c = (New-IPv4toBin $Address).ToCharArray()\n $res = $true\n for($i=0;$i -le $a.length;$i++)\n {\n if($a[$i] -ne $c[$i] -and $b[$i] -ne \"0\")\n {\n $res = $false\n } \n }\n return $res\n}\n\n# IPv4 In Range - Example\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.128/25\"\nTest-IPinIPRange \"192.168.23.200\" \"192.168.23.12\" \"255.255.255.128\"\nWrite-Output \"`r`nTest If IP In Range - 192.168.23.127/24\"\nTest-IPinIPRange \"192.168.23.127\" \"192.168.23.12\" \"24\"\n\n# convert an IPv4 address to a Bin\nfunction New-IPv4toBin ($ipv4)\n{\n $BinNum = $ipv4 -split '\\.' | ForEach-Object {[System.Convert]::ToString($_,2).PadLeft(8,'0')}\n return $binNum -join \"\"\n}\n\n# IPv4 To Bin - Example\nWrite-Output \"`r`nIP To Bin\"\nNew-IPv4toBin 192.168.10.10\n\n# convert a Bin to an IPv4 address\nfunction New-IPv4fromBin($addressInBin)\n{\n [string[]]$addressInInt32 = @()\n $addressInBin = $addressInBin.ToCharArray()\n for ($i = 0;$i -lt $addressInBin.length;$i++)\n {\n $partAddressInBin += $addressInBin[$i]\n if(($i+1)%8 -eq 0)\n {\n $partAddressInBin = $partAddressInBin -join \"\"\n $addressInInt32 += [Convert]::ToInt32($partAddressInBin -join \"\",2)\n $partAddressInBin = \"\"\n }\n }\n $addressInInt32 = $addressInInt32 -join \".\"\n return $addressInInt32\n}\n\n# IPv4 From Bin - Example\nWrite-Output \"`r`nIP From Bin - 192.168.23.250\"\nNew-IPv4fromBin \"11000000101010000001011111111010\"\n \nWrite-Output \"`r`nIP From Bin - 192.168.10.10\"\nNew-IPv4fromBin \"11000000101010000000101000001010\"\n\n# CIDR To IPv4 Range - Example\nWrite-Output \"`r`nIP CIDR to Range\"\nNew-IPRange \"192.168.23.120\" (Get-Broadcast \"192.168.23.120/25\")\n"
},
{
"answer_id": 74340510,
"author": "Matt Holmes",
"author_id": 20415279,
"author_profile": "https://Stackoverflow.com/users/20415279",
"pm_score": 1,
"selected": false,
"text": "param (\n [Parameter(Mandatory, Position=0)][string] $ip1,\n [Parameter(Mandatory, Position=1)] [string] $ip2,\n [Parameter(Mandatory, Position=2)] [string] $mask\n)\n# you can use [Parameter(Mandatory, Position=0)][IPAddress] $ip1 as input instead of string\n# ipaddress param can accept partial ip's like 192.168 and will convert it to 192.0.0.168\n# string with test would probably be better\n\nfunction IsValidIPv4 ($ip) {\n return ($ip -match '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' -and [bool]($ip -as [ipaddress]))\n}\n\n# Validate IP's as actual IPv4\nif (isValidIPv4 $ip1){\n write-host \"$($ip1) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip1) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $ip2){\n write-host \"$($ip2) IS a valid IPv4 Address\"\n} else {\n write-host \"$($ip2) is not a valid IPv4 Address\" -ForegroundColor Red\n}\nif (isValidIPv4 $mask){\n write-host \"$($mask) IS a valid IPv4 Address\"\n} else {\n write-host \"$($mask) is not a valid netmask\" -ForegroundColor Red\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20418639/"
] |
74,319,626 | <p>Here is my code which is producing some unexpected results when input value is changed. (I know that there are lot of comments in it, I was using that as a means of debugging).</p>
<pre><code>age = 0
age = input("please enter your age ")
#print(age)
#int(age)
#print(type(age))
age1 = int(age)
#print(type(age1))
print(age1)
if age1 > 30:
#ageV = "old"
print("old")
else: age1 < 30
#ageV = "young"
print("young")
#print(ageV)
</code></pre>
<p>How can I debug this?</p>
| [
{
"answer_id": 74319662,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 1,
"selected": false,
"text": "else: age1 < 30"
},
{
"answer_id": 74319854,
"author": "Speedy",
"author_id": 18284431,
"author_profile": "https://Stackoverflow.com/users/18284431",
"pm_score": 0,
"selected": false,
"text": "if age1 > 30: \n print(\"Old\")\nelse: \n print(\"Young\")\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1026713/"
] |
74,319,653 | <p>I have an HTML page that is partially generated by a 3rd party that I cannot change. However, I can add my own Javascript to the page to modify it's behavior.</p>
<p>I want to remove a keypress event listener from an input textbox.</p>
<p>In Chrome dev tools, if I view the element, I can see the following two events tied to a keypress:
<a href="https://i.stack.imgur.com/xYeyw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xYeyw.png" alt="enter image description here" /></a></p>
<p>I added the second event listener with the following code:</p>
<pre><code>$('#signInName').keypress(function (e) {
var key = e.which;
if(key == 13 && $('.sendCode').css('display') != 'none')
{
$('.sendCode').trigger('click');
return false;
}
});
</code></pre>
<p>I want to remove the first listener in the image. If I click the 'remove' button in dev tools I can confirm that I get the functionality I want, which is to click a different button when I press ENTER, than what the 3rd party has set to fire.</p>
<p>I can see that I can get access to the events using this jquery:</p>
<pre><code>> $('#signInName').keypress.length
< 2
</code></pre>
<p>But, I am very limited in my JQuery or javascript experience, and I want to remove the event listener as mentioned.</p>
<p>How can I reference and remove this other event listener preferably using a static identifier and without using the exact index of <code>0</code> in the collection, which might change?</p>
| [
{
"answer_id": 74319662,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 1,
"selected": false,
"text": "else: age1 < 30"
},
{
"answer_id": 74319854,
"author": "Speedy",
"author_id": 18284431,
"author_profile": "https://Stackoverflow.com/users/18284431",
"pm_score": 0,
"selected": false,
"text": "if age1 > 30: \n print(\"Old\")\nelse: \n print(\"Young\")\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8543505/"
] |
74,319,654 | <p>I have one JS file called taxForms.js and a script syntax within the html file. And I need to make changes within the html file, so the <code>console.log()</code> puts out the right output.
My task goes like this:</p>
<p>In income-greather-than-500k.html you will find an array of tax forms assigned to the variable called
taxForms.
In its current state the entire array is logged to the console. You need to change the Javascript in incomegreather-than-500k.html such that the array is iterated and only the real name of the superheroes
that have an income greater than 500 000 are logged with console.log.</p>
<p>I have tried if statements to output the right answer, but I always get an error in the console.</p>
<p>javaScript:</p>
<pre><code>const taxForms = [
{
realName: "Bruce Wayne",
income: 750000,
wealth: 300000
},
{
realName: "John Blake",
income: 440000,
wealth: 832000
},
{
realName: "Selina Kyle",
income: 640000,
wealth: 432000
}
];
</code></pre>
<p>html:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Income greather than 500 000</title>
<meta charset="UTF-8">
<script src="taxForms.js"></script>
</head>
<body>
<script>
if (taxForms[income] > 500000) {
console.log(taxForms);
}
</script>
</body>
</html>
</code></pre>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20229542/"
] |
74,319,660 | <p>Here's what I did.</p>
<ol>
<li>Made changes to my README directly in my github repo with 3 commits.</li>
<li>made 4 more commits locally without pulling those 3 commits in.</li>
</ol>
<p>Now when I try to push it says pull those remote commits first but when I do git pull it show error.</p>
<pre><code>warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
</code></pre>
<p>So I just ran the command <code>git config pull.ff only</code></p>
<p>And now when I pull this is what it says <code>fatal: Not possible to fast-forward, aborting.</code></p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16697095/"
] |
74,319,719 | <p>Basically i am doing a <strong>document.querySelectorAll()</strong> which returns an array of div elements . I have a function which has a <strong>handleclick()</strong> function and each time i click in this button i want the hide the table of the button that i am click on not.</p>
<p>This is what i have right now
<a href="https://i.stack.imgur.com/gJLM6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJLM6.png" alt="enter image description here" /></a></p>
<p>This is what happens when i click one of the dropdrown buttons
<a href="https://i.stack.imgur.com/bVfAL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bVfAL.png" alt="enter image description here" /></a></p>
<p><strong>CURRENT BEHAVIOUR: All of the tables hide</strong></p>
<p><strong>EXCEPTED BEHAVIOUR: Onlt the table which is related to the button that i am clicking should hide</strong></p>
<p>Here is the code snippet of the file</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const handleTitleClick = (e) => {
const row = document.querySelectorAll(
"div[class*='MuiDataGrid-root']"
) as NodeList;
const rowArr = Array.from(row);
rowArr.map((r, i) => {
const somerow = r;
somerow.style.display = 'none';
return row;
});
console.log(e);
console.log(rowArr);
console.log(row);
};</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18174677/"
] |
74,319,722 | <p>We use AG Grid. I want to add our license as a side effect before exporting the React component for use, rather than having to add the license every time we use the grid component.</p>
<p>What I tried below doesn't work. I thought side effects would run before import/export if declared like this, but clearly my mental model was wrong. I assume the build tool may affect what happens too, we use Gulp in this particular case.</p>
<p><strong>GridSupport.js</strong> (in a design package/repo)</p>
<pre class="lang-js prettyprint-override"><code>/**
* AG Grid License
*/
import { LicenseManager } from "@ag-grid-enterprise/core";
LicenseManager.setLicenseKey('…some license key…');
// Export below happens, but no license set above :(
export { AgGridReact as default } from "@ag-grid-community/react";
</code></pre>
<p><strong>Grid.js</strong> (in another package/repo)</p>
<pre><code>import { AgGridReact } from 'GridSupport';
const Grid = (props) => {
// AgGridReact should be usable without printing license warnings to the console
return <AgGridReact {...props} />
}
</code></pre>
<p>What should I do instead?</p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/750544/"
] |
74,319,739 | <p>I have these two lists (let's imagine we have hundreds of lists) :</p>
<pre><code>l1 = list(c(1,2,3),c(12))
l2 = list(data.frame(x=c(1,2,3)),c(4,5))
</code></pre>
<p>and I wish to choose only the second element from each list. How to do so ? thanks.</p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19720935/"
] |
74,319,765 | <p>I create this custom hook in my React app. It should return a <code>boolean</code>.</p>
<pre><code>const useFetchResponse = (url: string) => {
const [isValid, setIsValid] = useState<boolean>(false);
useEffect(() => {
const fetchResponse = async () => {
const response = await fetch(url);
console.log(response);
const obj = await response.json();
if (response.ok) {
console.log(await response.json());
setIsValid(true);
}
return response;
};
fetchResponse().then((res) => res);
}, []);
return isValid;
};
export default useFetchResponse;
</code></pre>
<p>When I log <code>const obj = await response.json();</code> it returns: <code>{"keyName":"some=key"}</code>.</p>
<p>How do I create a condition to check if <code>response.json()</code> has a key named <code>keyName</code>?</p>
<p>Is that for example <code>console.log('keyName' in obj) // true</code>?
Do you see more things which I can improve and refactor?</p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4822666/"
] |
74,319,777 | <p>We have recently migrated from sending emails with <code>deliver_now</code> to <code>deliver_later</code>. So that queued emails aren't lost when the system restarts, we implement this with Sidekiq.</p>
<p>When we used <code>deliver_now</code>, our Rake tests could test the sending of an email with</p>
<pre><code>assert_equal 1, ActionMailer::Base.deliveries.count
</code></pre>
<p>For Rspec there is the <code>assert_enqueued_emails</code> method to test whether or not emails are queued. Is there an equivalent for Rake test?</p>
| [
{
"answer_id": 74319750,
"author": "ericmp",
"author_id": 14569750,
"author_profile": "https://Stackoverflow.com/users/14569750",
"pm_score": 1,
"selected": false,
"text": "taxForms[income]"
},
{
"answer_id": 74319883,
"author": "Tony",
"author_id": 17146534,
"author_profile": "https://Stackoverflow.com/users/17146534",
"pm_score": 0,
"selected": false,
"text": "For (let i=0; i<taxForms.length; i++){ if (taxForms[i][income]>500000){ console.log(taxForms[i][realName] }}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4959100/"
] |
74,319,805 | <p>I am using "moveto" to reach at destination caller <em>Dryer</em>. <em>Dryer</em> have "queue" and "delay".
Now when agent come it first go to <em>Dryer</em> and then go to "queue" and then wait for its turn to go to <em>Dryer</em> for "delay".</p>
<p>What should happen is agent move to the "queue", wait for its turn to go to <em>Dryer</em>. How I can achieve that?</p>
<p><strong>My approach</strong></p>
<p><strong>1. MoveTo</strong></p>
<p><a href="https://i.stack.imgur.com/23org.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/23org.png" alt="enter image description here" /></a></p>
<p><strong>2. Queue</strong></p>
<p><a href="https://i.stack.imgur.com/IJO7d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IJO7d.png" alt="enter image description here" /></a></p>
<p><strong>3. Delay</strong></p>
<p><a href="https://i.stack.imgur.com/HEktm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HEktm.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74330297,
"author": "Yossi Benagou",
"author_id": 18366972,
"author_profile": "https://Stackoverflow.com/users/18366972",
"pm_score": 0,
"selected": false,
"text": "Node"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16779211/"
] |
74,319,816 | <p>Consider this program:</p>
<pre><code>#include <stdio.h>
int main()
{
int a;
a = 16;
printf("This is the first line
this is the second line
");
}
</code></pre>
<hr />
<p>Why does this program throw error? Why can't it compile successfully and show the output as:</p>
<pre><code>
This is the first line
this is the second line
|
</code></pre>
<p>the symbol '|' here denotes blinking cursor, which is to show that the cursor moved to next, implying that after the "second line" a '\n' character as appeared in STDOUT.</p>
<pre><code> .
</code></pre>
| [
{
"answer_id": 74319935,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 4,
"selected": true,
"text": "\\"
},
{
"answer_id": 74320171,
"author": "Ian Abbott",
"author_id": 5264491,
"author_profile": "https://Stackoverflow.com/users/5264491",
"pm_score": 1,
"selected": false,
"text": "\\"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20333834/"
] |
74,319,829 | <p>I am new to PulP. Below is the optimization problem.</p>
<p>Consider x11, x12, x13 be units of FG1 to be loaded on Medium Truck 1, Small Truck and Medium Truck 2 respectively. Similarly, consider x21,x22,x23 be variables to denote units of FG2 to be loaded on Medium Truck 1, Small Truck and Medium Truck 2 respectively.</p>
<p>The objective here is to distribute both products total qty = 2011 (FG1 = 900, FG2 = 1111) in 2 Medium Trucks and 1 Small Truck. There are some constraints wrt to area, volume and weights which are mentioned.</p>
<p>There is an additional constraint that if FG1 has to be loaded in any of the trucks, minimum qty should be 60 if not 0. Means either load more than or equal to 60 or 0. I am not able to figure out how to model such constraint. Please suggest.</p>
<h4>Current code:</h4>
<pre><code>from pulp import LpMinimize, LpProblem, LpStatus, lpSum, LpVariable
solver = pl.GLPK_CMD()
model = LpProblem(name="load_receipts", sense=LpMinimize)
x11 = LpVariable(name="x11", lowBound=0, cat='Continuous')
x12 = LpVariable(name="x12", lowBound=0, cat='Continuous')
x13 = LpVariable(name="x13", lowBound=0, cat='Continuous')
x21 = LpVariable(name="x21", lowBound=0, cat='Continuous')
x22 = LpVariable(name="x22", lowBound=0, cat='Continuous')
x23 = LpVariable(name="x23", lowBound=0, cat='Continuous')
model += (0.5*x11 + 0.333333*x21 <= 400)
model += (0.5*x12 + 0.333333*x22 <= 200)
model += (0.5*x13 + 0.333333*x23 <= 400)
model += (0.25*x11 + 0.142857*x21 <= 200)
model += (0.25*x12 + 0.142857*x22 <= 100)
model += (0.25*x13 + 0.142857*x23 <= 200)
model += (0.001*x11 + 0.000125*x21 <= 50)
model += (0.001*x12 + 0.000125*x22 <= 25)
model += (0.001*x13 + 0.000125*x23 <= 50)
model += (x11 + x12 + x13 + x21 + x22 + x23 - 2011 == 0)
model += (x11 + x12 + x13 == 900)
model += (x21 + x22 + x23 == 1111)
model += x11 + x12 + x13 + x21 + x22 + x23-2011
status = model.solve(solver)
print(f"status: {model.status}, {LpStatus[model.status]}")
for var in model.variables():
print(f"{var.name}: {var.value()}")
</code></pre>
| [
{
"answer_id": 74319935,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 4,
"selected": true,
"text": "\\"
},
{
"answer_id": 74320171,
"author": "Ian Abbott",
"author_id": 5264491,
"author_profile": "https://Stackoverflow.com/users/5264491",
"pm_score": 1,
"selected": false,
"text": "\\"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14577651/"
] |
74,319,834 | <p>I'm trying to make a loop that will print a message if the window size is too small while waiting for the user to press enter. Once the user presses enter, I want it to check again if the console window is big enough before it exits the loop</p>
<pre><code>{
WriteLine("The current terminal size is to small to show the race track.");
WriteLine("Please resize the window to atleast 64 character wide and 12 lines high.");
WriteLine("Please press [enter] to continue");
ReadLine();
}
</code></pre>
| [
{
"answer_id": 74319935,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 4,
"selected": true,
"text": "\\"
},
{
"answer_id": 74320171,
"author": "Ian Abbott",
"author_id": 5264491,
"author_profile": "https://Stackoverflow.com/users/5264491",
"pm_score": 1,
"selected": false,
"text": "\\"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419145/"
] |
74,319,843 | <p>When I clear the Text of the ComboBox or click again, the selected item is still not canceled.</p>
<pre class="lang-xml prettyprint-override"><code><ComboBox
MinWidth="120"
IsEditable="True"
PlaceholderText="please select">
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
</ComboBox>
</code></pre>
| [
{
"answer_id": 74319935,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 4,
"selected": true,
"text": "\\"
},
{
"answer_id": 74320171,
"author": "Ian Abbott",
"author_id": 5264491,
"author_profile": "https://Stackoverflow.com/users/5264491",
"pm_score": 1,
"selected": false,
"text": "\\"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20375410/"
] |
74,319,852 | <p>I have the following statement on my code to create a slider:</p>
<p><code>[sg.Text('SPI Frequency [MHz]: '),sg.Slider((0.50,2.50),1.250,0.750,size=(80,15),orientation='h',key='FREQ_SLIDER',enable_events=True,tick_interval=0.75)]</code></p>
<p>However, my final resolution is not of 0.75 but it is rounded. Instead, I have the following slider:
<a href="https://i.stack.imgur.com/nQeBj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nQeBj.png" alt="Slider" /></a></p>
<p>Why I can't get a resolution of 0.75 on my slider?</p>
<p>How I could do it?</p>
<p>Thanks
Jorge</p>
<p>I would like to have a slider with a resolution of 0.75 for each tick</p>
| [
{
"answer_id": 74370123,
"author": "MrMattBusby",
"author_id": 8507777,
"author_profile": "https://Stackoverflow.com/users/8507777",
"pm_score": 1,
"selected": false,
"text": "."
},
{
"answer_id": 74441720,
"author": "Joshua",
"author_id": 17608766,
"author_profile": "https://Stackoverflow.com/users/17608766",
"pm_score": 0,
"selected": false,
"text": "tkscale = element.Widget = tk.Scale(tk_row_frame,orient=element.Orientation,variable=element.TKIntVar,from_=range_from, to_=range_to,resolution=element.Resolution,length=slider_length, width=slider_width,bd=element.BorderWidth, relief=element.Relief, font=font,tickinterval=element.TickInterval)\n"
},
{
"answer_id": 74445081,
"author": "Jason Yang",
"author_id": 11936135,
"author_profile": "https://Stackoverflow.com/users/11936135",
"pm_score": 2,
"selected": true,
"text": "digits"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15852840/"
] |
74,319,859 | <p>If i have 2 dataframe, let's say dfA like this:</p>
<pre><code> hour distance short_summary
1 5 2.02 Overcast
2 7 1.16 Overcast
3 3 1.35 Partly Cloudy
4 12 1.17 Overcast
5 22 1.80 Overcast
6 9 1.72 Partly Cloudy
7 18 1.09 Partly Cloudy
</code></pre>
<p>and dfB like this:</p>
<pre><code> price
1 22.5
3 8.5
5 14.0
6 7.0
7 9.5
</code></pre>
<p>How do i remove the rows in dfA that have index which doesn't exist in dfB?
The final dfA should look like this:</p>
<pre><code> hour distance short_summary
1 5 2.02 Overcast
3 3 1.35 Partly Cloudy
5 22 1.80 Overcast
6 9 1.72 Partly Cloudy
7 18 1.09 Partly Cloudy
</code></pre>
| [
{
"answer_id": 74370123,
"author": "MrMattBusby",
"author_id": 8507777,
"author_profile": "https://Stackoverflow.com/users/8507777",
"pm_score": 1,
"selected": false,
"text": "."
},
{
"answer_id": 74441720,
"author": "Joshua",
"author_id": 17608766,
"author_profile": "https://Stackoverflow.com/users/17608766",
"pm_score": 0,
"selected": false,
"text": "tkscale = element.Widget = tk.Scale(tk_row_frame,orient=element.Orientation,variable=element.TKIntVar,from_=range_from, to_=range_to,resolution=element.Resolution,length=slider_length, width=slider_width,bd=element.BorderWidth, relief=element.Relief, font=font,tickinterval=element.TickInterval)\n"
},
{
"answer_id": 74445081,
"author": "Jason Yang",
"author_id": 11936135,
"author_profile": "https://Stackoverflow.com/users/11936135",
"pm_score": 2,
"selected": true,
"text": "digits"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20228780/"
] |
74,319,862 | <p>Model in Turing.jl seems to be stuck in errors with</p>
<pre><code>Warning: The current proposal will be rejected due to numerical error(s).
│ isfinite.((θ, r, ℓπ, ℓκ)) = (true, false, false, false)
</code></pre>
<p>for <code>NUTS()</code>, <code>HMCDA()</code> and sometimes <code>HMC()</code> sampling methods. I don't really understand what's causing these errors (what's <code>θ</code>?), but it makes NUTS and HMCDA unusable as sampling methods while HMC has around 2/3 of samples rejected. I looked at similar questions on here and on the forums, but no one seems to have a fix for this so far.</p>
| [
{
"answer_id": 74370123,
"author": "MrMattBusby",
"author_id": 8507777,
"author_profile": "https://Stackoverflow.com/users/8507777",
"pm_score": 1,
"selected": false,
"text": "."
},
{
"answer_id": 74441720,
"author": "Joshua",
"author_id": 17608766,
"author_profile": "https://Stackoverflow.com/users/17608766",
"pm_score": 0,
"selected": false,
"text": "tkscale = element.Widget = tk.Scale(tk_row_frame,orient=element.Orientation,variable=element.TKIntVar,from_=range_from, to_=range_to,resolution=element.Resolution,length=slider_length, width=slider_width,bd=element.BorderWidth, relief=element.Relief, font=font,tickinterval=element.TickInterval)\n"
},
{
"answer_id": 74445081,
"author": "Jason Yang",
"author_id": 11936135,
"author_profile": "https://Stackoverflow.com/users/11936135",
"pm_score": 2,
"selected": true,
"text": "digits"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18335909/"
] |
74,319,898 | <p>Well, hello, i've a doubt. The question is how i can open <strong>whatsapp desktop</strong> from a <code>button</code> in <code>VB6</code> in a <strong>specific number with a message</strong>. For example in <code>C#</code> i can do that with the property <code>Process</code>:</p>
<pre><code>var process = $"whatsapp://send?phone=54123456789&text=hello!!";
Process.Start(process);
</code></pre>
<p>But in <code>vb6</code> i don't have idea how i can do it 'cause the method can be:</p>
<pre><code>Shell "C://path_to_whatsapp_installed/whatsapp.exe"
</code></pre>
<p>But with that i can't open in a specific chat</p>
| [
{
"answer_id": 74355580,
"author": "Ehab",
"author_id": 20342736,
"author_profile": "https://Stackoverflow.com/users/20342736",
"pm_score": 3,
"selected": true,
"text": "ShellExecute"
},
{
"answer_id": 74359540,
"author": "Hel O'Ween",
"author_id": 6626183,
"author_profile": "https://Stackoverflow.com/users/6626183",
"pm_score": 1,
"selected": false,
"text": "Private Const SW_HIDE As Long = 0\nPrivate Const SW_SHOWNORMAL As Long = 1\nPrivate Const SW_SHOWMINIMIZED As Long = 2\nPrivate Const SW_SHOWMAXIMIZED As Long = 3\nPrivate Const SW_SHOWNOACTIVATE As Long = 4\nPrivate Const SW_SHOW As Long = 5\nPrivate Const SW_MINIMIZE As Long = 6\nPrivate Const SW_SHOWMINNOACTIVE As Long = 7\nPrivate Const SW_SHOWNA As Long = 8\nPrivate Const SW_RESTORE As Long = 9\nPrivate Const SW_SHOWDEFAULT As Long = 10\nPrivate Const SW_FORCEMINIMIZE As Long = 11\n\n' ShellOpenDocument verbs\n\nPublic Enum ShellExecuteVerbs\n sevNULL\n sevEdit\n sevExplore\n sevFind\n sevOpen\n sevPrint\n sevRunAs\nEnd Enum\n\nPrivate Declare Function ShellExecute Lib \"shell32.dll\" Alias \"ShellExecuteA\" ( _\n ByVal hWnd As Long, _\n ByVal lpOperation As String, _\n ByVal lpFile As String, _\n ByVal lpParameters As String, _\n ByVal lpDirectory As String, _\n ByVal nShowCmd As Long _\n ) As Long\n\n'------------------------------------------------------------------------------\n'Purpose : Opens a document with the registered application for this file type\n'\n'Prereq. : -\n'Parameter: sFileName - Fully qualified filename\n' eShellVerb - The action the associated application should do with documentName\n' lWindowState - Window state and/or focus of the associated application\n' hWndParent - Parent window handle\n' sWorkingDirectory - Working directory\n'Returns : > 32 = Success\n'Note : See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea\n' for possible error codes <= 32\n'------------------------------------------------------------------------------\nPublic Function ShellOpenDocument( _\n ByVal sFileName As String, _\n Optional ByVal eShellVerb As ShellExecuteVerbs = sevOpen, _\n Optional ByVal lWindowState As Long = SW_SHOWNORMAL, _\n Optional ByVal hWndParent As Long = 0, _\n Optional ByVal sWorkingDirectory As String = vbNullString _\n ) As Long\n \n Dim sVerb As String\n \n Select Case eShellVerb\n\n Case ShellExecuteVerbs.sevNULL\n sVerb = vbNull\n Case ShellExecuteVerbs.sevEdit\n sVerb = \"edit\"\n Case ShellExecuteVerbs.sevExplore\n sVerb = \"explore\"\n Case ShellExecuteVerbs.sevFind\n sVerb = \"find\"\n Case ShellExecuteVerbs.sevOpen\n sVerb = \"open\"\n Case ShellExecuteVerbs.sevPrint\n sVerb = \"print\"\n Case ShellExecuteVerbs.sevRunAs\n sVerb = \"runas\"\n Case Else\n sVerb = vbNull\n End Select\n \n If Len(sWorkingDirectory) < 1 Then\n sWorkingDirectory = App.Path\n End If\n \n ShellOpenDocument = ShellExecute(hWndParent, _\n sVerb, _\n sFileName, _\n vbNullString, _\n sWorkingDirectory, _\n lWindowState)\n\nEnd Function\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,319,900 | <p>However when i move my css code back into the body in the html file (not using href="") the edits like padding, and color got applies to the frontend, here is my css code.</p>
<pre><code><style>
.subscribe-button {
background-color: rgb(204, 0, 0);
color:white;
border: none;
padding-top: 10px;
padding-left: 16px;
padding-right: 16px;
padding-bottom: 10px;
border-radius: 2px;
cursor: pointer;
margin-right: 5px;
margin-left: 10px;
transition: opacity 0.15s;
vertical-align: top;}
</style>
</code></pre>
| [
{
"answer_id": 74355580,
"author": "Ehab",
"author_id": 20342736,
"author_profile": "https://Stackoverflow.com/users/20342736",
"pm_score": 3,
"selected": true,
"text": "ShellExecute"
},
{
"answer_id": 74359540,
"author": "Hel O'Ween",
"author_id": 6626183,
"author_profile": "https://Stackoverflow.com/users/6626183",
"pm_score": 1,
"selected": false,
"text": "Private Const SW_HIDE As Long = 0\nPrivate Const SW_SHOWNORMAL As Long = 1\nPrivate Const SW_SHOWMINIMIZED As Long = 2\nPrivate Const SW_SHOWMAXIMIZED As Long = 3\nPrivate Const SW_SHOWNOACTIVATE As Long = 4\nPrivate Const SW_SHOW As Long = 5\nPrivate Const SW_MINIMIZE As Long = 6\nPrivate Const SW_SHOWMINNOACTIVE As Long = 7\nPrivate Const SW_SHOWNA As Long = 8\nPrivate Const SW_RESTORE As Long = 9\nPrivate Const SW_SHOWDEFAULT As Long = 10\nPrivate Const SW_FORCEMINIMIZE As Long = 11\n\n' ShellOpenDocument verbs\n\nPublic Enum ShellExecuteVerbs\n sevNULL\n sevEdit\n sevExplore\n sevFind\n sevOpen\n sevPrint\n sevRunAs\nEnd Enum\n\nPrivate Declare Function ShellExecute Lib \"shell32.dll\" Alias \"ShellExecuteA\" ( _\n ByVal hWnd As Long, _\n ByVal lpOperation As String, _\n ByVal lpFile As String, _\n ByVal lpParameters As String, _\n ByVal lpDirectory As String, _\n ByVal nShowCmd As Long _\n ) As Long\n\n'------------------------------------------------------------------------------\n'Purpose : Opens a document with the registered application for this file type\n'\n'Prereq. : -\n'Parameter: sFileName - Fully qualified filename\n' eShellVerb - The action the associated application should do with documentName\n' lWindowState - Window state and/or focus of the associated application\n' hWndParent - Parent window handle\n' sWorkingDirectory - Working directory\n'Returns : > 32 = Success\n'Note : See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea\n' for possible error codes <= 32\n'------------------------------------------------------------------------------\nPublic Function ShellOpenDocument( _\n ByVal sFileName As String, _\n Optional ByVal eShellVerb As ShellExecuteVerbs = sevOpen, _\n Optional ByVal lWindowState As Long = SW_SHOWNORMAL, _\n Optional ByVal hWndParent As Long = 0, _\n Optional ByVal sWorkingDirectory As String = vbNullString _\n ) As Long\n \n Dim sVerb As String\n \n Select Case eShellVerb\n\n Case ShellExecuteVerbs.sevNULL\n sVerb = vbNull\n Case ShellExecuteVerbs.sevEdit\n sVerb = \"edit\"\n Case ShellExecuteVerbs.sevExplore\n sVerb = \"explore\"\n Case ShellExecuteVerbs.sevFind\n sVerb = \"find\"\n Case ShellExecuteVerbs.sevOpen\n sVerb = \"open\"\n Case ShellExecuteVerbs.sevPrint\n sVerb = \"print\"\n Case ShellExecuteVerbs.sevRunAs\n sVerb = \"runas\"\n Case Else\n sVerb = vbNull\n End Select\n \n If Len(sWorkingDirectory) < 1 Then\n sWorkingDirectory = App.Path\n End If\n \n ShellOpenDocument = ShellExecute(hWndParent, _\n sVerb, _\n sFileName, _\n vbNullString, _\n sWorkingDirectory, _\n lWindowState)\n\nEnd Function\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319900",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17810556/"
] |
74,319,909 | <p>There is an existing value <code>a</code>, and I want to get a reference to either <code>a</code> or a new value <code>b</code> created on demand, depending on some condition. The code below won't compile. I would like to know what is the idiomatic way of doing so in Rust.</p>
<pre><code>fn main() {
let condition = false;
let a: String = "a".to_string();
let r: &String = if condition {
&a
} else {
let b: String = "b".to_string();
&b
};
}
</code></pre>
<p>New example (in response to <a href="https://stackoverflow.com/a/74320059/20312298">@PitaJ</a>):</p>
<pre><code>struct S(i32);
fn main() {
let condition = false;
let a: S = S(0);
let r: &S = if condition {
&a
} else {
let b: S = S(1);
&b
};
}
</code></pre>
| [
{
"answer_id": 74320059,
"author": "PitaJ",
"author_id": 847382,
"author_profile": "https://Stackoverflow.com/users/847382",
"pm_score": 3,
"selected": true,
"text": "Cow"
},
{
"answer_id": 74324745,
"author": "fred xia",
"author_id": 16323026,
"author_profile": "https://Stackoverflow.com/users/16323026",
"pm_score": 0,
"selected": false,
"text": "#include <string>\n\nint main()\n{\n auto condition = false;\n std::string a(\"a\");\n const std::string* ptr;\n if (condition) {\n ptr = &a;\n } else {\n std::string b(\"b\");\n ptr = &b;\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20312298/"
] |
74,319,910 | <p>I have a custom Required if that works fine. I then needed a Ranged If - Required if another item was a certain value, and it needs to be within a range. this does work - but does not throw the error under the box. I assume due to "return new ValidationResult". is there a way to just throw error in custom attributes that I'm missing that will link back to the text box?</p>
<p>Ranged if reads like this: Value I want to look at, the value I want to make it require, min and max values for the range.</p>
<pre><code>public string IsMonetized { get; set; }
// [RequiredIf("IsMonetized", "Yes", "Please Enter a Value")]
// [Range(1, double.MaxValue, ErrorMessage = "Please Enter an Amount greater than 0")]
[RangedIf("IsMonetized", "Yes", 1, 200)]
public double MaxAmount { get; set; }
//[Range(1, 200, ErrorMessage = "Please Enter an Amount greater than 0")]
[RangedIf("IsMonetized", "Yes", 1, 200)]
public double? AnnualAmount { get; set; }
</code></pre>
<pre><code>public class RangedIfAttribute : RequiredAttribute
{
private String PropertyName { get; set; }
private Object DesiredValue { get; set; }
private double max { get; set; }
private double min { get; set; }
public RangedIfAttribute(String propertyName, Object desiredvalue, double Min, double Max)
{
PropertyName = propertyName;
DesiredValue = desiredvalue;
min = Min;
max = Max;
}
public RangedIfAttribute(String propertyName, Object desiredvalue, double Min, double Max, String Errormessage)
{
PropertyName = propertyName;
DesiredValue = desiredvalue;
ErrorMessage = Errormessage;
min = Min;
max = Max;
}
protected override ValidationResult IsValid(object value, ValidationContext context)
{
Object instance = context.ObjectInstance;
Type type = instance.GetType();
Object proprtyvalue = type.GetProperty(PropertyName).GetValue(instance, null);
try
{
if (proprtyvalue == null)
{
if (DesiredValue == null)
{
if (min <= (double)value && (double)value <= max)
{
return base.IsValid(value, context); // Null was intended , and value in range - Valid
}
}
}
else if (proprtyvalue.ToString().Equals(DesiredValue))
{
if (min <= (double)value && (double)value <= max)
{
return base.IsValid(value, context); // desired = property value, and value in range - Valid
}
}
// This should submit Not Valid
return new ValidationResult(this.FormatErrorMessage(context.DisplayName));
}
catch
{
// this should submit not valid - the required item is null
return new ValidationResult($"Value must be within the range of {min} and {max}");
}
}
}
</code></pre>
<p>I have tried looking through all of the custom attributes information I can find and it seems nothing is coming up useful. the Validate.Success can send a successful validation, but it seems there is no Auto Failure (Validate.Failure). seems like an over site to the attribute system.</p>
<p>The boxes on both do nothing right away - and are not flagged - but a validation summary at the bottom will read:</p>
<p>The MaxAmount field is required. - Max Amount Field falls to the bottom with not matching the correct if logic.</p>
<p>Value must be within the range of 1 and 200 - annual amount will hit the try/catch since it was null and throws an error.</p>
<p>Again - it stops the form from submitting, but there is no indication what box (normally highlights red when validation fails) fails to validate.</p>
| [
{
"answer_id": 74320059,
"author": "PitaJ",
"author_id": 847382,
"author_profile": "https://Stackoverflow.com/users/847382",
"pm_score": 3,
"selected": true,
"text": "Cow"
},
{
"answer_id": 74324745,
"author": "fred xia",
"author_id": 16323026,
"author_profile": "https://Stackoverflow.com/users/16323026",
"pm_score": 0,
"selected": false,
"text": "#include <string>\n\nint main()\n{\n auto condition = false;\n std::string a(\"a\");\n const std::string* ptr;\n if (condition) {\n ptr = &a;\n } else {\n std::string b(\"b\");\n ptr = &b;\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20090914/"
] |
74,319,921 | <pre><code>const face = document.querySelector('.face');
const con = document.querySelector('.con');
for (let i = 0; i < face.length; i++){
con.addEventListener("click" , () => {
face[i].style.transform = "translateZ(600px)";
});
}
</code></pre>
<p>I wanted to change a CSS property as you see in the code. But even though the con element is being clicked, no action is happening. The event I have written for con for the action click not running.
Actually there are five face elements in that con element in HTML code.</p>
| [
{
"answer_id": 74320059,
"author": "PitaJ",
"author_id": 847382,
"author_profile": "https://Stackoverflow.com/users/847382",
"pm_score": 3,
"selected": true,
"text": "Cow"
},
{
"answer_id": 74324745,
"author": "fred xia",
"author_id": 16323026,
"author_profile": "https://Stackoverflow.com/users/16323026",
"pm_score": 0,
"selected": false,
"text": "#include <string>\n\nint main()\n{\n auto condition = false;\n std::string a(\"a\");\n const std::string* ptr;\n if (condition) {\n ptr = &a;\n } else {\n std::string b(\"b\");\n ptr = &b;\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419119/"
] |
74,319,955 | <p>I need to add a script which will delete files from directory before installation of new version. I need save from directory one catalog - /logs and all files inside ( inside we have *.log and *.zg files)</p>
<p>Ive created this line : <code>find /directory/path/* ! -name 'logs' -type d,f -exec rm -r -v {} + </code>
But in Debian 11 Its cleaning also my files inside of catalog log.
Do you know what can be a reason ?</p>
<p>It works on zsh on macbook m1 and is not cleaning my log catalog.</p>
<p>Take Care : )</p>
<p>Expectation
bash script which delete all catalogs and files from given directory EXCEPT one catalog /log and all files inside ( inside we have *.log and *.zg files) .</p>
| [
{
"answer_id": 74322778,
"author": "William Pursell",
"author_id": 140750,
"author_profile": "https://Stackoverflow.com/users/140750",
"pm_score": 2,
"selected": false,
"text": "$ find . ! -name logs\n.\n./logs/a\n./foo\n./foo/a\n"
},
{
"answer_id": 74330848,
"author": "Paul Hodges",
"author_id": 8656552,
"author_profile": "https://Stackoverflow.com/users/8656552",
"pm_score": 0,
"selected": false,
"text": "shopt -s extglob\nrm -frv /directory/path/!(logs)\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20418343/"
] |
74,319,973 | <p>Best explained with an example:</p>
<p><a href="https://i.stack.imgur.com/JZv97.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JZv97.png" alt="enter image description here" /></a></p>
<p>I want to search the blue range and check if any of the cells contain any of the strings in the green range.</p>
<p>Ideally non-case-sensitive, and the search string could appear anywhere within the searched cells.</p>
| [
{
"answer_id": 74320051,
"author": "Argyll",
"author_id": 3181104,
"author_profile": "https://Stackoverflow.com/users/3181104",
"pm_score": 1,
"selected": false,
"text": "=arrayformula(sum(if(regexmatch(textjoin(\",\",false,\",\",A1:A10,\",\"),\",\"&B1:B3&\",\"),1,0)))>0\n"
},
{
"answer_id": 74320851,
"author": "ztiaa",
"author_id": 17887301,
"author_profile": "https://Stackoverflow.com/users/17887301",
"pm_score": 1,
"selected": false,
"text": "=ARRAYFORMULA(IF(BYROW(A5:C,LAMBDA(r,SUM(LEN(r))))=0,,BYROW(REGEXMATCH(A5:C,\"\\b\"&TEXTJOIN(\"\\b|\\b\",1,E1:E)&\"\\b\"),LAMBDA(r,SUM(--r)>0))))"
},
{
"answer_id": 74321609,
"author": "player0",
"author_id": 5632629,
"author_profile": "https://Stackoverflow.com/users/5632629",
"pm_score": 0,
"selected": false,
"text": "=INDEX(REGEXMATCH(FLATTEN(QUERY(TRANSPOSE(A5:C7),,9^9)), \n \"(?i)\\b\"&TEXTJOIN(\"|\", 1, E1:E)&\"\\b\"))\n"
},
{
"answer_id": 74329256,
"author": "Ping",
"author_id": 20288037,
"author_profile": "https://Stackoverflow.com/users/20288037",
"pm_score": 1,
"selected": false,
"text": "=BYROW(A5:C7,LAMBDA(ROW,REGEXMATCH(JOIN(\" \",ROW),JOIN(\"|\",$E$1:$E$3))))\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74319973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1166371/"
] |
74,320,021 | <p>first time using OAuth here and I am stuck. I am building a web app that needs to make authorized calls to the YouTube Data API. I am testing the OAuth flow from my local computer.</p>
<p>I am stuck receiving <code>Error 400: redirect_uri_mismatch</code> when I try to run my Google OAuth flow in Python. The error occurs when I access the link generated by <code>flow.run_console()</code></p>
<p>Here is my code:</p>
<pre><code>os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
client_secrets_file="./client_secret.json"
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
flow.redirect_uri = "http://127.0.0.1:8080" # Authorized in my client ID
credentials = flow.run_console()
</code></pre>
<p>This code returns the message:</p>
<pre><code>Please visit this URL to authorize this application: ***google oauth url ***
Enter the authorization code:
</code></pre>
<p>Visiting the link results in the following error:
<a href="https://i.stack.imgur.com/xKyy8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xKyy8.png" alt="URI mismatch error" /></a></p>
<p>I tried setting the Authorized Redirect URI in my OAuth Client ID to <code>http://127.0.0.1:8080</code> since I am testing from my local machine. I also set <code>flow.redirect_uri</code> to <code>http://127.0.0.1:8080</code> in Python. Using <code>http://127.0.0.1:8080</code> is currently my only option since the front end has not been set up yet.</p>
<p>I expected the code to authorize my request, since the Authorized URI matches the <code>redirect_uri</code>. But I am still receiving the error.</p>
<p>I have had no issues running the flow from Google's OAuth Playground, if that means anything.</p>
<p>Any help is appreciated, thank you.</p>
| [
{
"answer_id": 74320051,
"author": "Argyll",
"author_id": 3181104,
"author_profile": "https://Stackoverflow.com/users/3181104",
"pm_score": 1,
"selected": false,
"text": "=arrayformula(sum(if(regexmatch(textjoin(\",\",false,\",\",A1:A10,\",\"),\",\"&B1:B3&\",\"),1,0)))>0\n"
},
{
"answer_id": 74320851,
"author": "ztiaa",
"author_id": 17887301,
"author_profile": "https://Stackoverflow.com/users/17887301",
"pm_score": 1,
"selected": false,
"text": "=ARRAYFORMULA(IF(BYROW(A5:C,LAMBDA(r,SUM(LEN(r))))=0,,BYROW(REGEXMATCH(A5:C,\"\\b\"&TEXTJOIN(\"\\b|\\b\",1,E1:E)&\"\\b\"),LAMBDA(r,SUM(--r)>0))))"
},
{
"answer_id": 74321609,
"author": "player0",
"author_id": 5632629,
"author_profile": "https://Stackoverflow.com/users/5632629",
"pm_score": 0,
"selected": false,
"text": "=INDEX(REGEXMATCH(FLATTEN(QUERY(TRANSPOSE(A5:C7),,9^9)), \n \"(?i)\\b\"&TEXTJOIN(\"|\", 1, E1:E)&\"\\b\"))\n"
},
{
"answer_id": 74329256,
"author": "Ping",
"author_id": 20288037,
"author_profile": "https://Stackoverflow.com/users/20288037",
"pm_score": 1,
"selected": false,
"text": "=BYROW(A5:C7,LAMBDA(ROW,REGEXMATCH(JOIN(\" \",ROW),JOIN(\"|\",$E$1:$E$3))))\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19968680/"
] |
74,320,031 | <p>I have created an API from Database, I can view the API but I am unable to do a query via URL for example: <code>127.0.0.1:8000/author?author_id=9</code>, I am not sure where to add the query code. I want to filter using fields. Here is my <code>models.py</code></p>
<pre><code>class AuthorAPI(models.Model):
author_id=models.IntegerField()
name=models.TextField()
author_img_url=models.TextField()
title=models.TextField()
first_published_at=models.DateTimeField()
excerpt=models.TextField()
class Meta:
db_table = 'view_author'
</code></pre>
<p><code>serializers.py</code></p>
<pre><code>from rest_framework import serializers
from .models import SortAPI, AuthorAPI
class AuthorAPISerializer(serializers.ModelSerializer):
class Meta:
model=AuthorAPI
fields='__all__'
</code></pre>
<p><code>views.py</code></p>
<pre><code>from .serializers import APISerializer,AuthorAPISerializer
from .models import SortAPI, AuthorAPI
from rest_framework.response import Response
from rest_framework.decorators import api_view
@api_view(['GET'])
def getauthor(request):
if request.method == 'GET':
results = AuthorAPI.objects.all()
serialize = AuthorAPISerializer(results, many=True)
return Response(serialize.data)
</code></pre>
| [
{
"answer_id": 74320138,
"author": "Swift",
"author_id": 8874154,
"author_profile": "https://Stackoverflow.com/users/8874154",
"pm_score": 2,
"selected": false,
"text": "ModelViewset"
},
{
"answer_id": 74320272,
"author": "Sumithran",
"author_id": 6562458,
"author_profile": "https://Stackoverflow.com/users/6562458",
"pm_score": 1,
"selected": false,
"text": "@api_view(['GET'])\ndef getauthor(request):\n if request.method == 'GET':\n\n results = AuthorAPI.objects.all()\n\n # get author_id from the url query parameter\n author_id = request.GET.get('author_id', None)\n \n #if author_id is present in the url query parameter then filter the resluts queryset based on the author_id\n if author_id:\n results = results.filter(author_id=author_id)\n\n serialize = AuthorAPISerializer(results, many=True)\n return Response(serialize.data)\n"
},
{
"answer_id": 74334374,
"author": "Mohammad Fathi Rahman",
"author_id": 18411353,
"author_profile": "https://Stackoverflow.com/users/18411353",
"pm_score": 2,
"selected": true,
"text": "viewsets.ReadOnlyModelViewset"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18411353/"
] |
74,320,040 | <p>I'm struggling to understand how <code>livewire</code> works.</p>
<p>I have two text fields. One is where the user enters information like prefixes and the second field with a <code>read-only</code> attribute where data will be displayed based on the first field value.
But for some reason, I can't populate the second field. All examples on the internet are how to take a value and return it back or generate a dropdown menu.</p>
<p>my <code>blade</code> template:</p>
<pre><code><div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">prefix</label>
<input wire:change="testing"
type="text"
class="form-control"
id="prefix"
name="prefix"
/>
</div>
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Code</label>
<input wire:model="part"
type="text"
class="form-control"
id="part"
name="part"
value="{{ $part }}"
/>
</div>
</code></pre>
<p>and
<code>Livewire</code> <code>class</code>:</p>
<pre><code>class DoSomethingClass extends Component
{
public $prefix;
public $part;
public function testing()
{
$this->part = $this->prefix;
}
public function render()
{
return view('livewire.blade-template');
}
}
</code></pre>
| [
{
"answer_id": 74320138,
"author": "Swift",
"author_id": 8874154,
"author_profile": "https://Stackoverflow.com/users/8874154",
"pm_score": 2,
"selected": false,
"text": "ModelViewset"
},
{
"answer_id": 74320272,
"author": "Sumithran",
"author_id": 6562458,
"author_profile": "https://Stackoverflow.com/users/6562458",
"pm_score": 1,
"selected": false,
"text": "@api_view(['GET'])\ndef getauthor(request):\n if request.method == 'GET':\n\n results = AuthorAPI.objects.all()\n\n # get author_id from the url query parameter\n author_id = request.GET.get('author_id', None)\n \n #if author_id is present in the url query parameter then filter the resluts queryset based on the author_id\n if author_id:\n results = results.filter(author_id=author_id)\n\n serialize = AuthorAPISerializer(results, many=True)\n return Response(serialize.data)\n"
},
{
"answer_id": 74334374,
"author": "Mohammad Fathi Rahman",
"author_id": 18411353,
"author_profile": "https://Stackoverflow.com/users/18411353",
"pm_score": 2,
"selected": true,
"text": "viewsets.ReadOnlyModelViewset"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3747585/"
] |
74,320,054 | <p>I'm facing with an issue in the comment section of the app i'm working on (Instagram based). I have created a comment setion with a like button (that changes colours when the uid of the user is present in the DB) and I'd like to give the possibility to users to use it and save the data on FirebaseFirestore. I have created a subcollection "comments" from my "posts" collection.</p>
<p>Now when I link the code to the IconButton, I get this error:</p>
<p>W/Firestore(12560): (24.3.1) [WriteStream]: (607b719) Stream closed with status: Status{code=NOT_FOUND, description=No document to update: projects/gestigram-tut/databases/(default)/documents/comments/2a1d8040-5c57-11ed-80e6-2b7d542041dc, cause=null}.
I/flutter (12560): [cloud_firestore/not-found] Some requested document was not found.</p>
<p>As you can see in the code below the doc exist.</p>
<p>If I try to put the uid on Firebase in the commentLikes document, the IconButton Like/dislike change colour.</p>
<p>Can somebody help me figure out where is the issue? Thanks in advance.</p>
<p>Cheers.
Q</p>
<pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:gestigram/models/comment.dart';
import 'package:gestigram/models/post.dart';
import 'package:gestigram/ressources/storage_methods.dart';
import 'package:uuid/uuid.dart';
import 'package:image_picker/image_picker.dart';
class FirestoreMethods {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
Future<String> uploadPost(
String description,
Uint8List file,
String uid,
String username,
String profImage,
) async {
String res = "Some error occured";
try {
String photoUrl =
await StorageMethods().uploadImageToStorage('posts', file, true);
String postId = const Uuid().v1();
Post post = Post(
description: description,
uid: uid,
username: username,
postId: postId,
datePublished: DateTime.now(),
postUrl: photoUrl,
profImage: profImage,
likes: [],
);
_firestore.collection('posts').doc(postId).set(
post.toJson(),
);
res = 'success';
} catch (err) {
res = err.toString();
}
return res;
}
Future<String> uploadVideoPost(
String description,
Uint8List file,
String uid,
String username,
String profImage,
) async {
String res = "Some error occured";
try {
String photoUrl =
await StorageMethods().uploadVideoToStorage('posts', file, true);
String postId = const Uuid().v1();
Post post = Post(
description: description,
uid: uid,
username: username,
postId: postId,
datePublished: DateTime.now(),
postUrl: photoUrl,
profImage: profImage,
likes: [],
);
_firestore.collection('posts').doc(postId).set(
post.toJson(),
);
res = 'success';
} catch (err) {
res = err.toString();
}
return res;
}
Future<void> likePost(String postId, String uid, List likes) async {
try {
if (likes.contains(uid)) {
await _firestore.collection('posts').doc(postId).update({
'likes': FieldValue.arrayRemove([uid]),
});
} else {
await _firestore.collection('posts').doc(postId).update({
'likes': FieldValue.arrayUnion([uid]),
});
}
} catch (e) {
print(
e.toString(),
);
}
}
// post comment
Future<void> postComment(String postId, String text, String uid, String name,
String profilePic) async {
try {
if (text.isNotEmpty) {
String commentId = const Uuid().v1();
Comment comment = Comment(
commentId: commentId,
commentLikes: [],
datePublished: DateTime.now(),
name: name,
profilePic: profilePic,
text: text,
uid: uid);
await _firestore
.collection('posts')
.doc(postId)
.collection('comments')
.doc(commentId)
.set(
comment.toJson(),
);
} else {
print('Text is empty');
}
} catch (e) {
print(
e.toString(),
);
}
}
// like comment
Future<void> likeComment(
String commentId, String uid, List commentLikes) async {
try {
if (commentLikes.contains(uid)) {
await _firestore.collection('comments').doc(commentId).update({
'commentLikes': FieldValue.arrayRemove([uid]),
});
} else {
await _firestore.collection('comments').doc(commentId).update({
'commentLikes': FieldValue.arrayUnion([uid]),
});
}
} catch (e) {
print(
e.toString(),
);
}
}
//deleting posts
Future<void> deletePost(String postId) async {
try {
await _firestore.collection('posts').doc(postId).delete();
} catch (err) {
print(err.toString());
}
}
// follow user
Future<void> followUser(
String uid,
String followId,
) async {
try {
DocumentSnapshot snap =
await _firestore.collection('users').doc(uid).get();
List following = (snap.data()! as dynamic)['following'];
if (following.contains(followId)) {
await _firestore.collection('users').doc(followId).update({
'followers': FieldValue.arrayRemove([uid])
});
await _firestore.collection('users').doc(uid).update({
'following': FieldValue.arrayRemove([followId])
});
} else {
await _firestore.collection('users').doc(followId).update({
'followers': FieldValue.arrayUnion([uid])
});
await _firestore.collection('users').doc(uid).update({
'following': FieldValue.arrayUnion([followId])
});
}
} catch (e) {
print(e.toString());
}
}
}
</code></pre>
<p>As you can see in the code below the doc exist.</p>
<p>If I try to put the uid on Firebase in the commentLikes document, the IconButton Like/dislike change colour.</p>
<p>Can somebody help me figure out where is the issue? Thanks in advance.</p>
<p>Cheers.
Q</p>
| [
{
"answer_id": 74320138,
"author": "Swift",
"author_id": 8874154,
"author_profile": "https://Stackoverflow.com/users/8874154",
"pm_score": 2,
"selected": false,
"text": "ModelViewset"
},
{
"answer_id": 74320272,
"author": "Sumithran",
"author_id": 6562458,
"author_profile": "https://Stackoverflow.com/users/6562458",
"pm_score": 1,
"selected": false,
"text": "@api_view(['GET'])\ndef getauthor(request):\n if request.method == 'GET':\n\n results = AuthorAPI.objects.all()\n\n # get author_id from the url query parameter\n author_id = request.GET.get('author_id', None)\n \n #if author_id is present in the url query parameter then filter the resluts queryset based on the author_id\n if author_id:\n results = results.filter(author_id=author_id)\n\n serialize = AuthorAPISerializer(results, many=True)\n return Response(serialize.data)\n"
},
{
"answer_id": 74334374,
"author": "Mohammad Fathi Rahman",
"author_id": 18411353,
"author_profile": "https://Stackoverflow.com/users/18411353",
"pm_score": 2,
"selected": true,
"text": "viewsets.ReadOnlyModelViewset"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419261/"
] |
74,320,061 | <p>I have an API gateway in front of my Spring Boot app. This API gateway performs the oauth2 authentication and validation of the JWT token for me. My app receives the valid JWT token as HTTP header.</p>
<p>How can I combine this JWT token with the standard Spring security? I want to use the user groups passed in the JWT token for access control to my REST endpoints. And how can I avoid double validation of the JWT (on API gateway and service side)?</p>
| [
{
"answer_id": 74320692,
"author": "ch4mp",
"author_id": 619830,
"author_profile": "https://Stackoverflow.com/users/619830",
"pm_score": 1,
"selected": false,
"text": "<dependency>\n <groupId>com.c4-soft.springaddons</groupId>\n <!-- replace \"webmvc\" with \"weblux\" if your app is reactive -->\n <!-- replace \"jwt\" with \"introspecting\" to use token introspection instead of JWT decoding -->\n <artifactId>spring-addons-webmvc-jwt-resource-server</artifactId>\n <!-- this version is to be used with spring-boot 3.0.0-RC1, use 5.x for spring-boot 2.6.x or before -->\n <version>6.0.4</version>\n</dependency>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2851799/"
] |
74,320,153 | <p>So, I have the following two dataframes:</p>
<p>DF1 looks like following:</p>
<pre><code>+---------+-----------+
| Name | Money |
+---------+-----------+
| A | 50.3 |
| B | 26.9 |
| C | 11.4 |
| A | 35.8 |
| B | 59.2 |
| A | 90.8 |
| C | 23.5 |
| D | 23.5 |
| D | 54.6 |
| E | 78.0 |
| A | 12.3 |
| F | 20.3 |
| A | 57.1 |
+---------+-----------+
</code></pre>
<p>DF2 looks like following (list of unique names):</p>
<pre><code>+---------+
| Name |
+---------+
| A |
| C |
| D |
+---------+
</code></pre>
<p>What kind of join will give me the following (only keeping A, C and D that appear in DF2):</p>
<pre><code>+---------+-----------+
| Name | Money |
+---------+-----------+
| A | 50.3 |
| C | 11.4 |
| A | 35.8 |
| A | 90.8 |
| C | 23.5 |
| D | 23.5 |
| D | 54.6 |
| A | 12.3 |
| A | 57.1 |
+---------+-----------+
</code></pre>
| [
{
"answer_id": 74320203,
"author": "iDevlop",
"author_id": 78522,
"author_profile": "https://Stackoverflow.com/users/78522",
"pm_score": 0,
"selected": false,
"text": "Select * from df1 \nwhere df1.name in (\n Select name from df2)\n"
},
{
"answer_id": 74320333,
"author": "OdiumPura",
"author_id": 16459035,
"author_profile": "https://Stackoverflow.com/users/16459035",
"pm_score": 1,
"selected": false,
"text": "df = df1.alias(\"t0\").join(\n df2.alias(\"t1\"),\n on=f.col(\"t0.Name\") == f.col(\"t1.Name\"),\n how='inner'\n ).select(\n f.col(\"t0.Name\"),\n f.col(\"t0.Money\")\n )\n"
},
{
"answer_id": 74331236,
"author": "Bartosz Gajda",
"author_id": 6870955,
"author_profile": "https://Stackoverflow.com/users/6870955",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM df1 WHERE df1.Name IS IN df2.Name"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2941501/"
] |
74,320,161 | <p>I'm trying to format a PostgreSQL query in python and that query has to have '%' between the name of a survey so I can filter surveys by name.</p>
<p>Here is the code:</p>
<pre><code>sql = """select survey_data
from survey_data.survey_data
where codigo_do_projeto like '%s%'
ORDER BY data_de_inicio_da_coleta desc
limit %s
offset %s"""
</code></pre>
<p>However it throws this error:</p>
<blockquote>
<p>"unsupported format character 'P' (0x50) at index 79"</p>
</blockquote>
<p>I don't know how to make python ignore the "%" character.</p>
| [
{
"answer_id": 74320229,
"author": "jprebys",
"author_id": 3268228,
"author_profile": "https://Stackoverflow.com/users/3268228",
"pm_score": -1,
"selected": false,
"text": "survey_name"
},
{
"answer_id": 74321506,
"author": "Adrian Klaver",
"author_id": 7070613,
"author_profile": "https://Stackoverflow.com/users/7070613",
"pm_score": 1,
"selected": true,
"text": "%"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19426499/"
] |
74,320,176 | <p>In my app I have a <code>Dictionary<ContainerControl, int></code>.
I need to check if a key is present in the dictionary and alter its corresponding value if key is found or add the key if not already present.
The key for my dictionary is a ControlContainer object.
I could use this method:</p>
<pre><code>var dict = new Dictionary<ContainerControl, int>();
/*...*/
var c = GetControl();
if (dict.ContainsKey(c))
{
dict[c] = dict[c] + 1;
}
else
{
dict.Add(c, 0);
}
</code></pre>
<p>but I think that this way if the key is already present, my dictionary is iterated three times: once in ContainsKey and twice in the if branch.</p>
<p>I wander if there is a more efficient way to do this, something like</p>
<pre><code>var dict = new Dictionary<ContainerControl, int>();
/*...*/
var c = GetControl();
var kvp = dict.GetKeyValuePair(c); /* there is no such function in Dictionary */
if (kvp != null)
{
kvp.Value++;
}
else
{
dict.Add(c, 0);
}
</code></pre>
<p>This is possible using linq:</p>
<pre><code>var kvp = dict.SingleOrDefault(x => x.Key == c);
</code></pre>
<p>but what about performance?</p>
| [
{
"answer_id": 74320238,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "KeyValuePair<,>"
},
{
"answer_id": 74320288,
"author": "canton7",
"author_id": 1086121,
"author_profile": "https://Stackoverflow.com/users/1086121",
"pm_score": 2,
"selected": false,
"text": "class IntBox\n{\n public int Value { get; set; }\n}\n\nif (dict.TryGetValue(c, out var box))\n{\n box.Value++;\n}\nelse\n{\n dict[c] = new IntBox();\n}\n"
},
{
"answer_id": 74320432,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 2,
"selected": false,
"text": "CollectionsMarshal.GetValueRefOrAddDefault"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320176",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5573170/"
] |
74,320,191 | <p>I have a directory which contains files like this :
{users_20221104.txt | users_20221105.txt |
users_20221106.txt</p>
<p>dealers_20221104.txt |
dealers_20221105.txt |
dealers_20221106.txt |</p>
<p>nations_20221104.txt |
nations_20221105.txt |
nations_20221106.txt }</p>
<p>I need to retrieve only the last file of each occurence, which means users_20221106, dealers_20221106 and nations_20221106</p>
<p>At the moment I have something like this :</p>
<pre><code> private void downloadFiles() {
List<String> filesPath = ftpClient.listFiles(ftpFolderIn);
String usersFileTxt = null;
String dealerFileTxt = null;
String nationFileTxt = null;
for (String filepath : filesPath) {
if (filepath.contains("users")) {
usersFileTxt = filepath;
}
if (filepath.contains("dealers")) {
dealerFileTxt = filepath;
}
if (filepath.contains("nations")) {
nationFileTxt = filepath;
}
}
usersFile = ftpClient.downloadFile(usersFileTxt);
dealerFile = ftpClient.downloadFile(dealerFileTxt);
nationFile = ftpClient.downloadFile(nationFileTxt);
}
</code></pre>
| [
{
"answer_id": 74320238,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "KeyValuePair<,>"
},
{
"answer_id": 74320288,
"author": "canton7",
"author_id": 1086121,
"author_profile": "https://Stackoverflow.com/users/1086121",
"pm_score": 2,
"selected": false,
"text": "class IntBox\n{\n public int Value { get; set; }\n}\n\nif (dict.TryGetValue(c, out var box))\n{\n box.Value++;\n}\nelse\n{\n dict[c] = new IntBox();\n}\n"
},
{
"answer_id": 74320432,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 2,
"selected": false,
"text": "CollectionsMarshal.GetValueRefOrAddDefault"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19350908/"
] |
74,320,199 | <p>Hope you are all doing fine!
I am running with some difficulties when I want to deploy this api. I keep on receiving the message:"UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection"
My guess is that I am sending a response twice, but I cannot determine where. Does anyone know what could be going on?</p>
<pre><code>router.post('/add', async (req, res) => {
const friend = await User.findOne({username:req.body.friend})
const user = await User.findById(req.body.id)
if(friend && friend != req.headers.username) {
user.friends.find((x) => {
switch(friend.username){
case user.username:{
res.status(401).json({
status: "Failed",
message: "We are sorry but you cant add yourself as friend",
data:null
})
}
case x.friend_username: {
res.status(401).json({
status: "Error",
message: `Sorry, your friend has been already added`,
data: []
})
}
default: {
User.findByIdAndUpdate(req.body.id, {
$addToSet:{
friends: {
friend_id: friend.id,
friend_username: friend.username
}
}
}, {
upsert: true,
safe: true
})
.then(result => {
res.status(200).json({
status: "Success",
message: `Friend has been added correctly! `,
data: result
})
})
.catch((err)=>{
res.status(500).json({
status: "Failed",
message: "Database Error",
data: err
})
})
}
}
})
} else {
res.status(404).json({
status: "Failed",
message: "We are sorry but the username was not found",
data:null
})
console.log(`There has been an failed attempt of adding a new user. \nUser: ${req.headers.username} `)
}
})
</code></pre>
<p>`</p>
| [
{
"answer_id": 74320238,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "KeyValuePair<,>"
},
{
"answer_id": 74320288,
"author": "canton7",
"author_id": 1086121,
"author_profile": "https://Stackoverflow.com/users/1086121",
"pm_score": 2,
"selected": false,
"text": "class IntBox\n{\n public int Value { get; set; }\n}\n\nif (dict.TryGetValue(c, out var box))\n{\n box.Value++;\n}\nelse\n{\n dict[c] = new IntBox();\n}\n"
},
{
"answer_id": 74320432,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 2,
"selected": false,
"text": "CollectionsMarshal.GetValueRefOrAddDefault"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17959237/"
] |
74,320,227 | <p>So the idea is to scrap this particular page</p>
<p><a href="https://www.perlego.com/book/921329/getting-started-with-python-understand-key-data-structures-and-use-python-in-objectoriented-programming-pdf?queryID=9315f2c9285af80efdc99eaa9c5621bc&index=prod_BOOKS&gridPosition=2" rel="nofollow noreferrer">getting started with python perlego</a></p>
<p>so the idea is for a particular book, we look at the table of content and return every heading from Title Page to other books you may like</p>
<p>by using inspect element i found the tag and classes the table was using</p>
<p><a href="https://i.stack.imgur.com/RZbpd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RZbpd.png" alt="inspect element view" /></a></p>
<p>however in my following code:</p>
<pre><code>import requests
import json
from bs4 import BeautifulSoup
url = "https://www.perlego.com/book/921329/getting-started-with-python-understand-key-data-structures-and-use-python-in-objectoriented-programming-pdf?queryID=9315f2c9285af80efdc99eaa9c5621bc&index=prod_BOOKS&gridPosition=2"
r = requests.get(url)
print(r.status_code)
soup = BeautifulSoup(r.content, 'html.parser')
#another extra number on the side of sc-b81....-1 is the next link
print(soup.find_all(attrs={'class': 'sc-b81fc1ca-0'}))
</code></pre>
<p>what is printed out by this function is</p>
<pre><code><div class="sc-b81fc1ca-0 eqkOXa" data-testid="table-of-contents"><h2 class="sc-b81fc1ca-1 OnMGm">Table of contents</h2></div>]
</code></pre>
<p>whereas i would like all the tags under this class tag sc-b81fc1ca-2 although i've tried searching using findall but it only returns an empty list</p>
| [
{
"answer_id": 74320893,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": false,
"text": "requests"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10872352/"
] |
74,320,247 | <p>Given this data frame called 'names' and a series calles 'surnames', which is sorted differently, is it possible to use the assign function to add (on the left) the series to the data frame, to create a new data frame and maintain the order of 'name'?</p>
<pre><code> name = pd.DataFrame({'name': ['Max', 'Andre', 'Albert'],
'country': ['Germany', 'France', 'Germany']},
index= ['Max', 'Andre', 'Albert'])
surname = pd.Series(['Ampere', 'Einstein', 'Planck'],
index = ("Andre", "Albert", "Max"))
</code></pre>
<p>I tried several things, but I don't get the column surname neither on the left, nor in the right order...</p>
<p>Thanks a lot for your help!</p>
| [
{
"answer_id": 74320346,
"author": "finman69",
"author_id": 19628700,
"author_profile": "https://Stackoverflow.com/users/19628700",
"pm_score": 1,
"selected": false,
"text": "import pandas as pd\nname = pd.DataFrame({'name': ['Max', 'Andre', 'Albert'],\n'country': ['Germany', 'France', 'Germany']}, \nindex= ['Max', 'Andre', 'Albert'])\n\nsurname = pd.Series(['Ampere', 'Einstein', 'Planck'],\n index = (\"Andre\", \"Albert\", \"Max\"), name='Surname')\n\npd.concat([name, surname], axis=1)\n# or\nname.assign(Surname=surname)\n"
},
{
"answer_id": 74320365,
"author": "koding_buse",
"author_id": 20166777,
"author_profile": "https://Stackoverflow.com/users/20166777",
"pm_score": 3,
"selected": true,
"text": "name = name.assign(surname=surname)[['surname', 'name', 'country']]\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20273795/"
] |
74,320,285 | <p>I'm trying to make a footer with an image in the centre and a paragraph on the left side of the footer. This is what I have:
<a href="https://i.stack.imgur.com/WGqe5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WGqe5.png" alt="enter image description here" /></a></p>
<p>As you can see while the text is on the left, the image is not centred.</p>
<p>This is my code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.copyright {
color: #b4b4b4;
float: left;
font-size: 15px;
margin-left: 10px;
}
footer {
background: #303030;
padding: 35px 0;
text-align: center;
bottom: 0;
width: 100%;
height: auto;
display: inline-block;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><footer>
<p class="copyright">Aeron © 2022</p>
<a href="index.html"><img src="./images/logo.png" width="125px" title="Aeron Corporation" alt="logo" class="footer-logo"></a>
</footer></code></pre>
</div>
</div>
</p>
<p>How can I fix this? Thanks</p>
| [
{
"answer_id": 74320346,
"author": "finman69",
"author_id": 19628700,
"author_profile": "https://Stackoverflow.com/users/19628700",
"pm_score": 1,
"selected": false,
"text": "import pandas as pd\nname = pd.DataFrame({'name': ['Max', 'Andre', 'Albert'],\n'country': ['Germany', 'France', 'Germany']}, \nindex= ['Max', 'Andre', 'Albert'])\n\nsurname = pd.Series(['Ampere', 'Einstein', 'Planck'],\n index = (\"Andre\", \"Albert\", \"Max\"), name='Surname')\n\npd.concat([name, surname], axis=1)\n# or\nname.assign(Surname=surname)\n"
},
{
"answer_id": 74320365,
"author": "koding_buse",
"author_id": 20166777,
"author_profile": "https://Stackoverflow.com/users/20166777",
"pm_score": 3,
"selected": true,
"text": "name = name.assign(surname=surname)[['surname', 'name', 'country']]\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20197071/"
] |
74,320,308 | <p>I am returning a promise, but I am trying to return a string AND a promise. Is there a way to link the two <strong>without</strong> having to return it from the promise?</p>
<p>for example if my input was</p>
<pre><code>[
{
keepme:"abcd",
sql:"select top(1) * from X"
}
]
</code></pre>
<p>My goal is to return</p>
<pre><code>[
{
keepme:"abcd",
sql:"select top(1) * from X",
resultOfPromise:[{columnA:1,columnB:2}]
}
]
</code></pre>
<p>Here is my code so far. It returns the promise, but not the <code>abcd</code> value:</p>
<pre><code>let qq=[{keepme:"abcd",sql:"select top(1) * from X"}]
async function myFunc(sql:string){
return [{columnA:1,columnB:2}]
}
async function run(){
let prom=qq.map((qq) => myFunc(qq.sql));
for (let p of await (Promise as any).allSettled(prom)) {
console.log(p.value)
}
}
run();
</code></pre>
| [
{
"answer_id": 74320346,
"author": "finman69",
"author_id": 19628700,
"author_profile": "https://Stackoverflow.com/users/19628700",
"pm_score": 1,
"selected": false,
"text": "import pandas as pd\nname = pd.DataFrame({'name': ['Max', 'Andre', 'Albert'],\n'country': ['Germany', 'France', 'Germany']}, \nindex= ['Max', 'Andre', 'Albert'])\n\nsurname = pd.Series(['Ampere', 'Einstein', 'Planck'],\n index = (\"Andre\", \"Albert\", \"Max\"), name='Surname')\n\npd.concat([name, surname], axis=1)\n# or\nname.assign(Surname=surname)\n"
},
{
"answer_id": 74320365,
"author": "koding_buse",
"author_id": 20166777,
"author_profile": "https://Stackoverflow.com/users/20166777",
"pm_score": 3,
"selected": true,
"text": "name = name.assign(surname=surname)[['surname', 'name', 'country']]\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1634753/"
] |
74,320,337 | <p>im triying to center this element in the screen, and also when i hover.</p>
<p>In my example below, the div is not centred, even when i hover it knowing that i made the transform 50% and top/left too, that's what i use uselly to center an element.</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>* {
box-sizing: border-box;
}
body {
position: relative }
.zoom {
padding: 50px;
background-color: green;
transition: transform .2s;
width: 200px;
height: 200px;
margin: 0 auto;
transform: scale(.2) translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
.zoom:hover {
-ms-transform: scale(1.5); /* IE 9 */
-webkit-transform: scale(1.5); /* Safari 3-8 */
transform: scale(1.5);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="zoom"></div>
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74320485,
"author": "Laaouatni Anas",
"author_id": 17716837,
"author_profile": "https://Stackoverflow.com/users/17716837",
"pm_score": 2,
"selected": false,
"text": ":hover"
},
{
"answer_id": 74320558,
"author": "ComfyBlanket",
"author_id": 15353895,
"author_profile": "https://Stackoverflow.com/users/15353895",
"pm_score": 2,
"selected": true,
"text": "top: 50%; left: 50%;"
},
{
"answer_id": 74320757,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 0,
"selected": false,
"text": "translate(-50%, -50%)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18631280/"
] |
74,320,351 | <p>I have duplicate rows in a <code>PySpark</code> data frame and I want to combine and <code>sum</code> all of them into one row per column based on duplicate entries in one column.</p>
<p><strong>Current Table</strong></p>
<pre><code>Deal_ID Title Customer In_Progress Deal_Total
30 Deal 1 Client A 350 900
30 Deal 1 Client A 360 850
50 Deal 2 Client B 30 50
30 Deal 1 Client A 125 200
30 Deal 1 Client A 90 100
10 Deal 3 Client C 32 121
</code></pre>
<p><strong>Attempted PySpark Code</strong></p>
<pre><code>F.when(F.count(F.col('Deal_ID')) > 1, F.sum(F.col('In_Progress')) && F.sum(F.col('Deal_Total'))))
.otherwise(),
</code></pre>
<p><strong>Expected Table</strong></p>
<pre><code>Deal_ID Title Customer In_Progress Deal_Total
30 Deal 1 Client A 925 2050
50 Deal 2 Client B 30 50
10 Deal 3 Client C 32 121
</code></pre>
| [
{
"answer_id": 74320485,
"author": "Laaouatni Anas",
"author_id": 17716837,
"author_profile": "https://Stackoverflow.com/users/17716837",
"pm_score": 2,
"selected": false,
"text": ":hover"
},
{
"answer_id": 74320558,
"author": "ComfyBlanket",
"author_id": 15353895,
"author_profile": "https://Stackoverflow.com/users/15353895",
"pm_score": 2,
"selected": true,
"text": "top: 50%; left: 50%;"
},
{
"answer_id": 74320757,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 0,
"selected": false,
"text": "translate(-50%, -50%)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6932839/"
] |
74,320,352 | <p>Everytime an EC2 instance gets created, I want to run a script on that instance. I understand this could be done using the <strong>user_data</strong> parameter but some of these instances get created manually so people may forget to fill in that parameter sometimes. I want to rely on something automatic instead.</p>
<p>I figured to do it with <em>EventBridge</em>, catch an event that would indicate me that an instance has been created then trigger a <em>lambda</em> that would run the script. But when looking in the documentation I couldn't find any event that would relate to "EC2 created", see <a href="https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/monitoring-instance-state-changes.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/monitoring-instance-state-changes.html</a>.</p>
<p>Any idea how to get this done?</p>
| [
{
"answer_id": 74321023,
"author": "Paolo",
"author_id": 3390419,
"author_profile": "https://Stackoverflow.com/users/3390419",
"pm_score": 3,
"selected": true,
"text": "{\n \"source\": [\"aws.ec2\"],\n \"detail-type\": [\"AWS API Call via CloudTrail\"],\n \"detail\": {\n \"eventSource\": [\"ec2.amazonaws.com\"],\n \"eventName\": [\"RunInstances\"]\n }\n}\n"
},
{
"answer_id": 74348299,
"author": "Anthony B.",
"author_id": 19408037,
"author_profile": "https://Stackoverflow.com/users/19408037",
"pm_score": 1,
"selected": false,
"text": "{\n \"detail-type\": [\"EC2 Instance State-change Notification\"],\n \"detail\": {\n \"state\": [\"running\"]\n },\n \"source\": [\"aws.ec2\"]\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8368348/"
] |
74,320,367 | <p>I have hundreds of word documents that needs to be processed but need to organized them first by versions in subfolders.</p>
<p>I basically get a drop of these word documents within a single folder and need to automate the organization moving forward before I get nuts.</p>
<p>So I have a script that basically creates a folder with the same name of the file and moves the file inside that folder, this part is done.</p>
<p>Now I need to go into each subfolder, and get the document version from within the first word page of each document, then create a sub-folder withe version number and move the word file into that subfolder.</p>
<p>The structure should be as follows (taking two folders as examples):</p>
<pre><code>(Folder) Test
(Subfolder) 12.0
Test.docx
(Folder) Test1
(Subfolder) 13.0
Test1.docx
</code></pre>
<p>Luckily I was able to figure it out that "doc.paragraphs[6].text" will always return the version information in a single line as follows:</p>
<pre><code>>>> doc.paragraphs[6].text
'Version Number: 12.0'
</code></pre>
<p>Would appreciate if someone can point me out to the right direction.</p>
<p>This is the script I have so far:</p>
<pre><code>#!/usr/bin/env python3
import glob, os, shutil, docx, sys
folder = sys.argv[1]
#print(folder)
for file_path in glob.glob(os.path.join(folder, '*.docx')):
new_dir = file_path.rsplit('.', 1)[0]
#print(new_dir)
try:
os.mkdir(os.path.join(folder, new_dir))
except WindowsError:
# Handle the case where the target dir already exist.
pass
shutil.move(file_path, os.path.join(new_dir, os.path.basename(file_path)))
</code></pre>
| [
{
"answer_id": 74321023,
"author": "Paolo",
"author_id": 3390419,
"author_profile": "https://Stackoverflow.com/users/3390419",
"pm_score": 3,
"selected": true,
"text": "{\n \"source\": [\"aws.ec2\"],\n \"detail-type\": [\"AWS API Call via CloudTrail\"],\n \"detail\": {\n \"eventSource\": [\"ec2.amazonaws.com\"],\n \"eventName\": [\"RunInstances\"]\n }\n}\n"
},
{
"answer_id": 74348299,
"author": "Anthony B.",
"author_id": 19408037,
"author_profile": "https://Stackoverflow.com/users/19408037",
"pm_score": 1,
"selected": false,
"text": "{\n \"detail-type\": [\"EC2 Instance State-change Notification\"],\n \"detail\": {\n \"state\": [\"running\"]\n },\n \"source\": [\"aws.ec2\"]\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7839023/"
] |
74,320,404 | <p>I want that blue color apply to each line after 500ms. I am new to JavaScript I tried everything but nothing work..</p>
<p>here is the code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let para = document.getElementsByTagName("p");
for (let index = 0; index < para.length; index++) {
function timer() {
para[index].classList.toggle("blue");
}
setInterval(timer, 500);
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.blue {
color: blueviolet;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, ratione.
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, ratione.
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, ratione.
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, ratione.
</p></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74320446,
"author": "milner236",
"author_id": 17891020,
"author_profile": "https://Stackoverflow.com/users/17891020",
"pm_score": -1,
"selected": false,
"text": "para[index].classList.add(\"blue\");\n"
},
{
"answer_id": 74320458,
"author": "Dr. Vortex",
"author_id": 17637456,
"author_profile": "https://Stackoverflow.com/users/17637456",
"pm_score": 2,
"selected": true,
"text": "let i = 0, els = document.querySelectorAll('p');\n//the selector is the same but looks better and is more readable.\n\nsetInterval(() => {\n els[i++ % els.length].classList.toggle('blue');\n}, 500);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12846302/"
] |
74,320,428 | <p>I am trying to create a subtract function using pointers for 2d array but when I run it I get</p>
<blockquote>
<p>expression must have pointer-to-object type but it has type "int"C/C++(142)</p>
</blockquote>
<p>Can anybody explain why i'm getting this error and what is a better way around this?</p>
<p>this is my code</p>
<p>Function to read array</p>
<pre><code>int *readMatrix(int *arr)
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
printf("row %d, col %d: ", i + 1, j + 1);
scanf("%d", &arr[i * 4 + j]);
}
}
printf("\n");
return arr;
}
</code></pre>
<p>Function to subtract 2 2d arrays</p>
<pre><code>int *subM(int *arrA, int*arrB, int *arrC){
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
//printf("row %d, col %d: ", i + 1, j + 1);
&arrC[i][j] = &arrA[i][j] - &arrB[i][j]; //code where I am getting error
}
}
return arrC;
}
</code></pre>
<p>Main Function</p>
<pre><code>int main()
{
int arrA[3][4];
int arrB[3][4];
int arrC[3][4];
readMatrix(&arrA[3][4]);
readMatrix(&arrB[3][4]);
subM(&arrA[3][4],&arrB[3][4],&arrC[3][4]);
return 0;
}
</code></pre>
| [
{
"answer_id": 74320896,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 1,
"selected": false,
"text": "[]"
},
{
"answer_id": 74320909,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 0,
"selected": false,
"text": "readMatrix"
},
{
"answer_id": 74321169,
"author": "zhengliw",
"author_id": 20414672,
"author_profile": "https://Stackoverflow.com/users/20414672",
"pm_score": 3,
"selected": true,
"text": "readMatrix(&arrA[3][4]);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415156/"
] |
74,320,436 | <p>i have a parent component returning a flatlist , renderItem of flatlist returns child component , that child component makes a an api call so the parent component should wait promise of every child. I have tried to handle that by creating a promise inside useeffect but this did not work , could you help ,here is my code this is from child component:</p>
<pre><code>useEffect(() => {
const promises = async () => {
return await Promise.all([
userFollowers(link)
.then((datax) => {
setUserFollower(datax);
dispatch({
type: 'GET_FOLLOWING',
payload: datax,
});
})
.catch((e) => e),
userFollowing(item.item.followers_url)
.then((datax) => {
setFlwCounter(datax);
dispatch({
type: 'GET_FOLLOWERS',
payload: datax,
});
})
.catch((e) => e),
]);
};
return () => promises();
}, [item, userFollower, flwCounter]);
</code></pre>
<p>the error it says :</p>
<pre><code>Please report: Excessive number of pending callbacks: 501.
</code></pre>
<p>parent component here 's from where I call child component</p>
<pre><code> const renderItems = (item) => {
return <UserItem item={item} />;
};
</code></pre>
| [
{
"answer_id": 74320896,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 1,
"selected": false,
"text": "[]"
},
{
"answer_id": 74320909,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 0,
"selected": false,
"text": "readMatrix"
},
{
"answer_id": 74321169,
"author": "zhengliw",
"author_id": 20414672,
"author_profile": "https://Stackoverflow.com/users/20414672",
"pm_score": 3,
"selected": true,
"text": "readMatrix(&arrA[3][4]);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9758009/"
] |
74,320,480 | <p>I want to use a circle ci yaml pipeline to deploy to a Heroku App.</p>
<p>The yaml file I have right now is:</p>
<pre><code>version: 2.1
orbs:
heroku: circleci/heroku@0.0.10
jobs:
heroku_deploy_review_app:
executor: heroku/default
steps:
- checkout
- heroku/install
- heroku/deploy-via-git:
app-name: $HEROKU_APP_NAME
workflows:
heroku_deploy:
jobs:
- heroku_deploy_review_app:
filters:
branches:
only:
- test-123/test-heroku-orb
</code></pre>
<p>There are no issues from syntax side for this YAML. However, when I run this pipeline, I see <a href="https://i.stack.imgur.com/3yZMB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3yZMB.png" alt="enter image description here" /></a></p>
<p>I am not sure what I am doing wrong because this code looks all fine to me. I also confirmed with doc <a href="https://circleci.com/docs/deploy-to-heroku/" rel="nofollow noreferrer">https://circleci.com/docs/deploy-to-heroku/</a> and <a href="https://circleci.com/developer/orbs/orb/circleci/heroku" rel="nofollow noreferrer">https://circleci.com/developer/orbs/orb/circleci/heroku</a></p>
| [
{
"answer_id": 74320896,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 1,
"selected": false,
"text": "[]"
},
{
"answer_id": 74320909,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 0,
"selected": false,
"text": "readMatrix"
},
{
"answer_id": 74321169,
"author": "zhengliw",
"author_id": 20414672,
"author_profile": "https://Stackoverflow.com/users/20414672",
"pm_score": 3,
"selected": true,
"text": "readMatrix(&arrA[3][4]);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13815587/"
] |
74,320,496 | <p>I have web-page where I am trying to automate publishing of products with Selenium.</p>
<p>You can check situation here:
<a href="https://player.vimeo.com/video/767368522?h=a8feaf8791" rel="nofollow noreferrer">https://player.vimeo.com/video/767368522?h=a8feaf8791</a></p>
<p>I am able to click onto everything else but this button (because the id the number part is automatically generated).</p>
<p>I've thought of selecting it by class_name, by XPATH but it seems like it's just not ok...</p>
<p>This is the HTML structure:</p>
<pre><code><div id="mceu_104" class="mce-container mce-panel mce-floatpanel mce-window mce-in" hidefocus="1" role="dialog" aria-describedby="mceu_104-none" aria-label="Source code" style="border-width: 1px; z-index: 65536; left: 447px; top: 34px; width: 640px; height: 361px;">
<div class="mce-reset" role="application">
<div id="mceu_104-head" class="mce-window-head">
<div id="mceu_104-title" class="mce-title">Izvorni kod</div>
<button type="button" class="mce-close" aria-hidden="true">×</button>
<div id="mceu_104-dragh" class="mce-dragh"></div>
</div>
<div id="mceu_104-body" class="mce-container-body mce-window-body mce-abs-layout" style="width: 640px; height: 271px;">
<div id="mceu_104-absend" class="mce-abs-end"></div>
<div id="mceu_105" class="mce-container mce-form mce-abs-layout-item mce-first mce-last" style="left: 0px; top: 0px; width: 640px; height: 271px;">
<div id="mceu_105-body" class="mce-container-body mce-abs-layout" style="width: 640px; height: 271px;">
<div id="mceu_105-absend" class="mce-abs-end"></div>
<textarea id="mceu_106" class="mce-textbox mce-multiline mce-abs-layout-item mce-first mce-last" hidefocus="1" spellcheck="false" style="direction: ltr; text-align: left; left: 20px; top: 20px; width: 590px; height: 221px;"></textarea>
</div>
</div>
</div>
<div id="mceu_107" class="mce-container mce-panel mce-foot" hidefocus="1" tabindex="-1" role="group" style="border-width: 1px 0px 0px; left: 0px; top: 0px; width: 640px; height: 50px;">
<div id="mceu_107-body" class="mce-container-body mce-abs-layout" style="width: 640px; height: 50px;">
<div id="mceu_107-absend" class="mce-abs-end"></div>
<div id="mceu_108" class="mce-widget mce-btn mce-primary mce-abs-layout-item mce-first mce-btn-has-text" tabindex="-1" aria-labelledby="mceu_108" role="button" style="left: 508.975px; top: 10px; width: 58.025px; height: 28px;"><button role="presentation" type="button" tabindex="-1" style="height: 100%; width: 100%;"><span class="mce-txt">U redu</span></button></div>
<div id="mceu_109" class="mce-widget mce-btn mce-abs-layout-item mce-last mce-btn-has-text" tabindex="-1" aria-labelledby="mceu_109" role="button" style="left: 572px; top: 10px; width: 56px; height: 28px;"><button role="presentation" type="button" tabindex="-1" style="height: 100%; width: 100%;"><span class="mce-txt">Otkaži</span></button></div>
</div>
</div>
</div>
</div>
</code></pre>
<p>So I would need to click onto this element:</p>
<p><code><button role="presentation" type="button" tabindex="-1" style="height: 100%; width: 100%;"><span class="mce-txt">U redu</span></button></code></p>
<p>This is my code:</p>
<pre><code> final_description = html_and_css + csvproductDescription + html_and_css2
WebDriverWait(driver, 2).until(EC.visibility_of_element_located((By.CLASS_NAME, 'mce-textbox'))).send_keys(final_description)
WebDriverWait(driver, 2).until(EC.visibility_of_element_located((By.ID, 'mceu_108'))).click()
</code></pre>
<p>Can anyone help me, as this seems to be using tinymce and these ID's are generating automatically...</p>
<p>Thanks!</p>
| [
{
"answer_id": 74320896,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 1,
"selected": false,
"text": "[]"
},
{
"answer_id": 74320909,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 0,
"selected": false,
"text": "readMatrix"
},
{
"answer_id": 74321169,
"author": "zhengliw",
"author_id": 20414672,
"author_profile": "https://Stackoverflow.com/users/20414672",
"pm_score": 3,
"selected": true,
"text": "readMatrix(&arrA[3][4]);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20380926/"
] |
74,320,498 | <p>Hello I am trying to pass an input's event and another object as arguments to a change handler function.it works fine if you only pass e (I mean event) to function ,but when I try to add the second argument the first argument that is the Event disappears .I don't know what to pass as the first argument to fit as event. here is the code:</p>
<p>this is the function</p>
<pre><code>const changeHandler = (event, secondArgument) => {
console.log(event);
console.log(secondArgument);
}
</code></pre>
<p>and this is the jsx</p>
<pre><code> <input onChange={() => changeHandler(don't know what to pass here,myArgument)} name='name'} />
</code></pre>
| [
{
"answer_id": 74320896,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 1,
"selected": false,
"text": "[]"
},
{
"answer_id": 74320909,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 0,
"selected": false,
"text": "readMatrix"
},
{
"answer_id": 74321169,
"author": "zhengliw",
"author_id": 20414672,
"author_profile": "https://Stackoverflow.com/users/20414672",
"pm_score": 3,
"selected": true,
"text": "readMatrix(&arrA[3][4]);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16407358/"
] |
74,320,499 | <p>I looked at some threads but I think I'm missing something in Microsoft SQL Server (SSMS).</p>
<p>I have XML in column defined as <code>XML</code> datatype that looks like this:</p>
<p>(<em>I erased stuff before this not sure if it's needed</em>)</p>
<pre><code><ItemGroupData ItemGroupOID="TEST" TransactionType="Insert">
<ItemData ItemOID="TEACHER" Value="145"/>
<ItemData ItemOID="AGE" Value="50" />
</ItemGroupData>
<ItemGroupData ItemGroupOID="TEST" TransactionType="Insert">
<ItemData ItemOID="TEACHER" Value="151"/>
<ItemData ItemOID="AGE" Value="42" />
</ItemGroupData>
</code></pre>
<p>There's stuff I truncated but what is the most optimal way to locate the XML file where teacher 145 is and they can be in any of the Itemdata groups?</p>
<p>I can find it like:</p>
<pre><code>SELECT
CAST(XML AS nvarchar(max)) AS test
FROM
table1
WHERE
XML LIKE '%14%'
</code></pre>
<p>but I am looking into learning different ways without casting unless that is the most optimal way?</p>
| [
{
"answer_id": 74320802,
"author": "marc_s",
"author_id": 13302,
"author_profile": "https://Stackoverflow.com/users/13302",
"pm_score": 0,
"selected": false,
"text": "<root>....</root>"
},
{
"answer_id": 74321460,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 1,
"selected": false,
"text": "[@Value=sql:variable(\"@TeacherValue\")]"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2532928/"
] |
74,320,521 | <p>I'm unable to get spring boot to automatically load my database schema when I start it up. I am using MySQL as an external DB. Please find below the code</p>
<p>application properties</p>
<pre><code>spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/carsdb
spring.datasource.username=root
spring.datasource.password=password
</code></pre>
<p>Application.java</p>
<pre><code>package com.truckla.cars;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableAutoConfiguration
@SpringBootApplication
public class CarsApplication {
public static void main(String[] args) {
SpringApplication.run(CarsApplication.class, args);
}
}
</code></pre>
<p>Model entity</p>
<pre><code>package com.truckla.cars.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Entity
@Table(name = "cars")
@SequenceGenerator(name="seq", initialValue=4, allocationSize=100)
public class Car {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
Integer id;
String manufacturer;
String model;
Integer build;
public Car() {
}
public Car(Integer id, String manufacturer, String model, Integer build) {
this.id = id;
this.manufacturer = manufacturer;
this.model = model;
this.build = build;
}
public Integer getId() {
return id;
}
public String getManufacturer() {
return manufacturer;
}
public String getModel() {
return model;
}
public int getBuild() {
return build;
}
public void setId(Integer id) {
this.id = id;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public void setModel(String model) {
this.model = model;
}
public void setBuild(Integer build) {
this.build = build;
}
}
</code></pre>
<p>schema.sql</p>
<pre><code>CREATE TABLE cars (
id INT AUTO_INCREMENT PRIMARY KEY,
manufacturer VARCHAR(250) NOT NULL,
model VARCHAR(250) NOT NULL,
build YEAR DEFAULT NULL
);
</code></pre>
<p>data.sql</p>
<pre><code>INSERT INTO cars (manufacturer, model, build) VALUES
('Ford', 'Model T', 1927),
('Tesla', 'Model 3', 2017),
('Tesla', 'Cybertruck', 2019);
</code></pre>
<p>Any ideas what am i doing wrong and what i should change in order to get it work? Thanks in advance.</p>
| [
{
"answer_id": 74320802,
"author": "marc_s",
"author_id": 13302,
"author_profile": "https://Stackoverflow.com/users/13302",
"pm_score": 0,
"selected": false,
"text": "<root>....</root>"
},
{
"answer_id": 74321460,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 1,
"selected": false,
"text": "[@Value=sql:variable(\"@TeacherValue\")]"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15582416/"
] |
74,320,584 | <pre><code>def compa9():
a=int(input("enter the first number"))
b=int(input("enter the second number"))
compa9()
if a==b:
a==a
b==b
print("they are equal")
if a>b:
a==a
b==b
print (a,"is bigger and") (b,"is smaller")
if a<b:
a==a
b==b
print (b,"is bigger and") (a,"is smaller")
</code></pre>
<p>#i tried to write a program to find the which number is bigger or smaller in python but i am getting an error,what should i do??</p>
| [
{
"answer_id": 74320802,
"author": "marc_s",
"author_id": 13302,
"author_profile": "https://Stackoverflow.com/users/13302",
"pm_score": 0,
"selected": false,
"text": "<root>....</root>"
},
{
"answer_id": 74321460,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 1,
"selected": false,
"text": "[@Value=sql:variable(\"@TeacherValue\")]"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14558059/"
] |
74,320,605 | <p>I want to use system call(s) to grab values from first data line in file file and print into legend of plot.</p>
<p>The command returns a syntax error. I admit come confusion about a- the use of system calls and syntax, despite reading few advanced questions here.</p>
<p>This is what I have:</p>
<p>gnuplot> plot for [i=20:30:1] '4He-processed' index i u 8:($22>0.2&&$22<2?$9:1/0):10 w yerr t system("head -2 4He-processed | tail -1 | awk '{printf "%s %8.3f %8.3f %s" , "'", $3, $4,"'"}'")</p>
<blockquote>
<p>with the response: ')' expected with the pointer at the "f" in printf.</p>
</blockquote>
<p>I want to have the values in $3 and $4 written to the legend.</p>
<p>This alternate command</p>
<p>gnuplot> plot for [i=20:30:1] '4He-processed' index i u 8:($22>0.2&&$22<2?$9:1/0):10 w yerr t system("head -2 4He-processed | tail -1 ")</p>
<p>puts the entire first line, of each index loop, to the legend</p>
<p>It likely has to do with syntax?</p>
<p>I want the values from $3 and $4, not the column headings:</p>
<p>Here is the some lines (but not all the columns) from the file</p>
<h1>nz na e0 theta nu xsect ert y fy fye</h1>
<pre><code>2 4 0.150 60.000 0.025 0.330E+02 0.752E+00 -0.0459 0.956E+00 0.218E-01
2 4 0.150 60.000 0.030 0.497E+02 0.784E+00 -0.0001 0.146E+01 0.230E-01
2 4 0.150 60.000 0.035 0.483E+02 0.766E+00 0.0315 0.144E+01 0.229E-01
2 4 0.150 60.000 0.040 0.408E+02 0.728E+00 0.0573 0.125E+01 0.224E-01
</code></pre>
<p>This continues for many blocks. Here, if I were to start my loop with the first block, the values (at $3 and $4) would be 0.150 and 60.000 which correspond to the energy and angle of the projectile and they would hopefully appear in the legend. The plotted quantities ($8,$22 and $23) not pasted here (too many columns).</p>
| [
{
"answer_id": 74320802,
"author": "marc_s",
"author_id": 13302,
"author_profile": "https://Stackoverflow.com/users/13302",
"pm_score": 0,
"selected": false,
"text": "<root>....</root>"
},
{
"answer_id": 74321460,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 1,
"selected": false,
"text": "[@Value=sql:variable(\"@TeacherValue\")]"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12520696/"
] |
74,320,618 | <p>Problem</p>
<p>The code is to decode the word in such a way that For every letter x, if it is the ith letter of</p>
<p>the alphabet starting from the left, replace it with the ith letter starting from the right.</p>
<p>. For example, the string 'abcd' would be encoded to 'zyxw'.</p>
<p>Note: all the letters of the word are lower case alphabets</p>
<p>Editorial:</p>
<p>"abcdefghijklmnopqrstuvwxyz" is the sequence.</p>
<p>⚫ Here a is the fist alphabet appear in the sequence, so it will be replaced with the last</p>
<p>alphabet in the sequence i.e. z. ⚫b is the second alphabet from the begining in the sequence, so it will be replaced by the second last alphabet from the end i.e. y, and so on.</p>
<p>⚫ Here a is the fist alphabet appear in the sequence, so it will be replaced with the last</p>
<p>alphabet in the sequence i.e. z. ⚫b is the second alphabet from the begining in the sequence, so it will be replaced by the second last alphabet from the end i.e. y, and so on.</p>
| [
{
"answer_id": 74320802,
"author": "marc_s",
"author_id": 13302,
"author_profile": "https://Stackoverflow.com/users/13302",
"pm_score": 0,
"selected": false,
"text": "<root>....</root>"
},
{
"answer_id": 74321460,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 1,
"selected": false,
"text": "[@Value=sql:variable(\"@TeacherValue\")]"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419561/"
] |
74,320,650 | <p>I am trying to deploy <strong>istio's sample bookinfo application</strong> using the below command:</p>
<pre><code>kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
</code></pre>
<p>from <a href="https://istio.io/latest/docs/setup/getting-started/#bookinfo" rel="nofollow noreferrer">here</a></p>
<p>but each time I am getting <strong>ImagePullBackoff error</strong> like this:</p>
<pre><code>NAME READY STATUS RESTARTS AGE
details-v1-c74755ddf-m878f 2/2 Running 0 6m32s
productpage-v1-778ddd95c6-pdqsk 2/2 Running 0 6m32s
ratings-v1-5564969465-956bq 2/2 Running 0 6m32s
reviews-v1-56f6655686-j7lb6 1/2 ImagePullBackOff 0 6m32s
reviews-v2-6b977f8ff5-55tgm 1/2 ImagePullBackOff 0 6m32s
reviews-v3-776b979464-9v7x5 1/2 ImagePullBackOff 0 6m32s
</code></pre>
<p>For error details, I have run :</p>
<pre><code>kubectl describe pod reviews-v1-56f6655686-j7lb6
</code></pre>
<p>Which returns these:</p>
<pre><code>Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 7m41s default-scheduler Successfully assigned default/reviews-v1-56f6655686-j7lb6 to minikube
Normal Pulled 7m39s kubelet Container image "docker.io/istio/proxyv2:1.15.3" already present on machine
Normal Created 7m39s kubelet Created container istio-init
Normal Started 7m39s kubelet Started container istio-init
Warning Failed 5m39s kubelet Failed to pull image "docker.io/istio/examples-bookinfo-reviews-v1:1.17.0": rpc error: code = Unknown desc = context deadline exceeded
Warning Failed 5m39s kubelet Error: ErrImagePull
Normal Pulled 5m39s kubelet Container image "docker.io/istio/proxyv2:1.15.3" already present on machine
Normal Created 5m39s kubelet Created container istio-proxy
Normal Started 5m39s kubelet Started container istio-proxy
Normal BackOff 5m36s (x3 over 5m38s) kubelet Back-off pulling image "docker.io/istio/examples-bookinfo-reviews-v1:1.17.0"
Warning Failed 5m36s (x3 over 5m38s) kubelet Error: ImagePullBackOff
Normal Pulling 5m25s (x2 over 7m38s) kubelet Pulling image "docker.io/istio/examples-bookinfo-reviews-v1:1.17.0"
</code></pre>
<p>Do I need to build dockerfile first and push it to the local repository? There are no clear instructions there or I failed to find any.</p>
<p>Can anybody help?</p>
| [
{
"answer_id": 74321582,
"author": "paltaa",
"author_id": 6855531,
"author_profile": "https://Stackoverflow.com/users/6855531",
"pm_score": 1,
"selected": false,
"text": "context deadline exceeded"
},
{
"answer_id": 74321902,
"author": "mnhmilu",
"author_id": 1206344,
"author_profile": "https://Stackoverflow.com/users/1206344",
"pm_score": 0,
"selected": false,
"text": " minikube ssh docker pull istio/examples-bookinfo-reviews-v1:1.17.0\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1206344/"
] |
74,320,667 | <p>So at my previous role, whenever someone created a branch in 'develop' I could refresh/ pull and the branch would appear in my VSC Source control. If a branch was deleted on GitHub, the branch also deleted (disappeared) in VSC. In this new repo, we work off of main and branches, more as a place to store code, rather than updating a website.</p>
<p>As you can see below, I deleted (on GitHub) these branches after the PR's were merged. They don't automatically disappear.</p>
<p><a href="https://i.stack.imgur.com/74dC8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/74dC8.png" alt="enter image description here" /></a></p>
<p>Furthermore, If someone else makes a branch from main, it will not appear in my list (as mine would not in theirs). Before this would be automatic. This is quite annoying as today for example, I made a branch in prep for another dev, and wanted them to just refresh 'branches' and switch to it.</p>
<p>I have tried git fetch, git remote update origin, prunes etc - nothing seems to work but manual updates and cloning branches from github.</p>
<p>Advice is really appreciated. Is it something to do with the repo setup?</p>
<p>Edit: New clone of the repo: branches don't show. I ran a git fetch and fetch --all but as you can see, nothing happened.</p>
<p><a href="https://i.stack.imgur.com/5gUaC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5gUaC.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/VmuhB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VmuhB.png" alt="enter image description here" /></a></p>
<p>It might also be worth mentioning, if I open the repo on GitHub Desktop, I can see the branches, I can switch to the branch > open in VSC and then the branch is now displaying, allowing me to swap between main and said branch as expected.</p>
<p>Below is a screenshot of git branch --all
<a href="https://i.stack.imgur.com/R0Mt6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R0Mt6.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74321582,
"author": "paltaa",
"author_id": 6855531,
"author_profile": "https://Stackoverflow.com/users/6855531",
"pm_score": 1,
"selected": false,
"text": "context deadline exceeded"
},
{
"answer_id": 74321902,
"author": "mnhmilu",
"author_id": 1206344,
"author_profile": "https://Stackoverflow.com/users/1206344",
"pm_score": 0,
"selected": false,
"text": " minikube ssh docker pull istio/examples-bookinfo-reviews-v1:1.17.0\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13467487/"
] |
74,320,671 | <p>I need to make my styles to occur one after another after some interval time.</p>
<p>JS</p>
<pre><code>element.style.cssText = "width: 400px; height:400px; background-color:blue;
border: 1px solid green; border-radius: 10px; text-align: center; color:white; "
setInterval(function () {element.innerHTML += element.style},1000);
</code></pre>
<p>the styles have to be declerated in JS (not necessarily using .cssText)
`</p>
| [
{
"answer_id": 74320742,
"author": "Dr. Vortex",
"author_id": 17637456,
"author_profile": "https://Stackoverflow.com/users/17637456",
"pm_score": 0,
"selected": false,
"text": "element.style.cssText"
},
{
"answer_id": 74320779,
"author": "Scott Marcus",
"author_id": 695364,
"author_profile": "https://Stackoverflow.com/users/695364",
"pm_score": 1,
"selected": true,
"text": "classList"
},
{
"answer_id": 74320794,
"author": "Abhay Bisht",
"author_id": 14343411,
"author_profile": "https://Stackoverflow.com/users/14343411",
"pm_score": -1,
"selected": false,
"text": "const cssText = \"width: 400px; height:400px; background-color:blue; \nborder: 1px solid green; border-radius: 10px; text-align: center; color:white; \";\nconst stylesArray = cssText.split(\";\");\nlet i = 0;\nlet timer = setInterval(function () {\n element.style += styleArray[i++];\n// or your\n// element.innerHTML += styleArray[i++];\n if ( i >= stylesArray ) clearInterval(timer);\n},1000);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18920245/"
] |
74,320,693 | <p>it is necessary that when you click on the button, the 'active' class is removed from the first div, and added to the second. When pressed again, the active class was removed from the active block and added to the next one, and so on until the end</p>
<pre><code><div class="main">
<div class="block active"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
<button class="next">Next</button>
</code></pre>
<pre><code>.main {
display: flex;
}
.block {
width: 8px;
height: 16px;
background: #767676;
margin: 5px;
}
.active {
height: 26px;
}
.next {
padding: 5px;
}
</code></pre>
<pre><code>const btn = document.querySelector('.next');
btn.addEventListener(`click`, e => {
document.querySelectorAll(`.main > .block:not(.active)`)[0].classList += ` active`;
});
</code></pre>
| [
{
"answer_id": 74320742,
"author": "Dr. Vortex",
"author_id": 17637456,
"author_profile": "https://Stackoverflow.com/users/17637456",
"pm_score": 0,
"selected": false,
"text": "element.style.cssText"
},
{
"answer_id": 74320779,
"author": "Scott Marcus",
"author_id": 695364,
"author_profile": "https://Stackoverflow.com/users/695364",
"pm_score": 1,
"selected": true,
"text": "classList"
},
{
"answer_id": 74320794,
"author": "Abhay Bisht",
"author_id": 14343411,
"author_profile": "https://Stackoverflow.com/users/14343411",
"pm_score": -1,
"selected": false,
"text": "const cssText = \"width: 400px; height:400px; background-color:blue; \nborder: 1px solid green; border-radius: 10px; text-align: center; color:white; \";\nconst stylesArray = cssText.split(\";\");\nlet i = 0;\nlet timer = setInterval(function () {\n element.style += styleArray[i++];\n// or your\n// element.innerHTML += styleArray[i++];\n if ( i >= stylesArray ) clearInterval(timer);\n},1000);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419637/"
] |
74,320,702 | <p>I have this search which filters the elements directly when I type letters in the input field. And now I want to reset the search by clicking on the 'x'.</p>
<p>So far the filter only reacts 'live' and goes back to the initial state when I delete the letters with the backspace key. But when I click on the 'x' it just deletes my written letters. Other than that nothing happens and I have to press 'enter' in the input field to reset the search again.</p>
<p>But I would really love the search to reset itself (without having to press 'enter') when I click on the 'x' button.</p>
<p>That's my search in HTML. The span id="clear" is the 'x' button I'm talking about.</p>
<pre><code><div id="Search">
<div class="icon"></div>
<div class="input">
<input type="text" placeholder="nach AdSpecial suchen" id="adSearch" onkeyup="search_ads()">
</div>
<span id="clear" onclick="clearSearch()"></span>
</div>
</code></pre>
<p>And that's my JavaScript code. All my elements that I want to filter have the class '.filterDiv'.</p>
<pre><code>const search = document.getElementById("Search");
const items = document.querySelectorAll(".filterDiv");
function search_ads() {
let input = document.getElementById('adSearch').value
input=input.toLowerCase();
let x = document.getElementsByClassName('filterDiv');
for (i = 0; i < x.length; i++) {
if (!x[i].innerHTML.toLowerCase().includes(input)) {
x[i].style.display="none";
}
else {
x[i].style.display="";
}
}
}
function clearSearch() {
document.getElementById('adSearch').value="";
}
</code></pre>
<p>This is my first post here, so I apologise if I forgot to mention some important informations!</p>
| [
{
"answer_id": 74320742,
"author": "Dr. Vortex",
"author_id": 17637456,
"author_profile": "https://Stackoverflow.com/users/17637456",
"pm_score": 0,
"selected": false,
"text": "element.style.cssText"
},
{
"answer_id": 74320779,
"author": "Scott Marcus",
"author_id": 695364,
"author_profile": "https://Stackoverflow.com/users/695364",
"pm_score": 1,
"selected": true,
"text": "classList"
},
{
"answer_id": 74320794,
"author": "Abhay Bisht",
"author_id": 14343411,
"author_profile": "https://Stackoverflow.com/users/14343411",
"pm_score": -1,
"selected": false,
"text": "const cssText = \"width: 400px; height:400px; background-color:blue; \nborder: 1px solid green; border-radius: 10px; text-align: center; color:white; \";\nconst stylesArray = cssText.split(\";\");\nlet i = 0;\nlet timer = setInterval(function () {\n element.style += styleArray[i++];\n// or your\n// element.innerHTML += styleArray[i++];\n if ( i >= stylesArray ) clearInterval(timer);\n},1000);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419085/"
] |
74,320,720 | <p>I have some existing code that uses boto3 (python) DynamoDB Table objects to query the database:</p>
<pre class="lang-py prettyprint-override"><code>import boto3
resource = boto3.resource("dynamodb")
table = resource.table("my_table")
# Do stuff here
</code></pre>
<p>We now want to run the tests for this code using DynamoDB Local instead of connecting to DynamoDB proper, to try and get them running faster and save on resources. To do that, I gather that I need to use a client object, not a table object:</p>
<pre class="lang-py prettyprint-override"><code>import boto3
session = boto3.session.Session()
db_client = session.client(service_name="dynamodb", endpoint_url="http://localhost:8000")
# Do slightly different stuff here, 'cos clients and tables work differently
</code></pre>
<p>However, there's really rather a lot of the existing code, to the point that the cost of rewriting everything to work with clients rather than tables is likely to be prohibitive.</p>
<p>Is there any way to either get a table object while specifying the endpoint_url so I can point it at DynamoDB Local on creation, or else obtain a boto3 dynamodb table object from a boto3 dynamodb client object?</p>
<p>PS: I know I could also mock out the boto3 calls and not access the database at all. But that's also prohibitively costly, because for all of the existing tests we'd have to work out where they touch the database and what the appropriate mock setup and use is. For a couple of tests that's perfectly fine, but it's a lot of work if you've got a lot of tests.</p>
| [
{
"answer_id": 74320872,
"author": "jarmod",
"author_id": 271415,
"author_profile": "https://Stackoverflow.com/users/271415",
"pm_score": 3,
"selected": true,
"text": "resource = boto3.resource('dynamodb', endpoint_url='http://localhost:8000')\ntable = resource.Table(name)\n"
},
{
"answer_id": 74334280,
"author": "Nadav Har'El",
"author_id": 8891224,
"author_profile": "https://Stackoverflow.com/users/8891224",
"pm_score": 1,
"selected": false,
"text": "table = db_client.Table(name)\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5734324/"
] |
74,320,722 | <p>I am making a little program in C# that checks if input is an arithmetic array or a normal array.</p>
<p>The problem is when I make a for loop that checks if the array is arithmetic, I lose the last two elements off the array because i had to reduce <code>numbers.Length</code> with 2, otherwise I would get an error saying its out of bounds. (btw., arithmetic is for example: 2 - 4 - 6 - 8 - 10 - 12, so +2 every time)</p>
<pre class="lang-cs prettyprint-override"><code>int[] numbers = new int[6];
for (int i = 0; i < numbers.Length; i++)
{
Console.Write("Give a number: ");
numbers[i] = int.Parse(Console.ReadLine());
}
bool boolArithmetic = false;
bool boolNormal = false;
int counterArithmetic = 0;
for (int i = 0; i < numbers.Length - 2; i++)
{
if (numbers[i + 1] - numbers[i] == numbers[i + 2] - numbers[i + 1])
{
Console.WriteLine("Arithmetic Array");
Console.WriteLine(i);
counterArithmetic++;
boolArithmetic = true;
}
else
{
Console.WriteLine("Normal Array");
Console.WriteLine(i);
boolNormal = true;
}
}
if (counterArithmetic == 6 && boolArithmetic)
{
Console.WriteLine("ARITHMETIC ARRAY");
}
else if (boolNormal)
{
Console.WriteLine("NORMAL ARRAY");
}
</code></pre>
<p>I tried adding +2 to the array but this didn't work at all. I also tried a do while loop but it just confused me even more.</p>
<p>Does someone know how to fix this so that my code work fine?</p>
| [
{
"answer_id": 74320872,
"author": "jarmod",
"author_id": 271415,
"author_profile": "https://Stackoverflow.com/users/271415",
"pm_score": 3,
"selected": true,
"text": "resource = boto3.resource('dynamodb', endpoint_url='http://localhost:8000')\ntable = resource.Table(name)\n"
},
{
"answer_id": 74334280,
"author": "Nadav Har'El",
"author_id": 8891224,
"author_profile": "https://Stackoverflow.com/users/8891224",
"pm_score": 1,
"selected": false,
"text": "table = db_client.Table(name)\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19813966/"
] |
74,320,756 | <p>Ok so I know pretty easy to horizontally align a text inside a div using <code>text-align</code> but I want to remove it from the top of the div. I tried using <code>vertical-align</code> but it didn't work out.</p>
<p>Here's how it is looking right now</p>
<p><a href="https://i.stack.imgur.com/dtuSF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dtuSF.png" alt="enter image description here" /></a></p>
<p>Does anybody have a clue what might work? I know I could just add some margin-top but that seems to be like a stupid solution</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
background-color: rgb(255, 255, 255);
max-width: 95%;
margin: 0 auto;
}
header {
display: flex;
border-bottom: solid 1px black;
padding: 10px;
align-items: center;
}
.allButtons {
display: flex;
margin-left: auto;
}
.headerButtons {
margin: 10px;
background-color: rgb(10, 153, 254, .1);
text-align: center;
color: #0A99FE;
font-size: 20px;
width: 150px;
height: 40px;
border-radius: 10px;
}
.headerButtons:hover {
background-color: #0A99FE;
color: white;
}
ul {
margin: 0;
padding: 0;
border: 0;
display: flex;
list-style-type: none;
}
img {
border-radius: 10px;
}
li {
margin-right: 10px;
text-align: center;
background-color: #f8f8f8;
border-radius: 10px;
align-content: center;
}
h1 {
font-size: 20px;
font-weight: 400;
}
p {
font-size: 16px;
color: #868383;
}
#titleCards {
font-weight: 500;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><header class="headerItens">
<svg width="164" height="54" viewBox="0 0 164 54" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M34.6341 38.347C30.0324 40.0528 23.3232 39.2311 20.4862 37.9192C17.6411 36.6026 14.062 40.1065 18.1966 41.7563C22.3304 43.4058 29.3089 43.0965 34.6369 41.8034" fill="#0A99FE"/>
<path d="M34.6341 38.347C30.0324 40.0528 23.3232 39.2311 20.4862 37.9192C17.6411 36.6026 14.062 40.1065 18.1966 41.7563C22.3304 43.4058 29.3089 43.0965 34.6369 41.8034" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M37.3815 47.4288L35.3135 48.5538L33.8293 44.4007L35.8464 34.7222L32.7996 26.0337L36.9103 18.2146L48.8209 17.9628L51.3387 19.6712L54.0802 21.4771L54.9769 23.9681L53.8602 26.0206L52.7914 28.2193L53.5284 30.5154L51.6277 31.2494L48.2777 37.5047L42.3556 44.1037L39.9187 45.5867L37.3815 47.4288Z" fill="#0A99FE"/>
<path d="M49.8828 17.3271C53.6701 25.5104 52.6224 34.6247 45.3759 44.9323C51.416 45.9056 47.6171 50.3048 40.1762 45.8149" fill="#0A99FE"/>
<path d="M49.8828 17.3271C53.6701 25.5104 52.6224 34.6247 45.3759 44.9323C51.416 45.9056 47.6171 50.3048 40.1762 45.8149" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M33.2819 26.0334C35.8281 34.3033 35.9591 42.0565 31.6789 48.8662C35.5428 55.442 39.6209 50.6029 36.4317 48.3576" fill="#0A99FE"/>
<path d="M33.2819 26.0334C35.8281 34.3033 35.9591 42.0565 31.6789 48.8662C35.5428 55.442 39.6209 50.6029 36.4317 48.3576" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M47.7151 33.3036C46.3229 39.2472 42.4295 43.9228 36.4671 48.3316L47.7151 33.3036Z" fill="#0A99FE"/>
<path d="M47.7151 33.3036C46.3229 39.2472 42.4295 43.9228 36.4671 48.3316" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M50.6031 19.0504C55.364 21.167 56.3238 24.2183 53.0232 28.3173C54.9823 30.5633 53.4137 31.7456 51.7063 30.7128" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M33.0049 29.0136L38.6542 30.8666C39.1103 41.5652 29.7687 37.7605 35.5809 33.702C20.314 32.3437 20.5906 28.8259 35.275 19.8782L45.3531 16.9391L47.4802 19.4782" fill="#0A99FE"/>
<path d="M33.0049 29.0136L38.6542 30.8666C39.1103 41.5652 29.7687 37.7605 35.5809 33.702C20.314 32.3437 20.5906 28.8259 35.275 19.8782L45.3531 16.9391L47.4802 19.4782" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M41.3332 24.6116L31.4328 29.8635L41.3332 24.6116Z" fill="#0A99FE"/>
<path d="M41.3332 24.6116L31.4328 29.8635" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15.4239 4.30242C14.809 7.49465 14.0051 9.26857 10.0159 11.0189C6.6965 12.4488 0.889192 13.9475 0.0136247 17.6953C4.50403 20.0811 10.5996 22.2078 19.8948 19.5555C27.2064 17.4693 32.1783 21.6527 40.451 22.1748C38.4454 17.5598 37.1082 15.3508 34.6809 13.7268C30.626 13.5208 28.1016 8.65118 24.1513 6.68459C20.8398 5.036 19.9526 4.91399 15.4239 4.30242Z" fill="black"/>
<path d="M32.2778 2.95281C32.2518 2.6826 32.4969 2.5817 32.7189 2.77121L34.98 4.70148L37.2412 6.63179C37.4632 6.8213 37.4956 7.15902 37.2995 7.23976L35.3024 8.06176L33.3053 8.8838C33.1092 8.96449 32.8317 8.72759 32.8058 8.45739L32.5418 5.70508L32.2778 2.95281Z" fill="#0A99FE"/>
<path d="M32.2778 2.95281C32.2518 2.6826 32.4969 2.5817 32.7189 2.77121L34.98 4.70148L37.2412 6.63179C37.4632 6.8213 37.4956 7.15902 37.2995 7.23976L35.3024 8.06176L33.3053 8.8838C33.1092 8.96449 32.8317 8.72759 32.8058 8.45739L32.5418 5.70508L32.2778 2.95281Z" stroke="black" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M43.4032 1.38483C43.4997 1.12527 43.784 1.11048 43.915 1.35823L45.2494 3.88157L46.5838 6.40482C46.7148 6.65257 46.5942 6.97705 46.3668 6.9889L44.0499 7.10931L41.7331 7.2298C41.5056 7.24161 41.3418 6.93191 41.4383 6.67235L42.4207 4.02865L43.4032 1.38483Z" fill="#0A99FE"/>
<path d="M43.4032 1.38483C43.4997 1.12527 43.784 1.11048 43.915 1.35823L45.2494 3.88157L46.5838 6.40482C46.7148 6.65257 46.5942 6.97705 46.3668 6.9889L44.0499 7.10931L41.7331 7.2298C41.5056 7.24161 41.3418 6.93191 41.4383 6.67235L42.4207 4.02865L43.4032 1.38483Z" stroke="black" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M52.6317 13.1373C52.5355 18.1552 47.8016 22.1548 42.0581 22.0708C36.3146 21.9868 31.7365 17.851 31.8327 12.8332C31.9288 7.81534 36.6628 3.81572 42.4063 3.89972C48.1498 3.98372 52.7278 8.11954 52.6317 13.1373Z" fill="#0A99FE"/>
<path d="M52.6317 13.1373C52.5355 18.1552 47.8016 22.1548 42.0581 22.0708C36.3146 21.9868 31.7365 17.851 31.8327 12.8332C31.9288 7.81534 36.6628 3.81572 42.4063 3.89972C48.1498 3.98372 52.7278 8.11954 52.6317 13.1373Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M40.0902 8.01892C42.6114 13.6259 46.6678 12.0728 43.6248 7.43546" stroke="black" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M44.9714 7.21087C47.0745 12.7384 50.5785 10.8353 46.8276 6.65171" stroke="black" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M47.0793 12.4942L48.3819 15.1063" stroke="black" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M50.2585 15.8632L48.4904 15.2581L47.774 17.0972" stroke="black" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round"/>
<path d="M73.9091 23.7609C73.8097 23.4153 73.67 23.1099 73.4901 22.8447C73.3101 22.5748 73.09 22.3475 72.8295 22.1629C72.5739 21.9735 72.2803 21.8291 71.9489 21.7296C71.6222 21.6302 71.2599 21.5805 70.8622 21.5805C70.1188 21.5805 69.4654 21.7652 68.902 22.1345C68.3433 22.5038 67.9077 23.0412 67.5952 23.7467C67.2827 24.4474 67.1264 25.3045 67.1264 26.3177C67.1264 27.331 67.2803 28.1927 67.5881 28.9029C67.8958 29.6132 68.3314 30.1553 68.8949 30.5294C69.4583 30.8987 70.1236 31.0833 70.8906 31.0833C71.5866 31.0833 72.1809 30.9602 72.6733 30.714C73.1705 30.4631 73.5492 30.1103 73.8097 29.6558C74.0748 29.2012 74.2074 28.6638 74.2074 28.0436L74.8324 28.1359H71.0824V25.8206H77.169V27.6529C77.169 28.9313 76.8991 30.0298 76.3594 30.9484C75.8196 31.8622 75.0762 32.5677 74.1293 33.0649C73.1823 33.5573 72.098 33.8035 70.8764 33.8035C69.5128 33.8035 68.3149 33.5028 67.2827 32.9015C66.2505 32.2955 65.4455 31.4361 64.8679 30.3234C64.295 29.206 64.0085 27.8802 64.0085 26.3461C64.0085 25.1671 64.179 24.116 64.5199 23.1927C64.8655 22.2647 65.3485 21.4787 65.9688 20.8348C66.589 20.1908 67.3111 19.7008 68.1349 19.3646C68.9588 19.0284 69.8513 18.8603 70.8125 18.8603C71.6364 18.8603 72.4034 18.9811 73.1136 19.2225C73.8239 19.4593 74.4536 19.7955 75.0028 20.2311C75.5568 20.6667 76.009 21.1851 76.3594 21.7865C76.7098 22.3831 76.9347 23.0412 77.0341 23.7609H73.9091ZM84.3938 33.8177C83.2717 33.8177 82.3058 33.5904 81.4961 33.1359C80.6912 32.6766 80.0709 32.0279 79.6353 31.1899C79.1997 30.3471 78.9819 29.3504 78.9819 28.1998C78.9819 27.0777 79.1997 26.0928 79.6353 25.2453C80.0709 24.3977 80.6841 23.7372 81.4748 23.2637C82.2702 22.7903 83.203 22.5535 84.2731 22.5535C84.9928 22.5535 85.6628 22.6695 86.283 22.9015C86.908 23.1288 87.4525 23.4721 87.9165 23.9313C88.3853 24.3906 88.7499 24.9683 89.0103 25.6643C89.2707 26.3556 89.4009 27.1653 89.4009 28.0933V28.9242H80.1893V27.0492H86.5529C86.5529 26.6136 86.4582 26.2278 86.2688 25.8916C86.0794 25.5554 85.8166 25.2926 85.4805 25.1032C85.149 24.9091 84.7631 24.812 84.3228 24.812C83.8635 24.812 83.4563 24.9186 83.1012 25.1316C82.7508 25.34 82.4762 25.6217 82.2773 25.9768C82.0785 26.3272 81.9767 26.7178 81.9719 27.1487V28.9313C81.9719 29.4711 82.0714 29.9375 82.2702 30.3305C82.4738 30.7235 82.7603 31.0265 83.1296 31.2396C83.4989 31.4527 83.9369 31.5592 84.4435 31.5592C84.7797 31.5592 85.0875 31.5118 85.3668 31.4171C85.6462 31.3224 85.8853 31.1804 86.0842 30.991C86.283 30.8016 86.4345 30.5696 86.5387 30.295L89.337 30.4796C89.195 31.152 88.9038 31.7391 88.4634 32.241C88.0278 32.7382 87.4644 33.1264 86.7731 33.4058C86.0865 33.6804 85.2934 33.8177 84.3938 33.8177ZM96.3469 33.8177C95.2248 33.8177 94.2589 33.5904 93.4492 33.1359C92.6443 32.6766 92.024 32.0279 91.5884 31.1899C91.1528 30.3471 90.935 29.3504 90.935 28.1998C90.935 27.0777 91.1528 26.0928 91.5884 25.2453C92.024 24.3977 92.6372 23.7372 93.4279 23.2637C94.2234 22.7903 95.1561 22.5535 96.2262 22.5535C96.9459 22.5535 97.6159 22.6695 98.2362 22.9015C98.8612 23.1288 99.4057 23.4721 99.8697 23.9313C100.338 24.3906 100.703 24.9683 100.963 25.6643C101.224 26.3556 101.354 27.1653 101.354 28.0933V28.9242H92.1424V27.0492H98.506C98.506 26.6136 98.4113 26.2278 98.2219 25.8916C98.0326 25.5554 97.7698 25.2926 97.4336 25.1032C97.1022 24.9091 96.7163 24.812 96.2759 24.812C95.8166 24.812 95.4094 24.9186 95.0543 25.1316C94.704 25.34 94.4293 25.6217 94.2305 25.9768C94.0316 26.3272 93.9298 26.7178 93.9251 27.1487V28.9313C93.9251 29.4711 94.0245 29.9375 94.2234 30.3305C94.427 30.7235 94.7134 31.0265 95.0827 31.2396C95.4521 31.4527 95.89 31.5592 96.3967 31.5592C96.7328 31.5592 97.0406 31.5118 97.32 31.4171C97.5993 31.3224 97.8384 31.1804 98.0373 30.991C98.2362 30.8016 98.3877 30.5696 98.4918 30.295L101.29 30.4796C101.148 31.152 100.857 31.7391 100.417 32.241C99.9809 32.7382 99.4175 33.1264 98.7262 33.4058C98.0397 33.6804 97.2466 33.8177 96.3469 33.8177ZM106.07 30.4654L106.077 26.8362H106.517L110.012 22.6956H113.485L108.79 28.1785H108.073L106.07 30.4654ZM103.328 33.6046V19.0592H106.354V33.6046H103.328ZM110.147 33.6046L106.936 28.8532L108.953 26.7154L113.691 33.6046H110.147Z" fill="#1E1E1E"/>
<path d="M118.165 33.6046L114.188 19.0592H115.978L119.017 30.9058H119.159L122.256 19.0592H124.245L127.341 30.9058H127.483L130.523 19.0592H132.313L128.336 33.6046H126.517L123.307 22.0137H123.194L119.983 33.6046H118.165ZM137.696 33.8319C136.712 33.8319 135.847 33.5975 135.104 33.1288C134.365 32.66 133.788 32.0043 133.371 31.1615C132.959 30.3187 132.753 29.3338 132.753 28.2069C132.753 27.0706 132.959 26.0786 133.371 25.2311C133.788 24.3835 134.365 23.7254 135.104 23.2566C135.847 22.7879 136.712 22.5535 137.696 22.5535C138.681 22.5535 139.543 22.7879 140.282 23.2566C141.025 23.7254 141.603 24.3835 142.015 25.2311C142.431 26.0786 142.64 27.0706 142.64 28.2069C142.64 29.3338 142.431 30.3187 142.015 31.1615C141.603 32.0043 141.025 32.66 140.282 33.1288C139.543 33.5975 138.681 33.8319 137.696 33.8319ZM137.696 32.3262C138.444 32.3262 139.06 32.1345 139.543 31.751C140.026 31.3674 140.383 30.8632 140.615 30.2382C140.847 29.6132 140.963 28.9361 140.963 28.2069C140.963 27.4778 140.847 26.7983 140.615 26.1686C140.383 25.5388 140.026 25.0298 139.543 24.6416C139.06 24.2533 138.444 24.0592 137.696 24.0592C136.948 24.0592 136.333 24.2533 135.85 24.6416C135.367 25.0298 135.009 25.5388 134.777 26.1686C134.545 26.7983 134.429 27.4778 134.429 28.2069C134.429 28.9361 134.545 29.6132 134.777 30.2382C135.009 30.8632 135.367 31.3674 135.85 31.751C136.333 32.1345 136.948 32.3262 137.696 32.3262ZM145.198 33.6046V22.6956H146.817V24.3433H146.931C147.13 23.8035 147.49 23.3655 148.011 23.0294C148.531 22.6932 149.119 22.5251 149.772 22.5251C149.895 22.5251 150.049 22.5275 150.234 22.5322C150.418 22.5369 150.558 22.544 150.653 22.5535V24.2581C150.596 24.2438 150.466 24.2225 150.262 24.1941C150.063 24.161 149.853 24.1444 149.63 24.1444C149.1 24.1444 148.626 24.2557 148.21 24.4782C147.798 24.696 147.471 24.9991 147.229 25.3873C146.993 25.7708 146.874 26.2088 146.874 26.7012V33.6046H145.198ZM156.427 33.8319C155.518 33.8319 154.715 33.6023 154.019 33.143C153.323 32.679 152.779 32.0256 152.386 31.1828C151.993 30.3352 151.796 29.3338 151.796 28.1785C151.796 27.0327 151.993 26.0384 152.386 25.1956C152.779 24.3528 153.326 23.7017 154.026 23.2424C154.727 22.7831 155.537 22.5535 156.455 22.5535C157.165 22.5535 157.727 22.6719 158.138 22.9086C158.555 23.1406 158.872 23.4058 159.09 23.7041C159.313 23.9976 159.486 24.2391 159.609 24.4285H159.751V19.0592H161.427V33.6046H159.808V31.9285H159.609C159.486 32.1274 159.31 32.3783 159.083 32.6813C158.856 32.9796 158.531 33.2472 158.11 33.4839C157.689 33.7159 157.128 33.8319 156.427 33.8319ZM156.654 32.3262C157.326 32.3262 157.895 32.151 158.359 31.8007C158.823 31.4456 159.175 30.9555 159.417 30.3305C159.658 29.7008 159.779 28.974 159.779 28.1501C159.779 27.3357 159.661 26.6231 159.424 26.0123C159.187 25.3968 158.837 24.9186 158.373 24.5777C157.909 24.232 157.336 24.0592 156.654 24.0592C155.944 24.0592 155.352 24.2415 154.879 24.6061C154.41 24.9659 154.057 25.456 153.82 26.0762C153.588 26.6918 153.472 27.3831 153.472 28.1501C153.472 28.9266 153.591 29.6321 153.827 30.2666C154.069 30.8963 154.424 31.3982 154.893 31.7723C155.366 32.1416 155.953 32.3262 156.654 32.3262Z" fill="#0A99FE"/>
</svg>
<div class="allButtons">
<div class="headerButtons">Products</div>
<div class="headerButtons">Contatos</div>
</div>
</header>
<div class="container">
<Main>
<section>
<h1>Paintings</h1>
<ul>
<li><img src="./assets/img/painting/gamepad.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
<li><img src="./assets/img/painting/clock.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
<li><img src="./assets/img/painting/personagem.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
</ul>
</section>
<section>
<h1>Action Figures</h1>
<ul>
<li><img src="./assets/img/actions/animewoman.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
<li><img src="./assets/img/actions/dragonballpersonagem.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
<li><img src="./assets/img/actions/starwarspersonagem.jpg" height="275" width="207" alt="">
<p>
<h1>Main text</h1>
</p>
<p>Some leftover</p>
</li>
</ul>
</section>
</Main>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74320850,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 0,
"selected": false,
"text": "line-height: 40px;"
},
{
"answer_id": 74320945,
"author": "julien.giband",
"author_id": 3410989,
"author_profile": "https://Stackoverflow.com/users/3410989",
"pm_score": 1,
"selected": false,
"text": "flex"
},
{
"answer_id": 74321441,
"author": "Nuryanto",
"author_id": 20419807,
"author_profile": "https://Stackoverflow.com/users/20419807",
"pm_score": 0,
"selected": false,
"text": ".container {\n background-color: rgb(255, 255, 255);\n max-width: 95%;\n margin: 0 auto;\n}\n\nheader {\n display: flex;\n border-bottom: solid 1px black;\n padding: 10px;\n align-items: center;\n}\n\n.allButtons {\n display: flex;\n margin-left: auto;\n}\n\n.headerButtons {\n margin: 10px;\n background-color: rgb(10, 153, 254, .1);\n display: flex;\n justify-content: center;\n align-items: center;\n color: #0A99FE;\n font-size: 20px;\n width: 150px;\n height: 40px;\n border-radius: 10px;\n}\n\n.headerButtons a {\n text-decoration: none; // remove underscores in links, specific to that section.\n }\n\n.headerButtons:hover {\n background-color: #0A99FE;\n color: white;\n}\n\nul {\n margin: 0;\n padding: 0;\n border: 0;\n display: flex;\n list-style-type: none;\n}\n\nimg {\n border-radius: 10px;\n}\n\nli {\n margin-right: 10px;\n text-align: center;\n background-color: #f8f8f8;\n border-radius: 10px;\n align-content: center;\n}\n\nh1 {\n font-size: 20px;\n font-weight: 400;\n}\n\np {\n font-size: 16px;\n color: #868383;\n}\n\n#titleCards {\n font-weight: 500;\n}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419516/"
] |
74,320,761 | <p>I'm trying to implement simple sort with items that are in a state.</p>
<p>This will work perfectly, only problem is that the animation is now gone, because it doesn't have a key.</p>
<pre><code>LazyColumn(
state = listState,
) {
items(items.size) { index ->
val ticker = items[index]
Card(
modifier = Modifier
.fillMaxWidth()
.animateItemPlacement(), // This won't work
) {
Item(...)
}
}
}
</code></pre>
<p>But If I try to change it to:</p>
<pre><code>items(items.size, key = { items[it].name }) { index ->
</code></pre>
<p>or If I use:</p>
<pre><code>items(items, key = { items[it].name }) { item ->
</code></pre>
<p>It will have animations, but it will move items above and below current scroll position (even if you don't move).
The wanted result is that you stay on top of the items, because we didn't move.</p>
<p>This is in a viewModel:</p>
<pre><code>private val _state = MutableStateFlow<Response<List<Item>>>(Response.Loading)
val state get() = _state
</code></pre>
<pre><code>private fun updateList() {
viewModelScope.launch(Dispatchers.IO) {
client.getItems()
.onSuccess {
unFilteredList = it.toMutableList()
val filteredList = filterList()
_tickerListState.value = Response.Success(filteredList)
}
.onFailure {}
}
}
</code></pre>
| [
{
"answer_id": 74320850,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 0,
"selected": false,
"text": "line-height: 40px;"
},
{
"answer_id": 74320945,
"author": "julien.giband",
"author_id": 3410989,
"author_profile": "https://Stackoverflow.com/users/3410989",
"pm_score": 1,
"selected": false,
"text": "flex"
},
{
"answer_id": 74321441,
"author": "Nuryanto",
"author_id": 20419807,
"author_profile": "https://Stackoverflow.com/users/20419807",
"pm_score": 0,
"selected": false,
"text": ".container {\n background-color: rgb(255, 255, 255);\n max-width: 95%;\n margin: 0 auto;\n}\n\nheader {\n display: flex;\n border-bottom: solid 1px black;\n padding: 10px;\n align-items: center;\n}\n\n.allButtons {\n display: flex;\n margin-left: auto;\n}\n\n.headerButtons {\n margin: 10px;\n background-color: rgb(10, 153, 254, .1);\n display: flex;\n justify-content: center;\n align-items: center;\n color: #0A99FE;\n font-size: 20px;\n width: 150px;\n height: 40px;\n border-radius: 10px;\n}\n\n.headerButtons a {\n text-decoration: none; // remove underscores in links, specific to that section.\n }\n\n.headerButtons:hover {\n background-color: #0A99FE;\n color: white;\n}\n\nul {\n margin: 0;\n padding: 0;\n border: 0;\n display: flex;\n list-style-type: none;\n}\n\nimg {\n border-radius: 10px;\n}\n\nli {\n margin-right: 10px;\n text-align: center;\n background-color: #f8f8f8;\n border-radius: 10px;\n align-content: center;\n}\n\nh1 {\n font-size: 20px;\n font-weight: 400;\n}\n\np {\n font-size: 16px;\n color: #868383;\n}\n\n#titleCards {\n font-weight: 500;\n}"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4527839/"
] |
74,320,765 | <p>I am looking to remove END from 'Task' column if there is no START before it. The data can be grouped by 'Session' and if the first occurance of the 'Task' is END, then I want to replace that specific occurrence with nAn value.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>Session</th>
<th>Task</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>END</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>START</td>
</tr>
<tr>
<td>4</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td>1</td>
<td>END</td>
</tr>
<tr>
<td>6</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>7</td>
<td>2</td>
<td>START</td>
</tr>
<tr>
<td>8</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>9</td>
<td>2</td>
<td>END</td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>11</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>12</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>13</td>
<td>3</td>
<td>START</td>
</tr>
<tr>
<td>14</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>15</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>16</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>17</td>
<td>4</td>
<td>START</td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td>END</td>
</tr>
</tbody>
</table>
</div>
<p>the DataFrame</p>
<pre><code>import pandas as pd
d = {'Session':[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4],
'Task':['', 'END', '', 'START', '', 'END', '', 'START', '', 'END', '', '', '', 'START', '', '', '', 'START', '', '', 'END']}
df = pd.DataFrame(data=d)
</code></pre>
<p>My initial thought was to get the first occurrence of 'Task' for each group, in a different data frame df2, and filter only rows with 'END' value, and then use index of df2 to remove the value from the original df.</p>
<p>Below is the expected table</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>Session</th>
<th>Task</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>START</td>
</tr>
<tr>
<td>4</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td>1</td>
<td>END</td>
</tr>
<tr>
<td>6</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>7</td>
<td>2</td>
<td>START</td>
</tr>
<tr>
<td>8</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>9</td>
<td>2</td>
<td>END</td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>11</td>
<td>2</td>
<td></td>
</tr>
<tr>
<td>12</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>13</td>
<td>3</td>
<td>START</td>
</tr>
<tr>
<td>14</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>15</td>
<td>3</td>
<td></td>
</tr>
<tr>
<td>16</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>17</td>
<td>4</td>
<td>START</td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>18</td>
<td>4</td>
<td>END</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74321225,
"author": "DarrylG",
"author_id": 3066077,
"author_profile": "https://Stackoverflow.com/users/3066077",
"pm_score": 1,
"selected": false,
"text": "def remove_unmatched(x):\n ' removes \"END\" value when not preceeded by \"START\" '\n preceeded = False\n result = []\n for z in x:\n if z == \"START\":\n preceeded = True # Set preceeded to True since found a start\n result.append(z)\n elif z == \"END\":\n result.append(z if preceeded else \"\") # \"END\" or \"\" based upon whether preceede by \"START\"\n preceeded = False\n else:\n result.append(z) # value lunchanged\n \n return pd.Series(result, index = x.index) # new series\n\ndf['Task'] = df.groupby('Session')['Task'].apply(remove_unmatched) # provides desired df\n"
},
{
"answer_id": 74321542,
"author": "Nathan Furnal",
"author_id": 9479128,
"author_profile": "https://Stackoverflow.com/users/9479128",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nidx = df.where(df.groupby('Session').first().eq('END'))['Task'] == 'END'\ndf.loc[idx, 'Task'] = np.nan\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,320,804 | <p>I have a react-native project which will fetch all of a users Ethereum tokens, hopefully, using the Alchemy SDK. I have a function that should retrieve all token balances according to the documentation.</p>
<pre><code>import 'react-native-get-random-values';
import '@ethersproject/shims';
import { Network, Alchemy, Wallet } from 'alchemy-sdk';
import {ALCHEMY_API_KEY} from '@env';
const settings = {
apiKey: ALCHEMY_API_KEY,
network: Network.ETH_GOERLI
};
const alchemy = new Alchemy(settings);
export const getAllBalances = async (address) => {
try {
const balances = await alchemy.core.getTokenBalances(address, 'erc20');
return balances;
} catch (err) {
console.log(err.message);
}
}
</code></pre>
<p>However, when this runs I get this error message.</p>
<pre><code>"invalid 2nd argument: contract_addresses was not a valid contract address array, string literals 'DEFAULT_TOKENS' or 'erc20', or a valid options object.\"
</code></pre>
<p>As you can see, my 2nd argument is 'erc20' as the message states that the 2nd argument should be. I also tried 'DEFAULT_TOKENS' and receive the same error message. If I just try to retrieve the basic eth tokens in an account I have no issues so I believe that my settings are correct. Does anyone know how to fix this issue?</p>
| [
{
"answer_id": 74321225,
"author": "DarrylG",
"author_id": 3066077,
"author_profile": "https://Stackoverflow.com/users/3066077",
"pm_score": 1,
"selected": false,
"text": "def remove_unmatched(x):\n ' removes \"END\" value when not preceeded by \"START\" '\n preceeded = False\n result = []\n for z in x:\n if z == \"START\":\n preceeded = True # Set preceeded to True since found a start\n result.append(z)\n elif z == \"END\":\n result.append(z if preceeded else \"\") # \"END\" or \"\" based upon whether preceede by \"START\"\n preceeded = False\n else:\n result.append(z) # value lunchanged\n \n return pd.Series(result, index = x.index) # new series\n\ndf['Task'] = df.groupby('Session')['Task'].apply(remove_unmatched) # provides desired df\n"
},
{
"answer_id": 74321542,
"author": "Nathan Furnal",
"author_id": 9479128,
"author_profile": "https://Stackoverflow.com/users/9479128",
"pm_score": 0,
"selected": false,
"text": "import numpy as np\n\nidx = df.where(df.groupby('Session').first().eq('END'))['Task'] == 'END'\ndf.loc[idx, 'Task'] = np.nan\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13949933/"
] |
74,320,853 | <p><a href="https://i.stack.imgur.com/nf7L0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nf7L0.png" alt="enter image description here" /></a></p>
<p>It doesn't show me the code output. Should I change the setting or configure something ?</p>
<p>I tried edit task.json and reinstall VScode.</p>
| [
{
"answer_id": 74321550,
"author": "oarcas",
"author_id": 7920351,
"author_profile": "https://Stackoverflow.com/users/7920351",
"pm_score": 0,
"selected": false,
"text": "cd /Users/seal/Desktop/projects/cpp\n./practice\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419726/"
] |
74,320,884 | <p><code>enter code here</code>This is the original code that I wrote:</p>
<pre><code>while True:
user_input = (input(">>",))
try:
user_input = int(user_input)
except ValueError:
pass
if user_input in range(1, len(something):
break
</code></pre>
<p>I want to put in a method:</p>
<pre><code>`get_user_answer(n: int, p: str) -> int` # This is what the method should look like kind of
#But what should I write here?
def main()
# and how would I call it?
main()
</code></pre>
<p>I'm learning about methods so I'm confused</p>
<p>I'm expecting it to work like the code I first wrote, but in a method instead that I call to the main function.</p>
| [
{
"answer_id": 74321550,
"author": "oarcas",
"author_id": 7920351,
"author_profile": "https://Stackoverflow.com/users/7920351",
"pm_score": 0,
"selected": false,
"text": "cd /Users/seal/Desktop/projects/cpp\n./practice\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74320884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20419708/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.