qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,189,977 | <p>How can I compress images of different sizes (2-5-10-20 MB) of type .jpg to almost 1-1.5 MB in C#? I have been trying to compress using the 'quality' factor in the MagickImage library, but the quality factor is not proportional to the percentage. I have searched and tried different libraries but I couldn't find the solution I'm looking for.</p>
<p>There is an iterative way - compress the image, check its size and if its greater than the desired size, keep compressing it until the size is desired. Is this a good way?</p>
| [
{
"answer_id": 74190421,
"author": "hossein sabziani",
"author_id": 4301195,
"author_profile": "https://Stackoverflow.com/users/4301195",
"pm_score": 0,
"selected": false,
"text": "system.Drawing.Imaging"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74189977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15918459/"
] |
74,189,986 | <p>I have an array of arrays that look something like this:</p>
<pre><code>let arr = [
["Rhonda", "Great Britain", 1, "Coffee", "Roasted"],
["Greg", "United States", 2, "Sugar", "Brown"],
["Bob", "Australia", 1, "Bread", "White"],
];
</code></pre>
<p>I would like to duplicate the individual arrays, with the number of duplicates based on the element in the 2nd position. Also would like to choose what elements in the first 3 positions. This is the desired result:</p>
<pre><code>let result = [
["Rhonda", "Great Britain", 1, "Coffee", "Roasted"],
[" ", " ", " ", "Coffee", "Roasted"],
["Greg", "United States", 2, "Sugar", "Brown"],
[" ", " ", " ", "Sugar", "Brown"],
[" ", " ", " ", "Sugar", "Brown"],
["Bob", "Australia", 1, "Bread", "White"],
[" ", " ", 1, "Bread", "White"],
];
</code></pre>
<p>I don't believe Splice is the correct method in this instance, as this is the result I'm currently getting:</p>
<pre><code>[[Bob, Australia], [Bob, Australia],
[Rhonda, Great Britain, 1.0, Coffee, Roasted],
[Bob, Australia], [Greg, United States, 2.0, Sugar, Brown],
[Bob, Australia, 1.0, Bread, White]]
</code></pre>
<pre><code>for (var i = arr.length - 1; i >= 0; i--) {
let multiplier = arr[i][2];
arr.splice(multiplier, 0, [arr[i][0], arr[i][1]]);
}
</code></pre>
| [
{
"answer_id": 74190117,
"author": "Ricardo Sanchez",
"author_id": 659149,
"author_profile": "https://Stackoverflow.com/users/659149",
"pm_score": 1,
"selected": false,
"text": "const temp = []; // create an empty array to store the results\n\n// loop the original array\narr.forEach(item... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74189986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18936063/"
] |
74,190,028 | <p>I am facing this error since I restarted the system. I am not sure what went wrong.
I have restarted my system many times. Please help.</p>
<p><a href="https://i.stack.imgur.com/LtUpr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LtUpr.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74190321,
"author": "NiSø",
"author_id": 2485344,
"author_profile": "https://Stackoverflow.com/users/2485344",
"pm_score": 1,
"selected": false,
"text": "dotnet --list-sdks \n"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4968132/"
] |
74,190,077 | <p>I'm new to vue and I'm trying to make this work. I get some data from a XML, everything works, but I want to change which value I get from XML using a computed which gets a value from Store.</p>
<p>My computed is:</p>
<pre><code>currentStep: {
set (val) {
this.$store.commit('setCurrentStep', val)
},
get () {
return this.$store.state.currentStep
}
}
</code></pre>
<p>With axios and xml2js I get all data with this Method:</p>
<pre><code>getData() {
axios.get("https://something.xml").then((response) => {
this.parseXML(response.data).then((data) => {
this.flightInformations = data
})
})
},
parseXML(data) {
return new Promise((resolve) => {
let parser = new xml2js.Parser({
trim: true,
explicitArray: true,
});
parser.parseString(data, function (err, result) {
let obj = null
obj = result.flugplan.abflug[0].flug;
let flight_dates = {};
for (let item of obj) {
let flight_date = item.datum.join().toString();
if (!flight_dates[flight_date]) {
flight_dates[flight_date] = [];
}
flight_dates[flight_date].push({
flightNr: item.flugnr.join().toString(),
flightPlace: item.ort.join().toString(),
flightPlan: item.plan.join().toString(),
flightExpected: item.erwartet.join().toString(),
flightDate: item.datum.join().toString(),
})
}
resolve(flight_dates);
})
})
}
</code></pre>
<p>I need to change my OBJ using my computed like:</p>
<pre><code>let obj = null
if (this.currentStep === 'departures') {
obj = result.flugplan.abflug[0].flug;
} else {
obj = result.flugplan.ankunft[0].flug;
}
</code></pre>
<p>But it does not work. Can you guys please help ?</p>
<p>Thank you very much.</p>
| [
{
"answer_id": 74190321,
"author": "NiSø",
"author_id": 2485344,
"author_profile": "https://Stackoverflow.com/users/2485344",
"pm_score": 1,
"selected": false,
"text": "dotnet --list-sdks \n"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190077",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19433886/"
] |
74,190,081 | <p>I have a df that I intend to visualise as a stacked percentage bar plot, with the stacks ordered in descending order. The df contains values in proportion and has been transformed into long format. Below is a reprex with some dummy data that is based on the real data I'm using.</p>
<pre><code>df<- data.frame(ID=c("A","B","C","D","E"),
a1=c((0.452),(0.558),(0.554),(0.484),(0.661)),
a2=c((0.326),(0.373),(0.465),(0.434),(0.499)),
a3=c((0.450),(0.481),(0.613),(0.473),(0.504)),
a4=c((0.561),(0.681),(0.633),(0.504),(0.723)))
dflong<-df%>%
pivot_longer(!ID, names_to="aa", values_to="prop")
dflong$ID<-as.factor(dflong$ID)
</code></pre>
<pre><code># A tibble: 15 × 3
ID aa prop
<fct> <chr> <dbl>
1 A a1 0.452
2 A a2 0.326
3 A a3 0.45
4 A a4 0.561
5 B a1 0.558
6 B a2 0.373
7 B a3 0.481
8 B a4 0.681
9 C a1 0.554
10 C a2 0.465
11 C a3 0.613
12 C a4 0.633
13 D a1 0.484
14 D a2 0.434
15 D a3 0.473
</code></pre>
<pre><code>dflong %>%
ggplot(aes(x=ID,y=prop, fill=reorder(aa,-prop))) +
geom_col(position ="fill", data=dflong%>%filter(ID=="A")) +
geom_col(position ="fill", data=dflong%>%filter(ID=="B")) +
geom_col(position ="fill", data=dflong%>%filter(ID=="C")) +
geom_col(position ="fill", data=dflong%>%filter(ID=="D")) +
geom_col(position ="fill", data=dflong%>%filter(ID=="E")) +
geom_text(aes(label=scales::percent(prop)),
position=position_fill(vjust=.5), size=3, colour="black") +
scale_y_continuous(labels = NULL, breaks = NULL)+
scale_fill_brewer(palette="GnBu",
name="")+
coord_flip()+
theme_minimal()+
theme(legend.position = "bottom",
legend.direction = "horizontal") +
labs(caption="",
x="",
y="")
</code></pre>
<p>My problem is that the resulting plot will always switch between the 2 values within the variable "C", that is the stacked bar chart will exchange the values of C-a1 and C-a3. The image of the plot will demonstrate the issue clearly.</p>
<p><a href="https://i.stack.imgur.com/PEyX6.png" rel="nofollow noreferrer">For variable C, a1 should be 55.4% and a3 should be 61.3%</a></p>
<p>I have tried changing ID into factor, changing aa into factor, reordering the values in the original df, restarting a new session, updating RStudio, and running the code on the R GNU (in case it was an RStudio issue), but nothing I have done so far has fixed this problem. It seems to only affect 1 'variable' which is the C variable, and only for values of a1 and a3. I'm at my wits ends and will appreciate any kind of help, as the console isn't specifying an exact error that's causing this.</p>
<p><strong>EDIT:</strong> The reason I have used five separate <code>geom_col</code> functions is to ensure that each columns are stacked horizontally. This was largely influenced by the <a href="https://stackoverflow.com/questions/53596262/stacked-barchart-independent-fill-order-for-each-stack/53597254#53597254">answer to this question</a>.</p>
| [
{
"answer_id": 74190534,
"author": "Kim Ferrari",
"author_id": 2733169,
"author_profile": "https://Stackoverflow.com/users/2733169",
"pm_score": 1,
"selected": false,
"text": "dflong %>%\n group_by(ID) %>% \n ggplot(aes(x=ID,y=prop, fill=reorder(aa,-prop))) +\n geom_col(position =\"fi... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20327368/"
] |
74,190,088 | <p>TLDR:</p>
<p>I have option to add only one regex.</p>
<p>How to make those 2 expressions:</p>
<ul>
<li>\s</li>
<li>(\d{10})(19|20)(\d{2})$:$1$3</li>
</ul>
<p>work at the same time (one after another) and not separately?</p>
<p>This is not enough: \s|(\d{10})(19|20)(\d{2})$:$1$3</p>
<p>Long description:</p>
<p>I have an expression: '(\d{10})(19|20)(\d{2})$:$1$3'</p>
<p>What it does:</p>
<ul>
<li>user password should have 12 digits - ending with last 2 digits of the year</li>
<li>in case phrase has 14 digits (someone added full year) - ignore digits 11th and 12th</li>
</ul>
<p>Thanks to that we can accept both codes: 308814310175 and 30881431011975.</p>
<p>Now I'm looking for a way to ignore spaces in case user adds them anywhere by mistake (not my requirement).</p>
<p>Theoretically I can just add '|\s', to get '\s|(\d{10})(19|20)(\d{2})$:$1$3'.</p>
<p>Both regex works separately:</p>
<ul>
<li>when someone adds full year - it removes 11th and 12th digits</li>
<li>when someone adds space - it removes it
but if someone adds space AND adds full year then only removing of spaces works (because phrase is longer than 14 digits).</li>
</ul>
<p>So this works:</p>
<ul>
<li>308814310175</li>
<li>30881431011975</li>
<li>3088143 10119</li>
</ul>
<p>But this is not working:</p>
<ul>
<li>3088143101 1975</li>
</ul>
<p>because it removes space OR 11th/12th digits - not making both things work one after another.</p>
<p>How to make both expressions work at the same time?</p>
<p>Thank you in advance for your help.</p>
| [
{
"answer_id": 74192771,
"author": "JvdV",
"author_id": 9758194,
"author_profile": "https://Stackoverflow.com/users/9758194",
"pm_score": 2,
"selected": true,
"text": "^\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(\\d)\\s*(?:1\\s*9|2\\s*0)?\\s*(\\... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6725877/"
] |
74,190,108 | <p>Having following example:</p>
<pre class="lang-cs prettyprint-override"><code>public class Test{
public Animal DoSomething(AnimalCreateDto animal){
Animal created;
if(animal is DogCreateDto dogCreateDto){
Dog dog = new(dogCreateDto);
created = Create(dog);
}else if(animal is CateCreateDto catCreateDto){
Cat cat = new(catCreateDto);
created = Create(cat);
}
return created;
}
private Dog Create(Dog dog){ ... }
private Cat Create(Cat cat){ ... }
}
</code></pre>
<p>Is there any way to use e.g. the switch-case?</p>
| [
{
"answer_id": 74190187,
"author": "LLL",
"author_id": 3608449,
"author_profile": "https://Stackoverflow.com/users/3608449",
"pm_score": 3,
"selected": true,
"text": "object obj = new Developer { FirstName = \"Thomas\", YearOfBirth = 1980 };\n\nstring favoriteTask;\n\nswitch (obj)\n{\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8771409/"
] |
74,190,126 | <p><a href="https://stackoverflow.com/questions/14469689/how-to-use-css-counters-in-lists-without-resetting-the-counters">Previous stackoverflow question</a></p>
<p><a href="https://stackoverflow.com/users/196379/paul-hoffman">Paul Hoffman</a> asked this question some years ago.</p>
<blockquote>
<p>I want to have multiple "ol" lists where the counter value does not
reset between lists. Another way to say this is that I want the
counter for the first "li" in the second list to be one higher than
the counter value from the last element of the previous list. Is there
some CSS magic that will do this?</p>
</blockquote>
<p>I understand the suggested solution. However, if I now want to add a third list of which the counter has to start with the value one again. How can I accomplish this?</p>
| [
{
"answer_id": 74190209,
"author": "kmoser",
"author_id": 378779,
"author_profile": "https://Stackoverflow.com/users/378779",
"pm_score": 0,
"selected": false,
"text": "<html>\n<head>\n<style>\n #list-one { \n counter-reset : item;\n }\n #list-three { \n counter-re... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19299088/"
] |
74,190,138 | <p>Faced with such a problem that the application compiles for a very long time. I tried to clean the cache - with no result
Changed the settings in <code>build.gradle</code> - no result
Moreover, I have a similar project in terms of code volume and it compiles on the same configuration files for no more than a couple of minutes.</p>
<p><a href="https://i.stack.imgur.com/pSbSV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pSbSV.jpg" alt="Profiling" /></a></p>
<p><code>Android Studio Fox 2020.3.1 Patch 3</code> -
<code>AGP 7.0.4</code> -
<code>Gradle 7.0.2</code> -
<code>Kotlin 1.6.21</code></p>
| [
{
"answer_id": 74194241,
"author": "N Droidev",
"author_id": 8672015,
"author_profile": "https://Stackoverflow.com/users/8672015",
"pm_score": -1,
"selected": false,
"text": "invalidate cache and restart"
},
{
"answer_id": 74272240,
"author": "just_koala",
"author_id": 71... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7137521/"
] |
74,190,165 | <p>I have an S3 bucket in Account A and a lambda function in Account B. I want the lambda to read the contents from the bucket, so have assigned the appropriate permissions to the IAM role and added that IAM role to the bucket's trust policy. The lambda works fine when it is not part of my VPC, but when it is in the VPC of Account B then the lambda times out which makes me think that the timeout is due to a connectivity problem.</p>
<p>I have used a VPC endpoint for a different lambda to access Secrets Manager, but a VPC endpoint to connect to S3 doesn't solve the problem in this case. I have read in some places that the lambda needs a NAT/Internet Gateway in order to connect to a cross account Bucket, but AWS say:</p>
<pre><code>By default, Lambda functions have access to the public internet. This is not the case after they have been configured with access to one of your VPCs. If you continue to need access to resources on the internet, set up a NAT instance or Amazon NAT Gateway. Alternatively, you can also use VPC endpoints to enable private communications between your VPC and supported AWS services.
</code></pre>
<p>So, simple question really: Does the lambda need a NAT/Internet gateway to access the bucket, or should the VPC endpoint be enough?</p>
<p>EDIT:
terraform for the VPC endpoint.</p>
<pre><code>resource "aws_vpc_endpoint" "s3" {
vpc_id = aws_vpc.main.id
service_name = "com.amazonaws.eu-west-1.s3"
vpc_endpoint_type = "Interface"
security_group_ids = [
aws_security_group.lambda.id,
]
subnet_ids = [aws_subnet.subnet_1a.id]
tags = {
Name = "vpc-endpoint-s3"
Environment = var.aws_profile
Terraform = true
}
}
resource "aws_vpc_endpoint_security_group_association" "s3" {
vpc_endpoint_id = aws_vpc_endpoint.s3.id
security_group_id = aws_security_group.lambda.id
}
</code></pre>
| [
{
"answer_id": 74191337,
"author": "sobmortin",
"author_id": 10103114,
"author_profile": "https://Stackoverflow.com/users/10103114",
"pm_score": 0,
"selected": false,
"text": "VPC Endpoint"
},
{
"answer_id": 74192194,
"author": "Paolo",
"author_id": 3390419,
"author_p... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10103114/"
] |
74,190,167 | <p>When I am trying to create Search Service using ARM Template, it showing the below error</p>
<blockquote>
<p>The relative path 'artifacts/linkedTemplate.json' could not be
resolved. Please ensure the parent deployment references either an
external URI or a template spec ID. The relativePath property cannot
be used when creating a template deployment with a local file.</p>
</blockquote>
<pre><code>{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"searchService_name": {
"type": "string"
}
},
"variables": {
"linked-template": "artifacts/azure_deploycopy.json"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "azure-restore",
"properties": {
"mode": "Incremental",
"templateLink": {
"relativePath": "[variables('linked-template')]"
},
"parameters": {
"searchService_name": {
"value": "[parameters('searchService_name')]"
}
}
}
}
],
"outputs": {}
}
</code></pre>
| [
{
"answer_id": 74191337,
"author": "sobmortin",
"author_id": 10103114,
"author_profile": "https://Stackoverflow.com/users/10103114",
"pm_score": 0,
"selected": false,
"text": "VPC Endpoint"
},
{
"answer_id": 74192194,
"author": "Paolo",
"author_id": 3390419,
"author_p... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190167",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1752012/"
] |
74,190,203 | <p>The following code should execute multiple long-running HTTP requests sequentially:</p>
<ol>
<li>First HTTP request is started</li>
<li>First HTTP request is finished</li>
<li>Second HTTP request is started</li>
<li>Second HTTP request is finished</li>
<li>Third HTTP request is started</li>
<li>...</li>
</ol>
<p>Some of the requests can take up to 30 seconds, so the code needs to make sure that second request waits for the first request to finish. In addition, there needs to be one request for every id provided by <code>this.service.getAll()</code>.</p>
<p>However, I was not able to achieve the desired behavior with following code. Instead, after the completion of the first HTTP request (30 seconds) no further requests were sent. My assumption is that <code>concatMap</code> somehow does not buffer the other accounts while waiting for the current request to complete.</p>
<p>Component:</p>
<pre><code>this.service.getAll().pipe(
concatAll(), // flatten the observable
concatMap(acc => this.service.update(acc.id, {synchronize: true}).pipe(delay(1000)))
).subscribe(() => {
this.someFlag = false;
});
</code></pre>
<p>Service:</p>
<pre><code>getAll(): Observable<Account[]> {
return this.http.get<Account[]>('someUrl');
}
// The request can take up to 30 seconds
update(id: number, account: Account): Observable<Account> {
return this.http.put<Account>('someUrl', account);
}
</code></pre>
<p>How can I achieve the desired behavior?</p>
| [
{
"answer_id": 74190408,
"author": "Chuong Tran",
"author_id": 5589964,
"author_profile": "https://Stackoverflow.com/users/5589964",
"pm_score": 1,
"selected": false,
"text": "// example.js\nconst Promise_serial = require('promise-serial');\n \n \nconst promises =\n Array(15).fill()\n... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20327562/"
] |
74,190,233 | <p>I want to make two files with different settings for dev and prod.</p>
<p>I created a python package in the app folder where my settings are, and even if I run the app with old settings, I receive an error:</p>
<pre><code>CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
</code></pre>
<p>Here is my project structure:
<a href="https://i.stack.imgur.com/213hv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/213hv.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74190438,
"author": "Javad",
"author_id": 11833435,
"author_profile": "https://Stackoverflow.com/users/11833435",
"pm_score": 1,
"selected": false,
"text": "settings.py"
},
{
"answer_id": 74203266,
"author": "Rikki Tikki Tavi",
"author_id": 1512250,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512250/"
] |
74,190,267 | <p>so i have this simple object</p>
<pre><code>var dataSource = new kendo.data.DataSource({
data : ["One", "Two"]
});
console.log(dataSource.data[0]);
kendo.bind($("#container3"), {});
</code></pre>
<p>im trying to get the value of "One" or "Two" but i always get undefined.</p>
<pre><code>console.log(dataSource.data[0]);
</code></pre>
| [
{
"answer_id": 74190438,
"author": "Javad",
"author_id": 11833435,
"author_profile": "https://Stackoverflow.com/users/11833435",
"pm_score": 1,
"selected": false,
"text": "settings.py"
},
{
"answer_id": 74203266,
"author": "Rikki Tikki Tavi",
"author_id": 1512250,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18805532/"
] |
74,190,268 | <p>i am trying to find the null space of a matrix using python and sympy and i don't understand why <code>.nullspace()</code> doesn't work? What is my mistake? Is there another better python module for linear algebra?</p>
<p>If i print matrix x it is what i expect so i think the problem lies in the <code>.nullspace()</code> command or something with the data type of the matrix maybe?</p>
<pre><code>import sympy as sp
def ranking(A,m=0.1):
A = sp.Matrix(A)
shape = sp.shape(A)
n = shape[0]
S = []
for i in range(n):
S.append([])
for j in range(n):
S[i].append(1/n)
S = sp.Matrix(S)
google = (1-m)*A + m*S
x = sp.Matrix(google-sp.eye(n))
return x.nullspace()
A = [[0 , 0 , 1/2, 1 ],
[1/3, 0 , 0 , 0 ],
[1/3, 1/2, 0 , 0 ],
[1/3, 1/2, 1/2, 0 ]]
print(ranking(A))
</code></pre>
<p>I expect something like this (not exactly as this is the result of an approximation from a different program):</p>
<pre><code>Matrix([[0.376637031250000], [0.138913750000000],
[0.197734375000000], [0.286714843750000]])
</code></pre>
<p>But the function is returning only this:</p>
<pre><code>[]
</code></pre>
<p><strong>edit:</strong>
I found a solution, if i use</p>
<pre><code>from scipy.linalg import null_space
</code></pre>
<p>and then in the function</p>
<pre><code>return null_space(np.array(x).astype("float64"))
</code></pre>
<p>output now is the following which is what i expected:</p>
<pre><code>[[-0.70502501]
[-0.25856055]
[-0.3749128 ]
[-0.54362356]]
</code></pre>
<p>Why does scipy's <code>null_space()</code> work and not sympy's <code>.nullspace()</code>?</p>
| [
{
"answer_id": 74190438,
"author": "Javad",
"author_id": 11833435,
"author_profile": "https://Stackoverflow.com/users/11833435",
"pm_score": 1,
"selected": false,
"text": "settings.py"
},
{
"answer_id": 74203266,
"author": "Rikki Tikki Tavi",
"author_id": 1512250,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20327677/"
] |
74,190,288 | <p>I have a little problem with a recursion task that I found.</p>
<p>I have three functions that are stored in an array:</p>
<pre><code>const One = () => <div>One</div>
const Two = () => <div>Two</div>
const Three = () => <div>Three</div>
const arr = [One, Two, Three]
</code></pre>
<p>Then I pass this array as a prop to another component in which I must write a recursive function to make <strong>One</strong> a parent of *<em>Two</em>, and <strong>Two</strong> a parent of <strong>Three</strong>.</p>
<p>The HTML shopuld look like that:</p>
<pre><code><div class='App-box'>
One
<div class='App-box'>
Two
<div class='App-box'>
Three
</div>
</div>
</div>
</code></pre>
<p>I am able to write a recursive function for an array for objects or nested arrays but this one I cannot figure out.</p>
| [
{
"answer_id": 74190438,
"author": "Javad",
"author_id": 11833435,
"author_profile": "https://Stackoverflow.com/users/11833435",
"pm_score": 1,
"selected": false,
"text": "settings.py"
},
{
"answer_id": 74203266,
"author": "Rikki Tikki Tavi",
"author_id": 1512250,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13050914/"
] |
74,190,294 | <p>When I run <strong>npm run serve</strong> and make a request I see</p>
<blockquote>
<p>Proxy error: Could not proxy request /api/task from localhost:8080 to http://mevn-api:3080.
See <a href="https://nodejs.org/api/errors.html#errors_common_system_errors" rel="nofollow noreferrer">https://nodejs.org/api/errors.html#errors_common_system_errors</a> for more information (ENOTFOUND).</p>
</blockquote>
<p><a href="https://i.stack.imgur.com/mGlOO.png" rel="nofollow noreferrer">error</a></p>
| [
{
"answer_id": 74190438,
"author": "Javad",
"author_id": 11833435,
"author_profile": "https://Stackoverflow.com/users/11833435",
"pm_score": 1,
"selected": false,
"text": "settings.py"
},
{
"answer_id": 74203266,
"author": "Rikki Tikki Tavi",
"author_id": 1512250,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15662874/"
] |
74,190,319 | <p>I have implemented the following classes:</p>
<pre><code>public class classA {
String fieldA;
}
public class classB {
String fieldB;
}
</code></pre>
<p>Then i am using a rest controller having objects of these classes as input:</p>
<pre><code>@RestController
public class MyController {
@PostMapping(value="/resource")
public void foo(@RequestBody objA, @RequestBody objB){
//do stuff
}
}
</code></pre>
<p>When i invoke the API using the following input:</p>
<pre><code>{
"objA" : {
"fieldA" : "valueA"
},
"objB" : {
"fieldB" : "valueB"
}
}
</code></pre>
<p>I get the following error:</p>
<pre><code>org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void com.classA
</code></pre>
<p>Am i missing something on the JSON input?</p>
| [
{
"answer_id": 74190448,
"author": "berse2212",
"author_id": 20184128,
"author_profile": "https://Stackoverflow.com/users/20184128",
"pm_score": 3,
"selected": true,
"text": "public class ClassAB {\n ClassB classB;\n ClassA classA;\n}\n"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6523875/"
] |
74,190,346 | <p>So i'am new into classes in python, and i was struggling a little bit here :(. So I wanted to make a class point which contained coordinates (x, y). First I made a function which set the values and afterwards a function to print the values in a tuple. But then i wanted to manipulate the y coordinate to reflect along the x-axis. But suddenly it started to give me an AttributeError</p>
<p>Input:</p>
<pre><code>class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def print(self):
i = (self.x, self.y)
print(tuple(i))
def reflect_x(self):
self.y*=-1
p1 = Point(1,4)
p1.print()
p2 = Point(-3,5)
p2.print()
p3 = Point(-3,-5)
p3.reflect_x().print()
</code></pre>
<p>Output:</p>
<pre><code>(1, 4)
(-3, 5)
Traceback (most recent call last):
File "/I'd/love/to/keep/this/private/Oef.py", line 22, in <module>
p3.reflect_x().print()
AttributeError: 'NoneType' object has no attribute 'print'
</code></pre>
<p>As you can se as long as i don't implement my reflect_x function I don't get an error.</p>
<p>My wish-to output:</p>
<pre><code>(1, -4)
(-3, -5)
(-3, 5)
</code></pre>
<p>Thank you in advance <3</p>
| [
{
"answer_id": 74190386,
"author": "Tanner",
"author_id": 20178809,
"author_profile": "https://Stackoverflow.com/users/20178809",
"pm_score": 1,
"selected": false,
"text": "p3 = Point(-3,-5)\np3.reflect_x()\np3.print()\n"
},
{
"answer_id": 74190416,
"author": "Marc Leibold",
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16464059/"
] |
74,190,354 | <p><strong>System Information</strong>: <br />
<strong>OS</strong>: Ubuntu 20.04 LTS<br />
<strong>System</strong>: 80 GB RAM, 1 TB SSD, i7-12700k</p>
<p>The documents in this collection are on average 16KB, and there are 500K documents in this collection. I noticed that as the collection grows larger, the time taken to insert documents also grows larger.</p>
<p><a href="https://i.stack.imgur.com/8lD2e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8lD2e.png" alt="Linear relationship? " /></a></p>
<p><strong>In what ways could I improve the speed of writes?</strong></p>
<p>It is taking 10 Hours to insert 150k documents. Which is around what the graph predicted when we integrate the line:</p>
<pre><code>def f(num):
return 0.0004*num+0.9594
sum=0
for i in range(500,650):
sum+=f(i*1000)
>> sum/3600
>> 9.61497
</code></pre>
<p><strong>Potential upgrades in my mind:</strong></p>
<ul>
<li>Use the C++ mongo engine for writes</li>
<li>Allocate more RAM to Mongod</li>
</ul>
<p><strong>Logs</strong></p>
<p><code>iotop</code> showing mongod using < 1% of the IO capacity with write speeds around 10-20 KB/s</p>
<p><code>htop</code> showing the mongod is only using ~ 16GB of RAM \</p>
<p>Disks showing that some 300GB of SSD is free</p>
<p><strong>EDIT</strong>:</p>
<p>Psudo code:</p>
<pre class="lang-py prettyprint-override"><code>docs=[...]
for doc in docs:
doc["last_updated"]=str(datetime.now())
doc_from_db = collection.find_one({"key":doc["key"]})
new_dict = minify(doc)
if doc_from_db is None:
collection.insert_one(new_dict)
else:
collection.replace_one({"key":doc["key"]},new_dict,upsert=true)
</code></pre>
| [
{
"answer_id": 74190612,
"author": "Tom Slabbaert",
"author_id": 10770370,
"author_profile": "https://Stackoverflow.com/users/10770370",
"pm_score": 3,
"selected": true,
"text": "for"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20289089/"
] |
74,190,356 | <p>When writing the code, the following code will be activated on time, saying it is stopped until the hour.
However, to operate the code on time, it takes more than 59 minutes to run the code must run the code.
Is there a way to make it work at 12pm by adjusting the minutes and hours instead of seconds in that code?</p>
<hr />
<pre><code>enter code here`current_time = time.time()
time_to_sleep = (60 - (current_time % 60))
time.sleep(time_to_sleep)
</code></pre>
<hr />
| [
{
"answer_id": 74190612,
"author": "Tom Slabbaert",
"author_id": 10770370,
"author_profile": "https://Stackoverflow.com/users/10770370",
"pm_score": 3,
"selected": true,
"text": "for"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20279625/"
] |
74,190,371 | <p>I am creating a simple app which renders a list of courses and some details about the courses.</p>
<p>The course details are split into the Header, Content and Total.</p>
<p>In the Content section, is a child component: Part, however the component is not rendering with no error messages in the console or errors thrown by Typescript
Does anyone know why this is happening?</p>
<pre><code>App.js
import Header from './components/Header'
import Content from './components/Content'
import Total from './components/Total'
import { CoursePart } from './types'
const App = () => {
const courseName = "Half Stack application development";
const courseParts: CoursePart[] = [
{
name: "Fundamentals",
exerciseCount: 10,
description: "This is the easy course part",
type: "normal"
},
{
name: "Advanced",
exerciseCount: 7,
description: "This is the hard course part",
type: "normal"
},
{
name: "Using props to pass data",
exerciseCount: 7,
groupProjectCount: 3,
type: "groupProject"
},
{
name: "Deeper type usage",
exerciseCount: 14,
exerciseSubmissionLink: "https://fake-exercise-submit.made-up-url.dev",
type: "submission"
}
]
return (
<div>
<Header courseName={courseName} />
<Content courseParts={courseParts} />
<Total courseParts={courseParts} />
</div>
);
};
export default App;
</code></pre>
<p>Content.tsx</p>
<pre><code>import { interfacePart } from '../types'
import Part from './Part'
const Content = ({ courseParts }: {courseParts: interfacePart }) => {
return (
<div>
<Part courseParts={courseParts} />
</div>
)
}
export default Content
</code></pre>
<p>Part.tsx</p>
<pre><code>import { interfacePart } from '../types'
// eslint-disable-next-line react/prop-types
const Part = ({ courseParts }: {courseParts: interfacePart }) => {
console.log(courseParts)
return (
<>
{courseParts.forEach((part) => {
switch (part.name) {
case 'Fundamentals':
return <div><p>{part.name} {part.exerciseCount}</p> </div>;
case 'Advanced':
return <div>{part.name}</div>;
case 'Using props to pass data':
return <div>{part.name}</div>;
case 'Deeper type usage':
return <div>{part.name}</div>;
default:
break;
}
})}
</>
);
}
export default Part
</code></pre>
| [
{
"answer_id": 74190612,
"author": "Tom Slabbaert",
"author_id": 10770370,
"author_profile": "https://Stackoverflow.com/users/10770370",
"pm_score": 3,
"selected": true,
"text": "for"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12894011/"
] |
74,190,396 | <p>is there a difference in these 3 codes:</p>
<p>First: when i call my function inside onInit().</p>
<pre><code>@override
void onInit() {
super.onInit();
fetchProductsFromAPI();
}
</code></pre>
<p>Second: when i call my function inside of build method, in stateless widget.</p>
<pre><code>class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
fetchProductsFromAPI();
return GetMaterialApp(
home: ShoppingPage(),
);
}
}
</code></pre>
<p>Third: when i call my function outside of build method, in stateless widget.</p>
<pre><code> class MyApp extends StatelessWidget {
fetchProductsFromAPI();
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home: ShoppingPage(),
);
}
}
</code></pre>
| [
{
"answer_id": 74190511,
"author": "Valentin Vignal",
"author_id": 12066144,
"author_profile": "https://Stackoverflow.com/users/12066144",
"pm_score": 3,
"selected": true,
"text": "initState"
},
{
"answer_id": 74190586,
"author": "manhtuan21",
"author_id": 8921450,
"a... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11565523/"
] |
74,190,397 | <p>I try to do a simple thing: At route change, refetch data.</p>
<p>Here is my link:</p>
<pre class="lang-html prettyprint-override"><code><li v-for="category in categories" :key="category.id" class="mb-1">
<NuxtLink :to="{ query: { cat: category.slug } }">
{{category.title}}
</NuxtLink>
</li>
</code></pre>
<p>And my request:</p>
<pre class="lang-html prettyprint-override"><code><script setup>
const route = useRoute()
const { data:categories } = await useFetch('http://127.0.0.1:8000/api/tasks/category/', {
key: route.fullPath,
initialCache: false
})
const { data:tasks, refresh } = await useFetch(`http://127.0.0.1:8000/api/tasks/?cat=${route.query.cat}`, {
key: `tasks:${route.query.cat}`,
initialCache: false
})
watch(() => route.query.cat, () => refresh())
</script>
</code></pre>
<p>So, at click, url is well changed:</p>
<pre><code>http://localhost:3000/tasks?cat=category1
http://localhost:3000/tasks?cat=category3
http://localhost:3000/tasks?cat=category2
</code></pre>
<p>But requests are the same (from Django DRF backend):</p>
<pre><code>GET http://127.0.0.1:8000/api/tasks/?cat=category1
GET http://127.0.0.1:8000/api/tasks/?cat=category1
GET http://127.0.0.1:8000/api/tasks/?cat=category1
</code></pre>
<p>It seems that it keeps the first category, even with <code>initialCache: false</code></p>
| [
{
"answer_id": 74190511,
"author": "Valentin Vignal",
"author_id": 12066144,
"author_profile": "https://Stackoverflow.com/users/12066144",
"pm_score": 3,
"selected": true,
"text": "initState"
},
{
"answer_id": 74190586,
"author": "manhtuan21",
"author_id": 8921450,
"a... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9717891/"
] |
74,190,407 | <p>I have a dataframe <code>df</code> like below:</p>
<pre><code>import pandas as pd
data = {'A': ['XYZ', 'XYZ', 'XYZ', 'XYZ', 'PQR', 'XYZ', 'XYZ', 'ABC', 'XYZ', 'ABC'], 'B': ['2022-02-16 14:00:31', '2022-02-16 16:11:26', '2022-02-16 17:31:26',
'2022-02-16 22:47:46', '2022-02-17 07:11:11', '2022-02-17 10:43:36',
'2022-02-17 15:05:11', '2022-02-17 15:07:25', '2022-02-17 15:08:35',
'2022-02-17 15:09:46'], 'C': [1,0,0,0,1,0,0,1,0,0]}
df = pd.DataFrame(data)
df['B'] = pd.to_datetime(df['B'])
df
| A | B | C |
+-------+----------------------+------------+
| XYZ | 2022-02-16 14:00:31 | 1 |
| XYZ | 2022-02-16 16:11:26 | 0 |
| XYZ | 2022-02-16 17:31:26 | 0 |
| XYZ | 2022-02-16 22:47:46 | 0 |
| PQR | 2022-02-17 07:11:11 | 1 |
| XYZ | 2022-02-17 10:43:36 | 0 |
| XYZ | 2022-02-17 15:05:11 | 0 |
| ABC | 2022-02-17 15:07:25 | 1 |
| XYZ | 2022-02-17 15:08:35 | 0 |
| ABC | 2022-02-17 15:09:46 | 0 |
+-------+----------------------+------------+
</code></pre>
<p>What I want to achieve is that I want to count the number of duplicates for each of the occurences of <code>XYZ</code>, <code>PQR</code>, <code>ABC</code> such that I get an output like below.</p>
<pre><code>
Expected Output :
| A | B | C | Count |
+-------+----------------------+------------+----------+
| XYZ | 2022-02-16 14:00:31 | 1 | 7 |
| XYZ | 2022-02-16 16:11:26 | 0 | |
| XYZ | 2022-02-16 17:31:26 | 0 | |
| XYZ | 2022-02-16 22:47:46 | 0 | |
| PQR | 2022-02-17 07:11:11 | 1 | 1 |
| XYZ | 2022-02-17 10:43:36 | 0 | |
| XYZ | 2022-02-17 15:05:11 | 0 | |
| ABC | 2022-02-17 15:07:25 | 1 | 2 |
| XYZ | 2022-02-17 15:08:35 | 0 | |
| ABC | 2022-02-17 15:09:45 | 0 | |
+-------+----------------------+------------+----------+
</code></pre>
<p>Currently, I'm trying to achieve the same by using the code below but I'm unable to get expected/desired results.</p>
<pre><code>
one_index = df[df['C'] == 1].index
zero_index = df[df['C'] == 0].index
df.loc[0, 'Count'] = len(df)
| A | B | C | Count |
+-------+----------------------+------------+----------+
| XYZ | 2022-02-16 14:00:31 | 1 | 10 |
| XYZ | 2022-02-16 16:11:26 | 0 | |
| XYZ | 2022-02-16 17:31:26 | 0 | |
| XYZ | 2022-02-16 22:47:46 | 0 | |
| PQR | 2022-02-17 07:11:11 | 1 | |
| XYZ | 2022-02-17 10:43:36 | 0 | |
| XYZ | 2022-02-17 15:05:11 | 0 | |
| ABC | 2022-02-17 15:07:25 | 1 | |
| XYZ | 2022-02-17 15:08:35 | 0 | |
| ABC | 2022-02-17 15:09:45 | 0 | |
+-------+----------------------+------------+----------+
</code></pre>
<p>So, how can I get count of duplicates for each of the values of column <code>A</code> as mentioned ?</p>
<p>EDIT (OPTIONAL):</p>
<p>I would also like to have ID assigned to the groups for the <code>df</code> after the count values has been assigned. So, my final dataframe should look like below after ID has been assigned:</p>
<pre><code> | A | B | C | Count | ID |
+-------+----------------------+------------+----------+-------+
| XYZ | 2022-02-16 14:00:31 | 1 | 7 | ABC_1 |
| XYZ | 2022-02-16 16:11:26 | 0 | | |
| XYZ | 2022-02-16 17:31:26 | 0 | | |
| XYZ | 2022-02-16 22:47:46 | 0 | | |
| PQR | 2022-02-17 07:11:11 | 1 | 1 | ABC_2 |
| XYZ | 2022-02-17 10:43:36 | 0 | | |
| XYZ | 2022-02-17 15:05:11 | 0 | | |
| ABC | 2022-02-17 15:07:25 | 1 | 2 | ABC_3 |
| XYZ | 2022-02-17 15:08:35 | 0 | | |
| ABC | 2022-02-17 15:09:45 | 0 | | |
+-------+----------------------+------------+----------+-------+
</code></pre>
| [
{
"answer_id": 74190511,
"author": "Valentin Vignal",
"author_id": 12066144,
"author_profile": "https://Stackoverflow.com/users/12066144",
"pm_score": 3,
"selected": true,
"text": "initState"
},
{
"answer_id": 74190586,
"author": "manhtuan21",
"author_id": 8921450,
"a... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3046211/"
] |
74,190,415 | <p>I want a derived class to be able to copy from another class if it has the same type, if not just do nothing.</p>
<p>Example in semi-pseudocode:</p>
<pre><code>class Animal
{
public:
virtual void CopyFrom(Animal* animal) = 0;
// TODO: virtual destructor
};
class Dog : Animal
{
public:
Dog() {}
void CopyFrom(Animal* animal) override {
if (animal is Dog) {
likes_to_bark = ((Dog)animal).likes_to_bark;
}
}
private:
bool likes_to_bark;
}
</code></pre>
<p>I know this can be achieved a dynamic cast, but that is considered code smell.
I was looking into the visitor pattern and double dispatch, but I could not find a way to do this. Any ideas?</p>
| [
{
"answer_id": 74190595,
"author": "YSC",
"author_id": 5470596,
"author_profile": "https://Stackoverflow.com/users/5470596",
"pm_score": 1,
"selected": false,
"text": " if (animal is Dog)\n"
},
{
"answer_id": 74190771,
"author": "Captain Giraffe",
"author_id": 451600,
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2567078/"
] |
74,190,429 | <p>Is there a way where I can limit a website generaot output and make the output more randomize since it outputs the name alphabetically. I tried to use limit and randomize i, but it doesn't seem to work</p>
<pre><code>import re
from selenium import webdriver
import os
import json
import requests
import validators
from urllib.request import Request, urlopen
import numpy as np
import random
import whois
import pandas as pd
import itertools
Combined = open("dictionaries/Combined.txt", 'r', encoding="utf-8")
Example = open("dictionaries/examples.txt", 'w', encoding="utf-8")
with open("dictionaries/Combined.txt") as i:
Test = [line.rstrip() for line in i]
</code></pre>
<p>This is what's inside the <code>Combined.txt</code></p>
<p><a href="https://i.stack.imgur.com/ZtldI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZtldI.png" alt="Combined text file" /></a></p>
<pre><code>delimeters = ['','-', '.']
output_count = 100
web = 'web'
suffix = 'co.id'
for x in range(output_count):
output = []
for combo in itertools.combinations(Test, 2):
out = ''
for i, d in enumerate(delimeters):
out = d.join(combo)
out = delimeters[i-1].join([out, web])
addr = '.'.join([out, suffix])
output.append(random.choice(out))
Example.write(addr+'\n')
with open("dictionaries/examples.txt") as f:
websamples = [line.rstrip() for line in f]
</code></pre>
<p>This is the output that i get.</p>
<pre><code>websamples
</code></pre>
<p><a href="https://i.stack.imgur.com/0RyXG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0RyXG.png" alt="websamples" /></a></p>
<p><a href="https://i.stack.imgur.com/FqITM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FqITM.png" alt="Websamples 2" /></a></p>
<p>As you see at the image, the web generator outputs too many web domain generator it doesn't even show the rest of the output in Jupyter Notebook. Is there a way where the web domain generator doesn't output the web alphabetically and mix it up and limits the number of outputs that I want? for example i want to limit it to just a 100 with randomize outputs instead of outputting possible combination domain name and outputs it alphabetically</p>
<p>Thanks</p>
| [
{
"answer_id": 74190719,
"author": "Zach Bellay",
"author_id": 3788994,
"author_profile": "https://Stackoverflow.com/users/3788994",
"pm_score": 0,
"selected": false,
"text": "random"
},
{
"answer_id": 74190724,
"author": "Alexander",
"author_id": 17829451,
"author_pr... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20183167/"
] |
74,190,504 | <p>I am getting null response in laravel after dd(); ,however in Postman i am getting a response, maybe I am passing the wrong body to the API, kindly guide me on how to pass the following body to this API.</p>
<p>Thanks for your help.</p>
<p>This is my controller</p>
<pre><code>public function callpdf(Request $req)
{
// code...
$host = new HostClass();
$obj = new SessionClass();
$response8 = Http::POST($host->getserverIp() . '/PDFReport',[
// "patientId"=> $obj->getpatientId(),
"patientId"=>"001000010818",
"reportId"=> "618",
"con"=>"003001200326197",
"departmentId"=> "128",
"orderStatusId" => "12",
"organizationId"=>"332",
"sessionId"=> "3",
]);
dd($response8);
return $response8;
}
</code></pre>
<p>This is Postman request and response</p>
<pre><code>{
"patientId": "001000010818",
"departmentId": "128",
"con": "003001200326197",
"odi": "2",
"orderStatusId" : "12",
"reportId": "618",
"organizationId":"332",
"sessionId": "3"
}
</code></pre>
| [
{
"answer_id": 74191461,
"author": "Peppermintology",
"author_id": 281278,
"author_profile": "https://Stackoverflow.com/users/281278",
"pm_score": 2,
"selected": true,
"text": "dd();"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19704437/"
] |
74,190,506 | <p>I try to use a separate thread modifing visual control. I know how to use delegate to avoid a cross thread exception like this.</p>
<pre><code>delegate void LabelTextDelegate(string _String);
LabelTextDelegate LabelTextDelegate1;
private void Form1_Click(object sender, EventArgs e)
{
LabelTextDelegate1 = new(LabelText);
new Thread(Method1).Start();
}
void Method1()
{
label1.Invoke(LabelTextDelegate1, "a"); // delegate
}
void LabelText(string _String)
{
label1.Text = _String;
}
</code></pre>
<p>But the following code simpler works well too.</p>
<pre><code>private void Form1_Click(object sender, EventArgs e)
{
new Thread(Method1).Start();
}
void Method1()
{
label1.Invoke(LabelText, "a"); // non-delegate method
}
void LabelText(string _String)
{
label1.Text = _String;
}
</code></pre>
<p>What is the difference? Is the latter correct? If so, I know Control.Invoke needs a delegate as an argument and does it change non-delegate method to delegate internally?</p>
| [
{
"answer_id": 74190623,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "Action<string>"
},
{
"answer_id": 74190758,
"author": "vernou",
"author_id": 2703673,
"author_profi... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8189627/"
] |
74,190,544 | <p>I have a field in service (loginService) isLogged, it is a behavoiorSubject</p>
<pre><code>public isLogged = new BehaviorSubject<boolean>(!!localStorage.getItem('authToken'));
</code></pre>
<p>When I submit the form on login.component, onSubmit() method works and it change the value of isLogged to true.</p>
<pre><code>public onSubmit() {
if (this.user.valid) {
this.loginService.isLogged.next(true);
}
}
</code></pre>
<p>I want to show the isLogged value in header.component.html so I use async pipe in view but its value doesn't change in header.component.html when I submit the form.</p>
<pre><code><div (click)="loginBtnClick()" routerLink="login"> <span>{{loginService.isLogged | async}}</span></div>
</code></pre>
<p><a href="https://i.stack.imgur.com/0Cvzo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Cvzo.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/WhmoF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WhmoF.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/xaagV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xaagV.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/DzXsP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DzXsP.jpg" alt="enter image description here" /></a></p>
<p>What am I doing wrong here?</p>
| [
{
"answer_id": 74190623,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "Action<string>"
},
{
"answer_id": 74190758,
"author": "vernou",
"author_id": 2703673,
"author_profi... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20327888/"
] |
74,190,603 | <p>my code is :</p>
<pre class="lang-js prettyprint-override"><code>result = await mongoDBO.collection(collectionName).find({id: data.id},{projection : {'_id' : 0}}).toArray();
</code></pre>
<p>But I get the following error</p>
<pre><code>Unsupported projection option: projection: { _id: 0 }
</code></pre>
| [
{
"answer_id": 74190628,
"author": "NeNaD",
"author_id": 14389830,
"author_profile": "https://Stackoverflow.com/users/14389830",
"pm_score": 2,
"selected": true,
"text": "projection"
},
{
"answer_id": 74190874,
"author": "zahra aghli",
"author_id": 14477255,
"author_p... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14477255/"
] |
74,190,604 | <p>I am trying to <strong>multiply</strong> the <strong>number of owned shares by the current price</strong>, however, I am getting the following error:</p>
<pre><code>Function MULTIPLY parameter 2 expects number values. But 'OWNED SHARES' is a text and cannot be coerced to a number.
</code></pre>
<p><a href="https://i.stack.imgur.com/f1fGO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f1fGO.png" alt="enter image description here" /></a></p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>SYMBOL</th>
<th>OWNED SHARES</th>
<th>SHARES PRICE</th>
</tr>
</thead>
<tbody>
<tr>
<td>ABML</td>
<td>100</td>
<td>0,5</td>
</tr>
<tr>
<td>BABA</td>
<td>100</td>
<td>100</td>
</tr>
</tbody>
</table>
</div>
<p>Function is</p>
<pre><code>={"SHARES PRICE";BYROW(A2:A, LAMBDA(r, IF(r="",,GOOGLEFINANCE(r, "price")*B:B)))}
</code></pre>
<p>I tried *<strong>B2:B</strong> but it does not work.</p>
<p><strong>Excel demo:</strong>
<a href="https://docs.google.com/spreadsheets/d/1e9khzIuRrx9kJHyp8CqS22qX98aLg-50cfd9FCks7fc/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1e9khzIuRrx9kJHyp8CqS22qX98aLg-50cfd9FCks7fc/edit?usp=sharing</a></p>
<p><strong>Note:</strong>
I added <strong>+100 into the Owned Shares Function</strong> just for the demo it loads the data from another sheet in reality.</p>
| [
{
"answer_id": 74190824,
"author": "Neo",
"author_id": 19075135,
"author_profile": "https://Stackoverflow.com/users/19075135",
"pm_score": 2,
"selected": false,
"text": "B:B"
},
{
"answer_id": 74195053,
"author": "player0",
"author_id": 5632629,
"author_profile": "htt... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190604",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6416833/"
] |
74,190,639 | <p>I've got the following lines of code and I'd love to turn them into a Pandas data frame, not as a print output.</p>
<pre><code>embedder = SentenceTransformer('all-MiniLM-L6-v2')
corpus = ['About us. About Us · Our Coffees · Starbucks Stories & News · Starbucks® Ready to Drink · Foodservice Coffee · Customer Service · Tax Strategy 2022 · Careers.',
'Costa is the Nation Favourite coffee shop and the largest and fastest growing coffee shop chain in the UK.',
'Leading UK speciality coffee roaster with a focus on sustainability. B Corp certified. Become a wholesale partner or buy coffee beans online today.',
'Kick-start your morning with our amazing range of speciality coffee and equipment. World-class coffee, direct from the farmer, delivered free every time.',
'Coffee Direct - Freshly roasted coffee beans delivered to your door. Origin coffee, coffee blends and flavoured coffee for bean-to-cup',
'Whether you prefer whole coffee beans or freshly ground coffee, Whittard of Chelsea selection of light, medium and dark roast luxury coffees has something',
'Coffee beans are the seeds of a fruit called a coffee cherry. Coffee cherries grow on coffee trees from a genus of plants called Coffea.',
'On these coffee plants, bunches of cherries grow and inside these you will find two coffee beans, Arabica and Robusta coffee.',
]
corpus_embeddings = embedder.encode(corpus, convert_to_tensor=True)
# Query sentences:
queries = ['coffee', 'coffee near me', 'coffee bean', 'coffee house', 'coffee jelly','coffee order nyt crossword clue','coffee quotes', 'coffee shops near me']
# Find the closest 5 sentences of the corpus for each query sentence based on cosine similarity
top_k = min(5, len(corpus))
for query in queries:
query_embedding = embedder.encode(query, convert_to_tensor=True)
cos_scores = util.cos_sim(query_embedding, corpus_embeddings)[0]
top_results = torch.topk(cos_scores, k=top_k)
print("\n\n======================\n\n")
print("Query:", query)
print("\nTop 5 most similar sentences in snippet:")
for score, idx in zip(top_results[0], top_results[1]):
print(corpus[idx], "(Score: {:.4f})".format(score))
</code></pre>
<p>Here is an excerpt from the current output:</p>
<p>======================</p>
<p>Query: coffee</p>
<p>Top 5 most similar sentences in snippet:
Coffee Direct - Freshly roasted coffee beans delivered to your door. Origin coffee, coffee blends and flavoured coffee for bean-to-cup (Score: 0.6477)
Whether you prefer whole coffee beans or freshly ground coffee, Whittard of Chelsea selection of light, medium and dark roast luxury coffees has something (Score: 0.5873)
Kick-start your morning with our amazing range of speciality coffee and equipment. World-class coffee, direct from the farmer, delivered free every time. (Score: 0.5739)
Coffee beans are the seeds of a fruit called a coffee cherry. Coffee cherries grow on coffee trees from a genus of plants called Coffea. (Score: 0.4985)
Costa is the Nation Favourite coffee shop and the largest and fastest growing coffee shop chain in the UK. (Score: 0.4374)</p>
<p>======================</p>
<p>Instead, I'm looking at converting the output into something like</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>query</th>
<th>corpus</th>
<th>score</th>
</tr>
</thead>
<tbody>
<tr>
<td>---</td>
<td>---</td>
<td>---</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74190824,
"author": "Neo",
"author_id": 19075135,
"author_profile": "https://Stackoverflow.com/users/19075135",
"pm_score": 2,
"selected": false,
"text": "B:B"
},
{
"answer_id": 74195053,
"author": "player0",
"author_id": 5632629,
"author_profile": "htt... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328029/"
] |
74,190,664 | <p>I have identity set up on my Razor pages ASP.NET Core web application, and I've set the user name to V003950. A bit of backstory on my web app is that you can upload/download files, an admin can upload and assign a user, then the user logs on and can only see their files.</p>
<p>The id I am trying to compare it to is an integer, and the Id is 3950, so I'm trying to do an if statement like this:</p>
<pre><code>@foreach (var item in Model.Files)
{
if(User.Identity?.Name! == item.VendorId){
if (item.FileType == "Purchase Order")
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Number)
</td>
@*<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value)
</td>*@
@*<td>
@Html.DisplayFor(modelItem => item.FileType)
</td>
<td>
<a asp-page="Upload" asp-route-id="@item.Id">Upload File</a>
</td>*@
<td>
@if (item.Attachment != null)
{
<form asp-page-handler="Download" method="post" asp-route-id="@item.Id">
<input type="submit" class="btn btn-dark" value="Download">
</form>
}
</td>
</tr>
}
}
}
</code></pre>
<p>but because one is a string and one is an int it doesnt work. I've also tried converting the name to int, but the V at the start is becoming a problem.</p>
<p>Is there a way for me to remove the leading V from the if or maybe add in a .contains instead?</p>
| [
{
"answer_id": 74191013,
"author": "Dimitris Maragkos",
"author_id": 10839134,
"author_profile": "https://Stackoverflow.com/users/10839134",
"pm_score": 2,
"selected": false,
"text": "Name"
},
{
"answer_id": 74191090,
"author": "N0m4n904",
"author_id": 10611894,
"auth... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19923949/"
] |
74,190,732 | <p>Suppose I have the following table</p>
<pre><code>id | items | price |
1| item_1 | 15.0 |
2| item_2 | 10.0 |
3| item_1 | 15.0 |
4| item_1 | 15.0 |
5| item_2 | 10.0 |
6| item_2 | 10.0 |
7| item_3 | 25.0 |
</code></pre>
<p>and I want the following output</p>
<pre><code> items | price | count | sum |
item_1 | 15.0 | 3 | 45.0 |
item_2 | 10.0 | 3 | 30.9 |
item_3 | 25.0 | 1 | 25.0 |
</code></pre>
| [
{
"answer_id": 74190797,
"author": "MMAARR",
"author_id": 3218453,
"author_profile": "https://Stackoverflow.com/users/3218453",
"pm_score": 1,
"selected": false,
"text": "select items, price, count(items) as count, sum (price) as sum from table1 group by items, price\n"
},
{
"ans... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10753219/"
] |
74,190,755 | <p>So basically I installed 3.11(which is the latest release). But when I executed the exe file it said "install now" instead of "update now"(which I saw while updating from 3.10.5 to 3.10.8. Now installing would create a whole new directory and all of my important modules are in the dir "python3.10" and I'm too lazy to "pip install" every module to the new directory. So is there any way I could possibly update to 3.11 without creating a whole new directory and without separately installing all of my modules?</p>
| [
{
"answer_id": 74190898,
"author": "DeepSpace",
"author_id": 1453822,
"author_profile": "https://Stackoverflow.com/users/1453822",
"pm_score": 2,
"selected": false,
"text": "python3.10"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20327890/"
] |
74,190,757 | <p>I have the below csv data (sample), as you can see the date is in US format (MM/dd/yyyy) and sometimes the seconds (:ss) is missing. I would like to fix it so the date is in UK format (dd/MM/yyyy) and if the seconds is missing in the time, then add :00</p>
<pre><code>Time,Incident
03/25/2021 12:59:49,INC18072411
04/03/2021 13:00,INC17989469
05/14/2021 13:01:57,INC17987450
05/28/2021 13:02:56,INC18000995
06/01/2021 13:06,INC17990104
06/06/2021 13:06:23,INC17983804
07/19/2021 13:07,INC17973858
08/08/2021 13:08:04,INC17987287
09/20/2021 13:08:19,INC17986031
10/10/2021 13:13,INC17926602
</code></pre>
<p>I have tried the below</p>
<pre><code>Import-Csv $CsvPath | ForEach-Object { ([datetime]::ParseExact($_.Time,"MM/dd/yyyy HH:mm:ss",$null)).ToString('dd/MM/yyyy H:mm:ss') } | Export-Csv $CsvUpdatedPath -NoTypeInformation
</code></pre>
<p>but get error on records where the seconds is missing:</p>
<blockquote>
<p>Exception calling "ParseExact" with "3" argument(s): "String was not
recognized as a valid DateTime."</p>
</blockquote>
| [
{
"answer_id": 74191308,
"author": "Olaf",
"author_id": 9196560,
"author_profile": "https://Stackoverflow.com/users/9196560",
"pm_score": 1,
"selected": false,
"text": "[DateTime]"
},
{
"answer_id": 74192156,
"author": "Theo",
"author_id": 9898643,
"author_profile": "... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5852023/"
] |
74,190,789 | <p>I want to ship a SQLite database packed with my app, within Android App Bundle because my app needs it to function. I'm not sure if this is possible at all or app needs to download the data via internet after being installed on Android?</p>
<p>However, if it can be done, I need to know is there a proper path to copy database file, maybe something like 'MyApp\app\src\main\java\com\example\MyApp\databases', I dunno?</p>
<p>Thanx in advance!</p>
| [
{
"answer_id": 74191308,
"author": "Olaf",
"author_id": 9196560,
"author_profile": "https://Stackoverflow.com/users/9196560",
"pm_score": 1,
"selected": false,
"text": "[DateTime]"
},
{
"answer_id": 74192156,
"author": "Theo",
"author_id": 9898643,
"author_profile": "... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12025575/"
] |
74,190,823 | <p>I have a list of button like this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>button {
background-color: rgb(0, 174, 255);
color: rgb(227, 72, 20);
height: 30px;
width: 30px;
border-radius: 15px;
font-size: 10px;
margin-top: 85px;
margin-left: auto;
margin-right: auto;
border-color: rgb(189, 227, 20);
z-index: 20;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><button class = "btn" id = "tp1" onclick="testpoint1()">TP1</button>
<button class = "btn" id = "tp2" onclick="testpoint2()">TP2</button>
<button class = "btn" id = "tp3" onclick="testpoint3()">TP3</button>
<button class = "btn" id = "tp3" onclick="testpoint4()">TP4</button></code></pre>
</div>
</div>
</p>
<p>At first, all buttons have the same color (color A). Then, when I click a button (e.g. TP1, its background color change to another color (color B). And when I click on another button (TP2), its color will change to B and the color of TP1 will change to its original color (color A)
How can I do that with Javascripts.</p>
| [
{
"answer_id": 74190920,
"author": "Maharkus",
"author_id": 3956676,
"author_profile": "https://Stackoverflow.com/users/3956676",
"pm_score": -1,
"selected": false,
"text": "btn"
},
{
"answer_id": 74190990,
"author": "Amaarockz",
"author_id": 11281152,
"author_profile... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15322909/"
] |
74,190,832 | <p>In the following code:</p>
<pre><code>interface Obj {
requiredKey: string;
optionalKey?: string;
}
type Arr = Array<Obj>;
const arr: Arr = [
{
requiredKey: "a",
optionalKey: "b",
},
{
requiredKey: "c",
},
];
const filtered = arr.filter((obj) => obj.optionalKey);
</code></pre>
<p>How do I tell TS that <code>filtered</code> contains objects where <code>optionalKey</code> exists? Meaning that the type is now:</p>
<pre><code>{
requiredKey: string;
optionalKey: string;
}[]
</code></pre>
| [
{
"answer_id": 74190951,
"author": "Robby Cornelissen",
"author_id": 3558960,
"author_profile": "https://Stackoverflow.com/users/3558960",
"pm_score": 1,
"selected": false,
"text": "Required"
},
{
"answer_id": 74191202,
"author": "Tobias S.",
"author_id": 8613630,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12786831/"
] |
74,190,835 | <p>I have a dataset from the German Weather Service, consisting of daily temperature measurements, which can be downloaded using the <code>rdwd</code>-package.
I want to decompose this time series using the STL method.
I have previously converted the weather dataset into a <code>tsibble</code> time-series object.</p>
<pre><code>library(tidyverse)
library(rdwd)
library(seasonal)
library(tsibble)
df <-
readDWD(dataDWD(
selectDWD(
name = "Jena (Sternwarte)",
res = "daily",
var = "kl",
per = "historical"
),
read = FALSE
), varnames = TRUE)
df<-df%>%tibble()%>%
mutate(MESS_DATUM = as.Date(MESS_DATUM))%>%
filter(MESS_DATUM>=as.Date("2005-01-01"))%>%
rename(Temperatur = TMK.Lufttemperatur)
as_tsibble(df, index= MESS_DATUM)%>%
select(MESS_DATUM,Temperatur)%>%
stl(s.window = "periodic", robust = T)%>%
autoplot()
</code></pre>
<p>However, I don't really know if the dataset in its current format is suitable for STL decomposition or what parameters I need to set in the <code>stl</code> function for this daily dataset.
The trend series should be rather a straighter line and seasonal component is totally distorted.<br />
Can anyone help me with the programming?<br />
Many thanks in advance!</p>
<p><a href="https://i.stack.imgur.com/psVmh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/psVmh.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74191405,
"author": "Roland",
"author_id": 1412059,
"author_profile": "https://Stackoverflow.com/users/1412059",
"pm_score": 1,
"selected": false,
"text": "df$MESS_DATUM <- as.Date(df$MESS_DATUM)\ndf <- df[df$MESS_DATUM >= as.Date(\"2005-01-01\"),]\ntemps <- ts(df$TMK.Luft... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10915988/"
] |
74,190,856 | <p>The following is an example dataframe for this issue:</p>
<pre><code>name gender address phone no.
---------------------------------------
1 1 1 1
1 0 0 0
1 1 1 1
1 1 0 1
</code></pre>
<p>The desired output here is <strong>2</strong> because the number of rows containing all <strong>1s</strong> is <strong>2</strong>.</p>
<p>Can anyone please help me with this issue?
Thanks.</p>
| [
{
"answer_id": 74190910,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "eq(1)"
},
{
"answer_id": 74190918,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11756121/"
] |
74,190,881 | <p>my code:</p>
<pre><code>from PIL import Image
img = Image.open('this.jpg') # 2.72mb image
arrayA = np.array(img)
new_img = Image.fromarray(arrayA)
new_img.save("this_changed.jpg") # to 660 kb image size
</code></pre>
| [
{
"answer_id": 74190910,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "eq(1)"
},
{
"answer_id": 74190918,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20145166/"
] |
74,190,959 | <p>I have tried this using regex, loops and simple functions as well but cannot figure out anything. here are the few codes I have tried.</p>
<pre><code>import re
fp = open("apple.txt")
re.findall(r"([^.]*?apple[^.]*\.)",fp)
</code></pre>
| [
{
"answer_id": 74190910,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "eq(1)"
},
{
"answer_id": 74190918,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74190959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8747361/"
] |
74,191,055 | <p>I'm sure I'm missing something very obvious here, but I need to put an if statement in my application code that takes one branch if the current request is from cypress, and the other if not.</p>
<hr />
<p>(off-topic: I know full well that usually this is a Very-Bad-Idea®, because you want to test the app exactly as it is seen by end users. On the other hand, we live in the real world, with limited time, and sometimes a small bad idea is allowed)</p>
<hr />
<p>One way seems to be to manually change the user agent or add headers to the cypress calls, I just want to know if there is a very obvious (and better) way of doing this.</p>
| [
{
"answer_id": 74201649,
"author": "Amit Kahlon",
"author_id": 13508689,
"author_profile": "https://Stackoverflow.com/users/13508689",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('setFlag', (flag: string, value: string | boolean) => {\n cy.window().then((w) => {\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1207489/"
] |
74,191,059 | <p>Suppose that i have an object like:</p>
<pre><code>const obj = [
{ createdAt: "2022-10-25T08:06:29.392Z", updatedAt: "2022-10-25T08:06:29.392Z"},
{ createdAt: "2022-10-25T08:06:29.392Z", animal: "cat"}
]
</code></pre>
<p>I want to create a function to order by createdAt, which is the only field i'm sure it will be in the object.
The function will be something like:</p>
<pre><code>export const sortArrayByCreatedAt = (arr: TypeArr) => {
return arr.sort(function (a, b) {
return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf();
});
};
</code></pre>
<p>How can i define the type of arr?</p>
<pre><code>Type TypeArr {
createdAt: string
}
</code></pre>
<p>Is it good practice to define the type of the only known var?</p>
<p>I think that if someone else will see this function he will think that obj contains only createdAt, but i didn't find a better solution.</p>
| [
{
"answer_id": 74191140,
"author": "jeffreyquan",
"author_id": 13192867,
"author_profile": "https://Stackoverflow.com/users/13192867",
"pm_score": 0,
"selected": false,
"text": "?"
},
{
"answer_id": 74191141,
"author": "Eldar",
"author_id": 12354911,
"author_profile":... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9635453/"
] |
74,191,074 | <p>I am trying to transform a JSON using Jolt transformation looking for some input here.
I am trying to get all the items from all the levels into an array.</p>
<p><strong>My goal is to get an array that contains all the items without knowing how many levels I have in the json.</strong></p>
<p>Here is my input and expected output:</p>
<p>if I've 3 levels:</p>
<p><em>Input</em>:</p>
<pre class="lang-json prettyprint-override"><code>{
"id": 11,
"item": [
{
"id": "11_1",
"item": [
{
"id": "11_1_1",
"item": [
{
"id": "11_1_1_1"
}
]
},
{
"id": "11_1_2",
"item": [
{
"id": "11_1_2_1"
}
]
}
]
}
]
}
</code></pre>
<p><em>Expected output</em>:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"id": "11_1"
},
{
"id": "11_1_1"
},
{
"id": "11_1_1_1"
},
{
"id": "11_1_2"
},
{
"id": "11_1_2_1"
}
]
</code></pre>
<p>if I've 2 levels:</p>
<p><em>Input</em>:</p>
<pre class="lang-json prettyprint-override"><code>{
"id": 11,
"item": [
{
"id": "11_1",
"item": [
{
"id": "11_1_1"
},
{
"id": "11_1_2"
}
]
}
]
}
</code></pre>
<p><em>Expected output</em>:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"id": "11_1"
},
{
"id": "11_1_1"
},
{
"id": "11_1_2"
}
]
</code></pre>
<p>I tried to write something like:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"operation": "shift",
"spec": {
"item": { //to cover the second level
"*": "item"
}
}
},
{
"operation": "shift",
"spec": {
"item": {
"*": { //to cover the 3td level
"item": {
"*": "item"
}
}
}
}
}
]
</code></pre>
<p>The result was null, if I run each transformation separately, I get results when applicable
Can you please help me to write a simple spec that will do this?</p>
| [
{
"answer_id": 74193803,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 3,
"selected": true,
"text": "[\n {\n \"operation\": \"shift\",\n \"spec\": {\n \"item\": {\n \"*\": {\n \"id\":... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12067782/"
] |
74,191,077 | <p>I have two list comprehensions that do exactly same thing but differ in one dict's element - key of <code>stopped</code> and <code>warning</code>.</p>
<pre><code>logs_warning = [
DDLog(self.HOST, "dms", log["name"], log["StopReason"], f"env:{env}").to_log()
for env in self.envs
for log in tasks[env]["warning"]["tasks"]
]
logs_stopped = [
DDLog(self.HOST, "dms", log["name"], log["StopReason"], f"env:{env}").to_log()
for env in self.envs
for log in tasks[env]["stopped"]["tasks"]
]
</code></pre>
<p>I'm trying to get a <code>or</code> like logic to pick any of above keys. Trick is that <code>key</code> element is in the middle part of my selection so below didn't work:</p>
<pre><code>for log in [tasks.get(env) for key in ['stopped', 'warning']]
</code></pre>
<p>What I'm aiming at is below (pseudo code):</p>
<pre><code>tasks[env]["stopped" OR "warning"]["tasks"]
</code></pre>
| [
{
"answer_id": 74191152,
"author": "Andrew Menshicov",
"author_id": 20156518,
"author_profile": "https://Stackoverflow.com/users/20156518",
"pm_score": 0,
"selected": false,
"text": "(tasks[env].get(\"stopped\") or tasks[env].get(\"warning\"))[\"tasks\"]\n"
},
{
"answer_id": 7419... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191077",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7920004/"
] |
74,191,096 | <p>I want the index of candle that has highest high.
for example I write this code for get highest value:</p>
<pre><code>MyHighest = ta.highest(high,3)
</code></pre>
<p>this code return the high value of that candle but i want the index of that candle has highest value.
how can i do this?</p>
| [
{
"answer_id": 74191152,
"author": "Andrew Menshicov",
"author_id": 20156518,
"author_profile": "https://Stackoverflow.com/users/20156518",
"pm_score": 0,
"selected": false,
"text": "(tasks[env].get(\"stopped\") or tasks[env].get(\"warning\"))[\"tasks\"]\n"
},
{
"answer_id": 7419... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4749236/"
] |
74,191,109 | <p>I'm trying to render an Image as background, but is not working, I don't know why. Here is my code.</p>
<pre><code><ImageBackground
source={require('../assets/images/logos/AFC.svg')}
resizeMode="cover"
style={styles.style}>
</ImageBackground>
</code></pre>
| [
{
"answer_id": 74194903,
"author": "Moustaoui Salaheddine",
"author_id": 14724559,
"author_profile": "https://Stackoverflow.com/users/14724559",
"pm_score": 0,
"selected": false,
"text": "import { View, Text, Dimensions } from 'react-native'\nimport React from 'react'\nimport AFCIcon fro... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7362335/"
] |
74,191,121 | <p>I have the following lines inside a csv file</p>
<pre><code>[0 1 2 3 4 5],2145004.491585603,5.784000000019773e-05
[0 1 2 3 4 5],4986045.063898375,1.771400000016854e-05
[0 1 2 3 4 5],2185254.9265346257,1.468399999993153e-05
</code></pre>
<p>As you can see, the first entry is a list of integers. How can I read in the data, so that I end up with a list (or numpy.array), and 2 floats? I tried to use <code>np.genfromtxt</code> but I didn't know how to process the resulting bytes properly.</p>
<p>If there is no elegant solution, is there a better way to save the array inside one column?</p>
| [
{
"answer_id": 74194903,
"author": "Moustaoui Salaheddine",
"author_id": 14724559,
"author_profile": "https://Stackoverflow.com/users/14724559",
"pm_score": 0,
"selected": false,
"text": "import { View, Text, Dimensions } from 'react-native'\nimport React from 'react'\nimport AFCIcon fro... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7873966/"
] |
74,191,158 | <p>I have 5 functions: func1(), func2(), func3(), func4(), func5(). I need to implement the compositionFunc() function, which can take any number of functions as arguments, and create a composition from them. The compositionFunc() function takes my 5 functions as arguments. The compositionFunc() function returns a function that takes its initial value as an argument. This nested function successively passing through an array of functions with each iteration returns the result of calling the accumulated value of the current function-argument. The result of one function can be passed as an argument to another function. How can i do this?</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 func1 = (arg1) => {
return arg1;
};
const func2 = (arg2) => {
return arg2;
};
const func3 = (arg3) => {
return arg3;
};
const func4 = (arg4) => {
return arg4;
};
const func5 = (arg5) => {
return arg5;
};
const compositionFunc = () => {
...
};</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74191359,
"author": "R4ncid",
"author_id": 14326899,
"author_profile": "https://Stackoverflow.com/users/14326899",
"pm_score": 2,
"selected": true,
"text": "const pipe = (...functions) => args => functions.reduce((res, f) => f(res), args)\n\nconst combine = (...functions) ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20291334/"
] |
74,191,161 | <p>I tried implementing a solution into my sas code but with no luck. I'm trying to add a jaccard distance column. to my dataset.
I keep getting errors :
variable name & is not valid
invalid value for the keep option
The idea is to solve a matching problem between two datasets and to take into consideration the typing errors.</p>
<pre><code>data table_test;
input nom1 $3. nom2 $3.;
cards;
abcade
vdenfr
azfefs
;
run;
%macro kshingling
(string
,k=5
,out=&sysmacroname.
)
;
data &out.;
string = strip(prxchange('s#\s# #',-1,symget('string')));
do _n_ = 1 to lengthn(string)-&k.+1;
ngram = substr(string,_n_,&k.);
output;
end;
run;
%mend;
%macro jaccard
(string1
,string2
)
;
%kshingling(&string1.,k=2,out=s1)
%kshingling(&string2.,k=2,out=s2)
proc append base=s1 data=s2; run;
proc freq data=s1 noprint;
tables string*ngram / out=s2;
run;
proc transpose data=s2 out=s1(drop=_name_ _label_);
by string notsorted;
var count;
id ngram;
run;
proc stdize data=s1 out=s2 missing=0 reponly;
var _numeric_;
run;
proc distance data=s2 method=jaccard absent=0 out=s1;
var anominal(_numeric_);
id string;
run;
data t(keep=&string1.);
set s1(firstobs=2);
run;
data _null_;
set t;
call symput('Jaccard',&string1.);
%put Distance de Jaccard = &Jaccard;
run;
%mend;
data test;
set table_test;
call symput('n1',nom1);
call symput('n2',nom2);
%jaccard(&n1,&n2);
run;
data Jacc;
Dist_Jacc=&Jaccard;
run;
data Final; merge table_test Jacc; run;
</code></pre>
| [
{
"answer_id": 74192734,
"author": "Richard",
"author_id": 1249962,
"author_profile": "https://Stackoverflow.com/users/1249962",
"pm_score": 1,
"selected": false,
"text": "data test;\nset table_test;\ncall symput('n1',nom1);\ncall symput('n2',nom2);\n%jaccard(&n1,&n2);\nrun;\n"
},
{
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328389/"
] |
74,191,168 | <p>I have created a table, where the <code><tr></code> are in display: table-cell, the problem is that I dont know how to make them grow all equaly.</p>
<p>I need to make my table like this, because this table its created through a foreach loop with angular, so each <code><tr></code> tag its a column</p>
<p>And my result its something like this:</p>
<p><a href="https://i.stack.imgur.com/Ssgyt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ssgyt.png" alt="enter image description here" /></a></p>
<p>So, how can I make them all have the same heigth and width?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>table {
border-collapse: collapse;
width: 100%;
margin-bottom: 40px;
}
table .header {
display: table-cell;
}
table .header td {
display: block;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><table>
<tr class="header" *ngFor="let header of superficieColumnHeaders">
<td>Column name</td>
<td id="header-name">Another Value</td>
<td id="body-value">Some specific Value</td>
</tr>
<tr class="header" *ngFor="let header of superficieColumnHeaders">
<td>Column name</td>
<td id="header-name">Another Value</td>
<td id="body-value">Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value Some specific Value </td>
</tr>
</table></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74192734,
"author": "Richard",
"author_id": 1249962,
"author_profile": "https://Stackoverflow.com/users/1249962",
"pm_score": 1,
"selected": false,
"text": "data test;\nset table_test;\ncall symput('n1',nom1);\ncall symput('n2',nom2);\n%jaccard(&n1,&n2);\nrun;\n"
},
{
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13262576/"
] |
74,191,204 | <p>I have a Spark DataFrame that I created by reading an EBCDIC data file. Its schema is as follows</p>
<pre><code>scala> myDF.printSchema
root
|-- DF_RECORD: struct (nullable = true)
| |-- ID: string (nullable = true)
| |-- BALANCE_AMT: decimal(15,4) (nullable = true)
</code></pre>
<p>I can even get it to show its rows. But when I try to write it as CSV, I get the following error</p>
<pre><code>scala> myDF.write.format("csv").mode("overwrite").option("header", "true").save("/path")
org.apache.spark.sql.AnalysisException: CSV data source does not support struct<ID:string,BALANCE_AMT:decimal(15,4)> data type.;
</code></pre>
<p>Is there a column conversion I might have to de before writing?</p>
<p>Spark version 2.4.0-cdh6.2.1</p>
<p>Scala version 2.11.12</p>
| [
{
"answer_id": 74192734,
"author": "Richard",
"author_id": 1249962,
"author_profile": "https://Stackoverflow.com/users/1249962",
"pm_score": 1,
"selected": false,
"text": "data test;\nset table_test;\ncall symput('n1',nom1);\ncall symput('n2',nom2);\n%jaccard(&n1,&n2);\nrun;\n"
},
{
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3725491/"
] |
74,191,230 | <p>I'm new to programming and i'm following CS50, I have run the below code verbatim from the instructor but it does not work and I do not know why.</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>document.addEventListener("DOMContentLoaded", () => {
document.querySelector("select").onchange = function () {
document.querySelector("#hello").getElementsByClassName.color = this.value;
};
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1 id="hello" class="heading">hello</h1>
<select>
<option value="black">Black</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
<br />
<br />
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74191305,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "getElementById"
},
{
"answer_id": 74191356,
"author": "İlker",
"author_id": 14900449,
"au... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11969292/"
] |
74,191,231 | <p>I have a question how to generate dumpdata without this txt on start:</p>
<blockquote>
<p>[1mLoading .env environment variables...[0m</p>
</blockquote>
<p>Here is an example:</p>
<pre><code>[1mLoading .env environment variables...[0m
[
{
"model": "auth.permission",
"pk": 1,
"fields": {
"name": "Can add permission",
"content_type": 1,
"codename": "add_permission"
}
},
....
</code></pre>
<p>I can't find solution, it is annoying, because i want to do a sh script</p>
<blockquote>
<p>docker-compose exec django pipenv run python manage.py dumpdata --indent 2 > fixtures/test_dumpdata.json</p>
</blockquote>
| [
{
"answer_id": 74191354,
"author": "Swift",
"author_id": 8874154,
"author_profile": "https://Stackoverflow.com/users/8874154",
"pm_score": 1,
"selected": false,
"text": "-o"
},
{
"answer_id": 74192111,
"author": "Keso",
"author_id": 17539918,
"author_profile": "https:... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17539918/"
] |
74,191,241 | <p>With Plotly, I'd like to display two <code>imshow</code> on the same page, at the same place, with opacity.</p>
<p>This nearly works:</p>
<pre><code>import plotly.express as px, numpy as np
from skimage import io
img = io.imread('https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Crab_Nebula.jpg/240px-Crab_Nebula.jpg')
fig = px.imshow(img)
x = np.random.random((100, 200))
fig2 = px.imshow(x)
fig.show()
fig2.show()
</code></pre>
<p>but it displays the two <code>imshow</code> images in two different tabs.</p>
<p><strong>How to display the two "imshow" on the same plot, with an opacity slider for both layers?</strong></p>
<p>For reference, here is the <code>matplotlib</code> equivalent:</p>
<pre><code>import numpy as np, matplotlib.pyplot as plt, matplotlib.widgets as mpwidgets, scipy.misc
x = scipy.misc.face(gray=False) # shape (768, 1024, 3)
y = np.random.random((100, 133)) # shape (100, 133)
fig, (ax0, ax1) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [5, 1]})
OPACITY = 0.5
img0 = ax0.imshow(x, cmap="jet")
img1 = ax0.imshow(y, cmap="jet", alpha=OPACITY, extent=img0.get_extent())
slider0 = mpwidgets.Slider(ax=ax1, label='opacity', valmin=0, valmax=1, valinit=OPACITY)
slider0.on_changed(lambda value: img1.set_alpha(value))
plt.show()
</code></pre>
| [
{
"answer_id": 74191965,
"author": "Hamzah",
"author_id": 16733101,
"author_profile": "https://Stackoverflow.com/users/16733101",
"pm_score": 2,
"selected": false,
"text": "layer.Slider"
},
{
"answer_id": 74267108,
"author": "amance",
"author_id": 17142551,
"author_pr... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1422096/"
] |
74,191,265 | <p>I am making mini project where you have to guess color code based on the color you see in div which is generated random. One button is correct answer (the real color's number) and the second button has random number, so you have to guess between two options.
My question is, how I can make the buttons change position, so the correct button is not always on one position.</p>
<pre><code>**Codepen**: https://codepen.io/Sim9n/pen/vYrYyrp
</code></pre>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function generateRandomIntegerInRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
let value5 = generateRandomIntegerInRange(100000, 999999);
document.getElementById("color").style.backgroundColor = `#${value5}`
let k = document.getElementById("dk")
k.textContent = `Correct answer: ${value5}`
document.querySelector("#guess").appendChild(k)
let o = document.createElement("button")
o.textContent = value5
document.querySelector("#firstGuess").appendChild(o)
/////////////
function generateRandomIntegerInRangee(minn, maxx) {
return Math.floor(Math.random() * (maxx - minn + 1)) + minn;
}
let value6 = generateRandomIntegerInRangee(100000, 999999);
// let z = document.getElementById("firstGuess")
// z.textContent = value6
// document.querySelector("#firstGuess").appendChild(z)
let p = document.createElement("button")
p.textContent = value6
document.querySelector("#firstGuess").appendChild(p)
/////////////</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#color{
background-color: #627246;
width: 50px;
height: 50px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(50% , -50%);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code> <div id="color"></div>
<div id="guess"></div>
<div id="dk"></div>
<div id="firstGuess"></div></code></pre>
</div>
</div>
</p>
<p>Thank you <3</p>
| [
{
"answer_id": 74191391,
"author": "gustavozapata",
"author_id": 6099890,
"author_profile": "https://Stackoverflow.com/users/6099890",
"pm_score": 3,
"selected": true,
"text": "firstGuess"
},
{
"answer_id": 74191658,
"author": "Syed Haider Ali Rizvi",
"author_id": 9631933... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20076362/"
] |
74,191,311 | <p>Following is an example of string that is a variable of my df:</p>
<pre><code>df_final['newa_1'][8395389]
"['Y02T 10/70' 'Y02E 60/00' 'Y02T 90/16' 'Y04S 10/126' 'Y02T 10/7072' 'Y02T 90/12' 'Y02T 90/14']"
</code></pre>
<p>What I would like to do is to put an "_" within the elements between '' regardless of how many spaces there are. So, in the example above, the output should be something like:</p>
<pre><code>"['Y02T_10/70' 'Y02E_60/00' 'Y02T_90/16' 'Y04S_10/126' 'Y02T_10/7072' 'Y02T_90/12' 'Y02T_90/14']"
</code></pre>
| [
{
"answer_id": 74191426,
"author": "Foram",
"author_id": 13516505,
"author_profile": "https://Stackoverflow.com/users/13516505",
"pm_score": 0,
"selected": false,
"text": "str.replace"
},
{
"answer_id": 74191455,
"author": "vtasca",
"author_id": 7878991,
"author_profi... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10967961/"
] |
74,191,324 | <p>I'm having a problem with running my android app:</p>
<blockquote>
<pre><code>Can't determine type for tag '<macro name="m3_comp_bottom_app_bar_container_color">?attr/colorSurface</macro>'
</code></pre>
</blockquote>
<p><img src="https://i.stack.imgur.com/thjYB.png" alt="enter image description here" /></p>
| [
{
"answer_id": 74202312,
"author": "TheLV",
"author_id": 2997715,
"author_profile": "https://Stackoverflow.com/users/2997715",
"pm_score": 4,
"selected": false,
"text": "implementation 'androidx.appcompat:appcompat:1.4.1'\nimplementation 'com.google.android.material:material:1.6.0'\n"
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19967535/"
] |
74,191,342 | <p>When I put my mouse over it, the background image shows up in an instant. I want to show a gradual trasition. How can I fix this?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.category__mid {
min-height: 260px;
width: 200px;
border: 2px solid #000;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-color: rgba(255, 255, 255, 1);
background-blend-mode: lighten;
transition: all 0.9s ease;
}
.category__mid:hover {
background-color: rgba(255, 255, 255, 0);
background-blend-mode: normal;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="category__mid" style="background-image: url('https://i.postimg.cc/NG159gHv/pexels-kampus-production-8439682.jpg')">
<h3>I want to show transition on hover. NOT when the user leaves</h3>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74202312,
"author": "TheLV",
"author_id": 2997715,
"author_profile": "https://Stackoverflow.com/users/2997715",
"pm_score": 4,
"selected": false,
"text": "implementation 'androidx.appcompat:appcompat:1.4.1'\nimplementation 'com.google.android.material:material:1.6.0'\n"
... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4454909/"
] |
74,191,345 | <p>I have a file where I export constants.</p>
<pre><code>export const PASSWORD_MISMATCH_ERROR = 'Passwords not match!';
export const USER_NOT_FOUND_ERROR = 'User not found';
export const WRONG_PASSWORD_ERROR = 'The password is incorrect';
export const UNAUTHORIZED = 'User unauthorized';
</code></pre>
<p>How do I make it so that I don't have to export each constant separately?</p>
| [
{
"answer_id": 74191363,
"author": "Amaarockz",
"author_id": 11281152,
"author_profile": "https://Stackoverflow.com/users/11281152",
"pm_score": 1,
"selected": false,
"text": "module.exports"
},
{
"answer_id": 74191394,
"author": "NeNaD",
"author_id": 14389830,
"autho... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328528/"
] |
74,191,357 | <p>I have a code block in my class</p>
<pre><code>def datas(self):
source = requests.get("http://150.150.150.150/tek.json").json()
return source
</code></pre>
<p>My program uses this data and this data is updated in that server everyday at 12:05 AM.
When i run app at 12:00 and if i wait untill 12:10 the datas is not updated in my app.
Only if i restart the app then new data pulls from my app.</p>
<p>I used While True and sleep for 10 but this caused the program to wait every 10 seconds to run.</p>
<p>How can i fix this issue. Should i use Clock Schedule? I don't know how to use. Could you please help me? I want to apdate data in every 10 seceonds so new datas can seen on the screen.
Thanks very much.</p>
| [
{
"answer_id": 74191363,
"author": "Amaarockz",
"author_id": 11281152,
"author_profile": "https://Stackoverflow.com/users/11281152",
"pm_score": 1,
"selected": false,
"text": "module.exports"
},
{
"answer_id": 74191394,
"author": "NeNaD",
"author_id": 14389830,
"autho... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19925544/"
] |
74,191,375 | <p>I'm trying to make app that will take the value of input element and use this value in inc/dec component. I have 2 components and I use props.</p>
<ol>
<li>Component have input and a set button.</li>
<li>Component have inc/dec buttons and reset button</li>
</ol>
<p>I'm enter number to first component set it with button. Then I want to inc/dec it in second component and I have NaN error. When I reset it the element take the value of first component and after that inc/dec works well.</p>
<p><strong>first component:</strong></p>
<pre><code>import React, { useState } from "react";
import Sample from "../Sample/Sample";
const SetSample = () => {
const [value, setValue] = useState();
const formChange = (e) => {
e.preventDefault();
}
const handlerChange = () => {
const foo = document.querySelector("input").value * 1;
setValue(foo);
}
return (
<div>
<form onSubmit={formChange}>
<input type="text" />
<button type="submit" onClick={handlerChange}>Set start value</button>
</form>
<p>Start value is: {value || 'Please enter a number'}</p>
<hr />
<Sample start={value} />
</div>
);
}
export default SetSample;
</code></pre>
<p><strong>second component:</strong></p>
<pre><code>import React, { useState } from "react";
const Sample = (props) => {
const point = props.start;
const [counter = 0, setCounter] = useState(point);
const decrement = () => {
setCounter(counter - 1);
}
const increment = () => {
setCounter(counter + 1);
}
const reset = () => {
setCounter(point);
}
return (
<div>
<button onClick={decrement}>-</button>
<div>{counter}</div>
<button onClick={increment}>+</button>
<div><button onClick={reset}>reset</button></div>
</div>
);
}
export default Sample;
</code></pre>
<p>It seems to me that the problem is in counter and point values.</p>
| [
{
"answer_id": 74191644,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "NaN"
},
{
"answer_id": 74191729,
"author": "Ankit",
"author_id": 19757319,
"author_profil... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19344652/"
] |
74,191,383 | <p>I'm trying to create OpenGLx context after the Xlib's window creation. I'm trying to separate the Xlib window creation and opengl context creation into two different phases.
Win32 window-opengl context creation was rather simple but I couldnt find any resource that illustrates the same process with Xlib-opengl in linux</p>
<p>This is how its done for xlib-linux</p>
<pre><code>GLint glxAttribs[] = {
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, 24,
GLX_STENCIL_SIZE, 8,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_SAMPLE_BUFFERS, 0,
GLX_SAMPLES, 0,
None
};
XVisualInfo* visual = glXChooseVisual(display, screenId, glxAttribs);
XSetWindowAttributes windowAttribs;
windowAttribs.border_pixel = BlackPixel(display, screenId);
windowAttribs.background_pixel = WhitePixel(display, screenId);
windowAttribs.override_redirect = True;
windowAttribs.colormap = XCreateColormap(display, RootWindow(display, screenId), visual->visual, AllocNone);
windowAttribs.event_mask = ExposureMask;
window = XCreateWindow(display, RootWindow(display, screenId), 0, 0, 320, 200, 0, visual->depth, InputOutput, visual->visual, CWBackPixel | CWColormap | CWBorderPixel | CWEventMask, &windowAttribs);
</code></pre>
<p>This is how its done in windows</p>
<pre><code>const WindowsWindow* pWin32Window = (const WindowsWindow*)pOwnerWindow;
HWND windowHandle = pWin32Window->GetWin32WindowHandle();
HDC windowDeviceContext = pWin32Window->GetWin32WindowDeviceContext();
/*
* Create pixel format
*/
PIXELFORMATDESCRIPTOR pfd = { sizeof(pfd),1 };
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nVersion = 1;
pfd.cColorBits = OpenGLDeviceUtilsWin32::GetColorBits(desc.SwapchainBufferFormat);
pfd.cAlphaBits = OpenGLDeviceUtilsWin32::GetAlphaBits(desc.SwapchainBufferFormat);
pfd.cDepthBits = OpenGLDeviceUtilsWin32::GetDepthBits(desc.SwapchainDepthStencilBufferFormat);
pfd.cStencilBits = OpenGLDeviceUtilsWin32::GetStencilBits(desc.SwapchainDepthStencilBufferFormat);
pfd.cAuxBuffers = 3;
pfd.iLayerType = PFD_MAIN_PLANE;
const int pixelFormatIndex = ChoosePixelFormat(windowDeviceContext, &pfd);
ASSERT(pixelFormatIndex != 0,"OpenGLDevice","Invalid pixel format");
ASSERT(SetPixelFormat(windowDeviceContext, pixelFormatIndex, &pfd), "OpenGLDevice", "Win32 window rejected the specified pixel format");
HGLRC tempContext = wglCreateContext(windowDeviceContext);
ASSERT(tempContext != NULL, "OpenGLDevice", "Creation of wgl dummy context failed!");
wglMakeCurrent(windowDeviceContext, tempContext);
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
ASSERT(wglCreateContextAttribsARB != NULL, "OpenGLDevice", "WGL get proc address failed!");
</code></pre>
<p>But I would expect something like this.</p>
<ul>
<li>Create xlib window</li>
<li>Check for glx attribs if the window can support that pixel format</li>
<li>Create glx context using pixel format</li>
</ul>
<p>But instead it goes as</p>
<ul>
<li>Create window with your specific glx attribs</li>
<li>Create glx context</li>
</ul>
<p>I wonder if there is a way for us to create window without letting xlib know we are going to use it for opengl and implement OpenGL specific setup for window creation process.</p>
| [
{
"answer_id": 74191644,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "NaN"
},
{
"answer_id": 74191729,
"author": "Ankit",
"author_id": 19757319,
"author_profil... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15613723/"
] |
74,191,423 | <p>I am trying to write a function taking a string as an argument and using this argument as a class object.</p>
<p>Note that my explanantion might be strangely formulated sice I could not find an answer online. The MWE below should clarify what I mean, the problematic line is indicated.</p>
<p>Edit: in the MWE, "print" is an example. I need to be able to call the object to update it, print it or, in the case of a list, append to it. I need access to the object itself, not the value of the object.</p>
<p><strong>MWE</strong></p>
<pre><code># Create a class
class myClass():
def __init__(self):
self.one = "Test"
self.two = "Plop"
# Define function
def myFunction (parameter):
print(myObject.parameter)##### This line is currently not possible.
# Use class
myObject = myClass()
# Use function
myFunction("one")
</code></pre>
<p>I am not trying to append a new object to the class, only to call an existing object.</p>
<p>Is this even possible?</p>
| [
{
"answer_id": 74191453,
"author": "Andrew Menshicov",
"author_id": 20156518,
"author_profile": "https://Stackoverflow.com/users/20156518",
"pm_score": 3,
"selected": true,
"text": "getattr"
},
{
"answer_id": 74191619,
"author": "SKY",
"author_id": 5845060,
"author_pr... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14782823/"
] |
74,191,469 | <p>I am currently trying to make a board game in the style of memory (I am self taught, and things like that help me great in understanding javascript). My question is probably basic stuff, but I am new to all of this so I appreciate any help.</p>
<p>My problem is that I have two cards with the same class, and with my code, when I click on first or second one, it only works on the first card.</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>document.querySelectorAll(".first-card").forEach(container => {
container.addEventListener('click', flipCard)
})
function flipCard() {
document.querySelector(".first-card").classList.toggle("flip")
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>*,
*::before,
*::after {
box-sizing: border-box;
}
body {
padding: 100px;
display: flex;
}
.first-card,
.second-card {
width: 100px;
height: 150px;
border: 3px solid black;
border-radius: 10px;
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
margin: 10px;
}
.flip {
transform: rotateY(180deg);
}
.front,
.back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
z-index: 2;
transform: rotateY(0deg);
}
.back {
transform: rotateY(180deg);
}
.first-card .front {
background: lightblue;
width: 100%;
height: 100%;
}
.second-card .front {
background: red;
width: 100%;
height: 100%;
}
.first-card .back,
.second-card .back {
background: black;
width: 100%;
height: 100%;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/CSS" href="memory.css" />
</head>
<body>
<div class="first-card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
<div class="second-card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
<div class="first-card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
<div class="second-card">
<div class="front">
front
</div>
<div class="back">
back
</div>
</div>
<script src="memory.js"></script>
</body>
</html></code></pre>
</div>
</div>
</p>
<p>Like I said, I am only beginner, so any help or explanation is welcome.
Thank you</p>
| [
{
"answer_id": 74191534,
"author": "ask4you",
"author_id": 18309173,
"author_profile": "https://Stackoverflow.com/users/18309173",
"pm_score": 3,
"selected": true,
"text": "flipCard"
},
{
"answer_id": 74191684,
"author": "Deniz Karadağ",
"author_id": 14999457,
"author... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20003804/"
] |
74,191,484 | <p>I have a top folder named <code>home</code> and nested folders and files inside<br />
I need to insert some data from files and folders into a table<br />
The following (simplified) code works fine if I manually declare parent folder for each level separatelly, i.e. - <code>home/lorem/</code>, <code>home/impsum/</code>, <code>home/ipsum/dolor/</code> etc<br />
Is there a way to do this automatically for all nested files and folders ?<br />
Actually, I need the path for each of them on each level</p>
<pre><code>$folders = glob("home/*", GLOB_ONLYDIR);
foreach($folders as $el){
//$path = ??;
//do_something_with folder;
}
$files = glob("home/*.txt");
foreach($files as $el){
//$path = ??;
//do_something_with file;
}
</code></pre>
| [
{
"answer_id": 74191534,
"author": "ask4you",
"author_id": 18309173,
"author_profile": "https://Stackoverflow.com/users/18309173",
"pm_score": 3,
"selected": true,
"text": "flipCard"
},
{
"answer_id": 74191684,
"author": "Deniz Karadağ",
"author_id": 14999457,
"author... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10983537/"
] |
74,191,498 | <p>I want to retain the array instead of creating a new one (which map does), hence, I'm doing the following using forEach. But none of my comparisons are going through and the array remains the same.</p>
<pre><code>const array1 = [1, 2, 3];
array1.forEach(element => element < 2 ? 0 : element);
//array1.forEach(element => element + 2);
console.log(array1);
</code></pre>
<p>The result should be array1 = [0, 2, 3];</p>
<p>Is my understanding of how it works incorrect?</p>
| [
{
"answer_id": 74191600,
"author": "Mina",
"author_id": 11887902,
"author_profile": "https://Stackoverflow.com/users/11887902",
"pm_score": 3,
"selected": true,
"text": "map"
},
{
"answer_id": 74191652,
"author": "KooiInc",
"author_id": 58186,
"author_profile": "https... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17204104/"
] |
74,191,499 | <p>I am new to python and struggling with adding values to nested lists. I have a list that contains 6 values. My lists of lists contains 3 lists and I would like to add the values the 6 values in such a way that the 1 value goes to the 1 list, 2 value to 2nd list, 3rd value to 3 list. Then I would like to continue looping so that the 4 value goes to the first list, 5 value to second list and 6 value to 3rd list. In the end I want to end up with a list of three lists which each contains 2 items. I am struggling to get anything wise to run. Can someone help me on this, thank you!</p>
| [
{
"answer_id": 74191659,
"author": "tobias_k",
"author_id": 1639625,
"author_profile": "https://Stackoverflow.com/users/1639625",
"pm_score": 3,
"selected": true,
"text": "lists = [[], [], []] \nvalues = [1, 2, 3, 4, 5, 6] ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328508/"
] |
74,191,528 | <p>I have a list</p>
<pre class="lang-py prettyprint-override"><code>S = ["A", "B", "C", "D", "E", "F"]
</code></pre>
<p>and I want all combinations 3-by-3 without repetition but <strong>with restrictions</strong>: some elements cannot be in the same combination. Say, for example, that <code>A</code>, <code>B</code>, and <code>C</code> cannot be taken together: if there's <code>A</code> then <code>B</code> or <code>C</code> cannot belong to the combination, so in this case <code>[A, B, D]</code> is not a valid combination but <code>[A, D, E]</code> is valid.</p>
<p>I'm trying to code an algorithm (the list can be wider and we could have more restrictions).</p>
<p>What I've done for far is</p>
<pre class="lang-py prettyprint-override"><code>S = ["A", "B", "C", "D", "E", "F"]
restricts = [
["A", "B", "C"],
["E", "F"]
]
COMBS = []
combs = list(combinations(S, 3))
# for each combination
for comb in combs:
comb = list(comb)
print("==> CHECKING", comb)
valid = True
# for each restriction
for restrict in restricts:
if not valid:
break
intersect = len(set(comb).intersection(set(restrict)))
print("intersect", comb, restrict, "=", intersect)
# if more than an element
if intersect > 1:
valid = False
print("valid:", valid)
if valid:
COMBS.append(comb)
print("\nValid combinations:")
print(COMBS)
</code></pre>
<p>And it's working</p>
<pre><code>Valid combinations:
[['A', 'D', 'E'], ['A', 'D', 'F'], ['B', 'D', 'E'], ['B', 'D', 'F'], ['C', 'D', 'E'], ['C', 'D', 'F']]
</code></pre>
<p>But I'm wondering if there's a better/faster way to do it.</p>
| [
{
"answer_id": 74191853,
"author": "bn_ln",
"author_id": 10535824,
"author_profile": "https://Stackoverflow.com/users/10535824",
"pm_score": 0,
"selected": false,
"text": "for comb in combinations(S, 3):\n if all(len(set(comb).intersection(r)) < 2 for r in restricts):\n COMBS.a... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6822178/"
] |
74,191,530 | <p>I'm trying to view data that comes from API with GetX
but there is something wrong I tried to fix it but I can't
What's the problem guys please</p>
<p>this is my controller:</p>
<pre><code>class ProductController extends GetxController {
var productsList = <Product>[].obs;
var isLoading = true.obs;
@override
void onInit() {
fetchProducts();
super.onInit();
}
void fetchProducts() async {
try {
var product = await RemoteServices.fetchData();
if (product != null) {
productsList.value = product;
isLoading.value = false;
}
} catch (e) {
print(e);
}
}
}
</code></pre>
<p>and this is Remote Service:</p>
<pre><code>class RemoteServices {
static var client = http.Client();
static Future<List<Product>> fetchData() async {
final uri = Uri.parse(
"https://makeup-api.herokuapp.com/api/v1/products.json?product_type=blush");
final response = await client.get(uri);
if (response.statusCode == 200) {
var jsonData = json.decode(response.body);
final productsListJson =
(jsonData[''] as List).map((e) => Product.fromJson(e)).toList();
//jsonData['data']^^^
print("its WORK SUCCESSFULLY");
return productsListJson;
} else {
throw Exception('Something Wrong :(');
}
}
}
</code></pre>
<p>and this is View Page :</p>
<pre><code>class HomePage extends StatelessWidget {
final productController = Get.put(ProductController());
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.purple,
body: Obx(() => productController.isLoading.value
? Center(
child: CircularProgressIndicator(),
)
: ListView.builder(
itemCount: productController.productsList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Column(
children: [
Image.network(productController
.productsList[index].imageLink
.toString()),
Text(productController.productsList[index].name
.toString()),
Text(productController.productsList[index].price
.toString()),
],
),
);
},
)),
);
}
}
</code></pre>
<p>when I run the app The CircularProgressIndicator() still running and the run page tell me :</p>
<p><strong>Syncing files to device Android SDK built for x86...<br />
Restarted application in 4,096ms.<br />
[GETX] Instance "ProductController" has been created<br />
[GETX] Instance "ProductController" has been initialized<br />
I/flutter (28829): type 'String' is not a subtype of type 'int' of 'index'</strong></p>
| [
{
"answer_id": 74191826,
"author": "rasityilmaz",
"author_id": 15812214,
"author_profile": "https://Stackoverflow.com/users/15812214",
"pm_score": 0,
"selected": false,
"text": "final productsListJson = (jsonData as List).map((e) => Product.fromJson(e)).toList();\n"
},
{
"answer_... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191530",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9164154/"
] |
74,191,562 | <p>I am trying to come up with a better title.<br />
I am new in Chisel and Scala. Below there is a Chisel code defining and testing an module.</p>
<pre><code>import chisel3._
import chiseltest._
import org.scalatest.flatspec.AnyFlatSpec
class DeviceUnderTest extends Module {
val io = IO(new Bundle {
val a = Input(UInt(2.W))
val b = Input(UInt(2.W))
val out = Output(UInt(2.W))
})
io.out := io.a & io.b
}
class WaveformTestWithIteration extends AnyFlatSpec with ChiselScalatestTester {
"WaveformIteration" should "pass" in {
test(new DeviceUnderTest)
.withAnnotations(Seq(WriteVcdAnnotation)) ( dut => // ???
{
for (a <- 0 until 4; b <- 0 until 4) {
dut.io.a.poke(a.U)
dut.io.b.poke(b.U)
dut.clock.step()
}
}
)
}
}
</code></pre>
<p>The code line with comments <code>???</code> is where I am quite puzzled. Where does the variable <code>dut</code> is defined? It seems an reference to instance gained by <code>new DeviceUnderTest</code>.</p>
<p><code>test(new DeviceUnderTest).withAnnotations(Seq(WriteVcdAnnotation))</code> return an <code>TestBuilder[T]</code> with <code>apply</code> method:</p>
<pre><code> class TestBuilder[T <: Module](...) {
...
def apply(testFn: T => Unit): TestResult = {
runTest(defaults.createDefaultTester(dutGen, finalAnnos))(testFn)
}
...
}
</code></pre>
<p>So, <code>dut => {...}</code> is a function <code>(T) => Unit</code>? But it does not look like a standard lambda (<code>(x:T) => {...}</code>)? Or it is something else?<br />
What is this syntax in scala exactly?</p>
| [
{
"answer_id": 74192397,
"author": "Andrey Tyukin",
"author_id": 2707792,
"author_profile": "https://Stackoverflow.com/users/2707792",
"pm_score": 2,
"selected": true,
"text": "def test[A](testedThing: A)(testBody: A => Unit): Unit = testBody(testedThing)\n"
},
{
"answer_id": 741... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20051585/"
] |
74,191,573 | <p>I am trying to create code that will delete all sheets in active workbook if name contains part text from input. So far nothing seems working and I have no clue why.</p>
<p>I am using this code:</p>
<pre><code>Private Sub CommandButton28_Click()
Dim shName As String
Dim xName As String
Dim xWs As Worksheet
Dim cnt As Integer
shName = Application.InputBox("Enter the specific text:", "Delete sheets", _
ThisWorkbook.ActiveSheet.Name, , , , , 2)
If shName = "" Then Exit Sub
xName = "*" & shName & "*"
' MsgBox xName
Application.DisplayAlerts = False
cnt = 0
For Each xWs In ThisWorkbook.Sheets
If xWs.Name Like xName Then
xWs.Delete
cnt = cnt + 1
End If
Next xWs
Application.DisplayAlerts = True
MsgBox "Have deleted " & cnt & " worksheets", vbInformation, "Sheets removed"
End Sub
</code></pre>
<p>But when I enter specific text (no spaces before or after) it doesn't work. Any ideas how to fix it?
Here is data from sheet where I tested it: <a href="https://i.stack.imgur.com/DdMXt.png" rel="nofollow noreferrer">Sheets names</a></p>
<p>And here is the result of macro: <a href="https://i.stack.imgur.com/uBsR4.png" rel="nofollow noreferrer">Result of macro</a></p>
| [
{
"answer_id": 74192397,
"author": "Andrey Tyukin",
"author_id": 2707792,
"author_profile": "https://Stackoverflow.com/users/2707792",
"pm_score": 2,
"selected": true,
"text": "def test[A](testedThing: A)(testBody: A => Unit): Unit = testBody(testedThing)\n"
},
{
"answer_id": 741... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20181768/"
] |
74,191,585 | <p>I have a dataframe that looks like that (Date is the index):</p>
<pre><code>Date Value Sensor
19/08/2021 8787 A
20/08/2021 7360 A
23/08/2021 17570 A
24/08/2021 18993 A
25/08/2021 17947 A
26/08/2021 18317 A
27/08/2021 16940 A
30/08/2021 23837 A
31/08/2021 18353 A
19/08/2021 15010 B
20/08/2021 10873 B
23/08/2021 5270 B
24/08/2021 21060 B
25/08/2021 13430 B
26/08/2021 6267 B
27/08/2021 33677 B
30/08/2021 9460 B
31/08/2021 8223 B
</code></pre>
<p>I need to calculate a new column that would be the current value of the value column divided by the value 5 days ago, plus the value of 5 days ago divided by the value 15 days ago. This has to be done for each sensor. Values which cannot be calculated can be filled with NA or anything meaningless. This is what I would like to get as reslt:</p>
<pre><code>Date Value Sensor Calc
2/08/2021 8247 A NA
3/08/2021 20267 A NA
4/08/2021 10507 A NA
5/08/2021 10397 A NA
6/08/2021 15513 A NA
9/08/2021 10063 A NA
10/08/2021 7787 A NA
11/08/2021 7607 A NA
12/08/2021 12823 A NA
13/08/2021 10410 A NA
16/08/2021 12810 A NA
17/08/2021 22507 A NA
18/08/2021 15050 A NA
19/08/2021 8787 A NA
20/08/2021 7360 A NA
23/08/2021 17570 A 2.924876806
24/08/2021 18993 A 1.954395294
25/08/2021 17947 A 2.624870109
26/08/2021 18317 A 2.92970437
27/08/2021 16940 A 2.776071226
30/08/2021 23837 A 3.102687734
31/08/2021 18353 A 3.405368483
2/08/2021 18170 B NA
3/08/2021 11347 B NA
4/08/2021 10657 B NA
5/08/2021 18710 B NA
6/08/2021 8707 B NA
9/08/2021 8490 B NA
10/08/2021 11043 B NA
11/08/2021 10953 B NA
12/08/2021 9663 B NA
13/08/2021 20227 B NA
16/08/2021 14010 B NA
17/08/2021 15863 B NA
18/08/2021 11583 B NA
19/08/2021 15010 B NA
20/08/2021 10873 B NA
23/08/2021 5270 B 1.147211069
24/08/2021 21060 B 2.725608385
25/08/2021 13430 B 2.246349071
26/08/2021 6267 B 1.219766441
27/08/2021 33677 B 4.346070613
30/08/2021 9460 B 2.415796685
31/08/2021 8223 B 2.297546305
</code></pre>
<p>Within one sensor, I can do it with something like</p>
<pre><code>df['Calc'] = (df.iloc[:, 1].div(df.iloc[:, 1].shift(5))+df.iloc[:, 1].shift(15).div(df.iloc[:, 1].shift(15))
</code></pre>
<p>but I am struggling to do it within the group.</p>
<p>Bonus question :-) Once the calculation is done I need to transpose the dataframe and use sensor as index and dates as column headers with "Calc"s as horizontal values.</p>
<p>Appreciate your help!</p>
| [
{
"answer_id": 74192397,
"author": "Andrey Tyukin",
"author_id": 2707792,
"author_profile": "https://Stackoverflow.com/users/2707792",
"pm_score": 2,
"selected": true,
"text": "def test[A](testedThing: A)(testBody: A => Unit): Unit = testBody(testedThing)\n"
},
{
"answer_id": 741... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11361401/"
] |
74,191,586 | <p>Let's say I have an url that looks like this and yields data in json format by specifying a start and end date in the following format: "YYYY-MM-DD".</p>
<pre><code>url = "https://thisisaurl.com/data/asd007?start=2021-10-01&end=2021-10-28"
</code></pre>
<p>The maximum number of days for which data can be retrieved via this url is 28. In order to retrieve a year of data, this means that I need to :</p>
<ol>
<li>loop over a date range that each time generates a <code>start_date</code> and an <code>end_date</code> with (a max of) 28 days in between</li>
<li>feed this to the url</li>
<li>append / collect this data each time the url is called</li>
</ol>
<p>Let's say I want to retrieve data for the period <code>2021-05-01</code> - <code>2021-10-24</code>, I know how I can loop over this date range with a time delta of 28 days like so:</p>
<pre><code>from datetime import date, timedelta
start_date = date(2021, 5, 1)
end_date = date(2021, 10, 24)
delta = timedelta(days=28)
while start_date <= end_date:
print(start_date.strftime("%Y-%m-%d"))
start_date += delta
2021-05-01
2021-05-29
2021-06-26
2021-07-24
2021-08-21
2021-09-18
2021-10-16
</code></pre>
<p>But I struggle how to assign these values as start and end date to the url and how to make sure that the full period is being generated (e.g. 2021-10-24 instead of 2021-10-16). Any ideas?</p>
| [
{
"answer_id": 74192397,
"author": "Andrey Tyukin",
"author_id": 2707792,
"author_profile": "https://Stackoverflow.com/users/2707792",
"pm_score": 2,
"selected": true,
"text": "def test[A](testedThing: A)(testBody: A => Unit): Unit = testBody(testedThing)\n"
},
{
"answer_id": 741... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15376262/"
] |
74,191,591 | <p>I have a factory that returns objects:</p>
<pre class="lang-java prettyprint-override"><code> public class Factory {
public static Vehicle getVehicle(Options options) {
if (options.getType().equals("car")) return new Car(options);
if (options.getType().equals("moped")) return new Moped(options);
}
}
</code></pre>
<p>The objects that the factory creates should be able to take class specific options as parameters:</p>
<pre class="lang-java prettyprint-override"><code>public class Car extends Vehicle {
public Car(final CarOptions carOptions) { this.carOptions = carOptions; }
}
</code></pre>
<pre class="lang-java prettyprint-override"><code>public class Moped extends Vehicle {
public Moped(final MopedOptions mopedOptions) { this.mopedOptions = mopedOptions; }
}
</code></pre>
<p>The options classes:</p>
<pre class="lang-java prettyprint-override"><code>public class Options {
// methods
}
</code></pre>
<pre class="lang-java prettyprint-override"><code>public class CarOptions implements Options {
// methods
}
</code></pre>
<pre class="lang-java prettyprint-override"><code>public class Moped implements Options {
// methods
}
</code></pre>
<p>How can I give the <code>Factory.getVehicle</code> method a generic <code>Options</code> parameter and have it passed on to the objects the factory creates? I can call <code>Factory.getVehicle(new CarOptions())</code> just fine but inside the factory itself the objects expect a specific type of <code>Options</code>.</p>
<blockquote>
<p>Required type: CarOptions Provided: Options</p>
</blockquote>
<p>I thought that because <code>CarOptions</code> implements <code>Options</code> I could just pass it on as a parameter to <code>new Car(options)</code> but that does not seem to be the case.</p>
<p>I've tried to resolve this by using generics but haven't found a solution that works.</p>
| [
{
"answer_id": 74191890,
"author": "Stefan Warminski",
"author_id": 7707631,
"author_profile": "https://Stackoverflow.com/users/7707631",
"pm_score": 3,
"selected": true,
"text": "Factory.getVehicle"
},
{
"answer_id": 74192326,
"author": "AussieDev81",
"author_id": 140247... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2608063/"
] |
74,191,594 | <p>I have successfully centered the <code>Hello There</code> button.
But my problem is, a little bit of lines are appearing on it.
I could put a <code>background-color: white</code> to solve it, but is there a better way to do this and a better coding? Like not using <code>position: absolute</code> etc....?</p>
<p><a href="https://codesandbox.io/s/reverent-wright-w4hs8u?file=/demo.js" rel="nofollow noreferrer">CLICK HERE FOR CODESANDBOX</a></p>
<pre><code> <Stack
alignItems={"center"}
sx={{
marginTop: 2,
position: "absolute",
display: "flex",
left: 0,
right: 0
}}
>
<Button variant="outlined">Hello There</Button>
</Stack>
</code></pre>
| [
{
"answer_id": 74191890,
"author": "Stefan Warminski",
"author_id": 7707631,
"author_profile": "https://Stackoverflow.com/users/7707631",
"pm_score": 3,
"selected": true,
"text": "Factory.getVehicle"
},
{
"answer_id": 74192326,
"author": "AussieDev81",
"author_id": 140247... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8305219/"
] |
74,191,595 | <p>i am trying to implement and + operator that gets rhs obj
and lhs obj,
the object contains char* string;
for for e.g
s1 contains "eden"
s2 contains "sh"
I want that s3 = s1 +s2 will be "eden sh" yet I cannot figure it out.
I don't USE vector or std::string because the assignment was to do char* arr
code:</p>
<pre><code>auto *buff = new char[std::strlen(lhs.getName()) + std::strlen(rhs.getName()) + 2];
assert(buff);
std::strncpy(buff, lhs.getName(), std::strlen(lhs.getName()));
std::strncpy(buff + std::strlen(lhs.getName())," ", sizeof(char));
std::strncpy(buff + std::strlen(lhs.getName()), rhs.getName(), std::strlen(rhs.getName()));
tmp.setName(buff);
</code></pre>
<p>***set name is a function that copies buffer to m_name private data member.</p>
<p>the result is edensh</p>
| [
{
"answer_id": 74191890,
"author": "Stefan Warminski",
"author_id": 7707631,
"author_profile": "https://Stackoverflow.com/users/7707631",
"pm_score": 3,
"selected": true,
"text": "Factory.getVehicle"
},
{
"answer_id": 74192326,
"author": "AussieDev81",
"author_id": 140247... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14095705/"
] |
74,191,602 | <p>I was building a django project in that I need to create an edit option for a particular model named SchoolDetail. But while fetching the data from this table using id, its showing the above error</p>
<p><strong>views.py</strong></p>
<pre><code>def SchoolPage(request):
school_details = SchoolDetail.objects.all()
school_details_pk = school_details.id
context = {'school_details': school_details, 'school_details_pk':school_details_pk}
return render(request, 'busschool.html', context)
</code></pre>
<p><strong>models.py</strong></p>
<pre><code>class SchoolDetail(models.Model):
school_name = models.CharField(max_length=100, blank= True, null=True)
school_place = models.CharField(max_length=100, blank= True, null=True)
school_email = models.CharField(max_length=100, blank= True, null=True)
school_address = models.CharField(max_length=100, blank= True, null=True)
school_phone = models.CharField(max_length=15, blank= True, null=True)
is_verified = models.BooleanField(default=False)
def __str__(self):
return self.school_name
</code></pre>
<p><strong>template</strong></p>
<pre><code>enter code here
<tbody>
{% for i in school_details %}
<tr>
<td>{{i.school_name}}</td>
<td>{{i.school_place}}</td>
<td>{{i.school_email}}</td>
<td>{{i.school_address}}</td>
<td>{{i.school_phone}}</td>
<td>{{i.is_verified}}</td>
<td><a href="{% url 'schooledit' school_details_pk %}">click</a></td>
</tr>
{% endfor %}
<tbody>
</code></pre>
| [
{
"answer_id": 74192569,
"author": "inquirer",
"author_id": 11985088,
"author_profile": "https://Stackoverflow.com/users/11985088",
"pm_score": 2,
"selected": false,
"text": "school_details[0].id\n"
},
{
"answer_id": 74201832,
"author": "Noel S Jacob",
"author_id": 149673... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14967379/"
] |
74,191,665 | <p>I have <strong>two tables</strong>, clients and subscriptions. We can find <strong>many subscriptions in the table of subscriptions from a client</strong>. It is <strong>allied by a foreign key(client_id)</strong>.</p>
<p><strong>In the table subscriptions I have a parameter status</strong>, the values could be "active, start pending, cancelled..."</p>
<p><strong>I want to get all the clients</strong>(SELECT * FROM clients), but <strong>I want to add new column in the query(STATUS_CLIENT)</strong>: this column must be true if I find an status='active' in one of the subscriptions of the client and false if I dont get any active status in the table subscriptions.</p>
<p>Thanks!</p>
| [
{
"answer_id": 74191747,
"author": "scloudes",
"author_id": 10042276,
"author_profile": "https://Stackoverflow.com/users/10042276",
"pm_score": -1,
"selected": false,
"text": "SELECT *, CASE WHEN S.STATUS = 'ACTIVE' THEN TRUE\nELSE FALSE END AS STATUS_CLIENT\nFROM CLIENTS AS C\nLEFT JOIN... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328687/"
] |
74,191,681 | <pre><code>import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int i, temp, n, j ,num, array[], counter, k;
Scanner input = new Scanner(System.in);
num = input.nextInt();
array = new int[num];
n = array.length;
temp = 0;
for (counter = 0; counter < num; counter++)
array[counter] = input.nextInt();
for (i = 1; i < array.length; i++) {
for (j = i; j > 0; j--) {
if (array[j - 1] > array[j]) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
for(k=0; k<n; k++)System.out.print(array[k]+ " ");
System.out.print("\n");
}
}
}
}
</code></pre>
<p>The code above is for insertion sorting an array. For example,</p>
<p>INPUT:</p>
<pre><code>8
8 4 3 7 6 5 2 1
</code></pre>
<p>EXPECTED OUTPUT:</p>
<pre><code>1 4 3 7 6 5 2 8
1 2 3 7 6 5 4 8
1 2 3 4 6 5 7 8
1 2 3 4 5 6 7 8
</code></pre>
<p>ACTUAL OUTPUT:</p>
<pre><code>1 4 3 7 6 5 2 8
1 2 3 7 6 5 4 8
1 2 3 7 6 5 4 8
1 2 3 4 6 5 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
</code></pre>
<p>The code works in some sense but I would like to remove all the duplicates. In other words, only print if the swap happens. Anyone can help? Thank you so much.</p>
<p>EDIT:
When an already-sorted array is passed to the argument, the output should be nothing instead of printing the already-sorted array. For example,</p>
<p>INPUT:</p>
<pre><code>5
1 2 3 4 5
</code></pre>
<p>OUTPUT:</p>
<pre><code></code></pre>
| [
{
"answer_id": 74191815,
"author": "Teddy Tsai",
"author_id": 16959486,
"author_profile": "https://Stackoverflow.com/users/16959486",
"pm_score": 1,
"selected": false,
"text": "public class Main {\n public static void main(String[] args) {\n int i, temp, n, j, num, array[], cou... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19322926/"
] |
74,191,693 | <p>I already installed Dart extension for VS Code and also tried ngdart but it isnt working
So I pressed CTRL+SHIFT+P And picked > Dart: New Project</p>
<p>but there is no option for</p>
<blockquote>
<p>Angular Dart Web App</p>
</blockquote>
<p>only</p>
<blockquote>
<p>Bare-Bones Web App</p>
</blockquote>
<blockquote>
<p>Console Application</p>
</blockquote>
<blockquote>
<p>Dart Package</p>
</blockquote>
<blockquote>
<p>Server App</p>
</blockquote>
| [
{
"answer_id": 74202142,
"author": "Timothy",
"author_id": 19185956,
"author_profile": "https://Stackoverflow.com/users/19185956",
"pm_score": 2,
"selected": true,
"text": "ngdart_cli"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19185956/"
] |
74,191,725 | <p>DB fiddle: <a href="https://dbfiddle.uk/QLKIuW1G" rel="nofollow noreferrer">https://dbfiddle.uk/QLKIuW1G</a></p>
<hr />
<p>For a given table, I have grouped by two columns and calculated the average of a third column. However, I would like to only get rows that have a value for all possible values in the category column (these are <code>1</code> and <code>2</code>). How can this result be achieved?</p>
<p>Example table:</p>
<pre><code>| name | category | number |
| -------- | -------- | ------ |
| jack | 1 | 12.30 |
| jack | 1 | 12.50 |
| jack | 2 | 13.35 |
| jack | 2 | 13.35 |
| jack | 2 | 13.35 |
| james | 1 | 18.76 |
| james | 1 | 20.38 |
| kate | 1 | 22.14 |
| kate | 1 | 22.18 |
| kate | 2 | 21.80 |
| kate | 2 | 22.00 |
</code></pre>
<p>Current status:</p>
<pre><code>SELECT name, category, AVG(number) AS average_number
FROM dummy_table
GROUP BY name, category
-- Gives:
| name | category | average_number |
| -------- | -------- | -------------- |
| jack | 1 | 12.40 |
| jack | 2 | 13.35 |
| james | 1 | 19.57 |
| kate | 1 | 22.16 |
| kate | 2 | 21.90 |
</code></pre>
<p>Desired result:</p>
<pre><code>-- `James` is dropped because he only has values for category 1, and not category 2.
| name | category | average_number |
| -------- | -------- | -------------- |
| jack | 1 | 12.40 |
| jack | 2 | 13.35 |
| kate | 1 | 22.16 |
| kate | 2 | 21.90 |
</code></pre>
<hr />
<p>DDL (from fiddle, different values):</p>
<pre><code>Create Table Emps(person_name VARCHAR(50), category INT, number DECIMAL);
Insert Into Emps Values
('steve',1,15.30),
('steve',1,14.30),
('steve',2,14.30),
('steve',2,13.30),
('john',1,18.76),
('john',1,17.36),
('john',1,18.42),
('angela',1,23.84),
('angela',1,24.48),
('angela',2,22.00),
('angela',2,22.94);
</code></pre>
| [
{
"answer_id": 74202142,
"author": "Timothy",
"author_id": 19185956,
"author_profile": "https://Stackoverflow.com/users/19185956",
"pm_score": 2,
"selected": true,
"text": "ngdart_cli"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7052830/"
] |
74,191,748 | <p><strong>I have a global search (always in the navbar)</strong>. If the user searches for an ID in the search bar, the user is redirected to a search page where I show a table with all the results for that specific ID. If the user cleans the input field (backspace) the user is redirected to the previous page he/she was on (the user could have searched the ID from the dashboard or any other pages in the app).</p>
<p>But the issues I have now are:</p>
<ol>
<li>The user search for an ID</li>
<li>The user is redirected to the search page</li>
<li>The user after searching, decide to change page from the sidebar, then goes to any random page (let's say to a dashboard)</li>
<li>The input field with that specific ID user searched at the beginning is still present in the search input field, even if the user is now in the dashboard</li>
</ol>
<p>So basically I need to clean the input field in the search page all the time the user changes the page.</p>
<p>So far I have this:</p>
<pre><code>const searchPageRegex = /^\/org\/\d+\/search/;
interface SearchWidgetProps {
className?: string;
}
const SearchWidget = ({ className }: SearchWidgetProps) => {
const navigate = useNavigate();
const ref = useRef<HTMLInputElement>(null);
const location = useLocation() as Location & {
state: { from: string | undefined };
};
const currentPath = useRef<string>(location.pathname);
const isSearchPage = searchPageRegex.test(location.pathname);
const { state } = useLocalState();
const { organisationId } = useParams();
const [fromPath, setFromPath] = useState<string>();
useEffect(() => {
if (searchPageRegex.test(currentPath.current) && !isSearchPage) {
setFromPath(undefined);
} else if (location.state?.from) {
setFromPath(location.state.from);
}
currentPath.current = location.pathname;
}, [location.pathname]);
const onChange = () => {
if (ref?.current?.value === '') {
if (fromPath) {
navigate(fromPath);
} else {
navigate('..');
}
}
};
const onKeyPress: KeyboardEventHandler<HTMLInputElement> = (event) => {
if (event.key == 'Enter' && ref.current?.value.trim()) {
const state = isSearchPage ? undefined : { from: location };
navigate(`/org/${organisationId}/search?q=${ref.current.value.trim()}`, {
state
});
}
};
return (
<div className={`relative h-[42px] ${className}`}>
<SearchIcon className="absolute left-2 m-2 h-6 w-6 stroke-1" />
<input
ref={ref}
type="text"
name="search"
aria-label="Search"
defaultValue={state.q as string}
title="Search"
placeholder="Search ref. or end-to-end id"
className="h-full w-full rounded-lg border-none bg-white p-2.5 pl-12 shadow-plain hover:shadow-plain-lg focus:shadow-plain-lg focus:outline-0 focus:ring-0"
onKeyPress={onKeyPress}
onChange={onChange}
/>
</div>
);
};
export default SearchWidget;
</code></pre>
<p>I was thinking to use useEffect and useNavigate but not completely sure why it does not work and if it is the best approach. Any clues?</p>
| [
{
"answer_id": 74202142,
"author": "Timothy",
"author_id": 19185956,
"author_profile": "https://Stackoverflow.com/users/19185956",
"pm_score": 2,
"selected": true,
"text": "ngdart_cli"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19625670/"
] |
74,191,789 | <p>I'm a fairly basic android developer. I wrote a few apps for WearOS, nothing incredibly complex so far. A potential client wants me to develop an application for a custom device they have. Some sort of round screen the size of a kitchen watch (I don't have physical access to the device as it's remote work). At first I thought it would not be too hard as I have experience with wear devices. The thing is that I have absolutely no idea how to write an app for a custom device. They gave me several techical specs (exact screen size, Android version required, RAM, supported ABI (arm64-v8a), etc. But I only know how to build for predefined Android devices listed in Android Studio.</p>
<p>How am I supposed to handle such a project?</p>
<p>Some follow-up questions:</p>
<ul>
<li>Is it correct to say that their device runs a <strong>custom Android rom</strong>?</li>
<li>Let's say I start developping their product as if it was for a WearOS device (that's the closest from the list of predefined emulators). Am I right in assuming that eventually, once I know how to setup the proper build for their device, most of the code will remain the same, modulo some minor adptations?</li>
</ul>
| [
{
"answer_id": 74202142,
"author": "Timothy",
"author_id": 19185956,
"author_profile": "https://Stackoverflow.com/users/19185956",
"pm_score": 2,
"selected": true,
"text": "ngdart_cli"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9816072/"
] |
74,191,814 | <p>Find edges with NumPy 1D search in stencil like b&w image, e.g. <img src="https://i.stack.imgur.com/7a30P.jpg" alt="img" /></p>
<p>Not sure how to loop through 1D arrays to create a bool mask properly. Looked through quite a few numpy resources & stack which didn't cover explicitly this kind of basic operation.</p>
<p>Any tips appreciated.
Here's the pseudocode.</p>
<pre><code>#Pseudocode for 1D array search.
nrows, ncols = img.shape[:2]
nrows = nrows-1 #avoid index error
ncols = ncols-1
# i+1 pixel index wanted here
outedges_row = (img[nrows][i] == 0) & (img[nrows][i+1] == 255)
outedges_col = (img[ncols][i] == 0) & (img[ncols][i+1] == 255)
# i pixel index wanted here
inedges_row = (img[nrows][i] == 255) & (img[nrows][i+1] == 0)
inedges_col = (img[ncols][i] == 255) & (img[ncols][i+1] == 0)
# display outline of shapes
edges = np.unique(outedges_row & outedges_col & inedges_col & inedges_row)
img2 = np.copy(img)
img2[edges]
cv.imshow('',img2)
</code></pre>
<p>Even a very simple outline of the shape would be very valuable learning for my purposes.</p>
<p>Edit: Expected output
<img src="https://i.stack.imgur.com/tySUa.jpg" alt="enter image description here" /></p>
| [
{
"answer_id": 74192446,
"author": "Mateen Ulhaq",
"author_id": 365102,
"author_profile": "https://Stackoverflow.com/users/365102",
"pm_score": 0,
"selected": false,
"text": "# kernel: (-1, 1)\ndx = img[:, 1:] - img[:, :-1]\n"
}
] | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20280399/"
] |
74,191,830 | <p>I am able to exec into a pod , and in that pod i will also like to run a stolonctl command at the same time into the pod i just exec into. Here is an example of what i will like to achieve. I tried using the first command first and then tried to see if i write the second command if it will work based on the first but it didnt.</p>
<p><code>Special execution command ${cluster_name} kubectl exec -it pod -c container ${cluster_name} -- /bin/bash</code>
then in the bash i want to also run this
<code>stolonctl --cluster-name [cluster_name] --store-backend [store_backend] --store-endpoints kubernetes status</code>
i want to be able to achieve something like this in robot. be able to do something similar to ls in the pod</p>
<pre><code>controlplane $ kubectl run --image=nginx web --restart=Never
pod/web created
controlplane $ kubectl get po
NAME READY STATUS RESTARTS AGE
web 0/1 ContainerCreating 0 4s
controlplane $ kubectl exec -it web -- /bin/bash
root@web:/# ls
bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint.d etc lib media opt root sbin sys usr
</code></pre>
| [
{
"answer_id": 74192200,
"author": "SYN",
"author_id": 5607207,
"author_profile": "https://Stackoverflow.com/users/5607207",
"pm_score": 0,
"selected": false,
"text": "kubectl exec $pod -c $container -- \\\n stolonctl --custer-name $clustername and-any-other-options\n"
},
{
"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5539903/"
] |
74,191,848 | <pre class="lang-js prettyprint-override"><code>const queryMatch = {departureDate: {$gte: new Date(query.departureDateMin),$lte: new Date(query.departureDateMax)}};
const flightsByCriteria = await this.flightModel.find(queryMatch).exec();
</code></pre>
<p>The above request returns an empty table.
And yet I get data with mongodbCompass using <code>ISODate(dateString) </code> instead of <code>new Date(dateString)</code></p>
<p>I don't know where the problem lies in my request ?
Thank for your help.</p>
| [
{
"answer_id": 74192200,
"author": "SYN",
"author_id": 5607207,
"author_profile": "https://Stackoverflow.com/users/5607207",
"pm_score": 0,
"selected": false,
"text": "kubectl exec $pod -c $container -- \\\n stolonctl --custer-name $clustername and-any-other-options\n"
},
{
"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8788987/"
] |
74,191,854 | <p>I have a Test in Angular that looks like this. But it always fails because I cannot mock the MsalService correctly.</p>
<pre><code>export class MockedMsalService extends MsalService {}
describe('NavbarComponent', () => {
let component: NavbarComponent;
let fixture: ComponentFixture<NavbarComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [NavbarComponent],
imports: [
],
providers: [
{ provide: MsalService, useClass: MockedMsalService },
{ provide: Router, useClass: RouterMock },
{ provide: UsersService, useClass: UsersServiceMock },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(NavbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
</code></pre>
<p>When I try to run the test I get the error: <strong>NullInjectorError: R3InjectorError(DynamicTestModule)[MsalService -> InjectionToken MSAL_INSTANCE -> InjectionToken MSAL_INSTANCE]:
NullInjectorError: No provider for InjectionToken MSAL_INSTANCE!</strong></p>
<p>I would be very grateful if someone could help me further</p>
| [
{
"answer_id": 74192200,
"author": "SYN",
"author_id": 5607207,
"author_profile": "https://Stackoverflow.com/users/5607207",
"pm_score": 0,
"selected": false,
"text": "kubectl exec $pod -c $container -- \\\n stolonctl --custer-name $clustername and-any-other-options\n"
},
{
"... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9676335/"
] |
74,191,868 | <p>I'm trying to add a class to my bind however im getting an error on the "+ animation" its saying : is expected, how do i go about getting that class</p>
<pre><code>class="animation__placeholder"
:class="{
'animation__placeholder--' + animation,
'animation__placeholder--top':(alignment === 'top'),
'animation__placeholder--center':(alignment === 'center'),
'animation__placeholder--bottom':(alignment === 'bottom'),
'animation__placeholder--right':(side === 'right'),
'animation__placeholder--center':(side === 'center'),
'animation__placeholder--left':(side === 'left'),
}"
</code></pre>
| [
{
"answer_id": 74191976,
"author": "Amini",
"author_id": 15351296,
"author_profile": "https://Stackoverflow.com/users/15351296",
"pm_score": 2,
"selected": true,
"text": "new Vue({\n el: '#app',\n data() {\n return {\n animation: 'fade-out',\n alignment: 'center',\n s... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20328843/"
] |
74,191,891 | <p>Let's say I have a table like this:</p>
<pre><code> id | amount
-------------------------
1 | 10
1 | 10
2 | 20
2 | 10
3 | 20
3 | 10
3 | 10
4 | 10
</code></pre>
<p>Let's say id <strong>1</strong> and <strong>2</strong> are special, I want to group them together and name it as <strong>special</strong>. Ids that are other than <strong>1</strong> and <strong>2</strong> should also not be grouped together. Lastly, I want to sum the amount. So, how to I get the result like this:</p>
<pre><code> type | total_amount
-------------------------------
special | 50
3 | 40
4 | 10
</code></pre>
| [
{
"answer_id": 74191970,
"author": "Aleix CC",
"author_id": 11532919,
"author_profile": "https://Stackoverflow.com/users/11532919",
"pm_score": 4,
"selected": true,
"text": "case when"
},
{
"answer_id": 74192099,
"author": "Josua Marcel C",
"author_id": 1562112,
"auth... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10479197/"
] |
74,191,906 | <p>Once a screen share is started by "navigator.mediaDevices.getDisplayMedia()" and confirmed by user, there is a posibility in each browser to stop a screen share (for example Chrome - see pic).
<a href="https://i.stack.imgur.com/9XKPe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9XKPe.png" alt="enter image description here" /></a></p>
<p>How to attach a javascript handler on the event, when a screen share is stopped by this browser button?</p>
| [
{
"answer_id": 74191970,
"author": "Aleix CC",
"author_id": 11532919,
"author_profile": "https://Stackoverflow.com/users/11532919",
"pm_score": 4,
"selected": true,
"text": "case when"
},
{
"answer_id": 74192099,
"author": "Josua Marcel C",
"author_id": 1562112,
"auth... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1322616/"
] |
74,191,917 | <p>In my Cypress e2e tests I need to work with lots of files (some of them are heavy). I cannot just add them manually to fixtures folder and to push them to git (it will use all repository space).</p>
<p>So I have a server for files to store. With Selenium I could just use an absolute network path to get an access to a file. As I understand, in Cypress I cannot use an absolute network path, I need to add a file to fixtures folder to work with it.</p>
<p>So how do I transfer files from my server to Cypress fixtures folder?</p>
| [
{
"answer_id": 74193160,
"author": "Matthieu Mabillard",
"author_id": 4222551,
"author_profile": "https://Stackoverflow.com/users/4222551",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('loadMyFixtures', (filePath) => {\n cy.request({\n method: 'POST',\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4019586/"
] |
74,191,924 | <p><code>['0011111', '0011101', '0011110', '0011110', '0011100', '0010111', '0011000', '0011011', '0011000', '0010001', '0010100', '0010111', '0010110', '0010010', '0001110', '0001110', '0001010', '0001111', '0000111', '0001001', '0000101', '0001000', '0000100', '1000001']</code></p>
<p>Hi newbie here, how can I change the first index string value "1" in the List, example "1000001" to "0000001". Thanks for solution</p>
| [
{
"answer_id": 74193160,
"author": "Matthieu Mabillard",
"author_id": 4222551,
"author_profile": "https://Stackoverflow.com/users/4222551",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('loadMyFixtures', (filePath) => {\n cy.request({\n method: 'POST',\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8736196/"
] |
74,191,981 | <p>I am using Java, Spring and JPA and cannot get cascade deletion to work.</p>
<p>I have a class Tenant that looks like this</p>
<pre><code>@Entity
@Validated
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TenantConstraints
public class Tenant {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tenant_gen")
@SequenceGenerator(name="tenant_gen", sequenceName="tenant_seq", allocationSize=1)
@JsonProperty("id")
private Long id = null;
@JsonIgnore
@OneToMany(mappedBy = "tenant", fetch = FetchType.EAGER)
private List<DeploymentStep> deploymentSteps = new ArrayList();
...
}
</code></pre>
<p>My DeploymentStep class looks like this:</p>
<pre><code>@Entity
@Validated
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeploymentStep {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "deployment_step_gen")
@SequenceGenerator(name="deployment_step_gen", sequenceName="deployment_step_seq", allocationSize=1)
@JsonProperty("id")
private Long id = null;
@ManyToOne(cascade = CascadeType.ALL)
@JsonIgnore
private Tenant tenant = null;
...
}
</code></pre>
<p>I have a repository class that looks like this</p>
<pre><code>public interface TenantRepository extends JpaRepository<Tenant, Long> {
...
}
</code></pre>
<p>When I call the built-in delete method on this repository like so <code>tenantRepository.delete(tenantId)</code> and I have deployment steps for the particular tenant I'm deleting, the delete fails.</p>
<p>In my postgres database I have a cascade constraint set</p>
<pre><code>ALTER TABLE public.deployment_step
DROP CONSTRAINT tenant_fkey
, ADD CONSTRAINT tenant_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenant(id) ON DELETE CASCADE;
</code></pre>
<p>When I delete the tenant that has deployment steps using a database query manually, the tenant and all deploymentsteps get deleted without any issue.</p>
<p>What am I doing wrong in the code?</p>
| [
{
"answer_id": 74193160,
"author": "Matthieu Mabillard",
"author_id": 4222551,
"author_profile": "https://Stackoverflow.com/users/4222551",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('loadMyFixtures', (filePath) => {\n cy.request({\n method: 'POST',\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/991788/"
] |
74,191,988 | <p>I was trying to find cross join of two set. I am currently doing the code below:</p>
<pre><code>import itertools
a={1,2,3}
b={4,5,6}
itertools.product(a,b)
list(itertools.product(a,b))
itertools.product(b,a)
list(itertools.product(b,a))
</code></pre>
<p>Is there any other way to find out all possible cross join in a single code? and i need to convert the output to data frame?</p>
| [
{
"answer_id": 74193160,
"author": "Matthieu Mabillard",
"author_id": 4222551,
"author_profile": "https://Stackoverflow.com/users/4222551",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('loadMyFixtures', (filePath) => {\n cy.request({\n method: 'POST',\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20113351/"
] |
74,191,990 | <p>Please help me to know, how to commit server and client folder.
I started a new project. And i want to write back-end node-js, and front-end react-js.
I created 2 folders "client" for react, and "server" for node. I have two terminals for node and for react.
When i want to commit, git says that i have ../client folder. But i want to commit it separately.
If i'll commit it together i have to go to root folder and create third .env file, because node_modules not ignored in clients folder.</p>
<p>I need your help, maybe this question is easy, but for me this issue very heavy. I can't understand how can i do it.</p>
| [
{
"answer_id": 74193160,
"author": "Matthieu Mabillard",
"author_id": 4222551,
"author_profile": "https://Stackoverflow.com/users/4222551",
"pm_score": 1,
"selected": false,
"text": "Cypress.Commands.add('loadMyFixtures', (filePath) => {\n cy.request({\n method: 'POST',\n ... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74191990",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19213826/"
] |
74,192,016 | <p>Wondering if testing of a relations in Rails widely considered to be a best practice or not.
We have disagreement on the team on testing relations.</p>
<p>IMO it's redundant, i.e. to have each <code>has_many :people</code> to be tested with <code>should have_many(:people)</code> as it looks repetitive, just copy-paste from model to a test - i.e. I cannot imagine it stop working or some other workflow break it, the only way to break it - is just remove or change the line (but if someone just changing code randomly that someone can also just remove the test as well). Moreover it doesn't actually test relation (like if Company returns people who have appropriate <code>company_id</code> and if company destroyed - people are actually destroyed - as it can actually fail in case of destroy validation or foreign key) but it just test that relation is specified.
And we don't test like that class respond to every single method but if we do test - we test what method does.</p>
<p>As we don't test other static things, like templates (like simple HTML with no logic) - we assume rails will generate specified HTML, it's impossible to break unless someone just change it.</p>
<p>At the other hand there is an argument can be made that relations are extremely important part of the app and in effort to have 100% coverage that also should be tested.</p>
<p>Usually in case of disagreements we look to best practices but I cannot find any mention of relation tests - neither to do it or not.</p>
<p>Can you please help me to find out is it common practice or not. (links to best practices that says about that or similar thing or your experience working with those)</p>
<p>Thank you in advance</p>
| [
{
"answer_id": 74193249,
"author": "Leon",
"author_id": 18737438,
"author_profile": "https://Stackoverflow.com/users/18737438",
"pm_score": -1,
"selected": false,
"text": "has_many"
},
{
"answer_id": 74195850,
"author": "BenFenner",
"author_id": 14837782,
"author_prof... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74192016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6060322/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.