qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,160,279 | <p>I'm trying to use something like <code>strcmp</code> to compare a command like "Hello 4" and keep the 4 as a variable</p>
<p>Something like this:</p>
<pre><code>if(strcmp(c, "Hello %d") == 0){
int num = %d;
}
</code></pre>
| [
{
"answer_id": 74160317,
"author": "Silvio Mayolo",
"author_id": 2288659,
"author_profile": "https://Stackoverflow.com/users/2288659",
"pm_score": 4,
"selected": true,
"text": "sscanf"
},
{
"answer_id": 74160351,
"author": "Chris",
"author_id": 15261315,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305200/"
] |
74,160,293 | <p>I am trying to make the <code>header</code> element's height size to change depending on a criteria. I set the desired heights in a <code>headerHeightClass</code> inside a <code>computed</code> object but it doesn't seem to work.</p>
<pre class="lang-html prettyprint-override"><code><template>
<header :class="['w-full', 'text-sm', 'headerHeightClass']">
<div class="fixed top-0 left-0 w-full h-16 bg-white">
<!--Some irrelevant html code -->
</div>
</header>
</template>
</code></pre>
<pre class="lang-js prettyprint-override"><code><script>
export default {
name: "MainNav",
components: {},
data() {
return {
isLoggedIn: false,
};
},
computed: {
headerHeightClass() {
return {
"h-16": !this.isLoggedIn,
"h-32": this.isLoggedIn,
};
},
},
methods: {
loginUser() {
this.isLoggedIn = true;
},
},
};
</script>
</code></pre>
<p>I also tried:</p>
<pre class="lang-js prettyprint-override"><code>computed: {
headerHeightClass() {
return this.isLoggedIn? "h-32": "h-16",
},
},
</code></pre>
<p>The <code>headerHeightClass</code> appears as a simple string in the browser.</p>
| [
{
"answer_id": 74160317,
"author": "Silvio Mayolo",
"author_id": 2288659,
"author_profile": "https://Stackoverflow.com/users/2288659",
"pm_score": 4,
"selected": true,
"text": "sscanf"
},
{
"answer_id": 74160351,
"author": "Chris",
"author_id": 15261315,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305261/"
] |
74,160,315 | <pre><code>Set objShell = CreateObject("Wscript.Shell")
strFile ="Lafarrel.vbs"
dim fso, fullPath
set fso = CreateObject("Scripting.FileSystemObject")
fullPath = fso.GetAbsolutePathName(strFile)
Wscript.Echo fullPath
Wscript.Sleep 1000
dim SourceLocation
dim DestinationLocation
dim FileName
SourceLocation = fullPath
DestinationLocation = """C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"""
FileName = "Lafarrel.vbs"
fso.MoveFile SourceLocation & "" & FileName, DestinationLocation & ""
</code></pre>
<p>Error starts at line 14
Maybe because the last line is incorrect?</p>
<p>Explain what I want VBScript to do:
I want this VBScript to find itself and then change to a different directory</p>
| [
{
"answer_id": 74160538,
"author": "Dai",
"author_id": 159145,
"author_profile": "https://Stackoverflow.com/users/159145",
"pm_score": 3,
"selected": true,
"text": "Option Explicit"
},
{
"answer_id": 74194770,
"author": "Daz",
"author_id": 1013119,
"author_profile": "... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20304978/"
] |
74,160,329 | <p>I'm pretty new to C# and I have a project coming up. Recently, I've created another dummy project just to get this fact down. I'm just trying to get the user to input their name and for it to be displayed. Here's what I've got so far, which of course is not working. Some help would be greatly appreciated, even if this seems like a very dumb or basic question.</p>
<pre class="lang-cs prettyprint-override"><code>public class Employee
{
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string GetNames()
{
Console.WriteLine("Please enter your first name:");
firstName = Convert.ToString(Console.ReadKey());
return firstName;
}
public Employee()
{
firstName = this.firstName;
}
public static void Display(string firstName)
{
Console.WriteLine(firstName);
}
}
public class Program
{
static void Main(string[] args)
{
Employee employee = new Employee();
Console.Write(employee.FirstName);
}
}
</code></pre>
| [
{
"answer_id": 74160345,
"author": "Mishin870",
"author_id": 9630962,
"author_profile": "https://Stackoverflow.com/users/9630962",
"pm_score": 0,
"selected": false,
"text": "Console.WriteLine(\"Please enter your first name:\");\nfirstName = Console.ReadLine();\n"
},
{
"answer_id"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305266/"
] |
74,160,333 | <p>I have an fileuploader that has preview images for the files to be uploaded. There are frontend and backend validations that prevent more than 10 files being submitted in one upload.</p>
<p>What I would like to do is have it so when more than 10 files are attached, the preview images for anything over the 10th image are removed from the image previews (there are error messages currently outputted too). I have separate functionality regarding the actual FileList of files form the input element, but should be able to get the solution to work for both.</p>
<p>Below is a minimal code representation of the problem. If required I can show the full file uploader code, but there is quite a lot of code unrelated to this issue which may be confusing.</p>
<pre><code>// Generate a preview <img> for each selected file
// the submitData.files array is generated from a change event listener on a file input elment
[...submitData.files].forEach(showFiles);
});
function showFiles(file) {
let previewImage = new Image();
previewImage.className = "img upload-preview-image";
previewImage.src = URL.createObjectURL(file);
// use decode() method that waits for individual preview images to be added when running validations
previewImage.decode().then((response) => {
// validations happen here for each image as part of the showFiles() function called in the forEach loop above
let imgList = document.querySelectorAll('.upload-preview-image'), // redeclare under new var name inside promise
if (imgList.length > 10) {
/*** somehow remove all images from the imgList array after the 10th image,
either by deleting them or exiting this function when the 10th item is added ***/
}
}).catch((encodingError) => {
// Do something with the error.
});
}
</code></pre>
| [
{
"answer_id": 74160345,
"author": "Mishin870",
"author_id": 9630962,
"author_profile": "https://Stackoverflow.com/users/9630962",
"pm_score": 0,
"selected": false,
"text": "Console.WriteLine(\"Please enter your first name:\");\nfirstName = Console.ReadLine();\n"
},
{
"answer_id"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5219761/"
] |
74,160,344 | <p>I've spent hours on this one, and I'm still stuck. And the really baffling thing is, according to the Lua documentation, I shouldn't even be having this problem:</p>
<p><a href="https://www.lua.org/manual/5.1/manual.html#2.2.1" rel="nofollow noreferrer">https://www.lua.org/manual/5.1/manual.html#2.2.1</a></p>
<p>I've got the following Lua script:</p>
<pre><code>local takevol = tn(chunk:match("VOLPAN%s%d%s%d%s([+-]?%d*%.?%d*)"))
newchunk = string.gsub(chunk,"(\n%s*PT%s%d%s)([+-]?%d*%.?%d*)","%1"..takevol*tonumber("%2"))
</code></pre>
<p>The source I am working with is an item data chunk (string format) that looks like this (truncated for brevity):</p>
<pre><code>VOLPAN 1 0 15.848932 -1
SOFFS 365.84808854166607
PLAYRATE 0.25 0 0 -1 0 0.0025
CHANMODE 3
GUID {79C49752-9C32-D545-A54E-8CFFF9ACC14E}
<VOLENV
EGUID {92E4F259-A31C-0E49-81CB-B2C1ABA21CD4}
ACT 1 -1
VIS 1 1 1
LANEHEIGHT 0 0
ARM 0
DEFSHAPE 0 -1 -1
VOLTYPE 1
PT 0 1 0
>
>
</code></pre>
<p>Basically, I'm trying to get the volume value from the line starting <code>VOLPAN</code> (15.848932), multiply that with each second number captured from the lines starting <code>PT</code>, replacing the second number value in each <code>PT</code> line with the result, which, for this example, would come out like this:</p>
<pre><code>VOLPAN 1 0 15.848932 -1
SOFFS 365.84808854166607
PLAYRATE 0.25 0 0 -1 0 0.0025
CHANMODE 3
GUID {79C49752-9C32-D545-A54E-8CFFF9ACC14E}
<VOLENV
EGUID {92E4F259-A31C-0E49-81CB-B2C1ABA21CD4}
ACT 1 -1
VIS 1 1 1
LANEHEIGHT 0 0
ARM 0
DEFSHAPE 0 -1 -1
VOLTYPE 1
PT 0 15.848932 0
>
</code></pre>
<p>In this example, there is just one <code>PT</code> line. For some item chunks, there are dozens, which is why I chose gsub to iterate through them. And ultimately, I'll be processing anywhere from a few dozen to <em><strong>thousands</strong></em> of these items at a time.</p>
<p>Please help me. I'm really at a total loss on how to get the captured value from the <code>PT</code> lines into a number format that I can do the multiplication with. I've looked through Lua documentation, read through several semi-related forum posts/questions, and I've experimented with different ways of escaping the variable for the capture, trying to use a function and do the math outside of the gsub command, and a number of other things. But I still just keep getting errors, typically either "attempt to perform arithmetic on a nil value" or "attempt to perform arithmetic on a string value".</p>
<p>And, of course, based on the following excerpt from the manual (as linked above), it seems like performing arithmetic on a string value should normally work just fine in Lua.</p>
<blockquote>
<p>Lua provides automatic conversion between string and number values at
run time. Any arithmetic operation applied to a string tries to
convert this string to a number, following the usual conversion
rules.</p>
</blockquote>
| [
{
"answer_id": 74161554,
"author": "shingo",
"author_id": 6196568,
"author_profile": "https://Stackoverflow.com/users/6196568",
"pm_score": 3,
"selected": true,
"text": "newchunk = string.gsub(chunk,\"(\\n%s*PT%s%d%s)([+-]?%d*%.?%d*)\",\nfunction (a, b)\n return a..takevol*tonumber(b)... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7051766/"
] |
74,160,353 | <p>Matrix multiplication Y = A * B can be implemented by mul!(Y, A, B) to save on memory allocations. But mul! can't be used if Y = A. Is there a similarly efficient way to calculate Y *= B? Or if not, what is the most efficient way to do matrix multiplication Y *= B</p>
<p>Small working example:</p>
<pre><code>n = 10
A = rand(n,n)
B = rand(n,n)
Y = zeros(n,n)
#mul! removes allocations
@allocated Y = A * B #896
@allocated mul!(Y, A, B) #0
#mul! can't be applied in this case
@allocated Y *= B #896
#desired function performance
@allocated mul_2!(Y, B) #0
</code></pre>
<p>Thanks in advance for your help!</p>
| [
{
"answer_id": 74170326,
"author": "Dan Getz",
"author_id": 3580870,
"author_profile": "https://Stackoverflow.com/users/3580870",
"pm_score": 1,
"selected": false,
"text": "mul_2!"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4167240/"
] |
74,160,365 | <p>I'm parsing the zabix configuration file to get the variables, this can be done in separate tasks, but I want to do it in one. I need to put the output of a command into a dictionary. How to register this vars from file?</p>
<p>ROLE</p>
<pre><code># tasks file for roles/test
- name: Read vars
shell: egrep -v -e "^#|^$" /etc/zabbix/zabbix_agentd.conf
register: zbaconfig
- name: Debug 1
debug:
msg:
- "{{ zbaconfig.stdout_lines }}"
- name: Register vars
set_fact:
zba: "{{ dict(zbaconfig.stdout | split('\\n') | select() | map('split','=') | list) }}"
- name: Debug 2
debug:
msg:
- "{{ zba.Hostname }}"
- "{{ zba.ServerActive }}"
- "{{ zba.Server }}"
</code></pre>
<p>STDOUT</p>
<pre><code>TASK [test : Debug 1]
ok: [10.100.0.52] => {
"msg": [
[
"PidFile=/run/zabbix/zabbix_agentd.pid",
"LogFile=/var/log/zabbix/zabbix_agentd.log",
"LogFileSize=0",
"Server=zabbix.domain.com.ua",
"ServerActive=zabbix.domain.com.ua",
"Hostname=vs-net-dk01",
"Include=/etc/zabbix/zabbix_agentd.d/*.conf"
],
TASK [test : Register vars]
fatal: [10.100.0.52]: FAILED! => {"msg": "template error while templating string: no filter named 'split'. String: {{ dict(zbaconfig.stdout | split('\n') | select() | map('split','=') | list) }}"}
</code></pre>
| [
{
"answer_id": 74162176,
"author": "Frenchy",
"author_id": 7380779,
"author_profile": "https://Stackoverflow.com/users/7380779",
"pm_score": 1,
"selected": false,
"text": "split"
},
{
"answer_id": 74175340,
"author": "Vladimir Botka",
"author_id": 6482561,
"author_pro... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13815204/"
] |
74,160,374 | <p>I installed Laravel 8 with backpack 5.1 and I run <code>php artisan backpack:crud-operation SendNotification</code> I got error:</p>
<pre><code>root@9139092f4397:/var/www/khm-hrms# php artisan backpack:crud-operation SendNotification
BadMethodCallException
Method Illuminate\Support\Stringable::lcfirst does not exist.
at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:113
109▕ */
110▕ public function __call($method, $parameters)
111▕ {
112▕ if (! static::hasMacro($method)) {
➜ 113▕ throw new BadMethodCallException(sprintf(
114▕ 'Method %s::%s does not exist.', static::class, $method
115▕ ));
116▕ }
117▕
• Bad Method Call: Did you mean Illuminate\Support\Stringable::ucfirst() ?
+16 vendor frames
17 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
</code></pre>
<p>Does anyone know what the issue might be ? I cannot find a solution online.</p>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10077868/"
] |
74,160,408 | <p>I cannot get this code to execute in Snowflake SQL. The error message is PRIOR keyword is missing in Connect By statement. (line 5)</p>
<p>Any ideas?</p>
<pre><code>select associate_id, position_effective_date, home_department_code,
most_recent_record, (last_day(date_from_parts(year(current_date()),
month(current_date())-Q_LEVEL,1),month)) AS month
from(
WITH Q AS (SELECT LEVEL Q_LEVEL FROM DUAL A CONNECT BY LEVEL <= 36)
select Q.Q_LEVEL Q_LEVEL, v_dept_history_adj.associate_id,
v_dept_history_adj.home_department_code,
v_dept_history_adj.position_effective_date, max(position_effective_date)
OVER(PARTITION BY v_dept_history_adj.associate_id) AS most_recent_record
from src_table, Q
where v_dept_history_adj.position_effective_date <=
last_day(date_from_parts(year(current_date()),
month(current_date())-Q.Q_LEVEL,1),month))
where position_effective_date = most_recent_record
order by month desc, position_effective_date desc
</code></pre>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10259871/"
] |
74,160,421 | <p>I have a code base that is running on two separate app services. The first is logging fine with version 6.0.8 of the ASP.NET Core Logging Integration. The second which has ASP.NET Core Logging Integration 7.0.0-rc-2-22476-2 is not working. I get the following error when the web service starts:</p>
<pre><code>2022-10-25T21:07:05 sandboxproc.exe D:\DWASFiles\Sites\teams1stdevelopment\Temp\applicationhost.config True True
2022-10-25T21:07:05 env XPROC_TYPENAME=Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper, Microsoft.Web.Hosting, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
2022-10-25T21:07:05 env XPROC_METHODNAME=Transform
2022-10-25T21:07:05 Start 'Microsoft.AspNetCore.AzureAppServices.SiteExtension' site extension transform
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 7, 23)
2022-10-25T21:07:05 on /configuration/system.webServer
2022-10-25T21:07:05 Applying to 'configuration' element (no source line info)
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 8, 16)
2022-10-25T21:07:05 on /configuration/system.webServer/runtime
2022-10-25T21:07:05 Applying to 'system.webServer' element (no source line info)
2022-10-25T21:07:05 Inserted 'runtime' element
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 9, 31)
2022-10-25T21:07:05 on /configuration/system.webServer/runtime/environmentVariables
2022-10-25T21:07:05 Applying to 'runtime' element (no source line info)
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 :(10,406), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 :(11,158), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 :(12,146), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 Fail 'Microsoft.AspNetCore.AzureAppServices.SiteExtension' site extension transform
2022-10-25T21:07:05 sandboxproc.exe Elapsed = 426.00 ms failed with System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Fail transforming applicationHost.config with 'C:\home\SiteExtensions\Microsoft.AspNetCore.AzureAppServices.SiteExtension\applicationHost.xdt' with :(10,406), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext):(11,158), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext):(12,146), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionDefinition.Transform(XmlDocument document, IDictionary`2 environments, Boolean isMainSite, Boolean separateProcessForScm)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper.Transform(XmlDocument doc, List`1 definitions, IDictionary`2 environments, Boolean isMainSite, Boolean separateProcessForScm)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper.Transform(String appHostConfig, String isMainSiteStr, String separateProcessForScmStr)--- End of inner exception stack trace ---at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)at Microsoft.Web.Hosting.ProcessModel.Program.Main(String[] args)
</code></pre>
<p>Installed Packages:</p>
<p><a href="https://i.stack.imgur.com/x9A6d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9A6d.png" alt="Packages" /></a></p>
<pre><code> // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Azure.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
namespace Microsoft.BotBuilderSamples
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
config.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureLogging((logging) =>
{
logging.AddDebug();
logging.AddConsole();
});
webBuilder.UseStartup<Startup>();
});
}
}
</code></pre>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11854411/"
] |
74,160,426 | <p>Is there a way to change the Youtube flutter Flags after first init.</p>
<p>I am trying to make it so that upon clicking a button to a new video it changes video and then also sets the Flags startAt and endAt to my chosen ints.</p>
<p>However <code>controller.flags.startAt</code> and the end at come up with the error "can't be used as a setter because it's final.</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>_ytController = YoutubePlayerController(
initialVideoId: YoutubePlayer.convertUrlToId(defaultStream)!,
flags: const YoutubePlayerFlags(
mute: false,
loop: true,
autoPlay: true,
));
_ytController.startAt = 20; //doesn't allow due to final
_ytController.endAt = 30;</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18076231/"
] |
74,160,442 | <p>This goes back to a question I've asked some time ago - I'm still struggling in the same area.</p>
<p>I have a data.table with some values ('value'), lower limits ('min_val') and upper limits ('max_val'):</p>
<pre><code> | value | min_val | max_val |
1: | 94.001 | 94.00 | 94.02 |
2: | 94.002 | 94.00 | 94.03 |
3: | 94.003 | 94.01 | 94.04 |
4: | 95 | 94.98 | 95.02 |
5: | 100.00 | 99.00 | 101.00 |
6: | 100.10 | 99.10 | 101.00 |
7: | 200.00 | 199.00 | 201.00 |
8: | 200.10 | 199.00 | 201.00 |
</code></pre>
<p>With your help I have the count:</p>
<pre><code> | value | min_val | max_val | count | id |
1: | 94.001 | 94.00 | 94.02 | 1 | 1 |
2: | 94.002 | 94.00 | 94.03 | 2 | 2 |
3: | 94.003 | 94.01 | 94.04 | 2 | 2 |
4: | 95 | 94.98 | 95.02 | 1 | 3 |
5: | 100.00 | 99.00 | 101.00 | 2 | 4 |
6: | 100.10 | 99.10 | 101.00 | 2 | 4 |
7: | 200.00 | 199.00 | 201.00 | 2 | 5 |
8: | 200.10 | 199.00 | 201.00 | 2 | 5 |
</code></pre>
<p>Now I want to uniquely identify (col id) each "count group" so that I can use the identified later on (by=id).
I've tried calculating the mean of 'value' column hoping I'll get unique identifiers but the mean function returns 1/count. Not sure how to proceed - I'm stuck as I don't understand how to "go backwards" while doing the computations (example: for 94.003, I need to compare the next element of column value to it and also the previous element):</p>
<pre><code>dat[, count := mapply(function(mi,ma) mean(mi < value & value < ma), min_val, max_val)]
</code></pre>
<p>input:</p>
<pre><code> library(data.table)
dat <- setDT(structure(list(value = c(94.01, 94.02, 94.03, 95, 100, 100.1, 200, 200.1), min_val = c(94, 94, 94.01, 94.98, 99, 99.1, 199, 199), max_val = c(94.02, 94.03, 94.04, 95.02, 101, 101, 201, 201)), class = c("data.table", "data.frame"), row.names = c(NA, -4L)))
dat[, count := mapply(function(mi,ma) sum(mi < value & value < ma), min_val, max_val)]
</code></pre>
<p>I'm struggling with this for a few days. The only thing I could think of is that I need to modify the method that does the count so that I do the marking the same way. I did not find a solution. I use this method to generate the count</p>
<pre><code>dat[, count := mapply(function(mi,ma) sum(mi < value & value < ma), min_val, max_val)]
</code></pre>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10843657/"
] |
74,160,451 | <p>I created a frosted AppBar has a SafeArea wrapping. I want a scrollview that scrolls under it, but i'm unable to code a variable padding that adds the SafeArea of the AppBar to the top padding of the SingleChildScrollView. Does anyone have any tips? My appbar is at <code>appbar:</code>. The code for the body Scaffold follows bellow:</p>
<pre><code>home: Scaffold(
backgroundColor: const Color(0xFFF6FFF1),
extendBody: true,
extendBodyBehindAppBar: true,
// Body
body: SingleChildScrollView(
padding:
EdgeInsets.only(top: 90, left: 10, right: 10, bottom: 8),
child: Text(
lorem(paragraphs: 4, words: 480),
),
),
appBar: FrostedAppBar(
actions: [
IconButton(
icon: Icon(
Icons.help_outline_rounded,
color: lightColorScheme.tertiary,
shadows: const [
Shadow(
color: Colors.black,
blurRadius: 2,
offset: Offset(1, 2))
],
),
onPressed: null,
iconSize: 40,
)
],
title: Text(
'Title',
style: GoogleFonts.racingSansOne(
fontSize: 40, color: lightColorScheme.primary),
textAlign: TextAlign.center,
),
leading: IconButton(
icon: Icon(
Icons.menu_rounded,
color: lightColorScheme.tertiary,
shadows: const [
Shadow(
color: Colors.black, blurRadius: 2, offset: Offset(1, 2))
],
),
iconSize: 40,
onPressed: null,
),
),
</code></pre>
<p><a href="https://i.stack.imgur.com/pcQ1o.jpg" rel="nofollow noreferrer">Example of why I need variable padding</a></p>
<p><a href="https://i.stack.imgur.com/2nqDs.jpg" rel="nofollow noreferrer">Scaffold body content going under the appbar and being blurred by it</a></p>
<p>Thank you very much for your time!!!</p>
| [
{
"answer_id": 74161054,
"author": "Hefaz",
"author_id": 11273483,
"author_profile": "https://Stackoverflow.com/users/11273483",
"pm_score": 1,
"selected": false,
"text": "lcfirst"
},
{
"answer_id": 74184452,
"author": "Pedro X",
"author_id": 5622309,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305379/"
] |
74,160,495 | <p>I remember working on a project made in Django where you could create routes that could be given a prefix and then include another URL file for the rest of the endpoint.</p>
<pre class="lang-py prettyprint-override"><code>api_patterns= [
url('foo/', include(foo.urls)),
url('bar/', include(bar.urls)),
]
urlpatterns = [
url(r'api/', include(api_patterns)),
]
</code></pre>
<p>This implementation would result in endpoints <code>/api/foo/</code> and <code>/api/bar/</code> and these endpoints would live in separate directories with separate url files.</p>
<h1>The question is whether we can implement something equivalent to <strong>Spring Boot</strong>.</h1>
<p>I know you can add the prefix to the <code>@RequestMapping</code> on all the files.
But in my current project, we have a lot of controllers that start from the same route prefix and then, later on, differ from each other.</p>
<pre class="lang-java prettyprint-override"><code>// Foo controller
@Controller
@RequestMapping(path = "api/foo")
public class FooController {
@GetMapping(path = "")
// Endpoint to /api/foo
}
// Bar controller
@Controller
@RequestMapping(path = "api/bar")
public class BarController {
@GetMapping(path = "")
// Endpoint to /api/bar
}
// Tar controller by foo
@Controller
@RequestMapping(path = "api/foo/tar")
public class TarController {
@GetMapping(path = "")
// Endpoint to /api/foo/tar
}
</code></pre>
<p>The endpoint would then look like this <code>/api/foo</code>, <code>/api/bar</code>, and <code>/api/foo/tar</code>.</p>
<p>How can I prevent the repeated path prefix on all the files?</p>
<p><em>This routing might be a bad practice for working with API endpoint, I also think that this could be prevented, and that is why I'm asking as a junior developer to try to improve and show responsibility at my first job.</em></p>
| [
{
"answer_id": 74162119,
"author": "Kirill",
"author_id": 11984002,
"author_profile": "https://Stackoverflow.com/users/11984002",
"pm_score": 0,
"selected": false,
"text": "@RequestMapping(path = \"/api/foo\")"
},
{
"answer_id": 74162411,
"author": "Soumen Ghosh",
"author... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11809608/"
] |
74,160,509 | <p>I'm trying to print the last message from WinApi to the console. Sounds simple, or so I thought. I made this simple enough function, but I'm getting an error code 8 (ERROR_NOT_ENOUGH_MEMORY). I'm not sure how this could be. I didn't find anything online either. Here's what I've got:</p>
<pre><code>static inline void printLastMessage()
{
LPTSTR lpMsgBuf;
if(FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS), NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), lpMsgBuf, 0, NULL) == 0)
{
printf("Error Code: %d\n", GetLastError());
}
wprintf(L"Error: %s\n", lpMsgBuf);
LocalFree(lpMsgBuf);
}
</code></pre>
<p>The resulting buffer looks like this in the console:</p>
<pre><code>Error: (null)
</code></pre>
<p>I've also tried FormatMessageW, but it didn't make a difference. (And it seems like FormatMessage is defined as FormatMessageW with UNICODE)</p>
<p>I'm using MinGW's GCC with C11, Windows SDK 10.0.22621.</p>
<p>Edit: Updated (LPTSTR)&lpMsgBuf. Current code:</p>
<pre><code>static inline void printLastMessage()
{
LPTSTR lpMsgBuf;
DWORD err = GetLastError();
printf("Error code: %d\n", err);
if(FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS), NULL,
err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL) == 0)
{
printf("Error Code (FormatMessage): %d\n", GetLastError());
}
wprintf(L"Error: %s\n", lpMsgBuf);
LocalFree(lpMsgBuf);
}
</code></pre>
<p>And output:</p>
<pre><code>Error code: 87
Error:
</code></pre>
| [
{
"answer_id": 74162119,
"author": "Kirill",
"author_id": 11984002,
"author_profile": "https://Stackoverflow.com/users/11984002",
"pm_score": 0,
"selected": false,
"text": "@RequestMapping(path = \"/api/foo\")"
},
{
"answer_id": 74162411,
"author": "Soumen Ghosh",
"author... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7555282/"
] |
74,160,529 | <p>In Django, I'm trying to use <strong><code>\dt</code></strong> in <strong><code>cursor.execute()</code></strong> to get the tables in PostgreSQL as shown below:</p>
<pre class="lang-py prettyprint-override"><code># "views.py"
from django.http import HttpResponse
from django.db import connection
def test(request):
cursor = connection.cursor()
cursor.execute('''\dt''') # Here
row = cursor.fetchone()
print(row)
return HttpResponse("Test")
</code></pre>
<p>But, I got the error below:</p>
<blockquote>
<p>django.db.utils.ProgrammingError: syntax error at or near "\"<br />
LINE 1: \dt</p>
</blockquote>
<p>So, I replaced <strong><code>cursor.execute('''\dt''')</code></strong> with <strong><code>cursor.execute('''\\dt''')</code></strong> as shown below:</p>
<pre class="lang-py prettyprint-override"><code># "views.py"
from django.http import HttpResponse
from django.db import connection
def test(request):
# ...
cursor.execute('''\\dt''') # Here
# ...
return HttpResponse("Test")
</code></pre>
<p>But, I still got the error below:</p>
<blockquote>
<p>django.db.utils.ProgrammingError: syntax error at or near "\"<br />
LINE 1: \dt</p>
</blockquote>
<p>So, how do I use <strong><code>\dt</code></strong> in <code>cursor.execute()</code> to get the tables in PostgreSQL?</p>
| [
{
"answer_id": 74160878,
"author": "Pavel Stehule",
"author_id": 406691,
"author_profile": "https://Stackoverflow.com/users/406691",
"pm_score": 1,
"selected": false,
"text": "\\dt"
},
{
"answer_id": 74160900,
"author": "Eduardo Tolmasquim",
"author_id": 6871685,
"aut... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8172439/"
] |
74,160,552 | <p>I am trying to display a file on tap of button. But before the file loads, I want the circular progress indicator to start and after the file loads, I want it to stop. I have implemented the following code but the problem is the indicator keeps on loading even after file loads.</p>
<pre><code> InkWell(
onTap: () async {
player.stop();
Center(
child: CircularProgressIndicator(),
);
final files = await loadPdfFromNetwork(file.url);
openPdf(context, files, file.url,file.name.split('.').first);
}
</code></pre>
| [
{
"answer_id": 74161101,
"author": "Desmond",
"author_id": 13859889,
"author_profile": "https://Stackoverflow.com/users/13859889",
"pm_score": 1,
"selected": false,
"text": "onTap: () async {\n player.stop();\n\n\n\n Center(\n child: CircularProgressIndicator(),\n ... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19499418/"
] |
74,160,593 | <p>I am unable to understand why the code is not showing any error when I try:</p>
<pre><code>x = 2
def foo():
global x
del x
x = 3
foo()
print(x)
</code></pre>
<p>Output: <code>3</code></p>
<p>I was expecting that <code>del x</code> would delete the reference to <code>2</code> and thus, <em>there will not be any global variable</em>, keeping the reference to <code>3</code> locally (accessible only within the function and not outside it).</p>
<p>Can someone explain what's incorrect with my understanding of <code>global</code> and/or <code>del</code>?</p>
| [
{
"answer_id": 74160613,
"author": "Joran Beasley",
"author_id": 541038,
"author_profile": "https://Stackoverflow.com/users/541038",
"pm_score": 3,
"selected": true,
"text": "import dis\nprint(dis.dis(foo))\n"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7789963/"
] |
74,160,602 | <p>I have a list of key binds in a class like so:</p>
<pre><code>self.key_bind_list = [["A", "B"], ["C"], ["SHIFT", "NUM6", "NUM7"], ["A", "B"], ["A", "B", "C"]]
</code></pre>
<p>*in this case a duplicate should be detected by the sublists <code>["A", "B"]</code>, but not by <code>["A", "B"]</code> and <code>["A", "B", "C"]</code></p>
<p>And I'd like to check if there are any duplicates on the main list (assuming that the keys within each sublist are uniques, order is not important, and I don't need to know which ones that aren't unique)</p>
<p>I've tried using the <strong>set</strong> method in the following:</p>
<pre><code>if(len(self.key_bind_list) != len(set(self.key_bind_list))):
</code></pre>
<p>Which gave me a <code>unhashable type: 'list'</code> error.</p>
| [
{
"answer_id": 74160613,
"author": "Joran Beasley",
"author_id": 541038,
"author_profile": "https://Stackoverflow.com/users/541038",
"pm_score": 3,
"selected": true,
"text": "import dis\nprint(dis.dis(foo))\n"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17392401/"
] |
74,160,611 | <p>I have a PySpark dataframe:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>userid</th>
<th>sku</th>
<th>action</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>2345</td>
<td>2</td>
</tr>
<tr>
<td>123</td>
<td>2345</td>
<td>0</td>
</tr>
<tr>
<td>123</td>
<td>5422</td>
<td>0</td>
</tr>
<tr>
<td>123</td>
<td>7622</td>
<td>0</td>
</tr>
<tr>
<td>231</td>
<td>4322</td>
<td>2</td>
</tr>
<tr>
<td>231</td>
<td>4322</td>
<td>0</td>
</tr>
<tr>
<td>231</td>
<td>8342</td>
<td>0</td>
</tr>
<tr>
<td>231</td>
<td>5342</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
<p>The output should be like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>userid</th>
<th>sku_pos</th>
<th>sku_neg</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td>2345</td>
<td>5422</td>
</tr>
<tr>
<td>123</td>
<td>2345</td>
<td>7622</td>
</tr>
<tr>
<td>231</td>
<td>4322</td>
<td>8342</td>
</tr>
<tr>
<td>231</td>
<td>4322</td>
<td>5342</td>
</tr>
</tbody>
</table>
</div>
<p>For each distinct "userid" the "sku" which don't have an "action" > 0 will go to column "sku_neg", while the "sku" which has an "action" > 0 will go to column "sku_pos".</p>
| [
{
"answer_id": 74160613,
"author": "Joran Beasley",
"author_id": 541038,
"author_profile": "https://Stackoverflow.com/users/541038",
"pm_score": 3,
"selected": true,
"text": "import dis\nprint(dis.dis(foo))\n"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4435573/"
] |
74,160,637 | <p>I am writing a text based adventure game in a batch file.</p>
<p>Long story short, I want the program to convert a sentence the user types into the game from the first person into the second person, by simply replacing singular pronouns such as 'I' with 'You.'</p>
<p>So a person says: I search inside the box.
The program says: You search inside the box.</p>
<p>For this I'm using this script where 'choice' contains the user's entry.</p>
<pre><code>set choice=%choice:i=you%
set choice=%choice:we=you%
set choice=%choice:us=you%
set choice=%choice:my=your%
set choice=%choice:myself=yourself%
set choice=%choice:ourselves=yourselves%
set choice=%choice:am=are%
set choice=%choice:I'm=you're%
set choice=%choice:I am=you are%
</code></pre>
<p>However, every instance of 'I' is replaced.
So when you type: I search inside the box.
You get: You search younsyoude the box.</p>
<p>How do I tell the program to only replace an exact phrase (including spaces.)
I want to try and avoid using powershell if at all possible. Otherwise, I'm not opposed to ideas.</p>
| [
{
"answer_id": 74161080,
"author": "Magoo",
"author_id": 2128947,
"author_profile": "https://Stackoverflow.com/users/2128947",
"pm_score": 0,
"selected": false,
"text": "@ECHO OFF\nSETLOCAL ENABLEDELAYEDEXPANSION\nrem The following settings for the source directory and filename are names... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10361770/"
] |
74,160,646 | <pre><code>def konversi(j=0):
def minute(m=0):
def secon(d=0):
return ((j*60)+m)*60+d
return secon
return minute
data = "05:33:05"
data_split = data.split(':')
print("data = ",data)
print("data split = ",data_split)
</code></pre>
<p>i'm confuse how to append a value 'day' into fungsion</p>
<pre><code>hours = int(data_split[0])
minutes = int(data_split[1])
second = int(data_split[2])
print("Hours = ", hours)
print("minute = ", minutes)
print("second = ", second)
konvert = konversi(hours)(minutes)(second)
print("Result konversi = ", konvert) #19985
</code></pre>
<p>i would like to change data variable from string to list
and change the data to like this</p>
<pre><code>data = ["21 day 20 hour 9 minute 20 sec",
"19 day 14 hour 0 minute 13 sec",
"1 day 1 hour 1 minute 1 sec"]
</code></pre>
| [
{
"answer_id": 74163257,
"author": "bitflip",
"author_id": 20027803,
"author_profile": "https://Stackoverflow.com/users/20027803",
"pm_score": 1,
"selected": false,
"text": "data = [\"21 day 20 hour 9 minute 20 sec\",\n \"19 day 14 hour 0 minute 13 sec\",\n \"1 day 1 hour 1... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19534824/"
] |
74,160,675 | <p>Alright... I've been stuck on this for a while</p>
<p>I'm trying to grab the count of the each leader's(leaderDisplay) dateExit value that equals === "" and store it into an array</p>
<p>The output im trying to get is something like ['Albert Owens','Tina Snow','Rick Sanchez'] [2,1,2]</p>
<p>This is where I've gotten so far and I'm pretty sure i'm over thinking it...</p>
<pre><code>
const data = [
{
fieldData: {
dateExit: "",
dateHire: "06/14/2004",
leaderDisplay: "Tina Snow",
},
},
{
fieldData: {
dateExit: "",
dateHire: "06/14/2004",
leaderDisplay: "Rick Sanchez",
},
},
{
fieldData: {
dateExit: "",
dateHire: "06/14/2004",
leaderDisplay: "Albert Owens",
},
},
{
fieldData: {
dateExit: "07/14/2006",
dateHire: "06/14/2004",
leaderDisplay: "Tina Snow",
},
},
{
fieldData: {
dateExit: "",
dateHire: "06/14/2004",
leaderDisplay: "Albert Owens",
},
},
{
fieldData: {
dateExit: "07/14/2006",
dateHire: "06/14/2004",
leaderDisplay: "Rick Sanchez",
},
},
{
fieldData: {
dateExit: "",
dateHire: "06/14/2004",
leaderDisplay: "Rick Sanchez",
},
},
];
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
const allExit = data.map(function (e) {
return e.fieldData.dateExit;
});
const dateExits = allExit.filter(onlyUnique);
const allSupervisors = data.map(function (e) {
return e.fieldData.leaderDisplay;
});
const supervisors = allSupervisors.filter(onlyUnique);
let array = [];
let countArr = [];
let textColors = [];
supervisors.forEach(function (f, i) {
let count = 0;
if (f != "") {
let stat = f;
if (stat == "") {
countArr.push(count);
}
let obj = {
name: stat,
};
let keysArr = [];
let statArr = [];
supervisors.forEach(function (e, i) {
let sup = e;
let list = data
.filter(function (e) {
return (
e.fieldData.leaderDisplay === sup &&
e.fieldData.dateExit === ""
);
})
.map(function (e) {
return e.fieldData.ID;
});
statArr.push(list.length);
keysArr.push(list);
});
if (Array.isArray(statArr) && statArr.length > 0) {
obj.data = statArr;
obj.keys = keysArr;
}
obj.keys;
array.push(obj);
return array;
}
return array;
});
const categories = supervisors;
const series = array;
</code></pre>
| [
{
"answer_id": 74160716,
"author": "Nick",
"author_id": 9473764,
"author_profile": "https://Stackoverflow.com/users/9473764",
"pm_score": 2,
"selected": false,
"text": "reduce"
},
{
"answer_id": 74160718,
"author": "Tibrogargan",
"author_id": 2487517,
"author_profile"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19096052/"
] |
74,160,688 | <p>I typed the following SQL code in <a href="https://www.db-fiddle.com/" rel="nofollow noreferrer">DB Fiddle</a> using PostgreSQL v14 as the database engine to create the QUESTION relation.</p>
<pre><code>CREATE TABLE QUESTION
(
ID TEXT PRIMARY KEY,
SurveyScreenID TEXT,
QuestionNumber INT,
QuestionText TEXT
);
INSERT INTO QUESTION (ID, SurveyScreenID, QuestionNumber, QuestionText) VALUES
('dvif_s1_q1','dvif_s1',1,'How many vegetables did you eat today?'),
('dvif_s1_q2','dvif_s1',2,'What was the tastiest?'),
('dvif_s1_q3','dvif_s1',3,'What was the least tasty?'),
('dfif_s1_q1','dfif_s1',1,'How much fruit did you eat today?'),
('dfif_s1_q2','dfif_s1',2,'What was the tastiest?'),
('dfif_s1_q3','dfif_s1',3,'What was the least tasty?'),
('dfif_s2_q1','dfif_s2',1,'How many pieces were underripe?'),
('dfif_s2_q2','dfif_s2',2,'How many pieces were rotten?'),
('dfif_s3_q1','dfif_s3',1,'Would you recommend eating fruit to a friend?'),
('dfif_s3_q2','dfif_s3',2,'Why or why not?'),
('dnif_s1_q1','dnif_s1',1,'How many nuts did you eat today?'),
('dnif_s1_q2','dnif_s1',2,'What was the tastiest?'),
('dnif_s1_q3','dnif_s1',3,'What was the most disgusting?'),
('dnif_s3_q1','dnif_s3',1,'Would you recommend eating nuts to a friend?'),
('dnif_s3_q2','dnif_s3',2,'If yes, why, and if no, why not?');
</code></pre>
<p>I wrote the following SQL query to find the ID of the question with the longest text:</p>
<pre><code>SELECT ID
FROM QUESTION
WHERE length(QuestionText) = MAX(length(QuestionText));
</code></pre>
<p>However, the program returned a query error saying</p>
<blockquote>
<p>Query error: aggregate functions are not allowed in WHERE</p>
</blockquote>
<p>How can I solve this issue?</p>
| [
{
"answer_id": 74160723,
"author": "Deepstop",
"author_id": 11606193,
"author_profile": "https://Stackoverflow.com/users/11606193",
"pm_score": 2,
"selected": false,
"text": "SELECT ID, questiontext\n FROM question\n WHERE length(questiontext) =\n (SELECT max(length(question... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13602940/"
] |
74,160,697 | <p>I have a query output like that. I want to have N3 column is the distinct merge of N1 and N2.
<a href="https://i.stack.imgur.com/5J2qA.png" rel="nofollow noreferrer">Query output example</a></p>
<p>My current query is this:</p>
<pre><code>SELECT rd.cId
, rd.dId
,ARRAY_AGG(ei.IncentiveName IGNORE NULLS) AS N1
,ARRAY_AGG(ai.IncentiveName IGNORE NULLS) AS N2
FROM rd
join ei on...
join ai on ...
GROUP BY rd.cId, rd.dId
</code></pre>
| [
{
"answer_id": 74162188,
"author": "Samuel",
"author_id": 16529576,
"author_profile": "https://Stackoverflow.com/users/16529576",
"pm_score": 0,
"selected": false,
"text": "array_concat"
},
{
"answer_id": 74216865,
"author": "Mikhail Berlyant",
"author_id": 5221944,
"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10072393/"
] |
74,160,700 | <p>I'm trying to call a widget inside the other, recursively, I tried to illustrate what I want to do in the image below.
Does anyone know how I can do this?
Below is an example of what I'm trying to do.
<a href="https://i.stack.imgur.com/HYgbc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HYgbc.png" alt="enter image description here" /></a></p>
<pre><code>Widget createScreen() {
return SingleChildScrollView(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () {
setState(() {
_i++;
});
},
child: const Text('Buttom +'),
),
TextButton(
onPressed: () {
setState(() {
_i--;
});
},
child: const Text('Buttom -'),
),
],
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: _i,
itemBuilder: (BuildContext ctxt, int index) {
return Container(
margin: EdgeInsets.all(10),
color: Colors.blueGrey[500],
height: 100,
// child: createScreen(), //here I tried to call the function inside itself
);
},
),
],
),
);
}
</code></pre>
| [
{
"answer_id": 74162188,
"author": "Samuel",
"author_id": 16529576,
"author_profile": "https://Stackoverflow.com/users/16529576",
"pm_score": 0,
"selected": false,
"text": "array_concat"
},
{
"answer_id": 74216865,
"author": "Mikhail Berlyant",
"author_id": 5221944,
"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15784561/"
] |
74,160,764 | <p>I have the following list <code>a</code> with <code>None</code> values for which I want to make a "fill down".</p>
<pre><code>a = [
['A','B','C','D'],
[None,None,2,None],
[None,1,None,None],
[None,None,8,None],
['W','R',5,'Q'],
['H','S','X','V'],
[None,None,None,7]
]
</code></pre>
<p>The expected output would be like this:</p>
<pre><code>b = [
['A','B','C','D'],
['A','B',2,'D'],
['A',1,'C','D'],
['A','B',8,'D'],
['W','R',5,'Q'],
['H','S','X','V'],
['H','S','X',7]
]
</code></pre>
<p>I was able to make the next code and seems to work but I was wondering if there is a built-in method or more direct
way to do it. I know that there is something like that using pandas but needs to convert to dataframe, and I want
to continue working with list, if possible only update <code>a</code> list, and if not possible to modify <code>a</code> then get output in <code>b</code> list. Thanks</p>
<pre><code>b = []
for z in a:
if None in z:
b.append([temp[i] if value == None else value for i, value in enumerate(z) ])
else:
b.append(z)
temp = z
</code></pre>
| [
{
"answer_id": 74160838,
"author": "bn_ln",
"author_id": 10535824,
"author_profile": "https://Stackoverflow.com/users/10535824",
"pm_score": 3,
"selected": true,
"text": "b = [a[0]]\nfor a_row in a[1:]:\n b.append([i if i else j for i,j in zip(a_row, b[-1])])\n"
},
{
"answer_i... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19506623/"
] |
74,160,772 | <p>I have my custom annotation like this:</p>
<pre class="lang-java prettyprint-override"><code>@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface CutomAnnotation{
String value() default "";
}
</code></pre>
<p>My aspect class looks like this:</p>
<pre class="lang-java prettyprint-override"><code>@Aspect
@Component
public class MyCustomAspect{
@Around("@annotation(com.forceframework.web.handlers.monitoring.MeterRegTimer)")
public Object aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable{
System.out.println("Timer started: "+joinPoint.getSignature());
Object objToReturn=joinPoint.proceed();
System.out.println("Timer ended: "+joinPoint.getSignature());
return objToReturn;
}
}
</code></pre>
<p>The place I use the annotation in a controller class:</p>
<pre class="lang-java prettyprint-override"><code>@CustomAnnotation(value="timer")
@GetMapping(value="/test")
public ResponseEntity test() {}
</code></pre>
<p>I would like to know can I access the <code>value</code> passed from my <code>CustomAnnotation</code> in the around advice method <code>aroundJoinPoint</code> in <code>MyCustomAspect</code> class.</p>
| [
{
"answer_id": 74161365,
"author": "birca123",
"author_id": 10231374,
"author_profile": "https://Stackoverflow.com/users/10231374",
"pm_score": 1,
"selected": false,
"text": "@Around(\"@annotation(customAnnotationArgumentName)\")\npublic Object aroundJoinPoint(ProceedingJoinPoint joinPoi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18078409/"
] |
74,160,798 | <p>I'm debugging a reverted transaction on Polygon and this is all the information I have: <a href="https://mumbai.polygonscan.com/tx/0xfa86dc4957e3a3da9298b7672b11a20ebe921854fa494dc073920c067c1e693f#internal" rel="nofollow noreferrer">https://mumbai.polygonscan.com/tx/0xfa86dc4957e3a3da9298b7672b11a20ebe921854fa494dc073920c067c1e693f#internal</a></p>
<p>If I'm reading it correctly, it seems to be saying that a <code>CREATE2</code> reverted. But what are some reasons why a <code>CREATE2</code> can revert? I'm aware that it would revert if something already existed at the address, but this isn't the case here, as you can see from here: <a href="https://mumbai.polygonscan.com/address/0x6bb03ca906c0372f384b845bd5ce9ca4327ffbe6" rel="nofollow noreferrer">https://mumbai.polygonscan.com/address/0x6bb03ca906c0372f384b845bd5ce9ca4327ffbe6</a></p>
| [
{
"answer_id": 74161365,
"author": "birca123",
"author_id": 10231374,
"author_profile": "https://Stackoverflow.com/users/10231374",
"pm_score": 1,
"selected": false,
"text": "@Around(\"@annotation(customAnnotationArgumentName)\")\npublic Object aroundJoinPoint(ProceedingJoinPoint joinPoi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1563568/"
] |
74,160,804 | <p>I have a dataframe in pandas that originally had a parsed date column with values such as: <code>2020-05-11 02:23:00</code>. <br></p>
<p>From that I created a 'Date' column using <code>df['Date'] = df.parsed_date_column.dt.date</code> producing values eg <code>2020-05-11</code> with datatype 'object'. <br></p>
<p>From there I wanted to only retain the rows from a certain date, i.e. <code>df.loc[df['Date'] == '2021-06-26']</code> or more simply <code>df[df['Date'] == '2021-06-26']</code>. <br>
Whenever I execute this, it returns an empty dataframe with no rows and only the column names. <br></p>
<p>I have tried converting it to datetime64:<code>pd.to_datetime(df['Date'], format='%Y-%m-%d')</code>, <br>
specify the object as a string: <code>combined_lanes[~combined_lanes['Date'].str.contains("2021-06-20")]</code>, <br> and defining the date seperately:</p>
<pre><code>date = "2021-06-20"
df = df[df['Date'].str.lower() == date]
</code></pre>
<p>Nothing I've tried or researched works.</p>
<p>Note: this does not occur when I try other columns, including ones with the datatype 'object'.</p>
| [
{
"answer_id": 74161365,
"author": "birca123",
"author_id": 10231374,
"author_profile": "https://Stackoverflow.com/users/10231374",
"pm_score": 1,
"selected": false,
"text": "@Around(\"@annotation(customAnnotationArgumentName)\")\npublic Object aroundJoinPoint(ProceedingJoinPoint joinPoi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20058055/"
] |
74,160,846 | <p>I'm currently learning Julia and i'm trying to translate a Fortran77 code, but i got this error message and i can't see from where the issue is coming from.</p>
<pre><code>using DelimitedFiles, DataFrames
function diprcbk(iii,x,r)
if iii==0
df = DataFrame(readdlm("dipgbw800hp.dat"), [:ya,:xa, :ra, :da])
ya1=[]
xa1=[]
for ix in 1:801:370863
YA1 = df.ya[ix]
XA1 = df.xa[ix]
append!(ya1, YA1)
append!(xa1, XA1)
end
ya=[]
xa=[]
da=[]
ra=[]
ral=[]
for ix in 1:1:463
XA=xa1[ix]
YA=ya1[ix]
append!(ya, YA)
append!(xa, XA)
DA=df[df.ya .== ya[ix], :da]
push!(da, DA)
for ir in 1:1:801
RA = df.ra[ir]
RAL=log(RA)
append!(ra, RA)
append!(ral, RAL)
end
end
end
if iii==1
df = DataFrame(readdlm("dipmv800hp.dat"), [:ya,:xa, :ra, :da])
ya1=[]
xa1=[]
for ix in 1:801:370863
YA1 = df.ya[ix]
XA1 = df.xa[ix]
append!(ya1, YA1)
append!(xa1, XA1)
end
end
ya=[]
xa=[]
da=[]
ra=[]
ral=[]
for ix in 1:1:463
XA=xa1[ix]
YA=ya1[ix]
append!(ya, YA)
append!(xa, XA)
DA=df[df.ya .== ya[ix], :da]
push!(da, DA)
for ir in 1:1:801
RA = df.ra[ir]
RAL=log(RA)
append!(ra, RA)
append!(ral, RAL)
end
end
if r < ra[1]
return 0
#####Maybe the error is somewhere here?#####
elseif r>= ra[1] && r<=ra[801]
y = float(log((xa[1])/x))
for ix in 1:1:(length(ya)-1)
if y>ya[ix] && y<ya[ix+1]
indx=ix
for ir in 1:1:(802-1)
if r>ra[ir] && r<ra[ir + 1]
indr=ir
rl = log(r)
function xlinter(x1,x2,y1,y2,x)
xlinter = float((y2-y1)*(x-x1)/(x2-x1)+y1)
return xlinter
end
dindr=xlinter(ya[indx],ya[indx+1],da[indx][indr],da[indx+1][indr],y)
dindrp1=xlinter(ya[indx],ya[indx+1],da[indx][indr+1],da[indx+1][indr+1],y)
diprcbk=xlinter(ral[indr],ral[indr+1],dindr,dindrp1,rl)
return diprcbk
end
end
end
end
############################################
elseif r>ra[801]
return 1
end
end
MV=[]
GBW=[]
R=[]
for i in -90:1:20
r=10^((0.1)*i)
aaa=diprcbk(0, 10^(-4), r)
bbb=diprcbk(1, 10^(-4), r)
append!(R, r)
append!(GBW, aaa)
append!(MV, bbb)
end
</code></pre>
<blockquote>
<p>MethodError: objects of type Float64 are not callable</p>
<p>Maybe you forgot to use an operator such as *, ^, %, / etc. ?</p>
<p>Stacktrace:</p>
<p>[1] diprcbk(iii::Int64, x::Float64, r::Float64)</p>
<p>@ Main .\In[25]:94</p>
<p>[2] top-level scope</p>
<p>@ .\In[26]:6</p>
<p>[3] eval</p>
<p>@ .\boot.jl:368 [inlined]</p>
<p>[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String,
filename::String)</p>
<p>@ Base .\loading.jl:1428</p>
</blockquote>
| [
{
"answer_id": 74162585,
"author": "daycaster",
"author_id": 3800865,
"author_profile": "https://Stackoverflow.com/users/3800865",
"pm_score": 2,
"selected": false,
"text": "diprcbk"
},
{
"answer_id": 74162599,
"author": "fandak",
"author_id": 18390234,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14793158/"
] |
74,160,898 | <p>I have the following data:</p>
<pre><code> export interface BreakTimes {
start? : string;
end? : string;
}
export interface WorkingPlanDays {
start? : string;
end? : string;
breaks? : BreakTimes[];
}
export interface WorkingPlan {
[day : string] : WorkingPlanDays;
}
const WORKING_PLAN_DATA: WorkingPlan = {
"monday": null,
"tuesday": {
"start": "09:00",
"end": "17:30",
"breaks": [
{
"start": "12:00",
"end": "12:30"
},
{
"start": "13:30",
"end": "13:50"
}
]
},
"wednesday": {
"start": "09:00",
"end": "17:30",
"breaks": [
{
"start": "12:00",
"end": "12:30"
},
{
"start": "13:30",
"end": "13:50"
}
]
},
"thursday": {
"start": "09:00",
"end": "17:30",
"breaks": [
{
"start": "12:00",
"end": "12:30"
},
{
"start": "13:30",
"end": "13:50"
}
]
},
"friday": {
"start": "09:00",
"end": "20:00",
"breaks": [
{
"start": "12:00",
"end": "12:30"
},
{
"start": "13:30",
"end": "14:30"
}
]
},
"saturday": {
"start": "09:00",
"end": "17:00",
"breaks": [
{
"start": "12:00",
"end": "12:30"
},
{
"start": "13:30",
"end": "13:50"
}
]
},
"sunday": null
}
</code></pre>
<p>What I am trying to achieve is getting the break times in a new object like so:</p>
<pre><code> const ELEMENT_DATA: Breaks[] = [
{day: 'Tuesday', start: '12:00', end: '12:30'},
{day: 'Tuesday', start: '13:30', end: '13:50'},
{day: 'Wednesday', start: '12:00', end: '12:30'},
{day: 'Wednesday', start: '13:30', end: '13:50'},
...... etc....
];
</code></pre>
<p>What is the best way to do so?
I'm pretty new to javascript and typescript, getting a little confused on how to iterate over this object that has nested objects within.</p>
<p>If you have the answer could you please also explain how your code works to give me a better understanding?
Much appreciated guys!</p>
| [
{
"answer_id": 74162585,
"author": "daycaster",
"author_id": 3800865,
"author_profile": "https://Stackoverflow.com/users/3800865",
"pm_score": 2,
"selected": false,
"text": "diprcbk"
},
{
"answer_id": 74162599,
"author": "fandak",
"author_id": 18390234,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305931/"
] |
74,160,901 | <p>I have a textformfield but when I type something in the Underline color become red How can I change that color</p>
<p>code:</p>
<pre><code>TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) => validateCharacters(value),
inputFormatters: [
LengthLimitingTextInputFormatter(20),
],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.grey),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
),
hintText: 'Full Name',
hintStyle: TextStyle(fontSize: 12)),
onChanged: (value) {
setState(() {
fullName = value.trim();
});
},
)
</code></pre>
<p>image: <a href="https://i.stack.imgur.com/V0pGF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V0pGF.jpg" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74162585,
"author": "daycaster",
"author_id": 3800865,
"author_profile": "https://Stackoverflow.com/users/3800865",
"pm_score": 2,
"selected": false,
"text": "diprcbk"
},
{
"answer_id": 74162599,
"author": "fandak",
"author_id": 18390234,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17636769/"
] |
74,160,902 | <p>Edit: The following is a simplified code of a more complex example.</p>
<pre><code>def lottery(amount, callback=None):
print(f'You spent {amount} on a lottery ticket.')
if callback:
callback(amount)
def win(amount):
print(f'You won ${amount * 1000}!!!')
def lose(amount):
print(f"Sorry, you spent {amount} and didn't win anything.")
</code></pre>
<p>Edit: The 'lottery' function is from a third-party package. I would prefer not to modify their code.</p>
<p>The following works, but they aren't what I am looking for.</p>
<pre><code>lottery(100, win)
</code></pre>
<p>Output:</p>
<p>You spent 100 on a lottery ticket.
You won $100000!!!</p>
<pre><code>lottery(100, callback=win)
</code></pre>
<p>Output:</p>
<p>You spent 100 on a lottery ticket.
You won $100000!!!</p>
<pre><code>lottery(100, lose)
</code></pre>
<p>Output:</p>
<p>You spent 100 on a lottery ticket.
Sorry, you spent 100 and didn't win anything.</p>
<pre><code>lottery(100, callback=lose)
</code></pre>
<p>You spent 100 on a lottery ticket.
Sorry, you spent 100 and didn't win anything.</p>
<p><strong>What I'm looking for is to continue to use a callback and have a variable hold a value of either 'win', 'lose', [Edit: or additional functions like 'win_1', 'win_2', ..., 'win_n' or 'lose_1', 'lose_2', ..., 'lose_n'] and use that variable in the same place as the callback name.</strong></p>
<p>Wishful example:</p>
<pre><code>win_lose = 'win'
lottery(100, win_lose)
</code></pre>
<p>Edit: the string 'win' is built on the fly like:</p>
<pre><code>'win' + '_' + str(index)
</code></pre>
<p>or</p>
<pre><code>'lose' + '_' + str(index)
</code></pre>
<p>Wishful output:</p>
<p>You spent 100 on a lottery ticket.
You won $100000!!!</p>
| [
{
"answer_id": 74162585,
"author": "daycaster",
"author_id": 3800865,
"author_profile": "https://Stackoverflow.com/users/3800865",
"pm_score": 2,
"selected": false,
"text": "diprcbk"
},
{
"answer_id": 74162599,
"author": "fandak",
"author_id": 18390234,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7087618/"
] |
74,160,907 | <p>I have a list like below :
release=abc,xyz,pqr,bnm
and as output I need</p>
<pre><code>abc
xyz
pqr
bnm
</code></pre>
<p>I have tried below using sed , it successfully removes , but not able to insert new line after comma , if can help pls</p>
<pre><code>release=abc,xyz,pqr,bnm
for i in $release;do
b=`echo $i| sed 's/,/\\n/g'`
echo $b
done
</code></pre>
<p>output: abc xyz pqr bnm which is not expected here as need new line</p>
| [
{
"answer_id": 74162585,
"author": "daycaster",
"author_id": 3800865,
"author_profile": "https://Stackoverflow.com/users/3800865",
"pm_score": 2,
"selected": false,
"text": "diprcbk"
},
{
"answer_id": 74162599,
"author": "fandak",
"author_id": 18390234,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17775253/"
] |
74,160,920 | <p>I have a json file named as param.json that looks as below:</p>
<pre><code>[
{
"Value": "anshuman.ceg+Dev@gmail.com",
"Key": "AccountEmail"
},
{
"Value": "DevABC",
"Key": "AccountName"
},
{
"Value": "Security (ou-nzx5-8ajd1561)",
"Key": "ManagedOrganizationalUnit"
},
{
"Value": "anshuman.ceg+Dev@gmail.com",
"Key": "SSOUserEmail"
},
{
"Value": "John",
"Key": "SSOUserFirstName"
},
{
"Value": "Smith",
"Key": "SSOUserLastName"
}
]
</code></pre>
<p>I want to get only the Value for <strong>DevABC</strong> so that I can use while reading the -r line. I need only DevABC</p>
<p>I am using jq as follows which doesn't seem to work</p>
<p>jq -r .[1].Value param.json</p>
| [
{
"answer_id": 74167615,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 1,
"selected": false,
"text": "Key"
},
{
"answer_id": 74182646,
"author": "glenn jackman",
"author_id": 7552,
"author_profile": "h... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305962/"
] |
74,160,932 | <p>I'm trying to find the number of numbers divisble by 2 in 0-100, I have used a range() function and n1=n1+1 to generate 0 to 100, then with an if statement display only numbers wholely divisble by 2.</p>
<p>For the life of me I cannot find a way to count the number of times 0's are printed in the console, I googled count() but that seems to work for opening other files not the one you are in.</p>
<pre><code>n1 = 1
for x in range(100):
dTwo = n1 % 2
if (int(dTwo) == 0):
print(n1)
n1 = n1 + 1 #generates 0 to 101
#how to I keep track of the number of 0s outputted in console after this step?
</code></pre>
<p>Any help would be greatly appreciated</p>
| [
{
"answer_id": 74167615,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 1,
"selected": false,
"text": "Key"
},
{
"answer_id": 74182646,
"author": "glenn jackman",
"author_id": 7552,
"author_profile": "h... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20305997/"
] |
74,160,957 | <p>Alright, this is a very basic question, but I'm not seeing the fix here. I want to flatten an array that has one layer of depth and at the same time multiply each element by 2. However, when I run flat map on arr1 the console is returning NaN instead of an array of 5 elements with each element being multiplied by 2. Code example below:</p>
<p>const arr1 = [ [2,5] , [5,10,15] ];</p>
<p>const arr2 = arr1.flatMap((el) => el * 2);</p>
<p>console.log(arr2);</p>
<p>Expected // [4, 10, 10, 20, 30]</p>
<p>Actual // [Nan, Nan]</p>
<p>If I run the flatMap without the multiplication I get the array with each element but it's only once I try to mulitply each value that I get the two NaN. What am I missing?</p>
<p>const arr3 = arr1.flatMap((el) => el);
console.log(arr3);</p>
<p>Actaul // [2,5,5,10,15];</p>
| [
{
"answer_id": 74161036,
"author": "Shubham Sharma",
"author_id": 7160157,
"author_profile": "https://Stackoverflow.com/users/7160157",
"pm_score": -1,
"selected": false,
"text": "const arr1 = [ [2,5] , [5,10,15] ];\n\nvar flattened = arr1.reduce(function(a, b) {\n return a.concat(b);\n... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19498585/"
] |
74,160,961 | <p>I was following a youtube tutorial on making a codeigniter college management system
but i am stuck at a point.. when i try to submit the form on wamp server
select form fields not showing requied error on form submit</p>
<p>i have checked the name fields of the form inputs matching the database table but still when the form is submitted without any fiilling any fields
the role and gender select field errors doesnt show</p>
<p>here is my code
controller</p>
<p>welcome.php</p>
<pre><code>defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
//$this->load->helper('url');
$this->load->view('home');
}
public function adminRegister()
{
$this->load->model('queries');
$roles = $this->queries->getRoles();
// print_r($roles);
// exit();
$this->load->view('register',['roles'=>$roles]);
}
public function adminLogin()
{
echo 'Login';
}
public function adminSignup()
{
//echo 'Registered succesfully';
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('gender','Gender','required');
$this->form_validation->set_rules('role_id','Role','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('confpwd','Password Again','required');
$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if($this->form_validation->run()){
echo 'validation passed';
}else{
//echo 'validation error';
echo validation_errors();
}
}
}
</code></pre>
<p>and views
register.php</p>
<pre><code><?php include('inc/header.php');?>
<div class="container mt-2">
<?php echo form_open('welcome/adminSignup',['class'=>'form-hoizontal']);?>
<h3 class="text-center display-4">ADMIN REGISTER</h3>
<hr/>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label for="username" class="mt-2">User name:</label>
</div>
<div class="col-md-9">
<!-- <input type="text" class="form-control" placeholder="User name" id="username"> -->
<?php
$data = array(
'type' => 'text',
'name' => 'username',
'placeholder' => 'Enter Username',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('username','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Email address:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<?php
$data = array(
'type' => 'email',
'name' => 'email',
'placeholder' => 'Enter Email',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('email','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="gender" class="mt-2">Gender:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<select class="form-control" name="gender">
<option>Select</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('gender','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Role:</label>
</div>
<div class="col-md-9">
<select class="form-control" name="role_id">
<option>Select</option>
<?php if(count($roles)) { ?>
<?php foreach ($roles as $role){?>
<option><?php echo $role->rolename;?></option>
<?php }
} ?>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('role_id','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'password',
'placeholder' => 'Enter Password',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('password','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password Again:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'confpwd',
'placeholder' => 'Enter Password Again',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('confpwd','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<!-- <button type="submit" class="btn btn-dark float-right">Register</button> -->
<div class="float-right">
<?php echo form_submit('Register', 'Register',"class='btn btn-dark'"); ?>
<?php echo anchor('welcome','GO BACK',['class'=>'btn btn-warning']);?>
</div>
</div>
</div>
<?php echo form_close(); ?>
</div>
<?php include('inc/footer.php');?>
</code></pre>
<p>here is screenshot
<a href="https://i.stack.imgur.com/sJ7Mp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sJ7Mp.jpg" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74162651,
"author": "Marleen",
"author_id": 3960296,
"author_profile": "https://Stackoverflow.com/users/3960296",
"pm_score": 2,
"selected": true,
"text": "value"
},
{
"answer_id": 74330571,
"author": "Nilesh Karanjkar",
"author_id": 13028263,
"author_p... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2654750/"
] |
74,160,968 | <p>The following code holds the query,</p>
<pre><code>import React, {useEffect , useState} from 'react'
import './Body.css'
export default function Navbar() {
const [value , setvalue] = useState(0);
useEffect(() => {
console.log("useEffect ran");
}, [])
return (
<>
<div>
<button onClick={ () => setvalue(value-1)}> - </button>
<button> {value}</button>
<button onClickCapture={() => setvalue(value+1)} > + </button>
</div>
</>
)
</code></pre>
<p>When I am using <code>onClick= {setvalue(value+1)}</code> then I am getting an error for too many renderings.</p>
<p>But, when I am using an arrow function then it is preventing the renders.</p>
<p>Can you tell me how is it happening?</p>
| [
{
"answer_id": 74162651,
"author": "Marleen",
"author_id": 3960296,
"author_profile": "https://Stackoverflow.com/users/3960296",
"pm_score": 2,
"selected": true,
"text": "value"
},
{
"answer_id": 74330571,
"author": "Nilesh Karanjkar",
"author_id": 13028263,
"author_p... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19757319/"
] |
74,160,972 | <p>I have a txt file of data that looks like this:</p>
<pre><code>@0 #1
@30 #2
@750 #2
@20 #3
@500 #3
@2500 #4
@460 #4
@800 #1
@2200 #1
@290 #2
@4700 #4
@570 #1
</code></pre>
<p>How do I sort the file based on the integer between the @ and #?</p>
<p>The output should be:</p>
<pre><code>@0 #1
@20 #3
@30 #2
@290 #2
@460 #4
@500 #3
@570 #1
@750 #2
@800 #1
@2200 #1
@2500 #4
@4700 #4
</code></pre>
| [
{
"answer_id": 74162651,
"author": "Marleen",
"author_id": 3960296,
"author_profile": "https://Stackoverflow.com/users/3960296",
"pm_score": 2,
"selected": true,
"text": "value"
},
{
"answer_id": 74330571,
"author": "Nilesh Karanjkar",
"author_id": 13028263,
"author_p... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13743738/"
] |
74,160,978 | <p>i just want the <code>while</code> statement displayed and selenium clicks selenium have to follow the below code, Thank you in advance.</p>
<pre><code>while (driver.find_element(By.CLASS_NAME, 'area is-available').click()):
driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/div/div/article[1]/div/section[2]/label[2]/div[2]/span').click()
time.sleep(4)
</code></pre>
| [
{
"answer_id": 74162651,
"author": "Marleen",
"author_id": 3960296,
"author_profile": "https://Stackoverflow.com/users/3960296",
"pm_score": 2,
"selected": true,
"text": "value"
},
{
"answer_id": 74330571,
"author": "Nilesh Karanjkar",
"author_id": 13028263,
"author_p... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20100584/"
] |
74,160,989 | <p>I have a file .txt like belowe</p>
<pre><code>AXN1 6.9e+07 69000000
AXN2 7.2e+07 72000000
AXN2 81000000 81000000
AXN3 1.18e+08 118000000
AXN4 7.7e+07 77000000
AXN9 8e+07 80000000
AXN11 800000 800000
AXN11 2.9e+07 29000000
AXN12 48000001 48000001
AXN18 4.8e+07 48000000
</code></pre>
<p>I want get that</p>
<pre><code>AXN1 69000000 69000000
AXN2 72000000 72000000
AXN2 81000000 81000000
AXN3 118000000 118000000
AXN4 77000000 77000000
AXN9 80000000 80000000
AXN11 800000 800000
AXN11 29000000 29000000
AXN12 48000001 48000001
AXN18 48000000 48000000
</code></pre>
<p>How can I do it at Linux? Thank you.</p>
| [
{
"answer_id": 74161073,
"author": "tink",
"author_id": 1394729,
"author_profile": "https://Stackoverflow.com/users/1394729",
"pm_score": 2,
"selected": true,
"text": "awk"
},
{
"answer_id": 74164135,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_pro... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74160989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19814087/"
] |
74,161,018 | <p>Please explain to me how th3 output is <code>11</code>.</p>
<pre><code>int main(){
int delta = 12, alpha = 5, a = 0;
a = delta - 6 + alpha++;
printf("%d", a);
return 0;
}
</code></pre>
| [
{
"answer_id": 74161040,
"author": "tsoa",
"author_id": 19469480,
"author_profile": "https://Stackoverflow.com/users/19469480",
"pm_score": 2,
"selected": false,
"text": "++"
},
{
"answer_id": 74164406,
"author": "John Bode",
"author_id": 134554,
"author_profile": "ht... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17503444/"
] |
74,161,038 | <p>I have a dataset and am building a shiny flexdashboard with multiple user inputs which filter the data down to a subset. I am struggling with just one of the filters, where if the user chooses 'ALL' in <code>selectInput</code>, I want that filter function not to do anything and just return the data as is. Below is one of my attempts:</p>
<pre><code>library(flexdashboard)
library(DT)
library(lubridate)
library(readr)
library(tidyverse)
...
qry <- read_file("some_query.sql")
Data_df <- con %>% tbl(sql(qry)) %>% collect()
doctors_to_choose <- unique(pull(Data_df, 'Doctor')) %>%append('ALL')
Column {data-width=200 .sidebar}
-----------------------------------------------------------------------
```{r}
checkboxGroupInput("drug_classes",
label = "Choose the classes of drugs",
choices = c("II", "III", "IV", "V"),
selected = c("V"),
)
selectInput(
inputId="chosen_doctor",
label="Choose Doctor",
choices=doctors_to_choose,
selected = "ALL",
multiple = FALSE,
size = NULL
)
show_data_df <- reactive({
Data_df %>%
filter(`Drug Class` %in% input$drug_classes) %>%
{if (input$chosen_doctor != "ALL") filter(Doctor == input$chosen_doctor )
else filter(`Drug Class` %in% input$drug_classes) }
} )
```
</code></pre>
<p>I tried to use an if-else statement as above but failed. because In the original code, I have a long list of filters applied so ideally I would like to use something that does not require me to retype all the previous filters/actions like I did in the else part above.</p>
| [
{
"answer_id": 74161669,
"author": "TimTeaFan",
"author_id": 9349302,
"author_profile": "https://Stackoverflow.com/users/9349302",
"pm_score": 1,
"selected": true,
"text": "purrr::when"
},
{
"answer_id": 74169870,
"author": "Limey",
"author_id": 13434871,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2079111/"
] |
74,161,064 | <p>I have a torch tensors of shape (768, 8, 22), procesed by a Conv Layer 1-D Layer. The data is already standarized. The tensor is processed by the next layer:</p>
<p><strong>nn.Conv1d(input_chanels = 8, output_chanels = 1, kernel_size = 3)</strong></p>
<p>The output of the layer has the right dimensions, but the output matrix has the same value repeated over and over again.</p>
<pre><code>output = tensor(
[[[-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856,
-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856,
-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856]],
...
[[-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856,
-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856,
-0.1856, -0.1856, -0.1856, -0.1856, -0.1856, -0.1856]]]
</code></pre>
| [
{
"answer_id": 74168487,
"author": "Abner",
"author_id": 16825481,
"author_profile": "https://Stackoverflow.com/users/16825481",
"pm_score": 2,
"selected": false,
"text": "Conv1d"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15206347/"
] |
74,161,093 | <p>i need modify a csv file with pandas, I have the following table:</p>
<pre><code>Interface Description
Gi0/3/4/3 ISP
Gi0/3/4/3.401 Cliente A
Gi0/3/4/3.402 Cliente B
Gi0/3/4/3.403 Cliente C
Gi0/3/4/4 Cliente D
Gi0/3/4/4.1 Cliente E
Gi0/3/4/4.2 Cliente F
Gi0/3/4/5 Cliente G
</code></pre>
<p>I need to modify the Interface column, if the cell matches Gi0/3/4/3. I need to remove this part of the string and leave the rest and if it doesn't match Gi0/3/4/3. delete the row and finally make it look like this:</p>
<pre><code>Interface Description
401 Cliente A
402 Cliente B
403 Cliente C
</code></pre>
<p>From already thank you very much!</p>
| [
{
"answer_id": 74168487,
"author": "Abner",
"author_id": 16825481,
"author_profile": "https://Stackoverflow.com/users/16825481",
"pm_score": 2,
"selected": false,
"text": "Conv1d"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20178424/"
] |
74,161,096 | <p>I have a game, where there is an enemy and its ai only moves it northwest. It should move in all directions, but it doesnt and i cant figure it out. Can someone help me?
The enemy code:</p>
<pre class="lang-py prettyprint-override"><code>import pygame
import inventory_essentials
import variables
import level
import os
import projectiles
import math
import random
class Enemy(pygame.sprite.Sprite):
def __init__(self, pos, type, damage=50, health=100):
super().__init__()
self.image = type
self.pos = pos
self.damage = damage
self.state_stage = 0
self.direction = 0
self.health = health
self.fireballs = []
self.rect = self.image.get_rect(topleft=(pos[0] + 10, pos[1] + 10))
self.fireballs = pygame.sprite.Group()
def update(self, x_shift, do_damage=False):
self.ai()
self.rect.x += x_shift
self.rect.x += math.cos(self.direction)
self.rect.y += math.sin(self.direction)
if random.randint(0, 100) > 99:
destination = pygame.math.Vector2(variables.current_coords[0] - self.rect.x, variables.current_coords[1] - self.rect.y)
destination.normalize()
destination.scale_to_length(10)
new_fireball = projectiles.Fireball((self.rect.x + 10, self.rect.y + 10), variables.fireball_icon, self.damage, destination)
variables.level.create_fireball(new_fireball)
def ai(self):
dd = random.randint(-int(math.pi/2)*100, int(math.pi/2)*100)/100
self.direction += dd
print(math.cos(self.direction), math.sin(self.direction))
pass
</code></pre>
<p>i have calculated the sin and cos for the movement and it still doesnt work. Any help is appriciated!</p>
| [
{
"answer_id": 74161193,
"author": "Elijah Nicol",
"author_id": 14895492,
"author_profile": "https://Stackoverflow.com/users/14895492",
"pm_score": 0,
"selected": false,
"text": "[-pi/2, pi/2]"
},
{
"answer_id": 74161312,
"author": "Şahin Murat Oğur",
"author_id": 1273861... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16624010/"
] |
74,161,190 | <p>How do I group the array via javascript to just</p>
<ul>
<li>Vehicles</li>
<li>Food</li>
</ul>
<p>I can't figure it out via "reduce" since the array has no "key" to specify.</p>
<p><a href="https://i.stack.imgur.com/uMX7C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uMX7C.png" alt="enter image description here" /></a></p>
<p>Thank you</p>
| [
{
"answer_id": 74161193,
"author": "Elijah Nicol",
"author_id": 14895492,
"author_profile": "https://Stackoverflow.com/users/14895492",
"pm_score": 0,
"selected": false,
"text": "[-pi/2, pi/2]"
},
{
"answer_id": 74161312,
"author": "Şahin Murat Oğur",
"author_id": 1273861... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1491560/"
] |
74,161,204 | <p>I am trying to join two datasets, but they are not the same or have the same criteria.</p>
<p>Currently I have the dataset below, which contains the number of fires based on month and year, but the months are part of the header and the years are a column.</p>
<p><a href="https://i.stack.imgur.com/xCzJ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xCzJ5.png" alt="enter image description here" /></a></p>
<p>I would like to add this data, using as target data_medicao column from this other dataset, into a new column (let's hypothetically call it nr_total_queimadas).</p>
<p><a href="https://i.stack.imgur.com/oV7g0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oV7g0.png" alt="enter image description here" /></a></p>
<p>The date format is YYYY-MM-DD, but the day doesn't really matter here.</p>
<p>I tried to make a loop of this case, but I think I'm doing something wrong and I don't have much idea how to proceed in this case.</p>
<p>Below an example of how I would like the output with the junction of the two datasets:</p>
<p><a href="https://i.stack.imgur.com/6NQEz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6NQEz.png" alt="enter image description here" /></a></p>
<p>I used as an example the case where some dates repeat (which should happen) so the number present in the dataset that contains the number of fires, should also repeat.</p>
| [
{
"answer_id": 74161193,
"author": "Elijah Nicol",
"author_id": 14895492,
"author_profile": "https://Stackoverflow.com/users/14895492",
"pm_score": 0,
"selected": false,
"text": "[-pi/2, pi/2]"
},
{
"answer_id": 74161312,
"author": "Şahin Murat Oğur",
"author_id": 1273861... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11450796/"
] |
74,161,206 | <p>I'm trying to store date type data from <code>Oracle FORMS</code> with format mask as like <code>DD-MM-YYYY</code> but every time it store as like <code>DD/MON/YY</code>.
I already alter session with <code>NLS_DATE_FORMAT</code>, but result is as same as before.</p>
| [
{
"answer_id": 74162303,
"author": "d r",
"author_id": 19023353,
"author_profile": "https://Stackoverflow.com/users/19023353",
"pm_score": 2,
"selected": false,
"text": "WITH \n t AS\n (\n Select SYSDATE \"MY_DATE_COLUMN\" From Dual\n )\nSelect\n MY_DATE_CO... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19930892/"
] |
74,161,222 | <p>Input : x3b4U5i2
Output : bbbbiiUUUUUxxx</p>
<p>How can i solve this problem in Python. I have to print the word next to it's number n times and sort it</p>
| [
{
"answer_id": 74162303,
"author": "d r",
"author_id": 19023353,
"author_profile": "https://Stackoverflow.com/users/19023353",
"pm_score": 2,
"selected": false,
"text": "WITH \n t AS\n (\n Select SYSDATE \"MY_DATE_COLUMN\" From Dual\n )\nSelect\n MY_DATE_CO... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12633191/"
] |
74,161,229 | <p>I just found a curious case.</p>
<pre class="lang-java prettyprint-override"><code>class SomeClass {
abstract static class AbstractNested // for a templating purpose
extends SomeClass {
}
static class Sibling1
extends AbstractNested {
}
static class Sibling2
extends AbstractNested {
}
void a() {
new Sibling1.Sibling2(); // @@?
}
}
</code></pre>
<p>Why on earth does <code>new Sibling1.Sibling2();</code> work? How can I make it doesn't?</p>
| [
{
"answer_id": 74162303,
"author": "d r",
"author_id": 19023353,
"author_profile": "https://Stackoverflow.com/users/19023353",
"pm_score": 2,
"selected": false,
"text": "WITH \n t AS\n (\n Select SYSDATE \"MY_DATE_COLUMN\" From Dual\n )\nSelect\n MY_DATE_CO... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/330457/"
] |
74,161,232 | <p>I am using django rest framework. I want to include the url of an action defined in a view in its serializer.</p>
<p>My <code>serializers.py</code>:</p>
<pre class="lang-py prettyprint-override"><code>from rest_framework import serializers
class CommentSerializer(serializers.ModelSerializer):
"""Serializer for comments."""
class Meta:
model = Comment
fields = ["id", "item", "author", "content", "date_commented", "parent"]
class ItemDetailSerializer(serializers.ModelSerializer):
"""Serializer for items (for retrieving/detail purpose)."""
category = CategorySerializer(many=True, read_only=True)
media = MediaSerializer(many=True, read_only=True)
brand = BrandSerializer(many=False, read_only=True)
specifications = serializers.SerializerMethodField(source="get_specifications")
comments = ??????????????????????????????????????????????????
class Meta:
model = Item
fields = [
"id",
"slug",
"name",
"description",
"brand",
"show_price",
"location",
"specifications",
"is_visible",
"is_blocked",
"created_at",
"updated_at",
"seller",
"category",
"media",
"comments",
"users_wishlist",
"reported_by",
]
read_only = True
editable = False
lookup_field = "slug"
def get_specifications(self, obj):
return ItemSpecificationSerializer(obj.item_specification.all(), many=True).data
</code></pre>
<p>My <code>views.py</code>:</p>
<pre class="lang-py prettyprint-override"><code>from rest_framework import viewsets, mixins, status
from ramrobazar.inventory.models import Item, Comment
from ramrobazar.drf.serializers ItemSerializer, ItemDetailSerializer, CommentSerializer
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.filters import SearchFilter
from django_filters.rest_framework import DjangoFilterBackend
class ItemList(viewsets.GenericViewSet, mixins.ListModelMixin):
"""View for listing and retrieving all items for sale."""
queryset = Item.objects.all()
serializer_class = ItemSerializer
serializer_action_classes = {
"retrieve": ItemDetailSerializer,
}
permission_classes = [IsAuthenticatedOrReadOnly]
lookup_field = "slug"
filter_backends = [DjangoFilterBackend, SearchFilter]
filterset_fields = [
"category__slug",
"brand__name",
]
search_fields = ["name", "description", "category__name", "brand__name", "location"]
def get_serializer_class(self):
try:
return self.serializer_action_classes[self.action]
except:
return self.serializer_class
def retrieve(self, request, slug=None):
item = self.get_object()
serializer = self.get_serializer(item)
return Response(serializer.data)
@action(detail=True, methods=['GET'])
def comments(self, request, slug=None):
item = Item.objects.get(slug=slug)
queryset = Comment.objects.filter(item=item)
serializer = CommentSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
</code></pre>
<p>I have an action named <code>comments</code> in the <code>ItemList</code> view which gives all the comments of a specific item. I can get the details of the item from the url <code>/api/items/<slug></code>. I can get all the comments of the item from the url <code>api/items/<slug>/comments</code>. I want to include a <code>comments</code> field in the <code>ItemDetailSerializer</code> serializer which is a link to <code>api/items/<slug>/commments</code>. How can I accomplish this?</p>
| [
{
"answer_id": 74162303,
"author": "d r",
"author_id": 19023353,
"author_profile": "https://Stackoverflow.com/users/19023353",
"pm_score": 2,
"selected": false,
"text": "WITH \n t AS\n (\n Select SYSDATE \"MY_DATE_COLUMN\" From Dual\n )\nSelect\n MY_DATE_CO... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19159002/"
] |
74,161,233 | <p>When we are iterating in reverse direction, I see that most people use the following structure:</p>
<pre><code>for (auto it = vec.rbegin(); it != vec.rend(); it++)
{
// block of code //
}
</code></pre>
<p>But for a long time, I have a doubt about using this, and I want to know why the following code does not work.</p>
<p>As we know, the last element will have the highest index than any element index in the array, and the array is going to take contiguous memory.</p>
<p>My primary doubt is when iterating backwards, why shouldn't we use <code>it--</code>?</p>
<p>I want the reason why the following code is not going to work. I am running the loop from <code>rbegin</code>, that is the last element, and I am going until the first element. I am decrementing <code>it</code> by one in every iteration.</p>
<pre><code>for (auto it = vec.rbegin(); it >= vec.begin(); it--)
{
cout << *it << endl;
}
</code></pre>
<p>Even the below code is not working, why?</p>
<pre><code>for(auto it = vec.rbegin(); it >= vec.begin(); it++)
{
cout << *it << endl;
}
</code></pre>
| [
{
"answer_id": 74161268,
"author": "JeJo",
"author_id": 9609840,
"author_profile": "https://Stackoverflow.com/users/9609840",
"pm_score": 2,
"selected": false,
"text": "vec.rbegin()"
},
{
"answer_id": 74161353,
"author": "Xin Cheng",
"author_id": 4708399,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306231/"
] |
74,161,273 | <p>Is there a way to use javascript to select a link that only has an href and rel. I am trying to use the console to select a link, but the link in particular has no ID. I've tried the .click function but it seems that only works for buttons.</p>
| [
{
"answer_id": 74161268,
"author": "JeJo",
"author_id": 9609840,
"author_profile": "https://Stackoverflow.com/users/9609840",
"pm_score": 2,
"selected": false,
"text": "vec.rbegin()"
},
{
"answer_id": 74161353,
"author": "Xin Cheng",
"author_id": 4708399,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306319/"
] |
74,161,274 | <p>I have a microservice project. I am using DRF. Now I need to add notification system to this project. Since we have multiple service notification can come from any service. We also have web version and mobile version in frontend.
Which will be better option for notification service? Notification with firebase or Notification with celery?</p>
| [
{
"answer_id": 74161268,
"author": "JeJo",
"author_id": 9609840,
"author_profile": "https://Stackoverflow.com/users/9609840",
"pm_score": 2,
"selected": false,
"text": "vec.rbegin()"
},
{
"answer_id": 74161353,
"author": "Xin Cheng",
"author_id": 4708399,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14135538/"
] |
74,161,318 | <p>So I'm trying to practice c# and stumbled with the connection error, I already stated that my connection will be closed but it tells me that my connection is still open. I really have no idea what's wrong with this.</p>
<pre><code>public void getdept()
{
con.Open();
string query = "SELECT * FROM positions where PositionName=" + cbxposname.SelectedValue.ToString() + "";
SqlCommand cmd = new SqlCommand(query, con);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(query, con);
sda.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
txtdeptname.Text = dr["Department"].ToString();
}
con.Close();
}
</code></pre>
<p>Any tips is welcomed!</p>
| [
{
"answer_id": 74161387,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 2,
"selected": false,
"text": "using"
},
{
"answer_id": 74161569,
"author": "vivek nuna",
"author_id": 6527049,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20020126/"
] |
74,161,322 | <p>This query has so many joins and i have to apply conditions on joined table columns to get the desired results but query becomes slow when i apply condition on a <code>datetime</code> column.</p>
<p>Here is the query</p>
<pre class="lang-sql prettyprint-override"><code> select
distinct v0_.id as id_0,
MIN(v4_.price) as sclr_4
from
venue v0_
left join facility f5_ on
v0_.id = f5_.venue_id
and (f5_.deleted_at is null)
left join sport_facility_types s6_ on
f5_.id = s6_.facility_id
left join taxonomy_term t7_ on
s6_.sport_id = t7_.id
and (t7_.deleted_at is null)
left join term t8_ on
t7_.term_id = t8_.id
left join sport_facility_types_taxonomy_term s10_ on
s6_.id = s10_.sport_facility_types_id
left join taxonomy_term t9_ on
t9_.id = s10_.taxonomy_term_id
and (t9_.deleted_at is null)
left join term t11_ on
t9_.term_id = t11_.id
left join facility_venue_item_price f12_ on
f5_.id = f12_.facility_id
left join venue_item_price v4_ on
f12_.venue_item_price_id = v4_.id
left join calendar_entry c13_ on
v4_.calendar_entry_id = c13_.id
where
(v0_.status = 'active'
and f5_.status = 'active')
and (v0_.deleted_at is null)
and c13_.start_at >= '2022-10-21 19:00:00' --- this slows down the query
group by
v0_.id
</code></pre>
<p>And here is the query plan <a href="https://explain.dalibo.com/plan/46h0fb3343e246a5" rel="nofollow noreferrer">https://explain.dalibo.com/plan/46h0fb3343e246a5</a>.
The query plan is so big that i cannot paste it here</p>
<p>Plain query plan <a href="https://explain.depesz.com/s/7qnD" rel="nofollow noreferrer">https://explain.depesz.com/s/7qnD</a></p>
<p>Plain query plan without where condition <a href="https://explain.depesz.com/s/3sK3" rel="nofollow noreferrer">https://explain.depesz.com/s/3sK3</a></p>
<p>The query shouldn't take much time as there are not many rows in tables.</p>
<ul>
<li>calendar_entry table has ~350000 rows</li>
<li>venue_item_price table has also ~320000 rows</li>
</ul>
| [
{
"answer_id": 74161387,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 2,
"selected": false,
"text": "using"
},
{
"answer_id": 74161569,
"author": "vivek nuna",
"author_id": 6527049,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4286262/"
] |
74,161,327 | <p>I am trying to coded a Pix2Pix GAN but I am getting this error with my Data loader:</p>
<pre><code>Caught TypeError in DataLoader worker process 0.
</code></pre>
<p>here is my dataset class:</p>
<pre><code>class Pix2PixDataset(Dataset):
def __init__(self, data_points, transforms = None):
self.data_points = data_points
self.transforms = transforms
self.resize = T.Resize((512,512))
def __getitem__(self, index) :
image = self.resize(read_a_image(self.data_points[index].reference_image))
y_label = self.resize(read_a_image(self.data_points[index].drawing))
if self.transforms:
image = self.transforms(image)
y_label = self.transforms(y_label)
return(image, y_label)
def __len__(self):
return len(self.data_points)
</code></pre>
<p>and here is the code for my dataloader:</p>
<pre><code>test_loader2 = DataLoader(traindataset, batch_size=Batch, shuffle=True, num_workers = Num_Workers, collate_fn = transforms.RandomRotation(degrees=360), pin_memory=True)
for test_images, test_drawing in test_loader2:
display(test_images)
plt.show()
display(test_drawing)
break
</code></pre>
<p>again I am doing a Pix to Pix so both my x and y(label) has to be an images tensor.
How can I do this ?
I saw on this site but that someone else got this same error and they was told that y has to be an int, but again I am doing a Pix2Pix gans so both my x and y are images
so how do I do this?</p>
| [
{
"answer_id": 74161387,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 2,
"selected": false,
"text": "using"
},
{
"answer_id": 74161569,
"author": "vivek nuna",
"author_id": 6527049,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19467657/"
] |
74,161,332 | <p>I have a table with 3 rows.
<strong>| id | fullname | email.</strong><br>
In the php code, I have programmed that when someone registers on my site, it can be in active <strong>(y)</strong> or pending <strong>(t)</strong> status.<br><br>
What I want is to have a button called PENDING and when I press it, it will show only the users who are Pending in blue.
Now as it is, the pending users is blue without pressing the button.
Any idea; Thank you in advance..</p>
<pre><code><!-- Table -->
<?php if($this->data):?>
<table>
<thead>
<tr>
<th>UID</th>
<th>FULLNAME</th>
<th>EMAIL ADDRESS</th>
</tr>
</thead>
<?php
$name = 'ON';
echo '<button type="button" id="buttons"
onclick="myFunction(\'' . $name . '\')">Pending</button>';
?>
<script>
function myFunction(name) {
$('#buttons').toggleClass('active');
$('tr').toggleClass('active');
}
</script>
<style>
.active {
background: purple !important;
}
</style>
<?php foreach ($this->data as $row):?>
<?php if($row->active == t):?>
<?php
$blueColor = 'blue';
$greenColor = '#304030';?>
<tr style="background-color:<?php echo $blueColor ;?>">
<?php else:?>
<?php if($row->active == y):?>
<tr style="background-color:<?php echo $greenColor ;?>">
<?php endif;?>
<?php endif;?>
<td><?php echo $row->id;?></td>
<td><?php echo $row->fullname;?></td>
<td><?php echo $row->email;?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
</div>
</code></pre>
| [
{
"answer_id": 74161387,
"author": "jmcilhinney",
"author_id": 584183,
"author_profile": "https://Stackoverflow.com/users/584183",
"pm_score": 2,
"selected": false,
"text": "using"
},
{
"answer_id": 74161569,
"author": "vivek nuna",
"author_id": 6527049,
"author_profi... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19876007/"
] |
74,161,379 | <p>I want to declare sort of a configuration class. I want to access the properties as <code>Config.Params1.Prop1</code>.
I get <code>cannot declare a variable of static type</code> when I use the code below.
I understand why I get the error, but how do I declare the classes to get what I want?</p>
<pre><code>public static class Config
{
public static Section1 Params1;
}
public static class Section1
{
public static string Prop1 => "...";
public static string Prop2 => "...";
}
</code></pre>
| [
{
"answer_id": 74161400,
"author": "Rafal",
"author_id": 1495595,
"author_profile": "https://Stackoverflow.com/users/1495595",
"pm_score": 0,
"selected": false,
"text": "public static class Config\n{\n\n public static class Params1 \n {\n public static string Prop1 => \".... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/573082/"
] |
74,161,394 | <p>I have try to do all combination by matrix columns by R as below
Firstly, I have a 4*3 matrix as below</p>
<pre><code>> a
[,1] [,2] [,3] [,4]
[1,] 1 0 1 1
[2,] 1 0 0 0
[3,] 1 1 1 1
</code></pre>
<p>then we want to list total 3<em>1</em>2*2 = 12 combination, such as example below
one of example is</p>
<pre><code> [,1] [,2] [,3] [,4]
[1,] 1 0 1 1
[2,] 0 0 0 0
[3,] 0 1 0 0
</code></pre>
<p>and the second example is</p>
<pre><code> [,1] [,2] [,3] [,4]
[1,] 1 0 1 0
[2,] 0 0 0 0
[3,] 0 1 0 1
</code></pre>
<p>one column with only one number.
Currently, I already list down each column type, such as</p>
<pre><code>> whole.combination
[[1]]
b b b
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
[[2]]
b
[1,] 0
[2,] 0
[3,] 1
[[3]]
b b
[1,] 1 0
[2,] 0 0
[3,] 0 1
[[4]]
b b
[1,] 1 0
[2,] 0 0
[3,] 0 1
</code></pre>
<p>however, although i can using cbind by manual to generate one</p>
<pre><code>> cbind(a[[1]][,1],a[[2]][,1],a[[3]][,1],a[[4]][,1])
[,1] [,2] [,3] [,4]
[1,] 1 0 1 1
[2,] 0 0 0 0
[3,] 0 1 0 0
</code></pre>
<p><strong>how can i combine each column by each matrix to generate one 4*3 matrix?</strong>
but, does it have any efficient way to list all combination in once?
therefore, if i extend this problem by n*m matrix, i need one algorithm to generate those matrix combination.
thanks</p>
| [
{
"answer_id": 74161400,
"author": "Rafal",
"author_id": 1495595,
"author_profile": "https://Stackoverflow.com/users/1495595",
"pm_score": 0,
"selected": false,
"text": "public static class Config\n{\n\n public static class Params1 \n {\n public static string Prop1 => \".... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306378/"
] |
74,161,395 | <p>Disclaimer: Über-noob.</p>
<p>This question may have more to do with how files are executed than what http or node do. I have the following simple-as-all-hell file that will be executed with node to make a local server.</p>
<pre><code>const http = require("http");
const hostname = "127.0.0.1";
const port = 8000;
// Create http server
const server = http.createServer( function (req,res) {
// set response http header with http status and content type
res.writeHead(200, {"Content-Type": "text/plain"});
// send response "hello world"
res.end("G'day mate\n");
});
// Listen on a given port and print a log when it starts listening
server.listen(port, hostname, () => {
console.log("heyy maattteeeyyy")
});
</code></pre>
<p>My question: Why, when I enter the command <code>node hello.js</code> does this file <em>keep executing</em> / keep running? I presume it is something about the final <code>server.listen()</code> command that says "when you run this, just keep running, I am now hosting something", but what exactly is that?</p>
<p>Edit: I would greatly appreciate detailed and exact explanations -- I am just learning, but the purpose of the question is to understand <em>exactly</em> what is going on.</p>
<p>Thank you</p>
| [
{
"answer_id": 74162659,
"author": "CherryDT",
"author_id": 1871033,
"author_profile": "https://Stackoverflow.com/users/1871033",
"pm_score": 3,
"selected": true,
"text": "libuv"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12001578/"
] |
74,161,399 | <p>I have a React component that only expects some values, but I've been passing objects to components a lot regardless of whether the properties of those objects are used in the component or not.</p>
<p>Here is the code example I mean where I pass the <code>Post</code> object to the <code>Title</code> component, that means I also pass the <code>comments</code> even though the <code>Title</code> component doesn't need it.</p>
<pre><code>type Post = {
title: string;
comments: Comment[];
};
function Title({ post }: { post: Post }) {
return <h1>{post.title}</h1>;
}
function Post(post: Post) {
return (
<div>
{/* here: */}
<Title post={post} />
{/* .... */}
</div>
);
}
</code></pre>
<p>And here I just passed the title to the <code>Title</code> component.</p>
<pre><code>type Post = {
title: string;
comments: Comment[];
};
function Title({ title }: { title: string}) {
return <h1>{title}</h1>;
}
function Post(post: Post) {
return (
<div>
{/* here: */}
<Title title={post.title} />
{/* .... */}
</div>
);
}
</code></pre>
<p>What I want to ask is which one should I use better?</p>
| [
{
"answer_id": 74161520,
"author": "Mroxlog",
"author_id": 20305005,
"author_profile": "https://Stackoverflow.com/users/20305005",
"pm_score": 1,
"selected": false,
"text": "type Post = {\n title: string;\n comments: Comment[];\n};\n\nfunction Title({ post }: { post: Post }) {\n const... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11340631/"
] |
74,161,420 | <p>Im trying to put a blurred background image as it follows in html</p>
<pre><code><body>
<div class="fondoIndex"></div>
</body>
</code></pre>
<p>And then with css</p>
<pre><code>.fondoIndex {
background-image: url("images/bg3.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
filter: blur(5px);
}
</code></pre>
<p>But it does not make any effect. No background is shown.
If I remove the close /div tag, the background image is shown and blurred, but so it is with the entire body. :S</p>
<p>Thank you all.</p>
| [
{
"answer_id": 74161520,
"author": "Mroxlog",
"author_id": 20305005,
"author_profile": "https://Stackoverflow.com/users/20305005",
"pm_score": 1,
"selected": false,
"text": "type Post = {\n title: string;\n comments: Comment[];\n};\n\nfunction Title({ post }: { post: Post }) {\n const... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20212503/"
] |
74,161,459 | <pre><code> Container(
child: Row(
children: [
Icon(
Icons.facebook,
color: Colors.blue,
),
RichText(
text: TextSpan(
children: [
TextSpan(
style: defaultText,
text: " Visit Facebook Page",
recognizer: TapGestureRecognizer()..onTap = () async {
var url = "https://www.facebook.com/minorijapaneserestaurant";
if(!await canLaunch(url,)) {
await launch(url);
} else {
throw "Cannot load Url $url";
}
}
)
]
),
)],
),
),
</code></pre>
| [
{
"answer_id": 74161520,
"author": "Mroxlog",
"author_id": 20305005,
"author_profile": "https://Stackoverflow.com/users/20305005",
"pm_score": 1,
"selected": false,
"text": "type Post = {\n title: string;\n comments: Comment[];\n};\n\nfunction Title({ post }: { post: Post }) {\n const... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306517/"
] |
74,161,478 | <p>I am new to nestJS and I am trying to insert bulk data. But I get the following error and I can't seem to find what I am doing wrong here. Some guidance would be highly appreciated.</p>
<p><a href="https://i.stack.imgur.com/jSNfj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jSNfj.png" alt="enter image description here" /></a></p>
<p>stockStyle.entity.ts file:</p>
<pre><code>import {
Column,
ForeignKey,
Model,
Table,
HasMany,
} from 'sequelize-typescript';
import { Stock } from '../stocks/entities/stock.entity';
import { Style } from '../styles/entities/style.entity';
@Table({ tableName: 'stock_style' })
export class StockStyle extends Model<StockStyle> {
@ForeignKey(() => Stock)
@Column
stockId: string;
@ForeignKey(() => Style)
@Column
styleId: number;
}
</code></pre>
<p>stockStyle.service.ts file:</p>
<pre><code>import { Injectable } from '@nestjs/common';
import { StockStyle } from './v1/stockStyles/stockStyle.entity';
@Injectable()
export class StockStylesService {
async bulkInsert() {
const stockStyleArray = [
{ stockId: 'Diamond', styleId: 2 },
{ stockId: 'Gold', styleId: 2 },
{ stockId: 'Ruby', styleId: 2 },
];
StockStyle.bulkCreate(stockStyleArray)
}
}
</code></pre>
| [
{
"answer_id": 74161520,
"author": "Mroxlog",
"author_id": 20305005,
"author_profile": "https://Stackoverflow.com/users/20305005",
"pm_score": 1,
"selected": false,
"text": "type Post = {\n title: string;\n comments: Comment[];\n};\n\nfunction Title({ post }: { post: Post }) {\n const... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11591636/"
] |
74,161,486 | <p>I have a dropdown menu that is supposed to open and close when I click on "dropbtn". It is working perfectly but when I add Use effect so that it also closes when somebody clicks anywhere on the screen but after adding useeffect the dropdown menu is not getting closed when I click on "dropbtn". Here is the code:-</p>
<pre><code>import React, { useState, useEffect } from "react";
export default function App() {
const [listopen, setListopen] = useState(false)
let Dropdown = () => {
if (listopen) {
setListopen(false)
} else {
setListopen(true)
}
}
// Close the dropdown if the user clicks outside of it
useEffect(() => {
if (listopen) {
document.addEventListener("mousedown", () => {
setListopen(false)
})
}
})
return (
<main>
<header>
<nav>
<ul>
<div class="dropdown">
<li><button class="dropbtn" onClick={() => Dropdown()} >USD
<i class="fa fa-caret-down"></i>
</button></li>
<div class="dropdown-content" id="myDropdown" style={{ display: listopen === false ? 'none' : 'block' }}>
<a href="/">Link 1</a>
<a href="/">Link 2</a>
<a href="/">Link 3</a>
</div>
</div>
</ul>
</nav>
</header>
</main>
)
}
</code></pre>
| [
{
"answer_id": 74161798,
"author": "Sandip Jaiswal",
"author_id": 5762924,
"author_profile": "https://Stackoverflow.com/users/5762924",
"pm_score": 1,
"selected": false,
"text": "useEffect(() => {\n const mousedown = () => {\n setListopen(false)\n };\n document.addEventListener(\"m... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20003281/"
] |
74,161,510 | <p>I've this code and it's not working. I know it would be some obvious typo or logical error but I am not able to find it. When I click at any <code>nav-item</code>, it doesn't change the background of body. I'm new to JS. Please help me with this -</p>
<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let body = document.querySelector("body");
let navBack = document.getElementById("navbar");
let introNav = document.querySelector(".nav-item1");
let expNav = document.querySelector(".nav-item2");
let projectsNav = document.querySelector(".nav-item3");
let skillsNav = document.querySelector(".nav-item4");
let contactNav = document.querySelector(".nav-item5");
introNav.addEventListener("click", function() {
body.style.background = introNav.style.background;
navBack.style.background = introNav.style.background
})
expNav.addEventListener("click", function() {
body.style.background = expNav.style.background;
navBack.style.background = expNav.style.background
})
projectsNav.addEventListener("click", function() {
body.style.background = projectsNav.style.background;
navBack.style.background = projectsNav.style.background
})
skillsNav.addEventListener("click", function() {
body.style.background = skillsNav.style.background;
navBack.style.background = skillsNav.style.background
})
contactNav.addEventListener("click", function() {
body.style.background = contactNav.style.background;
navBack.style.background = contactNav.style.background
})</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#navbar {
background: var(--introduction-color);
z-index: 1;
width: 800px;
height: 800px;
border-radius: 50%;
position: absolute;
clip-path: polygon(50% 50%, 0% 100%, 100% 100%);
transform: rotate(-45deg);
top: -400px;
left: -400px;
}
.nav-items {
width: 800px;
height: 800px;
background: #fff;
border-radius: 50%;
position: absolute;
z-index: 3;
cursor: pointer;
clip-path: polygon(50% 50%, 100% 50%, 100% 66%);
}
.nav-item1 {
background: var(--introduction-color);
transform: rotate(45deg);
}
.nav-item2 {
transform: rotate(63deg);
background: var(--experience-color);
}
.nav-item3 {
transform: rotate(81deg);
background: var(--projects-color);
}
.nav-item4 {
transform: rotate(99deg);
background: var(--skills-color);
}
.nav-item5 {
transform: rotate(117deg);
background: var(--contacts-color);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="navbar">
<div class="nav-items nav-item1"></div>
<div class="nav-items nav-item2"></div>
<div class="nav-items nav-item3"></div>
<div class="nav-items nav-item4"></div>
<div class="nav-items nav-item5"></div>
</div></code></pre>
</div>
</div>
</p>
<p>Image - <a href="https://i.stack.imgur.com/3vFGw.png" rel="nofollow noreferrer">Image of the navbar</a></p>
| [
{
"answer_id": 74161864,
"author": "connexo",
"author_id": 3744304,
"author_profile": "https://Stackoverflow.com/users/3744304",
"pm_score": 2,
"selected": true,
"text": "element.style"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18727671/"
] |
74,161,516 | <p>I have a df like this.</p>
<pre><code>Date
2022-10-22
2022-10-21
2022-10-20
</code></pre>
<p>I want to combine and duplicate for each element in this list
<code>['NAB', 'CBA']</code></p>
<p>To get a result df like this.</p>
<pre><code>Date Bank
2022-10-22 NAB
2022-10-22 CBA
2022-10-21 NAB
2022-10-21 CBA
2022-10-20 NAB
2022-10-20 CBA
</code></pre>
<p>Thanks in advance.</p>
| [
{
"answer_id": 74161532,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "merge"
},
{
"answer_id": 74161570,
"author": "Azhar Khan",
"author_id": 2847330,
"author_profil... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8750024/"
] |
74,161,555 | <p>I have the list of [0.5, 1.5, 2.5, 3.5].</p>
<pre><code>def calc_mean(arglist):
return sum(arglist)/len(arglist)
print(calc_mean([0.5, 1.5, 2.5, 3.5]))
</code></pre>
<p>I have another list, <code>strlist = ['0.5','1.5','2.5','3.5']</code> and I need to convert the elements in it to floats and then calculate the average but I'm getting the error:</p>
<p><code>unsupported operand type(s) for +: 'int' and 'str')</code> because the line return sum(arglist)/len(arglist) is working with integers and strlist is a string why strlist isn't being converted to a float and it's being treated as a str even though I converted it using [float(i) if '.' in i else int(i) for i in strlist]</p>
<pre><code>def str2float(strlist):
flist = [float(i) if '.' in i else int(i) for i in strlist]
return flist
strlist = ['0.5','1.5','2.5','3.5']
print(str2float(strlist))
print(calc_mean(strlist))
</code></pre>
| [
{
"answer_id": 74161591,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 2,
"selected": true,
"text": "print(calc_mean(strlist))\n"
},
{
"answer_id": 74161625,
"author": "Giuseppe La Gualano",
"author_id"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20156403/"
] |
74,161,558 | <p>The question below is an extension of <a href="https://stackoverflow.com/questions/74135095/adding-a-column-to-the-data-that-looks-for-a-list-of-words-and-adds-them-if-foun">this question</a>.</p>
<h1>Example data</h1>
<p>I have example data as follows:</p>
<pre><code>library(data.table)
example_dat <- fread("var_nam description
some_var this_is_some_var_kg
other_var this_is_meters_for_another_var
extra_var the_price_of_apples
another_var cost_of_goods_sold")
example_dat$description <- gsub("_", " ", example_dat$description)
var_nam description
1: some_var this is some var kg
2: other_var this is meters for another var
3: extra_var the price of apples
4: another_var cost of goods sold
vector_of_units <- c("kg", "meters", "var")
</code></pre>
<h1>Previous solutions</h1>
<p>I first asked how to create a separate column in this data which looks for certain units listed in a vector (<code>vector_of_units</code>). One option is to <a href="https://stackoverflow.com/a/74135271/8071608">use this answer by maydin</a>. Which gets out all matches.</p>
<pre><code>library(tidyverse)
setDT(example_dat)[, unit := unlist(lapply(example_dat$description,function(x)
paste0(vector_of_units[str_detect(x,vector_of_units)],
collapse = ",")))]
var_nam description unit
1: some_var this is some var Kg kg,var
2: other_var this is meters for another var meters,var
3: extra_var the Price of apples
4: another_var cost of goods sold
</code></pre>
<p>I also found <a href="https://stackoverflow.com/a/71280592/8071608">this answer by langtang</a>, which gets out the first match (which is actually preferable in my situation):</p>
<pre><code>example_dat[, unit:=stringr::str_extract(description, paste0(vector_of_units,collapse = "|"))]
var_nam description unit
1: some_var this is some var kg var
2: other_var this is meters for another var meters
3: extra_var the price of apples <NA>
4: another_var cost of goods sold <NA>
</code></pre>
<p><a href="https://stackoverflow.com/questions/71280466/based-on-vector-of-strings-extract-string-from-data-table-column-into-new-column">Based on vector of strings extract string from data.table column into new column</a></p>
<h1>More flexibility with an ifelse statement</h1>
<p>I would however like to have a little more flexibility.</p>
<p>Firstly, I would like to supply a vector of matches and a vector for pasting separately, so that I can change the hits in to something else:</p>
<pre><code>vector_of_units_in <- c("kg", "meters", "var")
vector_of_units_out <- c("kilogram", "meters", "variable")
vector_of_units_euro <- c("cost", "price")
vector_of_units_euro_out <- "euro"
</code></pre>
<p>Secondly, I would like to be able to choose what happens when there is no hit. For example, when applying the solution by langtang, I want it to not overwrite the first variables with <code>NA</code>.</p>
<p>I have been trying to mess around with langtang's solution:</p>
<pre><code>setDT(example_dat)[, unit := ifelse(!is.na(stringr::str_extract(description, vector_of_units_in)), paste0(vector_of_units_out, collapse = "|"), NA)]
# NA has been replaced by unit, so that it is not overwritten in case of no match
setDT(example_dat)[, unit := ifelse(!is.na(stringr::str_extract(description, vector_of_units_euro)), paste0(vector_of_units_euro_out, collapse = "|"), unit)]
</code></pre>
<p>But I end with this:</p>
<pre><code> var_nam description unit
1: some_var this is some var kg kilogram|meters|variable
2: other_var this is meters for another var kilogram|meters|variable
3: extra_var the price of apples <NA>
4: another_var cost of goods sold <NA>
</code></pre>
<p>How should I write this syntax?</p>
<h1>Desired output</h1>
<pre><code> var_nam description unit
1: some_var this is some var Kg kilogram
2: other_var this is meters for another var meters
3: extra_var the Price of apples euro
4: another_var cost of goods sold euro
</code></pre>
| [
{
"answer_id": 74161591,
"author": "Chris",
"author_id": 15261315,
"author_profile": "https://Stackoverflow.com/users/15261315",
"pm_score": 2,
"selected": true,
"text": "print(calc_mean(strlist))\n"
},
{
"answer_id": 74161625,
"author": "Giuseppe La Gualano",
"author_id"... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8071608/"
] |
74,161,578 | <p>I'm trying to figure out how I can create a scatterplot with the concentration of Enterococci against the Months from this <a href="https://i.stack.imgur.com/frkxU.png" rel="nofollow noreferrer">dataset</a>.</p>
<p>As of now, I've tried this code:</p>
<pre><code>plot(Enterococci..cfu.100ml. ~ Month, data=bacteria_data)
</code></pre>
<p>but to no success, since it produces a 'need finite xlim values' error. Is there a way around this?</p>
<p>The data:</p>
<pre><code>df <- structure(list(Site = c("Avalon Beach", "Avalon Beach", "Avalon Beach",
"Avalon Beach", "Avalon Beach", "Avalon Beach", "Avalon Beach",
"Avalon Beach", "Avalon Beach", "Avalon Beach", "Avalon Beach",
"Avalon Beach", "Avalon Beach", "Avalon Beach", "Avalon Beach",
"Avalon Beach", "Avalon Beach", "Avalon Beach", "Avalon Beach",
"Avalon Beach"), Longitude = c(151.3324, 151.3324, 151.3324,
151.3324, 151.3324, 151.3324, 151.3324, 151.3324, 151.3324, 151.3324,
151.3324, 151.3324, 151.3324, 151.3324, 151.3324, 151.3324, 151.3324,
151.3324, 151.3324, 151.3324), Latitude = c(-33.63587, -33.63587,
-33.63587, -33.63587, -33.63587, -33.63587, -33.63587, -33.63587,
-33.63587, -33.63587, -33.63587, -33.63587, -33.63587, -33.63587,
-33.63587, -33.63587, -33.63587, -33.63587, -33.63587, -33.63587
), Date = c("2018-01-25", "2018-02-07", "2018-02-19", "2018-01-19",
"2018-02-01", "2018-03-08", "2018-03-14", "2018-10-09", "2018-10-31",
"2018-11-07", "2018-11-19", "2018-05-21", "2018-05-25", "2018-06-07",
"2018-06-13", "2018-03-26", "2018-04-10", "2018-05-09", "2018-09-10",
"2018-09-14"), Enterococci..cfu.100ml = c(6L, 0L, 1L, 1L, 2L,
0L, 33L, 5L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 2L, 0L, 0L, 0L, 0L),
Month = c("January", "February", "February", "January", "February",
"March", "March", "October", "October", "November", "November",
"May", "May", "June", "June", "March", "April", "May", "September",
"September"), Day.of.Week = c("Thursday", "Wednesday", "Monday",
"Friday", "Thursday", "Thursday", "Wednesday", "Tuesday",
"Wednesday", "Wednesday", "Monday", "Monday", "Friday", "Thursday",
"Wednesday", "Monday", "Tuesday", "Wednesday", "Monday",
"Friday")), class = "data.frame", row.names = c(NA, -20L))
</code></pre>
| [
{
"answer_id": 74162288,
"author": "TarJae",
"author_id": 13321647,
"author_profile": "https://Stackoverflow.com/users/13321647",
"pm_score": 1,
"selected": false,
"text": "lubridate's"
},
{
"answer_id": 74162314,
"author": "jay.sf",
"author_id": 6574038,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
74,161,608 | <p>I need to create some INDEXES in oracle database tables but always I got the error</p>
<pre><code>ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
</code></pre>
<p>I found in this question solutions to find out the sessions locked the table then kill the session but the table inserts each seconds a lot of results from interface sessions because this table interfaced with laboratory instruments and the machines insert laboratory results from the interface always ,</p>
<p>this is the solution I found :</p>
<pre><code>https://stackoverflow.com/questions/4842765/ora-00054-resource-busy-and-acquire-with-nowait-specified-or-timeout-expired
</code></pre>
<p>but I cannot do it also I cannot stop the interface</p>
<p>Is there any other way to execute CREATE INDEX without kill the sessions or stop the interface ?</p>
<p>this is the DDL command :</p>
<pre><code>CREATE INDEX LAB_RESULTS_A_IDX3 ON LAB_RESULT_STS
(HOSPITAL_NO, LAB_ORDER_NO, SAMPLE_NO, PROVIDING_RESOURCE, SERV_NO,
END_RESULT)
LOGGING
TABLESPACE TRNG_IDX
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 1181960K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
COMPRESS 1;
</code></pre>
| [
{
"answer_id": 74162288,
"author": "TarJae",
"author_id": 13321647,
"author_profile": "https://Stackoverflow.com/users/13321647",
"pm_score": 1,
"selected": false,
"text": "lubridate's"
},
{
"answer_id": 74162314,
"author": "jay.sf",
"author_id": 6574038,
"author_prof... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161608",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18314179/"
] |
74,161,609 | <p>I’m building an application using Nuxt 3, I want to add a page loader until the website loads.</p>
| [
{
"answer_id": 74183609,
"author": "florian_",
"author_id": 13482004,
"author_profile": "https://Stackoverflow.com/users/13482004",
"pm_score": 1,
"selected": false,
"text": "<NuxtLoadingIndicator>"
},
{
"answer_id": 74511681,
"author": "Muhammad Mahmoud",
"author_id": 17... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15273862/"
] |
74,161,611 | <p>I'm trying to find any number of <em><strong>words</strong></em> at the beginning or end of a string with a maximum of 20 characters.</p>
<p>This is what I have right now:</p>
<pre><code>s1 = "Hello, World! This is a reallly long string"
match = re.search(r"^(\b.{0,20}\b)", s1)
print(f"'{match.group(0)}'") # 'Hello, World! This '
</code></pre>
<p>My problem is the extra space that it adds at the end. I believe this is because \b matches either the beginning or the end of the string but I'm not sure what to do about it.</p>
<p>I run into the same issue if I try to do the same with the end of the string but with a leading space instead:</p>
<pre><code>s1 = "Hello, World! This is a reallly long string"
match = re.search(r"(\b.{0,20}\b)$", s1)
print(f"'{match.group(0)}'") # ' reallly long string'
</code></pre>
<p>I know I can just use rstrip and lstrip to get rid of the leading/trailing whitespace but I was just wondering if there's a way to do it with regex.</p>
| [
{
"answer_id": 74183609,
"author": "florian_",
"author_id": 13482004,
"author_profile": "https://Stackoverflow.com/users/13482004",
"pm_score": 1,
"selected": false,
"text": "<NuxtLoadingIndicator>"
},
{
"answer_id": 74511681,
"author": "Muhammad Mahmoud",
"author_id": 17... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12395605/"
] |
74,161,648 | <p>I have a question with the random string in python django.</p>
<p>I have created a django model</p>
<pre><code>class Post(models.Model):
slug = models.SlugField(unique=True,blank=True)
title = models.CharField(max_length=200)
description = models.TextField()
def save(self, *args, **kwargs):
str_ran = "abcdefghijklmnopqrstuvwxyz"
slug = ""
for i in range(5) :
slug += random.choice(str_ran)
self.slug = slug
super(Post, self).save(*args, **kwargs)
</code></pre>
<p>But sometimes that's have some error because the slug field is not unique by python random isn't random a unique string.</p>
<p>What should i do?
Do you have some recommend for random these string to make sure it will be unique?</p>
| [
{
"answer_id": 74183609,
"author": "florian_",
"author_id": 13482004,
"author_profile": "https://Stackoverflow.com/users/13482004",
"pm_score": 1,
"selected": false,
"text": "<NuxtLoadingIndicator>"
},
{
"answer_id": 74511681,
"author": "Muhammad Mahmoud",
"author_id": 17... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18907677/"
] |
74,161,664 | <p><strong>Scenario</strong>: Have 2 git branches main and develop. From develop branch I created a new branch with the name test. Did some changes in the test branch and am ready to merge it into the main branch. But before merging I need to get other changes made by another user to develop the branch and keep mine. Only after it, I can merge the test to the main.</p>
<p>Precondition: 2 branches main and develop</p>
<p>Step 1: create new branch develop -> test</p>
<p>Step 2: add some code to test branch</p>
<p>Step 3: bring changes from develop -> test (Note: update and keep my changes in test)</p>
<p>Step 4: merge test -> main</p>
<p>How can I perform step 3.</p>
| [
{
"answer_id": 74161692,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "develop"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16915268/"
] |
74,161,684 | <p>Link: <a href="https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-analyze-in-excel#save-and-share-your-new-workbook" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/power-bi/collaborate-share/service-analyze-in-excel#save-and-share-your-new-workbook</a></p>
<blockquote>
<p>When a user opens the workbook that you’ve shared your workbook with
them, they see your PivotTables and data as they were when you last
saved the workbook.</p>
</blockquote>
<p>Does RLS not apply when an excel file is shared with another user?</p>
<p>For exmaple: suppose I have RLS to restrict myself only to see country A. But if person having access to country B opens the analyze in excel report and saves this and shares it to me, then will I see country B even though I don't have access to country B?</p>
<p>Ofcourse if I refresh it will only show me country A based on my RLS.</p>
| [
{
"answer_id": 74161692,
"author": "Tim Biegeleisen",
"author_id": 1863229,
"author_profile": "https://Stackoverflow.com/users/1863229",
"pm_score": 2,
"selected": true,
"text": "develop"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1779091/"
] |
74,161,689 | <p>I am trying to create sequence that stored in db.
So just only with one service call I should get new sequence by order like AAB.
Next call should return AAC, next AAD.... AA9, ABA...
I tried to create three number sequences 0<=first_seq<36, also like this second_seq, third_seq.
I am using spring hibernate, postgresql.</p>
| [
{
"answer_id": 74161991,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "static final String DIGITS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\nstatic final int LENGTH = 3;\nstatic int SEED = 0;\n... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306721/"
] |
74,161,751 | <p>I want to make a generic Modal,so if I click add button I want the modal to open with Add functionality and if I click the edit button, I want the same modal but with edit functionnalities..like change the order</p>
<p>Here is my code</p>
<pre><code><c-row>
<c-col>
<button style="float: right;" cButton color="primary" (click)="onAddFamille()">Add Famille</button> //Add button
</c-col>
</c-row>
<c-row>
<table [striped]="true" cTable>
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Libelle</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let famille of familles">
<th scope="row">{{famille.id}}</th>
<td>{{famille.libelle}}</td>
<td>
<button cButton color="primary" (click)="onUpdate(famille.id)">
<svg cIcon name="cilPen" size="sm" title="Numbered List Icon"></svg>
</button>
|
<button cButton color="danger">
<svg cIcon name="cilTrash" size="sm" title="Numbered List Icon"></svg>
</button>
</td>
</tr>
</tbody>
</table>
</c-row>
</c-card-body>
</c-card>
</div>
//Modal
<c-modal id="liveDemoModal" [visible]="visible" (visibleChange)="handleLiveDemoChange($event)">
<c-modal-header>
<h2 cModalTitle>Modal title</h2>
<button (click)="toggleLiveDemo()" cButtonClose></button>
</c-modal-header>
<c-modal-body>
<label cLabel for="exampleFormControlInput1">Libelle</label>
<c-input-group class="flex-nowrap">
<input
aria-describedby="addon-wrapping"
aria-label="Libelle"
cFormControl
placeholder="Libelle"
id="libelle"
sizing="lg"
[(ngModel)] = "famille.libelle"
name="libelle"
/>
</c-input-group>
</c-modal-body>
<c-modal-footer>
<button (click)="toggleLiveDemo()" cButton color="secondary">
Close
</button>
<button cButton color="primary" (click)="updateFamille()">Save changes</button>
</c-modal-footer>
</c-modal>
</code></pre>
<p>and here is my Ts code</p>
<pre><code>onUpdate(famille:any){
this.visible = !this.visible;
this.familleService.getFamille(famille)
.subscribe(
(successResponse) =>{
this.famille = successResponse;
},
(errorResponse) =>{
console.log(errorResponse)
}
)
}
onAddFamille( ){
this.visible = !this.visible;
}
</code></pre>
<p>the update is working very well but if I click edit button and then click the add button the form comes with th name of the last clicked edit input</p>
| [
{
"answer_id": 74161991,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "static final String DIGITS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\nstatic final int LENGTH = 3;\nstatic int SEED = 0;\n... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18064065/"
] |
74,161,763 | <p>When creating a checkout session, I am providing line items with <code>price_data</code> and <code>quantity</code> and in the checkout I see the correct amount. For some payments the customer can use their in-app points which will reduce some amount from the total checkout amount. How can I apply that to the checkout?</p>
<p>Example:<br />
You buy 3 T-shirts (3x20) and one cap (1x15) which means you need to pay 75.00 (of some unit)<br />
You use the in-app option to use your points which gives you 5.00, so now your checkout session must be a custom value (70.00).</p>
<p>I am using this API:<br />
<a href="https://stripe.com/docs/api/checkout/sessions/create" rel="nofollow noreferrer">https://stripe.com/docs/api/checkout/sessions/create</a></p>
<p>The only solution that I came up with was to create a <a href="https://stripe.com/docs/api/coupons" rel="nofollow noreferrer">coupon</a> right before creating the checkout and apply it to the checkout, but I don't know if that's safe.</p>
| [
{
"answer_id": 74161991,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "static final String DIGITS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\nstatic final int LENGTH = 3;\nstatic int SEED = 0;\n... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19363672/"
] |
74,161,769 | <p>I want to <em><strong>improve the loop performance</strong></em> where it counts word occurrences in text, but it runs <em><strong>around 5 minutes for 5 records now</strong></em></p>
<p>DataFrame</p>
<pre><code>No Text
1 I love you forever...*500 other words
2 No , i know that you know xxx *100 words
</code></pre>
<p>My word list</p>
<pre><code>wordlist =['i','love','David','Mary',......]
</code></pre>
<p>My code to count word</p>
<pre><code>for i in wordlist :
df[i] = df['Text].str.count(i)
</code></pre>
<p>Result :</p>
<pre><code>No Text I love other_words
1 I love you ... 1 1 4
2 No, i know ... 1 0 5
</code></pre>
| [
{
"answer_id": 74162147,
"author": "Nick",
"author_id": 9473764,
"author_profile": "https://Stackoverflow.com/users/9473764",
"pm_score": 3,
"selected": true,
"text": "Counter"
},
{
"answer_id": 74163254,
"author": "SergFSM",
"author_id": 18344512,
"author_profile": "... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10020470/"
] |
74,161,772 | <p>I have the table in google-sheets which looks:</p>
<p><a href="https://i.stack.imgur.com/Ati2F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ati2F.png" alt="enter image description here" /></a></p>
<p>I need to sum sums according to the Card = "HDFC"</p>
<p><strong>i.e need to display in cell 1408.8</strong></p>
<p>Need help here.</p>
<p>I Tried:</p>
<pre><code>=COUNTIF(C3:C1000,"HDFC")
</code></pre>
<p>but its give count only not sure how to use to get sumif on column B if matches column C</p>
| [
{
"answer_id": 74162147,
"author": "Nick",
"author_id": 9473764,
"author_profile": "https://Stackoverflow.com/users/9473764",
"pm_score": 3,
"selected": true,
"text": "Counter"
},
{
"answer_id": 74163254,
"author": "SergFSM",
"author_id": 18344512,
"author_profile": "... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1328587/"
] |
74,161,794 | <p>Suppose we have a class <code>A</code>:</p>
<pre class="lang-cpp prettyprint-override"><code>class A{
int a_;
public:
friend class B;
A(int a):a_(a){}
int getA(){ return a_;}
void setA(int a){a_ = a;}
void print(int x){cout << x << endl;}
};
</code></pre>
<p>and another class <code>B</code>:</p>
<pre class="lang-cpp prettyprint-override"><code>class B{
int b_;
public:
B(int b):b_(b){}
void setB(int b){b_ = b;}
int getB(){return b_;}
//friend void A::print(int x);
};
</code></pre>
<p>How to use a method of class A like print() using an object of class B?</p>
<pre class="lang-cpp prettyprint-override"><code>//main.cpp
B b1(10);
b1.print(b1.getB());
</code></pre>
| [
{
"answer_id": 74161879,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 1,
"selected": true,
"text": "B"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15589188/"
] |
74,161,799 | <p>I want to create a button with two icons. One at the left edge and at the right edge.
How can I do it?</p>
<p>example:
<a href="https://archive.qooxdoo.org/current/playground/#Hello%20World-ria" rel="nofollow noreferrer">https://archive.qooxdoo.org/current/playground/#Hello%20World-ria</a></p>
| [
{
"answer_id": 74161879,
"author": "Jason Liam",
"author_id": 12002570,
"author_profile": "https://Stackoverflow.com/users/12002570",
"pm_score": 1,
"selected": true,
"text": "B"
}
] | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20300850/"
] |
74,161,800 | <p>Write a function that expects two lists of integers, a and b, as parameters and returns a list. The function should merge the elements of both input lists by index and return them as tuples in a new list. If one list is shorter than the other, the last element of the shorter list should be repeated as often as necessary. If one or both lists are empty, the empty list should be returned.</p>
<p>Please consider the following examples:</p>
<pre><code>merge([0, 1, 2], [5, 6, 7]) # should return [(0, 5), (1, 6), (2, 7)]
merge([2, 1, 0], [5, 6]) # should return [(2, 5), (1, 6), (0, 6)]
merge([], [2, 3]) # should return []
</code></pre>
<p>You can assume that the parameters are always valid lists and you do not need to provide any kind of input validation.</p>
<p>My attempt:</p>
<pre><code>def merge(a, b):
if len(a) == 0 or len(b) == 0:
mergelist = []
elif len(a) > len(b):
for i in range(0, len(b)):
mergelist = [a[i], b[i]]
for i in range(len(b), len(a)):
mergelist = [a[i], b[len(b)]]
elif len(b) > len(a):
for i in range(0, len(a)):
mergelist = [a[i], b[i]]
for i in range(len(a), len(b)):
mergelist = [a[len(a)], b[i]]
return mergelist
print(merge([0, 1, 2], [5, 6]))
</code></pre>
<p>Can someone tell me why my code is wrong? My IDE says</p>
<blockquote>
<p>the list index is out of range</p>
</blockquote>
<p>but i checked it over and over, it isn't,,,i think.</p>
<p>EDIT: I didn't think so many people would help me and give me their version of the code. They are extremely helpful. Thank you all so much!!!</p>
| [
{
"answer_id": 74161906,
"author": "perpetualstudent",
"author_id": 12370687,
"author_profile": "https://Stackoverflow.com/users/12370687",
"pm_score": 2,
"selected": false,
"text": "mergelist = [a[i], b[i]]"
},
{
"answer_id": 74161960,
"author": "Xin Cheng",
"author_id":... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9305280/"
] |
74,161,803 | <p>I want to write a <code>call</code> function:</p>
<pre><code>function call<F extends (...arg: any) => any, P extends Parameters<F>>(
fn?: F,
...arg: P
): ReturnType<F> | undefined {
if (fn) return fn(...arg) // Type 'P' must have a '[Symbol.iterator]()' method that returns an iterator
}
const fn = (a: string) => {}
// automatically infer `fn` arguments type
call(fn, )
</code></pre>
<p>what should I do?</p>
| [
{
"answer_id": 74162199,
"author": "Svetoslav Petkov",
"author_id": 11612861,
"author_profile": "https://Stackoverflow.com/users/11612861",
"pm_score": 0,
"selected": false,
"text": "Hey this will be an array, believe me"
},
{
"answer_id": 74163872,
"author": "caTS",
"aut... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14175485/"
] |
74,161,810 | <p>I have a function <code>ℚ -> ℚ -> Bool</code> taking a Cartesian coordinate, where <code>true</code> stands for black and <code>false</code> for white. Is there any existing library that I can use to "rasterize" it into a bitmap image?</p>
| [
{
"answer_id": 74168654,
"author": "user2667523",
"author_id": 2667523,
"author_profile": "https://Stackoverflow.com/users/2667523",
"pm_score": 0,
"selected": false,
"text": "m x n"
},
{
"answer_id": 74170187,
"author": "123omnomnom",
"author_id": 13595001,
"author_p... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5522635/"
] |
74,161,888 | <p>I have been learning and working with typescript. I am just curious to find out the correct signatures of express middlewares.
I have been defining middlewares as:</p>
<pre class="lang-js prettyprint-override"><code>const middleware = async(req: Request, res: Response, next: NextFunction) => {
// Middleware code here
if(ok)
next()
// Or I do
return next()
}
</code></pre>
<p>Is this the correct way? What is considered the best practice?
Also what is supposed to be the return type of middlewares?</p>
| [
{
"answer_id": 74161953,
"author": "Charlie",
"author_id": 4185234,
"author_profile": "https://Stackoverflow.com/users/4185234",
"pm_score": 0,
"selected": false,
"text": "RequestHandler"
},
{
"answer_id": 74162066,
"author": "Sandip Jaiswal",
"author_id": 5762924,
"a... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13227171/"
] |
74,161,897 | <p>I have a gradle Copy task that copies assets from the project directory into the build directory:</p>
<pre><code>tasks.register("copyAssets", Copy) {
def fromDir = "${project.projectDir.toString()}/../assets"
def toDir = "${project.buildDir.toString()}/assets"
println "Copying assets"
println " from $fromDir"
println " into $toDir"
from fromDir
into toDir
}
build.dependsOn copyAssets
run.dependsOn copyAssets
</code></pre>
<p>This works, but somehow it not only runs on <em>build</em> and <em>run</em>, but also on <em>clean</em>.</p>
<p>If I remove both lines with <code>dependsOn</code>, it doesn't run on <em>build</em>, <em>run</em>, or <em>clean</em>. But as soon as I put the line with <code>build.dependsOn</code> in, the task runs on <em>build</em>, <em>run</em>, and <em>clean</em>. If, on the other hand, I remove <code>build.dependsOn</code> and put in <code>run.dependsOn</code> instead, the outcome is the same: The task runs on <em>build</em>, <em>run</em>, and <em>clean</em>.</p>
<p>How does <code>dependsOn</code> work? How can I make it to run on <em>build</em> and <em>run</em>, but not on <em>clean</em>?</p>
<p>I use gradle wrapper, and it's a multi-module project, i.e.</p>
<pre><code>./gradlew main:clean
./gradlew main:build
./gradlew main:run
</code></pre>
<p>The task is in the <em>main</em> module only, not inside the top-level <code>build.gradle</code>.</p>
| [
{
"answer_id": 74163120,
"author": "PrasadU",
"author_id": 5845802,
"author_profile": "https://Stackoverflow.com/users/5845802",
"pm_score": -1,
"selected": false,
"text": "tasks.register(\"copyAssets\", Copy) {\n doLast() {\n def fromDir = \"${project.projectDir.toString()}/..... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161897",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1823332/"
] |
74,161,924 | <p>If my nested array named <strong>alpha</strong> has exactly same value as the object property in <strong>bravo</strong>, the object value should be added into the <strong>cost</strong>. After all the values in the fist nested array had finished went through the for-loop, the cost should be pushed into an array named <strong>charlie</strong>. However, I run <strong>console.log(charlie)</strong> and find that all values in <strong>charlie</strong> are <strong>0</strong>, why this happens?</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> var alpha = [["a", "b", "c"],["d", "e"]]
var bravo = { a: 1, b: 2, c: 3, d: 4, e: 999 }
var charlie = [];
//For-loop 1
for(let i = 0; i < alpha.length; i++){
var cost = 0;
const currentAlpha = alpha[i];
//For-loop 2
for(let j = 0; j < currentAlpha.length; j++){
//For-loop 3
for (let x in bravo) {
if (currentAlpha[j] == Object.getOwnPropertyNames(bravo[x])){
cost += bravo[x];
}
}
}
charlie.push(cost);
}
console.log(charlie);</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74163120,
"author": "PrasadU",
"author_id": 5845802,
"author_profile": "https://Stackoverflow.com/users/5845802",
"pm_score": -1,
"selected": false,
"text": "tasks.register(\"copyAssets\", Copy) {\n doLast() {\n def fromDir = \"${project.projectDir.toString()}/..... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13416645/"
] |
74,161,928 | <p>I'm creating a child object using class, but I don't want it to inherit some properties and methods from the parent object.</p>
<p>I want to know if there is any way to do this.</p>
<p>my code:</p>
<pre><code> class Player {
#name;
#marking;
#score;
constructor(){
this.#name = undefined;
this.#marking = undefined;
this.#score = {wins:0,defeats:0};
}
action(){...}
getName(){...}
setName(){...}
...
}
class AIPlayer extends Player{
constructor(){
super();
this.#name = "AI-0.1.2";
}
action(){...}
//I don't want AIPlayer to inherit setName() or #score
}
const p1 = new Player();
p1.setName("Mr.Banana);
console.log(p1.getName()); //-> Mr.Banana
const AIP0 = new AIPlayer();
AIP0.setName("stupid computer"); //->error
console.log(AIP0.getName()); //-> AI-0.1.2
</code></pre>
| [
{
"answer_id": 74162169,
"author": "MJG",
"author_id": 20283130,
"author_profile": "https://Stackoverflow.com/users/20283130",
"pm_score": 0,
"selected": false,
"text": "setName(name) {\n throw \"AI player name can't be modified.\"\n}\n"
},
{
"answer_id": 74175607,
"author":... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20194582/"
] |
74,161,966 | <p>It says I haven't defined the variable even though the code that does that is literally right above it, the error message appears:</p>
<p><em>"Traceback (most recent call last):
File "main.py", line 55, in
if kategoribmi == "underweight":
NameError: name 'kategoribmi' is not defined"</em></p>
<pre><code> if kelas == "('15', 'P')":
if bmi > 28.2:
kategoribmi = "obese"
elif bmi >= 23.6 < 28.2:
kategoribmi = "overweight"
elif bmi <= 15.8:
kategoribmi = "underweight"
else:
kategoribmi = "ideal"
if kategoribmi == "underweight":
underweight()
elif kategoribmi == "overweight":
overweight()
elif kategoribmi == "obese":
obese()
else:
ideal()
</code></pre>
<p>I'm really unsure what to do here, I've tried looking up how to fix this but I'm still unclear.</p>
| [
{
"answer_id": 74162169,
"author": "MJG",
"author_id": 20283130,
"author_profile": "https://Stackoverflow.com/users/20283130",
"pm_score": 0,
"selected": false,
"text": "setName(name) {\n throw \"AI player name can't be modified.\"\n}\n"
},
{
"answer_id": 74175607,
"author":... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16838860/"
] |
74,161,981 | <p>I am new in typescript, and i am trying to write a simple program, but i got this error:</p>
<pre><code>Type 'string' is not assignable to type 'number'.
</code></pre>
<p>How can i solve the problem?</p>
<p>file.ts:</p>
<pre><code>let aged = true;
let realAge = 0 ;
if (aged) {
realAge = '4 years';
}
let dogAge = realAge * 7;
console.log(`${dogAge} years`);
</code></pre>
| [
{
"answer_id": 74162020,
"author": "Tiskae",
"author_id": 13652112,
"author_profile": "https://Stackoverflow.com/users/13652112",
"pm_score": 1,
"selected": false,
"text": "let realAge = 0; // here the type of realAge is inferred to number"
},
{
"answer_id": 74162049,
"author... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16377085/"
] |
74,161,986 | <p>I am currently learning how to use the Bloc state management library in Flutter, and I have a scenario where I would like to listen to an action performed (e.g. clicking a button) and react to that action in a child widget down the widget tree using a Cubit. From the documentation, it seems like the only way to rebuild child widgets is by storing a state object and reacting to changes in the state. However in my case, I don't need to store any state, I just want to know if an action has been done and react every single time it has been invoked.</p>
<p>Given this example below, I want <code>WidgetB</code> to rebuild whenever the button in <code>WidgetA</code> has been pressed, but I can't figure out how to construct my Cubit to allow that without storing some kind of state object.</p>
<pre><code>import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// What should the code be here if I don't want to store any state?
class WidgetACubit extends Cubit<void> {
WidgetACubit({initialState}) : super(initialState);
void doSomething() => emit(null);
}
class App extends StatelessWidget {
App({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: BlocProvider(
create: (_) => WidgetACubit(),
child: WidgetA(),
),
),
);
}
}
class WidgetA extends StatelessWidget {
WidgetA({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: [
ElevatedButton(
onPressed: () {
BlocProvider.of<WidgetACubit>(context).doSomething();
print("Something has been done");
WidgetB.count++;
},
child: const Text("Press me to do something"),
),
WidgetB(),
],
);
}
}
class WidgetB extends StatelessWidget {
static int count = 0;
WidgetB({super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<WidgetACubit, void>(
builder: (context, state) {
return Text("I've been rebuilt $count times");
},
);
}
}
</code></pre>
| [
{
"answer_id": 74162020,
"author": "Tiskae",
"author_id": 13652112,
"author_profile": "https://Stackoverflow.com/users/13652112",
"pm_score": 1,
"selected": false,
"text": "let realAge = 0; // here the type of realAge is inferred to number"
},
{
"answer_id": 74162049,
"author... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8710943/"
] |
74,161,989 | <p>Here is my txt file and i need to get x,y of O</p>
<pre><code>####################
# #
# #
# #
# #
# #
# #
# O #
# #
####################
</code></pre>
| [
{
"answer_id": 74162015,
"author": "Ariel Silver",
"author_id": 16384895,
"author_profile": "https://Stackoverflow.com/users/16384895",
"pm_score": -1,
"selected": false,
"text": "int x = 0\nint y = 0\nfor line in lines\n x = 0\n for character in line\n if character == 'O'\n ... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74161989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18197217/"
] |
74,162,036 | <p>I am making an app that stores its settings in a .txt file. I am able to get the line count, but I don't know, how to store the text in one line in a variable. <br></p>
<p>For example:</p>
<pre><code>linecount = 0
datainfile = []
with open("txt.txt" , "r") as t:
linecount += 1
#Hoe to add lines to datainfile?
config1 = datainfile[0]
</code></pre>
| [
{
"answer_id": 74162015,
"author": "Ariel Silver",
"author_id": 16384895,
"author_profile": "https://Stackoverflow.com/users/16384895",
"pm_score": -1,
"selected": false,
"text": "int x = 0\nint y = 0\nfor line in lines\n x = 0\n for character in line\n if character == 'O'\n ... | 2022/10/22 | [
"https://Stackoverflow.com/questions/74162036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19973965/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.