qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,313,367 | <p>Im trying to proceed on the next activty from Kotlin to Java it gives me a red line in ".java"
in</p>
<pre><code> val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
</code></pre>
<p>This is my whole code:</p>
<pre><code>package com.heyletscode.artutorial
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
class Garlic : AppCompatActivity() {
lateinit var button : Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_garlic)
button = findViewById(R.id.Button)
button.setOnClickListener(listener)
}
val listener= View.OnClickListener { view ->
when (view.getId()) {
R.id.Button -> {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
}
}
</code></pre>
<p>Ive tried different methods to proceed to next activty but give me red line in .java</p>
| [
{
"answer_id": 74313498,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 1,
"selected": false,
"text": "onCreate"
},
{
"answer_id": 74313767,
"author": "Omkar",
"author_id": 6834114,
"author_profile": "https://Stackoverflow.com/users/6834114",
"pm_score": 0,
"selected": false,
"text": "package com.heyletscode.artutorial\n\n\nimport android.content.Intent\nimport androidx.appcompat.app.AppCompatActivity\nimport android.os.Bundle\nimport android.view.View\nimport android.widget.Button\n\nclass Garlic : AppCompatActivity() {\nlateinit var button : Button\n private lateinit var context: Context //create object of context\n\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.activity_garlic)\n context= this@MainActivity // init context here\n button = findViewById(R.id.Button)\n button.setOnClickListener(listener)\n }\n val listener= View.OnClickListener { view ->\n when (view.getId()) {\n R.id.Button -> {\n val intent = Intent(context, MainActivity::class.java) //replace this with context\n startActivity(intent)\n }\n }\n }\n\n\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13745390/"
] |
74,313,372 | <p>python for loop "stale element reference: element is not attached to the page document"</p>
<p>here is my code</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('F:\\work\\chromedriver_win32\\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
Content =["listtext1","listtext2","listtext3","listtext4"]
for i in range(4):
time.sleep(7)
url = "https://quillbot.com/"
driver.get(url)
Text_block = driver.find_element(By.ID, "inputText")
Text_block.send_keys(Content[i])# Change (fetch from Search_list)
time.sleep(2)
</code></pre>
| [
{
"answer_id": 74313538,
"author": "Barry the Platipus",
"author_id": 19475185,
"author_profile": "https://Stackoverflow.com/users/19475185",
"pm_score": 0,
"selected": false,
"text": "[....]\ncontent =[\"listtext1\",\"listtext2\",\"listtext3\",\"listtext4\"]\n\nfor i in content:\n driver.get('https://quillbot.com/')\n try:\n wait.until(EC.element_to_be_clickable((By.ID, \"onetrust-accept-btn-handler\"))).click()\n print('accepted cookies')\n except Exception as e:\n print('no cookie button!')\n text_block = wait.until(EC.element_to_be_clickable((By.ID, \"inputText\")))\n text_block.send_keys(i)\n print('sent', i)\n t.sleep(5)\n"
},
{
"answer_id": 74313614,
"author": "Giuseppe La Gualano",
"author_id": 20249888,
"author_profile": "https://Stackoverflow.com/users/20249888",
"pm_score": 2,
"selected": true,
"text": "from selenium import webdriver\nfrom selenium.webdriver.chrome.service import Service\nfrom selenium.webdriver.chrome.options import Options\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.common.by import By\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom selenium.webdriver.support import expected_conditions as EC\nfrom selenium.common.exceptions import TimeoutException\n\noptions = Options()\noptions.add_argument(\"start-maximized\")\n\n# add user_agent\nuser_agent = \"user-agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36]\"\noptions.add_argument(user_agent)\n\ndriver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) # to use over all systems\nbrowser_delay = 2 # set if based on your connection and device speed\n\nContent =[\"listtext1\",\"listtext2\",\"listtext3\",\"listtext4\"]\nfor i in range(len(Content)):\n url = \"https://quillbot.com/\"\n driver.get(url)\n try:\n cookie_btn = WebDriverWait(driver, browser_delay).until(EC.element_to_be_clickable((By.ID, 'onetrust-accept-btn-handler')))\n cookie_btn.click()\n except TimeoutException:\n pass # it's a timeout or element just clicked\n\n Text_block = driver.find_element(By.ID, \"inputText\")\n Text_block.send_keys(Content[i]) # Change (fetch from Search_list)\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20147022/"
] |
74,313,402 | <p>My data is URL</p>
<pre><code>https://www.stackoverflow.com/abc/sometihng-herer?&jhdsfj@38736
</code></pre>
<p>Output I am looking is from 3rd occurance of '/' till before '?'</p>
<p>sample output:</p>
<pre><code> /abc/sometihng-herer
</code></pre>
<p>Database is vertica and datatype is long char</p>
| [
{
"answer_id": 74313473,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "SELECT url, REGEXP_SUBSTR(url, 'https?://[^/]+(/[^?]+)', 1, 1, '', 1) AS path\nFROM yourTable;\n"
},
{
"answer_id": 74314673,
"author": "marcothesane",
"author_id": 6788255,
"author_profile": "https://Stackoverflow.com/users/6788255",
"pm_score": 0,
"selected": false,
"text": "SPLIT_PART"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10466645/"
] |
74,313,470 | <p>i am newly learn javascript, now i am having a serios compare in here.
In one nested array how to compare each array first 2 index, elements of first 4 digit are same to other array elemnts or not?</p>
<p>if array elements are same then will display rest of elemnts for both array in one array.</p>
<p>suppose the codes like this:</p>
<pre><code>const arr= [[100110, 556781, 'student', 'single' , 20, 'jacci'],
[100210, 667881 , 'employee', 'double' , 25, 'rock'],
[100310, 778981 ,'teacher', 'triple' , 45, 'poul'],
[100220, 667891 , 'employee', 'single' , 30, 'jack'],
[100320, 778991 ,'teacher', 'double' , 40, 'rose'],
[100120, 556791, 'student', 'double' , 35, 'laila']];
</code></pre>
<p>now i want to compare each array frist 2 index are same, if same then the array will be like:</p>
<pre><code>arry = [[100110, 556781,'student', 'single' , 20, 'jacci','student','double' , 35, 'laila'],
[100210, 667881 , 'employee', 'double' , 25, 'rock','employee','single' , 30, 'jack'],
[100310, 778991 ,'teacher', 'triple' , 45, 'poul', 'teacher','double' , 40, 'rose']]
</code></pre>
<p>how can i get the array like this in javascript.</p>
<p>anyone can help me to do the function for it.</p>
<p>Thanks for your trying in advance!</p>
| [
{
"answer_id": 74313473,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "SELECT url, REGEXP_SUBSTR(url, 'https?://[^/]+(/[^?]+)', 1, 1, '', 1) AS path\nFROM yourTable;\n"
},
{
"answer_id": 74314673,
"author": "marcothesane",
"author_id": 6788255,
"author_profile": "https://Stackoverflow.com/users/6788255",
"pm_score": 0,
"selected": false,
"text": "SPLIT_PART"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19983659/"
] |
74,313,524 | <p>We are a team of developers working on an app for one and a half years, with the backend using <code>Firebase</code> and <code>Firestore</code> as <code>cloud database</code>. We have several owners and contributors to this project. Now our <code>Firestore</code> data and user authentication data have been deleted and we've lost almost everything. Is there a way to see which owner/contributor has deleted our data? And most importantly is there a way to retrieve this deleted data? Thanks in advance.</p>
<p><strong>Note: We are on the Blaze (paid) plan of <code>Firebase</code>.</strong></p>
| [
{
"answer_id": 74313473,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "SELECT url, REGEXP_SUBSTR(url, 'https?://[^/]+(/[^?]+)', 1, 1, '', 1) AS path\nFROM yourTable;\n"
},
{
"answer_id": 74314673,
"author": "marcothesane",
"author_id": 6788255,
"author_profile": "https://Stackoverflow.com/users/6788255",
"pm_score": 0,
"selected": false,
"text": "SPLIT_PART"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14186586/"
] |
74,313,612 | <p>I recently learned about the <code>[[noreturn]]</code> attribute and wanted to try and implement it on one of my existing code snippets.</p>
<p>I added the attribute to a void return type function with no <code>return;</code> keyword on it whatsoever. However, I'm getting this error:</p>
<pre><code>[ 17%] Building CXX object CMakeFiles/Renderer.dir/src/opengl/text_render.cpp.o
/home/turgut/Desktop/CppProjects/videoo-render/src/opengl/text_render.cpp:7:25: error: function βconst void OpenGL::Text::set_background(int, int, float, int, int, int, int, float, std::string*)β declared β[[noreturn]]β but its first declaration was not
7 | [[noreturn]] const void Text::set_background(
|
make[2]: *** [CMakeFiles/Renderer.dir/build.make:132: CMakeFiles/Renderer.dir/src/opengl/text_render.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:277: CMakeFiles/Renderer.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
</code></pre>
<p>I'm using c++ 20+ so I don't think there is a problem with versions.</p>
<p>What is wrong with my usage of <code>[[noreturn]]</code> and how should I use it propperly? Am I missing a piece of knowledge about it?</p>
<p>Here is the function in question:</p>
<pre><code>[[noreturn]] void Text::set_background(
int x, int y, float z,
int w, int h,
int gw, int gh,
float ang, std::string* hex_color
){
background = new Background(x-w, y-h);
background->color = (*hex_color).c_str();
background->bg_texture = new Texture(
x - 10, (1000 - y) + 10, w, -h ,gw, gh
);
background->bg_texture->init(ang, z, nullptr);
}
</code></pre>
<p>I've also tried to use it on some other similar functions but got a similar result.</p>
| [
{
"answer_id": 74313663,
"author": "Some programmer dude",
"author_id": 440558,
"author_profile": "https://Stackoverflow.com/users/440558",
"pm_score": 4,
"selected": true,
"text": "Text"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19574336/"
] |
74,313,615 | <p>Currently my code, is not too fancy.</p>
<p>A Meeting ID value has to be present for each row. If there is no Meeting Id in meeting object, then return error and stop all process (Meeting Id is the same for each row in the list).</p>
<p>Agenda Item is required, and it cannot be a duplicate value. If missing, or duplicate, return error.</p>
<p>If Legistar Id is missing, then the value of Agenda Item will be assigned to the missing Legistar Id.</p>
<p>Neither Agenda Item, and/or Legistar Id, can contain duplicate values. Each value for these properties has to be unique. Otherwise, stop, return error.</p>
<p>The List I am trying to pass, and validate looks like:</p>
<pre><code>AgendaItem LegistarID Title
1 74490 Public Comment. (October 31 2022)
2 74491 Welcome Affirmative Action Commission Appointment. <-- Agenda Item 2
2 73403 Nomination Open Update. <-- Agenda Item 2
4 74490 Communication Strategy Update. <-- Legistar Id same as row 1
</code></pre>
<p>How can I pass a message specifying such particular cases so that the client app, receives it an alerts the user?</p>
<p>This is my current version of my ImportData routine, here goes to nothing</p>
<pre><code>public ActionResult ImportData(List<MeetingAgendaXref_WIP> meeting) // see comment above procedure name
{
bool status = false;
string message = "";
try
{
if (ModelState.IsValid)
{
var errors = new List<string>();
var rowCounter = 1;
using (ClerkEntities db = new ClerkEntities())
{
foreach (var i in meeting)
{
if (i.MeetingID == 0)
{
message = string.Format("No Meeting ID. Please make sure that the Cross Reference meets the required criteria for each row before clicking the ""Upload"" button.");
// log error to list
errors.Add($"Row {rowCounter}: No Meeting ID. Please make sure that the Cross Reference meets the required criteria for each row before clicking the ""Upload"" button.");
return new JsonResult { Data = new { status = status, message = message } };
}
if (i.AgendaItem == 0)
{
message = string.Format("No Agenda Item. Please make sure that the Cross Reference file meets the required criteria for each row before clicking the ""Upload"" button.");
// log error to list
errors.Add($"{rowCounter}:No Agenda Item. Please make sure that the Cross Reference file meets the required criteria for each row before clicking the ""Upload"" button.");
return new JsonResult { Data = new { status = status, message = message } };
}
// if Legistar ID,
if (i.LegistarID == 0)
{
// and Agenda Item are not present, return error message, log error message
if (i.AgendaItem == 0)
{
message = string.Format("Agenda Item, and Legistar Id are missing. Please make sure that the Cross Reference file meets the required criteria for each row before clicking the ""Upload"" button.");
// log error to list
errors.Add("Agenda Item, and Legistar Id are missing. Please make sure that the Cross Reference file meets the required criteria for each row before clicking the ""Upload"" button.");
return new JsonResult { Data = new { status = status, message = message } };
}
// otherwise, if legistar id, is empty, but agenda item is not, then assign Agenda Item to Legistar Id.
else
{
i.LegistarID = i.AgendaItem;
}
}
var compositeKey = db.MeetingAgendaXref_WIP.Find(i.MeetingID, i.AgendaItem);
if (compositeKey == null)
{
// Add new
db.MeetingAgendaXref_WIP.Add(i);
}
else
{
// Update previously saved values (same or new)
db.Entry(compositeKey).CurrentValues.SetValues(i);
db.Entry(compositeKey).State = EntityState.Modified;
}
rowCounter++;
}
// If there are errors do not save and return error message
if (errors.Count > 0)
{
return new JsonResult { Data = new { status = status, message = string.Join("\n", errors) } };
}
else
{
db.SaveChanges();
message = string.Format(@"Your Cross Reference file has been uploaded successfuly!");
status = true;
return new JsonResult { Data = new { status = status, message = message } };
}
}
}
else
{
message = string.Format(@"Please make sure that the Cross Reference file meets the required criteria for each row before clicking the ""Upload"" button.");
return new JsonResult {Data = new {status = status, message = message}};
}
}
catch (System.ArgumentException ex)
{
status = false;
ExceptionLogging.WriteLogError(ex.ToString());
}
return new JsonResult {Data = new {status = status, message = message}};
}
</code></pre>
| [
{
"answer_id": 74362943,
"author": "RohΓ¬t JΓndal",
"author_id": 4116300,
"author_profile": "https://Stackoverflow.com/users/4116300",
"pm_score": 2,
"selected": false,
"text": "MeetingID"
},
{
"answer_id": 74380254,
"author": "Ellioth Velasquez",
"author_id": 4484522,
"author_profile": "https://Stackoverflow.com/users/4484522",
"pm_score": 0,
"selected": false,
"text": " const arr1 = ['a', 'a'];\n const arr2 = ['a', 'b']; \n function containsDuplicates(array) {\n const result = array.some(element => {\n if (array.indexOf(element) !== array.lastIndexOf(element)) {\n return true;\n }\n return false;\n });\n return result;\n }\n console.log(containsDuplicates(arr1)); // οΈ true\n console.log(containsDuplicates(arr2)); // οΈ false\n"
},
{
"answer_id": 74381934,
"author": "JΓΌrgen RΓΆhr",
"author_id": 7126039,
"author_profile": "https://Stackoverflow.com/users/7126039",
"pm_score": 0,
"selected": false,
"text": "GroupBy"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5476615/"
] |
74,313,623 | <p>I want to implement an iterator that produces all the <a href="https://en.wikipedia.org/wiki/Subsequence" rel="nofollow noreferrer">subsequences</a> of an input sequence. Some examples:</p>
<pre><code>subsequences "abc"
["","a","b","ab","c","ac","bc","abc"]
subsequences [1,2]
[[],[1],[2],[1,2]]
subsequences [1,2,3]
[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
subsequences [1,2,3,4]
[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3],[4],[1,4],[2,4],[1,2,4],[3,4],[1,3,4],[2,3,4],[1,2,3,4]]
</code></pre>
<p>The Haskell implementation of this is very straightforward:</p>
<pre><code>subsequences :: [a] -> [[a]]
subsequences xs = [] : nonEmptySubsequences xs
nonEmptySubsequences :: [a] -> [[a]]
nonEmptySubsequences [] = []
nonEmptySubsequences (x:xs) = [x] : foldr f [] (nonEmptySubsequences xs)
where f ys r = ys : (x : ys) : r
</code></pre>
<p>I just cannot seem to figure out how to recreate this in Rust. I figure it should have the following signature so that it can produce very long sequences without unnecessary memory allocations.</p>
<pre><code>fn subsequences<A: Copy>(xs: &[A]) -> impl Iterator<Item=impl Iterator<Item=A>>;
</code></pre>
<p>Any guidance?</p>
| [
{
"answer_id": 74313979,
"author": "Nikolay Zakirov",
"author_id": 9023490,
"author_profile": "https://Stackoverflow.com/users/9023490",
"pm_score": 1,
"selected": false,
"text": "fn subsequences<A: Copy>(xs: &[A]) -> impl Iterator<Item=impl Iterator<Item=A>+ '_> {\n // return all subsequences of a given sequence\n let n = xs.len();\n (0..1 << n).map(move |i| {\n (0..n).filter(move |j| i & (1 << j) != 0).map(move |j| xs[j])\n })\n\n}\nmod tests {\n use super::*;\n\n #[test]\n fn test_subseq() {\n let xs = [1, 2, 3];\n let mut it = subsequences(&xs);\n for _ in 0..8 {\n println!(\"{:?}\", it.next().unwrap().collect::<Vec<_>>());\n }\n }\n}\n"
},
{
"answer_id": 74314059,
"author": "rodrigo",
"author_id": 865874,
"author_profile": "https://Stackoverflow.com/users/865874",
"pm_score": 0,
"selected": false,
"text": "[[a]]"
},
{
"answer_id": 74314262,
"author": "rodrigo",
"author_id": 865874,
"author_profile": "https://Stackoverflow.com/users/865874",
"pm_score": 1,
"selected": false,
"text": "use itertools::Itertools;\n\nfn main() {\n for s in ['a', 'b', 'c'].into_iter().powerset() {\n println!(\"{:?}\", s);\n }\n}\n\n[]\n['a']\n['b']\n['c']\n['a', 'b']\n['a', 'c']\n['b', 'c']\n['a', 'b', 'c']\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1002430/"
] |
74,313,634 | <p>I made a simple code that should reply when someone mentions the bot.</p>
<pre><code>client.on("messageCreate", (message) => {
if (message.content === "<@935849545789763585>" || '<@!935849545789763585>') {
message.channel.send('Hi');
}
});
</code></pre>
<p>But I have a problem because the bot is replying multiple times.</p>
<p><a href="https://i.stack.imgur.com/8WbJw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8WbJw.png" alt="here proof" /></a></p>
| [
{
"answer_id": 74313895,
"author": "Jakye",
"author_id": 10012735,
"author_profile": "https://Stackoverflow.com/users/10012735",
"pm_score": 2,
"selected": false,
"text": "<@935849545789763585>"
},
{
"answer_id": 74313918,
"author": "Zsolt Meszaros",
"author_id": 6126373,
"author_profile": "https://Stackoverflow.com/users/6126373",
"pm_score": 1,
"selected": false,
"text": "if (message.content === \"<@935849545789763585>\" || '<@!935849545789763585>')"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313634",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15321365/"
] |
74,313,641 | <p>When I read <a href="https://www.dropbox.com/s/lfxzqjqhisc502i/invalid_file.xlsx?dl=0" rel="nofollow noreferrer">this file</a> with pandas, only 15 of the 44 rows are read, seemingly without a system. Cell E31 is set to <code>nan</code>, and I'm unable to find out why.</p>
<p>How to reproduce:</p>
<pre><code>% pip show pandas
Name: pandas
Version: 1.5.1
(...)
% python3
Python 3.10.7 (main, Sep 15 2022, 01:51:29) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> test = pandas.read_excel("Downloads/invalid_file.xlsx")
>>> test
name super object ... comment_rm gui_element gui_attributes
0 hasSignature hasValue TextValue ... NaN SimpleText NaN
1 hasCreator hasValue TextValue ... NaN SimpleText NaN
2 hasProvenience hasValue TextValue ... NaN SimpleText NaN
3 hasDate hasValue TextValue ... NaN SimpleText NaN
4 hasLanguage hasValue TextValue ... NaN SimpleText NaN
5 hasCopyright hasValue TextValue ... NaN SimpleText NaN
6 hasComment hasValue TextValue ... NaN Textarea NaN
7 hasDescription hasValue TextValue ... NaN Richtext NaN
8 hasLatinName hasValue, dcterms:title TextValue ... NaN SimpleText NaN
9 hasSynonym hasValue Synonyme ... NaN SimpleText NaN
10 hasPagenum seqnum IntValue ... NaN SimpleText NaN
11 partOf isPartOf :Manuscript ... NaN Searchbox NaN
12 hasTitle hasValue TextValue ... NaN SimpleText NaN
13 hasFolio hasValue TextValue ... NaN SimpleText NaN
14 hasPlant hasLinkTo :Plant ... NaN Searchbox NaN
[15 rows x 15 columns]
>>> test.iloc[9,4]
nan
</code></pre>
<p>I carefully checked the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html" rel="nofollow noreferrer">docs</a> if I have to set a certain parameter, but I found nothing.</p>
| [
{
"answer_id": 74314316,
"author": "Π‘Π΅ΡΠ³Π΅ΠΉ ΠΠΎΡ
",
"author_id": 18400908,
"author_profile": "https://Stackoverflow.com/users/18400908",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\n\ntest = pd.read_excel(open('invalid_file.xlsx', 'rb'), sheet_name='Sheet1')\nprint(test.to_string())\n\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14414188/"
] |
74,313,668 | <p>Just trying to tinker with the Dart, a bit.
Here trying to use the Output of the first function ( which is a List) in the second function. but it prints 0, ?</p>
<pre><code>void main() {
print(secondFuncion(firstFuncion()));
}
List firstFuncion() {
List mylist = [];
for (var i = 0; i < 23; i++) {
mylist.add(i);
}
return mylist;
}
secondFuncion(List<mylist> b) {
for (var element in b) {
return element;
}
}
</code></pre>
| [
{
"answer_id": 74314830,
"author": "7eg",
"author_id": 13311722,
"author_profile": "https://Stackoverflow.com/users/13311722",
"pm_score": 0,
"selected": false,
"text": " secondFuncion(List<mylist> b) {\n for (var element in b) {\n return element;\n }\n}\n"
},
{
"answer_id": 74315397,
"author": "DAni M",
"author_id": 11440211,
"author_profile": "https://Stackoverflow.com/users/11440211",
"pm_score": -1,
"selected": false,
"text": "void main() {\n secondFuncion(firstFuncion());\n}\n\nList firstFuncion() {\n List mylist = [];\n for (var i = 0; i < 23; i++) {\n mylist.add(i);\n }\n return mylist;\n}\n\nsecondFuncion(List b) {\n for (var element in b) {\n print(element);\n }\n}\n"
},
{
"answer_id": 74368550,
"author": "Maurizio Mancini",
"author_id": 18439816,
"author_profile": "https://Stackoverflow.com/users/18439816",
"pm_score": 0,
"selected": false,
"text": "void main() {\n print(secondFuncion(firstFuncion()));\n}\n\nList firstFuncion() {\n List mylist = [];\n for (var i = 0; i < 23; i++) {\n mylist.add(i);\n }\n return mylist;\n}\n\nsecondFuncion(List<mylist> b) {\n List mylist2 = [];\n for (var element in b) {\n mylist2.add(element*2);\n }\n return mylist2\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11440211/"
] |
74,313,676 | <p>So I was getting my hands-on on the new DALL.E api for Python which has been made public. I was getting the Attribution Error as it was not detecting the Image model in Open ai after running the following code:</p>
<pre><code>response = openai.Image.create(
prompt="a white siamese cat",
n=1,
size="1024x1024"
)
image_url = response['data'][0]['url']
</code></pre>
<p>Why am I getting this error?</p>
| [
{
"answer_id": 74313677,
"author": "Usman Afridi",
"author_id": 15430546,
"author_profile": "https://Stackoverflow.com/users/15430546",
"pm_score": 3,
"selected": true,
"text": "pip install --upgrade openai\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15430546/"
] |
74,313,698 | <p>I am creating a simple application on Nodejs as a beginner. I am failing to connect nodejs with mongodb atlas. Kindly help me.
I have provided the username, password and clustername respectively.</p>
<pre><code>const express = require("express");
const app = express();
const userRouter = require("./routes/userRoutes");
const noteRouter = require("./routes/userRoutes");
const mongoose = require("mongoose");
app.use("/users", userRouter);
app.use("notes", noteRouter);
app.get("/", (req, res) => {
res.send("Hello");
});
mongoose
.connect(
"mongodb+srv://username:password@clustername.ox93pg1.mongodb.net/?retryWrites=true&w=majority"
)
.then(() => {
app.listen(5000, () => {
console.log("server started on port no. 5000");
});
})
.catch((err) => {
console.log(err);
});
</code></pre>
<p>The error I am getting is :</p>
<pre><code>MongoAPIError: URI must include hostname, domain name, and tld
at resolveSRVRecord (D:\Other Setups\backend setups\cheezy code\node_modules\mongodb\lib\connection_string.js:52:15)
at D:\Other Setups\backend setups\cheezy code\node_modules\mongodb\lib\mongo_client.js:120:78
at maybeCallback (D:\Other Setups\backend setups\cheezy code\node_modules\mongodb\lib\utils.js:337:21)
at MongoClient.connect (D:\Other Setups\backend setups\cheezy code\node_modules\mongodb\lib\mongo_client.js:114:42)
at D:\Other Setups\backend setups\cheezy code\node_modules\mongoose\lib\connection.js:809:12
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (D:\Other Setups\backend setups\cheezy code\node_modules\mongoose\lib\connection.js:798:19)
at D:\Other Setups\backend setups\cheezy code\node_modules\mongoose\lib\index.js:413:10
at D:\Other Setups\backend setups\cheezy code\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise (<anonymous>) {
[Symbol(errorLabels)]: Set(0) {}
}
[nodemon] clean exit - waiting for changes before restart
</code></pre>
<p>I was expecting a successful connection between mongodb and nodejs. With the output "server started on port no. 5000" in the console.</p>
| [
{
"answer_id": 74313677,
"author": "Usman Afridi",
"author_id": 15430546,
"author_profile": "https://Stackoverflow.com/users/15430546",
"pm_score": 3,
"selected": true,
"text": "pip install --upgrade openai\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415167/"
] |
74,313,712 | <p>I was reading a spark DF with options below:</p>
<pre><code>testDF = spark.read.format("parquet").option("header", "true") \
.option("mergeSchema", "true").option("inferSchema", "true").load("folderPath/*/*")
</code></pre>
<p>However, this fails because one of the col (Date) is of type timestamp in some source files and is of type string in some files.
I don't have control over the data producers, so wanted to know how can I handle this while processing.</p>
<p>Challenge is it's randomly either timestamp or string across files.</p>
<p>Thanks.</p>
| [
{
"answer_id": 74313677,
"author": "Usman Afridi",
"author_id": 15430546,
"author_profile": "https://Stackoverflow.com/users/15430546",
"pm_score": 3,
"selected": true,
"text": "pip install --upgrade openai\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2260620/"
] |
74,313,715 | <p>I just want to wait for all concurrent HTTP calls completed then make another HTTP request.</p>
<p>here is my code ...</p>
<pre><code>
const observable = requestData.map(x => this.blobService.addNewVideo(x.uniqueName, x.chunk, x.base64BlockId));
from(observable).pipe(mergeAll(5)).subscribe(
(event: HttpEvent<any>)=>{
switch (event.type) {
case HttpEventType.UploadProgress:
this.progress = Math.round((event.loaded / event.total!) * 100);
console.log(`uploaded! ${this.progress}%`);
break;
case HttpEventType.Response:
console.log('Successfully uploaded',event.body,' : ',event.status,event.statusText);
}
}
);
</code></pre>
<p>here are successfully uploaded all the chunks but the problem is that I am unable to wait for all requests completed to make another HTTP request. how can I do that?</p>
<p>Thanks in advance</p>
| [
{
"answer_id": 74313677,
"author": "Usman Afridi",
"author_id": 15430546,
"author_profile": "https://Stackoverflow.com/users/15430546",
"pm_score": 3,
"selected": true,
"text": "pip install --upgrade openai\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19296176/"
] |
74,313,753 | <p>I have iterative numbered values lambdaSample1_1, lambdaSample1_2, lambdaSample1_3.... lambdaSample1_1000.</p>
<h1>1000 random Lambadas for dataset 3</h1>
<p>for (i in 1:numSamples) {</p>
<pre><code># generate ramdomNumber for credible interval
randomNumber <- floor(runif(numSamples, min = 1, max = nrow(mcmcMatrix)))
assign(paste0("lambdaSample3_", i), mcmcMatrix[randomNumber[[i]], lambdas[[3]]])
}
</code></pre>
<p>I got lambdaSample3_1 ~ lambdaSample3_1000 from the Matrix that has 60000 rows by randomly selecting the values using randomnumbers from 1 ~ 1000.</p>
<p>Now what I like to do is to combine the generated values "lambda1_1" ~ "lambda1_1000" into a single list</p>
<p>I would like to store 1,000 values in one single list. Is there any way that I can write a simple code rather than writing 1,000 values into a list?</p>
<pre><code>mylist <- list(lambdaSample1_1, lambdaSample1_2 ,,,,, lambdaSample1_1000)
</code></pre>
<p>for (i in 1:numSamples) {</p>
<pre><code># generate ramdomNumber for credible interval
randomNumber <- floor(runif(numSamples, min = 1, max = nrow(mcmcMatrix)))
assign(paste0("lambdaSample3_", i), mcmcMatrix[randomNumber[[i]], lambdas[[3]]])
}
</code></pre>
<p>how can I make this type of list without writing down 1000 times of lambdaSample1_x ??</p>
| [
{
"answer_id": 74313677,
"author": "Usman Afridi",
"author_id": 15430546,
"author_profile": "https://Stackoverflow.com/users/15430546",
"pm_score": 3,
"selected": true,
"text": "pip install --upgrade openai\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17192847/"
] |
74,313,762 | <p>Consider the following code block:</p>
<pre><code>class MyException(Exception):
__hash__ = None
try:
raise ExceptionGroup("Foo", [
MyException("Bar")
])
except* Exception:
pass
</code></pre>
<p>The <code>except*</code> should catch any number of exceptions of any kind, thrown together as an <code>ExceptionGroup</code> (or a single exception of any kind if thrown alone, come to that). Instead, an unhandled <code>TypeError</code> occurs during handling of our <code>ExceptionGroup</code>, allegedly at "line -1" of our module:</p>
<pre><code> + Exception Group Traceback (most recent call last):
| File "C:\Users\Josep\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch_62.py", line 6, in <module>
| raise ExceptionGroup("Foo", [
| ExceptionGroup: Foo (1 sub-exception)
+-+---------------- 1 ----------------
| MyException: Bar
+------------------------------------
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Josep\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch_62.py", line -1, in <module>
TypeError: unhashable type: 'MyException'
</code></pre>
<p>(If we replace the <code>except* Exception</code> with something more specific, say <code>except* ValueError</code> or <code>except* MyException</code>, the same thing happens. If we try to just raise a single <code>MyException</code> and catch it normally with <code>except MyException</code>, that works fine.)</p>
<p>Normal <code>except</code> clauses don't care whether exceptions are hashable. I could not find this quirk of <code>except*</code> documented in PEP-654 or the Python 3.11 release notes. Is this intended behavior, or is it simply a bug in the Python implementation I'm using?</p>
<p>(For those who want to reproduce this behavior, I'm using Python 3.11.0, 64-bit, on Windows.)</p>
| [
{
"answer_id": 74313861,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": -1,
"selected": false,
"text": "Exception"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11729033/"
] |
74,313,783 | <p>I use VSC to compile and debug a CPP generated test executable. The name of the executable and makefile changes depending on which build I'm debugging, and importantly there is only ever a single executable/makefile in my workspace directory.</p>
<p>I'm wondering if there's a way to simply build/debug the makefile/exe that is found within the directory, as my current solution is to create a new build task/launch configuration (or update my existing configuration) for each build with the updated exe/makefile name, but this is of course not an ideal solution.</p>
<pre><code>"tasks":[
{
"label": "Build A",
"type": "shell",
"command": "vcvars32.bat && nmake /nologo /S /F .\\TestA.mak",
"group": "build",
"options": {"cwd": "${workspaceFolder}"
},
{
"label": "Build B",
"type": "shell",
"command": "vcvars32.bat && nmake /nologo /S /F .\\TestB.mak",
"group": "build",
"options": {"cwd": "${workspaceFolder}"
},
]
</code></pre>
<pre><code>"configurations":
[
{
"name": "Test A",
"program": "${workspaceRoot}\\TestA.exe"
"cwd": "${fileDirname}",
...
},
{
"name": "Test B",
"program": "${workspaceRoot}\\TestB.exe"
"cwd": "${fileDirname}",
...
}
]
</code></pre>
<p>Changing the name of the makefile/exe is not a solution here, I'm limited by the tools my org uses.</p>
<p>For reference, I open create a new workspace for each build. Our codebase is auto-generated code, so for each build, each required .cpp/.hpp is generated. Having a new workspace for each build means I don't have duplicates of files. I don't know if this is the optimal workflow for me.. but it works. As such, having some easily transferable/global build tasks/run configurations would make my life a little bit easier.</p>
<p>EDIT:
I was able to set up my task.json for this, just need to figure out for launch configurations :)</p>
<pre><code>"tasks":[
{
"label": "Build",
"type": "shell",
"command": "vcvars32.bat && for /r ${workspaceFolder} %i in (*.mak) do nmake /nologo /S /F %i",
"group": "build",
"options": {"cwd": "${workspaceFolder}"
},
]
</code></pre>
| [
{
"answer_id": 74313861,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": -1,
"selected": false,
"text": "Exception"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11432928/"
] |
74,313,799 | <p>I want to loop through a dictionary of values that contain protein sequences in letters. The dictionary could be as large as 200,000 keys.</p>
<p>Using a for loop, it takes way too long. Below is my current implementation.</p>
<pre><code>def find_msa_diversity(seq_dict):
"""Find the diversity of the MSA"""
summation = 0
for n in seq_dict.values():
count = 0
for m in seq_dict.values():
start = time.time()
if m == n:
continue
if seq_similarity(n, m) > 0.8:
count += 1
print(f"seq_count: {count}")
</code></pre>
<p>This is the seq_similarity function:</p>
<pre><code>def seq_similarity(n,m):
counter = 0
for i in range(len(seq_n)):
if seq_n[i] == seq_m[i]:
counter += 1
return 1 if counter/len(seq_n) > 0.8 else 0
</code></pre>
<p>I also tried to use np.array here:</p>
<pre><code>def seq_similarity(n,m):
similarity_count = sum(np.array(seq_n) == np.array(seq_m))
return similarity_count/len(seq_n)
</code></pre>
<p>However, the former code seems even faster than the second.</p>
<p>How can I optimise the "find_msa_diversity" first and foremost (I thought about using numpy vectorisation too, but it I hear it won't be much of a difference if the values are strings instead of numbers. I am also thinking about using Python Multiprocessing.)</p>
<p>I will appreciate your contributions. Thank you.</p>
| [
{
"answer_id": 74313861,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": -1,
"selected": false,
"text": "Exception"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13329337/"
] |
74,313,801 | <pre><code>cur.execute("""
CREATE TEMPORARY VIEW bobby_view AS
SELECT heading1, heading2
FROM bobby
WHERE heading2 = %s; """, (variable,))
cur.execute("""
SELECT d1.heading1
FROM bobby_view d1
WHERE d1.heading1 >= ALL (
SELECT d2.heading1
FROM bobby_view d2);
""")
answer = cur.fetchone()[0]
</code></pre>
<p>This produces the error:</p>
<blockquote>
<p>TypeError: 'NoneType' object is not subscriptable</p>
</blockquote>
<p>This is the structure of my code. Variable was an integer entered as a parameter to a function and it has been casted as a string prior to the above code.</p>
<p>The second block of code finds the heading1 data that is the highest. I've tested this on its own and I am fairly confident it works. Because of this, I think the error comes from variable not being used in the view properly. Any help or advice would be greatly appreciated.</p>
| [
{
"answer_id": 74313861,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": -1,
"selected": false,
"text": "Exception"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415241/"
] |
74,313,820 | <p>I receive a JSON in string format which I'm converting to Java Object Class using the Gson library. In that JSON the DateTime field is annotated with <strong>@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")</strong> The original format in which the date is <strong>"creationDate": "2022-10-25T10:38:32.000+01:00"</strong> after converting the JSON to Java Object Class the format of the DateTime fields changes to <strong>Tue Oct 25 15:08:32 IST 2022</strong> rather than converting it to the required format.
Below is an example of my POJO class</p>
<pre><code>@Data
public class Root{
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date creationDate;}
</code></pre>
<p>Below is an example of how I'm converting my string to Java Object Class</p>
<pre><code>String fileContent = Files.readString(Path.of"**Path of the file**"));
Root root = new Gson().fromJson(fileContent, Root.class);
</code></pre>
<p>JSON example:</p>
<pre><code>root{
"creationDate":"2022-10-25T10:38:32.000+01:00"
}
</code></pre>
<p>I dont understand why this is happening. I know I can convert it using new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(sDate1)
But I want to understand why @annotation is not working</p>
| [
{
"answer_id": 74313861,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": -1,
"selected": false,
"text": "Exception"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6825083/"
] |
74,313,829 | <p>I am starting learning "React Three Fiber" with TypeScript,
but when I started my journey, I got stuck with this problem. I've searched a lot on internet but didn't find my answer.</p>
<pre class="lang-js prettyprint-override"><code>import React from "react";
import { Canvas, useFrame } from "@react-three/fiber";
const AnimatedBox() {
const meshRef = useRef();
useFrame(()=>{
console.log("hi");
if(meshRef.current){
meshRef.current.rotation += 0.01;
}
});
return (
<mesh ref = {meshRef} scale={[0.5, 0.5 ,0.5]}>
<boxGeometry />
<meshStandardMaterial />
</mesh>
);
}
export default function App() {
return (
<div className="App">
<Canvas>
<AnimatedBox />
<ambientLight intensity={0.1} />
<directionalLight />
</Canvas>
</div>
);
}
</code></pre>
<p>Every time I run this code I got this error:</p>
<blockquote>
<p>Property 'rotation' does not exist on type 'never'.</p>
</blockquote>
| [
{
"answer_id": 74313856,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 1,
"selected": false,
"text": "const meshRef = useRef<HTMLElement>()\n"
},
{
"answer_id": 74314157,
"author": "mlegrix",
"author_id": 2561548,
"author_profile": "https://Stackoverflow.com/users/2561548",
"pm_score": 1,
"selected": true,
"text": "useRef"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17975554/"
] |
74,313,834 | <p>I'm creating a simple chat app wherein every chatbubbles will be shown in a RecyclerView, now I noticed that every time ill enter a new data coming from Firebase RealTime Database, the old data's / or let's say the old chat bubbles will disappear and reappear once the newly added data has been displayed. I would like the old chat bubbles to not behave just like that, I would like it to remain appeared the whole time.</p>
<p>Here's my method to load every chatbubbles:</p>
<pre><code>private void LoadChat() {
Query orderPosts = ChatRef.orderByChild("servertimestamp");
options = new FirebaseRecyclerOptions.Builder<Chat>().setQuery(orderPosts, Chat.class).build();
adapter = new FirebaseRecyclerAdapter<Chat, MyViewHolder12>(options) {
@Override
protected void onBindViewHolder(@NonNull MyViewHolder12 holder, int position, @NonNull Chat model) {
final String userpower = model.getPower();
final String pow = "Admin";
if (userpower.equals(pow)){
holder.chat_userpower.setVisibility(View.VISIBLE);
holder.chat_userpower.setText(model.getPower());
}
else{
holder.chat_userpower.setVisibility(View.GONE);
}
final String quotedc = model.getQuotedchat();
final String quotedn = model.getQuotedname();
if (quotedc == null){
holder.quotedchatbox.setVisibility(View.GONE);
holder.quotedchatboxlayout.setVisibility(View.GONE);
holder.quotedchatdescription.setVisibility(View.GONE);
}
else{
holder.quotedchatboxlayout.setVisibility(View.VISIBLE);
holder.quotedchatbox.setVisibility(View.VISIBLE);
holder.quotedchatdescription.setVisibility(View.VISIBLE);
holder.quotedchatdescription.setText("Quoted "+ model.getQuotedname() +" " + model.getQuotedchat());
}
holder.chat_usercomment.setText(model.getChat());
Picasso.get().load(model.getProfileimage()).placeholder(R.drawable.profile).into(holder.chat_userimage);
holder.chat_userdep.setText(model.getDep());
holder.chat_date.setText(model.getDate());
holder.chat_username.setText(model.getUsername());
holder.nestedchat_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quote = true;
quotedname = model.getUsername();
//CommentKey = getRef(holder.getAdapterPosition()).getKey();
quoting.setVisibility(View.VISIBLE);
quotedchat = model.getChat();
quoting.setText("Quoting "+ quotedname + ": " + model.getChat());
quoting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quote = false;
quoting.setVisibility(View.GONE);
}
});
}
});
}
@NonNull
@Override
public MyViewHolder12 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.allchatlayout, parent, false);
return new MyViewHolder12(view);
}
};
adapter.startListening();
allchatlist.setAdapter(adapter);
}
</code></pre>
<p>here's my layoutmanager:</p>
<pre><code> LinearLayoutManager lm = new LinearLayoutManager(this);
lm.setReverseLayout(false);
lm.setStackFromEnd(false);
allchatlist.setNestedScrollingEnabled(false);
allchatlist.setLayoutManager(lm);
</code></pre>
<p>here's my code calling the method:</p>
<pre><code> ChatRef = FirebaseDatabase.getInstance().getReference().child("Forums").child(ChatRoomNameKey).child("Forum ChatRoom");
ChatRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()){
LoadChat();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
</code></pre>
| [
{
"answer_id": 74313856,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 1,
"selected": false,
"text": "const meshRef = useRef<HTMLElement>()\n"
},
{
"answer_id": 74314157,
"author": "mlegrix",
"author_id": 2561548,
"author_profile": "https://Stackoverflow.com/users/2561548",
"pm_score": 1,
"selected": true,
"text": "useRef"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19240900/"
] |
74,313,835 | <p>I have an output that contains a high number of words. I want to take these in a list and find their frequency column by column in my data.</p>
<p>For example, my output is with frequencies in the whole data</p>
<pre><code>ich 4
mΓΆchte 5
doner 3
und 2
ayran 6
</code></pre>
<p>and my columns are 2000, 2001, 2002, 2003. I want to find how many "ich","mΓΆchte","doner","und","ayran" are in those columns separately.</p>
<p>Please help me about taking this output as a list and find their frequencies, as I explained above. Please use R.</p>
| [
{
"answer_id": 74314099,
"author": "KrisAnathema",
"author_id": 3829013,
"author_profile": "https://Stackoverflow.com/users/3829013",
"pm_score": 0,
"selected": false,
"text": "word_count <- data.frame(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words <- c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nword_count %>%\n group_by(Y2000) %>%\n summarize(Y2000_count = n()) %>%\n filter(Y2000 %in% interesting_words)\n\nword_count %>%\n group_by(Y2001) %>%\n summarize(Y2001_count = n()) %>%\n filter(Y2001 %in% interesting_words)\n\nword_count %>%\n group_by(Y2002) %>%\n summarize(Y2002_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n\nword_count %>%\n group_by(Y2003) %>%\n summarize(Y2003_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n"
},
{
"answer_id": 74315014,
"author": "edvinsyk",
"author_id": 16252296,
"author_profile": "https://Stackoverflow.com/users/16252296",
"pm_score": 1,
"selected": false,
"text": "library(data.table)\n\nword_count <- data.table(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words = c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nwc_long = melt(word_count, measure.vars = c(\"Y2000\", \"Y2001\", \"Y2002\", \"Y2003\"))\n\nwc_long[value %chin% interesting_words, .N, by = value][order(-N)]\n\n value N\n1: ich 5\n2: und 4\n3: ayran 3\n4: doner 2\n5: mΓΆchte 1\n\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17106998/"
] |
74,313,838 | <p>I am trying to add a search input control to the app header in my Flutter web app.</p>
<p>See...</p>
<pre><code>Widget _buildSearchControl() {
return Container(
alignment: Alignment.centerLeft,
color: Colors.white,
padding: EdgeInsets.only(right: 20),
margin: EdgeInsets.all(10),
width: 300,
child: TextField(
style: TextStyle(backgroundColor: Colors.white, color: Colors.black),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search,color: Colors.black,),
suffixIcon: IconButton(
icon: const Icon(Icons.clear,color: Colors.black,),
onPressed: () {
/* Clear the search field */
},
),
hintText: 'Search...',
border: InputBorder.none),
),
);
}
</code></pre>
<p>However, when entering the text, the characters are not vertically centre aligned as I wpuld expect</p>
<p><a href="https://i.stack.imgur.com/diG29.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/diG29.png" alt="enter image description here" /></a></p>
<p>Is there a way I can have the characters input to the TextField control vertically centered so that they line up with the icons?</p>
| [
{
"answer_id": 74314099,
"author": "KrisAnathema",
"author_id": 3829013,
"author_profile": "https://Stackoverflow.com/users/3829013",
"pm_score": 0,
"selected": false,
"text": "word_count <- data.frame(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words <- c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nword_count %>%\n group_by(Y2000) %>%\n summarize(Y2000_count = n()) %>%\n filter(Y2000 %in% interesting_words)\n\nword_count %>%\n group_by(Y2001) %>%\n summarize(Y2001_count = n()) %>%\n filter(Y2001 %in% interesting_words)\n\nword_count %>%\n group_by(Y2002) %>%\n summarize(Y2002_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n\nword_count %>%\n group_by(Y2003) %>%\n summarize(Y2003_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n"
},
{
"answer_id": 74315014,
"author": "edvinsyk",
"author_id": 16252296,
"author_profile": "https://Stackoverflow.com/users/16252296",
"pm_score": 1,
"selected": false,
"text": "library(data.table)\n\nword_count <- data.table(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words = c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nwc_long = melt(word_count, measure.vars = c(\"Y2000\", \"Y2001\", \"Y2002\", \"Y2003\"))\n\nwc_long[value %chin% interesting_words, .N, by = value][order(-N)]\n\n value N\n1: ich 5\n2: und 4\n3: ayran 3\n4: doner 2\n5: mΓΆchte 1\n\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2868835/"
] |
74,313,894 | <p>Have a csv file with tons of rows, small example:</p>
<pre><code>id,location_id,name,title,email,directorate
1,1, Amy lee,Singer,,
2,2,brad Pitt,Actor,,Production
3,5,Steven Spielberg,Producer,spielberg@my.com,Production
</code></pre>
<p>Need to:</p>
<ul>
<li>change first and last name to uppercase, example, Brad Pitt, Amy Lee.</li>
<li>create email with pattern first letter of first name + last name, all in lowercase with @google.com and value from <em>location_id</em>, example - ale1e@google.com, bpitt2@google.com</li>
<li>save it to new file.csv, with the same structure, example:</li>
</ul>
<pre><code>id,location_id,name,title,email,directorate
1,1, Amy Lee,Singer,alee1@google.com,
2,2,Brad Pitt,Actor,bpitt@google.com,Production
3,5,Steven Spielberg,Producer,sspielberg@google.com,Production
</code></pre>
<p>I started from create a array and iterate through it, with bunch of sed, awk, but it gives to me random results.
Please give me advice, how resolve this task.</p>
<pre><code>while read -ra array; do
for i in ${array[@]};
do
awk -F ',' '{print tolower(substr($3,1,1))$2$3"@google.com"}'
done
for i in ${array[@]};
do
awk -F "\"*,\"*" '{print $3}' | sed -e "s/\b\(.\)/\u\1/g"
done
done < file.csv
</code></pre>
<p><code>awk -F ',' '{print tolower(substr($3,1,1))$2$3"@google.com"}'</code> working not correct.</p>
| [
{
"answer_id": 74314099,
"author": "KrisAnathema",
"author_id": 3829013,
"author_profile": "https://Stackoverflow.com/users/3829013",
"pm_score": 0,
"selected": false,
"text": "word_count <- data.frame(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words <- c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nword_count %>%\n group_by(Y2000) %>%\n summarize(Y2000_count = n()) %>%\n filter(Y2000 %in% interesting_words)\n\nword_count %>%\n group_by(Y2001) %>%\n summarize(Y2001_count = n()) %>%\n filter(Y2001 %in% interesting_words)\n\nword_count %>%\n group_by(Y2002) %>%\n summarize(Y2002_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n\nword_count %>%\n group_by(Y2003) %>%\n summarize(Y2003_count = n()) %>%\n filter(Y2002 %in% interesting_words)\n"
},
{
"answer_id": 74315014,
"author": "edvinsyk",
"author_id": 16252296,
"author_profile": "https://Stackoverflow.com/users/16252296",
"pm_score": 1,
"selected": false,
"text": "library(data.table)\n\nword_count <- data.table(Y2000 = c(\"word1\", \"word2\", \"ich\", \"ich\", \"word5\", \"und\"),\n Y2001 = c(\"ich\", \"mΓΆchte\", \"word3\", \"ayran\", \"ayran\", \"word6\"),\n Y2002 = c(\"word1\", \"word2\", \"und\", \"und\", \"doner\", \"und\"),\n Y2003 = c(\"ich\", \"word2\", \"ayran\", \"ich\", \"word5\", \"doner\"))\n\ninteresting_words = c(\"ich\", \"mΓΆchte\", \"doner\", \"und\", \"ayran\")\n\nwc_long = melt(word_count, measure.vars = c(\"Y2000\", \"Y2001\", \"Y2002\", \"Y2003\"))\n\nwc_long[value %chin% interesting_words, .N, by = value][order(-N)]\n\n value N\n1: ich 5\n2: und 4\n3: ayran 3\n4: doner 2\n5: mΓΆchte 1\n\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10009512/"
] |
74,313,909 | <p>I try to implement push notification in android mobile app. Using</p>
<pre><code>cordova-plugin-firebase-messaging
</code></pre>
<p>I can send push notification to android mobile using firebase console , but what happen those are installed apk file , all are receive push notifications, but i want to send to specific users, so i want to get FCM token.</p>
<p>What i am tried, in 'index.js' file, onDeviceReady function i call the below function to get token.</p>
<pre><code>document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});
FCMPlugin.getToken(function(token){
alert(token);
});
}
</code></pre>
<p>When i build and install apk file and open in mobile device, but nothing show when open device.
My Cordova version is 11.0.0
and installed plugin is</p>
<pre><code>cordova-plugin-fcm-with-dependecy-updated 7.8.0 "Cordova FCM Push Plugin"
</code></pre>
<p>Any reply much appreciate.</p>
<p>Regards
Aravind</p>
| [
{
"answer_id": 74318458,
"author": "Eric",
"author_id": 749657,
"author_profile": "https://Stackoverflow.com/users/749657",
"pm_score": 0,
"selected": false,
"text": "https://fcm.googleapis.com/fcm/send"
},
{
"answer_id": 74336108,
"author": "Riya Singh",
"author_id": 13949589,
"author_profile": "https://Stackoverflow.com/users/13949589",
"pm_score": 2,
"selected": true,
"text": "<script type=\"module\">\n // Import the functions you need from the SDKs you need\n import { initializeApp } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js\";\n import { getAnalytics } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-analytics.js\";\n // TODO: Add SDKs for Firebase products that you want to use\n // https://firebase.google.com/docs/web/setup#available-libraries\n \n // Your web app's Firebase configuration\n // For Firebase JS SDK v7.20.0 and later, measurementId is optional\n const firebaseConfig = {\n apiKey: \"YOUR_API_KEY\",\n authDomain: \"YOUR_AUTH_DOMAIN (get it from your firebase project)\",\n databaseURL: \"YOUR_FIREBASE_DB_PATH\",\n projectId: \"YOUR_PROJECT_ID\",\n storageBucket: \"YOUR_STORAGE_BUCKET\",\n messagingSenderId: \"YOUR_SENDERS_ID\",\n appId: \"YOUR_APP_ID\",\n measurementId: \"G-4TN45ZQFFJ\"\n };\n \n // Initialize Firebase\n const app = initializeApp(firebaseConfig);\n const analytics = getAnalytics(app);\n </script>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2484835/"
] |
74,313,923 | <p>the idea is basically the loop takes in input and it runs until I type "quit" but it doesn't work the way I want to and I can't figure out why :( (p.s. im a beginner that came from python pls be kind)</p>
<pre><code>import java.util.Scanner;
class HelloWorld {
static String s1;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
do {
s1 = in.next();
} while (s1 != "quit");
System.out.println(s1);
}
}
</code></pre>
<p>I also tried adding a temporary variable so that the while loop could check the condition before continuing but it doesn't work that way too...</p>
<pre><code>import java.util.Scanner;
class HelloWorld {
static String s1;
static String s2;
static int s3;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
do {
s1=in.next();
if (s1=="quit"){
break;
}
s2=in.next();
s3=in.nextInt();
} while (s1!="quit");
System.out.println("Terminate");
}
}
</code></pre>
| [
{
"answer_id": 74318458,
"author": "Eric",
"author_id": 749657,
"author_profile": "https://Stackoverflow.com/users/749657",
"pm_score": 0,
"selected": false,
"text": "https://fcm.googleapis.com/fcm/send"
},
{
"answer_id": 74336108,
"author": "Riya Singh",
"author_id": 13949589,
"author_profile": "https://Stackoverflow.com/users/13949589",
"pm_score": 2,
"selected": true,
"text": "<script type=\"module\">\n // Import the functions you need from the SDKs you need\n import { initializeApp } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js\";\n import { getAnalytics } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-analytics.js\";\n // TODO: Add SDKs for Firebase products that you want to use\n // https://firebase.google.com/docs/web/setup#available-libraries\n \n // Your web app's Firebase configuration\n // For Firebase JS SDK v7.20.0 and later, measurementId is optional\n const firebaseConfig = {\n apiKey: \"YOUR_API_KEY\",\n authDomain: \"YOUR_AUTH_DOMAIN (get it from your firebase project)\",\n databaseURL: \"YOUR_FIREBASE_DB_PATH\",\n projectId: \"YOUR_PROJECT_ID\",\n storageBucket: \"YOUR_STORAGE_BUCKET\",\n messagingSenderId: \"YOUR_SENDERS_ID\",\n appId: \"YOUR_APP_ID\",\n measurementId: \"G-4TN45ZQFFJ\"\n };\n \n // Initialize Firebase\n const app = initializeApp(firebaseConfig);\n const analytics = getAnalytics(app);\n </script>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415373/"
] |
74,313,941 | <p>I'm trying to create a rule for create/access the FRD data based on authenticated user. But am getting an error where running the <strong><code>Rules Playground</code></strong></p>
<p>What I want is, Users are creating the categories. So Users is able to only read their categories and update those categories.</p>
<p><strong>Rule:</strong></p>
<pre><code>{
"rules": {
"users": {
"$uid": {
".write": "auth != null && $uid === auth.uid",
".read": "auth != null && $uid === auth.uid"
}
},
"categories": {
"$uid": {
".write": "auth != null && $uid === auth.uid",
".read": "auth != null && $uid === auth.uid"
}
}
}
}
</code></pre>
<p><strong>Auth Users:</strong></p>
<p><a href="https://i.stack.imgur.com/bNlOE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bNlOE.png" alt="Here is authentication users to firebase" /></a></p>
<p><strong>Realtime Database</strong></p>
<p><em><strong>Categories</strong></em>
<a href="https://i.stack.imgur.com/Anx32.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Anx32.png" alt="This is categories table" /></a></p>
<p><em><strong>Users</strong></em>
<a href="https://i.stack.imgur.com/x2hRk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x2hRk.png" alt="This is users table" /></a></p>
<p><em><strong>Categories Write function in Flutter</strong></em></p>
<pre><code>String uId = await userId();
final databaseRef = FirebaseDatabase.instance.ref('categories');
var data = await databaseRef.get();
var index = data.children.length;
await databaseRef.child('$index').set(<String, dynamic>{
"name": categoryBody.name,
"description": categoryBody.description,
"uid": uId,
"id": index,
});
</code></pre>
<p><em><strong>Error</strong></em>
<a href="https://i.stack.imgur.com/ge13c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ge13c.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/7WeRe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7WeRe.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/VB0jT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VB0jT.png" alt="enter image description here" /></a></p>
<p>Is there anything wrong with the rules that am applying?</p>
| [
{
"answer_id": 74318458,
"author": "Eric",
"author_id": 749657,
"author_profile": "https://Stackoverflow.com/users/749657",
"pm_score": 0,
"selected": false,
"text": "https://fcm.googleapis.com/fcm/send"
},
{
"answer_id": 74336108,
"author": "Riya Singh",
"author_id": 13949589,
"author_profile": "https://Stackoverflow.com/users/13949589",
"pm_score": 2,
"selected": true,
"text": "<script type=\"module\">\n // Import the functions you need from the SDKs you need\n import { initializeApp } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js\";\n import { getAnalytics } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-analytics.js\";\n // TODO: Add SDKs for Firebase products that you want to use\n // https://firebase.google.com/docs/web/setup#available-libraries\n \n // Your web app's Firebase configuration\n // For Firebase JS SDK v7.20.0 and later, measurementId is optional\n const firebaseConfig = {\n apiKey: \"YOUR_API_KEY\",\n authDomain: \"YOUR_AUTH_DOMAIN (get it from your firebase project)\",\n databaseURL: \"YOUR_FIREBASE_DB_PATH\",\n projectId: \"YOUR_PROJECT_ID\",\n storageBucket: \"YOUR_STORAGE_BUCKET\",\n messagingSenderId: \"YOUR_SENDERS_ID\",\n appId: \"YOUR_APP_ID\",\n measurementId: \"G-4TN45ZQFFJ\"\n };\n \n // Initialize Firebase\n const app = initializeApp(firebaseConfig);\n const analytics = getAnalytics(app);\n </script>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1826656/"
] |
74,313,977 | <p>I am creating MERN application and using env file but I am not able to access env variable inside react application , below is my code</p>
<pre><code>import React from 'react';
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Sidebar from './components/sidebar/Sidebar';
import "./app.css";
import TopBar from './components/topbar/Topbar';
import Home from './pages/home/Home';
import AdminUsersList from './pages/adminusers/AdminUsersList';
function App() {
return (
<Router>
<TopBar />
<div className="container">
<Sidebar />
<Routes>
<Route path='/' element={<Home/>} />
<Route path='/users' element={<AdminUsersList/>} />
</Routes>
<h1>Hello {process.env.MONGO_URI}</h1>
</div>
</Router>
);
}
export default App;
</code></pre>
<p>Want to access env variable inside function and class component of react.</p>
| [
{
"answer_id": 74318458,
"author": "Eric",
"author_id": 749657,
"author_profile": "https://Stackoverflow.com/users/749657",
"pm_score": 0,
"selected": false,
"text": "https://fcm.googleapis.com/fcm/send"
},
{
"answer_id": 74336108,
"author": "Riya Singh",
"author_id": 13949589,
"author_profile": "https://Stackoverflow.com/users/13949589",
"pm_score": 2,
"selected": true,
"text": "<script type=\"module\">\n // Import the functions you need from the SDKs you need\n import { initializeApp } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js\";\n import { getAnalytics } from \"https://www.gstatic.com/firebasejs/9.10.0/firebase-analytics.js\";\n // TODO: Add SDKs for Firebase products that you want to use\n // https://firebase.google.com/docs/web/setup#available-libraries\n \n // Your web app's Firebase configuration\n // For Firebase JS SDK v7.20.0 and later, measurementId is optional\n const firebaseConfig = {\n apiKey: \"YOUR_API_KEY\",\n authDomain: \"YOUR_AUTH_DOMAIN (get it from your firebase project)\",\n databaseURL: \"YOUR_FIREBASE_DB_PATH\",\n projectId: \"YOUR_PROJECT_ID\",\n storageBucket: \"YOUR_STORAGE_BUCKET\",\n messagingSenderId: \"YOUR_SENDERS_ID\",\n appId: \"YOUR_APP_ID\",\n measurementId: \"G-4TN45ZQFFJ\"\n };\n \n // Initialize Firebase\n const app = initializeApp(firebaseConfig);\n const analytics = getAnalytics(app);\n </script>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6384458/"
] |
74,313,981 | <p>I want to make a function that receive error message string then after some time to disappear, I want to call this function along my application so no need to write the whole code every time I have error response , I tried the code below which works fine but I feel it is still big and can be more short please advice</p>
<p>this code in commonService.ts file</p>
<pre><code>clearErrorMsg = () => {
return new Promise<string>((resolve) => {
setTimeout(() => {
resolve('');
}, 3000);
});
};
async errorMessageClear(){
return await this.clearErrorMsg();
};
</code></pre>
<p>and here I call it from different ts file</p>
<pre><code> const mainFunction = async () => {
this.error = err.message;
this.error = await this._commonService.clearErrorMsg();
};
mainFunction();
</code></pre>
<p>HTML</p>
<pre><code> <ngb-alert [type]="'danger'" [dismissible]="false"
*ngIf="error">
<div class="alert-body">
<p>{{error}}</p>
</div>
</code></pre>
| [
{
"answer_id": 74314112,
"author": "Park Numb",
"author_id": 19380738,
"author_profile": "https://Stackoverflow.com/users/19380738",
"pm_score": 2,
"selected": true,
"text": "MatSnackBar: @angular/material/snack-bar"
},
{
"answer_id": 74314151,
"author": "Fabian Strathaus",
"author_id": 17298437,
"author_profile": "https://Stackoverflow.com/users/17298437",
"pm_score": 0,
"selected": false,
"text": "rxjs"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15749884/"
] |
74,313,986 | <p>I have a generic table in global area and i want to use it in SELECT from. Is this possible or is there a way do this ?</p>
<p>Example Code:</p>
<pre><code>FIELD-SYMBOLS: <gt_data> TYPE STANDARD TABLE.
CLASS-DATA: mo_data TYPE REF TO data.
CREATE DATA mo_data LIKE lt_data.
ASSIGN mo_data->* TO <gt_data>.
<gt_data> = lt_data.
SELECT data~matnr,
mbew~malzeme_deger
FROM zmm_ddl_mbew AS mbew
INNER JOIN @<gt_data> AS data ON data~matnr EQ mbew~matnr
INTO TABLE @DATA(lt_mbew).
</code></pre>
| [
{
"answer_id": 74332052,
"author": "phil soady",
"author_id": 1347784,
"author_profile": "https://Stackoverflow.com/users/1347784",
"pm_score": 1,
"selected": false,
"text": "Select from DBTAB where (string_cond).\n"
},
{
"answer_id": 74409243,
"author": "Suncatcher",
"author_id": 911419,
"author_profile": "https://Stackoverflow.com/users/911419",
"pm_score": 0,
"selected": false,
"text": "SELECT"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74313986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8483991/"
] |
74,314,037 | <p>I have configured some filters (given below) in web.xml of the tomcat server which were working fine before when we are on log4j1.x.</p>
<pre><code><filter>
<filter-name>newsession</filter-name>
<display-name>newsession</display-name>
<description>newsession</description>
<filter-class>com.demo.custom.filter.NewSession</filter-class>
<init-param>
<param-name>DomainName</param-name>
<param-value>.testlab.com</param-value>
</init-param>
<init-param>
<param-name>DomConfigFile</param-name>
<param-value>/opt/tomcat/webapp/demoapp/WEB-INF/classes/NAM_log4j.xml</param-value>
</init-param>
<init-param>
<param-name>customPropFile</param-name>
<param-value>/opt/tomcat/webapp/demoapp/WEB-INF/classes/custom_resources.properties</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>newsession</filter-name>
<url-pattern>/idff/sso</url-pattern>
</filter-mapping>
</code></pre>
<p>But now when I have moved from log4j1.x to log4j2.x after that when we are starting the tomcat service we are getting the below error in the log. If I placed the "log4j-1.2.15.jar" file again it is working fine. But now we are on log4j2.x so we cannot use the old log4j1.x.</p>
<pre><code>ERROR com.demo.custom.filter.NewSession - No transformation given
ERROR com.demo.custom.filter.NewSession - domConfigFile got null from web.xml, setting hardcoded value
ERROR com.demo.custom.filter.NewSession - custom_resources got null from web.xml, setting hardcoded value
main ERROR Error processing element category ([Configuration: null]): CLASS_NOT_FOUND
main ERROR Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"]
</code></pre>
<p>My Java code is given below, I have pasted only the code where I am trying to initialize the servlet filters.</p>
<pre><code>package com.demo.custom.filter;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
@WebFilter({ "/NewSession" })
public class NewSession implements Filter {
static class FilteredRequest extends HttpServletRequestWrapper {
public FilteredRequest(ServletRequest request) {
super((HttpServletRequest)request);
}
public String getParameter(String paramName) {
String value = super.getParameter(paramName);
*********************************************
return value;
}
public static String decryptValue(String value){
String decryptvalue = null;
********************************************
return decryptvalue;
}
}
private static String domainName = null;
private static String domConfigFile=null;
private static Logger myLogger = LogManager.getLogger(NewSession.class);
private String custom_resources;
public void init(FilterConfig fConfig) throws ServletException {
try{
domainName = fConfig.getInitParameter("DomainName");
domConfigFile=fConfig.getInitParameter("DomConfigFile");
custom_resources=fConfig.getInitParameter("customPropFile");
}catch(Exception e){
myLogger.error(e.getMessage());
}
if(domainName == null){
domainName = ".testlab.com";
}
if(domConfigFile==null){
myLogger.error("domConfigFile got null from web.xml, setting hardcoded value");
domConfigFile = "/opt/tomcat/webapp/demoapp/WEB-INF/classes/NAM_log4j.xml";
}
if(custom_resources==null){
myLogger.error("custom_resources got null from web.xml, setting hardcoded value");
nidp_custom_resources = "/opt/tomcat/webapp/demoapp/WEB-INF/classes/custom_resources.properties";
}
}
}
</code></pre>
<p>Please help me on this. I am using tomcat 9 and log4j v2.17.1.</p>
| [
{
"answer_id": 74356279,
"author": "user3441151",
"author_id": 3441151,
"author_profile": "https://Stackoverflow.com/users/3441151",
"pm_score": 2,
"selected": true,
"text": "<Configuration>\n <Appenders>\n <Console name=\"STDOUT\" target=\"SYSTEM_OUT\">\n <PatternLayout pattern=\"%d{MM/dd HH:mm:ss} %-5p %30.30c %x - %m\\n\"/>\n </Console>\n <RollingFile name=\"RollingFile\" fileName=\"/opt/tomcat/logs/MyCustomClassLogs.log\" filePattern=\"/opt/tomcat/logs/MyCustomClassLogs.log-%i\">\n <PatternLayout>\n <pattern>%d{MM/dd HH:mm:ss} %-5p %30.30c %x - %m\\n</pattern>\n </PatternLayout>\n <Policies>\n <SizeBasedTriggeringPolicy size=\"5 MB\" />\n </Policies>\n <DefaultRolloverStrategy max=\"5\"/>\n </RollingFile>\n <RollingFile name=\"ResetClass\" fileName=\"/opt/tomcat/logs/resetTrace.log\" filePattern=\"/opt/tomcat/logs/resetTrace.log-%i\">\n <PatternLayout>\n <pattern>%d{MM/dd HH:mm:ss} %-5p %30.30c %x - %m\\n</pattern>\n </PatternLayout>\n <Policies>\n <SizeBasedTriggeringPolicy size=\"5 MB\" />\n </Policies>\n <DefaultRolloverStrategy max=\"5\"/>\n </RollingFile>\n </Appenders>\n <Loggers>\n <Logger name=\"com.demo.custom.filter.ResetClass\" level=\"TRACE\">\n <AppenderRef ref=\"ResetClass\"/>\n </Logger>\n <Logger name=\"com.demo.custom.test.MyCustomClass\" level=\"TRACE\">\n <AppenderRef ref=\"RollingFile\"/>\n </Logger>\n <Root level=\"error\">\n <AppenderRef ref=\"STDOUT\"/>\n </Root>\n </Loggers>\n</Configuration>\n"
},
{
"answer_id": 74356821,
"author": "Piotr P. Karwasz",
"author_id": 11748454,
"author_profile": "https://Stackoverflow.com/users/11748454",
"pm_score": 0,
"selected": false,
"text": "@WebFilter"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3441151/"
] |
74,314,054 | <p>I am trying to not make my code redundant and I would like to know, if in a .updateOne method, when Im passing data to change, if its possible to implement if statement to choose from the data. Here is a situation.</p>
<p>I have my db model:</p>
<pre><code>const depositarySchema = new Schema({
euid: {
type: String,
required: true
},
euid2: {
type: String
},
count: {
type: Number,
required: true
},
euroPallets: {
type: Number,
},
biggerPallets: {
type: Number,
},
otherPallets: {
type: Number,
},
depositary: {
type: Number,
required: true
},
title: {
type: String
}
});
</code></pre>
<p>Then I have a variable: var = 1 for euroPallets, 2 for biggerPallets and 3 for otherPallets. I would like to implement something like this:</p>
<pre><code>Depositary.updateOne(
{
euid: euid,
},
{
count: dep.count - palletCounter,
if(var === 1){
euroPallets: count}
elseif(var===2){
biggerPallets: count}
else{
otherPallets: count}
</code></pre>
<p>},</p>
<p>where count is just a number. I hope its understandable what im trying to achieve, sorry for a wrong syntax.</p>
| [
{
"answer_id": 74314766,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": true,
"text": "let upd = { \n euid: euid,\n count: dep.count - palletCounter\n};\n\nif (var === 1) {\n upd['euroPallets'] = count;\n}\nelse if (var === 2) {\n upd['biggerPallets'] = count;\n}\nelse {\n upd['otherPallets'] = count;\n}\n\nDepositary.updateOne(upd)\n"
},
{
"answer_id": 74315890,
"author": "Rickard ElimÀÀ",
"author_id": 5526624,
"author_profile": "https://Stackoverflow.com/users/5526624",
"pm_score": 1,
"selected": false,
"text": "const palletTypes = ['otherPallets', 'euroPallets', 'biggerPallets'];\nvar count = ep.count - palletCounter;\nvar palletType = palletTypes[count] ||Β palletTypes[0];\n\nvar pallets = {'count': count};\npallets[palletType] = count;\n\nDepositary.updateOne(\n {euid: euid},\n pallets\n)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15990133/"
] |
74,314,062 | <p><img src="https://i.stack.imgur.com/9Mwyd.png" alt="More Explaining picture" /></p>
<p>I WANNA AD AN IF CONDITION IN THE IF THE CONDITION IS TRUE PLACE
LIKE :
IF (G5> 0, IF(G5 > 6, "BIG", "SMALL"), "")</p>
<p><a href="https://i.stack.imgur.com/S0G3q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S0G3q.png" alt="THIS IS WHAT I AM TRYING TO CALCULATE" /></a>
=IF(G5>0, IF(D6>0, IF(G5>D6, G5-D6, 0), G5+E6),IF(D6<0,IF(E6>F5, E6-F5, 0),0))</p>
| [
{
"answer_id": 74314766,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": true,
"text": "let upd = { \n euid: euid,\n count: dep.count - palletCounter\n};\n\nif (var === 1) {\n upd['euroPallets'] = count;\n}\nelse if (var === 2) {\n upd['biggerPallets'] = count;\n}\nelse {\n upd['otherPallets'] = count;\n}\n\nDepositary.updateOne(upd)\n"
},
{
"answer_id": 74315890,
"author": "Rickard ElimÀÀ",
"author_id": 5526624,
"author_profile": "https://Stackoverflow.com/users/5526624",
"pm_score": 1,
"selected": false,
"text": "const palletTypes = ['otherPallets', 'euroPallets', 'biggerPallets'];\nvar count = ep.count - palletCounter;\nvar palletType = palletTypes[count] ||Β palletTypes[0];\n\nvar pallets = {'count': count};\npallets[palletType] = count;\n\nDepositary.updateOne(\n {euid: euid},\n pallets\n)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17381186/"
] |
74,314,108 | <p>I have a PHP page that shows me data from the database. I'm inserting a button that, if pressed, deletes the record. The problem is that if I push the button the action is done on all the records, because I can't uniquely identify the click on the button</p>
<p>some code</p>
<pre><code>foreach ( $associati as $associato ) {
echo "<hr />";
echo "Nome associato : ".$associato->Nome."</br>";
echo "Codice Fiscale : ".$associato->CF."</br>";
echo "<hr />";
if(isset($_POST["numerazione"])){
echo "Hello world"; //Query for delete
}
?>
<form method="POST" action="">
<input type="submit"
name="numerazione"
value="Elimina utente"
onclick="return confirm('Are you sure?')"
/>
</form>
<?php
}
</code></pre>
<p>How can I do to uniquely identify the button?</p>
| [
{
"answer_id": 74314766,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": true,
"text": "let upd = { \n euid: euid,\n count: dep.count - palletCounter\n};\n\nif (var === 1) {\n upd['euroPallets'] = count;\n}\nelse if (var === 2) {\n upd['biggerPallets'] = count;\n}\nelse {\n upd['otherPallets'] = count;\n}\n\nDepositary.updateOne(upd)\n"
},
{
"answer_id": 74315890,
"author": "Rickard ElimÀÀ",
"author_id": 5526624,
"author_profile": "https://Stackoverflow.com/users/5526624",
"pm_score": 1,
"selected": false,
"text": "const palletTypes = ['otherPallets', 'euroPallets', 'biggerPallets'];\nvar count = ep.count - palletCounter;\nvar palletType = palletTypes[count] ||Β palletTypes[0];\n\nvar pallets = {'count': count};\npallets[palletType] = count;\n\nDepositary.updateOne(\n {euid: euid},\n pallets\n)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20211382/"
] |
74,314,121 | <p>I have written this code:</p>
<p>In the first step, I read an Excel file that contains the addresses of the buildings as a string.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>LABE</th>
<th>HAUS</th>
<th>Gemeindename</th>
</tr>
</thead>
<tbody>
<tr>
<td>Hasenwinkel</td>
<td>14</td>
<td>Braunschweig</td>
</tr>
</tbody>
</table>
</div>
<p>The Excel file is similar to the table above.</p>
<p>I want to read the addresses inside a loop and get the coordinates of the addresses (Lat, Long) using CLGeocoder. Using the snapshotImage function, I give the coordinates as input to the function, and if there is picture, I want to save that picture of the target address with its address name.</p>
<p>But I get the following errors:</p>
<p>1.Cannot pass function of type '([CLPlacemark]?, (any Error)?) async throws -> Void' to parameter expecting synchronous function type</p>
<p>2. Invalid conversion from throwing function of type '([CLPlacemark]?, (any Error)?) async throws -> Void' to non-throwing function type '([CLPlacemark]?, (any Error)?) -> Void'</p>
<pre><code>let columnTypes: [String: CSVType] = ["LABE": .string,
"HAUS": .string,
"Gemeindename": .string]
let path = Bundle.main.url(forResource: "Adresse", withExtension: "csv")!
let options = CSVReadingOptions(
hasHeaderRow: true,
ignoresEmptyLines: true,
delimiter: ";"
)
let result = try DataFrame(contentsOfCSVFile: path,rows: 0..<50, types: columnTypes,options: options)
enum LookaroundError: Error {
case unableToCreateScene
}
func snapshotImage(for coordinate: CLLocationCoordinate2D) async throws -> UIImage {
guard let scene = try await MKLookAroundSceneRequest(coordinate: coordinate).scene else {
throw LookaroundError.unableToCreateScene
}
let options = MKLookAroundSnapshotter.Options()
options.size = CGSize(width: 1000, height: 500)
return try await MKLookAroundSnapshotter(scene: scene, options: options).snapshot.image
}
var address: String = ""
for row in result.rows {
if row["HAUS"] == nil {
address = "\(row["LABE"] ?? <#default value#>) \(row["Gemeindename"] ?? <#default value#>)"
} else {
address = "\(row["LABE"] ?? <#default value#>) \(row["HAUS"] ?? <#default value#>) \(row["Gemeindename"] ?? <#default value#>)"
}
print(address)
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address){ (placemarks, error) in
guard
let placemarks = placemarks,
let location: CLLocationCoordinate2D = placemarks.first?.location?.coordinate
else{
return
}
var image = try await snapshotImage(for: location)
var url = try FileManager.default
.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appending(component: "\(address).png")
try image.pngData()?.write(to: url)
}
}
</code></pre>
<p>Ideally, I want to read the addresses in this loop and save a picture of them using their coordinates.I don't have much experience in Swift programming. Does anyone have an idea how to solve the code problem?</p>
| [
{
"answer_id": 74314766,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": true,
"text": "let upd = { \n euid: euid,\n count: dep.count - palletCounter\n};\n\nif (var === 1) {\n upd['euroPallets'] = count;\n}\nelse if (var === 2) {\n upd['biggerPallets'] = count;\n}\nelse {\n upd['otherPallets'] = count;\n}\n\nDepositary.updateOne(upd)\n"
},
{
"answer_id": 74315890,
"author": "Rickard ElimÀÀ",
"author_id": 5526624,
"author_profile": "https://Stackoverflow.com/users/5526624",
"pm_score": 1,
"selected": false,
"text": "const palletTypes = ['otherPallets', 'euroPallets', 'biggerPallets'];\nvar count = ep.count - palletCounter;\nvar palletType = palletTypes[count] ||Β palletTypes[0];\n\nvar pallets = {'count': count};\npallets[palletType] = count;\n\nDepositary.updateOne(\n {euid: euid},\n pallets\n)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11332595/"
] |
74,314,139 | <p>I have a python list of touples like this:</p>
<pre><code>touple = [('Northwest Airlines', 93),
('Northwest Airlines', 81),
('Southwest Airlines', 79),
('NorthWestern', 77),
('NorthWestern', 69),
('Southwest Airlines', 69)]
</code></pre>
<p>Several of these items are duplicate. I want to keep only unique Touples having the largest value as the 2nd item.</p>
<p>The output I want to achieve is like this:</p>
<pre><code>processed_touple = [('Northwest Airlines', 93),
('Southwest Airlines', 79),
('NorthWestern', 77)]
</code></pre>
<p>What is the easiest way to achieve this ?</p>
| [
{
"answer_id": 74314766,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 1,
"selected": true,
"text": "let upd = { \n euid: euid,\n count: dep.count - palletCounter\n};\n\nif (var === 1) {\n upd['euroPallets'] = count;\n}\nelse if (var === 2) {\n upd['biggerPallets'] = count;\n}\nelse {\n upd['otherPallets'] = count;\n}\n\nDepositary.updateOne(upd)\n"
},
{
"answer_id": 74315890,
"author": "Rickard ElimÀÀ",
"author_id": 5526624,
"author_profile": "https://Stackoverflow.com/users/5526624",
"pm_score": 1,
"selected": false,
"text": "const palletTypes = ['otherPallets', 'euroPallets', 'biggerPallets'];\nvar count = ep.count - palletCounter;\nvar palletType = palletTypes[count] ||Β palletTypes[0];\n\nvar pallets = {'count': count};\npallets[palletType] = count;\n\nDepositary.updateOne(\n {euid: euid},\n pallets\n)"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4654120/"
] |
74,314,154 | <p>I am trying to run the flutter application on the android studio before now all works perfectly but after I changed my targetSdkVersion to <code>targetSdkVersion 31</code> I started getting this error that says</p>
<pre><code>Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not resolve com.google.firebase:firebase-core:25.12.0.
Required by:
project :app
> No cached version of com.google.firebase:firebase-core:25.12.0 available for offline mode.
</code></pre>
<p>And <code>google-services.json</code> is available in my project. My <code>pubspec.yaml</code> for firebase_message is <code>firebase_messaging: ^7.0.3</code>, <code>android/build.gradle</code>dependencies is</p>
<pre><code>buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
mavenCentral() // Maven Central repository
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
``` and my ```app/build.gradle``` dependencies is
</code></pre>
<pre><code>dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-analytics'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-core:11.0.4'
implementation platform('com.google.firebase:firebase-bom:31.0.2')
}
</code></pre>
<p>Thanks, in advance, please let me know if there is any information is needed</p>
<p>I tried to clean the project, pub upgrade, pub get, flutter upgrade, and even tried downloading a new version of firebase_messaging and pasting it inside the project still the same error.</p>
| [
{
"answer_id": 74314210,
"author": "MrShakila",
"author_id": 19292778,
"author_profile": "https://Stackoverflow.com/users/19292778",
"pm_score": 0,
"selected": false,
"text": "jcenter()"
},
{
"answer_id": 74342692,
"author": "YourDeveloper",
"author_id": 20230706,
"author_profile": "https://Stackoverflow.com/users/20230706",
"pm_score": 2,
"selected": true,
"text": "firebase_messaging"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20230706/"
] |
74,314,173 | <p>Im trying to capture numbers inside a file using AWK, I could capture all, but im not being able to capture those in a certain amount of digits. What im doing wrong?</p>
<p><code>echo -e "$teste" | awk '/_OA/ { match($0,/\[\([:digit:]{4,13}\]/);oa = substr($0,RSTART,RLENGTH);print oa}'</code></p>
<p>File sample:</p>
<pre><code>_OA ............. [6712227000168]
_OA Tasdsd, OA .. [91][355016]
_OA Tasdsd, DA .. [91][5512987000]
</code></pre>
<p>Expected:</p>
<pre><code>6712227000168
355016
5512987000
</code></pre>
<p>Hint for the regex match answers:
Thanks so much for all the answers, i found <a href="https://stackoverflow.com/questions/40736070/character-class-range-in-awk-version-3-1-7">link</a> that I need to use a <strong>--posix</strong> option because of my awk version.</p>
| [
{
"answer_id": 74314212,
"author": "Wiktor StribiΕΌew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 1,
"selected": false,
"text": "awk '/_OA/ { match($0,/\\[[[:digit:]]{4,13}]/);print substr($0,RSTART+1,RLENGTH-2)}'\n"
},
{
"answer_id": 74314214,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": false,
"text": "[[:digit:]]"
},
{
"answer_id": 74314474,
"author": "RavinderSingh13",
"author_id": 5866580,
"author_profile": "https://Stackoverflow.com/users/5866580",
"pm_score": 2,
"selected": false,
"text": "awk"
},
{
"answer_id": 74316486,
"author": "Ed Morton",
"author_id": 1745001,
"author_profile": "https://Stackoverflow.com/users/1745001",
"pm_score": 3,
"selected": true,
"text": "\\[\\([:digit:]{4,13}\\]"
},
{
"answer_id": 74317855,
"author": "glenn jackman",
"author_id": 7552,
"author_profile": "https://Stackoverflow.com/users/7552",
"pm_score": 2,
"selected": false,
"text": "grep -Eo '[[:digit:]]{4,13}'\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17165376/"
] |
74,314,203 | <p>I want to make a query like this:</p>
<pre><code>Student.objects.filter(id= id).update(name=value)
</code></pre>
<p>And the value comes from the user.</p>
<p>But the problem is that I'm not only to update name but also update some
other information like address or phone number. I don't want to create duplicated codes
like:</p>
<pre><code>Student.objects.filter(id= id).update(address=value)
Student.objects.filter(id= id).update(phone_number=value)
</code></pre>
<p>I only want to have one line code like:</p>
<pre><code>Student.objects.filter(id= id).update(XXX=XXX_value)
</code></pre>
<p>So I wonder if I can assign any variable to the left varaible inside update function
or not.</p>
<p>Sorry, the left key is not a certain value. It depends on the user's post.
It might be an address or just name next time. It's not a fixed value.</p>
<p>Thanks.</p>
| [
{
"answer_id": 74314212,
"author": "Wiktor StribiΕΌew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 1,
"selected": false,
"text": "awk '/_OA/ { match($0,/\\[[[:digit:]]{4,13}]/);print substr($0,RSTART+1,RLENGTH-2)}'\n"
},
{
"answer_id": 74314214,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": false,
"text": "[[:digit:]]"
},
{
"answer_id": 74314474,
"author": "RavinderSingh13",
"author_id": 5866580,
"author_profile": "https://Stackoverflow.com/users/5866580",
"pm_score": 2,
"selected": false,
"text": "awk"
},
{
"answer_id": 74316486,
"author": "Ed Morton",
"author_id": 1745001,
"author_profile": "https://Stackoverflow.com/users/1745001",
"pm_score": 3,
"selected": true,
"text": "\\[\\([:digit:]{4,13}\\]"
},
{
"answer_id": 74317855,
"author": "glenn jackman",
"author_id": 7552,
"author_profile": "https://Stackoverflow.com/users/7552",
"pm_score": 2,
"selected": false,
"text": "grep -Eo '[[:digit:]]{4,13}'\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1033591/"
] |
74,314,213 | <p>I need to use do-while loop for this.
My problem is that when I enter a positive number "5" the output should be 5 4 3 2 1 0 but instead, I get an output of 56543210
And if I enter a negative number "-5" the output should be -5 -4 3- -2 -1 0 but instead, I get an out put of -5-4-3-2-1010
Lastly, when I enter a number "0" the output should just be 0 ,but I get an output of 010</p>
<p>here is my code:</p>
<pre><code>#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
do {
printf("%d", n);
n++;
} while(n<=0);
do {
printf("%d", n);
n--;
} while(n>=0);
return 0;
}
</code></pre>
<p>I tried several ways but it didn't work. I also tried to incorporate switch case and if statement with do-while loop, but I keep on having errors.</p>
<p>Any advice will help. thanks!!
Sorry for grammatical errors and if my explanation is not clear.</p>
| [
{
"answer_id": 74314212,
"author": "Wiktor StribiΕΌew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 1,
"selected": false,
"text": "awk '/_OA/ { match($0,/\\[[[:digit:]]{4,13}]/);print substr($0,RSTART+1,RLENGTH-2)}'\n"
},
{
"answer_id": 74314214,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": false,
"text": "[[:digit:]]"
},
{
"answer_id": 74314474,
"author": "RavinderSingh13",
"author_id": 5866580,
"author_profile": "https://Stackoverflow.com/users/5866580",
"pm_score": 2,
"selected": false,
"text": "awk"
},
{
"answer_id": 74316486,
"author": "Ed Morton",
"author_id": 1745001,
"author_profile": "https://Stackoverflow.com/users/1745001",
"pm_score": 3,
"selected": true,
"text": "\\[\\([:digit:]{4,13}\\]"
},
{
"answer_id": 74317855,
"author": "glenn jackman",
"author_id": 7552,
"author_profile": "https://Stackoverflow.com/users/7552",
"pm_score": 2,
"selected": false,
"text": "grep -Eo '[[:digit:]]{4,13}'\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415475/"
] |
74,314,227 | <pre><code>int FibonacciArray(int n){
if(n<=2){
return 1;
}
else {
return FibonacciArray(n-1) + FibonacciArray(n-2);
}
}
</code></pre>
<p>Is there a function for counting recursive calls?</p>
| [
{
"answer_id": 74314535,
"author": "Aatif Shaikh",
"author_id": 12703411,
"author_profile": "https://Stackoverflow.com/users/12703411",
"pm_score": 2,
"selected": false,
"text": "int GlobalCount = 0 ;\nint FibonacciArray(int n)\n{\n static int LocalCounter = 0;\n LocalCounter++;\n GlobalCount++;\n if(n<=2)\n { \n return 1; \n }\n else \n {\n return FibonacciArray(n-1) + FibonacciArray(n-2);\n }\n}\n"
},
{
"answer_id": 74314699,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 1,
"selected": false,
"text": "0"
},
{
"answer_id": 74317439,
"author": "slago",
"author_id": 11535940,
"author_profile": "https://Stackoverflow.com/users/11535940",
"pm_score": 1,
"selected": false,
"text": "main()"
},
{
"answer_id": 74322066,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 0,
"selected": false,
"text": "x > 0"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415578/"
] |
74,314,233 | <p>Currently, my image is center within it's div, but when i make the browser smaller, the image won't move further left to keep center within it's div.</p>
<p><a href="https://i.stack.imgur.com/CQlwh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CQlwh.jpg" alt="enter image description here" /></a></p>
<p>HTML</p>
<pre><code><!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
<meta property="og:image" content="">
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="icon.png">
<link rel="stylesheet" href="https://development.beeldenfabriek.nl/woningzoeker/stylesheet.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css?version=3">
</head>
<body>
<section class="animation" id="Scene Section">
<div class="col-7 col-s-12">
<div class="deel1">
<div class="imgbox">
<img src="images/building_rotation/building_rotation_0014.png" class="img">
</div>
</div>
</div>
<div class="col-5 col-s-12">
<div class="deel2">
<div class="infobox">
</div>
<div class="planbox">
</div>
</div>
</div>
</section>
</body>
</html>
</code></pre>
<p>CSS</p>
<pre><code>/* COLUMN STRUCTURE */
[class*="col-"] {
width: 100%;
float: left;
text-align: center;
}
@media only screen and (min-width: 600px) {
.col-s-1 {width: 8.33%;}
.col-s-2 {width: 16.66%;}
.col-s-3 {width: 25%;}
.col-s-4 {width: 33.33%;}
.col-s-5 {width: 41.66%;}
.col-s-6 {width: 50%;}
.col-s-7 {width: 58.33%;}
.col-s-8 {width: 66.66%;}
.col-s-9 {width: 75%;}
.col-s-10 {width: 83.33%;}
.col-s-11 {width: 91.66%;}
.col-s-12 {width: 100%;}
}
@media only screen and (min-width: 768px) {
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}
* {
box-sizing: border-box;
margin: 0px;
padding: 0px;
}
html {
font-family: 'Arial';
}
.deel1 {
display: inline-block;
height: 100vh;
width: 100%;
}
.deel1 .imgbox {
height: 100vh;
width: 100%;
background-color: rgba(200, 200, 200, 1.0);
}
.deel1 .imgbox .img {
justify-content: center;
height: 100%;
}
.deel2 {
display: block;
height: 100vh;
}
.deel2 .infobox {
width: 100%;
height: 50vh;
background-color: rgba(230, 230, 230, 1.0);
}
.deel2 .planbox {
width: 100%;
height: 50vh;
background-color: rgba(240, 240, 240, 1.0);
}
</code></pre>
<p>I've tried to take the display: flex; approach and justify-content: center; but it still doesn't keep the image centered when the div gets smaller then the image width.</p>
| [
{
"answer_id": 74314535,
"author": "Aatif Shaikh",
"author_id": 12703411,
"author_profile": "https://Stackoverflow.com/users/12703411",
"pm_score": 2,
"selected": false,
"text": "int GlobalCount = 0 ;\nint FibonacciArray(int n)\n{\n static int LocalCounter = 0;\n LocalCounter++;\n GlobalCount++;\n if(n<=2)\n { \n return 1; \n }\n else \n {\n return FibonacciArray(n-1) + FibonacciArray(n-2);\n }\n}\n"
},
{
"answer_id": 74314699,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 1,
"selected": false,
"text": "0"
},
{
"answer_id": 74317439,
"author": "slago",
"author_id": 11535940,
"author_profile": "https://Stackoverflow.com/users/11535940",
"pm_score": 1,
"selected": false,
"text": "main()"
},
{
"answer_id": 74322066,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 0,
"selected": false,
"text": "x > 0"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15743242/"
] |
74,314,243 | <p>I'm again stuck with this hopefully simple task.</p>
<p>I have the following data frame:</p>
<pre><code>df <- data.frame(x1 = 1:3,
x2 = 2:4,
x3 = 3:5,
y1 = 1:3,
y2 = 2:4,
y3 = 3:5)
</code></pre>
<p>I now simply wanted to "loop" through each subscript and multiply the x* with the y* column, i.e. x1 * y1, x2 * y2 and so on and add these results to my data.</p>
<p>With these kind of tasks, I always think this should be easily doable with a <code>map</code> approach, but I don't get it to work, e.g.</p>
<pre><code>library(tidyverse)
df |>
map2(.x = _,
.y = 1:3,
.f = ~.x |>
mutate(!!sym(paste0(results, .y)) := !!sym(paste0(x, .y)) * !!sym(paste0(y, .y))))
</code></pre>
<p>doesn't work.</p>
<p>I also thought about using something with <code>across</code>, but that also doesn't work, because I can't tell across to "vectorize" over the x and y inputs.</p>
<p>Any ideas?</p>
| [
{
"answer_id": 74314535,
"author": "Aatif Shaikh",
"author_id": 12703411,
"author_profile": "https://Stackoverflow.com/users/12703411",
"pm_score": 2,
"selected": false,
"text": "int GlobalCount = 0 ;\nint FibonacciArray(int n)\n{\n static int LocalCounter = 0;\n LocalCounter++;\n GlobalCount++;\n if(n<=2)\n { \n return 1; \n }\n else \n {\n return FibonacciArray(n-1) + FibonacciArray(n-2);\n }\n}\n"
},
{
"answer_id": 74314699,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 1,
"selected": false,
"text": "0"
},
{
"answer_id": 74317439,
"author": "slago",
"author_id": 11535940,
"author_profile": "https://Stackoverflow.com/users/11535940",
"pm_score": 1,
"selected": false,
"text": "main()"
},
{
"answer_id": 74322066,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 0,
"selected": false,
"text": "x > 0"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2725773/"
] |
74,314,256 | <p>I am developing my first angular app and now when it has come to navigating on my page with routerLink, it does not work. It loads up with the welcome component, but when I click on a routerLink it sends me to a blank page.</p>
<pre class="lang-js prettyprint-override"><code>import { Component } from "@angular/core";
@Component({
selector: 'pm-root',
template: `<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand">{{pageTitle}}</a>
<ul class='nav nav-pills'>
<li><a class="nav-link" routerLink='/welcome' routerLinkActive="active">Home</a></li>
<li><a class="nav-link" routerLink='/products' routerLinkActive="active">Product list</a></li>
</ul>
</nav>
<div class="container">
<router-outlet></router-outlet>
</div>`
})
export class AppComponent {
pageTitle: string = 'Acme Project Mangement';
}
</code></pre>
<p>And my app.module.ts looks like this</p>
<pre><code>@NgModule({
declarations: [
AppComponent,
ProductList,
ConvertToSpacesPipe,
starComponent,
ProductDetailComponent,
WelcomeComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
RouterModule.forRoot([
{path: 'products', component: ProductListComponent},
{path: 'products/:id', component: ProductDetailComponent},
{path: 'welcome', component: WelcomeComponent},
{path: '', redirectTo: '/welcome', pathMatch: 'full'},
{path: '**', redirectTo: 'welcome', pathMatch: 'full'}
])
],
bootstrap: [AppComponent]
})
export class AppModule { }
</code></pre>
<p>I can not see any wrong with my code, and the compiler does not throw any error. Please help me so I can go on with angular.</p>
| [
{
"answer_id": 74314535,
"author": "Aatif Shaikh",
"author_id": 12703411,
"author_profile": "https://Stackoverflow.com/users/12703411",
"pm_score": 2,
"selected": false,
"text": "int GlobalCount = 0 ;\nint FibonacciArray(int n)\n{\n static int LocalCounter = 0;\n LocalCounter++;\n GlobalCount++;\n if(n<=2)\n { \n return 1; \n }\n else \n {\n return FibonacciArray(n-1) + FibonacciArray(n-2);\n }\n}\n"
},
{
"answer_id": 74314699,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 1,
"selected": false,
"text": "0"
},
{
"answer_id": 74317439,
"author": "slago",
"author_id": 11535940,
"author_profile": "https://Stackoverflow.com/users/11535940",
"pm_score": 1,
"selected": false,
"text": "main()"
},
{
"answer_id": 74322066,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 0,
"selected": false,
"text": "x > 0"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2631359/"
] |
74,314,294 | <p>I have folders deep inside lists that have well over 5K files in them that need to be split up and moved to archive
I am unable to use get-PnPFolderItem as it returns the dreaded 'The attempted operation is prohibited because it exceeds the list view threshold' error.</p>
<p>I should be able to use get-PnPListItem (with -pagesize) to get around this limit, but having a few issues.
As the folder is deep (6 levels) inside the root list get-PnPListItem returns the root list.</p>
<p>I tried the -FolderServerRelativeUrl switch, but it keeps returning 'The query.FolderServerRelativeUrl' argument is invalid</p>
<p>I tried creating a CAML Query to use, but that seems to be broken as it only returns the root folder for the list.</p>
<pre><code>$SiteUrl = "https://mytenant.sharepoint.com/Maintenance"
$listname = "workshop"
$ServerRelUrl = "Maintenance/workshop/level1/level2/level3/level4/level5/level6"
Connect-PnPOnline -URL $siteUrl -credentials $cred
get-pnpFolderItem $serverRelUrl # returns exceeded list view error
get-pnpListItem -list $listname -FolderServerRelativeUrl $ServerRelUrl # returns 'the query.FolderServerRelativeUrl argument is invalid
# please tell me what this should be?
$query="<View Scope='RecursiveAll'><RowLimit>5000</RowLimit></View>"
get-pnpListItem -list $listname -query $query # returns ALL files and folders under $listname, this is expected behaviour as it is paged and therefore does not exceed limit
# Workshop TK001 is part of the name of a file
$query='<view><Query><Where><Contains><FieldRef Name='FileDirRef'/><Value Type='Text'>'Workshop TK001'</Value></Contains></Where></Query></View>
get-pnpListItem -list $listname -query $query # returns nothing
$query="<Query> <Where> <Contains> <FieldRef Name='FileDirRef' /> <Value Type='File'>'workshop/level1/level2/level3/level4/level5'</Value> </Contains> </Where> </Query> <ViewFields /> <QueryOptions />"
get-pnpListItem -list $listname -query $query # returns the root folder of the list only
$query="<view Scope='RecursiveAll'><Query> <Where> <Contains> <FieldRef Name='FileDirRef' /> <Value Type='File'>'workshop/level1/level2/level3/level4/level5'</Value> </Contains> </Where> </Query> <ViewFields /> <QueryOptions /></view>"
get-pnpListItem -list $listname -query $query # returns the exceeds list view error
get-pnpListItem -list $listname -query $query -PageSize 2000 # returns the exceeds list view error
get-pnpListItem -list $listname -PageSize 2000 -query $query # returns the exceeds list view error
</code></pre>
<p>I would like to think that a CAML query would work, but it seems to be returning the root folder of the list instead of what it should be returning.</p>
<p>Some explanation of what I am missing, or reasons for its failure would be really appreciated.</p>
<p>A solution would be even better :)</p>
<p>I have tried the various methods listed and were expecting to have get-pnplistitem spit out a list for me to iterate through</p>
| [
{
"answer_id": 74314535,
"author": "Aatif Shaikh",
"author_id": 12703411,
"author_profile": "https://Stackoverflow.com/users/12703411",
"pm_score": 2,
"selected": false,
"text": "int GlobalCount = 0 ;\nint FibonacciArray(int n)\n{\n static int LocalCounter = 0;\n LocalCounter++;\n GlobalCount++;\n if(n<=2)\n { \n return 1; \n }\n else \n {\n return FibonacciArray(n-1) + FibonacciArray(n-2);\n }\n}\n"
},
{
"answer_id": 74314699,
"author": "Vlad from Moscow",
"author_id": 2877241,
"author_profile": "https://Stackoverflow.com/users/2877241",
"pm_score": 1,
"selected": false,
"text": "0"
},
{
"answer_id": 74317439,
"author": "slago",
"author_id": 11535940,
"author_profile": "https://Stackoverflow.com/users/11535940",
"pm_score": 1,
"selected": false,
"text": "main()"
},
{
"answer_id": 74322066,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 0,
"selected": false,
"text": "x > 0"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415279/"
] |
74,314,308 | <p>It is difficult to find the parent-branch in git ...</p>
<p>My current solution:</p>
<pre><code>git show-branch -a 2>/dev/null \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| perl -ple 's/\[[A-Za-z]+-\d+\][^\]]+$//; s/^.*\[([^~^\]]+).*$/$1/'
</code></pre>
<p>Source: <a href="https://stackoverflow.com/a/74314172/633961">https://stackoverflow.com/a/74314172/633961</a></p>
<p><strong>Why</strong> is it difficult to find the parent-branch in git?</p>
<p>This question is not about "how to solve this?". It is about "why is it not straight forward?"</p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/633961/"
] |
74,314,327 | <p>Let's say I have these types:</p>
<pre class="lang-js prettyprint-override"><code>interface A {
a: number
b: string
c: string
}
interface B {
a: string
b: string
}
type C = A | B
</code></pre>
<p>I want to get the possible values of the type <code>C</code>. For example</p>
<pre class="lang-js prettyprint-override"><code>type ValueOfObject<T, K> = What should be here?
type aValues = ValueOfObject<C, 'a'> // should return number | string
type bValue = ValueOfObject<C, 'b'> // should return string
type cValues = ValueOfObject<C, 'c'> //should return string | undefined
</code></pre>
<p>How can i achieve it?</p>
<p>I manage to get all the keys from union by</p>
<pre><code>type KeysOfUnion<T> = T extends T ? keyof T: never;
</code></pre>
<p>Cannot get the values though</p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5634526/"
] |
74,314,332 | <p>I need some help with sql.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Price1</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>01-09-2020</td>
<td>32</td>
</tr>
<tr>
<td>1</td>
<td>02-09-2020</td>
<td>343</td>
</tr>
<tr>
<td>2</td>
<td>03-09-2020</td>
<td>54543</td>
</tr>
<tr>
<td>2</td>
<td>03-09-2020</td>
<td>43232</td>
</tr>
<tr>
<td>2</td>
<td>05-09-2020</td>
<td>3232</td>
</tr>
<tr>
<td>2</td>
<td>05-09-2020</td>
<td>34323</td>
</tr>
<tr>
<td>3</td>
<td>06-09-2020</td>
<td>3234213</td>
</tr>
<tr>
<td>3</td>
<td>07-09-2020</td>
<td>3232213</td>
</tr>
</tbody>
</table>
</div>
<p>I have a table of this kind. I want to have difference in price based on dates. Like below</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>A.id</th>
<th>date 1</th>
<th>price 1</th>
<th>B.ID</th>
<th>date 2</th>
<th>price 2</th>
<th>diff</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>54543</td>
<td>2</td>
<td>05/09/2020</td>
<td>3232</td>
<td>-51311</td>
</tr>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>43232</td>
<td>2</td>
<td>05/09/2020</td>
<td>34323</td>
<td>-8909</td>
</tr>
</tbody>
</table>
</div>
<p>But I am getting is</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>A.id</th>
<th>date 1</th>
<th>price 1</th>
<th>B.ID</th>
<th>date 2</th>
<th>price 2</th>
<th>diff</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>54543</td>
<td>2</td>
<td>05/09/2020</td>
<td>3232</td>
<td>-51311</td>
</tr>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>54543</td>
<td>2</td>
<td>05/09/2020</td>
<td>34323</td>
<td>-20220</td>
</tr>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>43232</td>
<td>2</td>
<td>05/09/2020</td>
<td>3232</td>
<td>-40000</td>
</tr>
<tr>
<td>2</td>
<td>03/09/2020</td>
<td>43232</td>
<td>2</td>
<td>05/09/2020</td>
<td>34323</td>
<td>-8909</td>
</tr>
</tbody>
</table>
</div>
<p>i.e the price 1 column in repeating and taking difference for other values</p>
<pre class="lang-sql prettyprint-override"><code>Select a.id,a.date,a.price,b.id,b.date,b.price,(b.price-a.price)
from xyz a,xyz b -- same table
where a.id = 2
and a.id = b.id
and a.date = todate(03092020,'ddmmyyyy') and b.date = todate(05092020,'ddmmyyyy')
orderby a.id,a.date
</code></pre>
<p>This is the code I'm using. All I need is diff in corresponding values</p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13540991/"
] |
74,314,363 | <p>I have question regarding memory management in c++
In below example is there any memory leakage. If so how to clear memory.
Also defining int by * new is the only option to use and not int num = 25;</p>
<pre><code>int main()
{
for(int i = 0;i < 200;i++)
{
int num = * new int(25);
}
</code></pre>
<p>I tried many ways but delete and free does not work</p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415631/"
] |
74,314,369 | <p>I am trying to connect to a sql server with a different username/password combination than on my local account. I know it is valid credentials, since i am able to login through SSMS.</p>
<p>I've tried the following:</p>
<pre><code>connection_string = "DRIVER={SQL Server};SERVER=server;DATABASE=db;UID=username;PWD=password"
connection_url = URL.create("mssql", query={"odbc_connect": connection_string})
</code></pre>
<p>Where i get the login failed response:
<code>[SQL Server]Login failed for user 'username'. (18456) </code></p>
<p>I am trying to connect to a microsoft sql server (on the same network)</p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17637412/"
] |
74,314,399 | <p>Suppose I have a bunch of code, the format is like verilog <code>input/output (wire {signal_name}(,)</code>.</p>
<pre><code>input wire aaa,
input bbb, // "wire" can be omitted
input wire ccc // the comma can be omitted
input wire ddd_0,
output ddd_1
output wire ddd_1,
output wire EEE_E,
</code></pre>
<p>And I want to capture the signal name such as <code>aaa</code>, <code>bbb</code> ... <code>EEE_E</code>
My regex is:</p>
<pre><code>/\v(((input)|(output))[ ]+(wire)*[ ]*)@<=([_0-9a-zA-Z]+)
</code></pre>
<p>But it seems that <code>"wire"</code> itself also matchs this pattern and will be captured.<br />
I can use the <code>'\n'</code> '",\n"' to make sure no <code>"wire"</code> will be captured because there is never <code>'\n'</code> or '",\n"' behind <code>"wire"</code>. But is there any general method to filter out certain strings or certain patterns in vim regex?</p>
<pre><code>outcomes.filter_out("wire")
</code></pre>
<hr />
<p>Maybe I need a simpler example?
Suppose I have a bunch of "word" composed by <code>{'a'-'z', '0'-'9', '_', '$', '%'}</code></p>
<pre><code>11 apple pear banan0 wire _work m$oney && books wire word air 22
</code></pre>
<p>If I use<br />
<code>/\v(\s|^)@<=([a-z]*)\ze(\s|$)</code>,</p>
<p>I got all "pure" words:<br />
<code>apple pear wire books wire word air</code>.</p>
<p>But, what can I do if I don't want <code>wire</code> matched, only:<br />
<code>apple pear books word air</code></p>
| [
{
"answer_id": 74316598,
"author": "Adam",
"author_id": 1281548,
"author_profile": "https://Stackoverflow.com/users/1281548",
"pm_score": 2,
"selected": false,
"text": ".git/refs/heads/master"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20051585/"
] |
74,314,424 | <p>On my WooCommere shop, when my product is in backorder the Sales badge still shows up on my product. I would like to replace the Sales badge with the Out Of Stock label.</p>
<p>I have this code so far:</p>
<pre><code>add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 );
function new_badge() {
global $product;
if ( $product->is_on_backorder(1) ) {
echo '<span class="out-of-stock-badge" data-shape="type-3">' . esc_html__( 'Out Of Stock', 'woocommerce' ) . '</span>';
}
}
</code></pre>
<p>This code only add the span with the out-of-stock badge over the existing Sales badge, which provokes an overlap.</p>
<p>Is there a way to remove directly the Sales badge?</p>
| [
{
"answer_id": 74315040,
"author": "Vipin Singh",
"author_id": 14305064,
"author_profile": "https://Stackoverflow.com/users/14305064",
"pm_score": 0,
"selected": false,
"text": " echo '<span class=\"now_sold\">Now Sold</span>';\n"
},
{
"answer_id": 74315445,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 3,
"selected": true,
"text": "add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 ); \n\nfunction new_badge() {\n global $product;\n if ( $product->is_on_backorder(1) ) {\n add_filter('woocommerce_sale_flash', function (){return false;});\n echo '<span class=\"out-of-stock-badge\" data-shape=\"type-3\">' . esc_html__( 'Out Of Stock', 'woocommerce' ) . '</span>';\n }\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10957635/"
] |
74,314,428 | <p>I have 4 columns such as the ones below (but a total of 50,000 values not shown here):</p>
<pre><code>Date Speed Area Incidents
1/1/2016 6.5 Maly L
1/2/2016 7.7 Maly H
1/3/2016 14 Maly H
...
1/1/2017 5.5 Reet M
1/12/2017 9.8 Reet M
4/8/2017 3 Reet H
3/12/2017 5.8 Anlow L
</code></pre>
<p>I need to try and find the average speed recorded in all of 2017 in the area of Reet where the incidents were M.
So the output for this is supposed to be: <strong>7.65</strong>.</p>
<p>I have absolutely no idea what I'm missing, and so far I have tried using date_range() and set_index with .describe() for my average requirement but I couldn't get it right.</p>
| [
{
"answer_id": 74315040,
"author": "Vipin Singh",
"author_id": 14305064,
"author_profile": "https://Stackoverflow.com/users/14305064",
"pm_score": 0,
"selected": false,
"text": " echo '<span class=\"now_sold\">Now Sold</span>';\n"
},
{
"answer_id": 74315445,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 3,
"selected": true,
"text": "add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 ); \n\nfunction new_badge() {\n global $product;\n if ( $product->is_on_backorder(1) ) {\n add_filter('woocommerce_sale_flash', function (){return false;});\n echo '<span class=\"out-of-stock-badge\" data-shape=\"type-3\">' . esc_html__( 'Out Of Stock', 'woocommerce' ) . '</span>';\n }\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20413330/"
] |
74,314,457 | <p>I have some data in mongoDB and i want to group and sum it in object key - value:</p>
<pre><code>{
'_id': '1',
'value': {
A: 1,
B: 2,
C: 3
}
},
{
'_id': '2',
'value': {
B: 2,
C: 3
}
}
</code></pre>
<p>I need to group by keys name and sum the value of each key - that value. For the example above the result would be:</p>
<pre><code>{
'_id': 'A',
'total': 1
},
{
'_id': 'B',
'total': 4
},
{
'_id': 'C',
'total': 6
}
</code></pre>
| [
{
"answer_id": 74315040,
"author": "Vipin Singh",
"author_id": 14305064,
"author_profile": "https://Stackoverflow.com/users/14305064",
"pm_score": 0,
"selected": false,
"text": " echo '<span class=\"now_sold\">Now Sold</span>';\n"
},
{
"answer_id": 74315445,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 3,
"selected": true,
"text": "add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 ); \n\nfunction new_badge() {\n global $product;\n if ( $product->is_on_backorder(1) ) {\n add_filter('woocommerce_sale_flash', function (){return false;});\n echo '<span class=\"out-of-stock-badge\" data-shape=\"type-3\">' . esc_html__( 'Out Of Stock', 'woocommerce' ) . '</span>';\n }\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314457",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415611/"
] |
74,314,510 | <p>I am working on a Nodejs Express project and I keep getting 'Cannot GET /' error on Localhost. This is my server.js file</p>
<pre><code>console.clear();
const express = require("express");
const app = express();
const dbConnect = require("./config/dbConnect");
require("dotenv").config();
dbConnect();
app.use(express.json());
app.use("/api/user", require("./routes/user"));
app.use("/api/restaurant", require("./routes/restaurant"));
app.use("/api/item", require("./routes/item"));
app.use("/api/cart", require("./routes/cart"));
app.use("/api/order", require("./routes/order"));
const PORT = process.env.PORT;
app.listen(PORT, (err) =>
err
? console.error(err)
: console.log(` server is running on http://Localhost:${PORT}..`)
);
</code></pre>
<p>Can someone please tell me how to solve this?</p>
| [
{
"answer_id": 74315040,
"author": "Vipin Singh",
"author_id": 14305064,
"author_profile": "https://Stackoverflow.com/users/14305064",
"pm_score": 0,
"selected": false,
"text": " echo '<span class=\"now_sold\">Now Sold</span>';\n"
},
{
"answer_id": 74315445,
"author": "zillionera_dev",
"author_id": 15306153,
"author_profile": "https://Stackoverflow.com/users/15306153",
"pm_score": 3,
"selected": true,
"text": "add_action( 'woocommerce_before_shop_loop_item_title', 'new_badge', 3 ); \n\nfunction new_badge() {\n global $product;\n if ( $product->is_on_backorder(1) ) {\n add_filter('woocommerce_sale_flash', function (){return false;});\n echo '<span class=\"out-of-stock-badge\" data-shape=\"type-3\">' . esc_html__( 'Out Of Stock', 'woocommerce' ) . '</span>';\n }\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19801522/"
] |
74,314,513 | <p>is there a way to import a function from component in ReactJS Hooks?
Like, I have this component and function:</p>
<pre><code>export default const Test(){
const [state, setState] = useState(0);
function TestFnc(){
setState(20)
}
return(
<p>{state}</p>
)
}
</code></pre>
<p>And I wonder how can I use that function <code>TestFnc</code> inside of other component? like this:</p>
<pre><code>export default const Component(){
return(
<p onClick={()=> TestFnc()}>click me</p>
)
}
</code></pre>
<p>I know I could use class reactjs and export it to window DOM and use like this: <code>window.Test.TestFnc()</code> but with hooks is possible?</p>
<p>I tried custom Hooks but custom hooks didn't update the state
I've forgotten to mention, these components aren't related, they aren't parent and children.</p>
| [
{
"answer_id": 74314636,
"author": "ncpa0cpl",
"author_id": 8907391,
"author_profile": "https://Stackoverflow.com/users/8907391",
"pm_score": 1,
"selected": false,
"text": "const ChildComponent = (props) => {\n return <button onclick={() => props.fn()} />\n}\n\nconst ParentComponent = () => {\n const myFn = () => {};\n\n return <ChildComponent fn={myFn} />\n}\n\n"
},
{
"answer_id": 74372444,
"author": "VinΓcius Grippe",
"author_id": 20415758,
"author_profile": "https://Stackoverflow.com/users/20415758",
"pm_score": 1,
"selected": true,
"text": "useEffect(() => {\n window.resetSearch = resetSearch;\n}, []);\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415758/"
] |
74,314,546 | <p>This is a simple python language code, and I want to know the address of variable a:</p>
<pre class="lang-py prettyprint-override"><code>if __name__ == '__main__':
a = 2
print(a)
print(id(2))
print(id(a))
</code></pre>
<p>The output is:</p>
<pre><code>2
140704200824512
140704200824512
</code></pre>
<p>But I don't think the address of variable a is 140704200824512. I think 140704200824512 is the address of data 2.</p>
<p>As shown below, <strong>what is the value of the red question mark?</strong>
<a href="https://i.stack.imgur.com/6VXoI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6VXoI.png" alt="enter image description here" /></a></p>
<p><strong>Maybe the figure above is totally wrong</strong> because some documentation says the variables actually don't exist in python. They are just entries in namespace. But I still don't understand <strong>the internal principle.</strong></p>
<p>In C programming language, it is easy to understand the relationship between variable and data, but in python programming language, it is hard.</p>
<p>This is a simple C language code:</p>
<pre class="lang-c prettyprint-override"><code>#include <stdio.h>
int main(){
int a = 2;
printf("%d\n",a);
printf("%x\n",&a);
}
</code></pre>
<p>The output is:</p>
<pre><code>2
60fe1c
</code></pre>
<p>The relationship between variable a and data 2 is simple: <strong>a stores 2</strong>. Just as the following:
<a href="https://i.stack.imgur.com/mWMlG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mWMlG.png" alt="enter image description here" /></a></p>
<p>Can someone answer my question?</p>
| [
{
"answer_id": 74314625,
"author": "matszwecja",
"author_id": 9296093,
"author_profile": "https://Stackoverflow.com/users/9296093",
"pm_score": 1,
"selected": false,
"text": "id(a) == id(2)"
},
{
"answer_id": 74314902,
"author": "paime",
"author_id": 13636407,
"author_profile": "https://Stackoverflow.com/users/13636407",
"pm_score": 0,
"selected": false,
"text": "# Left value is if run in **script**\n# Right value is if run in **REPL** or **IPython**\n\na = 200\nb = 200\nprint(a is b) # True | True\n\na = 300\nb = 300\nprint(a is b) # True | *False*\n\na, b = 300, 300\nprint(a is b) # True | True\n\na = ((10, 20), (30, 40))\nb = ((10, 20), (30, 40))\nprint(a is b) # True | *False*\n\na, b = ((10, 20), (30, 40)), ((10, 20), (30, 40))\nprint(a is b) # True | True\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415573/"
] |
74,314,548 | <p>For my Lucene Queries I have some preconditions for security reasons.</p>
<pre><code>if isValid()
return build.parse query
else
return null
</code></pre>
<p>I want to replace this <strong><code>return null</code></strong>. I need something like "empty" query, a query thats will nothing do.</p>
<p>Is there a way to build it ?</p>
| [
{
"answer_id": 74316889,
"author": "andrewJames",
"author_id": 12567365,
"author_profile": "https://Stackoverflow.com/users/12567365",
"pm_score": 1,
"selected": false,
"text": "-"
},
{
"answer_id": 74352767,
"author": "Ben Borchard",
"author_id": 4054720,
"author_profile": "https://Stackoverflow.com/users/4054720",
"pm_score": 3,
"selected": true,
"text": "MatchNoDocsQuery"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314548",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3290745/"
] |
74,314,557 | <p>With Powershell 7.2 there seems to be a change in how a JSON is deserialized into an object in terms of dates -> instead of string it is now datetime. But I want to have the "old" behavior, i.e. that it is handled as string and NOT datetime.</p>
<p>How can I achieve that when using ConvertFrom-Json in Powershell 7.2 all dates are deserialized as string and not datetime?</p>
<p><strong>EDIT:</strong></p>
<pre><code>$val = '{ "date":"2022-09-30T07:04:23.571+00:00" }' | ConvertFrom-Json
$val.date.GetType().FullName
</code></pre>
| [
{
"answer_id": 74316212,
"author": "iRon",
"author_id": 1701026,
"author_profile": "https://Stackoverflow.com/users/1701026",
"pm_score": 3,
"selected": true,
"text": "#13598"
},
{
"answer_id": 74318647,
"author": "quervernetzt",
"author_id": 7009990,
"author_profile": "https://Stackoverflow.com/users/7009990",
"pm_score": 0,
"selected": false,
"text": "ConvertFrom-Json"
},
{
"answer_id": 74319203,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 2,
"selected": false,
"text": "powershell.exe"
},
{
"answer_id": 74352656,
"author": "iRon",
"author_id": 1701026,
"author_profile": "https://Stackoverflow.com/users/1701026",
"pm_score": 0,
"selected": false,
"text": "Get-Node"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7009990/"
] |
74,314,573 | <p>TypeScript treats errors as <code>unknown</code> which is fair but leads me to writing what I think is ugly code. For example, to handle a particular error that I know has a <code>"code"</code> attribute (but I don't know the class so can't use <code>instanceOf</code>), I have to write this:</p>
<pre class="lang-js prettyprint-override"><code>} catch (err) {
if (
typeof err === "object" &&
err !== null &&
"code" in err &&
(err as { code: unknown }).code === "<some value>"
) {
console.log("Special case for this particular situation")
}
throw err;
}
</code></pre>
<p>I find this ugly, too much code, and I still have to do a cast. It's tempting now to cast <code>err</code> to <code>any</code> instead but I wanna do proper TypeScript.</p>
<p>What's a nicer way to do this?</p>
| [
{
"answer_id": 74314631,
"author": "Clashsoft",
"author_id": 4138801,
"author_profile": "https://Stackoverflow.com/users/4138801",
"pm_score": 1,
"selected": false,
"text": "code"
},
{
"answer_id": 74314638,
"author": "Nullndr",
"author_id": 10503039,
"author_profile": "https://Stackoverflow.com/users/10503039",
"pm_score": 0,
"selected": false,
"text": "instanceof"
},
{
"answer_id": 74314879,
"author": "T.J. Crowder",
"author_id": 157247,
"author_profile": "https://Stackoverflow.com/users/157247",
"pm_score": 2,
"selected": false,
"text": "err"
},
{
"answer_id": 74314880,
"author": "nate-kumar",
"author_id": 9987590,
"author_profile": "https://Stackoverflow.com/users/9987590",
"pm_score": 0,
"selected": false,
"text": "as"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1376848/"
] |
74,314,576 | <p>I have been struggling to create a new column based on the values of certain rows and columns in another dataframe. I have a data frame that looks like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>sample_ID</th>
<th>date</th>
<th>test_result</th>
</tr>
</thead>
<tbody>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>positive</td>
</tr>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample2</td>
<td>2/1/2022</td>
<td>positive</td>
</tr>
<tr>
<td>sample2</td>
<td>3/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample3</td>
<td>4/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample3</td>
<td>5/1/2022</td>
<td>positive</td>
</tr>
<tr>
<td>sample4</td>
<td>5/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample4</td>
<td>6/1/2022</td>
<td>negative</td>
</tr>
<tr>
<td>sample4</td>
<td>7/1/2022</td>
<td>negative</td>
</tr>
</tbody>
</table>
</div>
<p>I want to create a new column with a decision of the final result of each sample ID. If sample is positive at any date, the final result will be the test result of the earliest date of positivity, otherwise the sample is negative. The results should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>sample_ID</th>
<th>date</th>
<th>test_result</th>
<th>final_result</th>
</tr>
</thead>
<tbody>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>positive</td>
<td>positive</td>
</tr>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>negative</td>
<td>positive</td>
</tr>
<tr>
<td>sample1</td>
<td>1/1/2022</td>
<td>negative</td>
<td>positive</td>
</tr>
<tr>
<td>sample2</td>
<td>2/1/2022</td>
<td>positive</td>
<td>positive</td>
</tr>
<tr>
<td>sample2</td>
<td>3/1/2022</td>
<td>negative</td>
<td>positive</td>
</tr>
<tr>
<td>sample3</td>
<td>4/1/2022</td>
<td>negative</td>
<td>positive</td>
</tr>
<tr>
<td>sample3</td>
<td>5/1/2022</td>
<td>positive</td>
<td>positive</td>
</tr>
<tr>
<td>sample4</td>
<td>5/1/2022</td>
<td>negative</td>
<td>negative</td>
</tr>
<tr>
<td>sample4</td>
<td>6/1/2022</td>
<td>negative</td>
<td>negative</td>
</tr>
<tr>
<td>sample4</td>
<td>7/1/2022</td>
<td>negative</td>
<td>negative</td>
</tr>
</tbody>
</table>
</div>
<p>I did try with ifelse and loop but it was not successful.
I would appreciate any help. Thank you very much.</p>
| [
{
"answer_id": 74314631,
"author": "Clashsoft",
"author_id": 4138801,
"author_profile": "https://Stackoverflow.com/users/4138801",
"pm_score": 1,
"selected": false,
"text": "code"
},
{
"answer_id": 74314638,
"author": "Nullndr",
"author_id": 10503039,
"author_profile": "https://Stackoverflow.com/users/10503039",
"pm_score": 0,
"selected": false,
"text": "instanceof"
},
{
"answer_id": 74314879,
"author": "T.J. Crowder",
"author_id": 157247,
"author_profile": "https://Stackoverflow.com/users/157247",
"pm_score": 2,
"selected": false,
"text": "err"
},
{
"answer_id": 74314880,
"author": "nate-kumar",
"author_id": 9987590,
"author_profile": "https://Stackoverflow.com/users/9987590",
"pm_score": 0,
"selected": false,
"text": "as"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415510/"
] |
74,314,605 | <p>I am trying to write a function that will take a target number, and a matrix as its parameter, and will return the 'co-ordinates' of the target number. If the target number doesn't exist, (-1, -1) will be returned.</p>
<p>It is assumed there will only be <strong>one</strong> occurrence of the target number.</p>
<p>Example matrix:</p>
<pre><code>my_matrix = [
[1, 4, 7, 12, 15, 1000],
[2, 5, 19, 31, 32, 1001],
[3, 8, 24, 33, 35, 1002],
[40, 41, 42, 44, 45, 1003],
[99, 100, 103, 106, 128, 1004]
]
</code></pre>
<p>example input/output:</p>
<p>target_number = 19
output = (1, 2)</p>
<p>Firstly I wrote the function to our put the indices of the col/row position:</p>
<pre><code>def find_target(target, matrix):
for i, row in enumerate(matrix):
for j, col in enumerate(row):
if col == target:
return i, j
</code></pre>
<p>This will output 'None' is the number doesn't exists, so I then tried to implement if/else, then tried try/except to outout (-1, -1) if the number doesn't exists however my attempts at implementing this seem to override the above, and output (-1, -1) even if the number exists.</p>
<p>My attempts:</p>
<pre><code>def find_target(target, matrix):
for i, row in enumerate(matrix):
for j, col in enumerate(row):
try:
if col == target:
return i, j
else:
raise ValueError
except ValueError:
return -1, -1
</code></pre>
<pre><code>def find_target(target, matrix):
for i, row in enumerate(matrix):
for j, col in enumerate(row):
if col == target:
return i, j
else:
return -1, -1
</code></pre>
<pre><code>def find_target(target, matrix):
try:
for i, row in enumerate(matrix):
for j, col in enumerate(row):
if col == target:
return i, j
except:
return -1, -1
</code></pre>
<p>None of the above seem to give the desired output, they will either output(-1, -1) regardless of input, or will output 'None' if the number doesn't exist. I'm going to keep trying to understand why this is ongoing, but any pointers would be appreciated.</p>
<p>Also, please note I am quite new to this; I appreciate feedback, and I always make a point of trying various methods/ implementations etc before coming here to ask! :)</p>
| [
{
"answer_id": 74314739,
"author": "Swifty",
"author_id": 20267366,
"author_profile": "https://Stackoverflow.com/users/20267366",
"pm_score": 3,
"selected": true,
"text": "def find_target(target, matrix):\n for i, row in enumerate(matrix):\n for j, col in enumerate(row):\n if col == target:\n return i, j\n return -1,-1\n"
},
{
"answer_id": 74314798,
"author": "Mehmaam",
"author_id": 19350100,
"author_profile": "https://Stackoverflow.com/users/19350100",
"pm_score": 1,
"selected": false,
"text": "def find_target(target, matrix):\n for i, row in enumerate(matrix):\n for j, col in enumerate(row):\n if col == target:\n return i, j\n else:\n return -1, -1\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20370719/"
] |
74,314,683 | <p>But I'm twisting it slightly, where I don't have a layout but rather a per page component that I'd like to add to the header.</p>
<p>I am getting the following error:
<a href="https://i.stack.imgur.com/G7NOp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G7NOp.png" alt="enter image description here" /></a></p>
<p><strong>Account.jsx</strong> looks something like this:</p>
<pre><code>import { useRecoilValue } from "recoil";
import { userProfile } from "../../../recoil";
export default function Account() {
const profile = useRecoilValue(userProfile);
return (
<div className="w-screen h-full ">
<header>
<Navbar profile={dataMe} />
</header>
<main className="h-screen relative">
<div className='h-screen flex bg-gray-bg my-15 static'>
<div className='w-full mt-10 m-auto bg-white rounded-lg border'>
<div>
<div>
<dataMe />
</div>
<DetailAccount />
</div>
</div>
</div>
</main>
</div >
);
};
</code></pre>
| [
{
"answer_id": 74314806,
"author": "MarioG8",
"author_id": 13705979,
"author_profile": "https://Stackoverflow.com/users/13705979",
"pm_score": 1,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74314813,
"author": "node_modules",
"author_id": 6060964,
"author_profile": "https://Stackoverflow.com/users/6060964",
"pm_score": 0,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74315066,
"author": "talent-jsdev",
"author_id": 15087608,
"author_profile": "https://Stackoverflow.com/users/15087608",
"pm_score": -1,
"selected": false,
"text": "import React from 'react';\nimport { RecoilRoot } from 'recoil';\nimport Account from './Account.jsx';\n\nfunction App() {\n return (\n <RecoilRoot>\n <Account />\n </RecoilRoot>\n );\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19592889/"
] |
74,314,684 | <p>Hej!</p>
<p>My automatized script is running through many month. I'd like to have the monthly plots to show always the window [1:31], actually YYYY-MM-01 to YYYY-MM-31. For all month my script is handling. (And I don't care that some month have no data at the ends, e.g., February.)</p>
<p>Unfortunately, I don't know how to provide the range to gnuplot correctly. Since data is time, sth like [1:31] doesn't work of course. But neither can I explicitly state the full date in my script since next month will be different again.</p>
<p>Any ideas?
Thanks!</p>
<p>EDIT: I edited the original post to include some more information. Sorry for not including it right away.</p>
<ul>
<li>DATA: My data basically looks like this (with many more lines in between). I have a separate datafile per month, starting on the 1st, 0 AM, towards the 31st, 12 PM:</li>
</ul>
<pre><code>2022-07-01,00:00:16,27.3,3,28.0,9.0,995.6
2022-07-01,00:05:16,27.3,3,28.0,9.0,995.5
2022-07-01,00:10:16,27.3,3,28.0,9.0,995.4
2022-07-01,00:15:16,27.3,3,28.0,9.0,995.3
2022-07-01,00:20:16,27.3,3,28.0,9.0,995.3
2022-07-01,00:25:16,27.3,3,28.0,9.0,995.3
...
2022-07-31,23:54:16,27.1,3,27.9,12.1,994.9
2022-07-31,23:55:16,27.1,3,27.9,12.1,994.9
2022-07-31,23:56:16,27.1,3,27.9,12.1,995.1
2022-07-31,23:57:16,27.1,3,27.9,11.9,995.0
2022-07-31,23:58:16,27.1,3,27.9,11.9,995.0
</code></pre>
<ul>
<li><p>EXAMPLE IMAGE: An example (for the month of July) is attached. As I'm not allowed to have embedded images, see the link:
<a href="https://i.stack.imgur.com/Nmc46.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nmc46.png" alt="Example plot for July" /></a></p>
</li>
<li><p>CODE EXAMPLE: The following code is used to modify the x-axis. A very basic attempt (set xrange ["01":"31"]) is included to set the range between 1 and 31. But since xdata is not integers, this is a failed attempt of course.</p>
</li>
</ul>
<pre><code>set xdata time
set timefmt '%Y-%m-%d,%H:%M:%S'
set format x "%d"
#set xrange ["01":"31"]
set xtics 21600*4*7
set mxtics 7
set grid xtics
set grid mxtics
</code></pre>
<p>Of course, the xdata changes from month to month. But I'd like to have the day of the month only, not the full date. And, like I said, fixed to 1-31 for easier comparison between months.</p>
| [
{
"answer_id": 74314806,
"author": "MarioG8",
"author_id": 13705979,
"author_profile": "https://Stackoverflow.com/users/13705979",
"pm_score": 1,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74314813,
"author": "node_modules",
"author_id": 6060964,
"author_profile": "https://Stackoverflow.com/users/6060964",
"pm_score": 0,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74315066,
"author": "talent-jsdev",
"author_id": 15087608,
"author_profile": "https://Stackoverflow.com/users/15087608",
"pm_score": -1,
"selected": false,
"text": "import React from 'react';\nimport { RecoilRoot } from 'recoil';\nimport Account from './Account.jsx';\n\nfunction App() {\n return (\n <RecoilRoot>\n <Account />\n </RecoilRoot>\n );\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415812/"
] |
74,314,696 | <p>This is a follow-up question from <a href="https://stackoverflow.com/questions/74309067/extract-data-in-subfields-of-multiple-xml-files?noredirect=1#comment131191194_74309067">here</a>. it got lost due to high amount of other topic on this forum. Maybe i presented the question too complicated. Since then I improved and simplified the approach.
To sum up: i'd like to extract data from subfields in multiple XML files and attach those to a new df on a matching positions.</p>
<p>This is a sample XML-1:</p>
<pre><code><?xml version="1.0" encoding="utf-8" standalone="no"?>
<reiXmlPrenos>
<Qfl>1808</Qfl>
<fOVE>13.7</fOVE>
<NetoVolumen>613</NetoVolumen>
<Hv>104.2</Hv>
<energenti>
<energent>
<sifra>energy_e</sifra>
<naziv>EE [kWh]</naziv>
<vrednost>238981</vrednost>
</energent>
<energent>
<sifra>energy_to</sifra>
<naziv>Do</naziv>
<vrednost>16359</vrednost>
</energent>
<rei>
<zavetrovanost>2</zavetrovanost>
<cone>
<cona>
<cona_id>1</cona_id>
<cc_si_cona>1110000</cc_si_cona>
<visina_cone>2.7</visina_cone>
<dolzina_cone>14</dolzina_cone>
</cona>
<cona>
<cona_id>2</cona_id>
<cc_si_cona>120000</cc_si_cona>
</cona>
</rei>
</reiXmlPrenos>
</code></pre>
<p>his is a sample XML-2:</p>
<pre><code><?xml version="1.0" encoding="utf-8" standalone="no"?>
<reiXmlPrenos>
<Qfl>1808</Qfl>
<fOVE>13.7</fOVE>
<NetoVolumen>613</NetoVolumen>
<Hv>104.2</Hv>
<energenti>
<energent>
<sifra>energy_e</sifra>
<naziv>EE [kWh]</naziv>
<vrednost>424242</vrednost>
</energent>
<energent>
<sifra>energy_en</sifra>
<naziv>Do</naziv>
<vrednost>29</vrednost>
</energent>
<rei>
<zavetrovanost>2</zavetrovanost>
<cone>
<cona>
<cona_id>1</cona_id>
<cc_si_cona>1110000</cc_si_cona>
<visina_cone>2.7</visina_cone>
<dolzina_cone>14</dolzina_cone>
</cona>
<cona>
<cona_id>2</cona_id>
<cc_si_cona>120000</cc_si_cona>
</cona>
</rei>
</reiXmlPrenos>
</code></pre>
<p>My code:</p>
<pre><code>import xml.etree.ElementTree as ETree
import pandas as pd
xmldata = r"C:\...\S1.xml"
prstree = ETree.parse(xmldata)
root = prstree.getroot()
# print(root)
store_items = []
all_items = []
for storeno in root.iter('energent'):
cona_sifra = storeno.find('sifra').text
cona_vrednost = storeno.find('vrednost').text
store_items = [cona_sifra, cona_vrednost]
all_items.append(store_items)
xmlToDf = pd.DataFrame(all_items, columns=[
'sifra', 'vrednost'])
print(xmlToDf.to_string(index=False))
</code></pre>
<p>This results in:</p>
<pre><code> sifra vrednost
energy_e 238981
energy_to 16359
</code></pre>
<p>Which is fine for 1 example. But i have 1,000 of XML files and the wish is to 1) have all results in 1 row for each XML and 2) to differentiate between different 'sifra' codes.</p>
<p>There can be e.g. <code>energy_e, energy_en, energy_to</code></p>
<p>So ideally the final df would look like this</p>
<pre><code>xml energy_e energy_en energy_to
xml-1 238981 0 16539
xml-2 424242 29 0
</code></pre>
<p>can it be done?</p>
| [
{
"answer_id": 74314806,
"author": "MarioG8",
"author_id": 13705979,
"author_profile": "https://Stackoverflow.com/users/13705979",
"pm_score": 1,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74314813,
"author": "node_modules",
"author_id": 6060964,
"author_profile": "https://Stackoverflow.com/users/6060964",
"pm_score": 0,
"selected": false,
"text": "RecoilRoot"
},
{
"answer_id": 74315066,
"author": "talent-jsdev",
"author_id": 15087608,
"author_profile": "https://Stackoverflow.com/users/15087608",
"pm_score": -1,
"selected": false,
"text": "import React from 'react';\nimport { RecoilRoot } from 'recoil';\nimport Account from './Account.jsx';\n\nfunction App() {\n return (\n <RecoilRoot>\n <Account />\n </RecoilRoot>\n );\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3579151/"
] |
74,314,700 | <p>I have one spark DF1 with datatype,</p>
<pre><code>string (nullable = true)
integer (nullable = true)
timestamp (nullable = true)
</code></pre>
<p>And one more spark DF2 (which I created from Pandas DF)</p>
<pre><code>object
int64
object
</code></pre>
<p>Now I need to change the DF2 datatype to match with the Df1 datatype. Is there any common way to do that. Because every time I may get different columns and different datatypes.
Is there any way like assign the DF1 data type to some structType and use that for DF2?</p>
| [
{
"answer_id": 74314947,
"author": "Jonathan Lam",
"author_id": 10445333,
"author_profile": "https://Stackoverflow.com/users/10445333",
"pm_score": 0,
"selected": false,
"text": " df2 = spark.createDataFrame(\n df2.rdd, schema=df1.schema\n )\n"
},
{
"answer_id": 74315285,
"author": "samkart",
"author_id": 8279585,
"author_profile": "https://Stackoverflow.com/users/8279585",
"pm_score": 2,
"selected": true,
"text": "data1_sdf"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18962965/"
] |
74,314,745 | <p>I have a table that has columns Name, Series and Season.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Name</th>
<th>series</th>
<th>season</th>
</tr>
</thead>
<tbody>
<tr>
<td>abc</td>
<td>alpha</td>
<td>s1</td>
</tr>
<tr>
<td>abc</td>
<td>alpha</td>
<td>s2</td>
</tr>
<tr>
<td>pqr</td>
<td>alpha</td>
<td>s1</td>
</tr>
<tr>
<td>xyz</td>
<td>beta</td>
<td>s2</td>
</tr>
<tr>
<td>xyz</td>
<td>gamma</td>
<td>s3</td>
</tr>
<tr>
<td>abc</td>
<td>theta</td>
<td>s1</td>
</tr>
</tbody>
</table>
</div>
<p>I am trying to extract the number of people who have watched only the series 'alpha', and not any other series.
How to get this count?</p>
<p>On giving the "where series='alpha' " condition, I get the counts of people who watched alpha, but not the counts of those who watched <em>only alpha</em> eg: abc has watched alpha as well as theta, but pqr has watched only alpha.</p>
| [
{
"answer_id": 74314964,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 0,
"selected": false,
"text": "NOT EXISTS"
},
{
"answer_id": 74315036,
"author": "kuriboh",
"author_id": 14485623,
"author_profile": "https://Stackoverflow.com/users/14485623",
"pm_score": 0,
"selected": false,
"text": "SELECT COUNT(DISTINCT name)\nFROM t \nWHERE name NOT IN (\n SELECT DISTINCT name\n FROM t\n WHERE series<>'alpha'\n) AND series='alpha'\n"
},
{
"answer_id": 74315099,
"author": "Ergest Basha",
"author_id": 16461952,
"author_profile": "https://Stackoverflow.com/users/16461952",
"pm_score": 1,
"selected": false,
"text": "select count(yt.name) as only_alpha\nfrom yourtable yt\ninner join ( select name \n from yourtable\n group by name\n having count(distinct series) = 1\n ) yt1 on yt.name=yt1.name\nwhere yt.series='alpha';\n"
},
{
"answer_id": 74315663,
"author": "andexte",
"author_id": 8380724,
"author_profile": "https://Stackoverflow.com/users/8380724",
"pm_score": 0,
"selected": false,
"text": "COUNT()"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415890/"
] |
74,314,783 | <p>I want to make a query that searches the table for names of cities and that the result will be names of cities that start with the letter b and then names of cities that contain the letter b.</p>
<pre><code>select *
from tb_city
where name like 'b%' or name like '%b%'
</code></pre>
<p>How can I first get the cities that start with the letter b and then the cities that contain the letter b?
The result I get is mixed</p>
| [
{
"answer_id": 74314964,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 0,
"selected": false,
"text": "NOT EXISTS"
},
{
"answer_id": 74315036,
"author": "kuriboh",
"author_id": 14485623,
"author_profile": "https://Stackoverflow.com/users/14485623",
"pm_score": 0,
"selected": false,
"text": "SELECT COUNT(DISTINCT name)\nFROM t \nWHERE name NOT IN (\n SELECT DISTINCT name\n FROM t\n WHERE series<>'alpha'\n) AND series='alpha'\n"
},
{
"answer_id": 74315099,
"author": "Ergest Basha",
"author_id": 16461952,
"author_profile": "https://Stackoverflow.com/users/16461952",
"pm_score": 1,
"selected": false,
"text": "select count(yt.name) as only_alpha\nfrom yourtable yt\ninner join ( select name \n from yourtable\n group by name\n having count(distinct series) = 1\n ) yt1 on yt.name=yt1.name\nwhere yt.series='alpha';\n"
},
{
"answer_id": 74315663,
"author": "andexte",
"author_id": 8380724,
"author_profile": "https://Stackoverflow.com/users/8380724",
"pm_score": 0,
"selected": false,
"text": "COUNT()"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13231407/"
] |
74,314,808 | <p>Here is the table data</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">id</th>
<th style="text-align: center;">time</th>
<th style="text-align: right;">amount</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">1</td>
<td style="text-align: center;">20221104</td>
<td style="text-align: right;">15</td>
</tr>
<tr>
<td style="text-align: left;">2</td>
<td style="text-align: center;">20221104</td>
<td style="text-align: right;">10</td>
</tr>
<tr>
<td style="text-align: left;">3</td>
<td style="text-align: center;">20221105</td>
<td style="text-align: right;">7</td>
</tr>
<tr>
<td style="text-align: left;">4</td>
<td style="text-align: center;">20221105</td>
<td style="text-align: right;">19</td>
</tr>
<tr>
<td style="text-align: left;">5</td>
<td style="text-align: center;">20221106</td>
<td style="text-align: right;">10</td>
</tr>
</tbody>
</table>
</div>
<p>The id and time field is asc, but time can be same.</p>
<p>The rows are very large, so we don't want to use page limit offset method, but with cursor id.</p>
<p>first query:</p>
<p><code>select * from t where time > xxx and time < yyy order by id asc limit 10;</code></p>
<p>get the biggest id zzz, then</p>
<p>next query:</p>
<p><code>select * from t where time > xxx and time < yyy and id > zzz order by id asc limit 10;</code></p>
<p>How should I build the index?
If I use id as index, the time range will cause huge scan if time is far away.
And If I use time as index, seek id will not be effective.</p>
| [
{
"answer_id": 74314964,
"author": "Jonas Metzler",
"author_id": 18794826,
"author_profile": "https://Stackoverflow.com/users/18794826",
"pm_score": 0,
"selected": false,
"text": "NOT EXISTS"
},
{
"answer_id": 74315036,
"author": "kuriboh",
"author_id": 14485623,
"author_profile": "https://Stackoverflow.com/users/14485623",
"pm_score": 0,
"selected": false,
"text": "SELECT COUNT(DISTINCT name)\nFROM t \nWHERE name NOT IN (\n SELECT DISTINCT name\n FROM t\n WHERE series<>'alpha'\n) AND series='alpha'\n"
},
{
"answer_id": 74315099,
"author": "Ergest Basha",
"author_id": 16461952,
"author_profile": "https://Stackoverflow.com/users/16461952",
"pm_score": 1,
"selected": false,
"text": "select count(yt.name) as only_alpha\nfrom yourtable yt\ninner join ( select name \n from yourtable\n group by name\n having count(distinct series) = 1\n ) yt1 on yt.name=yt1.name\nwhere yt.series='alpha';\n"
},
{
"answer_id": 74315663,
"author": "andexte",
"author_id": 8380724,
"author_profile": "https://Stackoverflow.com/users/8380724",
"pm_score": 0,
"selected": false,
"text": "COUNT()"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5383686/"
] |
74,314,858 | <p>I'm having a hard time finding a solution for this and I don't even know if it's possible...</p>
<p>I'm developing a small app where I have 5 types of items with different stats, 7 levels (some have only 3 levels), and I would like to find all the items stats combinaisons.</p>
<p>Ex:</p>
<ul>
<li>Item 1 lvl 1, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>Item 1 lvl 2, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>Item 1 lvl 3, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>Item 1 lvl 4, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>....</li>
<li>Item 7 lvl 7, Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>Item 7 lvl 7, Item 1 lvl 2 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>Item 7 lvl 7, Item 1 lvl 3 + Item 1 lvl 1 + Item 1 lvl 1 + Item 1 lvl 1</li>
<li>...</li>
</ul>
<p>So it will generate around 1 934 917 632 possibilities.</p>
<p>What should be the best approach to do this?</p>
<p>Is it ok to store those values into a Mysql Database?</p>
<p>Is there any way to optimize this? Do the calculation live with a lot of filters to reduce the possible combinaisons?</p>
<p>I already try <a href="https://stackoverflow.com/questions/30512570/how-to-get-all-combinations-from-multiple-arrays">How to get all combinations from multiple arrays?</a> it works fine, but I only test with 40 possibilities, I'am more concerned about the Database part...</p>
<p><strong>EDIT:</strong>
Each combinaison will give an amount of token, the tool would be used to find the combinaison that give more token than a previous combinaison. β</p>
<p>Thank you guys!</p>
| [
{
"answer_id": 74317809,
"author": "lzl",
"author_id": 20312513,
"author_profile": "https://Stackoverflow.com/users/20312513",
"pm_score": -1,
"selected": false,
"text": "public static void main(String[] args) {\n int[] arr = {1, 2, 3, 4, 5};\n int n = arr.length;\n int r = 3;\n int[] data = new int[r];\n combinationUtil(arr, data, 0, n - 1, 0, r);\n}\n\nstatic void combinationUtil(int[] arr, int[] data, int start, int end, int index, int r) {\n if (index == r) {\n for (int j = 0; j < r; j++) {\n System.out.print(data[j] + \" \");\n }\n System.out.println(\"\");\n return;\n }\n for (int i = start; i <= end && end - i + 1 >= r - index; i++) {\n data[index] = arr[i];\n combinationUtil(arr, data, i + 1, end, index + 1, r);\n }\n}\n"
},
{
"answer_id": 74331675,
"author": "Rick James",
"author_id": 1766831,
"author_profile": "https://Stackoverflow.com/users/1766831",
"pm_score": 0,
"selected": false,
"text": "TINYINT UNSIGNED"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11097001/"
] |
74,314,865 | <p>I need to pass optional, runtime parameter to a command in Docker.</p>
<p>The idea is that if PARAM env variable is set when docker is being run - it should be passed to java command as <code>--key VALUE</code> , and when runtime parameter is not set - it shoulddn't pass anything - in particular it shouldn't pass <code>--key</code> parameter name.</p>
<p>I.e. it should run following command if <code>PARAM</code> env variable is set:
<code>/bin/java -jar artifact.jar --key $PARAM</code></p>
<p>And following if it's not:
<code>/bin/java -jar artifact.jar</code></p>
<p>I wanted to use <code>:+</code> syntax, but it's resolved during build time, which means it won't be affected by runtime env variable.</p>
<pre><code>docker build -t test-abc . && docker run -e "PARAM=oooo" test-abc
</code></pre>
<pre><code>FROM openjdk:17
ENV PARAM=${PARAM:+"--key $PARAM"}
ENTRYPOINT /bin/java -jar artifact.jar $PARAM
</code></pre>
| [
{
"answer_id": 74317809,
"author": "lzl",
"author_id": 20312513,
"author_profile": "https://Stackoverflow.com/users/20312513",
"pm_score": -1,
"selected": false,
"text": "public static void main(String[] args) {\n int[] arr = {1, 2, 3, 4, 5};\n int n = arr.length;\n int r = 3;\n int[] data = new int[r];\n combinationUtil(arr, data, 0, n - 1, 0, r);\n}\n\nstatic void combinationUtil(int[] arr, int[] data, int start, int end, int index, int r) {\n if (index == r) {\n for (int j = 0; j < r; j++) {\n System.out.print(data[j] + \" \");\n }\n System.out.println(\"\");\n return;\n }\n for (int i = start; i <= end && end - i + 1 >= r - index; i++) {\n data[index] = arr[i];\n combinationUtil(arr, data, i + 1, end, index + 1, r);\n }\n}\n"
},
{
"answer_id": 74331675,
"author": "Rick James",
"author_id": 1766831,
"author_profile": "https://Stackoverflow.com/users/1766831",
"pm_score": 0,
"selected": false,
"text": "TINYINT UNSIGNED"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17062755/"
] |
74,314,868 | <p>Are this "*" mean anything like "." or ".." when we define path? I am not getting what those means. Why can't I specify the path in the <strong>usual way</strong>? I wanted to use paths like "../../XYZ" or something like that. But where is this asterisk coming from and what does it mean? Can I define the path in tailwind without using the asterisk?</p>
<p>If anyone can help I would be most glad. I am new to tailwind CSS so a little bit confused. Thank you.</p>
| [
{
"answer_id": 74317809,
"author": "lzl",
"author_id": 20312513,
"author_profile": "https://Stackoverflow.com/users/20312513",
"pm_score": -1,
"selected": false,
"text": "public static void main(String[] args) {\n int[] arr = {1, 2, 3, 4, 5};\n int n = arr.length;\n int r = 3;\n int[] data = new int[r];\n combinationUtil(arr, data, 0, n - 1, 0, r);\n}\n\nstatic void combinationUtil(int[] arr, int[] data, int start, int end, int index, int r) {\n if (index == r) {\n for (int j = 0; j < r; j++) {\n System.out.print(data[j] + \" \");\n }\n System.out.println(\"\");\n return;\n }\n for (int i = start; i <= end && end - i + 1 >= r - index; i++) {\n data[index] = arr[i];\n combinationUtil(arr, data, i + 1, end, index + 1, r);\n }\n}\n"
},
{
"answer_id": 74331675,
"author": "Rick James",
"author_id": 1766831,
"author_profile": "https://Stackoverflow.com/users/1766831",
"pm_score": 0,
"selected": false,
"text": "TINYINT UNSIGNED"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15721461/"
] |
74,314,893 | <p>english is not my first language, so sorry for my bad writting.</p>
<p>i need to optimize an Algorithm, which is written with Python and running on a Raspberry Pi. The clue is, that i need to write the optimized Code as a C-Programm running on a stm32f4.</p>
<p>It is a image-processing algorithm (i know, image-processing with C on a Microcontroller sounds fun ...) and the functionality muss stay the same (so same output with tolerance). Ofcourse i need a method of benchmarking the two programms.</p>
<p>In my case "Optimization" means that the programm should run faster (which it automatically will be, but i need to show that it is faster because of optimized Code and not because it is written in C and running on a bare-metal system).</p>
<p>i know that for examaple i can compare the number of Code lines, because the less lines the faster is the programm. is there more "factors", which are system independend and i can compare to explain why the optimized Code is faster?</p>
<p>kind regards,
Dan</p>
<p>PS: i thought about converting the Python code in C code with cython. Than i can compile it and compare the assembly or machine Code. But i am not sure if it is the right way, because i dont know what exactly cython is doing.</p>
| [
{
"answer_id": 74321406,
"author": "old_timer",
"author_id": 16007,
"author_profile": "https://Stackoverflow.com/users/16007",
"pm_score": 0,
"selected": false,
"text": "void more_fun ( unsigned int );\nvoid fun ( void )\n{\n more_fun(0x12345678);\n}\n\n00000000 <fun>:\n 0: 4801 ldr r0, [pc, #4] ; (8 <fun+0x8>)\n 2: f7ff bffe b.w 0 <more_fun>\n 6: bf00 nop\n 8: 12345678 .word 0x12345678\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415867/"
] |
74,314,906 | <p>I have rails application which is using sidekiq for background jobs. Recently upgraded ruby from 2.7.0 to 3.1.2 and respectively redis gem automatically updated to '5.0.5'. After this sidekiq(6.4.1) logs throws below error, if i revert to old redis version (4.6.0) in my gemlock, there is no error. Any idea what is the reason for this?</p>
<p>Error message:
<a href="https://i.stack.imgur.com/FSNEE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FSNEE.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74356180,
"author": "pmv",
"author_id": 13631843,
"author_profile": "https://Stackoverflow.com/users/13631843",
"pm_score": 4,
"selected": true,
"text": "FalseClass"
},
{
"answer_id": 74574896,
"author": "slhck",
"author_id": 435093,
"author_profile": "https://Stackoverflow.com/users/435093",
"pm_score": 0,
"selected": false,
"text": "sidekiq-unique-jobs"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17683683/"
] |
74,314,910 | <p>I'm setting my first steps in dependency injection related programming in an <code>EntityFramework</code> environment, and I have following <code>Exception</code>:</p>
<p><code>Database</code> is of the type <code>Microsoft.EntityFrameworkCore.DatabaseFacade</code>.</p>
<p>The <code>Database.EnsureCreated();</code> line gives following exception:</p>
<blockquote>
<p>System.InvalidOperationException:
'No suitable constructor was found for entity type 'Element'.
The following constructors had parameters that could not be bound to properties of the entity type:
cannot bind 'ipAddress', 'strategy', 'bufferSize' in 'Element(string name, IPAddress ipAddress, short port, IStrategy strategy, short bufferSize)';
cannot bind 'ipAddress' in 'Element(IPAddress ipAddress, short port)'.'</p>
</blockquote>
<p>Apparently <code>name</code> and <code>port</code> are well handled, but not the others. I've been looking into the constructors and the database related configuration, but I don't see how <code>name</code> and <code>port</code> seem to be treated better than the others. Does anybody have an idea?</p>
<p>The properties look as follows:</p>
<pre><code>public Guid Id { get; private set; }
public string Name { get; private set; }
public ElementStatus Status { get; private set; }
public IPAddress Ip { get; }
public short Port { get; }
public short BufferSize { get; }
public IStrategy Strategy { get; }
...
</code></pre>
<p>The constructors look as follows:</p>
<pre><code>public Element(string name, IPAddress ipAddress, short port, IStrategy Strategy, short bufferSize = 8192)
{
if (string.IsNullOrEmpty(ipAddress.ToString()))
throw new ArgumentException("Invalid IP address");
this.Name = name;
this.Ip = ipAddress;
this.Port = port;
BufferSize = bufferSize;
Strategy = Strategy;
}
public Element(IPAddress ipAddress, short port)
{
this.Ip = ipAddress;
this.Port = port;
}
</code></pre>
<p>The database configuration looks as follows:</p>
<pre><code>public class Configurations :
IEntityTypeConfiguration<Element>
{
public void Configure(EntityTypeBuilder<Element> builder)
{
builder.Property(o => o.Id).ValueGeneratedOnAdd();
builder.Property(o => o.Name).IsRequired();
builder.HasIndex(o => o.Name).IsUnique();
builder.Property(o => o.Ip).IsRequired();
builder.Property(o => o.Port).IsRequired();
builder.Property(o => o.Status).IsRequired();
builder.HasIndex("Ip", "Port").IsUnique();
}
}
</code></pre>
| [
{
"answer_id": 74315027,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 0,
"selected": false,
"text": "ipAddress"
},
{
"answer_id": 74315617,
"author": "LtObelix",
"author_id": 1926868,
"author_profile": "https://Stackoverflow.com/users/1926868",
"pm_score": 1,
"selected": false,
"text": "public Element(IPAddress ipAddress, short port)\n{\n this.Ip = ipAddress;\n this.Port = port;\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4279155/"
] |
74,314,911 | <p>I created these two components:</p>
<p><a href="https://i.stack.imgur.com/fSNqa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fSNqa.png" alt="enter image description here" /></a></p>
<p>After using ng serve i can see only one component in source of the chrome browser:</p>
<p><a href="https://i.stack.imgur.com/VzdDS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VzdDS.png" alt="enter image description here" /></a></p>
<p>How can i debug the standalone component? Breakpoints also can not be hitted with vs code with this config:</p>
<pre><code>{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200/"
},
</code></pre>
<p><strong>Update: using the supported node version for Angular Cli solves this problem!</strong></p>
<p><a href="https://i.stack.imgur.com/QpCRH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QpCRH.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74315027,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 0,
"selected": false,
"text": "ipAddress"
},
{
"answer_id": 74315617,
"author": "LtObelix",
"author_id": 1926868,
"author_profile": "https://Stackoverflow.com/users/1926868",
"pm_score": 1,
"selected": false,
"text": "public Element(IPAddress ipAddress, short port)\n{\n this.Ip = ipAddress;\n this.Port = port;\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2572885/"
] |
74,314,915 | <p>I created a tool in Excel that will extract emails from a particular mailbox.</p>
<pre class="lang-vb prettyprint-override"><code>Sub GetFromOutlook()
Dim OutlookApp as Outlook.Application
Dim OutlookNameSpace As Namespace
Dim Folder as MAPIfolder
Dim OutlookMail As Variant
Dim objowner As Variant
Dim i as Integer
Set OutlookApp = New Outlook.Application
Set OutlookNameSpace = OutlookApp. GetNamespace("MAPI")
Set objowner = OutlookNameSpace.CreateRecipient("abc@email.com")
Objowner.Resolve
If objowner.Resolved then
Set Folder = OutlookNameSpace.GetSharedDefaultFolder(objowner, olFolderInbox)
End if
Dim strDateFilter As String:
StrDateFilter = "[ReceivedTime] >= '" & Format(Range("Date").Value, "dddd h:nn AMPM") & "'"
Dim Items As Object: Set Items = Folder.Items.Restrict(strDateFilter)
i = 1
For each OutlookMail in Items
Range("eMail_subject").offset(i,0).Value = OutlookMail.Subject
Range("eMail_date").offset(i,0).Value = OutlookMail.ReceivedTime
Range("eMail_Sender").offset(i,0).Value = OutlookMail.SenderName
Range("eMail_text").offset(i,0).Value = OutlookMail.Body
i = i + i
Set Folder = Nothing
Set OutlookNameSpace = Nothing
Set OutlookApp = Nothing
End Sub
</code></pre>
<p>I need to extract emails from four more shared mailboxes (other than abc@email.com).</p>
<ol>
<li>def@email.com</li>
<li>Ghi@email.com</li>
<li>Jkl@email.com</li>
<li>Mnop@email.com</li>
</ol>
<p>I tried to insert the following lines.</p>
<pre><code>Dim Folder2 as MAPIfolder
Dim Folder3 as MAPIfolder
Dim Folder4 as MAPIfolder
Dim Folder5 as MAPIfolder
Dim objownwr2 as Variant
Dim objownwr3 as Variant
Dim objownwr4 as Variant
Dim objownwr5 as Variant
Set objowner2 = OutlookNameSpace.CreateRecipient("def@email.com")
Objowner2.Resolve '(and so on for all the other shared mailbox)
If objowner2.Resolved then
Set Folder = OutlookNameSpace.GetSharedDefaultFolder(objowner2, olFolderInbox)
End if
</code></pre>
<p>And so on. It only gets the emails from abc@email.com.</p>
| [
{
"answer_id": 74315027,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 0,
"selected": false,
"text": "ipAddress"
},
{
"answer_id": 74315617,
"author": "LtObelix",
"author_id": 1926868,
"author_profile": "https://Stackoverflow.com/users/1926868",
"pm_score": 1,
"selected": false,
"text": "public Element(IPAddress ipAddress, short port)\n{\n this.Ip = ipAddress;\n this.Port = port;\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11013637/"
] |
74,314,930 | <p>There is no <code>simd_packed_float3</code> type in Swift.</p>
<p>Why it's a problem?</p>
<p>Consider this Metal struct:</p>
<pre><code>struct Test{
packed_float3 x;
float y;
};
</code></pre>
<p>First of all, you can't calculate a buffer pointer to address the memory of <code>y</code>, since you can't do this:</p>
<pre><code>MemoryLayout<simd_packed_float3>.size
</code></pre>
<p>(Not sure if <code>stride</code> makes sense with packed types, but anyway with simd types it always gives the same length as size on my devices)</p>
<p>You can't use <code>MemoryLayout<simd_float3>.size</code> either, since it will return 16 and not 12 like in architectures available to me for testing.</p>
<p>Second, if you need to write a packed_float3 value of <code>x</code> to the buffer you will need to write the three consecutive floats, but not a single simd type. Again, simd_float3 is not usable since it will write 0 into the forth word corrupting the memory of the next property in the struct (<code>y</code>).</p>
<p>So I've done this:</p>
<pre><code>struct Float_3{
var x: Float
var y: Float
var z: Float
}
typealias simd_packed_float3 = Float_3
</code></pre>
<p>It seems to be a functioning solution, but I'm not sure it's not a nasty thing to do...
What problems may I encounter with this approach, and how could I be sure that it won't break on some device that I don't have?</p>
| [
{
"answer_id": 74315027,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 0,
"selected": false,
"text": "ipAddress"
},
{
"answer_id": 74315617,
"author": "LtObelix",
"author_id": 1926868,
"author_profile": "https://Stackoverflow.com/users/1926868",
"pm_score": 1,
"selected": false,
"text": "public Element(IPAddress ipAddress, short port)\n{\n this.Ip = ipAddress;\n this.Port = port;\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16896928/"
] |
74,314,932 | <p>I get a regular non-root logger of the default type:</p>
<pre><code>logger = logging.getLogger('a')
</code></pre>
<p>Now I want to change the type and get a new logger for the same name:</p>
<pre><code>logging.setLoggerClass(type('NewLoggerClass', (logging.Logger,), {}))
logger = logging.getLogger('a')
</code></pre>
<p>I would like the second call to <code>getLogger</code> to respect the new logger class I set. However, <code>logger</code> remains the same instance of <code>logging.Logger</code> instead of <code>__main__.NewLoggerClass</code>.</p>
<p>How do I either remove an existing logger for a given name, or replace it with one of a different type?</p>
| [
{
"answer_id": 74315027,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 0,
"selected": false,
"text": "ipAddress"
},
{
"answer_id": 74315617,
"author": "LtObelix",
"author_id": 1926868,
"author_profile": "https://Stackoverflow.com/users/1926868",
"pm_score": 1,
"selected": false,
"text": "public Element(IPAddress ipAddress, short port)\n{\n this.Ip = ipAddress;\n this.Port = port;\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2988730/"
] |
74,314,984 | <p>I wanna make a price alert bot. It's just for the fun btw I dΔ±n't have any purpose about it but also I wanna run certain code every n minutes. Anyway the most import thing is I am gettin the bellow error rightnow I hope you guys can guide me and help me about run certain code every n min. Thank you for ur info.</p>
<pre><code>from discord.ext import commands
import requests
import discord
import asyncio
intents = discord.Intents.all()
bot = commands.Bot(command_prefix= "?", intents=intents)
@bot.command()
async def foo(ctx, arg):
await ctx.send(arg)
@bot.command()
async def on_ready():
print("bot online")
@bot.command()
async def on_message(message):
if message.author == bot.id:
return
if message.content == "ana":
await message.channel.send("baban")
@bot.commands()
async def start_count(ctx):
key = "some-crypto-shit-api"
data = requests.get(key)
data = data.json()
price = data["price"]
coin = data["symbol"]
await ctx.send(price)
bot.add_command(start_count)
bot.run('my_Token')
</code></pre>
<p>And this is my error =</p>
<pre><code>Traceback (most recent call last):
File "c:\Users\usr\btc takip\yenibot.py", line 17, in <module>
async def on_ready():
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 1475, in decorator
result = command(name=name, cls=cls, *args, **kwargs)(func)
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 1748, in decorator
return cls(func, name=name, **attrs)
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 361, in __init__
self.callback = func
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 470, in callback
self.params: Dict[str, Parameter] = get_signature_parameters(function, globalns)
File "C:\Users\usr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 128, in get_signature_parameters
raise TypeError(f'Command signature requires at least {required_params - 1} parameter(s)')
TypeError: Command signature requires at least 0 parameter(s)
</code></pre>
| [
{
"answer_id": 74315423,
"author": "Annoymous",
"author_id": 14698023,
"author_profile": "https://Stackoverflow.com/users/14698023",
"pm_score": -1,
"selected": false,
"text": "@bot.command(name=\"MY_COMMAND_NAME\")\n"
},
{
"answer_id": 74323631,
"author": "stijndcl",
"author_id": 13568999,
"author_profile": "https://Stackoverflow.com/users/13568999",
"pm_score": 2,
"selected": true,
"text": "@bot.commands()"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18472400/"
] |
74,314,985 | <p>I've created a script that should read a file, then find out wether the first line has a vowel in the first word/line, and if it does, it should output only the first 10 words in the list.
If not the first 15. My issue is that the script instead of showing the first 10 lines when I input a file that starts with a vowel, it shows me the first 15 wether it's starts with a vowel or not.</p>
<p>My script is as following:</p>
<p>first reads file, then puts the first word in a variable to then be checked if it starts with a vowel, then outputs into another file.</p>
<pre><code>#!/bin/bash
cat file.txt | word=$(head -1 file.txt)
if [[ "$word" == '^[AaEeIiOoUu]' ]]
then head -10 file.txt > words.txt
else head -15 file.txt > words.txt
fi
</code></pre>
<p>The then statement is not acknowledged by my script, unsure why.</p>
<p>f.ex input file: file.txt
island
bus
carriage
train
tractor</p>
<p>I have tried changing the == in the 2 line to be =~.
I have tried removing, the else head -15 to see if I get the first 10 lines. Also spellcheck, and jdoodle shows no errors</p>
| [
{
"answer_id": 74315074,
"author": "choroba",
"author_id": 1030675,
"author_profile": "https://Stackoverflow.com/users/1030675",
"pm_score": 2,
"selected": false,
"text": "# cat file.txt | word=$(head -1 file.txt)\nword=$(head -1 file.txt)\n"
},
{
"answer_id": 74315120,
"author": "tripleee",
"author_id": 874188,
"author_profile": "https://Stackoverflow.com/users/874188",
"pm_score": 1,
"selected": false,
"text": "#!/bin/bash\n\n# avoid doubly useless cat\nword=$(head -1 file.txt)\n\n# fix regex operator and regex\nif [[ \"$word\" =~ [AaEeIiOoUu] ]]\nthen head -10 file.txt > words.txt\nelse head -15 file.txt > words.txt \nfi \n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74314985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400773/"
] |
74,315,005 | <p>I'm trying to write json data from a third-party site on a flater, but I've already tried different options. I get the same problem on the last step.
Please help me very much.</p>
<p>i have this model</p>
<pre><code>class SkinModel {
String src;
String name;
double minprice;
int count;
double avgprice;
double medianprice;
int popularity;
SkinModel(
{required this.src,
required this.name,
required this.minprice,
required this.count,
required this.avgprice,
required this.medianprice,
required this.popularity});
factory SkinModel.fromJson(Map<String, dynamic> json) {
return SkinModel(
src: json['src'],
name: json['name'],
minprice: json['minprice'],
count: json['count'],
avgprice: json['avgprice'],
medianprice: json['medianprice'],
popularity: json['popularity'],
);
}
}
</code></pre>
<p>and such a class for receiving and processing data</p>
<pre><code>import 'dart:convert';
import 'package:flutter_application_1/data_skins.dart';
import 'package:flutter_application_1/model/model_skin.dart';
import 'package:http/http.dart' as http;
class Skins {
Future<dynamic>? getSkinsPopular(String game, String? method) async {
late List<SkinModel> skinListModel = [];
if (method == null) {
skinListModel = skinssamplelist;
}
String url = 'https://market.dota2.net/api/v2/prices/USD.json';
print('Step 1 ' + url);
http.Response response = await http.get(
Uri.parse(url),
);
print('Step 2 ' + response.reasonPhrase!);
if (response.statusCode == 200) {
var decodeData = json.decode(response.body);
var rest = decodeData['items'] as List;
print('Step 3');
print(rest);
skinListModel =
rest.map<SkinModel>((json) => SkinModel.fromJson(json)).toList();
print('Step 4');
print(skinListModel);
} else {
throw 'Problem with get request';
}
return skinListModel;
}
}
}
</code></pre>
<p>But the last successful step 3 and after the debugger writes flutter: Sorry try again
I absolutely do not understand what the error is and what I did wrong</p>
| [
{
"answer_id": 74315282,
"author": "Ramil Rakhmatullin",
"author_id": 12030753,
"author_profile": "https://Stackoverflow.com/users/12030753",
"pm_score": 0,
"selected": false,
"text": "market_hash_name: String,\nvolume: String,\nprice: String,\n"
},
{
"answer_id": 74315465,
"author": "Sachin Kumawat",
"author_id": 11830339,
"author_profile": "https://Stackoverflow.com/users/11830339",
"pm_score": 3,
"selected": true,
"text": " late List<SkinModel> skinListModel = [];\n String url = 'https://market.dota2.net/api/v2/prices/USD.json';\n print('Step 1 ' + url);\n\n http.Response response = await http.get(\n Uri.parse(url),\n );\n print('Step 2 ' + response.reasonPhrase!);\n if (response.statusCode == 200) {\n var decodeData = jsonDecode(response.body);\n var rest = decodeData['items'] as List;\n print('Step 3');\n print(rest);\n for (var element in rest) {skinListModel.add(SkinModel.fromJson(element)); } //replace this line\n print('Step 4');\n print(skinListModel);\n\n } else {\n throw 'Problem with get request';\n }\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5942436/"
] |
74,315,011 | <p>Need to Merge the second row values with the first row of column C if the rows in columns A&B are null.</p>
<p>DATA:</p>
<pre><code> A B C
12525 1FWE23 1H654D
14654
24798 14654 S56E82
65116 63546 38945
46456 46485 R68R45
AD545
A5D66 45346 QA6683
</code></pre>
<p>EXPECTED:</p>
<pre><code> A B C
12525 1FWE23 1H654D 14654
24798 14654 S56E82
65116 63546 38945
46456 46485 R68R45 AD545
A5D66 45346 QA6683
</code></pre>
| [
{
"answer_id": 74315191,
"author": "DSteman",
"author_id": 11383969,
"author_profile": "https://Stackoverflow.com/users/11383969",
"pm_score": 1,
"selected": false,
"text": "df[\"C\"] = df[\"C\"] + df[\"C\"].shift(-1).fillna(\"\")\n"
},
{
"answer_id": 74315606,
"author": "Pravin",
"author_id": 19580067,
"author_profile": "https://Stackoverflow.com/users/19580067",
"pm_score": 1,
"selected": true,
"text": "df2.loc[df2['A'] != '', 'C'] = df2[\"C\"] + ' ' + df2[\"C\"].shift(-1).fillna(\"\")\n\ndf2[df2[\"A\"] != '']\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19580067/"
] |
74,315,035 | <p>I have created below workflow expecting github to ask the manual input and then run the rest of steps. However I don't see any button <code>run workflow</code> <a href="https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/" rel="nofollow noreferrer">such-as-this</a>. The workflow shows "null" value in the "print steps" of my workflow.(see attached the screenprint)</p>
<p>Does anyone knows what is wrong and why it's not prompting me any inputs?</p>
<pre><code>name: Input Workflow
on:
workflow_dispatch:
inputs:
myInput:
description: 'User Input:'
required: true
default: "Hello World"
push:
branches:
- feature/*
jobs:
run-python-test:
runs-on: ubuntu-latest
steps:
- name: Execute Test Script
run: |
echo "Store: ${{ github.event.inputs.myInput }}"
# INPUT_STORE=${{ github.event.inputs.myInput }} python3 input.py
</code></pre>
<p><a href="https://i.stack.imgur.com/Gs3EH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gs3EH.png" alt="outcome-workflow" /></a></p>
| [
{
"answer_id": 74315191,
"author": "DSteman",
"author_id": 11383969,
"author_profile": "https://Stackoverflow.com/users/11383969",
"pm_score": 1,
"selected": false,
"text": "df[\"C\"] = df[\"C\"] + df[\"C\"].shift(-1).fillna(\"\")\n"
},
{
"answer_id": 74315606,
"author": "Pravin",
"author_id": 19580067,
"author_profile": "https://Stackoverflow.com/users/19580067",
"pm_score": 1,
"selected": true,
"text": "df2.loc[df2['A'] != '', 'C'] = df2[\"C\"] + ' ' + df2[\"C\"].shift(-1).fillna(\"\")\n\ndf2[df2[\"A\"] != '']\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8406398/"
] |
74,315,039 | <p>Here I am trying to fetch all the data from the api using flutter http package. I am getting an error</p>
<p>"type 'int' is not a subtype of type 'String?'"</p>
<p>Here is the link where I am trying to fetch data from</p>
<pre><code>https://wrestlingworld.co/wp-json/wp/v2/posts/128354
</code></pre>
<p>Here is my model</p>
<pre><code>class NewsModel {
int? id;
String? date;
String? slug;
String? status;
Title? title;
Title? content;
List<OgImage>? ogImage;
String? author;
NewsModel(
{this.id,
this.date,
this.slug,
this.status,
this.title,
this.content,
this.ogImage,
this.author});
NewsModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
date = json['date'];
slug = json['slug'];
status = json['status'];
title = json['title'] != null ? new Title.fromJson(json['title']) : null;
content =
json['content'] != null ? new Title.fromJson(json['content']) : null;
if (json['og_image'] != null) {
ogImage = <OgImage>[];
json['og_image'].forEach((v) {
ogImage!.add(new OgImage.fromJson(v));
});
}
author = json['author'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['date'] = this.date;
data['slug'] = this.slug;
data['status'] = this.status;
if (this.title != null) {
data['title'] = this.title!.toJson();
}
if (this.content != null) {
data['content'] = this.content!.toJson();
}
if (this.ogImage != null) {
data['og_image'] = this.ogImage!.map((v) => v.toJson()).toList();
}
data['author'] = this.author;
return data;
}
}
class Title {
String? rendered;
Title({this.rendered});
Title.fromJson(Map<String, dynamic> json) {
rendered = json['rendered'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['rendered'] = this.rendered;
return data;
}
}
class OgImage {
String? url;
OgImage({this.url});
OgImage.fromJson(Map<String, dynamic> json) {
url = json['url'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['url'] = this.url;
return data;
}
}
</code></pre>
<p>Here is my controller</p>
<pre><code>import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:wrestling_news_app/Model/NewsModel.dart';
import 'package:http/http.dart' as http;
class NewsController with ChangeNotifier{
String urlnews = "https://wrestlingworld.co/wp-json/wp/v2/posts?categories=22";
List<NewsModel> _news = [];
Future<bool> getNews() async {
var url = Uri.parse(urlnews);
// var token = storage.getItem('token');
try {
http.Response response = await http.get(url);
print(response.body);
var data = json.decode(response.body) as List;
// print(data);
List<NewsModel> temp = [];
data.forEach((element) {
NewsModel product = NewsModel.fromJson(element);
temp.add(product);
});
_news = temp;
notifyListeners();
return true;
} catch (e) {
print(e);
return false;
}
}
List<NewsModel> get allNews {
return [..._news];
}
NewsModel getEventDetails(int id){
return _news.firstWhere((element) => element.id == id);
}
}
</code></pre>
<p>Here is the code where I tried to output the code:</p>
<pre><code> Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
physics: const ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: allNews.length,
itemBuilder: (context, i) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: NewsCard(
title: allNews[i].title!.rendered!,
desciption: allNews[i].content!.rendered!,
),
);
}),)
</code></pre>
<p>Previously I tried to fetch using FuturreBuilder. But With future builder I couldnt fetch the details. for that reason I am using this method to fetch data from the api. Can you please answer me what is wrong with my code?</p>
<p>Here is my api response</p>
<pre><code>[{"id":128640,"date":"2022-11-04T15:09:58","date_gmt":"2022-11-04T09:39:58","guid":{"rendered":"https:\/\/wrestlingworld.co\/?p=128640"},"modified":"2022-11-04T15:10:04","modified_gmt":"2022-11-04T09:40:04","slug":"impact-knockouts-tag-team-championship-match-announced-for-over-drive-2022","status":"publish","type":"post","link":"https:\/\/wrestlingworld.co\/news\/impact-knockouts-tag-team-championship-match-announced-for-over-drive-2022","title":{"rendered":"Impact Knockouts Tag Team Championship Match Announced for Over Drive"},"content":{"rendered":"\n<p>Impact Knockouts Tag Team Championships will be on the line at Over Drive on November 18th. It has <a href=\"https:\/\/impactwrestling.com\/2022\/11\/03\/tasha-steelz-savannah-evans-look-to-topple-the-death-dollz-in-knockouts-world-tag-team-title-showdown-at-over-drive\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">been announced<\/a> that Death Dollz (Taya Valkyrie and Jessicka) will be defending their titles against Tasha Steelz and Savannah
I/flutter (12372): type 'int' is not a subtype of type 'String?'
</code></pre>
| [
{
"answer_id": 74315226,
"author": "ThanhNguyen",
"author_id": 16992231,
"author_profile": "https://Stackoverflow.com/users/16992231",
"pm_score": 4,
"selected": true,
"text": "String? author"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315039",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19890273/"
] |
74,315,084 | <p>I'm working with an API and after I try to clean up the data, I got an array of arrays of arrays:</p>
<pre><code>arr = [[[{name: "john"}],[{name: "jack"}]],[[{name: "joe"}],[{name: "bob"}]]]
</code></pre>
<p>How can I clean this up to something like this:</p>
<pre><code>arr = [{name: "john"},{name: "jack"},{name: "joe"},{name: "bob"}]
</code></pre>
| [
{
"answer_id": 74315102,
"author": "Some random IT boy",
"author_id": 9248718,
"author_profile": "https://Stackoverflow.com/users/9248718",
"pm_score": 0,
"selected": false,
"text": "arr.flat().flat()"
},
{
"answer_id": 74315112,
"author": "jsejcksn",
"author_id": 438273,
"author_profile": "https://Stackoverflow.com/users/438273",
"pm_score": 2,
"selected": false,
"text": "Array.prototype.flat()"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13812691/"
] |
74,315,115 | <p>I am stuck at a problem.</p>
<p>I need to upload a file (a CSV file) to a server by using Delphi. The server have certain requirements that must be followed :</p>
<blockquote>
<ul>
<li>The request must be an HTTP PUT request.</li>
<li>Must contain the Client ID in the URL request, like this : <code>example.com/upload/{Client ID}</code> (<code>{Client ID}</code> would be replaced).</li>
<li>Must contain the future file name that will be received also in the URL after the client ID, like this : <code>example.com/upload/{Client ID}/{Future File Name}</code> (<code>{Future File Name}</code> would be replaced), which can be different from your local file name.</li>
<li>The API Key must be in the request header (header name: <code>x-api-key</code>). Example : <code>lXViWTzFic9sM8qe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr</code>.</li>
</ul>
</blockquote>
<p>I could do this in CURL, like this example : (Client ID : <code>d32krpq</code>, and Future file name : <code>20181023_update.csv</code>)</p>
<pre class="lang-none prettyprint-override"><code>curl -v -X PUT https://example.com/upload/d32krpq/20181023_update.csv --upload-file 20181023_update.csv --header "x-api-key: lXViWTzFic9sM8qe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr"
</code></pre>
<p>How to achieve this using Delphi components (using either <code>TNetHttpClient</code> or <code>TRESTClient</code>)?</p>
| [
{
"answer_id": 74315197,
"author": "Softacom",
"author_id": 15611794,
"author_profile": "https://Stackoverflow.com/users/15611794",
"pm_score": 2,
"selected": true,
"text": "PUT"
},
{
"answer_id": 74320508,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "TIdHTTP"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7183251/"
] |
74,315,122 | <p>In my DOCKERFILE I'm running some PowerShell script which creates a custom event log (on Windows Server), then writes an entry. [I should add that I'm currently doing this only for debug purposes.]</p>
<p>The script/command which creates the event log appear to execute without any problems, but an exception is thrown when writing to the log using...</p>
<pre><code>RUN powershell.exe -command Write-EventLog -LogName "my_log_name" -Source "my_source" -Message "EventLog created by DOCKERFILE." -Category 0 -EventID 0 -EntryType Information
</code></pre>
<p>The following exception is thrown...</p>
<pre><code>Write-EventLog : A positional parameter cannot be found that accepts argument
'created'.
At line:1 char:1
+ Write-EventLog -LogName my_log_name -Source my_source -EntryType Messag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-EventLog], Parameter
BindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.WriteEventLogCommand
</code></pre>
<p>I also tried wrapping <code>"EventLog created by DOCKERFILE."</code> in parentheses but then it complained about the word <code>by</code>.</p>
<p>Why does it seem unable to parse <code>"EventLog created by DOCKERFILE."</code> as a string argument, but is instead parsing the words within the string?</p>
<hr />
<p><strong>UPDATE</strong><br />
Even if I wrap the command in double-quotes and the individual strings in single quotes, I get the same error.</p>
<p><a href="https://i.stack.imgur.com/G3RzR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G3RzR.png" alt="enter image description here" /></a></p>
<hr />
<p><strong>UPDATE 2</strong><br />
Removing the quotes and escaping the spaces doesn't work either.</p>
<p><a href="https://i.stack.imgur.com/7a89P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7a89P.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74315197,
"author": "Softacom",
"author_id": 15611794,
"author_profile": "https://Stackoverflow.com/users/15611794",
"pm_score": 2,
"selected": true,
"text": "PUT"
},
{
"answer_id": 74320508,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "TIdHTTP"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/262892/"
] |
74,315,132 | <p>i currently have a array function that reads in values of user input and I want to print out the array using another function.</p>
<p>this is my code</p>
<p>Function to read in user input and store in 2d array</p>
<pre><code>void readMatrix(){
int arr[3][4];
int *ptr;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
printf("row %d, col %d: ", i + 1, j + 1);
scanf("%d", &arr[i][j]);
}
ptr = &arr;
}
}
</code></pre>
<p>function to print array stored in readMatrix() function</p>
<pre><code>void printMatrix(){
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 4; ++j)
{
printf("row %d, col %d = %d\n", i + 1, j + 1, arr[i][j]);
}
}
}
int main(){
//function to read matrix
readMatrix();
//function to print matrix
printMatrix();
return 0;
}
</code></pre>
| [
{
"answer_id": 74315312,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 3,
"selected": true,
"text": "int arr[3][4];"
},
{
"answer_id": 74316946,
"author": "lzl",
"author_id": 20312513,
"author_profile": "https://Stackoverflow.com/users/20312513",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n\nint *readMatrix(int *arr);\n\nvoid printMatrix(int *arr);\n\nint main()\n{\n int arr[3][4];\n\n readMatrix(&arr[0][0]);\n printMatrix(&arr[0][0]);\n\n return 0;\n}\n\nint *readMatrix(int *arr)\n{\n for (int i = 0; i < 3; ++i)\n {\n for (int j = 0; j < 4; ++j)\n {\n printf(\"row %d, col %d: \", i + 1, j + 1);\n scanf(\"%d\", &arr[i * 4 + j]);\n }\n }\n\n return arr;\n}\n\nvoid printMatrix(int *arr)\n{\n for (int i = 0; i < 3; ++i)\n {\n for (int j = 0; j < 4; ++j)\n {\n printf(\"row %d, col %d = %d\\n\", i + 1, j + 1, arr[i * 4 + j]);\n }\n }\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415156/"
] |
74,315,170 | <p>How to retrieve an object using multiple parameters in url? Example : 'customer/3/order/1/' or 'customer/<int:customer_pk>/order/<int:pk>/'</p>
<p>Using shell i'm able to get the object like this but i can't seem to do it from the views.</p>
<pre><code>>>> from temp.models import Customer, Order
>>> from temp.serializers import CustomerSerializer, OrderSerializer
>>> q = Order.objects.filter(customer=1).get(order_number=2)
>>> q.order_name
'fruit'
</code></pre>
<h3>views.py</h3>
<pre class="lang-py prettyprint-override"><code>from rest_framework import generics
from rest_framework.views import APIView
from .models import *
from .serializers import *
class OrderDetailView(generics.RetrieveDestroyAPIView):
serializer_class = OrderSerializer
def get_queryset(self):
queryset = Order.objects.filter(customer_id=self.kwargs["customer_pk"]).get(order_number=self.kwargs["pk"])
return queryset
</code></pre>
<h3>urls.py</h3>
<pre class="lang-py prettyprint-override"><code>from django.urls import path
from .views import *
urlpatterns = [
path('<int:customer_pk>/orders/<int:pk>/', OrderDetailView.as_view()),
]
</code></pre>
| [
{
"answer_id": 74316365,
"author": "Mahammadhusain kadiwala",
"author_id": 19205926,
"author_profile": "https://Stackoverflow.com/users/19205926",
"pm_score": 0,
"selected": false,
"text": "queryset = Order.objects.filter(customer_id=self.kwargs[\"customer_pk\"],order_number=self.kwargs[\"orde_pk\"])\n"
},
{
"answer_id": 74316396,
"author": "Mahrus Khomaini",
"author_id": 11697139,
"author_profile": "https://Stackoverflow.com/users/11697139",
"pm_score": 2,
"selected": true,
"text": "class OrderDetailView(generics.RetrieveDestroyAPIView):\n lookup_field = \"pk\"\n serializer_class = OrderSerializer \n\n def get_queryset(self):\n return Order.objects.filter(customer_id=self.kwargs[\"customer_pk\"])\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19859438/"
] |
74,315,173 | <p>I'm trying to have elements appear when I'm hovering a specific one but I don't know which approach to chose. My project only contains html, css and javascript.</p>
<p><a href="https://i.stack.imgur.com/ODprX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ODprX.png" alt="enter image description here" /></a></p>
<p>I want that when the user is hovering business rules (as seen on the picture), the other bubbles to lower in opacity and new bubbles to appear around the hovered one. Should I use js observer to add a class that will lower opacity on other bubbles and one that set visible the new bubbles ? My main problem being that I haven't found a way to trigger an observer on focus.</p>
| [
{
"answer_id": 74315387,
"author": "Aid Hadzic",
"author_id": 5963060,
"author_profile": "https://Stackoverflow.com/users/5963060",
"pm_score": 2,
"selected": true,
"text": "mouseenter"
},
{
"answer_id": 74315595,
"author": "Lakruwan Pathirage",
"author_id": 12383492,
"author_profile": "https://Stackoverflow.com/users/12383492",
"pm_score": 0,
"selected": false,
"text": "<div class=\"wrapper\">\n<div class=\"business_rules\"></div>\n</div>\n\n<div class=\"other_bubbles\"></div>\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16844067/"
] |
74,315,174 | <p><strong>Objective:</strong> How to access and assign object type variable value from terraform root config</p>
<p><strong>Code I am trying:</strong></p>
<p>I am using modules in terraform. The following is one module I am using to create a cosmos DB account</p>
<p><strong>child module:</strong></p>
<pre><code>resource "azurerm_cosmosdb_account" "cosmosaccount" {
name = var.account_name
location = var.location
resource_group_name = var.rg_name
offer_type = var.cosmos_db_config.cosmosdb_offer_type
kind = var.cosmos_db_config.cosmosdb_kind
is_virtual_network_filter_enabled = "true"
ip_range_filter = var.cosmos_db_config.ip_range_filter
enable_automatic_failover = false
consistency_policy {
consistency_level = var.cosmos_db_config.cosmosdb_consistancy_level
max_interval_in_seconds = 5
max_staleness_prefix = 100
}
geo_location {
location = var.location
failover_priority = 0
}
tags = var.tags
}
</code></pre>
<p><strong>child module variable.tf:</strong></p>
<pre><code>variable "cosmos_db_config" {
default = {
cosmosdb_offer_type = ""
cosmosdb_kind = ""
cosmosdb_consistancy_level = ""
ip_range_filter = ""
}
type = object(
{
cosmosdb_offer_type = string
cosmosdb_kind = string
cosmosdb_consistancy_level = string
ip_range_filter = string
}
)
}
</code></pre>
<p><strong>main root variable.tf:</strong></p>
<pre><code>variable "cosmos_db_config" {
default = {
cosmosdb_offer_type = ""
cosmosdb_kind = ""
cosmosdb_consistancy_level = ""
ip_range_filter = ""
}
type = object(
{
cosmosdb_offer_type = string
cosmosdb_kind = string
cosmosdb_consistancy_level = string
ip_range_filter = string
}
)
}
</code></pre>
<p><strong>Module call:</strong></p>
<pre><code>module "cosmosdb" {
source = "../modules/cosmosdb"
account_name = "test"
rg_name = module.resource_group.name
location = module.resource_group.location
cosmosdb_offer_type = var.cosmos_db_config.cosmosdb_offer_type
cosmosdb_kind = var.cosmos_db_config.cosmosdb_kind
ip_range_filter = var.cosmos_db_config.ip_range_filter
#subnet_id = var.subnet_id
cosmosdb_consistancy_level = var.cosmos_db_config.cosmosdb_consistancy_level
tags = local.common_tags
}
</code></pre>
<p><strong>terraform.tfvars.json:</strong></p>
<pre><code>"cosmos_db_config": {
"cosmosdb_offer_type": "Standard",
"cosmosdb_kind": "GlobalDocumentDB",
"cosmosdb_consistancy_level": "Session",
"ip_range_filter": ""
},
</code></pre>
<p><strong>Error I get:</strong></p>
<pre><code>Error: Unsupported argument
β
β on cosmosdb.tf line 6, in module "cosmosdb":
β 6: cosmosdb_offer_type = var.cosmos_db_config.cosmosdb_offer_type
β
β An argument named "cosmosdb_offer_type" is not expected here
</code></pre>
<p>Can you please suggest what mistake I am doing here ?</p>
| [
{
"answer_id": 74315243,
"author": "Marko E",
"author_id": 8343484,
"author_profile": "https://Stackoverflow.com/users/8343484",
"pm_score": 2,
"selected": true,
"text": "cosmos_db_config"
},
{
"answer_id": 74315275,
"author": "YCF_L",
"author_id": 5558072,
"author_profile": "https://Stackoverflow.com/users/5558072",
"pm_score": 2,
"selected": false,
"text": "cosmosdb_offer_type = var.cosmos_db_config.cosmosdb_offer_type\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9375954/"
] |
74,315,177 | <p>I already referred these posts <a href="https://stackoverflow.com/questions/2024954/line-of-best-fit-scatter-plot">here</a> and <a href="https://stackoverflow.com/questions/40941542/using-scikit-learn-linearregression-to-plot-a-linear-fit">here</a> and tried to plot the line of best fit for my linear regression problem.</p>
<p>So, my data shape looks like below</p>
<p><a href="https://i.stack.imgur.com/Lrfu2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lrfu2.png" alt="enter image description here" /></a></p>
<p>My code to plot the best fit line looks like below</p>
<pre><code>plt.scatter(X_test.values, Y_test.values, color="black") # throws error in this line
plt.plot(Y_test, y_pred, color="blue", linewidth=3)
plt.xticks(())
plt.yticks(())
plt.show()
</code></pre>
<blockquote>
<p>ValueError: x and y must be the same size</p>
</blockquote>
<p><strong>update - output</strong></p>
<p><a href="https://i.stack.imgur.com/l2I50.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l2I50.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74315328,
"author": "StonedTensor",
"author_id": 6023918,
"author_profile": "https://Stackoverflow.com/users/6023918",
"pm_score": 3,
"selected": true,
"text": "X_test"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10829044/"
] |
74,315,218 | <p>So, I have a data frame that looks like this:</p>
<pre><code>plot <- data.frame(plot=c("A", "A", "A", "B", "B", "C", "C", "C"),
grid= c(1,1,1,2,2,3,3,3),
year1=c(2000,2000,2010,2000,2010,2000,2010,2010),
year2=c(2005,2005,2015,2005,2015,2005,2015,2015))
plot
plot grid year1 year2
1 A 1 2000 2005
2 A 1 2000 2005
3 A 1 2010 2015
4 B 2 2000 2005
5 B 2 2010 2015
6 C 3 2000 2005
7 C 3 2010 2015
8 C 3 2010 2015
</code></pre>
<p>So for the <code>plot</code> column I have repeated values, the <code>grid</code> is always unique for each of the plots but the years are changing, what I want basically is a new data frame which will just keep all the unique combinations from these four columns, which would look like this:</p>
<pre><code> plot grid year1 year2
1 A 1 2000 2005
2 A 1 2010 2015
3 B 2 2000 2005
4 B 2 2010 2015
5 C 3 2000 2005
6 C 3 2010 2015
</code></pre>
<p>I tried to look for solution but I could not fine anything that fits to my example.</p>
| [
{
"answer_id": 74315328,
"author": "StonedTensor",
"author_id": 6023918,
"author_profile": "https://Stackoverflow.com/users/6023918",
"pm_score": 3,
"selected": true,
"text": "X_test"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20165603/"
] |
74,315,227 | <p>Hello I need to advice some formulas on my problem:</p>
<ul>
<li><p>How can I combine two, three or more columns into single one column?</p>
</li>
<li><p>And if in columns are <strong>"empty"</strong> cells I want to skip these cells inside of that single one column.</p>
</li>
</ul>
<p>But be aware! This is the problem. All columns are contains another formulas. So these <strong>"empty"</strong> cells are in fact contains my another formulas with result ="".</p>
<p>Here is example of what I want to get - in column E:
<a href="https://i.stack.imgur.com/3eHgg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3eHgg.png" alt="EXAMPLE" /></a></p>
<p>EDIT:</p>
<ul>
<li>New functions like TOCOL are not available in my Microsoft Office 365 MSO: 16.0.14326.21092 (32 bit).</li>
</ul>
| [
{
"answer_id": 74315288,
"author": "JvdV",
"author_id": 9758194,
"author_profile": "https://Stackoverflow.com/users/9758194",
"pm_score": 2,
"selected": false,
"text": "E2"
},
{
"answer_id": 74317973,
"author": "Terio",
"author_id": 4840576,
"author_profile": "https://Stackoverflow.com/users/4840576",
"pm_score": 1,
"selected": true,
"text": "=FILTERXML(\"<t><s>\"&TEXTJOIN(\"</s><s>\",1,TRANSPOSE(A2:C10))&\"</s></t>\",\"//s\")\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14583736/"
] |
74,315,255 | <p>I've found that I can access a local coming from my root Terraform module in its children Terraform modules.
I thought that a local is scoped to the very module it's declared in.
See: <a href="https://developer.hashicorp.com/terraform/language/values/locals#using-local-values" rel="nofollow noreferrer">https://developer.hashicorp.com/terraform/language/values/locals#using-local-values</a></p>
<blockquote>
<p>A local value can only be accessed in expressions within the module where it was declared.</p>
</blockquote>
<p>Seems like the documentation says locals shouldn't be visible outside their module. At my current level of Terraform knowledge I can't foresee what may be wrong with seeing locals of a root module in its children.</p>
<p>Does Terraform locals visibility scope span children (called) modules?
Why is that?
Is it intentional (by design) that a root local is visible in children modules?</p>
<p><strong>Details added later:</strong>
Terraform version I use 1.1.5
My sample project:</p>
<pre><code>.
βββ childmodulecaller.tf
βββ main.tf
βββ child
βββ some.tf
</code></pre>
<p>main.tf</p>
<pre><code>locals {
a = 1
}
</code></pre>
<p>childmodulecaller.tf</p>
<pre><code>locals {
b = 2
}
module "child" {
for_each = toset(try(local.a + local.b == 3, false) ? ["name"] : [])
source = "./child"
}
</code></pre>
<p>some.tf</p>
<pre><code>resource "local_file" "a_file" {
filename = "${path.module}/file1"
content = "foo!"
}
</code></pre>
<p>Now I see that my question was based on a wrongly interpreted observation.
Not sure if it is still of any value but leaving it explained.
Perhaps it can help someone else to understand the same and avoid the confusion I experienced and explained in my corrected answer.</p>
| [
{
"answer_id": 74315362,
"author": "Alexander Ites",
"author_id": 7425756,
"author_profile": "https://Stackoverflow.com/users/7425756",
"pm_score": -1,
"selected": false,
"text": "resource \"local_file\" \"a_file\" {\n filename = \"${path.module}/file1\"\n content = \"foo!\"\n}\n\noutput \"outa\" {\n value = local.a\n}\n\noutput \"outb\" {\n value = local.b\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7425756/"
] |
74,315,271 | <p>Given an array [[1, 7, 3, 8],[3, 2, 9, 4],[4, 3, 2, 1]],
how can I find the sum of its repeating elements? (In this case, the sum would be 10.)</p>
<p>Repeated values are - 1 two times, 3 three times, 2 two times, and 4 two times
So, 1 + 3 + 2 + 4 = 10</p>
<p>Need to solve this problem in the minimum time</p>
<p>There are multiple ways to solve this but time complexity is a major issue.</p>
<p>I try this with the recursion function</p>
<p>How can I optimize more</p>
<p>`</p>
<pre><code>var uniqueArray = []
var sumArray = []
var sum = 0
function sumOfUniqueValue (num){
for(let i in num){
if(Array.isArray(num[i])){
sumOfUniqueValue(num[i])
}
else{
// if the first time any value will be there then push in a unique array
if(!uniqueArray.includes(num[i])){
uniqueArray.push(num[i])
}
// if the value repeats then check else condition
else{
// we will check that it is already added in sum or not
// so for record we will push the added value in sumArray so that it will added in sum only single time in case of the value repeat more then 2 times
if(!sumArray.includes(num[i])){
sumArray.push(num[i])
sum+=Number(num[i])
}
}
}
}
}
sumOfUniqueValue([[1, 7, 3, 8],[1, 2, 9, 4],[4, 3, 2, 7]])
console.log("Sum =",sum)
</code></pre>
<p>`
That's a real problem, I am just curious to solve this problem so that I can implement it in my project.</p>
<p>If you guys please mention the time it will take to complete in ms or ns then that would be really helpful, also how the solution will perform on big data set.</p>
<p>Thanks</p>
| [
{
"answer_id": 74315362,
"author": "Alexander Ites",
"author_id": 7425756,
"author_profile": "https://Stackoverflow.com/users/7425756",
"pm_score": -1,
"selected": false,
"text": "resource \"local_file\" \"a_file\" {\n filename = \"${path.module}/file1\"\n content = \"foo!\"\n}\n\noutput \"outa\" {\n value = local.a\n}\n\noutput \"outb\" {\n value = local.b\n}\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20415827/"
] |
74,315,289 | <p>I have this code:</p>
<pre><code>if(isset($_POST['submit'])) {
$name = $_POST['name'];
$query = mysqli_query($conn, "select name from accounts where name = '{$name}'");
if($query) {
echo "success";
} else {
echo "error";
}
}
?>
<form action="" method="post">
Name: <input type="text" name="name"><br><br>
<input type="submit" name="submit" value="Add">
</form>
</code></pre>
<p>And I have written this in the form and submitted, only return (error), and the table was not deleted.
<a href="https://i.stack.imgur.com/WieXJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WieXJ.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74315620,
"author": "Tural Rzaxanov",
"author_id": 9922647,
"author_profile": "https://Stackoverflow.com/users/9922647",
"pm_score": -1,
"selected": false,
"text": "1';DROP table accounts where id!='123454321344321\n"
},
{
"answer_id": 74315621,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 3,
"selected": true,
"text": "$query = mysqli_query($conn, \"select name from accounts where name = '{$name}'\");\n"
}
] | 2022/11/04 | [
"https://Stackoverflow.com/questions/74315289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4399890/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.