qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,212,181 | <p>How do I format this string:</p>
<pre><code>'Item: Intel NUC onboard PC\n'
</code></pre>
<p>so I get this output:</p>
<pre><code>Intel NUC onboard PC
</code></pre>
<p>thanks</p>
| [
{
"answer_id": 74212338,
"author": "Mina",
"author_id": 11887902,
"author_profile": "https://Stackoverflow.com/users/11887902",
"pm_score": 2,
"selected": true,
"text": "reduce"
},
{
"answer_id": 74213402,
"author": "trincot",
"author_id": 5459839,
"author_profile": "... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19918015/"
] |
74,212,186 | <p>I have the following DataFrame (I'm sorry for posting an image but I dont know how to write tables with more than 2 columns here on Stackoverflow lol)</p>
<p><a href="https://i.stack.imgur.com/O0ice.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O0ice.png" alt="enter image description here" /></a></p>
<p>It is missing the fifth month as you can see.</p>
<p>How can I detect and add a new row that contains the fifth month to get a new DataFrame with all months?</p>
<p><a href="https://i.stack.imgur.com/Lo9VB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lo9VB.png" alt="enter image description here" /></a></p>
<pre><code>import pandas as pd
data = {'YEAR1': [2020]*11, 'YEAR2': [2019]*11, 'MONTH': [1,2,3,4,6,7,8,9,10,11,12]}
df = pd.DataFrame(data)
</code></pre>
| [
{
"answer_id": 74212738,
"author": "ddd",
"author_id": 14192594,
"author_profile": "https://Stackoverflow.com/users/14192594",
"pm_score": 1,
"selected": false,
"text": "df.loc[len(df.index)] = [2020, 2019, 5]\ndf.sort_values(by=\"MONTH\", inplace=True)\n"
},
{
"answer_id": 74212... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11789082/"
] |
74,212,191 | <p>I'm learning cypress, but I came across this error.</p>
<p>When running npm run test the cypress window open for a while, but a couple seconds later it close, then this error appears:</p>
<p><a href="https://i.stack.imgur.com/9Tq8K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Tq8K.png" alt="Error" /></a></p>
<p>I already installed the lastest cypress version and it didn't work.</p>
| [
{
"answer_id": 74212738,
"author": "ddd",
"author_id": 14192594,
"author_profile": "https://Stackoverflow.com/users/14192594",
"pm_score": 1,
"selected": false,
"text": "df.loc[len(df.index)] = [2020, 2019, 5]\ndf.sort_values(by=\"MONTH\", inplace=True)\n"
},
{
"answer_id": 74212... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19757597/"
] |
74,212,209 | <p>I developed a pack app that can run 3 functions depending on the user's choice:</p>
<p>It is pretty simple:</p>
<p><a href="https://i.stack.imgur.com/tKvpA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tKvpA.png" alt="enter image description here" /></a></p>
<p>For each option, we have another window to upload the required files an run the routine as follows:</p>
<p><a href="https://i.stack.imgur.com/KStCh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KStCh.png" alt="enter image description here" /></a></p>
<p>However, if I choose option A, once I ran the script I can't run A again, I need to close and open the application again.</p>
<p>Please check this example (try to run the same option (A, B or C) without close the app):</p>
<pre><code>import PySimpleGUI as sg
# --------------------------------------------- Menu Definition -------------------------------------------------------#
menu_def = [["Help", ["Applications description", "Template"]]]
# --------------------------------------------- GUI Definition ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
layout = [[sg.Menu(menu_def, tearoff = False, background_color="lightgray", disabled_text_color="white", text_color = "black")],
[sg.Text("Choose the application:", s = 14, text_color = 'black', background_color='lightgray', size = (30,1))],[sg.Radio('A', default=False, key="-IN-", group_id = "Group 1", background_color="lightgray", size = (5,5), text_color= "black")],
[sg.Radio('B', default=False, key="-IN2-", group_id = "Group 1", background_color="lightgray", size = (5,5), text_color= "black")], [sg.Radio('C', default=False, key="-IN3-", group_id = "Group 1", background_color="lightgray", size = (5,5), text_color= "black")],
[sg.Button('Submit', button_color=("black"), mouseover_colors="white"), sg.Button('Exit', button_color=("tomato"))]]
window = sg.Window("Pack App", layout, background_color= 'lightgray')
layout_app1 = [[sg.Text("A1 File:", s = 14, text_color = 'black', background_color='white')], [sg.Input(key="-IN-", justification='left'), sg.FileBrowse(file_types = (("Text Files","*.txt"),), button_color = 'darkgray')],
[sg.Text("A2 File:", s = 14, text_color = 'black', background_color='white', size = (40,1))], [sg.Input(key="-IN2-", justification='left'), sg.FileBrowse(file_types = (("Text Files","*.txt"),), button_color='darkgray')],
[sg.Text("Output Folder:", s = 14, text_color = 'black', background_color='white')], [sg.Input(key="-OUT-"), sg.FolderBrowse(button_color=('darkgray'))],
[sg.Text("File Name:", s = 14, text_color = 'black', background_color='white', size = (8,1)), sg.Input(key="-IN3-", background_color='white', justification='left', size = (34,1))],
[[sg.T("", background_color='white')], sg.Button("Generate File", s = 16, button_color='darkblue')]]
window_app1 = sg.Window("First Application", layout_app1, background_color= 'white')
layout_app2 = [[sg.Text("B1:", s = 14, text_color = 'black', background_color='white')], [sg.Input(key="-IN-", justification='left'), sg.FileBrowse(file_types = (("Excel Files","*.xlsx"),), button_color = 'darkgray')],
[sg.Text("Output Folder:", s = 14, text_color = 'black', background_color='white')], [sg.Input(key="-OUT-"), sg.FolderBrowse(button_color=('darkgray'))],
[sg.Text("File Name:", s = 14, text_color = 'black', background_color='white', size = (8,1)), sg.Input(key="-IN3-", background_color='white', justification='left', size = (34,1))],
[[sg.T("", background_color='white')], sg.Button("Generate File", s = 16, button_color='darkblue')]]
window_app2 = sg.Window("Second Application", layout_app2, background_color= 'white')
layout_app3 = [[sg.Text("C1:", s = 14, text_color = 'black', background_color='white', size = (35,1))], [sg.Input(key="-IN-", justification='left'), sg.FileBrowse(file_types = (("Excel Files","*.xlsx"),), button_color = 'darkgray')],
[sg.Text("Output Folder:", s = 14, text_color = 'black', background_color='white')], [sg.Input(key="-OUT-"), sg.FolderBrowse(button_color=('darkgray'))],
[sg.Text("File Name:", s = 14, text_color = 'black', background_color='white', size = (8,1)), sg.Input(key="-IN3-", background_color='white', justification='left', size = (34,1))],
[[sg.T("", background_color='white')], sg.Button("Generate File", s = 16, button_color='darkblue')]]
window_app3 = sg.Window("Third Application", layout_app3, background_color= 'white', )
while True:
event, values = window.read()
print(event, values)
if event in (sg.WINDOW_CLOSED, "Exit"):
break
elif values["-IN-"] == True:
event, values = window_app1.read()
if event == "Generate File":
sg.popup_no_titlebar("You selected the 1st app", background_color="white", button_color=("darkblue"), text_color="black")
elif values["-IN2-"] == True:
event, values = window_app2.read()
if event == "Generate File":
sg.popup_no_titlebar("You selected the 2nd app", background_color="white", button_color=("darkblue"), text_color="black")
elif values["-IN3-"] == True:
event, values = window_app3.read()
if event == "Generate File":
sg.popup_no_titlebar("You selected the 3rd app", background_color="white", button_color=("darkblue"), text_color="black")
window.close()
</code></pre>
<p>How can I make it possible? To repeat an event how many time I want to, without closing and opening the app all over again?</p>
| [
{
"answer_id": 74212738,
"author": "ddd",
"author_id": 14192594,
"author_profile": "https://Stackoverflow.com/users/14192594",
"pm_score": 1,
"selected": false,
"text": "df.loc[len(df.index)] = [2020, 2019, 5]\ndf.sort_values(by=\"MONTH\", inplace=True)\n"
},
{
"answer_id": 74212... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19537357/"
] |
74,212,243 | <p>Hi guys I want to change the look of these icons to a circle version.</p>
<p>Here's the current code:</p>
<pre><code><span>
<a href="/futbol" rel="noopener"><img style="border-radius: 50%" src="/wp-content/uploads/2022/04/MX-flag.webp" alt="Mexico Flag Translation" width="50"></a>
</span> <span style="color:white">SP</span> <span style="color:white">|</span>
<span>
<a href="/" rel="noopener"><img style="border-radius: 50%" src="/wp-content/uploads/2022/04/US-flag.jpeg" alt="English Flag Translation" width="50"></a>
</span> <span style="color:white">EN</span>
</code></pre>
<p>I tried doing it myself but couldn't make it.</p>
<p>Now they appear like ovals, what should I add to the code for the images to show as circles?</p>
| [
{
"answer_id": 74212738,
"author": "ddd",
"author_id": 14192594,
"author_profile": "https://Stackoverflow.com/users/14192594",
"pm_score": 1,
"selected": false,
"text": "df.loc[len(df.index)] = [2020, 2019, 5]\ndf.sort_values(by=\"MONTH\", inplace=True)\n"
},
{
"answer_id": 74212... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342169/"
] |
74,212,258 | <p>I have a question :</p>
<p>I have this DF</p>
<pre><code>#> # A tibble: 4 × 3
#> family name items
#> <chr> <chr> <list>
#> 1 Kelly Mark book, ring, necklace
#> 2 Kelly Scott axe, camera, watch
#> 3 Quin Tegan book, camera, watch
#> 4 Quin Sara sword, fork, book
</code></pre>
<p>How to count each items in the list inside that dataframe into Total like this :
count(book) = 3
count(camera) = 2
etc</p>
<p>should I pivot wider the entire item into new column?
I'm really sorry if my question is too basic, since I really new into Data Processing</p>
<p>Thank You</p>
<p>#My Approach
I tried to using pivot longer, but the columns become too many.
The list contains hundreds of value, and it seems bother me to handle such a big data.
I haven't yet tried another solution.</p>
| [
{
"answer_id": 74212395,
"author": "Ruam Pimentel",
"author_id": 13015865,
"author_profile": "https://Stackoverflow.com/users/13015865",
"pm_score": 2,
"selected": true,
"text": "library(dplyr)\nlibrary(tidyr)\n\ndf <- tibble(\n family = c(\"Kelly\", \"Kelly\", \"Quin\", \"Quin\"), \n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17076133/"
] |
74,212,259 | <pre><code>import csv
with open('myaddresses.csv','w','newline')as A:
thewriter = cav.writer(A)
thewriter.writerow({'11 Wall Street, New York, NY, 10005'})
thewriter.writerow({'350 Fifth Avenue, New York, NY, 10118'})
thewriter.writerow({'1600 Pennsylvania Avenue NW, Washington DC, 20500'})
thewriter.writerow({'4059 Mt Lee Dr.,Hollywood, CA, 90068'})
thewriter.writerow({'Statue of Liberty, Liberty Island, New York, NY, 10004'})
thewriter.writerow({'1313 Mockingbird Lane, Albany, NY, 12084'})
thewriter.writerow({'0001 Cemetery Lane, Westfield, NJ, 07091'})
thewriter.writerow({'3109 Grant Ave, Philadelphia , Pa, 19114'})
thewriter.writerow({'532 N. 7th Street, Philadelphia, PA, 19123'})
thewriter.writerow({'317 Chestnut Street, Philadelphia, PA, 19106'})
</code></pre>
<p>TypeError: 'str' object cannot be interpreted as an integer</p>
<p>any help would be appericated</p>
<p>I just need it to print the information I entered.</p>
| [
{
"answer_id": 74212395,
"author": "Ruam Pimentel",
"author_id": 13015865,
"author_profile": "https://Stackoverflow.com/users/13015865",
"pm_score": 2,
"selected": true,
"text": "library(dplyr)\nlibrary(tidyr)\n\ndf <- tibble(\n family = c(\"Kelly\", \"Kelly\", \"Quin\", \"Quin\"), \n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342173/"
] |
74,212,266 | <p>I run a command, <code>getFiles</code>, that outputs a newline delimited list filenames. Very similar to the output of <code>ls -1</code>. The filenames all end in a number representing a kind of timestamp. Larger numbers are more recent. The filenames follow no pattern. e.g. <code>file1234</code>, <code>other44234</code>, <code>something34142</code>, <code>carrot123</code>.</p>
<p>I need to find the filename with the largest number (numerically). In this example <code>other44234</code>.</p>
<p>After finding the filename I need to pass it as an argument into another command. i.e. <code>doItToIt "$THE_FILE"</code></p>
| [
{
"answer_id": 74212590,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 0,
"selected": false,
"text": "$ cat files.txt\nfile1234\nother44234\nsomething34142\ncarrot123\n"
},
{
"answer_id": 74213406,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1736623/"
] |
74,212,270 | <p>I can't seem to understand how to make abstract classes and their subclasses work properly with Freezed. Specifically, I need to define an abstract super-class with some to-override getters; the subclasses will need to override the getters, while exploiting freezed to generate their boilerplate code.</p>
<p>I do understand what the <a href="https://pub.dev/packages/freezed#mixins-and-interfaces-for-individual-classes-for-union-types" rel="nofollow noreferrer">documentation</a> suggests, but I do need more.</p>
<p>I created <a href="https://github.com/lucavenir/freezed_problems" rel="nofollow noreferrer">a repo</a> to show off what I need, in case you want to cut to the chase. All I need are <a href="https://github.com/lucavenir/freezed_problems/blob/main/test/this_test.dart" rel="nofollow noreferrer">these tests</a> to pass and work as intended.</p>
<p>I need a clean, readable and maintainable way to do this.</p>
<h2>Scenario</h2>
<p>In the repo you'll find a small reproduction case:</p>
<ul>
<li>A <code>Base</code> abstract class;</li>
<li>A class <code>A</code>, which extends the <code>Base</code> class (I wanted to simplify things, but I do have more subclasses in my real use case, say <code>X</code>, <code>Y</code>, <code>Z</code>, etc.);</li>
<li><code>A</code> needs to be implemented with Freezed, with JSON serialization / deserialization;</li>
</ul>
<p>Recap: <code>Base</code> is there to have write common ground between <code>A</code>, <code>X</code>, <code>Y</code> and <code>Z</code>; as mentioned above, Freezed is a must-have for these subclasses.</p>
<h2>Goal</h2>
<p>My goal is to exploit composition.</p>
<p>Let a class <code>B</code> have a <code>Base get myValue</code> getter, with Freezed. Unsurprisingly, I want to interact with this value by accessing its <code>copyWith</code> method (or others, like <code>toJson</code>), but this gets complicated quite fast (see Problem 1).</p>
<p>Again, read the tests for the desired outcome.</p>
<h2>Problem 1</h2>
<p>Implementing what I've described above, while it makes sense, is no easy task (to my understanding).</p>
<p>For example, the following:</p>
<pre class="lang-dart prettyprint-override"><code>abstract class Base {
const Base();
Function copyWith();
Map<String, dynamic> toJson();
String get id;
}
</code></pre>
<p>won't work because the subclasses will feel ambiguity onto which superclass method to use (error <a href="https://github.com/lucavenir/freezed_problems/blob/5afbea3292ac990c859b665296072ed79a0b4a8c/lib/models/a.dart#L9" rel="nofollow noreferrer">here</a>): should it use the one generated by <code>@freezed</code>, or the abstract one? That's a compile-time error.</p>
<p>I have no clue how to properly write a contract while exploiting Freezed.</p>
<h2>Problem 2</h2>
<p>At first, <code>build_runner</code> rightfully complains as it can't generate the <code>fromJson</code> method onto <code>B</code> because <code>Base</code> has no <code>@JsonSerializable</code> method.</p>
<p>This would imply implementing a converter manually: I did so, but this gets old quickly. This implies to re-write the converter for each new subclass created and raise an exception for a subclass that isn't handled, yet (that's a strong code smell).</p>
<p>Such atrocity is found in <a href="https://github.com/lucavenir/freezed_problems/blob/main/lib/models/base.dart" rel="nofollow noreferrer">this file</a>.</p>
<p>How can achieve this in a clean way?</p>
| [
{
"answer_id": 74212590,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 0,
"selected": false,
"text": "$ cat files.txt\nfile1234\nother44234\nsomething34142\ncarrot123\n"
},
{
"answer_id": 74213406,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15831316/"
] |
74,212,285 | <p>I am creating a personal website and I have a progress bar that has been done in css and html.</p>
<p>in order to control the progress bars all I need to do is change a variable(width).
This is the code for one bar:</p>
<pre><code>.bar-inner1 {
width: 559px;
height: 35px;
line-height: 35px;
background: #db3a34;
border-radius: 5px 0 0 5px;
}
</code></pre>
<p>This is the corresponding html that is affected by this css:</p>
<pre><code><div class="container">
<h2 class="my-skills">My Skills</h2>
<div class="bar-1">
<div class="title">HTML5</div>
<div class="bar" data-width="65%">
<div class="bar-inner1">
</div>
<div class="bar-percent">65%</div>
</div>
</div>
</code></pre>
<p>How would I use Django to change the variable width?</p>
<p>I have looked through documentation and tutorials but I cannot seem to work it out.</p>
| [
{
"answer_id": 74217185,
"author": "Pulath Yaseen",
"author_id": 12147680,
"author_profile": "https://Stackoverflow.com/users/12147680",
"pm_score": 2,
"selected": true,
"text": "width"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16644505/"
] |
74,212,296 | <p>I am trying to remove items from my list while iterate, that is why he used Iterator, to later insert emails into a queue. But I get the following error when inserting more elements:</p>
<pre><code>Iterator<String> listCorreos = request.getCorreos().iterator();
while (listCorreos.hasNext()) {
for (Cola cola : colas) {
String correo = listCorreos.next();
cola.insertar(correo);
System.err.println("Se agrego " + correo + " a la cola: " + cola.obtenerNombre());
listCorreos.remove();
}
}
</code></pre>
<p>I get the following error</p>
<pre><code>java.util.NoSuchElementException
at java.base/java.util.ArrayList$Itr.next(Unknown Source)
</code></pre>
<p>Thank you in advance for any kind of help.</p>
| [
{
"answer_id": 74212383,
"author": "ControlAltDel",
"author_id": 1291492,
"author_profile": "https://Stackoverflow.com/users/1291492",
"pm_score": 2,
"selected": true,
"text": "String correo = listCorreos.next(); "
},
{
"answer_id": 74212458,
"author": "Persixty",
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20267399/"
] |
74,212,311 | <p>I have a PowerShell script I run on a regular basis. Part of the script creates csv files that I later use to import data into various software programs.</p>
<p>The data is in a variable $enrolledStudents and the type is a System.Array</p>
<p>I use the following to export part of the data:</p>
<pre><code>$enrolledStudents | Select-Object @{Name="SFIRST";Expression={$_.FirstName}},`
@{Name="SLAST";Expression={$_.LastName}},`
@{Name="SGRADE";Expression={[int]$_.GradeLevel}},`
@{Name="SBIRTHDAY";Expression={$_.Birthdate }} |
Export-CSV C:\temp\Exported.csv -notype -Append
</code></pre>
<p>The Export looks like:<br />
"SFIRST","SLAST","SGRADE","SBIRTHDAY"<br />
"John","Doe","6","<strong>2009-11-22</strong>"</p>
<p>The software I upload the data to needs the date formatted as “11/22/2009” so it would look like:
"SFIRST","SLAST","SGRADE","SBIRTHDAY"<br />
"John","Doe","6","<strong>11/22/2009</strong>"</p>
<p>Is there a way to do this in the Select-Object ?</p>
| [
{
"answer_id": 74212383,
"author": "ControlAltDel",
"author_id": 1291492,
"author_profile": "https://Stackoverflow.com/users/1291492",
"pm_score": 2,
"selected": true,
"text": "String correo = listCorreos.next(); "
},
{
"answer_id": 74212458,
"author": "Persixty",
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20340897/"
] |
74,212,320 | <h2>All I want to do is add an item to the items array in my Cart object.</h2>
<blockquote>
<p>What I am trying to do is simply execute my backend addItem mutation. After that I want to manually update the cache, but for now I am just re-fetching the query because I am unable to even successfully get the query to run.</p>
</blockquote>
<p><strong>In this code I am using the pothos withinput plugin: <a href="https://pothos-graphql.dev/docs/plugins/with-input#install" rel="nofollow noreferrer">link to docs</a></strong></p>
<h4>I have tried:</h4>
<ol>
<li>Just putting the hardcoded input object into the addItem hook</li>
<li>Listing each Variable out one by one into the addItem hook</li>
<li>Describing the types of each prop in the original gql MUTATION</li>
<li>And passing the hardcoded input into the addItem hook via variables object</li>
<li>Passing hardcoded values into the actual addItem mutation</li>
<li>I have tried inputting the proper typing via a gql tag <em>example below</em>:</li>
</ol>
<pre class="lang-js prettyprint-override"><code> const THE_TYPE = gql`input addItemInput {
cartId: String!
id: String!
name: String!
price: Float!
}
`
const MUTATION = gql`
mutation AddItem($input: ${THE_TYPE}!) {
addItem(input: $input){carts{
id
items{
name
}}}
`;
</code></pre>
<h3>*When I run the following mutation in my graphiql interface it works:</h3>
<pre class="lang-js prettyprint-override"><code>mutation MyMutation{
addItem(input:{
cartId: "2",
id: "12",
name: "New Item!",
price: 1900,
}){
items{
name
}
}}
</code></pre>
<h3>However when I run the mutation below I get a 400 error:</h3>
<p><em>Error: Response not successful: Received status code 400</em></p>
<pre class="lang-js prettyprint-override"><code>import { useQuery, gql, useMutation } from '@apollo/client';
export default function DisplayCarts() {
interface Cart {
id: string;
items: string[];
}
interface Items {
}
const GET_CARTS = gql`
query {
carts{
id
items{
name
}}} `;
const MUTATION = gql`
mutation AddItem($input: Any) {
addItem(input: $input){
carts{
id
items{
name
}}
}}`;
const { loading, error, data } = useQuery(GET_CARTS)
const [addItem] = useMutation(MUTATION, {
refetchQueries: [{ query: GET_CARTS }]
// update(cache, { data: { addItem } }) {
// addItem is the response of the query of add item function
// console.log(data);
// @ts-ignore
// const { carts } = cache.readQuery({ query: GET_CARTS });
// cache.writeQuery({
// query: GET_CARTS,
// data: { carts: [...carts, addItem] }
// })
// }
})
function AddTodo() {
let theInput = {
cartId: "2",
id: "12",
name: "New Item!",
price: 1900,
quantity: 2
}
// @ts-ignore
addItem({ variables: { input: theInput } });
};
</code></pre>
<h3>Here is my backend resolver function using pothos</h3>
<p><strong>Keep in mind my query does work in my graphiql interface so the issue is probably not on the backend</strong></p>
<pre class="lang-js prettyprint-override"><code>builder.mutationType({
fields: (t) => ({
addItem: t.fieldWithInput({
input: {
cartId: t.input.string({ required: true }),
id: t.input.string({ required: true }),
name: t.input.string({ required: true }),
price: t.input.int({ required: true }),
quantity: t.input.int({ required: true, defaultValue: 1 }),
},
type: Cart,
resolve: (_, { input: { cartId, ...input } }) => {
const cart = CARTS.find((cart) => cart.id === cartId);
if (!cart) {
throw new Error(`Cart with id ${cartId} not found`)
}
return {
id: cartId,
items: [...cart?.items, input]
}
}
}),
}),
})
</code></pre>
| [
{
"answer_id": 74212685,
"author": "Michel Floyd",
"author_id": 2805154,
"author_profile": "https://Stackoverflow.com/users/2805154",
"pm_score": 1,
"selected": false,
"text": "mutation AddItem($input: Any) {\n addItem(input: $input){…}\n"
},
{
"answer_id": 74217531,
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4682551/"
] |
74,212,330 | <p>I'm trying to have js change the title attributes for each div based on each divs text content in html.</p>
<p>I want to add the title of each div from its own text, so for example: "Text Example 1"s title would be "Text Example 1", "Text Example 2"s title would be "Text Example 2" and so on.</p>
<p>Currently I've made a js code that does that but only for one of the divs. I'm a complete beginner in js so any advice is appreciated.</p>
<pre class="lang-html prettyprint-override"><code><div class="example">
<div class="text1" id="id-text1">Text Example 1</div>
</div>
<div class="example">
<div class="text1" id="id-text1">Text Example 2</div>
</div>
<div class="example">
<div class="text1" id="id-text1">Text Example 3</div>
</div>
</code></pre>
<pre class="lang-js prettyprint-override"><code>const titleContent = document.getElementById("id-text1");
function ChangeTitle(){
document.querySelectorAll('.text1').forEach(function ChangeTitleSecond(){
titleContent.setAttribute('title', titleContent.textContent);
})
};
window.onload = ChangeTitle();
</code></pre>
| [
{
"answer_id": 74212421,
"author": "RixTheTyrunt",
"author_id": 16359609,
"author_profile": "https://Stackoverflow.com/users/16359609",
"pm_score": 2,
"selected": true,
"text": "<div>"
},
{
"answer_id": 74212564,
"author": "toastifer",
"author_id": 4880394,
"author_pr... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20325315/"
] |
74,212,341 | <p>I'm developing a stack of Windows Batch scripts (<code>.bat</code>) which are subsequently converted to self-extracting executabled.</p>
<p>Currently I'm facing a really strange problem. I create this self-extracting executable, which, after extracting all the files, will launch the main wrapper, (<code>SETUP.bat</code>). The whole stack of the scripts gets running and everything goes right until some point.</p>
<p>One part of the stack has to commit some files with <code>UWFMGR</code>, and I have a loop for like this:</p>
<pre class="lang-bash prettyprint-override"><code>SETLOCAL EnableDelayedExpansion
FOR /F usebackq "tokens=*" %%F IN ("DIR /S /B /A-D") DO (
uwfmgr file commit "%%F"
)
</code></pre>
<p>If I run the executable, the execution of the stack does not recognize the command <code>UWFMGR</code></p>
<p>I stopped the execution of the script, and went with the same CMD, (which it's launched by the executable), to the <code>System32</code> folder to check if the <code>UWFMGR</code> is there. I did a <code>DIR "uwfmgr.exe"</code>, and it's not there. But if I go with another CMD (a new one) the command is there. I even went with a file explorer to verify it and it's completely there but somehow the CMD which it's being launched by the executable cannot recognize it.</p>
<p>I have tried to specify the whole path in the loop like this <code>"C:\Windows\System32\UWFMGR.exe"</code> and it doesn't even work.</p>
<p>The funny thing is that if run this script it works and commits all the files required.</p>
<pre class="lang-bash prettyprint-override"><code>SETLOCAL EnableDelayedExpansion
FOR /F usebackq "tokens=*" %%F IN ("DIR /S /B /A-D") DO (
uwfmgr file commit "%%F"
)
</code></pre>
<p>Does anyone have any idea of why this is happening?</p>
<p>Check the output of the command and the errorlevel, it's <code>9009</code> (the file/command does not exist)
Do an <code>echo</code> to check the command I'm passing through the loop, the command is OK</p>
<p>I expect the executable to do the whole stack and commit the files but the executable does not recognize <code>UWFMGR</code> command. I use other commands in my stack and I didn't have any problem.</p>
| [
{
"answer_id": 74212421,
"author": "RixTheTyrunt",
"author_id": 16359609,
"author_profile": "https://Stackoverflow.com/users/16359609",
"pm_score": 2,
"selected": true,
"text": "<div>"
},
{
"answer_id": 74212564,
"author": "toastifer",
"author_id": 4880394,
"author_pr... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11304108/"
] |
74,212,433 | <p>I have created a builder for client types <code>A</code> and <code>B</code>.</p>
<p>Client TypeA has two fields <code>fieldA</code> and <code>fieldB</code> (<em>see below</em>), while client TypeB has two additional fields. How can I make sure field <code>C</code> and <code>D</code> are only accessible to client TypeB, i.e. client TypeA should <strong>not</strong> take field <code>fieldC</code> and <code>fieldD</code> when creating it.</p>
<p>Construction client <code>A</code>:</p>
<pre><code>client.builder()
.withClientType(ClientType.TypeA)
.withFieldA(fieldA)
.withFieldB(fieldB)
.build();
</code></pre>
<p>Construction client <code>B</code>:</p>
<pre><code>client.builder()
.withClientType(ClientType.TypeB)
.withFieldA(fieldA)
.withFieldB(fieldB)
.withFieldC(fieldC)
.withFieldD(fieldD)
.build();
</code></pre>
<p>What's the correct usage builder pattern in this case?</p>
| [
{
"answer_id": 74215287,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 2,
"selected": false,
"text": "build()"
},
{
"answer_id": 74232831,
"author": "RDK",
"author_id": 3291897,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16990872/"
] |
74,212,442 | <p>My dataframe:</p>
<pre><code>df = pd.DataFrame({'a':['A', 'B'], 'b':[{5:1, 11:2}, {5:3}]})
</code></pre>
<p>Expected output (Each Key will be transformed to 'n' keys. Example row 1, key =5 (with value =2) get transformed to 5, 6. This change also need to reflect on 'a' column)</p>
<pre><code>df_expected = pd.DataFrame({'a':['A1', 'A2', 'A1', 'A2', 'B1', 'B2', 'B3'], 'key':[5, 6, 11, 12, 5, 6, 7]})
</code></pre>
<p>My present state:</p>
<pre><code>df['key']=df.apply(lambda x: x['b'].keys(), axis=1)
df['value']=df.apply(lambda x: max(x['b'].values()), axis=1)
df = df.loc[df.index.repeat(df.value)]
</code></pre>
<p>Stuck here. What should be next step?</p>
<p>Expected output:</p>
<pre><code>df_expected = pd.DataFrame({'a':['A1', 'A2', 'A1', 'A2', 'B1', 'B2', 'B3'], 'key':[5, 6, 11, 12, 5, 6, 7]})
</code></pre>
| [
{
"answer_id": 74215287,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 2,
"selected": false,
"text": "build()"
},
{
"answer_id": 74232831,
"author": "RDK",
"author_id": 3291897,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17900863/"
] |
74,212,444 | <p>I have a file with keywords on each line. The line starts with number then comma and after that the keyword (like comma separated csv but text file). The file looks like this</p>
<pre><code>7,n00t
41,n01
13,n021
21,n02
18,n03
13,n04
15,n05
13,n06
18,n07
13,n08
14,n09
9,n0a
</code></pre>
<p>What I'm trying is to run whole file and hash only the keywords without the number before the comma.</p>
<p>What I'm tried is this.</p>
<pre><code> $savePath = "test-file.txt";
$handle = fopen($savePath, "r+");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$hash1 = substr($line, strpos($line, ",") + 1);
$hash2 = hash('ripemd160', $hash1);
fwrite($handle, $hash2);
}
fclose($handle);
} else {
echo "Can't open the file!";
}
</code></pre>
<p>It is working but the problem is that it is hashing the number before the comma and on most of the lines I get one string. This is the output</p>
<pre><code>d743dcc66de14a3430d806aad64a67345fd0b23d0007
75f32ebf42e3ffd70fc3f63d3a61fc6af0075c24000088
7b816ac9cbe2da6a6643538564216e441f55fe9f6,00009
f0ba52b83ffac69fddd8786d6f48e7700562f0170b
def75b09e253faea412f67e67a535595b00366dce
c0da025038ed83c687ddc430da9846ecb97f3998l
c0da025038ed83c687ddc430da9846ecb97f39985,0000r
c12530b4b78bde7bc000e4f15a15bcea013eaf8c
9c1185a5c5e9fc54612808977ee8f548b2258d31,00010
efa60a26277fde0514aec5b51f560a4ba25be3c111
0e25f9d48d432ff5256e6da30ab644d1ca726cb700123
ad6d049d794146aca7a169fd6cb3086954bf2c63012
</code></pre>
<p>Should be</p>
<pre><code>7,d743dcc66de14a3430d806aad64a67345fd0b23d0007
41,75f32ebf42e3ffd70fc3f63d3a61fc6af0075c24000088
13,7b816ac9cbe2da6a6643538564216e441f55fe9f6,00009
21,f0ba52b83ffac69fddd8786d6f48e7700562f0170b
18,def75b09e253faea412f67e67a535595b00366dce
13,c0da025038ed83c687ddc430da9846ecb97f3998l
15,c0da025038ed83c687ddc430da9846ecb97f39985,0000r
13,c12530b4b78bde7bc000e4f15a15bcea013eaf8c
18,9c1185a5c5e9fc54612808977ee8f548b2258d31,00010
13,efa60a26277fde0514aec5b51f560a4ba25be3c111
14,0e25f9d48d432ff5256e6da30ab644d1ca726cb700123
9,ad6d049d794146aca7a169fd6cb3086954bf2c63012
</code></pre>
<p>Any ideas what is the problem?</p>
| [
{
"answer_id": 74215287,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 2,
"selected": false,
"text": "build()"
},
{
"answer_id": 74232831,
"author": "RDK",
"author_id": 3291897,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342144/"
] |
74,212,445 | <p>I need to select with regex the first sentence (all text to the first dot) of each question. And then in repleace I add <b>$1</b> to put this tag</p>
<p>I try this but select whole text, not only the first sentence.</p>
<p><code>^[a-zA-Z].*</code></p>
<p>I have an example:</p>
<blockquote>
<p>Cómo se hace para formatear una PC? Haz click sobre el botón de
inicio. Selecciona la rueda dentada para acceder a Ajustes del
Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de
Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre,
selecciona Restablecer Ajustes de Fábrica.</p>
<p>¿Cómo formatear mi PC windows 10 a estado de fábrica? Haz click sobre
el botón de inicio. Selecciona la rueda dentada para acceder a Ajustes
del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de
Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre,
selecciona Restablecer Ajustes de Fábrica.</p>
</blockquote>
<p>And this is what I need.</p>
<blockquote>
<p>Cómo se hace para formatear una PC?
<b>Haz click sobre el botón de inicio.</b> Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.<br><br>
¿Cómo formatear mi PC windows 10 a estado de fábrica?
<b>Haz click sobre el botón de inicio.</b> Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.</p>
</blockquote>
<p>I try a lot of features but I'm so bad with regex and I couldn't select that.</p>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15360244/"
] |
74,212,463 | <p>I have recently installed SSMS 2022 V18 on my D: drive to conserve some space on the C:
When I try to execute the <code>.dtsx</code> file it says that there is no program available to execute it.
Is there some way to make this work or do I have to re install SSMS on the default C: drive.</p>
<p>10/27/22
Loaded SQL server 19 developer version. included the Integration service. Now I can import my dtsx files and execute them. So far so good. What I would like to do is run the .dtsx packages using DTexec.exe. I follow the example of executing dtexec running a file dtexec /f "d:\documents\sql\hits.dtsx" and it complains about the version numbers.
<em><strong>Package migration from version 8 to version 3 failed with error 0xC001700A "The version number in the package is not valid. The version number cannot be greater than current version number.".</strong></em></p>
<p>THe dtsx file was created while running sql server 19 SSMS v 18.12.1. Should I load the SSMS package from SQL19?</p>
<p>Any other info would great.</p>
<p>Thanks</p>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7954774/"
] |
74,212,467 | <p>Consider the following data</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
<th>Column C</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>t</td>
<td>9</td>
</tr>
<tr>
<td>A</td>
<td>d</td>
<td>12</td>
</tr>
<tr>
<td>A</td>
<td>l</td>
<td>8</td>
</tr>
<tr>
<td>B</td>
<td>x</td>
<td>7</td>
</tr>
<tr>
<td>B</td>
<td>z</td>
<td>9</td>
</tr>
<tr>
<td>B</td>
<td>q</td>
<td>6</td>
</tr>
</tbody>
</table>
</div>
<p>How do I extract the record with the max value in Col C for each value in Col A.</p>
<p>So the expected result would be...</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
<th>Column C</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>d</td>
<td>12</td>
</tr>
<tr>
<td>B</td>
<td>z</td>
<td>9</td>
</tr>
</tbody>
</table>
</div>
<p>Trying</p>
<pre><code>select ColA, max(ColC) from table group by ColA
</code></pre>
<p>doesn't provide the value in ColB.</p>
<p>I'm sure there is a simple and elegant solution here, but it's escaping me....</p>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342152/"
] |
74,212,479 | <p>I'm trying to update a user and add a password to a new column that was created in the database as that password will be encrypted. However I'm getting the following error and it is not being sent as an update on the row but as a new row in the database, I checked and the majority does the update with the .save(method) in the repository but it updates the object not adds a new row:</p>
<pre><code>2022-10-26 12:50:37.648 INFO 13732 --- [nio-8080-exec-3] com.ssc.test.cb3.service.UserService
: Fetching user htorres
Existent user: User(serie=5, username=htorres, name=Herney Torres, password=htorres,
profile=1, email=, status=false, passwordc=null, roles=[Role(serie=1, name=ROLE_USER)])
2022-10-26 12:50:37.793 INFO 13732 --- [nio-8080-exec-3] com.ssc.test.cb3.service.UserService
: Saving new user Herney Torres to the database
2022-10-26 12:50:38.064 WARN 13732 --- [nio-8080-exec-3]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23505
2022-10-26 12:50:38.064 ERROR 13732 --- [nio-8080-exec-3]
o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: llave duplicada viola restricción de
unicidad «usuario_login_key»
Detail: Ya existe la llave (login)=(htorres).
</code></pre>
<p>The last message in Detail says: There is already a key (login) = (htorres).</p>
<p>How can I send the request without the primary key "login" which is the username? I tried to not include it in the request in postman but it returns the error <code>ERROR 13732 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper </code>: ERROR: The value null for the column <> violates the restriction not null`, I checked that with lists it is possible to use the .remove() to not include the primary key as in the following resource, but not sure how in my architecture:</p>
<p><a href="https://www.arquitecturajava.com/spring-rest-put-actualizando-registros/" rel="nofollow noreferrer">SpringRest with arrayLists</a></p>
<p>This is my class:</p>
<pre><code>package com.ssc.test.cb3.controller;
import com.ssc.test.cb3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
/**
* Class to handle REST services and APIs for the Customer's class
*
* @author ssc
*/
@RestController
@RequestMapping("/v1/users")
//@CrossOrigin(origins = "http://localhost:3000")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private PasswordEncoder passwordEncoder;
@PutMapping("/updateUser/{id}")
private ResponseEntity<?> updateUser(@PathVariable("id") String username, @RequestBody User user){
User existentUser = userService.getUser(username);
System.out.println("Existent user: " + existentUser);
existentUser.setPasswordc(passwordEncoder.encode(user.getPasswordc()));
return ResponseEntity.ok(userService.createUser(user));
}
}
</code></pre>
<p>The service class:</p>
<p>package com.ssc.test.cb3.service;</p>
<pre><code>import com.ssc.test.cb3.model.Role;
import com.ssc.test.cb3.model.User;
import com.ssc.test.cb3.repository.RoleRepository;
import com.ssc.test.cb3.repository.UserRepository;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Class to prepare the services to be dispatched upon request regarding Customers.
* @author ssc
*/
@Service
@Transactional
@Slf4j
@RequiredArgsConstructor
public class UserService implements UserDetailsService {
@Autowired
private UserRepository userRepository;
@Autowired
private final RoleRepository roleRepository;
@Autowired
private final PasswordEncoder passwordEncoder;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username); // details from user loaded by getting the username
if(user == null){
log.error("User not found in the database");
throw new UsernameNotFoundException("User not found in the database");
} else {
log.info("User found in the database: {}", username);
}
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
user.getRoles().forEach(role -> {
authorities.add(new SimpleGrantedAuthority(role.getName()));
});
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), authorities);
}
/**
* Method to get details from a user by the username
* @param username key that helps to identify the user we want to retrieve from the database
* @return the user details.
* @throws UsernameNotFoundException
*/
public User getUserDetailsByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findByUsername(username); // details from user loaded by getting the username
if(user == null){
log.error("User not found in the database by that username");
throw new UsernameNotFoundException("User not found in the database by that username");
} else {
log.info("User found in the database: {}", username);
}
return user;
}
/**
*
* @param id
* @return
*/
public User getUser(String username){
log.info("Fetching user {}", username);
return userRepository.findByUsername(username);
}
/**
* Functionality to create a new user
* @param user receives an objet User to be saved on the database
* @return the action of saving the user in the database.
*/
public User createUser(User user){
log.info("Saving new user {} to the database", user.getName());
user.setPassword(passwordEncoder.encode(user.getPassword()));
user.setPasswordc(passwordEncoder.encode(user.getPasswordc()));
return userRepository.save(user);
}
}
</code></pre>
<p>My repository class:</p>
<pre><code>package com.ssc.test.cb3.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.ssc.test.cb3.model.User;
/**
* Class that extends to the repository for database management queries with table Usuario
* @author ssc
*/
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
User findByUsername(String username);
}
</code></pre>
<p>And finally my user entity class:</p>
<pre><code>package com.ssc.test.cb3.model;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Class that models the entity User as table of the database
* @author cardo
*/
@Entity
@Table(name = "usuario")
@Data @NoArgsConstructor @AllArgsConstructor
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int serie;
@Column(name = "login")
private String username; // Username...
@Column(name = "nombre")
private String name;
private String password;
@Column(name = "perfil")
private int profile;
private String email;
@Column(name = "activo")
private boolean status;
private String passwordc;
@ManyToMany(fetch = FetchType.EAGER)
private Collection<Role> roles = new ArrayList<>();
}
</code></pre>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20134306/"
] |
74,212,481 | <p><a href="https://i.stack.imgur.com/ux9LU.png" rel="nofollow noreferrer">This is the logs</a><a href="https://i.stack.imgur.com/gIiqF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gIiqF.png" alt="enter image description here" /></a>
I have built an amazon clone and when i deployed it to vercel the signin with google is not working, and i got this error:
Server error
There is a problem with the server configuration.</p>
<p>Check the server logs for more information.</p>
<p>i have added my environement variables</p>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16225364/"
] |
74,212,497 | <p>In our project we use Auth0 with Google login and don't use username/password login. We started to write tests for our app, but we can't login in Cypress framework. We need login using Google auth (but it's not possible to do it using request). Also, we don't store token in localStorage, because frontend part uses auth0 react sdk for it.</p>
<p>I tried to find how to login in Cypress using auth0, but found only solutions for username/password login.</p>
<p>Possible solution from <a href="https://stackoverflow.com/questions/67222522/auth0-authentication-with-cypress">this post</a>:</p>
<pre class="lang-js prettyprint-override"><code>Cypress.Commands.add("login", () => {
cy.clearLocalStorage();
const email = "";
const password = "";
const client_id = "";
const client_secret = "";
const audience = "";
const scope = "";
cy.request({
method: "POST",
url: "",
body: {
grant_type: "password",
username: email,
password,
audience,
scope,
client_id,
client_secret,
},
}).then(({ body: { access_token, expires_in, id_token, token_type } }) => {
cy.window().then((win) => {
win.localStorage.setItem(
`@@auth0spajs@@::${client_id}::${audience}::${scope}`,
JSON.stringify({
body: {
client_id,
access_token,
id_token,
scope,
expires_in,
token_type,
decodedToken: {
user: JSON.parse(
Buffer.from(id_token.split(".")[1], "base64").toString("ascii")
),
},
audience,
},
expiresAt: Math.floor(Date.now() / 1000) + expires_in,
})
);
cy.reload();
});
});
});
</code></pre>
<p>I can get token using <code>client_credentials</code> grant type, but I can't use it in this solution, because it uses <code>id_token</code> instead of the <code>access_token</code>.</p>
<p>Is it possible to use <code>client_credentials</code> grant type for this login? Or should we turn ON username/password login for it?</p>
<p>Request for <code>client_credentials</code> grant type:</p>
<pre><code>curl --request POST \
--url 'https://YOUR_DOMAIN/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=YOUR_CLIENT_ID \
--data client_secret=YOUR_CLIENT_SECRET \
--data audience=YOUR_API_IDENTIFIER
</code></pre>
<p>It returns:</p>
<pre class="lang-json prettyprint-override"><code>{
"access_token":"eyJz93a...k4laUWw",
"token_type":"Bearer",
"expires_in":86400
}
</code></pre>
| [
{
"answer_id": 74212562,
"author": "JRiggles",
"author_id": 8512262,
"author_profile": "https://Stackoverflow.com/users/8512262",
"pm_score": 1,
"selected": false,
"text": "(?<=\\? )[^\\.]*"
},
{
"answer_id": 74269183,
"author": "Alex Bright",
"author_id": 16457174,
"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14425528/"
] |
74,212,512 | <p>I'm trying to draw rectangles pattern using DrawRect like this:</p>
<p><a href="https://i.stack.imgur.com/vPpA2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vPpA2.png" alt="enter image description here" /></a></p>
<p>Currently, I'm doing this like so:</p>
<pre><code>class PatternView: UIView {
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let numberOfBoxesPerRow = 7
let boxSide: CGFloat = rect.width / CGFloat(numberOfBoxesPerRow)
var yOrigin: CGFloat = 0
var xOrigin: CGFloat = 0
var isBlack = true
for y in 0...numberOfBoxesPerRow - 1 {
yOrigin = boxSide * CGFloat(y)
for x in 0...numberOfBoxesPerRow - 1 {
xOrigin = boxSide * CGFloat(x)
let color = isBlack ? UIColor.red : UIColor.blue
isBlack = !isBlack
context?.setFillColor(color.cgColor)
let rectnagle = CGRect(origin: .init(x: xOrigin, y: yOrigin), size: .init(width: boxSide, height: boxSide))
context?.addRect(rectnagle)
context?.fill([rectnagle])
}
}
}
}
</code></pre>
<p><strong>It's working but I'm trying to optimize it.<br />
Any help will be highly appreciated!</strong></p>
| [
{
"answer_id": 74212768,
"author": "Pierre",
"author_id": 12931221,
"author_profile": "https://Stackoverflow.com/users/12931221",
"pm_score": 1,
"selected": false,
"text": "context?.addRect(rectnagle)\ncontext?.fill([rectnagle])\n"
},
{
"answer_id": 74213146,
"author": "DonMa... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4156957/"
] |
74,212,516 | <p>This is in continuation from my previous question. I have 2 files, <code>file1.csv</code> and a large csv called <code>master_file.csv</code>. They have several columns and have a common column name called <code>EMP_Code</code>.</p>
<p>File 1 example:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>EMP_name</th>
<th>EMP_Code</th>
<th>EMP_dept</th>
</tr>
</thead>
<tbody>
<tr>
<td>b</td>
<td>f367</td>
<td>abc</td>
</tr>
<tr>
<td>a</td>
<td>c264</td>
<td>xyz</td>
</tr>
<tr>
<td>c</td>
<td>d264</td>
<td>abc</td>
</tr>
</tbody>
</table>
</div>
<p><code>master_file</code> example:</p>
<pre><code>EMP_name EMP_age EMP_Service EMP_Code EMP_dept
a 30 6 c264 xyz
b 29 3 f367 abc
r 27 1 g364 lmn
d 45 10 c264 abc
t 50 25 t453 lmn
</code></pre>
<p>I want to extract similar rows from <code>master_file</code> using all the <code>EMP_Code</code> values in <code>file1</code>. I tried the following code and I am loosing a lot of data. I cannot read the complete master csv file as it is around 20gb, has millions of rows and running out of memory. I want to read the <code>master_file</code> in chunks and extract the complete rows for each of the <code>EMP_Code</code> present in <code>file1</code> and save it into new file <code>Employee_full_data</code>.</p>
<pre class="lang-py prettyprint-override"><code>import csv
import pandas as pd
df = pd.read_csv(r"master_file.csv")
li = [c264,f367]
full_data = df[df.EMP_Code.isin(li)]
full_data.to_csv(r"Employee_full_data.csv", index=False)
</code></pre>
<p>I also tried the following code. I receive an empty file whenever I use <code>EMP_Code</code> column and works fine when I use columns like <code>Emp_name</code> or <code>EMP_dept</code>. I want to extract the data using <code>EMP_Code</code>.</p>
<pre class="lang-py prettyprint-override"><code>import csv
import pandas as pd
df = pd.read_csv(r"file1.csv")
list_codes = list(df.EMP_Code)
selected_rows = []
with open(r"master_file.csv") as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
if row['EMP_Code'] in list_codes:
selected_rows.append(row)`
article_usage = pd.DataFrame.from_records(selected_rows)
article_usage.to_csv(r"Employee_full_data.csv", index=False)
</code></pre>
<p>Is there any other way that I can extract the data without loss? I have heard about join and reading data in chunks but not sure how to use it here. Any help is appreciated</p>
| [
{
"answer_id": 74212768,
"author": "Pierre",
"author_id": 12931221,
"author_profile": "https://Stackoverflow.com/users/12931221",
"pm_score": 1,
"selected": false,
"text": "context?.addRect(rectnagle)\ncontext?.fill([rectnagle])\n"
},
{
"answer_id": 74213146,
"author": "DonMa... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17965533/"
] |
74,212,561 | <p>So lately I've been trying to make a "SHOW MORE" and "SHOW LESS" feature with embedded SVG.</p>
<p>The code seems to be working fine, although each time I add another button I have to create completly new function therefore I was wondering if you could help me optimize my code.</p>
<p>Currently it looks like this:</p>
<pre><code><!-- HTML CODE -->
<button id="hideShow" class="button slide-down">SHOW MORE
<svg id="showMoreSVG" width="13px" height="10px" viewBox="0 2 13 10">
<path id="showMorePATH" d="M 1 5 L 1 5 L 5 9 L 9 5 L 5 9"></path>
</svg>
</button>
</code></pre>
<pre><code>// js code
var button = document.getElementById("hideShow");
var content = document.getElementById("more-text");
let text = button.innerHTML.replace("MORE", "LESS");
let textR = button.innerHTML.replace("LESS", "MORE");
button.onclick = function () {
if (content.className == "open") {
content.className = "";
document.getElementById("hideShow").innerHTML = textR;
document.getElementById("showMoreSVG").setAttribute("viewBox", "0 2 13 10");
document
.getElementById("showMorePATH")
.setAttribute("d", "M 1 5 L 1 5 L 5 9 L 9 5 L 5 9");
} else {
content.className = "open";
document.getElementById("hideShow").innerHTML = text;
document
.getElementById("showMoreSVG")
.setAttribute("viewBox", "0 -2 13 10");
document
.getElementById("showMorePATH")
.setAttribute("d", "M 1 5 L 1 5 L 5 1 L 9 5 L 5 1");
}
};
</code></pre>
<p>Result as img:</p>
<p><a href="https://i.stack.imgur.com/Uckku.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uckku.png" alt="show more button" /></a></p>
<p><a href="https://i.stack.imgur.com/N6TuI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N6TuI.png" alt="show less button" /></a></p>
<p>It works based on changing max-height property in css class that is different depending on size of text (some are smaller, some are larger).
For example:</p>
<pre><code>#more-text,
#more-text2 {
max-height: 0px;
overflow: hidden;
transition: max-height 0.7s ease;
}
#more-text.open {
max-height: 1600px;
transition: max-height 0.7s ease;
}
#more-text2.open {
max-height: 600px;
}
</code></pre>
<p>I know that the part of css code can be optimized with jQuery but I don't want to implement it on my website. Rather vanilla javascript or some npm package.</p>
<p>Also I do realize that <code>content.className = "open";</code> is invalid way to change class, this is something I have on my todo list so please don't bother with that part.</p>
<p>Any help is much appreciated.</p>
| [
{
"answer_id": 74212768,
"author": "Pierre",
"author_id": 12931221,
"author_profile": "https://Stackoverflow.com/users/12931221",
"pm_score": 1,
"selected": false,
"text": "context?.addRect(rectnagle)\ncontext?.fill([rectnagle])\n"
},
{
"answer_id": 74213146,
"author": "DonMa... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9429122/"
] |
74,212,571 | <p>So we have a test file that has a 3 digit number per line, several hundred lines of in the file.</p>
<p>I need to find a way to read from the file the number (or 3 digits that make up the number), add them together, and then determine if the resulting sum is odd or even. My current script is reading each line as a whole number, and I am missing the part where I am able to sum the digits...</p>
<pre><code>while read number
do
echo $number
if [ $((number % 2)) -eq 0 ]; then
echo even
else
echo odd
fi
done < input.txt
</code></pre>
| [
{
"answer_id": 74212768,
"author": "Pierre",
"author_id": 12931221,
"author_profile": "https://Stackoverflow.com/users/12931221",
"pm_score": 1,
"selected": false,
"text": "context?.addRect(rectnagle)\ncontext?.fill([rectnagle])\n"
},
{
"answer_id": 74213146,
"author": "DonMa... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342309/"
] |
74,212,601 | <p>I am trying to make a code in C that takes a number as an input, counts how many times 0-9 appears in the given number.
The code as nooby as it might is:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,dig,dat[9],mod;
printf("Give a number: ");
scanf("%d",&num);
mod = num % 10;
while(mod != 0)
{
if(mod > 1)
{
dig = mod / 10;
while(dig >= 0 )
{
++dat[dig];
}
}
else if(mod =1)
{
dig = mod/1;
while(dig >= 0 )
{
++dat[dig];
}
}
--mod;
}
printf("%d appears %d\n",dig,dat[dig]);
return 0;
}
</code></pre>
<p>Thanks in advance</p>
<p>Nothing really works, i dont even get any response from printf.</p>
| [
{
"answer_id": 74212768,
"author": "Pierre",
"author_id": 12931221,
"author_profile": "https://Stackoverflow.com/users/12931221",
"pm_score": 1,
"selected": false,
"text": "context?.addRect(rectnagle)\ncontext?.fill([rectnagle])\n"
},
{
"answer_id": 74213146,
"author": "DonMa... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342366/"
] |
74,212,612 | <p>I have two sets of data that I will be evaluating against one another. A heavily reduced example looks like this:</p>
<pre><code>library(dplyr)
library(tidyverse)
library(sqldf)
library(dbplyr)
library(httr)
library(purrr)
library(jsonlite)
library(magrittr)
library(tidyr)
library(tidytext)
people_records_ex <- structure(list(id = c(123L, 456L, 789L), name = c("Anna Wilson",
"Jeff Smith", "Craig Mills"), biography = c("Student at Ohio State University. Class of 2024.",
"Second year law student at Stanford. Undergrad at William & Mary",
"University of North Texas Volleyball!")), class = "data.frame", row.names = c(NA,
-3L))
college_records_ex <- structure(list(college_id = c(234L, 567L, 891L, 345L), college_name = c("Ohio State University",
"Stanford", "William & Mary", "University of North Texas"), college_city = c("Columbus",
"Stanford", "Williamsburg", "Denton"), college_state = c("OH",
"CA", "VA", "TX")), class = "data.frame", row.names = c(NA, -4L
))
</code></pre>
<p>I am trying to create a match against the contents of the <code>biography</code> text string in <code>people_records_ex</code> against <code>college_name</code> in <code>college_records_ex</code> so the final output will look like this:</p>
<pre><code> final_records_ex <- structure(list(id = c(123L, 456L, 456L, 789L), name = c("Anna Wilson",
"Jeff Smith", "Jeff Smith", "Craig Mills"), college_name = c("Ohio State University",
"Stanford", "William & Mary", "University of North Texas"), college_city = c("Columbus",
"Stanford", "Williamsburg", "Denton"), college_state = c("OH",
"CA", "VA", "TX")), class = "data.frame", row.names = c(NA, -4L
))
</code></pre>
<p>Or to provide a more visual example of the final output I'm expecting:</p>
<p><a href="https://i.stack.imgur.com/L9w0u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L9w0u.png" alt="enter image description here" /></a></p>
<p>But when I run the following code, it produces zero results, which is not correct:</p>
<pre><code>college_extract <- people_records_ex %>%
left_join(college_records_ex, by = c("biography" = "college_name")) %>%
filter(!is.na(college_state)) %>% dplyr::select(id, name, college_name, college_city, college_state) %>% distinct()
</code></pre>
<p>What am I doing incorrectly and what would the correct version look like?</p>
| [
{
"answer_id": 74212840,
"author": "ejneer",
"author_id": 8827325,
"author_profile": "https://Stackoverflow.com/users/8827325",
"pm_score": 1,
"selected": false,
"text": "library(dplyr)\n\npeople_records_ex <- structure(list(id = c(123L, 456L, 789L), name = c(\n \"Anna Wilson\",\n \"Je... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5468495/"
] |
74,212,647 | <p>The following piece of code works fine.</p>
<pre><code>a = 2.0
b = int(a)
</code></pre>
<p>And <code>b</code> is <code>2</code>.</p>
<p>But the following does not work:</p>
<pre><code>a = None
b = int(a)
</code></pre>
<p>I get the following error:</p>
<blockquote>
<p>TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'</p>
</blockquote>
<p>This works:</p>
<pre><code>a = None
if a != None:
b = int(a)
else:
b = 0
</code></pre>
<p>But it is too much code because I have several such variables in my use case that can be None.</p>
<p>What I want:</p>
<ul>
<li>b = a, if a is not None.</li>
<li>b = 0, if a is None</li>
</ul>
<p>Is there an elegant way of doing this with a built in function or something that I am not aware of the existence of...?</p>
| [
{
"answer_id": 74212767,
"author": "scotscotmcc",
"author_id": 15804190,
"author_profile": "https://Stackoverflow.com/users/15804190",
"pm_score": 2,
"selected": false,
"text": "try:...except:..."
},
{
"answer_id": 74212796,
"author": "Kelly Bundy",
"author_id": 12671057,... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328846/"
] |
74,212,658 | <p>I was planning to <a href="https://towardsdatascience.com/named-entity-recognition-ner-with-bert-in-spark-nlp-874df20d1d77" rel="nofollow noreferrer">train a Spark NLP custom NER model</a>, which uses the CoNLL 2003 format to do so (this blog even leaves some <a href="https://github.com/JohnSnowLabs/spark-nlp/tree/master/src/test/resources/conll2003" rel="nofollow noreferrer">traning sample data</a> to speed-up the follow-up). This "sample data" is NOT useful for me, as I have my own training data to train a model with; this data however, consists of a list of spaCy <a href="https://spacy.io/api/doc" rel="nofollow noreferrer">Doc</a> objects and quite honestly, I don't know how to carry on with this conversion. I have found three approaches so far, each with some <em>considerable</em> weakness:</p>
<ol>
<li><p>In spaCy's documentation, I have found <a href="https://spacy.io/universe/project/spacy-conll" rel="nofollow noreferrer">an example code</a> about how to build a SINGLE Doc to CoNLL using <a href="https://github.com/BramVanroy/spacy_conll" rel="nofollow noreferrer"><code>spacy_conll</code> project</a>, but notice it uses a blank spacy model, so it is not clear where "my own labeled data" comes to play; <a href="https://github.com/BramVanroy/spacy_conll#in-python" rel="nofollow noreferrer">furthermore</a>, it seems <code>conll_formatter</code> component is "added at the end of the pipeline", so it seems "no direct conversion from Doc to CoNLL is actually done"... Is my grasping correct?</p>
</li>
<li><p>In Prodigy forum (another product of the same designers of spaCy), I found <a href="https://support.prodi.gy/t/ner-format-to-conll/1153" rel="nofollow noreferrer">this purposal</a>, however that "CoNLL" (2003 I suppose?) format seems to be incomplete: the POS tag seems to be missing (which can be easily obtained via <a href="https://spacy.io/api/token#attributes" rel="nofollow noreferrer"><code>Token.pos_</code></a>, as well as the <em>"Syntactic chunk"</em> (whose spaCy equivalent, does not seem to exist). These four fields are mentioned in <a href="https://www.clips.uantwerpen.be/conll2003/ner/#:%7E:text=Spanish%20and%20Dutch.-,Software%20and%20Data,-The%20CoNLL%2D2003" rel="nofollow noreferrer">CoNLL 2003 official documentation</a>.</p>
</li>
<li><p>Speaking of a "direct conversion from Doc to CoNLL", I have also found <a href="https://github.com/explosion/spaCy/issues/5188#issuecomment-602848635" rel="nofollow noreferrer">this</a> implementation based on <code>textacy</code> library, but it seems this implementation got deprecated by version <a href="https://github.com/chartbeat-labs/textacy/blob/main/CHANGES.md#0110-2021-04-12" rel="nofollow noreferrer">0.11.0</a>, because <em>"CONLL-U [...] wasn't enforced or guaranteed"</em> , so I am not sure whether to use it or not (BTW, the most up-to-date <code>textacy</code> implementation when writing these lines, is <code>0.12.0</code>)</p>
</li>
</ol>
<p>My current code looks like:</p>
<pre class="lang-py prettyprint-override"><code>import spacy
from spacy.training import offsets_to_biluo_tags
from spacy.tokens import Span
print("SPACY HELPER MODEL")
base_model = "en_core_web_sm"
nlp = spacy.load(base_model)
to_disable= ['parser', 'lemmatizer', 'ner']
_ = [nlp.remove_pipe(item) for item in to_disable]
print("Base model used: ", base_model)
print("Removed components: ", to_disable)
print("Enabled components: ", nlp.pipe_names)
# Assume text is already available as sentences...
# so no need for spaCy `sentencizer` or similar
print("\nDEMO SPACY DOC LIST BUILDING...", end="")
doc1 = nlp("iPhone X is coming.")
doc1.ents = [Span(doc1, 0, 2, label="GADGET")]
doc2 = nlp("Space X is nice.")
doc2.ents = [Span(doc1, 0, 2, label="BRAND")]
docs = [doc1, doc2]
print("DONE!")
print("\nCoNLL 2003 CONVERSION:\n")
results = []
for doc in docs:
# Preliminary: whole sentence
whole_sentence = doc.text
# 1st item (CoNLL 2003): word
words = [token.text for token in doc]
# 2nd item (CoNLL 2003): POS
pos = [token.tag_ for token in doc]
# 3rd item (CoNLL 2003): syntactic chunk tag
sct = ["[UNKNOWN]" for token in doc]
# 4th item (CoNLL 2003): named entities
spacy_entities = [
(ent.start_char, ent.end_char, ent.label_)
for ent in doc.ents
]
biluo_entities = offsets_to_biluo_tags(doc, spacy_entities)
results.append((whole_sentence, words, pos, sct, biluo_entities))
for result in results:
print(
"\nDOC TEXT (NOT included in CoNLL 2003, just for demo): ",
result[0], "\n"
)
print("-DOCSTART- -X- -X- O")
for w,x,y,z in zip(result[1], result[2], result[3], result[4]):
print(w,x,y,z)
# Pending: write to a file, but that's easy, and out of topic.
</code></pre>
<p>Which gives as output:</p>
<pre><code>DOC TEXT (NOT included in CoNLL 2003, just for demo): iPhone X is coming.
-DOCSTART- -X- -X- O
iPhone NNP [UNKNOWN] B-GADGET
X NNP [UNKNOWN] L-GADGET
is VBZ [UNKNOWN] O
coming VBG [UNKNOWN] O
. . [UNKNOWN] O
DOC TEXT (NOT included in CoNLL 2003, just for demo): Space X is nice.
-DOCSTART- -X- -X- O
Space NNP [UNKNOWN] B-BRAND
X NNP [UNKNOWN] L-BRAND
is VBZ [UNKNOWN] O
nice JJ [UNKNOWN] O
. . [UNKNOWN] O
</code></pre>
<p>Have you done something like this before?</p>
<p>Thanks!</p>
| [
{
"answer_id": 74216553,
"author": "polm23",
"author_id": 355715,
"author_profile": "https://Stackoverflow.com/users/355715",
"pm_score": 1,
"selected": false,
"text": "for doc in docs:\n for sent in doc.sents:\n print(\"#\", doc) # optional but makes it easier to read\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16706763/"
] |
74,212,662 | <p>Google sheets issue. I want a formula that will return TRUE or FALSE if two conditions are met. However for one of the conditions there are two possibilities.</p>
<p><strong>IF</strong> A2="Pizza <strong>OR</strong> Banana" <strong>AND</strong> B2="Food" then return TRUE</p>
<p>How can I go about it? For now I did the following but I am missing one option (banana):</p>
<pre><code>=IF(AND($A2="Pizza"),$B2="Food")
</code></pre>
<p>Thank you!</p>
| [
{
"answer_id": 74212735,
"author": "John Fish",
"author_id": 1020383,
"author_profile": "https://Stackoverflow.com/users/1020383",
"pm_score": 2,
"selected": false,
"text": "=IF(AND(OR(A2=\"Pizza\", A2=\"Banana\"), B2=\"Food\"), TRUE, FALSE)"
},
{
"answer_id": 74215001,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19618191/"
] |
74,212,688 | <p>i tried to create (my first) login page, i did communication between client and server with WebSocket in JS, it check credentials of user (Token that makes you login to page). Only thing that i can't figure out is how to redirect user to other page, with sure that, he will be logged into this account and to protect from not authorized users. (server -> (JS) nodemon, client -> JS, HTML, CSS)</p>
<p>I expect that someone will make this topic clear to me, and explain how to code it :)</p>
| [
{
"answer_id": 74212735,
"author": "John Fish",
"author_id": 1020383,
"author_profile": "https://Stackoverflow.com/users/1020383",
"pm_score": 2,
"selected": false,
"text": "=IF(AND(OR(A2=\"Pizza\", A2=\"Banana\"), B2=\"Food\"), TRUE, FALSE)"
},
{
"answer_id": 74215001,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19361172/"
] |
74,212,691 | <p>Using while loop to print 10-20 odd numbers on the screen, with <-> (exapmle 11-13-15-17-19, <-> not after 19).How to take the last number so as not to put a -. Thank you.</p>
<pre><code><?php
$x = 10;
while($x < 20){
$x++;
if($x % 2){
echo $x. "-";
}
}
</code></pre>
| [
{
"answer_id": 74212824,
"author": "Max Pattern",
"author_id": 18066399,
"author_profile": "https://Stackoverflow.com/users/18066399",
"pm_score": 2,
"selected": true,
"text": "$x = 10;\n$arr = [];\nwhile($x<20){\n $x++;\n if ($x%2){\n $arr[] = $x;\n }\n}\necho implode(\",\", $arr)... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324382/"
] |
74,212,741 | <p>I'm looking for type hint on an model object instance class:</p>
<pre><code>>>> Device.objects.get(pk=31)
<Device: Device object (31)>
>>> device = Device.objects.get(pk=31)
>>> type(device)
<class 'inventory.models.Device'>
</code></pre>
<p>I'll be passing above into a function which will be performing some action but i can't figure out what to use for the device object in the function where type hinting will take place?</p>
<pre><code>def do_something(device: ???) -> bool:
if device.id:
some_logic
return True
</code></pre>
| [
{
"answer_id": 74212824,
"author": "Max Pattern",
"author_id": 18066399,
"author_profile": "https://Stackoverflow.com/users/18066399",
"pm_score": 2,
"selected": true,
"text": "$x = 10;\n$arr = [];\nwhile($x<20){\n $x++;\n if ($x%2){\n $arr[] = $x;\n }\n}\necho implode(\",\", $arr)... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8086671/"
] |
74,212,780 | <p>So i have a list of values of longitude and latitude</p>
<pre><code>[[-82.99194508, 40.04649963], [-82.99223727, 40.04659349], [-82.99198391, 40.04614863], [-82.99211513, 40.04627218]]
</code></pre>
<p>and a dataframe</p>
<pre><code>hhinc8,owncar,longitude,latitude
5,1,-82.99194508,40.04649963
6,2,-82.99584706,40.03738548
5,1,-82.99697268,40.02674247
6,2,-82.99160441,40.03612997
6,2,-82.994716,40.04691778
6,2,-82.99793728,40.04385713
5,2,-82.98986012,40.03789279
7,2,-82.99602685,40.03216463
6,1,-82.99362168,40.0372023
.
.
.
</code></pre>
<p>How can I drop all the rows from the dataframe that have same longitude and latitude values as the given list</p>
| [
{
"answer_id": 74213046,
"author": "Naveed",
"author_id": 3494754,
"author_profile": "https://Stackoverflow.com/users/3494754",
"pm_score": 3,
"selected": true,
"text": "#create a DF from the list of the long/lat you want to exclude\n\ndf2=pd.DataFrame(l, columns=['longitude1','latitude1... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212780",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19490188/"
] |
74,212,789 | <p><a href="https://i.stack.imgur.com/gFl36.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gFl36.png" alt="Small snippet of a table with fields RecordSource, OrderNumber, and SerialNumber" /></a></p>
<p>Trying to make a new column in this large dataset that takes the serial number from the RecordSource SO rows and applies it to SI rows containing the same order number.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 74213046,
"author": "Naveed",
"author_id": 3494754,
"author_profile": "https://Stackoverflow.com/users/3494754",
"pm_score": 3,
"selected": true,
"text": "#create a DF from the list of the long/lat you want to exclude\n\ndf2=pd.DataFrame(l, columns=['longitude1','latitude1... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19845938/"
] |
74,212,793 | <p>I have a number of .msg files, which are saved emails from Outlook 2016. Some emails are encrypted, some have attachments.
How to figure out if email encrypted?
It should work on the <strong>server which do not have Office installed</strong>. Now I'm writing prove of concept console app, but this code also could be used in web app.
Could be subsequent tasks to a get list of recipients if it's encrypted. Is it even possible? It may require decryption, which could be .. difficult, if you are not a recipient.
Observation: if I search email string "sam@boo.com" in the .msg file, then I can find it only if email unencrypted.</p>
<p><a href="https://i.stack.imgur.com/FEVu1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FEVu1.png" alt="Example of creating email in the Outlook:" /></a></p>
<p><a href="https://i.stack.imgur.com/BqHNE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BqHNE.png" alt="Error opening encrypted email in the Outlook if you are not a recipient:" /></a></p>
<p><a href="https://i.stack.imgur.com/KWHI3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KWHI3.png" alt="Normal and encrypted .msg files in Notepad" /></a></p>
<p>My pseudo code below. I installed libary Microsoft.Office.Interop.Outlook by NuGet:</p>
<pre><code>using Microsoft.Office.Interop.Outlook;
namespace EmlReader
{
class Program
{
static void Main(string[] args)
{
const string emailPath = @"C:\Test\temp-saved-mail-enc.msg";
Microsoft.Office.Interop.Outlook.MailItem mailItem = ... load from file // how?
Outlook.Application POfficeApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application"); // note that it returns an exception if Outlook is not running
Outlook.MailItem POfficeItem = (Outlook.MailItem)POfficeApp.ActiveInspector().CurrentItem; // now pOfficeItem is the COM object that represents your .eml file
}
}
}
</code></pre>
<p>PS Related article written by me in relation to Outlook Plugin:
<a href="https://stackoverflow.com/questions/74102522/how-to-check-if-outlook-email-encrypted">How to check if outlook email encrypted?</a> But it related to workstation, not to the server.</p>
| [
{
"answer_id": 74213046,
"author": "Naveed",
"author_id": 3494754,
"author_profile": "https://Stackoverflow.com/users/3494754",
"pm_score": 3,
"selected": true,
"text": "#create a DF from the list of the long/lat you want to exclude\n\ndf2=pd.DataFrame(l, columns=['longitude1','latitude1... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3394776/"
] |
74,212,794 | <p>With the OpenNTF Domino API, I'm taking a <code>ViewEntryCollection</code> from a view that returns approximately 50k documents and I want to get a subset of these, perhaps 100 at a time but not starting at the first document.</p>
<p>The most obvious solution is looping over each entry using the <code>getNthEntry(int i)</code> method in the <code>ViewEntryCollection</code> class. However this seems about 20% slower than getting documents using for-each*. The <a href="https://help.hcltechsw.com/dom_designer/11.0.1/basic/H_GETNTHENTRY_METHOD_VEC_JAVA.html" rel="nofollow noreferrer">HCL documentation</a> discourages developers from using this method due to performance reasons too and I've yet to test this at scale.</p>
<p>Example code below:</p>
<pre><code> ViewEntryCollection vec = ...get some data in a collection...;
ViewEntry ve = null;
while(i < countEnd && (ve = vec.getNthEntry(i)) != null) {
if(ve.isDocument()) {
//Do something
}
i++;
}
</code></pre>
<p>As opposed to</p>
<pre><code> int i=0;
for(ViewEntry ve : vec) {
if(ve.isDocument()) {
//Do some processing here
i++;
}
if(i==this.maxDocs) break;
}
</code></pre>
<p>Is there a higher performance way of getting, say, 100 entries starting at entry i where i>0?</p>
<p>*Note: I ran a test using getNthEntry against the for-each loop starting from the first document and returning a few hundred documents.</p>
<p>Many thanks</p>
| [
{
"answer_id": 74222353,
"author": "Andre Krepsky",
"author_id": 4338049,
"author_profile": "https://Stackoverflow.com/users/4338049",
"pm_score": 2,
"selected": false,
"text": "getNth()"
},
{
"answer_id": 74224734,
"author": "Per Henrik Lausten",
"author_id": 785061,
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12571484/"
] |
74,212,839 | <p>I wrote the 1st ever macro.(Windows 10, WORD 2019)
I'm trying to find words that start with a capital letter in Standard style and continue to have Italic style.
Unfortunately, if I search a document using too many letters in the query - the macro closes (after checking, for example, 1.5 pages) or resets the WORD program.</p>
<p>If I reduce the number of words searched - the macro starts to run longer and longer.
With, for example, a search for 1 letter (U) instead of 32 (ABCDEFGHIJKLŁMNOPQRSTUVWXYZĆŚŃŻŹ) - it does not crash the program.</p>
<p>I tried to add</p>
<pre><code>Application.ScreenUpdating = False at the beginning and
Application.ScreenUpdating = True at the end of the code but it doesn't help much.
</code></pre>
<hr>
<pre><code>Sub Makro1()
Dim Rng As Range
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.find.ClearFormatting
With Selection.find.Font
.Bold = False
.Italic = False
End With
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = "U"
'.Text = "([ABCDEFGHI])"
'.Text = "([ABCDEFGHI])"
'.Text = "([JKLŁMNOP])"
'.Text = "([QRSTUVWX])"
'.Text = "([YZĆŚŃŻŹ])"
'.Text = "([ABCDEFGHIJKLŁMNOPQRSTUVWXYZĆŚŃŻŹ])"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Set Rng = Selection.Range
If Rng.Italic = True Then
MsgBox "FIND"
End
If Rng.Italic = False Then
Call Makro1
End If
End If
Call Makro1
End Sub
</code></pre>
<p>Thanks but your code didn't work. I change the code to:</p>
<pre><code>If .Words.Last.Characters(2).Font.Italic = True Then
.Characters(1).Font.Italic = True
End If
</code></pre>
<p>.find.Execute
but it only worked sometimes. When I enabled the macro on a longer text, the macro would hang, show error 5941 "collection object not exist" and stop on the line:</p>
<p>If .Words.Last.Characters(2).Font.Italic = True Then
I spent a lot of time before I discovered why. It turns out that the macro crashes because sometimes there is a punctuation mark in the text next to a capital letter, e.g. period comma...etc. e.g A. B; C: D., The code would have to be improved to ignore this. I try add .IgnorePunct = True after .MatchCase = True but didn't help and macro still crashes</p>
<p>I try change code:</p>
<p>.Text = "<[A-Z][!.,;:„”#$%-+=[\[/[//[@[?[![#[$[%[*[([)[&[*[{[}]*>"
Macro fix some errors in text, work longer but still somewhere is an unacceptable sign after a character with a capital letter and the macro crashes.</p>
<p>Add more unwanted signs</p>
<p>.Text = "<[A-Z][!.,;:„”#$%-+=[\[/[//[@[?[![#[$[%[*[([)[&[*[{[}[<[>_|` - …]*>"
and still the macro crashes.</p>
<p>After rewriting the code to show live which words it checks, I was able to understand in part why the macro crashes.
Problem is hard space:
<a href="https://i.stack.imgur.com/Ojp5M.jpg" rel="nofollow noreferrer">1</a> and the comma after digit
if I use normal space instead of hard space - macro work OK.</p>
<p>If change to N = 5, to N = 5 , also work OK.</p>
<p>Another place with STOP working:</p>
<p><a href="https://i.stack.imgur.com/eFNMp.jpg" rel="nofollow noreferrer">2</a></p>
<p><a href="https://i.stack.imgur.com/2V8yP.jpg" rel="nofollow noreferrer">3</a></p>
<p>I don't know what other adjustments to make so that the macro doesn't hang up in these places.</p>
<p>[EDIT]
I don't know too much what I'm doing, but I changed the code to:</p>
<pre><code>Sub m1select()
Application.ScreenUpdating = False
With Selection.find
.Text = "<[A-Za-z0-9][! ^13.^s^t^+^=,;:„”#$%-+=[\[[\][\\[\/[\//[\@[\?[\![\#[\$[\%[\*[\([\)[\&[\*[\{[\}[\<[\>_|` - …-]*>"
.MatchWildcards = True
.Execute Forward:=True, Wrap:=wdFindStop
End With
With ActiveDocument.Content
Do While Selection.find.Found
If Selection.Words.Last.Characters(1).Font.Italic = True Or Selection.Words.Last.Characters(2).Font.Italic = True Then
Selection.Font.Italic = True
End If
Selection.find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
</code></pre>
<p>and it works. It now corrects all words with partial Italic font not just capitalized.
Admittedly, it does it slowly because I used "Select" , but that way I can see what character the macro hangs on and add it to the exclusion in after the [!
( as all the time is Application.ScreenUpdating = True)
Doesn't work on expressions with a single U e.g.
U <em>letter</em> (after correction it should be <em>U letter</em>) but I make it myself with another script.</p>
| [
{
"answer_id": 74222353,
"author": "Andre Krepsky",
"author_id": 4338049,
"author_profile": "https://Stackoverflow.com/users/4338049",
"pm_score": 2,
"selected": false,
"text": "getNth()"
},
{
"answer_id": 74224734,
"author": "Per Henrik Lausten",
"author_id": 785061,
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342355/"
] |
74,212,851 | <p>My question is more about how to improve what I suspect is inefficient code.</p>
<p>I have two dataframes: one contains data on county-level disaster information and the other contains data on county-level income per-capita. As a first step, I am interested in identifying for which counties we are missing per-capita income data. Here is what that looks like with sample dataframes:</p>
<pre><code>counties <- data.frame(polyname = c("alabama,autauga","alabama,autauga",
"alabama,baldwin","alabama,baldwin",
"alabama,barbour","alabama,barbour",
"alabama,bibb", "alabama,bibb"),
indAnyDisaster_frequency = c("1-2", "1-2", "0", "0",
"3-5", "3-5", "1-2","1-2"))
counties_persinc_1980 <- data.frame(polyname = c("alabama,autauga","alabama,autauga",
"alabama,baldwin","alabama,baldwin",
"alabama,barbour","alabama,barbour",
"alabama,bibb", "alabama,bibb"),
persinc_1980 = c(NA, NA, NA, NA, 25, 30, 32, 28))
no_persinc_1980 <- unique(counties_persinc_1980$polyname[is.na(counties_persinc_1980$persinc_1980)])
</code></pre>
<p>Now, I want to use the vector of missing county names to replace counties$indAnyDisaster_frequency with NA if the counties$polyname of the same index matches an element of the vector. I believe I have been able to achieve this with a for-loop, but I don't believe it is very efficient. However, I have not been able to figure out how to use lapply to achieve the same outcome. I've included both the code for the loop and one of my attempts at using lapply.</p>
<pre><code>for(i in 1:length(no_persinc_1980)){
counties$indAnyDisaster_frequency[counties$polyname==no_persinc_1980[i]] <- NA
}
lapply(1:length(no_persinc_1980), function(x) counties$indAnyDisaster_frequency[counties$polyname==no_persinc_1980[x]] <- NA)
</code></pre>
<p>Any guidance on how to improve this approach would be appreciated.</p>
| [
{
"answer_id": 74212936,
"author": "Tom Hoel",
"author_id": 17213355,
"author_profile": "https://Stackoverflow.com/users/17213355",
"pm_score": 0,
"selected": false,
"text": "library(tidyverse)\n"
},
{
"answer_id": 74212942,
"author": "AndS.",
"author_id": 9778513,
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20169300/"
] |
74,212,908 | <p>I have a dataframe that represents a two year daily time series of temperature for two rivers. For each river and each year, I would like to know what day of year:</p>
<ol>
<li>temperature is greater than or equal to 15 degrees</li>
<li>temperature is sustained greater than or equal to 15 degrees (sustained is when there are no more dips below 15 until the autumn)</li>
<li>temperature is less than or equal to 15 degrees</li>
<li>temperature is sustained less than or equal to 15 degrees (sustained is when there are are no more peaks above 15 until the following spring)</li>
</ol>
<p>Example timeseries</p>
<pre><code>library(ggplot2)
library(lubridate)
library(dplyr)
library(dataRetrieval)
siteNumber <- c("01428500","01432805") # United States Geological Survey site numbers
parameterCd <- "00010" # temperature
statCd <- "00003" # mean
startDate <- "2018-01-01"
endDate <- "2019-10-31"
dat <- readNWISdv(siteNumber, parameterCd, startDate, endDate, statCd=statCd) # obtains the timeseries from the USGS
dat <- dat[,c(2:4)]
colnames(dat)[3] <- "temperature"
# To view at the time series
ggplot(data = dat, aes(x = Date, y = temperature)) +
geom_point() +
theme_bw() +
facet_wrap(~site_no)
# Adds a new column for year and day of year (doy; Jan 1 = 1, Dec 31 = 365)
dat <- dat %>%
mutate(year = year(Date),
doy = yday(Date))
</code></pre>
<p>I have tried using the <code>dplyr</code> <code>filter()</code> function but have had little success</p>
<pre><code>dat %>%
group_by(site_no,year) %>%
filter(temperature >= 15 & temperature <= 15)
</code></pre>
<p>The ideal output would look something like this:</p>
<pre><code> site_no year doy_firstabove15 doy_sustainedAbove15 doy_firstbelow15 doy_sustainedBelow15
1 01428500 2018 136 144 253 286
2 01428500 2019 140 146 279 289
3 01432805 2018 143 143 272 276
4 01432805 2019 140 140 278 278
</code></pre>
| [
{
"answer_id": 74213412,
"author": "AndS.",
"author_id": 9778513,
"author_profile": "https://Stackoverflow.com/users/9778513",
"pm_score": 0,
"selected": false,
"text": "library(tidyverse)\nlibrary(dataRetrieval)\n\ndat |>\n mutate(month = lubridate::month(Date),\n year = lubrid... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12836787/"
] |
74,212,921 | <p>I am trying to update item, I wrote a function which gets the items from the store and update with new item based on user's selection with <strong>this.name</strong> and <strong>this.price</strong> but the same item.id that is intended for update.</p>
<pre><code> public updateItemData(){
return this.store.select(itemSelector).subscribe(item => {
this.updatedItem = {
id: item.id,
name: this.name,
price: this.price
}
})
}
</code></pre>
<p>This works perfectly without any issue but in a unit test.</p>
<pre><code>it('should create', () => {
expect(component).toBeTruthy();
});
</code></pre>
<p>It marked green but with displayed error.</p>
<pre><code>TypeError: Cannot read properties of undefined (reading 'id')
</code></pre>
<p>When I ran the project, I didn't get any error concerning the "undefined property" or whatever. I started writing the test</p>
<p>Please help to resolve this. I will appreciate.</p>
| [
{
"answer_id": 74213036,
"author": "Sachila Ranawaka",
"author_id": 6428638,
"author_profile": "https://Stackoverflow.com/users/6428638",
"pm_score": 1,
"selected": false,
"text": "spyOn(store, 'select').and.returnValue(YOUR_VALUE);\n"
},
{
"answer_id": 74213207,
"author": "A... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15062485/"
] |
74,212,923 | <p>Goal: I'm trying to get all files that are 1 day old or newer. The remote directory has a lot of directories as well as files on the root directory.</p>
<p>I need to look in each directory, get any files 1 day old, as well as any file on the root directory 1 day old, and transfer all of those to 1 single directory. I'd like to not copy any empty directories, or any directories with files older than 1 day old.</p>
<p>The current code just keeps running and doesn't transfer any files. I'm not sure if I set up the <code>foreach</code> correctly, as well as the <code>GetFiles</code> section.</p>
<p>What does the <code>GetFiles</code> section need to say to meet the file requirements listed above?</p>
<p>Here is an example of what it looks like:</p>
<p><a href="https://i.stack.imgur.com/aVawK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aVawK.png" alt="enter image description here" /></a></p>
<p>Code:</p>
<pre><code># Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::ftp
HostName = "ftp site"
UserName = "UserName"
Password = "Password"
SshHostKeyFingerprint = "stuff"
}
$sessionOptions.AddRawSettings("FSProtocol", "2")
$session = New-Object WinSCP.Session
$session.SessionLogPath = $log
try {
# Connect
$session.Open($sessionOptions)
# Set up transfer options
$transferOptions = New-Object WinSCP.TransferOptions -Property @{
TransferMode = [WinSCP.TransferMode]::Ascii
}
$lcdPath = 'Filepath\'
$time = (Get-Date).AddDays(-1)
$files = @(Get-ChildItem -Path $lcdPath -Attributes !Directory -Recurse | Where-Object { $_.LastWriteTime -gt $time })
# Transfer files
foreach ($file in $files) {
$session.GetFiles($files, "LocalFilePath", $False, $transferOptions).Check()
}
}
finally {
$session.Dispose()
}
exit 0
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
</code></pre>
| [
{
"answer_id": 74214861,
"author": "MisterSmith",
"author_id": 4438168,
"author_profile": "https://Stackoverflow.com/users/4438168",
"pm_score": 0,
"selected": false,
"text": "Filepath\\"
},
{
"answer_id": 74255248,
"author": "Martin Prikryl",
"author_id": 850848,
"au... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3729714/"
] |
74,212,926 | <p>I have a user form to submit blog posts. I want to display errors on the form if users do not enter acceptable data or miss a field. I used event.preventDefault(); to keep the page from reloading when they push submit. Everything works how I want it to, accept I want the page to reload after the form is successfully submitted. as of right now, the data from the form will submit, but it will not reload the page. How can I get it so the page and form reload as soon as the form successfully submits, but not when there are errors?</p>
<p>Here is my jsx</p>
<pre><code>import React from 'react'
import fireIconImage from '../images/fireIcon.png'
import FireIcon from './FireIcon'
export default function BlogPostForm () {
const [formState, setFormState] = React.useState({ flaire: '', title: '', text: '', fireLevel: ''});
const [isHovered, setIsHovered] = React.useState();
const [isLit, setIsLit] = React.useState();
const [formErrors, setFormErrors] = React.useState({});
/*need to start implementing the validation states,
/*will need an errorState object with a specified error for each field*/
/*handleChange for input fields*/
function handleChange(e) {
const { name, value } = e.target;
setFormState({...formState, [name]: value})
}
/*functions for fire icon handling*/
function handleMouseOver(e) {
setIsHovered(e.target.id);
}
function handleMouseLeave(e) {
setIsHovered();
}
function handleFireIconClick(e) {
setIsLit(e.target.id);
setFormState((prevFormState) => ({...prevFormState, fireLevel: e.target.id}))
}
function handleFireIconClass(fireLevel) {
const classNames = ['fireIcon']
classNames.push(`fireIcon${fireLevel}`)
if (isHovered >= fireLevel) {
classNames.push('isHeld')
}
if (isLit >= fireLevel) {
classNames.push('isLit')
}
return classNames.join(' ');
}
/*render 5 fireIcons */
const fireIconsArray = [];
for (let i = 0; i < 5; i++) {
fireIconsArray.push(
<FireIcon
onClick={handleFireIconClick}
onMouseLeave={handleMouseLeave}
onMouseOver={handleMouseOver}
className={handleFireIconClass(i+1)}
src={fireIconImage}
alt="fire icon"
id={i+1}
key={i+1}
/>
)
}
/*submit function*/
function validate(values) {
const errors = {}
if(!values.flaire) {
errors.flaire = "Flaire is required!"
}
if(!values.title) {
errors.title = "Title is required!"
}
if(!values.text) {
errors.text = "Text is required!"
}
if(!values.fireLevel) {
errors.fireLevel = "Select a fire level!"
}
return errors;
}
function submitForm(event) {
event.preventDefault();
const errors = setFormErrors(validate(formState));
if (errors) {
console.log(errors)
return;
}
/*post to database*/
const data = formState;
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}
fetch('http://localhost:8000', options);
}
/*blogPostForm jsx*/
return (
<form className="postForm">
<h1 className="postFormHeader">Create a blog post!</h1>
<select
required
className="flaireSelect"
name="flaire"
value={formState.flaire}
onChange={handleChange}>
<option disabled={true} value="">Choose a flaire</option>
<option value="JavaScript">JavaScript</option>
<option value="CSS">CSS</option>
<option value="HTML">HTML</option>
<option value="REACT">REACT</option>
<option value="BACKEND">BACKEND</option>
</select>
{formErrors.flaire && <p className="inputError inputErrorCenter">{ formErrors.flaire }</p> }
<input
value={formState.title}
onChange={handleChange}
className="titleBox"
placeholder="title"
type="text"
id="title"
name="title"
/>
{formErrors.title && <p className="inputError">{ formErrors.title }</p> }
<textarea
value={formState.text}
onChange={handleChange}
className="textBox"
placeholder="text"
type="text"
id="blogPost"
name="text"
/>
{formErrors.text && <p className="inputError">{ formErrors.text }</p> }
<div className="fireIconContainer">
{fireIconsArray}
</div>
{formErrors.fireLevel && <p className="inputError inputErrorCenter">{ formErrors.fireLevel }</p> }
<div className="blogPostFormButtonContainer">
<button className="blogPostSubmit" type="submit" onClick={submitForm}>SUBMIT</button>
<button className="blogPostCancel" type="submit">CANCEL</button>
</div>
</form>
)
}
</code></pre>
| [
{
"answer_id": 74212993,
"author": "Archigan",
"author_id": 14333778,
"author_profile": "https://Stackoverflow.com/users/14333778",
"pm_score": 1,
"selected": false,
"text": "validate()"
},
{
"answer_id": 74213054,
"author": "Greg",
"author_id": 13628163,
"author_prof... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16635145/"
] |
74,212,928 | <p>I am trying to extract only the zip code values from my imported ACS data file, however, the rows all include "ZCTA" before the 5 digit zip code. Is there a way to remove that so just the 5 digit zip code remains?</p>
<p>Example:</p>
<p><a href="https://i.stack.imgur.com/cpKuy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cpKuy.png" alt="Image of data frame with ZCTA and Zip" /></a></p>
<p>I tried using strtrim on the data but I can't figure out how to target the last 5 digits. I image there is a function or loop that could also do this since the dataset is so large.</p>
| [
{
"answer_id": 74212973,
"author": "KacZdr",
"author_id": 12382064,
"author_profile": "https://Stackoverflow.com/users/12382064",
"pm_score": 2,
"selected": false,
"text": "gsub(\"ZCTA5\", \"\", df$zip) # df - your data.frame name\n"
},
{
"answer_id": 74213053,
"author": "And... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20292981/"
] |
74,212,938 | <p>I'm trying to get a pre-commit check to run a command (in npm) not in the root of the git repository (I have a folder "frontend" that contains the npm installation). This sounds trivial, but so far I have found no pre-commit package that supports this directly. I came up with a workaround, where pre-commit launches a script, then the script makes a change of directory and then it runs the command, but I would like something more direct. Pre-commit packages I have tried:</p>
<ul>
<li>pre-commit (python-based) <a href="https://pre-commit.com/" rel="nofollow noreferrer">https://pre-commit.com/</a></li>
<li>pre-commit (npm-based) <a href="https://github.com/observing/pre-commit" rel="nofollow noreferrer">https://github.com/observing/pre-commit</a></li>
<li>husky (npm based) <a href="https://github.com/typicode/husky" rel="nofollow noreferrer">https://github.com/typicode/husky</a></li>
</ul>
<p>None of these seem to support this directly</p>
<p>Any alternative packages to these would be welcome, or perhaps if I missed a setting in these somewhere.</p>
<p>A similar question was asked here for husky, but the answer again relied on a shell script: <a href="https://stackoverflow.com/questions/73535750/husky-npm-package-pre-commit-hook-not-working-in-sub-directory-repository">Husky npm package Pre-Commit hook not working in sub directory repository</a></p>
<p>UPDATE: Following comments, I will revise the emphasis of this question. I would really like to find out how to do this in one the three options I specified, although other solutions are welcome.</p>
| [
{
"answer_id": 74212973,
"author": "KacZdr",
"author_id": 12382064,
"author_profile": "https://Stackoverflow.com/users/12382064",
"pm_score": 2,
"selected": false,
"text": "gsub(\"ZCTA5\", \"\", df$zip) # df - your data.frame name\n"
},
{
"answer_id": 74213053,
"author": "And... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19024379/"
] |
74,212,962 | <p>I now want to upgrade to Next 13. I have different navbars on my portfolio. How can I use a different navbar for the /about and /skills route than the home page and /contact route?</p>
<p>I thought you could now create different subfolders within the app directory, each with the layout.tsx file, but then corresponding unwanted routes are created.</p>
<p>I tried the following file structure:</p>
<pre><code>/app/LayoutOne/layout.tsx
/app/LayoutOne/page.tsx
/app/LayoutOne/contact/page.tsx
/app/LayoutTwo/layout.tsx
/app/LayoutTwo/about/page.tsx
/app/LayoutTwo/skills/page.tsx
</code></pre>
<p>But then I had the following routes:</p>
<pre><code>../LayoutOne
../LayoutOne/contact
../LayoutTwo/about
../LayoutTwo/skills
</code></pre>
<p>I don't want the layout parts in the URL's</p>
| [
{
"answer_id": 74295776,
"author": "OGreeni",
"author_id": 16492542,
"author_profile": "https://Stackoverflow.com/users/16492542",
"pm_score": 3,
"selected": true,
"text": "/app/(LayoutOne)/layout.tsx\n/app/(LayoutOne)/page.tsx\n/app/(LayoutOne)/contact/page.tsx\n/app/(LayoutTwo)/layout.... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15606459/"
] |
74,212,983 | <p>Assume I have a dataframe: <code>df = pd.DataFrame({"cat":['a', 'a', 'b', 'c'],"A":[5, 6, 1, 4],"B":[7,8, 12, 5]})</code>
which looks like this:</p>
<pre><code> cat A B
0 a 5 7
1 a 6 8
2 b 1 12
3 c 4 5
</code></pre>
<p>Now I want to combine column <em>A</em> and <em>B</em> based on column <em>cat</em>. If <code>row['cat']</code> is the same, then combine <code>row['A']</code> and <code>row['B']</code> to list of tuples. So the above example's desired output is: <code>[[(5, 7), (6, 8)], [(1, 12)], [(4, 5)]]</code></p>
<p>Anyone knows how to do this?</p>
| [
{
"answer_id": 74213144,
"author": "gereleth",
"author_id": 7746385,
"author_profile": "https://Stackoverflow.com/users/7746385",
"pm_score": 3,
"selected": true,
"text": "x = df.groupby('cat').apply(lambda x: list(zip(x['A'], x['B'])))\n"
},
{
"answer_id": 74213307,
"author"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74212983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12787553/"
] |
74,213,034 | <p>Here is my dataframe:</p>
<pre><code>structure(list(Dispensary = c("A", "A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C",
"C", "C", "C", "C", "C", "C", "C"), cohort = c(1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L), t0 = c(100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100), t1 = c(46.1, 41.7,
37.5, 36.2, 35.9, 34.4, 39.8, 38.3, 0, 34.6, 37.4, 31.4, 29.5,
25.5, 33.2, 30.6, 30.8, 0, 28.6, 30.2, 28.1, 28.8, 30.7, 29.2,
33.5, 30.3, 0), t2 = c(41.4, 34.6, 38.6, 27.9, 30, 32.8, 35.2,
0, 0, 35.2, 31.4, 23.9, 24.2, 23.1, 30.1, 24, 0, 0, 26.9, 24.8,
21, 25.3, 25.8, 25.9, 23.3, 0, 0), t3 = c(29.6, 32.3, 31.7, 25.8,
29.5, 23.8, 0, 0, 0, 25.2, 28.9, 23, 23.8, 20.5, 22.6, 0, 0,
0, 20.7, 24, 21.5, 24.9, 23, 23.7, 0, 0, 0), t4 = c(30.9, 28,
30.4, 24.9, 29.5, 0, 0, 0, 0, 23.1, 23.1, 20.7, 21.8, 19.2, 0,
0, 0, 0, 21, 20.8, 21.3, 23.7, 20.5, 0, 0, 0, 0), t5 = c(30.3,
25.6, 23.5, 24.9, 0, 0, 0, 0, 0, 19.4, 22.1, 20, 19.5, 0, 0,
0, 0, 0, 17.2, 18.5, 20.4, 14.7, 0, 0, 0, 0, 0), t6 = c(30.9,
24, 23.2, 0, 0, 0, 0, 0, 0, 19.6, 20.3, 17.2, 0, 0, 0, 0, 0,
0, 20.3, 17.7, 18.2, 0, 0, 0, 0, 0, 0), t7 = c(27.6, 18.5, 0,
0, 0, 0, 0, 0, 0, 18, 16.1, 0, 0, 0, 0, 0, 0, 0, 14.2, 14.8,
0, 0, 0, 0, 0, 0, 0), t8 = c(17.8, 0, 0, 0, 0, 0, 0, 0, 0, 17.2,
0, 0, 0, 0, 0, 0, 0, 0, 11.4, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA,
-27L), class = c("tbl_df", "tbl", "data.frame"))
</code></pre>
<p>I'm trying to insert a blank row after every 9th row, in between where <code>cohort == 9</code> and <code>cohort == 1</code></p>
<p>The dataframe is long and I'm hoping to not have to do it one a time</p>
<p><a href="https://stackoverflow.com/questions/38279533/insert-2-blank-rows-after-every-currentregion">Here is a link</a> to a similar question, but I'm looking for an R method, not a VBA method</p>
| [
{
"answer_id": 74213144,
"author": "gereleth",
"author_id": 7746385,
"author_profile": "https://Stackoverflow.com/users/7746385",
"pm_score": 3,
"selected": true,
"text": "x = df.groupby('cat').apply(lambda x: list(zip(x['A'], x['B'])))\n"
},
{
"answer_id": 74213307,
"author"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7147717/"
] |
74,213,040 | <p>I have a list of tuples</p>
<pre><code>a = [('name', 'color'),('fruit', 'color'),('thing', 'type'),('sport', 'type')]
</code></pre>
<p>I want to join first elements grouped by second element. The output should look like.</p>
<pre><code>a = [('name fruit', 'color'),('thing sport', 'type')]
</code></pre>
| [
{
"answer_id": 74213079,
"author": "I'mahdi",
"author_id": 1740577,
"author_profile": "https://Stackoverflow.com/users/1740577",
"pm_score": 3,
"selected": true,
"text": "dict"
},
{
"answer_id": 74213165,
"author": "JustLearning",
"author_id": 19962393,
"author_profil... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17442474/"
] |
74,213,048 | <p>I have employee table. I have below fields. Few employees multiple mobile and home numbers. I want data in JSON format sending empid in where condition.</p>
<p>Select empid, empname, address, homenumber from dbo.emp</p>
<p>Values in these fields are</p>
<pre><code>homenumber = 1^2^3^4
address = Home1^Home2^Office1^Office2
</code></pre>
<p>I want above data in below JSON format for all these fields - empid, empname, address, homenumber</p>
<p>I tried below query but getting wrong output</p>
<pre><code> select empid, r.value , r1.value from dbo.emp
cross apply string_split (Homenumber,'^') r
cross apply string_split (address ,'^') r1 where empid=1
</code></pre>
<p>I'm supposed to get data in below format</p>
<pre><code> "Address": [{"Homenumber": 1, "address ":"Home1"},{"Homenumber":
2, "address ":"Home2"},{"Homenumber": 3, "address ":"Home3"},
{"Homenumber": 4, "address ":"Home4"}]
</code></pre>
<p>but since I have done cross join, it is getting more records. I would be great if someone can help me.</p>
| [
{
"answer_id": 74213166,
"author": "jhackso",
"author_id": 11452907,
"author_profile": "https://Stackoverflow.com/users/11452907",
"pm_score": -1,
"selected": false,
"text": "select [data] from [table] for **JSON Auto**\n"
},
{
"answer_id": 74215841,
"author": "Charlieface",
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1543122/"
] |
74,213,059 | <p>I am making a flask app where I have 2 tables in a data base.</p>
<ol>
<li>User</li>
<li>File</li>
</ol>
<p>A file has a column called fileOwnerId but I want to add another called allowed viewers.
How would I implement such a situation.</p>
<p>I've had 2 ideas:</p>
<ol>
<li>Is to make a column called validViewers that would store an array of valid viewer but I don't think you can store an array in a db.</li>
<li>Is to make a foreign key in User that would connect to only certain File rows. The problem is I don't think you can choose which files would apply to which user.</li>
</ol>
<p>If theres any other ideas you guys have I'm all ears. Ty in advance</p>
<pre><code>from flask_login import UserMixin
from . import db
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key = True)
userUuid = db.Column(db.String(1000), unique = True)
email = db.Column(db.String(1000), unique = True)
name = db.Column(db.String(1000))
password = db.Column(db.String(1000))
isAdmin = db.Column(db.Boolean(), default = False)
files = db.relationship("File")
class File(db.Model):
id = db.Column(db.Integer, primary_key = True)
fileUuid = db.Column(db.String(1000), unique = True)
filePath = db.Column(db.String(1000), unique = True)
fileName = db.Column(db.String(1000))
fileOwnerId = db.Column(db.Integer, db.ForeignKey("user.id"))
</code></pre>
| [
{
"answer_id": 74213166,
"author": "jhackso",
"author_id": 11452907,
"author_profile": "https://Stackoverflow.com/users/11452907",
"pm_score": -1,
"selected": false,
"text": "select [data] from [table] for **JSON Auto**\n"
},
{
"answer_id": 74215841,
"author": "Charlieface",
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20250792/"
] |
74,213,076 | <p>I have a user control which has one Button which should enable/disable if i change the state value from other user control.</p>
<p>Can someone help me know how i can achieve this? How to capture the bool for the changes on the enable/disable button?</p>
<p>Usercontrol1 UTILS</p>
<pre><code> public Utilitaires()
{
InitializeComponent();
PanelSlider_Utils.Controls.Add(new TCP());
}
//My button btnUndo created from the Visual interface
public void btnUndo_Click(object sender, EventArgs e)
{
my code...
}
</code></pre>
<p>Usercontrol2 TCP</p>
<pre><code> //My method which should by the bool canredo change the enabled state of my button btnredo Usercontrol1
public void Redo_CanRedoChanged(object Sender, bool CanRedo)
{
UTILS foo = new UTILS();
foo.btnRedo.Enabled = CanRedo;// This is my problem to reach the button btnRedo UserControl 1
}
</code></pre>
<p>Sorry for my English...! Thanks</p>
| [
{
"answer_id": 74230654,
"author": "Ken",
"author_id": 9336054,
"author_profile": "https://Stackoverflow.com/users/9336054",
"pm_score": 1,
"selected": false,
"text": "// this is usually done by creating a control in\n// the Winforms designer, not in directly in your code:\nUsercontrol1 ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5831682/"
] |
74,213,106 | <p>In the <a href="https://nextjs.org/docs/api-reference/next/image" rel="nofollow noreferrer">next/image docs</a> under version history, it states the following for v13.0.0:</p>
<blockquote>
<p>layout, objectFit, objectPosition, lazyBoundary, lazyRoot props removed.</p>
</blockquote>
<p>Under next/image docs for <a href="https://nextjs.org/docs/api-reference/next/image#fill" rel="nofollow noreferrer">fill</a> the documentation states we can set the object fit with <code>object-fit: "contain"</code> or alternatively to <code>object-fit: "cover"</code>. I am unable to set the object fit to cover with the following code:</p>
<pre><code><div className="relative">
<Image
src=""
alt=""
fill={true}
layout="fill"
object-fit="cover"
/>
</div>
</code></pre>
<p>How does one implement <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit" rel="nofollow noreferrer">object-fit</a> with Next.js 13?</p>
| [
{
"answer_id": 74354597,
"author": "TimTh",
"author_id": 20372875,
"author_profile": "https://Stackoverflow.com/users/20372875",
"pm_score": 1,
"selected": false,
"text": "<div className=\"relative\">\n <Image\n src=\"\"\n alt=\"\"\n fill\n objectFit=\"contain\"\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12718916/"
] |
74,213,120 | <p>I tried all the recommended steps and potential solutions suggested over the forums. However, this problem still persists. Its been 5 days and I am still trying to find why it happens only in build export and not in unity editor.</p>
<p>[Edit (1st Dec 2022): Recently I found that this issue doesn't happen when I "Build and Run" the project the first time. However, If I close and launch the game again using .exe file, the issue is still coming up. I don't know how it runs as expected only the first time when I do "Build and Run" instead of just "Build" or "Clean Build".]</p>
<p>Issue Details:</p>
<p><a href="https://i.stack.imgur.com/sdsJm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sdsJm.png" alt="Hierarchy Panel" /></a></p>
<p>'IntroductionHUD' (Canvas) is the canvas of this scene.
'TestText' (TextMeshPro) is used to test if the 'IntroModalScreenPanel' (Image) is active or not.
'IntroModalScreenManager' (Empty Object) has the script to handle activation and deactivation of IntroModalScreenPanel (Image) and its children.</p>
<p>There is an awake method in the 'IntroModalScreenManager' script which sets the 'IntroModalScreenPanel' and its children to inactive.</p>
<p>And there are other methods in the script which activates and deactivates the 'IntroModalScreenPanel' and its children accordingly. The objects are activated and deactivated using SetActive(bool) in the script. The objects are assigned through the inspector.</p>
<p><a href="https://i.stack.imgur.com/JsszB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JsszB.png" alt="IntroModalScreenManager" /></a></p>
<p>For some reason, which I have no idea of, the 'IntroModalScreenPanel' doesn't get activated after it deactivates in the awake method. Additionally, this weird problem only exists when I do a build export. Whereas, it works perfectly fine and as expected in Unity Editor.</p>
<p>The 'TestText' is used to test if the 'IntroModalScreenPanel' is active or not and every time it turns to be not active in the build export.</p>
<p>Another weird part is (if you see the hierarchy snapshot) the 'Background' and 'TestText' works fine being the children of the same canvas object (IntroductionHUD) as of 'IntroModalScreenManager'. As per my understanding the problem is only with the 'IntroModalScreenPanel' and its children.</p>
<p>I would really appreciate if anyone could advise on this. Any suggestions will do.</p>
<p>Script:</p>
<pre><code>using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class IntroModalScreenManager : MonoBehaviour
{
public bool IsIntroModalScreenActive() { return _isIntroModalScreenActive; }
//Bool variables...
[SerializeField] private bool _isIntroModalScreenActive;
//INTRO MODAL SCREEN MANAGER
[Header("INTRO MODAL SCREEN MANAGER")]
[SerializeField] private GameObject _introModalScreenPanel;
[SerializeField] private GameObject _introModalScreenHeader;
[SerializeField] private GameObject _introModalScreenBody;
[SerializeField] private GameObject _introModalScreenFooter;
//INTRO MODAL SCREEN PANEL
[Header("INTRO MODAL SCREEN PANEL")]
[SerializeField] private Image _introModalScreenPanelImage;
//HEADER
[Header("HEADER")]
[SerializeField] private Image _introModalScreenPanelImageHeaderImage;
[SerializeField] private TextMeshProUGUI _introModalScreenPanelImageHeaderImageHeaderText;
//BODY
[Header("BODY")]
[SerializeField] private Image _introModalScreenPanelImageBodyImage;
[SerializeField] private Image _introModalScreenPanelImageBodyImageBodyImage;
[SerializeField] private TextMeshProUGUI _introModalScreenPanelImageBodyImageBodyText;
//FOOTER
[Header("FOOTER")]
[SerializeField] private Image _introModalScreenPanelImageFooterImage;
[SerializeField] private Button _introModalScreenPanelImageFooterImageFooterNegativeButton;
[SerializeField] private TextMeshProUGUI _introModalScreenPanelImageFooterImageFooterNegativeButtonText;
[SerializeField] private Button _introModalScreenPanelImageFooterImageFooterAlternateButton;
[SerializeField] private TextMeshProUGUI _introModalScreenPanelImageFooterImageFooterAlternateButtonText;
[SerializeField] private Button _introModalScreenPanelImageFooterImageFooterPositiveButton;
[SerializeField] private TextMeshProUGUI _introModalScreenPanelImageFooterImageFooterPositiveButtonText;
public static IntroModalScreenManager Instance { get; private set; }
private void Awake()
{
if(Instance != null && Instance != this)
{
Destroy(this);
}
else
{
Instance = this;
}
DeactivateModalScreenDisplay();
//DontDestroyOnLoad(this.gameObject);
}
//Called by Awake() in the begining and by other script to deactivate modal screen when needed
public void DeactivateModalScreenDisplay()
{
DeactivateAndClearAll();
_introModalScreenPanel.SetActive(false);
_isIntroModalScreenActive = false;
}
void DeactivateAndClearAll()
{
DeactivateHeader();
DeactivateBody();
DeactivateFooter();
}
//Called by another script to activate modal screen when needed
public void ActivateModalScreenDisplay(bool isBook, bool isBookWithAlternateOption,
bool isSinglePage, bool isSinglePageWithNegativeOption, bool isSinglePageWithNegativeAndAlternateOption,
bool needBodyImage,
string headerText = "",
Sprite bodyImageSprite = null, string bodyText = "",
string footerNegativeButtonText = "", string footerAlternateButtonText = "", string footerPositiveButtonText = "",
Action negativeActionOption = null, Action alternateActionOption = null, Action positiveActionOption = null)
{
_introModalScreenPanel.SetActive(true);
//Book - has front and back navigation options
if (isBook)
{
ActivateHeader(headerText);
ActivateBody(needBodyImage, true, bodyImageSprite, bodyText);
ActivateFooter(true, false, true, footerNegativeButtonText, footerAlternateButtonText, footerPositiveButtonText,
negativeActionOption, alternateActionOption, positiveActionOption);
}
//BookWithAlternateOption - Book with an addition of alternate option. (Eg: Skip button)
else if (isBookWithAlternateOption)
{
ActivateHeader(headerText);
ActivateBody(needBodyImage, true, bodyImageSprite, bodyText);
ActivateFooter(true, true, true, footerNegativeButtonText, footerAlternateButtonText, footerPositiveButtonText,
negativeActionOption, alternateActionOption, positiveActionOption);
}
//SinglePage - has one button (positive option - Eg: Continue, start, etc. buttons)
else if (isSinglePage)
{
ActivateHeader(headerText);
ActivateBody(needBodyImage, true, bodyImageSprite, bodyText);
ActivateFooter(false, false, true, footerNegativeButtonText, footerAlternateButtonText, footerPositiveButtonText,
negativeActionOption, alternateActionOption, positiveActionOption);
}
//SinglePageWithNegativeOption - Single page with an addition of negative option (Eg: Confirmations)
else if (isSinglePageWithNegativeOption)
{
ActivateHeader(headerText);
ActivateBody(needBodyImage, true, bodyImageSprite, bodyText);
ActivateFooter(true, false, true, footerNegativeButtonText, footerAlternateButtonText, footerPositiveButtonText,
negativeActionOption, alternateActionOption, positiveActionOption);
}
//SinglePageWithNegativeAndAlternateOption - Single page with negative option and an aditional alternate button (Eg: 3rd option in any choice making scenes)
else if (isSinglePageWithNegativeAndAlternateOption)
{
ActivateHeader(headerText);
ActivateBody(needBodyImage, true, bodyImageSprite, bodyText);
ActivateFooter(true, true, true, footerNegativeButtonText, footerAlternateButtonText, footerPositiveButtonText,
negativeActionOption, alternateActionOption, positiveActionOption);
}
_isIntroModalScreenActive = true;
}
void ActivateHeader(string headerText)
{
//Only if the header text has some value, this component will be active... Implemented this only for header & footer, as header & footer is used for all types of modal screen layouts.
if(headerText != "" && headerText != null)
{
//HEADER
_introModalScreenHeader.SetActive(true);//Header Object
_introModalScreenPanelImageHeaderImageHeaderText.gameObject.SetActive(true);//Header Text Object
_introModalScreenPanelImageHeaderImageHeaderText.text = headerText;//Header Text
}
}
void DeactivateHeader()
{
_introModalScreenPanelImageHeaderImageHeaderText.text = "";//Header Text
if (_introModalScreenPanelImageHeaderImageHeaderText.gameObject.activeSelf)
{
_introModalScreenPanelImageHeaderImageHeaderText.gameObject.SetActive(false);//Header Text Object
}
if (_introModalScreenHeader.activeSelf)
{
_introModalScreenHeader.SetActive(false);//Header Object
}
}
void ActivateBody(bool needBodyImage, bool needBodyText, Sprite bodyImageSprite, string bodyText)
{
//BODY
_introModalScreenBody.SetActive(true);//Body Object
_introModalScreenPanelImageBodyImageBodyImage.gameObject.SetActive(needBodyImage);//Body Image Object
if (_introModalScreenPanelImageBodyImageBodyImage.gameObject.activeSelf)//Body Image Object Image Sprite
{ _introModalScreenPanelImageBodyImageBodyImage.sprite = bodyImageSprite; }
_introModalScreenPanelImageBodyImageBodyText.gameObject.SetActive(needBodyText);//Body Text Object
if (_introModalScreenPanelImageBodyImageBodyText.gameObject.activeSelf)//Body Text Object Text
{ _introModalScreenPanelImageBodyImageBodyText.text = bodyText; }
}
void DeactivateBody()
{
_introModalScreenPanelImageBodyImageBodyText.text = "";
if (_introModalScreenPanelImageBodyImageBodyText.gameObject.activeSelf)
{
_introModalScreenPanelImageBodyImageBodyText.gameObject.SetActive(false);//Body Text Object
}
_introModalScreenPanelImageBodyImageBodyImage.sprite = null;
if (_introModalScreenPanelImageBodyImageBodyImage.gameObject.activeSelf)
{
_introModalScreenPanelImageBodyImageBodyImage.gameObject.SetActive(false);//Body Image Object
}
if (_introModalScreenBody.activeSelf)
{
_introModalScreenBody.SetActive(false);//Body Object
}
}
void ActivateFooter(bool needFooterNegativeButton, bool needFooterAlternateButton, bool needFooterPositiveButton,
string footerNegativeButtonText, string footerAlternateButtonText, string footerPositiveButtonText,
Action negativeActionOption, Action alternateActionOption, Action positiveActionOption)
{
//FOOTER
_introModalScreenFooter.SetActive(true);//Footer Object
//When this footer button is needed, only if the footer text and action has some value, this component will be active... Implemented this only for header & footer, as header & footer is used for all types of modal screen layouts.
if (needFooterNegativeButton && footerNegativeButtonText != null && footerNegativeButtonText != "" && negativeActionOption != null)
{
_introModalScreenPanelImageFooterImageFooterNegativeButton.gameObject.SetActive(needFooterNegativeButton);//Footer Negative Button
if (_introModalScreenPanelImageFooterImageFooterNegativeButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterNegativeButtonText.text = footerNegativeButtonText;//Footer Negative Button Text
_introModalScreenPanelImageFooterImageFooterNegativeButton.onClick.AddListener(new UnityEngine.Events.UnityAction(negativeActionOption));//Add listener to the button's OnClick
}
}
else
{
_introModalScreenPanelImageFooterImageFooterNegativeButton.gameObject.SetActive(needFooterNegativeButton);//Footer Negative Button
}
//When this footer button is needed, only if the footer text and action has some value, this component will be active... Implemented this only for header & footer, as header & footer is used for all types of modal screen layouts.
if (needFooterAlternateButton && footerAlternateButtonText != null && footerAlternateButtonText != "" && alternateActionOption != null)
{
_introModalScreenPanelImageFooterImageFooterAlternateButton.gameObject.SetActive(needFooterAlternateButton);//Footer Alternate Button
if (_introModalScreenPanelImageFooterImageFooterAlternateButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterAlternateButtonText.text = footerAlternateButtonText;//Footer Alternate Button Text
_introModalScreenPanelImageFooterImageFooterAlternateButton.onClick.AddListener(new UnityEngine.Events.UnityAction(alternateActionOption));//Add listener to the button's OnClick
}
}
else
{
_introModalScreenPanelImageFooterImageFooterAlternateButton.gameObject.SetActive(needFooterAlternateButton);//Footer Alternate Button
}
//When this footer button is needed, only if the footer text and action has some value, this component will be active... Implemented this only for header & footer, as header & footer is used for all types of modal screen layouts.
if (needFooterPositiveButton && footerPositiveButtonText != null && footerPositiveButtonText != "" && positiveActionOption != null)
{
_introModalScreenPanelImageFooterImageFooterPositiveButton.gameObject.SetActive(needFooterPositiveButton);//Footer Positive Button
if (_introModalScreenPanelImageFooterImageFooterPositiveButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterPositiveButtonText.text = footerPositiveButtonText;//Footer Positive Button Text
_introModalScreenPanelImageFooterImageFooterPositiveButton.onClick.AddListener(new UnityEngine.Events.UnityAction(positiveActionOption));//Add listener to the button's OnClick
}
}
else
{
_introModalScreenPanelImageFooterImageFooterPositiveButton.gameObject.SetActive(needFooterPositiveButton);//Footer Positive Button
}
}
void DeactivateFooter()
{
#region COMMENTED PART - NEDD TO RESOLVE LATER - KEPT FOR FUTURE UPGRADE...
//To make the button not be in selected state after clicking once: is to set it's Navigation drop down option from inspector to none.
//Or can do it by code as done for each button below.
//Unfortunately, I tried, but it doesn't work that way. Maybe I did it wrong. For now lets do the inspector method.
//https://forum.unity.com/threads/clicking-a-button-leaves-it-in-mouseover-state.285167/
#endregion
_introModalScreenPanelImageFooterImageFooterNegativeButton.onClick.RemoveAllListeners();//Remove all listeners to the button's OnClick
//var nav = _introModalScreenPanelImageFooterImageFooterNegativeButton.navigation;
//nav.mode = Navigation.Mode.None;
if (_introModalScreenPanelImageFooterImageFooterNegativeButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterNegativeButton.gameObject.SetActive(false);//Footer Negative Button
}
_introModalScreenPanelImageFooterImageFooterAlternateButton.onClick.RemoveAllListeners();//Remove all listeners to the button's OnClick
//nav = _introModalScreenPanelImageFooterImageFooterAlternateButton.navigation;
//nav.mode = Navigation.Mode.None;
if (_introModalScreenPanelImageFooterImageFooterAlternateButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterAlternateButton.gameObject.SetActive(false);//Footer Alternate Button
}
_introModalScreenPanelImageFooterImageFooterPositiveButton.onClick.RemoveAllListeners();//Remove all listeners to the button's OnClick
//nav = _introModalScreenPanelImageFooterImageFooterPositiveButton.navigation;
//nav.mode = Navigation.Mode.None;
if (_introModalScreenPanelImageFooterImageFooterPositiveButton.gameObject.activeSelf)
{
_introModalScreenPanelImageFooterImageFooterPositiveButton.gameObject.SetActive(false);//Footer Positive Button
}
if (_introModalScreenFooter.activeSelf)
{
_introModalScreenFooter.SetActive(false);//Footer Object
}
}
}
</code></pre>
| [
{
"answer_id": 74354597,
"author": "TimTh",
"author_id": 20372875,
"author_profile": "https://Stackoverflow.com/users/20372875",
"pm_score": 1,
"selected": false,
"text": "<div className=\"relative\">\n <Image\n src=\"\"\n alt=\"\"\n fill\n objectFit=\"contain\"\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18762063/"
] |
74,213,169 | <p>I'm have some groups on azure, which I'm retriving with Get-AzADGroup like so:</p>
<p><strong>Get-AzADGroup -Filter "startsWith(DisplayName, 'groupname')"</strong></p>
<p>which yields the displayname, the id, the mailnickname and the discription..</p>
<p>What I want to do is to get the ID only and put it into a variable. How do I do this?</p>
| [
{
"answer_id": 74213359,
"author": "scottwtang",
"author_id": 18748575,
"author_profile": "https://Stackoverflow.com/users/18748575",
"pm_score": 2,
"selected": true,
"text": "Select-Object"
},
{
"answer_id": 74214724,
"author": "TeamEVQ",
"author_id": 18312998,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20276285/"
] |
74,213,200 | <p>I have a result set like this:</p>
<pre><code>UserName Action
-------------------
Joe Add
Joe Remove
Fred Add
Sam Add
Carl Remove
</code></pre>
<p>I only want to return the <code>Add</code> for <code>Joe</code> in this case. <code>Add</code> takes precedence. So if the user has an add record we only return that like.</p>
<pre><code>Joe Add
Fred Add
Sam Add
Carl Remove
</code></pre>
<p>Not sure the best way to accomplish this.</p>
| [
{
"answer_id": 74213359,
"author": "scottwtang",
"author_id": 18748575,
"author_profile": "https://Stackoverflow.com/users/18748575",
"pm_score": 2,
"selected": true,
"text": "Select-Object"
},
{
"answer_id": 74214724,
"author": "TeamEVQ",
"author_id": 18312998,
"auth... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13520940/"
] |
74,213,208 | <p>I'm working on updating our PowerShell scripts to use more secure connection methods. When I try, I get an error that says "UnAuthorized"</p>
<blockquote>
<p>PS X:> Connect-ExchangeOnline -AppId $clientId -CertificateThumbprint $thumbPrint -Organization $organization UnAuthorized
At C:\Program
Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.0.0\netFramework\ExchangeOnlineManagement.psm1:730 char:21</p>
<ul>
<li>throw $_.Exception;</li>
<li>
<pre><code></code></pre>
</li>
<li>CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException
<ul>
<li>FullyQualifiedErrorId : UnAuthorized</li>
</ul>
</li>
</ul>
</blockquote>
<p>Is what I highlighted in the following screenshot what I'm supposed to use for the organization parameter?
[snip]</p>
<p>How do I fix the UnAuthorized error?</p>
<p>Thanks</p>
| [
{
"answer_id": 74218750,
"author": "Sridevi",
"author_id": 18043665,
"author_profile": "https://Stackoverflow.com/users/18043665",
"pm_score": 2,
"selected": true,
"text": "$CN = \"GraphApp\" \n$cert=New-SelfSignedCertificate -Subject \"CN=$CN\" -CertStoreLocation \"Cert:\\CurrentUser\\M... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2258605/"
] |
74,213,242 | <p>If I create and array without initialization the program uses only a few MB of memory to save the reference. For example like this:</p>
<pre><code>int[] arr = new int[1000000000];
</code></pre>
<p>Later if I initialize the elements of array the memory usage goes up by the full array amount.</p>
<p>The memory usage is lower if I initialize only a part of array.</p>
<pre><code>for (int i = 0; i < arr.Length; i++) // Full memory usage, length * sizeof(int)
{
arr[i] = i;
}
----------------------------------------------------------
for (int i = 0; i < arr.Length/2; i++) // Only ~half memory usage, (length / 2) * sizeof(int)
{
arr[i] = i;
}
</code></pre>
<p>Now I need to use my full initialized array to create an data structure and then reduce its size by keeping every N element. Because the array is very big reducing its size can save several GB. The missing elements can be calculated from the remaining ones and created data structure. Its a trading calculation time for memory usage.</p>
<p>Now to the question:
<strong>Is it possible in C# to release some memory from array after the array is fully initialized?</strong></p>
<p>I have tried to set every Nth element to zero but the memory usage is still the same.</p>
| [
{
"answer_id": 74213386,
"author": "José Ramírez",
"author_id": 13886104,
"author_profile": "https://Stackoverflow.com/users/13886104",
"pm_score": 2,
"selected": true,
"text": "Array.Resize()"
},
{
"answer_id": 74213456,
"author": "mmartinez04",
"author_id": 20131874,
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12460488/"
] |
74,213,299 | <p>I have a string like this, with several tabs in it. I need to replace a single digit, it will always be the digit after the 2nd tab. The numbers before that could be different lengths, so I can't simply replace after 10 digits or something like that. It has to be after the 2nd tab. the new string will be exactly the same except for that one digit. example...</p>
<p><code>222[TAB]55555[TAB]9[TAB]hello[TAB]byebye[TAB]444</code></p>
<p>change to</p>
<p><code>222[TAB]55555[TAB]2[TAB]hello[TAB]byebye[TAB]444</code></p>
| [
{
"answer_id": 74214250,
"author": "Sammitch",
"author_id": 1064767,
"author_profile": "https://Stackoverflow.com/users/1064767",
"pm_score": 2,
"selected": true,
"text": "$input = \"222\\t55555\\t9\\thello\\tbyebye\\t444\";\n\n$parts = explode(\"\\t\", $input);\n$parts[2] = 2;\n$output ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3067447/"
] |
74,213,317 | <p>I'm using raw SQL and trying to do an update <em>and then</em> an insert on the same table, do you think I need some type of transaction or something?</p>
<p>If I add an <code>INSERT</code> and then an <code>UPDATE</code> in the same script file, will the order of the execution be respected by SQL?</p>
<p>Ended up with this so far:</p>
<pre class="lang-sql prettyprint-override"><code>IF NOT EXISTS (SELECT TOP 1 * FROM dbo.Settings
WHERE Descr = 'GL for Credit Memos')
BEGIN
SET IDENTITY_INSERT dbo.Settings ON
DECLARE @newOrderNo INT;
SET @newOrderNo = 7 -- OrderNo for credit memo to display below 'GL for A/P'
-- Update order no. for settings below 'GL for Credit Memo'
UPDATE dbo.Settings
SET [OrderNo] = [OrderNo] + 1
WHERE [OrderNo] >= @newOrderNo
INSERT INTO [dbo].[Settings]
([SettingID],
[Created],
[Descr],
[Category],
[OrderNo],
[DataType],
[InActive],
[IsRequired])
VALUES
(198, -- New Enum value for setting ID for 'Gl for Credit Memo'
DEFAULT,
'GL for Credit Memo',
'Accounting',
@newOrderNo,
4,
NULL,
1)
SET IDENTITY_INSERT dbo.Settings OFF
END
</code></pre>
| [
{
"answer_id": 74213700,
"author": "Eric Brandt",
"author_id": 5790584,
"author_profile": "https://Stackoverflow.com/users/5790584",
"pm_score": 0,
"selected": false,
"text": "BEGIN TRANSACTION"
},
{
"answer_id": 74215805,
"author": "Charlieface",
"author_id": 14868997,
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10122964/"
] |
74,213,320 | <p>I'm trying to create a Cobra command that uses a flag to inform the action of the command, specifically a configuration command that can either add or remove a configured setting. For example</p>
<pre><code>cli> prog_name config --set config_var var_vlue
cli> prog_name config --unset config_var var_value
</code></pre>
<p>Is there a way to do this in Cobra? I have been reading through the documentation and haven't found any way to validate that a flag is the first value in the command. I've seen information about positional arguments, but from what I've read it sounds like flags aren't considered arguments, so they wouldn't be covered by positional arguments.</p>
<p>I'd imagine I can do this in my PreRunE function and do the validation manually, but if there's a way to set this in Cobra I think that'd most likely be better, since I'd prefer Cobra to be doing that parsing and matching rather than me have to be comparing specific values in os.Args to "--set" and "--unset" or something similar.</p>
| [
{
"answer_id": 74214081,
"author": "Fulvio",
"author_id": 10519368,
"author_profile": "https://Stackoverflow.com/users/10519368",
"pm_score": -1,
"selected": false,
"text": "Flags()"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1493950/"
] |
74,213,408 | <p>I wrote this piece of code, in which I ask the user to input numbers twice, and then it joins them together in a list, inside a list. It works...buts it's in the wrong format.</p>
<p><strong>Here's what I did</strong></p>
<pre><code>list=[]
for i in range(2):
userinput = input("Enter some numbers: ")
x = userinput.split()
list.append(x)
print(list)
</code></pre>
<p><strong>The output is this</strong></p>
<pre><code>Enter some numbers: 1 2
Enter some numbers: 3 4
[['1', '2'], ['3', '4']]
</code></pre>
<p>...but I need it to be formatted <strong>[[1, 2], [3, 4]]</strong>
I'm very new python, and I feel like Ive exhausted all my options, I couldnt find anything online that works (tried the join, replace etc.) , unless its impossible with my code, please help</p>
<pre><code></code></pre>
| [
{
"answer_id": 74213424,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "x = [int(i) for i in userinput.split()]"
},
{
"answer_id": 74213594,
"author": "Mark",
"autho... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20341951/"
] |
74,213,409 | <p>I have a list of dates and want to create a column in an existing data frame for every element of the list and in that column, I want a 1 if the date is between the start and end date.</p>
<pre><code>#input:
my_date = as.Date(c("2022-10-02","2022-10-31","2022-10-05"))
df1 <- data.frame(ID = c(1, 2, 3),
start_date = as.Date(c("2022-10-01","2022-10-08","2022-10-01")),
end_date = as.Date(c("2022-10-22","2022-10-22","2022-10-08")))
#output:
df1 <- data.frame(ID = c(1, 2, 3),
start_date = as.Date(c("2022-10-01","2022-10-08","2022-10-01")),
end_date = as.Date(c("2022-10-22","2022-10-22","2022-10-08")),
flag_1= c(1,0,1), flag_2=c(0,0,0), flag_3= c(1,0,1))
</code></pre>
<p>I could do it manually, but I have to many rows. I was looking into a solution with mutate but not sure how to implement.</p>
| [
{
"answer_id": 74213424,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "x = [int(i) for i in userinput.split()]"
},
{
"answer_id": 74213594,
"author": "Mark",
"autho... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3284297/"
] |
74,213,416 | <p>How to create a class that can call multiple functions?</p>
<p><em>example:</em></p>
<pre><code>class ClassName
{
public static function func1()
{
}
public static function func2()
{
}
public static function func3()
{
}
}
ClassName::func1()->func2()->func3();
</code></pre>
<p><em>result</em>
Uncaught Error: Call to a member function funcX() on null</p>
| [
{
"answer_id": 74213424,
"author": "RJ Adriaansen",
"author_id": 11380795,
"author_profile": "https://Stackoverflow.com/users/11380795",
"pm_score": 2,
"selected": true,
"text": "x = [int(i) for i in userinput.split()]"
},
{
"answer_id": 74213594,
"author": "Mark",
"autho... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342737/"
] |
74,213,433 | <p>I've been banging my head against a brick wall on this.</p>
<p>I'm trying to deploy via Azure DevOps pipeline, a bicep/ARM Template an API Connection that uses a Custom Connector that is linked to an On-prem API via a Data Gateway.</p>
<p>Here is my bicep file...</p>
<pre><code>param connectionName string
param displayName string
param gatewayResourceGroup string
param gatewayName string
param connectorName string
param location string = resourceGroup().location
resource connector 'Microsoft.Web/customApis@2016-06-01' existing = {
name: connectorName
}
resource gatewayApi 'Microsoft.Web/connectionGateways@2016-06-01' existing = {
name: gatewayName
scope: resourceGroup(gatewayResourceGroup)
}
resource apiConnection 'Microsoft.Web/connections@2016-06-01' = {
name: connectionName
location: location
properties: {
displayName: displayName
nonSecretParameterValues: {
authType: 'anonymous'
#disable-next-line BCP036
gateway: {
name: gatewayName
id: gatewayApi.id
type: 'Microsoft.Web/connectionGateways'
}
}
api: {
name: connector.name
displayName: 'CONNECTOR ${connectorName}'
id: connector.id
type: 'Microsoft.Web/customApis'
}
}
}
</code></pre>
<p>I issue is the nonSecretParameterValues.</p>
<p>They don't go anywhere.</p>
<p>The API Connection is deployed like...
<a href="https://i.stack.imgur.com/jTM4j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jTM4j.png" alt="authType and gateway values are missing" /></a></p>
<p>What makes this a little worse is the deployment is successful...
<a href="https://i.stack.imgur.com/lRsC4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lRsC4.png" alt="Deployment status" /></a></p>
<p>But if I drill into the Operation details I can see there were two issues...
<a href="https://i.stack.imgur.com/kdSGB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kdSGB.png" alt="Request and Response" /></a></p>
<pre class="lang-json prettyprint-override"><code> "overallStatus": "Error",
"statuses": [
{
"status": "Error",
"target": "authType",
"error": {
"code": "ConfigurationNeeded",
"message": "Parameter value missing."
}
},
{
"status": "Error",
"target": "gateway",
"error": {
"code": "ConfigurationNeeded",
"message": "Parameter value missing."
}
}
],
</code></pre>
<p>Very frustrating.</p>
<p>Now I can manually add the values I intended to be there for the authType and gateway parameters after the deployment is "successful". Then my logic app that uses this API Connection and Custom Connector to Onprem Gateway works as expected.</p>
<p>But the exported template for the API Connection does not change between the connection having missing parameters (in the UI) or after I manually enter the values.</p>
<p>I have also tried added some Powershell after the deployment to pick up the connection and to try settings the "missing" values and updating the resource from there.</p>
<p>I can see another API Connection via Powershell which is correctly set with the authType and gateway parameters.</p>
<p>But when I try, to set these on the resource I need to "fix" it also complains...
<a href="https://i.stack.imgur.com/9JpYp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9JpYp.png" alt="No go from Powershell either :(" /></a></p>
<p>I would really like to have the API Connection deployment fully via Azure DevOps pipeline.</p>
<p>NOTE: I find it very odd to have to use the <code>#disable-next-line BCP036</code> to disable the warning in VSCode. And even opening the built ARM Template will give a warning on the "gateway" property name. I even tried replacing the "object" with just the resource id and that didn't help.
<a href="https://i.stack.imgur.com/XexAB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XexAB.png" alt="ARM Template warning" /></a></p>
| [
{
"answer_id": 74213898,
"author": "I. Appelgate",
"author_id": 8948656,
"author_profile": "https://Stackoverflow.com/users/8948656",
"pm_score": -1,
"selected": false,
"text": " nonSecretParameterValues: {\n authType: 'anonymous'\n gateway-name: gatewayName\n gateway-i... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19377/"
] |
74,213,442 | <p>Can I use find() method to search through a string not an array?</p>
<p>like 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-js lang-js prettyprint-override"><code>const text = "welcome";
const output = text.find(letter => letter === "e");</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74213898,
"author": "I. Appelgate",
"author_id": 8948656,
"author_profile": "https://Stackoverflow.com/users/8948656",
"pm_score": -1,
"selected": false,
"text": " nonSecretParameterValues: {\n authType: 'anonymous'\n gateway-name: gatewayName\n gateway-i... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14171925/"
] |
74,213,451 | <p>How to trigger useEffect only once when state of a variable changes the first time from null to something?</p>
<p>In the case below, <code>state.gender</code> changes from <code>null</code> to <code>0</code> or <code>1</code>. The useEffect should only trigger when it changes the first time. Thereafter, the subsequent switches between values <code>0</code> and <code>1</code> should not trigger useEffect.</p>
<pre><code> const [state, setState] = useState({
screen: 1,
gender: null,
});
useEffect(() => {
// Do something
})}
}, [state.gender]);
...
...
...
<RadioGroup
aria-labelledby="gender-group"
name="gender"
value={state.gender}
onChange={(event, fieldValue) => {handleInputChange(event, fieldValue, "gender")}}
>
<FormControlLabel value={1} control={<Radio />} label="Female" />
<FormControlLabel value={0} control={<Radio />} label="Male" />
</RadioGroup>
</code></pre>
| [
{
"answer_id": 74213483,
"author": "Konrad",
"author_id": 5089567,
"author_profile": "https://Stackoverflow.com/users/5089567",
"pm_score": 2,
"selected": false,
"text": "ref"
},
{
"answer_id": 74213495,
"author": "Haim Abeles",
"author_id": 15298697,
"author_profile"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3717114/"
] |
74,213,466 | <p>I'm trying to make a "create profile page" and there is a section where the user enters their experiences, in this section, the user can, insert, edit and delete their experiences.</p>
<p>the only way i know it is possible to perform a deletion is with something like this:</p>
<pre><code><form action="/projects/{{$Projects->id}}" method ="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger delete-btn mt-2"><ion-icon name="trash-outline"></ion-icon> Delete </button>
</form>
</code></pre>
<p>I searched and founded that i can't put a form inside a other form, so what i can do in this situation?</p>
<p>My final code in view is something like this</p>
<pre><code><div id="event-create-container" class="col-md-6 offset-md-3">
<h4>Finalize seu perfil! </h4>
<form action="/" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group col-12">
<label for="title">Descreva um pouco sobre você:</label>
<textarea name="description" id="description" class="form-control" placeholder="Insira uma descrição sobre você"></textarea>
</div>
<!-- Botão para acionar modal -->
<div class="col-12 text-right mt-3">
<a href="#" data-toggle="modal" data-target="#modalExperience">
<ion-icon name="add-outline"></ion-icon>
</a>
</div>
<div class="form-group col-12">
<label for="title">Outras formações acadêmicas:</label>
<div class="form-group col-12 mt-3">
@foreach ($Experiences as $Experience)
<div class="col-12 text-right">
<a href="#" data-toggle="modal" data-target="#modalExperience{{$Experience->id}}"><ion-icon name="pencil-sharp"></ion-icon></a>
<form action="/profile/delete/{{$Experience->id}}" method ="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger delete-btn mt-2"><ion-icon name="trash-outline"></ion-icon> Deletar</button>
</form>
</div>
Curso: {{$Experience->experienceName}}<br>
Instituição: {{ $Experience->institutionName }}<br>
Data de inicio: {{ date('d/m/Y', strtotime($Experience->firstDate)) }}<br>
Data fim: {{ date('d/m/Y', strtotime($Experience->lastDate))}}<br>
<hr>
@endforeach
</div>
</div>
<div class="form-group col-12 text-right">
<input type="submit" class="btn btn-primary" value="Finalizar perfil">
</div>
</form>
</code></pre>
<p>With him, when i click on delete button the main form is activeted</p>
| [
{
"answer_id": 74213617,
"author": "Tim Lewis",
"author_id": 3965631,
"author_profile": "https://Stackoverflow.com/users/3965631",
"pm_score": 1,
"selected": false,
"text": "<form>"
},
{
"answer_id": 74216450,
"author": "Dwight",
"author_id": 1125910,
"author_profile"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342671/"
] |
74,213,471 | <p>I have a school assignment that goes like this: Read the int variable number. Assume that number ≥ 0. Output the numbers from number to 1 in one line (or an empty line if no positive number to print). In the next line, output the numbers -number to number on one line. Use space in both lines to separate the numbers.</p>
<p>I am not allowed to use any for loops and I am encouraged to use while loops. The output should be like this: <a href="https://i.stack.imgur.com/rMt3g.png%5D(https://www.stackoverflow.com/)" rel="nofollow noreferrer">Output</a></p>
<p>I have been really struggling with this for hours. Please help. Here is the code I have so far. The main thing I am struggling with is the 2nd line and it not reaching back up to the higher numbers.</p>
<pre><code>import java.util.Scanner;
public class Exercise
{
public static void main(String[] args)
{
Scanner myScanner=new Scanner(System.in);
int number=myScanner.nextInt();
if(number<=0)
{
System.out.println();
}
else
{
do
{
System.out.print(number + " ");
number--;
}
while(number>=1);
System.out.println();
}
do
{
System.out.print(-number + " ");
number++;
}
while(-number>=0);
}
}
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 74213617,
"author": "Tim Lewis",
"author_id": 3965631,
"author_profile": "https://Stackoverflow.com/users/3965631",
"pm_score": 1,
"selected": false,
"text": "<form>"
},
{
"answer_id": 74216450,
"author": "Dwight",
"author_id": 1125910,
"author_profile"... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20233170/"
] |
74,213,477 | <p>R noob here, please bear with me!</p>
<p>I have a dataset in full tidy form that I'm trying to <code>summarise</code>. The records each have a <code>state</code>, <code>year</code>, and two different categories, which for now we'll say take on levels of <code>A, B, C</code> and <code>X, Y, Z</code>:</p>
<pre><code>state year cat1 cat2
AK 2010 A X
AK 2010 B Z
AK 2010 A Y
AK 2010 C Z
...
</code></pre>
<p>(For scale, there are ~500k records)</p>
<p>For each state-year combination, I'm trying to get a cross-tab of how many records there are with each combination of <code>cat1</code> and <code>cat2</code> level. I can do this with <code>group_by</code> and <code>summarise</code>:</p>
<pre><code>data %>%
group_by(state, year, cat1, cat2) %>%
summarise(count = n())
</code></pre>
<p>Which yields something like:</p>
<pre><code>state year cat1 cat2 count
AK 2010 A X 32
AK 2010 A Y 501
AK 2010 A Z 109
AK 2010 B X 47
AK 2010 B Y 670
AK 2010 B Z 38
AK 2010 C X 812
AK 2010 C Y 17
AK 2010 C Z 294
...
</code></pre>
<p>And so on for each state-year combo.</p>
<p><strong>BUT</strong> the problem is that for some state-year combos, certain combinations of <code>cat1</code> and <code>cat2</code> don't exist, mostly b/c of small sample sizes. For instance:</p>
<pre><code>state year cat1 cat2 count
RI 2010 A X 10
RI 2010 A Y 17
RI 2010 B Y 4
RI 2010 C X 32
RI 2010 C Z 12
...
</code></pre>
<p>In these cases, I would like to force the result of <code>group_by</code> + <code>summarise</code> to show <em>all</em> nine possible <code>cat1</code> and <code>cat2</code> pairs for each state-year combination, filling in zero values if there are no records of that combination. So the example above should then be:</p>
<pre><code>state year cat1 cat2 count
RI 2010 A X 10
RI 2010 A Y 17
RI 2010 A Z 0
RI 2010 B X 0
RI 2010 B Y 4
RI 2010 B Z 0
RI 2010 C X 32
RI 2010 C Y 0
RI 2010 C Z 12
...
</code></pre>
<p>How do I force these explicit zero values for the missing combinations?
(I have looked some at <code>complete</code> but cannot figure out how to make it work here, if it's relevant.)</p>
| [
{
"answer_id": 74213586,
"author": "Arthur",
"author_id": 10065473,
"author_profile": "https://Stackoverflow.com/users/10065473",
"pm_score": 2,
"selected": false,
"text": ".drop = FALSE"
},
{
"answer_id": 74213627,
"author": "Allan Cameron",
"author_id": 12500315,
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12305295/"
] |
74,213,524 | <p>I have a table that looks like</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>Event</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>a</td>
<td>1:00 PM</td>
</tr>
<tr>
<td>1</td>
<td>a</td>
<td>1:05 PM</td>
</tr>
<tr>
<td>1</td>
<td>b</td>
<td>2:00 PM</td>
</tr>
<tr>
<td>1</td>
<td>c</td>
<td>3:00 PM</td>
</tr>
<tr>
<td>1</td>
<td>d</td>
<td>4:00 PM</td>
</tr>
<tr>
<td>1</td>
<td>d</td>
<td>4:02 PM</td>
</tr>
<tr>
<td>2</td>
<td>a</td>
<td>11:30</td>
</tr>
<tr>
<td>2</td>
<td>b</td>
<td>3:04 PM</td>
</tr>
<tr>
<td>2</td>
<td>b</td>
<td>3:06 PM</td>
</tr>
<tr>
<td>2</td>
<td>c</td>
<td>2:15 PM</td>
</tr>
<tr>
<td>2</td>
<td>c</td>
<td>5:20 PM</td>
</tr>
<tr>
<td>3</td>
<td>a</td>
<td>12:30 PM</td>
</tr>
<tr>
<td>3</td>
<td>b</td>
<td>4:00 PM</td>
</tr>
<tr>
<td>3</td>
<td>c</td>
<td>1:00 PM</td>
</tr>
<tr>
<td>4</td>
<td>c</td>
<td>10:00 PM</td>
</tr>
</tbody>
</table>
</div>
<p>I have a code that pivots like</p>
<pre><code>select * from
(
select id, event, time, row_number() over(partition by event order by time) as line
from table
)
pivot(min(time) for event in (a,b,c)) where line=1;
</code></pre>
<p>I'm getting a table that returns only the IDs with earliest times per column per ID like below, with null values. It won't even return the 4th ID since it doesn't have the earliest time for event c. This is a large dataset with thousands of IDs. It looks like it is only returning the ID with the earliest time for the # of events. So if I have 5 event times, it will only return me with 5 IDs max with earliest time for one of the column. I'm hoping it makes sense.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>(null)</td>
<td>2:00 PM</td>
<td>(null)</td>
</tr>
<tr>
<td>2</td>
<td>11:30</td>
<td>(null)</td>
<td>(null)</td>
</tr>
<tr>
<td>3</td>
<td>(null)</td>
<td>(null)</td>
<td>1:00 PM</td>
</tr>
</tbody>
</table>
</div>
<p>What I want is a table like above that returns the earliest time for each event per ID. Like below:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>ID</th>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1:00</td>
<td>2:00</td>
<td>3:00</td>
</tr>
<tr>
<td>2</td>
<td>11:30</td>
<td>3:04</td>
<td>2:15</td>
</tr>
</tbody>
</table>
</div>
<p>The table looks like it needs to be pivoted so this is what I've tried so far.</p>
| [
{
"answer_id": 74213586,
"author": "Arthur",
"author_id": 10065473,
"author_profile": "https://Stackoverflow.com/users/10065473",
"pm_score": 2,
"selected": false,
"text": ".drop = FALSE"
},
{
"answer_id": 74213627,
"author": "Allan Cameron",
"author_id": 12500315,
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342711/"
] |
74,213,539 | <p>My columns in my table don't all get a background color. If I use a checkbox in my table, it does not get a background color.</p>
<p>I used this code to set the background:</p>
<pre><code>participantsTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setBackground(row % 2 == 0 ? new Color(230, 230, 230): Color.WHITE);
return this;
}
});
</code></pre>
<p>I've tried searching the internet for a solution, but to no avail. I'm not so familiar with the JTabel that I could come up with the error myself.</p>
<p>Here is what shouldn't happen:
<a href="https://i.stack.imgur.com/Fepnr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fepnr.png" alt="Here is what shouldn't happen" /></a></p>
<p>So it shouldn't look like that, but the background of the checkbox should be the same as the column to the left of it.</p>
<p>What am I doing wrong and how can I fix this problem?</p>
| [
{
"answer_id": 74213586,
"author": "Arthur",
"author_id": 10065473,
"author_profile": "https://Stackoverflow.com/users/10065473",
"pm_score": 2,
"selected": false,
"text": ".drop = FALSE"
},
{
"answer_id": 74213627,
"author": "Allan Cameron",
"author_id": 12500315,
"a... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342770/"
] |
74,213,540 | <p>I have a dataframe with 2 columns of period and inventory code as below. I want to forward fill the year for each inventory item from their starting year all the way to 2022. The yellow highlighted are the rows I want to fill for each inventory item. What would be the way to do this? Any suggestions are greatly appreciated.</p>
<pre><code>import pandas as pd
list_year =[2018, 2018, 2019, 2020, 2020, 2021, 2021, 2022]
list_inv = ['TTO', 'TZA', 'OMN', 'RUS', 'SUR', 'TUR', 'USA', 'VAT']
df_test = pd.DataFrame({'period':list_year, 'inventory code': list_inv})
</code></pre>
<p>I have a dataframe like this - I have year as period and inventory code for each year. In my real dataset, I have different number of rows (inventory code) associated with each year.</p>
<p><a href="https://i.stack.imgur.com/4Zvn0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Zvn0.png" alt="enter image description here" /></a></p>
<p>I want to forward fill the years for all inventory code.</p>
<p>For example, there are two inventory items in the year of 2018, I want to insert 2 rows for each of these 2 inventory item for each of the future year till 2022.</p>
<p>Be noted I don't need to backfill the information for previous year. For example, there are two inventory items in 2019, and I don't need to insert two rows for them for the year of 2018.</p>
<p>Below highlighted are the rows I want to fill for each inventory item</p>
<p><a href="https://i.stack.imgur.com/v5K2e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v5K2e.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74223119,
"author": "user032020",
"author_id": 13046093,
"author_profile": "https://Stackoverflow.com/users/13046093",
"pm_score": 1,
"selected": false,
"text": "# Restructure the data\ndf_table = df_test.groupby(['period','inventory code'])['inventory \ncode'].max().unsta... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13046093/"
] |
74,213,543 | <p><a href="https://i.stack.imgur.com/hgDcZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hgDcZ.jpg" alt="enter image description here" /></a></p>
<p>I'm trying to make this button that have a circle shape inside and contains this arrow icon.</p>
<p>My idea is when you hover it, the whole button became colored inside</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="col-12">
<div style="border: 1px solid #583F99; width: 180px; height: 40px; border-radius: 30px;">
<span class="class justify-content-center" style="">read more</span>
<div style="border: 1px solid #583F99; border-radius: 30px; width: 38px; height: 38px; position: absolute;">
<img src="img/arrow.svg" style="width: 18px;" />
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74213697,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": -1,
"selected": true,
"text": ".button {\n height: 22px;\n border: 1px solid rgb(128, 0, 128);\n display: inline-flex;\n align-... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14039546/"
] |
74,213,549 | <p>I am very new to R so please bear with me, I've spent a good few hours trying to figure this out so figured it's about time to ask for help.</p>
<p>I am currently trying to clean up a dataset part of which requires me to group answers from one column into a new column.</p>
<p>For example when "france" is matched in a "country" column, it would add "europe" in a new "continent" column.</p>
<p>Basically this:</p>
<h3>replicatable code</h3>
<pre><code># a handful of countries to sort
df = data.frame(country = c('france','england','usa','poland','brazil','kenya','canada','england', 'usa', 'france'))
# simplified vectors for each continent
europe <- c('england','france','poland')
north_america <- c('usa','canada')
south_america <- c('brazil')
africa <- c('kenya')
# the grouping
df_updated <- df %>%
mutate(across(country, ~ case_when(. %in% europe ~ 'europe',
. %in% north_america ~ 'north america',
. %in% south_america ~ 'south america',
. %in% africa ~ 'africa'),.names = 'region'))
</code></pre>
<p>This works great. However I have to do this type of grouping across dozens of different categories in many datasets. I know it's not good practice to just copy and paste huge chunks of code so I am instead trying to write a function to do this.</p>
<p>So I have added the following:</p>
<h3>the function</h3>
<pre><code>country_list <- list(europe, north_america, south_america, africa) # a list of the 4 region vectors
country_cat <- c('europe', 'north america', 'south america', 'africa') # a vector of corosponding labels for the categories
grouping_func <- function(dataframe, name, data, list, category) {
dataframe %>%
mutate(across(!!sym(data), ~ case_when(. %in% list[[1]] ~ category[1],
. %in% list[[2]] ~ category[2],
. %in% list[[3]] ~ category[3],
. %in% list[[4]] ~ category[4]), .names = '{name}'))
}
df_updated2 <- grouping_func(df, 'continent', 'country', country_list, country_cat)
</code></pre>
<p>This took a bit of playing around - realising I couldn't search through a vector of vectors etc. but it works great.</p>
<h3>The problem</h3>
<p>This brings me to my issue. Not all variables I want to categorise are going to be the same size.</p>
<p>For example there are 7 continents but only 4 US regions, or 12 timezones, or 10 colors of fruits or whatever I need to categorize.</p>
<p>Which means I need to find a way of iterating through my list/category based on the length of the list.</p>
<p>For example if I had to pipe the following into my function it would break as the function at this point is hard coded to work through lists of 4 categories:</p>
<pre><code>morning <- c(0:11)
afternoon <- c(12:18)
evening <- c(19:23)
time_list <- list(morning, afternoon, evening)
time_cat <- c('morning', 'afternoon', 'evening')
</code></pre>
<p>I've tried using a for loop in various ways and also tried to figure out how using lapply might help but with both I've hit a brick wall. I don't even know if I got particularly close to be honest. Based on any keywords I can think of I've read everything I can find on google and SO but part of me is wondering if my lack of experience means I don't even know what I need to be looking for as I'm really coming up with nothing.</p>
<p>Could someone give me a pointer on what I'm looking for and how best to proceed with this? I'm really keen to learn but I'm about 4hrs into this problem now and no further forward than when I started </p>
<p>Thanks</p>
<p>Edit: I've accepted AndS' answer as, while it was more complex than Jon Spring's answer, it does allow me to wrangle the code directly if I do need to do so and I learned a whole new way of engaging with R through it. Both answers were great and work well though. I do think in the future I will probably package up a bunch of csvs for each type I will be working with regularly and importing them to merge. Thanks again everyone!</p>
| [
{
"answer_id": 74213697,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": -1,
"selected": true,
"text": ".button {\n height: 22px;\n border: 1px solid rgb(128, 0, 128);\n display: inline-flex;\n align-... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19710700/"
] |
74,213,554 | <p>Hello I am working with sigmoidal data and am attempting to plot two scatter plots on top of each other: the raw data & the first derivative of the raw data. My issue doesn't lie in plotting the data, but more-so finding a function that will create an accurate representation of the first derivative.</p>
<p><strong>What have I tried:</strong> Creating a function that calculates the slope of the current & next point: (y2-y1)/(x2-x1) & assigning the value to the current temperature.</p>
<p><strong>dput() of Data Frame:</strong>
<code>structure(list(Temperature = c(4.98, 5.49, 6.01, 6.5, 7.02, 7.52, 8.03, 8.52, 9.03, 9.54, 10.04, 10.54, 11.05, 11.55, 12.05, 12.55, 13.05, 13.56, 14.06, 14.57, 15.07, 15.57, 16.07, 16.59, 17.08, 17.59, 18.08, 18.59, 19.09, 19.6, 20.1, 20.64, 21.12, 21.63, 22.13, 22.62, 23.13, 23.63, 24.13, 24.63, 25.11, 25.62, 26.11, 26.68, 27.19, 27.7, 28.2, 28.71, 29.21, 29.71, 30.21, 30.7, 31.21, 31.69, 32.19, 32.69, 33.19, 33.7, 34.19, 34.68, 35.19, 35.68, 36.19, 36.69, 37.19, 37.7, 38.19, 38.7, 39.2, 39.7, 40.21, 40.7, 41.22, 41.71, 42.21, 42.71, 43.21, 43.72, 44.22, 44.72, 45.22, 45.73, 46.23, 46.73, 47.23, 47.97, 48.71, 49.23, 49.74, 50.23, 50.73, 51.23, 51.73, 52.24, 52.75, 53.24, 53.75, 54.24, 54.75, 55.26, 55.75, 56.25, 56.75, 57.24, 57.75, 58.27, 58.77, 59.26, 59.77, 60.26, 60.78, 61.27, 61.79, 62.27, 62.77, 63.29, 63.79, 64.27, 64.78, 65.3, 65.8, 66.27, 66.8, 67.3, 67.8, 68.31, 68.78, 69.3, 69.8, 70.32, 70.81, 71.32, 71.81, 72.33, 72.82, 73.31, 73.83, 74.33, 74.82, 75.32, 75.83, 76.34, 76.84, 77.35, 77.82, 78.34, 78.85, 79.36, 79.84, 80.35, 80.85, 81.36, 81.86, 82.37, 82.86, 83.37, 83.88, 84.36, 84.88, 85.38, 85.88, 86.38, 86.89, 87.38, 87.89, 88.39, 88.89, 89.4, 89.9, 90.39, 90.9, 91.4, 91.91, 92.37, 92.89, 93.4, 93.91, 94.41, 94.91, 95.42), Absorbance = c(1.401351929, 1.403320313, 1.405181885, 1.406326294, 1.407440186, 1.409118652, 1.410095215, 1.410797119, 1.411560059, 1.412918091, 1.413970947, 1.414245605, 1.416000366, 1.415435791, 1.41809082, 1.4190979, 1.419677734, 1.420150757, 1.421966553, 1.420333862, 1.422637939, 1.422790527, 1.423461914, 1.426513672, 1.426315308, 1.426071167, 1.426467896, 1.428710938, 1.428070068, 1.428817749, 1.429733276, 1.432144165, 1.432434082, 1.433227539, 1.434616089, 1.435806274, 1.434814453, 1.436096191, 1.436096191, 1.436447144, 1.437896729, 1.4375, 1.438934326, 1.440139771, 1.440139771, 1.441741943, 1.442108154, 1.443969727, 1.444778442, 1.443862915, 1.444534302, 1.445648193, 1.444473267, 1.446395874, 1.447219849, 1.446151733, 1.449569702, 1.449066162, 1.448852539, 1.4503479, 1.451385498, 1.45111084, 1.451217651, 1.453125, 1.452560425, 1.455047607, 1.455093384, 1.456665039, 1.457977295, 1.457336426, 1.458648682, 1.46043396, 1.462158203, 1.464813232, 1.463531494, 1.468048096, 1.468643188, 1.470748901, 1.471878052, 1.476257324, 1.478057861, 1.482040405, 1.484466553, 1.486129761, 1.48815918, 1.496520996, 1.499786377, 1.504302979, 1.507217407, 1.512985229, 1.517471313, 1.524108887, 1.528198242, 1.534637451, 1.539169312, 1.546142578, 1.554611206, 1.55809021, 1.56854248, 1.572875977, 1.580307007, 1.585739136, 1.592514038, 1.600067139, 1.609222412, 1.616607666, 1.622375488, 1.631469727, 1.635635376, 1.642929077, 1.649780273, 1.655014038, 1.661483765, 1.663742065, 1.671859741, 1.677200317, 1.677108765, 1.683380127, 1.684082031, 1.687438965, 1.694595337, 1.694961548, 1.696685791, 1.696685791, 1.699768066, 1.702514648, 1.703613281, 1.705093384, 1.70022583, 1.707595825, 1.707962036, 1.709075928, 1.705276489, 1.71055603, 1.709259033, 1.70916748, 1.709732056, 1.710189819, 1.710281372, 1.711868286, 1.711883545, 1.713104248, 1.713760376, 1.711120605, 1.709716797, 1.711776733, 1.712814331, 1.714324951, 1.711120605, 1.713378906, 1.712432861, 1.716125488, 1.710006714, 1.710845947, 1.711502075, 1.711120605, 1.710006714, 1.70980835, 1.708602905, 1.708236694, 1.710189819, 1.707672119, 1.706939697, 1.710006714, 1.706192017, 1.706573486, 1.706207275, 1.705734253, 1.706207275, 1.705184937, 1.70954895, 1.705841064, 1.702972412, 1.703979492, 1.703063965, 1.709350586, 1.703338623, 1.700408936, 1.705276489, 1.705368042)), row.names = 1621:1800, class = "data.frame")</code></p>
<p><strong>Code For my Attempt</strong></p>
<pre><code>raw = "<insert dput line>>"
columns = c("Temperature","Absorbance")
first = data.frame(matrix(nrow=0,ncol=2))
colnames(dFrame) = columns
for (i in 1:nrow(raw)) {
if(i != nrow(raw)) {
cAbs = raw[i,2]
nextAbs = raw[i+1,2]
cT = raw[i,1]
nextT = raw[i+1,1]
Temperature = raw[i,1]
Absorbance =((nextAbs-cAbs)/(nextT-cT))
t <- data.frame(Temperature,Absorbance)
names(t) <- names(raw)
first <- rbind(first, t)
}
}
ggplot()+
geom_point(data=raw, aes(x=Temperature,y=Absorbance), color = "red") +
geom_point(data = first, aes(x=Temperature,y = Absorbance), color = "blue")
</code></pre>
<p><strong>What I was expecting</strong>
I was expecting an output that had the shape of something like so:<a href="https://i.stack.imgur.com/7naST.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7naST.png" alt="Example plot of Raw vs. First Derivative" /></a></p>
| [
{
"answer_id": 74213731,
"author": "Jon Spring",
"author_id": 6851825,
"author_profile": "https://Stackoverflow.com/users/6851825",
"pm_score": 2,
"selected": true,
"text": "library(dplyr); library(ggplot2)\ndf %>%\n arrange(Temperature) %>%\n mutate(slope = (Absorbance - lag(Absorbanc... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18377517/"
] |
74,213,562 | <p>I have never used Julia and I am following a tutorial. I have reached an instruction that are written below. When I tried the Lon3D, Lat3D,Depth3D =LonLatDepthGrid(lon,lat,depth) I got and error saying <strong>ERROR: UndefVarError: LonLatDepthGrid not defined</strong>
I tried creating the variable using <em>LonLatDepthGrid =()</em>
I ran the Lon3d.... command again then got the following error * MethodError: objects of type Tuple{} are not callable*
What am I missing????
THanks
K</p>
<p>Here is the order in which I am defining variables:</p>
<pre><code>lat = ncread("APVC.ANT+RF.Ward.2014_kmps.nc","latitude")
lon = ncread("APVC.ANT+RF.Ward.2014_kmps.nc","longitude")
depth = ncread("APVC.ANT+RF.Ward.2014_kmps.nc","depth")
Vs_3D = ncread("APVC.ANT+RF.Ward.2014_kmps.nc","vs")
depth = -1 .* depth
Lon3D,Lat3D,Depth3D = LonLatDepthGrid(lon, lat, depth);
</code></pre>
<p>I tried creating the variable using
LonLatDepthGrid =()
I ran the Lon3d.... command again then got the following error * MethodError: objects of type Tuple{} are not callable*
What am I missing????
THanks
K</p>
| [
{
"answer_id": 74213731,
"author": "Jon Spring",
"author_id": 6851825,
"author_profile": "https://Stackoverflow.com/users/6851825",
"pm_score": 2,
"selected": true,
"text": "library(dplyr); library(ggplot2)\ndf %>%\n arrange(Temperature) %>%\n mutate(slope = (Absorbance - lag(Absorbanc... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342786/"
] |
74,213,590 | <p>Forgive my javascript ignorance - I'm strictly a php developer</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function checkTotal() {
document.listForm.total.value = '';
var sum = 0;
var o = 0;
for (i = 0; i < document.listForm.choice.length; i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseInt(document.listForm.choice[i].value);
o++;
}
}
if (o > 1) {
sum = sum - 0;
}
document.listForm.total.value = sum.toFixed(2);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><form name="listForm">
<input type="checkbox" name="choice" value="10.25" onChange="checkTotal()" />Pizza<br/>
<input type="checkbox" name="choice" value="9.75" onChange="checkTotal()" />Salad<br/>
<input type="checkbox" name="choice" value="12.50" onChange="checkTotal()" />Wings<br/> Total:
<input type="number" size="5" name="total" value="0" />
</form></code></pre>
</div>
</div>
</p>
<p>The results were <code>10.00</code>, <code>9.00</code> & <code>12.00</code> (this does add correctly to 31.00)</p>
<p>should be: <code>10.25 + 9.75 + 12.50 = 32.50</code></p>
| [
{
"answer_id": 74213643,
"author": "ajm",
"author_id": 78738,
"author_profile": "https://Stackoverflow.com/users/78738",
"pm_score": 1,
"selected": false,
"text": "parseInt"
},
{
"answer_id": 74213877,
"author": "Dimava",
"author_id": 5734961,
"author_profile": "https... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342563/"
] |
74,213,616 | <p>I have a data frame and a dictionary like this:</p>
<pre><code>thresholds = {'column':{'A':10,'B':11,'C':9}}
df:
Column
A 13
A 7
A 11
B 12
B 14
B 14
C 7
C 8
C 11
</code></pre>
<p>For every index group, I want to calculate the count of values less than the threshold and greater than the threshold value.
So my output looks like this:</p>
<pre><code>df:
Values<Thr Values>Thr
A 1 2
B 0 3
C 2 1
</code></pre>
<p>Can anyone help me with this</p>
| [
{
"answer_id": 74213745,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 3,
"selected": true,
"text": "import numpy as np\n\nt = df.index.to_series().map(thresholds['column'])\n\nout = (pd.crosstab(df.index, np.where(df... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19675781/"
] |
74,213,632 | <p>Would anyone be able to give me help regarding <strong>React Navigation</strong> with Expo? The issue is with the drawer component where the 'Hamburger' icon isn't opening or closing the component when a user presses the icon. However, it does open/close on a default swipe gesture from React Navigation. Please see below for my code:</p>
<p>Router:</p>
<pre><code>import React from 'react';
import { NavigationContainer, DrawerActions } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { IconButton } from 'react-native-paper'
import i18n from '../i18n/i18n';
//Theme
import Theme from '../theme/theme'
//Components
import Menu from '../components/Menu'
//Import Interfaces
import { RootDrawerParamList } from '../utils/typescript/type.d';
import { IProps } from '../utils/typescript/props.d';
//Import Screens
import Screen1 from '../screens/Screen1';
import Screen2 from '../screens/Screen2';
import SettingsScreen from '../screens/Settings';
const Drawer = createDrawerNavigator<RootDrawerParamList>();
export default class Router extends React.Component<IProps, any> {
constructor(props: IProps) {
super(props);
}
render() {
return (
<NavigationContainer>
<Drawer.Navigator
initialRouteName='Screen1'
drawerContent={(props: any) => <Menu {...props} />}
screenOptions={({
swipeEnabled: true
})}>
<Drawer.Screen
name="Screen1"
component={Screen1}
initialParams={{ i18n: i18n, Theme: Theme }}
options={({route, navigation} : any) => ({
headerRight: () => (<IconButton icon="cog" size={24} color={Theme.colors.text} onPress={() => navigation.navigate('Settings')} />),
route: {route},
navigation: {navigation}
})}
/>
<Drawer.Screen
name="Settings"
component={SettingsScreen}
initialParams={{ i18n: i18n, Theme: Theme }}
options={({route, navigation} : any) => ({
headerTitle: i18n.t('settings', 'Settings'),
headerLeft: () => (<IconButton icon="arrow-left" color={Theme.colors.text} size={24} onPress={() => navigation.goBack()} />),
route: {route},
navigation: {navigation}
})}
/>
<Drawer.Screen
name="Screen2"
component={Screen2}
initialParams={{ i18n: i18n, Theme: Theme }}
options={({route, navigation} : any) => ({
route: {route},
navigation: {navigation}
})}
/>
</Drawer.Navigator>
</NavigationContainer>
);
}
}
</code></pre>
<p>Menu</p>
<pre><code>import React from 'react';
import { FlatList, StyleSheet, View } from 'react-native';
import { List, Title } from 'react-native-paper';
import { getDefaultHeaderHeight } from '@react-navigation/elements';
import { DrawerItem } from '@react-navigation/drawer';
import { useSafeAreaFrame, useSafeAreaInsets } from 'react-native-safe-area-context';
//Import Interfaces
import { IListItem } from '../utils/typescript/types.d';
import { IPropsMenu } from '../utils/typescript/props.d';
import { IStateMenu } from '../utils/typescript/state.d';
//A function is used to pass the header height, using hooks.
function withHeightHook(Component: any){
return function WrappedComponent(props: IPropsMenu) {
/*
Returns the frame of the nearest provider. This can be used as an alternative to the Dimensions module.
*/
const frame = useSafeAreaFrame();
/*
Returns the safe area insets of the nearest provider. This allows manipulating the inset values from JavaScript. Note that insets are not updated synchronously so it might cause a slight delay for example when rotating the screen.
*/
const insets = useSafeAreaInsets();
return <Component {...props} headerHeight={getDefaultHeaderHeight(frame, false, insets.top)} />
}
}
class Menu extends React.Component<IPropsMenu, IStateMenu> {
constructor(props: IPropsMenu) {
super(props);
this.state = {
menu: [
{
name: 'screen1.name',
fallbackName: 'Screen 1',
icon: 'dice-multiple-outline',
iconFocused: 'dice-multiple',
onPress: this.props.navigation.navigate.bind(this, 'screen1')
},
{
name: 'screen2.name',
fallbackName: 'Screen 2',
icon: 'drama-masks',
iconFocused: 'drama-masks',
onPress: this.props.navigation.navigate.bind(this, 'screen2')
}
]
}
}
renderItem = (item : IListItem) => {
const { i18n } = this.props.state.routes[0].params;
return (
<DrawerItem
label={ i18n.t(item.name, item.fallbackName) }
onPress={ item.onPress ? item.onPress: () => {} }
icon={ ({ focused, color, size }) => <List.Icon color={color} style={[styles.icon, {width: size, height: size }]} icon={(focused ? item.iconFocused : item.icon) || ''} /> }
/>
);
};
render() {
const { headerHeight } = this.props;
const { menu } = this.state;
const { Theme } = this.props.state.routes[0].params;
return (
<View>
<View style={{
backgroundColor: Theme.colors.primary,
height: headerHeight ?? 0,
}}>
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end',
}}>
<View style={{
flexDirection: 'row',
alignItems: 'center',
marginBottom: 5,
marginLeft: 5
}}>
<Title style={{ color: Theme.colors.text, marginLeft: 5 }}>
Title
</Title>
</View>
</View>
</View>
<FlatList
data={menu}
keyExtractor={item => item.name}
renderItem={({item}) => this.renderItem(item)}
/>
</View>
);
};
}
export default withHeightHook(Menu);
const styles = StyleSheet.create({
icon: {
alignSelf: 'center',
margin: 0,
padding: 0,
height:20
},
logo: {
width: 24,
height: 24,
marginHorizontal: 8,
alignSelf: 'center'
},
});
</code></pre>
| [
{
"answer_id": 74213875,
"author": "Sergio Schirmer",
"author_id": 5007447,
"author_profile": "https://Stackoverflow.com/users/5007447",
"pm_score": 0,
"selected": false,
"text": "onPress={()=> navigation.toggleDrawer()\n"
},
{
"answer_id": 74269977,
"author": "MartynFItz",
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9161829/"
] |
74,213,655 | <p>Does anyone knows any formula to extract the number with separation (dot, comma) from cell <code>A1</code> to cell <code>B1</code>?</p>
<p>Example, I want to extract <code>2,590.00</code> from cell <code>A1</code> which has the following value:</p>
<pre><code>[sum: 2,590.00]
</code></pre>
<p>I got the formula below that works nice, however is just getting all numbers e.g. <code>259000</code></p>
<pre><code>{=TEXTJOIN("",TRUE,IFERROR((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)*1),""))}
</code></pre>
<p>I appreciate every support</p>
| [
{
"answer_id": 74213875,
"author": "Sergio Schirmer",
"author_id": 5007447,
"author_profile": "https://Stackoverflow.com/users/5007447",
"pm_score": 0,
"selected": false,
"text": "onPress={()=> navigation.toggleDrawer()\n"
},
{
"answer_id": 74269977,
"author": "MartynFItz",
... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18440743/"
] |
74,213,658 | <p>From a given dataframe, I am trying to create a dictionary with the following format: <code>{(row, column):'cell value'}</code>. I am aware of <code>pandas.DataFrame.to_dict</code>, but that creates a dictionary of dictionaries: <code>{row:{column:'cell value'}}</code>.</p>
<p>Would you have any code suggestions? Would loop be a good idea?</p>
| [
{
"answer_id": 74213771,
"author": "jprebys",
"author_id": 3268228,
"author_profile": "https://Stackoverflow.com/users/3268228",
"pm_score": 0,
"selected": false,
"text": "to_dict"
},
{
"answer_id": 74213840,
"author": "wjandrea",
"author_id": 4518341,
"author_profile... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4898127/"
] |
74,213,662 | <p>I am trying to download a CSV file provided by the <em>Download to CSV</em> link here: <a href="https://www.misoenergy.org/planning/generator-interconnection/GI_Queue/gi-interactive-queue/" rel="nofollow noreferrer">https://www.misoenergy.org/planning/generator-interconnection/GI_Queue/gi-interactive-queue/</a>.</p>
<p>The problem is that it is appears to be hidden behind a javascript function and the resulting URL is different each time you click it.</p>
<p>I have tried using <code>requests.get()</code> and <code>urllib.urlretrieve()</code> but all it gives is the parent page.</p>
<p>How can I get the link behind that button and download the CSV using Python?</p>
| [
{
"answer_id": 74213806,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile": "https://Stackoverflow.com/users/10035985",
"pm_score": 3,
"selected": true,
"text": "import requests\nimport pandas as pd\n\napi_url = \"https://www.misoenergy.org/api/giqueue/getprojects\"\n\nd... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1370841/"
] |
74,213,674 | <p>I'm working with some images, using gray intensity values in data frames. I manipulate the raw values a handful of ways, and let's just say I end up with a data frame that looks like this:</p>
<pre><code>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 2 1 0 0 0 0 0 0
0 0 0 0 0 3 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 2 1 3 1 5 0 0 0 0
0 0 0 0 1 3 1 1 1 4 3 0 0 0 0
0 0 0 0 1 1 5 2 **0** 1 1 0 0 0 0
0 0 0 0 0 5 1 1 **0** 2 1 0 0 0 0
0 0 0 0 0 1 1 1 2 1 3 0 0 0 0
0 0 0 0 0 0 1 2 1 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
</code></pre>
<p>Note the bolded 0 values, which are the only 0s surrounded by non-zero values on all sides. What I'm hoping to do is convert the 0s in those locations, and only those locations, to 1 (for example), without disrupting all the outer 0s.</p>
<p>I've looked through the documentation but I'm not sure how--if it's possible--to tell pd.replace what conditions must be met to replace a given 0. Does anyone have any suggestions? Sorry for the formatting - new here.</p>
| [
{
"answer_id": 74214083,
"author": "Nanook",
"author_id": 19831517,
"author_profile": "https://Stackoverflow.com/users/19831517",
"pm_score": 2,
"selected": false,
"text": "df.values.tolist()"
},
{
"answer_id": 74214132,
"author": "chrslg",
"author_id": 20037042,
"aut... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20303560/"
] |
74,213,676 | <p>I have a static dictionary field. How do I conditonally include a 3rd item based on a certain condition?</p>
<pre><code>public static Dictionary<int, Object> dic = new Dictionary<int,Object>{
{1, new Object()},
{2, new Object()},
};
</code></pre>
| [
{
"answer_id": 74213733,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 0,
"selected": false,
"text": "public static Dictionary<int, Object> dic = initDic();\n\nprivate static Dictionary<int, Object> initDic() {\n var d ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2845850/"
] |
74,213,704 | <p>Having two tables with the following data (with 0 representing sad and 1 happy)
I need to have one graph for the two tables.
The IDs are unique for each table.</p>
<p>I tried implementing it as two different pivot tables or as one regular table with a relationship but didn't succeed.
Using Excel.</p>
<p>Is it the right approach? How can I merge both tables into one pivot chart?
Maybe with vlookup?</p>
<p>Table 1 - group A:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">happy/ sad</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">123</td>
<td style="text-align: center;">0</td>
</tr>
<tr>
<td style="text-align: center;">456</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: center;">789</td>
<td style="text-align: center;">0</td>
</tr>
</tbody>
</table>
</div>
<p>Table 2 - group B:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">happy/ sad</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">111</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: center;">444</td>
<td style="text-align: center;">1</td>
</tr>
<tr>
<td style="text-align: center;">888</td>
<td style="text-align: center;">0</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74213733,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 0,
"selected": false,
"text": "public static Dictionary<int, Object> dic = initDic();\n\nprivate static Dictionary<int, Object> initDic() {\n var d ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13572976/"
] |
74,213,723 | <p>I want to develop a vs-code plugin that extends the functionality of GitHub CoPilot. I want to listen to code completions and reward the user with points based on the length and content of the completions made with CoPilot. Is it possible to write a plugin that builds upon the original plugin, or do I have to use the OpenAI API to recreate the functionality of the plugin to add my Gamification elements?
Thanks a lot in advance for any kind of help.</p>
| [
{
"answer_id": 74213733,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 0,
"selected": false,
"text": "public static Dictionary<int, Object> dic = initDic();\n\nprivate static Dictionary<int, Object> initDic() {\n var d ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10766966/"
] |
74,213,747 | <p>I'm a beginner to Python, and for the sake of learning I looked up some challenges to solve. Here I have a dictionary, containing several dictionaries, each having a list of dicts. My job here is to sort the dictionary, in descending order, based on which child of <code>somedict</code> has more elements in the <code>key</code> list.</p>
<pre class="lang-py prettyprint-override"><code>somedict = {
'a': {
'key' : [{}, {}, ]
},
'b': {
'key' : [{}, ]
},
'c': {
'key' : [{}, {}, {} ]
},
'd': {
'key' : [{}, {}, {}, ]
},
'e': {
'key' : [{}, {}, {} ]
},
'f': {
'key' : [{}, ]
},
'g': {
'key' : [{}, {} ]
},
'h': {
'key' : [{}, {}, {},]
}
}
sorted_dict = sorted(somedict, key= lambda k: len(k['a']['key']))
print(sorted_dict)
</code></pre>
<p>While trying to use <code>sorted()</code>, I get:</p>
<p><code>TypeError: string indices must be integers</code></p>
| [
{
"answer_id": 74213823,
"author": "ᴊᴇsᴘᴇʀᴋ.ᴇᴛʜ",
"author_id": 3462321,
"author_profile": "https://Stackoverflow.com/users/3462321",
"pm_score": 2,
"selected": false,
"text": "somedict = {\n 'a': {\n 'key' : [{}, {}, ]\n },\n 'b': {\n 'key' : [{}, ]\n },\n 'c... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18781924/"
] |
74,213,779 | <p>I am relatively new to Javascript.
I am struggling with data wrangling. I would like to avoid loops.</p>
<p>I need to keep the higher levels of structure of "data_1", but insert an object in place of each of the key values of the form {name: "Key <em>n</em>", length: <em>int</em>}</p>
<p>The objects have of the following structures:</p>
<pre><code>const data_1 = {
Category1: ["Key A", "Key B", "Key C"],
Category2: ["Key D", "Key E", "Key F"],
Category3: ["Key G", "Key H"]
}
const data_2 = {
"Key A": 100,
"Key B": 200,
"Key C": 300,
"Key D": 400,
"Key E": 400,
"Key F": 300,
"Key G": 200,
"Key H": 100
}
</code></pre>
<p>The target structure should be:</p>
<pre><code>result = {
Category1: [{name:"Key A", length:100}, {name:"Key B", length:200}, {name: "Key C", length:300}],
Category2: [{name:"Key D", length:400}, {name:"Key E", length:400}, {name: "Key F", length:300}],
Category3: [{name:"Key G", length:200}, {name:"Key H", length:100}]
}
</code></pre>
<p>I suspect the way to tackle this is something akin to the following pseudo code. I am struggling to define an object as [name: key, length:data_2.key] .</p>
<pre><code>let results = Object.fromEntries(data_1.map(key => [name: key, length:data_2.key]));
</code></pre>
<p>Any and all help is appreciated :)</p>
| [
{
"answer_id": 74213838,
"author": "caTS",
"author_id": 18244921,
"author_profile": "https://Stackoverflow.com/users/18244921",
"pm_score": 1,
"selected": true,
"text": "const data_1 = {\n Category1: [\"Key A\", \"Key B\", \"Key C\"],\n Category2: [\"Key D\", \"Key E\", \"Key F\"],\n ... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11979840/"
] |
74,213,789 | <p>My code doesnt convert ex. dog_cat_dog into dogCatDog. The out put of my code is dogCat_dog. Trying to make a loop that doesn't stop at the first "_":</p>
<pre><code>public String underscoreToCamel(String textToConvert) {
int index_= textToConvert.indexOf("_",0);
String camelCase="";
String upperCase = "";
String lowerCase="";
for (int i=0; i < textToConvert.length(); i++){
if(i==index_){
upperCase= (textToConvert.charAt(index_+1)+upperCase).toUpperCase();
upperCase= upperCase+ textToConvert.substring(index_+2);
}
else{
lowerCase=textToConvert.substring(0,index_);
}
camelCase=lowerCase+upperCase;
}
return camelCase;
}
</code></pre>
| [
{
"answer_id": 74213894,
"author": "Elliott Frisch",
"author_id": 2970947,
"author_profile": "https://Stackoverflow.com/users/2970947",
"pm_score": 2,
"selected": false,
"text": "static"
},
{
"answer_id": 74213921,
"author": "Johnny Mopp",
"author_id": 669576,
"author... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342992/"
] |
74,213,805 | <p>i want to use the rem function with every element in a string v[j], i tried with <code>rem(v[j],3)</code> but i get the following error <code>MethodError: no method matching rem(::VariableRef, ::Int64)</code>.
Can i use rem with a string? is there any other function that does the same?</p>
| [
{
"answer_id": 74213879,
"author": "Przemyslaw Szufel",
"author_id": 9957710,
"author_profile": "https://Stackoverflow.com/users/9957710",
"pm_score": 0,
"selected": false,
"text": "s = \"some string\"\n\nrem.(Int32.(collect(s)), 3)\n"
},
{
"answer_id": 74214775,
"author": "O... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14148491/"
] |
74,213,815 | <p>I have assigned a shape and color to each point, and I want to draw the legend according to the group data, but I can't add the legend..</p>
<pre><code>library(datasets)
library(tidyverse)
library(reshape2)
name <- c("S1","S1","S1","S2","S2","S3","S3","S3","S4","S4","S5")
x <- c(1,5,9,8,5,6,7,4,3,6,4)
y <- c(3,8,9,5,7,5,3,8,9,3,4)
Shape <- c(21,21,21,22,22,23,23,23,24,24,25)
Color <- c("red","red","red","blue","blue","green","green","green","purple","purple","black")
df <- data.frame(x,y,name,Shape,Color)
graph1 <- ggplot(df,aes(x,y,fill = Color, shape = Shape))+
geom_point(size = 4)+
scale_shape_identity()+
scale_fill_identity()
graph1
</code></pre>
<p>the x and y is the main data. The name is the group. The Shape and Color is the shape and color I assigned for all those point. How to draw a legend according to the group?</p>
| [
{
"answer_id": 74213863,
"author": "br00t",
"author_id": 4028717,
"author_profile": "https://Stackoverflow.com/users/4028717",
"pm_score": 0,
"selected": false,
"text": "aes"
},
{
"answer_id": 74213988,
"author": "Allan Cameron",
"author_id": 12500315,
"author_profile... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213815",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20342906/"
] |
74,213,897 | <p>Im trying to create an discord embed that containts info of some webstite. Im trying to store the driver.find_element.text of with selenium.</p>
<p>Then I want to put that python variable into a json code that makes a discord embed.</p>
<p>The problem is that each product of this page give me 3 different texts. How can I save each one in diferents variables. I put my code here
`</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
import csv
DRIVER_PATH = 'C:\chromedriver.exe'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get('https://www.zalando.es/release-calendar/zapatillas-mujer/')
product_1 = driver.find_element(By.XPATH, '//*[@id="release-calendar"]/div/div[1]/div')
print(product_1.text)
</code></pre>
<p>The result in terminakl is
119,95€
adidas Originals
Forum MID TM
28 de octubre de 2022, 8:00
Recordármelo</p>
<p>Thanks for the help I really dont know how to save the .text info into differents python varaibles.</p>
| [
{
"answer_id": 74213975,
"author": "Zack Walton",
"author_id": 5601615,
"author_profile": "https://Stackoverflow.com/users/5601615",
"pm_score": 2,
"selected": true,
"text": "element_text = product_1.text\nelement_text_split = element_text.split() # split by space\n"
},
{
"answe... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213897",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16179319/"
] |
74,213,900 | <p>I am new to javascript. I am trying to creates a notesapp with notes made by user input. So far I am able to add and display the notes but each note is being displayed twice e.g if I input "hello" it prints hello but then if I then input "goodbye" it prints out "hello,hello,goodbye." I have my code printed below with my view and model class.</p>
<pre><code>class NotesView{
constructor(model){
this.model = model;
this.mainContainerEL = document.querySelector('#main-container');
this.noteButton = document.querySelector('#add-note');
this.noteButton.addEventListener('click', () => { this.addNewNote() });
}
addNewNote(){
const new_note = document.getElementById('message').value;
this.model.addNote(new_note);
this.displayNotes();
}
displayNotes() {
const notes = this.model.getNotes();
notes.forEach(note =>{
const noteEl = document.createElement('div');
noteEl.textContent = note;
noteEl.className = 'note';
this.mainContainerEL.append(noteEl);
})
}
}
module.exports = NotesView;
class notesModel{
constructor(notes){
this.notes = []
}
getNotes(){
return this.notes
}
addNote(note){
return this.notes.push(note)
}
reset(){
this.notes.splice(0, this.notes.length)
}
}
module.exports = notesModel;
</code></pre>
| [
{
"answer_id": 74213975,
"author": "Zack Walton",
"author_id": 5601615,
"author_profile": "https://Stackoverflow.com/users/5601615",
"pm_score": 2,
"selected": true,
"text": "element_text = product_1.text\nelement_text_split = element_text.split() # split by space\n"
},
{
"answe... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213900",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17526593/"
] |
74,213,903 | <p>I want to list which things are useable under \\root\ .However i don't know how to list or see which things i can use.Because,i am beginner in the powershell.</p>
<p>I am coding this thing:
wmic /namespace:\root\
(But i don't know which things i can use under root.And because of this, i cannot use anything :/)</p>
<p>How can i list which things could be useable under root ?
If someone can help, i will be really happy :D</p>
<p>I tried use "/?" but it didn't help.Also i researched on google BUT again i couldn't find something useful for myself or maybe i couldn't understand their solutions.</p>
| [
{
"answer_id": 74214054,
"author": "Cpt.Whale",
"author_id": 7411885,
"author_profile": "https://Stackoverflow.com/users/7411885",
"pm_score": 3,
"selected": true,
"text": "__namespace"
},
{
"answer_id": 74228607,
"author": "mklement0",
"author_id": 45375,
"author_pro... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20343051/"
] |
74,213,913 | <p>I want to use vscode instead of notepad. I prefer to type as fast as possible when launching vscode but i can't seem to find this option to do this. Does anyone know what this option is named after or if it's possible with a plugin?</p>
| [
{
"answer_id": 74220079,
"author": "Macley",
"author_id": 15361696,
"author_profile": "https://Stackoverflow.com/users/15361696",
"pm_score": 2,
"selected": true,
"text": "workbench.startupEditor"
}
] | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15361696/"
] |
74,213,940 | <p>I am relatively new to r and have been racking my head around trying to figure out how to make my code more efficient. This is a subset of the data I have been using:</p>
<pre><code>mydata <- structure(list(Subject = c("1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2"), Interval = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L), XDistance = c(240, 252.5, 125, 107.5, 170, 77.5,
105, 157.5, 187.5, 125, 62.5, 187.5, 15, 130, 45, 0, 80, 205,
97.5, 85, 160, 152.5, 12.5, 107.5, 157.5, 112.5, 102.5, 82.5,
55, 57.5, 217.5, 235, 142.5, 215, 127.5, 120, 115, 167.5, 182.5,
147.5, 207.5, 90, 165, 155, 222.5, 140, 175, 72.5, 112.5, 172.5
), YDistance = c(235, 190, 145, 132.5, 210, 92.5, 160, 150, 192.5,
170, 105, 162.5, 87.5, 170, 80, 12.5, 145, 182.5, 170, 87.5,
102.5, 122.5, 0, 117.5, 247.5, 195, 145, 167.5, 97.5, 75, 395,
277.5, 245, 260, 270, 237.5, 235, 275, 245, 210, 200, 92.5, 217.5,
195, 225, 247.5, 212.5, 135, 187.5, 192.5)), row.names = c(NA,
-50L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000022000ea9850>)e here
</code></pre>
<p>My aim is to get the means of XDistance & YDistance for each subject in 5 interval bins. There are a total of 30 intervals for each subject and I would 6 groups of means per subject. I would then like to create a new table of these means. I was able to do this, however, I did it in a convoluted manner. Here is the code I have used:</p>
<pre><code>mydata <- read.csv("DSR_Practice.csv")
par(mfrow = c(2,2))
library(dplyr)
mydata <- mydata[!(mydata$Subject == "Not Used"), ]
library(data.table)
setDT(mydata)
cuts <- list(c(1,5), c(6,10), c(11,15), c(16, 20), c(21, 25), c(26, 30))
data <- lapply(X = cuts, function(i) {
mydata[between(x = mydata[ , Interval], lower = i[1], upper = i[2])]
})
Bin1 <- as.data.frame(data[[1]])
Bin1 <- Bin1 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
Bin2 <- as.data.frame(data[[2]])
Bin2 <- Bin2 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
Bin3 <- as.data.frame(data[[3]])
Bin3 <- Bin3 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
Bin4 <- as.data.frame(data[[4]])
Bin4 <- Bin4 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
Bin5 <- as.data.frame(data[[5]])
Bin5 <- Bin5 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
Bin6 <- as.data.frame(data[[6]])
Bin6 <- Bin6 %>%
group_by(Subject) %>%
summarise(across(XDistance:YDistance, mean, X = "{XDistance}.{mean}", Y = "{YDistance}. {mean}")) %>%
as.data.frame()
df.list <- list(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6)
df.list <- Reduce(function(x, y) merge(x, y, all = TRUE), df.list)
</code></pre>
<p>Any help would be greatly appreciated!</p>
<p>I was trying to use a for loop create these bins and also tried to use lapply to get the means of a list of all bins but I can't seem to figure it out.</p>
| [
{
"answer_id": 74214176,
"author": "Seth",
"author_id": 19316600,
"author_profile": "https://Stackoverflow.com/users/19316600",
"pm_score": 0,
"selected": false,
"text": "library(dplyr)\nmydata %>%\n group_by(Subject) %>%\n mutate(Bin = case_when(\n Interval >= 1 & Interval <= 5 ~ 1... | 2022/10/26 | [
"https://Stackoverflow.com/questions/74213940",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20293578/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.