qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,282,669 | <p>Any help with PHP to convert the below, taking into consideration the time zone at the end, to UNIX epoch for MYSQL insert.</p>
<p>29/05/2022 22:23:04 +00:00</p>
<p>No examples of attempts :-/ Tried basic <code>strtotime</code> on it's own.</p>
| [
{
"answer_id": 74282928,
"author": "Zak",
"author_id": 1507691,
"author_profile": "https://Stackoverflow.com/users/1507691",
"pm_score": 0,
"selected": false,
"text": "+0:00"
},
{
"answer_id": 74283151,
"author": "RobIII",
"author_id": 215042,
"author_profile": "https://Stackoverflow.com/users/215042",
"pm_score": 3,
"selected": true,
"text": "$unixtime = DateTime::createFromFormat('d/m/Y H:i:s P', '29/05/2022 22:23:04 +00:00')->getTimestamp();\n\necho $unixtime;\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1844960/"
] |
74,282,694 | <p>I've read through <a href="https://kubernetes.io/docs/concepts/containers/images/" rel="nofollow noreferrer">this page</a> and I'm interested in where Kubernetes downloads an image to and how long it stores it for.</p>
<p>For example, let's say we have a large 3GB image. When i start up a pod will the image be downloaded to disk of the node the pod is being deployed to, and remain until that node is destroyed? If so does that mean i could allocate only 400MB of memory to a pod that is using a 3GB image?</p>
| [
{
"answer_id": 74282928,
"author": "Zak",
"author_id": 1507691,
"author_profile": "https://Stackoverflow.com/users/1507691",
"pm_score": 0,
"selected": false,
"text": "+0:00"
},
{
"answer_id": 74283151,
"author": "RobIII",
"author_id": 215042,
"author_profile": "https://Stackoverflow.com/users/215042",
"pm_score": 3,
"selected": true,
"text": "$unixtime = DateTime::createFromFormat('d/m/Y H:i:s P', '29/05/2022 22:23:04 +00:00')->getTimestamp();\n\necho $unixtime;\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7525684/"
] |
74,282,695 | <p>I get database table which contain postal numbers and regions for my country. That table have all information but i need to change it for my purpose.</p>
<p>I need to eliminate all rows that have duplicate content in specific column.</p>
<p><strong>Check screenshot to see result</strong>
<a href="https://i.stack.imgur.com/CHOHC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CHOHC.png" alt="enter image description here" /></a></p>
<p>I want to remove all duplicate rows which have <strong>postanski_broj</strong> (postal_number) the some. That number need to be unique. I try manualy to set that column to unique but i get duplicate entry when i try to execute statment.</p>
<ul>
<li>ID is primary key with auto increment.</li>
<li>postanski_broj column is VARCHAR which represent postal_code</li>
<li>naselje column is VARCHAR which represent region</li>
</ul>
<p>One region can have one postal_code</p>
<p><strong>I try</strong></p>
<pre><code>ALTER TABLE poste ADD UNIQUE INDEX idx_postanski_br (postanski_broj);
</code></pre>
<blockquote>
<p>00:03:20 ALTER TABLE poste ADD UNIQUE INDEX idx_postanski_br
(postanski_broj) Error Code: 1062. Duplicate entry '11158' for key
'idx_postanski_br' 0.118 sec</p>
</blockquote>
<pre><code>ALTER IGNORE TABLE poste ADD UNIQUE INDEX idx_postanski_br (postanski_broj);
</code></pre>
<blockquote>
<p>00:04:17 ALTER IGNORE TABLE poste ADD UNIQUE INDEX idx_postanski_br
(postanski_broj) Error Code: 1064. You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'IGNORE TABLE poste ADD UNIQUE INDEX
idx_postanski_br (postanski_broj)' at line 1 0.00037 sec</p>
</blockquote>
<p>Anyone have sugestion? Thanks</p>
| [
{
"answer_id": 74282928,
"author": "Zak",
"author_id": 1507691,
"author_profile": "https://Stackoverflow.com/users/1507691",
"pm_score": 0,
"selected": false,
"text": "+0:00"
},
{
"answer_id": 74283151,
"author": "RobIII",
"author_id": 215042,
"author_profile": "https://Stackoverflow.com/users/215042",
"pm_score": 3,
"selected": true,
"text": "$unixtime = DateTime::createFromFormat('d/m/Y H:i:s P', '29/05/2022 22:23:04 +00:00')->getTimestamp();\n\necho $unixtime;\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2040496/"
] |
74,282,738 | <p>I have 16 variables arranged in a 4 by 4 grid.
My goal is to make a function that can assigns a random number between 0 and 4 to every variables, with no duplicates in each column and each row - like a sudoku.</p>
<p>Each method I've tried results in duplicates. For example:</p>
<pre><code>column_A = [A1, A2, A3, A4]
column_B = [B1, B2, B3, B4]
column_C = [C1, C2, C3, C4]
column_D = [D1, D2, D3, D4]
row_1 = [A1, B1, C1, D1]
row_2 = [A2, B2, C2, D2]
row_3 = [A3, B3, C3, D3]
row_4 = [A4, B4, C4, D4]
all_rows = [row_1, row_2, row_3, row_4]
all_columns = [column_A, column_B, column_C, column_D]
def random_grid():
for i in range(len(all_rows)):
all_columns[i] = sample([0, 1, 2, 3, 4], 4)
all_rows[i] = sample([0, 1, 2, 3, 4], 4)
</code></pre>
<p>doesn't work
How could I do this?</p>
| [
{
"answer_id": 74282804,
"author": "Pranav Hosangadi",
"author_id": 843953,
"author_profile": "https://Stackoverflow.com/users/843953",
"pm_score": 2,
"selected": false,
"text": "[[1, 2, 3, 4],\n [4, 1, 2, 3],\n [3, 4, 1, 2],\n [2, 3, 4, 1]]\n"
},
{
"answer_id": 74282930,
"author": "kosciej16",
"author_id": 3361462,
"author_profile": "https://Stackoverflow.com/users/3361462",
"pm_score": 0,
"selected": false,
"text": "from random import sample\n\ndef check(matrix, size=4):\n return check_rows(matrix, size) and check_cols(matrix, size)\n\ndef check_rows(matrix, size=4):\n return all(len(set(matrix[i])) == size for i in range(size))\n\ndef check_cols(matrix, size=4):\n transposed = [[matrix[j][i] for j in range(size)] for i in range(size)]\n return check_rows(transposed, size)\n\ndef generate(size=4):\n return [sample(range(5), size) for _ in range(size)]\n\nwhile True:\n matrix = generate()\n if check(matrix):\n break\n\nprint(matrix)\n"
},
{
"answer_id": 74282934,
"author": "Swifty",
"author_id": 20267366,
"author_profile": "https://Stackoverflow.com/users/20267366",
"pm_score": 1,
"selected": false,
"text": "from random import choice\n\nnumbers = {0,1,2,3,4}\n\na=[[],[],[],[]]\n\nfor i in range(4):\n for j in range(4):\n available = list(numbers - set(a[i][:j]) - {a[x][j] for x in range(i)})\n a[i].append(choice(available))\n \nprint(a)\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19912330/"
] |
74,282,744 | <p>I have access to the top level tkinter window, but when I do:</p>
<pre><code>self._root = tk.Tk()
<snip>
x = 10 # in screen coordinates
y = 20 # in screen coordinates
self._root.event_generate('<Button-1>', x=x, y=y)
self._root.event_generate('<ButtonRelease-1>', x=x, y=y)
</code></pre>
<p>I expect the button click to be applied to the widget underneath location x,y on the window. In this example a Button.</p>
<p>My understanding is event_generate places an event on the message queue inside tkinter just like a real mouse click would do. Normally clicking anywhere inside a window or a frame, causes the click to go through the top-level panes until it finds a widget with a bind() associated with it, i.e. a Button.</p>
<p>And so using that I should be able to simulate a button click anywhere on the window without moving the actual mouse.</p>
<p>But it doesn't do anything, no click, no error, no anything.</p>
<p>What am I missing?</p>
| [
{
"answer_id": 74282960,
"author": "Bryan Oakley",
"author_id": 7432,
"author_profile": "https://Stackoverflow.com/users/7432",
"pm_score": 2,
"selected": true,
"text": "event_generate"
},
{
"answer_id": 74297271,
"author": "JohnA",
"author_id": 1935424,
"author_profile": "https://Stackoverflow.com/users/1935424",
"pm_score": 0,
"selected": false,
"text": "# the top level window\nself._root = tk.Tk() \n<snip>\nx = 10 # in screen coordinates\ny = 20 # in screen coordinates\n\n# get a reference to the widget in the root window that is\n# underneath coordinate x,y\nw = self._root.winfo_containing(x, y)\n\n# Note: the <Enter> is necessary. Without it the \n# button events don't do anything.\nw.event_generate('<Enter>', x=x, y=y)\nw.event_generate('<Button-1>', x=x, y=y)\nw.event_generate('<ButtonRelease-1>', x=x, y=y)\n\n# The invoke() also works.\n# w.invoke()\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282744",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1935424/"
] |
74,282,756 | <p>I have a problem with my code, I am supposed to import a list from a .txt file, each line in the txt file has two item, name and city for example</p>
<pre><code>Alex###London
Justin###Texas
</code></pre>
<p>I have a code that imports this list from the txt file into the listBox1 but I can not split Alex and London. My class is User and I want to add Alex to name and London to City.
this is the code I use but it doesnt work</p>
<pre><code>List<User> userList = new List<User>();
var charArray = listBox1.Text.Split('#' + "#" + "#");
string Name = charArray[0];
string City = charArray[1];
User user = new User(Name, City);
userList.Add(user);
</code></pre>
| [
{
"answer_id": 74282960,
"author": "Bryan Oakley",
"author_id": 7432,
"author_profile": "https://Stackoverflow.com/users/7432",
"pm_score": 2,
"selected": true,
"text": "event_generate"
},
{
"answer_id": 74297271,
"author": "JohnA",
"author_id": 1935424,
"author_profile": "https://Stackoverflow.com/users/1935424",
"pm_score": 0,
"selected": false,
"text": "# the top level window\nself._root = tk.Tk() \n<snip>\nx = 10 # in screen coordinates\ny = 20 # in screen coordinates\n\n# get a reference to the widget in the root window that is\n# underneath coordinate x,y\nw = self._root.winfo_containing(x, y)\n\n# Note: the <Enter> is necessary. Without it the \n# button events don't do anything.\nw.event_generate('<Enter>', x=x, y=y)\nw.event_generate('<Button-1>', x=x, y=y)\nw.event_generate('<ButtonRelease-1>', x=x, y=y)\n\n# The invoke() also works.\n# w.invoke()\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19197001/"
] |
74,282,776 | <p>I've been working on a to do list for my web dev studies with The Odin Project. My assignment is to create a to-do app and I chose the composite design pattern to do after a lot of struggle with my previous messy code. So far so good but one of my button oddly doesn't trigger the arrow function I prepared for it. I said oddly cause I've got a very similar approach for another button the works perfectly. The only difference I feel it's causing this issue is an assignment to a button for the let's call it root of this tree structure (session.js class). document.getElementById effectively finds the specific button in the document and the addEventListener trigger a alert for example if there's no arrow function involved. Can anyone lend me a hand with this please?</p>
<p>The problem is in the addEventListener inside the if statement inside the addChild function of the following class</p>
<pre><code>import Component from './component.js';
export default class Container extends Component{
child;
constructor(){
super();
}
addChild(id, parentId){
alert(id);
alert(parentId);
document.getElementById(parentId).appendChild(document.createElement('div'));
document.getElementById(parentId).lastChild.id = id;
document.getElementById(parentId).lastChild.innerHTML = this.child.innerHTML;
document.getElementById(parentId).lastChild.className = this.child.className;
if(document.getElementById(id).className!='check-list'){
document.getElementById(id).innerHTML+="<button id='"+id+"-add-button'></button>";
document.getElementById(id+'-add-button').addEventListener('click', ()=>{
this.child.addChild(this.parentNode.id);
});
}
document.getElementById(id).innerHTML+="<button id='"+id+"-remove-button'></button>";
document.getElementById(id+'-remove-button').addEventListener('click', ()=>{
document.getElementById(id).parentNode.removeChild(document.getElementById(id));
});
let inputs = document.getElementById(parentId).getElementsByClassName('input');
for(let i=0; i<inputs.length; ++i){
inputs[i].addEventListener('input', ()=>{
inputs[i].dataset.storage = inputs[i].value;});
}
}
}
</code></pre>
<p>Container class inherits from Component class</p>
<pre><code>export default class Component{
className;
innerHTML;
constructor(){
}
}
</code></pre>
<p>And Session class is the only class that, if I can call it override in this case the same event</p>
<pre><code>import Project from "./project.js";
import Container from "./container.js";
export default class Session extends Container{
constructor(username){
super();
this.username = username;
this.child = new Project();
this.innerHTML = ["<div id='"+this.username+"-session' class='session' data-checklist='' data-card='' data-list='' data-project''>",
"<H1>Call it a day!</H1>",
"<button id='session-add-button'>Add Project</button>",
"<button id='logout'>Log out</button>",
"</div>"].join("");
document.body.innerHTML = this.innerHTML;
document.getElementById('session-add-button').addEventListener('click', ()=>{
this.addChild(this.username+"-session");
})
}
addChild(parentId){
super.addChild(Project.getId(), parentId);
++Project.count;
}
}
</code></pre>
<p>BTW Project class is Session class child so you guys can picture the whole flow in your minds</p>
<pre><code>import Container from "./container";
import List from "./list";
export default class Project extends Container {
static count=0;
static getId(){
return 'P-'+Project.count;
}
constructor(){
super();
this.child = new List();
this.className = 'project';
this.innerHTML = ["<input class='input' data-storage='' type='text' placeholder='Project title'></input>"].join("");
}
addChild(parentId){
super.addChild(List.getId(), parentId);
++List.count;
}
}
</code></pre>
<p>I've checked already if the button inside that if in the container.js script is found as well as declare a function without the arrow function. I've also tried to find the difference between this add button that has issues with the remove button and I can't see anything that I'm doing wrong in terms of typing or syntax.</p>
| [
{
"answer_id": 74282824,
"author": "Fraser",
"author_id": 74861,
"author_profile": "https://Stackoverflow.com/users/74861",
"pm_score": 0,
"selected": false,
"text": "this"
},
{
"answer_id": 74282974,
"author": "Mark Schultheiss",
"author_id": 125981,
"author_profile": "https://Stackoverflow.com/users/125981",
"pm_score": 1,
"selected": false,
"text": "addEventListener('click', (event) => {});"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20302906/"
] |
74,282,784 | <p>I have an Ansible playbook which is supposed to replace some characters using stream editor.</p>
<pre><code>sed -i "s+foo+$(<replace_file)+g" some_file
</code></pre>
<p>or</p>
<pre><code>sed -i "s/foo/$(<replace_file)/g" some_file
</code></pre>
<p>cat some_file</p>
<pre><code>line one: foo
</code></pre>
<p>cat replace_file</p>
<pre><code>bar
</code></pre>
<p>expected result</p>
<pre><code>line one: bar
</code></pre>
<p>actual result</p>
<pre><code>line one: $(<bar)
</code></pre>
<p>I have tried the command directly on Ubuntu distro and it works perfectly, but running the command through Ansible gives the error.</p>
| [
{
"answer_id": 74285208,
"author": "tripleee",
"author_id": 874188,
"author_profile": "https://Stackoverflow.com/users/874188",
"pm_score": 2,
"selected": false,
"text": "sh"
},
{
"answer_id": 74286018,
"author": "Kevin C",
"author_id": 4834431,
"author_profile": "https://Stackoverflow.com/users/4834431",
"pm_score": 1,
"selected": false,
"text": "- shell: sed -i \"s+foo+$(<replace_file)+g\" some_file\n args:\n executable: /bin/bash\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12136403/"
] |
74,282,811 | <p>Currently I have setup a dynamic path for <code>/gallery/:id</code> that works fine. But now the children path of <code>/admin/gallery</code> doesn't load anymore. Only when I remove the dynamic one again.</p>
<pre><code>import { RouteRecordRaw } from "vue-router";
const routes: RouteRecordRaw[] = [
{
path: "/admin",
name: "admin",
meta: {
title: "Admin Panel",
enforceLogin: true,
},
redirect: "/admin/welcome",
component: () => import("@/views/AdminView.vue"),
children: [
{
path: "welcome",
name: "welcome",
meta: {
title: "Admin Panel",
enforceLogin: true,
},
component: () => import("@/views/admin/WelcomeInfo.vue"),
},
{
path: "gallery",
name: "gallery",
meta: {
title: "Galerie Administration",
enforceLogin: true,
},
component: () => import("@/views/admin/GalleryAdministration.vue"),
},
],
},
{
path: "/gallery/:id",
name: "gallery",
meta: {
title: "Galerie",
},
component: () => import("@/views/GalleryView.vue"),
},
];
export default routes;
</code></pre>
<p>I've also created a new vue-cli project and tested it there, still doesn't seem to work. I've noticed something weird while testing. If I move the <code>/gallery/:id</code> above the <code>/admin</code> route, the <code>/admin/gallery</code> route works again. So I think the route that comes first, gets overwritten.</p>
<h2>How to reproduce</h2>
<p>I've created a small guide for reproduction <a href="https://gist.github.com/Nevah5/5453df59d5b7c6315c85afe103ecb227" rel="nofollow noreferrer">here</a>.</p>
| [
{
"answer_id": 74282941,
"author": "kburakdemirci",
"author_id": 13312738,
"author_profile": "https://Stackoverflow.com/users/13312738",
"pm_score": 0,
"selected": false,
"text": "redirect: \"/admin/welcome\",\n"
},
{
"answer_id": 74289999,
"author": "Mocha_",
"author_id": 17466049,
"author_profile": "https://Stackoverflow.com/users/17466049",
"pm_score": 1,
"selected": false,
"text": "/gallery/:id"
},
{
"answer_id": 74313198,
"author": "Nevah5",
"author_id": 16029189,
"author_profile": "https://Stackoverflow.com/users/16029189",
"pm_score": 1,
"selected": true,
"text": "/admin/gallery"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16029189/"
] |
74,282,875 | <p>So, I'm a beginner to Pandas and I'm having a little trouble getting something to work.</p>
<p>My task is that I was given a dataframe as follows:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>AnimalID</th>
<th>Pet Name</th>
<th>Pet Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Whiskers</td>
<td>Cat</td>
</tr>
<tr>
<td>2</td>
<td>Charlie</td>
<td>Dog</td>
</tr>
<tr>
<td>3</td>
<td>Spot</td>
<td>Dog</td>
</tr>
<tr>
<td>4</td>
<td>Honey</td>
<td>Cat</td>
</tr>
</tbody>
</table>
</div>
<p>What I'm attempting to do is add a '+' symbol to the end of the ID if the pet type is a dog.</p>
<p>My solution was to iterate through each row using iterrows() and check if the Pet Type Matches, and if it does, change the ID in that row. My code is below:</p>
<pre><code>import pandas as pd
#df = pd.read_excel('AnimalList.xlsx')
df = pd.DataFrame({'AnimalID':[1,2,3,4], 'Pet Name':['Whiskers', 'Charlie', 'Spot', 'Honey'], 'Pet Type':['Cat', 'Dog', 'Dog', 'Cat']})
for row in df.iterrows():
if row['Pet Type'].eq('Dog').any():
row['AnimalID'] = df['AnimalID'].astype(str) + '+'
df
</code></pre>
<p>The dataframe is printing without error, but is there any reason that nothing is changing? I have to be missing something obvious. Thank you.</p>
| [
{
"answer_id": 74282941,
"author": "kburakdemirci",
"author_id": 13312738,
"author_profile": "https://Stackoverflow.com/users/13312738",
"pm_score": 0,
"selected": false,
"text": "redirect: \"/admin/welcome\",\n"
},
{
"answer_id": 74289999,
"author": "Mocha_",
"author_id": 17466049,
"author_profile": "https://Stackoverflow.com/users/17466049",
"pm_score": 1,
"selected": false,
"text": "/gallery/:id"
},
{
"answer_id": 74313198,
"author": "Nevah5",
"author_id": 16029189,
"author_profile": "https://Stackoverflow.com/users/16029189",
"pm_score": 1,
"selected": true,
"text": "/admin/gallery"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7443826/"
] |
74,282,877 | <p>Cloudflare's docs and <a href="https://blog.cloudflare.com/workers-javascript-modules/" rel="nofollow noreferrer">blog posts</a> clearly state they support JavaScript code in their Workers, but I can't find any way to add JavaScript or access the editor?</p>
<p>Specifically I'm trying to build a maintenance page via their Workers API, following <a href="https://www.resdevops.com/2018/03/20/cloudflare-workers-maintenance-mode-static-page/" rel="nofollow noreferrer">this (rather old) guide</a>.</p>
<p>I've been looking for a half hour now and can't find any way to add JS code to Workers for my life. Can anyone point me in the right direction?</p>
| [
{
"answer_id": 74282967,
"author": "Michael M.",
"author_id": 13376511,
"author_profile": "https://Stackoverflow.com/users/13376511",
"pm_score": 2,
"selected": true,
"text": "Quick Edit"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6025788/"
] |
74,282,893 | <p>Trying to create a collapsible segment on a webpage and so far have just tried the examples from W3 schools: <a href="https://www.w3schools.com/howto/howto_js_collapsible.asp" rel="nofollow noreferrer">https://www.w3schools.com/howto/howto_js_collapsible.asp</a>. When I click the 'current' button the div does not become expanded.</p>
<p>I understand that the button tag needs to be directly next to the section to be collapsed, which I have. By playing around with the Inspect feature on my browser, it looks like the content.style.display setting is not being set properly on a click, as manually toggling it produces the desired effect. I looked at similar questions which suggested using this.parentNode.nextElementSibling instead of this.nextElementSibling, but this just produced the same behaviour. Does the location of the tag matter? Below is a snippet of the code - in essence just the code from the W3 website.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const coll = document.getElementsByClassName("collapsible");
let i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
let content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.collapsible {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
.content {
padding: 0 18px;
overflow: hidden;
background-color: white;
background-color: #f1f1f1;
}
.active, .collapsible:hover {
background-color: #ccc;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><button type="button" class="collapsible">current</button>
<div class="content">
<p>Lorem ipsum...</p>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74282967,
"author": "Michael M.",
"author_id": 13376511,
"author_profile": "https://Stackoverflow.com/users/13376511",
"pm_score": 2,
"selected": true,
"text": "Quick Edit"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12838568/"
] |
74,282,905 | <p>I have a dictionary in this form:</p>
<pre><code>example ={'2020_01': {'PM0001': 1088, 'CA00006': 33, 'X00002': 125, 'J00009': 119, 'A0000S': 524},
'2020_02': {'F00067': 3, 'P00001': 1104, 'X00002': 98, 'J0009': 36, 'A0000S': 539},
'2020_03': {'P00001': 1200, 'Z78800': 45,'X00000': 84,'NK0000': 4,'A0000S': 577,'V000000':11}}
</code></pre>
<p>I would like to extract a second dict including only values in the second dictionary nested which keys comply with a certain rule. this rule is given by a function.</p>
<pre><code>def rule(string):
# this is an hipythetical rule which in reality is way more complicated.
if string.startswith("P") or string.startswith("X"):
if string[1] == "0":
return True
return False
</code></pre>
<p>Using for loops I am able to perform the operation as follows:</p>
<pre><code>new_dict={}
for date,ussage in example.items():
new_sub_dict = {key:value for key,value in ussage.items() if rule(key)==True}
new_dict[date] = new_sub_dict
new_dict
</code></pre>
<p>The question is if it is possible to rewrite that with one liner.</p>
| [
{
"answer_id": 74282967,
"author": "Michael M.",
"author_id": 13376511,
"author_profile": "https://Stackoverflow.com/users/13376511",
"pm_score": 2,
"selected": true,
"text": "Quick Edit"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7168098/"
] |
74,282,920 | <p>I have a variable called data and I would like to remove "//x00" from all of them if they have it. How would I go about doing so? I thought of iterating through all of them and checking each individually, but...</p>
<pre><code>data = ["b'$VNYMR", '-103.322', '-003.191', '-018.818', '+00.0183', '+00.0107', '+00.50\\x0075', '-00.553', '+03.138', '-09.272', '+00.000038', '-00.000815', "+00.000183*6F\\x00\\r\\n'"]
for x in data:
data[x] = data[x].replace('\\x00', '')
</code></pre>
| [
{
"answer_id": 74282954,
"author": "Acacia Ackles",
"author_id": 15222209,
"author_profile": "https://Stackoverflow.com/users/15222209",
"pm_score": 1,
"selected": false,
"text": "for x in data"
},
{
"answer_id": 74283184,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "new_data = [i.replace(\"\\\\x00\", \"\") for i in data]\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7838536/"
] |
74,282,979 | <p>I want to use string interpolation on an SF Symbol that has a <code>rotationEffect(_:anchor:)</code> modifier applied to it. Is it possible to do this?</p>
<p>Without the modifier this type of string interpolation works fine (in Swift 5.0):</p>
<pre><code>struct ContentView: View {
var body: some View {
Text("Some text before \(Image(systemName: "waveform.circle")) plus some text after.")
}
}
</code></pre>
<p>But applying the modifier like this:</p>
<pre><code>struct ContentView: View {
var body: some View {
Text("Some text before \(Image(systemName: "waveform.circle").rotationEffect(.radians(.pi * 0.5))) plus some text after.")
}
}
</code></pre>
<p>doesn't compile and gives this error:</p>
<blockquote>
<p>Instance method 'appendInterpolation' requires that 'some View' conform to '_FormatSpecifiable'</p>
</blockquote>
| [
{
"answer_id": 74282954,
"author": "Acacia Ackles",
"author_id": 15222209,
"author_profile": "https://Stackoverflow.com/users/15222209",
"pm_score": 1,
"selected": false,
"text": "for x in data"
},
{
"answer_id": 74283184,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "new_data = [i.replace(\"\\\\x00\", \"\") for i in data]\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14670348/"
] |
74,282,988 | <p>There is a record in the Salesforce Stay Information which has the following information. "Booked_Check_in_Date_Time__c": "2022-11-05T00:59:00Z"</p>
<p>When I try the following oData filter it does not work.
Booked_Check_in_Date_Time__c eq 2022-11-05</p>
<p>What do I need to change to bring back this record.</p>
| [
{
"answer_id": 74282954,
"author": "Acacia Ackles",
"author_id": 15222209,
"author_profile": "https://Stackoverflow.com/users/15222209",
"pm_score": 1,
"selected": false,
"text": "for x in data"
},
{
"answer_id": 74283184,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "new_data = [i.replace(\"\\\\x00\", \"\") for i in data]\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74282988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581658/"
] |
74,283,001 | <p>I'm having trouble logging into the server to do the authentication tests for my JWT password token, it claims problem</p>
<p>no " required:jwt({"</p>
<p>grateful to whoever helps me
<a href="https://i.stack.imgur.com/SIszf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SIszf.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/kzUeg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kzUeg.png" alt="enter image description here" /></a></p>
<p>user side of authentication
<a href="https://i.stack.imgur.com/bohpJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bohpJ.png" alt="enter image description here" /></a></p>
<p>I tried changing the commas but the problem persisted I believe it is something deeper</p>
| [
{
"answer_id": 74282954,
"author": "Acacia Ackles",
"author_id": 15222209,
"author_profile": "https://Stackoverflow.com/users/15222209",
"pm_score": 1,
"selected": false,
"text": "for x in data"
},
{
"answer_id": 74283184,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "new_data = [i.replace(\"\\\\x00\", \"\") for i in data]\n"
}
] | 2022/11/01 | [
"https://Stackoverflow.com/questions/74283001",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20374647/"
] |
74,283,012 | <p>I am trying to split diffrent lines of text in python. I tried to use the split function and it dosent work for what I want. here is an example.
`</p>
<pre><code>list = open(file,"r")
for Password in passlist:
print(list)
</code></pre>
<p>`</p>
<p>and I want it to give this output:
<code>number 1</code>
and
<code>number 2</code></p>
| [
{
"answer_id": 74283100,
"author": "Oktu",
"author_id": 15815140,
"author_profile": "https://Stackoverflow.com/users/15815140",
"pm_score": 0,
"selected": false,
"text": "passlist = open(\"file\" ,\"r\")\nx = passlist.read().split(\", \") <--- change to the format you use to save the passwords \nprint(x)\n"
},
{
"answer_id": 74283120,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "# Open the file (in read mode)\nfile = open(file, \"r\")\n\n# Read the file and split at every new line\n# The 'split()' function will return a list\ncontent = file.read().split(\"\\n\")\n\n# Close the file\nfile.close()\n\n# Now each line should be in the list\nprint(content)\n\n# Save the two variables by unpacking the list\nnum1, num2 = content\n"
},
{
"answer_id": 74283763,
"author": "CobraCabbe",
"author_id": 17170174,
"author_profile": "https://Stackoverflow.com/users/17170174",
"pm_score": 0,
"selected": false,
"text": "With open(\"file\", \"r\") as f:\n contents=f.read()\n print(contents)\n\n \n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20392316/"
] |
74,283,030 | <p>I am trying to create a new column which is a calculation between 2 other columns in my df, one column if a value and the other column if the % of the first column i wish to appear in my new column. Should be a bit easier to explain with my data;</p>
<pre><code>df
Country_Name gdp_per_capita Agriculture_GDP%
1 Albania 3281. 20.6
2 Algeria 3515. 9.86
3 Bosnia and Herzegovina 3828. 8.21
4 Croatia 11285. 3.90
5 Cyprus 24686. 2.60
</code></pre>
<p>So I want to create a new column with the value for Albania to be 20.6% of 3281 here which would be 675.8</p>
<p>I had an attempt at this my dividing the 1st column by the second but it gave me some wrong results;</p>
<pre><code>df$gdp_per_capita_agg_percen = df$gdp_per_capita/bar_df$Agriculture_GDP%
</code></pre>
| [
{
"answer_id": 74283100,
"author": "Oktu",
"author_id": 15815140,
"author_profile": "https://Stackoverflow.com/users/15815140",
"pm_score": 0,
"selected": false,
"text": "passlist = open(\"file\" ,\"r\")\nx = passlist.read().split(\", \") <--- change to the format you use to save the passwords \nprint(x)\n"
},
{
"answer_id": 74283120,
"author": "Darragh",
"author_id": 20392744,
"author_profile": "https://Stackoverflow.com/users/20392744",
"pm_score": -1,
"selected": false,
"text": "# Open the file (in read mode)\nfile = open(file, \"r\")\n\n# Read the file and split at every new line\n# The 'split()' function will return a list\ncontent = file.read().split(\"\\n\")\n\n# Close the file\nfile.close()\n\n# Now each line should be in the list\nprint(content)\n\n# Save the two variables by unpacking the list\nnum1, num2 = content\n"
},
{
"answer_id": 74283763,
"author": "CobraCabbe",
"author_id": 17170174,
"author_profile": "https://Stackoverflow.com/users/17170174",
"pm_score": 0,
"selected": false,
"text": "With open(\"file\", \"r\") as f:\n contents=f.read()\n print(contents)\n\n \n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18338223/"
] |
74,283,041 | <p>I have a pg file when I open it in Windows 7 I notice that it contains many images in one file.</p>
<p>Currently using python I'm trying to count the number of images inside this file or extract them but I can't find anything about pg files.</p>
<p>When I used an online converter, all the images were extracted and uploaded to a ZIP file
I'm trying to use the same thing but using Python but only get one image.</p>
<p><strong>Note:</strong> I used the pillow library (there is only one file 1.pg for example)</p>
<pre><code>from PIL import Image
img = Image.open('1.pg')
rgb_img = img.convert('RGB')
rgb_img.save('image.jpg')
</code></pre>
| [
{
"answer_id": 74283995,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 1,
"selected": false,
"text": "seek"
},
{
"answer_id": 74286408,
"author": "Mark Setchell",
"author_id": 2836621,
"author_profile": "https://Stackoverflow.com/users/2836621",
"pm_score": 0,
"selected": false,
"text": "OPENTEXT CORPORATION"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16165474/"
] |
74,283,073 | <p>Hello stack overflow community.</p>
<p>Wondering if you can help me with this.</p>
<p>I want to get the available storage space on a computer system and export it to a variable.</p>
<p>I know the command below will give me the available storage on a system.
export HOME=<code>cd;pwd</code>
df -H --output=avail ${HOME}</p>
<p>But it gives me a header of Avail</p>
<pre><code>Avail
891G
</code></pre>
<p>I only want the <code>891G</code> to be exported as a string into a variable.</p>
<p>I tried this command below but it didn't work</p>
<pre><code>df -H --output=avail ${HOME} | awk -F"\n" '{print$1}'
</code></pre>
<p>Any thoughts?</p>
| [
{
"answer_id": 74283124,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 1,
"selected": true,
"text": "$ df -H --output=avail ${HOME} | awk 'NR==2'\n 39G\n"
},
{
"answer_id": 74286248,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 0,
"selected": false,
"text": "awk -F\"\\n\" '{print $1}'\n"
},
{
"answer_id": 74310425,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": -1,
"selected": false,
"text": "jot 100 | mawk '_--{exit}_+=NR'\n\n2\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19557344/"
] |
74,283,077 | <p>I have a strange issue where my jquery menu comes up just fine the first time, but if the menu was closed by clicking outside the menu, it won't come up again until the browser is refreshed. Please help.</p>
<p>The following will show the menu only the first time until page is refreshed:</p>
<pre><code>document.getElementById("selectCourse").style.display = "block";
document.getElementById("selectCourse").style.display = "none";
</code></pre>
<p>The following will show the menu the first time, then will show subsequently for a brief moment then disappear:</p>
<pre><code>$("#selectCourse").show("fast");
$("#selectCourse").hide("fast");
</code></pre>
<hr />
<pre><code>function wSelect() {
var name = "#selectCourse";
var menuYloc = null;
//document.getElementById("selectCourse").style.display = "block"; // Display menu
$("#selectCourse").show("fast");
$(document).ready(function() {
menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
$(window).scroll(function () {
offset = menuYloc+$(document).scrollTop()+"px";
$(name).animate({top:offset},{duration:500,queue:false});
});
$("html").click(function() {
//document.getElementById("selectCourse").style.display = "none";
$("#selectCourse").hide("fast");
});
});
}
</code></pre>
<hr />
<pre><code><div id="selectCourse">
<div id="floatMenu">
<p>Select a Course</p>
<ul id="choices" class="menu">
<li>
<a href="course1.html" onlick="return true;">
<img src="course1.png" height="40">Course 1</a>
</li>
<li>
<a href="course2.html" onlick="return true;">
<img src="course2.png" height="40">Course 2</a>
</li>
</ul>
</div>
</div>
</code></pre>
<hr />
<pre><code>#selectCourse {
display: none;
width: 300px;
}
#floatMenu {
position: absolute;
background-color: #0078d0;
border: 1px solid #000;
top: 80px;
right: 10%;
margin: 5px;
}
#floatMenu ul {
margin: 20px 30px 20px 0;
font-size: 16px;
list-style-type: none;
}
#floatMenu ul li a {
display: flex;
align-items: center;
text-decoration: none;
color: #ccc;
padding: 5px 10px;
}
#floatMenu ul li a:hover {
color:#fff;
background-color:#333333;
}
/*
#floatMenu ul.menu li a:hover {
border-left: 4px solid #f09;
}
*/
#floatMenu p {
color: #ffffff;
text-align: left;
margin-left: 40px;
font-size: 18px;
}
</code></pre>
| [
{
"answer_id": 74283124,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 1,
"selected": true,
"text": "$ df -H --output=avail ${HOME} | awk 'NR==2'\n 39G\n"
},
{
"answer_id": 74286248,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 0,
"selected": false,
"text": "awk -F\"\\n\" '{print $1}'\n"
},
{
"answer_id": 74310425,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": -1,
"selected": false,
"text": "jot 100 | mawk '_--{exit}_+=NR'\n\n2\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283077",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3078682/"
] |
74,283,099 | <p>This is my html:</p>
<pre><code><input type="text" class="form-control mt-3" placeholder="Item name" aria-label="Item name" required>
<input type="file" class="form-control mt-3" required>
<button type="button" class="btn btn-danger mt-3 w-100 removeItem">Remove item</button>
</code></pre>
<p>This is my JS:</p>
<pre><code>document.querySelector('.container').addEventListener('click', (e) => {
if (e.target.classList.contains('removeItem')) {
// e.target.insertAdjacentHTML('beforebegin', 'test');
console.log(e.target.parentNode)
}
});
addItemBtn.addEventListener("click", (e) => {
if (createBinModalForm.checkValidity()) {
addItemBtn.insertAdjacentHTML('beforebegin', '<hr/>');
addItemBtn.insertAdjacentHTML('beforebegin', `
<input type="text" class="form-control mt-3" placeholder="Item name" aria-label="Item name" required>
<input type="file" class="form-control mt-3" required>
<button type="button" class="btn btn-danger mt-3 w-100 removeItem">Remove item</button>
`);
}
})
</code></pre>
<p>How can I use this JavaScript to remove the three elements before the target button is clicked but. not anything else?</p>
| [
{
"answer_id": 74283124,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 1,
"selected": true,
"text": "$ df -H --output=avail ${HOME} | awk 'NR==2'\n 39G\n"
},
{
"answer_id": 74286248,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 0,
"selected": false,
"text": "awk -F\"\\n\" '{print $1}'\n"
},
{
"answer_id": 74310425,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": -1,
"selected": false,
"text": "jot 100 | mawk '_--{exit}_+=NR'\n\n2\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20392761/"
] |
74,283,102 | <p>I am working on a project with React for the first time. What I am trying to do is send a Child component's value that is within an input field to a variable in its Parent. More precisely, I would like the value to be transmitted whenever the value in the input field is changed. Here is a basic overview of what I have (simplified):</p>
<pre><code>const Parent = () => {
const handleSubmit = (e) => {
e.preventDefault();
// Series of variables to hold the values from Child2
}
return (
<div>
<form onSubmit={handleSubmit}>
<div>
<Child1 name="child1"/>
<Child1 name="child2"/>
</div>
<button>Submit</button>
</form>
</div>
);
}
const Child1 = () => {
return (
<div>
<Child2 name="childchild1"/>
<Child2 name="childchild2"/>
<Child2 name="childchild3"/>
</div>
);
}
const Child2 = () => {
return (
<div>
<input type="number" .......></input>
</div>
);
}
</code></pre>
<p>In brief, my goal is to have the values from the input fields in the component Child2 to be transmitted to some array of values in Parent. That being said, I have looked at multiple ways of lifting up values in React online, but I haven't found something similar to my scenario. What would be the best way of proceeding? Thanks!</p>
| [
{
"answer_id": 74283152,
"author": "titleLogin",
"author_id": 17223188,
"author_profile": "https://Stackoverflow.com/users/17223188",
"pm_score": 1,
"selected": true,
"text": "const Parent = () => {\n \n const handleSubmit = (e) => {\n e.preventDefault();\n // Series of variables to hold the values from Child2\n }\n \n const getDataFromParent=(data)=>{\n console.log('DATA from Child2', data)\n }\n\n return (\n <div>\n <form onSubmit={handleSubmit}>\n <div>\n <Child1 name=\"child1\" handleGetDataFromParent={getDataFromParent}/>\n <Child1 name=\"child2\" handleGetDataFromParent={getDataFromParent}/>\n </div>\n <button>Submit</button>\n </form>\n </div>\n );\n}\n\nconst Child1 = ({handleGetDataFromParent}) => {\n \n return (\n <div>\n <Child2 name=\"childchild1\" handleGetDataFromParent={handleGetDataFromParent}/>\n <Child2 name=\"childchild2\" handleGetDataFromParent={handleGetDataFromParent}/>\n <Child2 name=\"childchild3\" handleGetDataFromParent={handleGetDataFromParent}/>\n </div>\n );\n}\n\nconst Child2 = ({handleGetDataFromParent}) => {\n\n const setNumber=(number)=>{\n handleGetDataFromParent(number)\n }\n\n return (\n <div>\n <input type=\"number\" onChange={(n)=>setNumber(n)}.......></input>\n </div>\n );\n}\n"
},
{
"answer_id": 74283363,
"author": "Chandra Raditya",
"author_id": 20330404,
"author_profile": "https://Stackoverflow.com/users/20330404",
"pm_score": 1,
"selected": false,
"text": "import { createContext, useContext } from \"react\";\n\nconst UserContext = createContext();\n\nconst Parent = () => {\n const handleSubmit = (e) => {\n e.preventDefault();\n // Series of variables to hold the values from Child2\n };\n\n const handleInput = (data) => {\n console.log(`this is data ${data.target.value}`);\n };\n\n return (\n <UserContext.Provider value={handleInput}>\n <div>\n <form onSubmit={handleSubmit}>\n <div>\n <Child1 name=\"child1\" />\n <Child1 name=\"child2\" />\n </div>\n <button>Submit</button>\n </form>\n </div>\n </UserContext.Provider>\n );\n};\n\nconst Child1 = () => {\n return (\n <div>\n <Child2 name=\"childchild1\" />\n <Child2 name=\"childchild2\" />\n <Child2 name=\"childchild3\" />\n </div>\n );\n};\n\nconst Child2 = () => {\n const handleInput = useContext(UserContext);\n\n return (\n <div>\n <input type=\"number\" onChange={(e) => handleInput(e)}></input>\n </div>\n );\n};\n\nexport default Parent;\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10993416/"
] |
74,283,108 | <p>So, I have this array of objects called "characters" (currently only 3 objects, but it's supposed to be much more) and I want to filter through this array with a function (or an array method) and for example: return every character's name, who is <code>character.bodyType: "tall"</code> or has <code>character.element: "fire"</code> AND is also <code>character.weapon: "sword"</code> user, based on how many parameter values I pass to the function.</p>
<p>I wrote a function "isThere" that takes 4 params max but I want to be able to call it with any number of values less than four and get the names based on only those parameter values. Let's say I want to display only the names of characters who are both tall and male. The result should be <code>['Igneus']</code> but instead I get <code>[ 'Renna', 'Igneus', 'Igneus', 'Dagon' ]</code> and I couldn't figure out the logic for it to only filter the ones that met both requirements and skipped duplicates and those that met only one of them.
If I want to see the names of "sword" characters only, the result should be <code>["Renna" , "Igneus]</code>... and so on and so forth.</p>
<p>My code is clearly unfinished and wrong, I tried several different approaches with if statements, this is just where I stopped. If it is possible to do with an array method, that's short and clean, I'll take it. I tried Array.filter() method but I just didn't know how to implement a 4 parameter function in it, or if it'spossible at all.</p>
<pre><code>const characters = [
{
bodyType: "tall",
element: "air",
gender: "female",
name: "Renna",
weapon: "sword",
},
{
bodyType: "tall",
element: "fire",
gender: "male",
name: "Igneus",
weapon: "sword",
},
{
bodyType: "medium",
element: "water",
gender: "male",
name: "Dagon",
weapon: "spear",
},
];
function isThere(body, element, gender, weapon) {
const arr = [];
for (const char of characters) {
if (char.bodyType === body) {
arr.push(char.name)
}
if(char.element === element){
arr.push(char.name)
}
if(char.gender === gender){
arr.push(char.name)
}
if(char.weapon === weapon){
arr.push(char.name)
}
}
return arr;
}
isThere("tall", undefined, "male", undefined)
</code></pre>
| [
{
"answer_id": 74283135,
"author": "caTS",
"author_id": 18244921,
"author_profile": "https://Stackoverflow.com/users/18244921",
"pm_score": 1,
"selected": false,
"text": "(typeof ... !== \"undefined\" ? ... : ...)"
},
{
"answer_id": 74283194,
"author": "Adam",
"author_id": 954940,
"author_profile": "https://Stackoverflow.com/users/954940",
"pm_score": 1,
"selected": false,
"text": "const characters = [\n {\n bodyType: \"tall\",\n element: \"air\",\n gender: \"female\",\n name: \"Renna\",\n weapon: \"sword\",\n },\n {\n bodyType: \"tall\",\n element: \"fire\",\n gender: \"male\",\n name: \"Igneus\",\n weapon: \"sword\",\n },\n {\n bodyType: \"medium\",\n element: \"water\",\n gender: \"male\",\n name: \"Dagon\",\n weapon: \"spear\",\n },\n];\n\n\nconst partialMatch = (object) => (character) => Object.entries(object).every(([key,value]) => character[key] === value)\n\nconst myMatchingCharacters = characters.filter(partialMatch({bodyType:'tall',gender:'male'}))\n\nconsole.log(myMatchingCharacters.map(({name}) => name))"
},
{
"answer_id": 74283615,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 0,
"selected": false,
"text": "filter"
},
{
"answer_id": 74284908,
"author": "Ro Milton",
"author_id": 1909499,
"author_profile": "https://Stackoverflow.com/users/1909499",
"pm_score": 1,
"selected": true,
"text": "const characters=[{bodyType:\"tall\",element:\"air\",gender:\"female\",name:\"Renna\",weapon:\"sword\"},{bodyType:\"tall\",element:\"fire\",gender:\"male\",name:\"Igneus\",weapon:\"sword\"},{bodyType:\"medium\",element:\"water\",gender:\"male\",name:\"Dagon\",weapon:\"spear\"}];\n\nconst isThere = (...args) => \n characters.filter(char => \n ['bodyType', 'element', 'gender', 'weapon'].every((key, index) =>\n args[index] === undefined || args[index] === char[key]\n )\n )\n .map(({ name }) => name);\n\nconsole.log(isThere(\"tall\", undefined, \"male\", undefined));\nconsole.log(isThere(undefined, undefined, undefined, \"sword\"));"
},
{
"answer_id": 74285314,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 0,
"selected": false,
"text": "const characters = [\n {\n bodyType: \"tall\",\n element: \"air\",\n gender: \"female\",\n name: \"Renna\",\n weapon: \"sword\",\n },\n {\n bodyType: \"tall\",\n element: \"fire\",\n gender: \"male\",\n name: \"Igneus\",\n weapon: \"sword\",\n },\n {\n bodyType: \"medium\",\n element: \"water\",\n gender: \"male\",\n name: \"Dagon\",\n weapon: \"spear\",\n },\n];\n\nconst matched = characters.filter((crits=> pers => crits.every(([k,v]) => pers[k] === v))([['bodyType','tall'],['weapon','sword']]))\n\nconsole.log(matched.map(({name}) => name))"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20392423/"
] |
74,283,113 | <p>I've a Vue project buit with vite.</p>
<p>While debbuging the app, everything works ok.</p>
<p>But when i build it to production, and try to open it with preview, the chrome windows hangs loading forever.</p>
<p>Nothing is show on console. Is there anyway to capture the error?</p>
<p>Looks like it's stuck in a forever loop.</p>
<p><strong>Edit</strong></p>
<p><strong>package.json</strong></p>
<pre class="lang-json prettyprint-override"><code>{
"name": "vue-project",
"version": "0.0.0",
"scripts": {
"dev": "npm run build:icons && vite --host --port 5050",
"build": "npm run build:icons && vue-tsc --noEmit && vite build",
"preview": "vite preview --port 5050",
"typecheck": "vue-tsc --noEmit",
"lint": "eslint src -c .eslintrc.js --fix --rulesdir eslint-internal-rules/ --ext .ts,.js,.vue,.tsx,.jsx",
"build:icons": "tsc -b src/@iconify && node src/@iconify/build-icons.js"
},
"dependencies": {
"@casl/ability": "^6.2.0",
"@casl/vue": "^2.2.0",
"@codemirror/highlight": "^0.19.8",
"@codemirror/lang-html": "^6.1.2",
"@codemirror/lang-javascript": "^6.1.0",
"@codemirror/lang-json": "^6.0.0",
"@codemirror/lint": "^6.0.0",
"@codemirror/theme-one-dark": "^6.1.0",
"@floating-ui/dom": "1.0.0",
"@formkit/auto-animate": "^1.0.0-beta.3",
"@mdi/font": "^7.0.96",
"@vueuse/core": "^8.9.4",
"apexcharts-clevision": "^3.28.5",
"axios": "^0.27.2",
"axios-mock-adapter": "^1.21.2",
"buffer": "^6.0.3",
"chart.js": "^3.9.1",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"pinia": "^2.0.22",
"prismjs": "^1.29.0",
"sass": "^1.54.9",
"unplugin-vue-define-options": "^0.6.2",
"uuid": "^9.0.0",
"vue": "3.2.41",
"vue-chartjs": "^4.1.1",
"vue-codemirror": "^6.1.1",
"vue-flatpickr-component": "^10.0.0",
"vue-i18n": "^9.2.2",
"vue-prism-component": "^2.0.0",
"vue-router": "^4.1.6",
"vue3-apexcharts": "^1.4.1",
"vue3-perfect-scrollbar": "^1.6.0",
"vuetify": "^3.0.0",
"webfontloader": "^1.6.28"
},
"devDependencies": {
"@antfu/eslint-config-vue": "^0.25.2",
"@fullcalendar/core": "^5.11.3",
"@fullcalendar/daygrid": "^5.11.3",
"@fullcalendar/interaction": "^5.11.3",
"@fullcalendar/list": "^5.11.3",
"@fullcalendar/timegrid": "^5.11.3",
"@fullcalendar/vue3": "^5.11.2",
"@iconify-json/mdi": "^1.1.33",
"@iconify/tools": "^2.1.0",
"@iconify/vue": "^3.2.1",
"@intlify/vite-plugin-vue-i18n": "^5.0.1",
"@types/lodash": "^4.14.186",
"@types/node": "^18.7.18",
"@types/uuid": "^8.3.4",
"@types/webfontloader": "^1.6.34",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"@vitejs/plugin-vue": "^3.1.0",
"@vitejs/plugin-vue-jsx": "^2.0.1",
"eslint": "^8.23.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-sonarjs": "^0.14.0",
"eslint-plugin-vue": "^9.5.1",
"postcss-html": "^1.5.0",
"stylelint": "^14.12.0",
"stylelint-config-idiomatic-order": "^8.1.0",
"stylelint-config-standard-scss": "^5.0.0",
"stylelint-use-logical-spec": "^4.1.0",
"type-fest": "^2.19.0",
"typescript": "^4.8.3",
"unplugin-auto-import": "^0.10.3",
"unplugin-vue-components": "^0.21.2",
"vite": "^3.2.2",
"vite-plugin-pages": "^0.27.1",
"vite-plugin-vue-layouts": "^0.7.0",
"vite-plugin-vuetify": "1.0.0",
"vue-tsc": "^1.0.9"
},
"packageManager": "yarn@1.22.18",
"resolutions": {
"postcss": "8",
"stylelint-order": "5",
"postcss-sorting": "^7.0.1"
}
}
</code></pre>
<p><strong>output of build</strong></p>
<pre class="lang-bash prettyprint-override"><code>╭─ ♥ 22:14 | E: code
╰─ npm run build
> vue-project@0.0.0 build
> npm run build:icons && vue-tsc --noEmit && vite build
> vue-project@0.0.0 build:icons
> tsc -b src/@iconify && node src/@iconify/build-icons.js
Bundled icons from E:\_Development\_repos\hiperstream\hiperstreamCloudPlatform\cloud-platform\code\node_modules\@iconify-json\mdi\icons.json
Saved src/@iconify/icons-bundle.js (2848016 bytes)
vite v3.2.2 building for production...
transforming (253) node_modules\vuetify\lib\composables\ssrBoot.mjs[plugin:vite:esbuild] Duplicate key "key" in object literal
50 | ? _withDirectives((_openBlock(), _createBlock(_resolveDynamicComponent(_unref(config).app.enableI18n ? 'i18n-t' : 'span'), _mergeProps({
51 | key: 0,
52 | key: "badge",
| ^
53 | class: ["nav-item-badge", __props.item.badgeClass]
54 | }, _unref(dynamicI18nProps)(__props.item.badgeContent, 'span')), {
✓ 1193 modules transformed.
dist/assets/avatar-1.aac046b6.png 15.96 KiB
dist/assets/avatar-2.0ae005f8.png 22.59 KiB
dist/assets/pose-f-28.a182fba0.png 9.21 KiB
dist/assets/pose-f-3.a3617bf1.png 8.31 KiB
dist/assets/mac-pc.4e376c3f.png 140.24 KiB
dist/assets/pose-f-39.43496c42.png 6.65 KiB
dist/assets/pose-m-14.a95cbb6a.png 5.87 KiB
dist/assets/pose-m-5.d7160542.png 6.80 KiB
dist/assets/pose-m-34.cb61966e.png 7.35 KiB
dist/assets/avatar-3.3ef9169b.png 11.57 KiB
dist/assets/avatar-4.406ee6ab.png 20.73 KiB
dist/assets/avatar-5.bad78850.png 18.35 KiB
dist/assets/avatar-6.3bc22d4b.png 18.22 KiB
dist/assets/avatar-7.8807e18e.png 18.07 KiB
dist/assets/avatar-8.942ae414.png 16.39 KiB
dist/assets/auth-v2-login-illustration-bordered-dark.1621a082.png 67.92 KiB
dist/assets/auth-v2-login-illustration-bordered-light.5efb7928.png 64.49 KiB
dist/assets/auth-v2-login-illustration-dark.c163247b.png 67.13 KiB
dist/assets/auth-v2-login-illustration-light.c910569c.png 68.40 KiB
dist/assets/paypal.8c1354c3.svg 2.24 KiB
dist/assets/illustration-1.20d12d31.png 12.84 KiB
dist/assets/illustration-2.042b082c.png 11.76 KiB
dist/assets/pose-fs-9.c6abbba4.png 28.74 KiB
dist/assets/sitting-girl-with-laptop-dark.aa688fe5.png 9.07 KiB
dist/assets/sitting-girl-with-laptop-light.bd520dbb.png 9.82 KiB
dist/assets/card-meetup.c5ffac4a.png 195.24 KiB
dist/assets/html5.ff3e7cf8.png 4.78 KiB
dist/assets/python.1d56c267.png 4.16 KiB
dist/assets/react.52bd27c0.png 5.31 KiB
dist/assets/vue.33fa8801.png 4.07 KiB
dist/assets/xamarin.d2086975.png 4.08 KiB
dist/assets/chrome.391a2294.png 7.47 KiB
dist/assets/american-express.2c04e485.png 8.14 KiB
dist/assets/knowledge-base-bg-dark.9e1eb36c.png 29.65 KiB
dist/assets/pricing-tree-1.61561baa.png 4.86 KiB
dist/assets/pricing-tree-3.7c67f762.png 5.59 KiB
dist/index.html 1.07 KiB
dist/assets/useGenerateImageVariant.ec010ed6.js 0.58 KiB / gzip: 0.27 KiB
dist/assets/VCard.b6709399.js 9.07 KiB / gzip: 2.06 KiB
dist/assets/VAlert.c1a0a22c.js 5.83 KiB / gzip: 1.70 KiB
dist/assets/webfontloader.b777d690.js 19.47 KiB / gzip: 5.78 KiB
dist/assets/VForm.45e996af.js 1.47 KiB / gzip: 0.61 KiB
dist/assets/VCheckbox.e52cedcf.js 1.67 KiB / gzip: 0.64 KiB
dist/assets/login.e1da9684.js 23.87 KiB / gzip: 8.25 KiB
dist/assets/blank.c23886c7.js 0.36 KiB / gzip: 0.24 KiB
dist/assets/VWindow.74c52ec5.js 9.08 KiB / gzip: 2.56 KiB
dist/assets/VWindowItem.f856cfbe.js 3.54 KiB / gzip: 1.11 KiB
dist/assets/VTabs.dffdacbb.js 20.22 KiB / gzip: 4.81 KiB
dist/assets/VTable.d527e358.js 1.56 KiB / gzip: 0.62 KiB
dist/assets/AppPricing.63e41703.js 14.20 KiB / gzip: 6.06 KiB
dist/assets/useInvoiceStore.3f404cbb.js 0.75 KiB / gzip: 0.36 KiB
dist/assets/sitting-girl-with-laptop-light.2ab0b492.js 0.25 KiB / gzip: 0.14 KiB
dist/assets/useLayoutsStore.7257820e.js 1.61 KiB / gzip: 0.62 KiB
dist/assets/VContainer.cf5a234e.js 0.52 KiB / gzip: 0.30 KiB
dist/assets/VTimelineItem.c57c8a72.js 7.16 KiB / gzip: 1.81 KiB
dist/assets/vue.runtime.esm-bundler.e5a66098.js 5.45 KiB / gzip: 1.89 KiB
dist/assets/index.21f4736b.js 42.20 KiB / gzip: 7.63 KiB
dist/assets/VTextarea.51d5864e.js 9.17 KiB / gzip: 2.56 KiB
dist/assets/_id_.30711c66.js 31.52 KiB / gzip: 4.48 KiB
dist/assets/index.aac33ec4.js 0.89 KiB / gzip: 0.46 KiB
dist/assets/index.9ba56bbe.js 28.73 KiB / gzip: 4.65 KiB
dist/assets/DefaultTabCrudLayout.vue_vue_type_script_setup_true_lang.c9f21d22.js 2.76 KiB / gzip: 0.97 KiB
dist/assets/DefaultCrudTabCardAccordionContentLayout.vue_vue_type_script_setup_true_lang.4411eb1b.js 5.70 KiB / gzip: 1.18 KiB
dist/assets/index.93a7da00.js 0.91 KiB / gzip: 0.47 KiB
dist/assets/VExpansionPanel.a3e74888.js 8.09 KiB / gzip: 2.00 KiB
dist/assets/pricing.3cf2db40.js 17.59 KiB / gzip: 2.80 KiB
dist/assets/Layout.vue_vue_type_script_setup_true_lang.59dd5321.js 39.91 KiB / gzip: 7.26 KiB
dist/assets/DefaultCrudTabCardAccordionContentLayout.a1cdd194.js 0.42 KiB / gzip: 0.23 KiB
dist/assets/faq.76ac9c5f.js 12.59 KiB / gzip: 2.88 KiB
dist/assets/DefaultCrudTabContentVCardLayout.ee966228.js 1.09 KiB / gzip: 0.51 KiB
dist/assets/DefaultVCardLayout.vue_vue_type_script_setup_true_lang.c0c59562.js 2.17 KiB / gzip: 0.78 KiB
dist/assets/DefaultLayoutWithHorizontalNav.fd6f082f.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultLayoutWithVerticalNav.e139d247.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultTabCrudLayout.df749d43.js 0.31 KiB / gzip: 0.18 KiB
dist/assets/NavBarI18n.8a521c1b.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultVCardLayout.dfa4f164.js 0.31 KiB / gzip: 0.17 KiB
dist/assets/NavBarNotifications.d9e7daac.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/NavbarThemeSwitcher.c87d20bf.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/UserProfile.8b5cee81.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/login.21c684c6.css 0.62 KiB / gzip: 0.26 KiB
dist/assets/VCardCrudTabContentLayout.abe161c0.js 1.66 KiB / gzip: 0.63 KiB
dist/assets/VAlert.12d954e1.css 4.68 KiB / gzip: 1.17 KiB
dist/assets/VCard.782c479c.css 6.74 KiB / gzip: 1.52 KiB
dist/assets/blank.21020790.css 0.06 KiB / gzip: 0.07 KiB
dist/assets/VCheckbox.de0921d5.css 0.13 KiB / gzip: 0.12 KiB
dist/assets/_tab_.960e3200.css 0.43 KiB / gzip: 0.24 KiB
dist/assets/VTabs.a70cd9cf.css 3.04 KiB / gzip: 0.82 KiB
dist/assets/VWindow.1bd1bd93.css 2.15 KiB / gzip: 0.51 KiB
dist/assets/EnableOneTimePasswordDialog.a42d412e.css 2.25 KiB / gzip: 0.63 KiB
dist/assets/AppPricing.61deeeed.css 0.06 KiB / gzip: 0.07 KiB
dist/assets/index.6b7aa9ad.css 0.46 KiB / gzip: 0.17 KiB
dist/assets/crm.95f00275.css 0.51 KiB / gzip: 0.31 KiB
dist/assets/VTable.4c8b70a0.css 5.63 KiB / gzip: 0.86 KiB
dist/assets/_id_.43495c33.css 0.43 KiB / gzip: 0.23 KiB
dist/assets/VTextarea.5dc8269a.css 1.36 KiB / gzip: 0.46 KiB
dist/assets/VTimelineItem.07999e79.css 16.35 KiB / gzip: 1.70 KiB
dist/assets/VExpansionPanel.da2668ed.css 6.40 KiB / gzip: 1.21 KiB
dist/assets/pricing.56987cf6.css 0.43 KiB / gzip: 0.25 KiB
dist/assets/faq.c2655a3e.css 0.37 KiB / gzip: 0.23 KiB
dist/assets/_id_.85426b33.css 0.53 KiB / gzip: 0.28 KiB
dist/assets/AppDateTimePicker.2e517c19.css 24.49 KiB / gzip: 3.87 KiB
dist/assets/_tab_.85a982d6.js 114.32 KiB / gzip: 17.83 KiB
dist/assets/EnableOneTimePasswordDialog.vue_vue_type_script_setup_true_lang.e28f045b.js 54.21 KiB / gzip: 26.72 KiB
dist/assets/AppDateTimePicker.vue_vue_type_style_index_0_lang.7a89fa00.js 102.95 KiB / gzip: 22.96 KiB
dist/assets/_id_.0d3c91dd.js 131.99 KiB / gzip: 24.15 KiB
dist/assets/index.60024895.css 440.04 KiB / gzip: 56.52 KiB
dist/assets/crm.b882faf7.js 723.03 KiB / gzip: 157.73 KiB
dist/assets/index.fc5e085d.js 4054.75 KiB / gzip: 978.41 KiB
</code></pre>
<p><strong>output of preview</strong></p>
<pre class="lang-bash prettyprint-override"><code>╰─ npm run preview
> vue-project@0.0.0 preview
> vite preview --port 5050
➜ Local: http://127.0.0.1:5050/
➜ Network: use --host to expose
</code></pre>
<p>The page on browser after build and preview</p>
<p><a href="https://i.stack.imgur.com/oBplE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oBplE.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74283135,
"author": "caTS",
"author_id": 18244921,
"author_profile": "https://Stackoverflow.com/users/18244921",
"pm_score": 1,
"selected": false,
"text": "(typeof ... !== \"undefined\" ? ... : ...)"
},
{
"answer_id": 74283194,
"author": "Adam",
"author_id": 954940,
"author_profile": "https://Stackoverflow.com/users/954940",
"pm_score": 1,
"selected": false,
"text": "const characters = [\n {\n bodyType: \"tall\",\n element: \"air\",\n gender: \"female\",\n name: \"Renna\",\n weapon: \"sword\",\n },\n {\n bodyType: \"tall\",\n element: \"fire\",\n gender: \"male\",\n name: \"Igneus\",\n weapon: \"sword\",\n },\n {\n bodyType: \"medium\",\n element: \"water\",\n gender: \"male\",\n name: \"Dagon\",\n weapon: \"spear\",\n },\n];\n\n\nconst partialMatch = (object) => (character) => Object.entries(object).every(([key,value]) => character[key] === value)\n\nconst myMatchingCharacters = characters.filter(partialMatch({bodyType:'tall',gender:'male'}))\n\nconsole.log(myMatchingCharacters.map(({name}) => name))"
},
{
"answer_id": 74283615,
"author": "Peter Seliger",
"author_id": 2627243,
"author_profile": "https://Stackoverflow.com/users/2627243",
"pm_score": 0,
"selected": false,
"text": "filter"
},
{
"answer_id": 74284908,
"author": "Ro Milton",
"author_id": 1909499,
"author_profile": "https://Stackoverflow.com/users/1909499",
"pm_score": 1,
"selected": true,
"text": "const characters=[{bodyType:\"tall\",element:\"air\",gender:\"female\",name:\"Renna\",weapon:\"sword\"},{bodyType:\"tall\",element:\"fire\",gender:\"male\",name:\"Igneus\",weapon:\"sword\"},{bodyType:\"medium\",element:\"water\",gender:\"male\",name:\"Dagon\",weapon:\"spear\"}];\n\nconst isThere = (...args) => \n characters.filter(char => \n ['bodyType', 'element', 'gender', 'weapon'].every((key, index) =>\n args[index] === undefined || args[index] === char[key]\n )\n )\n .map(({ name }) => name);\n\nconsole.log(isThere(\"tall\", undefined, \"male\", undefined));\nconsole.log(isThere(undefined, undefined, undefined, \"sword\"));"
},
{
"answer_id": 74285314,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 0,
"selected": false,
"text": "const characters = [\n {\n bodyType: \"tall\",\n element: \"air\",\n gender: \"female\",\n name: \"Renna\",\n weapon: \"sword\",\n },\n {\n bodyType: \"tall\",\n element: \"fire\",\n gender: \"male\",\n name: \"Igneus\",\n weapon: \"sword\",\n },\n {\n bodyType: \"medium\",\n element: \"water\",\n gender: \"male\",\n name: \"Dagon\",\n weapon: \"spear\",\n },\n];\n\nconst matched = characters.filter((crits=> pers => crits.every(([k,v]) => pers[k] === v))([['bodyType','tall'],['weapon','sword']]))\n\nconsole.log(matched.map(({name}) => name))"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9114389/"
] |
74,283,114 | <p>I want to count how many times the digit "5" appears from the range 1 to 4321. For example, the number 5 appears 1 or the number 555, 5 would appear 3 times etc.</p>
<p>Here is my code so far, however, the results are 0, and they are supposed to be 1262.</p>
<pre><code>#!/bin/bash
typeset -i count5=0
for n in {1..4321}; do
echo ${n}
done | \
while read -n1 digit ; do
if [ `echo "${digit}" | grep 5` ] ; then
count5=count5+1
fi
done | echo "${count5}"
</code></pre>
<p>P.s. I am looking to fix my code so it can print the right output. I do not want a completely different solution or a shortcut.</p>
| [
{
"answer_id": 74283333,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 1,
"selected": false,
"text": "bash"
},
{
"answer_id": 74283402,
"author": "j_b",
"author_id": 16482938,
"author_profile": "https://Stackoverflow.com/users/16482938",
"pm_score": 0,
"selected": false,
"text": "awk"
},
{
"answer_id": 74285544,
"author": "Diego Torres Milano",
"author_id": 236465,
"author_profile": "https://Stackoverflow.com/users/236465",
"pm_score": 2,
"selected": false,
"text": "seq 4321 | tr -Cd 5 | wc -c\n 1262\n"
},
{
"answer_id": 74285583,
"author": "user1934428",
"author_id": 1934428,
"author_profile": "https://Stackoverflow.com/users/1934428",
"pm_score": 1,
"selected": false,
"text": "n"
},
{
"answer_id": 74286214,
"author": "M. Nejat Aydin",
"author_id": 13809001,
"author_profile": "https://Stackoverflow.com/users/13809001",
"pm_score": 0,
"selected": false,
"text": "bash"
},
{
"answer_id": 74286558,
"author": "tripleee",
"author_id": 874188,
"author_profile": "https://Stackoverflow.com/users/874188",
"pm_score": 2,
"selected": false,
"text": "#!/bin/bash\ntypeset -i count5=0\nfor n in {1..4321}; do\n echo $n # braces around ${n} provide no benefit\ndone | # no backslash required here; fix weird indentation\nwhile read -n1 digit ; do\n # prefer modern command substitution syntax over backticks\n if [ $(echo \"${digit}\" | grep 5) ] ; then\n count5=count5+1\n fi\n echo \"${count5}\" # variable will not persist outside subprocess\ndone | head -n 1 # so instead just print the last one after the loop\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20215288/"
] |
74,283,121 | <p>Hello I'm trying to convert my database, one table and field to utf using this script</p>
<pre><code>-- Write a script that converts hbtn_0c_0 database to UTF8
-- (utf8mb4, collate utf8mb4_unicode_ci) in your MySQL server.
-- You need to convert all of the following to UTF8:
-- Database hbtn_0c_0
-- Table first_table
-- Field name in first_table
ALTER DATABASE
`hbtn_0c_0`
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
USE `hbtn_0c_0`;
ALTER TABLE
`first_table`
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
ALTER TABLE
`first_table`
CHANGE `name`
VARCHAR(256)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
</code></pre>
<p>But I have a SQL error. Please help me</p>
<pre><code>black_genius@genius:~/Documents/ALX_Task/alx-higher_level_programming/0x0D-SQL_introduction$ cat 100-move_to_utf8.sql | mysql -hlocalhost -uroot -p
Enter password:
ERROR 1064 (42000) at line 22: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(256)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci' at line 4
</code></pre>
<p>I'm using mysql version v8.0.31 on ubuntu 22.10</p>
| [
{
"answer_id": 74283178,
"author": "Paul Spiegel",
"author_id": 5563083,
"author_profile": "https://Stackoverflow.com/users/5563083",
"pm_score": 3,
"selected": true,
"text": "CHANGE [COLUMN] old_col_name new_col_name column_definition\n"
},
{
"answer_id": 74283230,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE ... CONVERT TO CHARACTER SET ..."
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14920567/"
] |
74,283,130 | <p>I am trying to implement a code that prints an 8 by 8 matrix (0 to 63). It should however remove the initial tab spaces and the last empty line. My code is below :</p>
<pre><code>s =''
for i in range(n):
for j in range(n):
z = i * n + j
s += ' '
if z < 10:
s += ' '
s += str(z)
s += '\n'
print(s)
</code></pre>
<p>The image Below is also the desired output</p>
<p><a href="https://i.stack.imgur.com/OLRAr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OLRAr.png" alt="enter image description here" /></a></p>
<p>I have tried the dedent function but it fails to remove the last line as well</p>
| [
{
"answer_id": 74283255,
"author": "Xin Cheng",
"author_id": 4708399,
"author_profile": "https://Stackoverflow.com/users/4708399",
"pm_score": 0,
"selected": false,
"text": "n = 8 \nprint(\"\\n\".join([\" \".join([\"{:2d}\".format(i*n+j) for j in range(n)]) for i in range(n) ]), end=\"\")\n"
},
{
"answer_id": 74283378,
"author": "was1209",
"author_id": 11549977,
"author_profile": "https://Stackoverflow.com/users/11549977",
"pm_score": 3,
"selected": true,
"text": " if j != 0:\n s += ' '\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17990967/"
] |
74,283,134 | <p>in the following code i want to save the String data that i get from firestore inside the .then() method into another variable. but once its outside the method i lose the value.</p>
<pre><code>String memberName = '';
member.user.get().then(
(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
memberName = documentSnapshot.get('Full_Name');
print(memberName) //'John Smith'
}
},
);
print(memberName) //''
</code></pre>
<p>posting all the code for reference.</p>
<pre><code> Widget buildGroupMemberTile(GroupMember member, bool loggedUserIsAdmin) {
final memberDoc = FirebaseFirestore.instance
.collection('groups')
.doc(widget.group.id)
.collection("members")
.doc(member.email);
print(getMemberName(member));
String memberName = '';
member.user.get().then(
(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
memberName = documentSnapshot.get('Full_Name');
print(memberName) //'John Smith'
}
},
);
print(memberName) //''
return ListTile(
onTap: (() {
if (loggedUserIsAdmin) {
if (member.role == 'admin') {
memberDoc.update({'role': 'member'});
} else if (member.role == 'member') {
memberDoc.update({'role': 'admin'});
}
}
}),
title: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
child: Container(
width: 450,
decoration: BoxDecoration(
color: Color.fromARGB(255, 65, 61, 82),
borderRadius: BorderRadius.all(Radius.circular(12))),
child: Padding(
padding: const EdgeInsets.fromLTRB(40, 20, 40, 20),
child: Column(
children: [
Text(
memberName,
style: GoogleFonts.poppins(
color: ThemeColors.whiteTextColor,
fontSize: FontSize.large,
fontWeight: FontWeight.w400,
),
),
],
),
),
),
),
));
}
</code></pre>
<p>Im guessing that I'm referencing <code>documentSnapshot.get('Full_Name')</code> and not copying its the value to <code>memberName</code>. How can i keep the value?</p>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19299462/"
] |
74,283,146 | <p>I have the following code, shown below where every time I make changes to a text field, a function gets called, in my case doSomething(). However, I assumed that since I bound the value of the text to a variable, if that variable were to get updated, the textfield text would also update. This is not happening, and my question is, what would be the simplest way to make the textfield update its text every time the corresponding variable changes.</p>
<p>Edit: Just to clarify, I have no problem getting the doSomething() function to update other parts of the code, I am looking for the inverse where an external variable changes the text of the textfield</p>
<pre><code>import 'package:flutter/material.dart';
class DynamicTextField extends StatefulWidget {
const DynamicTextField(
{
required this.value,
Key? key})
: super(key: key);
final double value;
@override
State<DynamicTextField> createState() =>
_DynamicTextFieldState(value);
}
class _DynamicTextFieldState extends State<DynamicTextField> {
_DynamicTextFieldState(this.value);
final double value;
late TextEditingController textChanged;
@override
void initState() {
textChanged = TextEditingController(text: value.toString());
super.initState();
}
@override
Widget build(BuildContext context) {
return TextField(
controller: textChanged,
onChanged: (text) {
doSomething();
},
);
}
}
</code></pre>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8379276/"
] |
74,283,148 | <p>I have a springboot Application with 10 Tables in my database. When i make a get request on one table, it returns a response with in all the tables having any related records in all the 10 tables. I use Lazy fetch, the problems does not solve. I need to return only response expectated by front end app. For example, if the client wants only students then the REST API should return only students (not its child entities). How can i solve this problem.</p>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11079729/"
] |
74,283,154 | <p>I am trying to catch a <code>RountedEvent</code> fired from multiple instances of a <code>UserControl</code>. This works in the non-MVVM world easily by catching the routed event at the <code>Window</code> level (local:MyControl.MyEvent="Window_CodeBehindHandler"). But I need to forward that event on to the View Model, and I am struggling to get an <code>Interaction.Triggers</code> setup to behave the same. The <code>EventTrigger</code> behaves as expected if I pass in a specific <code>SourceName</code> or <code>SourceObject</code> or place the <code>Interaction.Triggers</code> inside of the UserControl in the XAML, but that doesn't work the same.</p>
<p>I have tried various versions of setting <code>SourceName</code> or <code>SourceObject</code> to the control type or name without luck.</p>
<p>I've put together an MRE here: <a href="https://github.com/AndyStagg/WpfInteractionEventTriggerMRE" rel="nofollow noreferrer">WpfInteractionEventTriggerMRE</a>. The "real" implementation has an <code>ItemsView</code> bound to a collection created at runtime of these control objects, with a lot more going on than a single "Select" event, so "just use an {x} control with Click already implemented and restyle it" suggestions aren't helpful.</p>
<pre class="lang-xml prettyprint-override"><code><Window x:Class="WpfApp5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp5"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
local:ElipseControl.Select="Window_Select"> <!-- This works as expected -->
<b:Interaction.Triggers> <!-- This does not -->
<b:EventTrigger EventName="Select">
<b:InvokeCommandAction Command="{Binding ElipseSelectedCommand}" />
</b:EventTrigger>
</b:Interaction.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<local:ElipseControl Grid.Row="0" ElipseName="One" />
<local:ElipseControl Grid.Row="1" ElipseName="Two" />
</Grid>
</Window>
</code></pre>
<p>I am hoping there is something I am just overlooking here.</p>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1778608/"
] |
74,283,161 | <p>Google Sheet : <a href="https://docs.google.com/spreadsheets/d/1wpJvEgNDMb-VIRgsqnpzTddqLuaqTE-XTRrctRU34P4/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1wpJvEgNDMb-VIRgsqnpzTddqLuaqTE-XTRrctRU34P4/edit?usp=sharing</a></p>
<p>How do I display all the data that is in my google sheet?</p>
<pre><code> <tr id="tr">
<td name="Name" id="Name"></td>
<td name="Department" id="Department"></td>
<td name="Title" id="Title"></td>
<td name="Email" id="Email"></td>
<td name="Extension" id="Extension"></td>
</tr>
</code></pre>
<pre><code><script src="https://cdn.rawgit.com/Keyang/node-csvtojson/d41f44aa/browser/csvtojson.min.js"></script>
</code></pre>
<pre><code> var url = "https://docs.google.com/spreadsheets/d/1wpJvEgNDMb-VIRgsqnpzTddqLuaqTE-XTRrctRU34P4/export?format=csv";
fetch(url).then(result => result.text()).then(function(csvtext){
return csv().fromString(csvtext);
}).then(function(csv) {
csv.forEach(function(row){
document.getElementById("Name").innerHTML = row.Name;
document.getElementById("Department").innerHTML = row.Department;
document.getElementById("Title").innerHTML = row.Title;
document.getElementById("Email").innerHTML = row.Email;
document.getElementById("Extension").innerHTML = row.Extension;
});
});
</code></pre>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20392782/"
] |
74,283,162 | <p>I'm making a batch program to show recent updates based on a .HTML document. I wanted it to read exactly the "<strong>October 26, 2022</strong>" part (seen below), completely ignoring the other codes and put it in a variable.</p>
<p>Part of the document I want to read is based on this:</p>
<pre><code><li><span>Current version:</span><span>**October 26, 2022**</span></li>
</code></pre>
<p>I would implement it inside this batch code with the <strong>!CurrentVersionDate!</strong> variable</p>
<pre><code>FOR /L %%i in (1,1,%count%) DO (
call :GetLastModifiedDate "!File[%%i]!" LastModifiedDate
echo ::------------------------------------------------------------------
echo DLL File: "!file[%%i]!"
echo Version date: "!LastModifiedDate!"
echo Current version: "!CurrentVersionDate!"
echo ::------------------------------------------------------------------
)
</code></pre>
<p>As I said, I wanted it to be displayed without the HTML codes, like</p>
<pre><code>::------------------------------------------------------------------
DLL File: "!file[%%i]!"
Version date: "!LastModifiedDate!"
Current version: October 26, 2022
::------------------------------------------------------------------
</code></pre>
<p>So, I tried to use <strong><code>for /F "skip=385 delims=" %%i in (page.html) DO set "LastModifiedDate=%%i</code></strong>, it shows the following result:</p>
<pre><code>Current version: Current version:</span> <span> October 26, 2022 </span></li>
</code></pre>
<p>I also tried <strong><code>FINDSTR /C:"Current version" page.html</code></strong>, but it was useless, because it showed the same thing and I didn't have the variable in my hands.</p>
<p>Any suggestions?</p>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19332519/"
] |
74,283,198 | <p>I've called an instance method four times, and each time an instance of the Matplotlib class AxesSubPlot is returned.</p>
<p>I'm slowly getting to grips with Matplotlib, but I'm unsure how I render the four separate instances of AxesSubPlot as a MatplotLib subplot of 2x2.</p>
<p><strong>In short</strong>: if <em>something</em> returns an AxesSubplot instance, how do I plot it.</p>
<p>Thanks.</p>
| [
{
"answer_id": 74283201,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": false,
"text": "then"
},
{
"answer_id": 74283403,
"author": "flutterWithChris",
"author_id": 19431523,
"author_profile": "https://Stackoverflow.com/users/19431523",
"pm_score": 0,
"selected": false,
"text": "member.user.get()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4507231/"
] |
74,283,228 | <p>I am trying to figure out how to disable the <code>cache</code> in my 'react' app, but when it loads doesn't execute any <code>javascript</code> code.</p>
<p>I expect that when I click on my 'react' application, all the JS code will run and <strong>no-cache</strong> will be loaded.</p>
<ul>
<li>I hope someone can help me and thanks in advance!</li>
</ul>
| [
{
"answer_id": 74283319,
"author": "justin107d",
"author_id": 9487829,
"author_profile": "https://Stackoverflow.com/users/9487829",
"pm_score": 0,
"selected": false,
"text": "cache"
},
{
"answer_id": 74297730,
"author": "Gonzalo Cugiani",
"author_id": 20149906,
"author_profile": "https://Stackoverflow.com/users/20149906",
"pm_score": 1,
"selected": false,
"text": "back/forward cache"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20382999/"
] |
74,283,241 | <p>I'm trying to setup a route for downlading videos for my Vue app backed by an Express server. For some reason, first request that is sent to backend is working as expected and it results in successful file download; however, the subsequent requests fail with <code>Network Error</code>, and I only get a brief error message that looks like this <code>http://localhost:8080/download/videos/1667163624289.mp4 net::ERR_FAILED 200 (OK)</code>.</p>
<p>What could be the issue here?</p>
<p><strong>I have an Express.js server (localhost:8000) setup with cors like below:</strong></p>
<pre><code>const express = require("express");
const app = express();
const port = 8000;
const cors = require("cors");
app.use(cors());
app.get("/download/:kind/:fileName",
async (req, res, next) => {
const file = `${__dirname}/public/files/${req.params.kind}/${req.params.fileName}`;
res.download(file);
});
app.listen(port, () => {
});
</code></pre>
<p><strong>And my Vue (localhost:8080) component sends that request looks like this:</strong></p>
<pre><code>downloadVideo(fileName) {
const fileName = fileDir.split('/').pop();
const downloadUrl = `/download/videos/${fileName}`;
axios({
method: "get",
url: downloadUrl,
responseType: 'blob',
})
.then((response)=> {
// create file link in browser's memory
const href = URL.createObjectURL(response.data); // data is already a blob
// create "a" element with href to file & click
const link = document.createElement('a');
link.href = href;
link.setAttribute('download', 'my_video.mp4');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(href);
})
.catch((err) => {
// HANDLE ERROR HERE
})
},
</code></pre>
<p><strong>I also have a vue config setup to proxy the requests to 8000:</strong></p>
<pre><code>// vue.config.js
module.exports = {
devServer: {
proxy: 'http://localhost:8000',
disableHostCheck: true
},
outputDir: '../backend/public', // build will output to this folder
assetsDir: '' // relative to the output folder
}
</code></pre>
| [
{
"answer_id": 74283319,
"author": "justin107d",
"author_id": 9487829,
"author_profile": "https://Stackoverflow.com/users/9487829",
"pm_score": 0,
"selected": false,
"text": "cache"
},
{
"answer_id": 74297730,
"author": "Gonzalo Cugiani",
"author_id": 20149906,
"author_profile": "https://Stackoverflow.com/users/20149906",
"pm_score": 1,
"selected": false,
"text": "back/forward cache"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9842672/"
] |
74,283,246 | <p>I have a dataset and the task:"Average number of major credit cards held for people with top 10 income".</p>
<pre><code>dput(head(creditcard))
structure(list(card = structure(c(2L, 2L, 2L, 2L, 2L, 2L), levels = c("no","yes"), class = "factor"), reports = c(0L, 0L, 0L, 0L, 0L, 0L), age = c(37.66667, 33.25, 33.66667, 30.5, 32.16667, 23.25), income = c(4.52, 2.42, 4.5, 2.54, 9.7867, 2.5), share = c(0.03326991, 0.005216942, 0.004155556, 0.06521378, 0.06705059, 0.0444384), expenditure = c(124.9833, 9.854167, 15, 137.8692, 546.5033, 91.99667), owner = structure(c(2L, 1L, 2L, 1L, 2L, 1L), levels = c("no", "yes"), class = "factor"), selfemp = structure(c(1L, 1L, 1L, 1L, 1L, 1L), levels = c("no", "yes"), class = "factor"),
dependents = c(3L, 3L, 4L, 0L, 2L, 0L), days = c(54L, 34L,58L, 25L, 64L, 54L), majorcards = c(1L, 1L, 1L, 1L, 1L, 1L), active = c(12L, 13L, 5L, 7L, 5L, 1L), income_fam = c(1.13, 0.605, 0.9, 2.54, 3.26223333333333, 2.5)), row.names = c("1","2", "3", "4", "5", "6"), class = "data.frame")
</code></pre>
<p><a href="https://i.stack.imgur.com/NLCz5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NLCz5.jpg" alt="enter image description here" /></a></p>
<p>I tried to do the task like this</p>
<pre><code>round(mean(creditcard[order(creditcard$income, decreasing = TRUE),]$majorcards[1:10]))
</code></pre>
<p>But my solution turned out to be inoptimal and I do not understand how it can be corrected</p>
| [
{
"answer_id": 74283319,
"author": "justin107d",
"author_id": 9487829,
"author_profile": "https://Stackoverflow.com/users/9487829",
"pm_score": 0,
"selected": false,
"text": "cache"
},
{
"answer_id": 74297730,
"author": "Gonzalo Cugiani",
"author_id": 20149906,
"author_profile": "https://Stackoverflow.com/users/20149906",
"pm_score": 1,
"selected": false,
"text": "back/forward cache"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20366209/"
] |
74,283,249 | <p>I am scraping a website and would like to find specific content based on style, so I do</p>
<pre><code>soup.find_all('style')
</code></pre>
<p><a href="https://i.stack.imgur.com/g63J8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g63J8.png" alt="enter image description here" /></a></p>
<p>and it does return some result/text, but once I use .text <code>soup_name.find_all('style')[0].text</code> to extract the text, it returns an empty string</p>
<p><a href="https://i.stack.imgur.com/Ry43N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ry43N.png" alt="enter image description here" /></a></p>
<p>What can I do to extract the text in the style tag?</p>
| [
{
"answer_id": 74283261,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 2,
"selected": true,
"text": ".contents[0]"
},
{
"answer_id": 74283516,
"author": "Driftr95",
"author_id": 6146136,
"author_profile": "https://Stackoverflow.com/users/6146136",
"pm_score": 0,
"selected": false,
"text": "str(soup.find('style')).strip()[7:-8].strip()\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15410844/"
] |
74,283,264 | <p>My query returns a result like shown in the table. I would like to randomly pick an ID from the <code>ID</code> column and get all the rows having that <code>ID</code>. How can I do that in SnowFlake or SQL:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>Postalcode</th>
<th>Value</th>
<th>...</th>
</tr>
</thead>
<tbody>
<tr>
<td>1e3d</td>
<td>NK25F4</td>
<td>3214</td>
<td>...</td>
</tr>
<tr>
<td>1e3d</td>
<td>NK25F4</td>
<td>3258</td>
<td>...</td>
</tr>
<tr>
<td>1e3d</td>
<td>NK25F4</td>
<td>3354</td>
<td>...</td>
</tr>
<tr>
<td>1f74</td>
<td>NG2LK8</td>
<td>5524</td>
<td></td>
</tr>
<tr>
<td>1f74</td>
<td>NG2LK8</td>
<td>5548</td>
<td></td>
</tr>
<tr>
<td>3e9a</td>
<td>N6B7H4</td>
<td>3694</td>
<td></td>
</tr>
<tr>
<td>3e9a</td>
<td>N6B7H4</td>
<td>3325</td>
<td></td>
</tr>
<tr>
<td>38e4</td>
<td>N6C7H2</td>
<td>3654</td>
<td>...</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74283312,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 1,
"selected": false,
"text": "with\n dat as ( ... your query ...),\n tid as (select id from dat order by random() fetch first 1 row)\nselect d.*\nfrom dat d\ninner join tid t on t.id = d.id\n"
},
{
"answer_id": 74283316,
"author": "Frank Hopkins",
"author_id": 8045100,
"author_profile": "https://Stackoverflow.com/users/8045100",
"pm_score": 1,
"selected": false,
"text": "SELECT * \nFROM Table_NAME \nWHERE ID IN (SELECT ID FROM Table_Name ORDER BY RAND() LIMIT 1);\n"
},
{
"answer_id": 74283538,
"author": "Simeon Pilgrim",
"author_id": 43992,
"author_profile": "https://Stackoverflow.com/users/43992",
"pm_score": 2,
"selected": false,
"text": "SELECT t.* \nFROM your_table as t\nJOIN (SELECT ID FROM your_table SAMPLE (1 ROWS)) as r\n ON t.id = r.id\n"
},
{
"answer_id": 74283632,
"author": "Adrian White",
"author_id": 1352490,
"author_profile": "https://Stackoverflow.com/users/1352490",
"pm_score": 0,
"selected": false,
"text": "WITH DATA AS (\nselect '1e3d' id,'NK25F4' postalcode,3214 some_value union all \nselect '1e3d' id,'NK25F4' postalcode,3258 some_value union all \nselect '1e3d' id,'NK25F4' postalcode,3354 some_value union all \nselect '1f74' id,'NG2LK8' postalcode,5524 some_value union all \nselect '1f74' id,'NG2LK8' postalcode,5548 some_value union all \nselect '3e9a' id,'N6B7H4' postalcode,3694 some_value union all \nselect '3e9a' id,'N6B7H4' postalcode,3325 some_value union all \nselect '38e4' id,'N6C7H2' postalcode,3654 some_value )\nSELECT * FROM DATA ,LATERAL (SELECT ID FROM DATA SAMPLE(2 ROWS)) I WHERE I.ID = DATA.ID \n"
},
{
"answer_id": 74307808,
"author": "Rajat",
"author_id": 9947159,
"author_profile": "https://Stackoverflow.com/users/9947159",
"pm_score": 0,
"selected": false,
"text": "window frame"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1050648/"
] |
74,283,270 | <p>Environmant:</p>
<ul>
<li>Micronaut: 3.7.3</li>
<li>Java: OpenJDK 11.0.16</li>
<li>Groovy: 3.0.13</li>
</ul>
<p>My Controller is implemented with Groovy as below:</p>
<pre><code>@Controller("/")
@Slf4j
class Controller1 {
@Get(uri="/test-localdatetime", produces = MediaType.APPLICATION_JSON)
HttpResponse<String> testLocalDateTime() {
LocalDateTime now = LocalDateTime.now()
def map = [
status: "SSUCCESS",
time: now
]
return HttpResponse.ok(map)
}
}
</code></pre>
<p>When I call it, it returns:</p>
<pre><code>{"status":"SSUCCESS","time":[2022,11,2,8,24,13,948454300]}
</code></pre>
<p>If I want it to return a beautified JSON as below, I could add below code</p>
<pre><code>String json = new JsonBuilder(map).toPrettyString()
return HttpResponse.ok(json)
</code></pre>
<p>And the response will become (still not what I want):</p>
<pre><code>{
"status": "SSUCCESS",
"time": {
"month": "NOVEMBER",
"second": 29,
"hour": 8,
"nano": 944749300,
"year": 2022,
"dayOfMonth": 2,
"minute": 44,
"monthValue": 11,
"dayOfWeek": "WEDNESDAY",
"chronology": {
"calendarType": "iso8601",
"id": "ISO"
},
"dayOfYear": 306
}
}
</code></pre>
<p>But the idea response I want is below format:</p>
<pre><code>{
"status":"SSUCCESS",
"time":"2022-11-02 08:24:13"
}
</code></pre>
<p>So, I wonder if there is an easy way to reach the above idea format by just adding some configurations or annotations without changing the intial code ?</p>
| [
{
"answer_id": 74284874,
"author": "saw303",
"author_id": 960875,
"author_profile": "https://Stackoverflow.com/users/960875",
"pm_score": 1,
"selected": false,
"text": "jackson:\n dateFormat: yyyyMMdd\n timeZone: UTC\n serialization:\n writeDatesAsTimestamps: false\n"
},
{
"answer_id": 74285498,
"author": "cgrim",
"author_id": 9709361,
"author_profile": "https://Stackoverflow.com/users/9709361",
"pm_score": 0,
"selected": false,
"text": "import com.fasterxml.jackson.annotation.JsonFormat\nimport java.time.LocalDateTime\n\nclass SomeResponse {\n String status\n @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\")\n LocalDateTime time\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1125681/"
] |
74,283,292 | <p>I'm making a calculator and ran into some issues with an if/else function giving me unexpected results. The logic seems kind of sound when I run it over so I would like some input on what I may have wrong here. The code is giving unexpected results from <code>expressionMaker</code> where it seems to clear the first "if --> if " statements but none of the else ones.</p>
<p>Edit: thanks for the feedback. I've narrowed the issue down to this portion.</p>
<pre><code>else if ((EventTarget == numbers) && (expression.a > 0) && (expression.operand !== 0)) {
if (expression.b == 0) {
expression.b = keyValue
}
else {
expression.b = concat(expression.b, keyValue)
}
}
</code></pre>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const btn = document.getElementById("calculatorGrid");
const display = document.getElementById("display");
const miniscreen = document.getElementById("miniScreen")
const equals = document.getElementById("evaluate")
const numbers = document.querySelectorAll(".Nbuttons");
const clear = document.getElementById("clear");
const add = document.getElementById("plus");
const sub = document.getElementById("subtract");
const multi = document.getElementById("multiply");
const divi = document.getElementById("divide");
const operators = document.querySelectorAll(".operators");
let nums = document.getElementById("nums")
numbers.values = nums.textContent
const calculate = (() => {
const add = (a, b) => a + b;
const sub = (a, b) => a - b;
const mul = (a, b) => a * b;
const div = (a, b) => a / b;
return {
add,
sub,
mul,
div,
};
});
const expression = {
a: 0,
operand: 0,
b: 0,
};
function expressionMaker(keyValue) {
const concat = (a, b) => {
return ("" + a + b)
};
if (EventTarget == numbers && expression.a == 0 || expression.operand == 0) {
if (expression.a == 0) {
expression.a = keyValue
}
else if (expression.a > 0) {
expression.a = concat(expression.a, keyValue)
}
display.innerHTML = expression.a
}
else if ((EventTarget == numbers) && (expression.a > 0) && (expression.operand !== 0)) {
if (expression.b == 0) {
expression.b = keyValue
}
else {
expression.b = concat(expression.b, keyValue)
}
}
else {
null
}
}
function evaluate() {
var result
if (expression.operand == "+") {
var result = calculate.add(expression.a, expression.b)
}
else if (expression.operand == "-") {
result = calculate.sub(expression.a, expression.b)
}
else if (expression.operand == "x") {
result = calculate.mul(expression.a, expression.b)
}
else if (expression.operand == "/") {
result = calculate.div(expression.a, expression.b)
}
else {
return null
}
display.innerHTML = result
return result
}
clear.addEventListener("click", () => {
clearOut()
})
equals.addEventListener("click", () => {
evaluate(expression.a, expression.b)
})
function setNums() {
let nums = document.getElementById("nums")
numbers.values = nums.textContent
};
setNums();
function clearOut() {
display.textContent = 0
expression.a = 0
expression.operand = 0
expression.b = 0
};
clear.addEventListener("click", function() {
clearOut();
});
add.addEventListener("click", () => {
expression.operand = "+"
display.innerHTML = "+"
})
sub.addEventListener("click", () => {
expression.operand = "-"
display.innerHTML = "-"
})
multi.addEventListener("click", () => {
expression.operand = "x"
display.innerHTML = "x"
})
divi.addEventListener("click", () => {
expression.operand = "/"
display.innerHTML = "/"
})
numbers.forEach(function(element) {
element.addEventListener("click", function(event) {
var key = event.target
let keyValue = key.textContent
expressionMaker(keyValue)
});
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="display">
<div id="miniScreen"></div>
</div>
<div id="calculatorGrid">
<button class="Nbuttons" id="nums" data-number="1">1</button>
<button class="Nbuttons" id="nums" data-number="2">2</button>
<button class="Nbuttons" id="nums" data-number="3">3</button>
<button class="Nbuttons" id="nums" data-number="4">4</button>
<button class="Nbuttons" id="nums" data-number="5">5</button>
<button class="Nbuttons" id="nums" data-number="6">6</button>
<button class="Nbuttons" id="nums" data-number="7">7</button>
<button class="Nbuttons" id="nums" data-number="8">8</button>
<button class="Nbuttons" id="nums" data-number="9">9</button>
<button class="Nbuttons" id="nums" data-number="0">0</button>
<button class="operators" id="plus" data-operator="+">+</button>
<button class="operators" id="subtract" data-operator="-">-</button>
<button class="operators" id="multiply" data-operator="*">x</button>
<button class="operators" id="divide" data-operator="/">÷</button>
<button id="clear">clear</button>
<button id="evaluate"> =</button>
</div>
<script src="script.js" defer></script>
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74284874,
"author": "saw303",
"author_id": 960875,
"author_profile": "https://Stackoverflow.com/users/960875",
"pm_score": 1,
"selected": false,
"text": "jackson:\n dateFormat: yyyyMMdd\n timeZone: UTC\n serialization:\n writeDatesAsTimestamps: false\n"
},
{
"answer_id": 74285498,
"author": "cgrim",
"author_id": 9709361,
"author_profile": "https://Stackoverflow.com/users/9709361",
"pm_score": 0,
"selected": false,
"text": "import com.fasterxml.jackson.annotation.JsonFormat\nimport java.time.LocalDateTime\n\nclass SomeResponse {\n String status\n @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\")\n LocalDateTime time\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19642872/"
] |
74,283,320 | <p>This is literally my first foray into Mongo. I have exported my Active Directory into a Mongo collection. It's structure, as best I can describe it as a complete novice, is a row, with an object containing properties which contain an array of one string. (See attached image for clarification of my limited vocab).</p>
<p><a href="https://i.stack.imgur.com/idvBo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/idvBo.png" alt="enter image description here" /></a></p>
<p>My question is, I want to filter to a specific "givenname". What do I put in filter to do that? I tried {givenname: "Test"}, but it matches nothing. I suspect because I have to drill all the way down through the multiple layers. Probably something like:</p>
<pre><code>{Properties: { givenname: 0: {"Test"}}}
</code></pre>
<p>I really do not know the json syntax ('cause that's what it looks like) to go from row, to property {} object, to column [] array, to array element 0, to value "Test".</p>
<p><strong>EDIT:</strong> Here is an <strong>example</strong> of the JSON I imported to create this data. It's just a straight dump of an LDAP query, with PII edited out.</p>
<pre><code>[
{
"Path": "LDAP://CN=My Name,OU=Admins,OU=Service Accounts,OU=asdf Company,DC=asdf,DC=local",
"Properties": {
"objectclass": [
"top",
"person",
"organizationalPerson",
"user"
],
"countrycode": [
0
],
"primarygroupid": [
513
],
"givenname": [
"MyName"
],
"codepage": [
0
],
"memberof": [
"CN=sp-Net-FDA-RW,OU=Sharepoint,OU=Permission Groups"
],
"samaccounttype": [
805306368
],
"description": [
"IS - MyName Acct."
],
"msds-supportedencryptiontypes": [
0
],
}
},
{
// more accounts...
}
]
</code></pre>
<p>As you can see it's an array of objects, and each object's properties is an array of one or more elements. But almost always an array of a single element. GivenName, for example.</p>
| [
{
"answer_id": 74284874,
"author": "saw303",
"author_id": 960875,
"author_profile": "https://Stackoverflow.com/users/960875",
"pm_score": 1,
"selected": false,
"text": "jackson:\n dateFormat: yyyyMMdd\n timeZone: UTC\n serialization:\n writeDatesAsTimestamps: false\n"
},
{
"answer_id": 74285498,
"author": "cgrim",
"author_id": 9709361,
"author_profile": "https://Stackoverflow.com/users/9709361",
"pm_score": 0,
"selected": false,
"text": "import com.fasterxml.jackson.annotation.JsonFormat\nimport java.time.LocalDateTime\n\nclass SomeResponse {\n String status\n @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = \"yyyy-MM-dd HH:mm:ss\")\n LocalDateTime time\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2592937/"
] |
74,283,327 | <p>I am trying to run R in a google collab notebook (which worked fine before, however as I now tried to access it and run it it keeps giving me an error).</p>
<p>I have ran the following:</p>
<pre><code>
%load_ext rpy2.ipython
%%R
install.packages('rworldmap')
install.packages('classInt')
install.packages('reshape2')
install.packages('dplyr')
install.packages('ggpubr')
</code></pre>
<p>NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'str'>'</p>
<p>I have tried re-opening the notebook or creating a new one but I keep having the same issue.</p>
| [
{
"answer_id": 74283555,
"author": "Ric Villalba",
"author_id": 6912817,
"author_profile": "https://Stackoverflow.com/users/6912817",
"pm_score": 4,
"selected": true,
"text": "!pip install rpy2==3.5.1"
},
{
"answer_id": 74414817,
"author": "masud Rana",
"author_id": 20487104,
"author_profile": "https://Stackoverflow.com/users/20487104",
"pm_score": 0,
"selected": false,
"text": "rpy2"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14580403/"
] |
74,283,341 | <pre><code> const [search] = useSearchParams()
const sort = search.get('sort')
export interface Note {
id?: string | any
author: string
title: string
category: string
description: string
favourite: boolean
date: string
descLength: number
}
const sortedNotes = (notes: Note[]) => {
type sortProps = {
a: Note
b: Note
}
return notes.sort(({ a, b }: sortProps) => {
const { favourite, descLength, id } = a
const { favourite: favouriteB, descLength: descLengthB, id: id2 } = b
switch (sort) {
case 'favourite':
return favourite > favouriteB ? 1 : -1
case 'longest':
return descLength > descLengthB ? 1 : -1
case 'none':
return id - id2 ? 1 : -1
default
}
})
}
const sortingNotes = sortedNotes(notes)
const currentNotes = sortingNotes.slice(indexOfFirstNote, indexOfLastNote)
</code></pre>
<p><a href="https://i.stack.imgur.com/HRBfv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HRBfv.png" alt="enter image description here" /></a></p>
<p>I have tried to create a sort system in a note app but I don't know what the expected argument is</p>
<p>Please check a photo, i dont know why that error is occured</p>
| [
{
"answer_id": 74283555,
"author": "Ric Villalba",
"author_id": 6912817,
"author_profile": "https://Stackoverflow.com/users/6912817",
"pm_score": 4,
"selected": true,
"text": "!pip install rpy2==3.5.1"
},
{
"answer_id": 74414817,
"author": "masud Rana",
"author_id": 20487104,
"author_profile": "https://Stackoverflow.com/users/20487104",
"pm_score": 0,
"selected": false,
"text": "rpy2"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18735592/"
] |
74,283,383 | <p>I have a json/dict in the following format:</p>
<pre><code>{
"top": 590,
"left": 105,
"width": 240,
"height": 40,
"Zarya": "142612a11ad2ca629d2182a51b23d1f2",
"Kiriko": "4d0528271fd9d0104cd2af0b1c91f4f6",
"Echo": "175b9c62c57b0d6e18577f352fad4afc",
"Sojourn": "8ea40548f4472457cfbd46731958a432",
"Sombra": "319e88daf8a4b53869c6690cd008ebb0",
"Genji": "b5a7156b9a1921099a884e62f2f7c774",
"Reaper": "309527687ec1e89f63cfece162c57a66",
"Ana": "556e9f3ff210729dc9e1cf848c3c579f",
"Hanzo": "13d164a4f37fd7562b53ede9f5fd2671",
"Lucio": "d772ddc7e982cd6d714d0a19753c8b32",
"Torbjorn": "4fdf46b32b3435c714da7a75ba0ccde2",
"Junkrat": "be29c9729daf9e46606ffa26638641ea",
"Moira": "0b54634e09e4d108ca248e4e967d15a1",
"Mei": "90391ff04b11c73e49c48f9b2738d1b0",
"Dva": "859012ee744e79a630522190ef8ef92c",
"Soldier 76": "adbd70e889fe6135f372dbd28b7ae5e6",
"Winston": "1c4245a79b45f1a0b90e78383078cdd3",
"Tracer": "b5465050c403b020aac35da073d4ab11",
"Zenyatta": "dccc24bfe5d7b09df7b1387d4c8dfba7",
"Baptiste": "4d254bc437560ac21780732fc78ffa08",
"Sigma": "3c85376aee36a901bcbf24b07cf60aa2",
"Widowmaker": "049092cbd628a54ed22ae5522ca5681c",
"Orisa": "113acca96744081964854bd94191310a",
"Ashe": "48ca311fb1b288bb811965e6d84d1786"
}
</code></pre>
<p>I would like to sort everything after <code>top, left, width, height</code> alphabetically by the key, while leaving the first 4 keys at the start. How can I accomplish this?</p>
| [
{
"answer_id": 74283426,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "dct"
},
{
"answer_id": 74283452,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "data = {\n \"top\": 590,\n \"left\": 105, \n \"width\": 240, \n \"height\": 40,\n \"Zarya\": \"142612a11ad2ca629d2182a51b23d1f2\",\n \"Kiriko\": \"4d0528271fd9d0104cd2af0b1c91f4f6\",\n \"Echo\": \"175b9c62c57b0d6e18577f352fad4afc\",\n \"Sojourn\": \"8ea40548f4472457cfbd46731958a432\",\n \"Sombra\": \"319e88daf8a4b53869c6690cd008ebb0\",\n \"Genji\": \"b5a7156b9a1921099a884e62f2f7c774\",\n \"Reaper\": \"309527687ec1e89f63cfece162c57a66\",\n \"Ana\": \"556e9f3ff210729dc9e1cf848c3c579f\",\n \"Hanzo\": \"13d164a4f37fd7562b53ede9f5fd2671\",\n \"Lucio\": \"d772ddc7e982cd6d714d0a19753c8b32\",\n \"Torbjorn\": \"4fdf46b32b3435c714da7a75ba0ccde2\",\n \"Junkrat\": \"be29c9729daf9e46606ffa26638641ea\",\n \"Moira\": \"0b54634e09e4d108ca248e4e967d15a1\",\n \"Mei\": \"90391ff04b11c73e49c48f9b2738d1b0\",\n \"Dva\": \"859012ee744e79a630522190ef8ef92c\",\n \"Soldier 76\": \"adbd70e889fe6135f372dbd28b7ae5e6\",\n \"Winston\": \"1c4245a79b45f1a0b90e78383078cdd3\",\n \"Tracer\": \"b5465050c403b020aac35da073d4ab11\",\n \"Zenyatta\": \"dccc24bfe5d7b09df7b1387d4c8dfba7\",\n \"Baptiste\": \"4d254bc437560ac21780732fc78ffa08\",\n \"Sigma\": \"3c85376aee36a901bcbf24b07cf60aa2\",\n \"Widowmaker\": \"049092cbd628a54ed22ae5522ca5681c\",\n \"Orisa\": \"113acca96744081964854bd94191310a\",\n \"Ashe\": \"48ca311fb1b288bb811965e6d84d1786\"\n}\n\nkeys = ['top', 'left', 'width', 'height']\n"
},
{
"answer_id": 74283493,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "d"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11280068/"
] |
74,283,390 | <p>I am debugging a C program inside of GDB on linux. The C program prompts the user and then calls <code>read(0,&user_buffer,24)</code> where <code>user_buffer</code> is a 24-byte char buffer on the stack. I know that I can send binary data to the program from outside of gdb by e.g. <code>echo -e "\x41\x42\x43\x44" | <executable></code>, but is it possible for me to directly write raw bytes to the prompt from within gdb? I've only ever seen this done externally as shown, or using python like <code>python -c 'print("\x00\xFF\xAB")' </code> When I try to type in something like <code>\x41\x42\x43\x44</code> to the prompt within GDB, it interprets them as ascii chars. This is important for my security testing.</p>
| [
{
"answer_id": 74283426,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "dct"
},
{
"answer_id": 74283452,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "data = {\n \"top\": 590,\n \"left\": 105, \n \"width\": 240, \n \"height\": 40,\n \"Zarya\": \"142612a11ad2ca629d2182a51b23d1f2\",\n \"Kiriko\": \"4d0528271fd9d0104cd2af0b1c91f4f6\",\n \"Echo\": \"175b9c62c57b0d6e18577f352fad4afc\",\n \"Sojourn\": \"8ea40548f4472457cfbd46731958a432\",\n \"Sombra\": \"319e88daf8a4b53869c6690cd008ebb0\",\n \"Genji\": \"b5a7156b9a1921099a884e62f2f7c774\",\n \"Reaper\": \"309527687ec1e89f63cfece162c57a66\",\n \"Ana\": \"556e9f3ff210729dc9e1cf848c3c579f\",\n \"Hanzo\": \"13d164a4f37fd7562b53ede9f5fd2671\",\n \"Lucio\": \"d772ddc7e982cd6d714d0a19753c8b32\",\n \"Torbjorn\": \"4fdf46b32b3435c714da7a75ba0ccde2\",\n \"Junkrat\": \"be29c9729daf9e46606ffa26638641ea\",\n \"Moira\": \"0b54634e09e4d108ca248e4e967d15a1\",\n \"Mei\": \"90391ff04b11c73e49c48f9b2738d1b0\",\n \"Dva\": \"859012ee744e79a630522190ef8ef92c\",\n \"Soldier 76\": \"adbd70e889fe6135f372dbd28b7ae5e6\",\n \"Winston\": \"1c4245a79b45f1a0b90e78383078cdd3\",\n \"Tracer\": \"b5465050c403b020aac35da073d4ab11\",\n \"Zenyatta\": \"dccc24bfe5d7b09df7b1387d4c8dfba7\",\n \"Baptiste\": \"4d254bc437560ac21780732fc78ffa08\",\n \"Sigma\": \"3c85376aee36a901bcbf24b07cf60aa2\",\n \"Widowmaker\": \"049092cbd628a54ed22ae5522ca5681c\",\n \"Orisa\": \"113acca96744081964854bd94191310a\",\n \"Ashe\": \"48ca311fb1b288bb811965e6d84d1786\"\n}\n\nkeys = ['top', 'left', 'width', 'height']\n"
},
{
"answer_id": 74283493,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "d"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6396569/"
] |
74,283,410 | <p>Given a stringified phone number of non-zero length, write a function that returns all mnemonics for this phone number in any order.</p>
<p>`</p>
<pre><code>def phoneNumberMnemonics(phoneNumber, Mnemonics=[''], idx=0):
number_lookup={'0':['0'], '1':['1'], '2':['a','b','c'], '3':['d','e','f'], '4':['g','h','i'], '5':['j','k','l'], '6':['m','n','o'], '7':['p','q','r','s'], '8':['t','u','v'], '9':['w','x','y','z']}
if idx==len(phoneNumber):
return Mnemonics
else:
new_Mnemonics=[]
for letter in number_lookup[phoneNumber[idx]]:
for mnemonic in Mnemonics:
new_Mnemonics.append(mnemonic+letter)
phoneNumberMnemonics(phoneNumber, new_Mnemonics, idx+1)
</code></pre>
<p>`</p>
<p>If I use the input "1905", my function outputs null. Using a print statement right before the return statement, I can see that the list Mnemonics is</p>
<pre><code>['1w0j', '1x0j', '1y0j', '1z0j', '1w0k', '1x0k', '1y0k', '1z0k', '1w0l', '1x0l', '1y0l', '1z0l']
</code></pre>
<p>Which is the correct answer. Why is null being returned?</p>
<p>I am not very good at implementing recursion (yet?), your help is appreciated.</p>
| [
{
"answer_id": 74283426,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "dct"
},
{
"answer_id": 74283452,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "data = {\n \"top\": 590,\n \"left\": 105, \n \"width\": 240, \n \"height\": 40,\n \"Zarya\": \"142612a11ad2ca629d2182a51b23d1f2\",\n \"Kiriko\": \"4d0528271fd9d0104cd2af0b1c91f4f6\",\n \"Echo\": \"175b9c62c57b0d6e18577f352fad4afc\",\n \"Sojourn\": \"8ea40548f4472457cfbd46731958a432\",\n \"Sombra\": \"319e88daf8a4b53869c6690cd008ebb0\",\n \"Genji\": \"b5a7156b9a1921099a884e62f2f7c774\",\n \"Reaper\": \"309527687ec1e89f63cfece162c57a66\",\n \"Ana\": \"556e9f3ff210729dc9e1cf848c3c579f\",\n \"Hanzo\": \"13d164a4f37fd7562b53ede9f5fd2671\",\n \"Lucio\": \"d772ddc7e982cd6d714d0a19753c8b32\",\n \"Torbjorn\": \"4fdf46b32b3435c714da7a75ba0ccde2\",\n \"Junkrat\": \"be29c9729daf9e46606ffa26638641ea\",\n \"Moira\": \"0b54634e09e4d108ca248e4e967d15a1\",\n \"Mei\": \"90391ff04b11c73e49c48f9b2738d1b0\",\n \"Dva\": \"859012ee744e79a630522190ef8ef92c\",\n \"Soldier 76\": \"adbd70e889fe6135f372dbd28b7ae5e6\",\n \"Winston\": \"1c4245a79b45f1a0b90e78383078cdd3\",\n \"Tracer\": \"b5465050c403b020aac35da073d4ab11\",\n \"Zenyatta\": \"dccc24bfe5d7b09df7b1387d4c8dfba7\",\n \"Baptiste\": \"4d254bc437560ac21780732fc78ffa08\",\n \"Sigma\": \"3c85376aee36a901bcbf24b07cf60aa2\",\n \"Widowmaker\": \"049092cbd628a54ed22ae5522ca5681c\",\n \"Orisa\": \"113acca96744081964854bd94191310a\",\n \"Ashe\": \"48ca311fb1b288bb811965e6d84d1786\"\n}\n\nkeys = ['top', 'left', 'width', 'height']\n"
},
{
"answer_id": 74283493,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "d"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393019/"
] |
74,283,465 | <p>I have a single page react application that works perfectly fine on my local machine, but when i deploy the app to GitHub pages it runs but does not actually display my application. I know it runs because i noticed i am not getting a 404 page, or even a blank white screen but a screen with the background i chose, and when i change the background in the code and redeploy, the background gets updated. When i check the console, the only error i get is the one i attached. <a href="https://i.stack.imgur.com/nTpdO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nTpdO.png" alt="Console log error" /></a></p>
<p>and <a href="https://i.stack.imgur.com/NicvN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NicvN.png" alt="File which error references" /></a></p>
<p>I am trying to get the application to show up when deployed to GitHub pages rather than just displaying a blank app.</p>
| [
{
"answer_id": 74283426,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "dct"
},
{
"answer_id": 74283452,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 1,
"selected": false,
"text": "data = {\n \"top\": 590,\n \"left\": 105, \n \"width\": 240, \n \"height\": 40,\n \"Zarya\": \"142612a11ad2ca629d2182a51b23d1f2\",\n \"Kiriko\": \"4d0528271fd9d0104cd2af0b1c91f4f6\",\n \"Echo\": \"175b9c62c57b0d6e18577f352fad4afc\",\n \"Sojourn\": \"8ea40548f4472457cfbd46731958a432\",\n \"Sombra\": \"319e88daf8a4b53869c6690cd008ebb0\",\n \"Genji\": \"b5a7156b9a1921099a884e62f2f7c774\",\n \"Reaper\": \"309527687ec1e89f63cfece162c57a66\",\n \"Ana\": \"556e9f3ff210729dc9e1cf848c3c579f\",\n \"Hanzo\": \"13d164a4f37fd7562b53ede9f5fd2671\",\n \"Lucio\": \"d772ddc7e982cd6d714d0a19753c8b32\",\n \"Torbjorn\": \"4fdf46b32b3435c714da7a75ba0ccde2\",\n \"Junkrat\": \"be29c9729daf9e46606ffa26638641ea\",\n \"Moira\": \"0b54634e09e4d108ca248e4e967d15a1\",\n \"Mei\": \"90391ff04b11c73e49c48f9b2738d1b0\",\n \"Dva\": \"859012ee744e79a630522190ef8ef92c\",\n \"Soldier 76\": \"adbd70e889fe6135f372dbd28b7ae5e6\",\n \"Winston\": \"1c4245a79b45f1a0b90e78383078cdd3\",\n \"Tracer\": \"b5465050c403b020aac35da073d4ab11\",\n \"Zenyatta\": \"dccc24bfe5d7b09df7b1387d4c8dfba7\",\n \"Baptiste\": \"4d254bc437560ac21780732fc78ffa08\",\n \"Sigma\": \"3c85376aee36a901bcbf24b07cf60aa2\",\n \"Widowmaker\": \"049092cbd628a54ed22ae5522ca5681c\",\n \"Orisa\": \"113acca96744081964854bd94191310a\",\n \"Ashe\": \"48ca311fb1b288bb811965e6d84d1786\"\n}\n\nkeys = ['top', 'left', 'width', 'height']\n"
},
{
"answer_id": 74283493,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "d"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9452873/"
] |
74,283,477 | <p>There is a list of dates in a form combining month as a string (e.g, Jan) and date as a number (e.g., 13).</p>
<pre class="lang-py prettyprint-override"><code>a = ['20January', '14March', '3December', '1May', '17June', '2February']
</code></pre>
<p>How can I this list to Month-day format (e.g., 0120, 0314, 1203, ...) using <code>datetime.striptime</code>?</p>
| [
{
"answer_id": 74283889,
"author": "Utkonos",
"author_id": 1033217,
"author_profile": "https://Stackoverflow.com/users/1033217",
"pm_score": 2,
"selected": false,
"text": "import datetime\n\na = ['20January', '14March', '3December', '1May', '17June', '2February']\n\nfor entry in a:\n print(datetime.datetime.strptime(entry, '%d%B').strftime('%m%d'))\n"
},
{
"answer_id": 74285628,
"author": "user13322060",
"author_id": 13322060,
"author_profile": "https://Stackoverflow.com/users/13322060",
"pm_score": 0,
"selected": false,
"text": "import datetime\n\na = ['20January', '14March', '3December', '1May', '17June', '2February','31February','ekldnwld']\n\nfor entry in a:\n try:\n print(datetime.datetime.strptime(entry, '%d%B').strftime('%m%d'))\n except ValueError as ve:\n print(ve)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19071067/"
] |
74,283,496 | <p>[![html and css][<a href="https://i.stack.imgur.com/J5y3p.png" rel="nofollow noreferrer">1</a>: <a href="https://i.stack.imgur.com/J5y3p.png%5D%5B1%5D" rel="nofollow noreferrer">https://i.stack.imgur.com/J5y3p.png][1]</a>
what is the proper syntax to make this css element selector work? I cannot seem to change the background color of my page</p>
| [
{
"answer_id": 74283578,
"author": "Chris Schober",
"author_id": 8396541,
"author_profile": "https://Stackoverflow.com/users/8396541",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n <meta charset=\"UTF-8\">\n <title>Personal Size</title>\n <style>\n body {\n width:600px;\n margin:0 auto;\n background-color: #ff9500;\n padding: 0 20px 20px 20px;\n border: 5px solid black;\n }\n </style>\n</head>\n<body>\n \n</body>\n</html>"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15929816/"
] |
74,283,500 | <p>I have a DataFrame that looks like this:</p>
<pre><code>df = pd.DataFrame({
'name': ['John','Mary', 'Phil', 'Sue', 'Robert', 'Lucy', 'Blake'],
'age': ['15', '20s', 37, 'teen', '', 'elderly', 57]
})
df
name age
0 John 15
1 Mary 20s
2 Phil 37
3 Sue teen
4 Robert
5 Lucy elderly
6 Blake 57
</code></pre>
<p>I would like to:</p>
<ol>
<li>convert the <code>age</code> column into integers (where there is an integer already, or where one is able to be deduced, e.g. from a string)</li>
<li>otherwise replace with <code>NaN</code></li>
</ol>
<p>Here is what I'm looking to get:</p>
<pre><code>name age
0 John 15 <--- was originally a string
1 Mary NaN
2 Phil 37
3 Sue NaN
4 Robert NaN
5 Lucy NaN
6 Blake 57
</code></pre>
<p>How would I do this?</p>
| [
{
"answer_id": 74283578,
"author": "Chris Schober",
"author_id": 8396541,
"author_profile": "https://Stackoverflow.com/users/8396541",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n <meta charset=\"UTF-8\">\n <title>Personal Size</title>\n <style>\n body {\n width:600px;\n margin:0 auto;\n background-color: #ff9500;\n padding: 0 20px 20px 20px;\n border: 5px solid black;\n }\n </style>\n</head>\n<body>\n \n</body>\n</html>"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5179643/"
] |
74,283,514 | <p>I am stuck with this tricky part with time manipulation:-</p>
<p><code>start_time = 22.00.00</code> -------------[10pm]</p>
<p><code>end_time = 05.00.00</code> ---------[5.0am]</p>
<p><code>current_time = 01.00.00</code> -----------[1am]</p>
<p>Here, I want to verify my current time is between start and end time.</p>
<p>This line of condition does not work here:-</p>
<pre><code>if start_time < current_time < end_time:
DO THIS
</code></pre>
<p>How am I suppose to handle this ?</p>
| [
{
"answer_id": 74283575,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "datetime.datetime.strptime"
},
{
"answer_id": 74283836,
"author": "Nick",
"author_id": 9473764,
"author_profile": "https://Stackoverflow.com/users/9473764",
"pm_score": 2,
"selected": true,
"text": "HH.MM.SS"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6433588/"
] |
74,283,521 | <pre><code>
data = {'car': ['ford', 'ford','ford','toyota', 'honda', 'toyota','kia', 'nissan','honda'],
'colorblue': [1,1,0,1,1,0,0,0,1],
'colorred': [0,0,1,0,0,1,0,0,0],
'colorblack': [0,0,0,0,0,0,1,1,0],
'volume': [1,1,1,1,1,1,1,1,1]
}
df = pd.DataFrame(data)
df
df['colorbluepercent'] = 100 * df['colorblue'] / df.groupby('car')['colorblue'].transform('sum')
df['colorredpercent'] = 100 * df['colorred'] / df.groupby('car')['colorred'].transform('sum')
df['colorblackpercent'] = 100 * df['colorblack'] / df.groupby('car')['colorblack'].transform('sum')
cargroup = df.groupby('car').sum()
cargroup
</code></pre>
<p>Newish programmer here. I am trying to get the % of total but within the group itself. For instance, Colorblue should be 66% for ford (2/3) instead of 100%. I also tried using the volume column as a denominator, as:</p>
<pre><code>df['colorbluepercent'] = (df.groupby('car') ['colorblue'].transform('sum'))/(df.groupby('car') ['volume'].transform('sum'))
</code></pre>
<p>Is there a way to get the % that will give me the groupedby % of subtotal?
Additionally, this is a sample dataset. The real one has many columns. One thought I had originally is:</p>
<pre><code>feature_cols = df.select_dtypes([np.number]).columns
n = len(feature_cols)
append_str = '_percent'
feature_cols2 = [col + append_str for col in feature_cols]
feature_cols = str(feature_cols)
feature_cols2 = str(feature_cols2)
while n > 0:
df[feature_cols2] = 100 * df[{feature_cols}] / df.groupby('car')[{feature_cols}].transform('sum')
n=n-1
</code></pre>
<p>But I found without str conversion (I also tried tuple) I got an unhashable error, but once I added the str or tuple it indicates the column names are not in the df.</p>
<p>KeyError: "None of [Index(['Index(['colorblue', 'colorred', 'colorblack', 'volume', 'colorblue%',\n 'colorred%', 'colorblack%'],\n dtype='object')'], dtype='object')] are in the [columns]"</p>
<p>So if there is a solution for obtaining % of total for each group that allows me to feed all columns as a list in, that would be best solution.</p>
| [
{
"answer_id": 74283575,
"author": "Modularizer",
"author_id": 15607248,
"author_profile": "https://Stackoverflow.com/users/15607248",
"pm_score": 0,
"selected": false,
"text": "datetime.datetime.strptime"
},
{
"answer_id": 74283836,
"author": "Nick",
"author_id": 9473764,
"author_profile": "https://Stackoverflow.com/users/9473764",
"pm_score": 2,
"selected": true,
"text": "HH.MM.SS"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16931977/"
] |
74,283,527 | <p>I have the following table called "profile":</p>
<p><code>id, name, created_at</code></p>
<p>Every user ( with SupaBase ) has his own row in the "profile" table with his user_id as the key ( id )<br />
I added RLS so that only the user can update/delete his own row but everyone else can only select the row ( anyone can see his profile )</p>
<p>This works great but the issue is that someone could query every single user in the table using <code>SELECT * FROM profile</code> or something similar. I only want people to be able to view a row if they already have their "id" or their "name" with a <code>WHERE</code> statement.</p>
<p>The only solution I see is to remove the ability to SELECT the table ( basically make it private ) and make an API that will query with the admin key ( bypasses the RLS ). That way, no one could query the whole table and the client would just call the API which would then query the data.</p>
<p>However, I would like to query directly from the client so I want to know if there is a different solution that doesn't require an API in between. Currently learning Postgresql so I'm probably missing something really simple.</p>
| [
{
"answer_id": 74283679,
"author": "Amadan",
"author_id": 240443,
"author_profile": "https://Stackoverflow.com/users/240443",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE ... ENABLE ROW LEVEL SECURITY"
},
{
"answer_id": 74284507,
"author": "dshukertjr",
"author_id": 5458913,
"author_profile": "https://Stackoverflow.com/users/5458913",
"pm_score": 3,
"selected": true,
"text": "security definer"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18506312/"
] |
74,283,556 | <p>I am trying to write a function that will allow me to fill the color of certain paths in my SVG image. Here is a snippet of the SVG itself.</p>
<pre><code><svg baseprofile="tiny" fill="#ececec" height="857" stroke="black" stroke-linecap="round" stroke-linejoin="round" stroke-width=".2" version="1.2" viewbox="0 0 2000 857" width="2000" xmlns="http://www.w3.org/2000/svg">
<path d="M1383 261.6l1.5 1.8-2.9 0.8-2.4 1.1-5.9 0.8-5.3 1.3-2.4 2.8 1.9 2.7 1.4 3.2-2 2.7 0.8 2.5-0.9 2.3-5.2-0.2 3.1 4.2-3.1 1.7-1.4 3.8 1.1 3.9-1.8 1.8-2.1-0.6-4 0.9-0.2 1.7-4.1 0-2.3 3.7 0.8 5.4-6.6 2.7-3.9-0.6-0.9 1.4-3.4-0.8-5.3 1-9.6-3.3 3.9-5.8-1.1-4.1-4.3-1.1-1.2-4.1-2.7-5.1 1.6-3.5-2.5-1 0.5-4.7 0.6-8 5.9 2.5 3.9-0.9 0.4-2.9 4-0.9 2.6-2-0.2-5.1 4.2-1.3 0.3-2.2 2.9 1.7 1.6 0.2 3 0 4.3 1.4 1.8 0.7 3.4-2 2.1 1.2 0.9-2.9 3.2 0.1 0.6-0.9-0.2-2.6 1.7-2.2 3.3 1.4-0.1 2 1.7 0.3 0.9 5.4 2.7 2.1 1.5-1.4 2.2-0.6 2.5-2.9 3.8 0.5 5.4 0z" id="AF" name="Afghanistan">
</path>
<path class="Angola" d="M 1121.2 572 1121.8 574 1121.1 577.1 1122 580.1 1121.1 582.5 1121.5 584.7 1109.8 584.6 1109 605.1 1112.6 610.3 1116.2 614.3 1105.8 616.9 1092.3 616 1088.5 613 1065.8 613.2 1065 613.7 1061.7 610.8 1058.1 610.6 1054.7 611.7 1052 612.9 1051.5 608.9 1052.4 603.2 1054.4 597.3 1054.7 594.6 1056.6 588.8 1058 586.2 1061.3 582 1063.2 579.1 1063.8 574.4 1063.5 570.7 1061.9 568.4 1060.4 564.5 1059.1 560.7 1059.4 559.3 1061.1 556.8 1059.5 550.6 1058.3 546.3 1055.5 542.2 1056.1 541 1058.4 540.1 1060.1 540.2 1062.1 539.5 1078.8 539.6 1080.1 544.3 1081.7 548.2 1083 550.3 1085.1 553.6 1088.9 553.1 1090.7 552.2 1093.8 553.1 1094.7 551.5 1096.2 547.8 1099.7 547.5 1100 546.4 1102.9 546.4 1102.4 548.7 1109.2 548.6 1109.3 552.7 1110.4 555.1 1109.5 559 1109.9 563 1111.7 565.4 1111.3 573 1112.7 572.4 1115.1 572.6 1118.6 571.6 1121.2 572 Z">
</path>
<path class="Angola" d="M 1055.3 539 1053.8 534.2 1056.1 531.4 1057.8 530.3 1059.9 532.5 1057.9 533.9 1056.9 535.5 1056.7 538.3 1055.3 539 Z">
</path>
<path d="M1088 228l0.4 1.2 1.4-0.6 1.2 1.7 1.3 0.7 0.6 2.3-0.5 2.2 1 2.7 2.3 1.5 0.1 1.7-1.7 0.9-0.1 2.1-2.2 3.1-0.9-0.4-0.2-1.4-3.1-2.2-0.7-3 0.1-4.4 0.5-1.9-0.9-1-0.5-2.1 1.9-3.1z" id="AL" name="Albania">
</path>
<path d="M1296.2 336.7l1.3 5.1-2.8 0 0 4.2 1.1 0.9-2.4 1.3 0.2 2.6-1.3 2.6 0 2.6-1 1.4-16.9-3.2-2.7-6.6-0.3-1.4 0.9-0.4 0.4 1.8 4.2-1 4.6 0.2 3.4 0.2 3.3-4.4 3.7-4.1 3-4 1.3 2.2z" id="AE" name="United Arab Emirates">
</path>
<path class="Argentina" d="M 669.1 851.7 666.1 851.5 661.1 851.5 655.1 837.9 658.2 840.7 662.5 845.3 670.3 849 677.6 850.5 676.8 853.5 672.4 853.8 669.1 851.7 Z">
</path>
<path class="Argentina" d="M 638.6 644.7 649.9 655.1 654.5 656.1 661.8 660.9 667.7 663.4 668.8 666.2 664.6 676 670.4 677.7 676.7 678.7 680.9 677.7 685.2 672.7 685.5 667.1 688.1 665.8 691.3 669.6 691.7 674.7 687.5 678.2 684.2 680.8 678.9 687.1 672.9 695.8 672.4 701 672 707.6 673.2 714 672.3 715.4 672.7 719.5 673 722.9 680.8 728.4 681 732.8 684.9 735.6 685.2 738.7 681.9 746.9 674.9 750.4 664.7 751.7 658.7 751 660.8 754.9 660.9 759.6 662.7 762.8 660.2 765.1 655.1 766 649.5 763.6 648 765.3 650.5 771.6 654.5 773.5 656.8 771.5 659.3 774.8 655.1 776.8 652.2 780.8 653.4 787.1 653.3 790.5 648.5 790.5 645.5 793.7 645.6 798.5 652.1 803.1 657.3 804.3 657.5 810 652.9 813.5 652.3 820.8 648.8 823.2 647.9 826.1 652.1 832.6 656.7 836.1 654.6 835.8 649.7 834.8 637.6 834 634.1 830.4 632.2 825.8 629.1 826.2 626.5 823.9 623.4 817.4 626.1 814.6 626.2 810.7 624.4 807.5 625.1 802.1 624 793.8 622.2 790.1 624 788.9 622.6 786.5 619.8 785.3 620.6 782.6 617.5 780.2 613.8 772.9 615.5 771.6 612.2 763.8 611.4 757.3 611.2 751.6 613.7 749.3 610.4 743 608.8 737.2 611.8 733 610.4 727.6 612 721.4 610.6 715.5 609 714.3 604.1 703.2 606.2 696.6 604.5 690.4 605.4 684.5 608 678.5 611.3 674.5 609.3 672 610.1 669.9 608.5 659.2 614.1 656.1 615.3 649.4 614.4 647.8 618.4 642 625.9 643.6 629.6 648.2 631.2 643 637.6 643.3 638.6 644.7 Z">
</path>
<path d="M1230.8 253l-1.8 0.2-2.8-3.7-0.2-1-2.3 0-1.9-1.7-1 0.1-2.4-1.8-4.2-1.6-0.1-3.1-1.3-2.2 7-1 1.4 1.6 2.2 1.1-0.7 1.6 3.2 2.2-1.1 2.1 2.6 1.7 2.5 1 0.9 4.5z" id="AM" name="Armenia">
</path>
<path class="Australia" d="M 1743 763.6 1746.7 765.8 1750 764.9 1754.9 763.7 1757.7 764.1 1753.2 771.7 1749.9 773.8 1745.9 779 1745.3 777.2 1738.7 781.6 1737.9 781.3 1734.9 781.1 1735.4 775.7 1737.4 771.5 1738 765.9 1740 763 1743 763.6 Z">
</path>
<path class="Australia" d="M 1793.5 590.2 1794.7 595.2 1798.7 592.8 1800.1 595.5 1802.4 598 1801.3 600.9 1801.5 606.4 1801.7 609.6 1803 610.4 1803.4 615.9 1802.2 619.2 1803 623.5 1808.4 626.9 1811.6 629.9 1814.8 632.7 1813.7 634.3 1816 638.3 1816.5 645.3 1819.1 643.9 1820.6 646.6 1822.2 645.7 1821.5 652.5 1824.4 656.4 1826.3 658.8 1829.1 664 1829.1 669.2 1828.1 672.9 1826.3 676.8 1827 682.3 1824.5 688 1822.4 691 1818.6 696.7 1817.1 700.4 1814 705 1809 710.8 1803.5 714 1799.1 718.9 1795.8 722.1 1791.4 727.6 1787.7 730.8 1783.8 735.6 1780.7 740 1779.9 742.1 1775.6 744.3 1769.5 744.5 1763.2 747.2 1759.4 749.6 1754.6 752.4 1751.9 749.5 1749.3 748.4 1751.9 745.1 1748.4 746.3 1741.2 750.9 1737.6 749.2 1735.2 748.2 1732.4 747.7 1728.3 745.9 1727 741.9 1728.5 737.1 1728.9 733.8 1727.5 731.2 1722.8 730.5 1726 727.3 1726.9 722.6 1722.2 727 1716.9 728.2 1721.4 724.7 1723.9 721 1727.4 717.8 1729 713.1 1722.2 718.5 1717.9 720.7 1713.6 725.8 1710.6 723.2 1712.3 719.8 1710.9 715.1 1709.1 712.7 1710.7 711.2 1705.4 707.3 1701.6 707.2 1697.6 704 1687.7 704.6 1679.8 706.9 1672.9 709.1 1667.9 708.7 1660.9 712 1655.6 713.4 1653.3 716.8 1650.3 719.4 1645.6 719.6 1642 720.1 1637.8 719 1633.6 719.7 1629.8 720 1625.3 723.4 1623.8 723.1 1620.4 724.9 1617 726.9 1613.2 726.7 1609.7 726.7 1605.6 722.6 1603.2 721.4 1604.7 717.7 1607.6 716.8 1609.1 715.4 1609.7 713.1 1612 708.6 1612.7 704.8 1612 698.3 1612.2 694.6 1613.6 691 1612.7 686.8 1613 684.9 1611.3 682.3 1612 677.3 1610.1 672.2 1610 669.5 1611.8 672.3 1611.3 666.3 1613.6 668.2 1614.7 670.7 1615.3 667.4 1613.7 662.3 1613.6 660.3 1612.8 658.4 1614.1 654.7 1615.6 653.1 1616.9 649.9 1617 646.1 1620.1 641.5 1619.7 646.4 1622.8 642 1627.7 639.8 1630.9 637.1 1635.6 634.7 1638.2 634.2 1639.6 635 1644.4 632.6 1647.9 631.9 1649 630.5 1650.5 629.9 1653.6 630.1 1659.8 628.2 1663.3 625.3 1665.3 621.9 1669.2 618.7 1669.9 616.1 1670.6 612.6 1675.5 607.1 1676.9 612.7 1679.5 611.4 1678 608.4 1680.3 605.3 1682.5 606.7 1684 601.8 1687.5 598.6 1689.3 596.1 1692.2 595 1692.6 593.2 1694.9 593.9 1695.3 592.3 1697.9 591.4 1700.7 590.5 1704.4 593.5 1707 597.3 1710.5 597.3 1714 597.9 1713.3 594.4 1716.8 589.3 1719.5 587.6 1718.9 586 1721.8 582.3 1725.5 580 1728.2 580.8 1733.1 579.6 1733.4 576.3 1729.5 574.2 1732.6 573.3 1736.2 574.9 1738.9 577.5 1743.4 579.1 1745.1 578.5 1748.4 580.5 1751.9 578.6 1753.9 579.2 1755.4 577.9 1757.6 581.1 1755.6 584.6 1753.1 587.2 1751.2 587.4 1751.5 589.9 1749.3 593.1 1746.8 596.3 1747 598.1 1750.8 601.7 1754.8 603.7 1757.3 605.9 1760.6 609.7 1762.2 609.7 1764.8 611.4 1765.3 613.4 1770.2 615.5 1774.3 613.3 1776.1 609.9 1777.8 607 1779.1 603.5 1781.7 598.4 1781.5 595.3 1782.2 593.4 1782.1 589.8 1783.5 584.9 1784.8 583.6 1784.2 581.5 1786 578.1 1787.5 574.6 1787.9 572.7 1790.2 570.3 1791.5 573.5 1791.4 577.5 1792.7 578.3 1792.6 581 1794.2 584.2 1794.1 587.9 1793.5 590.2 Z">
</path>
<path d="M1070.6 190.8l-0.3 0.8 0.7 2.1-0.2 2.6-2.8 0 1.1 1.4-1.3 4-0.9 1.1-4.4 0.1-2.4 1.5-4.2-0.5-7.3-1.7-1.3-2.1-4.9 1.1-0.5 1.2-3.1-0.9-2.6-0.2-2.3-1.2 0.7-1.5-0.2-1.1 1.4-0.3 2.7 1.7 0.6-1.7 4.4 0.3 3.5-1.1 2.4 0.2 1.7 1.3 0.4-1.1-1-4.1 1.7-0.8 1.6-2.9 3.8 2.1 2.6-2.6 1.7-0.5 4 1.9 2.3-0.3 2.4 1.2z" id="AT" name="Austria">
</path>
<path class="Azerbaijan" d="M 1229 253.2 1225.2 252.3 1222 249.4 1220.8 246.9 1221.8 246.8 1223.7 248.5 1226 248.5 1226.2 249.5 1229 253.2 Z">
</path>
<path class="Azerbaijan" d="M 1235.3 236.2 1237.8 233.6 1241.3 236.9 1244.9 241.5 1247.4 241.8 1249.3 243.5 1245.1 244 1245.2 249 1244.8 251.2 1243.1 252.7 1243.9 255.8 1242.6 256.2 1238.7 252.8 1239.9 249.7 1238 247.8 1236.1 248.3 1230.8 253 1229.9 248.5 1227.4 247.5 1224.8 245.8 1225.9 243.7 1222.7 241.5 1223.4 239.9 1221.2 238.8 1219.8 237.2 1220.9 236.1 1225.1 238 1228 238.3 1228.6 237.6 1225.3 234.1 1226.5 233.3 1228 233.5 1232.3 237.3 1234.7 237.8 1235.3 236.2 Z">
</path>
<path d="M1154.9 530.4l-0.6 0.1 0-0.3-2-6.1-0.01-0.06-0.09-1.04-1.4-2.9 3.5 0.5 1.7-3.7 3.1 0.4 0.3 2.5 1.2 1.5 0 2.1-1.4 1.3-2.3 3.4-2 2.3z" id="BI" name="Burundi">
</path>
<path d="M1016.5 177.1l-0.4 4.2-1.3 0.2-0.4 3.5-4.4-2.9-2.5 0.5-3.5-2.9-2.4-2.5-2.2-0.1-0.8-2.2 3.9-1.2 3.6 0.5 4.5-1.3 3.1 2.7 2.8 1.5z" id="BE" name="Belgium">
</path>
<path d="M1006.7 427l-0.2 2.1 1.3 3.8-1.1 2.6 0.6 1.7-2.8 4-1.7 2-1.1 4 0.2 4.1-0.3 10.3-4.7 0.8-1.4-4.4 0.3-14.8-1.2-1.3-0.2-3.2-2-2.2-1.7-1.9 0.7-3.4 2-0.7 1.1-2.8 2.8-0.6 1.2-1.9 1.9-1.9 2 0 4.3 3.7z" id="BJ" name="Benin">
</path>
<path d="M988.5 406l-0.5 3.1 0.8 2.9 3.1 4.2 0.2 3.1 6.5 1.5-0.1 4.4-1.2 1.9-2.8 0.6-1.1 2.8-2 0.7-4.9-0.1-2.6-0.5-1.8 1-2.5-0.5-9.8 0.3-0.2 3.7 0.8 4.8-3.9-1.6-2.6 0.2-2 1.6-2.5-1.3-1-2.2-2.5-1.4-0.4-3.7 1.6-2.7-0.2-2.2 4.5-5.3 0.9-4.4 1.5-1.6 2.7 0.9 2.4-1.3 0.8-1.7 4.3-2.8 1.1-2 5.3-2.7 3.1-0.9 1.4 1.2 3.6 0z" id="BF" name="Burkina Faso">
</path>
<path d="M1500.6 360.3l0.6 4.6-2.1-1 1.1 5.2-2.1-3.3-0.8-3.3-1.5-3.1-2.8-3.7-5.2-0.3 0.9 2.7-1.2 3.5-2.6-1.3-0.6 1.2-1.7-0.7-2.2-0.6-1.6-5.3-2.6-4.8 0.3-3.9-3.7-1.7 0.9-2.3 3-2.4-4.6-3.4 1.2-4.4 4.9 2.8 2.7 0.3 1.2 4.5 5.4 0.9 5.1-0.1 3.4 1.1-1.6 5.4-2.4 0.4-1.2 3.6 3.6 3.4 0.3-4.2 1.5 0 4.4 10.2z" id="BD" name="Bangladesh">
</path>
<path d="M1132.6 221.6l-2.3 2.6-1.3 4.5 2.1 3.6-4.6-0.8-5 2 0.3 3.2-4.6 0.6-3.9-2.3-4 1.8-3.8-0.2-0.8-4.2-2.8-2.1 0.7-0.8-0.6-0.8 0.6-2 1.8-2-2.8-2.7-0.7-2.4 1.1-1.4 1.8 2.6 1.9-0.4 4 0.9 7.6 0.4 2.3-1.6 5.9-1.5 4 2.3 3.1 0.7z" id="BG" name="Bulgaria">
</path>
<path d="M1083 214.3l1.9-0.1-1.1 2.8 2.7 2.5-0.5 2.9-1.1 0.3-0.9 0.6-1.6 1.5-0.4 3.5-4.8-2.4-2.1-2.7-2.1-1.4-2.5-2.4-1.3-1.9-2.7-3 0.8-2.6 2 1.5 1-1.4 2.3-0.1 4.5 1.1 3.5-0.1 2.4 1.4z" id="BA" name="Bosnia and Herzegovina">
</path>
<path d="M1141.6 162.7l-3.9-0.2-0.8 0.6 1.5 2 2 4-4.1 0.3-1.3 1.4 0.3 3.1-2.1-0.6-4.3 0.3-1.5-1.5-1.7 1.1-1.9-0.9-3.9-0.1-5.7-1.5-4.9-0.5-3.8 0.2-2.4 1.6-2.3 0.3-0.5-2.8-1.9-2.8 2.8-1.3-0.4-2.4-1.7-2.3-0.6-2.7 4.7 0 4.8-2.3 0.5-3.4 3.6-2-1-2.7 2.7-1 4.6-2.3 5.3 1.5 0.9 1.5 2.4-0.7 4.8 1.4 1.1 2.9-0.7 1.6 3.8 4 2.1 1.1 0 1.1 3.4 1.1 1.7 1.6-1.6 1.3z" id="BY" name="Belarus">
</path>
<path d="M487.8 399.8l-1.7 0 1.3-7.2 0.7-5.1 0.1-1 0.7-0.3 0.9 0.8 2.5-3.9 1.1-0.1-0.1 1 1 0-0.3 1.8-1.3 2.7 0.4 1-0.9 2.3 0.3 0.6-1 3.3-1.3 1.7-1.1 0.2-1.3 2.2z" id="BZ" name="Belize">
</path>
<path d="M662.5 631.4l-0.3-2-5.4-3.3-5.2-0.1-9.6 1.9-2.1 5.6 0.2 3.5-1.5 7.7-1-1.4-6.4-0.3-1.6 5.2-3.7-4.6-7.5-1.6-4 5.8-3.9 0.9-3.1-8.9-3.7-7.2 1.1-6.2-3.2-2.7-1.2-4.6-3.2-4.4 2.9-6.9-2.9-5.4 1.1-2.2-1.2-2.4 1.9-3.2-0.3-5.4 0-4.6 1.1-2.1-5.5-10.4 4.2 0.6 2.9-0.2 1.1-1.9 4.8-2.6 2.9-2.4 7.3-1.1-0.4 4.8 0.9 2.5-0.3 4.3 6.5 5.7 6.4 1.1 2.3 2.4 3.9 1.3 2.5 1.8 3.5 0 3.4 1.9 0.5 3.7 1.2 1.9 0.3 2.7-1.7 0.1 2.8 7.5 10.7 0.3-0.5 3.7 0.8 2.5 3.2 1.8 1.7 4-0.6 5.1-1.3 2.8 0.8 3.6-1.6 1.4z" id="BO" name="Bolivia">
</path>
<path d="M665.8 489.6l3.1 0.6 0.6-1.4-1-1.2 0.6-1.9 2.3 0.6 2.7-0.7 3.2 1.4 2.5 1.3 1.7-1.7 1.3 0.2 0.8 1.8 2.7-0.4 2.2-2.5 1.8-4.7 3.4-5.9 2-0.3 1.3 3.6 3 11.2 3.1 1.1 0.1 4.4-4.3 5.3 1.7 1.9 10.1 1 0.2 6.5 4.3-4.2 7.1 2.3 9.5 3.9 2.8 3.7-0.9 3.6 6.6-2 11 3.4 8.5-0.2 8.4 5.3 7.4 7.2 4.4 1.8 4.8 0.3 2.1 2 2 8.2 1.1 3.9-2.1 10.6-2.7 4.2-7.7 8.9-3.4 7.3-4 5.5-1.4 0.2-1.3 4.7 0.9 12-1.1 9.9-0.3 4.2-1.6 2.6-0.5 8.6-5.2 8.3-0.5 6.7-4.3 2.7-1.1 3.9-6 0-8.5 2.4-3.7 2.9-6 1.9-6.1 5.1-4.1 6.4-0.3 4.8 1.3 3.5-0.3 6.5-0.8 3.1-3.4 3.6-4.5 11.3-4 5-3.2 3.1-1.5 6.1-2.9 3.6-2.1-3.6 1.8-3.1-3.8-4.3-4.8-3.6-6.3-4.1-1.9 0.2-6.3-5-3.4 0.7 6-8.7 5.3-6.3 3.3-2.6 4.2-3.5-0.4-5.1-3.2-3.8-2.6 1.3 0.7-3.7 0.3-3.8-0.3-3.6-2.1-1.1-2 1-2.1-0.3-0.8-2.4-1.1-5.9-1.2-1.9-3.9-1.8-2.2 1.3-5.9-1.3-0.4-8.7-2-3.5 1.6-1.4-0.8-3.6 1.3-2.8 0.6-5.1-1.7-4-3.2-1.8-0.8-2.5 0.5-3.7-10.7-0.3-2.8-7.5 1.7-0.1-0.3-2.7-1.2-1.9-0.5-3.7-3.4-1.9-3.5 0-2.5-1.8-3.9-1.3-2.3-2.4-6.4-1.1-6.5-5.7 0.3-4.3-0.9-2.5 0.4-4.8-7.3 1.1-2.9 2.4-4.8 2.6-1.1 1.9-2.9 0.2-4.2-0.6-3.2 1.1-2.6-0.7-0.1-9.7-4.4 3.7-5-0.1-2.3-3.5-3.8-0.3 1-2.8-3.3-3.9-2.6-5.8 1.5-1.1-0.2-2.8 3.4-1.8-0.7-3.5 1.4-2.2 0.3-3 6.3-4.4 4.6-1.2 0.8-1 5.1 0.3 2.2-17.6 0.1-2.8-0.9-3.6-2.6-2.4 0.1-4.7 3.2-1 1.1 0.7 0.2-2.5-3.3-0.7 0-4 11 0.2 1.9-2.3 1.6 2.1 1 3.8 1.1-0.8 3.1 3.4 4.4-0.4 1.1-2 4.2-1.5 2.4-1.1 0.7-2.7 4.1-1.8-0.3-1.4-4.8-0.5-0.7-4.1 0.3-4.3-2.5-1.6 1.1-0.6 4.1 0.8 4.5 1.6 1.7-1.5 4.1-1 6.4-2.4 2.1-2.5-0.7-1.8 3-0.2 1.2 1.4-0.8 2.9 2 0.9 1.2 3-1.6 2.3-1 5.4 1.4 3.3 0.3 3 3.5 3 2.8 0.3 0.6-1.3 1.8-0.3 2.6-1.1 1.8-1.7 3.2 0.6 1.3-0.3z" id="BR" name="Brazil">
</path>
<path d="M1633.1 472.8l2.2-2.4 4.6-3.6-0.1 3.2-0.1 4.1-2.7-0.2-1.1 2.2-2.8-3.3z" id="BN" name="Brunei Darussalam">
</path>
</code></pre>
<p>My goal is to be able to use JS to manipulate the color of the path. For example, when I add <code>style="fill: green"</code> to one of the path tags, it works, but this is done directly in the svg file. I would also like to do this for ALL path tags with a certain class name. So I'd like to change the color on the image to green for every path tag who's class is "Argentina" for example.</p>
<p>This is what my SVG looks like in HTML</p>
<pre><code> <object
id="color-change-svg"
data="../img/world.svg"
type="image/svg+xml"
>
</object>
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 74283956,
"author": "Dave Pritlove",
"author_id": 2005666,
"author_profile": "https://Stackoverflow.com/users/2005666",
"pm_score": 1,
"selected": false,
"text": "svg"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13569389/"
] |
74,283,572 | <p>I'm currently learning - and I don't understand a lot of specifics about python/pandas. So, there may be an easy fix for this.</p>
<p>currently what I am trying to do is list txt files in a select directory and then be able to select them by number/index. Then for it to be read as a dataframe, for me to run data analysis against.</p>
<p>e.g</p>
<ol>
<li>user inputs directory -> code lists files in folder/directory</li>
</ol>
<pre><code>0.text.txt
1.text2.txt
</code></pre>
<ol start="2">
<li>user should be able to select file by index/number</li>
</ol>
<pre><code>Select file number:
0
</code></pre>
<ol start="3">
<li>and the selected file be passed as a dataframe.</li>
</ol>
<p>Here is what i have tried so far:</p>
<pre><code>#user inputs directory
input_dir = input(r'Enter location of INPUT folder: ')
#list filenames and select file by number selection.
filelist = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
for cnt in range(len(filelist)):
filename = filelist[cnt]
print (cnt, filename)
choice = input("select file number: ")
# open the file based on the key input by user
df = pd.read_csv(filelist[int(choice)])
</code></pre>
<p>outputs:</p>
<pre><code>0 test.txt
1 test2.txt
</code></pre>
<p>however i keep getting the corresponding error after selecting an index:</p>
<pre><code>handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
</code></pre>
| [
{
"answer_id": 74283956,
"author": "Dave Pritlove",
"author_id": 2005666,
"author_profile": "https://Stackoverflow.com/users/2005666",
"pm_score": 1,
"selected": false,
"text": "svg"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20313820/"
] |
74,283,597 | <p>(I'm new to coding and to Swift; apologies in advance if the below is obvious to the more experienced. I've searched Stack Overflow and many other sites and have found only vaguely similar questions, but none quite the same as mine, and none with obviously adaptable answers. Here goes...)</p>
<p>My question is: In Swift, how can I evaluate an array of arrays and return a new array that has had a specified integer removed from each place it previously appeared? Without knowing if it is the best method to do this, I <em>think</em> what I want to do is filter a two dimensional array.</p>
<p>Here's the background: Using Swift Playgrounds, I'm building a simple simulation of how ranked-choice voting works. In my code, this involves creating an array that contains other arrays. My outer array, which I've named "allBallots," is a collection of inner arrays that each contain one or more integers. Each integer represents a vote for a specific candidate.</p>
<p>For instance, the allBallots array might look like this: [[3, 2, 0, 1], [1, 2], [4, 3, 2], [0, 1, 4, 2], [4, 1], [3], [3, 2, 0], [2], [0, 1], [4, 3, 1, 0], [1, 0, 2, 4]]. That represents eleven ballots (i.e., eleven inner arrays) - the first ballot ranks candidate 3 first, candidate 2 second, candidate 0 third, and candidate 1 last. The second ballot ranks candidate 1 first, ranks candidate 2 second, and ranks no one else, and so on for the other ballots.</p>
<p>After each simulated round of voting, my code combs the inner arrays (i.e., each "ballot") and tallies the number of "first-place votes" - that is, the values that appear <em>first</em> in each inner array. What it needs to do next is to remove <em>all</em> votes for the candidate who receives the fewest first-place votes. In the above example, 0 and 1 both appear first twice, 2 appears first once, and 3 and 4 each appear first three times. My code figures out which value appeared first the fewest times - in the above example, it's 2, since 2 appeared first just once. Now it's time to remove all the 2s wherever they appear, but this is the point at which I get stuck.</p>
<p>I want to remove <em>all</em> values of 2 from the whole "allBallots" array - not just the instances that appear first in inner arrays. I've tried .filter, but I can't figure out the syntax that would allow me to use it on a multidimensional array.</p>
<p>For instance, if I try...</p>
<pre><code>var newBallots = allBallots.filter { $0 != 2 }
</code></pre>
<p>...I get an error reading <em>Cannot convert value of type '[Int]' to expected argument type 'Int'</em>. I gather that that one is a problem involving the type system - there's a mismatch between the types of what I specified (the integer 2) and the actual contents of my array (other arrays), but I've no idea how to fix it.</p>
<p>If instead I try...</p>
<pre><code>var newBallots = allBallots.filter { $0 != [2] }
</code></pre>
<p>...I don't encounter an error, and something <em>has</em> been filtered, but only the inner array that consisted exactly of [2] is removed, rather than removing 2 from all locations throughout the array.</p>
<p>If instead I try...</p>
<pre><code>var newBallots = allBallots.filter { $0.contains(2) }
</code></pre>
<p>...no errors, but newBallots contains only [[3, 2, 0, 1], [1, 2], [4, 3, 2], [0, 1, 4, 2], [3, 2, 0], [2], [1, 0, 2, 4]], which is odd. Four arrays have been removed/filtered, but I've no idea why those four. What I wanted was to remove each instance of "2," which is definitely not what happened. I imagine that I'm misusing ".contains" in this context, but I'm at the limits of my understanding here.</p>
<p>Can anyone suggest how I might go about removing a specific value from a two-dimensional array at each place that it exists? Any help much appreciated.</p>
| [
{
"answer_id": 74283684,
"author": "Jacob Lange",
"author_id": 3694524,
"author_profile": "https://Stackoverflow.com/users/3694524",
"pm_score": 3,
"selected": true,
"text": "let allBallots = [[1, 2, 3], [1, 2]]\nlet newBallots = allBallots.reduce(into: []) { partial, element in\n partial.append(element.filter { $0 != 2 })\n}\n\nprint(newBallots) // [[1, 3], [1]]\n"
},
{
"answer_id": 74283941,
"author": "Zoro4rk",
"author_id": 19100950,
"author_profile": "https://Stackoverflow.com/users/19100950",
"pm_score": 0,
"selected": false,
"text": "// 2-dimensional\nlet allBallots = [[1, 2, 3], [1, 2], [2, 0, 3, 4]]\nvar newBallots = [[Int]]()\n\n// travel each 1-dimensional in 2-dimensional\nfor ballot in allBallots {\n \n //This code below equal: `let ballotRemoved2 = ballot.filter { $0 != 2 }`\n var ballotRemoved2 = [Int]()\n for element in ballot {\n if element != 2 { ballotRemoved2.append(element) }\n }\n \n newBallots.append(ballotRemoved2)\n}\n\nprint(newBallots)\n\n\n\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19025641/"
] |
74,283,599 | <p>I'm using Vaadin Flow 23 and want to apply some custom styling to <code>Button</code> (<code><vaadin-button></code>) elements.</p>
<p>I've added a file <code>/frontend/component-styles/button.css</code> where I apply some styles directly to the button itself (no specific theme variant or state):</p>
<pre><code>:host {
border: 1px solid #AEB136;
}
</code></pre>
<p>I've included this by adding <code>@CssImport</code> to a java class like this:</p>
<pre><code>@CssImport(value = "./component-styles/button.css", themeFor = "vaadin-button")
</code></pre>
<p>The problem is that this style is not only applied to <code><vaadin-button></code> elements, but also to <code><vaadin-menu-bar></code> elements, or more precisely the <code><vaadin-menu-bar-button></code> elements they contain. This does not seem to be the case if I specify a particular theme variant or <code>:hover</code> or <code>[active]</code> state.</p>
<p>Do I need to do anything special to make sure <code>:host { }</code> styles are applied to <code><vaadin-button></code> only and not to <code><vaadin-menu-bar-button></code>?</p>
<p><strong>Update</strong></p>
<p>I've noticed I can use <code>:host(vaadin-button) { }</code> to have it applied only to <code><vaadin-button></code>, but I thought <code>themeFor = "vaadin-button"</code> would take care of that?</p>
| [
{
"answer_id": 74283684,
"author": "Jacob Lange",
"author_id": 3694524,
"author_profile": "https://Stackoverflow.com/users/3694524",
"pm_score": 3,
"selected": true,
"text": "let allBallots = [[1, 2, 3], [1, 2]]\nlet newBallots = allBallots.reduce(into: []) { partial, element in\n partial.append(element.filter { $0 != 2 })\n}\n\nprint(newBallots) // [[1, 3], [1]]\n"
},
{
"answer_id": 74283941,
"author": "Zoro4rk",
"author_id": 19100950,
"author_profile": "https://Stackoverflow.com/users/19100950",
"pm_score": 0,
"selected": false,
"text": "// 2-dimensional\nlet allBallots = [[1, 2, 3], [1, 2], [2, 0, 3, 4]]\nvar newBallots = [[Int]]()\n\n// travel each 1-dimensional in 2-dimensional\nfor ballot in allBallots {\n \n //This code below equal: `let ballotRemoved2 = ballot.filter { $0 != 2 }`\n var ballotRemoved2 = [Int]()\n for element in ballot {\n if element != 2 { ballotRemoved2.append(element) }\n }\n \n newBallots.append(ballotRemoved2)\n}\n\nprint(newBallots)\n\n\n\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775138/"
] |
74,283,612 | <p>We have the below formula inside column D of our table</p>
<p>=SUMIFS(Table1[@[10/10/2022]:[30/11/2026]],Table1[[#Headers],[10/10/2022]:[30/11/2026]],">="&TODAY())</p>
<p>Using SUMIFS as we may add other parameters in the future.
Basically we are trying to sum entire rows but only from today in to the future. Historical data entered in these rows would not form the sum total as this would be catered for in the Actual column.</p>
<p>When we built this in a non table format it worked completely fine but now it is not working.</p>
<p>Fore reference, some of the date columns will be filled with numbers to sum and others not. Basically it's hour allocations dependant on the tasks being performed.</p>
<p><a href="https://i.stack.imgur.com/pY4Py.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pY4Py.png" alt="enter image description here" /></a></p>
<p>I'm hoping there is something simple we are missing to get this to work but haven't been able to find anything online.
Can someone please point us in the right direction?
Thanks very much</p>
| [
{
"answer_id": 74283684,
"author": "Jacob Lange",
"author_id": 3694524,
"author_profile": "https://Stackoverflow.com/users/3694524",
"pm_score": 3,
"selected": true,
"text": "let allBallots = [[1, 2, 3], [1, 2]]\nlet newBallots = allBallots.reduce(into: []) { partial, element in\n partial.append(element.filter { $0 != 2 })\n}\n\nprint(newBallots) // [[1, 3], [1]]\n"
},
{
"answer_id": 74283941,
"author": "Zoro4rk",
"author_id": 19100950,
"author_profile": "https://Stackoverflow.com/users/19100950",
"pm_score": 0,
"selected": false,
"text": "// 2-dimensional\nlet allBallots = [[1, 2, 3], [1, 2], [2, 0, 3, 4]]\nvar newBallots = [[Int]]()\n\n// travel each 1-dimensional in 2-dimensional\nfor ballot in allBallots {\n \n //This code below equal: `let ballotRemoved2 = ballot.filter { $0 != 2 }`\n var ballotRemoved2 = [Int]()\n for element in ballot {\n if element != 2 { ballotRemoved2.append(element) }\n }\n \n newBallots.append(ballotRemoved2)\n}\n\nprint(newBallots)\n\n\n\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393212/"
] |
74,283,683 | <p>I am learning python and have the following code in test.py:</p>
<pre><code>string = input()
print(string)
</code></pre>
<p>Contrary to tutorials, it gives me an error:</p>
<pre><code> string = input()
EOFError: EOF when reading a line
</code></pre>
<p>I have no idea what I do wrong here! Any help appreciated!</p>
| [
{
"answer_id": 74283901,
"author": "poiboi",
"author_id": 8341844,
"author_profile": "https://Stackoverflow.com/users/8341844",
"pm_score": 0,
"selected": false,
"text": "EOFError"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19740745/"
] |
74,283,717 | <p>I have access to two APIs. The first (and better API) responds with 404 for certain types of input. If the first API responds with 404 I want to send a request to the second API.</p>
<p>The log shows this after a 404:</p>
<pre class="lang-js prettyprint-override"><code>{
insertId: "0987654321"
labels: {2}
logName: "projects/my-awesome-project/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2022-11-01T21:41:50.570143002Z"
resource: {2}
textPayload: "Exception from a finished function: HTTPError: Response code 404 (NOT FOUND)"
timestamp: "2022-11-01T21:41:50.251844Z"
trace: "projects/my-awesome-project/traces/1234567890"
}
</code></pre>
<p>I'm guessing that the code will look something like this:</p>
<pre class="lang-js prettyprint-override"><code>try {
async function callFirstAPI() {
const response = await got(url, options).json();
// if successful do stuff with the data
callFirstAPI();
}
} catch (error) {
if (error.textPayload.includes('404') {
callBackupAPI();
}
}
</code></pre>
<p>What doesn't work is this. Nothing logs when the API throws a 404.</p>
<pre class="lang-js prettyprint-override"><code>try {
async function callFirstAPI() {
const response = await got(url, options).json();
console.log(response); // nothing logs
callFirstAPI();
}
} catch (error) {
console.error("Error!!! " + error); // nothing logs
}
</code></pre>
<p>Is <code>catch</code> not firing because a <code>404</code> response isn't considered an error? I.e., the <code>callFirstAPI</code> ran without crashing?</p>
| [
{
"answer_id": 74283901,
"author": "poiboi",
"author_id": 8341844,
"author_profile": "https://Stackoverflow.com/users/8341844",
"pm_score": 0,
"selected": false,
"text": "EOFError"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5153354/"
] |
74,283,785 | <p>I want to combine the two tables below in Big Query using a full outer join. Table A does not have certain products that I need to bring over from table B, but when I join on campaign & subcampaign, my join is not bringing over the <code>'CellPhone'</code> data. My results looks more like a left join. See below for my query</p>
<pre><code>SELECT
a.campaign
, a.subcampaign
, a.product
, sum(sales)
, sum(cost)
FROM
(
SELECT
campaign
, subcampaign
, product
, sum(sales)
FROM
table_a
GROUP BY
1, 2, 3
) a
FULL OUTER JOIN
(
SELECT
campaign
, subcampaign
, product
, sum(cost)
FROM
table_b
GROUP BY 1,2,3
) b
ON
a.campaign = b.campaign
AND a.subcampaign = b.subcampaign
GROUP BY
1,2,3
</code></pre>
<p>Table a</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Campaign</th>
<th>Subcampaign</th>
<th>Product</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Campaign 1</td>
<td>Store 581</td>
<td>Gaming</td>
<td>$50</td>
</tr>
<tr>
<td>Campaign 1</td>
<td>Store 583</td>
<td>TV</td>
<td>$100</td>
</tr>
</tbody>
</table>
</div>
<p>Table b</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Campaign</th>
<th>Subcampaign</th>
<th>Product</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>Campaign 1</td>
<td>Store 581</td>
<td>Gaming</td>
<td>$25</td>
</tr>
<tr>
<td>Campaign 1</td>
<td>Store 583</td>
<td>TV</td>
<td>$75</td>
</tr>
<tr>
<td>Campaign 1</td>
<td>Store 584</td>
<td>Cellphone</td>
<td>$10</td>
</tr>
</tbody>
</table>
</div>
<p>Desired result:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Campaign</th>
<th>Subcampaign</th>
<th>Product</th>
<th>Sales</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>Campaign 1</td>
<td>Store 581</td>
<td>Gaming</td>
<td>$50</td>
<td>$25</td>
</tr>
<tr>
<td>Campaign 1</td>
<td>Store 583</td>
<td>TV</td>
<td>$100</td>
<td>$75</td>
</tr>
<tr>
<td>Campaign 1</td>
<td>Store 584</td>
<td>Cellphone</td>
<td>NULL</td>
<td>$10</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74283901,
"author": "poiboi",
"author_id": 8341844,
"author_profile": "https://Stackoverflow.com/users/8341844",
"pm_score": 0,
"selected": false,
"text": "EOFError"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12086629/"
] |
74,283,819 | <p>When I use this command to create a new Nuxt 3 project:</p>
<pre><code>npx nuxi init nuxt-app
</code></pre>
<p>It outputs this error:</p>
<pre><code> ERROR (node:1752) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time 09:53:25
(Use `node --trace-warnings ...` to show where the warning was created)
ERROR Failed to download template from registry: fetch failed 09:53:25
at /C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13269:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async downloadTemplate (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13268:20)
at async Object.invoke (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13336:15)
at async _main (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/cli.mjs:50:20)
</code></pre>
<p>My environments:</p>
<ul>
<li>Operating System: Windows 11</li>
<li>node version : 18.12.0</li>
<li>npm version: 8.12.1</li>
</ul>
<p>At first I suspected that this was due to my network. But I didn't get an error when I tried to install other npm packages.</p>
| [
{
"answer_id": 74286219,
"author": "Starbugz",
"author_id": 12998158,
"author_profile": "https://Stackoverflow.com/users/12998158",
"pm_score": 2,
"selected": true,
"text": "raw.githubusercontent.com"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12998158/"
] |
74,283,837 | <p>I've started a document-base macOS app in SwiftUI and am using a FileDocument (not a Reference FileDocument) as the type of document. In every tutorial I've seen, even in Apple's own WWDC video discussing it (<a href="https://developer.apple.com/wwdc20/10039" rel="nofollow noreferrer">https://developer.apple.com/wwdc20/10039</a>), a <strong>struct</strong> is always used to define the FileDocument.</p>
<p><strong>My question is:</strong> is there an issue with using a class in the struct defining the document. Doing so doesn't result in any Xcode warnings but I wanted to be sure I'm not creating any issues for my app before going down this path.</p>
<p>Below is some example code for what I'm talking about: declaring <code>TestProjectData</code> as a class for use within the <code>DocumentDataAsClassInsteadOfStructDocument</code> - struct as a FileDocument?</p>
<pre><code>public class TestProjectData: Codable{
var anotherString: String
init(){
anotherString = "Hello world!"
}
}
struct DocumentDataAsClassInsteadOfStructDocument: FileDocument, Codable {
var project: TestProjectData
init() {
project = TestProjectData()
}
static var readableContentTypes: [UTType] { [.exampleText] }
init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let _ = String(data: data, encoding: .utf8)
else {
throw CocoaError(.fileReadCorruptFile)
}
let fileContents = try JSONDecoder().decode(Self.self, from: data)
self = fileContents
}
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let data = try JSONEncoder().encode(self)
return .init(regularFileWithContents: data)
}
}
</code></pre>
| [
{
"answer_id": 74286219,
"author": "Starbugz",
"author_id": 12998158,
"author_profile": "https://Stackoverflow.com/users/12998158",
"pm_score": 2,
"selected": true,
"text": "raw.githubusercontent.com"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1542125/"
] |
74,283,860 | <p>I have multiple rows of data that look like the following:</p>
<p><strong>dgov-nonprod-adp-personal.groups</strong></p>
<p><strong>dgov-prod-gcp-sensitive.groups</strong></p>
<p>I want to get the text between the last hyphen and before the period so:</p>
<p><strong>personal</strong></p>
<p><strong>sensitive</strong></p>
<p>I have this regex <code>(?:prod-(.*)-)(.*).groups</code> however it gives two groups and in bigquery I can only extract if there is one group, what would the regex be to just extract the text i want?</p>
<p>Note: after the second hyphen and before the third it will always be prod or nonprod, that's why in my original regex i use <code>prod-</code> since that will be a constant</p>
| [
{
"answer_id": 74286219,
"author": "Starbugz",
"author_id": 12998158,
"author_profile": "https://Stackoverflow.com/users/12998158",
"pm_score": 2,
"selected": true,
"text": "raw.githubusercontent.com"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17928364/"
] |
74,283,876 | <p>How can I run below file?</p>
<p>Here is my code:</p>
<p>main.py</p>
<pre><code>def calculation(a, b):
print(a)
return a
</code></pre>
<p>I have tried, py main.py it does not return anything.</p>
| [
{
"answer_id": 74283885,
"author": "mlokos",
"author_id": 19570235,
"author_profile": "https://Stackoverflow.com/users/19570235",
"pm_score": 2,
"selected": true,
"text": "def calculation(a, b):\n print(a)\n return a\n\nprint(calculation(1, 3))\n"
},
{
"answer_id": 74283904,
"author": "bn_ln",
"author_id": 10535824,
"author_profile": "https://Stackoverflow.com/users/10535824",
"pm_score": 1,
"selected": false,
"text": "sys.argv"
},
{
"answer_id": 74283987,
"author": "Python Nerd",
"author_id": 19629009,
"author_profile": "https://Stackoverflow.com/users/19629009",
"pm_score": 0,
"selected": false,
"text": "calculation(a, b)"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20256558/"
] |
74,283,883 | <p>I have a mini assignment where I have to review the fundamentals of classes and properties. In the context of this code, I am trying to figure out how to print all the properties for each task that is stored in a list.</p>
<p>Here is the code. The commented out code is what I tried so far to print all the properties for each task stored in TaskList.</p>
<pre><code>namespace FunProject
{
internal class Program
{
static void Main(string[] args)
{
var person1 = new Person
{
FirstName = "Mister",
LastName = "Programmer",
Age = 26
};
Console.WriteLine(person1.FullName());
var Task1 = new Task
{
TaskName = "read",
Description = "gain knowledge",
Id = 1,
IsDone = true
};
var Task2 = new Task
{
TaskName = "eat",
Description = "gain sustenance",
Id = 2,
IsDone = false
};
person1.TaskList = new List<Task>();
person1.TaskList.Add(Task1);
person1.TaskList.Add(Task2);
//Person1.TaskList.ForEach(i => Console.Write("{0}\t", i));
//Person1.TaskList.ForEach (x => Console.WriteLine(x));
//Console.WriteLine(String.Join("{0}\t", Person1.TaskList.ToString()));
//foreach (Task t in Person1.TaskList)
//{
// Console.WriteLine(t);
//}
Console.Read();
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set;}
public int Age { get; set; }
public List<Task>TaskList { get; set; }
public string FullName()
{
return ($"{FirstName} {LastName}");
}
}
public class Task
{
public int Id { get; set; }
public string TaskName { get; set;}
public string Description { get; set; }
public bool ?IsDone { get; set;}
}
}
</code></pre>
<p>Output should be something like:</p>
<pre><code>Mister Programmer
Current Tasks:
TaskName: read
TaskDescription: gain knowledge
Id: 1
IsDone: true
TaskName: eat
TaskDescription: gain sustenance
Id: 2
IsDone: false
</code></pre>
| [
{
"answer_id": 74283885,
"author": "mlokos",
"author_id": 19570235,
"author_profile": "https://Stackoverflow.com/users/19570235",
"pm_score": 2,
"selected": true,
"text": "def calculation(a, b):\n print(a)\n return a\n\nprint(calculation(1, 3))\n"
},
{
"answer_id": 74283904,
"author": "bn_ln",
"author_id": 10535824,
"author_profile": "https://Stackoverflow.com/users/10535824",
"pm_score": 1,
"selected": false,
"text": "sys.argv"
},
{
"answer_id": 74283987,
"author": "Python Nerd",
"author_id": 19629009,
"author_profile": "https://Stackoverflow.com/users/19629009",
"pm_score": 0,
"selected": false,
"text": "calculation(a, b)"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8046535/"
] |
74,283,903 | <p><a href="https://i.stack.imgur.com/fdDG9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fdDG9.png" alt="enter image description here" /></a></p>
<p>I mean the green rounded border that's outside the check icon. Currently, I have the entire circle around the check but I'm really confused about how to introduce that little cut in the top-left corner.</p>
<p>Here's the code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><div v-if="verified" class="flex justify-center items-center border-3 border-green rounded-full">
<svg viewBox="0 0 15 14" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-3 h-3">
<path
d="m10.51 4.525-3.6 3.6-1.65-1.65a.636.636 0 0 0-.9.9l2.1 2.1a.636.636 0 0 0 .9 0l4.05-4.05a.636.636 0 0 0-.9-.9z"
fill="#fff"
/>
</svg>
</div></code></pre>
</div>
</div>
</p>
<p>There's the SVG, and I'm using Tailwind, so the border class is right there in the <code><div></code>. Any suggestion/help is greatly appreciated, thanks!</p>
| [
{
"answer_id": 74284003,
"author": "Saroj Shrestha",
"author_id": 4217452,
"author_profile": "https://Stackoverflow.com/users/4217452",
"pm_score": 2,
"selected": true,
"text": "#circle {\n width: 200px;\n height: 200px;\n border-radius: 50%;\n border: 5px solid green;\n border-left: 5px solid white;\n transform: rotate(45deg);\n}"
},
{
"answer_id": 74284012,
"author": "Chris Schober",
"author_id": 8396541,
"author_profile": "https://Stackoverflow.com/users/8396541",
"pm_score": 0,
"selected": false,
"text": "<div class=\"p-24 flex items-center justify-center\">\n <div class=\"flex relative justify-center items-center w-auto border-[3px] border-green-400 rounded-lg px-8 py-3 \n before:block before:absolute before:-left-[3px] before:-top-[3px] before:w-[calc(50%+3px)] before:h-[calc(50%+3px)] z-10 before:bg-white\">\n <span class=\"relative z-20\">Your Button</span>\n </div>\n</div>"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17655903/"
] |
74,283,983 | <p>I have a web app that uses a websocket to receive information from an API I have put together.</p>
<p>Everything works great, however, every time new information arrives from the websocket, the whole list on my frontend (React) is updated.</p>
<p>Here is the relevent code:</p>
<pre><code> componentDidMount(prevState) {
socketIO.on('newNotification', (response) => {
const notifications = this.state.notifications;
console.log(response)
const newNotifications = response.data
this.setState(prevState => ({
notifications: [...this.state.notifications, newNotifications]
}))
});
}
</code></pre>
<p>notifications is a list of notifications that is received from my API, which I set to the state.notifications whenever a response is received.</p>
<p>My understanding is React only updates what it needs to, so I'm not sure what is going on.</p>
<p>Here is my Notification component:</p>
<pre><code>import React from "react"
class Notification extends React.Component {
render(){
return(
<ul>
<li
key = {this.props.notification.id}
onClick={() => this.props.deleteNotificationProps(this.props.notification.id)}>
<div className='separator-container'>
<div className={'notification-border ' + this.props.notification.stat_abr}>
<div className='notification' >
<div className='left-notification'>
<div className = 'stat-abr'>{this.props.notification.stat_abr}</div>
<div className = 'game-time'>{this.props.notification.game_time_string}</div>
</div>
<div className='middle-notification'>
<div className='player-image'>
<img src={"http://nhl.bamcontent.com/images/headshots/current/168x168/" + this.props.notification.player_id.toString() + ".jpg"} alt="" className="player-img" />
</div>
</div>
<div className = 'right-notification'> {this.props.notification.description} </div>
</div>
</div>
</div>
</li>
</ul>
)
}
}
export default Notification
</code></pre>
<p>I tried various diferent methods of updating the state, but nothing seems to work.</p>
<p>EDIT: here is the NotificationList class where the Notification component is created:</p>
<pre><code>class NotificationList extends React.Component {
render() {
return(
<ul>
{this.props.notifications.map(notification => (
<Notification
id = {notification.id}
notification = {notification}
handleChangeProps = {this.props.handleChangeProps}
deleteNotificationProps = {this.props.deleteNotificationProps}
/>
))}
</ul>
)
}
}
</code></pre>
| [
{
"answer_id": 74284009,
"author": "Nick Grealy",
"author_id": 782034,
"author_profile": "https://Stackoverflow.com/users/782034",
"pm_score": 1,
"selected": false,
"text": "Notification"
},
{
"answer_id": 74296921,
"author": "dvdrplus",
"author_id": 19677375,
"author_profile": "https://Stackoverflow.com/users/19677375",
"pm_score": 0,
"selected": false,
"text": "<ul></ul>"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74283983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19677375/"
] |
74,284,011 | <p>I received a homework assignment to create a shopping list program where it will ask the user for a list of ingredients, and after the user enters them, it will compare the inputs to a "pantry list" to see if everything is available. If yes, then it will print out "You got everything you need!" and if no, it will print out "You still need" + "item that is missing." The specific instructions are:</p>
<ol>
<li>A pre-created list for pantry items</li>
<li>User input into an ingredient list</li>
<li>Pass the ingredient list to a method</li>
<li>Use a conditional and loop in the method</li>
<li>Print out the results of whether the user needs to go shopping based on the items in the ingredient list that are not in the pantry.</li>
</ol>
<p>Below is my code:</p>
<pre><code>import java.util.Scanner;
import java.util.ArrayList;
public class TheList
{
public static String linearSearch(ArrayList<String> pantry, ArrayList<String> input)
{
for (int i = 0; i < pantry.size(); i++)
{
if (pantry == input)
{
return "You got everything you need!";
}
}
return "You still need something!";
}
public static void main(String[] args)
{
// Create list for pantry items
ArrayList<String> pantry = new ArrayList<String>();
pantry.add("Bread");
pantry.add("Peanut Butter");
pantry.add("Chips");
pantry.add("Jelly");
//Create list for input items
ArrayList<String> input = new ArrayList<String>();
input.add("ingredientOne");
input.add("ingredientTwo");
input.add("ingredientThree");
input.add("ingredientFour");
// Execution
input();
System.out.println(linearSearch(pantry, input));
}
private static void input()
{
Scanner ingredientScan = new Scanner(System.in);
System.out.println("Please enter an ingredient: ");
String ingredientOne = ingredientScan.nextLine();
System.out.println(ingredientOne + " Done.");
System.out.println("Please enter an ingredient: ");
String ingredientTwo = ingredientScan.nextLine();
System.out.println(ingredientTwo + " Done.");
System.out.println("Please enter an ingredient: ");
String ingredientThree = ingredientScan.nextLine();
System.out.println(ingredientThree + " Done.");
System.out.println("Please enter an ingredient: ");
String ingredientFour = ingredientScan.nextLine();
System.out.println(ingredientFour + " Done.");
}
}
</code></pre>
<p>What am I missing? This is pretty amateur, but I am a beginner and really need some help!</p>
<p>My main question is the if part for the loop in the linearSearch string. When I execute the program, it always print out "You still need something!" As for which thing is missing, I have no clue where to start in that aspect.</p>
| [
{
"answer_id": 74284009,
"author": "Nick Grealy",
"author_id": 782034,
"author_profile": "https://Stackoverflow.com/users/782034",
"pm_score": 1,
"selected": false,
"text": "Notification"
},
{
"answer_id": 74296921,
"author": "dvdrplus",
"author_id": 19677375,
"author_profile": "https://Stackoverflow.com/users/19677375",
"pm_score": 0,
"selected": false,
"text": "<ul></ul>"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393637/"
] |
74,284,034 | <p><strong>Case 1 :</strong> replace with function return results <code>j<*zz</code></p>
<pre><code>const str = 'z<*zj';
const letters = Array.from(str.replace(/[^a-zA-Z]/gm, ''));
const result = str.replace(/[a-zA-Z]/gm, () => letters.pop());
console.log('result', result); // result => j<*zz/
</code></pre>
<p><strong>Case 2 :</strong> replace without function return results <code>j<*jj</code></p>
<pre><code>const str = 'z<*zj';
const letters = Array.from(str.replace(/[^a-zA-Z]/gm, ''));
const result = str.replace(/[a-zA-Z]/gm, letters.pop());
console.log('result', result); // result => j<*jj/
</code></pre>
<p>So, It differs with function integration. what is behind ? Need the help to understand.</p>
| [
{
"answer_id": 74284370,
"author": "phasma",
"author_id": 3932026,
"author_profile": "https://Stackoverflow.com/users/3932026",
"pm_score": 1,
"selected": false,
"text": "String.prototype.replace"
},
{
"answer_id": 74285300,
"author": "Rohìt Jíndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 3,
"selected": true,
"text": "documentation"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2024080/"
] |
74,284,106 | <p>i have a question. How can i create list of a list from xml dataset in ElemenTree python? for example i have this dataset :</p>
<pre><code><data>
<article>
<author> Tony </author>
</article>
<article>
<author> Andy </author>
<author> John </author>
</article>
<article>
<author> Paul </author>
<author> leon </author>
</article>
</data>
</code></pre>
<p>There is a specific function like :</p>
<pre><code>tree = ET.parse('data.xml')
root = tree.getroot()
for author in root.iter('author'):
print(author.text, author.attrib['pid'])
</code></pre>
<p>that would find and show all author in dataset in single list <code>[Tony, Andy, John, Paul, Leon]</code>. How can i improve those code above so i can get result author in list of s list <code>[[Tony], [Andy, John], [Paul, Leon]]</code>? Maybe theres is a specific function to perform this?</p>
| [
{
"answer_id": 74284315,
"author": "Adi OS",
"author_id": 14383188,
"author_profile": "https://Stackoverflow.com/users/14383188",
"pm_score": 1,
"selected": true,
"text": "child"
},
{
"answer_id": 74295064,
"author": "balderman",
"author_id": 415016,
"author_profile": "https://Stackoverflow.com/users/415016",
"pm_score": 1,
"selected": false,
"text": "import xml.etree.ElementTree as ET\n\nxml = '''<data>\n <article>\n <author> Tony </author>\n </article>\n <article>\n <author> Andy </author>\n <author> John </author>\n </article>\n <article>\n <author> Paul </author>\n <author> leon </author>\n </article>\n</data>'''\nroot = ET.fromstring(xml)\nauthors = [[aut.text for aut in art.findall('author')] for art in root.findall('./article')]\nprint(authors)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14383188/"
] |
74,284,119 | <p>The requirement is to get an error when the activeState value given by the user is not true or false. If the user gives true or false, the code should give "passed" as output and any other input other than true or false should give "failed" as output.</p>
<p>Here is my code-</p>
<pre><code>...
public static boolean isActive(Boolean activeState){
boolean flag=false;
if(activeState !=null && (activeState.equals(true)||activeState.equals(false)))
{
flag=true;
}
return flag;
}
...
</code></pre>
<pre><code>activeState Output
true passed
false passed
null no output
true# no output
trrrrue no output
@false no output
Lucas no output
</code></pre>
<p>As per my observation the code is giving required output only when the user gives valid input ie. True or False. But when any other input value is being given ie. null,truuee,false#; nothing is coming as an output. It is neither giving any error nor any output, just blank. No response is getting generated.</p>
<p>I have checked out solutions where by changing the datatype of the input field fixes the issue, but I can't change the data type of activeState from Boolean to String. Is there any way to validate the activeState so that it can validate all the input values and generate output as required without changing the datatype?</p>
| [
{
"answer_id": 74284818,
"author": "Basil Bourque",
"author_id": 642706,
"author_profile": "https://Stackoverflow.com/users/642706",
"pm_score": 0,
"selected": false,
"text": "boolean"
},
{
"answer_id": 74284895,
"author": "oleg.cherednik",
"author_id": 3461397,
"author_profile": "https://Stackoverflow.com/users/3461397",
"pm_score": 0,
"selected": false,
"text": "Boolean"
},
{
"answer_id": 74284928,
"author": "ptan9o",
"author_id": 12160558,
"author_profile": "https://Stackoverflow.com/users/12160558",
"pm_score": 1,
"selected": false,
"text": "b"
},
{
"answer_id": 74285793,
"author": "Christoph Dahlen",
"author_id": 20370596,
"author_profile": "https://Stackoverflow.com/users/20370596",
"pm_score": 0,
"selected": false,
"text": "public static String validateIsActive(final String userInput) {\n return new Boolean(userInput) ? \"passed\" : \"failed\";\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393645/"
] |
74,284,137 | <p>I simply want to pass an <code>&arr</code> in C language.</p>
<p>For example:</p>
<pre><code>#include <stdio.h>
void test( PARAMETER??? )
{
return;
}
int main()
{
int arr[] = {1,2,3,4,5,6,7,8};
test(&arr);
return 0;
}
</code></pre>
<p>How should I declare the parameter?</p>
<p>As it is of type <code>int (*)[8]</code></p>
<p>I simply want to pass <code>&arr</code> in C language. I know I can pass <code>arr</code> and <code>length</code> argument, but how can I via this?</p>
| [
{
"answer_id": 74284182,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 3,
"selected": true,
"text": "int (*)[8]"
},
{
"answer_id": 74284189,
"author": "273K",
"author_id": 6752050,
"author_profile": "https://Stackoverflow.com/users/6752050",
"pm_score": -1,
"selected": false,
"text": "void test(int prm[restrict 8]);\n"
},
{
"answer_id": 74284245,
"author": "user8811698",
"author_id": 8811698,
"author_profile": "https://Stackoverflow.com/users/8811698",
"pm_score": 1,
"selected": false,
"text": "sizeof()"
},
{
"answer_id": 74284781,
"author": "ikegami",
"author_id": 589924,
"author_profile": "https://Stackoverflow.com/users/589924",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n\nvoid test( size_t n, int *p ) { // `p` is a pointer an `int`.\n printf( \"%zu\\n\", sizeof(p) ); // `sizeof( int* )`, 8 for me.\n printf( \"%zu\\n\", sizeof(*p) ); // `sizeof( int )`, 4 for me.\n printf( \"%d\\n\", p[0] ); // 1\n printf( \"%d\\n\", p[1] ); // 2\n}\n\nint main( void ) {\n int arr[] = {1,2,3,4,5,6,7,8,9,10,11};\n test( sizeof(arr)/sizeof(*arr), arr );\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17156716/"
] |
74,284,156 | <p>I have a dataframe that looks like this:</p>
<pre><code>df = pd.DataFrame({
'name': ['John','William', 'Nancy', 'Susan', 'Robert', 'Lucy', 'Blake', 'Sally', 'Bruce'],
'injury': ['right hand broken', 'lacerated left foot', 'foot broken', 'right foot fractured', '', 'sprained finger', 'chest pain', 'swelling in arm', 'laceration to arms, hands, and foot']
})
name injury
0 John right hand broken
1 William lacerated left foot
2 Nancy foot broken
3 Susan right foot fractured
4 Robert
5 Lucy sprained finger
6 Blake chest pain
7 Sally swelling in arm
8 Bruce lacerations to arm, hands, and foot <-- this is a weird case, since there are multiple body parts
</code></pre>
<p>Notably, some of the values in the <code>injury</code> column are blank.</p>
<p>I want to replace the values in the <code>injury</code> column with <em><strong>only the affected body part</strong></em>. In my case, that would be hand, foot, finger, and chest, arm. There are dozens more... this is a small example.</p>
<p>The desired dataframe would look like this:</p>
<pre><code> name injury
0 John hand
1 William foot
2 Nancy foot
3 Susan foot
4 Robert
5 Lucy finger
6 Blake chest
7 Sally arm
8 Bruce arm, hand, foot
</code></pre>
<p>I could do something like this:</p>
<pre><code>df.loc[df['injury'].str.contains('hand'), 'injury'] = 'hand'
df.loc[df['injury'].str.contains('foot'), 'injury'] = 'foot'
df.loc[df['injury'].str.contains('finger'), 'injury'] = 'finger'
df.loc[df['injury'].str.contains('chest'), 'injury'] = 'chest'
df.loc[df['injury'].str.contains('arm'), 'injury'] = 'arm'
</code></pre>
<p>But, this might not be the most elegant way.</p>
<p>Is there a more elegant way to do this? (e.g. using a dictionary)</p>
<p>(any advice on that last case with multiple body parts would be appreciated)</p>
<p>Thank you!</p>
| [
{
"answer_id": 74284182,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 3,
"selected": true,
"text": "int (*)[8]"
},
{
"answer_id": 74284189,
"author": "273K",
"author_id": 6752050,
"author_profile": "https://Stackoverflow.com/users/6752050",
"pm_score": -1,
"selected": false,
"text": "void test(int prm[restrict 8]);\n"
},
{
"answer_id": 74284245,
"author": "user8811698",
"author_id": 8811698,
"author_profile": "https://Stackoverflow.com/users/8811698",
"pm_score": 1,
"selected": false,
"text": "sizeof()"
},
{
"answer_id": 74284781,
"author": "ikegami",
"author_id": 589924,
"author_profile": "https://Stackoverflow.com/users/589924",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n\nvoid test( size_t n, int *p ) { // `p` is a pointer an `int`.\n printf( \"%zu\\n\", sizeof(p) ); // `sizeof( int* )`, 8 for me.\n printf( \"%zu\\n\", sizeof(*p) ); // `sizeof( int )`, 4 for me.\n printf( \"%d\\n\", p[0] ); // 1\n printf( \"%d\\n\", p[1] ); // 2\n}\n\nint main( void ) {\n int arr[] = {1,2,3,4,5,6,7,8,9,10,11};\n test( sizeof(arr)/sizeof(*arr), arr );\n}\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5179643/"
] |
74,284,202 | <p>I'm trying to use <code>posix_openpt</code> on Mac. The issue I'm seeing is that I get a file descriptor back from <code>posix_openpt</code>. I use the file descriptor for reading and create a copy using <code>dup</code> for writing. The issue I'm running into is that when I write to the master file descriptor, I read that data back out from the master. So no data ends up at the slave. I confirmed this by using <code>posix_spawnp</code> to run a program with stdin/stdout/stderr set to the slave file. The program hangs indefinitely waiting for input. Here is my code (note, all error handling was removed for legibility):</p>
<pre><code> int master_fd = posix_openpt(O_RDWR);
grantpt(master_fd);
unlockpt(master_fd);
char *slave_filename_orig = ptsname(master_fd);
size_t slave_filename_len = strlen(slave_filename_orig);
char slave_filename[slave_filename_len + 1];
strcpy(slave_filename, slave_filename_orig);
posix_spawn_file_actions_t fd_actions;
posix_spawn_file_actions_init(&fd_actions);
posix_spawn_file_actions_addopen(&fd_actions, STDIN_FILENO, slave_filename, O_RDONLY, 0644);
posix_spawn_file_actions_addopen(&fd_actions, STDOUT_FILENO, slave_filename, O_WRONLY, 0644);
posix_spawn_file_actions_adddup2(&fd_actions, STDOUT_FILENO, STDERR_FILENO);
pid_t pid;
posix_spawnp(&pid, "wc", &fd_actions, NULL, NULL, NULL);
int master_fd_write = dup(master_fd);
char *data = "hello world";
write(master_fd_write, data, strlen(data));
close(master_fd_write);
char buffer[1024];
read(master_fd, buffer, 1024); // <- Issue Here
// buffer now contains hello world. It should contain the output of `wc`
</code></pre>
| [
{
"answer_id": 74285218,
"author": "n. m.",
"author_id": 775806,
"author_profile": "https://Stackoverflow.com/users/775806",
"pm_score": 0,
"selected": false,
"text": "\"hello world\""
},
{
"answer_id": 74285225,
"author": "Shawn",
"author_id": 9952196,
"author_profile": "https://Stackoverflow.com/users/9952196",
"pm_score": 3,
"selected": true,
"text": "posix_spawn()"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/887128/"
] |
74,284,203 | <p>What the problem is:<br />
I'm new to Selenium and I'm trying to find an element on a webpage. The background is I want to write a script so that it can help me create instance on Oracle cloud. On the page where I have to select <em>Compartment</em>, I need to input my root name. I just can't find the input box.
<a href="https://i.stack.imgur.com/UNFVF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UNFVF.png" alt="The webpage with code" /></a>
I beleive the element is the one highlighted, corresponding to the "Choose a compartment" on the left side of the webpage, but the id is random.</p>
<p>What I tried:<br />
To name a few, I tried<br />
<code>driver.find_element(By.XPATH, '//*[@id="active_compartment_select-dc369079-e95a-2176-f8e4-6ee9c16fe105_trigger"]/ul/li/input')</code></p>
<p><code>driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/aside/div[3]/div/div[2]/div[1]/div/div/div/a/ul/li/input')</code></p>
<p>I also tried<br />
<code>By.CLASS_NAME, 'dropdown-trigger arrow bottom'</code>, it showed nothing;<br />
<code>By.XPATH, //div[contains(@id, 'active_compartment_select')]</code>, it showed nothing.<br />
I even tried <code>find_elements(By.TAG_NAME, 'input')</code> and there's still no such element in the returned list.<br />
I tried basically all the suggestions I could find on stackoverflow, but it still shows no such element exception.</p>
<p>Any suggestions? Thanks in advance!</p>
| [
{
"answer_id": 74284304,
"author": "AbiSaran",
"author_id": 7671727,
"author_profile": "https://Stackoverflow.com/users/7671727",
"pm_score": 1,
"selected": false,
"text": "WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, \"sandbox-compute-container\")))\n\ndriver.find_element(By.XPATH, \".//*[starts-with(@id,'active_compartment_select-')]//a\").click()\n"
},
{
"answer_id": 74285215,
"author": "Eugeny Okulik",
"author_id": 12023661,
"author_profile": "https://Stackoverflow.com/users/12023661",
"pm_score": 0,
"selected": false,
"text": "driver.find_element(By.XPATH,'//input[@placeholder=\"Choose a compartment\"]')"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393789/"
] |
74,284,220 | <p>How to add a class on click to Svelte inline?</p>
<pre><code><li on:click = {() => { this.classList.add('active'); }}>First</li>
</code></pre>
<p>The above is not working.</p>
| [
{
"answer_id": 74284355,
"author": "H.B.",
"author_id": 546730,
"author_profile": "https://Stackoverflow.com/users/546730",
"pm_score": 3,
"selected": true,
"text": "this"
},
{
"answer_id": 74286312,
"author": "Nicolas Le Thierry d'Ennequin",
"author_id": 494979,
"author_profile": "https://Stackoverflow.com/users/494979",
"pm_score": 0,
"selected": false,
"text": "<script>\n let clicked = false;\n</script>\n<li on:click|once={() => { clicked = true; }} class:active={ clicked }>First</li>\n<style>\n li.active { color: red; }\n</style>\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7065562/"
] |
74,284,263 | <p>I have dataframe with multivalue in some columns</p>
<pre><code>df = pd.DataFrame({'id': ['1','2','3',],
'fruits': ['apple, Apple','Orange, grapefruit','Melon'],
'count': [2,2,1]})
</code></pre>
<p>I want to seperate the value in fruits column, so my dataframe become like this</p>
<pre><code>id fruits
1 apple
1 Apple
2 Orange
2 grapefruit
3 Melon
</code></pre>
| [
{
"answer_id": 74284380,
"author": "anon01",
"author_id": 5032941,
"author_profile": "https://Stackoverflow.com/users/5032941",
"pm_score": 2,
"selected": false,
"text": "str"
},
{
"answer_id": 74284384,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "df = df.assign(fruits=df['fruits'].str.split(',')).explode('fruits')\n"
},
{
"answer_id": 74284421,
"author": "Luis Rubiano",
"author_id": 19039059,
"author_profile": "https://Stackoverflow.com/users/19039059",
"pm_score": 1,
"selected": false,
"text": "df2 = pd.DataFrame(columns=['id','fruits'])\n\nfor i, row in df.iterrows():\n temp = pd.DataFrame([[row['id'],fruit.replace(\" \", \"\")] for fruit in row['fruits'].split(',')], columns=['id','fruits'], index = [i for _ in row['fruits'].split(',')])\n df2 = df2.append(temp)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20341621/"
] |
74,284,328 | <p>I've a task to migrate core banking system from java to golang, but i get stuck when i try to perform precission deviding in golang. I've try with math/ package rounding function but i don't get my desired result. I think the problem is i can't find golang dividing function that equal to BigDecimal.devide(BigDecimal divisor, MathContext mc) in java.</p>
<p>can anyone help me to get my desired result, please..</p>
<p>Big Thanks..</p>
<p>Here's my java code and it's <strong>desired result</strong> :</p>
<pre><code>
public BigDecimal getGrossInterest(BigDecimal a, BigDecimal b, Integer c) {
BigDecimal d = a.multiply(b).multiply(new BigDecimal(c));
BigDecimal e = d.divide(new BigDecimal(365), MathContext.DECIMAL32);
BigDecimal result = e.setScale(0, RoundingMode.HALF_UP);
return result;
}
@Test
void TestGetGrossInterest() {
BigDecimal a1 = new BigDecimal(100000000);
BigDecimal b1 = new BigDecimal(0.045);
Integer c1 = Integer.valueOf(28);
BigDecimal result1 = getGrossInterest(a1, b1, c1);
System.out.println(result1); // result1 is 345206
BigDecimal a2 = new BigDecimal(10000000);
BigDecimal b2 = new BigDecimal(0.035);
Integer c2 = Integer.valueOf(16);
BigDecimal result2 = getGrossInterest(a2, b2, c2);
System.out.println(result2); // result2 is 15342
}
</code></pre>
<p>and my golang code with <strong>wrong result</strong> as showed below.</p>
<pre><code>
func getGrossInterest(a float64, b float64, c int) float64 {
d := a * b * float64(c)
e := d / 365
return math.Round(e)
}
func TestGetGrossInterest(t *testing.T) {
a1 := 100000000.00
b1 := 0.045
c1 := 28
result1 := getGrossInterest(a1, b1, c1)
fmt.Printf("result1: %f\n", result1)
assert.Equal(t, float64(345206), result1) // failed test because result1 is 345205
a2 := 10000000.00
b2 := 0.035
c2 := 16
result2 := getGrossInterest(a2,b2,c2)
fmt.Printf("result2: %f\n", result2)
assert.Equal(t, float64(15342), result2)
}
</code></pre>
| [
{
"answer_id": 74284380,
"author": "anon01",
"author_id": 5032941,
"author_profile": "https://Stackoverflow.com/users/5032941",
"pm_score": 2,
"selected": false,
"text": "str"
},
{
"answer_id": 74284384,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 3,
"selected": true,
"text": "df = df.assign(fruits=df['fruits'].str.split(',')).explode('fruits')\n"
},
{
"answer_id": 74284421,
"author": "Luis Rubiano",
"author_id": 19039059,
"author_profile": "https://Stackoverflow.com/users/19039059",
"pm_score": 1,
"selected": false,
"text": "df2 = pd.DataFrame(columns=['id','fruits'])\n\nfor i, row in df.iterrows():\n temp = pd.DataFrame([[row['id'],fruit.replace(\" \", \"\")] for fruit in row['fruits'].split(',')], columns=['id','fruits'], index = [i for _ in row['fruits'].split(',')])\n df2 = df2.append(temp)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15724409/"
] |
74,284,352 | <p>I'm trying to upgrade pip install to 22.3. I keep getting this error, "default to user install because normal sit-packages is not writeable."
I'm at the cmd prompt in win10 trying to install.</p>
<p>This came about because I'm trying to install pypdf2 and this won't install to python that's in my environment path. So I'm stumped.
Thanks for any help.</p>
| [
{
"answer_id": 74409987,
"author": "Shawn Bragdon",
"author_id": 19753194,
"author_profile": "https://Stackoverflow.com/users/19753194",
"pm_score": 0,
"selected": false,
"text": "pip install --user pypdf2\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/661878/"
] |
74,284,390 | <p>I am making a basic aim trainer game. I have a gameboard which is just a div with a range and a target icon which is really just a button. I want the button to move inside the range every time it is clicked.</p>
<p>this is my code for the gameboard and target</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function targetClicked() {
score++;
document.getElementById("scoreLabel").innerHTML = score;
moveTarget();
}
function moveTarget() {
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#gameboard {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
width: 500px;
height: 500px;
background-color: darkgray;
}
#target {
width: 75px;
height: 75px;
position: absolute;
left: 50%;
margin-right: -50%;
transform: translate(-50%, 50%);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="gameboard">
<input hidden type="image" src="target.png" id="target" onclick="targetClicked()">
</div></code></pre>
</div>
</div>
</p>
<p>everything else such as the countdown timer and score counter work. (not shown here) I even got the gameboard and everything to dissapear when the counter reaches 0, but I don't actually know how to move the target everytime it is clicked.</p>
<p>Can I used something like this and inside the moveTarget function adjust the property of the buttons location?</p>
<p>Is there a better way to go about it or can I simply make the button move its position when its clicked?</p>
| [
{
"answer_id": 74284496,
"author": "phasma",
"author_id": 3932026,
"author_profile": "https://Stackoverflow.com/users/3932026",
"pm_score": 0,
"selected": false,
"text": "style"
},
{
"answer_id": 74285614,
"author": "Yuvaraj M",
"author_id": 17543773,
"author_profile": "https://Stackoverflow.com/users/17543773",
"pm_score": 0,
"selected": false,
"text": "function randomAxis(min, max) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nconst img = document.getElementById(\"gameboard_target\");\nconst gameboard = document.getElementById(\"gameboard\").getBoundingClientRect();\nconst img_credentials = img.getBoundingClientRect();\nconst g_width = gameboard.width-img_credentials.width;\nconst g_height = gameboard.height-img_credentials.height;\nimg.onclick = function(){\n const y_axis = randomAxis(0,g_width);\n const x_axis = randomAxis(0,g_height);\n this.style.cssText = `transform:translate(${x_axis}px,${y_axis}px)`\n};"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20393941/"
] |
74,284,505 | <p>I have multiple questions for getting taint information.I know Taint info can be taken from here: (View existing taints on which Taints exist on current nodes.)
<code>kubectl get nodes -o='custom columns=NodeName:.metadata.name,TaintKey:.spec.taints[].key,TaintValue:.spec.taints[].value,TaintEffect:.spec.taints[*].effect'</code></p>
<ul>
<li><p>Above is as per documentation given in this link, but where is this being referenced from ? Where is this listed?<code>https://kubernetes.io/docs/reference/kubectl/cheatsheet/</code></p>
</li>
<li><p>but how do I find that taint is under Spec. As per kubectl commands, "Taint" value only comes under "kubectl describe node" and not "kubectl get node -o yaml". File output is coming as below:</p>
</li>
</ul>
<pre><code>kubectl get node server.ec2.internal -o yaml > nodespecoutput.yaml
</code></pre>
<pre class="lang-yaml prettyprint-override"><code> name: server.ec2.internal
resourceVersion: "..."
uid: 3a6be337-f45d-4d88-95de-ce3a727fc89b
spec:
providerID: aws:///us-east-1b/i-0ba5c3380ed5e423e
status:
addresses:
- address: 172.24.16.207
type: InternalIP
</code></pre>
<pre><code>kubectl describe node server.ec2.internal -o yaml > nodespecoutputdesc.yaml
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp: Tue, 05 Jul 2022 16:17:44 -0600
Taints: <none>
Unschedulable: false
Lease:
HolderIdentity: server.ec2.internal
AcquireTime: <unset>
RenewTime: Thu, 03 Nov 2022 19:57:02 -0600
</code></pre>
<ul>
<li><p>I can only find this documentation : (nothing here.)
<code>https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#nodespec-v1-core</code></p>
</li>
<li><p>how do I find out(proof) that spec contains "taints", either some documentation , or some "--help" style documentation , or output for "-o yaml ", or output for "-o json"?</p>
</li>
</ul>
<p><strong>I have tried using kubectl "get" and "describe".I have also tried understanding YAML structure, but it is not listed there, or I might be missing something.</strong></p>
| [
{
"answer_id": 74284496,
"author": "phasma",
"author_id": 3932026,
"author_profile": "https://Stackoverflow.com/users/3932026",
"pm_score": 0,
"selected": false,
"text": "style"
},
{
"answer_id": 74285614,
"author": "Yuvaraj M",
"author_id": 17543773,
"author_profile": "https://Stackoverflow.com/users/17543773",
"pm_score": 0,
"selected": false,
"text": "function randomAxis(min, max) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nconst img = document.getElementById(\"gameboard_target\");\nconst gameboard = document.getElementById(\"gameboard\").getBoundingClientRect();\nconst img_credentials = img.getBoundingClientRect();\nconst g_width = gameboard.width-img_credentials.width;\nconst g_height = gameboard.height-img_credentials.height;\nimg.onclick = function(){\n const y_axis = randomAxis(0,g_width);\n const x_axis = randomAxis(0,g_height);\n this.style.cssText = `transform:translate(${x_axis}px,${y_axis}px)`\n};"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10744066/"
] |
74,284,517 | <p>hello I wonder how to use U+00B7 this unicode on flutter text widget</p>
<p>I want to use this text. How can I use unicode on flutter Text widget?
thank you so much</p>
| [
{
"answer_id": 74284563,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": true,
"text": " Text('\\u00a9 example \\u00B7'),\n"
},
{
"answer_id": 74284592,
"author": "Himani",
"author_id": 18416001,
"author_profile": "https://Stackoverflow.com/users/18416001",
"pm_score": 1,
"selected": false,
"text": "Text(utf8.decode(text.codeUnits)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20135600/"
] |
74,284,552 | <p>I need to get hrefs from <code><a></code> tags in a website, but not all, but only ones that are in the spans locted in the <code><div></code>s with classes <code>arm</code></p>
<pre class="lang-html prettyprint-override"><code><html>
<body>
<div class="arm">
<span>
<a href="1">link</a>
<a href="2">link</a>
<a href="3">link</a>
</span>
</div>
<div class="arm">
<span>
<a href="4">link</a>
<a href="5">link</a>
<a href="6">link</a>
</span>
</div>
<div class="arm">
<span>
<a href="7">link</a>
<a href="8">link</a>
<a href="9">link</a>
</span>
</div>
<div class="footnote">
<span>
<a href="1">anotherLink</a>
<a href="2">anotherLink</a>
<a href="3">anotherLink</a>
</span>
</div>
</body>
</html>
</code></pre>
<pre class="lang-py prettyprint-override"><code>import requests
from bs4 import BeautifulSoup as bs
request = requests.get("url")
html = bs(request.content, 'html.parser')
for arm in html.select(".arm"):
anchor = arm.select("span > a")
print("anchor['href']")
</code></pre>
<p>But my code doesn't print anything</p>
| [
{
"answer_id": 74284563,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": true,
"text": " Text('\\u00a9 example \\u00B7'),\n"
},
{
"answer_id": 74284592,
"author": "Himani",
"author_id": 18416001,
"author_profile": "https://Stackoverflow.com/users/18416001",
"pm_score": 1,
"selected": false,
"text": "Text(utf8.decode(text.codeUnits)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,284,582 | <p>Let's say I have an epoch value 1665531785000 which converts to "Tuesday, October 11, 2022 11:43:05 PM" in human readable format.</p>
<p>How can we modify 1665531785000 to 1665532800000 which converts to "Wednesday, October 12, 2022 12:00:00 AM"(set the value to 12AM next day) in javascript/typescript</p>
| [
{
"answer_id": 74284563,
"author": "Gwhyyy",
"author_id": 18670641,
"author_profile": "https://Stackoverflow.com/users/18670641",
"pm_score": 1,
"selected": true,
"text": " Text('\\u00a9 example \\u00B7'),\n"
},
{
"answer_id": 74284592,
"author": "Himani",
"author_id": 18416001,
"author_profile": "https://Stackoverflow.com/users/18416001",
"pm_score": 1,
"selected": false,
"text": "Text(utf8.decode(text.codeUnits)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20394116/"
] |
74,284,591 | <p>I have price combinations which are arrays of objects. And I have traveler ages which are an array of numbers. So price combinations have fields like min age and max age and I want to filter travelers ages higher or lower than min age or max age. am stuck on this really don't know how to do it.</p>
<pre><code> const travelerAges = [5, 10, 35, 50]
priceCombinations.filter((priceCombination) => {
if (priceCombination.minAge > travelerAges && priceCombination.maxAge > travelerAges) {
return false
} else if (priceCombination.maxAge < travelerAges) {
return false
}
return true
})
</code></pre>
<p>Getting error on IF.</p>
<blockquote>
<p>Operator '>' cannot be applied to types 'number' and 'number[]'</p>
</blockquote>
<p>Any ideas on how can I do this operation?</p>
| [
{
"answer_id": 74284878,
"author": "Fajri",
"author_id": 20326895,
"author_profile": "https://Stackoverflow.com/users/20326895",
"pm_score": 0,
"selected": false,
"text": "travAgeMin = Math.min.apply(null, travelerAges)\ntravAgeMax = Math.max.apply(null, travelerAges)\n\npriceCombinations.filter((priceCombination) => {\n if (priceCombination.minAge > travAgeMin && priceCombination.maxAge > travAgeMin) {\n return false\n } else if (priceCombination.maxAge < travAgeMax) {\n return false\n }\n return true\n})\n"
},
{
"answer_id": 74287049,
"author": "Lain",
"author_id": 4728913,
"author_profile": "https://Stackoverflow.com/users/4728913",
"pm_score": 1,
"selected": false,
"text": "travelerAges"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19689505/"
] |
74,284,598 | <p>I want to use the following code to filter the data in models.py in views.py and output the Today_list to today.html, but when I open this url, nothing is displayed. What is the problem?</p>
<pre class="lang-py prettyprint-override"><code>class Post(models.Model):
created =models.DateTimeField(auto_now_add=True,editable=False,blank=False,null=False)
title =models.CharField(max_length=255,blank=False,null=False)
body =models.TextField(blank=True,null=False)
def __str__(self):
return self.title
</code></pre>
<p><code>views.py</code></p>
<pre class="lang-py prettyprint-override"><code>from Todolist import models
from django.views.generic import ListView
from django.utils import timezone
class TodayView(ListView):
model = models.Post
template_name ='Todolist/today.html'
def get_queryset(self):
Today_list= models.Post.objects.filter(
created=timezone.now()).order_by('-id')
return Today_list
</code></pre>
<p><code>todaylist.html</code></p>
<pre><code>{% extends "Todolist/base.html" %}
{% block content %}
{% for item in Today_list %}
<tr>
<td>{{item.title}}</td>
</tr>
{% endfor %}
{% endblock %}
</code></pre>
<p><code>urls.py</code></p>
<pre class="lang-py prettyprint-override"><code>urlpatterns=[
path('today/' ,views.TodayView.as_view() ,name='today')
]
</code></pre>
| [
{
"answer_id": 74284878,
"author": "Fajri",
"author_id": 20326895,
"author_profile": "https://Stackoverflow.com/users/20326895",
"pm_score": 0,
"selected": false,
"text": "travAgeMin = Math.min.apply(null, travelerAges)\ntravAgeMax = Math.max.apply(null, travelerAges)\n\npriceCombinations.filter((priceCombination) => {\n if (priceCombination.minAge > travAgeMin && priceCombination.maxAge > travAgeMin) {\n return false\n } else if (priceCombination.maxAge < travAgeMax) {\n return false\n }\n return true\n})\n"
},
{
"answer_id": 74287049,
"author": "Lain",
"author_id": 4728913,
"author_profile": "https://Stackoverflow.com/users/4728913",
"pm_score": 1,
"selected": false,
"text": "travelerAges"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20316579/"
] |
74,284,623 | <p>The background color is coming for the elevated button in flutter. I have added a background image for the elevated button, but the background color( blue and grey color ) is coming for it. I do not know where it is coming from. So how to remove it?</p>
<pre><code> child:SingleChildScrollView(
child: Wrap(
alignment: WrapAlignment.center,
runSpacing: 20.0, // Or more
spacing: 20, // Or more
children: [
const SizedBox(
height: 520,
),
SizedBox(
width: double.infinity, // <-- Your width
height: 50, // <-- Your height
),
SizedBox(
height: 80, // <-- Your height
width: 80,
child: ElevatedButton(
onPressed: () {
onGoogleSignIn(context);
},
child: Image.asset('images/gm.png')
),
),
SizedBox(
height: 80, // <-- Your height
width: 80,
child: ElevatedButton(
onPressed: () {
//validateForm();
Navigator.push(context,
MaterialPageRoute(builder: (c) => const PhoneLoginScreen()));
},
style: ElevatedButton.styleFrom(
primary: Colors.red.withOpacity(0),
),
child: Image.asset('images/mn.png')
),// Button
),
],
),
),
</code></pre>
| [
{
"answer_id": 74284919,
"author": "pmatatias",
"author_id": 12838877,
"author_profile": "https://Stackoverflow.com/users/12838877",
"pm_score": 0,
"selected": false,
"text": "InkWell(\n onTap:(){},\n splashColor: .... // this will add ripple effect\n child: Padding(padding:EdgeInsets.all(20),\n child: Image.asset('images/mn.png')\n )\n"
},
{
"answer_id": 74285033,
"author": "Afridi Kayal",
"author_id": 12636223,
"author_profile": "https://Stackoverflow.com/users/12636223",
"pm_score": 0,
"selected": false,
"text": "class ImageButton extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n const double size = 80;\n const String imageUrl = \"https://picsum.photos/512\";\n\n return SizedBox(\n width: size,\n height: size,\n child: Ink(\n decoration: BoxDecoration(\n image: const DecorationImage(image: NetworkImage(imageUrl)),\n borderRadius: BorderRadius.circular(size / 2),\n ),\n child: InkWell(\n onTap: () {},\n borderRadius: BorderRadius.circular(size / 2),\n ),\n ),\n );\n }\n}\n"
},
{
"answer_id": 74285343,
"author": "Tasnuva Tavasum oshin",
"author_id": 8480069,
"author_profile": "https://Stackoverflow.com/users/8480069",
"pm_score": 2,
"selected": true,
"text": " style: ButtonStyle(\n color: MaterialStateProperty.all(Colors.transparent),\n elevation: MaterialStateProperty.all(0), //Defines Elevation\n \n ), \n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19099386/"
] |
74,284,654 | <p>Why does swift behave so weird when comparing Doubles and Integers?</p>
<p>Consider the following code for repl/playground:</p>
<pre><code>12>12.0 //false
13 > 12.0 //true
13.0 > 12 //true
13 >= 12.0 //true
13 <= 12.0 //false
12.0 < 13 //Error: Ambiguous use of operator '<'
12 < 13.0 //Error: Ambiguous use of operator '<'
</code></pre>
<p>What exactly is Ambiguous in the use of operator here?</p>
<p>The debug console output is not especially helpful either:</p>
<pre><code>error: ambiguous use of operator '<'
12 < 13.0
^
Foundation.RunLoop:18:32: note: found this candidate
public static func < (lhs: RunLoop.SchedulerTimeType.Stride, rhs: RunLoop.SchedulerTimeType.Stride) -> Bool
^
Foundation.Decimal:4:24: note: found this candidate
public static func < (lhs: Decimal, rhs: Decimal) -> Bool
^
Foundation.OperationQueue:18:32: note: found this candidate
public static func < (lhs: OperationQueue.SchedulerTimeType.Stride, rhs: OperationQueue.SchedulerTimeType.Stride) -> Bool
^
Dispatch.DispatchQueue:22:32: note: found this candidate
public static func < (lhs: DispatchQueue.SchedulerTimeType.Stride, rhs: DispatchQueue.SchedulerTimeType.Stride) -> Bool
</code></pre>
<hr />
<p><strong>UPD:</strong> Just to clarify, I know that I can cast values explicitly.</p>
<p>The question is why exactly does the language behave this way and was is it designed to behave this way with <code><</code> operator?</p>
| [
{
"answer_id": 74284919,
"author": "pmatatias",
"author_id": 12838877,
"author_profile": "https://Stackoverflow.com/users/12838877",
"pm_score": 0,
"selected": false,
"text": "InkWell(\n onTap:(){},\n splashColor: .... // this will add ripple effect\n child: Padding(padding:EdgeInsets.all(20),\n child: Image.asset('images/mn.png')\n )\n"
},
{
"answer_id": 74285033,
"author": "Afridi Kayal",
"author_id": 12636223,
"author_profile": "https://Stackoverflow.com/users/12636223",
"pm_score": 0,
"selected": false,
"text": "class ImageButton extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n const double size = 80;\n const String imageUrl = \"https://picsum.photos/512\";\n\n return SizedBox(\n width: size,\n height: size,\n child: Ink(\n decoration: BoxDecoration(\n image: const DecorationImage(image: NetworkImage(imageUrl)),\n borderRadius: BorderRadius.circular(size / 2),\n ),\n child: InkWell(\n onTap: () {},\n borderRadius: BorderRadius.circular(size / 2),\n ),\n ),\n );\n }\n}\n"
},
{
"answer_id": 74285343,
"author": "Tasnuva Tavasum oshin",
"author_id": 8480069,
"author_profile": "https://Stackoverflow.com/users/8480069",
"pm_score": 2,
"selected": true,
"text": " style: ButtonStyle(\n color: MaterialStateProperty.all(Colors.transparent),\n elevation: MaterialStateProperty.all(0), //Defines Elevation\n \n ), \n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/113678/"
] |
74,284,661 | <p>I didn't understand how to give the path of the pro version in the current project</p>
<p>I read the setup from pub.dev but don't know how can I did it.</p>
<ol>
<li>followed this steps : <a href="https://pub.dev/packages/font_awesome_flutter#setup" rel="nofollow noreferrer">setup information</a></li>
<li>already clone a repo</li>
</ol>
<p><a href="https://i.stack.imgur.com/Gcvpql.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gcvpql.png" alt="enter image description here" /></a></p>
<blockquote>
<p>facing one error here : <code>zsh: permission denied: ./configurator.sh</code>. while running this ./configurator.sh it will show error.</p>
</blockquote>
<ol start="3">
<li><p>how to give path of new font repo to my project? ( in pubspec.yaml)</p>
<p><a href="https://i.stack.imgur.com/CfIKo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CfIKo.png" alt="enter image description here" /></a></p>
</li>
</ol>
<blockquote>
<p>here is image where i stored clone repo project
<a href="https://i.stack.imgur.com/0u8qJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0u8qJ.png" alt="enter image description here" /></a></p>
</blockquote>
| [
{
"answer_id": 74285237,
"author": "Sahil Sonawane",
"author_id": 15589902,
"author_profile": "https://Stackoverflow.com/users/15589902",
"pm_score": 1,
"selected": false,
"text": "packages"
},
{
"answer_id": 74285320,
"author": "Tasnuva Tavasum oshin",
"author_id": 8480069,
"author_profile": "https://Stackoverflow.com/users/8480069",
"pm_score": 4,
"selected": true,
"text": "$ sudo ./configurator.sh --exclude solid\n$ sudo ./configurator.sh --exclude solid,brands\n"
},
{
"answer_id": 74298175,
"author": "amit.flutter",
"author_id": 13078639,
"author_profile": "https://Stackoverflow.com/users/13078639",
"pm_score": 0,
"selected": false,
"text": "$ cd util\n$ bash ./configurator.sh --dynamic \n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13078639/"
] |
74,284,673 | <p>I am trying to extract the article body with images from <a href="https://www.cnbc.com/2022/01/03/5-ways-to-reset-your-retirement-savings-and-save-more-money-in-2022.html" rel="nofollow noreferrer">this link</a>, so that using the extracted article body I can make a HTML table. So, I have tried using <code>BeautifulSoup</code>.</p>
<pre><code>t_link = 'https://www.cnbc.com/2022/01/03/5-ways-to-reset-your-retirement-savings-and-save-more-money-in-2022.html'
page = requests.get(t_link)
soup_page = BeautifulSoup(page.content, 'html.parser')
html_article = soup_page.find_all("div", {"class": re.compile('ArticleBody-articleBody.?')})
for article_body in html_article:
print(article_body)
</code></pre>
<p>But unfortunately the <code>article_body</code> didn't show any image, like this. Because, <code><div class="InlineImage-wrapper"></code> is't scraping in this way</p>
<p><a href="https://i.stack.imgur.com/lTODi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lTODi.png" alt="enter image description here" /></a></p>
<p>So, how can I get article data with article images, so that I can make a HTML table?</p>
| [
{
"answer_id": 74314758,
"author": "baduker",
"author_id": 6106791,
"author_profile": "https://Stackoverflow.com/users/6106791",
"pm_score": 0,
"selected": false,
"text": "HTML"
},
{
"answer_id": 74326395,
"author": "aborruso",
"author_id": 757714,
"author_profile": "https://Stackoverflow.com/users/757714",
"pm_score": 1,
"selected": false,
"text": "grep"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14542180/"
] |
74,284,680 | <p>How can I find only the "<strong>hotels</strong>" property? <em>Data in MongoDB-</em></p>
<pre><code>[
{
"picture": "https://d.bcb.ic/dKkqr2da/lalkhal.jpg",
"name": "Lalakhal",
"about": "Lalakhal is....",
"latitude": 25.1048,
"longitude": 92.1770,
"hotels": [{}, {}, {}]
},
{
"picture": "https://d.bcb.ic/dKkqr2da/lalkhal.jpg",
"name": "Lalakhal",
"about": "Lalakhal is....",
"latitude": 25.1048,
"longitude": 92.1770,
"hotels": [{}, {}, {}]
},
]
</code></pre>
<p><em>Here is my code</em></p>
<pre><code>const places = client.db("travel-guru").collection("places");
const hotels = await places.findOne({name: placename})
</code></pre>
<p>I don't need the all result document. I need just hotels only for a specific document. I am expecting the result-
<code>hotels = [{}, {}, {}]</code></p>
| [
{
"answer_id": 74284726,
"author": "Anveeg Sinha",
"author_id": 17498746,
"author_profile": "https://Stackoverflow.com/users/17498746",
"pm_score": 1,
"selected": false,
"text": "const hotels = await places.findOne({name: placename},{hotels: 1})\n"
},
{
"answer_id": 74284791,
"author": "Tim",
"author_id": 20317091,
"author_profile": "https://Stackoverflow.com/users/20317091",
"pm_score": 2,
"selected": true,
"text": "await places.findOne({name: placename}).project({hotels: 1, _id: 0})"
},
{
"answer_id": 74284921,
"author": "Pawan Yadav",
"author_id": 16764381,
"author_profile": "https://Stackoverflow.com/users/16764381",
"pm_score": 0,
"selected": false,
"text": "const hotels = await places.findOne({name: placename}).select({hotels:1,_id:0});\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19859792/"
] |
74,284,691 | <p>In Pandas I have a table</p>
<pre><code>name sec
emp1 a
emp1 a
emp1 b
emp2 a
emp2 b
emp2 c
emp2 c
</code></pre>
<p>i want to extract each name with max count of sec like</p>
<pre><code> name sec
emp1 a
emp2 c
</code></pre>
<p>in pandas in know we can use groupBy but do not know how to get this format.</p>
<pre><code>df.groupby(['name','sec']).size()
</code></pre>
<p>this will give</p>
<pre><code>name sec
emp1 a 2
b 1
emp2 a 1
b 1
c 2
</code></pre>
<p>but I need this way with maximum occurrence of sec</p>
<pre><code> name sec
emp1 a
emp2 c
</code></pre>
| [
{
"answer_id": 74284771,
"author": "J_H",
"author_id": 8431111,
"author_profile": "https://Stackoverflow.com/users/8431111",
"pm_score": 0,
"selected": false,
"text": ".size()"
},
{
"answer_id": 74284827,
"author": "jaemmin",
"author_id": 18273129,
"author_profile": "https://Stackoverflow.com/users/18273129",
"pm_score": 3,
"selected": true,
"text": ">>> df.groupby(['name'], as_index = False)[['sec']].agg(pd.Series.mode) \n name sec\n0 emp1 a\n1 emp2 c\n\n"
},
{
"answer_id": 74284930,
"author": "David A",
"author_id": 10701113,
"author_profile": "https://Stackoverflow.com/users/10701113",
"pm_score": 0,
"selected": false,
"text": "df.groupby(['name','sec']).size().reset_index().sort_values(by=0,ascending=False).drop_duplicates(subset='name', keep='first').drop(columns=[0]).reset_index(drop=True)\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12939110/"
] |
74,284,715 | <p>I have table of tickers on one HTML page, and four charts displayed on another HTML page. These charts come from my static/images folder full of hundreds of images named by each ETF's benchmark index ticker. If I click the ETF ticker "PSCD" in the first row of the table, how can it be linked to another HTML page named charts.html which shows four charts whose filenames contain the ETF's benchmark index ticker, example: <code>chart1/S6COND.jpg</code>, <code>chart2/S6COND.jpg</code>, <code>chart3/S6COND.jpg</code>, <code>chart4/S6COND.jpg</code>. <- In this example, I hardcoded S6COND.jpg into the link, and it works...but I need it to be dynamically tied to the index ticker of whatever etf ticker row I click on in the table. The index ticker for each ETF for each row in the table is included in my models.py which you can see below.</p>
<p>In the charts.html code example below, I hardcoded S6COND into the image tag but I want this dynamically linked.</p>
<p><a href="https://i.stack.imgur.com/wPp3p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wPp3p.png" alt="enter image description here" /></a></p>
<p>Below you will see my table.html page showing my table from above. Next is the charts.html where I would like the etf_ticker that was clicked in that table to be entered into the image tags such as <code><img src="{% static 'myapp/images/chart1_S6COND.jpg' %}" alt="chart1"/></div></code> where you see I have hardcoded "S6COND" into the image tag. But I need this to be dynamic, from which you click on the link in table.html, and it gets inserted into the image tag in charts.html.</p>
<p>table.html</p>
<pre class="lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ETF Table</title>
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'myapp/css/table_style.css' %}">
<style type="text/css"></style>
</head>
<body>
<div class="container">
<table id="table" class="table table-dark table-hover table-striped table-bordered table-sm">
<thead>
<tr>
<th data-sortable="true">ETF Ticker</th>
<th>ETF Name</th>
<th>Index Name</th>
</tr>
</thead>
<tbody>
{% if d %}
{% for i in d %}
<tr>
<td><a href="{% url 'myapp:charts' %}" target="_blank">{{i.etf_ticker}}</a></td>
<td><a href="{% url 'myapp:charts' %}" target="_blank">{{i.etf_name}}</a></td>
<td><a href="{% url 'myapp:charts' %}" target="_blank">{{i.index_name}}</a></td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
<script>
$('#table').DataTable({
"bLengthChange": true,
"lengthMenu": [ [20, 50, 100 -1], [20, 50, 100, "All"] ],
"iDisplayLength": 20,
bInfo: false,
responsive: true,
order: [[4, 'desc']],
});
</script>
</div>
</body>
</html>
</code></pre>
<p>charts.html</p>
<pre class="lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Charts</title>
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'myapp/css/charts_style.css' %}">
<style type="text/css">
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<nav>
<ul>
<li><a class="nav" href="{% url 'myapp:index' %}">Home</a></li><br><br>
<li><a class="nav" href="{% url 'myapp:table' %}">Table</a></li><br>
</ul>
</nav>
<div class="container">
<div class="box"><img src="{% static 'myapp/images/chart1_S6COND.jpg' %}" alt="chart1"/></div>
<div class="box"><img src="{% static 'myapp/images/chart2_S6COND.jpg' %}" alt="chart2"/></div>
<div class="box"><img src="{% static 'myapp/images/chart3_S6COND.jpg' %}" alt="chart3"/></div>
<div class="box"><img src="{% static 'myapp/images/chart4_S6COND.jpg' %}" alt="chart4"/></div>
</div>
</body>
</html>
</code></pre>
<p>urls.py</p>
<pre class="lang-py prettyprint-override"><code>from django.urls import path
from . import views
from .views import ChartView
app_name = 'myapp'
urlpatterns = [
path('', views.index, name='index'),
path('table/', views.table, name='table'),
path('charts/', ChartView.as_view(), name='charts'),
]
</code></pre>
<p>models.py</p>
<pre class="lang-py prettyprint-override"><code>from django.db import models
class Table(models.Model):
etf_ticker = models.CharField(max_length=10)
etf_name = models.CharField(max_length=200)
index_name = models.CharField(max_length=200)
index_ticker = models.CharField(max_length=200)
</code></pre>
<p>views.py</p>
<pre class="lang-py prettyprint-override"><code>from django.shortcuts import render
from django.views.generic import TemplateView
from .models import Table
def index(request):
return render(request, 'index.html')
def table(request):
data = Table.objects.all().values()
context = {'d': data}
return render(request, 'table.html', context)
class ChartView(TemplateView):
template_name = 'charts.html'
</code></pre>
| [
{
"answer_id": 74284923,
"author": "Omar Siddiqui",
"author_id": 14170111,
"author_profile": "https://Stackoverflow.com/users/14170111",
"pm_score": 2,
"selected": false,
"text": "urls.py"
},
{
"answer_id": 74341883,
"author": "Python16367225",
"author_id": 16367225,
"author_profile": "https://Stackoverflow.com/users/16367225",
"pm_score": 1,
"selected": true,
"text": "table.html"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16367225/"
] |
74,284,717 | <p>user select image and submit on wwwroot folder.
i just want to submit the selected file but it refresh it all on submit button the submit button is post post the selected data on page how can i submit the image on select and then on submit button it show on page dont refresh the page.</p>
<pre><code> <form enctype="multipart/form-data" asp-controller="" asp-action="">
<a href="javascript:void(0);" class="btn btn-icon fs-xl mr-1" data-toggle="tooltip" data-original-title="Attach files" data-placement="top">
<div>
<input type="file" id="choose-file" name="formFile" />
<label for="choose-file"> <i class="fal fa-paperclip color-fusion-300"></i></label>
</div>
</a>
<a href="javascript:void(0);" class="btn btn-icon fs-xl mr-1" data-toggle="tooltip" data-original-title="Insert photo" data-placement="top">
<i class="fal fa-camera color-fusion-300"></i>
</a>
<button class="btn btn-info shadow-0 ml-auto " id="submit" onclick="addCode()">Post</button>
</form>
</code></pre>
<p>i had tried this it submit the image where i want to but it also refresh which i dont want to do.</p>
| [
{
"answer_id": 74284923,
"author": "Omar Siddiqui",
"author_id": 14170111,
"author_profile": "https://Stackoverflow.com/users/14170111",
"pm_score": 2,
"selected": false,
"text": "urls.py"
},
{
"answer_id": 74341883,
"author": "Python16367225",
"author_id": 16367225,
"author_profile": "https://Stackoverflow.com/users/16367225",
"pm_score": 1,
"selected": true,
"text": "table.html"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20279862/"
] |
74,284,724 | <p>I'm confused on how to manage SEO for client components in Next.js 13.</p>
<p>Let's say I want to create a contact us page at <code>/contact</code></p>
<p>In the new framework, I should create a folder named <code>contact</code> inside the <code>app</code> directory. And in it I should create a page called <code>page.js</code> by convention.</p>
<p>Now I need to create a form, which of course needs to manage its state. Thus I should use <code>useState</code> or other hooks from react.</p>
<p>But when I do that, Next.js compiler complains that it's a server component and if I want to use it on the client-side, I should mark it with <code>'use client'</code> directive at the top.</p>
<p>But I don't want the component to be rendered on the client-side. I need my <code>/contact</code> page to be indexed by search engines.</p>
<p>What should I do?</p>
| [
{
"answer_id": 74284923,
"author": "Omar Siddiqui",
"author_id": 14170111,
"author_profile": "https://Stackoverflow.com/users/14170111",
"pm_score": 2,
"selected": false,
"text": "urls.py"
},
{
"answer_id": 74341883,
"author": "Python16367225",
"author_id": 16367225,
"author_profile": "https://Stackoverflow.com/users/16367225",
"pm_score": 1,
"selected": true,
"text": "table.html"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19390849/"
] |
74,284,737 | <p>I'm using the jQuery Datatables component and I need to retrieve the number of rows to display and the current page number.
Thanks.</p>
| [
{
"answer_id": 74284853,
"author": "MAYUR SANCHETI",
"author_id": 12238257,
"author_profile": "https://Stackoverflow.com/users/12238257",
"pm_score": -1,
"selected": false,
"text": " data: tableData,\n columns: columnData,\n pageLength: 4,\n pagingType: \"first_last_numbers\"\n"
},
{
"answer_id": 74317563,
"author": "Yassine",
"author_id": 3311971,
"author_profile": "https://Stackoverflow.com/users/3311971",
"pm_score": 0,
"selected": false,
"text": "var table = $(id_table).DataTable();\nvar numPage= table.page();\n"
}
] | 2022/11/02 | [
"https://Stackoverflow.com/questions/74284737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3311971/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.