qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,336,638 | <p>I am trying to display the images and its content in a web page (VueJS). I am having a problem with display them in a row with maximum number of elements for each row is 4.</p>
<pre class="lang-html prettyprint-override"><code><div className="container" style="padding-top: 1rem; width: 100%; min-height: 600px">
<div class="columns">
<div class="column">
<div class="card" style="width: 15rem; height: 15rem; margin: 20px" v-for="(image, index) in allImagesData"
:key="index">
<img class="card-img-top" :src='image.media_url' alt="Image" style="max-height: 12rem; max-width: 10rem;">
<p>{{ image.platform }}</p>
<p>{{ image.count }}</p>
</div>
</div>
</div>
</div>
</code></pre>
<p>The images shows in a vertically, I need to have it in horizontally.</p>
<p><a href="https://i.stack.imgur.com/EoNMw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EoNMw.png" alt="enter image description here" /></a></p>
<p>Can anyone help me with this to display the images in horizontally. The list will have different number of elements each time.</p>
| [
{
"answer_id": 74337607,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "https://Stackoverflow.com/users/20037042",
"pm_score": 0,
"selected": false,
"text": "max( shortest_path(node1, node2) for node1 in nodes, node2 in nodes)"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336638",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10338420/"
] |
74,336,649 | <p>I am building an application using React Native, and I want to use data from Heroku api. But when I make an API call and consolog the data I can see the data, but when I try to map them, nothing is coming out of the DOM. Can anyone tell me what I am doing wrong? Thank you so much. Here below are my can and a screenshop.</p>
<p><strong>App.jsx:</strong></p>
<pre><code>import react, { useEffect, useState } from "react";
import { FlatList, useWindowDimensions, View, Text } from "react-native";
import axios from "axios";
const App = () => {
const { height } = useWindowDimensions();
const [places, setPlaces] = useState({});
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
useEffect(() => {
axios
.post(
"https://where2playdk.herokuapp.com/nearest?lat=55.70232019168349&lon=12.561693791177802"
)
.then((response) => console.log(response.data))
.catch((error) => setIsError(error))
.finally(() => setIsLoading(false));
}, []);
return (
<View>
{places.map(({ name, distance }) => (
<View>
<Text>name</Text>
<Text>{name}</Text>
<Text>{distance}</Text>
</View>
))}
</View>
);
};
export default App;
</code></pre>
<p><a href="https://i.stack.imgur.com/cxcrE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxcrE.png" alt="data from api" /></a></p>
| [
{
"answer_id": 74337607,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "https://Stackoverflow.com/users/20037042",
"pm_score": 0,
"selected": false,
"text": "max( shortest_path(node1, node2) for node1 in nodes, node2 in nodes)"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14201102/"
] |
74,336,659 | <p>I'm creating a user registration form. I create a form in the Component. when the user registers he redirects to the user page where he sees all users. when he wanted to edit or update something from in his details he redirects to the same registration form page but this will be a new URL and new Title. I'm getting an undefined variable $title and $url error. when I pass data from the controller to view I get this error.</p>
<p>Registration Form Controller</p>
<pre><code>public function create(Request $request)
{
$url = url('/register');
$title = ("Registration Form");
$data = compact( 'url');
return view('RegistrationForm')->with($data);
}
public function store (Request $request)
{
$request->validate(
[
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email',
'password' => 'required',
'confirm_password' => 'required|same:password|min:8',
'address' => 'required',
'country' => 'required',
'state' => 'required',
'city' => 'required',
'gender' => 'required',
'tearms_and_conditions' => 'required',
],
[
'firstname.required' => 'Please enter your First Name',
'lastname.required' => 'Please nter your Last Name',
'email.required' => 'Please enter an Email',
'password.required' => 'Please Enter a Password'
],
);
$users = new Users;
$users->firstname = $request['firstname'];
$users->lastname = $request['lastname'];
$users->email = $request['email'];
$users->password = md5($request['password']);
$users->address = $request['address'];
$users->country = $request['country'];
$users->state = $request['state'];
$users->city = $request['city'];
$users->gender = $request['gender'];
$users->date_of_birth = $request['date_of_birth'];
$users->save();
return redirect('/register/view');
}
public function view (Request $request)
{
$users = Users::all();
$data = compact('users');
return view('user-view')->with($data);
}
public function delete($id)
{
$user = Users::find($id);
echo "<pre>";
print_r ($user);
die;
return redirect('/register/view');
}
public function edit($id)
{
$user = Users::find($id);
if (is_null($user))
{
return redirect('/register/view');
}
else
{
$url = url("user/update"."/". $id);
$title = "Update Details";
$data = compact('user', 'url', 'title');
return redirect('/register')->with($data);
}
}
public function update($id, Request $request)
{
$user = Users::find($id);
$users->firstname = $request['firstname'];
$users->lastname = $request['lastname'];
$users->email = $request['email'];
$users->address = $request['address'];
$users->country = $request['country'];
$users->state = $request['state'];
$users->city = $request['city'];
$users->gender = $request['gender'];
$users->date_of_birth = $request['date_of_birth'];
$users->save();
return redirect('register/view');
}
</code></pre>
<p>}</p>
<p>Route</p>
<pre><code>Route::get('/register', [RegistrationFormController::class, 'index']);
</code></pre>
<p>View</p>
<pre><code><body>
<h1> {{$title}} </h1>
<x-registration-form-component :country="$country" :url="$url" />
</code></pre>
<p>RegisreationFormComponent</p>
| [
{
"answer_id": 74336687,
"author": "Harshana",
"author_id": 6952359,
"author_profile": "https://Stackoverflow.com/users/6952359",
"pm_score": 2,
"selected": false,
"text": "$data"
},
{
"answer_id": 74341615,
"author": "RShannon",
"author_id": 6718740,
"author_profile": "https://Stackoverflow.com/users/6718740",
"pm_score": -1,
"selected": false,
"text": "{{ $data['title'] }}\n{{ $data['url'] }}\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20330580/"
] |
74,336,713 | <p>I have some HTML code that includes some css and I want the button to actually have a use like a hyperlink I press it and it takes me to a certain file or web address I have tried using actual hyperlinks inside the field but it looked ugly and I could only press on the hyperlink, I tried adding a HTML default hyperlink button but it cannot be colored.</p>
<p>Here's the code:</p>
<pre class="lang-html prettyprint-override"><code><html>
<body style="background-color:rgb(48, 45, 45)">
<font color="white">
<font color="#4CAF50">
<head>
<style>
.button {
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {background-color: #4CAF50;}
.button2 {background-color: #008CBA;}
</style>
</head>
<body>
<button class="button button1">Green</button>
<button class="button button2">Blue</button>
</body>
</code></pre>
| [
{
"answer_id": 74336826,
"author": "Emile Youssef FEGHALI EL",
"author_id": 19603779,
"author_profile": "https://Stackoverflow.com/users/19603779",
"pm_score": 3,
"selected": true,
"text": "onclick"
},
{
"answer_id": 74337454,
"author": "Conor Romano",
"author_id": 15749744,
"author_profile": "https://Stackoverflow.com/users/15749744",
"pm_score": 0,
"selected": false,
"text": "<a href=\"inner/file.html\" class=\"button\">File</a>\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17856469/"
] |
74,336,715 | <p>Here is the issue to solve. I have a table <strong>USERS</strong> and a table <strong>GROUP_USER</strong>. I am updating table <strong>USERS</strong> and the data I update in that table will directly affect the <strong>GROUP_USER</strong> table.
Here are the tables</p>
<pre><code>**Users table**
id
number_of_items
group_type //**group_type** value from GROUP_USER table
current_group //id column value from GROUP_USER table
**Group_user table**
id
group_type
item_count
//Query to update users table
"UPDATE users SET number_of_items = number_of_items - 1 WHERE item_type = :item AND number_of_items > 0"
</code></pre>
<p>What I want is...IF after subtracting (1) item from <strong>number_of_items</strong> column in <em>USERS</em> table, the remainder equals zero(0), then subtract a value of (1) from the <em>'item_count'</em> column in the <em>GROUP_USER</em> table WHERE <strong>group_type</strong> in <strong>GROUP_USER</strong> table is equal to <strong>current_group</strong> in <em>USERS</em> table. So that for every number_of_items that reaches zero, it will subtract 1 from the Group_user table based off of which group_type they are a part of.</p>
<p>a query similar to this, if even possible:</p>
<pre><code>UPDATE
users a
SET
a.number_of_items = a.number_of_items - 1
WHERE
a.item_type = :item AND a.number_of_items > 0
(
if a.number_of_items - 1 = 0
UPDATE
group_user b, users a
SET
b.item_count - 1
WHERE
b.id = a.current_group
)
</code></pre>
<p>I'll probably have to run the next query separate, but it will update all users number_of_items to 0 if current_group is 0. Sorry, its a bit complicated.</p>
<pre><code>UPDATE
users
SET
current_group = 0
WHERE
number_of_items = 0
</code></pre>
| [
{
"answer_id": 74336798,
"author": "forpas",
"author_id": 10498828,
"author_profile": "https://Stackoverflow.com/users/10498828",
"pm_score": 2,
"selected": true,
"text": "LEFT"
},
{
"answer_id": 74337259,
"author": "Ehab",
"author_id": 20342736,
"author_profile": "https://Stackoverflow.com/users/20342736",
"pm_score": 0,
"selected": false,
"text": "SET @ID = 0; \nSET @C = 0;\nUPDATE \n users a \nSET \n a.number_of_items = @C := a.number_of_items - 1,\n current_group = @ID := current_group\nWHERE \n a.item_type = :item AND a.number_of_items > 0\n;\n\nUPDATE \n group_user\nSET\n item_count - 1\nWHERE\n (@C = 0) AND (id = @ID)\n;\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12697602/"
] |
74,336,742 | <p>I'm using the following script to take a csv with minute data and perform some operations like adding new data columns with calculations.</p>
<p>As an edit to include csv data as mentioned in comments:</p>
<pre><code>2022/11/05 23:40:02,1000.13575463,0.02115
2022/11/05 23:41:01,1000.13575463,0.0147
2022/11/05 23:42:02,1000.13573563,0.01058
2022/11/05 23:43:02,1000.13573563,0.00892
2022/11/05 23:44:02,1000.13573563,0.01975
2022/11/05 23:45:02,1000.13573563,0.01291
2022/11/05 23:46:02,1000.13573563,0.00117
2022/11/05 23:47:02,1000.13573563,0.00728
2022/11/05 23:48:02,1000.13573563,0.0093
2022/11/05 23:49:02,1000.13573563,-4e-05
2022/11/05 23:50:02,1000.13567035,0.00603
2022/11/05 23:51:02,1000.13567035,0.01651
2022/11/05 23:52:02,1000.13567035,0.02454
2022/11/05 23:53:03,1000.13567035,0.02232
2022/11/05 23:54:02,1000.13567035,0.02159
2022/11/05 23:55:02,1000.13567035,0.02388
2022/11/05 23:56:01,1000.13565737,0.02777
2022/11/05 23:57:02,1000.13565737,0.01263
2022/11/05 23:58:02,1000.13565737,0.01004
2022/11/05 23:59:02,1000.13561092,0.0137
2022/11/06 00:00:03,1000.13250552,0.014
2022/11/06 00:01:02,1000.1304933,0.0196
2022/11/06 00:02:02,1000.13048128,0.02217
2022/11/06 00:03:02,1000.13045553,0.0278
2022/11/06 00:04:02,1000.13044246,0.03552
</code></pre>
<p>I'm trying to resample this dataframe to days rather than minutes so I can play about with the data in different ways, like plotting it using daily data rather than minute, and using the data to work out total days traded etc.</p>
<p>Unfortunately I get this error as soon as the first new column operation comes along : <code>TypeError: unsupported operand type(s) for /: 'SeriesGroupBy' and 'SeriesGroupBy'</code>.</p>
<p>The new columns don't accept the resampled dataframe but I'm sure I'm doing something wrong to cause this.</p>
<pre><code>import pandas as pd
import numpy as np
df = pd.read_csv(r'/home/me/mydata.csv')
df['date_time'] = pd.to_datetime(df['date_time'],format="%Y/%m/%d %H:%M:%S",infer_datetime_format=True)
pd.options.display.max_columns = None
pd.options.display.width = None
df = df.resample('D', on='date_time')
df['draw_down'] = (df.upnl / df.wallet_balance * 100).fillna(0)
df['pnl'] = df.wallet_balance.diff(1).fillna(0)
df["pnl_pct"] = df.wallet_balance.pct_change(1).fillna(0) * 100
df['cum_pnl'] = df.pnl.cumsum(skipna=True)
df['cum_pnl_pct'] = df.pnl_pct.cumsum(skipna=True)
print(df)
</code></pre>
| [
{
"answer_id": 74337107,
"author": "Pierre D",
"author_id": 758174,
"author_profile": "https://Stackoverflow.com/users/758174",
"pm_score": 1,
"selected": false,
"text": ".resample()"
},
{
"answer_id": 74338934,
"author": "rusty_research",
"author_id": 18135786,
"author_profile": "https://Stackoverflow.com/users/18135786",
"pm_score": 0,
"selected": false,
"text": "df = df.groupby(df['date_time'].dt.date).tail(1)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18135786/"
] |
74,336,822 | <p>I have a data frame like below. It has two columns <code>column1,column2</code> from these two columns I want to filter few values(combinations of two lists) and get the index. Though I wrote the logic for it. It is will be too slow for filtering from a larger data frame. Is there any faster way to filter the data and get the list of indexes?</p>
<p>Data frame:-</p>
<pre><code>import pandas as pd
d = {'col1': [11, 20,90,80,30], 'col2': [30, 40,50,60,90]}
df = pd.DataFrame(data=d)
print(df)
col1 col2
0 11 30
1 20 40
2 90 50
3 80 60
4 30 90
l1=[11,90,30]
l2=[30,50,90]
final_result=[]
for i,j in zip(l1,l2):
res=df[(df['col1']==i) & (df['col2']==j)]
final_result.append(res.index[0])
print(final_result)
[0, 2, 4]
</code></pre>
| [
{
"answer_id": 74336882,
"author": "Naveed",
"author_id": 3494754,
"author_profile": "https://Stackoverflow.com/users/3494754",
"pm_score": 1,
"selected": false,
"text": "# create a DF of the list you like to match with\ndf2=pd.DataFrame({'col1': l1, 'col2': l2})\n\n# merge the two DF\ndf3=df.merge(df2, how='left',\n on=['col1', 'col2'], indicator='foundIn')\n\n# filterout rows that are in both\nout=df3[df3['foundIn'].eq('both')].index.to_list()\nout\n"
},
{
"answer_id": 74336898,
"author": "Bushmaster",
"author_id": 15415267,
"author_profile": "https://Stackoverflow.com/users/15415267",
"pm_score": 1,
"selected": false,
"text": "condition_1=df['col1'].astype(str).str.contains('|'.join(map(str, l1)))\ncondition_2=df['col2'].astype(str).str.contains('|'.join(map(str, l2)))\nfinal_result=df.loc[ condition_1 & condition_2 ].index.to_list()\n"
},
{
"answer_id": 74336929,
"author": "ThePyGuy",
"author_id": 9136348,
"author_profile": "https://Stackoverflow.com/users/9136348",
"pm_score": 3,
"selected": true,
"text": "mask=(df[['col1', 'col2']].values[:,None]==np.vstack([l1,l2]).T).all(-1).any(1)\n# mask\n# array([ True, False, True, False, True])\n\ndf.index[mask]\n# prints\n# Int64Index([0, 2, 4], dtype='int64')\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19079397/"
] |
74,336,836 | <pre><code>New-Item -Path "HKCR:\Directory\Background\shell\customname" -Force
</code></pre>
<p>I've been doing the same thing for HKCU and KHLM but when I try HKCR I get errors in PowerShell. how am I supposed to do it for HKEY_CLASSES_ROOT?</p>
<p>I searched for a solution but couldn't find any.</p>
| [
{
"answer_id": 74337077,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Get-PSDrive"
},
{
"answer_id": 74339349,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 1,
"selected": true,
"text": "HKEY_CLASSES_ROOT"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,336,854 | <p>This is a snippet of the code I am working on</p>
<pre><code>mark =[]
totMark1 = 0
# Set the value for pre_class_activity and determine the weight of pre-class activities
pre_class_activity = 4
weight1 = pre_class_activity * 4
try:
# ask the user to enter their marks they got in the pre class activity store them in the array
print("Please enter the marks you have obtained in the " + str(pre_class_activity) + " pre-class activities in numeric values: ")
for i in range(pre_class_activity):
mark.insert(i, int(input()))
#calculate average and percent mark for pre class activities
for i in range(pre_class_activity):
totMark1 = totMark1 + mark[i]*4
avg1 = totMark1/pre_class_activity
# check average to see if there is an error in user input
if avg1 >= 401:
print(avg1)
print("i am sorry you can not have a mark higher than 100%, try again")
quit()
</code></pre>
<p>I tried if in range for different variables, as well as creating a list although I cannot figure it out</p>
| [
{
"answer_id": 74337077,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Get-PSDrive"
},
{
"answer_id": 74339349,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 1,
"selected": true,
"text": "HKEY_CLASSES_ROOT"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20432817/"
] |
74,336,855 | <p>Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'.
Sample Testcase :
INPUT
3
2 6
OUTPUT
yes</p>
<p>How to solve this problem using javascript, I can't even understand the question,So please help me to solve this....</p>
| [
{
"answer_id": 74336897,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 2,
"selected": false,
"text": "N"
},
{
"answer_id": 74337210,
"author": "T. Bill",
"author_id": 8341684,
"author_profile": "https://Stackoverflow.com/users/8341684",
"pm_score": 1,
"selected": false,
"text": "let L = 2\nlet N = 3\nlet R = 6\n\nif (N > L && N < R) {\n console.log(\"Yes\")}\nelse {\n console.log(\"No\")}\n\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19328314/"
] |
74,336,875 | <p>I have an <strong>associative array</strong> that I want to pass to cURL as POST data. However i have tried multiple things, still it doesn't work.</p>
<p>The <strong>array</strong>:</p>
<pre><code>declare -A details
details[name]="Honey"
details[class]="10"
details[section]="A"
details[subject]="maths"
</code></pre>
<p>The <strong>cURL commands</strong> have tried so far (<em>all of these failed</em>):</p>
<pre><code>resp = $(cURL --request POST --data details "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data variables=details "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data "variables=$details" "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data "variables=${details}" "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data $details "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data ${details} "https://somedomain.net/getMarks")
resp = $(cURL --request POST --data variables=details "https://somedomain.net/getMarks")
</code></pre>
<p>Something like shown below, I want the above request to be (indirectly), however I want to pass the array directly instead of writing its contents.</p>
<pre><code>resp = $(cURL --request POST --data '{"variables":[{"name": "Honey"},{"class": "10"},{"section": "A"},{"subject": "maths"}]}' "https://somedomain.net/getMarks")
</code></pre>
<p>Please note that to begin with I will always have the associative array ONLY (not any json array or string).</p>
<p>This question rose when I was trying <strong>calling cURL command with the associative array</strong> as on this <a href="https://docs.gitlab.com/ee/api/pipelines.html#create-a-new-pipeline" rel="nofollow noreferrer">link</a> (GITLAB API)(the example <em>does not contain</em> variables array example). Here they have mentioned a variables array (array of hashes).</p>
| [
{
"answer_id": 74337170,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 0,
"selected": false,
"text": "bash"
},
{
"answer_id": 74365378,
"author": "KL_KISNE_DEKHA_HAI",
"author_id": 13223056,
"author_profile": "https://Stackoverflow.com/users/13223056",
"pm_score": 2,
"selected": true,
"text": "resp=$(cURL --request POST --data '{\"variables\":[{\"name\": \"Honey\"},{\"class\": \"10\"},{\"section\": \"A\"},{\"subject\": \"maths\"}]}' \"https://somedomain.net/getMarks\")\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13223056/"
] |
74,336,910 | <p>I am building a blog app in react and I am filtering some dict values and appending in list dict. But It is appending duplicate keys with unique values in list dict. And I am know trying to merge the two same keys into one But I have tried many times but it is not working.</p>
<p>App.js</p>
<pre><code>function App(response) {
var filteredResponse = []
response.forEach(function (element) {
for (let i = 0; i < blogTypes.length; i++) {
if (element['type'] === blogTypes[i]) {
filteredResponse.push({type: blogTypes[i], data : element})
}
}
})
console.log(filteredResponse);
return null;
}
</code></pre>
<p>It is showing</p>
<pre><code>[
{
"type": "Wellness",
"blog_title": "First Blog",
},
{
"type": "Writing",
"blog_title": "Second Blog",
},
{
"type": "Wellness",
"blog_title": "Third Blog",
},
{
"type": "Health",
"blog_title": "Fourth Blog",
}
]
</code></pre>
<p><strong>And I am trying to get like</strong></p>
<pre><code>
[
{
"type": "Wellness",
"blogs": [
"First Blog",
"Third Blog"
]
},
{
"type": "Writing",
"blogs": [
"Second Blog",
]
},
{
"type": "Health",
"blogs": [
"Fourth Blog",
]
},
]
</code></pre>
<p>I have tried using :-</p>
<pre><code>const map = new Map(filteredResponse.map(({ blog_title, type }) => [blog_title, { blog_title, type: [] }]));
for (let { blog_title, type } of multipleFilteredResponse) map.get(blog_title).type.push(...[type].flat());
console.log([...map.values()]);
</code></pre>
<p>But it reterned</p>
<pre><code>[
{
"data": [
{
"type": "Wellness",
"blog_title": "First Blog",
},
{
"type": "Writing",
"blog_title": "Second Blog",
},
{
"type": "Wellness",
"blog_title": "Third Blog",
},
{
"type": "Health",
"blog_title": "Fourth Blog",
}
]
},
department : undefined
]
</code></pre>
<p>I have tried many times but it is still not working. Any help would be much Appreciated.</p>
| [
{
"answer_id": 74336957,
"author": "Axnyff",
"author_id": 4949918,
"author_profile": "https://Stackoverflow.com/users/4949918",
"pm_score": 0,
"selected": false,
"text": "const blogByTypes = {};\n\n\nresponse.forEach(response => {\n if (blogByTypes[response.type]) {\n blogByTypes[response.type].blogs.push(response.blog_title);\n } else {\n blogByTypes[response.type] = {blogs: [response.blog_title]};\n }\n});\n"
},
{
"answer_id": 74337051,
"author": "AlgRev",
"author_id": 8580852,
"author_profile": "https://Stackoverflow.com/users/8580852",
"pm_score": 1,
"selected": false,
"text": "// Online Javascript Editor for free\n// Write, Edit and Run your Javascript code using JS Online Compiler\n\nfilteredResponse = [\n {\n \"type\": \"Wellness\",\n \"blog_title\": \"First Blog\",\n },\n {\n \"type\": \"Writing\",\n \"blog_title\": \"Second Blog\",\n\n },\n {\n \"type\": \"Wellness\",\n \"blog_title\": \"Third Blog\",\n\n },\n {\n \"type\": \"Health\",\n \"blog_title\": \"Fourth Blog\",\n }\n]\n\nconst map = new Map(filteredResponse.map(({ blog_title, type }) => [type, { type, blogs: [] }]));\n\nfor (let { type, blog_title } of filteredResponse) map.get(type).blogs.push(blog_title);\n\nconsole.log([...map.values()]);"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20432567/"
] |
74,336,977 | <p><a href="https://i.stack.imgur.com/ePcbq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ePcbq.jpg" alt="Formula" /></a></p>
<pre><code>%% Popolazione di detriti
% Costanti
Mv=10000; % 10000 kg massa nominale velivolo
V_0 = 200*.3048; % velocità al distacco dalla WKT in m/s a 14325 m
N=1000
D=rand(N,1); % vettore debris di 100 numeri casuali tra 0 e 1
somma=sum(D);
m_i=(D/somma)*Mv; %mass casuale dei detriti
ver=sum(m_i); % verifica che la somma dei dei 100 pezzi razionalizzati restituisce il peso del velivolo
vx_i = randn(N,1); % componenti random di velocità nelle tre direzioni
vy_i = randn(N,1);
vz_i= randn(N,1);
DeltaV_iStar= [vx_i,vy_i,vz_i]; % matrix velocity i-esima debris
%% Momentum
DeltaQ_err=zeros(1,3);
DeltaQ=zeros(N,3); %inizializzo matrice
for k=1:N
DeltaQ(k,:)=(m_i(k)*DeltaV_iStar(k,:));
DeltaQ_err=DeltaQ_err+DeltaQ(k,:);
end
DeltaQ_err
DeltaV_err = DeltaQ_err/Mv ; % errore da togliere agli incrementi iniziali
DeltaV_c = DeltaV_iStar-DeltaV_err;
DeltaQ_err2=zeros(1,3);
DeltaQ=zeros(N,3); %inizializzo matrice
for k=1:N
DeltaQ(k,:)=(m_i(k)*DeltaV_c(k,:));
DeltaQ_err2=DeltaQ_err2+DeltaQ(k,:);
end
DeltaQ_err2
%% Kinetic Energy
V_element= randn(3,1); % componenti della velocità iniziale
B = V_element/norm(V_element)
v=V_0*B
vlength= norm(v);
prodotto=0;
Ek_d=0;
for k=1:N
prodotto(k,:)=.5*[m_i(k)*(v(k)+DeltaV_c(k,:)).^2];
Ek_d=Ek_d+prodotto(k,:);
end
Ek_d
</code></pre>
<blockquote>
<p>Unable to perform assignment because the size of the left side is
1-by-1 and the size of the right side is 1-by-3.</p>
<p>Error in Debris_Footprint (line 59)
prodotto(k,:)=.5*[m_i(k)*(v(k)+DeltaV_c(k,:)).^2];</p>
</blockquote>
<p>I tried with a for loop but the result I get is a vector. the problem is that kinetic energy <strong>is NOT</strong> <strong>a vector quantity</strong>.
In my code: m is <strong>m_i</strong> V0 = <strong>v</strong> DeltaVc = <strong>DeltaV_c</strong>.
I upload the entire code for a better understanding.
It's for a university project. The first part of the code is right according to my pofessor. I need help with the <strong>kinetic energy</strong> part</p>
| [
{
"answer_id": 74338041,
"author": "Ahmed AEK",
"author_id": 15649230,
"author_profile": "https://Stackoverflow.com/users/15649230",
"pm_score": 1,
"selected": true,
"text": "prodotto=0;\nEk_d=0;\nfor k=1:N\n for direction = 1:3\n prodotto = .5*m_i(k)*(v(direction)+DeltaV_c(k,direction)).^2;\n Ek_d=Ek_d+prodotto;\n end\nend\nEk_d\n"
},
{
"answer_id": 74339201,
"author": "mohrafik",
"author_id": 17571246,
"author_profile": "https://Stackoverflow.com/users/17571246",
"pm_score": 1,
"selected": false,
"text": "sum =0;\nfor i=1:N\n sum = (1/2)* m.*((v+vc).*(v+vc))+sum;\nend\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20425012/"
] |
74,336,996 | <pre><code>
array = []
for vid in account:
vid_shares = (df.loc[df['account'] == '123', 'shares'])
array.append(vid_shares)
print(array)
</code></pre>
<p>This produces something in the following format.</p>
<pre><code>1 10.0
2 15.0
3 0.0
4 12.0
5 17.0
6 0.0
7 9.0
8 12.0
9 13.0
10 8.0
11 30.0
12 0.0
13 16.0
Name: shares, dtype: float64]
</code></pre>
<p>How would I convert this into <code>[10, 15, 0, 12]</code> etc so that I can use the sum function to output all the values added together?</p>
<p>Thanks.</p>
| [
{
"answer_id": 74338041,
"author": "Ahmed AEK",
"author_id": 15649230,
"author_profile": "https://Stackoverflow.com/users/15649230",
"pm_score": 1,
"selected": true,
"text": "prodotto=0;\nEk_d=0;\nfor k=1:N\n for direction = 1:3\n prodotto = .5*m_i(k)*(v(direction)+DeltaV_c(k,direction)).^2;\n Ek_d=Ek_d+prodotto;\n end\nend\nEk_d\n"
},
{
"answer_id": 74339201,
"author": "mohrafik",
"author_id": 17571246,
"author_profile": "https://Stackoverflow.com/users/17571246",
"pm_score": 1,
"selected": false,
"text": "sum =0;\nfor i=1:N\n sum = (1/2)* m.*((v+vc).*(v+vc))+sum;\nend\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74336996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11774730/"
] |
74,337,013 | <p>I want to collect GitHub users' monthly contributions from 2004 until now as shown in the picture. <a href="https://i.stack.imgur.com/cS3g1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cS3g1.jpg" alt="enter image description here" /></a> And output the monthly data into csv file with corresponding month columns (e.g., 2022_10). The Xpath of these texts is:</p>
<pre><code>#//*[@id="js-contribution-activity"]/div/div/div/div/details/summary/span[1]
</code></pre>
<p>This is what my csv file (df1) looks like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>LinkedIn Website</th>
<th>GitHub Website</th>
<th>user</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td><a href="https://www.linkedin.com/in/chad-roberts-b86699/" rel="nofollow noreferrer">https://www.linkedin.com/in/chad-roberts-b86699/</a></td>
<td><a href="https://github.com/crobby" rel="nofollow noreferrer">https://github.com/crobby</a></td>
<td>crobby</td>
</tr>
<tr>
<td>1</td>
<td><a href="https://www.linkedin.com/in/grahamdumpleton/" rel="nofollow noreferrer">https://www.linkedin.com/in/grahamdumpleton/</a></td>
<td><a href="https://github.com/GrahamDumpleton" rel="nofollow noreferrer">https://github.com/GrahamDumpleton</a></td>
<td>GrahamDumpleton</td>
</tr>
</tbody>
</table>
</div>
<p>Here is my best try so far:</p>
<pre><code>for index, row in df1.iterrows():
try:
user = row['user']
except:
pass
for y in range(2004, 2023):
for m in range(1, 13):
try:
current_url = f'https://github.com/{user}?tab=overview&from={y}-{m}-01&to={y}-{m}-31'
print(current_url)
driver.get(current_url)
time.sleep(0.1)
contribution = driver.findElement(webdriver.By.xpath("//*[@id='js-contribution-activity']/div/div/div/div/details/summary/span[1]")).getText();
df1.loc[index, f'{str(y)}_{str(m)}'] = contribution
except:
pass
print(df1)
df1.to_csv('C:/Users/fredr/Desktop/output today.csv')
</code></pre>
<p>I cannot figure out why there is no output. Thanks for your help.</p>
| [
{
"answer_id": 74337899,
"author": "Jack Fleeting",
"author_id": 9448090,
"author_profile": "https://Stackoverflow.com/users/9448090",
"pm_score": 0,
"selected": false,
"text": "requests"
},
{
"answer_id": 74338270,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 2,
"selected": true,
"text": "WebDriverWait"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10295124/"
] |
74,337,033 | <p>I'm currently a bit stuck, since I'm a bit unsure of how to even formulate my problem.
What I have is a dataframe of observations with a few variables.
Lets say:</p>
<pre><code>test <- data.frame(var1=c("a","b"),var2=c(15,12))
</code></pre>
<p>Is my initial dataset.
What I want to end up with is something like:</p>
<pre><code>test2 <- data.frame(var1_p=c("a","a","a","a","a","b","b","b","b","b"),
var2=c(15,15,15,15,15,12,12,12,12,12),
var3=c(1,2,3,4,5,1,2,3,4,5)
</code></pre>
<p>However, the initial observation count and the fact, that I need the numbering to run from 0-9 makes it rather tedious to do by hand.</p>
<p>Does anybody have a nice alternative solution?</p>
<p>Thank you.</p>
<p>What I tried so far was:<br />
<strong>a)</strong></p>
<pre><code>testdata$C <- 0
testdata <- for (i in testdata$Combined_Number) {add_row(testdata,C=seq(0,9))}
</code></pre>
<p>which results in the dataset to be empty.</p>
<p><strong>b)</strong></p>
<pre><code>testdata$C <- with(testdata, ave(Combined_Number,flur, FUN = seq(0,9)))
</code></pre>
<p>which gives the following error code:</p>
<blockquote>
<p>Error in get(as.character(FUN), mode = "function", envir = envir) :<br />
object 'FUN' of mode 'function' was not found</p>
</blockquote>
| [
{
"answer_id": 74337359,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 2,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74337710,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "crossing"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12637953/"
] |
74,337,073 | <p>I am a JavaScript (and an overall programming) newbie, and this is one of my first exercices. I have to do a login page, where the user has to type in an already existing username and password, which are saved in two different arrays (one for the usernames and one for the passwords):</p>
<pre><code>const users=["java", "visual", "personal", "key", "master"]
const passwords=["script", "studio", "computer", "board", "chief"];
</code></pre>
<p>Once the user clicks a "submit" button, the website tells him if the login was successful or not (if the credentials typed in exist or not).
The problem is that when the button is clicked, nothing happens: in the code, it should check if the credentials typed in by the user match with the existing ones in the arrays AND with their positions, but it doesn't, and I don't understand why.
The code is pasted below.
JS function:</p>
<pre><code>function login(){
const a=document.getElementById("usn").value;
const b=document.getElementById("psw").value;
for(var i=0; i<users.length; i++){
for(var j=0; j<passwords.length; i++){
if(users.indexOf(a)==passwords.indexOf(b)){
if(users[i].includes(a) && passwords[j].includes(b)){
var suc=document.getElementById("success");
suc.innerHTML="Login successful";
suc.style.backgroundColor="green";
}
else{
var fail=document.getElementById("fail");
fail.innerHTML="Login failed, user not registered";
fail.style.backgroundColor="red";
}
}
else
continue;
}
}
}
</code></pre>
<p>HTML (if needed):</p>
<pre><code><div class="col-md-5 col-sm-6 col-12">
<p class="font title pt-3">Login</p>
<p class="font">Don't have an account yet? <span>Create yours now</span>, it takes just a few seconds.</p>
<div id="fail" class="pt-2 pb-2 ps-1 pe-1 font"></div>
<div id="success" class="pt-2 pb-2 ps-1 pe-1 font"></div>
<br>
<div>
<p class="font">Username</p>
<div>
<input type="text" class="inf pb-3 inf" id="usn" onclick="switchColors()">
</div>
</div>
<br>
<div>
<p class="font">Password</p>
<div>
<input type="text" class="inf pb-3 inf" id="psw" onclick="switchColors()">
<i class="bi bi-eye-slash" id="eye2" onclick="change()"></i>
<i class="bi bi-eye hidden" id="eye1" onclick="change()"></i>
</div>
</div>
<br>
<button type="button" class="btn btn-primary" id="btn" onclick="login()">Login</button>
</div>
</div>
</code></pre>
<p>CSS (if needed):</p>
<pre><code>.inf{
border: none;
outline: none;
border-bottom: 1px solid black;
}
.hidden{
display: none;
}
</code></pre>
<p>Note: this is an exercise for school to be made ONLY for learning purposes.</p>
| [
{
"answer_id": 74337359,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 2,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74337710,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "crossing"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20427773/"
] |
74,337,074 | <p>When I input a word like for example <code>hello</code> it prints this <code> 4 + 1 + 3 + 3 + 1 += 12</code></p>
<pre><code>
Console.Write("Give a word: ");
string word = Console.ReadLine();
string smallword = word.ToLower();
int sum = 0;
foreach (char letter in smallword)
{
int index = Array.IndexOf(alphabet, letter);
int score = scores[index];
sum = sum + score;
string addingEverythingTogether = $" {score} +";
Console.Write(addingEverythingTogether);
}
Console.Write($"= {sum}");
</code></pre>
<p>But it should be printing this <code>4 + 1 + 3 + 3 + 1 = 12</code>. The same line but with out the extra "+" at the end. How can I remove this last '+'?</p>
| [
{
"answer_id": 74337359,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 2,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74337710,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "crossing"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19813966/"
] |
74,337,216 | <p>I am trying to create a new df <code>new_df</code> with columns from different data frames.</p>
<p>The columns are of unequal length, which I presume can be solved by replacing empty 'cells' with NA? However, this is above my current skill level, so any help will be much appreciated!</p>
<p>Packages:</p>
<pre><code>library(tidyverse)
library(ggplot2)
library(here)
library(readxl)
library(gt)
</code></pre>
<p>I want to create <code>new_df</code> with columns from the following subsets:</p>
<pre><code>Kube_liten$Unit_cm
Kube_Stor$Unit_cm
</code></pre>
| [
{
"answer_id": 74337359,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 2,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74337710,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "crossing"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20364879/"
] |
74,337,246 | <p>I am trying to pair the first and last values together from a list, the second and the 2nd last number and so on. I can do it manually:</p>
<pre><code>list = [ slist[0], slist[-1] ]
list1 = [ slist[1], slist[-2] ]
</code></pre>
<p>but the problem for me here is that I am taking an input for the number of students and I dont know how many values the list contains and im trying to find an efficient way to sort it.</p>
<pre><code>################################### ~ Instructions ~ ###################################
# For the following code to work use the following instructions:
# 1) You will be asked to enter the number of student in your classroom
# 2) You will then be required to enter each of the students names followed
# by their behaviour Score out of 10. ( Eg: John5 ) :Name = John, Score = 5
# 3) If you have entered a wrong value, Enter: " x ", to end the list.
# Unfortunately your are going to have to start again with the names and the scores
studentCount = int(input("Enter the amount of students in your class:"))
namesList = []
for i in range (studentCount):
names = input("Enter the name of your Student followed by their score:")
names = names.upper()
namesList.append(names)
if names == 'X':
print("It appears that you hve made a mistake!\n You are going to have to start over.")
break
else:
print("List Provided:",namesList)
slist = sorted(namesList, key=lambda x:x[-1], reverse=True)
print("List Sorted",slist)
</code></pre>
| [
{
"answer_id": 74337359,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 2,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74337710,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 2,
"selected": false,
"text": "crossing"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18261323/"
] |
74,337,252 | <p>I have a button which suppose to change a boolean variable from true to false and vice versa, like a switch. the variable and the button are in different components, how is that possible to share the variable if they components are not parent-child?</p>
| [
{
"answer_id": 74339318,
"author": "Brandon Taylor",
"author_id": 598683,
"author_profile": "https://Stackoverflow.com/users/598683",
"pm_score": 1,
"selected": true,
"text": "Subject"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20244043/"
] |
74,337,261 | <p>I have been working on a Scrabble assignment. I need to read words from a list, then read each char and assign a value, eventually assigning a total score to each word. That has been done! Phew. Now I need to use the Comparator to sort the words from greatest score to least. I have done a lot of reading and I'm still confused. I know that I could use the interface, but there's also using Comparator with a lambda expression, which is the direction that I think I want to go. I'm just not sure how. I need to compare the sumValue I have for each word, then print the words in decreasing order.</p>
<p>I created 2 loops to read the word (i), then the chars (j). I have printed to the screen the score of each word (sumValue) and its location (i) in my ArrayList. Now I need to use Comparator to compare the scores, and then reorder the location. I think my problem is that I feel like I'm not sorting the Arraylist. I'm sorting the scores, which are not in an ArrayList. Do I need to create a new ArrayList with scores attached to each word and sort that?</p>
| [
{
"answer_id": 74337668,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 1,
"selected": false,
"text": "List"
},
{
"answer_id": 74345669,
"author": "Joop Eggen",
"author_id": 984823,
"author_profile": "https://Stackoverflow.com/users/984823",
"pm_score": 0,
"selected": false,
"text": "int score(String word) {\n ...\n}\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400438/"
] |
74,337,304 | <p>My app is built in SwiftUI and mostly works as is with iOS 16 apart from a couple of design quirks which I'm currently working on a fix for.</p>
<p>One of the quirks is the background colours of lists. Previously I have used Introspect to set the color of the background on the lists but as Lists have been reimplemented in iOS16 this no longer works.</p>
<p>I have solved this for iOS 16 devices by using the new scrollContentBackground modifier:</p>
<pre><code>List() {
some foreach logic here
}
.background(color)
.scrollContentBackground(.hidden)
</code></pre>
<p>This works as expected apart from one issue.</p>
<p>When the list is empty the background color is ignored, It shows a white or black background (Not even the grouped background colours) depending on the light or dark mode setting.</p>
<p>Has anybody else come across this issue (or am I doing something wrong?) and if so what solutions have you come up with?</p>
<p>Thanks,
C</p>
| [
{
"answer_id": 74337668,
"author": "WJS",
"author_id": 1552534,
"author_profile": "https://Stackoverflow.com/users/1552534",
"pm_score": 1,
"selected": false,
"text": "List"
},
{
"answer_id": 74345669,
"author": "Joop Eggen",
"author_id": 984823,
"author_profile": "https://Stackoverflow.com/users/984823",
"pm_score": 0,
"selected": false,
"text": "int score(String word) {\n ...\n}\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2277583/"
] |
74,337,308 | <p>Windows has a 256 characters limit for file paths, but users can definitely create files with path longer than 256 characters. Let's call file paths shorter than or equal 255 characters as short paths, and those longer than or equal to 256 characters as long path.</p>
<p>While working on another problem, I need to check whether a file exists given its file path, regardless of the length of the file path, regardless of normal paths or UNC paths on Windows. Is it possible with VBA?</p>
<hr />
<h2>What I have tried</h2>
<p>In VBA, there are two main ways to check file existence:</p>
<ol>
<li>Use <code>Dir()</code>.</li>
</ol>
<pre class="lang-vb prettyprint-override"><code>Dim isExists As Boolean
isExists = Dir("some\file\path") = vbNullString
</code></pre>
<ol start="2">
<li>Use <code>FileSystemObject</code> (FSO).</li>
</ol>
<pre class="lang-vb prettyprint-override"><code>Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim isExists As Boolean
isExists = objFSO.FileExists("some\file\path")
</code></pre>
<p><code>Dir()</code> is not useful here because:</p>
<ul>
<li>It does not support file paths with Unicode characters, e.g. Chinese characters. And there are Chinese characters in the file paths that I work with.</li>
<li>For long paths, it throws File Not Found error no matter the file exists or not.</li>
</ul>
<p><code>FileSystemObject</code>, on the other hand, supports file paths with Unicode characters, but I cannot get it to report file existence correctly for files with a long path.</p>
<p>Whenever a long path is given, <code>objFSO.FileExists(...)</code> returns <code>False</code> even when the file obviously exists in Windows File Explorer?!</p>
<p>For example,</p>
<pre class="lang-vb prettyprint-override"><code>' Short paths: `True` if file exists and `False` otherwise, as expected.
objFSO.FileExists("C:\some\short\path") ' Windows native path.
objFSO.FileExists("\\server\drive\some\short\path") ' UNC path.
' Long paths: `False` no matter the file exists or not, unfortunately.
objFSO.FileExists("C:\some\very\long\path\that\may\have\unicode\characters") ' Windows native path.
objFSO.FileExists("\\server\drive\some\very\long\path\that\may\have\unicode\characters") ' UNC path.
</code></pre>
<p>I have read the Microsoft VBA documentation many times, e.g. <a href="https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/fileexists-method" rel="nofollow noreferrer">FileExists method</a>, but with no luck.</p>
<p><sub>Please forgive me to insert a small rant here that nowhere in the <a href="https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dir-function" rel="nofollow noreferrer">documentation of <code>Dir()</code></a> mentions the fact that it does not support Unicode characters. Come on!</sub></p>
<hr />
<h2>What I expect</h2>
<p>Can anyone please point out what I may have missed, or answer the question whether this is solvable with VBA? If so, what can I do? It will be kind of you if you include some code examples to illustrate your answer. Thank you!</p>
| [
{
"answer_id": 74337485,
"author": "Eugene Astafiev",
"author_id": 1603351,
"author_profile": "https://Stackoverflow.com/users/1603351",
"pm_score": 2,
"selected": false,
"text": "[DllImport(\"shlwapi\", EntryPoint = \"PathFileExists\", CharSet = CharSet.Unicode)]\npublic static extern bool PathExists(string path);\n"
},
{
"answer_id": 74352295,
"author": "NCSY",
"author_id": 8699155,
"author_profile": "https://Stackoverflow.com/users/8699155",
"pm_score": 1,
"selected": true,
"text": "IsFileExists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8699155/"
] |
74,337,312 | <p><strong>data.service.ts</strong></p>
<pre><code>testData$ = new Subject<any>();
initData() {
this.getDataFromApi().subscribe((response) => {
this.testData$.next(response)
});
}
getInitData() {
return this.testData$;
}
</code></pre>
<p><strong>parent.component.ts</strong></p>
<pre><code>ngOnInit(): void {
this.dataService.initData();
}
</code></pre>
<p><strong>child.component.ts</strong></p>
<pre><code>ngOnInit(): void {
this.dataService.getInitData().subscribe((response) =>
{
console.log(response);
})
}
</code></pre>
<p>In this situtation, when I getting first time on the website console.log in child.component.ts is not executed. It is executed after I go to another component (another tab on my website) and then get back to tab in which I have parent and child component. What to do to execute console.log when I getting first time on the website?</p>
<p>I have tried what I wrote.</p>
| [
{
"answer_id": 74337485,
"author": "Eugene Astafiev",
"author_id": 1603351,
"author_profile": "https://Stackoverflow.com/users/1603351",
"pm_score": 2,
"selected": false,
"text": "[DllImport(\"shlwapi\", EntryPoint = \"PathFileExists\", CharSet = CharSet.Unicode)]\npublic static extern bool PathExists(string path);\n"
},
{
"answer_id": 74352295,
"author": "NCSY",
"author_id": 8699155,
"author_profile": "https://Stackoverflow.com/users/8699155",
"pm_score": 1,
"selected": true,
"text": "IsFileExists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433039/"
] |
74,337,354 | <pre class="lang-json prettyprint-override"><code>{
"employerId":"{{employerId}}",
"firstName":"Sarah",
"lastName": "Longfield",
"last4TIN":"7066",
"emailId": "deepakre+356441@gmail.com.com",
"cellPhone": "+912637489264",
"callbackURLs":{
"identityCallbackUrls":[
"https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7998c7f8a"
],
"notificationUrls":[
"https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7998c7f8a"
]
},
"addressLine1":"250 Vesey Street",
"addressLine2":"",
"zip":"10281",
"city":"New York",
"state":"NY",
"dateOfBirth":"09-12-1995"
}
</code></pre>
<p>I have written 3 POJO classes but i am not getting the answer specifically i am focusing on below part</p>
<p>This is what is been excepted</p>
<pre class="lang-json prettyprint-override"><code> "callbackURLs":{
"identityCallbackUrls":[
"https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7998c7f8a"
],
"notificationUrls":[
"https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7998c7f8a"
]
},
</code></pre>
<p>When i tried this is what is i achieved</p>
<pre class="lang-json prettyprint-override"><code>"callbacks": [
{
"identitycallbackURL": "https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7994c7f8a"
},
{
"notificationURL": "https://webhook.site/4d0e80d0-ece1-4208-8f76-9ac7994c7f8a"
}
],
</code></pre>
<p>I want two different array in one json object but i am getting two object in one array
Please help me in resolving the issue.</p>
| [
{
"answer_id": 74337485,
"author": "Eugene Astafiev",
"author_id": 1603351,
"author_profile": "https://Stackoverflow.com/users/1603351",
"pm_score": 2,
"selected": false,
"text": "[DllImport(\"shlwapi\", EntryPoint = \"PathFileExists\", CharSet = CharSet.Unicode)]\npublic static extern bool PathExists(string path);\n"
},
{
"answer_id": 74352295,
"author": "NCSY",
"author_id": 8699155,
"author_profile": "https://Stackoverflow.com/users/8699155",
"pm_score": 1,
"selected": true,
"text": "IsFileExists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15632627/"
] |
74,337,394 | <p>I am using a MUI Text Field component. I added a select prop so i make it a select with dropwon values and a dropdown icon . I wanted to change the dropdown Icon to a custom icon i have in figma . The problem is that when i chage it to a custom icon , i cannot click it anymore and i've tried multiple solutions like the one shown in the snippet below but it's still not clickable . This is happening for all my text field everywhere in the App . Can someone help me with this who has used MUI before and has dealt with this thing , thanks !</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import { MenuItem, TextField } from '@mui/material';
import '../../assets/utils/_groupbySelect.scss';
const MuiSelect = ({
label,
value,
disabled,
onChange,
children,
defaultValue,
withNoneOption,
className,
}: MuiSelectProps) => {
const NewIcon = (props) => (
<svg
{...props}
style={{ width: '11px', height: '11px', marginTop: '2px' }}
className="sorter-dropdown"
width="8"
height="5"
viewBox="0 0 8 5"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M1 1L4 3.5L7 1" stroke="#4C4C4D" strokeLinecap="round" />
</svg>
);
return (
<TextField
select
defaultValue={defaultValue}
label={label}
disabled={disabled}
className={className}
value={value}
onChange={onChange}
variant="standard"
SelectProps={{
IconComponent: () => <NewIcon />,
}}
InputProps={{
disableUnderline: true,
}}
fullWidth
size="small"
>
{withNoneOption ? isNoneOption : children}
</TextField>
);
};
export default MuiSelect;</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74337485,
"author": "Eugene Astafiev",
"author_id": 1603351,
"author_profile": "https://Stackoverflow.com/users/1603351",
"pm_score": 2,
"selected": false,
"text": "[DllImport(\"shlwapi\", EntryPoint = \"PathFileExists\", CharSet = CharSet.Unicode)]\npublic static extern bool PathExists(string path);\n"
},
{
"answer_id": 74352295,
"author": "NCSY",
"author_id": 8699155,
"author_profile": "https://Stackoverflow.com/users/8699155",
"pm_score": 1,
"selected": true,
"text": "IsFileExists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18174677/"
] |
74,337,398 | <p>I am trying to return an array that has 1 added to the value represented by the array given the array of any length but I get this error once I execute my code:</p>
<pre><code>UnboundLocalError: local variable 'sbang' referenced before assignment
</code></pre>
<p>My code is :</p>
<pre><code>def up_array(arr):
for i in arr:
if i < 0:
return None
if i > 9:
return None
else:
sbang = ''.join(map(str, arr))
a = "0"+str(1+(int(sbang)))
b = [int(x) for x in str(a)]
if sbang[0] == "0" and len(sbang) > 2:
return b
else:
a = 1+(int(sbang))
c = [int(x) for x in str(a)]
return c
</code></pre>
<p>Any help would highly be appreciated.</p>
<p>I am expecting digits in the array to be added by 1 while saving leading zeros and if there are digits lower than zero and higher than 9 to return None.</p>
<p>What I got was that some of the digits were calculated while for others I got error:</p>
<pre><code>local variable 'sbang' referenced before assignment
</code></pre>
| [
{
"answer_id": 74337437,
"author": "Matteo Zanoni",
"author_id": 13384774,
"author_profile": "https://Stackoverflow.com/users/13384774",
"pm_score": 1,
"selected": false,
"text": "arr"
},
{
"answer_id": 74337516,
"author": "Skip",
"author_id": 6908550,
"author_profile": "https://Stackoverflow.com/users/6908550",
"pm_score": 0,
"selected": false,
"text": "local variable 'sbang' referenced before assignment"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433159/"
] |
74,337,419 | <p>I am trying to replicate some Matlab code in R and I have been looking around for an R equivalent of Matlab's <code>sphere()</code> function.</p>
<p>For reference the <code>sphere()</code> function documentation is <a href="https://www.mathworks.com/help/matlab/ref/sphere.html" rel="nofollow noreferrer">here</a>.</p>
<p>For clarification, I am interested in the actual assignment properties of <code>sphere()</code>. Namely I am interested in knowing how to write</p>
<pre class="lang-matlab prettyprint-override"><code>[X,Y,Z]=sphere(200)
</code></pre>
<p>In R.</p>
| [
{
"answer_id": 74337651,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 2,
"selected": false,
"text": "spheresurf3D"
},
{
"answer_id": 74339879,
"author": "Ben Bolker",
"author_id": 190277,
"author_profile": "https://Stackoverflow.com/users/190277",
"pm_score": 2,
"selected": false,
"text": "library(geometry)\nsphere <- function(n) {\n dd <- expand.grid(theta = seq(0, 2*pi, length.out = n+1)[-1],\n phi = seq(-pi, pi, length.out = n+1)[-1])\n sph2cart(dd$theta, dd$phi, r = 1)\n}\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7058869/"
] |
74,337,458 | <p>I am trying to figure out how to extract a substring from a column in SQL Server. I very much would like to be able to do it directly in SQL if at all possible. The content of my column holds the responses of a web form and looks like this:</p>
<pre><code>"a:27:{s:5:\"FieldX\";s:22:\"Response to FieldX\";s:16:\"WhatProductDoYouWant\";s:31:\"SomeProduct\";s:16:\"FieldY\";s:4:\"Response to FieldY\"}
</code></pre>
<p>In the previous example the form has three fields with their respective responses as:</p>
<pre><code>FieldName Response
FieldX Response to FieldX
WhatProductDoYouWant SomeProduct
FieldY Response to FieldY
</code></pre>
<p>I need to extract the answer to <code>WhatProductDoYouWant</code>, that is, I need <code>SomeProduct</code>.</p>
<p>Constraints:</p>
<ul>
<li>I do not know how many fields there are before or after the field I am looking for, it is a dynamic form.</li>
<li>The answer to the field is dynamic, meaning I do not know how many characters I need to account for, it could be anything.</li>
</ul>
<p>For a full example, let's say I have the following table in SQL Server table:</p>
<pre><code>CREATE TABLE WebFormData
(
FormID int,
Responses varchar(MAX)
);
INSERT INTO WebFormData (FormID, Responses)
VALUES (1, 'a:27:{s:5:\"FieldX\";s:22:\"Response to FieldX\";s:16:\"WhatProductDoYouWant\";s:31:\"SomeProduct\";s:16:\"FieldY\";s:4:\"Response to FieldY\"}');
INSERT INTO WebFormData (FormID, Responses)
VALUES (2, 'a:27:{s:5:\"FieldX\";s:22:\"Response to FieldX\";a:27:{s:7:\"FieldX2\";s:27:\"Response to FieldX2\";s:16:\"WhatProductDoYouWant\";s:31:\"SomeOtherProduct\";s:16:\"FieldZ\";s:4:\"Response to FieldZ\";s:16:\"FieldY\";s:4:\"Response to FieldY\"}');
</code></pre>
<p>I would like to have a SQL query like:</p>
<pre><code>SELECT FormID, someExpression AS Products
FROM WebFormData
</code></pre>
<p>And I would expect to have as results:</p>
<pre><code>1, SomeProduct
2, SomeOtherProduct
</code></pre>
<p>I have been able to identify the index of the initial character I am looking for but I have no idea how to determine the length of the substring:</p>
<pre><code>SELECT
FormID,
SUBSTRING(Responses, CHARINDEX('WhatProductDoYouWant', Responses) + 30, 20) AS Products
FROM
WebFormData
</code></pre>
<p>(The 20 in the length parameter of the substring function is just a random number for demonstration purposes)</p>
<p>The query returns:</p>
<pre><code>FormID,Products
1, SomeProduct\";s:16:\
2, SomeOtherProduct\";s
</code></pre>
<p>Any help would be appreciated. Please let me know if clarification is required.</p>
| [
{
"answer_id": 74337568,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 3,
"selected": true,
"text": "select Substring(Responses, NullIf(p1,0) + 30, p2-(NullIf(p1,0) + 30)) Products\nfrom WebFormData\ncross apply (values(CHARINDEX('WhatProductDoYouWant', Responses)))x(p1) \ncross apply (values(CHARINDEX('\\\"', Responses, p1 + 30 )))y(p2);\n"
},
{
"answer_id": 74337767,
"author": "John Cappelletti",
"author_id": 1570000,
"author_profile": "https://Stackoverflow.com/users/1570000",
"pm_score": 1,
"selected": false,
"text": ";with cte as (\nselect FormID \n ,B.RetSeq\n ,RetVal = replace(B.RetVal,'\\\"','')\n ,grp = sum(retSeq % 2) over (partition by FormID order by RetSEQ)\n ,col = retSeq % 2\n From WebFormData A\n Cross Apply [dbo].[tvf-Str-Extract-JSON](replace(Responses,'}',';'),':',';') B\n)\nSelect FormID\n ,Seq = Grp\n ,Question = max(case when col=1 then RetVal end)\n ,Response = max(case when col=0 then RetVal end)\n From cte\n Group By FormID,Grp\n Order By FormID,Grp\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9582610/"
] |
74,337,463 | <p><strong>I have a following text-file products.txt:</strong></p>
<p>Product;Amount;Price
Apple;3;10.00
Banana;1;5.00
Lemon;2;3.00
Orange;4;20.00
Apple;4;8.00</p>
<p><strong>I want read this file and make a new text-file newfile.txt, which contains value of each row (Amount X Price):</strong></p>
<p>30.00
5.00
6.00
80.00
32.00</p>
<p>Finally, I want to find the total sum of newfile.txt (which is 30+5+6+80+32 = <strong>153</strong>)</p>
<p>Note, the price of same product can vary and we are not interested total sum of each product.</p>
<p>I started with creating class.</p>
<pre><code>class DATA:
product= ""
amount= 0
price= 0
</code></pre>
<p>def read (name):</p>
<pre><code> list = []
file= open(name, 'r', encoding="UTF-8")
file.readline()
while (True):
row= file.readline()
if(rivi == ''):
break
columns= row[:-1].split(';')
info= DATA()
info.amount= int(columns[1])
info.price= int(columns[2])
info.total = info.amount * info.price
file.append(info)
tiedosto.close()
return list
</code></pre>
| [
{
"answer_id": 74337568,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 3,
"selected": true,
"text": "select Substring(Responses, NullIf(p1,0) + 30, p2-(NullIf(p1,0) + 30)) Products\nfrom WebFormData\ncross apply (values(CHARINDEX('WhatProductDoYouWant', Responses)))x(p1) \ncross apply (values(CHARINDEX('\\\"', Responses, p1 + 30 )))y(p2);\n"
},
{
"answer_id": 74337767,
"author": "John Cappelletti",
"author_id": 1570000,
"author_profile": "https://Stackoverflow.com/users/1570000",
"pm_score": 1,
"selected": false,
"text": ";with cte as (\nselect FormID \n ,B.RetSeq\n ,RetVal = replace(B.RetVal,'\\\"','')\n ,grp = sum(retSeq % 2) over (partition by FormID order by RetSEQ)\n ,col = retSeq % 2\n From WebFormData A\n Cross Apply [dbo].[tvf-Str-Extract-JSON](replace(Responses,'}',';'),':',';') B\n)\nSelect FormID\n ,Seq = Grp\n ,Question = max(case when col=1 then RetVal end)\n ,Response = max(case when col=0 then RetVal end)\n From cte\n Group By FormID,Grp\n Order By FormID,Grp\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433130/"
] |
74,337,517 | <p>I have a "html home page" and I want the button to direct to other local files in the browser. This works fine with hyperlinks but I got code for custom buttons that I want to use but they aren't allowing me to open local files just links.
Code:</p>
<pre class="lang-html prettyprint-override"><code><html>
<body style="background-color:rgb(48, 45, 45)">
<font color="white">
<font color="#4CAF50">
<head>
<style>
b {
color: rgb(0, 0, 0);
background-color: rgb(252, 239, 0);
text-decoration: none;
padding: 10px 15px;
border-radius: 8px;
cursor: pointer;
}
</style>
</head>
<body>
</body>
</html>
<h1 style="text-align: center">Science</h1>
<b href="file:///D:\School Project\Physics.html">Physics</b>
</code></pre>
<p><a href="https://i.stack.imgur.com/iZQvb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iZQvb.png" alt="Preview of the html code" /></a></p>
| [
{
"answer_id": 74337561,
"author": "lapourgagner",
"author_id": 20019442,
"author_profile": "https://Stackoverflow.com/users/20019442",
"pm_score": 2,
"selected": false,
"text": "<a href=\"file:///D:\\School Project\\Physics.html\"><b>Physics</b></a>\n"
},
{
"answer_id": 74337595,
"author": "Emile Youssef FEGHALI EL",
"author_id": 19603779,
"author_profile": "https://Stackoverflow.com/users/19603779",
"pm_score": -1,
"selected": false,
"text": "document.href.location"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17856469/"
] |
74,337,519 | <p>I have a list of coordinates with fixed Lon and vary Lat like this:</p>
<pre><code>75.5 36.5 37.4290504456
75.5 36.4 52.4753456116
75.5 36.3 66.4775466919
75.5 36.2 84.0023193359
75.5 36.1 111.997085571
75.5 36 172.343933105
75.5 35.9 111.806427002
75.5 35.8 83.5655899048
75.5 35.7 65.6402206421
75.5 35.6 50.8337936401
75.5 35.5 33.7828178406
</code></pre>
<p>But I would like to remove all rows where lat are integer or a number with 0.5 to have something like this:</p>
<pre><code>75.5 36.4 52.4753456116
75.5 36.3 66.4775466919
75.5 36.2 84.0023193359
75.5 36.1 111.997085571
75.5 35.9 111.806427002
75.5 35.8 83.5655899048
75.5 35.7 65.6402206421
75.5 35.6 50.8337936401
</code></pre>
<p>(I removed 36.5, 36 and 35.5)</p>
<p>How can I do this using awk?</p>
| [
{
"answer_id": 74337561,
"author": "lapourgagner",
"author_id": 20019442,
"author_profile": "https://Stackoverflow.com/users/20019442",
"pm_score": 2,
"selected": false,
"text": "<a href=\"file:///D:\\School Project\\Physics.html\"><b>Physics</b></a>\n"
},
{
"answer_id": 74337595,
"author": "Emile Youssef FEGHALI EL",
"author_id": 19603779,
"author_profile": "https://Stackoverflow.com/users/19603779",
"pm_score": -1,
"selected": false,
"text": "document.href.location"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433338/"
] |
74,337,528 | <p>I'm new to JQUERY and I want to change the button text when user clicks on it from "Reservar" to "RESERVADO" and from "RESERVADO" to "Reservar" again, and so on (toggle).</p>
<p>But I can only change the button text once, and then it doesn't change anymore. Any help is appreciated</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
$("#rec").click(function() {
if ($("#rec").text() === 'RESERVADO') {
$("#rec").html("Reservar")
$("#rec").css('color', 'blue');
$("#6").appendTo($("#disponibles"));
} else if ($("#rec").text() === 'Reservar') {
$("#rec").html("RESERVADO")
$("#rec").css('color', 'red');
$("#6").appendTo($("#reservados"));
}
});
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="6" class="m-2 bg-white rounded-lg shadow-xl lg:flex lg:max-w-lg">
<img src="https://via.placeholder.com/50" class="w-1/1 lg:w-1/2 rounded-l-2xl">
<div class="p-6 bg-gray-50">
<h2 class="mb-2 text-2xl font-bold text-gray-900">Recursividad y contingencia</h2>
<p class="text-gray-600">Yuk Hui se aboca a esa tarea mediante una reconstrucción histórico-crítica del concepto de lo orgánico en filosofía, que aparece en la Crítica de la facultad de juzgar de Kant y plantea una ruptura respecto a la visión mecanicista del mundo para fundar
un nuevo umbral del pensamiento.</p>
<button id="rec" class="bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded">
Reservar
</button>
</div>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74337632,
"author": "jerem",
"author_id": 20433168,
"author_profile": "https://Stackoverflow.com/users/20433168",
"pm_score": 1,
"selected": false,
"text": "<button id=\"rec\" class=\"bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded\">Reservar</button>\n"
},
{
"answer_id": 74337719,
"author": "isherwood",
"author_id": 1264804,
"author_profile": "https://Stackoverflow.com/users/1264804",
"pm_score": 1,
"selected": true,
"text": "$(document).ready(function() {\n const btnEl = $(\"#rec\");\n const sixEl = $(\"#6\")\n\n btnEl.click(function() {\n const btnText = btnEl.text().trim(); // remove leading and trailing whitespace\n\n if (btnText === 'RESERVADO') {\n btnEl.text(\"Reservar\").css('color', 'blue');\n sixEl.appendTo($(\"#disponibles\"));\n } else if (btnText === 'Reservar') {\n btnEl.text(\"RESERVADO\").css('color', 'red');\n sixEl.appendTo($(\"#reservados\"));\n }\n });\n});"
},
{
"answer_id": 74337809,
"author": "Mister Jojo",
"author_id": 10669010,
"author_profile": "https://Stackoverflow.com/users/10669010",
"pm_score": 0,
"selected": false,
"text": "::before"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17030107/"
] |
74,337,530 | <p>model class</p>
<pre><code>public int Year { get; set; } = 0;
public int Odometer { get; set; }
public string ImageURL { get; set; } = "NA";
public string Category { get; set; } = "NA";
</code></pre>
<p>My View</p>
<pre><code><div class="form-group">
<label class="control-label AutoLText">Has Vehicle Documents</label>
@Html.DropDownListFor(Model => Model.VehDocuments, new SelectList(Model.GetYesNo()),new { @class = "form-control AutoL" })
<span asp-validation-for="VehDocuments" class="text-danger"></span>
</div>
<div class="form-group">
@Html.HiddenFor(m => m.ImageURL)
<input type="submit" value="Add New Vehicle" class="btn MVButton_2" />
</div>
</code></pre>
<p>so if i dont have the <strong>"@Html.HiddenFor(m => m.ImageURL)"</strong> in my view then the "ImageURL" will not be passed to the controller.</p>
<p>using the "<strong>HiddenFor</strong>" is kind of a security issue ? as if they change the string it will mess-up the image path to the controller and save it to the DB.</p>
<p>How can i go around this ?</p>
| [
{
"answer_id": 74337632,
"author": "jerem",
"author_id": 20433168,
"author_profile": "https://Stackoverflow.com/users/20433168",
"pm_score": 1,
"selected": false,
"text": "<button id=\"rec\" class=\"bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded\">Reservar</button>\n"
},
{
"answer_id": 74337719,
"author": "isherwood",
"author_id": 1264804,
"author_profile": "https://Stackoverflow.com/users/1264804",
"pm_score": 1,
"selected": true,
"text": "$(document).ready(function() {\n const btnEl = $(\"#rec\");\n const sixEl = $(\"#6\")\n\n btnEl.click(function() {\n const btnText = btnEl.text().trim(); // remove leading and trailing whitespace\n\n if (btnText === 'RESERVADO') {\n btnEl.text(\"Reservar\").css('color', 'blue');\n sixEl.appendTo($(\"#disponibles\"));\n } else if (btnText === 'Reservar') {\n btnEl.text(\"RESERVADO\").css('color', 'red');\n sixEl.appendTo($(\"#reservados\"));\n }\n });\n});"
},
{
"answer_id": 74337809,
"author": "Mister Jojo",
"author_id": 10669010,
"author_profile": "https://Stackoverflow.com/users/10669010",
"pm_score": 0,
"selected": false,
"text": "::before"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337530",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18172758/"
] |
74,337,531 | <p>In the model that I am working on i have a Boolean of that controls the turn ON and OFF of a system, that means during simulation my system turns ON and OFF many times, so I want to calculate the frequency of the ON/OFF, does anyone have an idea, please</p>
<p>thank you</p>
| [
{
"answer_id": 74342081,
"author": "Akhil Nandan",
"author_id": 16020568,
"author_profile": "https://Stackoverflow.com/users/16020568",
"pm_score": 2,
"selected": false,
"text": "model Boolean_Test\n Modelica.Blocks.Sources.BooleanPulse BooleanPulse(period = 20e-3, width = 20) annotation(\n Placement(visible = true, transformation(origin = {-66, 6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));\n\nReal counter(start=0); // Counter to count the number of sets and resets\nReal frequency(start=0); \nequation\nwhen Modelica.Math.BooleanVectors.oneTrue([BooleanPulse.y,pre(BooleanPulse.y)]) then\ncounter =pre(counter)+1;\nfrequency=0.5*counter/time;\nend when;\n \nannotation(\n uses(Modelica(version = \"3.2.3\")));\nend Boolean_Test;\n"
},
{
"answer_id": 74343853,
"author": "Markus A.",
"author_id": 8649763,
"author_profile": "https://Stackoverflow.com/users/8649763",
"pm_score": 1,
"selected": false,
"text": "model Boolean_Test2\n Modelica.Blocks.Sources.BooleanPulse BooleanPulse(period = 20e-3, width = 20) annotation (\n Placement(visible = true, transformation(origin = {-66, 6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));\n\n Real counter(start=0); // Counter to count the number of sets and resets\n Real frequency(start=0);\n\nequation \n when BooleanPulse.y then\n counter =pre(counter)+1;\n frequency=counter/(max(time,1e-6));\n end when;\n\nannotation(uses(Modelica(version=\"4.0.0\")));\nend Boolean_Test2;\n"
},
{
"answer_id": 74373469,
"author": "Dahmani Merzaka",
"author_id": 11214365,
"author_profile": "https://Stackoverflow.com/users/11214365",
"pm_score": 0,
"selected": false,
"text": "when ON and ON <> pre(ON) then \nF=pre(ON)+1;\nend when;\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11214365/"
] |
74,337,566 | <p>I am attempting to implement a private route in React; the homepage should not be visible until the user logs in. If I restart my frontend, all protected routes are not accessible until the user logs in. However, after the first login, all protected routes don't seem to be protected; I can logout, the session is destroyed in my database and my backend sends a response of {isLoggedIn: false}, but for some reason I can still access the protected routes.</p>
<p>When I didn't use 'useState', I could login and my backend would confirm I was logged in, but I still couldn't access any protected routes. This is the closest I've got to my end goal, but obviously still doesn't work. Any help would be appreciated.</p>
<h1>Private Routes</h1>
<pre><code>import { useState, useEffect } from 'react';
import React from 'react';
import axios from 'axios';
const checkIfLogged = async () => {
let[logged, setLogged] = useState(false);
await axios.get("http://localhost:3001/auth", {
withCredentials: true
}).then((res) => {
setLogged(res.data.isLoggedIn);
})
return logged;
}
const updateAuth = async(check) => {
const loggedIn = await check;
return loggedIn;
}
const PrivateRoutes = () =>{
const loggedIn = updateAuth(checkIfLogged);
return(
loggedIn ? <Outlet /> : <Navigate to="/login" />
)
}
export default PrivateRoutes;
</code></pre>
<h1>Auth Check</h1>
<pre><code>app.get("/auth", (req, res) => {
if(req.session.isAuth){
res.send({isLoggedIn: true})
}
else{
res.send({isLoggedIn: false})
}
})
</code></pre>
<h1>App.js</h1>
<pre><code>import{
Routes,
Route,
} from "react-router-dom";
import React from "react";
import Home from "./screens/Home";
import About from "./screens/About";
import Login from "./screens/Login";
import Register from "./screens/Register";
import Logout from "./screens/Logout";
import PrivateRoutes from "./utils/private";
const App = () => {
return (
<>
<Routes>
<Route element={<PrivateRoutes/>}>
<Route path="/" exact element={<Home />}/>
<Route path="/about" element={<About />}/>
</Route>
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />}/>
<Route path="/logout" element={<Logout />}/>
</Routes>
</>
);
}
export default App;
</code></pre>
| [
{
"answer_id": 74339369,
"author": "Ghazi",
"author_id": 16589029,
"author_profile": "https://Stackoverflow.com/users/16589029",
"pm_score": 0,
"selected": false,
"text": "checkLoggedIn"
},
{
"answer_id": 74339462,
"author": "Ghazi",
"author_id": 16589029,
"author_profile": "https://Stackoverflow.com/users/16589029",
"pm_score": 2,
"selected": true,
"text": "null"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13923905/"
] |
74,337,567 | <p>So in C I'm supposed to let the user input an integer n from the interval [5, 25]. And then, for every number from 1 to n, in a new line print that many stars so it would look something like this:</p>
<pre><code>*
**
***
</code></pre>
<p>I tried doing it like this, but it's not working. What am I doing wrong here?</p>
<pre><code>#include <stdio.h>
int main(void)
{
int n, i;
char star = '*';
do {
printf("Input an int from [5, 25]");
scanf("%d", &n);
} while (n < 5 || n >= 25);
for (i=0; i < n; i++){
star += '*';
printf("%c", star);
}
return 0;
}
</code></pre>
| [
{
"answer_id": 74337605,
"author": "0___________",
"author_id": 6110094,
"author_profile": "https://Stackoverflow.com/users/6110094",
"pm_score": 0,
"selected": false,
"text": " for (int i=0; i < n; i++)\n {\n for(int j = 0; j <= i; j++)\n printf(\"*\");\n printf(\"\\n\");\n } \n"
},
{
"answer_id": 74337627,
"author": "lapourgagner",
"author_id": 20019442,
"author_profile": "https://Stackoverflow.com/users/20019442",
"pm_score": 1,
"selected": false,
"text": "star += '*';"
},
{
"answer_id": 74337635,
"author": "Akshay kumar",
"author_id": 19162293,
"author_profile": "https://Stackoverflow.com/users/19162293",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n\nint main() {\n \n int n,i,j;\n printf(\"enter a number between 5 & 25\");\n scanf(\"%d\",&n);\n \n for(i=1;i<=n;i++){\n for(j=1;j<=i;j++){\n printf(\"*\");\n }\n printf(\"\\n\");\n }\n \n \n return 0;\n}\n"
},
{
"answer_id": 74337756,
"author": "Andreas Wenzel",
"author_id": 12149471,
"author_profile": "https://Stackoverflow.com/users/12149471",
"pm_score": 0,
"selected": false,
"text": "star += '*';\n"
},
{
"answer_id": 74337764,
"author": "Oka",
"author_id": 2505965,
"author_profile": "https://Stackoverflow.com/users/2505965",
"pm_score": 0,
"selected": false,
"text": "char"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19296411/"
] |
74,337,577 | <p>I a learning cypress and new to javascript I need your help. I want to validate, weather the items, I added to cart, are in my bag, and as I iterate through my bag, it only validates first item, instead my whole collection and it gives this assertion error:</p>
<blockquote>
<p>Expected <code><p.product-name></code> to have text 'Cauliflower - 1 Kg Cashews - 1 Kg', but the text was 'Cauliflower - 1 Kg'</p>
</blockquote>
<p>Should I use implicit assertion or explicit one</p>
<p>My code:</p>
<pre class="lang-js prettyprint-override"><code>/// <reference types="Cypress" />
describe('Example_Test_Suite_1',()=>{
it("Products are added to cart",()=>{
cy.visit("https://rahulshettyacademy.com/seleniumPractise/#/")
cy.get('.products').as('productlocator')
cy.wait(2000)
cy.get('@productlocator').find('.product').each(($el, index, $list) => {
const textVeg = $el.find('h4.product-name').text()
if (textVeg.includes('Cashews')||textVeg.includes('Cauliflower')) {
cy.wrap($el).find('button').click()
}
})
cy.get('.cart-icon').click()
// cy.get('li\[class*="cart-item"\] p\[class="product-name"\]:visible')
// .should('have.text','Cauliflower - 1 Kg')
cy.get('li\[class*="cart-item"\]').find(' p\[class="product-name"\]:visible').should('have.length',2).each(($el, index, $list) => {
cy.wrap($el).should('have.text','Cauliflower - 1 Kg','Cashews - 1 Kg') // code for bag validation
})
})
</code></pre>
<p><a href="https://i.stack.imgur.com/BgwYW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BgwYW.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74338075,
"author": "Alapan Das",
"author_id": 4571271,
"author_profile": "https://Stackoverflow.com/users/4571271",
"pm_score": 0,
"selected": false,
"text": "const vegetables = ['Cauliflower - 1 Kg', 'Cashews - 1 Kg']\n\ncy.get('li[class*=\"cart-item\"]')\n .find(' p[class=\"product-name\"]:visible')\n .should('have.length', 2)\n .each(($el, index, $list) => {\n cy.wrap($el).should('have.text', vegetables[index])\n })\n"
},
{
"answer_id": 74338791,
"author": "Fody",
"author_id": 16997707,
"author_profile": "https://Stackoverflow.com/users/16997707",
"pm_score": 1,
"selected": false,
"text": ".each()"
},
{
"answer_id": 74339772,
"author": "Thelonious",
"author_id": 20434971,
"author_profile": "https://Stackoverflow.com/users/20434971",
"pm_score": 2,
"selected": false,
"text": ".should()"
},
{
"answer_id": 74349239,
"author": "jjhelguero",
"author_id": 17917809,
"author_profile": "https://Stackoverflow.com/users/17917809",
"pm_score": 0,
"selected": false,
"text": "cy.contains()"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13180353/"
] |
74,337,588 | <p>In my project (VUE + Vuex) I need to make some API requests simultaneously, according to some <code>contents</code> and then process the results.</p>
<p>The <code>getters.api_props(key)</code> function will return the method ('post', 'patch', 'delete') or false if there is no need for a request. It will also return the url and the object that is needed for the request.</p>
<p>The <code>api</code> method returns the request as a Promise using axios.</p>
<p>Here is my code so far:</p>
<pre><code>var contents = {person: {...}, info: {...}}
var promiseArray = [];
for (var key in contents) {
let [method, url, hash] = getters.api_props(key);
if (method) { promiseArray.push(api[method](url, hash)) }
}
await Promise.allSettled(promiseArray).then((results) => {
results.map(r => {
// THE RESULTS WILL BE PROCESSED HERE like:
// commit("save", [key, r])
console.info(r)
})
}).catch(e => console.log('ERROR:::',e)).finally(commit("backup"))
</code></pre>
<p>The problem is that the results does not include the 'key' so the <code>save</code> method that is called cannot know where to save the results.</p>
<p>Can you propose a fix or a better solution?</p>
| [
{
"answer_id": 74338184,
"author": "g_ap",
"author_id": 2799563,
"author_profile": "https://Stackoverflow.com/users/2799563",
"pm_score": 0,
"selected": false,
"text": "promiseArray"
},
{
"answer_id": 74338461,
"author": "Potter",
"author_id": 2041765,
"author_profile": "https://Stackoverflow.com/users/2041765",
"pm_score": -1,
"selected": false,
"text": "import forEach from 'lodash/forEach'\nimport mapValues from 'lodash/mapValues'\nimport { api, getters } from 'somewhere'\n\nvar contents = {person: {...}, info: {...}}\n\nconst promiseContents = mapValues(contents, (value, key) => {\n let [method, url, hash] = getters.api_props(key);\n\n if (!method) { return }\n\n return api[method](url, hash)\n})\n\nawait Promise.allSettled(Object.values(promiseContents))\n\nforEach(promiseContents, (promise, key) => {\n promise.then(response => {\n if (promise.status === 'rejected') {\n console.warn(key, ':', response)\n }\n\n console.info(key, ':', value.data)\n })\n})\n"
},
{
"answer_id": 74338549,
"author": "Bergi",
"author_id": 1048572,
"author_profile": "https://Stackoverflow.com/users/1048572",
"pm_score": 1,
"selected": true,
"text": "const contents = {person: {...}, info: {...}}\ncosnt promiseArray = [];\nfor (const key in contents) {\n let [method, url, hash] = getters.api_props(key);\n if (method) {\n promiseArray.push(api[method](url, hash)).then(value => ({\n key,\n status: 'fulfilled',\n value\n }), reason => ({\n key,\n status: 'rejected',\n reason\n })))\n }\n}\n\nconst results = await Promise.all(promiseArray);\nfor (const r of results) {\n if (r.status=='fulfilled') {\n console.info(r.key, ':', r.value.data)\n commit(\"save\", [r.key, r.value]);\n } else if (r.status=='rejected') {\n console.warn(r.key, ':', r.reason)\n }\n})\ncommit(\"backup\");\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2799563/"
] |
74,337,624 | <p>i have a input tag that can search skills. when i type, the option bar will be under the profile card.</p>
<pre><code> i want to make my select option on top of the profile card. [](https://i.stack.imgur.com/3E724.png)
here is my css code for select option box:
`
.hover {
list-style-type: none;
padding: 0;
margin: 0;
height: 400px;
width:300px;
overflow: auto;
position: absolute;
display:block;
}
`
im trying to make my select option box on top of the profile card
</code></pre>
| [
{
"answer_id": 74338184,
"author": "g_ap",
"author_id": 2799563,
"author_profile": "https://Stackoverflow.com/users/2799563",
"pm_score": 0,
"selected": false,
"text": "promiseArray"
},
{
"answer_id": 74338461,
"author": "Potter",
"author_id": 2041765,
"author_profile": "https://Stackoverflow.com/users/2041765",
"pm_score": -1,
"selected": false,
"text": "import forEach from 'lodash/forEach'\nimport mapValues from 'lodash/mapValues'\nimport { api, getters } from 'somewhere'\n\nvar contents = {person: {...}, info: {...}}\n\nconst promiseContents = mapValues(contents, (value, key) => {\n let [method, url, hash] = getters.api_props(key);\n\n if (!method) { return }\n\n return api[method](url, hash)\n})\n\nawait Promise.allSettled(Object.values(promiseContents))\n\nforEach(promiseContents, (promise, key) => {\n promise.then(response => {\n if (promise.status === 'rejected') {\n console.warn(key, ':', response)\n }\n\n console.info(key, ':', value.data)\n })\n})\n"
},
{
"answer_id": 74338549,
"author": "Bergi",
"author_id": 1048572,
"author_profile": "https://Stackoverflow.com/users/1048572",
"pm_score": 1,
"selected": true,
"text": "const contents = {person: {...}, info: {...}}\ncosnt promiseArray = [];\nfor (const key in contents) {\n let [method, url, hash] = getters.api_props(key);\n if (method) {\n promiseArray.push(api[method](url, hash)).then(value => ({\n key,\n status: 'fulfilled',\n value\n }), reason => ({\n key,\n status: 'rejected',\n reason\n })))\n }\n}\n\nconst results = await Promise.all(promiseArray);\nfor (const r of results) {\n if (r.status=='fulfilled') {\n console.info(r.key, ':', r.value.data)\n commit(\"save\", [r.key, r.value]);\n } else if (r.status=='rejected') {\n console.warn(r.key, ':', r.reason)\n }\n})\ncommit(\"backup\");\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433411/"
] |
74,337,655 | <p>I am adding an environmental variable in bashrc, but am unable to see the variables using os.environ.get in a Python file.</p>
<p>I am using Raspbian on a Raspberry Pi 4.</p>
<p>I am setting an environmental variable in “bashrc” as follows:</p>
<pre><code>export DB_USER='emailAddress@gmail.com'
</code></pre>
<p>When calling the following on Terminal:</p>
<pre><code>$ env
</code></pre>
<p>…I find DB_USER in a the list of 24 items.</p>
<p>However, when I use the following in a Python file (this file is called by a bash script):</p>
<pre><code>import os
...
try:
with open("tempFile.txt", "a") as f:
f.write(str(os.environ))
f.close()
except FileNotFoundError:
print("FileNotFoundError")
except IOError:
print("IOError")
</code></pre>
<p>then ‘DB_USER’ is not in the list of 11 entries in "tempFile.txt".</p>
<p>How can I access the list of 24 items so that I can use ‘DB_USER’ entry?</p>
<p>Thanks</p>
| [
{
"answer_id": 74339661,
"author": "JL Peyret",
"author_id": 1394353,
"author_profile": "https://Stackoverflow.com/users/1394353",
"pm_score": 1,
"selected": false,
"text": "DB_USER=emailAddress@gmail.com\n"
},
{
"answer_id": 74340018,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "import os, subprocess\n\n# try to simulate being the user so you can import/capture the env as that user\ncmd = 'env -i sh -c \". /home/user/.bashrc && env\"'\n\ntry:\n with open(\"tempFile.txt\", \"a\") as f:\n for line in subprocess.getoutput(cmd).split(\"\\n\"):\n f.write(str(line))\n f.close()\nexcept FileNotFoundError:\n print(\"FileNotFoundError\")\nexcept IOError:\n print(\"IOError\")\n\n"
},
{
"answer_id": 74412957,
"author": "Ron",
"author_id": 8388721,
"author_profile": "https://Stackoverflow.com/users/8388721",
"pm_score": 0,
"selected": false,
"text": " # get environmental variables\n source /etc/environment\n \n afile='<file path and name>‘\n\n date >> $afile\n \n echo >> $afile\n echo Straight from set >> $afile\n echo $DB_USER_environment >> $afile\n echo >> $afile\n \n echo Via a variable in the script >> $afile\n db_user02=$DB_USER_environment\n echo $db_user02 >> $afile\n \n echo >> $afile\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8388721/"
] |
74,337,674 | <p>I was working on a sagemaker studio for ML work, I attached Lifecycle Configuration with it, which was creating problem. Then I deleted the lifecycle configuration without detaching it, and this problem is happening. Can't start sagemaker studio notebook and this is shown.</p>
<p><a href="https://i.stack.imgur.com/A31PD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A31PD.png" alt="enter image description here" /></a></p>
<p>Any suggestion to fix this ?</p>
| [
{
"answer_id": 74339661,
"author": "JL Peyret",
"author_id": 1394353,
"author_profile": "https://Stackoverflow.com/users/1394353",
"pm_score": 1,
"selected": false,
"text": "DB_USER=emailAddress@gmail.com\n"
},
{
"answer_id": 74340018,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "import os, subprocess\n\n# try to simulate being the user so you can import/capture the env as that user\ncmd = 'env -i sh -c \". /home/user/.bashrc && env\"'\n\ntry:\n with open(\"tempFile.txt\", \"a\") as f:\n for line in subprocess.getoutput(cmd).split(\"\\n\"):\n f.write(str(line))\n f.close()\nexcept FileNotFoundError:\n print(\"FileNotFoundError\")\nexcept IOError:\n print(\"IOError\")\n\n"
},
{
"answer_id": 74412957,
"author": "Ron",
"author_id": 8388721,
"author_profile": "https://Stackoverflow.com/users/8388721",
"pm_score": 0,
"selected": false,
"text": " # get environmental variables\n source /etc/environment\n \n afile='<file path and name>‘\n\n date >> $afile\n \n echo >> $afile\n echo Straight from set >> $afile\n echo $DB_USER_environment >> $afile\n echo >> $afile\n \n echo Via a variable in the script >> $afile\n db_user02=$DB_USER_environment\n echo $db_user02 >> $afile\n \n echo >> $afile\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/973936/"
] |
74,337,681 | <p>If I read the JLS <a href="https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.1.6" rel="nofollow noreferrer">§8.1.6</a> and <a href="https://docs.oracle.com/javase/specs/jls/se19/html/jls-9.html#jls-9.1.4" rel="nofollow noreferrer">§9.1.4</a> correctly, the classes that a sealed class/interface permits, are just the <em>direct</em> subclasses/interfaces.</p>
<p>To illustrate this, consider the following example:</p>
<pre class="lang-java prettyprint-override"><code>public sealed interface I1 permits I2, C, D { /*...*/ }
public final class C implements I1 { /*...*/ }
public final class D implements I1 { /*...*/ }
public sealed interface I2 extends I1 permits E, F { /*...*/ }
public final class E implements I2 { /*...*/ }
public final class F implements I2 { /*...*/ }
</code></pre>
<p>If I understand the specification correctly, <code>I1</code> obviously permits <code>C</code> and <code>D</code> but not <code>E</code> and <code>F</code> (via the <code>extends</code> hierarchy of <code>I2</code> from <code>I1</code>). Is this correct?</p>
<p>The reason I'm asking is what patterns are allowed for switch expressions of the following kind:</p>
<pre class="lang-java prettyprint-override"><code>I1 i1 = // ...
return switch (i1) {
case C c -> "1";
case D d -> "2";
case E e -> "3"; // Can we match over E?
case F f -> "4"; // Can we match over F?
default -> "5";
};
</code></pre>
| [
{
"answer_id": 74337835,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 1,
"selected": false,
"text": "§8.1.6"
},
{
"answer_id": 74339207,
"author": "Sweeper",
"author_id": 5133585,
"author_profile": "https://Stackoverflow.com/users/5133585",
"pm_score": 3,
"selected": true,
"text": "I1"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3955765/"
] |
74,337,686 | <p>I am trying to create a dictionary from a list recursively and my code only works when there is only one item in the list. It fails for multiple items and I suspect that this is because the dictionary is being recreated through each instance of the recursion instead of adding to it after the first instance. How can I avoid doing this so that the whole list is converted to a dictionary?</p>
<p>Note: the list is a list of tuples containing two items.</p>
<pre><code>def poncePlanner(restaurantChoices):
if len(restaurantChoices) == 0:
return {}
else:
name, resto = restaurantChoices[0][0], restaurantChoices[0][1]
try:
dic[name] = resto
poncePlanner(restaurantChoices[1:])
return dic
except:
dic = {name: resto}
poncePlanner(restaurantChoices[1:])
return dic
</code></pre>
<p>Intended input and output:</p>
<pre><code>>>> restaurantChoice = [("Paige", "Dancing Goats"), ("Fareeda", "Botiwala"),
("Ramya", "Minero"), ("Jane", "Pancake Social")]
>>> poncePlanner(restaurantChoice)
{'Jane': 'Pancake Social',
'Ramya': 'Minero',
'Fareeda': 'Botiwala',
'Paige': 'Dancing Goats'}
</code></pre>
| [
{
"answer_id": 74337885,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 0,
"selected": false,
"text": "restaurantChoices"
},
{
"answer_id": 74337944,
"author": "Mark",
"author_id": 3874623,
"author_profile": "https://Stackoverflow.com/users/3874623",
"pm_score": 1,
"selected": false,
"text": "restaurantChoice = [(\"Paige\", \"Dancing Goats\"), (\"Fareeda\", \"Botiwala\"),\n (\"Ramya\", \"Minero\"), (\"Jane\", \"Pancake Social\")]\n\ndef poncePlanner(restaurantChoice):\n if not restaurantChoice:\n return {}\n head, *rest = restaurantChoice\n return {head[0]: head[1], **poncePlanner(rest)}\n\nponcePlanner(restaurantChoice)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18021751/"
] |
74,337,720 | <p>i have a task to do (based on nothing we have learnt.. this is part of the challange, but i cannot do it nor know what i am supposed to search i have tried everything.</p>
<p>this is the task:</p>
<pre><code>/**
* Create a function that accepts two numbers,
* and calls the callback with the sum of those numbers
* @param {number} x
* @param {number} y
* @param {Function} callback
*/
function sumAsync(x, y, callback) {
}
export default sumAsync;
</code></pre>
<p>can someone point me to the right direction?
are they asking a function inside a function? if so, where can i read about it and know how to do so?</p>
| [
{
"answer_id": 74337885,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 0,
"selected": false,
"text": "restaurantChoices"
},
{
"answer_id": 74337944,
"author": "Mark",
"author_id": 3874623,
"author_profile": "https://Stackoverflow.com/users/3874623",
"pm_score": 1,
"selected": false,
"text": "restaurantChoice = [(\"Paige\", \"Dancing Goats\"), (\"Fareeda\", \"Botiwala\"),\n (\"Ramya\", \"Minero\"), (\"Jane\", \"Pancake Social\")]\n\ndef poncePlanner(restaurantChoice):\n if not restaurantChoice:\n return {}\n head, *rest = restaurantChoice\n return {head[0]: head[1], **poncePlanner(rest)}\n\nponcePlanner(restaurantChoice)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20386686/"
] |
74,337,727 | <p>I am wondering if there is a way to call an API in few secs after user has entered the values.</p>
<p>This logic is implemented in <code>Saga middleware</code> where <code>takeLatest</code> keyword is being used to take the latest value and make an api call.</p>
<pre><code>import { takeLatest} from 'redux-saga/effects';
function* watchTheRequest() {
const watcher = yield takeLatest('SOME_TYPE', callMySaga);
yield take(LOCATION_CHANGE);
yield cancel(watcher);
}
</code></pre>
<p>I am trying to implement the same in React UseEffect hook.</p>
<p><strong>Requirement is:</strong> Once users stops typing, make an API call.</p>
<pre><code>const [search, setSearch] = useState("")
useEffect(() => {
//wait for user to stop updating the search.
// call API.
}, [search])
</code></pre>
<p>Not sure if I need to use either of the following to achieve this task</p>
<pre><code>var intervalID = setInterval(alert, 1000);
setTimeout(alert, 1000);
</code></pre>
| [
{
"answer_id": 74337885,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 0,
"selected": false,
"text": "restaurantChoices"
},
{
"answer_id": 74337944,
"author": "Mark",
"author_id": 3874623,
"author_profile": "https://Stackoverflow.com/users/3874623",
"pm_score": 1,
"selected": false,
"text": "restaurantChoice = [(\"Paige\", \"Dancing Goats\"), (\"Fareeda\", \"Botiwala\"),\n (\"Ramya\", \"Minero\"), (\"Jane\", \"Pancake Social\")]\n\ndef poncePlanner(restaurantChoice):\n if not restaurantChoice:\n return {}\n head, *rest = restaurantChoice\n return {head[0]: head[1], **poncePlanner(rest)}\n\nponcePlanner(restaurantChoice)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20319015/"
] |
74,337,792 | <p>I use two libraries in my project; let's say A and B for the sake of this question. Unfortunately, I ended up in the following situation:</p>
<p>In A.h:</p>
<pre><code>#define ssize_t long
</code></pre>
<p>In B.h:</p>
<pre><code>typedef long long ssize_t;
</code></pre>
<p>This leads to the following error, if A.h is included (i.e., processed) prior to B.h:</p>
<blockquote>
<p>E0084 invalid combination of type specifiers<br />
C2632 '__int64' followed by 'long' is illegal</p>
</blockquote>
<p>My Question: What is the recommended way to deal with this situation?</p>
<p>I could make sure B.h is included prior to A.h instead. I could also <code>#undef ssize_t</code> before including B.h. Neither of which is perfect as it would become my responsibility to ensure the ordering of these includes or uglyfy my code respectively.</p>
<p>Update: It's not my code. The first (A.h) seems to be generated from <a href="https://github.com/InsightSoftwareConsortium/DCMTK/blob/master/CMake/osconfig.h.in" rel="nofollow noreferrer">this</a>, the other (B.h) stems from <a href="https://github.com/rwinlib/hdf5/blob/master/include/H5public.h" rel="nofollow noreferrer">here</a>.</p>
| [
{
"answer_id": 74337885,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 0,
"selected": false,
"text": "restaurantChoices"
},
{
"answer_id": 74337944,
"author": "Mark",
"author_id": 3874623,
"author_profile": "https://Stackoverflow.com/users/3874623",
"pm_score": 1,
"selected": false,
"text": "restaurantChoice = [(\"Paige\", \"Dancing Goats\"), (\"Fareeda\", \"Botiwala\"),\n (\"Ramya\", \"Minero\"), (\"Jane\", \"Pancake Social\")]\n\ndef poncePlanner(restaurantChoice):\n if not restaurantChoice:\n return {}\n head, *rest = restaurantChoice\n return {head[0]: head[1], **poncePlanner(rest)}\n\nponcePlanner(restaurantChoice)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8735401/"
] |
74,337,800 | <p>This is a python file that's supposed to act like a phone book the file is called exam.txt its supposed to create, save, append, search and delete contacts but the delete part deletes all the strings instead of specific strings (the rest of the code is ok when executed the deleting part is the last part of the code)</p>
<pre><code>#inputing contacts
filename ="exam.txt"
n = int(input("enter the number of contacts you would like to save\n"))
file = open(filename, "a")
for i in range(n):
cont = (input("enter name and phone number respectively:\n"))
file.write(cont + "\n")
file.close
#searching for contacts
word = input("insert the name you would like to search for\n")
with open("exam.txt", "r") as file:
for line_number, line in enumerate(file, start=1):
if word in line:
print(f"Word '{word}' found on line {line_number}")
break
print("Search completed.")
#deleting contacts
# deleting a string/contact
try:
with open('exam.txt', 'r') as fr:
lines = fr.readlines()
with open('exam.txt', 'w') as fw:
for line in lines:
# strip() is used to remove '\n'
# present at the end of each line
if line.strip('\n') != input("input the contact you would like to delete:"):
fw.write(line)
break
print("Deleted")
except:
print("Oops! something error")
</code></pre>
| [
{
"answer_id": 74337885,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 0,
"selected": false,
"text": "restaurantChoices"
},
{
"answer_id": 74337944,
"author": "Mark",
"author_id": 3874623,
"author_profile": "https://Stackoverflow.com/users/3874623",
"pm_score": 1,
"selected": false,
"text": "restaurantChoice = [(\"Paige\", \"Dancing Goats\"), (\"Fareeda\", \"Botiwala\"),\n (\"Ramya\", \"Minero\"), (\"Jane\", \"Pancake Social\")]\n\ndef poncePlanner(restaurantChoice):\n if not restaurantChoice:\n return {}\n head, *rest = restaurantChoice\n return {head[0]: head[1], **poncePlanner(rest)}\n\nponcePlanner(restaurantChoice)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20417349/"
] |
74,337,804 | <p>I am reading content of a file and and trying to print it, but it is giving extra garbage value.</p>
<pre><code>#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
int main() {
long length;
char* content;
FILE *file = fopen("text.txt", "r");
fseek(file, 0, SEEK_END);
length = ftell(file);
fseek(file, 0, SEEK_SET);
content = (char *)malloc(length);
fread(content, 1, length, file);
printf("%s\n", content);
return 0;
}
</code></pre>
<p><a href="https://i.stack.imgur.com/B2Z2g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B2Z2g.png" alt="image" /></a></p>
<p>Maybe I have to null terminate <code>content[length] = '\0';</code>?</p>
<p>The more <code>\n</code> newline characters the file has at the end, the more garbage I get.</p>
<p>Any solution, except using <code>calloc</code>?</p>
| [
{
"answer_id": 74337823,
"author": "273K",
"author_id": 6752050,
"author_profile": "https://Stackoverflow.com/users/6752050",
"pm_score": 1,
"selected": false,
"text": "content = (char *)malloc(length + 1);\nmemset(content, 0, length + 1);\nfread(content, 1, length, file);\n"
},
{
"answer_id": 74337932,
"author": "Weather Vane",
"author_id": 4142924,
"author_profile": "https://Stackoverflow.com/users/4142924",
"pm_score": 3,
"selected": true,
"text": "#define _CRT_SECURE_NO_DEPRECATE"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20239215/"
] |
74,337,814 | <p>I want to put my Lists items in <strong>ExpansionTile</strong>, the title is set perfectly but children's items not set inside list. I want to add children items inside <strong>ExpansionTile</strong> children</p>
<p>My dataList:</p>
<pre><code>List dataList = [
{
"title": "Payments",
"icon": Icons.payment,
"children": [
{"title": "Paypal"},
{"title": "Credit Card"},
{"title": "Debit Card"}
]
},
{
"title": "Favorite",
"icon": Icons.favorite,
"children": [
{"title": "Swimming"},
{"title": "Football"},
{"title": "Movie"},
{"title": "Singing"},
{"title": "Jogging"},
]
},
];
</code></pre>
<p>var declarion:</p>
<pre><code>int? selected;
</code></pre>
<p>My Widget:</p>
<pre><code> ListView.builder(
key: Key('builder ${selected.toString()}'),
padding: const EdgeInsets.only(left: 13.0, right: 13.0, bottom: 25.0),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: dataList.length,
itemBuilder: (context, index) {
return ExpansionTile(
key: Key(index.toString()),
initiallyExpanded: index == selected,
trailing: const SizedBox(),
leading: Icon(
dataList[index]['icon'],
color: index == selected ? Colors.black : Colors.grey,
),
title: Text(dataList[index]['title'],
style: TextStyle(
color: index == selected ? Colors.black : Colors.grey,
fontSize: 17.0,
fontWeight: FontWeight.bold)),
onExpansionChanged: ((newState) {
if (newState) {
setState(() {
selected = index;
});
} else {
setState(() {
selected = -1;
});
}
}),
children: [
Padding(
padding: const EdgeInsets.all(25.0),
child: Text(
dataList[index]['children'][index]['title'],
style: TextStyle(
color: index == selected ? Colors.red : Colors.grey,
),
),
),
],
);
},
)
</code></pre>
<p>Current Result-</p>
<p><a href="https://i.stack.imgur.com/Ubum4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ubum4.png" alt="image" /></a></p>
<p><a href="https://i.stack.imgur.com/I5iZI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I5iZI.png" alt="image" /></a></p>
| [
{
"answer_id": 74337973,
"author": "OMi Shah",
"author_id": 5882307,
"author_profile": "https://Stackoverflow.com/users/5882307",
"pm_score": 2,
"selected": true,
"text": "index"
},
{
"answer_id": 74345431,
"author": "eamirho3ein",
"author_id": 10306997,
"author_profile": "https://Stackoverflow.com/users/10306997",
"pm_score": 2,
"selected": false,
"text": "int childSelected = -1;\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13997210/"
] |
74,337,876 | <p>I have created a deployment yaml file with an image name with my private docker repository.
when running the command :</p>
<pre><code> kubectl get pods
</code></pre>
<p>I see that the status of the created pod from that deployment file is ImagePullBackOff. from what I have read it is because I am pulling the image from a private registry without imagePullSecret.</p>
<p>how do I create "imagePullSecret" as a yaml file to work with the deployment.yaml file which contains an image from the private repository? or is it a feild which should be part of the deployment file?</p>
| [
{
"answer_id": 74341670,
"author": "Rakesh Gupta",
"author_id": 2777988,
"author_profile": "https://Stackoverflow.com/users/2777988",
"pm_score": 0,
"selected": false,
"text": "kubectl create secret generic regcred \\\n --from-file=.dockerconfigjson=<path/to/.docker/config.json> \\\n --type=kubernetes.io/dockerconfigjson\n"
},
{
"answer_id": 74341699,
"author": "YwH",
"author_id": 3781502,
"author_profile": "https://Stackoverflow.com/users/3781502",
"pm_score": 2,
"selected": true,
"text": "imagePullSecrets"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1906070/"
] |
74,337,881 | <p>I need to get the text from first <code><td></code> element of each <code><tr></code>. But not all the text, only the one inside tags <code><a></code> and outside of any other tag. I wrote examples of necessary text as "yyy"/"y" and examples of not necessary as "zzz"</p>
<pre class="lang-html prettyprint-override"><code><table>
<tbody>
<tr>
<td>
<b>zzz</b>
<a href="#">yyy</a>
"y"
<a href="#">yyy</a>
<sup>zzz</sup>
<a href="#">yyy</a>
<a href="#">yyy</a>
"y"
</td>
<td>
zzzzz
</td>
</tr>
</tbody>
</table>
</code></pre>
<p>Here what I have at the moment</p>
<pre class="lang-py prettyprint-override"><code>words = []
for tableRows in soup.select("table > tbody > tr"):
tableData = tableRows.find("td").text
text = [word.strip() for word in tableData.split(' ')]
words.append(text)
print(words)
</code></pre>
<p>But this code is parsing all the text from <code><td></code>: <code>["zzz", "yyyy", "yyyy", "zzz", "yyyy"]</code>.</p>
| [
{
"answer_id": 74341670,
"author": "Rakesh Gupta",
"author_id": 2777988,
"author_profile": "https://Stackoverflow.com/users/2777988",
"pm_score": 0,
"selected": false,
"text": "kubectl create secret generic regcred \\\n --from-file=.dockerconfigjson=<path/to/.docker/config.json> \\\n --type=kubernetes.io/dockerconfigjson\n"
},
{
"answer_id": 74341699,
"author": "YwH",
"author_id": 3781502,
"author_profile": "https://Stackoverflow.com/users/3781502",
"pm_score": 2,
"selected": true,
"text": "imagePullSecrets"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20431669/"
] |
74,337,909 | <p>I need to write a function that allows me to convert timeseries data (wind speed as the argument) to power output for a turbine. The output is based on several intervals.</p>
<p>So i have tried to create an additional dataframe to store the conversion coefficients.</p>
<p>The Problem is, that I get always the error 'float' object is not subscriptable. I know that it must has something to do with that Floating-point numbers are not subscriptable or cannot be accessed at an index but I can't figure out how to change the argument.</p>
<pre><code>import pandas as pd
time = pd.date_range(start='2019-01-06 20:00:00', end='2019-01-07 03:00:00', freq='H')
df_ws = pd.DataFrame({"wind_speed_hh":
[3.359367, 2.695838, 3.036351, 6.64743,
9.93, 13.13, 15.574893, 17.3432]}, index = time)
df_ws['power_production_Vestas'] = 0.0
</code></pre>
<p>weight_vestas are the conversion coefficients</p>
<pre><code>weight_vestas = pd.DataFrame(
{"wv1": [0.0],
"wv2": [0.2],
"wv3": [0.5],
"wv4": [1.4],
"wv5": [2.6],
"wv6": [3.0],
"wv7": [3.0],
"wv8": [3.0]})
weight_vestas.head()
</code></pre>
<p>The functions is:</p>
<pre><code>def conv_test(x):
if 4 <= x['wind_speed_hh']:
return (weight_vestas['wv1'] * x['wind_speed_hh'])
elif 4 < x['df_ws.wind_speed_hh'] < 6:
return (weight_vestas['wv2'] * x['df_ws.wind_speed_hh'])
elif 6 <= x['df_ws.wind_speed_hh'] < 8:
return (weight_vestas['wv3'] * x['df_ws.wind_speed_hh'])
elif 8 <= x['df_ws.wind_speed_hh'] < 10:
return (weight_vestas['wv4'] * x['df_ws.wind_speed_hh'])
elif 10 <= x['df_ws.wind_speed_hh'] < 12:
return (weight_vestas['wv5'] * x['df_ws.wind_speed_hh'])
elif 12 <= x['df_ws.wind_speed_hh'] < 14:
return (weight_vestas['wv6'] * x['df_ws.wind_speed_hh'])
elif 14 <= x['df_ws.wind_speed_hh'] < 16:
return (weight_vestas['wv7'] * x['df_ws.wind_speed_hh'])
elif 16 <= x['df_ws.wind_speed_hh']:
return (weight_vestas['wv8'] * x['df_ws.wind_speed_hh'])
return ''
</code></pre>
<p>Running the function and adding the production output:</p>
<pre><code>df_ws = df_ws.power_production_Vestas.apply(conv_test)
df_test.head()
</code></pre>
| [
{
"answer_id": 74341670,
"author": "Rakesh Gupta",
"author_id": 2777988,
"author_profile": "https://Stackoverflow.com/users/2777988",
"pm_score": 0,
"selected": false,
"text": "kubectl create secret generic regcred \\\n --from-file=.dockerconfigjson=<path/to/.docker/config.json> \\\n --type=kubernetes.io/dockerconfigjson\n"
},
{
"answer_id": 74341699,
"author": "YwH",
"author_id": 3781502,
"author_profile": "https://Stackoverflow.com/users/3781502",
"pm_score": 2,
"selected": true,
"text": "imagePullSecrets"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433452/"
] |
74,337,911 | <p>I would like to use a single mount point on a node (ie <code>/data</code>) and have a different sub folder for each <code>PersistentVolumeClaim</code> that I am going to use in my cluster.</p>
<p>At the moment I have multiple <code>StorageClass</code> and <code>PersistentVolume</code> for each sub folder, for example:</p>
<pre class="lang-yaml prettyprint-override"><code>---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: prometheus
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus
labels:
type: local
spec:
storageClassName: prometheus
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
local:
path: "/data/prometheus"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: disk
operator: In
values:
- local
</code></pre>
<p>As you can image having a <code>StorageClass</code>, a <code>PersistentVolume</code> for each <code>PersistentVolumeClaim</code> looks a bit of an overkill.</p>
<p>I have tried to use a single <code>StorageClass</code> and <code>PersistentVolume</code> (just pointing to <code>/data</code>), the <code>usePath</code> option (ie <code>prometheus</code>) with multiple <code>PersistentVolumeClaim</code>.
But I have noticed that if the <code>securityContext.fsGroupChangePolicy</code> option is enabled it will apply the user/group changes to root of the volume (ie <code>/data</code>) not to the <code>subPath</code> (ie <code>/data/prometheus</code>).</p>
<p>Is there a better solution?</p>
<p>Thanks</p>
| [
{
"answer_id": 74341670,
"author": "Rakesh Gupta",
"author_id": 2777988,
"author_profile": "https://Stackoverflow.com/users/2777988",
"pm_score": 0,
"selected": false,
"text": "kubectl create secret generic regcred \\\n --from-file=.dockerconfigjson=<path/to/.docker/config.json> \\\n --type=kubernetes.io/dockerconfigjson\n"
},
{
"answer_id": 74341699,
"author": "YwH",
"author_id": 3781502,
"author_profile": "https://Stackoverflow.com/users/3781502",
"pm_score": 2,
"selected": true,
"text": "imagePullSecrets"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4465440/"
] |
74,337,915 | <p>As the title mentioned, I have to remove adjacent duplicates in linked list such that if input is 'google', output should be 'le'. I'm supposed to code it in C. I've written 70% of the code, except that I don't know how to continuously loop till all adjacent duplicates are removed. I'm removing adjacent duplicates in remove_adjacent_duplicates() function, and since I don't know how to put terminating condition in loop, I've merely used if-else loop. But my code in remove_adjacent_duplicates() function might contain mistakes, so please rectify it if any and please give solution to looping till all adjacent duplicates are removed. Here's my code-</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node //node creation
{
char data;
struct node *next;
};
void remove_adjacent_duplicates(struct node** head_ref)
{
struct node* current = *head_ref;
struct node* cnext = NULL; //the one next to current one
int flag=0;
cnext = current->next; //storing next
//printf("%c %c %d\n",current->data,cnext->data,flag);
if(cnext->data==current->data)
{
flag=1;
while(cnext->data==current->data)
{
cnext=cnext->next;
}
current=cnext;
cnext = current->next; //storing next
}
else
{
current=current->next;
cnext = current->next; //storing next
}
//printf("%c %c %d\n",current->data,cnext->data,flag);
if(flag) *head_ref = current;
}
void push(struct node** head_ref, char new_data)
{
struct node* new_node = (struct node*)malloc(sizeof(struct node));
new_node->data = new_data;
new_node->next = *head_ref;
*head_ref = new_node;
}
void printList(struct node* head)
{
if (head == NULL)
{
printf("NULL\n\n");
return;
}
printf("%c->",head->data);
printList(head->next);
}
int main()
{
char s[100];
int i;
struct node* a = NULL;
printf("Enter string: ");
scanf("%s",s);
for(i=strlen(s)-1;i>-1;i--){
push(&a, s[i]); //last in first out, so in reverse g is last but first to come out
}
printf("\nConverting string to linked list: \n");
printList(a);
//printf("%c",current->data); prints first letter of a
remove_adjacent_duplicates(&a);
printList(a);
return 0;
}
</code></pre>
| [
{
"answer_id": 74338138,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 3,
"selected": true,
"text": "void remove_adjacent_duplicates(struct node** head_ref)\n{\n struct node* current = *head_ref;\n if (current == NULL || current->next == NULL) return;\n int isEqual = current->data == current->next->data; \n remove_adjacent_duplicates(¤t->next);\n if (current->next != NULL && current->data == current->next->data) {\n // Duplicates! Remove pair\n *head_ref = current->next->next;\n free(current->next);\n free(current);\n } else if (isEqual) {\n // Continue ongoing removal\n *head_ref = current->next;\n free(current);\n }\n}\n"
},
{
"answer_id": 74338165,
"author": "Craig Estey",
"author_id": 5382650,
"author_profile": "https://Stackoverflow.com/users/5382650",
"pm_score": 1,
"selected": false,
"text": "free"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19611563/"
] |
74,337,916 | <p>I am creating a game in visual studio using c sharp and want to add a pop up message saying 'game Over' once the timer reaches 0. Currently the countdown timer goes to negative seconds and the game keeps going. Currently attempt is below and any help is apricated.</p>
<pre><code>public MainPage()
{
InitializeComponent();
_random = new Random(); // r is my random number generator
_countDown = 30;
SetUpMyTimers();// method for my timer
endGame();
}
private void endGame()
{
throw new NotImplementedException();
}
private void SetUpMyTimers() // calling my method
{
// start a timer to run a method every 1000ms
// that method is "TimerFunctions" that runs on the UI thread
Device.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
{
Device.BeginInvokeOnMainThread(() =>
{ TimerFunctions(); });
return true;
});
}
private void TimerFunctions()
{
// change the countdown.
_countDown--;
LblCountdown.Text = _countDown.ToString();
}
</code></pre>
| [
{
"answer_id": 74342399,
"author": "Lynn-MSFT",
"author_id": 20376806,
"author_profile": "https://Stackoverflow.com/users/20376806",
"pm_score": 1,
"selected": false,
"text": "public partial class Form1 : Form\n{\n TimeSpan Span = new TimeSpan(0, 0, 10);\n public Form1()\n {\n InitializeComponent();\n \n }\n\n private void timer1_Tick(object sender, EventArgs e)\n {\n Span = Span.Subtract(new TimeSpan(0, 0, 1));\n label1.Text = Span.Hours.ToString() + \":\" + Span.Minutes.ToString() + \":\" + Span.Seconds.ToString();//时间格式0:0:10\n if (Span.TotalSeconds < 0.0)//when the countdown is over\n {\n timer1.Enabled = false;\n MessageBox.Show(\"game over\");\n }\n\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n timer1.Interval = 1000;//Set every interval to 1 second\n timer1.Enabled = true;\n MessageBox.Show(\"End the game after 10s\");\n\n }\n}\n"
},
{
"answer_id": 74530731,
"author": "Hui Liu-MSFT",
"author_id": 15181473,
"author_profile": "https://Stackoverflow.com/users/15181473",
"pm_score": 0,
"selected": false,
"text": "<Grid>\n <TextBlock Name=\"tbTime\" />\n </Grid>\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433628/"
] |
74,337,926 | <p>In the context of Functional Programming, I want to have the capabilities of Option or Maybe from Scala, Haskell in TypeScript.</p>
<p>I can simply define <code>Option</code> below with TS compiler option <strong>strictNullChecks</strong> turned on:</p>
<pre><code>type Option<A> = A | null
</code></pre>
<p>While in Haskell, PureScript, ... it is defined like</p>
<pre><code>type Option<A> = Some<A> | None
type Maybe<A> = Just<A> | Nothing
</code></pre>
<p>In order to benefit from the concept, Do I have to wrap my value in Some or Just and define a separate Symbol for null, or is what I typed above is enough?</p>
| [
{
"answer_id": 74338414,
"author": "Guillaume Brunerie",
"author_id": 521624,
"author_profile": "https://Stackoverflow.com/users/521624",
"pm_score": 3,
"selected": true,
"text": "type Option<T> = {value: T} | null;\n"
},
{
"answer_id": 74344156,
"author": "Shnd",
"author_id": 1341340,
"author_profile": "https://Stackoverflow.com/users/1341340",
"pm_score": 0,
"selected": false,
"text": "null"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1341340/"
] |
74,337,955 | <p><a href="https://i.stack.imgur.com/jNmxA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jNmxA.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/AkbCG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AkbCG.png" alt="enter image description here" /></a></p>
<p>I have a table with 3 columns <code>id</code>, <code>homeph</code>, <code>mobileph</code>.</p>
<p>If <code>homeph</code> is equal to <code>mobileph</code>, then <code>homeph</code> or <code>mobileph</code> with other line what is query for this?</p>
| [
{
"answer_id": 74337999,
"author": "Sebastian S.",
"author_id": 5607537,
"author_profile": "https://Stackoverflow.com/users/5607537",
"pm_score": 2,
"selected": false,
"text": "SELECT ID AS id, Homeph AS phone\nFROM table\n\nUNION\n\nSELECT ID AS id, Contactph AS phone\nFROM table\n"
},
{
"answer_id": 74339641,
"author": "MT0",
"author_id": 1509264,
"author_profile": "https://Stackoverflow.com/users/1509264",
"pm_score": 1,
"selected": true,
"text": "SELECT DISTINCT id, phone\nFROM input_table\nUNPIVOT (\n phone FOR type IN (homeph, contactph) \n)\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433631/"
] |
74,337,983 | <p>In SQL Server we can create new column by adding some value like below</p>
<pre><code>select *, new_column = fixed_value
from table
</code></pre>
<p>I want to replicate this in Databricks SQL, but in Databricks I'm getting an error "new_column is not present".</p>
<p>How to do this in Databricks for temp table?</p>
| [
{
"answer_id": 74338025,
"author": "nbk",
"author_id": 5193536,
"author_profile": "https://Stackoverflow.com/users/5193536",
"pm_score": 2,
"selected": true,
"text": " select *, 1 as new_column from table \n"
},
{
"answer_id": 74338289,
"author": "trillion",
"author_id": 12513693,
"author_profile": "https://Stackoverflow.com/users/12513693",
"pm_score": 0,
"selected": false,
"text": "select \n *, \n 'john' as name, \n 'us' country, \n 9999 as population \nfrom <table_name>\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74337983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6733403/"
] |
74,338,035 | <p>I hope you are all doing well.</p>
<p>I am trying to display a random fact whenever you load the website, and so far I've had no luck. The way it works is it sets a variable to a random number, then the text to the element in the array that corresponds to that number</p>
<pre><code> <p id="sciencefact">
<script>
var factnumber = Math.floor(Math.random() * 3);
console.log(factnumber);
const facts = new Array["Dead skin cells are commonly found in household dust", "The bumblebee bat is the world’s smallest mammal, weighing .05-.07 ounces", "There is parts of Africa in all four hemispheres", "The Phillipines is made of 7,641 islands"];
document.getElementById("sciencefact").innerText = facts[factnumber];
</script>
</code></pre>
<p>I get a type error stating the the array is not a constructor.</p>
| [
{
"answer_id": 74338086,
"author": "kimia shahbaghi",
"author_id": 20275256,
"author_profile": "https://Stackoverflow.com/users/20275256",
"pm_score": 0,
"selected": false,
"text": "\n <body>\n <p id=\"sciencefact\"></p>\n </body>\n <script>\n var factnumber = Math.floor(Math.random() * 3);\n console.log(factnumber);\n\n const facts = new Array (\n \"Dead skin cells are commonly found in household dust\",\n \"The bumblebee bat is the world’s smallest mammal, weighing .05-.07 ounces\",\n \"There is parts of Africa in all four hemispheres\",\n \"The Phillipines is made of 7,641 islands\",\n );\n document.getElementById(\"sciencefact\").innerText = facts[factnumber];\n </script>\n"
},
{
"answer_id": 74338197,
"author": "ths",
"author_id": 6388552,
"author_profile": "https://Stackoverflow.com/users/6388552",
"pm_score": -1,
"selected": false,
"text": "Array"
},
{
"answer_id": 74338203,
"author": "Sampat Aheer",
"author_id": 10835518,
"author_profile": "https://Stackoverflow.com/users/10835518",
"pm_score": 0,
"selected": false,
"text": "const facts = [\"Dead skin cells are commonly found in household dust\", \"The bumblebee bat is the world’s smallest mammal, weighing .05-.07 ounces\", \"There are parts of Africa in all four hemispheres\", \"The Philippines is made of 7,641 islands\"];\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18807942/"
] |
74,338,046 | <pre><code>function getObjKey(obj, value) {
return Object.keys(obj).find(key => obj[key] === value);
}
const obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};
console.log(getObjKey(obj, ['Santiago','Germany']));
</code></pre>
<p>I want to get the key of ['Santiago','Germany'] this array value as city1</p>
<pre><code>console.log(getObjKey(obj, 'Chicago'));
</code></pre>
<p>When I try the above code, I am getting the key of 'Chicago' as city2.</p>
<p>Same way I want to get the key of ['Santiago','Germany'] as well. How can I do that?</p>
<p>Any suggestions?</p>
<p>Thanks for the response.</p>
<p>Now my Object looks like</p>
<pre><code>const obj = {city1: ['Santiago','Germany'], city2: 'Chicago', level1:
{level2 : [{level3:chennai},{level4:madurai}]};
</code></pre>
<p>when I pass</p>
<pre><code>[{level3:chennai},{level4:madurai}]
</code></pre>
<p>as an argument, I need to get its key level2 . I wasn't able to find that. Any suggestions for this.</p>
| [
{
"answer_id": 74338115,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 1,
"selected": false,
"text": "obj[key]"
},
{
"answer_id": 74338420,
"author": "zb22",
"author_id": 3561607,
"author_profile": "https://Stackoverflow.com/users/3561607",
"pm_score": 1,
"selected": false,
"text": "Object.entries()"
},
{
"answer_id": 74338566,
"author": "denies",
"author_id": 16910396,
"author_profile": "https://Stackoverflow.com/users/16910396",
"pm_score": 0,
"selected": false,
"text": "==="
},
{
"answer_id": 74338712,
"author": "PeterKA",
"author_id": 3558931,
"author_profile": "https://Stackoverflow.com/users/3558931",
"pm_score": 1,
"selected": false,
"text": "value"
},
{
"answer_id": 74338851,
"author": "ddsultan",
"author_id": 2060245,
"author_profile": "https://Stackoverflow.com/users/2060245",
"pm_score": 0,
"selected": false,
"text": "function getObjKey(obj, value) {\n const valueToCompare = (rawValue) => (rawValue && rawValue.constructor === Array) ? rawValue.join('-') : rawValue; \n \n return Object.keys(obj).find(key => valueToCompare(obj[key]) === valueToCompare(value));\n}\n\nconst obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};\n\nconsole.log(getObjKey(obj, ['Santiago','Germany']));\n\nconsole.log(getObjKey(obj, 'Chicago'));"
},
{
"answer_id": 74343078,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 1,
"selected": false,
"text": "Arrays"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16536855/"
] |
74,338,049 | <p><a href="https://i.stack.imgur.com/adTgR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/adTgR.png" alt="enter image description here" /></a></p>
<p>This is my input table</p>
<p>but i want to get this table</p>
<p><a href="https://i.stack.imgur.com/ksjVk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksjVk.png" alt="enter image description here" /></a></p>
<p>Explaination:
I want to subtract value of segmeted 14/10/22 - 7/10/22 that means (28930-28799)</p>
<p>how could i get this kindly help me to figure it out. I cant format it properly.</p>
<p><a href="https://i.stack.imgur.com/adTgR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/adTgR.png" alt="enter image description here" /></a></p>
<p>This is my table</p>
<p>and i want to subtract value column subtraction by SEGMENTED_DATE wise
like (14th october value - 7th october value) that means (28930-28799)</p>
<p>the segment table is created by bellow query</p>
<pre><code>select segment ,count(distinct user_id)as value,SEGMENTED_DATE from weekly_customer_RFM_TABLE
where segment in('About to sleep','Promising','champion','Loyal_customer',
'Potential_Loyalist','At_Risk','Need_Attention','New_customer',
'Hibernating','Cant_loose')
and SEGMENTED_DATE between '2022-10-07' and '2022-10-28'
Group by segment,SEGMENTED_DATE
</code></pre>
<p>I want this table as output</p>
<p><a href="https://i.stack.imgur.com/ksjVk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ksjVk.png" alt="enter image description here" /></a></p>
<p>This is only value difference only Segment_date wise</p>
| [
{
"answer_id": 74338115,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 1,
"selected": false,
"text": "obj[key]"
},
{
"answer_id": 74338420,
"author": "zb22",
"author_id": 3561607,
"author_profile": "https://Stackoverflow.com/users/3561607",
"pm_score": 1,
"selected": false,
"text": "Object.entries()"
},
{
"answer_id": 74338566,
"author": "denies",
"author_id": 16910396,
"author_profile": "https://Stackoverflow.com/users/16910396",
"pm_score": 0,
"selected": false,
"text": "==="
},
{
"answer_id": 74338712,
"author": "PeterKA",
"author_id": 3558931,
"author_profile": "https://Stackoverflow.com/users/3558931",
"pm_score": 1,
"selected": false,
"text": "value"
},
{
"answer_id": 74338851,
"author": "ddsultan",
"author_id": 2060245,
"author_profile": "https://Stackoverflow.com/users/2060245",
"pm_score": 0,
"selected": false,
"text": "function getObjKey(obj, value) {\n const valueToCompare = (rawValue) => (rawValue && rawValue.constructor === Array) ? rawValue.join('-') : rawValue; \n \n return Object.keys(obj).find(key => valueToCompare(obj[key]) === valueToCompare(value));\n}\n\nconst obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};\n\nconsole.log(getObjKey(obj, ['Santiago','Germany']));\n\nconsole.log(getObjKey(obj, 'Chicago'));"
},
{
"answer_id": 74343078,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 1,
"selected": false,
"text": "Arrays"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1080145/"
] |
74,338,060 | <p><a href="https://i.stack.imgur.com/x2dW6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x2dW6.png" alt="enter image description here" /></a></p>
<p>Hi;
I have this data in excel file and I want to split the dash separated values into different rows within the same cell (splitting the dash separated values cell only).</p>
<p>I want to count the total credit hours for each SP & WD without replicating the credit hours, How can I do that in Power bi and Excel?</p>
<p>Any help will be appreciated.</p>
| [
{
"answer_id": 74338115,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 1,
"selected": false,
"text": "obj[key]"
},
{
"answer_id": 74338420,
"author": "zb22",
"author_id": 3561607,
"author_profile": "https://Stackoverflow.com/users/3561607",
"pm_score": 1,
"selected": false,
"text": "Object.entries()"
},
{
"answer_id": 74338566,
"author": "denies",
"author_id": 16910396,
"author_profile": "https://Stackoverflow.com/users/16910396",
"pm_score": 0,
"selected": false,
"text": "==="
},
{
"answer_id": 74338712,
"author": "PeterKA",
"author_id": 3558931,
"author_profile": "https://Stackoverflow.com/users/3558931",
"pm_score": 1,
"selected": false,
"text": "value"
},
{
"answer_id": 74338851,
"author": "ddsultan",
"author_id": 2060245,
"author_profile": "https://Stackoverflow.com/users/2060245",
"pm_score": 0,
"selected": false,
"text": "function getObjKey(obj, value) {\n const valueToCompare = (rawValue) => (rawValue && rawValue.constructor === Array) ? rawValue.join('-') : rawValue; \n \n return Object.keys(obj).find(key => valueToCompare(obj[key]) === valueToCompare(value));\n}\n\nconst obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};\n\nconsole.log(getObjKey(obj, ['Santiago','Germany']));\n\nconsole.log(getObjKey(obj, 'Chicago'));"
},
{
"answer_id": 74343078,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 1,
"selected": false,
"text": "Arrays"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6444652/"
] |
74,338,069 | <p>browser doesn't show progress bar when downloading a file</p>
<pre><code>function getSound(sound) {
var req = new XMLHttpRequest();
req.open("GET", sound, true);
req.responseType = "blob";
req.onload = function (event) {
var blob = req.response;//if you have the fileName header available
var link=document.createElement('a');
link.href=window.URL.createObjectURL(blob);
link.download='sound.mp3';
link.click();
};
req.send();
}
</code></pre>
<p>I want show like this
<a href="https://i.stack.imgur.com/zAkfH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zAkfH.png" alt="I want show like this" /></a></p>
| [
{
"answer_id": 74338115,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 1,
"selected": false,
"text": "obj[key]"
},
{
"answer_id": 74338420,
"author": "zb22",
"author_id": 3561607,
"author_profile": "https://Stackoverflow.com/users/3561607",
"pm_score": 1,
"selected": false,
"text": "Object.entries()"
},
{
"answer_id": 74338566,
"author": "denies",
"author_id": 16910396,
"author_profile": "https://Stackoverflow.com/users/16910396",
"pm_score": 0,
"selected": false,
"text": "==="
},
{
"answer_id": 74338712,
"author": "PeterKA",
"author_id": 3558931,
"author_profile": "https://Stackoverflow.com/users/3558931",
"pm_score": 1,
"selected": false,
"text": "value"
},
{
"answer_id": 74338851,
"author": "ddsultan",
"author_id": 2060245,
"author_profile": "https://Stackoverflow.com/users/2060245",
"pm_score": 0,
"selected": false,
"text": "function getObjKey(obj, value) {\n const valueToCompare = (rawValue) => (rawValue && rawValue.constructor === Array) ? rawValue.join('-') : rawValue; \n \n return Object.keys(obj).find(key => valueToCompare(obj[key]) === valueToCompare(value));\n}\n\nconst obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};\n\nconsole.log(getObjKey(obj, ['Santiago','Germany']));\n\nconsole.log(getObjKey(obj, 'Chicago'));"
},
{
"answer_id": 74343078,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 1,
"selected": false,
"text": "Arrays"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16625270/"
] |
74,338,110 | <p>I'm having a hard time including the conversion rates and the range. Can you help me with this? I'm a beginner programming in Python. Thank you so much. (<a href="https://i.stack.imgur.com/0PW99.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/0PW99.jpg</a>)]</p>
<p>Sample of expected output:</p>
<pre><code>This program will convert a range of LENGTH
Enter (F) to convert Feet to Centimeter
Enter (C to convert Centimeter to Feet
Enter Selection: F
Enter starting length to convert: 10
Enter ending length to convert: 20
Length Length
Feet Centimeter
10.0 304.8
11.0 335.3
12.0 365.8
13.0 396.2
14.0 426.7
15.0 457.2
16.0 487.7
17.0 518.2
18.0 548.6
19.0 579.1
20.0 609.6
</code></pre>
<p>Here's my initial input, but I really can't manage to do it. <a href="https://i.stack.imgur.com/M9Jig.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M9Jig.jpg" alt="enter image description here" /></a></p>
<pre><code>print("This program will convert a range of LENGTH ")
print("Enter (F) to convert Feet to Centimeter")
print("Enter (C) to convert Centimeter to Feet")
print()
feet = 'F'
centimeter = 'C'
which = input("Enter Selection: ", )
meas_start = int(input("Enter starting length to convert: "))
meas_end = int(input("Enter ending length to convert: "))
print()
print(" Length Length")
print("Feet Centimeter")
if meas_start == feet:
</code></pre>
| [
{
"answer_id": 74338115,
"author": "Asraf",
"author_id": 20361860,
"author_profile": "https://Stackoverflow.com/users/20361860",
"pm_score": 1,
"selected": false,
"text": "obj[key]"
},
{
"answer_id": 74338420,
"author": "zb22",
"author_id": 3561607,
"author_profile": "https://Stackoverflow.com/users/3561607",
"pm_score": 1,
"selected": false,
"text": "Object.entries()"
},
{
"answer_id": 74338566,
"author": "denies",
"author_id": 16910396,
"author_profile": "https://Stackoverflow.com/users/16910396",
"pm_score": 0,
"selected": false,
"text": "==="
},
{
"answer_id": 74338712,
"author": "PeterKA",
"author_id": 3558931,
"author_profile": "https://Stackoverflow.com/users/3558931",
"pm_score": 1,
"selected": false,
"text": "value"
},
{
"answer_id": 74338851,
"author": "ddsultan",
"author_id": 2060245,
"author_profile": "https://Stackoverflow.com/users/2060245",
"pm_score": 0,
"selected": false,
"text": "function getObjKey(obj, value) {\n const valueToCompare = (rawValue) => (rawValue && rawValue.constructor === Array) ? rawValue.join('-') : rawValue; \n \n return Object.keys(obj).find(key => valueToCompare(obj[key]) === valueToCompare(value));\n}\n\nconst obj = {city1: ['Santiago','Germany'], city2: 'Chicago'};\n\nconsole.log(getObjKey(obj, ['Santiago','Germany']));\n\nconsole.log(getObjKey(obj, 'Chicago'));"
},
{
"answer_id": 74343078,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 1,
"selected": false,
"text": "Arrays"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433757/"
] |
74,338,120 | <p>I have an HTML string. i want to select all span elements and remove spans with the same IDs and only let one of them remain in the string. The text between the span elements should not be deleted.</p>
<p>The spans with the same IDs are all after each other.
The remained one should wrap all the removed ones text.</p>
<p>e.g:</p>
<p>Input:</p>
<pre class="lang-html prettyprint-override"><code><p>
Hi,<span id="1">this is just a simple text and we</span>
<span id="1">want to save me because i had a lot of</span>
<span id="1">pressure on and i want to live a better life. </span>
I researched a lot about it but i could't find anything helpful
<span id="2">just another rant. </span>
</p>
</code></pre>
<p>Output:</p>
<pre class="lang-html prettyprint-override"><code><p>
Hi,
<span id="1">
this is just a simple text and we want to save me because i had a lot of
pressure on and i want to live a better life
</span>
I researched a lot about it but i could't find anything helpful
<span id="2">just another rant. </span>
</p>
</code></pre>
| [
{
"answer_id": 74338479,
"author": "54ka",
"author_id": 10968134,
"author_profile": "https://Stackoverflow.com/users/10968134",
"pm_score": 0,
"selected": false,
"text": "let list = [...$('span')];\n\nlet tempText = '';\n\nlist.forEach((el, i) => {\n\n let currElID = el.getAttribute('id');\n\n let nextElID = null;\n\n if (list[i + 1]) {\n nextElID = list[i + 1].getAttribute('id');\n } else {\n nextElID = null;\n };\n\n\n tempText += el.innerText;\n\n\n if (currElID !== nextElID) {\n\n let listByClass = [...$(`[id=${currElID}]`)];\n\n if (listByClass.length > 0) {\n listByClass.forEach((element, index) => {\n if (index > 0) {\n element.remove();\n }\n });\n };\n\n listByClass[0].innerText = tempText;\n\n tempText = '';\n };\n\n});"
},
{
"answer_id": 74338632,
"author": "NickSlash",
"author_id": 212869,
"author_profile": "https://Stackoverflow.com/users/212869",
"pm_score": 0,
"selected": false,
"text": "id"
},
{
"answer_id": 74338761,
"author": "marzelin",
"author_id": 5664434,
"author_profile": "https://Stackoverflow.com/users/5664434",
"pm_score": 0,
"selected": false,
"text": "let spans = document.querySelectorAll(\"span[id]\");\n"
},
{
"answer_id": 74339007,
"author": "Yogi",
"author_id": 943435,
"author_profile": "https://Stackoverflow.com/users/943435",
"pm_score": 2,
"selected": true,
"text": "[...document.querySelectorAll(\"span[id]\")].reduce((last,span) => {\n\n if (span.id === last.id) {\n last.innerHTML += ' \\n' + span.innerHTML;\n span.remove();\n return last;\n }\n return span;\n\n}, {});\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13825398/"
] |
74,338,145 | <p>So I created a delete button for when an element is clicked and I want to be able to remove it. I am using an input decorator but its not receiving the data when I try to delete the button. I console log but it shows the array is empty. Its a little confusing explaining. Essentially its an example of a mini project dilemma I am working on. If someone could also explain a better way of input decorator and how to use it.</p>
<pre><code> ChildComponent:
public valuesCheck: string [] = [];
@Input() valuesFilter: string[] = [];
public deleteClick(){
let chipValue = string [] = [];
this.valuesCheck = this.valuesFilter = chipValue;
chipValue.splice(0,1);
}
Parent Component:
public filters: CFilter[] | undefined;
Parent HTML:
<app-filter-chip [valuesFiter] = "chipValue">
<app-filter-chip>
Child HTML:
<div class="chip>
<button class="closebtn" (click)="deleteClick()">
<div>
</code></pre>
| [
{
"answer_id": 74338479,
"author": "54ka",
"author_id": 10968134,
"author_profile": "https://Stackoverflow.com/users/10968134",
"pm_score": 0,
"selected": false,
"text": "let list = [...$('span')];\n\nlet tempText = '';\n\nlist.forEach((el, i) => {\n\n let currElID = el.getAttribute('id');\n\n let nextElID = null;\n\n if (list[i + 1]) {\n nextElID = list[i + 1].getAttribute('id');\n } else {\n nextElID = null;\n };\n\n\n tempText += el.innerText;\n\n\n if (currElID !== nextElID) {\n\n let listByClass = [...$(`[id=${currElID}]`)];\n\n if (listByClass.length > 0) {\n listByClass.forEach((element, index) => {\n if (index > 0) {\n element.remove();\n }\n });\n };\n\n listByClass[0].innerText = tempText;\n\n tempText = '';\n };\n\n});"
},
{
"answer_id": 74338632,
"author": "NickSlash",
"author_id": 212869,
"author_profile": "https://Stackoverflow.com/users/212869",
"pm_score": 0,
"selected": false,
"text": "id"
},
{
"answer_id": 74338761,
"author": "marzelin",
"author_id": 5664434,
"author_profile": "https://Stackoverflow.com/users/5664434",
"pm_score": 0,
"selected": false,
"text": "let spans = document.querySelectorAll(\"span[id]\");\n"
},
{
"answer_id": 74339007,
"author": "Yogi",
"author_id": 943435,
"author_profile": "https://Stackoverflow.com/users/943435",
"pm_score": 2,
"selected": true,
"text": "[...document.querySelectorAll(\"span[id]\")].reduce((last,span) => {\n\n if (span.id === last.id) {\n last.innerHTML += ' \\n' + span.innerHTML;\n span.remove();\n return last;\n }\n return span;\n\n}, {});\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17339971/"
] |
74,338,171 | <p>I want to set a autoplay sound and it only play once, no matter the rotation is. I was trying to make my Mediaplayer in the onCreate of Mainactivity. And when I try to rotate the screen, the audio continued to play.</p>
<p>I try a different method like set up a subclass and call in the activity instead of puting it in onCreat of MainActivity to make it only play once and ignore doing rotate, but it still doesn't work, can someone explain to me how can I fix it? Thank you!</p>
| [
{
"answer_id": 74338479,
"author": "54ka",
"author_id": 10968134,
"author_profile": "https://Stackoverflow.com/users/10968134",
"pm_score": 0,
"selected": false,
"text": "let list = [...$('span')];\n\nlet tempText = '';\n\nlist.forEach((el, i) => {\n\n let currElID = el.getAttribute('id');\n\n let nextElID = null;\n\n if (list[i + 1]) {\n nextElID = list[i + 1].getAttribute('id');\n } else {\n nextElID = null;\n };\n\n\n tempText += el.innerText;\n\n\n if (currElID !== nextElID) {\n\n let listByClass = [...$(`[id=${currElID}]`)];\n\n if (listByClass.length > 0) {\n listByClass.forEach((element, index) => {\n if (index > 0) {\n element.remove();\n }\n });\n };\n\n listByClass[0].innerText = tempText;\n\n tempText = '';\n };\n\n});"
},
{
"answer_id": 74338632,
"author": "NickSlash",
"author_id": 212869,
"author_profile": "https://Stackoverflow.com/users/212869",
"pm_score": 0,
"selected": false,
"text": "id"
},
{
"answer_id": 74338761,
"author": "marzelin",
"author_id": 5664434,
"author_profile": "https://Stackoverflow.com/users/5664434",
"pm_score": 0,
"selected": false,
"text": "let spans = document.querySelectorAll(\"span[id]\");\n"
},
{
"answer_id": 74339007,
"author": "Yogi",
"author_id": 943435,
"author_profile": "https://Stackoverflow.com/users/943435",
"pm_score": 2,
"selected": true,
"text": "[...document.querySelectorAll(\"span[id]\")].reduce((last,span) => {\n\n if (span.id === last.id) {\n last.innerHTML += ' \\n' + span.innerHTML;\n span.remove();\n return last;\n }\n return span;\n\n}, {});\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16137590/"
] |
74,338,175 | <p>When I run the following, I get the correct console output but the value returned from the function is always 'undefined'</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 get_public_ip() {
http.get({
'host': 'api.ipify.org',
'port': 80,
'path': '/'
}, function (resp) {
resp.on('data', function (ip) {
console.log(ip.toString()); //outputs ip address
return ip.toString(); // returns 'undefined'
});
});
}
async function run() {
let pubip = await get_public_ip();
// do stuff with pubip
}</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74338209,
"author": "Lawrence Cherone",
"author_id": 661872,
"author_profile": "https://Stackoverflow.com/users/661872",
"pm_score": 0,
"selected": false,
"text": "get_public_ip"
},
{
"answer_id": 74338243,
"author": "PRIYESH PANDEY",
"author_id": 10414870,
"author_profile": "https://Stackoverflow.com/users/10414870",
"pm_score": -1,
"selected": false,
"text": " async function get_public_ip() {\n let data;\nawait fetch(\"https://jsonplaceholder.typicode.com/posts\").then((res) => {\n data = res;\n return res;\n });\n return data;\n}\n\nasync function run() {\n let pubip = await get_public_ip();\n console.log(\" pubip\", pubip);\n}\nrun();\n"
},
{
"answer_id": 74338633,
"author": "Wyck",
"author_id": 1563833,
"author_profile": "https://Stackoverflow.com/users/1563833",
"pm_score": 0,
"selected": false,
"text": "http.get"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1647854/"
] |
74,338,208 | <p>I'm currently working on a challange where I need to divide strings by specifing number into chunks reverse them and than glue those reversed chunnks back together.</p>
<p>I came up with way to execute this, however I could't come up with way to automate this task.</p>
<pre><code>def switch (n, txt):
a = (txt [0:n] [::-1]) #here I devide and reverse the txt
b = (txt [n:2*n] [::-1])
c = (txt [2*n : 3*n] [::-1])
d = (txt [3*n : 4*n] [::-1])
e = (txt [4*n : 5*n] [::-1])
f = (txt [5*n : 6*n] [::-1])
g = (txt [6*n : 7*n] [::-1])
h = (txt [7*n : 8*n] [::-1])````
ch = (txt [8*n : 9*n] [::-1])
i = (txt [9*n : 10*n] [::-1])
j = (txt [10*n : 11*n] [::-1])
k = (txt [11*n : 12*n] [::-1])
l = (txt [12*n : 13*n] [::-1])
m = (txt [13*n : 14*n] [::-1])
return (a + b + c + d + e + f + g + h + ch + i + j + k + l + m ) #and here I glue it back together
print (switch (3, "Potatos are veges")) #The result should be "topotaa s ergevse"
</code></pre>
| [
{
"answer_id": 74338403,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 2,
"selected": true,
"text": "range(start,end,n)"
},
{
"answer_id": 74338408,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "def switch(n, txt) -> str:\n returnstring = ''\n\n while txt:\n returnstring += txt[:n][::-1].lower()\n txt = txt[n:]\n \n return returnstring\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20276553/"
] |
74,338,216 | <p>I am trying to complete this.
A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.
Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Use the function in a program that prompts the user to enter a number then displays a message indicating whether the number is prime.</p>
<pre><code>def main():
#decribe the program
print ("This is a program to see if a number is prime")
#ask the user for a number
number = int (input ("Enter a number to see if it prime: "))
#see if the number is prime
result = is_prime (number)
print ("The number", number, "is", result)
def is_prime(number):
while number < 0:
print ("The number must be greater than 1")
number = int (input("Enter a valid number: "))
for x in range (1, number + 1):
if (number % x) == 0:
return False
else:
return True
main()
</code></pre>
<p>In my for statement, I am missing something and having a hard time figuring out what I did wrong. What step am I missing?</p>
| [
{
"answer_id": 74338403,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 2,
"selected": true,
"text": "range(start,end,n)"
},
{
"answer_id": 74338408,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "def switch(n, txt) -> str:\n returnstring = ''\n\n while txt:\n returnstring += txt[:n][::-1].lower()\n txt = txt[n:]\n \n return returnstring\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433867/"
] |
74,338,302 | <p>im running a spring boot project and I'm trying to load some beans conditionaly. I have the following configuration file:</p>
<pre><code>application:
components:
componentA:
- ex1
ex2
ex3
componentB:
- ex1
ex2
ex3
componentC:
- ex1
ex2
ex3
use: componentA
</code></pre>
<p>and the following configuration classes</p>
<pre><code>@Configuration
@ConfigurationProperties(prefix = "application.components")
@Primary
@Getter
@Setter
@NoArgsConstrutor
public class MainConfig
{
private List<ComponentAConfig> componentA = new ArrayList<ComponentAConfig>();
private List<ComponentBConfig> componentB = new ArrayList<ComponentBConfig>();
private List<ComponentCConfig> componentC = new ArrayList<ComponentCConfig>();
}
</code></pre>
<pre><code>@Getter
@Setter
@NoArgsConstrutor
public abstract class ComponentConfig
{
private String ex1;
private String ex2;
private String ex3;
}
</code></pre>
<pre><code>@Configuration
@ConditionalOnProperty(prefix = "application", name = "use", havingValue = "componentA")
public class ComponentAConfig extends ComponentConfig
{
}
</code></pre>
<pre><code>@Configuration
@ConditionalOnProperty(prefix = "application", name = "use", havingValue = "componentB")
public class ComponentBConfig extends ComponentConfig
{
}
</code></pre>
<pre><code>@Configuration
@ConditionalOnProperty(prefix = "application", name = "use", havingValue = "componentC")
public class ComponentCConfig extends ComponentConfig
{
}
</code></pre>
<p>Even though I have the <strong>@ConditionalOnProperty</strong> defined on each configuration class its still loads all of them. How can I load only componentA's list and ignore the other 2?
Thank you</p>
| [
{
"answer_id": 74338725,
"author": "Gobanit",
"author_id": 4106800,
"author_profile": "https://Stackoverflow.com/users/4106800",
"pm_score": 3,
"selected": true,
"text": "@Data\n@NoArgsConstructor\npublic class ComponentConfigPart {\n private String ex1;\n private String ex2;\n private String ex3;\n}\n"
},
{
"answer_id": 74338790,
"author": "acG",
"author_id": 13028173,
"author_profile": "https://Stackoverflow.com/users/13028173",
"pm_score": 0,
"selected": false,
"text": "application:\n components:\n componentA:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\n componentB:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\n componentC:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\nuse: componentA\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13028173/"
] |
74,338,307 | <p>The goal is to "break line" after each split.</p>
<p><strong>I have two arrays:</strong></p>
<pre><code>$split = [4, 2, 4];
$courses = ['HTML', 'JS', 'CSS', 'VueJS', 'ReactJs', 'PHP', 'Ruby', 'Python', 'Java', 'C#'];
</code></pre>
<p>As you can see I have the first <code>array</code> called split, and the second <code>array</code> called courses, I want to add <code><br></code> after each split</p>
<p>I want to loop over <code>$courses</code> and after the 4 items I print <code><br></code>. Also after 2 items I print another <code><br></code></p>
<p>Note: I can have more values in my <code>$split</code> array, that's why I don't want to use</p>
<pre><code>foreach($courses as $key => $value){
echo $value;
if ($key == 4 OR $key == 2){
echo '<br>';
}
}
</code></pre>
<p>My code is not working fine because I can't use a lot of <code>OR</code> with <code>if statements</code>, because I can have a lot of split in my <code>$split</code> <code>array</code></p>
<p>Is there any clean and best way to loop over <code>$courses</code> and print <code><br></code> after <code>4</code> loop and after <code>2</code> and after <code>4</code> and so on, it depends on how many split I have in my <code>$split</code></p>
| [
{
"answer_id": 74338725,
"author": "Gobanit",
"author_id": 4106800,
"author_profile": "https://Stackoverflow.com/users/4106800",
"pm_score": 3,
"selected": true,
"text": "@Data\n@NoArgsConstructor\npublic class ComponentConfigPart {\n private String ex1;\n private String ex2;\n private String ex3;\n}\n"
},
{
"answer_id": 74338790,
"author": "acG",
"author_id": 13028173,
"author_profile": "https://Stackoverflow.com/users/13028173",
"pm_score": 0,
"selected": false,
"text": "application:\n components:\n componentA:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\n componentB:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\n componentC:\n - ex1\n ex2\n ex3\n - ex1\n ex2\n ex3\nuse: componentA\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338307",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10424862/"
] |
74,338,328 | <p>I want to get the data from my MongoDB database depending on the URL . If I access localhost:3000/phones it should get all the data with the category phones, where if it is localhost:3000/laptops it should get all the laptops.</p>
<p>Below is my schema:</p>
<pre><code> name: {
required: true,
type: String
},
category: {
required: true,
type: String
},
</code></pre>
<p>Below is how my current version:</p>
<pre><code>router.get('/getAll', async (req, res) => {
try {
const data = await Model.find();
res.json(data)
}
catch (error) {
res.status(500).json({ message: error.message })
}
})
</code></pre>
<p>I tried to <code>findByID</code> but it did not work.</p>
| [
{
"answer_id": 74338445,
"author": "krish007",
"author_id": 16972288,
"author_profile": "https://Stackoverflow.com/users/16972288",
"pm_score": 2,
"selected": true,
"text": "router.get('/phones', async (req, res) => {\n try {\n const data = await Model.find({category: \"phones\"});\n res.json(data)\n }\n catch (error) {\n res.status(500).json({ message: error.message })\n }\n})\n"
},
{
"answer_id": 74338471,
"author": "eichkh",
"author_id": 20433534,
"author_profile": "https://Stackoverflow.com/users/20433534",
"pm_score": 0,
"selected": false,
"text": "req.query.category"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20322595/"
] |
74,338,349 | <p>I have a date column which stores a date in the GMT timezone in the format<p>
<strong>'dd-MON-yy HH.MM:SS.milliseconds AM/PM, e.g. 03-NOV-22 10.23.31.007000000 AM</strong>.<p>
I am provided a date and I want to write a query to check if the given date is equal to the date stored in the table but I would like to ignore the milli seconds.I want to make sure that the dates are in the same timezone (GMT) while performing the date comparison.
this is done to check if the date is already present and prevent a duplicate date insertion though ignoring the milli second part.<code>enter code here</code>
I will be using the condition to conditionally insert a record if the record with the date is not present</p>
<pre><code>Insert into table_name (col1, col2, col3, col4, col5, col6, col7)
SELECT ?,?,?,?,?,?,? from dual
where 0 = (select count(*) from table_name where strat_time = ?);
</code></pre>
| [
{
"answer_id": 74338445,
"author": "krish007",
"author_id": 16972288,
"author_profile": "https://Stackoverflow.com/users/16972288",
"pm_score": 2,
"selected": true,
"text": "router.get('/phones', async (req, res) => {\n try {\n const data = await Model.find({category: \"phones\"});\n res.json(data)\n }\n catch (error) {\n res.status(500).json({ message: error.message })\n }\n})\n"
},
{
"answer_id": 74338471,
"author": "eichkh",
"author_id": 20433534,
"author_profile": "https://Stackoverflow.com/users/20433534",
"pm_score": 0,
"selected": false,
"text": "req.query.category"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1081574/"
] |
74,338,359 | <p>I have large numbers of biological recording visits (c350K - hence use of data.table), the details of which include the date and coordinates. I want to lookup the weather at the time and place of each visit. Such data are available from MetOffice gridded daily weather data in which the values for each month are held in a .nc files. Therefore, I extract the year and month from the date, loop though the visits by year and month, load the relevant .nc file (using <code>raster</code> and <code>ncdf4</code> packages) for each year and month and then extract the data for the appropriate days and coordinates. However, I have run into a problem - selecting visits by year and month is not working.</p>
<p>Here is some example code illustrating the problem:</p>
<pre><code>library(data.table)
set.seed(21)
v <- data.table(dt=sample(seq(as.Date('2010/01/01'),
as.Date('2020/12/31'), by="day"), 50),
x=sample(seq(100,600),50),
y=sample(seq(0,1000),50))
v[ ,year:=as.integer(format(dt, "%Y"))]
v[ ,mon:=as.integer(format(dt, "%m"))]
v[ ,day:=as.integer(format(dt, "%d"))]
for(y in min(v$year):max(v$year)){
for(m in 1:12){
x <- v[year==y & mon==m, ]
if(nrow(x)>0){
print(paste(y,m,nrow(x)))
}
}
}
</code></pre>
<p>The result is - nothing is printed. <code>x <- v[year==y & mon==m, ]</code> does not select any rows. To illustrate this further, consider the following:</p>
<pre><code>> nrow(v[year==2020 & mon==9, ])
[1] 2
> y<-2020
> m<-9
> nrow(v[year==y & mon==m, ])
[1] 0
>
</code></pre>
<p>Examining the data.table, the <code>year</code>, <code>mon</code> and <code>day</code> variables are "int" and so are variables <code>y</code> and <code>m</code>. I don't understand what is going on here!</p>
| [
{
"answer_id": 74338445,
"author": "krish007",
"author_id": 16972288,
"author_profile": "https://Stackoverflow.com/users/16972288",
"pm_score": 2,
"selected": true,
"text": "router.get('/phones', async (req, res) => {\n try {\n const data = await Model.find({category: \"phones\"});\n res.json(data)\n }\n catch (error) {\n res.status(500).json({ message: error.message })\n }\n})\n"
},
{
"answer_id": 74338471,
"author": "eichkh",
"author_id": 20433534,
"author_profile": "https://Stackoverflow.com/users/20433534",
"pm_score": 0,
"selected": false,
"text": "req.query.category"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16957107/"
] |
74,338,371 | <p>Given:</p>
<ol>
<li>Table A with multiple rows and attributes: (<em>A_attr1</em> (key) , A_attr2).</li>
<li>Table B with attributes (<em>B_attr1</em> (key) , <em>A_attr1</em> (foreign key), B_attr2).</li>
</ol>
<p>How do I insert some values in the table B <strong>only if the foreign key exists</strong>?</p>
| [
{
"answer_id": 74338372,
"author": "Scooterz Giovanni",
"author_id": 10600769,
"author_profile": "https://Stackoverflow.com/users/10600769",
"pm_score": 0,
"selected": false,
"text": "ERROR: the INSERT or the UPDATE on the TABLE table_B violates the foreign key constraint\n\"_A_attr1_\"\nDETAIL: the key (A_attr1)=(wrong_value) it's not present in the table \"Table_A\"\n"
},
{
"answer_id": 74338558,
"author": "Karthikeyan K",
"author_id": 12447281,
"author_profile": "https://Stackoverflow.com/users/12447281",
"pm_score": 1,
"selected": false,
"text": "Where Exists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10600769/"
] |
74,338,387 | <p>I want to create a border (camera type) with 3 colors (blue, white and red).</p>
<p>I created this HTML code :</p>
<pre><code><div class="reinsurance-offer">
<div class="reinsurance-offer-link"><a href="/node/133" hreflang="fr">Faites la promotion de vos événements</a></div>
</div>
</code></pre>
<p>I applied this CSS :</p>
<pre><code>#block-subtheme-olivero-views-block-reassurance-block-1 .reinsurance-offer {
background-color: #f7f9fa;
padding-right: 2.25rem;
padding-left: 2.25rem;
padding-top: 1.6875rem;
padding-bottom: 1.6875rem;
text-align: center;
}
#block-subtheme-olivero-views-block-reassurance-block-1 .reinsurance-offer-link {
display: inline-flex;
padding: 0.75rem;
border: 5px solid;
border-color: #E20E17 #1F71B8;
background-color: #ffffff;
}
</code></pre>
<p>Here is the rendering :</p>
<p><a href="https://i.stack.imgur.com/FrDFW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FrDFW.png" alt="enter image description here" /></a></p>
<p>I want to make the same display as in the image below, without the blur effect.</p>
<p>How can I do this in CSS and is it possible ?</p>
<p><a href="https://i.stack.imgur.com/jhCWZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jhCWZ.jpg" alt="enter image description here" /></a></p>
<p>I didn't manage to get the desired result, who has a solution ? Thanks</p>
| [
{
"answer_id": 74338372,
"author": "Scooterz Giovanni",
"author_id": 10600769,
"author_profile": "https://Stackoverflow.com/users/10600769",
"pm_score": 0,
"selected": false,
"text": "ERROR: the INSERT or the UPDATE on the TABLE table_B violates the foreign key constraint\n\"_A_attr1_\"\nDETAIL: the key (A_attr1)=(wrong_value) it's not present in the table \"Table_A\"\n"
},
{
"answer_id": 74338558,
"author": "Karthikeyan K",
"author_id": 12447281,
"author_profile": "https://Stackoverflow.com/users/12447281",
"pm_score": 1,
"selected": false,
"text": "Where Exists"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,338,393 | <p>I have built a function with <code>apply</code> and <code>outer</code> that is working great. However, one issue is that I cannot figure out how to add a condition statement without breaking it.</p>
<p>The function currently is:</p>
<pre><code>df$match <- apply(outer(df$c2, df$c2, function(x, y) abs(x - y) < 1e7) &
diag(nrow(df)) == 0,
MARGIN = 1,
function(x) paste(df$c3[x], collapse = ", "))
</code></pre>
<p>Basically, it looks to see if a numeric value in <code>c2</code> of one row within a certain threshold (1e7) of any other row in <code>df</code> and then tells me which row(s) it matches by returned a specific row ID I have stored in <code>c3</code>. However, I want to modify this to only compare rows with the same numeric value in another column: <code>c1</code>.</p>
<p>Here is what the data looks like:</p>
<pre><code>c1 c2 c3 match
1 52426577 chr1.52426577_T chr2.43668478_G, chr2.47207905_G, chr2.47959251_C, chr2.49606475_C
1 108023890 chr1.108023890_A
1 129776943 chr1.129776943_T
2 39943710 chr2.39943710_C chr2.43668478_G, chr2.47207905_G, chr2.47959251_C,
2 43668478 chr2.43668478_G chr1.52426577_T, chr2.39943710_C, chr2.47207905_G, chr2.47959251_C
2 47207905 chr2.47207905_G chr1.52426577_T, chr2.39943710_C, chr2.43668478_G, chr2.47959251_C
2 47959251 chr2.47959251_C chr1.52426577_T, chr2.39943710_C, chr2.43668478_G, chr2.47207905_G
</code></pre>
<p>I've tried this but it doesn't work. The error I get is: <code>attempt to apply non-function</code></p>
<pre><code>df$match <- apply(outer(df$c2, df$c2, function(x, y) if(df$c1(x) == df$c1(y)) abs(x - y) < 1e7) &
diag(nrow(df)) == 0,
MARGIN = 1,
function(x) paste(df$c3[x], collapse = ", "))
</code></pre>
<p>This is my desired result:</p>
<pre><code>c1 c2 c3 match
1 52426577 chr1.52426577_T
1 108023890 chr1.108023890_A
1 129776943 chr1.129776943_T
2 39943710 chr2.39943710_C chr2.43668478_G, chr2.47207905_G, chr2.47959251_C
2 43668478 chr2.43668478_G chr2.39943710_C, chr2.47207905_G, chr2.47959251_C
2 47207905 chr2.47207905_G chr2.39943710_C, chr2.43668478_G, chr2.47959251_C
2 47959251 chr2.47959251_C chr2.39943710_C, chr2.43668478_G, chr2.47207905_G
</code></pre>
<p>I've also tried grouping in dplyr to no avail:</p>
<pre><code>df$match <- sapply(df$c3, function(x){
df %>%
group_by(c1) %>%
filter(abs(c2 - c2[c3 == x]) < 1e7,
c3 != x) %>%
pull(c3) %>%
paste0(collapse = ',')
})
Error in `filter()`:
! Problem while computing `..1 = abs(d2 - d2[d3 == x]) < 1e+07`.
✖ Input `..1` must be of size 17 or 1, not size 0.
ℹ The error occurred in group 2: d1 = 2.
</code></pre>
| [
{
"answer_id": 74369676,
"author": "Ritchie Sacramento",
"author_id": 2835261,
"author_profile": "https://Stackoverflow.com/users/2835261",
"pm_score": 3,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74372156,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 2,
"selected": false,
"text": "dplyr"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6836719/"
] |
74,338,417 | <p>Is there any way to change port in netlify actually need static port 3000 to make my app work.</p>
<p>The App need port 3000 in netlify prod.</p>
| [
{
"answer_id": 74369676,
"author": "Ritchie Sacramento",
"author_id": 2835261,
"author_profile": "https://Stackoverflow.com/users/2835261",
"pm_score": 3,
"selected": true,
"text": "dplyr"
},
{
"answer_id": 74372156,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 2,
"selected": false,
"text": "dplyr"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17582005/"
] |
74,338,432 | <p>I have the following structure:</p>
<pre><code>struct SimpleCommand {
// Simple command is simply a vector of strings
std::vector<std::string *> _arguments;
SimpleCommand();
~SimpleCommand();
void insertArgument( std::string * argument );
void print();
};
</code></pre>
<p>I want to call the <code>insertArgument</code> function with an arguments of type <code>char*</code> that are given to me in an array, in a loop. If I call it with the following code:</p>
<pre><code>for(i=0; i<n; i++){
insertArgument(array[i]);
}
</code></pre>
<p>it won't compile and gives me an</p>
<pre><code>cannot convert ‘char*’ to ‘std::string*’
</code></pre>
<p>error. If I use the following code as suggested:</p>
<pre><code>for(i=0; i<n; i++){
std:string s(array[i]);
insertArgument(&s);
}
</code></pre>
<p>all the values in the vector point to the same string. How do I resolve this issue.</p>
| [
{
"answer_id": 74338444,
"author": "lorro",
"author_id": 6292621,
"author_profile": "https://Stackoverflow.com/users/6292621",
"pm_score": 0,
"selected": false,
"text": "char* cs;\nstd::string s(cs);\ninsertArgument(&s);\n"
},
{
"answer_id": 74338634,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 2,
"selected": false,
"text": "void insertArgument( std::string * argument );\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2034811/"
] |
74,338,448 | <p>I am obtaining values from two tables. When I run the subquery in its own PROC SQL statement in SAS, it runs fine, with the count of citations for each ID. When I input the subquery into my SELECT outer query, it gives me ERROR: Subquery evaluated to more than one row. I am having a hard time determining the cause of this issue.</p>
<p>The subquery should result in one row of count of citations per ID. I am trying to get the count of citations (per ID) into my outer query. Not all items from B will be in A (hence the left join on B).</p>
<pre><code>SELECT
A.AREA
,A.NAME
,B.ID
,(
SELECT
COUNT(B.TYPE)
FROM
EVAL.CITATIONS AS B
GROUP BY
B.ID
)
AS COUNT_CITATIONS
FROM
EVAL.OCT AS A
LEFT JOIN EVAL.CITATIONS
ON A.DBA = B.NAME
ORDER BY A.NAME ASC
;
</code></pre>
<p>I expected the outer query to pull the counts for the citations per ID. The citations are coming from table B (which I'm using to left join into table A). I have been searching forums for this error and I understand that my query is resulting in more than one row, but I can't figure out why the outer query is not simply pulling the counts I need from ID when the left join completes.</p>
<p>I also tried adding in the subquery this WHERE clause after researching some similar questions to no avail.</p>
<pre><code>WHERE FACID = CDPH_CITATIONS.FACID
</code></pre>
| [
{
"answer_id": 74338671,
"author": "NickW",
"author_id": 13658399,
"author_profile": "https://Stackoverflow.com/users/13658399",
"pm_score": 3,
"selected": true,
"text": "SELECT \nA.AREA\n,A.NAME\n,B.ID\n,(\n SELECT \n COUNT(C.TYPE) \n FROM \n EVAL.CITATIONS AS C\n WHERE B.ID = C.ID\n GROUP BY \n C.ID\n ) \n AS COUNT_CITATIONS\n\nFROM \nEVAL.OCT AS A \n\nLEFT JOIN EVAL.CITATIONS \nON A.DBA = B.NAME\n\nORDER BY A.NAME ASC\n"
},
{
"answer_id": 74339923,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 1,
"selected": false,
"text": "SELECT"
},
{
"answer_id": 74340507,
"author": "Tom",
"author_id": 4965549,
"author_profile": "https://Stackoverflow.com/users/4965549",
"pm_score": 1,
"selected": false,
"text": "proc sql;\nSELECT \n A.NAME\n ,A.AREA\n ,B.ID\n ,COUNT(B.TYPE) AS COUNT_CITATIONS\nFROM EVAL.OCT AS A \nLEFT JOIN EVAL.CITATIONS B\n ON A.DBA = B.NAME\nGROUP BY ID\nORDER BY NAME \n;\nquit;\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433939/"
] |
74,338,455 | <p>I have the following data:</p>
<pre><code>df = pd.DataFrame({'id' : [1,2,3,4,5,6], 'category' : [1,3,1,4,3,2], 'day1' : [10,20,30,40,50,60], 'day2' : [1,2,3,4,5,7], 'day3' : [0,1,2,3,7,9] })
df
id category day1 day2 day3
0 1 1 10 1 0
1 2 3 20 2 1
2 3 1 30 3 2
3 4 4 40 4 3
4 5 3 50 5 7
5 6 2 60 7 9
</code></pre>
<p>It is time series data and I need to prepare the new DataFrame as records of ('id', 'category', 'day'):</p>
<pre><code>df = pd.DataFrame({'id' : [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6], 'category' : [1,1,1,3,3,3,1,1,1,4,4,4,3,3,3,2,2,2], 'day' : [10,1,0,20,2,1,30,3,2,40,4,3,50,5,7,60,7,9]})
df
id category day
0 1 1 10
1 1 1 1
2 1 1 0
3 2 3 20
4 2 3 2
5 2 3 1
6 3 1 30
7 3 1 3
8 3 1 2
9 4 4 40
10 4 4 4
11 4 4 3
12 5 3 50
13 5 3 5
14 5 3 7
15 6 2 60
16 6 2 7
17 6 2 9
</code></pre>
<p>But I don't know how to do it without looping by every DataFrame cell</p>
| [
{
"answer_id": 74338671,
"author": "NickW",
"author_id": 13658399,
"author_profile": "https://Stackoverflow.com/users/13658399",
"pm_score": 3,
"selected": true,
"text": "SELECT \nA.AREA\n,A.NAME\n,B.ID\n,(\n SELECT \n COUNT(C.TYPE) \n FROM \n EVAL.CITATIONS AS C\n WHERE B.ID = C.ID\n GROUP BY \n C.ID\n ) \n AS COUNT_CITATIONS\n\nFROM \nEVAL.OCT AS A \n\nLEFT JOIN EVAL.CITATIONS \nON A.DBA = B.NAME\n\nORDER BY A.NAME ASC\n"
},
{
"answer_id": 74339923,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 1,
"selected": false,
"text": "SELECT"
},
{
"answer_id": 74340507,
"author": "Tom",
"author_id": 4965549,
"author_profile": "https://Stackoverflow.com/users/4965549",
"pm_score": 1,
"selected": false,
"text": "proc sql;\nSELECT \n A.NAME\n ,A.AREA\n ,B.ID\n ,COUNT(B.TYPE) AS COUNT_CITATIONS\nFROM EVAL.OCT AS A \nLEFT JOIN EVAL.CITATIONS B\n ON A.DBA = B.NAME\nGROUP BY ID\nORDER BY NAME \n;\nquit;\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5592430/"
] |
74,338,472 | <p>I have tried to re-render my class component with user values , but set state is only rendering the previous value, and then the current value. By which I mean, it is working one step back. Lets say initial value was set to 0. After onclick, i wanted to update the value to 20,but it gave me 0. Now when I try to update to 40, it gives me the value 20. Can someone please help me with the solution and detailed explanation as to why is this happening.
<strong>My Class Component</strong></p>
<pre><code>import React, { Component } from 'react'
export default class TemperatureRange extends Component {
constructor(){
super()
this.state={
initialTemperature:0
}
}
handleClick(userValue){
this.setState({
initialTemperature:userValue
})
if(this.state.initialTemperature>0 && this.state.initialTemperature<30){
document.querySelector("#container").style.backgroundColor="red";
}
else{
document.querySelector("#container").style.backgroundColor="green";
}
}
render() {
return (
<div id="container">
<input type="number" id="number" />
<input type="button" id="button" value="Check" onClick={()=>{this.handleClick(document.querySelector("#number").value)}}/>
</div>
)
}
}
</code></pre>
<p><strong>App.js</strong></p>
<pre><code>import logo from './logo.svg';
import './App.css';
import TemperatureRange from './Components/TemperatureRange'
function App() {
return (
<div className="App">
<TemperatureRange/>
</div>
);
}
export default App;
</code></pre>
<p>I am confused as to why my state is not updated on click with the present user value. Please help me in this.</p>
| [
{
"answer_id": 74338584,
"author": "HappyDev",
"author_id": 16775611,
"author_profile": "https://Stackoverflow.com/users/16775611",
"pm_score": 2,
"selected": true,
"text": "setState"
},
{
"answer_id": 74338820,
"author": "Samer Murad",
"author_id": 2252297,
"author_profile": "https://Stackoverflow.com/users/2252297",
"pm_score": 0,
"selected": false,
"text": "setState"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14809089/"
] |
74,338,485 | <p>I have a table like below,</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>Sample1</td>
</tr>
<tr>
<td>A</td>
<td>Sample2</td>
</tr>
<tr>
<td>A</td>
<td>Sample3</td>
</tr>
<tr>
<td>B</td>
<td>Sample3</td>
</tr>
<tr>
<td>B</td>
<td>Sample1</td>
</tr>
<tr>
<td>C</td>
<td>Sample2</td>
</tr>
<tr>
<td>C</td>
<td>Sample3</td>
</tr>
<tr>
<td>D</td>
<td>Sample1</td>
</tr>
</tbody>
</table>
</div>
<p>If I group the table by Name to get the count,</p>
<pre><code>Select Name, Count(*) as count from table group by Name;
</code></pre>
<p>I will get the following result,</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Name</th>
<th>count</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>3</td>
</tr>
<tr>
<td>B</td>
<td>2</td>
</tr>
<tr>
<td>C</td>
<td>2</td>
</tr>
<tr>
<td>D</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>I need to get the number of repetitions of each count. Means desired outcome below,</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>count</th>
<th>numberOfTimes</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>I know the sql query would be</p>
<pre><code>SELECT DISTINCT COUNT(*) AS count,
COUNT(*) OVER (PARTITION BY COUNT(*)) AS numberOfTimes FROM tablename GROUP BY Name;
</code></pre>
<p>But I am not sure how to write this in LINQ</p>
| [
{
"answer_id": 74338584,
"author": "HappyDev",
"author_id": 16775611,
"author_profile": "https://Stackoverflow.com/users/16775611",
"pm_score": 2,
"selected": true,
"text": "setState"
},
{
"answer_id": 74338820,
"author": "Samer Murad",
"author_id": 2252297,
"author_profile": "https://Stackoverflow.com/users/2252297",
"pm_score": 0,
"selected": false,
"text": "setState"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3675978/"
] |
74,338,540 | <p>I'm new to python and I want to calculate the sum of the daily average temperatures on many hours and then append it to the dataframe e.g :</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>date</th>
<th>Temperature</th>
</tr>
</thead>
<tbody>
<tr>
<td>2015-04-01 00:00:00</td>
<td>3.9</td>
</tr>
<tr>
<td>2015-04-01 01:00:00</td>
<td>2.10</td>
</tr>
<tr>
<td>2015-04-01 02:00:00</td>
<td>4.8</td>
</tr>
<tr>
<td>⋮</td>
<td>⋮</td>
</tr>
<tr>
<td>2015-10-31 23:00:00</td>
<td>2.16</td>
</tr>
</tbody>
</table>
</div>
<p>I'm trying to get this output:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>date</th>
<th>Temperature</th>
<th>averageT</th>
</tr>
</thead>
<tbody>
<tr>
<td>2015-04-01 00:00:00</td>
<td>3.9</td>
<td>5</td>
</tr>
<tr>
<td>2015-04-01 01:00:00</td>
<td>2.10</td>
<td>5</td>
</tr>
<tr>
<td>2015-04-01 02:00:00</td>
<td>4.8</td>
<td>5</td>
</tr>
<tr>
<td>⋮</td>
<td>⋮</td>
<td></td>
</tr>
<tr>
<td>2015-10-31 23:00:00</td>
<td>2.16</td>
<td>7</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74338584,
"author": "HappyDev",
"author_id": 16775611,
"author_profile": "https://Stackoverflow.com/users/16775611",
"pm_score": 2,
"selected": true,
"text": "setState"
},
{
"answer_id": 74338820,
"author": "Samer Murad",
"author_id": 2252297,
"author_profile": "https://Stackoverflow.com/users/2252297",
"pm_score": 0,
"selected": false,
"text": "setState"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20433741/"
] |
74,338,597 | <p>I have a single record with column (type) containing an array of values, e.g. [Map,Table,Pie]</p>
<p>Using Athena I need to to flatten this record into 3 separate records each with one value from the array in the (type) column.</p>
<pre><code>SELECT type
FROM
athenadb.table,
UNNEST(type) as charttyp
</code></pre>
<p>This is the result of this query, three identical records.</p>
<pre><code>1 [Map, Pie, Table]
2 [Map, Pie, Table]
3 [Map, Pie, Table]
</code></pre>
<p>What am I missing here ? Clearly on one hand it recognizes the array length = 3 but does not parse the array elements...</p>
| [
{
"answer_id": 74338584,
"author": "HappyDev",
"author_id": 16775611,
"author_profile": "https://Stackoverflow.com/users/16775611",
"pm_score": 2,
"selected": true,
"text": "setState"
},
{
"answer_id": 74338820,
"author": "Samer Murad",
"author_id": 2252297,
"author_profile": "https://Stackoverflow.com/users/2252297",
"pm_score": 0,
"selected": false,
"text": "setState"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/491439/"
] |
74,338,623 | <p>Let's say that I have multiple files such as:</p>
<pre><code>root.file991
root.file81
root.file77
root.file989
</code></pre>
<p>If I want to delete all of them, I would need to use a regex first, so I have tried:</p>
<pre><code>find ./ - regex '\.\/root'
</code></pre>
<p>...which would find everything in root file, but how do I filter all these specific files?</p>
| [
{
"answer_id": 74338664,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 3,
"selected": true,
"text": "find ./ -regextype posix-extended -regex '\\./root\\.file[0-9]+'\n"
},
{
"answer_id": 74338739,
"author": "Greg A. Woods",
"author_id": 816536,
"author_profile": "https://Stackoverflow.com/users/816536",
"pm_score": 2,
"selected": false,
"text": "glob(7)"
},
{
"answer_id": 74338953,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "$ man find"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107424/"
] |
74,338,627 | <p>I am trying to split a string with " "(space) and assigning each value on row to each respective array.</p>
<p>The input file contains:</p>
<pre><code>4
2 2
1 3
4 7
3 4
</code></pre>
<p>The first line of the file has a single integer value <code>N</code> which is number of jobs.</p>
<p>The next <code>N</code> lines will represent a job, each with 2 values.</p>
<p>How do I start reading from second line from a Input file?</p>
<p>I want to split from Second line and assign it to 2D array. So if (2,2) is there on second line, then 2 should be assigned to <code>array[0][0]</code> and the other 2 to <code>array[0][1]</code>. For next line 1 should be assigned to <code>array[1][0]</code> and 3 should be assigned to <code>array[1][1]</code>.</p>
<pre class="lang-java prettyprint-override"><code>int num = scan.nextInt(); // taking number of jobs from first line
int[][] array = new int[num][num];
while (scan.hasNext()) //It reads till file has next line
{
String str = scan.nextLine();
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
array[i][j] = scan.nextInt();
}
}
}
</code></pre>
<p>Had done till here, couldn't figure out further.</p>
| [
{
"answer_id": 74338664,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 3,
"selected": true,
"text": "find ./ -regextype posix-extended -regex '\\./root\\.file[0-9]+'\n"
},
{
"answer_id": 74338739,
"author": "Greg A. Woods",
"author_id": 816536,
"author_profile": "https://Stackoverflow.com/users/816536",
"pm_score": 2,
"selected": false,
"text": "glob(7)"
},
{
"answer_id": 74338953,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "$ man find"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20434140/"
] |
74,338,662 | <p>I am working with the following table:</p>
<p><code>Var1</code> is of the format location.transport type. Therefore, <code>A.land</code> means location <code>A</code>, transport type <code>land</code>. Frequency is simply the number of times a location used the respective transport_type. <code>Location_ID</code> and <code>Transport_Type</code> were created in Stata by splitting <code>Var1</code>.</p>
<pre><code>| Var1 | Frequency | Location_ID | Transport_Type|
|---- |---- | ----- | ----- |
| A.land | 4 | A |land |
| A.air | 3 | A |air |
| A.sea | 2 | A |sea |
| B.sea | 5 | B |sea |
| B.other | 2 | B |other |
| B.land | 2 | B |land |
| C.land | 1 | C |land |
| C.air | 3 | C |air |
| C.other | 1 | C |other |
</code></pre>
<p>The goal is to find the distribution of the types of transports from each location A, B, and C.
I wish to create four variables: Proportion_land, Proportion_sea, Proportion_air, and Proportion_other.</p>
<p>For example, for location A I would want to create something like this:</p>
<pre><code>Location |Proportion_land| Proportion_sea | Proportion_air | Proportion_other|
|---- |---- |------ | ----- |----- |
|A | 4/9 | 3/9 | 2/9 |0 |
</code></pre>
| [
{
"answer_id": 74338664,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 3,
"selected": true,
"text": "find ./ -regextype posix-extended -regex '\\./root\\.file[0-9]+'\n"
},
{
"answer_id": 74338739,
"author": "Greg A. Woods",
"author_id": 816536,
"author_profile": "https://Stackoverflow.com/users/816536",
"pm_score": 2,
"selected": false,
"text": "glob(7)"
},
{
"answer_id": 74338953,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "$ man find"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19403138/"
] |
74,338,670 | <pre><code>import tkinter as tk
from subprocess import check_call
def copy_name():
cmd = 'echo ' + name.strip() + '|clip'
return check_call(cmd, shell=True)
root = tk.Toplevel(background="black")
root.title("Copying")
root.resizable(False, False)
T = tk.Label(root, text=name, height=2, width=len(name) + 25, background="black", foreground="white")
T.pack()
button = tk.Button(root, text="Copy", command=copy_name, background="black", foreground="white")
button.pack()
tk.mainloop()
</code></pre>
<p>This is my code.</p>
<p>I just wanted to test this way of copying text...</p>
<p>About my expectations... i want to understand from where those windows are appearing, and how to stop it.
Im just a newbie in Python and Tkinter... so please, tell me what i did wrong</p>
| [
{
"answer_id": 74338664,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 3,
"selected": true,
"text": "find ./ -regextype posix-extended -regex '\\./root\\.file[0-9]+'\n"
},
{
"answer_id": 74338739,
"author": "Greg A. Woods",
"author_id": 816536,
"author_profile": "https://Stackoverflow.com/users/816536",
"pm_score": 2,
"selected": false,
"text": "glob(7)"
},
{
"answer_id": 74338953,
"author": "TheAnalogyGuy",
"author_id": 6317990,
"author_profile": "https://Stackoverflow.com/users/6317990",
"pm_score": 0,
"selected": false,
"text": "$ man find"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20434184/"
] |
74,338,685 | <p>I am trying to implement Huffman compression and decompression of files, where all the information needed to decompress must be included in the compressed file. For this implementation I want to include the frequency table in the compressed file, such that the decompression program can rebuild the Huffman codes from this frequency table and then decompress the file. The frequency table looks something like this, where each index maps to an ASCII-character's decimal representation:</p>
<p><code>[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 847, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4183, 13, 0, 0, 0, 6, 0, 0, 26, 26, 0, 107, 84, 598, 124, 36, 72, 66, 42, 21, 8, 16, 9, 11, 10, 10, 46, 0, 0, 7, 0, 3, 0, 21, 30, 4, 20, 19, 30, 5, 34, 35, 0, 9, 19, 15, 7, 10, 9, 0, 8, 15, 19, 1, 9, 8, 2, 1, 8, 24, 29, 24, 23, 8, 0, 439, 189, 40, 252, 1514, 226, 241, 82, 462, 62, 353, 346, 306, 521, 436, 212, 0, 977, 512, 663, 100, 176, 24, 10, 53, 9, 23, 374, 23, 2, 0, 197, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 90, 0, 124, 0, 0, 75, 14, 0, 0, 49, 0, 33, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 34, 0, 0, 0, 0, 0, 0, 157, 154, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]</code></p>
<p>I.e., index 32 of the list is 4183, which tells me that SPACE (ASCII# 32) appears 4183 times in the compressed file.</p>
<p>I also have code in place to create the Huffman codes and convert each character into its Huffman code and append it to a long bitstring. The following code is functional, and it converts the bitstring into a byte-array and saves it as a binary-file:</p>
<pre class="lang-py prettyprint-override"><code>byte_array = bytearray()
for i in range(0, len(bitstring), 8):
byte = bitstring[i:i + 8]
byte_array.append(int(byte, 2))
with open(output_file_path, "wb") as compressed_file:
compressed_file.write(bytes(byte_array))
</code></pre>
<p>The resulting binary file is compressed from 17 KB to 10 KB successfully.</p>
<p>My problem is trying to include the frequency table at the beginning of this compressed file. I have tried several solutions but I run into problems and feel quite stuck.</p>
<p>Is there a simple way to include a frequency table such as above to the beginning of a compressed file in Python? Any tips for methods or functions that can be used to achieve this would be greatly appreciated.</p>
<p>I would want to achieve this with the frequency-table as-is and not using a Canonical Huffman code. And again, the compressed file alone and no other information must be enough to decompress the file without loss.</p>
<p>I have tried several function and methods that I find, but I am quite new to working with bytes and every method I have tried, such as converting the list to a bytearray, have failed. Because the list includes integers > 255 it won't convert to a byte-array like the bitstring does.</p>
<p>EDIT:</p>
<p>I am now sending the Huffman tree instead of the frequency table as suggested, but the tree is not rebuilt completely as it should be. Most of the leaf nodes are placed in the correct spot, but not all.</p>
<p>The following code creates the Huffman codes and at the same time creates the bitstring representing the Huffman tree:</p>
<pre class="lang-py prettyprint-override"><code>def __create_huffman_codes(self, current_node, current_huffman_code):
if not current_node:
return
self.huffman_tree_binary += "0"
if current_node.char:
self.huffman_tree_binary += "1"
self.huffman_tree_binary += bin(current_node.char)[2:].rjust(8, "0")
self.huffman_codes[current_node.char] = current_huffman_code
self.__create_huffman_codes(current_node.left, current_huffman_code + "0")
self.__create_huffman_codes(current_node.right, current_huffman_code + "1")
</code></pre>
<p>This method is called in the main method of the class as so:</p>
<pre class="lang-py prettyprint-override"><code>huffman_tree_root = self.huffman_tree.pop()
current_huffman_code = ""
self.__create_huffman_codes(huffman_tree_root, current_huffman_code)
self.huffman_tree_binary += "00"
</code></pre>
<p>I add two trailing zeroes because the binary representation of the Huffman tree always ended up at 350.75 bytes.</p>
<p>The method to create the bytes for compression is updated:</p>
<pre class="lang-py prettyprint-override"><code>def __create_bytes(self, bitstring):
byte_array = bytearray()
for i in range(0, len(self.huffman_tree_binary), 8):
byte = self.huffman_tree_binary[i:i + 8]
byte_array.append(int(byte, 2))
for i in range(0, len(bitstring), 8):
byte = bitstring[i:i + 8]
byte_array.append(int(byte, 2))
return byte_array
</code></pre>
<p>And then the bytes are written to a binary file.</p>
<p>On the other side, to rebuild the tree, I call the following method:</p>
<pre class="lang-py prettyprint-override"><code>def huffman_decompress(self):
[... open file ...]
[... read bytes ...]
if self.huffman_tree_binary.pop(0) == "0":
self.huffman_tree_root = Node(None)
self.huffman_tree_root.left = Node(None)
self.huffman_tree_root.right = Node(None)
self.__rebuild_huffman_tree(self.huffman_tree_root.left)
self.__rebuild_huffman_tree(self.huffman_tree_root.right)
[... decompression ...]
def __rebuild_huffman_tree(self, current_node):
if len(self.huffman_tree_binary) == 0:
return
self.huffman_tree_binary.pop(0)
if self.huffman_tree_binary[0] == "1":
self.huffman_tree_binary.pop(0)
bits = ""
for _ in range(8):
bits += self.huffman_tree_binary.pop(0)
current_node.char = int(bits, 2)
else:
current_node.left = Node(None)
current_node.right = Node(None)
self.__rebuild_huffman_tree(current_node.left)
self.__rebuild_huffman_tree(current_node.right)
</code></pre>
<p>This is surely not the most elegant implementation to recursively rebuild the tree, but I can't figure out why a fraction of the leaf nodes end up at different locations in the tree. I figure (naturally) there must be something wrong with how I build the binary representation pre-compression, or how I rebuild the tree, but I haven't figured out which one might be wrong yet.</p>
| [
{
"answer_id": 74338972,
"author": "PieCot",
"author_id": 5359797,
"author_profile": "https://Stackoverflow.com/users/5359797",
"pm_score": 0,
"selected": false,
"text": "FREQ_TABLE_LEN = 256\n\ndef write_frequency_table(f, table):\n assert len(table) == FREQ_TABLE_LEN\n for e in table:\n f.write(e.to_bytes(4, byteorder='little', signed=False))\n\ndef read_frequency_table(f):\n read_table = []\n for _ in range(FREQ_TABLE_LEN):\n data = f.read(4)\n number = int.from_bytes(data, 'little', signed=False)\n read_table.append(number)\n return read_table\n"
},
{
"answer_id": 74339336,
"author": "Mark Adler",
"author_id": 1180620,
"author_profile": "https://Stackoverflow.com/users/1180620",
"pm_score": 3,
"selected": true,
"text": "0"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15363376/"
] |
74,338,709 | <p>I have this HTML script:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles/login.css">
</head>
<body>
<div class="mb-3">
<h3>Welcome, Please register with Us</h3>
<form action="" method="post">
<img src="images/login.png" alt="Login" width="100" height="80">
<br>
<b>Full name</b>
<br>
<input type="text" id="fullname" class="form-control" name="txtFullName" placeholder="John Watson" required>
<br>
<b>User Name</b>
<br>
<input type="text" id="username" class="form-control" name="txtUserName" placeholder="john@example.com" required>
<br>
<b>Password</b>
<br>
<input type="password" id="first_pass" class="form-control" name="txtpassword" placeholder="minimum 6 characters" required>
<br>
<b>Repeat Password</b>
<br>
<input type="password" id="second_pass" class="form-control" name="txtpassword" placeholder="minimum 6 characters" required>
<script src="scripts/register.js"></script>
<br>
<input type="checkbox" checked="checked" name="rememberMe">Remember Me
<br>
<input type="submit" value="REGISTER" onclick="verifyid()">
</form>
<div id="output"></div>
</body>
</html>
</code></pre>
<p>The JS script is:</p>
<pre><code>function verifyid (){
str1 = document.getElementById("first_pass").value;
str2 = document.getElementById("second_pass").value;
if (str1 == str2) {
displayOutput = "You are our new user";
} else {
displayOutput = "The passwords do not match";
}
document.getElementById('output').innerHTML = displayOutput;
}
</code></pre>
<p>Also, the CSS script is not really important, so I will not include it.</p>
<p>When I run the HTML file, the JS function works great, also the message is printed correctly. My problem is that when I click "register," the form is emptied (as it should); however, the JS message print is also deleted. It happens so fast that there is no anyone can read JS function message.</p>
<p>Is there a way to allow the form to the emptied (as it should), but keep the message at the bottom?</p>
<p>This pic shows how I would like the message and HTML page displayed if the user did not type the same passwords.</p>
<p><a href="https://i.stack.imgur.com/EPKEu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EPKEu.png" alt="HTML output" /></a></p>
| [
{
"answer_id": 74338972,
"author": "PieCot",
"author_id": 5359797,
"author_profile": "https://Stackoverflow.com/users/5359797",
"pm_score": 0,
"selected": false,
"text": "FREQ_TABLE_LEN = 256\n\ndef write_frequency_table(f, table):\n assert len(table) == FREQ_TABLE_LEN\n for e in table:\n f.write(e.to_bytes(4, byteorder='little', signed=False))\n\ndef read_frequency_table(f):\n read_table = []\n for _ in range(FREQ_TABLE_LEN):\n data = f.read(4)\n number = int.from_bytes(data, 'little', signed=False)\n read_table.append(number)\n return read_table\n"
},
{
"answer_id": 74339336,
"author": "Mark Adler",
"author_id": 1180620,
"author_profile": "https://Stackoverflow.com/users/1180620",
"pm_score": 3,
"selected": true,
"text": "0"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7705108/"
] |
74,338,744 | <p>Sorry, i am completely new to VHDL, and i have these problems, i have read smth in the internet about it, someone told that i shoud complile some entity files too, but i have just one entity file. I have to make RTL simulation of boolean function using structural model of the architecture, so, there are my 4 problems<br />
Aslo i read that i need to make new files for smth, but i do not know for what and what has to be in it</p>
<pre><code>Error (12006): Node instance "x1" instantiates undefined entity "AND1"
Error (12006): Node instance "x2" instantiates undefined entity "AND1"
Error (12006): Node instance "x3" instantiates undefined entity "AND1"
Error (12006): Node instance "x4" instantiates undefined entity "OR1"
</code></pre>
<p>And also there is my code:</p>
<pre><code>ibrary ieee;
use ieee.std_logic_1164.all;
entity test_logic is
port(
a, b, c, d : in std_logic;
g : out std_logic
);
end test_logic;
architecture structure of test_logic is
component AND1
port(s, t : in std_logic;
u : out std_logic
);
end component;
component OR1
port(x, y, z : in std_logic;
n : out std_logic
);
end component;
signal e, f, h : std_logic;
begin
x1: AND1 port map(s => not(a),
t => not(d),
u => e);
x2: AND1 port map(s => not(b),
t => not(d),
u => f);
x3: AND1 port map(s => a,
t => d,
u => h);
x4: OR1 port map(x => e,
y => f,
z => h,
n => g);
end structure;
</code></pre>
<p>I have tried to change main entity name, but it didn`t help at all, so i am completely clueless what i have to do.</p>
| [
{
"answer_id": 74338972,
"author": "PieCot",
"author_id": 5359797,
"author_profile": "https://Stackoverflow.com/users/5359797",
"pm_score": 0,
"selected": false,
"text": "FREQ_TABLE_LEN = 256\n\ndef write_frequency_table(f, table):\n assert len(table) == FREQ_TABLE_LEN\n for e in table:\n f.write(e.to_bytes(4, byteorder='little', signed=False))\n\ndef read_frequency_table(f):\n read_table = []\n for _ in range(FREQ_TABLE_LEN):\n data = f.read(4)\n number = int.from_bytes(data, 'little', signed=False)\n read_table.append(number)\n return read_table\n"
},
{
"answer_id": 74339336,
"author": "Mark Adler",
"author_id": 1180620,
"author_profile": "https://Stackoverflow.com/users/1180620",
"pm_score": 3,
"selected": true,
"text": "0"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338744",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17412150/"
] |
74,338,762 | <p>Im trying to echo whole modal with data from db. I want to use my other functions "getLocations and getdescriptions" in my new function. But... Html shows those functions as comments
"<<em>!--?php echo getLocations(); ?--</em>> & <!<em>--?php echo getdescriptions(); ?--</em>>". How I can make these echos to work.</p>
<p>Code is not complete, so there is possible many problems, but this echo is my problem right now.</p>
<pre><code>$output .= "
<tr data-toggle='modal' data-target='#startWorkTime".$location_row['name'].gmdate("j", $start_day)."' href=''>
<td class='column7'>".gmdate("j", $start_day).".".gmdate("n", $start_day).".".gmdate("Y", $start_day)."</td>
<td class='column7'>".$location_row['name']."</td>
<td class='column7'><a href='https://www.w3schools.com/'>".$row['msg']."</a></td>
<td class='column7'>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</td>
</tr>
<div class='modal text-center fade' id='startWorkTime".$location_row['name'].gmdate("j", $start_day)."' >
<div class='modal-dialog modal-dialog-centered' style='min-width:50%' >
<div class='modal-content' style='background-color: #fff; border-radius: 10px; border: none; padding: 0; box-shadow: 0 0.46875rem 2.1875rem rgba(90,97,105,0.1), 0 0.9375rem 1.40625rem rgba(90,97,105,0.1), 0 0.25rem 0.53125rem rgba(90,97,105,0.12), 0 0.125rem 0.1875rem rgba; color: #fff; background-color: rgb(255, 255, 255);'>
<div class='modal-body'>
<button type='button' class='close text-danger' data-dismiss='modal'>&times;</button>
<div class=' text-dark'>
<form class='form-card' action='work_time.php' method='post'>
<div class='row justify-content-between text-left'>
<div class='form-group col-sm-12 flex-column d-flex'>
<h6>".$row['start']." ASD ".$row['stop']."Merkinnän id: ".$row['id']."</h6>
</div><div class='form-group col-sm-12 flex-column d-flex'>
<label class='form-control-label px-3'><b>Tiedot</b> <i>Muokkaa klikkaamalla</i></label>
<div style='margin-left: 5px;margin-right: 5px;'>
<br>
<div class='form-group col-sm-10 flex-column d-flex' >
<label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Aloitus</b></label>
<input style='padding-left: 20px;padding-right: 20px;' type='datetime-local' name='startdatetime' value='".date('Y-m-d', strtotime($row['start_date']))."T".date('H:i', strtotime($row['start']))."' >
</div>
<div class='form-group col-sm-10 flex-column d-flex' >
<label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Lopetus</b></label>
<input style='padding-left: 20px;padding-right: 20px;' type='datetime-local' name='stopdatetime' value='".date('Y-m-d', strtotime($row['stop_date']))."T".date('H:i', strtotime($row['stop']))."'>
<br>
<h6>Tunnit yhteensä: <b>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</b></h6>
</div>
<div class='form-group col-sm-10 flex-column d-flex'>
<label class='form-control-label px-3'><b>Työkohde</b></label>
<div style='margin-left: 5px;margin-right: 5px;'> **<?php echo getLocations(); ?>**
<div id='newLocation'>
<br>
<input class='mb-3' style='width: 100%;' name='new_location' placeholder='Uusi työkohde...'/>
</div>
</div>
</div>
<div class='form-group col-sm-10 flex-column d-flex' >
<label class='form-control-label px-3'><b>Työnkuva</b></label>
<div style='margin-left: 5px;margin-right: 5px;'> **<?php echo getdescriptions(); ?> **
<div id='newLocation'><br> <input style='width: 100%;' name='new_description' placeholder='Uusi työnkuva...'/></div>
</div> </div> <div class='form-group col-sm-10 flex-column d-flex' >
<label class='form-control-label px-3'><b>Viesti</b></label>
<div style='margin-left: 5px;margin-right: 5px;'>
<input style='width: 100%;' name='new_description' value='Jotta voidaan tulostaa viestit'>
</div>
</div>
<br>
</div>
</div>
<input type='hidden' name='action' value='start' />
<input type='hidden' name='msg' value='' />
</div>
<div class='row d-flex p-2 '>
<div class='col justify-content-around'>
<button type='submit' class='btn btn-success float-left' name='submit' value='Tallenna'><b>Tallenna</b></button>
<button type='submit' class='btn btn-danger float-right' name='submit' value='Tallenna'><b>Poista</b></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>";
</code></pre>
<p>How I can prevent to html shows those functions as comments
"<!<em>--?php echo getLocations(); ?--</em>> & <!<em>--?php echo getdescriptions(); ?--</em>>".</p>
| [
{
"answer_id": 74338972,
"author": "PieCot",
"author_id": 5359797,
"author_profile": "https://Stackoverflow.com/users/5359797",
"pm_score": 0,
"selected": false,
"text": "FREQ_TABLE_LEN = 256\n\ndef write_frequency_table(f, table):\n assert len(table) == FREQ_TABLE_LEN\n for e in table:\n f.write(e.to_bytes(4, byteorder='little', signed=False))\n\ndef read_frequency_table(f):\n read_table = []\n for _ in range(FREQ_TABLE_LEN):\n data = f.read(4)\n number = int.from_bytes(data, 'little', signed=False)\n read_table.append(number)\n return read_table\n"
},
{
"answer_id": 74339336,
"author": "Mark Adler",
"author_id": 1180620,
"author_profile": "https://Stackoverflow.com/users/1180620",
"pm_score": 3,
"selected": true,
"text": "0"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20434189/"
] |
74,338,788 | <p>I'm building an animation tool that uses Web Animations API, the problem that I have is that every time I play the animation, I'm actually creating a new animation, so if I do console.log(el.getAnimations()) it will return an array with multiple animations, but I'm using only the last one, and this of course is wasting a lot of memory. How can I reuse or delete the first animation?</p>
<p>To animate elements I do this:</p>
<pre><code> function play(){
el?.animate(el.kfs, {
duration: duration.value,
delay: -currentTime.value,
iterations: Infinity,
composite: "replace",
})
}
</code></pre>
<p>and to pause the animation I do this:</p>
<pre><code>function pause(){
el?.getAnimations().forEach(anim => anim?.pause()
}
</code></pre>
<p>Here is a simple working example:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const el = document.getElementById('el')
function playAnim(){
el.animate(
[{backgroundColor:'red'}, {backgroundColor:'black'}],
{
duration: 1000,
iterations: Infinity
})
}
playAnim()
el.getAnimations()[0].pause()
playAnim()
console.log(el.getAnimations().length) // will output 2</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="el">el</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74339052,
"author": "imvenx",
"author_id": 11740131,
"author_profile": "https://Stackoverflow.com/users/11740131",
"pm_score": 1,
"selected": true,
"text": "const el = document.getElementById('el');\nconst kfs = [{backgroundColor:'red'}, {backgroundColor:'black'}];\n\nfunction playAnim(){\n let anim = el.getAnimations()[0];\n if(anim){\n let eff = anim.effect;\n eff.setKeyframes(kfs);\n anim.play();\n }else{\n el.animate(kfs,\n {\n duration: 1000,\n iterations: Infinity\n });\n }\n }\n \n playAnim()\n el.getAnimations()[0].pause()\n playAnim()\n console.log(el.getAnimations().length)"
},
{
"answer_id": 74341041,
"author": "Kaiido",
"author_id": 3702797,
"author_profile": "https://Stackoverflow.com/users/3702797",
"pm_score": 1,
"selected": false,
"text": "cancel()"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11740131/"
] |
74,338,803 | <p>I have problem with displaying data using *ngFor:</p>
<p>Auction object contains array of Bids.</p>
<pre><code>export interface Auction {
descripton: string;
sellerId: string;
title: string;
price: number;
quantity: number;
bids: Bid[];
boughtByList: string[];
photoAlbum: PhotoAlbumModel;
auctionType: string;
starts: Date;
ends: Date;
comments: Comment[];
}
</code></pre>
<pre><code>export class Bid {
constructor(public amount: number, public userName: string, public productTitle: string) {
}
}
</code></pre>
<p>I getting auction data in AuctionDetailsComponent</p>
<pre><code>export class AuctionDetailsComponent implements OnInit, OnDestroy {
private title: string;
auction: Auction;
bid: Bid;
bidResponse: BidResponse;
highestBid: number;
coins: number;
private paramsSubscription: Subscription;
imageObjects: Array<object> = [];
constructor(private router: Router,
private activatedRoute: ActivatedRoute,
private productService: ProductService,
private cartService: CartService,
private authService: AuthenticationService,
private auctionService: AuctionService) {
}
ngOnInit(): void {
this.paramsSubscription = this.activatedRoute.params
.subscribe((params: Params) => {
this.title = params.title;
this.getAuction(this.title);
});
}
getAuction(title: string) {
this.auctionService
.get(title)
.subscribe((auction) => {
this.auction = auction;
this.setImageObject();
});
}
</code></pre>
<p>In auction-details.component.html I try to display Bid data using *ngFor</p>
<pre><code><div *ngFor="let bid of auction.bids">
<p>{{bid.userName}}</p>
</div>
</code></pre>
<p>Paragraphs are empty but in chrome debug there is a array.</p>
<p><a href="https://i.stack.imgur.com/luYOY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/luYOY.png" alt="enter image description here" /></a></p>
<p>and other Auction data - title, price displaying fine.</p>
<p>I don't know where is the problem.</p>
| [
{
"answer_id": 74339542,
"author": "Eli Porush",
"author_id": 14598976,
"author_profile": "https://Stackoverflow.com/users/14598976",
"pm_score": 1,
"selected": false,
"text": "subscribing"
},
{
"answer_id": 74344042,
"author": "wesky77",
"author_id": 20434225,
"author_profile": "https://Stackoverflow.com/users/20434225",
"pm_score": 0,
"selected": false,
"text": " ngOnInit(): void {\n this.paramsSubscription = this.activatedRoute.params\n .subscribe((params: Params) => {\n this.title = params.title;\n this.getAuction(this.title);\n console.log(this.getAuction(this.title)); // undefined \n });\n }"
},
{
"answer_id": 74344552,
"author": "wesky77",
"author_id": 20434225,
"author_profile": "https://Stackoverflow.com/users/20434225",
"pm_score": 0,
"selected": false,
"text": "async ngOnInit(): Promise<void> {\n const params = await lastValueFrom(this.activatedRoute.params);\n this.title = params.title;\n this.auction$ = this.auctionService.get(this.title);\n }"
},
{
"answer_id": 74344990,
"author": "wesky77",
"author_id": 20434225,
"author_profile": "https://Stackoverflow.com/users/20434225",
"pm_score": 0,
"selected": false,
"text": " <div>\n <p>{{this.bids[0].userName}}</p>\n </div>"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20434225/"
] |
74,338,806 | <p>I am trying to create a grid-layout like:
<a href="https://i.stack.imgur.com/421Lw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/421Lw.png" alt="enter image description here" /></a></p>
<p>I do not want to use any <code>frameworks</code> or <code>apis</code> online and want to accomplish this using <code>pure CSS, HTML</code> and <code>JS</code> if needed. Here's what I tried:</p>
<pre><code><div class="grid">
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>
</code></pre>
<pre><code>.grid{
width: 70%;
margin: auto;
margin-top: 120px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-template-rows: 200px 100px;
grid-gap: 1rem;
}
.grid-item{
background-color: #1EAAFC;
background-image: linear-gradient(130deg, #6C52D9 0%, #1EAAFC 85%, #3EDFD7 100%);
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
color: #fff;
border-radius: 4px;
grid-column: span 2;
border: 6px solid #171717;
}
</code></pre>
<p>However, this leads me to:
<a href="https://i.stack.imgur.com/fEe6g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fEe6g.png" alt="enter image description here" /></a></p>
<p>Any help is appreciated!</p>
| [
{
"answer_id": 74339229,
"author": "WhiteToggled",
"author_id": 20067906,
"author_profile": "https://Stackoverflow.com/users/20067906",
"pm_score": 2,
"selected": true,
"text": "grid-template-areas"
},
{
"answer_id": 74339283,
"author": "liquidot",
"author_id": 20400911,
"author_profile": "https://Stackoverflow.com/users/20400911",
"pm_score": 0,
"selected": false,
"text": "<div class=\"gridprimary\">\n <div class=\"gridprimary1\">\n <div class=\"grid\">\n <div class=\"grid-item\"></div>\n </div>\n </div>\n\n <div class=\"gridprimary1\">\n <div class=\"grid\">\n <div class=\"grid-item\"></div>\n </div>\n </div>\n</div>\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15042008/"
] |
74,338,853 | <p>I am creating a data class in kotlin as such</p>
<pre><code>
data class User(val name: String, val age: Int)
{
constructor(name: String, age: Int, size: String): this(name, age) {
}
}
</code></pre>
<p>In my main function, I can access the objects as such:</p>
<pre><code>fun main(){
val x = User("foo", 5, "M")
println(x.name)
println(x.age)
println(x.size) // does not work
}
</code></pre>
<p>My problem is that I can't get access to <code>size</code>.</p>
<p>What I am trying to do is, create a <code>data class</code> where top level params are the common items that will be accessed, and in the constructors, have additional params that fit certain situations. The purpose is so that I can do something like</p>
<pre><code>// something along the lines of
if (!haveSize()){
val person = User("foo", 5, "M")
} else {
val person = User("foo", 5)
}
}
</code></pre>
<p>Any ideas?</p>
| [
{
"answer_id": 74339009,
"author": "Xəyal Şərifli",
"author_id": 20432696,
"author_profile": "https://Stackoverflow.com/users/20432696",
"pm_score": 0,
"selected": false,
"text": "data class User(var name: String, var age: Int) {\n\n var size: String\n\n init {\n size = \"size\"\n }\n\nconstructor(name: String, age: Int, size: String) : this(name, age) {\n this.size = size\n }\n}\n"
},
{
"answer_id": 74340197,
"author": "Hubert Grzeskowiak",
"author_id": 2445864,
"author_profile": "https://Stackoverflow.com/users/2445864",
"pm_score": 2,
"selected": false,
"text": "\ndata class User(val name: String, val age: Int, val size: String = \"M\")\n"
},
{
"answer_id": 74343932,
"author": "aSemy",
"author_id": 4161471,
"author_profile": "https://Stackoverflow.com/users/4161471",
"pm_score": 0,
"selected": false,
"text": "MountDetails"
},
{
"answer_id": 74346751,
"author": "David Soroko",
"author_id": 239101,
"author_profile": "https://Stackoverflow.com/users/239101",
"pm_score": 0,
"selected": false,
"text": "data class OneDetails(val c: Int)\ndata class TwoDetails(val c: String)\ndata class MountOptions(val a: String, val b: String)\n\ndata class User(\n val mountOptions: MountOptions,\n val detailsOne: OneDetails? = null,\n val detailsTwo: TwoDetails? = null\n)\n\nfun main() {\n fun anotherCaller(user: User) = println(user)\n \n val mt = MountOptions(\"foo\", \"bar\")\n val one = OneDetails(1)\n val two = TwoDetails(\"2\")\n\n val switch = \"0\"\n when (switch) {\n \"0\" -> anotherCaller(User(mt))\n \"1\" -> anotherCaller(User(mt, detailsOne = one))\n \"2\" -> anotherCaller(User(mt, detailsTwo = two))\n \"12\" -> anotherCaller(User(mt, detailsOne = one, detailsTwo = two))\n else -> throw IllegalArgumentException(switch)\n }\n}\n\n"
}
] | 2022/11/06 | [
"https://Stackoverflow.com/questions/74338853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4931657/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.