qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,224,926 | <p>When we build an executable, and it gets loaded into RAM, my understanding is that the <code>.text</code> and <code>.ro</code> setions should be loaded into read-only memory locations. With an operating system and a virtual memory controller I can understand how the different sections could get loaded to the right memory locations.</p>
<p>However, considering a bare-metal system without an operating system and an ARM chip for example. How is the read-only attribute of those sections achieved. They could be stored in ROM or Flash? But then doesn't everything get loaded into RAM anyways? Thanks in advance.</p>
| [
{
"answer_id": 74225292,
"author": "the busybee",
"author_id": 11294831,
"author_profile": "https://Stackoverflow.com/users/11294831",
"pm_score": 2,
"selected": true,
"text": "const"
},
{
"answer_id": 74243684,
"author": "Clifford",
"author_id": 168986,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74224926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4768946/"
] |
74,224,947 | <p>I have the following Cycle Schema</p>
<pre class="lang-js prettyprint-override"><code>const mongoose=require('mongoose')
const Schema = mongoose.Schema;
const cycleSchema= new Schema({
startDate:{type:Date,required:true},
endDate:{type:Date,required:true},
users:[
{
firstName:String,
lastName:String,
goals:[{
mainGoal:String,
progress:{
type:Number,
default:0
},
subTasks: [{
task:String,
done:Boolean
}]
}]
}
]
},{
timestamps:true
})
const Cycle= mongoose.model('Cycle', cycleSchema)
module.exports = Cycle
</code></pre>
<p>And we import the above model to routes file as below</p>
<pre class="lang-js prettyprint-override"><code>const router = require('express').Router()
const Cycle = require('../models/cycle.model')
router.route('/').get((req,res)=>{
console.log("getting cycles ..")
Cycle.find()
.then(cycle=>res.json(cycle))
.catch(err=>res.status(400).json("Error "+ err))
})
router.route('/add').post((req,res)=>{
const startDate= Date.parse ( req.body.startDate)
const endDate= Date.parse ( req.body.endDate)
const users=req.body.users
const newCycle=new Cycle({
startDate,endDate,users
})
router.route('/:id').get((req,res)=>{
Cycle.findById(req.params.id)
.then(cycle=>res.json(cycle))
.catch(err=>res.status(400).json('Error:' + err))
})
module.exports = router
</code></pre>
<p>And this is imported in server.js</p>
<pre class="lang-js prettyprint-override"><code>
const cyclesRouter=require('./routes/cycles')
app.use('/cycles', cyclesRouter)
</code></pre>
<p>then we run the server and try the Get cycles request in postman we get something like this</p>
<p><a href="https://i.stack.imgur.com/9n6qn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9n6qn.png" alt="enter image description here" /></a></p>
<p>But when we try to get that specific cycle by using the id parameter as below , we get the 404 error as below
<a href="https://i.stack.imgur.com/DH7V7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DH7V7.png" alt="enter image description here" /></a></p>
<p>The mongodb CLI has the following structure
<a href="https://i.stack.imgur.com/Om9Gc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Om9Gc.png" alt="enter image description here" /></a>
Any help here would be appreciated</p>
| [
{
"answer_id": 74225166,
"author": "MahendraKumar sahu",
"author_id": 9169183,
"author_profile": "https://Stackoverflow.com/users/9169183",
"pm_score": 1,
"selected": false,
"text": "var ObjectId = require('mongodb').ObjectID;\n\n\nCycle.findById(new ObjectId(req.params._id))\n .then(... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74224947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4223447/"
] |
74,225,012 | <p>I have an assignment for class that tasks me with creating a function in R that takes in a vector of values and converts them between Fahrenheit, Celsius and Kelvin. The example that I try to run through my code should produce a return vector that contains only 3 values, yet it is returning a vector that holds 26 values.</p>
<p>Here is my code below:</p>
<pre><code>convTemp <- function(x, from = "C", to = "F") {
newX <- vector("double", length(x))
if (from == to) {
warning("Your 'from' parameter is the same as your 'to' parameter!") # From and To are same temperature scale
}
if (from == "C" && to == "F") { # Celsius to Fahrenheit
for (i in x) {
newX[i] <- ((9/5)*x[i]+32)
}
}
if (from == "C" && to == "K") { # Celsius to Kelvin
for (i in x) {
newX[i] <- (x[i]+273.15)
}
}
if (from == "F" && to == "C") { # Fahrenheit to Celsius
for (i in x) {
newX[i] <- ((x[i]-32)*(5/9))
}
}
if (from == "K" && to == "C") { # Kelvin to Celsius
for (i in x) {
newX[i] <- (x[i]-273.15)
}
}
if (from == "F" && to == "K") { # Fahrenheit to Kelvin
for (i in x) {
newX[i] <- ((((x[i]-32)*5)/9)+273.15)
}
}
if (from == "K" && to == "F") { # Kelvin to Fahrenheit
for (i in x) {
newX[i] <- ((((x[i]-273.15)*9)/5)+32)
}
}
return(newX)
}
convTemp(c(35,40,45), from="F", to="K")
</code></pre>
<p>And here is the output I'm receiving:</p>
<pre><code> [1] 0 0 0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
</code></pre>
<p>So I'm not sure why the function is returning such a large vector of missing values when it should be returning a vector of 3 Kelvin values.</p>
| [
{
"answer_id": 74225040,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 3,
"selected": true,
"text": "for(i in x)"
},
{
"answer_id": 74225222,
"author": "onyambu",
"author_id": 8380272,
"author_profile... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15697584/"
] |
74,225,051 | <p>I have to implement a system where a tenant can store multiple key-value stores. one key-value store can have a million records, and there will be multiple columns in one store</p>
<p>[Edited] I have to store tabular data (list with multiple columns) like Excel where column headers will be unique and have no defined schema.
This will be a kind of static data (eventually updated).
We will provide a UI to handle those updates.
Every tenant would like to store multiple table structured data which they have to refer it in different applications and the contract will be JSON only.</p>
<p>For Example, an Organization/Tenant wants to store their Employees List/ Country-State List, and there are some custom lists that are customized for the product and this data is in millions.</p>
<p>A simple solution is to use SQL but here schema is not defined, this is a user-defined schema, and though I have handled this in SQL, there are some performance issues, so I want to choose a NoSQL DB that suits better for this requirement.</p>
<p>Design Constraints:</p>
<ol>
<li>Get API latency should be minimum.</li>
<li>We can simply assume the Pareto rule, 80:20 80% read calls and 20% write so it is a read-heavy application</li>
<li>Users can update one of the records/one columns</li>
<li>Users can do queries based on some column value, we need to implement indexes on multiple columns.</li>
<li>It's schema-less so we can simply assume it is NoSql, SQL also supports JSON but it is very hard to update a single row, and we can not define indexes on dynamic columns.</li>
<li>I want to segregate key-values stores per tenant, no list will be shared between tenants.</li>
</ol>
<p>One Key Value Store :</p>
<p><a href="https://i.stack.imgur.com/O35uG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O35uG.png" alt="enter image description here" /></a></p>
<p>Another key value store example: <a href="https://datahub.io/core/country-list" rel="nofollow noreferrer">https://datahub.io/core/country-list</a></p>
<p>I am thinking of Cassandra or any wide-column database, we can also think of a document database (Mongo DB), every collection can be a key-value store or Amazon Dynamo database</p>
<p>Cassandra: allows you to partition data by partition key and in my use case I may want to get data by different columns in Cassandra we have to query all partitions which will be expensive.</p>
| [
{
"answer_id": 74225040,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 3,
"selected": true,
"text": "for(i in x)"
},
{
"answer_id": 74225222,
"author": "onyambu",
"author_id": 8380272,
"author_profile... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/358136/"
] |
74,225,052 | <p>I have been trying to use Split and Filter to display ONLY the duplicate zip codes within a column list of zip codes. Column A shows location name (irrevelant) and column B is a comma-separated list of zips. In column C+ I want only the zip codes that are a duplicate of the entire column B to be shown.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Location Name</th>
<th>Zip Code List</th>
<th>[Output]Col C</th>
<th>Col D</th>
<th>Col E</th>
</tr>
</thead>
<tbody>
<tr>
<td>Home 1</td>
<td>37075,37066,37072</td>
<td>37075</td>
<td>37066</td>
<td>37072</td>
</tr>
<tr>
<td>Home 2</td>
<td>37066,37072</td>
<td>37066</td>
<td>37072</td>
<td></td>
</tr>
<tr>
<td>Home 3</td>
<td>37072,37112,37089</td>
<td>37072</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Home 4</td>
<td>37075,37067</td>
<td>37075</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<p>In this case above, Column C, D, E are the expected output.</p>
<p>I currently have the following in cell C2
<code>=filter(split(B2,","),arrayformula(countif(split(B2,","),B2)>1))</code></p>
<p>But this is not working.</p>
| [
{
"answer_id": 74227410,
"author": "TheMaster",
"author_id": 8404453,
"author_profile": "https://Stackoverflow.com/users/8404453",
"pm_score": 3,
"selected": true,
"text": "SPLIT"
},
{
"answer_id": 74227703,
"author": "CodeCamper",
"author_id": 2446698,
"author_profil... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20350668/"
] |
74,225,059 | <p>I have the following dataframe.</p>
<pre><code>temp = structure(list(A = c(0, 0, 0, 3.72900887033786, 1.94860084749336,
0), C = c(0, 0, 0, 3.44095219802964, 2.35049724708413, 0.0285691521967709
), A = c(0, 0, 0, 3.29572302453997, 0.933572638261024, 0), D = c(0,
0, 0, 2.4905701304462, 1.54101915313356, 0), E = c(0, 0, 0, 4.23189316164533,
1.7311832415722, 0), E = c(0, 0, 0, 4.37851162325373, 2.50080205305716,
0), D = c(0, 0, 0, 3.68929916053589, 2.4905701304462, 0.189033824390017
), F = c(0, 2.27500704749987, 0, 3.68032435684402, 1.77820857639809,
0), A = c(0, 0, 0, 3.5668151540109, 1.72683121703249, 0.0285691521967709
), G = c(0, 0, 0, 5.6450098843911, 3.09929520433778, 0)), row.names = c("5_8S_rRNA",
"5S_rRNA", "7SK", "A1BG", "A1BG-AS1", "A1CF"), class = "data.frame")
</code></pre>
<p>It looks like this.</p>
<pre><code> A C A D E E D F A G
5_8S_rRNA 0.000000 0.00000000 0.0000000 0.000000 0.000000 0.000000 0.0000000 0.000000 0.00000000 0.000000
5S_rRNA 0.000000 0.00000000 0.0000000 0.000000 0.000000 0.000000 0.0000000 2.275007 0.00000000 0.000000
7SK 0.000000 0.00000000 0.0000000 0.000000 0.000000 0.000000 0.0000000 0.000000 0.00000000 0.000000
A1BG 3.729009 3.44095220 3.2957230 2.490570 4.231893 4.378512 3.6892992 3.680324 3.56681515 5.645010
A1BG-AS1 1.948601 2.35049725 0.9335726 1.541019 1.731183 2.500802 2.4905701 1.778209 1.72683122 3.099295
A1CF 0.000000 0.02856915 0.0000000 0.000000 0.000000 0.000000 0.1890338 0.000000 0.02856915 0.000000
</code></pre>
<p>What I'd like to do is collapse any column that are duplicates by averaging duplicates, but I want to do this for each row.</p>
<p>The ideal dataframe would contain the same amount of rows, but would only contain columns A, C, D, E, F, G. Is this possible?</p>
| [
{
"answer_id": 74225085,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 4,
"selected": true,
"text": "split.default"
},
{
"answer_id": 74225225,
"author": "Jilber Urbina",
"author_id": 1315767,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2759385/"
] |
74,225,061 | <p><a href="https://i.stack.imgur.com/MslaM.jpg" rel="nofollow noreferrer">Graph</a></p>
<p>I want to convert dates to quarters but I only want to display quarters once in altair because it would jam my x-axis column.</p>
<p>Is there a way to aggregate this?</p>
<p>The data/code is</p>
<pre><code>data[['date', 'percentage']]
alt.Chart(df_avg)
.mark_line(strokeDash=[5, 5])
.encode(
x=alt.X("date:N", title="Date", sort=None),
y=alt.Y(
"value:Q",
axis=alt.Axis(format=y_axis_format),
scale=alt.Scale(domain=y_axis_scale),
title=title,
),
color=alt.Color("series:N", title="Legend", scale=alt.Scale(domain=domain, range=range_)),
)
)
</code></pre>
<p>EDIT:</p>
<p><a href="https://i.stack.imgur.com/trAfH.png" rel="nofollow noreferrer">Dates</a></p>
<p>The above shows the actual data. I'm trying the resampling method of df['month'].resample('Q', label = 'right') and I'm getting an error that says</p>
<pre><code>
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex
</code></pre>
<p>How can I alter this data so it works out with the resampling method?</p>
| [
{
"answer_id": 74225085,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 4,
"selected": true,
"text": "split.default"
},
{
"answer_id": 74225225,
"author": "Jilber Urbina",
"author_id": 1315767,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15686117/"
] |
74,225,112 | <p>I have a table listing my todos. In the last column, I have a button to mark the todo as finished. Because I'd like to reuse this button in other tables and views, I've added it as a component that is being imported.</p>
<p>Furthermore, I'd like to use a table package such as <code>vue3-table-lite</code> so that I can have quick and easy access to 1) filtering, 2) pagination, and 3) sorting features.</p>
<p>These packages typically uses <code>:rows</code>, which is pretty straightforward if you only have text. However, I don't know how to provide Vue components, in this case <code><FinishedButton /></code> from the last <code><td></code> shown in the last code block below.</p>
<p><strong>How can I import Vue components into <code>:rows</code> of a table? Alternatively achieve filtering, pagination, and sorting without having to use <code>:rows</code> at all.</strong></p>
<hr />
<p>Here's how the button component is constructed:</p>
<pre><code><template>
<a v-show="todo.is_finishable" v-on:click="markFinished(todo.id)"
class="todo_finished btn btn-sm btn-light btn-light-border finalized_button">Finished</a>
</template>
<script>
export default {
name: 'FinishedButton',
props: ['todo',],
methods: {
remove: function () {
this.$emit("delete", this.todo);
},
markFinished: function (selected_todo_id) {
this.$http.patch('/api/todo/' + selected_todo_id + "/", {
status: 'Done'
})
.then(response => {
console.log(response);
this.remove();
})
.catch(e => {
console.log(e);
});
}
},
};
</script>
</code></pre>
<p>Here's how a simplified version of the table looks like (there's more columns in the actual table):</p>
<pre><code><table id="FOO" class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr v-for="todo in todos" :key="todo.id">
<td>{{ todo.name }}</td>
<td><FinishedButton :todo=todo /></td>
</tr>
</tbody>
</table>
</code></pre>
| [
{
"answer_id": 74225085,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 4,
"selected": true,
"text": "split.default"
},
{
"answer_id": 74225225,
"author": "Jilber Urbina",
"author_id": 1315767,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7522891/"
] |
74,225,128 | <p>The code below has stopped working since URL was changed from:
<a href="http://ec.europa.eu/taxation_customs/vies/services/checkVatService" rel="nofollow noreferrer">http://ec.europa.eu/taxation_customs/vies/services/checkVatService</a>
to:
<a href="https://ec.europa.eu/taxation_customs/vies/#/vat-validation" rel="nofollow noreferrer">https://ec.europa.eu/taxation_customs/vies/#/vat-validation</a></p>
<p>What should I correct in order to fix the code?
I would much appreciate your help.</p>
<pre><code>Sub VATCHECK()
Dim sURL As String
Dim sEnv As String
Dim xmlhttp As New MSXML2.xmlhttp
Dim xmlDoc As New MSXML2.DOMDocument 'DOMDocument
Dim sCountryCode As String
Dim sVATNo As String
Dim i As Long
On Error Resume Next
Range("D2", Range("D2").End(xlDown)).Clear
If Cells(Rows.Count, 1).End(xlUp).Row < 2 Then Exit Sub
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
sURL = "https://ec.europa.eu/taxation_customs/vies/#/vat-validation"
sCountryCode = Range("B" & i).Value
sVATNo = Range("C" & i).Value
sEnv = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"">"
sEnv = sEnv & "<soapenv:Header/>"
sEnv = sEnv & "<soapenv:Body>"
sEnv = sEnv & "<urn:checkVat>"
sEnv = sEnv & "<urn:countryCode>" & sCountryCode & "</urn:countryCode>"
sEnv = sEnv & "<urn:vatNumber>" & sVATNo & "</urn:vatNumber>"
sEnv = sEnv & "</urn:checkVat>"
sEnv = sEnv & "</soapenv:Body>"
sEnv = sEnv & "</soapenv:Envelope>"
With xmlhttp
.Open "POST", sURL, False
.setRequestHeader "Content-Type", "text/xml;"
.send sEnv
Set xmlDoc = New MSXML2.DOMDocument
xmlDoc.LoadXML .responseText
If Range("A" & i).Value = 0 Then
Range("D" & i).Value = ""
Else
If LCase(xmlDoc.getElementsByTagName("valid").Item(0).Text) = "true" Then
Range("D" & i).Value = "Valid VAT number"
Else
Range("D" & i).Value = "Invalid VAT number"
End If
End If
End With
Next i
End Sub
</code></pre>
<p>Changed URL but the code still does not work.</p>
| [
{
"answer_id": 74225085,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 4,
"selected": true,
"text": "split.default"
},
{
"answer_id": 74225225,
"author": "Jilber Urbina",
"author_id": 1315767,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20097611/"
] |
74,225,130 | <p>I'm very new to C, and I want to make a simple program that gets an index of a string from the value, and once it has the index, it removes it from a string. It's causing a buffer overflow error? Pretty sure it's from strcat from searching online but I'm not sure. Any help is appreciated! Also please don't use * in your answer, because I don't know how they work, I will learn very soon. (if its required for your answer, explain how you use it in the code please)</p>
<p>heres the code:</p>
<pre><code>#include <string.h>
int findIndex(char string[], char substr) {
for (int index = 0; index < strlen(string); index++) {
if (string[index] == substr) {
return index;
}
}
return -1;
}
int main(void) {
char howAreYou[9] = "howAreYou";
char newString[9];
int index = findIndex(howAreYou, 'o');
for (int i = 0; i < 8; i++) {
if (i != index) {
strncat(newString, &howAreYou[i], 1);
}
}
printf("new string: %s", newString);
return 0;
}
</code></pre>
| [
{
"answer_id": 74225405,
"author": "user3121023",
"author_id": 3121023,
"author_profile": "https://Stackoverflow.com/users/3121023",
"pm_score": -1,
"selected": true,
"text": "char howAreYou[] = \"howAreYou\";"
},
{
"answer_id": 74225412,
"author": "Vlad from Moscow",
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,225,170 | <p>I have a product table (1) and a fruit list table (2). I group by product ID and check if any fruit from the fruit table (2) is in the group by from table 1 with this group by statement. How can I check if the group by from table 1 also includes 'potato'. So results should be PID 1 and 3</p>
<p>table1</p>
<pre><code>PID | PRODUCT
1 | potato
1 | apple
1 | banana
1 | melon
1 | peach
2 | lime
2 | apple
2 | pear
2 | melon
3 | pear
3 | apple
3 | potato
3 | mango
3 | plum
</code></pre>
<p>table2</p>
<pre><code>FID | FRUIT
1 | peach
2 | lime
3 | apple
4 | pear
5 | apple
6 | banana
7 | melon
</code></pre>
<pre><code>
SELECT PID, COUNT(*)
FROM table1
GROUP BY PID, PRODUCT
HAVING PRODUCT in (SELECT FRUIT FROM table2)
</code></pre>
| [
{
"answer_id": 74225233,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 1,
"selected": false,
"text": "SELECT t1.PID\nFROM table1 t1\nLEFT JOIN table2 t2\n ON t2.FRUIT = t1.PRODUCT\nGROUP BY t1.PID\nHAVING CO... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18059806/"
] |
74,225,175 | <p>I have a data.table that I am trying to filter. Basically, for any row that has a value of "--" (they are all characters, and that was put in place of NA) in any one of about 750 columns, I want to delete that row.</p>
<p>Here is a sample dataset:</p>
<pre><code>library(tidyverse)
library(data.table)
snp <- c(1:5)
id1 <- c("AA", "AB", "BB", "--", "AA")
id2 <- c(rep("AA", 5))
id3 <- c("BB", "AB", "--", "AA", "AA")
data1 <- as.data.table(cbind(snp, id1, id2, id3))
data1
</code></pre>
<p>I also have a version of this dataset that is transposed, so I could filter out any column that has "--" in it, but I figured filtering rows would be easier.</p>
<p>Since there are hundreds of columns with strange names, I can't write out a function that includes each one with & between each one, such as:</p>
<pre><code>data2 <- data1 %>%
filter(id1 != "--" & id2 != "--" & id3 != "--")
data2
</code></pre>
<p>How can I filter based on every column at once with so many columns?</p>
<p>Thank you!</p>
<p>P.S. I know this sounds easy, but I have been searching for an answer for awhile and have come up dry.</p>
| [
{
"answer_id": 74225196,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 1,
"selected": false,
"text": "if_all"
},
{
"answer_id": 74225980,
"author": "SteveM",
"author_id": 3574156,
"author_profile": "h... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16870643/"
] |
74,225,221 | <p>I came up with a solution but it does not perform well enough to pass with very large inputs. Any way of maybe doing it without iterating?</p>
<blockquote>
<p>Challange:
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.</p>
<p>Note: sequence a0, a1, ..., an is considered to be a strictly increasing if a0 < a1 < ... < an. Sequence containing only one element is also considered to be strictly increasing.</p>
<p>Example</p>
<p>For sequence = [1, 3, 2, 1], the output should be
solution(sequence) = false.</p>
<p>There is no one element in this array that can be removed in order to get a strictly increasing sequence.</p>
<p>For sequence = [1, 3, 2], the output should be
solution(sequence) = true.</p>
<p>You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you can remove 2 to get the strictly increasing sequence [1, 3].</p>
<p>Input/Output</p>
<p>[execution time limit] 4 seconds (py3)</p>
<p>[input] array.integer sequence</p>
<p>Guaranteed constraints:
2 β€ sequence.length β€ 105,
-105 β€ sequence[i] β€ 105.</p>
<p>[output] boolean</p>
<p>Return true if it is possible to remove one element from the array in order to get a strictly increasing sequence, otherwise return false.</p>
</blockquote>
<p>My solution is below and it seems to work however it does not perform well enough with very large inputs to count as a solution.</p>
<p>My Solution:</p>
<pre><code>def solution(sequence):
for number in range(len(sequence)):
shortened = sequence.copy()
shortened.pop(number)
if len(shortened) == len(set(shortened)):
if shortened == sorted(shortened):
return True
return False
</code></pre>
| [
{
"answer_id": 74225196,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 1,
"selected": false,
"text": "if_all"
},
{
"answer_id": 74225980,
"author": "SteveM",
"author_id": 3574156,
"author_profile": "h... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18218525/"
] |
74,225,239 | <p>I met the following issue that compose file</p>
<pre><code>version: '3'
services:
minkowski:
build:
context: .
dockerfile: DockerfileGPU
volumes:
- "../:/app:rw"
- "${DATA_PATH}:/app/data:rw"
working_dir: /app
tty: true
stdin_open: true
network_mode: "host"
runtime: nvidia
</code></pre>
<p>results in</p>
<pre><code>ERROR: The Compose file './docker/compose-gpu.yaml' is invalid because:
services.minkowski.build contains unsupported option: 'runtime'
</code></pre>
<p>I have docker version 20.10.21 and docker-compose 1.25.0. Do you have any idea why that happens?</p>
<p>I tried use different versions. Running</p>
<pre><code>sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
</code></pre>
<p>works fine</p>
| [
{
"answer_id": 74225196,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 1,
"selected": false,
"text": "if_all"
},
{
"answer_id": 74225980,
"author": "SteveM",
"author_id": 3574156,
"author_profile": "h... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13608832/"
] |
74,225,252 | <p>I'm a bit stuck on an exercice I have to make and I can't figure out the best way to do it.</p>
<p>I have to make a method that asks a question and expects Y or N. So I thought I would make a boolean method to return true or false, but the problem is that it would also return false if the user puts something other than Y or N. If I'm not mistaken, a boolean method cannot return null.</p>
<p>I'm very new to java and I'm not very far in my course so this problem will probably have a very simple solution. I also tried looking for an answer but didn't seem to find what I was looking for.</p>
<p>This is what I have with the boolean method but i'm not quite happy with it:</p>
<pre><code> public static boolean test() {
Scanner sc = new Scanner(System.in);
System.out.println("question");
String reponse = sc.next();
if (reponse.equalsIgnoreCase("Y")) {
return true;
}
else if (reponse.equalsIgnoreCase("N")) {
return false;
}
else {
return false;
}
}
</code></pre>
| [
{
"answer_id": 74225277,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 2,
"selected": false,
"text": "equalsIgnoreCase(\"Y\")"
},
{
"answer_id": 74225416,
"author": "OH GOD SPIDERS",
"aut... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9022721/"
] |
74,225,257 | <p>The question has changed since its initial posting as I've chased down a few leads. At this point, I'd say that I'm really looking for the following answers:</p>
<ol>
<li><p>Can a significant amount of time be saved by replacing addition/multiplication followed by a modulo 2 operation with and/logical_xor (assuming that the total number of such operations is kept the same)? If not, then why not? <em>ANSWER: some time can indeed be saved, but it's arguable whether that amount is "significant"</em>.</p>
</li>
<li><p>Where can I read more about the specific approach taken by the BLAS matrix multiplication underlying numpy? Ideally, I'd like a source that doesn't require deciphering the FORTRAN code forged by the sages of the past. <em>ANSWER: The original paper proposing the BLAS matrix multiplication algorithms used today <a href="https://www.researchgate.net/publication/234792010_A_Set_of_Level_3_Basic_Linear_Algebra_Subprograms" rel="nofollow noreferrer">can be found here</a></em>.</p>
</li>
</ol>
<p>I've left my question in its original form below for posterity.</p>
<hr />
<p>The following are two algorithms for multiplying binary matrices (i.e. taking the "dot" product) modulo 2. The first ("default") approach just uses numpy matrix-multiplication, then reduces modulo 2. The second ("alternative") approach attempts to speed things up by replacing the addition operation with an xor operation.</p>
<pre><code>import timeit
import numpy as np
import matplotlib.pyplot as plt
def mat_mult_1(A,B):
return A@B%2
def mat_mult_2(A,B):
return np.logical_xor.reduce(A[:,:,None]&B[None,:,:],axis = 1)
</code></pre>
<p>Contrary to my expectations, the alternative approach seems to take about 4 times longer than the default for products of larger binary matrices. Why is that? Is there some way I could speed up my alternative approach?</p>
<p>Here's the script I used to test the above two methods</p>
<pre><code>n_vals = np.arange(5,205,5)
times = []
for n in n_vals:
s_1 = f"mat_mult_1(np.random.randint(2,size = ({n},{n}))\
,np.random.randint(2,size = ({n},{n})))"
s_2 = f"mat_mult_2(np.random.randint(2,size = ({n},{n})),\
np.random.randint(2,size = ({n},{n})))"
times.append((timeit.timeit(s_1, globals = globals(), number = 100),
timeit.timeit(s_2, globals = globals(), number = 100)))
</code></pre>
<p>and here are two plots of the results.</p>
<p><a href="https://i.stack.imgur.com/bPUXj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bPUXj.png" alt="enter image description here" /></a></p>
<hr />
<p>Minor updates:</p>
<p>I was able to test these out for larger matrices (up to 1000x1000) and get a better sense of the asymptotics here. It indeed seems to be the case that the "default" algorithm here is O(n<sup>2.7</sup>), whereas the alternative is the expected O(n<sup>3</sup>) (the observed slopes were 2.703 and 3.133, actually).</p>
<p><a href="https://i.stack.imgur.com/XjUrd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XjUrd.png" alt="enter image description here" /></a></p>
<p>I also checked how the alternative algorithm compared to the following implementation of "schoolbook" matrix multiplication followed by a mod operation.</p>
<pre><code>def mat_mult_3(A,B):
return np.sum(A[:,:,None]*B[None,:,:],axis = 1)%2
</code></pre>
<p>I was very surprised to find that this <strong>also</strong> does better than the and/xor based method!</p>
<p><a href="https://i.stack.imgur.com/dsb8l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dsb8l.png" alt="enter image description here" /></a></p>
<p>In response to Michael's comment, I replaced <code>mat_mult_2</code> with the following:</p>
<pre><code>def mat_mult_2(A,B):
return np.logical_xor.reduce(A.astype(bool)[:,:,None]
& B.astype(bool)[None,:,:],axis = 1).astype(int)
</code></pre>
<p>This arguably still places an undue burden of type conversion on the method, but sticking to multiplication between boolean matrices didn't significantly change performance. The result is that <code>mat_mult_2</code> now (marginally) outperforms <code>mat_mult_3</code>, as expected.</p>
<p><a href="https://i.stack.imgur.com/rBLvE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rBLvE.png" alt="enter image description here" /></a></p>
<p>In response to Harold's comment: another attempt to get the asymptotics of the <code>@</code> method. My device doesn't seem to be able to handle multiplication with n much greater than 2000.</p>
<p>The observed slope here is 2.93.</p>
<p><a href="https://i.stack.imgur.com/Nx2uv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nx2uv.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74226052,
"author": "hpaulj",
"author_id": 901925,
"author_profile": "https://Stackoverflow.com/users/901925",
"pm_score": 1,
"selected": false,
"text": "n=10"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2476977/"
] |
74,225,268 | <p>I am developping a WPF application in XAML. I am a beginner and I have an issue with my button. I need to set its height as a proportion of its container which is a grid. I saw that the height can be set to a value or to "Auto", but I don't know how to say to my button that his height must be 3/4 of the height of the grid in which it is contained.</p>
<p>Does anybody know how to deal with that ? Is it possible to do that with XAML ?</p>
<p>The objective is that when the grid grows, the button grows with it.</p>
<p>Any help would be appreciate.</p>
<p>Thanks</p>
<p>Here is the code I wrote :</p>
<pre><code><Window x:Class="WpfAppButtonSize.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfAppButtonSize"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid Height="100" Width="250" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Button 1" FontSize="30" Height="75" Width="150"/>
</Grid>
</Grid>
</code></pre>
<p>For the button, instead of Height="75", I would like to say Height=0.75 * Grid Height</p>
| [
{
"answer_id": 74226069,
"author": "ewerspej",
"author_id": 4308455,
"author_profile": "https://Stackoverflow.com/users/4308455",
"pm_score": 1,
"selected": true,
"text": "x:Name"
},
{
"answer_id": 74236221,
"author": "Peregrine",
"author_id": 967885,
"author_profile"... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20350716/"
] |
74,225,302 | <p>I'd always assumed a threading.Lock object would act as a mutex to prevent race conditions from occuring in a multithreading Python script, but I'm finding that either</p>
<ol>
<li>my assumption is false (contradicting years of experience), or</li>
<li>Python itself has a bug (in, at the very least, versions 2.7-3.9) regarding this.</li>
</ol>
<p>Theoretically, incrementing a value shared between two threads should be fine as long as you protect the critical section (ie the code incrementing that value) with a Lock, ie. mutex.</p>
<p>Running this code, I find mutexes in Python not to work as expected. Can anyone enlighten me on this?</p>
<pre><code>#!/usr/bin/env python
from __future__ import print_function
import sys
import threading
import time
Stop = False
class T(threading.Thread):
def __init__(self,list_with_int):
self.mycount = 0
self.to_increment = list_with_int
super(T,self).__init__()
def run(self,):
while not Stop:
with threading.Lock():
self.to_increment[0] += 1
self.mycount += 1
intList = [0]
t1 = T(intList)
t2 = T(intList)
t1.start()
t2.start()
Delay = float(sys.argv[1]) if sys.argv[1:] else 3.0
time.sleep(Delay)
Stop = True
t1.join()
t2.join()
total_internal_counts = t1.mycount + t2.mycount
print("Compare:\n\t{total_internal_counts}\n\t{intList[0]}\n".format(**locals()))
assert total_internal_counts == intList[0]
</code></pre>
| [
{
"answer_id": 74226069,
"author": "ewerspej",
"author_id": 4308455,
"author_profile": "https://Stackoverflow.com/users/4308455",
"pm_score": 1,
"selected": true,
"text": "x:Name"
},
{
"answer_id": 74236221,
"author": "Peregrine",
"author_id": 967885,
"author_profile"... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20350835/"
] |
74,225,349 | <p>I have a rule set to URL redirect specific domain names but I cannot figure out how to use a wildcard to forward all and any subdomains that a user would enter in.</p>
<p>My attempt was this with no luck.</p>
<p><a href="https://i.stack.imgur.com/KuAgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KuAgl.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74335732,
"author": "Roderick Bant",
"author_id": 3949759,
"author_profile": "https://Stackoverflow.com/users/3949759",
"pm_score": 0,
"selected": false,
"text": "Request URL"
},
{
"answer_id": 74403152,
"author": "Anna Gevel",
"author_id": 11494222,
"a... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/602066/"
] |
74,225,380 | <p>so i am fetching data from an API on page load in reactJS</p>
<pre><code> useEffect(() => {
fetch('https://xxxxx/getdata',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify({
Action : "xxxx",
OrganisationID : "xxx-1000",
})
})
.then((res) => res.json())
.then((json) => {
setResponse(json)
console.log(json)
})
.catch((err) => {
console.log(err.message);
});
}, []);
</code></pre>
<p>The json returns me an array of 2 objects.</p>
<pre><code>{
"OrganisationJobPosts": [
{
"Languages": [
"English",
"Spanish"
],
"Project_Type": "One-Time Project",
"Description": "This job requires Java and Javascript developers",
"Status": "open",
"Proposal_Questions": [
"question1?",
"question2?"
],
"Entity": "JOBPOST",
"Organization_Name": "ABC Company",
"Jobpost_ID": "JOBPOST-20220608-10",
"Jobpost_Title": "Web Developer",
"Organization_ID": "ORGANIZATION-1000",
"Rates": "$20/hour",
"Experience": "< 3 Years",
"Created_Date": 20220608,
"Location": "Singapore",
"SK": "JOBPOST-20220608-10",
"PK": "ORGANIZATION-1000",
"Skill_Set": [
"HTML",
"Javascript"
]
},
{
"Languages": [
"English",
"French"
],
"Project_Type": "Ongoing Project",
"Description": "This job requires DB design skills",
"Status": "Closed",
"Proposal_Questions": [
"Question A?",
"Question B?"
],
"Entity": "JOBPOST",
"Organization_Name": "ABC Company",
"Jobpost_ID": "JOBPOST-20220608-11",
"Jobpost_Title": "Database Developer",
"Organization_ID": "ORGANIZATION-1000",
"Rates": "$20/hour",
"Experience": "< 3 Years",
"test": [
"test"
],
"Created_Date": 20220610,
"Location": "TBD",
"SK": "JOBPOST-20220608-11",
"PK": "ORGANIZATION-1000",
"Skill_Set": [
"DynaomDB",
"GraphDB"
]
}
]
}
</code></pre>
<p>I then tried looping through the said array</p>
<pre><code> <header className="headerTabContent">
{(() => {
for (var key in response) {
if (response.hasOwnProperty(key)) {
const resultarray = response[key]
console.log(resultarray)
for (var i=0;i<=resultarray.length;i++) {
return(<h1 className="heading" onClick={()=>navigate('/dashboard/hire/discover/job-post')}>{resultarray[i].Jobpost_ID}</h1>)
}
}
}
})()};
</header>
</code></pre>
<p>As seen my array length is 2. But the loop always outputs only the first array object (Job ID JOBPOST-20220608-10) wheras the second array item (JOBPOST-20220608-11) is not output. I can confirm the size is correct because before the second for loop, I did a console log of the length and found 2 objects. Am I doing something wrong here ?</p>
| [
{
"answer_id": 74225471,
"author": "acdcjunior",
"author_id": 1850609,
"author_profile": "https://Stackoverflow.com/users/1850609",
"pm_score": 2,
"selected": false,
"text": "for"
},
{
"answer_id": 74225944,
"author": "Andy",
"author_id": 1377002,
"author_profile": "h... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2856499/"
] |
74,225,453 | <p>I'm new to git, and I can't find an answer for that which is kind of weird.
Here is my problem:
I want to commit changes to all files within my folder called "folder1"
here is the content of "folder1":</p>
<pre><code>folder1
pyproject1.py
pyproject2.py
myimg.png
</code></pre>
<p>To do that, I commit my changes to my github repository, using the following command lines:</p>
<pre><code>git add *
git commit-m"my changes"
git push origin main
</code></pre>
<p>But if I try to remove for example the file "myimg.png" from my local folder, and execute again the following command lines:</p>
<pre><code>git add *
git commit-m"my changes"
git push origin main
</code></pre>
<p>The file myimg.png isn't removed from the github repository. How can I make sure that every time I commit a change in my local folder, every file that is not anymore in my local folder gets deleted from the repository ?</p>
| [
{
"answer_id": 74225582,
"author": "Th3Ph4nt0m",
"author_id": 13350995,
"author_profile": "https://Stackoverflow.com/users/13350995",
"pm_score": -1,
"selected": false,
"text": "git commit"
},
{
"answer_id": 74230451,
"author": "torek",
"author_id": 1256452,
"author_p... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8332216/"
] |
74,225,466 | <p>Hope you all are doing well in these times.</p>
<p>here's my code:</p>
<pre><code>
def ab(n):
first = 0
last = -1
endprod = n[first] + n[last]
endprod2 = n[first+1] + n[last-1]
endprod3 = n[first+2] + n[last-2]
endprod4 = n[first+3] + n[last-3]
endprod5 = n[first+4] + n[last-4]
endprod100 = endprod[::-1] + endprod2[::-1] + endprod3[::-1]+ endprod4[::-1]+ endprod5[::-1]
return endprod100
</code></pre>
<p>I was able do to it, however mine isn't a loop. Is there a way to convert my code into a for loop. So, increment by 1 and decrement by 1.</p>
<p>Thanks,</p>
| [
{
"answer_id": 74225533,
"author": "Riccardo Bucco",
"author_id": 5296106,
"author_profile": "https://Stackoverflow.com/users/5296106",
"pm_score": 1,
"selected": false,
"text": "def ab(n):\n result = ''\n for j in range(len(n) // 2):\n result += n[-j-1] + n[j]\n if len(n... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19861101/"
] |
74,225,482 | <p>IΒ΄ve been trying to automize a list of addresses in SQL. I have multiple addresses and quantities and i need only the addresses that will fulfill the quantity i need</p>
<p>For example:</p>
<p>I have a table with</p>
<pre><code>Item A qty 20
Item B qty 5
Item C qty 23
</code></pre>
<p>And a table with addresses and units</p>
<pre><code>Address 1 item A 15units
Address 2 item A 10units
Address 3 item A 10units
Address 4 item A 13units
</code></pre>
<p>The result should show only</p>
<pre><code>Address 2 item A 10units
Address 3 item A 10units
</code></pre>
| [
{
"answer_id": 74225533,
"author": "Riccardo Bucco",
"author_id": 5296106,
"author_profile": "https://Stackoverflow.com/users/5296106",
"pm_score": 1,
"selected": false,
"text": "def ab(n):\n result = ''\n for j in range(len(n) // 2):\n result += n[-j-1] + n[j]\n if len(n... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15881212/"
] |
74,225,490 | <p>My code is as follows:</p>
<pre><code>import random
players = []
def player_list(new_player):
for x in range (5):
players.append(new_player)
return players
for x in range (5):
new_player = input("Please enter your player name: ")
winner=(random.choice(players))
print("You are the winner," , winner)
</code></pre>
<p>It keeps returning the following error message:</p>
<pre class="lang-none prettyprint-override"><code>Please enter your player name: Rashida
Traceback (most recent call last):
Random Role Assignment Program.py", line 11, in <module>
mafia=(random.choice(players))
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
IndexError: list index out of range
</code></pre>
<p>The code is supposed to fill up an empty list and the return it. I checked this and it didn't work.
Then the code is supposed to randomly select a player and tell them they won.</p>
<p>How do I fix this?</p>
<p>The code may not be perfect in other aspects either.</p>
| [
{
"answer_id": 74225542,
"author": "Dmitriy Neledva",
"author_id": 16786350,
"author_profile": "https://Stackoverflow.com/users/16786350",
"pm_score": 1,
"selected": false,
"text": "players"
},
{
"answer_id": 74225559,
"author": "logan_9997",
"author_id": 18749472,
"a... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20072068/"
] |
74,225,513 | <p>I'm gradually moving a RN project to typescript. I have a question about declaring types for styles that are being passed as a props to a component.</p>
<p>The Props within the component are defined as follows:</p>
<pre><code>interface Props {
children: ReactNode;
style?: ViewStyle;
}
</code></pre>
<p>It's ok if I pass just a simple styles object, eg:</p>
<pre><code><Component style={{ marginTop: 1 }}>...children...</Component>
<Component style={styleObj}>....children...</Component>
</code></pre>
<p>But it fails if I pass an array of styles:</p>
<pre><code><Component style={[styleObj, { marginTop: someVar }]}>...children...</Component>
</code></pre>
<p>What would be the best way to specify the style prop type?</p>
<p>EDIT: and the TS message is:</p>
<pre><code>TS2559: Type '({ flex: number; } | { marginTop: number; })[]' has no properties in common with type 'ViewStyle'. Component.tsx(12, 3): The expected type comes from property 'style' which is declared here on type 'IntrinsicAttributes & Props'
</code></pre>
| [
{
"answer_id": 74225550,
"author": "Harrison",
"author_id": 15291770,
"author_profile": "https://Stackoverflow.com/users/15291770",
"pm_score": 0,
"selected": false,
"text": "style"
},
{
"answer_id": 74225684,
"author": "Moistbobo",
"author_id": 13772644,
"author_prof... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1945363/"
] |
74,225,523 | <p>I have a large csv where each row is a separate school course, each of which is tagged with one or more topics, like so:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>school name</th>
<th>department</th>
<th>course name</th>
<th>topics</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>A1</td>
<td>X</td>
<td>1; 2</td>
</tr>
<tr>
<td>A</td>
<td>A1</td>
<td>Y</td>
<td>1; 3</td>
</tr>
<tr>
<td>B</td>
<td>B1</td>
<td>Z</td>
<td>1; 2; 4</td>
</tr>
<tr>
<td>C</td>
<td>C1</td>
<td>XX</td>
<td>1; 5</td>
</tr>
</tbody>
</table>
</div>
<p>I need to calculate the presence of each topic for each course. Each topic needs to be appended as its own column, with each row coded as either a 0 or 1 depending on whether the topic is present in the course. There are 49 topics in total, so I need to add 49 rows to the table.</p>
<p>There are 4000 rows, many of which are repeats of the same course name, so those need to be grouped as well. For example, if one instance of course name X has topics 1, 2 but another instance of the same course has topics 1, 3 the binary values for column topic 1 should be 1, topic 2 should be 1, and topic 3 should be 1, while the rest of the topic columns are coded as 0.</p>
<p>The output should look something like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>school name</th>
<th>department</th>
<th>course name</th>
<th>topic 1</th>
<th>topic 2</th>
<th>topic 3</th>
<th>topic 4</th>
<th>topic 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>A1</td>
<td>X</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>A</td>
<td>A1</td>
<td>Y</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>B</td>
<td>B1</td>
<td>Z</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>C</td>
<td>C1</td>
<td>XX</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>I have a nested loop structure that splits the topics by semicolon and then does some cleaning to standardize the topic names, but I'm stuck on how to append a new column for each topic coded as the correct binary value.</p>
<pre><code>import pandas as pd
import io
df = pd.read_csv(io.BytesIO(uploaded['courses.csv']))
df_dict = {}
result = []
topic = []
count = []
for item in df['Course ID']:
for item in df['Final Code']:
if type(item) == str:
item_list = item.split(';')
for each in item_list:
each = each.strip().lower()
if each == "[too ambigious]" or each == "too ambiguous":
each = "[too ambiguous]"
if each == "equity and equality\\":
each = "equity and equality"
if each == "[NA]" or each == "N/A":
each = "NA"
#create new column for each unique topic
for item in df['Final Code']:
result.append(item)
#1 if that topic is present in each course, else 0
if each in df_dict:
df_dict[each] = 1
else:
df_dict[each] = 0
print(df_dict)
print(result)
print(df)
</code></pre>
<p>I haven't used python for a long time, so I forget how to go about this.</p>
| [
{
"answer_id": 74225577,
"author": "jprebys",
"author_id": 3268228,
"author_profile": "https://Stackoverflow.com/users/3268228",
"pm_score": 0,
"selected": false,
"text": "expand=True"
},
{
"answer_id": 74225602,
"author": "Abhilash Kar",
"author_id": 20254308,
"autho... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3521871/"
] |
74,225,553 | <pre><code>$applicationArray = $filezilla = "C:\Program Files\FileZilla FTP Client\filezilla.exe", $notepad = "C:\Program Files\Notepad++\notepad++.exe", $cisco = "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe", $adobe = "C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe"
foreach ($application in $applicationArray)
{
Test-path
if (Test-path)
{
Write-Host "Folder Exists"
}
else
{
Write-Host "Folder Does Not Exist"
}
}
</code></pre>
<p>I am trying to write a script that will check if the above programs are installed by useing the "Test-path" command. when I run them in individual "if" statements they all work but I was looking to loop it so I could compress the script to be as eficient as possible. but when I try to run the above I get the below error:</p>
<pre><code>At C:\Users\Nicholas.McKinney\OneDrive - Brandmuscle\Documents\Scripts\Laptop_Setups.ps1:1 char:34
+ ... filezilla = "C:\Program Files\FileZilla FTP Client\filezilla.exe", $n ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
At C:\Users\Nicholas.McKinney\OneDrive - Brandmuscle\Documents\Scripts\Laptop_Setups.ps1:1 char:100
+ ... a.exe", $notepad = "C:\Program Files\Notepad++\notepad++.exe", $cisco ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
At C:\Users\Nicholas.McKinney\OneDrive - Brandmuscle\Documents\Scripts\Laptop_Setups.ps1:1 char:153
+ ... ", $cisco = "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mob ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidLeftHandSide
</code></pre>
| [
{
"answer_id": 74225669,
"author": "Toni",
"author_id": 19895159,
"author_profile": "https://Stackoverflow.com/users/19895159",
"pm_score": 0,
"selected": false,
"text": "$applicationArray = $filezilla = \"C:\\Program Files\\FileZilla FTP Client\\filezilla.exe\", $notepad = \"C:\\Program... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351006/"
] |
74,225,572 | <p>I have an html page where some words are split by <code>&#8203;</code> so they look e.g. like <code>ββFβRigβVβMβExternalβVariable</code> but in the code they are actually <code>F&#8203;Rig&#8203;V&#8203;M&#8203;External&#8203;Variable&#8203;</code>. And the problem is that when I click the word it selects only a part that is bordered by <code>&#8203;</code> while the desirable behavior is for it to select the whole word</p>
<p>How to override default double click behavior in JS so it would treat <code>&#8203;</code> not as a word boundary?</p>
| [
{
"answer_id": 74225685,
"author": "Niloct",
"author_id": 152016,
"author_profile": "https://Stackoverflow.com/users/152016",
"pm_score": 1,
"selected": false,
"text": "​"
},
{
"answer_id": 74226212,
"author": "zer00ne",
"author_id": 2813224,
"author_profile": "... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11681638/"
] |
74,225,595 | <p>I was looking to get the XPath to get the value of ad:pd element. I have tried all the ways possible in the XPath to get the value, but none of then worked.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<ad:sgRes
xmlns:ad="http://www.thehtf.co.uk/Data/V1.0">
<ad:Msg>
<ad:cpn>
<ad:ist>
<ad:tm>
<ad:pd>12016</ad:pd>
</ad:tm>
</ad:ist>
</ad:cpn>
</ad:Msg>
</ad:sgRes>
</code></pre>
<p>The XPATH I used was: <code>//pd</code> <code>//*:pd</code> <code>ad:sgRes/ad:Msg/ad:cpn/ad:ist/ad:tm/ad:pd</code> <code>//ad:tm/*:pd</code> but none of them worked. Also tried using <code>exclude-result-prefixes="ad"</code> with no success. I have gone through few posts here but none of them worked. That's why posting my question here. Probably a very easy things for you guys to answer. But definitely I am missing something here.</p>
<p>Adding my XSLT code here. None of the solution mentioned in the comments worked for me. What am I missing here:</p>
<pre><code><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ad="http://www.thehtf.co.uk/Data/V1.0"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:func="http://exslt.org/functions"
xmlns:apim="http://www.ibm.com/apimanagement"
extension-element-prefixes="dp func apim ad" exclude-result-prefixes="dp">
<xsl:import href="local:///isp/policy/apim.custom.xsl"/>
<xsl:template match="/">
<xsl:variable name="payload" select="apim:getVariable('Output.body')" />
<xsl:variable name="pdCode" select="$payload//*[local-name()='pd']"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$pdCode='66'">
<xsl:call-template name="apim:setVariable">
<xsl:with-param name="varName" select="'Check'"/>
<xsl:with-param name="value" select="'True'"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$pdCode='31'">
<xsl:call-template name="apim:setVariable">
<xsl:with-param name="varName" select="'Check'"/>
<xsl:with-param name="value" select="'False'"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="apim:setVariable">
<xsl:with-param name="varName" select="'Check'"/>
<xsl:with-param name="value" select="'UnknownError'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</code></pre>
<p>apim.custom.xsl</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:func="http://exslt.org/functions"
xmlns:apim="http://www.ibm.com/apimanagement"
xmlns:webapi="http://www.ibm.com/apimanagement"
xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"
extension-element-prefixes="dp func"
exclude-result-prefixes="dp func apim webapi json">
<xsl:import href="local:///isp/error_template.xsl" dp:ignore-multiple="yes"/>
<xsl:import href="apim.context.xsl" dp:ignore-multiple="yes" />
<xsl:import href="assembly-util.xsl" dp:ignore-multiple="yes" />
<xsl:include href="apim.setvariable-impl.xsl" dp:ignore-multiple="yes"/>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:payloadRead">
<xsl:variable name="gscript" select="'local:///isp/policy/apim.custom.xsl.js'"/>
<xsl:variable name="input-media" select="dp:variable('var://context/_apimgmt/content-type')" />
<xsl:variable name="polic-media" select="dp:variable('var://context/_apimgmt/policy-output-mediaType')" />
<xsl:variable name="usePolicyOutput" select="dp:variable('var://context/_apimgmt/use-policy-output')"/>
<xsl:if test="$debug1">
<xsl:message dp:priority="debug">
<xsl:text>apim:payloadRead: [</xsl:text>
<xsl:value-of select="$input-media"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$polic-media"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$usePolicyOutput"/>
<xsl:text>]</xsl:text>
</xsl:message>
</xsl:if>
<!-- -->
<!-- -->
<xsl:choose>
<xsl:when test="webapi:isContentJSON($polic-media) = 'y' or (webapi:isContentJSON($input-media) = 'y' and webapi:isContentXML($polic-media) = 'n')">
<xsl:variable name="params">
<parameter name="action">readInputAsJSONX</parameter>
</xsl:variable>
<xsl:variable name="result" select="dp:gatewayscript($gscript, ., true(), $params)"/>
<xsl:variable name="jsonx1" select="$result/gatewayscript/result/text()"/>
<func:result>
<xsl:choose>
<xsl:when test="string-length($jsonx1) &gt; 0">
<dp:parse select="$jsonx1"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="/.."/>
</xsl:otherwise>
</xsl:choose>
</func:result>
</xsl:when>
<!--@@ XML Payload from 'policy-output' -->
<xsl:when test="webapi:isContentXML($polic-media) = 'y' and $usePolicyOutput = 'true'">
<func:result>
<xsl:copy-of select="dp:variable('var://context/policy-output')" />
</func:result>
</xsl:when>
<!--@@ XML Payload from 'INPUT' - first time reading it -->
<xsl:when test="webapi:isContentXML($input-media) = 'y'">
<!-- If the original input media is specified, set the output media as that value. This will ensure
that the policy does not change the content type from text/xml to application/xml for example. If it
is not specified (the original content type is the name of the variable or is empty, it will default to
input-media (i.e. application/xml). -->
<xsl:variable name="original-input-media">
<xsl:choose>
<xsl:when test="dp:responding() = true()">
<xsl:variable name="temp" select="normalize-space(dp:variable('var://service/original-response-content-type'))" />
<xsl:choose>
<xsl:when test="not($temp = 'var://service/original-response-content-type')">
<xsl:value-of select="$temp" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/.." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="temp" select="normalize-space(dp:variable('var://service/original-content-type'))" />
<xsl:choose>
<xsl:when test="not($temp = 'var://service/original-content-type')">
<xsl:value-of select="$temp" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/.." />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="string($original-input-media)">
<dp:set-variable name="'var://context/_apimgmt/policy-output-mediaType'" value="string($original-input-media)" />
</xsl:when>
<xsl:otherwise>
<dp:set-variable name="'var://context/_apimgmt/policy-output-mediaType'" value="string($input-media)" />
</xsl:otherwise>
</xsl:choose>
<func:result>
<xsl:copy-of select="dp:variable('var://context/INPUT')" />
</func:result>
</xsl:when>
<!-- -->
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</func:function>
<!--
============================================================================================
============================================================================================
-->
<xsl:template name="apim:output">
<xsl:param name="mediaType" select="''" />
<xsl:if test="$mediaType != ''">
<dp:set-variable name="'var://context/_apimgmt/policy-output-mediaType'" value="string($mediaType)" />
</xsl:if>
<dp:set-variable name="'var://context/_apimgmt/policy-output-set'" value="'true'"/>
<dp:set-variable name="'var://context/_apimgmt/content-type-override'" value="''"/>
</xsl:template>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:payloadType">
<func:result>
<xsl:value-of select="dp:variable('var://context/_apimgmt/policy-output-mediaType')" />
</func:result>
</func:function>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:policyProperties">
<xsl:variable name="policy-props" select="webapi:getPolicyDoc()"/>
<xsl:variable name="processed">
<xsl:choose>
<xsl:when test="$policy-props/policy/properties[@array = 'true']">
<xsl:copy-of select="$policy-props/policy/properties"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$policy-props/policy/properties" mode="policyproperties"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<func:result>
<xsl:copy-of select="$processed"/>
</func:result>
</func:function>
<xsl:template match="properties[@name]" mode="policyproperties">
<xsl:choose>
<!-- if we have an array, must handle each child array element
that will have a @name of 0, 1 ... n -->
<xsl:when test="@array = 'true'">
<xsl:variable name="arrayName" select="@name" />
<xsl:for-each select="./properties | ./property">
<xsl:element name="{$arrayName}">
<xsl:apply-templates select="@* | node()" mode="policyproperties"/>
</xsl:element>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{@name}">
<xsl:value-of select="text()"/>
<xsl:apply-templates select="@* | node()" mode="policyproperties"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="properties" mode="policyproperties">
<xsl:apply-templates select="@* | node()" mode="policyproperties"/>
</xsl:template>
<xsl:template match="property" mode="policyproperties">
<xsl:choose>
<xsl:when test="@name = 'scopes'">
<xsl:element name="scopes">
<xsl:choose>
<xsl:when test="@type = 'string'">
<xsl:choose>
<xsl:when test="string-length(.) &gt; 0">
<xsl:copy-of select="dp:parse(.)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="/.."/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select=".//set"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:when>
<xsl:when test="starts-with(@name, 'scopes.')">
<xsl:element name="scope">
<xsl:attribute name="original"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="desc"><xsl:value-of select="text()"/></xsl:attribute>
<xsl:value-of select="substring-after(@name, 'scopes.')"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{@name}">
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@* | node()" mode="policyproperties">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="policyproperties"/>
</xsl:copy>
</xsl:template>
<!--
============================================================================================
============================================================================================
-->
<!-- deprecated -->
<func:function name="apim:readContext">
<func:result>
<xsl:call-template name="buildContext" />
</func:result>
</func:function>
<func:function name="apim:getContext">
<xsl:param name="var" />
<func:result>
<xsl:value-of select="apim:getContextByVariable($var)" />
</func:result>
</func:function>
<!--
============================================================================================
============================================================================================
-->
<xsl:template name="apim:error">
<xsl:param name="httpCode" />
<xsl:param name="httpReasonPhrase" />
<xsl:param name="errorName" select="'runtime.error'"/>
<xsl:param name="errorMessage" select="''"/>
<xsl:param name="ignorecatch" select="'false'"/>
<xsl:call-template name="error">
<xsl:with-param name="name" select="$errorName"/>
<xsl:with-param name="code" select="$httpCode"/>
<xsl:with-param name="reason" select="$httpReasonPhrase"/>
<xsl:with-param name="message" select="$errorMessage"/>
<xsl:with-param name="ignorecatch" select="$ignorecatch"/>
</xsl:call-template>
</xsl:template>
<!--
============================================================================================
Function to return the exception JSON object as XML so customers don't need to pull the
context variable directly.
============================================================================================
-->
<func:function name="apim:getError">
<xsl:variable name="exception" select="dp:variable('var://context/policy/fw/exception')" />
<xsl:variable name="result" select="dp:stringToJSONx($exception)"/>
<func:result>
<error>
<name><xsl:value-of select="$result/json:object/*[@name='name']"/></name>
<message><xsl:value-of select="$result/json:object/*[@name='message']"/></message>
<policyTitle><xsl:value-of select="$result/json:object/*[@name='policyTitle']"/></policyTitle>
<status>
<code><xsl:value-of select="$result/json:object/*[@name='httpCode']"/></code>
<reason><xsl:value-of select="$result/json:object/*[@name='httpReasonPhrase']"/></reason>
</status>
</error>
</func:result>
</func:function>
<!--
============================================================================================
Gateway properties can be set in local:///ext/gateway-properties.xml overridden by an
API property of the same name.
- Values must be a string type.
============================================================================================
-->
<func:function name="apim:getGatewayProperty">
<xsl:param name="propertyName"/>
<xsl:variable name="apiProp" select="apim:getApiPropertyValue($propertyName)" />
<xsl:variable name="result">
<xsl:choose>
<xsl:when test="string-length($apiProp) > 0">
<xsl:value-of select="$apiProp"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="domain" select="dp:variable('var://service/domain-name')" />
<xsl:variable name="extVar" select="concat('var://system/_apimgmt/', $domain,'/dpext')" />
<xsl:value-of select="dp:variable($extVar)//property[@name=$propertyName]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<func:result>
<xsl:value-of select="string($result)" />
</func:result>
</func:function>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:getApiProperty">
<xsl:param name="propertyName"/>
<func:result>
<xsl:value-of select="apim:getApiPropertyValue($propertyName)" />
</func:result>
</func:function>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:getApiProperties">
<xsl:variable name="policiesXml" select="dp:variable('var://context/policy/fw/input-map')" />
<xsl:variable name="configProperties">
<xsl:for-each select="$policiesXml/policies/cfgProperty">
<xsl:element name="{@name}">
<xsl:value-of select="apim:getApiPropertyValue(@name,$policiesXml)" />
</xsl:element>
</xsl:for-each>
</xsl:variable>
<func:result>
<xsl:copy-of select="$configProperties" />
</func:result>
</func:function>
<!-- ======================================================================= -->
<xsl:template name="apim:payloadReadOrigin" >
<xsl:param name="input-media" select="dp:variable('var://context/_apimgmt/content-type')" />
<xsl:variable name="ruletype" select="dp:variable('var://service/transaction-rule-type')" />
<xsl:choose>
<xsl:when test="$input-media = 'application/xml'">
<xsl:copy-of select="dp:variable('var://context/INPUT')" />
</xsl:when>
<xsl:when test="$ruletype = 'request' and $input-media = 'application/json'">
<xsl:copy-of select="dp:variable('var://context/__JSONASJSONX')" />
</xsl:when>
<xsl:when test="$input-media = 'application/json'">
<xsl:copy-of select="dp:variable('var://context/__JSONASJSONX2')" />
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>
<!-- ======================================================================= -->
<xsl:template name="apim:setVariable">
<xsl:param name="varName"/>
<xsl:param name="value"/>
<xsl:param name="action" select="'Set'" />
<xsl:call-template name="apim:setVariableImpl">
<xsl:with-param name="rawName" select="$varName" />
<xsl:with-param name="rawValue" select="$value" />
<xsl:with-param name="action" select="$action" />
</xsl:call-template>
</xsl:template>
<!-- ======================================================================= -->
<func:function name="apim:getVariable">
<xsl:param name="varName" />
<xsl:param name="decode" />
<xsl:param name="encodePlus" select="'false'"/>
<func:result select="apim:getVariableImpl($varName, $decode, $encodePlus)" />
</func:function>
<!--
============================================================================================
============================================================================================
-->
<func:function name="apim:getRegistry">
<xsl:param name="name"/>
<xsl:variable name="servicesXml" select="dp:variable('var://context/_apimgmt/tenant-policy')"/>
<xsl:variable name="result" select="$servicesXml/registries/ldap[@name = $name]"/>
<xsl:if test="not($result) and $debug1">
<xsl:message dp:type="apiconnect" dp:priority="debug">
<xsl:text>apim:getRegistry(</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>) not found. Known names are: </xsl:text>
<xsl:for-each select="$servicesXml/registries/ldap">
<xsl:value-of select="@name"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:message>
</xsl:if>
<func:result>
<xsl:copy-of select="$result"/>
</func:result>
</func:function>
<!-- ======================================================================= -->
<func:function name="apim:getTLSProfileObjName">
<xsl:param name="inputName" />
<xsl:variable name="params">
<parameter name="funcName">getTLSProfileObjName</parameter>
<parameter name="args"><xsl:value-of select="string($inputName)"/></parameter>
</xsl:variable>
<func:result>
<xsl:copy-of select="dp:gatewayscript('local:///isp/policy/xslt-to-js-bridge.js', $params, false())"/>
</func:result>
</func:function>
<!-- ======================================================================= -->
<func:function name="apim:getManagedObject">
<xsl:param name="type" /> <!-- Required -->
<xsl:param name="name" />
<!-- <xsl:param name="version" /> -->
<xsl:param name="property" />
<xsl:param name="asFilename" select="'false'"/>
<!-- <xsl:param name="id" /> -->
<xsl:variable name="params">
<parameter name="funcName">getManagedObject</parameter>
<parameter name="args">
<xsl:text>[{"name":"</xsl:text>
<xsl:value-of select="string($name)"/>
<!--
<xsl:text>","version":"</xsl:text>
<xsl:value-of select="string($version)"/>
<xsl:text>","id":"</xsl:text>
<xsl:value-of select="string($id)"/>
-->
<xsl:text>","property":"</xsl:text>
<xsl:value-of select="string($property)"/>
<xsl:text>","asFilename":"</xsl:text>
<xsl:value-of select="string($asFilename)"/>
<xsl:text>"},"</xsl:text>
<xsl:value-of select="string($type)"/>
<xsl:text>"]</xsl:text>
</parameter>
</xsl:variable>
<func:result>
<xsl:copy-of select="dp:gatewayscript('local:///isp/policy/xslt-to-js-bridge.js', $params, false())"/>
</func:result>
</func:function>
<!-- ======================================================================= -->
<func:function name="apim:getManagedObjectName">
<xsl:param name="type" /> <!-- Required -->
<xsl:param name="name" />
<xsl:variable name="params">
<parameter name="funcName">getManagedObjectName</parameter>
<parameter name="args">
<xsl:text>[{"name":"</xsl:text>
<xsl:value-of select="string($name)"/>
<xsl:text>","asObject": "</xsl:text>
<xsl:text>true</xsl:text>
<xsl:text>"},"</xsl:text>
<xsl:value-of select="string($type)"/>
<xsl:text>"]</xsl:text>
</parameter>
</xsl:variable>
<func:result>
<xsl:copy-of select="dp:gatewayscript('local:///isp/policy/xslt-to-js-bridge.js', $params, false())"/>
</func:result>
</func:function>
<func:function name="apim:determineMediaType">
<xsl:variable name="mediaType">
<!-- If the original input media is specified, set the output media as that value. This will ensure
that the policy does not change the content type from text/xml to application/xml for example. If it
is not specified (the original content type is the name of the variable or is empty, it will default to
input-media (i.e. application/xml). -->
<xsl:variable name="originalContentType">
<xsl:choose>
<xsl:when test="dp:responding() = true()">
<xsl:variable name="temp" select="normalize-space(dp:variable('var://service/original-response-content-type'))" />
<xsl:choose>
<xsl:when test="not($temp = 'var://service/original-response-content-type')">
<xsl:value-of select="$temp" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/.." />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="temp" select="normalize-space(dp:variable('var://service/original-content-type'))" />
<xsl:choose>
<xsl:when test="not($temp = 'var://service/original-content-type')">
<xsl:value-of select="$temp" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/.." />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="usePolicyOutput" select="dp:variable('var://context/_apimgmt/use-policy-output')"/>
<xsl:variable name="policyOutputMediaType" select="dp:variable('var://context/_apimgmt/policy-output-mediaType')"/>
<xsl:variable name="content-type-override" select="dp:variable('var://context/_apimgmt/content-type-override')"/>
<xsl:choose>
<xsl:when test="string-length($content-type-override) &gt; 0">
<xsl:value-of select="$content-type-override"/>
</xsl:when>
<xsl:when test="string-length($usePolicyOutput) &gt; 0 and string-length($policyOutputMediaType) &gt; 0">
<xsl:value-of select="$policyOutputMediaType"/>
</xsl:when>
<xsl:when test="$originalContentType">
<xsl:value-of select="$originalContentType"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<func:result>
<xsl:value-of select="string($mediaType)"/>
</func:result>
</func:function>
</xsl:stylesheet>
</code></pre>
| [
{
"answer_id": 74225653,
"author": "kjhughes",
"author_id": 290085,
"author_profile": "https://Stackoverflow.com/users/290085",
"pm_score": 1,
"selected": false,
"text": "xmlns:ad=\"http://www.thehtf.co.uk/Data/V1.0\""
},
{
"answer_id": 74225657,
"author": "Prophet",
"aut... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8434630/"
] |
74,225,623 | <p>I have two arrays, the first list contains a master list of all names:</p>
<pre><code>const masterNames = [
"Adam",
"Owen",
"Dylan",
"Luke",
"Gabriel",
"Anthony",
"Isaac",
"Grayson",
"Jack",
"Julian",
"Levi",
];
</code></pre>
<p>and another list which contains specific names:</p>
<pre><code>const students = ["Steve", "Dylan", "Luke"]
</code></pre>
<p>I want to search the master list and return the first name from students that is found in the master list. In this case "Dylan" since Steve is not on the list.</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 students = ["Steve", "Dylan", "Luke"];
const masterNames = [
"Adam",
"Owen",
"Dylan",
"Luke",
"Gabriel",
"Anthony",
"Isaac",
"Grayson",
"Jack",
"Julian",
"Levi",
];
masterNames.forEach(function (item, index) {
const found = students.find(element => element === item);
console.log(found);
});</code></pre>
</div>
</div>
</p>
<p>I used <code>Array.prototype.find()</code> inside a loop but it returns all name and not just the first item.</p>
| [
{
"answer_id": 74225686,
"author": "Jonathon Mederios",
"author_id": 20351074,
"author_profile": "https://Stackoverflow.com/users/20351074",
"pm_score": 0,
"selected": false,
"text": ".find()"
},
{
"answer_id": 74225690,
"author": "pilchard",
"author_id": 13762301,
"a... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4576720/"
] |
74,225,628 | <pre class="lang-js prettyprint-override"><code> client.on('messageCreate', async(message) => {
if (message.author.bot)return
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(message.content.startsWith('!reroll')){
if(!message.member.permissions.has("ADMINISTRATOR")) return;
const content = args.join(' ');
let winner = message.reactions.fetch(content).cache.get("").users.cache.filter((users) => !users.bot).random(winnerCount.toString().slice(0, -1));
const embed = new MessageEmbed()
.setDescription(`${winner}`);
message.channel.send({embeds: [embed]});
message.delete({timeout: 1500}).catch(err => console.log(err));
}
})
</code></pre>
<p>I tried to make a giveaway reroll command but I got this error.</p>
<pre><code>TypeError: message.reactions.fetch is not a function
</code></pre>
<p><a href="https://i.stack.imgur.com/YAGtG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YAGtG.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74225826,
"author": "Zsolt Meszaros",
"author_id": 6126373,
"author_profile": "https://Stackoverflow.com/users/6126373",
"pm_score": 1,
"selected": false,
"text": "reactions.fetch()"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19816140/"
] |
74,225,641 | <p>I have read in a monthly temperature anomalies csv file using Pandas read.csv() function. Years are from 1881 to 2022. I excluded the last 3 months of 202 to avoid -999 values). Date format is yyyy-mm-dd. How can I just plot the year and only one value instead of 12 on the x-axis (i.e., I don't need 12 1851s, 1852s, etc.)?</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.dates import YearLocator, MonthLocator, DateFormatter
import matplotlib.dates as mdates
ds = pd.read_csv('path_to_file.csv', header='infer', engine='python', skipfooter=3)
dates = ds['Date']
tAnoms = ds[' Berkeley Earth 2m Air Temperature (degree C) 0N-90N;0E-360E']
fig = plt.figure(figsize=(10,10))
ax = plt.subplot(111)
ax.plot(dates,tAnoms)
ax.plot(dates,tAnoms.rolling(60, center=True).mean())
ax.xaxis.set_major_locator(mdates.YearLocator(month=1) # EDIT
years_fmt = mdates.DateFormatter('%Y') # EDIT 2
ax.xaxis.set_major_formatter(years_fmt) # EDIT 2
plt.show()
</code></pre>
<p>EDIT: adding the following gives me the 2nd plot
EDIT 2: Gives me yearly values, but only from 1970-1975. 3rd plot</p>
<p><a href="https://i.stack.imgur.com/As5Xx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/As5Xx.png" alt="CSV file" /></a>
<a href="https://i.stack.imgur.com/w4VjS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w4VjS.png" alt="Plot" /></a>
<a href="https://i.stack.imgur.com/PcaFk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PcaFk.png" alt="How I want the dates to look like (minus month and day)" /></a>
<a href="https://i.stack.imgur.com/bsZDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bsZDs.png" alt="Plot after edits" /></a>
<a href="https://i.stack.imgur.com/sFUFF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sFUFF.png" alt="Plot after using set_major_formatter" /></a></p>
| [
{
"answer_id": 74225826,
"author": "Zsolt Meszaros",
"author_id": 6126373,
"author_profile": "https://Stackoverflow.com/users/6126373",
"pm_score": 1,
"selected": false,
"text": "reactions.fetch()"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15369801/"
] |
74,225,642 | <p>I am trying to get my code to open a new tab in the browser rather than opening in the same tab, so I added <code>target="_blank"</code> after the <code>href</code>, but this doesn't work as I don't think it is being sent.</p>
<p>does anyone know how to fix this code so it works in a new window?</p>
<pre><code><script>
function changeText1(){
var userInput = document.getElementById('userInput').value;
var lnk = document.getElementById('lnk');
lnk.href = "https://www.google.co.uk/search?q=" + userInput ;
lnk.innerHTML = lnk.href;
window.location = "https://www.google.co.uk/search?q=" + userInput;
}
function changeText2(){
var userInput = document.getElementById('userInput').value;
var lnk = document.getElementById('lnk');
lnk.href = "https://www.dogpile.com/serp?q=" + userInput;
lnk.innerHTML = lnk.href;
window.location = "https://www.dogpile.com/serp?q=" + userInput;
}
function changeText3(){
var userInput = document.getElementById('userInput').value;
var lnk = document.getElementById('lnk');
lnk.href = "https://uk.search.yahoo.com/search?p=" + userInput;
lnk.innerHTML = lnk.href;
window.location = "https://uk.search.yahoo.com/search?p=" + userInput;
}
</script>
<input type='text' id='userInput' value=' ' />
<input type='button' onclick='changeText1()' value='google'/>
<input type='button' onclick='changeText2()' value='Dogpile'/>
<input type='button' onclick='changeText3()' value='Yahoo'/>
<a href="" target="_blank" id=lnk </a> <br>
</code></pre>
<p>I tried adding target to this bit but, it didn't work.</p>
<pre><code><a href="" target="_blank" id=lnk </a> <br>
</code></pre>
| [
{
"answer_id": 74225826,
"author": "Zsolt Meszaros",
"author_id": 6126373,
"author_profile": "https://Stackoverflow.com/users/6126373",
"pm_score": 1,
"selected": false,
"text": "reactions.fetch()"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10001788/"
] |
74,225,656 | <p>I have below a sample structure of an HTML table and I'm looking for an output for the NVDA screen reader as below.</p>
<pre><code>Name INDIA Switzerland Germany
Country Name β β β
</code></pre>
<p>Looking for output for NVDA Screen reader
If I select checbox1
Then output
Country Name , INDIA, Checbox1 is checked</p>
<p>If I select checbox2
Then output
Country Name, Switzerland, Checbox2 is checked</p>
<p>If I select checbox3
Then output
Country Name, Germany, Checbox3 is checked</p>
<p>Here is table structure</p>
<pre><code><table>
<tr>
<th>
INDIA
</th>
<th>
Switzerland
</th>
<th>
Germany
</th>
</tr>
<tr>
<td>Country Name</td>
<td>Checkbox1</td>
<td>> Checkbox2</td>
<td>> Checkbox3</td>
</tr>
</table>
</code></pre>
| [
{
"answer_id": 74225792,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 0,
"selected": false,
"text": "th"
},
{
"answer_id": 74225863,
"author": "Ronnie Royston",
"author_id": 4797603,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9092347/"
] |
74,225,658 | <p>I'm making a navbar and for each button, I have a <div> and a , the div is the box and the a is the text+hyperlink.</p>
<p>I want to have my div change colors when I hover it, the problem is if I add a div :hover to my CSS it only changes colors when I hover over the , and not the div. So the box only changes colors when I hover the text.</p>
<p>I'm also having to copy everything from my normal div to the hover div because if I only change the color only the text will. (the last image is what it looks like when my div hover has only a background-color property)
The red circles on the images are where my mouse is.</p>
<p>I hope it didn't sound too confusing.
Code and example below:</p>
<pre><code>(this is inside a <nav>)
<div class="menu">
<div class="mapbox"><a class="map" href="">Erangel</a><br></div>
<div class="mapbox"><a class="map" href="">Miramar</a><br></div>
<div class="mapbox"><a class="map" href="">Sanhok</a><br></div>
<div class="mapbox"><a class="map" href="">Vikendi</a><br></div>
<div class="mapbox"><a class="map" href="">Taego</a><br></div>
<div class="mapbox"><a class="map" href="">Karakin</a></div>
</div>
</code></pre>
<pre><code>.map{
font-family: 'Rubik Mono One', Arial;
font-size: 1vw;
color: white;
text-decoration: none;
text-shadow: 0.125vw 0.125vw #282b30;
}
.mapbox{
display: flex;
justify-content: center;
align-items: center;
background-color: #424549;
border-radius: 1vw;
width: 12.5vw;
height: 2vw;
margin: auto;
margin-bottom: 0.85vw;
box-shadow: 0.225vw 0.225vw #1e2124;
}
.mapbox :hover{
display: flex;
justify-content: center;
align-items: center;
background-color: #7289da;
border-radius: 1vw;
width: 12.5vw;
height: 2vw;
margin: auto;
margin-bottom: 0.85vw;
}
</code></pre>
<p><a href="https://i.stack.imgur.com/RlRrr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlRrr.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/CQ4Gn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CQ4Gn.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/g28pB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g28pB.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74225743,
"author": "themujahidkhan",
"author_id": 16875752,
"author_profile": "https://Stackoverflow.com/users/16875752",
"pm_score": -1,
"selected": false,
"text": "!important"
},
{
"answer_id": 74225820,
"author": "Amaresh S M",
"author_id": 10112105,
... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287603/"
] |
74,225,697 | <p>Unsure how I can get this to work. Any ideas are appreciated. Thanks.</p>
<pre><code>import altair
user_input = input('Enter something here')
user_input_count = user_input.count
data = altair.Data(letters = user_input, number = user_input_count)
altair.Chart(data).mark_bar().encode(x = 'letters:N', y = 'number:N').display()
</code></pre>
| [
{
"answer_id": 74225743,
"author": "themujahidkhan",
"author_id": 16875752,
"author_profile": "https://Stackoverflow.com/users/16875752",
"pm_score": -1,
"selected": false,
"text": "!important"
},
{
"answer_id": 74225820,
"author": "Amaresh S M",
"author_id": 10112105,
... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19512280/"
] |
74,225,705 | <p>I successfully implemented the solution from <a href="https://stackoverflow.com/questions/28035464/how-does-one-invoke-the-windows-permissions-dialog-programmatically">How does one invoke the Windows Permissions dialog programmatically?</a> and related: <a href="https://stackoverflow.com/questions/30603139/how-to-display-file-properties-dialog-security-tab-from-c-sharp">How to display file properties dialog security tab from c#</a>.</p>
<pre><code> public static bool ShowFileProperties(string Filename)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = Filename;
info.lpParameters = "Security";
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
return ShellExecuteEx(ref info);
}
</code></pre>
<p>However, I would like to get to the Permissions window as you would with the Edit.. button from that dialogue.</p>
<p><a href="https://i.stack.imgur.com/lRXhV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lRXhV.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/jTCIS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jTCIS.png" alt="![enter image description here" /></a></p>
<p>Any ideas?</p>
| [
{
"answer_id": 74319044,
"author": "user2250152",
"author_id": 2250152,
"author_profile": "https://Stackoverflow.com/users/2250152",
"pm_score": 1,
"selected": false,
"text": "[DllImport(\"aclui.dll\", CharSet = CharSet.Auto)]\nstatic extern bool EditSecurity(IntPtr hwnd, ISecurityInform... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2844319/"
] |
74,225,736 | <p>In Julia, I want to stack heatmaps in one plot, just how it was done with Matlab in this stackoverflow post:
<a href="https://stackoverflow.com/questions/59749646/i-need-a-function-to-display-matrices-stacked">I need a function to display matrices stacked</a>
Preferably with the same color bar for all heatmaps, and with the ability to specify the position of each plane (i.e. along the third dimension).</p>
<p>I know how to stack surface plots by adding an offset to each surface (see this page: <a href="https://plotly.com/julia/3d-surface-plots/" rel="nofollow noreferrer">https://plotly.com/julia/3d-surface-plots/</a>), but this is not what I want to achieve as a surface plot is not flat, but, as the name suggests, a <em>surface</em>. My workaround currently is to use an offset large enough that each surface <em>appears</em> to be flat, but as the third axis relates to the real world height of my measurements, I am not happy with this fix.</p>
<p>What I would prefer is a parameter <code>positions_z = [z1, z2, z3, ...]</code> that specifies the location of all heatmaps along the third axis, but I am also happy with workarounds.
Does anyone know a solution?</p>
| [
{
"answer_id": 74239781,
"author": "August",
"author_id": 2498956,
"author_profile": "https://Stackoverflow.com/users/2498956",
"pm_score": 3,
"selected": true,
"text": "using GLMakie\n\nxs = range(-1, 1, length=10)\nheights = 1:5\n\ndata = reshape(heights, 1, 1, :) .* (xs .^2 .+ xs' .^2... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16560237/"
] |
74,225,739 | <p>I'm trying to get values of some specific form fields and then generate a XML file based on that data using JS actions when a user clicks a button in Adobe Acrobat. It's possible to get those values but I'm not sure how to generate that xml and provide it to the user.
I do check these documents but can't find anything related:</p>
<p><a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Doc.js.html" rel="nofollow noreferrer">https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Doc.js.html</a></p>
<p><a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/App.js.html" rel="nofollow noreferrer">https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/App.js.html</a></p>
<p><a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Util.js.html" rel="nofollow noreferrer">https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Util.js.html</a></p>
<p><a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Event.js.html" rel="nofollow noreferrer">https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Event.js.html</a></p>
<p><a href="https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Field.js.html" rel="nofollow noreferrer">https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/iosapi/files/Field.js.html</a></p>
<p>Any help would be appreciated.</p>
| [
{
"answer_id": 74350489,
"author": "joelgeraci",
"author_id": 4254700,
"author_profile": "https://Stackoverflow.com/users/4254700",
"pm_score": 0,
"selected": false,
"text": "this.exportAsXFDF();\n"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5995598/"
] |
74,225,756 | <p>I need help with a specific script, I have a form that performs an action with the "GET" method and I need to put a delay of 200ms before the form's action is executed.</p>
<p>Form:</p>
<pre><code><form action="#" method="GET" autocomplete="chrome-off" enctype="text/plain" id="form_cotation">
<div class="row">
<div class="text-center text-secondary h2 mb-3">
<b>FaΓ§a Sua CotaΓ§Γ£o Gratuita</b>
</div>
<div class="col-lg-6 ">
<div class="mb-3">
<label for="destinyGroup" class="form-label">Qual seu destino</label>
<select name="destinyGroup" id="destinyGroup" class="form-control ">
<option value="">Selecione seu destino</option>
<option value="1">Brasil</option>
<option value="2">AmΓ©rica Latina (inclui MΓ©xico)</option>
<option value="4">Estados Unidos e CanadΓ‘</option>
<option value="3">Europa</option>
<option value="5">Γsia</option>
<option value="6">Γfrica</option>
<option value="7">Oceania</option>
<option value="8">MΓΊltiplos destinos</option>
</select>
</div>
<div class="row">
<label class="form-label">Data da Viagem:</label>
<div class="col-lg-6 ">
<div class="mb-3">
<input type="text" class="form-control " id="departure" name="departure" value="" placeholder="Embarque" autocomplete="chrome-off" data-date-format='yyyy-mm-dd'>
</div>
</div>
<div class="col-lg-6 ">
<div class="mb-3">
<input type="text" class="form-control " id="arrival" name="arrival" value="" placeholder="Chegada" autocomplete="chrome-off" data-date-format='yyyy-mm-dd'>
</div>
</div>
</div>
<div class="mb-3 relative">
<label for="ages" class="form-label">Idade do(s) passageiro(s):</label>
<input type="text" class="form-control " id="ages" name="ages" value="Selecione as idades" readonly>
<div class="w-100 selectAges">
<div class="card">
<div class="card-body ">
<div class="row mt-2">
<div class="col-7 pt-2">
<label class="text-info h5"><span
class="text-primary"><b>0 a 40</b></span>
anos</label>
</div>
<div class="col-5 ages">
<div class="row">
<div class="col-4">
<div class="row">
<button class="btn-down">-</button>
</div>
</div>
<div class="col-4">
<div class="row">
<input type="text" class="w-100 p-0 text-center" name="old0" value="0" readonly>
</div>
</div>
<div class="col-4">
<div class="row">
<button class="btn-up">+</button>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-7 pt-2">
<label class="text-info h5"><span
class="text-primary"><b>41 a 64</b></span>
anos</label>
</div>
<div class="col-5 ages">
<div class="row">
<div class="col-4">
<div class="row">
<button class="btn-down">-</button>
</div>
</div>
<div class="col-4">
<div class="row">
<input type="text" class="w-100 p-0 text-center" name="old1" value="0" readonly>
</div>
</div>
<div class="col-4">
<div class="row">
<button class="btn-up">+</button>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-7 pt-2">
<label class="text-info h5"><span
class="text-primary"><b>65 a 75</b></span>
anos</label>
</div>
<div class="col-5 ages">
<div class="row">
<div class="col-4">
<div class="row">
<button class="btn-down">-</button>
</div>
</div>
<div class="col-4">
<div class="row">
<input type="text" class="w-100 p-0 text-center" name="old2" value="0" readonly>
</div>
</div>
<div class="col-4">
<div class="row">
<button class="btn-up">+</button>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-7 pt-2">
<label class="text-info h5"><span
class="text-primary"><b>76 a 99</b></span>
anos</label>
</div>
<div class="col-5 ages">
<div class="row">
<div class="col-4">
<div class="row">
<button class="btn-down">-</button>
</div>
</div>
<div class="col-4">
<div class="row">
<input type="text" class="w-100 p-0 text-center" name="old3" value="0" readonly>
</div>
</div>
<div class="col-4">
<div class="row">
<button class="btn-up">+</button>
</div>
</div>
</div>
</div>
</div>
<div class="text-center mt-4">
<a type="submit" class="btn btn-warning btn-aplicar text-white save">
<b>
Aplicar
</b>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6 ">
<div class="mb-3">
<label for="name" class="form-label">Nome:</label>
<input type="text" class="form-control " name="name" value="nome" id="name">
</div>
<div class="mb-3">
<label for="email" class="form-label">E-mail:</label>
<input type="email" name="email" class="form-control " id="email" value="email" id="email">
</div>
<div class="mb-3">
<label for="phone" class=" form-label">Telefone:</label>
<input type="text" name="phone" class="phone form-control " id="phone" value="telefone" id="phone">
</div>
</div>
<div class="col-lg-12 mt-3 mb-3 order-3">
<button class="btn w-100 btn-cotation" id="submitbtnt" type="submit">Cotar agora! βΊβΊ</button>
</div>
</div>
</form>
</code></pre>
<p>and script</p>
<pre><code>let timeToWait = 200;
let button = document.getElementById('submitbtnt');
setTimeout(() => {
button.onclick = function(e) {
e.preventDefault();
location.href ='URL-AQUI'
}
}, timeToWait);
</code></pre>
<p>I've tried in several ways but I'm not able to activate the delay with setTimeout()</p>
<p>In short, what I need is to leave a delay of 200ms before right after clicking the submit button</p>
| [
{
"answer_id": 74225823,
"author": "Frankusky",
"author_id": 4637140,
"author_profile": "https://Stackoverflow.com/users/4637140",
"pm_score": 1,
"selected": true,
"text": "setTimeout"
},
{
"answer_id": 74225929,
"author": "While1",
"author_id": 3573075,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20264830/"
] |
74,225,763 | <p>I'm trying to get multiple values from different cells in a sheet in Google Sheets and add in another sheet, but I couldn't figure out how to do it with setValue and getValue functions.</p>
<pre><code>function Formulario() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formCadastro = ss.getSheetByName("Cadastro2");
var dataS = ss.getSheetByName("Base1");
var cellNome = formCadastro.getRange("B4");
var cellSobrenome = formCadastro.getRange("B5");
var arrayCells = [
cellNome,
cellSobrenome
];
dataS.getRange(dataS.getLastRow()+1,1,1,2).setValue(arrayCells.getValue());
}
</code></pre>
<p>And if I use, I don't get any value from the variables added to Base1, only a new row:</p>
<pre><code> dataS.getRange(dataS.getLastRow()+1,1,1,2).setValue(arrayCells);
</code></pre>
<p>Before I was using <strong>appendRow()</strong> and added <strong>.getValue()</strong> after the variables in the array, but I was getting problems with the other function I create to clean all the cells after saving, using <strong>for</strong> and <strong>getRange</strong>.</p>
<p>Was something like:</p>
<pre><code> var arrayCells = [
cellNome.getValue(),
cellSobrenome.getValue()
];
dataS.appendRow(arrayCells);
</code></pre>
<p>And the function to clean the cells, but it doesn't work with variable.getValue():</p>
<pre><code> for ( var i = 0 ; i < arrayCells.length ; i++ ) {
arrayCells[i].clearContent();
}
</code></pre>
<pre><code></code></pre>
| [
{
"answer_id": 74225823,
"author": "Frankusky",
"author_id": 4637140,
"author_profile": "https://Stackoverflow.com/users/4637140",
"pm_score": 1,
"selected": true,
"text": "setTimeout"
},
{
"answer_id": 74225929,
"author": "While1",
"author_id": 3573075,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5828177/"
] |
74,225,775 | <p>I'm trying to find some article that helps me in the work I have to do. I have a table with the questions and answers of a customer service on a website and I would like to create a correlation between cause and effect between them, regardless of the line in which the complaint was made and the question was answered, the idea would be to have a histogram that you give me a direction which are the most used words by the customers in the complaints that are in the STR_COMPLAINTS column and the most used words in the treatment of the STR_ANSWERS in the answers column. As follows example:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: left;">STR_COMPLAINTS</th>
<th style="text-align: left;">STR_ANSWERS</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1</td>
<td style="text-align: left;">My pizza came cold</td>
<td style="text-align: left;">We will create a temperature control before serving the pizza</td>
</tr>
<tr>
<td style="text-align: center;">:--:</td>
<td style="text-align: left;">:-------------------</td>
<td style="text-align: left;">:--------------</td>
</tr>
<tr>
<td style="text-align: center;">2</td>
<td style="text-align: left;">My Burger came cold</td>
<td style="text-align: left;">We will create a temperature control before serving the Burger</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Expected outcome:</strong></p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">WORD</th>
<th style="text-align: center;">QUESTION</th>
<th style="text-align: center;">ANSWERS</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">My</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">0</td>
</tr>
<tr>
<td style="text-align: center;">pizza</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">came</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">0</td>
</tr>
<tr>
<td style="text-align: center;">cold</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">0</td>
</tr>
<tr>
<td style="text-align: center;">We</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">will</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">create</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">a</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">temperature</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">control</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">before</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">serving</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">the</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: center;">Burger</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">2</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74225823,
"author": "Frankusky",
"author_id": 4637140,
"author_profile": "https://Stackoverflow.com/users/4637140",
"pm_score": 1,
"selected": true,
"text": "setTimeout"
},
{
"answer_id": 74225929,
"author": "While1",
"author_id": 3573075,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18883896/"
] |
74,225,832 | <p>My first Flutter project, which is a tricycle booking system, has just begun. Using the ListView widget, I wanted to display all of the active passengers that are saved in my Firebase Database. However, when I attempted to display it and place it in a List, all functions are working fineΒ at first click. When you click the button to view theΒ ListView a second time, all of the saved data are replicated. The list continues after my third click and grows by three. The image below illustrates what takes place when I repeatedly click on the ListView.</p>
<p>These are the blocks of code that are utilized for this functionality:</p>
<p><strong>CODE for Functionality</strong></p>
<pre><code>retrieveOnlinePassengersInformation(List onlineNearestPassengersList) async
{
dList.clear();
DatabaseReference ref = FirebaseDatabase.instance.ref().child("passengers");
for(int i = 0; i<onlineNearestPassengersList.length; i++)
{
await ref.child(onlineNearestPassengersList[i].passengerId.toString())
.once()
.then((dataSnapshot)
{
var passengerKeyInfo = dataSnapshot.snapshot.value;
dList.add(passengerKeyInfo);
print("passengerKey Info: " + dList.toString());
});
}
}
</code></pre>
<p><strong>CODE for the UI</strong></p>
<pre><code>body: ListView.builder(
itemCount: dList.length,
itemBuilder: (BuildContext context, int index)
{
return GestureDetector(
onTap: ()
{
setState(() {
chosenPassengerId = dList[index]["id"].toString();
});
Navigator.pop(context, "passengerChoosed");
},
child: Card(
color: Colors.grey,
elevation: 3,
shadowColor: Colors.green,
margin: EdgeInsets.all(8.0),
child: ListTile(
leading: Padding(
padding: const EdgeInsets.only(top: 2.0),
child: Icon(
Icons.account_circle_outlined,
size: 26.sp,
color: Color(0xFF777777),
),
),
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Text(
dList[index]["first_name"] + " " + dList[index]["last_name"],
style: TextStyle(
fontFamily: "Montserrat",
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
Icon(
Icons.verified_rounded,
color: Color(0xFF0CBC8B),
size: 22.sp,
),
],
),
],
),
),
),
);
},
),
</code></pre>
<p><strong>Expected Result:</strong></p>
<p><a href="https://i.stack.imgur.com/fRI6k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fRI6k.jpg" alt="enter image description here" /></a></p>
<p><strong>Actual Result AFTER CLICKING MANY TIMES:</strong></p>
<p><a href="https://i.stack.imgur.com/sQvG0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sQvG0.jpg" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74225823,
"author": "Frankusky",
"author_id": 4637140,
"author_profile": "https://Stackoverflow.com/users/4637140",
"pm_score": 1,
"selected": true,
"text": "setTimeout"
},
{
"answer_id": 74225929,
"author": "While1",
"author_id": 3573075,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20057368/"
] |
74,225,877 | <p>When module A imports B, and B imports A, I get error:
<code>ImportError: cannot import name from partially initialized module (most likely due to a circular import)</code>.</p>
<p>However, if I merge contents of both modules into one, no error happens. Is there a reason why python does not treat circularly imported files as one big one?</p>
<p>I understand, that ambiguity arises: "Which to run first?", but that can be easily achieved by slightly adjusting syntax of imports and specifying the priority/order of import. Something like:</p>
<pre><code>from foo import A priority 2
from foo import B priority 1
</code></pre>
<p>Please provide counter-arguments, if you see any.</p>
| [
{
"answer_id": 74226036,
"author": "Mike_96a",
"author_id": 20296788,
"author_profile": "https://Stackoverflow.com/users/20296788",
"pm_score": 0,
"selected": false,
"text": "import foo"
},
{
"answer_id": 74227800,
"author": "Buzz",
"author_id": 5321862,
"author_profi... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2487835/"
] |
74,225,893 | <p>I have the below code that is creating the PriortyQueue structure using Dart. But since I cannot use heapify function inside the Constructor or factory constructor I cannot initialize PQ with an existing set of List. Can somebody guide me and show me how I can use heapify while creating PQ instance so I can initialize it with an existing List? Also If you have any other suggestions against doing something like this please also help me as well. thank you</p>
<pre><code>class PriorityQueue<T extends Comparable<T>> {
List<T?> _tree;
PriorityQueue._(List<T?> tree) : _tree = tree;
factory PriorityQueue([List<T>? array]) {
List<T?> newArray = [null, ...array ?? []];
// ignore: todo
//TODO: missing heapify
return PriorityQueue._(newArray);
}
void insert(T node) {
_tree.add(node);
_swim(_tree.length - 1);
}
T getTop() {
_swap(1, _tree.length - 1);
T top = _tree.removeLast() as T;
_sink(1);
return top;
}
List<T> _heapify(List<T> array) {
int sinkNodeIndex = (array.length - 1) ~/ 2;
while (sinkNodeIndex >= 1) {
_sink(sinkNodeIndex);
sinkNodeIndex--;
}
}
void _sink(int nodeIndex) {
int leftChildIndex = nodeIndex * 2;
int rightChildIndex = leftChildIndex + 1;
int minNodeIndex = leftChildIndex;
// index can be unreachable
T? leftChild =
leftChildIndex >= _tree.length ? null : _tree[leftChildIndex];
T? rightChild =
rightChildIndex >= _tree.length ? null : _tree[rightChildIndex];
if (leftChild == null) {
return;
}
if (rightChild != null && leftChild.compareTo(rightChild) > 0) {
minNodeIndex = rightChildIndex;
}
if ((_tree[minNodeIndex] as T).compareTo(_tree[nodeIndex] as T) < 0) {
_swap(nodeIndex, minNodeIndex);
_sink(minNodeIndex);
}
}
void _swim(int nodeIndex) {
if (nodeIndex <= 1) return;
int parentIndex = nodeIndex ~/ 2;
if ((_tree[nodeIndex] as T).compareTo(_tree[parentIndex] as T) < 0) {
_swap(nodeIndex, parentIndex);
_swim(parentIndex);
}
}
void _swap(int i, int j) {
T temp = _tree[i] as T;
_tree[i] = _tree[j];
_tree[j] = temp;
}
@override
String toString() {
return _tree.toString();
}
}
</code></pre>
| [
{
"answer_id": 74236825,
"author": "lrn",
"author_id": 2156621,
"author_profile": "https://Stackoverflow.com/users/2156621",
"pm_score": 2,
"selected": true,
"text": "_heapify"
},
{
"answer_id": 74375577,
"author": "mert Γzerdem",
"author_id": 11680256,
"author_profil... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11680256/"
] |
74,225,894 | <p>I am currently trying to get the execution time for a ballerina function. For that I need to get the timestamp before and after calling the function.
How to get the timestamp in milliseconds using ballerina?</p>
<p>I have tried <code>time</code> module and I did not find a direct way to get it.</p>
| [
{
"answer_id": 74225931,
"author": "Niveathika",
"author_id": 4027644,
"author_profile": "https://Stackoverflow.com/users/4027644",
"pm_score": 2,
"selected": false,
"text": "time:utcNow()"
},
{
"answer_id": 74230888,
"author": "Niveathika",
"author_id": 4027644,
"aut... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10721779/"
] |
74,225,914 | <p>I have two datasets, one for <code>migration inflow</code> to county <code>A</code> from other counties and other for <code>migration outflow</code> from county <code>A</code> to other counties. In order to combine the two data sets as:</p>
<pre><code>County State Inflow Outflow Year
</code></pre>
<p>The common column between the two datasets are <code>Origin_Place</code>, <code>Origin_StateName</code> and <code>Year</code> in <code>migration inflow</code> and <code>Dest_place</code>, <code>Dest_StateName</code> and <code>Year</code> in <code>migration outflow</code>.</p>
<p>Part of the problem is that the common columns have unequal number of rows.</p>
<p>How can combine the two into one dataset in such a way that I don't have to hardcode each and every common county name?</p>
<p>My original migration outflow data has 517 observations and migration inflow has 441, thus different number of counties in each dataset.</p>
<p>Dummy data:</p>
<pre><code># People moving out of county A to other counties
Origin_County_Name = c("A", "A", "A", "A", "A", "A", "A")
Origin_StateName = c("FL", "FL", "FL", "FL", "FL", "FL", "FL")
Individuals = c(223, 224, 2333, 4444, 5555, 6666, 7777)
Dest_place = c("B", "C", "D", "E", "F", "G", "H")
Dest_StateName = c("BB", "CC", "DD", "EE", "FF", "GG", "HH")
Year = c(2019, 2019, 2019, 2019, 2020, 2020, 2020)
Outflow_df = data.frame(Origin_County_Name, Origin_StateName, Individuals, Dest_place, Dest_StateName, Year)
# People moving in county A from other counties
Origin_Place = c("D", "E", "F")
Origin_StateName = c("DD", "EE", "FF")
Individuals = c(111, 8888, 9999)
Dest_County_Name = c("A", "A", "A")
Dest_StateName = c("FL", "FL", "FL")
Year = c(2019, 2019, 2020)
Inflow_df = data.frame(Origin_Place, Origin_StateName, Individuals, Dest_County_Name, Dest_StateName, Year)
</code></pre>
| [
{
"answer_id": 74225988,
"author": "stefan_aus_hannover",
"author_id": 2868899,
"author_profile": "https://Stackoverflow.com/users/2868899",
"pm_score": 2,
"selected": true,
"text": "all=T"
},
{
"answer_id": 74226114,
"author": "Will Oldham",
"author_id": 11501517,
"a... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12547996/"
] |
74,225,918 | <p>I have a dataframe row as such like below</p>
<pre><code>a | b | c | d
1 |-700.5;-1000.0;200.0| yes | blue
</code></pre>
<p>I want to change column b to be numeric so I can do data work like sorting on it but when I try the below code</p>
<pre><code>df= pd.to_numeric(df["b"])
print(df)
</code></pre>
<p>Get error ValueError: Unable to parse string or issue with "-".</p>
| [
{
"answer_id": 74225988,
"author": "stefan_aus_hannover",
"author_id": 2868899,
"author_profile": "https://Stackoverflow.com/users/2868899",
"pm_score": 2,
"selected": true,
"text": "all=T"
},
{
"answer_id": 74226114,
"author": "Will Oldham",
"author_id": 11501517,
"a... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9390633/"
] |
74,225,934 | <p>I want to implement something like rust's dyn trait(I know this doesn't work for multiple inheritance)</p>
<blockquote>
<pre><code>template<template<typename> typename Trait>
class Dyn
{
struct _SizeCaler:Trait<void>{ void* _p;};
char _buffer[sizeof(_SizeCaler)];
public:
template<typename T>
Dyn(T* value){
static_assert(std::is_base_of_v<Trait<void>,Trait<T>>
,"error Trait T,is not derive from trait<void>"
);
static_assert(sizeof(_buffer) >= sizeof(Trait<T>)
,"different vtable imple cause insufficient cache"
);
new (_buffer)Trait<T>{value};
}
Trait<void>* operator->(){
return static_cast<Trait<void>*>(reinterpret_cast<void*>(_buffer));
}
};
template<template<typename> typename Trait,typename T>
struct DynBase:Trait<void>
{
protected:
T* self;
public:
DynBase(T* value):self(value){}
};
struct Point{
double x,y;
};
struct Rect{
Point m_leftDown,m_rightUp;
Rect(Point p1,Point p2){
m_leftDown = Point{std::min(p1.x,p2.x),std::min(p1.y,p2.y)};
m_rightUp = Point{std::max(p1.x,p2.x),std::max(p1.y,p2.y)};
}
};
template<typename = void>
struct Shape;
template<>
struct Shape<void>
{
virtual double area() = 0;
};
template<>
struct Shape<Rect> final
:DynBase<Shape,Rect>
{
using DynBase<Shape,Rect>::DynBase;
double area() override{
return (self->m_rightUp.x - self->m_leftDown.x )
* (self->m_rightUp.y - self->m_leftDown.y);
}
};
void printShape(Dyn<Shape> ptr)
{
std::cout << ptr->area();
}
int main()
{
Rect r{{1,2},{3,4}};
printShape(&r);
}
</code></pre>
</blockquote>
<p>but I found that the c++standard may not be able to derive βnew (ptr) T() == static_cast<T*>(ptr)β?
So conversely, βstatic_cast<T*>(ptr) == new (ptr) T()β cannot prove</p>
<pre><code>Trait<void>* operator->(){ return static_cast<Trait<void>*>(reinterpret_cast<void*>(_buffer)); }
</code></pre>
<p>Other attempts</p>
<p>a abstruct class can't be a union member(why?),and I can't use placement new to calculate offset at compile time, because Trait is an abstract class.</p>
<p>So does the standard specify the validity of static_cast<T*>(ptr) == new (ptr) T()?</p>
| [
{
"answer_id": 74226088,
"author": "Ben Voigt",
"author_id": 103167,
"author_profile": "https://Stackoverflow.com/users/103167",
"pm_score": 2,
"selected": true,
"text": "new (ptr) T()"
},
{
"answer_id": 74226429,
"author": "user17732522",
"author_id": 17732522,
"auth... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351324/"
] |
74,225,938 | <p>I'm trying to deploy a 2nd generation cloud function as a zip file. The code is the following:</p>
<pre><code>// index.js
const functions = require('@google-cloud/functions-framework');
functions.http('mp4Transcoder', (req, res) => {});
</code></pre>
<pre><code>// dev-server.js
#!/usr/bin/env node
const express = require('express')
const app = express()
const router = express.Router()
const func = require('./index')
const bodyParser = require('body-parser')
app.use(bodyParser.raw({ type: 'application/octet-stream' }))
router.post('/transcoder', func.transcode)
router.options('/transcoder', func.transcode)
app.use('/', router)
// start the server
const port = 3030
const http = require('http')
app.set('port', port)
const server = http.createServer(app)
server.listen(port)
</code></pre>
<pre><code>// package.json
{
"name": "transcoder-cloud-function",
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0"
}
}
</code></pre>
<p>If I copy and paste this code and deploy the cloud function, it works. However, if I zip the three files and try to create uploading the zip file, the deployment fails with "function.js does not exist".</p>
<p>Any ideas of what I could try?</p>
<p><a href="https://i.stack.imgur.com/Xyf9S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xyf9S.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74226088,
"author": "Ben Voigt",
"author_id": 103167,
"author_profile": "https://Stackoverflow.com/users/103167",
"pm_score": 2,
"selected": true,
"text": "new (ptr) T()"
},
{
"answer_id": 74226429,
"author": "user17732522",
"author_id": 17732522,
"auth... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5261664/"
] |
74,225,943 | <p>I have my normal button that says "hide" in html and I would like to know how I can make with javasript so that when you click the text changes to show and when you click again back to hide and like that all the time</p>
<p>I think you could change the text with event listener but how do you change it back to its original state?</p>
<p>If anyone can help me with this It would be great</p>
<p>Thanks</p>
<p>the code for the button is here</p>
<p><code><button type="button">hide</button></code></p>
| [
{
"answer_id": 74226066,
"author": "Aman Mehta",
"author_id": 13378772,
"author_profile": "https://Stackoverflow.com/users/13378772",
"pm_score": 2,
"selected": true,
"text": "var btn = document.getElementById('btn');\nbtn.addEventListener('click', () => {\n debugger;\n var btnText = b... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19712977/"
] |
74,225,949 | <p>I am writing a python program that will parse a large dataframe (tens of thousands of lines) into smaller dataframes based on a column value, and it needs to be fairly efficient, because the user can change the ways they break up the dataframe, and I would like the output to update dynamically.</p>
<p>Example input:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: left;">Column_1</th>
<th style="text-align: left;">Column_2</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Oct</td>
<td style="text-align: left;">10000$</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Dec</td>
<td style="text-align: left;">9000$</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: left;">Oct</td>
<td style="text-align: left;">3400$</td>
</tr>
<tr>
<td style="text-align: left;">3</td>
<td style="text-align: left;">Dec</td>
<td style="text-align: left;">20000$</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: left;">Nov</td>
<td style="text-align: left;">9000$</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Nov</td>
<td style="text-align: left;">15000$</td>
</tr>
</tbody>
</table>
</div>
<p>Example Output:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: left;">Column_1</th>
<th style="text-align: left;">Column_2</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Oct</td>
<td style="text-align: left;">10000$</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Nov</td>
<td style="text-align: left;">15000$</td>
</tr>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: left;">Dec</td>
<td style="text-align: left;">9000$</td>
</tr>
</tbody>
</table>
</div><div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: left;">Column_1</th>
<th style="text-align: left;">Column_2</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: left;">Oct</td>
<td style="text-align: left;">3400$</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: left;">Nov</td>
<td style="text-align: left;">9000$</td>
</tr>
</tbody>
</table>
</div><div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: left;">Column_1</th>
<th style="text-align: left;">Column_2</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">3</td>
<td style="text-align: left;">Dec</td>
<td style="text-align: left;">20000$</td>
</tr>
</tbody>
</table>
</div>
<p>The naΓ―ve way, in my mind, is to do something like this:</p>
<pre><code>for id in list(df['id'].unique()):
filtered_df = df[df['id'] == id]
</code></pre>
<p>But I believe this would be looping over the same data more times than is necessary, which is inefficient. Is there a fast way of doing this?</p>
<hr />
<h2>Update</h2>
<p>Did a little software drag racing. Here are the results:</p>
<pre><code>%%timeit
[df.loc[df.id.eq(i)] for i in df.id.unique()]
</code></pre>
<p>9.96 ms Β± 1.26 ms per loop (mean Β± std. dev. of 7 runs, 100 loops each)</p>
<pre><code>%%timeit
dflist=[]
dflist2=[]
for k,v in df.groupby(['id']):
var='id'+str(k)
dflist.append(var)
globals()[var] = v
dflist2.append(v)
</code></pre>
<p>1.28 ms Β± 92.2 Β΅s per loop (mean Β± std. dev. of 7 runs, 1,000 loops each)</p>
<pre><code>%%timeit
d = {id:df[df.id==id] for id in df.id.unique()}
</code></pre>
<p>9.19 ms Β± 885 Β΅s per loop (mean Β± std. dev. of 7 runs, 100 loops each)</p>
<p>Does anyone know why the second solution would be so much faster?</p>
| [
{
"answer_id": 74226078,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 0,
"selected": false,
"text": "[df.loc[df.id.eq(i)] for i in df.id.unique()]\n"
},
{
"answer_id": 74226080,
"author": "Naveed",
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74225949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16292661/"
] |
74,226,030 | <p>I've got the following code in React-Admin v3</p>
<pre><code> <AutocompleteInput
onSelect={(value) => {
setCurrentCategory({ reference: value.id });
}}
</code></pre>
<p>After upgrading to v4 now the AutocompleteInput uses MUI not downshift, as described in <a href="https://marmelab.com/react-admin/Upgrade.html#autocompleteinput-and-autocompletearrayinput-now-use-mui-autocomplete" rel="nofollow noreferrer">https://marmelab.com/react-admin/Upgrade.html#autocompleteinput-and-autocompletearrayinput-now-use-mui-autocomplete</a></p>
<p>So the code above breaks with the error:
<code>Property 'id' does not exist on type 'SyntheticEvent<HTMLDivElement, Event>'.</code></p>
<p>How can I get the selectedItem again as per <a href="https://github.com/downshift-js/downshift#onselect" rel="nofollow noreferrer">onSelect on downshift</a> but using React-Admin v4 with MUI?</p>
| [
{
"answer_id": 74226078,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 0,
"selected": false,
"text": "[df.loc[df.id.eq(i)] for i in df.id.unique()]\n"
},
{
"answer_id": 74226080,
"author": "Naveed",
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/388038/"
] |
74,226,056 | <p>How can this code be accomplished using ToDictionary() instead of a For Each</p>
<pre><code> Dim stringDict As Dictionary(Of String, String) = new Dictionary(Of Integer, String)
Dim stringList As List(Of String) = {"alpha", "beta", "gamma", "delta"}
For Each stringItem As String In stringList
stringDict.Add($"Entry{stringDict.Count+1}",stringItem)
Next
</code></pre>
<p>This is what I am trying to do:</p>
<pre><code>Dim stringDict As Dictionary(Of String, String) = stringList.ToDictionary(Function(a) $"Entry{?}", Function(b) b)
</code></pre>
<p>I was hoping there might be a variable with the current row or index, or an incrementor</p>
| [
{
"answer_id": 74226078,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 0,
"selected": false,
"text": "[df.loc[df.id.eq(i)] for i in df.id.unique()]\n"
},
{
"answer_id": 74226080,
"author": "Naveed",
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15001456/"
] |
74,226,092 | <p>Given an input tuple, the goal is to produce a dictionary with some pre-defined keys, e.g. in this case, we have an <code>add_header</code> lambda and use the unpacking inside when calling the function.</p>
<pre><code>>>> z = (2,1)
>>> add_header = lambda x, y: {"EVEN": x, "ODD": y}
>>> add_header(*z)
{'EVEN': 2, 'ODD': 1}
</code></pre>
<p>My question is, is there way where the unpacking doesn't need to done when calling the <code>add_header</code> function?</p>
<p>E.g. I can change avoid the lambda and do it in a normal function:</p>
<pre><code>>>> def add_header(input):
... x, y = input
... return {"EVEN": x, "ODD":y}
...
>>> z = (2, 1)
>>> add_header(z)
{'EVEN': 2, 'ODD': 1}
</code></pre>
<p>Or I could not use the unpacking and use the index of the tuple, i.e. the <code>z[0]</code> and <code>z[1]</code>:</p>
<pre><code>>>> z = (2, 1)
>>> add_header = lambda z: {"EVEN": z[0], "ODD": z[1]}
>>> add_header(z)
{'EVEN': 2, 'ODD': 1}
</code></pre>
<p>But is there some way to:</p>
<ul>
<li>Use the lambda</li>
<li>Don't explicitly use the indexing in the tuple</li>
<li>Don't unpack with <code>*</code> when calling the <code>add_header()</code> function but it's okay to be inside the lambda function.</li>
</ul>
<p>and still achieve the same <code>{'EVEN': 2, 'ODD': 1}</code> output given <code>z = (2,1)</code> input?</p>
<hr />
<p>I know this won't work but does something like this exist?</p>
<pre><code>z = (2,1)
add_header = lambda x, y from *x: {"EVEN": x, "ODD": y}
add_header(z)
</code></pre>
| [
{
"answer_id": 74226137,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "dict()"
},
{
"answer_id": 74226175,
"author": "wjandrea",
"author_id": 4518341,
"author_p... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/610569/"
] |
74,226,105 | <p>I am very new to <code>ReactJS</code>. I have an array of object coming from <code>API</code> like this:</p>
<pre><code>transact = [
{
"id": 111,
"trans_id": "NP2209200435",
"order_id": "POWERRw8",
"full_name": "Customer/INSTANT",
"narration": "2035011W",
"amount": "10.0000",
"email": "xyz@g.com",
"order_time": "2022-09-20 16:23:49",
"merchant_id": "MID629dcf88a4537",
"bank_id": null,
"gateway": "N/A",
"transaction_status": "Pending",
"card_scheme": null,
"attempts": 0,
"review_status": null
},
{
"id": 111,
"trans_id": "NP2209200435",
"order_id": "POWERRw8",
"full_name": "Customer/INSTANT",
"narration": "2035011W",
"amount": "10.0000",
"email": "xyz@g.com",
"order_time": "2022-09-20 16:23:49",
"merchant_id": "MID629dcf88a4537",
"bank_id": null,
"gateway": "N/A",
"transaction_status": "Pending",
"card_scheme": null,
"attempts": 0,
"review_status": null
},
{
"id": 111,
"trans_id": "NP2209200435",
"order_id": "POWERRw8",
"full_name": "Customer/INSTANT",
"narration": "2035011W",
"amount": "10.0000",
"email": "xyz@g.com",
"order_time": "2022-09-20 16:23:49",
"merchant_id": "MID629dcf88a4537",
"bank_id": null,
"gateway": "N/A",
"transaction_status": "Pending",
"card_scheme": null,
"attempts": 0,
"review_status": null
},
{
"id": 111,
"trans_id": "NP2209200435",
"order_id": "POWERRw8",
"full_name": "Customer/INSTANT",
"narration": "2035011W",
"amount": "10.0000",
"email": "xyz@g.com",
"order_time": "2022-09-20 16:23:49",
"merchant_id": "MID629dcf88a4537",
"bank_id": null,
"gateway": "N/A",
"transaction_status": "Pending",
"card_scheme": null,
"attempts": 0,
"review_status": null
},
{
"id": 111,
"trans_id": "NP2209200435",
"order_id": "POWERRw8",
"full_name": "Customer/INSTANT",
"narration": "2035011W",
"amount": "10.0000",
"email": "xyz@g.com",
"order_time": "2022-09-20 16:23:49",
"merchant_id": "MID629dcf88a4537",
"bank_id": null,
"gateway": "N/A",
"transaction_status": "Pending",
"card_scheme": null,
"attempts": 0,
"review_status": null
}
]
</code></pre>
<p>And I wanted to convert few of those data to array form like this:</p>
<pre><code>[
['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537'],
['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537'],
['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537'],
['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537']
]
</code></pre>
<p>I've tried some sort solutions searched on <code>SO</code>, but still getting my normal tries, which are the following (Note: it added the second index into first index):</p>
<pre><code>['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537', 'NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537', 'NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537' ],
['NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537', 'NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537', 'NP2209200435', 'POWERRw8', 'Customer/INSTANT', '2035011W', '10.0000', 'MID629dcf88a4537' ]
</code></pre>
<p>I used:</p>
<pre><code>let dataSet = [];
response.data.transactions.forEach((item) => {
dataSet.push(
item.trans_id,
item.order_id,
item.full_name,
item.amount,
item.transaction_status,
item.narration,
item.created_at
);
});
</code></pre>
<p>and</p>
<pre><code>const trans_id = response.data.transactions.map(item => item.trans_id)
const order_id = response.data.transactions.map(item => item.order_id)
const full_name = response.data.transactions.map(item => item.full_name)
dataSet = [
trans_id,
order_id,
full_name
];
</code></pre>
<p>I need to populate it into <code>datatable</code>.</p>
| [
{
"answer_id": 74226986,
"author": "Falola Ibrahim Ayobami",
"author_id": 14974442,
"author_profile": "https://Stackoverflow.com/users/14974442",
"pm_score": 1,
"selected": false,
"text": "const convert = (arr) => {\n const newArr = arr.map((obj) => {\n delete obj.id;\n delete obj... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9077347/"
] |
74,226,143 | <p>My goal is to create a stratigraphic column (colored stacked rectangles) using matplotlib like the example below.
<a href="https://i.stack.imgur.com/ZKAsC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZKAsC.jpg" alt="enter image description here" /></a></p>
<p>Data is in this format:</p>
<pre><code>depth = [1,2,3,4,5,6,7,8,9,10] #depth (feet) below ground surface
lithotype = [4,4,4,5,5,5,6,6,6,2] #lithology type. 4 = clay, 6 = sand, 2 = silt
</code></pre>
<p>I tried matplotlib.patches.Rectangle but it's cumbersome. Wondering if someone has another suggestion.</p>
| [
{
"answer_id": 74226986,
"author": "Falola Ibrahim Ayobami",
"author_id": 14974442,
"author_profile": "https://Stackoverflow.com/users/14974442",
"pm_score": 1,
"selected": false,
"text": "const convert = (arr) => {\n const newArr = arr.map((obj) => {\n delete obj.id;\n delete obj... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19402292/"
] |
74,226,157 | <p>I want to update a datagridview from a thread using VB.</p>
<p>I have tried two approaches so far, but clearly I am missing something. The two methods are:</p>
<pre><code>If Control.invokeRequired Then
Control.Invoke(Sub() Control.rows.add(Event*Date, Event*Details))
</code></pre>
<p>And I have tried:</p>
<pre><code>If Control.InvokeRequired then
Control.Invoke(New Addrow(AddressOf Form1.AddToDatatable), New Object() {Data_row})
</code></pre>
<p>Where</p>
<pre><code>Public Delegate Sub Addrow(ByVal Data_row As DataRow)
Public Sub AddToDatatable(ByVal Data_row As DataRow)
Data_table.Rows.Add(Data_row)
Daily_Log.Refresh()
End Sub
</code></pre>
| [
{
"answer_id": 74226986,
"author": "Falola Ibrahim Ayobami",
"author_id": 14974442,
"author_profile": "https://Stackoverflow.com/users/14974442",
"pm_score": 1,
"selected": false,
"text": "const convert = (arr) => {\n const newArr = arr.map((obj) => {\n delete obj.id;\n delete obj... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7478148/"
] |
74,226,159 | <p>How do I take the data from one populated treeview and put it into another existing treeview.
All the nodes and children need to be copied.</p>
| [
{
"answer_id": 74226339,
"author": "Ehab",
"author_id": 20342736,
"author_profile": "https://Stackoverflow.com/users/20342736",
"pm_score": 2,
"selected": false,
"text": "var\n MS: TMemoryStream;\nbegin\n MS := TMemoryStream.Create;\n try\n Tree1.SaveToStream(MS);\n MS.Position ... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/322718/"
] |
74,226,197 | <p>I have created an integer program in Python with GurobiPy for the 0-1 knapsack problem. However, I want to add a constraint that sais that if product x is added, then product y must also be added for some product couples.</p>
<p>My current model:
There are 2 warehouses, if products are stored in the main warehouse, the profit loss (due to delays) is 0. If the products are stored in the new warehouse, the profit loss is as presented in the dataframe. The objective is to minimize the profit loss</p>
<pre><code># Note: I run the program for the second warehouse because Xi returns values of 1 if placed in the warehouse
# so I can calculate the profit loss easier by just multiplying Xi by the profit loss
c = 1720 # total number of boxes minus capacity of the main warehouse
p = dfGurobi['profit'].tolist() # profit of each product
w = dfGurobi['boxes_required'].tolist() # weight of each product (=number of boxes required)
l = dfGurobi['profitLoss'].tolist() # profit loss of each product
n = len(p) # so determine the number of variables
assert n == len(w) # lengths of p and w should be the same
model = Model() # create a model
x = model.addVars(n, vtype=GRB.BINARY) # add variables
model.setObjective(quicksum(l[i] * x[i] for i in range(n)), GRB.MINIMIZE) # set objective to minimize the profit loss generated by placing products in the new warehouse
model.addConstr(quicksum(w[i] * x[i] for i in range(n)) >= c) # set constraint that the number of boxes in the new warehouse is at least 1720 so that the number of boxes in the main warehouse is at most 960
result = model.optimize() # optimize the model
print(result)
print("The optimal total profit loss is: %g" % model.objVal)
print(dfGurobi)
</code></pre>
<p>Also, I have a list of product couples indicating that if product 1 is placed in the main op new warehouse, the second product must also be placed in the same warehouse. This is the list:</p>
<pre><code> product2
product1
74 45
74 328
74 367
74 535
74 642
74 802
191 356
191 931
328 929
362 535
367 929
382 587
382 823
382 828
535 665
535 1223
574 931
642 1223
685 535
685 671
685 828
685 845
685 921
685 1030
823 931
828 747
828 931
845 592
1136 191
1136 587
1136 823
1136 828
1136 845
</code></pre>
<p>Background info:</p>
<p>my Pandas Dataframe looks like this;</p>
<pre><code> profitLoss profit boxes_required
product_id
571 96.849644 484.248219 1.0
533 96.358619 481.793096 1.0
831 89.424493 447.122466 1.0
276 77.455923 387.279616 1.0
162 76.336142 381.680712 1.0
... ... ... ...
337 0.478582 0.957163 1.0
840 0.468519 0.937037 1.0
433 0.385460 0.770919 1.0
384 0.305156 0.610311 1.0
361 0.274544 0.549088 1.0
[1263 rows x 3 columns]
</code></pre>
<p>How can I best add the product couples as a constraint?
Edit:
My specific problem is: If product 1 is added to the warehouse (i.e. has a value of Xi = 1), then product 2 must also be added (i.e. have a value of Xi = 1). How can I do this?</p>
| [
{
"answer_id": 74236062,
"author": "Erwin Kalvelagen",
"author_id": 5625534,
"author_profile": "https://Stackoverflow.com/users/5625534",
"pm_score": 1,
"selected": false,
"text": " x[j] >= x[i]\n"
},
{
"answer_id": 74246673,
"author": "RB Vries de",
"author_id": 20255604... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20255604/"
] |
74,226,239 | <p>Hi,</p>
<p>I have a function like this</p>
<pre><code>checkconnection();
</code></pre>
<p>I want to execute it 5 times before this function below triggers:</p>
<pre><code>console.log('cant connect. Try again later');
</code></pre>
<p>How can I do that?</p>
<p>Thank you.</p>
| [
{
"answer_id": 74226411,
"author": "imvain2",
"author_id": 3684265,
"author_profile": "https://Stackoverflow.com/users/3684265",
"pm_score": 2,
"selected": true,
"text": "let cntr = 1;\n\nfunction checkconnection(){\n if(cntr == 5){\n console.log('cant connect. Try again later');\... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2230939/"
] |
74,226,250 | <p>I get this error:</p>
<blockquote>
<p>Member not found: 'FirebaseAppPlatform.verifyExtends'.
FirebaseAppPlatform.verifyExtends(_delegate);</p>
</blockquote>
<pre><code>flutter clean
flutter pub get
pod install
</code></pre>
| [
{
"answer_id": 74227868,
"author": "Plywood",
"author_id": 2005565,
"author_profile": "https://Stackoverflow.com/users/2005565",
"pm_score": 3,
"selected": false,
"text": "firebase_core_platform_interface: 4.5.1\n"
},
{
"answer_id": 74228013,
"author": "Praharsh Bhatt",
"... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351610/"
] |
74,226,259 | <p>So I got this mathematical equation and I need to write it in pure JS using the Math object obviously.</p>
<p>I looked up at the docs about the required methods to solve it, but I get the NaN in the console when I output the result.</p>
<p>I suppose it's my stupid brain that cannot solve this correctly</p>
<p>Here's 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
z = 5
, x = 10
, y = 2
, b = Math.cos(Math.pow(2)) * z + Math.tan(2 * x) + Math.abs(y)
;
console.log(b);</code></pre>
</div>
</div>
</p>
<p><a href="https://i.stack.imgur.com/4Eqs0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Eqs0.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74226328,
"author": "Mister Jojo",
"author_id": 10669010,
"author_profile": "https://Stackoverflow.com/users/10669010",
"pm_score": 3,
"selected": true,
"text": "let\n z = 5\n, x = 10\n, y = 2\n, b = Math.cos(z)**2 + Math.tan(2 * x) + Math.abs(y)\n ;\nconsole.log(b);"
... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13646793/"
] |
74,226,298 | <p>Here is my code snippet</p>
<p><a href="https://codesandbox.io/s/dropdown-primereact-gjcdm0?file=/src/demo/DropdownDemo.js" rel="nofollow noreferrer">https://codesandbox.io/s/dropdown-primereact-gjcdm0?file=/src/demo/DropdownDemo.js</a></p>
<p>I am making an API call for my dropdown,
Expected: The currency codes should be visible on drop down once I select it and also the options should be showing up</p>
<p>Actual: The currency is not visible on the dropdown, but the options are correctly fetched and placed in dropdown</p>
<p>Please let me know if I can persist the value onClick on the dropdown</p>
| [
{
"answer_id": 74226833,
"author": "rustyBucketBay",
"author_id": 11826132,
"author_profile": "https://Stackoverflow.com/users/11826132",
"pm_score": -1,
"selected": false,
"text": "useEffect(() => {\n fetchData(currency);\n }, []);\n"
}
] | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351542/"
] |
74,226,322 | <p>Im trying to create little program where if user inputs ip or port from command line it connect to a server.</p>
<pre><code>my code
ip := flag.String("i","","") // i choosen user provide ip but port will be default :8080
port := flag.String("p", "","") // p choosen has connect to port :???? but ip will be local host
ipPort := flaf.String("b","","") // b choosen user provides both ip and port
default_Ip := flag.String("d","","")// d choosen it connect to localhost ip and port 127.0.0.1:8080
flag.Parse()
log.Fatal(http.ListenAndServe(ip, nil))
log.Fatal(http.ListenAndServe(port, nil))
log.Fatal(http.ListenAndServe(ipPort, nil))
log.Fatal(http.ListenAndServe(default, nil))
</code></pre>
<p>what im doing wrong? Point me out to right direction?</p>
| [
{
"answer_id": 74226520,
"author": "monrovio",
"author_id": 20351805,
"author_profile": "https://Stackoverflow.com/users/20351805",
"pm_score": 0,
"selected": false,
"text": "log.Fatal(http.ListenAndServe(*ip, nil))"
},
{
"answer_id": 74241688,
"author": "matthold",
"auth... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19880359/"
] |
74,226,330 | <p>I am writing a program that will have an arbitrary number of <code>:</code> and <code>None</code> in arbitrary locations of an n-dimensional NumPy array. Therefore, I want a way to unpack these <code>:</code> and <code>None</code> axis operators into the <code>[]</code> that indexes an array and auto-populates certain axes according to where the <code>:</code> and <code>None</code> are. According to Pylance:</p>
<blockquote>
<p>Unpack operator in subscript requires Python 3.11 or newerPylance</p>
</blockquote>
<p>However, while using Python 3.11, I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "/home/.../quant.py", line 261, in <module>
print(arr[*lhs_axes] + arr2[None,None,:])
~~~^^^^^^^^^^^
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
</code></pre>
<p>Current code:</p>
<pre><code>import numpy as np
if __name__ == "__main__":
lhs_ind, rhs_ind = 'ij', 'k'
lhs_axes = [':' for i in lhs_ind]
lhs_axes.append(None)
arr1 = np.ones((2,2))
arr2 = np.ones(2)
print(arr1[*lhs_axes] + arr2[None,None,:])
</code></pre>
| [
{
"answer_id": 74226702,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "':'"
},
{
"answer_id": 74226964,
"author": "hpaulj",
"author_id": 901925,
"author_profile": "ht... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14684863/"
] |
74,226,345 | <p>In my C++ application I configure some features in this way:</p>
<pre><code>#define LED_SIZE 113
#define SEGMENT_SIZE 3
const int LED_SEGMENTS[SEGMENT_SIZE] = {30, 70, 13};
</code></pre>
<p>I would like to check if the sum of the literal values are equal to <code>LED_SIZE</code>:</p>
<pre><code>30+70+13 = 113
</code></pre>
<p>I'm interested to do this at <strong>compile time</strong>, using a pre-processor directives.
If the sum is not correct it should not compile.</p>
| [
{
"answer_id": 74226438,
"author": "apple apple",
"author_id": 5980430,
"author_profile": "https://Stackoverflow.com/users/5980430",
"pm_score": 2,
"selected": false,
"text": "static_assert"
},
{
"answer_id": 74226478,
"author": "MarkB",
"author_id": 17841694,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/881712/"
] |
74,226,349 | <p>I use Firebase for my backend but every time when the app request the image URL it loads very slow. How can I speed up this procedure? Or which CDN provider can I use in my React Native project to load images faster than now?</p>
<p>Thank you</p>
<p>I tried to request the URL from different sites but still slow load</p>
| [
{
"answer_id": 74226438,
"author": "apple apple",
"author_id": 5980430,
"author_profile": "https://Stackoverflow.com/users/5980430",
"pm_score": 2,
"selected": false,
"text": "static_assert"
},
{
"answer_id": 74226478,
"author": "MarkB",
"author_id": 17841694,
"author... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351639/"
] |
74,226,354 | <p>I have two lists</p>
<pre><code>x = ['34', '22', '45']
y = ['red', 'blue', 'grean']
</code></pre>
<p>I need to output these two lists together</p>
<pre><code>34, red
22, blue
45, grean
</code></pre>
<p>i tried to get it all through for in</p>
<pre><code>for a, b in x, y:
print(a, b)
</code></pre>
<p>but i get an error</p>
<blockquote>
<p>too many values to unpack (expected 2)</p>
</blockquote>
| [
{
"answer_id": 74226386,
"author": "L8R",
"author_id": 14551796,
"author_profile": "https://Stackoverflow.com/users/14551796",
"pm_score": 0,
"selected": false,
"text": "x = ['34', '22', '45']\ny = ['red', 'blue', 'green'] // you made a typo in 'green' so i fixed it\nfor i, x in enumerat... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,226,359 | <p>So I have a list of index <code>close_index</code> I want to iterate over these specific index and update the column values.</p>
<pre><code>hhinc8,owncar,longitude,latitude,category
5,1,-82.99194508,40.04649963,LRLC
6,2,-82.99584706,40.03738548,LRHC
5,1,-82.99697268,40.02674247,LRLC
6,2,-82.99160441,40.03612997,LRHC
1,2,-82.994716,40.04691778,ERHC
2,1,-82.99793728,40.04385713,ERLC
3,2,-82.98986012,40.03789279,ERHC
.
.
.
</code></pre>
<p><strong>close_index =[1,3,4]</strong></p>
<p>now in my code I update the all the close_index's <code>hhinc8</code> like
<code>df.loc[close_index,'hhinc8']=2</code>
now I want to update the category of all the close_index by checking the <code>owncar</code> variable. If <code>owncar</code> is 1 category should be <code>LRLC</code> else it should be <code>LRHC</code>.</p>
<p>I thought the best way to do this is by looping over all the index in <strong>close_index</strong> and checking the <code>owncar</code> and updating the category.</p>
<p>But I am unable to figure out a way to <strong>loop over specific index</strong>.
As the dataset I have is very big, looping over the whole dataset is very inefficient.
If there is a better way to do this, Please let me know.</p>
| [
{
"answer_id": 74226414,
"author": "Naveed",
"author_id": 3494754,
"author_profile": "https://Stackoverflow.com/users/3494754",
"pm_score": 2,
"selected": true,
"text": "# create a dictionary to map owncar to the category value\nd={1: 'LRLC', 2: 'LRHC'}\n\n\nclose_index =[1,3,4]\n\ndf['c... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19490188/"
] |
74,226,368 | <p>I have a menu with links that may look like one of the following:</p>
<pre><code>mywebsite.com/#find
mywebsite.com/about-us/#team
mywebsite.com/#social
mywebsite.com/services/#something
</code></pre>
<p>I want to do something <strong>only</strong> to the first and third links (the ones that don't have a subdirectory in the url path). How do I check if a # hash is the first element after the first slash in the link?</p>
<pre><code>$('#menu a').click(function() {
var target = this.href;
// check if "/#" is the first thing after the domain name
});
</code></pre>
<p>Thank you.</p>
| [
{
"answer_id": 74226546,
"author": "IT goldman",
"author_id": 3807365,
"author_profile": "https://Stackoverflow.com/users/3807365",
"pm_score": 0,
"selected": false,
"text": "https://"
},
{
"answer_id": 74226623,
"author": "Mohammad",
"author_id": 5104748,
"author_pro... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2274595/"
] |
74,226,379 | <p>I have the following node structure: <code>(:Patch)-[:INCLUDES]->(:Roster)-[:HAS]->(:PublicList)-[:INCLUDES]->(u:Unit)</code></p>
<p>Then I have an array of <code>:Unit</code> ids: <code>[197, 196, 19, 20, 191, 171, 3, 174, 194, 185]</code></p>
<p>I would like to check whether a <code>:PublicList</code> that has the <code>:INCLUDES</code> relationship to all the <code>:Unit</code> ids in the list already exists.</p>
<p>I tried writing a <code>COUNT</code> and <code>MATCH</code> query like this, but this just seems like an error-prone long-winded approach:</p>
<pre><code>MATCH (p:Patch)-[:INCLUDES]->(r:Roster)-[:HAS]-(d:PublicList)
WITH COLLECT(d) as drafts
UNWIND drafts as draft
WITH draft
UNWIND [197, 196, 19, 20, 191, 171, 3, 174, 194, 185] as unitID
MATCH (draft)-[:INCLUDES]->(u:Unit)
WHERE id(u) = unitID
WITH count(DISTINCT u) as draftUnits
WITH COLLECT(draftUnits) as matchCounts
RETURN matchCounts
</code></pre>
<p>Can someone help me write this so it returns a boolean if a <code>:PublicList</code> has a<code>:INCLUDES</code> relationship to all the IDs in the list?</p>
| [
{
"answer_id": 74227458,
"author": "Christophe Willemsen",
"author_id": 2662355,
"author_profile": "https://Stackoverflow.com/users/2662355",
"pm_score": 2,
"selected": true,
"text": "ALL"
},
{
"answer_id": 74234700,
"author": "jose_bacoy",
"author_id": 7371893,
"auth... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4341439/"
] |
74,226,407 | <p>I have three folders on my desktop, each containing 2,000 .txt files, with files named numerically from 1.txt through 2,000.txt.
I want to use R to create data frames using the contents of the .txt files, where each line from the file is a row in the data frame. I want the columns of the data frame to be</p>
<p>Eg: Data Frame 1:</p>
<pre><code>| Folder 1 | Folder 2 | Folder 3 |
| -------- | -------- | --------
| contents | contents | contents of
| of 1.txt | of 1.txt | 1.txt
from folder from folder from folder
1. 2. 3.
Data Frame 2:
| Folder 1 | Folder 2 | Folder 3 |
| -------- | -------- | --------
| contents | contents | contents of
| of 2.txt | of 2.txt | 2.txt
from folder from folder from folder
1. 2. 3.
</code></pre>
<p>I was able to create a dataframe for one .txt from one folder using:</p>
<pre><code>setwd('/Users/name/Desktop/foldername')
txt_1 = readLines("1.txt")
df1 = data.frame(txt_1)
</code></pre>
<ol>
<li><p>How do I iterate through the folder and create separate data frames for each of the 2,000 txt files?</p>
</li>
<li><p>Additionally, how do I add the 2,000 corresponding txt files from folder 2 and folder 3 and columns 2 and 3 in each of the dataframes?</p>
</li>
</ol>
<p>Thank you for the help!</p>
| [
{
"answer_id": 74227458,
"author": "Christophe Willemsen",
"author_id": 2662355,
"author_profile": "https://Stackoverflow.com/users/2662355",
"pm_score": 2,
"selected": true,
"text": "ALL"
},
{
"answer_id": 74234700,
"author": "jose_bacoy",
"author_id": 7371893,
"auth... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351621/"
] |
74,226,409 | <p>I was having some problems with a project on my android studio. so I deleted that project and start a new one but then following error shows up when I try to run the app.</p>
<pre><code>Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
</code></pre>
<p>it's very strange because I did not make any changes on to the hall project.
I tried to delete and recreate the project but it's the same error.</p>
| [
{
"answer_id": 74334054,
"author": "Radesh",
"author_id": 6401241,
"author_profile": "https://Stackoverflow.com/users/6401241",
"pm_score": 1,
"selected": false,
"text": "build.gradle"
},
{
"answer_id": 74376988,
"author": "Gaurav ",
"author_id": 16911506,
"author_pro... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17530237/"
] |
74,226,452 | <p>I currently have a form in which the results are returned into a targeted div.
It works great. EXCEPT when my form includes an upload ( INPUT TYPE="FILE" NAME="PIC_UPLOAD" ), in which case it simply does not work. Any ideas on what I am missing?
Here is the current (working) 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>/* attach a submit handler to the form */
$("#testform").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $(this),
url = $form.attr('action');
/* Send the data using post and put the results in a div */
$.post(url, $("#testform").serialize(),
function(data) {
var content = data;
$('#targetdiv').empty().append(content);
}
);
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div id="the form">
<form action="destination_file.html" id="testform">
<INPUT Type="hidden" NAME="func" VALUE="1004">
<TEXTAREA NAME="NOTES" ROWS=4 COLS=34></TEXTAREA>
<input type="submit" value="Submit">
</div>
<hr>
<div id="targetdiv"> results to go here </div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74334054,
"author": "Radesh",
"author_id": 6401241,
"author_profile": "https://Stackoverflow.com/users/6401241",
"pm_score": 1,
"selected": false,
"text": "build.gradle"
},
{
"answer_id": 74376988,
"author": "Gaurav ",
"author_id": 16911506,
"author_pro... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1056494/"
] |
74,226,474 | <pre><code>const [data,setData]=useState([])
</code></pre>
<p>i have Received that data as <code>{results:[20objects],info:{}}</code></p>
<p>i have tried console log of <code>Object.values(data)</code> showing that <code>[[20 objects],{}]</code></p>
<p>i have to do map over that 20 objects Array ?</p>
| [
{
"answer_id": 74334054,
"author": "Radesh",
"author_id": 6401241,
"author_profile": "https://Stackoverflow.com/users/6401241",
"pm_score": 1,
"selected": false,
"text": "build.gradle"
},
{
"answer_id": 74376988,
"author": "Gaurav ",
"author_id": 16911506,
"author_pro... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19851319/"
] |
74,226,485 | <p>I'm working on a web scraper. Among the fields it scrapes there is a Description tag like this one, different for each product:</p>
<pre><code><div class="productDescription" style="overflow: hidden; display: block;">
Black Tshirt
<br>
<br>
REF.: V23T87C88EC
<br>
<br>
COMPOSIΓΓO:
<br>
90% Poliamida
</div>
</code></pre>
<p>I can get the content of the description tag without problems, but I also need to get the value of REF inside the description (V23T87C88EC for this example).</p>
<p>The problem is this description is always different for all products, HOWEVER there is ALWAYS a "REF.: XXXXXXXXX" substring in there.
The length of the REF id can change, and it can be anywhere in the string.
What's the best way to always get the REF id?</p>
| [
{
"answer_id": 74334054,
"author": "Radesh",
"author_id": 6401241,
"author_profile": "https://Stackoverflow.com/users/6401241",
"pm_score": 1,
"selected": false,
"text": "build.gradle"
},
{
"answer_id": 74376988,
"author": "Gaurav ",
"author_id": 16911506,
"author_pro... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11036109/"
] |
74,226,503 | <p>I want to get the book author and the book title displayed in my rich text box. Here is a sample of my code:</p>
<pre><code> // Opretter info pΓ₯ bog
book.Author = "Hej Preben";
book.Title = "Hvem sagde hej?";
// tilfΓΈjer bogen til metoden
library.AddBook(book);
richTextBoxBooks.Text = library.GetAllBooks().ToString();
</code></pre>
<p>The GetallBooks is returning title and author (and a id), but when i look at my windows form, my textbox is displaying this: <a href="https://i.stack.imgur.com/rqGLp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqGLp.png" alt="Rich text box" /></a></p>
<p>My list is working, I just want to know how I can get the correct info displayed, insted of this.</p>
<p>Im feeling stuck, so have not tried many things</p>
| [
{
"answer_id": 74227796,
"author": "duerzd696",
"author_id": 17553803,
"author_profile": "https://Stackoverflow.com/users/17553803",
"pm_score": 0,
"selected": false,
"text": " string books = \"\";\n foreach(var item in someList)//replace someList with name of your list\n { //... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20275814/"
] |
74,226,510 | <p>I want to have a Game entity that has two List of player IDs stored as Longs</p>
<p>This is my table: game_player_team</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: right;">game_id</th>
<th style="text-align: right;">player_id</th>
<th style="text-align: right;">team</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">H</td>
</tr>
<tr>
<td style="text-align: right;">1</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">H</td>
</tr>
<tr>
<td style="text-align: right;">1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">A</td>
</tr>
<tr>
<td style="text-align: right;">1</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">A</td>
</tr>
</tbody>
</table>
</div>
<p>And this is how far I got modeling the Game entity</p>
<p>I can't work out how to get only the player_id's for the team H row and player_id's for the team A rows in to homePlayerIds and awayPlayerIds respectively.</p>
<p>I've seen the @Discriminator annotations but they only seem to work inheritence.</p>
<pre class="lang-java prettyprint-override"><code>@Entity
class Game {
@Id
private Long id
@ElementCollection
@CollectionTable(name="game_player_team", joinColumns={@JoinColumn(name="game_id")})
@Column(name="player_id")
private List<Long> homePlayerIds;
@ElementCollection
@CollectionTable(name="game_player_team", joinColumns={@JoinColumn(name="game_id")})
@Column(name="player_id")
private List<Long> awayPlayerIds;
}
</code></pre>
| [
{
"answer_id": 74226960,
"author": "Davide D'Alto",
"author_id": 2404683,
"author_profile": "https://Stackoverflow.com/users/2404683",
"pm_score": 2,
"selected": true,
"text": "@CollectionTable"
},
{
"answer_id": 74228046,
"author": "SternK",
"author_id": 6277104,
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/386464/"
] |
74,226,517 | <p>In my dataset, I have the following variables:</p>
<ul>
<li>gid = cell identifier</li>
<li>Year</li>
<li>Battle: count per year</li>
<li>Incidence: if at least one battle happened that year in that cell.
<em>For the construction of the incidence variable, I have used the following code: test$IncidenceBattles <-ifelse(Test$Battles>= 1,c(1), c(0))</em></li>
</ul>
<p>I would like to create a binary variable OnsetBattle that equals 1 if we observe at least 1 battle in a particular year and none in the preceding year.</p>
<p>Example for cell 115593 year 2001.
OnsetBattle will be equal to 1 because incidence battle = 1 in 2001 and there was no battle in 2000.</p>
<p>Note:
It's OK if there are missing values. Especially before 1997.</p>
<p>subset of my dataset:</p>
<pre><code>structure(list(gid = c(115593, 115593, 115593, 115593, 115593,
115593, 115593, 115593, 115593, 115593, 115593, 115593, 115593,
115593, 115593), Year = c(1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010), Battles = c(NA,
7, 9, 291, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0), IncidenceBattles = c(NA,
1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -15L), groups = structure(list(
gid = 115593, .rows = structure(list(1:15), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L), .drop = TRUE))
</code></pre>
| [
{
"answer_id": 74226960,
"author": "Davide D'Alto",
"author_id": 2404683,
"author_profile": "https://Stackoverflow.com/users/2404683",
"pm_score": 2,
"selected": true,
"text": "@CollectionTable"
},
{
"answer_id": 74228046,
"author": "SternK",
"author_id": 6277104,
"au... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16964076/"
] |
74,226,534 | <p>I have a <code>variables.cpp</code>, in which it defines:</p>
<pre><code>static MyNamespace::MyClass myObj('input');
</code></pre>
<p>I have a <code>variables.h</code> that is included by <code>variables.cpp</code></p>
<p>And I have a <code>main.cpp</code> that includes <code>variables.h</code>, which it refers to myObj:</p>
<pre><code>MyNameSpace::myObj.doRun();
</code></pre>
<p>And the compiler complains that: <code>no member named 'myObj' in namespace 'MyNameSpace'</code></p>
<p>What am I doing wrong?</p>
| [
{
"answer_id": 74227041,
"author": "hyde",
"author_id": 1717300,
"author_profile": "https://Stackoverflow.com/users/1717300",
"pm_score": 2,
"selected": false,
"text": "static"
},
{
"answer_id": 74227148,
"author": "apple apple",
"author_id": 5980430,
"author_profile"... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1008636/"
] |
74,226,536 | <p>I have an URL and I am trying to pass multiple params into it and fetch it with each param in the same call to provide the data for each param.
For example: param_1 has different data from param_2, and I am trying to fetch both datas in the same axios call.</p>
<pre><code>const data_1 = "param_1";
const data_2 = "param_2";
const URL = 'http://google_services?gls_url=${data_1}'
const URL = 'http://google_services?gls_url=${data_2}'
useEffect(()=> {
axios(URL).then(res => res.data);
},[])
</code></pre>
| [
{
"answer_id": 74227041,
"author": "hyde",
"author_id": 1717300,
"author_profile": "https://Stackoverflow.com/users/1717300",
"pm_score": 2,
"selected": false,
"text": "static"
},
{
"answer_id": 74227148,
"author": "apple apple",
"author_id": 5980430,
"author_profile"... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18836219/"
] |
74,226,542 | <p>I have an application in react native where i'm developing a search feature like Instagram.
It is like if user stop typing show him his query result.
my current approach is messing up redux. And sometimes it returns same element multiple times or sometime random elements which are irrelevant of that query.
right now. I'm calling search api immediately as use start typing in searchbar.</p>
<p>here is code below of my component.</p>
<pre><code>import { getSearchDataApi } from "../../api/search/search";
import { clearSearchData, setSearchData } from "../../redux/action/search";
const SearchScreen =(props)=>{
const [autoFocus,setAutoFocus] = useState(true)
const [keyWord,setKeyWord] = useState(null)
const [isLoading,setIsLoading] = useState(false)
const [isError,setIsError] = useState(false)
const [pageNumber,setPageNumber] = useState(1)
const [loadMore,setLoadMore] = useState(true)
const loadMoreDataFunc =()=>{
if (pageNumber <= props.totalSearchPage) {
setPageNumber(pageNumber+1)
}
else {
setLoadMore(false)
}
}
const searchData = async(keyWord)=>{
console.log(keyWord,pageNumber)
try {
setIsLoading(true)
var searchResponse = await getSearchDataApi(keyWord,pageNumber)
props.setSearchData(searchResponse.data)
setIsLoading(false)
}
catch (e) {
setIsError(true)
console.log("Error --- ", e.response.data.message)
showMessage({
message: e.response.data.message,
type: "danger",
});
}
}
return (
<View>
....
</View>
)
}
const mapStateToProps = (state)=>({
searchData: state.searchReducer.searchData,
totalSearchPage: state.searchReducer.totalSearchPage,
})
export default connect(mapStateToProps,{setSearchData,clearSearchData})(SearchScreen);
</code></pre>
<p>I will really every thankful to someone how can help me in fixing. Appreciation in advance!</p>
<p><em><strong>GOAL :</strong></em>
The goal that i want to achieve is when user stop typing then i call searchAPI with the keyword he/she entered in searchBar that's all.</p>
<p>I have also tried setTimeOut but that made things more worse.</p>
| [
{
"answer_id": 74290946,
"author": "Ahmed Yasin",
"author_id": 20286415,
"author_profile": "https://Stackoverflow.com/users/20286415",
"pm_score": 2,
"selected": true,
"text": " useEffect(()=>{\n setPageNumber(1)\n props.clearSearchData()\n const delayDebounceFn = setTimeout(() ... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20286415/"
] |
74,226,553 | <p>I have multiple function that instead of returning they print a certain string I canβt put the whole function but thatβs what they end up doing I want to take all of these function and make them into a single string.</p>
<pre><code>Hereβs an example of what one function would print and what I tried
def print_names(lst):
print(name)
def print_id(lst):
print(id)
lst = [name, not_name, not_name,id]
print_id(lst) + print_name(lst)
Doing this I get the error unsupported operand types for +: none type
</code></pre>
| [
{
"answer_id": 74290946,
"author": "Ahmed Yasin",
"author_id": 20286415,
"author_profile": "https://Stackoverflow.com/users/20286415",
"pm_score": 2,
"selected": true,
"text": " useEffect(()=>{\n setPageNumber(1)\n props.clearSearchData()\n const delayDebounceFn = setTimeout(() ... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,226,582 | <p>I have a templated class:</p>
<pre><code>template<Vector T>
struct diagonal_matrix;
</code></pre>
<p>Now, I want to create a <code>concept DiagonalMatrix</code> for all of templated class versions. So:</p>
<pre><code> DiagonalMatrix<diagonal_matrix<std::vector<double>>> == true
DiagonalMatrix<diagonal_matrix<std::array<float, 4>>> == true
DiagonalMatrix<diagonal_matrix<std::span<int, 10>>> == true
DiagonalMatrix<diagonal_matrix<my::random_access_container_view<unsigned int>>> == true
DiagonalMatrix<other_matrix> == false
</code></pre>
<p>Keep in mind that <code>diagonal_matrix</code> has a subset of <code>other_matrix</code> functionality.</p>
<p>Is there a way to create a <code>concept DiagonalMatrix</code> which only accepts <code>struct diagonal_matrix<?></code> without tagging the struct with a <code>static constexpr bool I_am_a_diagonal_matrix = true;</code>?. I don't care for implementations other than <code>struct diagonal_matrix<?></code>.</p>
| [
{
"answer_id": 74290946,
"author": "Ahmed Yasin",
"author_id": 20286415,
"author_profile": "https://Stackoverflow.com/users/20286415",
"pm_score": 2,
"selected": true,
"text": " useEffect(()=>{\n setPageNumber(1)\n props.clearSearchData()\n const delayDebounceFn = setTimeout(() ... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438465/"
] |
74,226,625 | <p>If a function <code>f: (X => Y) | undefined</code> is possibly undefined, and <code>x: X</code> is defined, then we can use optional-chaining operator <code>?.</code> to apply <code>f</code> to <code>x</code>:</p>
<pre class="lang-js prettyprint-override"><code>f?.(x) // ok, no problem if `f` is undefined
</code></pre>
<p>But when <code>f: X => Y</code> is defined and <code>x: X | undefined</code> is possibly undefined, there does not seem to be any syntax to "map" the <code>f</code> over the "optional" <code>x</code>:</p>
<pre><code>f(?.x) // not valid syntax; Unclear what to do when `x` is undefined
</code></pre>
<p>I could try to implement <code>pipeTo</code> to swap the order of <code>f</code> and <code>x</code>, and then make it work with <code>?.</code> again, as follows:</p>
<pre class="lang-js prettyprint-override"><code>function opt<X>(x: X | undefined): { pipeTo<Y>(f: (a: X) => Y): Y } | undefined {
return typeof x === 'undefined' ? undefined : {
pipeTo<Y>(f: (a: X) => Y): Y {
return f(x)
}
}
}
</code></pre>
<p>which I could then use as <code>opt(x)?.pipeTo(f)</code>, for example:</p>
<pre><code>function square(n: number): number { return n * n }
for (const x of [42, undefined, 58]) {
console.log(opt(x)?.pipeTo(square))
}
</code></pre>
<p>Is there any less cumbersome standard solution for applying a certainly existing <code>f</code> to a possibly undefined <code>x</code>?</p>
<hr />
<p>Clarification: <em>"cumbersome"</em> := anything that forces me to write down the subexpression <code>x</code> twice, or to clutter the scope with meaningless helper-variables.</p>
| [
{
"answer_id": 74227325,
"author": "Dimava",
"author_id": 5734961,
"author_profile": "https://Stackoverflow.com/users/5734961",
"pm_score": 1,
"selected": false,
"text": "\nfunction nonNullable<T>(v: T | null | undefined): v is T {return v != null}\n\nclass OneOrZeroArray<T> extends Arra... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2707792/"
] |
74,226,635 | <p>I have a drone player set up that has two cameras on it: a first person and a topdown camera, and i want to be able able to "scan" particular zones in the world by using the camera as a scanner. Currently i have a script set up that holds on the game objects to be scanned and handles the ray-casting and gradual color change of the objects. Currently, when i switch to first-person camera, all of my objects start turning red even though they each have different materials assigned to them. My current code is attached below. I only want to be able to turn one zone at a time to red while either the FPS or topdown cameras is looking directly at it.</p>
<p>`</p>
<pre><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZoneController : MonoBehaviour
{
private Camera frontViewCamera;
private Camera topDownCamera;
public Material[] zones;
public float speed = 0.05f;
private Color startColor, endColor = Color.red;
// Start is called before the first frame update
void Start()
{
frontViewCamera = GameObject.FindGameObjectWithTag("FrontFaceCam").GetComponent<Camera>() as Camera;
topDownCamera = GameObject.FindGameObjectWithTag("TopDownCam").GetComponent<Camera>() as Camera;
foreach (var zone in zones)
{
zone.color = Color.white;
}
startColor = Color.white;
}
private IEnumerator ChangeColour()
{
float tick = 0f;
foreach (var zone in zones)
{
while (zone.color != endColor)
{
tick += Time.deltaTime * speed;
zone.color = Color.Lerp(startColor, endColor, tick);
yield return null;
}
}
}
private void StartFadeToRed()
{
Ray frontCameraRayCast;
Ray topDownCameraRayCast;
RaycastHit fHit;
RaycastHit tHit;
frontCameraRayCast = frontViewCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
topDownCameraRayCast = topDownCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
if (frontViewCamera.enabled)
{
if (Physics.Raycast(frontCameraRayCast, out fHit))
{
Debug.DrawRay(frontCameraRayCast.origin, frontCameraRayCast.direction * 10, Color.red);
StartCoroutine("ChangeColour");
}
}
if (topDownCamera.enabled)
{
if (Physics.Raycast(topDownCameraRayCast, out tHit) && tHit.collider.CompareTag("Zone"))
{
Debug.Log("Raycast topdwon");
StartCoroutine("ChangeColour");
}
}
}
// Update is called once per frame
void Update()
{
StartFadeToRed();
}
}
</code></pre>
<p>`</p>
| [
{
"answer_id": 74227325,
"author": "Dimava",
"author_id": 5734961,
"author_profile": "https://Stackoverflow.com/users/5734961",
"pm_score": 1,
"selected": false,
"text": "\nfunction nonNullable<T>(v: T | null | undefined): v is T {return v != null}\n\nclass OneOrZeroArray<T> extends Arra... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351813/"
] |
74,226,640 | <p>I tried adding the styled component to the child component but the values are not changing at all.</p>
<p>Child component returns</p>
<pre><code> <a href='' className="displayCarft">{props.craftcolor}</a>
</code></pre>
<p>I am using the child component in parent component</p>
<pre><code> <div classname = 'container'>
<Child color={props.color}/>
</div>
</code></pre>
<p>i tried adding styled component</p>
<pre><code> const Styledcomp = styled(Child)`
.displayCarft{
color: green !important;
}
`
<div classname = 'container'>
<Styledcomp color={props.color}/>
</div>
</code></pre>
| [
{
"answer_id": 74226861,
"author": "Davit Gelovani",
"author_id": 17701360,
"author_profile": "https://Stackoverflow.com/users/17701360",
"pm_score": 0,
"selected": false,
"text": "Styledcomp"
},
{
"answer_id": 74226907,
"author": "Dulaj Ariyaratne",
"author_id": 13368318... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6146203/"
] |
74,226,650 | <p>I am trying to parse the numeral content embedded in a string. The string has three possible forms:</p>
<ol>
<li>'avenue\d+', where \d+ is a number with one or more digits
or</li>
<li>'road\d+'
or</li>
<li>'lane\d+'
I tried:</li>
</ol>
<pre><code>re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','road12')
</code></pre>
<p>This code works well for the first line below, but incorrectly for the second.</p>
<pre><code>re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','avenue12')
Out[81]: '12'
re.sub(r'(?:avenue(\d+)|road(\d+)|lane(\d*))',r'\1','road12')
Out[82]: ''
</code></pre>
<p>what am I doing incorrectly?
thanks
i</p>
| [
{
"answer_id": 74226710,
"author": "mjsqu",
"author_id": 3388954,
"author_profile": "https://Stackoverflow.com/users/3388954",
"pm_score": 1,
"selected": false,
"text": "re.sub(r'(?:avenue|road|lane)(\\d+)',r'\\1','road12')\n"
},
{
"answer_id": 74226713,
"author": "Wiktor Str... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2669041/"
] |
74,226,657 | <p>When I use the <code><Link></code> tag in NextJs to navigate between pages it doesn't rerun my scripts after changing pages. It only runs the scripts after the first page load or when I press reload. When using plain <code><a></code> tags instead, it works fine because the page reloads after each navigation. As far as I can tell this happens because the <code><Link></code> tag makes it a Single-Page Application and doesn't refresh the page when navigating between pages.</p>
<p>I would greatly appreciate anyway to have it rerun the scripts when navigating between pages or to have it refresh the page without using just plain <code><a></code> tags and losing the Single-Page Application functionality.</p>
<p>This code doesn't refresh the page</p>
<pre><code> <Link href="/page1">
<a>Page 1</a>
</Link>
<Link href="/page2">
<a>Page 2 </a>
</Link>
</code></pre>
<p>This code does refresh the page</p>
<pre><code> <a href="/page1">Page 1</a>
<a href="/page2">Page 2 </a>
</code></pre>
<p>I load in all my scripts using a scripts component</p>
<pre><code>export default const MyScripts = () => {
return (
<Script
strategy="afterInteractive"
type="module"
src="/scripts/myScript.js"
onReady={() => {
console.log("Ready")
}}
/>
)
}
</code></pre>
<p>One thing I've noticed is that the above <code>onReady</code> function fires each time I change pages. Maybe someone knows how to run the <code>myScript.js</code> from the <code>onReady</code>.</p>
| [
{
"answer_id": 74226710,
"author": "mjsqu",
"author_id": 3388954,
"author_profile": "https://Stackoverflow.com/users/3388954",
"pm_score": 1,
"selected": false,
"text": "re.sub(r'(?:avenue|road|lane)(\\d+)',r'\\1','road12')\n"
},
{
"answer_id": 74226713,
"author": "Wiktor Str... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226657",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19677826/"
] |
74,226,662 | <p>I am trying to write a Python script that more or less mimics the New York Times game Spelling Bee (if you've played it). I have a code that prints out all the words from a list of letters, but I want to be able to repeat letters. For example, <code>fsde</code> produces nothing, but I want <code>feed</code> to be part of the results. Another example is the letters <code>etmxr</code> to produce <code>extreme</code> (Basically any letter can be repeated as many times as possible if the language has a word that allows it). Here is the code I have using <code>itertools</code> so far:</p>
<pre><code>import itertools
import enchant
d = enchant.Dict("en_US")
answer = []
user_input = input("Input letters here: ")
center = input("Input center letter here: ")
while len(center)>1 or center not in user_input:
center = input("Either you entered a letter not in the first input, or you entered more than one letter. Try again: ")
letters = [x.lower() for x in user_input]
words = d
for t in range(4, len(user_input)):
for m in itertools.permutations(user_input, t):
a = "".join(m)
if center in a:
if d.check(a):
answer.append(a)
print(answer)
</code></pre>
<p>Right now you just enter letters and get all the words from them, and that's all I want right now. If there's any way to get a double or triple letter I would really appreciate it.</p>
<p>I have scoured google and stackoverflow to no avail, I got the original code from a video but it doesn't have repeated letters and even though I now fully understand <code>permutations</code> I can't get multiple letters haha. I've tried <code>product</code> and <code>combination</code> with no luck, and a lot more but I think it's just a methodology thing I have wrong.</p>
| [
{
"answer_id": 74226763,
"author": "gog",
"author_id": 3494774,
"author_profile": "https://Stackoverflow.com/users/3494774",
"pm_score": 3,
"selected": true,
"text": "letters = 'etmxr'\n\nwith open('/usr/share/dict/words') as fp:\n for word in fp:\n if set(word.strip()).issubse... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17163781/"
] |
74,226,669 | <p>I try to understand why my mongoDB client disconnect despite the global scope variable. There is something that i dont understand. I think, somehow, this is related the <code>ConnectToDatabase()</code> function.</p>
<p>If i try to do some operation on the DB in the <code>ConnectToDatabase()</code> function, it goes well but with another package, it keep return <code>Client disconnected</code> error.</p>
<p>Here the structure of the project:</p>
<pre><code>βββ database
β βββ connect.go
β βββ models
βββ go.mod
βββ go.sum
βββ handlers
β βββ user.go
βββ main.go
βββ README.md
βββ services
βββ create-user.go
βββ get-users.go
</code></pre>
<p>Here the code:</p>
<pre class="lang-golang prettyprint-override"><code>func main() {
fmt.Println("Users Data service started")
err := DB.ConnectToDatabase()
if err != nil {
log.Fatal(err)
}
l := log.New(os.Stdout, "service-user-data - ", log.LstdFlags)
userH := handlers.User(l)
sMux := http.NewServeMux()
sMux.Handle("/", userH)
s := &http.Server{
Addr: ":9090",
Handler: sMux,
IdleTimeout: 120 * time.Second,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
}
go func() {
err := s.ListenAndServe()
if err != nil {
l.Fatal(err)
}
}()
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt)
signal.Notify(sigChan, os.Kill)
// Wait for an available signal
// Then print the message into the channel
sig := <-sigChan
l.Println("Recieved terminated, gracefully shutdown", sig)
ctxTimeOut, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
s.Shutdown(ctxTimeOut)
}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>const (
dbURI = "mongodb://localhost:27017"
)
// CtxDB represent the context fot the database
var CtxDB, cancel = context.WithTimeout(context.Background(), 10*time.Second)
// DBClient spread all over the application the mongoDB client
var DBClient, err = mongo.NewClient(options.Client().ApplyURI(dbURI))
// DB represent the service database
var DB = DBClient.Database("service-users-data")
// UserCollection represent the user collection
var UserCollection = DB.Collection("users")
// ConnectToDatabase function handle the connection to the connection o the database
// It will return either client and err
func ConnectToDatabase() (err error) {
err = DBClient.Connect(CtxDB)
if err != nil {
log.Fatal(err)
} else {
fmt.Println("Database's client connected")
}
err = DBClient.Ping(CtxDB, readpref.Primary())
if err != nil {
log.Fatal(err)
} else {
fmt.Println("Client pinged")
}
defer DBClient.Disconnect(CtxDB)
return err
}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>type users = models.Users
// GetUsers function return a list of user
func GetUsers(resWriter http.ResponseWriter, req *http.Request) (u users) {
ctx := database.CtxDB
cursor, err := database.UserCollection.Find(ctx, bson.M{})
if err != nil {
log.Fatal(err)
}
if err = cursor.All(ctx, &u); err != nil {
log.Fatal(err)
}
return u
}
</code></pre>
<ul>
<li>Is this folder structure actually correct ?</li>
<li>Why this client keep disconnecting ?</li>
</ul>
| [
{
"answer_id": 74227799,
"author": "Corentin TRUFFAUT",
"author_id": 18484709,
"author_profile": "https://Stackoverflow.com/users/18484709",
"pm_score": 0,
"selected": false,
"text": "err"
},
{
"answer_id": 74229318,
"author": "Disturb",
"author_id": 4807950,
"author_... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18484709/"
] |
74,226,677 | <p>I'm unable to optimize the function to convert an array into multiple objects with keys for my desired output.</p>
<pre><code>const students = [
['Name01', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'y', 'OverAll', 'y', 'SecA'],
['Name02', 'Sub01', 'n', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'y', 'OverAll', 'n', 'SecA'],
['Name03', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'n', 'Sub04', 'y', 'OverAll', 'n', 'SecB'],
['Name04', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'y', 'OverAll', 'y', 'SecB'],
['Name05', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'n', 'OverAll', 'n', 'SecB']];
const newArr = students.reduce((a, [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Sec]) => {
a[A1] = { Name: A1, Sub01: A3, Sub02: A5, Sub03: A3, Sub04: A7, Sub05: A9, OverAll: A11, Sec }
return a;
}, {});
console.log(newArr)
</code></pre>
<p>And following is the output result for above code:</p>
<pre><code>{
Name01: {
Name: 'Name01', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'y', OverAll: 'y', Sec: 'SecA'
},
Name02: {
Name: 'Name02', Sub01: 'n', Sub02: 'y', Sub03: 'n', Sub04: 'y', Sub05: 'y', OverAll: 'n', Sec: 'SecA'
},
Name03: {
Name: 'Name03', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'n', Sub05: 'y', OverAll: 'n', Sec: 'SecB'
},
Name04: {
Name: 'Name04', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'y', OverAll: 'y', Sec: 'SecB'
},
Name05: {
Name: 'Name05', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'n', OverAll: 'n', Sec: 'SecB'
}
}
</code></pre>
<p>I'm trying to optimize the code for desired output result as follows:</p>
<pre><code>{
Pass: {
SecA: {
Name01: { Name: 'Name01', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'y' }
},
SecB: {
Name04: { Name: 'Name04', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'y' }
}
},
Fail: {
SecA: {
Name02: { Name: 'Name02', Sub01: 'n', Sub02: 'y', Sub03: 'n', Sub04: 'y', Sub05: 'y' }
},
SecB: {
Name03: { Name: 'Name03', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'n', Sub05: 'y' },
Name05: { Name: 'Name05', Sub01: 'y', Sub02: 'y', Sub03: 'y', Sub04: 'y', Sub05: 'n' }
}
}
}
</code></pre>
| [
{
"answer_id": 74227441,
"author": "MahendraKumar sahu",
"author_id": 9169183,
"author_profile": "https://Stackoverflow.com/users/9169183",
"pm_score": -1,
"selected": false,
"text": " const students = [\n ['Name01', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'y', 'OverAl... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10672840/"
] |
74,226,681 | <p>I have a class that wraps an array. It inherits from an abstract base class defining one <code>virtual constexpr</code> method for the function-call operator. In the child class, I override said method and access the internal array:</p>
<pre class="lang-cpp prettyprint-override"><code>#include <cstddef>
#include <array>
#include <initializer_list>
template <typename T, std::size_t N>
class ContainerBase {
public:
virtual constexpr const T& operator()(std::size_t i) const = 0;
};
template <typename T, std::size_t N>
class Container : public ContainerBase<T, N> {
public:
constexpr Container(std::initializer_list<T> data) {
std::copy(data.begin(), data.end(), _items.begin());
}
constexpr const T& operator()(std::size_t i) const override {
return _items[i];
}
private:
std::array<T, N> _items;
};
int main () {
constexpr Container<int, 3> C = {2, -91, 7};
constexpr int F = C(1);
static_assert(F == -91);
}
</code></pre>
<p>Here is the <a href="https://godbolt.org/z/roe36E7P4" rel="nofollow noreferrer">godbolt link</a>.</p>
<p>To the best of my understanding, this is all legal code in C++20, which allows <code>virtual constexpr</code>. G++ 10.3 and Clang 12 both accept this as valid code, however MSVC 19.33 does not accept it, claiming that variable <code>F</code> is not a constant expression:</p>
<pre><code>msvc_buggy_constexpr.cpp(29,21): error C2131: expression did not evaluate to a constant
msvc_buggy_constexpr.cpp(21,16): message : a non-constant (sub-)expression was encountered
msvc_buggy_constexpr.cpp(31,5): error C2131: expression did not evaluate to a constant
msvc_buggy_constexpr.cpp(21,16): message : a non-constant (sub-)expression was encountered
</code></pre>
<p>What gives? This looks like a compiler bug in MSVC to me. I would investigate further but MSVC on godbolt.org seems to be down right now.</p>
<p>I should add, the issue only presents itself when the function call operator method is <code>virtual</code> βwhen it is not, the issue does not occur.</p>
<p>Can anyone advise?</p>
| [
{
"answer_id": 74227441,
"author": "MahendraKumar sahu",
"author_id": 9169183,
"author_profile": "https://Stackoverflow.com/users/9169183",
"pm_score": -1,
"selected": false,
"text": " const students = [\n ['Name01', 'Sub01', 'y', 'Sub02', 'y', 'Sub03', 'y', 'Sub04', 'y', 'OverAl... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6177253/"
] |
74,226,682 | <p>I have a bunch of files names as such:</p>
<pre><code>Belinda Carlisle - Mad About You-Xmdtjwmr9zq.mp4
Air Supply - All Out of Love-Jwdzeumnrmi.mp4
Blue Savannah Song - Erasure-Wxoutwk8jv8.mp4
Breathe - How Can I Fall (1988)-Pwz4erdjzra.mp4
</code></pre>
<p>I would like to be able to trim out the suffix of random characters. I got some help with formulating a regex, and I slapped together a two-liner in PowerShell, and it works. The only caveat is that I have to first filter by the regex before piping it to 'rename-item', otherwise, it adds two extensions to the filename like
Belinda Carlisle -Mad About You.mp4.mp4 for the filenames that are 'clean' - aka without the extraneous suffix.</p>
<p>Can this be done another way so that I don't have to filter by matching regex and achieve the same thing? Not being nitpicky, just curious.</p>
<p>Here's the expression I cobbled together.</p>
<pre><code>Get-ChildItem $targetpath -file |
where-object {$_.name -match "-[a-z\d]+(?=\.[^.]+$)"} |
ForEach-Object {
Rename-Item -Path $_.FullName -NewName ('{0}{1}' -f ($_.Name -replace "-[a-z\d]+(?=\.[^.]+$).*","$1"), $_.Extension )
}
</code></pre>
| [
{
"answer_id": 74227072,
"author": "postanote",
"author_id": 9132707,
"author_profile": "https://Stackoverflow.com/users/9132707",
"pm_score": 1,
"selected": false,
"text": "Clear-Host\n(@'\nBelinda Carlisle - Mad About You-Xmdtjwmr9zq.mp4\nAir Supply - All Out of Love-Jwdzeumnrmi.mp4\nB... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20350806/"
] |
74,226,686 | <p>In <strong>Seize</strong> "resource choice condition" I add 3 technician but only one of them work and remaining 2 do nothing.</p>
<p><a href="https://i.stack.imgur.com/V72yy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V72yy.png" alt="enter image description here" /></a></p>
<p>Now according to the above image only technician with value "batter" which is first one will only work remaining two will remains ideal/will not work.</p>
<p><strong>Note</strong>: if I put technician with value "battery" on the top then it will only work remaining 2 will not work.</p>
<p>My <strong>ultimate goal</strong> is make all the technicians work so I can put condition on them.</p>
<p><em>For example</em> if My agent <strong>customer</strong> have parameter called "battery" is true then technician with value "battery" will work on it and on remaining customers remaining 2 technicians work.</p>
<p>Something like that:</p>
<pre><code>if (agent.batteryProb == true){
((technician)unit).problemsSolved.equals("battery");}
else{
((technician)unit).problemsSolved.equals("batter");
((technician)unit).problemsSolved.equals("batte");}
</code></pre>
<p>I am also adding the screenshot of my running model below. In which you can also see the ResourcePool details.</p>
<p><a href="https://i.stack.imgur.com/dAqgE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dAqgE.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74228022,
"author": "Emile Zankoul",
"author_id": 13755144,
"author_profile": "https://Stackoverflow.com/users/13755144",
"pm_score": 1,
"selected": true,
"text": "agent.batteryProb == true ? \n\n((technician)unit).problemsSolved.equals(\"battery\") :\n\nagent.batterProb =... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16779211/"
] |
74,226,691 | <p>I want to use different IWebDrivers For My Method. For that I use different public IWebDrivers. So far no problem. However I would like to use a variable whenever I for example want to search for a specific element.</p>
<p>For Illustration: <code>driver.Navigate.GoToUrl("https://www.google.com"); </code> So, how would I know use a not yet defined variable? In my method I will use an if statement in connection with an else if statement, so depending on which if statement is used, a specific driver should be used.</p>
<p>For Illustration: <code>if (...) a = driver1 else if (...) a = driver2</code>. Since the driver would only defined whenever one of the if-statements or if-else statements has been initialized, it tells me that I can't use .Navigate with a. Is there a way to solve this? Otherwise I would have a lot of duplicate code</p>
| [
{
"answer_id": 74228022,
"author": "Emile Zankoul",
"author_id": 13755144,
"author_profile": "https://Stackoverflow.com/users/13755144",
"pm_score": 1,
"selected": true,
"text": "agent.batteryProb == true ? \n\n((technician)unit).problemsSolved.equals(\"battery\") :\n\nagent.batterProb =... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,226,704 | <p>Good afternoon,
Here is my problem: I have a Pandas dataframe that looks like it:</p>
<pre><code>Birth_Year Name
1964 [X, Y]
1965 [A, B]
1964 [F, G, H]
</code></pre>
<p>I need to transform it to the following:</p>
<pre><code>Birth_Year Name_1 Name_2 Name_3
1964 X Y
1965 A B
1964 F G H
</code></pre>
<p>So I need to get the max length of lists in column 'Name', create the datafame with column for each item in the list, and populate it with the values from the list.</p>
<p>Would really appreciate an advice on how to handle this problem.</p>
<p>I have no good solution for it.</p>
| [
{
"answer_id": 74226774,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": false,
"text": "df = df.join(pd.DataFrame(df.pop('Name').tolist(), index=df.index)\n .fillna('')\n .ren... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16343012/"
] |
74,226,724 | <p>I am currently utilizing a hold block to restrict agent of type <code>Patient</code> passing to a seize block. Upstream in the model, <code>Patient</code> are assigned only 1 unit of <code>Doctor</code> that it will interact with downstream in the model every time is seizes <code>Doctor</code> (This is shown in photo one, in the <code>Doctor</code> resource pool).</p>
<p>The problem is that I would like to access this particular unit of <code>Doctors</code> in a function that I have, in order to check if that specific unit of <code>Doctor</code> is idle. Photo 2 is the function im using at the moment, and I would like to add this solution as the third condition in the if statements. It already checks if an Surgeon is available, but I need to add a check to see if their specific <code>Doctor</code> is available.</p>
<p>Photo 1
<a href="https://i.stack.imgur.com/1fTIy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fTIy.png" alt="enter image description here" /></a></p>
<p>Photo 2
<a href="https://i.stack.imgur.com/M7WHY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M7WHY.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74227711,
"author": "Emile Zankoul",
"author_id": 13755144,
"author_profile": "https://Stackoverflow.com/users/13755144",
"pm_score": 1,
"selected": false,
"text": "agent.doctor"
},
{
"answer_id": 74227901,
"author": "Yossi Benagou",
"author_id": 18366972,
... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13143177/"
] |
74,226,758 | <div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>PayID</th>
<th>userclass</th>
<th>category</th>
<th>paydate</th>
</tr>
</thead>
<tbody>
<tr>
<td>90</td>
<td>111</td>
<td>7</td>
<td>1/1/2022</td>
</tr>
<tr>
<td>91</td>
<td>111</td>
<td>7</td>
<td>3/1/2022</td>
</tr>
<tr>
<td>92</td>
<td>222</td>
<td>8</td>
<td>2/1/2022</td>
</tr>
<tr>
<td>93</td>
<td>333</td>
<td>8</td>
<td>2/1/2022</td>
</tr>
<tr>
<td>94</td>
<td>444</td>
<td>9</td>
<td>3/15/2022</td>
</tr>
<tr>
<td>95</td>
<td>444</td>
<td>9</td>
<td>4/1/2022</td>
</tr>
</tbody>
</table>
</div>
<p>So I want to write a SQL query that allows me to result with the records associated with payIDs 90,91,94 and 95 because I want records associated with multiple paydates of the same category within the same userclass.</p>
<p>--
So far I can get the entirety of the queried results as show in the example above</p>
<p>With my structure being something like:</p>
<pre><code>
SELECT
p.payID,
p.userclass,
pc.category,
p.paydate
FROM
pay p
INNER JOIN paycategory pc
ON p.categoryID = pc.categoryID
</code></pre>
<p>Which shows everything but not filtered down to the 4 records I want to be output.<br />
i.e</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>PayID</th>
<th>userclass</th>
<th>category</th>
<th>paydate</th>
</tr>
</thead>
<tbody>
<tr>
<td>90</td>
<td>111</td>
<td>7</td>
<td>1/1/2022</td>
</tr>
<tr>
<td>91</td>
<td>111</td>
<td>7</td>
<td>3/1/2022</td>
</tr>
<tr>
<td>94</td>
<td>444</td>
<td>9</td>
<td>3/15/2022</td>
</tr>
<tr>
<td>95</td>
<td>444</td>
<td>9</td>
<td>4/1/2022</td>
</tr>
</tbody>
</table>
</div>
<p>I think I need to use the count function or something along that line but I'm having trouble understanding it.</p>
| [
{
"answer_id": 74227711,
"author": "Emile Zankoul",
"author_id": 13755144,
"author_profile": "https://Stackoverflow.com/users/13755144",
"pm_score": 1,
"selected": false,
"text": "agent.doctor"
},
{
"answer_id": 74227901,
"author": "Yossi Benagou",
"author_id": 18366972,
... | 2022/10/27 | [
"https://Stackoverflow.com/questions/74226758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20351857/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.