qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
74,475,016
|
<p>When I make an input button and add a label, the label appears on the side of the input field. How can I make it appear inside the input field?</p>
<p>I have tried to put the label inside the input field with CSS, but when I write in the input, the label and the text overlap, and the text becomes unreadable. How can I make the label disappear when I type in the input field? If you have any other options, please tell me.</p>
<pre><code>
<div class="holder">
<label>username</label>
<input type="text">
</div>
</code></pre>
<pre><code>.holder {
position: relative;
}
.holder label {
position: absolute;
left: 2px;
top: 2px;
width: 20px;
height: 20px;
}
.holder input {
padding: 2px 2px 2px 25px;
}
</code></pre>
|
[
{
"answer_id": 74475038,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 3,
"selected": true,
"text": "do.call(pmax, df)\n\n[1] \"2020-11-30 22:09:29 GMT\" \"2026-06-14 20:00:05 GMT\"\n[3] \"2008-02-08 01:32:23 GMT\" \"2021-06-17 10:44:05 GMT\"\n[5] \"2025-02-18 23:20:28 GMT\" \"1997-03-27 18:10:44 GMT\"\n...\n"
},
{
"answer_id": 74475044,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "data.frame"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20136506/"
] |
74,475,090
|
<p>I have the following pandas column1 and I want to create a column2 displaying the count of the value in each row in the column1.</p>
<p>I do not want to use pandas value_counts as I do not want to group by the values of the column.
Column1 :</p>
<pre><code>COL 1
VALUE1
VALUE2
VALUE1
VALUE1
VALUE1
VALUE3
VALUE2
VALUE1
VALLUE3
VALUE2
</code></pre>
<p>Desired result :</p>
<pre><code>COL 1 Desired Result
VALUE1 5
VALUE2 3
VALUE1 5
VALUE1 5
VALUE1 5
VALUE3 1
VALUE2 3
VALUE1 5
VALLUE3 1
VALUE2 3
</code></pre>
|
[
{
"answer_id": 74475038,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 3,
"selected": true,
"text": "do.call(pmax, df)\n\n[1] \"2020-11-30 22:09:29 GMT\" \"2026-06-14 20:00:05 GMT\"\n[3] \"2008-02-08 01:32:23 GMT\" \"2021-06-17 10:44:05 GMT\"\n[5] \"2025-02-18 23:20:28 GMT\" \"1997-03-27 18:10:44 GMT\"\n...\n"
},
{
"answer_id": 74475044,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "data.frame"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19076108/"
] |
74,475,129
|
<p>I've a two columns in a file, like this</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apple</td>
<td>2</td>
</tr>
<tr>
<td>Bat</td>
<td>2</td>
</tr>
<tr>
<td>Cat</td>
<td>4</td>
</tr>
<tr>
<td>Bat</td>
<td>2.5</td>
</tr>
<tr>
<td>Apple</td>
<td>6</td>
</tr>
<tr>
<td>Cat</td>
<td>4.8</td>
</tr>
</tbody>
</table>
</div>
<p>I want to covert Column A values into individual columns & corresponding values from Column B</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th><strong>Apple</strong></th>
<th><strong>Bat</strong></th>
<th><strong>Cat</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>2</td>
<td>4</td>
</tr>
<tr>
<td>6</td>
<td>2.5</td>
<td>4.8</td>
</tr>
</tbody>
</table>
</div>
|
[
{
"answer_id": 74475038,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 3,
"selected": true,
"text": "do.call(pmax, df)\n\n[1] \"2020-11-30 22:09:29 GMT\" \"2026-06-14 20:00:05 GMT\"\n[3] \"2008-02-08 01:32:23 GMT\" \"2021-06-17 10:44:05 GMT\"\n[5] \"2025-02-18 23:20:28 GMT\" \"1997-03-27 18:10:44 GMT\"\n...\n"
},
{
"answer_id": 74475044,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "data.frame"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8484526/"
] |
74,475,169
|
<h3>Summary</h3>
<p>I would like to check that a cell contains the identical number of each letter from a-z and number from 0-9, as the cell next to it. The order does not matter, but the number of characters does. For example, if a cell contained "flat 1, 32 test road", and the cell next to it contained "32, flat 1, test road", it would match, as they both contain 3 t's, 2 a's, 1 l, etc.).</p>
<h3>Example Table</h3>
<p>An example of the expected output is below, with the formula being populated in column C:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Data 1</th>
<th>Data 2</th>
<th>Match?</th>
</tr>
</thead>
<tbody>
<tr>
<td>123 test road</td>
<td>testroad123</td>
<td>MATCH</td>
</tr>
<tr>
<td>FOOBAR 34</td>
<td>FOO,/,34BAR</td>
<td>MATCH</td>
</tr>
<tr>
<td>HELLOWORLD1</td>
<td>HELLOWORLD2</td>
<td>NO MATCH</td>
</tr>
<tr>
<td>FLAT4,33 STREET NAME</td>
<td>STREET NAME 33,FLAT 4</td>
<td>MATCH</td>
</tr>
<tr>
<td>12345</td>
<td>12345 Road</td>
<td>NO MATCH</td>
</tr>
</tbody>
</table>
</div><h3>Working code</h3>
<p>Currently, I have this working by first converting the contents of cell to lowercase, then individually checking each letter from a-z, and each number from 0-9 in an <code>IF(AND)</code> statement. It works, but looks horrible and undoubtedly is incredibly inefficient and resource intensive. The code is as follows:
<code>=IF(AND(LEN(A1)-LEN(SUBSTITUTE(A1,"a",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"a","")),LEN(A1)-LEN(SUBSTITUTE(A1,"b",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"b","")),LEN(A1)-LEN(SUBSTITUTE(A1,"c",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"c","")),LEN(A1)-LEN(SUBSTITUTE(A1,"d",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"d","")),LEN(A1)-LEN(SUBSTITUTE(A1,"e",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"e","")),LEN(A1)-LEN(SUBSTITUTE(A1,"f",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"f","")),LEN(A1)-LEN(SUBSTITUTE(A1,"g",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"g","")),LEN(A1)-LEN(SUBSTITUTE(A1,"h",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"h","")),LEN(A1)-LEN(SUBSTITUTE(A1,"i",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"i","")),LEN(A1)-LEN(SUBSTITUTE(A1,"j",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"j","")),LEN(A1)-LEN(SUBSTITUTE(A1,"k",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"k","")),LEN(A1)-LEN(SUBSTITUTE(A1,"l",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"l","")),LEN(A1)-LEN(SUBSTITUTE(A1,"m",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"m","")),LEN(A1)-LEN(SUBSTITUTE(A1,"n",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"n","")),LEN(A1)-LEN(SUBSTITUTE(A1,"o",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"o","")),LEN(A1)-LEN(SUBSTITUTE(A1,"p",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"p","")),LEN(A1)-LEN(SUBSTITUTE(A1,"q",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"q","")),LEN(A1)-LEN(SUBSTITUTE(A1,"r",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"r","")),LEN(A1)-LEN(SUBSTITUTE(A1,"s",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"s","")),LEN(A1)-LEN(SUBSTITUTE(A1,"t",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"t","")),LEN(A1)-LEN(SUBSTITUTE(A1,"u",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"u","")),LEN(A1)-LEN(SUBSTITUTE(A1,"v",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"v","")),LEN(A1)-LEN(SUBSTITUTE(A1,"w",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"w","")),LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"x","")),LEN(A1)-LEN(SUBSTITUTE(A1,"y",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"y","")),LEN(A1)-LEN(SUBSTITUTE(A1,"z",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"z","")),LEN(A1)-LEN(SUBSTITUTE(A1,"0",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"0","")),LEN(A1)-LEN(SUBSTITUTE(A1,"1",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"1","")),LEN(A1)-LEN(SUBSTITUTE(A1,"2",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"2","")),LEN(A1)-LEN(SUBSTITUTE(A1,"3",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"3","")),LEN(A1)-LEN(SUBSTITUTE(A1,"4",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"4","")),LEN(A1)-LEN(SUBSTITUTE(A1,"5",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"5","")),LEN(A1)-LEN(SUBSTITUTE(A1,"6",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"6","")),LEN(A1)-LEN(SUBSTITUTE(A1,"7",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"7","")),LEN(A1)-LEN(SUBSTITUTE(A1,"8",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"8","")),LEN(A1)-LEN(SUBSTITUTE(A1,"9",""))=LEN(B1)-LEN(SUBSTITUTE(B1,"9",""))),TRUE,FALSE)</code></p>
<p>As you can see, it's an eyesore. It works, but I will need to apply this to at least 100,000 rows of data, and I believe it will be too intensive to work reliably. The current solution is to go through each letter and make sure the count of them matches, and return TRUE if they all do.</p>
<h3>Conclusion</h3>
<p>I have a working solution that gives an example of what is required, but it's clunky and unreliable. I'm hoping there's a better way to utilise Excel in order to complete this task more efficiently. Thanks in advance for your time!</p>
<p><strong>I am using MSO 365, Excel version 2202</strong></p>
|
[
{
"answer_id": 74475382,
"author": "JvdV",
"author_id": 9758194,
"author_profile": "https://Stackoverflow.com/users/9758194",
"pm_score": 2,
"selected": false,
"text": "C2"
},
{
"answer_id": 74475594,
"author": "Tom Sharpe",
"author_id": 3894917,
"author_profile": "https://Stackoverflow.com/users/3894917",
"pm_score": 2,
"selected": false,
"text": "=LAMBDA(string,\n LET(\n codes, SEARCH(\n MID(\n string,\n SEQUENCE(\n LEN(\n string\n )\n ),\n 1\n ),\n \"0123456789abcdefghijklmnopqrstuvxyz\"\n ),\n fcodes, FILTER(\n codes,\n ISNUMBER(codes)\n ),\n freq, FREQUENCY(\n fcodes,\n SEQUENCE(36)\n ),\n freq\n )\n)\n"
},
{
"answer_id": 74475725,
"author": "Jos Woolley",
"author_id": 17007704,
"author_profile": "https://Stackoverflow.com/users/17007704",
"pm_score": 3,
"selected": true,
"text": "LEN"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17901329/"
] |
74,475,216
|
<p>Lets say we have component called Main, iam trying to set up condtion inside of it if user is signed it would have diffent styles, i know it seems easy but iam stuck on it for quit some time.
thanks for any ideas
i had code like this: <a href="https://i.stack.imgur.com/NuKdb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NuKdb.jpg" alt="code snippet" /></a></p>
|
[
{
"answer_id": 74475441,
"author": "Tjeu Foolen",
"author_id": 11023639,
"author_profile": "https://Stackoverflow.com/users/11023639",
"pm_score": 0,
"selected": false,
"text": "export function App(props) {\n const sign = true;\n return (\n <div className=\"container\">\n { sign ? (\n <div>\n <h1>Logged in!</h1>\n </div>\n ) : (\n <div>\n <h1>Guest</h1>\n </div>\n )}\n </div>\n );\n}"
},
{
"answer_id": 74475528,
"author": "Vayne Valerius",
"author_id": 11888674,
"author_profile": "https://Stackoverflow.com/users/11888674",
"pm_score": 1,
"selected": false,
"text": " className={`className1 ${sign ? 'className2' : `className3`}`}\n\n //Or if you want to remove classes based on sign\n className={`className1 ${sign ? 'className2' : ''}`}\n\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9786566/"
] |
74,475,247
|
<p>I have this <code>isData</code> variable declared in my ts file</p>
<pre><code>isData:boolean=false;
</code></pre>
<p>i have this button on my component</p>
<pre><code><button
class="btn btn-primary"
type="button"
(click)="save()"
*ngIf="isData===false"
>
Save
</button>
</code></pre>
<p><code>isData</code> is false but button is not shown i have tried with <code>isData=='false'</code> this also same issue.</p>
<p>Any solution Thanks</p>
|
[
{
"answer_id": 74475441,
"author": "Tjeu Foolen",
"author_id": 11023639,
"author_profile": "https://Stackoverflow.com/users/11023639",
"pm_score": 0,
"selected": false,
"text": "export function App(props) {\n const sign = true;\n return (\n <div className=\"container\">\n { sign ? (\n <div>\n <h1>Logged in!</h1>\n </div>\n ) : (\n <div>\n <h1>Guest</h1>\n </div>\n )}\n </div>\n );\n}"
},
{
"answer_id": 74475528,
"author": "Vayne Valerius",
"author_id": 11888674,
"author_profile": "https://Stackoverflow.com/users/11888674",
"pm_score": 1,
"selected": false,
"text": " className={`className1 ${sign ? 'className2' : `className3`}`}\n\n //Or if you want to remove classes based on sign\n className={`className1 ${sign ? 'className2' : ''}`}\n\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3653474/"
] |
74,475,271
|
<p>So for a project, I gotta make a web-site that fills a shape with circles that wont intersact at any point.The user is going to upload a shape, and also choose the radius of the circles, and the code is going to place as many circles(with the chosen radius) as it can into the shape.</p>
<p>For example, if the user uploads an 16cmx16cm square and chooses 4cm as the radius of the circles, the system is going to place as many circles with a radius of 4cm as possible into the square, and the circles wont intersact at any point.</p>
<p>I tried many things using python and failed eveytime. The shape can be anything, it can be completely random and no matter what the shape is, the site has to find out where to place the circles with the selected radius, place the circles, and show the final shape. I dont know if there is a way to do this without python, but I am open to every suggestion-solution.</p>
|
[
{
"answer_id": 74475441,
"author": "Tjeu Foolen",
"author_id": 11023639,
"author_profile": "https://Stackoverflow.com/users/11023639",
"pm_score": 0,
"selected": false,
"text": "export function App(props) {\n const sign = true;\n return (\n <div className=\"container\">\n { sign ? (\n <div>\n <h1>Logged in!</h1>\n </div>\n ) : (\n <div>\n <h1>Guest</h1>\n </div>\n )}\n </div>\n );\n}"
},
{
"answer_id": 74475528,
"author": "Vayne Valerius",
"author_id": 11888674,
"author_profile": "https://Stackoverflow.com/users/11888674",
"pm_score": 1,
"selected": false,
"text": " className={`className1 ${sign ? 'className2' : `className3`}`}\n\n //Or if you want to remove classes based on sign\n className={`className1 ${sign ? 'className2' : ''}`}\n\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20529785/"
] |
74,475,294
|
<p>I want to replace all forward slashes with a backward slash followed by a forward slash.
Example:</p>
<pre><code>../src/services/resource_mgmt/
</code></pre>
<p>Should be converted to</p>
<pre><code>..\/src\/services\/resource_mgmt\/
</code></pre>
<p>I don't know hot use <code>replaceAll(...)</code> with the correct regex.</p>
|
[
{
"answer_id": 74475450,
"author": "Jay Vaghasiya",
"author_id": 10562084,
"author_profile": "https://Stackoverflow.com/users/10562084",
"pm_score": 1,
"selected": true,
"text": "const url = '../src/services/resource_mgmt/';\nconst newUrl = url.replaceAll(/\\//g, '\\\\/');\nconsole.log(newUrl);"
},
{
"answer_id": 74475492,
"author": "otejiri",
"author_id": 11307127,
"author_profile": "https://Stackoverflow.com/users/11307127",
"pm_score": 1,
"selected": false,
"text": "var url = \"../src/services/resource_mgmt/\";\n\nconst replaceSlash = (url) => {\nvar result = [];\nvar array = url.split(\"\");\narray.forEach(el => {\nel === \"/\" ? result.push(\"\\\\/\") : result.push(el);\n})\nresult = result.join(\"\");\nreturn result;\n};\nconsole.log(replaceSlash(url))"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/951614/"
] |
74,475,304
|
<p>I have a String field in a Dataset in (mmddyyyy) format.</p>
<p>I am trying to convert it into a Date field in SSRS.</p>
<p>I already tried using the below command but I am getting error.</p>
<pre class="lang-vb prettyprint-override"><code>CDate(Fields!LocalTXNDate.Value)
</code></pre>
<p>Can anyone please suggest.</p>
|
[
{
"answer_id": 74475599,
"author": "Larnu",
"author_id": 2029983,
"author_profile": "https://Stackoverflow.com/users/2029983",
"pm_score": 1,
"selected": false,
"text": "MMddyyyy"
},
{
"answer_id": 74480445,
"author": "Hannover Fist",
"author_id": 4459617,
"author_profile": "https://Stackoverflow.com/users/4459617",
"pm_score": 2,
"selected": false,
"text": "=CDATE(\n RIGHT(Fields!LocalTXNDate.Value, 4) & \"-\" & \n LEFT(Fields!LocalTXNDate.Value, 2) & \"-\" & \n MID(Fields!LocalTXNDate.Value, 3, 2)\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4860775/"
] |
74,475,332
|
<p>I've been fighting to go from a nested dictionary of depth <em>D</em> to a pandas DataFrame.</p>
<p>I've tried with recursive function, like the following one, but my problem is that when I'm iterating over a KEY, I don't know what was the pervious key.</p>
<p>I've also tried with json.normalize, pandas from dict but I always end up with dots in the columns...</p>
<p>Example code:</p>
<pre><code>def iterate_dict(d, i = 2, cols = []):
for k, v in d.items():
# missing here how to check for the previous key
# so that I can create an structure to create the dataframe.
if type(v) is dict:
print('this is k: ', k)
if i % 2 == 0:
cols.append(k)
i+=1
iterate_dict(v, i, cols)
else:
print('this is k2: ' , k, ': ', v)
iterate_dict(test2)
</code></pre>
<p>This is an example of how my dictionary looks like:</p>
<pre><code># example 2
test = {
'column-gender': {
'male': {
'column-country' : {
'FRENCH': {
'column-class': [0,1]
},
('SPAIN','ITALY') : {
'column-married' : {
'YES': {
'column-class' : [0,1]
},
'NO' : {
'column-class' : 2
}
}
}
}
},
'female': {
'column-country' : {
('FRENCH', 'SPAIN') : {
'column-class' : [[1,2],'#']
},
'REST-OF-VALUES': {
'column-married' : '*'
}
}
}
}
}
</code></pre>
<p>And this is how I want the dataframe to look like:</p>
<p><a href="https://i.stack.imgur.com/8g2SC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8g2SC.png" alt="enter image description here" /></a></p>
<p>Any suggestion is welcome :)</p>
|
[
{
"answer_id": 74475599,
"author": "Larnu",
"author_id": 2029983,
"author_profile": "https://Stackoverflow.com/users/2029983",
"pm_score": 1,
"selected": false,
"text": "MMddyyyy"
},
{
"answer_id": 74480445,
"author": "Hannover Fist",
"author_id": 4459617,
"author_profile": "https://Stackoverflow.com/users/4459617",
"pm_score": 2,
"selected": false,
"text": "=CDATE(\n RIGHT(Fields!LocalTXNDate.Value, 4) & \"-\" & \n LEFT(Fields!LocalTXNDate.Value, 2) & \"-\" & \n MID(Fields!LocalTXNDate.Value, 3, 2)\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9274940/"
] |
74,475,341
|
<p>I am using <code>react-bootstrap</code> components. I have a <code>table</code> covered by a <code>div</code>. The table has six rows. I have added <code>height</code> to my div, but <code>table</code> is not sized according to <code>height</code>.</p>
<p><strong>I need the table to fit inside the div, and the table header should be fixed and table body content should scroll.</strong></p>
<p>UI Looks like this below</p>
<p><a href="https://i.stack.imgur.com/7D86s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7D86s.png" alt="enter image description here" /></a></p>
<p>It overflows in the div. I tried applying height and scroll. But it's not working.</p>
<p>Here's the Code I tried:</p>
<pre><code>import Table from "react-bootstrap/Table";
import "bootstrap/dist/css/bootstrap.min.css";
export default function App() {
return (
<div style={{ height: "200px", backgroundColor: "aqua" }}>
<Table striped bordered>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody style={{ overflow:"scroll" }}>
<tr>
<td>1</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<td>2</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<td>3</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<td>4</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<td>5</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<td>6</td>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
</tbody>
</Table>
</div>
);
}
</code></pre>
<p>I don't know how to make it. Please help me with some solutions.</p>
<p>Code SandBox Link: <a href="https://codesandbox.io/s/agitated-hamilton-qh1eh5?file=/src/App.js" rel="nofollow noreferrer">https://codesandbox.io/s/agitated-hamilton-qh1eh5?file=/src/App.js</a></p>
|
[
{
"answer_id": 74475559,
"author": "erecodes",
"author_id": 18703252,
"author_profile": "https://Stackoverflow.com/users/18703252",
"pm_score": 2,
"selected": true,
"text": "overflow-y: scroll"
},
{
"answer_id": 74475619,
"author": "SDP",
"author_id": 20451697,
"author_profile": "https://Stackoverflow.com/users/20451697",
"pm_score": 0,
"selected": false,
"text": "responsive"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19576691/"
] |
74,475,360
|
<p>I have my model called Restaurant:
realm object on kotlin:</p>
<pre><code>class Restaurant : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId.create()
var name: String = ""
var adress: String? = null
}
</code></pre>
<p>I want to use the _id property. But for that I need to convert to a String in SwiftUI</p>
<p>I tried: <code>restaurant_id as! String</code>, it does not work,</p>
<p>Is is related to this post: <a href="https://www.mongodb.com/community/forums/t/swift-convert-objectid-to-string/121829" rel="nofollow noreferrer">https://www.mongodb.com/community/forums/t/swift-convert-objectid-to-string/121829</a></p>
<p>No real answers there</p>
<p>Any other solutions?
the error when using .toHexString(): <code>Value of type 'any Library_baseObjectId' has no member 'toHexString'</code>:</p>
<p><a href="https://i.stack.imgur.com/etIAA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/etIAA.png" alt="enter image description here" /></a></p>
<p>the type of _id in this case:
<a href="https://i.stack.imgur.com/3HXKh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3HXKh.png" alt="enter image description here" /></a></p>
<p>The error when trying: <code>"\(restaurant._id.stringValue)"</code></p>
<p><a href="https://i.stack.imgur.com/pQTTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pQTTE.png" alt="enter image description here" /></a></p>
|
[
{
"answer_id": 74480085,
"author": "Jay",
"author_id": 2851937,
"author_profile": "https://Stackoverflow.com/users/2851937",
"pm_score": 0,
"selected": false,
"text": "let idAsAsString = someRealmObject._id.stringValue\n"
},
{
"answer_id": 74494828,
"author": "DhanDaniel",
"author_id": 20468094,
"author_profile": "https://Stackoverflow.com/users/20468094",
"pm_score": 2,
"selected": true,
"text": "class Restaurant : RealmObject {\n @PrimaryKey\n var _id: ObjectId = ObjectId.create()\n var name: String = \"\"\n var adress: String? = null\n\n fun getID() : String{\n return _id.toString()\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20468094/"
] |
74,475,381
|
<p>I am sending HTML to my back-end and back-end is using Send-Grid to send that HTML to provided email address in body of Email.</p>
<p><strong>C# Code</strong></p>
<pre><code>public async Task SendEmail(string toAddress, string html)
{
var email = new SendGridMessage
{
From = new EmailAddress(FromEmailAddress, FromDisplayName),
HtmlContent = html,
Personalizations = new List<Personalization>()
{
new Personalization()
{
Tos = new List<EmailAddress>(){new EmailAddress(toAddress)}
}
},
PlainTextContent = string.Empty,
Subject = Subject,
MailSettings= new MailSettings()
};
email.SetClickTracking(false, false);
await _sendGridClient.SendEmailAsync(email);
}
</code></pre>
<p>HTML Looks fine when I look it in back-end while debugging.</p>
<p><a href="https://i.stack.imgur.com/ckeN6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ckeN6.png" alt="enter image description here" /></a></p>
<p>But when I check this email within outlook Email within Chrome and Edge browser it looks like this.
<a href="https://i.stack.imgur.com/XzADO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XzADO.png" alt="enter image description here" /></a>
It should look like this actually , it working fine even for external outlook app. Problem is with Chrome and Edge
<a href="https://i.stack.imgur.com/2m3Uf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2m3Uf.png" alt="enter image description here" /></a></p>
<p>I have tried inclining the css in html as well using using Premail Package of .NET</p>
<p>I have tried few things
Before sending email I have tried to replace anchor tags with buttons like <code><button> ... </button></code>it resolved styling issue in browser but with that button is no more clickable , in other words href is no more working. So in next go I replaced anchor tag with <code><a type='button'>..</a></code>. Now styling working fine in outlook app but not in browsers and link is no more working in browser</p>
<p>This is the HTML I am recieving at the back-end.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional //EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">\n<head>\n<!--[if gte mso 9]>\n<xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n</xml>\n<![endif]-->\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"x-apple-disable-message-reformatting\">\n <!--[if !mso]><!--><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]-->\n <title></title>\n \n <style type=\"text/css\">\n @media only screen and (min-width: 520px) {\n .u-row {\n width: 500px !important;\n }\n .u-row .u-col {\n vertical-align: top;\n }\n\n .u-row .u-col-100 {\n width: 500px !important;\n }\n\n}\n\n@media (max-width: 520px) {\n .u-row-container {\n max-width: 100% !important;\n padding-left: 0px !important;\n padding-right: 0px !important;\n }\n .u-row .u-col {\n min-width: 320px !important;\n max-width: 100% !important;\n display: block !important;\n }\n .u-row {\n width: calc(100% - 40px) !important;\n }\n .u-col {\n width: 100% !important;\n }\n .u-col > div {\n margin: 0 auto;\n }\n}\nbody {\n margin: 0;\n padding: 0;\n}\n\ntable,\ntr,\ntd {\n vertical-align: top;\n border-collapse: collapse;\n}\n\np {\n margin: 0;\n}\n\n.ie-container table,\n.mso-container table {\n table-layout: fixed;\n}\n\n* {\n line-height: inherit;\n}\n\na[x-apple-data-detectors='true'] {\n color: inherit !important;\n text-decoration: none !important;\n}\n\ntable, td { color: #000000; } #u_body a { color: #0000ee; text-decoration: underline; }\n </style>\n \n \n\n</head>\n\n<body class=\"clean-body u_body\" style=\"margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #e7e7e7;color: #000000\">\n <!--[if IE]><div class=\"ie-container\"><![endif]-->\n <!--[if mso]><div class=\"mso-container\"><![endif]-->\n <table id=\"u_body\" style=\"border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: #e7e7e7;width:100%\" cellpadding=\"0\" cellspacing=\"0\">\n <tbody>\n <tr style=\"vertical-align: top\">\n <td style=\"word-break: break-word;border-collapse: collapse !important;vertical-align: top\">\n <!--[if (mso)|(IE)]><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"center\" style=\"background-color: #e7e7e7;\"><![endif]-->\n \n\n<div class=\"u-row-container\" style=\"padding: 0px;background-color: transparent\">\n <div class=\"u-row\" style=\"Margin: 0 auto;min-width: 320px;max-width: 500px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;\">\n <div style=\"border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;\">\n <!--[if (mso)|(IE)]><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td style=\"padding: 0px;background-color: transparent;\" align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:500px;\"><tr style=\"background-color: transparent;\"><![endif]-->\n \n<!--[if (mso)|(IE)]><td align=\"center\" width=\"500\" style=\"width: 500px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;\" valign=\"top\"><![endif]-->\n<div class=\"u-col u-col-100\" style=\"max-width: 320px;min-width: 500px;display: table-cell;vertical-align: top;\">\n <div style=\"height: 100%;width: 100% !important;\">\n <!--[if (!mso)&(!IE)]><!--><div style=\"height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;\"><!--<![endif]-->\n \n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <!--[if mso]><style>.v-button {background: transparent !important;}</style><![endif]-->\n<div align=\"center\">\n <!--[if mso]><v:roundrect xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"urn:schemas-microsoft-com:office:word\" href=\"\" style=\"height:37px; v-text-anchor:middle; width:139px;\" arcsize=\"11%\" stroke=\"f\" fillcolor=\"#3AAEE0\"><w:anchorlock/><center style=\"color:#FFFFFF;font-family:arial,helvetica,sans-serif;\"><![endif]--> \n <a href=\"\" target=\"_blank\" class=\"v-button\" style=\"box-sizing: border-box;display: inline-block;font-family:arial,helvetica,sans-serif;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;\">\n <span style=\"display:block;padding:10px 20px;line-height:120%;\"><span style=\"font-size: 14px; line-height: 16.8px;\">Button Bug Text</span></span>\n </a>\n <!--[if mso]></center></v:roundrect><![endif]-->\n</div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <div style=\"line-height: 140%; text-align: left; word-wrap: break-word;\">\n <p style=\"font-size: 14px; line-height: 140%;\">This is a new Text block. Change the text.</p>\n </div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n <!--[if (!mso)&(!IE)]><!--></div><!--<![endif]-->\n </div>\n</div>\n<!--[if (mso)|(IE)]></td><![endif]-->\n <!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->\n </div>\n </div>\n</div>\n\n\n <!--[if (mso)|(IE)]></td></tr></table><![endif]-->\n </td>\n </tr>\n </tbody>\n </table>\n <!--[if mso]></div><![endif]-->\n <!--[if IE]></div><![endif]-->\n</body>\n\n</html>\n"</code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74480085,
"author": "Jay",
"author_id": 2851937,
"author_profile": "https://Stackoverflow.com/users/2851937",
"pm_score": 0,
"selected": false,
"text": "let idAsAsString = someRealmObject._id.stringValue\n"
},
{
"answer_id": 74494828,
"author": "DhanDaniel",
"author_id": 20468094,
"author_profile": "https://Stackoverflow.com/users/20468094",
"pm_score": 2,
"selected": true,
"text": "class Restaurant : RealmObject {\n @PrimaryKey\n var _id: ObjectId = ObjectId.create()\n var name: String = \"\"\n var adress: String? = null\n\n fun getID() : String{\n return _id.toString()\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10569355/"
] |
74,475,386
|
<p>How do I add extra rows for all columns (except the grouping variable) for each group <code>id</code> in the data frame?</p>
<p>Data:</p>
<pre><code>> library(tidyverse)
> df <- tibble(id = c("A", "B", "C"), day = c(3, 1, 2), station = c(10, 9, 2))
> df
# A tibble: 3 × 3
id day station
<chr> <dbl> <dbl>
1 A 3 10
2 B 1 9
3 C 2 2
</code></pre>
<p>Expected output:</p>
<pre><code># A tibble: 6 × 3
# Groups: id [3]
id day station
<chr> <dbl> <dbl>
1 A 2 9
2 A 3 10
3 B 0 8
4 B 1 9
5 C 1 1
6 C 2 2
</code></pre>
<p>I could change <code>day</code> using:</p>
<pre><code>> df %>% group_by(id) %>% complete(day = (day - 1):day)
# A tibble: 6 × 3
# Groups: id [3]
id day station
<chr> <dbl> <dbl>
1 A 2 NA
2 A 3 10
3 B 0 NA
4 B 1 9
5 C 1 NA
6 C 2 2
</code></pre>
<p>But I couldn't use <code>mutate</code> appropriately to do this for <code>station</code> as well as since I don't know <em>how to refer to each column</em> inside <code>complete</code> properly:</p>
<p>Failed attempt:</p>
<pre><code>> df %>%
+ group_by(id) %>%
+ mutate(across(c("day", "station"), complete((.x - 1):.x)))
</code></pre>
|
[
{
"answer_id": 74475488,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 3,
"selected": true,
"text": "df %>% \nbind_rows(df %>% mutate(across(c('day', 'station'), ~.x - 1 ))) %>% \narrange(id)\n\n# A tibble: 6 × 3\n# id day station\n# <chr> <dbl> <dbl>\n# 1 A 3 10\n# 2 A 2 9\n# 3 B 1 9\n# 4 B 0 8\n# 5 C 2 2\n# 6 C 1 1\n"
},
{
"answer_id": 74475507,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 2,
"selected": false,
"text": "data.table"
},
{
"answer_id": 74475657,
"author": "dufei",
"author_id": 10363163,
"author_profile": "https://Stackoverflow.com/users/10363163",
"pm_score": 2,
"selected": false,
"text": "df %>%\n group_by(id) %>%\n summarize(across(day:station, ~ .x - 1:0))\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7789963/"
] |
74,475,404
|
<p>i have declared an array globally so that i can modify that inside a function. but after i try and modify the array. the array is showing showing any data and the array is alwayes becomes 0.</p>
<p>this is where the function is been callled from:</p>
<pre><code>var vehicleTypesArr = []; //globally accessable.
function loadVehicleTypes(data) {
if (data != null) {
var res = data.VehicleTypes;
if (res != '' && res != null) {
$.each(res, function () {
if (res.GroupName === 'ConEnhTyp_Vehicle')
vehicleTypesArr.push(this);
//console() : if i put a console here, the result will the data with specific groupName and prints until the loop is ended with the data.
});
}
}
console.log(JSON.stringify(vehicleTypesArr)); // console 1 : result = 0
resetVehicleTypes(); //here i call 2nd code snippet
};
</code></pre>
<p>This is the 2nd code snippet:</p>
<pre><code>function resetVehicleTypes() {
alert("1");
if (vehicleTypesArr.length > 0) {
alert("2");
$.each(vehicleTypesArr, function (val) {
val.prop('checked', false);
});
alert("1");
}
alert("Finished");
}
</code></pre>
<p>the code enters the function and alerts the 1, and then goes staright to the finished alert.</p>
<p>I tried,</p>
<p>on the console() : i put a console and the result was the data with specific groupName and prints until the loop is ended with the data.</p>
<p>but in the console 1 the array is empty. i tried changing length condition and its not working.</p>
<p>still has no supprt.</p>
|
[
{
"answer_id": 74475488,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 3,
"selected": true,
"text": "df %>% \nbind_rows(df %>% mutate(across(c('day', 'station'), ~.x - 1 ))) %>% \narrange(id)\n\n# A tibble: 6 × 3\n# id day station\n# <chr> <dbl> <dbl>\n# 1 A 3 10\n# 2 A 2 9\n# 3 B 1 9\n# 4 B 0 8\n# 5 C 2 2\n# 6 C 1 1\n"
},
{
"answer_id": 74475507,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 2,
"selected": false,
"text": "data.table"
},
{
"answer_id": 74475657,
"author": "dufei",
"author_id": 10363163,
"author_profile": "https://Stackoverflow.com/users/10363163",
"pm_score": 2,
"selected": false,
"text": "df %>%\n group_by(id) %>%\n summarize(across(day:station, ~ .x - 1:0))\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20414146/"
] |
74,475,405
|
<p>I need to get the first occurrence from duplicate column headers as follows:</p>
<p><a href="https://i.stack.imgur.com/2YQyh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2YQyh.png" alt="enter image description here" /></a></p>
<p>A workaround was to group all the same columns and use an <code>IF</code> blank then get next column formula. However, it seems not efficient if a column was added in between or the columns were re-arranged in some way. So the quickest way I could think of is to just get the first occurrence from a range that's equal to the column header.</p>
|
[
{
"answer_id": 74475569,
"author": "player0",
"author_id": 5632629,
"author_profile": "https://Stackoverflow.com/users/5632629",
"pm_score": 3,
"selected": true,
"text": "=INDEX(FILTER(A1:E5, A1:E1=\"name\"),,1)\n"
},
{
"answer_id": 74475967,
"author": "Martín",
"author_id": 20363318,
"author_profile": "https://Stackoverflow.com/users/20363318",
"pm_score": 1,
"selected": false,
"text": "=query({A1:Z},\"Select Col\"&JOIN(\", Col\",byrow(filter(unique(transpose(A1:1)),unique(transpose(A1:1))<>\"\"),lambda(each,match(each,A1:1,0)))),true)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1781041/"
] |
74,475,444
|
<p>I am trying to model the following strict constraint in python with docplex:</p>
<pre><code>mdl.add_constraint(sum(a[i] * mdl.variable[i] for i in range(nrItems)) > b)
</code></pre>
<p>but I keep getting the error:
docplex.mp.utils.DOcplexException: Unsupported relational operator: only <=, ==, >= are allowed</p>
<p>How can one programm a strict constraint in docplex?</p>
|
[
{
"answer_id": 74475569,
"author": "player0",
"author_id": 5632629,
"author_profile": "https://Stackoverflow.com/users/5632629",
"pm_score": 3,
"selected": true,
"text": "=INDEX(FILTER(A1:E5, A1:E1=\"name\"),,1)\n"
},
{
"answer_id": 74475967,
"author": "Martín",
"author_id": 20363318,
"author_profile": "https://Stackoverflow.com/users/20363318",
"pm_score": 1,
"selected": false,
"text": "=query({A1:Z},\"Select Col\"&JOIN(\", Col\",byrow(filter(unique(transpose(A1:1)),unique(transpose(A1:1))<>\"\"),lambda(each,match(each,A1:1,0)))),true)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20529940/"
] |
74,475,500
|
<p>I am implementing a custom side panel that opens up from the right. I am able to achieve show and hide of the panel on a click of a button. But I want the same thing to be hidden when i click outside. I am attaching the outside click handler, And when I do that it is not even showing up. Can someone help</p>
<p><a href="https://codesandbox.io/s/react-sliding-pane-v2-4xuj57?file=/src/SlideDrawer.jsx:100-173" rel="nofollow noreferrer">https://codesandbox.io/s/react-sliding-pane-v2-4xuj57?file=/src/SlideDrawer.jsx:100-173</a></p>
<pre><code>import React, { useRef, useCallback, useEffect } from "react";
import "./styles.css";
export default function SlideDrawer({ show, setDrawerOpen }) {
const sideMenuRef = useRef(null);
const onOutsideClick = useCallback(() => {
setDrawerOpen(false);
}, [setDrawerOpen]);
useEffect(() => {
document.addEventListener("click", onOutsideClick);
return () => document.removeEventListener("click", onOutsideClick);
}, [onOutsideClick]);
return (
<div ref={sideMenuRef} className={`panel ${show && "slidein"}`}>
I am sliding
</div>
);
}
</code></pre>
<pre><code>import React, { useState } from "react";
import ReactDOM from "react-dom";
import SlideDrawer from "./SlideDrawer.jsx";
import "./styles.css";
function App() {
const [drawerOpen, setDrawerOpen] = useState(false);
return (
<div className="box">
<SlideDrawer show={drawerOpen} setDrawerOpen={setDrawerOpen} />
<button onClick={() => setDrawerOpen((prev) => !prev)}>Click me!</button>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
</code></pre>
|
[
{
"answer_id": 74475574,
"author": "torquan",
"author_id": 10882109,
"author_profile": "https://Stackoverflow.com/users/10882109",
"pm_score": 2,
"selected": true,
"text": "drawerOpen"
},
{
"answer_id": 74475811,
"author": "Oleg Brazhnichenko",
"author_id": 7028321,
"author_profile": "https://Stackoverflow.com/users/7028321",
"pm_score": 0,
"selected": false,
"text": "document.addEventListener(\"mousedown\", onOutsideClick);\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16860065/"
] |
74,475,510
|
<p>I have an array of object and there is a field which is an array and I want to sort the result based on its length.</p>
<p>I have tried with lodash orderBy but its showing in asc to desc instead of desc to asc.</p>
<p>Code --></p>
<pre><code>const arr = [{answer: "don't knoweee",
questionText: "Test?" ,
upvote:[246,22]},
{answer: "Test2",
questionText: "dummy question?" ,
upvote:[246]
},
{answer: "answertest",
questionText: "Hello?" ,
upvote:null
}]
</code></pre>
<p>My solution :</p>
<pre><code>orderBy(arr, (i) => i?.upvote?.length, ['desc']
</code></pre>
<p>Its showing "dummy question?" first instead of "Test?" question.</p>
|
[
{
"answer_id": 74475547,
"author": "Andrew Parks",
"author_id": 5898421,
"author_profile": "https://Stackoverflow.com/users/5898421",
"pm_score": 2,
"selected": true,
"text": "const upvoteLength = ({upvote:x})=>x?.length??0;\nconst descending = f=>(a,b)=>f(b)-f(a);\nconsole.log([...arr].sort(descending(upvoteLength)));"
},
{
"answer_id": 74475734,
"author": "Mark Schultheiss",
"author_id": 125981,
"author_profile": "https://Stackoverflow.com/users/125981",
"pm_score": 0,
"selected": false,
"text": "const arr = [{\n answer: \"don't knoweee\",\n questionText: \"Test?\",\n upvote: [246, 22]\n },\n {\n answer: \"Test2\",\n questionText: \"dummy question?\",\n upvote: [246]\n },\n {\n answer: \"answertest\",\n questionText: \"Hello?\",\n upvote: null\n }\n];\n\nlet newarr = _.orderBy(arr, [(i) => i.upvote?.length], ['desc']);\nconsole.log(newarr);"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11957027/"
] |
74,475,561
|
<p>This is pretty easy to replicate but also code here:</p>
<p><a href="https://github.com/dominicshaw/dotnet-publish-error" rel="nofollow noreferrer">https://github.com/dominicshaw/dotnet-publish-error</a></p>
<ul>
<li>create an empty wpf project using .NET7</li>
<li>create a publish profile for ClickOnce</li>
<li>publish via command line (not visual studio)</li>
</ul>
<p>Publish profile is almost totally standard (<a href="https://github.com/dominicshaw/dotnet-publish-error/blob/main/PublishError/Properties/PublishProfiles/ClickOnceProfile.pubxml" rel="nofollow noreferrer">view here</a>)</p>
<p>Command line from project directory:</p>
<p><code>dotnet publish PublishError.csproj -p:PublishProfile=ClickOnceProfile</code></p>
<p>Subsequent error:</p>
<pre><code>MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.100\Microsoft.Common.CurrentVersion.targets(4149,5): error MSB4062: The "Microsoft.Build.Tasks.RequiresFr
amework35SP1Assembly" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKey
Token=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, a
nd that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\shawd\source\repos\PublishError\Publi
shError\PublishError.csproj]
</code></pre>
<p>I have the latest SDKs installed and VS2022 up to date. This only happens via command line - I am able to publish from Visual Studio (I am setting up devops, so require command line).</p>
<p>This happens regardless of adding nuget package for Microsoft.Build.Tasks.Core. Note however nuget package v15.1.0.0 is not available - I have tried 15.1.548 and the latest instead.</p>
<p>Totally at a loss! Any ideas very welcome.</p>
<p>Thanks vm</p>
|
[
{
"answer_id": 74475547,
"author": "Andrew Parks",
"author_id": 5898421,
"author_profile": "https://Stackoverflow.com/users/5898421",
"pm_score": 2,
"selected": true,
"text": "const upvoteLength = ({upvote:x})=>x?.length??0;\nconst descending = f=>(a,b)=>f(b)-f(a);\nconsole.log([...arr].sort(descending(upvoteLength)));"
},
{
"answer_id": 74475734,
"author": "Mark Schultheiss",
"author_id": 125981,
"author_profile": "https://Stackoverflow.com/users/125981",
"pm_score": 0,
"selected": false,
"text": "const arr = [{\n answer: \"don't knoweee\",\n questionText: \"Test?\",\n upvote: [246, 22]\n },\n {\n answer: \"Test2\",\n questionText: \"dummy question?\",\n upvote: [246]\n },\n {\n answer: \"answertest\",\n questionText: \"Hello?\",\n upvote: null\n }\n];\n\nlet newarr = _.orderBy(arr, [(i) => i.upvote?.length], ['desc']);\nconsole.log(newarr);"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4324180/"
] |
74,475,576
|
<p>let's assume the following code in c:</p>
<pre><code>#include <stdio.h>
#include <cs50.h>
int test (int a, int b);
int main(void)
{
test(2,3);
}
int test (int a, int b)
{
int c = a+b;
printf("%d \n", test(a,b));
return c;
}
</code></pre>
<p>why is it not possible to print the value of test without having to save it in a variable before and print the variable? I get the error:</p>
<blockquote>
<p>function.c:12:1: error: all paths through this function will call itself [-Werror,-Winfinite-recursion]</p>
</blockquote>
<p>Thank you!</p>
<pre><code>#include <stdio.h>
#include <cs50.h>
int test (int a, int b);
int main(void)
{
test(2,3);
}
int test (int a, int b)
{
int c = a+b;
printf("%d \n", test(a,b));
return c;
}
</code></pre>
|
[
{
"answer_id": 74475620,
"author": "abelenky",
"author_id": 34824,
"author_profile": "https://Stackoverflow.com/users/34824",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <cs50.h>\n\nint test (int a, int b);\n\nint main(void)\n{\n test(2,3);\n}\n\nint test (int a, int b)\n{\n int c = a+b;\n printf(\"%d \\n\", c); // Show the result of the calculation\n // but without calling this function again.\n return c;\n\n}\n"
},
{
"answer_id": 74475627,
"author": "Eric Postpischil",
"author_id": 298225,
"author_profile": "https://Stackoverflow.com/users/298225",
"pm_score": 3,
"selected": true,
"text": "printf(\"%d \\n\", test(a,b));"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20529705/"
] |
74,475,586
|
<p>I try to convert CSV from Clash Royale.</p>
<p>I wanna push number in rows to array</p>
<p>real csv data header or property is over 40 properties</p>
<p>example data:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">name</th>
<th style="text-align: left;">level count</th>
<th style="text-align: left;">upgrade cost</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">common</td>
<td style="text-align: left;">14</td>
<td style="text-align: left;">5</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">20</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">50</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">100</td>
</tr>
<tr>
<td style="text-align: left;">rare</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">50</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">150</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">400</td>
</tr>
<tr>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">1000</td>
</tr>
</tbody>
</table>
</div>
<p>my node.js code:</p>
<pre><code>const fs = require('fs')
const papa = require("papaparse")
const results = []
const options = { header: true, dynamicTyping: true }
fs.createReadStream("rarities.csv")
.pipe(papa.parse(papa.NODE_STREAM_INPUT, options))
.on("data", (data) => results.push(data))
.on("end", () => console.log(results))
</code></pre>
<p>output expecting:</p>
<pre><code>
[
{
name: "common",
level_count: 14,
upgrade_cost: [5, 20, 50, 100]
},
{
name: "rare",
level_count: 12,
upgrade_cost: [50, 150, 400, 1000]
},
]
</code></pre>
|
[
{
"answer_id": 74475707,
"author": "Mohit Singh",
"author_id": 15832446,
"author_profile": "https://Stackoverflow.com/users/15832446",
"pm_score": 1,
"selected": false,
"text": "convert-csv-to-json"
},
{
"answer_id": 74475901,
"author": "Pompedup",
"author_id": 12239272,
"author_profile": "https://Stackoverflow.com/users/12239272",
"pm_score": 2,
"selected": false,
"text": ".on(\"end\", () => {\n let savedName, savedLevelCount\n\n const goupedByNameAndLevelCount = results.reduce((acc, { name, level_count, upgrade_cost }) => {\n if (name && level_count) {\n savedName = name\n savedLevelCount = level_count\n }\n acc[savedName] ||= {}\n acc[savedName][savedLevelCount] ||= []\n acc[savedName][savedLevelCount].push(upgrade_cost)\n return acc\n }, {})\n const preciousData = Object.entries(goupedByNameAndLevelCount).map(([name, groupedByLevelCount]) => {\n return Object.entries(groupedByLevelCount).map(([level_count, upgrade_cost]) => ({\n name,\n level_count,\n upgrade_cost\n }))\n })\n console.log(preciousData)\n})\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18403575/"
] |
74,475,644
|
<p>We have an application on java springboot which would interact with IoT devices via HTTP Rest API. However, there is an IoT device that communicates with the LWM2M protocol. So, I need to set up an LWM2M server and make the application an LWM2M client.
First I wanted to make a prototype on my local machine running application on Windows with eclipse ide. I tried importing the Leshan project from this <a href="https://github.com/eclipse/leshan" rel="nofollow noreferrer">link</a> on eclipse workspace. However when maven clean install, it is not creating a jar file for every project. Attaching the result at eclipse console, when I do maven clean install.<a href="https://i.stack.imgur.com/OsGhl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OsGhl.png" alt="result of maven clean install" /></a>.
My ask is:</p>
<ol>
<li>Am I going the right way, in order to implement the LWM2M protocol locally?</li>
<li>How to resolve all jars not creating with Maven clean Install.</li>
</ol>
|
[
{
"answer_id": 74492273,
"author": "eliasw",
"author_id": 851896,
"author_profile": "https://Stackoverflow.com/users/851896",
"pm_score": 2,
"selected": true,
"text": " <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-core</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-core</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-cf</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-redis</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.californium</groupId>\n <artifactId>californium-core</artifactId>\n <version>3.7.0</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.californium</groupId>\n <artifactId>scandium</artifactId>\n <version>3.7.0</version>\n </dependency>\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5804899/"
] |
74,475,656
|
<p>I want to change a specific part of a tuple. Is it possible to use pattern matching?</p>
<pre class="lang-elixir prettyprint-override"><code>{1, [{:reach, [:s, :d]}, [link: [:s, :d]]]}
</code></pre>
<p>I want to change reach to <code>:reach_1</code>. I can fetch the reach field but cannot modify the whole tuple.</p>
<pre class="lang-elixir prettyprint-override"><code>{id, [{item, _}, _]} = {1, [{:reach, [:s, :d]}, [link: [:s, :d]]]}
:"#{item}_#{id}"
</code></pre>
<p>How can I add it back to the tuple replacing <code>:reach</code> ?</p>
|
[
{
"answer_id": 74492273,
"author": "eliasw",
"author_id": 851896,
"author_profile": "https://Stackoverflow.com/users/851896",
"pm_score": 2,
"selected": true,
"text": " <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-core</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-core</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-cf</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.leshan</groupId>\n <artifactId>leshan-server-redis</artifactId>\n <version>2.0.0-M9</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.californium</groupId>\n <artifactId>californium-core</artifactId>\n <version>3.7.0</version>\n </dependency>\n <dependency>\n <groupId>org.eclipse.californium</groupId>\n <artifactId>scandium</artifactId>\n <version>3.7.0</version>\n </dependency>\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6487751/"
] |
74,475,746
|
<p>I have built a Python package according to the documentation: <a href="https://packaging.python.org/en/latest/tutorials/packaging-projects/" rel="nofollow noreferrer">https://packaging.python.org/en/latest/tutorials/packaging-projects/</a></p>
<p>Everything works, but when I call pip install my_package.whl, the dependencies are not installed.</p>
<p>The dependencies are listed in the pyproject.toml file as follows:
requires = ["hatchling", "package1", "package2"]</p>
<p><strong>Question 1.</strong> During the build, I can see the following log:</p>
<pre><code>* Installing packages in isolated environment... (hatchling, pydicom~=2.3.1)
</code></pre>
<p>What does it mean the dependencies installed and for what purpose?</p>
<p><strong>Question 2.</strong> How to achieve the behavior, where after typing 'pip install my_package.whl', the required dependencies are installed beforehand. This must be possible, becaus all of the available python packages work this way.</p>
|
[
{
"answer_id": 74477414,
"author": "The Lazy Graybeard",
"author_id": 9608497,
"author_profile": "https://Stackoverflow.com/users/9608497",
"pm_score": 2,
"selected": true,
"text": "require"
},
{
"answer_id": 74477451,
"author": "Karol Borkowski",
"author_id": 3975218,
"author_profile": "https://Stackoverflow.com/users/3975218",
"pm_score": 0,
"selected": false,
"text": "from setuptools import setup\n\nsetup(\n name='my_package',\n version='1.0.0',\n description='Description',\n author='Karol',\n packages=['my_package'],\n install_requires=[\n 'numpy~=1.23.4',\n 'pillow~=9.3.0',\n 'pydicom~=2.3.1'\n ],\n zip_safe=False\n)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3975218/"
] |
74,475,753
|
<p>I am getting syntax errors when trying to run or sometimes it runs but does not execute the way I am intending it to.</p>
<p>I have been playing around with the formatting but still no solution.</p>
<pre><code>def checkVowelsConsonants(s):
vowels=0
consonants=0
for ch in s:
#convert character into its ASCII equivalent
ascii_value=ord(ch)
#if ASCII is between 65 to 90 to 97 to 122 then it's a character
#otherwise a special character
if((ascii_value>=65 and ascii_value<=90)or(ascii_value>=97 and ascii_value<=122)):
#check for lower case
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
vowels=vowels+1
#check for upper case
elif ch=='A' or ch=='E' or ch=='I' or ch=='O' or ch=='U':
vowels=vowels+1
else:
consonants=consonants+1
#print the result
print("The number of vowels is "+str(vowels)+" and consonants is "+str(consonants))
while True:
#print the menu
print("1. Print the number of vowels and consonats")
print("2. Exit the program")
#take choioce as input from user
choice=int(input("Enter choice: "))
#take sentence input from user
if choice==1:
sentence=input("Enter a sentence: ")
sentence_list=[]
for ch in sentence:
sentence_list.append(ch)
checkVowelsConsonants(sentence_list)
#exit the program
if choice==2:
break
#choice other that 1 and 2
else:
print("Invalid choice!")
</code></pre>
|
[
{
"answer_id": 74477414,
"author": "The Lazy Graybeard",
"author_id": 9608497,
"author_profile": "https://Stackoverflow.com/users/9608497",
"pm_score": 2,
"selected": true,
"text": "require"
},
{
"answer_id": 74477451,
"author": "Karol Borkowski",
"author_id": 3975218,
"author_profile": "https://Stackoverflow.com/users/3975218",
"pm_score": 0,
"selected": false,
"text": "from setuptools import setup\n\nsetup(\n name='my_package',\n version='1.0.0',\n description='Description',\n author='Karol',\n packages=['my_package'],\n install_requires=[\n 'numpy~=1.23.4',\n 'pillow~=9.3.0',\n 'pydicom~=2.3.1'\n ],\n zip_safe=False\n)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530075/"
] |
74,475,823
|
<p>I've defined a function <code>obtainToken</code>. This function, send a request to a specific URL and return a token:</p>
<pre><code>async function obtainToken () {
const config = { headers: { 'Content-Type': 'multipart/form-data' } };
await axios
.post('***',{
client_id: '***',
client_secret: '***',
grant_type: 'client_credentials'
},
config)
.then(res => {
return res.data.access_token
})
.catch(error => {
console.error(error)
})
}
module.exports.obtainToken = obtainToken
</code></pre>
<p>As you can see, this function return the token (<code>res.data.access_token</code>)
Into the main file, I've tried to do:</p>
<pre><code>async function initialize(){
var x = await utility.obtainToken()
console.log(x)
}
initialize()
</code></pre>
<p>The token value is <code>undefined</code>. What am I doing wrong? I'm new to nodejs, so I'm sure that the use of async functions is not correct...what's the right way to do what I want to do?</p>
|
[
{
"answer_id": 74477414,
"author": "The Lazy Graybeard",
"author_id": 9608497,
"author_profile": "https://Stackoverflow.com/users/9608497",
"pm_score": 2,
"selected": true,
"text": "require"
},
{
"answer_id": 74477451,
"author": "Karol Borkowski",
"author_id": 3975218,
"author_profile": "https://Stackoverflow.com/users/3975218",
"pm_score": 0,
"selected": false,
"text": "from setuptools import setup\n\nsetup(\n name='my_package',\n version='1.0.0',\n description='Description',\n author='Karol',\n packages=['my_package'],\n install_requires=[\n 'numpy~=1.23.4',\n 'pillow~=9.3.0',\n 'pydicom~=2.3.1'\n ],\n zip_safe=False\n)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20089535/"
] |
74,475,829
|
<p>Hi masters i need to find the best way to convert this:</p>
<pre><code> [
{ "id": 1, "animal": "cat", "age": 6, "name": "loky" },
{ "id": 2, "animal": "cat", "age": 3, "name": "michu", "parent": 1 },
{ "id": 3, "animal": "cat", "age": 2, "name": "boots", "parent": 1 },
{ "id": 4, "animal": "dog", "age": 9, "name": "bones" },
{ "id": 5, "animal": "dog", "age": 6, "name": "chok", "parent": 4 },
{ "id": 6, "animal": "dog", "age": 6, "name": "cofee","parent": 4 }
]
</code></pre>
<p>to this:</p>
<pre><code> [
{ "id": 1,
"animal": "cat",
"age": 6,
"name": "loky",
"childs":[ { "id": 2, "animal": "cat", "age": 3, "name": "michu", "parent": 1 },
{ "id": 3, "animal": "cat", "age": 2, "name": "boots", "parent": 1 }]
}
,
{ "id": 4,
"animal": "dog",
"age": 9,
"name": "bones",
"childs":[{ "id": 5, "animal": "dog", "age": 6, "name": "chok", "parent": 4 },
{ "id": 6, "animal": "dog", "age": 6, "name": "cofee", "parent": 4 }]
}
]
</code></pre>
<p>note that the "parent" key must be used to nest "childs" ,i create my way but with several functions is horrible ,i think there may be a more efficient way.</p>
<p>Thanks in advance sorry for my english</p>
|
[
{
"answer_id": 74476360,
"author": "Shawn",
"author_id": 14361465,
"author_profile": "https://Stackoverflow.com/users/14361465",
"pm_score": 2,
"selected": true,
"text": "const rows = [\n { id: 1, animal: 'cat', age: 6, name: 'loky' },\n { id: 2, animal: 'cat', age: 3, name: 'michu', parent: 1 },\n { id: 3, animal: 'cat', age: 2, name: 'boots', parent: 1 },\n { id: 4, animal: 'dog', age: 9, name: 'bones' },\n { id: 5, animal: 'dog', age: 6, name: 'chok', parent: 4 },\n { id: 6, animal: 'dog', age: 6, name: 'cofee', parent: 4 },\n];\n\nfunction map(rows) {\n const categories = Array.from(new Set(rows.map((row) => row.animal)));\n return categories.map((c) => {\n const parent = rows.find((row) => row.animal === c);\n parent.childs = rows\n .filter((r) => r.id !== parent.id && r.animal === c)\n .map((r) => ({ ...r, parent: parent.id }));\n return parent;\n });\n}\n\nconsole.log(map(row));\n"
},
{
"answer_id": 74482214,
"author": "Shawn",
"author_id": 14361465,
"author_profile": "https://Stackoverflow.com/users/14361465",
"pm_score": 0,
"selected": false,
"text": "const rows = [\n { id: 1, animal: 'cat', age: 6, name: 'loky' },\n { id: 2, animal: 'cat', age: 3, name: 'michu', parent: 1 },\n { id: 3, animal: 'cat', age: 2, name: 'boots', parent: 1 },\n { id: 4, animal: 'dog', age: 9, name: 'bones' },\n { id: 5, animal: 'dog', age: 6, name: 'chok', parent: 4 },\n { id: 6, animal: 'dog', age: 6, name: 'cofee', parent: 4 },\n];\n\nfunction nester(arr) {\n const parents = rows.filter((r) => !r.parent);\n const children = rows.filter((r) => r.parent);\n return parents.map((p) => {\n return {\n ...p,\n children: children.filter((c) => c.parent === p.id),\n };\n });\n}\nconsole.log(nester(rows));\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4781000/"
] |
74,475,833
|
<p>I have a dataframe with 2 columns. How can I create a third column which:</p>
<ol>
<li>Takes either col1 or col2 value if either exists</li>
<li>Takes mean if both exists</li>
<li>Keeps NaN if neither exists</li>
</ol>
<p>And finally I want to store it in df['col3']. I tried this, but the values are wrong.</p>
<pre><code>df['col3']=pd.concat([df['col2'], df['col1']]).groupby(level=0).mean()
</code></pre>
<p>How can I do this?</p>
<pre><code>time col1 col2
2000-01-31 389.5400 NaN
2000-02-29 387.7700 NaN
2000-03-31 386.6600 250.2
2000-04-30 384.1850 NaN
2000-05-31 383.3600 267.2
... ... ...
2020-03-31 396.3755 NaN
2020-04-30 NaN 350.12
2020-05-31 395.0485 NaN
2020-06-30 394.9400 396.321
2020-07-31 395.3070 NaN
</code></pre>
|
[
{
"answer_id": 74475879,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": true,
"text": "df['col3'] = df[['col1', 'col2']].mean(axis=1)\n"
},
{
"answer_id": 74476090,
"author": "Pranav",
"author_id": 11324471,
"author_profile": "https://Stackoverflow.com/users/11324471",
"pm_score": 0,
"selected": false,
"text": "df['col3'] = df.loc[:, [\"col1\",\"col2\"]].mean(axis = 1)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3942806/"
] |
74,475,837
|
<p>I have a DF that contains sources from the traffic of a webpage. the column <code>source</code> contains the detailed source, while <code>global_sources</code> is a handmade categorization that doesn't change. What I'm trying to do is, if <code>global_sources</code> is NA, string detect the unique values of <code>global_sources</code> in <code>source</code> and replace NA with the string that matched.</p>
<h3>What the DF lookslike:</h3>
<pre><code>source <- c('facebook / cpc', 'googletest', 'adwords.google', 'organic', 'source / referral', 'google / source', 'facebook / test')
global_sources <- c('facebook', 'google', NA, 'organic', 'referral', NA, NA)
df <- data.frame(source, global_sources)
df
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>source</th>
<th>global_sources</th>
</tr>
</thead>
<tbody>
<tr>
<td>facebook /cpc</td>
<td>facebook</td>
</tr>
<tr>
<td>googletest</td>
<td>google</td>
</tr>
<tr>
<td>adwords.google</td>
<td>NA</td>
</tr>
<tr>
<td>organic</td>
<td>organic</td>
</tr>
<tr>
<td>source / referral</td>
<td>referral</td>
</tr>
<tr>
<td>google / referral</td>
<td>google</td>
</tr>
<tr>
<td>facebook / test</td>
<td>NA</td>
</tr>
</tbody>
</table>
</div><h3>What I currently have:</h3>
<pre><code>df$global_sources <- ifelse(is.na(df$global_sources),
ifelse(str_detect(df$source, 'facebook'), 'facebook', NA), df$global_sources)
df
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>source</th>
<th>global_sources</th>
</tr>
</thead>
<tbody>
<tr>
<td>facebook /cpc</td>
<td>facebook</td>
</tr>
<tr>
<td>googletest</td>
<td>google</td>
</tr>
<tr>
<td>adwords.google</td>
<td>NA</td>
</tr>
<tr>
<td>organic</td>
<td>organic</td>
</tr>
<tr>
<td>source / referral</td>
<td>referral</td>
</tr>
<tr>
<td>google / referral</td>
<td>NA</td>
</tr>
<tr>
<td>facebook / test</td>
<td>facebook</td>
</tr>
</tbody>
</table>
</div>
<p>Up to this point the code only detects and replaces NA values in <code>global_sources</code> if the string in sources matches 'facebook', otherwise it leaves it as NA. The problem is that I need to do it for all the unique categories in <code>global_sources</code>. I tried doing it with another <code>ifelse</code>, but there are so many categories that it ends up in something super unefficent and hard to read.</p>
<h3>Expected outcome:</h3>
<p>I'm trying to do a <code>for loop</code> but I haven't been able to do anything that works. The intended outcome is:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>source</th>
<th>global_sources</th>
</tr>
</thead>
<tbody>
<tr>
<td>facebook /cpc</td>
<td>facebook</td>
</tr>
<tr>
<td>googletest</td>
<td>google</td>
</tr>
<tr>
<td>adwords.google</td>
<td>google</td>
</tr>
<tr>
<td>organic</td>
<td>organic</td>
</tr>
<tr>
<td>source / referral</td>
<td>referral</td>
</tr>
<tr>
<td>google / referral</td>
<td>google</td>
</tr>
<tr>
<td>facebook / test</td>
<td>facebook</td>
</tr>
</tbody>
</table>
</div>
<p>Note that some values in source have more than one category (like google / referral) but in those cases the last priority is matching with referral.</p>
|
[
{
"answer_id": 74476122,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 0,
"selected": false,
"text": "regex"
},
{
"answer_id": 74476185,
"author": "Dan Adams",
"author_id": 13210554,
"author_profile": "https://Stackoverflow.com/users/13210554",
"pm_score": 1,
"selected": false,
"text": "str_detect()"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14396599/"
] |
74,475,850
|
<p>I have a data frame like this.</p>
<pre><code>document_group
A12J3/381
A02J3/40
B12P4/2536
C10P234/3569
</code></pre>
<p>and I would like to get like this</p>
<pre><code> document_group
A12J3/38
A02J3/40
B12P4/25
C10P234/35
</code></pre>
<p>I have tried to adapt a function for single string like this</p>
<pre><code>def remove_str_start(s, start):
return s[:start] + s[start]
</code></pre>
<p>and work with this sample</p>
<pre><code>s='H02J3/381'
s.find('/')
remove_str_start(s,s.find('/')+2)
</code></pre>
<p>it returns 'H02J3/38', what I want to do while s is the input data frame and start is cutting the char start from the position char.</p>
<p>but when I tried with data frame</p>
<pre><code>remove_str_start(df['document_group'],df['document_group'].str.find('/')+2)
</code></pre>
<p>the result returns an error</p>
<p>could everyone help me with this kind of situation?</p>
|
[
{
"answer_id": 74475891,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": false,
"text": "str.replace"
},
{
"answer_id": 74475928,
"author": "sophocles",
"author_id": 9167382,
"author_profile": "https://Stackoverflow.com/users/9167382",
"pm_score": 3,
"selected": true,
"text": "str.split"
},
{
"answer_id": 74475953,
"author": "Gabino Antuña Ortiz",
"author_id": 17351698,
"author_profile": "https://Stackoverflow.com/users/17351698",
"pm_score": 0,
"selected": false,
"text": "df['new_column'] = [e[:e.find('/') + 3] for e in filt['your_initial_column']]\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10367947/"
] |
74,475,883
|
<p>I have a dataframe with data per day</p>
<pre><code>df = A. B. date
1. 2. 2016-12-31
7. 2. 2016-12-22
4. 3. 2016-12-12
6. 8. 2017-02-03
8. 3. 2017-01-31
1. 0. 2016-12-11
</code></pre>
<p>And so on. I have around 100 rows per month, from Dec-2016 to now.
I want to create a sns.boxplot, where x-axis is <year,month> and y is the value of the column B.
How can I do it?</p>
|
[
{
"answer_id": 74475891,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": false,
"text": "str.replace"
},
{
"answer_id": 74475928,
"author": "sophocles",
"author_id": 9167382,
"author_profile": "https://Stackoverflow.com/users/9167382",
"pm_score": 3,
"selected": true,
"text": "str.split"
},
{
"answer_id": 74475953,
"author": "Gabino Antuña Ortiz",
"author_id": 17351698,
"author_profile": "https://Stackoverflow.com/users/17351698",
"pm_score": 0,
"selected": false,
"text": "df['new_column'] = [e[:e.find('/') + 3] for e in filt['your_initial_column']]\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6057371/"
] |
74,475,887
|
<p>I want to convert the below statement result to list of my object.</p>
<pre><code>import com.amazonaws.services.dynamodbv2.model.ExecuteStatementResult;
ExecuteStatementResult executeStatementResult = dynamoDB.executeStatement(executeStatementRequest);
System.out.println( executeStatementResult.getItems() );
</code></pre>
<p>Output:</p>
<pre><code>[{bookingClasses={S: A,B,C,}, suppliers={S: BA,1A,TF,}, adjustmentType={S: PERCENTAGE,}, departureStartDate={S: 2022-11-17,}}]
</code></pre>
<p>Please note .getItems() method is like below:</p>
<pre><code>public java.util.List<java.util.Map<String, AttributeValue>> getItems() {
return items;
}
</code></pre>
<p>I want something like this to work for me:</p>
<pre><code>List<java.util.Map<String, AttributeValue>> items = executeStatementResult.getItems();
List<PricingRule> pricingRules = ( List<PricingRule> ) items;
</code></pre>
<p>Any help suggestion or workaround appreciated.</p>
<p>Thank you</p>
|
[
{
"answer_id": 74476086,
"author": "Holloway",
"author_id": 1916917,
"author_profile": "https://Stackoverflow.com/users/1916917",
"pm_score": 1,
"selected": false,
"text": "PricingRule::fromMap"
},
{
"answer_id": 74476569,
"author": "Sikandar Sahab",
"author_id": 7472239,
"author_profile": "https://Stackoverflow.com/users/7472239",
"pm_score": 1,
"selected": true,
"text": "public List<PricingRule> statementToList() {\n\n List<PricingRule> pricingRules = new ArrayList<>();\n\n try {\n // Create ExecuteStatementRequest\n ExecuteStatementRequest executeStatementRequest = createExecuteStatementRequest();\n ExecuteStatementResult executeStatementResult = dynamoDB.executeStatement(executeStatementRequest);\n\n final ObjectMapper mapper = new ObjectMapper();\n executeStatementResult.getItems().forEach(item -> pricingRules.add(mapper.convertValue(ItemUtils.toSimpleMapValue(item), PricingRule.class)));\n\n } catch (Exception e) {\n handleExecuteStatementErrors(e);\n }\n\n return pricingRules;\n\n}\n"
},
{
"answer_id": 74477251,
"author": "Borislav Stoilov",
"author_id": 5625696,
"author_profile": "https://Stackoverflow.com/users/5625696",
"pm_score": 1,
"selected": false,
"text": "var table = dynamoDbEnhancedClient.table(\"TableName\", TableSchema.fromClass(PricingRule.class));\nList<PricingRule> items = table.query(<condition>).items().stream().toList();\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7472239/"
] |
74,475,892
|
<p>I try to wrap long text on new line (including all titles main and additional) to new line if this text longer then image width. How can i do this?
I also provide example of my code in codepen
<a href="https://codepen.io/myacat339/pen/OJEjWEZ" rel="nofollow noreferrer">https://codepen.io/myacat339/pen/OJEjWEZ</a>.</p>
<p>Roles element need to be horizontal scrollable!</p>
<p>(I don't have rights of any of these images this only for example!)
<a href="https://i.stack.imgur.com/Sfnvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sfnvf.png" alt="Example of current view" /></a></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>#rolecard {
margin-left: 10px;
margin-bottom: 10px;
}
#containerimgrole {
width: 150px;
border-radius: 10px;
background-color: #000000;
}
#cardmaintext {
color: #ffffff;
font-size: 1rem;
margin-top: 5px;
display: inline-block;
font-family: "Roboto",serif;
font-weight: 600;
text-decoration: none;
hyphens: auto;
}
#cardadditionaltext {
color: #4d4d4d;
font-size: 0.65rem;
margin-top: 5px;
display: inline-block;
font-family: Roboto,serif;
text-decoration: none;
font-weight: 450;
}
#roles {
margin-top: 10px;
margin-left: 10px;
margin-bottom: 10px;
text-decoration: none;
background-color: #1e1e1e;
white-space: nowrap;
}
#characterstitle {
font-family: "Segoe UI",serif;
font-size: 20px;
font-weight: 600;
margin-top: 5px;
margin-left: 10px;
margin-bottom: 5px;
display: inline-block;
text-decoration: none;
color: #eaeaea;
}
.card {
display: inline-block;
text-align: center;
}
.scrolling-wrapper {
overflow-x: hidden;
overflow-y: hidden;
white-space: nowrap;
}
.scrolling-wrapper:hover {
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="roles" style="padding-right: 0.5rem; display: inline-block; margin-top: 5px; border-radius: 15px; margin-left: -3px; width: 60rem;">
<a id="characterstitle" style="margin-bottom: 10px;">Title</a>
<div style="display:block;" class="scrolling-wrapper">
<div class="card" id="rolecard">
<div id="cardrole" >
<img id="containerimgrole" loading="lazy" src="https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/nx21-tXMN3Y20PIL9.jpg" />
<br>
<a id="cardmaintext">Normal text</a>
<br>
<a id="cardadditionaltext">Normal text</a>
<br>
</div>
</div>
<div class="card" id="rolecard">
<div id="cardrole" >
<img id="containerimgrole" loading="lazy" src="https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/nx21-tXMN3Y20PIL9.jpg" />
<br>
<a id="cardmaintext">Very long text for example to text wrap</a>
<br>
<a id="cardadditionaltext">Very long text for example to text wrap</a>
<br>
</div>
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74476086,
"author": "Holloway",
"author_id": 1916917,
"author_profile": "https://Stackoverflow.com/users/1916917",
"pm_score": 1,
"selected": false,
"text": "PricingRule::fromMap"
},
{
"answer_id": 74476569,
"author": "Sikandar Sahab",
"author_id": 7472239,
"author_profile": "https://Stackoverflow.com/users/7472239",
"pm_score": 1,
"selected": true,
"text": "public List<PricingRule> statementToList() {\n\n List<PricingRule> pricingRules = new ArrayList<>();\n\n try {\n // Create ExecuteStatementRequest\n ExecuteStatementRequest executeStatementRequest = createExecuteStatementRequest();\n ExecuteStatementResult executeStatementResult = dynamoDB.executeStatement(executeStatementRequest);\n\n final ObjectMapper mapper = new ObjectMapper();\n executeStatementResult.getItems().forEach(item -> pricingRules.add(mapper.convertValue(ItemUtils.toSimpleMapValue(item), PricingRule.class)));\n\n } catch (Exception e) {\n handleExecuteStatementErrors(e);\n }\n\n return pricingRules;\n\n}\n"
},
{
"answer_id": 74477251,
"author": "Borislav Stoilov",
"author_id": 5625696,
"author_profile": "https://Stackoverflow.com/users/5625696",
"pm_score": 1,
"selected": false,
"text": "var table = dynamoDbEnhancedClient.table(\"TableName\", TableSchema.fromClass(PricingRule.class));\nList<PricingRule> items = table.query(<condition>).items().stream().toList();\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17695221/"
] |
74,475,899
|
<p>Trying to format the number as per the given format and culture.</p>
<p>Given:</p>
<pre><code>-4059587.225000, --Value
'#,##0.00;(#,##0.00)' --Format
'en-US' --Culture
</code></pre>
<p>Will have many patterns, the given one is for example.</p>
<p>Expected output: <code>(4,059,587.23)</code></p>
<p>In SQL Server we have <code>format()</code> function, what's the equivalent in PostgreSQL?</p>
<p>My try:</p>
<pre><code>select to_char( -4059587.225000, '#,##0.00;(#,##0.00)' );
</code></pre>
<p>Error:</p>
<blockquote>
<p>multiple decimal points</p>
</blockquote>
|
[
{
"answer_id": 74476308,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "to_char"
},
{
"answer_id": 74476309,
"author": "Reto",
"author_id": 6019471,
"author_profile": "https://Stackoverflow.com/users/6019471",
"pm_score": 0,
"selected": false,
"text": "select \nconcat( to_char( -4059587.225000, '#,##0.00;' ), to_char( -4059587.225000, '(#,##0.00)' ) );\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4268241/"
] |
74,475,912
|
<p>I have this function</p>
<pre><code>A=[(1,2,3),(2,3,4)]
B=[(2,4,3),(1,8,1),(2,3,5),(1,5,3)]
def closestNew(A,B):
C = {}
for bp in B:
closestDist = -1
for ap in A:
dist = sum(((bp[0]-ap[0])**2, (bp[1]-ap[1])**2, (bp[2]-ap[2])**2))
if(closestDist > dist or closestDist == -1):
C[bp] = ap
closestDist = dist
return C
</code></pre>
<p>That will return the closest coordinate between the two lists.</p>
<p>Output:</p>
<pre><code>{(1, 2, 3): (2, 4, 3), (2, 3, 4): (2, 3, 5)}
</code></pre>
<p>However, I want the <strong>index</strong> of array <strong>B</strong> (the points that matched with array A (check output)) as well in a seperate list, any ideas?</p>
<p>Return</p>
<p><code>idx=[0,2]</code></p>
|
[
{
"answer_id": 74476308,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "to_char"
},
{
"answer_id": 74476309,
"author": "Reto",
"author_id": 6019471,
"author_profile": "https://Stackoverflow.com/users/6019471",
"pm_score": 0,
"selected": false,
"text": "select \nconcat( to_char( -4059587.225000, '#,##0.00;' ), to_char( -4059587.225000, '(#,##0.00)' ) );\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20514383/"
] |
74,475,947
|
<p>I've made a database with a table called item, im trying to insert some new items with the help of but it wont show on my html page in the browser.</p>
<p>The code looks like this and i have no clue what the most of it does, but it looks almost exactly like the code in the video im following.</p>
<pre><code>@page "/addingredient"
@using DataAccess
@using BlazorApp.Models
@inject IMySQLDataAccess _data
@inject IConfiguration _config
<PageTitle>Add Ingredient</PageTitle>
<h1>Add Ingredient</h1>
<EditForm Model="@newItem" OnInvalidSubmit="@InsertItem">
<label for="name">Ingredient Name</label>
<input type="text" id="name" @bind-value="addItem.Name">
<label for="exp">Expiration Date</label>
<input type="datetime" id="date" @bind-value="addItem.Expiration">
<label for="q">Quantity</label>
<input type="number" id="q" @bind-value="addItem.Quantity">
<label for="qt">Quantity Type</label>
<input type="text" id="qt" @bind-value="addItem.Qtype">
</EditForm>
@code {
private ItemModel newItem = new ItemModel();
public class AddItem
{
public string? Name { get; set; }
public DateTime Expiration { get; set; }
public int Quantity { get; set; }
public string? Qtype { get; set; }
}
private AddItem addItem = new AddItem();
private async Task InsertItem()
{
ItemModel a = new ItemModel
{
ItemName = new string(addItem.Name),
Expiration = new DateTime(addItem.Expiration.Year, addItem.Expiration.Month, addItem.Expiration.Day, addItem.Expiration.Hour, addItem.Expiration.Minute, addItem.Expiration.Second),
Quantity = new int(addItem.Quantity),
Qtype = new string(addItem.Qtype)
};
string sql = "INSERT INTO item (ItemName,Expiration,Quantity,Qtype) VALUES (@ItemName,Expiration,Quantity,Qtype);";
await _data.SaveData(sql, a, _config.GetConnectionString("MySQLConnection"));
await OnInitializedAsync();
a = new ItemModel();
addItem = new AddItem();
}
}
</code></pre>
<p>I also only get one error message: 'int' does not contain a constructor that takes 1 argument in line 47</p>
|
[
{
"answer_id": 74476308,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "to_char"
},
{
"answer_id": 74476309,
"author": "Reto",
"author_id": 6019471,
"author_profile": "https://Stackoverflow.com/users/6019471",
"pm_score": 0,
"selected": false,
"text": "select \nconcat( to_char( -4059587.225000, '#,##0.00;' ), to_char( -4059587.225000, '(#,##0.00)' ) );\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10781487/"
] |
74,475,991
|
<p>I am trying to run my django application using docker which involves celery. I am able to set everything on local and it works perfectly fine. However, when I run it docker, and my task gets executed, it throws me the following error:</p>
<p><code>myapp.models.mymodel.DoesNotExist: mymodel matching query does not exist.</code></p>
<p>I am particularly new to celery and docker so not sure what am I doing wrong.</p>
<p>Celery is set up correctly, I have made sure of that. Following are the broker_url and backend:</p>
<pre><code>CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = 'django-db'
</code></pre>
<p>This is my docker-compose.yml file:</p>
<pre><code>version: "3.8"
services:
redis:
image: redis:alpine
container_name: rz01
ports:
- "6379:6379"
networks:
- npm-nw
- braythonweb-network
braythonweb:
build: .
command: >
sh -c "python manage.py makemigrations &&
python manage.py migrate &&
gunicorn braython.wsgi:application -b 0.0.0.0:8000 --workers=1 --timeout 10000"
volumes:
- .:/code
ports:
- "8000:8000"
restart: unless-stopped
env_file: .env
networks:
- npm-nw
- braythonweb-network
celery:
build: .
restart: always
container_name: cl01
command: celery -A braython worker -l info
depends_on:
- redis
networks:
- npm-nw
- braythonweb-network
networks:
braythonweb-network:
npm-nw:
external: false
</code></pre>
<p>I have tried few things from different stackoverflow posts like apply_async. I have also made sure that my model existed.</p>
<p><strong>Update</strong> On further investigating the issue, I have noticed that the celery task does not get created in the database in the first place. Don't know why, may be I have to the following with something else:</p>
<p><code>CELERY_RESULT_BACKEND = 'django-db'</code></p>
|
[
{
"answer_id": 74476308,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "to_char"
},
{
"answer_id": 74476309,
"author": "Reto",
"author_id": 6019471,
"author_profile": "https://Stackoverflow.com/users/6019471",
"pm_score": 0,
"selected": false,
"text": "select \nconcat( to_char( -4059587.225000, '#,##0.00;' ), to_char( -4059587.225000, '(#,##0.00)' ) );\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74475991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19250175/"
] |
74,476,001
|
<p>I am trying to use <code>PageNumberPagination</code> and <code>FilterSet</code> in <code>APIView</code>.
But I have an error below in my code.</p>
<blockquote>
<p>object of type 'ListSerializer' has no len()</p>
</blockquote>
<p>How to implement this?</p>
<hr />
<p>Here are the code:</p>
<pre><code>class MySerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = '__all__'
class MyFilter(filters.FilterSet):
class Meta:
model = MyModel
fields = '__all__'
class MyAPIView(views.APIView, PageNumberPagination):
def get(self, request, *args, **kwargs):
filterset = MyFilter(request.query_params, queryset=MyModel.objects.all())
if not filterset.is_valid():
raise ValidationError(filterset.errors)
serializer = MySerializer(instance=filterset.qs, many=True)
paginate_queryset = self.paginate_queryset(serializer, request, view=self)
return Response(paginate_queryset.data)
</code></pre>
<hr />
<p>Django 3.2.6</p>
<p>django-filter 22.1</p>
<p>djangorestframework 3.12.4</p>
<p>Python 3.8</p>
|
[
{
"answer_id": 74476404,
"author": "Mahammadhusain kadiwala",
"author_id": 19205926,
"author_profile": "https://Stackoverflow.com/users/19205926",
"pm_score": 0,
"selected": false,
"text": "from rest_framework.pagination import PageNumberPagination\nclass EventNewsItems(APIView, PageNumberPagination):\n def get(self, request, pk, format=None):\n event = Event.objects.get(pk=pk)\n news = event.get_news_items().all()\n results = self.paginate_queryset(news, request, view=self)\n serializer = NewsItemSerializer(results, many=True)\n return self.get_paginated_response(serializer.data)\n"
},
{
"answer_id": 74476414,
"author": "ThomasGth",
"author_id": 6106166,
"author_profile": "https://Stackoverflow.com/users/6106166",
"pm_score": 1,
"selected": false,
"text": "class MyAPIView(ListAPIView):\n queryset = MyModel.objects.all()\n serializer_class = MySerializer\n filterset_class = MyFilter\n pagination_class = PageNumberPagination\n"
},
{
"answer_id": 74478364,
"author": "Tio",
"author_id": 12611330,
"author_profile": "https://Stackoverflow.com/users/12611330",
"pm_score": 0,
"selected": false,
"text": "class MyAPIView(views.APIView, PageNumberPagination):\n\n def get(self, request):\n filterset = MyFilter(request.query_params, queryset=MyModel.objects.all())\n\n results = self.paginate_queryset(filterset.qs, request, view=self)\n serializer = Serializer(results, many=True)\n\n return self.get_paginated_response(serializer.data)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476001",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12611330/"
] |
74,476,005
|
<p>can anyone teach me how to plot a csv</p>
|
[
{
"answer_id": 74476196,
"author": "Lokeshwar G",
"author_id": 12588118,
"author_profile": "https://Stackoverflow.com/users/12588118",
"pm_score": 1,
"selected": false,
"text": "import matplotlib.pyplot as plt\nimport csv\n\nx = []\ny = []\n\nwith open('data_file.csv','r') as csvfile:\n plots = csv.reader(csvfile, delimiter = ',')\n \n for row in plots:\n x.append(row[0])\n y.append(row[1])\n\nplt.bar(x, y, color = 'g', width = 0.72, label = \"recall\")\nplt.xlabel('precision')\nplt.ylabel('recall')\nplt.title('Title')\nplt.legend()\nplt.show()\n"
},
{
"answer_id": 74476334,
"author": "Thales",
"author_id": 20401787,
"author_profile": "https://Stackoverflow.com/users/20401787",
"pm_score": 1,
"selected": false,
"text": "import csv\nimport matplotlib.pyplot as plt\n\nf = open(\"data_file.csv\", \"w\")\nw = csv.writer(f)\n_ = w.writerow([\"precision\", \"recall\"])\nrows = [[0.013,0.951],[0.376,0.851],[0.441,0.839],[0.570,0.758],[0.635,0.674],[0.721,0.604],[0.837,0.531],[0.860,0.453],[0.962,0.348],[0.982,0.273],[1.0,0.0]]\nprecision = [row[0] for row in rows]\nrecall = [row[1] for row in rows]\nw.writerows(rows)\nf.close()\nplt.plot(precision, recall)\nplt.show()\n"
},
{
"answer_id": 74476400,
"author": "Surya Teja Chavali",
"author_id": 13562851,
"author_profile": "https://Stackoverflow.com/users/13562851",
"pm_score": 0,
"selected": false,
"text": "NameError"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,476,010
|
<p>I want to iterate through an array of words, look up the definition and delete the word if no definition is found.</p>
<p>my code looks as follows;</p>
<pre><code>var words = ["word1", "word2", "word3",]
function Meaning(words){
const getMeaning = async () => {
const response = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${words}`)
const myJson = await response.json()
for(i = 0; i < words.length; ++i) {
if(!response[i]){
myJson.splice(i,1)
console.log(myJson)
}
}}
</code></pre>
<p>This is not really doing anything atm. Where am I going wrong?</p>
<p>edit to add context</p>
<p>tried like this as well;</p>
<pre><code>for(i = 0; i < words.length; ++i)
fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${words[i]}`).then((response) => {
if (response === 404) {
let response = words
words[i].splice(i,1)
console.log(response)
}
throw new Error('Something went wrong');
})
.then((responseJson) => {
let response = words
response[i].splice(i,1)
})
.catch((error) => {
console.log(error)
});
</code></pre>
<p>I can print out the 404 error when it finds no definition, but I can't remove it from the words array</p>
|
[
{
"answer_id": 74476196,
"author": "Lokeshwar G",
"author_id": 12588118,
"author_profile": "https://Stackoverflow.com/users/12588118",
"pm_score": 1,
"selected": false,
"text": "import matplotlib.pyplot as plt\nimport csv\n\nx = []\ny = []\n\nwith open('data_file.csv','r') as csvfile:\n plots = csv.reader(csvfile, delimiter = ',')\n \n for row in plots:\n x.append(row[0])\n y.append(row[1])\n\nplt.bar(x, y, color = 'g', width = 0.72, label = \"recall\")\nplt.xlabel('precision')\nplt.ylabel('recall')\nplt.title('Title')\nplt.legend()\nplt.show()\n"
},
{
"answer_id": 74476334,
"author": "Thales",
"author_id": 20401787,
"author_profile": "https://Stackoverflow.com/users/20401787",
"pm_score": 1,
"selected": false,
"text": "import csv\nimport matplotlib.pyplot as plt\n\nf = open(\"data_file.csv\", \"w\")\nw = csv.writer(f)\n_ = w.writerow([\"precision\", \"recall\"])\nrows = [[0.013,0.951],[0.376,0.851],[0.441,0.839],[0.570,0.758],[0.635,0.674],[0.721,0.604],[0.837,0.531],[0.860,0.453],[0.962,0.348],[0.982,0.273],[1.0,0.0]]\nprecision = [row[0] for row in rows]\nrecall = [row[1] for row in rows]\nw.writerows(rows)\nf.close()\nplt.plot(precision, recall)\nplt.show()\n"
},
{
"answer_id": 74476400,
"author": "Surya Teja Chavali",
"author_id": 13562851,
"author_profile": "https://Stackoverflow.com/users/13562851",
"pm_score": 0,
"selected": false,
"text": "NameError"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4377207/"
] |
74,476,087
|
<p>I have found ExecuteDeleteAsync and ExecuteUpdateAsync in EF Core 7 with great enthusiasm. They help to make my code much simpler and faster. There is no need to use self-made procedures for batch delete or update of 1-2 fields.
Anyway I have situations when the exact table and field of database for update should be selected in run time.</p>
<p>I can use the database table:</p>
<pre><code>public static IQueryable<object> Set(this DbContext context, Type entity) =>
context.ClrQuery(context.ClrType(entity));
</code></pre>
<p>I have the method to make expression to filter rows:</p>
<pre><code>public static IQueryable Where(this IQueryable source, string equalProperty, object value, [NotNull] Type EntityType)
{
PropertyInfo? property = EntityType.GetProperty(equalProperty);
if (property == null)
throw new NotImplementedException($"Type {EntityType.Name} does not contain property {equalProperty}");
ParameterExpression parameter = Expression.Parameter(EntityType, "r");
MemberExpression member = Expression.MakeMemberAccess(parameter, property);
LambdaExpression whereExpression = Expression.Lambda(Expression.Equal(member, Expression.Constant(value, property.PropertyType)), parameter);
MethodCallExpression resultExpression = WhereCall(source, whereExpression);
return source.Provider.CreateQuery(resultExpression);
}
</code></pre>
<p>So I can find the rows to make update using</p>
<pre><code>IQueryable Source = db.Set(EntityType).Where(FieldName, FieldValue, EntityType);
</code></pre>
<p>I should make expression to update <code>IQueryable ExecuteUpdateQuery = Source.ExecuteUpdateAsync(EntityType, FieldName, FieldValue);</code></p>
<p>What is the way to access to expression for SetProperty?</p>
|
[
{
"answer_id": 74476196,
"author": "Lokeshwar G",
"author_id": 12588118,
"author_profile": "https://Stackoverflow.com/users/12588118",
"pm_score": 1,
"selected": false,
"text": "import matplotlib.pyplot as plt\nimport csv\n\nx = []\ny = []\n\nwith open('data_file.csv','r') as csvfile:\n plots = csv.reader(csvfile, delimiter = ',')\n \n for row in plots:\n x.append(row[0])\n y.append(row[1])\n\nplt.bar(x, y, color = 'g', width = 0.72, label = \"recall\")\nplt.xlabel('precision')\nplt.ylabel('recall')\nplt.title('Title')\nplt.legend()\nplt.show()\n"
},
{
"answer_id": 74476334,
"author": "Thales",
"author_id": 20401787,
"author_profile": "https://Stackoverflow.com/users/20401787",
"pm_score": 1,
"selected": false,
"text": "import csv\nimport matplotlib.pyplot as plt\n\nf = open(\"data_file.csv\", \"w\")\nw = csv.writer(f)\n_ = w.writerow([\"precision\", \"recall\"])\nrows = [[0.013,0.951],[0.376,0.851],[0.441,0.839],[0.570,0.758],[0.635,0.674],[0.721,0.604],[0.837,0.531],[0.860,0.453],[0.962,0.348],[0.982,0.273],[1.0,0.0]]\nprecision = [row[0] for row in rows]\nrecall = [row[1] for row in rows]\nw.writerows(rows)\nf.close()\nplt.plot(precision, recall)\nplt.show()\n"
},
{
"answer_id": 74476400,
"author": "Surya Teja Chavali",
"author_id": 13562851,
"author_profile": "https://Stackoverflow.com/users/13562851",
"pm_score": 0,
"selected": false,
"text": "NameError"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15863202/"
] |
74,476,129
|
<p>I have written a simple program to test "vector.erase" feature. There is a simple class (MyClass0) which writes some related message in it's constructor and another in it's destructor. And then there is a vector which contains 4 objects of type MyClass0. As I erase the second element of the vector:</p>
<pre class="lang-cpp prettyprint-override"><code> vec0.erase(vec0.begin() + 1);
</code></pre>
<p>I suppose that the Message "GoodBye From 2" should be outputted on the screen. But the message "GoodBye From 4" is shown. It seems that the destructor of the 4'th element of the vector is called. (Although it is not the case, because the 4'th element will be destructed at the end, when the "main" is finished).
can anyone help me please so that I can find out the reason. The code and the output which is shown on the screen are:</p>
<p>Code:</p>
<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
#include <vector>
using std::cout;
using std::endl;
class MyClass0
{
public:
MyClass0(int i_i_) : i_(i_i_)
{
cout << "Hello From " << this->i_ << endl;
}
~MyClass0()
{
cout << "GoodBye From " << this->i_ << endl;
}
std::string MyToString()
{
return std::string("This is ") + std::to_string(this->i_);
}
private:
int i_;
};
int main()
{
std::vector<MyClass0> vec0 = { MyClass0(1), MyClass0(2), MyClass0(3), MyClass0(4) };
cout << endl << "Before erasing..." << endl;
vec0.erase(vec0.begin() + 1);
cout << "After erase" << endl << endl;
return 0;
}
</code></pre>
<p>Output on the screen:</p>
<pre><code>Hello From 1
Hello From 2
Hello From 3
Hello From 4
GoodBye From 4
GoodBye From 3
GoodBye From 2
GoodBye From 1
Before erasing...
GoodBye From 4
After erase
GoodBye From 1
GoodBye From 3
GoodBye From 4
</code></pre>
<p><a href="https://godbolt.org/z/qvrcb81Ma" rel="noreferrer">https://godbolt.org/z/qvrcb81Ma</a></p>
|
[
{
"answer_id": 74476223,
"author": "NathanOliver",
"author_id": 4342498,
"author_profile": "https://Stackoverflow.com/users/4342498",
"pm_score": 3,
"selected": false,
"text": "//start with\n1 2 3 4\n\n// erase 2, so move 3 into 2 and 4 into 3\n1 3 4 *\n\n// * is old 4 and we don't need that so remove it from the collection\n1 3 4\n\n// removing * calls the destructor for that element\n"
},
{
"answer_id": 74476292,
"author": "Marek R",
"author_id": 1387438,
"author_profile": "https://Stackoverflow.com/users/1387438",
"pm_score": 3,
"selected": false,
"text": "class MyClass0\n{\npublic:\n MyClass0(int i_i_) : i_(i_i_)\n {\n cout << \"Hello From \" << this->i_ << endl;\n }\n ~MyClass0()\n {\n cout << \"GoodBye From \" << this->i_ << endl;\n }\n std::string MyToString()\n {\n return std::string(\"This is \") + std::to_string(this->i_);\n }\n MyClass0(const MyClass0& other) : i_{other.i_}\n {\n std::cout << \"Copy construct \" << i_ << '\\n';\n }\n\n MyClass0& operator=(const MyClass0& other)\n {\n std::cout << \"Asign \" << other.i_ << \" onto \" << i_ << '\\n';\n i_ = other.i_;\n return *this;\n }\nprivate:\n int i_;\n};\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530129/"
] |
74,476,141
|
<p>I need a SQL query for Oracle that select groups that contains the elements "ABC" and "ANQ"</p>
<pre><code>group X Column Q
-------- ---------
123 ABC
123 AAA
123 ANQ
456 ANQ
456 PKR
579 AAA
579 XYZ
886 ABC
</code></pre>
<p>The desired result should be</p>
<pre><code> group X Column Q
-------- ---------
123 ABC
123 AAA
123 ANQ
</code></pre>
|
[
{
"answer_id": 74476244,
"author": "MT0",
"author_id": 1509264,
"author_profile": "https://Stackoverflow.com/users/1509264",
"pm_score": 2,
"selected": false,
"text": "COUNT"
},
{
"answer_id": 74476249,
"author": "Littlefoot",
"author_id": 9097906,
"author_profile": "https://Stackoverflow.com/users/9097906",
"pm_score": 2,
"selected": true,
"text": "SQL> with test (x, q) as\n 2 (select 123, 'abc' from dual union all\n 3 select 123, 'aaa' from dual union all\n 4 select 123, 'anq' from dual union all\n 5 select 456, 'anq' from dual union all\n 6 select 456, 'pkr' from dual union all\n 7 select 579, 'aaa' from dual union all\n 8 select 579, 'xyz' from dual union all\n 9 select 886, 'abc' from dual\n 10 )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2319747/"
] |
74,476,146
|
<p>I want to sum across undefined amount of columns that start with the same string pattern. I would like for each column of my new data frame to have the column name of the string that was used in column name search. However, I am not sure, how to automatically assign column names that it would result in a given format, e.g.</p>
<pre><code>c(m = "m", w = "w")
</code></pre>
<p>I want to use lapply in combination with rowSums like here:</p>
<pre><code>lapply(c(m = "m", w = "w"),
\(x) rowSums(df[startsWith(names(df), x)]))
</code></pre>
<p>Basic input:</p>
<pre><code># m_16 w_16 w_17 m_17 w_18 m_18
#values1 3 4 8 1 12 4
#values2 8 0 12 1 3 2
</code></pre>
<p>Desired output:</p>
<pre><code># m_16 w_16 w_17 m_17 w_18 m_18 m w
#values1 3 4 8 1 12 4 8 24
#values2 8 0 12 1 3 2 11 15
</code></pre>
<p>However, as I have mentioned above, there could be more columns and they could start with <em>z, w, etc</em>, and sums also should be calculated, so I want to vectorize the "column name giving" and not to assign the column names by hand.</p>
<p>I have tried looking for it through other stackoverflow threads, but wasn't sure how to search for this problem and have no idea how to solve it myself, beside assigning column names afterwards.</p>
|
[
{
"answer_id": 74476711,
"author": "Martin Gal",
"author_id": 12505251,
"author_profile": "https://Stackoverflow.com/users/12505251",
"pm_score": 3,
"selected": true,
"text": "#"
},
{
"answer_id": 74477205,
"author": "pluke",
"author_id": 948397,
"author_profile": "https://Stackoverflow.com/users/948397",
"pm_score": 1,
"selected": false,
"text": "tidyverse"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10346592/"
] |
74,476,171
|
<p>this is my layer and i have assigned it to a button, but the zoom is not working when I click the layer button. i tried adding the zoom inside the layer but its not working.</p>
<pre class="lang-js prettyprint-override"><code>rainfall1 = new ol.layer.Vector({
//title: 'CA_DEVELOPMENT_PLAN',
// extent: [-180, -90, -180, 90],
visible:false,
source: new ol.source.Vector({
url:"./data/village.geojson",
zoom: 12,
format: new ol.format.GeoJSON()
}),
style:function(feature) {
labelStyle.getText().setText(feature.getProperties().CA_NAME);
return style1;
},
declutter: true,
});
document.getElementById("lyr").onclick = function() {
layer1.setVisible(!rainfall1.getVisible());
};
var bindLayerButtonToggle = function (lyr, layer) {
document.getElementById(lyr).onclick = function() {
layer.setVisible(!layer.getVisible());
};
}
bindLayerButtonToggle("lyr", rainfall1);
</code></pre>
|
[
{
"answer_id": 74476711,
"author": "Martin Gal",
"author_id": 12505251,
"author_profile": "https://Stackoverflow.com/users/12505251",
"pm_score": 3,
"selected": true,
"text": "#"
},
{
"answer_id": 74477205,
"author": "pluke",
"author_id": 948397,
"author_profile": "https://Stackoverflow.com/users/948397",
"pm_score": 1,
"selected": false,
"text": "tidyverse"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20390024/"
] |
74,476,182
|
<p>The application I use generates data in a dataframe which I need to use upon request.</p>
<p>It looks similar to this.</p>
<pre><code><class 'pandas.core.frame.DataFrame'>
E Gg gnx2 J chs lwave J_ID
0 27.572025 82.308581 7.078391 3.0 1 [0] 1
1 46.387728 77.029548 58.112338 3.0 1 [0] 1
2 75.007554 82.087407 0.535442 3.0 1 [0] 1
</code></pre>
<p>Everything worked perfectly while I didn't try to use dataframes saved in separate files before. Because when I am trying to use the data after loading - I got errors about data types for the columns which contain arrays.
(lvawe for example) is an array and when saved in csv the information about data type is lost.</p>
<pre><code>#saving the data to csv
csv_filename = "ladder.csv"
ladder.to_csv(csv_filename)
</code></pre>
<p>So when loading a dataframe next time to use the data I can't get access to array elements like it should.</p>
<p>Because as I understand data in this column is loaded like string.
After loading the data through load_csv I get this for the data types:</p>
<pre><code>Unnamed: 0 int64
E float64
Gg float64
gnx2 float64
J float64
chs int64
lwave object
J_ID int64
dtype: object
</code></pre>
<p>How can I resolve this issue? How can I correctly load the data with the correct data type or maybe explicitly assign a data type to a column after loading?</p>
|
[
{
"answer_id": 74476711,
"author": "Martin Gal",
"author_id": 12505251,
"author_profile": "https://Stackoverflow.com/users/12505251",
"pm_score": 3,
"selected": true,
"text": "#"
},
{
"answer_id": 74477205,
"author": "pluke",
"author_id": 948397,
"author_profile": "https://Stackoverflow.com/users/948397",
"pm_score": 1,
"selected": false,
"text": "tidyverse"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7267480/"
] |
74,476,206
|
<pre><code># Initialising list of dictionary
ini_dict = [{'a':5, 'b':10, 'c':90},
{'a':45, 'b':78},
{'a':90, 'c':10}]
# printing initial dictionary
print ("initial dictionary", (ini_dict))
# sum the values with same keys
result = {}
for d in ini_dict:
for k in d.keys():
result[k] = result.get(k,0) + d[k]
print("resultant dictionary : ", (result))
</code></pre>
<p>Can someone explain the program line by line</p>
|
[
{
"answer_id": 74476349,
"author": "Stjonal",
"author_id": 20530420,
"author_profile": "https://Stackoverflow.com/users/20530420",
"pm_score": 0,
"selected": false,
"text": "ini_dict = [{'a':5, 'b':10, 'c':90},\n {'a':45, 'b':78},\n {'a':90, 'c':10}]\n"
},
{
"answer_id": 74476362,
"author": "LiiVion",
"author_id": 19328707,
"author_profile": "https://Stackoverflow.com/users/19328707",
"pm_score": 2,
"selected": false,
"text": "ini_dict = [{'a':5, 'b':10, 'c':90},\n {'a':45, 'b':78},\n {'a':90, 'c':10}]\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530403/"
] |
74,476,259
|
<p>I have 3 python dictionaries as below:</p>
<pre><code>gender = {'Female': 241, 'Male': 240}
marital_status = {'Divorced': 245, 'Engaged': 243, 'Married': 244, 'Partnered': 246, 'Single': 242}
family_type = {'Extended': 234, 'Joint': 235, 'Nuclear': 233, 'Single Parent': 236}
</code></pre>
<p>I add them to a list:</p>
<pre><code>lst = [gender, marital_status, family_type]
</code></pre>
<p>And create a <code>JSON</code> object which I need to save as a <code>JSON</code> file using <code>pd.to_json</code> using:</p>
<pre><code>jf = json.dumps(lst, indent = 4)
</code></pre>
<p>When we look at <code>jf</code> object:</p>
<pre><code>print(jf)
[
{
"Female": 241,
"Male": 240
},
{
"Divorced": 245,
"Engaged": 243,
"Married": 244,
"Partnered": 246,
"Single": 242
},
{
"Extended": 234,
"Joint": 235,
"Nuclear": 233,
"Single Parent": 236
}
]
</code></pre>
<p>Is there a way to make the dictionary name as key and get output as below:</p>
<pre><code>{
"gender": {
"Female": 241,
"Male": 240
},
"marital_status": {
"Divorced": 245,
"Engaged": 243,
"Married": 244,
"Partnered": 246,
"Single": 242
},
"family_type": {
"Extended": 234,
"Joint": 235,
"Nuclear": 233,
"Single Parent": 236
}
}
</code></pre>
|
[
{
"answer_id": 74476337,
"author": "StonedTensor",
"author_id": 6023918,
"author_profile": "https://Stackoverflow.com/users/6023918",
"pm_score": 3,
"selected": true,
"text": "my_data = {'gender': gender, 'marital_status':marital_status, 'family_type': family_type}\n"
},
{
"answer_id": 74476345,
"author": "Farhan Mushtaq",
"author_id": 20396064,
"author_profile": "https://Stackoverflow.com/users/20396064",
"pm_score": 0,
"selected": false,
"text": "dict_req = {\"gender\":gender, \"marital_status\":marital_status, \"family_type\":family_type}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10722752/"
] |
74,476,364
|
<p>Taking a file with DHCP host definitions as input I need to transform entries like:</p>
<pre><code>host mx {
fixed-address 10.0.1.161;
</code></pre>
<p>into entries like this:</p>
<pre><code>host mx - fixed-address 10.0.1.161;
</code></pre>
<p>(obviously I need to output this to <code>stdout</code>, not replace those entries in place)</p>
<p><code>sed</code> doesn't work because it basically doesn't allow replacing newlines.</p>
|
[
{
"answer_id": 74476657,
"author": "William Pursell",
"author_id": 140750,
"author_profile": "https://Stackoverflow.com/users/140750",
"pm_score": 2,
"selected": false,
"text": "sed"
},
{
"answer_id": 74476761,
"author": "Gilles Quenot",
"author_id": 465183,
"author_profile": "https://Stackoverflow.com/users/465183",
"pm_score": 1,
"selected": true,
"text": "$ perl -pe 's/{\\n/-/' file\nhost mx - fixed-address 10.0.1.161;\n"
},
{
"answer_id": 74476964,
"author": "dawg",
"author_id": 298607,
"author_profile": "https://Stackoverflow.com/users/298607",
"pm_score": 0,
"selected": false,
"text": "printf 'host mx {\\n fixed-address 10.0.1.161;\\n' | awk -F \"[ \\t]*\\\\\\{\" '/^host mx/{\n getline l2\n sub(/^[ \\t]*/,\"\",l2)\n printf \"%s - %s\\n\", $1, l2\n}'\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2022518/"
] |
74,476,399
|
<p>First, I would like to say I have already spent the due time and diligence on my part by watching videos, using other sources, and reading other posts and answers on SOF before asking this and have been unable to find a solution.</p>
<p>The issue I am running into, in a particular case, is a certain type is being passed in, which would require the use of LIKE as the specific type itself will not match anything as three types use the one type, say 'painting' in this situation. The database has a 'painting small' and 'painting large.'</p>
<p>Code</p>
<pre><code>// I tried this
CASE WHEN type = 'painting' THEN inventory.type LIKE '%'+type+'%' ELSE inventory.type = type END
</code></pre>
<p>I keep running into the "An expression of a non-boolean type specified in a context where a condition is expected. There are a few other variations I have tried as well as IF ELSE, however, I run into the same issue. Someone else may be able to word this question better.</p>
<p>I mainly want to be pointed in the right direction and receive clarification on what I am doing wrong.</p>
<p>Thank you</p>
|
[
{
"answer_id": 74476488,
"author": "Winston",
"author_id": 12063888,
"author_profile": "https://Stackoverflow.com/users/12063888",
"pm_score": -1,
"selected": false,
"text": " LIKE '%'+type+'%' \n"
},
{
"answer_id": 74476795,
"author": "Larnu",
"author_id": 2029983,
"author_profile": "https://Stackoverflow.com/users/2029983",
"pm_score": 3,
"selected": true,
"text": "CASE"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14078880/"
] |
74,476,421
|
<p>I have a timeline and would like a box to be drawn next to a particular number of years</p>
<pre><code>digraph timeline {
node [fontsize=24, shape = plaintext];
1940 -> 1950;
1950 -> 1955;
1955 -> 1960;
node [fontsize=20, shape = box];
{ rank=same; 1940 test; }
}
</code></pre>
<p>This places a timeline on the left hand side going from 1940 to 1950 and so forth. I would like draw a box next to the numbers that starts at 1940 - which is what I do now with <code>{ rank=same; 1940 test; }</code> and that ends with 1955.</p>
<p>Here is an example of the box drawn at 1940</p>
<p><a href="https://i.stack.imgur.com/3AJ50.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3AJ50.png" alt="enter image description here" /></a></p>
<p>Here is an example of the box drawn at 1955 with code <code>{ rank=same; 1955 test; }</code></p>
<p><a href="https://i.stack.imgur.com/5JGPP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5JGPP.png" alt="enter image description here" /></a></p>
<p>I would like to have the box drawn from the start of 1940 position to the end of 1955 position, so encompassing these two boxes right now.</p>
|
[
{
"answer_id": 74530432,
"author": "kirogasa",
"author_id": 14928633,
"author_profile": "https://Stackoverflow.com/users/14928633",
"pm_score": 3,
"selected": true,
"text": "style=invis"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/254694/"
] |
74,476,437
|
<p>When creating a WPF window with <code>AllowsTransparency="True" WindowStyle="None"</code> and maximizing it via</p>
<pre><code>private void btnMaximize_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.MainWindow.WindowState != WindowState.Maximized)
Application.Current.MainWindow.WindowState = WindowState.Maximized;
else
Application.Current.MainWindow.WindowState = WindowState.Normal;
}
</code></pre>
<p>the Window gets bigger than my screen.</p>
<p>When I set <code>ResizeMode</code> to <code>ResizeMode="NoResize"</code> it works like a charm.
But I want to resize my window. Any suggestions how to fix my problem?</p>
|
[
{
"answer_id": 74476910,
"author": "Kavya Kommuri",
"author_id": 18726537,
"author_profile": "https://Stackoverflow.com/users/18726537",
"pm_score": 0,
"selected": false,
"text": "public MainWindow()\n{\n InitializeComponent();\n this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;\n}\n"
},
{
"answer_id": 74478757,
"author": "New Guy",
"author_id": 19433977,
"author_profile": "https://Stackoverflow.com/users/19433977",
"pm_score": -1,
"selected": false,
"text": "private void btnMaximize_Click(object sender, RoutedEventArgs e)\n {\n this.Height = SystemParameters.MaximizedPrimaryScreenHeight;\n }\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19928474/"
] |
74,476,440
|
<p>I have a a strange question to ask. I started working on a project and I need to integrate flyway to make it execute any new migrations on application start-up. The flyway dependency and config exists, pointing at a batch of migration scripts, but these were previously executed against the target 'by hand' without flyway having been used. The prod database full of user data. I can not tell you why it was organised like this.</p>
<p>What I want to do is to integrate flyway to make it check that migration folder and to add a command to the pipeline. And I have a concern that if I don't configure flyway properly will it execute all those migrations from the beginning on start-up? (this can corrupt existing data) Or it will it only execute newly added migrations?</p>
|
[
{
"answer_id": 74476910,
"author": "Kavya Kommuri",
"author_id": 18726537,
"author_profile": "https://Stackoverflow.com/users/18726537",
"pm_score": 0,
"selected": false,
"text": "public MainWindow()\n{\n InitializeComponent();\n this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;\n}\n"
},
{
"answer_id": 74478757,
"author": "New Guy",
"author_id": 19433977,
"author_profile": "https://Stackoverflow.com/users/19433977",
"pm_score": -1,
"selected": false,
"text": "private void btnMaximize_Click(object sender, RoutedEventArgs e)\n {\n this.Height = SystemParameters.MaximizedPrimaryScreenHeight;\n }\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8336836/"
] |
74,476,524
|
<p>I am having a docker application which is running a python flask rest api.
I would like the user to input (<code>getpass()</code>) the database password instead of having it in any open readable config file.
Since I am also using docker network to resolve the dns names I would like to use <code>docker compose up</code> instead of <code>docker compose run</code>. Because run always creates new containers which is intefering my name resolution.</p>
<p>This is the docker compose file (illustrating just the effected service):</p>
<pre><code>version: '3.4'
services:
rest-api:
image: rest_api:latest
container_name: rest_api
tty: true
stdin_open: true
ports:
- 5000:5000
networks:
- mynetwork
networks:
mynetwork:
name: any_network
</code></pre>
<p>When starting the service with <code>docker compose up</code> it is just waiting without getting the prompt and the terminal does not react to any input by the user.
<a href="https://i.stack.imgur.com/Dqlmc.png" rel="nofollow noreferrer">docker compose up CLI</a></p>
<p>With <code>docker compose run</code> the input field is working properly but name resoultion is not working anymore since a new container name is created.
<a href="https://i.stack.imgur.com/x914q.png" rel="nofollow noreferrer">docker compose run CLI with user prompt</a></p>
<p>What would you recommend to overcome this issue?</p>
<ul>
<li>Shall I define static IP addresses in the compose file for all my services?</li>
<li>Can I have an encrypted config file to store the password? But I actually dont want any hardcoded passwords to open the config.</li>
<li>I know that the <code>run</code> command brings somehow its own terminal settings.
Can I have <code>compose up</code> behave in the same way? What settings may I need to add to the compose file then?</li>
<li>Shall I simply remove the containers after stopping them and always start <code>compose run</code> with <code>--name</code> in it to ensure the container naming? But then I would need to start all my services separately instead of just using the <code>compose up</code> command to start all at once. As I remember the run command also needs the port expose parameter since it is not read from the compose file,right?</li>
</ul>
<p>Many thanks for any advice!</p>
|
[
{
"answer_id": 74476910,
"author": "Kavya Kommuri",
"author_id": 18726537,
"author_profile": "https://Stackoverflow.com/users/18726537",
"pm_score": 0,
"selected": false,
"text": "public MainWindow()\n{\n InitializeComponent();\n this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;\n}\n"
},
{
"answer_id": 74478757,
"author": "New Guy",
"author_id": 19433977,
"author_profile": "https://Stackoverflow.com/users/19433977",
"pm_score": -1,
"selected": false,
"text": "private void btnMaximize_Click(object sender, RoutedEventArgs e)\n {\n this.Height = SystemParameters.MaximizedPrimaryScreenHeight;\n }\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15487103/"
] |
74,476,556
|
<p>I want to convert a string to a hash table, whose keys are the characters in the string, and values are are the list of index of this character in the string. Is there some elegant way to do this?</p>
<p>For example:</p>
<pre><code>String: "abcaad"
Hash table: { a: [0 3 4] , b: [1] , c: [2] , d: [5] }
</code></pre>
<p>I tried to write one with <code>hash-set!</code> and iterate the string from the end to avoid <code>append</code> which is slower than insert at begin. But I hope there will be some more elegant way (better if I can get a vector instead of a list for each hash value):</p>
<pre><code>(define (s->hash s)
(define h (make-hash))
(for ([c (in-string s (sub1 (string-length s)) -1 -1)]
[i (in-range (sub1 (string-length s)) -1 -1)])
(hash-set! h c (cons i (hash-ref h c empty))))
h)
</code></pre>
|
[
{
"answer_id": 74476910,
"author": "Kavya Kommuri",
"author_id": 18726537,
"author_profile": "https://Stackoverflow.com/users/18726537",
"pm_score": 0,
"selected": false,
"text": "public MainWindow()\n{\n InitializeComponent();\n this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;\n}\n"
},
{
"answer_id": 74478757,
"author": "New Guy",
"author_id": 19433977,
"author_profile": "https://Stackoverflow.com/users/19433977",
"pm_score": -1,
"selected": false,
"text": "private void btnMaximize_Click(object sender, RoutedEventArgs e)\n {\n this.Height = SystemParameters.MaximizedPrimaryScreenHeight;\n }\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13150528/"
] |
74,476,573
|
<p>I'm quite stuck with this problem in Python and I'm pretty sure it should be pretty easy to solve.</p>
<p>Please find this dict example:</p>
<pre><code>d = {
"a": "abc1",
"b": "abc1",
"c": "abc2",
"d": "abc3",
"e": "abc3",
"f": "abc3",
"g": "abc4"
}
</code></pre>
<p>Now I want a to create a list where 'a' till 'g' will be put in an order that is mixing up abc values as much as possible, but I require all keys in the list so:</p>
<pre><code>['a','c','d','g','b','e']
</code></pre>
<p>Then 'f' will be left over (because e also has value abc3) and can be added to a leftover list.</p>
<p>I tried the following:</p>
<pre><code>s = []
for x in d:
if len(s) < 1:
s.append(x)
if d[s[-1]] is not d[x]:
s.append(x)
</code></pre>
<p>But this will produce just:</p>
<pre><code>['a', 'c', 'd', 'g']
</code></pre>
<p>I need to go back and try again until no solutions are possible.</p>
<p>Thanks a lot for your time and suggestions!</p>
|
[
{
"answer_id": 74476854,
"author": "Nineteendo",
"author_id": 13454049,
"author_profile": "https://Stackoverflow.com/users/13454049",
"pm_score": 1,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\nlist_number = {}\nkey_lists = []\n\nfor key, value in d.items():\n if value in list_number:\n index = list_number[value] = list_number[value] + 1\n else:\n index = list_number[value] = 0\n if index < len(key_lists):\n key_lists[index].append(key)\n else:\n key_lists.append([key])\nresult = []\nremaining = []\nfor key_list in key_lists:\n if not result or len(key_list) > 1:\n result.extend(key_list)\n else:\n remaining.extend(key_list)\nprint(\"# Result\", result)\nprint(\"# Remaining:\", remaining)\n# Result ['a', 'c', 'd', 'g', 'b', 'e']\n# Remaining: ['f']\n"
},
{
"answer_id": 74477875,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 0,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\ncounted = {}\ndone = False\nwhile not done:\n # Assume done\n done = True\n last_value = None\n for key, value in d.items():\n if key not in counted and value != last_value:\n done = False\n last_value = value\n # Add the key to the result dict, the value 1 is arbitrary\n counted[key] = 1\n\nresult = list(counted)\nprint(f\"Result: {result}\")\n"
},
{
"answer_id": 74489948,
"author": "Sam Mason",
"author_id": 1358308,
"author_profile": "https://Stackoverflow.com/users/1358308",
"pm_score": 0,
"selected": false,
"text": "d"
},
{
"answer_id": 74509992,
"author": "keithpjolley",
"author_id": 2624770,
"author_profile": "https://Stackoverflow.com/users/2624770",
"pm_score": 0,
"selected": false,
"text": "from collections import defaultdict\nfrom itertools import zip_longest, chain\n\nd = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\n# Create and populate default dict of \"value\": [key1, key2, ...]\nvk = defaultdict(list)\n[vk[v].append(k) for k,v in d.items()]\n\n# Zip the values together column by column and remove any columns\n# with only one key because this means it's repeating.\nll = [c for c in [[b for b in a if b is not None]\n for a in zip_longest(*vk.values())]\n if len(c) > 1]\n\n# Flatten the list of lists into list of keys.\nkeys = list(chain(*ll))\n\nprint(keys)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530428/"
] |
74,476,574
|
<p>I would like to change so <code>True = False</code> or more exact change so <code>True = 0</code> and <code>False = 1</code> is there a way to do this?</p>
<p>I have a <code>dataframe</code> and would like to <code>df.groupby('country',as_index=False).sum()</code> and see how many <code>False</code> values there is in each country</p>
<p>I have tried <code>df['allowed'] = --df['allowed']</code> (allowed is the column with <code>True</code> and <code>False</code> values) to swap them but it didn't work</p>
|
[
{
"answer_id": 74476854,
"author": "Nineteendo",
"author_id": 13454049,
"author_profile": "https://Stackoverflow.com/users/13454049",
"pm_score": 1,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\nlist_number = {}\nkey_lists = []\n\nfor key, value in d.items():\n if value in list_number:\n index = list_number[value] = list_number[value] + 1\n else:\n index = list_number[value] = 0\n if index < len(key_lists):\n key_lists[index].append(key)\n else:\n key_lists.append([key])\nresult = []\nremaining = []\nfor key_list in key_lists:\n if not result or len(key_list) > 1:\n result.extend(key_list)\n else:\n remaining.extend(key_list)\nprint(\"# Result\", result)\nprint(\"# Remaining:\", remaining)\n# Result ['a', 'c', 'd', 'g', 'b', 'e']\n# Remaining: ['f']\n"
},
{
"answer_id": 74477875,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 0,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\ncounted = {}\ndone = False\nwhile not done:\n # Assume done\n done = True\n last_value = None\n for key, value in d.items():\n if key not in counted and value != last_value:\n done = False\n last_value = value\n # Add the key to the result dict, the value 1 is arbitrary\n counted[key] = 1\n\nresult = list(counted)\nprint(f\"Result: {result}\")\n"
},
{
"answer_id": 74489948,
"author": "Sam Mason",
"author_id": 1358308,
"author_profile": "https://Stackoverflow.com/users/1358308",
"pm_score": 0,
"selected": false,
"text": "d"
},
{
"answer_id": 74509992,
"author": "keithpjolley",
"author_id": 2624770,
"author_profile": "https://Stackoverflow.com/users/2624770",
"pm_score": 0,
"selected": false,
"text": "from collections import defaultdict\nfrom itertools import zip_longest, chain\n\nd = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\n# Create and populate default dict of \"value\": [key1, key2, ...]\nvk = defaultdict(list)\n[vk[v].append(k) for k,v in d.items()]\n\n# Zip the values together column by column and remove any columns\n# with only one key because this means it's repeating.\nll = [c for c in [[b for b in a if b is not None]\n for a in zip_longest(*vk.values())]\n if len(c) > 1]\n\n# Flatten the list of lists into list of keys.\nkeys = list(chain(*ll))\n\nprint(keys)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20470841/"
] |
74,476,585
|
<p>I want to use custom company colors in my shiny app. Below is a mock version of my app which shows the issue I face. The issue is I cannot set the background color (#f2f0eb) properly, as you see there is a white bar above the chart which does not get the background color #f2f0eb. The navigation bar, selection box and bottom white bar are fine. <a href="https://i.stack.imgur.com/AmlVT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AmlVT.png" alt="enter image description here" /></a></p>
<p><strong>So to be clear I want to get rid off the white bar above the chart, it should have the same brownish color (#f2f0eb) as the rest off the background main panel color.</strong></p>
<p>I have checked out this thread, but couldn't get it to solve my issue; <a href="https://stackoverflow.com/questions/57292235/r-shinydashboard-add-a-customized-color-for-status-parameter">StackOverflow thread add customized color for status paramater</a>
<a href="https://i.stack.imgur.com/dx2h6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dx2h6.png" alt="css code of white box" /></a></p>
<p>I am not very proficient with CSS so please incorporate any answers into the R code posted below</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>#test
## Packages ----
library(shiny);library(shinydashboard);library(shinydashboardPlus);
library(plyr);library(dplyr);library(dbplyr);library(tidyr);
library(ggplot2);library(scales);library(stringr);library(plotly)
library(ggiraph)
## Header ----
header <- dashboardHeader(title = span("Test app StackOverFlow", style = "font-size: 18px"))
## Sidebar ----
sidebar <- dashboardSidebar(
disable = FALSE,
width = 230,
sidebarMenu(
tags$br(),
textOutput("text1"),
tags$br(),
sidebarMenu(id="menu1",
menuItem("Test", tabName = "PERF", icon = icon("arrow-right", verify_fa = FALSE),
menuSubItem('blabla',tabName = 'kpi_1'),
menuSubItem('blablabla',tabName = 'kpi_2'))
)
)
)
# Body----
body <- dashboardBody(
# Set color ----
tags$head(tags$style(HTML('
body {
background-color: #f2f0eb;
}
.box {
border-top: 0px;
box-header with-border:0px;
}
/* logo */
.skin-blue .main-header .logo {
background-color: #109FC6;
}
/* logo when hovered */
.skin-blue .main-header .logo:hover {
background-color: #ce5368;
}
/* navbar (rest of the header) */
.skin-blue .main-header .navbar {
background-color: #f2f0eb;
}
/* main sidebar */
.skin-blue .main-sidebar {
background-color: #109FC6;
}
/* active selected tab in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu .active a{
background-color: #ce5368;
}
/* other links in the sidebarmenu */
.skin-blue .main-sidebar .sidebar .sidebar-menu a{
background-color: #109FC6;
color: #000000;
}
/* other links in the sidebarmenu when hovered */
.skin-blue .main-sidebar .sidebar .sidebar-menu a:hover{
background-color: #ce5368;
}
/* toggle button when hovered */
.skin-blue .main-header .navbar .sidebar-toggle:hover{
background-color: #ce5368;}
/* body */
.content-wrapper, .right-side {
background-color: #f2f0eb;
}
.tabs-above > .nav > li[class=active] > a {
background-color: #ce5368;
color: #ce5368;}
.tabbable > .nav > li > a {background-color: #ce5368; color:black}
'))),
# Selection buttons on top----
fluidRow(tags$head(tags$style(HTML('.box{-webkit-box-shadow: none; -moz-box-shadow: none;box-shadow: none;}'))), # remove grey line around chart
column(selectInput("selectclient", "Select choice:", choices = list("A" = "A1","B" = "B2","C" = "C2","D" = "D2"),
selected = "A"), width = 2)
),
tabItems(
# KPI1
tabItem(tabName = 'kpi_1',
tabPanel('Performance', box(
style = "background-color:#f2f0eb box-header with-border:0px;",
shinycssloaders::withSpinner(plotlyOutput("chart_kpi1")), width = 12)),
)
)
)
## ui----
ui <- dashboardPage(header, sidebar, body,
footer = dashboardFooter(
left = "Developed and maintained by",
right = "For questions email:"
))
# Define server logic required to draw a histogram
server <- function(input, output) {
output$chart_kpi1 = renderPlotly({
x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)
plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines') %>%
layout(paper_bgcolor = "#f2f0eb",
plot_bgcolor = "#f2f0eb",
fig_bgcolor = "#f2f0eb")
})
}
# Run the application
shinyApp(ui = ui, server = server)</code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 74476854,
"author": "Nineteendo",
"author_id": 13454049,
"author_profile": "https://Stackoverflow.com/users/13454049",
"pm_score": 1,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\nlist_number = {}\nkey_lists = []\n\nfor key, value in d.items():\n if value in list_number:\n index = list_number[value] = list_number[value] + 1\n else:\n index = list_number[value] = 0\n if index < len(key_lists):\n key_lists[index].append(key)\n else:\n key_lists.append([key])\nresult = []\nremaining = []\nfor key_list in key_lists:\n if not result or len(key_list) > 1:\n result.extend(key_list)\n else:\n remaining.extend(key_list)\nprint(\"# Result\", result)\nprint(\"# Remaining:\", remaining)\n# Result ['a', 'c', 'd', 'g', 'b', 'e']\n# Remaining: ['f']\n"
},
{
"answer_id": 74477875,
"author": "Hai Vu",
"author_id": 459745,
"author_profile": "https://Stackoverflow.com/users/459745",
"pm_score": 0,
"selected": false,
"text": "d = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\ncounted = {}\ndone = False\nwhile not done:\n # Assume done\n done = True\n last_value = None\n for key, value in d.items():\n if key not in counted and value != last_value:\n done = False\n last_value = value\n # Add the key to the result dict, the value 1 is arbitrary\n counted[key] = 1\n\nresult = list(counted)\nprint(f\"Result: {result}\")\n"
},
{
"answer_id": 74489948,
"author": "Sam Mason",
"author_id": 1358308,
"author_profile": "https://Stackoverflow.com/users/1358308",
"pm_score": 0,
"selected": false,
"text": "d"
},
{
"answer_id": 74509992,
"author": "keithpjolley",
"author_id": 2624770,
"author_profile": "https://Stackoverflow.com/users/2624770",
"pm_score": 0,
"selected": false,
"text": "from collections import defaultdict\nfrom itertools import zip_longest, chain\n\nd = {\n \"a\": \"abc1\",\n \"b\": \"abc1\",\n \"c\": \"abc2\",\n \"d\": \"abc3\",\n \"e\": \"abc3\",\n \"f\": \"abc3\",\n \"g\": \"abc4\"\n}\n\n# Create and populate default dict of \"value\": [key1, key2, ...]\nvk = defaultdict(list)\n[vk[v].append(k) for k,v in d.items()]\n\n# Zip the values together column by column and remove any columns\n# with only one key because this means it's repeating.\nll = [c for c in [[b for b in a if b is not None]\n for a in zip_longest(*vk.values())]\n if len(c) > 1]\n\n# Flatten the list of lists into list of keys.\nkeys = list(chain(*ll))\n\nprint(keys)\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8449782/"
] |
74,476,588
|
<p>I have 3 arguments in a move function those are list,source and destination.
List is here :</p>
<pre><code>const list = [
{
id: '1',
name: 'Folder 1',
files: [
{ id: '2', name: 'File 1' },
{ id: '3', name: 'File 2' },
{ id: '4', name: 'File 3' },
{ id: '5', name: 'File 4' },
],
},
{
id: '6',
name: 'Folder 2',
files: [{ id: '7', name: 'File 5' }],
},
];
</code></pre>
<p>in a given function I should enter the source and destination and I could move for example <code>move(list, '4', '6')</code> then I expect file with id <code>4</code> moved to the folder which has id <code>6</code>.</p>
<p>Like that :</p>
<pre><code>const result = [
{
id: '1',
name: 'Folder 1',
files: [
{ id: '2', name: 'File 1' },
{ id: '3', name: 'File 2' },
{ id: '5', name: 'File 4' },
],
},
{
id: '6',
name: 'Folder 2',
files: [
{ id: '7', name: 'File 5' },
{ id: '4', name: 'File 3' },
],
},
];
</code></pre>
<p>I moved it <code>Received: {"files": [{"id": "7", "name": "File 5"}, {"id": "4", "name": "File 3"}], "id": "6", "name": "Folder 2"}</code> but I couldn't delete the value that id is 4.</p>
<p>Here is my code</p>
<pre><code>let copyList =list.slice();
const filteredVal = copyList[0].files.find((file: { id: Object; })=> {
return file.id == source
} );// 2-3-4-5
// if (copyList[0].files.id === source){
// delete copyList[0].files.source
// } -> Doesn't work.
copyList[1].files.push(filteredVal);
return copyList[1]
</code></pre>
<p>I am using typescript also I'm testing it with jest I don't wait for the direct answers just I need steps to go or any need to write from scratch with another technique.</p>
|
[
{
"answer_id": 74476694,
"author": "Mina",
"author_id": 11887902,
"author_profile": "https://Stackoverflow.com/users/11887902",
"pm_score": -1,
"selected": true,
"text": "splice"
},
{
"answer_id": 74476787,
"author": "mplungjan",
"author_id": 295783,
"author_profile": "https://Stackoverflow.com/users/295783",
"pm_score": 0,
"selected": false,
"text": "id"
},
{
"answer_id": 74476992,
"author": "Pompedup",
"author_id": 12239272,
"author_profile": "https://Stackoverflow.com/users/12239272",
"pm_score": 1,
"selected": false,
"text": "function move(list, fileId, folderId) {\n // This does not copy the objects inside list, prefer something like JSON.parse(JSON.stringify(list)) to do a deep copy\n const copyList = list.slice();\n // Get the files from the folder where is located your fileId\n const { files: originFiles } = copyList.find(({ files }) => files.some(({ id }) => id === fileId))\n // Get the index of the file to move\n const fileToMoveIndex = originFiles.findIndex(({ id }) => id === fileId)\n // Find the destination folder with the folderId\n const destinationFolder = copyList.find(({ id }) => id === folderId)\n // Add the file in the destination folder\n destinationFolder.files.push(originFiles[fileToMoveIndex])\n // Remove the file from it origin folder\n originFiles.splice(fileToMoveIndex, 1)\n return destinationFolder\n}\nmove(list, '4', '6');\nconsole.log(list);"
},
{
"answer_id": 74477369,
"author": "3limin4t0r",
"author_id": 3982562,
"author_profile": "https://Stackoverflow.com/users/3982562",
"pm_score": 0,
"selected": false,
"text": "sourceFileID"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14818449/"
] |
74,476,591
|
<p>People I need make a funtion where return true or false. My code has a mistake
I don´t know how to do it.</p>
<pre><code>public bool Existe()
{
if (cbocarpeta.Text == "FORMULARIO N1 - DDJJ")
{
var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text
result = exist != null ? true : false;
}
}
</code></pre>
<p>I want that to make it do 'Return'</p>
<p>Error CS0161 'Form1.Exists()': not all code pathnames return a value</p>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19495598/"
] |
74,476,605
|
<p>Using Beautiful Soup, I'd like to detect porn keywords (that i get by concatening two lists of porn-keywords (one in french, the other in english) in a web page.</p>
<p>Here's my code (from <a href="https://stackoverflow.com/questions/49779905/beautifulsoup-find-two-different-strings">BeautifulSoup find two different strings</a>):</p>
<pre><code>proxy_support = urllib.request.ProxyHandler(my_proxies)
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
lst_porn_keyword_eng = str(urllib.request.urlopen("http://www.cs.cmu.edu/~biglou/resources/bad-words.txt").read()).split('\\n')
# the textfile starts with a LF, deleting it.
if lst_porn_keyword_eng[0] == "b\"":
del lst_porn_keyword_eng[0]
lst_porn_keyword_fr = str(urllib.request.urlopen("https://raw.githubusercontent.com/darwiin/french-badwords-list/master/list.txt").read()).split('\\n')
lst_porn_keyword = lst_porn_keyword_eng + lst_porn_keyword_fr
lst_porn_keyword_found = []
with urllib.request.urlopen("http://www.example.com") as page_to_check:
soup = BeautifulSoup(page_to_check, "html5lib")
for node in soup.find_all(text=lambda text: any(x in text for x in lst_porn_keyword)):
lst_porn_keyword_found.append(str(node.text))
return lst_porn_keyword_found
</code></pre>
<p>This code runs correctly but porn keyword are found even if they shouldn't be.
For instance, the text of the second node found in "http://www.example.com" is
<em>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</em>
And none of these words are in lst_porn_keyword</p>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11894831/"
] |
74,476,623
|
<p>I have a table that is meant to act as a configurable base class. In that class I want to be able to pass a menu with actions for each row:</p>
<pre><code> <table mat-table [dataSource]="tableDataSource" matSort (matSortChange)="sortTable($event)" class="mat-elevation-z8">
...
<!-- action column -->
<ng-container *ngIf="rowActionIcon?.length" [matColumnDef]="rowActionIcon">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell class="action-column" *matCellDef="let element" [id]="rowActionIcon" (click)="emitRowAction(element)">
<button mat-button [matMenuTriggerFor]="menu">
<mat-icon>{{rowActionIcon}}</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item *ngFor="let action of menuActions"><mat-icon>{{action.icon}}</mat-icon>{{action.label}}</button>
</mat-menu>
</td>
</ng-container>
</mat-table>
</code></pre>
<p>The action columns shows a button with a dropdown of menu items:</p>
<p><a href="https://i.stack.imgur.com/P8j4e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P8j4e.png" alt="enter image description here" /></a></p>
<p>How can I in my child component that uses this component get these clicks, along with the data for the row? Ideally I'd like to display that data in a dialog somehow.</p>
<p>The child component defines the menuActions that should exist on the parent table:</p>
<pre><code>export class CustomersComponent {
customers: Customer[];
selectedCustomer: Customer | null;
menuActions: MenuItemDefinition[];
customerColumns: { name: string; dataKey: string; isSortable: boolean }[];
constructor(private cust_api: CustomerApiService, public dialog: MatDialog) {
this.customers = [];
this.selectedCustomer = null;
this.menuActions = [
{ icon: 'border_color', label: 'Edit' },
{ icon: 'delete', label: 'Delete' },
];
this.customerColumns = [
{
name: 'Region',
dataKey: 'region',
isSortable: true,
},
{ name: 'Name', dataKey: 'name', isSortable: true },
{ name: 'Id', dataKey: 'id', isSortable: true },
];
}
</code></pre>
<p>and in the template:</p>
<pre><code> <app-data-table
[isFilterable]="true"
[isPageable]="true"
[tableColumns]="customerColumns"
[tableData]="customers"
[rowActionIcon]="'more_vert'"
[menuActions]="this.menuActions"
>
</app-data-table>
</code></pre>
<p>But I'm completely clueless as to how I should dynamically map data and actions to each of the buttons I create in the parent template.</p>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1230911/"
] |
74,476,626
|
<p>When trying to define helper functions to build up associative lists, I get an error, I cannot resolve myself (BASH 4.4):</p>
<blockquote>
<p>/tmp/foo.sh: line 18: 'key': syntax error: operand expected (error token is "'key'")</p>
</blockquote>
<p>For BASH 4.3 I got:</p>
<blockquote>
<p>/tmp/foo.sh: line 18: key: unbound variable</p>
</blockquote>
<p>Here is the test case:</p>
<pre class="lang-bash prettyprint-override"><code>#!/bin/bash
set -u
# add services list
add_list()
{
local list="$1"
eval "declare -a ${list}=(); declare -A ${list}_A=()"
}
# add services to list of services
add_service()
{
local list="$1" def="$2"
local s="${def%%:*}"
eval "${list}+=('$def'); ${list}_A['$s']='$def'"
}
add_list TEST
add_service TEST 'key:value'
</code></pre>
<p>The reason for the two array is that I want to access elements by key, and I want to preserve the original ordering (actually <code>${list}+=('$s')</code> would be sufficient for that).</p>
<p>Here is the output of <code>bash -x</code>:</p>
<pre class="lang-bash prettyprint-override"><code>> bash -x /tmp/foo.sh
+ set -u
+ add_list TEST
+ local list=TEST
+ eval 'declare -a TEST=(); declare -A TEST_A=()'
++ TEST=()
++ declare -a TEST
++ TEST_A=()
++ declare -A TEST_A
+ add_service TEST key:value
+ local list=TEST def=key:value
+ local s=key
+ eval 'TEST+=('\''key:value'\''); TEST_A['\''key'\'']='\''key:value'\'''
++ TEST+=('key:value')
++ TEST_A['key']=key:value
/tmp/foo.sh: line 18: 'key': syntax error: operand expected (error token is "'key'")
</code></pre>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6607497/"
] |
74,476,640
|
<p>I want to find the relational Formula between X and Z this below :</p>
<pre><code>X Z
8949430070120254001 24307547
8949430070120254019 64939975
8949430070120254027 62651206
8949430070120254035 42288628
8949430070120254043 09065578
</code></pre>
<p>the point is how to find the formula for the number that is Z from the number X</p>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530642/"
] |
74,476,652
|
<p>I have two separate data frames named df1 and df2 as shown below:</p>
<pre><code> Scaffold Position Ref_Allele_Count Alt_Allele_Count Coverage_Depth Alt_Allele_Frequency
0 1 11 7 51 58 0.879310
1 1 16 20 95 115 0.826087
2 2 9 9 33 42 0.785714
3 2 12 86 51 137 0.372263
4 2 67 41 98 139 0.705036
5 3 8 0 0 0 0.000000
6 4 99 32 26 58 0.448276
7 4 101 100 24 124 0.193548
8 4 115 69 26 95 0.273684
9 5 6 40 57 97 0.587629
10 5 19 53 87 140 0.621429
Scaffold Position Ref_Allele_Count Alt_Allele_Count Coverage_Depth Alt_Allele_Frequency
0 1 11 7 64 71 0.901408
1 1 16 10 90 100 0.900000
2 2 9 79 86 165 0.521212
3 2 12 12 73 85 0.858824
4 2 67 54 96 150 0.640000
5 3 8 0 0 0 0.000000
6 4 99 86 28 114 0.245614
7 4 101 32 25 57 0.438596
8 4 115 97 16 113 0.141593
9 5 6 86 43 129 0.333333
10 5 19 59 27 86 0.313953
</code></pre>
<p>I have already found the sum values for df1 and df2 in Allele_Count and Coverage Depth but I need to divide the resulting Alt_Allele_Count and Coverage_Depth of both df's with one another to fine the total allele frequency(AF). I have tried dividing the two variable and got the error message :
TypeError: float() argument must be a string or a number, not 'DataFrame'
when I tried to convert them to floats and this table when I laft it as a df:</p>
<pre><code> Alt_Allele_Count Coverage_Depth
0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 NaN NaN
5 NaN NaN
6 NaN NaN
7 NaN NaN
8 NaN NaN
9 NaN NaN
10 NaN NaN
</code></pre>
<p>My code so far:</p>
<pre><code>import csv
import pandas as pd
import numpy as np
df1 = pd.read_csv('C:/Users/Tom/Python_CW/file_pairA_1.csv')
df2 = pd.read_csv('C:/Users/Tom/Python_CW/file_pairA_2.csv')
print(df1)
print(df2)
Ref_Allele_Count = (df1[['Ref_Allele_Count']] + df2[['Ref_Allele_Count']])
print(Ref_Allele_Count)
Alt_Allele_Count = (df1[['Alt_Allele_Count']] + df2[['Alt_Allele_Count']])
print(Alt_Allele_Count)
Coverage_Depth = (df1[['Coverage_Depth']] + df2[['Coverage_Depth']]).astype(float)
print(Coverage_Depth)
AF = Alt_Allele_Count / Coverage_Depth
print(AF)
</code></pre>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20513017/"
] |
74,476,659
|
<p>I have a pdf stored in Cloud Storage and I'm trying to take this file to send it through email.</p>
<p>I'm trying to recover it but I receive back an error about access deniend:</p>
<blockquote>
<p>Uncaught (in promise): FirebaseError: Firebase Storage: User does not
have permission to access</p>
</blockquote>
<p>My code:</p>
<pre><code> const storageRef = firebase.storage().ref();
var forestRef = storageRef.child('/uploads/' + offerId + '/' + offerId + '.pdf');
forestRef.getDownloadURL()
.then(function (url) {
console.log("url ", url)
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function (event) {
var blob = xhr.response;
};
xhr.open('GET', url);
})
</code></pre>
<p>I think that the problem should be that I'm not using the access token but I don't know how to recover it. ( I have tried to use also the getMetadata, but the result is the same)</p>
<p>Edit:</p>
<p>I have also the url with token</p>
|
[
{
"answer_id": 74476865,
"author": "DonMiguelSanchez",
"author_id": 13337616,
"author_profile": "https://Stackoverflow.com/users/13337616",
"pm_score": 1,
"selected": false,
"text": " public bool Existe()\n{\n if (cbocarpeta.Text == \"FORMULARIO N1 - DDJJ\")\n {\n var exist = db.Ficha_Escribanos.SingleOrDefault(f => f.ApeyNom == txtapeynom.Text && f.Nro_Afiliado == txtafiliado.Text);\n\n return exist != null;\n }\n // you need to return something if the if cbocarpeta.Text != \"FORMULARIO N1 - DDJJ\"\n return false;\n\n}\n"
},
{
"answer_id": 74477018,
"author": "Zohar Peled",
"author_id": 3094533,
"author_profile": "https://Stackoverflow.com/users/3094533",
"pm_score": 3,
"selected": true,
"text": "Any"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11604252/"
] |
74,476,665
|
<p>The statement after return (Where I am sending props to ProList , in the mapping section) is showing unreachable. I am still learning react. Can anyone help me in this regard?</p>
<pre><code>import "./Workcard.css"
import React from 'react'
import ProList from "./ProList"
import projcarddata from "./ProlistData"
const Workcard = () => {
return (
<div className="work-container">
<h1 className="project-heading">Projects</h1>
<div className="project-container">
{
projcarddata.map((val,ind) =>
{
return
(
<ProList key={ind} imgsrc={val.imgsrc} title={val.title} text={val.text} view={val.view} source={val.source}/>
);
}
)
}
</div>
</div>
);
};
export default Workcard
</code></pre>
<p>`</p>
|
[
{
"answer_id": 74476705,
"author": "KcH",
"author_id": 11737596,
"author_profile": "https://Stackoverflow.com/users/11737596",
"pm_score": 0,
"selected": false,
"text": "return;"
},
{
"answer_id": 74476797,
"author": "SKR Sama",
"author_id": 17621694,
"author_profile": "https://Stackoverflow.com/users/17621694",
"pm_score": 2,
"selected": true,
"text": "Workcard = () => {\n return (\n <div className=\"work-container\">\n <h1 className=\"project-heading\">Projects</h1>\n <div className=\"project-container\">\n {projcarddata.map((val, ind) => {\n return <ProList key={ind} imgsrc={val.imgsrc} title={val.title} text={val.text} view={val.view} source={val.source} />;\n })}\n </div>\n </div>\n );\n };\n```\n\n\n\n\nWay 2: remove the return statement and directly add the return value after the arrow\n\n\n\n\n```\nWorkcard = () => {\n return (\n <div className=\"work-container\">\n <h1 className=\"project-heading\">Projects</h1>\n <div className=\"project-container\">\n {projcarddata.map((val, ind) => (\n <ProList key={ind} imgsrc={val.imgsrc} title={val.title} text={val.text} view={val.view} source={val.source} />\n ))}\n </div>\n </div>\n );\n };\n```\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15620055/"
] |
74,476,733
|
<p>I am trying to execute the same SQL but with different values for the where clause. One query is taking significantly longer time to process than the other. I have also observed that the execution plan for the two queries is different too,</p>
<p>Query1 and Execution Plan:</p>
<pre><code>explain analyze
select t."postal_code"
from dev."postal_master" t
left join dev."premise_master" f
on t."primary_code" = f."primary_code"
and t."name" = f."name"
and t."final_code" = f."final_code"
where 1 = 1 and t."region" = 'US'
and t."name" = 'UBQ'
and t."accountModCode" = 'LTI'
and t."modularity_code" = 'PHA'
group by t."postal_code", t."modularity_code", t."region",
t."feature", t."granularity"
Group (cost=4.19..4.19 rows=1 width=38) (actual time=76411.456..76414.348 rows=11871 loops=1)
Group Key: t."postal_code", t."modularity_code", t."region", t."feature", t.granularity
-> Sort (cost=4.19..4.19 rows=1 width=38) (actual time=76411.452..76412.045 rows=11879 loops=1)
Sort Key: t."postal_code", t."feature", t.granularity
Sort Method: quicksort Memory: 2055kB
-> Nested Loop Left Join (cost=0.17..4.19 rows=1 width=38) (actual time=45.373..76362.219 rows=11879 loops=1)
Join Filter: (((t."name")::text = (f."name")::text) AND ((t."primary_code")::text = (f."primary_code")::text) AND ((t."final_code")::text = (f."final_code")::text))
Rows Removed by Join Filter: 150642887
-> Index Scan using idx_postal_code_source on postal_master t (cost=0.09..2.09 rows=1 width=72) (actual time=36.652..154.339 rows=11871 loops=1)
Index Cond: (("name")::text = 'UBQ'::text)
Filter: ((("region")::text = 'US'::text) AND (("accountModCode")::text = 'LTI'::text) AND (("modularity_code")::text = 'PHA'::text))
Rows Removed by Filter: 550164
-> Index Scan using idx_postal_master_source on premise_master f (cost=0.08..2.09 rows=1 width=35) (actual time=0.016..3.720 rows=12690 loops=11871)
Index Cond: (("name")::text = 'UBQ'::text)
Planning Time: 1.196 ms
Execution Time: 76415.004 ms
</code></pre>
<p>Query2 and Execution plan:</p>
<pre><code>explain analyze
select t."postal_code"
from dev."postal_master" t
left join dev."premise_master" f
on t."primary_code" = f."primary_code"
and t."name" = f."name"
and t."final_code" = f."final_code"
where 1 = 1 and t."region" = 'DE'
and t."name" = 'EME'
and t."accountModCode" = 'QEW'
and t."modularity_code" = 'NFX'
group by t."postal_code", t."modularity_code", t."region",
t."feature", t."granularity"
Group (cost=50302.96..50426.04 rows=1330 width=38) (actual time=170.687..184.772 rows=8230 loops=1)
Group Key: t."postal_code", t."modularity_code", t."region", t."feature", t.granularity
-> Gather Merge (cost=50302.96..50423.27 rows=1108 width=38) (actual time=170.684..182.965 rows=8230 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Group (cost=49302.95..49304.62 rows=554 width=38) (actual time=164.446..165.613 rows=2743 loops=3)
Group Key: t."postal_code", t."modularity_code", t."region", t."feature", t.granularity
-> Sort (cost=49302.95..49303.23 rows=554 width=38) (actual time=164.444..164.645 rows=3432 loops=3)
Sort Key: t."postal_code", t."feature", t.granularity
Sort Method: quicksort Memory: 550kB
Worker 0: Sort Method: quicksort Memory: 318kB
Worker 1: Sort Method: quicksort Memory: 322kB
-> Nested Loop Left Join (cost=1036.17..49297.90 rows=554 width=38) (actual time=2.143..148.372 rows=3432 loops=3)
-> Parallel Bitmap Heap Scan on territory_postal_mapping t (cost=1018.37..38323.78 rows=554 width=72) (actual time=1.898..11.849 rows=2743 loops=3)
Recheck Cond: ((("accountModCode")::text = 'QEW'::text) AND (("region")::text = 'DE'::text) AND (("name")::text = 'EME'::text))
Filter: (("modularity_code")::text = 'NFX'::text)
Rows Removed by Filter: 5914
Heap Blocks: exact=2346
-> Bitmap Index Scan on territorypostal__source_region_mod (cost=0.00..1018.31 rows=48088 width=0) (actual time=4.783..4.783 rows=25973 loops=1)
Index Cond: ((("accountModCode")::text = 'QEW'::text) AND (("region")::text = 'DE'::text) AND (("name")::text = 'EME'::text))
-> Bitmap Heap Scan on premise_master f (cost=17.80..19.81 rows=1 width=35) (actual time=0.047..0.048 rows=1 loops=8230)
Recheck Cond: (((t."primary_code")::text = ("primary_code")::text) AND ((t."final_code")::text = ("final_code")::text))
Filter: ((("name")::text = 'EME'::text) AND ((t."name")::text = ("name")::text))
Heap Blocks: exact=1955
-> BitmapAnd (cost=17.80..17.80 rows=1 width=0) (actual time=0.046..0.046 rows=0 loops=8230)
-> Bitmap Index Scan on premise_master__accountprimarypostal (cost=0.00..1.95 rows=105 width=0) (actual time=0.008..0.008 rows=24 loops=8230)
Index Cond: ((t."primary_code")::text = ("primary_code")::text)
-> Bitmap Index Scan on premise_master__accountfinalterritorycode (cost=0.00..15.80 rows=1403 width=0) (actual time=0.065..0.065 rows=559 loops=4568)
Index Cond: ((t."final_code")::text = ("final_code")::text)
Planning Time: 1.198 ms
Execution Time: 185.197 ms
</code></pre>
<p>I am aware that there will be different number of rows depending on the where condition but is that the only reason for the different execution plan. Also, how can I improve the performance of the first query.</p>
|
[
{
"answer_id": 74477276,
"author": "histocrat",
"author_id": 1747583,
"author_profile": "https://Stackoverflow.com/users/1747583",
"pm_score": 1,
"selected": false,
"text": "EXPLAIN ANALYZE"
},
{
"answer_id": 74477419,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "ANALYZE premise_master, postal_master;\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12971556/"
] |
74,476,748
|
<p>I have a loop which uses <a href="https://automapper.org/" rel="nofollow noreferrer">AutoMapper</a> to map two different instances of objects <code>A</code> & <code>B</code> into a new instance of a third object, <code>C</code>. The object <code>C</code> contains all the fields of <code>A</code> & <code>B</code> combined.</p>
<p>In other words, they could look like this:</p>
<pre><code>class A
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
class B
{
public DateTime TimeOfBirth { get; set; }
}
// A & B combined
class C
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime TimeOfBirth { get; set; }
}
</code></pre>
<p>Currently I have a loop which uses AutoMapper to first map <code>A</code> into <code>C</code>. And then map <code>B</code> into the result. Like this:</p>
<pre><code>List<C> output = new();
foreach (var a in listA)
{
C result = _mapper.Map<C>(a);
_mapper.Map<B, C>(listB.Single(b => b.Id == a.ForeinKey), result);
output.Add(result);
}
</code></pre>
<p>I would like to do this with Linq. My initial thought was to use the <a href="https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.zip?view=net-7.0" rel="nofollow noreferrer">Zip method</a>, but I cannot get it to work with AutoMapper. I would expect that it should look something like the below, but I cannot get it to work (it doesn't compile):</p>
<pre><code>var output = _mapper.Map<C>(listA).Zip(_mapper.Map<C>(listB));
</code></pre>
<p>What am I missing? Is it even possible to do what I am trying - without making an even bigger mess?</p>
|
[
{
"answer_id": 74477276,
"author": "histocrat",
"author_id": 1747583,
"author_profile": "https://Stackoverflow.com/users/1747583",
"pm_score": 1,
"selected": false,
"text": "EXPLAIN ANALYZE"
},
{
"answer_id": 74477419,
"author": "Laurenz Albe",
"author_id": 6464308,
"author_profile": "https://Stackoverflow.com/users/6464308",
"pm_score": 3,
"selected": true,
"text": "ANALYZE premise_master, postal_master;\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2445415/"
] |
74,476,766
|
<p>I want to create a phone-like stopwatch using HTML, CSS, and vanilla JavaScript. The one I have already done does the task, but I don't want a separate button for stopping and starting. How could I make a button that changes from start to stop and stop to start?</p>
<p>Here is my HTML Code:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<h1>Stopwatch</h1>
<h2>Vanilla JavaScript Stopwatch</h2>
<p><span id="seconds">00</span>:<span id="tens">00</span></p>
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
</div>
</body>
</html>
</code></pre>
<p>Here is my JavaScript code:</p>
<pre><code>window.onload = function () {
var seconds = 00;
var tens = 00;
var appendTens = document.getElementById("tens")
var appendSeconds = document.getElementById("seconds")
var buttonStart = document.getElementById('button-start');
var buttonStop = document.getElementById('button-stop');
var buttonReset = document.getElementById('button-reset');
var Interval ;
buttonStart.onclick = function() {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
}
buttonStop.onclick = function() {
clearInterval(Interval);
}
buttonReset.onclick = function() {
clearInterval(Interval);
tens = "00";
seconds = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
}
function startTimer () {
tens++;
if(tens <= 9){
appendTens.innerHTML = "0" + tens;
}
if (tens > 9){
appendTens.innerHTML = tens;
}
if (tens > 99) {
console.log("seconds");
seconds++;
appendSeconds.innerHTML = "0" + seconds;
tens = 0;
appendTens.innerHTML = "0" + 0;
}
if (seconds > 9){
appendSeconds.innerHTML = seconds;
}
}
}
</code></pre>
|
[
{
"answer_id": 74476914,
"author": "becauseimbored",
"author_id": 20524149,
"author_profile": "https://Stackoverflow.com/users/20524149",
"pm_score": 2,
"selected": false,
"text": "var clockStarted = false;\n\nbuttonStart.onclick = function() {\n clearInterval(Interval);\n if (!clockStarted) {\n Interval = setInterval(startTimer, 10);\n clockStarted = true;\n } else {\n clockStarted = false;\n }\n}\n\n\nbuttonReset.onclick = function() {\n clearInterval(Interval);\n tens = \"00\";\n seconds = \"00\";\n appendTens.innerHTML = tens;\n appendSeconds.innerHTML = seconds;\n clockStarted = false;\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530641/"
] |
74,476,770
|
<p>currently working on a following function:</p>
<pre><code>public function boldText($searchSuggestions)
{
$search = $this->getRequestParameter('search');
$pattern = "/".$search."/u";
$searchSuggestions = preg_replace($pattern, '<b>'.$search.'</b>', $searchSuggestions);
echo $searchSuggestions;
}
</code></pre>
<p>Let's say $searchSuggestions = hello
While the user is typing in the search box, which in this case the variable $search contains this input, a dropdown menu of all possible result suggestions are displayed. If a user types 'hello', then the search results like 'helloworld' or 'hello2' would pop up and the inputted word, int this case 'hello' would be bold in all outputted search results. So far it is working fine, however, big Characters are being replaced with small Characters and vice versa in the outputted search results. I have a feeling that the underlying problem might be in this function, however I am not entirely sure. If anyone has any suggestions or tips on where to look, it would be great!</p>
<p>If I should give out more info please do let me know, and I will edit the question immediately.</p>
<p>Thankyou!</p>
<p>Example output currently -
User types in search bar - 'hello'
result shown should be - '<b>Hello</b>'
result actually being shown - '<b>hello</b>'</p>
<p>P.S The results are accessed from an sql query. If a user types, than a query that gets data related to the words inputted is shown. For instance - 'SELECT * FROM test WHERE example LIKE '%hello%'
In database one can find the word Hello. Note the H has a big character.</p>
<p>I tried this following code</p>
<pre><code>public function boldText($searchSuggestions)
{
$search = $this->getRequestParameter('search');
$pattern = "/".$search."/u";
$searchSuggestions = preg_replace($pattern, '<b>'.$search.'</b>', $searchSuggestions);
echo $searchSuggestions;
}
</code></pre>
<p>Brief Explanation
$searchSuggestions</p>
<pre><code>Hello
</code></pre>
<p>$search(being typed by the user)</p>
<pre><code>h
</code></pre>
<p>The output should be</p>
<pre><code><b>H</b>ello
</code></pre>
<p>The output I am currently getting is</p>
<pre><code><b>h</b>ello
</code></pre>
|
[
{
"answer_id": 74476914,
"author": "becauseimbored",
"author_id": 20524149,
"author_profile": "https://Stackoverflow.com/users/20524149",
"pm_score": 2,
"selected": false,
"text": "var clockStarted = false;\n\nbuttonStart.onclick = function() {\n clearInterval(Interval);\n if (!clockStarted) {\n Interval = setInterval(startTimer, 10);\n clockStarted = true;\n } else {\n clockStarted = false;\n }\n}\n\n\nbuttonReset.onclick = function() {\n clearInterval(Interval);\n tens = \"00\";\n seconds = \"00\";\n appendTens.innerHTML = tens;\n appendSeconds.innerHTML = seconds;\n clockStarted = false;\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530691/"
] |
74,476,772
|
<p>Can you please help me with the following. I am trying to catch two exceptions: 1) <code>TypeError</code> and 2)<code>NameError</code>. I use the following code below that estimates the average:</p>
<pre><code>def calculate_average(number_list):
try:
if type(number_list) is not list:
raise ValueError("You should pass list to this function")
except ValueError as err:
print(err)
return
try:
average = sum(number_list)/len(number_list)
except TypeError:
print('List should contain numbers')
return
except NameError:
print('List should contain numbers')
return
return average
</code></pre>
<p>The code works fine for:</p>
<pre><code>print(calculate_average([1, 2, 3]))
print(calculate_average([1, 2, 'a']))
</code></pre>
<p>But when I use:</p>
<pre><code>print(calculate_average([1, 2, a]))
</code></pre>
<p>I have the following error that was supposed to be captured by <code>except</code>:</p>
<pre><code>NameError: name 'a' is not defined
</code></pre>
<p>Can you please help me with understanding the issue? (I use Spyder)</p>
|
[
{
"answer_id": 74476914,
"author": "becauseimbored",
"author_id": 20524149,
"author_profile": "https://Stackoverflow.com/users/20524149",
"pm_score": 2,
"selected": false,
"text": "var clockStarted = false;\n\nbuttonStart.onclick = function() {\n clearInterval(Interval);\n if (!clockStarted) {\n Interval = setInterval(startTimer, 10);\n clockStarted = true;\n } else {\n clockStarted = false;\n }\n}\n\n\nbuttonReset.onclick = function() {\n clearInterval(Interval);\n tens = \"00\";\n seconds = \"00\";\n appendTens.innerHTML = tens;\n appendSeconds.innerHTML = seconds;\n clockStarted = false;\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8260088/"
] |
74,476,781
|
<p>I am new to spring boot.
I have a class Comment which has a oneToMany relationship to the class User.
Now I want to create a Comment with a post request. But how can I pass only the userId of the user who writes the comment? So I can save this Object to the database.</p>
<p>I hope somebody could help me with this. I would appreciate it.</p>
<p>Post Request:</p>
<pre><code>{
"message": "This is a message",
"writer_id": 1
}
</code></pre>
<h2>User</h2>
<pre><code>@Entity
@Table(name="tbl_users")
public class User {
@Id
@GeneratedValue(
strategy = GenerationType.AUTO,
generator = "user_sequence"
)
@SequenceGenerator(
name = "user_sequence",
allocationSize = 1,
sequenceName = "user_sequence"
)
private Long id;
private String name;
public User(String name) {
this.name = name;
}
public User(Long id, String name) {
this.id = id;
this.name = name;
}
public User() {
}
getter, setter ...
</code></pre>
<h2>Comment</h2>
<pre><code>@Entity
@Table(name="tbl_comments")
public class Comment {
@Id
@GeneratedValue(
strategy = GenerationType.AUTO,
generator = "comment_sequence"
)
@SequenceGenerator(
name = "comment_sequence",
allocationSize = 1,
sequenceName = "comment_sequence"
)
private Long id;
private String message;
@ManyToOne
@JoinColumn(name="user_id", nullable=false)
private User writer;
public Comment(String message, User writer) {
this.message = message;
this.writer = writer;
}
public Comment(Long id, String message, User writer) {
this.id = id;
this.message = message;
this.writer = writer;
}
public Comment() {
}
getter, setter...
</code></pre>
<h2>CommentController</h2>
<pre><code>@PostMapping
public void createComment(@RequestBody Comment comment) {
commentService.createComment(comment);
}
</code></pre>
<h2>CommentService</h2>
<pre><code>public void createComment(Comment comment) {
if(!userRepository.existsById(comment.getWriter().getId())) {
throw new UserNotFoundException("Writer does not exist");
}
commentRepository.save(comment);
}
</code></pre>
|
[
{
"answer_id": 74477354,
"author": "Manir Mahamat",
"author_id": 11185081,
"author_profile": "https://Stackoverflow.com/users/11185081",
"pm_score": 3,
"selected": true,
"text": "public class User {\n /**\n other attributes\n **/\n\n //relation with comment\n @OneToMany(cascade = CascadeType.ALL,\n fetch = FetchType.LAZY, orphanRemoval = true,\n mappedBy = \"user\")\n private Set<Comment> comments;\n}\n"
},
{
"answer_id": 74477360,
"author": "Verduttio",
"author_id": 19045480,
"author_profile": "https://Stackoverflow.com/users/19045480",
"pm_score": 0,
"selected": false,
"text": "public class CommentRequest {\n private String message;\n private int userId;\n\n getters, setters\n\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16909865/"
] |
74,476,784
|
<p>Using get-adgroupmember to find the immediate members of a group is well-known. Likewise, adding the -recursive parameter is a well-known way to find all users that are members of a group. Is there a way to find all <em>groups</em> that are members of a group?</p>
<p>Background: One of my customers have had a nasty habit of using nested groups for access management. The worst case sees six levels of nested groups, each level having a significant number of groups as members.</p>
|
[
{
"answer_id": 74478184,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": false,
"text": "Get-ADGroupMember"
},
{
"answer_id": 74492644,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "Stack<T>"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1252439/"
] |
74,476,789
|
<p>I have these two lists:</p>
<pre class="lang-cs prettyprint-override"><code>List<image> ImagesByPerimeterId
List<PerimeterTile> ImagesWithMorePerimeters
</code></pre>
<p>The context is the following:
I want to remove images that contain the id found in the <code>ImagesWithMorePerimeters</code> list from the <code>ImagesByPerimeterId</code> list. The <code>ImagesWithMorePerimeters</code> list has an <code>imageId</code> attribute to compare with the first one.</p>
<p>I have implemented this logic, and it works very well:</p>
<pre class="lang-cs prettyprint-override"><code>foreach(var i in ImagesByPerimeterId)
{
foreach(var j in ImagesWithMorePerimeters)
{
if (i.Id == j.ImageId)
{
ImagesByPerimeterId.Remove(i);
}
}
}
</code></pre>
<p>but I'm looking for a simpler way to compare these lists. Any suggestions?</p>
<p>I tried to use <code>list.Except()</code>, but as the lists are different objects, that did not make it</p>
|
[
{
"answer_id": 74478184,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": false,
"text": "Get-ADGroupMember"
},
{
"answer_id": 74492644,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "Stack<T>"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19943087/"
] |
74,476,804
|
<p>I am doing a course on SQL on MYSQL workbench. In the course I had an exercise in which I had to take an IN parameter value and save as an OUT parameter value for further use.</p>
<p>I came up with this query:-</p>
<pre><code>DROP PROCEDURE IF EXISTS avg_employee_sal_out;
DELIMITER $$
CREATE PROCEDURE avg_employee_sal_out( IN p_emp_no INT, OUT p_avg_sal DECIMAL(10, 2))
BEGIN
SELECT
AVG(s.salary) INTO p_avg_sal
FROM
employees e
JOIN
salaries s
ON e.emp_no = s.emp_no
WHERE
e.emp_no = p_emp_no;
END $$
DELIMITER ;
</code></pre>
<p>Which was the correct answer but when I run the code, the OUT parameter value 'p_avg_sal' was asking for an input.</p>
<p>[Screenshot of when I run the procedure from user interface]
<a href="https://i.stack.imgur.com/yLvfE.png" rel="nofollow noreferrer">1</a></p>
<p>If I run the stored procedure in the interface it was fine if I left the out value blank but when I call the procedure I is showing an error.</p>
<p>[Screenshot when I run the above procedure by command]
<a href="https://i.stack.imgur.com/nKp1h.png" rel="nofollow noreferrer">2</a></p>
<blockquote>
<p>Leaving the OUT parameter null didn't work, it shows another error</p>
</blockquote>
<p>[here is the error screenshot]
<a href="https://i.stack.imgur.com/5mUtp.png" rel="nofollow noreferrer">3</a></p>
<blockquote>
<p>In the course when the lecturer ran the same query by user interface it didn't ask for the input for OUT value.</p>
</blockquote>
<p>(Sorry, can't provide screenshot cause the lecture is a video and its screenshot is completely black but it the same as [1] if you remove the lower input slot.)</p>
|
[
{
"answer_id": 74478184,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": false,
"text": "Get-ADGroupMember"
},
{
"answer_id": 74492644,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "Stack<T>"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530643/"
] |
74,476,810
|
<p>Can someone please point me to the CSS precedence rules regarding "concatenated classes" vs "separated classes"?</p>
<p>Also, what are the correct terms for "concatenated classes" vs "separated classes" (I suspect that's why I can't find the documentation I'm looking for.)</p>
<p>For example, in the CSS below, <code>.row .second</code> (with a space) appears to take precedence over <code>.row.second</code> (no space), even though they both match 2 class attributes.</p>
<pre><code>.row {
width: 150px;
background-color: lightgray;
margin: 15px;
}
section {
margin-left: 15px;
}
.row .second {
color: purple;
}
.row.second {
color: orange;
}
</code></pre>
<p>When applied to the HTML below, the CSS above produces this result:
<a href="https://i.stack.imgur.com/acKxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/acKxF.png" alt="Result from example" /></a></p>
<p>Why is "Stuff 2b" in purple instead of orange? (In other words, why does <code>.row .second</code> take precedence over <code>.row.second</code> in this case?)</p>
<pre><code><div id='outerBox'>
<div class="row">
<div class="title">
Row 1 Title
</div>
<section>
Stuff 1a
</section>
<section class='second'>
Stuff 1b
</section>
<section>
Stuff 1c
</section>
</div>
<div class="row second">
<div class="title">
Row 2 Title
</div>
<section>
Stuff 2a
</section>
<section class='second'>
Stuff 2b
</section>
<section>
Stuff 2c
</section>
</div>
<div class="row">
<div class="title">
Row 3 Title
</div>
<section>
Stuff 3a
</section>
<section class='second'>
Stuff 3b
</section>
<section>
Stuff 3c
</section>
</div>
</div>
</code></pre>
<p>(I'm applying the CSS above to the HTML below in JSFiddle in Chrome on MacOS.)</p>
|
[
{
"answer_id": 74478184,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": false,
"text": "Get-ADGroupMember"
},
{
"answer_id": 74492644,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "Stack<T>"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/920599/"
] |
74,476,812
|
<p>I am a beginner on Symfony 6 and I am blocked because I have an error message: "Undefined method getDoctrine" with Intelephense</p>
<p>Here is my code:</p>
<pre><code> #[Route('/recettes', name: 'app_recettes')]
public function index(int $id): Response
{
$em = $this->getDoctrine()->getManager();
$recette = $em->getRepository(Recettes::class)->findBy(['id' => $id]);
return $this->render('recettes/index.html.twig', [
'RecettesController' => 'RecettesController',
]);
}
</code></pre>
|
[
{
"answer_id": 74477068,
"author": "Dylan KAS",
"author_id": 11350193,
"author_profile": "https://Stackoverflow.com/users/11350193",
"pm_score": 2,
"selected": true,
"text": "AbstractController"
},
{
"answer_id": 74478308,
"author": "fatoon",
"author_id": 13127919,
"author_profile": "https://Stackoverflow.com/users/13127919",
"pm_score": 0,
"selected": false,
"text": "#[Route('/recettes/{id}', name: 'app_recettes')]\npublic function index(Recette $recette): Response\n{\n return $this->render('recettes/index.html.twig', [\n 'recette' => $recette,\n ]);\n\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476812",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20530690/"
] |
74,476,830
|
<p>I have an SQL data table called sales that records product, quantity sold, unit price, and the date of the sale. I would like to create a view with monthly sales for chairs from 2000-2010. That is, for every unique month and year pair I would like to sum up quantity * unit_price where the product = "CHAIR". My attempt is the following:</p>
<pre><code>CREATE VIEW MONTHLY_SALES(product, monthly_sales, month, year) AS (
SELECT product, SUM(quantity * unit_price) AS monthly_sales,
TO_CHAR(sale_date, 'Month') AS month, EXTRACT(YEAR FROM sale_date) AS year
FROM sales
WHERE sale_date BETWEEN '2000-01-01' AND '2010-12-31' AND product = 'CHAIR'
GROUP BY quantity, unit_price, article, sale_date);
SELECT *
FROM MONTHLY_SALES;
</code></pre>
<p>I would expect to sum over the same month and year and get something like:</p>
<pre><code>product | monthly_sales | month | year
Chair 100 January 2001
Chair 110 February 2001
Chair 120 March 2001
Chair 300 April 2001
</code></pre>
<p>But I'm seeing different monthly_sales for the same month-year pairs so I don't know why the SUM isn't working. Any assistance to fix this would be much appreciated.</p>
<p>===============================================================</p>
<p>Sample Data:</p>
<pre><code>product | quantity | unit_price | sales_date
Chair 1 40 2001-01-01
Chair 3 40 2001-01-02
Chair 4 40 2001-02-01
Chair 1 40 2001-02-05
</code></pre>
<p>Expected Output:</p>
<pre><code>product | monthly_sales | month | year
Chair 160 January 2001
Chair 200 February 2001
</code></pre>
|
[
{
"answer_id": 74477068,
"author": "Dylan KAS",
"author_id": 11350193,
"author_profile": "https://Stackoverflow.com/users/11350193",
"pm_score": 2,
"selected": true,
"text": "AbstractController"
},
{
"answer_id": 74478308,
"author": "fatoon",
"author_id": 13127919,
"author_profile": "https://Stackoverflow.com/users/13127919",
"pm_score": 0,
"selected": false,
"text": "#[Route('/recettes/{id}', name: 'app_recettes')]\npublic function index(Recette $recette): Response\n{\n return $this->render('recettes/index.html.twig', [\n 'recette' => $recette,\n ]);\n\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13630719/"
] |
74,476,834
|
<p>I have a fs2 Stream <code>Stream[F, C</code>] where <code>C <: Coproduct</code>. And I want to transform it into a <code>Stream[F, H]</code> where <code>H <: HList</code>. This HList should contain all members that the coproduct <code>C</code> had.</p>
<p>So, essentially, a <code>Pipe[F, C, H]</code> .</p>
<p>The fs2 Pipe will work by waiting for at least one of each of the coproduct's members to be pulled, and then once at least one of each are pulled, finally combine it into a HList and output it.</p>
<p>So, it will be used pretty much like so:</p>
<pre class="lang-scala prettyprint-override"><code>type MyCoprod = A :+: B :+: C :+: CNil
type MyHList = A :: B :: C :: HNil
val stream: Stream[F, MyHList] = Stream
.emits(List(A, B, C)) // my coproducts
.through(pullAll) // i want to wait for A, B, C to pulled at least once and outputted
.map { hlist => ... }
</code></pre>
<p>I am very very new to Shapeless, and this is what I could think of before hitting a roadblock:</p>
<pre class="lang-scala prettyprint-override"><code>trait WaitFor[F[_], C <: Coproduct] {
type Out <: HList
def apply: Pipe[F, C, Out]
}
object WaitFor {
type Aux[F[_], C <: Coproduct, Out0 <: HList] =
WaitFor[F, C] { type Out = Out0 }
implicit def make[F[_], C <: Coproduct, L <: HList](implicit
toHList: ToHList.Aux[C, L]
): Aux[F, C, L] = new WaitFor.Aux[F, C, L] {
override type Out = L
override def apply: Pipe[F, C, Out] = {
def go(s2: Stream[F, C], currHList: L): Pull[F, L, Unit] = {
s2.pull.uncons1.flatMap {
case Some((coproduct, s3)) => {
// add or update coproduct member to currHList
// if currHList is the same as L (our output type) then output it (Pull.output1(currHList)) and clear currHList
// if not, keep iterating:
go(s3, ???)
}
case None => Pull.done
}
}
go(s1, ???).stream
}
}
def pullAll[F[_], C <: Coproduct](
stream: Stream[F, C]
)(implicit ev: WaitFor[F, C]): Stream[F, ev.Out] = {
stream.through(ev.apply)
}
}
</code></pre>
<p>My roadblock starts here:</p>
<pre class="lang-scala prettyprint-override"><code> override def apply: Pipe[F, C, Out] = ???
</code></pre>
<p>and that's when my knowledge of Shapeless exhausts.</p>
<p>My idea is to keep track of all coproduct members in a tuple (Option[C1], Option[C2], ...).</p>
<p>Once every element in the tuple is <code>Some</code>, I'll covert them to a HList and output them in the Stream.</p>
<p>(I'll be using FS2 Pull to keep track of the state recursively so I'm not worried about that).</p>
<p>But my issue is that, at the value level, there's no way for me to know how long the tuple will be, and for me to construct a tuple.</p>
<p>Any pointers so I can solve this?</p>
<p>Thanks</p>
|
[
{
"answer_id": 74521555,
"author": "Mateusz Kubuszok",
"author_id": 1305121,
"author_profile": "https://Stackoverflow.com/users/1305121",
"pm_score": 3,
"selected": true,
"text": "A :+: B :+: C :+: CNil"
},
{
"answer_id": 74522405,
"author": "eitaporra",
"author_id": 19703316,
"author_profile": "https://Stackoverflow.com/users/19703316",
"pm_score": 2,
"selected": false,
"text": "Collector"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19703316/"
] |
74,476,845
|
<p>With dplyr you can group by columns like this:</p>
<pre><code>library(dplyr)
df <- data.frame(a=c(1,2,1,3,1,4,1,5), b=c(2,3,4,1,2,3,4,5))
df %>%
group_by(a) %>%
summarise(count = n())
</code></pre>
<p>If I want to group by two columns all the guides say:</p>
<pre><code>df %>%
group_by(a,b) %>%
summarise(count = n())
</code></pre>
<p>But can I not feed the <code>group_by()</code> parameters more efficiently somehow, rather than having to type them in explicitly, e.g. like:</p>
<pre><code>cols = colnames(df)
df %>%
group_by(cols) %>%
summarise(count = n())
</code></pre>
<p>I have examples where I want to group by 10+ columns, and it is pretty horrible to write it out if you can just parse their names.</p>
|
[
{
"answer_id": 74476887,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 3,
"selected": true,
"text": "across"
},
{
"answer_id": 74476920,
"author": "MrFlick",
"author_id": 2372064,
"author_profile": "https://Stackoverflow.com/users/2372064",
"pm_score": 2,
"selected": false,
"text": "across"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1652219/"
] |
74,476,862
|
<p>Knowing that drools work with in memory data. Is there a way to distribute horizontally on different drools instances to enhance performance when performing CRUD operations on rules, fact types, etc? I guess the instances would need to be on sync with each other in some way, so they all have the same data in memory or share in some way a knowledge base. I'm kinda new on drools and trying to research on a way to move a monolith on a cloud environment (gcp) so it can take advantage on load balancing, scaling, etc. Want to know if there is any feature on drools itself that supports this or if there is any way to implement this myself, thanks in advance for any information/documentation/use case on this matter.</p>
<p>Currently I haven't tried a way to do this, but my goal is to improve performance and availability by using automatic scaling or support multiple instances of my app.</p>
|
[
{
"answer_id": 74476887,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 3,
"selected": true,
"text": "across"
},
{
"answer_id": 74476920,
"author": "MrFlick",
"author_id": 2372064,
"author_profile": "https://Stackoverflow.com/users/2372064",
"pm_score": 2,
"selected": false,
"text": "across"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19840953/"
] |
74,476,873
|
<p>I am using cloud firestore + cloud functions + firestore auth to support my game.</p>
<p>I developed the main part of the app with unit tests in the app plus typescript tests for cloud functions. Now I want to add security rules to secure the data.</p>
<p>When I do so, requiring the calls to be authenticated, all my unit tests in unity (naturally) fails, as I do not authenticate a user but mocks them as data representation of the user in the db.</p>
<p>I want to keep using my unit tests in unity but still requiring the real db to demand authentication.</p>
<p>I have tried to look around for mock auth, or auth test environment, but found nothing except the library <a href="https://firebase.google.com/docs/reference/emulator-suite/rules-unit-testing/rules-unit-testing" rel="nofollow noreferrer">rules-unit-testing</a>.</p>
<p>I see the content of it with specialized logic for mocking user, making me think that I am understanding this the wrong way by trying to do this in unity. My question is, <strong>How to continue to do game tests in unity, which requires interacting with the firestore server, while keeping security rules?</strong></p>
|
[
{
"answer_id": 74476887,
"author": "Juan C",
"author_id": 9462829,
"author_profile": "https://Stackoverflow.com/users/9462829",
"pm_score": 3,
"selected": true,
"text": "across"
},
{
"answer_id": 74476920,
"author": "MrFlick",
"author_id": 2372064,
"author_profile": "https://Stackoverflow.com/users/2372064",
"pm_score": 2,
"selected": false,
"text": "across"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8618797/"
] |
74,476,929
|
<p>How can I use <code>distinctUntilChanged()</code> but also add an expiry to it, which means if the same value is in the flow we still collect it because it was longer than <code>expiry</code> milliseconds after the previous duplicated value was emitted.</p>
<pre><code>flow {
emit("A") // printed
emit("B") // printed
emit("A") // printed
emit("A") // NOT printed because duplicate
delay(5000)
emit("A") // printed because 5 seconds elapsed which is more than expiry
}
.distinctUntilChanged(expiry = 2000)
.collect {
println(it)
}
</code></pre>
<p>I would like this to print:</p>
<pre><code>A
B
A
A
</code></pre>
<p>Here's the code to test it:</p>
<pre><code> @Test
fun `distinctUntilChanged works as expected`(): Unit = runBlocking {
flow {
emit("A") // printed
emit("B") // printed
emit("A") // printed
emit("A") // NOT printed because duplicate
delay(5000)
emit("A") // printed because 5 seconds elapsed which is more than expiry
}
.distinctUntilChanged(expiry = 2000)
.toList().also {
assertEquals("A", it[0])
assertEquals("B", it[1])
assertEquals("A", it[2])
assertEquals("A", it[3])
}
}
</code></pre>
|
[
{
"answer_id": 74477280,
"author": "Tenfour04",
"author_id": 506796,
"author_profile": "https://Stackoverflow.com/users/506796",
"pm_score": 3,
"selected": true,
"text": "havePreviousValue"
},
{
"answer_id": 74670341,
"author": "Ajmal Kunnummal",
"author_id": 1767204,
"author_profile": "https://Stackoverflow.com/users/1767204",
"pm_score": 1,
"selected": false,
"text": "fun <T> Flow<T>.distinctUntilChanged(expiry: Long) = \n merge(\n distinctUntilChanged(), \n channelFlow {\n val shared = buffer(Channel.CONFLATED).produceIn(this)\n debounce(expiry).takeWhile { !shared.isClosedForReceive }.collect { \n val lastVal = shared.receive()\n shared.receive().let { if(lastVal == it) send(it) }\n }\n }\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1502079/"
] |
74,476,930
|
<p>I have a dictionary called <code>cc_dict</code> and am trying to use list comprehension to iterate over each key to find a match in a string called <code>new_string</code>. The line below works but it also matches keys that are part of whole words. I want to match whole words only.</p>
<p>So, for example, the key "test" is matched in the string "text for testing".</p>
<p>How can I do this?</p>
<p>Example one:</p>
<pre><code>cc_dict = {“test one”: “SSK1”, “result”: “TGG”, “pass”: “PSS1”, “fail”: “FL1”}
new_string = "If test one is complete."
output = [te for key, te in cc_dict.items() if key in new_string]
</code></pre>
<p>Desired result: SSK1</p>
<p>Example two:</p>
<pre><code>cc_dict = {“test one”: “SSK1”, “result”: “TGG”, “pass”: “PSS1”, “fail”: “FL1”}
new_string = "There has been a failure in annex 1."
output = [te for key, te in cc_dict.items() if key in new_string]
</code></pre>
<p>Desired result: no result but as "fail" is contained in the word "failure" the list comprehension currently returns FL1.</p>
|
[
{
"answer_id": 74477280,
"author": "Tenfour04",
"author_id": 506796,
"author_profile": "https://Stackoverflow.com/users/506796",
"pm_score": 3,
"selected": true,
"text": "havePreviousValue"
},
{
"answer_id": 74670341,
"author": "Ajmal Kunnummal",
"author_id": 1767204,
"author_profile": "https://Stackoverflow.com/users/1767204",
"pm_score": 1,
"selected": false,
"text": "fun <T> Flow<T>.distinctUntilChanged(expiry: Long) = \n merge(\n distinctUntilChanged(), \n channelFlow {\n val shared = buffer(Channel.CONFLATED).produceIn(this)\n debounce(expiry).takeWhile { !shared.isClosedForReceive }.collect { \n val lastVal = shared.receive()\n shared.receive().let { if(lastVal == it) send(it) }\n }\n }\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16027663/"
] |
74,476,963
|
<p>I have 2 arrays: I need to sort them in foreach to modify 1 file.</p>
<p>1 array with dbs name like:</p>
<pre><code>$dbs = ['Honda', 'Toyota', 'BMW', 'Opel']
</code></pre>
<p>2nd array with their size like:</p>
<pre><code>$dbsSize = ['123', '300', '222', '143']
</code></pre>
<p>and I can sort names in foreach like</p>
<pre><code>foreach ($db in $dbs){
# some logic..
}
</code></pre>
<p>How can I sort 2nd array in the same <code>foreach</code> so I can use it in the same loop</p>
<p>Like this:</p>
<pre><code>foreach ($db in $dbs) {
# some logic with $db
# and here I need some logic with $dbsSize
}
</code></pre>
<p>but to sort out $dbsSize like $dbs because I need the result like :</p>
<pre class="lang-none prettyprint-override"><code>Honda
123
Toyota
300
</code></pre>
<p>etc.</p>
<p>Do I need to create another loop?</p>
|
[
{
"answer_id": 74477280,
"author": "Tenfour04",
"author_id": 506796,
"author_profile": "https://Stackoverflow.com/users/506796",
"pm_score": 3,
"selected": true,
"text": "havePreviousValue"
},
{
"answer_id": 74670341,
"author": "Ajmal Kunnummal",
"author_id": 1767204,
"author_profile": "https://Stackoverflow.com/users/1767204",
"pm_score": 1,
"selected": false,
"text": "fun <T> Flow<T>.distinctUntilChanged(expiry: Long) = \n merge(\n distinctUntilChanged(), \n channelFlow {\n val shared = buffer(Channel.CONFLATED).produceIn(this)\n debounce(expiry).takeWhile { !shared.isClosedForReceive }.collect { \n val lastVal = shared.receive()\n shared.receive().let { if(lastVal == it) send(it) }\n }\n }\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18644650/"
] |
74,476,981
|
<p>in antd Form component there is validateTrigger property that can get a string or array of strings as value.when and why we should use array of strings?</p>
<p><a href="https://ant.design/components/form/#Form" rel="nofollow noreferrer">antd form api</a></p>
|
[
{
"answer_id": 74477280,
"author": "Tenfour04",
"author_id": 506796,
"author_profile": "https://Stackoverflow.com/users/506796",
"pm_score": 3,
"selected": true,
"text": "havePreviousValue"
},
{
"answer_id": 74670341,
"author": "Ajmal Kunnummal",
"author_id": 1767204,
"author_profile": "https://Stackoverflow.com/users/1767204",
"pm_score": 1,
"selected": false,
"text": "fun <T> Flow<T>.distinctUntilChanged(expiry: Long) = \n merge(\n distinctUntilChanged(), \n channelFlow {\n val shared = buffer(Channel.CONFLATED).produceIn(this)\n debounce(expiry).takeWhile { !shared.isClosedForReceive }.collect { \n val lastVal = shared.receive()\n shared.receive().let { if(lastVal == it) send(it) }\n }\n }\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12510464/"
] |
74,476,987
|
<p>I am developing an app on Visual Studio for Mac with Xcode. I have a Window Controller with Sidebar that gives you a split view controller that is split into a sidebar controller and a view controller.</p>
<p>Right now it looks like this:</p>
<p><a href="https://i.stack.imgur.com/tpDIN.png" rel="nofollow noreferrer">Split View Controller</a></p>
<p>I want to be able to toggle the left sidebar (as in collapse or show) when I click on the sidebar icon in the toolbar. I added the icons in the toolbar as Custom Toolbar Items by just dragging and dropping a textured round button and putting an icon in it.</p>
<p>Does anyone have an idea as to how to do this? is there a function already that I need to call? would greatly appreciate it.</p>
<p>So far, I found online some resources like the following:
<a href="https://developer.apple.com/forums/thread/705335" rel="nofollow noreferrer">https://developer.apple.com/forums/thread/705335</a></p>
<p>However they are all in Swift and I could not find any equivalents for C#.</p>
|
[
{
"answer_id": 74477280,
"author": "Tenfour04",
"author_id": 506796,
"author_profile": "https://Stackoverflow.com/users/506796",
"pm_score": 3,
"selected": true,
"text": "havePreviousValue"
},
{
"answer_id": 74670341,
"author": "Ajmal Kunnummal",
"author_id": 1767204,
"author_profile": "https://Stackoverflow.com/users/1767204",
"pm_score": 1,
"selected": false,
"text": "fun <T> Flow<T>.distinctUntilChanged(expiry: Long) = \n merge(\n distinctUntilChanged(), \n channelFlow {\n val shared = buffer(Channel.CONFLATED).produceIn(this)\n debounce(expiry).takeWhile { !shared.isClosedForReceive }.collect { \n val lastVal = shared.receive()\n shared.receive().let { if(lastVal == it) send(it) }\n }\n }\n )\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340982/"
] |
74,476,995
|
<p>I have a text which need to be animated to show and hide with the value is null or not. it would have been straight forward if the visibility is separately handle, but this is what I got.
In the bellow code the enter animation works but the exit animation dont as the text value is null.
I can think of something with remembering the old value but not sure how.</p>
<pre><code>@Composable
fun ShowAnimatedText(
text : String?
) {
Column(
modifier = Modifier.fillMaxWidth()
) {
AnimatedVisibility(
visible = text != null,
enter = fadeIn(animationSpec = tween(2000)),
exit = fadeOut(animationSpec = tween(2000))
) {
text?.let {
Text(text = it)
}
}
}
}
</code></pre>
|
[
{
"answer_id": 74478074,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 2,
"selected": false,
"text": "text: String?"
},
{
"answer_id": 74478890,
"author": "SproutinGeek",
"author_id": 1608975,
"author_profile": "https://Stackoverflow.com/users/1608975",
"pm_score": 0,
"selected": false,
"text": "@Composable\nfun ShowAnimatedText(\n text : String?,\n show: Boolean\n) {\n var localText by remember {\n mutableStateOf<String?>(null)\n }\n AnimatedContent(show, localText)\n LaunchedEffect(key1 = text, block = {\n if(text == null){\n delay(2000)\n }\n localText = text\n })\n}\n@Composable\nprivate fun AnimatedContent(show: Boolean, localText: String?) {\n Column(\n modifier = Modifier.fillMaxWidth()\n ) {\n AnimatedVisibility(\n visible = show,\n enter = fadeIn(animationSpec = tween(2000)),\n exit = fadeOut(animationSpec = tween(2000))\n ) {\n localText?.let {\n Text(text = it)\n }\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74476995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1608975/"
] |
74,477,009
|
<p>I have a single table with ~ 1.5 mio entries and this query:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT id
FROM abc.items as I
where revisit < '2022-11-17T00:00:00Z'
AND type = 10
AND firstdelivery = (
select min(firstdelivery)
from abc.items
WHERE I.polizzennummer = polizzennummer
)
LIMIT 50
</code></pre>
<p>Which takes about 120-180 seconds to run.
The revisit is the part which changes the most, this is a query which runs every day.</p>
<p>Table schema:</p>
<pre class="lang-sql prettyprint-override"><code>'id','int(10) unsigned','NO','PRI',NULL,'auto_increment'
'polizzennummer','varchar(64)','YES','MUL',NULL,''
'type','tinyint(4)','YES','MUL',NULL,''
'revisit','datetime','YES','MUL',NULL,''
'status','tinyint(4)','YES','',NULL,''
'ts','datetime','YES','',NULL,''
'grund','text','YES','',NULL,''
'firstdelivery','datetime','YES','MUL',NULL,''
</code></pre>
<p>Explain Output:</p>
<pre><code>'1', 'PRIMARY', 'I', NULL, 'ref', 'idx_abc_type,idx_abc_revisit,idx_abc_type_revisit_firstdelivery', 'idx_abc_type', '2', 'const', '499036', '50.00', 'Using where'
'2', 'DEPENDENT SUBQUERY', 'abc', NULL, 'ref', 'polizzennummer,idx_abc_polizzennummer_firstdelivery', 'idx_abc_polizzennummer_firstdelivery', '195', 'abc.I.polizzennummer', '7', '100.00', 'Using index'
</code></pre>
<p>The table index output:</p>
<pre><code>'abc', '0', 'PRIMARY', '1', 'id', 'A', '998072', NULL, NULL, '', 'BTREE', '', ''
'abc', '0', 'id_UNIQUE', '1', 'id', 'A', '998072', NULL, NULL, '', 'BTREE', '', ''
'abc', '1', 'polizzennummer', '1', 'polizzennummer', 'A', '117288', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_type', '1', 'type', 'A', '10', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_revisit', '1', 'revisit', 'A', '93553', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_firstdelivery', '1', 'firstdelivery', 'A', '998072', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_polizzennummer_firstdelivery', '1', 'polizzennummer', 'A', '125237', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_polizzennummer_firstdelivery', '2', 'firstdelivery', 'A', '998072', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_type_revisit_firstdelivery', '1', 'type', 'A', '10', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_type_revisit_firstdelivery', '2', 'revisit', 'A', '116078', NULL, NULL, 'YES', 'BTREE', '', ''
'abc', '1', 'idx_abc_type_revisit_firstdelivery', '3', 'firstdelivery', 'A', '998072', NULL, NULL, 'YES', 'BTREE', '', ''
</code></pre>
<p>Im not sure how i could optimize this query further.</p>
<p>Any help or suggestion is appreciated</p>
|
[
{
"answer_id": 74478074,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 2,
"selected": false,
"text": "text: String?"
},
{
"answer_id": 74478890,
"author": "SproutinGeek",
"author_id": 1608975,
"author_profile": "https://Stackoverflow.com/users/1608975",
"pm_score": 0,
"selected": false,
"text": "@Composable\nfun ShowAnimatedText(\n text : String?,\n show: Boolean\n) {\n var localText by remember {\n mutableStateOf<String?>(null)\n }\n AnimatedContent(show, localText)\n LaunchedEffect(key1 = text, block = {\n if(text == null){\n delay(2000)\n }\n localText = text\n })\n}\n@Composable\nprivate fun AnimatedContent(show: Boolean, localText: String?) {\n Column(\n modifier = Modifier.fillMaxWidth()\n ) {\n AnimatedVisibility(\n visible = show,\n enter = fadeIn(animationSpec = tween(2000)),\n exit = fadeOut(animationSpec = tween(2000))\n ) {\n localText?.let {\n Text(text = it)\n }\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1966723/"
] |
74,477,013
|
<p>I need to POST a script by using BigCommerce API.
Here is the body</p>
<pre><code>{
"name": "string",
"description": "string",
"html": "string",
"src": "(function (sCDN, sCDNProject, sCDNWorkspace, sCDNVers) {
if (
window.localStorage !== null &&
typeof window.localStorage === 'object' &&
typeof window.localStorage.getItem === 'function' &&
window.sessionStorage !== null &&
typeof window.sessionStorage === 'object' &&
typeof window.sessionStorage.getItem === 'function'
) {
sCDNVers =
window.sessionStorage.getItem('wx_preview_version') ||
window.localStorage.getItem('wx_preview_version') ||
sCDNVers;
}
window.x= window.x|| {};
window.x.config = window.x.config || {};
window.x.config.frontend = window.x.config.frontend || {};
window.x.config.frontend.cdnhost =
sCDN + '/get/' + sCDNWorkspace + '/web/' + sCDNVers + '/';
window.x.config.frontend.vers = sCDNVers;
window.x.config.frontend.env = sCDNWorkspace;
window.x.config.frontend.project = sCDNProject;
window._wx = window._wx || [];
var f = document.getElementsByTagName('script')[0];
var j = document.createElement('script');
j.async = true;
j.src = window.x.config.frontend.cdnhost + 'sss.js';
f.parentNode.insertBefore(j, f);
})(
'https://xxxx.x-x-x.mybigcommerce.com',
'x-test-env',
'live',
'_'
);",
"auto_uninstall": true,
"load_method": "default",
"location": "head",
"visibility": "storefront",
"kind": "src",
"api_client_id": "string",
"consent_category": "essential",
"enabled": true,
"channel_id": 1
}
</code></pre>
<p>but it returned</p>
<blockquote>
<p>{
"status": 400,
"title": "Input is invalid",
"type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes",
"errors": {} }</p>
</blockquote>
<p>Seems like it occurred with '{'
<a href="https://i.stack.imgur.com/pDZT9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pDZT9.png" alt="enter image description here" /></a></p>
<p>Any method that I can POST this script to head?</p>
|
[
{
"answer_id": 74478074,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 2,
"selected": false,
"text": "text: String?"
},
{
"answer_id": 74478890,
"author": "SproutinGeek",
"author_id": 1608975,
"author_profile": "https://Stackoverflow.com/users/1608975",
"pm_score": 0,
"selected": false,
"text": "@Composable\nfun ShowAnimatedText(\n text : String?,\n show: Boolean\n) {\n var localText by remember {\n mutableStateOf<String?>(null)\n }\n AnimatedContent(show, localText)\n LaunchedEffect(key1 = text, block = {\n if(text == null){\n delay(2000)\n }\n localText = text\n })\n}\n@Composable\nprivate fun AnimatedContent(show: Boolean, localText: String?) {\n Column(\n modifier = Modifier.fillMaxWidth()\n ) {\n AnimatedVisibility(\n visible = show,\n enter = fadeIn(animationSpec = tween(2000)),\n exit = fadeOut(animationSpec = tween(2000))\n ) {\n localText?.let {\n Text(text = it)\n }\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19923865/"
] |
74,477,019
|
<p>What I am thinking might be naive. But I want to split the rows [1:3] of df based on the second "_", using <code>tidyr::extract()</code></p>
<pre><code>library(tidyr)
library(dplyr)
extract(col1, into = c("col1", "col2"), "^(.*?_.*?)_(.*)$")
</code></pre>
<p>and the rows of df [4:6] based on the first "_"</p>
<pre><code>extract(col1, into = c("col1", "col2"), "^(.*?)_(.*)$")
</code></pre>
<p>I am thinking of something like</p>
<pre><code>df %>%
mutate(n=row_number())
mutate(col2=case_when
(n<=3 ~ extract(col1, into = c("col1", "col2"), "^(.*?_.*?)_(.*)$"),
n>3 ~ extract(col1, into = c("col1", "col2"), "^(.*?)_(.*)$")
)
</code></pre>
<p>Of course, this is screamingly wrong but is it possible in some way?</p>
<p>Example data:</p>
<pre class="lang-r prettyprint-override"><code>df=tibble(col1 = c("2397_A_run379_CTTGTACT_S119_L004_R1_001",
"3779_A_run535_TTATAGCC_S91_L003_R1_001",
"4958_BV_run685_GCGTACGT_S89_L005_R1_001",
"5126AA_S27_L004_R1_001",
"5126AF_S32_L004_R1_001",
"5126AL_S38_L004_R1_001"))
df
#> # A tibble: 6 × 1
#> col1
#> <chr>
#> 1 2397_A_run379_CTTGTACT_S119_L004_R1_001
#> 2 3779_A_run535_TTATAGCC_S91_L003_R1_001
#> 3 4958_BV_run685_GCGTACGT_S89_L005_R1_001
#> 4 5126AA_S27_L004_R1_001
#> 5 5126AF_S32_L004_R1_001
#> 6 5126AL_S38_L004_R1_001
</code></pre>
<p><sup>Created on 2022-11-17 with <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex v2.0.2</a></sup></p>
|
[
{
"answer_id": 74478074,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 2,
"selected": false,
"text": "text: String?"
},
{
"answer_id": 74478890,
"author": "SproutinGeek",
"author_id": 1608975,
"author_profile": "https://Stackoverflow.com/users/1608975",
"pm_score": 0,
"selected": false,
"text": "@Composable\nfun ShowAnimatedText(\n text : String?,\n show: Boolean\n) {\n var localText by remember {\n mutableStateOf<String?>(null)\n }\n AnimatedContent(show, localText)\n LaunchedEffect(key1 = text, block = {\n if(text == null){\n delay(2000)\n }\n localText = text\n })\n}\n@Composable\nprivate fun AnimatedContent(show: Boolean, localText: String?) {\n Column(\n modifier = Modifier.fillMaxWidth()\n ) {\n AnimatedVisibility(\n visible = show,\n enter = fadeIn(animationSpec = tween(2000)),\n exit = fadeOut(animationSpec = tween(2000))\n ) {\n localText?.let {\n Text(text = it)\n }\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7179299/"
] |
74,477,028
|
<p>I have written a C program in which I output the lowest and highest temperature with day of the week and time in the lower function. However, sometimes values are duplicated. How can I implement this in my function so that both times are displayed?</p>
<pre><code>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <limits.h>
double week_statistics(double array[52][7][24], int kalenderwoche, int j, int i, int k, int daymin, int hourmin, int daymax, int hourmax){
double min = array[0][0][0];
for(j = 0; j < 7; j++){
for(k = 0; k < 24; k++){
if(array[i][j][k] < min){
min = array[i][j][k];
daymin = j + 1;
hourmin = k + 1;
}}}
printf("Die niedrigste Temperatur war %lf° in der %d. Kalenderwoche am %d. Wochentag um %d Uhr.\n", min, kalenderwoche, daymin, hourmin);
double max = array[0][0][0];
for(i = 0; i < 52; i++){
for(j = 0; j < 7; j++){
for(k = 0; k < 24; k++){
if(array[i][j][k] > max){
max = array[i][j][k];
daymax = j + 1;
hourmax = k + 1;
}}}}
printf("Die höchste Temperatur war %lf° in der %d. Kalenderwoche am %d. Wochentag um %d Uhr.\n", max, kalenderwoche, daymax, hourmax);
}
int main(){
double array[52][7][24] = {{
{9.6, 9.4, 9.3, 9.1, 7.9, 7.7, 7.3, 7.2, 8.8, 9.3, 9.7, 9.4, 10.2, 9.7, 9.9, 9.5, 9.2, 9.3, 9.2, 7.1, 6.1, 5.9, 5.6, 5.2},
{4.9, 4.6, 4.6, 4.1, 3.5, 3.1, 2.6, 2.6, 3.5, 5.1, 6.2, 8.3, 9.0, 9.3, 9.1, 8.0, 6.8, 6.4, 5.4, 5.2, 4.8, 4.5, 5.0, 5.5},
{6.3, 6.8, 7.0, 7.2, 7.1, 7.2, 7.1, 7.4, 7.7, 8.2, 8.7, 9.1, 8.8, 8.7, 8.6, 8.4, 8.0, 7.9, 7.7, 7.6, 7.5, 7.3, 7.3, 7.2},
{7.1, 7.0, 6.9, 6.8, 6.7, 6.7, 6.7, 6.6, 6.7, 6.8, 6.9, 7.2, 7.5, 7.7, 8.1, 8.3, 8.0, 7.7, 8.1, 8.2, 7.7, 7.5, 7.7, 7.9},
{8.1, 8.0, 7.9, 7.8, 7.5, 7.2, 6.9, 7.2, 8.0, 8.4, 8.7, 9.0, 8.7, 8.9, 9.0, 7.8, 8.5, 8.1, 7.7, 7.7, 6.7, 7.0, 6.5, 7.1},
{6.4, 6.6, 6.3, 5.8, 5.0, 4.9, 4.7, 4.6, 4.9, 5.3, 6.1, 5.5, 5.3, 5.7, 5.8, 6.5, 6.6, 5.8, 5.8, 7.1, 7.0, 7.0, 6.3, 5.8},
{4.4, 4.0, 3.8, 3.8, 4.2, 4.2, 4.3, 3.8, 4.4, 5.2, 5.7, 5.9, 6.1, 6.7, 6.3, 5.9, 5.5, 5.1, 5.0, 5.0, 5.2, 5.7, 7.2, 7.7}
}};
int kalenderwoche = 45;
int i, j,k;
int daymin,daymax = 1;
int hourmin,hourmax = 1;
week_statistics(array, kalenderwoche, i, j ,k, daymin, hourmin, daymax, hourmax); //c)
}
</code></pre>
|
[
{
"answer_id": 74478074,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 2,
"selected": false,
"text": "text: String?"
},
{
"answer_id": 74478890,
"author": "SproutinGeek",
"author_id": 1608975,
"author_profile": "https://Stackoverflow.com/users/1608975",
"pm_score": 0,
"selected": false,
"text": "@Composable\nfun ShowAnimatedText(\n text : String?,\n show: Boolean\n) {\n var localText by remember {\n mutableStateOf<String?>(null)\n }\n AnimatedContent(show, localText)\n LaunchedEffect(key1 = text, block = {\n if(text == null){\n delay(2000)\n }\n localText = text\n })\n}\n@Composable\nprivate fun AnimatedContent(show: Boolean, localText: String?) {\n Column(\n modifier = Modifier.fillMaxWidth()\n ) {\n AnimatedVisibility(\n visible = show,\n enter = fadeIn(animationSpec = tween(2000)),\n exit = fadeOut(animationSpec = tween(2000))\n ) {\n localText?.let {\n Text(text = it)\n }\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20401148/"
] |
74,477,082
|
<p>I'm working on a script that checks (with If statements) if a variable contains a specific character. If a character is found the script executes some code. If a certain character cannot be found, the script will go into another If Statement to check if the variable contains another specific character, and so on.</p>
<p>this all works perfectly fine.</p>
<p>But I need the script to tell me if none of the characters are found, but i'm having some trouble accomplishing this goal. the script looks like this.</p>
<pre><code>if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
</code></pre>
<p>If all these If Statements cannot find their character I need the script to echo that these characters are not found.</p>
<p>I tried to put a If/else statement around all the other If statements, but this did not work for me.</p>
<pre><code>if [[ ]]; then
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
else
echo "characters are not found."
</code></pre>
<p>I can't seem to get it to work. Can somebody give me a push in the right direction?</p>
<p>Kind Regards,</p>
<p>Sleek</p>
|
[
{
"answer_id": 74477197,
"author": "mju",
"author_id": 9197527,
"author_profile": "https://Stackoverflow.com/users/9197527",
"pm_score": 0,
"selected": false,
"text": "...\n\nif [[ \"$results\" == *\"specific character\"* ]]; then\n foundsmth=1\nfi\n\nif [[ -z ${foundsmth} ]] ; then\n # nothing found\nfi\n\n"
},
{
"answer_id": 74477332,
"author": "dawg",
"author_id": 298607,
"author_profile": "https://Stackoverflow.com/users/298607",
"pm_score": 0,
"selected": false,
"text": "if"
},
{
"answer_id": 74477447,
"author": "Dennis Williamson",
"author_id": 26428,
"author_profile": "https://Stackoverflow.com/users/26428",
"pm_score": 3,
"selected": true,
"text": "case"
},
{
"answer_id": 74477629,
"author": "Paul Hodges",
"author_id": 8656552,
"author_profile": "https://Stackoverflow.com/users/8656552",
"pm_score": 0,
"selected": false,
"text": "case"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14323669/"
] |
74,477,092
|
<p>React newbie here.</p>
<p>I'm trying to make a multi-step form to get some details from the user and for some of the nested views, there are only radio buttons. The <code>handleChange</code> works fine on text type but how can I handle radio buttons?</p>
<p>React does not render the radio button that is used to render in AngularJS, so I am a bit confused. I can choose multiple radio button and all of them looks like checkboxes instead of choosing only one</p>
<p><strong>MainForms.js</strong></p>
<pre><code>export class UserForm extends Component {
state = {
step: 1,
tema: '',
area: '',
type: '',
name: ''
};
// Proceed to next step
nextStep = () => {
const { step } = this.state;
this.setState({
step: step + 1
});
};
// Go back to prev step
prevStep = () => {
const { step } = this.state;
this.setState({
step: step - 1
});
};
// Handle fields change
handleChange = input => e => {
this.setState({ [input]: e.target.value });
console.log(e.target.value)
};
render() {
const { step } = this.state;
const { area, name, type, tema} = this.state;
const values = { area, name, type, tema};
switch (step) {
case 1:
return (
<FormUserDetails
nextStep={this.nextStep}
handleChange={this.handleChange}
values={values}
/>
);
</code></pre>
<p><strong>FormUserDetails.js</strong></p>
<pre><code>export class FormUserDetails extends Component {
continue = (e) => {
e.preventDefault();
this.props.nextStep();
};
back = (e) => {
e.preventDefault();
this.props.prevStep();
}
render() {
const { handleChange } = this.props;
return (
<div className="box item2">
<div className="radio">
<label>
<input
type="radio"
onChange={handleChange}
/>
Basic
</label>
</div>
);
}
}
</code></pre>
<p><a href="https://i.stack.imgur.com/g2R9M.png" rel="nofollow noreferrer">form example</a></p>
|
[
{
"answer_id": 74477197,
"author": "mju",
"author_id": 9197527,
"author_profile": "https://Stackoverflow.com/users/9197527",
"pm_score": 0,
"selected": false,
"text": "...\n\nif [[ \"$results\" == *\"specific character\"* ]]; then\n foundsmth=1\nfi\n\nif [[ -z ${foundsmth} ]] ; then\n # nothing found\nfi\n\n"
},
{
"answer_id": 74477332,
"author": "dawg",
"author_id": 298607,
"author_profile": "https://Stackoverflow.com/users/298607",
"pm_score": 0,
"selected": false,
"text": "if"
},
{
"answer_id": 74477447,
"author": "Dennis Williamson",
"author_id": 26428,
"author_profile": "https://Stackoverflow.com/users/26428",
"pm_score": 3,
"selected": true,
"text": "case"
},
{
"answer_id": 74477629,
"author": "Paul Hodges",
"author_id": 8656552,
"author_profile": "https://Stackoverflow.com/users/8656552",
"pm_score": 0,
"selected": false,
"text": "case"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20054954/"
] |
74,477,100
|
<p>in the Mbed OS System there is a library called RTX_Config.h . I need to change the value of this define in the lib.</p>
<pre><code>#ifndef OS_ISR_FIFO_QUEUE
#define OS_ISR_FIFO_QUEUE 16
#endif
</code></pre>
<p>could someone give me a hint, how the Mbed Configuring System works and if I'm able to overide this Value with the Configuring System ?</p>
<p>Thanks !</p>
|
[
{
"answer_id": 74619623,
"author": "Jib",
"author_id": 20124358,
"author_profile": "https://Stackoverflow.com/users/20124358",
"pm_score": 0,
"selected": false,
"text": "// <o>ISR FIFO Queue \n// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries\n// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries\n// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries\n// <i> RTOS Functions called from ISR store requests to this buffer.\n// <i> Default: 16 entries\n#ifndef OS_ISR_FIFO_QUEUE\n#define OS_ISR_FIFO_QUEUE 16\n#endif\n"
},
{
"answer_id": 74638712,
"author": "Zhubei Federer",
"author_id": 10769406,
"author_profile": "https://Stackoverflow.com/users/10769406",
"pm_score": 2,
"selected": true,
"text": "{\n \"target_overrides\": {\n \"*\": {\n \"OS_ISR_FIFO_QUEUE\": 32\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8078298/"
] |
74,477,108
|
<p>So I have a list (shown below) and I need to randomly access one of the dictionaries in a list, and print it out:</p>
<p>e.g. Instagram, 346, Social media platform, United States</p>
<p>I've tried to google and search for it, but whatever I tried it didn't work. I know how to print out the whole list, but I don't know how to print a single dictionary randomly.</p>
<pre><code> data = [
{
'name': 'Instagram',
'follower_count': 346,
'description': 'Social media platform',
'country': 'United States'
},
{
'name': 'Cristiano Ronaldo',
'follower_count': 215,
'description': 'Footballer',
'country': 'Portugal'
},
{
'name': 'Ariana Grande',
'follower_count': 183,
'description': 'Musician and actress',
'country': 'United States'
}
]
</code></pre>
|
[
{
"answer_id": 74619623,
"author": "Jib",
"author_id": 20124358,
"author_profile": "https://Stackoverflow.com/users/20124358",
"pm_score": 0,
"selected": false,
"text": "// <o>ISR FIFO Queue \n// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries\n// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries\n// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries\n// <i> RTOS Functions called from ISR store requests to this buffer.\n// <i> Default: 16 entries\n#ifndef OS_ISR_FIFO_QUEUE\n#define OS_ISR_FIFO_QUEUE 16\n#endif\n"
},
{
"answer_id": 74638712,
"author": "Zhubei Federer",
"author_id": 10769406,
"author_profile": "https://Stackoverflow.com/users/10769406",
"pm_score": 2,
"selected": true,
"text": "{\n \"target_overrides\": {\n \"*\": {\n \"OS_ISR_FIFO_QUEUE\": 32\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17442745/"
] |
74,477,154
|
<p>I have an output of a dataframe below, into a dictionary.</p>
<pre><code>{0: ['RevitCategory', 'Door'],
1: ['DesignModelID', 'ModelA_Rev1'],
2: ['DesignObjectID', 'ModelA_Rev1_Object1'],
3: ['TypeName', 'ARC_DOR_INTERNAL'],
4: ['Function', 'Internal'],
5: ['Uniclass2015_Ss', 'Ss_25_30_20_25 : Doorset systems'],
6: ['IfcExportAs', 'IfcDoorType.DOOR'],
7: ['NRM1Classification', '2.8.1.1 Internal doors'],
8: ['RevitCategory', 'Wall'],
9: ['DesignModelID', 'ModelA_Rev1'],
10: ['DesignObjectID', 'ModelA_Rev1_Object2'],
11: ['TypeName', 'ARC_WALL_PARTITION_TYPE1'],
12: ['Function', 'Internal'],
13: ['Uniclass2015_Ss', 'Ss_25_10_30_35 : Gypsum board partition systems'],
14: ['IfcExportAs', 'IfcWallType.PARTITIONING'],
15: ['NRM1Classification', '2.7.1.1 Internal walls'],
16: ['Area', 5],
17: ['RevitCategory', 'Wall'],
18: ['DesignModelID', 'ModelA_Rev1'],
19: ['DesignObjectID', 'ModelA_Rev1_Object3'],
20: ['TypeName', 'ARC_WALL_PARTITION_TYPE1'],
21: ['Function', 'Internal'],
22: ['Uniclass2015_Ss', 'Ss_25_10_30_35 : Gypsum board partition systems'],
23: ['IfcExportAs', 'IfcWallType.PARTITIONING'],
24: ['NRM1Classification', '2.7.1.1 Internal walls'],
25: ['Area', 5],
26: ['RevitCategory', 'Wall'],
27: ['DesignModelID', 'ModelA_Rev1'],
28: ['DesignObjectID', 'ModelA_Rev1_Object4'],
29: ['TypeName', 'ARC_WALL_PARTITION_TYPE1'],
30: ['Function', 'Internal'],
31: ['Uniclass2015_Ss', 'Ss_25_10_30_35 : Gypsum board partition systems'],
32: ['IfcExportAs', 'IfcWallType.PARTITIONING'],
33: ['NRM1Classification', '2.7.1.1 Internal walls'],
34: ['Area', 5]
</code></pre>
<p>How would I combine the columns, for example in an output like the one below, stacking the results of the columns as they are merged ?</p>
<pre><code>RevitCategory | DesignModelID | DesignObjectID | etc.
-----------------------------------------------------------------
Door | ModelA_Rev1 | ModelA_Rev1_Object1 |
Wall | ModelA_Rev1 | ModelA_Rev1_Object1 |
Wall | ModelA_Rev1 | ModelA_Rev1_Object1 |
-----------------------------------------------------------------
</code></pre>
|
[
{
"answer_id": 74619623,
"author": "Jib",
"author_id": 20124358,
"author_profile": "https://Stackoverflow.com/users/20124358",
"pm_score": 0,
"selected": false,
"text": "// <o>ISR FIFO Queue \n// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries\n// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries\n// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries\n// <i> RTOS Functions called from ISR store requests to this buffer.\n// <i> Default: 16 entries\n#ifndef OS_ISR_FIFO_QUEUE\n#define OS_ISR_FIFO_QUEUE 16\n#endif\n"
},
{
"answer_id": 74638712,
"author": "Zhubei Federer",
"author_id": 10769406,
"author_profile": "https://Stackoverflow.com/users/10769406",
"pm_score": 2,
"selected": true,
"text": "{\n \"target_overrides\": {\n \"*\": {\n \"OS_ISR_FIFO_QUEUE\": 32\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20479479/"
] |
74,477,182
|
<p>I have a list of names like below</p>
<p><code>100m LJ SP HJ 400m </code></p>
<p>I would like to have this in the following format:</p>
<p><code>"100m", "LJ", "SP", "HJ", "400m"</code></p>
<p>Is there any function that preexisted in R?</p>
|
[
{
"answer_id": 74619623,
"author": "Jib",
"author_id": 20124358,
"author_profile": "https://Stackoverflow.com/users/20124358",
"pm_score": 0,
"selected": false,
"text": "// <o>ISR FIFO Queue \n// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries\n// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries\n// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries\n// <i> RTOS Functions called from ISR store requests to this buffer.\n// <i> Default: 16 entries\n#ifndef OS_ISR_FIFO_QUEUE\n#define OS_ISR_FIFO_QUEUE 16\n#endif\n"
},
{
"answer_id": 74638712,
"author": "Zhubei Federer",
"author_id": 10769406,
"author_profile": "https://Stackoverflow.com/users/10769406",
"pm_score": 2,
"selected": true,
"text": "{\n \"target_overrides\": {\n \"*\": {\n \"OS_ISR_FIFO_QUEUE\": 32\n }\n }\n}\n"
}
] |
2022/11/17
|
[
"https://Stackoverflow.com/questions/74477182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2890129/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.