qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,392,997 | <p>this is my first question on Stackoverflow after one year of Front-end development self-learning. I've already serached foe an answer to my doubts, but since these questions are returning for the third time, I think it's the moment to ask the Web.</p>
<h1><strong>What I'm trying to build</strong></h1>
<h1></h1>
<p>I'm trying to build a library service, where a guest user can login, reserve books, add to wishlist, return etc. For the front-end I'm using <code>react</code>, <code>react-router</code>, <code>react-bootstrap</code> and <code>redux-toolkit</code>. Since I have no knowledge about back-end yet, I fetch data with <code>json-server</code>, which watch a simply database in which there are two big objects: <code>users</code> and the books <code>catalogue</code>.</p>
<h1><strong>The app flow, in my opinion</strong></h1>
<h1></h1>
<p>In the code there is a <code><Catalogue /></code> component, which send a request to the <code>json-server' to get the data (with </code>useEffect<code>), which is stored in the state. When data is fetched, it renders </code>` components, with the necessary info and two buttons. One of them is intended to reserve a book. The logic behind the Reserve Button is:</p>
<ul>
<li>verify <strong>IF</strong> the current user is not an admin</li>
<li>verify <strong>IF</strong> the current user has already reserved THIS book</li>
<li>verify <strong>IF</strong> there is at least one book to reserve in database</li>
</ul>
<p>ONLY IF everything it's ok, the code dispatch the action created with <code>createAsyncThunk</code> in <code>catalogueSlice</code>. In this thunk, it remove a copy of the book from the database and pass the result to the <code>extrareducers</code> to update the state. The handleClick function is <code>async</code> and waits for the end of this action. When the operation is finished, the code dispatch another action, the one created with <code>createAsyncThunk</code> in <code>userSlice</code>, which updates the database, adding that book in the current reservation of that user, and like the other thunk, pass the result to the state, and updates the user's state.</p>
<h1><strong>My doubts and questions</strong></h1>
<h1></h1>
<p><em>My main question</em></p>
<ol>
<li>Where is the correct place for the above IF statements which verify user, current reservations and presence of the book in the database? In the React component or in the createAsyncThunk? I mean: is it better to verify IF an action has to be dispatched, or dispatch the action and block it after? Is it ok for example to call <code>dispatch</code> inside the thunk using the <code>thunkAPI</code>?</li>
</ol>
<p><em>My other doubts</em></p>
<ol start="2">
<li><p>Is it usually better to retrieve the state using <code>useAppSelector</code> or, when it's possible, pass it through the children <code>props</code>?</p>
</li>
<li><p>Until now, I have already <code>reserve</code>, <code>addToWishlist</code>, <code>login</code>, <code>register</code>, which are all created with <code>createAsyncThunk</code>, and results a lot of code in the <code>extrareducers</code> of the slices. I'm planning to add more, which will be other thunks which send request to the server. Is this work-flow ok? I'm doing something big logic mistakes with the back-end?</p>
</li>
<li><p>I don't understand, which is the difference between a <code>thunk</code> and a <code>middleware</code>. Any useful resource?</p>
</li>
</ol>
<p>These are the two main thunk to send the requests. I'm sorry but they're not so clean, but I think it's enough to understand the question.</p>
<pre><code>export const patchCatalogue = createAsyncThunk(
'catalogue/patch',
async ({book, userInfo}: {
book: IBook;
userInfo: IUserInfo;
}, thunkAPI) => {
const {
id: bookId,
book_status: {
copies,
history,
current
}
} = book;
const {
id: userId,
username
} = userInfo;
try {
const response = await axios.patch(
`http://localhost:5000/catalogue/${bookId}`,
{
book_status: {
copies: copies - 1,
current: [...current, [userId, username]],
}
});
if (response.status === 200) {
const result = await thunkAPI.dispatch(reserve({ book, userInfo }))
// console.log(result)
return response.data;
}
}
catch (error) {
console.error(`PATCH failed - ${error}`)
}
},
);
</code></pre>
<pre><code>export const reserve = createAsyncThunk(
'user/reserve',
async ({ book, userInfo }: {
book: IBook;
userInfo: IUserInfo;
}, thunkAPI) => {
const {
id: userId,
reservations: {
current,
history,
}
} = userInfo;
try {
const response = await axios.patch(`http://localhost:5000/users/${userId}`,
{
reservations: {
current: [...current, book],
history: [...history],
}
});
return response.data;
}
catch (error) {
console.error(error)
}
}
);
</code></pre>
<hr />
<p>This is the Button component, which dispatches the two actions.</p>
<pre><code>if (userInfo.role === 'user') {
if (action === 'Book now!') {
const alreadyBooked = userInfo.reservations.current.find(item => item.id === book.id)
if (!alreadyBooked) {
await dispatch(patchCatalogue({ book, userInfo }));
dispatch(reserve({ book, userInfo }))
}
else {
alert('The book is already reserved!')
}
}
</code></pre>
| [
{
"answer_id": 74394478,
"author": "enxaneta",
"author_id": 7897395,
"author_profile": "https://Stackoverflow.com/users/7897395",
"pm_score": 3,
"selected": true,
"text": "d"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74392997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18038472/"
] |
74,393,009 | <p>Hi i doing a mini project of my class. I make the website book ticket for movies. I want to change color of the seat after click. But it just work for first seat. I want it work for other seat. Thank you.</p>
<pre><code>const img=document.getElementById('seat')
let toggle = true;
img.addEventListener('click',function(){
toggle=!toggle;
if(toggle){
img.src = 'seat.png';
}
else{
img.src = 'seat2.png';
}
})
</code></pre>
<p><a href="https://i.stack.imgur.com/BksOR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BksOR.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74393146,
"author": "Luke McCrea",
"author_id": 20463789,
"author_profile": "https://Stackoverflow.com/users/20463789",
"pm_score": 2,
"selected": false,
"text": "function selectSeat(element) {\n element.classList.toggle('active');\n if (!element.classList.contains('active')) {\n element.src = 'seat.png';\n } else {\n element.src = 'seat2.png';\n }\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19636464/"
] |
74,393,012 | <p>I want to convert this piece of code in JUNIT 5 without using @Rule. I tried JUINT 5 TestWatcher but it doens't have starting method.
tried with <a href="https://stackoverflow.com/questions/51012335/how-to-replace-wiremock-rule-annotation-in-junit-5">this </a> but not able to understand how to implement ExtendWith or Extension</p>
<pre><code> @Rule
public TestWatcher watchman = new TestWatcher() {
@Override
public void starting(final Description description) {
logger.info("STARTING test: " + description.getMethodName());
}
};
</code></pre>
| [
{
"answer_id": 74393216,
"author": "Klitos Kyriacou",
"author_id": 638028,
"author_profile": "https://Stackoverflow.com/users/638028",
"pm_score": 1,
"selected": false,
"text": "TestWatcher"
},
{
"answer_id": 74393909,
"author": "Slaw",
"author_id": 6395627,
"author_profile": "https://Stackoverflow.com/users/6395627",
"pm_score": 3,
"selected": true,
"text": "@BeforeEach"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14237523/"
] |
74,393,041 | <p>I have a txt file where from I can extract two strings (type and value). But, I need to cast it to the correct type. See the code bellow.</p>
<pre><code>string type;
string value;
//example 1 //from the txt file
type = "int";
value = "25";
//example 2
type = "double";
value = "1.3";
//example 3
type = "string";
value = "blablabla";
//conversion I would like to do:
dynamic finalResult = (type)element.Value; //this returns an error
</code></pre>
<p>I need to do something like this, but I don't know to create a object type from the content of the string.</p>
<p>I tried to declare a Type:</p>
<pre><code>Type myType = type;
</code></pre>
<p>But I dont know how to do it correctly.</p>
| [
{
"answer_id": 74393268,
"author": "big boy",
"author_id": 17944979,
"author_profile": "https://Stackoverflow.com/users/17944979",
"pm_score": 2,
"selected": false,
"text": "object result;\nstring value = \"some value\";\nstring type = \"some type\";\nswitch(type)\n{\n case \"int\":\n result = Convert.ToInt32(value);\n break;\n case \"double\":\n result = Convert.ToDouble(value);\n break;\n case \"string\":\n result = value;\n break;\n // case \"any other datatype\":\n // result = convert explicitly to that datatype\n}\n"
},
{
"answer_id": 74393331,
"author": "Narish",
"author_id": 12229910,
"author_profile": "https://Stackoverflow.com/users/12229910",
"pm_score": 3,
"selected": true,
"text": ".TryParse()"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19139784/"
] |
74,393,069 | <p>I have a function, that returns <code>Option<Result<X, String>></code> and it calls some functions that return <code>Result<Y, String></code>. How is it possible to use the <code>?</code> operator in a way, that it wraps the error in a <code>Some</code>?</p>
<pre class="lang-rust prettyprint-override"><code>fn other_func() -> Result<Y, String> {
// ...
}
fn my_func() -> Option<Result<X, String>> {
// ...
let value = other_func()?;
// ...
}
</code></pre>
<p>I have two problems:</p>
<ul>
<li>I do not know how to wrap <code>?</code> in <code>Some</code></li>
<li><code>Result<X, String></code> is different from <code>Result<Y, String></code>, but since I only care about the error at that point, it should not matter</li>
</ul>
<p>I am able to solve it with combining match and return, but I would like to use <code>?</code> if it is possible somehow. This is my current solution:</p>
<pre><code>let value = match other_func() {
Ok(value) => value,
Err(msg) => return Some(Err(msg))
};
</code></pre>
| [
{
"answer_id": 74393601,
"author": "Tyler Aldrich",
"author_id": 1580425,
"author_profile": "https://Stackoverflow.com/users/1580425",
"pm_score": 2,
"selected": false,
"text": "?"
},
{
"answer_id": 74394106,
"author": "user4815162342",
"author_id": 1600898,
"author_profile": "https://Stackoverflow.com/users/1600898",
"pm_score": 0,
"selected": false,
"text": "Result<Option<X>, String>"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3042117/"
] |
74,393,089 | <p>I need to join all the three tables as mentioned below</p>
<pre><code>datatype
id code
1 Q_1
2 Q_2
3 Q_3
4 Q_4
5 Q_5
6 Q_6
7 Q_7
8 Q_8
9 Q_9
10 Q_10
</code></pre>
<pre><code>model
id datatype_id values model_ex_id
1 10 0.001 1
2 8 0.008 1
3 9 0.1 4
4 1 0.9 3
5 2 0.6 2
</code></pre>
<pre><code>model_ex
id fk_id city
1 1 ny
2 2 ny
3 2 ca
4 1 ca
</code></pre>
<p>This is the final table should like after doing cross tab or pivot. I tried in many ways using cross tab but nothing working. Thanks for your help</p>
<pre><code>Final_table
id fk_id Q_1 Q_2 Q_3 Q_4 Q_5 Q_6 Q_7 Q_8 Q_9 Q_10
1 1 n n n n n n n 0.08 n 0.001
2 1 n 0.6 n n n n n n n n
3 1 0.9 n n n n n n n n n
4 1 n n n n n n n n 0.1 n
5 2 n n n n n n n 0.08 n 0.001
6 2 n 0.6 n n n n n n n n
7 2 0.9 n n n n n n n n n
8 2 n n n n n n n n 0.1 n
</code></pre>
<pre><code>
with data as (
select me.id,me.fk_id, d.code, m."values"
from model_ex me
join model m on me.id = m.model_ex_id
join datatype d on d.id = m.datatype_id
)
select id, fk_id,
max("values") filter (where code = 'Q_1') as q_1,
max("values") filter (where code = 'Q_2') as q_2,
max("values") filter (where code = 'Q_3') as q_3,
max("values") filter (where code = 'Q_4') as q_4,
max("values") filter (where code = 'Q_5') as q_5,
max("values") filter (where code = 'Q_6') as q_6,
max("values") filter (where code = 'Q_7') as q_7,
max("values") filter (where code = 'Q_8') as q_8,
max("values") filter (where code = 'Q_9') as q_9,
max("values") filter (where code = 'Q_10') as q_10
from data
group by id, fk_id;
I tried the above query but i get the results as
id fk_id Q_1 Q_2 Q_3 Q_4 Q_5 Q_6 Q_7 Q_8 Q_9 Q_10
1 1 n n n n n n n 0.08 n 0.001
2 1 n 0.6 n n n n n n n n
3 1 0.9 n n n n n n n n n
4 1 n n n n n n n n 0.1 n
5 1 n n n n n n n 0.08 n 0.001
6 1 n 0.6 n n n n n n n n
7 1 0.9 n n n n n n n n n
8 1 n n n n n n n n 0.1 n
</code></pre>
<p>I HAVE EDITED THE ABOVE QUESTION The second column has the same values INSTEAD OF UNIQUE fk_id</p>
| [
{
"answer_id": 74393124,
"author": "n3ko",
"author_id": 6493356,
"author_profile": "https://Stackoverflow.com/users/6493356",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE datatype(id serial , code text);\nINSERT INTO datatype\nSELECT r,format('Q_%s' ,r)\nFROM generate_series(1, 10) r;\n\nCREATE TABLE model (id serial , dtid serial , value numeric , exid serial);\nINSERT INTO model\nSELECT unnest(ARRAY[1,2 ,3,4 ,5])\n ,unnest(ARRAY[10,8 ,9,1 ,2])\n ,unnest(ARRAY[0.001,0.008,0.1,0.9,0.6])\n ,unnest(ARRAY[1,1 ,4,3 ,2]);\n\nCREATE EXTENSION crosstab;\n\nSELECT *\nFROM crosstab\n( $x$\n WITH a AS\n (\n SELECT exid, dt.id, dt.code ,SUM(value)\n FROM datatype dt\n JOIN model m\n ON m.dtid = dt.id\n GROUP BY 1,2,3\n ORDER BY 1,2\n ) , b AS\n (\n SELECT exid\n FROM a\n GROUP BY 1\n )\n SELECT b.exid, dt.code, coalesce(a.sum, 0)\n FROM b\n JOIN datatype dt\n ON true\n LEFT JOIN a\n ON a.exid = b.exid AND a.id = dt.id\n ORDER BY 1, 2$x$\n) AS (exid serial , q1 numeric , q2 numeric , q3 numeric , q4 numeric , q5 numeric , q6 numeric , q7 numeric , q8 numeric , q9 numeric , q10 numeric );\n"
},
{
"answer_id": 74393251,
"author": "a_horse_with_no_name",
"author_id": 330315,
"author_profile": "https://Stackoverflow.com/users/330315",
"pm_score": 1,
"selected": false,
"text": "with data as (\n select me.id, d.code, m.\"values\"\n from model_ex me\n join model m on me.id = m.model_ex_id\n join datatype d on d.id = m.datatype_id\n)\nselect id, \n max(\"values\") filter (where code = 'Q_1') as q_1,\n max(\"values\") filter (where code = 'Q_2') as q_2,\n max(\"values\") filter (where code = 'Q_3') as q_3,\n max(\"values\") filter (where code = 'Q_4') as q_4,\n max(\"values\") filter (where code = 'Q_5') as q_5,\n max(\"values\") filter (where code = 'Q_6') as q_6,\n max(\"values\") filter (where code = 'Q_7') as q_7,\n max(\"values\") filter (where code = 'Q_8') as q_8,\n max(\"values\") filter (where code = 'Q_9') as q_9,\n max(\"values\") filter (where code = 'Q_10') as q_10\nfrom data \ngroup by id;\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16966927/"
] |
74,393,100 | <p>How can I replace all '<code>NA</code>' with '<code>NULL</code>' in an <code>R</code> dataframe without specifying column names?
I found <code>replace_na</code> function from <code>tidyr</code> which has an example as:</p>
<pre><code># Replace NAs in a data frame
df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))
df %>% replace_na(list(x = 0, y = "unknown"))
</code></pre>
<p>but my table has more than 10 columns and it could change. Can't specify column names like in the example above.</p>
| [
{
"answer_id": 74393165,
"author": "br00t",
"author_id": 4028717,
"author_profile": "https://Stackoverflow.com/users/4028717",
"pm_score": 2,
"selected": true,
"text": "apply(df, 2, function(x) { x[ is.na(x) ] <- 'NULL'; x})"
},
{
"answer_id": 74393822,
"author": "Baraliuh",
"author_id": 11157753,
"author_profile": "https://Stackoverflow.com/users/11157753",
"pm_score": 0,
"selected": false,
"text": "library(tidyr); library(dplyr, warn.conflicts = FALSE)\ndf <- tibble(x = c(1, 2, NA), y = c(\"a\", NA, \"b\"))\ndf %>% \n mutate(\n across(where(is.numeric), replace_na, 0),\n across(where(is.character), replace_na, \"unknown\")\n )\n#> # A tibble: 3 × 2\n#> x y \n#> <dbl> <chr> \n#> 1 1 a \n#> 2 2 unknown\n#> 3 0 b\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11397513/"
] |
74,393,116 | <p>How can I extract the T3 Period, Year and maximum value?</p>
<p><em>file.json</em></p>
<pre><code>[
{"Fecha":"2022-08-01T00:00:00.000+02:00", "T3_TipoDato":"Avance", "T3_Periodo":"M08", "Anyo":2022, "value":10.4},
{"Fecha":"2022-07-01T00:00:00.000+02:00", "T3_TipoDato":"Definitivo", "T3_Periodo":"M07", "Anyo":2022, "value":10.8},
{"Fecha":"2022-06-01T00:00:00.000+02:00", "T3_TipoDato":"Definitivo", "T3_Periodo":"M06", "Anyo":2022, "value":10.2}
]
</code></pre>
<p>My code:</p>
<pre><code>import json
with open("file.json") as f:
distros_dict = json.load(f)
print (distros_dict)
</code></pre>
| [
{
"answer_id": 74393165,
"author": "br00t",
"author_id": 4028717,
"author_profile": "https://Stackoverflow.com/users/4028717",
"pm_score": 2,
"selected": true,
"text": "apply(df, 2, function(x) { x[ is.na(x) ] <- 'NULL'; x})"
},
{
"answer_id": 74393822,
"author": "Baraliuh",
"author_id": 11157753,
"author_profile": "https://Stackoverflow.com/users/11157753",
"pm_score": 0,
"selected": false,
"text": "library(tidyr); library(dplyr, warn.conflicts = FALSE)\ndf <- tibble(x = c(1, 2, NA), y = c(\"a\", NA, \"b\"))\ndf %>% \n mutate(\n across(where(is.numeric), replace_na, 0),\n across(where(is.character), replace_na, \"unknown\")\n )\n#> # A tibble: 3 × 2\n#> x y \n#> <dbl> <chr> \n#> 1 1 a \n#> 2 2 unknown\n#> 3 0 b\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4032510/"
] |
74,393,148 | <p>I have a simple table as below.</p>
<pre><code>tibble(
"KPI" =c("1 KPI","2 KPI","3 KPI","4 KPI","5 KPI"),
"VALUE" = c(1,500,1,0.20,7.88),
"BENCHMARK" = c(0,473,0,0.39,6.8),
"CRITERIA"= c(">=90%", "Lower than Benchmark", ">=90%","Lower than Benchmark","Higher than Benchmark"),
"APPROVAL" = c( case_when(
(`VALUE` >= 0.9) ~ 1,
(`VALUE` < `BENCHMARK`) ~ 1,
(`VALUE` >= 0.9) ~ 1,
(`VALUE` < `BENCHMARK`) ~ 1,
(`VALUE` > `BENCHMARK`) ~ 1,
TRUE ~ 0))
)
</code></pre>
<p>Does anybody know why I do not have <code>0</code> for the first criteria "Lower than Benchmark"?</p>
| [
{
"answer_id": 74393422,
"author": "pRo",
"author_id": 15230150,
"author_profile": "https://Stackoverflow.com/users/15230150",
"pm_score": 0,
"selected": false,
"text": "case_when"
},
{
"answer_id": 74395840,
"author": "Andrew Lee",
"author_id": 16911286,
"author_profile": "https://Stackoverflow.com/users/16911286",
"pm_score": 2,
"selected": true,
"text": "tibble(\n \"KPI\" =c(\"1 KPI\",\"2 KPI\",\"3 KPI\",\"4 KPI\",\"5 KPI\"),\n \"VALUE\" = c(1, 500, 1, 0.20, 7.88),\n \"BENCHMARK\" = c(0, 473, 0, 0.39, 6.8),\n \"CRITERIA\"= c(\">=90%\", \"Lower than Benchmark\", \">=90%\",\"Lower than Benchmark\",\"Higher than Benchmark\"),\n \"APPROVAL\" = case_when(\n (CRITERIA == \">=90%\") & (VALUE >= 0.9) ~ 1,\n (CRITERIA == \"Lower than Benchmark\") & (VALUE < BENCHMARK) ~ 1,\n (CRITERIA == \"Higher than Benchmark\")& (VALUE > BENCHMARK) ~ 1,\n TRUE ~ 0))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15230150/"
] |
74,393,159 | <p>I'm Trying to get only IP address from below command using Azure cli. But it always coming with extra "".</p>
<pre><code>az network nic ip-config list --resource-group "RG_TEST" --nic-name "TEST_NIC6768" --query "[0].privateIpAddress"
</code></pre>
<p>Output: "10.244.4.4"</p>
<p>Required Output: 10.244.4.4</p>
| [
{
"answer_id": 74393177,
"author": "Mathias R. Jessen",
"author_id": 712649,
"author_profile": "https://Stackoverflow.com/users/712649",
"pm_score": 1,
"selected": false,
"text": "|ForEach-Object Trim '\"'"
},
{
"answer_id": 74393662,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 0,
"selected": false,
"text": "az"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3757924/"
] |
74,393,201 | <p>I am trying to write a function to utilize memoization in a recursive fibonacci function and have the output returned as a string.</p>
<p>My current code is as follows:</p>
<pre><code>let cache = Hashtbl.create 100;;
Hashtbl.add cache 0 0;;
Hashtbl.add cache 1 1;;
let rec f(n:int): string =
match Hashtbl.mem cache n with
| true -> Hashtbl.find cache n
| false ->
let result = (f (n - 1)) + (f (n - 2)) in
Hashtbl.add cache n result;
result
;;
</code></pre>
<p>I was hoping to use this method and use <code>string_of_int</code> at the end to convert result to a string, but am being blocked by this error in line 6: (<code>| true -> Hashtbl.find cache n</code>):</p>
<pre class="lang-none prettyprint-override"><code>This expression has type int but an expression was expected of type string.
</code></pre>
<p>I am assuming that I need a helper function to convert the integer to string but don't understand how the later arithmetic can be done with strings.</p>
<p>I tried converting the int to string before <code>| true -> hashtbl.find cache n</code>, and was expecting for the table to take in my values.</p>
| [
{
"answer_id": 74393177,
"author": "Mathias R. Jessen",
"author_id": 712649,
"author_profile": "https://Stackoverflow.com/users/712649",
"pm_score": 1,
"selected": false,
"text": "|ForEach-Object Trim '\"'"
},
{
"answer_id": 74393662,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 0,
"selected": false,
"text": "az"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18075378/"
] |
74,393,213 | <p>I have a list and I want to find the starting and ending index of value 1.
Here is the list</p>
<pre><code>labels=[0,0,0,1,1,1,0,0,1,1]
</code></pre>
<p>The 1s index are <code>[3,5]</code> and <code>[8,9]</code></p>
<p>Is there any efficient way to do this. I have tried numpy index(), but it did not work for me. Using it, either i can find first or last 1, but not the ones in middle.
This is what I have tried.</p>
<pre><code>[labels.index(1),len(labels)-labels[::-1].index(1)-1]
</code></pre>
<p>This gives me <code>[3,9]</code> but i want to have indexes of consecutive 1s which is <code>[3,5]</code> and <code>[8,9]</code></p>
| [
{
"answer_id": 74393338,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": false,
"text": "diff"
},
{
"answer_id": 74394165,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 0,
"selected": false,
"text": "labels = [0, 0, 0, 1, 1, 1, 0, 0, 1, 1]\n\ndef func(labels):\n result = []\n se = -1\n for i, e in enumerate(labels):\n if e == 1:\n if se < 0:\n se = i\n else:\n if se >= 0:\n result.append([se, i-1])\n se = -1\n if se >= 0:\n result.append([se, len(labels)-1])\n return result\n\nprint(func(labels))\n"
},
{
"answer_id": 74396114,
"author": "Aivar Paalberg",
"author_id": 8663760,
"author_profile": "https://Stackoverflow.com/users/8663760",
"pm_score": 0,
"selected": false,
"text": "from itertools import groupby, compress, count\n\nserie = [0,0,0,1,1,1,0,0,1,1,0,1,0] \n\nstream = compress(*zip(*enumerate(serie))) # indices of 1\n\nconsecutives = ([*streak] for _, streak in groupby(stream, lambda n, c=count(): n - next(c))) # streaks of consecutive numbers\n\nindices = [[el[0], el[-1]] for el in consecutives]\n\n-> [[3, 5], [8, 9], [11, 11]]\n"
},
{
"answer_id": 74404807,
"author": "Alankrith G",
"author_id": 14722381,
"author_profile": "https://Stackoverflow.com/users/14722381",
"pm_score": 0,
"selected": false,
"text": "labels=[0,0,0,1,1,1,0,0,1,1,0,1]\nindices=np.array(np.nonzero(labels))[0]\ncount,result = 0 , []\nfor idx in range(len(indices)-1):\n if indices[idx]+1==indices[idx+1]:\n count+=1\n if idx==len(indices)-2:\n result.append([indices[idx],indices[idx]+1])\n else:\n result.append([indices[idx]-count,indices[idx]])\n count=0\nif indices[-1]-indices[-2]>1:\n result.append([indices[-1],indices[-1]])\nprint(result)\n\nOutput : [[3, 5], [8, 9], [11, 11]]\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11170350/"
] |
74,393,232 | <p>I have a list <code>x = [[2873, 5321, 5421], [2788, 5171, 5271], [2788, 5171, 5271]]</code>.
I want to add <code>y = 400</code>, to each of the elements in the list.
The output should be <code>z = [3273, 5721, 5821], 3188, 5571, 5671], [3188, 5571, 5671]]</code></p>
<p>I tried by using</p>
<pre><code>def add(x,y):
addlists=[(x[i] + y) for i in range(len(x))]
return addlists
z = add(x,y)
</code></pre>
<p>But that didn't work.</p>
<p>I've also tried</p>
<pre><code>def add(x,y):
addlists = [(x[i] + [y]) for i in range(len(x))]
return addlists
z = add(x,y)
</code></pre>
<p>But that returns <code>z = [[2873, 5321, 5421] + 400, [2788, 5171, 5271] + 400, [2788, 5171, 5271]+ 400]</code></p>
| [
{
"answer_id": 74393321,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "x = [[2873, 5321, 5421], [2788, 5171, 5271], [2788, 5171, 5271]]\n\ny = 400\n\nz = [[y + each for each in eachlist] for eachlist in x]\nprint (z)\n# result: \n[[3273, 5721, 5821], [3188, 5571, 5671], [3188, 5571, 5671]]\n"
},
{
"answer_id": 74393489,
"author": "S3DEV",
"author_id": 6340496,
"author_profile": "https://Stackoverflow.com/users/6340496",
"pm_score": 3,
"selected": true,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20471057/"
] |
74,393,250 | <p>I am trying to run migrations in my go-fiber rest API using golang-migrate.</p>
<p>I added the commands for running the migrations in a makefile. However, when I run <code>make migrateup</code>, I get the following error:</p>
<pre><code>migrate -path database/postgres/migrations -database "postgresql://postgres:postgres@localhost:5400/property?sslmode=disable" -verbose up
2022/11/10 18:00:17 error: database driver: unknown driver postgresql (forgotten import?)
make: *** [Makefile:15: migrateup] Error 1
</code></pre>
<p>This is the make file I am using.</p>
<pre><code>#### IMPORT ENV
include .env
DB_URL=postgresql://$(DB_USER):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable
postgres:
docker run --name postgres -p $(DB_PORT):5432 -e POSTGRES_USER=$(DB_USER) -e POSTGRES_PASSWORD=$(DB_PASSWORD) -d postgres:alpine
createdb:
docker exec -it postgres createdb --username=$(DB_USER) --owner=$(DB_OWNER) $(DB_NAME)
dropdb:
docker exec -it postgres dropdb --username=$(DB_USER) $(DB_NAME)
migrateup:
migrate -path database/postgres/migrations -database "$(DB_URL)" -verbose up
migratedown:
migrate -path database/postgres/migrations -database $(DB_URL) -verbose down
.PHONY: postgres createdb dropdb
</code></pre>
<p>Please can anyone help me understand why this is not working?</p>
| [
{
"answer_id": 74393321,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "x = [[2873, 5321, 5421], [2788, 5171, 5271], [2788, 5171, 5271]]\n\ny = 400\n\nz = [[y + each for each in eachlist] for eachlist in x]\nprint (z)\n# result: \n[[3273, 5721, 5821], [3188, 5571, 5671], [3188, 5571, 5671]]\n"
},
{
"answer_id": 74393489,
"author": "S3DEV",
"author_id": 6340496,
"author_profile": "https://Stackoverflow.com/users/6340496",
"pm_score": 3,
"selected": true,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8189936/"
] |
74,393,286 | <p>Have a problem with total count of ajax searche's results.
There is a mistake "Method Illuminate\Database\Eloquent\Collection::total does not exist." if I use directive for example</p>
<pre><code><div class="searched-item">
<a href="#" class="searched-item-res1">{{ __('main.res_found') }} {{$sfilms->total()}} {{ __('main.res_results') }}</a>
</div>
</code></pre>
<p>How to fix it correctly?</p>
<p>blade template:</p>
<pre><code>@if($sfilms)
@if($sfilms->count())
<div class="searched-item">
<a href="#" class="searched-item-res1">{{ __('main.res_found') }} {{$sfilms->count()}} {{ __('main.res_results') }}</a>
</div>
@else
<div class="searched-item">
<a href="#" class="searched-item-res2">{{ __('main.res_found') }} 0 {{ __('main.res_results') }}</a>
</div>
@endif
@foreach($sfilms as $sfilm)
<div class="search-hits">
<ol class="search-hits-list">
<li class="search-hits-item">
<a href="{{ url('films/'.$sfilm->film_id) }}">
<div class="search-img-wrapper">
@if(!is_null($sfilm->films->poster))
<img src="{{$sfilm->films->poster}}" alt="poster" class="news_movies-img">
@else
{{-- <img class="news_movies-img" src="{{ url('/img/no_poster.jpg') }}" alt="poster"/>--}}
<img src="{{asset('storage/poster/' . $sfilm->films->id . '.jpg')}}" alt="poster" class="news_movies-img">
@endif
</div>
<div class="search-hits-wrapper">
<div class="hit-title">
<h3>{{ $sfilm->title }}</h3>
</div>
<div class="hit-title">
<h4>{{ $sfilm->films->orig_title }}</h3>
</div>
<span>
<p class="poster_genre-link">{{ $sfilm->films->country}} {{ $sfilm->films->year }}</p>
</span>
<span>
<p class="poster_genre-link">For age {{ $sfilm->films->age }} +</p>
</span>
</div>
</a>
</li>
</ol>
</div>
@endforeach
@else
<li class="list-group-item">{{ __('search_no_results') }}</li>
@endif
</code></pre>
<p>javascript ajax code:</p>
<pre><code>$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#search').keyup(function() {
var search = $('#search').val();
if (search == "") {
$("#memlist").html("");
$('#result').hide();
} else {
$.get("{{ URL::to('/search') }}", {
search: search
}, function(data) {
$('#memlist').empty().html(data);
$('#result').show();
})
}
});
});
</code></pre>
<p>Controller:</p>
<pre><code>public function search(Request $request) : View
{
$search = $request->input('search');
$locales = app()->getLocale();
if ($locales == NULL) {
$sfilms = Local::where('title_en', 'like', "%$search%")
->orWhere('year', 'like', "$search%")->limit(4)->get();
} else {
$sfilms = Local::where('title' . '_' . $locales, 'like', "%$search%")
->orWhere('year', 'like', "$search%")->limit(4)->get();
}
return view('layouts.found')->with('sfilms', $sfilms);
}
</code></pre>
<p>This works correctly with searched results and I see them, but I don't fix to see exactly count of total results from request.</p>
| [
{
"answer_id": 74393321,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "x = [[2873, 5321, 5421], [2788, 5171, 5271], [2788, 5171, 5271]]\n\ny = 400\n\nz = [[y + each for each in eachlist] for eachlist in x]\nprint (z)\n# result: \n[[3273, 5721, 5821], [3188, 5571, 5671], [3188, 5571, 5671]]\n"
},
{
"answer_id": 74393489,
"author": "S3DEV",
"author_id": 6340496,
"author_profile": "https://Stackoverflow.com/users/6340496",
"pm_score": 3,
"selected": true,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19708349/"
] |
74,393,311 | <p>This is my code:</p>
<pre><code>data ='{"name": " sani", "address": " Czech", "Age": "10", "Gender": "Female"}'
pd.read_json(data) ( I cannot execute this line, it shows that error)
</code></pre>
<p>i tried adding Index= 0 and it didn't work as well</p>
| [
{
"answer_id": 74393321,
"author": "Vin",
"author_id": 7955271,
"author_profile": "https://Stackoverflow.com/users/7955271",
"pm_score": 0,
"selected": false,
"text": "x = [[2873, 5321, 5421], [2788, 5171, 5271], [2788, 5171, 5271]]\n\ny = 400\n\nz = [[y + each for each in eachlist] for eachlist in x]\nprint (z)\n# result: \n[[3273, 5721, 5821], [3188, 5571, 5671], [3188, 5571, 5671]]\n"
},
{
"answer_id": 74393489,
"author": "S3DEV",
"author_id": 6340496,
"author_profile": "https://Stackoverflow.com/users/6340496",
"pm_score": 3,
"selected": true,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20197921/"
] |
74,393,350 | <p>I have a Google Sheet with named ranges that extend beyond columns A-Z. The name ranges have header rows. I would like to use the <code>QUERY</code> function to select columns by their header labels.</p>
<p>My formula is like this:</p>
<pre><code>=QUERY(NamedRange,"SELECT AZ, AX, BM where BB='student' ORDER BY BM DESC",1)
</code></pre>
<p>Answers to other questions on StackOverflow, like that accepted <a href="https://stackoverflow.com/questions/7508477/select-columns-by-name-rather-than-letter-in-google-query-language-gql-with-go">here</a>, haven't worked. Another answer found <a href="https://support.google.com/docs/thread/117505394/formula-to-return-column-letter-of-a-searched-string?hl=en" rel="nofollow noreferrer">here</a> on Google's support page doesn't work for columns beyond Z.</p>
<p>How can I use the <code>QUERY</code> function and select columns beyond column AA by their header labels?</p>
<p><strong>DESIRED OUTPUT / SAMPLE DATA</strong></p>
<p><a href="https://i.stack.imgur.com/eqYQh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eqYQh.png" alt="enter image description here" /></a></p>
<p>A sample spreadsheet with desired output can be found <a href="https://docs.google.com/spreadsheets/d/1Pq60uv2a1H_gGBE2jdhxTOkDM-9ywPwqfLRWlZBB3eQ/edit?usp=sharing" rel="nofollow noreferrer">here</a>.</p>
| [
{
"answer_id": 74393500,
"author": "player0",
"author_id": 5632629,
"author_profile": "https://Stackoverflow.com/users/5632629",
"pm_score": 3,
"selected": true,
"text": "=TRANSPOSE(QUERY(TRANSPOSE(A1:C), \"where Col1 matches 'bb header|student'\", ))\n"
},
{
"answer_id": 74394006,
"author": "ztiaa",
"author_id": 17887301,
"author_profile": "https://Stackoverflow.com/users/17887301",
"pm_score": 0,
"selected": false,
"text": "_BETTERQUERY\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3035713/"
] |
74,393,390 | <p>I see a two ways to setup client in Ignite:</p>
<ol>
<li>then Ignition.start(IgniteConfiguration.clientMode = true)</li>
<li>Ignition.startClient</li>
</ol>
<p>but can't find any details about the first mode in docs.</p>
<p>What's the difference between two ways?</p>
| [
{
"answer_id": 74639965,
"author": "LostShepherd",
"author_id": 6361239,
"author_profile": "https://Stackoverflow.com/users/6361239",
"pm_score": 0,
"selected": false,
"text": "Ignition.setClientMode(true);\nIgniteConfiguration igniteConfiguration = new IgniteConfiguration();\nIgnite ignite = Ignition.start(igniteConfiguration);\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/597376/"
] |
74,393,391 | <p>I'm using a macro that is running into an error (Invalid qualifier) pointing that there is something wrong with the i variable. Hope someone could help me improve this code.</p>
<pre><code>Sub Macro6()
Dim last As Long
Dim i As Long
With ActiveSheet
last = .Cells(.Rows.Count, 1).End(xlDown).Row
For i = last To 1 Step -1
If .Cells(i, 1).Value Like "X" Then
.Cells(i.End(xlDown), 1).EntireRow.Delete
End If
Next i
</code></pre>
<p>This macro is supposed to identify cell with value "X" (that will be located at the end of column A) and then delete all rows below that are empty.</p>
<p>Hope someone could help me.</p>
<p>Many thanks!</p>
| [
{
"answer_id": 74393895,
"author": "BigBen",
"author_id": 9245853,
"author_profile": "https://Stackoverflow.com/users/9245853",
"pm_score": 2,
"selected": true,
"text": "Range.Find"
},
{
"answer_id": 74395219,
"author": "VBasic2008",
"author_id": 9814069,
"author_profile": "https://Stackoverflow.com/users/9814069",
"pm_score": 2,
"selected": false,
"text": "Application.Match"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12886320/"
] |
74,393,426 | <p>In Python, if you want to create a NaN, it must be a float, created as <code>float("nan")</code> (for ex). NaNs having to be floats is also the case in other programming languages (such as C++ or Java).</p>
<p>However, it sometimes would makes sense to have NaNs in "integer typed arrays".</p>
<p>Why doesn't a 'NaN integer' exist?</p>
<p>I am looking for a documented answer on programmatic constraints explaining this pattern.</p>
| [
{
"answer_id": 74393590,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "https://Stackoverflow.com/users/20037042",
"pm_score": 3,
"selected": true,
"text": "00000000"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7094593/"
] |
74,393,470 | <p>I am trying to align two plots, a line plot and bar plot, but the axis is slightly shifted. Can you recommend ways in ggplot2 or patchwork or other faceted plot package. Thanks</p>
<p>reproducible code</p>
<pre><code>data<-data.frame(
Gains=c(NA,18.26,27.7,13.09,-8.36,1.73,5.57,17.1,-31.31,5.43,38.97,18.81,6.12,1.85,NA,16.28,21.18,3.44,-0.14,-3.87,10.57,11.942,-2.12,-0.07,33.34,13.66,14.14,30.66,NA,17.7,24.286,14.638,-7.986,0.622,9.265,3.216,-30.509,4.714,37.78,17.842,11.606,12.188),
Site=c(67,66,61,60,58,57,55,52,48,44,42,39,33,24.5,67,66,61,60,58,57,55,52,48,44,42,39,33,24.5,67,66,61,60,58,57,55,52,48,44,42,39,33,24.5),
Discharge=c(0,18.26,52.16,65.25,56.89,58.62,64.4,81.5,50.19,55.62,94.59,129.37,146.87,154.17,0,16.28,43.09,46.53,46.39,42.52,53.3,65.242,39.46,39.39,72.73,98.21,112.35,143.01,0,17.7,49.266,63.904,55.918,57.67,67.155,78.255,47.746,52.46,90.24,125.092,141.84,162.68)
)
a<-ggplot(data, aes(x=Site, y=Discharge,))+
stat_summary(geom = "ribbon", fun.min = min, fun.max = max, alpha = 0.25) +
stat_summary(geom = "linerange", fun.min = min, fun.max = max, alpha = 0.3) +
stat_summary(geom = "line", fun = mean, size=1.2) +
geom_point(aes(y = Discharge)) +
annotate("rect", xmin = 60, xmax = 57, ymin = -Inf, ymax = Inf,
alpha = .08)+
annotate("rect", xmin = 52, xmax = 44, ymin = -Inf, ymax = Inf,
alpha = .08)+
scale_y_continuous(n.breaks=10)+
scale_x_reverse(n.breaks=10)+
xlab("River Mile")+
ylab("Discharge (cfs)")
b<-ggplot(data, aes(x=Site, y=Gains,))+
stat_summary(geom = "bar", fun = mean)+
#stat_summary(geom = "errorbar",fun.min = min, fun.max = max, alpha = 0.3)+
annotate("rect", xmin = 60, xmax = 57, ymin = -Inf, ymax = Inf,
alpha = .08)+
annotate("rect", xmin = 52, xmax = 44, ymin = -Inf, ymax = Inf,
alpha = .08)+
scale_x_reverse(breaks=seq(20,80,5))+
scale_y_continuous(breaks=seq(-30,50,10))+
ylab("Gain and Loss (cfs)")+
xlab("River Mile")
pwrk<- b/a
pwrk + plot_layout(heights = c(1,2))
</code></pre>
<p><a href="https://i.stack.imgur.com/NEJQO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NEJQO.png" alt="result shows problem" /></a></p>
| [
{
"answer_id": 74393590,
"author": "chrslg",
"author_id": 20037042,
"author_profile": "https://Stackoverflow.com/users/20037042",
"pm_score": 3,
"selected": true,
"text": "00000000"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11069510/"
] |
74,393,486 | <p>So let's say I have this code:</p>
<pre><code>const [test, setTest] = useState();
const [test2, setTest2] = useState();
useEffect(() => {
setTest2(undefined);
}, [test]);
const calledFunction => () {
setTest(whatever);
setTest2(thisIsWhatIwant);
}
return (
<>
{test2}
<button onClick={() => calledFunction}></button>
</>
);
</code></pre>
<p>After all of this code, I will get undefined in test2 even if I want to have "thisIsWhatIwant". So there is a small hack to achieve this:</p>
<pre><code>const [test, setTest] = useState();
const [test2, setTest2] = useState();
useEffect(() => {
setTest2(undefined);
}, [test]);
const calledFunction = () => {
setTest(whatever);
setTimeout(() => setTest2(thisIsWhatIwant), 1);
}
</code></pre>
<p>This will work because <code>setTimeout</code> will push setTest2 to the end of the stack (after the <code>useEffect</code>).</p>
<p>Is this bad practice? If so, is there any way to achieve what I want in a cleaner way?</p>
<p>Thanks.</p>
<p>//edit: calledFunction is called on click, on another button</p>
| [
{
"answer_id": 74393587,
"author": "Tushar Shahi",
"author_id": 10140124,
"author_profile": "https://Stackoverflow.com/users/10140124",
"pm_score": 0,
"selected": false,
"text": "ref"
},
{
"answer_id": 74393886,
"author": "3limin4t0r",
"author_id": 3982562,
"author_profile": "https://Stackoverflow.com/users/3982562",
"pm_score": 3,
"selected": true,
"text": "test2"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17274803/"
] |
74,393,568 | <p>I want to limit value/numbers inside a text input to match the HH:MM format, possibly also limit max hrs input (i.e. max 8) while also preventing any other input format in that field. Ideally would be if a number is entered to high, instead of resetting the field/number set it back to the previous number that was already contained or selected via the range slider (not simply clearing it).</p>
<p><strong>Would I have to extract the first, second, fourth & fifth number from that text field and check them individually or any other approach I could use?</strong></p>
<p>The only other alternative I can think of is using <em>two separate text input fields</em> and display a static colon symbol between them, checking each individually (but entry field may look neater where only hrs and mins are changeable) i.e.</p>
<pre><code>document.getElementById('hrs').addEventListener('keyup', function(){
this.value = (parseInt(this.value) < 0 || parseInt(this.value) > 8 || isNaN(this.value)) ? "00" : (this.value)
});
document.getElementById('mins').addEventListener('keyup', function(){
this.value = (parseInt(this.value) < 0 || parseInt(this.value) > 8 || isNaN(this.value)) ? "00" : (this.value)
});
//still requires a reset to previous value instead of fixed "00"
//I also tried this with just one field but no idea how to target just the first and last double digits separately while ignoring the colon symbol.
</code></pre>
<p>Here is my HH:MM range slider with synced text input field to allow for either input (I haven't found yet any better alternative to this).</p>
<p>HTML
</p>
<pre><code> <script
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"
integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<div class="slidecontainer">
<input type="text" id="durationtimestamp" value="00:00" oninput="durationtimestamp(this.value)" required="required">
<input type="range" min="0" max="480" value="0" class="durationslider" id="durationrange" oninput="durationslider(this.value)">
</div>
</code></pre>
<p>JS</p>
<pre><code>function durationslider(value) {
var hours = Math.floor(value / 60).toLocaleString('en-US', {
minimumIntegerDigits: 2,
//useGrouping: false
});
var minutes = (value % 60).toLocaleString('en-US', {
minimumIntegerDigits: 2,
//useGrouping: false
});
duration = hours+':'+minutes;
document.getElementById("durationtimestamp").value = duration;
}
function durationtimestamp(value) {
var hours = Math.floor(value / 60).toLocaleString('en-US', {
minimumIntegerDigits: 2,
//useGrouping: false
});
var minutes = (value % 60).toLocaleString('en-US', {
minimumIntegerDigits: 2,
//useGrouping: false
});
var myduration = moment.duration(value).asMinutes().toString();
var current = document.getElementById("durationrange").value;
document.getElementById("durationrange").value = myduration;
}
</code></pre>
<p>Demo: <a href="https://jsfiddle.net/markusd1984/u3gfod5x/11/" rel="nofollow noreferrer">https://jsfiddle.net/markusd1984/u3gfod5x/11/</a></p>
| [
{
"answer_id": 74393587,
"author": "Tushar Shahi",
"author_id": 10140124,
"author_profile": "https://Stackoverflow.com/users/10140124",
"pm_score": 0,
"selected": false,
"text": "ref"
},
{
"answer_id": 74393886,
"author": "3limin4t0r",
"author_id": 3982562,
"author_profile": "https://Stackoverflow.com/users/3982562",
"pm_score": 3,
"selected": true,
"text": "test2"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8719001/"
] |
74,393,574 | <p>Is there a way to use <strong>TOP</strong> and <strong>WHERE</strong> multiple times? similar as a for loop to create a table?</p>
<p>I am using the following query to create a table that contains the top 26 records where the value of the column [code] is 11:</p>
<pre><code>SELECT TOP 26 [date]
,[group]
,[code]
,[pol]
,[relation]
FROM [database].[table1] WHERE group in ('A','B','C',...,'Z') and code = '11'
</code></pre>
<p>The problem with this query is that I get 26 records with the value of the column [group] equal to A. This happens because there are thousands of records that meet that criterion.</p>
<p>Ideally, I would like the top 1 of each group (A to Z) with the value of code 11. I could achieve that by running the query above 26 times using <strong>TOP 1</strong> and a different value of group, but this is impractical.</p>
<p>Is there any way to run this query multiple times to get the desired table?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 74393714,
"author": "GRIV",
"author_id": 3092847,
"author_profile": "https://Stackoverflow.com/users/3092847",
"pm_score": 3,
"selected": true,
"text": "CTE"
},
{
"answer_id": 74393762,
"author": "GMB",
"author_id": 10676716,
"author_profile": "https://Stackoverflow.com/users/10676716",
"pm_score": 0,
"selected": false,
"text": "WITH TIES"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10624056/"
] |
74,393,610 | <p>i wanted to ask why my picture is not getting inside the first container when i set it as background image.</p>
<p>did i made the path wrong? <a href="https://i.stack.imgur.com/lGrRW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lGrRW.png" alt="enter image description here" /></a></p>
<p>this is so far the code i have</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<div class="first-image">
<h1>Delije</h1>
</div>
</body>
</html>
.first-image {
background-image: url(./images\pattern.jpeg);
border: 2px solid red;
}
</code></pre>
| [
{
"answer_id": 74393632,
"author": "orghu",
"author_id": 2817442,
"author_profile": "https://Stackoverflow.com/users/2817442",
"pm_score": 1,
"selected": false,
"text": ".first-image {\n background-image: url(images/pattern.jpeg);\n border: 2px solid red;\n}\n"
},
{
"answer_id": 74393648,
"author": "pzelenovic",
"author_id": 717683,
"author_profile": "https://Stackoverflow.com/users/717683",
"pm_score": 0,
"selected": false,
"text": "url(./images\\pattern.jpeg)\n"
},
{
"answer_id": 74393660,
"author": "Sarah",
"author_id": 11161751,
"author_profile": "https://Stackoverflow.com/users/11161751",
"pm_score": 1,
"selected": false,
"text": "background-image: url('./images/pattern.jpeg');"
},
{
"answer_id": 74394718,
"author": "Todd Sierra",
"author_id": 20463345,
"author_profile": "https://Stackoverflow.com/users/20463345",
"pm_score": 0,
"selected": false,
"text": ".first-image {\nbackground-image: url('images/pattern.jpeg');\nborder: 2px solid red;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16850827/"
] |
74,393,652 | <p>Hi I'm designing a grid system in NextJS using Tailwind.
I'm having trouble auto sizing the grids to fit the size of the parent element.</p>
<p>Below are two images to help convey my meaning.</p>
<ol>
<li>Mockup wireframe of the container and grids. (Red = Wrapper, Pink = Layout, Purple = Grids)</li>
</ol>
<p><a href="https://i.stack.imgur.com/hBXcJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hBXcJ.png" alt="enter image description here" /></a></p>
<ol start="2">
<li>What I've managed to code, (I want to resize the right hand boxes to the height of the window.)</li>
</ol>
<p><a href="https://i.stack.imgur.com/yGADv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yGADv.png" 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-html lang-html prettyprint-override"><code><div className="bg-white dark:bg-custom05 md:fixed md:inset-y-0 md:left-0 md:flex md:items-start md:overflow-y-auto md:w-full ">
<div className="min-h-full md:flex md:w-16 md:flex-none md:items-center md:whitespace-nowrap md:py-12 md:leading-7 md:[writing-mode:vertical-rl]">
<div className="flex justify-between text-sm gap-12">
<div className="sm:w-14 sm:h-14 md:w-14 md:h-14 rounded-lg flex items-center justify-center bg-custom03 order-1">Avatar</div>
<div className="sm:w-60 sm:h-14 md:w-14 md:h-60 rounded-lg flex items-center justify-center bg-custom03 order-2">Author Tag Line</div>
<div className="sm:w-14 sm:h-14 md:w-14 md:h-14 rounded-lg flex items-center justify-center bg-custom03 order-3">03</div>
</div>
</div>
<div className="bg-white dark:bg-custom06 relative z-10 mx-auto p-10 md:max-w-md md:min-h-full md:flex-auto md:border-x md:border-custom07">
<div className="grid grid-row-3 grid-flow-row gap-12 text-sm text-center rounded-lg ">
<div className="p-4 rounded-lg bg-custom03 grid place-content-center row-span-6">01</div>
<div className="p-4 rounded-lg bg-custom03 grid place-content-center row-span-6">02</div>
<div className="p-4 rounded-lg bg-custom03 grid place-content-center row-span-6">03</div>
</div>
</div>
<div className="bg-white dark:bg-custom05 relative z-9 p-10 mx-auto md:max-h-full md:flex-auto ">
<div className="grid grid-col-2 grid-flow-col gap-12 text-sm text-center rounded-lg ">
<div className="p-4 rounded-lg bg-custom03 grid place-content-center col-span-2">01</div>
<div className="p-4 rounded-lg bg-custom03 grid place-content-center row-span-2 col-span-2">02</div>
<div className="p-4 rounded-lg bg-custom03 grid place-content-center row-span-3">03</div>
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
<p><strong>Answer Result & Refactor</strong></p>
<p>Thanks to MagnusEffect's help I've been able solve the problem.
Ended up changing some of his styling and made sure to set the padding, gaps and other minor changes, hover its worked fantasticly!</p>
<p><a href="https://i.stack.imgur.com/6AmG5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6AmG5.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74393632,
"author": "orghu",
"author_id": 2817442,
"author_profile": "https://Stackoverflow.com/users/2817442",
"pm_score": 1,
"selected": false,
"text": ".first-image {\n background-image: url(images/pattern.jpeg);\n border: 2px solid red;\n}\n"
},
{
"answer_id": 74393648,
"author": "pzelenovic",
"author_id": 717683,
"author_profile": "https://Stackoverflow.com/users/717683",
"pm_score": 0,
"selected": false,
"text": "url(./images\\pattern.jpeg)\n"
},
{
"answer_id": 74393660,
"author": "Sarah",
"author_id": 11161751,
"author_profile": "https://Stackoverflow.com/users/11161751",
"pm_score": 1,
"selected": false,
"text": "background-image: url('./images/pattern.jpeg');"
},
{
"answer_id": 74394718,
"author": "Todd Sierra",
"author_id": 20463345,
"author_profile": "https://Stackoverflow.com/users/20463345",
"pm_score": 0,
"selected": false,
"text": ".first-image {\nbackground-image: url('images/pattern.jpeg');\nborder: 2px solid red;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13315865/"
] |
74,393,656 | <p>This question is a bit tricky to explain. Say i have an variable whose length is dynamic meaning it is random,i want to change its length to the first 5 or a certain amount of characters regardless of the length of the characters existing in the variable. I hope i could explain what i am trying to do</p>
<p>.________________________________________________________________________.
I really dont know which direction to go in or what step to take in order to reach my goal but i just copy/pasted some random code of the internet that didn't work so i did not think it is of any importance to include in this query,but i could share on demand</p>
| [
{
"answer_id": 74393632,
"author": "orghu",
"author_id": 2817442,
"author_profile": "https://Stackoverflow.com/users/2817442",
"pm_score": 1,
"selected": false,
"text": ".first-image {\n background-image: url(images/pattern.jpeg);\n border: 2px solid red;\n}\n"
},
{
"answer_id": 74393648,
"author": "pzelenovic",
"author_id": 717683,
"author_profile": "https://Stackoverflow.com/users/717683",
"pm_score": 0,
"selected": false,
"text": "url(./images\\pattern.jpeg)\n"
},
{
"answer_id": 74393660,
"author": "Sarah",
"author_id": 11161751,
"author_profile": "https://Stackoverflow.com/users/11161751",
"pm_score": 1,
"selected": false,
"text": "background-image: url('./images/pattern.jpeg');"
},
{
"answer_id": 74394718,
"author": "Todd Sierra",
"author_id": 20463345,
"author_profile": "https://Stackoverflow.com/users/20463345",
"pm_score": 0,
"selected": false,
"text": ".first-image {\nbackground-image: url('images/pattern.jpeg');\nborder: 2px solid red;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17181236/"
] |
74,393,670 | <p>Not quite sure what I'm doing wrong. I have</p>
<pre><code>$description = addslashes($description);
echo "<option onclick='updateTotals(`$urlOptions`,`$option_title`,`$description`)' value='".$description."' selected> ".$description."</option>";
</code></pre>
<p>An example of the text I'm trying to escape is</p>
<pre><code>422458 - 120' Boom if NOZZLE BODIES is CR II single nozzle body
</code></pre>
<p>The source code shows the slashes added in, but the code isn't acknowledging the slash?</p>
<p><a href="https://i.stack.imgur.com/rkHZG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rkHZG.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74393632,
"author": "orghu",
"author_id": 2817442,
"author_profile": "https://Stackoverflow.com/users/2817442",
"pm_score": 1,
"selected": false,
"text": ".first-image {\n background-image: url(images/pattern.jpeg);\n border: 2px solid red;\n}\n"
},
{
"answer_id": 74393648,
"author": "pzelenovic",
"author_id": 717683,
"author_profile": "https://Stackoverflow.com/users/717683",
"pm_score": 0,
"selected": false,
"text": "url(./images\\pattern.jpeg)\n"
},
{
"answer_id": 74393660,
"author": "Sarah",
"author_id": 11161751,
"author_profile": "https://Stackoverflow.com/users/11161751",
"pm_score": 1,
"selected": false,
"text": "background-image: url('./images/pattern.jpeg');"
},
{
"answer_id": 74394718,
"author": "Todd Sierra",
"author_id": 20463345,
"author_profile": "https://Stackoverflow.com/users/20463345",
"pm_score": 0,
"selected": false,
"text": ".first-image {\nbackground-image: url('images/pattern.jpeg');\nborder: 2px solid red;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/945671/"
] |
74,393,671 | <p>I'm pretty new to Ruby and have this scenario of writing multiple if statements. I want to optimize it and trying to find out if there are any other alternatives or better ways of writing the following conditions -</p>
<pre><code> if region == "uk"
value = 1
end
if region == "us"
value = 2
end
if region == "ind"
value = 3
end
if region == "cn"
value = 4
end
</code></pre>
<p>Problem statement - I can't be going on and on if other regions add up to my scenario. Any optimized way of writing the above code ?</p>
<p>Any teachings and solution would be really appreciated!</p>
| [
{
"answer_id": 74393835,
"author": "ScottM",
"author_id": 1326518,
"author_profile": "https://Stackoverflow.com/users/1326518",
"pm_score": 2,
"selected": false,
"text": "case"
},
{
"answer_id": 74393859,
"author": "Taimoor Hassan",
"author_id": 13000257,
"author_profile": "https://Stackoverflow.com/users/13000257",
"pm_score": 0,
"selected": false,
"text": "value = 1 if region == \"uk\"\nvalue = 2 if region == \"us\"\nvalue = 3 if region == \"ind\"\nvalue = 4 if region == \"cn\"\n"
},
{
"answer_id": 74394619,
"author": "Cary Swoveland",
"author_id": 256970,
"author_profile": "https://Stackoverflow.com/users/256970",
"pm_score": 2,
"selected": true,
"text": "region"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400359/"
] |
74,393,689 | <p>I would like to make a custom tooltip for the element, but I have it contained in the box, which doesn't have enough space for the tooltip, so it just crops (well, technically I can scroll to reveal it because <code>overflow</code> is set to <code>auto</code>, but I would like it to be visible without doing that). Is there a way to make it pop over the edge? I have tried using <code>z-index</code> to no result.</p>
<p>Here is what I am talking about:</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>.box {
width: 100px;
height: 100px;
overflow: auto;
border-style: solid;
border-color: red;
}
.tooltip {
padding-top: 20px;
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
display: none;
max-width: 60vw;
min-width: 15vw;
background-color: white;
border-style: solid;
border-color: #1a7bd9;
position: absolute;
z-index: 1000000;
}
.tooltip:hover .tooltiptext {
display: block;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class='box'>
<div class='tooltip'> Hover for tooltip
<div class='tooltiptext'>
Wow, this is amazing, such an epic tooltip text
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
<p>Edit: It is important that hover works on the element, not the box that it is in.</p>
| [
{
"answer_id": 74394023,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".box {\n overflow: visible;\n }\n"
},
{
"answer_id": 74394259,
"author": "John Li",
"author_id": 20436957,
"author_profile": "https://Stackoverflow.com/users/20436957",
"pm_score": 2,
"selected": false,
"text": "::before"
},
{
"answer_id": 74394289,
"author": "abgregs",
"author_id": 3145115,
"author_profile": "https://Stackoverflow.com/users/3145115",
"pm_score": 3,
"selected": true,
"text": "z-index"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9102437/"
] |
74,393,699 | <p>I need a little bit of help to move my command in the same section of copy/paste (context menu).</p>
<p><a href="https://i.stack.imgur.com/nAM2M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nAM2M.png" alt="enter image description here" /></a></p>
<p>I tried to copy the parenting of Copy command that can be found in ShellCmdPlace.vsct without success.</p>
<pre><code> <Group guid="guidSHLMainMenu" id="IDG_VS_CTXT_CMDWIN_CUTCOPY" priority="0x0100">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_COMMANDWINDOW"/>
</Group>
</code></pre>
<p>The only thing that I modified in my vsct file to obtain the result of the screenshot is the parent id of my menuGroup:</p>
<pre><code><Groups>
<Group guid="guidCommand1PackageCmdSet" id="MyMenuGroup" priority="0x0500">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/>
</Group>
</Groups>
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 74394023,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".box {\n overflow: visible;\n }\n"
},
{
"answer_id": 74394259,
"author": "John Li",
"author_id": 20436957,
"author_profile": "https://Stackoverflow.com/users/20436957",
"pm_score": 2,
"selected": false,
"text": "::before"
},
{
"answer_id": 74394289,
"author": "abgregs",
"author_id": 3145115,
"author_profile": "https://Stackoverflow.com/users/3145115",
"pm_score": 3,
"selected": true,
"text": "z-index"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11644133/"
] |
74,393,708 | <p>I am able to move the directory in azure using ShareDirectoryClient successfully.</p>
<pre><code>using System;
using System.Threading.Tasks;
using Azure.Storage.Files.Shares;
namespace SO69798149
{
class Program
{
const string MyconnectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key";
const string MyshareName = "share-name";
const string SourceDirectoryName = "source-directory-name";
private const string RenamedDirectoryName = "new-directory-name";
static async Task Main(string[] args)
{
ShareClient myshare = new ShareClient(MyconnectionString, MyshareName);
ShareDirectoryClient sourceDirectoryClient = myshare.GetDirectoryClient(SourceDirectoryName);
ShareDirectoryClient targetDirectoryClient = myshare.GetDirectoryClient(RenamedDirectoryName);
await RenameDirectory(sourceDirectoryClient, targetDirectoryClient);
Console.WriteLine("Directory renamed.");
}
static async Task RenameDirectory(ShareDirectoryClient sourceDirectoryClient,
ShareDirectoryClient targetDirectoryClient)
{
//Create target directory
await targetDirectoryClient.CreateIfNotExistsAsync();
//List files and folders from the source directory
var result = sourceDirectoryClient.GetFilesAndDirectoriesAsync();
await foreach (var items in result.AsPages())
{
foreach (var item in items.Values)
{
if (item.IsDirectory)
{
//If item is directory, then get the child items in that directory recursively.
await RenameDirectory(sourceDirectoryClient.GetSubdirectoryClient(item.Name),
targetDirectoryClient.GetSubdirectoryClient(item.Name));
}
else
{
//If item is file, then copy the file and then delete it.
var sourceFileClient = sourceDirectoryClient.GetFileClient(item.Name);
var targetFileClient = targetDirectoryClient.GetFileClient(item.Name);
await targetFileClient.StartCopyAsync(sourceFileClient.Uri);
await sourceFileClient.DeleteIfExistsAsync();
}
}
}
//Delete source directory.
await sourceDirectoryClient.DeleteIfExistsAsync();
}
}
}
</code></pre>
<p>I am moving the directory in azure using ShareDirectoryClient. Here How can we zip the folder after moving it.</p>
<p>My Approach:</p>
<pre><code>using System.IO.Compression;
ZipFile.CreateFromDirectory(sourceDirectoryClient.Path, targetDirectoryClient.Path);
</code></pre>
<p>Error: <strong>Could not find a part of the path '/app/NewFolder/test.zip'.</strong></p>
<p>Please assist me in resolving the issue</p>
<p>Note: We can also use the below library
<a href="https://github.com/icsharpcode/SharpZipLib" rel="nofollow noreferrer">https://github.com/icsharpcode/SharpZipLib</a></p>
<blockquote>
<p>Zipping a directory using C# and SharpZipLib</p>
</blockquote>
<pre><code>void fastcompressDirectory(string DirectoryPath, string OutputFilePath, int CompressionLevel = 9)
{
ICSharpCode.SharpZipLib.Zip.FastZip z = new ICSharpCode.SharpZipLib.Zip.FastZip();
z.CreateEmptyDirectories = true;
z.CreateZip(OutputFilePath, DirectoryPath, true, "");
if (File.Exists(OutputFilePath))
Console.WriteLine("D0ne");
else
Console.WriteLine("Failed");
}
</code></pre>
<p>The above code will zip all the folder contents to a new zip file. How can we achieve the same in azure sharedirectoryclient directory.</p>
| [
{
"answer_id": 74420404,
"author": "piotr.gradzinski",
"author_id": 779084,
"author_profile": "https://Stackoverflow.com/users/779084",
"pm_score": 2,
"selected": false,
"text": "ZipFile.CreateFromDirectory"
},
{
"answer_id": 74468262,
"author": "jgasiorowski",
"author_id": 2892208,
"author_profile": "https://Stackoverflow.com/users/2892208",
"pm_score": 1,
"selected": false,
"text": "Main"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2746601/"
] |
74,393,722 | <p>When you make your window smaller the the left sidebar gets in the way and the whole page just becomes a big mess. I am aiming for the left sidebar to scroll when overflown but I dont want it to stick when you scroll on the regular page.</p>
<p>I have tried everything I can think of to fix this problem but I cant seem to figure it out. I am new to most coding languages so that is probably why. I am expecting for the left scroll bar not to stick when I scroll on the main page. I also want the sidebar to scroll when it is overflown</p>
<p>`</p>
<pre><code>
<body onload="checkForName()">
<div class="header">
<a href="#test" id="nameOfCompany"> My Paper Company</a>
<div class="header-right">
<a href="#settings">Settings</a>
<a href="#contact">Contact</a>
<a href="#donate">Donate</a>
<div class="flexcolumn">
</div>
</div>
</div>
<div id="leftmain" class="leftmain">
<p id="button" div="leftmain" onclick='show("htpmain")'> How To Play</p>
</div>
<center>
<div id=htpmain class="main">
<div class="toptext">
<h1>
How To Play
</h1>
<p>This guide will get you start the game and will be helpful to grasp everything you need to do.
</p>
</div>
<div class="card" />
</div>
</center>
</body>
</code></pre>
<pre><code>function checkForName() {
let name = localStorage.getItem("storageName");
if (name != "" && name != null) {
alert("Welcome again " + name);
console.log("User Relogged")
document.getElementById("nameOfCompany").innerHTML = " " + name + "'s Paper Company";
} else {
name = prompt("Please enter your name:", "");
if (name != "" && name != null) {
localStorage.setItem("storageName", name);
console.log("Registered New User")
document.getElementById("nameOfCompany").innerHTML = " " + name + "'s Paper Company";
}
}
}
function hide(item) {
document.getElementById(item).hidden = true
}
function show(item) {
document.getElementById(item).hidden = false
}
hide("htpmain")
</code></pre>
<pre><code>body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.main {
margin-left: 345px;
border: 0px solid #ffffff;
padding: 0px 0px;
flex-direction: column;
align-content: center;
text-align: center;
width: 450px;
}
.card {
display: inline-block;
width: 400px;
height: 160px;
background-color: #404040;
border: 1px solid #404040;
border-radius: 4px;
margin: 0px;
margin-top: 20px;
text-decoration: none;
}
.toptext {
display: inline-block;
width: 400px;
height: 45px;
color: #ffffff;
background-color: #ffffff;
border: 1px solid #ffffff;
border-radius: 4px;
margin: 0px;
margin-top: 5px;
text-decoration: none;
text-align: left;
}
.toptext h1 {
font-size: 20px;
margin-left: 0px;
margin-top: 1px;
color: #404040;
}
.toptext p {
font-size: 12px;
margin-left: 0px;
margin-top: -10px;
color: #404040;
}
.flexcolumn {
flex-direction: column;
}
.leftmain {
height: 100%;
width: 325px;
padding: 0px 10px;
position: fixed;
flex-direction: column;
overflow-y: scroll;
background-color: #333333;
align-content: center;
}
.leftmain p {
float: left;
color: #ffffff;
text-align: left;
padding: 0px 10px;
text-decoration: none;
font-size: 12px;
line-height: 25px;
border-radius: 4px;
background-color: #333333;
width: 300px;
}
.leftmain p:hover {
background-color: #404040;
color: #ffffff;
}
.header {
overflow: hidden;
background-color: #404040;
padding: 10px 10px;
height: 36px;
text-align: center;
}
.header-right {
float: right;
padding: 0px 0px;
}
.header a {
float: left;
color: #ffffff;
text-align: center;
padding: 5px 10px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
align-content: center;
}
.header a:hover {
background-color: #333333;
color: #ffffff;
}
</code></pre>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20471402/"
] |
74,393,725 | <p>I am trying to use Realm as a database with a parent/children relationship and show the data in a hierarchical <a href="https://developer.apple.com/documentation/swiftui/list" rel="nofollow noreferrer">SwiftUI List</a> using the <code>children:</code> initializer. I oriented myself at the <a href="https://www.mongodb.com/docs/realm/sdk/swift/swiftui/" rel="nofollow noreferrer">SwiftUI+Realm tutorial</a>. My Realm class looks like this:</p>
<pre><code>import Foundation
import RealmSwift
class BlockList: RealmSwift.Object, RealmSwift.ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var id: RealmSwift.ObjectId
@Persisted var title: String
@Persisted var childBlockLists = RealmSwift.List<BlockList>()
@Persisted(originProperty: "childBlockLists") var parentBlockList: RealmSwift.LinkingObjects<BlockList>
convenience init(title: String) {
self.init()
self.title = title
}
}
</code></pre>
<p>Then my content view looks like this:</p>
<pre><code>struct ContentView: View {
@ObservedResults(BlockList.self) var blockLists
var body: some View {
let parentBlockLists = blockLists.where {
($0.parentBlockList.count == 0)
}
List(parentBlockLists) { blockList in
Text(blockList.title)
}
.toolbar {
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
func addItem() {
let realm = try! Realm()
let newBlockList = BlockList(title: "New List")
let newSubBlockList = BlockList(title: "New SubList")
newBlockList.childBlockLists.append(newSubBlockList)
try! realm.write {
realm.add(newBlockList)
}
}
}
</code></pre>
<p>This shows all lists that do not have a parent. The next step would be to use <code>List(children:)</code> to show the data hierarchically, ie show those lists that have sublists with a chevron to expand the list.</p>
<p>For this purpose, the children parameter expects the key paths to the child nodes. However, I cannot figure out how to provide that. I tried to write an extension to BlockList and provide a function that casts the children into something useful, but none of my approaches work:</p>
<pre><code>extension BlockList {
var childBlockListsArray: AnyRealmCollection<BlockList> {
AnyRealmCollection(childBlockLists)
// guard let set = childBlockLists as? Array<BlockList>, set.isEmpty == false else { return nil }
// childBlockLists.count == 0 ? nil : AnyRealmCollection(childBlockLists)
// childBlockLists.count == 0 ? nil : Array(childBlockLists)
}
}
</code></pre>
<p>I feel I get closest with casting in <code>AnyRealmCollection</code> and then use</p>
<pre><code>List(AnyRealmCollection(parentBlockLists), children: \.childBlockListsArray)
</code></pre>
<p>But I still get the error</p>
<blockquote>
<p>Key path value type 'AnyRealmCollection' cannot be
converted to contextual type 'AnyRealmCollection?'</p>
</blockquote>
<p>How can I provide the correct <code>Realm</code> data and their children key paths to be shown in SwiftUIs <code>List</code>?</p>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/988975/"
] |
74,393,731 | <p>I'm new to Angular and am trying to make an api call and return a response to my form so that I can show a success message.</p>
<p>Here's the function that is living within my service file</p>
<pre><code>upload(files: any): Observable<any> {
let fileContent = '';
//set the headers
const corsHeaders = new HttpHeaders();
corsHeaders.set('Content-Type', 'text/xml');
corsHeaders.set('Accept', '*/*');
corsHeaders.set('Access-Control-Allow-Origin', '*');
//create form data
const formData = new FormData();
//store form name as "file" with file data
formData.append('UploadedFile', files[0], files[0].name);
this.http
.post(this.baseUrl, formData, {
headers: corsHeaders,
observe: 'events',
reportProgress: true,
})
.subscribe(
(ApiResponse) =>
{
if (ApiResponse.type === HttpEventType.UploadProgress) {
console.log('Upload Progress:' + ApiResponse.loaded + '%');
} else if (ApiResponse.type === HttpEventType.Response) {
console.log("Second stage" + ApiResponse);
} else if (ApiResponse.type === HttpEventType.User)
{
console.log("User Sent a custom message");
}
}
);
return new Observable();
}
</code></pre>
<p>And here is what I have in my component</p>
<pre><code>onUpload() {
this.uploadService
.upload(this.UploadedFiles)
.subscribe(this.validateSvrResponse(Event));
}
</code></pre>
<p>How can I return the results of my service "subscribe" to the <code>this.validateSvrResponse</code> function</p>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2016653/"
] |
74,393,754 | <p>i am trying to generate a list in Prolog that contains all the instances of a variable.
for exemple:</p>
<pre><code>entree( 'foie gras' ).
entree( 'salade gourmande' ).
entree( 'crudites' ).
generateliste(E,L)//L should be L=["foie gras','salade gourmande,'crudites']
</code></pre>
<p>I tried this:</p>
<pre><code>generateliste(E,[E|R]):-entree(E),not(member(E,R)),generateliste(E,R).
</code></pre>
<p>but i know it won't work because there is no base case to stop the recursion ,
can anyone help me please?</p>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20313832/"
] |
74,393,757 | <p>I'm facing a problem with sveltejs. I'm trying to make a really simple frontend server with svelte to figure out if the flow of my backend in nest is ok.</p>
<p>Long story short, the backend make an oauth call to handle authorization and return a session cookie if the user successfully connected.</p>
<p>With insombnia, or postman, even with firefox or chrome, the oauth flow works perfectly fine when I directly call the backend.</p>
<p>But when I want to do this simple call from a sveltejs frontend, the difficulties start to come. I think I don't get really how I can do this with svelte.</p>
<p>Svelte code for "login.svelte" :</p>
<pre><code> <script lang="ts">
import axios from 'axios';
import {push} from 'svelte-spa-router';
$: submit = async() => {
console.log("submit");
const {data} = await axios.get('http://transcendance:8080/api/v2/auth',
{
withCredentials: true,
}
);
if (data.status === "ok") {
push('/');
}
}
</script>
<body>
<main class="form-signin w-100 m-auto">
<button on:click={submit} class="w-100 btn btn-lg btn-primary" type="submit">
Connexion
</button>
</main>
</body>
</code></pre>
<p>The nestjs and svelte server are dockerized. To make things simpler, I'm using a nginx as a reverse proxy - dockerized too - to handle the requests and dispatch them to the front or back end server.</p>
<p>The main problem is that no redirection are performed to the page for the oauth connection, and the requests are blocked due to cors policy. But every call come from the same domain thanks to nginx, and even if I change the cors policy in nestjs, nothing works.</p>
<p>I think that the oauth for the "42 api" don't really understand Xhr requests, but even with a different way, like fetch (to actually fetch nothing) does'nt work.</p>
<p>I think I don't understand how to do such a thing with svelte. If someone can point me something, give an idea, It would be much appreciated. Thanks !</p>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13101402/"
] |
74,393,767 | <p>I want to implement to Vectore3 values as constants values in ResourcesDictionary but sadly an error just appears saying "Vector3 doesn't support direct content"
Is there any way to do this??</p>
<p><a href="https://i.stack.imgur.com/vXlEx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vXlEx.png" alt="Describing image" /></a></p>
<p>I expecting that Vector3 to be applied in xaml directly like x:Double, x:String ...etc</p>
| [
{
"answer_id": 74393880,
"author": "Jimmy",
"author_id": 8940884,
"author_profile": "https://Stackoverflow.com/users/8940884",
"pm_score": 1,
"selected": false,
"text": ".leftmain"
},
{
"answer_id": 74481635,
"author": "Robert Bradley",
"author_id": 20206840,
"author_profile": "https://Stackoverflow.com/users/20206840",
"pm_score": 0,
"selected": false,
"text": "/***** Styling Scrollbars *****/\n\n\n/*** For Firefox ***/\n\n:root {\n scrollbar-width: thin; /* Width of Scrollbar (works with both Vertical and Horizontal bars) */\n}\n\n/*** For Other Browsers | When doing it this way, you cannot style one part of it without specifying all of it ***/\n\n/* Width of Scrollbar */\n::-webkit-scrollbar {\n width: 6px; /* For Vertical Scrollbar */\n height: 6px; /* For Horizontal Scrollbar */\n}\n\n/* Track */\n::-webkit-scrollbar-track {\n background: Whitesmoke; \n}\n \n/* Handle */\n::-webkit-scrollbar-thumb {\n background: hsl(0, 0%, 76%);\n}\n\n/* Handle on hover */\n::-webkit-scrollbar-thumb:hover {\n background: Gray; \n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8665881/"
] |
74,393,790 | <p>I would like to multiply the value in one dataframe (df_a) by the values in another dataframe (df_b) and then take the sum of these values, and append them together for all values in df_a. E.g.
df_a:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>col_x</th>
</tr>
</thead>
<tbody>
<tr>
<td>10</td>
</tr>
<tr>
<td>20</td>
</tr>
</tbody>
</table>
</div>
<p>and df_b:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>col_y</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</tbody>
</table>
</div>
<p>Would result in:
[(10 x 5) + (10 x 6), (20 x 5) + (20 x 6)] or [110, 220]</p>
<p>I think this can be done in a for loop:</p>
<pre><code>for x, y in zip(df_a, df_b):
i = sum(x * y)
a.append(i)
</code></pre>
<p>But this throws an error for float object not being iterable.</p>
| [
{
"answer_id": 74393877,
"author": "I'mahdi",
"author_id": 1740577,
"author_profile": "https://Stackoverflow.com/users/1740577",
"pm_score": 0,
"selected": false,
"text": "broadcasting"
},
{
"answer_id": 74393915,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "(10 x 5) + (10 x 6)"
},
{
"answer_id": 74393922,
"author": "Code Different",
"author_id": 2538939,
"author_profile": "https://Stackoverflow.com/users/2538939",
"pm_score": 1,
"selected": false,
"text": "x = df_a[\"col_x\"].to_numpy()\ny = df_b[\"col_y\"].to_numpy()[:, None]\n\n(x * y).sum(axis=0)\n"
},
{
"answer_id": 74393970,
"author": "suvayu",
"author_id": 289784,
"author_profile": "https://Stackoverflow.com/users/289784",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15243986/"
] |
74,393,883 | <p>I have this piece of code and I feel so dumb for not knowing how to run it. Please help.</p>
<pre><code>class Solution(object):
def countOdds(self, low: int, high: int):
if low % 2 == 0 and high % 2 == 0:
return (high-low)//2
else:
return (high-low)//2 + 1
</code></pre>
<p>I tried running <code>Solution.countOdds(3, 11)</code> but the error showed me that I haven't called <em>self</em>, and I don't know how to make it work.</p>
| [
{
"answer_id": 74393877,
"author": "I'mahdi",
"author_id": 1740577,
"author_profile": "https://Stackoverflow.com/users/1740577",
"pm_score": 0,
"selected": false,
"text": "broadcasting"
},
{
"answer_id": 74393915,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "(10 x 5) + (10 x 6)"
},
{
"answer_id": 74393922,
"author": "Code Different",
"author_id": 2538939,
"author_profile": "https://Stackoverflow.com/users/2538939",
"pm_score": 1,
"selected": false,
"text": "x = df_a[\"col_x\"].to_numpy()\ny = df_b[\"col_y\"].to_numpy()[:, None]\n\n(x * y).sum(axis=0)\n"
},
{
"answer_id": 74393970,
"author": "suvayu",
"author_id": 289784,
"author_profile": "https://Stackoverflow.com/users/289784",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19189038/"
] |
74,393,893 | <p>So if given an offline webapp made up of html5/css/js with standard directories of {[Main Folder] > 0001.html, 0002.html, 0003.html, {[assets folder] > [css],[js],[media]}} is it possible for a search function on 1.html to be able to search the text content of 2.html or 3.html?</p>
<p>I haven't been able to find any specific information about this as most searching people do for a site are for sites intended to be houses on server, but in the case of an offline webapp the files are stored locally which causes a big hangup as webapi REALLY doesnt like a webpage looking at local files, but any images and links are able to be references through the href tag, so is it possible to search the contents of an html file specified through an href?</p>
<p>if given sample html pages:</p>
<p>0001.html</p>
<pre><code><!DOCTYPE html>
<body>
<div class="allSearch">
<div class="search">
<input type="text" id="searchInput" class="searchField"><button id="clear" class="clear">Clear</button>
<button type="button" id="button" class="searchButton">Search</button>
</div>
<div id="searchResults" class="results"></div>
</div>
</body>
</code></pre>
<p>0002.html</p>
<pre><code><!DOCTYPE html>
<body>
<div id="content">
<p>lorem ipsum</p>
</div>
</body>
</code></pre>
<p>Is it possible to search the contents of 0002.html while on 0001.html?</p>
<p>The reason i didn't include more robust markup and js above is that we are working on proprietary html ebooks built in InDesign and exported to html5. our current method of searching involves using a script in InDesign that parses every text box on every page and generates a dictionary that looks something like:</p>
<pre><code>var searchDictionary = {
"Turtle": [1, 2],
"Fish": [2, 3],
"Fox": [3, 4],
"Snake": [4, 5],
"Dragon": [1, 5]
}
</code></pre>
<p>Where the content in "" is a term and the associated array are the page numbers that terms appears on, then you search that dictionary with the following js and return the page numbers that term appears on, which i coded up to pull in a pre-existing thumbnail and create a link to click through to the page:</p>
<pre><code>document.getElementById("button").addEventListener("click", function () {
var query = document.getElementById("searchInput").value.toLowerCase();
var pages = searchDictionary[query];
if (pages === undefined) {
document.getElementById('searchResults').innerHTML = '<p style = \"text-align:center;width:100%\"> Term Not Found </p>';
}
else {
html = ""
html += '<ul>';
pages.forEach(showResults);
html += '</ul>';
}
}, false);
function gotopage(destinationpageNumber) {
var currentpagenumber = $('.page').attr('data-name');
currentpagenumber = parseInt(currentpagenumber);
destinationpageNumber = parseInt(destinationpageNumber.split(' ')[1]);
var distance = destinationpageNumber - currentpagenumber;
var offset = currentpagenumber - nav.current;
nav.to(nav.current+distance);
}
function showResults(value) {
var pageNum = value.toString();
var thumbMid = pageNum.padStart(4,0);
var thumb = '<img src=\"assets/images/pagethumb_' + thumbMid + '_0.jpg\" class=\"searchThumb\">';
var result = "<button id=\"goto\" + class=\"gotopagebutton\">pg. "+ value + "</br>" + thumb + "</button>";
html += '<li class=\"result\">' + result + '</li>';
document.getElementById('searchResults').innerHTML = html;
var gotopagebuttons = document.getElementsByClassName('gotopagebutton');
for (var i = 0; i < gotopagebuttons.length; i++) {
gotopagebuttons[i].addEventListener('click', gotopage.bind(null, gotopagebuttons[i].innerHTML));
};
}
</code></pre>
| [
{
"answer_id": 74393877,
"author": "I'mahdi",
"author_id": 1740577,
"author_profile": "https://Stackoverflow.com/users/1740577",
"pm_score": 0,
"selected": false,
"text": "broadcasting"
},
{
"answer_id": 74393915,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "(10 x 5) + (10 x 6)"
},
{
"answer_id": 74393922,
"author": "Code Different",
"author_id": 2538939,
"author_profile": "https://Stackoverflow.com/users/2538939",
"pm_score": 1,
"selected": false,
"text": "x = df_a[\"col_x\"].to_numpy()\ny = df_b[\"col_y\"].to_numpy()[:, None]\n\n(x * y).sum(axis=0)\n"
},
{
"answer_id": 74393970,
"author": "suvayu",
"author_id": 289784,
"author_profile": "https://Stackoverflow.com/users/289784",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19461674/"
] |
74,393,899 | <p>I tried the 2 solutions posted here to detect a specific words and they do work:</p>
<p><strong>Solution 1</strong></p>
<pre><code>const badMessages = ["bad", "worst"];
badMessages.forEach((word) => {
if (message.content.includes(word)) {
message.reply("Detected.");
}
})
</code></pre>
<p><strong>Solution 2</strong></p>
<pre><code>const badMessages = ["bad", "worst"];
for(var i=0; i<badMessages.length; i++) {
if (message.content.includes(badMessages[i])) {
message.reply("Detected.");
}
}
</code></pre>
<p>However, the condition triggers even when the word in the array for example <strong>bad</strong> is mixed with other words like <strong>"badge"</strong>. How do I detect a specific word by itself which should trigger for the exact "bad" word only and not trigger when it is mixed with other words like badge.</p>
| [
{
"answer_id": 74393877,
"author": "I'mahdi",
"author_id": 1740577,
"author_profile": "https://Stackoverflow.com/users/1740577",
"pm_score": 0,
"selected": false,
"text": "broadcasting"
},
{
"answer_id": 74393915,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "(10 x 5) + (10 x 6)"
},
{
"answer_id": 74393922,
"author": "Code Different",
"author_id": 2538939,
"author_profile": "https://Stackoverflow.com/users/2538939",
"pm_score": 1,
"selected": false,
"text": "x = df_a[\"col_x\"].to_numpy()\ny = df_b[\"col_y\"].to_numpy()[:, None]\n\n(x * y).sum(axis=0)\n"
},
{
"answer_id": 74393970,
"author": "suvayu",
"author_id": 289784,
"author_profile": "https://Stackoverflow.com/users/289784",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/874737/"
] |
74,393,907 | <p>I am trying to get every value from the data array that is above my threshold, and put the values from data array that are above the threshold into a new array.</p>
<p>I found a way to do it but I am using two for loops, that are almost similar.
So I am wondering if there is a way to do it without the two loops.</p>
<pre><code>public int[] getValuesAboveThreshold(int threshold) {
int counter = 0;
int count =0;
for (int i = 0; i < data.length;i++) {
if(data[i] > threshold) {
counter++;
}
}
int [] thresholdArray = new int [counter];
for(int i =0; i <data.length;i++) {
if(data[i] > threshold) {
thresholdArray[count] = data[i];
count++;
}
}
return thresholdArray;
}
</code></pre>
| [
{
"answer_id": 74393999,
"author": "Jared Renzullo",
"author_id": 20409306,
"author_profile": "https://Stackoverflow.com/users/20409306",
"pm_score": 2,
"selected": false,
"text": "public static void main(String[] args) {\n int threshold = 4;\n int[] data = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n int[] filteredArray = getValuesAboveThreshold(data, threshold);\n\n System.out.println(Arrays.toString(filteredArray));\n}\n\nprivate static int[] getValuesAboveThreshold(int[] originalArray, int threshold) {\n return Arrays.stream(originalArray)\n .filter(val -> val > threshold)\n .toArray();\n}\n"
},
{
"answer_id": 74394057,
"author": "Ahmet M",
"author_id": 20382988,
"author_profile": "https://Stackoverflow.com/users/20382988",
"pm_score": 0,
"selected": false,
"text": " public Collection<Integer> getValuesAboveThreshold(int threshold) {\n final Collection<Integer> datasWhichAreGreaterThanThreshold = new ArrayList<>();\n \n for (int i = 0; i < datas.length;i++) {\n final int currentData = datas[i];\n \n if(currentData > threshold) \n datasWhichAreGreaterThanThreshold.add(currentData);\n \n }\n \n return datasWhichAreGreaterThanThreshold;\n } \n \n public Integer[] getValuesAboveThreshold(int threshold) {\n final Collection<Integer> datasWhichAreGreaterThanThreshold = new ArrayList<>();\n \n for (int i = 0; i < datas.length;i++) {\n final int currentData = datas[i];\n \n if(currentData > threshold) \n datasWhichAreGreaterThanThreshold.add(currentData);\n \n }\n \n \n return datasWhichAreGreaterThanThreshold.toArray(Integer[]::new);\n } \n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16854605/"
] |
74,393,912 | <p>I have the following code. It reads inputs of 2 integers and prints the sum of them.
It also tries to check if the user fails to provide the correct inputs, i.e. if by mistake the user inputs string or float, the code will produce an error message and ask the user to enter new inputs again.</p>
<pre><code>I1, I2 = map(int, input('Enter 2 numbers\n').split())
print('Numbers entered, I1, I2 =', I1,I2)
if isinstance(I1, int) == False or isinstance(I2, int) == False:
print('All inputs are not integers, please enter again\n')
else:
print('Sum of the given integers =', I1 + I2)
</code></pre>
<p>However, if one of the inputs is a non-integer (say, 'x'), I get the following error before the <code>if</code> condition checks whether the inputs are correct or not.</p>
<pre><code>ValueError: invalid literal for int() with base 10: 'x'
</code></pre>
<p>Can this be resolved?</p>
| [
{
"answer_id": 74393999,
"author": "Jared Renzullo",
"author_id": 20409306,
"author_profile": "https://Stackoverflow.com/users/20409306",
"pm_score": 2,
"selected": false,
"text": "public static void main(String[] args) {\n int threshold = 4;\n int[] data = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n int[] filteredArray = getValuesAboveThreshold(data, threshold);\n\n System.out.println(Arrays.toString(filteredArray));\n}\n\nprivate static int[] getValuesAboveThreshold(int[] originalArray, int threshold) {\n return Arrays.stream(originalArray)\n .filter(val -> val > threshold)\n .toArray();\n}\n"
},
{
"answer_id": 74394057,
"author": "Ahmet M",
"author_id": 20382988,
"author_profile": "https://Stackoverflow.com/users/20382988",
"pm_score": 0,
"selected": false,
"text": " public Collection<Integer> getValuesAboveThreshold(int threshold) {\n final Collection<Integer> datasWhichAreGreaterThanThreshold = new ArrayList<>();\n \n for (int i = 0; i < datas.length;i++) {\n final int currentData = datas[i];\n \n if(currentData > threshold) \n datasWhichAreGreaterThanThreshold.add(currentData);\n \n }\n \n return datasWhichAreGreaterThanThreshold;\n } \n \n public Integer[] getValuesAboveThreshold(int threshold) {\n final Collection<Integer> datasWhichAreGreaterThanThreshold = new ArrayList<>();\n \n for (int i = 0; i < datas.length;i++) {\n final int currentData = datas[i];\n \n if(currentData > threshold) \n datasWhichAreGreaterThanThreshold.add(currentData);\n \n }\n \n \n return datasWhichAreGreaterThanThreshold.toArray(Integer[]::new);\n } \n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2520186/"
] |
74,393,947 | <p>I have a dataclass and I want to iterate over in in a loop to spit out each of the values. I'm able to write a very short <code>__iter__()</code> within it easy enough, but is that what I should be doing? I don't see anything in the documentation about an 'iterable' parameter or anything, but I just <em>feel like</em> there ought to be...</p>
<p>Here is what I have which, again, works fine.</p>
<pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass
@dataclass
class MyDataClass:
a: float
b: float
c: float
def __iter__(self):
for value in self.__dict__.values():
yield value
thing = MyDataclass(1,2,3)
for i in thing:
print(i)
# outputs 1,2,3 on separate lines, as expected
</code></pre>
<p>Is this the best / most direct way to do this?</p>
| [
{
"answer_id": 74394017,
"author": "suvayu",
"author_id": 289784,
"author_profile": "https://Stackoverflow.com/users/289784",
"pm_score": 2,
"selected": false,
"text": "dataclasses.asdict"
},
{
"answer_id": 74394031,
"author": "ShadowRanger",
"author_id": 364696,
"author_profile": "https://Stackoverflow.com/users/364696",
"pm_score": 3,
"selected": true,
"text": "dataclasses.astuple"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15804190/"
] |
74,393,962 | <p>I'm trying to add a <strong>str</strong> method in my models.py file to my administrative page show me the objects I've register with their own name and not like a 'UserObject(1)'</p>
<p>But when I add this method that's what is happening:</p>
<p>AttributeError at /admin/crud_app/user/
'User' object has no attribute 'first_name'</p>
<p>models.py -></p>
<pre><code>from django.db import models
class User(models.Model):
"""
A normal class that represents an User object, the attributes are those bellow:
"""
first_name = models.CharField(name="First Name", max_length=30)
last_name = models.CharField(name="Last Name", max_length=30)
cpf = models.CharField(name="CPF", max_length=30)
age = models.IntegerField(name="Age")
email = models.EmailField(name="email", max_length=30)
def __str__(self):
return self.first_name
</code></pre>
<p>admin.py -></p>
<pre><code>from django.contrib import admin
from .models import User
admin.site.register(User)
</code></pre>
<p>I try to add the <strong>str</strong> method and I'm was expecting to recive the name that I give to my object registered instead of 'Name object(1)'</p>
| [
{
"answer_id": 74394043,
"author": "Sunderam Dubey",
"author_id": 17562044,
"author_profile": "https://Stackoverflow.com/users/17562044",
"pm_score": 2,
"selected": false,
"text": "f-strings"
},
{
"answer_id": 74431679,
"author": "Parth Mehta",
"author_id": 20297992,
"author_profile": "https://Stackoverflow.com/users/20297992",
"pm_score": 0,
"selected": false,
"text": "class User(models.Model):\n \"\"\"\n A normal class that represents an User object, the attributes are those bellow:\n \"\"\"\n first_name = models.CharField(verbose_name=\"First Name\", max_length=30)\n last_name = models.CharField(verbose_name=\"Last Name\", max_length=30)\n cpf = models.CharField(verbose_name=\"CPF\", max_length=30)\n age = models.IntegerField(verbose_name=\"Age\")\n email = models.EmailField(verbose_name=\"email\", max_length=30)\n\n def __str__(self):\n return self.first_name\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19494781/"
] |
74,393,971 | <p>I'm building a game and there's a score which updates every 5 sec with a timer.</p>
<p>Currently the score lives in a nested Component's state, but I'd like to make it available to other Components as well so it can affect their states (eg. higher score would affect the whole game's background color, the counters on top, and trigger pop-up messages).</p>
<p>I have Redux stores, and it feels like the right place for this score, but which component should be responsible for updating it/have the timer running?</p>
<p><a href="https://i.stack.imgur.com/LkCOd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LkCOd.png" alt="enter image description here" /></a></p>
<p>Thanks!</p>
| [
{
"answer_id": 74394043,
"author": "Sunderam Dubey",
"author_id": 17562044,
"author_profile": "https://Stackoverflow.com/users/17562044",
"pm_score": 2,
"selected": false,
"text": "f-strings"
},
{
"answer_id": 74431679,
"author": "Parth Mehta",
"author_id": 20297992,
"author_profile": "https://Stackoverflow.com/users/20297992",
"pm_score": 0,
"selected": false,
"text": "class User(models.Model):\n \"\"\"\n A normal class that represents an User object, the attributes are those bellow:\n \"\"\"\n first_name = models.CharField(verbose_name=\"First Name\", max_length=30)\n last_name = models.CharField(verbose_name=\"Last Name\", max_length=30)\n cpf = models.CharField(verbose_name=\"CPF\", max_length=30)\n age = models.IntegerField(verbose_name=\"Age\")\n email = models.EmailField(verbose_name=\"email\", max_length=30)\n\n def __str__(self):\n return self.first_name\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/177692/"
] |
74,393,998 | <p>I am trying to pull data based on multiple keywords from the same column.</p>
<p>Currently I have a SQL statement that works like this.</p>
<pre><code>SELECT *
FROM Customers
WHERE CustomerName LIKE 'a%'
OR CustomerName LIKE '_r%'
OR CustomerName LIKE 'si%';
</code></pre>
<p>That works fine. What I am trying to achieve is to pass the keywords <code>c("a", "_r", "si")</code> as a vector. Like this:</p>
<pre><code>keywords <- c("a", "_r", "si")
SELECT *
FROM Customers
WHERE CustomerName LIKE '%' + keywords + '%';
</code></pre>
<p>That did not work. How do I submit a variable with a bunch of keywords into the like statement?</p>
| [
{
"answer_id": 74394043,
"author": "Sunderam Dubey",
"author_id": 17562044,
"author_profile": "https://Stackoverflow.com/users/17562044",
"pm_score": 2,
"selected": false,
"text": "f-strings"
},
{
"answer_id": 74431679,
"author": "Parth Mehta",
"author_id": 20297992,
"author_profile": "https://Stackoverflow.com/users/20297992",
"pm_score": 0,
"selected": false,
"text": "class User(models.Model):\n \"\"\"\n A normal class that represents an User object, the attributes are those bellow:\n \"\"\"\n first_name = models.CharField(verbose_name=\"First Name\", max_length=30)\n last_name = models.CharField(verbose_name=\"Last Name\", max_length=30)\n cpf = models.CharField(verbose_name=\"CPF\", max_length=30)\n age = models.IntegerField(verbose_name=\"Age\")\n email = models.EmailField(verbose_name=\"email\", max_length=30)\n\n def __str__(self):\n return self.first_name\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74393998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18795729/"
] |
74,394,000 | <p>I have table towns which is main table. This table contains so many rows and it became so 'dirty' (<em>someone inserted 5 milions rows</em>) that I would like to get rid of unused towns.</p>
<p>There are 3 referent table that are using my town_id as reference to towns.</p>
<p>And I know there are many towns that are not used in this tables, and only if <code>town_id</code> is not found in neither of these 3 tables I am considering it as inactive and I would like to remove that town (because it's not used).</p>
<p>Print screen of my story:</p>
<p><a href="https://i.stack.imgur.com/NzqcC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NzqcC.png" alt="enter image description here" /></a></p>
<p>as you can see towns is used in this 2 different tables:</p>
<ul>
<li>employees</li>
<li>offices</li>
</ul>
<p>and <strong>for table * vendors there is <code>vendor_id</code> in table towns</strong> since one vendor can have multiple towns.</p>
<p>so if <code>vendor_id</code> in towns is null and town_id is not found in any of these 2 tables it is safe to remove it :)</p>
<p>I created a query which might work but it is taking tooooo much time to execute, and it looks something like this:</p>
<pre><code>select count(*)
from towns
where vendor_id is null
and id not in (select town_id from banks)
and id not in (select town_id from employees)
</code></pre>
<p>So basically I said, if <code>vendor_is</code> is null it means this town is definately not related to vendors and in the same time if same town is not in banks and employees, than it will be safe to remove it.. but query took too long, <strong>and never executed successfully.</strong>..since towns has 5 milions rows and that is reason why it is so dirty..</p>
<p>In face I'm not able to execute given query since server terminated abnormally..</p>
<p>Here is full error message:</p>
<blockquote>
<p>ERROR: server closed the connection unexpectedly This probably means
the server terminated abnormally before or while processing the
request.</p>
</blockquote>
<p>Any kind of help would be awesome
Thanks!</p>
| [
{
"answer_id": 74394451,
"author": "nbk",
"author_id": 5193536,
"author_profile": "https://Stackoverflow.com/users/5193536",
"pm_score": 0,
"selected": false,
"text": "IN"
},
{
"answer_id": 74394678,
"author": "Edouard",
"author_id": 8060017,
"author_profile": "https://Stackoverflow.com/users/8060017",
"pm_score": 1,
"selected": false,
"text": "LEFT JOIN"
},
{
"answer_id": 74443864,
"author": "deroby",
"author_id": 357429,
"author_profile": "https://Stackoverflow.com/users/357429",
"pm_score": 0,
"selected": false,
"text": "-- build empty temp-table\nCREATE TEMPORARY TABLE TEMP_must_keep \nAS\nSELECT town_id \n FROM tbl.towns\n WHERE 1 = 2;\n \n-- get id's from first table\nINSERT TEMP_must_keep (town_id)\nSELECT DISTINCT town_id \n FROM tbl.banks;\n \n-- add index to speed up the EXCEPT below\nCREATE UNIQUE INDEX idx_uq_must_keep_town_id ON TEMP_must_keep (town_id);\n\n-- add new ones from second table\nINSERT TEMP_must_keep (town_id)\nSELECT town_id \n FROM tbl.employees\n \nEXCEPT -- auto-distincts\n\nSELECT town_id \n FROM TEMP_must_keep;\n \n-- rebuild index simply to ensure little fragmentation\nREINDEX TABLE TEMP_must_keep;\n\n-- optional, but might help: create a temporary index on the towns table to speed up the delete\nCREATE INDEX idx_towns_town_id_where_vendor_null ON tbl.towns (town_id) WHERE vendor IS NULL;\n\n-- Now do actual delete\n-- You can do a `SELECT COUNT(*)` rather than a `DELETE` first if you feel like it, both will probably take some time depending on your hardware.\nDELETE \n FROM tbl.towns as del \n WHERE vendor_id is null \n AND NOT EXISTS ( SELECT * \n FROM TEMP_must_keep mk\n WHERE mk.town_id = del.town_id);\n \n \n-- cleanup\nDROP INDEX tbl.idx_towns_town_id_where_vendor_null;\nDROP TABLE TEMP_must_keep;\n\n \n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394000",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6726592/"
] |
74,394,008 | <p>I have a function in a controller like this:</p>
<pre><code>DB::transaction(function () use ($request) {
for ($parts=0; $parts < count($request->name) ; $parts++) {
$parts_info = new PartsInfo;
$parts_info -> part_id = $request -> id;
$parts_info -> name = $request -> name[$parts];
$parts_info -> qty = $request -> qty[$parts];
$parts_info -> price = $request -> price[$parts];
$parts_info -> save();
}
});
</code></pre>
<p>Now I want to update the records. How do I do that? Here multiple records have the same <code>part_id</code> which has a one-to-many relationship with another table.
Note: Tried using <code>$parts_info = PartsInfo::where('parts_id', $request->id)->get();</code> and without <code>get()</code></p>
| [
{
"answer_id": 74394451,
"author": "nbk",
"author_id": 5193536,
"author_profile": "https://Stackoverflow.com/users/5193536",
"pm_score": 0,
"selected": false,
"text": "IN"
},
{
"answer_id": 74394678,
"author": "Edouard",
"author_id": 8060017,
"author_profile": "https://Stackoverflow.com/users/8060017",
"pm_score": 1,
"selected": false,
"text": "LEFT JOIN"
},
{
"answer_id": 74443864,
"author": "deroby",
"author_id": 357429,
"author_profile": "https://Stackoverflow.com/users/357429",
"pm_score": 0,
"selected": false,
"text": "-- build empty temp-table\nCREATE TEMPORARY TABLE TEMP_must_keep \nAS\nSELECT town_id \n FROM tbl.towns\n WHERE 1 = 2;\n \n-- get id's from first table\nINSERT TEMP_must_keep (town_id)\nSELECT DISTINCT town_id \n FROM tbl.banks;\n \n-- add index to speed up the EXCEPT below\nCREATE UNIQUE INDEX idx_uq_must_keep_town_id ON TEMP_must_keep (town_id);\n\n-- add new ones from second table\nINSERT TEMP_must_keep (town_id)\nSELECT town_id \n FROM tbl.employees\n \nEXCEPT -- auto-distincts\n\nSELECT town_id \n FROM TEMP_must_keep;\n \n-- rebuild index simply to ensure little fragmentation\nREINDEX TABLE TEMP_must_keep;\n\n-- optional, but might help: create a temporary index on the towns table to speed up the delete\nCREATE INDEX idx_towns_town_id_where_vendor_null ON tbl.towns (town_id) WHERE vendor IS NULL;\n\n-- Now do actual delete\n-- You can do a `SELECT COUNT(*)` rather than a `DELETE` first if you feel like it, both will probably take some time depending on your hardware.\nDELETE \n FROM tbl.towns as del \n WHERE vendor_id is null \n AND NOT EXISTS ( SELECT * \n FROM TEMP_must_keep mk\n WHERE mk.town_id = del.town_id);\n \n \n-- cleanup\nDROP INDEX tbl.idx_towns_town_id_where_vendor_null;\nDROP TABLE TEMP_must_keep;\n\n \n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15787350/"
] |
74,394,024 | <p>I have a local path like this <code>C:\test\1\2\3\x\z\6\7\8</code> How do I insert a <code>y</code> folder in this hierarchy between <code>x</code> and <code>z</code> folders using PowerShell, assuming the folder names are random but the hierarchy is always the same</p>
<p>Tried <code>Get-ChildItem</code> <code>Split-Path</code> <code>Split-Path</code> <code>Join-Path</code> functions but didn't get the expected results...</p>
| [
{
"answer_id": 74394066,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 1,
"selected": false,
"text": "-replace"
},
{
"answer_id": 74394364,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "DirectoryInfo"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4494816/"
] |
74,394,034 | <p>I am trying to send discord message to channel using python bot, but when I print it's author, it's me and not the bot. So later I can't edit it because of the author.</p>
<p>How can I send message as the bot?</p>
<p>My function:</p>
<pre><code>@bot.command(name="send")
async def send(ctx: Context) -> None:
message = "message"
await ctx.channel.send(message)
print(ctx.message.author)
</code></pre>
| [
{
"answer_id": 74394066,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 1,
"selected": false,
"text": "-replace"
},
{
"answer_id": 74394364,
"author": "Santiago Squarzon",
"author_id": 15339544,
"author_profile": "https://Stackoverflow.com/users/15339544",
"pm_score": 0,
"selected": false,
"text": "DirectoryInfo"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16806651/"
] |
74,394,092 | <p>I want to create a list that contains vectors that display either a 1 or a 0 depending on whether a certain character is present.
The data has the following form:</p>
<pre><code>list <- list('a', 'b', 'c', 'd', 'e')
col1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')
</code></pre>
<p>What I want is a list for all elements of 'list' that contains a vector displaying a 1 when the element of list is present in the element of col1 and a 0 when it is not.
For 'a' this vector will look like (1,1,0,0,0,0,0,0) for example.</p>
<p>My question is why the following loop does not work:</p>
<pre><code>test <- list()
for (i in list){
test[[i]] <- ifelse(grepl(list[i], col1), 1, 0)
}
</code></pre>
<p>This loop returns a list with only zeroes.</p>
<p>However, when I run part of the loop individually it does give the correct result:</p>
<pre><code>ifelse(grepl(list[1], col1), 1, 0)
</code></pre>
<p>This does in fact return the vector I want: (1,1,0,0,0,0,0,0).</p>
<p>How do I loop over a list of strings in R correctly?</p>
| [
{
"answer_id": 74394172,
"author": "Nicso",
"author_id": 9215556,
"author_profile": "https://Stackoverflow.com/users/9215556",
"pm_score": 0,
"selected": false,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\ntest <- list() \nfor (i in 1:length(List)){\n test[[i]] <- ifelse(grepl(List[i], col1), 1, 0)\n}\n"
},
{
"answer_id": 74394316,
"author": "Neeraj",
"author_id": 5047311,
"author_profile": "https://Stackoverflow.com/users/5047311",
"pm_score": 2,
"selected": true,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\nlapply(List, FUN = function(x) as.numeric(grepl(x, col1)))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15635575/"
] |
74,394,095 | <p>I have been trying to extract the required data from a single cell and I have tried using some common formulas but its not working for all the cells exactly.</p>
<p>I would appreciate your help in this regards.</p>
<p><a href="https://docs.google.com/spreadsheets/d/1WS6EKTpA02LUxKCE1t-h08VrgDhiy0mGR4AhZjScagE/edit?usp=sharing" rel="nofollow noreferrer">Google Sheet</a></p>
<p>Formula 1</p>
<pre><code>=LEFT(A2,FIND(C2,A2)-1)
</code></pre>
<p>Formula 2</p>
<pre><code>=SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(LEFT(RIGHT(A2,len(A2)-FIND(") ",A2)),6),")",""),"(","")),"|","")
</code></pre>
| [
{
"answer_id": 74394172,
"author": "Nicso",
"author_id": 9215556,
"author_profile": "https://Stackoverflow.com/users/9215556",
"pm_score": 0,
"selected": false,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\ntest <- list() \nfor (i in 1:length(List)){\n test[[i]] <- ifelse(grepl(List[i], col1), 1, 0)\n}\n"
},
{
"answer_id": 74394316,
"author": "Neeraj",
"author_id": 5047311,
"author_profile": "https://Stackoverflow.com/users/5047311",
"pm_score": 2,
"selected": true,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\nlapply(List, FUN = function(x) as.numeric(grepl(x, col1)))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16968735/"
] |
74,394,115 | <p>I am trying to modify a driver for an LCD display. My Makefile contains:</p>
<pre><code>obj-m += dft0928.o
all:
make -C /usr/lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /usr/lib/modules/$(shell uname -r)/build M=$(PWD) clean
</code></pre>
<p>When I run "make" in the folder containing my source file (dft0928.c), I get this output:</p>
<pre><code>make -C /usr/lib/modules/5.15.74-v7+/build M=/home/pi/software/driver modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.74-v7+'
make[2]: *** No rule to make target '/home/pi/software/driver/dft0928.o', needed by '/home/pi/software/driver/dft0928.mod'. Stop.
make[1]: *** [Makefile:1898: /home/pi/software/driver] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.74-v7+'
make: *** [Makefile:4: all] Error 2
</code></pre>
<p>Where am I going wrong? All the existing guides that I can find suggest my Makefile should be sufficient.</p>
<p>Any help appreciated.</p>
| [
{
"answer_id": 74394172,
"author": "Nicso",
"author_id": 9215556,
"author_profile": "https://Stackoverflow.com/users/9215556",
"pm_score": 0,
"selected": false,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\ntest <- list() \nfor (i in 1:length(List)){\n test[[i]] <- ifelse(grepl(List[i], col1), 1, 0)\n}\n"
},
{
"answer_id": 74394316,
"author": "Neeraj",
"author_id": 5047311,
"author_profile": "https://Stackoverflow.com/users/5047311",
"pm_score": 2,
"selected": true,
"text": "List <- list('a', 'b', 'c', 'd', 'e')\ncol1 <- c('ta', 'ta', 'tb', 'tb', 'tb', 'tc', 'td', 'te')\n\nlapply(List, FUN = function(x) as.numeric(grepl(x, col1)))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14458895/"
] |
74,394,129 | <p>Im trying to use onHoover and onTap of a inkwell widget, but not OnHoover together with onTap doesn't work</p>
<p>I tried various combination, but with no success. please help.</p>
| [
{
"answer_id": 74394295,
"author": "TheHumanItSelf",
"author_id": 11938374,
"author_profile": "https://Stackoverflow.com/users/11938374",
"pm_score": 1,
"selected": false,
"text": "onHover"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5087676/"
] |
74,394,132 | <p>i try to parse website but there is error
<code>You need to enable support for <a href="https://yandex.ru/support/common/browsers-settings/browsers-java-js-settings.html">js</a> in your browser to visit this site</code></p>
<p>I try this code</p>
<pre><code>import requests
from bs4 import BeautifulSoup
URL = "https://siteurl"
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
page = requests.get(URL.strip(), headers=headers, timeout=100)
soup = BeautifulSoup(page.content, "html.parser")
print(soup.contents)
</code></pre>
<p>when i try to open in browser , it's work .
Any solution?</p>
| [
{
"answer_id": 74394195,
"author": "Harez",
"author_id": 20352132,
"author_profile": "https://Stackoverflow.com/users/20352132",
"pm_score": -1,
"selected": false,
"text": "import requests\nfrom bs4 import BeautifulSoup\n\nURL = \"https://siteurl\"\npage = requests.get(URL)\n\nsoup = BeautifulSoup(page.text, \"html.parser\")\nprint(soup)\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20315528/"
] |
74,394,150 | <p>What is done when encountered with special letters in file path, when trying to access it?</p>
<p>To open a file, we need the specific path to the location where it lies. But in cases where the file path itself contains some special characters, like <code>t</code>, just after <code>\</code>, it shows error:</p>
<p><code>OSError: [Errno 22] Invalid argument: 'tech\tech_part.txt'</code>.</p>
<p>How to deal with it?</p>
<p>I am writing this in python and the above error results at this line:</p>
<pre><code>f = open('tech\tech_part.txt', 'r')
</code></pre>
<p>Please note that I have already searched over the web and I found this <a href="https://stackoverflow.com/questions/18014535/how-to-read-files-with-special-characters-in-python">link</a> and some other (related) queries either not answered (or, done satisfactorily). Any help would be welcomed. If I have missed anything that is already available, please mention. Thanks.</p>
| [
{
"answer_id": 74394195,
"author": "Harez",
"author_id": 20352132,
"author_profile": "https://Stackoverflow.com/users/20352132",
"pm_score": -1,
"selected": false,
"text": "import requests\nfrom bs4 import BeautifulSoup\n\nURL = \"https://siteurl\"\npage = requests.get(URL)\n\nsoup = BeautifulSoup(page.text, \"html.parser\")\nprint(soup)\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15031437/"
] |
74,394,157 | <p>This is the Input</p>
<pre><code>| Type - I | Type - II | Type - I | Type - II |
|----------|-----------|----------|-----------|
| 560 | 189 | 128 | 244 |
| 379 | 460 | 357 | 679 |
| 238 | 568 | 125 | 147 |
| 389 | 357 | 780 | 459 |
</code></pre>
<p>This is the Output desired</p>
<pre><code>| Type - I | Type - II | | |
|----------|-----------|---|---|
| 560 | 189 | | |
| 128 | 244 | | |
| 379 | 460 | | |
| 357 | 679 | | |
| 238 | 568 | | |
| 125 | 147 | | |
| 389 | 357 | | |
| 780 | 459 | | |
</code></pre>
<p>Tried many ways but was not able to do it.</p>
| [
{
"answer_id": 74394284,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 2,
"selected": false,
"text": "stack"
},
{
"answer_id": 74394634,
"author": "rhug123",
"author_id": 13802115,
"author_profile": "https://Stackoverflow.com/users/13802115",
"pm_score": 0,
"selected": false,
"text": "(df.stack()\n.to_frame()\n.assign(cc = lambda x: x.groupby(level=1).cumcount())\n.set_index('cc',append=True)\n.droplevel(0)[0]\n.unstack(level=0))\n"
},
{
"answer_id": 74394811,
"author": "PaulS",
"author_id": 11564487,
"author_profile": "https://Stackoverflow.com/users/11564487",
"pm_score": 0,
"selected": false,
"text": "even"
},
{
"answer_id": 74395186,
"author": "sammywemmy",
"author_id": 7175713,
"author_profile": "https://Stackoverflow.com/users/7175713",
"pm_score": 0,
"selected": false,
"text": "cols = df.columns.unique()\nnew_df = df.to_numpy().reshape(-1, len(cols))\npd.DataFrame(new_df, columns = cols)\n Type - I Type - II\n0 560 189\n1 128 244\n2 379 460\n3 357 679\n4 238 568\n5 125 147\n6 389 357\n7 780 459\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4400984/"
] |
74,394,174 | <p>I need to add values to an int[] that are greater than a specific threshold. It does not work for me, because it returns wrong values. For example: "Output for values above 78: [85, 93, 81, 79, 81, 93]", but I get [93, 93, 93, 93, 93, 93]. Why is that so? Thank you.</p>
<pre><code>public int[] getValuesAboveThreshold(int threshold) {
// Output for values above 78: [85, 93, 81, 79, 81, 93]
int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };
int temp[] = new int[1];
for (int d : a) {
if (d > threshold) {
System.out.println(d);
temp = new int[temp.length + 1];
for (int i = 0; i < temp.length; i++) {
temp[i] = d;
}
}
}
return temp;
}
</code></pre>
| [
{
"answer_id": 74394315,
"author": "Perillai",
"author_id": 19393849,
"author_profile": "https://Stackoverflow.com/users/19393849",
"pm_score": 1,
"selected": false,
"text": " int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n ArrayList<Integer> temp = new ArrayList<Integer>();\n for (int d : a) {\n if (d > 73) {\n System.out.println(d); \n temp.add(d);\n }\n }\n System.out.println(temp);\n"
},
{
"answer_id": 74394346,
"author": "Dinuka Silva",
"author_id": 20457576,
"author_profile": "https://Stackoverflow.com/users/20457576",
"pm_score": 2,
"selected": true,
"text": "public static ArrayList<Integer> getValuesAboveThreshold(int threshold) {\n\n // Output for values above 78: [85, 93, 81, 79, 81, 93]\n\n int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n\n ArrayList<Integer> temp = new ArrayList<>();\n\n for (int d : a) {\n\n if (d > threshold) {\n\n temp.add(d);\n\n }\n\n }\n\n return temp;\n\n}\n"
},
{
"answer_id": 74394832,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 0,
"selected": false,
"text": "{A,B,C}"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20207972/"
] |
74,394,188 | <p>this problem has already been written, but it hasn't been solved, so I'll upload it again, so please understand. I made a function that registers an image in child component, and makes the image visible in parent component, and erases the image by also setting the value of url to "" in parent component. I can see the image well, but when I erase the image, the url of the image is erased and then the original url value is entered again. I think there is a problem in the process of passing the url value from child component to parent component as a function. I received the following answer in the previous article, and I think this is the right reason, but I don't know how to modify the code. I'd appreciate it if you let me know, thanks.</p>
<p><em>On deleting image in parent component you need to pass that state to the child and make sure it is in sync with the similar state in child. Else the child state preview will always have a value and since the toParent callback isn't wrapped in useEffect hook it'll run everytime setting a value to isUrl state. You could move all the code in useEffect and toParent callback inside handleChange method.</em></p>
<p><strong>Cild.jsx:</strong></p>
<p>this is child component. Upload the image here and pass the url value to parent component through 'toParent'</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> import React, { useEffect, useState } from 'react'
function Child({toParent}) {
//file upload functions
const fileInput = React.useRef(null);
const [isfile,setIsfile] = useState("");
const handleButtonClick = e => {
fileInput.current.click();
};
const handleChange = e => {
setIsfile(e.target.files[0]);
console.log(e.target.files[0]);
};
const [preview, setPreview] = useState('');
useEffect(() => {
if (isfile) {
const objectUrl = URL.createObjectURL(isfile);
setPreview(objectUrl);
}
return () => URL.revokeObjectURL(isfile);
}, [isfile]);
//pass state to parent
toParent(preview)
return (
<h1>
<input
type="file"
style={{display:'none'}}
ref={fileInput}
onChange={handleChange}
multiple={true}/>
<button onClick={handleButtonClick}>
upload
</button>
</h1>
)
}
export default Child;</code></pre>
</div>
</div>
</p>
<p><strong>App.js:</strong></p>
<p>and this is parent component. Get the url value here and show the image. Also, if I press delete, I want to empty the url of the image, but I can't. How can I empth the url??</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> import { useState } from "react";
import Child from "./Child";
function App() {
//receive state from child
const [isUrl,setIsUrl] = useState("")
const toParent = (url) => {
setIsUrl(url);
}
//delete image
const handelDelete = (e) => {
setIsUrl(" ")
}
return (
<div className="App">
<Child toParent={toParent} />
<div>
<img
style={{width:'300px', height:'300px'}}
src={isUrl}/>
</div>
<div>
<div onClick={handelDelete}>
delete
</div>
</div>
</div>
);
}
export default App;</code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 74394315,
"author": "Perillai",
"author_id": 19393849,
"author_profile": "https://Stackoverflow.com/users/19393849",
"pm_score": 1,
"selected": false,
"text": " int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n ArrayList<Integer> temp = new ArrayList<Integer>();\n for (int d : a) {\n if (d > 73) {\n System.out.println(d); \n temp.add(d);\n }\n }\n System.out.println(temp);\n"
},
{
"answer_id": 74394346,
"author": "Dinuka Silva",
"author_id": 20457576,
"author_profile": "https://Stackoverflow.com/users/20457576",
"pm_score": 2,
"selected": true,
"text": "public static ArrayList<Integer> getValuesAboveThreshold(int threshold) {\n\n // Output for values above 78: [85, 93, 81, 79, 81, 93]\n\n int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n\n ArrayList<Integer> temp = new ArrayList<>();\n\n for (int d : a) {\n\n if (d > threshold) {\n\n temp.add(d);\n\n }\n\n }\n\n return temp;\n\n}\n"
},
{
"answer_id": 74394832,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 0,
"selected": false,
"text": "{A,B,C}"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20108310/"
] |
74,394,214 | <p>After updating to 17.4.0 I can not discover tests in test explorer. Is anyone else experiencing this?
The output I see in test explorer after selecting run all tests is "test discovery finished: 0 tests found".
I am running .Net4.7.2, Selenium, Specflow and NUIT.</p>
<ul>
<li>I have searched the web w/o finding much.</li>
<li>I tried to update any nuget packages that may effect this with no resolve.</li>
<li>I also restarted visual studio and my PC.</li>
<li>Built and cleaned the solution several times</li>
</ul>
<p>At this point I am going to rollback to the previous version of visual studio 2022.</p>
| [
{
"answer_id": 74394315,
"author": "Perillai",
"author_id": 19393849,
"author_profile": "https://Stackoverflow.com/users/19393849",
"pm_score": 1,
"selected": false,
"text": " int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n ArrayList<Integer> temp = new ArrayList<Integer>();\n for (int d : a) {\n if (d > 73) {\n System.out.println(d); \n temp.add(d);\n }\n }\n System.out.println(temp);\n"
},
{
"answer_id": 74394346,
"author": "Dinuka Silva",
"author_id": 20457576,
"author_profile": "https://Stackoverflow.com/users/20457576",
"pm_score": 2,
"selected": true,
"text": "public static ArrayList<Integer> getValuesAboveThreshold(int threshold) {\n\n // Output for values above 78: [85, 93, 81, 79, 81, 93]\n\n int[] a = new int[] { 58, 78, 61, 72, 93, 81, 79, 78, 75, 81, 93 };\n\n ArrayList<Integer> temp = new ArrayList<>();\n\n for (int d : a) {\n\n if (d > threshold) {\n\n temp.add(d);\n\n }\n\n }\n\n return temp;\n\n}\n"
},
{
"answer_id": 74394832,
"author": "Alexander Ivanchenko",
"author_id": 17949945,
"author_profile": "https://Stackoverflow.com/users/17949945",
"pm_score": 0,
"selected": false,
"text": "{A,B,C}"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9567154/"
] |
74,394,244 | <p>I create a new project Microsoft Visual 2022 with the template ASP.NET Core 6.0 Web API with use of controllers.</p>
<p>The endpoint is <code>https://localhost:7251/weatherforecast</code>.</p>
<p>I set my <code>program.cs</code>:</p>
<pre><code>string? origins = "_myAllowSpecificOrigins";
builder.Services.AddCors(options =>
{
options.AddPolicy(origins, builder => builder.WithOrigins("https://localhost:7041")
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
app.UseCors(origins);
</code></pre>
<p>Then I create a new project Microsoft Visual 2022 with the template Blazor Web Assembly App NET 6.0 without ASP.NET Core Hosted.</p>
<p>I write this basic call:</p>
<pre><code>var client = new HttpClient();
var response = await client.GetFromJsonAsync<WeatherForecast[]>("https://localhost:7251/weatherforecast");
</code></pre>
<p>...and it works.</p>
<p>Now, for some project requirements, I have to replace in my API.program.cs</p>
<pre><code>app.MapControllers();
</code></pre>
<p>with</p>
<pre><code>app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
</code></pre>
<p>Then I get an error</p>
<blockquote>
<p>fetch is blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource</p>
</blockquote>
<p>For info, if the web app is a Client/Server/Shared, there is no problem.</p>
<p>How can I set the communication web app not hosted/API using endpoints?</p>
| [
{
"answer_id": 74403188,
"author": "HasanGundogdu",
"author_id": 2170298,
"author_profile": "https://Stackoverflow.com/users/2170298",
"pm_score": -1,
"selected": false,
"text": " app.Use(async (context, next) =>\n {\n context.Response.OnStarting(() =>\n {\n context.Response.Headers[\"Access-Control-Allow-Origin\"] = \"*\";\n context.Response.Headers[\"Access-Control-Allow-Credentials\"] = \"true\";\n\n return Task.CompletedTask;\n });\n\n await next();\n });\n"
},
{
"answer_id": 74524633,
"author": "GoupilSystem",
"author_id": 8550205,
"author_profile": "https://Stackoverflow.com/users/8550205",
"pm_score": 0,
"selected": false,
"text": "builder.Services.AddControllers();\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8550205/"
] |
74,394,272 | <p>I found this when I was watching a project tutorial.</p>
<pre><code>let isGameOver = false;
if(!isGameOver){
console.log('game goes on.')
}
if(isGameOver){
console.log('game over')
}
</code></pre>
<p>Inside this block, it seems "!" didn't negate the return of isGameOver.
It is more working like :
<code>if(isGameOver == false){...} //they are working functionally same. if(!isGameOver){....}</code>
so why it didn't nagate isGameOver to truthy value like</p>
<pre><code> if(isGameOver == true)
</code></pre>
| [
{
"answer_id": 74403188,
"author": "HasanGundogdu",
"author_id": 2170298,
"author_profile": "https://Stackoverflow.com/users/2170298",
"pm_score": -1,
"selected": false,
"text": " app.Use(async (context, next) =>\n {\n context.Response.OnStarting(() =>\n {\n context.Response.Headers[\"Access-Control-Allow-Origin\"] = \"*\";\n context.Response.Headers[\"Access-Control-Allow-Credentials\"] = \"true\";\n\n return Task.CompletedTask;\n });\n\n await next();\n });\n"
},
{
"answer_id": 74524633,
"author": "GoupilSystem",
"author_id": 8550205,
"author_profile": "https://Stackoverflow.com/users/8550205",
"pm_score": 0,
"selected": false,
"text": "builder.Services.AddControllers();\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19672483/"
] |
74,394,280 | <p>IntelliJ (2021.3.1 in this case) has a tool - via right-click, <code>Git</code>, <code>Resolve Conflicts...</code> - which provides a three-pane yours/merged/theirs tool to fix conflicts.</p>
<p>However, I always find it much easier to fix the problems in situ, in the normal IDE edit pane, then flag that the conflicts are fixed.</p>
<p>Having done this though, how <em>do</em> you flag that the problems with the file in question are fixed?</p>
<p>When using IJ in the past with Subversion there was an option to just flag the file as fixed (right-click, <code>Subversion</code>, <code>Mark Resolved</code> - I think it was.)</p>
<p>Surely there must be a way to do the same when using git?</p>
<p>This seems like a really simple thing. But I'm now on my third Google attempt, and trawl through the IJ documentation, and nothing.</p>
<p>UPDATE:</p>
<p>To be clear, I don't want to have to use the 3-pane Merge Revisions dialog <em>at all</em>. I want to edit the differences as shown in the regular edit window (as per below) and then flag the file as fixed when done. This used to be possible, at least with svn, though I suspect this might be a IJ version difference rather than specifically about svn vs git. The menu options to to <code>Mark Resolved</code> the current file just isn't there any more.</p>
<p>e.g. I want to edit this directly in the IDE ...</p>
<pre><code>before
<<<<<<< HEAD
my changes
=======
their changes
>>>>>>> master
after
</code></pre>
<p>And when I've edited it to be...</p>
<pre><code>before
my changes and their changes
after
</code></pre>
<p>... I just want to flag in IJ that I've fixed the conflict.</p>
| [
{
"answer_id": 74394886,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 0,
"selected": false,
"text": "All Changes have been processed"
},
{
"answer_id": 74395600,
"author": "michid",
"author_id": 402428,
"author_profile": "https://Stackoverflow.com/users/402428",
"pm_score": 2,
"selected": true,
"text": "git add"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2136767/"
] |
74,394,317 | <p>I just started learning C language. So, I am running into a lot of problems. I thought declaring i under for loop is enough, and I can use the value of i for outside too. But I think, that was not the case. Can someone explain the situation, please.</p>
<pre><code># include <stdio.h>
int main(void)
{
int x;
printf("Enter how many numbers in arrays you want to input : ");
scanf("%i", &x);
int score[x];
for(int i= 0; i <= x; i++)
{
printf("Enter the score : ");
scanf("%i", &score[i]);
}
// in the below line the output said "i" is undeclared.
float average = score[i] / x;
printf("The average score is : %f", average);
}
</code></pre>
| [
{
"answer_id": 74394355,
"author": "dbush",
"author_id": 1687119,
"author_profile": "https://Stackoverflow.com/users/1687119",
"pm_score": 0,
"selected": false,
"text": "i"
},
{
"answer_id": 74394361,
"author": "CamS",
"author_id": 16307981,
"author_profile": "https://Stackoverflow.com/users/16307981",
"pm_score": 1,
"selected": false,
"text": "i"
},
{
"answer_id": 74395763,
"author": "Simon Goater",
"author_id": 20460267,
"author_profile": "https://Stackoverflow.com/users/20460267",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define INPUTTEXTLEN 20\n#define MAXINPUTINT 1000\n\nint inputint() { \n char inputtext[INPUTTEXTLEN + 1] = {0};\n long inputval;\n while (1) {\n fgets(inputtext, INPUTTEXTLEN, stdin);\n if (strlen(inputtext) > 0) {\n inputval = atoi(inputtext);\n if ((inputval < MAXINPUTINT) && (inputval >= 0)) break;\n }\n }\n return (int)inputval;\n}\n\nint main(void)\n{\n int x = 0;\n printf(\"Enter how many numbers in arrays you want to input : \");\n //scanf(\"%i\", &x);\n while (x <= 0) {\n x = inputint();\n }\n\n int score[x];\n float average = 0;\n\n for(int i= 0; i < x; i++)\n {\n printf(\"Enter the score : \");\n //scanf(\"%i\", &score[i]); \n score[i] = inputint();\n average += score[i];\n }\n average /= x;\n printf(\"The average score is : %f\\n\", average);\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16075798/"
] |
74,394,340 | <p>the converted version. there must be one space between letters and two spaces between words. if the symbol is not possible to be converted into english (not in morse) there can be "#"</p>
<pre><code>this version does not work.. (((
sign_eng = {'.-': 'a', '-...': 'b', '-.-.': 'c',
'-..': 'd', '.': 'e', '..-.': 'f',
'--.': 'g', '....': 'h', '..': 'i',
'.---': 'j', '-.-': 'k', '.-..': 'l',
'--': 'm', '-.': 'n', '---': 'o',
'.--.': 'p', '--.-': 'q', '.-.': 'r',
'...': 's', '-': 't', '..-': 'u',
'...-': 'v', '.--': 'w', '-..-': 'x',
'-.--': 'y', '--..': 'z', '-----': '0',
'.----': '1', '..---': '2', '...--': '3',
'....-': '4', '.....': '5', '-....': '6',
'--...': '7', '---..': '8', '----.': '9'
}
text = input("Enter your Morse code here: ")
text_words = text.split(' ')
words = ''
for text_word in text_words:
text_letters = text_word.split(' ')
letters = ''
for text_letter in text_letters:
if text_letter in sign_eng:
text = words + str(sign_eng[text_letter])
if text_letter not in sign_eng:
text = words + "#"
result = "".join(words)
print(result)`
</code></pre>
| [
{
"answer_id": 74394355,
"author": "dbush",
"author_id": 1687119,
"author_profile": "https://Stackoverflow.com/users/1687119",
"pm_score": 0,
"selected": false,
"text": "i"
},
{
"answer_id": 74394361,
"author": "CamS",
"author_id": 16307981,
"author_profile": "https://Stackoverflow.com/users/16307981",
"pm_score": 1,
"selected": false,
"text": "i"
},
{
"answer_id": 74395763,
"author": "Simon Goater",
"author_id": 20460267,
"author_profile": "https://Stackoverflow.com/users/20460267",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define INPUTTEXTLEN 20\n#define MAXINPUTINT 1000\n\nint inputint() { \n char inputtext[INPUTTEXTLEN + 1] = {0};\n long inputval;\n while (1) {\n fgets(inputtext, INPUTTEXTLEN, stdin);\n if (strlen(inputtext) > 0) {\n inputval = atoi(inputtext);\n if ((inputval < MAXINPUTINT) && (inputval >= 0)) break;\n }\n }\n return (int)inputval;\n}\n\nint main(void)\n{\n int x = 0;\n printf(\"Enter how many numbers in arrays you want to input : \");\n //scanf(\"%i\", &x);\n while (x <= 0) {\n x = inputint();\n }\n\n int score[x];\n float average = 0;\n\n for(int i= 0; i < x; i++)\n {\n printf(\"Enter the score : \");\n //scanf(\"%i\", &score[i]); \n score[i] = inputint();\n average += score[i];\n }\n average /= x;\n printf(\"The average score is : %f\\n\", average);\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20243817/"
] |
74,394,363 | <p>I read like through 10 pages on how to resolve promises but i still don't get it.
Info: I want to fetch a specific member of a discord server</p>
<p>Currently I have a async function with the promise inside that returns it but it gives me a message with "Invalid Body Form"</p>
<pre class="lang-js prettyprint-override"><code>async function mbr() {
const mB = await client.guilds.cache.get("1037783624449282189").members.fetch(`${args[0]}`).then((m) => { return m; });
return mB
}
let member = mbr()
if (member.roles.cache.has("1039983830389510305"))
</code></pre>
<p>Edit: It gives me this Error when i do a async Function inside a async function</p>
<pre class="lang-js prettyprint-override"><code>G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\node_modules\@discordjs\rest\dist\index.js:659
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50035]: Invalid Form Body
user_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
at SequentialHandler.runRequest (G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\node_modules\@discordjs\rest\dist\index.js:659:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\node_modules\@discordjs\rest\dist\index.js:458:14)
at async REST.request (G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\node_modules\@discordjs\rest\dist\index.js:902:22)
at async GuildMemberManager._fetchSingle (G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\node_modules\discord.js\src\managers\GuildMemberManager.js:489:18)
at async mbr (G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\chatBridge\accountLink.js:8:32)
at async G:\Desktop\Minecraft Modding\Bedrock\_____\Server\legend\plugins\nodejs\discord-bot\chatBridge\accountLink.js:11:30 {
requestBody: { files: undefined, json: undefined },
rawError: {
code: 50035,
errors: {
user_id: {
_errors: [
{
code: 'NUMBER_TYPE_COERCE',
message: 'Value "undefined" is not snowflake.'
}
]
}
},
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1037783624449282189/members/undefined'
}
</code></pre>
| [
{
"answer_id": 74394407,
"author": "iEnis",
"author_id": 19693037,
"author_profile": "https://Stackoverflow.com/users/19693037",
"pm_score": -1,
"selected": false,
"text": "async function mbr() {\n const mB = await client.guilds.cache.get(\"1037783624449282189\").members.fetch(`${args[0]}`).then((m) => { return m; });\n return mB\n}\nlet member = await mbr()\n\nif (member.roles.cache.has(\"1039983830389510305\"))\n"
},
{
"answer_id": 74394436,
"author": "Mr. Polywhirl",
"author_id": 1762224,
"author_profile": "https://Stackoverflow.com/users/1762224",
"pm_score": 2,
"selected": false,
"text": "let member = await mbr();\nif (member.roles.cache.has(\"1039983830389510305\")) {\n // ...\n}\n"
},
{
"answer_id": 74394470,
"author": "Yanick Rochon",
"author_id": 320700,
"author_profile": "https://Stackoverflow.com/users/320700",
"pm_score": 2,
"selected": false,
"text": "p.then(callback)"
},
{
"answer_id": 74394505,
"author": "zmehall",
"author_id": 19853802,
"author_profile": "https://Stackoverflow.com/users/19853802",
"pm_score": 1,
"selected": false,
"text": "async"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19693037/"
] |
74,394,393 | <p>I need to get value for "UninstallString" in</p>
<p>Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
{1535CAA3-9F33-414E-8987-0365169BE741}</p>
<p>calling:</p>
<pre><code>Get-Item -path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1535CAA3-9F33-414E-8987-0365169BE741}
</code></pre>
<p>results in
<em>Get-Item : A positional parameter cannot be found that accepts argument '1535CAA3-9F33-414E-8987-0365169BE741'.</em></p>
| [
{
"answer_id": 74394559,
"author": "frankM_DN",
"author_id": 20034020,
"author_profile": "https://Stackoverflow.com/users/20034020",
"pm_score": -1,
"selected": false,
"text": "\"\""
},
{
"answer_id": 74394563,
"author": "js2010",
"author_id": 6654942,
"author_profile": "https://Stackoverflow.com/users/6654942",
"pm_score": 1,
"selected": false,
"text": "get-itemproperty 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{013DB423-A8DE-4423-9E50-D45ED1041789}' uninstallstring | \n % uninstallstring\n\nMsiExec.exe /I{013DB423-A8DE-4423-9E50-D45ED1041789}\n"
},
{
"answer_id": 74394738,
"author": "mklement0",
"author_id": 45375,
"author_profile": "https://Stackoverflow.com/users/45375",
"pm_score": 2,
"selected": true,
"text": "{"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9502952/"
] |
74,394,403 | <p>I am having a course about assembly language, and I bump into this question which is use the loop and xchg instruction to swap all of the element in the array
the array look like this
The inputStr contains these element “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”.
And after use the loop and xchg, it has to look like this “G”, “H”, “E”, “F”, “C”, “D”, “A”, “B”.</p>
<p>I have already tried to do it many times, but my output is not right. I cannot figure out the logic, or the right way to do this.</p>
<p>This is my code and it is in x86</p>
<pre><code>.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode: DWORD
.data
inputStr BYTE "A", "B", "C", "D", "E", "F", "G", "H"
.code
main PROC
mov ecx, 8
xor ebx, ebx
mov ebx, offset inputStr
l1:
xor eax, eax
mov al, [ebx]
add ebx, ecx
sub ebx, 2
xchg al, [ebx]
add ebx, 1
sub ebx, ecx
xchg al, [ebx]
inc ebx
dec ecx
loop l1
INVOKE ExitProcess, 0
main ENDP
END main
</code></pre>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20152569/"
] |
74,394,405 | <pre><code>path = '/Desktop/somefolder'
for filename in os.listdir(path):
with open(path+filename) as f:
- read the 3-4 excel files and attach the path
- be able to concat them based on a specific column
</code></pre>
<p>filename gives me the name of the file I have in the directory. My idea was to concat the filename with the path to be able to read and concat them.</p>
<p>I am not sure how to use the filename that I get to be able to load it as a df and concat it.</p>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15262691/"
] |
74,394,409 | <p>I have a character in unity controlled by a rigidbody. However, the jump is one jerky movement not a smooth motion. Here is my script:</p>
<pre><code>using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
public class Controller : MonoBehaviour
{
[Tooltip("Rigidbody component attached to the player")]
public Rigidbody rb;
private float movementX;
private float movementY;
private float gravity = -9.81f;
private float speedX = 10;
private float speedY = 1000;
private float speedZ = 5;
private bool isJumping = false;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
}
void OnCollisionEnter(Collision collision)
{
// SceneManager.LoadScene(1);
}
// Update is called once per frame
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void OnJump()
{
//isJumping = true;
Vector3 movementVelocity = new Vector3();
movementVelocity.y += Mathf.Sqrt(speedY * -3.0f * gravity);
movementVelocity.y *= 100;
rb.AddForce(movementVelocity, ForceMode.Force);
//isJumping = false;
}
void CalculateMovement()
{
Vector3 movementVelocity = new Vector3(movementX * speedX, 0, speedZ);
rb.velocity = movementVelocity;
}
void FixedUpdate()
{
CalculateMovement();
}
}
</code></pre>
<p>Is there a way to get a smooth jump with a rigidbody?</p>
<p>I have tried all the different options for <code>ForceMode</code> and tried updating the <code>Rigidbody.velocity</code> characteristic, both at the same time and separately to the movement.</p>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19445483/"
] |
74,394,434 | <p>I am looking for an easy/Pythonic way to get the elapsed time difference (in fractional seconds) between two Python datetime objects.</p>
<p>In the example below, I can see the delta.seconds and delta.microseconds attributes but am not sure what they actually contain and how they relate to the value returned by total_seconds().</p>
<p>I would like to have the elapsed time difference down to 1 decimal point if possible rather than rounded to whole seconds.</p>
<p>I know this is a simple question but even after googling I am unable to determine what delta.seconds and delta.microseconds actually contain when you construct a timeobject from the difference between two datetime objects (as below) rather than by a direct instantiation call. Once I know this information, I should be able to proceed the rest of the way myself.</p>
<pre><code>>>> mtime = datetime.strptime("2005-02-08T07:18:22", "%Y-%m-%dT%H:%M:%S")
>>> ctime = datetime.strptime("2005-02-08T07:18:26Z", "%Y-%m-%dT%H:%M:%SZ")
>>> delta = mtime - ctime
>>> delta.total_seconds()
-4.0
>>> delta.seconds
86396
>>> delta.microseconds
0
</code></pre>
<p>Thank you for answering this simple question,</p>
<p>Catherine</p>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3014653/"
] |
74,394,445 | <p>I am running into an issue while trying to create a toggle button. It moves on click but only after two clicks. I know that I have to set it before it will slide on the first click, but my confusion stems from when I did that, it clicked to the right and wouldn't move back no matter how many times I clicked it. Is there anyone that knows how I can solve this issue?</p>
<p>`</p>
<pre><code> <div class="main">
<div class="container">
<div class="slider" id="slideHousing">
<div class="slideBtn" id="slider" onclick="SlideRight()">
</div>
</div>
</div>
</div>
</code></pre>
<p>`</p>
<pre><code>.main {
display: table;
height: 100%;
width: 100%;
border: 1px solid transparent;
}
.container {
display: table-cell;
vertical-align: middle;
border: 1px solid transparent;
}
.slider {
height: 100px;
width: 200px;
border-radius: 50px;
background-color: #f2f2f2;
margin: 0 auto;
border: 1px solid transparent;
}
.slideBtn {
border: 1px solid transparent;
height: 95px;
margin: 1px;
width: 100px;
border-radius: 50px;
background-color: silver;
}
</code></pre>
<p>`</p>
<pre><code>function SlideRight() {
// Checks to see if the slider is to the left of the div
if (document.getElementById("slider").style.float === "left"){
// If it is we will float the sliderBtn to the right and change the background of the housing to green
document.getElementById("slider").style.float = "right";
document.getElementById("slideHousing").style.backgroundColor = "#00ff00";
// Toggle dark mode on
document.body.style.backgroundColor = "#595959";
document.getElementById("header").style.color = "#e6e6e6";
} else {
// If clicked again the btn will move back to the left side and change the color back to original
document.getElementById("slider").style.float = "left";
document.getElementById("slideHousing").style.backgroundColor = "#f2f2f2";
// Toggle dark mode off
document.body.style.backgroundColor = "#e6e6e6";
document.getElementById("header").style.color = "#000";
}
}
</code></pre>
<pre><code></code></pre>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17816713/"
] |
74,394,461 | <p>I have dataframe:</p>
<pre><code> d1 = [({'the town': 1, 'County Council s': 2, 'email':5},2),
({'Mayor': 2, 'Indiana': 2}, 4),
({'Congress': 2, 'Justice': 2,'country': 2, 'veterans':1},6)
]
df1 = spark.createDataFrame(d1, ['dct', 'count'])
df1.show()
ignore_lst = ['County Council s', 'emal','Indiana']
filter_lst = ['Congress','town','Mayor', 'Indiana']
</code></pre>
<p>I want to write two functions:
first function filters keys for the <code>dct</code> column that are <strong>not in</strong> the <code>ignore_list</code> and the second function filters if the keys are <strong>in</strong> <code>filter_lst</code></p>
<p>Thus there will be two columns that contain dictionaries with keys filtered by <code>ignore_list</code> and <code>filter_lst</code></p>
| [
{
"answer_id": 74399447,
"author": "bitRAKE",
"author_id": 478499,
"author_profile": "https://Stackoverflow.com/users/478499",
"pm_score": 0,
"selected": false,
"text": "ITEMS = 8\ninputList WORD \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\"\n\n mov rbx, inputList\n mov ecx, ITEMS/2/2\n@@:\n mov eax, [rbx]\n xchg [rbx+rcx*8-4], eax\n mov [rbx], eax\n\n add rbx, 4\n loop @B\n"
},
{
"answer_id": 74407323,
"author": "Sep Roland",
"author_id": 3144770,
"author_profile": "https://Stackoverflow.com/users/3144770",
"pm_score": 3,
"selected": true,
"text": "loop"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15112773/"
] |
74,394,498 | <p>I'm trying to write code that can check if an input contains;</p>
<ul>
<li>At least 8 letters, whereas at least 1 of those is a number (0-9)</li>
<li>Contains an upper and lower case character</li>
</ul>
<p>I keep getting stuck in a "inputs password, returns true, and input password again, exit" single loop..</p>
<p>Fairly new at programming, doing my first semester atm so all help would be appreciated!</p>
<p>This is my program so far</p>
<pre><code>def is_valid():
valid = 0
password = input("Password: ")
for ele in password:
if ele.isupper and ele.islower and ele.isdigit and len(password) > 7:
return "True"
else:
return "False"
print(is_valid())
is_valid()
</code></pre>
<p>I tried moving the print inside the function, as I think it is intended, by then It won't print..</p>
| [
{
"answer_id": 74394561,
"author": "PirateNinjas",
"author_id": 8237877,
"author_profile": "https://Stackoverflow.com/users/8237877",
"pm_score": 1,
"selected": false,
"text": "def is_valid():\n password = input(\"Password: \")\n if not any(el.isupper() for el in password):\n return False\n\n if not any(el.islower() for el in password):\n return False\n\n if not any(el.isdigit() for el in password):\n return False\n\n if len(password) < 8:\n return False\n\n return True\n\nis_valid()\n"
},
{
"answer_id": 74394581,
"author": "John Gordon",
"author_id": 494134,
"author_profile": "https://Stackoverflow.com/users/494134",
"pm_score": 2,
"selected": false,
"text": "for ele in password:\n if ele.isupper and ele.islower and ele.isdigit and len(password) > 7:\n return \"True\"\n else:\n return \"False\"\n"
},
{
"answer_id": 74394754,
"author": "Mateusz Anikiej",
"author_id": 11756392,
"author_profile": "https://Stackoverflow.com/users/11756392",
"pm_score": 1,
"selected": false,
"text": "valid = 0"
},
{
"answer_id": 74394879,
"author": "FG94",
"author_id": 20307335,
"author_profile": "https://Stackoverflow.com/users/20307335",
"pm_score": 2,
"selected": true,
"text": "ele.isupper"
},
{
"answer_id": 74394997,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 1,
"selected": false,
"text": "def is_valid(pwd):\n state = 0\n if len(pwd) >= 8:\n for c in pwd:\n if c.isdigit():\n state |= 1\n elif c.islower():\n state |= 2\n elif c.isupper():\n state |= 4\n else:\n state |= 8\n return state == 7\n\n\npassword = input('Password: ')\nprint(is_valid(password))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20358629/"
] |
74,394,508 | <p>I am having some issues with this DIV not getting centered.
I am sure it is something with CSS,</p>
<p>I need some corrections to CSS below and to get rid of unnecessary CSS statements if not needed</p>
<p>I would like the div to be centered and 75% wide</p>
<p>Thanks,</p>
<pre><code> .css_main_popup {
transition: opacity 10ms;
visibility: hidden;
position: absolute;
top: 10px;
right: 10px;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
margin: auto;
margin-left: auto;
margin-right: auto;
padding: 10px;
background: #fff;
border-radius: 5px;
width: 95%;
height: 90%;
overflow: auto;
align-self: center;
}
</code></pre>
<p>HTML</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SMT Explorer</title>
<link rel="stylesheet" href="explorer.css">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div id="main_div" style="position: relative; "></div>
<div id="popup_factory" class="css_main_popup">
<a class="css_close_popup" href="#" style='text-align:right' onclick="CloseFPopup()">&times;</a>
</div>
<div id="popup_stations" class="css_main_popup">
<a class="css_close_popup" href="#" style='text-align:right' onclick="CloseSPopup()">&times;</a>
</div>
<script type="text/javascript" src="explorer.js"></script>
</body>
</html>
</code></pre>
<p><a href="https://i.stack.imgur.com/fB5QF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fB5QF.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74394561,
"author": "PirateNinjas",
"author_id": 8237877,
"author_profile": "https://Stackoverflow.com/users/8237877",
"pm_score": 1,
"selected": false,
"text": "def is_valid():\n password = input(\"Password: \")\n if not any(el.isupper() for el in password):\n return False\n\n if not any(el.islower() for el in password):\n return False\n\n if not any(el.isdigit() for el in password):\n return False\n\n if len(password) < 8:\n return False\n\n return True\n\nis_valid()\n"
},
{
"answer_id": 74394581,
"author": "John Gordon",
"author_id": 494134,
"author_profile": "https://Stackoverflow.com/users/494134",
"pm_score": 2,
"selected": false,
"text": "for ele in password:\n if ele.isupper and ele.islower and ele.isdigit and len(password) > 7:\n return \"True\"\n else:\n return \"False\"\n"
},
{
"answer_id": 74394754,
"author": "Mateusz Anikiej",
"author_id": 11756392,
"author_profile": "https://Stackoverflow.com/users/11756392",
"pm_score": 1,
"selected": false,
"text": "valid = 0"
},
{
"answer_id": 74394879,
"author": "FG94",
"author_id": 20307335,
"author_profile": "https://Stackoverflow.com/users/20307335",
"pm_score": 2,
"selected": true,
"text": "ele.isupper"
},
{
"answer_id": 74394997,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 1,
"selected": false,
"text": "def is_valid(pwd):\n state = 0\n if len(pwd) >= 8:\n for c in pwd:\n if c.isdigit():\n state |= 1\n elif c.islower():\n state |= 2\n elif c.isupper():\n state |= 4\n else:\n state |= 8\n return state == 7\n\n\npassword = input('Password: ')\nprint(is_valid(password))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7375877/"
] |
74,394,509 | <p>I have a problem that's simple: I want to get the sum across some columns (<code>a</code> and <code>b</code> in my example) of strings equal to <code>-999</code>.</p>
<pre><code>df = tibble(a = c('-999', 'b', '-999'),
b = c('-999', 'a', 'b'),
c = 1:3)
</code></pre>
<p>from this:</p>
<pre><code> a b c
<chr> <chr> <int>
1 -999 -999 1
2 b a 2
3 -999 b 3
</code></pre>
<p>to this:</p>
<pre><code> a b c sum999
<chr> <chr> <int> <dbl>
1 -999 -999 1 2
2 b a 2 0
3 -999 b 3 1
</code></pre>
<p>I managed to do it in a not so straightforward way:</p>
<pre><code>df %>%
mutate(across(matches('^[ab]'), ~if_else(.x == '-999', 1, 0),
.names = '{.col}_' ) ) %>%
rowwise() %>%
mutate(sum999 = sum(c_across(matches('^[ab]_')) ),
.keep = 'unused')
</code></pre>
<p>So, my question is, am I missing a better way to do this? Perhaps using <code>rowSums</code> ?</p>
<p>Thanks</p>
| [
{
"answer_id": 74394561,
"author": "PirateNinjas",
"author_id": 8237877,
"author_profile": "https://Stackoverflow.com/users/8237877",
"pm_score": 1,
"selected": false,
"text": "def is_valid():\n password = input(\"Password: \")\n if not any(el.isupper() for el in password):\n return False\n\n if not any(el.islower() for el in password):\n return False\n\n if not any(el.isdigit() for el in password):\n return False\n\n if len(password) < 8:\n return False\n\n return True\n\nis_valid()\n"
},
{
"answer_id": 74394581,
"author": "John Gordon",
"author_id": 494134,
"author_profile": "https://Stackoverflow.com/users/494134",
"pm_score": 2,
"selected": false,
"text": "for ele in password:\n if ele.isupper and ele.islower and ele.isdigit and len(password) > 7:\n return \"True\"\n else:\n return \"False\"\n"
},
{
"answer_id": 74394754,
"author": "Mateusz Anikiej",
"author_id": 11756392,
"author_profile": "https://Stackoverflow.com/users/11756392",
"pm_score": 1,
"selected": false,
"text": "valid = 0"
},
{
"answer_id": 74394879,
"author": "FG94",
"author_id": 20307335,
"author_profile": "https://Stackoverflow.com/users/20307335",
"pm_score": 2,
"selected": true,
"text": "ele.isupper"
},
{
"answer_id": 74394997,
"author": "Cobra",
"author_id": 17580381,
"author_profile": "https://Stackoverflow.com/users/17580381",
"pm_score": 1,
"selected": false,
"text": "def is_valid(pwd):\n state = 0\n if len(pwd) >= 8:\n for c in pwd:\n if c.isdigit():\n state |= 1\n elif c.islower():\n state |= 2\n elif c.isupper():\n state |= 4\n else:\n state |= 8\n return state == 7\n\n\npassword = input('Password: ')\nprint(is_valid(password))\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9462829/"
] |
74,394,524 | <p>I want to create a curried function that can either accept an argument in the outer call, or the inner one - but never both/neither (xor). Is such a thing possible? I can't quite figure out how to make it work. The following clearly doesn't work because I'm not passing on any type information to the inner function:</p>
<pre><code>const outerFunc:
| ((outerVar: string) => (innerVar: never) => string)
| ((outerVar: never) => (innerVar: string) => string) =
(outerVar?: string) =>
(innerVar?: string): string =>
outerVar || innerVar // typescript still thinks this may be undefined
// What should pass:
outerFunc()('foo')
outerFunc('foo')()
// What should fail:
outerFunc('foo')('foo')
outerFunc()()
</code></pre>
<p>Anyone know any tricks to get this to work using a combination of generics and conditional types or something? Or maybe function overloads?</p>
| [
{
"answer_id": 74394850,
"author": "Andrey Tyukin",
"author_id": 2707792,
"author_profile": "https://Stackoverflow.com/users/2707792",
"pm_score": 2,
"selected": false,
"text": "function outerFunc(x: string): () => string;\nfunction outerFunc(): (y: string) => string;\nfunction outerFunc(x?: string): (y: string) => string {\n return (y) => x || y;\n}\n\n// What should pass:\nouterFunc()('foo') // OK\nouterFunc('foo')() // OK\n\n// What should fail:\nouterFunc('foo')('foo') // Fails: \"Expected 0 arguments, but got 1\"\nouterFunc()() // Fails: \"Expected 1 arguments, but got 0\"\n\n"
},
{
"answer_id": 74394899,
"author": "kaya3",
"author_id": 12299000,
"author_profile": "https://Stackoverflow.com/users/12299000",
"pm_score": 1,
"selected": false,
"text": "never"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3071004/"
] |
74,394,532 | <p>I have a Syncfusion SfDialog in my code and I need the component in the content to restart every time the dialog is open. So far I have tried this:</p>
<pre><code> <SfDialog Visible="_dialogTripRunAutoRoute" Width="75%" ShowCloseIcon="true" IsModal="true" AllowPrerender="true">
<DialogEvents Closed="@CloseDialogTripRunAutoRoute"></DialogEvents>
<DialogTemplates>
<Content>
@_tripRunAutoRoute
</Content>
</DialogTemplates>
<DialogPositionData X="center" Y="top"></DialogPositionData>
</SfDialog>
</code></pre>
<hr />
<pre><code> private async Task ToggleDialogTripRunAutoRoute(){
_tripRunAutoRoute = new TripRunAutoRoute();
_tripRunAutoRoute.ModelTripRun = TripOps.TripRunAutoRouteFormModel;
await InvokeAsync(StateHasChanged);
_dialogTripRunAutoRoute = !_dialogTripRunAutoRoute;
}
</code></pre>
<p>The result is <a href="https://i.stack.imgur.com/ciyEB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ciyEB.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74397500,
"author": "Ibrahim Timimi",
"author_id": 8316900,
"author_profile": "https://Stackoverflow.com/users/8316900",
"pm_score": 0,
"selected": false,
"text": "<ComponentInTheContent @key=\"@(componentId)\">\n\n</ComponentInTheContent>\n\n@code {\n private Guid componentId = Guid.NewGuid();\n\n private async Task CalledWhenDialogIsOpened()\n {\n // stuff\n\n // this change of id will make Blazor re-create \n // the component in the DOM as it sees it as a new component.\n componentId = Guid.NewGuid(); \n }\n}\n"
},
{
"answer_id": 74401298,
"author": "MrC aka Shaun Curtis",
"author_id": 13065781,
"author_profile": "https://Stackoverflow.com/users/13065781",
"pm_score": 1,
"selected": false,
"text": "@if(_dialogTripRunAutoRoute)\n{\n SfDialog stuff \n}\n"
},
{
"answer_id": 74440783,
"author": "Vinitha Jeyakumar",
"author_id": 19099146,
"author_profile": "https://Stackoverflow.com/users/19099146",
"pm_score": 1,
"selected": true,
"text": "<div class=\" col-lg-8 control-section sb-property-border\" id=\"target\" style=\"height:350px;\">\n<div>\n @if (this.ShowButton)\n {\n <button class=\"e-btn\" @onclick=\"@OnBtnClick\">Open</button>\n }\n</div>\n<SfDialog Width=\"335px\" IsModal=\"true\" @bind-Visible=\"Visibility\" AllowPrerender=\"true\" CssClass=\"dialog-medium\">\n <DialogTemplates>\n <Header> Software Update </Header>\n <Content>\n @if(DialogBool)\n {\n @DialogContent\n <div>@count</div>\n }\n \n </Content>\n </DialogTemplates>\n <DialogButtons>\n <DialogButton Content=\"OK\" IsPrimary=\"true\" OnClick=\"@DlgButtonClick\" />\n </DialogButtons>\n <DialogEvents OnOpen=\"@DialogOpen\" Closed=\"@DialogClose\"></DialogEvents>\n <DialogAnimationSettings Effect=\"@DialogEffect.None\"></DialogAnimationSettings>\n</SfDialog>\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20064183/"
] |
74,394,560 | <p>Is there a way to control the spacing between edges in dot, similar to the <code>nodesep</code> attribute in the other graphviz layout engines? I would like to keep using <code>dot</code> as the layout engine.</p>
<p>By edges I mean either multi-edges or multi-coloured edges, like in the following example. I would like to decrease the space between the <code>a->b</code> edges or increase the space between the <code>c->d</code> edges.</p>
<pre><code>digraph G {
nodesep = "0.15"
a -> b [dir=none color="red"]
a -> b [dir=none color="blue"]
a -> b [dir=none color="green"]
c -> d [dir=none color="green:red:blue"]
}
</code></pre>
<p><a href="https://i.stack.imgur.com/QBnmD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QBnmD.png" alt="graph" /></a></p>
<p>In dot, the <code>nodesep</code> attribute does not have the desired effect.</p>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9074788/"
] |
74,394,603 | <p>My <code>docker-compose.yml</code></p>
<pre><code># pull official base image
FROM python:3.10-alpine
# set work directory
WORKDIR .
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# copy project
COPY . .
</code></pre>
<p>My <code>Dockerfile</code> is as follows:</p>
<pre><code>services:
app:
build:
context: .
ports:
- "8000:8000"
command: >
sh -c "python3 manage.py runserver 0.0.0.0:8000"
redis:
image: redis:alpine
celery:
restart: always
build:
context: .
command: celery -A search worker -l info
depends_on:
- redis
- app
</code></pre>
<p>The tree structure of my project directory is as follows:</p>
<pre><code>├── Dockerfile
├── Procfile
├── books
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ ├── models.py
│ ├── templates
│ │ └── search.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── docker-compose.yml
├── manage.py
├── requirements.txt
├── search
│ ├── __init__.py
│ ├── asgi.py
│ ├── celery.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── templates
├── base.html
├── home.html
└── registration
├── login.html
└── logout.html
</code></pre>
<p>My settings is as follows:</p>
<pre><code>ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', 'localhost']
DISABLE_COLLECTSTATIC = 0
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"books.apps.BooksConfig",
"debug_toolbar",
"corsheaders",
"django.contrib.postgres",
"django_celery_beat",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
]
ROOT_URLCONF = "search.urls"
LOGIN_REDIRECT_URL = "home"
LOGOUT_REDIRECT_URL = "home"
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'http://localhost:8000',
'https://localhost:8000',
'http://0.0.0.0:8000',
'https://0.0.0.0:8000',
'http://127.0.0.1:8000',
'https://127.0.0.1:8000'
)
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
STATIC_URL = "/static/"
</code></pre>
<p>If I access <code>http://0.0.0.0:8000/admin/</code>, the console says the following and the css does not load.</p>
<pre><code>The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header.
</code></pre>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6213939/"
] |
74,394,621 | <pre><code>operation = str(input("Operation (type which operation you would like): "))
if operation == "division":
number1 = float(input("1st Number? "))
number2 = float(input("2nd Number? "))
quotient = number1 / number2
print(str(number1) + " / " + str(number2) " = " + str(division))
elif operation == "multiplication":
number1 = float(input("1st Number? "))
number2 = float(input("2nd Number? "))
product = number1 * number2
print(str(number1) + " * " + str(number2) + " = " + str(product))
elif operation == "addition":
number1 = float(input("1st Number? "))
number2 = float(input("2nd Number? "))
summary = number1 + number2
print(str(number1) + " * " + str(number2) + " = " + str(summary))
elif operation == "exponent":
number1 = float(input("Number? "))
exponent = float(input("Exponent? "))
product2 = number1 ** exponent
print(str(number1) + "^" + str(exponent) + " = " + str(product2))
</code></pre>
<p>The 'S' in 'str' was highlighted
I realized I didn't put "elif", so I tried that, still didn't work.
Don't know what's going wrong, perhaps some of you can answer</p>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20472020/"
] |
74,394,623 | <p>I have a function that takes 2 vectors and return 2 scalars.
The vectors are a part of a big array. I want to apply the function over the array, but I didn’t succeed using the apply family. I’m sure it’s possible, I just didn’t grasp the use of apply and a function and couldn't find an answer I can understand in similar questions here.
The loop method gives the desired results but is very slow (my data is bigger than in the example below and the function is more complex). I’ll be grateful for solutions!</p>
<pre><code># function receives two vectors and returns 2 scalars
fnd <- function(depths,temps) {
return (lm(depths~temps)$coefficients) }
d1 <- 20
stdt <- as.Date("2023-02-01") ; endt <- stdt + d1 -1
Time00 <- seq(stdt,endt,"day")
# input array
ar1 <- array(data=runif(2*10*d1), dim=c(2,10,d1), dimnames = list(c("Depth","Temp"),c(0:9),Time00))
# prepare output array
res_ar <- array(data=NA, dim=c(2,d1), dimnames=list(c("b","a"),Time00))
# this loop gives the desired result but is inefficient
for (i in 1:d1) {
res_ar[,i] <- fnd(ar1[1,,i],ar1[2,,i])
}
</code></pre>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11760203/"
] |
74,394,631 | <p>I'm a creating a blog using Remix.</p>
<p>Remix supports MDX as a route, which is perfect for me, as I can just write my blog posts as <code>.mdx</code> files and they'll naturally become routes.</p>
<p>However, if you access the index route - I would like to display the list of links to all the articles, (ideally sorted by creation date, or some kind of metadata in the .mdx file).</p>
<p>I can't see a natural way to do this in the Remix documentation.</p>
<p>Best solution I've got is that I would run a script as part of my build process, that the examines the <code>routes/</code> folder and generates a <code>TableOfContents.tsx</code> file, which the index route can use.</p>
<p>Is there an out of the box solution?</p>
<p>The <a href="https://remix.run/docs/en/v1/guides/mdx" rel="nofollow noreferrer">remix documentation</a> does hint at this, but doesn't appear to provide a solid suggestion.</p>
<blockquote>
<p>Clearly this is not a scalable solution for a blog with thousands of posts. Realistically speaking, writing is hard, so if your blog starts to suffer from too much content, that's an awesome problem to have. If you get to 100 posts (congratulations!), we suggest you rethink your strategy and turn your posts into data stored in a database so that you don't have to rebuild and redeploy your blog every time you fix a typo.</p>
</blockquote>
<p>(Personally, I don't think redeploying each time you fix a typo is too much of a problem, it's more I don't want to have to manually add links everytime I add a new post).</p>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1068446/"
] |
74,394,635 | <p>I am unable to delete PostgreSQL database in azure using the below command:</p>
<pre><code>az PostgreSQL db delete
</code></pre>
<p>Is there any other script such as bash to clean up azure postgreSQL database?</p>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18538111/"
] |
74,394,637 | <p>I am attempting to perform a global setup in the App.razor file, which would read some data from the browser local storage and then assign it some global state class.</p>
<p>However, I have run into a problem with the order of tasks being fulfilled. Consider the code below:</p>
<p>This is what I currently have:</p>
<pre><code>@inject IJSRuntime JSRuntime;
<Router AppAssembly="@typeof(App).Assembly">
@...
</Router>
@code {
string token { get; set; } = default!;
protected async override Task OnInitializedAsync()
{
token = await JSRuntime.InvokeAsync<string>("localStorage.getItem", "token");
stateService.token = token;
System.Console.WriteLine("Token A : " + token);
}
}
</code></pre>
<p>The above correctly gets the local storage item, but not before the next page below loads. The problem is the page below needs access to the stateService.token set above.</p>
<p>and then in pages/login.razor.cs:</p>
<pre><code>using Microsoft.AspNetCore.Components;
namespace Pages.Login
{
public partial class Login : ComponentBase
{
protected override void OnAfterRender(bool firstRender)
{
token = stateService.Token;
System.Console.WriteLine("Token B: " + token);
}
}
}
</code></pre>
<p>The output is:</p>
<pre><code>Token B:
Token A: TestValueToken
</code></pre>
<p>But of course I would need it to be:</p>
<pre><code>Token A: TestValueToken
Token B: TestValueToken
</code></pre>
<p>I know why the above is occuring but have no idea thow to fix it. Any suggestions would be welcomed.</p>
| [
{
"answer_id": 74395605,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n nodesep = \"0.15\"\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74397081,
"author": "sroush",
"author_id": 12317235,
"author_profile": "https://Stackoverflow.com/users/12317235",
"pm_score": 1,
"selected": false,
"text": "digraph G {\n // nodesep = \"0.15\"\n splines=false\n edge[penwidth=7]\n a:sw -> b:nw [dir=none color=\"red\"]\n a -> b [dir=none color=\"blue\"]\n a:se -> b:ne [dir=none color=\"green\"]\n \n c -> d [dir=none color=\"green:white:white:white:red:white:white:white:blue\"]\n}\n"
},
{
"answer_id": 74536797,
"author": "The Bic Pen",
"author_id": 9074788,
"author_profile": "https://Stackoverflow.com/users/9074788",
"pm_score": 1,
"selected": true,
"text": "digraph G {\n c -> d [\n dir=none\n penwidth=5\n color=\"red:transparent:transparent:green:transparent:transparent:blue\"\n ]\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3469841/"
] |
74,394,642 | <p>I'm trying to get the charindex for multiple CHAR(10) characters in a string in SQL Server.</p>
<p>The first and second linebreaks are found alright, the 3rd one is a problem however.</p>
<pre><code>CHARINDEX(CHAR(10),subadres) AS '1st linebreak',
CHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1)) AS '2rd linebreak',
CHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1)+(CHARINDEX(CHAR(10),subadres))) AS '3rd linebreak',
</code></pre>
<p>In the example below, the second entry is okay. The first entry results in a false value for the 3rd linebreak (the || represent the CHAR(10) in my datasource).</p>
<p>I'm assuming the character on the right is causing this, but I can't find out how (and why).</p>
<pre><code>Entry nr1: Line 1||Line 2||Line 3||Line 4||
Entry nr2: Line 1||Line 2||Line 3||Line4
</code></pre>
<p>I tried to trim the trailing CHAR(10) on the first line, this did not do anything however.</p>
| [
{
"answer_id": 74394921,
"author": "John Cappelletti",
"author_id": 1570000,
"author_profile": "https://Stackoverflow.com/users/1570000",
"pm_score": 1,
"selected": false,
"text": "Declare @YourTable Table ([subaddrs] varchar(50)) Insert Into @YourTable Values \n ('Line 1\nLine 2\nLine 3\nLine 4\n ')\n,('Line 1\nLine 2\nLine 3\nLine4')\n \nSelect Pos1 = JSON_VALUE(JS,'$[0]')\n ,Pos2 = JSON_VALUE(JS,'$[1]')\n ,Pos3 = JSON_VALUE(JS,'$[2]')\n ,Pos4 = JSON_VALUE(JS,'$[3]')\n ,Pos5 = nullif(JSON_VALUE(JS,'$[4]'),'') -- nullif() optional\n From @YourTable A\n Cross Apply (values ('[\"'+replace(\n string_escape(\n replace(\n replace([subaddrs],char(13),'')\n ,char(10),'||')\n ,'json')\n ,'||','\",\"'\n )+'\"]'\n ) ) C(JS)\n"
},
{
"answer_id": 74406910,
"author": "snijder",
"author_id": 20471977,
"author_profile": "https://Stackoverflow.com/users/20471977",
"pm_score": 0,
"selected": false,
"text": "CHARINDEX(CHAR(10),subadres)-1 AS '1st linebreak',\nCHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1)) AS '2nd linebreak',\nCHARINDEX(CHAR(10),subadres,CHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1))+1) AS '3rd linebreak',\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20471977/"
] |
74,394,665 | <p>I am binding ObservableCollection with CollectionView.</p>
<pre><code><CollectionView ItemsSource="{Binding LeftExercises}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:ExerciseModel">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="{Binding SetNumber}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" TextColor="Black" FontSize="Medium" />
<Label Grid.Column="1" Grid.Row="0" Text="{Binding Weight}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" TextColor="Black" FontSize="Medium" />
<Label Grid.Column="2" Grid.Row="0" Text="{Binding Reps}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" TextColor="Black" FontSize="Medium" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
private ObservableCollection<ExerciseModel> _leftExercises;
public ObservableCollection<ExerciseModel> LeftExercises
{
get => _leftExercises;
set
{
if (_leftExercises != value)
{
_leftExercises = value;
OnPropertyChanged(nameof(LeftExercises));
}
}
}
</code></pre>
<p>When I add a new object to the Collection, it will reflect in my UI but whenever I try to update the value of any object, it will not reflect.</p>
<p>This is my model</p>
<pre><code>public class ExerciseModel
{
public int SetNumber { get; set; }
public decimal Weight { get; set; }
public int Reps { get; set; }
public ExerciseType ExerciseType { get; set; }
public Side Side { get; set; }
}
</code></pre>
<p>I am incrementing the Reps (update Reps property) from the below command.</p>
<pre><code>private Command _dummyLeftIncreaseRepsCommand;
public Command dummyLeftIncreaseRepsCommand
{
get
{
return _dummyLeftIncreaseRepsCommand ??= new Command(() =>
{
ExerciseModel lastObj = LeftExercises.Last(x => x.Side == SharedVM.ActiveSide);
lastObj.Reps += 1;
});
}
}
</code></pre>
| [
{
"answer_id": 74394921,
"author": "John Cappelletti",
"author_id": 1570000,
"author_profile": "https://Stackoverflow.com/users/1570000",
"pm_score": 1,
"selected": false,
"text": "Declare @YourTable Table ([subaddrs] varchar(50)) Insert Into @YourTable Values \n ('Line 1\nLine 2\nLine 3\nLine 4\n ')\n,('Line 1\nLine 2\nLine 3\nLine4')\n \nSelect Pos1 = JSON_VALUE(JS,'$[0]')\n ,Pos2 = JSON_VALUE(JS,'$[1]')\n ,Pos3 = JSON_VALUE(JS,'$[2]')\n ,Pos4 = JSON_VALUE(JS,'$[3]')\n ,Pos5 = nullif(JSON_VALUE(JS,'$[4]'),'') -- nullif() optional\n From @YourTable A\n Cross Apply (values ('[\"'+replace(\n string_escape(\n replace(\n replace([subaddrs],char(13),'')\n ,char(10),'||')\n ,'json')\n ,'||','\",\"'\n )+'\"]'\n ) ) C(JS)\n"
},
{
"answer_id": 74406910,
"author": "snijder",
"author_id": 20471977,
"author_profile": "https://Stackoverflow.com/users/20471977",
"pm_score": 0,
"selected": false,
"text": "CHARINDEX(CHAR(10),subadres)-1 AS '1st linebreak',\nCHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1)) AS '2nd linebreak',\nCHARINDEX(CHAR(10),subadres,CHARINDEX(CHAR(10),subadres,(CHARINDEX(CHAR(10),subadres)+1))+1) AS '3rd linebreak',\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3265665/"
] |
74,394,682 | <p>I'm trying to make my own bubble-sort algorithm for learning purposes. I'm doing it by:</p>
<ul>
<li>Making a random array</li>
<li>Checking if the first two indexes of the array need to be swapped</li>
<li>it does this throughout the whole list</li>
<li>and does it over and over until when looping through until the end it doesn't need to swap anything anymore then the loop breaks</li>
</ul>
<p>but when I print any variable in the class it says that the class has no attribute of the variable.
this is my code right now</p>
<pre class="lang-python prettyprint-override"><code>from random import randint
class bubbleSort:
def __init__(self, size):
self.size = size # Array size
self.array = [] # Random array
self.sorted = self.array # Sorted array
self.random = 0 # Random number
self.count = 0
self.done = False
self.equal = 0
while self.count != self.size:
random = randint(1, self.size)
if random in self.array:
pass
else:
self.array.append(random)
self.count += 1
def sort(self):
while self.done != True:
self.equal = False
for i in range(self.size):
if i == self.size:
pass
else:
if self.sorted[i] > [self.tmp]:
self.equal += 1
if self.equal == self.size:
self.done = True
else:
self.sorted[i], self.sorted[i + 1] = self.sorted[i+1], self.sorted[i]
new = bubbleSort(10)
print(bubbleSort.array)
</code></pre>
<p>This is what outputs</p>
<pre><code>Traceback (most recent call last):
File "/home/musab/Documents/Sorting Algorithms/Bubble sort.py", line 38, in <module>
print(bubbleSort.array)
AttributeError: type object 'bubbleSort' has no attribute 'array'
</code></pre>
| [
{
"answer_id": 74394838,
"author": "mexx",
"author_id": 6206337,
"author_profile": "https://Stackoverflow.com/users/6206337",
"pm_score": 1,
"selected": false,
"text": "bubbleSort"
},
{
"answer_id": 74394901,
"author": "Elia",
"author_id": 1964317,
"author_profile": "https://Stackoverflow.com/users/1964317",
"pm_score": 1,
"selected": true,
"text": "bubbleSort"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20471910/"
] |
74,394,699 | <p>I'm trying to build a script to convert a XML file to CSV. I started following this guide <a href="https://learn.microsoft.com/en-us/answers/questions/542481/parse-xml-to-csv-help.html" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/answers/questions/542481/parse-xml-to-csv-help.html</a> but I'm stuck with the following situation now:</p>
<p>The first part of my code works fine and it's writing to the CSV file the first column, but as it gets through the following iterations, it doesn't write the values to the file even though it outputs them to the console.
This is my code:</p>
<pre><code>[xml]$x = Get-Content C:\Users\Desktop\Policy.xml
$x.Profiles |
ForEach-Object{
$_.Profile |
ForEach-Object{
$_.Ruleset |
ForEach-Object{
Write-Host "Policy ID = " $_.ID
[PSCustomObject]@{
policyName = $_.ID
}
$_.Conditions |
ForEach-Object{
$_.condition |
ForEach-Object{
if($_.name -eq "Resource") {
Write-Host "Resource = " $_.'#text'
[PSCustomObject]@{
resource = $_.'#text'
}
}
if($_.name -eq "Action") {
Write-Host "Action = " $_.'#text'
[PSCustomObject]@{
action = $_.'#text'
}
}
if($_.name -eq "actor") {
Write-Host "actor = " $_.'#text'
[PSCustomObject]@{
actor = $_.'#text'
}
}
if($_.name -eq "child") {
Write-Host "child = " $_.'#text'
[PSCustomObject]@{
child = $_.'#text'
}
}
if($_.name -eq "number") {
Write-Host "number = " $_.'#text'
[PSCustomObject]@{
number = $_.'#text'
}
}
}
}
}
}
} | Export-Csv C:\Users\Desktop\policy.csv -NoTypeInformation
</code></pre>
<p>So, until the first <code>[PSCustomObject]</code> (line 10) it works fine and the policyName column is written to the CSV value with its corresponding value. But in the second <code>[PSCustomObject]</code> (line 19) where it should write the Resource/Action/actor/child/number, it does not write to the file anymore.</p>
<p>What's the right way to add those values to the already existing <code>[PSCustomObject]</code>?</p>
<p><strong>For reference:</strong></p>
<p><strong>XML snippet</strong></p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Profiles xmlns:pcrf="nothing interesting here">
<Profile Desc="some description" ID="someid" Prio="0">
<Ruleset Class="class1" Desc="" ID="policyid1" Prio="10" active="true">
<Conditions>
<condition name="Resource" type="matchExact">resource1</condition>
<condition name="Action" type="matchExact">action1</condition>
<condition name="actor" type="matchExact">actor1</condition>
</Conditions>
</Ruleset>
<Ruleset Class="classX" Desc="" ID="policyidX" Prio="10" active="true">
<Conditions>
<condition name="Resource" type="matchExact">resource4</condition>
<condition name="Action" type="matchExact">action4</condition>
<condition name="child" type="matchExact">child1,child2</condition>
</Conditions>
</Ruleset>
</Profile>
<Profile Desc="some description" ID="someid" Prio="0">
<Ruleset Class="classY" Desc="" ID="policyidY" Prio="10" active="true">
<Conditions>
<condition name="Resource" type="matchExact">resource99</condition>
<condition name="Action" type="matchExact">action00</condition>
<condition name="child" type="matchExact">child5</condition>
<condition name="number" type="matchExact">number1</condition>
</Conditions>
</Ruleset>
</Profile>
</Profiles>
</code></pre>
<p><strong>I'm getting this CSV as result:</strong></p>
<pre><code>"policyName"
"policyid1"
</code></pre>
<p><strong>This is the powershell output:</strong></p>
<pre><code>PS C:\Users\Desktop> .\xmltocsv.ps1
Policy ID = policyid1
Resource = resource1
Action = action1
actor = actor1
Resource = resource4
Action = action4
child = child1,child2
Resource = resource99
Action = action00
child = child5
number = number1
</code></pre>
<p><strong>This is what I expect to get as a CSV file:</strong></p>
<pre><code>"policyName","Resource","Action","actor","child","number"
"policyid1","resource1","action1","actor1","",""
"policyidX","resource4","action4","","child1,child2",""
"policyidY","resource99","action0","","child5","number1"
</code></pre>
| [
{
"answer_id": 74394838,
"author": "mexx",
"author_id": 6206337,
"author_profile": "https://Stackoverflow.com/users/6206337",
"pm_score": 1,
"selected": false,
"text": "bubbleSort"
},
{
"answer_id": 74394901,
"author": "Elia",
"author_id": 1964317,
"author_profile": "https://Stackoverflow.com/users/1964317",
"pm_score": 1,
"selected": true,
"text": "bubbleSort"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1971762/"
] |
74,394,745 | <blockquote>
<p>I found this code but this sum all the digits but i want it to ad 31 not 3+1
Output : 28
Expected : 100</p>
</blockquote>
<pre><code>#include<stdio.h>
int main()
{
//Initializing variables.
char str[100] = "10+5+6+31+3+45";
int i,sum = 0;
//Iterating each character through for loop.
for (i= 0; str[i] != '\0'; i++)
{
if ((str[i] >= '0') && (str[i] <= '9')) //Checking for numeric characters.
{
sum += (str[i] - '0'); //Adding numeric characters.
}
}
//Printing result.
printf("Sum of all digits:\n%d", sum);
return 0;
}
</code></pre>
| [
{
"answer_id": 74394865,
"author": "David Grayson",
"author_id": 28128,
"author_profile": "https://Stackoverflow.com/users/28128",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main() {\n char str[] = \"10+5+6+31+3+45\";\n\n unsigned int sum = 0;\n unsigned int digit_value = 1;\n\n unsigned int length = strlen(str);\n for (unsigned int i = 0; i < length; i++) {\n char c = str[length - 1 - i];\n if (c == '+') {\n digit_value = 1;\n }\n else if (c >= '0' && c <= '9') {\n sum += digit_value * (c - '0');\n digit_value *= 10;\n }\n }\n\n printf(\"Sum: %d\\n\", sum);\n}\n"
},
{
"answer_id": 74394943,
"author": "NoDakker",
"author_id": 6032177,
"author_profile": "https://Stackoverflow.com/users/6032177",
"pm_score": 3,
"selected": true,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nint main()\n{\n //Initializing variables.\n char str[100] = \"10+5+6+31+3+45\";\n int sum = 0;\n char *token;\n const char s[2] = \"+\";\n\n /* get the first token */\n token = strtok(str, s);\n\n /* walk through other tokens */\n while( token != NULL )\n {\n sum = sum + atoi(token);\n\n token = strtok(NULL, s);\n }\n //Printing result.\n printf(\"Sum of all numbers is: %d\\n\", sum);\n return 0;\n}\n"
},
{
"answer_id": 74395071,
"author": "Kaz",
"author_id": 1250772,
"author_profile": "https://Stackoverflow.com/users/1250772",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <stdlib.h>\n\nstatic void add_up(const char *in, char *out, size_t ndig)\n{\n size_t dig = ndig;\n for (size_t i = strlen(in); i-- > 0; )\n {\n int ch = in[i];\n\n if (isdigit((unsigned char) ch)) {\n size_t j = dig;\n if (j == 0)\n goto overflow;\n out[--j] += (ch - '0');\n while (j >= 1 && out[j] > '9') {\n out[j] -= 10;\n out[--j]++;\n }\n if (out[j] > '9') {\n overflow:\n fputs(\"overflow\\n\", stderr);\n abort();\n }\n dig--;\n } else if (ch == '+') {\n dig = ndig;\n }\n }\n}\n\nint main(int argc, char **argv)\n{\n const char *self = argv[0] ? argv[0] : \"unknown\";\n char sum[] = \"00000000\";\n\n if (argc != 2) {\n fprintf(stderr, \"%s: argument required\\n\", self);\n return EXIT_FAILURE;\n }\n\n add_up(argv[1], sum, sizeof sum - 1);\n puts(sum);\n return 0;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18259502/"
] |
74,394,767 | <p>My <code>dataframe</code> has zero elements after I use <code>dropna()</code> on a 2-dimensional array:</p>
<p><a href="https://i.stack.imgur.com/7UQs2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7UQs2.png" alt="excel" /></a></p>
<pre><code>data = pd.read_excel('/file.xlsx', sheet_name='Sheet1', engine='openpyxl').iloc[0:, 0:].astype(float).dropna().values.flatten()
data
array([], dtype=float64)
</code></pre>
<p>However <code>dropna()</code> works perfectly fine on a 1-dimensional array and the <code>NaNs</code> get cleared out.</p>
<p>What could be something wrong I'm doing?</p>
| [
{
"answer_id": 74394865,
"author": "David Grayson",
"author_id": 28128,
"author_profile": "https://Stackoverflow.com/users/28128",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main() {\n char str[] = \"10+5+6+31+3+45\";\n\n unsigned int sum = 0;\n unsigned int digit_value = 1;\n\n unsigned int length = strlen(str);\n for (unsigned int i = 0; i < length; i++) {\n char c = str[length - 1 - i];\n if (c == '+') {\n digit_value = 1;\n }\n else if (c >= '0' && c <= '9') {\n sum += digit_value * (c - '0');\n digit_value *= 10;\n }\n }\n\n printf(\"Sum: %d\\n\", sum);\n}\n"
},
{
"answer_id": 74394943,
"author": "NoDakker",
"author_id": 6032177,
"author_profile": "https://Stackoverflow.com/users/6032177",
"pm_score": 3,
"selected": true,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nint main()\n{\n //Initializing variables.\n char str[100] = \"10+5+6+31+3+45\";\n int sum = 0;\n char *token;\n const char s[2] = \"+\";\n\n /* get the first token */\n token = strtok(str, s);\n\n /* walk through other tokens */\n while( token != NULL )\n {\n sum = sum + atoi(token);\n\n token = strtok(NULL, s);\n }\n //Printing result.\n printf(\"Sum of all numbers is: %d\\n\", sum);\n return 0;\n}\n"
},
{
"answer_id": 74395071,
"author": "Kaz",
"author_id": 1250772,
"author_profile": "https://Stackoverflow.com/users/1250772",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <stdlib.h>\n\nstatic void add_up(const char *in, char *out, size_t ndig)\n{\n size_t dig = ndig;\n for (size_t i = strlen(in); i-- > 0; )\n {\n int ch = in[i];\n\n if (isdigit((unsigned char) ch)) {\n size_t j = dig;\n if (j == 0)\n goto overflow;\n out[--j] += (ch - '0');\n while (j >= 1 && out[j] > '9') {\n out[j] -= 10;\n out[--j]++;\n }\n if (out[j] > '9') {\n overflow:\n fputs(\"overflow\\n\", stderr);\n abort();\n }\n dig--;\n } else if (ch == '+') {\n dig = ndig;\n }\n }\n}\n\nint main(int argc, char **argv)\n{\n const char *self = argv[0] ? argv[0] : \"unknown\";\n char sum[] = \"00000000\";\n\n if (argc != 2) {\n fprintf(stderr, \"%s: argument required\\n\", self);\n return EXIT_FAILURE;\n }\n\n add_up(argv[1], sum, sizeof sum - 1);\n puts(sum);\n return 0;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3340234/"
] |
74,394,821 | <p>I have a pandas dataframe like below</p>
<pre><code>import pandas as pd
data = [[5, 10], [4, 20], [15, 30], [20, 15], [12, 14], [5, 5]]
df = pd.DataFrame(data, columns=['x', 'y'])
</code></pre>
<p>I am trying to attain the value of this expression.</p>
<p><a href="https://i.stack.imgur.com/WGuHg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WGuHg.png" alt="enter image description here" /></a></p>
<p>I havnt got an idea how to mutiply first value in a column with 2nd value in another column like in the expression.</p>
| [
{
"answer_id": 74394865,
"author": "David Grayson",
"author_id": 28128,
"author_profile": "https://Stackoverflow.com/users/28128",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main() {\n char str[] = \"10+5+6+31+3+45\";\n\n unsigned int sum = 0;\n unsigned int digit_value = 1;\n\n unsigned int length = strlen(str);\n for (unsigned int i = 0; i < length; i++) {\n char c = str[length - 1 - i];\n if (c == '+') {\n digit_value = 1;\n }\n else if (c >= '0' && c <= '9') {\n sum += digit_value * (c - '0');\n digit_value *= 10;\n }\n }\n\n printf(\"Sum: %d\\n\", sum);\n}\n"
},
{
"answer_id": 74394943,
"author": "NoDakker",
"author_id": 6032177,
"author_profile": "https://Stackoverflow.com/users/6032177",
"pm_score": 3,
"selected": true,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nint main()\n{\n //Initializing variables.\n char str[100] = \"10+5+6+31+3+45\";\n int sum = 0;\n char *token;\n const char s[2] = \"+\";\n\n /* get the first token */\n token = strtok(str, s);\n\n /* walk through other tokens */\n while( token != NULL )\n {\n sum = sum + atoi(token);\n\n token = strtok(NULL, s);\n }\n //Printing result.\n printf(\"Sum of all numbers is: %d\\n\", sum);\n return 0;\n}\n"
},
{
"answer_id": 74395071,
"author": "Kaz",
"author_id": 1250772,
"author_profile": "https://Stackoverflow.com/users/1250772",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <stdlib.h>\n\nstatic void add_up(const char *in, char *out, size_t ndig)\n{\n size_t dig = ndig;\n for (size_t i = strlen(in); i-- > 0; )\n {\n int ch = in[i];\n\n if (isdigit((unsigned char) ch)) {\n size_t j = dig;\n if (j == 0)\n goto overflow;\n out[--j] += (ch - '0');\n while (j >= 1 && out[j] > '9') {\n out[j] -= 10;\n out[--j]++;\n }\n if (out[j] > '9') {\n overflow:\n fputs(\"overflow\\n\", stderr);\n abort();\n }\n dig--;\n } else if (ch == '+') {\n dig = ndig;\n }\n }\n}\n\nint main(int argc, char **argv)\n{\n const char *self = argv[0] ? argv[0] : \"unknown\";\n char sum[] = \"00000000\";\n\n if (argc != 2) {\n fprintf(stderr, \"%s: argument required\\n\", self);\n return EXIT_FAILURE;\n }\n\n add_up(argv[1], sum, sizeof sum - 1);\n puts(sum);\n return 0;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17939220/"
] |
74,394,829 | <p>I have to face some problem about my Googlesheets Data. I want to filter my googlesheets data between two dates and also filter more conditions at the same time in same sheets. Below are given some sample data.</p>
<p><a href="https://docs.google.com/spreadsheets/d/1h5PW52PoMUxXtrqEmfXSCWu_OKXVO8IwUbHqcqSPRzs/edit?usp=share_link" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1h5PW52PoMUxXtrqEmfXSCWu_OKXVO8IwUbHqcqSPRzs/edit?usp=share_link</a></p>
<p>Basically, I want to filter data between two date & two more conditions at a same time in same sheets.</p>
<p>Please help me about this issues.</p>
<p>Thanks</p>
<p>I am trying to hard to solve this issues but I cann't solve this with myself. so if anyone solve this issues then please do this.</p>
<p>I'm very glad for all of you.</p>
<p>Thanks</p>
| [
{
"answer_id": 74394865,
"author": "David Grayson",
"author_id": 28128,
"author_profile": "https://Stackoverflow.com/users/28128",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n\nint main() {\n char str[] = \"10+5+6+31+3+45\";\n\n unsigned int sum = 0;\n unsigned int digit_value = 1;\n\n unsigned int length = strlen(str);\n for (unsigned int i = 0; i < length; i++) {\n char c = str[length - 1 - i];\n if (c == '+') {\n digit_value = 1;\n }\n else if (c >= '0' && c <= '9') {\n sum += digit_value * (c - '0');\n digit_value *= 10;\n }\n }\n\n printf(\"Sum: %d\\n\", sum);\n}\n"
},
{
"answer_id": 74394943,
"author": "NoDakker",
"author_id": 6032177,
"author_profile": "https://Stackoverflow.com/users/6032177",
"pm_score": 3,
"selected": true,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nint main()\n{\n //Initializing variables.\n char str[100] = \"10+5+6+31+3+45\";\n int sum = 0;\n char *token;\n const char s[2] = \"+\";\n\n /* get the first token */\n token = strtok(str, s);\n\n /* walk through other tokens */\n while( token != NULL )\n {\n sum = sum + atoi(token);\n\n token = strtok(NULL, s);\n }\n //Printing result.\n printf(\"Sum of all numbers is: %d\\n\", sum);\n return 0;\n}\n"
},
{
"answer_id": 74395071,
"author": "Kaz",
"author_id": 1250772,
"author_profile": "https://Stackoverflow.com/users/1250772",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <stdlib.h>\n\nstatic void add_up(const char *in, char *out, size_t ndig)\n{\n size_t dig = ndig;\n for (size_t i = strlen(in); i-- > 0; )\n {\n int ch = in[i];\n\n if (isdigit((unsigned char) ch)) {\n size_t j = dig;\n if (j == 0)\n goto overflow;\n out[--j] += (ch - '0');\n while (j >= 1 && out[j] > '9') {\n out[j] -= 10;\n out[--j]++;\n }\n if (out[j] > '9') {\n overflow:\n fputs(\"overflow\\n\", stderr);\n abort();\n }\n dig--;\n } else if (ch == '+') {\n dig = ndig;\n }\n }\n}\n\nint main(int argc, char **argv)\n{\n const char *self = argv[0] ? argv[0] : \"unknown\";\n char sum[] = \"00000000\";\n\n if (argc != 2) {\n fprintf(stderr, \"%s: argument required\\n\", self);\n return EXIT_FAILURE;\n }\n\n add_up(argv[1], sum, sizeof sum - 1);\n puts(sum);\n return 0;\n}\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10004780/"
] |
74,394,853 | <p>Literally what the title says. I don't know where I'm wrong.</p>
<pre><code>
import { useState, useEffect, useRef } from "react";
const Gameboard = () => {
const [grids, setGrids] = useState([]);
const [snake, setSnake] = useState([100, 101]);
const [direction, setDirection] = useState('what');
const gameBoardRef = useRef(true);
const gameBoardChildren = grids.map(grid => (
<div key={ grid }></div>
));
const startInterval = () => {
window.addEventListener('keydown', e => switchDirection(e));
const gridsArray = Array.from(gameBoardRef.current.children);
setInterval(() => {
setSnake(prevState => {
let temp = [];
prevState.forEach(piece => {
piece++;
temp.push(piece);
gridsArray[piece].style.backgroundColor = 'black';
});
gridsArray[prevState[0]].style.backgroundColor = '';
console.log(temp)
return temp;
})
}, 1000);
};
const switchDirection = (e) => {
console.log(e.keyCode);
if (e.keyCode === 37) {
console.log(direction);
return setDirection('left');
};
if (e.keyCode === 40) {
console.log(direction);
return setDirection('down');
};
if (e.keyCode === 39) {
console.log(direction);
return setDirection('right');
};
if (e.keyCode === 38) {
console.log(direction);
return setDirection('up');
};
}
useEffect(() => {
let temp = [];
for (let i = 0; i < 196; i++) {
const grid = i;
temp.push(grid);
};
setGrids(temp);
}, []);
return (
<div>
<button onClick={startInterval}>Click me</button>
<div className="game-board" ref={gameBoardRef}>{ gameBoardChildren }</div>
</div>
);
}
export default Gameboard;
</code></pre>
<p>I've got no error messages. I tried everything literally. Assigning the direction values to a variable then setting the state to that var. I tried this with another state and the same thing happened. It either stays what the initial value was or if there was no value it's unidentified.</p>
| [
{
"answer_id": 74394963,
"author": "Oussama Mg",
"author_id": 16626467,
"author_profile": "https://Stackoverflow.com/users/16626467",
"pm_score": 1,
"selected": false,
"text": "const switchDirection = (e) => {\n console.log(e.keyCode);\n if (e.keyCode === 37) {\n setDirection('left');\n console.log(direction);\n };\n\n if (e.keyCode === 40) { \n setDirection('down');\n console.log(direction);\n \n };\n\n if (e.keyCode === 39) { \n setDirection('right');\n console.log(direction);\n };\n \n if (e.keyCode === 38) { \n setDirection('up');\n console.log(direction);\n };\n }\n"
},
{
"answer_id": 74395305,
"author": "John Li",
"author_id": 20436957,
"author_profile": "https://Stackoverflow.com/users/20436957",
"pm_score": 2,
"selected": true,
"text": "setDirection"
},
{
"answer_id": 74395585,
"author": "omers",
"author_id": 20001685,
"author_profile": "https://Stackoverflow.com/users/20001685",
"pm_score": 0,
"selected": false,
"text": " const switchDirection = (e) => {\n let newDirection;\n switch (e.keyCode) {\n case 37:\n newDirection = 'left';\n break;\n case 40:\n newDirection = 'down';\n break;\n case 39:\n newDirection = 'right';\n break;\n case 38:\n newDirection = 'up';\n break;\n default:\n newDirection = undefined;\n }\n console.log(e.keyCode, newDirection);\n if (direction) setDirection(newDirection);\n};\n"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20306342/"
] |
74,394,857 | <p>recently my Microsoft self hosted integration runtime automatically updated and now I can't pull data from my onprem folder and transfer it to a blob storage. The error code I receive is</p>
<p>Error Code 28051</p>
<p>Details d could not be resolved.
Activity ID: d999e0c0-cb2c-4161-aad5-e01510ca7e8f</p>
<p>Has this happened to any else before?</p>
<p><a href="https://i.stack.imgur.com/31TSu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/31TSu.png" alt="Error Code Image" /></a></p>
| [
{
"answer_id": 74601778,
"author": "jikuja",
"author_id": 776884,
"author_profile": "https://Stackoverflow.com/users/776884",
"pm_score": 1,
"selected": false,
"text": "dmgcmd.exe -DisableLocalFolderPathValidation"
},
{
"answer_id": 74646611,
"author": "Howard Renollet",
"author_id": 2382743,
"author_profile": "https://Stackoverflow.com/users/2382743",
"pm_score": 0,
"selected": false,
"text": "\\\\?\\"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20053349/"
] |
74,394,892 | <p>I have installed perlbrew and installed two Perls with it.
Now I am trying to separate libraries for modules I install with cpanm.</p>
<p>I want (if possible) to switch to one Perl (within Perlbrew) (for example: 5.22.4) and once I call <code>cpanm install Some::Module</code> the module will be installed in the separate library, related only to this Perl.</p>
<p>Then, in the script, I would like to have like the example below:</p>
<pre><code>#!/usr/bin/env perl
use strict;
use Some::Module;
print "Content-type:text/html\n\n";
print "Works!";
</code></pre>
<p>and that's it. No any other <code>use lib 'path';</code> or so.
I tried to use <code>perlbrew lib create perl-5.22.4@somename</code> and then switch to it.</p>
<p>Then call <code>cpanm install Some::Module</code> and I see the result at the location <code>~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm</code>, but when I call my script from a browser I see <code>Error 500</code> and the logs say <code>"missing module Some::Module, check @INC etc..."</code></p>
<p>What I also found that if I move the <code>~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm</code> to <code>~/perl5/perlbrew/perls/perl-5.22.4/lib/5.22.4/Some/Module.pm</code> or to <code>/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux/Some/Module.pm</code> then the script works. And Perl 5.22.4 (in our example) has its own library without need to use <code>use lib 'path';</code></p>
<p>But, how to set up Perlbrew to switch cpanm automatically to this directory?</p>
<p>What I was also trying: <code>cpanm install -l /home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux Some::Module</code> to specify the target lib dir, but it creates the next tree under <code>/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/lib/site_perl/5.22.4/x86_64-linux</code> instead:</p>
<ul>
<li>lib
<ul>
<li>perl5
<ul>
<li>Some
<ul>
<li>Module.pm</li>
</ul>
</li>
<li>x86_64-linux
<ul>
<li>auto
<ul>
<li>[.....]</li>
</ul>
</li>
<li>.meta
<ul>
<li>[.....]</li>
</ul>
</li>
<li>perllocal.pod</li>
</ul>
</li>
<li>install.pm</li>
</ul>
</li>
</ul>
</li>
<li>man
<ul>
<li>man3
<ul>
<li>[.....]</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>and, sadly, the script throws <code>Error 500</code>.</p>
<p>So, is there a possibility to omit <code>use lib 'path';</code> in the script, switching between multiple Perl versions in Perlbrew?</p>
<p>This all happens on Ubuntu 22.04.</p>
<p><strong>Update</strong>:</p>
<p>When switching to perl-5.22.4@somename and installing Some::Module via cpanm the module appears under the <code>~/.perlbrew/perl-5.22.4@somename/lib/perl5/Some/Module.pm</code> as mentioned above, but the CGI script fails with Error 500.</p>
<p>However, when I execute the next command: <code>perlbrew list-modules</code> it shows Some::Module as installed under the current Perl (which I am switched to). So, this is a dissonance: Perlbrew "sees" the module under the specific Perl, but the CGI script cannot "see" this module under the same Perl.</p>
<p><strong>Update 2</strong>:</p>
<p>here is the output of the <code>perlbrew info:</code></p>
<pre><code>Current perl:
Name: perl-5.22.4@somename
Path: /home/username/perl5/perlbrew/perls/perl-5.22.4/bin/perl
Config: -de -Dprefix=/home/username/perl5/perlbrew/perls/perl-5.22.4 -Dusesitecustomize -Aeval:scriptdir=/home/username/perl5/perlbrew/perls/perl-5.22.4/bin
Compiled at: Nov 10 2022 23:26:53
perlbrew:
version: 0.96
ENV:
PERLBREW_ROOT: /home/username/perl5/perlbrew
PERLBREW_HOME: /home/username/.perlbrew
PERLBREW_PATH: /home/username/.perlbrew/libs/perl-5.22.4@somename/bin:/home/username/perl5/perlbrew/bin:/home/arseniigorkin/perl5/perlbrew/perls/perl-5.22.4/bin
PERLBREW_MANPATH: /home/username/.perlbrew/libs/perl-5.22.4@somename/man:/home/username/perl5/perlbrew/perls/perl-5.22.4/man
</code></pre>
<p><strong>Update 3</strong>:</p>
<p>The dirs permissions for the libs:
<a href="https://i.stack.imgur.com/2QTYx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2QTYx.png" alt="enter image description here" /></a>
and
<a href="https://i.stack.imgur.com/d1gAQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d1gAQ.png" alt="enter image description here" /></a></p>
<p><code>@terry0its</code> is the name of the library (in the example I called it <code>@somename</code>.</p>
<p>Update 4:</p>
<p>Printing vars:</p>
<ul>
<li><code>PERL_MB_OPT</code></li>
<li><code>PERL_MM_OPT</code></li>
<li><code>PERL5LIB</code></li>
<li><code>PATH</code></li>
<li><code>PERL_LOCAL_LIB_ROOT</code></li>
</ul>
<p>with the script:</p>
<pre><code>#!/usr/bin/env perl
print "Content-type:text/html\n\n";
print <<HTML;
Vars:<br>
PERL_MB_OPT = @{[$ENV{"PERL_MB_OPT"}]}<br>
PERL_MM_OPT = @{[$ENV{"PERL_MM_OPT"}]}<br>
PERL5LIB = @{[$ENV{"PERL5LIB"}]}<br>
PATH = @{[$ENV{"PATH"}]}<br>
PERL_LOCAL_LIB_ROOT = @{[$ENV{"PERL_LOCAL_LIB_ROOT"}]}<br>
HTML
</code></pre>
<ol>
<li>In the web browser:</li>
</ol>
<p><em>Vars</em>:</p>
<p><code>PERL_MB_OPT</code> =</p>
<p><code>PERL_MM_OPT</code> =</p>
<p><code>PERL5LIB</code> =</p>
<p><code>PATH</code> = /home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/username/anaconda3/condabin:/root/Komodo IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts</p>
<p><code>PERL_LOCAL_LIB_ROOT</code> =</p>
<ol start="2">
<li>With the terminal:</li>
</ol>
<blockquote>
<p>Content-type:text/html</p>
<p>Vars:<br></p>
<p><code>PERL_MB_OPT</code> = --install_base
/home/username/.perlbrew/libs/perl-5.22.4@terry0its<br></p>
<p><code>PERL_MM_OPT</code> =
INSTALL_BASE=/home/username/.perlbrew/libs/perl-5.22.4@terry0its<br></p>
<p><code>PERL5LIB</code> =
/home/username/.perlbrew/libs/perl-5.22.4@terry0its/lib/perl5<br></p>
<p><code>PATH</code> =
/home/username/.perlbrew/libs/perl-5.22.4@terry0its/bin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo
IDE/bin:/home/username/anaconda3/condabin:/root/Komodo
IDE/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts<br></p>
<p><code>PERL_LOCAL_LIB_ROOT</code> =
/home/username/.perlbrew/libs/perl-5.22.4@terry0its<br></p>
</blockquote>
<p><strong>Update 5</strong>:</p>
<p>When I switch to a pure perl-5.22.4 (without external lib, like @terry0its) I see the next output for the same scripts (after the restart of the server):</p>
<ol>
<li>In the web browser:</li>
</ol>
<p><em>Vars</em>:</p>
<p><code>PERL_MB_OPT</code> =</p>
<p><code>PERL_MM_OPT</code> =</p>
<p><code>PERL5LIB</code> =</p>
<p><code>PATH</code> = /home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/arseniigorkin/perl5/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts</p>
<p><code>PERL_LOCAL_LIB_ROOT</code> =</p>
<ol start="2">
<li>With the terminal:</li>
</ol>
<blockquote>
<p>Content-type:text/html</p>
<p>Vars:<br></p>
<p><code>PERL_MB_OPT</code> --install_base "/home/username/perl5"<br></p>
<p><code>PERL_MM_OPT</code> = INSTALL_BASE=/home/username/perl5<br></p>
<p><code>PERL5LIB</code> = <br></p>
<p><code>PATH</code> =
/home/username/anaconda3/condabin:/home/username/perl5/perlbrew/bin:/home/username/perl5/perlbrew/perls/perl-5.22.4/bin:/root/Komodo IDE/bin:/home/username/perl5/bin:/home/username/pycharm/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts<br></p>
<p><code>PERL_LOCAL_LIB_ROOT</code> =
/home/username/perl5<br></p>
</blockquote>
| [
{
"answer_id": 74601778,
"author": "jikuja",
"author_id": 776884,
"author_profile": "https://Stackoverflow.com/users/776884",
"pm_score": 1,
"selected": false,
"text": "dmgcmd.exe -DisableLocalFolderPathValidation"
},
{
"answer_id": 74646611,
"author": "Howard Renollet",
"author_id": 2382743,
"author_profile": "https://Stackoverflow.com/users/2382743",
"pm_score": 0,
"selected": false,
"text": "\\\\?\\"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4895979/"
] |
74,394,904 | <p>I'm trying to convert Likert scale survey data (e.g., "Strongly Agree - 1") into numeric data for use in statistical analysis. I've got dozens of questions using the same scale.</p>
<p>I found a solution, but it seems clumsy and was hoping someone could suggest an improvement for the sake of learning.</p>
<pre><code>df = df %>%
mutate_all(funs(str_replace(.,"Very Dissatisfied1", "1"))) %>%
mutate_all(funs(str_replace(.,"ModeratelyDissatisfied2", "2"))) %>%
mutate_all(funs(str_replace(.,"SlightlyDissatisfied3", "3"))) %>%
mutate_all(funs(str_replace(.,"Neither SatisfiedNor Dissatisfied4", "4"))) %>%
mutate_all(funs(str_replace(.,"SlightlySatisfied5", "5"))) %>%
mutate_all(funs(str_replace(.,"ModeratelySatisfied6", "6"))) %>%
mutate_all(funs(str_replace(.,"VerySatisfied7", "7")))
</code></pre>
<p>I'm not sure what funs() is doing here, or to what extent mutate_all can take multiple arguments. How can this code be improved? Thanks for your help.</p>
| [
{
"answer_id": 74395163,
"author": "Baraliuh",
"author_id": 11157753,
"author_profile": "https://Stackoverflow.com/users/11157753",
"pm_score": 2,
"selected": false,
"text": "funs"
},
{
"answer_id": 74395468,
"author": "Jilber Urbina",
"author_id": 1315767,
"author_profile": "https://Stackoverflow.com/users/1315767",
"pm_score": 0,
"selected": false,
"text": "replacement"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13199647/"
] |
74,394,927 | <p>I have a structure like</p>
<pre><code> const test = [
{
items: [
{
id: "tete",
},
{
id: "tete",
},
],
},
{
items: [
{
id: "tete",
},
],
},
];
</code></pre>
<p>How go i get all the 'id' value from these array using javascript.</p>
| [
{
"answer_id": 74395022,
"author": "caTS",
"author_id": 18244921,
"author_profile": "https://Stackoverflow.com/users/18244921",
"pm_score": 1,
"selected": false,
"text": "flatMap"
},
{
"answer_id": 74395081,
"author": "Jagrut Sharma",
"author_id": 2780480,
"author_profile": "https://Stackoverflow.com/users/2780480",
"pm_score": 0,
"selected": false,
"text": "id"
}
] | 2022/11/10 | [
"https://Stackoverflow.com/questions/74394927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14568670/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.