qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,419,500 | <p>I have a list of lists and I'd like to generate the possible permutations, the first element coming from the first sub-list, the second from the second sub-list and so on.</p>
<pre><code>?- A = [[1], [a, b], [2]], magic_function(A, Ans).
Ans = [1, a, 2]
; Ans = [1, b, 2]
; false.
?- B = [[1], [a, b], [4, 5]], magic_function(B, Ans).
Ans = [1, a, 4]
; Ans = [1, a, 5]
; Ans = [1, b, 4]
; Ans = [1, b, 5]
; false
</code></pre>
<p>I suppose it's a pretty standard idea, but for some reason I just can't seem to come up with anything useful.</p>
| [
{
"answer_id": 74419615,
"author": "notoria",
"author_id": 14414324,
"author_profile": "https://Stackoverflow.com/users/14414324",
"pm_score": 3,
"selected": true,
"text": "maplist/3"
},
{
"answer_id": 74425830,
"author": "TessellatingHeckler",
"author_id": 478656,
"author_profile": "https://Stackoverflow.com/users/478656",
"pm_score": 0,
"selected": false,
"text": "perms([], []).\nperms([List|Ls], [Item|T]) :-\n member(Item, List),\n perms(Ls, T).\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9038952/"
] |
74,419,514 | <p>In the book "Haskell programming from first principles" it is said that:</p>
<blockquote>
<p>If you are using GHC 7.10 or newer, you’ll see an Applicative
constraint in the definition of Monad, as it should be:</p>
<pre><code>class Applicative m => Monad m where
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
</code></pre>
</blockquote>
<p>I have created the following applicative functor.</p>
<pre><code>data WhoCares a = ItDoesnt | Matter a | WhatThisIsCalled deriving (Eq, Show)
instance Functor WhoCares where
fmap _ ItDoesnt = ItDoesnt
fmap _ WhatThisIsCalled = WhatThisIsCalled
fmap f (Matter a) = Matter (f a)
instance Applicative WhoCares where
pure = Matter
Matter f <*> Matter a = Matter (f a)
main = do
-- fmap id == id
let funcx = fmap id "Hi Julie"
let funcy = id "Hi Julie"
print(funcx)
print(funcy)
print(funcx == funcy)
-- fmap (f . g) == fmap f . fmap g
let funcx' = fmap ((+1) . (*2)) [1..5]
let funcy' = fmap (+1) . fmap (*2) $ [1..5]
print(funcx')
print(funcy')
print(funcx' == funcy')
-- pure id <*> v = v
print(pure id <*> (Matter 10))
-- pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
let appx = pure (.) <*> (Matter (+1)) <*> (Matter (*2)) <*> (Matter 10)
let appy = (Matter (+1)) <*> ((Matter (*2)) <*> (Matter 10))
print(appx)
print(appy)
print(appx == appy)
-- pure f <*> pure x = pure (f x)
let appx' = pure (+1) <*> pure 1 :: WhoCares Int
let appy' = pure ((+1) 1) :: WhoCares Int
print(appx')
print(appy')
print(appx' == appy')
-- u <*> pure y = pure ($ y) <*> u
let appx'' = Matter (+2) <*> pure 2
let appy'' = pure ($ 2) <*> Matter (+ 2)
print(appx'')
print(appy'')
print(appx'' == appy'')
</code></pre>
<p>Due to lack of examples, I am not understanding how to implement <code>>>=</code> and <code>>></code>. The code I came up with so far is:</p>
<pre><code>instance Monad (WhoCares a) where
(>>=) :: Matter a -> (a -> Matter b) -> Matter b
(>>) :: Matter a -> Matter b -> Matter b
return :: a -> Matter a
return = pure
</code></pre>
<p>So, that I can do stuff like:</p>
<pre><code>half x = if even x
then Matter (x `div` 2)
else ItDoesnt
incVal :: (Ord a, Num a) => a -> WhoCares a
incVal x
| x + 1 <= 10 = return (x + 1)
| otherwise = ItDoesnt
decVal :: (Ord a, Num a) => a -> WhoCares a
decVal x
| x - 1 >= 0 = return (x - 1)
| otherwise = ItDoesnt
main = do
print (Matter 7 >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal)
print (Matter 7 >>= incVal >>= incVal >>= incVal >>= incVal >>= decVal >>= decVal)
print (Matter 2 >>= decVal >>= decVal >>= decVal)
print(Matter 20 >>= half >>= half)
</code></pre>
<p>With Output:</p>
<pre><code>10
ItDoesnt
ItDoesnt
ItDoesnt
5
</code></pre>
<p>Please help.</p>
| [
{
"answer_id": 74419615,
"author": "notoria",
"author_id": 14414324,
"author_profile": "https://Stackoverflow.com/users/14414324",
"pm_score": 3,
"selected": true,
"text": "maplist/3"
},
{
"answer_id": 74425830,
"author": "TessellatingHeckler",
"author_id": 478656,
"author_profile": "https://Stackoverflow.com/users/478656",
"pm_score": 0,
"selected": false,
"text": "perms([], []).\nperms([List|Ls], [Item|T]) :-\n member(Item, List),\n perms(Ls, T).\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1772898/"
] |
74,419,533 | <p>I have an Entity like the code down here where for every phrase I can have many translations in different languages.</p>
<p>The problem is that when I fetch the translations Hibernate makes a query to the database for every phrase.</p>
<p>So if I have 1000 translations Hibernate will automatically make 1 query for translations and 1000 for the phrases table.</p>
<p>But this is very slow as compared to a JOIN and a single query:
"SELECT * FROM ad_translations a JOIN ad_phrase ap ON (ap.id = a.id_ad_phrase)"</p>
<p>What are the options in this case? Should I use Native SQL or is there a better way?</p>
<pre><code>@Entity
@Table(name="ad_translations")
public class Translations implements Serializable {
...
@ManyToOne
@JoinColumn(name="id_ad_phrase")
private Phrase idAdPhrase;
@ManyToOne
@JoinColumn(name="id_ad_lang")
private Lang idAdLang;
...
}
</code></pre>
<p>UPDATE:
I read 3 possible solutions here <a href="https://hackernoon.com/3-ways-to-deal-with-hibernate-n1-problem" rel="nofollow noreferrer">https://hackernoon.com/3-ways-to-deal-with-hibernate-n1-problem</a>
But all seem to be imperfect as:</p>
<ul>
<li>the first solution is NativeSQL and it must be the correct one from the point of view of the performance but going this way I have a lot of code to write when I fetch the data as I must manually create the objects for Lang and Phrase and populate them from the result of the query.</li>
<li>the second solution(@BatchSize) involves too many queries</li>
<li>the third solution(@Fetch(FetchMode.SUBSELECT)) is obviously not as good as the first regarding the performance</li>
</ul>
<p>FetchType.Lazy will not help as I use this entity in a REST application and all data will be fetched at serialization time.</p>
<p>I'm not sure how Projections affect the N+1 problem, seems that they only help to make a selection with a custom number of columns but the number of queries remains the same.</p>
<p>I don't know why Hibernate doesn't have an auto JOIN option so we can use the first solution with very little code written.</p>
<p>I'll go for the native SQL option.</p>
| [
{
"answer_id": 74419678,
"author": "birca123",
"author_id": 10231374,
"author_profile": "https://Stackoverflow.com/users/10231374",
"pm_score": 1,
"selected": false,
"text": "*ToOne"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1510155/"
] |
74,419,594 |
<pre><code><div class="content-home">
<div class="logo-wrap-home">
<div class="logo-homepage"></div>
</div>
<div class="search-wrap-home">
<form method="get" class="search-home" action="https://raihan-zidan.github.io/search">
<div class="search-box">
<div class="search-field">
<input name="q" class="search-input" autocorrect="off" autocomplete="off" autocapitalize="off" placeholder="Type to search...">
<button type="submit" class="search-toggle"></button>
</div>
</div>
<noscript>Javascript is required for the site to work</noscript>
</form>
</div>
</div>
</code></pre>
`
<p>CSS:
`* {</p>
<p>padding: 0;</p>
<p>margin: 0;</p>
<p>box-sizing: border-box;</p>
<p>text-size-adjust: none;</p>
<p>}</p>
<p>html, body {</p>
<p>height: 100%;</p>
<p>background: #f5f8fa;</p>
<p>font-family: "Helvetica Neue", arial;</p>
<p>overflow: hidden;</p>
<p>}</p>
<p>.content-home {</p>
<p>margin: 0;</p>
<p>padding: 0;</p>
<p>}</p>
<p>.logo-wrap-home {</p>
<p>padding: 30px 0;</p>
<p>display: flex;</p>
<p>justify-content: center;</p>
<p>}</p>
<p>.logo-homepage {</p>
<p>width: 230px;</p>
<p>min-height: 58px;</p>
<p>background-image: url("logourl");</p>
<p>background-size: cover;</p>
<p>background-position: center;</p>
<p>background-repeat: no-repeat;</p>
<p>}</p>
<p>.search-toggle {</p>
<p>border: none;</p>
<p>background: transparent;</p>
<p>}</p>
<p>.search-box {</p>
<p>width: 100%;</p>
<p>position: relative;</p>
<p>}</p>
<p>.search-field {</p>
<p>width: 100%;</p>
<p>display: flex;</p>
<p>align-items: center;</p>
<p>}</p>
<p>.search-toggle {</p>
<p>position: absolute;</p>
<p>width: 45px;</p>
<p>height: 45px;</p>
<p>right: 0;</p>
<p>cursor: pointer;</p>
<p>background-image: url("logourl");</p>
<p>background-size: 18px;</p>
<p>background-repeat: no-repeat;</p>
<p>background-position: center</p>
<p>}</p>
<p>.search-input {</p>
<p>width: 100%;</p>
<p>height: 44px;</p>
<p>outline: 0;</p>
<p>border: none;</p>
<p>border-radius: 22px;</p>
<p>font-size: 16px;</p>
<p>box-shadow: 0 2px 4px 0 rgba(0,0,0,.08),0 0 1px 0 rgba(0,0,0,.1);</p>
<p>padding: 0 45px 0 20px;</p>
<p>background: white;</p>
<p>}`</p>
<p>Please help me I need this</p>
| [
{
"answer_id": 74419678,
"author": "birca123",
"author_id": 10231374,
"author_profile": "https://Stackoverflow.com/users/10231374",
"pm_score": 1,
"selected": false,
"text": "*ToOne"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491248/"
] |
74,419,626 | <p>I am using MongoDB to store data, and on retrieving them I want to get the date and convert it to something that looks like this:</p>
<pre><code>'2022-07-20T10:12:21.054Z'
</code></pre>
<p>right now my date looks like this:</p>
<pre><code>"Nov. 13, 2022 at 5:51 AM "
</code></pre>
<p>because I am getting it directly from mongo through the createdAt key. How can I achieve this?</p>
| [
{
"answer_id": 74419729,
"author": "Syful Islam",
"author_id": 10710013,
"author_profile": "https://Stackoverflow.com/users/10710013",
"pm_score": 0,
"selected": false,
"text": "> Try this using moment library you can make any format you want.\n<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title>Title</title>\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js\"></script>\n </head>\n <body>\n \n <button type=\"button\" onclick=\"clickHandler()\">\n Get Today!\n </button>\n <script>\n function clickHandler() {\n alert(moment('2022-07-20T10:12:21.054Z')\n .format('MMM. , DD YYYY at h:mm:ss a'))\n }\n </script>\n </body>\n </html>\n"
},
{
"answer_id": 74419784,
"author": "Ping",
"author_id": 20288037,
"author_profile": "https://Stackoverflow.com/users/20288037",
"pm_score": -1,
"selected": false,
"text": "const dateStr = 'Nov. 13, 2022 at 5:51 AM'\nconst regex = /\\.|,|\\s|:/g\nconst dateArray = dateStr.split(regex);\nconst ampmTo24hr = (hh,mm,ampm) => (\n ampm === 'AM' ?\n `${hh}:${mm}:00` :\n `${parseInt(hh,10) + 12}:${mm}:00`\n );\n\nconst [mmm,,dd,,yyyy,,hh,mm,ampm] = dateArray;\nconst time = ampmTo24hr(hh,mm,ampm);\n \nconsole.log(`${yyyy}-${mmm}-${dd} ${time}`)\nconsole.log(new Date(`${yyyy}-${mmm}-${dd} ${time}`))"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11120306/"
] |
74,419,698 | <p>Why is the for loop appending faster than list comprehension
For Loop Time: 7.214778099999876
List Comprehension Time: 7.4003780000002735</p>
<p>Code 1:</p>
<pre><code>import timeit
mycode = '''
new_list=[]
x=[1,2,3,4,5]
for obj in x:
if obj %2==0:
new_list.append(obj)
'''
print (timeit.timeit(stmt = mycode,
number = 10000000))
</code></pre>
<p>Code 2:</p>
<pre><code>import timeit
mycode = '''
x=[1,2,3,4,5]
new_list=[obj for obj in x if obj %2==0]
'''
print (timeit.timeit(stmt = mycode,
number = 10000000))
</code></pre>
<p>I expected the for loop to be slower than list comprehension when it came to appending repeatedly but that was not the case.</p>
| [
{
"answer_id": 74421686,
"author": "Jérôme Richard",
"author_id": 12939557,
"author_profile": "https://Stackoverflow.com/users/12939557",
"pm_score": 1,
"selected": false,
"text": "x=list(range(15))"
},
{
"answer_id": 74421901,
"author": "Dimitrius",
"author_id": 5558953,
"author_profile": "https://Stackoverflow.com/users/5558953",
"pm_score": 0,
"selected": false,
"text": "import tracemalloc\ntracemalloc.start()\n\ndef a():\n new_list = []\n x = [1, 2, 3, 4, 5]\n for obj in x:\n if obj % 2 == 0:\n new_list.append(obj)\n\n\ndef b():\n x = [1, 2, 3, 4, 5]\n new_list = [obj for obj in x if obj % 2 == 0]\n\na()\nb()\n\nsnapshot = tracemalloc.take_snapshot()\ntop_stats = snapshot.statistics('lineno')\n\nprint(\"[ Top 10 ]\")\nfor stat in top_stats[:10]:\n print(stat)\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19745616/"
] |
74,419,704 | <p>I am trying to replace a string in the config file.
I would like to run something like this:</p>
<p>OS</p>
<blockquote>
<p>(docker image php:8.1-apache-buster)</p>
<blockquote>
<p>Debian GNU/Linux 10 (buster)</p>
<blockquote>
<p>sed (GNU sed) 4.7 Packaged by Debian</p>
</blockquote>
</blockquote>
</blockquote>
<p>Possible inputs:</p>
<pre><code>post_max_size = 4M
post_max_size = 24M
post_max_size = 248M
...
</code></pre>
<p>Example output (any user given value):</p>
<pre><code>post_max_size = 128M
</code></pre>
<p>Example cmd:</p>
<pre><code>sed -i 's/(post_max_size = ([0-9]{1,})M/post_max_size = 128M/g' /usr/local/etc/php/php.ini
</code></pre>
<p><a href="https://i.stack.imgur.com/sqKlL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sqKlL.png" alt="enter image description here" /></a></p>
<p>Joining regex with strings does not work here.</p>
<p>It works when I run string replace without any regex</p>
<pre><code>sed -i 's/post_max_size = 8M/post_max_size = 128M/g' /usr/local/etc/php/php.ini
</code></pre>
<p>This works only if the value of the post_max_size is set exactly to 2M. I would like to be able to make a change with regex regardless of the value set.</p>
<p>I searched the Internet and <code>sed</code> cmd docs but did not find anything which fits my use case.</p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2179965/"
] |
74,419,785 | <pre><code>I have this database:
id power_count power_name type second_power second_power_type
0 001 1 fire attack nan nan
1 001 1 fire attack nan nan
2 002 2 water defense nan nan
3 002 2 sand attack nan nan
4 002 2 sand attack nan nan
5 003 1 fire defense nan nan
6 004 2 fire defense nan nan
7 004 2 water attack nan nan
</code></pre>
<p>And I want to get to this:</p>
<pre><code> id power_count power_name type second_power second_power_type
0 001 1 fire attack nan nan
1 001 1 fire attack nan nan
2 002 2 water defense sand attack
3 002 2 sand attack water defense
4 002 2 sand attack water defense
5 003 1 fire defense nan nan
6 004 2 fire attack water attack
7 004 2 water attack fire attack
</code></pre>
<p>So only in the rows that have 2 power count add the information on the other power</p>
<p>I tried to do a loop for doing it but didn't succeed.</p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19844859/"
] |
74,419,812 | <p>The task was to reverse the order of words in the sentence
I was able to reverse the order of the words, but the problem is that the order of the letters in the word also changes</p>
<p>For example: cats and dogs</p>
<p>The miracle in my plan:tac dna sgod</p>
<p>The desired output: dogs and cats</p>
<p>How can I fix the code to work correctly?</p>
<p>this is my code:</p>
<pre><code>void revSent(char str[]) {
int i;
int n = strlen(str);
char letter;
for (i = 0; i < n / 2; i++) {
letter = str[i];
str[i] = str[strlen(str) - i - 1];
str[strlen(str) - i - 1]=letter ;
}
}
</code></pre>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419812",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491301/"
] |
74,419,823 | <p>I'm learning to use linkedlist, I feel I already understand the concept but when coding why do I always get an error (bus error)....this code can run, but only until "SCANF the NAME" after that an error appears.</p>
<pre><code>typedef struct Student{
char name[20];
char idNum[10];
int saving;
struct Student *next;
}Student;
Student *head = NULL;
void insert_student(){
char *name,*idNum;
int saving;
Student *current;
Student *new_student;
new_student = (Student*)malloc(sizeof(Student));
// apakah ada memoory kosong?
if(new_student==NULL){
printf("==== YOUR MEMMORY IS FULL! ====\n");
exit(0);
}
printf("Enter your name : ");scanf("%[^\n]s",name);
printf("Enter your Id : ");scanf("%[^\n]s",idNum);
printf("How many your money : Rp");scanf("%d",&saving);
strcpy(new_student->name,name);
strcpy(new_student->idNum,idNum);
new_student->saving = saving;
new_student->next = NULL;
if(head==NULL){
head = new_student;
}
else{
current = head;
while (current->next != NULL)
{
current = current->next;
}
current->next = new_student;
}
}
void print_students(){
Student *current;
if(head==NULL){
printf("==== THERE IS NO STUDENT YET!\n");
exit(0);
}
current = head;
while (current!= NULL)
{
printf("Name : %s",current->name);
printf("id : %s",current->idNum);
printf("Saving : Rp%d",current->saving);
current = current->next;
}
}
int main(){
insert_student();
print_students();
return 0;
}
</code></pre>
<p>I'm hoping to create nodes for the dynamic linked-list Student and then display them</p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20095922/"
] |
74,419,839 | <p>I have the column shown in the figure I just want to convert the datetime column from UTC to IST I am trying to add 05:30:00 to each row using google query_language but couldn't find a way
Please help me
<a href="https://i.stack.imgur.com/lb4KX.png" rel="nofollow noreferrer">enter image description here</a></p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19599725/"
] |
74,419,883 | <p>I am developing an app with flutter. I plan to support Android, iOS, macOS, and windows.
But I found that Firebase doesn't work for mac os.</p>
<p>In flutterfire, I chose the following platforms:<br />
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios, macos</p>
<p>But when I ran flutter build -d macos, I got the error “DefaultFirebaseOptions have not been configured for macos”.</p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10518324/"
] |
74,419,893 | <p>I'm trying to create a histogram using ApexCharts (more specifically, React-ApexCharts, but I don't think it makes a difference).</p>
<p>Example of the output I'm after:
<a href="https://i.stack.imgur.com/gbXfi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gbXfi.png" alt="expected_output" /></a>
The example above was originally created using Chart.js (<a href="https://leimao.github.io/blog/JavaScript-ChartJS-Histogram/" rel="nofollow noreferrer">source</a>). The blue shading for one of the bars is irrelevant.</p>
<p>Even though "histogram" is listed as one of the chart types in ApexCharts (<a href="https://apexcharts.com/docs/options/chart/type/" rel="nofollow noreferrer">reference</a>), I haven't been able to reproduce the example above. The issues I cannot solve are:</p>
<ul>
<li>Having <code>number of bars + 1</code> number of labels in the x-axis (i.e. in the example above there are 10 labels and 9 bars)</li>
<li>Positioning the bars strictly between labels</li>
<li>Having a tooltip that references neighbor labels for each bar (e.g. <code>Hours: 6 - 7</code> above)</li>
</ul>
<p>Example code where I'm stuck: <a href="https://codesandbox.io/s/dreamy-wiles-8mbp3e" rel="nofollow noreferrer">https://codesandbox.io/s/dreamy-wiles-8mbp3e</a></p>
| [
{
"answer_id": 74420135,
"author": "C-nan",
"author_id": 13524500,
"author_profile": "https://Stackoverflow.com/users/13524500",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/^post_max_size = .*/post_max_size = 128M/g' /usr/local/etc/php/php.ini\n"
},
{
"answer_id": 74420463,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 2,
"selected": true,
"text": "[[:space:]]*"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8929855/"
] |
74,419,894 | <p>I want to slove this problem
I can't get the result I want</p>
<pre><code>// main.cpp
#include "Point.h"
#include <iostream>
using namespace std;
int main(void) {
double x, y;
Point p{ 10.5, 20.99 };
p.info();
p.get(x, y);
cout << x << ", " << y << endl;
return 0;
}
//Headerfile Point.h
#include <iostream>
using namespace std;
class Point {
private:
double x, y;
public:
Point(double P_x , double P_y) {
x = P_x;
y = P_y;
}
void info(void) {
cout << "(x,y) = " << x << ", " << y << endl;
}
double getx(double &x) {
x;
return 0;
}
double gety(double &y) {
y;
return 0;
}
void get(double& x, double& y) {
getx(x), gety(y);
}
};
</code></pre>
<p><strong>Output</strong>
My wrong result</p>
<blockquote>
<p>(x,y) = 10.5, 20.99</p>
</blockquote>
<blockquote>
<p>-9.25596e+61, -9.25596e+61</p>
</blockquote>
<p>But I want to get this re</p>
<blockquote>
<p>(x,y) = 10.5, 20.99</p>
</blockquote>
<blockquote>
<p>10.5, 20.99</p>
</blockquote>
| [
{
"answer_id": 74419920,
"author": "john",
"author_id": 882003,
"author_profile": "https://Stackoverflow.com/users/882003",
"pm_score": 2,
"selected": false,
"text": "get"
},
{
"answer_id": 74420461,
"author": "StellarClown",
"author_id": 10026471,
"author_profile": "https://Stackoverflow.com/users/10026471",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n\nusing namespace std;\n\nclass Point {\n private:\n double x;\n double y;\n public:\n Point(double P_x , double P_y) {\n x = P_x;\n y = P_y;\n }\n \n void info() const {\n cout << \"(x,y) = \" << this->x << \", \" << this->y << endl;\n }\n \n double getx() const {\n return this->x;\n }\n double gety() const {\n return this->y;\n }\n};\n\n\nint main() {\n Point p{ 10.5, 20.99 };\n p.info();\n \n double x = p.getx();\n double y = p.gety();\n \n cout << x << \",\" << y << endl;\n return 0;\n}\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,419,902 | <pre><code>$secPassword = Read-Host "Password" -AsSecureString
New-ADUser
-Name "XYZ ABC"
-SamAccountName xyz.a
-UserPrincipalName "xyz.a@ntsh.local"
-AccountPassword $secPassword
-Path "cn=Users,dc=ntsh,dc=local"
-Enabled:$true
-PasswordNeverExpires:$true
-CannotChangePassword:$true
-PasswordNotRequired:$false
-ChangePasswordAtLogon:$false
</code></pre>
<p>It's giving CommandNotFoundException Error for all Parameters. What's wrong in my script ?</p>
| [
{
"answer_id": 74420582,
"author": "miguelmtnezz_",
"author_id": 17387554,
"author_profile": "https://Stackoverflow.com/users/17387554",
"pm_score": 2,
"selected": true,
"text": "`"
},
{
"answer_id": 74422607,
"author": "RetiredGeek",
"author_id": 13702221,
"author_profile": "https://Stackoverflow.com/users/13702221",
"pm_score": 2,
"selected": false,
"text": "$NADUArgs = @{\n Name = \"XYZ ABC\"\n SamAccountName = \"xyz.a\"\n UserPrincipalNam = \"xyz.a@ntsh.local\"\n AccountPassword = $secPassword\n Path = \"cn=Users,dc=ntsh,dc=local\"\n Enabled = $true\n PasswordNeverExpires = $true\n CannotChangePassword = $true\n PasswordNotRequired = $false\n ChangePasswordAtLogon = $false\n}\n\nNew-ADUser @NADUArgs\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2811532/"
] |
74,419,938 | <p>I am working on a small project. What i want to do is when sorting happens <code>@click</code> event, <code>sortcol</code> column is given asc, desc, but. The thing I want is this, I want to clear the value of other columns except the clicked column.</p>
<p>I couldn't figure out how to get this done.</p>
<pre><code><template>
<table>
<thead>
<tr>
<th v-for="th in tableHeader" :key="th">
<div class="flex" @click.prevent="sortByColumn(th.name)">
<div class="sort-header-content">{{ th.text }}</div>
<div v-if="sortcol[th.name]==='asc'">ArrowDownIcon</div>
<div v-else-if="sortcol[th.name]==='desc'">ArrowUpIcon</div>
</div>
</th>
</tr>
</thead>
</table>
</template>
<script>
export default {
name: "Table",
data() {
return {
columns: [
{name: 'id', text: 'ID'},
{name: 'name', text: 'Name'},
{name: 'position', text: 'Position'},
{name: 'office', text: 'Office'},
{name: 'extension', text: 'Extension'},
{name: 'startdate', text: 'Start Date'},
{name: 'salary', text: 'Salary'},
],
sortcol: {
name: '',
position: '',
office: '',
extension: '',
startdate: '',
salary: '',
},
}
},
methods: {
sortByColumn(column) {
let sortedColumn = this.sortcol[column]
if (sortedColumn === '') {
this.sortcol[column] = 'asc'
} else if (sortedColumn === 'asc') {
this.sortcol[column] = 'desc'
} else if (sortedColumn === 'desc') {
this.sortcol[column] = ''
}
},
},
computed: {
tableHeader() {
return this.columns
},
}
}
</script>
</code></pre>
| [
{
"answer_id": 74420582,
"author": "miguelmtnezz_",
"author_id": 17387554,
"author_profile": "https://Stackoverflow.com/users/17387554",
"pm_score": 2,
"selected": true,
"text": "`"
},
{
"answer_id": 74422607,
"author": "RetiredGeek",
"author_id": 13702221,
"author_profile": "https://Stackoverflow.com/users/13702221",
"pm_score": 2,
"selected": false,
"text": "$NADUArgs = @{\n Name = \"XYZ ABC\"\n SamAccountName = \"xyz.a\"\n UserPrincipalNam = \"xyz.a@ntsh.local\"\n AccountPassword = $secPassword\n Path = \"cn=Users,dc=ntsh,dc=local\"\n Enabled = $true\n PasswordNeverExpires = $true\n CannotChangePassword = $true\n PasswordNotRequired = $false\n ChangePasswordAtLogon = $false\n}\n\nNew-ADUser @NADUArgs\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19329721/"
] |
74,419,964 | <pre><code>function Clothes() {
const { loading, error, data } = useQuery(GET_CLOTHES);
const [products,setProducts] = useState([]);
const [index,setIndex] = useState(0)
useEffect(() => {
if (data) {
setProducts(data.AllItem);
console.log(data.AllItem)
}
},[data,products]);
/*
useEffect(() => {
if(!loading && data){
setProducts(data);
}
}, [loading, data])
*/
if (loading) return 'Loading...'
if (error) return `Error! ${error.message}`
return (
<section className='section'>
<div className='title'>
<h2>
</h2>
{
products?.map((product,index) => {
//const {gallery} = product;
return <img src = {product.gallery} />
})
}
</div>
</section>
)
}
export default Clothes;
</code></pre>
<blockquote>
</blockquote>
<blockquote>
<p><img src="https://i.stack.imgur.com/G31Mf.png" alt="graphql schema" /></p>
</blockquote>
<p>Hello everyone I have a issues with map function. I am getting data from my graphql but when I was trying to fetch them in my console.log I can see just undefined.
Thank you in advance</p>
<pre><code></code></pre>
| [
{
"answer_id": 74420582,
"author": "miguelmtnezz_",
"author_id": 17387554,
"author_profile": "https://Stackoverflow.com/users/17387554",
"pm_score": 2,
"selected": true,
"text": "`"
},
{
"answer_id": 74422607,
"author": "RetiredGeek",
"author_id": 13702221,
"author_profile": "https://Stackoverflow.com/users/13702221",
"pm_score": 2,
"selected": false,
"text": "$NADUArgs = @{\n Name = \"XYZ ABC\"\n SamAccountName = \"xyz.a\"\n UserPrincipalNam = \"xyz.a@ntsh.local\"\n AccountPassword = $secPassword\n Path = \"cn=Users,dc=ntsh,dc=local\"\n Enabled = $true\n PasswordNeverExpires = $true\n CannotChangePassword = $true\n PasswordNotRequired = $false\n ChangePasswordAtLogon = $false\n}\n\nNew-ADUser @NADUArgs\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74419964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17465034/"
] |
74,420,001 | <p>I have some trouble with creating a python class and methods, and I don't know how to resolve it.</p>
<p>I have 2 files, 1 file contains a class with multiple methods. 2 of these are:</p>
<pre><code>def get_price_of(ticker: str) -> float:
URL = 'https://api.kucoin.com/api/v1/market/orderbook/level1?symbol='
r = requests.get(URL + ticker).json()
return r['data']['price']
def get_price_of_list(self, tickers):
prices = {}
for ticker in tickers:
prices[ticker] = self.get_price_of(ticker)
return prices
</code></pre>
<p>So the <code>get_price_of_list</code> method utilises the <code>get_price_of</code> method.</p>
<p>My problem: When accessing the <code>get_price_of_list</code> from another file it now asks for 2 params: self and tickers. However, I don't need it to be an instance so is there any way to convert it to a static method while still being able to access the other function?</p>
| [
{
"answer_id": 74420024,
"author": "The Myth",
"author_id": 15042008,
"author_profile": "https://Stackoverflow.com/users/15042008",
"pm_score": 0,
"selected": false,
"text": "get_price_of()"
},
{
"answer_id": 74420046,
"author": "S.B",
"author_id": 13944524,
"author_profile": "https://Stackoverflow.com/users/13944524",
"pm_score": 3,
"selected": true,
"text": "@staticmethod"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420001",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17318939/"
] |
74,420,049 | <p>I am using Mac OS and since latest rails version the delete key does not work anymore.</p>
<pre><code>❯ rails -v
Rails 7.0.4
❯ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
</code></pre>
<p>When I hit <code>delete</code> instead of removing the char and the current cursor position it inserts <code>^[[3~</code>.</p>
<p>I could not find out how to fix this. The previous rails version did not have this problem.</p>
| [
{
"answer_id": 74436152,
"author": "YvesR",
"author_id": 456266,
"author_profile": "https://Stackoverflow.com/users/456266",
"pm_score": 0,
"selected": false,
"text": "nano ~/.irbrc\nIRB.conf[:USE_READLINE] = true\n"
},
{
"answer_id": 74436759,
"author": "neongrau",
"author_id": 1010746,
"author_profile": "https://Stackoverflow.com/users/1010746",
"pm_score": 2,
"selected": true,
"text": ".irbrc"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/456266/"
] |
74,420,061 | <p>I am having trouble with array mappings. There is an array with data I would like to bind to my component. It looks like the following:</p>
<pre><code>export var arrayObjects: IObjects[] = [
{
name: 'First Object',
icon: 'bi bi-capsule',
subMenu: [
{
name: 'First Sub Object',
path: ''
},
{
name: 'Second Sub Object',
path: ''
}
]
}
]
</code></pre>
<p>The array's type is an interface IObjects which contais name, icon, path and subMenu: IObjects. I need to access the subMenu items in order to create a dynamic menu. Althought, everytime I try to map and call the objects there is no return.</p>
<p>Below you'll be able to see how the mapping I made goes:</p>
<pre><code> <ul>
{ arrayNavCadastros.map((item:any, subMenu: any) =>(
<li className="nav-item">
<i className={item.icon}></i>
<a href="">{item.name}</a>
<ul>
{ subMenu.map((name:any) =>(
<a href="">{name}</a>
))}
</ul>
</li>
)) }
</ul>
</code></pre>
<p>I also tried doing something like <code><a href="">{item.subMenu.name}</a></code> but there is also no return.</p>
<p>I'm new to react but I'm used to do these kind of bindings in Angular, which seems way easier since you should only do a loop inside the other subMenu from the arrayObjects... I would appreaciate any help!</p>
<p><em>Note:</em> when I map the first properties of the arrayObjects (which, from the example, returns 'First Object') it works as well as all the titles for the sub menus.</p>
| [
{
"answer_id": 74420150,
"author": "Ali Sattarzadeh",
"author_id": 11434567,
"author_profile": "https://Stackoverflow.com/users/11434567",
"pm_score": 2,
"selected": true,
"text": " { subMenu.map((name:any) =>(\n <a href=\"\">{name}</a>\n ))}\n"
},
{
"answer_id": 74420209,
"author": "Azzy",
"author_id": 2122822,
"author_profile": "https://Stackoverflow.com/users/2122822",
"pm_score": 0,
"selected": false,
"text": " <ul>\n { arrayNavCadastros.map((item:any, subMenu: any) =>(\n <li \n key={item.id} // key for React to know which item to udpate, when array updated\n className=\"nav-item\"\n >\n <i className={item.icon}></i>\n <a href=\"\">{item.name}</a>\n <ul>\n { subMenu.map((item:any, idx: number) =>(\n <li key={idx}> // key and might need li\n <a href={item.path}>{item.name}</a>\n </li>\n ))}\n </ul>\n </li>\n )) }\n </ul>\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14801612/"
] |
74,420,083 | <p>I have the following data structure</p>
<pre><code>[
{
"id": 3,
"name" "Important Topic 3",
"questions": [array of questions],
"topics: [array of topics],
"parentTopic": {
"id": 2,
"name": "Parent Topic 1",
"parentTopic": {
"id": 1,
"name": "Parent Topic 2",
"parentTopic: null
}
}
},
{
"id": 4,
"name" "Important Topic 4",
"questions": [array of questions],
"topics: [array of topics],
"parentTopic": {
"id": 2,
"name": "Parent Topic 1",
"parentTopic": {
"id": 1,
"name": "Parent Topic 2",
"parentTopic: null
}
}
}
]
</code></pre>
<p>I want to end up with the following</p>
<pre><code>[
{
"id": 1,
"name": "Parent Topic 2",
"topics": [
{
"id": 2,
"name": "Parent Topic 1"
"topics": [
{
"id": 3,
"name: "Important Topic 3",
"questions": [array of questions],
"topics: [array of topics]
},
{
"id": 4,
"name: "Important Topic 4",
"questions": [array of questions],
"topics: [array of topics]
}
]
}
]
}
]
</code></pre>
<p>I have some code which I got also as help from the awesome stackoverflow community, but it only works if I have nested dictionary objects, not lists of dictionaries in an array. Here is the stackoverflow reference - <a href="https://stackoverflow.com/questions/74353771/reverse-nested-tree-in-javascript">Reverse Nested Tree in Javascript</a></p>
<p>I would really appreciate if you could help solve this puzzle :)</p>
| [
{
"answer_id": 74420295,
"author": "Lucasbk38",
"author_id": 20480528,
"author_profile": "https://Stackoverflow.com/users/20480528",
"pm_score": 0,
"selected": false,
"text": "// The json data\nconst jsonData = `[\n {\n \"id\": 3,\n \"name\": \"Important Topic 3\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n },\n {\n \"id\": 4,\n \"name\": \"Important Topic 4\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n }\n]`\n\nconst baseData = JSON.parse(jsonData)\n\n\n// List of all topics (children and parents)\nlet topics = []\n\n// Recursive function to add children elements\nconst listTopics = topic => {\n // Push only if it doesn't already exists to avoid duplicates\n if (!topics.some(e => e.id === topic.id))\n topics.push(topic)\n\n // The recursive part\n if (topic.parentTopic)\n listTopics(topic.parentTopic)\n}\n\n// Ignite\nbaseData.forEach(listTopics)\n\n\n// Runs while none of the topics elements has a parent\n// You can replace it by `topics.length > 1` if you only have one root topic\nwhile (topics.some(e => e.parentTopic)) {\n const parent = topics.shift()\n\n topics = topics.filter(topic => {\n if (topic.parentTopic && topic.parentTopic.id === parent.id) {\n if (!parent.topics)\n parent.topics = []\n\n parent.topics.push(topic)\n return false\n }\n\n return true\n })\n\n topics.push(parent)\n}\n\n// Print the new tree as JSON with some modifications to avoid circulars between parents and children\nconsole.log(JSON.stringify(topics, (key, value) => key === 'parentTopic' ? (value === null ? null : {\n id: value.id\n}) : value, ' '))"
},
{
"answer_id": 74420408,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 2,
"selected": true,
"text": "topics"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2906950/"
] |
74,420,095 | <p>I'm trying to write an Outlook Add-in that deletes an email after the email has been read completely.
The problem is that the read-flag turns true the second we click on it and it doesn't give us much time to read the email.</p>
<p>I tried to delete the email after closing it:</p>
<pre><code>private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
Outlook.MAPIFolder inbox = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
foreach (Outlook.MailItem mail in inbox.Items)
{
((Outlook.ItemEvents_10_Event)mail).Close += new Outlook.ItemEvents_10_CloseEventHandler(MailItem_Close);
}
}
void MailItem_Close(ref bool Cancel)
{
Outlook.MAPIFolder inbox = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items inboxReadItems = inbox.Items.Restrict("[Unread]=false");
foreach (Outlook.MailItem mail in inboxReadItems)
{
mail.Delete();
}
}
</code></pre>
<p>This was the idea i came up with, sometimes it works but most of the times it ends with an error in the <strong>mail.Delete()</strong>:
<strong>The Error:</strong> System.Runtime.InteropServices.COMException: 'The item’s properties and methods cannot be used inside this event procedure.'</p>
| [
{
"answer_id": 74420295,
"author": "Lucasbk38",
"author_id": 20480528,
"author_profile": "https://Stackoverflow.com/users/20480528",
"pm_score": 0,
"selected": false,
"text": "// The json data\nconst jsonData = `[\n {\n \"id\": 3,\n \"name\": \"Important Topic 3\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n },\n {\n \"id\": 4,\n \"name\": \"Important Topic 4\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n }\n]`\n\nconst baseData = JSON.parse(jsonData)\n\n\n// List of all topics (children and parents)\nlet topics = []\n\n// Recursive function to add children elements\nconst listTopics = topic => {\n // Push only if it doesn't already exists to avoid duplicates\n if (!topics.some(e => e.id === topic.id))\n topics.push(topic)\n\n // The recursive part\n if (topic.parentTopic)\n listTopics(topic.parentTopic)\n}\n\n// Ignite\nbaseData.forEach(listTopics)\n\n\n// Runs while none of the topics elements has a parent\n// You can replace it by `topics.length > 1` if you only have one root topic\nwhile (topics.some(e => e.parentTopic)) {\n const parent = topics.shift()\n\n topics = topics.filter(topic => {\n if (topic.parentTopic && topic.parentTopic.id === parent.id) {\n if (!parent.topics)\n parent.topics = []\n\n parent.topics.push(topic)\n return false\n }\n\n return true\n })\n\n topics.push(parent)\n}\n\n// Print the new tree as JSON with some modifications to avoid circulars between parents and children\nconsole.log(JSON.stringify(topics, (key, value) => key === 'parentTopic' ? (value === null ? null : {\n id: value.id\n}) : value, ' '))"
},
{
"answer_id": 74420408,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 2,
"selected": true,
"text": "topics"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491745/"
] |
74,420,110 | <p>I'm working on a Winforms app and I have 5 radio buttons. I need to know which one is checked. Is there a better/more compact way of doing this in C#?</p>
<p>For now I have this:</p>
<pre><code>if (rbtnArgent.Checked)
return "Silver";
else if (rbtnBleuF.Checked)
return "Dark Blue";
else if (rbtnBleuP.Checked)
return "Light Blue";
else if (rbtnJaune.Checked)
return "Yellow";
else
return "Pink";
</code></pre>
<p>It's working but maybe i will need to add more radio buttons to my form in the future...</p>
| [
{
"answer_id": 74420295,
"author": "Lucasbk38",
"author_id": 20480528,
"author_profile": "https://Stackoverflow.com/users/20480528",
"pm_score": 0,
"selected": false,
"text": "// The json data\nconst jsonData = `[\n {\n \"id\": 3,\n \"name\": \"Important Topic 3\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n },\n {\n \"id\": 4,\n \"name\": \"Important Topic 4\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n }\n]`\n\nconst baseData = JSON.parse(jsonData)\n\n\n// List of all topics (children and parents)\nlet topics = []\n\n// Recursive function to add children elements\nconst listTopics = topic => {\n // Push only if it doesn't already exists to avoid duplicates\n if (!topics.some(e => e.id === topic.id))\n topics.push(topic)\n\n // The recursive part\n if (topic.parentTopic)\n listTopics(topic.parentTopic)\n}\n\n// Ignite\nbaseData.forEach(listTopics)\n\n\n// Runs while none of the topics elements has a parent\n// You can replace it by `topics.length > 1` if you only have one root topic\nwhile (topics.some(e => e.parentTopic)) {\n const parent = topics.shift()\n\n topics = topics.filter(topic => {\n if (topic.parentTopic && topic.parentTopic.id === parent.id) {\n if (!parent.topics)\n parent.topics = []\n\n parent.topics.push(topic)\n return false\n }\n\n return true\n })\n\n topics.push(parent)\n}\n\n// Print the new tree as JSON with some modifications to avoid circulars between parents and children\nconsole.log(JSON.stringify(topics, (key, value) => key === 'parentTopic' ? (value === null ? null : {\n id: value.id\n}) : value, ' '))"
},
{
"answer_id": 74420408,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 2,
"selected": true,
"text": "topics"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9282102/"
] |
74,420,117 | <p>I have the following code.</p>
<p>I am trying to sort the values of the first column of the 'happydflist' dataframe in ascending order.</p>
<p>However, the output this gives me includes some values such as '2','3' and '8' that do not fit in with the ascending order theme.</p>
<pre><code>happydflist = happydflist[happydflist.columns[0]]
happydflistnew = happydflist.sort_values(ascending=True)
print(happydflistnew)
12 13
10 19
13 2
11 24
15 3
6 33
24 35
8 36
5 37
25 49
17 49
20 50
26 51
22 52
16 52
18 52
19 52
28 53
27 54
23 54
21 59
9 74
7 75
14 8
Name: 0_happy, dtype: object
</code></pre>
<p>I would be so grateful for a helping hand!</p>
<p>'happydflist' looks like this:</p>
<pre><code>5 37
6 33
7 75
8 36
9 74
10 19
11 24
12 13
13 2
14 8
15 3
16 52
17 49
18 52
19 52
20 50
21 59
22 52
23 54
24 35
25 49
26 51
27 54
28 53
Name: 0_happy, dtype: object
</code></pre>
| [
{
"answer_id": 74420295,
"author": "Lucasbk38",
"author_id": 20480528,
"author_profile": "https://Stackoverflow.com/users/20480528",
"pm_score": 0,
"selected": false,
"text": "// The json data\nconst jsonData = `[\n {\n \"id\": 3,\n \"name\": \"Important Topic 3\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n },\n {\n \"id\": 4,\n \"name\": \"Important Topic 4\",\n \"questions\": [],\n \"topics\": [],\n \"parentTopic\": {\n \"id\": 2,\n \"name\": \"Parent Topic 1\",\n \"parentTopic\": {\n \"id\": 1,\n \"name\": \"Parent Topic 2\",\n \"parentTopic\": null\n }\n }\n }\n]`\n\nconst baseData = JSON.parse(jsonData)\n\n\n// List of all topics (children and parents)\nlet topics = []\n\n// Recursive function to add children elements\nconst listTopics = topic => {\n // Push only if it doesn't already exists to avoid duplicates\n if (!topics.some(e => e.id === topic.id))\n topics.push(topic)\n\n // The recursive part\n if (topic.parentTopic)\n listTopics(topic.parentTopic)\n}\n\n// Ignite\nbaseData.forEach(listTopics)\n\n\n// Runs while none of the topics elements has a parent\n// You can replace it by `topics.length > 1` if you only have one root topic\nwhile (topics.some(e => e.parentTopic)) {\n const parent = topics.shift()\n\n topics = topics.filter(topic => {\n if (topic.parentTopic && topic.parentTopic.id === parent.id) {\n if (!parent.topics)\n parent.topics = []\n\n parent.topics.push(topic)\n return false\n }\n\n return true\n })\n\n topics.push(parent)\n}\n\n// Print the new tree as JSON with some modifications to avoid circulars between parents and children\nconsole.log(JSON.stringify(topics, (key, value) => key === 'parentTopic' ? (value === null ? null : {\n id: value.id\n}) : value, ' '))"
},
{
"answer_id": 74420408,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": 2,
"selected": true,
"text": "topics"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12985497/"
] |
74,420,155 | <p>I'm going through <a href="https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-console?view=vs-2022" rel="nofollow noreferrer">this</a> C# intro tutorial by MS, and in the section "Fix the "format" error" I'm supposed to delete code in the namespace, but I'm not seeing that namespace since I'm in the "top-level statements" mode. How do I reveal the boilerplate code that is underneath?</p>
| [
{
"answer_id": 74420221,
"author": "Lesiak",
"author_id": 1570854,
"author_profile": "https://Stackoverflow.com/users/1570854",
"pm_score": 1,
"selected": false,
"text": "Console.WriteLine(\"Hello World!\");\n"
},
{
"answer_id": 74420443,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18891753/"
] |
74,420,190 | <p>I'm trying to solve a specific error from a library (pycountry_convert) in a code with try / except, but when I use the except to avoid this case it just doesn't work. I've tried so many things to solve this.</p>
<p>Here is the code</p>
<pre><code>import pycountry_convert as pc
def pegacontinente(nomepais):
nomepais = nomepais.replace("-", " ")
e = ['and', 'the']
nomepais = ' '.join([word.capitalize() if word not in e else word for word in nomepais.split()])
country_code = pc.country_name_to_country_alpha2(nomepais, cn_name_format="default")
try:
continent_name = pc.country_alpha2_to_continent_code(country_code)
except Exception as e:
# Special Case: Timor Leste
if e == "Invalid Country Alpha-2 code: \'TL\'":
continent_name = 'AS'
else:
continent_name = 'N/A'
return continent_name
</code></pre>
<p>In the case of Timor Leste, this code returns "N/A", when it's suppose to return 'AS'. I already tried to use "" before quote marks, remove all special characters from the string but it just don't work and I'm getting very frustrated.</p>
<p>I tried to do something like the image below to see if there is any typo at my string or something but it works out of the try/except thing</p>
<p><a href="https://i.stack.imgur.com/PLIgy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PLIgy.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/Zg1iw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zg1iw.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74420221,
"author": "Lesiak",
"author_id": 1570854,
"author_profile": "https://Stackoverflow.com/users/1570854",
"pm_score": 1,
"selected": false,
"text": "Console.WriteLine(\"Hello World!\");\n"
},
{
"answer_id": 74420443,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491830/"
] |
74,420,233 | <p>The string is:
<code>x = 'ABBA'</code></p>
<p>whenever I use this code:
<code>x = 'ABBA' x = ''.join(set(x)) print(x)</code></p>
<p>It results in:
<code>BA</code>
but I want it to be the first letters instead of the second letters:
<code>AB</code></p>
<p>Is there any way that I can do it without using reverse function?</p>
| [
{
"answer_id": 74420221,
"author": "Lesiak",
"author_id": 1570854,
"author_profile": "https://Stackoverflow.com/users/1570854",
"pm_score": 1,
"selected": false,
"text": "Console.WriteLine(\"Hello World!\");\n"
},
{
"answer_id": 74420443,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 0,
"selected": false,
"text": "Program.cs"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20440485/"
] |
74,420,235 | <p>I don't really have code for this problem. But I will try my best to actually explain everything.</p>
<p><a href="https://i.stack.imgur.com/nQVBp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nQVBp.png" alt="Example" /></a>
alright, say you are scraping a website, and in the website there are 3 different links and you want to scrape what is inside each and everyone one of them without having to manually do it. Is this possible for just BeautifulSoup and the Requests library? Or would you have to use another library, for e.g scrapy.</p>
<p>If you want you can try it on this website: <a href="https://www.bleepingcomputer.com/" rel="nofollow noreferrer">https://www.bleepingcomputer.com/</a>
What I am trying to achieve is scrape the website, and what is inside the links at the same time.</p>
<p>If it's not possible to do it with only requests & Beautifulsoup feel free to use scrapy as well.</p>
| [
{
"answer_id": 74420495,
"author": "Samurai6465",
"author_id": 20287896,
"author_profile": "https://Stackoverflow.com/users/20287896",
"pm_score": 0,
"selected": false,
"text": "<li href=“https://google.com > Site 1 </li> "
},
{
"answer_id": 74497640,
"author": "Driftr95",
"author_id": 6146136,
"author_profile": "https://Stackoverflow.com/users/6146136",
"pm_score": 0,
"selected": false,
"text": "linkTreeMapper('https://www.bleepingcomputer.com/', None, 1)"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491929/"
] |
74,420,254 | <p>I have a sql query I'm executing that I'm passing variables into. In the current context I'm passing the parameter values in as f strings, but this query is vulnerable to sql injection. I know there is a method to use a stored procedure and restrict permissions on the user executing the query. But is there a way to avoid having to go the stored procedure route and perhaps modify this function to be secure against SQL Injection?</p>
<pre><code>I have the below query created to execute within a python app.
</code></pre>
<pre><code>def sql_gen(tv, kv, join_kv, col_inst, val_inst, val_upd):
sqlstmt = f"""
IF NOT EXISTS (
SELECT *
FROM {tv}
WHERE {kv} = {join_kv}
)
INSERT {tv} (
{col_inst}
)
VALUES (
{val_inst}
)
ELSE
UPDATE {tv}
SET {val_upd}
WHERE {kv} = {join_kv};
"""
engine = create_engine(f"mssql+pymssql://{username}:{password}@{server}/{database}")
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.execute(sqlstmt)
connection.commit()
cursor.close()
</code></pre>
<pre><code></code></pre>
| [
{
"answer_id": 74420495,
"author": "Samurai6465",
"author_id": 20287896,
"author_profile": "https://Stackoverflow.com/users/20287896",
"pm_score": 0,
"selected": false,
"text": "<li href=“https://google.com > Site 1 </li> "
},
{
"answer_id": 74497640,
"author": "Driftr95",
"author_id": 6146136,
"author_profile": "https://Stackoverflow.com/users/6146136",
"pm_score": 0,
"selected": false,
"text": "linkTreeMapper('https://www.bleepingcomputer.com/', None, 1)"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20152722/"
] |
74,420,276 | <p>I have a problem. I would like to use <a href="https://github.com/Fintasys/emoji_picker_flutter" rel="nofollow noreferrer">emoji_picker_flutter</a>. This should be displayed under the TextInputField but is not displayed. What is the reason for this? Do I have to implement it differently or what is the reason? I tried to add the <code>Config</code>, but it did not change anything.</p>
<pre class="lang-dart prettyprint-override"><code>import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/foundation.dart' as foundation;
import '../Model/ChatModel.dart';
class IndidivdualPage extends StatefulWidget {
final ChatModel chatModel;
const IndidivdualPage({Key? key, required this.chatModel}) : super(key: key);
@override
_IndividualPageState createState() => _IndividualPageState();
}
class _IndividualPageState extends State<IndidivdualPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
leadingWidth: 70,
titleSpacing: 0,
leading: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.arrow_back, size: 24,),
CircleAvatar(
child: SvgPicture.asset(widget.chatModel.isGroup ? "assets/account-group.svg" : "assets/account.svg",
color: Colors.white, height: 34, width: 34),
radius: 20,
backgroundColor: Colors.lightBlue,
),
],
),
),
title: InkWell(
onTap: () {},
child: Container(
margin: EdgeInsets.all(6),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.chatModel.name, style: TextStyle(
fontSize: 18.5,
fontWeight: FontWeight.bold
),),
Text("last seend today at 15:03", style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal
),)
],
),
),
),
actions: [
IconButton(onPressed: () {}, icon: Icon(Icons.videocam)),
IconButton(onPressed: () {}, icon: Icon(Icons.call)),
PopupMenuButton<String>(
onSelected: (value){
print(value);
},
itemBuilder: (BuildContext context){
return [
PopupMenuItem(child: Text("View Contact"), value:"View Contact",),
];
})
],
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
ListView(),
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
children: [
Container(
width: MediaQuery.of(context).size.width - 60,
child:
Card(
margin: EdgeInsets.only(left: 2, right: 2, bottom: 8),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
child: TextFormField(
textAlignVertical: TextAlignVertical.center,
keyboardType: TextInputType.multiline,
maxLines: 5,
minLines: 1,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Send a message",
prefixIcon: IconButton(icon: Icon(Icons.emoji_emotions), onPressed: () { },),
suffixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.attach_file)),
IconButton(onPressed: () {}, icon: Icon(Icons.camera_alt)),
],
),
contentPadding: EdgeInsets.all(5),
),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8, right: 5, left: 2),
child: CircleAvatar(
radius: 25,
backgroundColor: Colors.lightBlue,
child: IconButton(icon: Icon(Icons.mic),color: Colors.white, onPressed: () {},),
),
),
],
),
emojiSelect(),
],
)
)
],
),
),
);
}
Widget emojiSelect() {
return EmojiPicker(
onEmojiSelected: (Category? category, Emoji? emoji) {
print(emoji);
},
onBackspacePressed: () {
// Do something when the user taps the backspace button (optional)
}, // pass here the same [TextEditingController] that is connected to your input field, usually a [TextFormField]
config: Config(
columns: 7,
emojiSizeMax: 32 * (Platform.isIOS ? 1.30 : 1.0), // Issue: https://github.com/flutter/flutter/issues/28894
verticalSpacing: 0,
horizontalSpacing: 0,
gridPadding: EdgeInsets.zero,
initCategory: Category.RECENT,
bgColor: Color(0xFFF2F2F2),
indicatorColor: Colors.blue,
iconColor: Colors.grey,
iconColorSelected: Colors.blue,
backspaceColor: Colors.blue,
skinToneDialogBgColor: Colors.white,
skinToneIndicatorColor: Colors.grey,
enableSkinTones: true,
showRecentsTab: true,
recentsLimit: 28,
noRecents: const Text(
'No Recents',
style: TextStyle(fontSize: 20, color: Colors.black26),
textAlign: TextAlign.center,
), // Needs to be const Widget
loadingIndicator: const SizedBox.shrink(), // Needs to be const Widget
tabIndicatorAnimDuration: kTabScrollDuration,
categoryIcons: const CategoryIcons(),
buttonMode: ButtonMode.MATERIAL,
),
);
}
}
</code></pre>
| [
{
"answer_id": 74420505,
"author": "eamirho3ein",
"author_id": 10306997,
"author_profile": "https://Stackoverflow.com/users/10306997",
"pm_score": 3,
"selected": true,
"text": "height"
},
{
"answer_id": 74420556,
"author": "Karzel",
"author_id": 8713068,
"author_profile": "https://Stackoverflow.com/users/8713068",
"pm_score": 1,
"selected": false,
"text": "SizedBox"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17136258/"
] |
74,420,282 | <p>I have Id, event_name, Timestamp columns.</p>
<p>I will concatenate last 5 event of every id.</p>
<p>I've used multiple WITH and JOIN to acquaire this. But BigQuery took so much time to compute.</p>
<p>Also this feels like such a bad practice. What can i use as an alternative?</p>
<p>My table looks something like this</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">event_name</th>
<th style="text-align: center;">timestamp</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">a</td>
<td style="text-align: center;">2022-10-21 12:10:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">b</td>
<td style="text-align: center;">2022-10-21 12:12:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">c</td>
<td style="text-align: center;">2022-10-21 12:15:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">d</td>
<td style="text-align: center;">2022-10-21 12:16:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">e</td>
<td style="text-align: center;">2022-10-21 12:28:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">f</td>
<td style="text-align: center;">2022-10-21 12:45:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">c</td>
<td style="text-align: center;">2022-10-21 10:12:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">f</td>
<td style="text-align: center;">2022-10-21 11:12:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">b</td>
<td style="text-align: center;">2022-10-21 11:25:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">a</td>
<td style="text-align: center;">2022-10-21 11:26:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">f</td>
<td style="text-align: center;">2022-10-21 15:32:00 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">c</td>
<td style="text-align: center;">2022-10-21 15:32:48 UTC</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">f</td>
<td style="text-align: center;">2022-10-21 15:36:00 UTC</td>
</tr>
</tbody>
</table>
</div>
<p>My code looks like this.</p>
<pre><code>WITH a AS ( id, timestamp, event_name, row_number() over(partition by ID ORDER BY timestamp DESC) as row_n
FROM my_table),
WITH b AS (id, timestamp, event_name, row_n
FROM a
WHERE row_n <= 5),
e1 AS(
SELECT ID, timestamp AS ev1
FROM b
WHERE row_n = 1),
e2 AS(
SELECT ID, timestamp AS ev2
FROM b
WHERE row_n = 2),
e3 AS(
SELECT ID, timestamp AS ev3
FROM b
WHERE row_n = 3),
e4 AS(
SELECT ID, timestamp AS ev4
FROM b
WHERE row_n = 4),
e5 AS(
SELECT ID, timestamp AS ev5
FROM b
WHERE row_n = 5),
concat_prep AS(
SELECT b.ID, ev1,ev2,ev3,ev4,ev5
FROM b
LEFT JOIN e1
ON b.ID = e1.ID
LEFT JOIN e2
ON e1.ID = e2.ID
LEFT JOIN e3
ON e2.ID = e3.ID
LEFT JOIN e4
ON e3.ID = e4.ID
LEFT JOIN e5
ON e4.ID= e5.ID)
SELECT ID, concat(ev1,',',ev2,',',ev3,',',ev4,',',ev5) as concatt
FROM concat_prep
GROUP BY ID ,concat(ev1,',',ev2,',',ev3,',',ev4,',',ev5)
</code></pre>
<p>And my output should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">concat</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">A1</td>
<td style="text-align: center;">f,e,d,c,b</td>
</tr>
<tr>
<td style="text-align: center;">B2</td>
<td style="text-align: center;">f,c,f,a,b</td>
</tr>
</tbody>
</table>
</div>
<p>How can I optimize it? (I've already filtered by date) this query is part of a bigger query.</p>
| [
{
"answer_id": 74420553,
"author": "Samuel",
"author_id": 16529576,
"author_profile": "https://Stackoverflow.com/users/16529576",
"pm_score": 1,
"selected": false,
"text": "group by"
},
{
"answer_id": 74421183,
"author": "Barbaros Özhan",
"author_id": 5841306,
"author_profile": "https://Stackoverflow.com/users/5841306",
"pm_score": 0,
"selected": false,
"text": "ROW_NUMBER()"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18296671/"
] |
74,420,314 | <p>I have a variable <code>a = [0.129, 0.369, 0.758, 0.012, 0.925]</code>. I want to transform this variable into a bucketed variable. What I mean by this is explained below.</p>
<p><code>min_bucket_value, max_bucket_value = 0, 1</code> (Can be anything, for example, 0 to 800, but the min value is always going to be 0)</p>
<p><code>num_divisions = 10</code> (For this example I've taken 10, but it can be higher as well, like 80 divisions instead of 10)</p>
<p>Bucket/division ranges are as shown below.</p>
<pre><code>0 - 0.1 -> 0
0.1 - 0.2 -> 1
0.2 - 0.3 -> 2
0.3 - 0.4 -> 3
0.4 - 0.5 -> 4
0.5 - 0.6 -> 5
0.6 - 0.7 -> 6
0.7 - 0.8 -> 7
0.8 - 0.9 -> 8
0.9 - 1.0 -> 9
</code></pre>
<p>so, <code>transformed_a = [1, 3, 7, 0, 9]</code></p>
<p>So it's like I divide <code>min_bucket_value, max_bucket_value</code> in <code>num_divisions </code> different ranges/buckets and then transform original <code>a</code> to tell which bucket it lies in</p>
<p>I've tried creating <code>torch.linspace(min_bucket_value, max_bucket_value, num_divisions)</code>, but not sure how to move forward and map it to a range so that I can get the bucket index to which it belongs to</p>
<p>Can you guys please help</p>
<p><strong>EDIT</strong></p>
<p>There's an extension to this problem.</p>
<p>Let's say that we've got <code>a = [127, 362, 799]</code> and I want to create two buckets. One is a coarse bucket, so <code>a_transform = [12, 36, 89]</code>, but what if I want a fine bucket as well so that my second transformation becomes <code>a_fine_transform = [7, 2, 9]</code>.</p>
<p>Sub-range index within the range. Basically, coarse division has 80 buckets (giving 127 in 12th bucket) and then the fine bucket which has 10 divisions which tells us that 127 lies in 12th coarse bucket and 7th fine bucket</p>
<p><code>a</code> can be in float as well. eg, <code>a = [127.36, 362.456, 789.646]</code>.</p>
<p>so <code>a_coarse_transform = [12, 36, 78]</code> & <code>a_fine_transform = [7, 2, 6]</code></p>
<p>where <code>min_bucket_value, max_bucket_value, num_coarse_divisions, num_fine_divisions = 0, 1, 80, 10</code></p>
| [
{
"answer_id": 74420511,
"author": "Bob",
"author_id": 12750353,
"author_profile": "https://Stackoverflow.com/users/12750353",
"pm_score": 2,
"selected": false,
"text": "0 < a1 < 1"
},
{
"answer_id": 74444715,
"author": "hellblazer",
"author_id": 11938714,
"author_profile": "https://Stackoverflow.com/users/11938714",
"pm_score": 2,
"selected": true,
"text": "a1 = (a - min_bucket_value) / (max_bucket_value - min_bucket_value)\n\na_coarse_transform, r = ((a1 * coarse_divisions)//1).type(torch.long), (a1 * coarse_divisions)%1\na_fine_transform, r = ((r * fine_divisions)//1).type(torch.long), (r * fine_divisions)%1\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11971761/"
] |
74,420,346 | <p>I have an issue that should have a very straight forward solution but I can't seem to find it. Basically I have observations nested within district*county but their values of candidate are wrong and the information for a single candidate is spread through multiple columns. The original dataset has the same problem but instead of only four non.grouping variables it has 500+.</p>
<p>But here it's what it looks like now:</p>
<pre><code>current_df
county district candidate name votes party
1 E100 1 1 john NA <NA>
2 E100 1 2 <NA> 100 <NA>
3 E100 1 3 <NA> NA D
4 E101 2 4 maria NA <NA>
5 E101 2 5 <NA> 200 <NA>
6 E101 2 6 <NA> NA I
7 E202 1 7 tom NA <NA>
8 E202 1 8 <NA> 78 <NA>
9 E202 1 9 <NA> NA R
10 E204 3 10 jose NA <NA>
11 E204 3 11 <NA> 120 <NA>
12 E204 3 12 <NA> NA <NA>
</code></pre>
<p>And this is what I'd want to have:</p>
<pre><code>target_df <- data.frame(county = c("E100", "E101","E202", "E204"),
district= c(1, 2, 1, 3),
candidate = c(1, 1, 2, 1),
name = c("john","maria",
"tom", "jose"),
votes = c(100,
200,
78,
120),
party = c( "D",
"I",
"R",
NA))
</code></pre>
<p>Again, if there is a solution that doesn't build on the fact that there are only 4 variables other than county and district that's ideal because I have many in many dataframe. For reference, <code>candidate</code> is just the ordered indicator of the candidate within each district.</p>
<p>Also, some rows, as is the case of that with <code>candidate == "jose"</code> in <code>target_df</code> have NA for their party value. This is just a function of the data's context.</p>
<p>I've tried way to many things and can't still find something doing it well. Any pointers very welcome, thanks!</p>
| [
{
"answer_id": 74420436,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "candidate"
},
{
"answer_id": 74420607,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 1,
"selected": false,
"text": "candidate"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13311198/"
] |
74,420,379 | <p>I'm trying to upload a CSV file to this website: <a href="https://maalaei97-test3.hf.space/?__theme=light" rel="nofollow noreferrer">https://maalaei97-test3.hf.space/?__theme=light</a> using selenium. I tried to find elements by XPath and Partial_link_text but none of them worked.</p>
<p>Here is the code I used:</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.implicitly_wait(0.5)
driver.maximize_window()
driver.get("https://maalaei97-test3.hf.space/?__theme=light")
#to identify element
s = driver.find_element(By.XPATH, "//input[@type='file']")
#file path specified with send_keys
s.send_keys("F:/elmo sanat/thesis/design/pythonProject/df.csv")
</code></pre>
<p>And this is the error I receive:</p>
<pre><code>Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='file']"}
</code></pre>
| [
{
"answer_id": 74420422,
"author": "Zed Wong",
"author_id": 17259882,
"author_profile": "https://Stackoverflow.com/users/17259882",
"pm_score": 0,
"selected": false,
"text": "s = driver.find_element(By.CLASS_NAME, \"css-yxxalb edgvbvh9\")\n"
},
{
"answer_id": 74421102,
"author": "AbiSaran",
"author_id": 7671727,
"author_profile": "https://Stackoverflow.com/users/7671727",
"pm_score": 0,
"selected": false,
"text": "driver.implicitly_wait(10)\n"
},
{
"answer_id": 74421298,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 2,
"selected": true,
"text": "WebDriverWait"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20486634/"
] |
74,420,409 | <p>I have a repayment table that looks like this below,</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>cus_id</th>
<th>due_date</th>
<th>principal</th>
<th>disbursed_date</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>01-01-2022</td>
<td>10</td>
<td>01-11-2021</td>
</tr>
<tr>
<td>1</td>
<td>01-02-2022</td>
<td>10</td>
<td>01-11-2021</td>
</tr>
<tr>
<td>1</td>
<td>01-03-2022</td>
<td>10</td>
<td>01-11-2021</td>
</tr>
<tr>
<td>2</td>
<td>15-03-2022</td>
<td>20</td>
<td>15-02-2022</td>
</tr>
<tr>
<td>1</td>
<td>01-04-2022</td>
<td>10</td>
<td>01-11-2021</td>
</tr>
<tr>
<td>3</td>
<td>01-04-2022</td>
<td>15</td>
<td>20-03-2022</td>
</tr>
<tr>
<td>2</td>
<td>15-04-2022</td>
<td>20</td>
<td>15-02-2022</td>
</tr>
<tr>
<td>3</td>
<td>01-05-2022</td>
<td>15</td>
<td>20-03-2022</td>
</tr>
<tr>
<td>2</td>
<td>30-05-2022</td>
<td>20</td>
<td>15-02-2022</td>
</tr>
<tr>
<td>1</td>
<td>30-05-2022</td>
<td>10</td>
<td>01-11-2021</td>
</tr>
<tr>
<td>3</td>
<td>01-06-2022</td>
<td>15</td>
<td>20-03-2022</td>
</tr>
<tr>
<td>2</td>
<td>15-06-2022</td>
<td>20</td>
<td>15-02-2022</td>
</tr>
<tr>
<td>2</td>
<td>30-06-2022</td>
<td>20</td>
<td>15-02-2022</td>
</tr>
<tr>
<td>3</td>
<td>01-07-2022</td>
<td>55</td>
<td>20-03-2022</td>
</tr>
</tbody>
</table>
</div>
<blockquote>
<p>One can <strong>pay any amount</strong> on <strong>any day of the month</strong>, there can also be <strong>2 payments</strong> by the <strong>same customer</strong> within <strong>one month</strong>.
<em><strong>disbursed_day</strong></em> is the day of disbursement (could be any day before 1st EMI) and is the same for each cus_id. The total amount for each customer is the <code>sum(principal) group by cus_id</code> i.e. for customers 1, 2, and 3 total amount is respectively 50, 100, and 100.</p>
</blockquote>
<p>I want to calculate the outstanding as of each <em><strong>due_date</strong></em>. My expected results would look like below,</p>
<pre><code>| date_as_of | outstanding | |
| ------------ | ----------- | ------------------------------------------ |
| 01-01-2022 | 40 | -- total outstanding as on 50, paid 10 |
| 01-02-2022 | 30 | -- cus1 paid emi 10 |
| 01-03-2022 | 120 | -- amt for 2 disbursed on 15-02, 20+100 |
| 15-03-2022 | 100 | -- cus2 paid emi of 20 |
| 01-04-2022 | 175 | -- amt for 3 disbursed on 20-03, 10+80+85 |
| 15-04-2022 | 155 | -- cus2 paid emi of 20 |
| 01-05-2022 | 140 | -- cus3 paid emi of 15 |
| 30-05-2022 | 110 | |
| 01-06-2022 | 95 | |
| 15-06-2022 | 75 | |
| 30-06-2022 | 55 | |
| 01-07-2022 | 0 | |
</code></pre>
<blockquote>
<p>For 1st Feb EMI, cus1 paid 2 EMI of 10, so outstanding as of 1st Feb will be 50-(10+10) = 30.</p>
</blockquote>
<blockquote>
<p>For 1st Mar EMI, cus1 paid 3 EMI of 10. Cus2 disbursed amt of 100 on 15th of Feb, so outstanding as of 1st Mar will be (50-(10+10+10))+100 = 120</p>
</blockquote>
<blockquote>
<p>On 15th Mar, cus 2 paid EMI of 20, so outstanding is (50-(10+10+10))+ (100-20) = 100</p>
</blockquote>
<blockquote>
<p>For 1st Apr EMI, cus1 paid 4 EMI of 10. Cus 2 paid 1 EMI of 20 (on 15th of March). Amt for cus3 disbursed on 20th March, but also had paid EMI of 15. So outstanding will be (50-(10+10+10+10)) + (100-20) + (100-15) = 175</p>
</blockquote>
<p>This is how the calculation of outstanding should be. I was trying this approach below,</p>
<pre><code>select *, (osp_as_on - principal) balance from (
select due_date, principal, sum(net_repayment) over(order by due_date desc) osp_as_on from (
select due_date, principal, sum(principal) net_repayment
from repayments
group by 1
) t1
) t2 order by 1;
</code></pre>
<p>But my approach isn't correct as my query isn't considering the <em><strong>disbursed_date</strong></em>, as only after the disbursement date, I've to consider the remaining balance from the total to calculate the correct outstanding as of due date.</p>
<p>Any help from the community would be greatly appreciated. I'm using MySQL8.0.</p>
| [
{
"answer_id": 74420422,
"author": "Zed Wong",
"author_id": 17259882,
"author_profile": "https://Stackoverflow.com/users/17259882",
"pm_score": 0,
"selected": false,
"text": "s = driver.find_element(By.CLASS_NAME, \"css-yxxalb edgvbvh9\")\n"
},
{
"answer_id": 74421102,
"author": "AbiSaran",
"author_id": 7671727,
"author_profile": "https://Stackoverflow.com/users/7671727",
"pm_score": 0,
"selected": false,
"text": "driver.implicitly_wait(10)\n"
},
{
"answer_id": 74421298,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 2,
"selected": true,
"text": "WebDriverWait"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8551281/"
] |
74,420,515 | <p>Suppose the table is:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>employee_id</th>
<th>branch</th>
<th>role</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>A</td>
<td>admin</td>
</tr>
<tr>
<td>2</td>
<td>A</td>
<td>engineer</td>
</tr>
<tr>
<td>3</td>
<td>A</td>
<td>finance</td>
</tr>
<tr>
<td>4</td>
<td>B</td>
<td>admin</td>
</tr>
<tr>
<td>5</td>
<td>B</td>
<td>finance</td>
</tr>
<tr>
<td>6</td>
<td>C</td>
<td>engineer</td>
</tr>
</tbody>
</table>
</div>
<p>How can I find the departments that do not have all the roles?</p>
<p>In this example:</p>
<ul>
<li>Department A has all the roles.</li>
<li>Department B does not have engineer role.</li>
<li>Department C does not have admin and finance roles.</li>
</ul>
<p>What would be the SQL query to get this result?</p>
<p>Ideally, the output should be</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>branch</th>
<th>role</th>
</tr>
</thead>
<tbody>
<tr>
<td>B</td>
<td>engineer</td>
</tr>
<tr>
<td>C</td>
<td>admin</td>
</tr>
<tr>
<td>C</td>
<td>finance</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74420422,
"author": "Zed Wong",
"author_id": 17259882,
"author_profile": "https://Stackoverflow.com/users/17259882",
"pm_score": 0,
"selected": false,
"text": "s = driver.find_element(By.CLASS_NAME, \"css-yxxalb edgvbvh9\")\n"
},
{
"answer_id": 74421102,
"author": "AbiSaran",
"author_id": 7671727,
"author_profile": "https://Stackoverflow.com/users/7671727",
"pm_score": 0,
"selected": false,
"text": "driver.implicitly_wait(10)\n"
},
{
"answer_id": 74421298,
"author": "Prophet",
"author_id": 3485434,
"author_profile": "https://Stackoverflow.com/users/3485434",
"pm_score": 2,
"selected": true,
"text": "WebDriverWait"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/98267/"
] |
74,420,530 | <p>I'm writing a Kotlin Multiplatform project in Android Studio. As a result, I have multiple sourceSets configured in the project but some of them are empty. Removing them from the Gradle build is not possible as they are required for building the project. Is there a way to hide them from being displayed by the IDE?</p>
<p>(Android Studio Dolphin | 2021.3.1 Patch 1)</p>
<p><a href="https://i.stack.imgur.com/wRsxB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wRsxB.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74470502,
"author": "Sparko Sol",
"author_id": 20407048,
"author_profile": "https://Stackoverflow.com/users/20407048",
"pm_score": 1,
"selected": false,
"text": "@Target(AnnotationTarget.CLASS)\n@Retention(AnnotationRetention.SOURCE)\nannotation class HideEmptySourceSet\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420530",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2318632/"
] |
74,420,570 | <p>I have the following Github action step which by design should do semantic release and at the end update "version" field in package.json but failed with error below.</p>
<p>I tried to use all the latest version but error remains, any ideas?</p>
<pre><code>semantic-versioning:
if: inputs.infra_dir != 'prod'
runs-on: ${{ inputs.runs_on }}
steps:
- name: ⤵️ Checkout repo
uses: actions/checkout@v3
- name: "⚙️ Setup Node"
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Action For Semantic Release
uses: cycjimmy/semantic-release-action@v3.2.0
with:
semantic_version: 19.0.5
branch: "main"
extra_plugins: |
@semantic-release/changelog@6
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
</code></pre>
<p>package.json:</p>
<pre><code>{
"name": "app",
"version": "0.1.0",
"release": {
"branches": ["master", "main", "SemVer"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/changelog",
{
"changelogFile": "docs/CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": ["docs/CHANGELOG.md"]
}
]
]
}
</code></pre>
<p>}</p>
<p>The log and the error <strong>Error: Cannot find module '../lib/cli.js'</strong> at line #63</p>
<pre><code>Acquiring 16.18.0
[semantic-release] [@semantic-release/npm] › ℹ Write version 1.1.0 to package.json in /home/ec2-user/actions-runner/_work/test
59 node:internal/modules/cjs/loader:936
60 throw err;
63 Error: Cannot find module '../lib/cli.js'
64 Require stack:
65 - /home/ec2-user/actions-runner/externals.2.299.1/node16/bin/npm
66 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
67 at Function.Module._load (node:internal/modules/cjs/loader:778:27)
68 at Module.require (node:internal/modules/cjs/loader:1005:19)
69 at require (node:internal/modules/cjs/helpers:102:18)
70 at Object.<anonymous> (/home/ec2-user/actions runner/externals.2.299.1/node16/bin/npm:2:1)
71 at Module._compile (node:internal/modules/cjs/loader:1101:14)
72 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
73 at Module.load (node:internal/modules/cjs/loader:981:32)
74 at Function.Module._load (node:internal/modules/cjs/loader:822:12)
75 at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
76 code: 'MODULE_NOT_FOUND',
77 requireStack: [ '/home/ec2-user/actions-runner/externals.2.299.1/node16/bin/npm' ]
78 }
79 [7:07:42 AM] [semantic-release] › ✖ Failed step "prepare" of plugin "@semantic-release/npm"
80 [7:07:42 AM] [semantic-release] › ✖ An error occurred while running semantic-release: Error: Command failed with exit code 1: npm version 1.1.0 --userconfig /tmp/5959228743ee200b6bb8b24654dabd8f/.npmrc --no-git-tag-version --allow-same-version
81 node:internal/modules/cjs/loader:936
</code></pre>
| [
{
"answer_id": 74470502,
"author": "Sparko Sol",
"author_id": 20407048,
"author_profile": "https://Stackoverflow.com/users/20407048",
"pm_score": 1,
"selected": false,
"text": "@Target(AnnotationTarget.CLASS)\n@Retention(AnnotationRetention.SOURCE)\nannotation class HideEmptySourceSet\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/354255/"
] |
74,420,577 | <p>similar topics have been opened, but I couldn't find exactly what I wanted and couldn't solve it myself.</p>
<p>What I want is to call my functions from an array in a loop, but the values that each function needs are different. Sending all values to all functions (they won't use what they don't need after all) or coding all 20 of my functions with if else is a solution but it seems like there must be a more efficient way.
Is there a solution? Thanks in advance for your help.</p>
<pre><code> def a_func(x1):
return x1
def b_func(y1):
return y1
mylist=['A','B']
dictionary = {'A': a_func, 'B':b_func}
def main(x1,y1):
for each in mylist:
value=dictionary[each](???) #x1 or x2 how can i send different variable according to each func
</code></pre>
<p>Actually, all the answers were indirect solutions, but ILS's comment was working in different multi-functions, I needed to be more specific in the question, thank you very much, I understood the logic.</p>
| [
{
"answer_id": 74420639,
"author": "SadeghPouriyan",
"author_id": 15154700,
"author_profile": "https://Stackoverflow.com/users/15154700",
"pm_score": 1,
"selected": false,
"text": " def a_func(x1):\n return x1\n\n def b_func(y1):\n return y1\n\n funcs = [a_func, b_func]\n\n def main(inputs):\n x1 = 0\n y1 = 1\n inputs = [x1, y1] # suppose it is given from out of this function\n func_outputs = []\n for i in range(len(funcs)):\n func_output = funcs[i](inputs[i])\n func_outputs.append(func_output)\n print(func_output)\n"
},
{
"answer_id": 74420648,
"author": "Edo Akse",
"author_id": 9267296,
"author_profile": "https://Stackoverflow.com/users/9267296",
"pm_score": 1,
"selected": false,
"text": "**kwargs"
},
{
"answer_id": 74420707,
"author": "ILS",
"author_id": 10017662,
"author_profile": "https://Stackoverflow.com/users/10017662",
"pm_score": 3,
"selected": true,
"text": "a_func"
},
{
"answer_id": 74420725,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 1,
"selected": false,
"text": "a_func"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11598428/"
] |
74,420,592 | <p>I wonder, if there is a more straightforward solution to the following problem. I want to separate the values in numeric columns by sign and a condition related to a categorical column.</p>
<p>If this is my data frame:</p>
<pre><code>library(tidyverse)
a <- tribble(
~category , ~val ,
'A' , 1 ,
'A' , -1 ,
'B' , -2 ,
'C' , 1 ,
'Z' , 3 ,
'Z' , -4
)
</code></pre>
<p>I want to create four new columns with positive and negativ values, if the category != 'Z' and positive and negative values if category == 'Z.</p>
<p>This code produces the desired result:</p>
<pre><code>a %>%
mutate(good = if_else(category != 'Z' & val >= 0 , val , 0) ,
bad = if_else(category != 'Z' & val < 0 , val , 0) ,
reserve = if_else(category == 'Z' & val >= 0 , val , 0) ,
risk = if_else(category == 'Z' & val < 0 , val , 0))
</code></pre>
<p>But as I have many category and value columns and a lot of rules to separate them, I would end up with a serious amount of if-else-conditions. So, does somebody know a more straightforward solution?</p>
| [
{
"answer_id": 74420690,
"author": "Santiago",
"author_id": 13507658,
"author_profile": "https://Stackoverflow.com/users/13507658",
"pm_score": 1,
"selected": false,
"text": "val"
},
{
"answer_id": 74420743,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 3,
"selected": true,
"text": "library(tidyverse)\n\na |>\n mutate(grp = c(\"bad\", \"good\", \"risk\", \"reserve\")[\n (val>0) + (category == \"Z\") + (val<0 & category == \"Z\") + (val>0 & category == \"Z\") +1\n ],\n id = row_number()) |>\n pivot_wider(names_from = grp, values_from = val, values_fill = 0) |>\n select(-id)\n#> # A tibble: 6 x 5\n#> category good bad reserve risk\n#> <chr> <dbl> <dbl> <dbl> <dbl>\n#> 1 A 1 0 0 0\n#> 2 A 0 -1 0 0\n#> 3 B 0 -2 0 0\n#> 4 C 1 0 0 0\n#> 5 Z 0 0 3 0\n#> 6 Z 0 0 0 -4\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12052802/"
] |
74,420,598 | <p>I am using GNU Make on Linux. Here is my Makefile.</p>
<pre><code>foo:
printf '\x41\n'
bar:
printf '\x41\n' | cat
</code></pre>
<p>Here is the output:</p>
<pre><code>$ make foo
printf '\x41\n'
A
$ make bar
printf '\x41\n' | cat
\x41
</code></pre>
<p>The shell being used is Dash:</p>
<pre><code># ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Sep 12 04:41 /bin/sh -> dash
</code></pre>
<p>Why does the output become different when I pipe through <code>cat</code>?</p>
<p>Strangely, <code>dash</code> itself has a different behavior when I execute the commands directly on it.</p>
<pre><code>$ printf '\x41\n'
\x41
$ printf '\x41\n' | cat
\x41
</code></pre>
<p>What is going on here? Why is the output of the commands in Makefile inconsistent with that in Dash?</p>
| [
{
"answer_id": 74420824,
"author": "Arkadiusz Drabczyk",
"author_id": 3691891,
"author_profile": "https://Stackoverflow.com/users/3691891",
"pm_score": 1,
"selected": false,
"text": "$ strace -f make\n(...)\n[pid 1396] execve(\"/usr/bin/printf\", [\"printf\", \"\\\\x41\\\\n\"], 0x56453618b880 /* 14 vars */ <unfinished ...>\n"
},
{
"answer_id": 74421875,
"author": "MadScientist",
"author_id": 939557,
"author_profile": "https://Stackoverflow.com/users/939557",
"pm_score": 3,
"selected": true,
"text": "\\xNN"
},
{
"answer_id": 74425499,
"author": "Claudio",
"author_id": 7711283,
"author_profile": "https://Stackoverflow.com/users/7711283",
"pm_score": 1,
"selected": false,
"text": "cat"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1175080/"
] |
74,420,629 | <p>Assume that an agent is moving from Node1 to Node3 in the following network:
Node1 - PathA - Node2 - PathB- Node3
How do I access the next node the agent will pass?</p>
<p>The actual task it for bus agents to move along the yellow paths and pickup/drop off passengers and crews at the corresponding stands (nodes) - one of the tasks requires me to acquire the "next node".</p>
<p><a href="https://i.stack.imgur.com/35CWX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/35CWX.png" alt="nodes and paths at airport" /></a></p>
| [
{
"answer_id": 74421213,
"author": "Felipe",
"author_id": 3438111,
"author_profile": "https://Stackoverflow.com/users/3438111",
"pm_score": 0,
"selected": false,
"text": "getTargetX()"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14497660/"
] |
74,420,664 | <p>I am trying to summarize some massive tables in a way that can help me investigate further for some data issues. There are hundreds of 1000s of rows, and roughly 80+ columns of data in most of these tables.</p>
<p>From each table, I have already performed queries to throw out any columns that have all nulls or 1 value only. I've done this for 2 reasons.... for my purposes, a single value or nulls in the columns are not interesting to me and provide little information about the data; additionally, the next step is that I want to query each of the remaining columns and return up to 30 distinct values in each column (if the column has more than 30 distinct values, we show the 1st 30 distinct values).</p>
<p>Here is the general format of output I wish to create:</p>
<pre><code>Column_name(total_num_distinct): distinct_val1(val1_count), distinct_val2(val2_couunt), ... distinct_val30(val30_count)
</code></pre>
<p>Assuming my data fields are integers, floats, and varchar2 data types, this is the SQL I was trying to use to generate that output:</p>
<pre><code>declare
begin
for rw in (
select column_name colnm, num_distinct numd
from all_tab_columns
where
owner = 'scz'
and table_name like 'tbl1'
and num_distinct > 1
order by num_distinct desc
) loop
dbms_output.put(rw.colnm || '(' || numd || '): ');
for rw2 in (
select dis_val, cnt from (
select rw.colnm dis_val, count(*) cnt
from tbl1
group by rw.colnm
order by 2 desc
) where rownum <= 30
) loop
dbms_output.put(rw2.dis_val || '(' || rw2.cnt || '), ');
end loop;
dbms_output.put_line(' ');
end loop;
end;
</code></pre>
<p>I get the output I expect from the 1st loop, but the 2nd loop that is supposed to output examples of the unique values in each column, coupled with the frequency of their occurrence for the 30 values with the highest frequency of occurrence, appears to not be working as I intended. Instead of seeing unique values along with the number of times that value occurs in the field, I get the column names and count of total records in that table.</p>
<p>If the 1st loop suggests the first 4 columns in 'tbl1' with more than 1 distinct value are the following:</p>
<pre><code>| colnm | numd |
|----------------|
| Col1 | 2 |
| Col3 | 4 |
| Col7 | 17 |
| Col12 | 30 |
</code></pre>
<p>... then the full output of 1st and 2nd loop together looks something like the following from my SQL:</p>
<pre><code>Col1(2): Col1(tbl1_tot_rec_count), Col3(tbl1_tot_rec_count)
Col3(4): Col1(tbl1_tot_rec_count), Col3(tbl1_tot_rec_count), Col7(tbl1_tot_rec_count), Col12(tbl1_tot_rec_count)
Col7(17): Col1(tbl1_tot_rec_count), Col3(tbl1_tot_rec_count), Col7(tbl1_tot_rec_count), Col12(tbl1_tot_rec_count), .... , ColX(tbl1_tot_rec_count)
Col12(30): Col1(tbl1_tot_rec_count), Col3(tbl1_tot_rec_count), Col7(tbl1_tot_rec_count), Col12(tbl1_tot_rec_count), .... , ColX(tbl1_tot_rec_count)
</code></pre>
<p>The output looks cleaner when real data is output, each table outputting somewhere between 20-50 lines of output (i.e. columns with more than 2 values), and listing 30 unique values for each field (with their counts) only requires a little bit of scrolling, but isn't impractical. Just to give you an idea with fake values, the output would look more like this with real data if it was working correctly (but fake in my example):</p>
<pre><code>Col1(2): DisVal1(874,283), DisVal2(34,578),
Col3(4): DisVal1(534,223), DisVal2(74,283), DisVal3(13,923), null(2348)
Col7(17): DisVal1(54,223), DisVal2(14,633), DisVal3(13,083), DisVal4(12,534), DisVal5(9,876), DisVal6(8,765), DisVal7(7654), DisVal8(6543), DisVal9(5432), ...., ...., ...., ...., ...., ...., ...., DisVal17(431)
</code></pre>
<p>I am not an Oracle or SQL guru, so I might not be approaching this problem in the easiest, most efficient way. While I do appreciate any better ways to approach this problem, I also want to learn why the SQL code above is not giving me the output I expect. My goal is trying to quickly run a single query that can tell me which columns have interesting data I might what to examine further in that table. I have probably 20 tables I need to examine that are all of similar dimensions and so very difficult to examine comprehensively. Being able to reduce these tables in this way to know what possible combinations of values may exist across the various fields in each of these tables would be very helpful in further queries to deep dive into the intricacies of the data.</p>
| [
{
"answer_id": 74420869,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 1,
"selected": false,
"text": "select rw.colnm dis_val, count(*) cnt from tbl1 group by rw.colnm order by 2 desc"
},
{
"answer_id": 74422075,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 0,
"selected": false,
"text": "select utc.table_name, utc.column_name,\n REPLACE( REPLACE(q'~select col_name, col_value, col_counter\nfrom (\n SELECT col_name, col_value, col_counter, \n ROW_NUMBER() OVER(ORDER BY col_counter DESC) AS rn\n FROM (\n select '{col_name}' AS col_name, \n {col_name} AS col_value, COUNT(*) as col_counter \n from {table_name} \n group by {col_name}\n )\n)\nWHERE rn <= 30~', '{col_name}', utc.column_name), '{table_name}', utc.table_name) AS sql\nfrom user_tab_columns utc \nwhere not exists( \n select 1\n from user_indexes ui\n join user_ind_columns uic on uic.table_name = ui.table_name \n and uic.index_name = ui.index_name\n where \n ui.table_name = utc.table_name\n and exists ( \n select 1 from user_ind_columns t where t.table_name = ui.table_name \n and t.index_name = uic.index_name and t.column_name = utc.column_name\n )\n group by ui.table_name, ui.index_name having( count(*) = 1 )\n)\nand not exists( \n SELECT 1\n FROM user_constraints uc\n JOIN user_cons_columns ucc ON ucc.constraint_name = uc.constraint_name\n WHERE constraint_type IN (\n 'P', -- primary key \n 'U' -- unique \n )\n AND uc.table_name = utc.table_name AND ucc.column_name = utc.column_name\n)\n;\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5723764/"
] |
74,420,714 | <p>I have created a genetic algorithm to create children from parents.
At the start of the algorithm a random workload(arrays of sub-arrays) is created.
Workload L=2, population size N=30, InputsNumber=3 and mutation rate m=0.05. Then I do some score calculations for the population to pick the 2 workloads(the parents) with highest score. Now the new population are the parents only. After that form the 2 parents I create children with crossover function and mutation function and I add the children to the population with the parents. Now I do the same thing for 10 times and every time I pick the 2 best to be the parents from the population. Now the problem is that when I change the children values in mutation function, all of a sudden the parents change their values to children values. How to avoid that? The parents are correct BEFORE I call the mutation() function and AFTER the mutation function they change. I can't understand why this is happening. Please help me find why this is happening!</p>
<p>HERE IS AN EXAMPLE OUTPUT: <a href="https://ibb.co/m5T0hSq" rel="nofollow noreferrer">https://ibb.co/m5T0hSq</a></p>
<p>Parent or child array example: [[0 0 0],[0 0 0]]
Parents or children array example: [ [[0 0 0],[0 0 0]], [[0 0 0],[0 0 0]] ]</p>
<pre><code>def generateRandomWorkload(inputsNumber, L, N):
global population
individualWorkload = []
for n in range(N):
for i in range(L):
individual = [0 for _ in range(len(inputsNumber))]
individualWorkload.append(individual)
population.append(individualWorkload)
individualWorkload = []
def crossover(L):
global parents, children
children = []
for i in range(2):
C = random.randint(0, 1)
R = random.randint(0, L)
if C == 0:
child = parents[0][0:R] + parents[1][R:L]
children.append(child)
elif C == 1:
child = parents[1][0:R] + parents[0][R:L]
children.append(child)
return children
def mutation(mutation_rate):
global children
for i in range(len(children)):
for j in range(len(children[i])):
for k in range(len(children[i][j])):
r = random.uniform(0, 1)
if r <= mutation_rate:
children[i][j][k] = 1 - children[i][j][k]
return children
def geneticAlgorithm(inputsNumber, L, N):
global parents, children, population
generateRandomWorkload(inputsNumber, L, N)
print("SEED POPULATION: ", population, "\n \n")
for generation in range(10):
print(bcolors.OKGREEN + "MEASUREMENTS OF ", generation+1, " GENERATION" + bcolors.ENDC)
for individualWorkload in population:
### HERE I CALCULATE SOME SCORES (scoreI) ###
# Parents
print("PARENTS SELECTION... \n")
scoreI.sort(key=lambda x: x[1])
parents = [scoreI[-1][0], scoreI[-2][0]]
population = [parents[0], parents[1]]
print("SELECTED PARENTS: \n", parents, "\n")
print("PARENTS IN POPULATION:", population)
# Crossover
print("BEGIN CROSSOVER... \n")
print("PARENTS: ", parents)
children = crossover(L)
print("CROSSOVER CHILDREN:\n", children, "\n")
# Mutation
print("BEGIN MUTATION...\n")
print("PARENTS: ", parents)
children = mutation(0.05)
print("MUTATION CHILDREN:\n", children, "\n")
# New population
population.append(children[0])
population.append(children[1])
print("PARENTS: ", parents)
print("NEW POPULATION: \n", population, "\n")
</code></pre>
| [
{
"answer_id": 74420869,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 1,
"selected": false,
"text": "select rw.colnm dis_val, count(*) cnt from tbl1 group by rw.colnm order by 2 desc"
},
{
"answer_id": 74422075,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 0,
"selected": false,
"text": "select utc.table_name, utc.column_name,\n REPLACE( REPLACE(q'~select col_name, col_value, col_counter\nfrom (\n SELECT col_name, col_value, col_counter, \n ROW_NUMBER() OVER(ORDER BY col_counter DESC) AS rn\n FROM (\n select '{col_name}' AS col_name, \n {col_name} AS col_value, COUNT(*) as col_counter \n from {table_name} \n group by {col_name}\n )\n)\nWHERE rn <= 30~', '{col_name}', utc.column_name), '{table_name}', utc.table_name) AS sql\nfrom user_tab_columns utc \nwhere not exists( \n select 1\n from user_indexes ui\n join user_ind_columns uic on uic.table_name = ui.table_name \n and uic.index_name = ui.index_name\n where \n ui.table_name = utc.table_name\n and exists ( \n select 1 from user_ind_columns t where t.table_name = ui.table_name \n and t.index_name = uic.index_name and t.column_name = utc.column_name\n )\n group by ui.table_name, ui.index_name having( count(*) = 1 )\n)\nand not exists( \n SELECT 1\n FROM user_constraints uc\n JOIN user_cons_columns ucc ON ucc.constraint_name = uc.constraint_name\n WHERE constraint_type IN (\n 'P', -- primary key \n 'U' -- unique \n )\n AND uc.table_name = utc.table_name AND ucc.column_name = utc.column_name\n)\n;\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11353686/"
] |
74,420,724 | <p>We have an <em>undirected acyclic</em> graph where there is only a <em>single path between two connected nodes</em> that may look something like <a href="https://i.stack.imgur.com/wG8vS.png" rel="nofollow noreferrer">this</a>.</p>
<p><a href="https://i.stack.imgur.com/wG8vS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wG8vS.png" alt="Enter image description here" /></a></p>
<p><strong>Simple guide to the image:</strong></p>
<ul>
<li>Black numbers: Node id's (note that each node contains a resource collector)</li>
<li>Resource collectors: Every resource collector collects resources on edges that are right next to it (so a collector on node 0 cannot reach resource deposits past node 1 and so on). A resource collector also requires fuel to operate - the amount of fuel a resource collector needs is directly connected to its range - the range determines the furthest resource node it can reach on the allowed edges (the range of the collectors is the blue circle on some nodes in the image). The fuel consumption of a collector is then calculated like this: <code>fuel = radius of the circle</code> (meaning that in the example case node 0 consumes 1 fuel and node 1 and 3 consume 2 fuel each, and since all the resource deposits have been covered our final fuel requirement is 5 (nodes 2, 5 and 4 do not use any fuel, since their radii are 0)).</li>
<li>Black lines: Graph edges</li>
<li>Red dots: Resource deposits, we only receive the number of deposits on a specific edge and all the deposits are evenly spaced apart on their respective edge.</li>
</ul>
<p><strong>Our task</strong> is to find the best configuration for our resource collectors (that is, find the configuration that consumes the lowest amount of fuel, and reaches all resource nodes) <em>By this is meant: set the collector radius.</em></p>
<p><strong>Things I've tried to solve this problem:</strong>
At first I've tried locating the "central" node of the graph and then traversing it with <a href="https://en.wikipedia.org/wiki/Breadth-first_search" rel="nofollow noreferrer">BFS</a> while checking one node ahead and determining the amount of fuel from there, this did work for some graphs, but it became unstable in more complex ones.</p>
<p>After that I've tried basically the same thing, but I chose the leaf nodes as the starting points, this produced similar, imperfect, results.</p>
| [
{
"answer_id": 74420869,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 1,
"selected": false,
"text": "select rw.colnm dis_val, count(*) cnt from tbl1 group by rw.colnm order by 2 desc"
},
{
"answer_id": 74422075,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 0,
"selected": false,
"text": "select utc.table_name, utc.column_name,\n REPLACE( REPLACE(q'~select col_name, col_value, col_counter\nfrom (\n SELECT col_name, col_value, col_counter, \n ROW_NUMBER() OVER(ORDER BY col_counter DESC) AS rn\n FROM (\n select '{col_name}' AS col_name, \n {col_name} AS col_value, COUNT(*) as col_counter \n from {table_name} \n group by {col_name}\n )\n)\nWHERE rn <= 30~', '{col_name}', utc.column_name), '{table_name}', utc.table_name) AS sql\nfrom user_tab_columns utc \nwhere not exists( \n select 1\n from user_indexes ui\n join user_ind_columns uic on uic.table_name = ui.table_name \n and uic.index_name = ui.index_name\n where \n ui.table_name = utc.table_name\n and exists ( \n select 1 from user_ind_columns t where t.table_name = ui.table_name \n and t.index_name = uic.index_name and t.column_name = utc.column_name\n )\n group by ui.table_name, ui.index_name having( count(*) = 1 )\n)\nand not exists( \n SELECT 1\n FROM user_constraints uc\n JOIN user_cons_columns ucc ON ucc.constraint_name = uc.constraint_name\n WHERE constraint_type IN (\n 'P', -- primary key \n 'U' -- unique \n )\n AND uc.table_name = utc.table_name AND ucc.column_name = utc.column_name\n)\n;\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492240/"
] |
74,420,726 | <p>I am using Minikube and here is my configuration:</p>
<p><code>kubectl describe deployment mysql</code></p>
<p>the output:</p>
<pre><code>Name: mysql
Namespace: default
CreationTimestamp: Sat, 12 Nov 2022 02:20:54 +0200
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=mysql
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=mysql
Containers:
mysql:
Image: mysql
Port: 3306/TCP
Host Port: 0/TCP
Environment:
MYSQL_ROOT_PASSWORD: <set to the key 'password' in secret 'mysql-pass'> Optional: false
Mounts:
/docker-entrypoint-initdb.d from mysql-init (rw)
Volumes:
mysql-init:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: mysql-init
Optional: false
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: mysql-77fd55bbd9 (1/1 replicas created)
</code></pre>
<p>when I try to connect to it using mysql workbench:</p>
<p><a href="https://i.stack.imgur.com/sGqJt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sGqJt.png" alt="workbench config" /></a></p>
<p>it shows me:</p>
<p><a href="https://i.stack.imgur.com/w94tA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w94tA.png" alt="failed to connect to mysql" /></a></p>
<p>However, when I execute this line to create a <strong>mysql-client</strong> to try to connect to mysql server:</p>
<p><code>kubectl run -it --rm --image=mysql:8.0 --restart=Never mysql-client -- mysql -h mysql -u skaffold -p</code>
and then enter the password, <strong>it works well!</strong> but still I need to use workbench better.</p>
<p>any help please?</p>
<p>edit 1:</p>
<p>Here is the yaml file for the deployment and the service:</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-init
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: mysql-init
configMap:
name: mysql-init
---
apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
name: mysql
spec:
ports:
- port: 3306
targetPort: 3306
protocol: TCP
selector:
app: mysql
</code></pre>
| [
{
"answer_id": 74420869,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 1,
"selected": false,
"text": "select rw.colnm dis_val, count(*) cnt from tbl1 group by rw.colnm order by 2 desc"
},
{
"answer_id": 74422075,
"author": "p3consulting",
"author_id": 4956336,
"author_profile": "https://Stackoverflow.com/users/4956336",
"pm_score": 0,
"selected": false,
"text": "select utc.table_name, utc.column_name,\n REPLACE( REPLACE(q'~select col_name, col_value, col_counter\nfrom (\n SELECT col_name, col_value, col_counter, \n ROW_NUMBER() OVER(ORDER BY col_counter DESC) AS rn\n FROM (\n select '{col_name}' AS col_name, \n {col_name} AS col_value, COUNT(*) as col_counter \n from {table_name} \n group by {col_name}\n )\n)\nWHERE rn <= 30~', '{col_name}', utc.column_name), '{table_name}', utc.table_name) AS sql\nfrom user_tab_columns utc \nwhere not exists( \n select 1\n from user_indexes ui\n join user_ind_columns uic on uic.table_name = ui.table_name \n and uic.index_name = ui.index_name\n where \n ui.table_name = utc.table_name\n and exists ( \n select 1 from user_ind_columns t where t.table_name = ui.table_name \n and t.index_name = uic.index_name and t.column_name = utc.column_name\n )\n group by ui.table_name, ui.index_name having( count(*) = 1 )\n)\nand not exists( \n SELECT 1\n FROM user_constraints uc\n JOIN user_cons_columns ucc ON ucc.constraint_name = uc.constraint_name\n WHERE constraint_type IN (\n 'P', -- primary key \n 'U' -- unique \n )\n AND uc.table_name = utc.table_name AND ucc.column_name = utc.column_name\n)\n;\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420726",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4349565/"
] |
74,420,733 | <p>According to AIMA (Russell & Norvig, 2010) this is the BNF grammar for FOL with Equality:</p>
<p><a href="https://i.stack.imgur.com/AlkuF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AlkuF.png" alt="bnf" /></a></p>
<p>How do I convert this to a lark grammar? Specifically, how do I represent n-ary predicates using lark grammar?</p>
| [
{
"answer_id": 74425961,
"author": "rici",
"author_id": 1566221,
"author_profile": "https://Stackoverflow.com/users/1566221",
"pm_score": 2,
"selected": true,
"text": "()"
},
{
"answer_id": 74467204,
"author": "daegontaven",
"author_id": 5586359,
"author_profile": "https://Stackoverflow.com/users/5586359",
"pm_score": 0,
"selected": false,
"text": "wff: atomic_wff | compound_wff\natomic_wff: predicate [left_parenthesis term (comma term)* right_parenthesis] | term equal_to term\ncompound_wff: left_parenthesis wff right_parenthesis\n | not space wff\n | wff space and space wff\n | wff space nand space wff\n | wff space or space wff\n | wff space xor space wff\n | wff space nor space wff\n | wff space implied_by space? wff\n | wff space implies space wff\n | wff space iff space wff\n | (quantifier left_curly_brace variable right_curly_brace)* space? left_parenthesis wff right_parenthesis\nterm: function left_parenthesis term (comma term)* right_parenthesis\n | name\n | variable\n\nspace: /\\s+/\ncomma: \",\"\nequal_to: \"=\"\nleft_parenthesis: \"(\"\nright_parenthesis: \")\"\nleft_curly_brace: \"{\"\nright_curly_brace: \"}\"\nquantifier: universal_quantifier | existential_quantifier | uniqueness_quantifier\nuniversal_quantifier: \"\\\\forall\"\nexistential_quantifier: \"\\\\exists\"\nuniqueness_quantifier: \"\\\\exists!\"\nname: /[a-t]/ | /[a-t]_[1-9]\\d*/\nvariable: /[u-z]/ | /[u-z]_[1-9]\\d*/\npredicate: /[A-HJ-Z]/ | /[A-HJ-Z]_[1-9]\\d*/\nfunction: /[a-z]/ | /[a-z]_[1-9]\\d*/\nnot: \"\\\\neg\"\nand: \"\\\\wedge\"\nnand: \"\\\\uparrow\" | \"\\\\barwedge\"\nor: \"\\\\vee\"\nxor: \"\\\\veebar\"\nnor: \"\\\\downarrow\"\nimplies: \"\\\\rightarrow\" | \"\\\\Rightarrow\" | \"\\\\Longrightarrow\" | \"\\\\implies\"\nimplied_by: \"\\\\leftarrow\" | \"\\\\Leftarrow\" | \"\\\\Longleftarrow\"\niff: \"\\\\leftrightarrow\" | \"\\\\iff\"\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5586359/"
] |
74,420,798 | <p>I am trying to do the following questions.</p>
<ol>
<li><p>Find the ISBN and title of books that was published in 2022.</p>
</li>
<li><p>Find the ISBN, title of book and publisher of books that have at least two authors and at most three authors.</p>
</li>
</ol>
<p><a href="https://pastebin.com/g7ySAeFD" rel="nofollow noreferrer">MongoDB subject.js</a></p>
<p>For Question 1, I've tried:
I wanted to try to use <code>$eq</code> but I'm not so sure how to so I tried using <code>$elemMatch</code> but it seems like I have no idea how it works too.</p>
<pre><code>db.Subject.aggregate( [
{"$unwind":"$subject.book"},
{"$match":{"subject.book":{"$elemMatch":{"subject.yearPub":2022}} }},
{"$project":{"subject.book.ISBN":1,"subject.book.bookTitle":1 }}
] )
</code></pre>
<p>For Question 2, I've tried:
This works so far it gives me books with 3 authors. But for some reason it misses the books with 2 authors.</p>
<pre><code>db.Subject.aggregate([{"$match": {"$or": [{'subject.book.author.3': {"$exists": true}},
{'book.author.2': {"$exists": true}}]}},
{"$project": {"subject.book.ISBN": 1,"subject.book.bookTitle": 1,"subject.book.publisher": 1,"_id":0}}
]).pretty()
</code></pre>
| [
{
"answer_id": 74421170,
"author": "Yong Shun",
"author_id": 8017690,
"author_profile": "https://Stackoverflow.com/users/8017690",
"pm_score": 2,
"selected": true,
"text": "db.Subject.aggregate([\n {\n \"$unwind\": \"$subject.book\"\n },\n {\n \"$match\": {\n \"subject.book.yearPub\": 2022\n }\n },\n {\n \"$project\": {\n \"subject.book.ISBN\": 1,\n \"subject.book.bookTitle\": 1\n }\n }\n])\n"
},
{
"answer_id": 74421296,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"author_profile": "https://Stackoverflow.com/users/3027266",
"pm_score": 0,
"selected": false,
"text": "$unwind"
},
{
"answer_id": 74426233,
"author": "Bryead",
"author_id": 10874912,
"author_profile": "https://Stackoverflow.com/users/10874912",
"pm_score": 1,
"selected": false,
"text": "db.collection.aggregate([\n {\n \"$unwind\": \"$subject.book\"\n },\n {\n \"$match\": {\n \"$or\": [\n {\n \"subject.book.author.2\": {\n \"$exists\": true\n }\n },\n {\n \"subject.book.author.1\": {\n \"$exists\": true\n }\n }\n ]\n }\n },\n {\n \"$project\": {\n \"subject.book.ISBN\": 1,\n \"subject.book.bookTitle\": 1,\n \"subject.book.publisher\": 1,\n \"_id\": 0\n }\n }\n])\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492247/"
] |
74,420,856 | <pre><code>Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(
// crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FloatingActionButton(
onPressed: () {
//ClearSession();
if (Navigator.canPop(context)) {
Navigator.pop(context, true);
}
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
Home(22.0, 22.0)));
}
// Add your onPressed code here!
,
backgroundColor: Colors.green,
child: const Icon(Icons.home),
),
FloatingActionButton(
onPressed: () {
//ClearSession();
if (Navigator.canPop(context)) {
Navigator.pop(context, true);
}
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
const Calender()));
}
// Add your onPressed code here!
,
backgroundColor: Colors.green,
child: const Icon(Icons.calendar_month),
),
FloatingActionButton(
onPressed: () {
//ClearSession();
if (Navigator.canPop(context)) {
Navigator.pop(context, true);
}
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) =>
const Community()));
},
backgroundColor: Colors.green,
child: const Icon(Icons.article_rounded),
),
FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
backgroundColor: Colors.green,
child: const Icon(
Icons.settings_accessibility_sharp),
),
],
),
],
),
</code></pre>
<p>it should be compatible with all types of screens regardless of screen size
I don't want to use padding because it only works for some screen , not for all type of the screen
the icons are in the middle of the screen,</p>
<p>I want to put all of them in the button of the screen</p>
<p><a href="https://i.stack.imgur.com/vRCPu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vRCPu.png" alt="this is the current position of icons " /></a></p>
<p>it should be compatible with all types of screens regardless of screen size
I don't want to use padding because it only works for some screen,not for all type of the screen the icons are in the middle of the screen, I want to put all of them in the button of the screen</p>
| [
{
"answer_id": 74420973,
"author": "aminjafari-dev",
"author_id": 19699656,
"author_profile": "https://Stackoverflow.com/users/19699656",
"pm_score": 3,
"selected": true,
"text": "scaffold()"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12933247/"
] |
74,420,922 | <p>I already know that I can postpone an Angular bootstrap until a Promise or Obseravable are resolved.</p>
<p>Example :</p>
<p><kbd>app.module.ts</kbd></p>
<pre><code>{
provide: APP_INITIALIZER,
useFactory: (configService: ConfigurationService) => ()=> configService.load(),
deps: [ConfigurationService],
multi: true
}
</code></pre>
<p>But i've seen this other approach of using <code>platformBrowserDynamic</code>'s providers :</p>
<p>example :</p>
<p><kbd><code>main.ts</code>:</kbd></p>
<pre><code> (function () {
return new Promise((resolver) => {
const someData = {...}
window.setTimeout(() => //simulate ajax data fetch
{
resolver(someData );
}, 1000);
});
})()
.then((myData:any) => platformBrowserDynamic([ {provide: 'pbdProvider', useValue: myData }]).bootstrapModule(...)
</code></pre>
<p><strong>Question:</strong></p>
<p>When should I use <code>APP_INITIALIZER</code> vs (<code>platformBrowserDynamic</code> with <code>provide</code>)?</p>
| [
{
"answer_id": 74420973,
"author": "aminjafari-dev",
"author_id": 19699656,
"author_profile": "https://Stackoverflow.com/users/19699656",
"pm_score": 3,
"selected": true,
"text": "scaffold()"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/859154/"
] |
74,420,927 | <p>I have a string:</p>
<pre><code>string = "Hello World"
</code></pre>
<p>That needs changing to:</p>
<pre><code>"hello WORLD"
</code></pre>
<p>Using only split and join in Python.</p>
<p>Any help?</p>
<pre><code>string = "Hello World"
split_str = string.split()
</code></pre>
<p>Can't then work out how to get first word to lowercase second word to uppercase and join</p>
| [
{
"answer_id": 74420958,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": -1,
"selected": true,
"text": "string = \"Hello World\"\nwords = string.split() # works also for multiple spaces and tabs\nresult = ' '.join((w.upper() if i&1 else w.lower()) for i,w in enumerate(words))\nprint(result)\n# \"hello WORLD\"\n"
},
{
"answer_id": 74421014,
"author": "Slonsoid",
"author_id": 20474992,
"author_profile": "https://Stackoverflow.com/users/20474992",
"pm_score": -1,
"selected": false,
"text": "split"
},
{
"answer_id": 74421273,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": false,
"text": "from itertools import cycle\n\nwords = 'hello world'\n\nCYCLE = cycle((str.lower, str.upper))\n\nprint(*(next(CYCLE)(word) for word in words.split()))\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18206734/"
] |
74,420,939 | <p>I'm a total noob with coding, so I'm probably going about this the wrong way.</p>
<p>For this fiveM server, we currently have an mp4 video running as the background of the loading screen, i want to randomise this with multiple videos created though.</p>
<p>This is the current HTML code we've got, where i've added the source, but I have no clue how to trigger it to randomise - do i need to add an additional JS file? or can i somehow trigger this off the CSS?</p>
<p><strong>HTML</strong></p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<title>Loading</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/fontstyle.css" />
<script type="text/javascript" src="js/modernizr.custom.86080.js"></script>
</head>
<video autoplay muted loop id="video">
<source src="video/2.mp4" type="video/mp4">
<source src="video/bgvideo.mp4" type="video/mp4">
</video>
<body style="background-color: rgb(49, 49, 49); overflow: hidden;">
<body id="page">
<div class="info">
<h1>Welcome to City In Motion<br><br><h2><i>Your story begins here...</i></h2>
</div>
<div class="loader">Loading...</div>
<div class="logo"><img src="images/logo.png" style='width:160%;height:345%'></div>
<div class="sidepanel" id="particles-js" style="background-color: black;"></div>
<script type="text/javascript" src="js/particles.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
<audio id="music" autoplay loop >
<source src="music/music.mp3" type="audio/mp3">
</audio>
<script>
var music = document.getElementById("music");
music.volume = 0.02
window.onload = function(){
document.onkeydown = function(event) {
switch (event.keyCode) {
case 32: //SpaceBar
music.muted = !music.muted;
break;
}
return false;
}}
</script>
</html>
</code></pre>
| [
{
"answer_id": 74420958,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": -1,
"selected": true,
"text": "string = \"Hello World\"\nwords = string.split() # works also for multiple spaces and tabs\nresult = ' '.join((w.upper() if i&1 else w.lower()) for i,w in enumerate(words))\nprint(result)\n# \"hello WORLD\"\n"
},
{
"answer_id": 74421014,
"author": "Slonsoid",
"author_id": 20474992,
"author_profile": "https://Stackoverflow.com/users/20474992",
"pm_score": -1,
"selected": false,
"text": "split"
},
{
"answer_id": 74421273,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": false,
"text": "from itertools import cycle\n\nwords = 'hello world'\n\nCYCLE = cycle((str.lower, str.upper))\n\nprint(*(next(CYCLE)(word) for word in words.split()))\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492512/"
] |
74,420,950 | <p>I am fairly new to using ggplot for data visualisation in R and I want to understand whether the following dataframe <code>df</code> needs restructuring so that there is only one metric <code>Spend</code> to create an area chart. For this area chart I want the x-axis to be Days, the y-axis to be Spend and for it to be split by person A and person B.</p>
<pre><code>df<-data.frame(Days=c(1,2,3,4,5,6,7),
PersonASpend=c(100,0,90,20,5,8,10),
PersonBSpend=c(30,20,120,20,55,20,0))
Days PersonASpend PersonBSpend
1 1 100 30
2 2 0 20
3 3 90 120
4 4 20 20
5 5 5 55
6 6 8 20
7 7 10 0
</code></pre>
<p>i.e. does it need to be structured as follows or is there another way to do this?</p>
<pre><code> Days Person Spend
1 1 A 100
2 2 A 0
3 3 A 90
4 4 A 20
5 5 A 5
6 6 A 7
7 7 A 10
8 1 B 30
9 2 B 20
10 3 B 120
11 4 B 20
12 5 B 55
13 6 B 20
14 7 B 0
</code></pre>
| [
{
"answer_id": 74420958,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": -1,
"selected": true,
"text": "string = \"Hello World\"\nwords = string.split() # works also for multiple spaces and tabs\nresult = ' '.join((w.upper() if i&1 else w.lower()) for i,w in enumerate(words))\nprint(result)\n# \"hello WORLD\"\n"
},
{
"answer_id": 74421014,
"author": "Slonsoid",
"author_id": 20474992,
"author_profile": "https://Stackoverflow.com/users/20474992",
"pm_score": -1,
"selected": false,
"text": "split"
},
{
"answer_id": 74421273,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 2,
"selected": false,
"text": "from itertools import cycle\n\nwords = 'hello world'\n\nCYCLE = cycle((str.lower, str.upper))\n\nprint(*(next(CYCLE)(word) for word in words.split()))\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74420950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17974332/"
] |
74,421,024 | <p>I have the following data (coming from Twitter):</p>
<pre><code>structure(list(entities.urls = list(structure(list(), .Names = character(0)),
NULL, structure(list(), .Names = character(0)), structure(list(), .Names = character(0)),
structure(list(start = 245L, end = 268L, url = "https://something.com",
expanded_url = "https://www.rtlnieuws.nl/nieuws/nederland/artikel/5330834/spaartaks-spaarders-compensatie-hoge-raad",
display_url = "rtlnieuws.nl/nieuws/nederla…", images = list(
structure(list(url = c("https://pbs.twimg.com/news_img/1569417166549663745/p12uVzUj?format=jpg&name=orig",
"https://pbs.twimg.com/news_img/1569417166549663745/p12uVzUj?format=jpg&name=150x150"
), width = c(1024L, 150L), height = c(576L, 150L)), class = "data.frame", row.names = 1:2)),
status = 200L, title = "Geen compensatie voor spaarders die te laat bezwaar maakten",
description = "Het kabinet gaat spaarders die te laat of geen bezwaar hebben gemaakt tegen de spaartaks niet compenseren. Dat bevestigen Haagse bronnen aan RTL Nieuws. Voor de zomer oordeelde de Hoge Raad al dat deze mensen geen recht hebben op compensatie.",
unwound_url = "https://www.rtlnieuws.nl/nieuws/nederland/artikel/5330834/spaartaks-spaarders-compensatie-hoge-raad"), class = "data.frame", row.names = 1L),
structure(list(start = 197L, end = 220L, url = "https://something.com",
expanded_url = "https://fd.nl/financiele-markten/1432905/oorlog-in-oekraine-is-ultieme-stresstest-voor-grondstoffenhandelaren?utm_medium=social&utm_source=app&utm_campaign=earned&utm_content=20220312&utm_term=app-ios",
display_url = "fd.nl/financiele-mar…", status = 200L,
unwound_url = "https://fd.nl/financiele-markten/1432905/oorlog-in-oekraine-is-ultieme-stresstest-voor-grondstoffenhandelaren?utm_medium=social&utm_source=app&utm_campaign=earned&utm_content=20220312&utm_term=app-ios"), class = "data.frame", row.names = 1L),
structure(list(), .Names = character(0)), structure(list(), .Names = character(0)),
structure(list(), .Names = character(0)), structure(list(), .Names = character(0)))), class = "data.frame", row.names = c(NA,
10L))
</code></pre>
<p>Each row of column <code>entities.urls</code> is either NULL, or contains a list, which is sometimes empty and sometimes holds a dataframe. I wanted to unnest that column so that so that every column of the nested data frame becomes a column in the top-level dataframe. Also, data should be in long format so that every row is repeated for the number of rows of the nested data frame.</p>
<p>I have tried with dplyr's <code>unnest</code>:</p>
<pre><code>tweets_02 %>% unnest(entities.urls, keep_empty = TRUE)
</code></pre>
<p>which throws an error. I guess the problem are the empty lists, but I have found no way filter them out efficiently.</p>
| [
{
"answer_id": 74421624,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 2,
"selected": true,
"text": "library(tidyverse)\n\ntest |>\n filter( map_chr(entities.urls, class)==\"data.frame\") |>\n unnest(entities.urls)\n#> # A tibble: 2 x 10\n#> start end url expan~1 displ~2 images status title descr~3 unwou~4\n#> <int> <int> <chr> <chr> <chr> <list> <int> <chr> <chr> <chr> \n#> 1 245 268 https://somet~ https:~ rtlnie~ <df> 200 Geen~ Het ka~ https:~\n#> 2 197 220 https://somet~ https:~ fd.nl/~ <NULL> 200 <NA> <NA> https:~\n#> # ... with abbreviated variable names 1: expanded_url, 2: display_url,\n#> # 3: description, 4: unwound_url\n"
},
{
"answer_id": 74428816,
"author": "Joris C.",
"author_id": 10766590,
"author_profile": "https://Stackoverflow.com/users/10766590",
"pm_score": 0,
"selected": false,
"text": "rrapply()"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10483692/"
] |
74,421,043 | <p>In below File I done some coding to make a jdbc connection. And I am using a xampp server for that.</p>
<p>ConnectionProvider.java</p>
<pre><code>package com.employeerecord.helper;
import java.sql.*;
public class ConnectionProvider {
//method GetConnection
private static Connection connection;
public static Connection getConnection() {
try {
//if connection is null then only it get created
if(connection==null) {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/emprecord","root",""); //Driver for Connection
}
} catch(Exception e) {
e.printStackTrace();
}
return connection;
}
}
</code></pre>
<p>In Below code I make a frontend of the jsp page and put some dummy values. But I'am getting an error of <em>"ConnectionProvider cannot be resolved"</em> and does not having an connection.</p>
<p>index.jsp</p>
<pre><code><%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home</title>
<!-- All CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous">
<link href="CSS/style.css" rel="stylesheet">
<!-- All JS -->
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"
integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB"
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"
integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13"
crossorigin="anonymous"></script>
</head>
<body>
<% Connection connection = ConnectionProvider.getConnection();
out.println(connection);
%>
<%@include file="navbar.jsp" %><br><br><br>
<!-- Table -->
<div class="row justify-content-center">
<div class="col-md-10">
<h3>All Employees In Our Company Are Listed Here</h3>
<table class="table">
<thead>
<tr>
<th scope="col"> EmployeeID </th>
<th scope="col"> Name </th>
<th scope="col"> Skills </th>
<th scope="col"> Address </th>
<th scope="col"> Gender </th>
<th scope="col"> Salary </th>
<th scope="col"> BirthDate </th>
<th scope="col"> Edit </th>
<th scope="col"> Delete </th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>xyz</td>
<td>Java</td>
<td>abc</td>
<td>Male</td>
<td>40,000</td>
<td>11/11/0000</td>
<td>Edit</td>
<td>Delete</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
</code></pre>
<p>Error</p>
<p>I'am doing a connection between the jsp file and mysql server using xampp.
<a href="https://i.stack.imgur.com/M7emX.png" rel="nofollow noreferrer">Erron I am Getting</a></p>
| [
{
"answer_id": 74421730,
"author": "changuk",
"author_id": 15566000,
"author_profile": "https://Stackoverflow.com/users/15566000",
"pm_score": 0,
"selected": false,
"text": "index.jsp"
},
{
"answer_id": 74426840,
"author": "lavantho0508_java_dev",
"author_id": 18500877,
"author_profile": "https://Stackoverflow.com/users/18500877",
"pm_score": 1,
"selected": false,
"text": "<%@page import=\"com.employeerecord.helper.ConnectionProvider\"%>\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492559/"
] |
74,421,060 | <p>Im trying to write a code, that will take colnames out of a given vector, and in each of these columns recode 1<-5,2<-4,3<-3,4<-2,5<-1
big5qflip is the vectore of columns that I need to recode out of a questionnaire,
I'm having trouble getting it to work, and writing case_when correctly</p>
<pre><code>big5new%>%mutate_at(vars(big5qflip),case_when(
big5qflip==1~5,
big5qflip==2~4,
big5qflip==3~3,
big5qflip==4~2,
big5qflip==5~2
))
</code></pre>
<p>thank you!</p>
<p>when I tried the code above I got the follwing error
Error in <code>mutate_at()</code>:
! <code>.funs</code> must be a one sided formula, a function, or a function name.
Run <code>rlang::last_error()</code> to see where the error occurred.</p>
| [
{
"answer_id": 74421730,
"author": "changuk",
"author_id": 15566000,
"author_profile": "https://Stackoverflow.com/users/15566000",
"pm_score": 0,
"selected": false,
"text": "index.jsp"
},
{
"answer_id": 74426840,
"author": "lavantho0508_java_dev",
"author_id": 18500877,
"author_profile": "https://Stackoverflow.com/users/18500877",
"pm_score": 1,
"selected": false,
"text": "<%@page import=\"com.employeerecord.helper.ConnectionProvider\"%>\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492573/"
] |
74,421,111 | <p>I have a JSON array with objects as items. Some of the objects have properties, some don't. How can I filter the list with jq to keep only non-empty objects in the list?</p>
<p>Input:</p>
<pre><code>[
{},
{ "x": 42 },
{},
{ "y": 21 },
{},
{ "z": 13 }
]
</code></pre>
<p>Expected output:</p>
<pre><code>[
{ "x": 42 },
{ "y": 21 },
{ "z": 13 }
]
</code></pre>
<p>I tried <code>jq 'select(. != {})'</code>, but the result still contains all items. Using <code>jq 'map(select(empty))'</code> doesn't keep any item and returns an empty array!</p>
| [
{
"answer_id": 74421354,
"author": "Philippe",
"author_id": 2125671,
"author_profile": "https://Stackoverflow.com/users/2125671",
"pm_score": 2,
"selected": true,
"text": "map"
},
{
"answer_id": 74421480,
"author": "jpseng",
"author_id": 16332641,
"author_profile": "https://Stackoverflow.com/users/16332641",
"pm_score": 0,
"selected": false,
"text": "del"
},
{
"answer_id": 74421913,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 1,
"selected": false,
"text": "map"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/112968/"
] |
74,421,127 | <p>when working in Angular, let's say we have <em>module A</em> and <em>module B</em>, if I want to use "<em>A-component</em>" inside components of <em>module B</em>, then what's the difference between importing <em>module A</em> inside <em>Module B</em>
, and adding the "<em>A-component</em>" in the exports of <em>module A</em> ?</p>
<p>I tried both, and I think they are not the same thing, this is confusing.</p>
| [
{
"answer_id": 74421354,
"author": "Philippe",
"author_id": 2125671,
"author_profile": "https://Stackoverflow.com/users/2125671",
"pm_score": 2,
"selected": true,
"text": "map"
},
{
"answer_id": 74421480,
"author": "jpseng",
"author_id": 16332641,
"author_profile": "https://Stackoverflow.com/users/16332641",
"pm_score": 0,
"selected": false,
"text": "del"
},
{
"answer_id": 74421913,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 1,
"selected": false,
"text": "map"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20225484/"
] |
74,421,129 | <p>I want to make a beginner website using HTML, CSS and JS. However, how do you highlight text using CSS tags and stuff? (is it called CSS tags??)</p>
<p>I'm stuck and nothing seems to work on the internet, whatever I find.</p>
<p>I did this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Trying out <mark>highlighted text<mark> now!</code></pre>
</div>
</div>
</p>
<p>Doesn't work...</p>
| [
{
"answer_id": 74421209,
"author": "eitzaz shah",
"author_id": 14329769,
"author_profile": "https://Stackoverflow.com/users/14329769",
"pm_score": 1,
"selected": false,
"text": "Trying out <mark>highlight my text</mark> right now!\n"
},
{
"answer_id": 74421236,
"author": "LakshyaK2011",
"author_id": 20192114,
"author_profile": "https://Stackoverflow.com/users/20192114",
"pm_score": 1,
"selected": true,
"text": "<h2 style=\"background-color:red;\">Hi Its Highlited</h2>"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18333951/"
] |
74,421,178 | <p>I've written the following code below and ran it without errors on both xcode and vscode. However, I wasn't able to get any output filename.txt. It wasn't in any of my folders.</p>
<p>Appreciate if anyone could help.</p>
<pre><code>#include <stdio.h>
#include <string.h>
int main() {
FILE *fp=NULL;
fp = fopen("filename.txt","w+");
if (fp!= NULL){
fprintf(fp,"%s %d","Hello",555);
}
fclose(fp);
return 0;
}
</code></pre>
| [
{
"answer_id": 74421279,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 2,
"selected": false,
"text": "fclose(NULL)"
},
{
"answer_id": 74421431,
"author": "Toby Speight",
"author_id": 4850040,
"author_profile": "https://Stackoverflow.com/users/4850040",
"pm_score": 1,
"selected": false,
"text": "FILE"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492676/"
] |
74,421,182 | <p>I want to delete the card when we click on the delete button after adding a TODO note<br/>
I have created a website which uses localstorage to store notes and display when clicking the create TODO button and it all works but when I click the delete button after the note is created (You have to create a TODO first) it does not delete the div itself <br/>
I want to delete the card when we click on the delete button <br/>
CODE:<br/></p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TODO List</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<style>
.main-title {
text-align: center;
}
.input {
border: 2px solid grey;
}
.all-todo {
display: flex;
margin: 30px;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">TODO List</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<h1 class="main-title">TODO List</h1>
<div class="container">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Task Name</label>
<input type="text" class="form-control input" id="exampleFormControlInput1">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Task Details</label>
<textarea class="form-control input" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary" id="main-btn">Create TODO</button>
<button type="button" class="btn btn-warning" id="clr">Clear LocalStorage</button>
</div>
<div class="all-todo"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"></script>
</body>
<script>
let button = document.getElementById("main-btn")
button.onclick = () => {
let key = document.getElementById("exampleFormControlInput1").value
let value = document.getElementById("exampleFormControlTextarea1").value
if (key != "" && value != "") {
iHTML = ""
localStorage.setItem(key, value)
iHTML += `
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">${key}</h5>
<p class="card-text">${localStorage.getItem(key)}</p>
<button type="button" id="note" onclick='${key}.innerHTML=""' class="btn btn-danger '${key}'">Delete</button>
</div>
</div>
`
document.getElementsByClassName("all-todo")[0].innerHTML += iHTML
}
else {
alert("Task Name or Details cannot be empty!")
}
}
let clr_btn = document.getElementById("clr")
clr_btn.onclick = () => {
localStorage.clear()
}
</script>
</html>
</code></pre>
| [
{
"answer_id": 74421463,
"author": "Greg",
"author_id": 13628163,
"author_profile": "https://Stackoverflow.com/users/13628163",
"pm_score": 3,
"selected": true,
"text": "onclick='${key}.innerHTML=\"\"'"
},
{
"answer_id": 74421979,
"author": "Adri",
"author_id": 18607375,
"author_profile": "https://Stackoverflow.com/users/18607375",
"pm_score": 1,
"selected": false,
"text": "<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n <meta charset=\"UTF-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>TODO List</title>\n <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\"\n integrity=\"sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi\" crossorigin=\"anonymous\">\n <style>\n .main-title {\n text-align: center;\n }\n\n .input {\n border: 2px solid grey;\n }\n\n .all-todo {\n display: flex;\n margin: 30px;\n }\n /* add css in this poiint to optimize code*/\n .card {\n width: 18rem;\n }\n </style>\n</head>\n\n<body>\n <nav class=\"navbar navbar-expand-lg bg-light\">\n <div class=\"container-fluid\">\n <a class=\"navbar-brand\" href=\"#\">TODO List</a>\n <button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\"\n data-bs-target=\"#navbarSupportedContent\" aria-controls=\"navbarSupportedContent\" aria-expanded=\"false\"\n aria-label=\"Toggle navigation\">\n <span class=\"navbar-toggler-icon\"></span>\n </button>\n <div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\">\n <ul class=\"navbar-nav me-auto mb-2 mb-lg-0\">\n <li class=\"nav-item\">\n <a class=\"nav-link active\" aria-current=\"page\" href=\"#\">Home</a>\n </li>\n <li class=\"nav-item\">\n <a class=\"nav-link\" href=\"#\">Link</a>\n </li>\n </ul>\n <form class=\"d-flex\" role=\"search\">\n <input class=\"form-control me-2\" type=\"search\" placeholder=\"Search\" aria-label=\"Search\">\n <button class=\"btn btn-outline-success\" type=\"submit\">Search</button>\n </form>\n </div>\n </div>\n </nav>\n <h1 class=\"main-title\">TODO List</h1>\n <div class=\"container\">\n <div class=\"mb-3\">\n <label for=\"exampleFormControlInput1\" class=\"form-label\">Task Name</label>\n <input type=\"text\" class=\"form-control input\" id=\"exampleFormControlInput1\">\n </div>\n <div class=\"mb-3\">\n <label for=\"exampleFormControlTextarea1\" class=\"form-label\">Task Details</label>\n <textarea class=\"form-control input\" id=\"exampleFormControlTextarea1\" rows=\"3\"></textarea>\n </div>\n <button type=\"submit\" class=\"btn btn-primary\" id=\"main-btn\">Create TODO</button>\n <button type=\"button\" class=\"btn btn-warning\" id=\"clr\">Clear LocalStorage</button>\n </div>\n <div class=\"all-todo\"></div>\n \n\n <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js\"\n integrity=\"sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3\"\n crossorigin=\"anonymous\"></script>\n</body>\n<script>\n let button = document.getElementById(\"main-btn\")\n\n button.onclick = () => {\n // collect the div that contains all the todos\n let alltodo = document.querySelector(\".all-todo\");\n\n let key = document.getElementById(\"exampleFormControlInput1\").value\n let value = document.getElementById(\"exampleFormControlTextarea1\").value\n\n // and if it any todo create the card\n if (key != \"\" && value != \"\") {\n\n localStorage.setItem(key, value)\n // with create element we can create the card more easy\n var todo = document.createElement(\"div\");\n todo.setAttribute(\"class\", \"card\");\n\n\n var button = document.createElement(\"button\");\n button.textContent = \"eliminar\";\n\n\n var titulo = document.createElement(\"h5\");\n\n titulo.textContent = key;\n\n button.onclick = () => {\n console.log(button.parentElement.remove())\n // in this point we can also remove the todo from the local storage wih localstorage.removeItem()\n }\n\n // introduce all items in dom \n todo.appendChild(titulo)\n todo.appendChild(button);\n alltodo.appendChild(todo);\n // iHTML = \"\"\n // localStorage.setItem(key, value)\n // iHTML += `\n // <div class=\"card\" style=\"width: 18rem;\">\n // <div class=\"card-body\">\n // <h5 class=\"card-title\">${key}</h5>\n // <p class=\"card-text\">${localStorage.getItem(key)}</p>\n // <button type=\"button\" id=\"note\" onclick='${key}.innerHTML=\"\"' class=\"btn btn-danger '${key}'\">Delete</button>\n // </div>\n // </div>\n // `\n // document.getElementsByClassName(\"all-todo\")[0].innerHTML += iHTML\n \n }\n else {\n alert(\"Task Name or Details cannot be empty!\")\n }\n\n }\n\n let clr_btn = document.getElementById(\"clr\")\n clr_btn.onclick = () => {\n localStorage.clear()\n }\n\n</script>\n\n</html>"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19610056/"
] |
74,421,185 | <p>I have seen couple of solutions to 301 redirect non www http i.e. http://domain-name to <a href="https://www.domain-name" rel="nofollow noreferrer">https://www.domain-name</a> but all of them (in my experience) gives 2 redirects.</p>
<p>Either they first redirect from non www to www first and than http to https or in 2nd redirect first and than 1st redirect. One of the example of such code is:</p>
<pre><code>RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</code></pre>
<p>The best solution would be one 301 redirect which takes care of both i.e. non www as well as http part. Can anyone please suggest me the right code.</p>
<p>Best rgds,</p>
<p>Jai</p>
| [
{
"answer_id": 74421501,
"author": "arkascha",
"author_id": 1248114,
"author_profile": "https://Stackoverflow.com/users/1248114",
"pm_score": 0,
"selected": false,
"text": "RewriteEngine on\nRewriteCond %{HTTP_HOST} !^www\\. [OR]\nRewriteCond %{HTTPS} off\nRewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]\n"
},
{
"answer_id": 74423459,
"author": "Valeriu Ciuca",
"author_id": 4527645,
"author_profile": "https://Stackoverflow.com/users/4527645",
"pm_score": 3,
"selected": true,
"text": "# ensure www\nRewriteCond %{HTTP_HOST} !^www.example.com$ [NC]\nRewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]\n\n# ensure https\nRewriteCond %{HTTP:X-Forwarded-Proto} !https\nRewriteCond %{HTTPS} off\nRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3000006/"
] |
74,421,189 | <p>I have this function:</p>
<pre><code>def total_fruit_per_sort():
number_found = re.findall(total_amount_fruit_regex(), verdi50)
fruit_dict = {}
for n, f in number_found:
fruit_dict[f] = fruit_dict.get(f, 0) + int(n)
return pprint.pprint(str( {value: key for value, key in fruit_dict.items() }).replace("{", "").replace("}", "").replace("'", ""))
print(total_fruit_per_sort())
</code></pre>
<p>But it prints the values like: <code> 'Watermeloenen: 466, Appels: 688, Sinaasappels: 803'</code></p>
<p>But I want them under each other, like this:</p>
<pre><code>Watermeloenen: 466
Appels: 688
Sinaasappels: 803
</code></pre>
<p>Question: how to archive this?</p>
| [
{
"answer_id": 74421215,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 2,
"selected": true,
"text": "string"
},
{
"answer_id": 74421289,
"author": "gog",
"author_id": 3494774,
"author_profile": "https://Stackoverflow.com/users/3494774",
"pm_score": 2,
"selected": false,
"text": "pprint"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7713770/"
] |
74,421,199 | <p>first.py:</p>
<pre><code>from third import *
from second import *
while running:
off()
</code></pre>
<p>second.py:</p>
<pre><code>from third import *
def off():
running = False
</code></pre>
<p>third.py:</p>
<pre><code>running = True
</code></pre>
<p>The program still running and running variable is not accessed.</p>
<p>I want to calling a function which is in another file, the function change the boolean which is in another file. I know I can just type everything to the first file but I want separate files for functions and variables.</p>
<p>I expect to close the program after running.</p>
<p>I tried using global variables.
I read all similar questions.</p>
| [
{
"answer_id": 74421361,
"author": "quamrana",
"author_id": 4834,
"author_profile": "https://Stackoverflow.com/users/4834",
"pm_score": 2,
"selected": true,
"text": "running = False"
},
{
"answer_id": 74421366,
"author": "LakshyaK2011",
"author_id": 20192114,
"author_profile": "https://Stackoverflow.com/users/20192114",
"pm_score": 0,
"selected": false,
"text": "running = True\ndef getRunning():\n return running\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20104349/"
] |
74,421,203 | <p>I have a string that looks like this :</p>
<pre><code>my_sting="AC=1;AN=249706;AF=4.00471e-06;rf_tp_probability=8.55653e-01;"
</code></pre>
<p>it is based on a column in my data :</p>
<p><a href="https://i.stack.imgur.com/0AXa3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0AXa3.png" alt="enter image description here" /></a></p>
<pre><code> REF ALT QUAL FILTER INFO
1 C A 3817.77 PASS AN=2;AF=4.00471e06;rf_tp_probability=8.55653
2 C G 3817.77 PASS AN=3;AF=5;rf_tp_probability=8.55653
</code></pre>
<p>i wish to select only the part that start with AF= and ends with the number AF is equal to .
for example here: AF=4.00471e-06</p>
<p>I tried this :</p>
<pre><code>print(str_extract_all(my_sting, "AF=.+;"))
[[1]]
[1] "AF=4.00471e-06;rf_tp_probability=8.55653e-01;"
</code></pre>
<p>but it returned everything until the end. instead of returning AF=4.00471e-06
is there any way to fix this ? thank you</p>
| [
{
"answer_id": 74421361,
"author": "quamrana",
"author_id": 4834,
"author_profile": "https://Stackoverflow.com/users/4834",
"pm_score": 2,
"selected": true,
"text": "running = False"
},
{
"answer_id": 74421366,
"author": "LakshyaK2011",
"author_id": 20192114,
"author_profile": "https://Stackoverflow.com/users/20192114",
"pm_score": 0,
"selected": false,
"text": "running = True\ndef getRunning():\n return running\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12733891/"
] |
74,421,216 | <p>It seems my question is related to this <a href="https://stackoverflow.com/questions/71478038/select-storage-blob-data-contributor-role-to-azure-storage-account-and-assign">post</a> but since there is no answer I will ask again.</p>
<p>I have an Azure Devops project which I use to deploy static content into a container inside a Storage Account via Pipelines. I've recently decided to deploy my infrastructure using Terraform as well as my code but I'm running into an issue. I managed to create all my infrastructure with Terraform inside my Pipeline except for the Role Assignment.</p>
<p>I basically need to add a new Role Assignment to my Storage Account, through Azure it goes :</p>
<ol>
<li>Go to my <strong>Storage Account</strong></li>
<li>Go to <strong>Access Control (IAM)</strong></li>
<li>Add a new <strong>Role Assignments</strong></li>
<li>Select <strong>Storage Blob Data Contributor</strong></li>
<li>Click on <strong>Select members</strong></li>
<li>Select my <strong>Azure Devops Project</strong></li>
<li><strong>Review + assign</strong></li>
</ol>
<p>From what I understand in the <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment" rel="nofollow noreferrer">Terraform documentation</a> I should do something like this :</p>
<pre><code>resource "azurerm_resource_group" "resource_group" {
name = var.resource_group_name
location = var.location
}
resource "azurerm_storage_account" "storage_account" {
name = var.storage_account_name
resource_group_name = azurerm_resource_group.resource_group.name
location = azurerm_resource_group.resource_group.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_role_assignment" "role_assignment" {
scope = azurerm_storage_account.storage_account.id
role_definition_id = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe" # Which is the Storage Blob Data Contributor role if I'm not mistaken.
principal_id = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" # Which should be the Application ID ?
}
</code></pre>
<p>Except it doesn't work, when I try to run it in local without the Azure Pipeline to check if this works, the process is stuck in the "Still creating..." state for more than 10 minutes, which seems weird since when you do it manually it only takes up to a few seconds. I don't have any error I just end up canceling the command.</p>
<p>What am I missing / doing wrong here ?</p>
| [
{
"answer_id": 74421361,
"author": "quamrana",
"author_id": 4834,
"author_profile": "https://Stackoverflow.com/users/4834",
"pm_score": 2,
"selected": true,
"text": "running = False"
},
{
"answer_id": 74421366,
"author": "LakshyaK2011",
"author_id": 20192114,
"author_profile": "https://Stackoverflow.com/users/20192114",
"pm_score": 0,
"selected": false,
"text": "running = True\ndef getRunning():\n return running\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12624874/"
] |
74,421,217 | <p>My problem is, when I am trying to generate my Excel file
I have some cells contains the tickmark symbol.</p>
<pre><code> using (ExcelRange Rng = wsSheet.Cells[col])
{
Rng.Value = Beneficiary.IDentityOrFamilyBookCheck;// this value is ü
Rng.Style.Font.SetFromFont("Wingdings", 16);
Rng.Style.Font.Charset = 178;
}
</code></pre>
<p>in fact with the specified font and value it must appear as a check
but it is not</p>
<p>This is how it actually appears</p>
<p><a href="https://i.stack.imgur.com/v0Icx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v0Icx.png" alt="this is how it actually appears" /></a></p>
<p>This is how it must appear</p>
<p><a href="https://i.stack.imgur.com/1qCBI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1qCBI.png" alt="this is how it must appear" /></a></p>
| [
{
"answer_id": 74434901,
"author": "Behnam",
"author_id": 14356409,
"author_profile": "https://Stackoverflow.com/users/14356409",
"pm_score": 2,
"selected": true,
"text": "Rng.Style.Font.Charset = 2;"
},
{
"answer_id": 74456305,
"author": "Taha Babi",
"author_id": 13118588,
"author_profile": "https://Stackoverflow.com/users/13118588",
"pm_score": 0,
"selected": false,
"text": "Rng.Style.Font.Charset"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13118588/"
] |
74,421,230 | <p>I'm trying to convert a list to a single integer using two methods:</p>
<p><code>for</code> loop works fine and gives me the integer</p>
<pre><code>>>> a_list = "123456789"
>>> a_list = list(a_list)
>>> b_int = ""
>>> for num in a_list:
... b_int += num
...
>>> print(int(b_int))
123456789
</code></pre>
<p>however <code>join()</code> returns a ValueError</p>
<pre><code>>>> a_list = "123456789"
>>> c_int = ""
>>> c_int.join(a_list)
>>> print(int(c_int))
Traceback (most recent call last):
File "xxx.py", line 4, in <module>
print(int(c_int))
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
</code></pre>
<p>Why does <code>join()</code> returns a ValueError? It was suggested in a number of different posts as a better solution.</p>
| [
{
"answer_id": 74421276,
"author": "Luke",
"author_id": 6359829,
"author_profile": "https://Stackoverflow.com/users/6359829",
"pm_score": 0,
"selected": false,
"text": "list(\"123456789\")\nOut[6]: ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n[int(x) for x in list(\"123456789\")]\nOut[7]: [1, 2, 3, 4, 5, 6, 7, 8, 9]\nsum([int(x) for x in list(\"123456789\")])\nOut[8]: 45\n"
},
{
"answer_id": 74421291,
"author": "cards",
"author_id": 16462878,
"author_profile": "https://Stackoverflow.com/users/16462878",
"pm_score": 2,
"selected": true,
"text": "ValueError"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20372709/"
] |
74,421,239 | <p>I've installed ClearML test manager solution using ClearML Docker-Compose. So now the whole thing is running using 6 containers (webserver,apiserver,redis,elasticsearch,fileserver and mongodb). I'm running the default Cleanup Service - However the task is in pending state because there are no Workers configured for this queue. How do I configure a Worker for the default queue when ClearML is configured to run using Docker ?<a href="https://i.stack.imgur.com/AQhl9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AQhl9.png" alt="enter image description here" /></a></p>
<p>Tried to run in locally . not using Docker .</p>
| [
{
"answer_id": 74421276,
"author": "Luke",
"author_id": 6359829,
"author_profile": "https://Stackoverflow.com/users/6359829",
"pm_score": 0,
"selected": false,
"text": "list(\"123456789\")\nOut[6]: ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n[int(x) for x in list(\"123456789\")]\nOut[7]: [1, 2, 3, 4, 5, 6, 7, 8, 9]\nsum([int(x) for x in list(\"123456789\")])\nOut[8]: 45\n"
},
{
"answer_id": 74421291,
"author": "cards",
"author_id": 16462878,
"author_profile": "https://Stackoverflow.com/users/16462878",
"pm_score": 2,
"selected": true,
"text": "ValueError"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20491584/"
] |
74,421,250 | <p>I have two df's: one has a date in the first column: all dates of the last three years and the second column are names of participants, other columns are information.</p>
<p>In the second df, I have some dates on which we did tests in the first column, then second column the names again and more columns information.</p>
<p>I would like to combine the two dateframes that in the first dataframe the information from the second will be added but for example if we did one test on 2-9-2020 and the same test for the same person on 16-9-2022 then from 2-9-202 until 16-9-2022 i want that variable and after that the other.</p>
<p>I hope it's clear what i mean.</p>
<p>i tried
data.merge(data_2, on='Date' & 'About')
but that is not possible to give two columns for on.</p>
| [
{
"answer_id": 74421276,
"author": "Luke",
"author_id": 6359829,
"author_profile": "https://Stackoverflow.com/users/6359829",
"pm_score": 0,
"selected": false,
"text": "list(\"123456789\")\nOut[6]: ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n[int(x) for x in list(\"123456789\")]\nOut[7]: [1, 2, 3, 4, 5, 6, 7, 8, 9]\nsum([int(x) for x in list(\"123456789\")])\nOut[8]: 45\n"
},
{
"answer_id": 74421291,
"author": "cards",
"author_id": 16462878,
"author_profile": "https://Stackoverflow.com/users/16462878",
"pm_score": 2,
"selected": true,
"text": "ValueError"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492425/"
] |
74,421,292 | <p>I have 2 simple .txt files. One file contains a person's name and pay. The second file contains a person's name and job title.</p>
<p><strong>Data from first file...</strong></p>
<p>John Doe $750.00</p>
<p>Jane Doe $450.00</p>
<p>Sammy Joe $350.00</p>
<p><strong>Data from second file...</strong></p>
<p>John Doe (Store Manager)</p>
<p>Jane Doe (Asst Store Mngr)</p>
<p>Sammy Joe (Shift Manager)</p>
<p>I need to produce an output like: Persons Name (Job Title) ---- Pay</p>
<p>Example/
John Doe (Store Manager) ---- $450.00</p>
| [
{
"answer_id": 74421276,
"author": "Luke",
"author_id": 6359829,
"author_profile": "https://Stackoverflow.com/users/6359829",
"pm_score": 0,
"selected": false,
"text": "list(\"123456789\")\nOut[6]: ['1', '2', '3', '4', '5', '6', '7', '8', '9']\n[int(x) for x in list(\"123456789\")]\nOut[7]: [1, 2, 3, 4, 5, 6, 7, 8, 9]\nsum([int(x) for x in list(\"123456789\")])\nOut[8]: 45\n"
},
{
"answer_id": 74421291,
"author": "cards",
"author_id": 16462878,
"author_profile": "https://Stackoverflow.com/users/16462878",
"pm_score": 2,
"selected": true,
"text": "ValueError"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492754/"
] |
74,421,315 | <p>I wanted to make a function called fillArray to set up random values to the Array.
Then i wanted the function to output all the values but i kept getting values way above 99.</p>
<p>This is what i have written so far:</p>
<pre><code>#include <ctime>
#include <iostream>
using namespace std;
void fillArray(){
srand(time(NULL));
const unsigned int sizeOfArray = 10; // this sets the array to the constant size of 10
int numberArray[sizeOfArray]; //this sets the array to the size of 'sizeOfArray' which is 10
for(int i = 0; i < sizeOfArray; i++)
{
numberArray[i] = rand() % 100;
cout << numberArray[i] << endl;
}
}
int main (){
void fillArray(int a[10], int randNum);
cout << numberArray[0] << " , " << numberArray[1] << " , " << numberArray[2] << " , " << numberArray[3] << " , " << numberArray[4] << " , " << numberArray[5] << " , " << numberArray[6] << " , " << numberArray[7] << " , " << numberArray[8] << " , " << numberArray[9] << '\n';
}
</code></pre>
<p>I understand the name numberArray hasnt been declared in the main function but just wondered what to do.</p>
| [
{
"answer_id": 74421459,
"author": "Robert Shepherd",
"author_id": 19970913,
"author_profile": "https://Stackoverflow.com/users/19970913",
"pm_score": 1,
"selected": true,
"text": "main"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492736/"
] |
74,421,327 | <p>Using <code>import { useRouter } from "next/router";</code> as <code>import { useRouter } from "next/navigation";</code> throws "Argument of type '{ pathname: string; query: { search: string; }; }' is not assignable to parameter of type 'string'."</p>
<pre><code> const router = useRouter();
const [searchInput, setSearchInput] = useState("");
const search = (e) => {
router.push({
pathname: '/search',
query: {
search: searchInput,
},
})
}
</code></pre>
<p>NextJS <a href="https://nextjs.org/docs/api-reference/next/router#router-object" rel="noreferrer">documentation </a></p>
<p>Froms docs:
"A component used useRouter outside a Next.js application, or was rendered outside a Next.js application. This can happen when doing unit testing on components that use the useRouter hook as they are not configured with Next.js' contexts."</p>
| [
{
"answer_id": 74421398,
"author": "Elvin",
"author_id": 11743253,
"author_profile": "https://Stackoverflow.com/users/11743253",
"pm_score": 0,
"selected": false,
"text": "const router = useRouter();\n\nconst search = (e) => {\n const searchParams = {\n pathname: '/search',\n query: {\n search: e.target.value,\n },\n } as any\n router.push(searchParams)\n}\n"
},
{
"answer_id": 74423295,
"author": "Luccin",
"author_id": 19272088,
"author_profile": "https://Stackoverflow.com/users/19272088",
"pm_score": 0,
"selected": false,
"text": "npm uninstall next\n\nnpm install next@12.2.0\n"
},
{
"answer_id": 74493127,
"author": "ivo",
"author_id": 13820446,
"author_profile": "https://Stackoverflow.com/users/13820446",
"pm_score": 5,
"selected": true,
"text": "usePathname()"
},
{
"answer_id": 74672801,
"author": "Yilmaz",
"author_id": 10262805,
"author_profile": "https://Stackoverflow.com/users/10262805",
"pm_score": 0,
"selected": false,
"text": "import { useRouter } from \"next/router\";\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15293377/"
] |
74,421,329 | <p>I am trying to make a plot using St Louis Fed data, using the <code>fredr</code> package and the pipe (<code>%>%) command in </code>ggplot2<code>. I am struggling to use the </code>xlim()<code>or</code>lims()` command.</p>
<p>I can get the series I want to plot I with the following code.</p>
<pre><code>#libraries
library(tidyverse)
library(fredr)
library(ggthemes)
#make the plot
map_dfr(c("LABSHPUSA156NRUG", "W273RE1A156NBEA"), fredr) %>%
pivot_wider(
names_from = series_id,
values_from = value) %>%
mutate(., labour_share_of_profit = LABSHPUSA156NRUG/W273RE1A156NBEA)
</code></pre>
<p>So far so good. This gives me the data I need, with a new variable called <code>labour_share_of_profit</code>. The data (using <code>put()</code> is at the bottom of the question:</p>
<pre><code> > . + # A tibble: 93 × 6
date realtime_start realtime_end LABSHPUSA156NRUG W273RE1A156…¹ labou…²
<date> <date> <date> <dbl> <dbl> <dbl>
1 1950-01-01 2022-11-13 2022-11-13 0.628 5.7 0.110
2 1951-01-01 2022-11-13 2022-11-13 0.634 5 0.127
3 1952-01-01 2022-11-13 2022-11-13 0.645 5.1 0.126
4 1953-01-01 2022-11-13 2022-11-13 0.644 4.8 0.134
5 1954-01-01 2022-11-13 2022-11-13 0.637 5.2 0.123
6 1955-01-01 2022-11-13 2022-11-13 0.627 6.1 0.103
7 1956-01-01 2022-11-13 2022-11-13 0.640 5.6 0.114
8 1957-01-01 2022-11-13 2022-11-13 0.639 5.3 0.121
9 1958-01-01 2022-11-13 2022-11-13 0.636 4.8 0.132
10 1959-01-01 2022-11-13 2022-11-13 0.629 5.7 0.110
# … with 83 more rows, and abbreviated variable names ¹W273RE1A156NBEA,
# ²labour_share_of_profit
# ℹ Use `print(n = ...)` to see more rows
>
</code></pre>
<p>So to pipe this to the plotting code I use:
%>%</p>
<pre><code>ggplot(data = ., mapping = aes(x = date, y =labour_share_of_profit)) +
geom_line(lwd=1.2) +
labs(x = "Year", y = "Share of Labour Compensation as Proportion of Profit") +
theme(legend.position = "none") +
theme_wsj()
%>%
{ggsave(filename = "p1_wsj.pdf",
device = "pdf",
width = 10*sqrt(2), height = 10)
}
</code></pre>
<p>This produces the following plot.</p>
<p><a href="https://i.stack.imgur.com/WpSNn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WpSNn.png" alt="enter image description here" /></a></p>
<p>Now, how do I use the <code>xlim()</code> function to set the plot limits for the beginning of the series? The two comments below don't do the job. I think it may be because of the way the date information is stored, and how it needs to be passed to <code>ggplot</code>.</p>
<p>The data using <code>put</code> for reproducibility is:</p>
<pre><code>structure(list(date = structure(c(-7305, -6940, -6575, -6209,
-5844, -5479, -5114, -4748, -4383, -4018, -3653, -3287, -2922,
-2557, -2192, -1826, -1461, -1096, -731, -365, 0, 365, 730, 1096,
1461, 1826, 2191, 2557, 2922, 3287, 3652, 4018, 4383, 4748, 5113,
5479, 5844, 6209, 6574, 6940, 7305, 7670, 8035, 8401, 8766, 9131,
9496, 9862, 10227, 10592, 10957, 11323, 11688, 12053, 12418,
12784, 13149, 13514, 13879, 14245, 14610, 14975, 15340, 15706,
16071, 16436, 16801, 17167, 17532, 17897, -14975, -14610, -14245,
-13880, -13514, -13149, -12784, -12419, -12053, -11688, -11323,
-10958, -10592, -10227, -9862, -9497, -9131, -8766, -8401, -8036,
-7670, 18262, 18628), class = "Date"), realtime_start = structure(c(19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309), class = "Date"), realtime_end = structure(c(19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309, 19309,
19309, 19309), class = "Date"), LABSHPUSA156NRUG = c(0.628362894058228,
0.633731782436371, 0.644851565361023, 0.644496023654938, 0.637051999568939,
0.626844048500061, 0.640427887439728, 0.638684749603271, 0.635847270488739,
0.629354357719421, 0.636741697788239, 0.633703410625458, 0.629107296466827,
0.626384675502777, 0.624378800392151, 0.619359791278839, 0.622894942760468,
0.630079448223114, 0.634225606918335, 0.643875300884247, 0.64898556470871,
0.63764888048172, 0.639445066452026, 0.640666723251343, 0.640968561172485,
0.625560820102692, 0.62158989906311, 0.621596157550812, 0.622295022010803,
0.62261962890625, 0.624348878860474, 0.614216029644012, 0.616743326187134,
0.603852272033691, 0.601951777935028, 0.60230153799057, 0.607737004756927,
0.615972578525543, 0.62066638469696, 0.611858665943146, 0.615197896957397,
0.615098834037781, 0.620048463344574, 0.614196300506592, 0.607954382896423,
0.607377409934998, 0.607116162776947, 0.609609842300415, 0.623013257980347,
0.625988662242889, 0.637073159217834, 0.640336573123932, 0.629616677761078,
0.621445715427399, 0.617115139961243, 0.605635344982147, 0.605510890483856,
0.604003727436066, 0.604088604450226, 0.59113609790802, 0.587999582290649,
0.592656254768372, 0.595092236995697, 0.593056976795197, 0.594270586967468,
0.595646262168884, 0.593772530555725, 0.596151113510132, 0.594325959682465,
0.597091138362885, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), W273RE1A156NBEA = c(5.7,
5, 5.1, 4.8, 5.2, 6.1, 5.6, 5.3, 4.8, 5.7, 5.5, 5.4, 6.1, 6.4,
6.8, 7.4, 7.3, 6.8, 6.3, 5.4, 4.5, 5, 5.4, 5.1, 4, 4.7, 5.3,
5.7, 5.9, 5.2, 4, 4.7, 4.4, 5, 5.5, 5.5, 4.3, 4.3, 4.5, 4, 3.7,
4.3, 4.2, 4.4, 5.2, 5.5, 5.9, 6.3, 5.3, 5, 3.9, 3.9, 5.4, 6,
6.7, 6.7, 7, 5.6, 4.4, 5.8, 7.2, 7.2, 7.6, 7.4, 7.3, 6.9, 6.6,
6.8, 7.2, 7.3, 8.9, 7, 3.2, -0.9, -1.2, 2.6, 3.9, 5.6, 5.7, 4.2,
5.2, 6.7, 6, 5.4, 5.1, 5.2, 4.2, 3.7, 4.9, 6.5, 6.6, 7.2, 8.4
), labour_share_of_profit = c(0.110239104220742, 0.126746356487274,
0.126441483404122, 0.134270004928112, 0.122509999917104, 0.10276131942624,
0.114362122757094, 0.120506556528919, 0.132468181351821, 0.110413045213934,
0.11577121777968, 0.117352483449159, 0.103132343683086, 0.0978726055473089,
0.0918204118223751, 0.083697269091735, 0.085328074350749, 0.0926587423857521,
0.100670731256879, 0.119236166830416, 0.144219014379713, 0.127529776096344,
0.118415753046672, 0.125620926127714, 0.160242140293121, 0.13309804683036,
0.117281113030776, 0.109051957465055, 0.105473732544204, 0.119734544020433,
0.156087219715118, 0.130684261626386, 0.140168937769803, 0.120770454406738,
0.109445777806369, 0.10950937054374, 0.141334187152774, 0.143249436866405,
0.137925863265991, 0.152964666485786, 0.166269701880378, 0.143046240473903,
0.147630586510613, 0.139590068296953, 0.116914304403158, 0.110432256351818,
0.102901044538466, 0.0967634670318119, 0.117549671317047, 0.125197732448578,
0.163352092107137, 0.164188864903572, 0.116595681066866, 0.103574285904566,
0.0921067373076482, 0.0903933350719623, 0.086501555783408, 0.107857808470726,
0.137292864647779, 0.101920016880693, 0.0816666086514791, 0.0823133687178294,
0.0783016101310128, 0.0801428347020536, 0.081406929721571, 0.0863255452418673,
0.0899655349326856, 0.0876692813985488, 0.0825452721781201, 0.0817933066250527,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -93L), class = c("tbl_df",
"tbl", "data.frame"))
</code></pre>
| [
{
"answer_id": 74421377,
"author": "user14836563",
"author_id": 14836563,
"author_profile": "https://Stackoverflow.com/users/14836563",
"pm_score": 0,
"selected": false,
"text": "ggplot(data = ., mapping = aes(x = date, y =labour_share_of_profit)) +\ngeom_line(lwd=1.2) +\nscale_x_continuous(breaks=1950:2020) +\nlabs(x = \"Year\", y = \"Share of Labour Compensation as Proportion of Profit\") +\ntheme(legend.position = \"none\") +\ntheme_wsj()\n"
},
{
"answer_id": 74421427,
"author": "JAdel",
"author_id": 16236118,
"author_profile": "https://Stackoverflow.com/users/16236118",
"pm_score": 1,
"selected": false,
"text": "coord_cartesian"
},
{
"answer_id": 74423444,
"author": "stefan",
"author_id": 12993861,
"author_profile": "https://Stackoverflow.com/users/12993861",
"pm_score": 0,
"selected": false,
"text": "NA"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1519289/"
] |
74,421,352 | <p>I am developping an app to order food online. As backend service I am using firestore to store the data and files. The user can order dishes and there are limited stocks. So every time a user order a dish and <strong>create a basket</strong> I <strong>update</strong> the stock of the corresponding ordered dishes. I am using a firebase function in order to perform this action. To be honest it is the first I am creating firebase function.
Into the Basket object, there is a list of ordered Dishes with the corresponding database DishID. When the basket is created, I go through the DishID list and I update the Quantity in the firestore database. On my local emulator it works perfectly and very fast. But online it takes minutes to perform the first update. I can deal with some seconds. Even if it takes a few seconds (like for cold restart) it's okay. But sometimes it can take 3 minutes and someone else can order a dish during this time.</p>
<p>Here is my code:</p>
<pre><code>//Update the dishes quantities when a basket is created
exports.updateDishesQuantity = functions.firestore.document('/Baskets/{documentId}').onCreate(async (snap, context) => {
try{
//Get the created basket
const originalBasket = snap.data();
originalBasket.OrderedDishes.forEach(async dish => {
const doc = await db.collection('Dishes').doc(dish.DishID);
console.log('Doc created');
return docRef = doc.get()
.then((result) =>{
console.log('DocRef created');
if(result.exists){
console.log('Result exists');
const dishAvailableOnDataBase = result.data().Available;
console.log('Data created');
const newQuantity = { Available: Math.max(dishAvailableOnDataBase - dish.Quantity, 0)};
console.log('Online doc updated');
return result.ref.set(newQuantity, { merge: true });
}else{
console.log("doc doesnt exist");
}
})
.catch(error =>{
console.log(error);
return null;
});
});
}catch(error){
console.log(error);
}
});
</code></pre>
<p>I have a couple of logs output to debug the outputs on the server. It's the doc.get() function that takes 2 minutes to execute as you can see on the logger below:
<a href="https://i.stack.imgur.com/DaUxx.jpg" rel="nofollow noreferrer">Firebase logger</a></p>
<p>Thanks for your help,</p>
| [
{
"answer_id": 74546259,
"author": "Renaud Tarnec",
"author_id": 3371862,
"author_profile": "https://Stackoverflow.com/users/3371862",
"pm_score": 0,
"selected": false,
"text": "forEach()"
},
{
"answer_id": 74615970,
"author": "Florent Pausé",
"author_id": 13841095,
"author_profile": "https://Stackoverflow.com/users/13841095",
"pm_score": 2,
"selected": true,
"text": "//Update the dishes quantities when a basket is created\nexports.updateDishesQuantity = functions.firestore.document('/Baskets/{documentId}').onCreate(async (snap, context) => {\n\n try {\n //Get the created basket\n const originalBasket = snap.data();\n\n const promises = [];\n const quantities = [];\n originalBasket.OrderedDishes.forEach(dish => {\n promises.push(db.collection('Dishes').doc(dish.DishID).get());\n quantities.push(dish.Quantity);\n });\n const docSnapshotsArray = await Promise.all(promises);\n console.log(\"Promises\", promises);\n\n const promises1 = [];\n var i = 0;\n docSnapshotsArray.forEach(result => {\n if (result.exists) {\n const dishAvailableOnDataBase = result.data().Available;\n const newQuantity = { Available: Math.max(dishAvailableOnDataBase - quantities[i], 0) };\n promises1.push(result.ref.set(newQuantity, { merge: true }));\n }\n i++;\n })\n\n return Promise.all(promises1)\n\n } catch (error) {\n console.log(error);\n return null;\n }\n\n});\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13841095/"
] |
74,421,411 | <p>I want to make a custom text editing controller which will show the numbers of text in Farsi (Persian), but returns it with English numbers when you call <code>textEditingController.text</code>.</p>
<p>Here's what I have implemented but it seems like the TextField doesn't use the setter of <code>text</code>:</p>
<pre><code>class PersianTextEditingController extends TextEditingController {
@override
String get text => value.text.toEnglishNumbers;
@override
set text(String newText) {
value = value.copyWith(
text: newText.toPersianNumbers,
selection: const TextSelection.collapsed(offset: -1),
composing: TextRange.empty,
);
}
factory PersianTextEditingController({String? text}) =>
PersianTextEditingController._(text: text);
PersianTextEditingController._({String? text}) {
this.text = text ?? '';
}
}
</code></pre>
<p>Here's the TextField:</p>
<pre><code>PersianTextEditingController controller = PersianTextEditingController();
@override
Widget build(BuildContext context) {
return TextField(
controller: widget.controller,
);
}
</code></pre>
| [
{
"answer_id": 74546259,
"author": "Renaud Tarnec",
"author_id": 3371862,
"author_profile": "https://Stackoverflow.com/users/3371862",
"pm_score": 0,
"selected": false,
"text": "forEach()"
},
{
"answer_id": 74615970,
"author": "Florent Pausé",
"author_id": 13841095,
"author_profile": "https://Stackoverflow.com/users/13841095",
"pm_score": 2,
"selected": true,
"text": "//Update the dishes quantities when a basket is created\nexports.updateDishesQuantity = functions.firestore.document('/Baskets/{documentId}').onCreate(async (snap, context) => {\n\n try {\n //Get the created basket\n const originalBasket = snap.data();\n\n const promises = [];\n const quantities = [];\n originalBasket.OrderedDishes.forEach(dish => {\n promises.push(db.collection('Dishes').doc(dish.DishID).get());\n quantities.push(dish.Quantity);\n });\n const docSnapshotsArray = await Promise.all(promises);\n console.log(\"Promises\", promises);\n\n const promises1 = [];\n var i = 0;\n docSnapshotsArray.forEach(result => {\n if (result.exists) {\n const dishAvailableOnDataBase = result.data().Available;\n const newQuantity = { Available: Math.max(dishAvailableOnDataBase - quantities[i], 0) };\n promises1.push(result.ref.set(newQuantity, { merge: true }));\n }\n i++;\n })\n\n return Promise.all(promises1)\n\n } catch (error) {\n console.log(error);\n return null;\n }\n\n});\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16779388/"
] |
74,421,425 | <p>I am learning React and I am trying to simulate this design here: <a href="https://www.figma.com/file/QG4cOExkdbIbhSfWJhs2gs/Travel-Journal?node-id=2%3A2&t=LV3bLPEMOLMR8ksp-0" rel="nofollow noreferrer">https://www.figma.com/file/QG4cOExkdbIbhSfWJhs2gs/Travel-Journal?node-id=2%3A2&t=LV3bLPEMOLMR8ksp-0</a></p>
<p><a href="https://i.stack.imgur.com/cc8yU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cc8yU.png" alt="enter image description here" /></a></p>
<p>I started working on the project and I more or less finished it.</p>
<p><a href="https://i.stack.imgur.com/FRObc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FRObc.png" alt="enter image description here" /></a></p>
<p>However, I am having trouble</p>
<ol>
<li>Adding a line break after each <code>trip-div</code>. I thought I could do so on the ".map" cycle but it breaks. How should I approach it?</li>
</ol>
<pre><code>const trips = data.map(trip=>{
return (<Trip
item={trip}
/> <hr>)
})
</code></pre>
<ol start="2">
<li>For some reason the <code>trip-div</code> is not expanding 100% to the right. It must be something related to max-widht but I can't understand it.</li>
</ol>
<p>Here is my code: <a href="https://scrimba.com/scrim/c3rDMnUL" rel="nofollow noreferrer">https://scrimba.com/scrim/c3rDMnUL</a></p>
<p><code>Trip</code></p>
<pre><code>export default function Trip(prop){
return(
<div className='trip container'>
<div className="trip-main">
<img src={prop.item.imageUrl} alt="" className="trip-img" />
</div>
<div className="trip-aside">
<p className="trip-location">{prop.item.location} <a href={prop.item.googleMapsUrl} className="trip-google-maps">View on Maps</a></p>
<h2 className="trip-title">{prop.item.location}</h2>
<p className="trip-dates">{prop.item.startDate} - {prop.item.endDate}</p>
<p className="trip-description">{prop.item.description}</p>
</div>
</div>
)
}
</code></pre>
<p><code>App</code></p>
<pre><code>import { useState } from 'react'
import reactLogo from './assets/react.svg'
import Nav from "./components/Nav"
import Trip from "./components/Trip"
import data from '../src/assets/data'
const trips = data.map(trip=>{
return (<Trip
item={trip}
/>)
})
function App() {
const [count, setCount] = useState(0)
return (
<div className="App">
<Nav/>
{trips}
</div>
)
}
export default App
</code></pre>
<p>css</p>
<pre><code>* {box-sizing: border-box;}
#root{
max-width: 600px;
}
body{
margin: 0;
font-family: 'Inter';
background: #FFFFFF;
}
h1,h2,h3,p {
margin:0
}
.container {
padding: 0 40px;
}
nav {
height: 55px;
background: #F55A5A;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 2.5rem;
}
.nav-img {
margin-right: 7px;
}
.nav-title{
font-style: normal;
font-weight: 500;
font-size: 14.4608px;
line-height: 18px;
letter-spacing: -0.075em;
color: #FFFFFF;
}
.trip{
display: flex;
gap: 20px;
margin-bottom: 18px;
min-width: 100%;
}
.trip-main{
max-width: 40%;
}
.trip-aside{
max-width: 60%;
}
.trip-img{
width: 125px;
height: 168px;
border-radius: 5px;
}
.trip-location{
font-weight: 400;
font-size: 10.24px;
line-height: 12px;
letter-spacing: 0.17em;
color: #2B283A;
margin-bottom: 7px;
}
.trip-title{
font-weight: 700;
font-size: 25px;
line-height: 30px;
color: #2B283A;
margin-bottom: 7px;
padding-bottom: 10px;
}
.trip-dates{
font-weight: 700;
font-size: 10.24px;
line-height: 12px;
margin-bottom: 10px;
color: #2B283A;
}
.trip-google-maps{
font-weight: 400;
font-size: 10.24px;
line-height: 12px;
/* identical to box height */
text-decoration-line: underline;
color: #918E9B;
}
.trip-description{
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 10.24px;
line-height: 150%;
/* or 15px */
color: #2B283A;
}
</code></pre>
| [
{
"answer_id": 74421604,
"author": "Amaan Rizvi",
"author_id": 8745223,
"author_profile": "https://Stackoverflow.com/users/8745223",
"pm_score": 1,
"selected": false,
"text": "<div>"
},
{
"answer_id": 74421651,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "const trips = data.map(trip=>{\n return (<Trip\n item={trip}\n /> <hr>)\n})\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9958179/"
] |
74,421,435 | <p>The general form of the equation is</p>
<pre><code>Sector ~ Beta_0 + Beta_1*absMkt + Beta_2*sqMkt
</code></pre>
<p>where Sector are the daily stock returns of each of the 12 sectors i.e AUTO ; IT ; REALTY ; BANK ; ENERGY ; FINANCIAL SERVICES ; FMCG ; INFRASTRUCTURE ; SERVICES ; MEDIA ; METAL and PHARMA.</p>
<p>Beta_0 is the intercept; Beta_1 is the coefficient of absolute market return; Beta_2 is the coefficient of the squared market return.</p>
<p>For each sector, I would like to run linear regression, where I want to extract the coefficients Beta_1 and Beta_2 if the corresponding p-value is less than 0.05 and store it.</p>
<p>Sample data is stated below.</p>
<p>It is also available for download from my google drive location</p>
<p><a href="https://drive.google.com/drive/folders/16XUq8_lXXtD2BSlUdDAAWeHiWIznf--c?usp=share_link" rel="nofollow noreferrer">https://drive.google.com/drive/folders/16XUq8_lXXtD2BSlUdDAAWeHiWIznf--c?usp=share_link</a></p>
<p>Name of the file : Week_1_CSV.csv</p>
<p><a href="https://i.stack.imgur.com/P46Gz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P46Gz.png" alt="enter image description here" /></a></p>
<p>Code that I have tried from my end, but not getting the result</p>
<pre><code># Reading the data
Returns <- read.csv("Week_1_CSV.CSV", header = TRUE, stringsAsFactors = FALSE)
# Splitting the Data into Sector and Market Returns
Sector_Returns <- Returns[,2:13]
Market_Returns <- Returns[,14:15]
# Defining the number of sectors
nc <- ncol(Sector_Returns)
# Creating a matrix with zero value to store the coefficient values and their corresponding p-values
Beta_1 <- Beta_2 <- p_1 <- p_2 <- matrix(0, 1, nc) # coefs and p values
# Converting the Sectoral Returns into a Matrix named "Sect_Ret_Mat"
Sect_Ret_Mat <- as.matrix(Sector_Returns)
head(Sect_Ret_Mat)
# Converting the Market Returns into a Matrix named "Mkt_Ret_Mat"
Mkt_Ret_Mat <- as.matrix(Market_Returns)
head(Mkt_Ret_Mat)
#### Without Loop ##############
mode1_lm <- lm(Sect_Ret_Mat[,1] ~ Mkt_Ret_Mat[,1] + Mkt_Ret_Mat[,2] )
summary(mode1_lm)
# Extracting the p-value
coef(summary(mode1_lm))[2, 4] ## p-value corresponding to Beta_1
coef(summary(mode1_lm))[3, 4] ## p-value corresponding to Beta_2
# Extracting the Coefficient
coef(mode1_lm)[[2]] ## Coeficient corresponding to Beta_1
coef(mode1_lm)[[3]] ## Coeficient corresponding to Beta_2
##############################################################################
#### WithLoop ##############
for (i in 1:nc) {
for (j in 1:nc) {
if (i != j) {
mode1_lm <- lm(Sect_Ret_Mat[,i] ~ Mkt_Ret_Mat[,1] + Mkt_Ret_Mat[,2] )
p_0[i,j] <- coef(summary(mode1_lm))[2, 4]
p_1[i,j] <- coef(summary(mode1_lm))[3, 4]
if
(p_0[i, j] < 0.05)
Beta_0[i,j] <- coef(mode1_lm)[[2]]
if
(p_1[i, j] < 0.05)
Beta_1[i,j] <- coef(mode1_lm)[[3]]
}
}
}
Beta_0
Beta_1
</code></pre>
| [
{
"answer_id": 74421604,
"author": "Amaan Rizvi",
"author_id": 8745223,
"author_profile": "https://Stackoverflow.com/users/8745223",
"pm_score": 1,
"selected": false,
"text": "<div>"
},
{
"answer_id": 74421651,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "const trips = data.map(trip=>{\n return (<Trip\n item={trip}\n /> <hr>)\n})\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7011325/"
] |
74,421,471 | <p>im just a beginner and i want to find the answer to this problem.</p>
<p>This is my html code.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<input type = "text" name = "step" id = "step">
<button onclick="myFunction()">Submit</button>
<p id = "demo"></p>
</body>
</html>
</code></pre>
<p>This is my javascript code.</p>
<pre><code>var step = document.getElementById("step").innerHTML;
parseInt(step);
function matchHouses(step) {
var num = 0;
var one = 1;
while (num != step){
one += 5;
num++;
}
return one;
}
function myFunction(){
document.getElementById("demo").innerHTML = matchHouses(step);
}
</code></pre>
<p>What I did is to call the function matchHouses(step) by the click of the button. But the output is always 1. I also put parseInt to the step id as it is string but it is still doesnt work. I was expecting an output of 1+5 if the input is 1, 1+5+5 if the input is two and so on. How do I make it work?</p>
| [
{
"answer_id": 74421604,
"author": "Amaan Rizvi",
"author_id": 8745223,
"author_profile": "https://Stackoverflow.com/users/8745223",
"pm_score": 1,
"selected": false,
"text": "<div>"
},
{
"answer_id": 74421651,
"author": "Mohammed Ahmed",
"author_id": 4292093,
"author_profile": "https://Stackoverflow.com/users/4292093",
"pm_score": 0,
"selected": false,
"text": "const trips = data.map(trip=>{\n return (<Trip\n item={trip}\n /> <hr>)\n})\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492814/"
] |
74,421,477 | <p>I'm writing a sidebar which displays additional information based on selected row/cell by user. It's rendering fine on sidebar open, but if the user changes active cell, I need to update content.</p>
<p>Apparently, I can add a "refresh" button in sidebar, but I really want to avoid clicking "refresh" every time. Putting it on timer also isn't very good cause will just spam with unnecessary requests to sheet app.</p>
<p>Has anyone ever did something similar and that approach did you use?</p>
<p>Maybe it's possible somehow to get event about user changing active cell into the sidebar javascript code?</p>
| [
{
"answer_id": 74430108,
"author": "Jacques-Guzel Heron",
"author_id": 11861954,
"author_profile": "https://Stackoverflow.com/users/11861954",
"pm_score": 1,
"selected": false,
"text": "onSelectionChange"
},
{
"answer_id": 74432422,
"author": "TheWizEd",
"author_id": 3656739,
"author_profile": "https://Stackoverflow.com/users/3656739",
"pm_score": 3,
"selected": true,
"text": "<!DOCTYPE html>\n<html>\n <head>\n <base target=\"_top\">\n </head>\n <body>\n <textarea id=\"textArea\" rows=\"10\" cols=\"35\" onmouseenter=\"onMouseEnter()\">\n </textarea>\n <?!= include('JS_Sidebar'); ?> \n </body>\n</html>\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1300518/"
] |
74,421,482 | <p>I've searched SO and google for a similar question, but couldn't find the exact thing I'm searching.</p>
<p>I'm developing an application that queries an API that returns the following result:</p>
<pre class="lang-json prettyprint-override"><code>{
"Ticket": {
"1": {
"DisplayName": "Ticket ID",
"Value": 117
},
"2": {
"DisplayName": "Last Modified",
"Value": "2022-10-05T18:09:32.1070000Z"
},
"3": {
"DisplayName": "Last User",
"Value": "SYSTEMACCOUNT"
},
"4": {
"DisplayName": "Seq_Group",
"Value": 1
},
...
}
}
</code></pre>
<p>And I want to deserialize it to an object like the following:</p>
<pre class="lang-cs prettyprint-override"><code>public class Ticket
{
public property int TicketID {get; set;}
public property DateTime LastModified {get; set;}
public property string LastUser {get; set;}
public property int Seq_Group {get; set;}
}
</code></pre>
<p>(there are several more properties hidden here for brevity)</p>
<p>Can you point me to the direction on how to do that mapping the best way?</p>
<p>I know I could deserialize it to a Dictionary and then iterate the dictionary with several ifs and elses, but I think there must be a smarter way to solve it.</p>
<p>Thanks!</p>
| [
{
"answer_id": 74430108,
"author": "Jacques-Guzel Heron",
"author_id": 11861954,
"author_profile": "https://Stackoverflow.com/users/11861954",
"pm_score": 1,
"selected": false,
"text": "onSelectionChange"
},
{
"answer_id": 74432422,
"author": "TheWizEd",
"author_id": 3656739,
"author_profile": "https://Stackoverflow.com/users/3656739",
"pm_score": 3,
"selected": true,
"text": "<!DOCTYPE html>\n<html>\n <head>\n <base target=\"_top\">\n </head>\n <body>\n <textarea id=\"textArea\" rows=\"10\" cols=\"35\" onmouseenter=\"onMouseEnter()\">\n </textarea>\n <?!= include('JS_Sidebar'); ?> \n </body>\n</html>\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4519548/"
] |
74,421,484 | <p>I have a py-spark code running in Azure databricks. I have a spark dataframe with 20 numerical columns, named column1, column2, ...column20.
I have to calculate the Zscore(<code>from scipy.stats import zscore</code>) of these 20 columns, for that I am reading these 20 columns as numpy array.</p>
<p>But this collect is causing the spark cluster to restart, I understand collect is trying to bring the entire data set into a driver, do we have an alternative approach for solving this problem?</p>
<p>I can increase the driver node memory or I can think of using memory optimized VM for the driver, but do we have an alternative without a higher infra?</p>
<p>Below is the code snippet to create the sample dataframe.</p>
<pre><code>import databricks.koalas as ks
import pandas as pd
import random
import numpy as np
from scipy.stats import zscore
df = ks.DataFrame.from_dict({
'Column1': [random.randint(0, 100000) for i in range(15000000)],
'Column2': [random.randint(0, 100000) for i in range(15000000)],
'Column3': [random.randint(0, 100000) for i in range(15000000)],
'Column4': [random.randint(0, 100000) for i in range(15000000)],
'Column5': [random.randint(0, 100000) for i in range(15000000)],
'Column6': [random.randint(0, 100000) for i in range(15000000)],
'Column7': [random.randint(0, 100000) for i in range(15000000)],
'Column8': [random.randint(0, 100000) for i in range(15000000)],
'Column9': [random.randint(0, 100000) for i in range(15000000)],
'Column10': [random.randint(0, 100000) for i in range(15000000)],
'Column11': [random.randint(0, 100000) for i in range(15000000)],
'Column12': [random.randint(0, 100000) for i in range(15000000)],
'Column13': [random.randint(0, 100000) for i in range(15000000)],
'Column14': [random.randint(0, 100000) for i in range(15000000)],
'Column15': [random.randint(0, 100000) for i in range(15000000)],
'Column16': [random.randint(0, 100000) for i in range(15000000)],
'Column17': [random.randint(0, 100000) for i in range(15000000)],
'Column18': [random.randint(0, 100000) for i in range(15000000)],
'Column19': [random.randint(0, 100000) for i in range(15000000)],
'Column20': [random.randint(0, 100000) for i in range(15000000)]
})
df_spark=df.to_spark()
stats_array = np.array(df_spark.select('Column1', 'Column2', 'Column3', 'Column4', 'Column5', 'Column6', 'Column7', 'Column8', 'Column9', 'Column10', 'Column11', 'Column12', 'Column13', 'Column14', 'Column15', 'Column16','Column17','Column18','Column19','Column20').collect()) #causing out of memory error
normalized_data = zscore(stats_array, axis=0)
normalized_data_remnan = np.nan_to_num(normalized_data)
normalized_df = pd.DataFrame(data=normalized_data_remnan, columns=['Column1', 'Column2', 'Column3', 'Column4', 'Column5', 'Column6', 'Column7', 'Column8', 'Column9', 'Column10', 'Column11', 'Column12', 'Column13', 'Column14', 'Column15', 'Column16','Column17','Column18','Column19','Column20'])
normalized_df['sq_dist'] = [np.linalg.norm(i) for i in normalized_data_remnan]
</code></pre>
<p>Is there a better way of doing this without getting all the columns as a numpy array in driver? I would appreciate your suggestions on this.</p>
| [
{
"answer_id": 74428417,
"author": "Ric S",
"author_id": 7465462,
"author_profile": "https://Stackoverflow.com/users/7465462",
"pm_score": 2,
"selected": true,
"text": "collect"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8229793/"
] |
74,421,500 | <p>I'm trying to visualize data where each X value has multiple Y values and I would like to distinguish each Y value visaully. This is the example code</p>
<pre><code>xLables = ['A1','A2','A3','A4','A5']
YValues = [[1,2,3,4],[1,2,3,4,5,6,7],[1,2,3],[5,6,7],[1,2,3]]
X = [xLables[i] for i, data in enumerate(YValues) for j in range(len(data))]
Y = [val for data in YValues for val in data]
plt.scatter(X, Y)
plt.grid()
plt.show()
</code></pre>
<p>When I plot this , I get the following attached</p>
<p><a href="https://i.stack.imgur.com/3xtfd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3xtfd.png" alt="enter image description here" /></a></p>
<p>Each X label has corresponding Y values ... For Ex: A1 has 1,2,3,4 , A2 has 1,2,3,4,5,6,7 and so on</p>
<p>I have two questions on this one</p>
<p>(1) Can I have different markers for different Y-values .. all 1's are stars , all 2's are diamonds , all 10's are circles ?</p>
<p>something like this may be</p>
<p><a href="https://i.stack.imgur.com/0KuH6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0KuH6.png" alt="enter image description here" /></a></p>
<p>(2) Is there a better way to plot such 2D data and distingush them where each X has multiple Y values</p>
<p>Any suggestions/help is highly appreciated</p>
<p>Thanks</p>
<p>I tried to add markers and different colors , but they apply to all Y values for each X .. but not specific to each Y values..</p>
| [
{
"answer_id": 74421575,
"author": "1Pre",
"author_id": 20416697,
"author_profile": "https://Stackoverflow.com/users/20416697",
"pm_score": 0,
"selected": false,
"text": "plt.scatter([1, 2, 3]"
},
{
"answer_id": 74421706,
"author": "Bhargav",
"author_id": 15358800,
"author_profile": "https://Stackoverflow.com/users/15358800",
"pm_score": 2,
"selected": false,
"text": "from matplotlib import pyplot as plt\nimport matplotlib\n\nxLables = ['A1','A2','A3','A4','A5']\n\nYValues = [[1,2,3,4],[1,2,3,4,5,6,7],[1,2,3],[5,6,7],[1,2,3]]\nX = [xLables[i] for i, data in enumerate(YValues) for j in range(len(data))]\nY = [val for data in YValues for val in data]\n\nplt.scatter(X, Y, marker=matplotlib.markers.CARETDOWNBASE)\nplt.grid()\n\nmarkers=['8','+', '.', 'o', '*','^', 's', 'p', 'h','8','+', '.', 'o', '*','^', 's', 'p', 'h' ]\nfor i in range(18):\n plt.plot(X[i], Y[i], marker=markers[i])\n plt.xlabel('X Label')\n plt.ylabel('Y Label') \nplt.show()\n"
},
{
"answer_id": 74421852,
"author": "gboffi",
"author_id": 2749397,
"author_profile": "https://Stackoverflow.com/users/2749397",
"pm_score": 2,
"selected": false,
"text": "import matplotlib.pyplot as plt\n\nlabels = ['A1','A2','A3','A4','A5']\nY2D = [[1,2,3,4],[1,2,3,4,5,6,7],[1,2,3],[5,6,7],[1,2,3]]\n\n# prepare a dictionary with the characteristics\n# we want to change according to the Y value\nd = {1:dict(marker=\"*\", s=150, color=\"red\"),\n 2:dict(marker=\"o\", s=100, color=\"yellow\"),\n 3:dict(marker=\"o\", s= 60, color=\"blue\"),\n 4:dict(marker=\"o\", s=100, color=\"green\"),\n 5:dict(marker=\"o\", s=100, color=\"red\"),\n 6:dict(marker=\"*\", s=150, color=\"blue\"),\n 7:dict(marker=\"o\", s=100, color=\"lightgray\")}\n# an outer loop on the abscissae and the lists of Y values\nfor x, ys in zip(labels, Y2D):\n an inner loop on the Y values, plotted separately\n for y in ys:\n # here the point is to unpack the values contained\n # in the \"inner\" dictionary, addressing the outer by Y\n # zorder=5 places the dots above the grid\n plt.scatter(x, y, ec='k', zorder=5, **d[y])\nplt.grid(1)\nplt.show()\n"
},
{
"answer_id": 74424317,
"author": "user3435121",
"author_id": 3435121,
"author_profile": "https://Stackoverflow.com/users/3435121",
"pm_score": 1,
"selected": false,
"text": "import matplotlib.pyplot as plt\nxLables = [ 'A1','A2','A3','A4','A5']\nYValues = [ [1,2,3,4],[1,2,3,4,5,6,7],[1,2,3],[5,6,7],[1,2,3]]\nmarkers = [ '.', 'o', '^', 'v', '>', '<', '*'] # to be customized\nY = [None for i in range( len( xLables))]\n\nfor y in range( len( markers)):\n for x in range( len( xLables)):\n Y[x] = y+1 if y+1 in YValues[x] else None # values start at 1\n if any( Y): # something to display?\n plt.scatter( xLables, Y, marker=markers[y])\nplt.grid()\nplt.show()\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11578518/"
] |
74,421,538 | <p>I am trying to set 2 columns by a condition on a 3rd column. I can set 1 column conditions on another column, and I can set 2 columns on a single condition value, but when I try to set 2 columns by a condition on a column, it fails.</p>
<p>Here is the code example:</p>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
import numpy as np
AAA = {"column A": [1, 1, 1, 2, 2, 2, 3, 3, 3]}
df = pd.DataFrame(AAA)
</code></pre>
<p>If I call:</p>
<pre class="lang-py prettyprint-override"><code>df["column B"], df["column C"] = np.where(True ,['4', '8'],['NaN', 'NaN'])
</code></pre>
<p>I get:</p>
<pre class="lang-none prettyprint-override"><code>df
column A column B column C
0 1 4 8
1 1 4 8
2 1 4 8
3 2 4 8
4 2 4 8
5 2 4 8
6 3 4 8
7 3 4 8
8 3 4 8
</code></pre>
<p>so I know I can fill 2 columns based on a condition.</p>
<p>If I call:</p>
<pre class="lang-py prettyprint-override"><code>df["column B"] = np.where( df["column A"] == 2 ,['4'],['NaN'])
</code></pre>
<p>I get:</p>
<pre class="lang-none prettyprint-override"><code> column A column B column C
0 1 NaN 8
1 1 NaN 8
2 1 NaN 8
3 2 4 8
4 2 4 8
5 2 4 8
6 3 NaN 8
7 3 NaN 8
8 3 NaN 8
</code></pre>
<p>so I know I can fill based on a condition on a column. (I assume this is treated as a boolean array)</p>
<p>However, If I call:</p>
<pre class="lang-py prettyprint-override"><code>df["column B"], df["column C"] = np.where( df["column A"] == 2 ,['4', '8'],['NaN', 'NaN'])
</code></pre>
<p>I expect to get</p>
<pre class="lang-none prettyprint-override"><code> column A column B column C
0 1 NaN NaN
1 1 NaN NaN
2 1 NaN NaN
3 2 4 8
4 2 4 8
5 2 4 8
6 3 NaN NaN
7 3 NaN NaN
8 3 NaN NaN
</code></pre>
<p>but I actually get:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
... pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<string>", line 2, in <module>
File "<__array_function__ internals>", line 6, in where
ValueError: operands could not be broadcast together with shapes (9,) (2,) (2,)
</code></pre>
<p>Is there a way to do what I am trying to do?
I don't want to use 2 separate calls, because the dataframes I need this for are very large.</p>
| [
{
"answer_id": 74421615,
"author": "C-3PO",
"author_id": 4667669,
"author_profile": "https://Stackoverflow.com/users/4667669",
"pm_score": 1,
"selected": false,
"text": "np.where"
},
{
"answer_id": 74421720,
"author": "Panda Kim",
"author_id": 20430449,
"author_profile": "https://Stackoverflow.com/users/20430449",
"pm_score": 2,
"selected": false,
"text": "loc"
},
{
"answer_id": 74421723,
"author": "ScottC",
"author_id": 20174226,
"author_profile": "https://Stackoverflow.com/users/20174226",
"pm_score": 0,
"selected": false,
"text": "import pandas as pd\nimport numpy as np\n\nAAA={\"column A\": [1, 1, 1, 2, 2, 2, 3, 3, 3]}\ndf = pd.DataFrame(AAA)\n\ncol_length = len(df['column A'])\nfours = np.repeat(4, col_length, axis =0)\neights = np.repeat(8, col_length, axis =0)\nempties = np.repeat(np.nan, col_length, axis =0)\n\ndf[\"column B\"], df[\"column C\"] = np.where( df[\"column A\"] == 2 ,[fours, eights], [empties, empties])\nprint(df)\n"
},
{
"answer_id": 74421869,
"author": "D.Manasreh",
"author_id": 7509907,
"author_profile": "https://Stackoverflow.com/users/7509907",
"pm_score": 1,
"selected": true,
"text": "# Reshape the condition, then transpose the output.\ndf[\"column B\"], df[\"column C\"] = np.where( np.array(df[\"column A\"] == 2).reshape(-1,1) ,['4', '8'],['NaN', 'NaN']).T\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20492643/"
] |
74,421,540 | <ul>
<li>Create an employee class with the following members: name, age, id, salary</li>
<li>setData() - should allow employee data to be set via user input</li>
<li>getData()- should output employee data to the console</li>
<li>create a list of 5 employees. You can create a list of objects in the following way, appending the objects to the lists.</li>
</ul>
<pre><code> emp_object = []
for i in range(5):
emp_ object.append(ClassName())
</code></pre>
<p>I'm trying to do this exercise and this is what I got:</p>
<pre><code>class employee:
def __init__(self, n = None, a = None, i = None, s = None):
self.name = n
self.age = a
self.id = i
self.salary = s
def setData(self):
self.n = input("Enter name: ")
self.a = int(input("Enter age: "))
self.i = int(input("Enter id: "))
self.s = int(input("Enter salary: "))
self.getData()
def getData(self):
print("Name:", self.name, self.age, self.id, self.salary)
e1 = employee()
e1.setData()
e2 = employee()
e2.setData()
e3 = employee()
e3.setData()
e4 = employee()
e4.setData()
e5 = employee()
e5.setData()
emp_object = []
for i in range(5):
emp_object.append(employee())
print(emp_object)
</code></pre>
<p>It prints the employee details as "None" and I need help to create a list</p>
<p>Expected Output:</p>
<pre><code>Name id Age Salary
AAA 20 1 2000
BBB 22 2 2500
CCC 20 3 1500
DDD 22 4 3500
EEE 22 5 4000
</code></pre>
| [
{
"answer_id": 74421709,
"author": "Eloi",
"author_id": 11591599,
"author_profile": "https://Stackoverflow.com/users/11591599",
"pm_score": 0,
"selected": false,
"text": "class Employee:\n def __init__(self, uid=None, name=None, age=None, salary=None):\n self.name = name\n self.age = age\n self.id = uid\n self.salary = salary\n"
},
{
"answer_id": 74421731,
"author": "D.Manasreh",
"author_id": 7509907,
"author_profile": "https://Stackoverflow.com/users/7509907",
"pm_score": 1,
"selected": false,
"text": "class employee:\n def __init__(self, n = None, a = None, i = None, s = None):\n self.name = n\n self.age = a\n self.id = i\n self.salary = s\n def setData(self):\n self.name = input(\"Enter name: \")\n self.age = int(input(\"Enter age: \"))\n self.id = int(input(\"Enter id: \"))\n self.salary = int(input(\"Enter salary: \"))\n self.getData()\n def getData(self):\n print(\"Name:\", self.name, self.age, self.id, self.salary)\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20372089/"
] |
74,421,560 | <p>Hello i write on a rating button and i wanted to change the background color from the button after i clicked it but my code does nothing.</p>
<pre><code> <ul>
<li><button class="btn"><p id="num">1</p></button></li>
<li><button class="btn"><p id="num">2</p></button></li>
<li><button class="btn"><p id="num">3</p></button></li>
<li><button class="btn"><p id="num">4</p></button></li>
<li><button class="btn"><p id="num">5</p></button></li>
</ul>
-----
const btn = document.querySelector('.btn');
btn.addEventListener('click', function onClick(){
btn.style.backgroundColor = 'orange';
});
</code></pre>
| [
{
"answer_id": 74421616,
"author": "The KNVB",
"author_id": 2018278,
"author_profile": "https://Stackoverflow.com/users/2018278",
"pm_score": 0,
"selected": false,
"text": "const btnList = document.querySelectorAll('.btn');\n\n btnList.forEach(btn => {\n btn.addEventListener('click', function onClick() {\n btn.style.backgroundColor = 'orange';\n });\n})\n"
},
{
"answer_id": 74421627,
"author": "Abbas Shaikh",
"author_id": 12667283,
"author_profile": "https://Stackoverflow.com/users/12667283",
"pm_score": 0,
"selected": false,
"text": "querySelectorAll"
},
{
"answer_id": 74421652,
"author": "Amaan Rizvi",
"author_id": 8745223,
"author_profile": "https://Stackoverflow.com/users/8745223",
"pm_score": 2,
"selected": true,
"text": "const btn = document.querySelector('.btn');"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19156627/"
] |
74,421,617 | <p>This script loops and even if it crashes it restarts.</p>
<p>Now I want it to restart the script even if it has NOT CRASHED yet.</p>
<pre><code>while True:
try:
do_main_logic()
except:
pass
</code></pre>
<p>I have the loop that restart on crash, but I want it to restart on 60 seconds.</p>
| [
{
"answer_id": 74421616,
"author": "The KNVB",
"author_id": 2018278,
"author_profile": "https://Stackoverflow.com/users/2018278",
"pm_score": 0,
"selected": false,
"text": "const btnList = document.querySelectorAll('.btn');\n\n btnList.forEach(btn => {\n btn.addEventListener('click', function onClick() {\n btn.style.backgroundColor = 'orange';\n });\n})\n"
},
{
"answer_id": 74421627,
"author": "Abbas Shaikh",
"author_id": 12667283,
"author_profile": "https://Stackoverflow.com/users/12667283",
"pm_score": 0,
"selected": false,
"text": "querySelectorAll"
},
{
"answer_id": 74421652,
"author": "Amaan Rizvi",
"author_id": 8745223,
"author_profile": "https://Stackoverflow.com/users/8745223",
"pm_score": 2,
"selected": true,
"text": "const btn = document.querySelector('.btn');"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20493043/"
] |
74,421,655 | <p>After merging three datasets I've got a mess. There is a unique <code>id</code> field and then there can be one or more samples associated with each <code>id</code>. So far I've got</p>
<pre><code>samples <- structure(list(id = c(1029459, 1029459, 1029459, 1029459, 1030272,
1030272, 1030272, 1032157, 1032157, 1032178, 1032178, 1032219,
1032219, 1032229, 1032229, 1032494, 1032494, 1032780, 1032780
), sample1 = c(853401, 853401, 853401, 853401, 852769, 852769,
852769, 850161, 850161, 852711, 852711, 852597, 852597, 850363,
850363, 850717, 850717, 848763, 848763), sample2 = c(853401,
853693, 853667, 853667, 852769, 853597, 853597, NA, NA, 852711,
853419, 852597, 852597, 850363, 852741, 850717, 851811, 848763,
848763), sample3 = c(NA, NA, NA, NA, NA, NA, NA, 853621, 852621,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -19L))
print(samples)
#> # A tibble: 19 × 4
#> id sample1 sample2 sample3
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1029459 853401 853401 NA
#> 2 1029459 853401 853693 NA
#> 3 1029459 853401 853667 NA
#> 4 1029459 853401 853667 NA
#> 5 1030272 852769 852769 NA
#> 6 1030272 852769 853597 NA
#> 7 1030272 852769 853597 NA
#> 8 1032157 850161 NA 853621
#> 9 1032157 850161 NA 852621
#> 10 1032178 852711 852711 NA
#> 11 1032178 852711 853419 NA
#> 12 1032219 852597 852597 NA
#> 13 1032219 852597 852597 NA
#> 14 1032229 850363 850363 NA
#> 15 1032229 850363 852741 NA
#> 16 1032494 850717 850717 NA
#> 17 1032494 850717 851811 NA
#> 18 1032780 848763 848763 NA
#> 19 1032780 848763 848763 NA
</code></pre>
<p>I'd like to get it so that all unique samples per id are combined into one <code>sample</code> column with a long dataframe. eg</p>
<pre><code>id sample
1029459 853401
1029459 853693
1030272 852769
1030272 853597
1032157 850161
1032157 853621
</code></pre>
<p>Any ideas?</p>
| [
{
"answer_id": 74421753,
"author": "JAdel",
"author_id": 16236118,
"author_profile": "https://Stackoverflow.com/users/16236118",
"pm_score": 3,
"selected": true,
"text": "1029459"
},
{
"answer_id": 74421818,
"author": "langtang",
"author_id": 4447540,
"author_profile": "https://Stackoverflow.com/users/4447540",
"pm_score": 0,
"selected": false,
"text": "library(data.table)\nunique(melt(setDT(samples), \"id\",value.name = \"sample\")[!is.na(sample),c(1,3)])\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2930596/"
] |
74,421,678 | <p>I don't really know what am I supposed to do with it.</p>
<p>For each file in the /etc directory whose name starts with the o or l and the second letter and the second letter of the name is t or r, display its name, size and type ('file'/'directory'/'link'). Use: wildcard, for loop and conditional statement for the type.</p>
<pre class="lang-bash prettyprint-override"><code>#!/bin/bash
etc_dir=$(ls -a /etc/ | grep '^o|^l|^.t|^.r')
for file in $etc_dir
do
stat -c '%s-%n' "$file"
done
</code></pre>
<p>I was thinking about something like that but I have to use if statement.</p>
| [
{
"answer_id": 74421817,
"author": "Vab",
"author_id": 17600005,
"author_profile": "https://Stackoverflow.com/users/17600005",
"pm_score": 2,
"selected": false,
"text": "find"
},
{
"answer_id": 74422095,
"author": "Daniel Trugman",
"author_id": 1030410,
"author_profile": "https://Stackoverflow.com/users/1030410",
"pm_score": 0,
"selected": false,
"text": "ls -a /etc/ | grep '^o|^l|^.t|^.r'\n"
},
{
"answer_id": 74426852,
"author": "Bach Lien",
"author_id": 3973676,
"author_profile": "https://Stackoverflow.com/users/3973676",
"pm_score": 0,
"selected": false,
"text": "shopt -s extglob\nls -dp /etc/@(o|l)@(t|r)* | grep -v '/$'\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421678",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20493053/"
] |
74,421,685 | <p>My problem is with Futures, because they should be obtained before build() method executed, as the documentation states:</p>
<blockquote>
<p>The future must be obtained earlier, because if the future is created
at the same time as the FutureBuilder, then every time the
FutureBuilder's parent is rebuilt, the asynchronous task will be
restarted.</p>
</blockquote>
<p>I know that Futures should be called in initstate() function before the build method executed, but my case is different.</p>
<p>I want to get data from api as a Future, but the request I am sending to the api needs some parameters that user should select inside the screen's build() method.</p>
<p>And I don't know what the parameter of the request will be until user selects in build() method, and I have to call the api in the build() method and use FutureBuilder there, but that makes FutureBuilder to get constantly called, and I don't want that.</p>
<p>basically, I don't want to call FutureBuilder indefinetely, and I can't put my Future inside initState() because the Future needs some parameters that user later selects when the screen is shown inside build() method.</p>
<p>inside the build method:</p>
<pre><code>FutureBuilder<List<LatLng>>(
builder: (context, snapshot) {
if (snapshot.hasData) {
return PolylineLayer(
polylines: [
Polyline(
points: snapshot.data!,
strokeWidth: 4,
color: Colors.purple),
],
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
} else {
return Container();
}
},
future: Provider.of<NavigationProvider>(context)
.getNavigationPoints(pointToGoTo!),
),
</code></pre>
<p>now if you look at the code, at the final lines, I am sending the parameter pointToGoTo to the function which calls the backend.</p>
<p>simply, I want to get rid of calling api and getting data back as a Future inside build method, I want to do it in initState or somewhere else that prevents the build methods calling backend indefinitely.</p>
<p>is there any way to fix this problem?
Thanks in advance.</p>
| [
{
"answer_id": 74421817,
"author": "Vab",
"author_id": 17600005,
"author_profile": "https://Stackoverflow.com/users/17600005",
"pm_score": 2,
"selected": false,
"text": "find"
},
{
"answer_id": 74422095,
"author": "Daniel Trugman",
"author_id": 1030410,
"author_profile": "https://Stackoverflow.com/users/1030410",
"pm_score": 0,
"selected": false,
"text": "ls -a /etc/ | grep '^o|^l|^.t|^.r'\n"
},
{
"answer_id": 74426852,
"author": "Bach Lien",
"author_id": 3973676,
"author_profile": "https://Stackoverflow.com/users/3973676",
"pm_score": 0,
"selected": false,
"text": "shopt -s extglob\nls -dp /etc/@(o|l)@(t|r)* | grep -v '/$'\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13059311/"
] |
74,421,698 | <p>I've got a python package running in a container.</p>
<p>Is it best practice to install it in <code>/opt/myapp</code> within the container?</p>
<p>Should the logs go in <code>/var/opt/myapp</code>?</p>
<p>Should the config files go in <code>/etc/opt/myapp</code>?</p>
<p>Is anyone recommending writing logs and config files to <code>/opt/myapp/var/log</code> and <code>/opt/myapp/config</code>?</p>
<p>I notice google chrome was installed in <code>/opt/google/chrome</code> on my (host) system, but it didn't place any configs in <code>/etc/opt/...</code></p>
| [
{
"answer_id": 74421997,
"author": "JRichardsz",
"author_id": 3957754,
"author_profile": "https://Stackoverflow.com/users/3957754",
"pm_score": 0,
"selected": false,
"text": "import os\nprint(os.environ['DATABASE_PASSWORD'])\n"
},
{
"answer_id": 74424211,
"author": "zsolt",
"author_id": 4223799,
"author_profile": "https://Stackoverflow.com/users/4223799",
"pm_score": 1,
"selected": false,
"text": "WORKDIR /app"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598461/"
] |
74,421,722 | <p>Dropdowns are useful, but they would be even more useful if the dropdown options could be formatted. For example, using bold or italic text for various selections, or changing the background color of other options on the dropdown display.</p>
<p>It's easy to have a cell formatting change according to the dropdown selected, but that's not what I'm trying to do. I want the formatting of the the dropdown items to be different than simple plain text.</p>
| [
{
"answer_id": 74421982,
"author": "Andrea Guerri",
"author_id": 13584834,
"author_profile": "https://Stackoverflow.com/users/13584834",
"pm_score": -1,
"selected": false,
"text": "function onEdit(e) {\nif(e.range.getRow()>1 && e.range.getColumn() ==5){\ne.source.getActiveRange()\n .setFontSize(11)\n .setFontWeight('bold')\n .setFontStyle('italic')\n .setFontLine('line-through')\n .setFontColor('#ff0000')\n .setBackground('#ffff00')\n };\n }\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10574914/"
] |
74,421,771 | <p>I have a Flutter app where users can predict the outcome of a soccer match. The problem is that if the user changes the time on their phone they can still predict even after it has ended. How do I prevent this so that it's independent of the time on each user's phone?
Thank you</p>
| [
{
"answer_id": 74421982,
"author": "Andrea Guerri",
"author_id": 13584834,
"author_profile": "https://Stackoverflow.com/users/13584834",
"pm_score": -1,
"selected": false,
"text": "function onEdit(e) {\nif(e.range.getRow()>1 && e.range.getColumn() ==5){\ne.source.getActiveRange()\n .setFontSize(11)\n .setFontWeight('bold')\n .setFontStyle('italic')\n .setFontLine('line-through')\n .setFontColor('#ff0000')\n .setBackground('#ffff00')\n };\n }\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11856923/"
] |
74,421,796 | <p>I am new to ruby and start learning ruby, and i came to this proc return concept where i completely confused how the proc is returning differently.</p>
<p>I am attaching my code here for the reference.
I did google search too but couldn't get my answer if anyone could help please.</p>
<pre><code>def call_proc
puts "Before proc"
my_proc = Proc.new { return 2 }
my_proc.call
puts "After proc"
end
def proc_call
def inside_call
my_proc = Proc.new {return 4}
end
proc = inside_call
proc.all
end
</code></pre>
| [
{
"answer_id": 74423268,
"author": "Jad",
"author_id": 2835151,
"author_profile": "https://Stackoverflow.com/users/2835151",
"pm_score": 1,
"selected": false,
"text": "Proc"
},
{
"answer_id": 74430818,
"author": "Stefan",
"author_id": 477037,
"author_profile": "https://Stackoverflow.com/users/477037",
"pm_score": 0,
"selected": false,
"text": "def inside_call\n Proc.new { return 4 }\nend\n\ndef proc_call\n proc = inside_call\n proc.call\nend\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20493155/"
] |
74,421,871 | <p>I am new in laravel and I try to make a it display on screen some information form my migration but it keeps giving me an error of undeclared variable in the "alunos" blade</p>
<p>this is my controller</p>
<pre><code><?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Aluno;
class AlunoCoontroller extends Controller
{
public function index()
{
$alunos = Aluno::all();
return view('alunos',['alunos' => $alunos]);
}
public function create()
{
return view('alunos.create');
}
}
</code></pre>
<p>Model</p>
<pre><code><?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Aluno extends Model
{
use HasFactory;
}
</code></pre>
<p>migation</p>
<pre><code><?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('_alunos', function (Blueprint $table) {
$table->id();
$table->string('nome');
$table->string('filme');
$table->string('RA');
$table->string('senha');
$table->string('cpf');
$table->string('cep');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
*
* @return void
*/
public function down()
{
Schema::dropIfExists('_alunos');
}
};
</code></pre>
<p>and the blade</p>
<pre><code>@extends('layouts.main')
@section('title', 'Star-Fox Company')
@section('content')
<h1>tela onde o aluno vai inserri os dados para acessar seu cadastro</h1>
@foreach ($alunos as $aluno)
<p>Nome: {{ $aluno->nome }}</p>
<p>Matricula: {{ $aluno->filme }}</p>
<p>Curso: {{ $aluno->curso }}</p>
<p>Senha: {{ $aluno->senha }}</p>
@endforeach
@endsection
</code></pre>
<p>I already try change the name of this variable but the error keeps, can someone help me with this
explaining why it giving an undeclared variable error on the blade</p>
| [
{
"answer_id": 74423268,
"author": "Jad",
"author_id": 2835151,
"author_profile": "https://Stackoverflow.com/users/2835151",
"pm_score": 1,
"selected": false,
"text": "Proc"
},
{
"answer_id": 74430818,
"author": "Stefan",
"author_id": 477037,
"author_profile": "https://Stackoverflow.com/users/477037",
"pm_score": 0,
"selected": false,
"text": "def inside_call\n Proc.new { return 4 }\nend\n\ndef proc_call\n proc = inside_call\n proc.call\nend\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20243847/"
] |
74,421,878 | <p>I am trying to deploy a blazor server template app on Nginx, but i'm stucked with this problem.
I tried everything that I could find online, but still the same error.</p>
<p>error.log
*36 upstream prematurely closed connection while reading response header from upstream, client:, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:7155/"</p>
<p>in case of that helps, browsers just show 502 code</p>
<p>this is my nginx.conf</p>
<pre><code>user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
</code></pre>
<p>and here the server block at /sites-enabled/</p>
<pre><code>server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;
location / {
proxy_pass http://dotnet;
proxy_set_header Host $host;
proxy_http_version 1.1; # you need to set this in order to use params below.
proxy_temp_file_write_size 64k;
proxy_connect_timeout 10080s;
proxy_send_timeout 10080;
proxy_read_timeout 10080;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_request_buffering off;
proxy_buffering off;
}
}
upstream dotnet {
zone dotnet 64k;
server 127.0.0.1:7155;
}
</code></pre>
<p>I don't know what I am doing wrong. please help</p>
| [
{
"answer_id": 74423268,
"author": "Jad",
"author_id": 2835151,
"author_profile": "https://Stackoverflow.com/users/2835151",
"pm_score": 1,
"selected": false,
"text": "Proc"
},
{
"answer_id": 74430818,
"author": "Stefan",
"author_id": 477037,
"author_profile": "https://Stackoverflow.com/users/477037",
"pm_score": 0,
"selected": false,
"text": "def inside_call\n Proc.new { return 4 }\nend\n\ndef proc_call\n proc = inside_call\n proc.call\nend\n"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20493209/"
] |
74,421,884 | <p>I want to give the user an option to hide or show columns of Antd table via a group of checkboxes.
I tried different online solutions but I didn't succeed. I want something like this, as in the below picture.</p>
<p><strong>note:</strong> some columns has been checked by default, but user can also uncheck them</p>
<p><a href="https://i.stack.imgur.com/VoX0L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VoX0L.png" alt="enter image description here" /></a></p>
<p>I am stuck with this problem from last 2 days.
Here is my code.Thanks in advance!</p>
<p><a href="https://stackblitz.com/edit/react-h8hoys-q2mfxy?file=demo.js" rel="nofollow noreferrer">https://stackblitz.com/edit/react-h8hoys-q2mfxy?file=demo.js</a></p>
| [
{
"answer_id": 74423311,
"author": "Muhammad Nouman Rafique",
"author_id": 19932999,
"author_profile": "https://Stackoverflow.com/users/19932999",
"pm_score": 0,
"selected": false,
"text": "Checkbox.Group"
},
{
"answer_id": 74423859,
"author": "Kamran Davar",
"author_id": 12510464,
"author_profile": "https://Stackoverflow.com/users/12510464",
"pm_score": 2,
"selected": false,
"text": "setState"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8297544/"
] |
74,421,889 | <p>I have two json objects i am getting remotely and one is of this format</p>
<pre><code>{
"form": {
"mounted_language": "en",
"enctype": "multipart/form-data",
"hydration_url": "",
"post_destination": "postFormData()",
"fields": {
"title": {
"type": "text",
"label": "Title",
"data-model": "title",
"value": "",
"required": true,
"name": "title",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"type": {
"type": "text",
"label": "Type",
"data-model": "type",
"value": "",
"required": true,
"name": "type",
"mobile_classes": "",
"desktop_classes": ""
},
"condition": {
"type": "text",
"label": "Condition",
"data-model": "condition",
"value": "",
"required": true,
"name": "condition",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"materials": {
"type": "select",
"label": "Materials",
"required": true,
"data-model": "Materials",
"mobile_classes": "col-6",
"desktop_classes": "col-6",
"name": "materials",
"selected": "selected",
"option_has_url": false,
"options_data_source": "https://example.com/api/url"
},
"color": {
"type": "text",
"label": "Color",
"data-model": "color",
"value": "",
"required": true,
"name": "color",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"weight": {
"type": "number",
"label": "Weight",
"data-model": "weight",
"value": "",
"required": true,
"name": "weight",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"length": {
"type": "number",
"label": "Length",
"data-model": "lengths",
"value": "",
"required": true,
"name": "lengths",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"width": {
"type": "number",
"label": "Width",
"data-model": "width",
"value": "",
"required": true,
"name": "width",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"height": {
"type": "number",
"label": "Height",
"data-model": "height",
"value": "",
"required": true,
"name": "height",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"pictures": {
"type": "file",
"label": "Pictures",
"x-change": "selectFile($event)",
"required": true,
"multiple": true,
"accept": "image/png, image/jpg, image/jpeg",
"name": "pictures",
"value": "",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
},
"description": {
"type": "textarea",
"label": "Description",
"data-model": "description",
"value": "",
"required": true,
"name": "description",
"mobile_classes": "col-6",
"desktop_classes": "col-6"
}
}
}
}
</code></pre>
<p>and the other</p>
<pre><code>{
"data": [{
"en": "One"
}, {
"en": "Two"
}, {
"en": "Three"
}, {
"en": "Four"
}]
}
</code></pre>
<p>I am getting the first json object and creating a form out of it</p>
<pre><code>$.get("http://localhost:8000/api_routes/agriculture_and_food_structure", function(data) {
data = JSON.parse(data);
let original_json_object = data;
console.log('Original Json Object', original_json_object);
for (let prop in data) {
console.log("Key:" + prop);
for (let prop2 in data.form.fields) {
console.log("Key2:" + prop2);
let typ = data.form.fields[prop2].type;
let label = data.form.fields[prop2].label;
let text_input = '';
if (typ == 'text') {
text_input = '<div class="col-6"><div class="mb-3 col-12"><label for="exampleFormControlInput1" class="form-label">' + label + '</label> <input type="text" data-model="" class="form-control" id="exampleFormControlInput1" placeholder=""></div></div>';
}
if (typ == 'number') {
text_input = '<div class="col-6"><div class="mb-3 col-12"><label for="exampleFormControlInput1" class="form-label">' + label + '</label> <input type="number" data-model="" class="form-control" id="exampleFormControlInput1" placeholder=""></div></div>';
}
if (typ == 'select') {
let options_data_source = data.form.fields[prop2].options_data_source;
$.get("http://localhost:8000/data_routes/materials_data", function(dt) {
for (let pr in dt) {
console.log('Options', dt[pr]);
}
});
text_input = '<div class="col-6"><div class="mb-3 col-12"><label for="exampleFormControlInput1" class="form-label">' + label + '</label> <select class="form-control"></select></div></div>';
}
$('#form').append(text_input);
}
}
});
console.log('mounted');
</code></pre>
<p>I want to get the individual options here</p>
<pre><code>for (let pr in dt) {
console.log('Options', dt[pr]);
}
</code></pre>
<p>so that i append to the <code>select</code> box. How can i output the data in the second json object with the identical key?</p>
| [
{
"answer_id": 74422177,
"author": "Vivasvan Patel",
"author_id": 8926214,
"author_profile": "https://Stackoverflow.com/users/8926214",
"pm_score": 1,
"selected": false,
"text": "// for each object in the option's api response.\nfor (let i = 0; i < dt.data.length; ++i) {\n\n // extract the option\n let option = dt[data][i][\"en\"]\n \n // print it or do whatever you want\n console.log(\"Options\", option)\n}\n"
},
{
"answer_id": 74422450,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 3,
"selected": true,
"text": "<select>"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/492293/"
] |
74,421,892 | <p>I have two <code>ConstraintLayout</code>s split in half like this:</p>
<pre class="lang-xml prettyprint-override"><code><?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent"
android:layout_height="96dp"
app:cardCornerRadius="4dp"
app:cardElevation="5dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/start_viewHolder"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="@id/end_viewHolder"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/date_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_round_schedule"
app:layout_constraintBottom_toTopOf="@id/amount_key"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/date_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/date_key" />
<TextView
android:id="@+id/amount_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/amount"
app:layout_constraintBottom_toTopOf="@id/id_key"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/date_key" />
<TextView
android:id="@+id/amount_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/amount_key" />
<TextView
android:id="@+id/id_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="شناسه تراکنش"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amount_key" />
<TextView
android:id="@+id/id_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/id_key" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/end_viewHolder"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/start_viewHolder">
<ImageView
android:id="@+id/time_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_outline_calendar_month"
app:layout_constraintBottom_toTopOf="@id/status_key"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/time_key" />
<TextView
android:id="@+id/status_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/status"
app:layout_constraintBottom_toTopOf="@id/transactionCode_key"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/time_key" />
<TextView
android:id="@+id/status_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/status_key" />
<TextView
android:id="@+id/transactionCode_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/transaction_code"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_key" />
<TextView
android:id="@+id/transactionCode_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/transactionCode_key" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</code></pre>
<p>The problem is that the two child ConstraintLayouts <code>start_viewHolder</code> and <code>end_viewHolder</code> do not show up on Device/Emulator but work correctly on design tab's preview! How can I fix this issue?</p>
| [
{
"answer_id": 74422177,
"author": "Vivasvan Patel",
"author_id": 8926214,
"author_profile": "https://Stackoverflow.com/users/8926214",
"pm_score": 1,
"selected": false,
"text": "// for each object in the option's api response.\nfor (let i = 0; i < dt.data.length; ++i) {\n\n // extract the option\n let option = dt[data][i][\"en\"]\n \n // print it or do whatever you want\n console.log(\"Options\", option)\n}\n"
},
{
"answer_id": 74422450,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 3,
"selected": true,
"text": "<select>"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19576538/"
] |
74,421,894 | <p>I am very new to Kotlin and Android. I am trying to calculate the average of the values in my Array in the function "array" but i'm not very sure how to do it. I have created a function called "average" which I want to calculate the average of the array within. Any help would be very appreciated. Below is all of my source code.</p>
<pre><code>class MainActivity2 : AppCompatActivity() {
private lateinit var addnumber: EditText
private lateinit var storednumber: TextView
private lateinit var output: TextView
private lateinit var addbutton: Button
private lateinit var clearbutton: Button
private lateinit var averagebutton: Button
private lateinit var minmaxbutton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
addnumber = findViewById(R.id.et_addNum)
storednumber = findViewById(R.id.stored_tv)
output = findViewById(R.id.answer2_tv)
addbutton = findViewById(R.id.addNum_btn)
clearbutton = findViewById(R.id.clear_btn)
averagebutton = findViewById(R.id.average_btn)
minmaxbutton = findViewById(R.id.minMax_btn)
addbutton.setOnClickListener {
array()
}
clearbutton.setOnClickListener {
clear()
}
clearbutton.setOnClickListener {
average()
}
}
private fun array() {
val ed = findViewById<View>(R.id.et_addNum) as EditText
var text = ed.text.toString()
val array: List<String> = text.split(",")
for (element in array) {
Log.e("elements", element)
storednumber.setText(array.toString())
}
}
private fun clear() {
storednumber.setText(null)
}
private fun average() {
}
}
</code></pre>
| [
{
"answer_id": 74422177,
"author": "Vivasvan Patel",
"author_id": 8926214,
"author_profile": "https://Stackoverflow.com/users/8926214",
"pm_score": 1,
"selected": false,
"text": "// for each object in the option's api response.\nfor (let i = 0; i < dt.data.length; ++i) {\n\n // extract the option\n let option = dt[data][i][\"en\"]\n \n // print it or do whatever you want\n console.log(\"Options\", option)\n}\n"
},
{
"answer_id": 74422450,
"author": "Carsten Massmann",
"author_id": 2610061,
"author_profile": "https://Stackoverflow.com/users/2610061",
"pm_score": 3,
"selected": true,
"text": "<select>"
}
] | 2022/11/13 | [
"https://Stackoverflow.com/questions/74421894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19506039/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.