qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
74,459,682 | <p>I have a component that i loop through using v-for and props. I want every rendered component to have a different on click event but i can't figure out how to pass a function as a prop.</p>
<p>Code:</p>
<p>Component:</p>
<pre><code><template>
<div v-on:click="cardProperties.scrollFunction" :id="cardProperties.id" class="flex text-text-color justify-around text-center bg-container-color h-1/6 w-2/12 rounded-3xl shadow-lg m-4 cursor-pointer ease-in-out duration-500 hover:bg-container-hover-color opacity-95">
<div class="py-6">
<h2>{{cardProperties.title}}</h2>
<font-awesome-icon class="h-12 my-4" :icon="cardProperties.icon" />
<p>{{cardProperties.text}}</p>
</div>
</div>
</template>
<script>
export default {
name: 'card-container',
components: {
},
props: {
cardProperties: Object,
},
data() {
return{
cardProps: this.cardProperties
}
},
methods: {
musicScroll() {
const musicDiv = document.getElementById("music");
if(musicDiv != null){
musicDiv.scrollIntoView({behavior: 'smooth'})
}
},
maoScroll() {
const maoDiv = document.getElementById("mao");
if(maoDiv != null){
maoDiv.scrollIntoView({behavior: 'smooth'})
}
},
},
}
</script>
</code></pre>
<p>App.vue:</p>
<pre><code><card
v-for="cardProperties in cardPropsArray"
v-bind:key="cardProperties.text"
:cardProperties = cardProperties
/>
</code></pre>
<p>...</p>
<pre><code>cardPropsArray:[
{
id: "music",
scrollFunction: "musicScroll()",
title: "Musik",
icon: "fa-solid fa-music",
text: "/play"
},
{
id: "mao",
scrollFunction: "maoScroll()",
title: "Med Andra Ord",
icon: "fa-solid fa-hourglass-end",
text: "/MAO"
},
</code></pre>
<p>I have tried to pass "scrollFunction" as a prop but since it sends the prop as a string it doesn't work.
It results in the error message: "TypeError: $props.cardProperties.scrollFunction is not a function"</p>
| [
{
"answer_id": 74459657,
"author": "Rory",
"author_id": 3611989,
"author_profile": "https://Stackoverflow.com/users/3611989",
"pm_score": 3,
"selected": true,
"text": "ws"
},
{
"answer_id": 74460430,
"author": "freeflow",
"author_id": 7177346,
"author_profile": "https://Stackoverflow.com/users/7177346",
"pm_score": 1,
"selected": false,
"text": "Option Explicit\n\n' Put the following in the module where you keep global variables\nConst ExcludeNames As String = \"BoQ,Sign Off Sheet,PIANOI\"\n\n' use this function to create the ArrayList of names you wish to exclude\n' ArrayList requires a reference to mscorlib\nPublic Function SetupExcludedWorksheets(ByVal ipStringOfNames As String) As ArrayList\n\n Dim myName As Variant\n Dim myExcludes As ArrayList\n Set myExcludes = New ArrayList\n \n For Each myName In ipStringOfNames.Split(\",\")\n myExcludes.Add myName\n Next\n \n Set SetupExcludedWorksheets = myExcludes(excludeNames)\n \nEnd Function\n\n' in your setup routines include the following lines\nDim myExcludes As ArrayList\nSet myExcludes = SetupExcludedWorksheets(ExcludeNames)\n\n' Your code now becomes\nDim ws As Worksheet\n\nFor Each ws In ActiveWorkbook.Worksheets\n If Not myExcludes.contains(ws.Name) Then\n ws.Cells(46, 14).Formula = \"=Frontsheet!J10\"\n ws.Cells(46, 16).Formula = \"=Frontsheet!J9\"\n End If\nNext\n"
},
{
"answer_id": 74463143,
"author": "VBasic2008",
"author_id": 9814069,
"author_profile": "https://Stackoverflow.com/users/9814069",
"pm_score": 0,
"selected": false,
"text": "Sub CopyFormulae()\n \n Const WORKSHEET_EXCLUSIONS_LIST As String _\n = \"BoQ,Sign Off Sheet,PIANOI\" ' maybe you want to add 'Frontsheet'?\n\n Dim WorksheetExclusions() As String\n WorksheetExclusions = Split(WORKSHEET_EXCLUSIONS_LIST, \",\")\n \n Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code\n \n Dim ws As Worksheet\n \n For Each ws In wb.Worksheets\n With ws\n If IsError(Application.Match(.Name, WorksheetExclusions, 0)) Then\n .Range(\"N46\").Formula = \"=Frontsheet!J10\"\n .Range(\"P46\").Formula = \"=Frontsheet!J9\"\n 'Else ' is found in the WorksheetExclusions array; do nothing\n End If\n End With\n Next ws\n\n MsgBox \"Formulae copied.\", vbInformation\n\nEnd Sub\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19677755/"
] |
74,459,686 | <p>Not sure about which one to use when and their differences</p>
<p>I tried browsing the internet but didn't get any answer</p>
| [
{
"answer_id": 74459657,
"author": "Rory",
"author_id": 3611989,
"author_profile": "https://Stackoverflow.com/users/3611989",
"pm_score": 3,
"selected": true,
"text": "ws"
},
{
"answer_id": 74460430,
"author": "freeflow",
"author_id": 7177346,
"author_profile": "https://Stackoverflow.com/users/7177346",
"pm_score": 1,
"selected": false,
"text": "Option Explicit\n\n' Put the following in the module where you keep global variables\nConst ExcludeNames As String = \"BoQ,Sign Off Sheet,PIANOI\"\n\n' use this function to create the ArrayList of names you wish to exclude\n' ArrayList requires a reference to mscorlib\nPublic Function SetupExcludedWorksheets(ByVal ipStringOfNames As String) As ArrayList\n\n Dim myName As Variant\n Dim myExcludes As ArrayList\n Set myExcludes = New ArrayList\n \n For Each myName In ipStringOfNames.Split(\",\")\n myExcludes.Add myName\n Next\n \n Set SetupExcludedWorksheets = myExcludes(excludeNames)\n \nEnd Function\n\n' in your setup routines include the following lines\nDim myExcludes As ArrayList\nSet myExcludes = SetupExcludedWorksheets(ExcludeNames)\n\n' Your code now becomes\nDim ws As Worksheet\n\nFor Each ws In ActiveWorkbook.Worksheets\n If Not myExcludes.contains(ws.Name) Then\n ws.Cells(46, 14).Formula = \"=Frontsheet!J10\"\n ws.Cells(46, 16).Formula = \"=Frontsheet!J9\"\n End If\nNext\n"
},
{
"answer_id": 74463143,
"author": "VBasic2008",
"author_id": 9814069,
"author_profile": "https://Stackoverflow.com/users/9814069",
"pm_score": 0,
"selected": false,
"text": "Sub CopyFormulae()\n \n Const WORKSHEET_EXCLUSIONS_LIST As String _\n = \"BoQ,Sign Off Sheet,PIANOI\" ' maybe you want to add 'Frontsheet'?\n\n Dim WorksheetExclusions() As String\n WorksheetExclusions = Split(WORKSHEET_EXCLUSIONS_LIST, \",\")\n \n Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code\n \n Dim ws As Worksheet\n \n For Each ws In wb.Worksheets\n With ws\n If IsError(Application.Match(.Name, WorksheetExclusions, 0)) Then\n .Range(\"N46\").Formula = \"=Frontsheet!J10\"\n .Range(\"P46\").Formula = \"=Frontsheet!J9\"\n 'Else ' is found in the WorksheetExclusions array; do nothing\n End If\n End With\n Next ws\n\n MsgBox \"Formulae copied.\", vbInformation\n\nEnd Sub\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11864960/"
] |
74,459,715 | <p>Is there a better / smarter way to do this?</p>
<pre><code>theTitle = responsesToUse[i]["Title"];
if(theTitle == null)
theTitle = "";
</code></pre>
| [
{
"answer_id": 74459743,
"author": "Zeephyros",
"author_id": 19626122,
"author_profile": "https://Stackoverflow.com/users/19626122",
"pm_score": -1,
"selected": false,
"text": "theTitle = responsesToUse[i][\"Title\"] ?? \"\";\n"
},
{
"answer_id": 74459761,
"author": "ask4you",
"author_id": 18309173,
"author_profile": "https://Stackoverflow.com/users/18309173",
"pm_score": 2,
"selected": false,
"text": "null"
},
{
"answer_id": 74459787,
"author": "Manish Kumar",
"author_id": 3442619,
"author_profile": "https://Stackoverflow.com/users/3442619",
"pm_score": -1,
"selected": false,
"text": "const theTitle = responsesToUse?.[i]?.[\"Title\"] || \"\";\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6773512/"
] |
74,459,722 | <p>I have a file containing logs for months and I want to store only the logs for a specific data into a csv file.</p>
<p>sample log data:</p>
<p>2022-06-21 09:06:09 15SS1B Equip = Z39 Text -0003254 Equipment has been added on-line</p>
<p>2022-07-21 09:06:09 15SS2B Equip = Z40 Text -0003254 Equipment has been added on-line</p>
<p>2022-08-21 09:06:09 15SS3B Equip = Z41 Text -0003254 Equipment has been added on-line</p>
<p>2022-09-21 09:06:09 15SS4B Equip = Z42 Text -0003254 Equipment has been added on-line</p>
<p>I get the result with the following columns: IgnoreCase, LineNumber, Line, Filename, Path, Pattern, Context, Matches.
I'm only interested in the result of Line column only.</p>
<p>Appreciate your help.
Thanks.</p>
<p>This is my code:</p>
<pre><code>$data = Get-Content '\log.log' | Select-String -Pattern "2022-08-21" | Export-CSV -Path '\output.csv' -NoTypeInformation
</code></pre>
<p>my request is to get that content and export them into new table like:</p>
<p><code>Date Time Number Type </code></p>
<p><code>2022-06-21 09:06:09 15SS1B Equip</code></p>
| [
{
"answer_id": 74460222,
"author": "Dilly B",
"author_id": 2670623,
"author_profile": "https://Stackoverflow.com/users/2670623",
"pm_score": 0,
"selected": false,
"text": "$line = \"2022-06-21 09:06:09 15SS1B Equip = Z39 Text -0003254 Equipment has been added on-line\"\n$data = $line.Split(\"=\")[0]\n$result = $data.Split(\" \") # A Space in between quotes\n[pscustomObject]@{\n Date = $result[0]\n Time = $result[1]\n Number = $result[2]\n Type = $result[3]\n}\n"
},
{
"answer_id": 74460285,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": true,
"text": "$dateToSearch = '2022-08-21' \n$regex = \"^(?<date>$dateToSearch)\\s+(?<time>\\d{2}:\\d{2}:\\d{2})\\s+(?<number>[a-z\\d]+)\\s+(?<type>\\w+)\\s+=\\.*\"\n\nGet-Content -Path '\\log.log' | Where-Object { $_ -match $regex } | \n Select-Object @{Name = 'Date'; Expression = {$matches['date']}},\n @{Name = 'Time'; Expression = {$matches['time']}},\n @{Name = 'Number'; Expression = {$matches['number']}},\n @{Name = 'Type'; Expression = {$matches['type']}} |\n Export-CSV -Path '\\output.csv' -NoTypeInformation\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519262/"
] |
74,459,752 | <p><a href="https://i.stack.imgur.com/wZfB5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wZfB5.png" alt="This is the blue color border I mean" /></a></p>
<p>I tried bunch of settings, but I can't find how to disable it.</p>
| [
{
"answer_id": 74460222,
"author": "Dilly B",
"author_id": 2670623,
"author_profile": "https://Stackoverflow.com/users/2670623",
"pm_score": 0,
"selected": false,
"text": "$line = \"2022-06-21 09:06:09 15SS1B Equip = Z39 Text -0003254 Equipment has been added on-line\"\n$data = $line.Split(\"=\")[0]\n$result = $data.Split(\" \") # A Space in between quotes\n[pscustomObject]@{\n Date = $result[0]\n Time = $result[1]\n Number = $result[2]\n Type = $result[3]\n}\n"
},
{
"answer_id": 74460285,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": true,
"text": "$dateToSearch = '2022-08-21' \n$regex = \"^(?<date>$dateToSearch)\\s+(?<time>\\d{2}:\\d{2}:\\d{2})\\s+(?<number>[a-z\\d]+)\\s+(?<type>\\w+)\\s+=\\.*\"\n\nGet-Content -Path '\\log.log' | Where-Object { $_ -match $regex } | \n Select-Object @{Name = 'Date'; Expression = {$matches['date']}},\n @{Name = 'Time'; Expression = {$matches['time']}},\n @{Name = 'Number'; Expression = {$matches['number']}},\n @{Name = 'Type'; Expression = {$matches['type']}} |\n Export-CSV -Path '\\output.csv' -NoTypeInformation\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519401/"
] |
74,459,806 | <p>I have a nested array of objects , so i am trying to display in table row only first 3 elements in array and after i am displaying remaining elements in array as a count (i.e +2).Now if i click on remain count i need to display all the elements in array on particular row click.</p>
<p>I am attaching the stack blitz URL for reference :- <a href="https://stackblitz.com/edit/primeng-chip-demo-agf8ey?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts" rel="nofollow noreferrer">https://stackblitz.com/edit/primeng-chip-demo-agf8ey?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts</a></p>
<p>Please help me on these issue.
Thanks in advance</p>
| [
{
"answer_id": 74460222,
"author": "Dilly B",
"author_id": 2670623,
"author_profile": "https://Stackoverflow.com/users/2670623",
"pm_score": 0,
"selected": false,
"text": "$line = \"2022-06-21 09:06:09 15SS1B Equip = Z39 Text -0003254 Equipment has been added on-line\"\n$data = $line.Split(\"=\")[0]\n$result = $data.Split(\" \") # A Space in between quotes\n[pscustomObject]@{\n Date = $result[0]\n Time = $result[1]\n Number = $result[2]\n Type = $result[3]\n}\n"
},
{
"answer_id": 74460285,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": true,
"text": "$dateToSearch = '2022-08-21' \n$regex = \"^(?<date>$dateToSearch)\\s+(?<time>\\d{2}:\\d{2}:\\d{2})\\s+(?<number>[a-z\\d]+)\\s+(?<type>\\w+)\\s+=\\.*\"\n\nGet-Content -Path '\\log.log' | Where-Object { $_ -match $regex } | \n Select-Object @{Name = 'Date'; Expression = {$matches['date']}},\n @{Name = 'Time'; Expression = {$matches['time']}},\n @{Name = 'Number'; Expression = {$matches['number']}},\n @{Name = 'Type'; Expression = {$matches['type']}} |\n Export-CSV -Path '\\output.csv' -NoTypeInformation\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519369/"
] |
74,459,828 | <p>I have created a two screen ,expense screen and incomescreen with toogle button to switching expense screen to income screen and visa versa..</p>
<p>here I have a textfield for amount..and it's value should be not changed while shifting to another screen...</p>
<p>(I mean if change expense screen to income screen, amount should be not changed in textfield...</p>
<p>here is my main file</p>
<pre><code>
class _MyAppState extends State<MyApp> {
bool isexpense=true;
void toogleit()
{
setState(() {
isexpense=!isexpense;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: isexpense==true? ExpenseScreen(ontap: toogleit,txtvalue: '',):IncomeScreen(ontap: toogleit,txtvalue: '',)
);
}
}
</code></pre>
<p>and here is expense screen file..not including income screen as both almost same...</p>
<p>(I could make a CustomScreenWidget but don't want to make it....I am given task to solve without customewidget)</p>
<p>here is expense screen code</p>
<pre><code>class ExpenseScreen extends StatefulWidget {
final VoidCallback ontap;
String txtvalue;
ExpenseScreen({Key? key, required this.ontap,required this.txtvalue}) : super(key: key);
@override
State<ExpenseScreen> createState() => _ExpenseScreenState();
}
class _ExpenseScreenState extends State<ExpenseScreen> {
TextEditingController txtcontroller = TextEditingController();
@override
void initState() {
// TODO: implement initState
super.initState();
txtcontroller.text=widget.txtvalue;
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
txtcontroller.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Container(
height: 300,
decoration: kboxdecoration1,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IntrinsicWidth(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: TextField(
onChanged: (x) {
setState(() {
});
},
controller: txtcontroller,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 30,
),
decoration: kinputdecoration1.copyWith(
hintText:
txtcontroller.text == '' ? 'Amount' : null),
),
),
),
SizedBox(
height: 10,
),
ElevatedButton(
style: kelevetedbutton1,
onPressed: () {},
child: Text('Save Expense')),
SizedBox(
height: 10,
),
TextButton(
onPressed: widget.ontap, child: Text('Jump To Income')),
],
),
),
),
),
),
);
}
}
</code></pre>
| [
{
"answer_id": 74460222,
"author": "Dilly B",
"author_id": 2670623,
"author_profile": "https://Stackoverflow.com/users/2670623",
"pm_score": 0,
"selected": false,
"text": "$line = \"2022-06-21 09:06:09 15SS1B Equip = Z39 Text -0003254 Equipment has been added on-line\"\n$data = $line.Split(\"=\")[0]\n$result = $data.Split(\" \") # A Space in between quotes\n[pscustomObject]@{\n Date = $result[0]\n Time = $result[1]\n Number = $result[2]\n Type = $result[3]\n}\n"
},
{
"answer_id": 74460285,
"author": "Theo",
"author_id": 9898643,
"author_profile": "https://Stackoverflow.com/users/9898643",
"pm_score": 2,
"selected": true,
"text": "$dateToSearch = '2022-08-21' \n$regex = \"^(?<date>$dateToSearch)\\s+(?<time>\\d{2}:\\d{2}:\\d{2})\\s+(?<number>[a-z\\d]+)\\s+(?<type>\\w+)\\s+=\\.*\"\n\nGet-Content -Path '\\log.log' | Where-Object { $_ -match $regex } | \n Select-Object @{Name = 'Date'; Expression = {$matches['date']}},\n @{Name = 'Time'; Expression = {$matches['time']}},\n @{Name = 'Number'; Expression = {$matches['number']}},\n @{Name = 'Type'; Expression = {$matches['type']}} |\n Export-CSV -Path '\\output.csv' -NoTypeInformation\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18817235/"
] |
74,459,873 | <p>I have an object as you have seen below, I want to get the data called measurementPointName from the measurement tables contained in this object, how can I print it to the screen using angular.</p>
<p><a href="https://i.stack.imgur.com/2XXxx.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>I tried <code>*ngFor="let x of measurementTableList"</code> but unfortunately it didn't work.</p>
| [
{
"answer_id": 74460139,
"author": "user2403735",
"author_id": 2403735,
"author_profile": "https://Stackoverflow.com/users/2403735",
"pm_score": 0,
"selected": false,
"text": "// your data\napiResult = [\n {\n workOderId: 1234\n ...\n },\n {\n measurementTableList: [\n ...\n ]\n }\n];\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519481/"
] |
74,459,886 | <p>When I Try to download WSO2 Process Server, It redirects me to API Manager.</p>
<p>The link is <a href="http://wso2.com/products/business-process-server" rel="nofollow noreferrer">http://wso2.com/products/business-process-server</a></p>
<p>Is the WSO2 Process Server deprecated?</p>
| [
{
"answer_id": 74461528,
"author": "ycr",
"author_id": 2627018,
"author_profile": "https://Stackoverflow.com/users/2627018",
"pm_score": 1,
"selected": false,
"text": "Business Process Server"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13091222/"
] |
74,459,919 | <p>how to remove duplicate through some value in object array?</p>
<pre class="lang-kotlin prettyprint-override"><code>
data class Person(
val id: Int,
val name: String,
val gender: String
)
val person1 = Person(1, "Lonnie", "female")
val person2 = Person(2, "Noah", "male")
val person3 = Person(3, "Ollie", "female")
val person4 = Person(4, "William", "male")
val person5 = Person(5, "Lucas", "male")
val person6 = Person(6, "Mia", "male")
val person7 = Person(7, "Ollie", "female")
val personList = listOf(person1,person2,person3,person4,person5,person6,person7)
</code></pre>
<p>Person 3 and person 7 have a "female" gender and have the same name. So person7 needs to be removed.</p>
<p><strong>But "male" gender can have duplicated name.</strong></p>
<p>And the order of the list must be maintained.</p>
<p>expect result</p>
<pre><code>[
Person(1, "Lonnie", "female"),
Person(2, "Noah", "male"),
Person(3, "Ollie", "female"),
Person(4, "William", "male"),
Person(5, "Lucas", "male"),
Person(6, "Mia", "male"),
]
</code></pre>
| [
{
"answer_id": 74461528,
"author": "ycr",
"author_id": 2627018,
"author_profile": "https://Stackoverflow.com/users/2627018",
"pm_score": 1,
"selected": false,
"text": "Business Process Server"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11680852/"
] |
74,459,952 | <p>I am using Python in CoLab and I am trying to find something that will allow me to move any cells from a subset of a data frame into a new/different column in the same data frame OR sort the cells of the dataframe into the correct columns.</p>
<p><a href="https://i.stack.imgur.com/UEEXS.png" rel="nofollow noreferrer">The original column in the CSV looked like this:</a></p>
<p>and using</p>
<pre><code>Users[['Motorbike', 'Car', 'Bus', 'Train', 'Tram', 'Taxi']] = Users['What distance did you travel in the last month by:'].str.split(',', expand=True)
</code></pre>
<p>I was able to split the column into 6 new series to give <a href="https://i.stack.imgur.com/mfJzC.png" rel="nofollow noreferrer">this</a></p>
<p>However, now I would like all the cells with 'Motorbike' in the motorbike column, all the cells wih 'Car' in the Car column and so on, without overwriting any other cells OR if this cannot be done, to just assign any occurances of Motorbike, Car etc into the new columns 'Motorbike1', 'Car1' etc. that I have added to the dataframe as shown below. Can anyone help please?
<a href="https://i.stack.imgur.com/n1gqM.png" rel="nofollow noreferrer">new columns</a></p>
<p>I have tried to copy the cells in original columns to the new columns and then get rid of values containing say not 'Car' However repeating for the next original column into the same first new column it overwrites.
There are no repeats of any mode of transport in any row. i.e there is only one or less occurrence of each mode of transport in every row.</p>
| [
{
"answer_id": 74461528,
"author": "ycr",
"author_id": 2627018,
"author_profile": "https://Stackoverflow.com/users/2627018",
"pm_score": 1,
"selected": false,
"text": "Business Process Server"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519409/"
] |
74,459,958 | <p>I tried to write a funtion, which can be inserted in any expresion, in order to log the value:</p>
<pre class="lang-kotlin prettyprint-override"><code>val x = (2.debug() + 3.debug()).debug("2+3")
</code></pre>
<p>But instead I wrote the following endless loop:</p>
<pre class="lang-kotlin prettyprint-override"><code>fun debug (message: String) {
Log.d (R.string.app_name.toString(), message) }
fun <T> T.debug (tag: String = "value"): T {
debug ("$tag: $this")
return this
}
</code></pre>
<p>My aim was to write a "normal" function (1st) and an extension function (2nd) and the extension function should call the normal function.</p>
<p>The problem in my code is: the extension function calls itself instead of the normal function. I do not understand this, because I did not specify an instance receiver in the extension function.</p>
<p>How to fix this?</p>
| [
{
"answer_id": 74460075,
"author": "Gustavo",
"author_id": 1401164,
"author_profile": "https://Stackoverflow.com/users/1401164",
"pm_score": 4,
"selected": true,
"text": "fun <T> T.debug (tag: String = \"value\"): T {\n debug (message = \"$tag: $this\")\n return this\n}\n"
},
{
"answer_id": 74460748,
"author": "Agent_L",
"author_id": 1059969,
"author_profile": "https://Stackoverflow.com/users/1059969",
"pm_score": 0,
"selected": false,
"text": "this"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/402322/"
] |
74,459,977 | <p>I have this line</p>
<pre><code>a[link], a[link] a [link] text text text a [link] text a[link] text
</code></pre>
<p>So I want to find the first links before the text and do one operation with them and highlight them in a special style (in this example, there may be three of them more or less) and find other links that go after the text and highlight them differently in styles.</p>
<p>I was able to find only the first three links, but I don't know how well I did it</p>
<pre><code><?php
$re = '/^(a\[(\w+[\s+]?)+\],?\s?)+/iu';
$str = 'a[link], a[link] a[link] text text text a[link] text a[link] text';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
var_dump($matches);
?>
</code></pre>
<hr />
<p>I will try now to give an illustrative example of what is needed:
There is such a text</p>
<blockquote>
<p>a[link1], a[link2] a[link3] text text text a[link4] text a[link5] text</p>
</blockquote>
<p>In this text there are links designated <code>a[...]</code>. In the future, I need to replace these links and bring it to this form:</p>
<blockquote>
<p><a href="link1" class="style1">link1</a><a href="link2" class="style1">link2</a><a href="link3" class="style1">link3</a> text text text <a href="link4" class="style2">link4</a> text <a href="link5" class="style2">link5</a> text</p>
</blockquote>
<p>The first three links have a class assigned with the value <code>style1</code>. The links that come after the text already have a class value assigned to <code>style2</code>.</p>
<p>At the very beginning, there can be three links before the text, four or even one, as well as after the text there can be any number of links in any order.</p>
| [
{
"answer_id": 74460530,
"author": "user3783243",
"author_id": 3783243,
"author_profile": "https://Stackoverflow.com/users/3783243",
"pm_score": 1,
"selected": false,
"text": "preg_match_all"
},
{
"answer_id": 74463603,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 1,
"selected": false,
"text": "\\G"
},
{
"answer_id": 74471420,
"author": "mickmackusa",
"author_id": 2943403,
"author_profile": "https://Stackoverflow.com/users/2943403",
"pm_score": 0,
"selected": false,
"text": "preg_replace_callback()"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74459977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519495/"
] |
74,460,012 | <p>while I am running the script in j meter some http requests show 409 error.</p>
<p>I've recorded a website while executing the script in view results tree it shows 409 conflict error in some http requests.</p>
| [
{
"answer_id": 74460530,
"author": "user3783243",
"author_id": 3783243,
"author_profile": "https://Stackoverflow.com/users/3783243",
"pm_score": 1,
"selected": false,
"text": "preg_match_all"
},
{
"answer_id": 74463603,
"author": "The fourth bird",
"author_id": 5424988,
"author_profile": "https://Stackoverflow.com/users/5424988",
"pm_score": 1,
"selected": false,
"text": "\\G"
},
{
"answer_id": 74471420,
"author": "mickmackusa",
"author_id": 2943403,
"author_profile": "https://Stackoverflow.com/users/2943403",
"pm_score": 0,
"selected": false,
"text": "preg_replace_callback()"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519440/"
] |
74,460,032 | <p>I have a batch of images thus the shape <code>[None, 256, 256, 3]</code> (the batch is set to none for practical purposes on use).</p>
<p>I am trying to implement a layer that calculates the average of each of the of images or frames in the batch to result the shape <code>[None, 1]</code> or <code>[None, 1, 1, 1]</code>. I have checked to use <a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/Average" rel="nofollow noreferrer"><code>tf.keras.layers.Average</code></a>, but apparently it calculates across the batch, returning a tensor of the same shape.</p>
<p>In hindsight I tried implementing the following custom layer:</p>
<pre class="lang-py prettyprint-override"><code>class ElementMean(tf.keras.layers.Layer):
def __init__(self, **kwargs):
super(ElementMean, self).__init__(**kwargs)
def call(self, inputs):
tensors = []
for ii in range(inputs.shape[0] if inputs.shape[0] is not None else 1):
tensors.append(inputs[ii, ...])
return tf.keras.layers.Average()(tensors)
</code></pre>
<p>but when it is used:</p>
<pre class="lang-py prettyprint-override"><code>import tensorflow as tf
x = tf.keras.Input([256, 256, 3], None)
y = ElementMean()(x)
model = tf.keras.Model(inputs=x, outputs=y)
model.compile()
model.summary()
tf.keras.utils.plot_model(
model,
show_shapes=True,
show_dtype=True,
show_layer_activations=True,
show_layer_names=True
)
</code></pre>
<p>I get the result:</p>
<pre><code>Model: "model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 256, 256, 3)] 0
element_mean (ElementMean) (256, 256, 3) 0
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________
</code></pre>
<p><a href="https://i.stack.imgur.com/y995V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y995V.png" alt="enter image description here" /></a></p>
<p>Which makes it entirely wrong.</p>
<p>I also tried this change on the <code>call</code>:</p>
<pre class="lang-py prettyprint-override"><code> def call(self, inputs):
tensors = []
for ii in range(inputs.shape[0] if inputs.shape[0] is not None else 1):
tensors.append(tf.reduce_mean(inputs[ii, ...]))
return tf.convert_to_tensor(tensors)
</code></pre>
<p>Which in turn results to:</p>
<pre><code>Model: "model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 256, 256, 3)] 0
element_mean (ElementMean) (1,) 0
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________
</code></pre>
<p><a href="https://i.stack.imgur.com/H0fmD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H0fmD.png" alt="enter image description here" /></a></p>
<p>Which is also wrong.</p>
| [
{
"answer_id": 74460214,
"author": "AloneTogether",
"author_id": 9657861,
"author_profile": "https://Stackoverflow.com/users/9657861",
"pm_score": 2,
"selected": true,
"text": "import tensorflow as tf\n\nclass ElementMean(tf.keras.layers.Layer):\n def __init__(self, **kwargs):\n super(ElementMean, self).__init__(**kwargs)\n \n def call(self, inputs):\n return tf.reduce_mean(inputs, axis=(1, 2, 3), keepdims=True)\n\nx = tf.keras.layers.Input([256, 256, 3], None)\nem = ElementMean()\ny = em(x)\nmodel = tf.keras.Model(x, y)\nmodel.summary()\n"
},
{
"answer_id": 74465336,
"author": "Jirayu Kaewprateep",
"author_id": 7848579,
"author_profile": "https://Stackoverflow.com/users/7848579",
"pm_score": -1,
"selected": false,
"text": "import os\nfrom os.path import exists\n\nimport tensorflow as tf\nimport tensorflow_io as tfio\n\nimport matplotlib.pyplot as plt\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Variables\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nPATH = os.path.join('F:\\\\datasets\\\\downloads\\\\Actors\\\\train\\\\Pikaploy', '*.tif')\nfiles = tf.data.Dataset.list_files(PATH)\nlist_file = []\n\nfor file in files.take(1):\n image = tf.io.read_file( file )\n image = tfio.experimental.image.decode_tiff(image, index=0)\n image = tf.image.resize(image, [28,32], method='nearest')\n list_file.append( image )\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Class / Definitions\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \nclass MyDenseLayer(tf.keras.layers.Layer):\n def __init__(self, num_outputs):\n super(MyDenseLayer, self).__init__()\n self.num_outputs = num_outputs\n \n def build(self, input_shape):\n self.kernel = self.add_weight(\"kernel\",\n shape=[int(input_shape[-1]),\n self.num_outputs])\n\n def call(self, inputs):\n \n temp = tf.transpose( tf.constant(tf.cast(list_file, dtype=tf.int64), shape=(28, 32, 4), dtype=tf.int64) )\n temp = tf.transpose( temp ) \n mean = tf.constant( tf.math.segment_mean( temp, tf.ones([28], dtype=tf.int64)).numpy() )\n \n temp = tf.image.rot90(temp)\n mean = tf.constant( tf.math.segment_mean( tf.constant(mean[1::], shape=(32, 4)), tf.ones([32], dtype=tf.int64)).numpy() )\n\n return mean[1::]\n\nlayer = MyDenseLayer(10)\nsample = tf.transpose( tf.constant(tf.cast(list_file, dtype=tf.int64), shape=(28, 32, 4), dtype=tf.int64) )\ndata = layer(sample)\n\nprint( data )\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11505421/"
] |
74,460,051 | <p>I am getting traffic network from a website. I want to getting the json file of a location on google maps because of that i need to take a json website link from traffic network. This traffic network I receive is recorded as a list. This list contains words. And every time I refresh the web page, the places in the list change.</p>
<p>its my code here</p>
<pre><code>import time
import json
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get("websitelinkhere.com")
while True:
ready = input("Ready?")
if ready =="y" or "Y":
html = driver.page_source
time.sleep(2)
#metadata dosyasını indiren yeri buluyor.
timings = driver.execute_script("return window.performance.getEntries();")
print(type(timings))
#print(timings)
for i in range(len(timings)):
print(i,timings[i])
print("-------------")
# close web browser
browser.close()
</code></pre>
<p>There are about 500 data in the list.</p>
<p>Output Example :</p>
<pre><code>140 {'connectEnd': 0, 'connectStart': 0, 'decodedBodySize': 0, 'domainLookupEnd': 0, 'domainLookupStart': 0, 'duration': 98.70000000018626, 'encodedBodySize': 0, 'entryType': 'resource', 'fetchStart': 49603, 'initiatorType': 'script', 'name': 'https://maps.googleapis.com/maps/api/js/GeoPhotoService.GetMetadata?pb=!1m4!1sapiv3!11m2!1m1!1b0!2m2!1str-TR!2sUS!3m3!1m2!1e2!2s6BOFuzJhNCDJbDNl_f4GVA!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3&callback=_callbacks____0lajjuohz', 'nextHopProtocol': '', 'redirectEnd': 0, 'redirectStart': 0, 'renderBlockingStatus': 'non-blocking', 'requestStart': 0, 'responseEnd': 49701.700000000186, 'responseStart': 0, 'secureConnectionStart': 0, 'serverTiming': [], 'startTime': 49603, 'transferSize': 0, 'workerStart': 0}
-------------
</code></pre>
<p>this time I found the data I wanted in row 140 of the list ("https://maps.googleapis.com/maps/api/js/GeoPhotoService.GetMetadata")
but every time I repeat this process, its place in the list changes.</p>
<p>and the only constant part I want in the above example is ("https://maps.googleapis.com/maps/api/js/GeoPhotoService.GetMetadata"). I need to get the rest of this link("https://maps.googleapis.com/maps/api/js/GeoPhotoService.GetMetadata?pb=!1m4!1sapiv3!11m2!1m1!1b0!2m2!1str-TR!2sUS!3m3%20!1m2!1e2!2s6BOFuzJhNCDJbDNl_f4GVA!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1!1!1!!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3&callback=_callbacks____0lajjuohz").</p>
<p>How can I do this debugging and finding what I want?</p>
| [
{
"answer_id": 74460214,
"author": "AloneTogether",
"author_id": 9657861,
"author_profile": "https://Stackoverflow.com/users/9657861",
"pm_score": 2,
"selected": true,
"text": "import tensorflow as tf\n\nclass ElementMean(tf.keras.layers.Layer):\n def __init__(self, **kwargs):\n super(ElementMean, self).__init__(**kwargs)\n \n def call(self, inputs):\n return tf.reduce_mean(inputs, axis=(1, 2, 3), keepdims=True)\n\nx = tf.keras.layers.Input([256, 256, 3], None)\nem = ElementMean()\ny = em(x)\nmodel = tf.keras.Model(x, y)\nmodel.summary()\n"
},
{
"answer_id": 74465336,
"author": "Jirayu Kaewprateep",
"author_id": 7848579,
"author_profile": "https://Stackoverflow.com/users/7848579",
"pm_score": -1,
"selected": false,
"text": "import os\nfrom os.path import exists\n\nimport tensorflow as tf\nimport tensorflow_io as tfio\n\nimport matplotlib.pyplot as plt\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Variables\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nPATH = os.path.join('F:\\\\datasets\\\\downloads\\\\Actors\\\\train\\\\Pikaploy', '*.tif')\nfiles = tf.data.Dataset.list_files(PATH)\nlist_file = []\n\nfor file in files.take(1):\n image = tf.io.read_file( file )\n image = tfio.experimental.image.decode_tiff(image, index=0)\n image = tf.image.resize(image, [28,32], method='nearest')\n list_file.append( image )\n\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n: Class / Definitions\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \nclass MyDenseLayer(tf.keras.layers.Layer):\n def __init__(self, num_outputs):\n super(MyDenseLayer, self).__init__()\n self.num_outputs = num_outputs\n \n def build(self, input_shape):\n self.kernel = self.add_weight(\"kernel\",\n shape=[int(input_shape[-1]),\n self.num_outputs])\n\n def call(self, inputs):\n \n temp = tf.transpose( tf.constant(tf.cast(list_file, dtype=tf.int64), shape=(28, 32, 4), dtype=tf.int64) )\n temp = tf.transpose( temp ) \n mean = tf.constant( tf.math.segment_mean( temp, tf.ones([28], dtype=tf.int64)).numpy() )\n \n temp = tf.image.rot90(temp)\n mean = tf.constant( tf.math.segment_mean( tf.constant(mean[1::], shape=(32, 4)), tf.ones([32], dtype=tf.int64)).numpy() )\n\n return mean[1::]\n\nlayer = MyDenseLayer(10)\nsample = tf.transpose( tf.constant(tf.cast(list_file, dtype=tf.int64), shape=(28, 32, 4), dtype=tf.int64) )\ndata = layer(sample)\n\nprint( data )\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14938794/"
] |
74,460,056 | <p>I am given this as a string:</p>
<pre><code>Orville Wright 21 July 1988 \n
Rogelio Holloway 13 September 1988 \n
Marjorie Figueroa 9 October 1988 \n
</code></pre>
<p>I need to separate the names from the dates and print it like this:</p>
<pre><code>Birthdate:
21 July 1988 \n
13 September 1988 \n
9 October 1988 \n
etc..
</code></pre>
<p>I tried to save the string into a variable and split it into a list</p>
<pre class="lang-py prettyprint-override"><code>content = ""
temp = content.strip()
temp = temp.split()
</code></pre>
| [
{
"answer_id": 74460189,
"author": "3dSpatialUser",
"author_id": 5775358,
"author_profile": "https://Stackoverflow.com/users/5775358",
"pm_score": 1,
"selected": false,
"text": "import re\nstr = 'Orville Wright 21 July 1988 \\n Rogelio Holloway 13 September 1988 \\n Marjorie Figueroa 9 October 1988 \\n'\nBirthdate = re.findall(r'(\\d+ \\w+ \\d+)', str)\n>>> ['21 July 1988', '13 September 1988', '9 October 1988']\n"
},
{
"answer_id": 74460311,
"author": "Aadesh Gurav",
"author_id": 18742430,
"author_profile": "https://Stackoverflow.com/users/18742430",
"pm_score": 0,
"selected": false,
"text": "content = 'Orville Wright 21 July 1988 \\n Rogelio Holloway 13 September 1988 \\n Marjorie Figueroa 9 October 1988 \\n'\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19698970/"
] |
74,460,062 | <p>The following works:</p>
<pre><code>awk '
NR==FNR { sub(/\.(png|txt|jpg|json)$/,""); a[$0]; next }
{ f=$0; sub(/\.(png|txt|jpg|json)$/,"", f) }
!(f in a)
' comp1.txt comp2.txt > result.txt
</code></pre>
<p>and now I want it to take the file endings that shall be ignored in the comparison as a variable, but cannot get it to work. My attempt below just compares without ignoring any file endings. I tried with $ and without, with () and without, escaping the |, but so far without success. What is the correct solution?</p>
<pre><code>fileEndingsToIgnore="png|txt|jpg|json"
awk -v fileEndingsToIgnore="${fileEndingsToIgnore}" '
NR==FNR { sub(/\.(fileEndingsToIgnore)$/,""); a[$0]; next }
{ f=$0; sub(/\.(fileEndingsToIgnore)$/,"", f) }
!(f in a)
' comp1.txt comp2.txt > result.txt
</code></pre>
| [
{
"answer_id": 74461117,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 2,
"selected": false,
"text": "AWK"
},
{
"answer_id": 74465327,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 2,
"selected": true,
"text": "sub()"
},
{
"answer_id": 74465727,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": 0,
"selected": false,
"text": "\"-v FS=...\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19017877/"
] |
74,460,067 | <p>I want to change the behavior of the editor such that when the user presses enter on an empty list bullet, their cursor position is reset to the start of the line (rather than leaving them at the indented amount).</p>
<p>I've tried:</p>
<p><code>aceEdit.moveCursorTo(rowToUpdate, 0)</code></p>
<p><code>aceEdit.getSession().indentRows(rowToUpdate, rowToUpdate, "")</code></p>
<p><code>aceEdit.getSession().replace(range(rowToUpdate, 0, rowToUpdate, 0), "")</code></p>
<p>However, all three of these leave the cursor at the previous indent level. How do I reset the indent level for the line?</p>
<hr />
<p>Update: adding example.</p>
<pre><code>* list
* list
* list
* <- user presses enter here
_
</code></pre>
<p>Cursor is where I placed the underscore above, and can't be reset programmatically to the start of the line using what I listed above. (User can backspace the indents to get back to the start.)</p>
| [
{
"answer_id": 74461117,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 2,
"selected": false,
"text": "AWK"
},
{
"answer_id": 74465327,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 2,
"selected": true,
"text": "sub()"
},
{
"answer_id": 74465727,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": 0,
"selected": false,
"text": "\"-v FS=...\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/717847/"
] |
74,460,090 | <p>My current time format is in "Wednesday, November 16, 2022 4:21:33.082 PM GMT+05:30" format.</p>
<p>How can I convert this to epoch time using python?</p>
<p>Here in this case the epoch time should be "1668595893082"</p>
<p><strong>Note: I always want to get my current time format in the above format and then convert that to epoch.</strong></p>
<p>Please guide me.</p>
<p>I tried using strftime('%s') but could not get the solution. Its throwing invalid format exception.</p>
| [
{
"answer_id": 74461117,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 2,
"selected": false,
"text": "AWK"
},
{
"answer_id": 74465327,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 2,
"selected": true,
"text": "sub()"
},
{
"answer_id": 74465727,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": 0,
"selected": false,
"text": "\"-v FS=...\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15183895/"
] |
74,460,120 | <p>On my host system (Ubuntu, 64Bit) I use <code>gcc/g++</code> compilers to crosscompile my library for my Android app (arm64-v8a). On calling functions from my App I receive messages that libraries like <code>libc.so.6</code> or <code>libstdc++.so.6</code> cannot be found.</p>
<p>Within my <code>/usr</code> directory I have an <code>aarch64-linux-gnu</code> folder containing <code>bin</code>, <code>include</code> and <code>lib</code> folders.</p>
<p><strong>CMakeLists.txt:</strong></p>
<pre><code>cmake_minimum_required(VERSION 3.6.0)
set(CMAKE_TOOLCHAIN_FILE android.toolchain.cmake)
project(testlibrary)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STYANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# find header & source
file(GLOB_RECURSE SOURCE_CPP "src/*.cpp")
file(GLOB_RECURSE HEADER "src/*.h")
add_library(${PROJECT_NAME} SHARED
${SOURCE_CPP}
${HEADER}
)
source_group("Header include" FILES ${HEADER})
source_group("Source src" FILES ${SOURCE_CPP})
</code></pre>
<p><strong>android.toolchain.cmake:</strong></p>
<pre><code>cmake_minimum_required(VERSION 3.6.0)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
set(CMAKE_ANDROID_NDK /home/ubuntu/Android/Sdk/ndk/21.4.7075529)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
</code></pre>
<p>The error messages are the following:</p>
<pre><code>dlopen failed: library "libc.so.6" not found: needed by /my/lib/path/testlib.so in namespace classloader-namespace
</code></pre>
<p>or</p>
<pre><code>dlopen failed: library "libstdc++.so.6" not found: needed by /my/lib/path/testlib.so in namespace classloader-namespace
</code></pre>
<p>Do I have to set a Sysroot or other paths so my libraries are found within my toolchain file and which path(s) do I use?</p>
<p><strong>EDIT1:</strong> Adding the <code>aarch64-linux-gnu</code> folder to my build directory and explicitly including</p>
<pre><code>target_link_libraries($PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/aarch64-linux-gnu/lib/libstdc++.so.6)
# also any other lib, e.g. libstdc++.so, libc.so and libc.so.6 don't work
</code></pre>
<p>still results in the mentioned error message.</p>
<p>I made a minimal example of the error using the <code>.cpp</code> and <code>.hpp</code> files below which results in this case in <code>libc.so.6 not found</code>. Removing the malloc line also removes the error messages. Calling the testFunc also return the correct value to my App which I can display.
<strong>src_file.cpp</strong></p>
<pre><code>#include "header_file.hpp"
#include <stdlib.h> // for malloc
int testFunc_(){
char* buffer;
buffer = (char *) malloc (10);
return 42;
}
</code></pre>
<p><strong>header_file.hpp</strong></p>
<pre><code>extern "C" int testFunc_();
</code></pre>
<p>I also added the following lines to my <code>android.toolchain.cmake</code> file (I copied the folder from /usr/aarch64/linux-gnu/ to my build dir)</p>
<pre><code>set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set(LDFLAGS="-Wl,-rpath,../aarch64-linux-gnu/lib")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LDFLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${LDFLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LDFLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${LDFLAGS}" CACHE INTERNAL "" FORCE)
</code></pre>
<p><strong>EDIT2:</strong>
On running <code>readelf -d 'path/to/lib'</code> I get the following (necessary I suppose) entries</p>
<pre><code>Tag Type Name/Value
0x000...1 (NEEDED) Shared library: [libc.so.6]
0x000..1d (RUNPATH) Library runpath: [/home/username/Desktop/projectfolder/aarch64-linux-gnu/lib]
</code></pre>
<p>Adding the following line to my <code>CMakeLists.txt</code> (after removing the <code>RPATH</code> related stuff from my toolchain file or changing them also to <code>./</code>) should allow me to add the libraries right next to my <code>library.so</code> in the build folder (arm64-v8a).</p>
<pre><code>set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,./")
</code></pre>
<p>There is no <code>RPATH</code> tag. The <code>RUNPATH</code> entry is the location of my <code>.so.6</code> and <code>.so</code> files I copied from the <code>/usr/aarch64-linux-gnu</code> folder. I think my main problem is bundling the necessary libraries correctly within my application as David Grayson implicated.</p>
<p><strong>EDIT3:</strong>
Running <code>file libc.so.6</code> also shows its an ELF 64-bit LSB shared object with ARM aarch64 architecture dynamically linked for GNU/Linux 3.7.0, interpreter /lib/ld-linux-aarch64.so.1, stripped</p>
<p><strong>EDIT4:</strong>
Within my <code>app/build.gradle</code> I have the following lines</p>
<pre><code>if(isNewArchitectureEnabled()) {
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-12",
"APP_STL=c_++shared",
"NDK_TOOLCHAIN_VERSION=gcc", // was clang before
"GENERATED_SRC_DIR=$buildDir/generated/source",
"PROJECT_BUILD_DIR=$buildDir",
"REACT_ANDROID_DIR=${reactNativeRoot}/ReactAndroid",
"REACT_ANDROID_BUILD_DIR=${reactNativeRoot}/ReactAndroid/build",
"NODE_MODULES_DIR=$rootDir/../node_modules"
cflags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
cppFlags "-std=c++17", //maybe 11 here(?) tried out both my App and .so to 11 but also no success
targets "myapp_appmodules"
}
}
}
</code></pre>
<p>and also</p>
<pre><code>packagingOptions {
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libm.so'
pickFirst 'lib/arm64-v8a/libm.so.6'
pickFirst 'lib/arm64-v8a/libstdc++.so'
pickFirst 'lib/arm64-v8a/libstdc++.so.6'
pickFirst 'lib/arm64-v8a/libc.so'
pickFirst 'lib/arm64-v8a/libc.so.6'
}
</code></pre>
<p>Am I probably using a wrong compiler/give the standalone toolchain within my ndk folder a try!</p>
| [
{
"answer_id": 74461117,
"author": "Daweo",
"author_id": 10785975,
"author_profile": "https://Stackoverflow.com/users/10785975",
"pm_score": 2,
"selected": false,
"text": "AWK"
},
{
"answer_id": 74465327,
"author": "markp-fuso",
"author_id": 7366100,
"author_profile": "https://Stackoverflow.com/users/7366100",
"pm_score": 2,
"selected": true,
"text": "sub()"
},
{
"answer_id": 74465727,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": 0,
"selected": false,
"text": "\"-v FS=...\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5773498/"
] |
74,460,130 | <p>I have this string</p>
<pre><code>$s = "red2 blue5 black4 green1 gold3";
</code></pre>
<p>I need to order by the number, but can show the numbers.
Numbers will always appears at the end of the word.
the result should be like:</p>
<pre><code>$s = "green red gold black blue";
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 74460517,
"author": "Foobar",
"author_id": 19625365,
"author_profile": "https://Stackoverflow.com/users/19625365",
"pm_score": 2,
"selected": true,
"text": "$s = \"red2 blue5 black4 green1 gold3\";\n$a=[];\npreg_replace_callback('/[a-z0-9]+/',function($m) use (&$a){\n $a[(int)ltrim($m[0],'a..z')] = rtrim($m[0],'0..9');\n},$s);\nksort($a);\nprint \" Version A: \".implode(' ',$a);\n\n$a=[];\nforeach(explode(' ',$s) as $m){\n $a[(int)ltrim($m,'a..z')] = rtrim($m,'0..9');\n}\nksort($a);\nprint \" Version B: \".implode(' ',$a);\n\npreg_match_all(\"/([a-z0-9]+)/\",$s,$m);\nforeach($m[1] as $i){\n $a[(int)substr($i,-1,1)] = rtrim($i,'0..9');\n}\nksort($a);\nprint \" Version C: \".implode(' ',$a);\n"
},
{
"answer_id": 74460660,
"author": "Oliver Scase",
"author_id": 5248827,
"author_profile": "https://Stackoverflow.com/users/5248827",
"pm_score": 2,
"selected": false,
"text": "preg_match_all"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15435343/"
] |
74,460,135 | <p>is there a way in SAS to order columns (variables) of a data set based on the order of another data set? The names are perfectly equal.</p>
<p>And is there also a way to append them (vertically) based on the same column names?</p>
<p>Thank you in advance</p>
<blockquote>
<pre><code> ID YEAR DAYS WORK DATASET
0001 2020 32 234 1
0002 2019 31 232 1
0003 2015 3 22 1
0004 2003 15 60 1
0005 2021 32 98 1
0006 2000 31 56 1
</code></pre>
</blockquote>
<blockquote>
<pre><code> DATASET DAYS WORK ID YEAR
2 56 23 0001 2010
2 34 123 0002 2011
2 432 3 0003 2013
2 45 543 0004 2022
2 76 765 0005 2000
2 43 8 0006 1999
</code></pre>
</blockquote>
<p>I just need to sort the second data set based on the first and append the second to the first.</p>
<p>Can anyone help me please?</p>
| [
{
"answer_id": 74460517,
"author": "Foobar",
"author_id": 19625365,
"author_profile": "https://Stackoverflow.com/users/19625365",
"pm_score": 2,
"selected": true,
"text": "$s = \"red2 blue5 black4 green1 gold3\";\n$a=[];\npreg_replace_callback('/[a-z0-9]+/',function($m) use (&$a){\n $a[(int)ltrim($m[0],'a..z')] = rtrim($m[0],'0..9');\n},$s);\nksort($a);\nprint \" Version A: \".implode(' ',$a);\n\n$a=[];\nforeach(explode(' ',$s) as $m){\n $a[(int)ltrim($m,'a..z')] = rtrim($m,'0..9');\n}\nksort($a);\nprint \" Version B: \".implode(' ',$a);\n\npreg_match_all(\"/([a-z0-9]+)/\",$s,$m);\nforeach($m[1] as $i){\n $a[(int)substr($i,-1,1)] = rtrim($i,'0..9');\n}\nksort($a);\nprint \" Version C: \".implode(' ',$a);\n"
},
{
"answer_id": 74460660,
"author": "Oliver Scase",
"author_id": 5248827,
"author_profile": "https://Stackoverflow.com/users/5248827",
"pm_score": 2,
"selected": false,
"text": "preg_match_all"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19938845/"
] |
74,460,162 | <p>I'm studying JavaScript combining functions. Supposed I have <code>firstname</code>
and <code>lastName</code> as two arguments of my function. I want the console to display <code>Doe</code> when <code>lastname</code> is <code>undefinded</code> . Here is my code but it printed out undefined. Any idea? Thank you!</p>
<pre><code>let name = 'John'
function greetByDefault(firstname,lastname){
return 'Hi ' + firstname +' '+ lastname + '!';
}
if (lastname === undefined){
return 'Doe';
}
console.log(greetByDefault('Jane', 'Doe'));
console.log(greetByDefault(name));
</code></pre>
<p>I want the console output to be:</p>
<p>Hi Jane Doe!
Hi John Doe!</p>
| [
{
"answer_id": 74460199,
"author": "R4ncid",
"author_id": 14326899,
"author_profile": "https://Stackoverflow.com/users/14326899",
"pm_score": 3,
"selected": false,
"text": "let name = 'John'\n\nfunction greetByDefault(firstname,lastname = 'Doe'){\n return 'Hi ' + firstname +' '+ lastname + '!';\n }\n \n\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\nconsole.log(greetByDefault(name, 'Smith'))"
},
{
"answer_id": 74460209,
"author": "Ankit",
"author_id": 19757319,
"author_profile": "https://Stackoverflow.com/users/19757319",
"pm_score": 3,
"selected": true,
"text": "function"
},
{
"answer_id": 74460258,
"author": "JustCode",
"author_id": 2728320,
"author_profile": "https://Stackoverflow.com/users/2728320",
"pm_score": 0,
"selected": false,
"text": "let name = 'John'\nfunction greetByDefault(firstname,lastname=''){\n if (lastname== ''){\n lastname = 'Doe';\n }\nreturn 'Hi ' + firstname +' '+ lastname + '!';\n\n}\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519432/"
] |
74,460,170 | <p>I have a DataFrame with duplicate row in column A that has difference value in column B</p>
<p>Example for my data:</p>
<pre><code>| Column A | Column B |
| -------- | -------- |
| APPLE | RED |
| APPLE | GREEN |
| GRAPE | BLACK |
| BANANA | RED |
| BANANA | BLUE |
| BANANA | GREEN |
| BANANA | GREEN |
</code></pre>
<p>I want to count distinct in column B and also group and sort by column A</p>
<p>Expected data:</p>
<pre><code>| Column A | Column B |
| -------- | -------- |
| APPLE | 2 |
| GRAPE | 1 |
| BANANA | 3 |
</code></pre>
<p>Any pointers on how to approach this problem? Either PySpark or SQL can be used.</p>
| [
{
"answer_id": 74460199,
"author": "R4ncid",
"author_id": 14326899,
"author_profile": "https://Stackoverflow.com/users/14326899",
"pm_score": 3,
"selected": false,
"text": "let name = 'John'\n\nfunction greetByDefault(firstname,lastname = 'Doe'){\n return 'Hi ' + firstname +' '+ lastname + '!';\n }\n \n\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\nconsole.log(greetByDefault(name, 'Smith'))"
},
{
"answer_id": 74460209,
"author": "Ankit",
"author_id": 19757319,
"author_profile": "https://Stackoverflow.com/users/19757319",
"pm_score": 3,
"selected": true,
"text": "function"
},
{
"answer_id": 74460258,
"author": "JustCode",
"author_id": 2728320,
"author_profile": "https://Stackoverflow.com/users/2728320",
"pm_score": 0,
"selected": false,
"text": "let name = 'John'\nfunction greetByDefault(firstname,lastname=''){\n if (lastname== ''){\n lastname = 'Doe';\n }\nreturn 'Hi ' + firstname +' '+ lastname + '!';\n\n}\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519402/"
] |
74,460,171 | <p>Here's the situation: registration.php with inputs (like firstname, lastname, password) and registrationErrors.php - having self-written error-checks and returning the type of error to the initial registration.php, where it is shown to the user.</p>
<p>In case one of my self-written error occurs, I'd like to save the inputs (registration.php) the user has already done and only clear the input with the error in it.</p>
<p>I have seen a couple of posts having the same problem - but mine's slightly different. Since the data is sent to</p>
<pre><code><form action="registrationErrors.php" method="post" ...>
</code></pre>
<p>, the suggestion</p>
<pre><code>value="<?php echo isset($_POST["firstname"]) ? $_POST["firstname"] : ''; ?>"
</code></pre>
<p>doesn't work, since it would have to be sent to:</p>
<pre><code><form action="registration.php"...>
</code></pre>
<p>Any idea how to keep my structure of the two php-files and still have the already-input data saved?</p>
| [
{
"answer_id": 74460199,
"author": "R4ncid",
"author_id": 14326899,
"author_profile": "https://Stackoverflow.com/users/14326899",
"pm_score": 3,
"selected": false,
"text": "let name = 'John'\n\nfunction greetByDefault(firstname,lastname = 'Doe'){\n return 'Hi ' + firstname +' '+ lastname + '!';\n }\n \n\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\nconsole.log(greetByDefault(name, 'Smith'))"
},
{
"answer_id": 74460209,
"author": "Ankit",
"author_id": 19757319,
"author_profile": "https://Stackoverflow.com/users/19757319",
"pm_score": 3,
"selected": true,
"text": "function"
},
{
"answer_id": 74460258,
"author": "JustCode",
"author_id": 2728320,
"author_profile": "https://Stackoverflow.com/users/2728320",
"pm_score": 0,
"selected": false,
"text": "let name = 'John'\nfunction greetByDefault(firstname,lastname=''){\n if (lastname== ''){\n lastname = 'Doe';\n }\nreturn 'Hi ' + firstname +' '+ lastname + '!';\n\n}\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10858923/"
] |
74,460,177 | <p>There is a table <em>Shops</em> with <em>Shop_number</em> and <em>Shop Address</em> columns.
Also a table called <em>Properties</em> with two columns:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Shop_number</th>
<th>Property_ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>222222</td>
<td>113</td>
</tr>
<tr>
<td>222222</td>
<td>114</td>
</tr>
<tr>
<td>222222</td>
<td>115</td>
</tr>
<tr>
<td>222223</td>
<td>113</td>
</tr>
<tr>
<td>222224</td>
<td>113</td>
</tr>
<tr>
<td>222225</td>
<td>111</td>
</tr>
<tr>
<td>222226</td>
<td>112</td>
</tr>
</tbody>
</table>
</div>
<p>A shop can have more than one property.
How to write a query which would return all shop numbers which does not have Property_ID: 113 at all (excluding 222222, because it indeed has other properties, but also 113).</p>
<pre><code>SELECT p.shop_number FROM Properties p
WHERE p.property_id != 113
</code></pre>
<p>My query returns also store 222222 which has 113 property_id.
I would like to return shop numbers: 222225 and 222226 in this case only.</p>
| [
{
"answer_id": 74460199,
"author": "R4ncid",
"author_id": 14326899,
"author_profile": "https://Stackoverflow.com/users/14326899",
"pm_score": 3,
"selected": false,
"text": "let name = 'John'\n\nfunction greetByDefault(firstname,lastname = 'Doe'){\n return 'Hi ' + firstname +' '+ lastname + '!';\n }\n \n\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\nconsole.log(greetByDefault(name, 'Smith'))"
},
{
"answer_id": 74460209,
"author": "Ankit",
"author_id": 19757319,
"author_profile": "https://Stackoverflow.com/users/19757319",
"pm_score": 3,
"selected": true,
"text": "function"
},
{
"answer_id": 74460258,
"author": "JustCode",
"author_id": 2728320,
"author_profile": "https://Stackoverflow.com/users/2728320",
"pm_score": 0,
"selected": false,
"text": "let name = 'John'\nfunction greetByDefault(firstname,lastname=''){\n if (lastname== ''){\n lastname = 'Doe';\n }\nreturn 'Hi ' + firstname +' '+ lastname + '!';\n\n}\nconsole.log(greetByDefault('Jane', 'Doe'));\nconsole.log(greetByDefault(name));\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14172808/"
] |
74,460,191 | <p>I have a model called <code>Purchase</code>, with two fields, <code>User</code> and <code>amount_spent</code>.</p>
<p>This is <code>models.py</code>:</p>
<pre><code>class Purchase(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
amount_spent = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
</code></pre>
<p>I want to get the last purchases from a list of users.
On <code>views.py</code> I have a list with some <code>User</code>'s objects, and I want to get the last purchase for each user in the list. I can't find a way of doing this in a single query, I checked the <a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#latest" rel="nofollow noreferrer">latest()</a> operator on <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#ref-models-querysets" rel="nofollow noreferrer">QuerySets</a>, but it only returns one object.</p>
<p>This is <code>views.py</code>:</p>
<pre><code>purchases = Purchase.objects.filter(user__in=list_of_users)
# purchases contains all the purchases from users, now I need to get the most recent onces for each user.
</code></pre>
<p>I now I could group the <code>purchases</code> by user and then get the most recent ones, but I was wondering it there is a way of making this as a single query to DB.</p>
| [
{
"answer_id": 74460476,
"author": "Hemal Patel",
"author_id": 16250404,
"author_profile": "https://Stackoverflow.com/users/16250404",
"pm_score": 2,
"selected": false,
"text": "Purchase.objects.filter(user__in=list_of_users).values(\"user_id\", \"amount_spent\").order_by(\"-id\").distinct(\"user_id\")\n"
},
{
"answer_id": 74460492,
"author": "Willem Van Onsem",
"author_id": 67579,
"author_profile": "https://Stackoverflow.com/users/67579",
"pm_score": 2,
"selected": true,
"text": "User"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13071340/"
] |
74,460,207 | <p>After solving the heat equation with analytical procedures, I'm trying to solve it numerically by the explicit Euler method. I'm given the <a href="https://i.stack.imgur.com/lpoXF.png" rel="nofollow noreferrer">following discretization</a>, where T is the temperature. My code is:</p>
<pre><code>#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define N 100
double T[N+1][N];
int main(){
int i,j;
double dt=1./N;
double dz=1./N;
double b=43351./94400;
for (i=0;i<N+2;i++){
T[i][0]=b;
T[i][N-1]=b;
}
for (j=0;j<N+1;j++){
T[0][j+1]=b;
}
for (i=0;i<N+1;i++){
for (j=1;j<N;j++){
T[i+1][j] = (dt/pow(dz, 2))*(T[i][j+1] - 2*T[i][j] + T[i][j-1]) + dt + T[i][j];
}
}
FILE* output;
output = fopen("numerica.txt", "w");
for (i=0;i<N+2;i++){
for (j=0;j<N+1;j++){
fprintf(output, "%lf\t", T[i][j]);
}
fprintf(output,"\n");
}
fclose(output);
return 0;
}
</code></pre>
<p>What I'm trying to do is to create a N+1xN matrix that saves all the values from the function. After compiling it I have an infinite .txt file. Some help?</p>
| [
{
"answer_id": 74460476,
"author": "Hemal Patel",
"author_id": 16250404,
"author_profile": "https://Stackoverflow.com/users/16250404",
"pm_score": 2,
"selected": false,
"text": "Purchase.objects.filter(user__in=list_of_users).values(\"user_id\", \"amount_spent\").order_by(\"-id\").distinct(\"user_id\")\n"
},
{
"answer_id": 74460492,
"author": "Willem Van Onsem",
"author_id": 67579,
"author_profile": "https://Stackoverflow.com/users/67579",
"pm_score": 2,
"selected": true,
"text": "User"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19307750/"
] |
74,460,253 | <p>Here's what I have :
<a href="https://stackblitz.com/edit/duplicates-aas5zs?file=app%2Fapp.component.ts,app%2Fapp.component.html" rel="nofollow noreferrer">https://stackblitz.com/edit/duplicates-aas5zs?file=app%2Fapp.component.ts,app%2Fapp.component.html</a>
I have little problem. It has to find duplicate values and print them below. Any help ?</p>
<p>I am new in arrays so maybe anyone could help ? I tried google...</p>
| [
{
"answer_id": 74460476,
"author": "Hemal Patel",
"author_id": 16250404,
"author_profile": "https://Stackoverflow.com/users/16250404",
"pm_score": 2,
"selected": false,
"text": "Purchase.objects.filter(user__in=list_of_users).values(\"user_id\", \"amount_spent\").order_by(\"-id\").distinct(\"user_id\")\n"
},
{
"answer_id": 74460492,
"author": "Willem Van Onsem",
"author_id": 67579,
"author_profile": "https://Stackoverflow.com/users/67579",
"pm_score": 2,
"selected": true,
"text": "User"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20298778/"
] |
74,460,268 | <p>I am trying to rename columns in a dataframe:</p>
<pre><code>data work.baseline;
set work.ehp30 (keep = Pat_TNO AssNo pain -- family sexual -- infertile);
where AssNo = 1;
run;
</code></pre>
<p>Which returns a dataframe to <code>work.baseline</code> with columns <code>Pat_TNO</code>, <code>AssNo</code>, and 11 columns between <code>pain</code> and <code>infertile</code>. I would like to rename the 11 columns to <code>baseline_pain</code>, <code>baseline_infertile</code>, etc, without affecting <code>Pat_TNO</code> and <code>AssNo</code>. How can I do this?</p>
| [
{
"answer_id": 74460485,
"author": "PeterClemmensen",
"author_id": 4044936,
"author_profile": "https://Stackoverflow.com/users/4044936",
"pm_score": 3,
"selected": true,
"text": "data class;\n set sashelp.class;\nrun;\n\ndata test;\n set sashelp.vcolumn end = z;\n where libname='WORK' and memname='CLASS' and name not in ('Name', 'Sex');\n \n if _n_ = 1 then \n call execute('proc datasets lib=work nolist; modify class;');\n\n call execute(compbl(cat('rename ', name, '= baseline_', name, ';')));\n\n if z then call execute('quit;');\n\nrun;\n\nproc contents data = class;\nrun;\n"
},
{
"answer_id": 74481846,
"author": "Richard",
"author_id": 1249962,
"author_profile": "https://Stackoverflow.com/users/1249962",
"pm_score": 0,
"selected": false,
"text": "data have; \n retain A B C D E F G H I J K L 0;\n stop;\nrun;\n\ndata _null_;\n dsid = open ('work.have(keep=c--g)');\n if dsid;\n\n call execute ('proc datasets nolist lib=work;modify have;rename');\n\n do _n_ = 1 by 1 until (sysmsg()=:'ERROR');\n name = varname(dsid,_n_);\n if not missing(name) then \n call execute (catx('=',name,'baseline_'||name));\n end;\n\n call execute (';quit;');\nrun;\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19414769/"
] |
74,460,282 | <p>I had an issue with body overflow being ignored and playing around I found out it happens because someone did:</p>
<pre><code>html{
overflow-x: hidden;
}
</code></pre>
<p>I would never do this because styling the html element directly seems like a sauvage act to me. But since someone did, I want to understand this situation:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>html{
overflow-x: hidden;
}
body{
overflow: hidden;
}
.fill{
height: 8000px;
border: 1px solid blue;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><html>
<body>
<div class="fill"></div>
</body>
</html></code></pre>
</div>
</div>
</p>
<p>Run it an note that the body overflows normal, hidden is ignored.</p>
<p>Of course, If I remove the overflow property from the html selector, it works as expected.</p>
| [
{
"answer_id": 74460485,
"author": "PeterClemmensen",
"author_id": 4044936,
"author_profile": "https://Stackoverflow.com/users/4044936",
"pm_score": 3,
"selected": true,
"text": "data class;\n set sashelp.class;\nrun;\n\ndata test;\n set sashelp.vcolumn end = z;\n where libname='WORK' and memname='CLASS' and name not in ('Name', 'Sex');\n \n if _n_ = 1 then \n call execute('proc datasets lib=work nolist; modify class;');\n\n call execute(compbl(cat('rename ', name, '= baseline_', name, ';')));\n\n if z then call execute('quit;');\n\nrun;\n\nproc contents data = class;\nrun;\n"
},
{
"answer_id": 74481846,
"author": "Richard",
"author_id": 1249962,
"author_profile": "https://Stackoverflow.com/users/1249962",
"pm_score": 0,
"selected": false,
"text": "data have; \n retain A B C D E F G H I J K L 0;\n stop;\nrun;\n\ndata _null_;\n dsid = open ('work.have(keep=c--g)');\n if dsid;\n\n call execute ('proc datasets nolist lib=work;modify have;rename');\n\n do _n_ = 1 by 1 until (sysmsg()=:'ERROR');\n name = varname(dsid,_n_);\n if not missing(name) then \n call execute (catx('=',name,'baseline_'||name));\n end;\n\n call execute (';quit;');\nrun;\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10716664/"
] |
74,460,294 | <p>I have the following DataFrame, with over 3 million rows:</p>
<pre><code>VALID_FROM VALID_TO VALUE
0 2022-01-01 2022-01-02 5
1 2022-01-01 2022-01-03 2
2 2022-01-02 2022-01-04 7
3 2022-01-03 2022-01-06 3
</code></pre>
<p>I want to create one large date_range with a sum of the values for each timestamp.</p>
<p>For the DataFrame above that would come out to:</p>
<pre><code> dates val
0 2022-01-01 7
1 2022-01-02 14
2 2022-01-03 12
3 2022-01-04 10
4 2022-01-05 3
5 2022-01-06 3
</code></pre>
<p>However, as the DataFrame has a little over 3 Million rows I don't want to iterate over each row and I'm not sure how to do this without iterating. Any suggestions?</p>
<p>Currently my code looks like this:</p>
<pre><code>new_df = pd.DataFrame()
for idx, row in dummy_df.iterrows():
dr = pd.date_range(row["VALID_FROM"], end = row["VALID_TO"], freq = "D")
tmp_df = pd.DataFrame({"dates": dr, "val": row["VALUE"]})
new_df = pd.concat(objs=[new_df, tmp_df], ignore_index=True)
new_df.groupby("dates", as_index=False, group_keys=False).sum()
</code></pre>
<p>The result of the groupby would be my desired output.</p>
| [
{
"answer_id": 74460385,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 3,
"selected": true,
"text": "Index.repeat"
},
{
"answer_id": 74460497,
"author": "sammywemmy",
"author_id": 7175713,
"author_profile": "https://Stackoverflow.com/users/7175713",
"pm_score": 1,
"selected": false,
"text": "# pip install pyjanitor\nimport pandas as pd\nimport janitor\n\n# build the date pandas object:\ndates = df.filter(like='VALID').to_numpy()\ndates = pd.date_range(dates.min(), dates.max(), freq='1D')\ndates = pd.Series(dates, name='dates')\n\n# compute the inequality join between valid_from and valid_to, \n# followed by the aggregation on a groupby:\n(df\n.conditional_join(\n dates, \n ('VALID_FROM', 'dates', '<='),\n ('VALID_TO','dates', '>='), \n # if you have numba installed, \n # it can improve performance\n use_numba=False, \n df_columns='VALUE')\n.groupby('dates')\n.VALUE\n.sum()\n) \ndates\n2022-01-01 7\n2022-01-02 14\n2022-01-03 12\n2022-01-04 10\n2022-01-05 3\n2022-01-06 3\nName: VALUE, dtype: int64\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519589/"
] |
74,460,312 | <p>I'm writing to ask you help me with the following issue.</p>
<p>The output of "timedatectl" on my Debian system is:</p>
<pre><code>Local time: Wed 2022-11-16 13:02:00 CET
Universal time: Wed 2022-11-16 12:02:00 UTC
RTC time: Wed 2022-11-16 12:02:01
Time zone: Europe/Rome (CET, +0100)
System clock synchronized: yes
NTP service: inactive
RTC in local TZ: no
</code></pre>
<p>How can I obtain only the "Europe/Rome" string, or obviously any other, using sed command?</p>
<p>I tried</p>
<p><code>timedatectl | sed -ne 's/^ *Time zone: \([A-z0-9_\/]*\).*$/\1/p'</code></p>
<p>but following message is returned:</p>
<blockquote>
<p>sed: -e expression #1, char 40: Invalid range end</p>
</blockquote>
<p>Thank you so much in advance!</p>
| [
{
"answer_id": 74460385,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 3,
"selected": true,
"text": "Index.repeat"
},
{
"answer_id": 74460497,
"author": "sammywemmy",
"author_id": 7175713,
"author_profile": "https://Stackoverflow.com/users/7175713",
"pm_score": 1,
"selected": false,
"text": "# pip install pyjanitor\nimport pandas as pd\nimport janitor\n\n# build the date pandas object:\ndates = df.filter(like='VALID').to_numpy()\ndates = pd.date_range(dates.min(), dates.max(), freq='1D')\ndates = pd.Series(dates, name='dates')\n\n# compute the inequality join between valid_from and valid_to, \n# followed by the aggregation on a groupby:\n(df\n.conditional_join(\n dates, \n ('VALID_FROM', 'dates', '<='),\n ('VALID_TO','dates', '>='), \n # if you have numba installed, \n # it can improve performance\n use_numba=False, \n df_columns='VALUE')\n.groupby('dates')\n.VALUE\n.sum()\n) \ndates\n2022-01-01 7\n2022-01-02 14\n2022-01-03 12\n2022-01-04 10\n2022-01-05 3\n2022-01-06 3\nName: VALUE, dtype: int64\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19136791/"
] |
74,460,317 | <p>I'm trying to pass a number of options for a bolean function and I wrote it like this:</p>
<pre><code>s = 'https://www.youtube.com/watch?v=nVNG8jjZN7k'
s.startswith('http://') or s.startswith('https://')
</code></pre>
<p>But I was wondering if there's a more efficient way to write it,
something like:</p>
<pre><code>s.startswith('http://' or 'https://')
</code></pre>
| [
{
"answer_id": 74460374,
"author": "chepner",
"author_id": 1126841,
"author_profile": "https://Stackoverflow.com/users/1126841",
"pm_score": 2,
"selected": true,
"text": "str.startswith"
},
{
"answer_id": 74461499,
"author": "Axeltherabbit",
"author_id": 8340761,
"author_profile": "https://Stackoverflow.com/users/8340761",
"pm_score": 0,
"selected": false,
"text": "urllib.parse.urlparse"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18571867/"
] |
74,460,320 | <p>I'm using Hardhat framewrok and doing some testing with an erc20 contract:
I used that tutorial to fork <a href="https://hardhat.org/hardhat-network/docs/guides/forking-other-networks" rel="nofollow noreferrer">https://hardhat.org/hardhat-network/docs/guides/forking-other-networks</a>.
I'm trying to swap two ERC20 tokens in mainnet fork using uniswap
I have created uniswap pair for tokens and I'm trying to add Liquidity.
Here is my code for tests.
I'm sure that I made right contracts for tokens</p>
<pre><code>require("@nomicfoundation/hardhat-chai-matchers")
const { expect } = require("chai")
const { ethers } = require("hardhat")
//https://unpkg.com/@uniswap/v2-core@1.0.0/build/IUniswapV2Pair.json
const uniswapPairAbi = require("../contracts/IUniswapV2Pair.json")
const uniswapFactoryAbi = require("../contracts/UniswapFactoryAbi.json")
const uniswapRouter02Abi = require("../contracts/IUniswapV2Router02.json")
const daiAbi = require("../contracts/DaiAbi.json")
const uniswapFactoryAddress = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
const uniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D "
describe("Swap", function () {
let owner
it("Create Token, Create Pair, Swap", async function () {
[owner, to] = await ethers.getSigners()
const MyToken = await ethers.getContractFactory("MyToken", owner)
const myToken = await MyToken.deploy()
await myToken.deployed()
const YourToken = await ethers.getContractFactory("YourToken", owner)
const yourToken = await YourToken.deploy()
await yourToken.deployed()
const factory = await ethers.getContractAt(uniswapFactoryAbi, uniswapFactoryAddress)
console.log("to ", to.address)
const pair = await factory.createPair(myToken.address, yourToken.address)
await expect(pair)
.to.emit(factory, "PairCreated")
const swapPairMTYTAddress = await factory.getPair(myToken.address, yourToken.address)
const wapPairMTYTContract = await ethers.getContractAt(uniswapPairAbi, swapPairMTYTAddress)
const router02Contract = await ethers.getContractAt(uniswapRouter02Abi, uniswapRouterAddress)
await router02Contract.addLiquidity(myToken.address, yourToken.address,1,1,1,1, owner.address, 12)
});
});
</code></pre>
<p>When I run npx hardhat test. I'm getting such error.</p>
<pre><code>npx hardhat test
Swap
to 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
1) Create Token, Create Pair, Swap
0 passing (6s)
1 failing
1) Swap
Create Token, Create Pair, Swap:
Error: network does not support ENS (operation="getResolver", network="unknown", code=UNSUPPORTED_OPERATION, version=providers/5.7.2)
at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
at EthersProviderWrapper.<anonymous> (node_modules\@ethersproject\providers\src.ts\base-provider.ts:1989:20)
at step (node_modules\@ethersproject\providers\lib\base-provider.js:48:23)
at Object.next (node_modules\@ethersproject\providers\lib\base-provider.js:29:53)
at fulfilled (node_modules\@ethersproject\providers\lib\base-provider.js:20:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
</code></pre>
<p>I'm sure that everything before addLiquidity works correctly</p>
| [
{
"answer_id": 74460374,
"author": "chepner",
"author_id": 1126841,
"author_profile": "https://Stackoverflow.com/users/1126841",
"pm_score": 2,
"selected": true,
"text": "str.startswith"
},
{
"answer_id": 74461499,
"author": "Axeltherabbit",
"author_id": 8340761,
"author_profile": "https://Stackoverflow.com/users/8340761",
"pm_score": 0,
"selected": false,
"text": "urllib.parse.urlparse"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14707606/"
] |
74,460,346 | <p>My current dataframe looks like this</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>A header</th>
<th>Another header</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
<td>i like apple</td>
</tr>
<tr>
<td>Second</td>
<td>alex is friends with jack</td>
</tr>
</tbody>
</table>
</div>
<p>I am expecting</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>A header</th>
<th>Another header</th>
</tr>
</thead>
<tbody>
<tr>
<td>First</td>
<td>[i, like, apple]</td>
</tr>
<tr>
<td>Second</td>
<td>[alex, is, friends, with, jack]</td>
</tr>
</tbody>
</table>
</div>
<p>How can I accomplish this efficiently?</p>
| [
{
"answer_id": 74460357,
"author": "Matt",
"author_id": 5125264,
"author_profile": "https://Stackoverflow.com/users/5125264",
"pm_score": 2,
"selected": false,
"text": "df['Another header'] = df['Another header'].str.split()\n"
},
{
"answer_id": 74460358,
"author": "jezrael",
"author_id": 2901002,
"author_profile": "https://Stackoverflow.com/users/2901002",
"pm_score": 1,
"selected": false,
"text": "Series.str.split"
},
{
"answer_id": 74460410,
"author": "Khaled DELLAL",
"author_id": 15852600,
"author_profile": "https://Stackoverflow.com/users/15852600",
"pm_score": 1,
"selected": false,
"text": "map"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18313588/"
] |
74,460,362 | <p>I have a file with a lot of data, I want to search for specific word and when found it, grep it and two other words after it, then keep searching the file to find this specific word again and do the same as I did previously.</p>
<p>Example:</p>
<pre><code>Test::All 123
Availability: Available
State: Enable
**Test:: Member PUT
Availability: Available
State: Enable****
Test:: Many 345
Availability: Available
State: Enable
</code></pre>
<p>now I want to search Test:: Member and grep it along with the word Availability and word State. and skip Availabilty and State if it came after any other grep criteria other than Test:: Member</p>
<p>Thanks,
Talal</p>
<pre><code>grep -iE '(Test:: Member|availability|State)'
</code></pre>
<p>... but I get Availability and state under the other Test:: ALL and Many.</p>
| [
{
"answer_id": 74460655,
"author": "Apex",
"author_id": 12799032,
"author_profile": "https://Stackoverflow.com/users/12799032",
"pm_score": 0,
"selected": false,
"text": "grep 'Test::Member' -A2\n"
},
{
"answer_id": 74460760,
"author": "Gilles Quenot",
"author_id": 465183,
"author_profile": "https://Stackoverflow.com/users/465183",
"pm_score": 0,
"selected": false,
"text": "$ perl -0ne 'print \"$1\\n\" if /(Test::.*?State: \\w+)/ms' file\nTest::All 123\n\nAvailability: Available\n\nState: Enable\n"
},
{
"answer_id": 74463915,
"author": "Paul Hodges",
"author_id": 8656552,
"author_profile": "https://Stackoverflow.com/users/8656552",
"pm_score": 1,
"selected": false,
"text": "sed"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519762/"
] |
74,460,376 | <p>I'm reading a json and want to get the label field with a specific id. What I currently have is:</p>
<pre><code>with open("local_en.json") as json_file:
parsed_dict = json.load(json_file)
print(parsed_dict) # works
print(parsed_dict["interface"]) # works
print(parsed_dict["interface"]["testkey"])
</code></pre>
<p>My json has data blocks (being "interface" or "settings") and those data blocks contain arrays.</p>
<pre><code>{
"interface":[
{"id": "testkey", "label": "The interface block local worked!"}
{"id": "testkey2", "label": "The interface block local worked, AGAIN!"}
],
"settings":[
],
"popup_success":[
],
"popup_error":[
],
"popup_warning":[
],
"other_strings":[
]
}
</code></pre>
| [
{
"answer_id": 74460655,
"author": "Apex",
"author_id": 12799032,
"author_profile": "https://Stackoverflow.com/users/12799032",
"pm_score": 0,
"selected": false,
"text": "grep 'Test::Member' -A2\n"
},
{
"answer_id": 74460760,
"author": "Gilles Quenot",
"author_id": 465183,
"author_profile": "https://Stackoverflow.com/users/465183",
"pm_score": 0,
"selected": false,
"text": "$ perl -0ne 'print \"$1\\n\" if /(Test::.*?State: \\w+)/ms' file\nTest::All 123\n\nAvailability: Available\n\nState: Enable\n"
},
{
"answer_id": 74463915,
"author": "Paul Hodges",
"author_id": 8656552,
"author_profile": "https://Stackoverflow.com/users/8656552",
"pm_score": 1,
"selected": false,
"text": "sed"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15489558/"
] |
74,460,396 | <p>I try to get the square root of negative number. I got the absolute value of data and, for the positive number, I use the squart root of absolute number directly, otherwive add an negaitve sign to the result. However all numbers I got are negaitve...</p>
<p><a href="https://i.stack.imgur.com/k68sG.png" rel="nofollow noreferrer">My code</a>
<a href="https://i.stack.imgur.com/57od4.png" rel="nofollow noreferrer">Results shown</a></p>
<p>I try to get negaitve and positive results, but I only got negative numbers.<code>your text``your text</code></p>
| [
{
"answer_id": 74460512,
"author": "Shawn Hemelstrand",
"author_id": 16631565,
"author_profile": "https://Stackoverflow.com/users/16631565",
"pm_score": 2,
"selected": false,
"text": "tidyverse"
},
{
"answer_id": 74460527,
"author": "diomedesdata",
"author_id": 10366237,
"author_profile": "https://Stackoverflow.com/users/10366237",
"pm_score": 1,
"selected": false,
"text": "?ifelse"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519773/"
] |
74,460,419 | <p>I want to create a Quartz job which reads .csv files and moves them when file is processed. I tried this:</p>
<pre><code>@Override
public void execute(JobExecutionContext context) {
File directoryPath = new File("C:\\csv\\nov");
// Create a new subfolder called "processed" into source directory
try {
Files.createDirectory(Path.of(directoryPath.getAbsolutePath() + "/processed"));
} catch (IOException e) {
throw new RuntimeException(e);
}
FilenameFilter textFileFilter = (dir, name) -> {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".csv")) {
return true;
} else {
return false;
}
};
// List of all the csv files
File filesList[] = directoryPath.listFiles(textFileFilter);
System.out.println("List of the text files in the specified directory:");
for(File file : filesList) {
try {
List<CsvLine> beans = new CsvToBeanBuilder(new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_16))
.....
.build()
.parse();
for(CsvLine item: beans){
....... sql queries
Optional<ProcessedWords> isFound = processedWordsService.findByKeyword(item.getKeyword());
......................................
}
} catch (Exception e){
e.printStackTrace();
}
// Move here file into new subdirectory when file processing is finished
Path copied = Paths.get(file.getAbsolutePath() + "/processed");
Path originalPath = file.toPath();
try {
Files.move(originalPath, copied, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
</code></pre>
<p>Folder <code>processed</code> is created when the job is started but I get exception:</p>
<pre><code> org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-2.3.2.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ~[quartz-2.3.2.jar:na]
Caused by: java.lang.RuntimeException: java.nio.file.FileSystemException: C:\csv\nov\07_06_26.csv -> C:\csv\nov\07_06_26.csv\processed: The process cannot access the file because it is being used by another process
at com.wordscore.engine.processor.ImportCsvFilePostJob.execute(ImportCsvFilePostJob.java:114) ~[main/:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.2.jar:na]
... 1 common frames omitted
Caused by: java.nio.file.FileSystemException: C:\csv\nov\07_06_26.csv -> C:\csv\nov\
07_06_26.csv\processed: The process cannot access the file because it is being used by another process
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92) ~[na:na]
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) ~[na:na]
</code></pre>
<p>Do you know how I can release the file and move it into a sub directory?</p>
<p><em><strong>EDIT: Update code with try-catch</strong></em></p>
<pre><code>@Override
public void execute(JobExecutionContext context) {
File directoryPath = new File("C:\\csv\\nov");
// Create a new subfolder called "processed" into source directory
try {
Path path = Path.of(directoryPath.getAbsolutePath() + "/processed");
if (!Files.exists(path) || !Files.isDirectory(path)) {
Files.createDirectory(path);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
FilenameFilter textFileFilter = (dir, name) -> {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".csv")) {
return true;
} else {
return false;
}
};
// List of all the csv files
File filesList[] = directoryPath.listFiles(textFileFilter);
System.out.println("List of the text files in the specified directory:");
for(File file : filesList) {
try {
try (var br = new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_16)){
List<CsvLine> beans = new CsvToBeanBuilder(br)
......
.build()
.parse();
for (CsvLine item : beans) {
.....
if (isFound.isPresent()) {
.........
}}
} catch (Exception e){
e.printStackTrace();
}
// Move here file into new subdirectory when file processing is finished
Path copied = Paths.get(file.getAbsolutePath() + "/processed");
Path originalPath = file.toPath();
try {
Files.move(originalPath, copied, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
</code></pre>
| [
{
"answer_id": 74460552,
"author": "rzwitserloot",
"author_id": 768644,
"author_profile": "https://Stackoverflow.com/users/768644",
"pm_score": 2,
"selected": false,
"text": "new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_16)\n"
},
{
"answer_id": 74509720,
"author": "jccampanero",
"author_id": 13942448,
"author_profile": "https://Stackoverflow.com/users/13942448",
"pm_score": 3,
"selected": true,
"text": "java.nio.file.FileSystemException: C:\\csv\\nov\\07_06_26.csv -> C:\\csv\\nov\\07_06_26.csv\\processed: The process cannot access the file because it is being used by another process\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103606/"
] |
74,460,424 | <p>I have this schematic:</p>
<pre><code><div class="fila">
<div class="dos_tercios">
<article>
......
</article>
</div>
<div class="un_tercios">
<article>
......
</article>
</div>
</div>
<div class="fila">
<div class="un_tercios">
<article>
......
</article>
</div>
<div class="dos_tercios">
<article>
......
</article>
</div>
</div>
</code></pre>
<p><a href="https://i.stack.imgur.com/dUUPi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dUUPi.png" alt="enter image description here" /></a></p>
<p>And i want to paint with Orange the first article of each .fila class, or saying in other words, the left side articles (this is because after this i have to add diferent margint to right-hand articles and left-hand articles) (Watch image)</p>
<p>I have been trying this:</p>
<pre><code>article:nth-child(odd){
background-color: rgb(255, 177, 113);
}
</code></pre>
| [
{
"answer_id": 74460552,
"author": "rzwitserloot",
"author_id": 768644,
"author_profile": "https://Stackoverflow.com/users/768644",
"pm_score": 2,
"selected": false,
"text": "new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_16)\n"
},
{
"answer_id": 74509720,
"author": "jccampanero",
"author_id": 13942448,
"author_profile": "https://Stackoverflow.com/users/13942448",
"pm_score": 3,
"selected": true,
"text": "java.nio.file.FileSystemException: C:\\csv\\nov\\07_06_26.csv -> C:\\csv\\nov\\07_06_26.csv\\processed: The process cannot access the file because it is being used by another process\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519810/"
] |
74,460,431 | <p>I have a method to set a BigDecimal number that is given as String:</p>
<pre class="lang-java prettyprint-override"><code>private Client mapClient(Client client){
ClientRequest clientRequest = new ClientRequest();
// Code
clientRequest.setCashAmount(castStringToBigDecimal(client.getCashAmount()));
// More Code
}
</code></pre>
<p>My <code>castStringToBigDecimal</code> method is the follosing:</p>
<pre><code>public BigDecimal castStringToBigDecimal(String value){
BigDecimal response = null;
if(value != null && !value.equals("")){
value = value.replaceAll("[.]", ",");
response = new BigDecimal(value);
}
return response;
}
</code></pre>
<p>An example of the input value is "1554.21"</p>
<p>I need that the bigDecimal separator to be a comma, not a dot. But this is giving me an exception.</p>
<p><strong>EDIT</strong></p>
<p>The value is the following:
<a href="https://i.stack.imgur.com/gRIns.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gRIns.png" alt="enter image description here" /></a></p>
<p>And the exception is:</p>
<pre><code>java.lang.NumberFormatException: Character , is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
</code></pre>
| [
{
"answer_id": 74460707,
"author": "rzwitserloot",
"author_id": 768644,
"author_profile": "https://Stackoverflow.com/users/768644",
"pm_score": 2,
"selected": true,
"text": ".replaceAll"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16862042/"
] |
74,460,454 | <p>I'm trying to run some asynchronous functions in her asynchronous function, the problem is, how did I understand that functions don't run like that, then how do I do it? I don't want to make the maze_move function asynchronous.</p>
<pre><code>async def no_stop():
#some logic
await asyncio.sleep(4)
async def stop(stop_time):
await asyncio.sleep(stop_time)
#some logic
def maze_move():
no_stop()
stop(1.5)
async def main(websocket):
global data_from_client, data_from_server, power_l, power_r
get_params()
get_data_from_server()
get_data_from_client()
while True:
msg = await websocket.recv()
allow_data(msg)
cheker(data_from_client)
data_from_server['IsBrake'] = data_from_client['IsBrake']
data_from_server['powerL'] = power_l
data_from_server['powerR'] = power_r
await websocket.send(json.dumps(data_from_server))
print(data_from_client['IsBrake'])
start_server = websockets.serve(main, 'localhost', 8080)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
</code></pre>
| [
{
"answer_id": 74460618,
"author": "Booboo",
"author_id": 2823719,
"author_profile": "https://Stackoverflow.com/users/2823719",
"pm_score": 1,
"selected": false,
"text": "def maze_move():\n loop = asyncio.get_event_loop()\n loop.run_until_complete(no_stop())\n loop.run_until_complete(stop(1.5))\n"
},
{
"answer_id": 74469416,
"author": "Paul Cornelius",
"author_id": 2442613,
"author_profile": "https://Stackoverflow.com/users/2442613",
"pm_score": 0,
"selected": false,
"text": "def maze_move():\n async def amaze_move():\n await no_stop()\n await stop(1.5)\n return asyncio.create_task(amaze_move())\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16853299/"
] |
74,460,509 | <p>I implemented a new feature to our CRM and everything works as it should on Safari (macOS), but it throws <code>Uncaught TypeError: X is not a function</code> on every other browser we tested it on (Chrome, Firefox, Edge). This is the piece of code that is the culprit:</p>
<pre class="lang-js prettyprint-override"><code>if (window.changeLabel === 'undefined') {
function changeLabel() {
// Do something
}
changeLabel();
} else {
changeLabel();
}
</code></pre>
<p>Why is it working only on Safari? Why is <code>changeLabel</code> not a function even after I check for its existence? Is this not the way to check if a function exists or not?</p>
| [
{
"answer_id": 74460563,
"author": "Cerbrus",
"author_id": 1835379,
"author_profile": "https://Stackoverflow.com/users/1835379",
"pm_score": 2,
"selected": false,
"text": "if (window.changeLabel === 'undefined') {\n window.changeLabel = function() {\n // Do something\n }\n}\n\nchangeLabel();"
},
{
"answer_id": 74460717,
"author": "KooiInc",
"author_id": 58186,
"author_profile": "https://Stackoverflow.com/users/58186",
"pm_score": 0,
"selected": false,
"text": "window.changeLabel"
},
{
"answer_id": 74460804,
"author": "Ben Aston",
"author_id": 38522,
"author_profile": "https://Stackoverflow.com/users/38522",
"pm_score": 3,
"selected": true,
"text": "window.changeLabel === 'undefined'"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13604898/"
] |
74,460,510 | <p>Hello stackoverflow community! I've been creating my own fullstack application for a while now, on the NEXTjs framework. This is going pretty well!! Unfortunately, I got stuck on a JSON import object for a treeview component. The treeview component must be populated using a specific nested structure, along with which treeview item should be selected on an initial render.</p>
<p>I managed to get the correct JSON object from the database, using a sql recursive tree function.</p>
<pre><code>const jsonObject =
{
"id": "bfa3fdf8-4672-404e-baf5-0f9098a5705b",
"label": "main category 1",
"children": [
{
"id": "12e544bc-91b1-4e5d-bdbc-2163a5618305",
"label": "sub category 1.1",
"children": []
},
{
"id": "3f5e5cc7-f8b2-4d75-89e1-841c66d863e6",
"label": "sub category 1.2",
"children": [
{
"id": "903a727f-d94d-44ff-b2f6-a985fd167343",
"label": "sub category 1.2.1",
"children": []
},
{
"id": "fb344480-8588-4ce3-9662-f8e89069e4b4",
"label": "sub category 1.2.2",
"children": []
}
]
}
]
}
</code></pre>
<p>The problem is that this object, with categories needs to be updated with a 'checked: "true"' or 'checked: "false"' key value pair based on the existence in the referenceSelectedCategories array. And I don't know how to do this; maintaining the structure and object as needed.</p>
<pre><code>const desiredOutputJsonObject =
{
"id": "bfa3fdf8-4672-404e-baf5-0f9098a5705b",
"label": "main category 1",
** "checked": "false",**
"children": [
{
"id": "12e544bc-91b1-4e5d-bdbc-2163a5618305",
"label": "sub category 1.1",
** "checked": "true",**
"children": []
},
{
"id": "3f5e5cc7-f8b2-4d75-89e1-841c66d863e6",
"label": "sub category 1.2",
** "checked": "false",**
"children": [
{
"id": "903a727f-d94d-44ff-b2f6-a985fd167343",
"label": "sub category 1.2.1",
** "checked": "false",**
"children": []
},
{
"id": "fb344480-8588-4ce3-9662-f8e89069e4b4",
"label": "sub category 1.2.2",
** "checked": "true",**
"children": []
}
]
}
]
}
</code></pre>
<pre><code>const referenceSelectedCategories =
[
{
"categoryId": "12e544bc-91b1-4e5d-bdbc-2163a5618305",
"productId": "efed1c38-391b-4b5a-a9f1-91f3faec5f44",
"Id": "f82b0f63-3f39-486c-9157-5c7683b8e3b2"
},
{
"categoryId": "fb344480-8588-4ce3-9662-f8e89069e4b4",
"productId": "efed1c38-391b-4b5a-a9f1-91f3faec5f44",
"Id": "b2e8681b-eec4-404d-8f87-c6314db42e30"
}
]
</code></pre>
<p>I've read several stackoverflow questions, also searched for examples, but can't get it to work. Could someone help me out here?</p>
<p>Some extra information:</p>
<ul>
<li>Code language I'm using is REACT on NEXTjs framework;</li>
<li>Treeview component could have a dept of max 5 levels;</li>
<li>The structure of the JSON object doesn't change, it's exactly as presented above.</li>
<li>The "id" in the JSON object corresponds to the "categoryId" in the array.</li>
<li>Do you need more information? :) Just ask, I'll provide you with the extra details!</li>
</ul>
<p>Kind Regards,</p>
<p>Chris</p>
| [
{
"answer_id": 74460563,
"author": "Cerbrus",
"author_id": 1835379,
"author_profile": "https://Stackoverflow.com/users/1835379",
"pm_score": 2,
"selected": false,
"text": "if (window.changeLabel === 'undefined') {\n window.changeLabel = function() {\n // Do something\n }\n}\n\nchangeLabel();"
},
{
"answer_id": 74460717,
"author": "KooiInc",
"author_id": 58186,
"author_profile": "https://Stackoverflow.com/users/58186",
"pm_score": 0,
"selected": false,
"text": "window.changeLabel"
},
{
"answer_id": 74460804,
"author": "Ben Aston",
"author_id": 38522,
"author_profile": "https://Stackoverflow.com/users/38522",
"pm_score": 3,
"selected": true,
"text": "window.changeLabel === 'undefined'"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11874568/"
] |
74,460,520 | <p>I have a XML with many records as nodes in it. I need to save each record in xml format a SQL server table in column of XML datatype .</p>
<p>I can perform this task in SSIS using "XML Task Editor" to count all the nodes and using "For Loop Container" and read Node value using "XML Task Editor" and save it database.</p>
<p>Another option is using Script task, reading the XML file and save each node in a loop.</p>
<p>Please suggest a better approach which is efficient with big files.</p>
<p>Below is sample of Input XML File. I need to save each (3 records in below example) "RECORD" full node in XML form in SQL Server database table which has a column with xml datatype.</p>
<p><a href="https://i.stack.imgur.com/mRK2f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mRK2f.png" alt="enter image description here" /></a></p>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7368821/"
] |
74,460,531 | <p>I have to select only the characters contained from <code>></code> to the last dot (not the first dot).</p>
<p>I tried this pattern</p>
<pre><code>^>[a-zA-Z]+$
</code></pre>
<p>but something doesn't work. Can I get some help? Thank you.</p>
<pre><code>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
</code></pre>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20483494/"
] |
74,460,575 | <p>I was learning python as a beginner through YouTube. In the video I was following the output was shown in terminal, but not in my case. It doesn't even accept taking in data for the variable. What am I doing wrong?</p>
<p>the code was simply :</p>
<pre><code>a = input("Enter name")
print(a)
</code></pre>
<p>but the output would only show the text, but wont let me type the input</p>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19583963/"
] |
74,460,587 | <p>I have collection in my Child view.</p>
<pre><code> <CollectionView SelectionMode="Single" SelectedItem="{Binding Source={Reference sideview}, Path=myViewModel.SelectedItem.FileName}"
ItemsSource="{Binding Source={x:Reference sideview}, Path=myViewModel.Items }" >
<CollectionView.ItemTemplate>
<DataTemplate >
<Grid>
<Label Text="{Binding FileName}" VerticalOptions="Center"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</code></pre>
<p>I want to delete selected item
My parent view where I have delete button</p>
<pre><code> <Button x:Name="BTN_REMOVE_FILE" Text="Remove" Command="{Binding DeleteCommand}" CommandParameter="{Binding SelectedItem}" >
</code></pre>
<p>I have created delete command in my viewmodel</p>
<pre><code> [RelayCommand]
public void Delete(Data s)
{
if (Items.Contains(s)) {
Items.Remove(s);
}
}
</code></pre>
<p>and from view I have pass the command parameter from view like this</p>
<p>I also have created selectedItem in my view Model</p>
<pre><code> public Data selectedItem;
public Data SelectedItem
{
get
{
return selectedItem;
}
set
{
if(selectedItem != value)
{
selectedItem = value;
}
}
}`public MyViewModel()
{
Items = new ObservableCollection<Data>();
selectedItem = new Data();
}
`
</code></pre>
<p>It is showing me exception like <strong>Parameter "parameter" (object) cannot be of type DemoApp.MVVM.ViewModel.MyViewModel, as the command type requires an argument of type DemoApp.MVVM.Model.Data. (Parameter 'parameter')</strong></p>
<p>Tried to add this in my viewModel <code> public Data Name { get; set; }</code></p>
<p>view <code> <Button x:Name="BTN_REMOVE_FILE" Text="Remove" Command="{Binding DeleteCommand}" CommandParameter="{Binding Name}" ></code></p>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19836184/"
] |
74,460,589 | <p>I have two tables</p>
<p><strong>trade_table</strong> as</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>start_date</th>
<th>transacted_date</th>
</tr>
</thead>
<tbody>
<tr>
<td>A1</td>
<td>2022-02-14</td>
<td>2022-02-17</td>
</tr>
<tr>
<td>A1</td>
<td>2022-02-17</td>
<td>2022-02-25</td>
</tr>
<tr>
<td>A5</td>
<td>2022-02-15</td>
<td>2022-02-19</td>
</tr>
<tr>
<td>A6</td>
<td>2022-02-21</td>
<td>NULL</td>
</tr>
</tbody>
</table>
</div>
<p>and
<strong>trading_days</strong> as</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>trade_date</th>
</tr>
</thead>
<tbody>
<tr>
<td>2022-02-14</td>
</tr>
<tr>
<td>2022-02-15</td>
</tr>
<tr>
<td>2022-02-16</td>
</tr>
<tr>
<td>2022-02-17</td>
</tr>
<tr>
<td>2022-02-19</td>
</tr>
<tr>
<td>2022-02-21</td>
</tr>
<tr>
<td>2022-02-23</td>
</tr>
<tr>
<td>2022-02-25</td>
</tr>
</tbody>
</table>
</div>
<p>How to get actual date difference from trade_date table based on values from transacted_date and start_date from trade_table.</p>
<p>Expected Output table</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>id</th>
<th>start_date</th>
<th>transacted_date</th>
<th>transact_in_days</th>
</tr>
</thead>
<tbody>
<tr>
<td>A1</td>
<td>2022-02-14</td>
<td>2022-02-17</td>
<td>3</td>
</tr>
<tr>
<td>A1</td>
<td>2022-02-17</td>
<td>2022-02-25</td>
<td>4</td>
</tr>
<tr>
<td>A2</td>
<td>2022-02-15</td>
<td>2022-02-19</td>
<td>3</td>
</tr>
<tr>
<td>A6</td>
<td>2022-02-21</td>
<td>NULL</td>
<td>null</td>
</tr>
</tbody>
</table>
</div> | [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460589",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6463651/"
] |
74,460,596 | <p>Im doing a notes APP in react that every note contains title and text and another functions that is not relevant for the question
The problem I am facing is that every time I change the title input its changes the title of all my previous results . My text input its working as expected . Can anyone give me a help in what I doing wrong or what can I do for solving it ?</p>
<pre><code>function NotesList({ noteText, noteIndex, deleteHandler, noteTitle }) {
<span className='elementmodal'><h4 className='titlemodal'>{noteTitle}</h4>
{noteText}<button onClick={toggleModal} className='closebutton'>x</button></span>
</div>
</div>
</div>
)}<span style={{ fontSize: '14px', margin: '4px' }}>{noteText}</span><button onClick={() => deleteHandler(noteText, noteIndex)} className='closebutton'>x</button>
</code></pre>
<pre><code>function AddNotesComponent() {
const [result, setResult] = useState([]);
const [note, setNote] = useState({title:'',text:''});
const addNote = () => {
const newItem = note.text + '(' + settingDate() + ')';
note.text && setResult([...result, newItem ])
}
</code></pre>
<pre><code> const HandleTitle = (e) => setNote({...note,title: e.target.value});
const HandleText = (e) => setNote({...note,text: e.target.value});
</code></pre>
<pre><code>
return (
<>
<div className='notebox'>
<input style={{ width: '425px', marginTop: '5px' }} onChange={HandleTitle} placeholder='title'></input>
<textarea style={{ width: '425px', marginTop: '15px' }} onChange={HandleText} placeholder='your note...'></textarea>
<button className='addbutton' onClick={addNote}>Add</button>
</div>
<div className='resultdiv'>
{result.map((item, index) => (<NotesList
key={index}
noteIndex={index}
noteTitle={note.title}
noteText={item}
deleteHandler={closeNoteHandle}
/>
))}
</div>
</>
)
</code></pre>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20003970/"
] |
74,460,633 | <p>While trying to import a OWL-file into Stardog using Stardog Studio, I receive the following error message</p>
<blockquote>
<p>The parser has encountered more than "100,000" entity expansions in
this document; this is the limit imposed by the application.</p>
</blockquote>
<p>According to the Stardog forum and a number of online articles, this behaviour should be solved by setting jdk.xml.entityExpansionLimit property. I tried to set it to 2000000 using the following steps.</p>
<ol>
<li>Setting the STARDOG_SERVER_JAVA_ARGS='-DentityExpansionLimit=2000000 -Xmx8g' environment entry in docker-compose.</li>
<li>Setting the STARDOG_SERVER_JAVA_ARGS='-Djdk.xml.entityExpansionLimit=2000000 -Xmx8g' environment entry in docker-compose.</li>
<li>Creating a jaxp.properties file under the JDK lib folder containing either a jdk.xml.entityExpansionLimit=2000000 entry or a entityExpansionLimit=2000000 entry.</li>
</ol>
<p>None of them seems to solve the problem... The same behaviour is posted in other SO-posts of 7 and 8 years ago, but they don't elaborate on the solution of the problem...</p>
<p>Did anyone found a solution for this behaviour? Any suggestions is highly appreciated!</p>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5585819/"
] |
74,460,676 | <p>I have JSON as follows</p>
<pre><code>dict =[
{'name':'Test01-Serial01'
},
{'name':'Tests04-Serial04'
}
]
</code></pre>
<p>First I wanted to separate the name with <code>-</code> and then with the index 0 that is <code>Test01</code>
I wanted to delete the dictionary which don't follow the rule in <code>name</code>
Rule: 4 Digit <strong>Word</strong> 2 Digit <strong>Number</strong></p>
<p>Here Tests04 doesn't follow 4 Digit <strong>Word</strong> 2 Digit <strong>Number</strong> rule and it contains 5 digit word.</p>
| [
{
"answer_id": 74461938,
"author": "Gerballi",
"author_id": 20358885,
"author_profile": "https://Stackoverflow.com/users/20358885",
"pm_score": 0,
"selected": false,
"text": "select node_table.xml_node_column.query('.') node \nfrom xmldocument\ncross apply xmldocument.nodes('/root/RECORD') node_table(xml_node_column)\n"
},
{
"answer_id": 74462122,
"author": "Yitzhak Khabinsky",
"author_id": 1932311,
"author_profile": "https://Stackoverflow.com/users/1932311",
"pm_score": 2,
"selected": true,
"text": "DECLARE @staging_tbl TABLE (id INT IDENTITY PRIMARY KEY, xmldata XML);\nINSERT INTO @staging_tbl (xmldata) VALUES\n(N'<root>\n <RECORD UI=\"F298AF1F\"></RECORD>\n <RECORD UI=\"4C6AAA65\"></RECORD>\n</root>');\n\n-- INSERT INTO destination_table (ID, xml_record)\nSELECT id \n , c.query('.') AS xml_record\nFROM @staging_tbl\nCROSS APPLY xmldata.nodes('/root/RECORD') AS t(c);\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14831308/"
] |
74,460,679 | <p>I I have a pandas dataframe, (df) that has three columns (user, values, and group name), the values column with multiple comma-separated values in each row.</p>
<pre><code>df = pd.DataFrame({'user': ['user_1', 'user_2', 'user_3', 'user_4', 'user_5', 'user_6'],
'values': [[1, 0, 2, 0], [1, 8, 0, 2],[6, 2, 0, 0], [5, 0, 2, 2], [3, 8, 0, 0],[6, 0, 0, 2]],
'group': ['B', 'A', 'C', 'A', 'B', 'B']})
df
</code></pre>
<p>output:</p>
<pre><code>user values group
0 user_1 [1, 0, 2, 0] B
1 user_2 [1, 8, 0, 2] A
2 user_3 [6, 2, 0, 0] C
3 user_4 [5, 0, 2, 2] A
4 user_5 [3, 8, 0, 0] B
5 user_6 [6, 0, 0, 2] B
</code></pre>
<p>Then I calculate the average of each cluster, which is called a centroid in the dataframe (df1).</p>
<pre><code>df1 = (df.groupby('group', as_index=False)['values']
.agg(lambda x: np.vstack(x).mean(0).round(2))
)
df1
</code></pre>
<p>Output:</p>
<pre><code>group values
0 A [3.0, 4.0, 1.0, 2.0]
1 B [3.33, 2.67, 0.67, 0.67]
2 C [6.0, 2.0, 0.0, 0.0]
</code></pre>
<p>Finally, I compute the average distance from each user to all clusters in the following code using euclidean distance.</p>
<pre><code>for value in df['values']:
distance_values = []
for centroid in df1['values']:
distance_values.append(distance.euclidean(value, centroid))
print(distance_values)
</code></pre>
<p>Output:</p>
<pre><code>[5.0, 3.8439042651970405, 5.744562646538029]
[4.58257569495584, 6.004631545732011, 8.06225774829855]
[4.242640687119285, 2.9112883745860696, 0.0]
[4.58257569495584, 3.668187563361503, 3.605551275463989]
[4.58257569495584, 5.4236150305861495, 6.708203932499369]
[5.0990195135927845, 4.059014658756482, 2.8284271247461903]
</code></pre>
<p>So, for each user, I calculate the average distance to the centroid of each cluster.
For example:<br />
For user_1 the average distance to clusters A=5.0, B=3.8439042651970405, and C=5.744562646538029.</p>
<p>How do I return the maximum value of each row in distance values with its cluster name in the dataframe?</p>
<p>For example, the expected output is:</p>
<pre><code>user max_value group
0 user_1 5.744562646538029 C
1 user_2 8.06225774829855 C
2 user_3 4.242640687119285 A
3 user_4 4.58257569495584 A
4 user_5 6.708203932499369 C
5 user_6 5.0990195135927845 A
</code></pre>
| [
{
"answer_id": 74460882,
"author": "Nuri Taş",
"author_id": 19255749,
"author_profile": "https://Stackoverflow.com/users/19255749",
"pm_score": 2,
"selected": false,
"text": "apply"
},
{
"answer_id": 74461354,
"author": "Renato Aranha",
"author_id": 11097866,
"author_profile": "https://Stackoverflow.com/users/11097866",
"pm_score": 2,
"selected": true,
"text": "max_dist_idx = []\ndistant_cluster = []\n\nfor value in df['values']:\n distance_values = []\n\n for centroid in df1['values']:\n distance_values.append(distance.euclidean(value, centroid))\n\n max_dist_idx.append(max(distance_values))\n distant_cluster.append(distance_values.index(max(distance_values)))\n\ncluster_map = {0: 'A', 1: 'B', 2: 'C'}\nmax_group = [cluster_map[i] for i in distant_cluster]\n"
},
{
"answer_id": 74461470,
"author": "Tranbi",
"author_id": 13525512,
"author_profile": "https://Stackoverflow.com/users/13525512",
"pm_score": 2,
"selected": false,
"text": "def calc_max_dist(value):\n dist_series = df1['values'].apply(lambda x: distance.euclidean(value, x))\n return dist_series.max(), df1[dist_series == dist_series.max()]['group'].values\n\ndf[['max_value', 'closest_group(s)']] = pd.DataFrame(df['values'].apply(calc_max_dist).tolist())\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17289012/"
] |
74,460,682 | <p>I have the following xml.</p>
<pre><code><root>
<!-- E, F, G, H-->
<node1>E</node1>
<!-- J, K, M ,L-->
<node2>J</node2>
</root>
</code></pre>
<p>Node 1 can have E,F,G,H values and node 2 can have J,K,M,L.</p>
<p>I would like to choose a single node base on its value.</p>
<p>I need to choose the values based on the following order E,J,F,K,G,M,H,L.</p>
<p>I know that I can do this with a choose.</p>
<pre><code> <xsl:template match="/">
<!-- sequence, E,J,F,K,G,M,H,L-->
<xsl:variable name="myNode" select="root/node1 || root/node2"/>
<output>
<xsl:choose>
<xsl:when test="contains($myNode, 'E')">
<xsl:text>E</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'J')">
<xsl:text>J</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'F')">
<xsl:text>F</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'K')">
<xsl:text>K</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'G')">
<xsl:text>G</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'M')">
<xsl:text>M</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'H')">
<xsl:text>H</xsl:text>
</xsl:when>
<xsl:when test="contains($myNode, 'L')">
<xsl:text>L</xsl:text>
</xsl:when>
</xsl:choose>
</output>
</xsl:template>
</code></pre>
<p>but is there an easier (less code) way to achieve this? Maybe a regular expression? I would like to have this in xslt 2.0.</p>
<p>Thanks</p>
| [
{
"answer_id": 74461062,
"author": "MJG",
"author_id": 20283130,
"author_profile": "https://Stackoverflow.com/users/20283130",
"pm_score": -1,
"selected": false,
"text": "takeOrderedString(node1, node2)"
},
{
"answer_id": 74461262,
"author": "michael.hor257k",
"author_id": 3016153,
"author_profile": "https://Stackoverflow.com/users/3016153",
"pm_score": 1,
"selected": true,
"text": "<root>\n <node1>F</node1>\n <node2>J</node2>\n</root>\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1466580/"
] |
74,460,736 | <p>How to create a list with a given length? I want my list to take only 3 variables, it should not expand.</p>
<p>How to do that in Dart / Flutter?</p>
| [
{
"answer_id": 74461062,
"author": "MJG",
"author_id": 20283130,
"author_profile": "https://Stackoverflow.com/users/20283130",
"pm_score": -1,
"selected": false,
"text": "takeOrderedString(node1, node2)"
},
{
"answer_id": 74461262,
"author": "michael.hor257k",
"author_id": 3016153,
"author_profile": "https://Stackoverflow.com/users/3016153",
"pm_score": 1,
"selected": true,
"text": "<root>\n <node1>F</node1>\n <node2>J</node2>\n</root>\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16968554/"
] |
74,460,752 | <pre><code>import java.io. {FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream}
object SymbolSerializeDemo {
def main(args: Array[String]): Unit = {
val fileName = "file.ser"
val symbolCheck: Symbol = Symbol("someSymbol")
//serializeToFile(symbolCheck, fileName)
deserializeFromFile(fileName)
}
private def serializeToFile(input: Symbol, fileName: String): Unit = {
try {
val file: FileOutputStream = new FileOutputStream(fileName)
val out: ObjectOutputStream = new ObjectOutputStream(file)
out.writeObject(input)
}
}
private def deserializeFromFile(fileName: String): Unit = {
try {
val file: FileInputStream = new FileInputStream(fileName)
val input: ObjectInputStream = new ObjectInputStream(file)
val output = input.readObject.asInstanceOf[Symbol]
println("Symbol after deseralization " + output.name)
}
}
}
</code></pre>
<p>I am trying to deserialized scala symbol, serialized in scala 2.11 but I am getting error as <code>java.io.InvalidClassException: scala.Symbol; local class incompatible: stream classdesc serialVersionUID = 2966401305346518859, local class serialVersionUID = 6865603221856321286</code> Can we write custom serialization for this or any other option?</p>
<p>I tried adding serialVersionUID for class as well as for Symbol</p>
| [
{
"answer_id": 74471051,
"author": "Dmytro Mitin",
"author_id": 5249621,
"author_profile": "https://Stackoverflow.com/users/5249621",
"pm_score": 0,
"selected": false,
"text": "// Scala 2.12\nimport sys.process._\n\nSymbol(\"scala-2.11.12/bin/scala path_to_deserializer/Deserializer.scala path_to_file/file.ser\".!!)\n// 'someSymbol\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3771712/"
] |
74,460,766 | <p>I have two datatypes called <code>DragonVector</code> and <code>UnbiasedDragon</code> and I am using visitor pattern for dynamic type inference.</p>
<p>I want to extend a <code>DragonVector</code> only by a <code>DragonVector</code> and similarly for <code>UnbiasedDragon</code>.</p>
<p>I have the following code for extending the vectors:</p>
<pre class="lang-cpp prettyprint-override"><code>template<class T>
class ExtendVisitor{
public:
void operator()(DragonVector<T>& vec1, const DragonVector<T>& vec2){
vec1.extend(vec2);
}
void operator()(UnbiasedDragon<T>& vec1, const UnbiasedDragon<T>& vec2){
vec1.extend(vec2);
}
void operator()(auto& vec1, const auto& vec2){
std::cout<<"wrong class"<<std::endl;
}
};
</code></pre>
<p>I get <code>error: 'auto' not allowed in function prototype</code>. I am using C++17.</p>
<p>Since, there are only two classes, I can exhaustively write the operator overloads in the visitor for all the combinations. But this seems infeasible as the number of classes grow large.</p>
<p>I tried using templating as a work around as</p>
<pre class="lang-cpp prettyprint-override"><code>template<class T>
class ExtendVisitor{
public:
void operator()(DragonVector<T>& vec1, const DragonVector<T>& vec2){
vec1.extend(vec2);
}
void operator()(UnbiasedDragon<T>& vec1, const UnbiasedDragon<T>& vec2){
vec1.extend(vec2);
}
template<class TT>
void operator()(TT& vec1, const TT& vec2){
std::cout<<"wrong class"<<std::endl;
}
};
</code></pre>
<p>but this also did not work out.</p>
<p>Is there a way to use visitor pattern without having to write all the possible combinations?</p>
| [
{
"answer_id": 74471051,
"author": "Dmytro Mitin",
"author_id": 5249621,
"author_profile": "https://Stackoverflow.com/users/5249621",
"pm_score": 0,
"selected": false,
"text": "// Scala 2.12\nimport sys.process._\n\nSymbol(\"scala-2.11.12/bin/scala path_to_deserializer/Deserializer.scala path_to_file/file.ser\".!!)\n// 'someSymbol\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9222360/"
] |
74,460,778 | <p><strong>How to solve (TypeError: must be a real number, not a tuple) error</strong></p>
<pre><code>class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
desc_str = "%s is a %s %s worth $%.2f." % (self.name, self.color, self.kind, self.value)
return desc_str
car1 = Vehicle()
car1.name = "Fer"
car1.color = "Red"
car1.kind = "Convertible"
car1.value = 60,000.00
car2 = Vehicle()
car2.name = "Jump"
car2.color = "Blue"
car2.kind = "Van"
car2.value = 10,000.00
print(car1.description())
print(car2.description())
</code></pre>
<p>After running this code, I'm getting the error. I wanted the info of the cars.</p>
| [
{
"answer_id": 74471051,
"author": "Dmytro Mitin",
"author_id": 5249621,
"author_profile": "https://Stackoverflow.com/users/5249621",
"pm_score": 0,
"selected": false,
"text": "// Scala 2.12\nimport sys.process._\n\nSymbol(\"scala-2.11.12/bin/scala path_to_deserializer/Deserializer.scala path_to_file/file.ser\".!!)\n// 'someSymbol\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15412130/"
] |
74,460,789 | <p>I have 5 tables in a row, all have 100% height which works correctly in the browser, the elements are stretched to fill all the available space but they wont stretch in print view.</p>
<p><a href="https://i.stack.imgur.com/9d1cg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9d1cg.png" alt="The table's print behavior" /></a></p>
<p>I want the table to extend beyond the page break and have the header. I tried using a single table with one column (since the cards have different heights and cannot be placed in a single <code>5 x n</code> table) where the only column contained the cards but it either wouldn't break inside or had very weird behavior, just changing a completely unrelated margin or padding broke the whole layout.</p>
<p>Edit: This is part of a large document so I can't include the whole implementation but here's a minimal example:</p>
<pre class="lang-html prettyprint-override"><code><style>
.flex {
display: flex;
gap: 1rem;
/* add some top margin to simulate content before the table */
margin-top: 50vh;
}
table {
flex: 1;
}
.card {
padding: 0.5rem;
border-radius: 0.25rem;
background: lightblue;
}
</style>
<div class="flex">
<table>
<thead>
<tr>
<td>
<div style="background: red">COLUMN1</div>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="card">CARD</div>
</td>
</tr>
<!-- more cards -->
</tbody>
</table>
<!-- more tables [1..5] -->
</div>
</code></pre>
<p>In print the tables are only as high as the total height of the cards inside but in the browser the stable is stretched.</p>
<p><a href="https://i.stack.imgur.com/ST4vc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ST4vc.png" alt="The HTML result of the example code" /></a></p>
<p><a href="https://i.stack.imgur.com/pZtX1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pZtX1.png" alt="The print result of the example code" /></a></p>
| [
{
"answer_id": 74539782,
"author": "Anton",
"author_id": 15545116,
"author_profile": "https://Stackoverflow.com/users/15545116",
"pm_score": 2,
"selected": false,
"text": "td {\n height: 2rem;\n line-height: 1;\n}\n"
},
{
"answer_id": 74544340,
"author": "Yann",
"author_id": 3675596,
"author_profile": "https://Stackoverflow.com/users/3675596",
"pm_score": 0,
"selected": false,
"text": "style=\"page-break-before: always;\""
},
{
"answer_id": 74597373,
"author": "Sahil bakoru",
"author_id": 17539341,
"author_profile": "https://Stackoverflow.com/users/17539341",
"pm_score": 0,
"selected": false,
"text": "body, html{height:100%}\ndiv{height:100%}\ntable{background:green; width:450px} \n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10581265/"
] |
74,460,828 | <p>I am trying to pass a text string to a PHP Variable using AJAX, but I keep getting this error when POST fires:</p>
<blockquote>
<p>Warning: Undefined array key "mydata"</p>
</blockquote>
<p>the alert fires and displays the value correctly, but then the PHP page displays the mentioned error. What's wrong here?</p>
<p>AJAX:</p>
<pre><code>$("#display_tasks").click(function() {
var name = $(this).text();
var namecut = name.substr(0,name.indexOf(' |'));
$.ajax({
type: 'POST',
url: 'opentask.php',
data: {mydata : namecut},
success:function(data) {
alert(data);
}
});
});
</code></pre>
<p>PHP:</p>
<pre><code>$taskname = $_POST['mydata'];
echo $taskname;
</code></pre>
| [
{
"answer_id": 74461176,
"author": "José Carlos PHP",
"author_id": 2826112,
"author_profile": "https://Stackoverflow.com/users/2826112",
"pm_score": 0,
"selected": false,
"text": "$_POST['mydata']"
},
{
"answer_id": 74461239,
"author": "Addis",
"author_id": 19985560,
"author_profile": "https://Stackoverflow.com/users/19985560",
"pm_score": -1,
"selected": false,
"text": "var name = $(this).text();"
},
{
"answer_id": 74461623,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": true,
"text": "href=\"opentask.php\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12124168/"
] |
74,460,862 | <p>I have a simple dash app containing a data table.Two user inputs make it possible to add a row or a column. Juste like when I add a row I get default values (here 0 hours) for every column, I would also like to have default values for all rows when adding a new column. Here is the code:</p>
<pre><code>import pathlib as pl
import dash
from dash import dash_table
from dash.dash_table.Format import Format, Scheme, Sign, Symbol
from dash import dcc
from dash import html
import plotly.graph_objs as go
import pandas as pd
from dash.dependencies import Input, Output, State
table_header_style = {
"backgroundColor": "rgb(2,21,70)",
"color": "white",
"textAlign": "center",
}
app = dash.Dash(__name__)
app.title = "Trial"
server = app.server
APP_PATH = str(pl.Path(__file__).parent.resolve())
list_rows = ['a', 'b', 'c', 'd']
tasks = ['task' + str(i) for i in range(5)]
data = {task:[0 for i in range(len(list_rows))] for task in tasks}
app.layout = html.Div(
className="",
children=[
html.Div(
# className="container",
children=[
html.Div(
# className="row",
style={},
children=[
html.Div(
# className="four columns pkcalc-settings",
children=[
html.P(["Study Design"]),
html.Div(
[
html.Label(
[
dcc.Input(
id="new-row",
placeholder="Row to be added...",
type="text",
debounce=True,
maxLength=20,
style={
'width':'66%',
'margin-left': '5px'
}
),
html.Button(
'Add',
id='add-row-button',
n_clicks=0,
style={
'font-size': '10px',
'width': '140px',
'display': 'inline-block',
'margin-bottom': '5px',
'margin-right': '5px',
'margin-left': '5px',
'height':'38px',
'verticalAlign': 'top'
}
),
]
),
html.Label(
[
dcc.Input(
id="new-task",
placeholder="Task to be added...",
type="text",
debounce=True,
maxLength=50,
style={'width':'66%'}
),
html.Button(
'Add',
id='add-task-button',
n_clicks=0,
style={
'font-size': '10px',
'width': '140px',
'display': 'inline-block',
'margin-bottom': '5px',
'margin-right': '5px',
'margin-left': '5px',
'height':'38px',
'verticalAlign': 'top'
}
),
]
),
]
),
],
),
html.Div(
# className="eight columns pkcalc-data-table",
children=[
dash_table.DataTable(
id='table',
columns=(
[{
'id': 'name',
'name': 'Name',
'type': 'text',
'deletable': True,
'renamable': True,
}] +
[{
'id': task,
'name': task,
'type': 'numeric',
'deletable': True,
'renamable': True,
'format': Format(
precision=0,
scheme=Scheme.fixed,
symbol=Symbol.yes,
symbol_suffix='h'
),
} for task in tasks]
),
data=[dict(name=i, **{task: 0 for task in tasks}) for i in list_rows],
editable=True,
style_header=table_header_style,
active_cell={"row": 0, "column": 0},
selected_cells=[{"row": 0, "column": 0}],
),
],
),
],
),
],
),
],
)
# Callback to add column
@app.callback(
Output(component_id='table', component_property='columns'),
Input(component_id='add-task-button', component_property='n_clicks'),
State(component_id='new-task', component_property='value'),
State(component_id='table', component_property='columns'),)
def update_columns(n_clicks, new_task, existing_tasks):
if n_clicks > 0:
existing_tasks.append({
'id': new_task, 'name': new_task,
'renamable': True, 'deletable': True
})
return existing_tasks
# Callback to add row
@app.callback(
Output(component_id='table', component_property='data'),
Input(component_id='add-row-button', component_property='n_clicks'),
State(component_id='new-row', component_property='value'),
State(component_id='table', component_property='columns'),
State(component_id='table', component_property='data'))
def update_rows(n_clicks, new_row, columns, rows):
if n_clicks > 0:
rows.append(
{
'name': new_row,
**{column['id']: 0 for column in columns[1:]}
}
)
return rows
if __name__ == "__main__":
app.run_server(debug=True)
</code></pre>
<p>Any help would be greatly appreciated!</p>
| [
{
"answer_id": 74461176,
"author": "José Carlos PHP",
"author_id": 2826112,
"author_profile": "https://Stackoverflow.com/users/2826112",
"pm_score": 0,
"selected": false,
"text": "$_POST['mydata']"
},
{
"answer_id": 74461239,
"author": "Addis",
"author_id": 19985560,
"author_profile": "https://Stackoverflow.com/users/19985560",
"pm_score": -1,
"selected": false,
"text": "var name = $(this).text();"
},
{
"answer_id": 74461623,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": true,
"text": "href=\"opentask.php\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10811647/"
] |
74,460,884 | <p>I have this function right here:</p>
<pre class="lang-js prettyprint-override"><code>const uploadedFiles: string[] = [];
await Promise.all(
selectedImageUrls.map(async (selectedUrl) => {
const fileName = selectedUrl.startsWith("data:image/png")
? `${id}-${Date.now()}.png`
: `${id}-${getFileNameFromUrl(selectedUrl)}`;
const fileData = await fetch(selectedUrl).then((x) => x.arrayBuffer());
const newUrl = await uploadInvoiceFile(userId, fileName, fileData);
uploadedFiles.push(newUrl);
})
);
</code></pre>
<p>So basically I have an array called <code>selectedImageUrls</code> and I map through this array to execute some async functions so I put this map inside of a <code>Promise.all()</code> and on the last line, you can see that in every map, I push the result of the async functions into an array called <code>uploadedFiles</code>, however, this result is not in the same order as the original array (<code>selectedImageUrls</code>). How can I modify this code so that the order will be exactly the same?</p>
| [
{
"answer_id": 74461176,
"author": "José Carlos PHP",
"author_id": 2826112,
"author_profile": "https://Stackoverflow.com/users/2826112",
"pm_score": 0,
"selected": false,
"text": "$_POST['mydata']"
},
{
"answer_id": 74461239,
"author": "Addis",
"author_id": 19985560,
"author_profile": "https://Stackoverflow.com/users/19985560",
"pm_score": -1,
"selected": false,
"text": "var name = $(this).text();"
},
{
"answer_id": 74461623,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": true,
"text": "href=\"opentask.php\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16170683/"
] |
74,460,908 | <p>i am trying to render the sub array as an individual item, but it keeps rendering all the sub array items inside one list
`</p>
<pre><code> const items = [
{ id: 1, header: "Global", lst: "All Fruits" },
{
id: 2,
header: "By Taste",
lst: ["sweet", "sour", "bitter"],
},
{
id: 3,
header: "By Region",
lst: [
"Tropical",
"dry",
"Continental",
"Temperate",
"Polar",
],
},
];
</code></pre>
<p>`</p>
<p>`</p>
<pre><code><ul className="dd-list">
{items.map((item) => (
<div key={item.id}>
<i>{item.header}</i>
<li className="dd-list-item">
<button
type="button"
onClick={(e) => {
setSelected(item.lst);
setOpen(false);
}}
>
{item.lst}
</button>
</li>
</div>
))}
</ul>
</code></pre>
<p>`
<a href="https://i.stack.imgur.com/6CSyN.png" rel="nofollow noreferrer">this is the result</a></p>
<p>thanks in advance</p>
<p>expected result</p>
<p><strong>By Taste</strong>
-sweet
-sour
-bitter
<strong>By Region</strong>
-Tropical
-dry
-Continental
-Temperate
-Polar</p>
| [
{
"answer_id": 74461176,
"author": "José Carlos PHP",
"author_id": 2826112,
"author_profile": "https://Stackoverflow.com/users/2826112",
"pm_score": 0,
"selected": false,
"text": "$_POST['mydata']"
},
{
"answer_id": 74461239,
"author": "Addis",
"author_id": 19985560,
"author_profile": "https://Stackoverflow.com/users/19985560",
"pm_score": -1,
"selected": false,
"text": "var name = $(this).text();"
},
{
"answer_id": 74461623,
"author": "Ken Lee",
"author_id": 11854986,
"author_profile": "https://Stackoverflow.com/users/11854986",
"pm_score": 2,
"selected": true,
"text": "href=\"opentask.php\""
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13429853/"
] |
74,460,910 | <p>I have ran into a problem. I have a website and some buttons to the right.
using JS, I want to change the style of the button we click on.
When you land on the page, the home button will have a <code>background-color: green</code>. But when you click another button, the home button <code>background-color</code> becomes black/gray. But the <code>background-color</code> of button you clicked will stay black/gray and no error will appear in the console. But when you click any other button after clicking the first time, the <code>background-color</code> will stay gray/black but an error appears in the console :
<code>app.js:12 Uncaught TypeError: Cannot read properties of undefined (reading 'className') at HTMLDivElement.<anonymous> (app.js:12:53)</code></p>
<p>The code :</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const sections = document.querySelectorAll('.section');
const sectBtns = document.querySelectorAll('.controls');
const sectBtn = document.querySelectorAll('.control');
const allSection = document.querySelector('.main-content');
function PageTransitions() {
// Button click active class
for (let i = 0; i < sectBtn.length; i++) {
sectBtn[i].addEventListener('click', function() {
let currentBtn = document.querySelectorAll('.active-btn');
currentBtn[0].className = currentBtn[0].className.replace('active-btn', '');
this.className += 'active-btn';
})
}
}
PageTransitions();</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
margin: 0;
padding: 0;
box-sizing: border-box;
list-style: none;
}
:root {
--color-primary: #191d2b;
--color-secondary: #27AE60;
--color-white: #FFFFFF;
--color-black: #000;
--color-grey0: #f8f8f8;
--color-grey-1: #dbe1e8;
--color-grey-2: #b2becd;
--color-grey-3: #6c7983;
--color-grey-4: #454e56;
--color-grey-5: #2a2e35;
--color-grey-6: #12181b;
--br-sm-2: 14px;
--box-shadow-1: 0 3px 15px rgba(0, 0, 0, .3);
}
body {
background-color: var(--color-primary);
font-family: "Poppins", sans-serif;
font-size: 1.1rem;
color: var(--color-white);
transition: all 0.4s ease-in-out;
}
a {
display: inline-block;
color: inherit;
font-family: inherit;
text-decoration: none;
}
header {
height: 100vh;
color: var(--color-white);
overflow: hidden;
}
section {
min-height: 100vh;
width: 100%;
position: absolute;
top: 0;
left: 0;
padding: 3rem 18rem;
}
.section {
transform: translateY(-100%) scale(0);
transition: all 0.4s ease-in-out;
background-color: var(--color-primary);
}
.sec1 {
display: none;
transform: translateY(0) scale(1);
}
.sec2 {
display: none;
transform: translateY(0) scale(1);
}
.sec3 {
display: none;
transform: translateY(0) scale(1);
}
.sec4 {
display: none;
transform: translateY(0) scale(1);
}
.sec5 {
display: none;
transform: translateY(0) scale(1);
}
.controls {
position: fixed;
z-index: 10;
top: 50%;
right: 3%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transform: translateY(-50%);
}
.controls .active-btn {
background-color: var(--color-secondary) !important;
transition: all 0.4s ease-in-out;
}
.controls .active-btn i {
color: var(--color-white) !important;
}
.controls .control {
padding: 1rem;
cursor: pointer;
background-color: var(--color-grey-4);
width: 55px;
height: 55px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0.7rem 0;
box-shadow: var(--box-shadow-1);
}
.controls .control i {
font-size: 1.2rem;
color: var(--color-grey-2);
pointer-events: none;
}/*# sourceMappingURL=style.css.map */</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portfolio</title>
<link rel="stylesheet" href="file://C:\Users\emile\Desktop\Portfolio Website\styles\style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap" rel="stylesheet">
</head>
<body class="main-content">
<header class="section sec1 header active"></header>
<main>
<section class="section sec2 about"></section>
<section class="section sec3 portfolio"></section>
<section class="section sec4 blogs"></section>
<section class="section sec5 contact"></section>
</main>
<div class="controls">
<div class="control control-1 active-btn" data-id="header">
<i class="fas fa-home"></i>
</div>
<div class="control control-2" data-id="about">
<i class="fas fa-user"></i>
</div>
<div class="control control-3" data-id="portfolio">
<i class="fas fa-briefcase"></i>
</div>
<div class="control control-4" data-id="blogs">
<i class="fas fa-newspaper"></i>
</div>
<div class="control control-5" data-id="contact">
<i class="fas fa-envelope-open"></i>
</div>
</div>
<script src="C:\Users\emile\Desktop\Portfolio Website\app.js"></script>
</body>
</html></code></pre>
</div>
</div>
</p>
<p>Due to this the background color does not change.
Any idea on how to fix that ?
Thanks !</p>
| [
{
"answer_id": 74461520,
"author": "Ankit",
"author_id": 19757319,
"author_profile": "https://Stackoverflow.com/users/19757319",
"pm_score": 2,
"selected": false,
"text": "this.className += 'active-btn';"
},
{
"answer_id": 74461543,
"author": "Ritik Mewada",
"author_id": 20520148,
"author_profile": "https://Stackoverflow.com/users/20520148",
"pm_score": 2,
"selected": true,
"text": "this.className += 'active-btn';"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19603779/"
] |
74,460,931 | <p>I have JSON stored in a table. The JSON is nested and has the following structure</p>
<pre class="lang-json prettyprint-override"><code>[
{
"name": "abc",
"ques": [
{
"qId": 100
},
{
"qId": 200
}
]
},{
"name": "xyz",
"ques": [
{
"qId": 100
},
{
"qId": 300
}
]
}
]
</code></pre>
<pre class="lang-sql prettyprint-override"><code>Update TABLE_NAME
set COLUMN_NAME = jsonb_set(COLUMN_NAME, '{ques,qId}', '101')
WHERE COLUMN_NAME->>'qId'=100
</code></pre>
<p>I am trying to update qId value from JSON. If qId is 100, I want to update it to 101.</p>
| [
{
"answer_id": 74461228,
"author": "bitifet",
"author_id": 4243912,
"author_profile": "https://Stackoverflow.com/users/4243912",
"pm_score": 1,
"selected": false,
"text": "jsonb_set(\n jsonb_set(\n COLUMN_NAME\n , '{0,ques,qId}'\n , '101'\n )\n , '{1,ques,qId}'\n , '101'\n)\n"
},
{
"answer_id": 74465680,
"author": "Edouard",
"author_id": 8060017,
"author_profile": "https://Stackoverflow.com/users/8060017",
"pm_score": 3,
"selected": true,
"text": "json"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9945033/"
] |
74,460,956 | <p>I cannot find how to swap two words in a string using <strong>Python</strong>, without using any external/imported functions.</p>
<hr />
<p>What I have is a string that I get from a text document.
For example the string is:</p>
<p><em><strong>line</strong> = "Welcome to your personal dashboard, where you can find an introduction to how GitHub works, tools to help you build software, and help merging your first lines of code."</em></p>
<p>I find the longest and the shortest words, from a list, that containts all the words from the <strong>line</strong> string, without punctions.</p>
<p><strong>longest</strong> = "introduction"</p>
<p><strong>shortest</strong> = "to"</p>
<p>What I need to do is to swap tthe longest and the shortest words together, while keeping the punctions intact.</p>
<p>Tried using replace, but can only get it to replace 1 word with the other, but the second word remains the same.</p>
<p>Don't know what exactly to use or how to.</p>
<p>The string needs to end up from:
"Welcome to your personal dashboard, where you can find an <strong>introduction</strong> to how GitHub works, tools <strong>to</strong> help you build software, and help merging your first lines of code."</p>
<p>When swapped:
"Welcome to your personal dashboard, where you can find an <strong>to</strong> to how GitHub works, tools <strong>introduction</strong> help you build software, and help merging your first lines of code."</p>
<hr />
<p>Tried replacing it with:
newline = newline.replace(shortest, longest)</p>
<p>But it will only replace 1 word as mentioned before.</p>
| [
{
"answer_id": 74461025,
"author": "Ridhwan Saal",
"author_id": 19698570,
"author_profile": "https://Stackoverflow.com/users/19698570",
"pm_score": 0,
"selected": false,
"text": "{word1}"
},
{
"answer_id": 74461315,
"author": "StonedTensor",
"author_id": 6023918,
"author_profile": "https://Stackoverflow.com/users/6023918",
"pm_score": 2,
"selected": true,
"text": "import string #to check for punctuation\n\nline = \"Welcome to your personal dashboard, where you can find an introduction to how GitHub works, tools to help you build software, and help merging your first lines of code.\"\n\nwords = line.split() #this includes punctuation attached to words as well\n\nshortest = min(words, key = len) #find the length of the words that is the smallest\n\nlongest = max(words, key = len) #opposite of above\n\nfor i, word in enumerate(words): #iterate with both the index and word in the list\n if word == shortest:\n if word[-1] in string.punctuation: #check if the punctuation is at the end since we want to keep it\n words[i] = longest + word[-1] #this keeps the punctuation\n else:\n words[i] = longest\n elif word == longest:\n if word[-1] in string.punctuation:\n words[i] = shortest + word[-1]\n else:\n words[i] = shortest\n\nline = ' '.join(words) #make a new line that has the replaced words\n\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520080/"
] |
74,460,972 | <p>my problem is when I send an object of Order to my function, it comes Null without updating my values, how can I edit them?</p>
<p>I try to update my Object. I expecting get in my function Object of Order with the value and not null</p>
<p>here is my function that needs to get the Object.</p>
<pre><code> [RelayCommand]
async Task Continue(Order order)
{
//Order order = new Order()
//{
// DateStart = dateStart,
// DateEnd = dateEnd,
// DogName = dogName
//};
await Shell.Current.GoToAsync(nameof(ShowOrderPage), true, new Dictionary<string, object>
{
{"Order", order}
});
}
</code></pre>
<p>using Pension.ViewsModels;</p>
<pre><code>namespace Pension.View;
public partial class MainPage : ContentPage
{
public MainPage(MainViewModel vm)
{
InitializeComponent();
BindingContext = vm;//here the error
}
}
</code></pre>
<p>my XAML:</p>
<pre><code><?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:Pension.Models"
xmlns:viewmodel="clr-namespace:Pension.ViewsModels"
x:DataType="viewmodel:MainViewModel"
x:Class="Pension.Views.MainPage"
BackgroundColor="#F2F2F2">
<VerticalStackLayout Margin="0,20,0,0" Spacing="10" FlowDirection="RightToLeft">
<Label Text="הזמנת פנסיון לכלב" FontSize="40" HorizontalOptions="Center" Margin="5"/>
<Label Text="לפני שנתחיל נשמח לדעת מה התאריך בו תרצו להתארח אצלנו" HorizontalOptions="Center" FontSize="20" FontFamily="op-light"/>
<Grid Padding="20" Background="#FFFFFF" Margin="54">
<Grid.Shadow>
<Shadow Brush="#000"
Offset="5,0"
Opacity="0.26"/>
</Grid.Shadow>
<VerticalStackLayout Spacing="10" x:DataType="model:Order">
<Label Text="בחירת תאריך" FontSize="30" HorizontalOptions="Center" Margin="0,0,0,15"/>
<Frame x:Name="DateStart" CornerRadius="0" Padding="10,0">
<DatePicker MinimumDate="01/01/2022"
MaximumDate="12/31/2025"
Date="{Binding DateStart}"/>
</Frame>
<Frame CornerRadius="0" Padding="10,0">
<DatePicker x:Name="DateEnd" MinimumDate="01/01/2022"
MaximumDate="12/31/2025"
Date="{Binding DateEnd}" />
</Frame>
<Frame CornerRadius="0" Padding="10,0">
<Entry x:Name="dogName" Placeholder="שם הכלב/ה" Text="{Binding DogName}"/>
</Frame>
<Button Text="המשך" BackgroundColor="#EEBF3E"
TextColor="Black" CornerRadius="0"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MainViewModel}},Path=ContinueCommand}"
CommandParameter="{Binding Source={RelativeSource AncestorType={x:Type model:Order}}}">
<Button.Shadow>
<Shadow Brush="#ccccd0"
Offset="3,6"
Opacity="1"/>
</Button.Shadow>
</Button>
</VerticalStackLayout>
</Grid>
</VerticalStackLayout>
</ContentPage>
</code></pre>
<p>into the Entry, I try to insert my values and it's not working</p>
| [
{
"answer_id": 74461025,
"author": "Ridhwan Saal",
"author_id": 19698570,
"author_profile": "https://Stackoverflow.com/users/19698570",
"pm_score": 0,
"selected": false,
"text": "{word1}"
},
{
"answer_id": 74461315,
"author": "StonedTensor",
"author_id": 6023918,
"author_profile": "https://Stackoverflow.com/users/6023918",
"pm_score": 2,
"selected": true,
"text": "import string #to check for punctuation\n\nline = \"Welcome to your personal dashboard, where you can find an introduction to how GitHub works, tools to help you build software, and help merging your first lines of code.\"\n\nwords = line.split() #this includes punctuation attached to words as well\n\nshortest = min(words, key = len) #find the length of the words that is the smallest\n\nlongest = max(words, key = len) #opposite of above\n\nfor i, word in enumerate(words): #iterate with both the index and word in the list\n if word == shortest:\n if word[-1] in string.punctuation: #check if the punctuation is at the end since we want to keep it\n words[i] = longest + word[-1] #this keeps the punctuation\n else:\n words[i] = longest\n elif word == longest:\n if word[-1] in string.punctuation:\n words[i] = shortest + word[-1]\n else:\n words[i] = shortest\n\nline = ' '.join(words) #make a new line that has the replaced words\n\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74460972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13622774/"
] |
74,461,040 | <p>I have my table like this:</p>
<pre><code>WITH my_table (event_date, coordinates) AS (
values
('2021-10-01','{"x":"1.0","y":"0.049"}'),
('2021-10-01','{"x":"0.0","y":"0.865"}'),
('2021-10-02','{"y":"0.5","x":"0.5"}'),
('2021-10-02','{"y":"0.469","x":"0.175"}'),
('2021-10-02','{"x":"0.954","y":"0.021"}')
)
SELECT *
FROM my_table
</code></pre>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>event_date</th>
<th>coordinates</th>
</tr>
</thead>
<tbody>
<tr>
<td>2021-10-01</td>
<td>{"x":"1.0","y":"0.049"}</td>
</tr>
<tr>
<td>2021-10-01</td>
<td>{"x":"0.0","y":"0.865"}</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>{"y":"0.5","x":"0.5"}</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>{"y":"0.469","x":"0.175"}</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>{"x":"0.954","y":"0.021"}</td>
</tr>
</tbody>
</table>
</div>
<p>I want to parse x and y fields separately
Desired table should look like this:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>event_date</th>
<th>x</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr>
<td>2021-10-01</td>
<td>1.0</td>
<td>0.049</td>
</tr>
<tr>
<td>2021-10-01</td>
<td>0.0</td>
<td>0.865</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>0.5</td>
<td>0.5</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>0.469</td>
<td>0.175</td>
</tr>
<tr>
<td>2021-10-02</td>
<td>0.954</td>
<td>0.021</td>
</tr>
</tbody>
</table>
</div>
<p>Thanks for helping me!</p>
| [
{
"answer_id": 74461174,
"author": "Elie M",
"author_id": 1951045,
"author_profile": "https://Stackoverflow.com/users/1951045",
"pm_score": 2,
"selected": false,
"text": "select event_date,json_extract_scalar(coordinates,'$.attributes[\"x\"]') as x, json_extract_scalar(coordinates,'$.attributes[\"y\"]') as y;\n"
},
{
"answer_id": 74462435,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 2,
"selected": true,
"text": "json_extract_scalar"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5011113/"
] |
74,461,105 | <p>I want to get user data from the return of creating a user, as below:</p>
<pre><code>const newUserRes = await db.collection('users').add(userData);
</code></pre>
<p>Do you have any suggestions for me to get the new user document straight away from <code>newUserRes</code>?</p>
<p>I don't feel right to call a new read to get it:</p>
<pre><code>const newUserRef = await db.collection('users').doc(newUserRes.id).get();
const newUser = newUserRef.data()
</code></pre>
| [
{
"answer_id": 74461174,
"author": "Elie M",
"author_id": 1951045,
"author_profile": "https://Stackoverflow.com/users/1951045",
"pm_score": 2,
"selected": false,
"text": "select event_date,json_extract_scalar(coordinates,'$.attributes[\"x\"]') as x, json_extract_scalar(coordinates,'$.attributes[\"y\"]') as y;\n"
},
{
"answer_id": 74462435,
"author": "Guru Stron",
"author_id": 2501279,
"author_profile": "https://Stackoverflow.com/users/2501279",
"pm_score": 2,
"selected": true,
"text": "json_extract_scalar"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10434805/"
] |
74,461,144 | <p>Say I have folders named <code>user/john/john1</code>, <code>john2</code> and <code>john3</code> and I have one file called <code>dog.txt</code> inside each of them. I want to create a separate folder called <code>johns_dogs</code> and copy all the <code>dog.txt</code> from each folder into this new folder, but with the files renamed as <code>john1_dog.txt</code>, <code>john2_dog.txt</code>, <code>john3_dog.txt</code>.</p>
<p>How would I go about this? I assume I can use a for loop for this, and I have been playing around with it..i just can't seem to get it right; specifically isolating the folder names to apply to the file name using the linux terminal. Using GUI is not an option. Thank you :)</p>
<pre class="lang-bash prettyprint-override"><code>for fname in user/john/*/dog.txt;
do
new_name=basename $(PWD)
cp user/john/*/dog.txt > $new_name.txt;
done
</code></pre>
<p>This is what I've tried to do...but it doesn't work, and i don't know why?</p>
| [
{
"answer_id": 74462246,
"author": "j_b",
"author_id": 16482938,
"author_profile": "https://Stackoverflow.com/users/16482938",
"pm_score": 3,
"selected": true,
"text": "for f in ./user/john/*/dog.txt ; do \n new=\"${f//\\//_}\"\n new=\"${new/._user_john_/./johns_dogs/}\"\n cp \"$f\" \"$new\"\ndone\n"
},
{
"answer_id": 74472421,
"author": "Mike Nakis",
"author_id": 773113,
"author_profile": "https://Stackoverflow.com/users/773113",
"pm_score": 1,
"selected": false,
"text": "ls"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18801691/"
] |
74,461,153 | <p>I want to create a Quartz job that reads .csv files and moves them when the file is processed. I tried this:</p>
<pre><code>@Override
public void execute(JobExecutionContext context) {
File directoryPath = new File("C:\\csv\\nov");
// Create a new subfolder called "processed" into source directory
try {
Files.createDirectory(Path.of(directoryPath.getAbsolutePath() + "/processed"));
} catch (IOException e) {
throw new RuntimeException(e);
}
.......................
}
</code></pre>
<p>When I run the code a second time I get the error:</p>
<pre><code>Caused by: java.nio.file.FileAlreadyExistsException: C:\csv\nov\processed
</code></pre>
<p>Is there some way to make a check for this directory and skip directory creation? I can remove the line <code>throw new RuntimeException(e);</code> but I'm looking for a better way to handle the case.</p>
| [
{
"answer_id": 74461254,
"author": "YCF_L",
"author_id": 5558072,
"author_profile": "https://Stackoverflow.com/users/5558072",
"pm_score": 3,
"selected": true,
"text": "try {\n Path path = Path.of(directoryPath.getAbsolutePath() + \"/processed\");\n\n // Check first if the file not exist\n if (!Files.exists(path)) {\n Files.createDirectory(path);\n }\n} catch(..)\n"
},
{
"answer_id": 74461255,
"author": "DuncG",
"author_id": 4712734,
"author_profile": "https://Stackoverflow.com/users/4712734",
"pm_score": 1,
"selected": false,
"text": "Files.createDirectories(path)"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1103606/"
] |
74,461,161 | <p>I want to make my own dataset so I can use it for training and testing purposes. The problem is that I can handpick the points for training and testing to be a certain number of points (4096 in my case) but for new data it is not possible as I want to go for a real-time scenario and handpicking points is not an option.</p>
<p>Every time, the number of points that I get as new data is different. Sometimes the points are around 100k, other times it's ~200k. Is there a way I can downsample the point cloud to a specific number of points?</p>
<p>I am working with Open3D, but I cannot find any method which can help me with this. Any kind of help would be appreciated.</p>
| [
{
"answer_id": 74461254,
"author": "YCF_L",
"author_id": 5558072,
"author_profile": "https://Stackoverflow.com/users/5558072",
"pm_score": 3,
"selected": true,
"text": "try {\n Path path = Path.of(directoryPath.getAbsolutePath() + \"/processed\");\n\n // Check first if the file not exist\n if (!Files.exists(path)) {\n Files.createDirectory(path);\n }\n} catch(..)\n"
},
{
"answer_id": 74461255,
"author": "DuncG",
"author_id": 4712734,
"author_profile": "https://Stackoverflow.com/users/4712734",
"pm_score": 1,
"selected": false,
"text": "Files.createDirectories(path)"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20519351/"
] |
74,461,168 | <p>let's assume I have big data frame X (around 500,000 rows), and small data frame y (around 3000 rows).
I need to do join between those df's, and then I need to filter on the result df.
I recently realized I can do the filtering on X and that will give me the same result as filtering on the result joined df.
the filtering ensures me really small df.</p>
<p>This code is already in use.
my question is:
Does spark smart enough to do the filter before the join operation and to "ease" the join?
Or maybe this is just small improvement.</p>
| [
{
"answer_id": 74461254,
"author": "YCF_L",
"author_id": 5558072,
"author_profile": "https://Stackoverflow.com/users/5558072",
"pm_score": 3,
"selected": true,
"text": "try {\n Path path = Path.of(directoryPath.getAbsolutePath() + \"/processed\");\n\n // Check first if the file not exist\n if (!Files.exists(path)) {\n Files.createDirectory(path);\n }\n} catch(..)\n"
},
{
"answer_id": 74461255,
"author": "DuncG",
"author_id": 4712734,
"author_profile": "https://Stackoverflow.com/users/4712734",
"pm_score": 1,
"selected": false,
"text": "Files.createDirectories(path)"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17593430/"
] |
74,461,185 | <p>I want to convert a list with numbers to a matrix. This is my code:</p>
<pre><code> def converttomtx(mylist, rows, columns):
mtx = []
for r in range(rows):
lrow = []
for c in range(columns):
lrow.append(mylist[rows * r + c])
mtx.append(lrow)
return mtx
</code></pre>
<p>Assuming I use the following list:
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]</p>
<p>The code works if I set the rows to 3 and columns to 4, but when I set rows to 4 and columns to 3 then it throws an error that the list index is out of range. I cannot see why. The same happens when I use 2x6 and 6x2, 2x6 works but 6x2 doesn't.</p>
| [
{
"answer_id": 74461285,
"author": "Yevhen Kuzmovych",
"author_id": 4727702,
"author_profile": "https://Stackoverflow.com/users/4727702",
"pm_score": 0,
"selected": false,
"text": "mylist[rows * r + c]"
},
{
"answer_id": 74461289,
"author": "Jay",
"author_id": 8677071,
"author_profile": "https://Stackoverflow.com/users/8677071",
"pm_score": 1,
"selected": true,
"text": "rows * r + c"
},
{
"answer_id": 74461339,
"author": "Mr. Hobo",
"author_id": 6623589,
"author_profile": "https://Stackoverflow.com/users/6623589",
"pm_score": 1,
"selected": false,
"text": "numpy"
},
{
"answer_id": 74461477,
"author": "keithpjolley",
"author_id": 2624770,
"author_profile": "https://Stackoverflow.com/users/2624770",
"pm_score": 0,
"selected": false,
"text": "def l2m(mylist, rows, cols):\n if len(mylist) != rows * cols:\n print('wrong shape')\n return\n return [mylist[row*cols:(row+1)*cols] for row in range(rows)]\n\n\nmylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n\nprint(l2m(mylist, 12, 1))\nprint(l2m(mylist, 3, 4))\nprint(l2m(mylist, 9, 3)\n\n"
},
{
"answer_id": 74461640,
"author": "Circuit Planet",
"author_id": 15721021,
"author_profile": "https://Stackoverflow.com/users/15721021",
"pm_score": 0,
"selected": false,
"text": "mylist[rows * r + c]"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10448570/"
] |
74,461,187 | <p>I have a controller class in a JavaFX program which is handling numerous Nodes. I created a method <code>addEventListeners</code> which looks like:</p>
<pre><code> cleanButton.setOnAction(e -> {
...
});
advSett.setOnAction(e -> {
...
});
imageLoaderItem.setOnAction(e -> {
...
});
outputButton.setOnAction(e -> {
...
});
</code></pre>
<p>And so on for each element handled by the controller.
This method is occupying 300 lines of code making the controller class quite messy. I was wondering, is there a cleaner way of adding the listeners?</p>
| [
{
"answer_id": 74461788,
"author": "Vinz",
"author_id": 17173476,
"author_profile": "https://Stackoverflow.com/users/17173476",
"pm_score": 1,
"selected": false,
"text": "private void addEventListener(final ButtonBase element) {\n element.setOnAction(e -> {\n //do the thing\n });\n}\n"
},
{
"answer_id": 74468244,
"author": "jewelsea",
"author_id": 1155209,
"author_profile": "https://Stackoverflow.com/users/1155209",
"pm_score": 3,
"selected": true,
"text": "#"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10276248/"
] |
74,461,209 | <ol start="4">
<li>Write an SP that given input an integer n prints in the message window the first n numbers of the Fibonacci sequence, where each number f in the series is defined as follows: f0 = 0 f1 = 1 fn = fn-1</li>
</ol>
<ul>
<li>fn-2 (with n>1) For example, the first 10 numbers in the Fibonacci series are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34</li>
</ul>
<p>I'm missing the correct statement to align pyramid. Here's the code:</p>
<pre class="lang-sql prettyprint-override"><code>ALTER PROCEDURE dbo.pyramid(@i int)
as
BEGIN
DECLARE @max INT=4,@n INT=0,@J int =0
While @i<=@max
Begin
WHILE @J<=@i
BEGIN
Print space((@max-@j)/2) +REPLICATE((@n+@j),(@j))
Set @j += 1
END
set @i+=1
End
END
EXEC dbo.pyramid 1
</code></pre>
<p>the result is this:</p>
<pre><code> 1
22
333
4444
</code></pre>
<p>the expected result is this one:</p>
<pre><code> 1
2 2
3 3 3
4 4 4 4
</code></pre>
| [
{
"answer_id": 74462009,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 2,
"selected": false,
"text": "create or alter procedure dbo.pyramid(@i int) as\nwith n as (select * from (values(1),(2),(3),(4),(5),(6),(7),(8),(9))n(n))\n\nselect Concat(Replicate(' ', @i - n), Replicate(Concat(n, ' '), n))\nfrom n\nwhere n <= @i\norder by n;\n"
},
{
"answer_id": 74463630,
"author": "Sean Bloch",
"author_id": 20187370,
"author_profile": "https://Stackoverflow.com/users/20187370",
"pm_score": 0,
"selected": false,
"text": "CREATE OR ALTER PROCEDURE #pyramid \n(@i int = 9)\nAS\nBEGIN\nIF @i > 9 OR ISNULL(@i,0) < 1\nRAISERROR('no',11,1)\nELSE\nBEGIN\nSET ANSI_PADDING ON;\nSET CONCAT_NULL_YIELDS_NULL ON;\n ;WITH One2Nine AS (\n SELECT CAST(1 AS int) X\n UNION ALL SELECT X+1 FROM One2Nine o WHERE LEN(o.X+1) < 2\n )\n SELECT \n --'['+\n CAST(SUBSTRING(\n REPLICATE(CAST(REPLACE(CAST(CAST(\n ISNULL(NULLIF(ISNULL(STR(NULLIF(X%2,0),1,0),' '),'1'),' ')+REPLACE(STR(X,X,0),' ',X)\n AS NCHAR(10)) AS BINARY(20)),0x00,0x20) AS CHAR(20)),2)\n ,23-(9-x),17) AS CHAR(17))\n -- +']'\n FROM\n One2Nine\n WHERE X <= @i ORDER BY X\nEND\nEND\n\nEXEC #pyramid 4\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20426481/"
] |
74,461,258 | <p>This one's been giving me problems for a week, cross my fingers one of you can help me here...</p>
<p>This application was built on Laravel and the front scaffolded using Vue.</p>
<p>Thing is I have an array of objects that is supposed to be sent to the backend in order for it to be stored in a database. Thing is this is an editor and the idea is not reload the page every time something is changed, so here comes my problem...</p>
<p>The way of getting the information is through window.postMessage(), so it seems the information lingers on even after saving, since the page behavior is for it to not reload, I have tried emptying the array after firing the save function. Now it works the first time because the array is empty so there's nothing to compare it to, it also works the second time, but from the third time on, it duplicates some of the objects inside and stores them in DB.</p>
<p>Here's my code:</p>
<pre><code>saveNewSettings() {
//THIS IS THE ARRAY I NEED TO EMPTY (ALREADY DECLARED IN THE DATA OBJECT)
/* this.newItems = [
{ id="123", name="a", otherProps="someProps" },
{ id="456", name="ab, otherProps="someProps" },
{ id="789", name="c", otherProps="someProps" },
]
*/
//THIS IS THE AN EMPTY ARRAY I'M USING TO COMPARE LATER ON... (ALREADY DECLARED IN THE DATA OBJECT)
// this.newlyCreatedItems = [];
if ( !this.newlyCreatedItems.length ) {
this.newlyCreatedItems = this.newItems;
} else {
for ( let i = 0; i < this.newItems.length; i++ ) {
for ( let j = 0; j < this.newlyCreatedItems.length; j++ ) {
if ( this.newItems[i].id == this.newlyCreatedItems[j].id ) {
this.newItems.splice( i, 1 );
}
}
}
}
//THIS IS THE SERVICE I USE TO SEND THE INFO TO THE BACK END
//THIS ONE HAS BEEN IMPORTED FROM AN SERVICE FILE
settingsService.save( this.newItems )
.then(response => {
//WHAT TO DO AFTER THE RESPONSE GOES HERE
});
}
</code></pre>
<p>So here's the thing, firing the function for the first time, since it's the first, doesn't duplicate anything in the database... For the second time, it works well and it only saves the new item, from the third time on, it starts duplicating.</p>
<p>If you need me to elaborate more, just let me know, I thank you all in advance...</p>
| [
{
"answer_id": 74462009,
"author": "Stu",
"author_id": 15332650,
"author_profile": "https://Stackoverflow.com/users/15332650",
"pm_score": 2,
"selected": false,
"text": "create or alter procedure dbo.pyramid(@i int) as\nwith n as (select * from (values(1),(2),(3),(4),(5),(6),(7),(8),(9))n(n))\n\nselect Concat(Replicate(' ', @i - n), Replicate(Concat(n, ' '), n))\nfrom n\nwhere n <= @i\norder by n;\n"
},
{
"answer_id": 74463630,
"author": "Sean Bloch",
"author_id": 20187370,
"author_profile": "https://Stackoverflow.com/users/20187370",
"pm_score": 0,
"selected": false,
"text": "CREATE OR ALTER PROCEDURE #pyramid \n(@i int = 9)\nAS\nBEGIN\nIF @i > 9 OR ISNULL(@i,0) < 1\nRAISERROR('no',11,1)\nELSE\nBEGIN\nSET ANSI_PADDING ON;\nSET CONCAT_NULL_YIELDS_NULL ON;\n ;WITH One2Nine AS (\n SELECT CAST(1 AS int) X\n UNION ALL SELECT X+1 FROM One2Nine o WHERE LEN(o.X+1) < 2\n )\n SELECT \n --'['+\n CAST(SUBSTRING(\n REPLICATE(CAST(REPLACE(CAST(CAST(\n ISNULL(NULLIF(ISNULL(STR(NULLIF(X%2,0),1,0),' '),'1'),' ')+REPLACE(STR(X,X,0),' ',X)\n AS NCHAR(10)) AS BINARY(20)),0x00,0x20) AS CHAR(20)),2)\n ,23-(9-x),17) AS CHAR(17))\n -- +']'\n FROM\n One2Nine\n WHERE X <= @i ORDER BY X\nEND\nEND\n\nEXEC #pyramid 4\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16549000/"
] |
74,461,265 | <pre><code> S1 S2 S3 S4
Cohort 1 2 1 1
G1 23 44 67 13
G2 11 78 88 30
G3 45 46 56 66
G4 67 77 22 45
</code></pre>
<p>This is a demo dataset that I am using where S1, S2... are samples, cohort is the cohort variable which is 1 or 2, and G1, G2... are genes. The values are the expression values.</p>
<p>I want to find mean expression in cohort 1 and cohort 2.</p>
<p>I tried using if statements like <code>if(data$cohort ==1)</code> but it gives me an error: the condition has length > 1
Is there an easy way to work this out?</p>
| [
{
"answer_id": 74461557,
"author": "Gregor Thomas",
"author_id": 903061,
"author_profile": "https://Stackoverflow.com/users/903061",
"pm_score": 2,
"selected": false,
"text": "library(tidyr)\nlibrary(dplyr)\nlibrary(tibble)\ndf = t(data) |> \n as.data.frame() |> \n rownames_to_column(var = \"sample\") |>\n pivot_longer(cols = starts_with(\"G\"), names_to = \"gene\", values_to = \"expression\")\ndf\n# # A tibble: 16 × 4\n# sample Cohort gene expression\n# <chr> <int> <chr> <int>\n# 1 S1 1 G1 23\n# 2 S1 1 G2 11\n# 3 S1 1 G3 45\n# 4 S1 1 G4 67\n# 5 S2 2 G1 44\n# 6 S2 2 G2 78\n# 7 S2 2 G3 46\n# 8 S2 2 G4 77\n# 9 S3 1 G1 67\n# 10 S3 1 G2 88\n# ...\n"
},
{
"answer_id": 74461695,
"author": "zephryl",
"author_id": 17303805,
"author_profile": "https://Stackoverflow.com/users/17303805",
"pm_score": 2,
"selected": true,
"text": "Cohort"
},
{
"answer_id": 74461796,
"author": "MarBlo",
"author_id": 4282026,
"author_profile": "https://Stackoverflow.com/users/4282026",
"pm_score": 1,
"selected": false,
"text": " \ndf %>% pivot_longer(-Cohort) %>% \n nest(data = -Cohort) %>% \n mutate(mean = map(data, ~mean(.$value))) %>% \n unnest(mean)\n#> # A tibble: 2 × 3\n#> Cohort data mean\n#> <int> <list> <dbl>\n#> 1 1 <tibble [12 × 2]> 44.4\n#> 2 2 <tibble [4 × 2]> 61.2\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20511527/"
] |
74,461,272 | <p>I have a txt.file that looks like this:</p>
<pre><code>data1 data2 data3
data4 data5 data6
data7 data8 data9
data10 data11 data12
data13 data14 data15
data16 data17 data18
data19 data20 data21
data22 data23 data24
.
.
.
</code></pre>
<p>and I want to rearrange my txt file so that from data1 to data12 will be 1 line, and data13 to data24 will be second line and so on so forth. It is basically combining every 4 lines into 1 line. Desired output should look like this:</p>
<p>I desire something like this:</p>
<pre><code>data1 data2 data3 data4 data5 data6 data7 data8 data9 data10 data11 data12
data13 data14 data15 data16 data17 data18 data19 data20 data21 data22 data23 data24
</code></pre>
<p>How can I do this in Python?</p>
<p>Thank you for any advices,
Baris</p>
<p>I tried methods shared under various posts but none of them actually worked.</p>
| [
{
"answer_id": 74461418,
"author": "berkelem",
"author_id": 4844311,
"author_profile": "https://Stackoverflow.com/users/4844311",
"pm_score": 1,
"selected": false,
"text": "with open(\"text.txt\" \"r\") as f: # load data\n lines = f.readlines()\n\nnewlines = []\nfor i in range(0, len(lines), 4): # step through in blocks of four\n newline = lines[i].strip() + \" \" + lines[i+1].strip() + \" \" + lines[i+2].strip() + \" \" + lines[i+3].strip() + \" \" # add the lines together after stripping the newline characters at the end\n newlines.append(newline + \"\\n\") # save them to a list\n"
},
{
"answer_id": 74461539,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": true,
"text": "N = 4\ndf = pd.read_csv('your_file', sep='\\s+', header=None)\ndf2 = pd.DataFrame(df.to_numpy().reshape(-1, N*df.shape[1]))\n"
},
{
"answer_id": 74461764,
"author": "klimenkov",
"author_id": 2580443,
"author_profile": "https://Stackoverflow.com/users/2580443",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520264/"
] |
74,461,301 | <p>I'm having an introductory course in python right now and i get into some troubles with the task.</p>
<p>I have two strings in format:</p>
<pre><code>a b c d e
f g h i l
</code></pre>
<p>I need to get this strings from .txt file,convert them as matrix to vertical format like this:</p>
<pre><code>a f
b g
c h
d i
e l
</code></pre>
<p>and put into another .txt file, without using the numpy and pandas libraries. The problem is that from matrix like this:</p>
<pre><code>1 2 3 4 5
6 7 8 9 10
</code></pre>
<p>where each number don't have to be an integer, i need to get this matrix:</p>
<pre><code>1 6
2 7
3 8
4 9
5 10
</code></pre>
<p>and right now i can get only that with decimals:</p>
<pre><code>1.0 6.0
2.0 7.0
3.0 8.0
4.0 9.0
5.0 10.0
</code></pre>
<p>So, from my POW, i need to somehow remove the .0 from the final result, but i dk how i can remove decimals from the strings, consisted with float numbers.</p>
<p>Here goes my code:</p>
<pre><code>with open('input.txt') as f:
Matrix = [list(map(float, row.split())) for row in f.readlines()]
TrMatrix=[[Matrix[j][i] for j in range(len(Matrix))] for i in range(len(Matrix[0]))]
file=open('output.txt','w')
for i in range(len(TrMatrix)):
print(*TrMatrix[i],file=file)
</code></pre>
| [
{
"answer_id": 74461418,
"author": "berkelem",
"author_id": 4844311,
"author_profile": "https://Stackoverflow.com/users/4844311",
"pm_score": 1,
"selected": false,
"text": "with open(\"text.txt\" \"r\") as f: # load data\n lines = f.readlines()\n\nnewlines = []\nfor i in range(0, len(lines), 4): # step through in blocks of four\n newline = lines[i].strip() + \" \" + lines[i+1].strip() + \" \" + lines[i+2].strip() + \" \" + lines[i+3].strip() + \" \" # add the lines together after stripping the newline characters at the end\n newlines.append(newline + \"\\n\") # save them to a list\n"
},
{
"answer_id": 74461539,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": true,
"text": "N = 4\ndf = pd.read_csv('your_file', sep='\\s+', header=None)\ndf2 = pd.DataFrame(df.to_numpy().reshape(-1, N*df.shape[1]))\n"
},
{
"answer_id": 74461764,
"author": "klimenkov",
"author_id": 2580443,
"author_profile": "https://Stackoverflow.com/users/2580443",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520103/"
] |
74,461,310 | <p>during my internship, I have to launch a build on kubernetes. My setup is with K3s.</p>
<p>I must have an error in my deployment file, do you have an explanation please?</p>
<p>Thank you.</p>
<p>deployment.yml</p>
<pre><code>---
kind: Namespace
apiVersion: v1
metadata:
name: demo
labels:
name: demo
---
kind: Pod
apiVersion: v1
metadata:
name: kaniko-demo
namespace: demo
spec:
containers:
- name: kaniko-demo
image: gcr.io/kaniko-project/executor:latest
args:
[
"--dockerfile=Dockerfile_Kubernetes01",
"--context=dir:///context",
"--cache=true",
"--destination=reg.gitlab.reewayy.io/incubator/npivaut/k3s_kaniko",
"--cache=true",
"--cache-dir=/cache",
]
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker
- name: kaniko-context
mountPath: /context
- name: kaniko-cache
mountPath: /cache
restartPolicy: Never
volumes:
- name: kaniko-secret
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: config.json
- name: kaniko-context
hostPath:
path: /tmp/kaniko_context
- name: kaniko-context
hostPath:
path: /tmp/kaniko_cache
</code></pre>
<pre><code>kubectl apply -f /home/nicolas/demo-reewayy/k3s/kubernetes-deployment-01.yaml
namespace/demo unchanged
The Pod "kaniko-demo" is invalid:
* spec.volumes[2].name: Duplicate value: "kaniko-context"
* spec.containers[0].volumeMounts[2].name: Not found: "kaniko-cache"
</code></pre>
<p>Dockerfile</p>
<pre><code>FROM alpine/git as source
COPY deployment_key /root/.ssh/id_rsa
RUN git clone ssh://git@gitlab.reewayy.io:32222/incubator/npivaut.git ;\
cd /git/npivaut && git pull
FROM gradle:7.5.1-jdk17-focal as build
COPY --from=source /git/demo-reewayy /home/gradle/project
USER gradle
WORKDIR /home/gradle/project
RUN gradle :assemble
FROM ibm-semeru-runtimes:open-17-jre-jammy
RUN mkdir /opt/reewayy/demo-reewayy
COPY --from=build /home/gradle/project/build/libs/demo-0.0.1-SNAPSHOT.jar /opt/reewayy/demo/demo-0.0.1-SNAPSHOT.jar
COPY --from=build /home/gradle/project/src/main/resources/application.properties /opt/reewayy/demo/application.properties
RUN useradd -s /bin/bash -u 1000 -U -m -d /home/reewayy reewayy && chown -R reewayy.reewayy /opt/reewayy/
USER reewayy
CMD ["java","-jar","/opt/reewayy/demo-reewayy/demo-0.0.1-SNAPSHOT.jar"]
</code></pre>
<p>My internship mentor told me to optimize the deployment file but I have trouble understanding the error...</p>
| [
{
"answer_id": 74461418,
"author": "berkelem",
"author_id": 4844311,
"author_profile": "https://Stackoverflow.com/users/4844311",
"pm_score": 1,
"selected": false,
"text": "with open(\"text.txt\" \"r\") as f: # load data\n lines = f.readlines()\n\nnewlines = []\nfor i in range(0, len(lines), 4): # step through in blocks of four\n newline = lines[i].strip() + \" \" + lines[i+1].strip() + \" \" + lines[i+2].strip() + \" \" + lines[i+3].strip() + \" \" # add the lines together after stripping the newline characters at the end\n newlines.append(newline + \"\\n\") # save them to a list\n"
},
{
"answer_id": 74461539,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": true,
"text": "N = 4\ndf = pd.read_csv('your_file', sep='\\s+', header=None)\ndf2 = pd.DataFrame(df.to_numpy().reshape(-1, N*df.shape[1]))\n"
},
{
"answer_id": 74461764,
"author": "klimenkov",
"author_id": 2580443,
"author_profile": "https://Stackoverflow.com/users/2580443",
"pm_score": 0,
"selected": false,
"text": "numpy"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20280195/"
] |
74,461,327 | <pre><code>[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesResponseType(StatusCodes.Status303SeeOther)]
[HttpPost]
[Route("RegisterUsers")]
public async Task<ActionResult<List<UsersInfo>>> RegisterUsers(List<UsersInfo> Users)
{
// .. how to detect errors here ...
return Users;
}
</code></pre>
<p>How do I get errors here specially when API receive wrong format for UserInfo type in the body?</p>
<p>The method implementation never run in the case of wrong userinfo type.</p>
| [
{
"answer_id": 74461840,
"author": "Lonli-Lokli",
"author_id": 462669,
"author_profile": "https://Stackoverflow.com/users/462669",
"pm_score": 3,
"selected": true,
"text": " if (!ModelState.IsValid)\n {\n return BadRequest(ModelState);\n }\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1383383/"
] |
74,461,361 | <p>I have one array like below</p>
<p><code>[["GJ","MP"],["HR","MH"],["MP","KL"],["KL","HR"]]</code></p>
<p>And I want result like below</p>
<p><code>"GJ, MP, KL, HR, MH"</code></p>
<p>First element of array <code>["GJ","MP"]</code>
Added is in the <code>answer_string = "GJ, MP"</code>
Now Find <code>MP</code> which is the last element of this array in the other where is should be first element like this <code>["MP","KL"]</code>
after this I have to add <code>KL</code> in to the <code>answer_string = "GJ, MP, KL"</code></p>
<p>This is What I want as output</p>
| [
{
"answer_id": 74461434,
"author": "dangarfield",
"author_id": 3265253,
"author_profile": "https://Stackoverflow.com/users/3265253",
"pm_score": 1,
"selected": false,
"text": "d = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\no = [] # List for output\nc = d[0][0] # Save the current first object\nloop do # Keep looping through until there are no matching pairs\n o.push(c) # Push the current first object to the output\n n = d.index { |a| a[0] == c } # Get the index of the first matched pair of the current `c`\n break if n == nil # If there are no found index, we've essentially gotten to the end of the graph\n c = d[n][1] # Update the current first object\nend\nputs o.join(',') # Join the results\n"
},
{
"answer_id": 74462674,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 1,
"selected": false,
"text": "a"
},
{
"answer_id": 74462736,
"author": "Konstantin Strukov",
"author_id": 8008340,
"author_profile": "https://Stackoverflow.com/users/8008340",
"pm_score": 3,
"selected": true,
"text": "ary = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\n"
},
{
"answer_id": 74462940,
"author": "LihnNguyen",
"author_id": 15527415,
"author_profile": "https://Stackoverflow.com/users/15527415",
"pm_score": 1,
"selected": false,
"text": "arr.size.times"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4265308/"
] |
74,461,398 | <p>I am making a survey in Spyder. I need to make it so the output does not allow for anyone under 18 to complete the survey.... I can get it to print the error message but the survey still continues...</p>
<p>As you can probably tell, I am a beginner.</p>
<pre><code>excluded_ages= '17''16''15''14''13''12''11''10''9''8''7''6''5''4''3''2''1''0'
age_input=input('Enter your age: ')
print(input)
if age_input in excluded_ages:
print('You may not proceed with this survey')
break
postcode_input=input('Enter your postcode: ')
print(input)
</code></pre>
<p>I don't even know if break is the right function here, either way, it is showing up as an error because it is outside the loop... everything I type is either outside the loop or outside a function!</p>
| [
{
"answer_id": 74461434,
"author": "dangarfield",
"author_id": 3265253,
"author_profile": "https://Stackoverflow.com/users/3265253",
"pm_score": 1,
"selected": false,
"text": "d = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\no = [] # List for output\nc = d[0][0] # Save the current first object\nloop do # Keep looping through until there are no matching pairs\n o.push(c) # Push the current first object to the output\n n = d.index { |a| a[0] == c } # Get the index of the first matched pair of the current `c`\n break if n == nil # If there are no found index, we've essentially gotten to the end of the graph\n c = d[n][1] # Update the current first object\nend\nputs o.join(',') # Join the results\n"
},
{
"answer_id": 74462674,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 1,
"selected": false,
"text": "a"
},
{
"answer_id": 74462736,
"author": "Konstantin Strukov",
"author_id": 8008340,
"author_profile": "https://Stackoverflow.com/users/8008340",
"pm_score": 3,
"selected": true,
"text": "ary = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\n"
},
{
"answer_id": 74462940,
"author": "LihnNguyen",
"author_id": 15527415,
"author_profile": "https://Stackoverflow.com/users/15527415",
"pm_score": 1,
"selected": false,
"text": "arr.size.times"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520426/"
] |
74,461,402 | <p>Input CSV as below:</p>
<p><a href="https://i.stack.imgur.com/tOcp9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tOcp9.png" alt="enter image description here" /></a></p>
<p>Expected new CSV file :</p>
<p><a href="https://i.stack.imgur.com/oSWOf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oSWOf.png" alt="enter image description here" /></a></p>
<p>I'm getting disk info from below code:</p>
<pre><code>$Global:diskinfo=get-WmiObject win32_logicaldisk | select-object DeviceID, volumename, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
</code></pre>
<p>How I can append this data to original csv.</p>
| [
{
"answer_id": 74461434,
"author": "dangarfield",
"author_id": 3265253,
"author_profile": "https://Stackoverflow.com/users/3265253",
"pm_score": 1,
"selected": false,
"text": "d = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\no = [] # List for output\nc = d[0][0] # Save the current first object\nloop do # Keep looping through until there are no matching pairs\n o.push(c) # Push the current first object to the output\n n = d.index { |a| a[0] == c } # Get the index of the first matched pair of the current `c`\n break if n == nil # If there are no found index, we've essentially gotten to the end of the graph\n c = d[n][1] # Update the current first object\nend\nputs o.join(',') # Join the results\n"
},
{
"answer_id": 74462674,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 1,
"selected": false,
"text": "a"
},
{
"answer_id": 74462736,
"author": "Konstantin Strukov",
"author_id": 8008340,
"author_profile": "https://Stackoverflow.com/users/8008340",
"pm_score": 3,
"selected": true,
"text": "ary = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\n"
},
{
"answer_id": 74462940,
"author": "LihnNguyen",
"author_id": 15527415,
"author_profile": "https://Stackoverflow.com/users/15527415",
"pm_score": 1,
"selected": false,
"text": "arr.size.times"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14917783/"
] |
74,461,411 | <p>I've made a container and there is text and a background image in the container. The text is in h3 tags. I want the text to stay hidden showing only image. When user hover over the container I want to display the text and background image has to little transparent.
How can I do that??
this is my CSS code so far... I have also attached the image I'm using<a href="https://i.stack.imgur.com/MLu3i.jpg" rel="nofollow noreferrer">Image I'm using for this code</a></p>
<pre><code>.container{
background-size: cover;
background-repeat: no-repeat;
margin-top: 100px;
padding: 18px 40px;
font-size: 22px;
text-align: center;
width: 250px;
height: 250px;
border-radius: 35px;
color: transparent;
line-height: 200px;
float: left;
margin-left: 20%;
background-image: url(/Unstitched.jpeg.jpg);
}
.container:hover{
background: rgba(255,0,0,0.3) ;
color: black
}
</code></pre>
| [
{
"answer_id": 74461434,
"author": "dangarfield",
"author_id": 3265253,
"author_profile": "https://Stackoverflow.com/users/3265253",
"pm_score": 1,
"selected": false,
"text": "d = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\no = [] # List for output\nc = d[0][0] # Save the current first object\nloop do # Keep looping through until there are no matching pairs\n o.push(c) # Push the current first object to the output\n n = d.index { |a| a[0] == c } # Get the index of the first matched pair of the current `c`\n break if n == nil # If there are no found index, we've essentially gotten to the end of the graph\n c = d[n][1] # Update the current first object\nend\nputs o.join(',') # Join the results\n"
},
{
"answer_id": 74462674,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 1,
"selected": false,
"text": "a"
},
{
"answer_id": 74462736,
"author": "Konstantin Strukov",
"author_id": 8008340,
"author_profile": "https://Stackoverflow.com/users/8008340",
"pm_score": 3,
"selected": true,
"text": "ary = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\n"
},
{
"answer_id": 74462940,
"author": "LihnNguyen",
"author_id": 15527415,
"author_profile": "https://Stackoverflow.com/users/15527415",
"pm_score": 1,
"selected": false,
"text": "arr.size.times"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520316/"
] |
74,461,429 | <p>I have my application.properties file in src/main/resources and i have my different active profile (application-dev.properties and application-prod.properties) in differenent directory as src/main/resources/properties.</p>
<p><strong>I'm using springboot version 2.7.5</strong></p>
<p>I tried to configure it in application.properties file which is in directory-src/main/resources
spring.profiles.active=dev</p>
<p>but it is not reading the application-dev.properties from directory src/main/resources/properties</p>
<p>For fixing this issue i created two class</p>
<pre><code>@Configuration
public class ActiveProfileConfiguration extends AbstractSecurityWebApplicationInitializer{
private static final Logger log = LoggerFactory.getLogger(ApplicationJPAConfiguration.class);
private static final String SPRING_PROFILES_ACTIVE = "SPRING_PROFILES_ACTIVE";
String profile;
protected void setSpringProfile(ServletContext servletContext) {
if(null!= System.getenv(SPRING_PROFILES_ACTIVE)){
profile=System.getenv(SPRING_PROFILES_ACTIVE);
}else if(null!= System.getProperty(SPRING_PROFILES_ACTIVE)){
profile=System.getProperty(SPRING_PROFILES_ACTIVE);
}else{
profile="local";
}
log.info("***** Profile configured is ****** "+ profile);
servletContext.setInitParameter("spring.profiles.active", profile);
}
}
</code></pre>
<p>and</p>
<pre><code>@Configuration
@Profile("local")
public class DevPropertyReader {
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] { new ClassPathResource("application.properties"), new ClassPathResource("EnvironmentProfiles/application-local.properties") };
ppc.setLocations(resources);
ppc.setIgnoreUnresolvablePlaceholders(true);
System.out.println("env active profile");
return ppc;
}
}
</code></pre>
<p>But still not able to resolve this issue.</p>
| [
{
"answer_id": 74461434,
"author": "dangarfield",
"author_id": 3265253,
"author_profile": "https://Stackoverflow.com/users/3265253",
"pm_score": 1,
"selected": false,
"text": "d = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\no = [] # List for output\nc = d[0][0] # Save the current first object\nloop do # Keep looping through until there are no matching pairs\n o.push(c) # Push the current first object to the output\n n = d.index { |a| a[0] == c } # Get the index of the first matched pair of the current `c`\n break if n == nil # If there are no found index, we've essentially gotten to the end of the graph\n c = d[n][1] # Update the current first object\nend\nputs o.join(',') # Join the results\n"
},
{
"answer_id": 74462674,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 1,
"selected": false,
"text": "a"
},
{
"answer_id": 74462736,
"author": "Konstantin Strukov",
"author_id": 8008340,
"author_profile": "https://Stackoverflow.com/users/8008340",
"pm_score": 3,
"selected": true,
"text": "ary = [[\"GJ\",\"MP\"],[\"HR\",\"MH\"],[\"MP\",\"KL\"],[\"KL\",\"HR\"]]\n"
},
{
"answer_id": 74462940,
"author": "LihnNguyen",
"author_id": 15527415,
"author_profile": "https://Stackoverflow.com/users/15527415",
"pm_score": 1,
"selected": false,
"text": "arr.size.times"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18405240/"
] |
74,461,438 | <p>I am trying to create a table where each cell consists of a letter and a number. see an image of the target table:</p>
<p><img src="https://i.stack.imgur.com/HOuJY.jpg" alt="target table" /></p>
<p>Here is the HTML code that I am using. It's a simple button that when clicked, should call the <code>populateTable()</code> function and then display the table on the page.</p>
<pre><code><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Document</title>
<style>
table { border-collapse: collapse; margin: 1em 0; }
td { border: 1px solid black; padding: 0.3em; }
</style>
</head>
<body>
<h2>Table</h2>
<table id="the-table"></table>
<button type="button" onclick="populateTable();">Populate table</button>
<script src="table.js"></script>
</body>
</html>
</code></pre>
<p>But the main issue here is my JS code.</p>
<pre><code>function populateTable(){
letters = ["a", "b", "c", "d", "e"]
numbers = ["1", "2", "3", "4", "5"]
for(let i = 0; i < numbers.length; i++){
document.getElementById("the-table").innerHTML += "<tr>"
for(let j = 0; j < letters.length; j++){
document.getElementById("the-table").innerHTML += "<td>" + letters[j] + numbers[i] + "</td>"
}
document.getElementById("the-table").innerHTML += "</tr>"
}
}
</code></pre>
<p>How can I create a new <tr> after inner loop exits?</p>
<p>The outcome of this current code looks like <a href="https://i.stack.imgur.com/KxLck.png" rel="nofollow noreferrer">this</a></p>
<p>Please help :'D</p>
<p>I tried moving around the</p>
<pre><code>document.getElementById("the-table").innerHTML += "<tr>"
</code></pre>
<p>and</p>
<pre><code>document.getElementById("the-table").innerHTML += "</tr>"
</code></pre>
<p>but to no avail.
I tried looking for an answer online, but I found nothing that is useful to my case. things like appendChild were not really what i am looking for exactly. I just want to know why these lines mentioned above ("<tr>") won't work and what's the easiest way to fix this?</p>
| [
{
"answer_id": 74461566,
"author": "aloisdg",
"author_id": 1248177,
"author_profile": "https://Stackoverflow.com/users/1248177",
"pm_score": 2,
"selected": false,
"text": "creatElement"
},
{
"answer_id": 74461657,
"author": "Gauge",
"author_id": 20520502,
"author_profile": "https://Stackoverflow.com/users/20520502",
"pm_score": 3,
"selected": true,
"text": "function populateTable(){\n letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n numbers = [\"1\", \"2\", \"3\", \"4\", \"5\"]\n innerTable = '';\n \n for(let i = 0; i < numbers.length; i++){\n innerTable += \"<tr>\"\n \n for(let j = 0; j < letters.length; j++){\n innerTable += \"<td>\" + letters[j] + numbers[i] + \"</td>\"\n }\n \n innerTable += \"</tr>\"\n }\n \n document.getElementById(\"the-table\").innerHTML += innerTable;\n}"
},
{
"answer_id": 74461772,
"author": "Shakhawat Hossain SHIHAB",
"author_id": 11052029,
"author_profile": "https://Stackoverflow.com/users/11052029",
"pm_score": 0,
"selected": false,
"text": "<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\"/>\n <title>Document</title>\n <style>\n table { border-collapse: collapse; margin: 1em 0; }\n td { border: 1px solid black; padding: 0.3em; }\n </style>\n </head>\n <body>\n \n <h2>Table</h2>\n <table id=\"the-table\"></table>\n <button type=\"button\" onclick=\"populateTable();\">Populate table</button> \n \n <script >\n function populateTable(){\n letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n numbers = [\"1\", \"2\", \"3\", \"4\", \"5\"]\n let str=\"\"\n numbers.map(n=>{\n str+=\"<tr>\"\n letters.map(l=>{\n str+=`<td> ${l} ${n} </td>`\n })\n str+=\"</tr>\"\n })\n //console.log('str ',str);\n document.getElementById(\"the-table\").innerHTML=str;\n }\n\n </script>\n </body>\n</html>"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20145017/"
] |
74,461,445 | <p>I have dataframe</p>
<pre><code>0 г. Санкт-Петербург, ул. Карпинского,
1 г. Челябинск, проспект Комсомольский,
2 г. Екатеринбург, ул. Щербакова,
3 г. Санкт-Петербург, ул. Латышских Стрелков,
4 г. Москва, вн.тер.г. муниципальный округ Измай...
</code></pre>
<p>I want all between 'г.' and ',' like</p>
<pre><code>0 Санкт-Петербург
1 Челябинск
2 Екатеринбург
3 Санкт-Петербург
4 Москва
</code></pre>
<p>I have code data['col'] = data['address'].str.extract('(г.*,)') but it doesn't give me desired result</p>
| [
{
"answer_id": 74461476,
"author": "Celius Stingher",
"author_id": 11897007,
"author_profile": "https://Stackoverflow.com/users/11897007",
"pm_score": 0,
"selected": false,
"text": "split()"
},
{
"answer_id": 74461583,
"author": "mozway",
"author_id": 16343464,
"author_profile": "https://Stackoverflow.com/users/16343464",
"pm_score": 1,
"selected": false,
"text": "str.extract"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20407815/"
] |
74,461,446 | <p>I'm trying to teach myself React and I have a 'Bop it' button function that changes the text on each click.</p>
<pre><code> function BopButton() {
const [action, setAction] = React.useState('');
const actions = ['Bop', 'Twist', 'Spin', 'Pull'];
function handleClick() {
const len = actions.length;
setAction(actions[Math.floor(Math.random() * len)].text)
console.log("change text")
}
return (
<div>
<button onClick={handleClick}>{action} it</button>
</div>
);
}
</code></pre>
<p>I'm expecting the state of the button text to change. What am I doing wrong?</p>
| [
{
"answer_id": 74461471,
"author": "kind user",
"author_id": 6695924,
"author_profile": "https://Stackoverflow.com/users/6695924",
"pm_score": 3,
"selected": true,
"text": "actions"
},
{
"answer_id": 74461546,
"author": "stasdes",
"author_id": 2091359,
"author_profile": "https://Stackoverflow.com/users/2091359",
"pm_score": 0,
"selected": false,
"text": ".text"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20034635/"
] |
74,461,448 | <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>let pppp = {
name: "duanxiao",
age: 1,
job: {
title: "~~~"
}
};
let ppppCopy = {};
({
name: ppppCopy.name,
age: ppppCopy.age,
job: ppppCopy.job
} = pppp);
pppp.job.title = "Hacker";
console.log(pppp);
console.log(ppppCopy);</code></pre>
</div>
</div>
</p>
<p>The output values are the same.</p>
<p><strong>Why modifying the value of one object, the other object will also be modified?</strong></p>
<p>Whenever I modify the value of one object, the value of the other object is also modified.</p>
| [
{
"answer_id": 74461555,
"author": "Evgeni Dikerman",
"author_id": 1761692,
"author_profile": "https://Stackoverflow.com/users/1761692",
"pm_score": 2,
"selected": false,
"text": "pppp"
},
{
"answer_id": 74461598,
"author": "Edoardo Sichelli",
"author_id": 14498331,
"author_profile": "https://Stackoverflow.com/users/14498331",
"pm_score": 0,
"selected": false,
"text": " name: \"duanxiao\",\n age: 1,\n job: {\n title: \"~~~\"\n }\n};\nlet ppppCopy = JSON.parse(JSON.stringify(pppp));\n\n\n\npppp.job.title = \"Hacker\";\n\nconsole.log(pppp);\nconsole.log(ppppCopy);\n"
},
{
"answer_id": 74461601,
"author": "Ravindra Thorat",
"author_id": 3578755,
"author_profile": "https://Stackoverflow.com/users/3578755",
"pm_score": 3,
"selected": true,
"text": "pppp"
},
{
"answer_id": 74462236,
"author": "Osama Younus",
"author_id": 11674487,
"author_profile": "https://Stackoverflow.com/users/11674487",
"pm_score": 0,
"selected": false,
"text": "let copy = { ...original} "
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16033355/"
] |
74,461,463 | <p>Using the <code>.resample()</code> method yields a DataFrame with a DatetimeIndex and a frequency.</p>
<p>Does anyone have an idea on how to iterate through the values of that DatetimeIndex ?</p>
<pre class="lang-py prettyprint-override"><code>df = pd.DataFrame(
data=np.random.randint(0, 10, 100),
index=pd.date_range('20220101', periods=100),
columns=['a'],
)
df.resample('M').mean()
</code></pre>
<p>If you iterate, you get individual entries taking the <code>Timestamp(‘2022-11-XX…’, freq=‘M’)</code> form but I did not manage to get the date only.</p>
<pre class="lang-py prettyprint-override"><code>g.resample('M').mean().index[0]
Timestamp('2022-01-31 00:00:00', freq='M')
</code></pre>
<p>I am aiming at feeding all the dates in a list for instance.</p>
<p>Thanks for your help !</p>
| [
{
"answer_id": 74462253,
"author": "skillsmuggler",
"author_id": 11523400,
"author_profile": "https://Stackoverflow.com/users/11523400",
"pm_score": 1,
"selected": false,
"text": "Datetime"
},
{
"answer_id": 74466919,
"author": "pomseb",
"author_id": 14825527,
"author_profile": "https://Stackoverflow.com/users/14825527",
"pm_score": 0,
"selected": false,
"text": "I = [k.strftime('%Y-%m') for k in g.resample('M').groups]"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14825527/"
] |
74,461,468 | <p>It's 2022 and sadly I'm learning AngularJS (already past end of life!)</p>
<p>I need need to use what might be called a dynamic element/component. Pseudocode example:</p>
<p>In controller:</p>
<pre><code> this.theElementName = 'b';
</code></pre>
<p>In the template:</p>
<pre><code> <{{$ctrl.theElementName}}>this is some text</{{$ctrl.theElementName}}>
</code></pre>
<p>I would want this to create <code><b>this is some text</b></code>.</p>
<p>The reason is that I want to generate an array of different directives to render, and I <strong>don't</strong> want code like:</p>
<pre><code><b ng-if="$ctrl.theElementName === 'b'">this is some text</b>
<div ng-if="$ctrl.theElementName === 'div'">this is some text</div>
<directive-abc ng-if="$ctrl.theElementName === 'directive-abc'">this is some text</directive-abc>
...
</code></pre>
<p>In Svelte, it's</p>
<pre><code><svelte:element this={theElementName} />
</code></pre>
<p>In Vue it's</p>
<pre><code><div :is="theElementName" />
</code></pre>
<h2>EDIT: in response to the reluctant 'that person', clarifying the use-case</h2>
<p>Consider a user-configurable UI. The result of the configuration might be an array list of components desired. I would then need to loop and output those different components in my template. Of course the components would need a standard interface for properties passesd in, events emitted etc. but that can all be designed for.</p>
<p>My code could do a big switch statement, but that requires prior knowledge of every possible component that might be used now or in the future. By doing it the way I intend to, however, a future person could add a component without needing to touch this code.</p>
| [
{
"answer_id": 74473243,
"author": "artfulrobot",
"author_id": 623519,
"author_profile": "https://Stackoverflow.com/users/623519",
"pm_score": 0,
"selected": false,
"text": "ng-include"
},
{
"answer_id": 74494621,
"author": "Petr Averyanov",
"author_id": 4019404,
"author_profile": "https://Stackoverflow.com/users/4019404",
"pm_score": 1,
"selected": false,
"text": "my-directive"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/623519/"
] |
74,461,512 | <p>i Download 2 files from instgram</p>
<pre><code>504273856298686966_186593000.mp4
1445150401635783037_186593000.jpg
</code></pre>
<p>This part (_186593000) is dedicated to the user ID from which I downloaded the two files.
What I'm interested in is the part before (Underscore _) that specifies the date of the file</p>
<p>When I used (Bulk Rename Utility) program, it changed the name of the two files (based on the actual date of the two files, not the name) to the following:</p>
<pre><code>504273856298686966_186593000.mp4 TO 2013-07-20_18-29-09.mp4
1445150401635783037_186593000.jpg TO 2017-02-07_22-22-54.jpg
</code></pre>
<p>Is there a way For the extraction the date based on the filename (504273856298686966 AND 1445150401635783037) by php code?</p>
| [
{
"answer_id": 74461745,
"author": "Spomky-Labs",
"author_id": 2157818,
"author_profile": "https://Stackoverflow.com/users/2157818",
"pm_score": 1,
"selected": false,
"text": "exif_read_data"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15119287/"
] |
74,461,516 | <p>All, I have a spreadsheet where I'm exporting a set of numbers. The spreadsheet tracks missing numbers and looks like this:</p>
<p>[NOTE: this spreadsheet can have 'X' number of columns so I never know the A1:XX range -- I may need to do Range.Find?]</p>
<pre><code>A1 |B1 |C1 |D1 |E1 |F1
------------------------------------------------------------
Column 1 |Missing # |Column 2 |Missing # |Column 3 |Missing#
1 |2 |4 |5 |7 |8
2 | |5 |6 |8 |
3 | |6 | |9 |
</code></pre>
<p>The VBA macro in the spreadsheet exports the numbers in the "Missing #" columns. Currently, the macro successfully exports just the numbers from the "Missing #" columns.</p>
<p>BUT --</p>
<p>What I would like to do is export the data so the missing number is prepended/concatenated with the previous (associated) column name. Like this:</p>
<pre><code>Column 1 - 2
Column 2 - 5
Column 2 - 6
Column 3 - 8
</code></pre>
<p>Currently, it simply exports like this:</p>
<pre><code>Missing # Missing # Missing#
2 5 8
6
</code></pre>
<p>Some of the background logic: The column range is never fixed so it is always A1:??. Also, if a number from a batch is missing, it is always placed in the next column, ie, if a number in the E column is missing, it will be noted as missing in the F column, etc.</p>
<p>And here's what I have so far:</p>
<pre><code>Sub FindMissing()
Application.ScreenUpdating = False
Dim xRg As Range, xRgUni As Range, xFirstAddress As String, xStr As String, srcWB As Workbook
Set srcWB = ThisWorkbook
xStr = "Missing #"
Set xRg = Rows(1).Find(xStr, , xlValues, xlWhole, , , True)
If Not xRg Is Nothing Then
xFirstAddress = xRg.Address
Do
Set xRg = Range("A1:Z1").FindNext(xRg)
If xRgUni Is Nothing Then
Set xRgUni = xRg
Else
Set xRgUni = Application.Union(xRgUni, xRg)
End If
Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
xRgUni.EntireColumn.Copy
Workbooks.Add
ActiveSheet.Paste
fName = srcWB.Path & "\Missing UPCs" & ".csv"
With ActiveWorkbook
.SaveAs Filename:=fName, FileFormat:=xlCSV, CreateBackup:=False
MsgBox "your missing numbers file " & vbNewLine & "has been saved!"
.Close False
End With
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub
</code></pre>
<p>Thanks for any help, not sure how I go about concatenating the previous column name or taking into account the unknown column range... thanks!</p>
| [
{
"answer_id": 74462431,
"author": "Ike",
"author_id": 16578424,
"author_profile": "https://Stackoverflow.com/users/16578424",
"pm_score": 2,
"selected": false,
"text": "findMissing"
},
{
"answer_id": 74462986,
"author": "FaneDuru",
"author_id": 2233308,
"author_profile": "https://Stackoverflow.com/users/2233308",
"pm_score": 1,
"selected": false,
"text": "Sub FindMissing()\n Dim xRg As Range, xRgUni As Range, xFirstAddress As String, xStr As String, srcWB As Workbook\n Dim fName As String, countMiss As Long\n \n Set srcWB = ThisWorkbook\n xStr = \"Missing #\"\n Set xRg = rows(1).Find(xStr, , xlValues, xlWhole, , , True)\n countMiss = WorksheetFunction.CountIf(rows(1), xStr) 'number of \"Missing #\" columns\n \n Dim strPref As String, arrFin, i As Long, j As Long, k As Long, lastR As Long\n \n If Not xRg Is Nothing Then\n strPref = xRg.Offset(, -1).Value\n lastR = Range(\"A\" & rows.count).End(xlUp).row\n ReDim arrFin(1 To lastR, 1 To countMiss): i = 1: k = 1\n \n For i = 1 To countMiss: arrFin(1, i) = xStr: Next: i = 2 'fill the array header\n \n lastR = cells(rows.count, xRg.Column).End(xlUp).row\n For j = 1 To lastR\n If xRg.Offset(j).Value = \"\" Then k = k + 1: Exit For\n arrFin(i + j - 1, k) = strPref & \" - \" & xRg.Offset(j).Value\n Next j\n xFirstAddress = xRg.address\n Do\n Set xRg = rows(1).FindNext(xRg)\n If xRg.address = xFirstAddress Then Exit Do\n If Not xRg Is Nothing Then\n strPref = xRg.Offset(, -1).Value\n lastR = Range(\"A\" & rows.count).End(xlUp).row\n For j = 1 To lastR\n If xRg.Offset(j).Value = \"\" Then k = k + 1: Exit For\n arrFin(i + j - 1, k) = strPref & \" - \" & xRg.Offset(j).Value\n Next j\n End If\n Loop While (xRg.address <> xFirstAddress)\n End If\n\n Workbooks.Add\n ActiveSheet.Range(\"A1\").Resize(UBound(arrFin), UBound(arrFin, 2)).Value2 = arrFin\n\n fName = srcWB.Path & \"\\Missing UPCs\" & \".csv\"\n With ActiveWorkbook\n .saveas fileName:=fName, FileFormat:=xlCSV, CreateBackup:=False\n MsgBox \"Your missing numbers file \" & vbNewLine & \"has been saved!\", vbInformation, _\n \"Saving confirmation\"\n .Close False\n End With\nEnd Sub\n"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20007308/"
] |
74,461,578 | <p>I am trying this :</p>
<p>print " Enter Value "
num = gets.chomp</p>
<h1>also tried .kind_of? but didn't work</h1>
<p>if num.is_a? Float<br />
print " Number is in float "</p>
<h1>also tried .kind_of? but didn't work</h1>
<p>else num.is_a? Integer<br />
print " Number is in integer "</p>
<p>end</p>
| [
{
"answer_id": 74461930,
"author": "BenFenner",
"author_id": 14837782,
"author_profile": "https://Stackoverflow.com/users/14837782",
"pm_score": 0,
"selected": false,
"text": "num = 6.6\nnum.is_a?(Integer)\n=> false\nnum.is_a?(Float)\n=> true\n"
},
{
"answer_id": 74461949,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 2,
"selected": false,
"text": "gets"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12018669/"
] |
74,461,586 | <p>Suppose I have this table:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Image</th>
<th>Perimeter</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>1</td>
</tr>
<tr>
<td>b</td>
<td>1</td>
</tr>
<tr>
<td>b</td>
<td>2</td>
</tr>
<tr>
<td>d</td>
<td>3</td>
</tr>
<tr>
<td>e</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
<p>I want to return the images that have relationship with only ONE perimeter.</p>
<p>The expected result would be images "a,d,e" because image "b" has relationship with perimeter "1" and "2".</p>
<p>The objective is to remove the releated image when I delete the perimeter. But if it is linked to another perimeter, I can't remove it.</p>
<p>How can I write this query with LINQ?</p>
<p>I think it would be something like this:</p>
<pre><code>SELECT "ImageId"
WHERE "PerimeterId" = PerimeterId IN
(
SELECT "ImageId"
GROUP BY "ImageId"
HAVING COUNT("PerimeterId") = 1
)
</code></pre>
<p>but I don't know how to convert it to LINQ.</p>
| [
{
"answer_id": 74461930,
"author": "BenFenner",
"author_id": 14837782,
"author_profile": "https://Stackoverflow.com/users/14837782",
"pm_score": 0,
"selected": false,
"text": "num = 6.6\nnum.is_a?(Integer)\n=> false\nnum.is_a?(Float)\n=> true\n"
},
{
"answer_id": 74461949,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 2,
"selected": false,
"text": "gets"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19943087/"
] |
74,461,587 | <p>I'm using the <code>cypress-fail-fast</code> plugin > <a href="https://github.com/javierbrea/cypress-fail-fast" rel="nofollow noreferrer">https://github.com/javierbrea/cypress-fail-fast</a> in my Typescript Cypress config, but it doesn't seem to be working.</p>
<pre><code>// cypress.config.ts
import { defineConfig } from 'cypress';
import plugin from './cypress/plugins/index';
export default defineConfig({
projectId: '**',
fixturesFolder: 'cypress/fixtures',
screenshotOnRunFailure: true,
video: true,
videoCompression: 1,
viewportHeight: 1000,
viewportWidth: 1600,
e2e: {
env: {
API_URL: '**',
CYPRESS_PASSWORD: '**',
},
supportFile: 'cypress/support/index.ts',
baseUrl: 'http://localhost:4200',
experimentalInteractiveRunEvents: true,
setupNodeEvents(on, config) {
plugin(on, config);
},
},
});
</code></pre>
<pre><code>// supprt/index.ts
import './commands';
import './hooks';
import 'cypress-real-events/support';
import 'cypress-file-upload';
import 'cypress-fail-fast/plugin';
</code></pre>
<p>That's how I got it set up, but after a test fails in a spec, it still runs each test.</p>
| [
{
"answer_id": 74461930,
"author": "BenFenner",
"author_id": 14837782,
"author_profile": "https://Stackoverflow.com/users/14837782",
"pm_score": 0,
"selected": false,
"text": "num = 6.6\nnum.is_a?(Integer)\n=> false\nnum.is_a?(Float)\n=> true\n"
},
{
"answer_id": 74461949,
"author": "engineersmnky",
"author_id": 1978251,
"author_profile": "https://Stackoverflow.com/users/1978251",
"pm_score": 2,
"selected": false,
"text": "gets"
}
] | 2022/11/16 | [
"https://Stackoverflow.com/questions/74461587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/848706/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.