qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,132,476 | <p>I would like to know if there is way to deploy cloud run to multiple regions at once. Currently there is only one option to specify region like this</p>
<blockquote>
<p>gcloud run deploy --image gcr.io/shaale-one-development/testservice
testservice --platform managed --region=us-central1"</p>
</blockquote>
<p>is there a possibility to deploy to multiple regions say</p>
<blockquote>
<p>gcloud run deploy --image gcr.io/shaale-one-development/testservice
testservice --platform managed --region=us-central1,asia-south1"</p>
</blockquote>
<p>Currently I am not specifying the region in the command and then later choosing the regions. Since we have predefined regions deploying to those regions at once saves time.</p>
| [
{
"answer_id": 74132639,
"author": "DazWilkin",
"author_id": 609290,
"author_profile": "https://Stackoverflow.com/users/609290",
"pm_score": 2,
"selected": false,
"text": "REGIONS=(\n \"us-central1\"\n \"asia-south1\"\n)\nfor REGION in ${REGIONS[@]}\ndo\n gcloud run deploy ... -- regi... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9165735/"
] |
74,132,502 | <pre><code>public interface IPerson
{
int Id { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
string Address { get; set; }
}
List<Customer> Customers = new List<Customer>();
private void button3_Click(object sender, EventArgs e)
{
int b = Convert.ToInt32(comboBox1.Text);
foreach (IPerson person in Customers)
if (person.Id == b)
Customers.Remove((Customer)person);
}
</code></pre>
<p>I want to delete the customer data kept in this way according to the id information selected from the combobox that appears in the visual. what should I do ?</p>
| [
{
"answer_id": 74132578,
"author": "Moho",
"author_id": 1464084,
"author_profile": "https://Stackoverflow.com/users/1464084",
"pm_score": 2,
"selected": false,
"text": "List<T>"
},
{
"answer_id": 74132805,
"author": "riffnl",
"author_id": 313663,
"author_profile": "ht... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20286701/"
] |
74,132,503 | <p>Given the following function the variable <strong>currentModel</strong> is already the modified model that I want to update and it might have some properties different from the ones in the database and this function correctly updates the modified values.</p>
<p>Now I want to track the changes made before the update, the problem is that the <code>ChangeTracker</code> is detecting all properties as modified even when only one is acctualy different from the original model.</p>
<p>Is there a way to use <code>ChangeTracker</code> while also updating the statement with <code>EntityState.Modified</code> <a href="https://stackoverflow.com/questions/30987806/dbset-attachentity-vs-dbcontext-entryentity-state-entitystate-modified">(reference)</a>?</p>
<p>Here is the function used:</p>
<pre><code>public void SaveCustomer(Clients currentModel)
{
var objFromDbAct = _db.Clients.Local.FirstOrDefault(u => u.Recid == currentModel.Recid);
if (objFromDbAct != null) { _db.Entry(objFromDbAct).State = EntityState.Detached; }
_db.Entry(currentModel).State = EntityState.Modified;
_db.ChangeTracker.DetectChanges();
string trackChanges = _db.ChangeTracker.DebugView.LongView;
_db.SaveChanges();
}
</code></pre>
<p>Here is the return from ChangeTracker.DebugView.LongView (I have removed some fields to simplify, but the same applies to all of them. In this case only Zip was changed.</p>
<pre><code>Clients {Recid: 6391} Modified
Recid: 6391 PK
Additional: '' Modified
Addr1: '12345 Somewhere' Modified
Addr2: '' Modified
Addr3: <null> Modified
Zip: '000002222' Modified
PortalUsers: <null>
</code></pre>
| [
{
"answer_id": 74132759,
"author": "dropoutcoder",
"author_id": 8442437,
"author_profile": "https://Stackoverflow.com/users/8442437",
"pm_score": 3,
"selected": true,
"text": "public void SaveCustomer(Clients currentModel)\n{\n var objFromDbAct = _db.Clients.Local.FirstOrDefault(u => ... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14993187/"
] |
74,132,525 | <p>I'm attempting to create a single query that UPDATES another table but the SUBQUERY/DERIVED-QUERY that I would use requires me to have them GROUP BY and GROUP_CONCAT().</p>
<p>I was able to get my desired output but to do so I had to create a temporary table to store the "grouped/ concated" data and then push that "re-organized" data to the destination table. TO do so, I have to literally run 2 separate queries one that populates the temp table with the "organized" data in it's fields and then run another UPDATE that pushes the "organized" data from the temp table to the final destination table.</p>
<p>I've created a REPREX that exemplifies what I'm trying to achieve below:</p>
<pre><code>/*
Create a simplified sample table:
*/
CREATE TABLE `test_tbl` (
`equipment_num` varchar(20),
`item_id` varchar(40),
`quantity` decimal(10,2),
`po_num` varchar(20)
)
--
-- Dumping data for table `test_tbl`
--
INSERT INTO `test_tbl` (`equipment_num`, `item_id`, `quantity`, `po_num`) VALUES
(TRHU8399302, '70-8491', '5.00', 'PO10813-Air'),
(TRHU8399302, '40-21-72194', '22.00', '53841'),
(TRHU8399302, '741-PremBundle-CK', '130.00', 'NECTAR-PMBUNDLE-2022'),
(TRHU8399302, '741-GWPBundle-KG', '650.00', 'NECTAR2021MH185-Fort'),
(TRHU6669420, '01-DGCOOL250FJ', '76000.00', '4467'),
(TRHU6669420, '20-2649', '450.00', 'PO9994'),
(TRHU6669420, 'PFL-PC-GRY-KG', '80.00', '1020'),
(TRHU6669420, '844067025947', '120.00', 'Cmax 2 15 22'),
(TRHU5614145, 'Classic Lounge Chair Walnut leg- A XH301', '372.00', 'P295'),
(TRHU5614145, '40-21-72194', '22.00', '53837'),
(TRHU5614145, 'MAR-PLW-55K-BX', '2313.00', 'SF220914R-CA'),
(TRHU5614145, 'OPCP-BH1-L', '150.00', 'PO-00000429B'),
(TRHU5367889, 'NL1000WHT', '3240.00', 'PO1002050'),
(TRHU4692842, '1300828', '500.00', '4500342008'),
(TRHU4560701, 'TSFP-HB2-T', '630.00', 'PO-00000485A'),
(TRHU4319443, 'BGS21ASFD', '20.00', 'PO10456-1'),
(TRHU4317564, 'CSMN-AM1-X', '1000.00', 'PO-00000446'),
(TRHU4249449, '4312970', '3240.00', '4550735164'),
(TRHU4238260, '741-GWPBundle-TW', '170.00', 'NECTAR2022MH241'),
(TRHU3335270, '1301291', '60000.00', '4500330599'),
(TRHU3070607, '36082233', '150.00', '11199460'),
(TLLU8519560, 'BGM03AWFX', '360.00', 'PO10181A'),
(TLLU8519560, '10-1067', '9120.00', 'PO10396'),
(TLLU8519560, 'LUNA-KP-SS', '8704.00', '4782'),
(TLLU5819760, 'GS-1319', '10000.00', '62719'),
(TLLU5819760, '2020124775', '340.00', '3483'),
(TLLU5389611, '1049243', '63200.00', '4500343723'),
(TLLU4920852, '40-21-72194', '22.00', '53839'),
(TRHU3335270, '4312904', '1050.00', '4550694829'),
(TLLU4540955, '062-06-4580', '86.00', '1002529'),
(TRHU3335270, 'BGM03AWFK', '1000.00', 'PO9912'),
(TLLU4196942, 'Classic Dining Chair,Walnut Legs, SF XH1', '3290.00', 'P279'),
(TLLU4196942, 'BGM61AWFF', '852.00', 'PO10365');
---
--- The data above is a subsample of what I have on the db, what I'm trying to do is to update another table based off this info but with some GROUP_CONCAT()
--- With the data from above, I need to GROUP_CONCAT(item_id),GROUP_CONCAT(quantity), GROUP_CONCAT(po_num) -- grouping by equipment_num field.
---
--- What I'm attempting to do is to do an UPDATE to another table with the GROUPED by equipment_num with and the Group_concats for the fields described above.
---
--- The only way I was able to do what I desired was with a intermediary TEMPORARY table.
---
--- Create the temp table:
--- Since what I need is a "list" of the quantities, I had to do a GROUP_CONCAT(CONCAT(quantity,''))
DROP TABLE __tmp__; CREATE TABLE __tmp__
SELECT equipment_num, GROUP_CONCAT( item_id ), GROUP_CONCAT(CONCAT( quantity , '' ) ), GROUP_CONCAT( po_num )
FROM `test_tbl`
GROUP BY equipment_num
--- Then FINALLY pull the information in the format I desire to the destination table:
UPDATE `dest_tbl` AS ms INNER JOIN `__tmp__` AS isn ON ( ms.equipment_num = isn.equipment_num ) SET ms.item_id = isn.item_id,
ms.piece_count = isn.quantity,
ms.pieces_detail = isn.po_num
</code></pre>
<p>I'm trying to create a single queries that generates a derived query that does the group_concat part and then pushes that derived query result to the final destination table.</p>
<p>Any suggestions would be greatly appreciated.</p>
<p>Thank you for your time.</p>
<p>TB.</p>
<hr />
<p>EDIT: Thank you for the replies I've got, but I'm trying to AVOID using the temp table.</p>
<p>I'm trying to AVOID creating a temp table.... I'm wondering how to do it in one go...</p>
<p>I was thinking something along the lines of:</p>
<pre><code>UPDATE dest
INNER JOIN(
SELECT src.equipment_num, GROUP_CONCAT(src.item_id) as item_id,
GROUP_CONCAT(CONCAT(src.quantity)) as quantity,
GROUP_CONCAT(src.po_num) as po_num
FROM `item_shipped_ns` as src
INNER JOIN milestone_test_20221019 as dest ON(src.equipment_num=dest.equipment_num)
WHERE src.importer_id='123456'
GROUP BY src.equipment_num
) as tmp ON(src.equipment_num=tmp.equipment_num)
SET
dest.item_num=tmp.item_id,
dest.piece_count=tmp.quantity,
dest.pieces_detail=tmp.po_num;
</code></pre>
<p>Unfortunately, the above doesn't work, I get the following error msg.</p>
<blockquote>
<p>#1146 - Table 'fgcloud.dest' doesn't exist</p>
</blockquote>
<p>Edit 2: I had a missing brackets in the above which caused a different error, I've fixed it but having issues with the table aliases. The table in question that should be updated is the "milestone_test_20221019" - it is declared as "dest", yet I it says it cannot find it, suggestions? The source table which I need to get the info and aggregate before updating "milestone_test_20221019" is the "item_shipped_ns" and I believe that "tmp" table is the derived/sub-query table alias...</p>
| [
{
"answer_id": 74132573,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 2,
"selected": false,
"text": "GROUP_CONCAT()"
},
{
"answer_id": 74145649,
"author": "Technobrat",
"author_id": 13811107,
"autho... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13811107/"
] |
74,132,567 | <pre><code>#include <stdio.h>
int main(void) {
int num1;
int num2;
int i;
scanf("%d", &num1);
scanf("%d", &num2);
if (num1 <= num2) {
for(i = num1; i <= num2; i +=5 ){
printf("%d \n",i);
}
}
else {
printf("Second integer can't be less than the first.\n");
}
return 0;
}
</code></pre>
<p>I'm trying to only add one new line to the end of the outputs but every time I execute this program it adds several new lines to the end of each output and I only need one at the very last output.
for example, if I input <code>-15 10</code> then I will get an output of</p>
<pre><code> -15
-10
-5
0
5
10
</code></pre>
<p>when I'm only looking for one new line at the end of the <code>10</code>
I want my output to look like this with only one new line at the end.</p>
<pre><code>-15 -10 -5 0 5 10 \n
</code></pre>
| [
{
"answer_id": 74132602,
"author": "Vorkos",
"author_id": 6917716,
"author_profile": "https://Stackoverflow.com/users/6917716",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n\nint main(void) {\n int num1;\n int num2;\n int i;\n \n scanf(\"%d\", &num1);\n scanf(\"%d\... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20095788/"
] |
74,132,583 | <p>I was using media query and it was working, but now it just stopped working, but if I use the developer tool of the browser the media query works well
<a href="https://i.stack.imgur.com/w8AMQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w8AMQ.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/Srnsi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Srnsi.png" alt="enter image description here" /></a></p>
<p>Here is my media query code, but I dont think that that is the error</p>
<pre><code>@media only screen and (max-width: 760px) and (max-device-width: 760px) {
.conainerInp {
display: block !important;
}
.contInputs,
.contInputs3 {
flex: 100% !important;
max-width: 100% !important;
margin-bottom: 10px;
width: 100%;
}
.last {
margin-bottom: 60px;
}
.contenido {
display: flex !important;
flex-wrap: wrap !important;
}
.contenedoresGen {
max-width: 100% !important;
width: 100% !important;
}
::ng-deep .mat-horizontal-content-container {
padding: 0 !important;
}
::ng-deep.mat-horizontal-stepper-content {
overflow: auto !important;
}
::ng-deep .mat-tab-label-container {
overflow-x: auto !important;
}
}
</code></pre>
<p>the screen was at a measure less thant the indicated in the media query
<a href="https://i.stack.imgur.com/61JDk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/61JDk.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74132605,
"author": "Haim Abeles",
"author_id": 15298697,
"author_profile": "https://Stackoverflow.com/users/15298697",
"pm_score": 1,
"selected": false,
"text": "meta"
},
{
"answer_id": 74143642,
"author": "Edy",
"author_id": 18466936,
"author_profile"... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18466936/"
] |
74,132,613 | <p>What I need to do is to extend a 2D matrix to 3D and fill the 3rd axis with an arbitrary number of zero. The error returned is:</p>
<blockquote>
<p>all the input arrays must have same number of dimensions, but the
array at index 0 has 3 dimension(s) and the array at index 1 has 0
dimension(s)</p>
</blockquote>
<p>What should I correct?</p>
<pre><code>import numpy as np
kernel = np.ones((3,3)) / 9
kernel = kernel[..., None]
print(type(kernel))
print(np.shape(kernel))
print(kernel)
i = 1
for i in range(27):
np.append(kernel, 0, axis = 2)
print(kernel)
</code></pre>
| [
{
"answer_id": 74132605,
"author": "Haim Abeles",
"author_id": 15298697,
"author_profile": "https://Stackoverflow.com/users/15298697",
"pm_score": 1,
"selected": false,
"text": "meta"
},
{
"answer_id": 74143642,
"author": "Edy",
"author_id": 18466936,
"author_profile"... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132613",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11356206/"
] |
74,132,614 | <pre><code>class Human # Problem received from Raul Romero
attr_reader :name
def initialize(name)
end
end
gilles = Human.new("gilles")
anna = Human.new("gilles")
puts anna.equal?(gilles) #should output true #
puts anna + gilles # should output annagilles
</code></pre>
<p>How do I make the last line of code output annagilles?</p>
| [
{
"answer_id": 74132758,
"author": "Haumer",
"author_id": 11042897,
"author_profile": "https://Stackoverflow.com/users/11042897",
"pm_score": 3,
"selected": true,
"text": "class Human # Problem received from Raul Romero\n attr_reader :name \n \n def initialize(name)\n @name = name... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17592044/"
] |
74,132,643 | <p>I am using tableau for a dashboard that pulls data in from a MySQL database. It works perfectly but the query takes too long to execute. The data is limited to the previous 2 years and the most recent Saturday that has passed from today.</p>
<p><strong>Background info:</strong>
I have sales data on a daily cadence databased in a single table per account(client). There is a field called <em>distributor_view</em> which can have one of the following 2 values: <em>Manufacturing</em> and <em>Sourcing</em>. An item will sometimes disappear from the manufacturing view, but will always be on the sourcing. The revenue figures between the 2 are not equal, but for data completeness- if any items are missing from the manufacturing view (preferred) then the revenue is pulled from the sourcing.</p>
<p>Note: If all data is queried most of it will be duplicated on an itemId level- only about 5% of items are missing from the manufacturing view and need to be referenced by the sourcing view.</p>
<p>The logic of the query below is such that it will pull all items that are in the manufacturing view, and UNION ALL items that exist in the sourcing view and are missing from the manufacturing view.</p>
<p><strong>Query:</strong></p>
<pre><code>SELECT * FROM
(
SELECT 'Client1' as Client, date as 'Date', distributor_view as 'Distributor View', item_id as 'ItemID', product_title as 'Title', ordered_revenue as 'Ordered Revenue'
FROM table1
WHERE
distributor_view = 'Manufacturing'
AND
YEAR(date) >= YEAR(CURDATE()) - 2
AND
date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
UNION ALL
SELECT 'Client1' as Client, date as 'Date', distributor_view as 'Distributor View', item_id as 'ItemID', product_title as 'Title', ordered_revenue as 'Ordered Revenue'
FROM table1
WHERE
distributor_view = 'Sourcing'
AND
(date, item_id) NOT IN (
SELECT date, item_id FROM table1 WHERE distributor_view = 'Manufacturing' AND YEAR(date) >= YEAR(CURDATE()) - 2 AND date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
)
AND
YEAR(date) >= YEAR(CURDATE()) - 2
AND
date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
UNION ALL
SELECT 'Client2' as Client, date as 'Date', distributor_view as 'Distributor View', item_id as 'ItemID', product_title as 'Title', ordered_revenue as 'Ordered Revenue'
FROM table2
WHERE
distributor_view = 'Manufacturing'
AND
YEAR(date) >= YEAR(CURDATE()) - 2
AND
date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
UNION ALL
SELECT 'Client2' as Client, date as 'Date', distributor_view as 'Distributor View', item_id as 'ItemID', product_title as 'Title', ordered_revenue as 'Ordered Revenue'
FROM table2
WHERE
distributor_view = 'Sourcing'
AND
(date, item_id) NOT IN (
SELECT date, item_id FROM table2 WHERE distributor_view = 'Manufacturing' AND YEAR(date) >= YEAR(CURDATE()) - 2 AND date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
)
AND
YEAR(date) >= YEAR(CURDATE()) - 2
AND
date <= DATE_ADD(CURDATE(), INTERVAL(-DAYOFWEEK(CURDATE())) DAY)
) AS sales
ORDER BY date DESC
</code></pre>
<p>In an earlier iteration of this I used Python to create a script that would delete out items from sourcing that existed in manufacturing. The query would then be much simpler- a select with no regard to distributor_view. I don't like this method because it requires a script to be ran each time the data changes(daily).</p>
<p>Another option I'm brainstorming is to just pull all data and attempt to reconcile the two within tableau using some calculation.</p>
| [
{
"answer_id": 74132758,
"author": "Haumer",
"author_id": 11042897,
"author_profile": "https://Stackoverflow.com/users/11042897",
"pm_score": 3,
"selected": true,
"text": "class Human # Problem received from Raul Romero\n attr_reader :name \n \n def initialize(name)\n @name = name... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3249399/"
] |
74,132,654 | <p>I have a Next.js app which has multiple pages. Each page has the same bar at the top of the screen which displays some data which is fetched from an internal API using SWR. The issue I am having is that to fetch that data it requires an ID of the logged in user (they log in with Discord via <code>next-auth</code>) and after they have left the first page, that ID value is no longer accessible to me.</p>
<p>I have tired storing it in local storage and session storage, I have tried passing it through other components, but nothing has worked and I am out of ideas of how to fix this. Is there any other way where I can pass a value between pages? Or is there a way I can access the session data again?</p>
| [
{
"answer_id": 74132758,
"author": "Haumer",
"author_id": 11042897,
"author_profile": "https://Stackoverflow.com/users/11042897",
"pm_score": 3,
"selected": true,
"text": "class Human # Problem received from Raul Romero\n attr_reader :name \n \n def initialize(name)\n @name = name... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12263681/"
] |
74,132,684 | <p>For input values, i. e. x, y, z, n, I wanted to print all combinations as list comprehesion, where 0<=i<=x, 0<=j<=y, 0<=k<=z, where i+j+k != n.</p>
<p>How to do this? I was thinking about using itertools.permutations() but I don't know how. How to input these x, y, z, n in appropriate format?</p>
| [
{
"answer_id": 74132711,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "https://Stackoverflow.com/users/20037042",
"pm_score": -1,
"selected": true,
"text": "[(i,j,k) for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k!=n]\n"
},
{
"answer_id": 7413... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20236195/"
] |
74,132,741 | <p>For example lets say my input is 12, I am attempting to get the output of the lucas sequence to be [2 1 3 4 7 11], but instead I keep receiving the output of
[2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199]. I'm attempting to get it to display the previous sequence number before my input, but I am struggling to find out.</p>
<p>This is my code</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>my_list = [2, 1]
input = 12
while len(my_list) in range(input):
for i in my_list:
second_to_last = my_list[-2]
counter = i + second_to_last
my_list.append(counter)
print(my_list)</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74132802,
"author": "Guimoute",
"author_id": 9282844,
"author_profile": "https://Stackoverflow.com/users/9282844",
"pm_score": 3,
"selected": true,
"text": "my_list = [2, 1]\nmax_length = 12\n\nwhile len(my_list) < max_length:\n my_list.append(sum(my_list[-2:]))\n\nprin... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20017084/"
] |
74,132,742 | <p>I'm trying to create a dqn agent for a space invaders environment and I keep getting this attribute error when I try to run the program, the error pops up at the dqn.fit() line. It seems that in memory.py observations.shape in zeroed_observation cant find 'shape'.
Ive installed tensorflow-cpu, gym, gym[atari], keras-rl2, and numpy.</p>
<pre><code>import gym
# Create Deep Learning Model
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Flatten, Convolution2D
from keras.optimizers import Adam
# Apply Reinforcement Learning
from rl.agents import DQNAgent
from rl.memory import SequentialMemory
from rl.policy import LinearAnnealedPolicy, EpsGreedyQPolicy
env = gym.make('SpaceInvaders-v4', render_mode='human')
height, width, channels = env.observation_space.shape
actions = env.action_space.n
states = env.observation_space.shape
#This is for testing our environment
#Uncomment if you want to see how the game works
"""
episodes = 5
for episode in range(1, episodes+1):
state = env.reset()
done = False
score = 0
while not done:
env.render()
action = r.choice([0,1,2,3,4,5])
nState, reward, done, a, info = env.step(action)
score += reward
print(f'Episode: {episode} Score: {score}')
env.close()
"""
def buildModel(states, actions):
model = Sequential()
model.add(Convolution2D(32, (8,8), strides=(4,4), activation='relu', input_shape=(states)))
model.add(Convolution2D(64, (4,4), strides=(2,2), activation='relu'))
model.add(Convolution2D(64, (3,3), activation='relu'))
model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dense(256, activation='relu'))
model.add(Dense(actions, activation='linear'))
return model
newModel = buildModel(states, actions)
newModel.summary()
# Create our model
#model = buildModel(height, width, channels, actions)
#model.summary()
#print(model)
def buildAgent(model, actions):
# Set up our policy and memory
policy = LinearAnnealedPolicy(EpsGreedyQPolicy(), attr='eps', value_max=1.0, value_min=0.1, value_test=0.2, nb_steps=10000)
memory = SequentialMemory(limit=1000, window_length=3)
# Create our Agent
dqn = DQNAgent(model=model, memory=memory, policy=policy, enable_dueling_network=True, enable_double_dqn=True, dueling_type='avg', nb_actions=actions, nb_steps_warmup=1000)
return dqn
# Create our Agent
dqn = buildAgent(newModel, actions)
dqn.compile(Adam(learning_rate=1e-4), metrics=['mae'])
# Train our model
dqn.fit(env, nb_steps=100, visualize=False, verbose=2)
# Run and test our AI
scores = dqn.test(env, nb_episodes=30, visualize=True)
print(np.mean(scores.history['episode_reward']))```
Here is the TraceBack
```Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321,
in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135,
in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\ekche\.vscode\extensions\ms-python.python-2022.16.1\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124,
in _run_code
exec(code, run_globals)
File "c:\Users\ekche\Documents\WEBots\MLGame\SpaceInvaders.py", line 80, in <module>
# Run and test our AI
File "C:\Users\ekche\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rl\core.py",
line 168, in fit
action = self.forward(observation)
File "C:\Users\ekche\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rl\agents\dqn, line 107, in get_recent_state
state.insert(0, zeroed_observation(state[0]))
, line 63, in zeroed_observation
out.append(zeroed_observation(x))
File "C:\Users\ekche\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\rl\memory.py", line 58, in zeroed_observation
obs[key] = np.zeros(observation[key].shape)
AttributeError: 'int' object has no attribute 'shape'```
I have tried looking through the memory.py file but havent been able to make anything of it.
</code></pre>
| [
{
"answer_id": 74149499,
"author": "Bob Jones",
"author_id": 20297408,
"author_profile": "https://Stackoverflow.com/users/20297408",
"pm_score": 0,
"selected": false,
"text": "~$ conda create --name YOURENVNAME python=3.7"
}
] | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20286813/"
] |
74,132,756 | <p>I'm using SSMS and our tables have a lot of columns, so it gets frustrating trying to scroll and try to find a column. Is there a way to quickly locate a column?</p>
| [
{
"answer_id": 74149499,
"author": "Bob Jones",
"author_id": 20297408,
"author_profile": "https://Stackoverflow.com/users/20297408",
"pm_score": 0,
"selected": false,
"text": "~$ conda create --name YOURENVNAME python=3.7"
}
] | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14664018/"
] |
74,132,761 | <p>I have seen so many people discussing stuff that doesn't work all the times.</p>
<p>I am using react 18. I want to import an SVG file on my disk and render it on my DOM.</p>
<p>I tried to import it as:</p>
<pre class="lang-js prettyprint-override"><code>import { ReactComponent as Underconstruction } from '../../media/business/under-construction.svg';
const Sidebar= ()=> {
return <Underconstruction />
}
</code></pre>
<p>But it showed me this error:</p>
<p><a href="https://i.stack.imgur.com/h0pB4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h0pB4.png" alt="enter image description here" /></a></p>
<p>I have also tried to use it as a regular image tag and it showed me the same error:</p>
<pre class="lang-js prettyprint-override"><code>const Sidebar= ()=> {
return <img src={require('../../media/business/under-construction.svg')} />
}
</code></pre>
<p>and I have tried to use <code>require()</code> but it showed 404 couldn't find the file:</p>
<pre class="lang-js prettyprint-override"><code>const Sidebar= ()=> {
return <img src="../../media/business/under-construction.svg" />
}
</code></pre>
<p>I am using create-react-app</p>
<p>I am using react 18.</p>
<p>20 Oct 2022.</p>
| [
{
"answer_id": 74149499,
"author": "Bob Jones",
"author_id": 20297408,
"author_profile": "https://Stackoverflow.com/users/20297408",
"pm_score": 0,
"selected": false,
"text": "~$ conda create --name YOURENVNAME python=3.7"
}
] | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18387350/"
] |
74,132,778 | <pre><code>Sub test()
Dim diaFolder As FileDialog
Dim selected As Boolean
Dim FolderName As String
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
selected = diaFolder.Show
If selected Then
FolderName = diaFolder.SelectedItems(1)
End If
Set diaFolder = Nothing
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
xmlFileName = foldername & "/*.xml" ' I'm working on it
oXMLFile.Load xmlFileName
Set NameNode = oXMLFile.SelectNodes("/nfeProc/NFe/infNFe")
Range("A1") = NameNode(0).Attributes.getNamedItem("Id").Text ' (Range A1 + 1 ???)
End Sub
</code></pre>
<p>I changed this code to extract a specific string of a <code>.xml</code> file. It worked, but now I'm trying to change it to loop for all <code>.xml</code> files in a folder and put the results on <code>Range A1,A2,A3...until finish all files in the folder</code></p>
<p>Someone can help me?</p>
<p>Edit 1:</p>
<pre><code>Sub test ()
Dim NameNode As Object
Dim xmlIdx As Integer
Dim xmlFileName As String
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
xmlFileName = Dir("C:\Users\default\Desktop\TEST\*.xml")
xmlIdx = 1
Do While Len(xmlFileName) > 0
oXMLFile.Load xmlFileName
Set NameNode = oXMLFile.SelectNodes("/nfeProc/NFe/infNFe")
If Not NameNode Is Nothing Then
Range("A" & xmlIdx) = NameNode(0).Attributes.getNamedItem("Id").Text
xmlFileName = Dir
xmlIdx = xmlIdx + 1
Else
Set NameNode = Nothing
End If
Loop
End Sub
</code></pre>
| [
{
"answer_id": 74133176,
"author": "Whale Shark",
"author_id": 19877425,
"author_profile": "https://Stackoverflow.com/users/19877425",
"pm_score": 1,
"selected": false,
"text": "Sub test()\n Dim diaFolder As FileDialog\n Dim selected As Boolean\n Dim FolderName As String\n\n ... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10000255/"
] |
74,132,785 | <p>I'm working with an index, script and style files for my project, when I finished some modifications I want to add and commit with a message to each file, so I can track the changes that I made in that specifically file, how can I do that? (instead of doing git add -> git commit -m -> git add -> git commit -m -> ...)</p>
| [
{
"answer_id": 74133176,
"author": "Whale Shark",
"author_id": 19877425,
"author_profile": "https://Stackoverflow.com/users/19877425",
"pm_score": 1,
"selected": false,
"text": "Sub test()\n Dim diaFolder As FileDialog\n Dim selected As Boolean\n Dim FolderName As String\n\n ... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15403281/"
] |
74,132,823 | <p>Very confused about what is happening with my <code>UITableViewCell</code> when <code>reloadData</code> is called. When the tableview first loads, each cell has its correct rounding. The top has its top corners rounded, the middle has no rounding, and the bottom has only its bottom.</p>
<p>Here is what it looks like on first load:
<a href="https://i.stack.imgur.com/kZneY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kZneY.jpg" alt="First Load Cells" /></a></p>
<p>Here is what happens if a <code>tableview.reloadData</code> is called (1 or more times)
<a href="https://i.stack.imgur.com/J9bpk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J9bpk.jpg" alt="Subsequent reloads" /></a></p>
<p>Here is the code where the cells are created <code>(in func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath))</code></p>
<pre class="lang-swift prettyprint-override"><code> guard let cell = tableView.dequeueReusableCell(withIdentifier: MyCell().reuseIdentifier, for: indexPath) as? MyCell else { return UITableViewCell() }
if indexPath.row == 0 {
cell.roundCorners(corners: (top: true, bottom: false))
}
if indexPath.row == 1 {
cell.roundCorners(corners: (top: false, bottom: false))
}
if indexPath.row == 2 {
cell.roundCorners(corners: (top: false, bottom: true))
}
</code></pre>
<p>Here is the code for the rounded corners:</p>
<pre class="lang-swift prettyprint-override"><code> func roundCorners(corners: (top: Bool, bottom: Bool)) {
if !corners.top && !corners.bottom {
roundCorners(withRadius: 0)
} else if corners.top && corners.bottom {
roundCorners(withRadius: 20)
} else if corners.top {
roundCorners(corners: [.topLeft, .topRight], radius: 20)
} else if corners.bottom {
roundCorners(corners: [.bottomLeft, .bottomRight], radius: 20)
}
}
// and the actual rounding methods
func roundCorners() {
roundCorners(withRadius: bounds.size.height * 0.5)
}
func roundCorners(withRadius radius: CGFloat) {
layer.cornerRadius = radius
layer.masksToBounds = true
}
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
func maskedCorners(withRadius radius: CGFloat) {
layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
layer.cornerRadius = radius
clipsToBounds = true
}
func maskedCorners(corners: CACornerMask, radius: CGFloat) {
layer.maskedCorners = corners
layer.cornerRadius = radius
clipsToBounds = true
}
</code></pre>
<p>I have tried several things which did not work.</p>
<ol>
<li><p>Instead of reusing cells (I thought maybe the way they were being reused was mucking with the draw calls), I tried instantiating the cell each time</p>
</li>
<li><p>I tried resetting the cell borders to 0 and then setting which corners should be rounded</p>
</li>
<li><p>I tried calling the .setNeedsDisplay() after updating the borders</p>
</li>
</ol>
<p>I will also note that if I comment out the rounding calls, no rounding occurs at all, so the issue is strictly isolated to the code above.</p>
<p>Very open to suggestions as to why after the first reloadData() call it rounds the middle cell and keeps it rounded moving forward.</p>
| [
{
"answer_id": 74135964,
"author": "Ali Hamza",
"author_id": 10149222,
"author_profile": "https://Stackoverflow.com/users/10149222",
"pm_score": 2,
"selected": false,
"text": "Inset Grouped"
},
{
"answer_id": 74136539,
"author": "Mohammad Zmy",
"author_id": 12460620,
... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3324388/"
] |
74,132,825 | <p>I have string like this in javascript</p>
<p><code>at LoggerService.log (/Users/apps/api/webpack:/pcs-goc-api/pcs-libs/logger/src/logger.service.ts:107:29) </code></p>
<p>I want to extract <code>logger.service</code> from it. the formula is between last <code>/</code> to last <code>.</code></p>
<p>I can extract from last <code>/</code> using <code>/([^\/]+$)/g</code> but don't know how to limit the finding to last <code>.</code></p>
<p>Note: these are other examples:</p>
<p><code>at LoggerService.log (/Users/apps/api/webpack:/pcs-goc-api/pcs-libs/logger/src/logger.ts:107:29) </code>
expected: <code>logger</code></p>
<p><code>at LoggerService.log (/Users/apps/api/webpack:/pcs-goc-api/pcs-libs/logger/src/logger.js:107:29) </code>
expected: <code>logger</code></p>
<p><code>at LoggerService.log (/Users/apps/api/webpack:/pcs-goc-api/pcs-libs/logger/src/api.logger.service.ts:107:29) </code>
expected: <code>api.logger.service</code></p>
| [
{
"answer_id": 74132875,
"author": "Onur Uslu",
"author_id": 6106487,
"author_profile": "https://Stackoverflow.com/users/6106487",
"pm_score": 1,
"selected": false,
"text": "([^\\/]+)[.][^:]+:\\d+:\\d+\n"
},
{
"answer_id": 74132890,
"author": "Wiktor Stribiżew",
"author_i... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2279488/"
] |
74,132,882 | <p>Neovim 0.8.0 with 34 plugins via packer. In a config file I have set <code>epandtab = true</code>. But a large majority of files opened for editing have <code>noexpandtab</code> set. This issue seems to be independent of filetype; e.g., of a couple dozen .lua files tested, only 3 had an <code>expandtab</code> result for <code>:set et?</code> and the rest a <code>noexpandtab</code> result. I used grep over all my config files and all the plugin repositories to find instances of <code>expandtab</code> and found many, but most were setting it to true and the rest were setting it to false in a non-applicable context.</p>
<p>I could write an autocmd to set it to true but I wonder what, if anything, that might break. What is a good way to find out what is the "culprit"?</p>
| [
{
"answer_id": 74135524,
"author": "jdhao",
"author_id": 6064933,
"author_profile": "https://Stackoverflow.com/users/6064933",
"pm_score": 1,
"selected": false,
"text": ":verbose set expandtab?"
},
{
"answer_id": 74167350,
"author": "brec",
"author_id": 1121892,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1121892/"
] |
74,132,885 | <p>I'm new to using MongoDB queries.</p>
<p>I would like to count the number of selected answers based on the question.</p>
<p>Here is an example of data I'm trying to process:</p>
<pre><code> {
"_id": "910ef391-bc06-4fda-80c5-c6a6d9bcXXXX",
"book": {
"register": [
{
"questions": [
{
"id": "87b8c60c-9c9e-41d1-a52a-588400deXXXX",
"name": "Question A",
"answers": [
{
"_id": 1,
"label": "Answer 1",
"selected": true
},
{
"_id": 2,
"label": "Answer 2",
"selected": false
}
]
},
{
"id": "55b8c60c-9c9e-41d1-a52a-588400deXXXX",
"name": "Question B",
"answers": [
{
"_id": 1,
"label": "Answer 1",
"selected": true
},
{
"_id": 2,
"label": "Answer 2",
"selected": false
}
]
}
]
}
]
}
},
{
"_id": "120ef391-bc06-4fda-80c5-c6a6d9bcXXXX",
"book": {
"register": [
{
"questions": [
{
"id": "99b8c60c-9c9e-41d1-a52a-588400deXXXX",
"name": "Question A",
"answers": [
{
"_id": 1,
"label": "Answer 1",
"selected": true
},
{
"_id": 2,
"label": "Answer 2",
"selected": false
}
]
}
]
}
]
}
}
]
</code></pre>
<p>Here is the expected result:</p>
<pre><code>[
{
"Answer 1": 2
}
]
</code></pre>
<p>I would like to count the number of selected answers to question A.</p>
<p>I've tried something, but it returns no <code>document found</code></p>
<pre><code>db.collection.aggregate([
{
$group: {
_id: "$book.register.questions",
questions: {
$push: "$book.register.questions"
}
}
},
{
$match: {
"questions.name": "Question A"
}
}
])
</code></pre>
<p>Thank you for your help !</p>
| [
{
"answer_id": 74135524,
"author": "jdhao",
"author_id": 6064933,
"author_profile": "https://Stackoverflow.com/users/6064933",
"pm_score": 1,
"selected": false,
"text": ":verbose set expandtab?"
},
{
"answer_id": 74167350,
"author": "brec",
"author_id": 1121892,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18058472/"
] |
74,132,934 | <p>I am trying to draw a quad as the background and set it to a constant color in the fragment shader. However, only one triangle of the quad gets drawn and its scaled weirdly.
My vertices for the triangle are:</p>
<pre><code>const glm::vec3 background_vertices[6] =
{
glm::vec3(-1.0f, -1.0f, 1.0f),
glm::vec3(1.0f, -1.0f, 1.0f),
glm::vec3(1.0f, 1.0f, 1.0f),
glm::vec3(1.0f, 1.0f, 1.0f),
glm::vec3(-1.0f, 1.0f, 1.0f),
glm::vec3(-1.0f, -1.0f, 1.0f)
};
</code></pre>
<p>I generate a VAO and VBO for this quad with:</p>
<pre><code> // For background
glGenVertexArrays(1, &background_vao);
glGenBuffers(1, &background_vbo);
glBindVertexArray(background_vao);
glBindBuffer(GL_ARRAY_BUFFER, background_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(background_vertices), background_vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0);
glEnableVertexAttribArray(0);
</code></pre>
<p>And I finally draw it in my <code>display</code> function with:</p>
<pre><code> glUniform1i(UniformLocs::pass, BACKGROUND);
glBindVertexArray(background_vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
</code></pre>
<p>I also load a mesh and render that with some transparency so I have multiple shader passes (for background and for other calculations).</p>
<p>My vertex shader takes <code>in pos_attrib</code> and shoots <code>out position</code> which gets set in:</p>
<pre><code>position = (pass == 0) ? pos_attrib : vec3(M * vec4(pos_attrib, 1.0));
</code></pre>
<p>And <code>gl_Position</code> is</p>
<pre><code> gl_Position = (pass == 0) ? vec4(position, 1.0) : PV * vec4(position, 1.0);
</code></pre>
<p>Since my vertices are in NDC range, I don't apply any transformation to them and send them to the fragment shader as is.</p>
<p>My fragment shader either applies a constant color or calculates the object's transparency through:</p>
<pre><code> switch(pass)
{
case 0: // Render Background
fragcolor = vec4(0.9f, 0.45f, 0.25f, 1.0f);
break;
default:
fragcolor = min(HackTransparency(), vec4(1.0));
break;
}
</code></pre>
<p>But this results in:
<a href="https://i.stack.imgur.com/rQ4k3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rQ4k3.png" alt="Output" /></a></p>
<p>It seems straightforward but I am not able to figure out what I'm doing wrong.</p>
<p>How do I display a colored quad as the background?
Any pointers for this will be helpful.</p>
<p>Edit:
The output now looks like:
<a href="https://i.stack.imgur.com/CL1WN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CL1WN.png" alt="Latest output" /></a></p>
| [
{
"answer_id": 74132998,
"author": "user253751",
"author_id": 106104,
"author_profile": "https://Stackoverflow.com/users/106104",
"pm_score": 3,
"selected": true,
"text": "GL_CULL_FACE"
},
{
"answer_id": 74133141,
"author": "MinorMapillai",
"author_id": 8581973,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8581973/"
] |
74,132,939 | <p>I am writing automated test cases for an open source app called "Featurehub" on github. It has to be run through docker container.
I am having the problem in obtaining xpaths for elements because all of them have a same path or css selector and selenium cannot distinguish between them.
For example,
I had to implement the login test case using an enter(return) statement to get into the password field:</p>
<pre><code>def step_impl(context, email, password):
context.driver.find_element(By.XPATH, "(//body[@id='app-container']/flt-glass-pane)[1]").send_keys(email)
context.driver.find_element(By.XPATH, "(//body[@id='app-container']/flt-glass-pane)[1]").send_keys(Keys.ENTER)
context.driver.find_element(By.XPATH, "(//body[@id='app-container']/flt-glass-pane)[1]").send_keys(password)
context.driver.find_element(By.XPATH, "(//body[@id='app-container']/flt-glass-pane)[1]").send_keys(Keys.ENTER)
time.sleep(3)
</code></pre>
<p>I have attached an image below in which you can see that there are no unique xpaths and nothing is in the source code either. <a href="https://i.stack.imgur.com/ArTxU.png" rel="nofollow noreferrer">Screenshot: Chrome Dev Tools</a>
I tried recording it through Selenium IDE and it also shows same css selector for all clicks. <a href="https://i.stack.imgur.com/h7Swm.png" rel="nofollow noreferrer">Screenshot: Selenium IDE</a></p>
| [
{
"answer_id": 74132998,
"author": "user253751",
"author_id": 106104,
"author_profile": "https://Stackoverflow.com/users/106104",
"pm_score": 3,
"selected": true,
"text": "GL_CULL_FACE"
},
{
"answer_id": 74133141,
"author": "MinorMapillai",
"author_id": 8581973,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74132939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20286948/"
] |
74,133,020 | <p>I have 2 github users accounts (private and work), call them <strong>Allison</strong> and <strong>Bob</strong>.</p>
<p>I have a bash script, call it: <strong>allison_git</strong> that does:</p>
<pre><code>ssh-add -D
eval $(ssh-agent -s)
git config --global credential.helper wincred
git config --global credential.useHttpPath true
git config --global user.name Allison
git config --global user.email allison@gmail.com
ssh-add ~/.ssh/allison_git_rsa
ssh -T git@github.com
</code></pre>
<p>if all goes well for Allison, I get:
<strong>Hi Allison! You've successfully authenticated, but GitHub does not provide shell access.</strong></p>
<p>So I can switch between the users with the script that I have. Great.</p>
<p>However... say that user Bob is for my work and Allison is for my private and I'm working on my work repo but forgot to switch to Bob. <strong>My commit would apply as user Allison and not Bob.</strong></p>
<p>I'm not sure why (I guess because they're on the same computer?!) Q: how can I restrict user Allison to use Bobs repo and reverse? Is my approach to all this with the bash <strong>allison_git / bob_git</strong> causes all this?</p>
<p>Note: I added bob's pub key (bob_git_rsa ) on his github account <code>(settings-->SSH and PGP Keys)</code>, and same for allison (allison_git_rsa). The keys are different</p>
| [
{
"answer_id": 74134708,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": true,
"text": "# All work Git repositories are in a subdirectory of ~/work.\n# All other Git repositories are outside ~/work.\n[includeIf \"g... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19751436/"
] |
74,133,036 | <p>I would like to filter out from allData Dataframe those records which types appears in the wrongTypes DataFrame (it has like 2000 records). I convert the wrongTypes DF to list of Strings then in the filter check if record is in that list.
Here is my code:</p>
<pre><code>import org.apache.spark.sql.functions._
import spark.implicits._
val allData = Seq(
("id1", "X"),
("id2", "X"),
("id3", "Y"),
("id4", "A")
).toDF("id", "type")
val wrongTypes = Seq(
("X"),
("Y"),
("Z")
).toDF("type").select("type").map(r => r.getString(0)).collect.toList
allData.filter(col("type").isin(wrongTypes)).show()
</code></pre>
<p>and I get this error:</p>
<pre><code>SparkRuntimeException: The feature is not supported: literal for 'List(X, Y, Z)' of class scala.collection.immutable.$colon$colon.
</code></pre>
| [
{
"answer_id": 74136563,
"author": "user2695543",
"author_id": 2695543,
"author_profile": "https://Stackoverflow.com/users/2695543",
"pm_score": 1,
"selected": false,
"text": "allData.filter(col(\"type\").isInCollection(wrongTypes)).show()\n"
},
{
"answer_id": 74137623,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2695543/"
] |
74,133,046 | <p>I've got a bunch of log data from a KQL Table that I want to plot. Here's the simplified query:</p>
<pre><code>MyDataTable
| where ['TimeGenerated'] >= ago(30m)
| summarize count=count() by bin(TimeGenerated, 15m), log_level
</code></pre>
<p>That gets me a table like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>"TimeGenerated [UTC]"</th>
<th>"log_level"</th>
<th>count</th>
</tr>
</thead>
<tbody>
<tr>
<td>"10/19/2022, 11:00:00.000 PM"</td>
<td>info</td>
<td>3527</td>
</tr>
<tr>
<td>"10/19/2022, 11:00:00.000 PM"</td>
<td>warn</td>
<td>33</td>
</tr>
<tr>
<td>"10/19/2022, 11:00:00.000 PM"</td>
<td>error</td>
<td>2</td>
</tr>
<tr>
<td>"10/19/2022, 11:15:00.000 PM"</td>
<td>info</td>
<td>5274</td>
</tr>
<tr>
<td>"10/19/2022, 11:15:00.000 PM"</td>
<td>warn</td>
<td>42</td>
</tr>
<tr>
<td>"10/19/2022, 11:15:00.000 PM"</td>
<td>error</td>
<td>5</td>
</tr>
<tr>
<td>"10/19/2022, 11:30:00.000 PM"</td>
<td>info</td>
<td>1553</td>
</tr>
<tr>
<td>"10/19/2022, 11:30:00.000 PM"</td>
<td>warn</td>
<td>15</td>
</tr>
<tr>
<td>"10/19/2022, 11:30:00.000 PM"</td>
<td>error</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>But I want to combine the entries with the same timestamp and put the count into different columns based on log_level. Essentially, I want to end up with this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>"TimeGenerated [UTC]"</th>
<th>info</th>
<th>warn</th>
<th>error</th>
</tr>
</thead>
<tbody>
<tr>
<td>"10/19/2022, 11:00:00.000 PM"</td>
<td>3527</td>
<td>33</td>
<td>2</td>
</tr>
<tr>
<td>"10/19/2022, 11:15:00.000 PM"</td>
<td>5274</td>
<td>42</td>
<td>5</td>
</tr>
<tr>
<td>"10/19/2022, 11:30:00.000 PM"</td>
<td>1533</td>
<td>15</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>Any tips on how to do that transformation?</p>
<p>PS: An ideal solution would create new columns dynamically depending on the different values of <code>log_level</code> but if I have to use <code>info</code>/<code>warn</code>/<code>error</code> in the query that's better than the current situation.</p>
| [
{
"answer_id": 74136563,
"author": "user2695543",
"author_id": 2695543,
"author_profile": "https://Stackoverflow.com/users/2695543",
"pm_score": 1,
"selected": false,
"text": "allData.filter(col(\"type\").isInCollection(wrongTypes)).show()\n"
},
{
"answer_id": 74137623,
"auth... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1304462/"
] |
74,133,047 | <p>I have an optimization problem that has a condition such that if the variable value is greater than 0, a certain constraint applies.</p>
<p>I tried to use m.if3 to generate a binary value that assumes the value of 1 if the variable value is greater than 0, but that did not work because the m.if3 condition applies for greater than or equal to 0, and I need it to be strictly greater than 0. Here is an example of the code I had with if3 but it didn't work.</p>
<pre><code>x = m.Var(lb=0)
a = m.if3(x,0,1)
m.Equation(b - c == a*f ) #b,c,f are calculated values
</code></pre>
<p>I also attempted to use a typical if statement condition, but that did not work with the gekko variable (example below).</p>
<pre><code>if x>0:
m.Equation(b - c == f )
</code></pre>
<p>Is there another way for me to be able to apply this condition (strictly greater than zero)?</p>
| [
{
"answer_id": 74133499,
"author": "Danyal",
"author_id": 2172751,
"author_profile": "https://Stackoverflow.com/users/2172751",
"pm_score": 1,
"selected": false,
"text": "a = m.if3(x,0,1)"
},
{
"answer_id": 74134506,
"author": "John Hedengren",
"author_id": 2366941,
"... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17125325/"
] |
74,133,078 | <pre class="lang-html prettyprint-override"><code><!---LOGO IN MIDDLE-->
<style>
body{
width:100%;
height:100%;
}
img{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin-top: 31px;
}
</style>
</body>
<body>
<img src="./IMAGES/white logo.png" width="80" height="80" alt="logo">
</body>
</a>
</div>
</code></pre>
<p>I'm having problems putting background color and centering my logo in
the center of my navigation bar.</p>
| [
{
"answer_id": 74133499,
"author": "Danyal",
"author_id": 2172751,
"author_profile": "https://Stackoverflow.com/users/2172751",
"pm_score": 1,
"selected": false,
"text": "a = m.if3(x,0,1)"
},
{
"answer_id": 74134506,
"author": "John Hedengren",
"author_id": 2366941,
"... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18730427/"
] |
74,133,096 | <p>While the provided code I created works, it is non-scalable and slow. I need a way to determine if a token (t) is the same as any element in several arrays. However, it cannot match more than one array, as one list might supersede the other. Is there any way to succinctly and quickly program this in python other than using tons of individual functions?</p>
<pre><code>def keyword(t):
for n in keywords:
if t == n:
return True
break
else:
return False
def separator(t):
for n in separators:
if t == n:
return True
break
else:
return False
def operator(t):
for n in operators:
if t == n:
return True
break
else:
return False
def identifier(t):
if keyword(t) is False and operator(t) is False and separator(t) is False:
return True
else:
return False
</code></pre>
| [
{
"answer_id": 74133180,
"author": "tdelaney",
"author_id": 642070,
"author_profile": "https://Stackoverflow.com/users/642070",
"pm_score": 2,
"selected": true,
"text": "keyword"
},
{
"answer_id": 74133225,
"author": "Dante K",
"author_id": 17655168,
"author_profile":... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20286778/"
] |
74,133,097 | <p>Given this text</p>
<pre><code>unit: 100 street: 200 city: 300
</code></pre>
<p>How do I write a regex that will give this output as different groups in JS. I also need to mention that the text may not contain street or city. It could just be <code>unit: 100</code>.</p>
<pre><code>group[1] - 100
group[2] - 200
group[3] - 300
</code></pre>
<p>Where I'm at so far - <code>unit:\s(.*?)\s(?:.*|$)</code></p>
<p>Not sure how to proceed further and get all 3 groups in one regex!</p>
| [
{
"answer_id": 74133319,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 0,
"selected": false,
"text": "match()"
},
{
"answer_id": 74134628,
"author": "anubhava",
"author_id": 548225,
"author_... | 2022/10/19 | [
"https://Stackoverflow.com/questions/74133097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11944367/"
] |
74,133,118 | <p>I have an array i'm attempting to sort by the amount of total orders. I am having an issue finding a way to solve this goal. I've tried looking up examples and couldn't find a question similar to what I am attempting to do</p>
<p>I currently have an array of data that I am trying to sort by the largest amount of orders to the least amount of orders.</p>
<p>I am currently sorting by the length of the array which is not giving what I want because some orders can have a count of 10. Which would be greater then some arrays of a higher length but lower count.</p>
<p>How can I sort by the total of <code>items.amount</code> within the sort method?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const orders = [{
id: 242,
items: [{
id: '3000',
amount: 2
},
{
id: '3001',
amount: 1
},
{
id: '3002',
amount: 4
}
]
}, {
id: 1,
items: [{
id: '3000',
amount: 10
}]
},
{
id: 14,
items: [{
id: '3211',
amount: 3
},
{
id: '3000',
amount: 1
}
]
}
]
const sortedOrders = orders.sort(
(taskA, taskB) =>
taskB.items.length - taskA.items.length
);
console.log(sortedOrders)</code></pre>
</div>
</div>
</p>
<p>I am expecting an output like this with <code>amount: 10</code> being the greatest value so displaying first:</p>
<pre><code>[
{
"id": 242,
"items": [
{
"id": 1,
"items": [
{
"id": "3000",
"amount": 10
}
]
},
{
"id": "3000",
"amount": 2
},
{
"id": "3001",
"amount": 1
},
{
"id": "3002",
"amount": 4
}
]
},
{
"id": 14,
"items": [
{
"id": "3211",
"amount": 3
},
{
"id": "3000",
"amount": 1
}
]
}
]
</code></pre>
| [
{
"answer_id": 74133246,
"author": "Urenbach",
"author_id": 20195074,
"author_profile": "https://Stackoverflow.com/users/20195074",
"pm_score": 2,
"selected": true,
"text": "function totalAmount(order) {\n let sum = 0;\n for (let i = 0; i < order.items.length; i++) {\n sum +... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13366922/"
] |
74,133,128 | <p>I'm writing unit tests where I use the fetch command to return a response object back and store it in a variable.</p>
<p>But when I try to convert back to text, it returns <code>[object Blob]</code></p>
<p>Any ideas of what's going wrong?</p>
<p>Here's my code:</p>
<pre><code>const obj = { hello: "world" };
const blob = new Blob([JSON.stringify(obj, null, 2)], {
type: "application/json",
});
var init = { "status" : 200 , "statusText" : "SuperSmashingGreat!" };
var myResponse = new Response(blob, init);
console.log(await myResponse.text()); // [object Blob]
</code></pre>
<p>Any ideas where I'm going wrong? I want to get "hello world" back from the response.</p>
| [
{
"answer_id": 74133246,
"author": "Urenbach",
"author_id": 20195074,
"author_profile": "https://Stackoverflow.com/users/20195074",
"pm_score": 2,
"selected": true,
"text": "function totalAmount(order) {\n let sum = 0;\n for (let i = 0; i < order.items.length; i++) {\n sum +... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1447849/"
] |
74,133,145 | <p>This is probably an example of an untrained person trying to get a simple outcome using the wrong tools; but...</p>
<p>I've got a really simple database with a Client Table and a Review Table, each entry on the Review table is linked to a ClientID. I want to view the last review for the client when I'm on a form linked to the Client table.</p>
<p>I think the best way to do this is to create a query. Ive tried two approaches;</p>
<pre><code>SELECT TableClient.ClientID, TableClient.ClientFullName, Max(TableReviews.ReviewDate) AS LastReview
FROM TableClient INNER JOIN TableReviews ON TableClient.ClientID = TableReviews.ReviewClient
GROUP BY TableClient.ClientID, TableClient.ClientFullName;
</code></pre>
<p>This gives me the most recent review date, but no clear way (in my limited understanding) to get the other data from the Review table, like ReviewID or the Review Notes. whenever I try this, it just returns all the entries from the Review table. I think my problem with this approach is that I don't understand the how to use the GROUP function for an enquiry like this.</p>
<p>The other approach I've tried is to just query the Review table;</p>
<pre><code>SELECT TableReviews.ReviewClient, TableReviews.ReviewID, Max(TableReviews.ReviewDate) AS LastReview
FROM TableReviews
GROUP BY TableReviews.ReviewClient, TableReviews.ReviewID;
</code></pre>
<p>This gives me all the results in my Review table, but again, no way to group/restrict the results to the most recent review for each client.</p>
<p>I've struggled to write an SQL statement that groups or filters properly. This seems like it should be simple, and usually this means I'm trying to solve the problem using the wrong tools. Should I be using a different approach to grab the most recent Review for a client?</p>
<p>many thanks.</p>
<p>UPDATE - I need a query that shows the most recent review for each client, so my TableReviews is:</p>
<pre><code>ReviewID ReviewDate ReviewClient
1 17/10/2022 Johnny Smith
2 4/10/2022 Neddy Not-Here
3 13/10/2022 Johnny Smith
4 3/10/2022 Johnny Smith
</code></pre>
<p>and the desired result would be</p>
<pre><code>ReviewID ReviewDate ReviewClient
1 17/10/2022 Johnny Smith
2 4/10/2022 Neddy Not-Here
</code></pre>
| [
{
"answer_id": 74133246,
"author": "Urenbach",
"author_id": 20195074,
"author_profile": "https://Stackoverflow.com/users/20195074",
"pm_score": 2,
"selected": true,
"text": "function totalAmount(order) {\n let sum = 0;\n for (let i = 0; i < order.items.length; i++) {\n sum +... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5614609/"
] |
74,133,148 | <p>I have a data frame like this:</p>
<pre><code>ID <- c("x", "y", "z", "ad", "tgfg", "gfgh", "asj", "gh", "sdf", "asdgz")
diagnosis <- c("yes", "no", "yes", "yes", "yes", "no", "yes", "no", "no", "no")
Q1 <- c("A",NA,"A",NA,NA,"C","D","A","B", NA)
Q2 <- c("D",NA,"D","C",NA,NA,"A","A","A","A")
Q3 <- c("B","B","C","A",NA,"A","B","D","E",NA)
Q4 <- c("B",NA,"C","C","C","C","D","B",NA,"A")
mydf <- data.frame(ID, diagnosis, Q1,Q2,Q3,Q4)
mydf
ID diagnosis Q1 Q2 Q3 Q4
x yes A D B B
y no <NA> <NA> B <NA>
z yes A D C C
ad yes <NA> C A C
tgfg yes <NA> <NA> <NA> C
gfgh no C <NA> A C
asj yes D A B D
gh no A A D B
sdf no B A E <NA>
asdgz no <NA> A <NA> A
</code></pre>
<p>I want to eliminate participants who did not answer more than 2 questions in the test(rows including more than 2 NAs) but only for the diagnosed group. I don't want to touch the undiagnosed group although they might have more than 2 NAs.</p>
<p>This is what I tried after my search on stackoverflow:</p>
<pre><code>delete.na <- function(DF, n=0) {
DF[rowSums(is.na(DF)) <= n,]
}
new_df <- mydf %>% group_by(diagnosis== "yes") %>% delete.na(2) %>% ungroup()
new_df
ID diagnosis Q1 Q2 Q3 Q4 `diagnosis == "yes"`
x yes A D B B TRUE
z yes A D C C TRUE
ad yes NA C A C TRUE
gfgh no C NA A C FALSE
asj yes D A B D TRUE
gh no A A D B FALSE
sdf no B A E NA FALSE
asdgz no NA A NA A FALSE
</code></pre>
<p>As you can see, although participant "y" doesn't belong to "diagnosis == yes" group, it got deleted too. What should I do to prevent it?</p>
<p>Thanks a lot!</p>
| [
{
"answer_id": 74133246,
"author": "Urenbach",
"author_id": 20195074,
"author_profile": "https://Stackoverflow.com/users/20195074",
"pm_score": 2,
"selected": true,
"text": "function totalAmount(order) {\n let sum = 0;\n for (let i = 0; i < order.items.length; i++) {\n sum +... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19838934/"
] |
74,133,183 | <p><a href="https://i.stack.imgur.com/DTJ03.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTJ03.png" alt="enter image description here" /></a>I uploaded a list of highly frequent words which includes stop words and I used the STOPWORDS list to remove stop words. When I print my word cloud, it's not displaying several non-stopwords that are high ranking.</p>
<p>For example, "data" and "learning" appear more frequently than "distribution", "algorithm" and such. Other words like "training", "regression" are also missing despite ranking high in frequency. (No, none of these words exist in the STOPWORDS list.) How can I get words like "data", "learning", "training" to appear according to their frequency?
(I've attached a screenshot of the words/frequencies.)</p>
<p>Here's the code:</p>
<pre><code>from wordcloud import WordCloud, STOPWORDS
text = open("test.txt", mode="r", encoding="utf-8").read()
wc = WordCloud(background_color="white", stopwords=STOPWORDS, height=400, width=600)
wc.generate(text)
wc.to_file("my_first_word_cloud.png")
</code></pre>
<p><a href="https://i.stack.imgur.com/NezyZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NezyZ.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74136731,
"author": "lynx",
"author_id": 13130448,
"author_profile": "https://Stackoverflow.com/users/13130448",
"pm_score": 1,
"selected": false,
"text": "from wordcloud import WordCloud, STOPWORDS\ntext = open(\"test.txt\", mode=\"r\", encoding=\"utf-8\").read()\n\nwc = ... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17854139/"
] |
74,133,201 | <p>New to power automate. I've created a flow that gets specific rows from an html_to_text output. That one works fine, but the requirement is that I also need to display rows that contain "FAIL"</p>
<p>What I did was to create an array and then a condition where "Current item contains FAIL". If "yes", then it will display the current item + the initial output for the other string.</p>
<p>I have 240 rows of html_to_text data.</p>
<p>The apply_to_each and its condition works, but I don't know how to display ALL of the outputs that had 'FAIL' string in them in one Compose.</p>
<p><a href="https://i.stack.imgur.com/qf53E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qf53E.png" alt="If expression result is false" /></a></p>
<p><a href="https://i.stack.imgur.com/K04L4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K04L4.png" alt="if expression result is true" /></a></p>
| [
{
"answer_id": 74136731,
"author": "lynx",
"author_id": 13130448,
"author_profile": "https://Stackoverflow.com/users/13130448",
"pm_score": 1,
"selected": false,
"text": "from wordcloud import WordCloud, STOPWORDS\ntext = open(\"test.txt\", mode=\"r\", encoding=\"utf-8\").read()\n\nwc = ... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13074283/"
] |
74,133,202 | <p>I have the following list in grid which works so well, but I haven't been able to centralize it according the green section. I've already tried to use <code>flex</code>, but it didn't work. Could anybody help me kindly?</p>
<p>EDIT: I've added more itens to the list, once that it grid adjust itself to show more itens in rows. When I've tried to use the codes indicated in the answers, the grid is centralized, but in only one row (and I don't know if it is possible to centralize it with more than one row in the grid).</p>
<p>I inserted below my main code showing what I have done until now.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>section {
background: green
}
#related-posts ul {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fill, minmax(min(7.1rem, 100%), 1fr));
justify-items: center;
}
#related-posts ul li {
display: inline-block;
text-align: center;
vertical-align: top;
}
.pthumb img {
height: 97px;
width: 129px;
object-fit: cover;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><section>
<div id="related-posts">
<ul>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 1</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 2</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 3</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 4</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 5</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 6</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 7</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 8</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 9</a>
</li>
</ul>
</div>
</section></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74133249,
"author": "Bits Please",
"author_id": 9699127,
"author_profile": "https://Stackoverflow.com/users/9699127",
"pm_score": 2,
"selected": true,
"text": "display: grid;\njustify-content: center;\n"
},
{
"answer_id": 74133257,
"author": "Crystal",
"aut... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6419926/"
] |
74,133,212 | <p>All the methods I have seen in blazor wasm to inject Javascript involves calling a javascript function. what if I want to inject a dynamic javascript function block.
Example: <code>await JS.InvokeVoidAsync("<script>alert('A')</script",null);</code>
Is this possible? "InvokeAsync" only seems to accept a function name.</p>
| [
{
"answer_id": 74133249,
"author": "Bits Please",
"author_id": 9699127,
"author_profile": "https://Stackoverflow.com/users/9699127",
"pm_score": 2,
"selected": true,
"text": "display: grid;\njustify-content: center;\n"
},
{
"answer_id": 74133257,
"author": "Crystal",
"aut... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5837255/"
] |
74,133,220 | <h1>Question:</h1>
<p>How do I modify an element within an established list and re-assign it back to the list in the same index/position?</p>
<h1>Setup and Example</h1>
<p>First, here's a dataframe that I am breaking up by groups into a list:</p>
<pre><code>library(tidyverse) # Not absolutely required, but I'm working this way.
df <- tibble(A = rep(paste("Group", c(1:3)),3),
B = seq(1, 18, 2),
C = (1:9))
lst <- df %>%
group_by(A) %>%
group_split()
</code></pre>
<p>Dataframe and resulting list should be as below:</p>
<pre><code>> df
# A tibble: 9 × 3
A B C
<chr> <dbl> <int>
1 Group 1 1 1
2 Group 2 3 2
3 Group 3 5 3
4 Group 1 7 4
5 Group 2 9 5
6 Group 3 11 6
7 Group 1 13 7
8 Group 2 15 8
9 Group 3 17 9
> lst
<list_of<
tbl_df<
A: character
B: double
C: integer
>
>[3]>
[[1]]
# A tibble: 3 × 3
A B C
<chr> <dbl> <int>
1 Group 1 1 1
2 Group 1 7 4
3 Group 1 13 7
[[2]]
# A tibble: 3 × 3
A B C
<chr> <dbl> <int>
1 Group 2 3 2
2 Group 2 9 5
3 Group 2 15 8
[[3]]
# A tibble: 3 × 3
A B C
<chr> <dbl> <int>
1 Group 3 5 3
2 Group 3 11 6
3 Group 3 17 9
</code></pre>
<h2>Here's the problem...</h2>
<p>For reasons irrelevant here, I need to give each sub-dataframe in the list a different treatment based on the Group. I thought I could apply the modifications in a loop like below, leaving the list structure in place.</p>
<pre><code>for (j in 1:3){
lst[[j]] <- lst[[j]] %>%
mutate(D = B * C)
}
</code></pre>
<p>...but that throws this error:</p>
<pre><code>Error in `[[<-`:
! Can't convert from `value` <tbl_df<
A: character
B: double
C: integer
D: double
>> to <tbl_df<
A: character
B: double
C: integer
>> due to loss of precision.
</code></pre>
<p>I know that the assignment back to the list is the problem, because I can successfully do this:</p>
<pre><code>df2 <- NULL
df_final <- NULL
for (j in 1:3){
df2 <- lst[[j]] %>%
mutate(D = B * C)
df_final <- rbind(df_final, df2)
}
df_final
</code></pre>
<p>...which returns a dataframe that I could break back up as in the beginning.</p>
<pre><code>> df_final
# A tibble: 9 × 4
A B C D
<chr> <dbl> <int> <dbl>
1 Group 1 1 1 1
2 Group 1 7 4 28
3 Group 1 13 7 91
4 Group 2 3 2 6
5 Group 2 9 5 45
6 Group 2 15 8 120
7 Group 3 5 3 15
8 Group 3 11 6 66
9 Group 3 17 9 153
</code></pre>
<p>...but I feel like I'm missing some nuance in how the list could be assigned "in place" as above, and I don't understand the error message. What am I missing about assigning to lists that makes <code>lst[[j]] <- lst[[j]] %>% <ANY MODIFICATION></code> fail?</p>
| [
{
"answer_id": 74133285,
"author": "Ric Villalba",
"author_id": 6912817,
"author_profile": "https://Stackoverflow.com/users/6912817",
"pm_score": 3,
"selected": true,
"text": "group_split()"
},
{
"answer_id": 74133297,
"author": "Matt",
"author_id": 12967938,
"author_... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3601357/"
] |
74,133,242 | <p>I have two HTML files - <code>a.html</code> and <code>b.html</code>. I would like to replace the title tag in <code>b.html</code> with the one in <code>a.html</code>.</p>
<p>How would we do it using shell script? I know how to do a simple replacement in the same file by using <code>sed</code> command.</p>
<p><strong>a.html</strong></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-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document AAAAA</title>
</head>
<body>
This is Document A
</body>
</html></code></pre>
</div>
</div>
</p>
<p><strong>b.html</strong></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-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document BBBB</title>
</head>
<body>
This is Document B
</body>
</html></code></pre>
</div>
</div>
</p>
<p><strong>b.html - afer running the script</strong> - Notice "Document BBBBB" is changed to "Document AAAAA"</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-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document AAAAA</title>
</head>
<body>
This is Document B
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74133402,
"author": "petrus4",
"author_id": 2953345,
"author_profile": "https://Stackoverflow.com/users/2953345",
"pm_score": 0,
"selected": false,
"text": "sed -i 's@BBBBB@AAAAA@' b.html\n"
},
{
"answer_id": 74133681,
"author": "Max Ivanov",
"author_id": 2... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9013776/"
] |
74,133,265 | <p>I have a large data set (35.8 GB, over 1 billion rows) that I need to tidy.</p>
<p>Here is some reproducible code to show its format.</p>
<pre><code>id <- c(1, 1, 2, 2)
item <- c("a1", "a2", "a1", "a2")
itemformat <- c("AA", "AB", "BB", "AB")
full <- cbind(id, item, itemformat)
full <- as.data.table(full)
full
</code></pre>
<p>This code works for this example:</p>
<pre><code>full2 <- full %>%
pivot_wider(names_from = item, values_from = itemformat)
full2
</code></pre>
<p>However, when using this method on the massive dataset, R has either said that a vector of size 3.8 GB is too large (I restarted R and used the gc() function) or just crashed (after working for over 30 minutes).</p>
<p>I have noticed that <strong>fread()</strong> and <strong>fwrite()</strong> from the <strong>data.table</strong> package are much faster than anything else I've used (e.g., <strong>read.csv()</strong> and <strong>read_csv()</strong>).</p>
<p>So, is there a way (per the <strong>data.table</strong> package, perhaps?) to rearrange this data into having roughly 800,000 columns?</p>
<p>Also, is 800,000 columns above some sort of limit?</p>
<p>After tidying this, the file size should go down (hopefully).</p>
<p>Side note: I have 64 GB of RAM.</p>
<p>Thank you!</p>
| [
{
"answer_id": 74133885,
"author": "jared_mamrot",
"author_id": 12957340,
"author_profile": "https://Stackoverflow.com/users/12957340",
"pm_score": 2,
"selected": false,
"text": "cat full.csv\n\"id\",\"item\",\"itemformat\"\n\"1\",\"a1\",\"AA\"\n\"1\",\"a2\",\"AB\"\n\"2\",\"a1\",\"BB\"\n... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16870643/"
] |
74,133,303 | <p><strong>I want to center the Text("MJ") without it being moved if i added another widget</strong></p>
<pre><code> body: SingleChildScrollView(
child: Column(children: [
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(height: 60, width: 200, child: CircleAvatar())
]),
Padding(
padding: EdgeInsets.only(top: 10),
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text("MJ"),
Icon(Icons.verified),
]),
),
]))
</code></pre>
<p><strong>Current run</strong>
<a href="https://i.stack.imgur.com/VVdFK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VVdFK.png" alt="Here's a run of this code snippet" /></a></p>
<p><strong>What i want to do:</strong>
<a href="https://i.stack.imgur.com/lVUHa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lVUHa.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74133885,
"author": "jared_mamrot",
"author_id": 12957340,
"author_profile": "https://Stackoverflow.com/users/12957340",
"pm_score": 2,
"selected": false,
"text": "cat full.csv\n\"id\",\"item\",\"itemformat\"\n\"1\",\"a1\",\"AA\"\n\"1\",\"a2\",\"AB\"\n\"2\",\"a1\",\"BB\"\n... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13861519/"
] |
74,133,306 | <pre><code>xmin = as.integer(readline("Input the left boundary of the period: "))
xmax = readline("Input the right boundary of the period: ")
step = readline("Input the step of the sequence: ")
new.function = function(xmin, xmax, step) {
while (xmin<=xmax) {
y = (5 + log(xmin) * exp(xmin) * xmin - (1.5/xmin))
print(y)
xmin = as.integer(xmin) + as.integer(step)
}
}
v <- unlist(new.function(xmin, xmax, step))
print(v)
</code></pre>
<p>I would like to change the answer to vector, which mean showing all answers in one line
not in 4 consecutive lines. If I input 1, 4, 1 the answer will be 3.5 to 307.1 from top to bottom.
Is it possible to get the answer in one line? (3.5, 14.49341, 70.69865, 307.3814)</p>
| [
{
"answer_id": 74133342,
"author": "onyambu",
"author_id": 8380272,
"author_profile": "https://Stackoverflow.com/users/8380272",
"pm_score": 3,
"selected": true,
"text": "new.function = function(xmin, xmax, step) {\n y <- c() ## Add this to your function\n while (xmin<=xmax) {\n y =... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287224/"
] |
74,133,346 | <p>I have structs that just contain data, a minimal example would be</p>
<pre><code>struct A{
int a;
};
struct B{
int a;
int b;
};
</code></pre>
<p>I realized now after using these two structs that A is always should be a subset of B. Because of this, I would like to couple the structs together, so any change in A is reflected in B.</p>
<p>The most obvious way to do this is with inheritance, so just</p>
<pre><code>struct B: public A{
int b;
};
</code></pre>
<p>However, I don't want any accidental object slicing, so I also want for B to not visibly subtype A. Basically, I don't want users to know that B extends A, it should be hidden as an implementation detail.</p>
<p>I know that the standard is "favor composition over inheritance", but that would make it so accessing the fields of B would be like "B.inner.a", which I don't really want for various reasons. Like I stated before, I want the knowledge that B is a superset of A to be an implementation detail.</p>
<p>So far, the only things I know about C++ inheritance is that it can be public, protected, or private, but none of those modifiers help me here. Is there any language features or standard practices that can help me here?</p>
| [
{
"answer_id": 74133342,
"author": "onyambu",
"author_id": 8380272,
"author_profile": "https://Stackoverflow.com/users/8380272",
"pm_score": 3,
"selected": true,
"text": "new.function = function(xmin, xmax, step) {\n y <- c() ## Add this to your function\n while (xmin<=xmax) {\n y =... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12310828/"
] |
74,133,347 | <p>So, I generated like thousands of images that I need to rename with this format:</p>
<p><strong>19-10-2022 17-35-10</strong> (HH:MM:SS format)</p>
<p>And the next one should be:</p>
<p><strong>19-10-2022 17-35-11</strong> (increases by one second) and so on.</p>
<p>Also, my images are perfectly numbered (like 1.png, 2.png, 3.png and so on)</p>
<p>Is there any way to archieve this with a bash script or something? I would like to specify the starting date as well.</p>
<p>Edit: I have already searched for this question all over internet and I couldn't find any useful information. All I find is how to append regular dates and not a custom one that increases by one second like I am asking here.</p>
<p>Edit 2: I need it to be a different starting date than "now".</p>
| [
{
"answer_id": 74133554,
"author": "dimich",
"author_id": 14772619,
"author_profile": "https://Stackoverflow.com/users/14772619",
"pm_score": 3,
"selected": true,
"text": "#!/bin/bash\n\nSTART=$(date +\"%s\" -d \"2022-10-20 13:00\")\n\nfor F in *.png; do\n N=\"${F%.png}\"\n DATE=$(... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287213/"
] |
74,133,357 | <p>I am trying to optimize a function with 2 inputs, each being a list of numbers. I created these similar but simpler version of the function:</p>
<pre><code>w1 = [1,2,3]
w2 = [4,5,6]
w = [w1,w2]
def objective(x):
a = x[0][0]**2+x[0][1]**2+x[0][2]**2+x[1][0]**2+x[1][1]**2+x[1][2]**2
return a
bnds_1 = tuple((0.1, 1) for w in w1)
bnds_2 = tuple((0,0.5) for w in w2)
result = minimize(objective,x0=w,bounds=(bnds_1,bnds_2))
result
</code></pre>
<p>where the bound for each number in w1 is (0.1,1) and bound for each number in w2 is (0,0.5)</p>
<p>I get the following error when running the code:</p>
<blockquote>
<p>ValueError: length of x0 != length of bounds</p>
</blockquote>
<p>Could you please advise on what's wrong with this?</p>
<p>P.S. I know that I could put both w1 and w2 in 1 list and just call the different items, but was just wondering why this method with 2 inputs doesn't work</p>
| [
{
"answer_id": 74133554,
"author": "dimich",
"author_id": 14772619,
"author_profile": "https://Stackoverflow.com/users/14772619",
"pm_score": 3,
"selected": true,
"text": "#!/bin/bash\n\nSTART=$(date +\"%s\" -d \"2022-10-20 13:00\")\n\nfor F in *.png; do\n N=\"${F%.png}\"\n DATE=$(... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287252/"
] |
74,133,375 | <p>I would like to increment salary number inside map function.</p>
<p>My code is currently working but I would like to know is this a correct way to increment number in React or what is the better method or how else should I do it?</p>
<p>find below the code so far</p>
<pre><code>const users = [
{
id: 1,
name: "Tiger Nixon",
salary: 320800,
age: 61,
},
{
id: 2,
name: "Garrett Winters",
salary: 170750,
age: 63,
},
{
id: 3,
name: "Ashton Cox",
salary: 86000,
age: 66,
},
{
id: 4,
name: "Cedric Kelly",
salary: 433060,
age: 22,
}
]
</code></pre>
<pre><code>const [salary, setSalary] = useState(users)
const incrementSalary = (employeeSalary) => {
salary.map(x =>
x.salary === employeeSalary? {...salary, salary : x.salary += 1} : x
)
setSalary([...salary])
}
return (
<tbody>
{salary.map((employee) => (
<tr key={employee.id}>
<th>{employee.id}</th>
<td>{employee.name}</td>
<td>{employee.age}</td>
<td>
<button>
-
</button>
<span>{employee.salary}</span>
<button onClick={() => incrementSalary(employee.salary)}>
+
</button>
</td>
</tr>
)}
</tbody>
</code></pre>
| [
{
"answer_id": 74133554,
"author": "dimich",
"author_id": 14772619,
"author_profile": "https://Stackoverflow.com/users/14772619",
"pm_score": 3,
"selected": true,
"text": "#!/bin/bash\n\nSTART=$(date +\"%s\" -d \"2022-10-20 13:00\")\n\nfor F in *.png; do\n N=\"${F%.png}\"\n DATE=$(... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11539744/"
] |
74,133,381 | <p>In the Aptos Move docs, it explains how to interact with a smart contract which has exposed "entry functions".In the hello_blockchain example, set_message is used.</p>
<blockquote>
<p>Move modules expose access points, also referred as entry functions. These access points can be called via transactions. The CLI allows for seamless access to these access points. The example Move module hello_blockchain exposes a set_message entry function that takes in a string. This can be called via the CLI:</p>
</blockquote>
<p>However, there is no explanation on how to query the get_message function which to my understanding is akin to a read function.</p>
<p>Furthermore, there is no explanation of how to query read/write functions using the Python SDK.</p>
<p>Two questions:</p>
<ol>
<li>Is it possible to use the Python SDK to query read/write functions in a Move module?</li>
<li>How do you define a read function in a Move module?</li>
</ol>
| [
{
"answer_id": 74227930,
"author": "Daniel Porteous",
"author_id": 3846032,
"author_profile": "https://Stackoverflow.com/users/3846032",
"pm_score": 2,
"selected": false,
"text": "curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/<addr>/resource/<resource>\n"
},
{
"answer_i... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20122954/"
] |
74,133,430 | <p>Ultimately, I'd like to have an extra feature in my app if the app is running on AWS EC2.</p>
<p>How do I check and set a variable to indicate if it is on AWS or not? I found <a href="https://stackoverflow.com/questions/66647568/nodejs-detect-whether-app-is-on-aws-or-local">this thread</a> to do the check, but upon startup how do I set a variable across the app like a boolean? Something like:</p>
<pre><code>let checkAWS;
metadata.isEC2().then(function (onEC2) {
checkAWS = true;
console.log("EC2: " + onEC2);
});
let app = express();
app.locals.isAWS = checkAWS;
console.log(checkAWS);
</code></pre>
<p>Every time, I always get the same output:</p>
<pre><code>undefined
EC2: true
</code></pre>
<p>I am using the <code>isAWS</code> variable in my <code>.ejs</code> file to decide on that functionality.</p>
| [
{
"answer_id": 74227930,
"author": "Daniel Porteous",
"author_id": 3846032,
"author_profile": "https://Stackoverflow.com/users/3846032",
"pm_score": 2,
"selected": false,
"text": "curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/<addr>/resource/<resource>\n"
},
{
"answer_i... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20235528/"
] |
74,133,433 | <p>I have a function that will accept 3 arguments; an array of data, a key and a <strong>partial value</strong>. I want to group the results by a value that may be in each objects nested array. It looks like my code is working, but I'm wondering if refactoring to use reduce would be better. Here is what I have:</p>
<pre><code>const arr = [
{
"id": "vghjnbghjkoijhjnmkjhjk",
"region": "US",
"tags": ["tag1:bvghjhgh","tag2:bvghjkjnm","tag3:vghjbghj"]
},
{
"id": "cvbhyt56789-mnbvghyu76",
"region": "US",
"tags": ["tag1:bvghjhgh"]
},
{
"id": "ghjkjnbhjnbhjkmnhjkmjk",
"region": "US",
"tags": ["tag2:bvghjkjnm"]
},
{
"id": "ghjkjnbhjnbhjkmnhjkmjk",
"region": "US",
"tags": []
},
{
"id": "bghjkjnbghjkjnhjnbhjhj",
"region": "CA",
"tags": ["tag1:bvghjhgh","tag3:vghjbghj"]
}
];
</code></pre>
<p>The expected results are as follows, based on a key of <code>tags</code> and a value of <code>tag1</code>:</p>
<pre><code>[
[
{
"id": "vghjnbghjkoijhjnmkjhjk",
"region": "US",
"tags": ["tag1:bvghjhgh","tag2:bvghjkjnm","tag3:vghjbghj"]
},
{
"id": "cvbhyt56789-mnbvghyu76",
"region": "US",
"tags": ["tag1:bvghjhgh"]
},
{
"id": "bghjkjnbghjkjnhjnbhjhj",
"region": "CA",
"tags": ["tag1:bvghjhgh","tag3:vghjbghj"]
}
],
[
{
"id": "ghjkjnbhjnbhjkmnhjkmjk",
"region": "US",
"tags": ["tag2:bvghjkjnm"]
},
{
"id": "ghjkjnbhjnbhjkmnhjkmjk",
"region": "US",
"tags": []
},
]
]
</code></pre>
<p>Here is my current function:</p>
<pre><code>function groupData(arr, key, value) {
const grouped = {};
const remaining = [];
for (const obj of arr) {
const index = obj[key].findIndex(elem => elem.includes(value));
if (index > -1) {
const groupByKey = obj[key][index];
if (grouped.hasOwnProperty(groupByKey)) {
grouped[groupByKey].push(obj);
} else {
grouped[groupByKey] = [obj];
}
} else {
remaining.push(obj);
}
}
return [Object.values(grouped).flat(), noMatch];
}
</code></pre>
| [
{
"answer_id": 74133586,
"author": "Ry-",
"author_id": 707111,
"author_profile": "https://Stackoverflow.com/users/707111",
"pm_score": 0,
"selected": false,
"text": "groupBy"
},
{
"answer_id": 74134075,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "h... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7338454/"
] |
74,133,470 | <p>I try to delete some of my post with slug but it's not found.
My route:</p>
<pre><code>Route::resource('/dashboard/berita', DashboardController::class)->parameters([
'berita' => 'post:slug'
])->middleware('auth');
</code></pre>
<p>My Controller:</p>
<pre><code>public function destroy(Post $post) {
$post->delete();
return redirect('/dashboard/berita')->with('success', 'Berita sudah dihapus!');
}
</code></pre>
<p>My blade:</p>
<pre><code><form action="{/dashboard/berita/{{ $post->slug }}}" method="post" class="d-inline">
@method('delete')
@csrf
<button class="badge bg-danger border-0"> </button>
</form>
</code></pre>
| [
{
"answer_id": 74133586,
"author": "Ry-",
"author_id": 707111,
"author_profile": "https://Stackoverflow.com/users/707111",
"pm_score": 0,
"selected": false,
"text": "groupBy"
},
{
"answer_id": 74134075,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "h... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20154462/"
] |
74,133,487 | <p>I have the following data frame:</p>
<pre><code>| Category | idlist |
| -------- | -----------------------------------------------------------------|
| new | {100: ['1A', '2B'], 200: ['2A', '3B'], 300: ['3A', '3B', '4B']} |
| old | ['99A', '99B'] |
</code></pre>
<p>I want it to be converted into this:</p>
<pre><code>| Category | id | list |
| -------- | --- | -------------------- |
| new | 100 | ['1A', '2B'] |
| new | 200 | ['2A', '3B'] |
| new | 300 | ['3A', '3B', '4B'] |
| old | -1 | ['99A', '99B'] |
</code></pre>
<p>The column 'idlist' is a json for category new with id as key and value a list of items. Then there is category that is old and it just has a list of items and since it doesn't have any id we can default it to -1 or 0.</p>
<p>I was trying some examples on internet but I was not able to flatten the json for category new because the key is a number. Can this be achieved? I can handle the old separately as a subset by putting id as '-1' because I really don't need to flatten the cell corresponding to old. But is there a way to handle all this together?</p>
<p>As requested, I am sharing the original JSON format before I converted it into a df:</p>
<pre><code>{'new' : {100: ['1-A', '2-B'], 200: ['2-A', '3-B'], 300: ['3-A', '3-B', '4-B']}, 'old' : ['99-A', '99-B']}
</code></pre>
| [
{
"answer_id": 74133807,
"author": "G.G",
"author_id": 20284103,
"author_profile": "https://Stackoverflow.com/users/20284103",
"pm_score": 1,
"selected": false,
"text": " def function1(s:pd.Series):\n global df2\n list1 = []\n var1=eval(s.idlist)\n if isinstance(var1,dict):... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12203155/"
] |
74,133,497 | <p>I'm trying to modify a table by transferring the address direction in one field to another field.
So lets say the Addresses in the "Address" field of said table is "123 Fake Street S" I need to transfer just the S into a field called "strtDirect". However, some of the addresses do not have a direction associated with them. So the code I have now is as follows:[Code in Calculate Field tool][1] [1]: https://i.stack.imgur.com/GSfsg.jpg</p>
<p>(the pic will give a better picture): So this code transfers the direction into the correct field but when it gets to an address with no direction associated with it, the fields stop being filled out. I think I need an if statement in there. Any thoughts would be appreciated. I'm pretty new to this.</p>
<pre><code> def GetStrtDirect(strtAddress):
aList = strtAddress.split(" ")
return aList[3]
</code></pre>
| [
{
"answer_id": 74133807,
"author": "G.G",
"author_id": 20284103,
"author_profile": "https://Stackoverflow.com/users/20284103",
"pm_score": 1,
"selected": false,
"text": " def function1(s:pd.Series):\n global df2\n list1 = []\n var1=eval(s.idlist)\n if isinstance(var1,dict):... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287344/"
] |
74,133,524 | <p>I'm trying to create a visual-only freight calculation area for a school project. But the input is taking the edge off the div as I change the font size of the input and the button.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.box-cep {
width : 245px;
height : 30px;
margin-top : 10px;
margin-left : 25px;
border : 2px solid black;
}
.box-cep input {
width : 150px;
height : 30px;
border : none;
}
.box-cep button {
width : 90px;
height : 30px;
border : none;
background-color : #FF7518;
color : white;
font-family : "Century Gothic";
font-size : 18px;
font-weight : bold;
}
.cep-txt {
font-family : "Century Gothic";
font-size : 14px;
padding-left : 5px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="box-cep">
<label for="">
<input type="text" class="cep-txt" placeholder="Digite seu CEP...">
<button>Calcular!</button>
</label>
</div></code></pre>
</div>
</div>
</p>
<p><img src="https://i.stack.imgur.com/Dir4Q.png" alt="Printscreen" /></p>
| [
{
"answer_id": 74133789,
"author": "Huda Addelson",
"author_id": 19123792,
"author_profile": "https://Stackoverflow.com/users/19123792",
"pm_score": 0,
"selected": false,
"text": "height : 30px"
},
{
"answer_id": 74133806,
"author": "Ferri Adi Prasetya",
"author_id": 1952... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287385/"
] |
74,133,559 | <p>So i have a problem with my static files. Here's my code:</p>
<pre><code>const express = require ('express')
const app = express()
app.listen(4040,() => console.log("on"))
app.use(express.static(__dirname + "/public"))
</code></pre>
<p>Everything works. Until I change html file name in public folder
It works if it's index.html but doesn't if it's about.html or everything else.</p>
<p>My folders are like that:</p>
<pre><code>Main
node_modules
public
assets
style.css
index.html/about.html
main.js
package-lock.json
package.json
</code></pre>
| [
{
"answer_id": 74133789,
"author": "Huda Addelson",
"author_id": 19123792,
"author_profile": "https://Stackoverflow.com/users/19123792",
"pm_score": 0,
"selected": false,
"text": "height : 30px"
},
{
"answer_id": 74133806,
"author": "Ferri Adi Prasetya",
"author_id": 1952... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20179833/"
] |
74,133,566 | <p>Below is a piece of code which provides an example of using inner class in Java.
I would like to know how the inner class instance <em>iterator</em> is created and linked to the <em>arrayOfInts</em> array.</p>
<pre><code> DataStructureIterator iterator = this.new EvenIterator();
</code></pre>
<p>I understand that the <em>'ds'</em> instance is created by the constructor of <em>DataStructure</em> class, but the <em>iterator</em> instance is of <em>DataStructureIterator</em> type. It seems not quite reasonable that a <em>DataStructureIterator</em> instance can be constructed by a constructor of another class.</p>
<p>Full code here:</p>
<pre><code>public class DataStructure {
// Create an array
private final static int SIZE = 15;
private int[] arrayOfInts = new int[SIZE];
public DataStructure() {
// fill the array with ascending integer values
for (int i = 0; i < SIZE; i++) {
arrayOfInts[i] = i;
}
}
public void printEven() {
// Print out values of even indices of the array
DataStructureIterator iterator = this.new EvenIterator();
while (iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
System.out.println();
}
interface DataStructureIterator extends java.util.Iterator<Integer> { }
// Inner class implements the DataStructureIterator interface,
// which extends the Iterator<Integer> interface
private class EvenIterator implements DataStructureIterator {
// Start stepping through the array from the beginning
private int nextIndex = 0;
public boolean hasNext() {
// Check if the current element is the last in the array
return (nextIndex <= SIZE - 1);
}
public Integer next() {
// Record a value of an even index of the array
Integer retValue = Integer.valueOf(arrayOfInts[nextIndex]);
// Get the next even element
nextIndex += 2;
return retValue;
}
}
public static void main(String s[]) {
// Fill the array with integer values and print out only
// values of even indices
DataStructure ds = new DataStructure();
ds.printEven();
}
}
</code></pre>
<p><em>This is a question from the Oracle's Java documents, here is the source: <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html</a></em></p>
| [
{
"answer_id": 74133789,
"author": "Huda Addelson",
"author_id": 19123792,
"author_profile": "https://Stackoverflow.com/users/19123792",
"pm_score": 0,
"selected": false,
"text": "height : 30px"
},
{
"answer_id": 74133806,
"author": "Ferri Adi Prasetya",
"author_id": 1952... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287388/"
] |
74,133,574 | <p>When I run <code>firebase deploy --only functions</code> I get this error:</p>
<pre class="lang-bash prettyprint-override"><code>Build failed: node:internal/errors:477
ErrorCaptureStackTrace(err);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /workspace/src/index.ts
at new NodeError (node:internal/errors:387:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:76:11)
at defaultGetFormat (node:internal/modules/esm/get_format:118:38)
at checkSyntax (node:internal/main/check_syntax:57:26) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}; Error ID: 037e0eb0
Functions deploy had errors with the following functions:
triggerMe(us-central1)
</code></pre>
<p>I'm also getting an error in the Firebase Console showing a red triangle next to this function, saying <code>Function deployment failed. Please try again.</code></p>
<p>I ran <code>npm outdated</code> and <code>npm update</code>, everything is the latest version.</p>
<p>Here's my <code>index.ts</code> file:</p>
<pre class="lang-js prettyprint-override"><code>const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.triggerMe = functions.firestore.document('Triggers/{docId}').onWrite((data, context) => {
console.log("Trigger warning!")
console.log(data.message);
return 30
});
</code></pre>
<p>I was getting errors about the <code>data</code> and <code>context</code> parameters being implicit <code>any</code> type so I added <code>"noImplicitAny": false,</code> to <code>tsconfig.json</code>:</p>
<pre class="lang-js prettyprint-override"><code>{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"noImplicitAny": false,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
</code></pre>
<p>I also tried switching <code>strict</code> to <code>false</code>. This didn't help.</p>
<p>In my <code>environments.ts</code> file I added <code>useEmulators: true</code>. I get this error whether this property is set to <code>true</code> or <code>false</code>.</p>
<p>Here's my <code>functions/package.json</code>:</p>
<pre class="lang-js prettyprint-override"><code>{
"name": "functions",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "src/index.ts",
"dependencies": {
"firebase-admin": "^10.2.0",
"firebase-functions": "^3.21.0"
},
"devDependencies": {
"typescript": "^4.8.4"
},
"private": true
}
</code></pre>
<p>And the other <code>package.json</code> file:</p>
<pre class="lang-js prettyprint-override"><code>{
"name": "triggerable-functions-tutorial",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^14.2.0",
"@angular/common": "^14.2.0",
"@angular/compiler": "^14.2.0",
"@angular/core": "^14.2.0",
"@angular/fire": "^7.4.1",
"@angular/forms": "^14.2.0",
"@angular/platform-browser": "^14.2.0",
"@angular/platform-browser-dynamic": "^14.2.0",
"@angular/router": "^14.2.0",
"firebase": "^9.12.1",
"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^14.2.6",
"@angular/cli": "~14.2.6",
"@angular/compiler-cli": "^14.2.0",
"@types/jasmine": "~4.3.0",
"jasmine-core": "~4.4.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.8.4"
}
}
</code></pre>
<p>And <code>firebase.json</code>:</p>
<pre class="lang-js prettyprint-override"><code>{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}
</code></pre>
| [
{
"answer_id": 74133649,
"author": "Pexers",
"author_id": 9213148,
"author_profile": "https://Stackoverflow.com/users/9213148",
"pm_score": 2,
"selected": true,
"text": "\"type\": \"module\""
},
{
"answer_id": 74143438,
"author": "Thomas David Kehoe",
"author_id": 5153354... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5153354/"
] |
74,133,606 | <p>my rust version is 1.64.0.</p>
<p>In file "C:\Users\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs".
I see the implementation of std::ptr::slice_from_raw_parts:</p>
<pre><code>pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
from_raw_parts(data.cast(), len)
}
</code></pre>
<p>In file "C:\Users\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\metadata.rs". I see the implementation of from_raw_parts:</p>
<pre><code>pub const fn from_raw_parts<T: ?Sized>(
data_address: *const (),
metadata: <T as Pointee>::Metadata,
) -> *const T {
// SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T
// and PtrComponents<T> have the same memory layouts. Only std can make this
// guarantee.
unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
}
</code></pre>
<p>The function slice_from_raw_parts return type is *const [T], the function from_raw_parts return type is *const T.</p>
<p>Why function slice_from_raw_parts can directly return function from_raw_parts's result?</p>
<p>They have different return type.</p>
| [
{
"answer_id": 74133649,
"author": "Pexers",
"author_id": 9213148,
"author_profile": "https://Stackoverflow.com/users/9213148",
"pm_score": 2,
"selected": true,
"text": "\"type\": \"module\""
},
{
"answer_id": 74143438,
"author": "Thomas David Kehoe",
"author_id": 5153354... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287409/"
] |
74,133,634 | <p>I'm trying to debug a javascript file, but whenever I use the Chrome Devtools, a random old JS file opens instead. I haven't been able to move on with my project because of this. Does anybody know why it won't read the current file? You can see down on the gif that I am using index.js but every time I debug it opens a random file and reads that instead.</p>
<p><a href="https://i.stack.imgur.com/zBGQs.gif" rel="nofollow noreferrer">GIF OF THE ERROR</a></p>
| [
{
"answer_id": 74133649,
"author": "Pexers",
"author_id": 9213148,
"author_profile": "https://Stackoverflow.com/users/9213148",
"pm_score": 2,
"selected": true,
"text": "\"type\": \"module\""
},
{
"answer_id": 74143438,
"author": "Thomas David Kehoe",
"author_id": 5153354... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133634",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12305989/"
] |
74,133,665 | <p>I have a language link, which opens up a vertical menu of language choice:</p>
<p><a href="https://i.stack.imgur.com/aIqNG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIqNG.png" alt="enter image description here" /></a></p>
<p>This is its html:</p>
<pre><code><div class="header__lang-container _flex-column-center nav__item-container">
<a href="" class="nav__simple-link header__lang lang-switcher">eng</a>
<ul class="lang-container">
<li><a href="" data-lang="eng" class="lang-container__eng lang-container__item">eng</a></li>
<li><a href="" data-lang="ukr" class="lang-container__ukr lang-container__item">ukr</a></li>
</ul>
</div>
</code></pre>
<p>And CSS:</p>
<pre><code>.lang-container {
margin-top: .5em;
background-color: white;
border-radius: 15px;
padding: .5em 0;
position: absolute;
top: 15px;
transition: opacity 2s;
display: none;
opacity: 0;
}
</code></pre>
<p>I want this menu to pop up gradually, which means I want to gradually set the opacity from zero to one. I set the opacity from javascript code through click event (don't pay attention to multiple const_switchers, there are several of them on my page):</p>
<pre><code>const lang_switchers = document.querySelectorAll('.lang-switcher');
lang_switchers.forEach((lang_switcher) => {
const lang_container = lang_switcher.nextElementSibling;
let container_is_shown = false;
lang_switcher.addEventListener('click', (e) => {
e.preventDefault();
if(!container_is_shown) {
lang_container.style.display = "block";
lang_container.style.opacity = '1';
}
else {
lang_container.style.opacity = '0';
lang_container.style.display = "none";
}
container_is_shown = !container_is_shown;
});
});
</code></pre>
<p>However, when I click the link, the menu immediately shows up, not gradually. Does this mean I cannot change opacity using transition through js? If no, is there a way to do it using css?</p>
| [
{
"answer_id": 74133815,
"author": "DSDmark",
"author_id": 16517581,
"author_profile": "https://Stackoverflow.com/users/16517581",
"pm_score": 0,
"selected": false,
"text": "Run snippet"
},
{
"answer_id": 74133850,
"author": "Henhen1227",
"author_id": 7729847,
"author... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19517550/"
] |
74,133,684 | <p>I'm trying to obtain the following:</p>
<pre class="lang-none prettyprint-override"><code>+--------------------+
|work_time | day_shift|
+--------------------+
| 00:45:40 | No |
| 10:05:47 | Yes |
| 15:25:28 | Yes |
| 19:38:52 | No |
</code></pre>
<p>where I classify the "work_time" into "day_shift".<br />
"Yes" - if the time falls between 09:00:00 and 18:00:00<br />
"No" - otherwise</p>
<p>My "work_time" is in datetime format showing only the time. I tried the following, but I'm just getting "No" for everything.</p>
<pre class="lang-py prettyprint-override"><code>df = df.withColumn('day_shift', when(df.work_time >= to_timestamp(lit('09:00:00'), 'HH:mm:ss') & df.work_time <= to_timestamp(lit('18:00:00'), 'Yes').otherwise('No'))
</code></pre>
| [
{
"answer_id": 74134125,
"author": "Jonathan Lam",
"author_id": 10445333,
"author_profile": "https://Stackoverflow.com/users/10445333",
"pm_score": 0,
"selected": false,
"text": "TimestampType"
},
{
"answer_id": 74137212,
"author": "ZygD",
"author_id": 2753501,
"autho... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16875138/"
] |
74,133,790 | <p>I have the following within my <code>App.js</code> file:</p>
<pre><code>let theme = createTheme({
palette: {
bgCells: {
textAlign: 'right',
color: '#8ccadf',
backgroundColor: '#eef7ff'
}
}
});
</code></pre>
<p>I then have another component <code>Report.js</code> where I would like to access <code>bgCells</code> within a className via the useTheme hook, i.e.:</p>
<pre><code>import React from 'react';
import { TableCell, TableRow, useTheme } from '@mui/material';
export default function Report(props) {
const { info } = props;
const theme = useTheme();
let myClass;
if (info.is_active) {
myClass = classes.someStyles;
} else {
myClass = theme.palette.bgCells;
}
return (
<TableRow className={myClass}>
<TableCell>
{
. . . .
</code></pre>
<p>Unfortuantely this is not working as <code>myClass = theme.palette.bgCells</code> is not being reference within my <code><TableRow className={myClass}></code></p>
<p>Any ideas as to what I am missing?</p>
| [
{
"answer_id": 74134125,
"author": "Jonathan Lam",
"author_id": 10445333,
"author_profile": "https://Stackoverflow.com/users/10445333",
"pm_score": 0,
"selected": false,
"text": "TimestampType"
},
{
"answer_id": 74137212,
"author": "ZygD",
"author_id": 2753501,
"autho... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15958296/"
] |
74,133,824 | <p>I am trying to write a function in python that takes a phone number as a string and provides me all the permutations of number combinations that are 1 "character" away.</p>
<p>So for example if the phone number is 9879876 it would return 8879876, 6879876, 9579876, 9779876, 9979876, so on so forth. I have tried mapping it out each of the 10 options using str.replace but it changes all instances of that number rather than only that specific number. I've also tried using the "count" parameter in the replace function but it still did not work.</p>
<p>So to clarify, I wanted to create permutations with a pattern format.</p>
<pre><code>rep1 = ["2","4"]
rep2 = ["1","3","5"]
rep3 = ["2","6"]
rep4 = ["1","5","7"]
rep5 = ["2","4","6","8"]
rep6 = ["3","5","9"]
rep7 = ["4","8"]
rep8 = ["5","7","9","0"]
rep9 = ["6","8"]
rep0 = ["8"]
</code></pre>
<p>If the current digit in the loop is 1 then replace that with each char in rep1 while keeping the rest of the phone number intact. If the current digit is a 2 then replace it with each char in rep2. I'm didn't use this list approach in my current code, its just for explanation of the conditional changes.</p>
<pre><code>def myfunc(phone:str):
for digit in phone:
if digit == "1":
newphone = phone.replace("1", "2", 1)
print(newphone)
newphone = phone.replace("1", "4",1)
print(newphone)
if digit == "2":
newphone = phone.replace("2", "1",1)
print(newphone)
newphone = phone.replace("2", "3",1)
print(newphone)
newphone = phone.replace("2", "5",1)
print(newphone)
if digit == "3":
newphone = phone.replace("3", "2",1)
print(newphone)
newphone = phone.replace("3", "6",1)
print(newphone)
if digit == "4":
newphone = phone.replace("4", "1",1)
print(newphone)
newphone = phone.replace("4", "5",1)
print(newphone)
newphone = phone.replace("4", "7",1)
print(newphone)
if digit == "5":
newphone = phone.replace("5", "2",1)
print(newphone)
newphone = phone.replace("5", "4",1)
print(newphone)
newphone = phone.replace("5", "6",1)
print(newphone)
newphone = phone.replace("5", "8",1)
print(newphone)
if digit == "6":
newphone = phone.replace("6", "3",1)
print(newphone)
newphone = phone.replace("6", "5",1)
print(newphone)
newphone = phone.replace("6", "9",1)
print(newphone)
if digit == "7":
newphone = phone.replace("7", "4",1)
print(newphone)
newphone = phone.replace("7", "8",1)
print(newphone)
if digit == "8":
newphone = phone.replace("8", "5",1)
print(newphone)
newphone = phone.replace("8", "7",1)
print(newphone)
newphone = phone.replace("8", "9",1)
print(newphone)
newphone = phone.replace("8", "0",1)
print(newphone)
if digit == "9":
newphone = phone.replace("9", "6",1)
print(newphone)
newphone = phone.replace("9", "8",1)
print(newphone)
if digit == "0":
newphone = phone.replace("0", "8",1)
print(newphone)
</code></pre>
<p>This didn't work and there must be a more elegant solution and probably easier solution. Any help would be appreciated, thanks!</p>
| [
{
"answer_id": 74133844,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 2,
"selected": true,
"text": "replace()"
},
{
"answer_id": 74134223,
"author": "Xin Cheng",
"author_id": 4708399,
"author_profil... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287584/"
] |
74,133,827 | <p>I want to perform a general version of</p>
<pre class="lang-py prettyprint-override"><code>df.groupby([columns]).agg(new_name1=('col1':'min'),
new_name2=('col1':'max'),
new_name3=('col2':'mean'))
</code></pre>
<p>I would like to be able to specify the new column names dynamically so that this function is general.
ie -</p>
<pre><code>d = {
'new_name1':('col1':'min'),
'new_name2':('col1':'max'),
'new_name3':('col2':'mean')
}
</code></pre>
<p>And then use this dictionary in the agg, doing something like</p>
<pre><code>groupby([columns]).agg(d)
</code></pre>
<p>Currently all I can do is</p>
<pre><code>groupby([columns]).agg({'col1':['min', 'max'] 'col2':['mean']}).reset_index()
</code></pre>
<p>But that returns a dataframe where the aggregations down a level and I can't rename them.</p>
| [
{
"answer_id": 74133915,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile": "https://Stackoverflow.com/users/10315163",
"pm_score": 3,
"selected": true,
"text": "**"
},
{
"answer_id": 74133993,
"author": "G.G",
"author_id": 20284103,
"author_profile": "htt... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10339757/"
] |
74,133,836 | <p>Is there a better way to get the Site Names that represent the top 25% of total cases. My approach worked but I wonder if there is a better way. I used =SUM(B3:B426)/4 which resulted in 281.5, then I added 0+44 to get 44. Then I added 44 + 39 to get 83. I repeated the process until I got close to 281.5. Any Suggestions Is appreciated.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">Row Labels</th>
<th style="text-align: left;">Count of Site Name</th>
<th>281.5</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Site - 470</td>
<td style="text-align: left;">44</td>
<td>44</td>
</tr>
<tr>
<td style="text-align: left;">Site - 316</td>
<td style="text-align: left;">39</td>
<td>83</td>
</tr>
<tr>
<td style="text-align: left;">Site - 222</td>
<td style="text-align: left;">38</td>
<td>121</td>
</tr>
<tr>
<td style="text-align: left;">Site - 496</td>
<td style="text-align: left;">34</td>
<td>155</td>
</tr>
<tr>
<td style="text-align: left;">Site - 279</td>
<td style="text-align: left;">20</td>
<td>175</td>
</tr>
<tr>
<td style="text-align: left;">Site - 435</td>
<td style="text-align: left;">16</td>
<td>191</td>
</tr>
<tr>
<td style="text-align: left;">Site - 335</td>
<td style="text-align: left;">16</td>
<td>207</td>
</tr>
<tr>
<td style="text-align: left;">Site - 507</td>
<td style="text-align: left;">15</td>
<td>222</td>
</tr>
<tr>
<td style="text-align: left;">Site - 301</td>
<td style="text-align: left;">15</td>
<td>237</td>
</tr>
<tr>
<td style="text-align: left;">Site - 413</td>
<td style="text-align: left;">14</td>
<td>251</td>
</tr>
<tr>
<td style="text-align: left;">Site - 542</td>
<td style="text-align: left;">13</td>
<td>264</td>
</tr>
<tr>
<td style="text-align: left;">Site - 473</td>
<td style="text-align: left;">12</td>
<td>276</td>
</tr>
<tr>
<td style="text-align: left;">Site - 469</td>
<td style="text-align: left;">12</td>
<td>288</td>
</tr>
<tr>
<td style="text-align: left;">Site - 136</td>
<td style="text-align: left;">12</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 506</td>
<td style="text-align: left;">11</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 498</td>
<td style="text-align: left;">10</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 427</td>
<td style="text-align: left;">10</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 277</td>
<td style="text-align: left;">9</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 522</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 424</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 228</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 233</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 275</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 141</td>
<td style="text-align: left;">8</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 494</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 230</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 208</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 253</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 439</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 366</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 151</td>
<td style="text-align: left;">7</td>
<td></td>
</tr>
<tr>
<td style="text-align: left;">Site - 520</td>
<td style="text-align: left;">6</td>
<td></td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74133915,
"author": "Ynjxsjmh",
"author_id": 10315163,
"author_profile": "https://Stackoverflow.com/users/10315163",
"pm_score": 3,
"selected": true,
"text": "**"
},
{
"answer_id": 74133993,
"author": "G.G",
"author_id": 20284103,
"author_profile": "htt... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11308695/"
] |
74,133,845 | <p>I have pair of images in the folder:</p>
<p>221013.bmp<br />
221013.png<br />
221018.bmp<br />
221018.png<br />
221020.bmp<br />
221020.png</p>
<p>I'm trying to merge every pair of images in a folder and combine that result into a JPG file with imagemagick</p>
<p><code>magick convert C:\Img\*.bmp -set filename:f "%t" "C:\Img\%[filename:f].png" -composite "C:\Img\%[filename:f].jpg"</code></p>
<p>One JPG with correct name is created and error:<br />
convert: unable to open image 'C:\Img%[filename:f].png': No such file or directory @ error/blob.c/OpenBlob/3537.</p>
<p>Any idea?, thank you.</p>
| [
{
"answer_id": 74133925,
"author": "Ryan Cargan",
"author_id": 8953964,
"author_profile": "https://Stackoverflow.com/users/8953964",
"pm_score": 0,
"selected": false,
"text": "convert -list configure"
},
{
"answer_id": 74134390,
"author": "GeeMack",
"author_id": 8174768,
... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287282/"
] |
74,133,847 | <p>I'm trying to make cell G3 say "Completed" when all cells from
A3:E3 say "Completed" (for this, Im using =IF(AND) statement). Also trying to make G3 say "In progress" when either from A3:E3 say "Started" (for this I'm using =OR statement).</p>
<p>I'm very new into this, sorry about my ignorance.</p>
<pre><code>=IF(AND(A3="Completed",C3="Completed",E3="Completed"),"Completed","Pending")=IF(OR(A3:E3="Started"),"In Progress")
</code></pre>
<p><img src="https://i.stack.imgur.com/EcCeS.png" alt="Cell G3 with a FALSE value, not sure how to put together this formula" /></p>
| [
{
"answer_id": 74134320,
"author": "Max R",
"author_id": 19662289,
"author_profile": "https://Stackoverflow.com/users/19662289",
"pm_score": 2,
"selected": false,
"text": "condition"
},
{
"answer_id": 74135415,
"author": "Ike",
"author_id": 16578424,
"author_profile":... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17260465/"
] |
74,133,863 | <p>I want to position a box within a floor and 4 walls so the boxes movements would be within a constraint. <a href="https://codesandbox.io/s/oc9qh?file=/src/App.js" rel="nofollow noreferrer">This example</a> shows a floor and backwall and works fine. However. I want to add left/right and front wall, so it can't exceed those bounds.</p>
<p>Adding in <code><PhyPlane color="lightblue" position={[0, 0, 10]} /></code> Which would add another plane near the user sends the physics boxes haywire. They get pushed out of the current camera view and don't just drop down like the original example.</p>
<p>But the boxes are within the 3 planes so it doesn't make sense why they're affected by the plane hitboxes.</p>
<p>How can I create a boundary plane box around a box so it won't move past that size. Like if the box is 10x10, if it hits the sides then it'd just interact like a normal physics object hitting a wall.</p>
<h3>EDIT</h3>
<p>Even with just 2 planes, <code><PhyPlane color="lightblue" position={[0, 0, 10]} /></code> modifying the existing backplane to be a frontplane with that code, the box object shoots off into nowhere.</p>
<p>I wonder if the issue is the rendering order of everything. So, ALL objects would render into the scene at exactly the same time. Both the box and the plane start at origin <code>[0, 0, 0]</code>, then the plane moves to <code>[0, 0, 10]</code>, which would push the box in that direction.</p>
<p>Can the plane be set not register any items until it reaches it's intended position?</p>
<p>Seems that, if I set the mass to be 0, or type not to be dynamic, the boxes wouldn't get initially pushed by the planes. Then I'd just need to set the type back to dynamic after the scene loaded up.</p>
| [
{
"answer_id": 74134320,
"author": "Max R",
"author_id": 19662289,
"author_profile": "https://Stackoverflow.com/users/19662289",
"pm_score": 2,
"selected": false,
"text": "condition"
},
{
"answer_id": 74135415,
"author": "Ike",
"author_id": 16578424,
"author_profile":... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17094284/"
] |
74,133,874 | <p>The requirements for the codes are as below:
Create a class called <code>Burrito</code>. This burrito should have:</p>
<ul>
<li><p>An attribute (<code>is_california</code>) is a boolean that indicates if the burrito is a California burrito (in other words, if it has fries in it!).</p>
</li>
<li><p>An instance-specific attribute, (contents) is a list of contents in the burrito.</p>
</li>
<li><p>A method, (<code>add_fries</code>). If there were not already fries in the contents list, this method should add fries to the list of contents and update <code>is_california</code> to be true.</p>
</li>
</ul>
<p>and my codes are below:</p>
<pre><code>class Burrito():
def is_california(self):
contents = []
if 'fries' in contents:
is_california = True
if 'fries' not in contents:
is_california = False
def __init__(self,contents = []):
self.contents = contents
def add_fries(self):
if 'fries' not in contents:
contents.append('fries')
</code></pre>
<p>It does not work when I try to test the <code>add_fries()</code>, is there any improvements to be made? Thanks!</p>
| [
{
"answer_id": 74134320,
"author": "Max R",
"author_id": 19662289,
"author_profile": "https://Stackoverflow.com/users/19662289",
"pm_score": 2,
"selected": false,
"text": "condition"
},
{
"answer_id": 74135415,
"author": "Ike",
"author_id": 16578424,
"author_profile":... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20251827/"
] |
74,133,877 | <p>I have a component called DateComponent, and it contains 3 inputs (year/month/day). I also have a component which contains a formGroup and has a formControlname date which is like yyyy-mm-dd.</p>
<p>If I want to go through the FormGroup path, how can I get the data from DateComponent nicely as yyyy-mm-dd to the form in parent component?</p>
<p>I tried to use ControlValueAccessor, but the problem is I have 3 ngmodel (day, month, year) in DateComponent while in parent there is one which is Date.</p>
<p>I really prefer not to break down my formControl from date to 3 fields. Any thoughts or solution.</p>
| [
{
"answer_id": 74134645,
"author": "Shailesh B",
"author_id": 14983457,
"author_profile": "https://Stackoverflow.com/users/14983457",
"pm_score": 0,
"selected": false,
"text": "let date = 10\nlet month = 1\nlet year = 2019\n\nlet finalDate = new Date()\nfinalDate = new Date(finalDate.set... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5187258/"
] |
74,133,924 | <p>link example :</p>
<pre><code><img src="https://thumbs.com/thumbs/test.mp4/test1.mp4-3.jpg" alt="This is the description i want to get too" >
</code></pre>
<p>and the method i'm using to parse the links from html downloaded source file :</p>
<pre><code>public List<string> GetLinks(string message)
{
List<string> list = new List<string>();
string txt = message;
foreach (Match item in Regex.Matches(txt, @"(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?"))
{
if (item.Value.Contains("thumbs"))
{
int index1 = item.Value.IndexOf("mp4");
string news = ReplaceLastOccurrence(item.Value, "thumbs", "videos");
if (index1 != -1)
{
string result = news.Substring(0, index1 + 3);
if (!list.Contains(result))
{
list.Add(result);
}
}
}
}
return list;
}
</code></pre>
<p>but this wil give only the link i want to get also the link description in this example:</p>
<p>This is a test</p>
<p>Then using it :</p>
<pre><code>string[] files = Directory.GetFiles(@"D:\Videos\");
foreach (string file in files)
{
foreach(string text in GetLinks(File.ReadAllText(file)))
{
if (!videosLinks.Contains(text))
{
videosLinks.Add(text);
}
}
}
</code></pre>
<p>and when downloading the links :</p>
<pre><code>private async void btnStartDownload_Click(object sender, EventArgs e)
{
if (videosLinks.Count > 0)
{
for (int i = 0; i < videosLinks.Count; i++)
{
string fileName = System.IO.Path.GetFileName(videosLinks[i]);
await DownloadFile(videosLinks[i], @"D:\Videos\videos\" + fileName);
}
}
}
</code></pre>
<p>but the fileName i want to be the description of each link.</p>
| [
{
"answer_id": 74134159,
"author": "Anirudha Gupta",
"author_id": 713789,
"author_profile": "https://Stackoverflow.com/users/713789",
"pm_score": -1,
"selected": false,
"text": " string test = \"<img src=\\\"https://thumbs.com/thumbs/test.mp4/test1.mp4-3.jpg\\\" alt=\\\"This is th... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20200502/"
] |
74,133,955 | <p>I'm trying to create a new machine image from a .tar.gz file in one of my storage buckets. Doing this through the console is easy enough, but I need to do this programmatically with Python for a project I'm working on.</p>
<p>I've found what I think is the correct sections on how to create the machine image, but without examples I'm a little lost. I am fairly new to Python to still learning. I looks like I can use the Class "MachineImagesClient" and the "insert" method to make this happen.</p>
<p>If anyone can give me a bit of an example of where to start it would be much appreciated.</p>
<p><a href="https://cloud.google.com/python/docs/reference/compute/latest/google.cloud.compute_v1.services.machine_images.MachineImagesClient#google_cloud_compute_v1_services_machine_images_MachineImagesClient_insert" rel="nofollow noreferrer">https://cloud.google.com/python/docs/reference/compute/latest/google.cloud.compute_v1.services.machine_images.MachineImagesClient#google_cloud_compute_v1_services_machine_images_MachineImagesClient_insert</a>
<a href="https://cloud.google.com/python/docs/reference/compute/latest/google.cloud.compute_v1.types.MachineImage" rel="nofollow noreferrer">2</a></p>
| [
{
"answer_id": 74147798,
"author": "cypherlock1010",
"author_id": 17678316,
"author_profile": "https://Stackoverflow.com/users/17678316",
"pm_score": 1,
"selected": false,
"text": "from pprint import pprint\nimport os\nfrom googleapiclient import discovery\nfrom oauth2client.client impor... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17678316/"
] |
74,133,956 | <p>I am using Java 8 streams and would like to remove an item in my list if multiple items with the same room number are present and use the one with the most current date.</p>
<p>I have this list:</p>
<pre><code>final List<TestClass> testClasses = Arrays.asList(
new TestClass(100L, LocalDate.of(2020, 1, 10)),
new TestClass(100L, LocalDate.of(2019, 1, 10)),
new TestClass(101L, LocalDate.of(2020, 7, 20)),
new TestClass(102L, LocalDate.of(2020, 1, 9)),
new TestClass(103L, LocalDate.of(2020, 1, 11)),
new TestClass(104L, LocalDate.of(2020, 2, 13))
);
</code></pre>
<p>I would like to filter this list down in a way such that if the roomNumber (first param of TestClass constructor) occurs multiple times in the list then that entry should be removed and the one with the most current date will be saved.</p>
<p>Sample output from above list after filtering:</p>
<pre><code>[
TestClass(100L, LocalDate.of(2020, 1, 10)),
TestClass(101L, LocalDate.of(2020, 7, 20)),
TestClass(102L, LocalDate.of(2020, 1, 9)),
TestClass(103L, LocalDate.of(2020, 1, 11)),
TestClass(104L, LocalDate.of(2020, 2, 13))
]
</code></pre>
<p>As you can see the second TestClass object with a roomNumber of 100 has been removed and we are left with the first TestClass object that also has a roomNumber of 100 but we keep it since the date is higher or more recent than the other entry.</p>
<p>I have read through the Java streams documentation and am aware of filtering. Is there a way to achieve this functionality using Java streams? I feel like there is but there may be a way to use this api that I am unaware of.</p>
<p>TIA and please let me know if more information is required :)</p>
<p>EDIT:
This is the attempt that I made. I learned about the groupingBy function and was able to get the TestClasses into a list grouped by their room number. I am not sure where to go from there.</p>
<pre><code> Map<Long, List<TestClass>> c = testClasses.stream()
.collect(Collectors.groupingBy(TestClass::getRoomNumber));
</code></pre>
| [
{
"answer_id": 74147798,
"author": "cypherlock1010",
"author_id": 17678316,
"author_profile": "https://Stackoverflow.com/users/17678316",
"pm_score": 1,
"selected": false,
"text": "from pprint import pprint\nimport os\nfrom googleapiclient import discovery\nfrom oauth2client.client impor... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11521276/"
] |
74,133,959 | <p>Hi so I wanted to put array elements to become a string. The objective is I wanted to put the string in print function.
For instance:</p>
<p>Given an array of [1, 2, 0, 1]
Is there any way to make the elements to become one string (i.e. to be 1201)?
Lets say the string variable is '''array_elements'''
I want to have the output of:</p>
<blockquote>
<p>the elements are: 1201.</p>
</blockquote>
<p>So of course what I should do to the print function is:</p>
<pre><code>print("the elements are: " + str(array_elements), ".")
</code></pre>
<p>The problem is, I'm a python beginner and i don't know how to solve the problem without using string function (since this is what google told me to do, but I'm now allowed to use that." What I could think of is by using looping but I still can't manage to make it as one string variable</p>
| [
{
"answer_id": 74133975,
"author": "Nikolay Zakirov",
"author_id": 9023490,
"author_profile": "https://Stackoverflow.com/users/9023490",
"pm_score": 2,
"selected": false,
"text": "\"\".join(str(x) for x in [1, 2, 0, 1])\n"
},
{
"answer_id": 74134002,
"author": "Jiří Baum",
... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20254119/"
] |
74,133,966 | <p>I have a C library <code>A</code> with no test and I am trying to add tests for one of its functions <code>funC</code>:</p>
<p>in <code>funC</code> is not declared in <code>A/lib.h</code> and only declared in <code>A/lib.c</code>:</p>
<pre><code>static int funC();
static int funC(){
// do something
}
</code></pre>
<p>and I created a test file in <code>test/A.t.cpp</code> and want to access funC to test it. funC is only declared in .c file so i decide to use <code>extern C</code>. in <code>test/A.t.cpp</code> I have:</p>
<pre><code>extern "C"{
static int funC();
}
TEST(A,test){
funC();
.....
}
</code></pre>
<p>I thought with the declaration in the .t.cpp file, it would be able to link against the actual implementation in the .c file so I should be able to call the function and test it, but I got:</p>
<p><code> Error: The function funC() has not had a body defined</code></p>
<p>how should I fix it? Then I also tried to add the implementation within the test file and it worked but that's not what I want. I want the .t.cpp file to link against the actual implementation in .c file. Thanks!</p>
| [
{
"answer_id": 74133975,
"author": "Nikolay Zakirov",
"author_id": 9023490,
"author_profile": "https://Stackoverflow.com/users/9023490",
"pm_score": 2,
"selected": false,
"text": "\"\".join(str(x) for x in [1, 2, 0, 1])\n"
},
{
"answer_id": 74134002,
"author": "Jiří Baum",
... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8348955/"
] |
74,133,986 | <p>I was trying write a code that gives index of a minimum value of list one after other
For example:</p>
<pre><code>if list=[2,4,1,2,5]
0 1 2 3 4
</code></pre>
<p>output:</p>
<blockquote>
<p>[2,0,3,1,4]--> where each element in this corresponds to index of list
variable</p>
</blockquote>
<pre><code>import math
list=[2,4,1,2,5]
a=[]
i=0
while(i <= (len(list)-1)):
if(list[i]==min(list)):
a.append(i)
list[i]=math.inf
i=-1
i+=1
print(a)
</code></pre>
| [
{
"answer_id": 74134122,
"author": "Ian Moote",
"author_id": 7655269,
"author_profile": "https://Stackoverflow.com/users/7655269",
"pm_score": 1,
"selected": false,
"text": "list"
},
{
"answer_id": 74134187,
"author": "tasrif",
"author_id": 16991126,
"author_profile":... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18391287/"
] |
74,133,997 | <p>I have a Linked list homework in C programming and we are tasked to write a program that accepts two integer input, and create two nodes with the values. Make the node with greater value the first node. The next node of the first node is the other input.</p>
<p>Although I got the program right, for some reason, there's an extra "->" in my output I have been trying to analyze the problem and solve it, but I'm still struggling with it. Can I ask for assistance?</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int value;
struct node* next;
} node;
node* create_node(int value){
node* new_node = (node*)malloc(sizeof(node));
new_node -> value = value;
new_node -> next = NULL;
return new_node;
}
void printList(node* head){
while(head){
printf("%d -> ", head -> value);
head = head -> next;
}
}
int main(){
int num1, num2;
struct node node1;
node* head = NULL;
node* temp = NULL;
printf("Enter number 1: ");
scanf("%d", &num1);
printf("Enter number 2: ");
scanf("%d", &num2);
if(num1 > num2){
head = create_node(num1);
temp = create_node(num2);
head -> next = temp;
} else {
head = create_node(num2);
temp = create_node(num1);
head -> next = temp;
}
printList(head);
return 0;
}
</code></pre>
<p>the Output should be</p>
<pre><code>Enter number 1: 1
Enter number 2: 2
2 -> 1
</code></pre>
<p>but the Output I got is</p>
<pre><code>Enter number 1: 1
Enter number 2: 2
2 -> 1 ->
</code></pre>
| [
{
"answer_id": 74134066,
"author": "John Bollinger",
"author_id": 2402272,
"author_profile": "https://Stackoverflow.com/users/2402272",
"pm_score": 2,
"selected": false,
"text": " printf(\"%d -> \", head -> value);\n"
},
{
"answer_id": 74134327,
"author": "Fe2O3",
... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74133997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20001242/"
] |
74,134,032 | <p>Say I have a group (or set) of words: {foo, bar, baz}, and I want to match and extract the group. The words can be in any order, but they need to be next to each other. For example,</p>
<pre><code>hello foo bar baz wow yeah => foo bar baz
hello bar foo baz wow yeah => bar foo baz
wow yeah hello baz bar foo hello => baz bar foo
baz yeah bar foo hello => no match
</code></pre>
<p>What'd be a good regex, preferably Python, to accomplish this?</p>
| [
{
"answer_id": 74134123,
"author": "41686d6564 stands w. Palestine",
"author_id": 8967612,
"author_profile": "https://Stackoverflow.com/users/8967612",
"pm_score": 3,
"selected": true,
"text": "(?:\\b(foo|bar|baz)(?!.*\\b\\1\\b) ){3}\n"
},
{
"answer_id": 74134299,
"author": "... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1561610/"
] |
74,134,045 | <p>We have a project that uses launchSettings.json to setup environment variables. When we open the project in the Visual Studio for Mac it ignores the launchSettings.json. When we add env. variables via the IDE (Properties > Configurations) it places them inside the .csproj file. (Inside the .csproj.user file if 'User-specific configuration' is selected.)</p>
<p>We need the Visual Studio to use the launchSetttings.json however there doesn't seem to be a way to make it. Even in the official documentation (<a href="https://learn.microsoft.com/en-us/visualstudio/mac/launch-settings?view=vsmac-2022" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/visualstudio/mac/launch-settings?view=vsmac-2022</a>) it is mentioned that it would use launchSettings.json however that doesn't seem to be the case.</p>
<p>Does anybody has a solution for this issue?</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 74138381,
"author": "Yousi",
"author_id": 1043964,
"author_profile": "https://Stackoverflow.com/users/1043964",
"pm_score": 0,
"selected": false,
"text": "launchSettings.json"
},
{
"answer_id": 74319481,
"author": "darasd",
"author_id": 42119,
"author_p... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2133839/"
] |
74,134,047 | <p>I need some help recursively searching a python dict that contains nested lists.</p>
<p>I have a structure like the below example. The value of key "c" is a list of one or more dicts. The structure can be nested multiple times (as you can see in the second item), but the pattern is the same. In all likelihood, the nested depth will probably not be more than 5 deep.</p>
<p>My objective (in this example) is to find all occurrences of ref = 'hij789', <strong>no matter where they occur</strong> (however deep they are nested) and then add the missing 'b' = 'something' to each occurrence.</p>
<pre><code>{
'ref': 'abc123',
'a': 'something',
'b': 'something',
'c': [{
'ref': 'def456',
'a': 'something',
'b': 'something',
'c': [{
'ref': 'hij789',
'a': 'something'
}]
},{
'ref': 'klm012',
'a': 'something',
'b': 'something',
'c': [{
'ref': 'nop345',
'a': 'something',
'b': 'something',
'c': [{
'ref': 'hij789',
'a': 'something'
}]
}]
},{
'ref': 'qrs678',
'a': 'something',
'b': 'something',
'c': [{
'ref': 'tuv901',
'a': 'something'
}]
}]
}
</code></pre>
<p>I first tried something like this, but it of course does not search beyond the first nested dict:</p>
<pre><code>l = next((n for n in mydict['c'] if n['ref'] == 'myref'), None)
l['b'] = 'somevalue'
</code></pre>
<p>I also tried a variation of this, but could not make it work:
<a href="https://stackoverflow.com/questions/63646525/recursive-list-inside-dict-python">Recursive list inside dict? - python</a></p>
<p>Is there a relatively straightforward way to achieve this?
Thanks.</p>
| [
{
"answer_id": 74138381,
"author": "Yousi",
"author_id": 1043964,
"author_profile": "https://Stackoverflow.com/users/1043964",
"pm_score": 0,
"selected": false,
"text": "launchSettings.json"
},
{
"answer_id": 74319481,
"author": "darasd",
"author_id": 42119,
"author_p... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287604/"
] |
74,134,069 | <p>Good day. I am a flutter beginner and now do some simple pratice.</p>
<p>I want: Press a button and call login api, if api response is success then go to main page.</p>
<p>but I don't know how to get callback result.</p>
<p>viewModel</p>
<pre><code> Future<String> login(String account, String password) async {
try {
futureLogin = logon(account, password);
await futureLogin.then((value) {
print("key=${value.data.key}");//success print correct key
return value.data.key;
}).catchError((error) {
print("error=$error");
});
} catch (error) {}
return "";
}
</code></pre>
<p>Button click event</p>
<pre><code>onPressed: () async {
var result = await viewModel.login(account, password);
print("result=${result}");//print ""
}
</code></pre>
<p>I think that I can simply use <code>await</code> keyword to get my api result but not works.</p>
<p>How to solve it.</p>
<p>Any help will be appreciate.</p>
| [
{
"answer_id": 74134165,
"author": "powerman23rus",
"author_id": 6163011,
"author_profile": "https://Stackoverflow.com/users/6163011",
"pm_score": 0,
"selected": false,
"text": " Future<String> login(String account, String password) async {\n try {\n final result = awai... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9881903/"
] |
74,134,118 | <p>Example:
I the <code>df['column']</code> has a bunch of values similar to: <strong>F/4500/O</strong> or <strong>G/2/P</strong></p>
<p>The length of the digits range from 1 to 4 similar to the examples given above.</p>
<p>How can I transform that column to only keep <strong>1449</strong> as an integer?</p>
<p>I tried the split method but I can't get it right.
Thank you!</p>
<p><a href="https://i.stack.imgur.com/Hx9Fs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hx9Fs.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74134141,
"author": "Igor Rivin",
"author_id": 2977256,
"author_profile": "https://Stackoverflow.com/users/2977256",
"pm_score": 0,
"selected": false,
"text": "df['column'].map(lambda x: int(x.split('/')[1]))\n"
},
{
"answer_id": 74134218,
"author": "mozway",
... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20194660/"
] |
74,134,145 | <p>The question: Add a gender field. Ensure the field will only
accept ‘M’ or ‘F’ and the default value should be
‘F’</p>
<p>PostgresSQL code:</p>
<pre><code>alter table Patient
add Gender varchar(1) default 'F' ,Check (Gender = 'M' or Gender = 'F');
</code></pre>
<blockquote>
<p>ERROR: syntax error at or near "Check"<BR> LINE 2: add Gender
varchar(1) default 'F' ,Check (Gender = 'M' or G...</p>
</blockquote>
<p>How do i fix it?</p>
| [
{
"answer_id": 74134212,
"author": "Rahul Beniwal",
"author_id": 7764935,
"author_profile": "https://Stackoverflow.com/users/7764935",
"pm_score": 1,
"selected": false,
"text": "CREATE TYPE gender AS ENUM ('F', 'M');\n\nCREATE TABLE t (\n g gender default 'F' -- <==== default value\n)... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287917/"
] |
74,134,174 | <p>I have a dataframe 'df' where I would like to compare the list of column names to the values found under the dataframe titled 'set_cols' I have code that i previously used to compare a dictionary key to the df column name but i cant figure out how to make it work to compare a dataframe column heading values to another dataframe values under the heading</p>
<pre><code>import pandas as pd
filename='template'
df= pd.DataFrame(columns=['firstName', 'lastName', 'state', 'Communication_Language__c',
'country', 'company', 'email', 'industry', 'System_Type__c',
'AccountType', 'customerSegment', 'Existing_Customer__c',
'GDPR_Email_Permission__c','persons name'])
data= ['firstName', 'lastName', 'state', 'Communication_Language__c',
'country', 'company', 'email', 'industry', 'System_Type__c',
'AccountType', 'customerSegment', 'Existing_Customer__c',
'GDPR_Email_Permission__c']
set_cols=pd.DataFrame(data, columns=['Numbers'])
errors= {}
errors[filename]={}
df_cols = df[list(df.columns)]
mask = df_cols.apply(lambda d: d.isin(set_cols[d.name]))
df_cols.mask(mask|df_cols.eq(' ')).stack()
for err_i, (r, v) in enumerate(df_cols.mask(mask|df_cols.eq(' ')).stack().iteritems()):
errors[filename][err_i] = {"column": r[1],
"message": r + " is invalid column heading'}
</code></pre>
<p>in the errors dictionary I would expect an output something along the line of this:</p>
<pre><code>{'column': 'person name', 'message': 'person name is an invalid column heading'}
</code></pre>
<p>How do i compare the heading column values of one data frame to a data frame with the values under the column?</p>
| [
{
"answer_id": 74134212,
"author": "Rahul Beniwal",
"author_id": 7764935,
"author_profile": "https://Stackoverflow.com/users/7764935",
"pm_score": 1,
"selected": false,
"text": "CREATE TYPE gender AS ENUM ('F', 'M');\n\nCREATE TABLE t (\n g gender default 'F' -- <==== default value\n)... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,134,195 | <p>I am trying to remove the checkered background (which represents transparent background in Adobe Illustrator and Photoshop) with transparent color (alpha channel) in some PNGs with Python script.</p>
<p>First, I use <em>template matching</em>:</p>
<pre><code>import cv2
import numpy as np
from matplotlib import pyplot as plt
img_rgb = cv2.imread('testimages/fake1.png', cv2.IMREAD_UNCHANGED)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('pattern.png', 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
if len(img_rgb[0][0]) == 3:
# add alpha channel
rgba = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2RGBA)
rgba[:, :, 3] = 255 # default not transparent
img_rgb = rgba
# replace the area with a transparent rectangle
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (255, 255, 255, 0), -1)
cv2.imwrite('result.png', img_rgb)
</code></pre>
<p><strong>Source Image: fake1.png</strong></p>
<p><a href="https://i.stack.imgur.com/grBtL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/grBtL.png" alt="Source Image" /></a></p>
<p><strong>Pattern Template: pattern.png</strong></p>
<p><a href="https://i.stack.imgur.com/kTuoB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kTuoB.png" alt="Pattern Template" /></a></p>
<p><strong>Output: result.png</strong> (the gray area is actually transparent; enlarge a bit for viewing easier)</p>
<p><a href="https://i.stack.imgur.com/Rflnt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rflnt.png" alt="Output Image" /></a></p>
<p>I know this approach has problems, as the in some cases, the template cannot be identified fully, as part of the pattern is hidden by the graphics in the PNG image.</p>
<p><strong>My question is:</strong> How can I match such a pattern perfectly using OpenCV? via FFT Filtering?</p>
<p>References:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/15528669/how-particular-pixel-to-transparent-in-opencv-python">How particular pixel to transparent in opencv python?</a></li>
<li><a href="https://stackoverflow.com/questions/54544203/detecting-a-pattern-in-an-image-and-retrieving-its-position">Detecting a pattern in an image and retrieving its position</a></li>
<li><a href="https://python.plainenglish.io/how-to-remove-image-background-using-python-6f7ffa8eab15" rel="nofollow noreferrer">https://python.plainenglish.io/how-to-remove-image-background-using-python-6f7ffa8eab15</a></li>
<li><a href="https://answers.opencv.org/question/232506/make-the-background-of-the-image-transparent-using-a-mask/" rel="nofollow noreferrer">https://answers.opencv.org/question/232506/make-the-background-of-the-image-transparent-using-a-mask/</a></li>
<li><a href="https://dsp.stackexchange.com/questions/36679/which-image-filter-can-be-applied-to-remove-gridded-pattern-from-corrupt-jpegs">https://dsp.stackexchange.com/questions/36679/which-image-filter-can-be-applied-to-remove-gridded-pattern-from-corrupt-jpegs</a></li>
</ul>
| [
{
"answer_id": 74141647,
"author": "Max Prakken",
"author_id": 5848555,
"author_profile": "https://Stackoverflow.com/users/5848555",
"pm_score": 1,
"selected": false,
"text": "inRange()"
},
{
"answer_id": 74144913,
"author": "fmw42",
"author_id": 7355741,
"author_prof... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/188331/"
] |
74,134,200 | <p>I'm working with a React Native project, setting up Xcode Cloud builds.</p>
<p>I keep getting this error:</p>
<pre><code>unable to open configuration settings file
Pods-XXX.debug.xcconfig:1
</code></pre>
<p><a href="https://i.stack.imgur.com/bsIP2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bsIP2.png" alt="Xcode Cloud Screenshot" /></a></p>
<p>The files in my workspace look like the following:</p>
<pre><code>|-- XXX
|-- Pods
|. -- Podfile
|. -- Targets Support Files
|. -- Pods-XXX
|. -- Pods-XXX.debug
</code></pre>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6885605/"
] |
74,134,222 | <p>This function works with a little bit of data, but not with hundreds of rows and I wonder if I'm missing some <code>Spreadsheet.flush()</code> or something of this nature.</p>
<pre><code>const values = [["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"],["2022-12-31T06:00:00.000Z"]];
function DeleteRows(sheetName, year) {
sheetName = 'Saved Budgets'//For tests
year = '2022' //For tests
var SS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); //Get Open Lines Sheet
var lastRow = SS.getLastRow();
var range = SS.getRange(2, 1, lastRow - 1, 1); //get range
range.sort({ column: 1, ascending: false }) // filter data descending
var firstRowToDelete = 0;
var numOfRows = 1; // starting row to be increment and become the number of rows
var values = range.getValues();//Got it for comparison
for (let a = 0; a < values.length; a++) {
let dt = new Date(values[a]).getFullYear();
if (dt == year) {
firstRowToDelete = parseInt(a);
numOfRows++
}
}
if (numOfRows != 1) {
numOfRows = numOfRows - 1 // minus 1 to get the last row
SS.deleteRows(firstRowToDelete, numOfRows);
}
range.sort({ column: 1, ascending: true }) // filter data again ascending
}
</code></pre>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11832197/"
] |
74,134,252 | <p>So I'm trying to get all the values and id of every input from an array, but I have an issue, the user can duplicate the input and each input have a randomly generated ID so I can't select the data with the ID and every input use <code>name="cate[]"</code> so every input have the same name, so I can use something like this:</p>
<pre><code>function regTour() {
var input = document.getElementsByName('cat[]');
var k = "The respective values are :";
for (var i = 0; i < input.length; i++) {
var a = input[i];
k = k + "array[" + i + "].value= "
+ a.value + " ";
}
console.log('Console: ' + k);
}
</code></pre>
<p>but how I can get the ID from every input from the array paired with the input value?</p>
<p>Edit: -------------------</p>
<p>the input looks like this:</p>
<pre><code> <input type="text" id="1666239497429" name="cat[]" class="form-control">
<input type="text" id="12983172462" name="cat[]" class="form-control">
<input type="text" id="812361647812" name="cat[]" class="form-control">
</code></pre>
<p>this input it's created dynamically by the user so the id changes, this id later it's stored with other sub fields that should be related with that id, that's why it's some kind important for me be able to store all the id's</p>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1937246/"
] |
74,134,253 | <p><strong>how to add ainmation in GoRouter flutter</strong>
and also if the animation class can sit in a stand alone file so that i can have so many animation classes to call on different pages.
<a href="https://pub.dev/packages/go_router/example" rel="nofollow noreferrer">code source</a></p>
<pre><code>void main() => runApp(App());
class App extends StatelessWidget {
App({Key? key}) : super(key: key);
static const String title = 'GoRouter Example: Declarative Routes';
@override
Widget build(BuildContext context) => MaterialApp.router(
routerConfig: _router,
title: title,
);
final GoRouter _router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const Page1Screen(),
routes: <GoRoute>[
GoRoute(
path: 'page2',
builder: (BuildContext context, GoRouterState state) =>
const Page2Screen(),
),
],
),
],
);
}
</code></pre>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11154531/"
] |
74,134,273 | <p>input a integer X and tell if it is a prime.
If it is a prime, output 'Y'
If not, output 'N' and the smallest prime factor.</p>
<p>Here is the program I have tried to write.</p>
<p>X = int(input('enter a integer X:'))
for i in range(2, X):
if X % i == 0:
print('Y')
else:
print('N')</p>
<p>But I would like to print just one time 'Y' or 'N'. And I also do not know how to make the smallest prime factor show on my program result.</p>
<p>Thank you all for helping me</p>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20287984/"
] |
74,134,300 | <p>I am trying to parse 1 line that is constructed in this format:</p>
<pre><code>Files("textfile1.txt", 7268474425, "textfile2.txt", 661204928, "textfile3.txt", 121034)
</code></pre>
<p>I have this working perfectly in C# using named capture groups, but this is PHP and strictly on topic. So I have no idea how to separate each field and build a associative array I can iterate.</p>
<p>I can retrieve the first item in double-quotes "textfile1.txt" using</p>
<pre><code>$string = 'Files("textfile1.txt", 7268474425, "textfile2.txt", 661204928, "textfile3.txt", 121034)';
preg_match("/(?:(?:\"(?:\\\\\"|[^\"])+\")|(?:'(?:\\\'|[^'])+'))/is", $string, $match);
print_r($match);
</code></pre>
<pre><code>Array
(
[0] => 'textfile1.txt'
)
</code></pre>
<p>I cant figure it out. I have tried different expressions to consider both the string/long fields but no luck.</p>
<p>Is there something I am missing?</p>
<p>End result is having each filename/size added to a array to access later.</p>
<p>Any help is appreciated</p>
<p><a href="https://regex101.com/r/naSdng/1" rel="nofollow noreferrer">https://regex101.com/r/naSdng/1</a></p>
<p>My C# implementation looks like this:</p>
<pre><code>MatchCollection result = Regex.Matches(file, @"(?:\G(?!\A)\s*,\s*|\w+\()(?:""(?<filename>.*?)""|'(?<filename>.*?)')\s*,\s*(?<filesize>\d+)");
matchCol = result;
foreach (Match match in result)
{
ListViewItem ItemArray = new(new string[] {
match.Groups["filename"].Value.Trim(), BytesToReadableString(Convert.ToInt64(match.Groups["filesize"].Value)), "Ready"
});
fileList.Items.Add(ItemArray);
}
</code></pre>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19708490/"
] |
74,134,310 | <p>I tried to use Laravel-passport so I installed this package in my project, but when i wanted to make route
i wrote this code in the AuthServiceProvider</p>
<pre><code> public function boot()
{
$this->registerPolicies();
Passport::routes();
}
</code></pre>
<p>When i run php artisan route:list in the cmd i face with this error</p>
<ul>
<li>Call to undefined method Laravel\Passport\Passport::routes()</li>
</ul>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18457863/"
] |
74,134,343 | <p>I am a newbie at react-native and I am facing some issues in the react-native app, after installing 'react-navigation', everything is mentioned in the images. Hope you can help me. Have a good day.</p>
<p><a href="https://i.stack.imgur.com/rbyQb.png" rel="nofollow noreferrer">App.js file</a></p>
<p><a href="https://i.stack.imgur.com/PXn4y.png" rel="nofollow noreferrer">MainActivity.java</a></p>
<p><a href="https://i.stack.imgur.com/wOutk.png" rel="nofollow noreferrer">Package.json</a></p>
<p><a href="https://i.stack.imgur.com/gg2Ju.png" rel="nofollow noreferrer">Terminal-issue</a></p>
<p><a href="https://i.stack.imgur.com/IpHRy.png" rel="nofollow noreferrer">Node-cli</a></p>
| [
{
"answer_id": 74208257,
"author": "BEK ROZ",
"author_id": 15234056,
"author_profile": "https://Stackoverflow.com/users/15234056",
"pm_score": 3,
"selected": false,
"text": "ci_scripts"
},
{
"answer_id": 74386883,
"author": "PricipledPrimate",
"author_id": 20467029,
"... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18065138/"
] |
74,134,350 | <p>The following code fails to compile when <code>n</code> is <code>size_t</code> but works fine for <code>int</code> and <code>unsigned</code>.</p>
<pre class="lang-c++ prettyprint-override"><code>#include <vector>
#include <ranges>
int main() {
size_t n = 1;
auto view = std::ranges::iota_view{n, n};
std::vector test(view.begin(), view.end()); //std::vector dislikes these itterators
}
</code></pre>
<p><a href="https://godbolt.org/z/a3eGeMWqh" rel="noreferrer">https://godbolt.org/z/a3eGeMWqh</a></p>
| [
{
"answer_id": 74134882,
"author": "user17732522",
"author_id": 17732522,
"author_profile": "https://Stackoverflow.com/users/17732522",
"pm_score": 4,
"selected": false,
"text": "difference_type"
},
{
"answer_id": 74134946,
"author": "康桓瑋",
"author_id": 11638718,
"aut... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/897778/"
] |
74,134,351 | <p>I am trying to translate a pyspark job, which is dynamically coalescing the columns from two datasets with additional filters/condition.</p>
<pre><code>conditions_ = [when(df1[c]!=df2[c], lit(c)).otherwise("") for c in df1.columns if c not in ['firstname','middlename','lastname']]
</code></pre>
<p>can I do this in scala?</p>
<p>What I have tried so far is:</p>
<pre><code>df1.join(df2, Seq("col1"), "outer").select(col("col1"), coalesce(df1.col("col2"), df2.col("col2")).as(col("col2"), coalesce(df1.col("col3")..........as(col("col30"))
</code></pre>
<p>is there a better way to add them with a loop instead of expanding this?</p>
| [
{
"answer_id": 74134882,
"author": "user17732522",
"author_id": 17732522,
"author_profile": "https://Stackoverflow.com/users/17732522",
"pm_score": 4,
"selected": false,
"text": "difference_type"
},
{
"answer_id": 74134946,
"author": "康桓瑋",
"author_id": 11638718,
"aut... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11535500/"
] |
74,134,353 | <p>I would like to take the result of an 8-bit vertical SIMD comparison between 256-bit vectors and pack the bits into the lowest byte of each 32-bit element for a <code>vpshufb</code> lookup on the lowest bytes. This isn't terribly difficult with AVX-512 (replace the <code>&</code> with a masked move if using 512-bit vectors):</p>
<pre><code>__m256i cmp_8_into_32(__m256i a, __m256i b) {
return _mm256_popcnt_epi32(_mm256_cmpeq_epi8(a, b)
& _mm256_set1_epi32(0xff0f0301 /* can be any order */));
}
</code></pre>
<p>That's three uops and, assuming perfect scheduling, a throughput of 1 according to uops.info—not bad. Alas, <code>vpopcntd</code> isn't in AVX2. What's the optimal way to do this operation there? The best I can think of is to mask the pairs of bits at indices 7,8 and 15,16, then perform two constant-amount <code>vpsrld</code> and a <code>vpor</code>. So that's 6 uops, throughput of 2.5 ish. Not bad, but I wonder if there's something better.</p>
| [
{
"answer_id": 74136297,
"author": "Ovinus Real",
"author_id": 13458117,
"author_profile": "https://Stackoverflow.com/users/13458117",
"pm_score": 2,
"selected": false,
"text": "__m256i cmp_8_into_32_1(__m256i a, __m256i b) {\n const __m256i weights = _mm256_set1_epi32(0x08040201);\n ... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13458117/"
] |
74,134,403 | <p>My function is set to find email brought from /login POST method, but I am failing to declare the variable properly, what is the variable to be inserted into the findOne form on app.get('/data')?</p>
<p>I have:</p>
<pre><code>app.post('/login', function (req, res) {
//console.log(req.body);
const uri = "mongodb+srv://<PRIVATE INFO>.eapnyil.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
const users = client.db("data").collection("users");
users.findOne({email:req.body.email},function(err,data){
if(data){
if(data.password==req.body.password){
//console.log("Logged In.");
console.log('Email in DB is: ' + data.email);
console.log('Email in form is: ' + req.body.email);
//res.send({"Success":"Success!"});
res.redirect('/data');
}else{
res.send({"Failed with":"Wrong password!"});
}
}else{
res.send({"Try again":"Email not registered!"});
}
});
});
app.get('/data', (req, res) => {
const users = client.db("data").collection("users");
users.findOne({unique_id:req.session.id})((err, result) => {
if (err) return console.log(err)
// renders index.ejs
res.render('pages/data.ejs', {users: result})
})
});
</code></pre>
<p>and on the login.ejs file the following:</p>
<pre><code> <p>Login</p>
</div>
<div class="form-group">
<form id="form" method="POST" action="/login">
<input type="text" name="email" placeholder="E-mail" required="" class="form-control"><br/>
<input type="password" name="password" placeholder="Password" required="" class="form-control"><br/>
<input type="submit" value="Login" class="btn btn-success">
</form>
</div>
</code></pre>
| [
{
"answer_id": 74136297,
"author": "Ovinus Real",
"author_id": 13458117,
"author_profile": "https://Stackoverflow.com/users/13458117",
"pm_score": 2,
"selected": false,
"text": "__m256i cmp_8_into_32_1(__m256i a, __m256i b) {\n const __m256i weights = _mm256_set1_epi32(0x08040201);\n ... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18006609/"
] |
74,134,412 | <p>I have a table containing data such as:</p>
<pre><code>BP_NUMBER,CONTRACT_TYPE
0000123, 1
0000123, 2
0000123, 3
0000123, 4
0000124, 4
0000124, 4
0000124, 4
0000125, 4
0000126, 1
0000126, 5
</code></pre>
<p>I want to select rows containing one or more occurrences of CONTRACT_TYPE = 4. In other words, I want to know who are the clients with one or more contracts of the same type and type 4.</p>
<p>I tried this query:</p>
<pre><code>SELECT * FROM (
SELECT BP_NUMBER, CONTRACT_TYPE, COUNT(*) OVER (PARTITION BY BP_NUMBER) CT FROM CONTRACTS
WHERE (1=1)
AND DATE = '18/10/2022'
AND CONTRACT_TYPE = 4)
WHERE CT= 1;
</code></pre>
<p>But it returns rows with only one occurrence of CONTRACT_TYPE = 4.</p>
<p>Also tried something like:</p>
<pre><code>SELECT BP_NUMBER FROM CONTRACTS
WHERE (1=1)
AND CONTRACT_TYPE = 4
AND CONTRACT_TYPE NOT IN (SELECT CONTRACT_TYPE FROM CONTRACTS WHERE CONTRACT_TYPE != 4 GROUP BY CONTRACT_TYPE);
</code></pre>
<p>Trying to avoid any other contract types than 4. I really don't understand why it doesn't work.</p>
<p>The expected result would be:</p>
<pre><code>0000124 --(4 occurrences of type 4)
0000125 --(1 occurrence of type 4)
</code></pre>
<p>Any help? Thanks</p>
| [
{
"answer_id": 74134634,
"author": "Craig",
"author_id": 15404009,
"author_profile": "https://Stackoverflow.com/users/15404009",
"pm_score": 1,
"selected": false,
"text": "SELECT \nBP_NUMBER\nFROM CONTRACTS c1\nWHERE CONTRACT_TYPE = 4\nAND NOT EXISTS \n(SELECT 1 FROM CONTRACTS c2 WHERE c... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8509051/"
] |
74,134,439 | <p>Let's say I declare an array of constant values for use as a lookup table:</p>
<pre><code>function Square(num : Integer) return Integer is
use Ada.Text_IO;
type LookupItemsRange is range 1..10;
type LookupTable is array(LookupItemsRange) of integer;
A : constant LookupTable := (2312,2,3,4,5,6,7,8,9, 10);
begin
Sqr := A(1);
Sqr := 2 * A(2);
return Sqr;
end Square;
</code></pre>
<p>The LookupTable shouldn't use any space. The compiler should be able to substitute array access with the actual inlined values. At the highest optimization setting, here's what Ada yields:</p>
<pre><code>_ada_square:
li a0,4 #,
ret
</code></pre>
<p>I am planning on substituting a large amount of redundant MCU code with a cleaner lookup table implementation. Since the microcontroller's resources are constrained, I would like to avoid needless allocation and indexing.</p>
<p>Under what circumstances will Ada allocate the array or am I completely safe?</p>
| [
{
"answer_id": 74159406,
"author": "Jere",
"author_id": 9604966,
"author_profile": "https://Stackoverflow.com/users/9604966",
"pm_score": 4,
"selected": true,
"text": "function Square return Integer is\n\n type Lookup_Items_Range is range 1..10;\n\n function A(Index : Lookup_Items_... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/148298/"
] |
74,134,444 | <p>I'm using react-router-dom v6</p>
<p>currently, it works well (successfully rendering reviewTab) below code</p>
<pre class="lang-js prettyprint-override"><code> <NavLink to='reviews' >reviewTab </NavLink>
~~
<Routes>
<Route path="reviews" element={<ReviewTab />}></Route>
</Routes>
</code></pre>
<p>and I want to add pagination this ReviewTab. so I just add queryParameter <code>reviews?page=1</code> like below code</p>
<pre class="lang-js prettyprint-override"><code> <NavLink to='reviews?page=1' >reviewTab </NavLink>
~~
<Routes>
<Route path="reviews?page=1" element={<ReviewTab />}></Route>
</Routes>
</code></pre>
<p>and it cannot render ReviewTab. what is the reason about this error?</p>
| [
{
"answer_id": 74159406,
"author": "Jere",
"author_id": 9604966,
"author_profile": "https://Stackoverflow.com/users/9604966",
"pm_score": 4,
"selected": true,
"text": "function Square return Integer is\n\n type Lookup_Items_Range is range 1..10;\n\n function A(Index : Lookup_Items_... | 2022/10/20 | [
"https://Stackoverflow.com/questions/74134444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18659819/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.