qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
74,598,380
|
<p>I am unable to get few of the table columns as it requires <code>recursive query</code> which I am not good at. So basically, if its a direct transfer, then remarks section is likely to be null. And if there is a halt in between origin and destination then I need to add the stations to my remarks column.</p>
<pre><code>A to B -> nothing
B to C -> Via B
C -> D -> Via B,C
</code></pre>
<p>SQL query is:</p>
<pre><code>CREATE TABLE IPhone (Id int, Country NVARCHAR(12), seqNo int, Send datetime2(0), Arrive datetime2(0));
INSERT INTO IPhone VALUES
('1001','America','1', '2022-11-23 18:30:00.000',null),
('1002','China','2', '2022-11-24 08:18:00.000','2022-11-24 05:00:00'),
('1003','Argentina','3', '2022-11-25 18:30:00.000','2022-11-24 18:18:00.000'),
('1004','Saudi Arabia','4',null,'2022-11-25 20:30:00.000');
</code></pre>
<p>Tried</p>
<pre><code>select f.id,f.Country CountryFrom, t.Country CountryTo
, convert(varchar(4),f.seqNo) + '-' + convert(varchar(4),t.seqNo) seqNo
, f.Send, t.Arrive,concat('VIA ', f.Country ,', ', t.Country) Remarks from IPhone f inner join IPhone t on f.seqNo < t.seqNo order by id;
</code></pre>
<p>Gives</p>
<p><a href="https://i.stack.imgur.com/pNam2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pNam2.png" alt="enter image description here" /></a></p>
<p><strong>Requirement is the following.</strong> I tired looking into <a href="https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query">How to create a MySQL hierarchical recursive query?</a> but I am unbale to get the expected result. Your help is appreciated.</p>
<p><a href="https://i.stack.imgur.com/IgHKk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IgHKk.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74598510,
"author": "Benny Schärer",
"author_id": 10445130,
"author_profile": "https://Stackoverflow.com/users/10445130",
"pm_score": -1,
"selected": false,
"text": "with base as (\n\n <some initial data select>\n\n UNION ALL\n\n select ...\n from base\n \n)\nselect ...\n"
},
{
"answer_id": 74599166,
"author": "HariHaravelan",
"author_id": 2816429,
"author_profile": "https://Stackoverflow.com/users/2816429",
"pm_score": 2,
"selected": true,
"text": " SELECT f.id,\n f.country CountryFrom,\n t.country CountryTo,\n CONVERT(VARCHAR(4), f.seqno) + '-'\n + CONVERT(VARCHAR(4), t.seqno) seqNo,\n f.send,\n t.arrive,\n CASE\n WHEN t.seqno - f.seqno = 1 THEN ''\n ELSE (SELECT 'VIA '\n + (SELECT LEFT(country, Len(country) - 1)\n FROM (SELECT country + ', '\n FROM iphone\n WHERE seqno BETWEEN f.seqno + 1 AND\n t.seqno - 1\n FOR xml path ('')) c (country)))\n END Remarks\nFROM iphone f\n INNER JOIN iphone t\n ON f.seqno < t.seqno\nORDER BY id; \n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20319015/"
] |
74,598,383
|
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>ul{
display: inline;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul>hi
<li>
1234
</li>
<li>
5678
</li>
</ul>
<ul>hello
<li>
abcdef
</li>
<li>
ghijkl
</li>
</ul></code></pre>
</div>
</div>
</p>
<p>question:the ul items(hi,hello) in above css code moved a couple of places to the right if I used the css display:inline tag . But They do not get moved if I execute with a css ul tag having no display:inline value..please explain. and second question why have the circle markers disappeared ?</p>
|
[
{
"answer_id": 74598448,
"author": "CBroe",
"author_id": 1427878,
"author_profile": "https://Stackoverflow.com/users/1427878",
"pm_score": 1,
"selected": false,
"text": "ul padding-left 40px inline padding-left padding-right inline-block"
},
{
"answer_id": 74598477,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "li list-item list-style-position: outside ul{\n display: inline;\n}\nli {\n margin-left: 20px;\n} <ul>hi\n <li>\n 1234\n </li>\n <li>\n 5678\n </li>\n </ul> \n \n<ul>hello\n <li>\n abcdef\n </li>\n <li>\n ghijkl\n </li>\n </ul>"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20589585/"
] |
74,598,418
|
<p>Say I've got a class who has a property called <code>MyClass.name</code>. I'm looping through some data where I want to arrange names to either be <code>MyClass.name</code> or <code>other</code>. I've got a method:</p>
<pre><code>def return_name(self, the_name):
if the_name == self.name:
return the_name
else:
return 'other'
</code></pre>
<p>Would it make sense to rewrite the method as:</p>
<pre><code>def return_name(self, the_name):
return the_name * (self.name == the_name) + 'other' * (self.name != the_name)
</code></pre>
<p>I get that both examples produce the same output (the second might even have slightly better performance due to being branchless, but that's gotta be negligible, the method is so short that it's isn't going to affect the runtime at all), so I'm asking purely from a readability versus code length standpoint.</p>
<p>Which one is to be preferred?</p>
|
[
{
"answer_id": 74598448,
"author": "CBroe",
"author_id": 1427878,
"author_profile": "https://Stackoverflow.com/users/1427878",
"pm_score": 1,
"selected": false,
"text": "ul padding-left 40px inline padding-left padding-right inline-block"
},
{
"answer_id": 74598477,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "li list-item list-style-position: outside ul{\n display: inline;\n}\nli {\n margin-left: 20px;\n} <ul>hi\n <li>\n 1234\n </li>\n <li>\n 5678\n </li>\n </ul> \n \n<ul>hello\n <li>\n abcdef\n </li>\n <li>\n ghijkl\n </li>\n </ul>"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11350541/"
] |
74,598,432
|
<p>I have a view controller with the below UI layout.</p>
<p>There is a header view at the top with 3 labels, a footer view with 2 buttons at the bottom and an uitableview inbetween header view and footer view. The uitableview is dynamically loaded and on average has about 6 tableview cells. One of the buttons in the footer view is take screenshot button where i need to take the screenshot of full tableview. In small devices like iPhone 6, the height of the table is obviously small as it occupies the space between header view and footer view. So only 4 cells are visible to the user and as the user scrolls others cells are loaded into view. If the user taps take screen shot button without scrolling the table view, <strong>the last 2 cells are not captured in the screenshot.</strong> The current implementation tried to negate this by changing table view frame to table view content size before capturing screenshot and resetting frame after taking screenshot, but this approach is not working starting iOS 13 as the table view content size returns incorrect values.</p>
<p><a href="https://i.stack.imgur.com/5Ghbj.png" rel="nofollow noreferrer">Current UI layout implementation</a></p>
<p>Our first solution is to embed the tableview inside the scrollview and have the tableview's scroll disabled. By this way the tableview will be forced to render all cells at once. We used the below custom table view class to override intrinsicContentSize to make the tableview adjust itself to correct height based on it contents</p>
<pre><code>class CMDynamicHeightAdjustedTableView: UITableView {
override var intrinsicContentSize: CGSize {
self.layoutIfNeeded()
return self.contentSize
}
override var contentSize: CGSize {
didSet {
self.invalidateIntrinsicContentSize()
}
}
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
}
}
</code></pre>
<p><a href="https://i.stack.imgur.com/evi8j.png" rel="nofollow noreferrer">Proposed UI implementation</a></p>
<p>But we are little worried about how overriding intrinsicContentSize could affect performance and other apple's internal implementations</p>
<p>So our second solution is to set a default initial height constraint for tableview and observe the tableview's content size keypath and update the tableview height constraint accordingly. But the content size observer gets called atleast 12-14 times before the screen elements are visible to the user.</p>
<pre><code>override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.confirmationTableView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
</code></pre>
<p>}</p>
<pre><code>override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "contentSize" {
if object is UITableView {
if let newvalue = change?[.newKey], let newSize = newvalue as? CGSize {
self.confirmationTableViewHeightConstraint.constant = newSize.height
}
}
}
}
</code></pre>
<ol>
<li>Will the second approach impact performance too?</li>
<li>What is the better approach of the two?</li>
<li>Is there any alternate solution?</li>
</ol>
|
[
{
"answer_id": 74598448,
"author": "CBroe",
"author_id": 1427878,
"author_profile": "https://Stackoverflow.com/users/1427878",
"pm_score": 1,
"selected": false,
"text": "ul padding-left 40px inline padding-left padding-right inline-block"
},
{
"answer_id": 74598477,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "li list-item list-style-position: outside ul{\n display: inline;\n}\nli {\n margin-left: 20px;\n} <ul>hi\n <li>\n 1234\n </li>\n <li>\n 5678\n </li>\n </ul> \n \n<ul>hello\n <li>\n abcdef\n </li>\n <li>\n ghijkl\n </li>\n </ul>"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20620823/"
] |
74,598,438
|
<p>I have a pandas dataframe with a column named ranking_pos. All the rows of this column look like this: #123 of 12,216.</p>
<p>The output I need is only the number of the ranking, so for this example: 123 (as an integer).</p>
<p>How do I extract the number after the # and get rid of the of 12,216?</p>
<p>Currently the type of the column is object, just converting it to integer with .astype() doesn't work because of the other characters.</p>
|
[
{
"answer_id": 74598471,
"author": "DoreenBZ",
"author_id": 6054532,
"author_profile": "https://Stackoverflow.com/users/6054532",
"pm_score": 0,
"selected": false,
"text": "df.loc[:,\"ranking_pos\"] =df.loc[:,\"ranking_pos\"].str.replace(\"#\",\"\").astype(int)\n"
},
{
"answer_id": 74598564,
"author": "T C Molenaar",
"author_id": 8814131,
"author_profile": "https://Stackoverflow.com/users/8814131",
"pm_score": 2,
"selected": true,
"text": ".str.extract df['ranking_pos'].str.extract(r'#(\\d+)').astype(int)\n .str.split() df['ranking_pos'].str.split(' of ').str[0].str.replace('#', '').astype(int)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20618564/"
] |
74,598,440
|
<p>I have a table called "employment" which looks like</p>
<p><a href="https://i.stack.imgur.com/MTLBR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MTLBR.png" alt="enter image description here" /></a></p>
<p>if the boss column is empty it means he/she is the "CEO"</p>
<p>and if he/she manages one another under boss column it means "Manager"</p>
<p>else it's "Worker"</p>
<p>Finally it should look like</p>
<p><a href="https://i.stack.imgur.com/yM0c0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yM0c0.png" alt="enter image description here" /></a></p>
<p>Can you help build some query to make the following result?</p>
<p>Thank you</p>
|
[
{
"answer_id": 74598614,
"author": "Akina",
"author_id": 10138734,
"author_profile": "https://Stackoverflow.com/users/10138734",
"pm_score": 2,
"selected": true,
"text": "SELECT name,\n CASE WHEN boss = '' -- or maybe WHEN boss IS NULL \n THEN 'CEO'\n WHEN EXISTS (SELECT NULL FROM employment t2 WHERE t1.name = t2.boss)\n THEN 'MANAGER'\n ELSE 'WORKER'\n END posession\nFROM employment t1\n"
},
{
"answer_id": 74598799,
"author": "Ojaswi Awasthi",
"author_id": 14062271,
"author_profile": "https://Stackoverflow.com/users/14062271",
"pm_score": 0,
"selected": false,
"text": "select Name,\ncase \n when BOSS = \"\" then \"CEO\"\n when exists(select NULL from employment t2 where t1.NAME = t2.BOSS) then \"MANAGER\"\n else \"WORKER\"\nend as BOSS\nfrom Employment t1\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17890063/"
] |
74,598,442
|
<p>I want to get closest date from $search_date if is not same values in $array['date']. If is same value in $array['date'] I want all array.</p>
<ul>
<li>Format date is 'Y-m-d'.</li>
</ul>
<p>Example 1:</p>
<pre><code>$search_date = '2022-12-08';
$array = [{"price":"200","date":"2022-12-12"},{"price":"50","date":"2022-12-10"},{"price":"100","date":"2022-12-10"}]
Return should be: [{"price":"50","date":"2022-12-10"},{"price":"100","date":"2022-12-10"}]
</code></pre>
<p>Example 2:</p>
<pre><code>$search_date = '2022-12-08';
$array = [{"price":"200","date":"2022-12-08"},{"price":"50","date":"2022-12-09"},{"price":"100","date":"2022-12-11"}]
Return should be: [{"price":"200","date":"2022-12-08"}]
</code></pre>
<p>Example 3:</p>
<pre><code>$search_date = '2022-12-08';
$array = [{"price":"200","date":"2022-12-10"},{"price":"100","date":"2022-12-10"},{"price":"50","date":"2022-12-11"}]
Return should be: [{"price":"200","date":"2022-12-10"},{"price":"100","date":"2022-12-10"}]
</code></pre>
<p>Example 4:</p>
<pre><code>$search_date = '2022-12-08';
$array = [{"price":"200","date":"2022-12-08"},{"price":"100","date":"2022-12-08"},{"price":"50","date":"2022-12-08"}]
Return should be: [{"price":"200","date":"2022-12-08"},{"price":"100","date":"2022-12-08"},{"price":"50","date":"2022-12-08"}]
</code></pre>
<p>Thank you!</p>
|
[
{
"answer_id": 74598936,
"author": "DatIsVinnie",
"author_id": 13044558,
"author_profile": "https://Stackoverflow.com/users/13044558",
"pm_score": 0,
"selected": false,
"text": "array_search($value, $array); \n $lowest_date = null;\n\nfor ($i = 0; count($i); $i++) {\n if ($array['date'] < $lowest_date) {\n $lowest_date = $array['date'];\n }\n}\n"
},
{
"answer_id": 74599832,
"author": "Jacob Mulquin",
"author_id": 1427345,
"author_profile": "https://Stackoverflow.com/users/1427345",
"pm_score": 2,
"selected": true,
"text": "$search <?php\n\n/*\n\nQuestion Author: Catalin Iamandei\nQuestion Answerer: Jacob Mulquin\nQuestion: PHP - get closest date from array\nURL: https://stackoverflow.com/questions/74598442/php-get-closest-date-from-array\nTags: php, arrays, laravel, date, php-carbon\n\n*/\n\n$search = '2022-12-10';\n$searchObj = new DateTime($search);\n\n$records = json_decode('[{\"price\":\"200\",\"date\":\"2022-12-10\"},{\"price\":\"100\",\"date\":\"2022-12-10\"},{\"price\":\"50\",\"date\":\"2022-12-11\"}]', true);\n\n$distances = [];\nforeach ($records as $index => $record) {\n $recordObj = new DateTime($record['date']);\n $daysDiff = $searchObj->diff($recordObj)->format(\"%r%a\");\n $distances[$index] = abs($daysDiff);\n}\n\n$minimumDiff = min($distances);\n\n$output = [];\nforeach ($distances as $index => $distance) {\n if ($distance == $minimumDiff) {\n $output[] = $records[$index];\n }\n}\n\necho json_encode($output, JSON_PRETTY_PRINT);\n [\n {\n \"price\": \"50\",\n \"date\": \"2022-12-09\"\n },\n {\n \"price\": \"100\",\n \"date\": \"2022-12-11\"\n }\n]\n abs() $distances min()"
},
{
"answer_id": 74599852,
"author": "FatFreddy",
"author_id": 9322156,
"author_profile": "https://Stackoverflow.com/users/9322156",
"pm_score": 0,
"selected": false,
"text": "'2022-12-07' 2022-12-06 2022-12-08 <?php\n$SearchDate = new DateTimeImmutable('2022-12-08');\n$array = array ('{\"price\":\"200\",\"date\":\"2022-12-12\"}',\n '{\"price\":\"50\",\"date\":\"2022-12-10\"}',\n '{\"price\":\"100\",\"date\":\"2022-12-10\"}');\n$laResult = array();\nforeach($array as $jsonO) {\n $json = json_decode($jsonO);\n $CompareDate = new DateTimeImmutable($json->{'date'});\n $interval = date_diff($SearchDate, $CompareDate);\n $laThis['date'] = $json->{'date'};\n $laThis['diff'] = $interval->format('%a');\n $laThis['origin'] = $jsonO;\n $laResult[] = $laThis;\n}\n\n$min_diff = min( array_column( $laResult, 'diff') );\necho 'nearestDiff:'. $min_diff .PHP_EOL;\nforeach($laResult as $laSingleResult) {\n if($laSingleResult['diff'] == $min_diff) {\n echo $laSingleResult['origin'] .PHP_EOL;\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10033692/"
] |
74,598,490
|
<p><strong>Problem Overview :</strong></p>
<ol>
<li>Building personal website with a Homepage.js, a Sidebar.js component, and a Project.js component.</li>
<li>Project components are mapped on Homepage from a project list array of objects.</li>
<li>Sidebar.js component will open and display active project info when a Project component is clicked on.</li>
<li>App.js has activeProject state, with a default set to first project in list so sidebar doesn't throw errors.</li>
<li>End result is that Sidebar displays correct project title, info, and video src (inspect mode) on Project click, but the video itself is wrong and always shows the placeholder's video set on App.js</li>
</ol>
<p><a href="https://i.stack.imgur.com/uYgSD.png" rel="nofollow noreferrer">Props passes right info, wrong video</a></p>
<p><strong>Details :</strong></p>
<p>In my App.js I set activeProject to the first project in my list as a default, via it's title.</p>
<pre><code>const [activeProject, setActiveProject] = useState(ListOfProjects[0].title);
return (
<div className="App">
<Navigation />
<HomePage
isOpen={isOpen}
setIsOpen={setIsOpen}
activeProject={activeProject}
setActiveProject={setActiveProject}
/>
<Sidebar
isOpen={isOpen}
setIsOpen={setIsOpen}
activeProject={activeProject}
/>
<Footer />
</div>
);
</code></pre>
<p>My projects are mapped out on my Homepage.js</p>
<pre><code><div className="project-list">
{ListOfProjects.map((obj) => (
<ProjectItem
key={obj.id}
title={obj.title}
video={obj.video}
videoAlt={obj.videoAlt}
liveLink={obj.liveLink}
codeLink={obj.codeLink}
isOpen={isOpen}
setIsOpen={setIsOpen}
activeProject={activeProject}
setActiveProject={setActiveProject}
/>
))}
</div>
</code></pre>
<p>Each project component has a click event to open the sidebar component with extra project information based on the project title that was clicked on.</p>
<pre><code>const showSidebar = () => {
setActiveProject(title);
setIsOpen(!isOpen);
}
</code></pre>
<p>On Sidebar.js I have this list of props being pulled from the project with a title that matches the current active project set state.</p>
<pre><code>const {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {
return project.title === activeProject;
});
</code></pre>
<p>The result is that the sidebar component displays the correct title, project info, and even the right video src when shown in the inspection tool, but the project video is always of the first project in the list. Here is my website for more context (<a href="https://bryanfink.dev" rel="nofollow noreferrer">https://bryanfink.dev</a>)</p>
<p><strong>Things I have tried :</strong></p>
<p>I tried changing the App.js activeProject state placeholder to the second project.</p>
<pre><code>const [activeProject, setActiveProject] = useState(ListOfProjects[1].title);
</code></pre>
<p>This resulted in the Sidebar showing the correct project title, info, and video src(inspect mode) but now the video always shows the second project's video.</p>
<p>Then I tried changing the App.js activeProject state placeholder to ""</p>
<pre><code>const [activeProject, setActiveProject] = useState("");
</code></pre>
<p>But this results in errors in the sidebar.</p>
<pre><code>Sidebar.js:15 Uncaught TypeError: Cannot destructure property 'title' of '_Projects_listOfProjects__WEBPACK_IMPORTED_MODULE_2__.default.find(...)' as it is undefined
</code></pre>
|
[
{
"answer_id": 74598629,
"author": "Kriss_Vector",
"author_id": 20621722,
"author_profile": "https://Stackoverflow.com/users/20621722",
"pm_score": 2,
"selected": false,
"text": "|| {} ListOfProjects.find((project) => { return project.title === activeProject; }) {} const {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || {};\n"
},
{
"answer_id": 74598737,
"author": "Ibrahim shamma",
"author_id": 12613405,
"author_profile": "https://Stackoverflow.com/users/12613405",
"pm_score": 0,
"selected": false,
"text": "const defaultProject = {\ntitle: \"\",\nliveLink: \"\",\n}\nconst {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || defaultProject;\n\n title .find"
},
{
"answer_id": 74600322,
"author": "Jay F.",
"author_id": 20504019,
"author_profile": "https://Stackoverflow.com/users/20504019",
"pm_score": 0,
"selected": false,
"text": "src <source /> load() useEffect(() => {\n document.querySelector(\"video\").load();\n}, [])\n video src useEffect className=\"sidebar-video\" <video /> useEffect(() => {\n document.querySelector(\".sidebar-video\").load();\n}, [title]);\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19838086/"
] |
74,598,498
|
<pre><code>
</code></pre>
<p>import Cookies from 'universal-cookie';
const cookies = new Cookies();</p>
<pre><code>
cookies.set('jwt', "chalmeraputt");
console.log(cookies.get("jwt"));
</code></pre>
<p>I have using this code to add cookie but could not get it and also not showed in the browser also.</p>
|
[
{
"answer_id": 74598629,
"author": "Kriss_Vector",
"author_id": 20621722,
"author_profile": "https://Stackoverflow.com/users/20621722",
"pm_score": 2,
"selected": false,
"text": "|| {} ListOfProjects.find((project) => { return project.title === activeProject; }) {} const {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || {};\n"
},
{
"answer_id": 74598737,
"author": "Ibrahim shamma",
"author_id": 12613405,
"author_profile": "https://Stackoverflow.com/users/12613405",
"pm_score": 0,
"selected": false,
"text": "const defaultProject = {\ntitle: \"\",\nliveLink: \"\",\n}\nconst {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || defaultProject;\n\n title .find"
},
{
"answer_id": 74600322,
"author": "Jay F.",
"author_id": 20504019,
"author_profile": "https://Stackoverflow.com/users/20504019",
"pm_score": 0,
"selected": false,
"text": "src <source /> load() useEffect(() => {\n document.querySelector(\"video\").load();\n}, [])\n video src useEffect className=\"sidebar-video\" <video /> useEffect(() => {\n document.querySelector(\".sidebar-video\").load();\n}, [title]);\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20457014/"
] |
74,598,513
|
<p>This question have been asked multiple times in this community but I couldn't find the correct answers since I am beginner in Python. I got 2 questions actually:</p>
<ol>
<li>I want to concatenate 3 columns (A,B,C) with its value into 1 Column. Header would be ABC.</li>
</ol>
<p>import os
import pandas as pd</p>
<p>directory = 'C:/Path'
ext = ('.csv')</p>
<p>for filename in os.listdir(directory):
f = os.path.join(directory, filename)</p>
<pre><code>if f.endswith(ext):
head_tail = os.path.split(f)
head_tail1 = 'C:/Output'
k =head_tail[1]
r=k.split(".")[0]
p=head_tail1 + "/" + r + " - Revised.csv"
mydata = pd.read_csv(f)
new =mydata[["A","B","C","D"]]
new = new.rename(columns={'D': 'Total'})
new['Total'] = 1
new.to_csv(p ,index=False)
</code></pre>
<ol start="2">
<li>Once concatenated, is it possible to count the uniqueid and put the total in Column D? Basically, to get the total count per uniqueid (Column ABC),the data can be found on a link when you click that UniqueID. For ex: Column ABC - uniqueid1, -> click -> go to the next page, total of that uniqueid.</li>
</ol>
<p>On the link page, you can get the total numbers of uniqueid by Serial ID</p>
<p>I have no idea how to do this, but I would really appreciate if someone can help me on this project and would learn a lot from this.</p>
<p>Thank you very much. God Bless</p>
<p>Searched in Google, Youtube and Stackoverflow, couldn't find the correct answer.</p>
|
[
{
"answer_id": 74598629,
"author": "Kriss_Vector",
"author_id": 20621722,
"author_profile": "https://Stackoverflow.com/users/20621722",
"pm_score": 2,
"selected": false,
"text": "|| {} ListOfProjects.find((project) => { return project.title === activeProject; }) {} const {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || {};\n"
},
{
"answer_id": 74598737,
"author": "Ibrahim shamma",
"author_id": 12613405,
"author_profile": "https://Stackoverflow.com/users/12613405",
"pm_score": 0,
"selected": false,
"text": "const defaultProject = {\ntitle: \"\",\nliveLink: \"\",\n}\nconst {title, liveLink, codeLink, video, videoAlt, tags, details, challenges, lessons} = ListOfProjects.find((project) => {\n return project.title === activeProject;\n}) || defaultProject;\n\n title .find"
},
{
"answer_id": 74600322,
"author": "Jay F.",
"author_id": 20504019,
"author_profile": "https://Stackoverflow.com/users/20504019",
"pm_score": 0,
"selected": false,
"text": "src <source /> load() useEffect(() => {\n document.querySelector(\"video\").load();\n}, [])\n video src useEffect className=\"sidebar-video\" <video /> useEffect(() => {\n document.querySelector(\".sidebar-video\").load();\n}, [title]);\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20610995/"
] |
74,598,544
|
<p>I want to get previous and next news order by date. The code below works fine if there is only one news a day. But cannot handle multiple news on the same day.</p>
<p><strong>NewsController.php</strong></p>
<pre><code>public function detail($slug){
$news = \App\News::active()->where('slug', $slug)->firstOrFail();
$prev_news = \App\News::whereDate('date', '>', $news->date)->active()->orderBy('date', 'desc')->first();
$next_news = \App\News::whereDate('date', '<', $news->date)->active()->orderBy('date', 'desc')->first();
}
</code></pre>
<p><strong>web.php</strong></p>
<pre><code> Route::get('/news/{slug}', 'NewsController@detail')->name('news');
</code></pre>
<p>Thanks</p>
|
[
{
"answer_id": 74598619,
"author": "Delano van londen",
"author_id": 19923550,
"author_profile": "https://Stackoverflow.com/users/19923550",
"pm_score": 1,
"selected": false,
"text": "$prev_news = $news->whereDate('date', '>', $news->date)->active()->orderBy('date', 'desc')->get();\n\n$next_news = $news->whereDate('date', '<', $news->date)->active()->orderBy('date', 'desc')->get();\n"
},
{
"answer_id": 74675257,
"author": "Wilson",
"author_id": 7573253,
"author_profile": "https://Stackoverflow.com/users/7573253",
"pm_score": 1,
"selected": true,
"text": "$news = \\App\\News::active()->where('slug', $slug)->firstOrFail();\n\n$prev_news = \\App\\News::withDescription()->where(function($query) use($news){\n $query->where(function($query) use($news){\n $query->whereDate('date', $news->date)->where('id', '<', $news->id);\n })->orWhereDate('date', '>', $news->date);\n})->online()->orderBy('date', 'asc')->orderBy('id', 'desc')->active()->first();\n\n$next_news = \\App\\News::withDescription()->where(function($query) use($news){\n $query->where(function($query) use($news){\n $query->whereDate('date', $news->date)->where('id', '>', $news->id);\n })->orWhereDate('date', '<', $news->date);\n})->online()->orderBy('date', 'desc')->orderBy('id', 'asc')->active()->first();\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7573253/"
] |
74,598,555
|
<p>This is the full script:</p>
<pre><code>(venv) ubuntu@ubuntu:~$ pip install wxPython
Collecting wxPython
Using cached wxPython-4.2.0.tar.gz (71.0 MB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-jlwwpkvj/wxpython_66c7996a596740a4b92c4f3a3724336d/setup.py", line 27, in <module>
from buildtools.config import Config, msg, opj, runcmd, canGetSOName, getSOName
File "/tmp/pip-install-jlwwpkvj/wxpython_66c7996a596740a4b92c4f3a3724336d/buildtools/config.py", line 30, in <module>
from attrdict import AttrDict
File "/home/ubuntu/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/attrdict/__init__.py", line 5, in <module>
from attrdict.mapping import AttrMap
File "/home/ubuntu/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/attrdict/mapping.py", line 4, in <module>
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
(venv) ubuntu@ubuntu:~$
</code></pre>
<p>I think cause of the problem is virtuel machine. I can download packages on my host OS.
I am using UTM for ubuntu.</p>
<p>I try updating pip and setuptolls. I reinstalled differently ubuntu for multiple times.
I am searcing forums for weeks and still nothing.</p>
|
[
{
"answer_id": 74598619,
"author": "Delano van londen",
"author_id": 19923550,
"author_profile": "https://Stackoverflow.com/users/19923550",
"pm_score": 1,
"selected": false,
"text": "$prev_news = $news->whereDate('date', '>', $news->date)->active()->orderBy('date', 'desc')->get();\n\n$next_news = $news->whereDate('date', '<', $news->date)->active()->orderBy('date', 'desc')->get();\n"
},
{
"answer_id": 74675257,
"author": "Wilson",
"author_id": 7573253,
"author_profile": "https://Stackoverflow.com/users/7573253",
"pm_score": 1,
"selected": true,
"text": "$news = \\App\\News::active()->where('slug', $slug)->firstOrFail();\n\n$prev_news = \\App\\News::withDescription()->where(function($query) use($news){\n $query->where(function($query) use($news){\n $query->whereDate('date', $news->date)->where('id', '<', $news->id);\n })->orWhereDate('date', '>', $news->date);\n})->online()->orderBy('date', 'asc')->orderBy('id', 'desc')->active()->first();\n\n$next_news = \\App\\News::withDescription()->where(function($query) use($news){\n $query->where(function($query) use($news){\n $query->whereDate('date', $news->date)->where('id', '>', $news->id);\n })->orWhereDate('date', '<', $news->date);\n})->online()->orderBy('date', 'desc')->orderBy('id', 'asc')->active()->first();\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20621727/"
] |
74,598,563
|
<p>How can I do something like this on python :</p>
<pre class="lang-py prettyprint-override"><code>class Game:
def __init__(self, size: int):
self.settings = {
'timeout_turn' = 0
'timeout_match' = 0
'max_memory' = 0
'time_left' = 2147483647
'game_type' = 0
'rule' = 0
'evaluate' = 0
'folder' = './'
}
</code></pre>
<p>there is an error, I think this is not the right way to do it but I didn't find an other solution.</p>
<p>Thanks in advance</p>
|
[
{
"answer_id": 74598585,
"author": "Bas van der Linden",
"author_id": 11119684,
"author_profile": "https://Stackoverflow.com/users/11119684",
"pm_score": 3,
"selected": true,
"text": "= : , class Game:\n def __init__(self, size: int):\n self.settings = { \n 'timeout_turn': 0,\n 'timeout_match': 0,\n 'max_memory': 0,\n 'time_left': 2147483647,\n 'game_type': 0,\n 'rule': 0,\n 'evaluate': 0,\n 'folder': './'\n }\n settings"
},
{
"answer_id": 74598618,
"author": "Ghassen Sultana",
"author_id": 12986294,
"author_profile": "https://Stackoverflow.com/users/12986294",
"pm_score": 2,
"selected": false,
"text": "class Game:\n def __init__(self, size: int):\n self.settings = { \n 'timeout_turn' : 0,\n 'timeout_match' : 0,\n 'max_memory' : 0,\n 'time_left' : 2147483647,\n 'game_type' : 0,\n 'rule' : 0,\n 'evaluate' : 0,\n 'folder' : './',\n }\n"
},
{
"answer_id": 74598635,
"author": "Kupofty",
"author_id": 12134984,
"author_profile": "https://Stackoverflow.com/users/12134984",
"pm_score": 1,
"selected": false,
"text": ": = class Game:\n\ndef __init__(self, size: int):\n self.timeout_turn=0\n self.max_memory=0\n ....\n \n \n"
},
{
"answer_id": 74598713,
"author": "Volodymyr Pivoshenko",
"author_id": 20554409,
"author_profile": "https://Stackoverflow.com/users/20554409",
"pm_score": 1,
"selected": false,
"text": "dict : = class Game:\n\n def __init__(self, size: int) -> None:\n \"\"\"Initialize.\"\"\"\n\n self.settings = {\n \"timeout_turn\": 0,\n \"timeout_match\": 0,\n \"max_memory\": 0,\n \"time_left\": 2147483647,\n \"game_type\": 0,\n \"rule\": 0,\n \"evaluate\": 0,\n \"folder\": \"./\",\n }\n class Game:\n\n def __init__(self, size: int) -> None:\n \"\"\"Initialize.\"\"\"\n\n self.timeout_turn = 0\n self.timeout_match = 0\n\n ...\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18326919/"
] |
74,598,586
|
<p>In a tutorial on Laravel (*1) it is said that the controller name should be plural instead of singular. I am surprised because Laravel always generates the controller automatically in singular. There was also the question in 2018 in the Laravel Context here in the SO (*2). Has anything changed here in this regard? Is there a general valid statement here or is this a matter of taste. For me personally, singular makes total sense.</p>
<p>*1 <a href="https://youtu.be/L1owEfA9ioc?t=148" rel="nofollow noreferrer">https://youtu.be/L1owEfA9ioc?t=148</a></p>
<p>*2 <a href="https://stackoverflow.com/questions/48031176/laravel-controller-name-should-be-plural-or-singular">laravel controller name should be plural or singular?</a></p>
|
[
{
"answer_id": 74598968,
"author": "keepyourmouthshut",
"author_id": 10408643,
"author_profile": "https://Stackoverflow.com/users/10408643",
"pm_score": 0,
"selected": false,
"text": "PHP artisan make:model Todo -a php artisan stub:publish"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18066399/"
] |
74,598,625
|
<p>HTML and Lists are on a new level for me with this question.
I am trying to create a nested list in HTML with related numbering and in the third level a alpa numbering type.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
padding-left: 100px;
}
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;
}
ol>li {
display: table;
counter-increment: item;
margin-bottom: 0.6em;
}
ol>li:before {
content: counters(item, ".",decimal-leading-zero) ". ";
display: table-cell;
padding-right: 0.6em;
}
li ol>li {
margin: 0;
}
li ol>li:before {
content: counters(item, ".",decimal-leading-zero) " ";
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><ol>
<li>
<ol>
<li></li>
<li></li>
<li></li>
</ol>
</li>
<li></li>
<li></li>
<li>
<ol>
<li></li>
<li>
<ol>
<li></li>
<li></li>
<li></li>
</ol>
</li>
</ol>
</li>
</ol></code></pre>
</div>
</div>
</p>
<p>Above is what I have. And that results in :</p>
<pre><code>01.
01.01
01.02
01.03
02.
03.
04.
04.01
04.02
04.02.01
04.02.02
04.02.03
</code></pre>
<p>But I am looking for:</p>
<pre><code>01.
01.01
01.02
01.03
02.
03.
04.
04.01
04.02
a. ←
b. ←
c. ←
04.03
</code></pre>
<p>Does anyone have a idea how to solve this?</p>
<p>I already tried numerise solution and searched the web. That is how I came to the above solution. But I could not find the third level lower-alpha type style solution.</p>
|
[
{
"answer_id": 74598768,
"author": "Kairav Thakar",
"author_id": 20447312,
"author_profile": "https://Stackoverflow.com/users/20447312",
"pm_score": 2,
"selected": false,
"text": "ol {\n list-style-type: none;\n counter-reset: item;\n margin: 0;\n padding: 0;\n }\n\n ol>li {\n display: block;\n counter-increment: item;\n margin-bottom: 0.6em;\n padding-left: 15px;\n }\n\n ol>li:before {\n content: counters(item, \".\",decimal-leading-zero) \". \";\n display: table-cell;\n padding-right: 0.6em;\n }\n\n li ol>li {\n margin: 0;\n }\n\n li ol>li:before {\n content: counters(item, \".\",decimal-leading-zero) \" \";\n }\n \n ol>li>ol>li>ol\n {\n counter-reset: listStyle;\n }\n \n ol>li>ol>li>ol li{\n margin-left: 1em;\n counter-increment: listStyle;\n}\n \n ol>li>ol>li>ol li::before {\n margin-right: 1em;\n content: counter(listStyle, lower-alpha);\n} <html>\n\n<head>\n\n</head>\n\n<body>\n\n</body>\n<ol>\n <li>\n <ol>\n <li></li>\n <li></li>\n <li></li>\n </ol>\n </li>\n <li></li>\n <li></li>\n <li>\n <ol>\n <li></li>\n <li>\n <ol>\n <li></li>\n <li></li>\n <li></li>\n </ol>\n </li>\n </ol>\n </li>\n </ol>\n</body>\n\n</html> ol li ol lower-alpha"
},
{
"answer_id": 74598892,
"author": "Pete",
"author_id": 1790982,
"author_profile": "https://Stackoverflow.com/users/1790982",
"pm_score": 1,
"selected": true,
"text": "ol {\n list-style-type: none;\n counter-reset: item;\n margin: 0;\n padding: 0;\n}\n\nol>li {\n display: table;\n counter-increment: item;\n margin-bottom: 0.6em;\n}\n\nol>li:before {\n content: counters(item, \".\", decimal-leading-zero) \". \";\n display: table-cell;\n padding-right: 0.6em;\n}\n\nli ol>li {\n margin: 0;\n}\n\nli ol>li:before {\n content: counters(item, \".\", decimal-leading-zero) \" \";\n}\n\n/* below styles added, nothing else changed */\n\nol ol ol {\n list-style-type: lower-alpha;\n}\n\nol ol ol li {\n display:list-item;\n margin-left: 1em;\n}\nol ol ol li:before {\n content: none;\n} <ol>\n <li>\n <ol>\n <li></li>\n <li></li>\n <li></li>\n </ol>\n </li>\n <li></li>\n <li></li>\n <li>\n <ol>\n <li></li>\n <li>\n <ol>\n <li></li>\n <li></li>\n <li></li>\n </ol>\n </li>\n </ol>\n </li>\n</ol>"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14669927/"
] |
74,598,636
|
<p>I want to get all the positions (indexes) of an element in a string and store them in a dictionary.</p>
<p>This is what I've tried:</p>
<pre><code>string = "This is an example"
test = {letter: pos for pos, letter in enumerate(string)}
</code></pre>
<p>But this only gives the last position of the letter. I'd like all positions, desired output:</p>
<pre><code>test["a"]
{8, 13}
</code></pre>
|
[
{
"answer_id": 74598678,
"author": "Abdul Niyas P M",
"author_id": 6699447,
"author_profile": "https://Stackoverflow.com/users/6699447",
"pm_score": 2,
"selected": false,
"text": ">>> my_dict = {}\n>>> my_dict['my_val'] = 1 # creating new value\n>>> my_dict\n{'my_val': 1}\n>>> my_dict['my_val'] = 2 # overwriting the value for `my_val`\n>>> my_dict\n{'my_val': 2}\n dict.setdefault >>> print(dict.setdefault.__doc__)\nInsert key with a value of default if key is not in the dictionary.\nReturn the value for key if key is in the dictionary, else default.\n>>>\n>>> result = {}\n>>> string = \"This is an example\"\n>>> \n>>> for index, value in enumerate(string):\n... result.setdefault(value, []).append(index)\n... \n>>> result[\"a\"]\n[8, 13]\n"
},
{
"answer_id": 74598901,
"author": "Bhavesh Rathod",
"author_id": 19997160,
"author_profile": "https://Stackoverflow.com/users/19997160",
"pm_score": 1,
"selected": false,
"text": "output = {}\n input_string \"This is an example\" input_string = \"This is an example\"\n index character output.setdefault(character, []) character output character [] character .append(index) index character for index, character in enumerate(input_string):\n output.setdefault(character, []).append(index) \n \n output[\"i\"]\n[2, 5]\n output = {}\n\ninput_string = \"This is an example\"\n\nfor index, character in enumerate(input_string):\n output.setdefault(character, []).append(index) \n \n output = {}\n\ninput_string = \"This is an example\"\n\nfor index, character in enumerate(input_string):\n output.setdefault(character, set()).add(index) \n \n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20279847/"
] |
74,598,649
|
<p>To explain about the program that I am making, it is program that asks the user how many times he would like his coin to flip. In this program, the coin of the head is even, and the odd is the tail.</p>
<p>I created a script that randomizes numbers from 1 to 10 based on the number you entered. And also I've made the script that how many odd and even numbers had come out, but I don't know how to make a script that shows how many times do each of the 10 random numbers occur and which number occurred most often.</p>
<p>Here is the script that I have made:</p>
<pre><code>import java.util.*;
public class GreatCoinFlipping {
public static void main(String[] args) {
System.out.println("How many times do you want to flip the coin? : ");
Scanner sc = new Scanner(System.in);
int amount = sc.nextInt();
int[] arrNum = new int[amount];
int even = 0, odd = 0;
for (int i = 0; i < amount ; i++) {
arrNum[i] = (int)(Math.random() * 10 + 1);
System.out.println(arrNum[i]);
if (arrNum[i] % 2 == 0) even++;
else odd++;
}//end for
System.out.println("Head: " + even + ", Tail: " + odd);
}//end main
}//end class
</code></pre>
<p>What I am expecting on this script that that I want to make the script that shows how many times do each of the 10 random numbers occur and which number occurred most often and I want to make it by the count method. But the ramdon number part has to be in array method. Can someone please help me with this problem?</p>
|
[
{
"answer_id": 74598678,
"author": "Abdul Niyas P M",
"author_id": 6699447,
"author_profile": "https://Stackoverflow.com/users/6699447",
"pm_score": 2,
"selected": false,
"text": ">>> my_dict = {}\n>>> my_dict['my_val'] = 1 # creating new value\n>>> my_dict\n{'my_val': 1}\n>>> my_dict['my_val'] = 2 # overwriting the value for `my_val`\n>>> my_dict\n{'my_val': 2}\n dict.setdefault >>> print(dict.setdefault.__doc__)\nInsert key with a value of default if key is not in the dictionary.\nReturn the value for key if key is in the dictionary, else default.\n>>>\n>>> result = {}\n>>> string = \"This is an example\"\n>>> \n>>> for index, value in enumerate(string):\n... result.setdefault(value, []).append(index)\n... \n>>> result[\"a\"]\n[8, 13]\n"
},
{
"answer_id": 74598901,
"author": "Bhavesh Rathod",
"author_id": 19997160,
"author_profile": "https://Stackoverflow.com/users/19997160",
"pm_score": 1,
"selected": false,
"text": "output = {}\n input_string \"This is an example\" input_string = \"This is an example\"\n index character output.setdefault(character, []) character output character [] character .append(index) index character for index, character in enumerate(input_string):\n output.setdefault(character, []).append(index) \n \n output[\"i\"]\n[2, 5]\n output = {}\n\ninput_string = \"This is an example\"\n\nfor index, character in enumerate(input_string):\n output.setdefault(character, []).append(index) \n \n output = {}\n\ninput_string = \"This is an example\"\n\nfor index, character in enumerate(input_string):\n output.setdefault(character, set()).add(index) \n \n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20079200/"
] |
74,598,654
|
<p>edit : Sorry gurus, I have to rephrase my question since I forgot there are 3 tables in one query.
I have three tables with tbl_goods ,tbl_units and tbl_sat which looks like this :</p>
<p>tbl_goods, consists of sold goods</p>
<pre><code> +--------+-------+-------+-------+
| goods |code |qty |unit |
+--------+-------+-------+-------+
| cigar | G001 | 1 | pack |
| cigar | G001 | 2 | pcs |
| bread | G002 | 2 | pcs |
| soap | G003 | 1 | pcs |
+--------+-------+-------+-------+
</code></pre>
<p>and tbl_units as below :</p>
<pre><code> +--------+-------------+-------+
| code |ucode |qty |
+--------+-------------+-------+
| KG001 | U001 | 10 |
+--------+-------------+-------+
</code></pre>
<p>I add letter 'K' in front of code in tbl_units to differ and make sure not collide with code in tbl_goods.</p>
<p>and tbl_sat as below :</p>
<pre><code> +--------+-------------+
| ucode | unit |
+--------+-------------+
| U001 | pack |
+--------+-------------+
| U002 | box |
+--------+-------------+
| U003 | crate | etc
</code></pre>
<p>so only cigar will have conversion because table units have the code</p>
<p>what the result I need to show as below :</p>
<pre><code> +--------+-------+-------+-------+--------+
| goods |code |qty |unit | total |
+--------+-------+-------+-------+--------+
| cigar | G001 | 1 | pack | 10 |
| cigar | G001 | 2 | pcs | 2 |
| bread | G002 | 2 | pcs | 2 |
| soap | G003 | 1 | pcs | 1 |
+--------+-------+-------+-------+--------+
</code></pre>
<p>so if the code in goods doesn't have match in tbl_units then it will show just as qty in tbl_goods, but if they match then it will convert multiply from tbl_units</p>
<p>Thank you very much..really appreciated</p>
<p>regards</p>
<p>EDIT (might worked ?) :
I try to modify from @danielpr query, and this is the result
think it worked, please help to check it out</p>
<pre><code>SELECT j.code,j.qty ,j.unit, IIF(j.unit=t.unit,j.qty*u.qty,j.fqty) FROM tbl_goods j
LEFT JOIN tbl_units u on u.code ='K' || j.code
LEFT JOIN tbl_sat t ON t.ucode =u.ucode [WHERE j.code='G001']
GROUP BY j.code,j.qty
</code></pre>
<p>[WHERE ..] optional if omitted will list all items, but if I just want to check the cigar..just put WHERE CLAUSE</p>
|
[
{
"answer_id": 74598885,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 3,
"selected": true,
"text": "LEFT JOIN CASE WHEN COALESCE CASE WHEN SELECT g.goods, g.code, g.qty, g.unit, \nCASE WHEN u.conversion IS NULL \n THEN g.qty\n ELSE g.qty * u.qty\n END AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u\nON g.code = u.code\nAND g.unit = u.conversion;\n COALESCE SELECT g.goods, g.code, g.qty, g.unit, \ng.qty * COALESCE(u.qty,1) AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u\nON g.code = u.code\nAND g.unit = u.conversion;\n CASE WHEN CASE WHEN COALESCE CASE WHEN SELECT g.goods, g.code, g.qty, g.unit, \nCASE WHEN u.qty IS NULL OR u.ucode IS NULL OR t.unit IS NULL\n THEN g.qty\n ELSE g.qty * u.qty\n END AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u ON u.code = CONCAT('K', g.code)\nLEFT JOIN tbl_sat t ON u.ucode = t.ucode AND g.unit = t.unit;\n"
},
{
"answer_id": 74598962,
"author": "danielpr",
"author_id": 2714096,
"author_profile": "https://Stackoverflow.com/users/2714096",
"pm_score": 1,
"selected": false,
"text": "SELECT\n tbl_goods.goods\n, tbl_goods.code\n, tbl_goods.qty\n, tbl_goods.unit\n, IF(tbl_goods.unit=tbl_units.conversion,tbl_goods.qty*tbl_units.qty,tbl_goods.qty) total \nFROM tbl_goods\nLEFT JOIN tbl_units ON tbl_goods.code=tbl_units.code\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13553946/"
] |
74,598,656
|
<p>I have a dataset in excel which looks like this:</p>
<p><a href="https://i.stack.imgur.com/Ndulc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ndulc.png" alt="enter image description here" /></a></p>
<p>There can be more cells with data. I am trying to extract data from these big cells and paste values to more comprehensive table, which should look like this:</p>
<p><a href="https://i.stack.imgur.com/xWCsD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xWCsD.png" alt="enter image description here" /></a></p>
<p>What would be the best way to proceed? I imagine process should look like this:
Select range of filled cells, store row count as value
Do a loop for that many rows as value
Store whole cell value as string
Find "Btc = *" and store it as btc value. Paste that value into prefered table
Find "Qua= *" and store it as qua value. Paste that value into prefered table
..etc
Clean up cells in new table using Replace</p>
<p>I am stuck on extracting part of text to value. What function can I use to assign that "Btc = *" to variable? Like operator gets be a whole string, but I only need parts of it
Or maybe you have ideas on how to do this task easier?</p>
|
[
{
"answer_id": 74598885,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 3,
"selected": true,
"text": "LEFT JOIN CASE WHEN COALESCE CASE WHEN SELECT g.goods, g.code, g.qty, g.unit, \nCASE WHEN u.conversion IS NULL \n THEN g.qty\n ELSE g.qty * u.qty\n END AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u\nON g.code = u.code\nAND g.unit = u.conversion;\n COALESCE SELECT g.goods, g.code, g.qty, g.unit, \ng.qty * COALESCE(u.qty,1) AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u\nON g.code = u.code\nAND g.unit = u.conversion;\n CASE WHEN CASE WHEN COALESCE CASE WHEN SELECT g.goods, g.code, g.qty, g.unit, \nCASE WHEN u.qty IS NULL OR u.ucode IS NULL OR t.unit IS NULL\n THEN g.qty\n ELSE g.qty * u.qty\n END AS total\nFROM \ntbl_goods g\nLEFT JOIN tbl_units u ON u.code = CONCAT('K', g.code)\nLEFT JOIN tbl_sat t ON u.ucode = t.ucode AND g.unit = t.unit;\n"
},
{
"answer_id": 74598962,
"author": "danielpr",
"author_id": 2714096,
"author_profile": "https://Stackoverflow.com/users/2714096",
"pm_score": 1,
"selected": false,
"text": "SELECT\n tbl_goods.goods\n, tbl_goods.code\n, tbl_goods.qty\n, tbl_goods.unit\n, IF(tbl_goods.unit=tbl_units.conversion,tbl_goods.qty*tbl_units.qty,tbl_goods.qty) total \nFROM tbl_goods\nLEFT JOIN tbl_units ON tbl_goods.code=tbl_units.code\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4700561/"
] |
74,598,689
|
<p>Given a <a href="https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.DataFrame.html" rel="nofollow noreferrer">PySpark DataFrame</a> is it possible to obtain a list of source columns that are being referenced by the DataFrame?</p>
<p>Perhaps a more concrete example might help explain what I'm after. Say I have a DataFrame defined as:</p>
<pre class="lang-py prettyprint-override"><code>import pyspark.sql.functions as func
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
source_df = spark.createDataFrame(
[("pru", 23, "finance"), ("paul", 26, "HR"), ("noel", 20, "HR")],
["name", "age", "department"],
)
source_df.createOrReplaceTempView("people")
sqlDF = spark.sql("SELECT name, age, department FROM people")
df = sqlDF.groupBy("department").agg(func.max("age").alias("max_age"))
df.show()
</code></pre>
<p>which returns:</p>
<pre><code>+----------+--------+
|department|max_age |
+----------+--------+
| finance| 23|
| HR| 26|
+----------+--------+
</code></pre>
<p>The columns that are referenced by <code>df</code> are <code>[department, age]</code>. Is it possible to get that list of referenced columns programatically?</p>
<p>Thanks to <a href="https://stackoverflow.com/questions/54124386/capturing-the-result-of-explain-in-pyspark">Capturing the result of explain() in pyspark</a> I know I can extract the plan as a string:</p>
<pre class="lang-py prettyprint-override"><code>df._sc._jvm.PythonSQLUtils.explainString(df._jdf.queryExecution(), "formatted")
</code></pre>
<p>which returns:</p>
<pre><code>== Physical Plan ==
AdaptiveSparkPlan (6)
+- HashAggregate (5)
+- Exchange (4)
+- HashAggregate (3)
+- Project (2)
+- Scan ExistingRDD (1)
(1) Scan ExistingRDD
Output [3]: [name#0, age#1L, department#2]
Arguments: [name#0, age#1L, department#2], MapPartitionsRDD[4] at applySchemaToPythonRDD at NativeMethodAccessorImpl.java:0, ExistingRDD, UnknownPartitioning(0)
(2) Project
Output [2]: [age#1L, department#2]
Input [3]: [name#0, age#1L, department#2]
(3) HashAggregate
Input [2]: [age#1L, department#2]
Keys [1]: [department#2]
Functions [1]: [partial_max(age#1L)]
Aggregate Attributes [1]: [max#22L]
Results [2]: [department#2, max#23L]
(4) Exchange
Input [2]: [department#2, max#23L]
Arguments: hashpartitioning(department#2, 200), ENSURE_REQUIREMENTS, [plan_id=60]
(5) HashAggregate
Input [2]: [department#2, max#23L]
Keys [1]: [department#2]
Functions [1]: [max(age#1L)]
Aggregate Attributes [1]: [max(age#1L)#12L]
Results [2]: [department#2, max(age#1L)#12L AS max_age#13L]
(6) AdaptiveSparkPlan
Output [2]: [department#2, max_age#13L]
Arguments: isFinalPlan=false
</code></pre>
<p>which is useful, however its not what I need. I need a list of the referenced columns. Is this possible?</p>
<p>Perhaps another way of asking the question is... is there a way to obtain the explain plan as an object that I can iterate over/explore?</p>
|
[
{
"answer_id": 74611155,
"author": "user8523750",
"author_id": 8523750,
"author_profile": "https://Stackoverflow.com/users/8523750",
"pm_score": -1,
"selected": false,
"text": "for field in df.schema.fields:\n print(field.name +\" , \"+str(field.dataType))\n"
},
{
"answer_id": 74646188,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 2,
"selected": false,
"text": ">>> df._jdf.queryExecution().executedPlan().apply(0).output().apply(0).toString()\nu'department#1621'\n>>> df._jdf.queryExecution().executedPlan().apply(0).output().apply(1).toString()\nu'max_age#1632L'\n apply plan = df._jdf.queryExecution().executedPlan()\nsteps = [ plan.apply(i).toString() for i in range(1,100) if not isinstance(plan.apply(i), type(None)) ]\n size"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/201657/"
] |
74,598,694
|
<p>I'm building a group of buttons with Angular and Angular Material using the Button component and what I'm trying to achieve is the same behaviour of Button Toggle but with normal Button component, in order to use all the available styles.</p>
<p>In my angular component I have an array which is used to create the buttons:</p>
<pre><code>buttonNames: string[] = ['1', '2', '3', '4'];
</code></pre>
<p>Then in the html file I use the ngFor directive:</p>
<pre><code><button mat-raised-button *ngFor="let num of buttonNames">{{ num }}</button>
</code></pre>
<p>Now my goal is to have a way to change the button's color on click event, and to reset the color of the previous selected one. <br />
As an example: <br />
this should be the <a href="https://i.stack.imgur.com/TZPZE.png" rel="nofollow noreferrer">initial state</a> then when i press on another button (i.e. the second) this should happen <a href="https://i.stack.imgur.com/hbPYk.png" rel="nofollow noreferrer">changed state</a>.</p>
|
[
{
"answer_id": 74611155,
"author": "user8523750",
"author_id": 8523750,
"author_profile": "https://Stackoverflow.com/users/8523750",
"pm_score": -1,
"selected": false,
"text": "for field in df.schema.fields:\n print(field.name +\" , \"+str(field.dataType))\n"
},
{
"answer_id": 74646188,
"author": "Matt Andruff",
"author_id": 13535120,
"author_profile": "https://Stackoverflow.com/users/13535120",
"pm_score": 2,
"selected": false,
"text": ">>> df._jdf.queryExecution().executedPlan().apply(0).output().apply(0).toString()\nu'department#1621'\n>>> df._jdf.queryExecution().executedPlan().apply(0).output().apply(1).toString()\nu'max_age#1632L'\n apply plan = df._jdf.queryExecution().executedPlan()\nsteps = [ plan.apply(i).toString() for i in range(1,100) if not isinstance(plan.apply(i), type(None)) ]\n size"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14655059/"
] |
74,598,697
|
<p>I have 2 columns, one is Country and the other is Value</p>
<p>How can I make turn this table into a division table of sorts such that each value is divided by every other value and I would have the Country as rownames and column names, the values would be every possible division value. The picture describes what I'm trying to accomplish but in Excel. I would like to do this in R. Where the first table in transformed into the second table. I don't care to have the original values displayed in yellow only the division table.</p>
<p><a href="https://i.stack.imgur.com/yo8lw.png" rel="nofollow noreferrer">Transform top table into bottom table</a></p>
<p>I've tired many combinations of pivoting, joining, copying columns etc and get close but not the result I'm looking for. Is there a tidy way to do this?</p>
|
[
{
"answer_id": 74598752,
"author": "Maël",
"author_id": 13460602,
"author_profile": "https://Stackoverflow.com/users/13460602",
"pm_score": 3,
"selected": true,
"text": "outer x <- c(Argentina = 1.7, Australia = 5.5, Belgium = 0.5, Brazil = 8.7)\nt(outer(x, x, `/`))\n Argentina Australia Belgium Brazil\nArgentina 1.0000000 3.2352941 0.29411765 5.117647\nAustralia 0.3090909 1.0000000 0.09090909 1.581818\nBelgium 3.4000000 11.0000000 1.00000000 17.400000\nBrazil 0.1954023 0.6321839 0.05747126 1.000000\n"
},
{
"answer_id": 74598777,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 0,
"selected": false,
"text": "x = c(arg = 1.7, aus = 5.5, bel = 0.5, bra = 8.7)\n\ny = outer(x, x, FUN = \\(a,b) b/a)\ny\n\n# arg aus bel bra\n# arg 1.0000000 3.2352941 0.29411765 5.117647\n# aus 0.3090909 1.0000000 0.09090909 1.581818\n# bel 3.4000000 11.0000000 1.00000000 17.400000\n# bra 0.1954023 0.6321839 0.05747126 1.000000\n\ncbind(c(NA, x), rbind(\" \" = x, y))\n\n# arg aus bel bra\n# NA 1.7000000 5.5000000 0.50000000 8.700000\n# arg 1.7 1.0000000 3.2352941 0.29411765 5.117647\n# aus 5.5 0.3090909 1.0000000 0.09090909 1.581818\n# bel 0.5 3.4000000 11.0000000 1.00000000 17.400000\n# bra 8.7 0.1954023 0.6321839 0.05747126 1.000000\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20620375/"
] |
74,598,698
|
<p>I'm trying to decode a JSON file from an <a href="http://madlibz.herokuapp.com/api/random" rel="nofollow noreferrer">API</a> that I want to use but the <code>value</code> array contains a bunch of strings and an int at the end. When I specify the data type in the struct as AnyObject, it says that the struct does not conform to the Decodable protocol. Am I missing something? Is there a way I can fetch the data without the last Int?
<a href="https://i.stack.imgur.com/B98CW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B98CW.png" alt="JSON API Call result" /></a>
<a href="https://i.stack.imgur.com/phT8E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/phT8E.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74598963,
"author": "Sateesh Yemireddi",
"author_id": 5519329,
"author_profile": "https://Stackoverflow.com/users/5519329",
"pm_score": 2,
"selected": true,
"text": "// MARK: - DataModel\nstruct DataModel: Codable {\n let title: String\n let blanks: [String]\n let value: [Value]\n}\n\nenum Value: Codable {\n case integer(Int)\n case string(String)\n\n init(from decoder: Decoder) throws {\n let container = try decoder.singleValueContainer()\n if let x = try? container.decode(Int.self) {\n self = .integer(x)\n return\n }\n if let x = try? container.decode(String.self) {\n self = .string(x)\n return\n }\n throw DecodingError.typeMismatch(Value.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: \"Wrong type for Value\"))\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.singleValueContainer()\n switch self {\n case .integer(let x):\n try container.encode(x)\n case .string(let x):\n try container.encode(x)\n }\n }\n}\n Value let jsonData = jsonString.data(using: .utf8)!\nlet dataModel = try? JSONDecoder().decode(DataModel.self, from: jsonData)\ndataModel?.value.forEach { value in\n switch value {\n case .integer(let intValue):\n print(intValue)\n case .string(let stringValue):\n print(stringValue)\n }\n}\n"
},
{
"answer_id": 74599168,
"author": "vadian",
"author_id": 5044042,
"author_profile": "https://Stackoverflow.com/users/5044042",
"pm_score": 0,
"selected": false,
"text": "Decodable Any(Object) Value UnkeyedContainer strings integer struct DataModel: Decodable {\n let title: String\n let blanks: [String]\n let value: Value\n}\n\nstruct Value: Decodable {\n let strings : [String]\n let integer : Int\n \n init(from decoder: Decoder) throws {\n var container = try decoder.unkeyedContainer()\n var stringData = [String]()\n guard let numberOfItems = container.count else {\n throw DecodingError.dataCorruptedError(in: container,\n debugDescription: \"Number of items in the array is unknown\")\n }\n while container.currentIndex < numberOfItems - 1 {\n stringData.append(try container.decode(String.self))\n }\n strings = stringData\n integer = try container.decode(Int.self)\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15184847/"
] |
74,598,711
|
<p>i need to send the post data from angular to DRF through angular form but geeting the error</p>
<p>i checked almost all the answers available on the internet but did not found and useful answer.</p>
<pre><code> "detail": "CSRF Failed: CSRF token missing."
</code></pre>
<p>//post logic sources.service.ts</p>
<pre><code>import { Injectable } from '@angular/core';
import { sources } from './sources';
import { HttpClient } from '@angular/common/http';
import { Observable , of, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
// Authorization: 'my-auth-token',
cookieName: 'csrftoken',
headerName: 'X-CSRFToken',
// X-CSRFToken: 'sjd8q2x8hgjkvs1GJcOOcgnVGEkdP8f02shB',
// headerName: 'X-CSRFToken',
// headerName: ,
})
};
@Injectable({
providedIn: 'root'
})
export class SourcesService {
API_URL = 'http://127.0.0.1:8000/sourceapi.api';
constructor(private http: HttpClient) { }
/** GET sources from the server */
Sources() : Observable<sources[]> {
return this.http.get<sources[]>(this.API_URL);
}
/** POST: add a new source to the server */
// addSource(data: object) : Observable<object>{
// return this.http.post<object>(this.API_URL,data, httpOptions);
// }
addSource(source : sources[]): Observable<sources[]>{
return this.http.post<sources[]> (this.API_URL, source, httpOptions);
//console.log(user);
}
}
</code></pre>
<p>//add-source.component.ts</p>
<pre><code>import { Component, OnInit } from '@angular/core';
import { sources } from '../sources';
import { SourcesService } from '../sources.service';
import { FormGroup, FormControl, ReactiveFormsModule} from '@angular/forms';
@Component({
selector: 'app-add-source',
templateUrl: './add-source.component.html',
styleUrls: ['./add-source.component.css']
})
export class AddSourceComponent implements OnInit {
// a form for entering and validating data
sourceForm = new FormGroup({
name : new FormControl(),
url : new FormControl(),
client : new FormControl(),
});
constructor(private sourcesService: SourcesService) { }
ngOnInit(): void {
}
sourceData_post: any;
saveSource(){
if(this.validate_form()){
this.sourceData_post = this.sourceForm.value;
this.sourcesService.addSource(this.sourceData_post).subscribe((source)=>{
alert('source added');
});
}
else{
alert('please fill from correctly');
}
}
validate_form(){
const formData = this.sourceForm.value;
if(formData.name == null){
return false;
}else if(formData.url == null){
return false;
}else{
return true;
}
}
}
</code></pre>
<p>// add-source.component.html</p>
<pre><code>
<div class="bread-crumb">
<div> <span>Add Source</span> </div>
</div>
<div class="container flex">
<div class="form">
<form action="" [formGroup]="sourceForm" (ngSubmit)="saveSource()">
<table>
<tr>
<td>Source Name:</td>
<td>
<input class="input" type="text" formControlName="name">
</td>
</tr>
<tr>
<td>Source URL:</td>
<td>
<input class="input" type="text" formControlName="url">
</td>
</tr>
<tr>
<td>Source client:</td>
<td>
<input class="input" type="text" formControlName="client">
</td>
</tr>
<tr>
<td colspan="2">
<div class="center">
<button type="submit">submit</button>
</div>
</td>
</tr>
</table>
</form>
</div>
</div>
</code></pre>
<p>i tried</p>
<pre><code>imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
Ng2SearchPipeModule,
FormsModule,
ReactiveFormsModule,
HttpClientXsrfModule,
HttpClientXsrfModule.withOptions({
cookieName: 'XSRF-TOKEN',
headerName: 'X-XSRF-TOKEN',
})
</code></pre>
<p>but did not help</p>
<p>Note :- this is angular 13</p>
|
[
{
"answer_id": 74598759,
"author": "Ajay K",
"author_id": 10782096,
"author_profile": "https://Stackoverflow.com/users/10782096",
"pm_score": -1,
"selected": false,
"text": "from django.views.decorators.csrf import csrf_exempt\n @csrf_exempt\ndef index(request):\npass\n"
},
{
"answer_id": 74599244,
"author": "Arnaud Denoyelle",
"author_id": 2192903,
"author_profile": "https://Stackoverflow.com/users/2192903",
"pm_score": 0,
"selected": false,
"text": "GET HttpClientXsrfModule HttpClientXsrfModule.withOptions({\n cookieName: 'XSRF-TOKEN',\n headerName: 'X-XSRF-TOKEN',\n})\n const httpOptions = {\n headers: new HttpHeaders({\n 'Content-Type': 'application/json',\n cookieName: 'csrftoken',\n headerName: 'X-CSRFToken',\n })\n};\n[...]\n\naddSource(source : sources[]): Observable<sources[]>{\n return this.http.post<sources[]> (this.API_URL, source, httpOptions);\n addSource(source : sources[]): Observable<sources[]>{\n return this.http.post<sources[]> (this.API_URL, source);\n CSRF XSRF CSRF XSRF csrftoken HttpClientXsrfModule HttpClientXsrfModule.withOptions({\n cookieName: 'csrftoken', // << This one is certain\n headerName: 'X-XSRF-TOKEN', // << For this one, I don't know yet\n})\n headerName csrftoken HTTP_X_CSRFTOKEN HttpClientXsrfModule.withOptions({\n cookieName: 'csrftoken',\n headerName: 'HTTP_X_CSRFTOKEN',\n})\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622036/"
] |
74,598,712
|
<p>I have a dictionary</p>
<pre><code>d = {(1,100) : 0.5 , (1,150): 0.7 ,(1,190) : 0.8, (2,100) : 0.5 , (2,120): 0.7 ,(2,150) : 0.8, (3,100) : 0.5 , (3,110): 0.7 ,(4,100) : 0.5 , (4,150): 0.7 ,(4,190) : 0.8,(5,100) : 0.5 , (5,150): 0.7}
list = [4,2,1,3,5]
for (k1,k2),k3 in d.items():
for k1 in list :
print(k1,k2 : ,k3)
</code></pre>
<p>I want get the value of dictionary sequential like my list for the key 1
and for key 2 I have diferrent score and count</p>
<pre><code>(4,100) : 0.5 , (4,150): 0.7 ,(4,190) : 0.8,(2,100) : 0.5 , (2,120): 0.7 ,(2,150) : 0.8,(1,100) : 0.5 , (1,150): 0.7 ,(1,190) : 0.8,(3,100) : 0.5 , (3,110): 0.7 ,(5,100) : 0.5 , (5,150): 0.7}
</code></pre>
|
[
{
"answer_id": 74598841,
"author": "Orfeas Bourchas",
"author_id": 16781682,
"author_profile": "https://Stackoverflow.com/users/16781682",
"pm_score": 0,
"selected": false,
"text": "d = {(1, 100): 0.5,\n (1, 150): 0.5,\n (1, 190): 0.8,\n (2, 100): 0.5,\n (2, 120): 0.7,\n (2, 150): 0.8,\n (3, 100): 0.5,\n (3, 110): 0.7,\n (4, 100): 0.5,\n (4, 150): 0.7,\n (4, 190): 0.8,\n (5, 100): 0.5,\n (5, 150): 0.7}\n\n\nlst = [4, 2, 1, 3, 5]\n\nfor key, k3 in d.items():\n\n print(f'({lst[key[0]-1]},{key[1]}) : ,{k3}')\n (4,100) : ,0.5\n(4,150) : ,0.5\n(4,190) : ,0.8\n(2,100) : ,0.5\n(2,120) : ,0.7\n(2,150) : ,0.8\n(1,100) : ,0.5\n(1,110) : ,0.7\n(3,100) : ,0.5\n(3,150) : ,0.7\n(3,190) : ,0.8\n(5,100) : ,0.5\n(5,150) : ,0.7\n"
},
{
"answer_id": 74598950,
"author": "Guy",
"author_id": 5168011,
"author_profile": "https://Stackoverflow.com/users/5168011",
"pm_score": 1,
"selected": false,
"text": "sorted() d = dict(sorted(d.items(), key=lambda x: lst.index(x[0][0])))\nprint(d)\n {(4, 100): 0.5, (4, 150): 0.7, (4, 190): 0.8, (2, 100): 0.5, (2, 120): 0.7, (2, 150): 0.8, (1, 100): 0.5, (1, 150): 0.7, (1, 190): 0.8, (3, 100): 0.5, (3, 110): 0.7, (5, 100): 0.5, (5, 150): 0.7}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20621483/"
] |
74,598,722
|
<p>I'm trying to save the customer field on the Test model, I'm not getting any errors but it's not saving the field either, how do I fix it?</p>
<p>Models</p>
<pre><code>class Test(models.Model):
customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, blank=True, null=True)
email = models.EmailField(max_length=200, blank=False)
</code></pre>
<p>Forms</p>
<pre><code>class TestForm(forms.Form):
email = forms.EmailField(required=True)
class Meta:
model = Test
fields = ("email")
def save(self, commit=False):
# Creating the customer object
Test.objects.create(email=self.cleaned_data['email'])
</code></pre>
<p>Views</p>
<pre><code>def test_view(request):
customer = request.user.customer
if form.is_valid():
email = form.cleaned_data['email']
customer = customer
form.save()
</code></pre>
|
[
{
"answer_id": 74598913,
"author": "lucutzu33",
"author_id": 8770336,
"author_profile": "https://Stackoverflow.com/users/8770336",
"pm_score": 0,
"selected": false,
"text": "class TestForm(forms.ModelForm):\n\n class Meta:\n model = Test\n fields = [\"email\", ]\n def test_view(request):\n customer = request.user.customer #I'm not sure this line is right, but I can't see all your models\n\n if form.is_valid():\n test = form.save(commit=False)\n test.customer = customer\n test.save()\n"
},
{
"answer_id": 74599614,
"author": "Sunderam Dubey",
"author_id": 17562044,
"author_profile": "https://Stackoverflow.com/users/17562044",
"pm_score": 3,
"selected": true,
"text": "cleaned_data class TestForm(forms.ModelForm):\n\n class Meta:\n model = Test\n fields = [\"email\"]\n POST def test_view(request):\n if request.method==\"POST\":\n form=TestForm(request.POST)\n \n customer = request.user.customer\n\n if form.is_valid():\n email = form.cleaned_data['email']\n test=Test(customer=customer,email=email)\n test.save()\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18982716/"
] |
74,598,734
|
<p>I want to search something on Google using Selenium chromedriver and enter it. I can normally do this within the site, but I couldn't type it into google. What code can we use for this?</p>
<p>driver.findElement(By.xpath("//input[@class='desktopOldAutosuggestTheme-UyU36RyhCTcuRs_sXL9b']")).sendKeys("HBCV00000ODHHV");</p>
<p>Fakat olmadı.</p>
|
[
{
"answer_id": 74598804,
"author": "Bas van der Linden",
"author_id": 11119684,
"author_profile": "https://Stackoverflow.com/users/11119684",
"pm_score": 1,
"selected": false,
"text": "german shepards search_bar : WebElement = driver.get_element(By.XPATH, \"//input[@title='Search']\")\n\n# then you can perform the send_keys\nsearch_bar.send_keys(...)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20588290/"
] |
74,598,788
|
<p>I'm trying recreate this photo but I have run into an issue that I'm not so sure how to fix! So I need to shrink the width of the container class but I'm no entirely sure how. I've tried all kinds of different flex box strategies. My question is how can I shrink the width of the container class and how can I move all of the content to the center of the screen like in the photo? (If you expand the snippet to full screen all the content shows in the top left) <a href="https://i.stack.imgur.com/XkfqO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XkfqO.png" alt="recreation" /></a>
<strong>Here is what I have so far:</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
font-family: Helvetica;
background-color: #000000;
color: white;
}
.container {
display: flex;
align-content: center;
justify-content: space-evenly;
align-items: center;
background-color: #5A5A5A;
color: white;
padding: 0px;
margin: 5px 0;
border-radius: 5px;
}
#clickMe {
border: 1px solid white;
display: inline-block;
padding: 10px;
font-family: Helvetica;
border-radius: 3px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>List of items</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>Products</h1>
<p>______
<p>
</div>
<div id="appendToMe">
<div class="boxes">
<div class="container">
<p>Hello</p>
<p>World</p>
<p>Hello</p>
</div>
<div class="container">
<p>Hello</p>
<p>World</p>
<p>Hello</p>
</div>
<div class="container">
<p>Hello</p>
<p>World</p>
<p>Hello</p>
</div>
</div>
</div>
<div id="clickMe">Toggle Dark Mode</div>
</body>
</html></code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74598804,
"author": "Bas van der Linden",
"author_id": 11119684,
"author_profile": "https://Stackoverflow.com/users/11119684",
"pm_score": 1,
"selected": false,
"text": "german shepards search_bar : WebElement = driver.get_element(By.XPATH, \"//input[@title='Search']\")\n\n# then you can perform the send_keys\nsearch_bar.send_keys(...)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9277512/"
] |
74,598,794
|
<p>I have this function that borrows two individual elements from a vector. It works as expected:</p>
<pre class="lang-rs prettyprint-override"><code>fn borrow_mut_two<T>(v: &mut [T], i: usize, j: usize) -> (&mut T, &mut T) {
assert!(i < j);
let (left, right) = v.split_at_mut(j);
(&mut left[i], &mut right[0])
}
fn test() {
let mut v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8];
let i = 2;
let j = 5;
let (ref_a, ref_b) = borrow_mut_two(&mut v, i, j);
*ref_a += 1;
*ref_b += 5;
assert_eq!(*ref_a, i + 1);
assert_eq!(*ref_b, j + 5);
}
</code></pre>
<p>What I'm trying to understand is why the following code doesn't compile:</p>
<pre class="lang-rs prettyprint-override"><code>fn test() {
let mut v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8];
let i = 2;
let j = 5;
let (ref_a, ref_b) = borrow_mut_two(&mut v, i, j);
// Added this line:
let (other_ref_a, other_ref_b) = borrow_mut_two(&mut v, i, j);
*ref_a += 1;
*ref_b += 5;
assert_eq!(*ref_a, i + 1);
assert_eq!(*ref_b, j + 5);
}
</code></pre>
<p>It seems it works in a safe manner, because it doesn't allow me to mutably borrow the same elements twice (or potentially other elements).</p>
<p>My question is how does the compiler know that this is unsafe (and therefore reject compiling it)?</p>
<p>The compiler errors are:</p>
<pre><code>229 | let (ref_a, ref_b) = borrow_mut_two(&mut v, i, j);
| ------ first mutable borrow occurs here
230 | let (other_ref_a, other_ref_b) = borrow_mut_two(&mut v, i, j);
| ^^^^^^ second mutable borrow occurs here
</code></pre>
<p>As far as I know the return value of <code>borrow_mut_two</code> is the tuple <code>(&mut T, &mut T)</code>, which may or may not be a borrow to <code>self</code>, but it seems the compiler does know it's borrowing <code>self</code>. My assumptions may be wrong though .</p>
<p>The only thing that comes to mind is that Rust automatically adds the lifetime:</p>
<pre class="lang-rs prettyprint-override"><code>fn borrow_mut_two<'a, T>(v: &'a mut [T], i: usize, j: usize) -> (&'a mut T, &'a mut T)
</code></pre>
<p>Which would mean that in my <code>test</code> function, <code>'a</code> is still alive (i.e. <code>self</code> mutably borrowed) due to the first call to <code>borrow_mut_two</code> while the second call happens, and that's how it detects a second mutable borrow.</p>
<p>But I'd like to confirm if this is correct.</p>
<h2>Extra</h2>
<p>It could be related to this part of the book. The only difference I see is that my function returns a tuple. So the question can be reduced to: Does Rust's second lifetime elision rule also add <code>'a</code> to each element of a tuple? If so, then my doubt is solved:</p>
<blockquote>
<p>The first rule is that the compiler assigns a lifetime parameter to
each parameter that’s a reference. In other words, a function with one
parameter gets one lifetime parameter: <code>fn foo<'a>(x: &'a i32);</code> a
function with two parameters gets two separate lifetime parameters: fn
<code>foo<'a, 'b>(x: &'a i32, y: &'b i32);</code> and so on.</p>
<p>The second rule is that, if there is exactly one input lifetime
parameter, that lifetime is assigned to all output lifetime
parameters: <code>fn foo<'a>(x: &'a i32) -> &'a i32</code>.</p>
</blockquote>
|
[
{
"answer_id": 74598907,
"author": "Joe Clay",
"author_id": 5436257,
"author_profile": "https://Stackoverflow.com/users/5436257",
"pm_score": 3,
"selected": true,
"text": "fn borrow_mut_two<T>(v: &mut [T], i: usize, j: usize) -> (&mut T, &mut T)\nfn borrow_mut_two<'a, T>(v: &'a mut [T], i: usize, j: usize) -> (&'a mut T, &'a mut T)\n v v"
},
{
"answer_id": 74599054,
"author": "jthulhu",
"author_id": 5956261,
"author_profile": "https://Stackoverflow.com/users/5956261",
"pm_score": 0,
"selected": false,
"text": "v fn test() {\n // ...\n let (ref_a, ref_b) = borrow_mut_two(&'3 mut v, i, j); // ------+\n // ^^^^^ ^^^^^ ^^^^^^^ Let's call // |\n // +---+ this lifetime '3 // |\n // | // |\n // Let's call the lifetime of these mutable borrows '1 // |\n // Added this line: // +- '1\n let (other_ref_a, other_ref_b) = borrow_mut_two(&'4 mut v, i, j); // -+ '2 |\n // ^^^^^^^^^^^ ^^^^^^^^^^^ // | |\n // +------+ Let's call the lifetimes of these borrows '2 // -+ |\n *ref_a += 1; // |\n *ref_b += 5; // ------+\n}\n '3 '4 v borrow_mut_two '1='3 '2='4 '1 '2 '1 '2 '1 '2 '2 '1 '2 '1 split_at_mut"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4757175/"
] |
74,598,833
|
<p>So basically this.props.children in my code isn't working. i.e it isn't displaying the content in another js file. There is one file defaullayout.js which has a content section in order to display the layou in a page hompage.js. So i am trying to give {this.prop.children} in content to display the defaltlayout page in homepage but the whole page is being shown blank. Please help me with this.Thank you!</p>
<p>Here is my code for first page`thta is DefaultLayout.js</p>
<p>`</p>
<pre><code>import React, { useState } from 'react';
import {
MenuFoldOutlined,
MenuUnfoldOutlined,
UploadOutlined,
UserOutlined,
VideoCameraOutlined,
CopyOutlined ,
UnorderedListOutlined,
LogoutOutlined ,
HomeOutlined
} from '@ant-design/icons';
import { Layout, Menu } from 'antd';
import '../resources/layout.css';
import { Link } from 'react-router-dom';
import { ReactDOM } from "react-dom";
const { Header, Sider, Content } = Layout;
const DefaultLayout = () => {
const [collapsed, setCollapsed] = useState(false);
return (
<Layout>
<Sider trigger={null} collapsible collapsed={collapsed}>
<div className="logo"> <h3>SI Pos</h3> </div>
<Menu theme="dark" mode="inline" defaultSelectedKeys={window.location.pathname}>
<Menu.Item key="/home" icon={<HomeOutlined />}>
<Link to='/home'>Home</Link>
</Menu.Item>
<Menu.Item key="/bills" icon={<CopyOutlined />}>
<Link to='/bills'>Bills</Link>
</Menu.Item>
<Menu.Item key="/items" icon={<UnorderedListOutlined />}>
<Link to='/items'>Items</Link>
</Menu.Item>
<Menu.Item key="/customers" icon={<UserOutlined />}>
<Link to='/customers'>Customers</Link>
</Menu.Item>
<Menu.Item key="/logout" icon={<LogoutOutlined />}>
Logout
</Menu.Item>
</Menu>
</Sider>
<Layout className="site-layout">
<Header
className="site-layout-background"
style={{
padding: 10,
}}
>
{React.createElement(collapsed ? MenuUnfoldOutlined : MenuFoldOutlined, {
className: 'trigger',
onClick: () => setCollapsed(!collapsed),
})}
</Header>
<Content
className="site-layout-background"
style={{
margin: '10px',
padding: 24,
minHeight: 280,
}}>
{this.props.children}
</Content>
</Layout>
</Layout>
);
};
export default DefaultLayout;
</code></pre>
<p>and the second page is Homepage.js</p>
<p>`</p>
<pre><code>import React from "react";
import DefaultLayout from "../components/DefaultLayout";
function Homepage(){
return(
<DefaultLayout>
<h1>hey</h1>
</DefaultLayout>
)
}
export default Homepage;
</code></pre>
<p>`
``</p>
<p>I am expecting to get my default page displayed in homepage. Thanks in advance.</p>
|
[
{
"answer_id": 74598959,
"author": "Hilory",
"author_id": 11703584,
"author_profile": "https://Stackoverflow.com/users/11703584",
"pm_score": 2,
"selected": false,
"text": "{this.props.children} this props < DefaultLayout/> const DefaultLayout = (props) => {\n...\n<Content className=\"site-layout-background\" style={...}>\n {props.children}\n</Content>\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622118/"
] |
74,598,839
|
<p>there are 4 checkbox data in my modal. I want the previously selected data to be selected when the modal is closed and opened. How can I do this?</p>
<p>I added the selected data to a list, but unfortunately I could not make it selected.</p>
<p>HTML temaplate:</p>
<pre><code><div class="row">
<div class="col-md-4 mt-2"
*ngFor="let measurementTableList of getMeasurementPointIds()">
<p>
<mat-checkbox [checked]="checkedMeasurmentPointId" value="measurementTableList"
(change)="checkedMeasurmentPoint(measurementTableList, $event)">
{{getMeasurementPointName(measurementTableList).measurementPointName}}</mat-checkbox>
</p>
</div>
</div>
</code></pre>
<p>TypeScript:</p>
<pre><code> checkedMeasurmentPoint(selectedPoint: number, event: boolean) {
if (event['checked']) {
this.checkedMeasurmentPointId.push(selectedPoint)
}
else {
const index = this.checkedMeasurmentPointId.indexOf(selectedPoint, 0);
if (index > -1) {
this.checkedMeasurmentPointId.splice(index, 1);
}
}
this.ref.markForCheck();
}
</code></pre>
<p>I tried <code>[(ngModel)]</code> but it didn't work</p>
|
[
{
"answer_id": 74598959,
"author": "Hilory",
"author_id": 11703584,
"author_profile": "https://Stackoverflow.com/users/11703584",
"pm_score": 2,
"selected": false,
"text": "{this.props.children} this props < DefaultLayout/> const DefaultLayout = (props) => {\n...\n<Content className=\"site-layout-background\" style={...}>\n {props.children}\n</Content>\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519481/"
] |
74,598,983
|
<p>I want to create an object with every value as "true" and the length of keys will be same with array length.</p>
<p>Example :</p>
<pre><code>const myCar = [{name:ford,type:A},{name:opel,type:B}]
</code></pre>
<p>The output want to be like this below</p>
<pre><code>{0:true,1:true}
</code></pre>
<p>If the length from the array myCar will be 3 so the output will be like this as well:</p>
<pre><code>{0:true,1:true,2:true}
</code></pre>
|
[
{
"answer_id": 74599038,
"author": "AbsoluteZero",
"author_id": 20539156,
"author_profile": "https://Stackoverflow.com/users/20539156",
"pm_score": -1,
"selected": false,
"text": "Array.prototype.map const myCar = [{\n name: 'ford',\n type: 'A'\n}, {\n name: 'opel',\n type: 'B'\n}];\n\nconst myArr = [...new Array(myCar.length)].fill('').map((_, i) => ({\n [i]: true\n}));\n\nconsole.log(myArr); [...new Array(N)] .fill('') .map((_, i)) [i]: true true const myCar = [{\n name: 'ford',\n type: 'A'\n}, {\n name: 'opel',\n type: 'B'\n}];\n\nconst myArr = myCar.reduce((prev, curr, i) => ({ ...prev, [i]: true }), {});\n\nconsole.log(myArr);"
},
{
"answer_id": 74599075,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": 0,
"selected": false,
"text": "const myCar = [{name:\"ford\",type:\"A\"},{name:\"opel\",type:\"B\"}] \nlet obj={};\nmyCar.forEach((item, index)=>{\n obj={...obj,[index]:true};\n})\nconsole.log(obj);"
},
{
"answer_id": 74599079,
"author": "mplungjan",
"author_id": 295783,
"author_profile": "https://Stackoverflow.com/users/295783",
"pm_score": 3,
"selected": true,
"text": "const myCar = [{ name: 'ford', type: 'A' }, { name: 'opel', type: 'B' }];\n\nconst myObj = myCar.reduce((acc,_,i) => (acc[i] = true,acc),{});\n\nconsole.log(myObj); const myObj = myCar\n .reduce(\n (acc,_,i) => // reduce passes the accumulator, the current object which we ignore here and the index\n (acc[i] = true // set the accumulator at key=index to true \n ,acc) // and use the comma operator to return the accumulator\n ,{}); // initialise the accumulator to an empty object\n"
},
{
"answer_id": 74599171,
"author": "T.J. Crowder",
"author_id": 157247,
"author_profile": "https://Stackoverflow.com/users/157247",
"pm_score": 1,
"selected": false,
"text": "0 const myCar = [{name: \"ford\",type: \"A\"},{name: \"opel\", type: \"B\"}];\n\nconst result = {};\nfor (let index = 0; index < myCar.length; ++index) {\n result[index] = true;\n}\nconsole.log(result);"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16870482/"
] |
74,598,985
|
<p>I have a String, for example <code>ABC_Michael_A_V1.3_Update</code></p>
<p>In my SQLite database, i have a table <code>beginnings</code> with 2 columns. The first one is of type String and contains multiple possible beginnings of the string, the second one is of type Integer.
for example:</p>
<pre><code>StringBeginning | Score
------------------------------
ABC_Michael_C | 2
ABC_Mich | 5
ABC_Johannes_A | 4
ABC_Michael_A | 5
ABC_Michael_A_V1 | 7 <-----
ABC_Jack_A_V1.2 | 12
</code></pre>
<p>What I would need to find, is the row with the string that hast the longest matching beginning with my inputstring. (in this sample marked with a row.) Please note, that also row 2 and 4 match, but they are not the longest one.</p>
<p>I know how to do it the other way around, having the beginning of a string and searching all strings that start with that string, but I dont know how to do it if my input string is longer than what I am searching for.</p>
<p>Any help is greatly appreciated</p>
|
[
{
"answer_id": 74599182,
"author": "sharkyenergy",
"author_id": 1780761,
"author_profile": "https://Stackoverflow.com/users/1780761",
"pm_score": -1,
"selected": false,
"text": "select *, length(StringBeginning) as len from beginnings where instr('ABC_Michael_A_V1.3_Update',StringBeginning) = 1 order by len desc limit 1\n"
},
{
"answer_id": 74610900,
"author": "Groco",
"author_id": 2519138,
"author_profile": "https://Stackoverflow.com/users/2519138",
"pm_score": 0,
"selected": false,
"text": "select *,\nlength(replace('ABC_Michael_A_V1.3_Update',StringBeginning,'')) as len\nfrom beginnings \nwhere instr('ABC_Michael_A_V1.3_Update',StringBeginning) = 1 \norder by len asc\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74598985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1780761/"
] |
74,599,012
|
<p>I created a heatmap using pheatmap package as follows:</p>
<pre><code>test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
a=pheatmap(test)
a
</code></pre>
<p><a href="https://i.stack.imgur.com/egpY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/egpY3.png" alt="heatmap" /></a></p>
<p>And I created GOplot using GOplot package as follows:
dput(circ)</p>
<pre><code>structure(list(category = c("Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms", "Enriched Terms", "Enriched Terms",
"Enriched Terms", "Enriched Terms"), ID = c("inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "inflammatory response",
"inflammatory response", "inflammatory response", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "T cell activation", "T cell activation",
"T cell activation", "cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"cytokine mediated signaling pathway", "cytokine mediated signaling pathway",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "T cell proliferation", "T cell proliferation",
"T cell proliferation", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"wound healing", "wound healing", "wound healing", "wound healing",
"response to progesterone", "response to progesterone", "response to progesterone",
"response to progesterone", "response to progesterone", "response to progesterone",
"response to progesterone", "response to progesterone", "response to progesterone",
"response to progesterone", "response to progesterone"), term = c("GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954", "GO:0006954",
"GO:0006954", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110", "GO:0042110",
"GO:0042110", "GO:0042110", "GO:0042110", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221", "GO:0019221",
"GO:0019221", "GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098",
"GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098",
"GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098",
"GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098",
"GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098", "GO:0042098",
"GO:0042098", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060", "GO:0042060",
"GO:0032570", "GO:0032570", "GO:0032570", "GO:0032570", "GO:0032570",
"GO:0032570", "GO:0032570", "GO:0032570", "GO:0032570", "GO:0032570",
"GO:0032570"), count = c(72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L,
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L,
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L,
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L,
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L,
72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L,
47L, 47L, 47L, 47L, 47L, 47L, 47L, 38L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L,
38L, 38L, 38L, 38L, 38L, 38L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L,
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L,
39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L,
39L, 39L, 39L, 39L, 39L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L), genes = c("CDO1", "HLA-DRB1", "ACP5", "HMGB2",
"HMOX1", "ADCY1", "F7", "CD163", "TYROBP", "FCER1G", "CIITA",
"FCGR3A", "CXCL9", "CCL2", "CCR1", "CCL5", "MMP3", "ABCC2", "ALOX15",
"SGK1", "FPR3", "APOD", "SCUBE1", "SERPINC1", "PDE5A", "IL1B",
"CYBB", "SLAMF8", "TRAF3IP2", "IL18", "METRNL", "IL17B", "IRAK2",
"IL20RB", "IRF5", "PTAFR", "IL1RL2", "ITGB2", "PTGIR", "ITGB6",
"PDCD4", "GGT1", "PTN", "BMPR1B", "PLA2G2D", "SPHK1", "CXCL17",
"SCG2", "SIGLEC10", "TRIM55", "C1QA", "LILRB4", "RHBDF2", "SOCS3",
"GRN", "RELB", "PSTPIP1", "ECM1", "NFAM1", "BCL6B", "ACE2", "CD6",
"CD14", "TIMP1", "GPR68", "CD36", "CD74", "ADGRE5", "TNFAIP3",
"LYZ", "HCK", "CD96", "ERBB2", "HLA-DQA1", "HLA-DQB1", "HLA-DRB1",
"ZNF683", "EOMES", "ICOS", "FCER1G", "CCL2", "CCL5", "WAS", "RASAL3",
"SOCS1", "PDE5A", "IL1B", "STX11", "IL7", "TRAF3IP2", "TNFRSF9",
"IL18", "TNFRSF14", "IL20RB", "IRF1", "ITGAX", "IL1RL2", "ITGB2",
"ITK", "LAPTM5", "BMP4", "CLEC4F", "PLA2G2D", "LILRB4", "SH2B3",
"VTCN1", "RELB", "SH2D2A", "TSPAN32", "RUNX3", "CD6", "CD7",
"LMO1", "CD86", "CD70", "CD74", "PAX1", "MPZL2", "LEF1", "FCER1G",
"IFITM3", "CXCL9", "CCL2", "CCR1", "CCL5", "CNTFR", "CD300LF",
"PYDC1", "MST1R", "SOCS1", "IL1B", "IL17RD", "IL2RB", "IL7",
"IL10RA", "TRAF3IP2", "IL15RA", "IL18", "TNFRSF14", "IRAK2",
"IL20RB", "IRF1", "IRF5", "IL1RL2", "LAPTM5", "PXDN", "IL1RAPL2",
"SPHK1", "CXCL17", "LILRB4", "SH2B3", "ECM1", "GREM2", "CD70",
"CD74", "TNFAIP3", "HCK", "ERBB2", "HLA-DQA1", "HLA-DRB1", "CCL5",
"RASAL3", "PDE5A", "IL1B", "TNFRSF9", "IL18", "TNFRSF14", "IL20RB",
"IRF1", "ITGAX", "ITGB2", "LAPTM5", "BMP4", "PLA2G2D", "LILRB4",
"VTCN1", "SH2D2A", "TSPAN32", "CD6", "LMO1", "CD86", "CD70",
"HGFAC", "NRG1", "ERBB2", "HMOX1", "F7", "FCER1G", "FCGR3A",
"CCL2", "C1QTNF1", "VAV3", "FGG", "MMP3", "POU2F3", "ALOX15",
"MIA3", "WAS", "ENPP4", "SCUBE1", "SERPINC1", "IL1B", "GATA2",
"ITGA5", "ITGB6", "BMP4", "DST", "LILRB4", "IL24", "KRT6A", "RAP2B",
"SH2B3", "DSP", "TSPAN32", "TFPI", "TIMP1", "EVPLL", "CD36",
"TNFAIP3", "PAX7", "PARD3", "NRG1", "ERBB2", "CCL2", "SOCS1",
"RELN", "PTN", "SPHK1", "DSG1", "ABHD2", "SOCS3", "OXTR"), logFC = c(-2.737960452,
1.241037398, 1.374760702, -1.103596949, 1.079758824, 3.086032109,
-2.877651668, 1.09476118, 1.118517102, 1.041377427, 1.319558299,
1.118681141, 2.891440638, 1.122498237, 1.92052302, 1.54657149,
2.538427301, -2.69483845, -3.915575094, 1.319202149, 1.697645266,
-2.86918927, 2.1371583, -5.659311147, -1.53119513, 1.945184259,
1.347387517, 1.722650321, -1.180236204, 1.21734454, 1.084121694,
-5.283056691, 1.205271542, 1.917439533, 1.256984968, 1.180701005,
-3.027851614, 1.24994078, 1.527263076, -2.185935071, -1.146129256,
-5.061405849, -3.572421784, 4.006705524, 2.224401737, 1.169631321,
-3.463052584, -2.572606019, 1.94368823, -5.940020275, 1.152347835,
1.716108464, 1.201977508, 1.706652811, 1.062033751, 1.233980975,
1.310927918, 1.903484885, 1.115666204, 1.293787307, -3.656400355,
1.959492212, 1.067545802, 1.499824047, 1.404434777, -2.937891421,
1.107773701, 1.043144439, 1.777494393, 1.646834437, 1.156112282,
1.10944754, -4.210238561, 1.865313935, 1.513262912, 1.241037398,
1.782577274, 2.516774087, 2.339406632, 1.041377427, 1.122498237,
1.54657149, 1.191237579, 1.472211185, 1.857872456, -1.53119513,
1.945184259, 1.511626606, -1.727937842, -1.180236204, 1.911680124,
1.21734454, 1.334667618, 1.917439533, 1.484782869, 1.212649627,
-3.027851614, 1.24994078, 1.811227395, 1.233641, -2.12693152,
-1.836124452, 2.224401737, 1.716108464, 1.035261508, -2.405733686,
1.233980975, 1.267228904, 2.207264277, 1.410751117, 1.959492212,
2.971479523, -4.825751399, 1.047624972, 2.837308276, 1.107773701,
-4.987747449, -1.74915527, 1.247360205, 1.041377427, 1.058227706,
2.891440638, 1.122498237, 1.92052302, 1.54657149, -4.172482769,
1.333487402, 4.152707357, -1.785658712, 1.857872456, 1.945184259,
-1.95196654, 1.941367702, -1.727937842, 1.057464494, -1.180236204,
1.020161179, 1.21734454, 1.334667618, 1.205271542, 1.917439533,
1.484782869, 1.256984968, -3.027851614, 1.233641, 1.788558045,
-5.462904275, 1.169631321, -3.463052584, 1.716108464, 1.035261508,
1.903484885, -2.291272692, 2.837308276, 1.107773701, 1.777494393,
1.156112282, -4.210238561, 1.865313935, 1.241037398, 1.54657149,
1.472211185, -1.53119513, 1.945184259, 1.911680124, 1.21734454,
1.334667618, 1.917439533, 1.484782869, 1.212649627, 1.24994078,
1.233641, -2.12693152, 2.224401737, 1.716108464, -2.405733686,
1.267228904, 2.207264277, 1.959492212, -4.825751399, 1.047624972,
2.837308276, 5.993222336, -2.978513041, -4.210238561, 1.079758824,
-2.877651668, 1.041377427, 1.118681141, 1.122498237, 1.376906496,
-1.914010292, -5.261606201, 2.538427301, -3.653580929, -3.915575094,
-1.138879528, 1.191237579, 1.613578374, 2.1371583, -5.659311147,
1.945184259, -1.574242178, 1.141089282, -2.185935071, -2.12693152,
-1.138578308, 1.716108464, 4.7309855, 2.559918081, 1.135394507,
1.035261508, -1.581412595, 2.207264277, -1.836137414, 1.499824047,
-5.643250914, -2.937891421, 1.777494393, -4.220593474, -1.301224439,
-2.978513041, -4.210238561, 1.122498237, 1.857872456, -2.263900849,
-3.572421784, 1.169631321, -4.277817031, 1.778735721, 1.706652811,
-2.319315751), adj_pval = c(3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05,
3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 3.96e-05, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237, 0.00237,
0.00237, 0.00237, 0.00237, 0.00542, 0.00542, 0.00542, 0.00542,
0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542,
0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542,
0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542,
0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542,
0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00542, 0.00593,
0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593,
0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593,
0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593, 0.00593,
0.00593, 0.00593, 0.00593, 0.00631, 0.00631, 0.00631, 0.00631,
0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631,
0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631,
0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631,
0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631,
0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631, 0.00631,
0.00682, 0.00682, 0.00682, 0.00682, 0.00682, 0.00682, 0.00682,
0.00682, 0.00682, 0.00682, 0.00682), zscore = c(3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.77123616632825,
3.77123616632825, 3.77123616632825, 3.77123616632825, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.64662478744736, 3.64662478744736,
3.64662478744736, 3.64662478744736, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3.24442842261525, 3.24442842261525, 3.24442842261525, 3.24442842261525,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
0.160128153805087, 0.160128153805087, 0.160128153805087, 0.160128153805087,
-0.301511344577764, -0.301511344577764, -0.301511344577764, -0.301511344577764,
-0.301511344577764, -0.301511344577764, -0.301511344577764, -0.301511344577764,
-0.301511344577764, -0.301511344577764, -0.301511344577764)), class = "data.frame", row.names = c(NA,
-232L))
</code></pre>
<p>and</p>
<pre><code>b=GOBar(circ, display = 'multiple')
b
</code></pre>
<p><a href="https://i.stack.imgur.com/Rn4vC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rn4vC.png" alt="goplot" /></a></p>
<p>Next, I wanted to merge a, b as single figure.
I tried</p>
<pre><code>ggarrange(a,b,labels = c("A", "B"), ncol = 1, nrow = 1)
</code></pre>
<p>But it ouput only Goplot as b keeping a as blank:</p>
|
[
{
"answer_id": 74599375,
"author": "Venk Murthy",
"author_id": 10604345,
"author_profile": "https://Stackoverflow.com/users/10604345",
"pm_score": 1,
"selected": false,
"text": "patchwork"
},
{
"answer_id": 74599545,
"author": "stefan",
"author_id": 12993861,
"author_profile": "https://Stackoverflow.com/users/12993861",
"pm_score": 3,
"selected": true,
"text": "pheatmap pheatmap list gtable GOplot library(pheatmap)\nlibrary(ggpubr)\n\nset.seed(123)\n\na <- pheatmap(test)\n\nb <- ggplot(mtcars, aes(hp, mpg)) +\n geom_point()\n\nggarrange(a$gtable, b, labels = c(\"A\", \"B\"))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2110417/"
] |
74,599,017
|
<p>is there a plugin or way that if i press the run button pycharms starts to highlight the code that is currently running step by step so i can see what pycharms is doing</p>
<p>I looked into the pycharms editor settings but didnt really find anything that would help me</p>
|
[
{
"answer_id": 74599375,
"author": "Venk Murthy",
"author_id": 10604345,
"author_profile": "https://Stackoverflow.com/users/10604345",
"pm_score": 1,
"selected": false,
"text": "patchwork"
},
{
"answer_id": 74599545,
"author": "stefan",
"author_id": 12993861,
"author_profile": "https://Stackoverflow.com/users/12993861",
"pm_score": 3,
"selected": true,
"text": "pheatmap pheatmap list gtable GOplot library(pheatmap)\nlibrary(ggpubr)\n\nset.seed(123)\n\na <- pheatmap(test)\n\nb <- ggplot(mtcars, aes(hp, mpg)) +\n geom_point()\n\nggarrange(a$gtable, b, labels = c(\"A\", \"B\"))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622223/"
] |
74,599,102
|
<p>I have a data frame with dimension 24,523x3,468 and I want to shuffle the entries of this dataframe. For example, I have a simple data frame</p>
<pre><code>df <- data.frame(c1=c(1, 1.5, 2, 4), c2=c(1.1, 1.6, 3, 3.2), c3=c(2.1, 2.4, 1.4, 1.7))
df_shuffled = transform(df, c2 = sample(c2))
</code></pre>
<p>It works for one column, but I want to shuffle all column, or all rows. I tried</p>
<pre><code>col = colnames(df)
for (i in 1:ncol(df)){
df2 = transform(df, col[i] = sample(col[i]))
}
df2
</code></pre>
<p>It will produce an error like this</p>
<p><a href="https://i.stack.imgur.com/5GgOc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5GgOc.png" alt="error" /></a></p>
<p>I have tried this too to shuffle, but it only shuffles rows and columns</p>
<pre><code>df_shuf = df[sample(rownames(df), nrow(df)), sample(colnames(df), ncol(df))]
df_shuf
</code></pre>
<p><a href="https://i.stack.imgur.com/qZYWm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qZYWm.png" alt="shuffle" /></a></p>
<p>How can I shuffle the entries of the data frame df using a loop for I by rows and columns?</p>
|
[
{
"answer_id": 74599180,
"author": "B. Christian Kamgang",
"author_id": 10848898,
"author_profile": "https://Stackoverflow.com/users/10848898",
"pm_score": 3,
"selected": false,
"text": "df[] = lapply(df, sample)\n"
},
{
"answer_id": 74599743,
"author": "r2evans - GO NAVY BEAT ARMY",
"author_id": 3358272,
"author_profile": "https://Stackoverflow.com/users/3358272",
"pm_score": 2,
"selected": false,
"text": "lapply(df, sample) for transform col[i] df2[[ col[i] ]] df2 <- df\ncol = colnames(df)\nfor (i in 1:ncol(df)) {\n df2[[ col[i] ]] = sample(df2[[ col[i] ]])\n}\n df2 <- df\nfor (i in 1:ncol(df)) {\n df2[[ i ]] = sample(df2[[ i ]])\n}\n c1 c2 df2 <- df[sample(nrow(df)),]\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13282670/"
] |
74,599,103
|
<p>I would like to find values from one CSV in another and modify/remove the rows accordingly.</p>
<p>Removing already works quite well, but I would like to automate this process as much as possible.</p>
<p>So my question is how can I put all values from the serachforthat.csv (column [0]) into a kind of array or list and use it to run through the all.csv.</p>
<p>what i got so far:</p>
<pre><code>*args = "searchforthat.csv[0]" # These are my values
import csv
with open('all.csv', 'r') as inp, open('final.csv', 'w') as out:
writer = csv.writer(out)
for row in csv.reader(inp):
if row[3] != args: # That does not work :(
writer.writerow(row)
</code></pre>
<p>I am completely new to python and a little confused as to the correct way to write it...</p>
|
[
{
"answer_id": 74599196,
"author": "Bas van der Linden",
"author_id": 11119684,
"author_profile": "https://Stackoverflow.com/users/11119684",
"pm_score": 0,
"selected": false,
"text": "search_values = []\nwith open('searchforthat.csv', 'r') as sfile:\n lines = [line.replace(\"\\n\", \"\") for line in sfile.readlines()]\n search_values = [line.split(\",\")[0] for line in lines]\n\n search_values # get the row data from searchforthat.csv\nsearch_row_data = []\nwith open('searchforthat.csv', 'r') as sfile:\n lines = [line.replace(\"\\n\", \"\") for line in sfile.readlines()]\n search_row_data = [line.split(\",\") for line in lines]\n\n\n# map search data to values\nsearch_values = [row_data[0] for row_data in search_row_data]\n\n# get the row data from all.csv\nall_row_data = []\nwith open('all.csv', 'r') as afile:\n lines = [line.replace(\"\\n\", \"\") for line in afile.readlines()]\n all_row_data = [line.split(\",\") for line in lines\n\n# go over all.csv values and if it is not it searchforthat.csv, write it.\nwith open('out.csv', 'w') as ofile:\n for row_data in all_row_data: \n if row_data[3] not in search_values:\n ofile.write(','.join(row_data) + '\\n')\n\n"
},
{
"answer_id": 74599251,
"author": "Yip",
"author_id": 15047837,
"author_profile": "https://Stackoverflow.com/users/15047837",
"pm_score": 1,
"selected": false,
"text": "import csv\n\nwith open('searchforthat.csv', 'r') as inp:\n args = [row[0] for row in csv.reader(inp)]\n\nwith open('all.csv', 'r') as inp, open('final.csv', 'w') as out:\n writer = csv.writer(out)\n for row in csv.reader(inp):\n if row[3] not in args:\n writer.writerow(row)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2292490/"
] |
74,599,116
|
<p>I'm trying to use <code>pandas.DataFrame.assign</code> in Pandas 1.5.2. Let's consider this code, for instance:</p>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame({"col1":[1,2,3], "col2": [4,5,6]})
df.assign(
test1="hello",
test2=df.test1 + " world"
)
</code></pre>
<p>I'm facing this error:</p>
<blockquote>
<p>AttributeError: 'DataFrame' object has no attribute 'test1'</p>
</blockquote>
<p>However, it's explicitly stated <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.assign.html" rel="nofollow noreferrer">in the documentation</a> that:</p>
<blockquote>
<p>Assigning multiple columns within the same <code>assign</code> is possible. Later items in <code>**kwargs</code> may refer to newly created or modified columns in <code>df</code>; items are computed and assigned into <code>df</code> in order.</p>
</blockquote>
<p>So I don't understand: <strong>how can I refer to newly created or modified columns in <code>df</code> when calling <code>assign</code></strong>?</p>
|
[
{
"answer_id": 74599160,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "assign df = pd.DataFrame({\"col1\":[1,2,3], \"col2\": [4,5,6]})\n\ndf.assign(\n test1=\"hello\",\n test2=lambda d: d.test1 + \" world\"\n)\n col1 col2 test1 test2\n0 1 4 hello hello world\n1 2 5 hello hello world\n2 3 6 hello hello world\n"
},
{
"answer_id": 74599192,
"author": "Orfeas Bourchas",
"author_id": 16781682,
"author_profile": "https://Stackoverflow.com/users/16781682",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\ndf = pd.DataFrame({\"col1\":[1,2,3], \"col2\": [4,5,6]})\ndf['test1'] = \"hello\"\ndf['test2']=df.test1 + \" world\"\ndf\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12236313/"
] |
74,599,128
|
<p>here i'm facing some issue in scrolling</p>
<p>i have made one custom selection value through drum design with scrolling(that you can see on live code)
<strong>issue</strong></p>
<p>1.parent div scrolling while selecting the values in child component by scrolling</p>
<p><strong>what i tried</strong>
<strong>method-1</strong></p>
<p>i have tried the some kind of css methods like {overflow-y : scroll , position fixed} but no use, because i thought i have used the onWheel event insted of onScroll according to code needs</p>
<p><strong>Method-2</strong></p>
<p>i tried this method with the <code>mouseover</code> and <code>mouseout</code> event</p>
<p>here is the functionality in each block</p>
<p><strong>mouseover</strong></p>
<pre><code> const mouseHoverHandle = () => {
var parentScrollableDiv = document.querySelector(".container");
parentScrollableDiv.classList.add("containerScrollFiller");
};
</code></pre>
<p>here while mouseover on the component i just adding one class to desable scroll bar with hiden and adding one filler in the place of scroll strip by using Css <code>::after</code> class</p>
<p>here is the <code>containerScrollFiller</code> class property in css file</p>
<pre><code>.containerScrollFiller{
overflow-y: hidden ;
}
.containerScrollFiller::after{
position: absolute;
top: 0;
right: 0;
background-color: lightgray;
width: .5rem;
height: 100%;
content: "";
border-radius: .6rem;
}
</code></pre>
<p>here is the mouseOut block</p>
<p><strong>mouseOut</strong></p>
<pre><code> const mouseOutHandle = () => {
var parentScrollableDiv = document.querySelector(".container");
parentScrollableDiv.classList.remove("containerScrollFiller");
};
</code></pre>
<p>here im simply removing the class from the classlist</p>
<p>this method is working partially but UI shaking while mouseOut and mouseOver the component continiously. This looks little wiere (you can see this issue on live code below)</p>
<p><strong>how can we stop the scrolling without hiding or removing the scroll bar</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="true">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const CustomCalender = () => {
// let index = 1;
let getPeriod = { value1: "", value2: "", value3: "", value4: "" };
let index = [1, 1, 1, 1];
function scrollClass(event, array, td, md, bd, pt, objPt) {
var elementMd = document.getElementById(md);
var elementTo = document.getElementById(td);
var elementBo = document.getElementById(bd);
console.log(index[pt]);
index[pt] = event < 0 ? ++index[pt] : event > 0 ? --index[pt] : index[pt];
index[pt] =
index[pt] > array.length - 1
? 0
: index[pt] < 0
? array.length - 1
: index[pt];
elementMd.innerHTML = array[index[pt]];
elementTo.innerHTML =
array[index[pt] + 1] === undefined ? array[0] : array[index[pt] + 1];
elementBo.innerHTML =
array[index[pt] - 1] === undefined
? array[array.length - 1]
: array[index[pt] - 1];
getPeriod[objPt] = array[index[pt]];
}
const colors = [
"Dec",
"Nov",
"Oct",
"Sep",
"Aug",
"Jul",
"Jun",
"May",
"Apr",
"Mar",
"Feb",
"Jan",
];
const year = ["2025", "2024", "2023", "2022", "2021", "2020", "2019"];
const changeValueByWheel = (e, ar, td, md, bd, pt, objPlace) => {
scrollClass(e.deltaY, ar, td, md, bd, pt, objPlace);
};
const changeItem = (payload, ar, td, md, bd, pt, objPlace) => {
scrollClass(-payload, ar, td, md, bd, pt, objPlace);
};
const getCustomDate = () => {
console.log(getPeriod);
var parentScrollableDiv = document.querySelector(".container");
parentScrollableDiv.classList.remove("containerScrollFiller");
};
// demandForeCastingScrollFiller
const mouseOutHandle = () => {
var parentScrollableDiv = document.querySelector(".container");
parentScrollableDiv.setAttribute("style", "overflow-y:scroll");
parentScrollableDiv.classList.remove("containerScrollFiller");
};
const mouseHoverHandle = () => {
var parentScrollableDiv = document.querySelector(".container");
parentScrollableDiv.setAttribute("style", "overflow-y:hidden");
parentScrollableDiv.classList.add("containerScrollFiller");
};
return (
<div className="container">
<h4>What is Lorem Ipsum?</h4>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
</p>
<div
onMouseLeave={mouseOutHandle}
onMouseOver={mouseHoverHandle}
className="customCalenderContainer"
>
<div id="showItem" className="DemoContainer">
<div
onWheelCapture={(e) =>
changeValueByWheel(
e,
colors,
"startMonthTopEle",
"startMonthMiddleEle",
"startMonthBottomEle",
0,
"value1"
)
}
className="monthDiv"
>
<div
onClick={() =>
changeItem(
+1,
colors,
"startMonthTopEle",
"startMonthMiddleEle",
"startMonthBottomEle",
0,
"value1"
)
}
id="startMonthTopEle"
></div>
<div id="startMonthMiddleEle">{colors[colors.length - 1]}</div>
<div
onClick={() =>
changeItem(
-1,
colors,
"startMonthTopEle",
"startMonthMiddleEle",
"startMonthBottomEle",
0,
"value1"
)
}
id="startMonthBottomEle"
>
{colors[colors.length - 2]}
</div>
</div>
<div
onWheelCapture={(e) =>
changeValueByWheel(
e,
year,
"startYearTopEle",
"startYearMiddleEle",
"startYearBottomEle",
1,
"value2"
)
}
className="monthDiv"
>
<div
id="startYearTopEle"
onClick={() =>
changeItem(
+1,
year,
"startYearTopEle",
"startYearMiddleEle",
"startYearBottomEle",
1,
"value2"
)
}
></div>
<div id="startYearMiddleEle">{year[year.length - 1]}</div>
<div
onClick={() =>
changeItem(
-1,
year,
"startYearTopEle",
"startYearMiddleEle",
"startYearBottomEle",
1,
"value2"
)
}
id="startYearBottomEle"
>
{year[year.length - 2]}
</div>
</div>
<div className="middleDis">TO</div>
<div
onWheelCapture={(e) =>
changeValueByWheel(
e,
colors,
"endMonthTopEle",
"endMonthMiddleEle",
"endMonthBottomEle",
2,
"value3"
)
}
className="monthDiv"
>
<div
id="endMonthTopEle"
onClick={() =>
changeItem(
+1,
colors,
"endMonthTopEle",
"endMonthMiddleEle",
"endMonthBottomEle",
2,
"value3"
)
}
></div>
<div id="endMonthMiddleEle">{colors[colors.length - 1]}</div>
<div
onClick={() =>
changeItem(
-1,
colors,
"endMonthTopEle",
"endMonthMiddleEle",
"endMonthBottomEle",
2,
"value3"
)
}
id="endMonthBottomEle"
>
{colors[colors.length - 2]}
</div>
</div>
<div
onWheelCapture={(e) =>
changeValueByWheel(
e,
year,
"endYearTopEle",
"endYearMiddleEle",
"endYearBottomEle",
3,
"value4"
)
}
className="monthDiv"
>
<div
id="endYearTopEle"
onClick={() =>
changeItem(
+1,
year,
"endYearTopEle",
"endYearMiddleEle",
"endYearBottomEle",
3,
"value4"
)
}
></div>
<div id="endYearMiddleEle">{year[year.length - 2]}</div>
<div
onClick={() =>
changeItem(
-1,
year,
"endYearTopEle",
"endYearMiddleEle",
"endYearBottomEle",
3,
"value4"
)
}
id="endYearBottomEle"
>
{year[year.length - 3]}
</div>
</div>
</div>
<div className="calanderButtonContainer">
<button className="applyBtnCalender" onClick={getCustomDate}>
Apply
</button>
</div>
</div>
<h4>What is Lorem Ipsum?</h4>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
</p>
</div>
);
};
//==========================================
ReactDOM.createRoot(
document.getElementById("root")
).render(
<CustomCalender/>
);</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container{
width: 30rem;
height: 20rem;
background-color: white;
border: 1px solid gray;
overflow-y: scroll;
margin: auto auto;
background-color: purple;
color: white;
position: relative;
}
.container::-webkit-scrollbar{
width: .5rem;
/* background-color: green; */
}
.container::-webkit-scrollbar-thumb {
background: lightgray;
border-radius: .6rem;
}
.container::-webkit-scrollbar-thumb:hover {
background: #d8d8d8;
border-radius: .6rem;
}
.customCalenderContainer{
width: 15rem;
height: 12rem;
border-radius: .3rem;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
/* justify-content: space-evenly; */
justify-content: flex-start;
border: .01rem solid #f0f1f2;
margin: 2rem auto;
padding-top: 1rem;
}
.DemoContainer{
width: 13rem;
height: 8rem;
border-radius: .3rem;
background-color: white;
display: flex;
align-items: center;
justify-content: space-around;
margin: 0 auto;
}
.monthDiv{
height: 8rem;
width: 3rem;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
/* background-color: black; */
cursor: all-scroll;
}
#startMonthMiddleEle,
#startYearMiddleEle,
#endMonthMiddleEle,
#endYearMiddleEle{
border-bottom: .1rem solid #868686;
border-top: .1rem solid #868686;
font-weight: 700;
color: #717171;
padding: .3rem 0;
width: 80%;
text-align: center;
font-size: .9rem;
transition: 1s ease-in-out;
/* transform : translateY(-20px) */
}
#startMonthTopEle,
#startMonthBottomEle,
#startYearTopEle,
#startYearBottomEle,
#endMonthTopEle,
#endMonthBottomEle,
#endYearTopEle,
#endYearBottomEle{
font-weight: 500;
font-size: .6rem;
transition: 1s ease-in-out;
color: #9d9d9d;
/* background-color: green; */
height: 2rem;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.middleDis{
height: 9rem;
width: 2rem;
/* background-color: rgb(200, 254, 200); */
align-items: center;
display: flex;
justify-content: center;
font-weight: bolder;color: #717171;
}
.calanderButtonContainer{
width: 13rem;
display: flex;
align-items: flex-end;
justify-content: flex-end;
}
.applyBtnCalender{
background-color: orange;
color: white;
/* margin-top: -4vh; */
padding: 0.6em 1.1em;
font-size: .7rem;
font-family: 'Roboto', sans-serif;
border: none;
border-radius: .3rem;
cursor: pointer;
}
.containerScrollFiller::after{
position: absolute;
top: 0;
right: 0;
background-color: lightgray;
width: .5rem;
height: 100%;
content: "";
border-radius: .6rem;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.1.0/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.1.0/umd/react-dom.development.js"></script></code></pre>
</div>
</div>
</p>
<p>any help is so appreciatable</p>
<p><strong>thanks advance !!</strong></p>
|
[
{
"answer_id": 74599846,
"author": "Hoargarth",
"author_id": 9184970,
"author_profile": "https://Stackoverflow.com/users/9184970",
"pm_score": 2,
"selected": true,
"text": "mouseenter wheel e.preventdefault() e.stopPropagation mouseout removeEventListener() function preventScroll() mouseenter function preventScroll(e){\n // preventDefault keeps the element from scrolling\n e.preventDefault();\n \n // stopPropagation keeps the event to bubble up and scroll an outer container\n e.stopPropagation();\n\n return false;\n}\n\n// we get the containers here\nconst preventScrollElement = document.querySelector('.prevent-scroll');\nconst scrollContainer = document.querySelector('.container');\n\n// when you enter the element with your mouse, we add another eventlistener the the scrolling container itself\npreventScrollElement.addEventListener('mouseenter', () => {\n scrollContainer.addEventListener('wheel', preventScroll, {passive: false});\n});\n\n// as soon as we leave the element, we remove the eventlistener from the scroll container\npreventScrollElement.addEventListener('mouseout', () => {\n scrollContainer.removeEventListener('wheel', preventScroll);\n}); .container {\n height: 200px;\n width: 300px;\n margin: 0 auto;\n border: 1px solid black;\n overflow-y: scroll;\n}\n\n.prevent-scroll {\n width: 100px;\n height: 100px;\n margin: 0 auto;\n background: green;\n}\n\n.prevent-scroll:hover {\n background: red;\n} <div class=\"container\">\n <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>\n <div class=\"prevent-scroll\"></div>\n <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>\n</div>"
},
{
"answer_id": 74600423,
"author": "jsBug",
"author_id": 18055582,
"author_profile": "https://Stackoverflow.com/users/18055582",
"pm_score": 0,
"selected": false,
"text": "const CustomCalender = () => {\n // let index = 1;\n\n let getPeriod = { value1: \"\", value2: \"\", value3: \"\", value4: \"\" };\n let index = [1, 1, 1, 1];\n\n function scrollClass(event, array, td, md, bd, pt, objPt) {\n var elementMd = document.getElementById(md);\n var elementTo = document.getElementById(td);\n var elementBo = document.getElementById(bd);\n console.log(index[pt]);\n index[pt] = event < 0 ? ++index[pt] : event > 0 ? --index[pt] : index[pt];\n index[pt] =\n index[pt] > array.length - 1\n ? 0\n : index[pt] < 0\n ? array.length - 1\n : index[pt];\n elementMd.innerHTML = array[index[pt]];\n elementTo.innerHTML =\n array[index[pt] + 1] === undefined ? array[0] : array[index[pt] + 1];\n elementBo.innerHTML =\n array[index[pt] - 1] === undefined\n ? array[array.length - 1]\n : array[index[pt] - 1];\n getPeriod[objPt] = array[index[pt]];\n }\n const colors = [\n \"Dec\",\n \"Nov\",\n \"Oct\",\n \"Sep\",\n \"Aug\",\n \"Jul\",\n \"Jun\",\n \"May\",\n \"Apr\",\n \"Mar\",\n \"Feb\",\n \"Jan\",\n ];\n const year = [\"2025\", \"2024\", \"2023\", \"2022\", \"2021\", \"2020\", \"2019\"];\n \n function preventScroll(e) {\n // preventDefault keeps the element from scrolling\n e.preventDefault();\n\n return false;\n }\n\n const changeValueByWheel = (e, ar, td, md, bd, pt, objPlace) => {\n scrollClass(e.deltaY, ar, td, md, bd, pt, objPlace);\n };\n const changeItem = (payload, ar, td, md, bd, pt, objPlace) => {\n scrollClass(-payload, ar, td, md, bd, pt, objPlace);\n };\n const getCustomDate = () => {\n console.log(getPeriod);\n var parentScrollableDiv = document.querySelector(\".container\");\n };\n\n const mouseOutHandle = () => {\n var parentScrollableDiv = document.querySelector(\".container\");\n parentScrollableDiv.removeEventListener(\"wheel\", preventScroll);\n };\n const mouseHoverHandle = () => {\n var parentScrollableDiv = document.querySelector(\".container\");\n parentScrollableDiv.addEventListener(\"wheel\", preventScroll, {\n passive: false,\n });\n };\n\n return (\n <div className=\"container\">\n <h4>What is Lorem Ipsum?</h4>\n <p>\n Lorem Ipsum is simply dummy text of the printing and typesetting\n industry. Lorem Ipsum has been the industry's standard dummy text ever\n since the 1500s, when an unknown printer took a galley of type and\n scrambled it to make a type specimen book. It has survived not only five\n centuries, but also the leap into electronic typesetting, remaining\n essentially unchanged. It was popularised in the 1960s with the release\n of Letraset sheets containing Lorem Ipsum passages, and more recently\n with desktop publishing software like Aldus PageMaker including versions\n of Lorem Ipsum.\n </p>\n <div\n onMouseLeave={mouseOutHandle}\n onMouseOver={mouseHoverHandle}\n className=\"customCalenderContainer\"\n >\n <div id=\"showItem\" className=\"DemoContainer\">\n <div\n onWheelCapture={(e) =>\n changeValueByWheel(\n e,\n colors,\n \"startMonthTopEle\",\n \"startMonthMiddleEle\",\n \"startMonthBottomEle\",\n 0,\n \"value1\"\n )\n }\n className=\"monthDiv\"\n >\n <div\n onClick={() =>\n changeItem(\n +1,\n colors,\n \"startMonthTopEle\",\n \"startMonthMiddleEle\",\n \"startMonthBottomEle\",\n 0,\n \"value1\"\n )\n }\n id=\"startMonthTopEle\"\n ></div>\n <div id=\"startMonthMiddleEle\">{colors[colors.length - 1]}</div>\n <div\n onClick={() =>\n changeItem(\n -1,\n colors,\n \"startMonthTopEle\",\n \"startMonthMiddleEle\",\n \"startMonthBottomEle\",\n 0,\n \"value1\"\n )\n }\n id=\"startMonthBottomEle\"\n >\n {colors[colors.length - 2]}\n </div>\n </div>\n <div\n onWheelCapture={(e) =>\n changeValueByWheel(\n e,\n year,\n \"startYearTopEle\",\n \"startYearMiddleEle\",\n \"startYearBottomEle\",\n 1,\n \"value2\"\n )\n }\n className=\"monthDiv\"\n >\n <div\n id=\"startYearTopEle\"\n onClick={() =>\n changeItem(\n +1,\n year,\n \"startYearTopEle\",\n \"startYearMiddleEle\",\n \"startYearBottomEle\",\n 1,\n \"value2\"\n )\n }\n ></div>\n <div id=\"startYearMiddleEle\">{year[year.length - 1]}</div>\n <div\n onClick={() =>\n changeItem(\n -1,\n year,\n \"startYearTopEle\",\n \"startYearMiddleEle\",\n \"startYearBottomEle\",\n 1,\n \"value2\"\n )\n }\n id=\"startYearBottomEle\"\n >\n {year[year.length - 2]}\n </div>\n </div>\n <div className=\"middleDis\">TO</div>\n <div\n onWheelCapture={(e) =>\n changeValueByWheel(\n e,\n colors,\n \"endMonthTopEle\",\n \"endMonthMiddleEle\",\n \"endMonthBottomEle\",\n 2,\n \"value3\"\n )\n }\n className=\"monthDiv\"\n >\n <div\n id=\"endMonthTopEle\"\n onClick={() =>\n changeItem(\n +1,\n colors,\n \"endMonthTopEle\",\n \"endMonthMiddleEle\",\n \"endMonthBottomEle\",\n 2,\n \"value3\"\n )\n }\n ></div>\n <div id=\"endMonthMiddleEle\">{colors[colors.length - 1]}</div>\n <div\n onClick={() =>\n changeItem(\n -1,\n colors,\n \"endMonthTopEle\",\n \"endMonthMiddleEle\",\n \"endMonthBottomEle\",\n 2,\n \"value3\"\n )\n }\n id=\"endMonthBottomEle\"\n >\n {colors[colors.length - 2]}\n </div>\n </div>\n <div\n onWheelCapture={(e) =>\n changeValueByWheel(\n e,\n year,\n \"endYearTopEle\",\n \"endYearMiddleEle\",\n \"endYearBottomEle\",\n 3,\n \"value4\"\n )\n }\n className=\"monthDiv\"\n >\n <div\n id=\"endYearTopEle\"\n onClick={() =>\n changeItem(\n +1,\n year,\n \"endYearTopEle\",\n \"endYearMiddleEle\",\n \"endYearBottomEle\",\n 3,\n \"value4\"\n )\n }\n ></div>\n <div id=\"endYearMiddleEle\">{year[year.length - 2]}</div>\n <div\n onClick={() =>\n changeItem(\n -1,\n year,\n \"endYearTopEle\",\n \"endYearMiddleEle\",\n \"endYearBottomEle\",\n 3,\n \"value4\"\n )\n }\n id=\"endYearBottomEle\"\n >\n {year[year.length - 3]}\n </div>\n </div>\n </div>\n <div className=\"calanderButtonContainer\">\n <button className=\"applyBtnCalender\" onClick={getCustomDate}>\n Apply\n </button>\n </div>\n </div>\n <h4>What is Lorem Ipsum?</h4>\n <p>\n Lorem Ipsum is simply dummy text of the printing and typesetting\n industry. Lorem Ipsum has been the industry's standard dummy text ever\n since the 1500s, when an unknown printer took a galley of type and\n scrambled it to make a type specimen book. It has survived not only five\n centuries, but also the leap into electronic typesetting, remaining\n essentially unchanged. It was popularised in the 1960s with the release\n of Letraset sheets containing Lorem Ipsum passages, and more recently\n with desktop publishing software like Aldus PageMaker including versions\n of Lorem Ipsum.\n </p>\n </div>\n );\n};\n\n\n//==========================================\nReactDOM.createRoot(\n document.getElementById(\"root\")\n).render(\n <CustomCalender/>\n); .container{\n width: 30rem;\n height: 20rem;\n background-color: white;\n border: 1px solid gray;\n overflow-y: scroll;\n margin: auto auto;\n background-color: purple;\n color: white;\n position: relative;\n}\n.container::-webkit-scrollbar{\n width: .5rem;\n /* background-color: green; */\n }\n .container::-webkit-scrollbar-thumb {\n background: lightgray;\n border-radius: .6rem;\n }\n \n .container::-webkit-scrollbar-thumb:hover {\n background: #d8d8d8;\n border-radius: .6rem;\n }\n\n\n.customCalenderContainer{\n width: 15rem;\n height: 12rem;\n border-radius: .3rem; \n background-color: black; \n display: flex;\n flex-direction: column;\n align-items: center;\n /* justify-content: space-evenly; */\n justify-content: flex-start;\n border: .01rem solid #f0f1f2;\n margin: 2rem auto;\n padding-top: 1rem;\n}\n.DemoContainer{\n width: 13rem;\n height: 8rem;\n border-radius: .3rem; \n background-color: white; \n display: flex;\n align-items: center;\n justify-content: space-around;\n margin: 0 auto;\n}\n.monthDiv{\n height: 8rem;\n width: 3rem;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n /* background-color: black; */\n cursor: all-scroll;\n}\n#startMonthMiddleEle,\n#startYearMiddleEle,\n#endMonthMiddleEle,\n#endYearMiddleEle{\n border-bottom: .1rem solid #868686;\n border-top: .1rem solid #868686;\n font-weight: 700;\n color: #717171;\n padding: .3rem 0;\n width: 80%;\n text-align: center;\n font-size: .9rem;\n transition: 1s ease-in-out;\n /* transform : translateY(-20px) */\n}\n#startMonthTopEle,\n#startMonthBottomEle,\n#startYearTopEle,\n#startYearBottomEle,\n#endMonthTopEle,\n#endMonthBottomEle,\n#endYearTopEle,\n#endYearBottomEle{\n font-weight: 500;\n font-size: .6rem;\n transition: 1s ease-in-out;\n color: #9d9d9d;\n /* background-color: green; */\n height: 2rem;\n width: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n}\n\n\n.middleDis{\n height: 9rem;\n width: 2rem;\n /* background-color: rgb(200, 254, 200); */\n align-items: center;\n display: flex;\n justify-content: center;\n font-weight: bolder;color: #717171;\n}\n.calanderButtonContainer{\n width: 13rem;\n display: flex;\n align-items: flex-end;\n justify-content: flex-end;\n}\n.applyBtnCalender{\nbackground-color: orange;\ncolor: white;\n/* margin-top: -4vh; */\npadding: 0.6em 1.1em;\nfont-size: .7rem;\nfont-family: 'Roboto', sans-serif;\nborder: none;\nborder-radius: .3rem;\ncursor: pointer;\n} <div id=\"root\"></div>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/react/18.1.0/umd/react.development.js\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.1.0/umd/react-dom.development.js\"></script>"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18055582/"
] |
74,599,137
|
<p>I have a class "SuperBase" with public methods and a class "Base", that derives from SuperBase, also with public methods. I cannot alter these, as they come from an external project.</p>
<p>I want my own class "Derived" to inherit privately from Base, but still keep SuperBase public.</p>
<p>External Code (cannot be changed):</p>
<pre><code>class SuperBase
{
public:
void printSuperBase() const
{
std::cout << "Super Base Class\n";
}
};
class Base : public SuperBase
{
public:
void print() const
{
std::cout << "Base Class\n";
}
};
</code></pre>
<p>My own code (can be changed):</p>
<pre><code>class Derived: private Base
{
public:
void print() const
{
std::cout << "Derived Class\n";
}
};
void function(SuperBase const& sb)
{
sb.printSuperBase();
}
int main()
{
Derived D{};
D.print(); //prints "Derived Class\n"
function(D); //cannot access SuperBase, as Base was included privately
}
</code></pre>
<p>Note that I cannot override any of the Base class methods, as they are not declared virtual.</p>
<p>Including both, Base and SuperBase does not work as this makes SuperBase ambiguous.</p>
<pre><code>class Derived: private Base, public SuperBase
{
public:
void print() const
{
std::cout << "Derived Class\n";
}
};
void function(SuperBase const& sb)
{
sb.printSuperBase();
}
int main()
{
Derived D{};
D.print(); //prints "Derived Class\n"
function(D); //base class SuperBase is ambiguous
}
</code></pre>
<p>Including Base publicly and declaring it's methods as private does not work either, as I now can pass Derived to functions using Base, that can access all privately declared methods</p>
<pre><code>class Derived: public Base
{
public:
void print() const
{
std::cout << "Derived Class\n";
}
private:
using Base::print; //declare base method private to make it inaccessible
};
void function2(Base const& b)
{
b.print(); //prints "Base Class\n", but shall be inaccessible instead.
b.printSuperBase();
}
int main()
{
Derived D{};
D.print(); //prints "Derived Class\n"
function2(D); //D gets passed as Base class, but shall not be allowed
}
</code></pre>
|
[
{
"answer_id": 74599311,
"author": "The Dreams Wind",
"author_id": 5690248,
"author_profile": "https://Stackoverflow.com/users/5690248",
"pm_score": 0,
"selected": false,
"text": "Derived Base Base SuperBase Base class Derived: public SuperBase\n{\n Base imp;\npublic:\n void print() const\n {\n std::cout << \"Derived Class\\n\";\n }\n};\n"
},
{
"answer_id": 74599319,
"author": "fabian",
"author_id": 2991525,
"author_profile": "https://Stackoverflow.com/users/2991525",
"pm_score": 0,
"selected": false,
"text": "SuperBase virtual Base function function void function(SuperBase const& sb);\n\nclass Derived : private Base\n{\npublic:\n void print() const\n {\n std::cout << \"Derived Class\\n\";\n }\n\n /**\n * Introduce a overload of function at namespace scope that has access to the conversion to SuperBase\n */\n friend void function(Derived const& derived)\n {\n function(static_cast<SuperBase const&>(derived));\n }\n};\n\nvoid function(SuperBase const& sb)\n{\n sb.printSuperBase();\n}\n"
},
{
"answer_id": 74599426,
"author": "Simon Kraemer",
"author_id": 4181011,
"author_profile": "https://Stackoverflow.com/users/4181011",
"pm_score": 3,
"selected": true,
"text": "class Derived\n{\nprivate:\n Base mBase;\n\npublic:\n void print() const\n {\n std::cout << \"Derived Class\\n\";\n }\n\n operator SuperBase const&() const\n {\n return mBase;\n }\n\n operator SuperBase&()\n {\n return mBase;\n }\n};\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7506852/"
] |
74,599,147
|
<p>Say I am generating random numbers using <code>Math.random()</code>, maybe 1000 of them, and I want to have them in ascending order (at all times). Is there an algorithm of some variety that can keep them sorted the whole time, without ever having to call a sort routine? The only thing I can think of is a BST? but there might be a better way.</p>
<p>Some code will help:</p>
<pre><code>const numContainer = {};
for(let i = 0; i < 1000; i++){
const r = Math.random(); // I generate a new RV
numContainer[r] = {r}; // I want to store it in order, but this isn't helping :-)
}
</code></pre>
<p>clearly the above is not really going to maintain any numerical order for the keys etc. I am looking to have them be sorted as I go.</p>
<p><strong>Update</strong>: I realize the use-case might be good to know (or interesting). The use-case is a discrete-event-simulation, the smaller the random uniform variable the sooner the event, so I need to read the events in numerical order so it would be nice if they were sorted, naturally, instead of requiring a sort or what not.</p>
|
[
{
"answer_id": 74600580,
"author": "Dave",
"author_id": 2041077,
"author_profile": "https://Stackoverflow.com/users/2041077",
"pm_score": 2,
"selected": false,
"text": "/**\n * Generate an sorted list of random numbers sorted from 1 to 0, given the size\n * of the list being requested.\n * \n * This is an implementation of an algorithm developed by Bentley and Sax, and\n * published in in ACM Transactions on Mathematical Software (v6, iss3, 1980) on\n * 'Generating Sorted Lists of Random Numbers'.\n */\npublic class SortedRandomDoubleGenerator {\n private long valsFound;\n private double curMax;\n private final long numVals;\n\n /**\n * Instantiate a generator of sorted random doubles.\n * \n * @param numVals the size of the list of sorted random doubles to be\n * generated\n */\n public SortedRandomDoubleGenerator(long numVals) {\n curMax = 1.0;\n valsFound = 0;\n this.numVals = numVals;\n }\n\n /**\n * @return the next random number, in descending order.\n */\n public double getNext() {\n curMax = curMax\n * Math.pow(Math.E, Math.log(RandomNumbers.nextDouble())\n / (numVals - valsFound));\n valsFound++;\n return curMax;\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1223975/"
] |
74,599,149
|
<p>I am trying to sum each year's quantity but I also want to add previous year's closing quantity in this sum.</p>
<p>Following is the sample dataset.</p>
<pre><code>DROP TABLE IF EXISTS #tmpTable
CREATE TABLE #tmpTable (
FinancialYear varchar(max),
Date date,
ItemName varchar(255),
InQTY int,
ClosingQTY int)
INSERT INTO #tmpTable (FinancialYear, Date, ItemName, InQTY, ClosingQTY) VALUES
('2021-22', CONVERT(DATETIME, '2021-04-05', 120), 'ItemA', 5, 5),
('2021-22', CONVERT(DATETIME, '2021-05-17', 120), 'ItemA', 3, 7),
('2021-22', CONVERT(DATETIME, '2021-11-09', 120), 'ItemA', 2, 9),
('2021-22', CONVERT(DATETIME, '2022-02-25', 120), 'ItemA', NULL, 7),
('2022-23', CONVERT(DATETIME, '2022-04-02', 120), 'ItemA', 2, 9),
('2022-23', CONVERT(DATETIME, '2022-11-01', 120), 'ItemA', 3, 11),
('2022-23', CONVERT(DATETIME, '2022-12-14', 120), 'ItemA', 4, 15)
GO
SELECT * FROM #tmpTable
</code></pre>
<p>Sample Table:</p>
<pre><code>╔═══════════════╤════════════╤══════════╤═══════╤════════════╗
║ FinancialYear │ Date │ ItemName │ InQTY │ ClosingQTY ║
╠═══════════════╪════════════╪══════════╪═══════╪════════════╣
║ 2021-22 │ 2021-04-05 │ ItemA │ 5 │ 5 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2021-22 │ 2021-05-17 │ ItemA │ 3 │ 7 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2021-22 │ 2021-11-09 │ ItemA │ 2 │ 9 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2021-22 │ 2022-02-25 │ ItemA │ NULL │ 7 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2022-23 │ 2022-04-02 │ ItemA │ 2 │ 9 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2022-23 │ 2022-11-01 │ ItemA │ 3 │ 11 ║
╟───────────────┼────────────┼──────────┼───────┼────────────╢
║ 2022-23 │ 2022-12-14 │ ItemA │ 4 │ 15 ║
╚═══════════════╧════════════╧══════════╧═══════╧════════════╝
</code></pre>
<p>I tried "Over (Partition By )" to get each year's running sum.</p>
<pre><code>SELECT a.FinancialYear, a.Date, a.ItemName, a.InQTY, a.ClosingQTY
,SUM(a.InQTY) OVER (PARTITION BY a.ItemName, a.FinancialYear ORDER BY a.Date) [RunningInQTY]
FROM #tmpTable a
</code></pre>
<p>But I am not able to find a way to add previous year's closing QTY which is lying in another column and last row before beginning of new year.</p>
<p>Following is the expected result (marked in red box)</p>
<p><a href="https://i.stack.imgur.com/WTkxa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WTkxa.png" alt="Required Output" /></a></p>
|
[
{
"answer_id": 74600580,
"author": "Dave",
"author_id": 2041077,
"author_profile": "https://Stackoverflow.com/users/2041077",
"pm_score": 2,
"selected": false,
"text": "/**\n * Generate an sorted list of random numbers sorted from 1 to 0, given the size\n * of the list being requested.\n * \n * This is an implementation of an algorithm developed by Bentley and Sax, and\n * published in in ACM Transactions on Mathematical Software (v6, iss3, 1980) on\n * 'Generating Sorted Lists of Random Numbers'.\n */\npublic class SortedRandomDoubleGenerator {\n private long valsFound;\n private double curMax;\n private final long numVals;\n\n /**\n * Instantiate a generator of sorted random doubles.\n * \n * @param numVals the size of the list of sorted random doubles to be\n * generated\n */\n public SortedRandomDoubleGenerator(long numVals) {\n curMax = 1.0;\n valsFound = 0;\n this.numVals = numVals;\n }\n\n /**\n * @return the next random number, in descending order.\n */\n public double getNext() {\n curMax = curMax\n * Math.pow(Math.E, Math.log(RandomNumbers.nextDouble())\n / (numVals - valsFound));\n valsFound++;\n return curMax;\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1041627/"
] |
74,599,158
|
<p>We have a project in <code>spring-integration</code> that will work with either <code>webflex</code> or <code>servlet</code> implementations and this seems to work pretty well using the <code>spring.main.web-application-type</code> property set as a system property.</p>
<p>I'm now looking for how to choose the embedded web server at runtime.</p>
<p>The <code>spring-boot</code> documentation says that this is accomplished via dependency inclusion or exclusion with the <code>pom.xml</code>.</p>
<p><a href="https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html</a></p>
<p>What I'm looking for is to be able to start any of <code>jetty</code>, <code>netty</code>, <code>undertow</code> or <code>tomcat</code> from the same project/executable jar.</p>
<p>Is this feasible by some specific startup sequence in SpringApplication?</p>
<p>Thanks for any pointers/suggestions.</p>
|
[
{
"answer_id": 74602298,
"author": "Artem Bilan",
"author_id": 2756547,
"author_profile": "https://Stackoverflow.com/users/2756547",
"pm_score": 1,
"selected": false,
"text": "test FilteredClassLoader @SpringBootApplication.exclude()"
},
{
"answer_id": 74607255,
"author": "al.truisme",
"author_id": 16750357,
"author_profile": "https://Stackoverflow.com/users/16750357",
"pm_score": 0,
"selected": false,
"text": "spring-boot WebServerApplicationContext spring.main.web-application-type reactive servlet ReactiveWebServerApplicationContext ServletWebServerApplicationContext createWebServer() ReactiveWebServerFactory ServletWebServerFactory WebServerFactory WebApplicationContext WebServerFactory WebServerFactory my.main.web-server spring.main.web-application-type BeanFactory WebServerFactory package net.demo;\n\n...\n\npublic class MyWebServerFactoryBeanFactory implements EnvironmentAware {\n private Environment environment;\n\n public ReactiveWebServerFactory createReactiveWebServerFactory() {\n switch(getWebServer()) {\n case \"jetty\":\n return new JettyReactiveWebServerFactory();\n case \"netty\":\n return new NettyReactiveWebServerFactory();\n case \"undertow\":\n return new UndertowReactiveWebServerFactory();\n case \"tomcat\":\n case default:\n return new TomcatReactiveWebServerFactory();\n }\n }\n\n public ServletWebServerFactory createServletWebServerFactory() {\n switch(getWebServer()) {\n case \"jetty\":\n return new JettyServletWebServerFactory();\n case \"undertow\":\n return new UndertowServletWebServerFactory();\n case \"tomcat\":\n case default:\n return new TomcatServletWebServerFactory();\n }\n }\n\n private String getWebServer() {\n return environment.getProperty(\"my.main.web-server\");\n }\n}\n reactive servlet ...\n<import resource=\"classpath:my-${spring.main.web-application-type:servlet}.xml\" />\n\n<bean id=\"myWebServerFactoryBeanFactory\"\n class=\"net.demo.MyWebServerFactoryBeanFactory\" />\n...\n WebServerFactory my-reactive.xml <bean id=\"myWebServerFactory\" factory-bean=\"net.demo.MyWebServerFactoryBeanFactory\"\n factory-method=\"createReactiveWebServerFactory\" />\n my-servlet.xml <bean id=\"myWebServerFactory\" factory-bean=\"net.demo.MyWebServerFactoryBeanFactory\"\n factory-method=\"createServletWebServerFactory\" />\n ReactiveWebServerFactory ServletWebServerFactory"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16750357/"
] |
74,599,179
|
<p>I want to let user to download some file from storage path. In this case will be some backups they have made. So i have a method can create backups and show on vue js table. And now i am trying to downlaod manyally from vue</p>
<pre><code><tr v-show="backups.length" v-for="backup in backups" :key="backup.id">
<td>{{backup.path}}</td>
<td>{{backup.size}} KB</td>
<td>
<v-button type="sm-secondary" title="Download" @click="downloadBackup(backup.path)">
<i class="fa-solid fa-download"></i>
</v-button>
</td>
</tr>
methods: {
downloadBackup(path) {
axios.get('/download-backup-system/'+path)
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
}
}
//dd($Filepath);
//RETURN
//"C:\...\storage\app/Backup/2022-11-28-10-21-27.zip"
</code></pre>
<p>Laravel controller</p>
<pre><code>public function downloadBackups($path)
{
$Filepath = storage_path('app/Backup/'.$path);
if (file_exists($Filepath)) {
return Response::download($Filepath);
}
}
</code></pre>
<p>But this does not work and on response i get something like this</p>
<pre><code>PK�.�&_���vt�8̩��....
</code></pre>
<p>Also i have tryed this <code>https://stackoverflow.com/questions/48534837/how-to-download-zip-file-through-browser-laravel</code> method, but does not work for me</p>
|
[
{
"answer_id": 74599374,
"author": "Delano van londen",
"author_id": 19923550,
"author_profile": "https://Stackoverflow.com/users/19923550",
"pm_score": 0,
"selected": false,
"text": "public function download(Request $request, int $fileId)\n// $fileId is the id from the download button\n{\n $fullfile = File::find($fileId);\n $downloadfile = File::find($fullfile, ['file'])->pluck('file')->last();\n\n return response()->download($downloadfile);\n\n}\n"
},
{
"answer_id": 74602190,
"author": "John Zwarthoed",
"author_id": 4920105,
"author_profile": "https://Stackoverflow.com/users/4920105",
"pm_score": 2,
"selected": true,
"text": "a href <tr v-show=\"backups.length\" v-for=\"backup in backups\" :key=\"backup.id\">\n <td>{{backup.path}}</td>\n <td>{{backup.size}} KB</td>\n <td>\n <a :href=\"`/download-backup-system/` + backup.path\">\n Download <i class=\"fa-solid fa-download\"></i>\n </a>\n </td>\n</tr>\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19617678/"
] |
74,599,202
|
<p>I have a database with tables ARTIST and SONG. Each song has a number of reproductions, an album associated and the artist_id that owns it. I want to get for each artist, the album that has the highest number of reproductions counting al of its songs. The tables are something like this:</p>
<p>Artist:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Artist_Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Ignacio Guitar</td>
</tr>
<tr>
<td>2</td>
<td>Rosalia</td>
</tr>
<tr>
<td>3</td>
<td>Makande</td>
</tr>
</tbody>
</table>
</div>
<p>Song:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Artist_Id</th>
<th>Name</th>
<th>N_reproductions</th>
<th>Name_album</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Song1</td>
<td>10</td>
<td>Album1</td>
</tr>
<tr>
<td>1</td>
<td>Song2</td>
<td>15</td>
<td>Album1</td>
</tr>
<tr>
<td>1</td>
<td>Song3</td>
<td>13</td>
<td>Album1</td>
</tr>
<tr>
<td>1</td>
<td>Song4</td>
<td>20</td>
<td>Album2</td>
</tr>
<tr>
<td>1</td>
<td>Song5</td>
<td>12</td>
<td>Album2</td>
</tr>
<tr>
<td>1</td>
<td>Song6</td>
<td>25</td>
<td>Album2</td>
</tr>
<tr>
<td>2</td>
<td>Song7</td>
<td>17</td>
<td>Album3</td>
</tr>
<tr>
<td>2</td>
<td>Song8</td>
<td>21</td>
<td>Album3</td>
</tr>
<tr>
<td>2</td>
<td>Song9</td>
<td>20</td>
<td>Album4</td>
</tr>
<tr>
<td>2</td>
<td>Song10</td>
<td>25</td>
<td>Album4</td>
</tr>
<tr>
<td>2</td>
<td>Song11</td>
<td>31</td>
<td>Album4</td>
</tr>
</tbody>
</table>
</div>
<p>So the result I want to get would be</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Name</th>
<th>Name_album</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ignacio Guitar</td>
<td>Album2</td>
</tr>
<tr>
<td>Rosalia</td>
<td>Album4</td>
</tr>
</tbody>
</table>
</div>
<p>So far I've tried this:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT a.name, s.name_alb
FROM artist a
JOIN song s
ON (a.artist_id = s.artist_id)
GROUP BY a.artist_id, a.name, s.name_alb
HAVING SUM(s.n_reproductions) = (SELECT MAX(SUM(s1.n_reproductions))
FROM song s1
WHERE s1.artist_id = a.artist_id
AND s1.name_alb = s.name_alb
GROUP BY s1.artist_id, s1.name_alb);
</code></pre>
<p>but this returns every album from every artist instead.</p>
|
[
{
"answer_id": 74599374,
"author": "Delano van londen",
"author_id": 19923550,
"author_profile": "https://Stackoverflow.com/users/19923550",
"pm_score": 0,
"selected": false,
"text": "public function download(Request $request, int $fileId)\n// $fileId is the id from the download button\n{\n $fullfile = File::find($fileId);\n $downloadfile = File::find($fullfile, ['file'])->pluck('file')->last();\n\n return response()->download($downloadfile);\n\n}\n"
},
{
"answer_id": 74602190,
"author": "John Zwarthoed",
"author_id": 4920105,
"author_profile": "https://Stackoverflow.com/users/4920105",
"pm_score": 2,
"selected": true,
"text": "a href <tr v-show=\"backups.length\" v-for=\"backup in backups\" :key=\"backup.id\">\n <td>{{backup.path}}</td>\n <td>{{backup.size}} KB</td>\n <td>\n <a :href=\"`/download-backup-system/` + backup.path\">\n Download <i class=\"fa-solid fa-download\"></i>\n </a>\n </td>\n</tr>\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14936363/"
] |
74,599,206
|
<p>My file is having unwanted Control-M characters at the end of the records and because of this file is not getting processed.</p>
<p><strong>Sample file (CSV)</strong>
<a href="https://i.stack.imgur.com/fccCA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fccCA.png" alt="Sample file" /></a></p>
<p>Please suggest how can I use ReplaceAll function in Groovy to remove it .</p>
|
[
{
"answer_id": 74599334,
"author": "Gicu Aftene",
"author_id": 18811731,
"author_profile": "https://Stackoverflow.com/users/18811731",
"pm_score": 1,
"selected": true,
"text": "csvFileContent.replaceAll(\"\\r\\n\", \"\\n\");\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18116970/"
] |
74,599,250
|
<p>Based on a passed parameter containing a type I'm looking for a better way to initialize the class based on that type. Currently I'm "solving" it with a switch statement which is feels quite redundant.</p>
<p>Bad example showing what the functionality is:</p>
<pre><code>protected Quest GenerateQuest(QuestConfiguration questConfiguration)
{
List<QuestObjective> objectives = new();
foreach ( QuestObjectiveConfiguration questConfigurationObjective in questConfiguration.ObjectiveConfigurations)
{
switch (questConfigurationObjective.ObjectiveType)
{
case ObjectiveType.Fetch:
objectives.Add(new ObjectiveFetch(questConfigurationObjective.InternalId));
break;
case ObjectiveType.Gather:
objectives.Add(new ObjectiveGather(questConfigurationObjective.InternalId));
break;
case ObjectiveType.Craft:
objectives.Add(new ObjectiveCraft(questConfigurationObjective.InternalId));
break;
case ObjectiveType.Deliver:
objectives.Add(new ObjectiveDeliver(questConfigurationObjective.InternalId));
break;
case ObjectiveType.Combat:
objectives.Add(new ObjectiveCombatEncounter(questConfigurationObjective.InternalId));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
return new Quest(objectives);
}
</code></pre>
<p>Looked/googled for suiting patterns but I'm having a hard time getting specific results because the related terms are generic and the issue is an edgecase.</p>
|
[
{
"answer_id": 74599605,
"author": "Peter Csala",
"author_id": 13268855,
"author_profile": "https://Stackoverflow.com/users/13268855",
"pm_score": 1,
"selected": false,
"text": "protected Quest GenerateQuest(QuestConfiguration questConfiguration)\n{\n List<QuestObjective> objectives = questConfiguration.ObjectiveConfigurations\n .Select(questConfigurationObjective =>\n {\n var id = questConfigurationObjective.InternalId;\n QuestObjective objective = questConfigurationObjective.ObjectiveType switch\n {\n ObjectiveType.Fetch => new ObjectiveFetch(id),\n ObjectiveType.Gather => new ObjectiveGather(id),\n ObjectiveType.Craft => new ObjectiveCraft(id),\n ObjectiveType.Deliver => new ObjectiveDeliver(id),\n ObjectiveType.Combat => new ObjectiveCombatEncounter(id),\n _ => throw new ArgumentOutOfRangeException()\n };\n return objective;\n })\n .ToList();\n \n return new Quest(objectives);\n}\n protected Quest GenerateQuest(QuestConfiguration questConfiguration)\n => new Quest(questConfiguration.ObjectiveConfigurations\n .Select(questConfigurationObjective =>\n {\n var id = questConfigurationObjective.InternalId;\n return questConfigurationObjective.ObjectiveType switch\n {\n ObjectiveType.Fetch => new ObjectiveFetch(id),\n ObjectiveType.Gather => new ObjectiveGather(id),\n ObjectiveType.Craft => new ObjectiveCraft(id),\n ObjectiveType.Deliver => new ObjectiveDeliver(id),\n ObjectiveType.Combat => new ObjectiveCombatEncounter(id),\n _ => throw new ArgumentOutOfRangeException()\n };\n })\n .ToList());\n"
},
{
"answer_id": 74599682,
"author": "noel",
"author_id": 10650696,
"author_profile": "https://Stackoverflow.com/users/10650696",
"pm_score": 2,
"selected": true,
"text": "QuestObjective QuestObjectiveConfiguration static class QuestObjectiveConfigurationExtensions\n{\n public static QuestObjective ToQuestObjective(\n this QuestObjectiveConfiguration config) => config.ObjectiveType switch\n {\n ObjectiveType.Fetch => new ObjectiveFetch(config.InternalId),\n //rest of your types\n _ => //maybe throw an Exception here\n };\n}\n var objectives = questConfiguration.ObjectiveConfigurations.Select(x => x.ToQuestObjective)\n QuestConfiguration Quest ToQuest QuestObjectiveConfiguration ToQuestObjective"
},
{
"answer_id": 74599722,
"author": "D A",
"author_id": 13840530,
"author_profile": "https://Stackoverflow.com/users/13840530",
"pm_score": 0,
"selected": false,
"text": " Quest GenerateQuest(QuestConfiguration questConfiguration)\n {\n\n List<QuestObjective> objectives = new();\n Dictionary<ObjectiveType, Type> lstActions = new Dictionary<ObjectiveType, Type>();\n lstActions.Add(ObjectiveType.Fetch, typeof(ObjectiveFetch));\n lstActions.Add(ObjectiveType.Gather, typeof(ObjectiveGather));\n lstActions.Add(ObjectiveType.Craft, typeof(ObjectiveCraft));\n lstActions.Add(ObjectiveType.Deliver, typeof(ObjectiveDeliver));\n lstActions.Add(ObjectiveType.Combat, typeof(ObjectiveCombatEncounter));\n\n foreach (QuestObjectiveConfiguration questConfigurationObjective in questConfiguration.ObjectiveConfigurations)\n {\n if (lstActions.ContainsKey(questConfigurationObjective.ObjectiveType))\n objectives.Add((QuestObjective)Activator.CreateInstance(lstActions[questConfigurationObjective.ObjectiveType], new[] { questConfigurationObjective.InternalId }));\n else\n throw new ArgumentOutOfRangeException();\n }\n }\n return new Quest(objectives);\n }\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1145747/"
] |
74,599,252
|
<p>I am doing a field validation in Angular component. There is a one field like it should allow to enter either 6 or 8 length of any characters. Usually minLength(6), maxLength(8) will work if it is 6 to 8 in between but length 7 should not allow here. I can do custom validation, but out of curiosity I'm looking is there any way to handle this kind of scenario. Thanks in advance.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>'myField': ['', [Validators.minLength(6), Validators.maxLength(8)]]</code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74599399,
"author": "MoxxiManagarm",
"author_id": 11011793,
"author_profile": "https://Stackoverflow.com/users/11011793",
"pm_score": 3,
"selected": true,
"text": "Validator.pattern myControl: FormControl = new FormControl(undefined, [\n Validators.pattern('^.{6}$|^.{8}$'),\n ]);\n myControl: FormControl = new FormControl(undefined, [\n Validators.pattern('^[a-zA-Z]{6}$|^[a-zA-Z]{8}$'),\n ]);\n"
},
{
"answer_id": 74599459,
"author": "Chady BAGHDADI",
"author_id": 16227834,
"author_profile": "https://Stackoverflow.com/users/16227834",
"pm_score": 0,
"selected": false,
"text": "function between(x, min, max) {\n return x >= min && x <= max;\n}\n\n\nfunction ratingRange(min: number, max: number): \n\n ValidatorFn {\n return (c: AbstractControl): { [key: string]: boolean } | null => {\n if (c.value !== null && (isNaN(c.value) || c.value < min || c.value > max) || this.between(c.value , min , max)) {\n return { range: true };\n }\n return null;\n };\n }\n 'myField': [null, ratingRange(6, 8)],\n"
},
{
"answer_id": 74599569,
"author": "Abdullah Alhazmy",
"author_id": 2476476,
"author_profile": "https://Stackoverflow.com/users/2476476",
"pm_score": 1,
"selected": false,
"text": "'myField': ['', [Validators.pattern('^(?=(?:.{6}|.{8})$).*$')]]\n\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8779864/"
] |
74,599,262
|
<p>let currdate =2022-11-28T10:26:00.949Z</p>
<pre><code>I have to convert the date like
28 Nov , 2022 :4:05:33 PM
</code></pre>
<p>Please suggest , tried some examples but not getting like this</p>
<p>Thanks</p>
|
[
{
"answer_id": 74599341,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": -1,
"selected": false,
"text": "moment(\"2022-11-28T10:26:00.949Z\").format(\"DD MMM , yyyy :h:mm:ss A\")\n"
},
{
"answer_id": 74599622,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 3,
"selected": true,
"text": "DateTimeFormat const formatter = new Intl.DateTimeFormat('en-GB', {\n year: 'numeric', month: '2-digit', day: '2-digit',\n hour: 'numeric', minute: '2-digit', second: '2-digit',\n hourCycle: 'h12',\n});\n\nconsole.log(\n formatter\n .format(\n new Date('2022-11-28T10:26:00.949Z')\n )\n); .as-console-wrapper { min-height: 100%!important; top: 0; }"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20459903/"
] |
74,599,271
|
<p>Question: How to uniquely identify a record in AS400 database</p>
<p>Detailed Question:</p>
<p>I have AS400 database and some tables within it.
Tables don't have primary key / unique key / composite key defined.</p>
<p>Like oracle has concept of ROWID, in same way do we have something for AS400 database.
or can we create something like ROWID?</p>
|
[
{
"answer_id": 74599341,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": -1,
"selected": false,
"text": "moment(\"2022-11-28T10:26:00.949Z\").format(\"DD MMM , yyyy :h:mm:ss A\")\n"
},
{
"answer_id": 74599622,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 3,
"selected": true,
"text": "DateTimeFormat const formatter = new Intl.DateTimeFormat('en-GB', {\n year: 'numeric', month: '2-digit', day: '2-digit',\n hour: 'numeric', minute: '2-digit', second: '2-digit',\n hourCycle: 'h12',\n});\n\nconsole.log(\n formatter\n .format(\n new Date('2022-11-28T10:26:00.949Z')\n )\n); .as-console-wrapper { min-height: 100%!important; top: 0; }"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622382/"
] |
74,599,304
|
<p>After upgrading from .net core 6 to 7 and rolling forward all the libraries, after scaffolding the database(we use db first) a lot of the generated properties no longer have setters. These were present before and heavily used. I was looking for options on the scaffold command to include setters or any alternative method to make sure this happens</p>
<p>EF Core 6</p>
<pre><code>public virtual ICollection<AccountsPurchaseInvoiceLines> AccountsPurchaseInvoiceLines { get; set; } = new List<AccountsPurchaseInvoiceLines>();
</code></pre>
<p>EF Core 7</p>
<pre><code>public virtual ICollection<AccountsPurchaseInvoiceLines> AccountsPurchaseInvoiceLines { get; } = new List<AccountsPurchaseInvoiceLines>();
</code></pre>
<p>The lack of the setter on all the entities is the problem. I can go and add manually to get the project building again but I can't find a way to make sure next time I generate the entities the setters remain.</p>
<p>Thanks</p>
|
[
{
"answer_id": 74599341,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": -1,
"selected": false,
"text": "moment(\"2022-11-28T10:26:00.949Z\").format(\"DD MMM , yyyy :h:mm:ss A\")\n"
},
{
"answer_id": 74599622,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 3,
"selected": true,
"text": "DateTimeFormat const formatter = new Intl.DateTimeFormat('en-GB', {\n year: 'numeric', month: '2-digit', day: '2-digit',\n hour: 'numeric', minute: '2-digit', second: '2-digit',\n hourCycle: 'h12',\n});\n\nconsole.log(\n formatter\n .format(\n new Date('2022-11-28T10:26:00.949Z')\n )\n); .as-console-wrapper { min-height: 100%!important; top: 0; }"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2417808/"
] |
74,599,313
|
<p>I know TailwindCSS have class <code>group</code> to use but that is only use for change styles of child element when the parent element activate some event, but I want it in vise versa.</p>
<pre class="lang-html prettyprint-override"><code><div class="parent"> <!-- border color should be red when child is focused -->
<img class="icon">
<input class="child" type="text">
</div>
</code></pre>
<p>And I don't want to re-write css classes. Just use TailwindCSS.</p>
|
[
{
"answer_id": 74599490,
"author": "JadBlackstone",
"author_id": 15181384,
"author_profile": "https://Stackoverflow.com/users/15181384",
"pm_score": 0,
"selected": false,
"text": "<input class=\"child\" type=\"text\" onclick=\"focusFunction()\">\n\n<script>\nfunction focusFunction() {\n document.getElementByClass(\"parent\").classList.add(\"focusclass\");\n}\n</script>\n focusFuncition parent focusclass getElementByID parent"
},
{
"answer_id": 74599623,
"author": "Ihar Aliakseyenka",
"author_id": 14305076,
"author_profile": "https://Stackoverflow.com/users/14305076",
"pm_score": 3,
"selected": true,
"text": "<!-- border will be red when input focuesd -->\n<div class=\"focus-within:border-red-500 border\">\n <img class=\"icon\">\n <input class=\"\" type=\"text\">\n</div>\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5513282/"
] |
74,599,327
|
<p>Suppose I have a simple string that I want to parse into array of string:</p>
<p><code>"add (multiply (add 1 2) (add 3 4)) (add 5 6)"</code></p>
<p>How do I parse it into 3 strings (based on outer parentheses):</p>
<pre><code>add
(multiply (add 1 2) (add 3 4))
(add 5 6)
</code></pre>
<p>With my OOP mind, I think I need a for loop index and if else statement to do this.</p>
<p>I have tried parse it with string split, however I got:</p>
<pre><code>command
(multiply
1
(add
3
2))
(add
3
4)
</code></pre>
<p>which is not what I expected</p>
|
[
{
"answer_id": 74599772,
"author": "leetwinski",
"author_id": 5400548,
"author_profile": "https://Stackoverflow.com/users/5400548",
"pm_score": 1,
"selected": false,
"text": "(def s \"add (multiply (add 1 2) (add 3 4)) (add 5 6)\")\n\n(map str (clojure.edn/read-string (str \"(\" s \")\")))\n\n;;=> (\"add\" \"(multiply (add 1 2) (add 3 4))\" \"(add 5 6)\")\n"
},
{
"answer_id": 74599808,
"author": "Rulle",
"author_id": 1008794,
"author_profile": "https://Stackoverflow.com/users/1008794",
"pm_score": 1,
"selected": true,
"text": "LispReader (import '[clojure.lang LispReader LineNumberingPushbackReader])\n(import '[java.io PushbackReader StringReader])\n\n(defn could-read? [pr]\n (try\n (LispReader/read pr nil)\n true\n (catch RuntimeException e false)))\n\n(defn paren-split2 [s]\n (let [sr (StringReader. s)\n pr (LineNumberingPushbackReader. sr)\n inds (loop [result [0]]\n (if (could-read? pr)\n (recur (conj result (.getColumnNumber pr)))\n result))\n len (count s)\n bounds (partition 2 1 inds)]\n (for [[l u] bounds\n :let [result (clojure.string/trim (subs s l (min len u)))] :when (seq result)]\n result)))\n\n(paren-split2 \"add ( multiply ( add 1 2) (add 3 4)) (add 5 6 )\")\n;; => (\"add\" \"( multiply ( add 1 2) (add 3 4))\" \"(add 5 6 )\")\n (def conj-non-empty ((remove empty?) conj))\n\n(defn acc-paren-split [{:keys [dst depth current] :as state} c]\n (case c\n \\( (-> state\n (update :depth inc)\n (update :current str c))\n \\) (if (= 1 depth)\n {:depth 0 :dst (conj-non-empty dst (str current c)) :current \"\"}\n (-> state\n (update :depth dec)\n (update :current str c)))\n \\space (if (zero? depth)\n {:depth 0 :dst (conj-non-empty dst current) :current \"\"}\n (update state :current str c))\n (update state :current str c)))\n\n(defn paren-split [s]\n (:dst (reduce acc-paren-split\n {:dst []\n :depth 0\n :current \"\"}\n s)))\n\n(paren-split \"add ( multiply ( add 1 2) (add 3 4)) (add 5 6 )\")\n;; => [\"add\" \"( multiply ( add 1 2) (add 3 4))\" \"(add 5 6 )\"]\n"
},
{
"answer_id": 74606312,
"author": "Gwang-Jin Kim",
"author_id": 9690090,
"author_profile": "https://Stackoverflow.com/users/9690090",
"pm_score": 0,
"selected": false,
"text": "read-string str clojure.string/trim (defn pre-parse [s]\n (loop [s s\n acc []]\n (if (zero? (count s))\n acc\n (let* [chunk (read-string s)\n s_ (str chunk)\n rest-s (clojure.string/trim (subs s (count s_)))]\n (recur rest-s (conj acc s_))))))\n recure loop loop (def x \"add (multiply (add 1 2) (add 3 4)) (add 5 6)\")\n(pre-parse x)\n;; => [\"add\" \"(multiply (add 1 2) (add 3 4))\" \"(add 5 6)\"]\n\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11817809/"
] |
74,599,360
|
<p>I am facing these error messages: `Uncaught TypeError: candidate.toLowerCase is not a function. I am using AutoComplete API in the material UI, but when I search in the input field, it will bring me to blank page.</p>
<p><a href="https://i.stack.imgur.com/Yv3ZU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yv3ZU.png" alt="img" /></a></p>
<p>These are my existing code:</p>
<pre class="lang-html prettyprint-override"><code>getOptionLabel={option => {
return (
<>
{option.name}
<span className="**">{option.dob}</span>
</>
);
}}
</code></pre>
<p>What I've tried, but didn't work (I followed this StackOverflow <a href="https://stackoverflow.com/questions/66813809/candidate-tolowercase-is-not-a-function-in-candidate-tolowercase-candida">candidate.toLowerCase is not a function. (In 'candidate.toLowerCase()', 'candidate.toLowerCase' is undefined) Material UI</a> guideline):</p>
<pre class="lang-html prettyprint-override"><code>getOptionLabel={option => {
return (
<>
{option.name.toString()}
<span className="**">{option.dob.toString()}</span>
</>
);
}}
</code></pre>
<p>Hope some one can guide me on how to solve this problem. Thanks.</p>
<p><strong>Option data:</strong></p>
<p><a href="https://i.stack.imgur.com/3aMy9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3aMy9.png" alt="311" /></a></p>
|
[
{
"answer_id": 74599424,
"author": "Bas van der Linden",
"author_id": 11119684,
"author_profile": "https://Stackoverflow.com/users/11119684",
"pm_score": 0,
"selected": false,
"text": "getOptionLabel={option => {\nreturn (\n <>\n {option.name.toString()}\n <span className=\"**\">{option.dob.toString()}</span>\n </>\n);\n}}\n getOptionLabel={option => {\n return option.name.toString();\n}}\n"
},
{
"answer_id": 74599540,
"author": "Nick Parsons",
"author_id": 5648954,
"author_profile": "https://Stackoverflow.com/users/5648954",
"pm_score": 2,
"selected": true,
"text": "getOptionLabel getOptionLabel renderOption <Autocomplete\n getOptionLabel={option => `${option.name} ${option.dob}`}\n renderOption={(props, option) => <>\n {option.name}\n <span className=\"**\">{option.dob}</span>\n </>\n }\n ...\n/>\n renderOption option <Autocomplete\n getOptionLabel={option => `${option.name} ${option.dob}`}\n renderOption={option => <>\n {option.name}\n <span className=\"**\">{option.dob}</span>\n </>\n }\n ...\n/>\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14562541/"
] |
74,599,371
|
<p>I want to need multiple array combaine in one array</p>
<p>I have array</p>
<pre><code>array(
0=> test 1
)
array(
0=> test 2
)
array(
0=> test 3
)
</code></pre>
<p>I need expected output</p>
<pre><code>`array(
0=>Test1
1=>Test2
2=>test3
)`
</code></pre>
|
[
{
"answer_id": 74599480,
"author": "Malik",
"author_id": 10804565,
"author_profile": "https://Stackoverflow.com/users/10804565",
"pm_score": 2,
"selected": false,
"text": "array_merge() array_merge(array ...$arrays): array\n $a1=array(\"red\",\"green\");\n$a2=array(\"blue\",\"yellow\");\nprint_r(array_merge($a1,$a2));\n Array ( [0] => red [1] => green [2] => blue [3] => yellow )\n"
},
{
"answer_id": 74599916,
"author": "Piyush Sapariya",
"author_id": 5527729,
"author_profile": "https://Stackoverflow.com/users/5527729",
"pm_score": 2,
"selected": false,
"text": "$a = array('test_1');\n$b = array('test_2');\n$c = array('test_3');\nprint_r(array_merge($a,$b,$c));\n Array ( [0] => test_1 [1] => test_2 [2] => test_3 )"
},
{
"answer_id": 74600136,
"author": "Ajju Bhai",
"author_id": 20580686,
"author_profile": "https://Stackoverflow.com/users/20580686",
"pm_score": 2,
"selected": false,
"text": "$array1 = [0 => \"Test 1\"]; $array2 = [0 => \"Test 2\"]; $array3 = [0 => \"Test 3\"]; print_r(array_merge($array1,$array2,$array3));"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20253641/"
] |
74,599,412
|
<p>I've some processing instructions like the one below at the top of my XML file:</p>
<pre><code><?ID Object="AUTO_REPORT_OBJECT" Version="1.0"?>
</code></pre>
<p>I would like to read Object and Version attributes value using Go libraries. I'm using Go 1.19.</p>
<p>My XML file is like this:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<?ID Object="AUTO_REPORT_OBJECT" Version="1.0"?>
<?xml-stylesheet type="text/xsl" href="../XML/ProdRep.xsl"?>
<!DOCTYPE Auto_Report SYSTEM "../XML/ProdRep.dtd" [
<!ELEMENT Auto_Report (Production_Report+)>
]>
<Auto_Report>
<Production_Report Type="AUTO">
... more tags
</Production_Report>
</Auto_Report>
<?End?>
</code></pre>
|
[
{
"answer_id": 74614201,
"author": "Hermann12",
"author_id": 12621346,
"author_profile": "https://Stackoverflow.com/users/12621346",
"pm_score": 0,
"selected": false,
"text": "Go import xml.etree.ElementTree as ET\n\nfor event, elem in ET.iterparse('your.xml', events=(\"pi\")):\n if event == \"pi\":\n print(ET.tostring(elem))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4117563/"
] |
74,599,413
|
<p>i am making a chess game using js html and css what i am trying to do is i have given every pawn an onclick function which gets id of pawns parent div/block and based on that it highlights the blocks where the pawn can go but when i get the id of parent div it gives me id of another div idk why can some one help me</p>
<p>my code</p>
<p>html</p>
<pre><code><div id="7b" class="whitesmoke"><button class="Btns r7"></button></div>
<div id="7b"><button class="Btns r7"></button><div id="mp1" class="blp"></div></div>
<div id="7b" class="whitesmoke"><button class="Btns r7"></button></div>
<div id="7b"><button class="Btns r7"></button><div id="mp2" class="blp"></div></div>
<div id="7b" class="whitesmoke"><button class="Btns r7"></button></div>
<div id="7b"><button class="Btns r7"></button><div id="mp3" class="blp"></div></div>
<div id="7b" class="whitesmoke"><button class="Btns r7"></button></div>
<div id="7b"><button class="Btns r7"></button><div id="mp4" class="blp"></div></div>
<div id="8b"><button class="Btns r8"></button><div id="mp5" class="blp"></div></div>
<div id="8b" class="whitesmoke"><button class="Btns r8"></button></div>
<div id="8b"><button class="Btns r8"></button><div id="mp6" class="blp"></div></div>
<div id="8b" class="whitesmoke"><button class="Btns r8"></button></div>
<div id="8b"><button class="Btns r8"></button><div id="mp7" class="blp"></div></div>
<div id="8b" class="whitesmoke"><button class="Btns r8"></button></div>
<div id="8b"><button class="Btns r8"></button><div id="mp8" class="blp"></div></div>
<div id="8b" class="whitesmoke"><button class="Btns r8"></button></div>
</code></pre>
<p>js</p>
<pre><code>for (let i=0; i<8; i++) {
let blps = document.getElementsByClassName("blp")[i]
let whps = document.getElementsByClassName("whp")[i]
whps.onclick = function() {moveblp(i)};
blps.onclick = function() {movewhp(i)};
}
function movewhp(a) {
let pawn = document.getElementsByClassName("whp")[a]
let parent = Number.parseInt(pawn.parentElement.id)
console.log(parent)
}
</code></pre>
<p>b stands for block and r stands for row i have 8x8 rows so total 64 parent divs</p>
|
[
{
"answer_id": 74614201,
"author": "Hermann12",
"author_id": 12621346,
"author_profile": "https://Stackoverflow.com/users/12621346",
"pm_score": 0,
"selected": false,
"text": "Go import xml.etree.ElementTree as ET\n\nfor event, elem in ET.iterparse('your.xml', events=(\"pi\")):\n if event == \"pi\":\n print(ET.tostring(elem))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20545624/"
] |
74,599,414
|
<p>I have a landing file which is in pure HTML. (<code>landing.html</code>)
I want the main URL of the website to be this file and the rest of the URLs to go in the React app.</p>
<p>For example:</p>
<pre><code>example.com -> landing.html
example.com/app -> react app
example.com/login -> react app
</code></pre>
<p>As I said, I want the main URL to read the <code>landing.html</code>.
But the rest of the app should read the build version of React.</p>
<p><strong>If it's possible</strong> i want it to be a part of the React app and not adding it directly in build folder. After running build it should be automaticly in build folder so basicly kinda implicitly to be a part of react app.</p>
<p>One more thing I dont want to convert it to jsx. </p>
<p>How can I implement this ?</p>
|
[
{
"answer_id": 74614201,
"author": "Hermann12",
"author_id": 12621346,
"author_profile": "https://Stackoverflow.com/users/12621346",
"pm_score": 0,
"selected": false,
"text": "Go import xml.etree.ElementTree as ET\n\nfor event, elem in ET.iterparse('your.xml', events=(\"pi\")):\n if event == \"pi\":\n print(ET.tostring(elem))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13825398/"
] |
74,599,419
|
<p><strong>Can anyone let me know how can I transform this input json I have tried with below transformation but didn't worked.</strong></p>
<p>I have tried to used filter function and groupBy function, but for Multiple output it is failing the testCase.</p>
<p>tried with this method
`</p>
<pre><code>%dw 2.0
output application/json
---
payload.Bd map (val,index) ->{
"d23": val,
"lt":(payload.output2 filter(payload.Bd contains val) map(Value) ->
{
Val34: Value.PId
}
)
}
</code></pre>
<p><code>input -</code></p>
<pre><code>[
{
"Val34": "968",
"d23": "Y1"
},
{
"Val34": "958",
"d23": "Y2"
},
{
"Val34": "951",
"d23": "Y2"
}
]
</code></pre>
<p><code>expected output - </code></p>
<pre><code>[
{
"d23": "Y1",
"lt": [
{
"Val34": "968"
}
]
},
{
"d23": "Y2",
"lt": [
{
"Val34": "958"
},
{
"Val34": "951"
}
]
}
]
</code></pre>
<p>`</p>
|
[
{
"answer_id": 74599544,
"author": "StackOverflowed",
"author_id": 7255897,
"author_profile": "https://Stackoverflow.com/users/7255897",
"pm_score": 2,
"selected": false,
"text": "%dw 2.0\noutput application/json\n---\npayload groupBy ((item, index) -> item.d23) pluck {\n d23: $[0].d23,\n lt: ($.Val34 map (l,indOfl) -> {Val34: l})\n}\n"
},
{
"answer_id": 74601359,
"author": "Karthik",
"author_id": 12870513,
"author_profile": "https://Stackoverflow.com/users/12870513",
"pm_score": 0,
"selected": false,
"text": "index[1] %dw 2.0\noutput application/json\n---\n(payload groupBy ((item, index) -> item[1])) pluck $ map{\n ($[0][&1]),\n \"lt\": ($ map(it,in)->(it[&0]))\n}\n [\n {\n \"Val34\": \"968\",\n \"d23\": \"Y1\"\n },\n {\n \"Val34\": \"998\",\n \"d23\": \"Y3\"\n },\n\n {\n \"Val34\": \"988\",\n \"d23\": \"Y1\"\n },\n {\n \n \"Val34\": \"958\",\n \"d23\": \"Y2\"\n },\n {\n \n \"Val34\": \"951\",\n \"d23\": \"Y2\"\n }\n]\n [\n {\n \"d23\": \"Y1\",\n \"lt\": [\n {\n \"Val34\": \"968\"\n },\n {\n \"Val34\": \"988\"\n }\n ]\n },\n {\n \"d23\": \"Y3\",\n \"lt\": [\n {\n \"Val34\": \"998\"\n }\n ]\n },\n {\n \"d23\": \"Y2\",\n \"lt\": [\n {\n \"Val34\": \"958\"\n },\n {\n \"Val34\": \"951\"\n }\n ]\n }\n]\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9169753/"
] |
74,599,468
|
<p>In my ec2 instance I am able to run <code>pm2</code> command.</p>
<p><a href="https://i.stack.imgur.com/c5r7l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c5r7l.png" alt="enter image description here" /></a></p>
<p>But while deploying application through code deployment I get this error.</p>
<p><a href="https://i.stack.imgur.com/OYiWq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OYiWq.png" alt="enter image description here" /></a></p>
<blockquote>
<p>LifecycleEvent - ApplicationStop
Script - application_stop.sh
[stdout]Stopping any existing node servers
[stderr]/opt/codedeploy-agent/deployment-root/878477e5-6ffb-4175-8e9e-97045ea99290/d-HVRQ58IBL/deployment-archive/application_stop.sh: line 4: pm2: command not found</p>
</blockquote>
<p>My application_stop.sh code.</p>
<pre><code>#!/bin/bash
#Stopping existing node servers
echo "Stopping any existing node servers"
pm2 stop main
</code></pre>
<p>As per @ranjanistic I checked my pm2 path using <code>which pm2</code> command and it returned</p>
<p><code>~/.nvm/versions/node/v16.15.1/bin/pm2</code></p>
<p>After that I update my application_stop.sh using this below command</p>
<p><code>~/.nvm/versions/node/v16.15.1/bin/pm2 start main</code></p>
<p>Also added symbolic link like this to npm, node and pm2.</p>
<p>///this process worked. Thanks @ranjanistic</p>
<pre><code>which npm
which node
which pm2
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/npm
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/node
sudo ln -s /home/ec2-user/.nvm/versions/node/v16.15.1/bin/pm2
</code></pre>
<p>Still not working</p>
|
[
{
"answer_id": 74599544,
"author": "StackOverflowed",
"author_id": 7255897,
"author_profile": "https://Stackoverflow.com/users/7255897",
"pm_score": 2,
"selected": false,
"text": "%dw 2.0\noutput application/json\n---\npayload groupBy ((item, index) -> item.d23) pluck {\n d23: $[0].d23,\n lt: ($.Val34 map (l,indOfl) -> {Val34: l})\n}\n"
},
{
"answer_id": 74601359,
"author": "Karthik",
"author_id": 12870513,
"author_profile": "https://Stackoverflow.com/users/12870513",
"pm_score": 0,
"selected": false,
"text": "index[1] %dw 2.0\noutput application/json\n---\n(payload groupBy ((item, index) -> item[1])) pluck $ map{\n ($[0][&1]),\n \"lt\": ($ map(it,in)->(it[&0]))\n}\n [\n {\n \"Val34\": \"968\",\n \"d23\": \"Y1\"\n },\n {\n \"Val34\": \"998\",\n \"d23\": \"Y3\"\n },\n\n {\n \"Val34\": \"988\",\n \"d23\": \"Y1\"\n },\n {\n \n \"Val34\": \"958\",\n \"d23\": \"Y2\"\n },\n {\n \n \"Val34\": \"951\",\n \"d23\": \"Y2\"\n }\n]\n [\n {\n \"d23\": \"Y1\",\n \"lt\": [\n {\n \"Val34\": \"968\"\n },\n {\n \"Val34\": \"988\"\n }\n ]\n },\n {\n \"d23\": \"Y3\",\n \"lt\": [\n {\n \"Val34\": \"998\"\n }\n ]\n },\n {\n \"d23\": \"Y2\",\n \"lt\": [\n {\n \"Val34\": \"958\"\n },\n {\n \"Val34\": \"951\"\n }\n ]\n }\n]\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1682525/"
] |
74,599,482
|
<p>I have a 2D list from which I am trying to extract the unique rows example:</p>
<pre><code>list = [['16', 'jun', 'jun', '18'],
['jun', '16', 'jun', '18'],
['aug', '16', 'jun', '18'],
['aug', '16', 'jun', '18'],
['sep', '17', 'mar', '18']]
</code></pre>
<p>should return</p>
<pre><code>desired_list = [['16', 'jun', 'jun', '18'],
['aug', '16', 'jun', '18'],
['sep', '17', 'mar', '18']]
</code></pre>
<p>explanation:</p>
<ul>
<li>So, if we compare row 1 with row 2 in list we see the items inside the two rows is same hence, I will take one of the row and store in desired_list</li>
<li>row 3 and 4 in list are exactly same therefore, I'll store any one row in desired_list.</li>
<li>row 5 is totally unique therefore, I'll add in desired_list.</li>
</ul>
<p>My only target is to remove duplicate value rows(even if items inside rows have different order) and only store the unique rows.</p>
<pre><code>print('LP:',lp, "\n")
l=[]
for i in range(len(lp)):
for j in range(i+1, len(lp)):
k=i
print(set(lp[j]) == set(lp[k]), lp[j] not in l, lp[j], lp[k],l)
if set(lp[j]) != set(lp[k]):
if lp[j] not in l:
l.append(lp[j])
print('\n', l)
</code></pre>
<p>I am only half successful in achieving this. Below I am attaching the screenshot of the output so far:
<a href="https://i.stack.imgur.com/1wqKo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1wqKo.png" alt="enter image description here" /></a></p>
<pre><code></code></pre>
|
[
{
"answer_id": 74599544,
"author": "StackOverflowed",
"author_id": 7255897,
"author_profile": "https://Stackoverflow.com/users/7255897",
"pm_score": 2,
"selected": false,
"text": "%dw 2.0\noutput application/json\n---\npayload groupBy ((item, index) -> item.d23) pluck {\n d23: $[0].d23,\n lt: ($.Val34 map (l,indOfl) -> {Val34: l})\n}\n"
},
{
"answer_id": 74601359,
"author": "Karthik",
"author_id": 12870513,
"author_profile": "https://Stackoverflow.com/users/12870513",
"pm_score": 0,
"selected": false,
"text": "index[1] %dw 2.0\noutput application/json\n---\n(payload groupBy ((item, index) -> item[1])) pluck $ map{\n ($[0][&1]),\n \"lt\": ($ map(it,in)->(it[&0]))\n}\n [\n {\n \"Val34\": \"968\",\n \"d23\": \"Y1\"\n },\n {\n \"Val34\": \"998\",\n \"d23\": \"Y3\"\n },\n\n {\n \"Val34\": \"988\",\n \"d23\": \"Y1\"\n },\n {\n \n \"Val34\": \"958\",\n \"d23\": \"Y2\"\n },\n {\n \n \"Val34\": \"951\",\n \"d23\": \"Y2\"\n }\n]\n [\n {\n \"d23\": \"Y1\",\n \"lt\": [\n {\n \"Val34\": \"968\"\n },\n {\n \"Val34\": \"988\"\n }\n ]\n },\n {\n \"d23\": \"Y3\",\n \"lt\": [\n {\n \"Val34\": \"998\"\n }\n ]\n },\n {\n \"d23\": \"Y2\",\n \"lt\": [\n {\n \"Val34\": \"958\"\n },\n {\n \"Val34\": \"951\"\n }\n ]\n }\n]\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2814290/"
] |
74,599,505
|
<p>I'm trying to have my Python code write everything it does to a log, with a timestamp. But it doesn't seem to work.</p>
<p>this is my current code:</p>
<pre><code>filePath= Path('.')
time=datetime.datetime.now()
bot_log = ["","Set up the file path thingy"]
with open ('bot.log', 'a') as f:
f.write('\n'.join(bot_log)%
datetime.datetime.now().strftime("%d-%b-%Y (%H:%M:%S.%f)"))
print(bot_log[0])
</code></pre>
<p>but when I run it it says:</p>
<pre><code>Traceback (most recent call last):
File "c:\Users\Name\Yuna-Discord-Bot\Yuna Discord Bot.py", line 15, in <module>
f.write('\n'.join(bot_log)%
TypeError: not all arguments converted during string formatting
</code></pre>
<p>I have tried multiple things to fix it, and this is the latest one. is there something I'm doing wrong or missing? I also want the time to be in front of the log message, but I don't think it would do that (if it worked).</p>
|
[
{
"answer_id": 74599572,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 3,
"selected": true,
"text": "filePath= Path('.')\ntime=datetime.datetime.now()\nbot_log = \"%s Set up the file path thingy\\n\"\nwith open ('bot.log', 'a') as f:\n f.write(bot_log % datetime.datetime.now().strftime(\"%d-%b-%Y (%H:%M:%S.%f)\"))\n print(bot_log)\n"
},
{
"answer_id": 74599678,
"author": "import random",
"author_id": 2280890,
"author_profile": "https://Stackoverflow.com/users/2280890",
"pm_score": 1,
"selected": false,
"text": "writelines filePath= Path('.')\ntime=datetime.datetime.now()\nbot_log = [\"\",\"Set up the file path thingy\"]\nwith open ('bot.log', 'a') as f:\n bot_log.append(datetime.datetime.now().strftime(\"%d-%b-%Y (%H:%M:%S.%f)\"))\n f.writelines('\\n'.join(bot_log))\n print(bot_log[0])\n import datetime\nfrom pathlib import Path\n\nfilePath = Path('.')\n\nwith open('bot.log', 'a') as f:\n time = datetime.datetime.now()\n msg = \"Set up the file path thingy\"\n f.write(f\"\"\"{time.strftime(\"%d-%b-%Y (%H:%M:%S.%f)\")} {msg}\\n\"\"\")\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17936283/"
] |
74,599,519
|
<p>I have the following data in Excel, which I'm importing into PowerBI.</p>
<p><a href="https://i.stack.imgur.com/p3O6y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p3O6y.png" alt="Original Spreadshet" /></a></p>
<p>In the short description, there is a code (immediately after IDN) in each row - I need to extract just the number. THe number is not always the same length and it may be followed by a space, or another character (a - in the screenshot).</p>
<p>In excel I can use: =SEARCH("IDN",A2) to find the start of the IDN text - FirstDetectIDN</p>
<p>I can then find the next space (NextSpace) using find again: =FIND(" ",A2,B2)</p>
<p>I use the same to find the NextSpace2 - so I now have the starting and end position of the spaces surrounding the number I want to extract.</p>
<p>But that gives me the extra characters on the end of the number ("-EOL" above in the screenshot) that I don't want.</p>
<p>Is there any way in PowerBI that I can replicate all of that in one new calculated column AND also only extract the number part (so for the second line, I would only want 784729 in the new calculated field).</p>
<p>Thanks for any suggestions,</p>
<p>Mark</p>
|
[
{
"answer_id": 74599677,
"author": "David Bacci",
"author_id": 18345037,
"author_profile": "https://Stackoverflow.com/users/18345037",
"pm_score": 2,
"selected": false,
"text": "let \na = Text.AfterDelimiter([Column1],\"IDN\"),\nb = List.Transform({a}, each Text.Select(_, {\"0\"..\"9\"}))\nin b{0}\n let\n Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(\"i45WCk4tUzBV8HTxU7A0MbcwVtBVcCxNyfTITM9QitWJVvJNLUksSszNL80rASsytzAxN7LUdfX3AaoMT03JTU1Rio0FAA==\", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),\n #\"Changed Type\" = Table.TransformColumnTypes(Source,{{\"Column1\", type text}}),\n #\"Added Custom\" = Table.AddColumn(#\"Changed Type\", \"Custom\", each let \n a = Text.AfterDelimiter([Column1],\"IDN\"),\n b = List.Transform({a}, each Text.Select(_, {\"0\"..\"9\"}))\n in b{0})\nin\n #\"Added Custom\"\n"
},
{
"answer_id": 74601066,
"author": "Ron Rosenfeld",
"author_id": 2872922,
"author_profile": "https://Stackoverflow.com/users/2872922",
"pm_score": 3,
"selected": true,
"text": "IDN type text IDN type number Int64.Type let\n\n//Change next line to reflect actual data source\n Source = Excel.CurrentWorkbook(){[Name=\"Table7\"]}[Content],\n\n//Set data type\n #\"Changed Type\" = Table.TransformColumnTypes(Source,{{\"Short description\", type text}}),\n\n//Extract the first set of digits after \"IDN\"\n #\"Added Custom\" = Table.AddColumn(#\"Changed Type\", \"IDN\", each \n Text.Trim(\n Splitter.SplitTextByCharacterTransition({\"0\"..\"9\"}, (c) => not List.Contains({\"0\"..\"9\"}, c))\n (Text.AfterDelimiter([Short description],\"IDN\")){0}), type text)\nin\n #\"Added Custom\"\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6812673/"
] |
74,599,533
|
<p>I have a view with the list of articles the user add to basket.</p>
<p>In each article i have an increment/decrement button to edit the quantity.
The increment/decrement buttons are working because it's adding in my array a new Object every time my user change the quantity</p>
<p>For now, i just have a "+" and "-" button, but i would like to see the number of the quantity</p>
<p>What i was thinking about :</p>
<ul>
<li>get all the articles list and count the duplicate in a useEffect (every time the articles list is changing)</li>
<li>set the article id and quantity with useState object</li>
</ul>
<p>What is the best way to count individual quantity of each articles ?</p>
<p>here my component with the articles map and increment/decrement buttons</p>
<pre><code> import React from 'react';
import { Table } from 'react-bootstrap';
import { useFieldArray } from 'react-hook-form';
export const ListArticle = ({ watch, control }) => {
const list = watch('Articles');
//listWithoutDuplicates is because i just want to see once my articles even if the quantity is more than 1
const listWithoutDuplicates = list?.filter(
(ele, ind) => ind === list?.findIndex((elem) => elem.name === ele.name)
);
const { append, remove } = useFieldArray({
control,
name: 'Articles',
});
const increment = (oneArticle) => {
append(oneArticle);
};
const decrement = (oneArticle) => {
remove(oneArticle);
};
return (
<>
<Table responsive>
<thead>
<tr>
<th> Name </th>
<th> Color</th>
<th> Quantity </th>
</tr>
</thead>
<tbody>
{listWithoutDuplicates?.map((oneArticle, index) => {
return (
<tr key={index}>
<td>
<span>{oneArticle?.name}</span>
</td>
<td>
<span>{oneArticle?.color}</span>
</td>
<td>
<button type="button" onClick={() => decrement(oneArticle)}>
-
</button>
<p> HERE MY QUANTITY </p>
<button type="button" onClick={() => increment(oneArticle)}>
+
</button>
</td>
</tr>
);
})}
</tbody>
</Table>
</>
);
};
</code></pre>
|
[
{
"answer_id": 74599701,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 2,
"selected": true,
"text": "const { append, remove, update } = useFieldArray({\n control,\n name: 'Articles',\n}); \n\nconst increment = (index) => {\n const oneArticle = {...list[index]};\n oneArticle.quantity += 1;\n update(index, oneArticle);\n};\n \nconst decrement = (index) => {\n const oneArticle = {...list[index]};\n // It's the last quantity of the article so we should remove it from the list.\n if(oneArticle.quantity === 1) {\n remove(index);\n // It's not the last quantity of the article so we should decrease the quantity.\n } else {\n oneArticle.quantity -= 1;\n update(index, oneArticle);\n }\n};\n <tbody>\n {list?.map((oneArticle, index) => {\n return (\n <tr key={index}>\n <td>\n <span>{oneArticle?.name}</span>\n </td>\n <td>\n <span>{oneArticle?.color}</span>\n </td>\n <td>\n <span>{oneArticle?.quantity}</span>\n </td>\n <td>\n <button type=\"button\" onClick={() => decrement(index)}>\n -\n </button>\n <button type=\"button\" onClick={() => increment(index)}>\n +\n </button>\n </td> \n </tr>\n )\n })}\n</tbody> \n"
},
{
"answer_id": 74599731,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": -1,
"selected": false,
"text": " import React,{useState} from 'react';\n import { Table } from 'react-bootstrap';\n import { useFieldArray } from 'react-hook-form';\n \n export const ListArticle = ({ watch, control }) => {\n const [list, setList] = useState(watch('Articles'));\n \n //listWithoutDuplicates is because i just want to see once my articles even if the quantity is more than 1\n //const listWithoutDuplicates = list?.filter(\n // (ele, ind) => ind === list?.findIndex((elem) => elem.name === ele.name)\n // );\n \n const { append, remove } = useFieldArray({\n control,\n name: 'Articles',\n });\n \n const increment = (index) => {\n //append(oneArticle);\n let newList =list;\n newList[index].quantity =(newList[index].quantity || 0) +1\n setList(newList)\n };\n \n const decrement = (index) => {\n //remove(oneArticle);\n let newList =list;\n newList[index].quantity =(newList[index].quantity || 0) -1\n setList(newList)\n };\n \n \n return (\n <>\n <Table responsive>\n <thead>\n <tr>\n <th> Name </th>\n <th> Color</th>\n <th> Quantity </th>\n </tr>\n </thead>\n <tbody>\n {list?.map((oneArticle, index) => {\n return (\n <tr key={index}>\n <td>\n <span>{oneArticle?.name}</span>\n </td>\n <td>\n <span>{oneArticle?.color}</span>\n </td>\n <td>\n <button type=\"button\" onClick={() => decrement(index)}>\n -\n </button>\n <p>{oneArticle.quantity || 0}</p>\n <button type=\"button\" onClick={() => increment(index)}>\n +\n </button>\n \n </td> \n </tr>\n );\n })}\n </tbody> \n </Table>\n </>\n );\n};\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19389219/"
] |
74,599,600
|
<p>I have a <code>Products</code> table where prices of products are updated every day.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>eff_date</th>
<th>product_id</th>
<th>price</th>
</tr>
</thead>
<tbody>
<tr>
<td>2022-11-25</td>
<td>P1</td>
<td>150</td>
</tr>
<tr>
<td>2022-11-25</td>
<td>P2</td>
<td>75.8</td>
</tr>
<tr>
<td>2022-11-25</td>
<td>P3</td>
<td>2.9</td>
</tr>
<tr>
<td>2022-11-26</td>
<td>P1</td>
<td>180.5</td>
</tr>
<tr>
<td>2022-11-26</td>
<td>P2</td>
<td>77</td>
</tr>
<tr>
<td>2022-11-26</td>
<td>P4</td>
<td>13.92</td>
</tr>
</tbody>
</table>
</div>
<p>But sometimes not all products will have data for each date (like how p3 do not have data for 26th and p4 do not have data for 25th).</p>
<p>Consider today's date is 26th then I want to compare today's price with yesterday's price and if difference is > 10% (price increased by 10% or more )then I want output like below:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>eff_date</th>
<th>product_id</th>
<th>todays_price</th>
<th>yesterdays_price</th>
</tr>
</thead>
<tbody>
<tr>
<td>2022-11-26</td>
<td>P1</td>
<td>180.5</td>
<td>150</td>
</tr>
</tbody>
</table>
</div>
|
[
{
"answer_id": 74599701,
"author": "Amirhossein",
"author_id": 11342834,
"author_profile": "https://Stackoverflow.com/users/11342834",
"pm_score": 2,
"selected": true,
"text": "const { append, remove, update } = useFieldArray({\n control,\n name: 'Articles',\n}); \n\nconst increment = (index) => {\n const oneArticle = {...list[index]};\n oneArticle.quantity += 1;\n update(index, oneArticle);\n};\n \nconst decrement = (index) => {\n const oneArticle = {...list[index]};\n // It's the last quantity of the article so we should remove it from the list.\n if(oneArticle.quantity === 1) {\n remove(index);\n // It's not the last quantity of the article so we should decrease the quantity.\n } else {\n oneArticle.quantity -= 1;\n update(index, oneArticle);\n }\n};\n <tbody>\n {list?.map((oneArticle, index) => {\n return (\n <tr key={index}>\n <td>\n <span>{oneArticle?.name}</span>\n </td>\n <td>\n <span>{oneArticle?.color}</span>\n </td>\n <td>\n <span>{oneArticle?.quantity}</span>\n </td>\n <td>\n <button type=\"button\" onClick={() => decrement(index)}>\n -\n </button>\n <button type=\"button\" onClick={() => increment(index)}>\n +\n </button>\n </td> \n </tr>\n )\n })}\n</tbody> \n"
},
{
"answer_id": 74599731,
"author": "NAZIR HUSSAIN",
"author_id": 20587701,
"author_profile": "https://Stackoverflow.com/users/20587701",
"pm_score": -1,
"selected": false,
"text": " import React,{useState} from 'react';\n import { Table } from 'react-bootstrap';\n import { useFieldArray } from 'react-hook-form';\n \n export const ListArticle = ({ watch, control }) => {\n const [list, setList] = useState(watch('Articles'));\n \n //listWithoutDuplicates is because i just want to see once my articles even if the quantity is more than 1\n //const listWithoutDuplicates = list?.filter(\n // (ele, ind) => ind === list?.findIndex((elem) => elem.name === ele.name)\n // );\n \n const { append, remove } = useFieldArray({\n control,\n name: 'Articles',\n });\n \n const increment = (index) => {\n //append(oneArticle);\n let newList =list;\n newList[index].quantity =(newList[index].quantity || 0) +1\n setList(newList)\n };\n \n const decrement = (index) => {\n //remove(oneArticle);\n let newList =list;\n newList[index].quantity =(newList[index].quantity || 0) -1\n setList(newList)\n };\n \n \n return (\n <>\n <Table responsive>\n <thead>\n <tr>\n <th> Name </th>\n <th> Color</th>\n <th> Quantity </th>\n </tr>\n </thead>\n <tbody>\n {list?.map((oneArticle, index) => {\n return (\n <tr key={index}>\n <td>\n <span>{oneArticle?.name}</span>\n </td>\n <td>\n <span>{oneArticle?.color}</span>\n </td>\n <td>\n <button type=\"button\" onClick={() => decrement(index)}>\n -\n </button>\n <p>{oneArticle.quantity || 0}</p>\n <button type=\"button\" onClick={() => increment(index)}>\n +\n </button>\n \n </td> \n </tr>\n );\n })}\n </tbody> \n </Table>\n </>\n );\n};\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3123056/"
] |
74,599,601
|
<p>I have a polynomial like this:
<code>3*D*c1*cos_psi**2*p**2*u/(d*k**4*kappa**2) + 3*D*c1*cos_psi*p*q*u/(2*k**4*kappa**2) - 3*D*c1*cos_psi*p*q*u/(d*k**4*kappa**2) - 3*D*c1*u/(2*k**2*kappa**2) - 3*D*c1*p**2*u/(2*k**4*kappa**2) - 3*D*c1*q**2*u/(4*k**4*kappa**2) + 3*D*c1*p**2*u*(1 - cos_psi**2)/(d*k**4*kappa**2) + 3*D*c1*q**2*u/(2*d*k**4*kappa**2) - 6*D*c3*cos_psi**2*p**2*u/(d*k**4*kappa**2) - 6*D*c3*cos_psi*p*q*u/(k**4*kappa**2) + 6*D*c3*cos_psi*p*q*u/(d*k**4*kappa**2) + 6*D*c3*p**2*u/(k**4*kappa**2) + 3*D*c3*q**2*u/(k**4*kappa**2) - 6*D*c3*p**2*u*(1 - cos_psi**2)/(d*k**4*kappa**2) - 3*D*c3*q**2*u/(d*k**4*kappa**2)</code></p>
<p>I want to collect the terms like a multivariable polynomial of powers of q and p.</p>
<p>I found the <code>Poly(expr,q,p)</code> does exactly what I want. But the outcome is <code>Poly((-3*D*c1*d*u + 6*D*c1*u + 12*D*c3*d*u - 12*D*c3*u)/(4*d*k**4*kappa**2)*q**2 + (3*D*c1*cos_psi*d*u - 6*D*c1*cos_psi*u - 12*D*c3*cos_psi*d*u + 12*D*c3*cos_psi*u)/(2*d*k**4*kappa**2)*q*p + (-3*D*c1*d*u + 6*D*c1*u + 12*D*c3*d*u - 12*D*c3*u)/(2*d*k**4*kappa**2)*p**2 - 3*D*c1*u/(2*k**2*kappa**2), q, p, domain='ZZ(u,c1,c3,d,k,D,cos_psi,kappa)')</code>. I just want the final expression without the 'Poly(__,q,p,domain=....)'. I only want the ____ .</p>
|
[
{
"answer_id": 74599922,
"author": "Nikos Pap",
"author_id": 9259357,
"author_profile": "https://Stackoverflow.com/users/9259357",
"pm_score": 0,
"selected": false,
"text": " expr = collect(simplify(expr),(q,p,p*q))\n"
},
{
"answer_id": 74605746,
"author": "smichr",
"author_id": 1089161,
"author_profile": "https://Stackoverflow.com/users/1089161",
"pm_score": 2,
"selected": true,
"text": ">>> Poly(3*x+y*x+4+z,x).as_expr()\nx*(y + 3) + z + 4\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9259357/"
] |
74,599,602
|
<p>I want to find download URL for the latest version of Cura right now it is (<a href="https://github.com/Ultimaker/Cura/releases/download/5.2.1/Ultimaker-Cura-5.2.1-win64.exe" rel="nofollow noreferrer">https://github.com/Ultimaker/Cura/releases/download/5.2.1/Ultimaker-Cura-5.2.1-win64.exe</a>)
and I have written
<code>(Invoke-WebRequest -Uri "https://ultimaker.com/software/ultimaker-cura").innerHTML -match "(https*.exe)"</code>
I tried it with .innerHTML or usebasicparsing or Invoke-Restmethod and I could not find it, can someone help me to find it?
thanks in advance</p>
|
[
{
"answer_id": 74599922,
"author": "Nikos Pap",
"author_id": 9259357,
"author_profile": "https://Stackoverflow.com/users/9259357",
"pm_score": 0,
"selected": false,
"text": " expr = collect(simplify(expr),(q,p,p*q))\n"
},
{
"answer_id": 74605746,
"author": "smichr",
"author_id": 1089161,
"author_profile": "https://Stackoverflow.com/users/1089161",
"pm_score": 2,
"selected": true,
"text": ">>> Poly(3*x+y*x+4+z,x).as_expr()\nx*(y + 3) + z + 4\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18917305/"
] |
74,599,631
|
<p>I have a list of dicts that looks like this:</p>
<pre><code>totalList = [
{'sku': '222222', 'title': 'apple', 'quantity': '2', 'price': '3$'},
{'sku': '333333', 'title': 'banana', 'quantity': '1', 'price': '1.5$'},
{'sku': '444444', 'title': 'peach', 'quantity': '5', 'price': '9$'},
{'sku': '123456', 'title': 'tv', 'quantity': '1', 'price': '500$'},
{'sku': '777777', 'title': 'apple', 'quantity': '2', 'price': '3$'},
{'sku': '123456', 'title': 'tv', 'quantity': '2', 'price': '1000$'},
{'sku': '333333', 'title': 'banana', 'quantity': '4', 'price': '6$'},
]
</code></pre>
<p>the final result should look like this:</p>
<pre><code>totalList = [
{'sku': '222222', 'title': 'apple', 'quantity': '2', 'price': '3$'},
{'sku': '333333', 'title': 'banana', 'quantity': '5', 'price': '7.5$'},
{'sku': '444444', 'title': 'peach', 'quantity': '5', 'price': '9$'},
{'sku': '123456', 'title': 'tv', 'quantity': '3', 'price': '1500$'},
{'sku': '777777', 'title': 'apple', 'quantity': '2', 'price': '3$'},
]
</code></pre>
<p>my code so far is looking like this:</p>
<pre><code>newList = []
for x in totalList:
for y in totalList:
if x['sku'] == y['sku']:
x['quantity'] = int(x['quantity']) + int(y['quantity'])
else:
newList.append(x)
</code></pre>
<p>it should find all duplicated "sku" and then calc them all together into 1 remove all other duplicates and have like a summary of everything in 1 list.</p>
|
[
{
"answer_id": 74599922,
"author": "Nikos Pap",
"author_id": 9259357,
"author_profile": "https://Stackoverflow.com/users/9259357",
"pm_score": 0,
"selected": false,
"text": " expr = collect(simplify(expr),(q,p,p*q))\n"
},
{
"answer_id": 74605746,
"author": "smichr",
"author_id": 1089161,
"author_profile": "https://Stackoverflow.com/users/1089161",
"pm_score": 2,
"selected": true,
"text": ">>> Poly(3*x+y*x+4+z,x).as_expr()\nx*(y + 3) + z + 4\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622545/"
] |
74,599,665
|
<p>In my python file I always start with the following lines</p>
<pre class="lang-py prettyprint-override"><code>import sys
import matplotlib as mpl
sys.append('C:\\MyPackages')
rc_fonts = {
"text.usetex": True,
'font.size': 20,
'text.latex.preamble': r"\usepackage{bm}",
}
mpl.rcParams.update(rc_fonts)
</code></pre>
<p>Is there a way to indicate to VScode that each time I create a new <code>file.py</code>, it will start with the previous lines ?</p>
<p>For now, I copy/paste a 'template.py' but this is not really convenient.</p>
<p>And because I work with Windows, I also tried to add 'C:\MyPackages' to the user variables Path but it didn't work.</p>
|
[
{
"answer_id": 74599922,
"author": "Nikos Pap",
"author_id": 9259357,
"author_profile": "https://Stackoverflow.com/users/9259357",
"pm_score": 0,
"selected": false,
"text": " expr = collect(simplify(expr),(q,p,p*q))\n"
},
{
"answer_id": 74605746,
"author": "smichr",
"author_id": 1089161,
"author_profile": "https://Stackoverflow.com/users/1089161",
"pm_score": 2,
"selected": true,
"text": ">>> Poly(3*x+y*x+4+z,x).as_expr()\nx*(y + 3) + z + 4\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12451058/"
] |
74,599,713
|
<p>I'm trying to merge two dictionaries based on key value. However, I'm not able to achieve it. Below is the way I tried solving.</p>
<pre><code>dict1 = {4: [741, 114, 306, 70],
2: [77, 325, 505, 144],
3: [937, 339, 612, 100],
1: [52, 811, 1593, 350]}
dict2 = {1: 'A', 2: 'B', 3: 'C', 4: 'D'}
#My resultant dictionary should be
output = {'D': [741, 114, 306, 70],
'B': [77, 325, 505, 144],
'C': [937, 339, 612, 100],
'A': [52, 811, 1593, 350]}
#My code
def mergeDictionary(dict_obj1, dict_obj2):
dict_obj3 = {**dict_obj1, **dict_obj2}
for key, value in dict_obj3.items():
if key in dict_obj1 and key in dict_obj2:
dict_obj3[key] = [value , dict_obj1[key]]
return dict_obj3
dict_3 = mergeDictionary(dict1, dict2)
#But I'm getting this as output
dict_3={4: ['D', [741, 114, 306, 70]], 2: ['B', [77, 325, 505, 144]], 3: ['C', [937, 339, 612, 100]], 1: ['A', [52, 811, 1593, 350]]}
</code></pre>
<p>Thanks for your help in advance</p>
|
[
{
"answer_id": 74599751,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 4,
"selected": true,
"text": "output = {dict2[k]: v for k,v in dict1.items()}\n {'D': [741, 114, 306, 70],\n 'B': [77, 325, 505, 144],\n 'C': [937, 339, 612, 100],\n 'A': [52, 811, 1593, 350]}\n"
},
{
"answer_id": 74599839,
"author": "Leno",
"author_id": 11153525,
"author_profile": "https://Stackoverflow.com/users/11153525",
"pm_score": 1,
"selected": false,
"text": "dict_obj3[key] = [value , dict_obj1[key]]\n value dict_obj3[value] = dict_obj1[key]\n dict1={4: [741, 114, 306, 70], 2: [77, 325, 505, 144], 3: [937, 339, 612, 100], 1: [52, 811, 1593, 350]}\ndict2={1: 'A', 2: 'B', 3: 'C', 4: 'D'}\n\n# My resultant dictionary should be \n# output={D: [741, 114, 306, 70], B: [77, 325, 505, 144], C: [937, 339, 612, 100], A: [52, 811, 1593, 350]}\n\n\n# My code\n\ndef mergeDictionary(dict_obj1, dict_obj2):\n dict_obj3 = {} # {**dict_obj1, **dict_obj2}\n for key, value in dict_obj2.items():\n dict_obj3[value] = dict_obj1[key]\n return dict_obj3\n\ndict_3 = mergeDictionary(dict1, dict2)\nprint(dict_3)\n"
},
{
"answer_id": 74599893,
"author": "Antony Hatchkins",
"author_id": 237105,
"author_profile": "https://Stackoverflow.com/users/237105",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\n\ndf1 = pd.DataFrame(dict1)\ndf1.rename(columns=dict2)\ndf1\n"
},
{
"answer_id": 74600086,
"author": "D P",
"author_id": 20622893,
"author_profile": "https://Stackoverflow.com/users/20622893",
"pm_score": -1,
"selected": false,
"text": "# Python code to demonstrate dictionary\n# comprehension\n\n# Lists to represent keys and values\nkeys = ['a','b','c','d','e']\nvalues = [1,2,3,4,5]\n\n# but this line shows dict comprehension here\nmyDict = { k:v for (k,v) in zip(keys, values)}\n\n# We can use below too\n# myDict = dict(zip(keys, values))\n\nprint (myDict)\n"
},
{
"answer_id": 74600210,
"author": "Daniil Fajnberg",
"author_id": 19770795,
"author_profile": "https://Stackoverflow.com/users/19770795",
"pm_score": 2,
"selected": false,
"text": "dict1 dict2 KeyError dict1 dict2 from collections.abc import Mapping\n\nKT = str\nVT = list[int]\n\ndef merge(\n keys_map: Mapping[int, KT],\n values_map: Mapping[int, VT],\n) -> dict[KT, VT]:\n output = {}\n for key, value in values_map.items():\n try:\n output[keys_map[key]] = value\n except KeyError:\n pass\n return output\n if __name__ == \"__main__\":\n dict1 = {\n 5: [1, 2, 3],\n 4: [741, 114],\n 2: [77, 325],\n 3: [937, 339],\n 1: [52, 811],\n }\n dict2 = {1: 'A', 2: 'B', 3: 'C', 4: 'D'}\n print(merge(dict2, dict1))\n"
},
{
"answer_id": 74601744,
"author": "Arifa Chan",
"author_id": 19574157,
"author_profile": "https://Stackoverflow.com/users/19574157",
"pm_score": 2,
"selected": false,
"text": "dict.update() def mergeDictionary(dict_obj1, dict_obj2):\n dict_obj3 = dict()\n for key, val in dict_obj1.items():\n dict_obj3.update({dict_obj2[key]: val})\n return dict_obj3\n def mergeDictionary(dict_obj1, dict_obj2):\n dict_obj3 = dict()\n for key, val in dict_obj1.items():\n dict_obj3[dict_obj2[key]] = val\n return dict_obj3\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16710696/"
] |
74,599,719
|
<p>I have a list, that contains many sub-lists. Each sub-list, has two values. I want to substract the first value from the second value in each sub-list, and store the results in new lists.</p>
<p>Now those new lists are also sub-lists, of another list of lists.</p>
<p>So for example, <code>lists_of_lists1</code> is something like this:</p>
<pre><code>lists_of_lists1 = [ran_list1, ran_list2, ran_list3, ran_list4, ran_list5, ran_list6,
ran_list7,ran_list8]
</code></pre>
<p>And this is <code>ran_list1</code>, a sub-list. All sub-lists look similar to this.</p>
<pre><code>[[34.39460533995712, 47.84539466004288],
[33.095772478005635, 46.50422752199436],
[36.66750709361337, 44.44360401749775],
[33.33459042563053, 42.14689105585095],
[36.638367322851444, 43.62250224236595],
[36.465767572400296, 49.200899094266376],
[32.220702473831686, 42.65929752616831],
[34.31937169660605, 41.14216676493242],
[31.198269305510344, 42.801730694489656],
[31.216878962221035, 40.6092079943007],
[28.465488368524227, 38.793770890735026],
[34.50342917911651, 45.32990415421682]]
</code></pre>
<p>Now substract <code>ran_list1[1] - ran_list1[0]</code> (for each sublist in this manner), and the results store in here:</p>
<pre><code>list_of_lists2 = [ran_subresult1 , ran_subresult2 , ran_subresult3 , ran_subresult4 ,
ran_subresult5 , ran_subresult6 , ran_subresult7, ran_subresult8]
</code></pre>
<p>So <code>ran_subresult1</code>, is an empty list that the results of <code>ran_list1[1] - ran_list1[0]</code> would be store in it, and <code>ran_subresult2</code> would store the resuls of <code>ran_list2[1] - ran_list2[0]</code>, and so on...</p>
<p>My try of this look like this:</p>
<pre><code>for i in lists_of_lists1:
for j in range(len(i)):
list_of_lists2[j].append(lists_of_lists1[j][1] - lists_of_lists1[j][0])
</code></pre>
<p>I got a bit lost with the <code>i</code> and <code>j</code>, I guess I'm in the right direction but I'm still unable to do it. I'll appreciate some help with this. Thanks!</p>
<h3>EDIT - This is the expected output. From <code>lists_of_lists1</code>, let's take the first sub-list as an example, which is <code>ran_list1</code>. The values inside <code>ran_list1</code> are pairs of numbers:</h3>
<pre><code>[[34.39460533995712, 47.84539466004288],
[33.095772478005635, 46.50422752199436],
[36.66750709361337, 44.44360401749775],
[33.33459042563053, 42.14689105585095],
[36.638367322851444, 43.62250224236595],
[36.465767572400296, 49.200899094266376],
[32.220702473831686, 42.65929752616831],
[34.31937169660605, 41.14216676493242],
[31.198269305510344, 42.801730694489656],
[31.216878962221035, 40.6092079943007],
[28.465488368524227, 38.793770890735026],
[34.50342917911651, 45.32990415421682]]
</code></pre>
<p>Now substract in this manner:</p>
<pre><code>47.84539466004288 - 34.39460533995712 = 13.451
46.50422752199436 - 33.095772478005635 = 13.409
</code></pre>
<p>And so on...</p>
<p>Now those results will be stored inside <code>ran_subresult1</code>, which is the first sub-list inside <code>list_of_lists2</code>.</p>
<p>Hence, <code>ran_subresult1</code> would be <code>[13.451, 13.409.....]</code></p>
<p>And so on for each sub-list.</p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17945841/"
] |
74,599,721
|
<p>I'm pretty new to WinForms and I need something for a project: I'm writing a test program for a device. The device sends some data about itself and I have to output some information about it in a tab and on a chart.</p>
<p>Here is the twist: the device can be a double, triple, or n-uple device which means I'll have to output n tabs and n charts.
For this I would like to have a "template" with a tab and a chart and put one for every sub-device, one under another in my winforms window. How do you think is this possible? Do you have a better idea?</p>
<p>I don't know if I'm very clear so I added a picture to explain what I want.(<a href="https://i.stack.imgur.com/Nd00g.png" rel="nofollow noreferrer">https://i.stack.imgur.com/Nd00g.png</a>)
Thank you</p>
<p>I tried to search the web for templates in winforms but found nothing that fits what I want.</p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20439316/"
] |
74,599,729
|
<p>I have a PySpark dataframe with values and dictionaries that provide a textual mapping for the values.
Not every row has the same dictionary and the values can vary too.</p>
<pre><code>| value | dict |
| -------- | ---------------------------------------------- |
| 1 | {"1": "Text A", "2": "Text B"} |
| 2 | {"1": "Text A", "2": "Text B"} |
| 0 | {"0": "Another text A", "1": "Another text B"} |
</code></pre>
<p>I want to make a "status" column that contains the right mapping.</p>
<pre><code>
| value | dict | status |
| -------- | ------------------------------- | -------- |
| 1 | {"1": "Text A", "2": "Text B"} | Text A |
| 2 | {"1": "Text A", "2": "Text B"} | Text B |
| 0 | {"0": "Other A", "1": "Other B"} | Other A |
</code></pre>
<p>I have tried this code:</p>
<pre><code>df.withColumn("status", F.col("dict").getItem(F.col("value"))
</code></pre>
<p>This code does not work. With a hard coded value, like "2", the same code does provide an output, but of course not the right one:</p>
<pre><code>df.withColumn("status", F.col("dict").getItem("2"))
</code></pre>
<p>Could someone help me with getting the right mapped value in the status column?</p>
<p>EDIT: my code did work, except for the fact that my "value" was a double and the keys in dict are strings. When casting the column from double to int to string, the code works.</p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12904151/"
] |
74,599,793
|
<p>I have this array:</p>
<pre class="lang-js prettyprint-override"><code>[ {
id_base: 2,
nombre_base: 'Hayama',
nombre_flota: 'Browseblab',
matricula: '#b65e9e',
id_vehiculo: 3
}, {
id_base: 2,
nombre_base: 'Hayama',
nombre_flota: 'Browseblab',
matricula: '#b65e9e',
id_vehiculo: 3
}, {
id_base: 2,
nombre_base: 'Hayama',
nombre_flota: 'Browseblab',
matricula: '#a606f8',
id_vehiculo: 4
}, {
id_base: 1,
nombre_base: 'Cabitan',
nombre_flota: 'Browseblab',
matricula: '#8f72c2',
id_vehiculo: 1
}, {
id_base: 1,
nombre_base: 'Cabitan',
nombre_flota: 'Browseblab',
matricula: '#8f72c2',
id_vehiculo: 1
}]
</code></pre>
<p>And i want it to be grouped like this:</p>
<pre class="lang-js prettyprint-override"><code>[{
id_base: 2,
nombre_base: 'Hayama',
nombre_flota: 'Browseblab',
[{
matricula: '#b65e9e',
id_vehiculo: 3
}, {
matricula: '#a606f8',
id_vehiculo: 4
}]
}, {
id_base: 1,
nombre_base: 'Cabitan',
nombre_flota: 'Browseblab',
[{
matricula: '#8f72c2',
id_vehiculo: 1
}, {
matricula: '#8f72c2',
id_vehiculo: 1
}]
}]
</code></pre>
<p>I have tried this:</p>
<pre class="lang-js prettyprint-override"><code>let agrupadoBases = result.reduce((group, linea) => {
const { id_base } = linea
group[id_base] = group[id_base] ?? []
delete linea.id_base
group[id_base].push(linea)
return group
}, {})
</code></pre>
<p>But it only separates id_base from the rest</p>
<p><code>{ '1': [ RowDataPacket { nombre_base: 'Cabitan', nombre_flota: 'Browseblab', matricula: '#8f72c2', id_vehiculo: 1 }, ], '2': [ RowDataPacket { nombre_base: 'Hayama', nombre_flota: 'Browseblab', matricula: '#b65e9e', id_vehiculo: 3 }, RowDataPacket { nombre_base: 'Hayama', nombre_flota: 'Browseblab', matricula: '#a606f8', id_vehiculo: 4 } ] }</code></p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15375795/"
] |
74,599,805
|
<p>I am using retrofit Multipart request to upload an image and it is uplaoding successfully to the server, in another screen I want to implement the functionality to change or delete that image and when I fetch the image from the server I only got the name of the image and a Base URL by using which I can display the picture in ImageView/RecyclerView and the problem is I am not able to upload exact the same image again as I have only the name of the image, is there any way in android from where I can get the image as a File by just providing the name of the image like (1000007983.jpg).</p>
<p>I have tried creating the file from the URL which the server is returing but getting an error of file not found.</p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13730008/"
] |
74,599,812
|
<pre><code>public class Menu {
public static void main(String[] args)
throws java.io.IOException {
char choice;
do {
System.out.println("Help on:");
System.out.println(" 1. if");
System.out.println(" 2. while");
System.out.println(" 3. do-while");
System.out.println(" 4. for");
System.out.println(" 5. switch");
choice = (char) System.in.read();
} while(choice < '1' || choice > '5');
}
}
</code></pre>
<p>when i input 0 or greater than 5 it cause the loop to execute three time. like this:</p>
<pre><code>Help on:
1. if
2. while
3. do-while
4. for
5. switch
6
Help on:
1. if
2. while
3. do-while
4. for
5. switch
Help on:
1. if
2. while
3. do-while
4. for
5. switch
Help on:
1. if
2. while
3. do-while
4. for
5. switch
</code></pre>
<p>How can I fix this problem?</p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599812",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622822/"
] |
74,599,820
|
<pre><code>views.py
def index(request):
if request.method == "POST":
from_date = request.POST.get("from_date")
f_date = datetime.datetime.strptime(from_date,'%Y-%m-%d')
print(f_date)
to_date = request.POST.get("to_date")
t_date = datetime.datetime.strptime(to_date, '%Y-%m-%d')
print(t_date)
global get_records_by_date
get_records_by_date = Scrapper.objects.all().filter(Q(start_time__range=f_date),Q(end_time__range=t_date))
print(get_records_by_date)
</code></pre>
<p>I need to get the dates from the range start time and end time based on datetime field. When I run the script its showing TypeError at / 'datetime.datetime' object is not iterable. Is there any solution for particular issue</p>
<p><a href="https://i.stack.imgur.com/EgRAz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EgRAz.png" alt="Table structure" /></a></p>
|
[
{
"answer_id": 74599958,
"author": "Hack3r",
"author_id": 12171536,
"author_profile": "https://Stackoverflow.com/users/12171536",
"pm_score": -1,
"selected": false,
"text": "list = [[1, 23], [3, 2], [32, 213], [2321, 23]]\nres_list = []\nfor i in list:\n res_list.append((i[1]-i[0]))\n\nprint(res_list)\n"
},
{
"answer_id": 74600015,
"author": "alfonsoSR",
"author_id": 16569183,
"author_profile": "https://Stackoverflow.com/users/16569183",
"pm_score": 0,
"selected": false,
"text": "main_list = [\n [\n [34.39460533995712, 47.84539466004288],\n [33.095772478005635, 46.50422752199436],\n [36.66750709361337, 44.44360401749775],\n [33.33459042563053, 42.14689105585095],\n [36.638367322851444, 43.62250224236595],\n [36.465767572400296, 49.200899094266376],\n [32.220702473831686, 42.65929752616831],\n [34.31937169660605, 41.14216676493242],\n [31.198269305510344, 42.801730694489656],\n [31.216878962221035, 40.6092079943007],\n [28.465488368524227, 38.793770890735026],\n [34.50342917911651, 45.32990415421682],\n ]\n]\n\nres_list = main_list.copy()\nfor i, main_i in enumerate(main_list):\n for j, main_i_j in enumerate(main_i):\n res_list[i][j] = [main_i_j[1] - main_i_j[0]]\n"
},
{
"answer_id": 74600038,
"author": "yagod",
"author_id": 5615895,
"author_profile": "https://Stackoverflow.com/users/5615895",
"pm_score": 1,
"selected": true,
"text": "import numpy as np\n ran_list list_of_lists2 = []\nfor sub_list in lists_of_lists1:\n new_sub_list = np.array(sub_list)\n new_sub_list = new_sub_list[:,1] - new_sub_list[:,0]\n list_of_lists2.append(new_sub_list.tolist())\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20467368/"
] |
74,599,828
|
<p>I've created empty dataframe that I have to fill.</p>
<pre><code>d = {'A': [], 'B': [], 'C': []}
dataframe = pd.DataFrame(data=d)
</code></pre>
<p>Then I am assigning data like this:</p>
<pre><code>dataframe['A'] = some_list_1a
dataframe['B'] = some_list_1b
dataframe['C'] = some_list_1c
</code></pre>
<p>So my dataframe is filled like this:</p>
<pre><code> A B C
----------------
val1 val1 val1
val1 val1 val1
val1 val1 val1
</code></pre>
<p>Then I have to add new values from list but the previous way is not working:
<code>dataframe['A'] = some_list_2a </code> etc.</p>
<p>That's what I want:</p>
<pre><code> A B C
----------------
val1 val1 val1
val1 val1 val1
val1 val1 val1
val2 val2 val2
val2 val1 val2
val2 val2 val2
</code></pre>
<p>(val1 - values from first lists, val2 - values from second lists)</p>
<p>I know I can make second dataframe and use <code>concat</code> method, but is there another way of doing it?</p>
|
[
{
"answer_id": 74599862,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "d = {'A': some_list_1a + some_list_2a, \n 'B': some_list_1b + some_list_2b,\n 'C': some_list_1c + some_list_2c}\ndataframe = pd.DataFrame(data=d)\n from collections import defaultdict\n\nd = defaultdict(list)\n\n#some loop\nfor x in iter:\n d[col_name].append(sublist)\n \ndataframe = pd.DataFrame(data=d)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14147572/"
] |
74,599,836
|
<p>I am working on an e-commerce app in Angular 11.</p>
<p>I have a service that makes a <code>get</code> request and reads a JSON.</p>
<p>The purpose of this service is to <em>determine which product is promoted</em>.</p>
<p>The service:</p>
<pre><code>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Campaign } from '../models/campaign';
@Injectable({
providedIn: 'root'
})
export class PromoProductsService {
public apiURL: string;
constructor(private http: HttpClient) {
this.apiURL = `${apiURL}/promo-products`;
}
public getPromoData(){
return this.http.get<Campaign>(`${this.apiURL}/campaign`);
}
}
</code></pre>
<p>In the product card component I have:</p>
<pre><code>public getPromoData() {
this.PromoProductsService.getPromoData().pipe(takeUntil(this.destroyed$)).subscribe(data => {
this.campaignData = data;
this.campaignProducts = this.campaignData.campaign.products;
let promoProduct = this.campaignProducts.find((product:any) => {
return this.product.product_id == product.id;
});
if (promoProduct) {
this.isCampaignProduct = true;
this.cdr.detectChanges();
}
});
}
</code></pre>
<h4>The problem</h4>
<p>The code above checks, for every product card, if the product is in the array of promoted products.</p>
<p>The problem with this is that there is <em>a request for the array of promoted products for every product</em> on the page.</p>
<h4>Question:</h4>
<p>How can I make (and use) a <em>single request</em> for the array of promoted products?</p>
|
[
{
"answer_id": 74600219,
"author": "Fabian Strathaus",
"author_id": 17298437,
"author_profile": "https://Stackoverflow.com/users/17298437",
"pm_score": 2,
"selected": true,
"text": "import { Injectable } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { Campaign } from '../models/campaign';\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport class PromoProductsService {\n\n public apiURL: string;\n\n promo$: Observable<Campaign>;\n \n constructor(private http: HttpClient) {\n this.apiURL = `${apiURL}/promo-products`;\n this.promo$ = this.http.get<Campaign>(`${this.apiURL}/campaign`).pipe(shareReplay());\n }\n}\n\n public getPromoData() { \n this.PromoProductsService.promo$.pipe(takeUntil(this.destroyed$)).subscribe(data => {\n this.campaignData = data;\n this.campaignProducts = this.campaignData.campaign.products;\n\n let promoProduct = this.campaignProducts.find((product:any) => { \n return this.product.product_id == product.id;\n });\n\n if (promoProduct) {\n this.isCampaignProduct = true;\n this.cdr.detectChanges();\n }\n });\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4512005/"
] |
74,599,886
|
<p>I have a question regarding views in the context of jpa entities in SpringBoot. Up to now I am using the auto create feature that automatically creates the tables by the definitions of the entities in Java. Now my application has grown so far that I need to use views. I do not want to write and maintain the sql create statements for all tables/entities otherwise I could simple add the create view statement to the schema.sql file, which I do not want to use. Instead I have a commandLineRunner that creates the views after startup but when testing the app it fails because the entities reference the views before the idividual views are created.</p>
<p>So is there a way to write an sql create statement in the entity maybe with an annotation to create a view during entity instantiation?</p>
|
[
{
"answer_id": 74600197,
"author": "kenneth",
"author_id": 9877340,
"author_profile": "https://Stackoverflow.com/users/9877340",
"pm_score": 1,
"selected": false,
"text": "void Autowired private final PriceRepository priceRepository;\n\n @Autowired\n public ProductionDataLoader(PriceRepository priceRepository, KeywordRepository keywordRepository, AccountRepository accountRepository) {\n this.priceRepository = priceRepository;\n }\n\n @Override\n public void loadEnvironmentSpecificData() {\n doSomethingWithData();\n }\n @Profile dev prod"
},
{
"answer_id": 74609947,
"author": "ChopStick",
"author_id": 9317010,
"author_profile": "https://Stackoverflow.com/users/9317010",
"pm_score": 1,
"selected": true,
"text": "public class StartUpRunner implements CommandLineRunner {\n\n public static final String VIEW_INIT_FILE = \"after_hibernate_init.sql\";\n @Autowired\n private DataSource dataSource;\n\n @Override\n public void run(String... arg) throws Exception {\n createSQLViews();\n }\n\n private void createSQLViews(){\n boolean IGNORE_FAILED_DROPS = true;\n ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(false, IGNORE_FAILED_DROPS , \"UTF-8\", new ClassPathResource(VIEW_INIT_FILE));\n resourceDatabasePopulator.execute(dataSource);\n }\n}\n DROP TABLE IF exists YOUR_VIEW_NAME;\n\nCREATE OR REPLACE View YOUR_VIEW_NAME\n//Your view creation statement here....\n @ActiveProfiles(\"sqltest\")\n@ExtendWith(SpringExtension.class)\n@SpringBootTest\n@TestMethodOrder(MethodOrderer.OrderAnnotation.class)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9317010/"
] |
74,599,899
|
<p>Could you help me please find coordinates of point on a plane?</p>
<p><a href="https://i.stack.imgur.com/9WGOk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9WGOk.png" alt="enter image description here" /></a></p>
<p>I try to find coordinates of the point.</p>
|
[
{
"answer_id": 74600197,
"author": "kenneth",
"author_id": 9877340,
"author_profile": "https://Stackoverflow.com/users/9877340",
"pm_score": 1,
"selected": false,
"text": "void Autowired private final PriceRepository priceRepository;\n\n @Autowired\n public ProductionDataLoader(PriceRepository priceRepository, KeywordRepository keywordRepository, AccountRepository accountRepository) {\n this.priceRepository = priceRepository;\n }\n\n @Override\n public void loadEnvironmentSpecificData() {\n doSomethingWithData();\n }\n @Profile dev prod"
},
{
"answer_id": 74609947,
"author": "ChopStick",
"author_id": 9317010,
"author_profile": "https://Stackoverflow.com/users/9317010",
"pm_score": 1,
"selected": true,
"text": "public class StartUpRunner implements CommandLineRunner {\n\n public static final String VIEW_INIT_FILE = \"after_hibernate_init.sql\";\n @Autowired\n private DataSource dataSource;\n\n @Override\n public void run(String... arg) throws Exception {\n createSQLViews();\n }\n\n private void createSQLViews(){\n boolean IGNORE_FAILED_DROPS = true;\n ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(false, IGNORE_FAILED_DROPS , \"UTF-8\", new ClassPathResource(VIEW_INIT_FILE));\n resourceDatabasePopulator.execute(dataSource);\n }\n}\n DROP TABLE IF exists YOUR_VIEW_NAME;\n\nCREATE OR REPLACE View YOUR_VIEW_NAME\n//Your view creation statement here....\n @ActiveProfiles(\"sqltest\")\n@ExtendWith(SpringExtension.class)\n@SpringBootTest\n@TestMethodOrder(MethodOrderer.OrderAnnotation.class)\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7699088/"
] |
74,599,926
|
<p>Consider the below code in any method.</p>
<p><code>count += new String(text.getBytes()).length()</code></p>
<p>I am facing memory issue.</p>
<p>I am using this to count number of characters in file. When I am fetching heap dump I am getting huge amount of memory occupied by String Objects. Is it because of this line of code? I am just looking for suggestions.</p>
|
[
{
"answer_id": 74600048,
"author": "mozturk",
"author_id": 13499450,
"author_profile": "https://Stackoverflow.com/users/13499450",
"pm_score": -1,
"selected": false,
"text": "for(int i=0; i<text.length(); i++) { \n count++;\n}\n"
},
{
"answer_id": 74600107,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 3,
"selected": true,
"text": "text String count +=text.length() text ? length() text"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19642753/"
] |
74,599,939
|
<p>I have two arrays as codely illustrated below:</p>
<pre><code>let arrayOne = [1669683600000, 1669770000000, 1669698000000, 1669755600000];
let arrayTwo = [1669683600000, 1669770000000];
</code></pre>
<p>I would like to remove the contents of <code>arrayTwo</code> from <code>arrayOne</code>.
I thought the code below would work:</p>
<pre><code>let results = arrayOne.filter((item)=> item !== arrayTwo);
console.log('results: ' ,results );
</code></pre>
<p>The code above yeilds:</p>
<pre><code>results: [1669683600000, 1669770000000, 1669698000000, 1669755600000]
</code></pre>
<p>The desired results are:</p>
<pre><code>results: [1669698000000, 1669755600000]
</code></pre>
<p>How do I achieve my desired results?</p>
|
[
{
"answer_id": 74600048,
"author": "mozturk",
"author_id": 13499450,
"author_profile": "https://Stackoverflow.com/users/13499450",
"pm_score": -1,
"selected": false,
"text": "for(int i=0; i<text.length(); i++) { \n count++;\n}\n"
},
{
"answer_id": 74600107,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 3,
"selected": true,
"text": "text String count +=text.length() text ? length() text"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/745262/"
] |
74,599,943
|
<ol>
<li>Spring cloud-config server started with application.properties :</li>
</ol>
<pre><code>server.port:8888
spring.application.name=test-config-server
spring.cloud.config.server.git.uri=https://gitlab.com/pearsontechnology/gpt/sms/sms-micro-services/config-server.git
spring.cloud.config.server.git.default-label=develop
#Private repo. access credentials
spring.cloud.config.server.git.username=xxx
spring.cloud.config.server.git.password=xxxx
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.profile=dev
</code></pre>
<p>On starting the config-client,
<em>Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.</em></p>
<p>My version of spring boot, spring-cloud and dependencies are as follows from pom.xml :</p>
<pre><code><artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<java.version>17</java.version>
<spring-cloud.version>2021.0.3</spring-cloud.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
</code></pre>
<p>application.prop of config-client :</p>
<pre><code>spring.application.name=systems-lookup-service
spring.cloud.config.profile=dev
spring.config.import=optional:configserver:
server.port=8081
</code></pre>
<p>Properties related to Datasource like url etc. need to be taken from
systems-lookup-service-dev.properties hosted on Git.</p>
<pre><code>custom.url=jdbc:oracle:thin:@localhost:1998/smscert
custom.username=smscert
custom.password=go#salt
custom.driverClassName=
</code></pre>
<p>And the DAO class in config-client accessing the db :</p>
<pre><code>public class XXDaoImpl implements XXDao {
private JdbcTemplate jdbcTemplate;
@Autowired(required=false)
private DataSourceConfig config;
@Autowired
public SystemDaoImpl(JdbcTemplate jdbcTemplateIn){
final DataSource dataSource = DataSourceBuilder.create()
.driverClassName(config.getDriverClassName())
.url(config.getUrl())
.username(config.getUsername())
.password(config.getPassword())
.build();
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
...............
}
@Component
@ConfigurationProperties("custom")
public class DataSourceConfig {
private String url;
private String username;
private String password;
//@Value("${greeting.message}")
private String driverClassName;
....
}
</code></pre>
|
[
{
"answer_id": 74600845,
"author": "Lunatic",
"author_id": 15758781,
"author_profile": "https://Stackoverflow.com/users/15758781",
"pm_score": 0,
"selected": false,
"text": "pom <dependency>\n <groupId>org.springframework.cloud</groupId>\n <artifactId>spring-cloud-starter-config</artifactId>\n</dependency>\n application.prop spring.application.name=systems-lookup-service\nspring.cloud.config.uri=http://localhost:\"cloud-config-port\"\nspring.profiles.active=dev\nspring.config.import=optional:configserver:\n @EnableConfigServer pom <dependency>\n <groupId>org.springframework.cloud</groupId>\n <artifactId>spring-cloud-config-server</artifactId>\n</dependency>\n spring.application.name=configuration-server\nserver.port=8780\nmanagement.endpoints.web.exposure.include=*\nspring.cloud.config.server.git.uri=file:absoluthe-path\nspring.cloud.config.server.git.clone-on-start=true\nspring.cloud.config.allowOverride=true\n servicename-profile"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74599943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1812810/"
] |
74,600,089
|
<p>I am making a for loop run the amount of times I have records in a table to see if a checkbox has been checked or not. It works however, the line of code which is used to actually see if there is something checked does not. It only works if it sees it in the top row but does not if it has to loop as it reports null.</p>
<pre><code> for(int i = 0; i < dgvForSale.Rows.Count; i++)
{
bool isCellChecked = (bool)dgvForSale.Rows[i].Cells[4].Value;
if (isCellChecked == true)
{
MessageBox.Show("Well this may have worked");
}
else
{
MessageBox.Show("Empty");
}
}
</code></pre>
<p>The code that errors is " bool isCellChecked = (bool)dgvForSale.Rows[i].Cells[4].Value; "</p>
<p>I have tried changing it in some small ways but not really sure how to fix it without a whole different way of trying to see if the box is checked. I just expect it to be able to run.</p>
|
[
{
"answer_id": 74600234,
"author": "Maahi",
"author_id": 10786431,
"author_profile": "https://Stackoverflow.com/users/10786431",
"pm_score": -1,
"selected": false,
"text": "bool? isCellChecked = (bool?)dgvForSale.Rows[i].Cells[4].Value;\n if (isCellChecked !=null && isCellChecked == true)\n{\n MessageBox.Show(\"Well this may have worked\");\n}\nelse\n{\n MessageBox.Show(\"Empty\");\n}\n"
},
{
"answer_id": 74609907,
"author": "Jiale Xue - MSFT",
"author_id": 16764901,
"author_profile": "https://Stackoverflow.com/users/16764901",
"pm_score": 1,
"selected": false,
"text": "dataGridView1.AllowUserToAddRows = false; foreach (DataGridViewRow item in dataGridView1.Rows)\n{\n if (item.Cells[3].Value == null) { continue; }\n bool isCellChecked = (bool)item.Cells[3].Value;\n\n if (isCellChecked == true)\n {\n MessageBox.Show(\"Well this may have worked\");\n }\n else\n {\n MessageBox.Show(\"Empty\");\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19374209/"
] |
74,600,099
|
<p>I have few folders inside the Data lake (Example:Test1 container) that are created every month in this format YYYY-MM (Example:2022-11) and inside this folder I have few set of data files, I want to copy this data files to different folders in the data lake.</p>
<p>And again in the next month new folder is created in the same data lake (Example:Test1 container) with 2022-12 and list goes on, 2023-01.....etc., I want to copy files inside these folders every month to different data lake folder.</p>
<p>How to achieve this?</p>
|
[
{
"answer_id": 74600234,
"author": "Maahi",
"author_id": 10786431,
"author_profile": "https://Stackoverflow.com/users/10786431",
"pm_score": -1,
"selected": false,
"text": "bool? isCellChecked = (bool?)dgvForSale.Rows[i].Cells[4].Value;\n if (isCellChecked !=null && isCellChecked == true)\n{\n MessageBox.Show(\"Well this may have worked\");\n}\nelse\n{\n MessageBox.Show(\"Empty\");\n}\n"
},
{
"answer_id": 74609907,
"author": "Jiale Xue - MSFT",
"author_id": 16764901,
"author_profile": "https://Stackoverflow.com/users/16764901",
"pm_score": 1,
"selected": false,
"text": "dataGridView1.AllowUserToAddRows = false; foreach (DataGridViewRow item in dataGridView1.Rows)\n{\n if (item.Cells[3].Value == null) { continue; }\n bool isCellChecked = (bool)item.Cells[3].Value;\n\n if (isCellChecked == true)\n {\n MessageBox.Show(\"Well this may have worked\");\n }\n else\n {\n MessageBox.Show(\"Empty\");\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20054635/"
] |
74,600,128
|
<p>How to display the <code>selected</code> value "please pick and select" in this dropdown menu example?</p>
<p>The given code is not working:</p>
<pre><code><div className="col-md-6">
<select
className="form-select"
aria-label="Default select example"
>
{" "}
{this.state.values.map((obj) => {
return (
<option selected ="please pick and select" key={obj.id} value={obj.id}>
{obj.name}
</option>
);
})}
</select>
</div>
</code></pre>
|
[
{
"answer_id": 74600234,
"author": "Maahi",
"author_id": 10786431,
"author_profile": "https://Stackoverflow.com/users/10786431",
"pm_score": -1,
"selected": false,
"text": "bool? isCellChecked = (bool?)dgvForSale.Rows[i].Cells[4].Value;\n if (isCellChecked !=null && isCellChecked == true)\n{\n MessageBox.Show(\"Well this may have worked\");\n}\nelse\n{\n MessageBox.Show(\"Empty\");\n}\n"
},
{
"answer_id": 74609907,
"author": "Jiale Xue - MSFT",
"author_id": 16764901,
"author_profile": "https://Stackoverflow.com/users/16764901",
"pm_score": 1,
"selected": false,
"text": "dataGridView1.AllowUserToAddRows = false; foreach (DataGridViewRow item in dataGridView1.Rows)\n{\n if (item.Cells[3].Value == null) { continue; }\n bool isCellChecked = (bool)item.Cells[3].Value;\n\n if (isCellChecked == true)\n {\n MessageBox.Show(\"Well this may have worked\");\n }\n else\n {\n MessageBox.Show(\"Empty\");\n }\n}\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18862993/"
] |
74,600,150
|
<p>I have a data set with many columns (DATA_OLD) in which I want to exchange all values based on an allocation list with many entries (KEY).</p>
<p>Every value in DATA_OLD should be replaced by its counterpart (can be seen in KEY) to create DATA_NEW.</p>
<p>For simplicity, the example here contains a short KEY and DATA_OLD set. In reality, there are >2500 rows in KEY and >100 columns in DATA_OLD. Therefore, an approach that can be applied to the whole data set simultaneously without calling each colname of DATA_OLD is important.</p>
<p>KEY:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>old</th>
<th>new</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
</tr>
<tr>
<td>7</td>
<td>3</td>
</tr>
<tr>
<td>12</td>
<td>4</td>
</tr>
<tr>
<td>55</td>
<td>5</td>
</tr>
</tbody>
</table>
</div>
<p><em>Following this example, every value "1" should be replaced with another value "1". Every value "3" should be replaced with value "2". Every value "7" should be replaced with value "3".</em></p>
<p>DATA_OLD (START):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>var1</th>
<th>var2</th>
<th>var3</th>
</tr>
</thead>
<tbody>
<tr>
<td>NA</td>
<td>3</td>
<td>NA</td>
</tr>
<tr>
<td>NA</td>
<td>55</td>
<td>NA</td>
</tr>
<tr>
<td>1</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>NA</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>3</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>55</td>
<td>NA</td>
<td>12</td>
</tr>
</tbody>
</table>
</div>
<p>DATA_NEW (RESULT):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>var1</th>
<th>var2</th>
<th>var3</th>
</tr>
</thead>
<tbody>
<tr>
<td>NA</td>
<td>2</td>
<td>NA</td>
</tr>
<tr>
<td>NA</td>
<td>5</td>
<td>NA</td>
</tr>
<tr>
<td>1</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>NA</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>2</td>
<td>NA</td>
<td>NA</td>
</tr>
<tr>
<td>5</td>
<td>NA</td>
<td>4</td>
</tr>
</tbody>
</table>
</div>
<p>Here reproducible data:</p>
<pre><code>KEY<-structure(list(old = c(1, 3, 7, 12, 55), new = c(1, 2, 3, 4,
5)), class = "data.frame", row.names = c(NA, -5L))
DATA_OLD<-structure(list(var1 = c(NA, NA, 1, NA, 3, 55), var2 = c(3,
55, NA, NA, NA, NA), var3 = c(1, NA, NA, NA, NA, 12)), class = "data.frame", row.names = c(NA, -6L))
DATA_NEW<-structure(list(var1 = c(NA, NA, 1, NA, 2, 5), var2 = c(2,
5, NA, NA, NA, NA), var3 = c(1, NA, NA, NA, NA, 4)), class = "data.frame", row.names = c(NA, -6L))
</code></pre>
<p>I have tried back and forth, and it appears that I am completely clueless. Help would be greatly apprecciated! The real data set is quite large...</p>
|
[
{
"answer_id": 74601191,
"author": "Ottie",
"author_id": 17732851,
"author_profile": "https://Stackoverflow.com/users/17732851",
"pm_score": 1,
"selected": true,
"text": "key <- setNames(KEY$new, KEY$old)\n> key\n 1 3 7 12 55 \n 1 2 3 4 5 \n > key[3]\n7 \n3 # WRONG! This is the 3rd item!\n> key[\"3\"]\n3 \n2 # RIGHT! This is the item named \"3\"\n apply as.data.frame(apply(DATA_OLD, 2, \\(col) key[as.character(col)]))\n var1 var2 var3\n1 NA 2 1\n2 NA 5 NA\n3 1 NA NA\n4 NA NA NA\n5 2 NA NA\n6 5 NA 4\n"
},
{
"answer_id": 74601796,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 1,
"selected": false,
"text": "match lapply DATA_OLD |>\n lapply(function(x) with(KEY, new[match(x, old)])) |>\n as.data.frame()\n DATA_NEW <- DATA_OLD\nDATA_NEW[] <- lapply(DATA_OLD, function(x) with(KEY, new[match(x, old)]))\n DATA_NEW <- DATA_OLD\nix <- 1:2 # only convert these columns\nDATA_NEW[ix] <- lapply(DATA_OLD[ix], function(x) with(KEY, new[match(x, old)]))\n map_dfr library(purrr)\nmap_dfr(DATA_OLD, ~ with(KEY, new[match(.x, old)]))\n across everything() where(is.numeric) library(purrr)\nDATA_OLD %>%\n mutate(across(everything(), ~ with(KEY, new[match(.x, old)])))\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15382910/"
] |
74,600,194
|
<p>I have a basic slider setup, with three banners in it. The id is there to set the background image. Only the banner with the class "active" is shown at the frontend.</p>
<p>I'd like to cycle that class within the elements in the "slider" div every 8 seconds, so I can add new banners in the html and they will be implemented in the loop easily.</p>
<p>My initial approach only works, if two banners are active within the slider.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>setInterval(changebanner, 8000);
function changebanner() {
document.getElementsByClassName("banner").classList.toggle("active");
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="slider">
<div class="banner active" id="sky"></div>
<div class="banner" id="outdoor"></div>
<div class="banner" id="photo"></div>
</div></code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74600430,
"author": "Pete",
"author_id": 1790982,
"author_profile": "https://Stackoverflow.com/users/1790982",
"pm_score": 2,
"selected": true,
"text": "const banners = document.getElementsByClassName(\"banner\"); // get banners\nlet currentActive = 0; // set the current active slide index\nsetInterval(changebanner, 2000); // have changed to 2000 for demo so you don't have to wait 8 seconds\n\nfunction changebanner() {\n banners[currentActive].classList.remove(\"active\"); // remove class from current active banner\n\n currentActive++; // increment active slide\n\n if (currentActive === banners.length) {\n currentActive = 0; // reset active to 0 if last banner is active\n }\n\n banners[currentActive].classList.add(\"active\"); // add active to next slide\n} .active {\n color: red;\n} <div class=\"slider\">\n <div class=\"banner active\" id=\"sky\">1</div>\n <div class=\"banner\" id=\"outdoor\">2</div>\n <div class=\"banner\" id=\"photo\">3</div>\n</div>"
},
{
"answer_id": 74600435,
"author": "Abhishek Kokate",
"author_id": 17349359,
"author_profile": "https://Stackoverflow.com/users/17349359",
"pm_score": 0,
"selected": false,
"text": "\n let currIndex = 0;\n setInterval(changebanner, 8000);\n \n function changebanner() {\n let banners = document.getElementsByClassName(\"banner\");\n let activeBanner = document.getElementByClassName(\"active\");\n activeBanner.classList.remove('active')\n if(currIndex >= banners.length){\n currIndex = 0;\n }\n banners[currIndex].classList.add('active')\n currIndex++;\n }\n\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20622668/"
] |
74,600,215
|
<p>I have a requirement to insert new records and delete this record 3 months after created date.
I will create a new table.
I want that query will create the table as well as auto delete the records which are more than 3 months of the created date.</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600215",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2278863/"
] |
74,600,252
|
<p>I am using on a new project Laravel 9 / Livewire 2.1 / Jquery 3.6.1 / and LivewireAlert from jantinnerezo from here: <a href="https://github.com/jantinnerezo/livewire-alert" rel="nofollow noreferrer">https://github.com/jantinnerezo/livewire-alert</a>
I am using an adminPanel dashboard for showing nice menus and so on from here: <a href="https://themewagon.com/themes/celestial-free-responsive-bootstrap-4-admin-dashboard-template/" rel="nofollow noreferrer">https://themewagon.com/themes/celestial-free-responsive-bootstrap-4-admin-dashboard-template/</a>
I've included into my project only necessary things like css and js files from the admin-dashboard - but it seems to conflict with the Livewire alert Css or Js and I have no idea where to look at.
My problem is:</p>
<ul>
<li><p>if I include a livewire component to my blade file and in this livewire component there is a button which calls a function lets say so: wire:click="testSwal"</p>
<pre><code> public function testSwal(){
$this->alert('info', 'Abgebrochen', [
'position' => 'top-end',
// 'timer' => 3000,
'toast' => true,
// 'timerProgressBar' => true,
]);
</code></pre>
</li>
</ul>
<p>this works as expected I can see the toast notification and everything is fine.
But if I try to show a message after saving a model or doing other stuff and redirecting afterwards to another page example:</p>
<pre><code>public function cancelOperation() {
$this->alert('info', 'Abgebrochen', [
'position' => 'top-end',
// 'timer' => 3000,
'toast' => true,
// 'timerProgressBar' => true,
]);
return redirect()->to('/admin/companies');
}
</code></pre>
<p>It redirects me to the page and I can see for half a second or less :( the notification top-right.
The same happens if I try to call the alert in the mount() function of the component - it only works if I click a button :(
I can see in Chrome developer tools that the swal class and so on is added to the html tag for this half second and then removed. I have no errors at all in console. So my question is how can I find out which js/css is causing this issue - I have no idea where to start.
Thank you.</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7527669/"
] |
74,600,257
|
<p>Good morning, I'm trying to make an ATM, I'm having a problem, I do not know how to save in the database the new information I'm entering.</p>
<pre><code>decimal deposit = 0;
Console.WriteLine("\n Quanto deseja depositar ?"); //Ask how much the client want deposit
deposit = decimal.Parse(Console.ReadLine());
decimal value = depositarOperacao(debitCard, pin); /*goes to the database for the amount that the customer has in the account*/
decimal saldoAtual = value + deposit; /*calculation of the sum of the balance plus the deposit to give the current balance*/
Console.WriteLine("\n O seu saldo atual é de " + saldoAtual + " euro(s) \n Depósito: " + deposit + " euro(s)");
saldoAtual = updateSaldo(debitCard, pin, saldoAtual);
</code></pre>
<pre><code>private static decimal updateSaldo(string numeroCartao, string pin, decimal saldoAtual)
{
return getDbSaldo($@"UPDATE atmbd.atm Balance='{saldoAtual}' WHERE Pin='{pin}' AND CardNumber = '{numeroCartao}'");
}
private static decimal getDbUpdate(string query)
{
using (var cn = new SqlConnection("Data Source=MAD-PC-023;Database=atmbd;Trusted_Connection=True;"))
{
cn.Open();
using (var cmd = new SqlCommand() { Connection = cn, CommandText = query })
{
var reader = cmd.ExecuteReader();
if (reader.Read() == true)
{
return reader.GetDecimal(0);
}
else
{
return 0;
}
}
}
}
</code></pre>
<p>Now I have to put something save the current balance in the database in case the customer deposits more money add to the current balance.</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20571251/"
] |
74,600,275
|
<p>I want to use a azure SQL Database and want connect to it via ip-adress.</p>
<p>My current setup:</p>
<ol>
<li>Azure Database e.g. "example.database.windows.net"</li>
<li>Private Link in Azure Subnet connected with the database (10.231.1.5)</li>
<li>Azure Win VM (10.231.1.4)</li>
</ol>
<p>When I open SSMS on my Windows VM, I can't connect to the private link database via IP-Address. It only works with the FQDN.
The error message is "Cannot open Server "10.231.1.5" requested by login"
Does somebody knows why?</p>
<p>In the future I want to use a P2S VPN to my local Subnet, there I dont have these Azure DNS entries.
Is it possible to make a Azure Database work only with the private IP-Address?
Otherwise I have to tell the IT-Support that they have to configure internal DNS to use a Azure DNS for Zone *.windows.net.
Is there a best practice how DNS Zones can be linked to local?</p>
<p>I don't want the database to be reached via public IP, so all connections must use the private link.</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4975457/"
] |
74,600,315
|
<p>I am using express to add/update/delete the data on MongoDB. Good think is its working fine.</p>
<p><strong>Updated</strong></p>
<pre><code>function UpData(chk, _action, up){
Employee.updateOne( chk ,{ _action : up})
.then(data => {
if (!data) {
res.status(404).send({
message: `Cannot update Employee with id=${id}. Maybe Employee was not found!`
});
} else res.send({ message: "Absence is added successfully." });
})
.catch(err => {
res.status(500).send({
message: "Error updating Employee with id=" + id
});
});
}
</code></pre>
<p>This isn't working, ca anybody help if I doing any mistake with syntax?</p>
<p>I guess the issue action, when I tried add console.log in function before update:</p>
<pre><code>console.log( chk ,{ _action : up})
console.log(_action)
</code></pre>
<p>Output:</p>
<pre><code>{ _id: '691fa64', 'absences.ab_id': 'MEk' } { _action: { 'absences.$.ab_comments': { comment: 'K1' } } }
$push
</code></pre>
<p><strong>The question</strong> why in both console.log action value $push didnt print?</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20412540/"
] |
74,600,319
|
<p>I have a basic MongoDB Atlas trigger in NodeJS :</p>
<pre><code>exports = function(changeEvent) {
// Make an http request
};
</code></pre>
<p>My goal is to call an AWS lambda function from this trigger, so i would like to know the syntax to make a basic <code>GET</code> request to a specific endpoint from the NodeJS code.</p>
<p>EDIT :</p>
<p>I am unable to run axios, the dependency is indeed installed but the <code>get</code> method doesn't seem to exist.</p>
<p><a href="https://i.stack.imgur.com/kHK8G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kHK8G.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11665178/"
] |
74,600,340
|
<p>Im trying to create a search bar type filter within shadow dom as follows</p>
<pre><code>const root = mainContainer.attachShadow({ mode: "open" });
var filter = root.getElementById("myInput"), // search box
list = root.querySelectorAll(".clubguests-card"); // all list items
// (B) ATTACH KEY UP LISTENER TO SEARCH BOX
filter.onkeyup = () => {
// (B1) GET CURRENT SEARCH TERM
let search = filter.value.toLowerCase();
// (B2) LOOP THROUGH LIST ITEMS - ONLY SHOW THOSE THAT MATCH SEARCH
for (let i of list) {
let item = i.className.toLowerCase();
console.log(item);
if (item.indexOf(search) == -1) { i.classList.add("hide"); }
else { i.classList.remove("hide"); }
}
}
</code></pre>
<p>The console is showing that the classes are added/removed, but the display is not affected.</p>
<p>If I use document.querySelectorAll(".clubguests-card") it works fine.</p>
<p>IS there a way of making this work within the shadow dom?</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11868530/"
] |
74,600,376
|
<p>I Am trying to write one query.</p>
<p>Below is the query ritten till now.</p>
<pre><code>@Query(value = "select cn from CapNumber cn " +
"WHERE (:#{#request.number} = '' OR cn.number LIKE CONCAT('%',:#{#request.number},'%')) " +
"AND (:#{#request.name} IS '' OR cn.name LIKE CONCAT('%',:#{#request.name},'%') )" +
"AND (:#{#request.smsStatus} IS '' OR cn.smsStatus = :#{#request.smsStatus} )" +
"AND (:#{#request.internalId} IS '' OR cn.internalId LIKE CONCAT('%',:#{#request.internalId},'%') )")
Page<CapNumber> search(NumbersRequest request, Pageable pageable);
</code></pre>
<p>No as per current query if smsStatus is '' I am getting all the records and data if I am passing correct keyword.</p>
<p>Now I want all the records in which smsStatus is null, Not able to figure out How can i do that. I know I have to use IS NULL with CASE but somehow what I tried is not working.</p>
<p>Can someone please help</p>
|
[
{
"answer_id": 74604830,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": "https://Stackoverflow.com/users/5298879",
"pm_score": 0,
"selected": false,
"text": "CREATE EXTENSION pg_cron;\n\n-- Delete old data daily at 3:30am (GMT)\nSELECT cron.schedule(\n 'delete outdated records',\n '30 3 * * *', \n $$ DELETE FROM new_table WHERE created_date < now()-'3 months'::interval $$\n ); \n cron # weekdays at 01:00am\n# min hour mday month wday command-to-run\n0 1 * * 1-5 psql -h dbhost -p 5432 -U dbuser --dbname dbname < my.sql\n -('3 months'::interval-'1 day'::interval) create table new_table (data text, created_date timestamp default now());\ninsert into new_table (data) values ('value1');\n\nalter table new_table rename to new_table_raw;\n\ncreate view new_table as \nselect * from new_table_raw where created_date>now()-'3 months'::interval;\n\n--insert, update, delete still work even though it's a view now\ninsert into new_table (data) values ('value2');\ndelete from new_table where data='value2';\nupdate new_table set data='value3' where data='value1';\n cron pg_cron NOTIFY LISTEN at schtasks at now + 3 months -f delete_older_than_3_months_using_psql.sh\n delete pop() with\n test_dates(example) as\n( values\n ('2023.01.01'::date),\n ('2023.02.01'::date),\n ('2024.02.01'::date),--leap year\n ('2023.03.01'::date))\nselect example, (example + '90 days'::interval)::date as \"date 90 days later\"\nfrom test_dates;\n-- example | date 90 days later\n--------------+--------------------\n-- 2023-01-01 | 2023-04-01\n-- 2023-02-01 | 2023-05-02\n-- 2024-02-01 | 2024-05-01 --leap year\n-- 2023-03-01 | 2023-05-30\n with \n test_dates(example) as \n( values \n ('2023.01.01'::timestamp),\n ('2023.02.01'::timestamp),\n ('2024.02.01'::timestamp),--leap year\n ('2023.03.01'::timestamp),\n ('2023.04.01'::timestamp),\n ('2023.05.01'::timestamp),\n ('2023.06.01'::timestamp) )\nselect example, example + '3 months'::interval - example as \"3 months length in days\"\nfrom test_dates;\n-- example | 3 months length in days\n-----------------------+-------------------------\n-- 2023-01-01 00:00:00 | 90 days\n-- 2023-02-01 00:00:00 | 89 days\n-- 2024-02-01 00:00:00 | 90 days --leap year\n-- 2023-03-01 00:00:00 | 92 days\n-- 2023-04-01 00:00:00 | 91 days\n-- 2023-05-01 00:00:00 | 92 days\n-- 2023-06-01 00:00:00 | 92 days\n select '01-31-2023'::timestamp + '1 month';--2023-02-28 00:00:00\nselect '02-28-2023'::timestamp + '1 month';--2023-03-28 00:00:00\nselect '02-29-2024'::timestamp + '1 month';--2024-03-29 00:00:00 --leap year\nselect '03-31-2023'::timestamp + '1 month';--2023-04-30 00:00:00\n at $ echo \"command\" | at \"00:00 013123\" + 1 month\njob 14 at Fri Mar 3 00:00:00 2023\n$ echo \"command\" | at \"00:00 022823\" + 1 month\njob 15 at Tue Mar 28 00:00:00 2023\n$ echo \"command\" | at \"00:00 022924\" + 1 month #leap year\njob 16 at Tue Mar 29 00:00:00 2024\n$ echo \"command\" | at \"00:00 033123\" + 1 month\njob 17 at Mon May 1 00:00:00 2023\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4210210/"
] |
74,600,377
|
<p>I would like to know if I can perform operations on some numbers straight in the file without</p>
<p>the need to read them. I wrote this code to check if a file is sorted but I had to read them</p>
<p>first into a vector and then check if the vector is sorted or not but then I figured that this</p>
<p>code might be inefficient since I had to make few extra steps. this is the code:</p>
<p>// method to check if the numbers are already sorted:</p>
<pre><code>bool number_sorted(vector <int> vector){
bool is_sorted = true;
for(int i = 0; i < vector.size(); i++){
for(int j = i + 1; j < vector.size(); j++){
if(vector[i] > vector[j]){
is_sorted = false;
cout << vector[i] << " and " << vector[j] << " are in the wrong order" << endl;
}
}
}
return is_sorted;
}
</code></pre>
<p>// method to sort the numbers:</p>
<pre><code>vector <int> sort(vector <int> vector){
for(int i = 0; i < vector.size(); i++){
for(int j = i + 1; j < vector.size(); j++){
if(vector[i] > vector[j]){
int temp = vector[i];
vector[i] = vector[j];
vector[j] = temp;
}
}
}
return vector;
}
</code></pre>
<p>// Main methdod:</p>
<pre><code>int main(){
vector <int> list;
fstream fs;
fs.open("/Users/brah79/Downloads/skola/c++/inlämningsuppgiter/number1.txt");
bool is_sorted = number_sorted(list);
if(is_sorted){
cout << "the list of numbers is sorted" << endl;
}
else{
sort(list);
}
</code></pre>
<p>as you can see everything is performed on a vector first but I want to make the check and the</p>
<p>sorting straight on the file. Hope I made myself clear</p>
|
[
{
"answer_id": 74600662,
"author": "Marek R",
"author_id": 1387438,
"author_profile": "https://Stackoverflow.com/users/1387438",
"pm_score": 2,
"selected": false,
"text": "vector bool areIntsInStreamSorted(std::istream& in)\n{\n return std::is_sorted(std::istream_iterator<int>{in}, {}) && in.eof();\n}\n\nbool areIntsInFileSorted(std::filesystem::path p)\n{\n std::ifstream in{p};\n return areIntsInStreamSorted(in);\n}\n"
},
{
"answer_id": 74600815,
"author": "463035818_is_not_a_number",
"author_id": 4117728,
"author_profile": "https://Stackoverflow.com/users/4117728",
"pm_score": 1,
"selected": false,
"text": "bool number_sorted(vector <int> vector){\n bool is_sorted = true;\n for(int i = 0; i < vector.size(); i++){\n for(int j = i + 1; j < vector.size(); j++){\n if(vector[i] > vector[j]){\n is_sorted = false; \n cout << vector[i] << \" and \" << vector[j] << \" are in the wrong order\" << endl; \n }\n }\n } \n return is_sorted;\n}\n vector[i] j > i vector[i] vector[j] vector[i] vector[j] i vector[i] > vector[i+1]\n"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20431658/"
] |
74,600,389
|
<p>I have a variable <code>result</code> that contains around 1M entries, which looks like this:</p>
<pre><code>result = [
{
'name': 'x',
'other fields': '...',
},
{
'name': 'y',
'other fields': '...',
},
.. and so on ..
]
</code></pre>
<p>I want to create another array that only contains a list of names but in object format:</p>
<pre><code>nameArray = [
{name: 'x'},
{name: 'y'},
.. and so on ..
]
</code></pre>
<p>I am currently using the following loop, but it is extremely slow for 1M entries</p>
<pre><code>let nameArray = []
result.forEach(item => {
let name = {name : item.name}
nameArray.push(name)
});
</code></pre>
<p>What would be the fastest way to achieve this? I also tried lodash maps but still a little slow. But I would prefer not using lodash since it adds one more dependency.</p>
|
[
{
"answer_id": 74600478,
"author": "Aramil Rey",
"author_id": 4187849,
"author_profile": "https://Stackoverflow.com/users/4187849",
"pm_score": 0,
"selected": false,
"text": "for .. of forEach const namesResults = []\nfor (const { name } of result) {\n namesResults.push(name)\n}\n .reduce .map"
},
{
"answer_id": 74600616,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 1,
"selected": false,
"text": "var arr=[]\nfor (let i=0;i<1000000; i++) arr.push({name:\"id\"+i, a:\"abc\", b:\"def\"+i});\nconsole.log(\"input data created\", arr.length);\n\n// method 1: Array.map\n// ====================\nlet time=new Date().getTime();\nconst res=arr.map(({name})=>({name}));\ntime=new Date().getTime() - time;\nconsole.log(`Method 1 (.map) in ${time}ms , res:`, JSON.stringify(res.slice(0,10)));\n\n// method 2: while loop\n// =====================\nconst names = [];\narr=arr.reverse()\nlet i = arr.length;\ntime = new Date().getTime();\nwhile (i--) names.push({name: arr[i].name});\ntime = new Date().getTime() - time;\nconsole.log(`Method 2 (while) in ${time}ms , res:`, JSON.stringify(names.slice(0,10)));"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768337/"
] |
74,600,429
|
<p>Hello guys i wanna write a Shell script that runs Python code saved in variable called $code.</p>
<p>So i save the script in variable <code>$code</code> with this command:</p>
<pre><code>$ export CODE='print("Hello world")'
</code></pre>
<p>To resolve the problem
I write the following script in a file called run:</p>
<pre><code>#!/bin/bash
echo "$CODE" > main.py
python3 main.py
</code></pre>
<p>To running the shell script i use:</p>
<pre><code>./run
</code></pre>
<p>and its work but
I found another answer which I don't understand:</p>
<pre><code>python3 <<< $CODE
</code></pre>
<p>so what do we mean by using <code><<<</code>?</p>
|
[
{
"answer_id": 74600750,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 0,
"selected": false,
"text": "<<< echo \"$PYCODE\" | python3\n"
},
{
"answer_id": 74600760,
"author": "alexisdevarennes",
"author_id": 2973474,
"author_profile": "https://Stackoverflow.com/users/2973474",
"pm_score": 1,
"selected": false,
"text": "<<< <<< $ python3 <<< 'print(\"hi there\")'\nhi there\n << command <<MultiLineDoc \nStandard Input\nThat\n Streches many\nLines and preserves \n indentation and \n\nlinebreaks\n\nwhich is useful for passing many arguments to a command, \ne.g. passing text to a program and preserving its indentation.\nThe beginning and ending _MultiLineDoc_ delimiter can be named any way wanted, \nit can be considered the name of the document. \nImportant is that it repeats identically at \nboth beginning and end and nowhere else in the \ndocument, everything between that delimiter is passed.\nMultiLineDoc\n < command < filename.txt |"
}
] |
2022/11/28
|
[
"https://Stackoverflow.com/questions/74600429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20170267/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.