qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
74,514,091
|
<pre><code>au FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyrightconfig.json']
</code></pre>
<p>I guess not many people using this config with neovim.</p>
|
[
{
"answer_id": 74519515,
"author": "Evans Benedict",
"author_id": 20560614,
"author_profile": "https://Stackoverflow.com/users/20560614",
"pm_score": 0,
"selected": false,
"text": "\"cookies-next\""
},
{
"answer_id": 74521768,
"author": "Yilmaz",
"author_id": 10262805,
"author_profile": "https://Stackoverflow.com/users/10262805",
"pm_score": 3,
"selected": true,
"text": "import { cookies } from \"next/headers\";\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16786537/"
] |
74,514,097
|
<p>how to stop fetching again image if already fetch ? I am using below plugin to check whether element come in view port or not. but issue is when I scroll down it fetch image which is correct behaviour but when I move up it hide the image again . If I move down again it again fetch the image ?</p>
<p>how to prevent fetching again and again image . If already come in DOM don't remove .</p>
<p><a href="https://www.npmjs.com/package/react-intersection-observer" rel="nofollow noreferrer">https://www.npmjs.com/package/react-intersection-observer</a></p>
<pre><code>import * as React from "react";
// @ts-ignore Wrong type
import { createRoot } from "react-dom/client";
import { useInView } from "react-intersection-observer";
import ScrollWrapper from "./elements/ScrollWrapper";
import "./styles.css";
function App() {
const { ref, inView } = useInView({
threshold: 0
});
return (
<>
<div style={{ height: "200vh" }}>eeeeee</div>
<div ref={ref} className="inview-block">
<h2>
<img
src={
inView
? "https://inviewimaging.com/wp-content/uploads/2015/04/Inview-Graphic.png"
: null
}
alt=""
/>
</h2>
</div>
</>
);
}
const root = createRoot(document.getElementById("root"));
root.render(<App />);
</code></pre>
<p>here is my code ... any suggestion ?</p>
<p><a href="https://codesandbox.io/s/useinview-forked-74y015?file=/src/index.tsx:0-786" rel="nofollow noreferrer">https://codesandbox.io/s/useinview-forked-74y015?file=/src/index.tsx:0-786</a></p>
|
[
{
"answer_id": 74514595,
"author": "Ali Sattarzadeh",
"author_id": 11434567,
"author_profile": "https://Stackoverflow.com/users/11434567",
"pm_score": 3,
"selected": true,
"text": " const { ref, inView } = useInView({\n threshold: 0,\n triggerOnce:true,\n });\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19883277/"
] |
74,514,123
|
<p>In the following code, I expect the result has 2 elements with same values("Item1","Item1") but the <code>result</code> has 1 element("Item1"):</p>
<pre><code>var list = new List<string>(){"Item1","Item1"};
var emptyList = new List<string>();
// I expect the result of follwing line be {"Item1","Item1"} but is {"Item1"}
var result = list.Except(emptyList);
</code></pre>
<p>Seems <code>Except()</code> method return unique values of the result set, How can I get desired value?</p>
|
[
{
"answer_id": 74514161,
"author": "Loocid",
"author_id": 2987253,
"author_profile": "https://Stackoverflow.com/users/2987253",
"pm_score": 1,
"selected": false,
"text": "var result = list.Where(s => !emptyList.Contains(s));"
},
{
"answer_id": 74514222,
"author": "vivek nuna",
"author_id": 6527049,
"author_profile": "https://Stackoverflow.com/users/6527049",
"pm_score": 3,
"selected": true,
"text": "list.Where(x => !emptyList.Contains(x))"
},
{
"answer_id": 74514340,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 0,
"selected": false,
"text": "Add"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1594487/"
] |
74,514,124
|
<p>I am a beginner with React, JS, and I wrote a simple, ten-line program that tracks clicks in a web document and displays their positions in a text element.</p>
<p>It seems simple, and it works as intended, but only for seven clicks, after which the program locks up and will not execute any more, and won't display the positions of new clicks, and the page will not even update.</p>
<p>This exact thing happens whether I run it from my local Chrome and Safari or if I run it inside an online sandbox.</p>
<p>What could be causing this issue? How should I diagnose this kind of an issue?</p>
<p>Here is the code:</p>
<pre class="lang-js prettyprint-override"><code>import "./styles.css";
import React from "react";
import { useState } from "react";
export default function App() {
const [coordinates, setCoordinates] = useState({ x: 1, y: 1 });
function handleClick(e) {
setCoordinates({ x: e.screenX, y: e.screenY });
}
document.addEventListener("click", handleClick);
return (
<p>
x: {coordinates.x}, y: {coordinates.y};
</p>
);
}
</code></pre>
<p>The sandbox with code is <a href="https://codesandbox.io/s/agitated-sea-0vmq12?file=/src/App.js:0-401" rel="nofollow noreferrer">here</a>.</p>
<p>I appreciate any suggestions and apologize if I am making a very obvious mistake.</p>
|
[
{
"answer_id": 74514186,
"author": "Phil",
"author_id": 283366,
"author_profile": "https://Stackoverflow.com/users/283366",
"pm_score": 2,
"selected": false,
"text": "useEffect(() => {\n document.addEventListener(\"click\", handleClick);\n\n // cleanup\n return () => document.removeEventListener(\"click\", handleClick);\n}, []);\n"
},
{
"answer_id": 74514208,
"author": "tezarsurya",
"author_id": 20538454,
"author_profile": "https://Stackoverflow.com/users/20538454",
"pm_score": 0,
"selected": false,
"text": "document.addEventListener()"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514124",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8560949/"
] |
74,514,126
|
<p>Say I'm working on a project with two tickets. And has some dirty commits.</p>
<pre><code>commit4 do ticket2.2
commit3 do ticket1.2
commit2 do ticket2.1
commit1 do ticket1.1
</code></pre>
<p>Is it safe, if I reorder it to such like this <strong>with no conflict</strong>:</p>
<pre><code>commit4 do ticket2.2
commit3 do ticket2.1
commit2 do ticket1.2
commit1 do ticket1.1
</code></pre>
<p>I think git judge conflict using what deletes and what adds(Sometimes not very clever however). But if we reorder commits with no conflict, is it guaranteed to be the same code with previous? And how can we prove that?</p>
<p>I've been quite frequently using <code>git rebase -i</code> to reorder commits and checked <code>git diff</code> later, the code was same as expexted. But is it always true?</p>
|
[
{
"answer_id": 74514137,
"author": "ti7",
"author_id": 4541045,
"author_profile": "https://Stackoverflow.com/users/4541045",
"pm_score": 1,
"selected": false,
"text": "git rebase"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16685520/"
] |
74,514,138
|
<p>When I hover over my first div to reveal the full text, the second div's position changes to go behind that first div. I need the second div to remain where it is, with the text from the first div overlapping it.</p>
<p><strong>Demo:</strong> <a href="https://codepen.io/adivity/pen/OJEzoPm" rel="nofollow noreferrer">https://codepen.io/adivity/pen/OJEzoPm</a></p>
<pre><code><html>
<body>
<div class="container">
<div>1) This is the full title that I want to be revealed. That is super duper long and totally will overlap the next div.
</div>
<div>2) This is the full title that I want to be revealed. That is super duper long and totally will overlap the next div.
</div>
<div>3) This is the full title that I want to be revealed. That is super duper long and totally will overlap the next div.
</div>
</div>
</body>
</html>
</code></pre>
<pre><code>.container {
max-width: 100px;
margin: 0 auto;
}
.container div {
height: 80px;
background-color: grey;
}
.container div {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.container div:hover {
overflow: visible;
white-space: normal;
z-index: 2;
max-width: 100px;
}
</code></pre>
|
[
{
"answer_id": 74514163,
"author": "yo_sup",
"author_id": 20538807,
"author_profile": "https://Stackoverflow.com/users/20538807",
"pm_score": 1,
"selected": false,
"text": "position: absolute"
},
{
"answer_id": 74514173,
"author": "jerry",
"author_id": 20493210,
"author_profile": "https://Stackoverflow.com/users/20493210",
"pm_score": 0,
"selected": false,
"text": ".container {\n max-width: 100px;\n margin: 0 auto;\n}\n.container div {\n height: 100px;\n background-color: grey;\n}\n.container div {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.container div:hover {\n overflow: visible;\n white-space: normal;\n z-index: 2;\n max-width: 100px;\n}"
},
{
"answer_id": 74514194,
"author": "escapeVelocity",
"author_id": 3725910,
"author_profile": "https://Stackoverflow.com/users/3725910",
"pm_score": 0,
"selected": false,
"text": ".container {\n max-width: 100px;\n margin: 0 auto;\n}\n.container div {\n height: 100px;\n/* background-color: grey; */\n}\n.container div {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.container div:hover {\n overflow: visible;\n white-space: normal;\n z-index: 2;\n position: absolute;\n max-width: 100px;\n}"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7180697/"
] |
74,514,158
|
<p>I want to bind some fontawesome icons into my XAML via view model.
I have it as following</p>
<p>Models</p>
<pre><code> public string Icon { get; set; }
</code></pre>
<p>ViewModel</p>
<pre><code>new Models.Item {Icon="&#xf713;",},
</code></pre>
<p>XAML</p>
<pre><code><Label>
<Span Text="{Binding Icon}"FontFamily="Materiales" FontSize="22" />
</Label>
</code></pre>
<p><a href="https://i.stack.imgur.com/A4qlJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A4qlJ.png" alt="I get it as text not the icon ." /></a></p>
<p><a href="https://i.stack.imgur.com/A4qlJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A4qlJ.png" alt="enter image description here" /></a></p>
<p>What do I need to change or add?</p>
|
[
{
"answer_id": 74514163,
"author": "yo_sup",
"author_id": 20538807,
"author_profile": "https://Stackoverflow.com/users/20538807",
"pm_score": 1,
"selected": false,
"text": "position: absolute"
},
{
"answer_id": 74514173,
"author": "jerry",
"author_id": 20493210,
"author_profile": "https://Stackoverflow.com/users/20493210",
"pm_score": 0,
"selected": false,
"text": ".container {\n max-width: 100px;\n margin: 0 auto;\n}\n.container div {\n height: 100px;\n background-color: grey;\n}\n.container div {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.container div:hover {\n overflow: visible;\n white-space: normal;\n z-index: 2;\n max-width: 100px;\n}"
},
{
"answer_id": 74514194,
"author": "escapeVelocity",
"author_id": 3725910,
"author_profile": "https://Stackoverflow.com/users/3725910",
"pm_score": 0,
"selected": false,
"text": ".container {\n max-width: 100px;\n margin: 0 auto;\n}\n.container div {\n height: 100px;\n/* background-color: grey; */\n}\n.container div {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.container div:hover {\n overflow: visible;\n white-space: normal;\n z-index: 2;\n position: absolute;\n max-width: 100px;\n}"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8765409/"
] |
74,514,177
|
<pre><code> int velikostVstupu=0;
while(scanf("%d", vstup+velikostVstupu)!=EOF){
velikostVstupu++;
if(velikostVstupu>2000){
printf( "Nespravny vstup.\n");
return 0;
}
}
</code></pre>
<p>This code is supposed to input no more than 2000 <code>int</code> values into my array "<code>vstup[2000]</code>". But nowhere do I check if the input is <code>int</code>, yet if it isn't, it succeeds my "<code>if(velikostVstupu>2000)</code>" (that's where I check if I am not over 2000).</p>
<p>Why is that? What is the math behind that?</p>
|
[
{
"answer_id": 74514485,
"author": "Allan Wind",
"author_id": 9706,
"author_profile": "https://Stackoverflow.com/users/9706",
"pm_score": 1,
"selected": false,
"text": "scanf()"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559319/"
] |
74,514,179
|
<p>i want to round off a float to 3 dp in python with 00 in the end if the float don't have 3 dp
like 15.4 into 15.400
thank you.</p>
<p>programme:</p>
<pre><code>x=round(15.4)
</code></pre>
<p>result:
15.400</p>
|
[
{
"answer_id": 74514203,
"author": "Code-Apprentice",
"author_id": 1440565,
"author_profile": "https://Stackoverflow.com/users/1440565",
"pm_score": 2,
"selected": false,
"text": "x = 15.4\nprint(f\"{x:.3f}\")\n"
},
{
"answer_id": 74514230,
"author": "muchhar bharat",
"author_id": 20546821,
"author_profile": "https://Stackoverflow.com/users/20546821",
"pm_score": 1,
"selected": true,
"text": "a=15.4\nb=(\"%.3f\" % a)\nprint(b)\n"
},
{
"answer_id": 74514255,
"author": "Martin Massera",
"author_id": 1438045,
"author_profile": "https://Stackoverflow.com/users/1438045",
"pm_score": 0,
"selected": false,
"text": "15.4"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559358/"
] |
74,514,185
|
<p>I have an abundance df with 63 species in the columns and a column with the plots from 1 to 6. The plot repeats 9 times because it represents the 9 subplots I have. With the first 18 (2 plots) rows and first 3 columns it looks like this:</p>
<pre><code>> taxa_ab
plot Sp1 Sp2
1 1 0 0
2 1 1 1
3 1 0 0
4 1 0 0
5 1 0 0
6 1 0 3
7 1 0 0
8 1 0 0
9 1 0 4
10 2 4 0
11 2 0 0
12 2 0 2
13 2 0 0
14 2 0 0
15 2 0 0
16 2 0 2
17 2 0 0
18 2 0 0
</code></pre>
<p>I want to sum the species by plot so the plot becomes the row name and it looks like this:</p>
<pre><code>> ab_new
Sp1 Sp2
1 1 8
2 4 4
</code></pre>
<p>I tried to use the aggregate function but I haven't understood how to use it.</p>
<pre><code>ab_new <- taxa.ab[,-2] %>%
aggregate(., by = plot, FUN = "sum")
</code></pre>
<p>Also my species abundance are integers and I can't seem to convert them to numeric without loosing the structure of the data frame by unlisting the columns.</p>
<pre><code>> str(taxa_ab)
'data.frame': 54 obs. of 64 variables:
$ plot : chr "1" "1" "1" "1" ...
$ Sp1 : int 0 1 0 0 0 0 0 0 0 0 ...
$ Sp2 : int 0 0 0 0 0 0 0 0 0 0 ...
$ Sp3 : int 0 0 0 1 0 0 1 2 1 1 ...
</code></pre>
|
[
{
"answer_id": 74514226,
"author": "TheMoonandSixpence",
"author_id": 19822406,
"author_profile": "https://Stackoverflow.com/users/19822406",
"pm_score": 1,
"selected": false,
"text": "group_by"
},
{
"answer_id": 74514477,
"author": "Ruam Pimentel",
"author_id": 13015865,
"author_profile": "https://Stackoverflow.com/users/13015865",
"pm_score": 2,
"selected": false,
"text": "aggregate"
},
{
"answer_id": 74514644,
"author": "Rui Barradas",
"author_id": 8245406,
"author_profile": "https://Stackoverflow.com/users/8245406",
"pm_score": 2,
"selected": false,
"text": "aggregate"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16379362/"
] |
74,514,211
|
<p>I would like to create a menu from multiple JSON files.</p>
<p>Please see the following: <a href="https://jsfiddle.net/varJSFiddle/teghqov0/10/" rel="nofollow noreferrer">https://jsfiddle.net/varJSFiddle/teghqov0/10/</a></p>
<p>The desired output would be a dynamic menu that looks something like:</p>
<pre><code><ul class="filter-menu-wrapper">
<li class="filter-menu is-active" id="filter-menu_01"><span class="filter-category">Type<i class='cstm-icon-glyph cstm-icon-glyph-plus'></i></span>
<div class="filter-options">
<span class="filter-option" data-filter="">any</span>
<span class="filter-option" data-filter=".TypeHuman">Human</span>
<span class="filter-option" data-filter=".TypeBlue">Blue</span>
<span class="filter-option thefirst" data-filter=".TypeRed">Red</span>
<span class="filter-option" data-filter=".TypeSpirit">Spirit</span>
</div>
</li>
<li class="filter-menu" id="filter-menu_02"><span class="filter-category">Special<i class='cstm-icon-glyph cstm-icon-glyph-plus'></i></span>
<div class="filter-options">
<span class="filter-option" data-filter="">any</span>
<span class="filter-option" data-filter=".SpecialFireflies">Fireflies</span>
<span class="filter-option" data-filter=".SpecialButterfly">Butterfly</span>
<span class="filter-option" data-filter=".SpecialFoxFire">Fox Fire</span>
<span class="filter-option" data-filter=".SpecialSmoke">Smoke</span>
<span class="filter-option" data-filter=".SpecialSakura">Sakura</span>
<span class="filter-option" data-filter=".SpecialFire">Fire</span>
<span class="filter-option" data-filter=".SpecialEarth">Earth</span>
<span class="filter-option" data-filter=".SpecialWater">Water</span>
<span class="filter-option" data-filter=".SpecialLightning">Lightning</span>
</div>
</li>
<li class="filter-menu" id="filter-menu_03"><span class="filter-category">Clothing<i class='cstm-icon-glyph cstm-icon-glyph-plus'></i></span>
<div class="filter-options">
<span class="filter-option" data-filter="">any</span>
<span class="filter-option" data-filter=".ClothingLightKimono">Light Kimono</span>
<span class="filter-option" data-filter=".ClothingMaroonYukata">Maroon Yukata</span>
<span class="filter-option" data-filter=".ClothingBlueKimono">Blue Kimono</span>
<span class="filter-option" data-filter=".ClothingGreenYukata">Green Yukata</span>
</div>
</li>
</ul>
</code></pre>
|
[
{
"answer_id": 74515203,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": 1,
"selected": true,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var loopFunction = function(dataIsLoading) { // the loop\n \n var itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n \n var myArray = []; // create an array to capture all traits\n \n for (let i = 0; i < 4; i++) {\n \n $.getJSON(itemURI+i, function(data) {\n \n var menuItems = \"\";\n var headings = \"\";\n var subheadings = \"\";\n var dataFilter = \"\";\n \n $.each(data.attributes,function(index,entry) { // i (index), e (entry)\n \n headings = entry.trait_type;\n subheadings = entry.value;\n dataFilter = entry.trait_type + entry.value;\n dataFilter = dataFilter.replace(/ /g, '');\n \n menuItems += '<li class=\"category\"><b>' + headings + '</b>: <br/> ';\n menuItems += subheadings + ', ';\n menuItems += dataFilter;\n menuItems += '</li>'\n\n myArray += entry.trait_type + ': ' + entry.value;\n });\n \n $('#myList').html(menuItems);\n $('#dump').html(myArray);\n //console.log(myArray);\n });\n }\n };\n \n $.when(loopFunction()).done(function() {\n \n var secondaryFunction = function(secondary) { // the loop\n \n // alert(\"it's done, sort and display\");\n \n }\n \n secondaryFunction();\n });\n});"
},
{
"answer_id": 74526539,
"author": "JavaScriptLearner",
"author_id": 20545420,
"author_profile": "https://Stackoverflow.com/users/20545420",
"pm_score": -1,
"selected": false,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var getItemData = async function(id) {\n \n const itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n return await $.getJSON(itemURI+id);\n }\n \n var loopFunction = async function(dataIsLoading) {\n \n var items = {};\n var promises = [];\n \n for (let i = 0; i < 1000; i++) {\n \n // Get data and add to promises array:\n promises.push(getItemData(i));\n }\n \n // Wait on all promises:\n return await Promise.all(promises).then(function(promise) {\n \n // Loop over each returned promise:\n $.each(promise, function(index, data) {\n \n // Loop over attribute data:\n $.each(data.attributes, function(index, entry) {\n \n let menuParent = entry.trait_type;\n let menuChild = entry.value;\n let menuParentItem = {};\n \n // Check for menuParent:\n if (items.hasOwnProperty(menuParent)) {\n \n // Get menuParent:\n menuParentItem = items[menuParent];\n }\n \n // Check for menuChild:\n if (!menuParentItem.hasOwnProperty(menuChild)) {\n \n // Add menuChild:\n menuParentItem[menuChild] = menuChild;\n }\n \n // Update items object:\n items[menuParent] = menuParentItem;\n });\n });\n \n // Return items.\n return items;\n });\n };\n \n $.when(loopFunction()).done(function(items) {\n \n // Loop over all items creating the markup.\n var menuItems = '';\n \n $.each(items, function(menuParent, menuChildren) {\n \n menuItems += '<li class=\"menuParent\"><b>' + menuParent + '</b>: <ul>';\n \n // Loop over menuChildren.\n $.each(menuChildren, function(menuChild, menuChildValue) {\n \n menuItems += '<li class=\"menuChild\">' + menuChild + '</li>';\n });\n \n menuItems += '</ul></li>';\n });\n \n // Render menu items.\n $('#myList').append(menuItems);\n });\n});\n\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20545420/"
] |
74,514,265
|
<p>This is something so simple but is giving me a big headache: how do I remove the top and bottom margin that seem to be automatically added in HTML text components?</p>
<pre><code><!DOCTYPE html>
<html>
<body>
<h1 style="background-color: red; margin: 0px; padding: 0px">Hello World!</h1>
</body>
</html>
</code></pre>
<p>Essentially the parts I marked in black on the top and bottom here:</p>
<p><a href="https://i.stack.imgur.com/GyYgo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GyYgo.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74515203,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": 1,
"selected": true,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var loopFunction = function(dataIsLoading) { // the loop\n \n var itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n \n var myArray = []; // create an array to capture all traits\n \n for (let i = 0; i < 4; i++) {\n \n $.getJSON(itemURI+i, function(data) {\n \n var menuItems = \"\";\n var headings = \"\";\n var subheadings = \"\";\n var dataFilter = \"\";\n \n $.each(data.attributes,function(index,entry) { // i (index), e (entry)\n \n headings = entry.trait_type;\n subheadings = entry.value;\n dataFilter = entry.trait_type + entry.value;\n dataFilter = dataFilter.replace(/ /g, '');\n \n menuItems += '<li class=\"category\"><b>' + headings + '</b>: <br/> ';\n menuItems += subheadings + ', ';\n menuItems += dataFilter;\n menuItems += '</li>'\n\n myArray += entry.trait_type + ': ' + entry.value;\n });\n \n $('#myList').html(menuItems);\n $('#dump').html(myArray);\n //console.log(myArray);\n });\n }\n };\n \n $.when(loopFunction()).done(function() {\n \n var secondaryFunction = function(secondary) { // the loop\n \n // alert(\"it's done, sort and display\");\n \n }\n \n secondaryFunction();\n });\n});"
},
{
"answer_id": 74526539,
"author": "JavaScriptLearner",
"author_id": 20545420,
"author_profile": "https://Stackoverflow.com/users/20545420",
"pm_score": -1,
"selected": false,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var getItemData = async function(id) {\n \n const itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n return await $.getJSON(itemURI+id);\n }\n \n var loopFunction = async function(dataIsLoading) {\n \n var items = {};\n var promises = [];\n \n for (let i = 0; i < 1000; i++) {\n \n // Get data and add to promises array:\n promises.push(getItemData(i));\n }\n \n // Wait on all promises:\n return await Promise.all(promises).then(function(promise) {\n \n // Loop over each returned promise:\n $.each(promise, function(index, data) {\n \n // Loop over attribute data:\n $.each(data.attributes, function(index, entry) {\n \n let menuParent = entry.trait_type;\n let menuChild = entry.value;\n let menuParentItem = {};\n \n // Check for menuParent:\n if (items.hasOwnProperty(menuParent)) {\n \n // Get menuParent:\n menuParentItem = items[menuParent];\n }\n \n // Check for menuChild:\n if (!menuParentItem.hasOwnProperty(menuChild)) {\n \n // Add menuChild:\n menuParentItem[menuChild] = menuChild;\n }\n \n // Update items object:\n items[menuParent] = menuParentItem;\n });\n });\n \n // Return items.\n return items;\n });\n };\n \n $.when(loopFunction()).done(function(items) {\n \n // Loop over all items creating the markup.\n var menuItems = '';\n \n $.each(items, function(menuParent, menuChildren) {\n \n menuItems += '<li class=\"menuParent\"><b>' + menuParent + '</b>: <ul>';\n \n // Loop over menuChildren.\n $.each(menuChildren, function(menuChild, menuChildValue) {\n \n menuItems += '<li class=\"menuChild\">' + menuChild + '</li>';\n });\n \n menuItems += '</ul></li>';\n });\n \n // Render menu items.\n $('#myList').append(menuItems);\n });\n});\n\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5870333/"
] |
74,514,272
|
<p>I want to sort the javascript object in order of another object that have keys and sorting order</p>
<p>I have an object let say</p>
<pre><code>sectionSorting = {
"metrics": "12",
"details": "3",
"portfolio": "5"
"backetst":"14"
}
</code></pre>
<p>I have another object like</p>
<pre><code>sections = {
backtest: [{key: "abc", value: "xyz"}],
metrics: [{key: "abc", value: "xyz"}],
details: [{key: "abc", value: "xyz"}],
methodology: [{key: "abc", value: "xyz"}],
portfoolio: [{key: "abc", value: "xyz"}]
}
</code></pre>
<p>Now I want to sort the 'sections' object in the sorting order of 'sectionSorting' object.
The feilds which do not have sorting order will remail in last.</p>
<p>The desired Output I need is,</p>
<pre><code>sortedSections = {
details: [{key: "abc", value: "xyz"}],
portfoolio: [{key: "abc", value: "xyz"}],
metrics: [{key: "abc", value: "xyz"}],
backtest: [{key: "abc", value: "xyz"}],
methodology: [{key: "abc", value: "xyz"}],
}
</code></pre>
<p>I can not figure out how to do that
Can Anybody help me ?</p>
|
[
{
"answer_id": 74515203,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": 1,
"selected": true,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var loopFunction = function(dataIsLoading) { // the loop\n \n var itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n \n var myArray = []; // create an array to capture all traits\n \n for (let i = 0; i < 4; i++) {\n \n $.getJSON(itemURI+i, function(data) {\n \n var menuItems = \"\";\n var headings = \"\";\n var subheadings = \"\";\n var dataFilter = \"\";\n \n $.each(data.attributes,function(index,entry) { // i (index), e (entry)\n \n headings = entry.trait_type;\n subheadings = entry.value;\n dataFilter = entry.trait_type + entry.value;\n dataFilter = dataFilter.replace(/ /g, '');\n \n menuItems += '<li class=\"category\"><b>' + headings + '</b>: <br/> ';\n menuItems += subheadings + ', ';\n menuItems += dataFilter;\n menuItems += '</li>'\n\n myArray += entry.trait_type + ': ' + entry.value;\n });\n \n $('#myList').html(menuItems);\n $('#dump').html(myArray);\n //console.log(myArray);\n });\n }\n };\n \n $.when(loopFunction()).done(function() {\n \n var secondaryFunction = function(secondary) { // the loop\n \n // alert(\"it's done, sort and display\");\n \n }\n \n secondaryFunction();\n });\n});"
},
{
"answer_id": 74526539,
"author": "JavaScriptLearner",
"author_id": 20545420,
"author_profile": "https://Stackoverflow.com/users/20545420",
"pm_score": -1,
"selected": false,
"text": "$(document).ready(function() {\n \n // 1.) create an attributes (trait) array\n // 2.) loop through the items, check if the trait is already in the array, if not then add it\n // 3.) loop over attributes array and create the menu items off that.\n \n var getItemData = async function(id) {\n \n const itemURI = \"https://ikzttp.mypinata.cloud/ipfs/QmQFkLSQysj94s5GvTHPyzTxrawwtjgiiYS2TBLgrvw8CW/\"\n return await $.getJSON(itemURI+id);\n }\n \n var loopFunction = async function(dataIsLoading) {\n \n var items = {};\n var promises = [];\n \n for (let i = 0; i < 1000; i++) {\n \n // Get data and add to promises array:\n promises.push(getItemData(i));\n }\n \n // Wait on all promises:\n return await Promise.all(promises).then(function(promise) {\n \n // Loop over each returned promise:\n $.each(promise, function(index, data) {\n \n // Loop over attribute data:\n $.each(data.attributes, function(index, entry) {\n \n let menuParent = entry.trait_type;\n let menuChild = entry.value;\n let menuParentItem = {};\n \n // Check for menuParent:\n if (items.hasOwnProperty(menuParent)) {\n \n // Get menuParent:\n menuParentItem = items[menuParent];\n }\n \n // Check for menuChild:\n if (!menuParentItem.hasOwnProperty(menuChild)) {\n \n // Add menuChild:\n menuParentItem[menuChild] = menuChild;\n }\n \n // Update items object:\n items[menuParent] = menuParentItem;\n });\n });\n \n // Return items.\n return items;\n });\n };\n \n $.when(loopFunction()).done(function(items) {\n \n // Loop over all items creating the markup.\n var menuItems = '';\n \n $.each(items, function(menuParent, menuChildren) {\n \n menuItems += '<li class=\"menuParent\"><b>' + menuParent + '</b>: <ul>';\n \n // Loop over menuChildren.\n $.each(menuChildren, function(menuChild, menuChildValue) {\n \n menuItems += '<li class=\"menuChild\">' + menuChild + '</li>';\n });\n \n menuItems += '</ul></li>';\n });\n \n // Render menu items.\n $('#myList').append(menuItems);\n });\n});\n\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17786978/"
] |
74,514,275
|
<p>How do I find two max value in a list and sum up, not using rec, only can use <code>List.fold_left</code> or right and <code>List.map</code>?
I used <code>filter</code>, but it's not allowed, anyways I can replace the <code>filter</code>?</p>
<pre><code>let max a b =
if b = 0 then a
else if a > b then a
else b;;
let maxl2 lst =
match lst with
| [] -> 0
| h::t ->
let acc = h in
List.fold_left max acc lst +
List.fold_left
max acc
(List.filter (fun x -> (x mod List.fold_left max acc lst) != 0) lst);;
</code></pre>
|
[
{
"answer_id": 74514372,
"author": "Jeffrey Scofield",
"author_id": 821679,
"author_profile": "https://Stackoverflow.com/users/821679",
"pm_score": 2,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74514440,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74518216,
"author": "coredump",
"author_id": 124319,
"author_profile": "https://Stackoverflow.com/users/124319",
"pm_score": 1,
"selected": false,
"text": "type max_of_acc = \n | SortedPair of int * int (* invariant: fst <= snd *)\n | Single of int\n | Empty\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20354496/"
] |
74,514,296
|
<p>I am trying to modify a given code and add an average to all the elements within a user given 2d array. I'm initializing the array <code>ave</code> to have the same elements of array <code>sum</code> and then displaying it outside the <code>for</code> loop to do the calculation.</p>
<pre class="lang-java prettyprint-override"><code>import java.util.Scanner;
public class Arrays2D_GeneratorRevised {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
final int R=4, C=3;
int r,c;
double[][] volt = new double[R][C];
double[] sum = new double[R];
double[] ave = new double[R];
System.out.println("Enter the output voltages for the following generators :");
for(r=0; r<R; r++) {
System.out.print("Generator "+(r+1)+" :\n");
for(c=0; c<C; c++) {
volt[r][c]=in.nextInt();
sum[r]+=volt[r][c];
ave[r]+=sum[r];
}
}
//display table
System.out.print("\n\t Generator Test Results");
System.out.printf("\n\t%16s%10s%9s%10s","Output 1","Output 2","Output 3","Average");
for(r=0; r<R; r++) {
System.out.print("\nGenerator "+(r+1));
for(c=0; c<C; c++) {
System.out.printf("%10.2f",volt[r][c]);
}
System.out.printf("%10.2f",sum[r]/C);
}
System.out.printf("%10.2f",ave[r]/=(R*C));
System.out.print("\n\n");
}
}
</code></pre>
<p>I tried making the <code>ave</code> to a 2d array and assigning it different variables of R,C,c,r. This also happens whenever I make a 1d array and display it using the argument <code>array[i]</code>. Somehow it only works whenever I use the <code>Arrays.toString()</code> to display or manipulate the elements inside.</p>
|
[
{
"answer_id": 74514372,
"author": "Jeffrey Scofield",
"author_id": 821679,
"author_profile": "https://Stackoverflow.com/users/821679",
"pm_score": 2,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74514440,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74518216,
"author": "coredump",
"author_id": 124319,
"author_profile": "https://Stackoverflow.com/users/124319",
"pm_score": 1,
"selected": false,
"text": "type max_of_acc = \n | SortedPair of int * int (* invariant: fst <= snd *)\n | Single of int\n | Empty\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19891678/"
] |
74,514,319
|
<p>I'm using CKEditor for a form. In the admin it works fine, but when using it in the ModelForm of a CreateView the editor doesn't save data. As in the official docs, with this code:</p>
<pre><code>class EventForm(forms.ModelForm):
description = forms.CharField(widget=CKEditorWidget())
image = forms.ImageField(widget=forms.ClearableFileInput(), required=False)
class Meta:
model = Event
fields = ['title', 'description', 'type', 'start_date', 'end_date', 'fee']
</code></pre>
<p>And this html:</p>
<pre><code><div>
<form hx-post="{{ request.path }}" enctype="multipart/form-data" class="modal-content">
{% csrf_token %}
<div class="modal-header">
<h1>Create new event</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{{form.media}}
{{form.as_p}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<input type="submit" value="Submit">
</div>
</form>
</div>
</code></pre>
<p>It won't let me submit the form as it will keep saying that the description field is required. Trying to add the CKEditor widget field in the <strong>init</strong> method, with this code:</p>
<pre><code>class EventForm(forms.ModelForm):
image = forms.ImageField(widget=forms.ClearableFileInput(), required=False)
class Meta:
model = Event
fields = ['title', 'description', 'type', 'start_date', 'end_date', 'fee']
def __init__(self, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)
self.fields['start_date'].widget = forms.SelectDateWidget()
self.fields['end_date'].widget = forms.SelectDateWidget()
self.fields['description'].widget = CKEditorWidget()
</code></pre>
<p>The form will be sent, and the instance created. However, the 'description' field will be empty even if I enter some content. This is my view:</p>
<pre><code>class CreateEvent(LoginRequiredMixin, CreateView):
model = Event
form_class = EventForm
template_name = 'events/events_form.html'
success_url = reverse_lazy('events:index')
def form_valid(self, form):
form.instance.author = self.request.user
event_obj = form.save(commit=True)
image = self.request.FILES.get('image')
if image:
EventImage.objects.create(title=event_obj.title, image=image, event=event_obj)
return HttpResponse(status=204, headers={'HX-Trigger' : 'eventsListChanged'})
</code></pre>
<p>How should I make sure the data is being saved from the CKeditor?</p>
|
[
{
"answer_id": 74514372,
"author": "Jeffrey Scofield",
"author_id": 821679,
"author_profile": "https://Stackoverflow.com/users/821679",
"pm_score": 2,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74514440,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "List.fold_left"
},
{
"answer_id": 74518216,
"author": "coredump",
"author_id": 124319,
"author_profile": "https://Stackoverflow.com/users/124319",
"pm_score": 1,
"selected": false,
"text": "type max_of_acc = \n | SortedPair of int * int (* invariant: fst <= snd *)\n | Single of int\n | Empty\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18415229/"
] |
74,514,341
|
<p>I am building a Flutter web app using FirebaseAuth for authentication, and I am trying to figure out how to load the correct route when the user a) is authenticated, and b) the user refreshes the web page.</p>
<p>When the app loads, firebase gets initialised and then fetches the user's auth state, returning it about 2 seconds later in an <code>authStateChanges</code> handler.</p>
<p>The problem I have is that by the time the auth state is returned, my app has already determined which route should be presented to the user, namely, login (since, as far as the app is concerned, the user is not yet authenticated).</p>
<p>This results in the user first being navigated to login, and then later, when the auth state is updated, they can be navigated somewhere else - which is a crappy UX.</p>
<p>In the <a href="https://firebase.google.com/docs/auth/flutter/start#persisting_authentication_state" rel="nofollow noreferrer">Firebase Auth docs</a> under the section "Persisting Authentication State" it says "The Firebase SDKs for all platforms provide out of the box support for ensuring that your user's authentication state is persisted across app restarts or page reloads" - and then goes on to say "On web platforms, the user's authentication state is stored in IndexedDB."</p>
<p>Does that mean, on page reloads, I need to access the auth state of the user directly from the IndexedDB? Or does it mean Firebase returns the value stored there for me automatically?</p>
<p>If I am supposed to consume IndexedDB directly, how do I do that, and what key should I use?</p>
|
[
{
"answer_id": 74514398,
"author": "Frank van Puffelen",
"author_id": 209103,
"author_profile": "https://Stackoverflow.com/users/209103",
"pm_score": 3,
"selected": true,
"text": "onAuthStateChanged"
},
{
"answer_id": 74514453,
"author": "Sayyid J",
"author_id": 15366030,
"author_profile": "https://Stackoverflow.com/users/15366030",
"pm_score": 0,
"selected": false,
"text": "GoRouter(\n....\ninitialLocation: LoadingPage(),\nredirect: _goTologinPageorHomePageBasedAuthStatus()\n..)\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5133055/"
] |
74,514,366
|
<p>I want to find all</p>
<pre><code><a href='https://example.com/'>
</code></pre>
<p>references in a large file and append the</p>
<pre><code>target='_blank' rel='noopener noreferrer'
</code></pre>
<p>option to the end of the tag, if it is missing.</p>
<p>Roughly, I did the following:</p>
<pre><code>re.sub(r'<a href=([^>]+)', r'<a href=([^>]+)' + " target='_blank' rel='noopener noreferrer'", content)
</code></pre>
<p>Note: content contains the body of text to alter.</p>
<p>But, the second argument, which should be the value to replace is messing up the result.</p>
<p>The output I am getting is:</p>
<pre><code><a href=([^>]+) target='_blank' rel='noopener noreferrer'>
</code></pre>
<p>The expected result should be:</p>
<pre><code><a href='https://example.com/' target='_blank' rel='noopener noreferrer'>
</code></pre>
<p>What am I doing incorrectly, and how do I fix this issue?</p>
|
[
{
"answer_id": 74514430,
"author": "ti7",
"author_id": 4541045,
"author_profile": "https://Stackoverflow.com/users/4541045",
"pm_score": 0,
"selected": false,
"text": "from bs4 import BeautifulSoup\nsoup = BeautifulSoup(html_contents, \"html.parser\")\nsoup.find_all(\"a\")\n"
},
{
"answer_id": 74514523,
"author": "MZM",
"author_id": 20551381,
"author_profile": "https://Stackoverflow.com/users/20551381",
"pm_score": 1,
"selected": false,
"text": "import re\ncontent = \"<a href='https://example.com/'>\"\nx = re.sub(r'(<a href=([^>]+))', r'\\1' + \" target='_blank' rel='noopener noreferrer'\", content)\nprint(x)\n\noutput:\n <a href='https://example.com/' target='_blank' rel='noopener noreferrer'>\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9111676/"
] |
74,514,379
|
<p>Suppose I have a 10x10 Python array, M. I would like to extract the 3x3 array with the values of the rows [2,3,5], and columns [2,3,5]. How do I do this? I would like to obtain the equivalent of M[0:3,0:3] but using coordinates [2,3,5] instead of [0,1,2].</p>
<p>I have tried M[[2,3,5],[2,3,5]], but this produces three values, not a 3x3 array.</p>
|
[
{
"answer_id": 74514430,
"author": "ti7",
"author_id": 4541045,
"author_profile": "https://Stackoverflow.com/users/4541045",
"pm_score": 0,
"selected": false,
"text": "from bs4 import BeautifulSoup\nsoup = BeautifulSoup(html_contents, \"html.parser\")\nsoup.find_all(\"a\")\n"
},
{
"answer_id": 74514523,
"author": "MZM",
"author_id": 20551381,
"author_profile": "https://Stackoverflow.com/users/20551381",
"pm_score": 1,
"selected": false,
"text": "import re\ncontent = \"<a href='https://example.com/'>\"\nx = re.sub(r'(<a href=([^>]+))', r'\\1' + \" target='_blank' rel='noopener noreferrer'\", content)\nprint(x)\n\noutput:\n <a href='https://example.com/' target='_blank' rel='noopener noreferrer'>\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559510/"
] |
74,514,393
|
<p>I have created an app with Jetpack compose and expected the start up background is black or some other colors, not white. This is my themes.xml</p>
<pre><code><style name="Theme.AlluringScreenshot" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="android:statusBarColor">#030318</item>
<item name="android:windowBackground">#030318</item>
</style>
</code></pre>
<p>The above style works well till on Android 11 but Android 12. My app still has white background at starting up. Any suggestions for this matter?</p>
|
[
{
"answer_id": 74516235,
"author": "zjmo",
"author_id": 14507326,
"author_profile": "https://Stackoverflow.com/users/14507326",
"pm_score": 0,
"selected": false,
"text": "implementation 'androidx.compose.material3:material3:1.1.0-alpha02'\nimplementation 'com.google.android.material:material:1.8.0-alpha02'\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12697321/"
] |
74,514,416
|
<p>Is there any instance to use a filter with its own type? Right now I have this type:</p>
<pre><code>data Tree a = Leaf | Node a Color (Tree a) (Tree a) deriving (Show)
</code></pre>
<p>And I'd like to write something like:</p>
<pre><code>filter (>4) tree
</code></pre>
<p>If there is such an instance, can someone give me an example code, because I do not understand how it should be different from fmap</p>
|
[
{
"answer_id": 74514647,
"author": "Joseph Sible-Reinstate Monica",
"author_id": 7509065,
"author_profile": "https://Stackoverflow.com/users/7509065",
"pm_score": 3,
"selected": true,
"text": "base"
},
{
"answer_id": 74517300,
"author": "amalloy",
"author_id": 625403,
"author_profile": "https://Stackoverflow.com/users/625403",
"pm_score": 2,
"selected": false,
"text": "Foldable Tree"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20343349/"
] |
74,514,458
|
<p>i had found fews lines of code online where</p>
<p>1: filter data from "Mst SKU"
2: split the data into different multiple sheets
3: sheet should be added before "All_total"</p>
<p>step 1 and 2 are working good but step 3 the sheets are added after last worksheet in workbook</p>
<p>added the screenshot ,sheet 1,2,3 is inserted after , which is dont want to happen it should be inserted before "All_Total" , please let me know where i am going wrong</p>
<pre><code>Sub Splitdatabycol()
Dim Data_Sheet, allsku_Data_Sheet As Worksheet
Dim Pivot_Sheet As Worksheet
Dim StartPoint, DataRange As Range
Dim PivotName, NewRange, Asin, typ As String
Dim LastCol, lastRow, LastcolA, lastRowA, qtySum As Single
Dim priceSum As Single
Dim answer, j, k, l, Downcell, DowncellA, col1, col2, col3, col4, col5, col6, col7 As Integer
Dim saleExists, stockExists, errorExists, aListing As Boolean
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
Dim xTRg As Range
Dim xVRg As Range
Dim xWSTRg As Worksheet
Dim xWS As Worksheet
Dim XwsNAme As Worksheet
Dim all_sku As Worksheet
On Error Resume Next
Set xTRg = Application.InputBox("Please select the header rows:", "Please Select Header", "'Mst SKU'!$AK$1", Type:=8)
If TypeName(xTRg) = "Nothing" Then Exit Sub
Set xVRg = Application.InputBox("Please select the column you want to split data based on:", "Please Select Column", "'Mst SKU'!$AK$1", Type:=8)
If TypeName(xVRg) = "Nothing" Then Exit Sub
vcol = xVRg.Column
Set ws = xTRg.Worksheet
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = xTRg.AddressLocal
titlerow = xTRg.Cells(0).Row
icol = ws.Columns.Count
ws.Cells(0, icol) = "Unique"
Application.DisplayAlerts = False
If Not Evaluate("=ISREF('xTRgWs_Sheet!A1')") Then
'Sheets.Add(Before:=Worksheets(Worksheets.Count)).Name = "All Total"
Else
'Sheets("All Total").Delete
'Sheets.Add(Before:=Worksheets(Worksheets.Count)).Name = "xTRgWs_Sheet!A1"
'Sheets.Add(Before:=ActiveSheet).Name = "xTRgWs_Sheet!A1"
End If
Set xWSTRg = Sheets("xTRgWs_Sheet!A1")
xTRg.Copy
xWSTRg.Paste Destination:=xWSTRg.Range("A1")
ws.Activate
For i = (titlerow + xTRg.Rows.Count) To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Set xWS = Sheets.Add(Before:=Worksheets(Worksheets.Count))
xWS.Name = myarr(i) & ""
Else
'xWS.Move Before:=Worksheets(Worksheets.Count)
xWS.Move Before:=Worksheets(ActiveSheet)
End If
xWSTRg.Range(title).Copy
xWS.Paste Destination:=xWS.Range("A")
ws.Range("A" & (titlerow + xTRg.Rows.Count) & ":A" & lr).EntireRow.Copy xWS.Range("A" & (titlerow + xTRg.Rows.Count))
Sheets(myarr(i) & "").Columns.AutoFit
Next
xWSTRg.Delete
ws.AutoFilterMode = False
ws.Activate
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Call split_data
'Set Pivot Table & Source Worksheet
Set Data_Sheet = ThisWorkbook.Worksheets("Mst SKU")
Set Pivot_Sheet = ThisWorkbook.Worksheets("All Total")
'Enter in Pivot Table Name
PivotName = "PivotTable1"
'Defining Staring Point & Dynamic Range
Data_Sheet.Activate
Set StartPoint = Data_Sheet.Range("A1")
LastCol = StartPoint.End(xlToRight).Column
Downcell = StartPoint.End(xlDown).Row
Set DataRange = Data_Sheet.Range(StartPoint, Cells(Downcell, LastCol))
NewRange = Data_Sheet.Name & "!" & DataRange.Address(ReferenceStyle:=xlR1C1)
'Change Pivot Table Data Source Range Address
Pivot_Sheet.PivotTables(PivotName). _
ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=NewRange)
'Ensure Pivot Table is Refreshed
Pivot_Sheet.PivotTables(PivotName).RefreshTable
'Complete Message
Pivot_Sheet.Activate
MsgBox "Your Pivot Table is now updated."
Dim TitleNAme As Range
Application.ScreenUpdating = True
Application.CutCopyMode = False
Application.DisplayAlerts = True
TitleNAme = Application.GetOpenFilename(Filefilter = "Excel Files,*.xlsx,*.xlsm")
MsgBox TitleNAme
End Sub
</code></pre>
|
[
{
"answer_id": 74514647,
"author": "Joseph Sible-Reinstate Monica",
"author_id": 7509065,
"author_profile": "https://Stackoverflow.com/users/7509065",
"pm_score": 3,
"selected": true,
"text": "base"
},
{
"answer_id": 74517300,
"author": "amalloy",
"author_id": 625403,
"author_profile": "https://Stackoverflow.com/users/625403",
"pm_score": 2,
"selected": false,
"text": "Foldable Tree"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559518/"
] |
74,514,537
|
<p>I am using moment.js. I want to restrict the user son that he can only select a date which is from current date to 50 years before.
In short, i just want that user's date of birth cannot be more than 50 years. So, from the current date, only ranges before the 50 years should only be there.
How can i do so? please guide me.</p>
|
[
{
"answer_id": 74514590,
"author": "Shubhanu Sharma",
"author_id": 7012018,
"author_profile": "https://Stackoverflow.com/users/7012018",
"pm_score": 1,
"selected": false,
"text": "fiftyYearsBackDate = moment().subtract(50, \"years\")\n"
},
{
"answer_id": 74514626,
"author": "Tehila",
"author_id": 16142839,
"author_profile": "https://Stackoverflow.com/users/16142839",
"pm_score": 2,
"selected": false,
"text": "difference"
},
{
"answer_id": 74514839,
"author": "Rajeev Singh",
"author_id": 16560548,
"author_profile": "https://Stackoverflow.com/users/16560548",
"pm_score": 1,
"selected": false,
"text": "const past = moment().subtract(50, 'years'); // To past\nconst future = moment().add(50, 'years'); // Back to future\n"
},
{
"answer_id": 74515467,
"author": "RobG",
"author_id": 257182,
"author_profile": "https://Stackoverflow.com/users/257182",
"pm_score": 1,
"selected": false,
"text": "birthdate < new Date().setFullYear(new Date().getFullYear() - 50);\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19350699/"
] |
74,514,540
|
<pre><code>repeat = "y"
while repeat == "y":
#First get the two integers from the user
a = int(input("Enter the first integer: "))
b = int(input("Enter the second integer: "))
#Start the answer with 0
answer = 0
print("A", "B")
print("---")
print(a, b)
#run loop until b is not zero
while b != 0:
#loop while 'b' is odd number
if (b % 2 != 0):
answer = answer + a
print(a*2, b//2)
a = a*2 #double every 'a' integers
b = b//2 #halve the 'b' integers
#loop while 'b' is even number
elif (b % 2 == 0):
print(a*2, b//2)
a = a*2 #double every 'a' integers
b = b//2 #halve the 'b' integers
print("The product is {}.".format(answer))
repeat = input("Would you like to repeat? (y/n)")
print("Goodbye!")
</code></pre>
<p>I am writing a program that uses Ancient Egyptian method to multiply. My program works for positive numbers but not negative. How do I fix it so that if both inputted values of user are negative. My result should give the product of any two positive, negative or one negative and positive number. My current program gives the product for any two positive values, or negative <code>a</code> value and positive <code>b</code> value. However, when user enters a negative <code>b</code> value, it produces infinite outputs.</p>
|
[
{
"answer_id": 74514590,
"author": "Shubhanu Sharma",
"author_id": 7012018,
"author_profile": "https://Stackoverflow.com/users/7012018",
"pm_score": 1,
"selected": false,
"text": "fiftyYearsBackDate = moment().subtract(50, \"years\")\n"
},
{
"answer_id": 74514626,
"author": "Tehila",
"author_id": 16142839,
"author_profile": "https://Stackoverflow.com/users/16142839",
"pm_score": 2,
"selected": false,
"text": "difference"
},
{
"answer_id": 74514839,
"author": "Rajeev Singh",
"author_id": 16560548,
"author_profile": "https://Stackoverflow.com/users/16560548",
"pm_score": 1,
"selected": false,
"text": "const past = moment().subtract(50, 'years'); // To past\nconst future = moment().add(50, 'years'); // Back to future\n"
},
{
"answer_id": 74515467,
"author": "RobG",
"author_id": 257182,
"author_profile": "https://Stackoverflow.com/users/257182",
"pm_score": 1,
"selected": false,
"text": "birthdate < new Date().setFullYear(new Date().getFullYear() - 50);\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559638/"
] |
74,514,554
|
<p>Here I have two tables:</p>
<p><strong>Table A</strong>: col_A, col_B, col_C, metric_1, metric_2, metric_3</p>
<p><strong>Table B</strong>: col_A, col_B, col_C, metric_X, metric_Y, metric_Z</p>
<p>I may need to put them in the report with col_A, col_B, col_C as <strong>shared filters</strong>. col_A, col_B, col_C are many to many relationship, for example, age, country, domain. How could I achieve this?</p>
<p>The solutions I may know are:</p>
<ol>
<li><p>Pull column col_A, col_B, col_C as filters from table 1, but in this case table 2 doesn't have any relation with table 1 and the filter won't work for table 2. And if I add relation of table 2 with table 1 for col_A, then I couldn't next also add relation for col_B or col_C as only one relation could be added.</p>
</li>
<li><p>Another solution is that I would extract col_A, col_B, col_C as a new table for dimensions shared between table 1 and table 2. Then the filters may have better performance as there is less data. However, how could I apply the shared dimension table filter to table 1 and table 2? Or is there way like filter could achieve this?</p>
<p><code>ForAll(Table1, Collect(col_A, Filter(Table2, col_A in FullName).FullName))</code></p>
</li>
</ol>
<p>Thanks.</p>
|
[
{
"answer_id": 74514590,
"author": "Shubhanu Sharma",
"author_id": 7012018,
"author_profile": "https://Stackoverflow.com/users/7012018",
"pm_score": 1,
"selected": false,
"text": "fiftyYearsBackDate = moment().subtract(50, \"years\")\n"
},
{
"answer_id": 74514626,
"author": "Tehila",
"author_id": 16142839,
"author_profile": "https://Stackoverflow.com/users/16142839",
"pm_score": 2,
"selected": false,
"text": "difference"
},
{
"answer_id": 74514839,
"author": "Rajeev Singh",
"author_id": 16560548,
"author_profile": "https://Stackoverflow.com/users/16560548",
"pm_score": 1,
"selected": false,
"text": "const past = moment().subtract(50, 'years'); // To past\nconst future = moment().add(50, 'years'); // Back to future\n"
},
{
"answer_id": 74515467,
"author": "RobG",
"author_id": 257182,
"author_profile": "https://Stackoverflow.com/users/257182",
"pm_score": 1,
"selected": false,
"text": "birthdate < new Date().setFullYear(new Date().getFullYear() - 50);\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5266554/"
] |
74,514,558
|
<p>I had a slow performance of default save method in spring data jpa. So, i decided to make save method work asynchronously cause i did not need response in this specific method.</p>
<pre><code>@Repository
public interface WorkplaceRepo extends JpaRepository<Workplace, Long> {
@Async
public <S extends Workplace> S save(S workplaceE);
</code></pre>
<p>It caused the problem that all save methods in whole project started to call this asynchronous method. The question is: how to use both save methods without losing one of them(default version and async version)</p>
<p>i thought to create custom insert method using native query, but the entity have so many columns and foreign keys, and i am not sure that it would work correctly.</p>
|
[
{
"answer_id": 74514590,
"author": "Shubhanu Sharma",
"author_id": 7012018,
"author_profile": "https://Stackoverflow.com/users/7012018",
"pm_score": 1,
"selected": false,
"text": "fiftyYearsBackDate = moment().subtract(50, \"years\")\n"
},
{
"answer_id": 74514626,
"author": "Tehila",
"author_id": 16142839,
"author_profile": "https://Stackoverflow.com/users/16142839",
"pm_score": 2,
"selected": false,
"text": "difference"
},
{
"answer_id": 74514839,
"author": "Rajeev Singh",
"author_id": 16560548,
"author_profile": "https://Stackoverflow.com/users/16560548",
"pm_score": 1,
"selected": false,
"text": "const past = moment().subtract(50, 'years'); // To past\nconst future = moment().add(50, 'years'); // Back to future\n"
},
{
"answer_id": 74515467,
"author": "RobG",
"author_id": 257182,
"author_profile": "https://Stackoverflow.com/users/257182",
"pm_score": 1,
"selected": false,
"text": "birthdate < new Date().setFullYear(new Date().getFullYear() - 50);\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12510729/"
] |
74,514,579
|
<p>My home.html in div where I called the { data } to display in HTML</p>
<pre><code><div id= "main">
<h1> DATA SCRAPPER</h1>
<h2>Header Data from html Page</h2>
{ data }
</div>
</code></pre>
<p>The local host shows
<a href="https://i.stack.imgur.com/9IDKg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9IDKg.png" alt="enter image description here" /></a></p>
<p>But in terminal it is showing the scrapped data</p>
<p>Views.py where</p>
<pre><code>def home(request):
soup= None
URL = 'https://www.abc.html'
page = requests.get(URL)
soup = bs(page.content, 'html.parser')
print(soup.h1.text)
head=soup.h1.text
return render(request, 'home.html', {'data': head})
</code></pre>
|
[
{
"answer_id": 74514601,
"author": "François Constant",
"author_id": 1000378,
"author_profile": "https://Stackoverflow.com/users/1000378",
"pm_score": 3,
"selected": true,
"text": "{{ data }}\n"
},
{
"answer_id": 74514619,
"author": "sunil ghimire",
"author_id": 9572929,
"author_profile": "https://Stackoverflow.com/users/9572929",
"pm_score": 0,
"selected": false,
"text": "{{data}}\n"
},
{
"answer_id": 74514727,
"author": "16-48-YUVARAJ R",
"author_id": 20559716,
"author_profile": "https://Stackoverflow.com/users/20559716",
"pm_score": 0,
"selected": false,
"text": "<!doctype html>\n<html>\n<head>\n<title>code </title>\n</head>\n<body>\n<div id=\"main\">\n<h1> data </h1>\n<h2> header data from html </h2>\n{{data}}\n</div>\n</body>\n</html>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18427291/"
] |
74,514,600
|
<p>When I do a backup, we transfer It to another server and today I wanted to unzip to check the contents and It asks me for a password.</p>
<p>I checked the config files, documentation, but I cannot seem to find where to find It or how to set It</p>
<p>Package: spatie/laravel-backup</p>
|
[
{
"answer_id": 74514802,
"author": "stefket",
"author_id": 2499739,
"author_profile": "https://Stackoverflow.com/users/2499739",
"pm_score": 2,
"selected": true,
"text": " /*\n * The password to be used for archive encryption.\n * Set to `null` to disable encryption.\n */\n 'password' => env('BACKUP_ARCHIVE_PASSWORD'),\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3636359/"
] |
74,514,639
|
<p>Hi I'm learning C through the Modern Approach book. For this program, we just need to input a first name and last name, and the program should return Last Name, First Initial.</p>
<pre><code>char *first [255];
char *last [255];
printf("Enter a first name and a last name: ");
while (getchar() == ' ');
scanf("%s", first);
while (getchar() == ' ');
scanf("%s", last);
while (getchar() == ' ');
char firstInitial = (char) first[0];
printf("%s, ", last);
putchar(firstInitial);
</code></pre>
<p>When I run it, it doesn't print the first two characters.</p>
<p>e.g
Enter a first name and a last name: Aaron Smith
mith, a</p>
|
[
{
"answer_id": 74514802,
"author": "stefket",
"author_id": 2499739,
"author_profile": "https://Stackoverflow.com/users/2499739",
"pm_score": 2,
"selected": true,
"text": " /*\n * The password to be used for archive encryption.\n * Set to `null` to disable encryption.\n */\n 'password' => env('BACKUP_ARCHIVE_PASSWORD'),\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559704/"
] |
74,514,676
|
<p>I have removed the default React icon from the <code>index.html</code> file in create-react-app, but, it is still showing up.</p>
<p>Here is the code of <code>index.html</code> file</p>
<pre><code><!DOCTYPE html>
<html lang="en" class="h-full bg-gray-50">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>ResumeBuilder</title>
</head>
<body class="h-full">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
</code></pre>
<p><a href="https://i.stack.imgur.com/ppDbt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ppDbt.png" alt="Icon showing in tab title" /></a></p>
<p><strong>Folder structure</strong> of public of create-react-app:</p>
<p><a href="https://i.stack.imgur.com/dYWlG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dYWlG.png" alt="folder structure" /></a></p>
<p><strong>How can I remove it?</strong></p>
|
[
{
"answer_id": 74514802,
"author": "stefket",
"author_id": 2499739,
"author_profile": "https://Stackoverflow.com/users/2499739",
"pm_score": 2,
"selected": true,
"text": " /*\n * The password to be used for archive encryption.\n * Set to `null` to disable encryption.\n */\n 'password' => env('BACKUP_ARCHIVE_PASSWORD'),\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12045119/"
] |
74,514,686
|
<p>I looked into the code of inverting binary tree in the internet. But I couldnt what it is doing. Its written in Python. I am a python programmer myself but couldnt understand it.</p>
<p>The snippet is as follows:</p>
<pre><code>def invertTree(root):
if root:
root.left, root.right = invertTree(root.right), invertTree(root.left)
return root
</code></pre>
<p>I don't understand this <code>root.left</code> and <code>root.right</code> . Root is the main node in the graph, it will be an integer or a single character. But what does root.left represent in Python? I honestly do not get it.</p>
<p><strong>Update:</strong></p>
<p>My understanding is the node is access like below:</p>
<pre><code>class Node:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def PrintTree(self):
print(self.data)
root = Node(10)
root.PrintTree()
</code></pre>
|
[
{
"answer_id": 74514802,
"author": "stefket",
"author_id": 2499739,
"author_profile": "https://Stackoverflow.com/users/2499739",
"pm_score": 2,
"selected": true,
"text": " /*\n * The password to be used for archive encryption.\n * Set to `null` to disable encryption.\n */\n 'password' => env('BACKUP_ARCHIVE_PASSWORD'),\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14673832/"
] |
74,514,700
|
<p>I'm using input text field to input numbers only. I can't use input type="number" because i probably use the decimal or (.) characters</p>
<p>Example of expected result:</p>
<ol>
<li>whole numbers</li>
<li>numbers with decimal</li>
<li>restricted alphabets</li>
</ol>
<p>If possible, only decimal character are allowed, the rest will restricted also in special character.</p>
|
[
{
"answer_id": 74514776,
"author": "kgajjar20",
"author_id": 9212246,
"author_profile": "https://Stackoverflow.com/users/9212246",
"pm_score": 1,
"selected": true,
"text": "<input type=\"number\" required name=\"price\" min=\"0\" value=\"0\" step=\"any\">\n"
},
{
"answer_id": 74514808,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": -1,
"selected": false,
"text": "Enter Input try it. <br/>\n<input type=\"text\" onkeypress=\"return event.charCode >= 46 && event.charCode <= 57\" onpaste=\"return false\">"
},
{
"answer_id": 74514844,
"author": "4b0",
"author_id": 965146,
"author_profile": "https://Stackoverflow.com/users/965146",
"pm_score": 0,
"selected": false,
"text": "$(\".decimal\").on(\"input\", function(evt) {\n var txt = $(this).val();\n txt = txt.replace(/[^0-9\\.]/g, '');\n if (txt.split('.').length > 2)\n txt = txt.replace(/\\.+$/, \"\");\n $(this).val(txt);\n});"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20517886/"
] |
74,514,708
|
<p>I have Dialogflow ES angent with a version.
With "Draft" version in Dialogflow, I can call curl command and get response like below.</p>
<pre><code>curl \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer <token>" \
-d "{\"queryInput\":{\"text\":{\"text\":\"バージョン\",\"languageCode\":\"ja\"}},\"queryParams\":{\"source\":\"DIALOGFLOW_CONSOLE\",\"timeZone\":\"Asia/Tokyo\",\"sentimentAnalysisRequestConfig\":{\"analyzeQueryTextSentiment\":true}}}" \
"https://dialogflow.googleapis.com/v2/projects/<project_name>/agent/sessions/<session_id>:detectIntent"
</code></pre>
<p>When I tried to access custom version, I got 404 in response text like below.</p>
<pre><code>curl \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer <token>" \
-d "{\"queryInput\":{\"text\":{\"text\":\"バージョン\",\"languageCode\":\"ja\"}},\"queryParams\":{\"source\":\"DIALOGFLOW_CONSOLE\",\"timeZone\":\"Asia/Tokyo\",\"sentimentAnalysisRequestConfig\":{\"analyzeQueryTextSentiment\":true}}}" \
"https://dialogflow.googleapis.com/v2/projects/<project_name>/agent/environments/DEV/sessions/<session_id>:detectIntent"
</code></pre>
<pre class="lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/v2/projects/%3Cproject_name%3E/agent/environments/DEV/sessions/%3Csession_id%3E:detectIntent</code> was not found on this server. <ins>That’s all we know.</ins>
</code></pre>
<p>I followed the guid in <a href="https://cloud.google.com/dialogflow/es/docs/agents-versions#test_your_agent_in_an_environment" rel="nofollow noreferrer">Dialogflow ES Documentation</a>.</p>
<p>I made the active environments Dialogflow console.</p>
<p><a href="https://i.stack.imgur.com/lseEa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lseEa.png" alt="Environments tab" /></a></p>
<p><a href="https://i.stack.imgur.com/XBhxi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XBhxi.png" alt="The active status" /></a></p>
<p>Does anybody know how to curl to custome environment?</p>
|
[
{
"answer_id": 74529926,
"author": "Sakshi Gatyan",
"author_id": 15750473,
"author_profile": "https://Stackoverflow.com/users/15750473",
"pm_score": 2,
"selected": true,
"text": "https://dialogflow.googleapis.com/v2/projects/my-project-id/agent/environments/<env-name>/users/-/sessions/123456789:detectIntent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13742758/"
] |
74,514,714
|
<p>I have an array of accounts and there are two request one is to get domain and from that get data of account. if i have to get all accounts data how can i do it?</p>
<pre><code>accountsData = acounts.map(account => {
getDomain(account).then(domain => getData(domain))
})
Promises.all(accountsData).then(e => console.log(e))
</code></pre>
<p>Since the few request all failing so this is not working.</p>
<p>I have tried the above aproch and it not works when few request fails.</p>
|
[
{
"answer_id": 74529926,
"author": "Sakshi Gatyan",
"author_id": 15750473,
"author_profile": "https://Stackoverflow.com/users/15750473",
"pm_score": 2,
"selected": true,
"text": "https://dialogflow.googleapis.com/v2/projects/my-project-id/agent/environments/<env-name>/users/-/sessions/123456789:detectIntent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20302103/"
] |
74,514,719
|
<p>I have an <code>async</code> <code>axios</code> request:</p>
<pre><code> /*
|--------------------------------------------------------------------------
| Function : Get > User > Current Avatar
|--------------------------------------------------------------------------
*/
async function getUserCurrentAvatar() {
// Ajax URL
const ajax_url = process.env.NEXT_PUBLIC_FRONTEND_API_ROOT + 'user' + '/' + session.user.id + '/' + 'edit/avatar/getusercurrentavatar';
/*
|--------------------------------------------------------------------------
| AJAX > Request
|--------------------------------------------------------------------------
*/
await axios.post(ajax_url)
.then(response => {
setCurrentUserAvatarId(response.data.id);
setCurrentUserAvatarUrl(response.data.current_avatar);
}).catch((error) => {
// Error
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// console.log(error.response.data);
// console.log(error.response.status);
// console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the
// browser and an instance of
// http.ClientRequest in node.js
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
console.log(error.config);
});
}
</code></pre>
<p>and I called it in <code>useEffect()</code> like:</p>
<pre><code> /*
|--------------------------------------------------------------------------
| Use Effect 1
|--------------------------------------------------------------------------
*/
useEffect(() => {
// Session > Available
if(session) {
getUserCurrentAvatar();
}
}, [session]);
</code></pre>
<p>but I am getting the warning <code>Promise returned from getUserCurrentAvatar is ignored, Add '.then()'</code></p>
<p>my question is can I do side effects inside <code>.then()</code>?</p>
<p>Inside <code>async function getUserCurrentAvatar() { ... }</code> I set the <code>state</code> for:</p>
<pre><code> setCurrentUserAvatarId(response.data.id);
setCurrentUserAvatarUrl(response.data.current_avatar);
</code></pre>
<p>I need to perform a <code>sideEffect</code> after <code>currentUserAvatarUrl</code> state is set, I tried in <code>useEffect()</code> with <code>then()</code> but it does not work:</p>
<pre><code> /*
|--------------------------------------------------------------------------
| Use Effect 1
|--------------------------------------------------------------------------
*/
useEffect(() => {
// Session > Available
if(session) {
getUserCurrentAvatar().then(() => {
const fileName = 'myFile.jpg'
imageSrcToFile(currentUserAvatarUrl, fileName).then();
});
}
}, [session]);
</code></pre>
<p>the anonymous function in <code>then()</code> was never triggered, nothing in it works</p>
<p>but if I do it in another <code>useEffect()</code> as usual it works:</p>
<pre><code> /*
|--------------------------------------------------------------------------
| Use Effect 2
|--------------------------------------------------------------------------
*/
useEffect(() => {
const fileName = 'myFile.jpg'
imageSrcToFile(currentUserAvatarUrl, fileName).then();
}, [currentUserAvatarUrl]);
</code></pre>
<p>What is the use of <code>then()</code> then?
Why the IDE is giving me warning everytime to include <code>then()</code> after the <code>async</code> function call?</p>
<p><strong>EDIT</strong>: I tried:</p>
<pre><code> useEffect(() => {
// Session > Available
if(session) {
getUserCurrentAvatar().then((response) => {
alert(`Received response: ${JSON.stringify(response, null, 2)}`);
const fileName = 'myFile.jpg'
imageSrcToFile(currentUserAvatarUrl, fileName).then();
});
}
}, [session]);
</code></pre>
<p>but the <code>response</code> I got is <code>Received response: undefined</code></p>
|
[
{
"answer_id": 74529926,
"author": "Sakshi Gatyan",
"author_id": 15750473,
"author_profile": "https://Stackoverflow.com/users/15750473",
"pm_score": 2,
"selected": true,
"text": "https://dialogflow.googleapis.com/v2/projects/my-project-id/agent/environments/<env-name>/users/-/sessions/123456789:detectIntent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15469002/"
] |
74,514,723
|
<p>I have a dataset that looks something like this:</p>
<pre><code> id col1 col2 col3 col4
1 1 12 ABC Henry Alex 13 AB
2 2 123 12 David 344
3 3 John 567 Luke Huh8
4 4 123344567 abc 123 Paul 98
5 5 1345677. Sam 17df Tom
</code></pre>
<p><strong>Goal</strong>: For each row, I would like to take every cell that does not contain a numerical value, and create new columns from the existing values of that row:</p>
<pre><code> Name col1 col2 col3 col4
1 Henry 12 ABC <NA> <NA> 13 AB
2 Alex 12 ABC <NA> <NA> 13 AB
3 David 123 12 <NA> 344
4 John <NA> 567 <NA> Huh8
5 Luke <NA> 567 <NA> Huh8
6 Paul 123344567 abc 123 <NA> 98
7 Sam 1345677 <NA> 17df <NA>
8 Tom 1345677 <NA> 17df <NA>
</code></pre>
<p>Based on the nature of this question, I think the two following concepts can be used:</p>
<ul>
<li><p>To determine if a column contains a numerical value, the following code can be used: <code>grepl("\\d", my_data$col1)</code></p>
</li>
<li><p>I think some form of "pivot_wider" and "pivot_longer" might be applicable, but I am not sure exactly how to do this.</p>
</li>
</ul>
<p>Can someone please show me how to do this?</p>
<h2>Data</h2>
<pre><code>my_data <- structure(list(id = 1:5, col1 = c("12 ABC", "123", "John", "123344567",
"1345677."), col2 = c("Henry", "12", "567", "abc 123", "Sam"),
col3 = c("Alex", "David", "Luke", "Paul", "17df"), col4 = c("13 AB",
"344", "Huh8", "98", "Tom")), class = "data.frame", row.names = c(NA,
-5L))
</code></pre>
|
[
{
"answer_id": 74529926,
"author": "Sakshi Gatyan",
"author_id": 15750473,
"author_profile": "https://Stackoverflow.com/users/15750473",
"pm_score": 2,
"selected": true,
"text": "https://dialogflow.googleapis.com/v2/projects/my-project-id/agent/environments/<env-name>/users/-/sessions/123456789:detectIntent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13203841/"
] |
74,514,734
|
<p>I want to fit parent div height to fit it's child</p>
<p>that means I want height of parent div to fit red color</p>
<p>and green part will hide</p>
<p><a href="https://jsfiddle.net/zfpwb54L/" rel="nofollow noreferrer">https://jsfiddle.net/zfpwb54L/</a></p>
<pre><code><style>
.container {
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
width: 100%;
}
.section {
padding: 20px 0;
position: relative;
}
.style_content {
color: #27272a;
max-width: 700px;
position: relative;
text-align: center;
z-index: 9;
}
</style>
<div id="parent" style="background-color:green; position: relative; direction: rtl;width:fit-content;">
<div style="position: absolute; inset: 0px;"></div>
<div style="width: 280px;; ">
<div id="child" style="background:red;flex: 0 0 auto; width: 1400px; transform-origin: right top 0px; transform: matrix(0.2, 0, 0, 0.2, 0, 0);">
<section class="section">
<div class="style_content container">
<div><h1>Hello</h1></div>
<div><p>that is for test.that is for test.that is for test.that is for test.that is for test.
that is for test.that is for test.that is for test.that is for test.that is for test.that is for test.that is for test.that is for test.</p></div>
<a href="#" target="_blank">click me</a>
</div>
</section>
</div>
</div>
</div>
</code></pre>
|
[
{
"answer_id": 74529926,
"author": "Sakshi Gatyan",
"author_id": 15750473,
"author_profile": "https://Stackoverflow.com/users/15750473",
"pm_score": 2,
"selected": true,
"text": "https://dialogflow.googleapis.com/v2/projects/my-project-id/agent/environments/<env-name>/users/-/sessions/123456789:detectIntent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9779942/"
] |
74,514,750
|
<p>How can I print all the alphabet characters (A to Z, a to z)?</p>
<p>I did the following. It lets me print all the characters from A-Z and a-z but the problem is that I get the in-between ASCII characters that I want to filter.<br />
CX is expected to be set to 52 in a working program.</p>
<pre><code>ORG 100h
MOV AX,0B800H
MOV DS,AX
MOV BX,0000 ;SET BX REGISTER
MOV CX, 58 ;USED AS A COUNTER
MOV AL,'A'
MOV AH,0x0E
MOV DL, 41h
CMP AX, DX
JG UPPERCASE
UPPERCASE:
ADD DL, 1
CMP DX, 5Bh
JG LOWERCASE
JMP BACK
LOWERCASE:
ADD DL, 1
CMP DX, 60h
JG BACK
JL UPPERCASE
HLT
BACK:
MOV [BX],AX
ADD AL,1
ADD AH,1
ADD BX,2
LOOP UPPERCASE
</code></pre>
|
[
{
"answer_id": 74537228,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 2,
"selected": true,
"text": "CMP AX, DX\nCMP DX, 5Bh\nCMP DX, 60h\n"
},
{
"answer_id": 74554131,
"author": "rediska",
"author_id": 20551534,
"author_profile": "https://Stackoverflow.com/users/20551534",
"pm_score": 0,
"selected": false,
"text": "include emu8086.inc\nORG 100h \nMOV AX,0B800H \nMOV DS,AX\nMOV BX,0000 ;SET BX REGISTER\nMOV CX, 52 ;USED AS A COUNTER \nMOV AL,'A'\nMOV AH,0x0F \nCMP AL, 41h\nJMP BACK\n\nBACK:\n CMP AL,5Bh\n JE NOTLETTER\n\n JMP GO\n\nGO: \n MOV [BX],AX\n ADD AL,1\n ADD AH,17\n ADD BX,2\n LOOP BACK\n\nHLT\n \nNOTLETTER:\n CMP AL, 61h\n MOV AL, 61h\n printn \" \"\n JMP GO \n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514750",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20551534/"
] |
74,514,779
|
<p>This may be an extremely stupid question, but here goes:</p>
<p>Why can Dafny very this:</p>
<pre><code>var arr := new int[2];
arr[0], arr[1] := -1, -2;
assert exists k :: 0 <= k < arr.Length && arr[k] < 0;
</code></pre>
<p>but not this:</p>
<pre><code>var arr := new int[2];
arr[0], arr[1] := -1, 2;
assert exists k :: 0 <= k < arr.Length && arr[k] < 0;
</code></pre>
<p>I've traced an error in my bigger program back to this. I'm sure it's something minor that I overlooked, but I'd appreciate the help!</p>
|
[
{
"answer_id": 74515123,
"author": "James Wilcox",
"author_id": 438267,
"author_profile": "https://Stackoverflow.com/users/438267",
"pm_score": 3,
"selected": true,
"text": "arr[k]"
},
{
"answer_id": 74618566,
"author": "Clément",
"author_id": 695591,
"author_profile": "https://Stackoverflow.com/users/695591",
"pm_score": 2,
"selected": false,
"text": "type T\npredicate P(t: T)\n\nmethod ThisFails(t0: T, yes: T, no: T) requires P(yes) && !P(no) {\n var arr := new T[2](_ => t0);\n arr[0] := yes;\n arr[1] := no;\n assert exists k :: 0 <= k < arr.Length && P(arr[k]); // FAILS [:(]\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13484416/"
] |
74,514,782
|
<p>Hi everyone I am new to heroku and deploying websites online in general is pretty new to me.
Everytime I do a heroku push in the cmd line client, I get the error message that says : Error: Cannot find module './../.env' .</p>
<p>I have a .env file that contains my connection string for mongoDB and a secret key. I do not want to push that to the remote server. So I included it in the git.ignore file. I think that is what is causing the issue. It says it cannot find the .env file, I am assuming that is because it is not on git remotely. But how can I deploy the site then without having to push my .env file with information I do not want out to the public?? I do not want to have to push it to git for it to work because that defeats the purpose.</p>
<p>Before I created the .env file I had a config file with a module.exports object and it had the connection string and the secret key in it. But that did not work and I kept getting the same error which was at that time .config module not found. So I looked online and found tutorials that said if I install the dotenv package and use a .env file instead than that should work. But I am getting the exact same error just with the .env file instead. So I see no difference there.</p>
<p>Here are the index.js file and the package.json file. The only thing that is in the .env file is my database connection string and my secret key.</p>
<p>index.js file
`</p>
<pre><code>
const dotenv = require("dotenv");
dotenv.config({ path: "./.env" });
const { ApolloServer, PubSub } = require("apollo-server");
const mongoose = require("mongoose");
const typeDefs = require("./graphql/typeDefs");
const resolvers = require("./graphql/resolvers");
const pubsub = require("graphql-subscriptions");
const PORT = process.env.port || 5000;
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ req, pubsub }),
});
mongoose
.connect(process.env.MONGODB_URI, { useNewUrlParser: true })
.then(() => {
console.log("MongoDB Connected");
return server.listen({ port: PORT });
})
.then((res) => {
console.log(`Server running at ${res.url}`);
})
.catch((err) => {
console.error(err);
});
</code></pre>
<p>`</p>
<p>Package.json file
`</p>
<pre><code>
{
"name": "social-media-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "node index",
"start": "node index"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server": "^3.10.2",
"bcryptjs": "^2.4.3",
"dotenv": "^16.0.3",
"graphql": "^16.6.0",
"graphql-subscriptions": "^2.0.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.6.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
</code></pre>
<p>`</p>
<p>Here is the error message I keep getting in the client when I push it. I put it in a pastebin because it is quite long.</p>
<p><a href="https://pastebin.com/DC0q27aA" rel="nofollow noreferrer">https://pastebin.com/DC0q27aA</a></p>
|
[
{
"answer_id": 74514868,
"author": "Kasra Karami",
"author_id": 8425590,
"author_profile": "https://Stackoverflow.com/users/8425590",
"pm_score": 1,
"selected": false,
"text": "Reveal Config Vars"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19036311/"
] |
74,514,800
|
<p><a href="https://i.stack.imgur.com/6GCck.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>I've been having problem importing another data from another table in-order to create a new record of log-in</p>
<pre><code>ConnectToDB()
sql = "insert into monitoring (id_num, fname, lname, status, floor_level) VALUES (@num),(@name),(@lname),(@stat),(@lev)"
cmd = New MySqlCommand(sql, cn)
With cmd
.Parameters.AddWithValue("@name", TextBox2.Text)
.Parameters.AddWithValue("@lname", TextBox3.Text)
.Parameters.AddWithValue("@stat", TextBox5.Text)
.Parameters.AddWithValue("@lev", lev)
.ExecuteNonQuery()
End With
</code></pre>
<p>This is what I tried yet I keep getting a SQL error</p>
<p>and now this is what I kept getting after I fixed my SQL syntax
<a href="https://i.stack.imgur.com/xnIcI.png" rel="nofollow noreferrer">enter image description here</a> It says An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Column count doesn't match value count at row 1 however if I count my database column it is fit and same amount in my query</p>
|
[
{
"answer_id": 74514868,
"author": "Kasra Karami",
"author_id": 8425590,
"author_profile": "https://Stackoverflow.com/users/8425590",
"pm_score": 1,
"selected": false,
"text": "Reveal Config Vars"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19101467/"
] |
74,514,801
|
<p>This is the old way of calling <code>NavigationLink</code> on <code>Button</code>s</p>
<pre><code>struct ContentView: View {
@State private var selection: String? = nil
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: View1(), tag: "tag1", selection: $selection) {
EmptyView()
}
NavigationLink(destination: NotView1(), tag: "tag2", selection: $selection) {
EmptyView()
}
Button("Do work then go to View1") {
// do some work that takes about 1 second
mySleepFunctionToSleepOneSecond()
selection = "tag1"
}
Button("Instantly go to NotView1") {
selection = "tag2"
}
}
.navigationTitle("Navigation")
}
}
}
</code></pre>
<p>This code works perfectly. It can go to different <code>View</code> targets depending on which button is clicked. Not only that, it guarantees all work is done <strong>BEFORE</strong> navigating to the target view. However, the only issue is that <code>'init(destination:tag:selection:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView</code></p>
<p>I get <code>NavigationStack</code> is awesome and such. But how can I translate the code to use the new <code>NavigationStack</code> + <code>NavigationLink</code>. Especially, how can I make sure work is done <strong>Before</strong> navigation?</p>
|
[
{
"answer_id": 74514868,
"author": "Kasra Karami",
"author_id": 8425590,
"author_profile": "https://Stackoverflow.com/users/8425590",
"pm_score": 1,
"selected": false,
"text": "Reveal Config Vars"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10349656/"
] |
74,514,826
|
<p>My DataFrame:</p>
<pre><code>Col X Col Y ID Value
A a 'r' 3
A a 'b' 2
A a 'c' 1
B b 'd' 5
B b 's' 6
B b 'd' 7
</code></pre>
<p>Output required:</p>
<pre><code>Col X Col Y Out
A a {'r':3, 'b':2, 'c':1}
B b {'d': 5, 's': 6, 'd':7}
</code></pre>
<p>Approach tried so far:</p>
<pre><code>df = df.set_index(['Col X', 'Col Y', 'ID']).Value
dict_column = {k: df.xs((k, v)).to_dict() for k,v,v2 in df.index}
</code></pre>
|
[
{
"answer_id": 74514872,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 2,
"selected": true,
"text": "GroupBy.apply"
},
{
"answer_id": 74514883,
"author": "Nuri Taş",
"author_id": 19255749,
"author_profile": "https://Stackoverflow.com/users/19255749",
"pm_score": 0,
"selected": false,
"text": "pd.Series"
},
{
"answer_id": 74514885,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 0,
"selected": false,
"text": "groupby.apply"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17900863/"
] |
74,514,840
|
<p>Please refer this
<a href="https://i.stack.imgur.com/qRA5K.png" rel="nofollow noreferrer">Code input</a></p>
<p>This code doesn't give the expected output</p>
<pre><code>class User{
protected $name;
protected $age;
public function __construct($name, $age){
$this->name = $name;
$this->age = $age;
}
}
class Customer extends User{
private $balance;
public function __construct($name, $age, $balance){
$this->balance = $balance;
}
public function pay($amount){
return $this->name . ' paid $' . $amount;
}
}
$customer1 = new Customer('Adithya', 23, 50);
echo $customer1->pay(100);
</code></pre>
<p>It only gives this<br />
Can someone please explain the reason?</p>
|
[
{
"answer_id": 74514921,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": false,
"text": "parent::__construct($name, $age);\n"
},
{
"answer_id": 74515589,
"author": "penn ",
"author_id": 19101058,
"author_profile": "https://Stackoverflow.com/users/19101058",
"pm_score": -1,
"selected": true,
"text": " class Customer extends User{\n private $balance;\n\n public function __construct($name, $age, $balance){\n $this->balance = $balance;\n parent::__construct($name,$age,$balance);\n }\n\n public function pay($amount){\n return $this->name . ' paid $' . $amount;\n }\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514840",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16098324/"
] |
74,514,851
|
<p>Basically I am using react-router(version 5) to pass data, however I can't access the state that I passed. Here is the code where it routes from:</p>
<pre><code>export default function MarketsList(props) {
const history = useHistory();
function changePage(sym, id) {
history.push({ pathname: `/${sym}`, state: { id: id } })
}
</code></pre>
<p>how do I access it from the other page? I tried this.state.id but it doesn't work.
here is the code for the other page just in case.</p>
<pre><code>export default function Symgraph(props) {
useEffect(() => {
}, []);
const { sym} = useParams();
return (
<div className='main-chart mb15' >
<ThemeConsumer>
{({ data }) => {
return data.theme === 'light' ? (
<AdvancedChart
widgetProps={{
theme: 'light',
symbol: 'OKBUSDT',
allow_symbol_change: false,
toolbar_bg: '#fff',
height: 550,
details: 'true',
style: '3',
}}
/>
) : (
<AdvancedChart
widgetProps={{
theme: 'dark',
symbol: 'OKBUSDT',
allow_symbol_change: false,
toolbar_bg: '#000',
height: 550,
details: 'true',
style: '3',
}}
/>
);
}}
</ThemeConsumer>
<h1>{sym},{this.state.id}</h1>
</div>
)
}
</code></pre>
|
[
{
"answer_id": 74514921,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": false,
"text": "parent::__construct($name, $age);\n"
},
{
"answer_id": 74515589,
"author": "penn ",
"author_id": 19101058,
"author_profile": "https://Stackoverflow.com/users/19101058",
"pm_score": -1,
"selected": true,
"text": " class Customer extends User{\n private $balance;\n\n public function __construct($name, $age, $balance){\n $this->balance = $balance;\n parent::__construct($name,$age,$balance);\n }\n\n public function pay($amount){\n return $this->name . ' paid $' . $amount;\n }\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10969500/"
] |
74,514,880
|
<p>I want to change the label of the "No Filter" option to "Sin Filtro" like an spanish translation. I only know about the FilterMatchMode from FilterService to change the label of the filter match modes, like that:</p>
<pre><code>export const FilterMatch = [
{ label: "Empieza con", value: FilterMatchMode.STARTS_WITH },
{ label: "Termina en", value: FilterMatchMode.ENDS_WITH },
];
</code></pre>
<p>And by using the [matchModeOptions] property in a p-columnFilter, I can make the next column filter options with the changes from the code above:</p>
<p><a href="https://i.stack.imgur.com/hLLq3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hLLq3.png" alt="enter image description here" /></a></p>
<p>But I also want to change the "No Filter" option label to "Sin Filtro" marked in the red rectangle, I don't know how. Any help is welcome.</p>
|
[
{
"answer_id": 74514921,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": false,
"text": "parent::__construct($name, $age);\n"
},
{
"answer_id": 74515589,
"author": "penn ",
"author_id": 19101058,
"author_profile": "https://Stackoverflow.com/users/19101058",
"pm_score": -1,
"selected": true,
"text": " class Customer extends User{\n private $balance;\n\n public function __construct($name, $age, $balance){\n $this->balance = $balance;\n parent::__construct($name,$age,$balance);\n }\n\n public function pay($amount){\n return $this->name . ' paid $' . $amount;\n }\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19877806/"
] |
74,514,886
|
<p>I'm trying to find out if my use of 'const' is appropriate given the behavior I am seeing.</p>
<pre><code>function showInstructions() {
const againText = (clickCounter > 0) ? "again " : "";
my2DContext.fillText("Click " + againText + "to try to do the thing", myCanvas.clientWidth / 2, myCanvas.clientHeight / 2);
}
</code></pre>
<p>The first time this function is called, clickCounter is 0, and it displays:</p>
<blockquote>
<p>"Click to try to do the thing"</p>
</blockquote>
<p>called later, when clickCounter > 0, the function displays:</p>
<blockquote>
<p>"Click again to try to do the thing"</p>
</blockquote>
<p>This works as intended.</p>
<p>Is this an appropriate use of 'const'? Should this be the expected behavior? Does it match other languages?</p>
|
[
{
"answer_id": 74514948,
"author": "Bergi",
"author_id": 1048572,
"author_profile": "https://Stackoverflow.com/users/1048572",
"pm_score": 2,
"selected": true,
"text": "clickCounter"
},
{
"answer_id": 74515032,
"author": "Unclebigay",
"author_id": 7953084,
"author_profile": "https://Stackoverflow.com/users/7953084",
"pm_score": 0,
"selected": false,
"text": "againText"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3669691/"
] |
74,514,914
|
<p><strong>My "ListView" not showing inside "TabBar".</strong></p>
<p>drive.google.com/file/d/1MLB7oizJ468V1SmCO_IsjL6OaoGhUAPd/… ----- <strong>List Page Code</strong>
drive.google.com/file/d/1d-iRa14-DupdLo3QdHd_iCHFkGi-_HD6/… <strong>TabBar Code</strong></p>
<p><strong>"TabBar" Section code:</strong>
<a href="https://i.stack.imgur.com/m3q1L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m3q1L.png" alt="enter image description here" /></a></p>
<p><strong>"ListView" section code:</strong>
<a href="https://i.stack.imgur.com/FsF2S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FsF2S.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74514948,
"author": "Bergi",
"author_id": 1048572,
"author_profile": "https://Stackoverflow.com/users/1048572",
"pm_score": 2,
"selected": true,
"text": "clickCounter"
},
{
"answer_id": 74515032,
"author": "Unclebigay",
"author_id": 7953084,
"author_profile": "https://Stackoverflow.com/users/7953084",
"pm_score": 0,
"selected": false,
"text": "againText"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11635379/"
] |
74,514,936
|
<pre><code> let obj1 ={
fName : 'Ayush',
lName : 'Singh',
city: 'Asansol',
getName : function(){
console.log(`I am ${this.fName} ${this.lName} from ${this.city}`)
}
}
let obj2 = {
fName : 'Aman'
}
obj2.__proto__ = obj1;
console.log(obj1.getName())
obj2.getName()
console.log(obj2.__proto__.getName())
console.log(obj1.__proto__.getName())
</code></pre>
<p>Here I am trying to check how <strong>proto</strong> works. Why can't I access of obj1.<strong>proto</strong>.getName</p>
|
[
{
"answer_id": 74514948,
"author": "Bergi",
"author_id": 1048572,
"author_profile": "https://Stackoverflow.com/users/1048572",
"pm_score": 2,
"selected": true,
"text": "clickCounter"
},
{
"answer_id": 74515032,
"author": "Unclebigay",
"author_id": 7953084,
"author_profile": "https://Stackoverflow.com/users/7953084",
"pm_score": 0,
"selected": false,
"text": "againText"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559948/"
] |
74,514,966
|
<p>I have an excel table (sample.xlsx) which contains 3 sheets ('Sheet1','Sheet2','Sheet3').
Now I have read all the sheets and combine them into one dataframe.</p>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
data_df = pd.concat(pd.read_excel("sample.xlsx", header=None, index_col=None, sheet_name=None))
</code></pre>
<p>data_df looks like this:</p>
<pre><code> 0 1 2
Sheet1 0 val1 val2 val3
1 val11 val21 val31
Sheet2 0 val1 val2 val3
1 val11 val21 val31
Sheet3 0 val1 val2 val3
1 val11 val21 val31
</code></pre>
<p>Is there any way to create a new dataframe which has the same shape with data_df but each cell value is the cell position info?</p>
<p>I have tried to get multiple index:</p>
<pre class="lang-py prettyprint-override"><code>multi_index = data_df.index.levels[:]
</code></pre>
<p>and I get:</p>
<pre class="lang-py prettyprint-override"><code>[['Sheet1', 'Sheet2', 'Sheet3'], [0, 1]]
</code></pre>
<p>But I don't know how to use these data to create a new dataframe like this:</p>
<pre><code> 0 1 2
0 Sheet1 - A1 Sheet1 - B1 Sheet1 - C1
1 Sheet1 - A2 Sheet1 - B2 Sheet1 - C2
2 Sheet2 - A1 Sheet2 - B1 Sheet2 - C1
3 Sheet2 - A2 Sheet2 - B2 Sheet2 - C2
4 Sheet3 - A1 Sheet3 - B1 Sheet3 - C1
5 Sheet3 - A2 Sheet3 - B2 Sheet3 - C2
</code></pre>
<p>Thanks in advance!</p>
|
[
{
"answer_id": 74516598,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 2,
"selected": true,
"text": "data_df"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14636214/"
] |
74,514,976
|
<p>I have a dataframe like this</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Value.</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>08/08/2009</td>
</tr>
<tr>
<td>A</td>
<td>09/12/2021</td>
</tr>
<tr>
<td>A</td>
<td>05/10/2022</td>
</tr>
<tr>
<td>A</td>
<td>06/09/2022</td>
</tr>
<tr>
<td>A</td>
<td>07/08/2022</td>
</tr>
</tbody>
</table>
</div>
<p>I need output like</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>VALUE</th>
<th>DATE</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>05/10/2022</td>
</tr>
<tr>
<td>A</td>
<td>06/09/2022</td>
</tr>
<tr>
<td>A</td>
<td>07/08/2022</td>
</tr>
</tbody>
</table>
</div>
<p>We have to print a latest year with all month data present in the date column .please refer output table.</p>
<p>i used SQL query like</p>
<p>Select Top 10 * from table where
Order by (Date) DESC;</p>
<p>The max() select only one date so that didn't help me</p>
<p>But didn't get expected answer.
Can please someone help me with the query ?</p>
|
[
{
"answer_id": 74516598,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 2,
"selected": true,
"text": "data_df"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19606332/"
] |
74,514,985
|
<p>I'm trying to calculate the number of rolls it takes to go broke, and the amount of rolls that would have left you with the most money. The program is split into several functions outside of main (not my choice) so that makes it more difficult for me.</p>
<p>I'm very new to python, and this is an exercise for school. I'm just not really sure where to go from here, and I realize I'm probably doing some of this wrong. Here's the code I have so far:</p>
<pre><code>import random
def displayHeader(funds):
print ("--------------------------")
print ("--------------------------")
print ("- Lucky Sevens -")
print ("--------------------------")
print ("--------------------------")
funds = int(input("How many dollars do you have? "))
def rollDie(newFunds):
#this function is supposed to simulate the roll of two die and return results
while funds > 0:
diceRoll = random.randint(1,6)
totalRoll = (diceRoll + diceRoll)
if totalRoll == 7:
funds = funds + 4
else:
funds = funds - 1
if funds == 0:
newFunds = funds
def displayResults():
#this function is supposed to display the final results.
#the number of rolls, the number of rolls you should have stopped at, and the max amount of money you would have had.
def main():
#everything gathered from the last function would be printed here.
main()
</code></pre>
|
[
{
"answer_id": 74516598,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 2,
"selected": true,
"text": "data_df"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,514,987
|
<p>I'm using ReactJs to build a video call app.
I also up agora-token-service into railway. Testing is oke. But when i try to fetch data, it's has a ploblem, I also tried to fix it but it didn't work. mode: 'no-cors also didn't work</p>
<p><a href="https://i.stack.imgur.com/zBIKQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zBIKQ.png" alt="enter image description here" /></a></p>
<p>i need a solution please!</p>
|
[
{
"answer_id": 74516598,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 2,
"selected": true,
"text": "data_df"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74514987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20559916/"
] |
74,515,037
|
<p>I am trying to filter out groups based on the condition that the group does not contain a Submit or Cancel. Please see the following dataset:</p>
<pre><code>df <- structure(list(
session = c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3),
event = c("pg1", "click1", "submit", "pg2", "click1", "click2", "cancel", "pg1", "click1", "click3")),
.Names = c("session", "event"),
row.names = c(NA, -10L),
class = "data.frame")
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>session</th>
<th>event</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>pg1</td>
</tr>
<tr>
<td>1</td>
<td>click1</td>
</tr>
<tr>
<td>1</td>
<td>submit</td>
</tr>
<tr>
<td>2</td>
<td>pg2</td>
</tr>
<tr>
<td>2</td>
<td>click1</td>
</tr>
<tr>
<td>2</td>
<td>click2</td>
</tr>
<tr>
<td>2</td>
<td>cancel</td>
</tr>
<tr>
<td>3</td>
<td>pg1</td>
</tr>
<tr>
<td>3</td>
<td>click1</td>
</tr>
<tr>
<td>3</td>
<td>click3</td>
</tr>
</tbody>
</table>
</div>
<p>I would like to filter out all the sessions that contain a submit or cancel. The resulting dataset should look this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>session</th>
<th>event</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>pg1</td>
</tr>
<tr>
<td>3</td>
<td>click1</td>
</tr>
<tr>
<td>3</td>
<td>click3</td>
</tr>
</tbody>
</table>
</div>
<p>This code does not work:</p>
<pre><code>df %>%
group_by(session) %>%
filter(any (event != "submit" | event != "cancel"))
</code></pre>
|
[
{
"answer_id": 74516598,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 2,
"selected": true,
"text": "data_df"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2845095/"
] |
74,515,050
|
<p>I have this component called <strong>SpecialComp</strong> that is being passed as a prop to <strong>MyComp</strong> . My question is how to pass all of the props from <strong>SpecialComp</strong> (color, size, weight) to MyComp so then I can override the attributes set in MyComp? In other words how can I have access to SpecialComp’s props inside of MyComp?</p>
<pre><code><MyComp customcomp ={<SpecialComp color=‘green’ size=‘20’ weight=‘bold’/>} />
export const MyComp = ({customcomp}) => {
return (
<div>
{React.cloneElement(customcomp, {color: ‘red’})}
</div>
);
}
</code></pre>
|
[
{
"answer_id": 74515173,
"author": "Unclebigay",
"author_id": 7953084,
"author_profile": "https://Stackoverflow.com/users/7953084",
"pm_score": 0,
"selected": false,
"text": "import React from \"react\";\n\nexport const App = () => {\n const [specialProps, setSpecialProps] = useState({\n color: \"green\",\n size: \"20\",\n weight: \"bold\",\n }); // make the properties as state\n\n return (\n <MyComp\n customComponentStyles={specialProps} // you can pass it here\n customComponent={\n <SpecialComp\n color={specialProps.color} // you can pass it here too\n size={specialProps.size}\n weight={specialProps.weight}\n />\n }\n />\n );\n};\n\nexport const MyComp = ({ customComponentStyles, customComponent }) => { // access the same prop here as well\n return <div>{React.cloneElement(customcomp, { color: \"red\" })}</div>;\n};\n"
},
{
"answer_id": 74515252,
"author": "Tehila",
"author_id": 16142839,
"author_profile": "https://Stackoverflow.com/users/16142839",
"pm_score": 2,
"selected": true,
"text": "customcomp.props"
},
{
"answer_id": 74515361,
"author": "Shreyansh Gupta",
"author_id": 18046485,
"author_profile": "https://Stackoverflow.com/users/18046485",
"pm_score": 0,
"selected": false,
"text": "<MyComp customcomp ={<SpecialComp color=‘green’ size=‘20’ weight=‘bold’/>} />\n\nexport const MyComp = ({customcomp}) => {\n return (\n <div>\n {React.cloneElement(customcomp, {...customcomp.props,color: ‘red’})}\n </div>\n );\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5245070/"
] |
74,515,060
|
<p>AFAIK, data member of enclosing class are also visible in nested class.</p>
<pre><code>struct A {
struct B {
int arr[n]; // how come n is not visible here, but it is visible in next statement.
int x = n;
};
static const int n = 5;
};
</code></pre>
<p><a href="https://godbolt.org/z/zvrhqjdn6" rel="nofollow noreferrer">see live demo here</a></p>
|
[
{
"answer_id": 74515135,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 3,
"selected": true,
"text": "int x = n;"
},
{
"answer_id": 74515182,
"author": "MZM",
"author_id": 20551381,
"author_profile": "https://Stackoverflow.com/users/20551381",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\nusing namespace std;\n\n struct A {\n struct B {\n int *arr = new int[n]();\n int x = n;\n };\n \n static const int n = 5;\n };\n int main() {\n cout << \"Hello World!\";\n return 0;\n }\n"
},
{
"answer_id": 74515235,
"author": "Özgür Murat Sağdıçoğlu",
"author_id": 5106317,
"author_profile": "https://Stackoverflow.com/users/5106317",
"pm_score": 0,
"selected": false,
"text": "int arr[n]"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20038708/"
] |
74,515,061
|
<p>Assume I have the following domain object:</p>
<pre><code>public class MyObj {
private Long id;
private Long relationId;
private Long seq;
// getters
}
</code></pre>
<p>There is a list <code>List<MyObj> list</code>. I want to create a Map by grouping the data by <code>relationId</code> (*key) and sort values (value is a list of <code>id</code>).</p>
<p>My code without sort values:</p>
<pre><code>List<MyObj> list = getMyObjs();
// key: relationId, value: List<Long> ids (needs to be sorted)
Map<Long, List<Long>> map = list.stream()
.collect(Collectors.groupingBy(
MyObj::getRelationId,
Collectors.mapping(MyObj::getId, toList())
));
</code></pre>
<pre><code>public class MyObjComparator{
public static Comparator<MyObj> compare() {
...
}
}
</code></pre>
<p>I have created compare method <code>MyObjComparator::compare</code>, my question is how to sort this map's values in the above stream.</p>
|
[
{
"answer_id": 74515135,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 3,
"selected": true,
"text": "int x = n;"
},
{
"answer_id": 74515182,
"author": "MZM",
"author_id": 20551381,
"author_profile": "https://Stackoverflow.com/users/20551381",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\nusing namespace std;\n\n struct A {\n struct B {\n int *arr = new int[n]();\n int x = n;\n };\n \n static const int n = 5;\n };\n int main() {\n cout << \"Hello World!\";\n return 0;\n }\n"
},
{
"answer_id": 74515235,
"author": "Özgür Murat Sağdıçoğlu",
"author_id": 5106317,
"author_profile": "https://Stackoverflow.com/users/5106317",
"pm_score": 0,
"selected": false,
"text": "int arr[n]"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8230537/"
] |
74,515,066
|
<p>But getting this error</p>
<pre><code>Error in setGeneric("+", function(x, y) standardGeneric("+")) :
'+' dispatches internally; methods can be defined, but the generic function is implicit, and cannot be changed.
Execution halted
</code></pre>
<p>after running the below code</p>
<pre><code>> setClass("string", representation(
+ data = "character"))
>
> setGeneric("+", function(x, y) standardGeneric("+"))
setMethod("+", "string", "string", function(x, y) {
new("string", data = paste0(x@data, y@data)) })
</code></pre>
|
[
{
"answer_id": 74515135,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 3,
"selected": true,
"text": "int x = n;"
},
{
"answer_id": 74515182,
"author": "MZM",
"author_id": 20551381,
"author_profile": "https://Stackoverflow.com/users/20551381",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\nusing namespace std;\n\n struct A {\n struct B {\n int *arr = new int[n]();\n int x = n;\n };\n \n static const int n = 5;\n };\n int main() {\n cout << \"Hello World!\";\n return 0;\n }\n"
},
{
"answer_id": 74515235,
"author": "Özgür Murat Sağdıçoğlu",
"author_id": 5106317,
"author_profile": "https://Stackoverflow.com/users/5106317",
"pm_score": 0,
"selected": false,
"text": "int arr[n]"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20485468/"
] |
74,515,105
|
<p>Suppose i have package named src</p>
<pre><code> src
- __init__.py
- app.py
</code></pre>
<p>__init__.py</p>
<pre><code> ___version__ = '0.1.0'
import os
ENTRY_DIR = os.path.dirname(__file__)
BASE_DIR = os path.dirname(ENTRY_DIR)
DATA_DIR = os.path.join(BASE_DIR, 'data')
</code></pre>
<p>how can i access the variable DATA_DIR in app.py</p>
<p>I tried like this,</p>
<p>app.py</p>
<pre><code> from src import DATA_DIR
print(DATA_DIR)
</code></pre>
<p>It didn't worked, i got an error.</p>
<blockquote>
<p>ModuleNotFoundError: No module named 'src'</p>
</blockquote>
<p>How can i acces the variable inside the app module</p>
|
[
{
"answer_id": 74515538,
"author": "Raida",
"author_id": 13763683,
"author_profile": "https://Stackoverflow.com/users/13763683",
"pm_score": 3,
"selected": true,
"text": "__init__.py"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12108866/"
] |
74,515,149
|
<p>We are running AKS multi cluster environments with high uptime SLA's. We are more causious about
tier of cluster where we don't know on which our clusters are running.
Can anyone suggest where we can verify the current tier?
Suggest where we can change that from free to paid service either in portal or CLI?</p>
<p>So that our clusters will get uptime SLAs. Appreciate your responses!</p>
<p>Azure Kubernetes Cluster tier change via CLI</p>
|
[
{
"answer_id": 74515729,
"author": "Swarna Anipindi",
"author_id": 20264791,
"author_profile": "https://Stackoverflow.com/users/20264791",
"pm_score": 2,
"selected": true,
"text": " az aks get-credentials --resource-group <resourcegroup Name> --name <cluster Name>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20288005/"
] |
74,515,204
|
<p>A third-party js script is installed on the site, which adds a form to html. Iframe is not used.</p>
<p>I want to add a new class for an element that is generated by a third-party script, but nothing happens.
Please help me understand why.</p>
<pre><code>var elem = document.querySelector('.CustomAccountField_689153');
window.addEventListener('load', (event) => {
elem.classList.add('dropdown');
});
</code></pre>
|
[
{
"answer_id": 74515729,
"author": "Swarna Anipindi",
"author_id": 20264791,
"author_profile": "https://Stackoverflow.com/users/20264791",
"pm_score": 2,
"selected": true,
"text": " az aks get-credentials --resource-group <resourcegroup Name> --name <cluster Name>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20560112/"
] |
74,515,213
|
<p>I have a ListView builder in my Flutter app that does some heavy computation for each item in the list, so it can take some time to populate new elements. The computation is all synchronous code. I'd like to add a spinner while the list is adding new elements, but don't want to change all the computation code. So I think that means making the itemBuilder itself async, but I'm not sure how to do this. Is it possible?</p>
<p>Below is the code I had, trying to use the EasyLoading package, but that didn't work, because the APIs from EasyLoading are async, which wasn't mentioned in the description.</p>
<pre class="lang-dart prettyprint-override"><code>class Matches extends StatefulWidget {
final Iterator<String> _match;
Matches(this._matcher);
@override
MatchesState createState() => MatchesState(_match);
}
class MatchesState extends State<Matches> {
final Iterator<String> _matcher;
final _matches = <String>[];
MatchesState(this._matcher);
_next() {
// This is async so doesn't work
EasyLoading.show(status: 'Searching...');
// Get the next ten results
for (var i = 0; i < 10; i++) {
// _matcher is a synchronous iterator that does some
// computationally intensive work each iteration.
if (_matcher.moveNext()) {
_matches.add(_matcher.current);
EasyLoading.showProgress(0.1 * i, status: 'Searching...');
} else {
EasyLoading.showSuccess('Searching...');
break;
}
}
EasyLoading.dismiss(animation: false);
}
Widget _buildMatches() {
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i) {
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _matches.length) {
_next();
}
final row = (index < _matches.length) ? _matches[index] : '';
return ListTile(title: Text(row));
}
);
}
@override
Widget build(BuildContext context) {
return FlutterEasyLoading(
child: Scaffold(
appBar: AppBar(
title: Text(TITLE),
),
body: _buildMatches(),
));
}
}
</code></pre>
<p>It seems like I need to use a FutureBuilder. I found a good article here <a href="https://blog.devgenius.io/understanding-futurebuilder-in-flutter-491501526373" rel="nofollow noreferrer">https://blog.devgenius.io/understanding-futurebuilder-in-flutter-491501526373</a> but it (like most I have seen) assumes that all the results are computed before the list is populated, whereas I want to build my list lazily as the user scrolls through it. So I need something like FutureListItemBuilder, if that only existed.</p>
<p>Update: I found this article which is closer to what I want to do; going to see if I can make it work for me: <a href="https://medium.com/theotherdev-s/getting-to-know-flutter-list-lazy-loading-1cb0ed5de91f" rel="nofollow noreferrer">https://medium.com/theotherdev-s/getting-to-know-flutter-list-lazy-loading-1cb0ed5de91f</a></p>
|
[
{
"answer_id": 74515729,
"author": "Swarna Anipindi",
"author_id": 20264791,
"author_profile": "https://Stackoverflow.com/users/20264791",
"pm_score": 2,
"selected": true,
"text": " az aks get-credentials --resource-group <resourcegroup Name> --name <cluster Name>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/968133/"
] |
74,515,214
|
<p>I am very new to flutter. I have to make an app that send the device location every 10 seconds, even if app is minimised and gets killed by the user.
After that data i have to make a socket connection and a http post if(socket fails).</p>
<p>The app should must work with both Android and IOS.
Is it possible to do in flutter?</p>
|
[
{
"answer_id": 74515729,
"author": "Swarna Anipindi",
"author_id": 20264791,
"author_profile": "https://Stackoverflow.com/users/20264791",
"pm_score": 2,
"selected": true,
"text": " az aks get-credentials --resource-group <resourcegroup Name> --name <cluster Name>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13572964/"
] |
74,515,224
|
<p>I have PageView with photo, and i want open photos from my PageView to fullscreen, when i click on photo, how can i make it?</p>
<p>my code:</p>
<pre><code>class BannerItem extends StatelessWidget {
final AppBanner appBanner;
const BannerItem({Key? key, required this.appBanner}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 14.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: NetworkImage(appBanner.url), fit: BoxFit.cover)),
);
}
}
</code></pre>
<p><a href="https://i.stack.imgur.com/UoEKs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UoEKs.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74515729,
"author": "Swarna Anipindi",
"author_id": 20264791,
"author_profile": "https://Stackoverflow.com/users/20264791",
"pm_score": 2,
"selected": true,
"text": " az aks get-credentials --resource-group <resourcegroup Name> --name <cluster Name>"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20320364/"
] |
74,515,230
|
<p>I have installed <code>Spark 3.3.1</code> and it was running previously with both <code>spark-shell</code> and <code>pyspark</code> commands. But after I installed <code>Hadoop 3.3.1</code> it seems that <code>pyspark</code> command doesn't work properly and this is the result of running that:</p>
<pre><code>C:\Users\A>pyspark2 --num-executors 4 --executor-memory 1g
[I 2022-11-20 22:36:09.100 LabApp] JupyterLab extension loaded from C:\Users\A\AppData\Local\Programs\Python\Python311\Lib\site-packages\jupyterlab
[I 2022-11-20 22:36:09.100 LabApp] JupyterLab application directory is C:\Users\A\AppData\Local\Programs\Python\Python311\share\jupyter\lab
[I 22:36:09.107 NotebookApp] Serving notebooks from local directory: C:\Users\A
[I 22:36:09.107 NotebookApp] Jupyter Notebook 6.5.2 is running at:
[I 22:36:09.107 NotebookApp] http://localhost:8888/?token=0fca9f0378976c7af19886970c9e801ac27a8d1a209528db
[I 22:36:09.108 NotebookApp] or http://127.0.0.1:8888/?token=0fca9f0378976c7af19886970c9e801ac27a8d1a209528db
[I 22:36:09.108 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 22:36:09.189 NotebookApp]
To access the notebook, open this file in a browser:
file:///C:/Users/A/AppData/Roaming/jupyter/runtime/nbserver-8328-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=0fca9f0378976c7af19886970c9e801ac27a8d1a209528db
or http://127.0.0.1:8888/?token=0fca9f0378976c7af19886970c9e801ac27a8d1a209528db
0.01s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
</code></pre>
<p>It opens the <code>Jupyter notebook</code> but the Spark logo doesn't shown and Python shell wouldn't be available as before in <code>CMD</code>. But <code>spark-shell</code> still works as below:</p>
<pre><code>Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Spark context Web UI available at http://168.150.8.52:4040
Spark context available as 'sc' (master = local[*], app id = local-1669062477403).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 3.3.1
/_/
Using Scala version 2.12.15 (OpenJDK 64-Bit Server VM, Java 11.0.16.1)
Type in expressions to have them evaluated.
Type :help for more information.
scala> 22/11/21 12:28:12 WARN ProcfsMetricsGetter: Exception when trying to compute pagesize, as a result reporting of ProcessTree metrics is stopped
scala>
</code></pre>
<p>EDIT: These are all my related system variables and paths:</p>
<pre><code>JAVA_HOME : C:\ProgramData\OpenJDK
HADOOP_HOME : C:\ProgramData\hadoop
SPARK_HOME : C:\ProgramData\spark
PYSPARK_PYTHON : python
PYSPARK_DRIVER_PYTHON : jupyter
PYSPARK_DRIVER_PYTHON_OPTS : notebook
PYTHONPATH : %SPARK_HOME%\python;%SPARK_HOME%\python\lib\py4j-0.10.9.5-src.zip;%PYTHONPATH%
</code></pre>
<p>system paths:</p>
<pre><code>C:\ProgramData\OpenJDK\bin
C:\ProgramData\spark\bin
C:\ProgramData\hadoop\bin
C:\ProgramData\hadoop\sbin
C:\Users\A\AppData\Local\Programs\Python\Python311
C:\Users\A\AppData\Local\Programs\Python\Python311\Lib\site-packages
</code></pre>
|
[
{
"answer_id": 74534219,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 0,
"selected": false,
"text": "echo $PATH"
},
{
"answer_id": 74534445,
"author": "OneCricketeer",
"author_id": 2308683,
"author_profile": "https://Stackoverflow.com/users/2308683",
"pm_score": 1,
"selected": false,
"text": "pyspark2.cmd"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20551429/"
] |
74,515,266
|
<p>I am using OpenSSL to encode base64 string.</p>
<p>On windows:</p>
<pre><code>echo -n "1" | openssl.exe base64
MQo=
</code></pre>
<p>On Debian:</p>
<pre><code>echo -n "1" | openssl base64
MQ==
</code></pre>
<p>I get <code>MQo=</code> from Windows, but <code>MQ==</code> from linux.</p>
<p>Does anyone know the reason? and which platform generated the right one?</p>
|
[
{
"answer_id": 74534219,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 0,
"selected": false,
"text": "echo $PATH"
},
{
"answer_id": 74534445,
"author": "OneCricketeer",
"author_id": 2308683,
"author_profile": "https://Stackoverflow.com/users/2308683",
"pm_score": 1,
"selected": false,
"text": "pyspark2.cmd"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10244606/"
] |
74,515,285
|
<p>In python, you can write A filter and assign a value to a new column by using <strong>df.loc[df["A"].isin([1,2,3]),"newColumn"] ="numberType"</strong>. How does this work in pyspark?</p>
|
[
{
"answer_id": 74534219,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 0,
"selected": false,
"text": "echo $PATH"
},
{
"answer_id": 74534445,
"author": "OneCricketeer",
"author_id": 2308683,
"author_profile": "https://Stackoverflow.com/users/2308683",
"pm_score": 1,
"selected": false,
"text": "pyspark2.cmd"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19741304/"
] |
74,515,304
|
<p>In my models.py file I have a property method which returns a value and I need to store that value in the database field.</p>
<p>`</p>
<pre><code>class bug(models.Model):
......
.......
id_of_bug = models.CharField(max_length=20, blank= False, null= False)
@property
def bug_id(self):
bugid = "BUG{:03d}".format(self.pk)
self.id_of_bug = bugid
return bugid
Tried to store the value in database using self method, but not working.
</code></pre>
|
[
{
"answer_id": 74534219,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 0,
"selected": false,
"text": "echo $PATH"
},
{
"answer_id": 74534445,
"author": "OneCricketeer",
"author_id": 2308683,
"author_profile": "https://Stackoverflow.com/users/2308683",
"pm_score": 1,
"selected": false,
"text": "pyspark2.cmd"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20529531/"
] |
74,515,327
|
<p>I am working on an audio related project, and is there a way to know if an audio URL is a streaming(radio) audio programmatically? Like from the header information or somewhere else. I am trying to apply some filter or process differently based on if the audio is a streaming(radio) audio or not.</p>
|
[
{
"answer_id": 74596439,
"author": "Brad",
"author_id": 362536,
"author_profile": "https://Stackoverflow.com/users/362536",
"pm_score": 0,
"selected": false,
"text": "Content-Length"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9426164/"
] |
74,515,370
|
<p>I have a set of small images stacked on the side and a larger version of the image on the right. I want the large image to change when I click on the small image but the problem is I could achieve this using vanilla JavaScript but I am unable to do that in reactjs.</p>
<p>Screenshot of how it looks is <a href="https://i.stack.imgur.com/nirGj.png" rel="nofollow noreferrer">here</a></p>
<p>And below is the code</p>
<pre><code><div class="header-body">
<div class="wrapper">
<div class="product-box">
<div class="all-images">
<div class="small-images">
<img src="https://i.ibb.co/5LdMxNp/image.jpg" alt="image" onclick="clickimg(this)">
<img src="https://i.ibb.co/TqMj09C/image-1.jpg" alt="image" onclick="clickimg(this)">
<img src="https://i.ibb.co/5LdMxNp/image.jpg" alt="image" onclick="clickimg(this)">
<img src="https://i.ibb.co/5LdMxNp/image.jpg" alt="image" onclick="clickimg(this)">
</div>
<div class="main-images">
<img src="https://i.ibb.co/5LdMxNp/image.jpg" id="imagebox">
</div>
</div>
</div>
</code></pre>
<p>And below is the vanilla JavaScript function I wrote</p>
<pre><code>function clickimg(smallImg){
var fullImg = document.getElementById("imagebox");
fullImg.src= smallImg.src;
}
</code></pre>
<p>This runs properly on codepen. But this function doesn't work in reactjs.</p>
|
[
{
"answer_id": 74515530,
"author": "Nury Amandurdyev",
"author_id": 14652434,
"author_profile": "https://Stackoverflow.com/users/14652434",
"pm_score": 1,
"selected": false,
"text": "useState"
},
{
"answer_id": 74515578,
"author": "Unclebigay",
"author_id": 7953084,
"author_profile": "https://Stackoverflow.com/users/7953084",
"pm_score": 0,
"selected": false,
"text": "src"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14595121/"
] |
74,515,388
|
<p>my code is not linking with my css</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<link href="main.css" rel="slylesheet" text="text/css">
<title></title>
</head>
<body>
<header>
<div class="container">
<img src="beens.jpg" alt="logo" class="logo">
<nav>
<ul>
<li><a href="#">about</a></li>
<li><a href="#">games</a></li>
<li><a href="#">contact</a></li>
<li><a href="#">blog</a></li>
</ul>
</nav>
</div>
</header>
</body>
</html>
</code></pre>
<p>it worked on my flash drive but not localy</p>
<pre><code>.container {
width: 80%;
margin: 0 auto;
}
.header {
background: rgb(51, 146, 153);
}
li {
color: rgb(142, 15, 15);
}
</code></pre>
<p>my background is still white plz help</p>
<p>i tryed rewriting my link code and checking here</p>
|
[
{
"answer_id": 74515446,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": 0,
"selected": false,
"text": ".container {\n width: 80%;\n margin: 0 auto;\n}\nheader {\n background: rgb(51, 146, 153);\n}\nli {\n color: rgb(142, 15, 15);\n}"
},
{
"answer_id": 74515481,
"author": "Spyr0",
"author_id": 16905893,
"author_profile": "https://Stackoverflow.com/users/16905893",
"pm_score": 3,
"selected": true,
"text": "<link href=\"main.css\" rel=\"slylesheet\" text=\"text/css\">"
},
{
"answer_id": 74515498,
"author": "ahmmedsabbirbd",
"author_id": 19359757,
"author_profile": "https://Stackoverflow.com/users/19359757",
"pm_score": -1,
"selected": false,
"text": "li a {\n color: RGB(142, 15, 15);}\n"
},
{
"answer_id": 74515533,
"author": "Azim Feta",
"author_id": 15969669,
"author_profile": "https://Stackoverflow.com/users/15969669",
"pm_score": -1,
"selected": false,
"text": "<!DOCTYPE html>\n<html>\n<head>\n<link rel=\"stylesheet\" href=\"main.css\">\n<title></title>\n\n</head>\n<body>\n <header>\n <div class=\"header\">\n <img src=\"beens.jpg\" alt=\"logo\" class=\"logo\">\n <nav>\n <ul class=\"li\">\n <li><a href=\"#\">about</a></li>\n <li><a href=\"#\">games</a></li>\n <li><a href=\"#\">contact</a></li>\n <li><a href=\"#\">blog</a></li>\n </ul>\n </nav>\n </div>\n \n </header>\n</body>\n</html>\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515388",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20560294/"
] |
74,515,399
|
<p>I have a <code>List<List<string>> Full</code>, build up by</p>
<pre><code>for(...){
Full.Add(new List<string>());
Full[ListIndex].Add(string1);
Full[ListIndex].Add(string2);
Full[ListIndex].Add(string3);
...
}
</code></pre>
<p>can be read by</p>
<pre><code>string2 = Full[sublistX][element1];
</code></pre>
<p>A <code>List<string> Strings</code> contain some of the instance for <code>string2</code></p>
<p>I want to create a new <code>List<List<string> NewList</code> only contain sublist from <code>Full[sublistX][element1]</code> which equals to any element in <code>List<string>Strings</code></p>
<p><strong>For example,</strong></p>
<pre><code>List<List<string>> Full = new List<List<string>>()
{
new List<string>() { "11", "AA", "!!", },
new List<string>() { "22", "BB", "@@", },
new List<string>() { "33", "CC", "##", },
new List<string>() { "44", "DD", "$$", },
};
List<string> Strings = new List<string>()
{
"AA", "DD",
};
</code></pre>
<p>I want the <code>List<List<string> NewList</code> contain:</p>
<pre><code>sublist0: "11", "AA", "!!"; //match "AA"
sublist1: "44", "DD", "$$"; //match "DD"
</code></pre>
<p><strong>For now, I'm probably doing this in a stupid way (hardcoded)</strong></p>
<pre><code>List<List<string>> Full;
List<string> Strings;
List<List<string>> NewList;
for (int i = 0; i < Full.Count; i++)
{
if (Strings.Contains(Full[i][4]))
{
NewList.Add(new List<string>());
NewList[ListIndex].Add(Full[i][0]);
NewList[ListIndex].Add(Full[i][1]);
NewList[ListIndex].Add(Full[i][2]);
NewList[ListIndex].Add(Full[i][3]);
NewList[ListIndex].Add(Full[i][4]);
NewList[ListIndex].Add(Full[i][5]);
NewList[ListIndex].Add(Full[i][6]);
NewList[ListIndex].Add(Full[i][7]);
NewList[ListIndex].Add(Full[i][8]);
NewList[ListIndex].Add(Full[i][9]);
ListIndex++;
}
}
</code></pre>
<p><strong>My question is: is there a better way to do it?</strong></p>
<p>I think there could be two points that need optimizing:</p>
<ol>
<li>Avoid using <code>for()</code> to traverse the whole list "Full," especially when "Full" contains a lot of sublists and "Strings" only have little elements.</li>
<li>From the code you can see I now have 10 elements in each sublist, and that could be increased/decreased in the future, but I hard coded the <code>NewList[ListIndex].Add</code> from index 0 to 9. Is there a way to get the counts of sublist elements? So that I can use <code>for(sublist elements count)</code> to add the NewList.</li>
</ol>
|
[
{
"answer_id": 74515461,
"author": "Eldar",
"author_id": 12354911,
"author_profile": "https://Stackoverflow.com/users/12354911",
"pm_score": 2,
"selected": false,
"text": "var filteredList = Full.Where(strs => strs.Any(s=> Strings.Contains(s))).ToList();\n"
},
{
"answer_id": 74515465,
"author": "Firo",
"author_id": 671619,
"author_profile": "https://Stackoverflow.com/users/671619",
"pm_score": 2,
"selected": false,
"text": "List<List<string>> full = ...;\nList<string> searchItems = ...;\n\n// only filtering\nvar result = full.Where(l => searchItems.Any(l.Contains)).ToList();\n\n// also copying\nvar result = full.Where(l => searchItems.Any(l.Contains)).Select(l => l.ToList()).ToList();\n\n// or faster for big lists\nvar searchItemsSet = new HashSet<string>(searchItems);\nvar result = full.Where(list => list.Any(searchItemsSet .Contains)).ToList();\n"
},
{
"answer_id": 74516021,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 3,
"selected": true,
"text": "Intersect"
},
{
"answer_id": 74516264,
"author": "Enigmativity",
"author_id": 259769,
"author_profile": "https://Stackoverflow.com/users/259769",
"pm_score": 1,
"selected": false,
"text": "List<List<string>> NewList =\n(\n from xs in Full\n where xs.Any(x => Strings.Any(s => x.Contains(s)))\n select xs\n).ToList();\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17754180/"
] |
74,515,444
|
<p>Given a currency table I need to find the latest record of conversion rate which is less than given particular date</p>
<p><strong>Input table structure</strong> given below:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: center;">baseCur</th>
<th style="text-align: right;">Curr</th>
<th style="text-align: right;">rate</th>
<th style="text-align: right;">date</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">USD</td>
<td style="text-align: right;">81</td>
<td style="text-align: right;">2022-11-09</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">USD</td>
<td style="text-align: right;">82</td>
<td style="text-align: right;">2022-11-08</td>
</tr>
<tr>
<td style="text-align: left;">3</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">USD</td>
<td style="text-align: right;">80</td>
<td style="text-align: right;">2022-11-06</td>
</tr>
<tr>
<td style="text-align: left;">4</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">CAD</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">2022-11-05</td>
</tr>
<tr>
<td style="text-align: left;">5</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">RUB</td>
<td style="text-align: right;">.74</td>
<td style="text-align: right;">2022-11-04</td>
</tr>
<tr>
<td style="text-align: left;">6</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">CAD</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">2022-11-12</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Problem statement:</strong></p>
<p>I need to <strong>find all latest currencies rate</strong> that is less than 2022-11-09.On any given date there will be only conversation rate for any particular currency</p>
<p>so expected output</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: center;">baseCur</th>
<th style="text-align: right;">Curr</th>
<th style="text-align: right;">rate</th>
<th style="text-align: right;">date</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">USD</td>
<td style="text-align: right;">82</td>
<td style="text-align: right;">2022-11-08</td>
</tr>
<tr>
<td style="text-align: left;">4</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">CAD</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">2022-11-05</td>
</tr>
<tr>
<td style="text-align: left;">5</td>
<td style="text-align: center;">INR</td>
<td style="text-align: right;">RUB</td>
<td style="text-align: right;">.74</td>
<td style="text-align: right;">2022-11-04</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Explanantion of output :</strong></p>
<p>Id 1,6 rejected : cause they are greater than 2022-11-09 date</p>
<p>Id 3 rejected cause we have one more record for INR to CAD in row 2 and its date is more new to Id 3</p>
|
[
{
"answer_id": 74515788,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 1,
"selected": false,
"text": "DENSE_RANK()"
},
{
"answer_id": 74516018,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 1,
"selected": false,
"text": "SELECT \ncurr, MAX(yourdate) maxDate\nFROM yourtable\nWHERE yourdate < '2022-11-09' \nGROUP BY curr; \n"
},
{
"answer_id": 74516029,
"author": "Prasuna",
"author_id": 15126914,
"author_profile": "https://Stackoverflow.com/users/15126914",
"pm_score": 0,
"selected": false,
"text": "-- 1. Based on id column\nSELECT * FROM sometable as t WHERE t.id = \n(SELECT MAX(id) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n-- 2. Based on date column\nSELECT * FROM sometable as t WHERE t.date = \n(SELECT MAX(date) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3245676/"
] |
74,515,486
|
<p>I have the following prediction model:</p>
<pre><code>library(tidymodels)
data(ames)
set.seed(4595)
data_split <- initial_split(ames, strata = "Sale_Price", prop = 0.75)
ames_train <- training(data_split)
ames_test <- testing(data_split)
rec <- recipe(Sale_Price ~ ., data = ames_train)
norm_trans <- rec %>%
step_zv(all_predictors()) %>%
step_nzv(all_predictors()) %>%
step_corr(all_numeric_predictors(), threshold = 0.1)
# Preprocessing
norm_obj <- prep(norm_trans, training = ames_train)
rf_ames_train <- bake(norm_obj, ames_train) %>%
dplyr::select(Sale_Price, everything()) %>%
as.data.frame()
dim(rf_ames_train )
rf_xy_fit <- rand_forest(mode = "regression") %>%
set_engine("ranger") %>%
fit_xy(
x = rf_ames_train,
y = log10(rf_ames_train$Sale_Price)
)
</code></pre>
<p>Note that after preprocessing step the number of features are reduced from 74 to 33.</p>
<pre><code>dim(rf_ames_train )
# 33
</code></pre>
<p>Currently, I have to explicitly pass the predictors in the function:</p>
<pre><code>preds <- colnames(rf_ames_train)
my_pred_function <- function (fit = NULL, test_data = NULL, predictors = NULL) {
test_results <- test_data %>%
select(Sale_Price) %>%
mutate(Sale_Price = log10(Sale_Price)) %>%
bind_cols(
predict(fit, new_data = ames_test[, predictors])
)
test_results
}
my_pred_function(fit = rf_xy_fit, test_data = ames_test, predictors = preds)
</code></pre>
<p>Shown as <code>predictors = preds</code> in the function call above.</p>
<p>In practice, I have to save the <code>rf_xy_fit</code> and <code>preds</code> as two RDS files, then read them again. This is prone to error and troublesome.</p>
<p>I would like to by-pass this explicit passing. Is there a way I can extract that from <code>rf_xy_fit</code> directly?</p>
|
[
{
"answer_id": 74515788,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 1,
"selected": false,
"text": "DENSE_RANK()"
},
{
"answer_id": 74516018,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 1,
"selected": false,
"text": "SELECT \ncurr, MAX(yourdate) maxDate\nFROM yourtable\nWHERE yourdate < '2022-11-09' \nGROUP BY curr; \n"
},
{
"answer_id": 74516029,
"author": "Prasuna",
"author_id": 15126914,
"author_profile": "https://Stackoverflow.com/users/15126914",
"pm_score": 0,
"selected": false,
"text": "-- 1. Based on id column\nSELECT * FROM sometable as t WHERE t.id = \n(SELECT MAX(id) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n-- 2. Based on date column\nSELECT * FROM sometable as t WHERE t.date = \n(SELECT MAX(date) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8391698/"
] |
74,515,514
|
<pre><code>"caprometheusip" : {
"id" : 11,
"key" : "caprometheusip",
"value" : "[fd02::100:ffff:ffff:ffff:e0]",
"description" : "",
"createTime" : 1660630139000,
"updateTime" : 1644822836000
},
</code></pre>
<p>There are the following fields in my json file. I want to replace this IP address, which corresponds to value, with ""</p>
<p>I tried to pass this command</p>
<pre><code>Sed - i - e 's/ "[fd02:: 100: ffff: ffff: ffff: e0] "/ ""/' 1.json
</code></pre>
<p>After json executes, it has no effect</p>
<p>I wonder if it is because the Ip address starts with [. The sed command resolves to regular. If so, how should I modify the command</p>
|
[
{
"answer_id": 74515788,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 1,
"selected": false,
"text": "DENSE_RANK()"
},
{
"answer_id": 74516018,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 1,
"selected": false,
"text": "SELECT \ncurr, MAX(yourdate) maxDate\nFROM yourtable\nWHERE yourdate < '2022-11-09' \nGROUP BY curr; \n"
},
{
"answer_id": 74516029,
"author": "Prasuna",
"author_id": 15126914,
"author_profile": "https://Stackoverflow.com/users/15126914",
"pm_score": 0,
"selected": false,
"text": "-- 1. Based on id column\nSELECT * FROM sometable as t WHERE t.id = \n(SELECT MAX(id) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n-- 2. Based on date column\nSELECT * FROM sometable as t WHERE t.date = \n(SELECT MAX(date) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18842940/"
] |
74,515,536
|
<p>I have a dataframe such as :</p>
<pre><code> COL1 COL2 COL3 COL4 COL5 COL6 COL7
1 Sp1-2 Sp1-2 Sp3_2-54 Sp3-2 Sp3-2 Sp3-2 SP9-43
2 Sp5-1 Sp5-2 Sp2-4 Sp9-2 Sp10-3 SP9-90 NA
3 Sp_7-3 Sp_7-3 NA SP6-56 Sp2-7 SP3-3 NA
</code></pre>
<p>And I would simply like to merge columns when at leats two elements are duplicated.</p>
<p>for example, in <code>COL1</code> and <code>COL2</code>, <code>Sp1-2</code> & <code>Sp_7-3</code> are duplicated in both columns, then I merge it that way by adding a pipe "|" between non-duplicated elements:</p>
<pre><code> COL1|COL2 COL3 COL4|COL5|COL6 COL7
1 Sp1-2 Sp3_2-54 Sp3-2 SP9-43
2 Sp5-1|Sp5-2 Sp2-4 Sp9-2|Sp10-3|SP9-90 NA
3 Sp_7-3 NA SP6-56|Sp2-7|SP3-3 NA
</code></pre>
<p>Here is the dput format :</p>
<pre><code>structure(list(COL1 = c("Sp1-2", "Sp5-1", "Sp_7-3"), COL2 = c("Sp1-2",
"Sp5-2", "Sp_7-3"), COL3 = c("Sp3_2-54", "Sp2-4", NA), COL4 = c("Sp3-2",
"Sp9-2", "SP6-56"), COL5 = c("Sp3-2", "Sp10-3", "Sp2-7"), COL6 = c("Sp3-2",
"SP9-90", "SP3-3"), COL7 = c("SP9-43", NA, NA)), class = "data.frame", row.names = c(NA,
-3L))
</code></pre>
<p>Another example :</p>
<pre><code> G136 G348 G465
1 NA NA NA
2 NA NA NA
3 SP4-140 SP4-140 NA
4 SP2-8 NA NA
5 SP3-59 NA NA
6 SP1_contig.682-8 NA SP1_contig.682-8
</code></pre>
<p>expected output:</p>
<pre><code> G136|G348|G465
1 NA
2 NA
3 SP4-140
4 SP2-8
5 SP3-59
6 SP1_contig.682-8
</code></pre>
<p>the deput format :</p>
<pre><code>dat<- structure(list(G136 = c(NA, NA, "SP4-140", "SP2-8", "SP3-59", "SP1_contig.682-8", NA, NA, NA), G348 = c(NA, NA, "SP4-140", NA, NA, NA, NA, NA, NA), G465 = c(NA, NA, NA, NA, NA, "SP1_contig.682-8", NA, NA, NA)), row.names = c(NA, -9L), class = c("tbl_df", "tbl", "data.frame"))
</code></pre>
|
[
{
"answer_id": 74515788,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 1,
"selected": false,
"text": "DENSE_RANK()"
},
{
"answer_id": 74516018,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 1,
"selected": false,
"text": "SELECT \ncurr, MAX(yourdate) maxDate\nFROM yourtable\nWHERE yourdate < '2022-11-09' \nGROUP BY curr; \n"
},
{
"answer_id": 74516029,
"author": "Prasuna",
"author_id": 15126914,
"author_profile": "https://Stackoverflow.com/users/15126914",
"pm_score": 0,
"selected": false,
"text": "-- 1. Based on id column\nSELECT * FROM sometable as t WHERE t.id = \n(SELECT MAX(id) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n-- 2. Based on date column\nSELECT * FROM sometable as t WHERE t.date = \n(SELECT MAX(date) FROM sometable WHERE Curr = t.Curr and date < '2022-11-09');\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12559770/"
] |
74,515,573
|
<p>Something has piqued my curiosity recently..</p>
<p><strong>Why</strong> is the <code>Enumerable.Any(Func<TSource, bool> predicate)</code> method <strong>so much slower</strong> than manual foreach, <strong>when they do the same thing?</strong></p>
<p>I've been messing with some benchmarks and thought of this. I'm checking of a <code>List<int></code> contains and item that's approximately in the half of the list.</p>
<p>Here are my test results for a few diffent sizes of the list:</p>
<p>Items: 1 000, searched item: 543</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Method</th>
<th style="text-align: right;">Mean</th>
<th style="text-align: right;">Ratio</th>
<th style="text-align: right;">Allocated</th>
<th style="text-align: right;">Alloc Ratio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Foreach</td>
<td style="text-align: right;">838.3 ns</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">-</td>
<td style="text-align: right;">NA</td>
</tr>
<tr>
<td>Any</td>
<td style="text-align: right;">3,348.8 ns</td>
<td style="text-align: right;">4.05</td>
<td style="text-align: right;">40 B</td>
<td style="text-align: right;">NA</td>
</tr>
</tbody>
</table>
</div>
<p>Items: 10 000, searched item: 5 432</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Method</th>
<th style="text-align: right;">Mean</th>
<th style="text-align: right;">Ratio</th>
<th style="text-align: right;">Allocated</th>
<th style="text-align: right;">Alloc Ratio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Foreach</td>
<td style="text-align: right;">7.988 us</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">-</td>
<td style="text-align: right;">NA</td>
</tr>
<tr>
<td>Any</td>
<td style="text-align: right;">30.991 us</td>
<td style="text-align: right;">3.88</td>
<td style="text-align: right;">40 B</td>
<td style="text-align: right;">NA</td>
</tr>
</tbody>
</table>
</div>
<p>Items: 100 000, searched item: 54 321</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Method</th>
<th style="text-align: right;">Mean</th>
<th style="text-align: right;">Ratio</th>
<th style="text-align: right;">Allocated</th>
<th style="text-align: right;">Alloc Ratio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Foreach</td>
<td style="text-align: right;">82.35 us</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">-</td>
<td style="text-align: right;">NA</td>
</tr>
<tr>
<td>Any</td>
<td style="text-align: right;">328.86 us</td>
<td style="text-align: right;">4.00</td>
<td style="text-align: right;">40 B</td>
<td style="text-align: right;">NA</td>
</tr>
</tbody>
</table>
</div>
<p>There are two benchmarks:</p>
<ul>
<li><strong>Foreach</strong>: manual <code>foreach</code> with an <code>if</code> statement</li>
<li><strong>Any</strong>: LINQ's <code>Any</code> method (that turns into <code>Enumerable.Any</code>)</li>
</ul>
<p>Here's my code for the benchmarks (using BenchmarkDotNet, .NET 6.0 console app running in Release mode):</p>
<pre class="lang-cs prettyprint-override"><code>[MemoryDiagnoser(displayGenColumns: false)]
[HideColumns("Error", "StdDev", "RatioSD")]
public class Benchmarks
{
private readonly List<int> _items;
private readonly Func<int, bool> _filter;
public Benchmarks()
{
_items = Enumerable.Range(1, 10_000).ToList();
_filter = x => x == 5432;
}
[Benchmark(Baseline = true)]
public bool Foreach()
{
if (_items is null)
{
throw new ArgumentNullException(nameof(_items));
}
if (_filter is null)
{
throw new ArgumentNullException(nameof(_filter));
}
foreach (var item in _items)
{
if (_filter(item))
{
return true;
}
}
return false;
}
[Benchmark]
public bool Any()
{
return _items.Any(_filter);
}
}
</code></pre>
<p>The <strong>Any</strong> approach is <strong>4 times slower</strong> and allocates a bit of memory despite my best attempts to optimize it.</p>
<p>I tried to make the <strong>Any</strong> approach faster by caching the predicate (<code>Func<int, bool></code>) in a variable (<code>_filter</code>). However, it still allocates 40B and I have no idea why...</p>
<p>When decompiled, the <strong>Any</strong> approach turns into <code>Enumerable.Any(Func<TSource, bool> predicate)</code> method:</p>
<pre class="lang-cs prettyprint-override"><code>public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
{
if (source == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
}
if (predicate == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.predicate);
}
foreach (TSource element in source)
{
if (predicate(element))
{
return true;
}
}
return false;
}
</code></pre>
<p>How is the <strong>Any</strong> approach different from the <strong>Foreach</strong> approach? Just curious...</p>
|
[
{
"answer_id": 74520037,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 4,
"selected": true,
"text": "List<T>"
},
{
"answer_id": 74592061,
"author": "Michal Diviš",
"author_id": 4317797,
"author_profile": "https://Stackoverflow.com/users/4317797",
"pm_score": 2,
"selected": false,
"text": "_items"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4317797/"
] |
74,515,610
|
<p>I know this topic is just all over the place, and I was sincerely attempting for quite a lot of hours, and without shred of success.</p>
<p>My issue is that my git doesn't recognize my <strong>own</strong> repository. It provides me with the following error on any attempt to perform pull/push:</p>
<pre><code>remote: Repository not found.
fatal: repository 'https://github.com/danieln-juno/bugreport.git/' not found
</code></pre>
<p>Now, I did not misspell the name of the repository/URL. Also, I do have an access as I am the owner of the repository.</p>
<p>when I perform the command <code>git remote -v</code>, I get the correct url:</p>
<pre><code> origin https://github.com/danieln-juno/bugreport.git (fetch) origin
https://github.com/danieln-juno/bugreport.git (push)
</code></pre>
<p>My current local folder has been initialized, of course.</p>
<p>I'll just add that I had Git initialized and working along GitHub, up to the point I had to do a System Reset (Not format), plus I wanted to create and use a new GitHub account.</p>
<p>I'm using Windows10 with MINGW64 (Git Bash).</p>
<p>Any ideas what might be causing this issue?</p>
<p>Regards.</p>
|
[
{
"answer_id": 74520037,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 4,
"selected": true,
"text": "List<T>"
},
{
"answer_id": 74592061,
"author": "Michal Diviš",
"author_id": 4317797,
"author_profile": "https://Stackoverflow.com/users/4317797",
"pm_score": 2,
"selected": false,
"text": "_items"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9517800/"
] |
74,515,611
|
<p>In addition to this <a href="https://stackoverflow.com/questions/74499675/how-to-get-a-specific-value-from-an-array-of-object-and-store-them-individually/74509632?noredirect=1#comment131535317_74509632">question</a>
I am trying to map individually a state to another state to store the <code>amountToPay</code> object to get the sum of it. The problem is every time it renders the <code>onChange</code> function. It stores every state as object as you can see here: <a href="https://i.stack.imgur.com/qdv6A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qdv6A.png" alt="here" /></a>.</p>
<p>What I want to happen is to only get [<code>434</code>] instead of <code>['','4','43','434']</code>
So I can .reduce the array to get the sum.</p>
<p>My method on storing the array object to another state is this</p>
<pre class="lang-js prettyprint-override"><code> const [amountToPay, setAmountToPay] = useState("")
console.log("AMOUNT TO PAY", amountToPay)
useEffect(() => {
serviceItem.map((item) => (
setAmountToPay([...amountToPay, item.amountToPay])
))
}, [serviceItem])
useEffect(() => {
serviceItem.map((item) => (
setAmountToPay([...amountToPay, item.amountToPay])
))
}, [serviceItem])
</code></pre>
<p>You can check the whole code here <a href="https://codesandbox.io/s/dazzling-leftpad-9ft2od?file=/src/App.js" rel="nofollow noreferrer">CodeSandbox code</a>.Any help is appreciated :)</p>
|
[
{
"answer_id": 74515982,
"author": "Evgeny",
"author_id": 7309962,
"author_profile": "https://Stackoverflow.com/users/7309962",
"pm_score": 2,
"selected": true,
"text": "serviceItem"
},
{
"answer_id": 74516118,
"author": "Ragnar",
"author_id": 9608873,
"author_profile": "https://Stackoverflow.com/users/9608873",
"pm_score": 1,
"selected": false,
"text": "import React, { useState, useMemo, useEffect } from \"react\";\n\nexport default function App() {\n //Values\n const [serviceItem, setServiceList] = useState([\n { serviceValue: \"\", quantityValue: \"\", amountToPay: \"\" }\n ]);\n console.log(\"SERVICE ITEM\", serviceItem);\n\n //Add item function\n const handleItemAdd = () => {\n setServiceList([\n ...serviceItem,\n { serviceValue: \"\", quantityValue: \"\", amountToPay: \"\" }\n ]);\n handleSetAmountToPAY(serviceItem)\n };\n\n //Remove item function\n const handleItemRemove = (index) => {\n const list = [...serviceItem];\n list.splice(index, 1);\n setServiceList(list);\n handleSetAmountToPAY(list)\n };\n\n //Get Values\n const handleGetValues = (e, index) => {\n const { name, value } = e.target;\n const list = [...serviceItem];\n list[index][name] = value;\n setServiceList(list);\n };\n\n //Saving state to another state\n const [amountToPay, setAmountToPay] = useState([]);\n console.log(\"AMOUNT TO PAY\", amountToPay);\n const handleSetAmountToPAY = (list) => {\n list && list.map((item) =>\n setAmountToPay([...amountToPay, item.amountToPay])\n );\n }\n\n //Add total amount\n const procedurePriceTotal = amountToPay.reduce(\n (index, value) => (index = index + value),\n 0\n );\n console.log(\"TOTAL PRICE\", procedurePriceTotal);\n\n return (\n <div className=\"App\">\n {serviceItem.map((singleItem, index) => (\n <div class=\"row form-row\">\n <div class=\"col-12 col-md-6 col-lg-4\">\n <div class=\"form-group\">\n <label>\n Service <span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"serviceValue\"\n type=\"text\"\n class=\"form-control\"\n value={singleItem.serviceValue}\n placeholder=\"Tooth Extraction\"\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-3\">\n <div class=\"form-group\">\n <label>\n Quantity <span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"quantityValue\"\n type=\"text\"\n class=\"form-control\"\n placeholder=\"1\"\n value={singleItem.quantityValue}\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-3\">\n <div class=\"form-group\">\n <label>\n Amount (₱)<span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"amountToPay\"\n type=\"number\"\n class=\"form-control\"\n placeholder=\"500\"\n value={singleItem.amountToPay}\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-2\">\n <div class=\"add-more\">\n <br />\n {serviceItem.length !== 1 && (\n <button\n type=\"submit\"\n onClick={() => handleItemRemove(index)}\n className=\"btn btn-primary rx-pr\"\n >\n <i className=\"fas fa-plus\" /> Remove Item\n </button>\n )}\n </div>\n </div>\n </div>\n ))}\n\n {/* Add Item */}\n <div className=\"add-more-item rx-pr\">\n <button\n type=\"submit\"\n onClick={handleItemAdd}\n className=\"btn btn-primary rx-pr\"\n >\n <i className=\"fas fa-plus\" /> Add Item\n </button>\n </div>\n </div>\n );\n}\n"
},
{
"answer_id": 74520185,
"author": "dape",
"author_id": 20542465,
"author_profile": "https://Stackoverflow.com/users/20542465",
"pm_score": 0,
"selected": false,
"text": "reduce"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20542465/"
] |
74,515,613
|
<p>I'm selling hand-painted artwork on a WooCommerce store. Since It's hand-painted artwork,
The product quantity is limited to 1 (Limit purchases to 1 item per order)</p>
<p>I have created product variations for the artwork frame as below :</p>
<p>Variation 1: Wooden Frame (stock qty = 1 in variations)
Variation 2: acrylic Frame (stock qty = 1 in variations)</p>
<p>I want to limit the order to per product/per variations basis.</p>
<p>Example: A User can purchase an artwork with either a wooden or acrylic frame only.</p>
<p>Currently, A user can add to cart artwork with both wooden & acrylic frames.</p>
<p>I don't want a user to purchase a unique hand-made artwork with 2 separate variations.</p>
<p>How can I achieve this ? Is there any function that can be used to limit this?</p>
|
[
{
"answer_id": 74515982,
"author": "Evgeny",
"author_id": 7309962,
"author_profile": "https://Stackoverflow.com/users/7309962",
"pm_score": 2,
"selected": true,
"text": "serviceItem"
},
{
"answer_id": 74516118,
"author": "Ragnar",
"author_id": 9608873,
"author_profile": "https://Stackoverflow.com/users/9608873",
"pm_score": 1,
"selected": false,
"text": "import React, { useState, useMemo, useEffect } from \"react\";\n\nexport default function App() {\n //Values\n const [serviceItem, setServiceList] = useState([\n { serviceValue: \"\", quantityValue: \"\", amountToPay: \"\" }\n ]);\n console.log(\"SERVICE ITEM\", serviceItem);\n\n //Add item function\n const handleItemAdd = () => {\n setServiceList([\n ...serviceItem,\n { serviceValue: \"\", quantityValue: \"\", amountToPay: \"\" }\n ]);\n handleSetAmountToPAY(serviceItem)\n };\n\n //Remove item function\n const handleItemRemove = (index) => {\n const list = [...serviceItem];\n list.splice(index, 1);\n setServiceList(list);\n handleSetAmountToPAY(list)\n };\n\n //Get Values\n const handleGetValues = (e, index) => {\n const { name, value } = e.target;\n const list = [...serviceItem];\n list[index][name] = value;\n setServiceList(list);\n };\n\n //Saving state to another state\n const [amountToPay, setAmountToPay] = useState([]);\n console.log(\"AMOUNT TO PAY\", amountToPay);\n const handleSetAmountToPAY = (list) => {\n list && list.map((item) =>\n setAmountToPay([...amountToPay, item.amountToPay])\n );\n }\n\n //Add total amount\n const procedurePriceTotal = amountToPay.reduce(\n (index, value) => (index = index + value),\n 0\n );\n console.log(\"TOTAL PRICE\", procedurePriceTotal);\n\n return (\n <div className=\"App\">\n {serviceItem.map((singleItem, index) => (\n <div class=\"row form-row\">\n <div class=\"col-12 col-md-6 col-lg-4\">\n <div class=\"form-group\">\n <label>\n Service <span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"serviceValue\"\n type=\"text\"\n class=\"form-control\"\n value={singleItem.serviceValue}\n placeholder=\"Tooth Extraction\"\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-3\">\n <div class=\"form-group\">\n <label>\n Quantity <span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"quantityValue\"\n type=\"text\"\n class=\"form-control\"\n placeholder=\"1\"\n value={singleItem.quantityValue}\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-3\">\n <div class=\"form-group\">\n <label>\n Amount (₱)<span class=\"text-danger\">*</span>\n </label>\n <input\n name=\"amountToPay\"\n type=\"number\"\n class=\"form-control\"\n placeholder=\"500\"\n value={singleItem.amountToPay}\n onChange={(e) => {\n handleGetValues(e, index);\n }}\n />\n </div>\n </div>\n <div class=\"col-12 col-md-6 col-lg-2\">\n <div class=\"add-more\">\n <br />\n {serviceItem.length !== 1 && (\n <button\n type=\"submit\"\n onClick={() => handleItemRemove(index)}\n className=\"btn btn-primary rx-pr\"\n >\n <i className=\"fas fa-plus\" /> Remove Item\n </button>\n )}\n </div>\n </div>\n </div>\n ))}\n\n {/* Add Item */}\n <div className=\"add-more-item rx-pr\">\n <button\n type=\"submit\"\n onClick={handleItemAdd}\n className=\"btn btn-primary rx-pr\"\n >\n <i className=\"fas fa-plus\" /> Add Item\n </button>\n </div>\n </div>\n );\n}\n"
},
{
"answer_id": 74520185,
"author": "dape",
"author_id": 20542465,
"author_profile": "https://Stackoverflow.com/users/20542465",
"pm_score": 0,
"selected": false,
"text": "reduce"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515613",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/369411/"
] |
74,515,635
|
<p>it's simple html tag related problem, I guess.</p>
<p>I want to share few lines of code in my blog, and I want to write <code><h1> heading</h1></code>. visitors must see <code><h1> heading </h1></code>, and not just <strong>heading</strong>. do I need to use JavaScript for this, please help me with this problem.</p>
|
[
{
"answer_id": 74515742,
"author": "Bittar",
"author_id": 10535461,
"author_profile": "https://Stackoverflow.com/users/10535461",
"pm_score": 1,
"selected": false,
"text": "<h1><h1>heading;/h1></h1>\n"
},
{
"answer_id": 74515781,
"author": "Shivangam Soni",
"author_id": 16659219,
"author_profile": "https://Stackoverflow.com/users/16659219",
"pm_score": 0,
"selected": false,
"text": "textContent"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20548111/"
] |
74,515,636
|
<p>i have been suffering to get the items' data listed according to their categories</p>
<p>i don't know what am I doing wrong.</p>
<p>so basically, I have data coming from a bearer token API and it is listed successfully on the screen but I want as a second step to list according to their categories. there are five categories and more than 60 items.</p>
<p>here is my code:</p>
<pre><code> const [filterList, setFilterList] = useState("all");
const [newProduct, setNewProduct] = useState(products);
// filtering data by category
useEffect(() => {
let isValidScope = true;
const fetchData = async () => {
// pass filterList in fetch to get products for the selected category ??
// pass parameters to fetch accordingly
const res = await fetch(
"https://myapi-api.herokuapp.com/api/categories/",
{
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
}
);
if (!isValidScope) {
return;
}
setNewProduct(res);
};
fetchData();
return () => {
isValidScope = false;
};
}, [filterList]);
function onFilterValueSelected(filterValue) {
setFilterList(filterValue);
}
let filteredProductList = newProduct?.filter((product) => {
// should return true or false
// option 2 if product has a category property
return product.category === filterList;
// existing code
if (filterList === "electronics") {
return product.electronics == true;
} else if (filterList === "clothing") {
return product.clothing === true;
} else if (filterList === "accsessories") {
return product.accsessories === true;
} else if (filterList === "furniture") {
return product.furniture === true;
} else if (filterList === "hobby") {
return product.hobby === true;
} else {
// here dont return truthy
return false;
}
});
</code></pre>
|
[
{
"answer_id": 74515739,
"author": "ColdDarkness",
"author_id": 20480318,
"author_profile": "https://Stackoverflow.com/users/20480318",
"pm_score": 0,
"selected": false,
"text": "const categories = ['Cat1', 'Cat2', 'Cat3'] // Since you hardcode it anyway, its fine to have a hardcoded array here. But you can retrieve unique categories by getting Object.values on category and new Set() them\nreturn (<> {categories.forEach(category => {\nfetchedData.filter(el => el.category === category).map(filteredElement => {return <h1> {filteredElement.property} <h1>})}) </>} \n\n"
},
{
"answer_id": 74515904,
"author": "Marios",
"author_id": 20229075,
"author_profile": "https://Stackoverflow.com/users/20229075",
"pm_score": 2,
"selected": true,
"text": "const [filterCategory, setFilterCategory] = useState(\"\");\n \nfunction onFilterValueSelected(filterValue) {\n setFilterCategory(filterValue);\n }\n\n let filteredProductList = newProduct?.filter((product) => {\n return product.category === filterCategory; \n });\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15208666/"
] |
74,515,645
|
<p>I would like to turn float integers (123.0) into ints (123).</p>
<p>What I would like the function to do:</p>
<p>Input: 2.1
Output: Exception, cannot turn float into int</p>
<p>Input: 2.0
Output: 2</p>
<p>Using int() on a float seems to just be math.floor() and that is not what I'm looking for.</p>
|
[
{
"answer_id": 74515736,
"author": "Guy",
"author_id": 5168011,
"author_profile": "https://Stackoverflow.com/users/5168011",
"pm_score": 2,
"selected": false,
"text": "int()"
},
{
"answer_id": 74515752,
"author": "Joran Beasley",
"author_id": 541038,
"author_profile": "https://Stackoverflow.com/users/541038",
"pm_score": 2,
"selected": false,
"text": "def convert(n):\n return int(f\"{n:g}\")\n"
},
{
"answer_id": 74515770,
"author": "MangoNrFive",
"author_id": 15219428,
"author_profile": "https://Stackoverflow.com/users/15219428",
"pm_score": 2,
"selected": false,
"text": ".is_integer()"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20488228/"
] |
74,515,699
|
<p>I have a column in my Dataframe that contains datetime.time() values.
example :</p>
<pre><code>--> df.loc[0,'tat']
output: datetime.time(0, 21, 4)
</code></pre>
<p>I want to write multiple if conditions with this column.
example:</p>
<pre><code>--> if df.loc[0,'tat'] < 2:
df.loc[0,'SLA'] = 'less than 2 hour SLA'
else:
df.loc[0,'SLA'] = 'greater than 2 hour SLA'
--> if df.loc[0,'tat'] < 4 and df.loc[0,'tat'] > 2:
df.loc[0,'SLA'] = '2-4 hour SLA'
else:
df.loc[0,'SLA'] = 'greater than 4 hour SLA'
</code></pre>
<p>When I compare df.loc[r,'tat']< 2 it gives a <strong>TypeError: '<' not supported between instances of 'datetime.time' and 'int'</strong></p>
<p>I then tried to create timedeltas.</p>
<pre><code>timedelta_2 = timedelta(hours=2)
df.loc[r,'tat']< timedelta_2
</code></pre>
<p>It still gives me a <strong>TypeError: '<' not supported between instances of 'datetime.time' and 'datetime.timedelta'</strong></p>
<p>How else am I supposed to compare ?!</p>
|
[
{
"answer_id": 74515724,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 2,
"selected": false,
"text": "hour"
},
{
"answer_id": 74515777,
"author": "Anirudh B M",
"author_id": 14540976,
"author_profile": "https://Stackoverflow.com/users/14540976",
"pm_score": 0,
"selected": false,
"text": "import datetime.datetime as dt\nif df.loc[0,'tat'] < dt.time(hours=2,minutes=0,seconds=0):\n df.loc[0,'SLA'] = 'less than 2 hour SLA'\nelse:\n df.loc[0,'SLA'] = 'greater than 2 hour SLA'\n\nif df.loc[0,'tat'] < dt.time(4,0,0) and df.loc[0,'tat'] > dt.time(hours=2,minutes=0,seconds=0):\n df.loc[0,'SLA'] = '2-4 hour SLA'\nelse:\n df.loc[0,'SLA'] = 'greater than 4 hour SLA'\n"
},
{
"answer_id": 74515894,
"author": "riigs",
"author_id": 19844059,
"author_profile": "https://Stackoverflow.com/users/19844059",
"pm_score": 0,
"selected": false,
"text": "datetime.time(0, 21, 4)\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12435792/"
] |
74,515,717
|
<p>I have a problem to write code:
I have a state</p>
<pre><code>const [theme, setTheme] = useState({ mode: "LIGHT" });
</code></pre>
<p>and I want to made a toggle function that change mode to 'DARK' and change DARK to 'LIGHT' by double click. how can I write it?</p>
<pre><code>import { createContext, useContext, useState } from "react";
const DARK = "DARK";
const ThemeContext = createContext();
const ThemeProvider = ({ children }) => {
const [theme, setTheme] = useState({ mode: "LIGHT" });
const toggleThemeMode = () => {
setTheme();
console.log(theme);
};
return (
<ThemeContext.Provider value={{ theme, toggleThemeMode }}>
{children}
</ThemeContext.Provider>
);
};
const useTheme = () => useContext(ThemeContext);
export { ThemeProvider, useTheme, DARK };
</code></pre>
|
[
{
"answer_id": 74515751,
"author": "Fabian Strathaus",
"author_id": 17298437,
"author_profile": "https://Stackoverflow.com/users/17298437",
"pm_score": 0,
"selected": false,
"text": "const [theme, setTheme] = useState(\"LIGHT\");\n\n...\n\nsetTheme(theme === DARK ? \"LIGHT\" : DARK);\n"
},
{
"answer_id": 74515824,
"author": "KcH",
"author_id": 11737596,
"author_profile": "https://Stackoverflow.com/users/11737596",
"pm_score": 1,
"selected": false,
"text": "onClick"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12798431/"
] |
74,515,720
|
<p>The code posted at the bottom does a nice job of filling in a dataframe, using package <code>tidyr</code>, so that all ID's end up with the same number of periods, in the case of period defined as number of months ("Period_1" in the below code). Base dataframe <code>testDF</code> has ID of 1 with 5 periods, and ID of 50 and 60 with only 3 periods each. The <code>tidyr</code> code creates additional periods ("Period_1") for ID of 50 and 60 so they too have 5 Period_1´s. The code copies down the "Bal" and "State" fields so that all ID end up with the same number of Period_1, which is correct.</p>
<p>However, how would I extend the calendar month expression of "Period_2" in the same manner, as illustrated immediately below?</p>
<p><a href="https://i.stack.imgur.com/GwQGV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GwQGV.png" alt="enter image description here" /></a></p>
<p>Code:</p>
<pre><code>library(tidyr)
testDF <-
data.frame(
ID = as.numeric(c(rep(1,5),rep(50,3),rep(60,3))),
Period_1 = as.numeric(c(1:5,1:3,1:3)),
Period_2 = c("2012-06","2012-07","2012-08","2012-09","2012-10","2013-06","2013-07","2013-08","2012-01","2012-02","2012-03"),
Bal = as.numeric(c(rep(10,5),21:23,36:34)),
State = c("XX","AA","BB","CC","XX","AA","BB","CC","SS","XX","AA")
)
testDFextend <-
testDF %>%
tidyr::complete(ID, nesting(Period_1)) %>%
tidyr::fill(Bal, State, .direction = "down")
testDFextend
</code></pre>
<p><strong>Edit: rolling from one year to the next</strong></p>
<p>A better OP example would have <code>Period 2 = c("2012-06","2012-07","2012-08","2012-09","2012-10","2013-06","2013-07","2013-08","2012-10","2012-11","2012-12")</code>, providing an example whereby extending Period_2 causes a rollover to the next year. Below I add to the tidyr/dplyr answer below to correctly roll over the year:</p>
<pre><code>library(tidyr)
library(dplyr)
testDF <-
data.frame(
ID = as.numeric(c(rep(1,5),rep(50,3),rep(60,3))),
Period_1 = as.numeric(c(1:5,1:3,1:3)),
Period_2 = c("2012-06","2012-07","2012-08","2012-09","2012-10","2013-06","2013-07","2013-08","2012-10","2012-11","2012-12"),
Bal = as.numeric(c(rep(10,5),21:23,36:34)),
State = c("XX","AA","BB","CC","XX","AA","BB","CC","SS","XX","AA")
)
testDFextend <-
testDF %>%
tidyr::complete(ID, nesting(Period_1)) %>%
tidyr::fill(Bal, State, .direction = "down")
testDFextend %>%
separate(Period_2, into = c("year", "month"), convert = TRUE) %>%
fill(year) %>%
group_by(ID) %>%
mutate(month = sprintf("%02d", zoo::na.spline(month))) %>%
unite("Period_2", year, month, sep = "-") %>%
# Now I add the below lines:
separate(Period_2, into = c("year", "month"), convert = TRUE) %>%
mutate(month = as.integer(sprintf("%02d", zoo::na.spline(month)))) %>%
mutate(year1 = ifelse(month > 12, year+trunc(month/12), year)) %>%
mutate(month1 = ifelse(month > 12 & month%%12!= 0, month%%12, month)) %>%
mutate(month1 = ifelse(month1 < 10, paste0(0,month1),month1)) %>%
unite("Period_2", year1, month1, sep = "-") %>%
select("ID","Period_1","Period_2","Bal","State")
</code></pre>
|
[
{
"answer_id": 74515971,
"author": "jay.sf",
"author_id": 6574038,
"author_profile": "https://Stackoverflow.com/users/6574038",
"pm_score": 2,
"selected": false,
"text": "by"
},
{
"answer_id": 74516450,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 2,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74517048,
"author": "diomedesdata",
"author_id": 10366237,
"author_profile": "https://Stackoverflow.com/users/10366237",
"pm_score": 2,
"selected": true,
"text": "padr"
},
{
"answer_id": 74520204,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 2,
"selected": false,
"text": "Period_2"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19657749/"
] |
74,515,722
|
<p>I have a path like the one in the image shown</p>
<p><a href="https://i.stack.imgur.com/K4Iit.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K4Iit.png" alt="path" /></a></p>
<p>When I do this match query, there is no match returned, which is strange:</p>
<pre><code>match (a:A)--(b:B)--(c:C)--(d:D)--(c2:C)--(b2:B)--(a2:A)
where a.id = a2.id and b.id = b2.id
return count(d)
</code></pre>
<p>This one is giving no match too:</p>
<pre><code>match (a:A)--(b:B)
with a,b
match (a)--(b)--(c:C)--(d:D)--(c2:C)--(b)--(a)
return count(d)
</code></pre>
<p>But this one is giving the paths, if <code>C</code> type nodes have the property <code>B_id</code> which is the ID of their node <code>B</code> type attached to them:</p>
<pre><code>match (c:C)--(d:D)--(c2:C)
where c.B_id = c2.B_id
return count(d)
</code></pre>
<p>This seems strange to me.
Any ideas on why those matches are not working?<br />
Which would be the query to retrieve <code>count(d)</code>?</p>
|
[
{
"answer_id": 74515971,
"author": "jay.sf",
"author_id": 6574038,
"author_profile": "https://Stackoverflow.com/users/6574038",
"pm_score": 2,
"selected": false,
"text": "by"
},
{
"answer_id": 74516450,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 2,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74517048,
"author": "diomedesdata",
"author_id": 10366237,
"author_profile": "https://Stackoverflow.com/users/10366237",
"pm_score": 2,
"selected": true,
"text": "padr"
},
{
"answer_id": 74520204,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 2,
"selected": false,
"text": "Period_2"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1817860/"
] |
74,515,748
|
<p>I was facing a problem for sometime, that was I'm unable to clear cache using RTK query.
I tried in various ways but cache data is not clear.</p>
<p>I used invalidatesTag in my mutation query and it called the api instantly. But in this case I want to refetch multiple api again, but not from any rtk query or mutation. I want to make the api call after some user activity like click.
How can I solve this problem?</p>
<pre><code>I made a separate function where I return api.util.invalidateTags(tag) or api.util.resetApiState().
this is my code-snipet:-
</code></pre>
<p>` const api = createApi({.....})</p>
<pre><code>export const resetRtkCache = (tag?: String[]) => {
const api =
if (tag) {
return api.util.invalidateTags(tag)
} else {
return api.util.resetApiState()
}
</code></pre>
<p>}`</p>
<pre><code>
& I called it using dispatch method from other files
</code></pre>
<pre><code>`const reloadData = () => {
dispatch(resetRtkCache())
}`
</code></pre>
<pre><code>
but here cache data is not removed.I think dispatch funtion is not working. I don't see the api call is being sent to server in the browser network.
</code></pre>
|
[
{
"answer_id": 74515971,
"author": "jay.sf",
"author_id": 6574038,
"author_profile": "https://Stackoverflow.com/users/6574038",
"pm_score": 2,
"selected": false,
"text": "by"
},
{
"answer_id": 74516450,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 2,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74517048,
"author": "diomedesdata",
"author_id": 10366237,
"author_profile": "https://Stackoverflow.com/users/10366237",
"pm_score": 2,
"selected": true,
"text": "padr"
},
{
"answer_id": 74520204,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 2,
"selected": false,
"text": "Period_2"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20560512/"
] |
74,515,760
|
<p>I'm having a sample HTML on which I'm writing an XPath to extract content. And my main clause is to ignore <code>style</code> and <code>script</code> tags in it irrespective of the position and I want to do it from the parent itself. Here is my test block.</p>
<pre><code> <div itemprop="articleBody">
<div>Main text.</div>
<p>
<style type="text/css">
#pStule{
font-size: 10pt;
line-height: 15pt;
}
</style>
sub text.</p>
<style type="text/css">
#dhtmltooltip{
font-size: 10pt;
line-height: 15pt;
}
</style>
<script>
var offsetxpoint=-60;
var offsetypoint=20;
</script>
<p>Another subtext.</p>
</div>
</code></pre>
<p>and my Xpath is</p>
<pre><code><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="descendant::div[@itemprop='articleBody']/descendant::*[not(descendant::style) and not(descendant::script) and not(self::style) and not(self::script)]
"/>
</xsl:template>
</xsl:stylesheet>
</code></pre>
<p>I am aware that we can achieve this using an <code>xsl:for-each</code> and doing the stuff inside it. But my program only accepts 1 line of XPath, that's the reason I want to do it from the parent.</p>
<p>My current output is</p>
<blockquote>
Main text.Another subtext.
</blockquote>
<p>Expected output.</p>
<blockquote>
Main text.sub text.Another subtext.
</blockquote>
<p>Currently, my <code>p</code> is getting ignored as it has a <code>style</code> tag inside it. Please let me know how can I do this.</p>
|
[
{
"answer_id": 74515971,
"author": "jay.sf",
"author_id": 6574038,
"author_profile": "https://Stackoverflow.com/users/6574038",
"pm_score": 2,
"selected": false,
"text": "by"
},
{
"answer_id": 74516450,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 2,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74517048,
"author": "diomedesdata",
"author_id": 10366237,
"author_profile": "https://Stackoverflow.com/users/10366237",
"pm_score": 2,
"selected": true,
"text": "padr"
},
{
"answer_id": 74520204,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 2,
"selected": false,
"text": "Period_2"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3872094/"
] |
74,515,807
|
<p>I've got an error while do migration to next 13 on my old project written in next 12.</p>
<p><a href="https://i.stack.imgur.com/fbc0u.png" rel="nofollow noreferrer">Console Error Log</a></p>
<p>I can't find fault in my code for that errors.
And I googled it but i can't find any solution for this.
It don't explains any errors for my code.
How can I solve it?</p>
<p>I couldn't try anything because it do not explains any error for my code.
Please let me know what is the origin for that error.
Thank you.</p>
<p>++++++++++
navigation.js</p>
<pre><code>function useRouter() {
const router = (0, _react).useContext(_appRouterContext.AppRouterContext);
if (router === null) {
throw new Error('invariant expected app router to be mounted');
}
return router;
}
</code></pre>
<p>i think "next/navigation" contains this file (navigation.js)</p>
<p>this error threw when router is null, but i still can't know why router is null.</p>
<p>+++++++++++ layout.jsx</p>
<pre><code>"use client";
import { motion, AnimatePresence } from "framer-motion";
import "animate.css";
import { useRouter } from "next/navigation";
import LoadingSpinner from "../components/layout/media/LoadingSpinner";
import Users from "../class/Users.class";
import { useEffect } from "react";
import create from "zustand";
import Head from "next/head";
import Image from "next/image";
import NavBar from "../components/layout/NavBar";
import SubTransition from "../components/transition/SubTransition";
import LoginModal from "../components/layout/LoginModal";
import "../styles/betconstruct_icons.css";
import "../styles/global.css";
const useStore = create(() => ({
isShowLoginModal: false,
isLoading: true,
}));
//default layout
function MainLayout({ children }) {
useEffect(() => {
Users.checkToken().then((res) => {
if (res) {
console.log("token is valid");
} else {
console.log("token is invalid");
}
LoadingDone();
});
//router.events.on("routeChangeStart", (url) => {
// LoadingNow();
//});
//router.events.on("routeChangeComplete", () => LoadingDone());
//router.events.on("routeChangeError", () => LoadingDone());
if (router.pathname === "/") {
document.querySelector("body").classList.add("layout-bc");
document.querySelector("body").classList.add("theme-default");
document.querySelector("body").classList.add("smart-panel-is-visible");
document.querySelector("body").classList.add("betslip-Hidden");
document.querySelector("body").classList.add("is-home-page");
}
if (router.pathname !== "/") {
document.querySelector("body").classList.add("layout-bc");
document.querySelector("body").classList.add("theme-default");
document.querySelector("body").classList.add("smart-panel-is-visible");
document.querySelector("body").classList.add("betslip-Hidden");
document.querySelector("body").classList.add("is-home-page");
}
}, []);
const animate = {
initial: {
opacity: 0,
transition: `transform 0.24s ease`,
},
animate: {
opacity: 1,
transition: `transform 0.24s ease`,
},
exit: {
opacity: 0,
transition: `transform 0.24s ease`,
},
};
const animateFlyIn = {
initial: {
opacity: 0,
x: 100,
transition: `transform 0.24s ease`,
},
animate: {
opacity: 1,
x: 0,
transition: `transform 0.24s ease`,
},
exit: {
opacity: 0,
x: 100,
transition: `transform 0.24s ease`,
},
};
const { isShowLoginModal, isLoading } = useStore();
const openLoginModal = () => {
useStore.setState({ isShowLoginModal: true });
};
const hideLoginModal = () => {
useStore.setState({ isShowLoginModal: false });
};
const LoadingNow = () => {
useStore.setState({ isLoading: true });
};
const LoadingDone = () => {
useStore.setState({ isLoading: false });
};
const router = useRouter();
return (
<>
<AnimatePresence exitBeforeEnter mode={"wait"}>
{isLoading ? (
<motion.div
key={router.route}
initial={animate.initial}
animate={animate.animate}
exit={animate.exit}
>
<LoadingSpinner router={router} />
</motion.div>
) : null}
{isShowLoginModal && (
<LoginModal
openLoginModal={openLoginModal}
isShowLoginModal={isShowLoginModal}
hideLoginModal={hideLoginModal}
LoadingNow={LoadingNow}
LoadingDone={LoadingDone}
/>
)}
</AnimatePresence>
<NavBar
isLoading={isLoading}
isShowLoginModal={isShowLoginModal}
openLoginModal={openLoginModal}
hideLoginModal={hideLoginModal}
LoadingNow={LoadingNow}
LoadingDone={LoadingDone}
router={router}
/>
<SubTransition>
<div className="layout-content-holder-bc">{children}</div>
</SubTransition>
</>
);
}
export default MainLayout;
</code></pre>
<p>+++ This error not occurs for <code>/pages</code> directory. only occurs in using <code>/app</code> directory</p>
|
[
{
"answer_id": 74520706,
"author": "Evans Benedict",
"author_id": 20560614,
"author_profile": "https://Stackoverflow.com/users/20560614",
"pm_score": 2,
"selected": false,
"text": "export default function RootLayout({ children}: {\n children: React.ReactNode\n}) {\n return (\n <html lang=\"en\">\n <div className={styles.container}>\n <header className={styles.header}>\n <>\n <Image\n priority\n src=\"/images/profile.jpg\"\n className={utilStyles.borderCircle}\n height={144}\n width={144}\n alt=\"\"\n />\n <h1 className={utilStyles.heading2Xl}>{name}</h1>\n </>\n </header>\n <main>{children}</main>\n </div>\n </html>\n );\n"
},
{
"answer_id": 74601107,
"author": "Ayhan APAYDIN",
"author_id": 4786167,
"author_profile": "https://Stackoverflow.com/users/4786167",
"pm_score": 1,
"selected": false,
"text": "layout.tsx"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20560614/"
] |
74,515,818
|
<p>I am trying to install an extension from the Visual Studio 2022 Manage Extension window.</p>
<p>It says I have to close all Visual Studio windows, which I did, but it is still not installing.</p>
|
[
{
"answer_id": 74520706,
"author": "Evans Benedict",
"author_id": 20560614,
"author_profile": "https://Stackoverflow.com/users/20560614",
"pm_score": 2,
"selected": false,
"text": "export default function RootLayout({ children}: {\n children: React.ReactNode\n}) {\n return (\n <html lang=\"en\">\n <div className={styles.container}>\n <header className={styles.header}>\n <>\n <Image\n priority\n src=\"/images/profile.jpg\"\n className={utilStyles.borderCircle}\n height={144}\n width={144}\n alt=\"\"\n />\n <h1 className={utilStyles.heading2Xl}>{name}</h1>\n </>\n </header>\n <main>{children}</main>\n </div>\n </html>\n );\n"
},
{
"answer_id": 74601107,
"author": "Ayhan APAYDIN",
"author_id": 4786167,
"author_profile": "https://Stackoverflow.com/users/4786167",
"pm_score": 1,
"selected": false,
"text": "layout.tsx"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13822943/"
] |
74,515,822
|
<p>I have some problem with useEffect. When the counter changes it causes the whole table to be rerendered, but i dont pass timer as props in table. How i can prevent this behavior?</p>
<pre><code>function App() {
const dispatch = useDispatch();
const data = useSelector(state => state.data);
const [error, setError] = useState("");
const [counter, setCounter] = useState();
useEffect(() => {
const fetchData = async (setError, setCounter) => {
try {
const response = await axios(url, token);
dispatch(getData(response.data.value));
setError("");
setCounter(180);
} catch(e) {
setError("Error!");
setCounter(180);
}}
fetchData(setError, setCounter);
const interval = setInterval(() => {
fetchData(setError, setCounter);
}, timeToReload * 1000);
const countInterval = setInterval(() =>
setCounter((prev) => prev - 1), 1000)
return () => {
clearInterval(interval);
clearInterval(countInterval);
}
},[dispatch])
const dataForTable = selectorData([...data], {name: sortArrow.columnName, order: sortArrow.sortOrder, type: sortArrow.type})
return (
<div className="App">
<div className="headerWrapper">
<div
className={error ? "LoadingStatus disconnect": "LoadingStatus connect"}>
{error && <div>{error}</div>}
{isFinite(counter) && <div>{"Reload " + counter + " sec"}</div> }
</div>
</div>
<Table specialCategory={specialCategory} data={dataForTable} sortArrow={sortArrow} setSortArrow={setSortArrow}/>
</div>
);
}
export default App;
</code></pre>
<p>I trued to useRef without useState, but nothing has changed. Maybe another props in Table component trigger the change?</p>
<p>Imptortant notice: only the body of the table is changed.<a href="https://i.stack.imgur.com/Q6pel.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q6pel.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74520706,
"author": "Evans Benedict",
"author_id": 20560614,
"author_profile": "https://Stackoverflow.com/users/20560614",
"pm_score": 2,
"selected": false,
"text": "export default function RootLayout({ children}: {\n children: React.ReactNode\n}) {\n return (\n <html lang=\"en\">\n <div className={styles.container}>\n <header className={styles.header}>\n <>\n <Image\n priority\n src=\"/images/profile.jpg\"\n className={utilStyles.borderCircle}\n height={144}\n width={144}\n alt=\"\"\n />\n <h1 className={utilStyles.heading2Xl}>{name}</h1>\n </>\n </header>\n <main>{children}</main>\n </div>\n </html>\n );\n"
},
{
"answer_id": 74601107,
"author": "Ayhan APAYDIN",
"author_id": 4786167,
"author_profile": "https://Stackoverflow.com/users/4786167",
"pm_score": 1,
"selected": false,
"text": "layout.tsx"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20199506/"
] |
74,515,850
|
<p>I use sparse matrices in COO format in my program. The COO format uses 3 separate vectors to represent the matrix: rowindex, colindex and values. I need to sort the matrix first by rowindex and then by colindex. For example, if the vectors contain:</p>
<pre><code>rowindex = [1 2 2 1 0 2 0 1 0 2 1 2]
colindex = [7 7 2 1 3 9 8 6 6 0 3 4]
values = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2]
</code></pre>
<p>(meaning that element [1,7] in the matrix has a value of 0.1, element [2,7] has a value of 0.2, element [2,2] has a value of 0.3, etc) the matrix after sorting should be:</p>
<pre><code>rowindex = [0 0 0 1 1 1 1 2 2 2 2 2]
colindex = [3 6 8 1 3 6 7 0 2 4 7 9]
values = [0.5 0.9 0.7 0.4 1.1 0.8 0.1 1.0 0.3 1.2 0.2 0.6]
</code></pre>
<p>I left some more spaces in the desired result to (hopefully) better show what I would like to achieve.</p>
<p>Can this be achieved somehow:</p>
<ul>
<li>Using the available sort functions in C++</li>
<li>Without using additional memory (e.g. additional vectors), as the sparse matrices I use are huge and almost take up all memory</li>
<li>Without having to resort to representing the matrix as an array of structs (where I know that the sort() function can be used).</li>
</ul>
<p>Some answers I found about sorting multiple vectors, perform sorting regarding values of only one of the vectors. They do not have the requirement to sort elements that have the same value in the first vector, according to the second vector.</p>
|
[
{
"answer_id": 74520706,
"author": "Evans Benedict",
"author_id": 20560614,
"author_profile": "https://Stackoverflow.com/users/20560614",
"pm_score": 2,
"selected": false,
"text": "export default function RootLayout({ children}: {\n children: React.ReactNode\n}) {\n return (\n <html lang=\"en\">\n <div className={styles.container}>\n <header className={styles.header}>\n <>\n <Image\n priority\n src=\"/images/profile.jpg\"\n className={utilStyles.borderCircle}\n height={144}\n width={144}\n alt=\"\"\n />\n <h1 className={utilStyles.heading2Xl}>{name}</h1>\n </>\n </header>\n <main>{children}</main>\n </div>\n </html>\n );\n"
},
{
"answer_id": 74601107,
"author": "Ayhan APAYDIN",
"author_id": 4786167,
"author_profile": "https://Stackoverflow.com/users/4786167",
"pm_score": 1,
"selected": false,
"text": "layout.tsx"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2466695/"
] |
74,515,885
|
<p>So I run into a problem where I Dim A as range, but when I set A = to cells(1,1) and Cell(1,1) happen to be fill in with a text let say "BB" then A = "BB" instead of range("A1"). Can someone explain to me wat going on.</p>
<p>I Haven't tried anything as I don't know where to start I have been trying to work around it but I cant anymore</p>
|
[
{
"answer_id": 74515996,
"author": "Ike",
"author_id": 16578424,
"author_profile": "https://Stackoverflow.com/users/16578424",
"pm_score": 1,
"selected": false,
"text": "A"
},
{
"answer_id": 74526265,
"author": "Lee",
"author_id": 20560688,
"author_profile": "https://Stackoverflow.com/users/20560688",
"pm_score": 0,
"selected": false,
"text": "A"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20560688/"
] |
74,515,887
|
<p>I'm trying to submit a form using Redux, however, getting an error message in the console: Uncaught Error: Actions must be plain objects. Instead, the actual type was: 'Promise'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions.</p>
<p>I am already using thunk as my middleware when creating the store. Here's the code:</p>
<pre><code>const store = createStore(reducers, compose(applyMiddleware(thunk)))
</code></pre>
<p>create post action:</p>
<pre><code>export const createPosts = (post) => async (dispatch)=>{
try {
const {data} = await api.createPost(post)
dispatch({type:'CREATE', payload:data})
} catch (error) {
console.log(error.message);
}
}
</code></pre>
<p>PS: submit form works after page is refreshed</p>
<p>Adding the requested code as per in the comments:</p>
<p>createPost controller:</p>
<pre><code>export const createPost = async (req, res) => {
const { title, message, selectedFile, creator, tags } = req.body;
const newPostMessage = new PostMessage({
title,
message,
selectedFile,
creator,
tags,
});
try {
await newPostMessage.save();
res.status(201).json(newPostMessage);
} catch (error) {
res.status(409).json({ message: error.message });
}
};
</code></pre>
<p>reducer index.js</p>
<pre><code>
import posts from "./posts";
export default combineReducers({
posts,
})
</code></pre>
<p>post reducers:</p>
<pre><code> switch (action.type) {
case 'UPDATE':
return posts.map((post)=>post._id === action.payload._id ? action.payload : post)
case "FETCH_ALL":
return action.payload;
case "CREATE":
return [...posts, action.payload];
default:
return posts;
}
};
</code></pre>
|
[
{
"answer_id": 74515996,
"author": "Ike",
"author_id": 16578424,
"author_profile": "https://Stackoverflow.com/users/16578424",
"pm_score": 1,
"selected": false,
"text": "A"
},
{
"answer_id": 74526265,
"author": "Lee",
"author_id": 20560688,
"author_profile": "https://Stackoverflow.com/users/20560688",
"pm_score": 0,
"selected": false,
"text": "A"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16604189/"
] |
74,515,907
|
<p>I am trying to implement a "Pin Message" functionality on the chat app I'm developing.</p>
<p>Chat Activity looks like this:</p>
<p><a href="https://i.stack.imgur.com/zxvGn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zxvGn.png" alt="enter image description here" /></a></p>
<p>I have a TextView above the chat RecyclerView and would like to set the text of that to the TextView value inside the RecyclerView. I can get the string value of what's inside the RecyclerView by using a PopupMenu (inside its adapter class) by showing it in a Toast for now.</p>
<p>How should I implement this? Thank you!</p>
<p>P.S. I'm still using Java.</p>
|
[
{
"answer_id": 74516181,
"author": "OneDev",
"author_id": 17781856,
"author_profile": "https://Stackoverflow.com/users/17781856",
"pm_score": 0,
"selected": false,
"text": "public interface PinMessageListener {\n\n void onPin(String value);\n\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11157146/"
] |
74,515,918
|
<p>I have following code where i fetch results from SQL server. These are razor pages, blazor framework .Net</p>
<pre><code><button @onclick="Filter">Filter</button>
@{
async Task Filter() {
await FetchFromDb();
}
</code></pre>
<p>This query runs for 18 seconds. So i want to show loading spinner. In blazor, you can use a predefined div with spinner class to do this.</p>
<pre><code><div class="spinner"> </div>
</code></pre>
<p>I want to use this div like following</p>
<pre><code>@(IsLoading) {
<div class="spinner"></div>
} else {
show results from query
}
</code></pre>
<p>For which i need to change the Filter function as follows</p>
<pre><code>async Task Filter() {
IsLoading = true;
await FetchFromDb();
IsLoading = false;
}
</code></pre>
<p>But I figured, that the whole process of changing IsLoading=true and Isloading=false is done in one go and i don't see a spinner.</p>
<p>Is there a way to change IsLoading=true, while Filter function is getting results from Db in await FetchFromDb();
?</p>
<pre><code>@(IsLoading) {
<div class="spinner"></div>
} else {
show results from query
}
async Task Filter() {
IsLoading = true;
await FetchFromDb();
IsLoading = false;
}
</code></pre>
<p>But this doesn't work. IsLoading doesn't get updated on changing IsLoading=True.</p>
|
[
{
"answer_id": 74516147,
"author": "MrC aka Shaun Curtis",
"author_id": 13065781,
"author_profile": "https://Stackoverflow.com/users/13065781",
"pm_score": 2,
"selected": false,
"text": "async Task Filter() {\n IsLoading = true;\n await FetchFromDb();\n IsLoading = false;\n}\n"
},
{
"answer_id": 74536720,
"author": "Vikram Reddy",
"author_id": 20552709,
"author_profile": "https://Stackoverflow.com/users/20552709",
"pm_score": 0,
"selected": false,
"text": "@code {\n [Inject] protected PreloadService PreloadService { get; set; }\n\n private void GetEmployees()\n {\n try\n {\n PreloadService.Show();\n\n // TODO: call the service/api to get the employees\n }\n catch\n {\n // handle exception\n }\n finally\n {\n PreloadService.Hide();\n }\n }\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2546441/"
] |
74,515,932
|
<p>I have two dataframes</p>
<pre><code>df1 = pd.DataFrame({'col1': [1,2,3], 'col2': [4,5,6]})
df2 = pd.DataFrame({'col3': [1,5,3]})
</code></pre>
<p>and would like to left merge <code>df1</code> to <code>df2</code>. I don't have a fixed merge column in <code>df1</code> though. I would like to merge on <code>col1</code> if the cell value of <code>col1</code> exists in <code>df2.col3</code> and on <code>col2</code> if the cell value of <code>col2</code> exists in <code>df2.col3</code>. So in the above example merge on <code>col1</code>, <code>col2</code> and then <code>col1</code>. (This is just an example, I actually have more than only two columns).
I could do this but I'm not sure if it's ok.</p>
<pre><code>df1 = df1.assign(merge_col = np.where(df1.col1.isin(df2.col3), df1.col1, df1.col2))
df1.merge(df2, left_on='merge_col', right_on='col3', how='left')
</code></pre>
<p>Are there any better ways to solve it?</p>
|
[
{
"answer_id": 74516147,
"author": "MrC aka Shaun Curtis",
"author_id": 13065781,
"author_profile": "https://Stackoverflow.com/users/13065781",
"pm_score": 2,
"selected": false,
"text": "async Task Filter() {\n IsLoading = true;\n await FetchFromDb();\n IsLoading = false;\n}\n"
},
{
"answer_id": 74536720,
"author": "Vikram Reddy",
"author_id": 20552709,
"author_profile": "https://Stackoverflow.com/users/20552709",
"pm_score": 0,
"selected": false,
"text": "@code {\n [Inject] protected PreloadService PreloadService { get; set; }\n\n private void GetEmployees()\n {\n try\n {\n PreloadService.Show();\n\n // TODO: call the service/api to get the employees\n }\n catch\n {\n // handle exception\n }\n finally\n {\n PreloadService.Hide();\n }\n }\n}\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11426624/"
] |
74,515,958
|
<p>i have an array of join args (columns):</p>
<pre><code>attrs = ['surname', 'name', 'patronymic', 'birth_date',
'doc_type', 'doc_series','doc_number']
</code></pre>
<p>i'm trying to join two tables just like this but i need to coalesce each column for join to behave normally (cause it wont join correctly if there are nulls)</p>
<pre><code>new_df = pre_df.join(res_df, attrs, how='leftanti')
</code></pre>
<p>i've tried listing every condition but is there a possibility to do this another way?</p>
|
[
{
"answer_id": 74563532,
"author": "schoolboychik",
"author_id": 17597010,
"author_profile": "https://Stackoverflow.com/users/17597010",
"pm_score": 2,
"selected": true,
"text": "join_attrs = [F.coalesce(pre_df[elem], F.lit('')) == F.coalesce(res_df[elem], F.lit('')) for elem in attrs]\n"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17597010/"
] |
74,515,962
|
<p>I am not sure if that is possible at all. I want when I create a tuple and iterate over it multiple *args to be created.
For example:</p>
<pre><code>alabama_state="Alabama","Montgomery","Mobile","Tuscaloosa","Dothan","Huntsville","Birmingham","Madison","Auburn","Phenix City"
state_name,capital,*metropolitan,*city=alabama_state
print(state_name)
print(capital)
print(metropolitan)
print(city)
</code></pre>
<p>I want <code>print(state_name)</code> to print <strong>Alabama</strong>, <code>print(capital)</code> to print <strong>Montgomery</strong>, <code>print(metropolitan)</code> to print everything from <strong>Mobile</strong> to <strong>Huntsville</strong> included and <code>print(city)</code> to print everything from <strong>Birmingham</strong> to the end. How can I include specific count in the *args. Didn't find useful info.</p>
|
[
{
"answer_id": 74516002,
"author": "Barmar",
"author_id": 1491895,
"author_profile": "https://Stackoverflow.com/users/1491895",
"pm_score": 0,
"selected": false,
"text": "state_name, capital, *rest = alabama_state\nmetropolitan, city = rest[:4], rest[4:]\n"
},
{
"answer_id": 74516160,
"author": "Mechanic Pig",
"author_id": 17980931,
"author_profile": "https://Stackoverflow.com/users/17980931",
"pm_score": 1,
"selected": false,
"text": "itertools.islice"
}
] |
2022/11/21
|
[
"https://Stackoverflow.com/questions/74515962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19971042/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.