qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,432,148 | <p>Can somebody explain to me what's the difference between the variables in <code>:root</code> and the variables above it please?</p>
<p>Why can't we just use one syntax (either with <code>&</code> or <code>--</code>) or just put the <code>$primary</code> and <code>$secondary</code> in <code>:root{...}</code> ?</p>
<pre><code>$primary: #ffcc00;
$secondary: #4b4b4b;
:root{
--data-color-primary: #{$primary};
--data-color-secondary: #{$secondary};
}
</code></pre>
| [
{
"answer_id": 74432397,
"author": "Jaswinder Kaur",
"author_id": 15258737,
"author_profile": "https://Stackoverflow.com/users/15258737",
"pm_score": 2,
"selected": true,
"text": "ss-go-top {\n z-index: 2;\n opacity: 0;\n border: 2px;\n border-style: solid;\n border-radius: 50%;\n border-color: #07b8b5;\n visibility: hidden;\n -webkit-transform: translate3d(0, 200%, 0);\n transform: translate3d(0, 200%, 0);\n -webkit-transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);\n transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);\n position: fixed;\n bottom: 8.4rem;\n right: 4rem;\n}\n.ss-go-top a:hover svg, .ss-go-top a:hover svg path {\n fill: #fff;\n}\n.ss-go-top a {\n text-decoration: none;\n border: 2px;\n display: block;\n height: 6.4rem;\n width: 6.4rem;\n border-radius: 50%;\n background-color: transparent;\n -webkit-transition: all .3s;\n transition: all .3s;\n position: relative;\n}\n\n.ss-go-top a:hover,\n.ss-go-top a:focus {\n background-color: #07b8b5;\n}\n\n.ss-go-top svg {\n height: 1.2rem;\n width: 1.2rem;\n position: absolute;\n -webkit-transform: translate3d(-50%, -50%, 0);\n transform: translate3d(-50%, -50%, 0);\n left: 50%;\n top: 50%;\n}\n\n.ss-go-top svg path {\n fill: #07b8b5;\n}\n\n.ss-go-top.link-is-visible {\n opacity: 1;\n visibility: visible;\n -webkit-transform: translate3d(0, 0, 0);\n transform: translate3d(0, 0, 0);\n}\n "
},
{
"answer_id": 74432450,
"author": "matt lost",
"author_id": 20381102,
"author_profile": "https://Stackoverflow.com/users/20381102",
"pm_score": -1,
"selected": false,
"text": ".ss-go-top:hover .smoothscroll{background: #07b8b5;}\n.ss-go-top:hover .smoothscroll svg path {fill: #fff;}\n"
},
{
"answer_id": 74432570,
"author": "tfernandez",
"author_id": 20500972,
"author_profile": "https://Stackoverflow.com/users/20500972",
"pm_score": 1,
"selected": false,
"text": " .smoothscroll {\n background-color: transparent;\n display: grid;\n place-items: center;\n width: 100px;\n height: 100px;\n border-radius: 50%;\n }\n .smoothscroll svg {\n fill: #07b8b5;\n background-color: transparent;\n }\n\n .smoothscroll:hover {\n background-color: #07b8b5;\n }\n .smoothscroll:hover svg {\n fill: #ffffff;\n }"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18631280/"
] |
74,432,192 | <p>I have two buttons validate and notify as shown in the below image in XML.</p>
<p><a href="https://i.stack.imgur.com/eVjcj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eVjcj.png" alt="enter image description here" /></a></p>
<p>I want to show validate button below notify button programmatically. as shown in the below image</p>
<p><a href="https://i.stack.imgur.com/rGEPB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rGEPB.png" alt="enter image description here" /></a></p>
<p>I have implemented kotlin code and code sniped mentioned below:</p>
<pre><code>
fun changeConstraint() {
val valetBtnParent = binding.root.findViewById<ConstraintLayout>(R.id.childLayout)
ConstraintSet().apply {
val layoutParams = ConstraintLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT)
clone(valetBtnParent)
clear(R.id.button_validate, ConstraintSet.END)
clear(R.id.button_validate, ConstraintSet.BOTTOM)
clear(R.id.button_validate, ConstraintSet.START)
connect(R.id.button_validate, ConstraintSet.BOTTOM, R.id.detail_cardview, ConstraintSet.TOP, ZERO)
connect(R.id.button_validate, ConstraintSet.END, R.id.detail_cardview, ConstraintSet.END, ZERO)
connect(R.id.button_validate, ConstraintSet.START, R.id.button_notify, ConstraintSet.BOTTOM, TWO_HUNDRED)
applyTo(childLayout)
}
}
</code></pre>
<p>Please Help me!!!!</p>
| [
{
"answer_id": 74432397,
"author": "Jaswinder Kaur",
"author_id": 15258737,
"author_profile": "https://Stackoverflow.com/users/15258737",
"pm_score": 2,
"selected": true,
"text": "ss-go-top {\n z-index: 2;\n opacity: 0;\n border: 2px;\n border-style: solid;\n border-radius: 50%;\n border-color: #07b8b5;\n visibility: hidden;\n -webkit-transform: translate3d(0, 200%, 0);\n transform: translate3d(0, 200%, 0);\n -webkit-transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);\n transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);\n position: fixed;\n bottom: 8.4rem;\n right: 4rem;\n}\n.ss-go-top a:hover svg, .ss-go-top a:hover svg path {\n fill: #fff;\n}\n.ss-go-top a {\n text-decoration: none;\n border: 2px;\n display: block;\n height: 6.4rem;\n width: 6.4rem;\n border-radius: 50%;\n background-color: transparent;\n -webkit-transition: all .3s;\n transition: all .3s;\n position: relative;\n}\n\n.ss-go-top a:hover,\n.ss-go-top a:focus {\n background-color: #07b8b5;\n}\n\n.ss-go-top svg {\n height: 1.2rem;\n width: 1.2rem;\n position: absolute;\n -webkit-transform: translate3d(-50%, -50%, 0);\n transform: translate3d(-50%, -50%, 0);\n left: 50%;\n top: 50%;\n}\n\n.ss-go-top svg path {\n fill: #07b8b5;\n}\n\n.ss-go-top.link-is-visible {\n opacity: 1;\n visibility: visible;\n -webkit-transform: translate3d(0, 0, 0);\n transform: translate3d(0, 0, 0);\n}\n "
},
{
"answer_id": 74432450,
"author": "matt lost",
"author_id": 20381102,
"author_profile": "https://Stackoverflow.com/users/20381102",
"pm_score": -1,
"selected": false,
"text": ".ss-go-top:hover .smoothscroll{background: #07b8b5;}\n.ss-go-top:hover .smoothscroll svg path {fill: #fff;}\n"
},
{
"answer_id": 74432570,
"author": "tfernandez",
"author_id": 20500972,
"author_profile": "https://Stackoverflow.com/users/20500972",
"pm_score": 1,
"selected": false,
"text": " .smoothscroll {\n background-color: transparent;\n display: grid;\n place-items: center;\n width: 100px;\n height: 100px;\n border-radius: 50%;\n }\n .smoothscroll svg {\n fill: #07b8b5;\n background-color: transparent;\n }\n\n .smoothscroll:hover {\n background-color: #07b8b5;\n }\n .smoothscroll:hover svg {\n fill: #ffffff;\n }"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20500768/"
] |
74,432,275 | <p>I am trying to deploy cloudformation stack into a cross-account account. However, when i am deploying the cloudfromation.yml file i am getting the following below error. I have even tried using cloudformation.yaml but same error.</p>
<p>However, when i try to create S3 bucket, the bucket is created without any problem. the issue only arises when doing lambda deployment</p>
<pre><code>Waiting for changeset to be created..
Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state:
For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworldpython3] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.
</code></pre>
<p>Here is my cloudformation.yml file that i have got, which is deploying a simple lambda function. I have even tried using cloudformation.yaml but i get the same error</p>
<pre><code>AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: A starter AWS Lambda function.
Resources:
helloworldpython3:
Type: "AWS::Serverless::Function"
Properties:
Handler: lambda_function.lambda_handler
Runtime: python3.6
CodeUri: ./lambda
Description: 'Lambda function for CD Demo'
MemorySize: 128
Timeout: 30
</code></pre>
<p>Here is my buildspec.yml file that i have got setup</p>
<pre><code>version: 0.2
phases:
install:
commands:
- echo $CROSS_ACCOUNT_ROLE
- echo $TARGET_ACCOUNT_ID
- cd $CODEBUILD_SRC_DIR
- chmod +x cross-account-setup.sh
build:
commands:
- echo "Start Deploy"
- cd $CODEBUILD_SRC_DIR
- . ./cross-account-setup.sh
- >
aws cloudformation deploy --stack-name amr-manual-deployment-cicd --template-file cloudformation-stack.yml --no-fail-on-empty-changeset
- echo "End Deploy"
</code></pre>
<p>What changes do i need to make in the .yml file in oder to deploy the cloud-formation stack successfully.</p>
<p>Thank you</p>
| [
{
"answer_id": 74441141,
"author": "user11666461",
"author_id": 11666461,
"author_profile": "https://Stackoverflow.com/users/11666461",
"pm_score": 2,
"selected": true,
"text": "AWS::Serverless::Function"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570179/"
] |
74,432,287 | <p>I have a dataset which is similar to below one. Please note that there are multiple values for a single ID.</p>
<pre><code>import pandas as pd
import numpy as np
import random
df = pd.DataFrame({'DATE_TIME':pd.date_range('2022-11-01', '2022-11-05 23:00:00',freq='h'),
'SBP':[random.uniform(110, 160) for n in range(120)],
'DBP':[random.uniform(60, 100) for n in range(120)],
'ID':[random.randrange(1, 100) for n in range(120)],
'TIMEINTERVAL':[random.randrange(1, 200) for n in range(120)]})
df['VISIT'] = df['DATE_TIME'].dt.day
df['MODE'] = np.select([df['VISIT']==1, df['VISIT'].isin([2,3])], ['New', 'InProgress'], 'Done')
</code></pre>
<p>I use the following DASH code to make slider:</p>
<pre><code>app = Dash(__name__)
app.layout = html.Div([
html.H4('Interactive Scatter Plot with ABPM dataset'),
dcc.Graph(id="scatter-plot"),
html.P("Filter by time interval:"),
dcc.Dropdown(df.ID.unique(), id='pandas-dropdown-1'), # for choosing ID,
dcc.RangeSlider(
id='range-slider',
min=0, max=600, step=10,
marks={0: '0', 50: '50', 100: '100', 150: '150', 200: '200', 250: '250', 300: '300', 350: '350', 400: '400', 450: '450', 500: '500', 550: '550', 600: '600'},
value=[0, 600]
),
html.Div(id='dd-output-container')
])
@app.callback(
Output("scatter-plot", "figure"),
Input("pandas-dropdown-1", "value"),
Input("range-slider", "value"),
prevent_initial_call=True)
def update_bar_chart(value,slider_range):
low, high = slider_range
df1 = df.query("ID == @value & TIMEINTERVAL > @low & TIMEINTERVAL < @high").copy()
if df1.shape[0] != 0:
fig = px.scatter(df1, x="DATE_TIME", y=["SBP","DBP"],
hover_data=['TIMEINTERVAL'],facet_col='VISIT',
facet_col_wrap=2,
symbol='MODE')
fig.update_xaxes(matches= None, showticklabels=True)
return fig
else:
return dash.no_update
app.run_server(debug=True, use_reloader=False)
</code></pre>
<p>If df1 Visit column has value more than 1, then I would like to annotate subplots with arrow to articulate reading. To do so, I wrote the followings cript in update_bar_charts function, but it did not compile.</p>
<pre><code>def update_bar_chart(value,slider_range):
low, high = slider_range
df1 = df.query("ID == @value & TIMEINTERVAL > @low & TIMEINTERVAL < @high").copy()
if df1.shape[0] != 0:
fig = px.scatter(df1, x="DATE_TIME", y=["SBP","DBP"],
hover_data=['TIMEINTERVAL'],facet_col='VISIT',
facet_col_wrap=2,
symbol='MODE')
fig.update_xaxes(matches= None, showticklabels=True)
if df1.VISIT!=1:
fig.add_annotation(
xref="x domain",
yref="y domain",
# The arrow head will be 25% along the x axis, starting from the left
x=0.25,
# The arrow head will be 40% along the y axis, starting from the bottom
y=0.4,
arrowhead=2,
)
return fig
else:
return dash.no_update
app.run_server(debug=True, use_reloader=False)
</code></pre>
<p>What I have is<a href="https://i.stack.imgur.com/CnUPG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CnUPG.png" alt="enter image description here" /></a>:</p>
<p>Whan I want to achieve is:</p>
<p><a href="https://i.stack.imgur.com/GOSeA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GOSeA.png" alt="enter image description here" /></a></p>
<p>How can I add those arrows to make reading the plots easier? Number of arrows should change dynamically because each ID has different number of visits.</p>
| [
{
"answer_id": 74441141,
"author": "user11666461",
"author_id": 11666461,
"author_profile": "https://Stackoverflow.com/users/11666461",
"pm_score": 2,
"selected": true,
"text": "AWS::Serverless::Function"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19948301/"
] |
74,432,313 | <p>I'm fairly new to custom form controls in Angular and have been struggling with setting required fields while using a mat-stepper. I am trying to make a reusable address template. I've set required in both HTML and Ts but when I click on the <code>next</code> button it moves to the next stepper. Any suggestions would be greatly appreciated.</p>
<h1>Address Class Model</h1>
<pre><code>export declare class Address {
unitNumber: string;
streetName: string;
suburb: string;
city: string;
province: string;
postalCode: string;
}
</code></pre>
<h1>Address TS</h1>
<pre><code>import { Component, ElementRef, HostBinding, Inject,
Input, OnDestroy, Optional, Self } from '@angular/core';
import { ControlValueAccessor, NgControl } from '@angular/forms';
import { Address, Helper, SelectOption } from '@trade-up/common';
import { Subject } from 'rxjs';
import { MatFormField, MatFormFieldControl, MAT_FORM_FIELD } from '@angular/material/form-field';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
@Component({
selector: 'app-address-form',
templateUrl: './address-form.component.html',
styleUrls: ['./address-form.component.scss'],
providers: [
{provide: MatFormFieldControl, useExisting: AddressFormComponent}
]
})
export class AddressFormComponent implements OnDestroy, ControlValueAccessor, MatFormFieldControl<Address> {
@HostBinding('attr.id')
externalId: string;
@HostBinding('class.floating')
get shouldLabelFloat(): boolean {
return this.focused || !this.empty;
}
@HostBinding('class.invalid')
get valid(): boolean {
return this.touched;
}
@Input()
set id(value: string) {
this._ID = value;
this.externalId = null;
}
get id(): string {
return this._ID;
}
provinces: SelectOption[] = Helper.provinces;
address: Address;
stateChanges = new Subject<void>();
/*tslint:disable-next-line*/
private _ID: string;
/*tslint:disable-next-line*/
private _placeholder: string;
/*tslint:disable-next-line*/
private _required: boolean;
/*tslint:disable-next-line*/
private _disabled: boolean;
focused: boolean;
errorState: boolean;
controlType?: string;
autofilled?: boolean;
userAriaDescribedBy?: string;
touched: boolean;
get empty(): boolean {
return !this.address.unitNumber && !this.address.streetName && !this.address.suburb
&& !this.address.province && !this.address.city && !this.address.postalCode;
}
@Input()
get placeholder(): string {
return this._placeholder;
}
set placeholder(plh) {
this._placeholder = plh;
this.stateChanges.next();
}
@Input()
get required(): boolean {
return this._required;
}
set required(req) {
this._required = coerceBooleanProperty(req);
this.stateChanges.next();
}
@Input()
get disabled(): boolean {
return this._disabled;
}
set disabled(dis) {
this._disabled = coerceBooleanProperty(dis);
this.stateChanges.next();
}
onChange = () => {};
onTouched = () => {};
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
writeValue(add: Address): void {
this.address = add;
}
get value(): Address {
return this.address;
}
set value(add: Address) {
this.address = add;
this.stateChanges.next();
}
setDescribedByIds(ids: string[]): void {
this.userAriaDescribedBy = ids.join(' ');
}
onContainerClick(): void {
}
ngOnDestroy(): void {
this.stateChanges.complete();
}
/*tslint:disable-next-line*/
constructor(@Optional() @Self() public ngControl: NgControl, @Optional() @Inject(MAT_FORM_FIELD) public _formField: MatFormField,
/*tslint:disable-next-line*/
private _elementRef: ElementRef<HTMLElement>) {
if (ngControl !== null) {
ngControl.valueAccessor = this;
}
this.address = new Address();
}
}
</code></pre>
<h1>Address Html</h1>
<pre><code><div role="group" class="input-container"
[class.invalid]="valid"
[attr.aria-labelledby]="_formField?.getLabelId()">
<mat-form-field>
<mat-label>Unit Number</mat-label>
<input matInput
[(ngModel)]="address.unitNumber"
[class.invalid]="valid"
type="text"
maxlength="5"
required>
</mat-form-field>
<br>
<mat-form-field>
<input matInput
[(ngModel)]="address.streetName"
[class.invalid]="valid"
type="text"
placeholder="Street Name"
maxLength="45"
required>
</mat-form-field>
<br>
<mat-form-field>
<input matInput
[(ngModel)]="address.suburb"
[class.invalid]="valid"
type="text"
placeholder="Suburb"
maxLength="45"
required>
</mat-form-field>
<br>
<mat-form-field>
<mat-label>Province</mat-label>
<mat-select placeholder="Province"
[(ngModel)]="address.province"
[class.invalid]="valid"
required>
<mat-option *ngFor="let province of provinces" [value]="province.value">
{{province.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<br>
<mat-form-field>
<input matInput
type="text"
[(ngModel)]="address.city"
[class.invalid]="valid"
placeholder="City"
maxLength="45"
required>
</mat-form-field>
<br>
<mat-form-field>
<input matInput
type="text"
[(ngModel)]="address.postalCode"
[class.invalid]="valid"
placeholder="Postal Code"
maxlength="4"
pattern="[0-9]*"
required>
</mat-form-field>
</div>
</code></pre>
<h1>Collection Address TS</h1>
<pre><code> this.homeCollectionForm = this.formBuilder.group({
homeAddress: [new Address(), Validators.required],
});
</code></pre>
<h1>Collection Address HTML</h1>
<pre><code><mat-horizontal-stepper linear="true">
<mat-step [stepControl]="homeCollectionForm">
<form [formGroup]="homeCollectionForm">
<mat-card>
<mat-card-content>
<mat-form-field class="mat-form-field-center">
<app-address-form formControlName="homeAddress" required></app-address-form>
</mat-form-field>
<button
mat-raised-button
matStepperNext
color="warn">
Next
</button>
</mat-card-content>
</mat-card>
</form>
</mat-step>
</mat-horizontal-stepper>
</code></pre>
| [
{
"answer_id": 74441141,
"author": "user11666461",
"author_id": 11666461,
"author_profile": "https://Stackoverflow.com/users/11666461",
"pm_score": 2,
"selected": true,
"text": "AWS::Serverless::Function"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20041772/"
] |
74,432,330 | <p>I have a customized Hook to change the state of the of a use state variable from true to false, and i want to change it on the onclick of a button to show and hide a div, how can this be done?</p>
<pre><code>import { useEffect, useState } from 'react';
export const useOpenFiltersHook = (): boolean => {
const [showFilter, setShowFilter] = useState(false);
useEffect(() => {
function handleShowFilter(): void {
setShowFilter(true);
}
window.addEventListener('resize', handleShowFilter);
handleShowFilter();
return () => window.removeEventListener('resize', handleShowFilter);
}, []);
return showFilter;
};
</code></pre>
<pre><code> const showFilter = useOpenFiltersHook();
{showFilter && (
<div>
<button onClick={() => !showFilter}>
<div>Show filter</div>
</button>
</div>
)}
</code></pre>
| [
{
"answer_id": 74432409,
"author": "Markus",
"author_id": 321492,
"author_profile": "https://Stackoverflow.com/users/321492",
"pm_score": 0,
"selected": false,
"text": "setShowFilter"
},
{
"answer_id": 74432420,
"author": "Bikas Lin",
"author_id": 17582798,
"author_profile": "https://Stackoverflow.com/users/17582798",
"pm_score": 2,
"selected": true,
"text": "import React, { useEffect, useState } from 'react';\n\ntype TOpenFilterHook = {\n showFilter: boolean;\n setShowFilter: any;\n}\n\nexport const useOpenFiltersHook = (): TOpenFilterHook => {\n const [showFilter, setShowFilter] = useState(false);\n\n useEffect(() => {\n function handleShowFilter(): void {\n setShowFilter(true);\n }\n\n window.addEventListener('resize', handleShowFilter);\n handleShowFilter();\n\n return () => window.removeEventListener('resize', handleShowFilter);\n }, []);\n return { showFilter, setShowFilter };\n};\n\n\n... ... ...\n\nconst { showFilter, setShowFilter } = useOpenFiltersHook();\n {showFilter && (\n <div>\n <button onClick={() => setShowFilter(false)}>\n <div>Show filter</div>\n </button>\n </div>\n )}\n"
},
{
"answer_id": 74432449,
"author": "Naveen",
"author_id": 16260451,
"author_profile": "https://Stackoverflow.com/users/16260451",
"pm_score": -1,
"selected": false,
"text": " <button onClick={() => !showFilter}>\n"
},
{
"answer_id": 74433090,
"author": "Oleg Brazhnichenko",
"author_id": 7028321,
"author_profile": "https://Stackoverflow.com/users/7028321",
"pm_score": 0,
"selected": false,
"text": "import { useEffect, useState } from 'react';\n\nexport const useOpenFiltersHook = (isOpened): boolean => {\n const [showFilter, setShowFilter] = useState(isOpened);\n\n function handleShowFilter(): void {\n setShowFilter(true);\n }\n\n useEffect(() => {\n window.addEventListener('resize', handleShowFilter);\n\n return () => window.removeEventListener('resize', handleShowFilter);\n }, []);\n return { showFilter, setShowFilter };\n};\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18892774/"
] |
74,432,359 | <p>I have an JaxRS API like this :</p>
<pre><code>@GET
@Path("list")
public Response list(@QueryParam("id") Long id) {
...
}
</code></pre>
<p>How can i handle exception when send non digits parameter as id ?<br />
actually i can not found any validation annotation on JakartaEE framework for handle this problem .<br />
example request :</p>
<pre><code>curl http://localhost:8080/api/list?id=ABCD
</code></pre>
<p><strong>NOTE:</strong> I won't change Long to String .</p>
| [
{
"answer_id": 74432409,
"author": "Markus",
"author_id": 321492,
"author_profile": "https://Stackoverflow.com/users/321492",
"pm_score": 0,
"selected": false,
"text": "setShowFilter"
},
{
"answer_id": 74432420,
"author": "Bikas Lin",
"author_id": 17582798,
"author_profile": "https://Stackoverflow.com/users/17582798",
"pm_score": 2,
"selected": true,
"text": "import React, { useEffect, useState } from 'react';\n\ntype TOpenFilterHook = {\n showFilter: boolean;\n setShowFilter: any;\n}\n\nexport const useOpenFiltersHook = (): TOpenFilterHook => {\n const [showFilter, setShowFilter] = useState(false);\n\n useEffect(() => {\n function handleShowFilter(): void {\n setShowFilter(true);\n }\n\n window.addEventListener('resize', handleShowFilter);\n handleShowFilter();\n\n return () => window.removeEventListener('resize', handleShowFilter);\n }, []);\n return { showFilter, setShowFilter };\n};\n\n\n... ... ...\n\nconst { showFilter, setShowFilter } = useOpenFiltersHook();\n {showFilter && (\n <div>\n <button onClick={() => setShowFilter(false)}>\n <div>Show filter</div>\n </button>\n </div>\n )}\n"
},
{
"answer_id": 74432449,
"author": "Naveen",
"author_id": 16260451,
"author_profile": "https://Stackoverflow.com/users/16260451",
"pm_score": -1,
"selected": false,
"text": " <button onClick={() => !showFilter}>\n"
},
{
"answer_id": 74433090,
"author": "Oleg Brazhnichenko",
"author_id": 7028321,
"author_profile": "https://Stackoverflow.com/users/7028321",
"pm_score": 0,
"selected": false,
"text": "import { useEffect, useState } from 'react';\n\nexport const useOpenFiltersHook = (isOpened): boolean => {\n const [showFilter, setShowFilter] = useState(isOpened);\n\n function handleShowFilter(): void {\n setShowFilter(true);\n }\n\n useEffect(() => {\n window.addEventListener('resize', handleShowFilter);\n\n return () => window.removeEventListener('resize', handleShowFilter);\n }, []);\n return { showFilter, setShowFilter };\n};\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1319938/"
] |
74,432,370 | <p>I have my data:</p>
<pre class="lang-r prettyprint-override"><code>x <- list(10,50,100,250,500,2500)
y <- list(0.09090909,0.01960784,0.003984064,0.003984064,0.001996008,0.0003998401)
</code></pre>
<p>I want to link my data to code found on this website</p>
<pre class="lang-r prettyprint-override"><code>log_c <- seq(-12, 0, by = 0.1)
df <- data.frame(log_c = log_c, response = V(log_c, E, HS, log_EC50))
ggplot(df, aes(log_c, response)) +
geom_line()
</code></pre>
<p><img src="https://i.stack.imgur.com/oNAMK.png" alt="enter image description here" /></p>
<p>I want to put the x data in place of log_c and y data in place of response. These are my beginnings in R, so I am asking for help</p>
| [
{
"answer_id": 74432475,
"author": "Ben Bolker",
"author_id": 190277,
"author_profile": "https://Stackoverflow.com/users/190277",
"pm_score": 3,
"selected": false,
"text": "c()"
},
{
"answer_id": 74433042,
"author": "TarJae",
"author_id": 13321647,
"author_profile": "https://Stackoverflow.com/users/13321647",
"pm_score": 2,
"selected": true,
"text": "library(tidyverse)\n\ntibble(x,y) %>% \n unnest() %>% \n ggplot(aes(x, y))+\n geom_line()\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20466352/"
] |
74,432,401 | <p>I have imported a CSV containing dates in the column "Activity_Date_Minute". The date value for example is "04/12/2016 01:12:00". Now when I read the .csv into a dataframe and extract only the date this gives me date in the column as 4-12-20. Can someone help how to get the date in mm-dd-yyyy in a separate column?</p>
<p>Tried the below code. Was expecting to see a column with dates e.g 04/12/2016 (mm/dd/yyyy).</p>
<pre><code>#Installing packages
install.packages("tidyverse")
library(tidyverse)
install.packages('ggplot2')
library(ggplot2)
install.packages("dplyr")
library(dplyr)
install.packages("lubridate")
library(lubridate)
##Installing packages
install.packages("tidyverse")
library(tidyverse)
install.packages('ggplot2')
library(ggplot2)
install.packages("dplyr")
library(dplyr)
install.packages("lubridate")
library(lubridate)
##Reading minute-wise METs into "minutewiseMET_Records" and summarizing MET per day for all the IDs
minutewiseMET_Records <- read.csv("minuteMETsNarrow_merged.csv")
str(minutewiseMET_Records)
## converting column ID to character,Activity_Date_Minute to date
minutewiseMET_Records$Id <- as.character(minutewiseMET_Records$Id)
minutewiseMET_Records$Date <- as.Date(minutewiseMET_Records$Activity_Date_Minute)
str(minutewiseMET_Records)
</code></pre>
<p><strong>The Console is as follows:</strong></p>
<pre><code>> minutewiseMET_Records <- read.csv("minuteMETsNarrow_merged.csv")
> str(minutewiseMET_Records)
'data.frame': 1048575 obs. of 3 variables:
$ Id : num 1.5e+09 1.5e+09 1.5e+09 1.5e+09 1.5e+09 ...
$ Activity_Date_Minute: chr "04/12/2016 00:00" "04/12/2016 00:01" "04/12/2016 00:02" "04/12/2016 00:03" ...
$ METs : int 10 10 10 10 10 12 12 12 12 12 ...
> ## converting column ID to character,Activity_Date_Minute to date
> minutewiseMET_Records$Id <- as.character(minutewiseMET_Records$Id)
> minutewiseMET_Records$Date <- as.Date(minutewiseMET_Records$Activity_Date_Minute)
> ## converting column ID to character,Activity_Date_Minute to date
> minutewiseMET_Records$Id <- as.character(minutewiseMET_Records$Id)
> minutewiseMET_Records$Date <- as.Date(minutewiseMET_Records$Activity_Date_Minute)
> str(minutewiseMET_Records)
'data.frame': 1048575 obs. of 4 variables:
$ Id : chr "1503960366" "1503960366" "1503960366" "1503960366" ...
$ Activity_Date_Minute: chr "04/12/2016 00:00" "04/12/2016 00:01" "04/12/2016 00:02" "04/12/2016 00:03" ...
$ METs : int 10 10 10 10 10 12 12 12 12 12 ...
$ Date : Date, format: "4-12-20" "4-12-20" ...
>
</code></pre>
| [
{
"answer_id": 74432607,
"author": "zephryl",
"author_id": 17303805,
"author_profile": "https://Stackoverflow.com/users/17303805",
"pm_score": 0,
"selected": false,
"text": "Activity_Date_Minute"
},
{
"answer_id": 74432630,
"author": "R18",
"author_id": 6930388,
"author_profile": "https://Stackoverflow.com/users/6930388",
"pm_score": 2,
"selected": true,
"text": "minutewiseMET_Records$Date <- format(as.Date(minutewiseMET_Records$Activity_Date_Minute, format = \"%d/%m/%Y\"),\"%m/%d/%Y\")\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20068843/"
] |
74,432,429 | <p>I am trying to add some properties to an array of objects inside useEffect but it renders DOM while those fields are still not present. Is there any reliable way how to wait till those properties are added:</p>
<p>useEffect hook look like this:</p>
<pre><code> useEffect(() => {
onSnapshot(query(collection(db, "conversations"), where('canRead', 'array-contains', user.user.uid), orderBy("lastMsgDate", 'desc')),
async (snapshot) => {
let conversations = snapshot.docs.map(doc => toConversation(doc, user.user.uid));
await conversations.map(async (convo, index) => {
const profile = await getDoc(doc(db, "users", convo.canRead[0]))
conversations[index].picture = profile.data().picture
conversations[index].name = profile.data().name
})
setConversations(conversations)
})
}, []);
</code></pre>
<p>This is how I am rendering list of convos:</p>
<pre><code><IonCard>
{conversations.length > 0 ?
conversations.map((conversation) =>
<IonItem key={conversation.id}>
<IonAvatar slot='start'>
<img src={conversation.picture ? conversation.picture : '/assets/default-profile.svg'} alt={conversation.name} />
</IonAvatar>
<IonLabel>{conversation.name}</IonLabel>
</IonItem>
)
:
<IonCardContent>
no convos
</IonCardContent>
}
</IonCard>
</code></pre>
<p>the name and picture does not render even i can see it when log array into console</p>
<pre><code>0:{
canRead: ['iwPmOBesFQV1opgs3HT9rYPF7Sj1'],
id: "W6cefXGoBAZijPof8jVl",
lastMsg: "test",
lastMsgDate: nt {seconds: 1668418292, nanoseconds: 281000000},
lastMsgSender: "Hyw4Argt8rR25mFaFo1Sl4iAWoM2",
name: "Warren"
picture: "https://firebasestorage.googleapis.com/v0/b/..."
users: {
Hyw4Argt8rR25mFaFo1Sl4iAWoM2: true,
iwPmOBesFQV1opgs3HT9rYPF7Sj1: true
}
}
</code></pre>
<p>Any help appreciated</p>
| [
{
"answer_id": 74432605,
"author": "jasjamjos",
"author_id": 11882303,
"author_profile": "https://Stackoverflow.com/users/11882303",
"pm_score": -1,
"selected": false,
"text": "const [loading, setLoading] = useState(false);\n const [conversations,setConversations] = useState(null);\n const onSnapshot = async () => {\n setLoading(true)\n onSnapshot(\n query(\n collection(db, \"conversations\"),\n where(\"canRead\", \"array-contains\", user.user.uid),\n orderBy(\"lastMsgDate\", \"desc\")\n ),\n async (snapshot) => {\n let conversations = snapshot.docs.map((doc) =>\n toConversation(doc, user.user.uid)\n );\n await conversations.map(async (convo, index) => {\n const profile = await getDoc(doc(db, \"users\", convo.canRead[0]));\n conversations[index].picture = profile.data().picture;\n conversations[index].name = profile.data().name;\n });\n setConversations(conversations);\n }\n );\n\n setLoading(false);\n };\n \n useEffect(() => {\n onSnapshot()\n },[])\n\n return loading ? <span>loading...</span> : <div>{conversations.map((con,i) => <span key={i}>con</span>)}</div>\n"
},
{
"answer_id": 74432699,
"author": "Dan Salomon",
"author_id": 5261252,
"author_profile": "https://Stackoverflow.com/users/5261252",
"pm_score": 0,
"selected": false,
"text": " const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n onSnapshot(query(collection(db, \"conversations\"), where('canRead', 'array-contains', user.user.uid), orderBy(\"lastMsgDate\", 'desc')),\n async (snapshot) => {\n ....\n setConversations(conversations);\n setLoading(false);\n })\n }, []);\n\n if(loading) return <p>Loading...</p>\n\n return <> your content </>\n"
},
{
"answer_id": 74433430,
"author": "Igor Mizak",
"author_id": 2313433,
"author_profile": "https://Stackoverflow.com/users/2313433",
"pm_score": 0,
"selected": false,
"text": "setTimeout"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2313433/"
] |
74,432,455 | <p>I have a list of keywords based on which I want to categorize the job description. Here are example list of keywords</p>
<pre><code>manager = ["manager", "president", "management", "managing"]
assistant = ["assistant", "assisting"]
engineer = ["engineer", "engineering", "scientist", "architect"]
</code></pre>
<p>If a job description contains any of the keyword from the "manager" list, I would like to classify job description as manager regardless of whether it contains the other keywords or not. So in a way there is a hierarchy in different lists (manager > assistant > engineer)
Example data frame:</p>
<pre><code>job_description
Managing engineer is responsible for
This job entails assisting to
Engineer is required the execute
Pilot should be able to control
</code></pre>
<p>After the classification I would like to obtain the following data frame</p>
<pre><code> job_description classification
Managing engineer is responsible for manager
This job entails assisting to engineers assistant
Engineer is required the execute engineer
Pilot should be able to control
</code></pre>
<p>I have more than three lists, is there an efficient way of classifying such text? Looking at previous answers, I wrote the following code but it does not work for text for some reason</p>
<pre><code>import re
def get_dummy_vars(col, lsts):
out = []
len_lsts = len(lsts)
for row in col:
tmp = []
# in the nested loop, we use the any function to check for the first match
# if there's a match, break the loop and pad 0s since we don't care if there's another match
for lst in lsts:
tmp.append(int(any(True for x in lst if re.search(fr"\b{x}\b", row))))
if tmp[-1]:
break
tmp += [0] * (len_lsts - len(tmp))
out.append(tmp)
return out
df2 = df[~df['job_description'].isna()]
lsts = [manager, assistant, engineer]
out = df2.join(pd.DataFrame(get_dummy_vars(df2['cleaned'], lsts), columns=["manager", "assistant", "engineer"]))
</code></pre>
| [
{
"answer_id": 74432605,
"author": "jasjamjos",
"author_id": 11882303,
"author_profile": "https://Stackoverflow.com/users/11882303",
"pm_score": -1,
"selected": false,
"text": "const [loading, setLoading] = useState(false);\n const [conversations,setConversations] = useState(null);\n const onSnapshot = async () => {\n setLoading(true)\n onSnapshot(\n query(\n collection(db, \"conversations\"),\n where(\"canRead\", \"array-contains\", user.user.uid),\n orderBy(\"lastMsgDate\", \"desc\")\n ),\n async (snapshot) => {\n let conversations = snapshot.docs.map((doc) =>\n toConversation(doc, user.user.uid)\n );\n await conversations.map(async (convo, index) => {\n const profile = await getDoc(doc(db, \"users\", convo.canRead[0]));\n conversations[index].picture = profile.data().picture;\n conversations[index].name = profile.data().name;\n });\n setConversations(conversations);\n }\n );\n\n setLoading(false);\n };\n \n useEffect(() => {\n onSnapshot()\n },[])\n\n return loading ? <span>loading...</span> : <div>{conversations.map((con,i) => <span key={i}>con</span>)}</div>\n"
},
{
"answer_id": 74432699,
"author": "Dan Salomon",
"author_id": 5261252,
"author_profile": "https://Stackoverflow.com/users/5261252",
"pm_score": 0,
"selected": false,
"text": " const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n onSnapshot(query(collection(db, \"conversations\"), where('canRead', 'array-contains', user.user.uid), orderBy(\"lastMsgDate\", 'desc')),\n async (snapshot) => {\n ....\n setConversations(conversations);\n setLoading(false);\n })\n }, []);\n\n if(loading) return <p>Loading...</p>\n\n return <> your content </>\n"
},
{
"answer_id": 74433430,
"author": "Igor Mizak",
"author_id": 2313433,
"author_profile": "https://Stackoverflow.com/users/2313433",
"pm_score": 0,
"selected": false,
"text": "setTimeout"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7403752/"
] |
74,432,470 | <p>Recursively implement the function halves that takes two positive integers a and b, and returns a list containing the value a (converted to type float) and all successive halves of a that are greater than b.
I tried like this but it's returning an empty list and I don't understand what's going on:</p>
<pre><code>def metades(a, b):
if a < b: return []
if a > b:
lst = []
a = float(a/2)
lst.append(a)
return lst and metades(a,b)
print(metades(100,3))
</code></pre>
<p>Should return:</p>
<p>[100.0, 50.0, 25.0, 12.5, 6.25, 3.125]</p>
<p>Return:</p>
<p>[]</p>
| [
{
"answer_id": 74432574,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "def metades(a, b, res = None):\n\n res = res or []\n\n if a <= b: return res\n if a > b:\n res.append(a) # put first append and then division to retrieve also first value of 'a'\n a = float(a / 2)\n\n return metades(a, b, res)\n\nprint(metades(100,2))\n"
},
{
"answer_id": 74432815,
"author": "sahasrara62",
"author_id": 5086255,
"author_profile": "https://Stackoverflow.com/users/5086255",
"pm_score": 0,
"selected": false,
"text": "# your code goes here\ndef metades(a, b):\n result = []\n if a >= b:\n result.append(float(a))\n result.extend(metades(a/2, b))\n return result\n \nprint(metades(100,3))\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491883/"
] |
74,432,476 | <p>I am trying to figure out a formula to find the sum of hours worked for each worker per month and also per project. I am pretty sure the XLOOKUP, AND/IF, and SUBTotal could be useful but I am not exactly sure how to combine it all. Here are the exact data.</p>
<p>Lookup values for each employee (Column A),
Lookup values for each project per employee (Column B),
Lookup values for each Timesheet period (column C) format: 2022/06/03,
Then sum the total hours work of each employee, per project per month (Column D)</p>
<p>Thanks in advance!</p>
<p>I tried the XLOOKUP formula
AND formula for the dates
SUBTOTAL formula for the hours.</p>
<p><a href="https://i.stack.imgur.com/Hxx1u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hxx1u.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74432574,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "def metades(a, b, res = None):\n\n res = res or []\n\n if a <= b: return res\n if a > b:\n res.append(a) # put first append and then division to retrieve also first value of 'a'\n a = float(a / 2)\n\n return metades(a, b, res)\n\nprint(metades(100,2))\n"
},
{
"answer_id": 74432815,
"author": "sahasrara62",
"author_id": 5086255,
"author_profile": "https://Stackoverflow.com/users/5086255",
"pm_score": 0,
"selected": false,
"text": "# your code goes here\ndef metades(a, b):\n result = []\n if a >= b:\n result.append(float(a))\n result.extend(metades(a/2, b))\n return result\n \nprint(metades(100,3))\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18223918/"
] |
74,432,479 | <p>I'm having issues with Terraform when wanting to apply changes. Namely, even though the configuration (for launch template and node group) stays the same Terraform wants to change node groups settings because it thinks launch template version has been change.</p>
<p>My node group config looks like this:</p>
<pre><code>resource "aws_eks_node_group" "test" {
depends_on = [aws_launch_template.test]
...other settings
launch_template {
name = aws_launch_template.test.name
version = aws_launch_template.test.latest_version
}
}
</code></pre>
<p>Launch template:</p>
<pre><code>resource "aws_launch_template" "test" {
name = "test"
instance_type = var.instance
image_id = data.aws_ssm_parameter.eks-ami.value
user_data = base64encode(local.eks-node-userdata)
tag_specifications {
resource_type = "instance"
tags = {
Name = "test
}
}
lifecycle {
create_before_destroy = true
}
}
</code></pre>
<p>The output from <code>terraform apply</code>:</p>
<pre><code> # aws_launch_template.test will be updated in-place
~ resource "aws_launch_template" "test" {
id = "xxx"
~ image_id = (sensitive)
~ latest_version = 3 -> (known after apply)
name = "test"
tags = {}
# (16 unchanged attributes hidden)
# (1 unchanged block hidden)
}
# aws_eks_node_group.test will be updated in-place
~ resource "aws_eks_node_group" "general" {
...other settings
~ launch_template {
id = "xxx"
name = "test"
~ version = "3" -> (known after apply)
}
}
</code></pre>
<p>Everytime I run terraform commands (plan or apply) it wants to update node group thinking launch template has new version and node group should be updated. But nothing was changes in configuration files. Why is that happening? And how can I fix that?</p>
| [
{
"answer_id": 74432574,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "def metades(a, b, res = None):\n\n res = res or []\n\n if a <= b: return res\n if a > b:\n res.append(a) # put first append and then division to retrieve also first value of 'a'\n a = float(a / 2)\n\n return metades(a, b, res)\n\nprint(metades(100,2))\n"
},
{
"answer_id": 74432815,
"author": "sahasrara62",
"author_id": 5086255,
"author_profile": "https://Stackoverflow.com/users/5086255",
"pm_score": 0,
"selected": false,
"text": "# your code goes here\ndef metades(a, b):\n result = []\n if a >= b:\n result.append(float(a))\n result.extend(metades(a/2, b))\n return result\n \nprint(metades(100,3))\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9223556/"
] |
74,432,498 | <p>There's an input element in my page, and I use the input to add new items to the page. I want the focus to be always in the input element, so I can type => press enter to add => type another ...</p>
<p>However, the page rerenders everytime the new item got added.</p>
<p>I've tried</p>
<pre class="lang-js prettyprint-override"><code>const handleAdd = () => {
if (value) {
// process the value
// ...
setValue("");
inputRef.current?.focus();
}
};
</code></pre>
<p>But when I <code>console.log(document.activeElement)</code>, it first prints out the input, but then the focus goes to <code>body</code> element.</p>
<p>Is there any way to keep the focus in the input? Until I click away?</p>
| [
{
"answer_id": 74432574,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "def metades(a, b, res = None):\n\n res = res or []\n\n if a <= b: return res\n if a > b:\n res.append(a) # put first append and then division to retrieve also first value of 'a'\n a = float(a / 2)\n\n return metades(a, b, res)\n\nprint(metades(100,2))\n"
},
{
"answer_id": 74432815,
"author": "sahasrara62",
"author_id": 5086255,
"author_profile": "https://Stackoverflow.com/users/5086255",
"pm_score": 0,
"selected": false,
"text": "# your code goes here\ndef metades(a, b):\n result = []\n if a >= b:\n result.append(float(a))\n result.extend(metades(a/2, b))\n return result\n \nprint(metades(100,3))\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4971866/"
] |
74,432,527 | <p>I'm using janusgraph with AWSKeyspace (cassandra) and elasticsearch as the storage and indexing backends respectively.
I have a requirement to delete all the edges older than 30days. Setting a TTL on edge property doesn't work as expected(error below).</p>
<pre><code>ERROR org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager - Could not create GremlinScriptEngine for gremlin-groovy
java.lang.IllegalStateException: javax.script.ScriptException: javax.script.ScriptException:
java.lang.UnsupportedOperationException: The storage engine does not support TTL
</code></pre>
<p>My script is below:</p>
<pre><code>edgeId = mgmt.getPropertyKey("edge_id")
sourceId = mgmt.getPropertyKey("source_id")
severity = mgmt.getPropertyKey("severity")
source = mgmt.getPropertyKey("source")
createdAt = mgmt.getPropertyKey("created_at")
alertStatus = mgmt.getPropertyKey("alert_status")
investigationStatus = mgmt.getPropertyKey("investigation_status")
investigationPriority = mgmt.getPropertyKey("investigation_priority")
attributes = mgmt.getPropertyKey("attributes")
edgeType = mgmt.getPropertyKey("edge_type")
if (!mgmt.containsGraphIndex(edgeIndexName)) {
mgmt.buildIndex(edgeIndexName, Edge.class).
addKey(edgeType, Mapping.TEXT.asParameter()).
addKey(tenant, Mapping.TEXT.asParameter()).
addKey(severity, Mapping.DEFAULT.asParameter()).
addKey(source, Mapping.TEXT.asParameter()).
addKey(createdAt, Mapping.DEFAULT.asParameter()).
addKey(investigationPriority, Mapping.DEFAULT.asParameter()).
addKey(attributes, Mapping.TEXT.asParameter()).
buildMixedIndex(indexBackendName)
}
makeEdgeCompositeIndex(mgmt, edgeCompositeIndexName, edgeId)
makeEdgeCompositeIndex(mgmt, edgeCompositeIndexName, sourceId)
// ###########
// Add TTL
// ###########
mgmt.setTTL(sourceId, Duration.ofDays(30))
</code></pre>
<p>I did try replacing AWSKeyspace with cassandra and run the same script in a docker compose file and it works well(setting of TTL). Just like cassandra AWSKeyspace supports adding TTLs.</p>
| [
{
"answer_id": 74432574,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "def metades(a, b, res = None):\n\n res = res or []\n\n if a <= b: return res\n if a > b:\n res.append(a) # put first append and then division to retrieve also first value of 'a'\n a = float(a / 2)\n\n return metades(a, b, res)\n\nprint(metades(100,2))\n"
},
{
"answer_id": 74432815,
"author": "sahasrara62",
"author_id": 5086255,
"author_profile": "https://Stackoverflow.com/users/5086255",
"pm_score": 0,
"selected": false,
"text": "# your code goes here\ndef metades(a, b):\n result = []\n if a >= b:\n result.append(float(a))\n result.extend(metades(a/2, b))\n return result\n \nprint(metades(100,3))\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/377902/"
] |
74,432,540 | <p>i got this code that take webhook message but i dont understand the pattern matching behind it</p>
<pre><code>function getContent(link)
cmd = io.popen('powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Write-Host (Invoke-WebRequest -Uri "'..link..'").Content"')
return cmd:read("*all"):match('"description": "(.+)"}],')
end
function blabla(a)
link= webhookLink.."/messages/"..messageId
text = [[
$webHookUrl = "]]..link..[["
$embedObject = @{
description = "]]..getContent(link):gsub("\\([nt])", {n="\n", t="\t"})..[[`n]]..a..[["
}
$embedArray = @($embedObject)
$payload = @{
embeds = $embedArray
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Uri $webHookUrl -Body ($payload | ConvertTo-Json -Depth 4) -Method Patch -ContentType 'application/json'
]]
file = io.popen("powershell -command -", "w")
file:write(text)
file:close()
end
</code></pre>
<p>My question is what does <code>"(.+)"}]</code> mean in the <code>getContent</code> function and <code>]]..getContent(link):gsub("\\([nt])", {n="\n", t="\t"})..[[</code>n]]..a..[[<code>in</code>blabla` function ?</p>
| [
{
"answer_id": 74432769,
"author": "Ivo",
"author_id": 1514861,
"author_profile": "https://Stackoverflow.com/users/1514861",
"pm_score": -1,
"selected": false,
"text": "."
},
{
"answer_id": 74432900,
"author": "AMR",
"author_id": 15323004,
"author_profile": "https://Stackoverflow.com/users/15323004",
"pm_score": 1,
"selected": false,
"text": "return cmd:read(\"*all\"):match('\"description\": \"(.+)\"}],')"
},
{
"answer_id": 74434580,
"author": "LMD",
"author_id": 7185318,
"author_profile": "https://Stackoverflow.com/users/7185318",
"pm_score": 1,
"selected": false,
"text": "\"description\": \"(.+)\"}],"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20215528/"
] |
74,432,541 | <p>i'am using “storms” tibble in dplyr package,in R
i want to know</p>
<ol>
<li>if there are storms that occur in different years but given the same name?</li>
<li>if any Which storm names, were reused in which years?</li>
</ol>
<p>for example:</p>
<pre><code>name year
-------- -----------
Alberto 1997
Alberto 2001
Gordon 1993
Felix 2000
</code></pre>
<p>so Alberto display in different years and have the same name</p>
| [
{
"answer_id": 74432588,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "dplyr::storms %>%\n count(name, year) %>% \n arrange(name)\n\n# A tibble: 512 x 3\n name year n\n <chr> <dbl> <int>\n 1 AL011993 1993 8\n 2 AL012000 2000 4\n 3 AL021992 1992 5\n 4 AL021994 1994 6\n 5 AL021999 1999 4\n 6 AL022000 2000 12\n 7 AL022001 2001 5\n 8 AL022003 2003 4\n 9 AL022006 2006 5\n10 AL031987 1987 32\n# ... with 502 more rows\n"
},
{
"answer_id": 74432680,
"author": "Hansel Palencia",
"author_id": 10897981,
"author_profile": "https://Stackoverflow.com/users/10897981",
"pm_score": 1,
"selected": false,
"text": "library(dplyr)\nlibrary(tidyr)\n\nstorms %>% \n select(name, year) %>% \n distinct() %>% \n group_by(name, year) %>% \n summarise(Count = n()) %>% \n group_by(name) %>% \n filter(n() > 1) %>% \n select(-Count)\n \n\n--- Output\n\n# Groups: name [106]\n name year\n <chr> <dbl>\n 1 Alberto 1982\n 2 Alberto 1988\n 3 Alberto 1994\n 4 Alberto 2000\n 5 Alberto 2006\n 6 Alberto 2012\n 7 Alberto 2018\n 8 Alex 1998\n 9 Alex 2004\n10 Alex 2010\n"
},
{
"answer_id": 74432832,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 0,
"selected": false,
"text": "count"
},
{
"answer_id": 74433462,
"author": "Santiago",
"author_id": 13507658,
"author_profile": "https://Stackoverflow.com/users/13507658",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\n\nstorms %>% \n distinct(name, year) %>% \n filter(duplicated(name) | duplicated(name, fromLast = TRUE)) %>% \n arrange(name)\n\n# # A tibble: 404 × 2\n# name year\n# <chr> <dbl>\n# 1 Alberto 1982\n# 2 Alberto 1988\n# 3 Alberto 1994\n# 4 Alberto 2000\n# 5 Alberto 2006\n# 6 Alberto 2012\n# 7 Alberto 2018\n# 8 Alex 1998\n# 9 Alex 2004\n# 10 Alex 2010\n# # … with 394 more rows\n# # ℹ Use `print(n = ...)` to see more rows\n\n"
},
{
"answer_id": 74433513,
"author": "Ottie",
"author_id": 17732851,
"author_profile": "https://Stackoverflow.com/users/17732851",
"pm_score": 1,
"selected": false,
"text": "aggregate"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501128/"
] |
74,432,546 | <p>I am currently trying to run an excel function that runs the logic that if the cell that has date X is greater than date 2023-01-01 then run an XLookup function. If it is not then do not run it.</p>
<p>Here's what I tried below:</p>
<pre><code>=IF(table2!N5>DATE(2023,1,1),XLOOKUP(A2,'Table2'!A:A,'Table2'!B:B),"FALSE")
</code></pre>
<p>N5 has the date 2022-12-01. The rest is just a standard xlookup function that would run if cell N5 is greater than the date 2023-01-01.</p>
<p>Data for the Xlookup below:</p>
<p>Table 1 : This table provides the lookup value A1.</p>
<pre><code> A B C
1 Position Classification Full Name
2 111111 IT 04 John Smith
</code></pre>
<p>Table 2 : This table provides the lookup array being A:A and the return array being B:B</p>
<pre><code> A B C D
1 Employment Position CC Valid From Valid To
2 111111 8888888 2022-10-01 2023-03-31
</code></pre>
| [
{
"answer_id": 74432588,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "dplyr::storms %>%\n count(name, year) %>% \n arrange(name)\n\n# A tibble: 512 x 3\n name year n\n <chr> <dbl> <int>\n 1 AL011993 1993 8\n 2 AL012000 2000 4\n 3 AL021992 1992 5\n 4 AL021994 1994 6\n 5 AL021999 1999 4\n 6 AL022000 2000 12\n 7 AL022001 2001 5\n 8 AL022003 2003 4\n 9 AL022006 2006 5\n10 AL031987 1987 32\n# ... with 502 more rows\n"
},
{
"answer_id": 74432680,
"author": "Hansel Palencia",
"author_id": 10897981,
"author_profile": "https://Stackoverflow.com/users/10897981",
"pm_score": 1,
"selected": false,
"text": "library(dplyr)\nlibrary(tidyr)\n\nstorms %>% \n select(name, year) %>% \n distinct() %>% \n group_by(name, year) %>% \n summarise(Count = n()) %>% \n group_by(name) %>% \n filter(n() > 1) %>% \n select(-Count)\n \n\n--- Output\n\n# Groups: name [106]\n name year\n <chr> <dbl>\n 1 Alberto 1982\n 2 Alberto 1988\n 3 Alberto 1994\n 4 Alberto 2000\n 5 Alberto 2006\n 6 Alberto 2012\n 7 Alberto 2018\n 8 Alex 1998\n 9 Alex 2004\n10 Alex 2010\n"
},
{
"answer_id": 74432832,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 0,
"selected": false,
"text": "count"
},
{
"answer_id": 74433462,
"author": "Santiago",
"author_id": 13507658,
"author_profile": "https://Stackoverflow.com/users/13507658",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\n\nstorms %>% \n distinct(name, year) %>% \n filter(duplicated(name) | duplicated(name, fromLast = TRUE)) %>% \n arrange(name)\n\n# # A tibble: 404 × 2\n# name year\n# <chr> <dbl>\n# 1 Alberto 1982\n# 2 Alberto 1988\n# 3 Alberto 1994\n# 4 Alberto 2000\n# 5 Alberto 2006\n# 6 Alberto 2012\n# 7 Alberto 2018\n# 8 Alex 1998\n# 9 Alex 2004\n# 10 Alex 2010\n# # … with 394 more rows\n# # ℹ Use `print(n = ...)` to see more rows\n\n"
},
{
"answer_id": 74433513,
"author": "Ottie",
"author_id": 17732851,
"author_profile": "https://Stackoverflow.com/users/17732851",
"pm_score": 1,
"selected": false,
"text": "aggregate"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17346534/"
] |
74,432,554 | <pre><code> return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 2),
child: FaIcon(
FontAwesomeIcons.compass,
color: orange,
size: 26,
),
),
],
),
),
SizedBox(
height: 25,
),
Text(
'The final step for exploration.',
style: homepageSubtitle,
),
SizedBox(
height: 50,
),
TextFormWidget(
onChanged: () => null,
controller: _usernameController,
labelText: 'Username',
hintText: 'example@gmail.com'),
TextFormWidget(
onChanged: () => (value) => _checkPassword(value),
controller: _passwordController,
labelText: 'Password',
hintText: 'Min. 8 characters'),
</code></pre>
<p>Here, I created the page you see in the image.</p>
<pre><code>return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 20,
),
child: TextFormField(
onChanged: onChanged(),
keyboardType: TextInputType.text,
controller: controller,
decoration: InputDecoration(
contentPadding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
labelText: labelText,
hintText: hintText,
labelStyle: labelTextStyle,
hintStyle: hintTextStyle,
),
),
),
],
);
</code></pre>
<p>Here is the TextFormWidget I created.</p>
<p><a href="https://i.stack.imgur.com/pBALJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pBALJ.png" alt="enter image description here" /></a></p>
<p>If I click on a TextFormField to enter a value, I get an overflowed error. What should I wrap the widget I created or the place where I show this widget so that I don't get this error?</p>
| [
{
"answer_id": 74432609,
"author": "eamirho3ein",
"author_id": 10306997,
"author_profile": "https://Stackoverflow.com/users/10306997",
"pm_score": 0,
"selected": false,
"text": "Scaffold"
},
{
"answer_id": 74432613,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 2,
"selected": false,
"text": "SingleChildScrollView(\n child : Column(\n children: [\n // your children\n ]\n );\n)\n \n"
},
{
"answer_id": 74432622,
"author": "noxgood",
"author_id": 20003715,
"author_profile": "https://Stackoverflow.com/users/20003715",
"pm_score": 0,
"selected": false,
"text": "Column"
},
{
"answer_id": 74437154,
"author": "Ritik Saxena",
"author_id": 10591484,
"author_profile": "https://Stackoverflow.com/users/10591484",
"pm_score": 0,
"selected": false,
"text": "class DemoApp extends StatelessWidget {\n const DemoApp({super.key});\n\n @override\n Widget build(BuildContext context) {\n return MaterialApp(\n home: Scaffold(\n body: Column(\n children: [\n Container(\n height: 600,\n color: Colors.deepPurple,\n ),\n TextFormField(\n decoration: const InputDecoration(labelText: 'Username'),\n ),\n TextFormField(\n decoration: const InputDecoration(labelText: 'Password'),\n )\n ],\n ),\n ),\n );\n }\n}\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17906689/"
] |
74,432,583 | <pre><code>vc = bot.get_channel(ctx.author.voice.channel.id)
await vc.connect()
await vc.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source="assets/a.mp3"))
</code></pre>
<p>This code was working like 3 months ago, and now it doesn't because voice channel object (vc) has no attribute play. Any reason why it stopped working and how to fix it?</p>
<pre><code>Ignoring exception in command play:
Traceback (most recent call last):
File "C:\Users\Poco\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Poco\Desktop\py\elevate\main.py", line 38, in play
await vc.play(discord.FFmpegPCMAudio(executable="ffmpeg.exe", source="assets/ass.mp3"))
AttributeError: 'VoiceChannel' object has no attribute 'play'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Poco\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Poco\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Poco\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceChannel' object has no attribute 'play'
</code></pre>
<p>I tried to use different vcs, servers, permissions but nothing has solved the problem</p>
| [
{
"answer_id": 74433475,
"author": "mousetail",
"author_id": 6333444,
"author_profile": "https://Stackoverflow.com/users/6333444",
"pm_score": 1,
"selected": true,
"text": "AttributeError"
},
{
"answer_id": 74433523,
"author": "Ildaron",
"author_id": 13904129,
"author_profile": "https://Stackoverflow.com/users/13904129",
"pm_score": 1,
"selected": false,
"text": "voice = get(bot.voice_clients, guild=ctx.guild)\nif voice and voice.is_connected:\n await voice.move_to(channel)\nelse:\n voice = await channel.connect()\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19926187/"
] |
74,432,602 | <p>I have a few elements inside this kind of tag as below:</p>
<p><a href="https://i.stack.imgur.com/dNj55.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>How do I locate these kinds of elements</p>
<p>I tried to locate the foresaid element, which the Selenium C# is not working</p>
| [
{
"answer_id": 74432660,
"author": "Mark Barton",
"author_id": 4357444,
"author_profile": "https://Stackoverflow.com/users/4357444",
"pm_score": 0,
"selected": false,
"text": "var driver = //whatever your driver is;\n\ndriver.FindElement(By.Id(\"element-id-goes-here\"));\n\n"
},
{
"answer_id": 74433102,
"author": "Alex Karamfilov",
"author_id": 7031148,
"author_profile": "https://Stackoverflow.com/users/7031148",
"pm_score": 1,
"selected": false,
"text": "//div[@data-testid='patientLink']/p\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9168223/"
] |
74,432,603 | <p>I need to find relative paths of folders and its files with length in MB in separate csv columns and compare that csv file with another csv file and print unmatched filepaths with length in another csv in absolute path</p>
<pre><code>$srcpth = "C:\Users\vavenkatamanoj\Downloads"
$files = Get-ChildItem -Path $srcpth -File -Recurse
foreach ($f in $files)
{
$filen = $f.Name
$relativePath = $f.fullname.remove(0,($srcpth.length))
$filesize = $f.Length
Write-Output "$relativePath,$filesize" | Out-File C:\Users\vavenkatamanoj\Downloads\check.csv -Append
}
</code></pre>
<p>I try this script to get relative paths with size. It is ok but filepath and length are returned in the same column; I need separate columns. Can anyone help me?</p>
| [
{
"answer_id": 74432660,
"author": "Mark Barton",
"author_id": 4357444,
"author_profile": "https://Stackoverflow.com/users/4357444",
"pm_score": 0,
"selected": false,
"text": "var driver = //whatever your driver is;\n\ndriver.FindElement(By.Id(\"element-id-goes-here\"));\n\n"
},
{
"answer_id": 74433102,
"author": "Alex Karamfilov",
"author_id": 7031148,
"author_profile": "https://Stackoverflow.com/users/7031148",
"pm_score": 1,
"selected": false,
"text": "//div[@data-testid='patientLink']/p\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,432,628 | <p>I'm trying to solve MIP problem with IBM ILOG CPLEX Optimization studio. All the parameters have been defined. I want to save the output from the first iteration and use this output as input for the next iteration and change some data too. I have 14 iterations and the mod file is fixed in each iteration.
could you help me?
Regards</p>
<p>I expect them to answer</p>
| [
{
"answer_id": 74432660,
"author": "Mark Barton",
"author_id": 4357444,
"author_profile": "https://Stackoverflow.com/users/4357444",
"pm_score": 0,
"selected": false,
"text": "var driver = //whatever your driver is;\n\ndriver.FindElement(By.Id(\"element-id-goes-here\"));\n\n"
},
{
"answer_id": 74433102,
"author": "Alex Karamfilov",
"author_id": 7031148,
"author_profile": "https://Stackoverflow.com/users/7031148",
"pm_score": 1,
"selected": false,
"text": "//div[@data-testid='patientLink']/p\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501040/"
] |
74,432,650 | <p>I am trying to install the compiled firmware for a microprocessor in my yocto image. This firmware is sent to a microprocessor on startup. The compiler for this firmware only runs on windows, therefore it is not possible to just clone the git repository and compile during build. I get this firmware file from the artifacts of a GitLab CI CD pipeline.</p>
<p>For debugging purposes, i would like to download this firmware file from the master branch, everytime that I build the image.</p>
<p>I previously worked with a custom <code>do_fetch</code> task and had set <code>do_fetch[nostamp] = "1"</code>. This worked, but I ran into trouble when <code>curl</code> just put the 404 Error into the file. I have now tried to switch to <code>wget</code> and <code>SRC_URI</code>, but even though the <code>nostamp</code> is still set, it generates a <code>.done</code> file. It now never downloads the file again.</p>
<p>Here is the Recipe file I use:</p>
<pre><code>S = "${WORKDIR}/"
PRIVATE_TOKEN = "xxxxxxxxxxx" # redacted
PROJECT_ID = "224"
VERSION = "2.00.01"
TAG = "master"
DOWNLOAD_FILE_PATH = "Production/firmware.bin"
INSTALL_NAME = "my-firmware-file.bin"
VERSION_FILE = "version.txt"
URL = "https://git.mycompany.com/api/v4/projects/${PROJECT_ID}/jobs/artifacts/${TAG}/raw/${DOWNLOAD_FILE_PATH}?job=publish_executable"
FETCHCMD_wget = "/usr/bin/env wget --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}""
BB_STRICT_CHECKSUM = "0"
SRC_URI = "${URL};downloadfilename=${INSTALL_NAME}"
do_fetch[nostamp] = "1"
do_patch(){
echo ${VERSION} > ${VERSION_FILE}
}
do_install(){
install -d ${D}${libdir}/test-dir/${PN}
# Install binary from artifacts
install -m 644 ${S}${INSTALL_NAME} ${D}${libdir}/test-dir/${PN}/${INSTALL_NAME}
# Instal version file created from tag
install -m 644 ${S}${VERSION_FILE} ${D}${libdir}/test-dir/${PN}/${VERSION_FILE}
}
FILES_${PN} += "${libdir}/test-dir/${PN}"
</code></pre>
<p>After running the recipe (either <code>bitbake <PN></code> or <code>bitbake <PN> -c fetch -f</code>) I can run <code>ls -la build/download | grep my-firmware-file</code> and it shows two entries:</p>
<pre><code>-rw-rw-r-- 1 root root 613924 Nov 11 11:50 my-firmware-file.bin
-rw-rw-r-- 1 root root 463 Nov 14 14:26 my-firmware-file.bin.done
</code></pre>
<p>As you see, it generated a <code>.done</code> file, that is newer than the last download of the actual file. Even when changing the <code>TAG</code> variable, no new file is downloaded. However for some reason, it always puts the correct version into the <code>version.txt</code>file.</p>
<p>What am I missing? I could run a <code>cleanall</code> before every build, but that does not seem like a permanent solution. Also, the endgoal is to version the recipe and use the package version to pull from the correct release, but currently it pulls from master, so this does not make much sense.</p>
<p><strong>Update</strong>: I checked the logfiles, and it seems wget is not the problem, as the command is never even executed. The first time after a clean, the log for <code>do_fetch</code> looks like this:</p>
<pre><code>DEBUG: Executing python function extend_recipe_sysroot
NOTE: Direct dependencies are []
NOTE: Installed into sysroot: []
NOTE: Skipping as already exists in sysroot: []
DEBUG: Python function extend_recipe_sysroot finished
DEBUG: Executing python function do_fetch
DEBUG: Executing python function base_do_fetch
DEBUG: Trying PREMIRRORS
DEBUG: Trying Upstream
DEBUG: Fetching https://git.mycompany.com/api/v4/projects/224/jobs/artifacts/master/raw/Production/firmware.bin?job=publish_executable;downloadfilename=my-firmware-file.bin using command '/usr/bin/env wget -r --header "PRIVATE-TOKEN: xxxxxxxxxxxxxx" -O /home/.../build/downloads/my-firmware-file.bin.tmp -P /home/.../build/downloads 'https://git.mycompany.com/api/v4/projects/224/jobs/artifacts/master/raw/Production/firmware.bin?job=publish_executable''
DEBUG: Fetcher accessed the network with the command /usr/bin/env wget -r --header "PRIVATE-TOKEN: xxxxxxxxxxxxxx" -O /home/.../build/downloads/my-firmware-file.bin.tmp -P /home/.../build/downloads 'https://git.mycompany.com/api/v4/projects/224/jobs/artifacts/master/raw/Production/firmware.bin?job=publish_executable'
DEBUG: Running export PSEUDO_DISABLED=1; export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1005/bus"; export PATH="..."; export HOME="/home/..."; /usr/bin/env wget -r --header "PRIVATE-TOKEN: xxxxxxxxxxxxxx" -O /home/.../build/downloads/my-firmware-file.bin.tmp -P /home/.../build/downloads 'https://git.mycompany.com/api/v4/projects/224/jobs/artifacts/master/raw/Production/firmware.bin?job=publish_executable' --progress=dot -v
WARNING: combining -O with -r or -p will mean that all downloaded content
will be placed in the single file you specified.
--2022-11-18 07:01:11-- https://git.mycompany.com/api/v4/projects/224/jobs/artifacts/master/raw/Production/firmware.bin?job=publish_executable
Resolving git.mycompany.com (git.mycompany.com)... <IP>
Connecting to git.mycompany.com (git.mycompany.com)|<IP>|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 613924 (600K) [application/octet-stream]
Saving to: ‘/home/.../build/downloads/my-firmware-file.bin.tmp’
2022-11-18 07:01:11 (70.4 MB/s) - ‘/home/.../build/downloads/my-firmware-file.bin.tmp’ saved [613924/613924]
FINISHED --2022-11-18 07:01:11--
Total wall clock time: 0.5s
Downloaded: 1 files, 600K in 0.008s (70.4 MB/s)
WARNING: Missing checksum for '/home/.../build/downloads/my-firmware-file.bin', consider adding at least one to the recipe:
SRC_URI[sha256sum] = "83aa3c373228b48eea58964b4ffec7ad42226014351d18bed12cb9b5eb3d261e"
DEBUG: Python function base_do_fetch finished
DEBUG: Python function do_fetch finished
</code></pre>
<p>When I then run <code>do_fetch</code> again (even when changing the <code>TAG</code> variable, so <code>SRC_URI</code> changes), the log looks as follows:</p>
<pre><code>DEBUG: Executing python function extend_recipe_sysroot
NOTE: Direct dependencies are []
NOTE: Installed into sysroot: []
NOTE: Skipping as already exists in sysroot: []
DEBUG: Python function extend_recipe_sysroot finished
DEBUG: Executing python function do_fetch
DEBUG: Executing python function base_do_fetch
WARNING: Missing checksum for '/home/.../build/downloads/my-firmware-file.bin', consider adding at least one to the recipe:
SRC_URI[sha256sum] = "83aa3c373228b48eea58964b4ffec7ad42226014351d18bed12cb9b5eb3d261e"
WARNING: Missing checksum for '/home/.../build/downloads/my-firmware-file.bin', consider adding at least one to the recipe:
SRC_URI[sha256sum] = "83aa3c373228b48eea58964b4ffec7ad42226014351d18bed12cb9b5eb3d261e"
DEBUG: Python function base_do_fetch finished
DEBUG: Python function do_fetch finished
</code></pre>
<p>Notice the duplicated missing checksum warning in the second log. I also tried to delete only the <code>./downloads/my-firmware-file.bin.done</code> file, but it still is not redownloaded, the log is the same as the second one.</p>
| [
{
"answer_id": 74432660,
"author": "Mark Barton",
"author_id": 4357444,
"author_profile": "https://Stackoverflow.com/users/4357444",
"pm_score": 0,
"selected": false,
"text": "var driver = //whatever your driver is;\n\ndriver.FindElement(By.Id(\"element-id-goes-here\"));\n\n"
},
{
"answer_id": 74433102,
"author": "Alex Karamfilov",
"author_id": 7031148,
"author_profile": "https://Stackoverflow.com/users/7031148",
"pm_score": 1,
"selected": false,
"text": "//div[@data-testid='patientLink']/p\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14906662/"
] |
74,432,682 | <p>I'm in the process of changing what was formerly a Class into a Struct, as part of an editor patch within Unity. I've read a lot of advice on using structs being "Don't allow mutable structs", due to poor copy behaviour resulting in modified copies, and being hard to track. As I understand, a result of being stack-based and having no data overhead.</p>
<p>However, I'd like to clarify that with the specific case. Is a boolean value okay to mutate within a struct, since the data size can never change? The particular boolean property <em>could</em> theoretically be modified with frequency, so if it's likely to cause memory problems I'll have to implement some other way to track that parameter that elsewhere.</p>
<p>Extra notes, in case of unexpected relevance:</p>
<ul>
<li>The class has three properties, one of which is a boolean.</li>
<li>The two non-boolean properties will not be mutable.</li>
</ul>
| [
{
"answer_id": 74432660,
"author": "Mark Barton",
"author_id": 4357444,
"author_profile": "https://Stackoverflow.com/users/4357444",
"pm_score": 0,
"selected": false,
"text": "var driver = //whatever your driver is;\n\ndriver.FindElement(By.Id(\"element-id-goes-here\"));\n\n"
},
{
"answer_id": 74433102,
"author": "Alex Karamfilov",
"author_id": 7031148,
"author_profile": "https://Stackoverflow.com/users/7031148",
"pm_score": 1,
"selected": false,
"text": "//div[@data-testid='patientLink']/p\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10964168/"
] |
74,432,685 | <p>this the forth project from the odin project, all tests passed but the fifth one which required removing all elements failed and when i run the code it returns an array with half elements in original array before mutating.</p>
<p>**I don't know why IT DOESN'T RETURN AN EMPTY ARRAY. ** in the fifth test.</p>
<pre><code></code></pre>
<pre><code>const removeFromArray = function (array, ...deleteElement) {
for (let i = 0; i < array.length; i++) {
if (array.includes(deleteElement[i])) {
array.splice(array.indexOf(deleteElement[i]), 1);
}
}
return array;
};
const randomArray = [1, 2, 3, 4];
console.log(removeFromArray(randomArray, 1, 2, 3, 4));
</code></pre>
<pre><code>and this the test
</code></pre>
<pre><code>const removeFromArray = require('./removeFromArray')
describe('removeFromArray', () => {
test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
});
test('removes multiple values', () => {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
});
test('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
});
test('ignores non present values, but still works', () => {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
});
test.skip('can remove all values', () => {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
});
test.skip('works with strings', () => {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
});
test.skip('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
});
});
</code></pre>
<pre><code></code></pre>
| [
{
"answer_id": 74432826,
"author": "Dawid .T",
"author_id": 10771724,
"author_profile": "https://Stackoverflow.com/users/10771724",
"pm_score": 1,
"selected": true,
"text": "for"
},
{
"answer_id": 74432837,
"author": "bcngr",
"author_id": 5220895,
"author_profile": "https://Stackoverflow.com/users/5220895",
"pm_score": -1,
"selected": false,
"text": "array.length"
},
{
"answer_id": 74432844,
"author": "Dr. Vortex",
"author_id": 17637456,
"author_profile": "https://Stackoverflow.com/users/17637456",
"pm_score": 0,
"selected": false,
"text": "array.length"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18390247/"
] |
74,432,707 | <pre class="lang-py prettyprint-override"><code>def check_22(num_list):
for i in range(0, len(num_list)-1):
if num_list[i] == 2 and num_list[i+1] == 2:
return True
else:
return False
print(check_22([3,2,5,1,2,1,2,2]))
</code></pre>
<p>How come the output is <code>False</code> when it needs to display <code>True</code>?</p>
| [
{
"answer_id": 74432736,
"author": "dkalouris",
"author_id": 20488115,
"author_profile": "https://Stackoverflow.com/users/20488115",
"pm_score": 0,
"selected": false,
"text": "for i in range(0,len(num_list)-1): \n if num_list[i]==2 and num_list[i+1]==2: \n return True\nreturn False\n"
},
{
"answer_id": 74432747,
"author": "Mike",
"author_id": 232115,
"author_profile": "https://Stackoverflow.com/users/232115",
"pm_score": -1,
"selected": false,
"text": "def check_22(num_list): \n#start writing your code here\n for i in range(0,len(num_list)-1):\n if num_list[i]==2 and num_list[i+1]==2: \n return True\n else:\n return False\n"
},
{
"answer_id": 74432759,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 0,
"selected": false,
"text": "def check_22(num_list):\n for i in range(0, len(num_list)-1):\n if num_list[i] == 2 and num_list[i+1] == 2:\n return True\n return False\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501258/"
] |
74,432,719 | <p>I want to make a pyramid of a string for an exercise.
I just don't know how to do it.
For example:</p>
<pre><code>string = "these***are***just***random***words*"
</code></pre>
<p>and the pyramid I want to make is:</p>
<pre><code> t
hes
e***a
re***ju
st***rand
om***words*
</code></pre>
<p>How do I do this?</p>
<pre><code>def draw_pyramid(string, size):
if size > 15:
size = 15
if size < 5:
size = 5
l = string * size
for i in range(size + 1):
stars = i
p = l[0:stars]
spaces = size - i
print(" " * spaces + p)
def main():
size = int(input("How many layers do you want it to be?: "))
string = "these***are***just***random***words*"
draw_pyramid(string, size)
if __name__ == '__main__':
main()
</code></pre>
<p>Result:</p>
<pre><code>
t
th
the
thes
these
these*
these**
these***
these***a
these***ar
</code></pre>
| [
{
"answer_id": 74433125,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 0,
"selected": false,
"text": "l"
},
{
"answer_id": 74433139,
"author": "T C Molenaar",
"author_id": 8814131,
"author_profile": "https://Stackoverflow.com/users/8814131",
"pm_score": 2,
"selected": true,
"text": "string.center()"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17997138/"
] |
74,432,785 | <h1>Problem description</h1>
<p>I am trying to write a math test for my little son.
Such test must generate a list of random algebraic expressions according to certain rules and check the correctness of solution.</p>
<p>In particular, I want to generate expressions consisting strictly of a given number of operators that are selected from a certain list.
For example <em>generate a list of expression consisting of 3 operators of addition and subtraction in random order</em> like:</p>
<ul>
<li>12 - (5 + 2) + 2</li>
<li>3 + 4 - 2 + 10</li>
<li>and so on</li>
</ul>
<p>To represent and calculate the expression, I use the <em>binary expression tree</em> structure.
Each tree consists of either a <code>Leaf</code> or a <code>Node</code> that contains an <code>Operator</code> and two subtrees.
This is a simple recursive structure and I want to work with it only recursively.
No setters in the classes of the tree. I can only use constructors to create a tree.</p>
<h4>Leaf class</h4>
<pre><code>public final class Leaf implements Expression {
private final int value;
public Leaf(int value) {
this.value = value;
}
// ...
}
</code></pre>
<h4>Node Class</h4>
<pre><code>public final class Node implements Expression {
private final Operator operator;
private final Expression left;
private final Expression right;
public Node(@NotNull Operator operator,
@NotNull Expression left,
@NotNull Expression right) {
this.operator = operator;
this.left = left;
this.right = right;
}
// ...
}
</code></pre>
<p>And <code>Operator</code> is a simple <code>Enum</code> type. I simplify my classes for the purposes of this question.</p>
<h1>My issue</h1>
<p>I am trying to build an expression based on the following rules:</p>
<ul>
<li>There should be at least one operator in the expression, so my tree always starts from the <code>Node</code>.</li>
<li>I choose a random operator from a given list and increase the number of operators used</li>
<li>While this number less than the given number of operators I construct the left and rights subtree for current <code>Node</code>.</li>
<li>The left subtree can be randomly either a <code>Leaf</code> or <code>Node</code></li>
<li>The right subtree can also be either a <code>Leaf</code> or <code>Node</code>, but if the left subtree is a <code>Leaf</code> and there are still unused operators, then the right must be a <code>Node</code>.</li>
</ul>
<p>I wrote such an expression builder:</p>
<pre><code>public class SmartExpressionBuilder {
private final Random random = ThreadLocalRandom.current();
private final List<Operator> allowedOperators;
private final int numberOfOperators;
public SmartExpressionBuilder(List<Operator> allowedOperators, int numberOfOperators) {
this.allowedOperators = allowedOperators;
this.numberOfOperators = numberOfOperators;
}
private int operatorsUsed;
public Expression build() {
operatorsUsed = 0;
return helper();
}
private Expression helper() {
if (operatorsUsed == numberOfOperators) return randomLeaf();
Operator op = randomOperator();
Expression left = random.nextBoolean() ? helper() : randomLeaf();
Expression right = (left instanceof Leaf || random.nextBoolean()) ? helper() : randomLeaf();
return new Node(op, left, right);
}
private Operator randomOperator() {
operatorsUsed++;
return allowedOperators.get(random.nextInt(allowedOperators.size()));
}
private Leaf randomLeaf() {
return new Leaf(random.nextInt(1, 10));
}
public static void main(String[] args) {
final var builder = new SmartExpressionBuilder(List.of(Operator.ADD, Operator.SUB), 4);
IntStream.range(0, 10)
.mapToObj(ignored -> builder.build())
.forEach(exp -> {
System.out.printf("%s = %d%n", exp.infix(), exp.evaluate());
TreePrinter.print(exp);
});
}
}
</code></pre>
<p>This works in principle. In the sense that a tree really builds with a given number of operators.
But there's a problem.
I get nodes looks like this:</p>
<pre><code> Node Node
/ \ or / \
Leaf Node Node Leaf
</code></pre>
<p>For example my actual expression and tree may looks like this:</p>
<pre><code>4 + 4 - (1 + 3) - 2 = 2
+
4 -
- 2
4 +
1 3
</code></pre>
<p>but i never get tree like this:</p>
<pre><code> Node +
/ \ or - +
Node Node 5 2 2 -
6 1
</code></pre>
<p>I understand what the essence of the problem is.
In my recursive function, I always go into the left tree first.
And every time my random generates an the <code>Node</code> is in the left subtree, and not the <code>Leaf</code>, recursion dive deeper and deeper int the left subtree until unused operators ends.
This means that if an <code>Node</code> appeared in the left subtree, then <code>Node</code> cannot appear in the right at the same depths of tree.</p>
<p>I broke my brain, but did not figure out how to solve this problem without abandoning the recursive construction of my tree.</p>
<p>I would be very grateful for any ideas how build nodes of this kind</p>
<pre><code> Node
/ \
Node Node
</code></pre>
| [
{
"answer_id": 74433150,
"author": "Edward Peters",
"author_id": 6016064,
"author_profile": "https://Stackoverflow.com/users/6016064",
"pm_score": 2,
"selected": true,
"text": "size"
},
{
"answer_id": 74444601,
"author": "chptr-one",
"author_id": 13797513,
"author_profile": "https://Stackoverflow.com/users/13797513",
"pm_score": 0,
"selected": false,
"text": "Node"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13797513/"
] |
74,432,821 | <p>when i press login ,it triggered this body file,but it only show background png. It's not showing content of body file.</p>
<p>background.dart</p>
<pre><code>class Login_Background extends StatelessWidget {
const Login_Background({required this.size, required Column child});
final Size size;
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned(
top: 0,
left: 0,
child: Image.asset(
"android/assets/images/login_top.png",
width: size.width * .22,
)),
Positioned(
bottom: 0,
right: 0,
child: Image.asset(
"android/assets/images/login_bottom.png",
width: size.width * 0.31,
)),
],
);
}
}
</code></pre>
<h1>body.dart</h1>
<pre><code>class body extends StatelessWidget {
const body({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Login_Background(
size: size,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"login",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height*0.03),
Image.asset(
"android/assets/images/12085707_20944201.jpg",
height: 400,
width: 100,
),
RoundedInputField(
hintText: 'Your Email',
onChanged: (String value) {},
icon: Icons.person,
),
Rounded_password_field(
onChanged: (String value) {},
),
Roundedbutton(
text: "login",
press: () {},
color: kPrimaryColor,
textColor: kPrimaryColor,
),
already_have_an_accountcheck(press: (){},)
]));
}
}
</code></pre>
<p>i want to see body component when i hit login.</p>
<p><a href="https://i.stack.imgur.com/xdIYx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xdIYx.png" alt="image" /></a></p>
| [
{
"answer_id": 74432972,
"author": "Rahul",
"author_id": 16569443,
"author_profile": "https://Stackoverflow.com/users/16569443",
"pm_score": 0,
"selected": false,
"text": "child"
},
{
"answer_id": 74432977,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 2,
"selected": false,
"text": "return Stack(\n children: [\n Positioned(\n top: 0,\n left: 0,\n child: Image.asset(\n \"android/assets/images/login_top.png\",\n width: size.width * .22,\n )),\n Positioned(\n bottom: 0,\n right: 0,\n child: Image.asset(\n \"android/assets/images/login_bottom.png\",\n width: size.width * 0.31,\n )),\n // add this\n Positioned.fill( \n child : child\n )\n\n ],\n );\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15554800/"
] |
74,432,834 | <p>I have this string:</p>
<pre><code>'/api/media-objects/e78c7cfa-e469-4edd-8a87-9517a5b9e5da'
</code></pre>
<p>I want to return only the id ('<strong>e78c7cfa-e469-4edd-8a87-9517a5b9e5da</strong>') after the last '<strong>/</strong>'. The id changes everytime I make an API call. How can I do that using any String functions?</p>
| [
{
"answer_id": 74432972,
"author": "Rahul",
"author_id": 16569443,
"author_profile": "https://Stackoverflow.com/users/16569443",
"pm_score": 0,
"selected": false,
"text": "child"
},
{
"answer_id": 74432977,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 2,
"selected": false,
"text": "return Stack(\n children: [\n Positioned(\n top: 0,\n left: 0,\n child: Image.asset(\n \"android/assets/images/login_top.png\",\n width: size.width * .22,\n )),\n Positioned(\n bottom: 0,\n right: 0,\n child: Image.asset(\n \"android/assets/images/login_bottom.png\",\n width: size.width * 0.31,\n )),\n // add this\n Positioned.fill( \n child : child\n )\n\n ],\n );\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15611096/"
] |
74,432,838 | <p>So I'm trying to select 3 divs in my parent element. With my current code the result is I get 162 nodeLists back, instead of just the 3 main divs in that parent element.</p>
<p>The page code looks like this (simplified):</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var parent = document.querySelector('.parent');
var wantedChildren = parent.querySelectorAll('div');
console.log(wantedChildren);</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="parent">
<div class="wantedChild">
<div class="unwantedChild">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="unwantedChild"></div>
</div>
<div class="wantedChild">
<div class="unwantedChild"></div>
<div class="unwantedChild"></div>
</div>
<div class="wantedChild">
<div class="unwantedChild"></div>
<div class="unwantedChild"></div>
</div>
</div></code></pre>
</div>
</div>
</p>
<p>So the divs are just examples. The entire code on the page is way bigger.</p>
<p>I just want those 3 divs.</p>
<p>Does anybody know how to do this?</p>
| [
{
"answer_id": 74432972,
"author": "Rahul",
"author_id": 16569443,
"author_profile": "https://Stackoverflow.com/users/16569443",
"pm_score": 0,
"selected": false,
"text": "child"
},
{
"answer_id": 74432977,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 2,
"selected": false,
"text": "return Stack(\n children: [\n Positioned(\n top: 0,\n left: 0,\n child: Image.asset(\n \"android/assets/images/login_top.png\",\n width: size.width * .22,\n )),\n Positioned(\n bottom: 0,\n right: 0,\n child: Image.asset(\n \"android/assets/images/login_bottom.png\",\n width: size.width * 0.31,\n )),\n // add this\n Positioned.fill( \n child : child\n )\n\n ],\n );\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18371936/"
] |
74,432,847 | <p>I'm trying to write a Table-valued function in oracle, which contains a CTE.
I've been able to do it in SQL Server in this way:</p>
<pre><code>ALTER FUNCTION [dbo].[region_parents]
(
@regionId INT
)
RETURNS TABLE
AS
RETURN
(
WITH cte AS
(
SELECT id, owner_region_id FROM regions WHERE id = @regionId
UNION ALL
SELECT r.id, r.owner_region_id
FROM cte INNER JOIN
regions r ON cte.owner_region_id = r.id
)
SELECT id
FROM cte
)
</code></pre>
<p>This is needed in order to call it in a cross apply:</p>
<pre><code>SELECT *
FROM shops s
...
...
...
INNER JOIN locations l ON s.location_id = l.id
LEFT JOIN location_criteria lc ON lc.location_id = l.id
CROSS APPLY region_parents(l.region_id) r
</code></pre>
<p>In Oracle, I've tried to do it in this way, using User-Defined Datatypes:</p>
<pre><code>
CREATE OR REPLACE TYPE TABLE_RES_OBJ AS OBJECT (
id NUMBER
);
CREATE OR REPLACE TYPE TABLE_RES AS TABLE OF TABLE_RES_OBJ;
CREATE OR REPLACE FUNCTION region_parents (regionId IN INTEGER)
RETURN TABLE_RES
IS
cteresult TABLE_RES;
BEGIN
WITH cte(id, owner_region_id) AS
(
SELECT id AS id, owner_region_id AS owner_region_id FROM regions WHERE id = regionId
UNION ALL
SELECT r.id, r.owner_region_id
FROM cte INNER JOIN
regions r ON cte.owner_region_id = r.id
)
SELECT TABLE_RES(id)
BULK COLLECT INTO cteresult
FROM cte;
RETURN cteresult;
END;
/
</code></pre>
<p>The problem is that I obtain the following error:</p>
<p>PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER</p>
<p>I've also tried to achieve it in this <a href="https://stackoverflow.com/questions/53615259/oracle-table-function-from-cte">way</a>, without success.</p>
| [
{
"answer_id": 74433174,
"author": "Alex Poole",
"author_id": 266304,
"author_profile": "https://Stackoverflow.com/users/266304",
"pm_score": 1,
"selected": false,
"text": " SELECT TABLE_RES(id)\n BULK COLLECT INTO cteresult\n FROM cte;\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16813519/"
] |
74,432,848 | <p>I am trying to use HttpContextAccessor on my custom class(BLL class) and while i succesfully initializes the ContextAccessor meantime HttpContext itself is null.</p>
<p>Code in program.cs</p>
<pre><code>builder.Services.AddSingleton<IUserPermissionConfig, UserPermisionConfig>();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
var setUserPermission = app.Services.GetRequiredService<IUserPermissionConfig>();
setUserPermission.SetUserPermissionsSession(UserConstants.SYSTEM_ID);
</code></pre>
<p>UserPermisionConfig component code</p>
<pre><code> private readonly IHttpContextAccessor _httpContextAccessor;
public UserPermisionConfig( IHttpContextAccessor httpContextAccessor)
{
_permisionServiceClient = new PermissionServiceClient();
_httpContextAccessor = httpContextAccessor ?? throw new Exception("Http context accessor is null.");
}
public async Task SetUserPermissionsSession(int systemId)
{
string userName = _httpContextAccessor.HttpContext.
User.Identity.Name; //here httpcontext is alway null
UserPermissionsModel userPermissionModel = await GetUserPermission(systemId, userName);
_httpContextAccessor.HttpContext.Session.Set(UserConstants.SESSION_USER_PERMISSIOS, ByteArrayExtensions.ToByteArray(userPermissionModel));
}
</code></pre>
<p>Any help ?</p>
| [
{
"answer_id": 74433238,
"author": "José Ramírez",
"author_id": 13886104,
"author_profile": "https://Stackoverflow.com/users/13886104",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74441147,
"author": "Ruikai Feng",
"author_id": 18177989,
"author_profile": "https://Stackoverflow.com/users/18177989",
"pm_score": 1,
"selected": false,
"text": "Application_Start()"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7398819/"
] |
74,432,872 | <p>What is the recommended way to define <code>KafkaTemplate</code> when there are several different types of messages to send? Use just one <code>KafkaTemplate</code> for all messages (with <code>Object</code>) or define each <code>KafkaTemplate</code> for every type of messages?</p>
<p>One template <code>KafkaTemplate</code> with <code>Object</code>:</p>
<pre><code>// Object
@Bean
ProducerFactory<String, Object> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfiguration());
}
@Bean
KafkaTemplate<String, Object> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
</code></pre>
<p>Or multiple <code>KafkaTemplate</code>:</p>
<pre><code>// Address
@Bean
ProducerFactory<String, Address> addressProducerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfiguration());
}
@Bean
KafkaTemplate<String, Address> addressKafkaTemplate() {
return new KafkaTemplate<>(addressProducerFactory());
}
// Person
@Bean
ProducerFactory<String, Person> personProducerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfiguration());
}
@Bean
KafkaTemplate<String, Person> personPafkaTemplate() {
return new KafkaTemplate<>(personProducerFactory());
}
</code></pre>
<p>In the latter example <code>ProducerFactory</code> beans are also usually defined for every message type, which adds extra code. Do we really need them? It is ok just use a constructor, like this:</p>
<pre><code>// Address
@Bean
KafkaTemplate<String, Address> addressKafkaTemplate() {
return new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(producerConfiguration()));
}
// Person
@Bean
KafkaTemplate<String, Person> personPafkaTemplate() {
return new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(producerConfiguration()));
}
</code></pre>
| [
{
"answer_id": 74433238,
"author": "José Ramírez",
"author_id": 13886104,
"author_profile": "https://Stackoverflow.com/users/13886104",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74441147,
"author": "Ruikai Feng",
"author_id": 18177989,
"author_profile": "https://Stackoverflow.com/users/18177989",
"pm_score": 1,
"selected": false,
"text": "Application_Start()"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4003272/"
] |
74,432,955 | <p>I created a checkbox treeview with ttkwidgets. I want these checkboxes to be "checked" by default. How can I do that.</p>
<pre class="lang-Python prettyprint-override"><code>from tkinter import *
from ttkwidgets import CheckboxTreeview
import tkinter as tk
root = tk.Tk()
tree = CheckboxTreeview(root)
tree.pack()
list = [("apple"), ("banana"), ("orange")]
n=0
for x in list:
tree.insert(parent="", index="end", iid=n, text=x)
n+=1
root.mainloop()
</code></pre>
| [
{
"answer_id": 74433238,
"author": "José Ramírez",
"author_id": 13886104,
"author_profile": "https://Stackoverflow.com/users/13886104",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74441147,
"author": "Ruikai Feng",
"author_id": 18177989,
"author_profile": "https://Stackoverflow.com/users/18177989",
"pm_score": 1,
"selected": false,
"text": "Application_Start()"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18071313/"
] |
74,432,969 | <pre><code>import java.io.*;
import java.util.*;
public class Planets
{
public static void main(String[] args) throws IOException
{
Scanner in;
in = new Scanner(System.in);
boolean runAgain = true;
System.out.println("Starting program...\n\n");
double weight = getWeight();
while(runAgain)
{
String planet = getPlanet();
calculateWeight(weight, planet);
System.out.println("\nWould you like to see your weight on a different planet? (Yes or No)");
String input = in.nextLine();
if(input.charAt(0)=='N' || input.charAt(0)=='n')
{
runAgain = false;
}
}
} //end main
public static double getWeight() throws IOException
{ //Prompts user to enter their weight
Scanner in;
in = new Scanner(System.in);
System.out.println("Greetings! This program calculates how much you would weigh on other planets.\n\nPlease enter your weight (lbs.): ");
double weight = in.nextDouble();
return weight;
}
public static String getPlanet() throws IOException
{ //Prompts user to enter their planet
Scanner in;
in = new Scanner(System.in);
System.out.println("\nChoose your planet:\nSun\nMoon\nSaturn\nMercury\nMars\nUranus\nVenus\nJupiter\nNeptune");
String planet = in.nextLine();
return planet;
}
public static void calculateWeight(double weight, String planet) throws IOException
{ //Outputs the weight of the given planet ; takes two parameters weight and planet
switch(planet.charAt(0))
{
case 's':
case 'S':
switch(planet.charAt(1))
{
case 'u':
case 'U':
System.out.println("Your weight on the Earth is " + weight + " lbs.\nYour weight on the Sun is " + 27.94*weight);
break;
case 'a':
case 'A':
System.out.println("Your weight on the Earth is " + weight + " lbs.\nYour weight on Saturn is " + .91*weight);
break;
}
case 'm':
case 'M':
switch(planet.charAt(1))
{
case 'o':
case 'O':
System.out.println("Your weight on the Earth is " + weight + " lbs.\nYour weight on the Moon is " + .17*weight);
break;
case 'e':
case 'E':
System.out.println("Your weight on the Earth is " + weight + " lbs.\nYour weight on Mercury is " + .37*weight);
break;
case 'a':
case 'A':
System.out.println("Your weight on the Earth is " + weight + " lbs.\nYour weight on Mars is " + .38*weight);
break;
}
case 'u':
case 'U':
System.out.println("Your weight on Earth is " + weight + " lbs.\nYour weight on Uranus is " + .88*weight);
break;
case 'v':
case 'V':
System.out.println("Your weight on Earth is " + weight + " lbs.\nYour weight on Venus is " + .90*weight);
break;
case 'j':
case 'J':
System.out.println("Your weight on Earth is " + weight + " lbs.\nYour weight on Jupiter is " + 2.64*weight);
break;
case 'n':
case 'N':
System.out.println("Your weight on Earth is " + weight + " lbs.\nYour weight on Neptune is " + 1.12*weight);
break;
}
}
} //end class
</code></pre>
<p>Working on an assignment for my CS101 class. Our professor wants us to print our weight on a specific planet using nested switch statements with charAt to determine which planet the user is talking about. The nested switch statement is not doing as expected.</p>
<p>Errors:
When I pick Sun it outputs the result of Sun AND Uranus</p>
<p>When I pick Moon it outputs the result of Moon AND Uranus</p>
<p>When I pick Saturn it outputs the result of Saturn, Mars, AND Uranus.</p>
<p>When I pick Mercury it outputs the result of Mercury AND Uranus</p>
<p>When I pick Mars it outputs the result of Mars AND Mercury.</p>
<p>I don't understand why it is printing the result of multiple planets, even if the letter at the index does not match. Uranus, Venus, Jupiter, and Neptune works fine and prints as expected.</p>
| [
{
"answer_id": 74433238,
"author": "José Ramírez",
"author_id": 13886104,
"author_profile": "https://Stackoverflow.com/users/13886104",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74441147,
"author": "Ruikai Feng",
"author_id": 18177989,
"author_profile": "https://Stackoverflow.com/users/18177989",
"pm_score": 1,
"selected": false,
"text": "Application_Start()"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20451609/"
] |
74,432,999 | <p>I am trying to run a command that recognizes if the user is root or not, then run a script with parameters, and check the results. The problem is bash wont let me do it with <code>runuser</code>.</p>
<pre><code>#!/bin/bash
check_other_script(){
user=mruser
bin_dir=/home/$user/bin
script_name=myscript
decho "[d] Performing $script processing of settings check"
sub_cmd="${bin_dir}/${script_name} -s"
if [ "$running_user_type" == "root" ]; then
#cmd="runuser -l $user -c "$sub_cmd""
elif [ "$running_user_type" == "non-root" ]; then
cmd="$sub_cmd"
fi
decho "[d] command to run: $cmd"
$cmd
status="$?"
decho "[d] script status code: $status."
}
check_other_script
exit 0
</code></pre>
<p>Here is the output I get though:</p>
<pre><code>runuser -l mruser -c /home/mruser/bin/myscript -s
runuser: option requires an argument -- 's'
Try 'runuser --help' for more information.
</code></pre>
<p>Bash does not like how I am putting runuser into a variable and trying to use quotes in the command. It does not see the quotes and thinks <code>-s</code> is a parameter for runuser which it is not. I tried using single quotes an double quotes, nothing works.</p>
<pre><code>cmd="runuser -l $user -c "$sub_cmd""
cmd="runuser -l $user -c '$sub_cmd'"
cmd="runuser -l $user -c \"$sub_cmd\""
cmd='runuser -l $user -c '/home/mruser/bin/myscript -s''
</code></pre>
<p>How can I get runuser into a variable and have it run the command with a parameter without errors from runuser?</p>
| [
{
"answer_id": 74433264,
"author": "Arnaud Valmary",
"author_id": 6255757,
"author_profile": "https://Stackoverflow.com/users/6255757",
"pm_score": 1,
"selected": false,
"text": "...\nsub_cmd=\"ls -l \\\"xxxx\\\"\"\n...\ndeclare -a cmd=(\"runuser\" \"-l\" \"$user\" \"-c\" \"$sub_cmd\")\n...\n\"${cmd[@]}\"\n...\n"
},
{
"answer_id": 74433512,
"author": "Dave",
"author_id": 7211014,
"author_profile": "https://Stackoverflow.com/users/7211014",
"pm_score": 0,
"selected": false,
"text": "#!/bin/bash\ncheck_other_script(){\n user=mruser\n bin_dir=/home/$user/bin\n script_name=myscript\n decho \"[d] Performing $script processing of settings check\"\n sub_cmd=\"${bin_dir}/${script_name} -s\"\n if [ \"$running_user_type\" == \"root\" ]; then\n script_cmd(){\n runuser -l $user -c \"$sub_cmd\"\n }\n elif [ \"$running_user_type\" == \"non-root\" ]; then\n script_cmd(){\n $sub_cmd\n }\n fi\n script_cmd\n status=\"$?\"\n decho \"[d] script status code: $status.\"\n\n}\n\ncheck_other_script\nexit 0\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74432999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7211014/"
] |
74,433,000 | <p>I'm having an issue retrieving the MAX number from database.
The catch is that the numbers are in string format since they contain an underscore.</p>
<p>Example case:
I have 3 numbers in the database:</p>
<p>123456_1,
123456_2,
123456_13,</p>
<p>The MAX number I would like to fetch is 123456_13 (basically the biggest after underscore), but since they are string, Oracle processes them alphabetically and orders ascending as:</p>
<ol>
<li>123456_1</li>
<li>123456_13</li>
<li>123456_2</li>
</ol>
<p>making 123456_2 the MAX.</p>
<p>This would be possible, if I would not need to display the actual MAX or MIN number by replacing the underscore and converting to number:</p>
<pre><code>SELECT
MAX(TO_NUMBER(REPLACE(number,'_',''))) max_nr,
MIN(TO_NUMBER(REPLACE(number,'_',''))) min_nr
FROM
...
</code></pre>
<p>This would return
12345613 max_nr
1234561 min_nr
from my 3 examples, but I need to fetch the actual numbers with underscore and display that.</p>
<p>Is there any way to do this?</p>
| [
{
"answer_id": 74433264,
"author": "Arnaud Valmary",
"author_id": 6255757,
"author_profile": "https://Stackoverflow.com/users/6255757",
"pm_score": 1,
"selected": false,
"text": "...\nsub_cmd=\"ls -l \\\"xxxx\\\"\"\n...\ndeclare -a cmd=(\"runuser\" \"-l\" \"$user\" \"-c\" \"$sub_cmd\")\n...\n\"${cmd[@]}\"\n...\n"
},
{
"answer_id": 74433512,
"author": "Dave",
"author_id": 7211014,
"author_profile": "https://Stackoverflow.com/users/7211014",
"pm_score": 0,
"selected": false,
"text": "#!/bin/bash\ncheck_other_script(){\n user=mruser\n bin_dir=/home/$user/bin\n script_name=myscript\n decho \"[d] Performing $script processing of settings check\"\n sub_cmd=\"${bin_dir}/${script_name} -s\"\n if [ \"$running_user_type\" == \"root\" ]; then\n script_cmd(){\n runuser -l $user -c \"$sub_cmd\"\n }\n elif [ \"$running_user_type\" == \"non-root\" ]; then\n script_cmd(){\n $sub_cmd\n }\n fi\n script_cmd\n status=\"$?\"\n decho \"[d] script status code: $status.\"\n\n}\n\ncheck_other_script\nexit 0\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433000",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14619427/"
] |
74,433,007 | <p>I would like that the code below show an alert when an input email contains both "<code>@</code>" and "<code>.com</code>" when the submit button is clicked.</p>
<p>Currently, the alert is not showing up. Not sure whether the error has to do with the submit button or not.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code> function myFunction() {
const email = document.getElementById("e").value;
var button = document.getElementById("s").onclick;
if (email.includes('@') && (button.clicked == true)) {
alert("Thank you for subscribing!");
} else {
alert("Please enter a valid email.")
}
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>input {
border: 0;
padding: 10px;
font-size: 18px;
}
input[type="submit"] {
background: red;
color: white;
border: solid black;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type="email" placeholder="Your email" id="e">
<input type="submit" id="s"></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74433180,
"author": "GeirR",
"author_id": 2477938,
"author_profile": "https://Stackoverflow.com/users/2477938",
"pm_score": -1,
"selected": false,
"text": "<input type=\"email\" placeholder=\"Your email\" id=\"e\">\n<input type=\"submit\" id=\"s\" onClick=\"myFunction()\"\n"
},
{
"answer_id": 74433221,
"author": "18jad",
"author_id": 15927691,
"author_profile": "https://Stackoverflow.com/users/15927691",
"pm_score": -1,
"selected": false,
"text": "<input type=\"email\" placeholder=\"Your email\" id=\"email\">\n<button id=\"submit\">Submit</button>\n"
},
{
"answer_id": 74433227,
"author": "node_modules",
"author_id": 6060964,
"author_profile": "https://Stackoverflow.com/users/6060964",
"pm_score": 2,
"selected": true,
"text": "button.clicked"
},
{
"answer_id": 74433266,
"author": "Matias Bertoni",
"author_id": 19272564,
"author_profile": "https://Stackoverflow.com/users/19272564",
"pm_score": 0,
"selected": false,
"text": "const email = \"email@example.com\"\n\nif(email.indexOf(\"@\") !== -1 && email.split('.').at(-1) === \"com\") {\n //do something\n}\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11185390/"
] |
74,433,008 | <p>I have hourly data on electricity consumption for a specific day. I would like to use this data to "predict" the hourly electricity consumption for the following days. The value for the following day should be the value from the same hour the day before, multiplied by a scaling factor <code>f</code> (e.g. 2).</p>
<p>The dataframe <code>df</code> that I have looks something like this:</p>
<pre><code> load_kWh
2021-01-01 00:00:00 1.0
2021-01-01 01:00:00 1.0
2021-01-01 02:00:00 1.0
2021-01-01 03:00:00 1.0
2021-01-01 04:00:00 1.0
2021-01-01 05:00:00 1.0
2021-01-01 06:00:00 1.0
2021-01-01 07:00:00 3.0
2021-01-01 08:00:00 3.0
2021-01-01 09:00:00 3.0
2021-01-01 10:00:00 3.0
2021-01-01 11:00:00 3.0
2021-01-01 12:00:00 3.0
2021-01-01 13:00:00 3.0
2021-01-01 14:00:00 3.0
2021-01-01 15:00:00 3.0
2021-01-01 16:00:00 3.0
2021-01-01 17:00:00 3.0
2021-01-01 18:00:00 3.0
2021-01-01 19:00:00 3.0
2021-01-01 20:00:00 1.0
2021-01-01 21:00:00 1.0
2021-01-01 22:00:00 1.0
2021-01-01 23:00:00 1.0
</code></pre>
<p>And I would like the output dataframe <code>df_ex</code> to look something like this:</p>
<pre><code> load_kWh
2021-01-01 00:00:00 1.0
2021-01-01 01:00:00 1.0
2021-01-01 02:00:00 1.0
2021-01-01 03:00:00 1.0
2021-01-01 04:00:00 1.0
2021-01-01 05:00:00 1.0
2021-01-01 06:00:00 1.0
2021-01-01 07:00:00 3.0
2021-01-01 08:00:00 3.0
2021-01-01 09:00:00 3.0
2021-01-01 10:00:00 3.0
2021-01-01 11:00:00 3.0
2021-01-01 12:00:00 3.0
2021-01-01 13:00:00 3.0
2021-01-01 14:00:00 3.0
2021-01-01 15:00:00 3.0
2021-01-01 16:00:00 3.0
2021-01-01 17:00:00 3.0
2021-01-01 18:00:00 3.0
2021-01-01 19:00:00 3.0
2021-01-01 20:00:00 1.0
2021-01-01 21:00:00 1.0
2021-01-01 22:00:00 1.0
2021-01-01 23:00:00 1.0
2021-01-02 00:00:00 2.0
2021-01-02 01:00:00 2.0
2021-01-02 02:00:00 2.0
2021-01-02 03:00:00 2.0
2021-01-02 04:00:00 2.0
2021-01-02 05:00:00 2.0
2021-01-02 06:00:00 2.0
2021-01-02 07:00:00 6.0
2021-01-02 08:00:00 6.0
2021-01-02 09:00:00 6.0
2021-01-02 10:00:00 6.0
2021-01-02 11:00:00 6.0
2021-01-02 12:00:00 6.0
2021-01-02 13:00:00 6.0
2021-01-02 14:00:00 6.0
2021-01-02 15:00:00 6.0
2021-01-02 16:00:00 6.0
2021-01-02 17:00:00 6.0
2021-01-02 18:00:00 6.0
2021-01-02 19:00:00 6.0
2021-01-02 20:00:00 2.0
2021-01-02 21:00:00 2.0
2021-01-02 22:00:00 2.0
2021-01-02 23:00:00 2.0
2021-01-03 00:00:00 4.0
2021-01-03 01:00:00 4.0
2021-01-03 02:00:00 4.0
2021-01-03 03:00:00 4.0
2021-01-03 04:00:00 4.0
2021-01-03 05:00:00 4.0
2021-01-03 06:00:00 4.0
2021-01-03 07:00:00 12.0
2021-01-03 08:00:00 12.0
2021-01-03 09:00:00 12.0
2021-01-03 10:00:00 12.0
2021-01-03 11:00:00 12.0
2021-01-03 12:00:00 12.0
2021-01-03 13:00:00 12.0
2021-01-03 14:00:00 12.0
2021-01-03 15:00:00 12.0
2021-01-03 16:00:00 4.0
2021-01-03 17:00:00 4.0
2021-01-03 18:00:00 4.0
2021-01-03 19:00:00 4.0
2021-01-03 20:00:00 4.0
2021-01-03 21:00:00 4.0
2021-01-03 22:00:00 4.0
2021-01-03 23:00:00 4.0
</code></pre>
<p>I have tried the following solution (<code>df</code> as defined above):</p>
<pre><code>import pandas as pd
import datetime
start = '2021-01-01 00:00'
end = '2021-01-03 23:00'
freq = 'H'
index = pd.date_range(start,
end,
freq=freq)
df_ex = df.reindex(index)
i = df_ex.index[0].day
f = 2.0
df_ex.loc[df_ex.index.day == i+1] = df_ex.loc[df_ex.index.day == i] * f
print(df_ex)
</code></pre>
<p>Which results in:</p>
<pre><code> load_kWh
2021-01-01 00:00:00 1.0
2021-01-01 01:00:00 1.0
2021-01-01 02:00:00 1.0
2021-01-01 03:00:00 1.0
2021-01-01 04:00:00 1.0
... ...
2021-01-03 19:00:00 NaN
2021-01-03 20:00:00 NaN
2021-01-03 21:00:00 NaN
2021-01-03 22:00:00 NaN
2021-01-03 23:00:00 NaN
</code></pre>
<p>It appears that my attempt to populate the rows after the first day with values did not succeed. The index is a DateTimeIndex.</p>
<p>Any suggestions on how to solve this would be greatly appreciated!</p>
| [
{
"answer_id": 74433180,
"author": "GeirR",
"author_id": 2477938,
"author_profile": "https://Stackoverflow.com/users/2477938",
"pm_score": -1,
"selected": false,
"text": "<input type=\"email\" placeholder=\"Your email\" id=\"e\">\n<input type=\"submit\" id=\"s\" onClick=\"myFunction()\"\n"
},
{
"answer_id": 74433221,
"author": "18jad",
"author_id": 15927691,
"author_profile": "https://Stackoverflow.com/users/15927691",
"pm_score": -1,
"selected": false,
"text": "<input type=\"email\" placeholder=\"Your email\" id=\"email\">\n<button id=\"submit\">Submit</button>\n"
},
{
"answer_id": 74433227,
"author": "node_modules",
"author_id": 6060964,
"author_profile": "https://Stackoverflow.com/users/6060964",
"pm_score": 2,
"selected": true,
"text": "button.clicked"
},
{
"answer_id": 74433266,
"author": "Matias Bertoni",
"author_id": 19272564,
"author_profile": "https://Stackoverflow.com/users/19272564",
"pm_score": 0,
"selected": false,
"text": "const email = \"email@example.com\"\n\nif(email.indexOf(\"@\") !== -1 && email.split('.').at(-1) === \"com\") {\n //do something\n}\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14490607/"
] |
74,433,052 | <p>We have a camera that streams RAW8 video at 1920x1080. The GUID used is GREY. We are able to stream video from this camera using ffmpeg on Windows with the below command:</p>
<pre><code>ffmpeg -f dshow -pix_fmt gray -video_size 1920x1080 -i video="CAM0" -f nut - | ffplay -
</code></pre>
<p>We are now trying to grab images from this camera using OpenCV using the below code snippet, but its unable to grab any frame (frame_grabbed is always false)</p>
<pre><code>import cv2
import numpy as np
# reading the video from CAM0
source = cv2.VideoCapture(1)
height = 1920
width = 1080
source.set(cv2.CAP_PROP_FRAME_WIDTH, width)
source.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
image = np.zeros([height, width, 3], np.uint8)
while True:
# Extracting the frames
frame_grabbed , image = source.read()
if (frame_grabbed ):
colour1 = cv2.cvtColor(image, cv2.COLOR_BayerRG2BGR)
cv2.imshow("Demosaiced image", colour1)
else:
print("No images grabbed")
#Exit on q
key = cv2.waitKey(1)
if key == ord("q"):
break
# closing the window
cv2.destroyAllWindows()
source.release()
</code></pre>
<p>Are we missing something here?</p>
<p>We then came across this post to pipe ffmpeg output to python (<a href="https://stackoverflow.com/questions/71349914/using-ffmpeg-command-to-read-the-frame-and-show-using-the-inshow-function-in-ope">link</a>). However, when we are passing the command as below:</p>
<pre><code>command = [ 'ffmpeg.exe',
'-f', 'dshow',
'-i', 'video="CAM0"',
'-pix_fmt', 'gray',
'-video_size','1920x1080'
'-f', 'nut', '-']
</code></pre>
<p>its throwing</p>
<blockquote>
<p>Could not find video device with name ["CAM0"] among source devices
of type video. video="CAM0": I/O error</p>
</blockquote>
<p>I have verified that the camera is present using the below command:</p>
<pre><code>command = [ 'ffmpeg.exe',
'-list_devices', 'true',
'-f', 'dshow',
'-i', 'dummy']
</code></pre>
<p>This detects CAM0 as shown below:</p>
<pre><code>ffmpeg version 5.0.1-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 11.2.0 (Rev7, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab
--enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.100
libpostproc 56. 3.100 / 56. 3.100
[dshow @ 000001ea39e40600] "HP HD Camera" (video)
[dshow @ 000001ea39e40600] Alternative name "@device_pnp_\\?\usb#vid_04f2&pid_b6bf&mi_00#6&1737142c&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 000001ea39e40600] "CAM0" (video)
[dshow @ 000001ea39e40600] Alternative name "@device_pnp_\\?\usb#vid_0400&pid_0011&mi_00#7&1affbd5b&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
</code></pre>
<p>In short, we are able to capture video using ffmpeg commandline, but unable to grab any frame using OpenCV videocapture or ffmpeg in opencv. Any pointers?</p>
<p>Thanks!</p>
| [
{
"answer_id": 74433662,
"author": "kesh",
"author_id": 4516027,
"author_profile": "https://Stackoverflow.com/users/4516027",
"pm_score": 0,
"selected": false,
"text": "'rawvide'"
},
{
"answer_id": 74436041,
"author": "Rotem",
"author_id": 4926757,
"author_profile": "https://Stackoverflow.com/users/4926757",
"pm_score": 1,
"selected": false,
"text": "stdout"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13250657/"
] |
74,433,057 | <p>I'm trying to create a vertical line using CSS that contains multiple dots. However, I'm not quite sure how to do that.</p>
<p>Could anyone help me out with this?</p>
<p>I want to create something just like this one here.</p>
<p><a href="https://i.stack.imgur.com/itDPc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/itDPc.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74433705,
"author": "Ponsiva",
"author_id": 9936892,
"author_profile": "https://Stackoverflow.com/users/9936892",
"pm_score": 3,
"selected": true,
"text": "vertical wizard"
},
{
"answer_id": 74433816,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 1,
"selected": false,
"text": "<svg width=\"100\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\">\n <defs>\n <pattern id=\"pattern\" x=\"0\" y=\"0\" width=\"1\" height=\".2\">\n <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"100\" style=\"stroke:rgb(255,0,0);stroke-width:3\" />\n <circle cx=\"10\" cy=\"50\" r=\"6\" stroke=\"white\" stroke-width=\"4\" fill=\"red\" />\n </pattern>\n </defs>\n \n <rect fill=\"url(#pattern)\" width=\"100\" height=\"400\" />\n</svg>"
},
{
"answer_id": 74434023,
"author": "Yarden Buzaglo",
"author_id": 19441159,
"author_profile": "https://Stackoverflow.com/users/19441159",
"pm_score": 1,
"selected": false,
"text": ".container {\n background-color: rgb(173, 173, 216);\n width: 50px;\n height: 400px;\n display: flex;\n justify-content: center;\n}\n.vl {\n\n\n width: 5px;\n height: 400px;\n background-color: red;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n \n }\n.rnd {\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background-color: yellow;\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19389593/"
] |
74,433,089 | <p>I have 2 tables from google sheets. df1 where it has the users completion of different modules. And df2 that consists of user details.</p>
<p>df1:</p>
<p><img src="https://i.stack.imgur.com/mUogD.png" alt="df1" /></p>
<p>df2:</p>
<p><img src="https://i.stack.imgur.com/a7OE7.png" alt="df2" /></p>
<p>I want to merge tables just like the image below. Currently, I am able to achieve this using array vlookup. Sometimes I also use index match. But it takes forever because in reality, df1 has atleast 50000 rows, that is 40 modules for roughly 5000 users. I am new to python and pandas.</p>
<p>output:</p>
<p><img src="https://i.stack.imgur.com/s45Q0.png" alt="Completion tbl" /></p>
<p>Thank you in advance!</p>
| [
{
"answer_id": 74433705,
"author": "Ponsiva",
"author_id": 9936892,
"author_profile": "https://Stackoverflow.com/users/9936892",
"pm_score": 3,
"selected": true,
"text": "vertical wizard"
},
{
"answer_id": 74433816,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 1,
"selected": false,
"text": "<svg width=\"100\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\">\n <defs>\n <pattern id=\"pattern\" x=\"0\" y=\"0\" width=\"1\" height=\".2\">\n <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"100\" style=\"stroke:rgb(255,0,0);stroke-width:3\" />\n <circle cx=\"10\" cy=\"50\" r=\"6\" stroke=\"white\" stroke-width=\"4\" fill=\"red\" />\n </pattern>\n </defs>\n \n <rect fill=\"url(#pattern)\" width=\"100\" height=\"400\" />\n</svg>"
},
{
"answer_id": 74434023,
"author": "Yarden Buzaglo",
"author_id": 19441159,
"author_profile": "https://Stackoverflow.com/users/19441159",
"pm_score": 1,
"selected": false,
"text": ".container {\n background-color: rgb(173, 173, 216);\n width: 50px;\n height: 400px;\n display: flex;\n justify-content: center;\n}\n.vl {\n\n\n width: 5px;\n height: 400px;\n background-color: red;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n \n }\n.rnd {\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background-color: yellow;\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13365777/"
] |
74,433,103 | <p>I'm unable to display a Shiny reactive DT within the tabPanel. May I know where the bug is?</p>
<p>The dataset is from Hong Kong Government. It is about the departure / arrival population from various control points since 2021: <a href="https://www.immd.gov.hk/opendata/eng/transport/immigration_clearance/statistics_on_daily_passenger_traffic.csv" rel="nofollow noreferrer">https://www.immd.gov.hk/opendata/eng/transport/immigration_clearance/statistics_on_daily_passenger_traffic.csv</a></p>
<p>I slightly tidy a bit the columns:</p>
<pre><code>library(readr)
library(dplyr)
statistics_on_daily_passenger_traffic <-
read_csv(
"C:/Users/User/Downloads/statistics_on_daily_passenger_traffic.csv"
)
df <- statistics_on_daily_passenger_traffic
df <- df %>%
select(-ncol(df))
</code></pre>
<p>The UI is fine. But the server code has problems for my first tabPanel already:</p>
<pre><code>library(shiny)
library(DT)
ui <-
fluidPage(
titlePanel("Daily passenger traffic at control points in Hong Kong"),
sidebarLayout(
sidebarPanel(
selectInput(
'control_point',
'Select Control Point',
unique(df$`Control Point`)
),
radioButtons(
'arrival_departure',
'Travel',
unique(df$`Arrival / Departure`)
),
dateRangeInput(
'date_range',
'Select Date',
start = '2021-01-01',
end = Sys.Date() - 1,
min = '2021-01-01',
max = Sys.Date() - 1
)
),
mainPanel(tabsetPanel(
tabPanel('Hong Kong Residents', DT::DTOutput('plot_hk')),
tabPanel('Mainland Visitors'),
tabPanel('Other Visitors'),
tabPanel('Total')
))
)
)
server <- function(input, output, session) {
rval_plot_hk <- reactive({
output$plot_hk <- DT::renderDT({
df %>% filter(
date >= input$date_range[1],
date <= input$date_range[2],
control_point <- input$control_point,
arrival_departure <- input$arrival_departure
)
})
})
}
shinyApp(ui, server)
</code></pre>
<p><a href="https://i.stack.imgur.com/pSrQB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pSrQB.jpg" alt="enter image description here" /></a></p>
<p>Also, may I know how to plot the graph showing the time changes using <code>plotly</code>? I only know how to plot in static version:</p>
<pre><code>df %>%
mutate(Date = as.Date(Date, format = "%d-%m-%Y")) %>%
filter(`Control Point` == "Airport") %>%
gather(Item, Count, `Hong Kong Residents`:Total) %>%
ggplot(aes(
x = Date,
y = Count,
fill = Item,
color = `Arrival / Departure`
)) +
ggtitle("Daily passenger traffic") +
scale_x_date(date_labels = "%y/%m", date_breaks = "3 month") +
theme(legend.position = "bottom") +
geom_line() +
facet_wrap( ~ Item)
</code></pre>
<p>Thank you for your help.</p>
| [
{
"answer_id": 74433705,
"author": "Ponsiva",
"author_id": 9936892,
"author_profile": "https://Stackoverflow.com/users/9936892",
"pm_score": 3,
"selected": true,
"text": "vertical wizard"
},
{
"answer_id": 74433816,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 1,
"selected": false,
"text": "<svg width=\"100\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\">\n <defs>\n <pattern id=\"pattern\" x=\"0\" y=\"0\" width=\"1\" height=\".2\">\n <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"100\" style=\"stroke:rgb(255,0,0);stroke-width:3\" />\n <circle cx=\"10\" cy=\"50\" r=\"6\" stroke=\"white\" stroke-width=\"4\" fill=\"red\" />\n </pattern>\n </defs>\n \n <rect fill=\"url(#pattern)\" width=\"100\" height=\"400\" />\n</svg>"
},
{
"answer_id": 74434023,
"author": "Yarden Buzaglo",
"author_id": 19441159,
"author_profile": "https://Stackoverflow.com/users/19441159",
"pm_score": 1,
"selected": false,
"text": ".container {\n background-color: rgb(173, 173, 216);\n width: 50px;\n height: 400px;\n display: flex;\n justify-content: center;\n}\n.vl {\n\n\n width: 5px;\n height: 400px;\n background-color: red;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n \n }\n.rnd {\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background-color: yellow;\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4225430/"
] |
74,433,120 | <p>I have been reading about RDD's a lot but something that I don't quite understand how is RDD distributed when there is no replication in Apache spark?</p>
<p>The post[1] says that</p>
<blockquote>
<p>To achieve Spark fault tolerance for all the RDDs, the entire data is
copied across multiple nodes in the cluster.</p>
</blockquote>
<p>As per my understanding, If this this the case then there should be data replication, but most articles says the DAG is the way spark achieves fault tolerance.</p>
<p>Can someone explain a bit detail on this?</p>
<p>[1]: <a href="https://hevodata.com/learn/spark-fault-tolerance/#:%7E:text=Spark%20Fault%20Tolerance%20is%20the,or%20more%20faults%20within%20them" rel="nofollow noreferrer">https://hevodata.com/learn/spark-fault-tolerance/#:~:text=Spark%20Fault%20Tolerance%20is%20the,or%20more%20faults%20within%20them</a>).</p>
| [
{
"answer_id": 74433705,
"author": "Ponsiva",
"author_id": 9936892,
"author_profile": "https://Stackoverflow.com/users/9936892",
"pm_score": 3,
"selected": true,
"text": "vertical wizard"
},
{
"answer_id": 74433816,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 1,
"selected": false,
"text": "<svg width=\"100\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\">\n <defs>\n <pattern id=\"pattern\" x=\"0\" y=\"0\" width=\"1\" height=\".2\">\n <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"100\" style=\"stroke:rgb(255,0,0);stroke-width:3\" />\n <circle cx=\"10\" cy=\"50\" r=\"6\" stroke=\"white\" stroke-width=\"4\" fill=\"red\" />\n </pattern>\n </defs>\n \n <rect fill=\"url(#pattern)\" width=\"100\" height=\"400\" />\n</svg>"
},
{
"answer_id": 74434023,
"author": "Yarden Buzaglo",
"author_id": 19441159,
"author_profile": "https://Stackoverflow.com/users/19441159",
"pm_score": 1,
"selected": false,
"text": ".container {\n background-color: rgb(173, 173, 216);\n width: 50px;\n height: 400px;\n display: flex;\n justify-content: center;\n}\n.vl {\n\n\n width: 5px;\n height: 400px;\n background-color: red;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n \n }\n.rnd {\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background-color: yellow;\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15074748/"
] |
74,433,147 | <p>I have a c program:</p>
<pre><code>#include<stdio.h>
long fibo(int n);
int main(void)
{
int input = 0;
printf("Enter your number: ");
scanf("%i", &input);
/*check buffer*/
if (getchar() != '\n' || input <= 0)
{
printf("Try again\n");
return 0;
}
printf("result: %li\n", fibo(input));
return 1;
}
long fibo(int n)
{
if (n > 2)
{
return fibo(n - 1) + fibo(n - 2);
}
else
{
return 1;
}
}
</code></pre>
<p>I compiled it with gcc.</p>
<pre><code>000035e0: 735f 7374 6172 7400 6d61 696e 0066 6962 s_start.**main.fib**
000035f0: 6f00 5f5f 6973 6f63 3939 5f73 6361 6e66 **o**.__isoc99_scanf
</code></pre>
<p>When I review compile file, I see functions name(main and fibo) but I couldn't find variables name.</p>
<p>My question is why compiler keep function name? And what is usage? If for developersreview binery file and deassembling why didn't save variables name?</p>
<p>I am new</p>
<p><a href="https://i.stack.imgur.com/HRfl9.jpg" rel="nofollow noreferrer">Objdump</a></p>
| [
{
"answer_id": 74433705,
"author": "Ponsiva",
"author_id": 9936892,
"author_profile": "https://Stackoverflow.com/users/9936892",
"pm_score": 3,
"selected": true,
"text": "vertical wizard"
},
{
"answer_id": 74433816,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 1,
"selected": false,
"text": "<svg width=\"100\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\">\n <defs>\n <pattern id=\"pattern\" x=\"0\" y=\"0\" width=\"1\" height=\".2\">\n <line x1=\"10\" y1=\"0\" x2=\"10\" y2=\"100\" style=\"stroke:rgb(255,0,0);stroke-width:3\" />\n <circle cx=\"10\" cy=\"50\" r=\"6\" stroke=\"white\" stroke-width=\"4\" fill=\"red\" />\n </pattern>\n </defs>\n \n <rect fill=\"url(#pattern)\" width=\"100\" height=\"400\" />\n</svg>"
},
{
"answer_id": 74434023,
"author": "Yarden Buzaglo",
"author_id": 19441159,
"author_profile": "https://Stackoverflow.com/users/19441159",
"pm_score": 1,
"selected": false,
"text": ".container {\n background-color: rgb(173, 173, 216);\n width: 50px;\n height: 400px;\n display: flex;\n justify-content: center;\n}\n.vl {\n\n\n width: 5px;\n height: 400px;\n background-color: red;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n align-items: center;\n \n }\n.rnd {\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background-color: yellow;\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19965005/"
] |
74,433,172 | <p>I'm trying to update the state and show shadow in nav if user scrolls but it's not listening to the event. <br/> i'm using nextJS 13 and tailwind css.</p>
<pre><code>const [shadow, setShadow] = useState(false);
useEffect(() => {
const handleShadow = () => {
if (window.scrollY >= 90) {
setShadow(true);
} else {
setShadow(false);
}
window.addEventListener("scroll", handleShadow, true);
};
return window.removeEventListener("scroll", handleShadow);
}, []);
</code></pre>
<p>in my div</p>
<pre><code><div
className={
shadow
? "fixed left-0 top-0 w-full z-10 ease-in duration-300 bg-[#112240] shadow-xl"
: "fixed left-0 top-0 w-full z-10 ease-in duration-300 bg-[#112240]"
}
>
other code
</div>
</code></pre>
| [
{
"answer_id": 74435317,
"author": "IGnyte",
"author_id": 15370799,
"author_profile": "https://Stackoverflow.com/users/15370799",
"pm_score": 3,
"selected": true,
"text": "handleShadow"
},
{
"answer_id": 74437676,
"author": "Dan Block",
"author_id": 19593206,
"author_profile": "https://Stackoverflow.com/users/19593206",
"pm_score": -1,
"selected": false,
"text": "useEffect(() => {\nconst handleShadow = () => {\n if (window.scrollY >= 90) {\n setShadow(true);\n } else {\n setShadow(false);\n }\n};\nwindow.addEventListener(\"scroll\", handleShadow);\n }, []);\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12256795/"
] |
74,433,173 | <p>I have a list:</p>
<pre><code>lst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']
</code></pre>
<p>I would like to take 2 random values from this list and put them in to a new list as pairs until the original list is empty.</p>
<p>For example:</p>
<p>new_list = [('ab', 'ef'), ('ij', 'yz') exc. ]
lst = []</p>
<p>How can I do this using a while and for loop?</p>
<p>I've tried using this method to generate a random pair from the list:</p>
<pre><code>random_lst = random.randint(0,len(lst)-1)
</code></pre>
<p>However I'm not sure how to remove the values from the original lsit and then add them to the new list as pairs.</p>
| [
{
"answer_id": 74433258,
"author": "YOLO",
"author_id": 9299259,
"author_profile": "https://Stackoverflow.com/users/9299259",
"pm_score": -1,
"selected": false,
"text": "np.random.choice"
},
{
"answer_id": 74433280,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 1,
"selected": true,
"text": "import random\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nnew_list = []\n\nfor i in range(len(lst)//2):\n # Get a random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove the respective element and store it\n element1 = lst.pop(idx)\n # Get another random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove and store that element as well\n element2 = lst.pop(idx)\n # Create an entry (tuple) in the final list\n new_list.append((element1, element2))\n\nprint(new_list)\n"
},
{
"answer_id": 74433297,
"author": "Johnny Mopp",
"author_id": 669576,
"author_profile": "https://Stackoverflow.com/users/669576",
"pm_score": 1,
"selected": false,
"text": "lst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nresult = []\nrandom.shuffle(lst)\nfor i in range(0, len(lst), 2):\n result.append((lst[i], lst[i+1]))\n"
},
{
"answer_id": 74433404,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "from random import sample as SAMPLE\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\noutput = []\n\nwhile lst:\n output.append(SAMPLE(lst, min(2, len(lst))))\n for e in output[-1]:\n lst.remove(e)\n\nprint(output)\n"
},
{
"answer_id": 74433593,
"author": "scoochy",
"author_id": 13791656,
"author_profile": "https://Stackoverflow.com/users/13791656",
"pm_score": 0,
"selected": false,
"text": "import random\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nrandom_lst = []\nwhile lst:\n random_lst.append((lst.pop(random.randint(0,len(lst)-1)), lst.pop(random.randint(0,len(lst)-1))))\n\nprint(random_lst)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20223442/"
] |
74,433,194 | <p>I am working with a handful of dataframes whose information I would like to combine.</p>
<pre><code>df1 <- data.frame(id = c(1, 1, 2, 2), year = c(1990, 2000, 1990, 2000))
df1990 <- data.frame(id = c(1, 2), year = c(1990, 1990), X= c(1, 2))
df2000 <- data.frame(id = c(1, 2), year = c(2000, 2000), X= c(1, 2))
</code></pre>
<p>Above is code for creating toy inputs.
I want to append the information in df2 and df3 to df1, resulting in a dataframe like this</p>
<pre><code>df <- data.frame(id = c(1, 1, 2, 2), year = c(1990, 2000, 1990, 2000), X = c(1, 1, 2, 2))
</code></pre>
<p>To do this, my first thought was to use <code>left_join()</code> but I can only do this successfully once -- it works with the first attempted merge, but the NAs remain NAs when I try to do a second merge.
So I run:</p>
<pre><code>df <- left_join(df1, df1990)
df <- left_join(df, df2000)
</code></pre>
<p>But I still have NAs.
Any idea how I can fix this?</p>
| [
{
"answer_id": 74433258,
"author": "YOLO",
"author_id": 9299259,
"author_profile": "https://Stackoverflow.com/users/9299259",
"pm_score": -1,
"selected": false,
"text": "np.random.choice"
},
{
"answer_id": 74433280,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 1,
"selected": true,
"text": "import random\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nnew_list = []\n\nfor i in range(len(lst)//2):\n # Get a random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove the respective element and store it\n element1 = lst.pop(idx)\n # Get another random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove and store that element as well\n element2 = lst.pop(idx)\n # Create an entry (tuple) in the final list\n new_list.append((element1, element2))\n\nprint(new_list)\n"
},
{
"answer_id": 74433297,
"author": "Johnny Mopp",
"author_id": 669576,
"author_profile": "https://Stackoverflow.com/users/669576",
"pm_score": 1,
"selected": false,
"text": "lst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nresult = []\nrandom.shuffle(lst)\nfor i in range(0, len(lst), 2):\n result.append((lst[i], lst[i+1]))\n"
},
{
"answer_id": 74433404,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "from random import sample as SAMPLE\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\noutput = []\n\nwhile lst:\n output.append(SAMPLE(lst, min(2, len(lst))))\n for e in output[-1]:\n lst.remove(e)\n\nprint(output)\n"
},
{
"answer_id": 74433593,
"author": "scoochy",
"author_id": 13791656,
"author_profile": "https://Stackoverflow.com/users/13791656",
"pm_score": 0,
"selected": false,
"text": "import random\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nrandom_lst = []\nwhile lst:\n random_lst.append((lst.pop(random.randint(0,len(lst)-1)), lst.pop(random.randint(0,len(lst)-1))))\n\nprint(random_lst)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11370167/"
] |
74,433,243 | <p>I downloaded ServiceAccountKey.json to make local cloud functions env.
I think ServiceAccountKey.json should not be public and it should not be in GCP.
So when I deploy cloud functions, how do I exclude it?
Or is that no problem to upload ServiceAccountKey.json using <code>firebase deploy --only functions</code>?
Please teach me how to do. Thank you.</p>
| [
{
"answer_id": 74433258,
"author": "YOLO",
"author_id": 9299259,
"author_profile": "https://Stackoverflow.com/users/9299259",
"pm_score": -1,
"selected": false,
"text": "np.random.choice"
},
{
"answer_id": 74433280,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 1,
"selected": true,
"text": "import random\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nnew_list = []\n\nfor i in range(len(lst)//2):\n # Get a random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove the respective element and store it\n element1 = lst.pop(idx)\n # Get another random index in the current list\n idx = random.randint(0,len(lst)-1)\n # Remove and store that element as well\n element2 = lst.pop(idx)\n # Create an entry (tuple) in the final list\n new_list.append((element1, element2))\n\nprint(new_list)\n"
},
{
"answer_id": 74433297,
"author": "Johnny Mopp",
"author_id": 669576,
"author_profile": "https://Stackoverflow.com/users/669576",
"pm_score": 1,
"selected": false,
"text": "lst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nresult = []\nrandom.shuffle(lst)\nfor i in range(0, len(lst), 2):\n result.append((lst[i], lst[i+1]))\n"
},
{
"answer_id": 74433404,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "from random import sample as SAMPLE\n\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\noutput = []\n\nwhile lst:\n output.append(SAMPLE(lst, min(2, len(lst))))\n for e in output[-1]:\n lst.remove(e)\n\nprint(output)\n"
},
{
"answer_id": 74433593,
"author": "scoochy",
"author_id": 13791656,
"author_profile": "https://Stackoverflow.com/users/13791656",
"pm_score": 0,
"selected": false,
"text": "import random\nlst = ['ab', 'cd','ef', 'gh', 'ij', 'mn', 'op', 'qr', 'st', 'uv', 'wx', 'yz']\nrandom_lst = []\nwhile lst:\n random_lst.append((lst.pop(random.randint(0,len(lst)-1)), lst.pop(random.randint(0,len(lst)-1))))\n\nprint(random_lst)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16375313/"
] |
74,433,246 | <p>I just discovered that iterating the rows of a pandas dataframe, and making updates to each row, does not update the dataframe! Is this expected behaviour, or does one need to do something to the row first so the update reflects in the parent dataframe?</p>
<p>I know one could update the dataframe directly in the loop, or with a simple recalculation on the column in this simple/contrived example, but my question is about the fact that iterrows() seems to provide copies of the rows rather than references to the actual rows in the dataframe. Is there a reason for this?</p>
<pre><code>import pandas as pd
fruit = {"Fruit": ['Apple','Avacado','Banana','Strawberry','Grape'],"Color": ['Red','Green','Yellow','Pink','Green'],
"Price": [45, 90, 60, 37, 49]
}
df = pd.DataFrame(fruit)
for index, row in df.iterrows():
row['Price'] = row['Price'] * 2
print(row['Price']) # the price is doubled here as expected
print(df['Price']) # the original values of price in the dataframe are unchanged
</code></pre>
| [
{
"answer_id": 74433271,
"author": "Celius Stingher",
"author_id": 11897007,
"author_profile": "https://Stackoverflow.com/users/11897007",
"pm_score": 1,
"selected": false,
"text": "row['Price']"
},
{
"answer_id": 74433289,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 0,
"selected": false,
"text": "for index, row in df.iterrows():\n df.loc[index, 'Price'] = row['Price'] * 2\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3210158/"
] |
74,433,255 | <p>I have an HTML input element. I want the element to be in the center, but because the right margin is not working, the element is slightly off to the right. <code>box-sizing: border-box;</code> does not resolve the issue.</p>
<p>My code</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
margin: 0;
padding: 10px;
font-family: Arial, Helvetica, sans-serif;
}
* {
margin: 40px;
padding: 10px;
}
input {
border-style: solid;
border-color: #5f9341;
border-width: 2px;
width: 100%;
box-sizing: border-box;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><html>
<head>
<link rel="stylesheet" href="css/index.css">
<script src="js/index.js"></script>
</head>
<body>
<input type="text" id="input-el">
<button id="input-btn">SAVE INPUT</button>
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74433395,
"author": "jessica-98",
"author_id": 20261328,
"author_profile": "https://Stackoverflow.com/users/20261328",
"pm_score": 2,
"selected": true,
"text": "body {\n box-sizing: border-box;\n margin: 0;\n padding: 10px;\n font-family: Arial, Helvetica, sans-serif;\n}\n\n* {\n margin: 40px;\n padding: 10px;\n}\n\n.flex {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n}\n\ninput {\n border-style: solid;\n border-color: #5f9341;\n border-width: 2px;\n width: 100%;\n margin: 0;\n}"
},
{
"answer_id": 74433460,
"author": "Johannes",
"author_id": 5641669,
"author_profile": "https://Stackoverflow.com/users/5641669",
"pm_score": 1,
"selected": false,
"text": "margin"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14022782/"
] |
74,433,260 | <p>I have the following script. Its full purpose is to remove cells of columns B,C,D,E,F if the content in column A was deleted, only on the matching row. It functions as it should. However, it is a bit slow.</p>
<p>I couldn't figure out a way to do it myself. Which is why I am here. How could I go about adjusting it, so instead of removing the cells individually, I could instead grab a full range of them, in the matching row? Perhaps based on the offset of the initially adjusted cell.</p>
<pre><code> function onEdit(e) {
if(e.range.columnStart === 1
&& e.range.rowStart > 1
&& e.range.getSheet().getName() == 'Sheet1'
&& e.range.getValue() == '') {
e.range.offset(0,1).deleteCells(SpreadsheetApp.Dimension.ROWS);
e.range.offset(0,2).deleteCells(SpreadsheetApp.Dimension.ROWS);
e.range.offset(0,3).deleteCells(SpreadsheetApp.Dimension.ROWS);
e.range.offset(0,4).deleteCells(SpreadsheetApp.Dimension.ROWS);
e.range.offset(0,5).deleteCells(SpreadsheetApp.Dimension.ROWS)
}
}
</code></pre>
| [
{
"answer_id": 74433480,
"author": "Martín",
"author_id": 20363318,
"author_profile": "https://Stackoverflow.com/users/20363318",
"pm_score": 0,
"selected": false,
"text": " function onEdit(e) {\n if(e.range.columnStart === 1 \n && e.range.rowStart > 1 \n && e.range.getSheet().getName() == 'Sheet1'\n && e.range.getValue() == '') { \n deletecols()\n }\n}\n\nfunction deletecols(){\n \n var sh = SpreadsheetApp.getActive().getActiveSheet()\n var range = sh.getActiveRange()\n var numrows = range.getNumRows()\n var row = range.getRow()\n sh.getRange(row,2,numrows,5).clearContent()\n\n}\n"
},
{
"answer_id": 74433510,
"author": "Cooper",
"author_id": 7215091,
"author_profile": "https://Stackoverflow.com/users/7215091",
"pm_score": 0,
"selected": false,
"text": " function onEdit(e) {\n const sh = e.range.getSheet();\n if(e.range.columnStart == 1 && e.range.rowStart > 1 && sh.getName() == 'Sheet1' && e.value == '') { \n sh.getRange(e.range.rowStart,2,1,5).setValues([['','','','','']]);\n }\n}\n"
},
{
"answer_id": 74433775,
"author": "doubleunary",
"author_id": 13045193,
"author_profile": "https://Stackoverflow.com/users/13045193",
"pm_score": 3,
"selected": true,
"text": "/**\n* Simple trigger that runs each time the user hand edits the spreadsheet.\n*\n* @param {Object} e The onEdit() event object.\n*/\nfunction onEdit(e) {\n if (e.range.columnStart !== 1\n || e.range.rowStart <= 1\n || e.range.getSheet().getName() !== 'Sheet1'\n || (e.value || e.range.getValue())\n || e.range.getHeight() + e.range.getWidth() > 2) {\n return;\n }\n e.range.offset(0, 1, 1, 5).clearContent();\n}\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19307436/"
] |
74,433,262 | <p>Jquery push and append not working.</p>
<p>I have this code</p>
<pre><code><form action="">
<input type="text" name="text">
<input type="text" name="textw">
<button type="submit" name="submit">submit</button>
</form>
<p>teasdfas</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$('form').on('submit', function(e) {
e.preventDefault();
let formata = $('form').serialize();
formata.append('id', '1300');
console.log(formata)
})
</script>
</code></pre>
<p>The problem is that when I submit the form the console outputs</p>
<pre><code>pay.php:12 Uncaught TypeError: formata.append is not a function
at HTMLFormElement.<anonymous> (pay.php:12:17)
at HTMLFormElement.dispatch (jquery.min.js:2:43064)
at v.handle (jquery.min.js:2:41048)
</code></pre>
<p>saying append is not a function, also did with push and some regular objects and same output. Please how do i go on with this.</p>
| [
{
"answer_id": 74433480,
"author": "Martín",
"author_id": 20363318,
"author_profile": "https://Stackoverflow.com/users/20363318",
"pm_score": 0,
"selected": false,
"text": " function onEdit(e) {\n if(e.range.columnStart === 1 \n && e.range.rowStart > 1 \n && e.range.getSheet().getName() == 'Sheet1'\n && e.range.getValue() == '') { \n deletecols()\n }\n}\n\nfunction deletecols(){\n \n var sh = SpreadsheetApp.getActive().getActiveSheet()\n var range = sh.getActiveRange()\n var numrows = range.getNumRows()\n var row = range.getRow()\n sh.getRange(row,2,numrows,5).clearContent()\n\n}\n"
},
{
"answer_id": 74433510,
"author": "Cooper",
"author_id": 7215091,
"author_profile": "https://Stackoverflow.com/users/7215091",
"pm_score": 0,
"selected": false,
"text": " function onEdit(e) {\n const sh = e.range.getSheet();\n if(e.range.columnStart == 1 && e.range.rowStart > 1 && sh.getName() == 'Sheet1' && e.value == '') { \n sh.getRange(e.range.rowStart,2,1,5).setValues([['','','','','']]);\n }\n}\n"
},
{
"answer_id": 74433775,
"author": "doubleunary",
"author_id": 13045193,
"author_profile": "https://Stackoverflow.com/users/13045193",
"pm_score": 3,
"selected": true,
"text": "/**\n* Simple trigger that runs each time the user hand edits the spreadsheet.\n*\n* @param {Object} e The onEdit() event object.\n*/\nfunction onEdit(e) {\n if (e.range.columnStart !== 1\n || e.range.rowStart <= 1\n || e.range.getSheet().getName() !== 'Sheet1'\n || (e.value || e.range.getValue())\n || e.range.getHeight() + e.range.getWidth() > 2) {\n return;\n }\n e.range.offset(0, 1, 1, 5).clearContent();\n}\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19480605/"
] |
74,433,306 | <p>How can I make sure that there is nothing at the end of the last print statement instead of "-"?</p>
<pre><code>for i in range(0, 4,):
print(i, end="-")
print()
for i in range(0, 10, 2):
print(i, end="-")
</code></pre>
| [
{
"answer_id": 74433364,
"author": "AdmiJW",
"author_id": 14033758,
"author_profile": "https://Stackoverflow.com/users/14033758",
"pm_score": 1,
"selected": true,
"text": "sep"
},
{
"answer_id": 74433379,
"author": "Matteo Zanoni",
"author_id": 13384774,
"author_profile": "https://Stackoverflow.com/users/13384774",
"pm_score": 2,
"selected": false,
"text": "join"
},
{
"answer_id": 74433441,
"author": "Vivs",
"author_id": 13839378,
"author_profile": "https://Stackoverflow.com/users/13839378",
"pm_score": -1,
"selected": false,
"text": "for i in range(0, 4,):\n print(i, sep=\"-\")\nprint()\nfor i in range(0, 10, 2):\n print(i, sep=\"-\")\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501566/"
] |
74,433,317 | <p>I wanna display certain product when it's clicked on based on their id from django rest framework api.. I was doing that using match from the react-router-dom v5, but I don't know how to accomplish the same thing with match not existing in v6. I looked at the react-router-dom v6 documentation for a clue and i couldn't find a solution..</p>
<p>ProductScreen.js:</p>
<pre><code>import React, { useState, useEffect } from "react";
import { Link } from "react-router-dom";
import { Row, Col, Image, ListGroup, Button, Card } from "react-bootstrap";
//import products from "../../products";
import Rating from "../Rating";
import axios from "axios";
function ProductScreen({ match }) {
const [product, setProduct] = useState([]);
useEffect(() => {
async function fetchProduct() {
const { data } = await axios.get(`/api/products/${match.params.id}`);
setProduct(data);
}
fetchProduct();
}, []);
return (
<div>
<Link to="/" className="btn btn-dark my-3">
Go Back
</Link>
<Row>
<Col md={6}>
<Image
className="imgCustom"
src={product.image}
alt={product.name}
></Image>
</Col>
<Col md={3}>
<ListGroup variant="flush">
<ListGroup.Item>
<h3>{product.name}</h3>
</ListGroup.Item>
<ListGroup.Item>
<Rating
value={product.rating}
text={`${product.numReviews} reviews`}
color={"f8e825"}
/>
</ListGroup.Item>
<ListGroup.Item>Price : ${product.price}</ListGroup.Item>
<ListGroup.Item>Description: ${product.description}</ListGroup.Item>
</ListGroup>
</Col>
<Col md={3}>
<Card>
<ListGroup variant="flush">
<ListGroup.Item>
<Row>
<Col>Price : </Col>
<Col>
<strong>$ {product.price}</strong>
</Col>
</Row>
</ListGroup.Item>
<ListGroup.Item>
<Row>
<Col>Status : </Col>
<Col>
{product.coutInStock > 0 ? "In Stock" : "Out of Stock"}
</Col>
</Row>
</ListGroup.Item>
<ListGroup.Item>
<Button
className="btn-block"
disabled={product.coutInStock === 0}
type="button"
>
Add to Cart
</Button>
</ListGroup.Item>
</ListGroup>
</Card>
</Col>
</Row>
{product.name}
</div>
);
}
export default ProductScreen;
</code></pre>
| [
{
"answer_id": 74433364,
"author": "AdmiJW",
"author_id": 14033758,
"author_profile": "https://Stackoverflow.com/users/14033758",
"pm_score": 1,
"selected": true,
"text": "sep"
},
{
"answer_id": 74433379,
"author": "Matteo Zanoni",
"author_id": 13384774,
"author_profile": "https://Stackoverflow.com/users/13384774",
"pm_score": 2,
"selected": false,
"text": "join"
},
{
"answer_id": 74433441,
"author": "Vivs",
"author_id": 13839378,
"author_profile": "https://Stackoverflow.com/users/13839378",
"pm_score": -1,
"selected": false,
"text": "for i in range(0, 4,):\n print(i, sep=\"-\")\nprint()\nfor i in range(0, 10, 2):\n print(i, sep=\"-\")\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19778871/"
] |
74,433,323 | <p>I can't figure out how to decode a JSON to a specific Map.</p>
<p>First of all I have a map that stores the date as the map key, and the value is a list of objects.
I also made custom methods to convert the objects to JSON.
The class model for the list of objects is:</p>
<pre><code>class Task {
late int taskId;
late bool isCompleted;
late String text;
late PriorityItem priority;
Map<String, dynamic> toJson() =>
{
"id": taskId,
"isCompleted": isCompleted,
"text": text,
"priority": priority.toString(),
};
factory Task.fromJson(Map<String, dynamic> json) =>
Task(
json["isCompleted"],
taskId:json["id"],
text: json["text"],
priority: json["priority"]);
}
enum PriorityItem{
low,
medium,
high
}
</code></pre>
<p>The map is stored inside another class called TaskList as</p>
<pre><code>static LinkedHashMap<DateTime, List<Task>> weeklyTaskMap = LinkedHashMap<DateTime, List<Task>>();
static Map<String, dynamic> toJson(LinkedHashMap<DateTime, List<Task>> taskMap) {
Map<String, dynamic> myMap = {};
taskMap.forEach((key, value) {
myMap[key.toIso8601String()] = List<dynamic>.from(value.map((x) => x.toJson()));
});
return myMap;
}
static LinkedHashMap<DateTime, List<Task>> fromJson(Map<String, dynamic> json) {
LinkedHashMap<DateTime, List<Task>> myMap = {} as LinkedHashMap<DateTime, List<Task>>;
json.forEach((key, value) {
myMap[DateTime.parse(key)] = List<Task>.from(json[value]
.map((x) => Task.fromJson(value)));
});
return myMap;
}
</code></pre>
<p>Encoding the map to JSON is working just fine, this would be an output after encoding the map:</p>
<pre><code>{
"2022-11-14T15:38:52.879009": [
{
"id": 0,
"isCompleted": false,
"text": "how to get rid ",
"priority": "PriorityItem.medium"
},
{
"id": 1,
"isCompleted": false,
"text": "good morning and I ",
"priority": "PriorityItem.low"
}
],
"2022-11-15T00:00:00.000Z": [
{
"id": 2,
"isCompleted": false,
"text": "how to get rid of the ",
"priority": "PriorityItem.high"
}
]
}
</code></pre>
<p>Methods used to encode and decode:</p>
<pre><code>void getMapsFromPrefs() async {
SharedPreferences getMaps = await _prefs;
Map dailyMap = TaskList.fromJson(jsonDecode(getMaps.getString('daily')!));
LinkedHashMap<DateTime, List<Task>> weeklyMap = jsonDecode(getMaps.getString('weekly')!);
TaskList.taskMap = dailyMap;
TaskList.weeklyTaskMap = weeklyMap;
}
void saveMapsToPrefs() async {
SharedPreferences getMaps = await _prefs;
getMaps.clear();
var dailyTasksJson = json.encode(TaskList.toJson(TaskList.taskMap));
var weeklyTasksJson = json.encode(TaskList.toJson(TaskList.weeklyTaskMap));
getMaps.setString('daily', dailyTasksJson);
getMaps.setString('weekly', weeklyTasksJson);
print("saved ${getMaps.getString('daily')}");
}
</code></pre>
<p><strong>The only problem I have is decoding the JSON to my desired Map.</strong>
I hope this is understandable, if anyone needs extra information please feel free to ask :)
Thank you.</p>
| [
{
"answer_id": 74433364,
"author": "AdmiJW",
"author_id": 14033758,
"author_profile": "https://Stackoverflow.com/users/14033758",
"pm_score": 1,
"selected": true,
"text": "sep"
},
{
"answer_id": 74433379,
"author": "Matteo Zanoni",
"author_id": 13384774,
"author_profile": "https://Stackoverflow.com/users/13384774",
"pm_score": 2,
"selected": false,
"text": "join"
},
{
"answer_id": 74433441,
"author": "Vivs",
"author_id": 13839378,
"author_profile": "https://Stackoverflow.com/users/13839378",
"pm_score": -1,
"selected": false,
"text": "for i in range(0, 4,):\n print(i, sep=\"-\")\nprint()\nfor i in range(0, 10, 2):\n print(i, sep=\"-\")\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20182920/"
] |
74,433,327 | <p>I'm trying to make a program to calculate the surface area of a shack with a pitched roof. I've only been in this class for 2 weeks and I'm a bit overwhelmed. The program should ask the user via console for the values and then calculate the values using the definition.</p>
<p>I'm not asking for the entire code at all. But I don't understand how I can calculate inputs using a definition and then print them. this is my code so far:</p>
<pre><code>import math
def floorspace(a,b):
G = 0
G = a*b
return (G)
#main program
a = int(input("enter the length of the floor!"))
b = int(input("Enter the width of the floor!"))
print(floorspace, G)
</code></pre>
| [
{
"answer_id": 74433400,
"author": "Mohamed chouai",
"author_id": 19371185,
"author_profile": "https://Stackoverflow.com/users/19371185",
"pm_score": 0,
"selected": false,
"text": "print(floorspace,G)"
},
{
"answer_id": 74433432,
"author": "Paulina Khew",
"author_id": 15100309,
"author_profile": "https://Stackoverflow.com/users/15100309",
"pm_score": 1,
"selected": false,
"text": "math"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501251/"
] |
74,433,334 | <p>I have a .net 6.0 class library project that has class files in the root, but also contains a Models folder with public classes declared in the class library. I've tried using the *.nupkg file created via nuget pack at the *.csproj level and the one created when the build preference to generate a package on every build. The package is created fine as MyPackage.</p>
<p>When I include 'MyPackage' in another project, I have access to the root classes, but the namespace MyPackage.Models doesn't seem to be included even though it was part of the project. Additionally, the xml documentation file does not seem to be included because I see none of my comments included when calling any of the methods on classes at MyPackage root.</p>
<p>I'm new to using my own nuget packages so this might be a rookie mistake, but I'm not sure what I'm doing wrong here.</p>
<p>Any advice?</p>
| [
{
"answer_id": 74433400,
"author": "Mohamed chouai",
"author_id": 19371185,
"author_profile": "https://Stackoverflow.com/users/19371185",
"pm_score": 0,
"selected": false,
"text": "print(floorspace,G)"
},
{
"answer_id": 74433432,
"author": "Paulina Khew",
"author_id": 15100309,
"author_profile": "https://Stackoverflow.com/users/15100309",
"pm_score": 1,
"selected": false,
"text": "math"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433334",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1709186/"
] |
74,433,361 | <p>I'm trying to create a formula depending on the values of a dropdown in Google Sheets, so Basically I have Low, Medium and High their values are 1, 2 and 3 so I would like to multiplicate this numbers in two columns to do have an score this is my list:</p>
<pre><code>Rate Rate two Total score
Medium Low
High High
Low Medium
</code></pre>
<p>How can I solve it with and if?</p>
<p>I have this formula it works but I would like to know a better option</p>
<pre><code>=(SWITCH(B2, "High", 1, "Medium", 2, "Low", 3,, 0))*(SWITCH(C2, "High", 1, "Medium", 2, "Low", 3,, 0))
</code></pre>
| [
{
"answer_id": 74433400,
"author": "Mohamed chouai",
"author_id": 19371185,
"author_profile": "https://Stackoverflow.com/users/19371185",
"pm_score": 0,
"selected": false,
"text": "print(floorspace,G)"
},
{
"answer_id": 74433432,
"author": "Paulina Khew",
"author_id": 15100309,
"author_profile": "https://Stackoverflow.com/users/15100309",
"pm_score": 1,
"selected": false,
"text": "math"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16239103/"
] |
74,433,378 | <p>I need help with Linq Contains method. Here's the code below.</p>
<p>This code does work but outputs an empty sets.</p>
<pre><code>var query = _context.RegistrationCodes.Select(x => x);
if (request.OperatorId != null && request.OperatorId != Guid.Empty)
{
var checkOperator = _context.Operators.Include(a => a.OperatorLevel).Include(a => a.City).Include("City.StateRegion.Country").FirstOrDefault(a => a.Id == request.OperatorId);
List<String> Cities = new List<String>();
if (checkOperator.OperatorLevel.Name == "City")
{
Cities = await _context.Cities
.Where(a => (checkOperator.CityId) == (a.Id))
.Select(a => a.Code)
.ToListAsync();
}
else if (checkOperator.OperatorLevel.Name == "Regional")
{
Cities = await _context.Cities
.Where(a => checkOperator.City.StateRegionId == a.StateRegionId)
.Select(a => a.Code)
.ToListAsync();
}
else if (checkOperator.OperatorLevel.Name == "National")
{
List<Guid> StateRegion = await _context.StateRegions
.Where(a => checkOperator.City.StateRegion.CountryId == a.CountryId)
.Select(a => a.Id)
.ToListAsync();
Cities = await _context.Cities
.Where(a => StateRegion.Contains(a.StateRegionId))
.Select(a => a.Code)
.ToListAsync();
}
var nullableStrings = Cities.Cast<String?>().ToList();
query = query.Where(a => nullableStrings.Contains(a.Code));
}
</code></pre>
<p>I need to compare nullableStrings to a.Code which is something like this, but does not work.</p>
<pre><code>query = query.Where(a => a.Code.Contains(nullableStrings));
</code></pre>
<p>Error : Argument 1: cannot convert from 'System.Collections.Generic.List' to 'char'</p>
<p>I need a method that would replace</p>
<pre><code>query = query.Where(a => nullableStrings.Contains(a.Code));
</code></pre>
<p>A help would be appreciated. Thanks.</p>
| [
{
"answer_id": 74433400,
"author": "Mohamed chouai",
"author_id": 19371185,
"author_profile": "https://Stackoverflow.com/users/19371185",
"pm_score": 0,
"selected": false,
"text": "print(floorspace,G)"
},
{
"answer_id": 74433432,
"author": "Paulina Khew",
"author_id": 15100309,
"author_profile": "https://Stackoverflow.com/users/15100309",
"pm_score": 1,
"selected": false,
"text": "math"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4646017/"
] |
74,433,383 | <p>I am wondering how to construct a string, which takes 1st letter of each word from list. Then it takes 2nd letter from each word etc.
For example :
Input --> my_list = ['good', 'bad', 'father']
Every word has different length (but the words in the list could have equal length)
The output should be: 'gbfoaaodtdher'.</p>
<p>I tried:</p>
<pre><code>def letters(my_list):
string = ''
for i in range(len(my_list)):
for j in range(len(my_list)):
string += my_list[j][i]
return string
print(letters(['good', 'bad', 'father']))
</code></pre>
<p>and I got:
'gbfoaaodt'.</p>
| [
{
"answer_id": 74433416,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "itertools.zip_longest"
},
{
"answer_id": 74433456,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 0,
"selected": false,
"text": "def letters(my_list):\n string = ''\n\n max_len = max([len(s) for s in my_list])\n\n for i in range(max_len):\n for j in range(len(my_list)):\n if i < len(my_list[j]):\n string += my_list[j][i]\n\n return string\n\nprint(letters(['good', 'bad', 'father']))\n"
},
{
"answer_id": 74433686,
"author": "Talha Tayyab",
"author_id": 13086128,
"author_profile": "https://Stackoverflow.com/users/13086128",
"pm_score": 0,
"selected": false,
"text": "l = ['good', 'bad', 'father']\nlongest_string=max(l,key=len)\n''.join(''.join([e[i] for e in l if len(e) > i]) for i in range(len(longest_string)))\n\n#'gbfoaaodtdher'\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20485972/"
] |
74,433,408 | <p><a href="https://i.stack.imgur.com/pQPrQ.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>I need to rotate object in python with this formula (<a href="https://i.stack.imgur.com/k7G8i.png" rel="nofollow noreferrer">enter image description here</a>)</p>
<pre><code>rotate an object by a specified angle.
</code></pre>
| [
{
"answer_id": 74433416,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "itertools.zip_longest"
},
{
"answer_id": 74433456,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 0,
"selected": false,
"text": "def letters(my_list):\n string = ''\n\n max_len = max([len(s) for s in my_list])\n\n for i in range(max_len):\n for j in range(len(my_list)):\n if i < len(my_list[j]):\n string += my_list[j][i]\n\n return string\n\nprint(letters(['good', 'bad', 'father']))\n"
},
{
"answer_id": 74433686,
"author": "Talha Tayyab",
"author_id": 13086128,
"author_profile": "https://Stackoverflow.com/users/13086128",
"pm_score": 0,
"selected": false,
"text": "l = ['good', 'bad', 'father']\nlongest_string=max(l,key=len)\n''.join(''.join([e[i] for e in l if len(e) > i]) for i in range(len(longest_string)))\n\n#'gbfoaaodtdher'\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501601/"
] |
74,433,434 | <p>So, I have created an automation script performs a task every minute, on the minute (I want the task to be ran at the :00 second of each minute). As a test, the function that I am calling every minute just writes to console and to a text file that it has ran and at which time it has ran.</p>
<p>I don't know anything about resource usage of apps and how to reduce it, but for some reason this application is using around 17% of my CPU on an i7 8750h cpu.</p>
<p>The entire code for the script is as follows:</p>
<pre><code>Logger.WriteLine("Program starting... @ " + DateTime.Now.ToString("HH:mm:ss"));
static void TestTask()
{
string currentTime = DateTime.Now.ToString("HH:mm:ss");
Logger.WriteLine("Test task ran at: " + currentTime);
}
// This currently runs forever, as there is no boolean condition evaluated to false to break the while loop (which is expected behavior)
while (true)
{
// Evyer minute on the minute
if (DateTime.Now.Second == 0)
{
TestTask();
Thread.Sleep(1000);
}
}
</code></pre>
<p>The Logger.WriteLine class is a custom class I created that essentially acts the same as Console.WriteLine as it prints the string to the console, but it also adds it to a stringbuilder that then gets written using stringwriter to a .txt file on my desktop. Could this be the issue?</p>
<p>I also tried creating the exact same program in Python, and it uses the same amount of CPU usage. Both .exe versions of the program use about 5mb of memory which is fine for me, but its just the CPU usage that I would like to reduce.</p>
<p>Anyone know anything I could do? Thanks!</p>
| [
{
"answer_id": 74433702,
"author": "YungDeiza",
"author_id": 19214431,
"author_profile": "https://Stackoverflow.com/users/19214431",
"pm_score": 3,
"selected": true,
"text": "Thread.Sleep"
},
{
"answer_id": 74433852,
"author": "madmonk46",
"author_id": 9796331,
"author_profile": "https://Stackoverflow.com/users/9796331",
"pm_score": 2,
"selected": false,
"text": "true == true"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19433830/"
] |
74,433,437 | <p>I have to write a method that returns/prints the odd numbers between 1 and 100, but I have to use another method, which checks whether a given integer is odd or not:</p>
<pre><code>static boolean isOdd(int c) {
boolean d;
d = c % 2 != 0;
return d;
}
</code></pre>
<p>I'm guessing that I have to use either a for- or while-loop (probably can be done with both?), but I think what I'm really struggling with is "connecting" both methods. So the numbers actually run through isOdd() which determines whether they are odd.</p>
<p>I've tried these two options so far, but they're not working.
Option 1:</p>
<pre><code>static void func1() {
int number = 1;
while (number < 100 && isOdd(number)) {
System.out.println(number);
number = number + 1;
}
}
</code></pre>
<p>Option 2:</p>
<pre><code>static void func1() {
int i;
for (i = 1; i < 100; i++) {
isOdd(i);
}
System.out.println(i);
}
</code></pre>
| [
{
"answer_id": 74433544,
"author": "LMD",
"author_id": 7185318,
"author_profile": "https://Stackoverflow.com/users/7185318",
"pm_score": 2,
"selected": true,
"text": "for"
},
{
"answer_id": 74433546,
"author": "cyberbrain",
"author_id": 2846138,
"author_profile": "https://Stackoverflow.com/users/2846138",
"pm_score": 2,
"selected": false,
"text": "while"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20390902/"
] |
74,433,449 | <p>Imaging we have a <code>props</code>, <strong>a really large</strong> object:</p>
<pre><code>{
"firstname": "John",
"lastname": "Doe",
"age": 11,
"mode: "expert",
"website": "stackoverflow.com"
"protocol": "https",
"job": "dev",
"env": "main",
..... and a lot of key-values pairs coming
}
</code></pre>
<p>What usually we are calling to create "component variables":</p>
<pre><code>let {firstname,
lastname,
age,
mode,
website,
protocol,
job,
env
...and a lot of "keys" as variable names} = props
// so we can call variable, {age} for example
</code></pre>
<p><em>I don't like to type all these variables in <code>let {}</code>, do we have something dynamic to declare "all keys" dynamically?</em> I am not sure it's possible.</p>
<p>Of course I can use <code>{props.firstname}</code> in my code.</p>
<p>There is a way to create dynamically variables in <code>let {}</code> scope?</p>
<p>Any help is appreciated.</p>
| [
{
"answer_id": 74433544,
"author": "LMD",
"author_id": 7185318,
"author_profile": "https://Stackoverflow.com/users/7185318",
"pm_score": 2,
"selected": true,
"text": "for"
},
{
"answer_id": 74433546,
"author": "cyberbrain",
"author_id": 2846138,
"author_profile": "https://Stackoverflow.com/users/2846138",
"pm_score": 2,
"selected": false,
"text": "while"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8280112/"
] |
74,433,484 | <p>I recently found this library, vanilla-js datepicker (<a href="https://mymth.github.io/vanillajs-datepicker/#/" rel="nofollow noreferrer">https://mymth.github.io/vanillajs-datepicker/#/</a>) and I'm trying to use the inline picker.</p>
<p>Example:</p>
<pre><code><div id="foo" data-date="01/25/2020"></div>
const elem = document.getElementById('foo');
const datepicker = new Datepicker(elem, {
// ...options
});
</code></pre>
<p>So far, so good, I have the picker showing in my site.</p>
<p>My problem is that I can't get the date on change, according to the documentation (<a href="https://mymth.github.io/vanillajs-datepicker/#/api?id=events" rel="nofollow noreferrer">https://mymth.github.io/vanillajs-datepicker/#/api?id=events</a>) for the inline datepicker I should get the block-element, that would be <code><div id="foo" data-date="01/25/2020"></div></code> and there is an event called changeDate (<a href="https://mymth.github.io/vanillajs-datepicker/#/api?id=changedate" rel="nofollow noreferrer">https://mymth.github.io/vanillajs-datepicker/#/api?id=changedate</a>).</p>
<p>So, according to that, I figure that this is the code that I should work on:</p>
<pre><code>elem.addEventListener('changeDate', (e) => {
console.log('Date selected');
})
</code></pre>
<p>I also tried</p>
<pre><code>datepicker.addEventListener('changeDate', (e) => {
console.log('Date selected');
})
</code></pre>
<p>But no, is not working for me, this might be taken as a repeat question but the examples here works for the input type datepickers but not for the inline one.</p>
<p>Any help will be much appreciated. Thanks in advance!</p>
| [
{
"answer_id": 74433544,
"author": "LMD",
"author_id": 7185318,
"author_profile": "https://Stackoverflow.com/users/7185318",
"pm_score": 2,
"selected": true,
"text": "for"
},
{
"answer_id": 74433546,
"author": "cyberbrain",
"author_id": 2846138,
"author_profile": "https://Stackoverflow.com/users/2846138",
"pm_score": 2,
"selected": false,
"text": "while"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12406361/"
] |
74,433,538 | <p>I have a 1D-array which has the following structure:</p>
<pre><code>arr = [x,a,b,c,y,a,b,c]
</code></pre>
<p>How can I convert that 1D array into a 3D-array like this:</p>
<p><code>arr2 = [[[x,a],[x,b],[x,c]], [[y,a], [y,b], [y,c]]]</code>
(3 y-values for each x-value)</p>
| [
{
"answer_id": 74433618,
"author": "Ildaron",
"author_id": 13904129,
"author_profile": "https://Stackoverflow.com/users/13904129",
"pm_score": 1,
"selected": false,
"text": "arr = [1,2,3,4,5,6,7,8,9]\narr = np.array(arr)\narr = arr.reshape(3,3)\nprint (list(arr))\n"
},
{
"answer_id": 74433631,
"author": "Alex P",
"author_id": 11554968,
"author_profile": "https://Stackoverflow.com/users/11554968",
"pm_score": 3,
"selected": true,
"text": "arr = np.array([1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6])\n\narr = arr.reshape((3, -1))\narr = np.delete(arr, 0, 1)\nprint(arr)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13686580/"
] |
74,433,559 | <p>So that's how HTML looks:</p>
<pre><code><p class="details">
<span>detail1</span>
<span class="number">1</span>
<span>detail2</span>
<span>detail3</span>
</p>
</code></pre>
<p>I need to extract detail2 & detail3.</p>
<p>But with this piece of code I only get detail1.</p>
<pre><code>info = data.find("p", class_ = "details").span.text
</code></pre>
<p>How do I extract the needed items?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 74433637,
"author": "HedgeHog",
"author_id": 14460824,
"author_profile": "https://Stackoverflow.com/users/14460824",
"pm_score": 1,
"selected": false,
"text": "<span>"
},
{
"answer_id": 74433646,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": true,
"text": "<span>"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501743/"
] |
74,433,586 | <p>From what I have read so far Cassandra is using timestamps provided by client or coordinator to resolve conflicts. If Cassandra receives write for cell which already exists it picks up the one with higher timestamp.</p>
<p>In case of clock skews, when there are no concurrent updates and even when using <code>ALL</code> consistency level, it still might be the case that client has updated value and received ACK from all servers. The actual value however was not updated since provided timestamp was older than existing value at this cell (due to clock skews). Such behaviour violates causal consistency, which AFAIK R+W>N was supposed to provide?</p>
<p>It seems to me that using logical clocks (lamport/vector clocks) to pick newest value and falling back to using actual timestamps (or other strategy that can provided by client) only when concurrent update was detected using read repair. Seems like a better solution and AFAIK this is more or less the approach that dynamo uses, right?</p>
<p>As I am probably missing something, can you let me know why Cassandra doesn't use such approach?</p>
<p><a href="https://i.stack.imgur.com/zTmd7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zTmd7.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74433637,
"author": "HedgeHog",
"author_id": 14460824,
"author_profile": "https://Stackoverflow.com/users/14460824",
"pm_score": 1,
"selected": false,
"text": "<span>"
},
{
"answer_id": 74433646,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": true,
"text": "<span>"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3364192/"
] |
74,433,625 | <p>I have a file with some IDs listed like this:</p>
<pre><code>id1
id2
id3
etc
</code></pre>
<p>I want to use those IDs to extract data from files (IDs are occurring in every file) and save output for each of these IDs to a separate file (IDs are protein family names and I want to get each protein from a specific family). And, when I have the name for each of the protein I want to use this name to get those proteins (in <code>.fasta</code> format), so that they would be grouped by their family (they'll be staying in the same group)</p>
<p>So I've tried to do it like this (I knew that it would dump all the IDs into one file):</p>
<pre class="lang-bash prettyprint-override"><code>#! /bin/bash
for file in *out
do grep -n -E 'id1|id2|id3' /directory/$file >> output; done
</code></pre>
<p>I would appreciate any help and I will gladly specify if not everything is clear to you.</p>
<p>EDIT: i will try to clarify, sorry for the inconvenience:</p>
<p>so theres a file called "pfamacc" with the following content:</p>
<pre><code>PF12312
PF43555
PF34923
</code></pre>
<p>and so on - those are the IDs that i need to acces other files, which have a structure like that "something_something.faa.out"</p>
<pre><code><acc_number> <aligment_start> <aligment_end> <pfam_acc>
RXOOOA 5 250 PF12312
OC2144 6 200 PF34923
</code></pre>
<p>i need those accesion numbers so i can then get protein sequences from files which look like this:</p>
<pre><code>>RXOOOA
ASDBSADBASDGHH
>OC2144
SADHHASDASDCJHWINF
</code></pre>
| [
{
"answer_id": 74433637,
"author": "HedgeHog",
"author_id": 14460824,
"author_profile": "https://Stackoverflow.com/users/14460824",
"pm_score": 1,
"selected": false,
"text": "<span>"
},
{
"answer_id": 74433646,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": true,
"text": "<span>"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501684/"
] |
74,433,632 | <p>How can i find date inside a string in PHP and extract it?'</p>
<p>example: I have a date in string</p>
<pre><code>$status = "OK, 26.10.2022 13:24:00, Delivered Zak";
</code></pre>
<p>but also next time i can only get string which looks like this:</p>
<pre><code>$status = "28.10.2022 11:20:00, Delivered";
</code></pre>
<p>So explode it to the pieces by "," is not a option here, because everytime is in different position. How can i get this date everytime?
Thanks for any suggestion.</p>
| [
{
"answer_id": 74433637,
"author": "HedgeHog",
"author_id": 14460824,
"author_profile": "https://Stackoverflow.com/users/14460824",
"pm_score": 1,
"selected": false,
"text": "<span>"
},
{
"answer_id": 74433646,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": true,
"text": "<span>"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13533140/"
] |
74,433,634 | <p>I attempted to use execve to run the command: <code>ls -l /tmp</code>, I'm familiar with the system call usage but I do not know how it runs commands.</p>
<p>I've tried this and i keep getting errors</p>
<pre><code>char *argv[] = {"ls", "-l", NULL};
int exec;
exec = execve("/tmp", argv, NULL);
printf("%d\n", exec);
return (0);
</code></pre>
| [
{
"answer_id": 74433697,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 1,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433712,
"author": "ikegami",
"author_id": 589924,
"author_profile": "https://Stackoverflow.com/users/589924",
"pm_score": 2,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433733,
"author": "Mathieu",
"author_id": 1212012,
"author_profile": "https://Stackoverflow.com/users/1212012",
"pm_score": 2,
"selected": false,
"text": "execve"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433634",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20184925/"
] |
74,433,654 | <p>I've got a tab navigator that has <code>Home</code> and <code>Profile</code> as screens. <code>Home</code> is a stack navigator that contains <code>RestaurantDetails</code> and <code>RestaurantList</code> as screens.</p>
<p>I have a <code>Button</code> that is in the <code>RestaurantList</code> screen. I want to navigate to <code>RestaurantDetails</code>.</p>
<p>Button.tsx</p>
<pre><code>const Button = ({name}) => {
const navigation = useNavigation()
const onPress = () => {
navigation.navigate("RestaurantDetails", {name})
}
return (
<TouchableOpacity onPress={onPress}>
</TouchableOpacity>
)
}
</code></pre>
<p>The problem is that typescript complains</p>
<pre><code>Argument of type '["RestaurantDetails", { name: string}]' is not assignable to parameter of type '[screen: "Home", params: NavigatorScreenParams<HomeStackParamList, Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<ParamListBase, string>[]; type: string; stale: false; }>>] | [screen: ...] | [screen: ...] | [screen: ...] | [screen: ...]'.
Type '["RestaurantDetails", { name: string}]' is not assignable to type '[screen: "Profile", params: undefined]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type '"RestaurantDetails"' is not assignable to type '"Profile"'.
</code></pre>
<p>I'm pretty sure the problem is that typescript looks in <code>TRootParamList</code> instead of <code>HomeStackParamList</code> for the <code>RestaurantDetails</code> screen, since if I add <code>RestaurantDetails</code> to <code>TRootParamList</code> typescript stops complaining. However, I am unsure on how to actually stop this problem.</p>
<p>types.ts</p>
<pre><code>import { NavigatorScreenParams } from '@react-navigation/native';
type QueueDetailsParams = {
name: string
};
type HomeStackParamList = {
RestaurantDetails: QueueDetailsParams | undefined;
RestaurantList: undefined
};
type TRootParamList = {
Home: NavigatorScreenParams<HomeStackParamList>;
Profile: undefined
};
declare global {
namespace ReactNavigation {
interface RootParamList extends TRootParamList {}
}
}
</code></pre>
<p>P.S
I know that I can replace my <code>onPress</code> with the below but would rather not do this.</p>
<pre><code>const onPress = () => {
navigation.navigate("Home", {screen: "RestaurantDetails", params: {name}})
}
</code></pre>
| [
{
"answer_id": 74433697,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 1,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433712,
"author": "ikegami",
"author_id": 589924,
"author_profile": "https://Stackoverflow.com/users/589924",
"pm_score": 2,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433733,
"author": "Mathieu",
"author_id": 1212012,
"author_profile": "https://Stackoverflow.com/users/1212012",
"pm_score": 2,
"selected": false,
"text": "execve"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10613037/"
] |
74,433,684 | <p>I have a file containing school codes and votes for different cities.</p>
<p>The file is like:</p>
<pre class="lang-none prettyprint-override"><code>City: California
ADS, 532
SJD, 221
WPE, 239
City: Chicago
ADS, 238
SJD, 233
WPE, 456
...
</code></pre>
<p>My questions are</p>
<ol>
<li><p>How to add information to the file? Let's say, I want to add DJF, 204 for Chicago, how do I do that?</p>
</li>
<li><p>How do I calculate the total of votes for each school code? Like for WPE for both Chicago and California?</p>
</li>
</ol>
<p>I tried using dictionaries to make it easier, but I feel lost. Also, I set the code to add new info to the file, but I want to add it to a specific category and not just at the end of the file.</p>
<p>P.S. I'm a beginner so it's still a lot for me to process.</p>
| [
{
"answer_id": 74433697,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 1,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433712,
"author": "ikegami",
"author_id": 589924,
"author_profile": "https://Stackoverflow.com/users/589924",
"pm_score": 2,
"selected": false,
"text": "execve"
},
{
"answer_id": 74433733,
"author": "Mathieu",
"author_id": 1212012,
"author_profile": "https://Stackoverflow.com/users/1212012",
"pm_score": 2,
"selected": false,
"text": "execve"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501836/"
] |
74,433,704 | <p>So let's say I ask for some input of n-rows and k-columns:</p>
<pre><code>rows = n
columns = k
</code></pre>
<p>What I want to do is to create an array of dimensions <code>(rows, columns)</code> and then populate said array with a set of numbers starting from some number <code>x</code> with some step size <code>y</code> such that no matter the inputs for <code>rows</code> and <code>columns</code> it would be able to create an array of said dimensions with the "last"/bottom right element of the array then being some yet to be determined number <code>z</code>.</p>
<p>As an example input I could have:</p>
<pre><code>rows = 4
columns = 3
# Starting number
x = 1
# Step size
y = 2
</code></pre>
<p>The expected output would then be:</p>
<pre><code>array = [[ 1 3 5]
[ 7 9 11]
[13 15 17]
[19 21 23]]
</code></pre>
<p>As the array changes dimensions, then so would the numbers inside it, determined by the dimensions of the array, the starting number and step size.</p>
| [
{
"answer_id": 74433795,
"author": "3dSpatialUser",
"author_id": 5775358,
"author_profile": "https://Stackoverflow.com/users/5775358",
"pm_score": 2,
"selected": false,
"text": "import numpy\nrows = 4\ncolumns = 3\n# Starting number\nx = 1\n# Step size\ny = 2\n\narray = np.arange(x, (rows*columns)*y+x, y).reshape(rows, columns)\n"
},
{
"answer_id": 74433796,
"author": "Sala",
"author_id": 15673412,
"author_profile": "https://Stackoverflow.com/users/15673412",
"pm_score": 2,
"selected": false,
"text": "start = 1\nincrement = 2\nrows = 4\ncols = 3\n\narray = np.zeros(shape=(rows, cols))\n\nfor i in range(rows):\n for j in range(cols):\n array[i][j] = start\n start += increment\n"
},
{
"answer_id": 74433822,
"author": "KillerRebooted",
"author_id": 18554284,
"author_profile": "https://Stackoverflow.com/users/18554284",
"pm_score": 1,
"selected": false,
"text": "rows = 4\ncolumns = 3\n\n# Starting number\nx = 1\n\n# Step size\ny = 2\n\narray = []\nnum = 1\n\nfor i in range(rows):\n list = []\n for j in range(columns):\n list.append(num)\n\n num += y\n\n array.append(list)\n\nprint(array)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16854347/"
] |
74,433,706 | <p>I am trying to display a certain series of widgets based on objects contained in a formula. Here is how I am assigning the widgets to a variable based on their type.</p>
<pre><code> var l = TankFormulaLength(length: tankSpec.tankSpecs.imperialLength);
var w = TankFormulaWidth(width: tankSpec.tankSpecs.imperialWidth);
var h = TankFormulaHeight(height: tankSpec.tankSpecs.imperialHeight);
var d = TankFormulaDiameter(diameter: tankSpec.tankSpecs.imperialDiameter);
List<Widget> tankMeasurements = [l, w, h, d];
</code></pre>
<p>Here is where these are being used.</p>
<pre><code>Column(children: <Widget>[
...tankFormula(tankMeasurements,
tankSpec.tankSpecs.formula),
],
),
</code></pre>
<p>The formula is pulled from an api call that happens based on a tank specification and is delivered as show below..currently I am printing it to the console so I can see what formula each tank spec is using.<a href="https://i.stack.imgur.com/96xyx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96xyx.png" alt="enter image description here" /></a></p>
<p>in my tankFormula function, I want to take the specific formula and use it to iterate through my list of widgets and only return the ones specific to the formula. Currently I am able to make all of them show up, because they are not being filtered.</p>
<pre><code>List<Widget> tankFormula(formulaComponents, formula) {
List<Widget> calculatedFormula = [];
print(formula);
return formulaComponents;
}
</code></pre>
<p>I am unsure how to get the end result I am looking for. As shown in the screenshot below, I only needs the fields from the formula, 'Length' and 'Diameter', to show up as those are the only ones used in this particular formula for this specific tank specification. In other instances, it could be some of the additional fields i.e. 'Width or 'Height'. Again, based on the formula returned from the API. The additional fields 'Product', 'Tank Capacity', and 'Sensor Offset', will always be displayed.</p>
<p><a href="https://i.stack.imgur.com/M8KLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M8KLP.png" alt="enter image description here" /></a></p>
<p>I am aware that calculatedFormula is not being used. I created this variable to hold the returned List of Widgets that will be displayed on the screen. I am stuck and unsure how to move forward. Thank you sincerely for your help in advance!</p>
| [
{
"answer_id": 74435733,
"author": "void void",
"author_id": 18969611,
"author_profile": "https://Stackoverflow.com/users/18969611",
"pm_score": 1,
"selected": false,
"text": " Widget build(BuildContext context) {\n return Column(\n children: [\n if (list.contains('l')) TankFormulaLength(),\n if (list.contains('h')) TankFormulaHeight(),\n if (list.contains('w')) TankFormulaWidth(),\n if (list.contains('d')) TankFormulaDiameter(),\n ],\n );\n }\n"
},
{
"answer_id": 74436231,
"author": "Robert Sandberg",
"author_id": 13263384,
"author_profile": "https://Stackoverflow.com/users/13263384",
"pm_score": 0,
"selected": false,
"text": "return Column(\n children: list.map<Widget>((e) {\n switch(e) {\n case 'l': return TankFormulaLength(...);\n case 'h': return TankFormulaHeight(...);\n case 'w': return TankFormulaWidth(...);\n case 'd': return TankFormulaDiameter(...);\n }\n return const SizedBox.shrink();\n ).toList(),\n );\n \n"
},
{
"answer_id": 74439034,
"author": "Mackina",
"author_id": 8227931,
"author_profile": "https://Stackoverflow.com/users/8227931",
"pm_score": 0,
"selected": false,
"text": " List<Widget> tankFormula(l, w, h, d, formula) {\n List<Widget> calculatedFormula = [];\n if (formula.contains('l')) {\n calculatedFormula.add(TankFormulaLength(length: l));\n }\n if (formula.contains('w')) {\n calculatedFormula.add(TankFormulaWidth(width: w));\n }\n if (formula.contains('h')) {\n calculatedFormula.add(TankFormulaHeight(height: h));\n }\n if (formula.contains('d')) {\n calculatedFormula.add(TankFormulaDiameter(diameter: d));\n }\n\n print(formula);\n return calculatedFormula;\n }\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8227931/"
] |
74,433,732 | <p>I am trying to replace all dashes(-) by a "br" but it gives me issues.</p>
<p>I have tried</p>
<pre><code>var strNewString = $('.member__designation').html().replace(/-/g,'<br>');
$('.member__designation').html(strNewString);
</code></pre>
<p>Here is the html
<a href="https://i.stack.imgur.com/hOtWd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hOtWd.png" alt="" /></a></p>
<p>Before applying the code above
<img src="https://i.stack.imgur.com/OfjQ6.png" alt="" /></p>
<p>After applying the code above
<img src="https://i.stack.imgur.com/g1lly.png" alt="" /></p>
| [
{
"answer_id": 74435733,
"author": "void void",
"author_id": 18969611,
"author_profile": "https://Stackoverflow.com/users/18969611",
"pm_score": 1,
"selected": false,
"text": " Widget build(BuildContext context) {\n return Column(\n children: [\n if (list.contains('l')) TankFormulaLength(),\n if (list.contains('h')) TankFormulaHeight(),\n if (list.contains('w')) TankFormulaWidth(),\n if (list.contains('d')) TankFormulaDiameter(),\n ],\n );\n }\n"
},
{
"answer_id": 74436231,
"author": "Robert Sandberg",
"author_id": 13263384,
"author_profile": "https://Stackoverflow.com/users/13263384",
"pm_score": 0,
"selected": false,
"text": "return Column(\n children: list.map<Widget>((e) {\n switch(e) {\n case 'l': return TankFormulaLength(...);\n case 'h': return TankFormulaHeight(...);\n case 'w': return TankFormulaWidth(...);\n case 'd': return TankFormulaDiameter(...);\n }\n return const SizedBox.shrink();\n ).toList(),\n );\n \n"
},
{
"answer_id": 74439034,
"author": "Mackina",
"author_id": 8227931,
"author_profile": "https://Stackoverflow.com/users/8227931",
"pm_score": 0,
"selected": false,
"text": " List<Widget> tankFormula(l, w, h, d, formula) {\n List<Widget> calculatedFormula = [];\n if (formula.contains('l')) {\n calculatedFormula.add(TankFormulaLength(length: l));\n }\n if (formula.contains('w')) {\n calculatedFormula.add(TankFormulaWidth(width: w));\n }\n if (formula.contains('h')) {\n calculatedFormula.add(TankFormulaHeight(height: h));\n }\n if (formula.contains('d')) {\n calculatedFormula.add(TankFormulaDiameter(diameter: d));\n }\n\n print(formula);\n return calculatedFormula;\n }\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19497015/"
] |
74,433,780 | <p>This is my first class with a default member and I'm still getting a feel for it. I have a let / get property data:</p>
<pre><code>class ArrayClass
private D as variant
Property Get data() As Variant
data = D
End Property
Property Let data(arg1 As Variant)
D = arg1
End Property
</code></pre>
<p>I have added the following in my .cls file (using notepad) to make data the default parameter which looks like this:</p>
<pre><code>Property Get data() As Variant
Attribute data.VB_UserMemId = 0
data = D
End Property
</code></pre>
<p>I'm just testing this to see how well this works using an array for "D":</p>
<pre><code>Dim testArray As ArrayClass
Dim passArray(5, 1) As Variant
passArray(0, 0) = 1
passArray(1, 0) = 2
passArray(2, 0) = 3
passArray(3, 0) = 4
passArray(4, 0) = 5
passArray(5, 0) = 6
passArray(0, 1) = 7
passArray(1, 1) = 8
passArray(2, 1) = 9
passArray(3, 1) = 10
passArray(4, 1) = 11
passArray(5, 1) = 12
Set testArray = new ArrayClass
testArray = passArray
testArray(1, 1) = 5
Debug.Print testArray(2, 1)
</code></pre>
<p>It "mostly" works. The "testArray = passArray" calls the "Let Data" property, and assigns the passArray to parameter "D" inside the object.</p>
<p>Also, "Debug.Print testArray(2,1)" also works. That calls the "Get Data" property, and it returns the index values of 2,1 of the "D" parameter in the object.</p>
<p>My problem is the "testArray(1,1) = 5" instruction. The intent was to assign the 1,1 index to parameter D to the number 5. But what happens is it calls the "Get Data" property, instead of the "Let Data" property.</p>
<p>To be clear, I wasn't really expecting it to work because I'm not yet sure how to do it. But I'm at a loss on why its calling the "get property" instead of the "let property" being that the instruction is on the left side of the equal sign.</p>
<p>Anyone have any ideas on how to make it work? Thanks.</p>
| [
{
"answer_id": 74434818,
"author": "Cristian Buse",
"author_id": 8488913,
"author_profile": "https://Stackoverflow.com/users/8488913",
"pm_score": 2,
"selected": false,
"text": "testArray(1,1) = 5"
},
{
"answer_id": 74450628,
"author": "Anthony Meeks",
"author_id": 18103643,
"author_profile": "https://Stackoverflow.com/users/18103643",
"pm_score": 2,
"selected": true,
"text": "Property Let data(ParamArray sizes() As Variant, data As Variant)\nend property\nProperty Get data(ParamArray sizes() As Variant) As Variant\n Attribute data.VB_UserMemID = 0 'This line makes the data property the default property. \n 'It is Only visible/editable in .cls file opened in text editer\nend property\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433780",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18103643/"
] |
74,433,786 | <p>I have the next regex:</p>
<pre><code>comment_pattern = "(/\*[\w\W]*\*/)"
</code></pre>
<p>With it I am able to search match strings like bellow:</p>
<pre><code>/*
blablabla example
blabla
*/
</code></pre>
<p>Basically I would also like to search in those comments for the variable Compiler_Warning -> in case its inside a multiline comment to get all the expression-> Can some one tell me how to get it.
Basically my regex should return a match for :</p>
<pre><code>/* blabla
Compiler_Warning blablalba
*/
</code></pre>
<p>But not for the first example.</p>
| [
{
"answer_id": 74433937,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "import re\n\ntext = \"\"\"\\\n/*\nblablabla example \nblabla\n*/\n\nNot comment\n\n/* blabla\nCompiler_Warning blablalba\n*/\"\"\"\n\npat = re.compile(r\"/\\*(?=(?:(?!\\*/).)*?Compiler_Warning).*?\\*/\", flags=re.S)\n\nfor comment in pat.findall(text):\n print(comment)\n"
},
{
"answer_id": 74434912,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": false,
"text": "/*"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15824988/"
] |
74,433,810 | <p>I'm trying to remove "ال" from every arabic string thats contains "ال"</p>
<p>I'm trying to do this by using this code but its only delete "ال" from the first word:</p>
<pre><code>input : الغيث الغيث الغيث
output : غيث الغيث الغيث
what i need: غيث غيث غيث
</code></pre>
<pre class="lang-cs prettyprint-override"><code>string[] prefixes = { "ال", "اَلْ", "الْ", "اَل" };
foreach (string prefix in prefixes)
{
if (text.StartsWith(prefix))
{
text = text.Substring(prefix.Length);
break;
}
</code></pre>
| [
{
"answer_id": 74433961,
"author": "Dmitry Bychenko",
"author_id": 2319407,
"author_profile": "https://Stackoverflow.com/users/2319407",
"pm_score": 2,
"selected": false,
"text": "Replace"
},
{
"answer_id": 74434320,
"author": "SaSkY",
"author_id": 18104248,
"author_profile": "https://Stackoverflow.com/users/18104248",
"pm_score": 2,
"selected": false,
"text": "\\b\\u0627(?:\\u0644\\u0652?|\\u064e\\u0644\\u0652?)\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20314375/"
] |
74,433,811 | <p>Hello Guys I have a problem with my bottom navigation bar. The problem is that I created a stack, in that there is a container with gradient color and then there is a bottomAppBar, I made the bottomAppBar color transparent. I actual problem is that I have a centerDocked floating action button and it's margin is 5. Because of container my floating action button notched is not visible is there any possibility that I have the gradient color along with notch below floating action button? I hope you understand my problem.</p>
<pre><code>floatingActionButton: FloatingActionButton(
//backgroundColor: Color(0XFFFF4F5A),
backgroundColor: Colors.black87,
onPressed: () {},
child: const Icon(
Icons.camera_alt,
color: Colors.white,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Stack(
children: [
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0XFFFF1C2A),
Color(0XFFFF4F5A),
],
),
),
height: 48,
),
BottomAppBar(
elevation: 0,
color: Colors.transparent,
shape: CircularNotchedRectangle(),
notchMargin: 5,
child: Padding(
padding: EdgeInsets.only(left: 25, right: 25),
child ...
),
)
],
)
</code></pre>
| [
{
"answer_id": 74434161,
"author": "Yeasin Sheikh",
"author_id": 10157127,
"author_profile": "https://Stackoverflow.com/users/10157127",
"pm_score": 2,
"selected": true,
"text": "bottomNavigationBar: BottomAppBar(\n elevation: 0,\n color: Colors.transparent,\n shape: CircularNotchedRectangle(),\n notchMargin: 5,\n clipBehavior: Clip.hardEdge,\n child: Container(\n height: kToolbarHeight,\n decoration: const BoxDecoration(\n gradient: LinearGradient(\n begin: Alignment.topLeft,\n end: Alignment.bottomRight,\n colors: [\n Color(0XFFFF1C2A),\n Color(0XFFFF4F5A),\n ],\n ),\n ),\n child: Padding(\n padding: EdgeInsets.only(left: 25, right: 25),\n child: Text(\"tada\"),\n ),\n )),\n\n"
},
{
"answer_id": 74434231,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 0,
"selected": false,
"text": "clipBehavior: Clip.antiAlias, // or Clip.hardEdge\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10535413/"
] |
74,433,826 | <p>I have my funcion :</p>
<pre><code>fun1 <- function( x, y, z ){
1 / (1 + (x / y)^z)
}
</code></pre>
<p>I want to crate <code>curve</code> for my function</p>
<p>On X axxis I want values I will give for x, e.g. 10 50, 1000 in my function for Y axis I want fun1 results given different x. For y in function I wants the value 1 and for z I want 0.5 always regardless of the given x.</p>
<p>I try to emulate this code from the site <a href="https://r-charts.com/evolution/curve/" rel="nofollow noreferrer">https://r-charts.com/evolution/curve/</a></p>
<pre><code># Function
fun <- function(x) {
sin(sqrt(x ^ 2))
}
# Plot
curve(fun, from = -7, to = 7)
</code></pre>
| [
{
"answer_id": 74434161,
"author": "Yeasin Sheikh",
"author_id": 10157127,
"author_profile": "https://Stackoverflow.com/users/10157127",
"pm_score": 2,
"selected": true,
"text": "bottomNavigationBar: BottomAppBar(\n elevation: 0,\n color: Colors.transparent,\n shape: CircularNotchedRectangle(),\n notchMargin: 5,\n clipBehavior: Clip.hardEdge,\n child: Container(\n height: kToolbarHeight,\n decoration: const BoxDecoration(\n gradient: LinearGradient(\n begin: Alignment.topLeft,\n end: Alignment.bottomRight,\n colors: [\n Color(0XFFFF1C2A),\n Color(0XFFFF4F5A),\n ],\n ),\n ),\n child: Padding(\n padding: EdgeInsets.only(left: 25, right: 25),\n child: Text(\"tada\"),\n ),\n )),\n\n"
},
{
"answer_id": 74434231,
"author": "manhtuan21",
"author_id": 8921450,
"author_profile": "https://Stackoverflow.com/users/8921450",
"pm_score": 0,
"selected": false,
"text": "clipBehavior: Clip.antiAlias, // or Clip.hardEdge\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501829/"
] |
74,433,835 | <p>I am running a suite of APIs test cases which is build on maven Project. There are some failure in Test cases due to this my entire build is getting failed. how to make build success even the Test Case got failed. Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test</p>
<p>Maven build failure solution</p>
| [
{
"answer_id": 74433980,
"author": "toinetoine",
"author_id": 1053362,
"author_profile": "https://Stackoverflow.com/users/1053362",
"pm_score": 1,
"selected": false,
"text": "-DskipTests"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501844/"
] |
74,433,854 | <p>I've got a button that I want to have enact changes to an element that is the sibling of the button's parent.</p>
<pre><code><div class="parent">
<div class="target"></div>
<div class="child">
<button>Click!</button>
</div>
</div>
</code></pre>
<p>I've tried playing around with <code>event.target.closest</code> and similar, like so, but I cannot get it to work:</p>
<pre><code>function clicks(event) {
const childElement = event.target.closest(".child");
const parentElement = childElement.target.closest(".parent");
const targetElement = parentElement.target.closest(".target");
targetElement.style.display = "none";
}
addEventListener('click', clicks);
</code></pre>
<p><a href="https://i.stack.imgur.com/j0BJz.png" rel="nofollow noreferrer">Vizualisation of intention</a></p>
| [
{
"answer_id": 74433980,
"author": "toinetoine",
"author_id": 1053362,
"author_profile": "https://Stackoverflow.com/users/1053362",
"pm_score": 1,
"selected": false,
"text": "-DskipTests"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18179440/"
] |
74,433,868 | <p>I have the following structure, when the label is required, there’s a star next to the label. The problem that I’m having is that if the label has an icon and tooltip inside, it get’s between the label and the star. What could be the possible solution to always have the start right after the label?</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>.required:after {
content: '*';
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><label for="input-required" class="required">
Label
<span class="tooltip">
<i class="icon icon-info"></i>
<span class="message top">Message</span>
</span>
</label></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74433984,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 0,
"selected": false,
"text": ".required > span:first-child:after {\n content: '*';\n}"
},
{
"answer_id": 74433989,
"author": "Rene van der Lende",
"author_id": 2015909,
"author_profile": "https://Stackoverflow.com/users/2015909",
"pm_score": 0,
"selected": false,
"text": "<label>"
},
{
"answer_id": 74433995,
"author": "borderr",
"author_id": 20486034,
"author_profile": "https://Stackoverflow.com/users/20486034",
"pm_score": -1,
"selected": false,
"text": "<label for=\"input-required\" class=\"required\">\n Label\n <span class=\"star\">*</span>\n <span class=\"tooltip\">\n <i class=\"icon icon-info\"></i>\n <span class=\"message top\">Message</span>\n </span>\n</label>\n"
},
{
"answer_id": 74434153,
"author": "A Haworth",
"author_id": 10867454,
"author_profile": "https://Stackoverflow.com/users/10867454",
"pm_score": 2,
"selected": true,
"text": ".required::after,\n.required>span::before {\n content: '*';\n}\n\n.required:has(span)::after {\n content: '';\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12130996/"
] |
74,433,943 | <p>I am working on an app that uses some older dependencies and deprecated methods which I realized after upgrading to latest Flutter version.</p>
<p>So until i correct all of these, i downgraded back to v2.2.3 to be able to keep working on my app.</p>
<p>But now when i try to run i get some error that i didnt have before.</p>
<pre><code>Running Gradle task 'assembleDebug'...
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/tooltip.dart:158:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/tooltip.dart:166:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/tooltip.dart:188:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((_) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/tooltip.dart:202:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((_) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/tooltip.dart:361:31: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/ballon_transition.dart:150:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/balloon.dart:56:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/balloon_positioner.dart:134:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((_) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/obfuscate_tooltip_item.dart:34:29: Error: Method 'addObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addObserver(this);
^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/obfuscate_tooltip_item.dart:43:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/simple_tooltip-1.2.0/lib/src/obfuscate_tooltip_item.dart:59:29: Error: Method 'removeObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.removeObserver(this);
^^^^^^^^^^^^^^
/C:/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/carousel_slider-4.1.1/lib/carousel_slider.dart:268:7: Error: No named parameter with the name 'padEnds'.
padEnds: widget.options.padEnds,
^^^^^^^
/C:/Flutter/flutter/packages/flutter/lib/src/widgets/page_view.dart:664:3: Context: Found this candidate, but the arguments don't match.
PageView.builder({
^^^^^^^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 19s
Exception: Gradle task assembleDebug failed with exit code 1
</code></pre>
<p>I tried changing the location and removing of "?" as suggested in other threads but it only mad it worst.</p>
<p>Any idea of how i could solve this issue?</p>
| [
{
"answer_id": 74433984,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 0,
"selected": false,
"text": ".required > span:first-child:after {\n content: '*';\n}"
},
{
"answer_id": 74433989,
"author": "Rene van der Lende",
"author_id": 2015909,
"author_profile": "https://Stackoverflow.com/users/2015909",
"pm_score": 0,
"selected": false,
"text": "<label>"
},
{
"answer_id": 74433995,
"author": "borderr",
"author_id": 20486034,
"author_profile": "https://Stackoverflow.com/users/20486034",
"pm_score": -1,
"selected": false,
"text": "<label for=\"input-required\" class=\"required\">\n Label\n <span class=\"star\">*</span>\n <span class=\"tooltip\">\n <i class=\"icon icon-info\"></i>\n <span class=\"message top\">Message</span>\n </span>\n</label>\n"
},
{
"answer_id": 74434153,
"author": "A Haworth",
"author_id": 10867454,
"author_profile": "https://Stackoverflow.com/users/10867454",
"pm_score": 2,
"selected": true,
"text": ".required::after,\n.required>span::before {\n content: '*';\n}\n\n.required:has(span)::after {\n content: '';\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13217134/"
] |
74,433,973 | <p>I have dotnet WebAPI and I'm trying to get a specific behaviour but am constantly getting 415 responses.</p>
<p>I have reproduced this by starting a new webapi project using <code>dotnet new webapi</code> on the command line. From there, I added two things: a new controller, and a model class. In my real project the model class is obviously a bit more complex, with inheritance and methods etc...</p>
<p>Here they are:</p>
<pre><code>[HttpGet("/data")]
public async Task<IActionResult> GetModel(BodyParams input)
{
var response = new { Message = "Hello", value = input.valueOne };
return Ok(response);
}
public class BodyParams {
public bool valueOne { get; set; } = true;
}
</code></pre>
<p>My goal is that the user can call https://localhost:7222/data with no headers or body needed at all, and will get the response - BodyParams will be used with the default value of true. Currently, from postman, or from the browser, I get a 415 response.</p>
<p>I've worked through several suggestions on stack and git but nothing seems to be working for me. Specifically, I have tried:</p>
<ol>
<li>Adding <code>[FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)]</code> into the controller, but this makes no difference unless I provide an empty {} json object in the body. This is not what I want.</li>
<li>Making BodyParams nullable - again, no change.</li>
<li>Adding <code>.AddControllers(opt => opt.AllowEmptyInputInBodyModelBinding = true)</code>... again, no change.</li>
<li>I Implemented the solution suggested <a href="https://stackoverflow.com/questions/72690148/how-to-disable-content-type-validation-for-empty-request-bodies-in-asp-net-core">here</a> using the attribute modification in the comment by @HappyGoLucky. Again, this did not give the desired outcome, but it did change the response to : 400 - "The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true."</li>
<li>I tried modifying the solution in (4) to manually set <code>context.HttpContext.Request.Body</code> to an empty json object... but I can't figure out the syntax for this because it need to be a byte array and at that point I feel like I am way over complicating this.</li>
</ol>
<p>How can I get the controller to use BodyParams with default values in the case that the user provides no body and no headers at all?</p>
| [
{
"answer_id": 74433984,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 0,
"selected": false,
"text": ".required > span:first-child:after {\n content: '*';\n}"
},
{
"answer_id": 74433989,
"author": "Rene van der Lende",
"author_id": 2015909,
"author_profile": "https://Stackoverflow.com/users/2015909",
"pm_score": 0,
"selected": false,
"text": "<label>"
},
{
"answer_id": 74433995,
"author": "borderr",
"author_id": 20486034,
"author_profile": "https://Stackoverflow.com/users/20486034",
"pm_score": -1,
"selected": false,
"text": "<label for=\"input-required\" class=\"required\">\n Label\n <span class=\"star\">*</span>\n <span class=\"tooltip\">\n <i class=\"icon icon-info\"></i>\n <span class=\"message top\">Message</span>\n </span>\n</label>\n"
},
{
"answer_id": 74434153,
"author": "A Haworth",
"author_id": 10867454,
"author_profile": "https://Stackoverflow.com/users/10867454",
"pm_score": 2,
"selected": true,
"text": ".required::after,\n.required>span::before {\n content: '*';\n}\n\n.required:has(span)::after {\n content: '';\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11571390/"
] |
74,433,982 | <p>There is a toggle button in AutoCAD's default ribbons, but I don't know how to add it to AutoCAD using C# (or any other programming language).</p>
<p><a href="https://i.stack.imgur.com/R3Vpx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R3Vpx.png" alt="sample of toggle button in autocad" /></a></p>
| [
{
"answer_id": 74433984,
"author": "Adam",
"author_id": 12571484,
"author_profile": "https://Stackoverflow.com/users/12571484",
"pm_score": 0,
"selected": false,
"text": ".required > span:first-child:after {\n content: '*';\n}"
},
{
"answer_id": 74433989,
"author": "Rene van der Lende",
"author_id": 2015909,
"author_profile": "https://Stackoverflow.com/users/2015909",
"pm_score": 0,
"selected": false,
"text": "<label>"
},
{
"answer_id": 74433995,
"author": "borderr",
"author_id": 20486034,
"author_profile": "https://Stackoverflow.com/users/20486034",
"pm_score": -1,
"selected": false,
"text": "<label for=\"input-required\" class=\"required\">\n Label\n <span class=\"star\">*</span>\n <span class=\"tooltip\">\n <i class=\"icon icon-info\"></i>\n <span class=\"message top\">Message</span>\n </span>\n</label>\n"
},
{
"answer_id": 74434153,
"author": "A Haworth",
"author_id": 10867454,
"author_profile": "https://Stackoverflow.com/users/10867454",
"pm_score": 2,
"selected": true,
"text": ".required::after,\n.required>span::before {\n content: '*';\n}\n\n.required:has(span)::after {\n content: '';\n}"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19762249/"
] |
74,433,987 | <h1>Python concurrent.futures.ProcessPoolExecutor crashing with full RAM</h1>
<h2>Program description</h2>
<p>Hi, I've got a computationally heavy function which I want to run in parallel. The function is a test that accepts as inputs:</p>
<ul>
<li>a DataFrame to test on</li>
<li>parameters based on which the calculations will be ran.</li>
</ul>
<p>The return value is a short list of calculation results.</p>
<p>I want to run the same function in a for loop with different parameters and the same input DataFrame, basically run a brute-force to find optimal parameters for my problem.</p>
<h2>The code I've written</h2>
<p>I currently am running the code concurrently with ProcessPoolExecutor from the module concurrent.futures.</p>
<pre class="lang-py prettyprint-override"><code>import concurrent.futures
from itertools import repeat
import pandas as pd
from my_tests import func
parameters = [
(arg1, arg2, arg3),
(arg1, arg2, arg3),
...
]
large_df = pd.read_csv(csv_path)
with concurrent.futures.ProcessPoolExecutor() as executor:
for future in executor.map(func, repeat(large_df.copy()), parameters):
test_result = future.result()
...
</code></pre>
<h2>The problem</h2>
<p>The problem I face is that I need to run a large amount of iterations, but my program crashes almost instantly.</p>
<p>In on order for it not to crash, I need to limit it to max 4 workers, which is 1/4 of my CPU resources.</p>
<pre class="lang-py prettyprint-override"><code>with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
...
</code></pre>
<p>I figured out my program crashes due to a full RAM (16 GB). What I found weird is that when I was running it on more workers, it was gradually eating more and more RAM, which it never released, until it crashed.</p>
<p>Instead of passing a copy of the DataFrame, I tried to pass the file path, but apart of slowing down my program, it didn't change anything.</p>
<p>Do you have any idea of why that problem occurs and how to solve it?</p>
| [
{
"answer_id": 74450459,
"author": "Booboo",
"author_id": 2823719,
"author_profile": "https://Stackoverflow.com/users/2823719",
"pm_score": 2,
"selected": true,
"text": "map"
},
{
"answer_id": 74473866,
"author": "janboro",
"author_id": 17163860,
"author_profile": "https://Stackoverflow.com/users/17163860",
"pm_score": 0,
"selected": false,
"text": "func"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74433987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17163860/"
] |
74,434,030 | <p>We store volunteer hours in a database for every user, i'm trying to figure out how to structure a Postgres SQL query to find the percentage of total hours a specific user has spent at a location vs the total number of hours at that location (by any user)</p>
<pre><code>CREATE TABLE entries (
id INT,
userId INT,
volunteerHours DOUBLE PRECISION NOT NULL,
location INT
);
INSERT INTO entries (id, userId, volunteerHours, location) VALUES (1, 1, 3.0, 2);
INSERT INTO entries (id, userId, volunteerHours, location) VALUES (2, 1, 3.0, 1);
INSERT INTO entries (id, userId, volunteerHours, location) VALUES (3, 1, 3.0, 1);
INSERT INTO entries (id, userId, volunteerHours, location) VALUES (4, 2, 3.0, 1);
INSERT INTO entries (id, userId, volunteerHours, location) VALUES (5, 2, 3.0, 1);
</code></pre>
<p><em>There could be hundreds of these entries in the db, these are shown just for examples</em></p>
<p>Pseudo code:</p>
<pre><code>SELECT
(SELECT location from entries ORDER BY id DESC FETCH NEXT 1 ROWS ONLY) as lastEntryLocation,
(SELECT SUM(volunteerHours) from entries WHERE userId = 2 AND location = lastEntryLocation) as userHours,
(SELECT SUM(volunteerHours) from entries AND location = lastEntryLocation) as totalHours,
(SELECT userHours / totalHours) as userContributionPercentage
</code></pre>
<p>I'm still learning how to write custom SQL queries, hoping someone could at least point me in the right direction of how I should be structuring this query correctly, to return in this situation <strong>0.50</strong></p>
<p>Thought process from sudo query:</p>
<ol>
<li>Pull the latest entry in the db to determine the last location ID value inserted</li>
<li>Use last location value ID to then query the <code>SUM</code> of all <code>userId 2</code>'s hours</li>
<li>Use last location value ID to query the <code>SUM</code> of all users hours</li>
<li>Divide <code>userId 2</code>'s total hours by the total hours at that specific location</li>
</ol>
<p>I would like to try and do all of this in a SQL query if possible (I could break it out into separate SQL query calls and programmatically do the math, but I would prefer to learn how to do this through one SQL query call if at all possible.</p>
<p>Created a db fiddle as well for this:
<a href="https://www.db-fiddle.com/f/7dfFZTa2yN3jpSMVLcFXWc/4" rel="nofollow noreferrer">https://www.db-fiddle.com/f/7dfFZTa2yN3jpSMVLcFXWc/4</a></p>
<p>If you could also explain why you chose a specific method used to create the query for this, that would greatly help me to understand the reasoning behind it and know where to look further to learn more myself. Thank you!</p>
<p>EDIT: Looking for a way to not have to do the query twice for the latest location (as it feels like the wrong way to do this)</p>
| [
{
"answer_id": 74434185,
"author": "Farhan Mushtaq",
"author_id": 20396064,
"author_profile": "https://Stackoverflow.com/users/20396064",
"pm_score": 0,
"selected": false,
"text": "SELECT\n ( SELECT\n ( SELECT SUM(volunteerHours) \n from entries \n WHERE userId = 2 \n AND location = (\n SELECT location \n from entries \n ORDER BY id \n DESC FETCH NEXT 1 ROWS ONLY))\n / \n ( SELECT SUM(volunteerHours) \n from entries \n Where location = (\n SELECT location \n from entries \n ORDER BY id DESC \n FETCH NEXT 1 ROWS ONLY))\n ) as userContributionPercentage\n"
},
{
"answer_id": 74434835,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 2,
"selected": true,
"text": "select distinct on (e.userId) \n sum(e.volunteerHours) over (partition by userId,location,id)\n / sum(e.volunteerHours) over (partition by userId,location) \n as percentage_volunteered_here\nfrom entries e\nwhere userId=1\norder by userId, id desc;\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/378506/"
] |
74,434,035 | <p>I am trying to build iOS app from expo managed project. The build fails At fastlane step.</p>
<p>In Expo SDK 44, 45 everything was okay. But when I upgrade to SDK 46, I am facing the issue.</p>
<p>Here is my package.json</p>
<pre><code> {
"name": "App123",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@expo/vector-icons": "^13.0.0",
"@openspacelabs/react-native-zoomable-view": "^2.0.4",
"@react-native-community/datetimepicker": "6.2.0",
"@react-native-community/netinfo": "9.3.0",
"@react-native-community/slider": "4.2.3",
"@react-native-google-signin/google-signin": "^8.0.0",
"@react-navigation/bottom-tabs": "^6.4.0",
"@react-navigation/drawer": "^6.5.0",
"@react-navigation/native": "^6.0.13",
"@react-navigation/native-stack": "^6.9.0",
"@react-navigation/stack": "^6.3.2",
"@stripe/stripe-react-native": "0.13.1",
"apisauce": "^2.1.6",
"expo": "~46.0.13",
"expo-apple-authentication": "^4.3.0",
"expo-auth-session": "^3.7.1",
"expo-constants": "^13.2.4",
"expo-dev-client": "~1.3.1",
"expo-document-picker": "^10.3.0",
"expo-firebase-recaptcha": "^2.3.0",
"expo-font": "^10.2.1",
"expo-image-picker": "^13.3.1",
"expo-linear-gradient": "^11.4.0",
"expo-linking": "^3.2.2",
"expo-localization": "^13.1.0",
"expo-location": "^14.3.0",
"expo-notifications": "^0.16.1",
"expo-secure-store": "^11.3.0",
"expo-splash-screen": "^0.16.2",
"expo-status-bar": "^1.4.0",
"expo-tracking-transparency": "^2.3.1",
"expo-updates": "^0.14.6",
"firebase": "9.9.2",
"formik": "^2.2.9",
"html-entities": "^2.3.3",
"lodash": "^4.17.21",
"lottie-react-native": "5.1.3",
"mime": "^3.0.0",
"moment": "^2.29.4",
"qs": "^6.11.0",
"react": "18.0.0",
"react-native": "0.69.6",
"react-native-credit-card-input": "^0.4.1",
"react-native-credit-card-input-view": "^0.0.7",
"react-native-draggable-flatlist": "^3.1.2",
"react-native-fbsdk-next": "^11.0.0",
"react-native-geocoding": "^0.5.0",
"react-native-gesture-handler": "~2.5.0",
"react-native-google-mobile-ads": "^8.2.0",
"react-native-maps": "0.31.1",
"react-native-phone-number-input": "^2.1.0",
"react-native-progress": "^5.0.0",
"react-native-razorpay": "^2.2.9",
"react-native-read-more-text": "^1.1.2",
"react-native-reanimated": "~2.9.1",
"react-native-safe-area-context": "4.3.1",
"react-native-screens": "~3.15.0",
"react-native-svg": "12.3.0",
"react-native-webview": "11.23.0",
"react-native-youtube-iframe": "^2.2.2",
"yup": "^0.32.11"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
</code></pre>
<p>Here is fastlane error logs</p>
<pre><code>Executing App123 » Start Packager on http://localhost:8081
› Compiling App123 » ExpoModulesProvider.swift
› Compiling App123 » noop-file.swift
› Compiling App123 » main.m
› Compiling App123 » App123.c
› Linking App123 » App123
❌ ld: '/Users/expo/Library/Developer/Xcode/DerivedData/App123-djegplhkioltttdpxhkjholomhle/Build/Intermediates.noindex/ArchiveIntermediates/App123/BuildProductsPath/Release-iphoneos/XCFrameworkIntermediates/FBAEMKit/FBAEMKit.framework/FBAEMKit' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Users/expo/Library/Developer/Xcode/DerivedData/App123-djegplhkioltttdpxhkjholomhle/Build/Intermediates.noindex/ArchiveIntermediates/App123/BuildProductsPath/Release-iphoneos/XCFrameworkIntermediates/FBAEMKit/FBAEMKit.framework/FBAEMKit' for architecture arm64
❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)
▸ ** ARCHIVE FAILED **
▸ The following build commands failed:
▸ Ld /Users/expo/Library/Developer/Xcode/DerivedData/App123-djegplhkioltttdpxhkjholomhle/Build/Intermediates.noindex/ArchiveIntermediates/App123/InstallationBuildProductsLocation/Applications/App123.app/App123 normal (in target 'App123' from project 'App123')
▸ (1 failure)
2022-11-10 03:21:16.259 xcodebuild[4548:14785] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-11-10 03:21:16.259 xcodebuild[4548:14785] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-11-10 03:21:16.334 xcodebuild[4548:14785] XType: failed to connect - Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.fonts was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.fonts was invalidated: failed at lookup with error 3 - No such process.}
2022-11-10 03:21:16.334 xcodebuild[4548:14785] Font server protocol version mismatch (expected:5 got:0), falling back to local fonts
2022-11-10 03:21:16.334 xcodebuild[4548:14785] XType: unable to make a connection to the font daemon!
2022-11-10 03:21:16.334 xcodebuild[4548:14785] XType: XTFontStaticRegistry is enabled as fontd is not available.
** ARCHIVE FAILED **
The following build commands failed:
Ld /Users/expo/Library/Developer/Xcode/DerivedData/App123-djegplhkioltttdpxhkjholomhle/Build/Intermediates.noindex/ArchiveIntermediates/App123/InstallationBuildProductsLocation/Applications/App123.app/App123 normal (in target 'App123' from project 'App123')
(1 failure)
Exit status: 65
+-------------+-------------------------+
| Build environment |
+-------------+-------------------------+
| xcode_path | /Applications/Xcode.app |
| gym_version | 2.206.1 |
| sdk | iPhoneOS15.5.sdk |
+-------------+-------------------------+
Looks like fastlane ran into a build/archive error with your project
It's hard to tell what's causing the error, so we wrote some guides on how
to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
Before submitting an issue on GitHub, please follow the guide above and make
sure your project is set up correctly.
fastlane uses `xcodebuild` commands to generate your binary, you can see the
the full commands printed out in yellow in the above log.
Make sure to inspect the output above, as usually you'll find more error information there
[stderr] [!] Error building the application - see the log above
Error: Fastlane build failed with unknown error. See logs for the "Run fastlane" and "Xcode Logs" phases for more information.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when looking for an error message.
</code></pre>
<p>I've used 'eas build -p ios' command also used 'eas build -p ios --clear-cache'</p>
<p>didn't work.</p>
<p>Can anybody help please. Please please please!!!!</p>
| [
{
"answer_id": 74434185,
"author": "Farhan Mushtaq",
"author_id": 20396064,
"author_profile": "https://Stackoverflow.com/users/20396064",
"pm_score": 0,
"selected": false,
"text": "SELECT\n ( SELECT\n ( SELECT SUM(volunteerHours) \n from entries \n WHERE userId = 2 \n AND location = (\n SELECT location \n from entries \n ORDER BY id \n DESC FETCH NEXT 1 ROWS ONLY))\n / \n ( SELECT SUM(volunteerHours) \n from entries \n Where location = (\n SELECT location \n from entries \n ORDER BY id DESC \n FETCH NEXT 1 ROWS ONLY))\n ) as userContributionPercentage\n"
},
{
"answer_id": 74434835,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 2,
"selected": true,
"text": "select distinct on (e.userId) \n sum(e.volunteerHours) over (partition by userId,location,id)\n / sum(e.volunteerHours) over (partition by userId,location) \n as percentage_volunteered_here\nfrom entries e\nwhere userId=1\norder by userId, id desc;\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8460578/"
] |
74,434,048 | <p>When button clicked JS is showing <strong>[object HTMLButtonElement]</strong> instead of original value.</p>
<p>I want that whenever a button is clicked the value of button is showed.
like when button having value 3 is pressed it will show 3 and not [object HTMLButtonElement]</p>
<p>this is my html file</p>
<pre><code><div class="col-3">
<button onclick="val(this)" id="n1" value="1" type="button" class="btn btn-outline-primary "
style="width:100%" value="1">1</button>
</div>
<div class="col-3">
<button onclick="val(this)" id="n1" value="2" type="button" class="btn btn-outline-primary "
style="width:100%" value="2">2</button>
</div>
</code></pre>
<p>This is my script.js</p>
<pre><code>function val(num) {
let n = num;
document.getElementById("ta").innerHTML = n;
}
</code></pre>
<p><a href="https://i.stack.imgur.com/3B7mb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3B7mb.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74434244,
"author": "Diego D",
"author_id": 1221208,
"author_profile": "https://Stackoverflow.com/users/1221208",
"pm_score": 3,
"selected": true,
"text": "this"
},
{
"answer_id": 74434279,
"author": "Keith",
"author_id": 6870228,
"author_profile": "https://Stackoverflow.com/users/6870228",
"pm_score": 1,
"selected": false,
"text": "addEventListener"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16221393/"
] |
74,434,050 | <p>I have coins for 10, 30 and 50. But I want to use only <code>M</code> coins to get a given <code>sum</code>.</p>
<p>I have this code (from <a href="https://www.geeksforgeeks.org/coin-change-dp-7/" rel="nofollow noreferrer">this</a> as reference) that just find all possible ways to get the total sum without applying the condition of using only <code>M</code> coins.</p>
<pre><code>static long countWays(int coins[], int n, int sum)
{
// Time complexity of this function: O(n*sum)
// Space Complexity of this function: O(sum)
// table[i] will be storing the number of solutions
// for value i. We need sum+1 rows as the table is
// constructed in bottom up manner using the base
// case (sum = 0)
long[] table = new long[sum + 1];
// Initialize all table values as 0
Arrays.fill(table, 0);
// Base case (If given value is 0)
table[0] = 1;
// Pick all coins one by one and update the table[]
// values after the index greater than or equal to
// the value of the picked coin
for (int i = 0; i < n; i++)
for (int j = coins[i]; j <= sum; j++)
table[j] += table[j - coins[i]];
return table[sum];
}
// Driver Function to test above function
public static void main(String args[])
{
int coins[] = { 10, 30, 50 };
int n = coins.length;
int sum = 80;
System.out.println(countWays(coins, n, sum));
}
</code></pre>
<p>How can we add that condition for this problem or is there any alternate approach for this.</p>
<p><strong>For example:</strong></p>
<pre><code>M=4 and sum = 80
</code></pre>
<p><strong>Output</strong> <code>2.</code></p>
<p><strong>Explanation:</strong></p>
<pre><code>case 1 : 10*2 + 30*2 = 80 ( used 4 coins i.e. M coins)
case 2 : 10*3 + 50*1 = 80 ( used 4 coins i.e. M coins)
</code></pre>
<p><strong>Constraints:</strong></p>
<pre><code>M reaches up to 5000
sum reaches up to 250000
</code></pre>
| [
{
"answer_id": 74436474,
"author": "Idle_Mind",
"author_id": 2330053,
"author_profile": "https://Stackoverflow.com/users/2330053",
"pm_score": 2,
"selected": false,
"text": "0 in base 3: [0, 0, 0, 0]\n1 in base 3: [0, 0, 0, 1]\n2 in base 3: [0, 0, 0, 2]\n3 in base 3: [0, 0, 1, 0]\n4 in base 3: [0, 0, 1, 1]\n5 in base 3: [0, 0, 1, 2]\n6 in base 3: [0, 0, 2, 0]\n7 in base 3: [0, 0, 2, 1]\n8 in base 3: [0, 0, 2, 2]\n9 in base 3: [0, 1, 0, 0]\n10 in base 3: [0, 1, 0, 1]\n11 in base 3: [0, 1, 0, 2]\n12 in base 3: [0, 1, 1, 0]\n13 in base 3: [0, 1, 1, 1]\n14 in base 3: [0, 1, 1, 2]\n15 in base 3: [0, 1, 2, 0]\n16 in base 3: [0, 1, 2, 1]\n17 in base 3: [0, 1, 2, 2]\n18 in base 3: [0, 2, 0, 0]\n19 in base 3: [0, 2, 0, 1]\n20 in base 3: [0, 2, 0, 2]\n21 in base 3: [0, 2, 1, 0]\n22 in base 3: [0, 2, 1, 1]\n23 in base 3: [0, 2, 1, 2]\n24 in base 3: [0, 2, 2, 0]\n25 in base 3: [0, 2, 2, 1]\n26 in base 3: [0, 2, 2, 2]\n27 in base 3: [1, 0, 0, 0]\n28 in base 3: [1, 0, 0, 1]\n29 in base 3: [1, 0, 0, 2]\n30 in base 3: [1, 0, 1, 0]\n31 in base 3: [1, 0, 1, 1]\n32 in base 3: [1, 0, 1, 2]\n33 in base 3: [1, 0, 2, 0]\n34 in base 3: [1, 0, 2, 1]\n35 in base 3: [1, 0, 2, 2]\n36 in base 3: [1, 1, 0, 0]\n37 in base 3: [1, 1, 0, 1]\n38 in base 3: [1, 1, 0, 2]\n39 in base 3: [1, 1, 1, 0]\n40 in base 3: [1, 1, 1, 1]\n41 in base 3: [1, 1, 1, 2]\n42 in base 3: [1, 1, 2, 0]\n43 in base 3: [1, 1, 2, 1]\n44 in base 3: [1, 1, 2, 2]\n45 in base 3: [1, 2, 0, 0]\n46 in base 3: [1, 2, 0, 1]\n47 in base 3: [1, 2, 0, 2]\n48 in base 3: [1, 2, 1, 0]\n49 in base 3: [1, 2, 1, 1]\n50 in base 3: [1, 2, 1, 2]\n51 in base 3: [1, 2, 2, 0]\n52 in base 3: [1, 2, 2, 1]\n53 in base 3: [1, 2, 2, 2]\n54 in base 3: [2, 0, 0, 0]\n55 in base 3: [2, 0, 0, 1]\n56 in base 3: [2, 0, 0, 2]\n57 in base 3: [2, 0, 1, 0]\n58 in base 3: [2, 0, 1, 1]\n59 in base 3: [2, 0, 1, 2]\n60 in base 3: [2, 0, 2, 0]\n61 in base 3: [2, 0, 2, 1]\n62 in base 3: [2, 0, 2, 2]\n63 in base 3: [2, 1, 0, 0]\n64 in base 3: [2, 1, 0, 1]\n65 in base 3: [2, 1, 0, 2]\n66 in base 3: [2, 1, 1, 0]\n67 in base 3: [2, 1, 1, 1]\n68 in base 3: [2, 1, 1, 2]\n69 in base 3: [2, 1, 2, 0]\n70 in base 3: [2, 1, 2, 1]\n71 in base 3: [2, 1, 2, 2]\n72 in base 3: [2, 2, 0, 0]\n73 in base 3: [2, 2, 0, 1]\n74 in base 3: [2, 2, 0, 2]\n75 in base 3: [2, 2, 1, 0]\n76 in base 3: [2, 2, 1, 1]\n77 in base 3: [2, 2, 1, 2]\n78 in base 3: [2, 2, 2, 0]\n79 in base 3: [2, 2, 2, 1]\n80 in base 3: [2, 2, 2, 2]\n"
},
{
"answer_id": 74439966,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 1,
"selected": false,
"text": "// Pick all coins one by one and update the table[]\n// values after the index greater than or equal to\n// the value of the picked coin\n\nfor (int i = 0; i < n; i++)\n for (int j = coins[i]; j <= sum; j++)\n table[j] += table[j - coins[i]];\n"
},
{
"answer_id": 74459048,
"author": "Paul Hankin",
"author_id": 1400793,
"author_profile": "https://Stackoverflow.com/users/1400793",
"pm_score": 3,
"selected": true,
"text": " 10i + 30j + 50k = S\n i + j + k = M\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3181365/"
] |
74,434,075 | <p>The logic is similar to the content-based recommender,</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>content</th>
<th>undesirable</th>
<th>desirable</th>
<th>user_1</th>
<th>...</th>
<th>user_10</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>3.00</td>
<td>2.77</td>
<td>0.11</td>
<td></td>
<td>NA</td>
</tr>
<tr>
<td>...</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>5000</td>
<td>2.50</td>
<td>2.11</td>
<td>NA</td>
<td></td>
<td>0.12</td>
</tr>
</tbody>
</table>
</div>
<p>I need to run the model for undesirable and desirable as independent values and each user as the dependent value, thus I need run 10 times to fit the model and predict each user's NA value.</p>
<p>This is the code that I hard coding, but I wonder how to use for loop, I just searched for several methods but they do not work for me...</p>
<p>the data as 'test'</p>
<pre><code>hard code
#fit model
fit_1 = lm(user_1 ~ undesirable + desirable, data = test)
...
fit_10 = lm(user_10 ~ undesirable + desirable, data = test)
#prediction
u_1_na = test[is.na(test$user_1), c('user_1', 'undesirable', 'desirable')]
result1 = predict(fit_1, newdata = u_1_na)
which(result1 == max(result1))
max(result1)
...
u_10_na = test[is.na(test$user_10), c('user_10', 'undesirable', 'desirable')]
result10 = predict(fit_10, newdata = u_10_na)
which(result10 == max(result10))
max(result10)
#make to csv file
apply each max predict value to csv.
</code></pre>
<p>this is what I try for now(for loop)</p>
<pre><code>mod_summaries <- list()
for(i in 1:10) {
predictors_i <- colnames(data)[1:10]
mod_summaries[[i - 1]] <- summary(
lm(predictors_i ~ ., test[ , c("undesirable", 'desirable')]))
}
</code></pre>
| [
{
"answer_id": 74434256,
"author": "Nico",
"author_id": 9055967,
"author_profile": "https://Stackoverflow.com/users/9055967",
"pm_score": 0,
"selected": false,
"text": "as.formula"
},
{
"answer_id": 74434477,
"author": "M.Viking",
"author_id": 10276092,
"author_profile": "https://Stackoverflow.com/users/10276092",
"pm_score": 1,
"selected": false,
"text": "mod_summaries_lapply <-\n lapply(\n colnames(mtcars),\n FUN = function(x)\n summary(lm(reformulate(\".\", response = x), data = mtcars))\n )\n"
},
{
"answer_id": 74434534,
"author": "Limey",
"author_id": 13434871,
"author_profile": "https://Stackoverflow.com/users/13434871",
"pm_score": 0,
"selected": false,
"text": "library(tidyverse)\n\ntest %>%\n select(-content) %>%\n pivot_longer(\n starts_with(\"user\"),\n names_to=\"user\",\n values_to=\"value\"\n ) %>%\n group_by(user) %>%\n group_map(\n function(.x, .y) {\n summary(lm(user ~ ., data=.x))\n }\n )\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20179908/"
] |
74,434,111 | <p>I apologize if my question is stupid or impossible but I am a complete beginner in JavaScript.</p>
<p>I have to make a carousel on my own and <strong>change the active bullet point to the next on click on the right arrow</strong>.</p>
<pre class="lang-js prettyprint-override"><code>const bulletPoints = document.querySelectorAll('.dot')
const arrowRight = document.querySelector('.arrow_right')
arrowRight.addEventListener('click', function(event) {
event.stopPropagation()
console.log('arrow right click')
bulletPoints.forEach(function(item) {
item.classList.remove('dot_selected')
item.nextElementSibling.classList.add('dot_selected')
})
</code></pre>
<p>As you can see, for each item in my <code>bulletPoints</code> <code>NodeList</code>, I'm <strong>trying to remove the <code>dot_selected</code> class from the first item and add it to the next item</strong>, but I cannot. I tried with a for loop but also without success.</p>
<p>Thank you for your kindness.</p>
| [
{
"answer_id": 74434241,
"author": "ekans",
"author_id": 3568245,
"author_profile": "https://Stackoverflow.com/users/3568245",
"pm_score": -1,
"selected": false,
"text": "forEach"
},
{
"answer_id": 74434338,
"author": "Mr. Polywhirl",
"author_id": 1762224,
"author_profile": "https://Stackoverflow.com/users/1762224",
"pm_score": 1,
"selected": false,
"text": "const\n bulletPoints = document.querySelectorAll('.dot'),\n arrowLeft = document.querySelector('.arrow_left'),\n arrowRight = document.querySelector('.arrow_right');\n\nconst moveTo = (event, delta) => {\n event.stopPropagation();\n const\n size = bulletPoints.length,\n currIndex = [...bulletPoints].findIndex(bullet =>\n bullet.classList.contains('dot_selected')),\n nextIndex = (currIndex + delta + size) % size;\n bulletPoints[currIndex].classList.remove('dot_selected');\n bulletPoints[nextIndex].classList.add('dot_selected');\n};\n\narrowLeft.addEventListener('click', (e) => moveTo(e, -1));\narrowRight.addEventListener('click', (e) => moveTo(e, +1));"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20501970/"
] |
74,434,125 | <p>I am trying to crawl this <a href="https://www.nepsealpha.com/investment-calandar/ipo" rel="nofollow noreferrer">website</a> but I am getting empty response
I am using scrapy and I tried printing xpath but I am getting empty array I though this was straight forward task but now I am unable to get data from the table.
here is my code.</p>
<pre><code>import scrapy
from scrapy import Request
class ShareInfoSpider(scrapy.Spider):
name = 'share'
def start_requests(self):
url = "https://nepsealpha.com/investment-calandar/ipo"
yield Request(url, callback=self.parse)
def parse(self, response):
for tr in response.xpath("//table[@id='DataTables_Table_0']"):
print(tr)
</code></pre>
| [
{
"answer_id": 74434301,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": false,
"text": "requests"
},
{
"answer_id": 74435441,
"author": "Fazlul",
"author_id": 12848411,
"author_profile": "https://Stackoverflow.com/users/12848411",
"pm_score": 3,
"selected": true,
"text": "Scrapy"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20293303/"
] |
74,434,139 | <p>I'm attempting to create a new list with all the possible pairs in a list but only want to have the numbers that are neighbors be possible pairs.</p>
<p>For example, I have already created this list from a file:</p>
<p>[1, 8, 10, 16, 19, 22, 27, 33, 36, 40, 47, 52, 56, 61, 63, 71, 72, 75, 81, 81, 84, 88, 96, 98, 103, 110, 113, 118, 124, 128, 129, 134, 134, 139, 148, 157, 157, 160, 162, 164]</p>
<p>Im trying to create a list that outputs like this:</p>
<p>[(1,8), (8,10), (10,16), (16, 19), (19, 22), (22, 27), (27, 33), (33, 36), (36, 40), (40, 47), (47, 52), (52, 56), (56, 61), (61, 63), (63, 71), (71, 72), (72, 75), (75, 81), (81, 81), (81, 84), (84, 88), (88,96) .... (162, 164)]</p>
<p>I was attempting to use the import itertools but that is giving be all the possible combinations not just the number neighbors.</p>
<pre><code>import itertools
for A, B in itertools.combinations(newl, 2):
print(A, B)
</code></pre>
| [
{
"answer_id": 74434176,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 3,
"selected": true,
"text": "zip()"
},
{
"answer_id": 74434194,
"author": "KillerRebooted",
"author_id": 18554284,
"author_profile": "https://Stackoverflow.com/users/18554284",
"pm_score": 0,
"selected": false,
"text": "newl = [1, 8, 10, 16, 19, 22, 27, 33, 36, 40, 47, 52, 56, 61, 63, 71, 72, 75, 81, 81, 84, 88, 96, 98, 103, 110, 113, 118, 124, 128, 129, 134, 134, 139, 148, 157, 157, 160, 162, 164]\n\nlst = []\n\nfor i in range(len(newl)):\n try:\n lst.append((newl[i], newl[i+1]))\n except:\n pass\n"
}
] | 2022/11/14 | [
"https://Stackoverflow.com/questions/74434139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14783967/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.