qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,398,999 | <p>I am using laravel and mysql ,i am joining two tables based on conditions it's working fine but my requirement was i have to fetch those details inside json ,can anyone give me some idea how to proceed with this scenario ?</p>
<pre><code>Table1::leftJoin(//mycondition)->select('table1.id','table1.name','table2.*')->get()->toArray();
</code></pre>
<p><strong>currentResult</strong></p>
<pre><code>[
{
'id':1,
'name':'test',
'tab2id':1,
'tab2name':'tab2'
}
]
</code></pre>
<p><strong>ExpectedResult</strong></p>
<pre><code>[
{
'id':1,
'name':'test',
'tab2':{
'tab2id':1,
'tab2name':'tab2'
}
}
]
</code></pre>
| [
{
"answer_id": 74400008,
"author": "Hady_Khann",
"author_id": 14682350,
"author_profile": "https://Stackoverflow.com/users/14682350",
"pm_score": -1,
"selected": false,
"text": "case \"title\" or \"phone\" or \"address\" or \"e_mail\" or \"work_phone\":\n\ncase \"title\",\"phone\",\"address\",\"e_mail\",\"work_phone\":\n"
},
{
"answer_id": 74401009,
"author": "Palle Due",
"author_id": 5516339,
"author_profile": "https://Stackoverflow.com/users/5516339",
"pm_score": 1,
"selected": false,
"text": "if (!string.IsNullOrEmpty(dict[\"title\"])\n _trp.Name = ___ANY_METHOD___(dict[\"title\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"phone\"])\n _trp.Phone = ___ANY_METHOD___(dict[\"phone\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"address\"])\n _trp.Address = ___ANY_METHOD___(dict[\"address\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"e_mail\"])\n _trp.Email = ___ANY_METHOD___(dict[\"e_mail\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"work_phone\"])\n _trp.WorkPhone = ___ANY_METHOD___(dict[\"work_phone\"])[0].ToString();\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74398999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20336151/"
] |
74,399,030 | <p>I am working on the Electron app and to build executables, I'm using <a href="https://www.electron.build/cli" rel="nofollow noreferrer">electron-builder</a></p>
<p>I've the following environment:</p>
<ul>
<li>Electron-Builder Version: ^23.6.0,</li>
<li>Node Version: v14.21.1</li>
<li>Electron Version: ^10.1.5</li>
<li>Electron Type (current, beta, nightly): Current</li>
<li>Target: Windows</li>
</ul>
<p>I've installed Python 3.11, node-gyp v8.4.0 (Latest 9.3 was giving error of <code>gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp</code> so rolled backed the version), Microsoft Visual Studio 2022 and MS VS Build tools 2022 installed.
Also added python to the environment variable and VS to the npm config.</p>
<p>I'm getting below error:</p>
<pre><code>> zinniax-chathub@2.7.0 build-installer D:\CodeMaster\ZinniaX-Chat-Frontend
> electron-builder
• electron-builder version=23.6.0 os=10.0.22621
• loaded configuration file=package.json ("build" field)
• writing effective config file=zinniax-chathub-setup\builder-effective-config.yaml
• rebuilding native dependencies dependencies=bufferutil@4.0.7, utf-8-validate@5.0.10 platform=win32 arch=x64
• packaging platform=win32 arch=x64 electron=10.4.7 appOutDir=zinniax-chathub-setup\win-unpacked
• rebuilding native dependencies dependencies=bufferutil@4.0.7, utf-8-validate@5.0.10 platform=win32 arch=ia32
⨯ cannot execute cause=exit status 1
out=
> bufferutil@4.0.7 install D:\CodeMaster\ZinniaX-Chat-Frontend\node_modules\bufferutil
> node-gyp-build
errorOut=gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2017
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS checking VS2022 (17.4.33103.184) found at:
gyp ERR! find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v143
gyp ERR! find VS - missing any Windows SDK
gyp ERR! find VS checking VS2022 (17.4.33103.184) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
gyp ERR! find VS - found "Visual Studio C++ core features"
gyp ERR! find VS - found VC++ toolset: v143
gyp ERR! find VS - missing any Windows SDK
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
gyp ERR! stack at C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\find-visualstudio.js:75:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
gyp ERR! stack at C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\find-visualstudio.js:71:14
gyp ERR! stack at C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\find-visualstudio.js:384:16
gyp ERR! stack at C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack at C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack at ChildProcess.exithandler (child_process.js:390:5)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at maybeClose (internal/child_process.js:1088:16)
gyp ERR! System Windows_NT 10.0.22621
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\faiza\\AppData\\Roaming\\nvm\\v14.21.1\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\CodeMaster\ZinniaX-Chat-Frontend\node_modules\bufferutil
gyp ERR! node -v v14.21.1
gyp ERR! node-gyp -v v8.4.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bufferutil@4.0.7 install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bufferutil@4.0.7 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\faiza\AppData\Roaming\npm-cache\_logs\2022-11-11T06_57_00_232Z-debug.log
command='C:\Program Files\nodejs\node.exe' 'C:\Users\faiza\AppData\Roaming\nvm\v14.21.1\node_modules\npm\bin\npm-cli.js' rebuild bufferutil@4.0.7 utf-8-validate@5.0.10
workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zinniax-chathub@2.7.0 build-installer: `electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the zinniax-chathub@2.7.0 build-installer script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\faiza\AppData\Roaming\npm-cache\_logs\2022-11-11T06_57_00_312Z-debug.log
</code></pre>
<p>I tried various solutions:</p>
<ul>
<li>Deleted node-module and re-install</li>
<li>Reinstall node-gpy globally</li>
<li>npm update and npm install</li>
<li>Installed Visual Studio build tools</li>
<li>Tried with Python 2.7, 3.x, and win store python version</li>
<li>VS Build tools 2022, VS Community 2022</li>
</ul>
<p>But nothing works for me. This issue occurred after I formatted my laptop. Earlier it was working fine</p>
| [
{
"answer_id": 74400008,
"author": "Hady_Khann",
"author_id": 14682350,
"author_profile": "https://Stackoverflow.com/users/14682350",
"pm_score": -1,
"selected": false,
"text": "case \"title\" or \"phone\" or \"address\" or \"e_mail\" or \"work_phone\":\n\ncase \"title\",\"phone\",\"address\",\"e_mail\",\"work_phone\":\n"
},
{
"answer_id": 74401009,
"author": "Palle Due",
"author_id": 5516339,
"author_profile": "https://Stackoverflow.com/users/5516339",
"pm_score": 1,
"selected": false,
"text": "if (!string.IsNullOrEmpty(dict[\"title\"])\n _trp.Name = ___ANY_METHOD___(dict[\"title\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"phone\"])\n _trp.Phone = ___ANY_METHOD___(dict[\"phone\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"address\"])\n _trp.Address = ___ANY_METHOD___(dict[\"address\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"e_mail\"])\n _trp.Email = ___ANY_METHOD___(dict[\"e_mail\"])[0].ToString();\nif (!string.IsNullOrEmpty(dict[\"work_phone\"])\n _trp.WorkPhone = ___ANY_METHOD___(dict[\"work_phone\"])[0].ToString();\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5875983/"
] |
74,399,033 | <p>I've a C++ program running in a docker container. I want to reboot container via my program but I cannot.</p>
<p>Dockerfile:</p>
<pre><code>FROM gcc
WORKDIR /client
COPY . .
RUN apt-get update && apt-get install qt5-qmake qtbase5-dev libmosquitto-dev -y
RUN qmake mainapp.pro && make
RUN chmod +x docker-entrypoint.sh
</code></pre>
<p>docker-entrypoint.sh</p>
<pre><code>#!/bin/bash
./mainapp -e
</code></pre>
<p>Here is my reboot function (cleared from unnecessary codes):</p>
<pre><code> Logger::getInstance()->write(QString("Sync"));
sync();
Logger::getInstance()->write(QString("Setuid"));
setuid(0);
Logger::getInstance()->write(QString("RB_AUTOBOOT"));
reboot(RB_AUTOBOOT);
Logger::getInstance()->write(QString("Reboot"));
system("reboot");
</code></pre>
<p>I can see ALL the outputs and then it prints an error message. Here is the error message:</p>
<pre><code>System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.
</code></pre>
<p>I tried to reboot from container but it doesn't work as well:</p>
<pre><code>root@93501f6d7fc8:/client# reboot
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Failed to talk to init daemon.
root@93501f6d7fc8:/client# shutdown -r
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
</code></pre>
<p>I've searched this problem and tried most of the suggestions but they didn't solved my problem.</p>
<p>I am open to all your ideas and suggestions.</p>
| [
{
"answer_id": 74400137,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 2,
"selected": false,
"text": "system(\"reboot\")"
},
{
"answer_id": 74401467,
"author": "Syrenthia",
"author_id": 3944303,
"author_profile": "https://Stackoverflow.com/users/3944303",
"pm_score": 2,
"selected": true,
"text": " privileged: true\n restart: always\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3944303/"
] |
74,399,056 | <p><strong>Want to do</strong></p>
<p>I want to make checkbox with <a href="https://i.stack.imgur.com/eYXDO.png" rel="nofollow noreferrer">4 patterns</a>.
To achieve this, I want to know,</p>
<p>① How to change the color of check.</p>
<p>② How to change the color of frame border of checkbox.</p>
<p>I already tried this code and changed the background's color. However it doesn't work enough to achieve what I want.</p>
<pre><code>//change the color of background in a checkbox
android:buttonTint="#ffffff"
</code></pre>
| [
{
"answer_id": 74401169,
"author": "zaifrun",
"author_id": 324975,
"author_profile": "https://Stackoverflow.com/users/324975",
"pm_score": 0,
"selected": false,
"text": " <CheckBox\n android:layout_width=\"60dp\"\n android:layout_height=\"60dp\"\n android:button=\"@null\"\n android:id=\"@+id/checkbox\"\n android:background=\"?android:attr/listChoiceIndicatorMultiple\"\n android:colorAccent=\"@color/checkboxcolor\"\n android:buttonTint=\"@color/checkboxcolor\" />\n"
},
{
"answer_id": 74442738,
"author": "Jessie Zhang -MSFT",
"author_id": 10308336,
"author_profile": "https://Stackoverflow.com/users/10308336",
"pm_score": 2,
"selected": true,
"text": "android:button"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20229243/"
] |
74,399,059 | <pre><code>public class Solution {
public static String[] combineAllStrings(String[] s1, String[] s2) {
int a=s1.length*s2.length;
String[] str1= new String[a];
String str2="";
for(int i=0;i<s1.length;i++)
{
for(int j=0;j<s2.length;j++)
{
str2=s1[i]+s2[j];
}
}
return str2;
}
</code></pre>
<p>How can i store the result in an array and return it.</p>
<p>Hint: Use nested loops to iterate through the two given arrays and generate the combinations.</p>
<p>Hint: Initialize an output array and keep adding the combined strings in it. Finally, return this array.</p>
<p>Sample Input 1
["a", "c", "e"]</p>
<p>["b", "d", "f"]</p>
<p>Sample Output 1
["ab", "ad", "af", "cb", "cd", "cf", "eb", "ed", "ef"]</p>
<p>Explanation 1
We get "ab", "ad", "af" by combining a with b, d and f. Similarly all other elements are combined</p>
| [
{
"answer_id": 74401169,
"author": "zaifrun",
"author_id": 324975,
"author_profile": "https://Stackoverflow.com/users/324975",
"pm_score": 0,
"selected": false,
"text": " <CheckBox\n android:layout_width=\"60dp\"\n android:layout_height=\"60dp\"\n android:button=\"@null\"\n android:id=\"@+id/checkbox\"\n android:background=\"?android:attr/listChoiceIndicatorMultiple\"\n android:colorAccent=\"@color/checkboxcolor\"\n android:buttonTint=\"@color/checkboxcolor\" />\n"
},
{
"answer_id": 74442738,
"author": "Jessie Zhang -MSFT",
"author_id": 10308336,
"author_profile": "https://Stackoverflow.com/users/10308336",
"pm_score": 2,
"selected": true,
"text": "android:button"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20475414/"
] |
74,399,100 | <p>base class: since my ts file handling multiple feature's i am splitting them.</p>
<pre><code> constructor(
) {
super(MatDialog);
}
</code></pre>
<p>error: <code>Argument of type 'typeof MatDialog' is not assignable to parameter of type 'MatDialog'.</code></p>
<p>super class:</p>
<pre><code>export class AddClicnicComponent {
popTableSchema;
tableSchema;
@ViewChild('popupTemp', { static: true })
popupTemp: TemplateRef<HTMLAllCollection>;
constructor(public dialog: MatDialog) {
console.log('i am called by super');
}
handleAddClinic() {
this.popTableSchema = { ...this.tableSchema };
this.openDialog(this.popupTemp);
}
openDialog(templateRef: TemplateRef<HTMLAllCollection>) {
const dialogRef = this.dialog.open(templateRef);
dialogRef.afterClosed().subscribe((result) => {
console.log(`Dialog result: ${result}`);
});
}
}
</code></pre>
<p>what is the exact params i need to send with super? can't i avoid the params? or what is the right way? needs the help.</p>
| [
{
"answer_id": 74399226,
"author": "jitender",
"author_id": 5621827,
"author_profile": "https://Stackoverflow.com/users/5621827",
"pm_score": 2,
"selected": true,
"text": "MatDialog"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/218349/"
] |
74,399,126 | <p>Javascript event Listeners are not working on updating the DOM.</p>
<p>**HTML CODE:
**</p>
<pre><code>
<div class="task-list">
</div>
</code></pre>
<p>**JAVASCRIPT CODE: **</p>
<pre><code>function showList(num) {
const taskBox = document.querySelector('.task-list');
let listHtml = "";
for(let i =1;i<=num;i++){
listHtml += `
<li class="list-item">Hello ${i}</li>
`;
}
taskBox.innerHTML = listHtml;
}
showList(5);
const listItem = document.querySelectorAll('.list-item');
listItem.forEach((item) => {
item.addEventListener('click', (e) => {
console.log(e.target.innerText);
showList(4);
});
});
</code></pre>
<p>With this code event Listener just working once. After that it is not working and not even showing error. So why this is happening. How to udpation of the DOM affecting eventlistener exactly.</p>
<p>I have faced this problem multiple times, I solved this by using <code>onclick()</code> function on each elmeent, but i never got solution of why it is not working in this way.</p>
| [
{
"answer_id": 74399197,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "showList()"
},
{
"answer_id": 74399240,
"author": "Muhammad Muflih",
"author_id": 11726761,
"author_profile": "https://Stackoverflow.com/users/11726761",
"pm_score": 0,
"selected": false,
"text": "showList(5);\n"
},
{
"answer_id": 74399328,
"author": "ray",
"author_id": 636077,
"author_profile": "https://Stackoverflow.com/users/636077",
"pm_score": 0,
"selected": false,
"text": "function showList(num) {\n const taskBox = document.querySelector('.task-list'); \n let listHtml = \"\";\n \n for(let i =1;i<=num;i++){\n listHtml += `<li class=\"list-item\">Hello ${i}</li>`;\n }\n\n taskBox.innerHTML = listHtml;\n}\n\n// listen on the container and use the\n// event to figure out what was clicked\n// instead of adding a listener on every\n// child.\ndocument.querySelector('.task-list').addEventListener(\n 'click',\n (e) => { console.log(e.target.innerText) }\n)\n\nshowList(5);"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20475440/"
] |
74,399,149 | <p>I'm trying to find a glob that I can use with <code>tar</code> to match all files and folders, including hidden files in the current directory. I don't want to include the parent directory. I need my tar not have anything leading before the files. I also can't use <code>shopt</code></p>
<p>I'm using a format similar to</p>
<pre><code>tar --ignore-failed-read -czvf ../archive.tar.gz .[^.]* *
</code></pre>
<p>The <code>--ignore-failed-read</code> is required if there are NO hidden files because the first glob will return an error when it doesn't match anything.</p>
<p>I'm considering the following types of names for hidden files:</p>
<ul>
<li><code>.a</code></li>
<li><code>.aa</code></li>
<li><code>..a</code></li>
</ul>
<p>I've found a few examples of globs that will work but here are the problems I have:</p>
<p><code>.[^.]*</code></p>
<ul>
<li>gets files <code>.a</code> and <code>.aa</code> but misses <code>..a</code></li>
</ul>
<p><code>.??*</code></p>
<ul>
<li>gets <code>.aa</code> and <code>..a</code> but misses <code>.a</code></li>
</ul>
<ol>
<li>Any ideas here?</li>
<li>Is there any way I can remove <code>--ignore-failed-read</code></li>
</ol>
| [
{
"answer_id": 74399197,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "showList()"
},
{
"answer_id": 74399240,
"author": "Muhammad Muflih",
"author_id": 11726761,
"author_profile": "https://Stackoverflow.com/users/11726761",
"pm_score": 0,
"selected": false,
"text": "showList(5);\n"
},
{
"answer_id": 74399328,
"author": "ray",
"author_id": 636077,
"author_profile": "https://Stackoverflow.com/users/636077",
"pm_score": 0,
"selected": false,
"text": "function showList(num) {\n const taskBox = document.querySelector('.task-list'); \n let listHtml = \"\";\n \n for(let i =1;i<=num;i++){\n listHtml += `<li class=\"list-item\">Hello ${i}</li>`;\n }\n\n taskBox.innerHTML = listHtml;\n}\n\n// listen on the container and use the\n// event to figure out what was clicked\n// instead of adding a listener on every\n// child.\ndocument.querySelector('.task-list').addEventListener(\n 'click',\n (e) => { console.log(e.target.innerText) }\n)\n\nshowList(5);"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/836450/"
] |
74,399,187 | <p>like consider the following python code,</p>
<pre><code>
n = 4
if n>3 :
n = 5
if n>2 :
n = 6
if n>1 :
n = 4
</code></pre>
<p>How to achieve this in haskell??</p>
<pre><code>let n = 4
main :: IO()
main = do
if n>3 then let n = 5
if n>2 then let n = 6
if n>1 then let n = 4
</code></pre>
<p>Tried this but gives an error, looking for some modifications</p>
| [
{
"answer_id": 74399197,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "showList()"
},
{
"answer_id": 74399240,
"author": "Muhammad Muflih",
"author_id": 11726761,
"author_profile": "https://Stackoverflow.com/users/11726761",
"pm_score": 0,
"selected": false,
"text": "showList(5);\n"
},
{
"answer_id": 74399328,
"author": "ray",
"author_id": 636077,
"author_profile": "https://Stackoverflow.com/users/636077",
"pm_score": 0,
"selected": false,
"text": "function showList(num) {\n const taskBox = document.querySelector('.task-list'); \n let listHtml = \"\";\n \n for(let i =1;i<=num;i++){\n listHtml += `<li class=\"list-item\">Hello ${i}</li>`;\n }\n\n taskBox.innerHTML = listHtml;\n}\n\n// listen on the container and use the\n// event to figure out what was clicked\n// instead of adding a listener on every\n// child.\ndocument.querySelector('.task-list').addEventListener(\n 'click',\n (e) => { console.log(e.target.innerText) }\n)\n\nshowList(5);"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20475453/"
] |
74,399,196 | <p>I have a list of elements <code>mylist = [1, 2, 3, 4, 5, 6, 7, 8]</code> and would like to iteratively:</p>
<ol>
<li>copy the list</li>
<li>pop the first element of the copied list</li>
<li>and append it to the end of the copied list</li>
<li>repeat this for the next row, etc.</li>
</ol>
<p>Desired output:</p>
<pre><code>index A B C D E F G H
0 1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 1
2 3 4 5 6 7 8 1 2
3 4 5 6 7 8 1 2 3
4 5 6 7 8 1 2 3 4
5 6 7 8 1 2 3 4 5
6 7 8 1 2 3 4 5 6
7 8 1 2 3 4 5 6 7
</code></pre>
<p>I suspect a <code>for</code> loop is needed but am having trouble iteratively generating rows based on the prior row.</p>
| [
{
"answer_id": 74399197,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "showList()"
},
{
"answer_id": 74399240,
"author": "Muhammad Muflih",
"author_id": 11726761,
"author_profile": "https://Stackoverflow.com/users/11726761",
"pm_score": 0,
"selected": false,
"text": "showList(5);\n"
},
{
"answer_id": 74399328,
"author": "ray",
"author_id": 636077,
"author_profile": "https://Stackoverflow.com/users/636077",
"pm_score": 0,
"selected": false,
"text": "function showList(num) {\n const taskBox = document.querySelector('.task-list'); \n let listHtml = \"\";\n \n for(let i =1;i<=num;i++){\n listHtml += `<li class=\"list-item\">Hello ${i}</li>`;\n }\n\n taskBox.innerHTML = listHtml;\n}\n\n// listen on the container and use the\n// event to figure out what was clicked\n// instead of adding a listener on every\n// child.\ndocument.querySelector('.task-list').addEventListener(\n 'click',\n (e) => { console.log(e.target.innerText) }\n)\n\nshowList(5);"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12708740/"
] |
74,399,265 | <p><b>Hi All</b><br>
First data:<br></p>
<pre><code> let NewDivForGame_0 = document.createElement('div');
let NewDivForGame_1 = document.createElement('div');
let NewDivForGame_2 = document.createElement('div');
</code></pre>
<p>and so on...12<br>
Next:<br></p>
<pre><code> NewDivForGame_0.id = 'Key';
NewDivForGame_1.id = 'string_1';
NewDivForGame_2.id = '1a1';
</code></pre>
<p>and so on...12<br>
Next: append. <br>
Next:<br></p>
<pre><code> for (i=0;i<=12;i++){
document.getElementById("NewDivForGame_"+i.id).style.width ="35px"; //ERROR
document.getElementById("NewDivForGame_"+[i].id).style.height= "35px"; //ERROR
document.getElementById("NewDivForGame_"+[i].id).style.backgroundColor = "blue";
console.log('Create size div run #'+i);
</code></pre>
<p>It doesn't work. Help me please. <b>Please write a solution.</b></p>
<p>tried:<br>
1)<code>document.getElementById("NewDivForGame_"+i.id).style.width = "35px"; //ERROR</code>
2)<code>document.getElementById("NewDivForGame_"+[i].id).style.width = "35px"; //ERROR</code><br>
3)<br></p>
<pre><code>let DetectPer = "NewDivForGame_";
document.getElementById(DetectPer+i.id).style.width = "35px"; //ERROR
</code></pre>
<p>It doesn't work. Help me please. <b>Please write a solution.</b></p>
| [
{
"answer_id": 74399492,
"author": "mplungjan",
"author_id": 295783,
"author_profile": "https://Stackoverflow.com/users/295783",
"pm_score": 1,
"selected": false,
"text": "window[\"NewDivForGame_\"+i].id\n"
},
{
"answer_id": 74399881,
"author": "Daedalus",
"author_id": 785241,
"author_profile": "https://Stackoverflow.com/users/785241",
"pm_score": 1,
"selected": true,
"text": " for (i=0;i<=12;i++){\n document.getElementById(\"NewDivForGame_\"+i.id).style.width =\"35px\"; //ERROR\n document.getElementById(\"NewDivForGame_\"+[i].id).style.height= \"35px\"; //ERROR\n document.getElementById(\"NewDivForGame_\"+[i].id).style.backgroundColor = \"blue\";\n console.log('Create size div run #'+i);\n ...\n"
},
{
"answer_id": 74399912,
"author": "eRtuSa",
"author_id": 16422168,
"author_profile": "https://Stackoverflow.com/users/16422168",
"pm_score": 1,
"selected": false,
"text": "{\n const newDivForGame = [];\n for (let i = 0; i < 12; ++i) {\n newDivForGame.push(document.createElement('div'));\n newDivForGame[i].id = `key${i}`;\n document.body.appendChild(newDivForGame[I]);\n }\n\n for (const elem of newDivForGame) {\n elem.style.width = '35px';\n elem.style.height = '35px';\n elem.style.background = 'blue';\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20472492/"
] |
74,399,275 | <p>Trying to use findUnique on my model project returns this error -></p>
<pre><code>Type '{ client_key: any; }' is not assignable to type 'ProjectWhereUniqueInput'.
Object literal may only specify known properties, and 'client_key' does not exist in type 'ProjectWhereUniqueInput'.ts(2322)
index.d.ts(4250, 5): The expected type comes from property 'where' which is declared here on type '{ rejectOnNotFound?: RejectOnNotFound | undefined; select?: ProjectSelect | null | undefined; include?: ProjectInclude | null | undefined; where: ProjectWhereUniqueInput; }'
</code></pre>
<p>.
I understand to use the findUnique I need to add the @unique identifier however Im stuck on this now. Heres the model and func call. Any help?</p>
<pre><code>model Project {
id String @id
created DateTime
org Organization @relation(fields: org_id, references: id)
org_id String
content_title String
content_id String?
client_key String @unique
has_data Boolean
}
const proj = await prisma.project.create({
data: {
id: '9999',
created: time,
org_id: '8888',
content_title: 'content',
client_key: 'client_key',
has_data: true,
},
});
const project = await prisma.project.findUnique({
where:{
client_key: 'client_key',
}
});
</code></pre>
| [
{
"answer_id": 74399492,
"author": "mplungjan",
"author_id": 295783,
"author_profile": "https://Stackoverflow.com/users/295783",
"pm_score": 1,
"selected": false,
"text": "window[\"NewDivForGame_\"+i].id\n"
},
{
"answer_id": 74399881,
"author": "Daedalus",
"author_id": 785241,
"author_profile": "https://Stackoverflow.com/users/785241",
"pm_score": 1,
"selected": true,
"text": " for (i=0;i<=12;i++){\n document.getElementById(\"NewDivForGame_\"+i.id).style.width =\"35px\"; //ERROR\n document.getElementById(\"NewDivForGame_\"+[i].id).style.height= \"35px\"; //ERROR\n document.getElementById(\"NewDivForGame_\"+[i].id).style.backgroundColor = \"blue\";\n console.log('Create size div run #'+i);\n ...\n"
},
{
"answer_id": 74399912,
"author": "eRtuSa",
"author_id": 16422168,
"author_profile": "https://Stackoverflow.com/users/16422168",
"pm_score": 1,
"selected": false,
"text": "{\n const newDivForGame = [];\n for (let i = 0; i < 12; ++i) {\n newDivForGame.push(document.createElement('div'));\n newDivForGame[i].id = `key${i}`;\n document.body.appendChild(newDivForGame[I]);\n }\n\n for (const elem of newDivForGame) {\n elem.style.width = '35px';\n elem.style.height = '35px';\n elem.style.background = 'blue';\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10792278/"
] |
74,399,276 | <p>Whenever I refresh the page, I instantly logout and localstorage lose all it's data. How to fix that?</p>
<pre><code> useEffect(() => {
setAuthToken(window.localStorage.getItem('authToken'));
setAuthTokenType(window.localStorage.getItem('authTokenType'))
setUsername(window.localStorage.getItem('username'))
setUserId(window.localStorage.getItem('userId'))
}, [])
useEffect(() => {
authToken
? window.localStorage.setItem('authToken', authToken)
: window.localStorage.removeItem('authToken')
authTokenType
? window.localStorage.setItem('authTokenType', authTokenType)
: window.localStorage.removeItem('authTokenType')
username
? window.localStorage.setItem('username', username)
: window.localStorage.removeItem('username')
userId
? window.localStorage.setItem('userId', userId)
: window.localStorage.removeItem('userId')
}, [authToken, authTokenType, userId, username])
</code></pre>
| [
{
"answer_id": 74399329,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 2,
"selected": true,
"text": "useEffect"
},
{
"answer_id": 74405087,
"author": "nofamenoname",
"author_id": 18948634,
"author_profile": "https://Stackoverflow.com/users/18948634",
"pm_score": 0,
"selected": false,
"text": " useEffect(() => {\n setAuthToken(window.localStorage.getItem('authToken'));\n setAuthTokenType(window.localStorage.getItem('authTokenType'));\n setUserId(window.localStorage.getItem('userId'));\n setUsername(window.localStorage.getItem('username'))\n }, [])\n\n useEffect(() => {\n authToken && window.localStorage.setItem('authToken', authToken)\n authTokenType && window.localStorage.setItem('authTokenType', authTokenType)\n userId && window.localStorage.setItem('userId', userId)\n username && window.localStorage.setItem('username', username)\n }, [authToken, authTokenType, userId])\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18948634/"
] |
74,399,288 | <p>I am trying to center a div that has a few inner div with some classes.
For example:</p>
<pre><code><div class="one">
<div class="two">
<article class="three">
...
</article>
</div>
</div>
</code></pre>
<p>Assume we don't know what classes <code>one</code>, <code>two</code>, and <code>three</code> are. Is it possible to center horizontally <code><div class="one"></code> and everything inside?</p>
<p>I have tried for example <code>text-align: center;</code> as style but it didn't work.</p>
<p>UPDATE:</p>
<p>Actually, tacoshy's recommendation worked, but it is not exactly what I want. Please see these drawings:</p>
<p>This is before applying tacoshy's recommendation:</p>
<p><a href="https://i.stack.imgur.com/179K8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/179K8.jpg" alt="enter image description here" /></a></p>
<p>This is after applying his recommendation:</p>
<p><a href="https://i.stack.imgur.com/iGMiP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iGMiP.jpg" alt="enter image description here" /></a></p>
<p>And this is what I want:</p>
<p><a href="https://i.stack.imgur.com/WYRmc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WYRmc.jpg" alt="enter image description here" /></a></p>
<p>Is is possible to make the books closer together at the center?</p>
| [
{
"answer_id": 74399329,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 2,
"selected": true,
"text": "useEffect"
},
{
"answer_id": 74405087,
"author": "nofamenoname",
"author_id": 18948634,
"author_profile": "https://Stackoverflow.com/users/18948634",
"pm_score": 0,
"selected": false,
"text": " useEffect(() => {\n setAuthToken(window.localStorage.getItem('authToken'));\n setAuthTokenType(window.localStorage.getItem('authTokenType'));\n setUserId(window.localStorage.getItem('userId'));\n setUsername(window.localStorage.getItem('username'))\n }, [])\n\n useEffect(() => {\n authToken && window.localStorage.setItem('authToken', authToken)\n authTokenType && window.localStorage.setItem('authTokenType', authTokenType)\n userId && window.localStorage.setItem('userId', userId)\n username && window.localStorage.setItem('username', username)\n }, [authToken, authTokenType, userId])\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/755000/"
] |
74,399,312 | <p>How to select the number in a text?</p>
<p>I want to convert the Latin number and English numbers in the text. For example, in the text "……one telephone……". I want to change the English number "one" into "1", but I do not want to change "telephone" into "teleph1".</p>
<p>Is it right to select only the number with a space ahead of the word and a space after it? How to do it?</p>
| [
{
"answer_id": 74399329,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 2,
"selected": true,
"text": "useEffect"
},
{
"answer_id": 74405087,
"author": "nofamenoname",
"author_id": 18948634,
"author_profile": "https://Stackoverflow.com/users/18948634",
"pm_score": 0,
"selected": false,
"text": " useEffect(() => {\n setAuthToken(window.localStorage.getItem('authToken'));\n setAuthTokenType(window.localStorage.getItem('authTokenType'));\n setUserId(window.localStorage.getItem('userId'));\n setUsername(window.localStorage.getItem('username'))\n }, [])\n\n useEffect(() => {\n authToken && window.localStorage.setItem('authToken', authToken)\n authTokenType && window.localStorage.setItem('authTokenType', authTokenType)\n userId && window.localStorage.setItem('userId', userId)\n username && window.localStorage.setItem('username', username)\n }, [authToken, authTokenType, userId])\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20423891/"
] |
74,399,364 | <p>I am new to Intel VTune. So, I have a general doubt.</p>
<p>I am trying to profile an application with VTune and would like to know the placement of VTune core.</p>
<p>How many cores does VTune take up while profiling an application?</p>
<p>Does it depend on OS?</p>
| [
{
"answer_id": 74407963,
"author": "Peter Cordes",
"author_id": 224132,
"author_profile": "https://Stackoverflow.com/users/224132",
"pm_score": 3,
"selected": true,
"text": "perf record"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19205740/"
] |
74,399,372 | <p>Here, I am passing Url as an prop to display uploaded files in edit Modal. All I want is, to not show any attachment if Url is empty. I can srill see empty attachments like shown in image :</p>
<p><a href="https://i.stack.imgur.com/dkzu1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dkzu1.png" alt="enter image description here" /></a></p>
<pre><code>export const FileUploader = ({ label, Url, setUrl, editMode }) => {
console.log("Url", Url);
const props = {
maxCount: 1,
onChange(info) {
if (info.file.status !== "uploading") {
console.log(info.file, info.fileList);
}
},
fileList: [
Url ? {
uid: "1",
name: label + ".png",
status: "done",
response: '{"status": "success"}',
url: Url,
} : "",
],
};
</code></pre>
| [
{
"answer_id": 74401921,
"author": "Andy Refuerzo",
"author_id": 1846040,
"author_profile": "https://Stackoverflow.com/users/1846040",
"pm_score": 1,
"selected": false,
"text": "<Radio value={\"True\"} checked={hasOutdoorSpace}>True</Radio>\n<Radio value={\"False\"} checked={!hasOutdoorSpace}>False</Radio>\n"
},
{
"answer_id": 74434254,
"author": "Saeed Mansouri",
"author_id": 9229280,
"author_profile": "https://Stackoverflow.com/users/9229280",
"pm_score": 0,
"selected": false,
"text": "fileList = [\"\"]"
},
{
"answer_id": 74449436,
"author": "Anchal Gupta",
"author_id": 14326998,
"author_profile": "https://Stackoverflow.com/users/14326998",
"pm_score": 1,
"selected": true,
"text": "showUploadList"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14326998/"
] |
74,399,373 | <p>I am trying to handle a C++ DLL which in turn connects to a C# DLL.
My problem is when I want to send or receive arrays between C++ and C# DLLs.
I have created the C# DLL and C++ DLL, so I can modified all the files. Within the C# DLL, I must necessarily have an array of <code>string</code> an another of <code>double</code> because that is where I make use of other functions unrelated to this question. (The declaration of the function that I have to use in C# DLL is <code>Error SetMultipleChannelValues(string[] names,double[] values)</code>.</p>
<p>I am using CLI in Visual Studio 2015 to compile and generate all DLLs and projects.</p>
<p><strong>Here it is the C# code that I have:</strong></p>
<pre><code>public static Error SetMultipleSignals(string[] signals, double[] values)
{
Error error = null;
error = workspace.SetMultipleChannelValues(signals, values);
if (error.IsError)
Console.WriteLine("[DLL] Error in SetMultipleChannelValues(). Code: " + error.Code + ". Message: " + error.Message);
return error;
}
</code></pre>
<p><strong>Here it is the C++ code that I have:</strong></p>
<pre><code>bool setMultipleSignals(double* setSignal_values)
{
array<double, DEFAULT_SETSIGNAL_SIZE> values;
for (int index = 0 ; index < DEFAULT_SETSIGNAL_SIZE ;index++)
{
values[index] = *(setSignal_values + index);
}
if (!veristand_wrapper_cs::VeriStand_dll::SetMultipleSignals(setSignals_path, values)) // This is the call to C# function
return true;
else
return false;
}
</code></pre>
<p><strong>Here it is the C++ header that I have:</strong></p>
<pre><code>#pragma once
#define VERISTAND_WRAPPER_CPP __declspec(dllexport)
#include <string>
#include <iostream>
#include <windows.h>
#include <array>
using namespace std;
using namespace System;
using System::Runtime::InteropServices::Marshal;
#using "veristand_wrapper_cs.dll" // This is the C# DLL
#define DEFAULT_SETSIGNAL_SIZE 100
extern "C" VERISTAND_WRAPPER_CPP bool setMultipleSignals(double* setSignal_values); // This function is called from API C++
</code></pre>
<p>I pass the double array with a pointer to <code>double</code> as a parameter from my C++ application, but I have to pass to C# DLL an array, so I have tried to build a whole array of double before pass it.
The array <code>setSignals_path</code> is created as a global array in this C++ DLL as <code>array<String^, DEFAULT_SETSIGNAL_SIZE> setSignals_path;</code>.</p>
<p>The problem is that the call of C# function provides me an error that says that I can not call the function with these arguments. It expects <code>array<System::String^> ^signals, array<double> ^values</code> and I am passing <code>std::array<System::String^, 100Ui64>, std::array<double, 100Ui64></code></p>
<p>The concept of my idea is simple. From the C++ API, pass a pointer to the array of doubles, so that the function of my DLL in C++ passes the array of doubles and strings to the DLL of C#, and it returns the array of modified doubles to be able to indicate to the API from C++ that the values have been modified from that memory address.</p>
<p>Would anyone know how to approach this problem or how to do it in some other way to make it work?</p>
| [
{
"answer_id": 74401921,
"author": "Andy Refuerzo",
"author_id": 1846040,
"author_profile": "https://Stackoverflow.com/users/1846040",
"pm_score": 1,
"selected": false,
"text": "<Radio value={\"True\"} checked={hasOutdoorSpace}>True</Radio>\n<Radio value={\"False\"} checked={!hasOutdoorSpace}>False</Radio>\n"
},
{
"answer_id": 74434254,
"author": "Saeed Mansouri",
"author_id": 9229280,
"author_profile": "https://Stackoverflow.com/users/9229280",
"pm_score": 0,
"selected": false,
"text": "fileList = [\"\"]"
},
{
"answer_id": 74449436,
"author": "Anchal Gupta",
"author_id": 14326998,
"author_profile": "https://Stackoverflow.com/users/14326998",
"pm_score": 1,
"selected": true,
"text": "showUploadList"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10958195/"
] |
74,399,407 | <p>I have 2 separate Docker containers: Node app and Nginx running locally on a Windows machine. Both containers are up and running but I am unable to access my Node app via reverse proxy that I have set up in Nginx:</p>
<p>Node app container is ruuning using below command:</p>
<pre><code>docker run -p 2020:2020 --name nodeapp myimage:1.0
</code></pre>
<p>Node app is accessible at <code>localhost:2020</code> url</p>
<p>For the Nginx container I am using</p>
<pre><code>docker run -p 7070:80 --name nginx mynginx:1.0
</code></pre>
<p>Nginx is accessible at <code>localhost:7070</code></p>
<p>Below is my nginx configuration file:</p>
<p><strong>default.conf</strong></p>
<pre><code>upstream nodeserver {
server 127.0.0.1:2020;
}
server {
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded_Proto $scheme;
proxy_pass http://nodeserver;
}
}
</code></pre>
<p>What am I doing wrong?</p>
| [
{
"answer_id": 74401921,
"author": "Andy Refuerzo",
"author_id": 1846040,
"author_profile": "https://Stackoverflow.com/users/1846040",
"pm_score": 1,
"selected": false,
"text": "<Radio value={\"True\"} checked={hasOutdoorSpace}>True</Radio>\n<Radio value={\"False\"} checked={!hasOutdoorSpace}>False</Radio>\n"
},
{
"answer_id": 74434254,
"author": "Saeed Mansouri",
"author_id": 9229280,
"author_profile": "https://Stackoverflow.com/users/9229280",
"pm_score": 0,
"selected": false,
"text": "fileList = [\"\"]"
},
{
"answer_id": 74449436,
"author": "Anchal Gupta",
"author_id": 14326998,
"author_profile": "https://Stackoverflow.com/users/14326998",
"pm_score": 1,
"selected": true,
"text": "showUploadList"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7780102/"
] |
74,399,440 | <p>The method 'toStringAsFixed' can't be unconditionally invoked because the receiver can be 'null'.</p>
<pre><code>amount.toStringAsFixed(2)
</code></pre>
<p>while accessing amount double value with "toStringAsFixed(2)" the result have to be a a double with decimal rounded to 2 digit.</p>
| [
{
"answer_id": 74399478,
"author": "xn69",
"author_id": 20200999,
"author_profile": "https://Stackoverflow.com/users/20200999",
"pm_score": 0,
"selected": false,
"text": "?"
},
{
"answer_id": 74399527,
"author": "Ivo",
"author_id": 1514861,
"author_profile": "https://Stackoverflow.com/users/1514861",
"pm_score": 1,
"selected": false,
"text": "amount"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20200999/"
] |
74,399,441 | <p>How to get the result of all the select queries executed in oracle procedure as the output of the procedure?</p>
<p>I am having n of tables in my database where the table name starts with "test"(for ex. test1, test2, etc.) and all these table have a primary key column, "id" where the value starts from 1. Each table has 10000s of records. I wanted to get the name of all the table with table name starting with "test" and also all the records in the those table in batch wise as the output of the procedure. I have written a procedure, but it is only returning the result of last select query executed by the procedure since I am using cursor. Is there any other alternative for this</p>
<p>My current Procedure:</p>
<pre><code>create or replace PROCEDURE TEST (tablenamecursor out sys_refcursor,mycursorresult out sys_refcursor
)
As
maxx number;
startindex number := 1;
strcountquery clob;
strquery clob;
strquery1 clob;
countt number;
rowcountt number;
batchsize number :=100;
tablenamequery clob;
test clob;
Begin
select count(*) into countt from user_tables where table_name like 'test_%';
loop
exit when (countt=1);
test:='test_'||countt;
tablenamequery := 'SELECT table_name FROM user_tables where table_name = '''||test||'''';
open tablenamecursor for tablenamequery;
strcountquery := 'select count(*) from "'||test||'"';
execute immediate strcountquery into maxx;
loop
exit when (StartIndex>=maxx);
strquery:='SELECT a.*, Row_number() OVER (ORDER BY "id") AS lookup FROM "'||test||'"
a WHERE "id" >='||StartIndex||' and rownum <='||batchsize;
StartIndex:= StartIndex +batchsize;
open mycursorresult for strquery;
End loop;
countt:=countt-1;
End loop;
end;
</code></pre>
<p>Suppose, I have 2 tables(say, test1, test2, test3), then I am getting only, "test1" in tablenamecursor cursor and the last set of 100 records of "test1" in mycursorresult cursor.
But I need all the result of select queries in line no. 19 & 25 in the procedure as the output of my procedure in the same order.</p>
| [
{
"answer_id": 74399478,
"author": "xn69",
"author_id": 20200999,
"author_profile": "https://Stackoverflow.com/users/20200999",
"pm_score": 0,
"selected": false,
"text": "?"
},
{
"answer_id": 74399527,
"author": "Ivo",
"author_id": 1514861,
"author_profile": "https://Stackoverflow.com/users/1514861",
"pm_score": 1,
"selected": false,
"text": "amount"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19735078/"
] |
74,399,490 | <p>I migrated from React Router v5 to v6 following this <a href="https://reactrouter.com/en/main/start/tutorial" rel="nofollow noreferrer">tutorial</a>. I want to test it with <a href="https://testing-library.com/" rel="nofollow noreferrer">react-testing-library</a>, but my old unit tests (using the pattern in <a href="https://testing-library.com/docs/example-react-router/" rel="nofollow noreferrer">this doc</a>) stopped working.</p>
<p>My app with React Router v6 is like this</p>
<pre><code>const router = createBrowserRouter([
{
path: "/",
element: (
<>
<SiteHeader />
<Outlet />
</>
),
errorElement: <NotFound />,
children: [
{ path: "/", element: <Home /> },
{ path: "/posts", element: <Posts /> },
{ path: "/post/:postId", element: <PostPage /> },
],
},
]);
function App() {
return (
<div className="app">
<RouterProvider router={router} />
</div>
);
}
</code></pre>
<p>As you can see, it's using <code>RouterProvider</code> instead of <code>Switch</code>/<code>Route</code> (so I'm confused that this <a href="https://stackoverflow.com/questions/70654872/how-to-test-react-router-v6-outlet-using-testing-library-react">SO question</a> says it's using React Router v6 but it looks so different.).</p>
<p><a href="https://testing-library.com/docs/example-react-router/" rel="nofollow noreferrer">The code in official doc of testing-library</a> is not using <code>RouterProvider</code> either.</p>
<p>I want to test some routing logic like this pseudo code:</p>
<pre><code>renderWithRouter(<App />, "/posts"); // loads /posts page initially
await user.click(screen.getByText("some post title")); // trigger click
expect(getUrl(location)).toEqual("/post/123"); // checks the URL changed correctly
</code></pre>
<p><strong>How can I create a <code>renderWithRouter</code> function like <a href="https://testing-library.com/docs/example-react-router/#reducing-boilerplate" rel="nofollow noreferrer">this</a> with <code>RouterProvider</code>?</strong> Note that <a href="https://testing-library.com/docs/example-react-router/#reducing-boilerplate" rel="nofollow noreferrer">this <code>renderWithRouter</code></a> worked for me when I used React Router v5, but after migrating to v6, it stopped working.</p>
<p>My current dependency versions:</p>
<ul>
<li>"react": "^18.2.0",</li>
<li>"react-dom": "^18.2.0",</li>
<li>"react-router-dom": "^6.4.3",</li>
<li>"@testing-library/jest-dom": "^5.16.5",</li>
<li>"@testing-library/react": "^13.4.0",</li>
<li>"@testing-library/user-event": "^14.4.3",</li>
</ul>
<hr />
<p>I tried this</p>
<pre><code>test("click post goes to /post/:postId", async () => {
render(
<MemoryRouter initialEntries={["/posts"]}>
<App />
</MemoryRouter>,
);
// ...
});
</code></pre>
<p>but I got error</p>
<pre><code>You cannot render a <Router> inside another <Router>. You should never have more than one in your app.
31 | test("click post goes to /post/:postId", async () => {
> 32 | render(
| ^
34 | <MemoryRouter initialEntries={["/posts"]}>
36 | <App />
</code></pre>
| [
{
"answer_id": 74399920,
"author": "Drew Reese",
"author_id": 8690857,
"author_profile": "https://Stackoverflow.com/users/8690857",
"pm_score": 3,
"selected": true,
"text": "react-router-dom@6.4"
},
{
"answer_id": 74411317,
"author": "lzl124631x",
"author_id": 3127828,
"author_profile": "https://Stackoverflow.com/users/3127828",
"pm_score": 0,
"selected": false,
"text": "renderWithRouter"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3127828/"
] |
74,399,510 | <p>so im using <code>xml.etree.ElementTree</code> to read multiple .xmls in a Folder.</p>
<p>i extract the desired Attributes using <code>x.attrib</code> and put those into a variable.</p>
<pre><code>attributes = x.attrib
</code></pre>
<p>The stored information comes in multiple dictonaries:</p>
<pre><code>{'Key1': 'Value1', 'Key2': 'Value2', 'Key3': 'Value3', 'Key4': 'Value4', 'Key5': 'Value_1'}
{'Key1': 'Value1', 'Key2': 'Value2', 'Key3': 'Value3', 'Key4': 'Value4', 'Key5': 'Value_2'}
{'Key1': 'Value1', 'Key2': 'Value2', 'Key3': 'Value3', 'Key4': 'Value4', 'Key5': 'Value_3'}
{'Key1': 'Value1', 'Key2': 'Value2', 'Key3': 'Value3', 'Key4': 'Value4', 'Key5': 'Value_4'}
{'Key1': 'Value1', 'Key2': 'Value2', 'Key3': 'Value3', 'Key4': 'Value4', 'Key5': 'Value_5'}
</code></pre>
<p>Now i've tried to iterate through all of them and putting all Key5 Values into a single List:</p>
<pre><code>li = []
for d in attributes:
li.append(attributes.get("Key5"))
</code></pre>
<p>Current output is:</p>
<pre><code>['Value_5', 'Value_5', 'Value_5', 'Value_5', 'Value_5']
</code></pre>
<p>Output should be:</p>
<pre><code>['Value_1', 'Value_2', 'Value_3', 'Value_4', 'Value_5']
</code></pre>
<p>Full Code for clarity:</p>
<pre><code>import xml.etree.ElementTree as ET
import os
path = "directory/here"
for filenames in os.listdir(path):
if filenames.endswith('.xml'):
fullnames = os.path.join(path, filenames)
tree = ET.parse(fullnames)
root = tree.getroot()
for x in root[2:]:
attributes = x.attrib
l = []
for d in attributes:
l.append(attributes.get("Key5"))
</code></pre>
| [
{
"answer_id": 74399572,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 2,
"selected": false,
"text": "import xml.etree.ElementTree as ET\nimport os\n\npath = \"directory/here\"\n\nfor filenames in os.listdir(path):\n if filenames.endswith('.xml'):\n fullnames = os.path.join(path, filenames)\n tree = ET.parse(fullnames)\n root = tree.getroot()\n l = []\n for x in root[2:]:\n d = x.attrib # <- .attrib method returns a dictionary, not the list\n l.append(d.get(\"Key5\")) # <-- note we are referring to \"d\" here\n print(l)\n"
},
{
"answer_id": 74399680,
"author": "CutePoison",
"author_id": 6224975,
"author_profile": "https://Stackoverflow.com/users/6224975",
"pm_score": 2,
"selected": false,
"text": "x.attrib"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18016558/"
] |
74,399,524 | <pre><code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.scode</groupId>
<artifactId>Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo</name>
<description>Demo projectŌ for Spring Boot</description>
<properties>
<java.version>19</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
</code></pre>
<p>This is my pom.xml file. But when I run the project I have get error like <code>java: package javax.persistance does not exist</code></p>
<p>I am a beginner and can someone help me to solve this issue</p>
<p>I have download javax.persistance jar and import. But it is not works</p>
<p>I try to add hiberate-entitymanager for pom.xml file. But it also not works</p>
<p>I tried to external import hibernate-jpa. It also not works</p>
<p><a href="https://i.stack.imgur.com/n2z2G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n2z2G.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74399572,
"author": "svfat",
"author_id": 2419628,
"author_profile": "https://Stackoverflow.com/users/2419628",
"pm_score": 2,
"selected": false,
"text": "import xml.etree.ElementTree as ET\nimport os\n\npath = \"directory/here\"\n\nfor filenames in os.listdir(path):\n if filenames.endswith('.xml'):\n fullnames = os.path.join(path, filenames)\n tree = ET.parse(fullnames)\n root = tree.getroot()\n l = []\n for x in root[2:]:\n d = x.attrib # <- .attrib method returns a dictionary, not the list\n l.append(d.get(\"Key5\")) # <-- note we are referring to \"d\" here\n print(l)\n"
},
{
"answer_id": 74399680,
"author": "CutePoison",
"author_id": 6224975,
"author_profile": "https://Stackoverflow.com/users/6224975",
"pm_score": 2,
"selected": false,
"text": "x.attrib"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15756097/"
] |
74,399,538 | <p>I need to determine the most frequent character of a list of strings by each index in Python.</p>
<p>Example</p>
<p>list1 = ['one', 'two', 'twin', 'who']</p>
<p>the most frequent character between all the strings at index 0 is 't'
the most frequent character between all the strings at index 1 is 'w'
the most frequent character between all the strings at index 2 is 'o'
the most frequent character between all the strings at index 3 is 'n'(because there is only one character at the index 3</p>
<p>from that I want to create a final string 'twon' which shows the most frequent character of all the strings by each index</p>
<p>how can I perform this on python without importing any library?
thanks</p>
| [
{
"answer_id": 74399710,
"author": "Dmitriy Neledva",
"author_id": 16786350,
"author_profile": "https://Stackoverflow.com/users/16786350",
"pm_score": 0,
"selected": false,
"text": "from collections import Counter\n\nlist1 = ['one', 'two', 'twin', 'who']\n\nidx =0 #t \nprint(Counter(list(zip(*[i for i in list1 if len(i)>3]))[idx]).most_common()[0][0])\n"
},
{
"answer_id": 74400029,
"author": "Hamid Rasti",
"author_id": 11100417,
"author_profile": "https://Stackoverflow.com/users/11100417",
"pm_score": 3,
"selected": true,
"text": "from itertools import zip_longest\n\nlist1 = ['one', 'two', 'twin', 'who']\n\nchars = {}\nfor i, item in enumerate(zip_longest(*list1)):\n set1 = set(item)\n if None in set1:\n set1.remove(None)\n chars[i] = max(set1, key=item.count)\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20347645/"
] |
74,399,574 | <p>I try to send a string array with HttpClient post method to my backend.</p>
<pre><code>getAnnouncementsByIds(ids: string[]): Observable<Announcement[]> {
return this.http.post<Announcement[]>(`${environment.serverUrl}${this.urlGetAnnouncementsByIds}`, ids);
}
</code></pre>
<p>Current error is: Http Status 400 with message "JSON parse error: Cannot deserialize value of type <code>[Ljava.lang.String;</code> from Integer value (token <code>JsonToken.VALUE_NUMBER_INT</code>);</p>
<p>I tried different things to make it work:</p>
<ul>
<li>add the number array as stringified value to HttpParams</li>
<li>add a header with "Content-Type": "application/json"</li>
</ul>
<p>i cant find a solution how to send an array as body in an Http Post request.</p>
<p>Can someone help me? Im sure it should be pretty easy.</p>
| [
{
"answer_id": 74399652,
"author": "Dmytro Demyanenko",
"author_id": 20265473,
"author_profile": "https://Stackoverflow.com/users/20265473",
"pm_score": 0,
"selected": false,
"text": "getAnnouncementsByIds(ids: string[]): Observable<Announcement[]> {\n // ids -> { ids }\n return this.http.post<Announcement[]>(`${environment.serverUrl}${this.urlGetAnnouncementsByIds}`, { ids });\n}\n"
},
{
"answer_id": 74399889,
"author": "Andriu1510",
"author_id": 17238007,
"author_profile": "https://Stackoverflow.com/users/17238007",
"pm_score": 3,
"selected": true,
"text": "export interface IdList{\n ids: string[]\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20396278/"
] |
74,399,637 | <p>Please help me, the question is probably stupid, but I'm at a dead end. There is a <strong>table with the following data</strong>:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Num</th>
<th>Start number</th>
<th>Date start</th>
</tr>
</thead>
<tbody>
<tr>
<td>111</td>
<td>225</td>
<td>11.11.22</td>
</tr>
<tr>
<td>111</td>
<td>223</td>
<td>9.11.22</td>
</tr>
<tr>
<td>111</td>
<td>220</td>
<td>9.11.22</td>
</tr>
<tr>
<td>222</td>
<td>347</td>
<td>11.11.22</td>
</tr>
<tr>
<td>222</td>
<td>345</td>
<td>11.11.22</td>
</tr>
<tr>
<td>222</td>
<td>343</td>
<td>10.11.22</td>
</tr>
</tbody>
</table>
</div>
<p>I would like to come to something like this, so that <strong>Num is displayed in one cell</strong>, the first and last values are displayed in the <strong>Start number and Date start</strong> fields, respectively, and their number is also counted in <strong>one cell</strong>:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Num</th>
<th>Start number</th>
<th>Date start</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr>
<td>111</td>
<td>225</td>
<td>11.11.22</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>220</td>
<td>9.11.22</td>
<td></td>
</tr>
<tr>
<td>222</td>
<td>347</td>
<td>11.11.22</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>343</td>
<td>10.11.22</td>
<td></td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74399840,
"author": "Tomáš Záluský",
"author_id": 653539,
"author_profile": "https://Stackoverflow.com/users/653539",
"pm_score": 2,
"selected": true,
"text": "with t(Num, Start_number, Date_start) as (\nselect 111 , 225 , '11.11.22' from dual union all\nselect 111 , 223 , '9.11.22' from dual union all\nselect 111 , 220 , '9.11.22' from dual union all\nselect 222 , 347 , '11.11.22' from dual union all\nselect 222 , 345 , '11.11.22' from dual union all\nselect 222 , 343 , '10.11.22' from dual\n)\nselect case when p.is_first = 1 then p.num end as num\n , p.start_number\n , p.date_start\n , case when p.is_first = 1 then p.cnt end as num\nfrom (\n select t.*\n , case when start_number = max(start_number) over (partition by num) then 1 else 0 end as is_first\n , case when start_number = min(start_number) over (partition by num) then 1 else 0 end as is_last\n , count(*) over (partition by num) as cnt\n from t\n) p\nwhere p.is_first = 1 or p.is_last = 1\n"
},
{
"answer_id": 74400163,
"author": "Ivan Yuzafatau",
"author_id": 1889110,
"author_profile": "https://Stackoverflow.com/users/1889110",
"pm_score": 0,
"selected": false,
"text": "SELECT\n Num,\n StartNumber,\n DateStart,\n [Count]\nFROM\n (\n SELECT\n Num,\n [Count],\n (SELECT MAX(StartNumber) FROM table AS t2 WHERE (t2.Num = t1.Num) AND (t2.DateStart = t1.MaxDateStart)) AS StartNumber,\n MaxDateStart AS DateStart\n FROM\n (\n SELECT\n Num,\n COUNT(*) AS [Count],\n MAX(DateStart) AS MaxDateStart\n FROM\n table\n GROUP BY\n Num\n ) AS t1\n \n UNION\n \n SELECT\n Num,\n [Count],\n (SELECT MIN(StartNumber) FROM table AS t2 WHERE (t2.Num = t1.Num) AND (t2.DateStart = t1.MinDateStart)) AS StartNumber,\n MinDateStart AS DateStart\n FROM\n (\n SELECT\n Num,\n COUNT(*) AS [Count],\n MIN(DateStart) AS MinDateStart\n FROM\n table\n GROUP BY\n Num\n ) AS t1\n ) AS t \nORDER BY\n Num, DateStart DESC\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20465987/"
] |
74,399,654 | <p>I have a txt file with lines of text like this, and I want to swap the word in
quotations with the last word that is separated from the sentence with a tab:</p>
<h2>it looks like this:</h2>
<pre><code>This "is" a person are
She was not "here" right
"The" pencil is not sharpened a
</code></pre>
<h2>desired output:</h2>
<pre><code>This "are" a person is
She was not "right" here
</code></pre>
<h2>Some ideas:</h2>
<h4>#1: Use Numpy</h4>
<ol>
<li>Seperate all the words by whitespace with numpy-> <code>['This','"is"','a','person',\t,'are']</code></li>
</ol>
<p><strong>Problems:</strong></p>
<ol>
<li>How do I tell python the position of the quoted word</li>
<li>How to convert the list back to normal text. Concatenate all?</li>
</ol>
<h4>#2: Use Regex</h4>
<ol>
<li>Use regex and find the word in <code>""</code></li>
</ol>
<pre><code>with open('readme.txt','r') as x:
x = x.readlines()
swap = x[-1]
re.findall(\"(\w+)\", swap)
</code></pre>
<p><strong>Problems:</strong></p>
<ol>
<li>I don't know what to read the txt file with regex. most examples I see here will assign the entire sentence to a variable.
Is it something like this?</li>
</ol>
<pre><code> with open('readme.txt') as f:
lines = f.readlines()
lines.findall(....)
</code></pre>
<p>Thanks guys</p>
| [
{
"answer_id": 74399860,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": true,
"text": "with open('foo.txt', 'r+') as txt:\n lines = txt.readlines()\n for k, line in enumerate(lines):\n words = line.split()\n for i, word in enumerate(words[:-1]):\n if word[0] == '\"' and word[-1] == '\"':\n words[i] = f'\"{words[-1]}\"'\n words[-1] = word[1:-1]\n break\n lines[k] = ' '.join(words[:-1]) + f'\\t{words[-1]}'\n txt.seek(0)\n print(*lines, sep='\\n', file=txt)\n txt.truncate()\n"
},
{
"answer_id": 74399990,
"author": "user56700",
"author_id": 11355926,
"author_profile": "https://Stackoverflow.com/users/11355926",
"pm_score": 0,
"selected": false,
"text": "This \"is\" a person are\nShe was not \"here\" right\n\"The\" pencil is not sharpened a\n"
},
{
"answer_id": 74400031,
"author": "Jahir Unzueta",
"author_id": 5435638,
"author_profile": "https://Stackoverflow.com/users/5435638",
"pm_score": 1,
"selected": false,
"text": "import re\nfile1 = open('test.txt', 'r')\ncount = 0\n\nwhile True:\n\n # Get next line from file\n line = file1.readline()\n\n # if line is empty\n # end of file is reached\n if not line:\n break\n \n get_tab = line.strip().split('\\t')[1]\n regex = r'\\\"[\\s\\S]*\\\"'\n print(\"original: {} mod ----> {}\".format(line.strip(), re.sub(regex, get_tab, line.strip().split('\\t')[0])))\n"
},
{
"answer_id": 74400371,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": false,
"text": "import re\n\npat = re.compile(r'\"([^\"]*)\"(.*\\t)(.*)')\n\nwith open(\"your_file.txt\", \"r\") as f_in:\n for line in f_in:\n print(pat.sub(r'\"\\3\"\\2\\1', line.rstrip()))\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16305691/"
] |
74,399,663 | <p>hi guys i have a problem i have two entities product and category i want to add a category and multiple product in the same form like that in this capture</p>
<p><a href="https://i.stack.imgur.com/myWPU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/myWPU.png" alt="enter image description here" /></a></p>
<p>this is my entity Category</p>
<pre><code>@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idcategory;
private String nom;
@JsonManagedReference("category")
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
private List<Product> products= new ArrayList<>();
public void add(Product item) {
if (item != null) {
if (products == null) {
products= new ArrayList<>();
}
products.add(item);
item.setCategory(this);
}
}
}
</code></pre>
<p>and this is entity Product</p>
<pre><code>@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idproduct;
private String nom;
private Integer prix;
@JsonBackReference("category")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "categoryproduct", referencedColumnName = "idcategory")
private Category category;
}
</code></pre>
<p>and this is my controller</p>
<pre><code>@RequestMapping(method = RequestMethod.POST)
public void addcategory(@RequestBody Category c) throws IOException {
List<Product> products = c.getProducts();
products.forEach(item -> c.add(item)
);
categorieRepository.save(c);
}
</code></pre>
<p>when i try to post a category and multiple product it shows this problem</p>
<pre><code>java.util.ConcurrentModificationException\\r\\n\\tat java.base/java.util.ArrayList.forEach(ArrayList.java:1513)\\r\\n\\tat com.example.users.controller.CategoryController.addcategory(CategoryController.java:46)\\r\\n\\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
</code></pre>
<p>i want to know whats wrong with my code and how to fix that guys</p>
| [
{
"answer_id": 74399860,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": true,
"text": "with open('foo.txt', 'r+') as txt:\n lines = txt.readlines()\n for k, line in enumerate(lines):\n words = line.split()\n for i, word in enumerate(words[:-1]):\n if word[0] == '\"' and word[-1] == '\"':\n words[i] = f'\"{words[-1]}\"'\n words[-1] = word[1:-1]\n break\n lines[k] = ' '.join(words[:-1]) + f'\\t{words[-1]}'\n txt.seek(0)\n print(*lines, sep='\\n', file=txt)\n txt.truncate()\n"
},
{
"answer_id": 74399990,
"author": "user56700",
"author_id": 11355926,
"author_profile": "https://Stackoverflow.com/users/11355926",
"pm_score": 0,
"selected": false,
"text": "This \"is\" a person are\nShe was not \"here\" right\n\"The\" pencil is not sharpened a\n"
},
{
"answer_id": 74400031,
"author": "Jahir Unzueta",
"author_id": 5435638,
"author_profile": "https://Stackoverflow.com/users/5435638",
"pm_score": 1,
"selected": false,
"text": "import re\nfile1 = open('test.txt', 'r')\ncount = 0\n\nwhile True:\n\n # Get next line from file\n line = file1.readline()\n\n # if line is empty\n # end of file is reached\n if not line:\n break\n \n get_tab = line.strip().split('\\t')[1]\n regex = r'\\\"[\\s\\S]*\\\"'\n print(\"original: {} mod ----> {}\".format(line.strip(), re.sub(regex, get_tab, line.strip().split('\\t')[0])))\n"
},
{
"answer_id": 74400371,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": false,
"text": "import re\n\npat = re.compile(r'\"([^\"]*)\"(.*\\t)(.*)')\n\nwith open(\"your_file.txt\", \"r\") as f_in:\n for line in f_in:\n print(pat.sub(r'\"\\3\"\\2\\1', line.rstrip()))\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16292904/"
] |
74,399,665 | <p>Someday I just got curious about <code>node_module</code> in framework or UI libraries such as React. After searching some stuff, I found there should be no changes in <code>node_modules</code> unless the user really needs to, so here's my questions.</p>
<ol>
<li>Why there shouldn't be changes in <code>node_modules</code>?</li>
<li>Even I change the code, there were no change in result. Why does this happen? Even deleting the file or folder inside <code>node_modules</code> there were no changes. (I thought it should show an error, but it worked Ok...)</li>
<li>When we start the framework (like <code>npm start</code> in React), does NPM downloads the external files for example from Github everytime and places in the DOM? If that's right, the files in <code>node_modules</code> are just readable ones?</li>
</ol>
<p>Could someone give me an answer?</p>
| [
{
"answer_id": 74400672,
"author": "iyhc",
"author_id": 15300260,
"author_profile": "https://Stackoverflow.com/users/15300260",
"pm_score": 3,
"selected": true,
"text": "node_modules"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16616376/"
] |
74,399,686 | <p>I have about 40 TextFormFields and I retrieve their values with TextEditingController. The values are converted into a Map<String, String> map via the following step:</p>
<pre><code>// map that stores controllers
Map<String, TextEditingController> storeControllers = controllers;
// convert to map that stores only controller texts
Map<String, String> currentSelections = storeControllers
.map((key, value) => MapEntry(key, storeControllers[key]!.text))
</code></pre>
<p>The current output with all values in String type:</p>
<pre><code>//currentSelections map
Map<String, String>
{
"field1": "1",
"field2": "Two",
"field3": "0.03",
...
"field40": "four40",
}
</code></pre>
<p>How do I convert the currentSelections map into a JSON that stores the values in their corresponding types?</p>
<pre><code>//Desired output:
Map<String, dynamic>
{
"field1": 1, //int
"field2": "Two", //String
"field3": 0.03, //double
...
"field40": "four40", //String
}
</code></pre>
<p>Any help would be appreciated! :)</p>
<p>I understand that the way to convert Strings to other types is using <code>int.parse("text")</code> method. But how do I do it with so many different types involved?</p>
| [
{
"answer_id": 74400672,
"author": "iyhc",
"author_id": 15300260,
"author_profile": "https://Stackoverflow.com/users/15300260",
"pm_score": 3,
"selected": true,
"text": "node_modules"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15442631/"
] |
74,399,855 | <p>I am trying to create a numeric array out of two columns of a <code>data.frame</code>. I have the columns "first" and "last" and I create the "range" one with <code>paste0(first,':',last)</code>.</p>
<p>I get to the point where I have the string with which I would obtain the desired array, but as I have it as a string, no numeric array gets declared.</p>
<p>I'm probably not explaining myself correctly, but I think with my actual output and desired one it is clearer.</p>
<pre><code>data <- structure(list(first = c(22, 26, 29, 32, 36, 39, 43, 47), last = c(24,
27, 30, 34, 37, 41, 45, 49), range = c("22:24", "26:27", "29:30",
"32:34", "36:37", "39:41", "43:45", "47:49")), row.names = c(NA,
-8L), class = "data.frame")
</code></pre>
<p>Actual output:</p>
<pre><code>> paste0('c(',paste(datos2$range,collapse=','),')')
# [1] "c(22:24,26:27,29:30,32:34,36:37,39:41,43:45,47:49)"
</code></pre>
<p>Desired output:</p>
<pre><code>> c(22:24,26:27,29:30,32:34,36:37,39:41,43:45,47:49)
# [1] 22 23 24 26 27 29 30 32 33 34 36 37 39 40 41 43 44 45 47 48 49
</code></pre>
<p>I'm sure I'm doing things harder than they have to be but I can't come up with any other approach to my problem.</p>
<p>Can someone help me?</p>
| [
{
"answer_id": 74399934,
"author": "Quinten",
"author_id": 14282714,
"author_profile": "https://Stackoverflow.com/users/14282714",
"pm_score": 2,
"selected": false,
"text": "eval"
},
{
"answer_id": 74399968,
"author": "Chris Ruehlemann",
"author_id": 8039978,
"author_profile": "https://Stackoverflow.com/users/8039978",
"pm_score": 0,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74400005,
"author": "sindri_baldur",
"author_id": 4552295,
"author_profile": "https://Stackoverflow.com/users/4552295",
"pm_score": 3,
"selected": true,
"text": "mapply(seq, data$first, data$last) |> unlist()\n# [1] 22 23 24 26 27 29 30 32 33 34 36 37 39 40 41 43 44 45 47 48 49\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19569763/"
] |
74,399,882 | <p>I am looking for the simplest answer to the given problem statement.</p>
<pre><code>class X{
Address add;
}
class Address{
String str;
String pincode;
}
</code></pre>
<p>The request is formed with x object as :</p>
<pre><code>X:{
add : {} //when none of the fields(str, pincode) present & they do not have any value
}
</code></pre>
<p>Now , I do not want to send address: {} in the payload.</p>
<p>Any JSON annotations will do this job?</p>
<p>I tried with <code>@JsonInclude(JsonInclude.Include. NON_NULL)</code> but not helpful to avoid the field.</p>
| [
{
"answer_id": 74400085,
"author": "Jinadee Yasiruka",
"author_id": 5955497,
"author_profile": "https://Stackoverflow.com/users/5955497",
"pm_score": 0,
"selected": false,
"text": "class X{\n @JsonIgnore\n Address add;\n}\n"
},
{
"answer_id": 74400505,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 1,
"selected": false,
"text": "Include.CUSTOM"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7843970/"
] |
74,399,935 | <p>Why this would be a violation of the hooks rules.?</p>
<p>In my case:</p>
<pre><code>const getTopicId = useSelector((state) => state.topics.selectTopic.topicId) !== "" ? useSelector((state) => state.topics.selectTopic.topicId) : JSON.parse(localStorage.getItem("topic")).topicId;
</code></pre>
<p>I don't put a condition inside the useSelector, i try to say that if useSelector() has data, use it, if not use the localStorage data.</p>
<p>the solution that accept EsLint is:
Put the useSelector inside a variable and then inside the ternary....but i don't understant why.</p>
<pre><code>const getTopicSelector = useSelector((state) => state.topics.selectTopic.topicId);
const getTopicId = useSelector((state) => state.topics.selectTopic.topicId) !== "" ? getTopicSelector : JSON.parse(localStorage.getItem("topic")).topicId
</code></pre>
<p>Thanks for your explanations.</p>
| [
{
"answer_id": 74400085,
"author": "Jinadee Yasiruka",
"author_id": 5955497,
"author_profile": "https://Stackoverflow.com/users/5955497",
"pm_score": 0,
"selected": false,
"text": "class X{\n @JsonIgnore\n Address add;\n}\n"
},
{
"answer_id": 74400505,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 1,
"selected": false,
"text": "Include.CUSTOM"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12289678/"
] |
74,399,945 | <p>A task is given:
Find how many times the text in the PATTERN is repeated in the TEXT. Repetitions may overlap with each other. We propose to cycle through all possible positions in TEXT in which the PATTERN can begin. When iterating, check each position in a loop, iterating over the characters in the PATTERN and the characters that go from the position being iterated. If at least one of the characters does not match during the check, the position does not fit and we move on to the next one. Otherwise, you need to increase the repetition count.</p>
<p>I understand that in order to find out which character is at the i-th position in the string, use the charAt(i) method, which each object of the String type has.</p>
<p>But what exactly, categorically does not come to mind.</p>
<pre><code>public class Main {
public static final String TEXT = "aaababaabaaaabaabaabaabaaababaabaaababaabaaaabaabaabaabbabaabaaababaababaabaabaabaaabbaab";
public static final String PATTERN = "aab";
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < TEXT.length(); i++) {
int count = 1;
}
System.out.println("String " + PATTERN + " met in the text " + count + " times");
}
}
</code></pre>
| [
{
"answer_id": 74400085,
"author": "Jinadee Yasiruka",
"author_id": 5955497,
"author_profile": "https://Stackoverflow.com/users/5955497",
"pm_score": 0,
"selected": false,
"text": "class X{\n @JsonIgnore\n Address add;\n}\n"
},
{
"answer_id": 74400505,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 1,
"selected": false,
"text": "Include.CUSTOM"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20475969/"
] |
74,399,948 | <p>This is the input data I am dealing with.</p>
<pre><code>November (5th-26th)
</code></pre>
<p>What I want to do is get 2 seperate outputs from this data string. i.e. {November 5th} and {November 26th}</p>
<p>I currently use this python script to remove the uneccesary characters in it</p>
<pre><code>Name = input_data['date'].replace("(", "").replace(")", "")
output = [{"Date": Name}]
</code></pre>
<p>and use other no code formating tools (Zapier) to split the data and make the output come as {November 5th} and {November 26th}</p>
<p>I would like to know form you guys if there is a single python code I could use to get the desired output without using other formating tools.</p>
<p>Thanks</p>
<p>I haven't treid anything with the code yet.</p>
| [
{
"answer_id": 74399989,
"author": "azro",
"author_id": 7212686,
"author_profile": "https://Stackoverflow.com/users/7212686",
"pm_score": 0,
"selected": false,
"text": "import re\n\nvalue = \"November (5th-26th)\"\nmonth, date_from, date_to = re.match(r\"(\\w+)\\s+\\((.*)-(.*)\\)\", value).groups()\nprint([month, date_from, date_to]) # ['November', '5th', '26th']\n\nresult = [f\"{month} {date_from}\", f\"{month} {date_to}\"]\nprint(result) # ['November 5th', 'November 26th']\n"
},
{
"answer_id": 74400021,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 3,
"selected": true,
"text": "string = \"November (5th-26th)\"\nmonth, days = [x.strip('()') for x in string.split(' ')]\nstart, end = days.split('-')\n\noutput = {'date_range' : [f\"{month} {start}\", f\"{month} {end}\"]}\nprint(output)\n"
},
{
"answer_id": 74400397,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "s = 'November (5th-26th)'\nm, d = s.split()\nfor dt in d[1:-1].split('-'):\n print(f'{{{m} {dt}}}')\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74399948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19912615/"
] |
74,400,007 | <p>I was trying to extract lists from a tuple with a condition that every X numbers in ascending order should be extracted in same list, using a list comprehension.</p>
<p>Example:</p>
<ul>
<li>Input: <code>(4,2,2,3,5,6,0,0,2)</code></li>
<li>Desired output: <code>[[4],[2,2,3,5,6],[0,0,2]]</code></li>
</ul>
<p>I tried the following:</p>
<pre class="lang-py prettyprint-override"><code>E=tuple([random.randint(0,10) for x in range(10)])
Res=[E[x:y] for x in range(0,len(E)) for y in range(x+1,len(E)) if (y>x)]
</code></pre>
| [
{
"answer_id": 74400187,
"author": "Rabinzel",
"author_id": 15521392,
"author_profile": "https://Stackoverflow.com/users/15521392",
"pm_score": 0,
"selected": false,
"text": "np.split"
},
{
"answer_id": 74400273,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "from random import randint as RANDINT\n\nt = 4, 2, 2, 3, 5, 6, 0, 0, 2\nout = []\noffset = 0\nwhile offset < len(t):\n e = RANDINT(1, len(t)+1-offset)\n out.append(list(t[offset:offset+e]))\n offset += e\nprint(out)\n"
},
{
"answer_id": 74400394,
"author": "Y U",
"author_id": 17524926,
"author_profile": "https://Stackoverflow.com/users/17524926",
"pm_score": 0,
"selected": false,
"text": "t=(4,2,2,3,5,6,0,0,2)\n\nsplit_list=[0]+[x for x in range(len(t)) if t[x]<t[x-1]]\nsplit_list_end=[x for x in range(len(t)) if t[x]<t[x-1]]\nsplit_list_end.append(len(t))\n\n[list(t[x]) for x in [slice(x[0],x[1]) for x in list(zip(split_list,split_list_end))]]\n"
},
{
"answer_id": 74400660,
"author": "R. Baraiya",
"author_id": 13888486,
"author_profile": "https://Stackoverflow.com/users/13888486",
"pm_score": 2,
"selected": true,
"text": "append element as a list"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20139720/"
] |
74,400,027 | <p>I need to create a function</p>
<pre><code>Map<Category, Double> averagePricePerCategory
</code></pre>
<p>that receives a <code>List<Buildings> buildings</code> as a parameter of objects that have:</p>
<pre><code>private int price;
private String neighborhood;
private Category category;
</code></pre>
<p>I need to get the price for each of them, calculate the average and return a Map with their respective category and its average price.
I'm really struggling to understand how I can do this.</p>
<p>So far I'm stuck at what to do next and how it should like.</p>
<pre><code>static Map<Category, Double> averagePricePerCategory(List<Building> buildings) {
Map<String, Double> averagePriceCategory = new HashMap<>();
Category x = buildings.get(0).getCategory();
if(buildings.isEmpty()){
return new HashMap<>();
}else{
for(Building b: buildings){
}
}
return null;
}
</code></pre>
| [
{
"answer_id": 74400287,
"author": "azro",
"author_id": 7212686,
"author_profile": "https://Stackoverflow.com/users/7212686",
"pm_score": 0,
"selected": false,
"text": "avg = sum/count"
},
{
"answer_id": 74400406,
"author": "Giuseppe Gallo",
"author_id": 4030320,
"author_profile": "https://Stackoverflow.com/users/4030320",
"pm_score": 2,
"selected": false,
"text": "static Map<Category, Double> averagePricePerCategory(List<Building> buildings) {\n return buildings.stream().collect(Collectors.groupingBy(Building::getCategory, Collectors.averagingDouble(Building::getPrice)));\n }\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476094/"
] |
74,400,050 | <p>I generate SQL statements dynamically from the input file and I want to have the output in JSON format grouped by a key which I provide in an alias in the select statement.</p>
<p>The input file comes from another system and it looks like this:</p>
<pre><code>'abc' AS [x.test1],
'cde' AS [y.test2],
'fgh' AS [y.test3]
</code></pre>
<p>In SQL Server I have a working query like this:</p>
<pre><code>SELECT
(SELECT
'abc' AS [x.test1],
'cde' AS [y.test2],
'fgh' AS [y.test3]
FROM "dbo"."TEST"
FOR JSON PATH,
WITHOUT_ARRAY_WRAPPER
) AS RESULT
</code></pre>
<p>It returns this output which is grouped by key and this is working perfectly:</p>
<p><code>{"x":{"test1":"abc"},"y":{"test2":"cde","test3":"fgh"}}</code></p>
<p>I want to achieve the same output with oracle.</p>
<p>Currently, I got to here:</p>
<pre><code>SELECT
(
SELECT json_object(
KEY '[x.test1]' IS 'abc',
KEY '[y.test2]' IS 'cde',
KEY '[y.test3]' IS 'fgh'
)
FROM test
)
AS RESULT from DUAL;
</code></pre>
<p>Problem is that this doesn't group my output by the key:</p>
<pre><code>{"[x.test1]":"abc","[y.test2]":"cde","[y.test3]":"fgh"}
</code></pre>
| [
{
"answer_id": 74400346,
"author": "Alex Poole",
"author_id": 266304,
"author_profile": "https://Stackoverflow.com/users/266304",
"pm_score": 1,
"selected": false,
"text": "json_object()"
},
{
"answer_id": 74402976,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 1,
"selected": true,
"text": "WITH data (expr) AS (\n SELECT q'~'abc' AS [x.test1],'cde' AS [y.test2],'fgh' AS [y.test3]~' FROM DUAL \n),\nrdata(expr) AS (\n SELECT regexp_substr(expr,'[^,]+',1,LEVEL) AS expr\n FROM data\n CONNECT BY regexp_substr(expr,'[^,]+',1,LEVEL) IS NOT NULL\n), \nexprs AS (\n SELECT expr, regexp_substr(expr, q'~'(.*)'~', 1, 1, 'i', 1) as val, \n regexp_substr(expr, q'~\\[(.*)\\]~', 1, 1, 'i', 1) as path \n FROM rdata \n),\nspaths AS (\n SELECT e.*, LEVEL as lvl, regexp_substr(path,'[^\\.]+',1,LEVEL) as pitem\n FROM exprs e\n CONNECT BY regexp_substr(path,'[^\\.]+',1,LEVEL) IS NOT NULL AND prior val = val AND PRIOR sys_guid() IS NOT NULL\n)\nSELECT json_object(\n s.pitem VALUE json_objectagg(\n p.pitem VALUE p.val\n )\n) AS js\nFROM spaths s\n JOIN spaths p ON s.val = p.val AND p.lvl = 2\nWHERE s.lvl = 1\nGROUP BY s.pitem\n;\n\n\nJS\n{\"x\":{\"test1\":\"abc\"}}\n{\"y\":{\"test2\":\"cde\",\"test3\":\"fgh\"}}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5632034/"
] |
74,400,057 | <p>Conditions of the 6-digit code:</p>
<ul>
<li>None of the digits are 0</li>
<li>Each digit of the combination is different</li>
<li>The 6-digit number is divisible by each one of the digits</li>
</ul>
<p>Input:</p>
<ul>
<li>Two integers, L and H</li>
<li>L is the limit on the smallest number on the range</li>
<li>H is the limit on the largest number on the range</li>
</ul>
<p>Output:</p>
<ul>
<li>C, which defines the number of possible combinations where L<=c<=H</li>
</ul>
<p>I thought I could use arrays as the condition check, then realized I couldn't use it to find the number of possible combinations. Tried using loops, but couldn't figure it out, all I got for the pseudocode is the input, then a condition if L is less or equal to H. Then I sort of ran to a brick wall.</p>
<p>Here's the code.</p>
<p>''''''''</p>
<pre><code> public static void main(String[] args) {
Scanner FF = new Scanner(System.in);
List<Integer> result = new ArrayList<>();
int l = FF.nextInt();
int h = FF.nextInt();
for (int i = l; i <= h; i++) {
result.add(i);
}
for (int i=l; i<=h; i++){
if (result.get(i) == result.get(i)){
result.remove(i);
}
int temp = result.get(i);
while (result.get(i)>0){
int k = result.get(i)%10;
if (temp % k != 0){
result.remove(i);
}
}
if (String.valueOf(result.get(i)).contains("0")){
result.remove(i);
}
}
System.out.println(result);
}
</code></pre>
<p>}</p>
| [
{
"answer_id": 74400125,
"author": "Lorenz Hetterich",
"author_id": 20473701,
"author_profile": "https://Stackoverflow.com/users/20473701",
"pm_score": 0,
"selected": false,
"text": "boolean isOk(int number){\n String numberStr = Integer.toString(number);\n if(numberStr.contains(\"0\"))\n return false;\n for(int i = 0; i < numberStr.length(); i++){\n for(int j = i + 1; j < numberStr.length(); j++){\n if(numberStr.charAt(i) == numberStr.charAt(j))\n return false;\n }\n }\n return true;\n}\n\n...\nint count = 0;\nfor(int i = L; i <= H; i++){\n if(isOk(i))\n count ++;\n}\n"
},
{
"answer_id": 74402686,
"author": "FredvN",
"author_id": 8052787,
"author_profile": "https://Stackoverflow.com/users/8052787",
"pm_score": 1,
"selected": false,
"text": "public class SixDigitCode {\npublic static void main(String[] args) {\n\n IntStream.iterate(111111, i -> i < 1000000, i -> i + 1)\n .filter(containsZero.negate())\n .filter(digitDifferent)\n .filter(divideByDigits)\n .forEach(System.out::println);\n}\n\nstatic IntPredicate containsZero = i -> Integer.toString(i).contains(\"0\");\nstatic IntPredicate digitDifferent = i -> Integer.toString(i).chars().boxed().collect(Collectors.toSet()).size() == 6;\nstatic IntPredicate divideByDigits = i -> Integer.toString(i).chars().boxed()\n .filter( x -> i%Character.getNumericValue(x) ==0)\n .count() ==6;\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476058/"
] |
74,400,061 | <p>I am trying to solve HackerRank SQL - <strong>The PADS</strong> question.</p>
<p>The Question is:</p>
<p>Generate the following two result sets:</p>
<ol>
<li><p>Query an <em>alphabetically ordered</em> list of all names in <strong>OCCUPATIONS</strong>, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: <code>AnActorName(A)</code>, <code>ADoctorName(D)</code>, <code>AProfessorName(P)</code>, and <code>ASingerName(S)</code>.</p>
</li>
<li><p>Query the number of ocurrences of each occupation in <strong>OCCUPATIONS</strong>. Sort the occurrences in <em>ascending order</em>, and output them in the following format:</p>
<pre><code>There are a total of [occupation_count] [occupation]s.
</code></pre>
<p>where <code>[occupation_count]</code> is the number of occurrences of an occupation in <strong>OCCUPATIONS</strong> and <code>[occupation]</code> is the <em>lowercase</em> occupation name. If more than one <em>Occupation</em> has the same <code>[occupation_count]</code>, they should be ordered alphabetically.</p>
</li>
</ol>
<p>My Solution is:</p>
<pre><code>SELECT NAME || '(' || SUBSTR(OCCUPATION,1,1) || ')'
FROM OCCUPATIONS
ORDER BY NAME
UNION
SELECT 'There are a total of ' || COUNT(OCCUPATION) || ' ' || LOWER(OCCUPATION) || 's.'
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY OCCUPATION;
OP:
ERROR at line 4:
ORA-00933: SQL command not properly ended
(It seems, we cannot use ORDER BY BEFORE UNION)
</code></pre>
<p>I revised my code to:</p>
<pre><code>SELECT NAME || '(' || SUBSTR(OCCUPATION,1,1) || ')'
FROM OCCUPATIONS
UNION
SELECT 'There are a total of ' || COUNT(OCCUPATION) || ' ' || LOWER(OCCUPATION) || 's.'
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY NAME, OCCUPATION;
OP:
ERROR at line 7:
ORA-00904: "NAME": invalid identifier
</code></pre>
<p>Please, help me out here.</p>
| [
{
"answer_id": 74400331,
"author": "Boneist",
"author_id": 4479309,
"author_profile": "https://Stackoverflow.com/users/4479309",
"pm_score": 2,
"selected": true,
"text": "SELECT info\nFROM (SELECT 1 qry, NAME || '(' || SUBSTR(OCCUPATION,1,1) || ')' info\n FROM OCCUPATIONS\n UNION ALL\n SELECT 2 qry, 'There are a total of ' || COUNT(OCCUPATION) || ' ' || LOWER(OCCUPATION) || 's.' info\n FROM OCCUPATIONS\n GROUP BY OCCUPATION)\nORDER BY qry, info;\n"
},
{
"answer_id": 74400628,
"author": "MT0",
"author_id": 1509264,
"author_profile": "https://Stackoverflow.com/users/1509264",
"pm_score": 2,
"selected": false,
"text": "SELECT"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15110512/"
] |
74,400,081 | <p>I have this code --></p>
<pre><code>list=("kek" "lol")
dict+=(["memes"]=$list)
</code></pre>
<p>with array, and the dictionary ( i guess ).<br />
now i want to get, for example, second index out of the list, but using dictionary.<br />
Something like
<code>echo ${dict[1]}</code>, but that does not print out anything, even tho if to call <code>echo ${dict[0]}</code>, it will print out <code>kek</code>. So my guess that i have done something wrong on declaring dictionary step... and i was not able to google anything about this issue for some reason.<br />
So... How do i do it?</p>
| [
{
"answer_id": 74400118,
"author": "BaronRandom",
"author_id": 14706190,
"author_profile": "https://Stackoverflow.com/users/14706190",
"pm_score": 0,
"selected": false,
"text": "dict+=([\"memes\"]=\"kek\" \"lol\")"
},
{
"answer_id": 74400386,
"author": "user1934428",
"author_id": 1934428,
"author_profile": "https://Stackoverflow.com/users/1934428",
"pm_score": 2,
"selected": true,
"text": "list"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14706190/"
] |
74,400,088 | <p><strong>There are two main widgets:</strong></p>
<p>I have this <code>OverflowingWidget</code> that is basically a <code>Column</code> - in reality this contains many widgets - However for this example, it has been given a height bigger than its parent widget.</p>
<p>The Parent widget <code>ContainerWidget</code> is basically <code>AnimatedSwitcher</code> which is basically a <code>Stack</code> contained by <code>Column</code> which constrained by a hight less than <code>OverflowingWidget</code>.
As you can see in <a href="https://dartpad.dev/?id=46765b328c3ac8c8be7409dc26d4ead6" rel="nofollow noreferrer">dart-pad</a> there is an overflow. The <code>OverflowingWidget</code>.</p>
<pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: ContainerWidget(),
),
),
);
}
}
class ContainerWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
height: 100,
width: 50,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: ClipRect(
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: OverflowingWidget(),
layoutBuilder: (currentChild, previousChildren) => Stack(
children: [
...previousChildren,
if (currentChild != null) currentChild,
],
)),
),
),
],
));
}
}
class OverflowingWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [Container(color: Colors.blue, height: 150, width: 50)]);
}
}
</code></pre>
<p><strong>Desired result:</strong></p>
<p>I need the <code>OverflowingWidget</code> to be clean clipped without trying to resize the content inside. The same effect that can be obtained when in <code>css</code>:<code>overflow:hidden</code>.</p>
| [
{
"answer_id": 74400241,
"author": "Yeasin Sheikh",
"author_id": 10157127,
"author_profile": "https://Stackoverflow.com/users/10157127",
"pm_score": 1,
"selected": false,
"text": "AnimatedSwitcher"
},
{
"answer_id": 74561333,
"author": "Sami Al-Subhi",
"author_id": 947473,
"author_profile": "https://Stackoverflow.com/users/947473",
"pm_score": 1,
"selected": true,
"text": "Wrap"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/947473/"
] |
74,400,107 | <p>I gave a project that's split in "server" and "client" repos. Most times I make a change involving both repos, but to commit and push them, I need to open multiple tabs on sourcetree, stage all, commit, message etc...</p>
<p>Is there a way of tracking all repos in a folder and push the relevant changes to the relevant repo with the same commit message?</p>
<p>I've tried submodules, and I do see them in sourcetree (pic attached)
<a href="https://i.stack.imgur.com/r6eaL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r6eaL.png" alt="enter image description here" /></a></p>
<p>but their commit/push must be made one by one...</p>
| [
{
"answer_id": 74400241,
"author": "Yeasin Sheikh",
"author_id": 10157127,
"author_profile": "https://Stackoverflow.com/users/10157127",
"pm_score": 1,
"selected": false,
"text": "AnimatedSwitcher"
},
{
"answer_id": 74561333,
"author": "Sami Al-Subhi",
"author_id": 947473,
"author_profile": "https://Stackoverflow.com/users/947473",
"pm_score": 1,
"selected": true,
"text": "Wrap"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/471573/"
] |
74,400,122 | <p>I'm trying to get the arguments of a function, where the function name is stored as a string <code>func_name</code>. Normally I would do this as <code>formals(func_name)</code> and this works fine. However, I have a particular case where <code>func_name</code> has the package name attached as well, e.g. <code>package::func_name</code>.</p>
<p>The problem is that calling <code>formals(package::func_name)</code> I get:</p>
<pre><code>Error in get(fun, mode = "function", envir = envir) :
object 'package::func_name' of mode 'function' was not found
</code></pre>
<p>This works if I remove the <code>package::</code> bit, so the problem is clearly the presence of <code>package::</code>.</p>
<p>The reason I need to this is because the <code>formals()</code> command is inside a function inside an R package that I maintain, and I want to call this function from another package that I am building. Hence, I have to use the <code>package::func_name</code> syntax in the call.</p>
<p>Is there any way to somehow modify the <code>formals()</code> command to accept the <code>package::func_name</code> format? I guess I could also just remove the <code>package::</code> part of the string but this seems a bit hacky. Any suggestions?</p>
| [
{
"answer_id": 74400631,
"author": "Robert Hacken",
"author_id": 2094893,
"author_profile": "https://Stackoverflow.com/users/2094893",
"pm_score": 2,
"selected": false,
"text": "formals('gls', envir=getNamespace('nlme'))\n"
},
{
"answer_id": 74401994,
"author": "G. Grothendieck",
"author_id": 516548,
"author_profile": "https://Stackoverflow.com/users/516548",
"pm_score": 1,
"selected": false,
"text": "base::subset"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7744908/"
] |
74,400,154 | <p>My dilemma can be summarised with the following:</p>
<ul>
<li>I want to preserve the semantic structure of the first example</li>
<li>I want to lay it out as per the second example</li>
</ul>
<p>The semantically correct HTML would be to have the <code><header></code> nested within the <code><article></code> element, as the heading belongs to the article.</p>
<p>However, for CSS grid to work, the <code><header></code> has to be a child of the grid container.</p>
<p>Is there a solution to this conflict?</p>
<h2>Semantically correct, doesn't work</h2>
<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>.layout {
display: grid;
grid-template-columns: 4fr 8fr;
grid-template-rows: auto 1fr;
gap: var(--grid-gap);
grid-template-areas:
"top top"
"menu content";
}
.layout nav {
border: 1px solid aqua;
grid-area: menu;
}
.layout main {
border: 1px solid green;
grid-area: content;
}
.layout header {
border: 1px solid red;
grid-area: top;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="layout">
<nav>
<p>nav</p>
</nav>
<main>
<article>
<header>
<h1>Title</h1>
<p>Subtitle</p>
</header>
<p>Lorum ipsum content etc</p>
</article>
</main>
</div></code></pre>
</div>
</div>
</p>
<h2>Semantically wrong, layout is correct</h2>
<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>.layout {
display: grid;
grid-template-columns: 4fr 8fr;
grid-template-rows: auto 1fr;
gap: var(--grid-gap);
grid-template-areas:
"top top"
"menu content";
}
.layout nav {
border: 1px solid aqua;
grid-area: menu;
}
.layout main {
border: 1px solid green;
grid-area: content;
}
.layout header {
border: 1px solid red;
grid-area: top;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="layout">
<nav>
<p>nav</p>
</nav>
<header>
<h1>Title</h1>
<p>Subtitle</p>
</header>
<main>
<article>
<p>Lorum ipsum content etc</p>
</article>
</main>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74400189,
"author": "Fenton",
"author_id": 75525,
"author_profile": "https://Stackoverflow.com/users/75525",
"pm_score": 0,
"selected": false,
"text": ".layout {\n display: grid; \n grid-template-columns: 4fr 8fr; \n grid-template-rows: auto 1fr; \n gap: var(--grid-gap);\n grid-template-areas: \n \"top top\"\n \"menu content\"; \n}\n\n.layout nav {\n border: 1px solid aqua;\n grid-area: menu;\n}\n\n.layout div{\n border: 1px solid green;\n grid-area: content;\n}\n\n.layout header {\n border: 1px solid red;\n grid-area: top;\n}"
},
{
"answer_id": 74403404,
"author": "basherkev",
"author_id": 3402083,
"author_profile": "https://Stackoverflow.com/users/3402083",
"pm_score": 1,
"selected": false,
"text": "<article>"
},
{
"answer_id": 74404312,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "display: contents"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/75525/"
] |
74,400,160 | <p>I have a datetime columns on that basis I calculate <code>min_time</code> and <code>max_time</code>. so from current <code>min_time</code> of the row want to subtract from previous row <code>max_time</code> and want to save into another column. How to do that?</p>
<pre><code>data = pd.DataFrame()
data['datetime'] = 18-6-22 8:22:22, 18-6-22 8:22:23, 18-6-22 8:22:24, 18-6-22 8:22:25, 18-6-22 8:22:26, 18-6-22 11:22:27
data['min_time'] = 18-6-22 8:22:22, 18-6-22 8:22:23, 18-6-22 8:22:24, 18-6-22 8:22:25, 18-6-22 8:22:26, 18-6-22 11:22:27
data['max_time'] = 18-6-22 8:22:22, 18-6-22 8:22:23, 18-6-22 8:22:24, 18-6-22 8:22:25, 18-6-22 8:22:26, 18-6-22 11:22:27
data['t_diff_time'] = 0, 0, 0, 0, 0, 0 Day 3:00:1
</code></pre>
<p>Is there any function to do this?</p>
<p><strong>expected output :</strong></p>
<p><a href="https://i.stack.imgur.com/SBtOk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SBtOk.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74400189,
"author": "Fenton",
"author_id": 75525,
"author_profile": "https://Stackoverflow.com/users/75525",
"pm_score": 0,
"selected": false,
"text": ".layout {\n display: grid; \n grid-template-columns: 4fr 8fr; \n grid-template-rows: auto 1fr; \n gap: var(--grid-gap);\n grid-template-areas: \n \"top top\"\n \"menu content\"; \n}\n\n.layout nav {\n border: 1px solid aqua;\n grid-area: menu;\n}\n\n.layout div{\n border: 1px solid green;\n grid-area: content;\n}\n\n.layout header {\n border: 1px solid red;\n grid-area: top;\n}"
},
{
"answer_id": 74403404,
"author": "basherkev",
"author_id": 3402083,
"author_profile": "https://Stackoverflow.com/users/3402083",
"pm_score": 1,
"selected": false,
"text": "<article>"
},
{
"answer_id": 74404312,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "display: contents"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15543946/"
] |
74,400,169 | <p>I'm building a white-label service and we need a logic where users should have a chance to authenticate with the same email through different domains (example1.com, example2.com).</p>
<p>I'm using ruby-on-rails 6.1.7, ruby 2.7.0p0 and device 4.8.1</p>
<p>I have tried to do that by using <a href="https://github.com/heartcombo/devise/wiki/How-to:-Scope-login-to-subdomain" rel="nofollow noreferrer">this documentation</a> and I have added to my devise initializer this line <code>config.authentication_keys = [ :email, :domain ]</code>. After that, I created a migrations file where I'm adding indexes:</p>
<pre><code>add_column :users, :domain, :string, null: false, default: 'example.com'
remove_index :users, :email
add_index :users, [:email, :domain], unique: true
</code></pre>
<p>also added to Users model:</p>
<pre><code>devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, authentication_keys: [:domain, :email]
def self.find_for_authentication
where(domain: warden_conditions[:domain], email: warden_conditions[:email]).first
end
</code></pre>
<p>and registration controller where I create a new account looks like this:</p>
<pre><code>def create
build_resource(sign_up_params)
resource.domain = request.domain
puts
puts '*' * 100
p resource
puts '*' * 100
puts
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
sign_up(resource_name, resource)
else
render json: { success: true, location: '/registrations/success' }
end
else
render json: { errors: resource.errors.messages }, status: 422
end
end
</code></pre>
<p>now I am faced with a problem. In the database, I have an account with the email random@mail.com and the domain example1.com, so now when I'm trying to create a new account for the same person with the same email, but from a different domain example2.com I'm getting an error that user with this email exists. I see that devise does the wrong query to the database and this query looks like this <code>User Exists? (1.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "random@mail.com"], ["LIMIT", 1]]</code>, but it should look like this <code>User Exists? (1.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 AND "users"."domain" = $2 LIMIT $3 [["email", "random@mail.com"], ["domain", "example.com"], ["LIMIT", 1]]</code></p>
<p>That I've missed? Thanks for any help.</p>
| [
{
"answer_id": 74400189,
"author": "Fenton",
"author_id": 75525,
"author_profile": "https://Stackoverflow.com/users/75525",
"pm_score": 0,
"selected": false,
"text": ".layout {\n display: grid; \n grid-template-columns: 4fr 8fr; \n grid-template-rows: auto 1fr; \n gap: var(--grid-gap);\n grid-template-areas: \n \"top top\"\n \"menu content\"; \n}\n\n.layout nav {\n border: 1px solid aqua;\n grid-area: menu;\n}\n\n.layout div{\n border: 1px solid green;\n grid-area: content;\n}\n\n.layout header {\n border: 1px solid red;\n grid-area: top;\n}"
},
{
"answer_id": 74403404,
"author": "basherkev",
"author_id": 3402083,
"author_profile": "https://Stackoverflow.com/users/3402083",
"pm_score": 1,
"selected": false,
"text": "<article>"
},
{
"answer_id": 74404312,
"author": "Temani Afif",
"author_id": 8620333,
"author_profile": "https://Stackoverflow.com/users/8620333",
"pm_score": 2,
"selected": true,
"text": "display: contents"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8201176/"
] |
74,400,170 | <p>I have a React Application with backend on Nodejs and database MySQL, I am using a python api and I want to send data from my React input fields to python so that I can use that data as parameters to my python functions. For this, I am using axios to send data to a flask server, but I am getting this cyclic object error. I have attached the code below.</p>
<p>React Component :</p>
<pre><code> const send_data = ()=>
{
const trade = document.getElementById("trade");
const index = document.getElementById("index");
const tradeType = document.getElementById("type");
const strikePrice = document.getElementById("strikeP");
const trigger = document.getElementById("trigger");
const perc = document.getElementById("percentage");
const ce = document.getElementById("ce");
const pe = document.getElementById("pe");
const entry = document.getElementById("entry");
const exit = document.getElementById("exit");
axios.post("127.0.0.1:5000/trade_data" , {
trade_no : trade.value,
index_name : index.value,
trade_type : tradeType.value,
strike_price : strikePrice,
ce_d : ce.value,
pe_d : pe.value,
entry_time : entry.value,
exit_time : exit.value,
trigger_points : trigger.value,
sl_percentage : perc.value
}).then(console.log("Data Sent"));
}
</code></pre>
<p>and I am calling this function onclicking the button :</p>
<pre><code> <button id="start" onClick={send_data}>Start</button>
</code></pre>
<p>Here is my flask code:</p>
<pre><code>from flask import Flask
import requests
app = Flask(__name__)
@app.route('/trade_data' , methods = ['GET'])
def show_data():
r = requests.get("http://127.0.0.1:5000/trade_data")
print(r)
return r
if __name__ == '__main__':
app.run(debug = True)
</code></pre>
<p>And here is the error I am getting :
<a href="https://i.stack.imgur.com/nPkSJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nPkSJ.png" alt="enter image description here" /></a></p>
<p>New error :</p>
<p><a href="https://i.stack.imgur.com/cRSFE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cRSFE.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74400263,
"author": "Suaro",
"author_id": 8713074,
"author_profile": "https://Stackoverflow.com/users/8713074",
"pm_score": 1,
"selected": false,
"text": " axios.post(\"127.0.0.1:5000/trade_data\" , {\n trade_no : trade.value,\n index_name : index.value,\n trade_type : tradeType.value,\n strike_price : strikePrice.value,\n ce_d : ce.value,\n pe_d : pe.value,\n entry_time : entry.value,\n exit_time : exit.value,\n trigger_points : trigger.value,\n sl_percentage : perc.value\n }).then(console.log(\"Data Sent\"));\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12027725/"
] |
74,400,188 | <p>I'm training an nlp model using spacy. I have the preprocessing steps all written as a pipeline, and now I need to do the training. According to <a href="https://spacy.io/usage/training" rel="nofollow noreferrer">spacy's documentation</a> I need to run the following command:</p>
<pre><code>python -m spacy train config.cfg --output ./output --paths.train ./train.spacy --paths.dev ./dev.spacy
</code></pre>
<p>The files <code>config.cfg</code>, <code>train.spacy</code> and <code>dev.spacy</code> are all registered in my data catalog. I want to run this command with something similar to the following code:</p>
<pre><code>import subprocess
def train_spacy_nlp_model(
config_filepath: str,
train_filepath: str,
dev_filepath: str,
output_dir: str
):
cmd = [
"python -m", "spacy",
"train", config_filepath,
"--output", output_dir,
"--paths.train", train_filepath,
"--paths.dev", dev_filepath
]
result = subprocess.run(" ".join(cmd), shell=True)
if result.returncode != 0:
raise RuntimeError("Spacy training failed")
</code></pre>
<p>But I have no idea how to retrieve the file path information from the items in my data catalog, is there a way of passing this information to my nodes when creating the pipeline?</p>
| [
{
"answer_id": 74400263,
"author": "Suaro",
"author_id": 8713074,
"author_profile": "https://Stackoverflow.com/users/8713074",
"pm_score": 1,
"selected": false,
"text": " axios.post(\"127.0.0.1:5000/trade_data\" , {\n trade_no : trade.value,\n index_name : index.value,\n trade_type : tradeType.value,\n strike_price : strikePrice.value,\n ce_d : ce.value,\n pe_d : pe.value,\n entry_time : entry.value,\n exit_time : exit.value,\n trigger_points : trigger.value,\n sl_percentage : perc.value\n }).then(console.log(\"Data Sent\"));\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4534466/"
] |
74,400,207 | <p>I have the following data frame:</p>
<pre><code>dat <- structure(list(ref_string = c("K", "Y", "Q", "C", "H", "A", "S",
"Y", "L", "Y"), peptide_name = c("p47", "p666", "p506", "p356",
"p598", "p458", "p448", "p117", "p232", "p464"), peptide = c("FKDHKHIDVKgrrrskrrrrTRCYHIDPHH",
"FKDHKHIDVKsrgrkrrrrrTRCYHIDPHH", "FKDHKHIDVKrrrrskrgrrTRCYHIDPHH",
"FKDHKHIDVKrrrgrrrrskTRCYHIDPHH", "FKDHKHIDVKrsgrrrrrkrTRCYHIDPHH",
"FKDHKHIDVKrrrrrkrrgsTRCYHIDPHH", "FKDHKHIDVKrrrrrgrskrTRCYHIDPHH",
"FKDHKHIDVKkrrrrsrrgrTRCYHIDPHH", "FKDHKHIDVKrkrrrrsgrrTRCYHIDPHH",
"FKDHKHIDVKrrrrrksrrgTRCYHIDPHH"), status = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0)), class = c("rowwise_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -10L), groups = structure(list(.rows = structure(list(
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame")))
</code></pre>
<p>It looks like this:</p>
<pre><code># A tibble: 10 × 4
# Rowwise:
ref_string peptide_name peptide status
<chr> <chr> <chr> <dbl>
1 K p47 FKDHKHIDVKgrrrskrrrrTRCYHIDPHH 0
2 Y p666 FKDHKHIDVKsrgrkrrrrrTRCYHIDPHH 0
3 Q p506 FKDHKHIDVKrrrrskrgrrTRCYHIDPHH 0
4 C p356 FKDHKHIDVKrrrgrrrrskTRCYHIDPHH 0
5 H p598 FKDHKHIDVKrsgrrrrrkrTRCYHIDPHH 0
6 A p458 FKDHKHIDVKrrrrrkrrgsTRCYHIDPHH 0
7 S p448 FKDHKHIDVKrrrrrgrskrTRCYHIDPHH 0
8 Y p117 FKDHKHIDVKkrrrrsrrgrTRCYHIDPHH 0
9 L p232 FKDHKHIDVKrkrrrrsgrrTRCYHIDPHH 0
10 Y p464 FKDHKHIDVKrrrrrksrrgTRCYHIDPHH 0
</code></pre>
<p>Currently, I have this dplyr's process which is slow for real data set:</p>
<pre><code>library(tidyverse)
dat %>%
dplyr::group_by(peptide_name, peptide) %>%
mutate(tot = sum(status)) %>%
filter(tot == 0) %>%
pivot_wider(names_from = ref_string, values_from = status) %>%
dplyr::select(-tot) %>%
ungroup()
</code></pre>
<p>Which produces:</p>
<pre><code># A tibble: 10 × 10
peptide_name peptide K Y Q C H A S L
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 p47 FKDHKHIDVKgrrrskrrrrTRCYHIDPHH 0 NA NA NA NA NA NA NA
2 p666 FKDHKHIDVKsrgrkrrrrrTRCYHIDPHH NA 0 NA NA NA NA NA NA
3 p506 FKDHKHIDVKrrrrskrgrrTRCYHIDPHH NA NA 0 NA NA NA NA NA
4 p356 FKDHKHIDVKrrrgrrrrskTRCYHIDPHH NA NA NA 0 NA NA NA NA
5 p598 FKDHKHIDVKrsgrrrrrkrTRCYHIDPHH NA NA NA NA 0 NA NA NA
6 p458 FKDHKHIDVKrrrrrkrrgsTRCYHIDPHH NA NA NA NA NA 0 NA NA
7 p448 FKDHKHIDVKrrrrrgrskrTRCYHIDPHH NA NA NA NA NA NA 0 NA
8 p117 FKDHKHIDVKkrrrrsrrgrTRCYHIDPHH NA 0 NA NA NA NA NA NA
9 p232 FKDHKHIDVKrkrrrrsgrrTRCYHIDPHH NA NA NA NA NA NA NA 0
10 p464 FKDHKHIDVKrrrrrksrrgTRCYHIDPHH NA 0 NA NA NA NA NA NA
</code></pre>
<p>How can I achieve the same result with <a href="https://rdatatable.gitlab.io/data.table/" rel="nofollow noreferrer">data.table</a>?</p>
<p>I'm stuck here:</p>
<pre><code>library(data.table)
dt <- as.data.table(dat)
dt[,by = peptide, tot:=sum(status) ]
dt
</code></pre>
<p>with this result:</p>
<pre><code> ref_string peptide_name peptide status tot
1: K p47 FKDHKHIDVKgrrrskrrrrTRCYHIDPHH 0 0
2: Y p666 FKDHKHIDVKsrgrkrrrrrTRCYHIDPHH 0 0
3: Q p506 FKDHKHIDVKrrrrskrgrrTRCYHIDPHH 0 0
4: C p356 FKDHKHIDVKrrrgrrrrskTRCYHIDPHH 0 0
5: H p598 FKDHKHIDVKrsgrrrrrkrTRCYHIDPHH 0 0
6: A p458 FKDHKHIDVKrrrrrkrrgsTRCYHIDPHH 0 0
7: S p448 FKDHKHIDVKrrrrrgrskrTRCYHIDPHH 0 0
8: Y p117 FKDHKHIDVKkrrrrsrrgrTRCYHIDPHH 0 0
9: L p232 FKDHKHIDVKrkrrrrsgrrTRCYHIDPHH 0 0
10: Y p464 FKDHKHIDVKrrrrrksrrgTRCYHIDPHH 0 0
</code></pre>
<p>I don't know how to use filter and pivot_wider for data.table.</p>
| [
{
"answer_id": 74400447,
"author": "zephryl",
"author_id": 17303805,
"author_profile": "https://Stackoverflow.com/users/17303805",
"pm_score": 2,
"selected": false,
"text": "library(dplyr)\nlibrary(tidyr)\nlibrary(dtplyr)\n\ndat_dt <- lazy_dt(dat)\n\ndat_dt %>% \n group_by(peptide_name, peptide) %>% \n mutate(tot = sum(status)) %>% \n filter(tot == 0) %>% \n pivot_wider(names_from = ref_string, values_from = status) %>%\n select(-tot) %>% \n ungroup() %>%\n as_tibble()\n"
},
{
"answer_id": 74400465,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 4,
"selected": true,
"text": "data.table"
},
{
"answer_id": 74401297,
"author": "B. Christian Kamgang",
"author_id": 10848898,
"author_profile": "https://Stackoverflow.com/users/10848898",
"pm_score": 2,
"selected": false,
"text": "data.table"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8391698/"
] |
74,400,210 | <p>I'm working with some store procedures, one in particular, requires me to use a condition for a specific field of the select.
My select is like this:</p>
<pre><code> acc.AccountNum AS [Voucher_ID],
pol.Number AS [Policy_Number],
veh.Vehicle AS [VIN],
</code></pre>
<p>What I'm trying to do is change the column alias to the AS dynamically, which then amends based on a condition, I tried to insert an if like this:</p>
<pre><code>acc.AccountNum AS If(@x = 1){[Voucher_ID]} else {[Voucher_ID2]},
</code></pre>
<p>But it does not work,
I also tried a case but that didn't work either, is there a way to do this or do I have to create two distinct selects?</p>
| [
{
"answer_id": 74400447,
"author": "zephryl",
"author_id": 17303805,
"author_profile": "https://Stackoverflow.com/users/17303805",
"pm_score": 2,
"selected": false,
"text": "library(dplyr)\nlibrary(tidyr)\nlibrary(dtplyr)\n\ndat_dt <- lazy_dt(dat)\n\ndat_dt %>% \n group_by(peptide_name, peptide) %>% \n mutate(tot = sum(status)) %>% \n filter(tot == 0) %>% \n pivot_wider(names_from = ref_string, values_from = status) %>%\n select(-tot) %>% \n ungroup() %>%\n as_tibble()\n"
},
{
"answer_id": 74400465,
"author": "ThomasIsCoding",
"author_id": 12158757,
"author_profile": "https://Stackoverflow.com/users/12158757",
"pm_score": 4,
"selected": true,
"text": "data.table"
},
{
"answer_id": 74401297,
"author": "B. Christian Kamgang",
"author_id": 10848898,
"author_profile": "https://Stackoverflow.com/users/10848898",
"pm_score": 2,
"selected": false,
"text": "data.table"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16982267/"
] |
74,400,240 | <p>I'm working on an access query and kinda hit a dead end. I want to delete all duplicate rows in a table that have the same value in the columns Brand, SerialNr, Seats and LastRepair that have the value "2013" in the year column.</p>
<p>I'm trying to delete all rows that have duplicates in those columns and the year 2013 so there isnt a single one left. (Not just delete the duplicated so there is only one left but delete all instances so there is none left)</p>
<p>The original table looks like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Brand</th>
<th>SerialNr</th>
<th>Seats</th>
<th>Color</th>
<th>LastRepair</th>
<th>Year</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Blue</td>
<td>01.01.2020</td>
<td>2010</td>
</tr>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Red</td>
<td>01.01.2020</td>
<td>2010</td>
</tr>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Red</td>
<td>01.01.2020</td>
<td>2013</td>
</tr>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Green</td>
<td>01.01.2020</td>
<td>2013</td>
</tr>
<tr>
<td>Porsche</td>
<td>146</td>
<td>2</td>
<td>White</td>
<td>01.01.2022</td>
<td>2013</td>
</tr>
<tr>
<td>Ferrari</td>
<td>146</td>
<td>2</td>
<td>White</td>
<td>01.01.2022</td>
<td>2013</td>
</tr>
<tr>
<td>Volkswagen</td>
<td>147</td>
<td>4</td>
<td>Blue</td>
<td>01.01.2021</td>
<td>2017</td>
</tr>
<tr>
<td>Volkswagen</td>
<td>147</td>
<td>4</td>
<td>Red</td>
<td>01.01.2021</td>
<td>2013</td>
</tr>
<tr>
<td>Volkswagen</td>
<td>147</td>
<td>4</td>
<td>Orange</td>
<td>01.01.2021</td>
<td>2013</td>
</tr>
</tbody>
</table>
</div>
<p>And the outcome table should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Brand</th>
<th>SerialNr</th>
<th>Seats</th>
<th>Color</th>
<th>LastRepair</th>
<th>Year</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Blue</td>
<td>01.01.2020</td>
<td>2010</td>
</tr>
<tr>
<td>Ford</td>
<td>145</td>
<td>4</td>
<td>Red</td>
<td>01.01.2020</td>
<td>2010</td>
</tr>
<tr>
<td>Porsche</td>
<td>146</td>
<td>2</td>
<td>White</td>
<td>01.01.2022</td>
<td>2013</td>
</tr>
<tr>
<td>Ferrari</td>
<td>146</td>
<td>2</td>
<td>White</td>
<td>01.01.2022</td>
<td>2013</td>
</tr>
<tr>
<td>Volkswagen</td>
<td>147</td>
<td>4</td>
<td>Blue</td>
<td>01.01.2021</td>
<td>2017</td>
</tr>
</tbody>
</table>
</div>
<p>I tried doing it with <a href="https://stackoverflow.com/questions/17695467/finding-duplicates-in-access-with-more-than-2-columns-as-basis-and-results">this question</a> but I need the rows deleted if they have a duplicated value in the those columns so there isnt a single one left who has the same year.</p>
<p>I also tried to do a "find duplicates" query and make an outter join but was unsuccesful so far achieving the desired outcome. I'm thankful for any help.</p>
<pre><code>DELETE Exists (SELECT 1
FROM carTable As t2
WHERE t1.Brand = t2.Brand AND t1.SerialNr = t2.SerialNr AND t1.Seats = t2.Seats AND t1.LastRepair = t2.LastRepair
HAVING Count(*) > 1
), t1.[FilNr], *
FROM carTable AS t1, carTable
WHERE (((Exists (SELECT 1
FROM carTable As t2
WHERE t1.Brand = t2.Brand AND t1.SerialNr = t2.SerialNr AND t1.Seats = t2.Seats AND t1.LastRepair = t2.LastRepair
HAVING Count(*) > 1
))<>False) AND ((t1.[year])=2013));
</code></pre>
| [
{
"answer_id": 74400864,
"author": "Erik A",
"author_id": 7296893,
"author_profile": "https://Stackoverflow.com/users/7296893",
"pm_score": 2,
"selected": true,
"text": "EXISTS"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6254732/"
] |
74,400,245 | <p>I get a datetime value from api in this format: <code>2022-11-11T08:52:01.000000Z</code> I need to convert it to readable form with javascript.</p>
<p>I need this in any readable form, both time and date should be included</p>
| [
{
"answer_id": 74400317,
"author": "Erik Dreifaldt",
"author_id": 9540823,
"author_profile": "https://Stackoverflow.com/users/9540823",
"pm_score": 1,
"selected": false,
"text": "warning: pseudo code"
},
{
"answer_id": 74400337,
"author": "Vu Phung",
"author_id": 12040727,
"author_profile": "https://Stackoverflow.com/users/12040727",
"pm_score": 3,
"selected": true,
"text": "import moment from \"moment\"\n\nconst time = \"2022-11-11T08:52:01.000000Z\"\nconst formattedDate = moment(time, \"DD/MM/YYYY\")\nconsole.log(formattedDate)\n"
},
{
"answer_id": 74400493,
"author": "Mustapha Iconic",
"author_id": 19540318,
"author_profile": "https://Stackoverflow.com/users/19540318",
"pm_score": 1,
"selected": false,
"text": "import moment from 'moment';\nmoment('2022-11-11T08:52:01.000000Z').format(\"DD/MM/YY\")\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9663776/"
] |
74,400,271 | <p>I need help to rewrite some arrow functions to regular functions but right now my brain is totally stucked, I have some example code here from a rock paper scissors game I got from kyle, how would it look if I was to ditch the arrow function please somebody?</p>
<pre><code>selectionButtons.forEach(selectionButton => {
selectionButton.addEventListener('click', e => {
const selectionName = selectionButton.dataset.selection;
const selection = SELECTIONS.find(selection => selection.name === selectionName);
makeSelection(selection);
</code></pre>
<p>would it be as easy as?:</p>
<p><code>selectionButtons.forEach(selectionButton = function() {</code></p>
<p>or have I completely lost it?</p>
| [
{
"answer_id": 74400317,
"author": "Erik Dreifaldt",
"author_id": 9540823,
"author_profile": "https://Stackoverflow.com/users/9540823",
"pm_score": 1,
"selected": false,
"text": "warning: pseudo code"
},
{
"answer_id": 74400337,
"author": "Vu Phung",
"author_id": 12040727,
"author_profile": "https://Stackoverflow.com/users/12040727",
"pm_score": 3,
"selected": true,
"text": "import moment from \"moment\"\n\nconst time = \"2022-11-11T08:52:01.000000Z\"\nconst formattedDate = moment(time, \"DD/MM/YYYY\")\nconsole.log(formattedDate)\n"
},
{
"answer_id": 74400493,
"author": "Mustapha Iconic",
"author_id": 19540318,
"author_profile": "https://Stackoverflow.com/users/19540318",
"pm_score": 1,
"selected": false,
"text": "import moment from 'moment';\nmoment('2022-11-11T08:52:01.000000Z').format(\"DD/MM/YY\")\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19346065/"
] |
74,400,275 | <p>Im using Angular Material to build a table, which is supposed to have a menu and menu items for each row in the table. The <code>.html</code> file is</p>
<pre><code><!-- 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" *ngFor="let action of menuActions">
<button mat-menu-item>{{action}}</button>
</mat-menu>
</td>
</ng-container>
</code></pre>
<p>But the compiler is complaining that</p>
<pre><code>error TS2339: Property 'menu' does not exist on type 'TableComponent'.
19 <button mat-button [matMenuTriggerFor]="menu">
~~~~
</code></pre>
<p>If i look at the documentation for menu, I can't see any declarations of this specific attribute in the examples:
<a href="https://material.angular.io/components/menu/examples" rel="nofollow noreferrer">https://material.angular.io/components/menu/examples</a></p>
<p>Im obviously missing something (noob at Angular and Material) but I thought <code>menu</code> in the button referred to the <code>#menu</code> DOM element in the <code><mat-menu></code> tag?</p>
<p>I have no specification of the MatMenu in the ts file. Do I need to add that?</p>
| [
{
"answer_id": 74400428,
"author": "Carles Ramos",
"author_id": 13309394,
"author_profile": "https://Stackoverflow.com/users/13309394",
"pm_score": 2,
"selected": true,
"text": "<ng-container *ngIf=\"rowActionIcon?.length\" [matColumnDef]=\"rowActionIcon\">\n <th mat-header-cell *matHeaderCellDef></th>\n <td mat-cell class=\"action-column\" *matCellDef=\"let element\" [id]=\"rowActionIcon\" (click)=\"emitRowAction(element)\">\n <button mat-button [matMenuTriggerFor]=\"menu\">\n <mat-icon>{{rowActionIcon}}</mat-icon>\n </button>\n <mat-menu #menu=\"matMenu\">\n <button mat-menu-item *ngFor=\"let action of menuActions\">{{action}}</button>\n </mat-menu>\n </td>\n</ng-container>\n"
},
{
"answer_id": 74400437,
"author": "Đỗ văn Thắng",
"author_id": 11303128,
"author_profile": "https://Stackoverflow.com/users/11303128",
"pm_score": 0,
"selected": false,
"text": "<mat-menu #menu=\"matMenu\" *ngFor=\"let action of menuActions\">\n <button mat-menu-item>{{action}}</button>\n</mat-menu>\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1230911/"
] |
74,400,277 | <p>Can I ask for help on something that has me really puzzled? I have written a small function to demonstrate:</p>
<pre class="lang-cs prettyprint-override"><code>void Test()
{
CheckBox checkBox1 = new CheckBox();
string temp = checkBox1.Name;
}
</code></pre>
<p><code>temp</code> is an empty string after this has run. Since "checkBox1" is not the Name of the control what is it?</p>
| [
{
"answer_id": 74414369,
"author": "IVSoftware",
"author_id": 5438626,
"author_profile": "https://Stackoverflow.com/users/5438626",
"pm_score": 0,
"selected": false,
"text": "Name"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14109587/"
] |
74,400,284 | <p>I have created a web app using razor pages in ASP.NET Core 6 and I am reaching a problem when it comes to adding a new razor pages link into the _Layout.cshtml. Every time I try to test the website and press the link to new page I added, it does not send me to that page.</p>
<p>I have looked into the razor pages properties and matched the Build property with Content hoping that was the reason why it was not working but I was unsuccessful.</p>
<p>I have also tried adding to the page link so that it can clearly find it, but it did not work.</p>
<pre><code> <li><a asp-page="Pages/Login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</code></pre>
| [
{
"answer_id": 74414369,
"author": "IVSoftware",
"author_id": 5438626,
"author_profile": "https://Stackoverflow.com/users/5438626",
"pm_score": 0,
"selected": false,
"text": "Name"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476162/"
] |
74,400,295 | <p>Am doing a task where am supposed to used getline function read input from a user from the terminal. Here is my code:</p>
<pre><code>int main(int ac, char **av)
{
printf("Write something: \n");
char **buf = NULL;
size_t buf_size = 0;
ssize_t bytes_read = getline(buf, &buf_size, stdin);
if (bytes_read != -1)
write(STDOUT_FILENO, buf, buf_size);
else
printf("An error occured\n");
free(buf);
return (0);
}
</code></pre>
<p>From the code above. My program displayed the text: An error occurred.
Did some code refactoring and this is what I came up with:</p>
<pre><code>int main(int ac, char **av)
{
printf("Write something: \n");
char *buf = NULL;
size_t buf_size = 0;
ssize_t bytes_read = getline(&buf, &buf_size, stdin);
if (bytes_read != -1)
write(STDOUT_FILENO, buf, buf_size);
else
printf("An error occured\n");
free(buf);
return (0);
}
</code></pre>
<p>Voila! The code displayed whatever was inputted, just what I wanted. So I fixed my the issue. But what am trying to understand is what's wrong the first code snippet? An it is right to do this?:
<code>char **name = "John Doe";</code>
or
<code>char **name = NULL;</code></p>
<p>I did some quick test on an online compiler. Here is the code:</p>
<pre><code>int main() {
// Write C code here
char **name = "John Doe";
printf("%p\n", name); //0x55f5f9890004
printf("%p\n", *name); //0x656f44206e686f4a
printf("%c\n", *name); //J
printf("%p", "John Doe"); //0x55f5f9890004
return 0;
}
</code></pre>
<p>I realised that the double pointer was just treated as a single char pointer. Not sure if my finding are right. If you can give a better explanation the above main function that would be cool.</p>
| [
{
"answer_id": 74400387,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 0,
"selected": false,
"text": "char *buf"
},
{
"answer_id": 74400448,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 2,
"selected": true,
"text": " char *buf = NULL; \n size_t buf_size = 0; \n \n ssize_t bytes_read = getline(&buf, &buf_size, stdin); \n"
},
{
"answer_id": 74400690,
"author": "0___________",
"author_id": 6110094,
"author_profile": "https://Stackoverflow.com/users/6110094",
"pm_score": 0,
"selected": false,
"text": "int main(int ac, char **av)\n{\n printf(\"Write something: \\n\");\n char *realBuf = NULL\n char **buf = &realBuf;\n size_t buf_size = 0;\n\n ssize_t bytes_read = getline(buf, &buf_size, stdin);\n if (bytes_read != -1)\n write(STDOUT_FILENO, *buf, buf_size);\n else\n printf(\"An error occured\\n\");\n free(*buf);\n return (0);\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13871283/"
] |
74,400,296 | <p>I installed Python on a new computer and unfortunately I get an error message from a code that I had been using for quite some time. It is about the 'match' statement. Here is the code:</p>
<pre><code>import os
def save(df, filepath):
dir, filename = os.path.split(filepath)
os.makedirs(dir, exist_ok=True)
_, ext = os.path.splitext(filename)
match ext:
case ".pkl":
df.to_pickle(filepath)
case ".csv":
df.to_csv(filepath)
case _:
raise NotImplementedError(f"Saving as {ext}-files not implemented.")
</code></pre>
<p>Now my question is, how can I tackle the problem of "Python version 3.9 does not support match statements"?</p>
| [
{
"answer_id": 74400348,
"author": "noxdafox",
"author_id": 1794497,
"author_profile": "https://Stackoverflow.com/users/1794497",
"pm_score": 0,
"selected": false,
"text": "MATCH = {\n '.pkl': df.to_pickle\n '.csv': df.to_csv\n}\n\n_, ext = os.path.splitext(filename)\n\ntry:\n MATCH[ext](filepath)\nexcept KeyError:\n raise NotImplementedError(f\"Saving as {ext}-files not implemented.\")\n"
},
{
"answer_id": 74400388,
"author": "0x0fba",
"author_id": 20339407,
"author_profile": "https://Stackoverflow.com/users/20339407",
"pm_score": 2,
"selected": true,
"text": "if"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7133942/"
] |
74,400,327 | <p>I want to iterate over a list of lists of dictionaries:</p>
<pre><code>data = [
{'name': 'sravan'},
{'name': 'bobby'},
{'name': 'ojsawi', 'number': '123'},
{'name': 'rohith', 'number': '456'},
{'name': 'gnanesh', 'number': '123'}
]
</code></pre>
<p>Furthermore I want to check each entry if there is a key number where the value is <code>123</code>.
If so, I want to append the value of name of this entry in a new list
which would be <code>'ojsawi'</code> and <code>'gnanesh'</code> in the above case.
Else, I want to append 0 in the new list.</p>
<p>This means, the final <code>new_list</code> with the appended values should look like this:
<code> new_list = {0, 0, 'ojsawi', 0, 'gnanesh'}</code></p>
<p>I have tried different versions/possibillities with 2D for loops and lambdas etc. but I think the main problem is that the lists have different sizes. Any help/tipps would be much appreciated.</p>
| [
{
"answer_id": 74400356,
"author": "Celius Stingher",
"author_id": 11897007,
"author_profile": "https://Stackoverflow.com/users/11897007",
"pm_score": 3,
"selected": true,
"text": "new_list = [x.get('name') if x.get('number') == '123' else 0 for x in data]\n"
},
{
"answer_id": 74400498,
"author": "Felix An",
"author_id": 12946280,
"author_profile": "https://Stackoverflow.com/users/12946280",
"pm_score": 0,
"selected": false,
"text": "map()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476296/"
] |
74,400,339 | <p>I am currently learning Kotlin and am working through the <a href="https://play.kotlinlang.org/byExample/" rel="nofollow noreferrer">By Example Guide</a>. In the chapter Functional/Higher-Order Functions it explained how functions themselves can return functions with this example:</p>
<pre><code>fun operation(): (Int) -> Int {
return ::square
}
fun square(x: Int) = x * x
fun main() {
val func = operation()
println(func(2))
}
</code></pre>
<p>Since I had previously learned to check the type of a variable in a "when" block, I tried to do the same here. Checking if a variable is of type function.</p>
<pre><code>fun operation(): (Int) -> Int {
return ::square
}
fun square(x: Int) = x * x
fun main() {
val func = operation()
when (func){
is fun -> println(func(2))
else -> println("Not a function")
}
}
</code></pre>
<p>But this throws an error "Type expected", I guess because fun in itself is not a type.</p>
<p>I tried searching for things like "kotlin check if variable is function" but all I could find where guides on how to check for primitives or classes, nothing even mentioned functions.</p>
| [
{
"answer_id": 74400647,
"author": "Nikolai Shevchenko",
"author_id": 2224047,
"author_profile": "https://Stackoverflow.com/users/2224047",
"pm_score": 1,
"selected": false,
"text": "is Function<*>"
},
{
"answer_id": 74400745,
"author": "Sweeper",
"author_id": 5133585,
"author_profile": "https://Stackoverflow.com/users/5133585",
"pm_score": 3,
"selected": true,
"text": "func"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14529789/"
] |
74,400,369 | <p>So I'm currently trying to get a certain attribute just by the content of the HTML element.
I know how to get an attribute by another attribute in the same HTML section. But this time I need the attribute by the content of the section.</p>
<p>"https://www.skatedeluxe.ch/de/adidas-skateboarding-busenitz-vulc-ii-schuh-white-collegiate-navy-bluebird_p155979?cPath=216&value[55][]=744" this is the link I try to scrape.</p>
<p>So I'm trying to get the "data-id" just by the " US 12"</p>
<p><a href="https://i.stack.imgur.com/Yosd8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yosd8.png" alt="This is how it looks" /></a></p>
<p>What I tried to do is getting it similar to how I'd get an attribute by an attribute.
This is my code:</p>
<pre><code>def carting ():
a = session.get(producturl, headers=headers, proxies=proxy)
soup = BeautifulSoup(a.text, "html.parser")
product_id = soup.find("div", {"class" : "product-grid"})["data-product-id"]
option_id = soup.find("option", {"option" : " US 12"})["data-id"]
print(option_id)
carting()
</code></pre>
<p>This is what I get:</p>
<pre><code>'NoneType' object is not subscriptable
</code></pre>
<p>I know that the code is wrong and doesn't work like I wrote it but I cannot figure how else I'm supposed to do it.
Would appreciate help and ofc if you need more information just ask.
Kind Regards</p>
| [
{
"answer_id": 74400458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 2,
"selected": false,
"text": "import requests\nfrom bs4 import BeautifulSoup\n\n\nurl = \"https://www.skatedeluxe.ch/de/adidas-skateboarding-busenitz-vulc-ii-schuh-white-collegiate-navy-bluebird_p155979?cPath=216&value[55][]=744\"\nsoup = BeautifulSoup(requests.get(url).content, \"html.parser\")\n\nsizes = soup.select_one(\"#product-size-chooser\")\nprint(sizes.select_one('option:-soup-contains(\"US 12\")')[\"data-id\"])\n"
},
{
"answer_id": 74400553,
"author": "TomerG",
"author_id": 1885248,
"author_profile": "https://Stackoverflow.com/users/1885248",
"pm_score": 1,
"selected": false,
"text": "soup.find(\"option\", text=re.compile(\"US 12\"))[\"data-id\"]\n"
},
{
"answer_id": 74400614,
"author": "Hanna",
"author_id": 17246406,
"author_profile": "https://Stackoverflow.com/users/17246406",
"pm_score": 1,
"selected": false,
"text": "# find all the option tags that have the attribute \"data-id\"\nfor option in soup.find_all(\"option\", attrs={'data-id':True}):\n if option.text.strip() == 'US 12':\n print(option.text.strip(), '/', option['data-id'])\n break\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20133611/"
] |
74,400,393 | <p>This is my issue when I try to Login on Emulator!
<a href="https://i.stack.imgur.com/3Fv7l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Fv7l.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/GAuS4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GAuS4.png" alt="enter image description here" /></a></p>
<p>How do I resolve this?</p>
| [
{
"answer_id": 74400458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 2,
"selected": false,
"text": "import requests\nfrom bs4 import BeautifulSoup\n\n\nurl = \"https://www.skatedeluxe.ch/de/adidas-skateboarding-busenitz-vulc-ii-schuh-white-collegiate-navy-bluebird_p155979?cPath=216&value[55][]=744\"\nsoup = BeautifulSoup(requests.get(url).content, \"html.parser\")\n\nsizes = soup.select_one(\"#product-size-chooser\")\nprint(sizes.select_one('option:-soup-contains(\"US 12\")')[\"data-id\"])\n"
},
{
"answer_id": 74400553,
"author": "TomerG",
"author_id": 1885248,
"author_profile": "https://Stackoverflow.com/users/1885248",
"pm_score": 1,
"selected": false,
"text": "soup.find(\"option\", text=re.compile(\"US 12\"))[\"data-id\"]\n"
},
{
"answer_id": 74400614,
"author": "Hanna",
"author_id": 17246406,
"author_profile": "https://Stackoverflow.com/users/17246406",
"pm_score": 1,
"selected": false,
"text": "# find all the option tags that have the attribute \"data-id\"\nfor option in soup.find_all(\"option\", attrs={'data-id':True}):\n if option.text.strip() == 'US 12':\n print(option.text.strip(), '/', option['data-id'])\n break\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476080/"
] |
74,400,434 | <p>I am trying to validate the json for required fields using python. I am doing it manually like iterating through the json reading it. Howerver i am looking for more of library / generic solution to handle all scenarios.</p>
<p>For example I want to check in a list, if a particular attribute is available in all the list items.</p>
<p>Here is the sample json which I am trying to validate.</p>
<pre><code>{
"service": {
"refNumber": "abc",
"item": [{
"itemnumber": "1",
"itemloc": "uk"
}, {
"itemnumber": "2",
"itemloc": "us"
}]
}
}
</code></pre>
<p>I want to validate if I have refNumber and itemnumber in all the list items.</p>
| [
{
"answer_id": 74400458,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 2,
"selected": false,
"text": "import requests\nfrom bs4 import BeautifulSoup\n\n\nurl = \"https://www.skatedeluxe.ch/de/adidas-skateboarding-busenitz-vulc-ii-schuh-white-collegiate-navy-bluebird_p155979?cPath=216&value[55][]=744\"\nsoup = BeautifulSoup(requests.get(url).content, \"html.parser\")\n\nsizes = soup.select_one(\"#product-size-chooser\")\nprint(sizes.select_one('option:-soup-contains(\"US 12\")')[\"data-id\"])\n"
},
{
"answer_id": 74400553,
"author": "TomerG",
"author_id": 1885248,
"author_profile": "https://Stackoverflow.com/users/1885248",
"pm_score": 1,
"selected": false,
"text": "soup.find(\"option\", text=re.compile(\"US 12\"))[\"data-id\"]\n"
},
{
"answer_id": 74400614,
"author": "Hanna",
"author_id": 17246406,
"author_profile": "https://Stackoverflow.com/users/17246406",
"pm_score": 1,
"selected": false,
"text": "# find all the option tags that have the attribute \"data-id\"\nfor option in soup.find_all(\"option\", attrs={'data-id':True}):\n if option.text.strip() == 'US 12':\n print(option.text.strip(), '/', option['data-id'])\n break\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16863914/"
] |
74,400,456 | <p>Consider the following code:</p>
<pre class="lang-cs prettyprint-override"><code>public record Foo
{
public required string A { get; init; }
public required string B { get; init; }
}
public record Bar : Foo
{
public Bar()
{
A = "TEST";
}
}
var bar = new Bar
{
B = "ANOTHER TEST"
}
</code></pre>
<p>In this situation the compiler will say that field <code>A</code> is not set, while it is clearly set it just does not know about it. Is there any workaround for this?</p>
| [
{
"answer_id": 74400567,
"author": "Ilya Chernomordik",
"author_id": 1671558,
"author_profile": "https://Stackoverflow.com/users/1671558",
"pm_score": 1,
"selected": false,
"text": "public record Foo(string A)\n{\n public required string B { get; init; }\n}\n\npublic record Bar : Foo(\"TEST\")\n{\n}\n"
},
{
"answer_id": 74400728,
"author": "Amit Panchauly",
"author_id": 7533677,
"author_profile": "https://Stackoverflow.com/users/7533677",
"pm_score": 0,
"selected": false,
"text": "public record Foo\n{\n public string A { get; init; }\n public required string B { get; init; }\n}\npublic record Bar : Foo\n{\n public Bar() \n {\n A = \"TEST\";\n }\n}\nvar bar = new Bar\n {\n B = \"ANOTHER TEST\"\n };\n"
},
{
"answer_id": 74401630,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 3,
"selected": true,
"text": "Foo"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1671558/"
] |
74,400,463 | <p>I was trying to map a pattern-restricted simpleType</p>
<pre><code><xs:simpleType name="exampleType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3,6}"/>
</xs:restriction>
</xs:simpleType>
</code></pre>
<p>to an enum class (with values based on some specification document):</p>
<pre><code><jaxb:bindings node="//xs:simpleType[@name='ExampleType']">
<jaxb:typesafeEnumClass name="EnumExample">
<jaxb:typesafeEnumMember value="1" name="description_1" />
....
</jaxb:typesafeEnumClass>
</jaxb:bindings>
</code></pre>
<p>but got</p>
<pre><code>com.sun.istack.SAXParseException2: enum class customization is specified on a type that has no enumeration facet.
</code></pre>
<p>Is that or something similar possible somehow?</p>
| [
{
"answer_id": 74400567,
"author": "Ilya Chernomordik",
"author_id": 1671558,
"author_profile": "https://Stackoverflow.com/users/1671558",
"pm_score": 1,
"selected": false,
"text": "public record Foo(string A)\n{\n public required string B { get; init; }\n}\n\npublic record Bar : Foo(\"TEST\")\n{\n}\n"
},
{
"answer_id": 74400728,
"author": "Amit Panchauly",
"author_id": 7533677,
"author_profile": "https://Stackoverflow.com/users/7533677",
"pm_score": 0,
"selected": false,
"text": "public record Foo\n{\n public string A { get; init; }\n public required string B { get; init; }\n}\npublic record Bar : Foo\n{\n public Bar() \n {\n A = \"TEST\";\n }\n}\nvar bar = new Bar\n {\n B = \"ANOTHER TEST\"\n };\n"
},
{
"answer_id": 74401630,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 3,
"selected": true,
"text": "Foo"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1124509/"
] |
74,400,479 | <p>Hello guys I'm trying to create a function that returns a list out of a string ((((Without the space))))
I'm using the replace function to remove the space however I'm still getting a space</p>
<pre class="lang-py prettyprint-override"><code>def str2list(argstr):
retlist = []
for c in argstr:
c=c.replace(" ", "")
retlist.append(c)
return retlist
print(str2list('abc efg'))
</code></pre>
<pre><code>output: ['a', 'b', 'c', '', 'e', 'f', 'g']
desired output: ['a', 'b', 'c', 'e', 'f', 'g']
</code></pre>
| [
{
"answer_id": 74400506,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 1,
"selected": false,
"text": "inp = \"abc efg\"\nletters = re.findall(r'[a-z]', inp, flags=re.I)\nprint(letters) # ['a', 'b', 'c', 'e', 'f', 'g']\n"
},
{
"answer_id": 74400533,
"author": "tripleee",
"author_id": 874188,
"author_profile": "https://Stackoverflow.com/users/874188",
"pm_score": 2,
"selected": true,
"text": "\" \""
},
{
"answer_id": 74400536,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": false,
"text": "def str2list(argstr):\n return [c for c in argstr if c != ' ']\n"
},
{
"answer_id": 74400543,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 1,
"selected": false,
"text": "def str2list(argstr):\n return [x for x in argstr if x != \" \"]\n"
},
{
"answer_id": 74400564,
"author": "CamS",
"author_id": 16307981,
"author_profile": "https://Stackoverflow.com/users/16307981",
"pm_score": 0,
"selected": false,
"text": "if c == ' '"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20157026/"
] |
74,400,484 | <p>I'm struggling every day with 1035 tables in a database and every table has many columns. Some columns are quite long although it was not necessary to be so long.</p>
<p>For example in the table <code>Messages</code> which contains the emails, the columns <code>MailTo</code> and <code>MailFrom</code> are <code>nvarchar(400)</code> or the <code>Subject</code> is defined as <code>nvarchar(500)</code>.</p>
<p>Suppose that I want to see the table using a simple query:</p>
<pre><code>SELECT TOP 100 *
FROM Messages;
</code></pre>
<p>but most columns have long length and they do not fit to the monitor. I must scroll left and right to see the table correctly and because the scrollbars are not thumb-tracking it is very boring.</p>
<p>I can use the select query like:</p>
<pre><code>SELECT TOP 100
LEFT(Subject, 20) as Subject_,
LEFT(MailFrom, 20) as MailFrom_,
LEFT(MailTo, 20) as MailTo_,
Deleted, DeletedByUser, Status, MsgType, *
FROM Messages;
</code></pre>
<p>to be able to see the table better, but the problem is that I do not want to write such a complicated select statement every time that I want just seeing each table.</p>
<p>It would be much simpler for me to see the tables like this:</p>
<pre><code>SELECT TOP 100 LimitLength(*, 20)
FROM A_Table_Name;
</code></pre>
<p>because I use select statement many times a day to see the database.</p>
<p>By the way, I have to use a software called SQL-Spy which my company has written to be able to access the database. This software is written by Delphi and uses a simple TDBGrid to show the tables.</p>
| [
{
"answer_id": 74400618,
"author": "Venkataraman R",
"author_id": 634935,
"author_profile": "https://Stackoverflow.com/users/634935",
"pm_score": 1,
"selected": false,
"text": "Tools > Options"
},
{
"answer_id": 74403105,
"author": "Pieter B",
"author_id": 1107597,
"author_profile": "https://Stackoverflow.com/users/1107597",
"pm_score": 0,
"selected": false,
"text": "CREATE VIEW MessagesView AS\nSELECT TOP 100\n LEFT(Subject, 20) as Subject_,\n LEFT(MailFrom, 20) as MailFrom_,\n LEFT(MailTo, 20) as MailTo_,\n Deleted, DeletedByUser, Status, MsgType, *\nFROM Messages;\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20288923/"
] |
74,400,512 | <p>I am learning to use SQL in R.
I want to select cities that are more northern than Berlin from a dataset.</p>
<p>For this, I have tried:</p>
<pre><code>sql4 = "SELECT Name, Latitude FROM city HAVING Latitude > Latitude(Berlin)"
result4 = dbSendQuery(con, sql4)
df4 = dbFetch(result4)
head(df4)
</code></pre>
<p>and</p>
<pre><code>sql4 = "SELECT Name, Latitude FROM city HAVING Latitude > (Name IN 'Berlin')"
result4 = dbSendQuery(con, sql4)
df4 = dbFetch(result4)
head(df4)
</code></pre>
<p>Neither syntax works unfortunatley.
So my question is: How do I select all cities "north from Berlin", i.e. latitude value higher than that of the Name row 'Berlin'? Is there a different, better approach?</p>
| [
{
"answer_id": 74400579,
"author": "CIE Pro Suhas",
"author_id": 16195593,
"author_profile": "https://Stackoverflow.com/users/16195593",
"pm_score": 0,
"selected": false,
"text": "SELECT Name, Latitude FROM city WHERE Latitude = (SELECT Latitude from city WHERE Name = \"Berlin\")\n"
},
{
"answer_id": 74400583,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 1,
"selected": false,
"text": "city"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4636470/"
] |
74,400,514 | <p>Given a class Object1</p>
<pre><code>class Object1 {
private Object2 object2;
private List<Object3> object3s;
}
</code></pre>
<p>and a <code>List<Object1></code></p>
<p>cuurent implementation</p>
<pre><code>Map<Object3, Object2> accountMap = new HashMap<>();
for (Object1 dto : accounts) {
dto.getObject3s()
.forEach(dto -> accountMap.put(dto, dto.getObject2()));
}
</code></pre>
<p>How do I create a <code>Map<Object3, Object2></code> preferably in a stream?</p>
| [
{
"answer_id": 74400716,
"author": "khelwood",
"author_id": 3890632,
"author_profile": "https://Stackoverflow.com/users/3890632",
"pm_score": 3,
"selected": false,
"text": "Map<Object3, Object2> map = list.stream()\n .flatMap(o1 -> o1.object3s.stream().map(o3 -> Map.entry(o3, o1.object2)))\n .collect(Collectors.toMap(Entry::getKey, Entry::getValue));\n"
},
{
"answer_id": 74400850,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 1,
"selected": false,
"text": "Object3"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3103115/"
] |
74,400,545 | <p>I am working on a app where user can logged into a app and can enter a text in a textformfileld it and can also apply different fontstyle and font family and generate a image from it.</p>
<p>is it possible ?</p>
<p>Any help would be highly appreciated</p>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6708100/"
] |
74,400,584 | <p>So I have these selectors:</p>
<pre><code>cy.get(':nth-child(1) > abc-51 > xyz')
cy.get(':nth-child(2) > abc-51 > xyz')
cy.get(':nth-child(3) > abc-51 > xyz')
</code></pre>
<p>How do I only use <code>cy.get(':nth-child(1)')</code> or <code>cy.get(':nth-child(2)')</code> instead of whole thing because the issue is <code>abc-51</code> keeps changing like it will become <code>abc-43</code>, etc. so tests keeps on failing.</p>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17993800/"
] |
74,400,637 | <p>Consider a table like this -</p>
<pre><code>data = {'Name': {0: 'Alex',
1: 'Smith',
2: 'Federico',
3: 'George',
4: 'Ram',
5: 'Helen',
6: 'Mike',
7: 'Mark',
8: 'Alex',
9: 'Smith',
10: 'Federico',
11: 'George',
12: 'Ram',
13: 'Helen',
14: 'Mike',
15: 'Mark',
16: 'Alex',
17: 'Smith',
18: 'Federico',
19: 'George',
20: 'Ram',
21: 'Helen',
22: 'Mike',
23: 'Mark',
24: 'Alex',
25: 'Smith',
26: 'Federico',
27: 'George',
28: 'Ram',
29: 'Helen',
30: 'Mike',
31: 'Mark',
32: 'Alex',
33: 'Smith',
34: 'Federico',
35: 'George',
36: 'Ram',
37: 'Helen'},
'Category': {0: 'A',
1: 'A',
2: 'A',
3: 'A',
4: 'A',
5: 'A',
6: 'A',
7: 'A',
8: 'B',
9: 'B',
10: 'B',
11: 'B',
12: 'B',
13: 'B',
14: 'B',
15: 'B',
16: 'C',
17: 'C',
18: 'C',
19: 'C',
20: 'C',
21: 'C',
22: 'C',
23: 'C',
24: 'D',
25: 'D',
26: 'D',
27: 'D',
28: 'D',
29: 'D',
30: 'D',
31: 'D',
32: 'E',
33: 'E',
34: 'E',
35: 'E',
36: 'E',
37: 'E'},
'Value': {0: 125,
1: 399,
2: 129,
3: 147,
4: 59,
5: 169,
6: 94,
7: 142,
8: 133,
9: 54,
10: 86,
11: 49,
12: 49,
13: 64,
14: 88,
15: 65,
16: 35,
17: 89,
18: 72,
19: 62,
20: 59,
21: 198,
22: 59,
23: 109,
24: 147,
25: 108,
26: 164,
27: 110,
28: 70,
29: 321,
30: 256,
31: 58,
32: 178,
33: 121,
34: 65,
35: 251,
36: 204,
37: 303}}
</code></pre>
<p>I have used plotly express to plot a facetted scatter plot where each sub-plot is based on the Category column. One subplot is shown here -</p>
<p><a href="https://i.stack.imgur.com/oBflC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oBflC.png" alt="Facet sub plot for category A" /></a></p>
<p>How can I add an annotation for ONLY those values that are either above a certain value or max value within that category in plotly express?</p>
<p>My pseudo code is as below -</p>
<pre><code>d = pd.read_csv(fileName.csv)
fig = px.scatter(d[d['Category']=='A'], x="Name", y="Value", facet_col="Category")
fig.update_layout(font_family="Rockwell",
template='plotly_dark', title='Values with category A')
fig.update_xaxes(showticklabels=True, visible=True, showgrid=False)
fig.show()
</code></pre>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9606744/"
] |
74,400,653 | <p>I'm new to python and django
What is the correct syntax to render number and text?
I want to get the name and add 2 numbers from addition.html and print it back to results.html</p>
<p>I tried this code</p>
<pre><code>def add(request):
my_context = {
'fname' : request.GET['first_name'],
'val1' : int(request.GET['num1']),
'val2' : int(request.GET['num2']),
'res' : val1 + val2
}
return render(request, "result.html",my_context)
</code></pre>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476548/"
] |
74,400,667 | <p>Background: My application receives asynchronous sensor data from a variety of IoT devices, displays it in several windows, and manages a physical system based on the data. Data are not archived. I am currently managing the data a C# dataset which contains several different datatables, each with just one row. The datatable structures never change (add, remove rows, etc.) but individual values change constantly. I am using a dataset/datatables architecture because its change notification plumbing is transparent; value updates are propagated throughout the application automatically and GUI databinding is easy.</p>
<p>Problem: Asynchronous updates to datatables are not thread-safe and eventually the dataset gets corrupted because multiple threads are making changes simultaneously.</p>
<p>Question: How can I consume asynchronous, dynamic data in a thread-safe manner and propagate changed values throughout my application... without complex plumbing?</p>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19958209/"
] |
74,400,674 | <p>This is my current code (see image)
I need my OwnProfile function to wait for my GetUsername function to finish reading data from firebase before continuing.
I tried async await, but it is not working as shown in the terminal where line 52 and 54 are used before GetUsername has gotten the data.</p>
<p>Anyone got any tips to fix this?</p>
<p><a href="https://i.stack.imgur.com/xZqt7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xZqt7.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74404859,
"author": "BarisY",
"author_id": 14144819,
"author_profile": "https://Stackoverflow.com/users/14144819",
"pm_score": 2,
"selected": true,
"text": "class MyHomePage extends StatefulWidget {\n const MyHomePage({super.key, required this.title});\n\n final String title;\n\n @override\n State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n TextEditingController controller = TextEditingController();\n Image? img;\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.stretch,\n children: <Widget>[\n TextFormField(\n controller: controller,\n ),\n ElevatedButton(onPressed: _onPressedButton, child: const Text(\"Create Image\")),\n Container(width: 200, height: 200, color: Colors.blueGrey, child: img ?? Container())\n ],\n ),\n ),\n );\n }\n\n void getCanvasImage(String str) async {\n var builder = ParagraphBuilder(ParagraphStyle(fontStyle: FontStyle.normal));\n builder.addText(str);\n Paragraph paragraph = builder.build();\n paragraph.layout(const ParagraphConstraints(width: 100));\n\n final recorder = PictureRecorder();\n var newCanvas = Canvas(recorder);\n\n newCanvas.drawParagraph(paragraph, Offset.zero);\n\n final picture = recorder.endRecording();\n var res = await picture.toImage(100, 100);\n ByteData? data = await res.toByteData(format: ImageByteFormat.png);\n\n if (data != null) {\n img = Image.memory(Uint8List.view(data.buffer));\n }\n\n setState(() {});\n }\n\n void _onPressedButton() {\n getCanvasImage(controller.text);\n }\n}\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19323592/"
] |
74,400,713 | <p>I'm getting Array of objects inside useEffect:
<a href="https://i.stack.imgur.com/fgjZ1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fgjZ1.png" alt="enter image description here" /></a></p>
<p>Then I'm trying to map it and render:
<a href="https://i.stack.imgur.com/dPR5e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPR5e.png" alt="enter image description here" /></a></p>
<p>And I'm getting the result that it doesn't render it. Firstly it get's an empty Array as default and when State changes in useEffect it doesn't rerender it. Why and how to solve it?
(Next.js + React.js maybe some troubles with next? )</p>
| [
{
"answer_id": 74400777,
"author": "Vedran",
"author_id": 14662161,
"author_profile": "https://Stackoverflow.com/users/14662161",
"pm_score": 0,
"selected": false,
"text": "if(!token) { //you're checking if token is already set, so you don't get into a loop\n//your code here\n}, [token] //you want your component to re-render in case of a token change, which will happen only on first setToken because you're checking if token is already set above.\n"
},
{
"answer_id": 74400917,
"author": "Moussa Bistami",
"author_id": 15628525,
"author_profile": "https://Stackoverflow.com/users/15628525",
"pm_score": 2,
"selected": true,
"text": "tokens"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3498235/"
] |
74,400,724 | <p>i trying run multipe processing with ThreadPool and i have error <code>maximum recursion depth exceeded</code></p>
<p>this is my code:</p>
<pre><code>def extract_all_social_link(bio_url):
data = extract_all_social_link(bio_url)
return data
def run_extract_all_social_link(df, max_count, displays_steps = 1000):
tt = time.time()
user_data = []
with concurrent.futures.ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
future_to_url = dict()
cnt = 0
for _, row in df.iterrows():
bio_url = row["bio_url"]
if cnt > max_count:
break
if pd.isna(bio_url):
continue
future = executor.submit(extract_all_social_link, bio_url)
future_to_url[future] = (bio_url)
cnt += 1
future_iter = concurrent.futures.as_completed(future_to_url)
total = len(future_to_url)
for cnt, future in tqdm(enumerate(future_iter), total=total):
if (cnt+1) % displays_steps == 0:
tt1 = time.time()
print(f"{cnt+1} requests in {tt1 - tt:.3f} seconds")
tt = tt1
bio_url = future_to_url[future]
try:
data = future.result()
except Exception as exc:
print(f"{bio_url} generated an exception: {exc}")
return user_data
</code></pre>
<p>`</p>
<p>and this is error:</p>
<pre><code>generated an exception: maximum recursion depth exceeded
</code></pre>
<p>how can i fix it?</p>
| [
{
"answer_id": 74401848,
"author": "0x0fba",
"author_id": 20339407,
"author_profile": "https://Stackoverflow.com/users/20339407",
"pm_score": 1,
"selected": false,
"text": "extract_all_social_link()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15336233/"
] |
74,400,784 | <p>I have a lambda proxy function (A) working along with API Gateway that I use to store some data in a remote database. I have another lambda function (B) that processes some data and I wish to reuse A to save data in the database.</p>
<p>I am therefore invoking A from B with a payload. I am able to invoke from B only if I convert this payload from a dictionary to a json it seems. Function A works fine when working along with API Gateway but when I invoke it from B I get an error when I do:</p>
<pre><code>body = json.loads(event['body']) # [ERROR] TypeError: the JSON object must be str, bytes or bytearray, not dict
</code></pre>
<p>Let's say this is the code I use in B to invoke A:</p>
<pre><code>def lambda_handler(event, context):
lambda_payload = {
'headers': {},
'response': False,
'queryStringParameters': {},
'body': { 'user_id' : 2, 'payload' : {'name': "James", 'age': 35}}
}
lambda_client.invoke(FunctionName='A',
InvocationType='RequestResponse',
Payload=json.dumps(lambda_payload))
</code></pre>
<p>And the following is function A:</p>
<pre><code>def lambda_handler(event, context):
body = json.loads(event['body'])
...
</code></pre>
<p>I would prefer not having to change A but do the changes in B if possible. But if there is no other way I will handle it in A of course. How could I solve this? I am confused with the event type.</p>
| [
{
"answer_id": 74401848,
"author": "0x0fba",
"author_id": 20339407,
"author_profile": "https://Stackoverflow.com/users/20339407",
"pm_score": 1,
"selected": false,
"text": "extract_all_social_link()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2950492/"
] |
74,400,803 | <p>I have deploy my kubernetes cluster in AWS EKS. I have setup prometheus and grafana to monitor the EKS cluster. How to find Max no of running pods throughout the day ??</p>
| [
{
"answer_id": 74401848,
"author": "0x0fba",
"author_id": 20339407,
"author_profile": "https://Stackoverflow.com/users/20339407",
"pm_score": 1,
"selected": false,
"text": "extract_all_social_link()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12666897/"
] |
74,400,829 | <p>let's say i have a function like this:</p>
<pre><code>def foo (a = "a", b="b", c="c", **kwargs):
#do some work
</code></pre>
<p>I want to pass a <code>dict</code> like this to the function as the only argument.</p>
<pre><code>arg_dict = {
"a": "some string"
"c": "some other string"
}
</code></pre>
<p>which should change the values of the <code>a</code> and <code>c</code> arguments but <code>b</code> still remains the default value.</p>
<p>since <code>foo</code> is in an external library i don't want to change the function itself.</p>
<p>is there any way to achieve this?</p>
<p><strong>EDIT</strong></p>
<p>to clarify <code>foo</code> has both default arguments like <code>a</code> and has <code>keyword arguments</code> like <code>**kwargs</code></p>
<p>when i do this:</p>
<pre><code>foo(**arg_dict)
</code></pre>
<p><code>**arg_dict</code> is passed as the <code>**kwargs</code> and other arguments stay the default value.</p>
| [
{
"answer_id": 74401848,
"author": "0x0fba",
"author_id": 20339407,
"author_profile": "https://Stackoverflow.com/users/20339407",
"pm_score": 1,
"selected": false,
"text": "extract_all_social_link()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14721109/"
] |
74,400,852 | <p>I'm learning backend development using NodeJS with <strong>Hapi</strong> framework, and I got an error after starting the node with <code>npm run start</code>.</p>
<p><code>server.js</code></p>
<pre class="lang-js prettyprint-override"><code>const Hapi = require('@hapi/hapi');
const init = async() => {
const server = Hapi.server({
port: 5000,
host: 'localhost',
});
await server.start();
console.log(`Server berjalan pada ${server.info.uri}`);
}
init();
</code></pre>
<p><code>package.json</code></p>
<pre class="lang-json prettyprint-override"><code>{
"name": "hapi-web-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@hapi/hapi": "^21.0.0"
}
}
</code></pre>
<p>Running <code>npm run start</code> on PowerShell:</p>
<pre><code>> hapi-web-server@1.0.0 start E:\DOCUMENT\Dicoding\hapi-web-server
> node server.js
(node:19696) UnhandledPromiseRejectionWarning: TypeError: PerfHooks.performance.eventLoopUtilization is not a function
at new Heavy (E:\DOCUMENT\Dicoding\hapi-web-server\node_modules\@hapi\heavy\lib\index.js:42:60)
at new module.exports.internals.Core (E:\DOCUMENT\Dicoding\hapi-web-server\node_modules\@hapi\hapi\lib\core.js:122:22)
at Object.module.exports (E:\DOCUMENT\Dicoding\hapi-web-server\node_modules\@hapi\hapi\lib\server.js:22:18)
at init (E:\DOCUMENT\Dicoding\hapi-web-server\server.js:4:25)
at Object.<anonymous> (E:\DOCUMENT\Dicoding\hapi-web-server\server.js:13:1)
at Module._compile (internal/modules/cjs/loader.js:1251:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:19696) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
</code></pre>
<p>I expect the output should be:</p>
<pre><code>Server berjalan pada http://localhost:5000’
</code></pre>
<p>And when I enter <code>curl -X GET http://localhost:5000</code>, it should give this output:</p>
<pre><code>{"statusCode":404,"error":"Not Found","message":"Not Found"}
</code></pre>
| [
{
"answer_id": 74412781,
"author": "Build For Dev",
"author_id": 20477335,
"author_profile": "https://Stackoverflow.com/users/20477335",
"pm_score": -1,
"selected": false,
"text": "const init = async () => {\n const server = Hapi.server({\n port: 3000,\n host: 'localhost'\n });\n\n server.route({\n method: 'GET',\n path: '/',\n handler: function (request, h) {\n \n return 'Hello World!';\n }\n });\n\n await server.start();\n console.log('Server running on %s', server.info.uri);\n};\n"
},
{
"answer_id": 74413633,
"author": "Owen Lie",
"author_id": 14232964,
"author_profile": "https://Stackoverflow.com/users/14232964",
"pm_score": 1,
"selected": true,
"text": "@hapi/hapi@^20.1.0"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14232964/"
] |
74,400,865 | <p>I have a simple alert that I would like the user to be able to dismiss. Just looking for the easiest way to do this in Swift 5 / iOS 15</p>
<p><code>present(alert, animated: true, completion: nil)</code></p>
<p>Edit: Figured out the answer. Hope this will help out someone in the future who has the same question as me. (Mods, if you don't think it will help anyone, feel free to delete this thread)</p>
<pre><code>
// dismiss alert after 2 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
alert.dismiss(animated: true, completion: nil)
})
</code></pre>
| [
{
"answer_id": 74412781,
"author": "Build For Dev",
"author_id": 20477335,
"author_profile": "https://Stackoverflow.com/users/20477335",
"pm_score": -1,
"selected": false,
"text": "const init = async () => {\n const server = Hapi.server({\n port: 3000,\n host: 'localhost'\n });\n\n server.route({\n method: 'GET',\n path: '/',\n handler: function (request, h) {\n \n return 'Hello World!';\n }\n });\n\n await server.start();\n console.log('Server running on %s', server.info.uri);\n};\n"
},
{
"answer_id": 74413633,
"author": "Owen Lie",
"author_id": 14232964,
"author_profile": "https://Stackoverflow.com/users/14232964",
"pm_score": 1,
"selected": true,
"text": "@hapi/hapi@^20.1.0"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10241862/"
] |
74,400,879 | <p>I am working with the library gapminder as follows:</p>
<pre><code>library(gapminder)
library(dplyr)
db1 <-gapminder
db1Asia<-db1 %>% filter(year==1962 | year==1967) %>% filter(country=="China" | country=="India")
ggplot(data=db1Asia %>% filter(year==1962), aes(x=country, y=pop, color=country)) +geom_bar()
</code></pre>
<p>to study the evolution of the population of the two nations between 1962 and 1967. However, I get the following error:</p>
<pre><code>Error in `f()`:
! stat_count() can only have an x or y aesthetic.
</code></pre>
<p>I am following <a href="http://www.sthda.com/english/wiki/ggplot2-barplots-quick-start-guide-r-software-and-data-visualization" rel="nofollow noreferrer">this tutorial</a> and I cannot see what I am doing wrong. Can someone please help me?</p>
| [
{
"answer_id": 74412781,
"author": "Build For Dev",
"author_id": 20477335,
"author_profile": "https://Stackoverflow.com/users/20477335",
"pm_score": -1,
"selected": false,
"text": "const init = async () => {\n const server = Hapi.server({\n port: 3000,\n host: 'localhost'\n });\n\n server.route({\n method: 'GET',\n path: '/',\n handler: function (request, h) {\n \n return 'Hello World!';\n }\n });\n\n await server.start();\n console.log('Server running on %s', server.info.uri);\n};\n"
},
{
"answer_id": 74413633,
"author": "Owen Lie",
"author_id": 14232964,
"author_profile": "https://Stackoverflow.com/users/14232964",
"pm_score": 1,
"selected": true,
"text": "@hapi/hapi@^20.1.0"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9974205/"
] |
74,400,928 | <p>Requirement:
Table data:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Col A</th>
<th>Col B</th>
</tr>
</thead>
<tbody>
<tr>
<td>N</td>
<td>123</td>
</tr>
<tr>
<td>N</td>
<td>456</td>
</tr>
<tr>
<td>Y</td>
<td>456</td>
</tr>
</tbody>
</table>
</div>
<p>Required data:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Col A</th>
<th>Col B</th>
</tr>
</thead>
<tbody>
<tr>
<td>N</td>
<td>123</td>
</tr>
<tr>
<td>Y</td>
<td>456</td>
</tr>
</tbody>
</table>
</div>
<p>Can someone help me which method I should use here to filter records.</p>
<p>I am grouping this data depends upon multiple fields.
After grouping I need to take single row for Col B.</p>
<p>Eg. Col B = 123 has only 1 record so we need to fetch that.
And for col B = 456, we have 2 records so in that case we just need to take records which is col A = Y</p>
<p>Thanks in advance</p>
<p>I have tried analytical function here but it's not working as expected</p>
| [
{
"answer_id": 74412781,
"author": "Build For Dev",
"author_id": 20477335,
"author_profile": "https://Stackoverflow.com/users/20477335",
"pm_score": -1,
"selected": false,
"text": "const init = async () => {\n const server = Hapi.server({\n port: 3000,\n host: 'localhost'\n });\n\n server.route({\n method: 'GET',\n path: '/',\n handler: function (request, h) {\n \n return 'Hello World!';\n }\n });\n\n await server.start();\n console.log('Server running on %s', server.info.uri);\n};\n"
},
{
"answer_id": 74413633,
"author": "Owen Lie",
"author_id": 14232964,
"author_profile": "https://Stackoverflow.com/users/14232964",
"pm_score": 1,
"selected": true,
"text": "@hapi/hapi@^20.1.0"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476629/"
] |
74,400,948 | <p>Oracle - How to select and re-alias column by column-position, not column-name?
Exp:</p>
<pre><code>SELECT $1 AS NEW_COL_1, $2 AS NEW_COL_2
FROM
(SELECT 'x' AS COL_1, 'y' AS COL_2 FROM DUAL)
</code></pre>
<p>$1, $2 mean col_1, col_2</p>
<p>I have tried google but no solution yet!</p>
| [
{
"answer_id": 74411359,
"author": "Ngoc Trung",
"author_id": 6756303,
"author_profile": "https://Stackoverflow.com/users/6756303",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM (\n SELECT NULL NEW_COL1, NULL NEW_COL2\n UNION ALL \n SELECT 'x' AS COL_1, 'y' AS COL_2 FROM DUAL\n) \nWHERE NEW_COL1 IS NOT NULL;\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6756303/"
] |
74,400,978 | <p>I'm developing a timeout functionality for an embedded device where the system time is updated via gps. This means I can't just compare two timestamps to get the elapsed time:</p>
<pre class="lang-py prettyprint-override"><code>import time
t1 = time.time()
# system time change, e.g. from 1970-01-01 to 2022-11-10
t2 = time.time()
elapsed = t2 - t1 # this is now wrong!
</code></pre>
<p>Is getting the real elapsed time even possible in this case?</p>
| [
{
"answer_id": 74460202,
"author": "watch-this",
"author_id": 20280771,
"author_profile": "https://Stackoverflow.com/users/20280771",
"pm_score": 2,
"selected": false,
"text": ">>> wrong = time.time()\n>>> right = time.perf_counter()\n>>> # set clock back to correct time\n>>> time.time() - wrong\n1420070455.9668648\n>>> time.perf_counter() - right\n42.46595245699996\n"
},
{
"answer_id": 74522866,
"author": "Richa Bhuwania",
"author_id": 9921738,
"author_profile": "https://Stackoverflow.com/users/9921738",
"pm_score": 1,
"selected": false,
"text": "time.monotonic()"
},
{
"answer_id": 74527348,
"author": "the-foobar",
"author_id": 5329465,
"author_profile": "https://Stackoverflow.com/users/5329465",
"pm_score": 0,
"selected": false,
"text": "#!/usr/bin/env python3\n\nimport psutil\nfrom hwcounter import Timer\n\nclass Solution:\n def getElapsedTime(self) -> float:\n '''\n Method to get elpased time of a task using cpu cycles\n '''\n max_freq = psutil.cpu_freq().max\n print(f'CPU Max frequency: {max_freq} MHz')\n\n # Get frequency in Hz = 1/second\n max_freq_in_hz = max_freq * 10**6\n\n with Timer() as t:\n self.doTask()\n\n print(f'Elapsed cycles: {t.cycles}')\n print(f'Duration of task: {t.cycles / max_freq_in_hz} seconds')\n\n def doTask(self):\n sum = 0\n for i in range(100):\n sum += i\n\nif __name__ == '__main__':\n solution = Solution()\n solution.getElapsedTime()\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/300783/"
] |
74,400,989 | <p>I want to get the last record from the duplicate records and want the non-duplicate records also.</p>
<p>As depicted in the below image I want to get row number 4, 5, 7 and 9 in my output.</p>
<p><a href="https://i.stack.imgur.com/XF6Af.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XF6Af.png" alt="[[Sql data table Output](https://i.stack.imgur.com/EZ2fF.png)](https://i.stack.imgur.com/EZ2fF.png)" /></a></p>
<p>Here, In the below image the ** Main table** was shown. From which I have to concat first two columns and then from that new column I need the last row of duplicate records and the non-duplicate rows also.</p>
<p><a href="https://i.stack.imgur.com/H7tPa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H7tPa.png" alt="enter image description here" /></a></p>
<p>I have tried with the given below SQL code.</p>
<pre><code>DECLARE @dense_rank_demo AS TABLE (
Bid INT,
cid INT,
BCode NVARCHAR(10)
);
INSERT INTO @dense_rank_demo(Bid,cid,BCode)
VALUES(2393,1,'LAX'),(2394,54,'BRK'),(2395,57,'ONT'),(2393,1,'SAN'),(2393,1,'LAX'),(2393,1,'BRK'),(2394,54,'ONT'),(2395,57,'SAN'),(2394,1,'ONT');
SELECT * FROM @dense_rank_demo;
SELECT
CONCAT([Bid],'_',[cid]) as [Key],BCode,DENSE_RANK() over( order by CONCAT([Bid],'_',[cid]))
from @dense_rank_demo
</code></pre>
| [
{
"answer_id": 74405205,
"author": "BishNaboB",
"author_id": 1872455,
"author_profile": "https://Stackoverflow.com/users/1872455",
"pm_score": 0,
"selected": false,
"text": "dense_rank()"
},
{
"answer_id": 74405371,
"author": "trillion",
"author_id": 12513693,
"author_profile": "https://Stackoverflow.com/users/12513693",
"pm_score": 0,
"selected": false,
"text": "order by"
},
{
"answer_id": 74441234,
"author": "Krupa Panchal",
"author_id": 18835979,
"author_profile": "https://Stackoverflow.com/users/18835979",
"pm_score": 3,
"selected": true,
"text": "DECLARE @dense_rank_demo AS TABLE (\nID INT IDENTITY(1,1),\nBid INT,\ncid INT,\nBCode NVARCHAR(10));\nDECLARE @tableGroupKey TABLE\n(\n dr bigint,\n [Key] VARCHAR(50)\n) \nINSERT INTO @dense_rank_demo(Bid,cid,BCode)\nVALUES(2393,1,'LAX'),\n(2394,54,'BRK'),\n(2395,57,'ONT'),\n(2393,1,'SAN'),\n(2393,1,'LAX'),\n(2393,1,'BRK'),\n(2394,54,'ONT'),\n(2395,57,'SAN'),\n(2394,1,'ONT');\nwith [drd] as\n(\n select\n concat([Bid],'_',[cid]) as [Key],\n BCode,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \n from @dense_rank_demo\n)\nINSERT INTO @tableGroupKey(dr,[Key])\nselect MAX(dr) dr,[Key]\nfrom [drd]\nGROUP BY [Key]\nSELECT *,CONCAT(Bid,'_',cid) AS [Key] FROM @dense_rank_demo [drd]\nselect Result.* FROM\n(\n SELECT *,CONCAT(Bid,'_',cid) AS [Key] ,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \nFROM @dense_rank_demo [drd]\n) as [Result]\nINNER JOIN @tableGroupKey [gk] ON\n[Result].[Key] = [gk].[Key] AND [gk].dr = [Result].dr\nORDER BY [Result].ID\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19323657/"
] |
74,400,996 | <p>I want to sweep each table in a libname and calculate a hash over each row.
For that purpose, i have already a table with libname, memname, concatenated columns with ',' and number of observations</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">libname</th>
<th style="text-align: left;">memname</th>
<th style="text-align: left;">columns</th>
<th style="text-align: center;">num_obs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">lib_A</td>
<td style="text-align: left;">table_A</td>
<td style="text-align: left;">col1a,col2a...colna</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: left;">lib_A</td>
<td style="text-align: left;">table_B</td>
<td style="text-align: left;">col1b,col2b...colnb</td>
<td style="text-align: center;">2</td>
</tr>
<tr>
<td style="text-align: left;">lib_B</td>
<td style="text-align: left;">table_C</td>
<td style="text-align: left;">col1c,col2c...colnc</td>
<td style="text-align: center;">1</td>
</tr>
</tbody>
</table>
</div>
<p>I first get all data into ranged macro variables (i think its easier to work, but could be wrong, ofc)</p>
<pre><code>proc sql;
select libname, memname, columns, num_obs
into :lib1-, :tab1-, :column1-, :sqlobs1-
from have
where libname="&sel_livraria"; /*macro var = prompt from user*/
quit;
</code></pre>
<p>Just for developing guideline i made the code just to check one specific table without getting the row number of it since with a simple counter doesn't work (i get the order of the rows mess up each time i run) and it works for that purpose</p>
<pre><code>%let lib=lib_A;
%let tab=table_B;
%let columns=col1b,col2b,colnb;
data want;
length check $32.;
format check $hex32.;
set &lib..&tab;
libname="&lib";
memname="&tab";
check = md5(cats(&columns));
hash = put(check,$hex32.);
keep libname memname hash;
put hash;
put _all_;
run;
</code></pre>
<p>So, what’s the best approach for getting a MD5 from each row (<strong>same order as tables</strong>) of all tables in a libname? I saw problems i couldn’t overcame using data steps, procs or macros.</p>
<p>The result i wanted if lib_A was selected in prompt were something like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">libname</th>
<th style="text-align: left;">memname</th>
<th style="text-align: left;">obs_row</th>
<th style="text-align: center;">hash</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">lib_A</td>
<td style="text-align: left;">table_A</td>
<td style="text-align: left;">1</td>
<td style="text-align: center;">64A29CCA15F53C83A9583841294A26AA</td>
</tr>
<tr>
<td style="text-align: left;">lib_A</td>
<td style="text-align: left;">table_B</td>
<td style="text-align: left;">1</td>
<td style="text-align: center;">80DAC7B9854CF71A67F9C00A7EC4D9EF</td>
</tr>
<tr>
<td style="text-align: left;">lib_A</td>
<td style="text-align: left;">table_B</td>
<td style="text-align: left;">2</td>
<td style="text-align: center;">0AC44CD79DAB2E33C93BB2312D3A9A40</td>
</tr>
</tbody>
</table>
</div>
<p>Need some help.</p>
<p>Tks in advance.</p>
| [
{
"answer_id": 74405205,
"author": "BishNaboB",
"author_id": 1872455,
"author_profile": "https://Stackoverflow.com/users/1872455",
"pm_score": 0,
"selected": false,
"text": "dense_rank()"
},
{
"answer_id": 74405371,
"author": "trillion",
"author_id": 12513693,
"author_profile": "https://Stackoverflow.com/users/12513693",
"pm_score": 0,
"selected": false,
"text": "order by"
},
{
"answer_id": 74441234,
"author": "Krupa Panchal",
"author_id": 18835979,
"author_profile": "https://Stackoverflow.com/users/18835979",
"pm_score": 3,
"selected": true,
"text": "DECLARE @dense_rank_demo AS TABLE (\nID INT IDENTITY(1,1),\nBid INT,\ncid INT,\nBCode NVARCHAR(10));\nDECLARE @tableGroupKey TABLE\n(\n dr bigint,\n [Key] VARCHAR(50)\n) \nINSERT INTO @dense_rank_demo(Bid,cid,BCode)\nVALUES(2393,1,'LAX'),\n(2394,54,'BRK'),\n(2395,57,'ONT'),\n(2393,1,'SAN'),\n(2393,1,'LAX'),\n(2393,1,'BRK'),\n(2394,54,'ONT'),\n(2395,57,'SAN'),\n(2394,1,'ONT');\nwith [drd] as\n(\n select\n concat([Bid],'_',[cid]) as [Key],\n BCode,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \n from @dense_rank_demo\n)\nINSERT INTO @tableGroupKey(dr,[Key])\nselect MAX(dr) dr,[Key]\nfrom [drd]\nGROUP BY [Key]\nSELECT *,CONCAT(Bid,'_',cid) AS [Key] FROM @dense_rank_demo [drd]\nselect Result.* FROM\n(\n SELECT *,CONCAT(Bid,'_',cid) AS [Key] ,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \nFROM @dense_rank_demo [drd]\n) as [Result]\nINNER JOIN @tableGroupKey [gk] ON\n[Result].[Key] = [gk].[Key] AND [gk].dr = [Result].dr\nORDER BY [Result].ID\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74400996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20294371/"
] |
74,401,022 | <p>I have a very simple <code>ContentView</code>, The <code>Text</code>'s width set to <code>68</code></p>
<pre><code>struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
.frame(width: 68)
}
.padding()
}
}
</code></pre>
<p>But in <strong>Debug View Hierarchy</strong> I can see the <code>Text</code>'s width is not 68 at all, instead, the wrapper width of the <code>Text</code>is 68. Did I miss something?
<a href="https://i.stack.imgur.com/KuQ1i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KuQ1i.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/4vls6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4vls6.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74405205,
"author": "BishNaboB",
"author_id": 1872455,
"author_profile": "https://Stackoverflow.com/users/1872455",
"pm_score": 0,
"selected": false,
"text": "dense_rank()"
},
{
"answer_id": 74405371,
"author": "trillion",
"author_id": 12513693,
"author_profile": "https://Stackoverflow.com/users/12513693",
"pm_score": 0,
"selected": false,
"text": "order by"
},
{
"answer_id": 74441234,
"author": "Krupa Panchal",
"author_id": 18835979,
"author_profile": "https://Stackoverflow.com/users/18835979",
"pm_score": 3,
"selected": true,
"text": "DECLARE @dense_rank_demo AS TABLE (\nID INT IDENTITY(1,1),\nBid INT,\ncid INT,\nBCode NVARCHAR(10));\nDECLARE @tableGroupKey TABLE\n(\n dr bigint,\n [Key] VARCHAR(50)\n) \nINSERT INTO @dense_rank_demo(Bid,cid,BCode)\nVALUES(2393,1,'LAX'),\n(2394,54,'BRK'),\n(2395,57,'ONT'),\n(2393,1,'SAN'),\n(2393,1,'LAX'),\n(2393,1,'BRK'),\n(2394,54,'ONT'),\n(2395,57,'SAN'),\n(2394,1,'ONT');\nwith [drd] as\n(\n select\n concat([Bid],'_',[cid]) as [Key],\n BCode,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \n from @dense_rank_demo\n)\nINSERT INTO @tableGroupKey(dr,[Key])\nselect MAX(dr) dr,[Key]\nfrom [drd]\nGROUP BY [Key]\nSELECT *,CONCAT(Bid,'_',cid) AS [Key] FROM @dense_rank_demo [drd]\nselect Result.* FROM\n(\n SELECT *,CONCAT(Bid,'_',cid) AS [Key] ,\n dense_rank() over(partition by concat([Bid],'_',[cid]) order by ID) as \n[dr] \nFROM @dense_rank_demo [drd]\n) as [Result]\nINNER JOIN @tableGroupKey [gk] ON\n[Result].[Key] = [gk].[Key] AND [gk].dr = [Result].dr\nORDER BY [Result].ID\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2581578/"
] |
74,401,023 | <p>Hi to restart the device without resetting RTC clock. For example, when I run:</p>
<pre><code>import machine
print(str(time.localtime()))
# Set the datetime
machine.RTC().datetime((...))
print(str(time.localtime()))
machine.reset()
print(str(time.localtime()))
</code></pre>
<p>Outputs like this</p>
<pre><code>(2000, 1, 1, 0, 2, 4, 5, 1)
(2052, 11, 10, 10, 26, 45, 6, 315)
# Resets
(2000, 1, 1, 0, 2, 4, 5, 1)
</code></pre>
<p>I would like reset everything but the RTC time</p>
| [
{
"answer_id": 74410004,
"author": "Shawn Bragdon",
"author_id": 19753194,
"author_profile": "https://Stackoverflow.com/users/19753194",
"pm_score": 0,
"selected": false,
"text": "import machine\nimport time\n\n# Save the current time in RTC memory\nrtc = machine.RTC()\nrtc.memory(str(time.localtime()))\n\n# Set the datetime\nrtc.datetime((...))\n\n# Reset the device\nmachine.reset()\n\n# Restore the time from RTC memory\nrtc = machine.RTC()\ntime.localtime(eval(rtc.memory()))\nprint(str(time.localtime()))\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9010507/"
] |
74,401,041 | <p>I like to use keyword where, for example.</p>
<p>I simply do it like this</p>
<pre><code>Dim orderFromThisGridTrading = _orders1.Where(Function(x) x.customIdentifier = ASimpleGridTradeSettings.name).ToArray
</code></pre>
<p>However, most samples would say I have to use from</p>
<pre><code>Dim customersForRegion = From cust In customers Where cust.Region = region
</code></pre>
<p>Which is weird af and don't follow normal vb.net format. That looks a like like SQL languages and not a real programming language.</p>
<p>I wonder if I can always avoid using Form and just use like I am using? Are there any cases where that is not possible?</p>
<p>Is this even a good idea?</p>
| [
{
"answer_id": 74401137,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 3,
"selected": true,
"text": "Function"
},
{
"answer_id": 74408029,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "IEnumerable"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/700663/"
] |
74,401,042 | <p>The Loading screen is not showing before the homepage appears. here is my code for the screen with the button.</p>
<pre><code>import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:instacash/screens/Customer%20Onboarding/onboarding/slider_page1.dart';
import 'package:instacash/screens/Customer%20Onboarding/onboarding/slider_page2.dart';
import 'package:instacash/screens/Customer%20Onboarding/onboarding/slider_page3.dart';
import 'package:instacash/screens/Customer%20Onboarding/onboarding/slider_page4.dart';
import 'package:instacash/screens/Customer%20Onboarding/onboarding/slider_page5.dart';
import 'package:instacash/screens/loading.dart';
class Landing extends StatefulWidget {
const Landing({super.key});
@override
// ignore: library_private_types_in_public_api
_LandingState createState() => _LandingState();
}
class _LandingState extends State<Landing> {
int _currentPage = 0;
final PageController _controller = PageController();
final List<Widget> _pages = [
const SliderPage1(),
const SliderPage2(),
const SliderPage3(),
const SliderPage4(),
const SliderPage5(),
];
_onchanged(int index) {
setState(() {
_currentPage = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
PageView.builder(
scrollDirection: Axis.horizontal,
onPageChanged: _onchanged,
controller: _controller,
itemCount: _pages.length,
itemBuilder: (context, int index) {
return _pages[index];
},
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(_pages.length, (int index) {
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: 10,
width: (index == _currentPage) ? 30 : 10,
margin: const EdgeInsets.symmetric(
horizontal: 5, vertical: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: (index == _currentPage)
? Colors.blue.shade900
: Colors.white));
})),
const SizedBox(
height: 70,
),
Row(
//mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const SizedBox(
width: 50.0,
),
MaterialButton(
onPressed: () => {
check(context),
},
color: Colors.white,
height: 50.0,
minWidth: 300,
elevation: 10.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Text(
'Get Started',
style: GoogleFonts.poppins(
textStyle: const TextStyle(
color: Colors.black45,
fontSize: 18.0,
fontWeight: FontWeight.w500),
),
)),
//const SizedBox(height: 50.0,)
],
),
const SizedBox(
height: 30,
),
],
),
],
),
);
}
}
Future check(context) async {
await Future.delayed(const Duration(seconds: 3), () {
const Loading();
})
Navigator.pushNamed(context, '/homepage');
}
</code></pre>
<p>I am trying to make the loading screen in the future method show for about 3 seconds before the home screen appears but it just keeps navigating to the homepage. The future check method has the loading screen and the homepage screen to navigate to.</p>
| [
{
"answer_id": 74401137,
"author": "Tim Schmelter",
"author_id": 284240,
"author_profile": "https://Stackoverflow.com/users/284240",
"pm_score": 3,
"selected": true,
"text": "Function"
},
{
"answer_id": 74408029,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "IEnumerable"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17302941/"
] |
74,401,067 | <p>Trying to mock calls to this interface (excert thereof) using Moq...</p>
<pre><code>Task<T> StoreAsync<T>(
IAuthUser user,
T model,
IDataModel relative = null,
IDictionary<string, object> args = null)
where T : class, IDataModel;
</code></pre>
<p>I would like one 'setup' for successful calls</p>
<pre><code>mockModelService.Setup(s => s.StoreAsync(It.IsAny<IAuthUser>(), It.IsAny<PaymentModel>(), It.IsAny<IDataModel>(), It.IsAny<IDictionary<string, object>>()))
.ReturnsAsync((IAuthUser u, PaymentModel m, IDataModel d, IDictionary<string, object> c) =>
{
m.Id++;
return m;
});
</code></pre>
<p>And I aim to have a 'setup' for an override that throws an exception when the model type is specified</p>
<pre><code>// Notably the DuplicatePaymentCheck implements a static implicit constructor that takes a PaymentModel as parameter
mockModelService.Setup(s => s.StoreAsync<DuplicatePaymentCheck>(
It.IsAny<IAuthUser>(), It.IsAny<DuplicatePaymentCheck>(), null, null))
.ThrowsAsync(
new ValidationException(40003, "Invalid", "DUPLICATE!"));
</code></pre>
<p>However, my code doesn't compile because I have an ambiguous call. How can I mock this correctly?</p>
<p>(Btw I checked <a href="https://stackoverflow.com/questions/8461853/setup-method-in-moq-ambiguous-call">the similar Q&A</a> and couldn't see the connection to this scenario)</p>
| [
{
"answer_id": 74401133,
"author": "Prakhar Londhe",
"author_id": 4037191,
"author_profile": "https://Stackoverflow.com/users/4037191",
"pm_score": 2,
"selected": false,
"text": "It.IsAny<IDataModel>(), It.IsAny<IDictionary<string, object>>()\n"
},
{
"answer_id": 74403153,
"author": "David Savage",
"author_id": 8102749,
"author_profile": "https://Stackoverflow.com/users/8102749",
"pm_score": 2,
"selected": true,
"text": "mockModelService.Setup(c => c.StoreAsync(\n It.IsAny<IAuthUser>(), It.IsAny<DuplicatePaymentCheck>(), It.IsAny<IDataModel>(), It.IsAny<IDictionary<string, object>>()))\n .ThrowsAsync(\n new ValidationException(40003, \"Invalid\", \"DUPLICATE!\"));\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8102749/"
] |
74,401,130 | <p>Say that you have a <code><Button></code> and <code><Dialog></code> component. On button click, the dialog should open (<code>open</code> prop). Normally you would put both components togheter, using react <code>useState</code> to control the state:</p>
<pre><code>export const FilterDialog() {
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<Button onClick={handleOpen}
Open
</Button>
<Dialog open={open}>
<Button onClick={handleClose}
Close
</Button>
</Dialog>
);
};
</code></pre>
<p>This isn't a good solution as other part of the application may open the <code>FilterDialog</code>.</p>
<p>Thr problem could easly solved using a state pattern where state is global and the Dialog is attached to the <code>isFilterDialogOpen</code> state slice.</p>
<p>Is there any way to avoid the use of the global state pattern and have multiple button triggers controlling the dialog?</p>
| [
{
"answer_id": 74401133,
"author": "Prakhar Londhe",
"author_id": 4037191,
"author_profile": "https://Stackoverflow.com/users/4037191",
"pm_score": 2,
"selected": false,
"text": "It.IsAny<IDataModel>(), It.IsAny<IDictionary<string, object>>()\n"
},
{
"answer_id": 74403153,
"author": "David Savage",
"author_id": 8102749,
"author_profile": "https://Stackoverflow.com/users/8102749",
"pm_score": 2,
"selected": true,
"text": "mockModelService.Setup(c => c.StoreAsync(\n It.IsAny<IAuthUser>(), It.IsAny<DuplicatePaymentCheck>(), It.IsAny<IDataModel>(), It.IsAny<IDictionary<string, object>>()))\n .ThrowsAsync(\n new ValidationException(40003, \"Invalid\", \"DUPLICATE!\"));\n"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/220180/"
] |
74,401,144 | <p>In Qt Widget Application (c++), a part of my *.ui file consists of a QListView with two QTextEdits as its items like the below figure.</p>
<p><a href="https://i.stack.imgur.com/3lPUf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3lPUf.png" alt="enter image description here" /></a></p>
<p>As you can see custom widget includes two QTextEdit that each one has its text and stylesheet. As I searched on the net, there are solutions like HtmlDelegate classes for rendering text of items on QListView. But these classes only present <strong>ONE</strong> QTextEdit as item for QListView. In future, I want sync the QListView scrol status with a QMultimedia status like Podcast apps. Does anyone have any idea?</p>
| [
{
"answer_id": 74409272,
"author": "Parisa.H.R",
"author_id": 9484913,
"author_profile": "https://Stackoverflow.com/users/9484913",
"pm_score": 2,
"selected": true,
"text": "QListView"
},
{
"answer_id": 74413224,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 0,
"selected": false,
"text": "ListView"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3711075/"
] |
74,401,148 | <p>I'm trying to filter some data but I am trying to get all the elements with the same <code>id</code> that have the number <code>3</code>.</p>
<p>The id <code>10</code> and <code>300</code> has number <code>3</code> so I want to get all the elements with id <code>10</code> and <code>300</code></p>
<p>Is it possible to do this using filters? My current code is filtering too much elements</p>
<pre><code>const data = [{
id: 10,
number: 3
}, {
id: 10,
number: 2
}, {
id: 300,
number: 1
}, {
id: 300,
number: 3
}, {
id: 40,
number: 1
},
{
id: 40,
number: 2
}
]
const filteredData = data.filter(elem => elem.number === 3);
console.log(filteredData);
</code></pre>
<p>Expected Result:</p>
<pre><code>{
id: 10,
number: 3
}, {
id: 10,
number: 2
}, {
id: 300,
number: 1
}, {
id: 300,
number: 3
}
</code></pre>
| [
{
"answer_id": 74401192,
"author": "Dogbert",
"author_id": 320615,
"author_profile": "https://Stackoverflow.com/users/320615",
"pm_score": 3,
"selected": true,
"text": "Set"
},
{
"answer_id": 74401287,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "some()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12046376/"
] |
74,401,152 | <p>I created the following dictionary that includes multiple key-value pairs. The values are lists containing numbers.</p>
<pre><code>PLE_dict = {
"Task_1": [1, 2, 8],
"Task_2": [5, 1, 9],
"Task_3": [1, 1, 3],
"Task_4": [5, 3 ,5],
}
</code></pre>
<p>I also have an empty list: <code>Task_mean = []</code></p>
<p>My aim is to compute the averages across the four lists’ "columns" in the dictionary <code>PLE_dict</code> to subsequently insert them into the list <code>Task_mean</code>. More precisely, each new value in <code>Task_mean</code> should correspond to the mean or average across each "column" so to speak in the dictionary.</p>
<p>The result would look as follows:
<code>Task_mean = [3, 1.75, 6.25]</code></p>
<p>I tried something along the following lines, but I am stuck:</p>
<pre><code> for key, item in PLE_dict.items():
mean_column = np.mean(item[0])
</code></pre>
| [
{
"answer_id": 74401192,
"author": "Dogbert",
"author_id": 320615,
"author_profile": "https://Stackoverflow.com/users/320615",
"pm_score": 3,
"selected": true,
"text": "Set"
},
{
"answer_id": 74401287,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "some()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17530552/"
] |
74,401,201 | <p>I am facing this error:</p>
<blockquote>
<p>Attempt to read property "users_id" on null</p>
</blockquote>
<p>in Laravel 8 controller.</p>
<pre><code>public function editData88(Request $request, $id)
{
$id = Auth::user()->id;
$user = User::where('id', $id)->with(['detail_data' => function ($query) {
$query->with('agama');
}])->first();
$data_agama = Agama88::all();
return view('crud.edit88', compact('user', 'data_agama', 'id'));
}
</code></pre>
<p>Blade</p>
<pre><code><div class="form-group">
<label for="exampleInputPassword1">Alamat</label>
@if ($user->id == $user->detail_data->users_id)
<input type="text" class="form-control" id="alamat" name="alamat"
value="{{ $user->detail_data->alamat }}">
@else
<input type="text" class="form-control" id="alamat" name="alamat"
placeholder="Masukkan Alamat">
@endif
</div>
</code></pre>
<p>Model</p>
<pre><code>public function detail_data()
{
// return $this->belongsTo(detail_data::class);
return $this->hasOne(Data88::class, "users_id", "id");
}
</code></pre>
<p>How to fix the error?</p>
| [
{
"answer_id": 74401192,
"author": "Dogbert",
"author_id": 320615,
"author_profile": "https://Stackoverflow.com/users/320615",
"pm_score": 3,
"selected": true,
"text": "Set"
},
{
"answer_id": 74401287,
"author": "flyingfox",
"author_id": 3176419,
"author_profile": "https://Stackoverflow.com/users/3176419",
"pm_score": 1,
"selected": false,
"text": "some()"
}
] | 2022/11/11 | [
"https://Stackoverflow.com/questions/74401201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20476901/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.