qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,380,646 | <p>I have a RecyclerView whose entries are CardViews. Each CardView contains a horizontal LinearLayout with 5 TextViews. No matter what I try, I cannot get the CardView to fill the width of the screen. The RecyclerView's width matches the parent container (the phone screen), and each CardView matches its parent's (the RecyclerView's) width. The design panel in Android Studio shows that the CardView should stretch to the edges of the screen, but it doesn't.</p>
<p>Here is the XML of the RecyclerView's layout:
`</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.example.weatherapp.home.HomeViewModel"/>
</data>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/locations_list"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:scrollbars="vertical"
app:listData="@{viewModel.locList}"/>
</layout>
</code></pre>
<p>`</p>
<p>And here is my XML for the layout of each item in the RecyclerView:
`</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="location"
type="com.example.weatherapp.entity.Entry" />
</data>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/cityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{location.cityName}" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:text="@{location.stateName}"
android:visibility="@{location.stateVisibility}" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:text="@{location.countryName}" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:text="@{location.fTemp}" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:text="@{location.weather}" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</layout>
</code></pre>
<p>`</p>
<p><strong>EDIT</strong>: I colored the CardView and RecylerView to show the clear boundries. The CardView is purple and the RecyclerView its in is the green-turquoise color.</p>
<p><a href="https://i.stack.imgur.com/0rzL5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0rzL5.png" alt="enter image description here" /></a></p>
<p>I have played around with the <code>android:layout_weight</code> settings of each TextView, setting them all to 1 and the <code>android:layout_width</code> of each to <code>0dp</code>, as per Google's LinearLayout documentation. This did not stretch the CardView to the edges of the screen, and only served to shrink each TextView down. My goal is for the CardView to stretch to the edges and for the 5 TextViews to be spaced evenly within.</p>
| [
{
"answer_id": 74380753,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 2,
"selected": true,
"text": "select t.title Trial_Name, Count(*) Num_Patients\nfrom Trials t\njoin Patients p on p.Trial_Id = t.Id\ngroup by t.title;\n"
},
{
"answer_id": 74380883,
"author": "anar1501",
"author_id": 14558434,
"author_profile": "https://Stackoverflow.com/users/14558434",
"pm_score": 0,
"selected": false,
"text": "SELECT trial.title AS Trial_Name, COUNT(p.id) AS Num_Patients\nFROM trial\nINNER JOIN patients AS p\nON trial.patient_fk_id = p.id\nGROUP BY trial.title,p.id;\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19011329/"
] |
74,380,658 | <p>I have a bytes array returned from a hardware module,
the len is:</p>
<pre><code>len(a)
51
</code></pre>
<p>when I display it in vscode or terminal, it shows:</p>
<blockquote>
<p>b'>128 143 134 135 141 139 134 120 137 135 132 143 \r\n'</p>
</blockquote>
<p>when I try to convert it to list:</p>
<pre><code> s = list(a.strip())
s[0]
62
s[1]
49
s[2]
50
s[3]
56
</code></pre>
<p>how could I convert list s to 12 integers shown in vscode or terminal?</p>
| [
{
"answer_id": 74380759,
"author": "tdelaney",
"author_id": 642070,
"author_profile": "https://Stackoverflow.com/users/642070",
"pm_score": 2,
"selected": true,
"text": "bytes"
},
{
"answer_id": 74381362,
"author": "Mark Setchell",
"author_id": 2836621,
"author_profile": "https://Stackoverflow.com/users/2836621",
"pm_score": 0,
"selected": false,
"text": "import re\n\nb = b'>128 143 134 135 141 139 134 120 137 135 132 143 \\r\\n'\n\nl = [int(x) for x in re.findall(r'[0-9]+', str(b))]\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13021296/"
] |
74,380,661 | <p>I have one table (Bigquery), which has ', ' separated values in two columns:</p>
<pre><code> id tag_id tag_name
1 1, 2, 4 a, b, d
2 3 c
3 1, 4 a, d
</code></pre>
<p>For each tag_id is 1:1 matched with a tag_name. I want to split the comma separated values and convert them into rows. The ideal output is like:</p>
<pre><code>id tag_id tag_name
1 1 a
1 2 b
1 4 d
2 3 c
3 1 a
3 4 d
</code></pre>
<p>My working progress SQL:</p>
<pre><code>SELECT * EXCEPT(t, tn) REPLACE(t AS tag_id, tn AS tags_name)
FROM `table`,
UNNEST(SPLIT(tag_id, ', ')) t, UNNEST(SPLIT(tags_name, ', ')) tn
</code></pre>
<p>But it seems that tag_id is not 1:1 matched with tags_name... I'd like to use the <code>EXCEPT</code> in the select query as there are many other columns which I don't want to list them all out manually.</p>
| [
{
"answer_id": 74381144,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 3,
"selected": true,
"text": "select t.id, elt_id, elt_name\nfrom mytable t\ncross join unnest( split(t.tag_id, ', ') ) elt_id with offset as rn_id\ncross join unnest( split(t.tag_name, ', ') ) elt_name with offset as rn_name\nwhere rn_id = rn_name\n"
},
{
"answer_id": 74381912,
"author": "Rajat",
"author_id": 9947159,
"author_profile": "https://Stackoverflow.com/users/9947159",
"pm_score": 0,
"selected": false,
"text": "unnest"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8457035/"
] |
74,380,693 | <p>I have a similar question to this post: <a href="https://stackoverflow.com/questions/67156005/fill-in-values-between-start-and-end-value-in-r">Fill in values between start and end value in R</a></p>
<p>The difference is that I need to fill in values between the start and end of multiple values and it doesn’t contain and ID column:</p>
<p>My data look like this (Original data have many different values) :<a href="https://i.stack.imgur.com/aLu9Q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aLu9Q.jpg" alt="enter image description here" /></a></p>
<p>My final result should look like this : <a href="https://i.stack.imgur.com/gJJY7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJJY7.jpg" alt="enter image description here" /></a></p>
<p>Data :</p>
<pre><code>structure(list(elevation = c(150L,140L, 130L, 120L, 110L, 120L, 130L, 140L, 150L, 90L, 80L, 70L,66L, 60L, 50L, 66L, 70L, 72L, 68L, 65L, 60L, 68L, 70L),code = c(NA, NA, "W", NA, NA, NA, "W", NA, NA, NA, NA, NA, "X", NA, NA, "X", NA, NA, "Y", NA, NA, "Y", NA)), class = "data.frame", row.names = c(NA,-23L))
</code></pre>
<p>Thanks in advance</p>
| [
{
"answer_id": 74380847,
"author": "MrFlick",
"author_id": 2372064,
"author_profile": "https://Stackoverflow.com/users/2372064",
"pm_score": 2,
"selected": false,
"text": "codepos <- which(!is.na(dd$code))\nstopifnot(length(codepos)%%2==0)\nfor (group in split(codepos, (seq_along(codepos)+1)%/%2)) {\n stopifnot(dd$code[group[1]] == dd$code[group[2]])\n dd$code[group[1]:group[2]] <- dd$code[group[1]]\n}\n"
},
{
"answer_id": 74380917,
"author": "onyambu",
"author_id": 8380272,
"author_profile": "https://Stackoverflow.com/users/8380272",
"pm_score": 4,
"selected": true,
"text": "df %>% \n mutate(code = runner::fill_run(code, only_within = T))\n\n elevation code\n1 150 <NA>\n2 140 <NA>\n3 130 W\n4 120 W\n5 110 W\n6 120 W\n7 130 W\n8 140 <NA>\n9 150 <NA>\n10 90 <NA>\n11 80 <NA>\n12 70 <NA>\n13 66 X\n14 60 X\n15 50 X\n16 66 X\n17 70 <NA>\n18 72 <NA>\n19 68 Y\n20 65 Y\n21 60 Y\n22 68 Y\n23 70 <NA>\n"
},
{
"answer_id": 74380947,
"author": "Andre Wildberg",
"author_id": 9462095,
"author_profile": "https://Stackoverflow.com/users/9462095",
"pm_score": 1,
"selected": false,
"text": "tidyverse"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12322285/"
] |
74,380,703 | <p>I'm using the latest version of tailwind and I have a custom breakpoint, <code>xs:</code>, which is equal to 540px. When I use it like this: <code>h-[420px] xs:h-[400px] xl:h-[360px]</code> it works fine for mobile and the xs breakpoint, but the xl breakpoint no longer registers- the height is 400 even on desktop.</p>
<p>This is my config:</p>
<pre><code>theme: {
extend: {
screens: {
'xs': '540px',
...
</code></pre>
<p>Unfortunately, this works in the sandbox <a href="https://play.tailwindcss.com/Vqkh6ZTGdl" rel="nofollow noreferrer">here</a> and I'm not sure why it doesn't work on my local. I'm using Sveltekit (a version before the breaking changes), Ubuntu Linux and Chrome.</p>
| [
{
"answer_id": 74482565,
"author": "Idris Haslin",
"author_id": 9225297,
"author_profile": "https://Stackoverflow.com/users/9225297",
"pm_score": 0,
"selected": false,
"text": "const defaultTheme = require('tailwindcss/defaultTheme')\n\nmodule.exports = {\n theme: {\n screens: {\n 'xs': '475px',\n ...defaultTheme.screens,\n },\n },\n plugins: [],\n}"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11832959/"
] |
74,380,739 | <p>I am trying to translate on Microsoft Cognitive Service text with XML-like tags:</p>
<p><LABEL0>John</LABEL0> <LABEL1>Smith</LABEL1> is reading a <LABEL2>blue book</LABEL2>.</p>
<p>I am wondering if this is something that the NMT service would be able to handle and conserve tags in the translation?</p>
<p>Thanks</p>
| [
{
"answer_id": 74482565,
"author": "Idris Haslin",
"author_id": 9225297,
"author_profile": "https://Stackoverflow.com/users/9225297",
"pm_score": 0,
"selected": false,
"text": "const defaultTheme = require('tailwindcss/defaultTheme')\n\nmodule.exports = {\n theme: {\n screens: {\n 'xs': '475px',\n ...defaultTheme.screens,\n },\n },\n plugins: [],\n}"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15727016/"
] |
74,380,748 | <p>We were given an assignment in class to provide at the minimum two different solutions to find departments, which don't have any employees. As you can see from below I completed the task successfully.</p>
<p>An additional solution is extra credit, which I like to get. Unfortunately, I can't think of a third solution and was hoping someone can point me in the right direction. Would something with a MINUS function work?</p>
<p>Below is my setup and 2 working test cases. Any suggestions and help would be greatly appreciated.</p>
<pre><code>CREATE TABLE departments
(
department_id,
department_name
) AS
SELECT 1, 'IT' FROM DUAL UNION ALL
SELECT 3, 'Sales' FROM DUAL UNION ALL
SELECT 2, 'DBA' FROM DUAL;
CREATE TABLE employees
(
employee_id,
first_name, last_name,
hire_date,
salary,
department_id
) AS
SELECT 1, 'Lisa', 'Saladino', DATE '2001-04-03', 100000, 1 FROM DUAL UNION ALL
SELECT 2, 'Abby', 'Abbott', DATE '2001-04-04', 50000, 1 FROM DUAL UNION ALL
SELECT 3, 'Beth', 'Cooper', DATE '2001-04-05', 60000, 1 FROM DUAL UNION ALL
SELECT 4, 'Carol', 'Orr', DATE '2001-04-06', 70000,1 FROM DUAL UNION ALL
SELECT 5, 'Vicky', 'Palazzo', DATE '2001-04-07', 88000,2 FROM DUAL UNION ALL
SELECT 6, 'Cheryl', 'Ford', DATE '2001-04-08', 110000,1 FROM DUAL UNION ALL
SELECT 7, 'Leslee', 'Altman', DATE '2001-04-10', 66666, 1 FROM DUAL UNION ALL
SELECT 8, 'Jill', 'Coralnick', DATE '2001-04-11', 190000, 2 FROM DUAL UNION ALL
SELECT 9, 'Faith', 'Aaron', DATE '2001-04-17', 122000,2 FROM DUAL;
/* departments with no employees */
select
d.department_id,
d.department_name
from
employees e
right join
departments d on e.department_id = d.department_id
group by
d.department_id, d.department_name
having
count(e.employee_id) = 0;
</code></pre>
<p>Output:</p>
<pre><code>DEPARTMENT_ID DEPARTMENT_NAME
--------------------------------
3 Sales
</code></pre>
<pre><code>SELECT
d.department_id,
d.department_name
FROM
departments d
WHERE
NOT EXISTS (SELECT * FROM employees e
WHERE d.department_id = e.department_id)
</code></pre>
<p>Output:</p>
<pre><code>DEPARTMENT_ID DEPARTMENT_NAME
--------------------------------
3 Sales
</code></pre>
| [
{
"answer_id": 74380933,
"author": "ahmed",
"author_id": 12705912,
"author_profile": "https://Stackoverflow.com/users/12705912",
"pm_score": 3,
"selected": true,
"text": "select \n d.department_id,\n d.department_name\nfrom departments d left join employees e \non e.department_id=d.department_id\nwhere e.employee_id is null\n"
},
{
"answer_id": 74380945,
"author": "Ankit Bajpai",
"author_id": 3627756,
"author_profile": "https://Stackoverflow.com/users/3627756",
"pm_score": 1,
"selected": false,
"text": "SELECT * \n FROM departments\n WHERE department_id in (SELECT department_id\n FROM departments\n minus \n SELECT DISTINCT department_id\n FROM employees\n );\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16771377/"
] |
74,380,761 | <p>I have a table called AuditLogs that has a log of every single user action and their timestamp.</p>
<p>All these timestamp logs are recorded in UTC with a time offset of zero. While the actual users performing these actions are in California, with UTC-8.</p>
<p>I am trying to write a report with this data, and all the data needs to be in Californa time, to correctly contextualize when users are performing certain actions.</p>
<p>This is what my query looks like</p>
<pre><code>select distinct top 1000
Users.FirstName + ' ' + Users.LastName Name
,AuditRecords.username
,AuditRecords.subtype
,convert(varchar, timestamp at time zone 'Pacific Standard Time', 0) time
,timestamp
from
AuditRecords
join Users on AuditRecords.UserId = Users.Id
where
AuditRecords.subtype <> 'log%'
and DATEPART(dy,timestamp at time zone 'Pacific Standard Time') = datepart(dy,SYSDATETIMEOFFSET() at time zone 'Pacific Standard Time')-1
</code></pre>
<p>With the key line being</p>
<pre><code>and DATEPART(dy,timestamp at time zone 'Pacific Standard Time') = datepart(dy,SYSDATETIMEOFFSET() at time zone 'Pacific Standard Time')-1
</code></pre>
<p>With that line, I am trying to retrieve all records from the previous date, not based on a rolling 24 hours. For example, if the report is run on November 9th, it doesn't matter if the report was run at 6 AM or 6 PM, it will return all records for November 8th.</p>
<p>The problem is, if I change that line to be without the</p>
<pre><code>at time zone 'Pacific Standard Time'
</code></pre>
<p>in both places, the query runs a lot faster. However, when the time is adjusted to the correct timezone with that line, then the query becomes a lot slower.</p>
<p>Is there any more efficient way to do this?</p>
<p>Thanks a lot for any advice.</p>
| [
{
"answer_id": 74380933,
"author": "ahmed",
"author_id": 12705912,
"author_profile": "https://Stackoverflow.com/users/12705912",
"pm_score": 3,
"selected": true,
"text": "select \n d.department_id,\n d.department_name\nfrom departments d left join employees e \non e.department_id=d.department_id\nwhere e.employee_id is null\n"
},
{
"answer_id": 74380945,
"author": "Ankit Bajpai",
"author_id": 3627756,
"author_profile": "https://Stackoverflow.com/users/3627756",
"pm_score": 1,
"selected": false,
"text": "SELECT * \n FROM departments\n WHERE department_id in (SELECT department_id\n FROM departments\n minus \n SELECT DISTINCT department_id\n FROM employees\n );\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7959439/"
] |
74,380,783 | <p>I have tables <code>T1</code> and <code>T2</code>. Both have columns <code>ID</code>, <code>X</code> and <code>Y</code>. In addition, <code>T1</code> has another column <code>Z</code> and <code>T2</code> has another column <code>A</code>. <code>ID</code> is primary key. <code>X</code> is calculated from <code>ID</code> (so if <code>ID</code> matches, also <code>X</code> matches). Column <code>Y</code> exists in both tables but content is not the same relative to <code>ID</code>. <code>A</code> and <code>Z</code> do not have anything to do with each other.</p>
<p><code>T1</code>:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>X</th>
<th>Y</th>
<th>Z</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>X1</td>
<td>Y1</td>
<td>Z1</td>
</tr>
<tr>
<td>2</td>
<td>X2</td>
<td>Y2</td>
<td>Z2</td>
</tr>
</tbody>
</table>
</div>
<p><code>T2</code>:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>X</th>
<th>Y</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>X2</td>
<td>Y3</td>
<td>A1</td>
</tr>
<tr>
<td>3</td>
<td>X3</td>
<td>Y4</td>
<td>A2</td>
</tr>
</tbody>
</table>
</div>
<p>I want a query which returns a record that contains all data from both tables and fills in <code>NULL</code> whenever a field has no data.</p>
<p>Result:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>X</th>
<th>T1Y</th>
<th>T2Y</th>
<th>Z</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>X1</td>
<td>Y1</td>
<td>NULL</td>
<td>Z1</td>
<td>NULL</td>
</tr>
<tr>
<td>2</td>
<td>X2</td>
<td>Y2</td>
<td>Y3</td>
<td>Z2</td>
<td>A1</td>
</tr>
<tr>
<td>3</td>
<td>X3</td>
<td>NULL</td>
<td>Y4</td>
<td>NULL</td>
<td>A2</td>
</tr>
</tbody>
</table>
</div>
<p>My SQLite version does not support <code>RIGHT JOIN</code> or <code>FULL JOIN</code>. I tried :</p>
<pre><code>SELECT T1.ID, T2.ID
FROM T1
LEFT JOIN T2
ON T1.ID = T2.ID
UNION
SELECT T1.ID, T2.ID
FROM T2
LEFT JOIN T1
ON T1.ID = T2.ID
WHERE T1.ID IS NULL
ORDER BY T1.ID
</code></pre>
<p>But got:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Null</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>NULL</td>
<td>3</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74380875,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 2,
"selected": true,
"text": "full join"
},
{
"answer_id": 74380971,
"author": "forpas",
"author_id": 10498828,
"author_profile": "https://Stackoverflow.com/users/10498828",
"pm_score": 2,
"selected": false,
"text": "FULL OUTER JOIN"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7471360/"
] |
74,380,786 | <p>I'm trying to convert something like this:</p>
<pre><code>const map<string, string> digits = {{"zero", "0"},{"one", "1"},{"two", "2"},{"three", "3"},{"four", "4"},{"five", "5"},{"six", "6"},{"seven", "7"},{"eight", "8"},{"nine", "9"}};
</code></pre>
<p>Into this:</p>
<pre><code>map<string, uint> out = {{"zero", 0},{"one", 0},{"two", 0},{"three", 0},{"four", 0},{"five", 0},{"six", 0},{"seven", 0},{"eight", 0},{"nine", 0}};
</code></pre>
<p>In a short way using STL algorithms.</p>
<p>I've tried many things, but right now I'm at:</p>
<pre><code>map<string, uint> counting;
transform(begin(digits), end(digits), inserter(counting, end(counting)), [](auto & p) {
return {p.first, 0};
});
</code></pre>
<p>and am scratching my head as to how I do this... Is there a way to use the transform algorithm on dissimilar iterators?</p>
| [
{
"answer_id": 74380893,
"author": "Nelfeal",
"author_id": 3854570,
"author_profile": "https://Stackoverflow.com/users/3854570",
"pm_score": 1,
"selected": false,
"text": "std::map<std::string, uint>::value_type"
},
{
"answer_id": 74380906,
"author": "Some programmer dude",
"author_id": 440558,
"author_profile": "https://Stackoverflow.com/users/440558",
"pm_score": 0,
"selected": false,
"text": "std::map"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12861190/"
] |
74,380,792 | <p>I am new to JavaScript and coding in general. I made a basic conditional function and have played around with it a bit, but for some reason the answer is not coming out right in the console after the prompts are entered and passed into the function.</p>
<p>Basically, it is supposed to take two fractions and compare them to see which one is bigger. When I pass arguments into the function directly through the console, it comes out right. However, when I try and enter the fractions in the prompt which is stored in the variables the function is supposed to take, it comes out wrong sometimes.</p>
<p>It must be something simple I am missing here, any help would be appreciated!</p>
<p>Here is the code:</p>
<pre><code>function compareFractionSizes(fractionA,fractionB) {
if (fractionA > fractionB) {
console.log("fraction a is bigger")
}
if (fractionA == fractionB) {
console.log("The fractions are equal")
}
if (fractionA < fractionB) {
console.log("fraction b is bigger")
}
}
var fractionA = prompt("what is your first fraction?")
var fractionB = prompt("what is your second fraction?")
compareFractionSizes(fractionA,fractionB)
</code></pre>
<p>I tried changing the variables to a float to see if that would work better, but it didn't seem to do anything. Also, I tried to enter different fractions and some of them worked while others didn't. For ex,
1st frac: 3/4
2nd frac: 4/6
result: "fraction b is bigger" ---which clearly isn't true.</p>
| [
{
"answer_id": 74380893,
"author": "Nelfeal",
"author_id": 3854570,
"author_profile": "https://Stackoverflow.com/users/3854570",
"pm_score": 1,
"selected": false,
"text": "std::map<std::string, uint>::value_type"
},
{
"answer_id": 74380906,
"author": "Some programmer dude",
"author_id": 440558,
"author_profile": "https://Stackoverflow.com/users/440558",
"pm_score": 0,
"selected": false,
"text": "std::map"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19400193/"
] |
74,380,821 | <p>I have this code in which I initialize a class (Adapter) by the name I get from the request.
It seems to be a bit clumsy, and I'm sure there's a better/cleaner way of doing it.</p>
<pre><code>from adapters.gofirst_adapter import GoFirstAdapter
from adapters.spicejet_adapter import SpiceJetAdapter
from adapters.airasia_adapter import AirAsiaAdapter
class Adapter():
def __init__(self, adapter_name):
if(adapter_name=='goFirst'):
gofirst_adapter = GoFirstAdapter()
self.adapter = gofirst_adapter
if(adapter_name=='spiceJet'):
spicejet_adapter = SpiceJetAdapter()
self.adapter = spicejet_adapter
if(adapter_name=='airAsia'):
airasia_adapter = AirAsiaAdapter()
self.adapter = airasia_adapter
</code></pre>
<p>What I'm aiming at is to have a list of the adapter names such as:</p>
<pre><code>adapters = ['goFirst', 'spiceJet', 'airAsia']
</code></pre>
<p>and create the classes by the list.</p>
<p>Thank you.</p>
| [
{
"answer_id": 74380870,
"author": "quamrana",
"author_id": 4834,
"author_profile": "https://Stackoverflow.com/users/4834",
"pm_score": 3,
"selected": true,
"text": "dict"
},
{
"answer_id": 74380905,
"author": "J. Ferrarons",
"author_id": 7383560,
"author_profile": "https://Stackoverflow.com/users/7383560",
"pm_score": 1,
"selected": false,
"text": "from adapters.gofirst_adapter import GoFirstAdapter\nfrom adapters.spicejet_adapter import SpiceJetAdapter\nfrom adapters.airasia_adapter import AirAsiaAdapter\n\nclass Adapter():\n _adapter_builders = {\n \"goFirst\": GoFirstAdapter,\n \"spiceJet\": SpiceJetAdapter,\n \"airAsia\": AirAsiaAdapter,\n }\n\n def __init__(self, adapter_name):\n self.adapter = self._adapter_builders[adapter_name]()\n\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18464138/"
] |
74,380,836 | <p>I'm thinking that perhaps my entire idea of how to approach this is wrong, so let me explain what I'm trying to do.</p>
<p>I have a UserId that is a property contained within my JWT token.</p>
<p>On many of my REST endpoints, I need to read that UserId to use it within my DB queries.</p>
<p>I implemented a filter which intercepts all of my calls and decodes my JWT and assigns the UserId value into a static Globals class that I had created.</p>
<p>I just realised now though, that that class is GLOBAL. As in, the values are actually shared across the entire server for anybodies REST requests.
I intended for the value to essentially just be transiently available for the duration of each individual request.</p>
<p>How can I change my implementation so that I can globally access the UserId contained in the JWT token for the current request.</p>
| [
{
"answer_id": 74381160,
"author": "Neistow",
"author_id": 12400440,
"author_profile": "https://Stackoverflow.com/users/12400440",
"pm_score": 2,
"selected": false,
"text": "ICurrentUser"
},
{
"answer_id": 74382345,
"author": "Martin",
"author_id": 2630668,
"author_profile": "https://Stackoverflow.com/users/2630668",
"pm_score": 2,
"selected": true,
"text": "public UserService : IUserService \n{\n private readonly IHttpContextAccessor _accessor;\n\n /// inject the `IHttpContextAccessor` to access the actual \n /// request / token / headers etc.\n public UserService(IHttpContextAccessor accessor)\n {\n _accessor = accessor;\n }\n\n public async Task<string> GetUserIdAsync() \n {\n var userId = await GetUserIdFromTokenAsync();\n return userId;\n }\n\n private Task<string> GetUserIdFromTokenAsync() \n {\n /// Add your logic here to get or parse the \n /// user id from the token or do some other stuff to get the user id.\n /// ... or get the user id from the current User object claim\n /// depends on your auth settings `_accessor.HttpContext?.User`\n var token = _accessor... // from headers?\n return userId;\n }\n}\n\n/// Always use an interface to make it well testable and mockable for unit tests\npublic interface IUserService \n{\n Task<string> GetUserIdAsync();\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10245924/"
] |
74,380,867 | <p>I have a dataframe with information about a race and one column shows the distance that was driven by a car at a specific timepoint. It looks something like this:</p>
<pre><code>data.frame(id = rep(c("A"), each = 15),
distance = seq(from = 1, to = 20, length.out = 15))
id distance
1 A 1.000000
2 A 2.357143
3 A 3.714286
4 A 5.071429
5 A 6.428571
6 A 7.785714
7 A 9.142857
8 A 10.500000
9 A 11.857143
10 A 13.214286
11 A 14.571429
12 A 15.928571
13 A 17.285714
14 A 18.642857
15 A 20.000000
</code></pre>
<p>If I know that one lap is 5 units, I would like to create a new column that tells the lap at which each data point was taken, based on the distance driven. The result should look like this:</p>
<pre><code>data.frame(id = rep("A", each = 15),
distance = seq(from = 1, to = 20, length.out = 15),
lap = c(1,1,1,2,2,2,2,3,3,3,3,4,4,4,4))
id distance lap
1 A 1.000000 1
2 A 2.357143 1
3 A 3.714286 1
4 A 5.071429 2
5 A 6.428571 2
6 A 7.785714 2
7 A 9.142857 2
8 A 10.500000 3
9 A 11.857143 3
10 A 13.214286 3
11 A 14.571429 3
12 A 15.928571 4
13 A 17.285714 4
14 A 18.642857 4
15 A 20.000000 4
</code></pre>
<p>How can I do this, preferably using tidyverse?</p>
| [
{
"answer_id": 74380968,
"author": "divibisan",
"author_id": 8366499,
"author_profile": "https://Stackoverflow.com/users/8366499",
"pm_score": 4,
"selected": true,
"text": "ceiling"
},
{
"answer_id": 74381022,
"author": "Ed_Gravy",
"author_id": 12547996,
"author_profile": "https://Stackoverflow.com/users/12547996",
"pm_score": 0,
"selected": false,
"text": "group_by()"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15229242/"
] |
74,380,907 | <p>Please take a look at this snippet of code:</p>
<pre><code>uint16_t buffer_array[2]; //Two uint16_t = 4 bytes
temp = swSerial.read(); // Populate with serial readings coming from the sensor
switch(received_counter)
{
case 3: //when we receive the fourth byte from the sensor
buffer_array[0] = temp;
break;
case 4: //fifth byte
buffer_array[0] += temp;
break;
case 5: //sixth byte
buffer_array[1] = temp;
break;
case 6: //seventh byte
buffer_array[1] += temp;
break;
default:
break;
}
</code></pre>
<p>This code populates the array I declared with readings from a source. When this ends, the array <code>buffer_array[2]</code> will have its 4 bytes populated (or 8 hexadecimal values). This is straightforward.</p>
<p>But now we have four raw bytes stored in the array. These four bytes represent a floating point value (i know that from documentation). So we want these 4 bytes (8 hex values) converter to a floating point value.</p>
<p>I can do this with:</p>
<pre><code>float voltage;
memcpy(&voltage, &buffer_array, sizeof(float));
</code></pre>
<p>My question is why does this work? <code>memcpy()</code> copies n characters from memory area src to memory area dest.
Does this imply an implicit casting when the values in the memory area is not the same as the value in the destination variable? Am i missing something?</p>
| [
{
"answer_id": 74380996,
"author": "tadman",
"author_id": 87189,
"author_profile": "https://Stackoverflow.com/users/87189",
"pm_score": 0,
"selected": false,
"text": "memcpy()"
},
{
"answer_id": 74381423,
"author": "Useless",
"author_id": 212858,
"author_profile": "https://Stackoverflow.com/users/212858",
"pm_score": 1,
"selected": false,
"text": "memcpy"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1584421/"
] |
74,380,915 | <p>Hi guys so I am trying to set up a little survey app, I am now building my survey result page, which will display the results of a given survey.
The data that I am fetching is an array of object with <code>answers</code> arrays inside them.</p>
<pre><code>{ totalAnswers: [
{ answers: [answer0, answer1, answer2, answer3] },
{ answers: [Array] },
... ] }
</code></pre>
<p>I am wondering how to display the data since all the objects keys are all the same, but the arrays also all have the same length... Any leads are welcomed :)</p>
<hr />
<p>Edit:
I figured that I wasn't clear enough in what I am trying to achieve, and I apologize for that.</p>
<p>So basically in this survey web app that I am building. I want to enable the survey creator to , optimally, be
able to view the answer data of each question seperately. Or at least be able to display those answers on the DOM.
To be able to do so I should somehow find a way to destructure this big <code>totalAnswers</code> array containing objects having each an <code>answers</code> array.</p>
<p>The <code>answers.length</code> can vary depending on the number of the questions that the survey has. And the number of objects with an answer array may also vary depending on the number of survey answers.</p>
<p>But whenever I try to do <code>console.log(totalAnswers.length)</code> it is returning <code>undefined</code> so does it mean that it might be an object after all ? I thought that since there were brackets after <code>totalAnswer</code> it meant that it was an array.</p>
| [
{
"answer_id": 74380996,
"author": "tadman",
"author_id": 87189,
"author_profile": "https://Stackoverflow.com/users/87189",
"pm_score": 0,
"selected": false,
"text": "memcpy()"
},
{
"answer_id": 74381423,
"author": "Useless",
"author_id": 212858,
"author_profile": "https://Stackoverflow.com/users/212858",
"pm_score": 1,
"selected": false,
"text": "memcpy"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18187041/"
] |
74,380,925 | <p>I have a single .txt with +200k rows.
In this file, i want to delete duplicates and original rows.</p>
<p>I have now:</p>
<ul>
<li>text a</li>
<li>text a</li>
<li>text b</li>
<li>text c</li>
<li>text d</li>
<li>text d</li>
<li>text e</li>
</ul>
<p>But i need a result like this</p>
<ul>
<li>text b</li>
<li>text c</li>
<li>text e</li>
</ul>
<pre><code>Suggest?
i have tried normal "delete duplicate" procedure of excel and notepad++ but i obtain this
text a
text b
text c
text d
text e
and it not work fine for me
looking for discussion i find something like that but applicated to access.
</code></pre>
| [
{
"answer_id": 74381591,
"author": "Harishma Ashok",
"author_id": 20403698,
"author_profile": "https://Stackoverflow.com/users/20403698",
"pm_score": 0,
"selected": false,
"text": "# Importing Pandas to create DataFrame\nimport pandas as pd\n\n# Creating Empty DataFrame and Storing it in variable df\ndf = pd.DataFrame()\n\n#replce this with our requiremnt\n# lt = [\"text a\", \"text a\", \"text b\", \"text c\", \"text d\", \"text d\", \"text e\"]\n\ntext_file = open(r\"C:\\Users\\antch\\Desktop\\txt.txt\", \"r\")\nlt = text_file.readlines()\n# print (lt)\n# print (type(lt))\ntext_file.close()\n\ndf['cols'] = lt\n#creating an empty column with count value set to 1\ndf['dummy_count'] = 1\n\n# grouping values \ndf = df.groupby('cols').count()\n# print(df)\n\ndf.reset_index(inplace = True)\n\ndf = df.loc[df[\"dummy_count\"] == 1]\nprint(df[\"cols\"])\n"
},
{
"answer_id": 74488731,
"author": "AdrianHHH",
"author_id": 546871,
"author_profile": "https://Stackoverflow.com/users/546871",
"pm_score": 1,
"selected": false,
"text": "^(.*\\R)\\1+"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20255410/"
] |
74,380,932 | <p>So I am trying to orchestrate a workflow in Airflow. One task is to read GCP Cloud Storage, which needs me to specify the Google Application Credentials.</p>
<p>I decided to create a new folder in the dag folder and put the JSON key. Then I specified this in the dag.py file;</p>
<p><code>os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "dags\support\keys\key.json"</code></p>
<p>Unfortunately, I am getting this error below;</p>
<p>google.auth.exceptions.DefaultCredentialsError: File dags\support\keys\dummy-surveillance-project-6915f229d012.json was not found</p>
<p>Can anyone help with how I should go about declaring the service account key?</p>
<p>Thank you.</p>
| [
{
"answer_id": 74382623,
"author": "Simon D",
"author_id": 3287250,
"author_profile": "https://Stackoverflow.com/users/3287250",
"pm_score": 0,
"selected": false,
"text": "GCSToLocalFilesystemOperator"
},
{
"answer_id": 74387168,
"author": "Mazlum Tosun",
"author_id": 9261558,
"author_profile": "https://Stackoverflow.com/users/9261558",
"pm_score": 1,
"selected": false,
"text": "Google Cloud"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19515785/"
] |
74,380,984 | <p>I don't find a way in JavaScript to get on what device my website is open.</p>
<p>I want something like this:</p>
<pre class="lang-js prettyprint-override"><code>if ( website.size < 768px) {
//do something for mobile
}
</code></pre>
<p>I know that I can use a media query in CSS, but I want use JS, and I'm very curious if it's possible without CSS.</p>
<p><code>window.matchMedia</code> or <code>window.width</code> don't seem to work because they take the size of my window.</p>
<p>In difference on the related question is this case is to make a responsive website. So, the related answer doesn't resolve the case where the user resize the window in computer.</p>
| [
{
"answer_id": 74381257,
"author": "Stranger",
"author_id": 13349935,
"author_profile": "https://Stackoverflow.com/users/13349935",
"pm_score": 3,
"selected": true,
"text": "navigator.userAgent"
},
{
"answer_id": 74381589,
"author": "Axel G",
"author_id": 19947889,
"author_profile": "https://Stackoverflow.com/users/19947889",
"pm_score": 1,
"selected": false,
"text": "const vw = Math.max(\n document.documentElement.clientWidth || 0,\n window.innerWidth || 0\n);\nconst vh = Math.max(\n document.documentElement.clientHeight || 0,\n window.innerHeight || 0\n);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74380984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19947889/"
] |
74,381,013 | <p>I am trying to do a regex match at a specific position in Typescript.</p>
<p>Here's what I have tried.</p>
<pre><code>var str = "0123ABC789"
function matchesAt(rgx: RegExp, s : string, i : number) : string | void {
rgx.lastIndex = i
console.log(rgx.exec(s));
}
matchesAt(/(ABC)/g, str, 4 )
</code></pre>
<p>In essence, I am trying to recreate the String.startsWith(string, number) method, but with a regex inside - instead of another string.</p>
<p>I am expecting that the function should only match when the index is 4. any other number should return a nil.</p>
| [
{
"answer_id": 74381257,
"author": "Stranger",
"author_id": 13349935,
"author_profile": "https://Stackoverflow.com/users/13349935",
"pm_score": 3,
"selected": true,
"text": "navigator.userAgent"
},
{
"answer_id": 74381589,
"author": "Axel G",
"author_id": 19947889,
"author_profile": "https://Stackoverflow.com/users/19947889",
"pm_score": 1,
"selected": false,
"text": "const vw = Math.max(\n document.documentElement.clientWidth || 0,\n window.innerWidth || 0\n);\nconst vh = Math.max(\n document.documentElement.clientHeight || 0,\n window.innerHeight || 0\n);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/876444/"
] |
74,381,035 | <p>Why python does not replace last character for @?</p>
<pre><code>str_manip = input("Enter a sentence ")
last_char = str_manip[-1]
print(last_char)
change_char = str_manip.replace("last_char", "@")
print(change_char)
</code></pre>
<p>It comes up as exactly the same sentence as I enter, unchanged.</p>
<p>I have read a few websites and still do not understand. I thought maybe it was because @ is char but str() doesn't help, saving it as separate string variable also doesn't work.</p>
| [
{
"answer_id": 74381094,
"author": "Danut Popa",
"author_id": 20462687,
"author_profile": "https://Stackoverflow.com/users/20462687",
"pm_score": 1,
"selected": false,
"text": "change_char = str_manip.replace(\"last_char\", \"@\")\n"
},
{
"answer_id": 74381111,
"author": "Bill Goldberg",
"author_id": 2788009,
"author_profile": "https://Stackoverflow.com/users/2788009",
"pm_score": 2,
"selected": false,
"text": "str_manip = input(\"Enter a sentence \")\nlast_char = str_manip[-1]\nprint(last_char)\nchange_char = str_manip.replace(last_char, \"@\")\nprint(change_char)\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20148679/"
] |
74,381,053 | <p>I want to create the mean of the values in two rows, based on values in a third row. In one row I have ID's A, B and C and means have to be created for the values in two rows with the ID A & B, B & C and A & C. Is there a simple way to do this?</p>
<pre><code>My dataset is as the example below:
station group groupA groupB groupC value time
1 A A nan nan 4 30
1 B nan B nan 7 30
1 C nan nan C 6 30
2 A A nan nan 5 30
2 B nan B nan 3 30
2 C nan nan C 1 30
3 A A nan nan 2 30
3 B nan B nan 3 30
3 C nan nan C 4 30
....
</code></pre>
<pre><code>#creating the mean of station 1 in time 30 works with this code.
df['mean_allstations'] = df.groupby(['station','time'])['value'].transform('mean')
#But if I only want to create the mean of station 1 in time 30 for group A and B I tried this, which #gives me a column with nan values
df['mean_AB'] = df.groupby(['station','time', 'group_A', 'group_B'])['value'].transform('mean')
expected outcome:
station group groupA groupB groupC value time meanAB meanAC meanBC ALLme
1 A A nan nan 4 30 5.5 5 6.5 5.6
1 B nan B nan 7 30 5.5 5 6.5 5.6
1 C nan nan C 6 30 5.5 5 6.5 5.6
2 A A nan nan 5 30 4 3 2 3
2 B nan B nan 3 30 4 3 2 3
2 C nan nan C 1 30 4 3 2 3
3 A A nan nan 2 30 2.5 3 3.5 3
3 B nan B nan 3 30 2.5 3 3.5 3
3 C nan nan C 4 30 2.5 3 3.5 3
</code></pre>
| [
{
"answer_id": 74381094,
"author": "Danut Popa",
"author_id": 20462687,
"author_profile": "https://Stackoverflow.com/users/20462687",
"pm_score": 1,
"selected": false,
"text": "change_char = str_manip.replace(\"last_char\", \"@\")\n"
},
{
"answer_id": 74381111,
"author": "Bill Goldberg",
"author_id": 2788009,
"author_profile": "https://Stackoverflow.com/users/2788009",
"pm_score": 2,
"selected": false,
"text": "str_manip = input(\"Enter a sentence \")\nlast_char = str_manip[-1]\nprint(last_char)\nchange_char = str_manip.replace(last_char, \"@\")\nprint(change_char)\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16009255/"
] |
74,381,068 | <p>Is it wrong to put env variables in the express server file ? is it going to be seen by any one?</p>
<p>env variables in server file</p>
| [
{
"answer_id": 74381094,
"author": "Danut Popa",
"author_id": 20462687,
"author_profile": "https://Stackoverflow.com/users/20462687",
"pm_score": 1,
"selected": false,
"text": "change_char = str_manip.replace(\"last_char\", \"@\")\n"
},
{
"answer_id": 74381111,
"author": "Bill Goldberg",
"author_id": 2788009,
"author_profile": "https://Stackoverflow.com/users/2788009",
"pm_score": 2,
"selected": false,
"text": "str_manip = input(\"Enter a sentence \")\nlast_char = str_manip[-1]\nprint(last_char)\nchange_char = str_manip.replace(last_char, \"@\")\nprint(change_char)\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20462769/"
] |
74,381,070 | <p>I want to add an iconButton and display a website preview when the mouse hover the help icon. I found something similar using css but I need to convert that to material UI.
This is the css code to be converted from this post <a href="https://stackoverflow.com/questions/2117046/how-to-show-live-preview-in-a-small-popup-of-linked-page-on-mouse-over-on-link">How to show live preview in a small popup of linked page on mouse over on link?</a></p>
<pre><code>.box{
display: none;
width: 100%;
}
a:hover + .box,.box:hover{
display: block;
position: relative;
z-index: 100;
}
</code></pre>
<p>This is what I have so far:</p>
<pre><code>const HoverText = () => {
return (
<div className={classes.box}>
<iframe src="https://en.wikipedia.org/" width="500px" height="500px">
</iframe>
</div>
);
};
return (
<>
<IconButton size="large" color="inherit" onClick={() => window.open("https://en.wikipedia.org/", "_blank")}>
<HelpIcon className={classes.act} />
<HoverText />
</IconButton>
</>
);
</code></pre>
<p>Could you please help me to fix this:</p>
<pre><code>const useStyles = makeStyles((theme: Theme) =>
createStyles({
box: {
width: '100%',
display: 'none'
},
act: {
"&:hover + .box, .box:hover": {
display: 'block',
position: 'relative',
zIndex: 100
}
}
}),
);
</code></pre>
<p>Im expect to display a preview of a website page when mouse is over the icon.</p>
| [
{
"answer_id": 74381094,
"author": "Danut Popa",
"author_id": 20462687,
"author_profile": "https://Stackoverflow.com/users/20462687",
"pm_score": 1,
"selected": false,
"text": "change_char = str_manip.replace(\"last_char\", \"@\")\n"
},
{
"answer_id": 74381111,
"author": "Bill Goldberg",
"author_id": 2788009,
"author_profile": "https://Stackoverflow.com/users/2788009",
"pm_score": 2,
"selected": false,
"text": "str_manip = input(\"Enter a sentence \")\nlast_char = str_manip[-1]\nprint(last_char)\nchange_char = str_manip.replace(last_char, \"@\")\nprint(change_char)\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16028889/"
] |
74,381,078 | <pre><code>let db = Firestore.firestore()
let docRef = db.collection("users").document(result!.user.uid)
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
print("Document data: \(dataDescription)")
print()
} else {
print("Document does not exist")
}
}
</code></pre>
<p><code>print("Document data: \(dataDescription)")</code> outputs the following:</p>
<p>Document data: <code>["uid": LjqBXo41qMStt89ysQ4I9hxla2h1, "firstname": Tim, "lastname": Dorsemagen]</code></p>
<p>How can I extract each value such as the <code>uid</code>, the <code>firstname</code> and the <code>lastname</code> from <code>dataDescription</code>?</p>
| [
{
"answer_id": 74381094,
"author": "Danut Popa",
"author_id": 20462687,
"author_profile": "https://Stackoverflow.com/users/20462687",
"pm_score": 1,
"selected": false,
"text": "change_char = str_manip.replace(\"last_char\", \"@\")\n"
},
{
"answer_id": 74381111,
"author": "Bill Goldberg",
"author_id": 2788009,
"author_profile": "https://Stackoverflow.com/users/2788009",
"pm_score": 2,
"selected": false,
"text": "str_manip = input(\"Enter a sentence \")\nlast_char = str_manip[-1]\nprint(last_char)\nchange_char = str_manip.replace(last_char, \"@\")\nprint(change_char)\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12778601/"
] |
74,381,122 | <p>I have my first small project and I just started a PowerShell (total beginner).</p>
<p>We have three different shared C:\ drives and I need to output each disk storage info (e.g. total and free space) by using Powershell script.</p>
<p>Here is the script I made, but these three results are all the same even though they have different free spaces and total.</p>
<p>Can anyone please advise me on what is wrong with my ps script?</p>
<p>Plus, in the result, I don't want to display any other drives (e.g D and E) but only the C drive. How to do so?</p>
<p><strong>[Script]</strong></p>
<pre><code>Set-Location -Path \\vm1\c$
Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId, @{n='Size'; e={[math]::Round($_.Size/1GB, 2)}}, @{n="FreeSpace"; e={[math]::Round($_.FreeSpace/1GB, 2)}}
Set-Location -Path \\vm2\c$
Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId, @{n='Size'; e={[math]::Round($_.Size/1GB, 2)}}, @{n="FreeSpace"; e={[math]::Round($_.FreeSpace/1GB, 2)}}
Set-Location -Path \\vm3\c$
Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId, @{n='Size'; e={[math]::Round($_.Size/1GB, 2)}}, @{n="FreeSpace"; e={[math]::Round($_.FreeSpace/1GB, 2)}}
</code></pre>
<p><strong>[Result]</strong></p>
<pre><code>DeviceId Size FreeSpace
-------- ---- ---------
C: 473.95 114.22
D: 0 0
E: 0 0
DeviceId Size FreeSpace
-------- ---- ---------
C: 473.95 114.22
D: 0 0
E: 0 0
DeviceId Size FreeSpace
-------- ---- ---------
C: 473.95 114.22
D: 0 0
E: 0 0
</code></pre>
| [
{
"answer_id": 74381247,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 2,
"selected": true,
"text": "win32_logicaldisk"
},
{
"answer_id": 74381312,
"author": "Toni",
"author_id": 19895159,
"author_profile": "https://Stackoverflow.com/users/19895159",
"pm_score": 0,
"selected": false,
"text": "Set-Location"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20111546/"
] |
74,381,129 | <p>I am trying to align two divs next to each other. The left div has four small images on top of each other, and the right div has one large image the size of the left div. I've been trying to use block and inline-block as well as relative positioning for them, but I don't understand why they are not aligning next to each other. I got a temporary solution using absolute positions but I know it's not really something functional. Here is my code:</p>
<p>HTML</p>
<pre><code><div class="container product-container">
<!--Product Information-->
<div class="row row-sm">
<!--Product Images-->
<div class="col-md-6 product-image-container">
<!--Side Images-->
<div class="side-picture-container">
<ul class="picture-list">
<li><img src="https://s.fotorama.io/1.jpg"></li>
<li><img src="https://s.fotorama.io/2.jpg"></li>
<li><img src="https://s.fotorama.io/3.jpg"></li>
<li><img src="https://ucarecdn.com/382a5139-6712-4418-b25e-cc8ba69ab07f/-/stretch/off/-/resize/760x/"></li>
</ul>
</div>
<!--Current Product Image-->
<div class="big-product-image">
<img class="current-product-image" src="https://s.fotorama.io/1.jpg">
</div>
</div>
<!--Product Text-->
<div class="col-md-6">
</div>
</div>
</div>
</code></pre>
<p>CSS</p>
<pre><code>.product-container
{
margin-top: 4vw;
display: block;
}
.product-image-container
{
display: inline-block;
}
.picture-list li
{
display: inline-block;
width: 110px;
height: 114px;
border: none;
}
.picture-list li img
{
width: 97%;
height: auto;
}
.product-image-container .side-picture-container
{
width: 90px;
display: inline-block;
vertical-align: top;
margin-top: 0px;
position: relative;
}
.picture-list li img
{
height: 100px;
object-fit: cover;
border-radius: 10%;
}
/* .big-product-image
{
position: relative;
} */
.current-product-image
{
position: absolute;
height: 450px;
width: 350px;
margin-top: 0.25vw;
border-radius: 10%;
top: 27.75%;
left: 20%;
}
</code></pre>
<p>What do I need to do to get 'side-picture-container' and 'big-product-image' next to each other?</p>
| [
{
"answer_id": 74381215,
"author": "Kevon",
"author_id": 766684,
"author_profile": "https://Stackoverflow.com/users/766684",
"pm_score": 0,
"selected": false,
"text": "<div class=\"flex-container\">\n\n <div class=\"flex-child magenta\">\n Flex Column 1\n </div>\n \n <div class=\"flex-child green\">\n Flex Column 2\n </div>\n \n</div>\n\n.flex-container {\n display: flex;\n}\n\n.flex-child {\n flex: 1;\n border: 2px solid yellow;\n} \n\n.flex-child:first-child {\n margin-right: 20px;\n} \n"
},
{
"answer_id": 74381356,
"author": "computercarguy",
"author_id": 1836461,
"author_profile": "https://Stackoverflow.com/users/1836461",
"pm_score": 2,
"selected": true,
"text": ".product-container\n{\n margin-top: 4vw;\n}\n\n.product-image-container\n{\n display: flex;\n}\n\n.picture-list li\n{\n width: 110px;\n height: 114px;\n border: none;\n}\n\n.picture-list li img\n{\n width: 97%;\n height: auto;\n}\n\n.product-image-container .side-picture-container\n{\n vertical-align: top;\n margin-top: 0px;\n}\n\n.picture-list li img\n{\n height: 100px;\n border-radius: 10%;\n}\n\n.current-product-image\n{\n height: 450px;\n width: 350px;\n margin-top: 0.25vw;\n border-radius: 10%;\n}"
},
{
"answer_id": 74381427,
"author": "jozef koko",
"author_id": 10489766,
"author_profile": "https://Stackoverflow.com/users/10489766",
"pm_score": 0,
"selected": false,
"text": ".flex-container {\n display: flex;\n gap: 10px;\n}\n/* any child element of flex container that has .flex-child can grow by 1 */\n\n.flex-container > *.flex-child {\n flex: 1;\n border: 2px solid yellow;\n} \n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9245162/"
] |
74,381,153 | <p>I am working on a project where I am interfacing(?) with another program. This other program has no way for me to interface with it, so, I need to pull values out of memory. I have already found the addresses where these values are stored relative to the MZ Start address listed in the programs PE header. I simply need to look at that address and get its value. Is there a way to do this in Python, or will I need a different language?</p>
<p>I used Cheat Engine to find the memory address relative to the MZ Start address listed in the programs PE header. However, I have no way to interface with Cheat Engine in order to do something with the value it is looking at. Then I had the idea to manually look at that address while the program is running with a python script. However, I am unsure of where to begin.</p>
<p>Here's what I know:</p>
<p>First line of memory starts at address: 0x00CC0000</p>
<p>It always starts here.</p>
<p>Hexadecimal Address: 00CC0000(StartOfMem)+841984(Offset) = 0x01501984</p>
<p>This is where the pointer is stored in memory. I have verified that it is always in this location.</p>
<p>This pointer points to the memory address of a UI class object in the program I am trying to interface with, this object contains data I want to read.</p>
<p>If I dereference the pointer it will give me another memory address. Let's call this value AddressAtPointer.</p>
<p>I know the two things I am looking have an offset of 43C and 434 from AddressAtPointer and are 4 byte integers.</p>
<p>Is there a way for me to read the data at these specific memory addresses?</p>
| [
{
"answer_id": 74381455,
"author": "Nick ODell",
"author_id": 530160,
"author_profile": "https://Stackoverflow.com/users/530160",
"pm_score": 1,
"selected": false,
"text": "import ctypes\nfoo = ctypes.c_char.from_address(0x00000000)\nfoo.value = 1\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20223506/"
] |
74,381,175 | <p>What is time complexity for std::find_if() function using std::set in C++?</p>
<p>Consider we have the following example:</p>
<pre><code>auto cmp = [&](const pair<int, set<int>>& a , const pair<int, set<int>>& b) -> bool {
if (a.second.size() == b.second.size()) {
return a.first < b.first;
}
return a.second.size() < b.second.size();
};
set<pair<int, set<int>>, decltype(cmp)> tree(cmp);
...
int value = ...;
auto it = find_if(tree.begin(), tree.end(), [](const pair<int, int> &p) {
return p.first == value;
});
</code></pre>
<p>I know it takes std::find_if O(n) to work with std::vector. Can't see any problems for this function not to work with std::set with time complexity O(log(n)).</p>
| [
{
"answer_id": 74381224,
"author": "user4581301",
"author_id": 4581301,
"author_profile": "https://Stackoverflow.com/users/4581301",
"pm_score": 0,
"selected": false,
"text": "std::find_if"
},
{
"answer_id": 74381227,
"author": "NathanOliver",
"author_id": 4342498,
"author_profile": "https://Stackoverflow.com/users/4342498",
"pm_score": 1,
"selected": false,
"text": "std::find"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17109814/"
] |
74,381,187 | <p>Please don't write that I should do my homework myself. I have tried but cannot find the answer.</p>
<p>Input:</p>
<pre class="lang-none prettyprint-override"><code>arr[11]={1,2,3,4,1,5,6,7,8,1,9}
</code></pre>
<p>Output:</p>
<pre class="lang-none prettyprint-override"><code>0 4 9
</code></pre>
<p>Returned position numbers are to be inserted into another array, I mean:</p>
<pre class="lang-none prettyprint-override"><code>arr_min_index[HowManyMinValues]={0,4,9}
</code></pre>
<p>I tried to end it in many different ways, but I failed.</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"How many elements should be in the array?"<<endl;
cin>>n;
int arr[n];
int i, j, MIN = arr[0], position=0, how_many;
for(i=0; i<n; i++)
{
cin>>arr[i];
}
for(i=0; i<n; i++)
{
if(arr[i]<MIN)
{
MIN = arr[i];
how_many=0;
}
if(tab[i]==MIN)
{
how_many=+1;
}
}
}
</code></pre>
| [
{
"answer_id": 74381224,
"author": "user4581301",
"author_id": 4581301,
"author_profile": "https://Stackoverflow.com/users/4581301",
"pm_score": 0,
"selected": false,
"text": "std::find_if"
},
{
"answer_id": 74381227,
"author": "NathanOliver",
"author_id": 4342498,
"author_profile": "https://Stackoverflow.com/users/4342498",
"pm_score": 1,
"selected": false,
"text": "std::find"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20462765/"
] |
74,381,189 | <p>I am tryig to render data from STRAPI, using Graphql and nextjs.</p>
<h5>I have an event Adapter which is working perfectly.</h5>
<h5>But when i try to render that data ON UI, it just give an error <code>event.map is not a function.</code></h5>
<h5>Even though i can get the same result in the front-end, but the only problem is the map.</h5>
<h1>conosle.log:</h1>
<pre><code> const eventsAd = eventsAdapter(data);
console.log("events data", eventsAd)
</code></pre>
<h1>Result - (IMG):</h1>
<p><a href="https://i.stack.imgur.com/b9GBn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b9GBn.png" alt="enter image description here" /></a></p>
<h2>Data result in the console - (IMG).</h2>
<p><a href="https://i.stack.imgur.com/Sjxar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sjxar.png" alt="enter image description here" /></a></p>
<h1>Map that i created:</h1>
<pre><code> <div>
{eventsAd.map((event) => {
return (
<>
<h1>{event.title}</h1>
</>
);
})}
</div>
</code></pre>
<h1>Error code:</h1>
<p><a href="https://i.stack.imgur.com/eCQQa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eCQQa.png" alt="enter image description here" /></a></p>
<h4>Please advise me if i am doing something wrong. Thanks</h4>
| [
{
"answer_id": 74381225,
"author": "Martinez",
"author_id": 19027584,
"author_profile": "https://Stackoverflow.com/users/19027584",
"pm_score": 1,
"selected": false,
"text": "<div>\n {eventsAd['Featured Events'].map((event) => {\n return (\n <>\n <h1>{event.title}</h1>\n </>\n );\n })}\n</div>\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16986538/"
] |
74,381,197 | <p>I have a data file like following:</p>
<pre><code>>> cat file1.txt
@target G0.S0
1 6
1 4
4 2
@target G0.S0
2 4
8 9
5 7
@target G0.S0
3 5
0 9
3 7
</code></pre>
<p>I want to make split columns delimited by <code>@target G0.S0</code> in a new file where columns set one next the previous ones like following:</p>
<pre><code>>> cat file2.txt
1 6 2 4 3 5
1 4 8 9 0 9
4 2 5 7 3 7
</code></pre>
<p>I searched in internet but I don't get what I want.</p>
| [
{
"answer_id": 74383249,
"author": "Diego Torres Milano",
"author_id": 236465,
"author_profile": "https://Stackoverflow.com/users/236465",
"pm_score": 1,
"selected": false,
"text": "awk"
},
{
"answer_id": 74383387,
"author": "Dave Pritlove",
"author_id": 2005666,
"author_profile": "https://Stackoverflow.com/users/2005666",
"pm_score": 0,
"selected": false,
"text": "awk"
},
{
"answer_id": 74383457,
"author": "Jetchisel",
"author_id": 4452265,
"author_profile": "https://Stackoverflow.com/users/4452265",
"pm_score": 2,
"selected": false,
"text": "pr"
},
{
"answer_id": 74387147,
"author": "potong",
"author_id": 967492,
"author_profile": "https://Stackoverflow.com/users/967492",
"pm_score": 0,
"selected": false,
"text": "csplit -qz --suppress file '/@target/' '{*}' && paste -d' ' xx* |\nsed 's/ / /g' >outFile && rm xx*\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15290424/"
] |
74,381,210 | <p>Im a total noob when it comes to Unity & C#
and now I got a task that I find a bit overwhelming so any input would be much appreciated...</p>
<p>I got a class that looks like this:</p>
<pre><code>//using directives
public class PipelineExample : MonoBehaviour
{
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private bool res = false;
// Start is called before the first frame update
void Start()
{
StartPipeline();
while (!res) ;
}
async void StartPipeline()
{
// create models, pipeline, pipeline step
IModel fbxModel = new FbxModel();
Pipeline<IModel> pipeline = new Pipeline<IModel>();
IAction<IModel> pipelineStep = new GenericPipelineStep<IModel>();
// add steps to pipeline
pipeline.AddPipeLineStep(pipelineStep);
try
{
res = await pipeline.Execute(fbxModel, cancellationTokenSource.Token);
Console.Write("Result of pipeline: " + res);
}
catch (OperationCanceledException)
{
Console.WriteLine("Canceled successfully!");
}
}
// Update is called once per frame
void Update()
{
}
}
</code></pre>
<p>Now I would like to call this startmethod(?) from another class somehow when I click on a Button "Start":</p>
<pre><code>private void OnStartButtonClicked(MouseUpEvent evt)
{
//What goes in here?
}
</code></pre>
<p>I cant just PipelineExample.Start obviously,</p>
<p>public PipelineExample something;
something.Start also doesnt work.</p>
<p>So basically my question is, how can I start this PipeLineExample class from another class?</p>
| [
{
"answer_id": 74383249,
"author": "Diego Torres Milano",
"author_id": 236465,
"author_profile": "https://Stackoverflow.com/users/236465",
"pm_score": 1,
"selected": false,
"text": "awk"
},
{
"answer_id": 74383387,
"author": "Dave Pritlove",
"author_id": 2005666,
"author_profile": "https://Stackoverflow.com/users/2005666",
"pm_score": 0,
"selected": false,
"text": "awk"
},
{
"answer_id": 74383457,
"author": "Jetchisel",
"author_id": 4452265,
"author_profile": "https://Stackoverflow.com/users/4452265",
"pm_score": 2,
"selected": false,
"text": "pr"
},
{
"answer_id": 74387147,
"author": "potong",
"author_id": 967492,
"author_profile": "https://Stackoverflow.com/users/967492",
"pm_score": 0,
"selected": false,
"text": "csplit -qz --suppress file '/@target/' '{*}' && paste -d' ' xx* |\nsed 's/ / /g' >outFile && rm xx*\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17187057/"
] |
74,381,216 | <p>I am working on the migration of a legacy API to microservice. The legacy API is encoding a java object into a base64 String. The following code is used:</p>
<pre><code>public String serialize() throws Exception {
String mementoXml = null;
Document document = DocumentHelper.createDocument();
Element dictionary = document.addElement("Dictionary");
dictionary.add(this.addChildren());
StringWriter sw = new StringWriter();
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndent(" ");
format.setTrimText(false);
XMLWriter writer = new XMLWriter(sw, format);
try {
writer.write(document);
writer.flush();
}
catch (Exception var8) {
}
mementoXml = sw.toString().replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
return encodeString(mementoXml);
}
public Element addChildren(){
Element response DocumentHelper.createElement("response");
Element el1 = response.addElement("element");
el1.setText(this.javaObject.getValue());
return response;
}
</code></pre>
<p>The method for encoding is:</p>
<pre><code>public String encodeString(String in) throws EncoderException {
CompressedBase64Impl impl = new CompressedBase64Impl();
String output = null;
output = impl.encodeBytes(in.getBytes());
return output;
}
</code></pre>
<p>What would be the modernized way in Spring boot to encode an object into a base64String. Is there something like <code>JSONWriter</code>?</p>
| [
{
"answer_id": 74381366,
"author": "Sajith Vijesekara",
"author_id": 1515665,
"author_profile": "https://Stackoverflow.com/users/1515665",
"pm_score": 0,
"selected": false,
"text": "String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());\n"
},
{
"answer_id": 74381586,
"author": "Jesse Barnum",
"author_id": 260516,
"author_profile": "https://Stackoverflow.com/users/260516",
"pm_score": 2,
"selected": true,
"text": "public class EncodeToBase64 {\n public static void main(String[] args) throws Exception {\n List<?> someObjectToSerialize = new ArrayList<>();\n System.out.println( serializeToBase64( someObjectToSerialize ) );\n }\n\n private static String serializeToBase64( Object someObjectToSerialize ) throws IOException {\n try( final ByteArrayOutputStream baos = new ByteArrayOutputStream();\n ObjectOutputStream objectOutputStream = new ObjectOutputStream( Base64.getEncoder().wrap( baos ) ) ) {\n objectOutputStream.writeObject( someObjectToSerialize );\n return baos.toString();\n }\n }\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7899320/"
] |
74,381,218 | <p>I'm trying to display a React Spinner component centered horizontally and vertically in the screen, after search and read different similar answers, for example this <a href="https://stackoverflow.com/questions/19026884/flexbox-center-horizontally-and-vertically">post</a>, I could center it horizontally, currently my code is this:</p>
<pre><code>import ClipLoader from "react-spinners/BounceLoader";
function Spinner() {
return (
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
flexDirection: "row",
}}
>
<ClipLoader color="#52bfd9" size={100} />
</div>
);
}
export default Spinner;
</code></pre>
<p>The result I'm getting is this:</p>
<p><a href="https://i.stack.imgur.com/0EJ2c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0EJ2c.png" alt="center horizontally" /></a></p>
<p>However, I'm dealing how to center it vertically, the nearest I get from the solution is this code:</p>
<pre><code><div style={{ verticalAlign: 'middle', position:'absolute', top: '50%', left: '50%', marginTop: '-100px', marginLeft: '-250px' }}>
</code></pre>
<p>But it is not centered it vertically and horizontally, please take a look at the next image:</p>
<p><a href="https://i.stack.imgur.com/t9rlc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t9rlc.png" alt="notcentered" /></a></p>
<p>My question is: do you have any recommendation how to center vertically and horizontally the div tag and the component?</p>
| [
{
"answer_id": 74381280,
"author": "davidleininger",
"author_id": 254072,
"author_profile": "https://Stackoverflow.com/users/254072",
"pm_score": 3,
"selected": true,
"text": "height: auto;"
},
{
"answer_id": 74381291,
"author": "jozef koko",
"author_id": 10489766,
"author_profile": "https://Stackoverflow.com/users/10489766",
"pm_score": 1,
"selected": false,
"text": "<div\n className=\"spinner\"\n>\n <ClipLoader color=\"#52bfd9\" size={100} />\n</div>\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4645889/"
] |
74,381,250 | <p>I have a div element "editorPathDisplay" to display a path (ex: <em>root/something/anotherthing</em>), and I want the '/' characters to be bold to distinguish the separation. To accomplish this, I am trying to populate the editorPathDisplay div with spans. The first in this example would contain "root" and have no classes, the next would contain "/" and have the class "bold", etc.</p>
<p>The bold class is working when the span contains strings, but when it only contains a slash '/', they don't appear as bold. I tried this with a different class name and different styling differences, but no class styles appear in the procedurally-added spans when they only contain a slash '/'. I've attached a code snippet below of my js and the resulting page structure (which looks right!) please let me know what I am doing wrong!</p>
<p>CODE:</p>
<pre><code>var pathDisplay = document.getElementById("editorPathDisplay");
// pathDisplay.innerHtml = "";
pathDisplay.textContent = "PATH: ";
var path = selectedObj.dataset.path;
var pathList = path.split("/");
for (var i = 0; i < pathList.length; i++) {
var unformatedSpanInsert = document.createElement("span");
unformatedSpanInsert.textContent = pathList[i]
pathDisplay.appendChild(unformatedSpanInsert);
if (i < pathList.length - 1) {
var spanInsert = document.createElement("span");
spanInsert.classList.add("bold");
spanInsert.textContent = "/"; // <- this is the only code changing between Results 1 and 2
pathDisplay.appendChild(spanInsert);
}
}
</code></pre>
<p>RESULT 1:</p>
<p><a href="https://i.stack.imgur.com/X7Zbb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X7Zbb.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/EiyM3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EiyM3.png" alt="enter image description here" /></a></p>
<p>RESULT 2:</p>
<p><code>spanInsert.textContent = "/";</code></p>
<p><a href="https://i.stack.imgur.com/KMsvo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMsvo.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/NLLhn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NLLhn.png" alt="enter image description here" /></a></p>
<p>Can someone help me figure out why it's doing this and how to fix it? If you can think of a better way to accomplish this goal, that would be helpful too. All I want is to fill the string from the path variable, but bold the slashes.</p>
<p>Thanks.</p>
| [
{
"answer_id": 74381280,
"author": "davidleininger",
"author_id": 254072,
"author_profile": "https://Stackoverflow.com/users/254072",
"pm_score": 3,
"selected": true,
"text": "height: auto;"
},
{
"answer_id": 74381291,
"author": "jozef koko",
"author_id": 10489766,
"author_profile": "https://Stackoverflow.com/users/10489766",
"pm_score": 1,
"selected": false,
"text": "<div\n className=\"spinner\"\n>\n <ClipLoader color=\"#52bfd9\" size={100} />\n</div>\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6207231/"
] |
74,381,252 | <p>is there a difference between using <strong>$emit</strong> directly and <strong>$root.$emit</strong> ?
=> <strong>this.$emit('default-choice', this.choice);</strong> & <strong>this.$root.$emit('default-choice', this.choice);</strong></p>
<p><code>`this.$emit('default-choice', this.choice);` </code></p>
<p><code>`this.$root.$emit('default-choice', this.choice);</code></p>
| [
{
"answer_id": 74381785,
"author": "kissu",
"author_id": 8816585,
"author_profile": "https://Stackoverflow.com/users/8816585",
"pm_score": 0,
"selected": false,
"text": "$emit"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19447351/"
] |
74,381,253 | <p>Uploading an inventory feed to Walmart using C# creates the feed and the feed id is returned in the response but the feed has error "Can not find any valid inventory in Feed.". When I try the upload using Postman the feed goes through with no errir. I copied the C# code from Postman into my program and I get the same results. Walmart support has been of no help. Any suggestions has to what could be wrong?</p>
<p>Here is my the code from Postman, essentially looks like the code I was using before I tried Postman:</p>
<pre><code>RestClient client = new RestClient("https://marketplace.walmartapis.com/v3/feeds?feedType=inventory&shipNode=<myshipnode>");
RestRequest request = new RestRequest(Method.POST);
client.Timeout = -1;
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Accept-Encoding", "*");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("WM_SEC.ACCESS_TOKEN", this.Credentials.Token);
request.AddHeader("WM_CONSUMER.CHANNEL.TYPE", System.Guid.NewGuid().ToString());
request.AddHeader("WM_QOS.CORRELATION_ID", this.Credentials.ConsumerId) ;
request.AddHeader("WM_SVC.NAME", "Walmart Marketplace");
request.AddHeader("Authorization", "Basic " + this.Credentials.Authorization);
request.AddFile("file", "c:\\temp\\file.json", "multipart/form-data");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
</code></pre>
<p>JSON I am sending:</p>
<pre><code>{
"InventoryHeader": {
"version": "1.4"
},
"Inventory": [
{
"sku": "X27A001-A",
"quantity": {
"unit": "EACH",
"amount": 89
}
}
]
}
</code></pre>
<p>Walmart sample JSON:</p>
<pre><code>{
"InventoryHeader": {
"version": "1.4"
},
"Inventory": [
{
"sku": "test1",
"quantity": {
"unit": "EACH",
"amount": 10
}
},
{
"sku": "894728",
"quantity": {
"unit": "EACH",
"amount": 20
}
}
]
}
</code></pre>
| [
{
"answer_id": 74382020,
"author": "Tom Libby",
"author_id": 7910521,
"author_profile": "https://Stackoverflow.com/users/7910521",
"pm_score": 0,
"selected": false,
"text": "request.AddParameter(\"file\", File.ReadAllText(\"c:\\\\temp\\\\file.json\"), \"multipart/form-data\", ParameterType.RequestBody);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7910521/"
] |
74,381,273 | <p>Basically, I want to create a loop that loops through a big range and if that cell isn't a certain value it deletes the whole column outright. I'm guessing the best way is create an union of all the ranges to delete and after the loop is done delete the whole range. I tried to do it deleting the column during the loop itself. Stepping through the subroutine was fine but if I just executed it the whole thing would freeze up. Here's a small example (I lost my code when it froze up).</p>
<pre><code>Dim NoOfRows as long
Dim Something as range
For i = 2 to NoOfRows
if not Something.offset(i,0).value = "A" and not Something.offset(i,0).value = "B" then
Something.offset(i,0).EntireRow.Delete
i = i - 1
End If
Next
</code></pre>
<p>I'm guessing this proved somewhat heavy but I wanted to make a code that was resource intensive. Thanks</p>
<p>I tried running it the described way and it crashed</p>
| [
{
"answer_id": 74382020,
"author": "Tom Libby",
"author_id": 7910521,
"author_profile": "https://Stackoverflow.com/users/7910521",
"pm_score": 0,
"selected": false,
"text": "request.AddParameter(\"file\", File.ReadAllText(\"c:\\\\temp\\\\file.json\"), \"multipart/form-data\", ParameterType.RequestBody);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20265106/"
] |
74,381,285 | <p>Consider the following code:</p>
<pre><code>typedef struct Object
{
uint8_t size;
uint8_t array[];
}Object;
</code></pre>
<p>How would I make the Object with a compile time but user defined size array?</p>
<p>After reading some stackoverflow posts and trying the code myself I now know that as long as I use at least the compiler standard C99 I can declare the Object with a custom size like this:</p>
<pre><code>Object o = {.size = 2, .array = {1, 2}};
</code></pre>
<p>But what I want is just an empty array with a custom size so instead of typing</p>
<pre><code>Object o = {.size = 5, .array = {1, 2, 3, 4, 5}};
</code></pre>
<p>i want to type something like</p>
<pre><code>Object o = {.size = 5, .array = uint8_t[5]};
</code></pre>
<p>What is also important is, that I need to know the array size at compile time and can't use dynamic memory like malloc so the typical solution of a flexible array member which is just allocated with the use of malloc wouldn't work for me.</p>
<p>Does a solution like this exist?</p>
<p>If it does not exist:
Why would the first example work (for some compilers) but just telling the compiler I need a size 10 array in the struct at compile time without initializing the values in it would not?</p>
<p>Edit:
I guess I should have made clear that my goal was to create something similar to the C++ <code>std::array</code> since with that datatype the user can just choose the size of the array without having to know the inner workings and rewriting the struct for every new size.</p>
| [
{
"answer_id": 74381322,
"author": "James Risner",
"author_id": 8864226,
"author_profile": "https://Stackoverflow.com/users/8864226",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdint.h>\n\ntypedef struct Object\n{\n uint8_t size;\n uint8_t array[5];\n} Object;\n\nint main() {\n Object o = { .size = 2, {1, 2}};\n printf(\"%d %d\\n\", o.array[0], o.array[1]);\n}\n"
},
{
"answer_id": 74381513,
"author": "Simon Goater",
"author_id": 20460267,
"author_profile": "https://Stackoverflow.com/users/20460267",
"pm_score": 0,
"selected": false,
"text": "#define MYARRAYSIZE 10\n\ntypedef struct \n{\n uint8_t size;\n uint8_t array[MYARRAYSIZE];\n}Object_t;\n"
},
{
"answer_id": 74381747,
"author": "supercat",
"author_id": 363751,
"author_profile": "https://Stackoverflow.com/users/363751",
"pm_score": 0,
"selected": false,
"text": "struct polygon { int sides; int coords[]; };\n\nstruct poly5 { int sides; int coords[10]; }\n const myPentagonn = {5, {0,-5, 4,-3, 3,5, -3,5, -4,-3} };\n\n#define myPentagon (*((struct polygon*)&myPentagonn))\n"
},
{
"answer_id": 74381774,
"author": "Ted Lyngmo",
"author_id": 7582247,
"author_profile": "https://Stackoverflow.com/users/7582247",
"pm_score": 1,
"selected": false,
"text": "Object"
},
{
"answer_id": 74381938,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 3,
"selected": true,
"text": "Object *o = &(union { Object o;\n // anonymous struct\n struct { uint8_t size; uint8_t array[N]; };\n } ) { .size = N }.o;\n"
},
{
"answer_id": 74387468,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 0,
"selected": false,
"text": "#define create_obj(name, ...) \\\ntypedef struct \\\n{ \\\n uint8_t size; \\\n uint8_t array[sizeof( (uint8_t[]){__VA_ARGS__} )]; \\\n} obj_##name; \\\n \\\nobj_##name name = \\\n{ \\\n .size = sizeof( (uint8_t[]){__VA_ARGS__} ), \\\n .array = { __VA_ARGS__ } \\\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5585649/"
] |
74,381,295 | <p>I want to write a Python program which iterates multiple lists and gets all the possible combinations of each element. I will illustrate the idea in greater detail below.</p>
<p>I have three lists as following:</p>
<pre><code>list_01=['A','B','C','D']
list_02=[2, 2.5, 3, 3.5]
list_03=['2003','2004','2005','2006','2007','2008']
</code></pre>
<p>And I would like to obtain the following output:</p>
<pre><code>A,2,2003
A,2,2004
A,2,2005
A,2,2006
A,2,2007
...
...
...
D,3.5,2006
D,3.5,2007
D,3.5,2008
</code></pre>
<p>Is there a solution for this task? Thank you so much.</p>
| [
{
"answer_id": 74381322,
"author": "James Risner",
"author_id": 8864226,
"author_profile": "https://Stackoverflow.com/users/8864226",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdint.h>\n\ntypedef struct Object\n{\n uint8_t size;\n uint8_t array[5];\n} Object;\n\nint main() {\n Object o = { .size = 2, {1, 2}};\n printf(\"%d %d\\n\", o.array[0], o.array[1]);\n}\n"
},
{
"answer_id": 74381513,
"author": "Simon Goater",
"author_id": 20460267,
"author_profile": "https://Stackoverflow.com/users/20460267",
"pm_score": 0,
"selected": false,
"text": "#define MYARRAYSIZE 10\n\ntypedef struct \n{\n uint8_t size;\n uint8_t array[MYARRAYSIZE];\n}Object_t;\n"
},
{
"answer_id": 74381747,
"author": "supercat",
"author_id": 363751,
"author_profile": "https://Stackoverflow.com/users/363751",
"pm_score": 0,
"selected": false,
"text": "struct polygon { int sides; int coords[]; };\n\nstruct poly5 { int sides; int coords[10]; }\n const myPentagonn = {5, {0,-5, 4,-3, 3,5, -3,5, -4,-3} };\n\n#define myPentagon (*((struct polygon*)&myPentagonn))\n"
},
{
"answer_id": 74381774,
"author": "Ted Lyngmo",
"author_id": 7582247,
"author_profile": "https://Stackoverflow.com/users/7582247",
"pm_score": 1,
"selected": false,
"text": "Object"
},
{
"answer_id": 74381938,
"author": "tstanisl",
"author_id": 4989451,
"author_profile": "https://Stackoverflow.com/users/4989451",
"pm_score": 3,
"selected": true,
"text": "Object *o = &(union { Object o;\n // anonymous struct\n struct { uint8_t size; uint8_t array[N]; };\n } ) { .size = N }.o;\n"
},
{
"answer_id": 74387468,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 0,
"selected": false,
"text": "#define create_obj(name, ...) \\\ntypedef struct \\\n{ \\\n uint8_t size; \\\n uint8_t array[sizeof( (uint8_t[]){__VA_ARGS__} )]; \\\n} obj_##name; \\\n \\\nobj_##name name = \\\n{ \\\n .size = sizeof( (uint8_t[]){__VA_ARGS__} ), \\\n .array = { __VA_ARGS__ } \\\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20462756/"
] |
74,381,313 | <p>I don't know enough about C#, .NET, or the MVC pattern to know exactly what is relevant to include here, but I'm pulling my hair out with a very simple change I'm working on.</p>
<p>I have a controller with a Search action (method?) that looks like:</p>
<pre><code>public string Search(int id)
{
return $"The id was {id}";
}
</code></pre>
<p>and when I hit the route I get the expected response, e.g.</p>
<pre><code>$ curl https://localhost:7180/Players/Search/1
The id was 1
</code></pre>
<p><a href="https://i.stack.imgur.com/a0udP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a0udP.png" alt="expected behavior when visiting route" /></a></p>
<p>but when I change the variable name from <code>id</code> to anything else, the behavior changes and the value goes to 0 for some reason.</p>
<pre><code>public string Search(int thing)
{
return $"The thing was {thing}";
}
</code></pre>
<pre><code>$ curl https://localhost:7180/Players/Search/1
The thing was 0
</code></pre>
<p><a href="https://i.stack.imgur.com/RSVDc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RSVDc.png" alt="unexpected behavior when visiting route" /></a></p>
<p>I thought maybe it had to do with the Model itself, because the model code at least has an <code>Id</code> attribute</p>
<pre><code> public class Player
{
public int Id { get; set; }
public string? Name { get; set; }
}
</code></pre>
<p>but renaming that variable to <code>name</code> (which seems analogous) also doesn't help.</p>
<p>So what concept am I missing here? Why can't I just rename that variable to whatever I want? Thanks in advance!</p>
<p>(I don't know how better to communicate all the different aspects of the code, so here is a <a href="https://github.com/emgrasmeder/pingpong/blob/ask-stack-overflow/Controllers/PlayersController.cs#L50" rel="nofollow noreferrer">link to the line in question, inside the project</a>)</p>
| [
{
"answer_id": 74381379,
"author": "Andrei Lazarescu",
"author_id": 4953821,
"author_profile": "https://Stackoverflow.com/users/4953821",
"pm_score": 1,
"selected": false,
"text": " // GET api/values/5\n [HttpGet(\"{id}\")]\n public virtual async Task<ActionResult<IEntity>> Get(string id)\n {\n var entity = await Repository.GetEntity(x => x.Id == id);\n if (entity == null) return NotFound();\n\n return Ok(entity);\n }\n"
},
{
"answer_id": 74381398,
"author": "John M. Wright",
"author_id": 682840,
"author_profile": "https://Stackoverflow.com/users/682840",
"pm_score": 2,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74381438,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 3,
"selected": true,
"text": "Program"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1415599/"
] |
74,381,317 | <p>I'm new to Flutter and I'm trying to output the start of the current day in UTC format.
I use Flutter 3.3.7 and Dart SDK 2.18.4.</p>
<p>First, I take the current date.</p>
<pre><code>DateTime dt = DateTime.now();
</code></pre>
<p>Next, I use extension for the DateTime class, which I implemented myself.</p>
<pre><code>extension DateTimeFromTimeOfDay on DateTime {
DateTime appliedFromTimeOfDay(TimeOfDay timeOfDay) {
return DateTime(year, month, day, timeOfDay.hour, timeOfDay.minute);
}
}
</code></pre>
<p>It outputs the same date, only with the time that I pass it via TimeOfDay class(In this case 00:00).</p>
<pre><code>dt = dt.appliedFromTimeOfDay(const TimeOfDay(hour: 0, minute: 0));
print(dt.toUtc()); //2022-11-08 21:00:00.000Z
</code></pre>
<p>But when I run this code, it outputs a date with a non-zero time.</p>
<p>I also tried adding the toUtc() method to the extension.</p>
<pre><code>extension DateTimeFromTimeOfDay on DateTime {
DateTime appliedFromTimeOfDay(TimeOfDay timeOfDay) {
return DateTime(year, month, day, timeOfDay.hour, timeOfDay.minute).toUtc();
}
}
</code></pre>
<p>That didn't work either.</p>
<p>How can I get the DateTime in UTC format with zeroed time of day? For example,
<strong>2022-11-08 00:00:00.000Z</strong></p>
| [
{
"answer_id": 74381379,
"author": "Andrei Lazarescu",
"author_id": 4953821,
"author_profile": "https://Stackoverflow.com/users/4953821",
"pm_score": 1,
"selected": false,
"text": " // GET api/values/5\n [HttpGet(\"{id}\")]\n public virtual async Task<ActionResult<IEntity>> Get(string id)\n {\n var entity = await Repository.GetEntity(x => x.Id == id);\n if (entity == null) return NotFound();\n\n return Ok(entity);\n }\n"
},
{
"answer_id": 74381398,
"author": "John M. Wright",
"author_id": 682840,
"author_profile": "https://Stackoverflow.com/users/682840",
"pm_score": 2,
"selected": false,
"text": "Program.cs"
},
{
"answer_id": 74381438,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 3,
"selected": true,
"text": "Program"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20462714/"
] |
74,381,349 | <p>How can i bold only second element in css
I want to change only >Products< but cannot change the html code.</p>
<p>`</p>
<pre><code><header>
<nav>
<a href="#">Home</a>
<a href="#">Products</a>
<a href="#">About Us</a>
<a href="#">Contacts</a>
</nav>
</header>
</code></pre>
<p>`</p>
<p>Bold only Products</p>
| [
{
"answer_id": 74381382,
"author": "Full Stack Developer",
"author_id": 20246691,
"author_profile": "https://Stackoverflow.com/users/20246691",
"pm_score": 1,
"selected": false,
"text": "header nav a:nth-child(2) {\n font-weight: bold;\n}"
},
{
"answer_id": 74381419,
"author": "Ryan Cahill",
"author_id": 9178159,
"author_profile": "https://Stackoverflow.com/users/9178159",
"pm_score": 0,
"selected": false,
"text": "font-weight: bold"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20462908/"
] |
74,381,373 | <p>My plot has <code>ylim(0,0.08)</code>, but I am only displaying up to <code>0.06</code>. The problem is, my <code>ylabel</code> is centered on a spine that is <code>0.08</code>, instead of <code>0.06</code>. Is there a way to have the label centered only on the visible spine?</p>
<p><a href="https://i.stack.imgur.com/NxXlQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NxXlQ.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74381911,
"author": "Joao_PS",
"author_id": 20262902,
"author_profile": "https://Stackoverflow.com/users/20262902",
"pm_score": -1,
"selected": false,
"text": "import matplotlib.pyplot as plt #3.5\nimport numpy as np\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 5))\n\nax1.set_yticks(np.linspace(0, 0.08, 9))\nax1.set_ylim(0, 0.08)\nax1.set_ylabel('Fraction', loc='center')\n\nax2.set_yticks(np.linspace(0, 0.06, 7))\nax2.set_ylim(0, 0.06)\nax2.set_ylabel('Fraction', loc='center')\n"
},
{
"answer_id": 74382141,
"author": "JohanC",
"author_id": 12046409,
"author_profile": "https://Stackoverflow.com/users/12046409",
"pm_score": 3,
"selected": true,
"text": "sns.despine(trim=True)"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3633487/"
] |
74,381,410 | <p>I am new to Vue and I have to fix the following issue for work. I have a Bootstrap Vue b-form-checkbox-group similar to the one bellow. The listofOption comes from backend and from legacy databses. Sometime the ColumnName is empty or null. Right now it shows null or a blank space, but I want it to print the text "_blank" if that is the case.</p>
<pre><code><b-form-checkbox-group id="flavors"
v-model="status"
:options="listofOption"
:text-field="ColumnName"
:value-field="ColumnName"
name="flavors" class="ml-4" aria-label="Individual flavours" stacked>
</b-form-checkbox-group>
</code></pre>
<p>I have replaced the :text-field with the following line but can't make it work:</p>
<pre><code>:text-field="[(ColumnName && ColumnName != null && ColumnName != '') ? ColumnName : '_blank']"
</code></pre>
| [
{
"answer_id": 74381911,
"author": "Joao_PS",
"author_id": 20262902,
"author_profile": "https://Stackoverflow.com/users/20262902",
"pm_score": -1,
"selected": false,
"text": "import matplotlib.pyplot as plt #3.5\nimport numpy as np\n\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 5))\n\nax1.set_yticks(np.linspace(0, 0.08, 9))\nax1.set_ylim(0, 0.08)\nax1.set_ylabel('Fraction', loc='center')\n\nax2.set_yticks(np.linspace(0, 0.06, 7))\nax2.set_ylim(0, 0.06)\nax2.set_ylabel('Fraction', loc='center')\n"
},
{
"answer_id": 74382141,
"author": "JohanC",
"author_id": 12046409,
"author_profile": "https://Stackoverflow.com/users/12046409",
"pm_score": 3,
"selected": true,
"text": "sns.despine(trim=True)"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16880334/"
] |
74,381,415 | <p>I have a list:</p>
<pre><code>groups = ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D']
</code></pre>
<p>I need to map each value to have an output like this, independently from the numbers of groups and elements inside:</p>
<pre><code>[0,0,0,1,1,0,0,1]
</code></pre>
<p>The values in output should switch every time when the group is changing.</p>
| [
{
"answer_id": 74381500,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "groups = ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D']\n\nflag = 0\n\nout = [flag if a==b else (flag:=1-flag) for a, b in zip(groups, groups[:1]+groups)]\n"
},
{
"answer_id": 74381705,
"author": "Nick Falco",
"author_id": 4402750,
"author_profile": "https://Stackoverflow.com/users/4402750",
"pm_score": 0,
"selected": false,
"text": "def value_switcher(groups):\n if not groups:\n return groups\n new_groups = [0]\n for i in range(1, len(groups)):\n if groups[i-1] != groups[i]:\n if new_groups[i-1] == 0:\n new_groups.append(1)\n else:\n new_groups.append(0)\n else:\n new_groups.append(new_groups[i-1])\n return new_groups\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13826532/"
] |
74,381,432 | <p>I would like to be able to modify the body, html and the * of the <code>login</code> component but impossible to do this. I'm desperate, do you have a solution please?</p>
<p><a href="https://stackblitz.com/github/kora1348/red?file=README.md" rel="nofollow noreferrer">Stackblitz</a></p>
<p>login.component.css</p>
<pre><code>@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: red;
}
...
</code></pre>
| [
{
"answer_id": 74381500,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "groups = ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D']\n\nflag = 0\n\nout = [flag if a==b else (flag:=1-flag) for a, b in zip(groups, groups[:1]+groups)]\n"
},
{
"answer_id": 74381705,
"author": "Nick Falco",
"author_id": 4402750,
"author_profile": "https://Stackoverflow.com/users/4402750",
"pm_score": 0,
"selected": false,
"text": "def value_switcher(groups):\n if not groups:\n return groups\n new_groups = [0]\n for i in range(1, len(groups)):\n if groups[i-1] != groups[i]:\n if new_groups[i-1] == 0:\n new_groups.append(1)\n else:\n new_groups.append(0)\n else:\n new_groups.append(new_groups[i-1])\n return new_groups\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18427717/"
] |
74,381,482 | <p>I have two tables with one referencing the other.</p>
<pre><code>CREATE TABLE blogs (
article LONGTEXT,
id VARCHAR(255) PRIMARY KEY
);
CREATE TABLE blog_eval (
blog_id VARCHAR(255) REFERENCES blogs(id) ON DELETE CASCADE,
user_id VARCHAR(255) REFERENCES users(id),
is_like BOOLEAN, --true if like / false if dislike
PRIMARY KEY (blog_id, user_id)
);
</code></pre>
<p>I need all blogs with two additional columns: sum of likes and sum of dislikes.</p>
<p>How do I combine a JOIN with the COUNT function and also distinguish between likes and dislikes?</p>
| [
{
"answer_id": 74381500,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "groups = ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D']\n\nflag = 0\n\nout = [flag if a==b else (flag:=1-flag) for a, b in zip(groups, groups[:1]+groups)]\n"
},
{
"answer_id": 74381705,
"author": "Nick Falco",
"author_id": 4402750,
"author_profile": "https://Stackoverflow.com/users/4402750",
"pm_score": 0,
"selected": false,
"text": "def value_switcher(groups):\n if not groups:\n return groups\n new_groups = [0]\n for i in range(1, len(groups)):\n if groups[i-1] != groups[i]:\n if new_groups[i-1] == 0:\n new_groups.append(1)\n else:\n new_groups.append(0)\n else:\n new_groups.append(new_groups[i-1])\n return new_groups\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19700822/"
] |
74,381,483 | <p>This code finds the intersection of two polygons and create a polygon out of the intersection. My aim is to do the exact <code>opposite</code>. I would like to create a polygone which has a hole in it in others words it excludes the intersection from the big polygone.</p>
<p>The code i managed to construct is:</p>
<pre><code>from shapely.geometry import shape,Polygon,MultiPolygon,mapping
import geopandas as gpd
g1 = geomap
print(geomap)
g2 = geomap_world
print(geomap_world)
data=[]
for index, orig in g1.iterrows():
for index2, ref in g2.iterrows():
if ref['geometry'].intersects(orig['geometry']):
data.append({'geometry':ref['geometry'].intersection(orig['geometry'])})
df = gpd.GeoDataFrame(data,columns=['geometry'])
</code></pre>
<p>where df is :</p>
<pre><code>162 POLYGON ((-2.16991 35.16840, -1.79299 34.52792...
</code></pre>
<p>But I am looking to construct the opposite result which is a polygone that excludes the intersection. Any hint?</p>
<p>I also tried <code>symmetric_difference</code> instead of <code>intersection</code> as follows:</p>
<pre><code>data=[]
for index, orig in g1.iterrows():
for index2, ref in g2.iterrows():
if ref['geometry'].symmetric_difference(orig['geometry']):
data.append({'geometry':ref['geometry'].symmetric_difference(orig['geometry'])})
df = gpd.GeoDataFrame(data,columns=['geometry'])
</code></pre>
<p>The result is a polygon that is equal to the intersection i would like to exclude. Where I am going wrong?</p>
| [
{
"answer_id": 74383495,
"author": "swatchai",
"author_id": 2177413,
"author_profile": "https://Stackoverflow.com/users/2177413",
"pm_score": 2,
"selected": true,
"text": "difference"
},
{
"answer_id": 74388904,
"author": "bravopapa",
"author_id": 20176161,
"author_profile": "https://Stackoverflow.com/users/20176161",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\nimport numpy as np\nimport re \n# Geospatial libraries\nimport geopandas as gpd \nimport glob \nfrom shapely.geometry import shape,Polygon,MultiPolygon,mapping, LineString, Point \n\n#geomap contains the polygon that i would like to extract (ref)\ngeomap = import_shapes_list(path_to_data,shapes_folder,crs='EPSG:4326')\n\nworld = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\n# world contains the big polygon (orig)\ngeomap_world=world[world['name']=='Morocco']\n\n\ng1=gpd.GeoDataFrame({'geometry': geomap.geometry, 'df1':[1]})\ng2=gpd.GeoDataFrame({'geometry': geomap_world.geometry, 'df2':[1]})\n# double iteration through the coordinates and takes the `difference` between polygones\ndata=[]\nfor index, orig in g1.iterrows():\n for index2, ref in g2.iterrows():\n if ref['geometry'].difference(orig['geometry']): \n data.append({'geometry':ref['geometry'].difference(orig['geometry'])}) \n\n\ndf = gpd.GeoDataFrame(data,columns=['geometry'])\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20176161/"
] |
74,381,503 | <p>I see a code as below in <a href="https://github.com/terraform-aws-modules/terraform-aws-efs/blob/master/examples/complete/main.tf#L58" rel="nofollow noreferrer">https://github.com/terraform-aws-modules/terraform-aws-efs/blob/master/examples/complete/main.tf#L58</a></p>
<pre><code> # Mount targets / security group
mount_targets = { for k, v in toset(range(length(local.azs))) :
element(local.azs, k) => { subnet_id = element(module.vpc.private_subnets, k) }
}
</code></pre>
<p>I am trying to understand what => means here. Also this command with for loop, element and =>.
Could anyone explain here please?</p>
| [
{
"answer_id": 74396122,
"author": "Martin Atkins",
"author_id": 281848,
"author_profile": "https://Stackoverflow.com/users/281848",
"pm_score": 2,
"selected": true,
"text": "=>"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3217396/"
] |
74,381,519 | <p>I have one service which requires the data of date and time which I am collecting from my database.
The data in the database is stored according to the UTC time zone.
Now I want to get those data from the data and present it to the user in the time zone whatever the want it to be in or just so the data of time and data as per there systems default time zone.
As right now I have some hard coded thing that makes the changes if the Daylight Saving Time changes
For example I the DST starts it substracts 4 hours(as per EDT) from the data that is in the system and if the DST ends I have to manually change the substracted hour with 5(as per EST) hours and the present it to the user.</p>
<p>I am currently doing it as bellow</p>
<p>Here I m using</p>
<ol>
<li><p>Date from java.util.Date</p>
</li>
<li><p>getObtainedDate is for getting data from the database</p>
</li>
<li><p>I have added this minus so that it will substract that amount of time from the date.</p>
<p>Instant ins = attachment.getObtainedDate().toInstant();
ins = ins.minus(5, Chronounit.HOURS); // without DST
Date alteredDate = Date.from(ins);</p>
<p>Instant ins = attachment.getObtainedDate().toInstant();
ins = ins.minus(4, ChronoUnit.HOURS); // during DST
Date alteredDate = Date.from(ins);</p>
</li>
</ol>
<p>I want to get rid of this hard coded thing as I have to manually change the 5 and 4 whenever the DST starts and ends.</p>
<p>Thank you in advance</p>
| [
{
"answer_id": 74381686,
"author": "Basil Bourque",
"author_id": 642706,
"author_profile": "https://Stackoverflow.com/users/642706",
"pm_score": 2,
"selected": false,
"text": "myResultSet\n.getObject( … , OffsetDateTime.class ) // Returns a `OffsetDateTime` object, the appropriate class mapping to the standard SQL type `TIMESTAMP WITH TIME ZONE`. \n.atZoneSameInstant( ZoneId.of( \"America/New_York\" ) ) // Returns a `ZonedDateTime` object. \n"
},
{
"answer_id": 74393271,
"author": "Patel Harsh",
"author_id": 18243455,
"author_profile": "https://Stackoverflow.com/users/18243455",
"pm_score": 0,
"selected": false,
"text": "Date date = attachment.getObtainedDate(); // for getting the date in the system\n// Here I m setting the zone to system default\nZoneId zoneId = ZoneId.systemDefault(); // for setting the zoneId as per the location you want\nZonedDateTime zonedDateTime = Instant.ofEpochMilli(date.getTime()).atZone(zoneId);\n\n// for formatting date and time\nDateTimeFormatter dtf = DateTimeFormatter.ofPattern(\"MM/dd/yyyy HH:mm\");\nString requiredDate = zonedDateTime.format(dtf);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18243455/"
] |
74,381,537 | <p>Let's took a look a this functional component :</p>
<p>note : this is just an exemple</p>
<pre><code>function Foo() {
const [data, setData] = useState([]);
const GetData = () => {
//setting the data...
setData([1, 2, 3]);
}
const ShowData = (data) => {
if(data)
console.log(data);
}
useEffect( () => {
GetData();
ShowData(data)
},[]);
console.log(data) // Here I get the new data normally;
return (
<>
<h2>Hello world ! </h2>
</>
)}
</code></pre>
<p>So my question is how can I get the updated value ( the new value of data ) to use it inside ShowData function ?</p>
| [
{
"answer_id": 74381680,
"author": "Beatriz Infante",
"author_id": 7773975,
"author_profile": "https://Stackoverflow.com/users/7773975",
"pm_score": 2,
"selected": true,
"text": "useEffect( () => {\n GetData(); \n},[]); \n\nuseEffect( () => {\n ShowData()\n},[data]); // runs when data is updated\n"
},
{
"answer_id": 74381778,
"author": "Henrik Maaland",
"author_id": 11524115,
"author_profile": "https://Stackoverflow.com/users/11524115",
"pm_score": 0,
"selected": false,
"text": "useEffect(() => {\n GetData();\n},[]);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17500542/"
] |
74,381,540 | <p>Find the smallest number M, which is divided by exactly n-1 numbers from the input array. If there is no such M then return -1.</p>
<p><strong>Example:</strong></p>
<pre><code>array = [2,3,5]
</code></pre>
<p><strong>Answer :</strong></p>
<pre><code>6
</code></pre>
<p><strong>Explanation :</strong></p>
<pre><code>6 can be divided by 2 and 3
</code></pre>
<p><strong>Example:</strong></p>
<pre><code>array = [2,3,6]
</code></pre>
<p><strong>Answer:</strong></p>
<pre><code> -1
</code></pre>
<p><strong>Explanation :</strong></p>
<pre><code>It's not possible in this case so return -1.
</code></pre>
<p>My code:</p>
<p>As we need to find the smallest <code>M</code>, I am selecting only the elements from 0 to n-2</p>
<pre><code>public int process(int[] arr) {
int answer = 1;
for(int i=0; i<arr.length-1; i++) {
answer *= arr[i];
}
return answer;
}
</code></pre>
<p>This program works for these 2 sample test cases but it was failing for multiple hidden test cases. I trying to understand what I am missing here.</p>
| [
{
"answer_id": 74381869,
"author": "frankfalse",
"author_id": 18108367,
"author_profile": "https://Stackoverflow.com/users/18108367",
"pm_score": 2,
"selected": false,
"text": "public int lowerCommonMultiple(int x1, int x2)"
},
{
"answer_id": 74382113,
"author": "Pentragon",
"author_id": 19010882,
"author_profile": "https://Stackoverflow.com/users/19010882",
"pm_score": 0,
"selected": false,
"text": "process()"
},
{
"answer_id": 74386154,
"author": "Maurice Perry",
"author_id": 7036419,
"author_profile": "https://Stackoverflow.com/users/7036419",
"pm_score": 2,
"selected": true,
"text": "process"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3181365/"
] |
74,381,545 | <p>I have done some programming in the past, so I would be able to figure this problem out in a programming language. But, I do not know how to proceed with accomplishing my task in an Excel spreadsheet. Any kind of guidance would be helpful because I am not familiar with anything but a basic use of MS Excel, so I don't even know which topics to search for to get some guidance on solving this problem.</p>
<p>Here is the breakdown for my problem:</p>
<p>I work for a construction company and I am keeping count of the number of days which need to be extended to a schedule deadline. All "lost weather days" are in a column (assume they are in chronological order and there are not bad dates like 2/32/22).</p>
<p>Contractually, we eat the first 5 lost weather days for any given month. But, if there are more than 5 lost weather days in any given month, then I need to add those days to a count by which the schedule deadline can be extended. So, any time a month has more than 5 lost weather days, I need to start counting.</p>
<p>For example:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th><strong>DATE</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>1/1/23</td>
</tr>
<tr>
<td>1/2/23</td>
</tr>
<tr>
<td>1/13/23</td>
</tr>
<tr>
<td>1/14/23</td>
</tr>
<tr>
<td>1/25/23</td>
</tr>
<tr>
<td><strong>1/26/23</strong></td>
</tr>
<tr>
<td><strong>1/27/23</strong></td>
</tr>
<tr>
<td>2/1/23</td>
</tr>
<tr>
<td>2/12/23</td>
</tr>
</tbody>
</table>
</div>
<p>Here, 1/6/23 and 1/7/23 need to be counted while all of the other dates are ignored because 1/1/22, 1/2/22, 1/3/22, 1/4/22, and 1/5/22 are the first five days in January 2023. So, I should have a cell with a value of 2.</p>
<p>Any help or guidance would be appreciated. Thank you.</p>
<p>I haven't tried anything specific because I am unfamiliar with excel at the moment.</p>
| [
{
"answer_id": 74381661,
"author": "Scott Craner",
"author_id": 4851590,
"author_profile": "https://Stackoverflow.com/users/4851590",
"pm_score": 1,
"selected": false,
"text": "=LET(rng,A2:A10,uq,UNIQUE(DATE(YEAR(rng),MONTH(rng),1)),SUM(BYROW(uq,LAMBDA(a,MAX(0,COUNTIFS(A2:A10,\">=\"&a,A2:A10,\"<\"&EOMONTH(a,0)+1)-5)))))\n"
},
{
"answer_id": 74385253,
"author": "P.b",
"author_id": 12634230,
"author_profile": "https://Stackoverflow.com/users/12634230",
"pm_score": 2,
"selected": false,
"text": "=LET(m,EOMONTH(TRANSPOSE(A2:A10),0),\n f,FREQUENCY(m,m),\nSUM(IF(f>5,f-5)))\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20412030/"
] |
74,381,560 | <p>I'm not sure how to ignore files on .gitignore, I think it has 3 options but I don't know the correct one</p>
<ol>
<li>/node_modules</li>
<li>.node_modules</li>
<li>.node_modules/</li>
</ol>
<p>Please, can you tell me which is the correct one or if none of the 3 works, can you tell me how to ignore files on .gitignore?</p>
<p>I really appreciate any help you can provide.</p>
| [
{
"answer_id": 74381661,
"author": "Scott Craner",
"author_id": 4851590,
"author_profile": "https://Stackoverflow.com/users/4851590",
"pm_score": 1,
"selected": false,
"text": "=LET(rng,A2:A10,uq,UNIQUE(DATE(YEAR(rng),MONTH(rng),1)),SUM(BYROW(uq,LAMBDA(a,MAX(0,COUNTIFS(A2:A10,\">=\"&a,A2:A10,\"<\"&EOMONTH(a,0)+1)-5)))))\n"
},
{
"answer_id": 74385253,
"author": "P.b",
"author_id": 12634230,
"author_profile": "https://Stackoverflow.com/users/12634230",
"pm_score": 2,
"selected": false,
"text": "=LET(m,EOMONTH(TRANSPOSE(A2:A10),0),\n f,FREQUENCY(m,m),\nSUM(IF(f>5,f-5)))\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19628878/"
] |
74,381,567 | <p>How to prevent exposure of sensitive files while keeping them in the local repository?</p>
<p>Scenario: I have sensitive files in my local repo. As a security measure, I specify those files in .gitignore file, so they are not pushed to the remote. A collaborator deletes my .gitignore file and pushes that change to the remote repo. I pull his changes. My sensitive files are not ignored anymore and I will push them accidentally to the remote. My sensitive files are now exposed.</p>
<p>Can scenario like this happen? How to prevent it?</p>
| [
{
"answer_id": 74381901,
"author": "acran",
"author_id": 11932806,
"author_profile": "https://Stackoverflow.com/users/11932806",
"pm_score": 2,
"selected": false,
"text": ".gitignore"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19067446/"
] |
74,381,574 | <p>There's a part of my schoolwork. I need to give an error output when user doesn't give an second input, but as you know python gives an error itself when you don't give the second output. Is there any way to do that or do I have to change my implementation?
I have to check the second argument that's why I am getting the arguments seperately.
I tried this but obviously it didn't work:</p>
<pre><code> option, person = input("Choose an option and person: ").split()
if person==None:
print("Missing argument")
</code></pre>
<p>Also sorry for my poorly written code I just started learning..</p>
| [
{
"answer_id": 74381901,
"author": "acran",
"author_id": 11932806,
"author_profile": "https://Stackoverflow.com/users/11932806",
"pm_score": 2,
"selected": false,
"text": ".gitignore"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463011/"
] |
74,381,583 | <p>I apologize for not knowing the correct terminology, but I am looking for a way in Pandas to transform a data frame with several similar columns into a data frame with rows that explode? into more rows. Basically for every column that starts with Line.{x}, I want to create a new row that has all the Line.{x} columns. Same for all columns with values in {x}, e.g. 1,2,3.</p>
<p>Here is an example of a data frame I'd like to convert from:</p>
<pre><code> Column1 Column2 Column3 Column4 Line.0.a Line.0.b Line.0.c Line.1.a Line.1.b Line.1.c Line.2.a Line.2.b Line.2.c Line.3.a Line.3.b Line.3.c
0 the quick brown dog 100 200 300 400 500 600 700 800 900 1000 1100 1200
1 you see spot run 101 201 301 401 501 601
2 four score and seven 102 202 302
</code></pre>
<p>I would like to convert it to this:</p>
<pre><code> Column1 Column2 Column3 Column4 Line.a Line.b Line.c
0 the quick brown dog 100 200 300
1 the quick brown dog 400 500 600
2 the quick brown dog 700 800 900
3 the quick brown dog 1000 1100 1200
4 you see spot run 101 201 301
5 you see spot run 401 501 601
6 four score and seven 102 202 302
</code></pre>
<p>Thank you in advance!</p>
| [
{
"answer_id": 74381901,
"author": "acran",
"author_id": 11932806,
"author_profile": "https://Stackoverflow.com/users/11932806",
"pm_score": 2,
"selected": false,
"text": ".gitignore"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16053979/"
] |
74,381,654 | <p>For the get_gc_stats( ) function:
The first value in the returned list will be the minimum GC value in the dictionary
The second value in the returned list will be the maximum GC value in the dictionary
The third value in the returned list will be the average GC value from the dictionary
Assuming the dictionary is:</p>
<pre><code>dna_dict = {
'TAGC' : [0.5, 4],
'ACGTATGC' : [0.5, 8],
'ATG' : [0.3333333333333333, 3],
'ACGGCTAG' : [0.625, 8]
}
</code></pre>
<p>I am going through this problem and I am getting confused on what to do. I think I need to go through each value in the dictionary and get the max, min, and average of the number that is in index 0. However I need more guidance.</p>
<p>This is my code</p>
<pre><code>def get_gc_stats(dna_dict):
for key, value in dna_dict.items():
for i in value[0]:
</code></pre>
| [
{
"answer_id": 74381901,
"author": "acran",
"author_id": 11932806,
"author_profile": "https://Stackoverflow.com/users/11932806",
"pm_score": 2,
"selected": false,
"text": ".gitignore"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20113635/"
] |
74,381,667 | <p>I have two tables, on is called <em>df_information</em>. This table just have information about each user. Here is how it looks:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">id_user</th>
<th style="text-align: center;">job_function</th>
<th style="text-align: center;">job_area</th>
<th style="text-align: center;">title</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Compensation / Benefit Policy</td>
<td style="text-align: center;">Human Resources</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">HR Systems Administration</td>
<td style="text-align: center;">Human Resources</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Cyber Security / Information Security</td>
<td style="text-align: center;">IT / Computers / Electronic</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1125</td>
<td style="text-align: center;">Equipment</td>
<td style="text-align: center;">Manufacturing / Production / Operations</td>
<td style="text-align: center;">manager</td>
</tr>
<tr>
<td style="text-align: center;">1602</td>
<td style="text-align: center;">Product Development</td>
<td style="text-align: center;">IT / Computers / Electronics</td>
<td style="text-align: center;">director</td>
</tr>
</tbody>
</table>
</div>
<p>And I have second table that is called <em>df_all_possible_job_function_job_area</em>. This table has job_function and job_area combinations that are not included in <em>df_information</em> for each title.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">job_function</th>
<th style="text-align: center;">job_area</th>
<th style="text-align: center;">title</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">ASIC / Layout Design</td>
<td style="text-align: center;">TwoIT / Computers / Electronics</td>
<td style="text-align: center;">director</td>
</tr>
<tr>
<td style="text-align: center;">Accounting</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">Accounts Payable</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">Account Management</td>
<td style="text-align: center;">Customer Support / Client Services</td>
<td style="text-align: center;">personnel</td>
</tr>
</tbody>
</table>
</div>
<p>I want to merge <em>df_information</em> with <em>df_all_possible_job_function_job_area</em>, but the thing is each job_function, job_area combination for each title in df_information should be merged for every id_user, for example if merging two small dataframe above, something like this should be gotten in result:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">id_user</th>
<th style="text-align: center;">job_function</th>
<th style="text-align: center;">job_area</th>
<th style="text-align: center;">title</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Compensation / Benefit Policy</td>
<td style="text-align: center;">Human Resources</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Accounting</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Accounting</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Accounts Payable</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1123</td>
<td style="text-align: center;">Account Management</td>
<td style="text-align: center;">Customer Support / Client Services</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">HR Systems Administration</td>
<td style="text-align: center;">Human Resources</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Cyber Security / Information Security</td>
<td style="text-align: center;">IT / Computers / Electronic</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Accounting</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Accounting</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Accounts Payable</td>
<td style="text-align: center;">Finance / Accounting</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1124</td>
<td style="text-align: center;">Account Management</td>
<td style="text-align: center;">Customer Support / Client Services</td>
<td style="text-align: center;">personnel</td>
</tr>
<tr>
<td style="text-align: center;">1125</td>
<td style="text-align: center;">Equipment</td>
<td style="text-align: center;">Manufacturing / Production / Operations</td>
<td style="text-align: center;">manager</td>
</tr>
<tr>
<td style="text-align: center;">1602</td>
<td style="text-align: center;">Product Development</td>
<td style="text-align: center;">IT / Computers / Electronics</td>
<td style="text-align: center;">director</td>
</tr>
<tr>
<td style="text-align: center;">1602</td>
<td style="text-align: center;">ASIC / Layout Design</td>
<td style="text-align: center;">TwoIT / Computers / Electronics</td>
<td style="text-align: center;">director</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74381901,
"author": "acran",
"author_id": 11932806,
"author_profile": "https://Stackoverflow.com/users/11932806",
"pm_score": 2,
"selected": false,
"text": ".gitignore"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19199709/"
] |
74,381,668 | <p>I recently asked a question about a contact form animation (the label text moves up when the box is clicked) and while I got the animation to work properly, I've run into a bug:</p>
<p>When I click on either the first and second boxes (not the third for some reason), it activates the animation for the rest of the boxes which is very annoying.</p>
<p>How can I get it so that when clicking on one box, it ONLY animates the box I clicked on and not the rest?</p>
<pre><code><div class="contact-col" style="position:relative display:inline;" >
<input type="text" name="name" required>
<span id="floating-label">Yourname</span>
<input type="email" name="email" required>
<span id="floating-label-1">Your email</span>
<input type="text" name="subject" required>
<span id="floating-label-2">Subject</span>
</div>
</code></pre>
<pre><code>.contact-col input, .contact-col textarea{
width: 100%;
padding: 15px;
margin-bottom: 25px;
outline: none;
font-family: 'Merriweather Sans', sans-serif;
font-weight: 300;
font-size: 16px;
border: 1px solid #ccc;
box-sizing: border-box;
}
.contact-col input:focus, .contact-col textarea:focus {
border: 1px solid yellowgreen;
box-shadow: 0 0 0 1px #8C7D50;
transition: 25ms box-shadow ease-in-out;
}
input:focus ~ #floating-label,
input:not(:focus):valid ~ #floating-label{
top: -0.5%;
left: 0.5rem;
padding: 0.5rem;
font-size: 14px;
color: #8C7D50 ;
font-weight: 400;
transition: 0.2s ease-in-out;
}
#floating-label {
font-family: 'Merriweather Sans', sans-serif;
font-weight: 300;
font-size: 16px;
position: absolute;
pointer-events: none;
left: 1rem;
transform: translateY(-50%);
top: 4.5%;
color: #777;
background: white;
transition: 0.2s ease all;
}
#floating-label-1{
font-family: 'Merriweather Sans', sans-serif;
font-weight: 300;
font-size: 16px;
position: absolute;
pointer-events: none;
left: 1rem;
transform: translateY(-50%);
top: 19%;
color: #777;
background: white;
transition: 0.2s ease all;
}
input:focus ~ #floating-label-1,
input:not(:focus):valid ~ #floating-label-1{
top: 14.25%;
left: 0.5rem;
padding: 0.5rem;
font-size: 14px;
color: #8C7D50 ;
font-weight: 400;
transition: 0.2s ease-in-out;
}
#floating-label-2{
font-family: 'Merriweather Sans', sans-serif;
font-weight: 300;
font-size: 16px;
position: absolute;
pointer-events: none;
left: 1rem;
transform: translateY(-50%);
top: 33.5%;
color: #777;
background: white;
transition: 0.2s ease all;
}
input:focus ~ #floating-label-2,
input:not(:focus):valid ~ #floating-label-2{
top: 28.5%;
left: 0.5rem;
padding: 0.5rem;
font-size: 14px;
color: #8C7D50 ;
font-weight: 400;
transition: 0.2s ease-in-out;
}
</code></pre>
| [
{
"answer_id": 74381768,
"author": "Mithat Ercan",
"author_id": 13456625,
"author_profile": "https://Stackoverflow.com/users/13456625",
"pm_score": 3,
"selected": true,
"text": "\n.contact-col input,\n.contact-col textarea {\n width: 100%;\n padding: 15px;\n margin-bottom: 25px;\n outline: none;\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n border: 1px solid #ccc;\n box-sizing: border-box;\n}\n\n.contact-col input:focus,\n.contact-col textarea:focus {\n border: 1px solid yellowgreen;\n box-shadow: 0 0 0 1px #8c7d50;\n transition: 25ms box-shadow ease-in-out;\n}\n\ninput[name='name']:focus ~ #floating-label,\ninput[name='name']:not(:focus):valid ~ #floating-label {\n top: -0.5%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n#floating-label {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 4.5%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\n#floating-label-1 {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 19%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\ninput[name='email']:focus ~ #floating-label-1,\ninput[name='email']:not(:focus):valid ~ #floating-label-1 {\n top: 14.25%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n#floating-label-2 {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 33.5%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\ninput[name='subject']:focus ~ #floating-label-2,\ninput[name='subject']:not(:focus):valid ~ #floating-label-2 {\n top: 28.5%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n\n"
},
{
"answer_id": 74382090,
"author": "Nevah5",
"author_id": 16029189,
"author_profile": "https://Stackoverflow.com/users/16029189",
"pm_score": 1,
"selected": false,
"text": "input:focus ~ #floating-label,\ninput:not(:focus):valid ~ #floating-label{\n //...\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19991177/"
] |
74,381,687 | <p>I have JSONL file as text - string, its a very big file and not useful to convert to standard JSON:</p>
<pre><code>{"id":"gid:\/\/shopify\/ProductVariant\/32620848382088","__parentId":"gid:\/\/shopify\/Product\/4632300847240"}
{"id":"gid:\/\/shopify\/Product\/4632300912776"}
{"namespace":"daily_deals","key":"status","value":"inactive","__parentId":"gid:\/\/shopify\/Product\/4632300912776"}
{"namespace":"daily_deals","key":"endtime","value":"1604966400000","__parentId":"gid:\/\/shopify\/Product\/4632300912776"}
{"id":"gid:\/\/shopify\/ProductVariant\/32620848447624","__parentId":"gid:\/\/shopify\/Product\/4632300912776"}
{"id":"gid:\/\/shopify\/Product\/4632301011080"}
{"namespace":"daily_deals","key":"status","value":"inactive","__parentId":"gid:\/\/shopify\/Product\/4632301011080"}
{"namespace":"daily_deals","key":"endtime","value":"1604966400000","__parentId":"gid:\/\/shopify\/Product\/4632301011080"}
{"id":"gid:\/\/shopify\/ProductVariant\/32620848808072","__parentId":"gid:\/\/shopify\/Product\/4632301011080"}
{"id":"gid:\/\/shopify\/ProductVariant\/39402297720968","__parentId":"gid:\/\/shopify\/Product\/4632301011080"}
{"id":"gid:\/\/shopify\/Product\/4673135444104"}
</code></pre>
<p>I want to solve problem at frontend so I need to use javascript
.
How I can using regex to select only rows which contain text: <strong>"gid://shopify/Product/4632301011080"</strong> and <strong>"namespace":"daily_deals"</strong> ?
So I need whole row from { to } if contain text</p>
<p>Is the best solution to use regex or some other technic? Please suggest? The text JSONL file is average 10mb so I think it wont affect browser memory a lot.</p>
<p><em><strong>UPDATE:</strong></em>
All rows I want to search starts with <code>{"namespace":</code> and other onces I want to ignore because of performance</p>
| [
{
"answer_id": 74381768,
"author": "Mithat Ercan",
"author_id": 13456625,
"author_profile": "https://Stackoverflow.com/users/13456625",
"pm_score": 3,
"selected": true,
"text": "\n.contact-col input,\n.contact-col textarea {\n width: 100%;\n padding: 15px;\n margin-bottom: 25px;\n outline: none;\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n border: 1px solid #ccc;\n box-sizing: border-box;\n}\n\n.contact-col input:focus,\n.contact-col textarea:focus {\n border: 1px solid yellowgreen;\n box-shadow: 0 0 0 1px #8c7d50;\n transition: 25ms box-shadow ease-in-out;\n}\n\ninput[name='name']:focus ~ #floating-label,\ninput[name='name']:not(:focus):valid ~ #floating-label {\n top: -0.5%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n#floating-label {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 4.5%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\n#floating-label-1 {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 19%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\ninput[name='email']:focus ~ #floating-label-1,\ninput[name='email']:not(:focus):valid ~ #floating-label-1 {\n top: 14.25%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n#floating-label-2 {\n font-family: 'Merriweather Sans', sans-serif;\n font-weight: 300;\n font-size: 16px;\n position: absolute;\n pointer-events: none;\n left: 1rem;\n transform: translateY(-50%);\n top: 33.5%;\n color: #777;\n background: white;\n transition: 0.2s ease all;\n}\n\ninput[name='subject']:focus ~ #floating-label-2,\ninput[name='subject']:not(:focus):valid ~ #floating-label-2 {\n top: 28.5%;\n left: 0.5rem;\n padding: 0.5rem;\n font-size: 14px;\n color: #8c7d50;\n font-weight: 400;\n transition: 0.2s ease-in-out;\n}\n\n\n"
},
{
"answer_id": 74382090,
"author": "Nevah5",
"author_id": 16029189,
"author_profile": "https://Stackoverflow.com/users/16029189",
"pm_score": 1,
"selected": false,
"text": "input:focus ~ #floating-label,\ninput:not(:focus):valid ~ #floating-label{\n //...\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6310798/"
] |
74,381,725 | <p>My problem is that I want to convert this type of pieces of string into tuples. But I want the word to be a string and the number to be an integer. Is there some simple solution for this problem?</p>
<pre><code>mystring = "(Ilioupoli,2)"
</code></pre>
<p>The output should be:</p>
<pre><code>("Ilioupoli", 2)
</code></pre>
<p>I've been looking for some solutions but didn't find the solution for this one. I've found solutions to convert string of numbers into tuples with "map" but it doesn't fit well here.</p>
| [
{
"answer_id": 74381752,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 1,
"selected": false,
"text": "()"
},
{
"answer_id": 74381776,
"author": "mudi loodi",
"author_id": 11962536,
"author_profile": "https://Stackoverflow.com/users/11962536",
"pm_score": 0,
"selected": false,
"text": "()"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463128/"
] |
74,381,739 | <p>previously I posted a question here (<a href="https://stackoverflow.com/questions/74214912/create-a-list-from-json-file-with-multiple-values/74215028#74215028">Create a list from json file, with multiple values</a>). However, I found some of my keys are outdated, and they contain a key called "end". I was not able to filter them out, making the data erratic.</p>
<p>Here's the updated JSON that I use for testing:</p>
<pre class="lang-json prettyprint-override"><code>[
{
"primary": "JOHN DOE",
"attributes": [
{
"type": "double",
"name": "BUILDING_NUMBER",
"value": "123"
},
{
"type": "double",
"name": "FLOOR",
"value": 10
},
{
"type": "string",
"name": "EMAIL",
"value": "john.doe@contoso.com"
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "SALESMAN"
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "TRAINEE",
"end": "11-09-2022"
}
],
"aliases": [
{
"alias": "joao.doe@contoso.com"
}
]
},
{
"primary": "LORRAINE DOE",
"attributes": [
{
"type": "double",
"name": "BUILDING_NUMBER",
"value": 456
},
{
"type": "double",
"name": "FLOOR",
"value": 10
},
{
"type": "string",
"name": "STATUS",
"value": "Unavaliable"
},
{
"type": "string",
"name": "EMAIL",
"value": "lorraine.doe@contoso.com"
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "Procurement",
"end": "11-09-2021"
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "SECRETARY"
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "SALES",
"end": "11-09-2021"
}
],
"aliases": [
{
"alias": "lorris.doe@contoso.com"
},
{
"alias": "lorris2.doe@contoso.com"
}
]
},
{
"primary": "JACK DOE",
"attributes": [
{
"type": "double",
"name": "BUILDING_NUMBER",
"value": "123"
},
{
"type": "double",
"name": "FLOOR",
"value": 10
},
{
"type": "string",
"name": "JOB_TITLE",
"value": "OWNER"
}
],
"aliases": [
{
"alias": "jack.doe@contoso.com"
},
{
"alias": "jackson.doe@contoso.com"
}
]
},
{
"primary": "NOAH DOE",
"attributes": [
{
"type": "double",
"name": "BUILDING_NUMBER",
"value": "123"
},
{
"type": "double",
"name": "FLOOR",
"value": 10
},
{
"type": "string",
"name": "EMAIL",
"value": "noah.doe@contoso.com"
}
],
"aliases": [
{
"alias": "noah.doe95@contoso.com"
}
]
}
]
</code></pre>
<p>Is there a way to filter out the attributes with key "end" and make the result as below?</p>
<pre><code>"john.doe@contoso.com": "SALESMAN",
"lorraine.doe@contoso.com": "SECRETARY"
</code></pre>
<p>This is the old solution:</p>
<pre><code>.[].attributes | from_entries
| select(has("JOB_TITLE") and has("EMAIL"))
| "\"\(.EMAIL)\": \"\(.JOB_TITLE)\""
</code></pre>
| [
{
"answer_id": 74381752,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 1,
"selected": false,
"text": "()"
},
{
"answer_id": 74381776,
"author": "mudi loodi",
"author_id": 11962536,
"author_profile": "https://Stackoverflow.com/users/11962536",
"pm_score": 0,
"selected": false,
"text": "()"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4951263/"
] |
74,381,754 | <p>How can i move 3 items from list a to list b, removing those elements from list a at the same time</p>
<pre><code> for (int i = 0; i < NeedToClean.Count; i++)
{
if (!Cleaing.Contains(NeedToClean[i]) && Cleaing.Count != 3)
{
Cleaing.Add(NeedToClean[i]);
break;
}
else
{
NeedToClean.Remove(Cleaing[i]);
}
}
</code></pre>
| [
{
"answer_id": 74381907,
"author": "Nopesound",
"author_id": 1503161,
"author_profile": "https://Stackoverflow.com/users/1503161",
"pm_score": 1,
"selected": false,
"text": "var a = new List<string>() { \"Alpha\", \"Beta\", \"Gamma\", \"Delta\" };\nvar b = new List<string>();\n\nb.AddRange(a.Take(3));\na.RemoveRange(0, 3);\n"
},
{
"answer_id": 74381939,
"author": "Attila Gál",
"author_id": 19852159,
"author_profile": "https://Stackoverflow.com/users/19852159",
"pm_score": 0,
"selected": false,
"text": "List indexes;\nfor (int i = 0; i < NeedToClean.Count; i++)\n{\n if(!Cleaing.Contains(NeedToClean[i]) && Cleaing.Count != 3)\n {\n Cleaing.Add(NeedToClean[i]);\n indexes.Add(i);\n }\n}\nwhile(indexes.Length != 0)\n{\n int biggest;\n foreach(int i in indexes){\n biggest = (i > biggest) ? i : biggest;\n }\n NeedToClean.Remove(Cleaing[biggest]);\n}\n"
},
{
"answer_id": 74381979,
"author": "Rufus L",
"author_id": 2052655,
"author_profile": "https://Stackoverflow.com/users/2052655",
"pm_score": 2,
"selected": false,
"text": "for (int i = NeedToClean.Count - 1; i >= 0; i--)\n{\n if (!Cleaing.Contains(NeedToClean[i]))\n {\n // Add the item to one array\n Cleaing.Add(NeedToClean[i]);\n\n // Remove it from the original array\n NeedToClean.RemoveAt(i);\n\n // Quit when we've moved 3 items\n if (Cleaning.Count == 3) break;\n }\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463154/"
] |
74,381,760 | <p>say there is a function in my code:
<code>int getwords(int argc, char *argv[])</code>
and I want to call this function in main().
How do I call this in main without erroring out?</p>
<pre><code>`void main(void)
getwords();`
</code></pre>
| [
{
"answer_id": 74381907,
"author": "Nopesound",
"author_id": 1503161,
"author_profile": "https://Stackoverflow.com/users/1503161",
"pm_score": 1,
"selected": false,
"text": "var a = new List<string>() { \"Alpha\", \"Beta\", \"Gamma\", \"Delta\" };\nvar b = new List<string>();\n\nb.AddRange(a.Take(3));\na.RemoveRange(0, 3);\n"
},
{
"answer_id": 74381939,
"author": "Attila Gál",
"author_id": 19852159,
"author_profile": "https://Stackoverflow.com/users/19852159",
"pm_score": 0,
"selected": false,
"text": "List indexes;\nfor (int i = 0; i < NeedToClean.Count; i++)\n{\n if(!Cleaing.Contains(NeedToClean[i]) && Cleaing.Count != 3)\n {\n Cleaing.Add(NeedToClean[i]);\n indexes.Add(i);\n }\n}\nwhile(indexes.Length != 0)\n{\n int biggest;\n foreach(int i in indexes){\n biggest = (i > biggest) ? i : biggest;\n }\n NeedToClean.Remove(Cleaing[biggest]);\n}\n"
},
{
"answer_id": 74381979,
"author": "Rufus L",
"author_id": 2052655,
"author_profile": "https://Stackoverflow.com/users/2052655",
"pm_score": 2,
"selected": false,
"text": "for (int i = NeedToClean.Count - 1; i >= 0; i--)\n{\n if (!Cleaing.Contains(NeedToClean[i]))\n {\n // Add the item to one array\n Cleaing.Add(NeedToClean[i]);\n\n // Remove it from the original array\n NeedToClean.RemoveAt(i);\n\n // Quit when we've moved 3 items\n if (Cleaning.Count == 3) break;\n }\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20352716/"
] |
74,381,799 | <p>I was taking on a JS challenge to take a first/last name string input and do the following:</p>
<ol>
<li>swap the first letter of first/last name</li>
<li>convert all characters to lowercase, except for the first characters, which need to be uppercase</li>
</ol>
<p>Example:
input: DonAlD tRuMp<br />
output: Tonald Drump</p>
<p>The following is the code I came up with:</p>
<pre><code>const input = prompt("Enter a name:")
function switchFirstLetters(input) {
let stringArray = input.split('');
for(let i=0; i < stringArray.length; i++) {
if(stringArray[i - 1] === ' ') {
[stringArray[0], stringArray[i]] = [stringArray[i], stringArray[0]]; // destructuring
}
}
return result = stringArray.join('');
}
let swappedString = switchFirstLetters(input);
function capFirstLetters(swappedString) {
let stringArray = swappedString.toLowerCase();
stringArray = stringArray.split('');
stringArray[0] = stringArray[0].toUpperCase();
for(let i=0; i < stringArray.length; i++) {
if(stringArray[i - 1] === ' ') {
stringArray[i] = stringArray[i].toUpperCase();
}
}
return result = stringArray.join('');
}
let finalString = capFirstLetters(swappedString);
console.log(finalString);
</code></pre>
<p>My thought process for the <code>switchFirstLetters</code> function was:</p>
<ol>
<li>Create an array from the string parameter</li>
<li>Run through the array length. If the value of the element prior the current element is equal to <code>' '</code>, use destructuring to swap the current element with the element at index 0</li>
<li>Concatenate elements into a new string and return that value</li>
</ol>
<p>My thought process for the <code>capFirstLetters</code> function:</p>
<ol>
<li>Convert all characters in the string to lowercase (this could be handled outside of the function as well)</li>
<li>Create an array from the new, lowercase string</li>
<li>Make character at index 0 be uppercase (this could also be integrated into the for loop)</li>
<li>Run through the array length. If the value of the element prior to the current element is equal to <code>' '</code>, convert that element to uppercase.</li>
<li>Concatenate array elements into a new string</li>
</ol>
<p>The code works, but I'm still early in my coding journey and realize it's likely not an ideal solution, so I was wondering if anyone here could help me optimize this further to help me learn. Thanks!</p>
| [
{
"answer_id": 74381907,
"author": "Nopesound",
"author_id": 1503161,
"author_profile": "https://Stackoverflow.com/users/1503161",
"pm_score": 1,
"selected": false,
"text": "var a = new List<string>() { \"Alpha\", \"Beta\", \"Gamma\", \"Delta\" };\nvar b = new List<string>();\n\nb.AddRange(a.Take(3));\na.RemoveRange(0, 3);\n"
},
{
"answer_id": 74381939,
"author": "Attila Gál",
"author_id": 19852159,
"author_profile": "https://Stackoverflow.com/users/19852159",
"pm_score": 0,
"selected": false,
"text": "List indexes;\nfor (int i = 0; i < NeedToClean.Count; i++)\n{\n if(!Cleaing.Contains(NeedToClean[i]) && Cleaing.Count != 3)\n {\n Cleaing.Add(NeedToClean[i]);\n indexes.Add(i);\n }\n}\nwhile(indexes.Length != 0)\n{\n int biggest;\n foreach(int i in indexes){\n biggest = (i > biggest) ? i : biggest;\n }\n NeedToClean.Remove(Cleaing[biggest]);\n}\n"
},
{
"answer_id": 74381979,
"author": "Rufus L",
"author_id": 2052655,
"author_profile": "https://Stackoverflow.com/users/2052655",
"pm_score": 2,
"selected": false,
"text": "for (int i = NeedToClean.Count - 1; i >= 0; i--)\n{\n if (!Cleaing.Contains(NeedToClean[i]))\n {\n // Add the item to one array\n Cleaing.Add(NeedToClean[i]);\n\n // Remove it from the original array\n NeedToClean.RemoveAt(i);\n\n // Quit when we've moved 3 items\n if (Cleaning.Count == 3) break;\n }\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2890343/"
] |
74,381,808 | <p>I have a named list of data frames that all contain the same columns, but for some of these data frames some of these columns are empty. What Im hoping to return is the name of the data frame in the list, and the name(s) of the empty column.</p>
<p>The repex below mirrors the process I am using on the full problem</p>
<pre><code>library(tidyverse)
data("diamonds")
data1 <- diamonds
data1$color <- NA
data1$price <- NA
data2 <- diamonds
data2$carat <- NA
data1$Type <- "data1"
data2$Type <- "data2"
data1%>%
bind_rows(data2) -> dataFull
dataSplit <- split(dataFull, f = dataFull$Type)
for(i in dataSplit){
which(sapply(dataSplit[[i]], function(x) all(is.na(x))))
}
</code></pre>
<p>My hope is to return something like</p>
<p>data1: price, color</p>
<p>data2: carat</p>
<p>I've tried the very basic for-loop included above, which are admittedly not my strong suit.</p>
| [
{
"answer_id": 74382032,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile": "https://Stackoverflow.com/users/12500315",
"pm_score": 3,
"selected": true,
"text": "sapply"
},
{
"answer_id": 74382043,
"author": "br00t",
"author_id": 4028717,
"author_profile": "https://Stackoverflow.com/users/4028717",
"pm_score": 2,
"selected": false,
"text": "library(tidyverse)\n\ndata(\"diamonds\") \n\ndata1 <- diamonds \n\ndata1$color <- NA\n\ndata1$price <- NA\n\ndata2 <- diamonds\n\ndata2$carat <- NA\n\ndata1$Type <- \"data1\"\n\ndata2$Type <- \"data2\"\n\ndata1%>%\n bind_rows(data2) -> dataFull\n\ndataSplit <- split(dataFull, f = dataFull$Type)\n\nlapply(dataSplit, function(x) {\n cn <- colnames(x)\n isempty <- apply(x, 2, function(col) is.na(col) |> all())\n cn[ isempty ]\n})\n\n"
},
{
"answer_id": 74383319,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 0,
"selected": false,
"text": "select"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17399602/"
] |
74,381,833 | <p>I have Kotlin pet-project with docker-compose file:</p>
<pre><code>version: '3.1'
services:
app:
build:
context: .
dockerfile: Dockerfile
command: java -jar ./testapp.jar
ports:
- "8080:8080"
depends_on:
- postgres
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://172.25.1.3:5432/kotlin-app
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=Tolstochok3000
networks:
app-network:
ipv4_address: 172.25.1.2
postgres:
build:
context: docker/db
dockerfile: Dockerfile
command: postgres
environment:
POSTGRES_DB: "kotlin-app"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "Tolstochok3000"
ports:
- "5432:5432"
networks:
app-network:
ipv4_address: 172.25.1.3
restart: always
networks:
app-network:
ipam:
config:
- subnet: 172.25.1.0/16
</code></pre>
<p>I tried docker-compose up, postgres started without problem, but app throw exception: Factory method 'resourceHandlerMapping' threw exception;
nested exception is java.lang.IllegalStateException: No ServletContext set</p>
<p>When I started application on localhost (without docker), application work correctly with db in docker.</p>
<p>Application dockerfile:</p>
<pre><code>FROM gradle:jdk17 as builder
WORKDIR /test-kotlin-app
COPY src ./src
COPY build.gradle.kts ./build.gradle.kts
RUN gradle clean build
FROM openjdk:17-alpine as backend
WORKDIR /root
COPY --from=builder /test-kotlin-app/build/libs/* ./app
ENTRYPOINT ["java", "-jar", "/root/app"]
</code></pre>
<p>Application propeties:</p>
<pre><code> #DATABSE SETTINGS
datasource:
driver-class-name: org.postgresql.Driver
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/kotlin-app}
username: ${SPRING_DATASOURCE_USERNAME:postgres}
password: ${SPRING_DATASOURCE_PASSWORD:Tolstochok3000}
#JPA SETTINGS
jpa:
show-sql: 'true'
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
</code></pre>
<p>I tried change docker-compose file application.yml (remove variables) and try remove network, but it didn't help</p>
<p>Error: java.lang.IllegalStateException: No ServletContext set
stacktrace:</p>
<pre><code>test_kotlin_app-app-1 | 08:01:35.023 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Before shutdown stats (total=10, active=0, idle=10, waiting=0)
test_kotlin_app-app-1 | 08:01:35.029 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@2db15f70: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@6d2041d5: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@22daa83a: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@3599b284: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@42f55775: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@54a28df5: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@5668d8b3: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@2e9d5d68: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.031 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@46bbe931: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.031 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection@6b60936: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.032 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - After shutdown stats (total=0, active=0, idle=0, waiting=0)
test_kotlin_app-app-1 | 08:01:35.032 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
test_kotlin_app-app-1 | 08:01:35.035 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
test_kotlin_app-app-1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/W
ebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.se
rvlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
test_kotlin_app-app-1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
test_kotlin_app-app-1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
test_kotlin_app-app-1 | at ru.rsu.app.KotlinAppApplicationKt.main(KotlinAppApplication.kt:13)
test_kotlin_app-app-1 | Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; ne
sted exception is java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
test_kotlin_app-app-1 | ... 18 common frames omitted
test_kotlin_app-app-1 | Caused by: java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.util.Assert.state(Assert.java:76)
test_kotlin_app-app-1 | at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:591)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
test_kotlin_app-app-1 | at java.base/java.lang.reflect.Method.invoke(Method.java:568)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
test_kotlin_app-app-1 | ... 19 common frames omitted
</code></pre>
| [
{
"answer_id": 74400227,
"author": "Nikita Romanov",
"author_id": 20447886,
"author_profile": "https://Stackoverflow.com/users/20447886",
"pm_score": 1,
"selected": false,
"text": "tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>(\"bootJar\") {\nmainClass.set(\"con.example.app.KotlinAppApplicationKt\")\narchiveBaseName.set(\"testapp\")\narchiveFileName.set(\"testapp.jar\") }\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20447886/"
] |
74,381,966 | <p>My script sometimes errors which is fine, but I have to manually restart the script.</p>
<p>Anyone knows how to make it so that it actually works infinitely even if it crashed 50 times, currently what I have only works for 1 crash.</p>
<pre><code>try:
while True:
do_main_logic()
except:
continue
</code></pre>
<p>I have tried many scripts, but I am expecting it to just continue no matter what.</p>
| [
{
"answer_id": 74382010,
"author": "HmBloqued",
"author_id": 17183809,
"author_profile": "https://Stackoverflow.com/users/17183809",
"pm_score": -1,
"selected": false,
"text": "while True:\n try:\n while True:\n do_main_logic()\n\n\n except:\n continue\n"
},
{
"answer_id": 74382018,
"author": "Matthias",
"author_id": 1209921,
"author_profile": "https://Stackoverflow.com/users/1209921",
"pm_score": 3,
"selected": true,
"text": "do_main_logic()"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16901344/"
] |
74,381,972 | <p>I'm new to JavaScript and programming in general. I've taken a challenge of building a calculator usign HTML/CSS and JavaScript, I've already managed to add the sum function so the two numbers split by '+' are summed and the result shows up in the same text input. But I can't seem to get it working for the other operations. For example, whenever I try to subtract, let's say 5-3, the result is -8...</p>
<p>Also, if I make a different operation first, the other operations I try to make after will display 'NaN' in the text input. For example, if I operate a sum first and then try to operate a subtraction, the result will not be "-8", it will display 'NaN' instead, and vice versa...</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var equals = document.querySelector('#equals');
// The textfield element
var visor = document.getElementById("visor");
// The reset button
var resetBtn = document.getElementById("reset");
// Get all the buttons to an Array
var buttons = document.getElementsByClassName("key");
// Get all operators button
var plus = document.getElementById("plus");
var subtract = document.getElementById("subtract");
var multiply = document.getElementById("multiply");
var divide = document.getElementById("divide");
function numbersAndOperators() {
Array.prototype.forEach.call(buttons, (button) => {
button.addEventListener("click", () => {
visor.value += button.innerText
})
})
// Add click event listener to reset button
resetBtn.addEventListener("click", () => {
visor.value = null
})
}
plus.addEventListener('click', function() {
equals.addEventListener('click', function() {
var valAdd = visor.value.split('+');
visor.value = valAdd.reduce((a, c) => a + Number(c), 0);
});
});
subtract.addEventListener('click', function() {
equals.addEventListener('click', function() {
var valSub = visor.value.split('-');
visor.value = valSub.reduce((a, c) => a - Number(c), 0);
});
});
multiply.addEventListener('click', function() {
equals.addEventListener('click', function() {
var valMul = visor.value.split('*');
visor.value = valMul.reduce((a, c) => a * Number(c), 0);
});
});
divide.addEventListener('click', function() {
equals.addEventListener('click', function() {
var valDiv = visor.value.split('/');
visor.value = valDiv.reduce((a, c) => a / Number(c), 0);
});
});
document.addEventListener("DOMContentLoaded", numbersAndOperators);</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
<div class="title-theme">
<div>
<h1>Calc</h1>
</div>
<div class="theme">
<p>Theme</p><input type="range" min="0" max="2" id="range"></div>
</div>
<div class="visor">
<div><input type="text" id="visor"></div>
</div>
<div>
<div class="board">
<button class="key key_7">7</button><button class="key key_8">8</button><button class="key key_9">9</button><button class="key_DEL" id="del">DEL</button>
</div>
<div class="board">
<button class="key key_4">4</button><button class="key key_5">5</button><button class="key key_6">6</button><button class="key key_+" id="plus">+</button>
</div>
<div class="board">
<button class="key key_1">1</button><button class="key key_2">2</button><button class="key key_3">3</button><button class="key key_-" id="subtract">-</button>
</div>
<div class="board">
<button class="key key_period">.</button><button class="key key_0">0</button><button class="key key_/" id="divide">/</button><button class="key key_x" id="multiply">*</button>
</div>
<div class="board">
<button class="key_reset" id="reset">RESET</button><button class="key_=" id="equals">=</button>
</div>
</div>
</body></code></pre>
</div>
</div>
</p>
<p>Previously, the JS for the equals button was like that:</p>
<pre><code>equals.addEventListener('click', function(){
if (visor.value.split('+')){
visor.value = visor.value.split('+').reduce((a,c) => a + Number(c), 0);
}
if (visor.value.split('-')){
visor.value = visor.value.split('-').reduce((a,c) => a - Number(c), 0);
}
if (visor.value.split('*')){
visor.value = visor.value.split('*').reduce((a,c) => a * Number(c), 0);
}
if (visor.value.split('/')){
visor.value = visor.value.split('/').reduce((a,c) => a / Number(c), 0);
}
});
document.addEventListener("DOMContentLoaded", numbersAndOperators);
</code></pre>
| [
{
"answer_id": 74382183,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 1,
"selected": true,
"text": "reduce()"
},
{
"answer_id": 74383314,
"author": "Rubens Oliveira",
"author_id": 20358068,
"author_profile": "https://Stackoverflow.com/users/20358068",
"pm_score": 1,
"selected": false,
"text": "<!--begin snippet-->\n<body>\n <div class=\"title-theme\">\n <div><h1>Calc</h1></div>\n <div class=\"theme\"><p>Theme</p><input type=\"range\" min=\"0\" max=\"2\" id=\"range\"></div>\n </div>\n <div class=\"visor\">\n <div><input type=\"text\" id=\"visor\"></div>\n </div>\n <div>\n <div class=\"board\">\n <button class=\"key key_7\">7</button><button class=\"key key_8\">8</button><button class=\"key key_9\">9</button><button class=\"key_DEL\" id=\"del\" >DEL</button>\n </div>\n <div class=\"board\">\n <button class=\"key key_4\">4</button><button class=\"key key_5\">5</button><button class=\"key key_6\">6</button><button class=\"key key_+\" id=\"plus\">+</button>\n </div>\n <div class=\"board\">\n <button class=\"key key_1\">1</button><button class=\"key key_2\">2</button><button class=\"key key_3\">3</button><button class=\"key key_-\" id=\"subtract\">-</button>\n </div>\n <div class=\"board\">\n <button class=\"key key_period\">.</button><button class=\"key key_0\">0</button><button class=\"key key_/\" id=\"divide\">/</button><button class=\"key key_x\" id=\"multiply\">*</button>\n </div>\n <div class=\"board\">\n <button class=\"key_reset\" id=\"reset\">RESET</button><button class=\"key_=\" id=\"equals\">=</button>\n </div>\n </div>\n</body>\n\n<script>\nvar equals = document.querySelector('#equals');\nvar visor = document.getElementById(\"visor\");\nvar resetBtn = document.getElementById(\"reset\");\nvar buttons = document.getElementsByClassName(\"key\");\nvar plus = document.getElementById(\"plus\");\nvar subtract = document.getElementById(\"subtract\");\nvar multiply = document.getElementById(\"multiply\");\nvar divide = document.getElementById(\"divide\");\n\nfunction numbersAndOperators() {\n Array.prototype.forEach.call (buttons, (button) => {\n button.addEventListener(\"click\", () => {\n visor.value += button.innerText\n })\n })\n resetBtn.addEventListener(\"click\", () => {\n visor.value = null\n })\n}\n\nequals.addEventListener('click', function(){\n if (visor.value.split('-')){\n visor.value = visor.value.split('-').slice(1).reduce((a, c) => parseFloat(a) - parseFloat(c), (visor.value.split('-')[0]));\n }\n if (visor.value.split('+')){\n visor.value = visor.value.split('+').slice(1).reduce((a, c) => parseFloat(a) + parseFloat(c), (visor.value.split('+')[0]));\n }\n if (visor.value.split('*')){\n visor.value = visor.value.split('*').slice(1).reduce((a, c) => parseFloat(a) * parseFloat(c), (visor.value.split('*')[0]));\n }\n if (visor.value.split('/')){\n visor.value = visor.value.split('/').slice(1).reduce((a, c) => parseFloat(a) / parseFloat(c), (visor.value.split('/')[0]));\n }\n})\n\ndocument.addEventListener(\"DOMContentLoaded\", numbersAndOperators);\n</script>\n<!--end snippet-->\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20358068/"
] |
74,381,980 | <p>I see people using count to block resource creation in terraform. I want to create some resources if a condition is set to true. Is there such a thing same as in <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html" rel="nofollow noreferrer">CloudFormation</a>?</p>
| [
{
"answer_id": 74382537,
"author": "Danilo Cacace",
"author_id": 17871774,
"author_profile": "https://Stackoverflow.com/users/17871774",
"pm_score": 1,
"selected": false,
"text": "count"
},
{
"answer_id": 74396052,
"author": "Martin Atkins",
"author_id": 281848,
"author_profile": "https://Stackoverflow.com/users/281848",
"pm_score": 0,
"selected": false,
"text": "resource"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74381980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15500282/"
] |
74,382,062 | <p>I have a mysql table with the following columns- Date, country, YEAR, MONTH, supercategory, class, corp_manufacturer, brand, license,item_description,amount, units, arp.</p>
<p>Total number of records = 7.1 million</p>
<p>Now i want to add a new column which shows the max value of arp for the group (country, YEAR, MONTH, supercategory, class, corp_manufacturer, brand, license,item_description). This max value has to repeated for the all the members in the group.</p>
<p>I have tried the following 2 methods. Both works but both of them takes a long time to update the data more than 2 hrs.</p>
<p>I'm looking for any better solutions that can do this faster. Please help.</p>
<p>Method 1- update the table from subquery</p>
<pre><code>UPDATE table a
INNER JOIN (SELECT Country,YEAR, MONTH, supercategory, class, corp_manufacturer, brand, license, item_description, MAX(arp) AS max_arp FROM table GROUP BY 1,2,3,4,5,6,7,8,9) b
on a.country = b.country AND a.year = b.year AND a.month=b.month AND a.supercategory=b.supercategory AND a.class=b.class AND a.corp_manufacturer=b.corp_manufacturer AND a.brand=b.brand AND a.license=b.license AND a.item_description = b.item_description
SET a.max_arp= b.max_arp
</code></pre>
<p>Method 2 - create temp tables with indexes and join them in to a new table</p>
<pre><code>INSERT INTO temp1
(SELECT Country,YEAR, MONTH, supercategory, class, corp_manufacturer, brand, license, item_description, MAX(arp) AS max_arp
FROM table
GROUP BY 1,2,3,4,5,6,7,8,9);
INSERT IGNORE INTO temp2
SELECT a.*,b.max_arp AS SRP FROM table a JOIN temp1 b
ON a.country = b.country AND a.year = b.year AND a.month=b.month AND a.supercategory=b.supercategory AND a.class=b.class AND a.corp_manufacturer=b.corp_manufacturer
AND a.brand=b.brand AND a.license=b.license AND a.item_description = b.item_description;
</code></pre>
| [
{
"answer_id": 74382105,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 2,
"selected": true,
"text": "create myview v as\nselect t.*,\n max(arp) over(partition by \n country, \n year, \n month, \n supercategory, \n class, \n corp_manufacturer, \n brand, \n license,\n item_description\n ) max_arp\nfrom mytable t\n"
},
{
"answer_id": 74383130,
"author": "Ehab",
"author_id": 20342736,
"author_profile": "https://Stackoverflow.com/users/20342736",
"pm_score": 0,
"selected": false,
"text": "arp"
},
{
"answer_id": 74383152,
"author": "Rick James",
"author_id": 1766831,
"author_profile": "https://Stackoverflow.com/users/1766831",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE the_groups (\n PRIMARY KEY (Country,YEAR, MONTH, supercategory,\n class, corp_manufacturer,\n brand, license, item_description)\n ) AS\n SELECT Country,YEAR, MONTH, supercategory,\n class, corp_manufacturer,\n brand, license, item_description,\n MAX(arp) AS max_arp\n FROM table\n GROUP BY 1,2,3,4,5,6,7,8,9;\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15254963/"
] |
74,382,084 | <p>I create a rating scale has N <strong></strong> with fixed width.
Each rate has got a value which is shown inside of the correspective <strong>div</strong> and a description.</p>
<p>My problem is that the description and the relative icon are not align in center under the <strong>div</strong> but starts from the left.</p>
<pre><code> <div class="card card-accent-primary">
<div class="card-header text-left">
Rating values
</div>
<div class="card-body">
<div class="col-12 mt-2 mb-1 p-buttonset valore-rating-display justify-content-center">
<div *ngFor="let scala of scalaRating; let i=index" style="width: 5rem">
<div>
<button pButton type="button" label="{{scala.valoreRating}}" class="p-button-outlined cursor-default"
[class.rounded-left]="i == 0" [class.rounded-right]="i == (scalaRating.length - 1)"
style="background-color: {{scala.codColoreValRating}}; color: black; width: 5rem">
</button>
</div>
<div *ngIf="rating == scala.valoreRating" class="position-relative">
<i class="fa fa-caret-up font-weight-bold font-xxlarge"></i>
<div class="position-absolute" style="word-wrap: break-word; left: -1rem">{{scala.descrizioneValRating}}</div>
</div>
</div>
</div>
</div>
</div>
</code></pre>
<p>I want the icon and description positioned in center like in the image(I marked with red color the desire position):
<a href="https://i.stack.imgur.com/KUfaz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KUfaz.png" alt="enter image description here" /></a></p>
<p>Here there is the example code:</p>
<p><a href="https://stackblitz.com/edit/angular-a3akxa?file=src/app/app.component.html" rel="nofollow noreferrer">https://stackblitz.com/edit/angular-a3akxa?file=src/app/app.component.html</a></p>
| [
{
"answer_id": 74382171,
"author": "Kevon",
"author_id": 766684,
"author_profile": "https://Stackoverflow.com/users/766684",
"pm_score": 0,
"selected": false,
"text": "<div class=\"demo-solution demo-solution--flexbox\">\n <img width=\"100\" height=\"50\" src=\"http://placehold.it/100x50\" alt=\"\" />\n <span>Alignment using flexbox</span>\n</div>\n\n.demo-problem, .demo-solution {\n font-size: 3em;\n}\n\n.demo-solution--flexbox {\n display: flex;\n align-items: center;\n margin:auto;\n img {\n margin: 10px;\n padding: 10px;\n transition: margin 300ms;\n }\n}\n"
},
{
"answer_id": 74382706,
"author": "richlira",
"author_id": 5848847,
"author_profile": "https://Stackoverflow.com/users/5848847",
"pm_score": 0,
"selected": false,
"text": ".fa-caret-up {\n display: flex;\n justify-content: center;\n}\n"
},
{
"answer_id": 74383861,
"author": "CQLI",
"author_id": 1345734,
"author_profile": "https://Stackoverflow.com/users/1345734",
"pm_score": 0,
"selected": false,
"text": "text-align: center;"
},
{
"answer_id": 74385644,
"author": "Eliseo",
"author_id": 8558186,
"author_profile": "https://Stackoverflow.com/users/8558186",
"pm_score": 2,
"selected": true,
"text": " <div *ngFor=\"let scala of scalaRating; let i=index\" class=\"wrapper\">\n <button ...></button>\n <ng-container *ngIf=\"rating == scala.valoreRating\" >\n <i class=\"...\"></i>\n <div style=\"word-wrap: break-word;\">{{scala.descrizioneValRating}}\n </div>\n </ng-container>\n </div>\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11488464/"
] |
74,382,150 | <p>In my Unity project I have a List with 2d string arrays as elements inside of that list:</p>
<pre class="lang-cs prettyprint-override"><code>List<string[,]> listOfLists = new List<string[,]>()
//the array has a variable amount of rows and 3 columns
</code></pre>
<p>It basically holds some arrays that I need to save. Now, to control if everything is working, I want to put it in a <em>foreach-loop</em> and output everything that was saved, but it just returns the 3rd column of the array saved in <code>listOfLists[0]</code></p>
<pre><code> foreach(string smth in listOfLists[0])
{
return smth;
}
</code></pre>
<p>I put that <em>foreach-loop</em> inside <code>override .ToString()</code> (<code>Debug.Log(xxx.ToString())</code>) and I know it should work returning a <code>string[,]</code> as string but it does and it returns the 1st column, so if the array is defined like this:</p>
<pre class="lang-cs prettyprint-override"><code>listOfLists[0][0, 0] = "A";
listOfLists[0][0, 1] = "B";
listOfLists[0][0, 2] = "C";
listOfLists[0][1, 0] = "D";
listOfLists[0][1, 1] = "E";
listOfLists[0][1, 2] = "F";
</code></pre>
<p>it JUST returns A and NOT B, C, D, E or F.</p>
<p>I can output it like this, so the array isn't not working or anything:</p>
<pre class="lang-cs prettyprint-override"><code>return $"{listOfLists[0][0, 0]} geht in die {listOfLists[0][0, 2]} und ihr Foto ist aufzufinden bei: {listOfLists[0][0, 1]}";
</code></pre>
<p>I just think its more practical to put it in a <em>foreach-loop</em>, than to call everything by it's own.</p>
<p>I know I did something wrong on the <em>foreach-loop</em> but I don't know, what it is or how to solve it.</p>
<p>My goal is to return the whole array like that:</p>
<pre class="lang-cs prettyprint-override"><code>//return
A B C D E F
</code></pre>
| [
{
"answer_id": 74386810,
"author": "George H.",
"author_id": 9805813,
"author_profile": "https://Stackoverflow.com/users/9805813",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n \npublic class Program\n{\n public static void Main()\n {\n \n List<string[,]> arrayList = new List<string[,]>();\n var twoDArray = new string[5,5];\n // just a couple of items for testing, intentionally leaving some indices null as well\n twoDArray[0,0] = \"a\";\n twoDArray[0,1] = \"b\";\n twoDArray[0,2] = \"c\";\n \n twoDArray[1,0] = \"d\";\n twoDArray[1,1] = \"e\";\n twoDArray[1,2] = \"f\";\n \n arrayList.Add(twoDArray);\n arrayList.Add(twoDArray);\n \n foreach(var array in arrayList)\n {\n Console.WriteLine(\"=== Starting iterration for another array in the array list ===\");\n // iterates over the array as flattened items\n foreach(var arrayItem in array)\n {\n Console.WriteLine(string.Format(\"Flattened iteration - value {0}\", arrayItem));\n }\n \n // or you can iterate over the items with their indices\n for (int x = 0; x < array.GetLength(0); x += 1) \n {\n for (int y = 0; y < array.GetLength(1); y += 1) \n {\n var indexedItem = array[x,y];\n Console.WriteLine(string.Format(\"Indexed iteration - at index {0},{1} value {2}\", x, y, indexedItem));\n }\n }\n }\n \n }\n}\n"
},
{
"answer_id": 74389852,
"author": "The Crazy",
"author_id": 17326832,
"author_profile": "https://Stackoverflow.com/users/17326832",
"pm_score": 0,
"selected": false,
"text": "public override string ToString()\n{\n string test = \"\";\n\n foreach(string smth in listOfLists[0])\n {\n test += smth;\n }\n\n return test;\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17326832/"
] |
74,382,157 | <p>I'm trying to change the line length for Code wrapping in VSCode I've tried a lot of solutions here in Stackoverflow but it didn't work out for me, something weird.
This is an image of a dart code shows the code wrapped if it exceeded that column:</p>
<p><a href="https://i.stack.imgur.com/vIpRS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vIpRS.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74386810,
"author": "George H.",
"author_id": 9805813,
"author_profile": "https://Stackoverflow.com/users/9805813",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n \npublic class Program\n{\n public static void Main()\n {\n \n List<string[,]> arrayList = new List<string[,]>();\n var twoDArray = new string[5,5];\n // just a couple of items for testing, intentionally leaving some indices null as well\n twoDArray[0,0] = \"a\";\n twoDArray[0,1] = \"b\";\n twoDArray[0,2] = \"c\";\n \n twoDArray[1,0] = \"d\";\n twoDArray[1,1] = \"e\";\n twoDArray[1,2] = \"f\";\n \n arrayList.Add(twoDArray);\n arrayList.Add(twoDArray);\n \n foreach(var array in arrayList)\n {\n Console.WriteLine(\"=== Starting iterration for another array in the array list ===\");\n // iterates over the array as flattened items\n foreach(var arrayItem in array)\n {\n Console.WriteLine(string.Format(\"Flattened iteration - value {0}\", arrayItem));\n }\n \n // or you can iterate over the items with their indices\n for (int x = 0; x < array.GetLength(0); x += 1) \n {\n for (int y = 0; y < array.GetLength(1); y += 1) \n {\n var indexedItem = array[x,y];\n Console.WriteLine(string.Format(\"Indexed iteration - at index {0},{1} value {2}\", x, y, indexedItem));\n }\n }\n }\n \n }\n}\n"
},
{
"answer_id": 74389852,
"author": "The Crazy",
"author_id": 17326832,
"author_profile": "https://Stackoverflow.com/users/17326832",
"pm_score": 0,
"selected": false,
"text": "public override string ToString()\n{\n string test = \"\";\n\n foreach(string smth in listOfLists[0])\n {\n test += smth;\n }\n\n return test;\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6884574/"
] |
74,382,168 | <p>I have logic in my application that requires me to create different variations of one specific class. These variations differ only by class properties.</p>
<p>If variation == "A", then some class properties need to be set to zero and others filled with the provided input, else if variation == "B", some other properties are zero etc.</p>
<p>It looks to me that the factory pattern is a perfect solution for this problem, but there is a complication I cannot find a solution for - every variation is expected to receive a <strong>different number of arguments</strong>. Basically, business logic knows that, let's say, property X of variation A is always 0, so function create_variation_a() should not expect X as argument.</p>
<p>I could just set argument X to a default value, but than other devs would not know if X needs to be provided or not without checking the code.</p>
<pre><code>class Something:
def __init__(self, one: int, two: int, three: int):
self.one = one
self.two = two
self.three = three
def create_one(one: int) -> Something:
return Something(one=one, two=0, three=0)
def create_two(one: int, two: int) -> Something:
return Something(one=one, two=two, three=0)
def create_three(one: int, two: int, three: int) -> Something:
return Something(one=one, two=two, three=three)
factory = {
"one": create_one,
"two": create_two,
"three": create_three
}
myfunc1 = factory["one"]
# I want type checker to know that I only need to supply one
variation_one = myfunc1()
myfunc3 = factory["three"]
# I want type checker to know that I need to supply one, two and three
variation_three = myfunc3()
</code></pre>
| [
{
"answer_id": 74386810,
"author": "George H.",
"author_id": 9805813,
"author_profile": "https://Stackoverflow.com/users/9805813",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n \npublic class Program\n{\n public static void Main()\n {\n \n List<string[,]> arrayList = new List<string[,]>();\n var twoDArray = new string[5,5];\n // just a couple of items for testing, intentionally leaving some indices null as well\n twoDArray[0,0] = \"a\";\n twoDArray[0,1] = \"b\";\n twoDArray[0,2] = \"c\";\n \n twoDArray[1,0] = \"d\";\n twoDArray[1,1] = \"e\";\n twoDArray[1,2] = \"f\";\n \n arrayList.Add(twoDArray);\n arrayList.Add(twoDArray);\n \n foreach(var array in arrayList)\n {\n Console.WriteLine(\"=== Starting iterration for another array in the array list ===\");\n // iterates over the array as flattened items\n foreach(var arrayItem in array)\n {\n Console.WriteLine(string.Format(\"Flattened iteration - value {0}\", arrayItem));\n }\n \n // or you can iterate over the items with their indices\n for (int x = 0; x < array.GetLength(0); x += 1) \n {\n for (int y = 0; y < array.GetLength(1); y += 1) \n {\n var indexedItem = array[x,y];\n Console.WriteLine(string.Format(\"Indexed iteration - at index {0},{1} value {2}\", x, y, indexedItem));\n }\n }\n }\n \n }\n}\n"
},
{
"answer_id": 74389852,
"author": "The Crazy",
"author_id": 17326832,
"author_profile": "https://Stackoverflow.com/users/17326832",
"pm_score": 0,
"selected": false,
"text": "public override string ToString()\n{\n string test = \"\";\n\n foreach(string smth in listOfLists[0])\n {\n test += smth;\n }\n\n return test;\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9154956/"
] |
74,382,180 | <p>I have a table <code>items</code> and a table <code>batches</code>. A batch can have n items associated by <code>items.batch_id</code>.</p>
<p>I'd like to write a query item counts in two groups <code>batched</code> and <code>unbatched</code>:</p>
<ol>
<li>items WHERE batch_id IS NOT NULL (batched)</li>
<li>items WHERE batch_id IS NULL (unbatched)</li>
</ol>
<p>The result should look like this</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>batched</th>
<th>unbatched</th>
</tr>
</thead>
<tbody>
<tr>
<td>1200000</td>
<td>100</td>
</tr>
</tbody>
</table>
</div>
<p>Any help appreciated, thank you!</p>
<p>EDIT:
I got stuck with using <code>GROUP BY</code> which turned out to be the wrong tool for the job.</p>
| [
{
"answer_id": 74386810,
"author": "George H.",
"author_id": 9805813,
"author_profile": "https://Stackoverflow.com/users/9805813",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n \npublic class Program\n{\n public static void Main()\n {\n \n List<string[,]> arrayList = new List<string[,]>();\n var twoDArray = new string[5,5];\n // just a couple of items for testing, intentionally leaving some indices null as well\n twoDArray[0,0] = \"a\";\n twoDArray[0,1] = \"b\";\n twoDArray[0,2] = \"c\";\n \n twoDArray[1,0] = \"d\";\n twoDArray[1,1] = \"e\";\n twoDArray[1,2] = \"f\";\n \n arrayList.Add(twoDArray);\n arrayList.Add(twoDArray);\n \n foreach(var array in arrayList)\n {\n Console.WriteLine(\"=== Starting iterration for another array in the array list ===\");\n // iterates over the array as flattened items\n foreach(var arrayItem in array)\n {\n Console.WriteLine(string.Format(\"Flattened iteration - value {0}\", arrayItem));\n }\n \n // or you can iterate over the items with their indices\n for (int x = 0; x < array.GetLength(0); x += 1) \n {\n for (int y = 0; y < array.GetLength(1); y += 1) \n {\n var indexedItem = array[x,y];\n Console.WriteLine(string.Format(\"Indexed iteration - at index {0},{1} value {2}\", x, y, indexedItem));\n }\n }\n }\n \n }\n}\n"
},
{
"answer_id": 74389852,
"author": "The Crazy",
"author_id": 17326832,
"author_profile": "https://Stackoverflow.com/users/17326832",
"pm_score": 0,
"selected": false,
"text": "public override string ToString()\n{\n string test = \"\";\n\n foreach(string smth in listOfLists[0])\n {\n test += smth;\n }\n\n return test;\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/924050/"
] |
74,382,185 | <p>I'm trying to fill the category description/text and have the category name change based on the category page you are on.</p>
<p>For example this category description:
You are watching [category].</p>
<p>If you are on the category page with the name drinks, it should change the description/text to:
You are watching drinks.</p>
<p>I tried to use the solution for retrieving the category name on this site, but that uses the product to show the category it belongs with. I'm trying to get the category name without any product, just the name of the category to fill the shortcode.</p>
| [
{
"answer_id": 74383207,
"author": "Shoelaced",
"author_id": 1512787,
"author_profile": "https://Stackoverflow.com/users/1512787",
"pm_score": -1,
"selected": true,
"text": "single_term_title()"
},
{
"answer_id": 74384087,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 0,
"selected": false,
"text": "do_shortcode('[category prefix=\"You are watching \"]');"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17319158/"
] |
74,382,195 | <p>I have a database where the users booking classes.</p>
<p>There is a table Bookings where lets say we want to have ony 5 rows for 5 students.</p>
<p>When the student trying to book the class, i am checking first how many rows are in the table and if are less than 5, i do the Insert.</p>
<p>The problem is that when there are concurrent bookings in the same second of the time, i have more than 5 records in the table.</p>
<p>In every Insert i check first the number of the rows, but when are in the same time, the return number is the same and its not increasing.</p>
<p>How to avoid these concurrent inserts and keep the table rows to 5.</p>
| [
{
"answer_id": 74383207,
"author": "Shoelaced",
"author_id": 1512787,
"author_profile": "https://Stackoverflow.com/users/1512787",
"pm_score": -1,
"selected": true,
"text": "single_term_title()"
},
{
"answer_id": 74384087,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 0,
"selected": false,
"text": "do_shortcode('[category prefix=\"You are watching \"]');"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1136939/"
] |
74,382,221 | <p><strong>This my HTML Code</strong></p>
<pre><code><html>
<body>
<h2>Validation Array</h2>
<input id="search" onblur="read()">
<label id="creat"></label>
</body>
</html>
</code></pre>
<p><strong>And this my Javascript</strong></p>
<pre><code>var fruits = ["Banana", "Orange", "Apple", "Mango"];
var search = document.getElementById("search").value;
function read() {
if(search != fruits){
document.getElementById("creat").innerHTML = "Error";
} else {
document.getElementById("creat").innerHTML = "Valid";
}
}
</code></pre>
<p>i want to validation write "Valid" if value = in array. thanks</p>
| [
{
"answer_id": 74383207,
"author": "Shoelaced",
"author_id": 1512787,
"author_profile": "https://Stackoverflow.com/users/1512787",
"pm_score": -1,
"selected": true,
"text": "single_term_title()"
},
{
"answer_id": 74384087,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 0,
"selected": false,
"text": "do_shortcode('[category prefix=\"You are watching \"]');"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5800463/"
] |
74,382,240 | <p>I'm testing out different way of displaying figures. I have one figure which is made up of 12 subplots split into two columns. Something like...</p>
<pre><code>fig, ax = plt.subplots(6, 2, figsize= (20,26))
</code></pre>
<p>I have another code which splits the 12 subplots into 3 different figures based on categorical data. Something like</p>
<pre><code>figA, ax = plt.subplots(5, 1, figsize= (10,23))
figB, ax = plt.subplots(3, 1, figsize= (10,17))
fig2, ax = plt.subplots(4, 1, figsize= (10,20))
</code></pre>
<p><strong>Is there a way to ensure all the subplots in every figure have the same x and y axis length?</strong></p>
| [
{
"answer_id": 74383207,
"author": "Shoelaced",
"author_id": 1512787,
"author_profile": "https://Stackoverflow.com/users/1512787",
"pm_score": -1,
"selected": true,
"text": "single_term_title()"
},
{
"answer_id": 74384087,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 0,
"selected": false,
"text": "do_shortcode('[category prefix=\"You are watching \"]');"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16138574/"
] |
74,382,263 | <p>I am creating a game with three different rooms with three different functions. The game needs to be started in the living room but the living room function will not run it only will start in the attic() function. Another problem I am having is having the other functions being called to change the room that the player is in. I use the selection to change the room but it will not change to the right room. I am sure there are other bugs in my program but I need to solve these two problems first.
`</p>
<pre><code>def living_room():
Gamewon = False
Mouse = ""
Inventory = ""
Hole = ""
Location = "living room"
while Location == "Living room":
print("")
print("Room: living room")
print("You are in the living room of the house. You see in this Room:")
print("A pot of soil")
print("Stairs going to the second floor")
print("A dark doorway")
print("A ball of string")
print("")
print("Room actions:")
print("(l)ook: go closer to look at the pot of soil")
Inventory = ""
if Inventory == "" or Inventory == "Cheese":
print("(p)ick up: ball of string")
print("(g)o: through the dark doorway")
print("(u)p: take the stairs to the second floor")
selection = input("Your selection: ")
if selection in "l":
print("The soil looks very dry")
elif selection in "l" and Mouse == "full":
print("The growing beanstalk takes you away to saftey!")
Gamewon = True
elif Inventory == "" and selection in "p":
Inventory = "String"
print("You have picked up the string")
elif selection in "g":
Location = "bed room"
elif selection in "u":
print("You take the stairs to the attic")
Location = "attic"
else:
print("Please make a proper selection")
def attic():
Gamewon = False
Inventory = ""
Hole = ""
Location = "attic"
while Location == "attic":
print("")
print("Room: Attic")
print("You have entered the attic of the house. In this room there is:")
print("A large assortment of random cheeses being stored up here.")
print("A hole much smaller then the pieces of cheese.")
print("")
print("Room actions:")
print("(c)heese: Pick up cheese and attempt to drop it in the hole.")
if Inventory == "String" or Inventory == "String,Cheese":
print("(s)tring: Drop the string into the hole.")
print("(p)ick up: Pick up a piece of cheese and keep it.")
print("(d)own: Go down the stairs.")
selection = input("Your selection: ")
if selection in "c":
print("The cheese does not fit down this hole.")
elif selection in "s":
print("The string has disappeared down the hole.")
Hole = "DroppedString"
elif selection in "p":
print("You have picked up a piece of cheese.")
Inventory = "Cheese"
elif selection in "d":
print("You have gone down the stairs.")
Location = "living room"
else:
print("Please make a proper selection")
def bed_room():
Gamewon = False
Hole = ""
Inventory = ""
Location = "bed room"
while Location == "bed room":
print("")
print("Room: Bedroom")
print("You have entered the bedroom.")
if Hole == "":
print("In the room there is the usual furnishings along with a cat staring at a mouse hole.")
if Hole == "DroppedString":
print("In the room there is the usual furnishings along with a mouse in front of the mouse hole.")
print("")
print("Room actions:")
print("(g)o through the entrance way.")
if Inventory == "String":
print("(u)se ball of string to play with cat.")
elif Hole == "DroppedString" and Inventory == "Cheese":
print("(f)eed the mouse the cheese")
selection = input("Your selection: ")
if selection in "g":
print("You have left the bedroom.")
Location = "living room"
elif selection in "u":
print("The cat looks and the string but then goes back to the mouse hole.")
elif selection in "f":
print("The mouse happily eats the cheese and scurries out of the room.")
Mouse = "full"
else:
print("please make a proper selection")
def start():
Location = "attic"
Gamewon = False
while Gamewon == False:
if Location == "attic":
attic()
elif Location == "living room":
living_room()
elif Location == "bed room":
bed_room()
while Gamewon == True:
print("Congratulations you have won the game!")
start()
</code></pre>
<p>I have tried rewriting the function and going through it to figure out what is different from the other functions but I am relatively new to coding so I cannot see what is wrong everything I have tried so far has just created more problems.</p>
| [
{
"answer_id": 74382278,
"author": "Code-Apprentice",
"author_id": 1440565,
"author_profile": "https://Stackoverflow.com/users/1440565",
"pm_score": 0,
"selected": false,
"text": "Location == 'attic'"
},
{
"answer_id": 74382507,
"author": "eezageeza",
"author_id": 18714512,
"author_profile": "https://Stackoverflow.com/users/18714512",
"pm_score": 2,
"selected": true,
"text": "def start()"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463396/"
] |
74,382,305 | <p>Assuming that</p>
<ul>
<li><code>m</code> is a <code>Map<number, V></code> for some type <code>V</code></li>
<li><code>k</code> is a <code>number</code>,</li>
</ul>
<p>how do I write down an expression that</p>
<ul>
<li>either gets an already existing <code>V</code> for the key <code>k</code>, or</li>
<li>creates a new <code>v: V</code>, puts it into the map for the key <code>k</code>, and evaluates to <code>v</code>?</li>
</ul>
<p>For example, <code>SOME_EXPR(m, k, [])</code> should either return <code>m.get(k)</code> if it already exists, or put the <code>[]</code> into <code>m.set(k, [])</code> and return the <code>[]</code>.</p>
<hr />
<p><strong>Concrete example</strong></p>
<p>Suppose that I want to incrementally build a <code>Map<number, number[]></code>.
I want to assign values <code>100</code> and <code>200</code> to the key <code>48</code>, and value <code>300</code> to <code>52</code>.
I want to create new empty arrays on demand whenever needed.
For this, I need something like an <code>SOME_EXPR(map, key, value)</code> such that</p>
<pre><code>var m = new Map(); // Map<number, number[]>
SOME_EXPR(m, 48, []).push(100)
SOME_EXPR(m, 48, []).push(200)
SOME_EXPR(m, 52, []).push(300)
</code></pre>
<p>results in a map</p>
<pre><code>{ 48 -> [100, 200]; 52 -> [300] }
</code></pre>
<p>What should one write instead of <code>SOME_EXPR</code>?</p>
<hr />
<p><strong>What I've tried</strong></p>
<p>I could, of course, create a helper method:</p>
<pre><code>function getOrElseUpdate(m, k, defaultValue) {
if (!m.has(k)) {
m.set(k, defaultValue);
}
return m.get(k);
}
</code></pre>
<p>and then use <code>SOME_EXPR(m, k, []) := getOrElseUpdate(m, k, [])</code>. But not only does it have to compute the hash code thrice, it's also just heavyweight and annoying (and possibly not obvious to the maintainer of the code, who has to click on it to see the definition in yet another file etc.).</p>
<p>I could try to inline this somehow:</p>
<pre><code>SOME_EXPR(m,k,v) := ((k) => (m.get(k) || ((v) => (m.set(k, v), v))(v)))(k)
</code></pre>
<p>so that the above example would become</p>
<pre><code>var m = new Map();
((k) => (m.get(k) || ((v) => (m.set(k, v), v))([])))(42).push(100);
((k) => (m.get(k) || ((v) => (m.set(k, v), v))([])))(42).push(200);
((k) => (m.get(k) || ((v) => (m.set(k, v), v))([])))(58).push(300);
</code></pre>
<p>which works, but is just bizarre.</p>
<p>I've also tried looking around for related answers, but this search turned out frustratingly unfruitful.</p>
<p>Is there any idiomatic way to achieve that? (preferably also in a way that's nicely typeable in TS)</p>
<hr />
<p><strong>Analogous methods from some other languages</strong></p>
<p><em>(optional; skip this if you're not into JVM)</em></p>
<p>In Scala, it would look like somewhat like this:</p>
<pre class="lang-scala prettyprint-override"><code>val m = HashMap.empty[Int, ListBuffer[Int]]
m.getOrElseUpdate(48, ListBuffer.empty) += 100
m.getOrElseUpdate(48, ListBuffer.empty) += 200
m.getOrElseUpdate(52, ListBuffer.empty) += 300
// m is now:
//
// HashMap(
// 48 -> ListBuffer(100, 200),
// 52 -> ListBuffer(300)
// )
</code></pre>
<p>In Java, very similarly:</p>
<pre class="lang-java prettyprint-override"><code>HashMap<Integer, List<Integer>> m = new HashMap<>();
m.computeIfAbsent(42, k -> new LinkedList<>()).add(100);
m.computeIfAbsent(42, k -> new LinkedList<>()).add(200);
m.computeIfAbsent(58, k -> new LinkedList<>()).add(300);
// m = {58=[300], 42=[100, 200]}
</code></pre>
| [
{
"answer_id": 74382426,
"author": "Madison Courto",
"author_id": 2926779,
"author_profile": "https://Stackoverflow.com/users/2926779",
"pm_score": 2,
"selected": false,
"text": "var m = new Map();\n\nfunction SOME_EXPR(m, k, v) {\n return m.get(k) || (m.set(k, v) && v);\n}\n\nfunction add(m, k, v) {\n SOME_EXPR(m, k, []).push(v)\n}\n\nadd(m, 48, 100)\nadd(m, 48, 200)\nadd(m, 52, 300)\n\nconsole.log(m);\n"
},
{
"answer_id": 74382480,
"author": "Benjamin Penney",
"author_id": 6545526,
"author_profile": "https://Stackoverflow.com/users/6545526",
"pm_score": 3,
"selected": true,
"text": "((k, d) => m.get(k) ?? (m.set(k, d), d))(48, []).push(100);\n"
},
{
"answer_id": 74382526,
"author": "Aid Hadzic",
"author_id": 5963060,
"author_profile": "https://Stackoverflow.com/users/5963060",
"pm_score": 1,
"selected": false,
"text": "function addValue(m, k, v) {\n m.set(k, [...(m.get(k) || []), v]);\n}\n\nvar map = new Map();\naddValue(map, 48, 100);\naddValue(map, 48, 200);\naddValue(map, 52, 300);\n\nconsole.log(map);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2707792/"
] |
74,382,313 | <p>What I want is products according to the click order, adding the product field to the objects of the customers, and removing the product from the added user when the clicked checkbox is removed.</p>
<p>The product field is not a place entered manually, it is a place selected by checkbox above.<br />
My english is a bit bad. I hope you understood what I wanted to say.</p>
<p>The first click should be added to the first customer, the second click to the second customer, and the third click to the third customer. If the relevant checkbox is removed, it should find out which customer the product belongs to and remove that product from the customer.</p>
<pre class="lang-html prettyprint-override"><code><template>
<div>
<input
v-for="(product, index) in products"
type="checkbox"
name="`element${index}`"
:value="product"
@click="onSelected(i)"
/>
</div>
<div>
<table>
<thead>
<tr>
<th scope="col">
<span>Name</span>
</th>
<th scope="col">
<span>Surname</span>
</th>
<th scope="col">
<span>Birthday</span>
</th>
</tr>
</thead>
</table>
<tbody>
<tr v-for="customer in customers" :key="customer.id">
<td>
<input v-model="customer.name" type="text" placeholder="name" />
</td>
<td>
<input v-model="customer.surname" type="text" placeholder="name" />
</td>
<td>
<input v-model="customer.birthday" type="date" placeholder="name" />
</td>
</tr>
</tbody>
</div>
</template>
<script>
export default {
data() {
return {
customers: [
{
name: null,
surname: null,
birthday: null,
},
{ name: null, surname: null, birthday: null },
{ name: null, surname: null, birthday: null },
],
products: [
{ i: 1, name: 'home' },
{ i: 2, name: 'car' },
{ i: 3, name: 'yatch' },
{ i: 4, name: 'villa' },
],
selectedProduct: null,
}
},
methods: {
getCheck(i) {
for (let i = 0; i < this.products.length; ++i) {
if (this.products[i].id === i) {
return this.products[i]
}
}
return null
},
onSelected(i) {
if (this.selectedProduct === this.getCheck(i)) {
this.selectedProduct = null
} else {
this.selectedProduct = this.getCheck(i)
}
},
},
}
</script>
</code></pre>
| [
{
"answer_id": 74382426,
"author": "Madison Courto",
"author_id": 2926779,
"author_profile": "https://Stackoverflow.com/users/2926779",
"pm_score": 2,
"selected": false,
"text": "var m = new Map();\n\nfunction SOME_EXPR(m, k, v) {\n return m.get(k) || (m.set(k, v) && v);\n}\n\nfunction add(m, k, v) {\n SOME_EXPR(m, k, []).push(v)\n}\n\nadd(m, 48, 100)\nadd(m, 48, 200)\nadd(m, 52, 300)\n\nconsole.log(m);\n"
},
{
"answer_id": 74382480,
"author": "Benjamin Penney",
"author_id": 6545526,
"author_profile": "https://Stackoverflow.com/users/6545526",
"pm_score": 3,
"selected": true,
"text": "((k, d) => m.get(k) ?? (m.set(k, d), d))(48, []).push(100);\n"
},
{
"answer_id": 74382526,
"author": "Aid Hadzic",
"author_id": 5963060,
"author_profile": "https://Stackoverflow.com/users/5963060",
"pm_score": 1,
"selected": false,
"text": "function addValue(m, k, v) {\n m.set(k, [...(m.get(k) || []), v]);\n}\n\nvar map = new Map();\naddValue(map, 48, 100);\naddValue(map, 48, 200);\naddValue(map, 52, 300);\n\nconsole.log(map);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19301566/"
] |
74,382,338 | <p>I am having configuration.ini file which contain following content -></p>
<pre><code>[Objects]
obj1={7CE7ECE0-B70D-4622-8F4B-D999E5F06AAD}
obj2={5964945B-C31B-4805-9408-D56A4A5457CF}
obj3={5964945B-C31B-4805-9408-D56A4A5457CF}
</code></pre>
<p>Those keys - objN can be dynamically added.</p>
<p>With help of ConfigurationBuilder I am creating the config -></p>
<pre class="lang-cs prettyprint-override"><code>IConfigurationRoot configuration = new ConfigurationBuilder()
.AddIniFile(Path.Combine(configFolderPath, @"Configuration.ini"))
.Build();
</code></pre>
<p>Now when it come to the topic of Binding to object I get stuck and cant find any solution.</p>
<pre class="lang-cs prettyprint-override"><code>
services.AddOptions<SomeObject>()
.Bind(_configuration.GetSection("Object"))
</code></pre>
<p>P.S
<br/>
As temporary solution I found is to get configuration section as enumerable which is <code>dictionary<string,string></code> and then map it manually. This is just look quite dirty.</p>
<pre><code>configuration.GetSection("Objects").AsEnumerable()
</code></pre>
| [
{
"answer_id": 74382426,
"author": "Madison Courto",
"author_id": 2926779,
"author_profile": "https://Stackoverflow.com/users/2926779",
"pm_score": 2,
"selected": false,
"text": "var m = new Map();\n\nfunction SOME_EXPR(m, k, v) {\n return m.get(k) || (m.set(k, v) && v);\n}\n\nfunction add(m, k, v) {\n SOME_EXPR(m, k, []).push(v)\n}\n\nadd(m, 48, 100)\nadd(m, 48, 200)\nadd(m, 52, 300)\n\nconsole.log(m);\n"
},
{
"answer_id": 74382480,
"author": "Benjamin Penney",
"author_id": 6545526,
"author_profile": "https://Stackoverflow.com/users/6545526",
"pm_score": 3,
"selected": true,
"text": "((k, d) => m.get(k) ?? (m.set(k, d), d))(48, []).push(100);\n"
},
{
"answer_id": 74382526,
"author": "Aid Hadzic",
"author_id": 5963060,
"author_profile": "https://Stackoverflow.com/users/5963060",
"pm_score": 1,
"selected": false,
"text": "function addValue(m, k, v) {\n m.set(k, [...(m.get(k) || []), v]);\n}\n\nvar map = new Map();\naddValue(map, 48, 100);\naddValue(map, 48, 200);\naddValue(map, 52, 300);\n\nconsole.log(map);\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11530565/"
] |
74,382,369 | <p>I am building and debugging the application through VSCode and live-server, and I am hosting the application on a local XAMPP apache server.</p>
<p>I would like to keep the javascript code the same and just switch between live-server and apache</p>
<p>the way I see doing this is by keeping an <code>index.html</code> for apache and <code>debug.html</code> for live-server in VSCode</p>
<p>So in index.html I would have something like this:</p>
<pre><code><body>
<div id="main_div" style="position: relative; "></div>
<script type="text/javascript" src="main.js">
bbCSV = 'http://xxx.xxx.xxx.xxx/BB.csv';
smtCSV = 'http://xxx.xxx.xxx.xxx/SMT.csv';
</script>
</body>
</code></pre>
<p>Where <code>xxx.xxx.xxx.xxx</code> represents the IP of the server</p>
<p>And in debug.html I would have this</p>
<pre><code><body>
<div id="main_div" style="position: relative; "></div>
<script type="text/javascript" src="main.js">
bbCSV = 'http://localhost:8080/BB.csv';
smtCSV = 'http://localhost:8080/SMT.csv';
</script>
</body>
</code></pre>
<p>But these variables do not work in the javascript file, presumably because they are created after main.js is parsed.</p>
<p>Is there a way to create the variables before the JavaScript file is loaded?</p>
<p>Or is there a better suggested way of doing this?</p>
| [
{
"answer_id": 74382406,
"author": "vnetkc",
"author_id": 3421628,
"author_profile": "https://Stackoverflow.com/users/3421628",
"pm_score": 0,
"selected": false,
"text": "\n<script type=\"text/javascript\">\n\nconst bbCSV = 'http://localhost:8080/BB.csv';\nconst smtCSV = 'http://localhost:8080/SMT.csv';\n\n</script>\n\n<script type=\"text/javascript\" src=\"main.js\"></script> \n"
},
{
"answer_id": 74382432,
"author": "Paulo Fernando",
"author_id": 19223586,
"author_profile": "https://Stackoverflow.com/users/19223586",
"pm_score": 1,
"selected": false,
"text": "src"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2056201/"
] |
74,382,378 | <p>So i wanted the user to enter date and based on that day to get named day of the week, for example today's date is 2022.11.10, so wanted answer would be Thursday.
I know this is wrong, can anybody help?</p>
<pre><code>import datetime
def dayOfTheWeek(day, month, year):
date = datetime.date(year, month, day)
weekday = date.weekday()
day_dict = { 0 : "Monday", 1 : "Tuesday", 2 : "Wednesday", 3 : "Thursday", 4 : "Friday", 5 : "Sturday", 6 : "Sunday"}
for key in day_dict.key():
if weekday == key:
return day[key]
year = int(input("Year: "))
month = int(input("Month: "))
day = int(input("Day: "))
dayOfTheWeek(day, month, year)
</code></pre>
| [
{
"answer_id": 74382406,
"author": "vnetkc",
"author_id": 3421628,
"author_profile": "https://Stackoverflow.com/users/3421628",
"pm_score": 0,
"selected": false,
"text": "\n<script type=\"text/javascript\">\n\nconst bbCSV = 'http://localhost:8080/BB.csv';\nconst smtCSV = 'http://localhost:8080/SMT.csv';\n\n</script>\n\n<script type=\"text/javascript\" src=\"main.js\"></script> \n"
},
{
"answer_id": 74382432,
"author": "Paulo Fernando",
"author_id": 19223586,
"author_profile": "https://Stackoverflow.com/users/19223586",
"pm_score": 1,
"selected": false,
"text": "src"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12112430/"
] |
74,382,387 | <p>I have never tried this, and I have been searching to see the best way to make a script that can extract content from a txt file into their own txt files <br></p>
<p>Now I managed this and it extracts all content into their own txt files, but not sure how to make it use the extracted content as the txt filename <br></p>
<pre><code>@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ('type "a.txt"') do (
cd > %%a.txt
)
endlocal
</code></pre>
<p>so I have this <br></p>
<p>Content of my a.txt:</p>
<pre><code> All_type_2020
All_Foods_2021
</code></pre>
<p>and this is what I get</p>
<pre><code>All_type_2020All_Foods_2021.txt
</code></pre>
<p>I have tested many different scripts, and the closes I have gotten was with the script above <br></p>
<p>my goal is to have this results <br></p>
<pre><code>All_type_2020.txt
All_Foods_2021.txt
</code></pre>
| [
{
"answer_id": 74382406,
"author": "vnetkc",
"author_id": 3421628,
"author_profile": "https://Stackoverflow.com/users/3421628",
"pm_score": 0,
"selected": false,
"text": "\n<script type=\"text/javascript\">\n\nconst bbCSV = 'http://localhost:8080/BB.csv';\nconst smtCSV = 'http://localhost:8080/SMT.csv';\n\n</script>\n\n<script type=\"text/javascript\" src=\"main.js\"></script> \n"
},
{
"answer_id": 74382432,
"author": "Paulo Fernando",
"author_id": 19223586,
"author_profile": "https://Stackoverflow.com/users/19223586",
"pm_score": 1,
"selected": false,
"text": "src"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20207746/"
] |
74,382,412 | <p>I have a PHP task which I made a login page without a database and I have a button in the project file index.php i want to be unavailable for a normal user and available to an admin user.
how can I check or differentiate between user types in this case??</p>
<p>I made a login page which I save the username and password in an array like "john" => "123"</p>
| [
{
"answer_id": 74382472,
"author": "IT goldman",
"author_id": 3807365,
"author_profile": "https://Stackoverflow.com/users/3807365",
"pm_score": 1,
"selected": false,
"text": "users"
},
{
"answer_id": 74383025,
"author": "loisuperv",
"author_id": 15875287,
"author_profile": "https://Stackoverflow.com/users/15875287",
"pm_score": 0,
"selected": false,
"text": "// assuming your table looks like this\n$users = [\n 0 => [\n 'username' => 'user1',\n 'password' => 'password123',\n 'type' => 'admin'\n ],\n 1 => [\n 'username' => 'user2',\n 'password' => 'password123',\n 'type' => 'user'\n ],\n];\n\n// check type of user with id: 1\nif($users[1]['type'] == 'admin')\n{\n echo 'user is admin';\n}\nelse\n{\n echo 'user is not an admin';\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17602368/"
] |
74,382,420 | <p>I want to know if it’s possible de make a server and client in the same time using sockets</p>
<p>The goal is to do a bidirectional file transfer from client to server and from server to client using python socket</p>
<p>Any one have an idea ?</p>
| [
{
"answer_id": 74382472,
"author": "IT goldman",
"author_id": 3807365,
"author_profile": "https://Stackoverflow.com/users/3807365",
"pm_score": 1,
"selected": false,
"text": "users"
},
{
"answer_id": 74383025,
"author": "loisuperv",
"author_id": 15875287,
"author_profile": "https://Stackoverflow.com/users/15875287",
"pm_score": 0,
"selected": false,
"text": "// assuming your table looks like this\n$users = [\n 0 => [\n 'username' => 'user1',\n 'password' => 'password123',\n 'type' => 'admin'\n ],\n 1 => [\n 'username' => 'user2',\n 'password' => 'password123',\n 'type' => 'user'\n ],\n];\n\n// check type of user with id: 1\nif($users[1]['type'] == 'admin')\n{\n echo 'user is admin';\n}\nelse\n{\n echo 'user is not an admin';\n}\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11211151/"
] |
74,382,431 | <p>I have the following csv file:</p>
<pre><code>Topic,Characteristics,Total
Population and dwellings,Population-2016,183314
Population and dwellings,Population-2011,175779
Population and dwellings,Population percentage change,4.3
Age characteristics,0 to 14 years,30670
Age characteristics,0 to 4 years,9275
Age characteristics,5 to 9 years,10475
</code></pre>
<p>I would like to output a json file such that each unique 'Topic' is a key, and the value is a dictionary of 'Characteristic': 'Total', i.e. the output would be:</p>
<pre><code>{
"Population and dwellings": {
"Population-2016": 183314,
"Population-2011": 175779,
"Population percent change": 4.3
},
"Age characteristics": {
"0 to 14 years": 30670,
"0 to 4 years": 9275,
"5 to 9 years": 10475
}
}
</code></pre>
<p>How can I do this properly? All the methods I have tried so far overwrite each other, any help would be appreciated. Thanks.</p>
| [
{
"answer_id": 74382458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "csv"
},
{
"answer_id": 74382525,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 1,
"selected": false,
"text": "defaultdict"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8686353/"
] |
74,382,474 | <p>I have a dataframe with two columns of interest, one which is a binary variable (so either 1 or 0) and the other column is a collection of multiple strings. For instance, there are around 1000 different strings throughout 700k observations.
What I would like to do now: I would basically want to create a ratio WITHIN EACH group that computes the share of the sum of observations where the binary variable =1 divided by the sum of observations where the binary variable is either 1 or 0.
In addition, i would like to do it with dplyr (in case thats possible).</p>
<p>my base code looks the following, where isFraud is the binary variable and merchantName the variable that represents different groups.</p>
<pre><code>dt_nm %>%
group_by(merchantName) %>%
summarise(ratio_fraud = sum(isFraud == 1) / nrow(merchantName))
</code></pre>
<p>I know the code I inserted above does not work, however I would just like to emphasize the way i would want to code to be constructed.</p>
<p>I appreciate any help!!</p>
<p>Many thanks in advance!</p>
| [
{
"answer_id": 74382458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "csv"
},
{
"answer_id": 74382525,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 1,
"selected": false,
"text": "defaultdict"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15205232/"
] |
74,382,475 | <p>I'm confused about how to compare user input and a set list on python. For this problem, I have to create a program that asks the user for a list of ingredients. As the user enters the ingredients, I then need to store them in a list. Once the user is done entering their list, I need to pass this list to a function that will compare the ingredients to an already existing list of pantry items. If all items are available in the pantry, it should print out "you don’t need to go shopping". If any item is missing, it should print out "you need to go shopping" and list the missing ingredients. I've tried several ways of doing it but I can't figure it out.</p>
<p>So basically my function has to have:
1: A pre-created list for pantry items
2: User input into an ingredient list
3: Pass the ingredient list to a method
4: Use a conditional and loop in the method
5: Print out the results of whether the user needs to go shopping based on the items in the ingredient list that are not in the pantry.</p>
<p>This is what I have right now. Whenever I run it, it allows me to type in an item but then says <function end at 0x7fec87bf58b0> :</p>
<pre class="lang-py prettyprint-override"><code>shopping_list = []
set_list = ['bread', 'jelly', 'peanut butter', 'chips']
#prints out what I need or if I have everything on my list
def end():
for item in shopping_list:
if shopping_list == set_list:
print("you have everything")
else:
print("You have to go grocery shopping! You need:" + str(new_list))
while True:
#asks for new items and removes them from the set list to return a new list
try:
new_item = input("Item? : ")
except ValueError:
print("Oops! That was no valid item. Try again...")
new_list = set_list.remove(new_item)
print(new_list)
if new_item == 'done':
print(end)
</code></pre>
| [
{
"answer_id": 74382458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "csv"
},
{
"answer_id": 74382525,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 1,
"selected": false,
"text": "defaultdict"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463556/"
] |
74,382,514 | <p>This function works like a checklist. It takes a task name and date in the format <code>yyyy/mm/dd HH:MM:SS</code>, and appends them to a list as a tuple. However, when I print them out there is a problem.</p>
<p>When printing the tuple it look like <code>("A", 2022/12/08 22:15:56)</code>. What I am actually seeing is something like <code>('A', datetime.datetime(2022, 12, 8, 22, 23, 56)</code>.</p>
<p>The second problem I have is how to retrieve the values from inside the tuple for use in the function. I don't want them to be printed like <code>("A",2022/12/08 22:15:56)</code>. I want them to be outside of the tuple parenthesis.</p>
<pre><code>from datetime import datetime
ToDoList = []
Format_Time = "%Y/%m/%d %H:%M:%S" # formatting type for strptime function
def addNewItems():
global ToDoList
while True:
name = input("Pleas enter your task's name: ")
if checkItemExists(name) == True:
print("Task already exists! Select the options again.")
continue
else:
Task_Name = name # storing in another variable
break
while True:
date = input(
"Please enter your task's completion date as yyyy/mm/dd HH:MM:SS : ")
date = datetime.strptime(date, Format_Time)
if date < datetime.now(): # determines if the date is in the past or not
print("Time entered is in the past! Select the options again")
continue
else:
Complete_Time = date # Storing in another variable
print(Complete_Time)
break
task = (Task_Name, Complete_Time)
ToDoList.append(task)
ToDoList.sort(key=takeSecond)
def checkItemExists(taskName):
global ToDoList
for i in ToDoList:
if taskName == i[0]:
return True
def takeSecond(element):
global ToDoList
for i in ToDoList:
if element == i[0]:
return i[1]
def printListItems():
global ToDoList
for count, task in enumerate(ToDoList):
print(count, end=".")
print(task)
</code></pre>
| [
{
"answer_id": 74382681,
"author": "Nathaniel Ford",
"author_id": 442945,
"author_profile": "https://Stackoverflow.com/users/442945",
"pm_score": 1,
"selected": false,
"text": ">>> format_time = \"%Y/%m/%d %H:%M:%S\"\n>>> my_tuple = (1, datetime.strptime(\"1919/04/13 12:00:00\", format_time))\n>>> print(my_tuple)\n(1, datetime.datetime(1919, 4, 13, 12, 0))\n"
},
{
"answer_id": 74382688,
"author": "picobit",
"author_id": 6030926,
"author_profile": "https://Stackoverflow.com/users/6030926",
"pm_score": 2,
"selected": true,
"text": "datetime.now()"
},
{
"answer_id": 74383232,
"author": "RobinLeicester",
"author_id": 20454146,
"author_profile": "https://Stackoverflow.com/users/20454146",
"pm_score": 0,
"selected": false,
"text": "print (task[0],task[1])\n"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,382,522 | <p>I am really struggling plotting these spatial data points in r. I have tried using ggmap, sf, and sp but I can't get it to cooperate with me.
I have a table, tbl, that has the following makeup:
tbl</p>
<p>| lat | long | alive| species|
where lat and long are the latitude and longitude respectively. "alive" is boolean so is "TRUE" or "FALSE" and "species" is a species code for one of the three species in the data set.</p>
<p>I am trying to get a graph that has points where all of the animals were found, with the color of the point denoting if the animal was found alive or dead and the shape of the point denoting the species. So I could include a key.</p>
<p>I am more familiar with python, and I understand how I could do this in python. But I am really struggling with doing this in r. Could all of these options be passed in the 'aes' parameter? How ould I do that?</p>
<p>Most success doing:</p>
<pre><code>mapplot(longitude=table_1$lon,latitude=table_1$lat,type="p")
mapplot <- get_map(center= c(lon=mean(tbl$lon),lat=mean(tbl$lat)),zoom=2,maptype="satellite",scale=2)
ggmap(mapplot) + geom_point(data=tbl, aes(x=lon,y=lat))
</code></pre>
| [
{
"answer_id": 74382906,
"author": "Stewart Macdonald",
"author_id": 2269574,
"author_profile": "https://Stackoverflow.com/users/2269574",
"pm_score": 0,
"selected": false,
"text": "sf"
},
{
"answer_id": 74383043,
"author": "mrhellmann",
"author_id": 7547327,
"author_profile": "https://Stackoverflow.com/users/7547327",
"pm_score": 1,
"selected": false,
"text": "sf"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18433895/"
] |
74,382,584 | <p>My code runs fine, for example, if i input 123, i will get 321. However there is a problem when I try the input 01230, it would output 321. I can't seem to figure it out.</p>
<p>edit: it has to be done using integers as data type.</p>
<pre><code>while True:
reverse=0
num=str(input("Enter an integer of at least 2 digits or -1 to quit: "))
if num == str(-1):
break
elif len(num)< 2 or len(num)>11:
print("error")
else:
num=int(num)
while(num>0):
lastDigit=num%10
reverse=(reverse*10)+lastDigit
num=num//10
print(reverse)
</code></pre>
<p>I have tried using if statements to check for the zeros but i felt like that was too inefficient and couldn't figure out a better way.</p>
| [
{
"answer_id": 74382906,
"author": "Stewart Macdonald",
"author_id": 2269574,
"author_profile": "https://Stackoverflow.com/users/2269574",
"pm_score": 0,
"selected": false,
"text": "sf"
},
{
"answer_id": 74383043,
"author": "mrhellmann",
"author_id": 7547327,
"author_profile": "https://Stackoverflow.com/users/7547327",
"pm_score": 1,
"selected": false,
"text": "sf"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20463453/"
] |
74,382,684 | <p>I have this JSON:</p>
<pre class="lang-json prettyprint-override"><code>{
"agent": "Teste",
"obs": "obs 2 in other obs",
"id": 4,
"queue": "Suply",
"name": "Other"
}
</code></pre>
<p>I need a regular expression to produce this JSON:</p>
<pre class="lang-json prettyprint-override"><code>{
"agent": "Teste",
"obs": "<b>obs</b> 2 in other <b>obs</b>",
"id": 4,
"queue": "Suply",
"name": "Other"
}
</code></pre>
<p>I fail in replace because the key <code>"obs":</code> is replaced too.</p>
| [
{
"answer_id": 74382808,
"author": "morganney",
"author_id": 258174,
"author_profile": "https://Stackoverflow.com/users/258174",
"pm_score": 3,
"selected": true,
"text": "/obs(?!\":)/g\n"
},
{
"answer_id": 74383112,
"author": "user3425506",
"author_id": 3425506,
"author_profile": "https://Stackoverflow.com/users/3425506",
"pm_score": 0,
"selected": false,
"text": "const JSONString = JSON.stringify('{\"agent\": \"Teste\",\"obs\": \"obs 2 in other obs\",\"id\": 4,\"queue\": \"Suply\",\"name\":\"Other\"}');\n\nconst re = /(obs)(..[^:])/g;\n\nlet newJSONString = JSONString.replace(re, '<b>$1</b>$2');\n\nnewObject = JSON.parse(newJSONString);\n\nconsole.log(newObject);"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8773335/"
] |
74,382,690 | <p>I have an array of content blocks like so:</p>
<pre><code>interface Content{
type: string,
content: string | string[]
}
const content: Content[] = [
{
type: "heading"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "heading"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "list_item"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
]
</code></pre>
<p>I'm trying to write a function which can merge these <code>list_item</code>'s into a <code>list</code> with an array for the content of each. So, the output of the function for the above input should be:</p>
<pre><code>[
{
type: "heading"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "list"
content: ["whatever","whatever","whatever"]
},
{
type: "para"
content: "whatever"
},
{
type: "heading"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "para"
content: "whatever"
},
{
type: "list"
content: ["whatever", "whatever", "whatever", "whatever"]
},
{
type: "para"
content: "whatever"
},
]
</code></pre>
<p>I've been trying to use a three-pointer system, looping over the array from i=1 to i < length - 1, tracking the <code>prev</code>, <code>curr</code> and <code>next</code> blocks, however, I am getting very stuck with the logic and how I should handle the cases.</p>
<p>I feel like this is quite a simple problem for more experienced algorithm designers, so, I was looking for some guidance.</p>
| [
{
"answer_id": 74382824,
"author": "pilchard",
"author_id": 13762301,
"author_profile": "https://Stackoverflow.com/users/13762301",
"pm_score": 2,
"selected": true,
"text": "current.type"
},
{
"answer_id": 74383084,
"author": "dtm",
"author_id": 20320613,
"author_profile": "https://Stackoverflow.com/users/20320613",
"pm_score": -1,
"selected": false,
"text": "const a = [\n {\n type: \"heading\",\n content: \"whatever\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n {\n type: \"list_item\",\n content: \"whatever 1\"\n },\n {\n type: \"list_item\",\n content: \"whatever 2\"\n },\n {\n type: \"list_item\",\n content: \"whatever 3\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n {\n type: \"heading\",\n content: \"whatever\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n {\n type: \"list_item\",\n content: \"whatever 4\"\n },\n {\n type: \"list_item\",\n content: \"whatever 5\"\n },\n {\n type: \"list_item\",\n content: \"whatever 6\"\n },\n {\n type: \"list_item\",\n content: \"whatever 7\"\n },\n {\n type: \"para\",\n content: \"whatever\"\n },\n ]\n let listItemContent = [];\n const res = a.reduce((total, v) => {\n if(v.type === \"list_item\") {\n listItemContent.push(v.content);\n }\n else if(listItemContent.length > 0) {\n total.push({type: \"list\", content: listItemContent});\n listItemContent = [];\n } else {\n total.push(v);\n }\n return total;\n }, []);\n if(listItemContent.length > 0) {\n res.push({type: \"list\", content: listItemContent});\n }\n console.log(res)"
},
{
"answer_id": 74385378,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 1,
"selected": false,
"text": "reduce"
}
] | 2022/11/09 | [
"https://Stackoverflow.com/questions/74382690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14538687/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.