qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
74,163,920
<p>I have a problem with this snippet</p> <pre><code>fun main() { val list = MutableList(5) { 4 } println(list) } </code></pre> <p><a href="https://pl.kotl.in/UelOEOTdS?theme=darcula" rel="nofollow noreferrer">this snippet</a> will print <code>[4, 4, 4, 4, 4]</code></p> <p>and</p> <pre><code>fun main() { val list = MutableList(5) { index -&gt; 4 + index } println(list) } </code></pre> <p><a href="https://pl.kotl.in/cs9XXKDW-?theme=darcula" rel="nofollow noreferrer">this snippet</a> will print [4, 5, 6, 7, 8]</p> <p>What i want to ask, and this is might be very very silly. If we using the same snippet as above, is there a way to make a custom list such as <code>[4, 6, 7, 9, 10]</code></p> <p>I try to use <code>[4, 6, 7, 9, 10]</code> or <code>(4, 6, 7, 9, 10)</code> or <code>4, 6, 7, 9, 10</code> or <code>4; 6; 7; 9; 10</code>, it just doesn't work.</p> <p>If I used <code>4; 6; 7; 9; 10</code>, the list will print</p> <pre><code>[10, 10, 10, 10, 10] </code></pre> <p>if anyone care to help, <a href="https://pl.kotl.in/2f47xTqsJ?theme=darcula" rel="nofollow noreferrer">this snippet</a> below it just doesn't work</p> <pre><code>fun main() { val list = MutableList(5) { //[4, 6, 7, 9, 10] //(4, 6, 7, 9, 10) //4, 6, 7, 9, 10 4; 6; 7; 9; 10 } println(list) } </code></pre>
[ { "answer_id": 74163986, "author": "Michael", "author_id": 1524450, "author_profile": "https://Stackoverflow.com/users/1524450", "pm_score": 0, "selected": false, "text": "4, 6, 7, 9, 10" }, { "answer_id": 74164765, "author": "Todd", "author_id": 49746, "author_profil...
2022/10/22
[ "https://Stackoverflow.com/questions/74163920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19990104/" ]
74,163,927
<p>I must upgrade a project written in flutter to compileSdkVersion 33 Since i upgraded, the app crahes at least in simulator. A new flutter project whith compileSdkVersion 33 make no problems, but i can't find the differences in gradle.build files or android manifest.</p> <p>Any ideas?</p> <p>Flutter Version:</p> <pre><code> Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 3.3.5, on macOS 12.6 21G115 darwin-arm, locale de-DE) [βœ“] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [βœ“] Xcode - develop for iOS and macOS (Xcode 14.0.1) [βœ“] Chrome - develop for the web [βœ“] Android Studio (version 2021.3) [βœ“] IntelliJ IDEA Ultimate Edition (version 2022.2.2) [βœ“] VS Code (version 1.72.2) [βœ“] Connected device (3 available) [βœ“] HTTP Host Availability </code></pre> <p>Error:</p> <pre><code>D/FlutterLocationService(13862): Binding to location service. E/AndroidRuntime(13862): FATAL EXCEPTION: main E/AndroidRuntime(13862): Process: de.roegmbh.checkit, PID: 13862 E/AndroidRuntime(13862): java.lang.NoSuchMethodError: No interface method addWindowLayoutInfoListener(Landroid/app/Activity;Lj$/util/function/Consumer;)V in class Landroidx/window/extensions/layout/WindowLayoutComponent; or its super classes (declaration of 'androidx.window.extensions.layout.WindowLayoutComponent' appears in /system_ext/framework/androidx.window.extensions.jar) E/AndroidRuntime(13862): at androidx.window.layout.ExtensionWindowLayoutInfoBackend.registerLayoutChangeCallback(ExtensionWindowLayoutInfoBackend.kt:68) E/AndroidRuntime(13862): at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invokeSuspend(WindowInfoTrackerImpl.kt:52) E/AndroidRuntime(13862): at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:8) E/AndroidRuntime(13862): at androidx.window.layout.WindowInfoTrackerImpl$windowLayoutInfo$1.invoke(Unknown Source:4) E/AndroidRuntime(13862): at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61) E/AndroidRuntime(13862): at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212) E/AndroidRuntime(13862): at androidx.window.java.layout.WindowInfoTrackerCallbackAdapter$addListener$1$1.invokeSuspend(WindowInfoTrackerCallbackAdapter.kt:96) E/AndroidRuntime(13862): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) E/AndroidRuntime(13862): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) E/AndroidRuntime(13862): at android.os.Handler.handleCallback(Handler.java:942) E/AndroidRuntime(13862): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(13862): at android.os.Looper.loopOnce(Looper.java:201) E/AndroidRuntime(13862): at android.os.Looper.loop(Looper.java:288) E/AndroidRuntime(13862): at android.app.ActivityThread.main(ActivityThread.java:7898) E/AndroidRuntime(13862): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(13862): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/AndroidRuntime(13862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) </code></pre>
[ { "answer_id": 74257036, "author": "som-R91", "author_id": 18448760, "author_profile": "https://Stackoverflow.com/users/18448760", "pm_score": 3, "selected": false, "text": "implementation 'androidx.window:window:1.0.0'\nimplementation 'androidx.window:window-java:1.0.0'\n" }, { ...
2022/10/22
[ "https://Stackoverflow.com/questions/74163927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2779037/" ]
74,163,952
<p>I'm using UIKit <strong>not SwiftUI</strong>. I found solutions which all in SwiftUI but not solved my problem.</p> <p>I have a @Published object like: <code>@Published var searchText = &quot;&quot;</code></p> <p>I'm using that @Published object for search functionality like in following function. Also, I'm trying to reach that function outside of corresponding class which is <code>final class MainViewModel</code></p> <pre><code>final class MainViewModel { @Published var searchText = &quot;&quot; //subscribes to the searchText 'Publisher' func searchTextManipulation(searchText: String) { $searchText .debounce(for: .seconds(1.0), scheduler: RunLoop.main) .removeDuplicates() .sink { [weak self] (text) in //(text) is always empty string &quot;&quot; ... </code></pre> <p>I want to use that function parameter <code>searchText: String</code> as <code>$searchText</code> to search with text come from another screen something like:</p> <pre><code>final class MainViewController { let viewModel = MainViewModel() @Published var searchText = &quot;&quot; override func viewDidLoad() { viewModel.searchTextManipulation($searchText: searchText) //but it's not possible. } } </code></pre> <p>Can you show me a workaround for solving that crucial part?</p>
[ { "answer_id": 74257036, "author": "som-R91", "author_id": 18448760, "author_profile": "https://Stackoverflow.com/users/18448760", "pm_score": 3, "selected": false, "text": "implementation 'androidx.window:window:1.0.0'\nimplementation 'androidx.window:window-java:1.0.0'\n" }, { ...
2022/10/22
[ "https://Stackoverflow.com/questions/74163952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4442254/" ]
74,163,958
<p>In R, I'm trying to average a subset of a column based on selecting a certain value (ID) in another column. Consider the example of choosing an ID among 100 IDs, perhaps the ID number being 5. Then, I want to average a subset of values in another column that corresponds to the ID number that is 5. Then, I want to do the same thing for the rest of the IDs. What should this function be?</p>
[ { "answer_id": 74164228, "author": "Panagiotis Togias", "author_id": 6181820, "author_profile": "https://Stackoverflow.com/users/6181820", "pm_score": 1, "selected": false, "text": "dplyr" }, { "answer_id": 74165190, "author": "KacZdr", "author_id": 12382064, "author_...
2022/10/22
[ "https://Stackoverflow.com/questions/74163958", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308626/" ]
74,163,982
<p>I have a rule using files named with a series of numbers from <code>01</code>, <code>02</code>, <code>03</code> ... until <code>12</code> in their file name, and I would need to format them in <code>1</code>, <code>2</code>, <code>3</code>... <code>12</code> for the next step in the analysis.</p> <p>I am sure there is a way to do this with either f-strings or <code>.format()</code>, but I am not sure how to do it within one rule where I also specify the number series with a list.</p> <p>How do I get there?</p> <p>A minimal example (not working):</p> <pre><code>numbers = [&quot;01&quot;, &quot;02&quot;, &quot;03&quot;, &quot;04&quot;, &quot;05&quot;, &quot;06&quot;, &quot;07&quot;, &quot;08&quot;, &quot;09&quot;, &quot;10&quot;, &quot;11&quot;, &quot;12&quot;] starting_folder = &quot;project/temp&quot; rule rename_files: input: f&quot;{starting_folder}/file.{{numbers}}.ext&quot; output: f&quot;{starting_folder}/file.{{{numbers}}:01d}_new.ext&quot; shell: &quot;ln -s {input} {output}&quot; </code></pre> <p>E.g. I would like to get <code>project/temp/file.1_new.ext</code> as the output file path.</p>
[ { "answer_id": 74164228, "author": "Panagiotis Togias", "author_id": 6181820, "author_profile": "https://Stackoverflow.com/users/6181820", "pm_score": 1, "selected": false, "text": "dplyr" }, { "answer_id": 74165190, "author": "KacZdr", "author_id": 12382064, "author_...
2022/10/22
[ "https://Stackoverflow.com/questions/74163982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10798015/" ]
74,164,017
<p>I have a scrollable <code>&lt;div&gt;</code> and I need to prevent the user from scrolling. But at the same time, JavaScript should be allowed to scroll it.</p> <p>Previously, I've tried setting <code>overflow: hidden;</code> but in some browsers/os it didn't let JavaScript scroll. I've tried setting <code>overflow: auto;</code> and hiding the scrollbar and then in JavaScript listening for <code>wheel</code> events and calling <code>preventDefault()</code> but that did nothing. I can't listen for <code>scroll</code> events because then it prevents JavaScript from scrolling too.</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 btn = document.querySelector('button#scroll'); const cnt = document.querySelector('div#container'); btn.addEventListener('click', e =&gt; { cnt.scrollTo(20, 500); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>div#container { width: 400px; height: 400px; overflow-y: auto; scroll-behavior: smooth; -ms-overflow-style: none; scrollbar-width: none; } div#container::-webkit-scrollbar { display: none; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button id="scroll"&gt;Click to scroll&lt;/button&gt; &lt;div id="container"&gt; &lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt; &lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt;&lt;img src="https://p.turbosquid.com/ts-thumb/bK/x6a3nk/nlMteHHm/r1/jpg/1590782525/600x600/fit_q87/f469b1b09d4935ef73b0746eb4b77fbe06b57293/r1.jpg"&gt; &lt;br&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>Any ideas? TYIA</p>
[ { "answer_id": 74164206, "author": "Migats21", "author_id": 9077625, "author_profile": "https://Stackoverflow.com/users/9077625", "pm_score": 3, "selected": true, "text": "overflow-y: hidden" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15584743/" ]
74,164,038
<p>So here's something I don't understand : Every single time you include something in c, you have to do <code>#include &quot;dir/subdir/file.h&quot;</code>. Since the <code>.c</code> file is in the <strong>exact</strong> same place, why do I also have to do <code>gcc main.c dir/subdir/file.c -o main</code> ?</p> <p>It doesn't seem to make sense, every single other language I've used (arguably not that many, but still, several) was able to make sense of imports on its own. Am I missing something ? Is there a way to tell gcc to &quot;just find them yourself&quot; ?</p>
[ { "answer_id": 74164120, "author": "Eric Postpischil", "author_id": 298225, "author_profile": "https://Stackoverflow.com/users/298225", "pm_score": 2, "selected": false, "text": "gcc main.c dir/subdir/file.c -o main" }, { "answer_id": 74166301, "author": "John Bode", "aut...
2022/10/22
[ "https://Stackoverflow.com/questions/74164038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10981696/" ]
74,164,048
<p>I'm currently trying to set up a webdriver, and I just realised the reason it's not working is because I can't get the path to work. Currently, I'm trying basic code:</p> <pre><code>file = &quot;D:\\&quot; if os.path.exists(file): print(True) else: print(False) </code></pre> <p>And the answer is &quot;False&quot;. Now, I do have a D:/ drive on my computer.</p> <p>I tried r&quot;D:&quot;, &quot;D:\&quot;, &quot;D:/&quot;, basically everything I could find in other articles. Has anybody else ever encountered this?</p>
[ { "answer_id": 74164270, "author": "Erik WistrΓΆm", "author_id": 20307906, "author_profile": "https://Stackoverflow.com/users/20307906", "pm_score": 0, "selected": false, "text": "file = \"D:/\"\n" }, { "answer_id": 74164425, "author": "Loxley", "author_id": 19291069, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308673/" ]
74,164,066
<p>I have a string that starts &quot;{{ABC...&quot; and which will also contain a closing brace pair. The problem is that it may also contain nested open/close brace pairs, and may contain further brace pairs after the matching closing pair. E.g. this is possible:</p> <pre><code> {{ABC foo bar {{baz}} {{fred}} foo2}} other text {{other brace pair}} </code></pre> <p>In this case I would want the string up to &quot;foo2}}. I can see how to do this by writing my own recursive function call, but is there a way to match this in a single pass?</p>
[ { "answer_id": 74164270, "author": "Erik WistrΓΆm", "author_id": 20307906, "author_profile": "https://Stackoverflow.com/users/20307906", "pm_score": 0, "selected": false, "text": "file = \"D:/\"\n" }, { "answer_id": 74164425, "author": "Loxley", "author_id": 19291069, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5828291/" ]
74,164,086
<p>Good morning friends, good ... what happens is this: I tried to make a logic so that the setLoaded changes the value of my progress bar, and when the value of it reaches 100, it shows the Modal. But nothing is happening. I wanted when I pressed the play button my ProgressBar to start loading its value, and when I clicked the pause button the value of it would stop at the value it was. Will someone help me please? I've worked very hard, I'm getting discouraged I want activate this through Play button (touchable opacity)</p> <pre><code>import * as React from 'react'; import { useState} from 'react'; import { Text, View, ScrollView, KeyboardAvoidingView, Image, TouchableOpacity } from 'react-native'; import { Entypo, Feather } from 'react-native-vector-icons'; import { Card } from 'react-native-shadow-cards'; import * as Progress from 'react-native-progress'; import { NavigationContainer } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native'; import Modal from 'react-native-modal'; //link redefinir senha //https://account.activedirectory.windowsazure.com/ChangePassword.aspx const taskDetails = () =&gt; { const navigate = useNavigation(); const [showHide, setShowHide] = useState(false); const [modal, setModal] = useState(false); const [progress, setProgress] = useState(0); const [isLoaded, setLoaded] = useState(false); return ( &lt;&gt; { !isLoaded ? &lt;Modal isVisible={modal}&gt; &lt;View style={{ backgroundColor: '#fff', paddingVertical: 20, paddingHorizontal: 20, alignSelf: 'center', borderRadius: 15, height: 480, width: 300}}&gt; &lt;Image source={require('../../assets/images/working-hours(1).png')} style={{alignSelf: 'center', width: 100, height: 100, margin: 10, marginTop: 20}}/&gt; &lt;Text style={{ fontWeight: 'bold', fontSize: 20, textAlign: 'center', padding: 10, }}&gt; {'Eba! \n Task finalizada com sucesso!'} &lt;/Text&gt; &lt;Text style={{textAlign: 'center'}}&gt; {'Suas horas nesta task foram \n lanΓ§adas,volte para a home para \n comeΓ§ar uma nova tarefa!'} &lt;/Text&gt; &lt;Text style={{ textAlign: 'center', color: '#808080', padding: 5, marginBottom: 10 }}&gt; Com isso vocΓͺ ganhou: &lt;/Text&gt; &lt;Image source={require('../../assets/images/grin-stars.png')} style={{ alignSelf: 'flex-start', marginLeft: 75, margin: 5}}/&gt; &lt;Text style={{fontSize: 20, fontWeight: 'bold', textAlign: 'right', marginRight: 95, bottom: 40}}&gt; 10pts &lt;/Text&gt; &lt;Text style={{ textAlign: 'right', fontSize: 12, marginRight: 70, bottom: 45}}&gt; de experiΓͺncia &lt;/Text&gt; &lt;TouchableOpacity style={{ justifyContent: 'center', alignItems: 'center', alignSelf: 'center', marginTop: 20, backgroundColor: '#000000', paddingVertical: 10, borderRadius: 10, padding: 10, width: 250, height: 50, elevation: 8, bottom: 30 }} onPress={() =&gt; setModal(false)}&gt; &lt;Text style={{ color: '#fff', fontWeight: 'bold', alignSelf: 'center', }}&gt; Fechar&lt;/Text&gt; &lt;/TouchableOpacity&gt; &lt;/View&gt; &lt;/Modal&gt; : &lt;Progress.Bar progress={progress} width={200} color={'#A0D800'} backgroundColor={'#ECECEC'} borderColor={'transparent'} height={10} borderRadius={10} style={{alignSelf: 'center'}} bottom={20} /&gt; } &lt;KeyboardAvoidingView style={{ flex: 2, justifyContent: 'center', alignItems: 'center', backgroundColor: '#fff' }}&gt; &lt;ScrollView &gt; &lt;View&gt; &lt;TouchableOpacity&gt; &lt;Card style={{ margin: 20, height: 450, }}&gt; &lt;Feather name={'file-text'} color={'#F2CB1D'} size={20} style={{paddingLeft: 20, top: 20,}}/&gt; &lt;Text style={{paddingLeft: 50}}&gt;Task 59788&lt;/Text&gt; &lt;Entypo name={'controller-record'} style={{paddingLeft: 270, bottom: 14 }} color={'#007ACC'} size={10} /&gt; &lt;Text style={{paddingLeft: 290, bottom: 30}} &gt;Active&lt;/Text&gt; &lt;Text style={{fontSize: 12, paddingLeft: 20, bottom: 15 }}&gt;App corporativo OnlineTeam&lt;/Text&gt; &lt;Text style={{ paddingLeft: 20, fontSize: 20, bottom: 10}}&gt; Criar telas no Figma&lt;/Text&gt; &lt;Text style={{ paddingLeft: 20, fontSize: 12}}&gt; Original Estimate: 4h&lt;/Text&gt; &lt;Text style={{ paddingLeft: 250,bottom: 17, fontSize: 12}}&gt; Completed: 2h&lt;/Text&gt; &lt;Text style={{textAlign: 'left', bottom: 10, fontSize: 10, paddingLeft: 55}}&gt; 0%&lt;/Text&gt; &lt;Progress.Bar progress={progress} width={200} color={'#A0D800'} backgroundColor={'#ECECEC'} borderColor={'transparent'} height={10} borderRadius={10} style={{alignSelf: 'center'}} bottom={20} /&gt; &lt;Text style={{textAlign: 'right', fontSize: 10,bottom: 35, paddingRight: 45}}&gt; 100%&lt;/Text&gt; &lt;View style={{ borderBottomColor: '#ECECEC', borderBottomWidth: 1, alignSelf: 'center', marginBottom: 20, width: 300, }} /&gt; &lt;Text style={{fontSize: 15, color: &quot;#A0D800&quot;, paddingLeft: 20, }}&gt; Detalhes da task&lt;/Text&gt; &lt;Text style={{color: &quot;#808080&quot;, alignContent: 'center', padding: 15}}&gt; Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae enim nisl. Proin iaculis eu felis sed cursus. In facilisis eleifend nisl, at efficitur diam placerat ut. Aliquam neque nulla, convallis a eleifend eget, elementum ut quam. Aliquam gravida mauris auctor, gravida nisi vel, lobortis tellus. Donec ac velit vulputate, dictum neque vitae, tempus velit. Donec placerat in mauris vel porttitor. Mauris viverra ante a suscipit gravida. Mauris fringilla erat felis, eu facilisis erat laoreet ultrices. &lt;/Text&gt; &lt;/Card&gt; &lt;/TouchableOpacity&gt; &lt;TouchableOpacity style={{ borderRadius: 10, alignItems: &quot;center&quot;, backgroundColor: &quot;#A0D800&quot;, height: 50, width: 50,marginLeft: 25 }} onPress = { () =&gt; setLoaded(isLoaded) }&gt; &lt;Image source={require('../../assets/images/play(1).png')} style={{alignSelf: 'center',padding: 5, marginTop: 15}}/&gt; &lt;/TouchableOpacity&gt; &lt;TouchableOpacity style={{ backgroundColor: &quot;#000000&quot;, height: 50, width: 300,marginLeft: 20, borderRadius: 10, alignSelf: 'flex-end', bottom: 50, marginRight: 20 }}&gt; &lt;Text style={{textAlign: 'center', color: '#fff', fontSize: 16, fontWeight: 'bold', paddingTop: 10, margin: 5 }}&gt; Pausar task &lt;/Text&gt; &lt;Image source={require('../../assets/images/pause.png')} style={{alignSelf: 'flex-start', marginRight: 15, bottom: 25, marginLeft: 75}}/&gt; &lt;/TouchableOpacity&gt; &lt;/View&gt; &lt;/ScrollView&gt; &lt;/KeyboardAvoidingView&gt; &lt;/&gt; ) } export default taskDetails; </code></pre>
[ { "answer_id": 74164270, "author": "Erik WistrΓΆm", "author_id": 20307906, "author_profile": "https://Stackoverflow.com/users/20307906", "pm_score": 0, "selected": false, "text": "file = \"D:/\"\n" }, { "answer_id": 74164425, "author": "Loxley", "author_id": 19291069, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164086", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20056289/" ]
74,164,090
<pre><code>indepgroupl = ['numerical', 'categorical'] depgroupl = [&quot;numerical&quot;, &quot;categorical&quot;, &quot;factors&quot;, &quot;count&quot;] for i in indepgroupl: for j in depgroupl: if i == 'categorical': if i == 'numerical': if j == 'numerical': print(&quot;utter_indepnumcat_depnum&quot;) elif j == 'categorical': print(&quot;utter_indepnumcat_depcat&quot;) elif j == 'time to event': print(&quot;utter_indepnumcat_deptimetoevent&quot;) if j == 'numerical': print(&quot;utter_indep2cat_depnum&quot;) elif i == 'factors': if j == 'count': print(&quot;utter_indepfac_depcount&quot;) elif j == 'numerical': print(&quot;utter_indepfac_depnum&quot;) </code></pre> <p>Is there a more elegant way to write this if/elif/else loop? Can I use list comprehension for this?</p>
[ { "answer_id": 74164270, "author": "Erik WistrΓΆm", "author_id": 20307906, "author_profile": "https://Stackoverflow.com/users/20307906", "pm_score": 0, "selected": false, "text": "file = \"D:/\"\n" }, { "answer_id": 74164425, "author": "Loxley", "author_id": 19291069, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16277480/" ]
74,164,142
<p>I want to integrate Keycloak with spring boot application. The problem is that at the end, I got 403 forbidden error when calling the protected endpoints.</p> <p>Following is my decoded JWT token, which is issued by Keycloak. I have a client, which is named clientApp1, and a realm role, which is named clientApp1User and mapped to the created user. Following is my decoded JWT token:</p> <pre><code>{ alg: &quot;RS256&quot;, typ: &quot;JWT&quot;, kid: &quot;ZWDbgcSI8nD2Yq4LA6hxYcsTbnf6y6Zj8PKyUobE_qE&quot; }. { exp: 1666444432, iat: 1666444132, jti: &quot;e6883855-ef20-4fac-95dd-8f13bd0ae552&quot;, iss: &quot;http://localhost:12500/auth/realms/sampleRealm&quot;, aud: &quot;account&quot;, sub: &quot;80e1e45f-49fb-4a5a-9a60-b0057d291c53&quot;, typ: &quot;Bearer&quot;, azp: &quot;clientApp1&quot;, session_state: &quot;c22af762-7be9-4150-94d5-8bd35065ac57&quot;, acr: &quot;1&quot;, allowed-origins: [ &quot;http://localhost:11501&quot; ], realm_access: { roles: [ &quot;clientApp1User&quot;, &quot;offline_access&quot;, &quot;uma_authorization&quot;, &quot;default-roles-samplerealm&quot; ] }, resource_access: { account: { roles: [ &quot;manage-account&quot;, &quot;manage-account-links&quot;, &quot;view-profile&quot; ] } }, scope: &quot;email profile&quot;, sid: &quot;c22af762-7be9-4150-94d5-8bd35065ac57&quot;, email_verified: false, name: &quot;user1FirstName User1LastName&quot;, preferred_username: &quot;user1&quot;, given_name: &quot;user1FirstName&quot;, family_name: &quot;User1LastName&quot; }. [signature] </code></pre> <p>Moreover, here is my pom.xml file:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;parent&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt; &lt;version&gt;2.7.5&lt;/version&gt; &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt; &lt;/parent&gt; &lt;groupId&gt;com.example&lt;/groupId&gt; &lt;artifactId&gt;ResourceServerSample&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;name&gt;ResourceServerSample&lt;/name&gt; &lt;description&gt;ResourceServerSample&lt;/description&gt; &lt;properties&gt; &lt;java.version&gt;17&lt;/java.version&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-oauth2-resource-server&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.security&lt;/groupId&gt; &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>Since, I want to use Security annotations to secure my end points I have set the security configuration as following:</p> <pre><code>@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity( prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http .cors() .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and().authorizeRequests() .anyRequest().permitAll() .and().oauth2ResourceServer().jwt(); http.csrf().disable(); return http.build(); } </code></pre> <p>Finally, in order to protect my endpoints I have used annotations like following:</p> <pre><code>@RestController public class TestControllers { // Public endpoint @GetMapping(&quot;/welcome&quot;) public ResponseEntity&lt;String&gt; welcome() { return ResponseEntity.status(HttpStatus.OK).body(&quot;Welcome to the unprotected endpoint&quot;); } // @RolesAllowed(&quot;clientApp1User&quot;) // @Secured(&quot;clientApp1User&quot;) @PreAuthorize(&quot;hasAuthority('clientApp1User')&quot;) @GetMapping(&quot;/clientApp1User&quot;) public ResponseEntity&lt;String&gt; clientApp1User() { return ResponseEntity.status(HttpStatus.OK).body(&quot;clientApp1User protected endpoint sends its regards&quot;); } @PreAuthorize(&quot;hasAuthority('SCOPE_email')&quot;) @GetMapping(&quot;/testScope&quot;) public ResponseEntity&lt;String&gt; testScope() { return ResponseEntity.status(HttpStatus.OK).body(&quot;testScope protected endpoint sends its regards&quot;); } } </code></pre> <p>The problem that I face is that the endpoint, which is protected with @RolesAllowed(&quot;clientApp1User&quot;) or @Secured(&quot;clientApp1User&quot;) or @PreAuthorize(&quot;hasAuthority('clientApp1User')&quot;) returns 403 forbidden, when it's called with a valid access token.</p> <p>On the other hand endpoints with annotations like @PreAuthorize(&quot;hasAuthority('SCOPE_email')&quot;) or @PreAuthorize(&quot;hasAuthority('SCOPE_profile')&quot;) return 200 Ok.</p> <p>I believe spring boot can not accurately parse the JWT token and only excepts values in scope claim with the prefix &lt;SCOPE_&gt; and as an authority.</p> <p>Can any one help me to fix the problem and use the <strong>RolesAllowed/Secured/PreAuthorize</strong> annotations to secure the endpoint with <strong>declared roles in realm_access and resource_access claims</strong>?</p>
[ { "answer_id": 74164383, "author": "ch4mp", "author_id": 619830, "author_profile": "https://Stackoverflow.com/users/619830", "pm_score": 2, "selected": true, "text": "Converter<Jwt, AbstractAuthenticatonToken>" }, { "answer_id": 74164767, "author": "kesaven", "author_id":...
2022/10/22
[ "https://Stackoverflow.com/questions/74164142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19584950/" ]
74,164,180
<p>This works: (A)</p> <pre class="lang-cpp prettyprint-override"><code>class Foo { public: const bool b; constexpr ~Foo() = default; constexpr Foo(const bool b) : b(b) {}; }; class Bar { public: static constexpr Foo tru { true };//Foo is complete type }; </code></pre> <p>This fails to compile: (B)</p> <pre class="lang-cpp prettyprint-override"><code>class Bar { public: class Foo { public: const bool b; constexpr ~Foo() = default; constexpr Foo(const bool b) : b(b) {}; }; static constexpr Foo tru { true };//undefined constructor 'Foo' cannot be used }; </code></pre> <p>error:</p> <pre><code>$ clang++ --std=c++20 -D_POSIX_C_SOURCE=200112L -fPIC -g -Werror -Wall LiteralStruct.cpp -o LiteralStruct LiteralStruct.cpp:9:24: error: constexpr variable 'tru' must be initialized by a constant expression static constexpr Foo tru { true }; ^~~~~~~~~~~~ LiteralStruct.cpp:9:24: note: undefined constructor 'Foo' cannot be used in a constant expression LiteralStruct.cpp:7:15: note: declared here constexpr Foo(const bool b) : b(b) {}; ^ 1 error generated. </code></pre> <p>This also fails to compile, but gives a good reason: (C)</p> <pre class="lang-cpp prettyprint-override"><code>class Foo { public: const bool b; constexpr ~Foo() = default; constexpr Foo(const bool b) : b(b) {}; static constexpr Foo tru { true };//Foo is NOT a complete type }; </code></pre> <p>error:</p> <pre><code>$ clang++ --std=c++20 -D_POSIX_C_SOURCE=200112L -fPIC -g -Werror -Wall LiteralStruct.cpp -o LiteralStruct LiteralStruct.cpp:6:24: error: constexpr variable cannot have non-literal type 'const Foo' static constexpr Foo tru { true }; ^ LiteralStruct.cpp:6:24: note: incomplete type 'const Foo' is not a literal type LiteralStruct.cpp:1:7: note: definition of 'Foo' is not complete until the closing '}' class Foo { </code></pre> <p>version:</p> <pre><code>clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu </code></pre> <p>C failing makes sense and has a good error message. B feels like it should work, Foo and all it's contents should be complete and defined at that point in the file. Basically my question is: do I report a clang bug that B should work, or a feature request for a better error message? If Foo is truly not complete by virtue of being a member of an incomplete type, then I should think the error message should be similar to that of C.</p> <p><em>Edit:</em></p> <p>I just upgraded clang to the bleeding edge (<code>16.0.0-++20221021052626+7dd2f4bc009d-1~exp1~20221021172738.418</code>) and got the same result.</p>
[ { "answer_id": 74164830, "author": "user17732522", "author_id": 17732522, "author_profile": "https://Stackoverflow.com/users/17732522", "pm_score": 3, "selected": true, "text": "Foo" }, { "answer_id": 74164872, "author": "Jason Liam", "author_id": 12002570, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11529348/" ]
74,164,199
<p>I'm having some trouble figuring out a problem in my code. Basically, I have a contract that represents games using structs. I store some details there like the gameId, required buyin to play, etc. But I also want to store player addresses that interact with that specific game: (in an array in the game struct, preferably).</p> <p>I try to append them to the array on initialization but that doesn't work - I assume due to the static length of the array. I've read online about incrementing the length of the players array as they are not dynamic, but honestly I'm not sure how to implement that in this case.</p> <p>Here is my code for the Game struct:</p> <pre><code>struct Game { address host; // Establishes host function access uint gameId; // Allows different games to be played concurrently uint buyinRequirement; // To establish minimum buyin amount for a game uint etherWithdrawalReqs; // Tracks # of ether in total from requests. If &gt;/&lt; than contract balance, throws error uint gamePot; // Tracks how much ether is in the game's pot uint8 tableWithdrawalReqs; // Tracks how many players have requested a withdrawal uint8 playerCount; // Tracks # of of players in a game uint8 verifiedWithdrawalReqs; // Tracks # of verifs that withdrawal requests are valid bool endedBuyin; // Host function to end buyin stage address[] playerList; // Stores player addresses } </code></pre> <p>Here is my attempt to initialize the struct:</p> <pre><code>function initializeGame(string memory name, uint buyinReq) public payable { idToGame[gameNumber] = Game(msg.sender, gameNumber, buyinReq, 0, 0, 0, 0, 0, false, playerList.push(msg.sender)); games.push(idToGame[gameNumber]); } </code></pre> <p>This is the error I get:</p> <pre><code> DeclarationError: Undeclared identifier. --&gt; contracts/YourContract.sol:104:93: | 104 | idToGame[gameNumber] = Game(msg.sender, gameNumber, buyinReq, 0, 0, 0, 0, 0, false, playerList.push(msg.sender)); | ^^^^^^^^^^ Error HH600: Compilation failed </code></pre> <p>Ultimately, I just need to track addresses tied to a specific game so I can render those addresses to the front end with some other information. If there is an easier way to do this and I'm just overlooking something due to tunnel vision, I'm all ears for alternative solutions.</p> <h2>Edit</h2> <p>Shout out to 7Ony for the response!</p> <p>Here is my code now:</p> <pre><code>function initializeGame(string memory name, uint buyinReq) public payable isNotInGame { require(initFee == .001 ether, &quot;In order to prevent spam games that never resolve, each game initialization will cost ether.&quot;); playerInfo[msg.sender] = Player(name, gameNumber, 0, 0, false, false, false, false, true); address[] memory add; idToGame[gameNumber] = Game(msg.sender, gameNumber, buyinReq, 0, 0, 0, 0, 0, false, true, add); idToGame[gameNumber].playerList.push(msg.sender); games.push(idToGame[gameNumber]); incGameNumber(); addFeesPending(); } </code></pre> <p>There are no errors when I compile this code, however when I attempt to render the Game to my front end via ethersjs, it's like the array was never created:</p> <pre><code>0x59D101AD9DdeA84C0e11DA137000Dd91A0b20c79,1,1000000000000000000,0,1000000000000000000,0,1,0,false,true (cuts off the playerList array, which should be the very last element) </code></pre> <p>Console-logged output:</p> <p><a href="https://i.stack.imgur.com/TS1J2.png" rel="nofollow noreferrer">Console-logged image of Game struct</a></p> <p>Am I doing something wrong here?</p> <h2>Edit 2</h2> <p>Alright, here is my getter function:</p> <pre><code>function getPlayers(uint inputId) external returns (address[] memory playerList) { playerList = games[inputId].playerList; } </code></pre> <p>As a reminder, playerList is the array I have located inside the Game struct and games holds those structs. As of now, this is what it looks like getPlayers is returning:</p> <pre><code> {&quot;type&quot;:2,&quot;chainId&quot;:31337,&quot;nonce&quot;:32,&quot;maxPriorityFeePerGas&quot;:{&quot;type&quot;:&quot;BigNumber&quot;,&quot;hex&quot;:&quot;0x59682f00&quot;},&quot;maxFeePerGas&quot;:{&quot;type&quot;:&quot;BigNumber&quot;,&quot;hex&quot;:&quot;0x59b61d36&quot;},&quot;gasPrice&quot;:null,&quot;gasLimit&quot;:{&quot;type&quot;:&quot;BigNumber&quot;,&quot;hex&quot;:&quot;0x6f8c&quot;},&quot;to&quot;:&quot;0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0&quot;,&quot;value&quot;:{&quot;type&quot;:&quot;BigNumber&quot;,&quot;hex&quot;:&quot;0x00&quot;},&quot;data&quot;:&quot;0x460e20490000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;accessList&quot;:[],&quot;hash&quot;:&quot;0x221b93ed95fdc65e07a340a8e099e0b8e3600a0b34538825462d7dbbff400a89&quot;,&quot;v&quot;:0,&quot;r&quot;:&quot;0xbb258e1b11ed29ea57b12c6336f73572f4bf7c7ad13415dc6af19895ff628b54&quot;,&quot;s&quot;:&quot;0x0e09991ebb19abdc6359f847b35e74d3358d8d43460f9d5b55289d77f2745a5d&quot;,&quot;from&quot;:&quot;0x59D101AD9DdeA84C0e11DA137000Dd91A0b20c79&quot;,&quot;confirmations&quot;:0} </code></pre> <p>In this instance, I had it so there should be both the account address of <code>0x59D101AD9DdeA84C0e11DA137000Dd91A0b20c79</code> and <code>0xd8098C8D6D474a8C7aA3eFa076C1695DcBc6DD4F</code> in the playerList, but neither show up.</p> <p>Unless I am not seeing something that you are, the getter I retrofitted over from the previous question does not seem to be outputting what I expected it to.</p>
[ { "answer_id": 74164830, "author": "user17732522", "author_id": 17732522, "author_profile": "https://Stackoverflow.com/users/17732522", "pm_score": 3, "selected": true, "text": "Foo" }, { "answer_id": 74164872, "author": "Jason Liam", "author_id": 12002570, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19228115/" ]
74,164,209
<p>How to get RedisInsight working with <code>PersistentVolumeClaim</code>s?</p> <p>I installed RedisInsight following the <a href="https://docs.redis.com/latest/ri/installing/install-k8s/" rel="nofollow noreferrer">docs</a> and the Pod starts normally and is available via the created Service, if the <code>deployment.yaml</code> uses <code>emptyDir</code>. Therefore, my question differs from <a href="https://stackoverflow.com/questions/62714925/redisinsights-with-persistent-volume-in-kubernetes">redisinsights-with-persistent-volume-in-kubernetes</a>, where the Service was the issue.</p> <p>However, if I add a <code>peristentVolumeClaim</code> the Pod starts and data is added to the mounted directory (i.e., it is an nfs share, with mod 777 and user/group 1001:1001 ownership), but RedisInsight is not accessible anymore (local on the Pod and externally via the Service).</p> <p>I used the similar <code>yaml</code> files for other deployments and there they worked as expected.</p> <p>The RedisInsight logs are empty.</p> <p>deployment.yaml</p> <pre class="lang-yaml prettyprint-override"><code> apiVersion: apps/v1 kind: Deployment metadata: labels: app: redis-insight name: redis-insight namespace: default spec: replicas: 1 selector: matchLabels: app: redis-insight template: metadata: labels: app: redis-insight spec: containers: - image: redislabs/redisinsight:latest name: redis-insight env: - name: RIHOST value: 0.0.0.0 - name: RIPORT value: &quot;8001&quot; - name: RIHOMEDIR value: /db - name: RILOGDIR value: /db volumeMounts: - name: db mountPath: /db ports: - containerPort: 8001 name: redis-ui-port volumes: - name: db # emptyDir: {} persistentVolumeClaim: claimName: pvc-nfs-redis-insight </code></pre> <p>service.yaml</p> <pre class="lang-yaml prettyprint-override"><code>apiVersion: v1 kind: Service metadata: name: redis-insight-service-loadbalancer spec: type: LoadBalancer selector: app: redis-insight ports: - port: 8001 targetPort: 8001 protocol: TCP name: redis-ui-port </code></pre> <p>persistent-volume-claim.yaml</p> <pre class="lang-yaml prettyprint-override"><code>apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-nfs-redis-insight spec: storageClassName: nfs accessModes: - ReadWriteMany resources: requests: storage: 10Gi </code></pre> <p>persistent-volume.yaml</p> <pre class="lang-yaml prettyprint-override"><code> apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs-redis-insight labels: type: nfs spec: storageClassName: nfs capacity: storage: 10Gi accessModes: - ReadWriteMany nfs: path: /srv/redis-insight/ server: nfs.local readOnly: false </code></pre> <p>data dir on nfs-server (exported as <code>srv/redis-insight</code>):</p> <pre class="lang-bash prettyprint-override"><code>/mnt/redis-insight$ ls -aln total 24 drwxrwxrwx 6 1001 1001 4096 Okt 22 15:17 . drwxr-xr-x 6 1000 1000 4096 Okt 22 15:16 .. drwxr-xr-x 2 1001 1001 4096 Okt 22 15:17 bulk_operation drwxr-xr-x 2 1001 1001 4096 Okt 22 15:17 dropbox drwxr-xr-x 2 1001 1001 4096 Okt 22 15:17 profiler_logs -rw-r--r-- 1 1001 1001 0 Okt 22 15:17 queries.log -rw-r--r-- 1 1001 1001 0 Okt 22 15:17 redisinsight.db -rw-r--r-- 1 1001 1001 0 Okt 22 15:17 redisinsight.log drwxr-xr-x 2 1001 1001 4096 Okt 22 15:17 rsnaps </code></pre>
[ { "answer_id": 74164830, "author": "user17732522", "author_id": 17732522, "author_profile": "https://Stackoverflow.com/users/17732522", "pm_score": 3, "selected": true, "text": "Foo" }, { "answer_id": 74164872, "author": "Jason Liam", "author_id": 12002570, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13095767/" ]
74,164,217
<p>How do I use env variable defined inside deployment? For example, In yaml file dow below I try to use env CONT_NAME for setting container name, but it does not succeed. Could you help please with it, how to do it?</p> <pre><code>apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: $CONT_NAME image: nginx:1.7.9 env: - name: CONT_NAME value: nginx ports: - containerPort: 80 </code></pre>
[ { "answer_id": 74164830, "author": "user17732522", "author_id": 17732522, "author_profile": "https://Stackoverflow.com/users/17732522", "pm_score": 3, "selected": true, "text": "Foo" }, { "answer_id": 74164872, "author": "Jason Liam", "author_id": 12002570, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19199709/" ]
74,164,219
<p>I need to express that a reference to a certain type parameter can be converted to a reference to another one.</p> <p>Example:</p> <pre class="lang-rust prettyprint-override"><code>trait TestTrait {} struct TestStruct {} impl TestTrait for TestStruct {} fn test&lt;Trait: ?Sized, Type&gt;(object: &amp;Type) -&gt; &amp;Trait where ... { object } fn call_test() { let object = TestStruct{}; let t = test::&lt;dyn TestTrait, TestStruct&gt;(&amp;object); } </code></pre> <p>What do I need to put in the where clause?</p> <p>EDIT: I don't want to be implementing From, AsRef, etc. I've considered those.</p>
[ { "answer_id": 74164830, "author": "user17732522", "author_id": 17732522, "author_profile": "https://Stackoverflow.com/users/17732522", "pm_score": 3, "selected": true, "text": "Foo" }, { "answer_id": 74164872, "author": "Jason Liam", "author_id": 12002570, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/104104/" ]
74,164,263
<p>The animation works but I cannot get the <code>sidebar</code> to disappear off-canvas before the animation starts. The <code>sidebar</code> is always there. How to get the <code>sidebar</code> hidden in the left and only appear with the animation, that is when you click <code>Slide</code>? I tried <code>display: none</code> but then the animation does not work anymore.</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>input+label+#sidebar { position: fixed; } input:checked+label+#sidebar { height: 100%; width: 100%; animation: appear 1s; } @keyframes appear { from { right: 1000px; } to { right: 0; } }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="checkbox" id="slide" name="slide" /&gt; &lt;label for="slide"&gt;Slide&lt;/label&gt; &lt;nav id="sidebar"&gt; &lt;ul&gt; &lt;li&gt;One&lt;/li&gt; &lt;li&gt;Two&lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;li&gt;Four&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74164353, "author": "Andrei Fedorov", "author_id": 6641198, "author_profile": "https://Stackoverflow.com/users/6641198", "pm_score": 1, "selected": false, "text": "#sidebar {\n transform: translateX(-1000px);\n}\n\ninput:checked~#sidebar {\n height: 100%;\n width: 100%;...
2022/10/22
[ "https://Stackoverflow.com/questions/74164263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19674442/" ]
74,164,264
<p>As per the Riverpod documentation, asynchronously we use ref.read such as inside a function and for synchronous code, we use ref.watch such as inside the build method.</p> <p>Once I press a button, the function with ref.read will fire up and it will be for only one time. Here, I should use ref.watch as it is now inside build method and with onPressed it will be ref.read</p> <p>Case 1:</p> <pre><code>// Bad practice // Documentation says, &quot;DON'T use ref.read inside the build method&quot;. final counterProvider = StateProvider((ref) =&gt; 0); Widget build(BuildContext context, WidgetRef ref) { StateController counter = ref.read(counterProvider.notifier); return ElevatedButton( onPressed: () =&gt; counter.state++, child: const Text('button'), ); } </code></pre> <p>Case 2:</p> <pre><code>// Good Practice ElevatedButton( onPressed: () =&gt; ref.read(counterProvider.notifier).state++, child: const Text('button'), ), </code></pre> <p>Case 3:</p> <pre><code>// Good Practice Widget build(BuildContext context, WidgetRef ref) { StateController counter = ref.watch(counterProvider.notifier); return ElevatedButton( onPressed: () =&gt; counter.state++, child: const Text('button'), ); } </code></pre> <p>In all 3 cases, code remains asynchronous since it is called only when the button is pressed then why is case1 bad and case 3 good practice?</p>
[ { "answer_id": 74164373, "author": "Michael Soliman", "author_id": 13478605, "author_profile": "https://Stackoverflow.com/users/13478605", "pm_score": 1, "selected": false, "text": "ref.read" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18265188/" ]
74,164,277
<p>I have hundreds of thousands of files with several hundreds of thousands of lines in each of them.</p> <pre><code>2022-09-19/SALES_1.csv:CUST1,US,2022-09-19,43.31,17.56,47.1,154.48,154. 114 2022-09-20/SALES_2.csv:CUST2,NA,2022-09-20,12.4,16.08,48.08,18.9,15.9,3517 </code></pre> <p>The lines may have different number of fields. NO matter how many fields are present, I'm wanting to extract just the last 7 fields.</p> <p>I'm trying with cut &amp; awk but, have been only able to prit a range of fields but not last 'n' fields.</p> <p>Please could I request guidance.</p>
[ { "answer_id": 74164331, "author": "karakfa", "author_id": 1435869, "author_profile": "https://Stackoverflow.com/users/1435869", "pm_score": 3, "selected": true, "text": "$ rev file | cut -d, -f1-7 | rev\n" }, { "answer_id": 74164346, "author": "Ed Morton", "author_id": ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5366075/" ]
74,164,279
<p>Having a dataframe like this:</p> <pre><code>data.frame(id = c(1,2,3), date1 = c(&quot;2014-Dec 2018&quot;,&quot;2009-2010&quot;,&quot;Jan 2009-Aug 2010&quot;), date2 = c(&quot;Feb 2016-Dec 2018&quot;,&quot;2014-Dec 2018&quot;,&quot;Oct 2013-Dec 2018&quot;)) </code></pre> <p>How is it possible to keep rows which contain in any column year without month, months have 3 letters.</p> <p>Example output:</p> <pre><code>data.frame(id = c(1,2), date1 = c(&quot;2014-Dec 2018&quot;,&quot;2009-2010&quot;), date2 = c(&quot;Feb 2016-Dec 2018&quot;,&quot;2014-Dec 2018&quot;)) </code></pre>
[ { "answer_id": 74164345, "author": "Anoushiravan R", "author_id": 14314520, "author_profile": "https://Stackoverflow.com/users/14314520", "pm_score": 3, "selected": true, "text": "library(dplyr)\n\ndf %>%\n filter(!if_all(!id, ~ grepl('^[A-Z][a-z]{2}\\\\s+', .x)))\n\n id da...
2022/10/22
[ "https://Stackoverflow.com/questions/74164279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20224217/" ]
74,164,300
<p>So I'm doing something stupid in my class solution because I am expecting a number but I get a zero. The code is as follows:</p> <pre><code>class Spel { private int _nummer1; public int Nummer1 { get { return _nummer1; } set { _nummer1 = value; } } private int _nummer2; public int Nummer2 { get { return _nummer2; } set { _nummer2 = value; } } private int _nummer3; public int Nummer3 { get { return _nummer3; } set { _nummer3 = value; } } private int _punten; public int Punten { get { return _punten; } set { _punten = value; bepaal(); } } public void bepaal() { Random rnd = new Random(); _nummer1 = rnd.Next(1, 4); _nummer2 = rnd.Next(1, 4); _nummer3 = rnd.Next(1, 4); if (_nummer1 == _nummer2 &amp;&amp; _nummer2 == _nummer3 &amp;&amp; _nummer1 == _nummer3) { _punten = 10; } else if (_nummer1 == _nummer2 &amp;&amp; _nummer2 == _nummer3) { _punten = 5; } else if (_nummer1 == _nummer2 &amp;&amp; _nummer1 == _nummer3) { _punten = 5; } else if (_nummer2 == _nummer3 &amp;&amp; _nummer1 == _nummer3) { _punten = 5; } } </code></pre> <p>I think the fault is in the area where I give the 'nummer' a random number. Here is the code where I call the class with a controller:</p> <pre><code>public class Controller { private Spel spl = new Spel(); public int getNummer1() { return spl.Nummer1; } </code></pre> <p>In the next code I'm using the controller to bring up the class:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { teller++; label1.Text = spl.getNummer1().ToString(); .... </code></pre> <p>I don't know where the fault is so, can someone help me?</p>
[ { "answer_id": 74164362, "author": "Erik WistrΓΆm", "author_id": 20307906, "author_profile": "https://Stackoverflow.com/users/20307906", "pm_score": 1, "selected": false, "text": "public class Class1\n {\n public int Number {get; set;} = 10;\n }\n" }, { "answer_id": 7...
2022/10/22
[ "https://Stackoverflow.com/questions/74164300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308853/" ]
74,164,315
<p>I am trying to write an app like IMDB in rails.</p> <p>I have created the Movie model. Every movie has many movie recommendations (which are also instances of Movie).</p> <p>I don't know how to add the &quot;has_many&quot; association, how to write the migration file or how to add recommended movies to each movie.</p>
[ { "answer_id": 74169096, "author": "Paarth Agrawal", "author_id": 15064432, "author_profile": "https://Stackoverflow.com/users/15064432", "pm_score": 0, "selected": false, "text": "create_table :student do |t|\n t.references :class, foreign_key: true\nend\n" }, { "answer_id": 741...
2022/10/22
[ "https://Stackoverflow.com/questions/74164315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19785930/" ]
74,164,316
<p>I wanted a function to control and change a vector in rust. Here is a simplified version:</p> <pre class="lang-rust prettyprint-override"><code>fn foo(vec: &amp;mut Vec&lt;i32&gt;) { for (i, element) in vec.iter().enumerate() { // Some checks here vec[(*element) as usize] = i as i32; } } fn main() { let mut bar: Vec&lt;i32&gt; = vec![1, 0, 2]; foo(&amp;mut bar); } </code></pre> <p>This code does not compile because there is both an immutable and a mutable borrow of <code>vec</code> in <code>foo</code>. I tried getting around this by copying <code>vec</code> to a separate copy, which didn't work and also wouldn't have been very pretty. What is the correct way to do this?</p>
[ { "answer_id": 74164385, "author": "isaactfa", "author_id": 11423104, "author_profile": "https://Stackoverflow.com/users/11423104", "pm_score": 2, "selected": false, "text": "Vec" }, { "answer_id": 74164502, "author": "peterulb", "author_id": 6874359, "author_profile"...
2022/10/22
[ "https://Stackoverflow.com/questions/74164316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15209993/" ]
74,164,330
<p>I am new to problem-solving. I found a code for finding the <code>nth Fibonacci number</code>. But I am confused about the work of some variables.</p> <pre><code>var fibonacci = function (n) { let prev = 0, cur = 1, temp; for (let i = 1; i &lt; n; i++) { temp = cur; cur = cur + prev; prev = temp; } return cur; }; </code></pre> <p>can you describe what the <code>temp</code> <code>cur</code> and <code>prev</code> variable is doing? especially the <code>temp</code> variable. <strong>Thank you!</strong></p>
[ { "answer_id": 74164421, "author": "link2name", "author_id": 16087645, "author_profile": "https://Stackoverflow.com/users/16087645", "pm_score": 0, "selected": false, "text": "cur = cur + prev" }, { "answer_id": 74164490, "author": "Andrew Parks", "author_id": 5898421, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164330", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17325120/" ]
74,164,332
<p>I am pretty new to vue.js . I have a minor issue to fix and need one help.</p> <p>So I have one vue.js file which has an existing method let's say,</p> <pre><code>doSomething(){ //updates few properties here } </code></pre> <p>Now I have a list/array <strong>computed</strong> property let's say <strong>pageUser()</strong> , and I want to invoke doSomething whenever <code>pageUser.length == 0</code>.</p> <p>How we can achieve this in <strong>vue.js</strong> , can we use v-if in any tag and from there can invoke the method, or what are the other ways to do this.</p>
[ { "answer_id": 74164417, "author": "Nikola Pavicevic", "author_id": 11989189, "author_profile": "https://Stackoverflow.com/users/11989189", "pm_score": 3, "selected": true, "text": "const app = Vue.createApp({\n data() {\n return {\n user: [{id: 1}, {id: 2}],\n };\n },\n co...
2022/10/22
[ "https://Stackoverflow.com/questions/74164332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5949783/" ]
74,164,336
<p>I want to build an algorithm who convert AM/PM to the 24hours format. It's not finished, but the code I have so far is behaving strangely.</p> <p>When I give the input <code>&quot;25:05:45PM&quot;</code>, it should enter the first branch of the first <code>if</code> statement, but should <em>not</em> enter the second <code>if</code> statement. I've checked the condition, and it's definitely <code>false</code>. My brain is melting.</p> <p>Here is 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>function conversionTime(s) { if (s.includes('PM')) { let temp = s.slice(0, 8).split(':'); if (temp[0] &gt;= 01 &amp;&amp; temp[0] &lt;= 12); { temp[0] = Number(temp[0]) + 12; return temp.join(':') } } else if (s.includes('AM')) { let temp2 = s.slice(0, 8).split(':'); return temp2 } } console.log(conversionTime("25:05:45PM"))</code></pre> </div> </div> </p>
[ { "answer_id": 74164446, "author": "wizzwizz4", "author_id": 5223757, "author_profile": "https://Stackoverflow.com/users/5223757", "pm_score": 3, "selected": true, "text": "if (temp[0] >= 01 && temp[0] <= 12);\n" }, { "answer_id": 74164709, "author": "Mister Jojo", "autho...
2022/10/22
[ "https://Stackoverflow.com/questions/74164336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16583686/" ]
74,164,386
<h2>Issue:</h2> <p>I created a web app in Flutter and deployed to the web using GitHub Pages. It worked on the first release (the page was functional, all content worked), and then I made some updates and attempted to redeploy and the web page now shows up blank. The screen is white. No content is displayed, and it only shows the generic title and favicon.</p> <p>I am able to view the page normally when I run directly from Android Studio using Chrome. It is only when I deploy to the GitHub Pages that the screen is blank.</p> <p>My process:</p> <ul> <li>Released using <code>flutter build web</code> command and also tried <code>flutter build web --release</code> and other combinations</li> <li>Moving code from Android Studio to GitHub Pages by uploading the contents of the build &gt; web folder to the main branch</li> </ul> <h2>What I have tried:</h2> <p>Every combination of modifying removing the line that has been suggested in similar questions.</p> <ul> <li>Removing <code>&lt;base href=...&gt;</code></li> <li><code>&lt;base href=&quot;/&quot;&gt;</code></li> <li><code>&lt;base href=&quot;./&quot;&gt;</code></li> <li><code>&lt;base href=&quot;/homepage/&quot;&gt;</code></li> <li>Removing and replacing the entire GitHub repo</li> <li>Building using <code>flutter build web --web-renderer html</code></li> <li>Removing all complex code from the app itself, leaving just a banner</li> </ul> <p>I have read every StackOverflow and GitHub page on this topic and no solution has worked. Looking for any help!</p> <p>Here is my GitHub repo <a href="https://i.stack.imgur.com/jmelF.png" rel="nofollow noreferrer">1</a></p> <p>And here is my index.html file</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;!-- If you are serving your web app in a path other than the root, change the href value below to reflect the base path you are serving from. The path provided below has to start and end with a slash "/" in order for it to work correctly. For more details: * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base This is a placeholder for base href that will be replaced by the value of the `--base-href` argument provided to `flutter build`. --&gt; &lt;!--&lt;base href="/"&gt;--&gt; &lt;meta charset="UTF-8"&gt; &lt;meta content="IE=Edge" http-equiv="X-UA-Compatible"&gt; &lt;meta name="description" content="A new Flutter project."&gt; &lt;!-- iOS meta tags &amp; icons --&gt; &lt;meta name="apple-mobile-web-app-capable" content="yes"&gt; &lt;meta name="apple-mobile-web-app-status-bar-style" content="black"&gt; &lt;meta name="apple-mobile-web-app-title" content="sports_app"&gt; &lt;link rel="apple-touch-icon" href="icons/Icon-192.png"&gt; &lt;!-- Favicon --&gt; &lt;link rel="icon" type="image/png" href="favicon.png"/&gt; &lt;title&gt;sports_app&lt;/title&gt; &lt;link rel="manifest" href="manifest.json"&gt; &lt;script&gt; // The value below is injected by flutter build, do not touch. var serviceWorkerVersion = '1014210939'; &lt;/script&gt; &lt;!-- This script adds the flutter initialization JS code --&gt; &lt;script src="flutter.js" defer&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script&gt; window.addEventListener('load', function(ev) { // Download main.dart.js _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, } }).then(function(engineInitializer) { return engineInitializer.initializeEngine(); }).then(function(appRunner) { return appRunner.runApp(); }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> </p> <p>Here is Flutter Doctor:</p> <pre><code>[βœ“] Flutter (Channel master, 3.5.0-10.0.pre.40, on macOS 11.3.1 20E241 darwin-arm64 (Rosetta), locale en-US) β€’ Flutter version 3.5.0-10.0.pre.40 on channel master at /Users/mikebeazer/Developer/flutter β€’ Upstream repository https://github.com/flutter/flutter.git β€’ Framework revision 20c4b6c53e (3 hours ago), 2022-10-23 15:22:39 -0400 β€’ Engine revision f62df69205 β€’ Dart version 2.19.0 (build 2.19.0-330.0.dev) β€’ DevTools version 2.18.0 [βœ“] Android toolchain - develop for Android devices (Android SDK version 32.0.0) β€’ Android SDK at /Users/mikebeazer/Library/Android/sdk β€’ Platform android-31, build-tools 32.0.0 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 13.2.1) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Build 13C100 β€’ CocoaPods version 1.11.3 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio β€’ Android Studio at /Applications/Android Studio Preview.app/Contents β€’ Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) [βœ“] Android Studio (version 2020.3) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) [βœ“] Connected device (2 available) β€’ macOS (desktop) β€’ macos β€’ darwin-arm64 β€’ macOS 11.3.1 20E241 darwin-arm64 (Rosetta) β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 106.0.5249.119 [βœ“] HTTP Host Availability β€’ All required HTTP hosts are available β€’ No issues found! </code></pre>
[ { "answer_id": 74164558, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 2, "selected": true, "text": " <base href=\"$FLUTTER_BASE_HREF\">\n" }, { "answer_id": 74164773, "author": "K K Muhammed Fazil"...
2022/10/22
[ "https://Stackoverflow.com/questions/74164386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308849/" ]
74,164,407
<p>I have a line of code that should be spitting out the phrase &quot;Testing 1&quot;</p> <p>Instead it's spitting out the letter &quot;h&quot;. The exact line of code is in reference to the link tag with in the UL/LI.</p> <p>My goal is to have the link tag link to individual blogs however using the blog name which is currently referred to as more_blogs_title I am not sure why it is pulling an &quot;h&quot; in I can't find any issues within that line of code at the moment so looking for some help.</p> <p>Thanks :)</p> <pre><code>&lt;section&gt; &lt;?php if ( have_rows( 'blog_layout' ) ): ?&gt; &lt;?php while ( have_rows( 'blog_layout' ) ) : the_row(); ?&gt; &lt;?php if ( get_row_layout() == 'blog_structure' ) : ?&gt; &lt;?php $hero_image = get_sub_field( 'hero_image' ); ?&gt; &lt;?php if ( $hero_image ) : ?&gt; &lt;img src=&quot;&lt;?php echo esc_url( $hero_image['url'] ); ?&gt;&quot; alt=&quot;&lt;?php echo esc_attr( $hero_image['alt'] ); ?&gt;&quot; /&gt; &lt;?php endif; ?&gt; &lt;div class=&quot;wrapper&quot;&gt; &lt;h1&gt;&lt;?php the_sub_field( 'blog_title' ); ?&gt;&lt;/h1&gt; &lt;?php if ( have_rows( 'blog_body_copy' ) ) : ?&gt; &lt;?php while ( have_rows( 'blog_body_copy' ) ) : the_row(); ?&gt; &lt;p&gt;&lt;?php the_sub_field( 'blog_body_copy_area' ); ?&gt;&lt;p&gt; &lt;?php endwhile; ?&gt; &lt;/div&gt; &lt;?php else : ?&gt; &lt;?php // No rows found ?&gt; &lt;?php endif; ?&gt; &lt;div class=&quot;wrapper&quot;&gt; &lt;h2&gt;&lt;?php the_sub_field( 'more_blogs_header' ); ?&gt;&lt;/h2&gt; &lt;?php if ( have_rows( 'more_blogs_links' ) ) : ?&gt; &lt;?php while ( have_rows( 'more_blogs_links' ) ) : the_row(); ?&gt; &lt;?php $link_to_blogs = get_sub_field( 'link_to_blogs' ); ?&gt; &lt;?php if ( $link_to_blogs ) : ?&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=&quot;&lt;?php echo esc_url( $link_to_blogs); ?&gt;&quot;&gt;&lt;?php echo esc_html( $link_to_blogs ['more_blogs_title']); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php // No rows found ?&gt; &lt;?php endif; ?&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php else: ?&gt; &lt;?php // No layouts found ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;/section&gt; </code></pre>
[ { "answer_id": 74164558, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 2, "selected": true, "text": " <base href=\"$FLUTTER_BASE_HREF\">\n" }, { "answer_id": 74164773, "author": "K K Muhammed Fazil"...
2022/10/22
[ "https://Stackoverflow.com/questions/74164407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308959/" ]
74,164,414
<p>I have a <code>LazyColumn</code> with nested <code>LazyRows</code> (similar to Netflix or Spotify home page feed). In short, the issue I'm having is that when the content of the page changes, the scrolling positions of the nested LazyRows are not reset.</p> <p>For example, user scrolls down the home page, scrolls the 3rd horizontal sections to see the 5th item, refreshes the home page, the new page content is loaded. But the 3rd horizontal section still shows the 5th instead of resetting to the initial position.</p> <p>In terms of code, here's some snippets:</p> <p>In HomeScreen composable:</p> <pre><code> Scaffold { when (val viewState = viewModel.stateFlow.collectAsState().value) { is ViewState.Success -&gt; { Box { with(viewState.data) { LazyColumn { itemsIndexed(sections) { index, section -&gt; LazyRow{} //etc. } } } } } </code></pre> <p>In the HomeViewModel, when user refreshes home screen this function is called:</p> <pre><code>private val _stateFlow = MutableStateFlow&lt;ViewState&lt;HomePage&gt;&gt;(ViewState.Loading) val stateFlow: StateFlow&lt;ViewState&lt;HomePage&gt;&gt; get() = _stateFlow fun loadHomeScreen() { viewModelScope.launch { repository.getHomePage() .collect { _stateFlow.tryEmit(it) } } } </code></pre> <p>Now I have managed to add extra code to scrolls the home page's LazyColumn to the top of the screen when user refreshes the home screen. However, I still don't know what's the best way to do that for the nested LazyRows. I do not want to keep a reference to their <code>LazyListState</code> as that solution does not scale well. However, I am confused on why the scrolling position is not being reset when new state is emitted and new LazyRows are displayed. Is that a bug in Compose? Or am I missing something?</p>
[ { "answer_id": 74171047, "author": "Merkost", "author_id": 15419983, "author_profile": "https://Stackoverflow.com/users/15419983", "pm_score": 1, "selected": false, "text": "LaunchedEffect(\n key1 = scrollToTopState,\n) {\n if (scrollToTopState) {\n listState.scrollToItem(0)...
2022/10/22
[ "https://Stackoverflow.com/questions/74164414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4438634/" ]
74,164,460
<p>please, I'm learning React with my simple TODO App. Everything now works OK. No errors or warnings (or issues in browser). But please, can you see the <code>console.log('PING!')</code>?</p> <p>I'm using for list of tasks this loop:</p> <pre class="lang-js prettyprint-override"><code>&lt;ul&gt; {tasks.map((task, index) =&gt; { console.log('PING!'); return ( &lt;Task id={task.id} name={task.name} isFinished={task.isFinished} key={index} onActionButtonClick={handleActionButtonClick}/&gt; ); })} &lt;/ul&gt; </code></pre> <p><code>console.log()</code> it's just for show the problem. <code>handleActionButtonClick</code> is used to passing arguments from child <code>Task</code>.</p> <p>But If I type the first task and hit enter (submit form). Everything is OK. I got <strong>PING!</strong> message once. But then it's called after every type new character. I'm using <code>onChange</code> event in <code>&lt;input&gt;</code>. Look here:</p> <pre class="lang-js prettyprint-override"><code>&lt;input id=&quot;newTaskInput&quot; type=&quot;text&quot; onChange={handleChange} value={newTask} placeholder=&quot;Add new task here...&quot; autoFocus /&gt; </code></pre> <p><code>handleChange</code> functions looks like here:</p> <pre class="lang-js prettyprint-override"><code>const handleChange = (e) =&gt; { if (e.target.value.length === 1) { e.target.value = e.target.value.toUpperCase(); } setNewTask(e.target.value); }; </code></pre> <p>This is called aways when I'm typing a new task (after the first one). Look on the screenshot please:</p> <p><a href="https://i.stack.imgur.com/6zQPJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6zQPJ.png" alt="enter image description here" /></a></p> <p>You can see the first <strong>PING!</strong> was called after submit <code>Butter</code> item. But then I'm typing a new item called <code>Milk</code> and you can see 4x <strong>PING!</strong> message in console. But I'm just setting the state called <code>setNewTask</code> which is <code>useState</code>. Look at the definition:</p> <pre class="lang-js prettyprint-override"><code>function App() { const [newTask, setNewTask] = useState(''); const [tasks, setTasks] = useState([]); const [editTaskId, setEditTaskId] = useState(); // other code } export default App; </code></pre> <p>I will be glad if someone can explain me why is <code>map</code> function is called everytime after the first submit and how to avoid it. Thanks to any advice</p> <p>For better understand my logic here is whole code please:</p> <pre class="lang-js prettyprint-override"><code>import React, { useState } from 'react'; import Task from './components/Task'; import Header from './components/Header'; function App() { const [newTask, setNewTask] = useState(''); const [tasks, setTasks] = useState([]); const [editTaskId, setEditTaskId] = useState(); const handleChange = (e) =&gt; { if (e.target.value.length === 1) { e.target.value = e.target.value.toUpperCase(); } setNewTask(e.target.value); }; const handleSubmit = (e) =&gt; { e.preventDefault(); if (editTaskId &gt; 0) { //editing exisitng task let newTasksArray = [...tasks]; let newTask = newTasksArray[editTaskId]; newTask.name = newTask; setTasks(newTasksArray); } else { //creating new task setTasks([ { id: [...tasks].length === 0 ? 0 : Math.max(...tasks.map((task) =&gt; task.id)) + 1, name: newTask, isFinished: false, }, ...tasks, ]); } setNewTask(''); }; const handleActionButtonClick = (buttonValues) =&gt; { switch (buttonValues.type) { case 'edit': tasks.map((task) =&gt; { if (task.id === buttonValues.id) { setNewTask(task.name); setEditTaskId(task.id); return; } }); break; case 'delete': setTasks(tasks.filter((task) =&gt; task.id !== buttonValues.id)); break; default: //TODO: We shoudn't reverse array. Instead of that we shoud find a right id in a array and change value console.log(buttonValues.id); let newTasksArray = [...tasks].reverse(); let newTask = newTasksArray[buttonValues.id]; //if task if already finished we can return state if (newTask.isFinished) newTask.isFinished = false; else newTask.isFinished = true; setTasks(newTasksArray.reverse()); } }; return ( &lt;&gt; &lt;Header /&gt; &lt;div className=&quot;container&quot;&gt; &lt;form onSubmit={handleSubmit}&gt; &lt;label htmlFor=&quot;newTaskInput&quot; className=&quot;sr-only&quot;&gt; Input for new task &lt;/label&gt; &lt;input id=&quot;newTaskInput&quot; type=&quot;text&quot; onChange={handleChange} value={newTask} placeholder=&quot;Add new task here...&quot; autoFocus /&gt; &lt;/form&gt; &lt;ul&gt; {tasks.map((task, index) =&gt; { console.log('PING!'); return ( &lt;Task id={task.id} name={task.name} isFinished={task.isFinished} key={index} onActionButtonClick={handleActionButtonClick} /&gt; ); })} &lt;/ul&gt; &lt;/div&gt; &lt;/&gt; ); } export default App; </code></pre> <p>Best regards folks.</p>
[ { "answer_id": 74164533, "author": "CertainPerformance", "author_id": 9515207, "author_profile": "https://Stackoverflow.com/users/9515207", "pm_score": 2, "selected": true, "text": "tasks" }, { "answer_id": 74164542, "author": "Mohamed Ashraf", "author_id": 19760581, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1169081/" ]
74,164,469
<p>If the string in the first column is different to the string in the first column of the previous line, prints the entire previous line.</p> <p>Another way to put this is, whenever the first column is equal, print the entire last line, of matched columns and discard the previous one, that are equal.</p> <p>I used this:</p> <pre><code>awk 'BEGIN { FS=OFS=&quot;;&quot; } $1==last{next} {last=$1} {print last}' test.txt </code></pre> <p>test.txt</p> <pre class="lang-none prettyprint-override"><code>818522;&quot;Joey&quot;; 817399;&quot;john&quot;; 817399;&quot;CCE&quot;; 817399;&quot;smith&quot;; 817399;&quot;Ron&quot;; 817400; 817400; 817400; 818000;&quot;ODC&quot;; 890021; 890021; 890021;&quot;rachel&quot;; 890021;&quot;monica&quot; </code></pre> <p>Ideal output:</p> <pre class="lang-none prettyprint-override"><code>818522;&quot;Joey&quot;; 817399;&quot;Ron&quot;; 817400; 818000;&quot;ODC&quot;; 890021;&quot;monica&quot; </code></pre>
[ { "answer_id": 74164496, "author": "Ed Morton", "author_id": 1745001, "author_profile": "https://Stackoverflow.com/users/1745001", "pm_score": 2, "selected": false, "text": "$ awk -F';' '$1!=p1{if (NR>1) print p0} {p1=$1; p0=$0} END{print p0}' test.txt\n818522;\"Joey\";\n817399;\"Ron\";\...
2022/10/22
[ "https://Stackoverflow.com/questions/74164469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12867534/" ]
74,164,474
<p>I want to count the number of characters, words and newlines in a program. My code look like this:</p> <pre><code>#include &lt;stdio.h&gt; int main() { int nw, nl, nc, c; nw = nc = nl = 0; for (c = getchar(); c != EOF; c = getchar()) { if (c == '\n') ++nl; if (c != '\n' || c != '\t' || c != ' ') { for (c = getchar(); c == '\n' || c == '\t' || c == ' '; c = getchar()) { ++nc; } ++nw; ++nc; if (c == '\n') ++nl; } else ++nc; } printf(&quot;%d %d %d&quot;, nc, nw, nl); return 0; } </code></pre> <p>Input:</p> <pre><code>smith book c c++ bug </code></pre> <p>Output: <code>9 0 13</code></p> <p>What's wrong with this program?<br /> I am a beginner. Forgive if I made any mistake.</p>
[ { "answer_id": 74164496, "author": "Ed Morton", "author_id": 1745001, "author_profile": "https://Stackoverflow.com/users/1745001", "pm_score": 2, "selected": false, "text": "$ awk -F';' '$1!=p1{if (NR>1) print p0} {p1=$1; p0=$0} END{print p0}' test.txt\n818522;\"Joey\";\n817399;\"Ron\";\...
2022/10/22
[ "https://Stackoverflow.com/questions/74164474", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20283429/" ]
74,164,494
<p>I'm new to RXJS and would to know if what I am doing is best practice. I have an API whihc returns a list of countries. I need to use this list in several different components. I have an external api that returns this, it can be very slow.</p> <p>I have a service to call this API. In the constructor of this service I kick off the HTTP request which then passes the list to a BehaviorSubject. I need to use the unedited list in one component this subscribes the BehaviorSubject. Another component will use selected values from the list and I am using the getCountryById function to do this and return a single value in a string</p> <p>Should I be using AsyncSubject to do this and is it bad practice to use this.CountriesSubject.value in my getCountryById function, should I also be using a BehaviorSubject.subscribe in there as well?</p> <p>All of this does need to happen in the service</p> <p>Thanks for your time :-)</p> <pre><code> export class CountryListService implements OnDestroy { private baseUrl = 'api/countries/'; private CountriesSubject = new BehaviorSubject&lt;country[]&gt;([]); Countries$: Observable&lt;Country[]&gt; = this.CountriesSubject.asObservable(); constructor(private http: HttpClient) { this.getCountries(); } getCountries() { console.log('=======fetching Countries from API'); this.http.get&lt;any&gt;(this.baseUrl + 'Countries').subscribe((data) =&gt; this.CountriesSubject.next(data?.countries)); } getCountryById(id: any[]) { if (!this.CountriesSubject.value) { return undefined; } const country = this.CountriesSubject.value.find((f) =&gt; { //Logic in here to get a country by and return its name }); return country?.name; } ngOnDestroy() { this.CountriesSubject.complete(); } } </code></pre>
[ { "answer_id": 74165074, "author": "Matthieu Riegler", "author_id": 884123, "author_profile": "https://Stackoverflow.com/users/884123", "pm_score": 0, "selected": false, "text": "value" }, { "answer_id": 74165076, "author": "BizzyBob", "author_id": 1858357, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308892/" ]
74,164,507
<p>Hi guys I'm new to JavaScript. I'm trying to get the Date and Time in a non-editable textbox in this format: (e.g. 7 October 2022 Friday 10:47). The content is the current date or today’s date which will change every day.</p> <p>Currently these are my codes:</p> <pre><code>function getDate() { const date = new Date(); const months = [ &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, &quot;June&quot;, &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot; ]; const days = [ &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot; &quot;Sunday&quot; ]; document.getElementById(&quot;dateandtime&quot;).value = months[(date.getMonth()+1)] + (date.getFullYear()) + days[(date.getDay())] + (date.getHours()) + ':' +(date.getMinutes()); } </code></pre> <pre><code> Current Date and Time: &lt;br/&gt; &lt;input type = &quot;text&quot; id = &quot;dateandtime&quot; name = &quot;dateandtime&quot; onload=&quot;getDate()&quot; readonly&gt; &lt;br/&gt;&lt;br/&gt; </code></pre> <p>However, when I run it, nothing is displayed in my textbox.</p> <p>Any idea why that is the case?</p>
[ { "answer_id": 74165074, "author": "Matthieu Riegler", "author_id": 884123, "author_profile": "https://Stackoverflow.com/users/884123", "pm_score": 0, "selected": false, "text": "value" }, { "answer_id": 74165076, "author": "BizzyBob", "author_id": 1858357, "author_pr...
2022/10/22
[ "https://Stackoverflow.com/questions/74164507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19864327/" ]
74,164,521
<p>The question says to write a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if the string is valid, and false if it's invalid.</p> <p>All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: ()[]{}.</p> <p>The tests should give these:</p> <pre><code>&quot;(){}[]&quot; =&gt; True &quot;([{}])&quot; =&gt; True &quot;(}&quot; =&gt; False &quot;[(])&quot; =&gt; False &quot;[({})](]&quot; =&gt; False </code></pre> <p>The code I've written is:</p> <pre><code>def validBraces(braces) revBraces = braces.reverse arr = [] i = -1 loop do i += 1 if braces[i] == &quot;(&quot; &amp;&amp; revBraces[i] == &quot;)&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end if braces[i] == &quot;)&quot; &amp;&amp; revBraces[i] == &quot;(&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end if braces[i] == &quot;{&quot; &amp;&amp; revBraces[i] == &quot;}&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end if braces[i] == &quot;}&quot; &amp;&amp; revBraces[i] == &quot;{&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end if braces[i] == &quot;[&quot; &amp;&amp; revBraces[i] == &quot;]&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end if braces[i] == &quot;]&quot; &amp;&amp; revBraces[i] == &quot;[&quot; arr &lt;&lt; 1 else arr &lt;&lt; 0 end break if i &lt;= braces.length end if arr.include? 0 puts false else puts true end end </code></pre> <p>I cant tell where I've gone wrong and why it doesn't work.</p>
[ { "answer_id": 74164586, "author": "Gwang-Jin Kim", "author_id": 9690090, "author_profile": "https://Stackoverflow.com/users/9690090", "pm_score": 0, "selected": false, "text": "def freqs(l)\n h = Hash.new(0)\n l.each do |e|\n h[e] += 1\n end\n return h\nend\n\ndef balanced(braces...
2022/10/22
[ "https://Stackoverflow.com/questions/74164521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308905/" ]
74,164,546
<p>So I have a dataframe structured like:</p> <pre><code>Date Metric Value 2020-01-01 Low 34.5 2020-01-01 High 36.5 2020-01-01 Open 23.5 2020-01-02 Low 32.5 ... </code></pre> <p>I am trying to create another frame, where for every date there is a new 'Volume' column which is the High-low for that specific date. The frame is not keyed on the dates so it needs to be joined and then values in different columns added together? Not sure exactly how to do this. I'm trying to get the final result to look like this:</p> <pre><code>Date Volume 2020-01-01 2.00 2020-01-02 6.45 </code></pre>
[ { "answer_id": 74164689, "author": "ouroboros1", "author_id": 18470692, "author_profile": "https://Stackoverflow.com/users/18470692", "pm_score": 2, "selected": true, "text": "df" }, { "answer_id": 74165357, "author": "Azhar Khan", "author_id": 2847330, "author_profil...
2022/10/22
[ "https://Stackoverflow.com/questions/74164546", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8723794/" ]
74,164,559
<p>When using this formula I get the correct answer. However, when I copy this down to the next blank cell I get &quot;FALSE&quot; but I want it to be blank. Not &quot;BLANK&quot; but empty.</p> <p>=IF(ISNUMBER(E5),IF(D5=&quot;LONG&quot;,((H5<em>I5)+(K5</em>L5))-(E5<em>F5),IF(D5=&quot;SHORT&quot;,(E5</em>F5)-((H5<em>I5)+(K5</em>L5)))))</p> <p>I have also tried these formulas with the same results:</p> <p>=IF(D17=&quot;LONG&quot;,((H17<em>I17)+(K17</em>L17))-(E17<em>F17),IF(D17=&quot;SHORT&quot;,(E17</em>F17)-((H17<em>I17)+(K17</em>L17,””))))</p> <p>=IF(D18=&quot;LONG&quot;,((H18<em>I18)+(K18</em>L18))-(E18<em>F18),IF(D18=&quot;SHORT&quot;,(E18</em>F18)-((H18<em>I18)+(K18</em>L18),&quot;&quot;)))</p>
[ { "answer_id": 74164635, "author": "Terio", "author_id": 4840576, "author_profile": "https://Stackoverflow.com/users/4840576", "pm_score": 1, "selected": true, "text": "=IF(ISNUMBER(E5),IF(D5=\"LONG\",((H5I5)+(K5L5))-(E5F5),IF(D5=\"SHORT\",(E5F5)-((H5I5)+(K5L5)),\"\")),\"\")\n" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20308975/" ]
74,164,563
<p>I'm an absolute beginner - like I'm Today-years-old with this.</p> <p>So I'm mucking about with a silly little piece of code to try and help me understand If statements:</p> <pre><code>print ('How many sausages have you eaten today?') userInput = ('&gt;5' or '&lt;5') if userInput input == int ('&gt; 5'): print ('Whoa! Slow down Fatty!') elif userInput input == ('&lt; 5'): print ('Ok, but better call it a day now') </code></pre> <p>I'm trying to alter the printed message based on how many sausages the user inputs - e.g. above 5 or below 5. I know that I'm doing something (probably many things) wrong. Can anyone help to tidy this up?</p>
[ { "answer_id": 74164635, "author": "Terio", "author_id": 4840576, "author_profile": "https://Stackoverflow.com/users/4840576", "pm_score": 1, "selected": true, "text": "=IF(ISNUMBER(E5),IF(D5=\"LONG\",((H5I5)+(K5L5))-(E5F5),IF(D5=\"SHORT\",(E5F5)-((H5I5)+(K5L5)),\"\")),\"\")\n" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309060/" ]
74,164,599
<pre><code>// './file_1' import { createSlice } from '@reduxjs/toolkit'; export const array = createSlice({ name: 'array', initialState: { value: [] }, reducers:{ append(state, a) { state.value.push(a) } } }); export const { append } = array.actions; export default array.reducer; </code></pre> <p>I've also updated the store, so no problem on that side</p> <pre><code>'/.file_2' import { useSelector, useDispatch } from 'react-redux'; import { append } from './file_1'; const dispatch = useDispatch() let x = 5 dispatch(append(x)); </code></pre> <p>raises this error: Objects are not valid as a React child (found: object with keys {type, payload}). If you meant to render a collection of children, use an array instead.</p>
[ { "answer_id": 74164635, "author": "Terio", "author_id": 4840576, "author_profile": "https://Stackoverflow.com/users/4840576", "pm_score": 1, "selected": true, "text": "=IF(ISNUMBER(E5),IF(D5=\"LONG\",((H5I5)+(K5L5))-(E5F5),IF(D5=\"SHORT\",(E5F5)-((H5I5)+(K5L5)),\"\")),\"\")\n" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19860468/" ]
74,164,603
<h1>Objective</h1> <ul> <li>Display a 3D <strong>Sphere</strong> graph structure based on input edges &amp; nodes using VTK for visualisation. As for example shown in <a href="https://epfl-lts2.github.io/gspbox-html/doc/graphs/gsp_sphere.html" rel="nofollow noreferrer">https://epfl-lts2.github.io/gspbox-html/doc/graphs/gsp_sphere.html</a></li> </ul> <p>Target:</p> <p><a href="https://i.stack.imgur.com/r6Bta.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r6Bta.png" alt="enter image description here" /></a></p> <h1>State of work</h1> <ul> <li>Input data as given factor</li> <li>NetworkX for position calculation</li> <li>Handover to VTK methods for 3D visualisation</li> </ul> <h1>Problem</h1> <p>3 years ago, I had achieved the visualisation as shown above. Unfortunately, I did a little bit of too much cleaning and I just realized, that I dont have these methods anymore. It is somehow a force-directed graph on a sphere surface. Maybe similar to the &quot;strong gravity&quot; parameter in the 2D forceatlas. I have not found any 3D implementation of this yet.</p> <p>I tried again with the following algorithms, but none of them has produced this layout, neither have parameter tuning of these algorithms (or did I miss an important one?):</p> <ul> <li>NetworkX: Spherical, Spring, Shell, Kamada Kawaii, Fruchterman-Reingold (the 2D fruchterman-reingold in Gephi looks like it could come close to the target in a 3D version, yet gephi does not support 3D or did I oversee something?)</li> <li>ForceAtlas2</li> <li>Gephi (the 2D fruchterman-reingold looks like a circle, but this is not available in 3D, nor does the 3D Force Atlas produce valid Z-Coordinates (they are within a range of +1e-4 and -1e-4)</li> </ul> <p>Researching for &quot;spherical graph layout&quot; has not brought me to any progress (only to this view which seems very similar <a href="https://observablehq.com/@fil/3d-graph-on-sphere" rel="nofollow noreferrer">https://observablehq.com/@fil/3d-graph-on-sphere</a> ).</p> <p>How can I achieve this spherical layout using python (or a third party which provides a positioning information)</p> <p><strong>Update:</strong> I made some progress and found the keywords non-euclidean, hyperbolic and spherical force-directed algorithms, however still not achieved anything yet. Or Non-Euclidean Riemann Embeddings (<a href="https://www2.cs.arizona.edu/%7Ekobourov/riemann_embedders.pdf" rel="nofollow noreferrer">https://www2.cs.arizona.edu/~kobourov/riemann_embedders.pdf</a>)</p>
[ { "answer_id": 74164635, "author": "Terio", "author_id": 4840576, "author_profile": "https://Stackoverflow.com/users/4840576", "pm_score": 1, "selected": true, "text": "=IF(ISNUMBER(E5),IF(D5=\"LONG\",((H5I5)+(K5L5))-(E5F5),IF(D5=\"SHORT\",(E5F5)-((H5I5)+(K5L5)),\"\")),\"\")\n" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12885050/" ]
74,164,604
<p>I am trying to search and replace certain words in my .xml file and replace it with another, but I struggle a bit.</p> <p>I have been using this code so far:</p> <pre><code>import xml.etree.ElementTree as ET with open('Rom1.xml', encoding=&quot;utf8&quot;) as f: tree = ET.parse(f) #root = tree.find('ExportedObjects') root = tree.getroot() for elem in root.iter(): try: elem.text = elem.text.replace('Rom1', 'Rom2') except AttributeError: pass </code></pre> <p><a href="https://i.stack.imgur.com/rdPUC.png" rel="nofollow noreferrer">Rom1.xml</a> this is a snapshot from the XML file showing the structure</p> <p>The XML file is pretty big but it contains the string 'Rom1' 41 times and I would like to replace all of them.</p> <p>I know a simple search and replace in text editor does the job, but I want to automate this since I will do it for several hundered of files.</p> <p>Any help is appriciated :)</p>
[ { "answer_id": 74164635, "author": "Terio", "author_id": 4840576, "author_profile": "https://Stackoverflow.com/users/4840576", "pm_score": 1, "selected": true, "text": "=IF(ISNUMBER(E5),IF(D5=\"LONG\",((H5I5)+(K5L5))-(E5F5),IF(D5=\"SHORT\",(E5F5)-((H5I5)+(K5L5)),\"\")),\"\")\n" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19662215/" ]
74,164,643
<p>In C, you can use the <code>static</code> keyword to make global variables and functions private to the file in which they're defined. The compiler won't export these symbols, and thus the linker will not allow other modules to use these definitions.</p> <p>However, I'm struggling to figure out how to restrict a struct definition such that it doesn't get added as an exported symbol that could accidentally be used by another module during the linking process. I would like to restrict this to the only file in which its defined.</p> <p>Here are my attempts thus far which I've been struggling with.</p> <pre><code>// structure that is visible to other modules struct PrivateStruct { int hello; int there; }; // this seems to throw an error static struct PrivateStruct { int hello; int there; }; // i would ideally like to also wrap in the struct in a typedef, but this definitely doesn't work. typedef static struct PrivateStruct { int hello; int there; } PrivateStruct; </code></pre> <p>Edit: I realize if I just define this struct in the .c file, others won't know about it. But won't it still technically be an exported symbol by the compiler? It would be nice to prevent this behavior.</p>
[ { "answer_id": 74164738, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 3, "selected": true, "text": "typedef" }, { "answer_id": 74185106, "author": "Luis Colorado", "author_id": 3899431, "aut...
2022/10/22
[ "https://Stackoverflow.com/questions/74164643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2649384/" ]
74,164,647
<p>I've bound an enum to a combobox in WPF using a method a friend showed me instead of everything I've found online. What I need to do is convert the selected item from the dropdown back to an enum because I'm using it to set a property. I'm new to WPF and C# so I'm not even sure I'm properly asking the question, therefor not finding the answer I need.</p> <pre><code> private void cmbInputPath_SelectionChanged(object sender, SelectionChangedEventArgs e) { FM.InputPath = cmbInputPath.SelectedItem; } </code></pre> <p>Here is the property that uses the enum.</p> <pre><code>public Input InputPath { set { switch (value) { case Input.DIPLEXER: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P7); break; case Input.AUX1: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P2); break; case Input.AUX2: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P3); break; case Input.AUX3: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P1); break; case Input.AUX4: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P4); break; case Input.AUX5: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P8); break; case Input.AUX6: SetSwitchPosition(SWC3.CurrentPosition, SWC3.P5); break; } } } </code></pre> <p>Please let me know if I need to show anything else.</p> <p>Here's the combobox XAML..</p> <pre><code>&lt;ComboBox x:Name=&quot;cmbInputPath&quot; Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot; Text=&quot;Select...&quot; IsEditable=&quot;True&quot; IsReadOnly=&quot;True&quot; FontWeight=&quot;Bold&quot; FontSize=&quot;14&quot; VerticalContentAlignment=&quot;Center&quot; ItemsSource=&quot;{Binding MyInputPath}&quot; SelectionChanged=&quot;cmbInputPath_SelectionChanged&quot;&gt; &lt;/ComboBox&gt; </code></pre>
[ { "answer_id": 74164738, "author": "John Bollinger", "author_id": 2402272, "author_profile": "https://Stackoverflow.com/users/2402272", "pm_score": 3, "selected": true, "text": "typedef" }, { "answer_id": 74185106, "author": "Luis Colorado", "author_id": 3899431, "aut...
2022/10/22
[ "https://Stackoverflow.com/questions/74164647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14057275/" ]
74,164,650
<p>So, I saw a related 'topic' question on here, but it is using a different method.</p> <p>Further, I understand there are more efficient algorithms out there such as Mid-point/Bresenham's.</p> <p>Yet, at least thus far in my discovery, perhaps 'simple and traditional' is best for my needed end-point application.</p> <p>Thus I put together this tiny Python app to experiment. I needed to at least ensure that descending radii of a circle described this way would cover the area. Again, I fully understand there would be much easier ways to make a circle, and a fill--</p> <p>But that is not really what I'm after. I just need to determine a list of all the (x,y) pixel points, in the end, that describe it.</p> <p>However, at first, this is of course much easier to see 'visually'.</p> <p>So, from my simple code:</p> <pre><code>from PIL import Image import math import numpy as np img = Image.new('RGB', (800, 800), color = (255, 255, 255)) x = 400 y = 400 #r = 300 for r in range(0, 300, 1): for i in np.arange(0, 361, 0.1): angle = i x1 = math.trunc(r * math.cos(angle * math.pi / 180)) y1 = math.trunc(r * math.sin(angle * math.pi / 180)) #print (&quot;(&quot; + str(x + x1) + &quot;,&quot; + str(y + y1) + &quot;)&quot;) img.putpixel((x + x1, y + y1), (0, 0, 0, 255)) img.show() </code></pre> <p>I guess I am a little confused as to how/why I am blanking out in these four points, one in each quadrant, almost exactly like a square:</p> <p><a href="https://i.stack.imgur.com/xragJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xragJ.png" alt="enter image description here" /></a></p> <p>Anyone have a guess 'what gives ?'</p>
[ { "answer_id": 74164793, "author": "Manfred", "author_id": 13134095, "author_profile": "https://Stackoverflow.com/users/13134095", "pm_score": 3, "selected": true, "text": "r_squared = r*r\nfor x1 in range(0, r):\n for y1 in range(0, r):\n if x1*x1 + y1*y1 < r_squared:\n img.put...
2022/10/22
[ "https://Stackoverflow.com/questions/74164650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9277565/" ]
74,164,657
<p>I want to understand how this works. In the HTML is used the onclick=&quot;changeColor(<strong>this</strong>)&quot; to communicate with the js. But if I change the word <strong>this</strong> in the HTML the code stops working. Why?</p> <p>HTML:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt; &lt;link rel=&quot;script&quot; href=&quot;script.js&quot;&gt; &lt;title&gt;Tente vocΓͺ&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div onclick=&quot;changeColor(this)&quot; style=&quot;background-color: blue;&quot;&gt; Me aperte para mudar de cor! &lt;/div&gt; &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JS:</p> <pre><code>function changeColor(element) { var currentColor = element.style.backgroundColor; if (currentColor == &quot;red&quot;) { element.style.backgroundColor = &quot;green&quot;; } else { element.style.backgroundColor = &quot;red&quot;; } } </code></pre>
[ { "answer_id": 74164695, "author": "philale", "author_id": 14974627, "author_profile": "https://Stackoverflow.com/users/14974627", "pm_score": 2, "selected": false, "text": "this" }, { "answer_id": 74164768, "author": "MJG", "author_id": 20283130, "author_profile": "h...
2022/10/22
[ "https://Stackoverflow.com/questions/74164657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309129/" ]
74,164,684
<p>I am trying to use state hoisting in android</p> <hr /> <p>I am new to android development using jetpack compose</p> <pre><code>onSearchChange: (String) -&gt; Unit, onCategoryChange: (Category) -&gt; Unit, onProductSelect: (Product) -&gt; Unit, composable(Screen.Home.route) { MainPage(navController = navController, searchQuery = &quot;&quot;, productCategories = categories, selectedCategory = Category(&quot;&quot;,&quot;&quot;,0), products = pros, /* what do I write here for the 3 lines above?? :( the onSearch,etc I have an error bc of them */ )} </code></pre>
[ { "answer_id": 74165614, "author": "Arthur Kasparian", "author_id": 19454251, "author_profile": "https://Stackoverflow.com/users/19454251", "pm_score": 0, "selected": false, "text": "@Composable\nfun OuterComposable(\n modifier: Modifier = Modifier \n) {\n\n // This is your stat...
2022/10/22
[ "https://Stackoverflow.com/questions/74164684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18517775/" ]
74,164,685
<p>I would like to make this call and return a string but I'm having this error:</p> <p><em><strong>&quot;java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3&quot;</strong></em></p> <p>I dont understand why am I doing wrong? WebClient supports asynchronous as well as synchronous calls.</p> <p>This a springboot project with just 3 dependencies.</p> <p>How can I return just a string like a normal synchronous call?</p> <pre><code>@RestController public class HomeController { @GetMapping(&quot;/&quot;) public String home() { String resp = webclient.get() .uri(ANY_URL).retrieve() .bodyToMono(String.class) .block(); return resp; } } pom.xml &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;io.projectreactor&lt;/groupId&gt; &lt;artifactId&gt;reactor-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; </code></pre> <p>Thanks.</p>
[ { "answer_id": 74165614, "author": "Arthur Kasparian", "author_id": 19454251, "author_profile": "https://Stackoverflow.com/users/19454251", "pm_score": 0, "selected": false, "text": "@Composable\nfun OuterComposable(\n modifier: Modifier = Modifier \n) {\n\n // This is your stat...
2022/10/22
[ "https://Stackoverflow.com/questions/74164685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4262784/" ]
74,164,687
<p>I have this sample string in the variable test_string. I want to delete chorus text. It is situated in this format: <em>[chorus etc..] chorus_text [verse etc..]</em>. I tried some regex patterns in python but nothing. Any idea? The pattern I am providing doesn't give me what i need. The chorus_text includes punctuation and characters.</p> <pre><code>test_string = &quot;&quot;&quot;Cordae,RNP,2019.0,&quot;RNP Lyrics[Chorus: Anderson .Paak] text text text text text text te'all tean' tean' text text text [Verse 1: YBN Cordae].&quot;&quot;&quot; pattern = re.compile(r&quot;[^\[chorus\]$][^\[verse\]]&quot;) subbed_chorus_before_verse = pattern.findall(test_string) </code></pre>
[ { "answer_id": 74164763, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": false, "text": "test_string = \"\"\"Cordae,RNP,2019.0,\"RNP Lyrics[Chorus: Anderson .Paak] text text text text text text te'all tean'...
2022/10/22
[ "https://Stackoverflow.com/questions/74164687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17703071/" ]
74,164,703
<p>This is the task I need to complete:</p> <p>Consider that you are interested in coloured shapes on paper. Write a class 'Shape'which has a hidden attribute of colour, an access method to get the colour (you may wish to have a default colour) and an modifier method to set the colour.</p> <p>Try and make it so that you can chain your methods, e.g.</p> <pre><code>s = Shape() s.set('Red').colour() Output: Red s.set('Yellow').set('Blue').colour() Output: Yellow </code></pre> <p>I'm very new to python, and im lost. This is what I already have and it's probably really wrong. I would appreciate some help.</p> <p>This is what I already have:</p> <pre><code>class Shape: def __init__(self, colour = None): self._colour = colour def colour(self): print(self._colour) def set(self, new_colour): self.new_colour = new_colour self._colour = new_colour s = Shape() </code></pre> <p>but it doesn't seem to work the way the task wants it to. please help.</p>
[ { "answer_id": 74164763, "author": "Naveed", "author_id": 3494754, "author_profile": "https://Stackoverflow.com/users/3494754", "pm_score": 2, "selected": false, "text": "test_string = \"\"\"Cordae,RNP,2019.0,\"RNP Lyrics[Chorus: Anderson .Paak] text text text text text text te'all tean'...
2022/10/22
[ "https://Stackoverflow.com/questions/74164703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20300079/" ]
74,164,719
<p>What's the best way I can get a list of BSD names of all USB devices (and maybe including internal Mac drives) without using a <b>diskutil</b> CLI wrapper?</p> <p>I <b>don't want</b> to use any <b>wrappers</b> that interact with the CLI interface, as this way of interacting is quite <b>slow</b> and <b>unreliable</b>:</p> <p><a href="https://i.stack.imgur.com/JMcB8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JMcB8.jpg" alt="" /></a></p> <p><sup>This is an example of why I'm not happy with using CLI wrappers<br /> (Compare <b>'Time elapsed for DiskUtil CLI Wrapper.'</b> and <b>'Time elapsed for Disk Arbitration'</b>)</sup></p> <p>What is the best way to implement the solution for my problem?<br /> Use the data from <b>IOReg</b>?<br /> If yes, how can I get a list of BSD names of connected devices using it?</p> <p>Here is an example what I want to get:</p> <pre><code>[&quot;disk0&quot;, &quot;disk0s1&quot;, &quot;disk0s2&quot;, &quot;disk0s3&quot;, &quot;disk1&quot;, &quot;disk1s1&quot;, &quot;disk1s2&quot;, &quot;disk1s3&quot;, &quot;disk1s4&quot;, &quot;disk2&quot;, &quot;disk2s1&quot;, &quot;disk2s2&quot;, &quot;disk3&quot;, &quot;disk3s1&quot;, &quot;disk3s1s1&quot;, &quot;disk3s2&quot;, &quot;disk3s3&quot;, &quot;disk3s4&quot;, &quot;disk3s5&quot;, &quot;disk3s6&quot;, &quot;disk4&quot;, &quot;disk4s1&quot;, &quot;disk4s2&quot;, &quot;disk5&quot;, &quot;disk5s1&quot;, &quot;disk5s2&quot;, &quot;disk6&quot;, &quot;disk6s1&quot;, &quot;disk6s2&quot;, &quot;disk10&quot;, &quot;disk10s1&quot;, &quot;disk10s2&quot;, &quot;disk11&quot;, &quot;disk11s1&quot;] </code></pre> <p>At the moment, I have the following:</p> <pre><code>static func getMountedBSDNames() -&gt; [String] { guard let session = DASessionCreate(nil) else { return [] } guard let mountedVolumeURLs = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: nil) else { return [] } var BSDNames: [String] = [] for volumeURL in mountedVolumeURLs { if let disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, volumeURL as CFURL), let BSDName = DADiskGetBSDName(disk) { BSDNames.append( String(cString: BSDName) ) } } return BSDNames } </code></pre> <p>But in this case, <b>only mounted</b> are returning.<br /> I want there to have even those, that were <b>ejected</b></p>
[ { "answer_id": 74165214, "author": "ReSophie", "author_id": 13099129, "author_profile": "https://Stackoverflow.com/users/13099129", "pm_score": 3, "selected": true, "text": "func getDriveBSDNames() -> [String] {\n var iterator: io_iterator_t = 0\n\n let matching: CFDictionary = IOS...
2022/10/22
[ "https://Stackoverflow.com/questions/74164719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13099129/" ]
74,164,755
<p>This is my data. <a href="https://i.stack.imgur.com/2SVHh.png" rel="nofollow noreferrer">(click the link)</a> I want to plot a bar chart in R which the x-axis is the income and the y-axis is the Degree (undergraduate, master...).Also, each bar in one group is represented by region. Could you tell me how to get the bar plot in R? Thank you so much for answering.</p>
[ { "answer_id": 74165090, "author": "br00t", "author_id": 4028717, "author_profile": "https://Stackoverflow.com/users/4028717", "pm_score": 2, "selected": false, "text": "dput" }, { "answer_id": 74165108, "author": "user7264", "author_id": 16085883, "author_profile": "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14572875/" ]
74,164,760
<p>I'm trying to have an alertDialog displayed when opening my app (that: it works) and I would like to have a boolean as an option (with shared preferences) to propose not to display the message when opening . What is my mistake?</p> <p>my boolean and my initState:</p> <pre><code> late bool _alertMessage = true; @override void initState() { super.initState(); retrieveBoolData(); alertMessageAppOpen(); } </code></pre> <p>my shared preferences settings:</p> <pre><code> Future&lt;void&gt; addBoolData() async { SharedPreferences prefs = await SharedPreferences.getInstance(); _alertMessage = false; setState(() { prefs.setBool('alertbool', false); }); } Future&lt;void&gt; retrieveBoolData() async { SharedPreferences prefs = await SharedPreferences.getInstance(); setState(() { _alertMessage = prefs.getBool('alertbool')!; }); } </code></pre> <p>My Alert dialog :</p> <pre><code> void alertMessageAppOpen() { return _alertMessage == false ? null : WidgetsBinding.instance.addPostFrameCallback((_) async { await showDialog&lt;String&gt;( context: context, builder: (BuildContext context) =&gt; AlertDialog( backgroundColor: Colors.white, title: const Text('Alert !', style: TextStyle(color: Colors.black54), ), actions: &lt;Widget&gt;[ TextButton( child: const Text('do not display anymore', style: TextStyle(color: Colors.white), ), onPressed: () { setState(() { _alertMessage == false; addBoolData(); }); Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK', style: TextStyle(color: Colors.white), ), onPressed: () { Navigator.of(context).pop(); }, ), ], ), ); }); } </code></pre>
[ { "answer_id": 74165090, "author": "br00t", "author_id": 4028717, "author_profile": "https://Stackoverflow.com/users/4028717", "pm_score": 2, "selected": false, "text": "dput" }, { "answer_id": 74165108, "author": "user7264", "author_id": 16085883, "author_profile": "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6438473/" ]
74,164,790
<p>need script for reboot modem when packet loss &gt; 70 i see it:</p> <pre><code> a=&quot;$(ping -c10 &quot;host&quot; | awk 'END{print}' | awk '{ print $7 }' | sed s/%//g)&quot;; b=70; if [ &quot;$a&quot; -gt &quot;$b&quot; ]; then echo &quot;trouble ping&quot; #reboot modem else echo &quot;ping ok&quot; fi </code></pre> <p>When the host does not answer first str = 100 (without &quot;%&quot;) its correct, but when he answers the output is empty (why not 0), i can't understand the reason</p>
[ { "answer_id": 74165090, "author": "br00t", "author_id": 4028717, "author_profile": "https://Stackoverflow.com/users/4028717", "pm_score": 2, "selected": false, "text": "dput" }, { "answer_id": 74165108, "author": "user7264", "author_id": 16085883, "author_profile": "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20300777/" ]
74,164,805
<p>If I have this:</p> <pre><code> vol=list() ;df=data.frame(name=c(5,2,15,4),name=c(2,0,1,2)) </code></pre> <p>I want to add this to vol, I tried but</p> <pre><code> vol[[1]]= unclass(df) </code></pre> <p>The output is not what i wanted</p> <p>I need the out put to be like this:</p> <pre><code>$name (i need to add this title here, the first name) name name.1 5 2 2 0 15 1 4 2 </code></pre>
[ { "answer_id": 74165090, "author": "br00t", "author_id": 4028717, "author_profile": "https://Stackoverflow.com/users/4028717", "pm_score": 2, "selected": false, "text": "dput" }, { "answer_id": 74165108, "author": "user7264", "author_id": 16085883, "author_profile": "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11101169/" ]
74,164,827
<p>I can't figure out why my code couldn't work.</p> <pre><code>from tkinter import * &quot;&quot;&quot; We need the Pillow library (or PIL) to import images in out application) I need to import both ImageTk and Image &quot;&quot;&quot; from PIL import ImageTk, Image &quot;&quot;&quot; doens't work at the moment bc I can't figure out what's wrong with PIL &quot;&quot;&quot; root = Tk() root.title(&quot;Icono, Boton Exit y Imagenes&quot;) root.geometry(&quot;200x100&quot;) ''' root.iconbitmap(&quot;c:/gui/codemy.ico&quot;) this is to put a personalized icon to the window application ''' my_img = imageTk.PhotoImage(Image.open(&quot;something.png&quot;)) my_label = Label(image=my_img) my_label.pack() button_quit = Button(root, text=&quot;Salir del programa&quot;, command=root.destroy) button_quit.pack() &quot;&quot;&quot; https://www.geeksforgeeks.org/how-to-close-a-tkinter-window-with-a-button/ for other examples of exit button also command=root.quit &quot;&quot;&quot; root.mainloop() </code></pre> <p>I tried to look it up around and from what I've been asked by others, I don't have two Python versions installed;</p> <p>I installed Pillow;</p> <p>And PIL I couldn't install since pip could not find it.</p> <p>I'm not sure what to try next.</p> <p>Thank you for reading my question.</p> <p>EDIT: This is the traceback.</p> <blockquote> <p>Traceback (most recent call last):</p> <p>File &quot;F:\python ejercicios\TkIconsImagesExitButtons.py&quot;, line 6, &gt;in </p> <p>from PIL import ImageTk, Image</p> <p>ModuleNotFoundError: No module named 'PIL'</p> </blockquote> <p>Edit2: These are the warnings which I Kind of find confusing?</p> <blockquote> <p>Line 6 : Name &quot;Image&quot; already defined (possibly by an import)</p> <p>Line 6 : Unused ImageTk imported from PIL It looks like the imported module or variable is not used.</p> <p>Line 22 : Name &quot;imageTk&quot; is not defined</p> <p>Line 22 : &quot;Type[Image]&quot; has no attribute &quot;open&quot;</p> </blockquote> <p>Final edit: Found the problem. Thanks to those who tried to help me out.</p>
[ { "answer_id": 74164967, "author": "Aditya Tripathi ", "author_id": 20309204, "author_profile": "https://Stackoverflow.com/users/20309204", "pm_score": 2, "selected": true, "text": "my_img = ImageTk.PhotoImage(Image.open(\"something.png\"))" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11488000/" ]
74,164,843
<pre><code>#include &lt;stdio.h&gt; #include&lt;math.h&gt; int main() { int n; int x; printf(&quot;enter base&quot;); scanf(&quot;%d&quot;,&amp;x); printf(&quot;number of tearms&quot;); scanf(&quot;%d&quot;,&amp;n); float sum=1.00; int fact=1; int s=1; int p=1; for(int i=1;i&lt;=n;i++) { s =s*(-1); int z=2*i; p =pow(x,z); fact =fact*2*i*(2*i-1); int k=s*p/fact; sum =sum+k; } printf(&quot;the sum is : %0.2f&quot;,sum); } </code></pre> <p>The logic and everything is correct, but I don't know why the output is getting an error. after getting some feedbacks i rectified some errors. now the out put is showing -1.00 for every input.</p>
[ { "answer_id": 74164967, "author": "Aditya Tripathi ", "author_id": 20309204, "author_profile": "https://Stackoverflow.com/users/20309204", "pm_score": 2, "selected": true, "text": "my_img = ImageTk.PhotoImage(Image.open(\"something.png\"))" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74164843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309286/" ]
74,164,850
<p>I want to use <code>%random% %%118</code> to pick a random variable from a number of variables called &quot;song1&quot; through &quot;song118&quot; Here's my current code:</p> <pre><code>@ECHO off TITLE Music Randomize SET count=0 GOTO cont :func ECHO %1 SET /A count+=1 SET &quot;song%count%=%1&quot; GOTO :eof :cont FOR %%F IN (C:\Users\153651\Desktop\usic\*) DO CALL :func &quot;%%F&quot; ECHO %song%random% %%118 +1% PAUSE </code></pre> <p>Right now the last ECHO command gives me the output <code>&quot;random18 +1&quot;</code>. How can I get it to output a random one of the variables?</p>
[ { "answer_id": 74164986, "author": "Marc", "author_id": 1024832, "author_profile": "https://Stackoverflow.com/users/1024832", "pm_score": -1, "selected": false, "text": "set SONG=TaylorSwift\n\nREM Choose a random number between 1 and 118\nset /a SONGNUM=%RANDOM% * 118 / 32768 + 1\n\nREM...
2022/10/22
[ "https://Stackoverflow.com/questions/74164850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309312/" ]
74,164,854
<p>Problem showcase<br /> <a href="https://i.stack.imgur.com/ofEur.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ofEur.png" alt="enter image description here" /></a></p> <p>I've just started to code in python and coded a calculator (its unfinished atm) it works fine except for the fact that &quot;none&quot; keeps popping up in the output. Here is my code.</p> <pre><code>num1 = float(input(print(&quot;Enter the first value &quot;))) num2 = float(input(print(&quot;Enter the second value &quot;))) operator = input(&quot;Enter the operator you want to calculate with;+,-,* &quot;) sum = num1+num2 product = num1*num2 difference = num1-num2 if operator == &quot;+&quot;: print(sum) elif operator==&quot;*&quot;: print(product) else: print(difference) </code></pre> <p>Output:</p> <pre><code>None 1 Enter the second value None 2 Enter the operator you want to calculate with;+,-,* 3.0 </code></pre> <p>Any fixes available for this? I've seen another query with the same issue but different code so I didn't understand that a bit.</p>
[ { "answer_id": 74164901, "author": "m2r105", "author_id": 18164421, "author_profile": "https://Stackoverflow.com/users/18164421", "pm_score": 1, "selected": false, "text": "num1 = float(input(\"Enter the first value \")) \nnum2 = float(input(\"Enter the second value \"))\noperator = inpu...
2022/10/22
[ "https://Stackoverflow.com/questions/74164854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309309/" ]
74,164,859
<p>I have this table <code>Test</code>:</p> <pre><code>ID - int primary key not null, CODE - nvarchar(max), NAME - nvarchar(max) </code></pre> <p>It has clustered index on <code>ID</code>.</p> <p>But in an execution plan, the search uses <code>ID</code> and <code>CODE</code> columns.</p> <p>How can I add non-clustered index to the table? When I try, I get an error:</p> <blockquote> <p>Column code in table Test is of a type that is invalid for use as a key column in an index</p> </blockquote> <p>Could you recommend what actions must be done?</p> <p>I need to add the index for the query fast processing.</p> <p>There is already clustered index which is not effective in query processing.</p> <p>In SSMS, for creating NON-CLUSTERED INDEX - the only option was to add <code>ID</code> as key column and then to add CODE as <code>Include</code> in the index. But it means that table will have both CLUSTERED INDEX on ID column and NON-CLUSTERED INDEX on ID with CODE include. Is that right?</p> <p>What is the best practice:</p> <ul> <li>If table can have both clustered and non-clustered indexes basing on same id key column?</li> <li>How should you do for fixing the problem?</li> </ul>
[ { "answer_id": 74164901, "author": "m2r105", "author_id": 18164421, "author_profile": "https://Stackoverflow.com/users/18164421", "pm_score": 1, "selected": false, "text": "num1 = float(input(\"Enter the first value \")) \nnum2 = float(input(\"Enter the second value \"))\noperator = inpu...
2022/10/22
[ "https://Stackoverflow.com/questions/74164859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6172639/" ]
74,164,866
<p>I'm using <code>aiohttp</code> to get and test proxies (creating my first package <a href="https://github.com/555Russich/proxy_master" rel="nofollow noreferrer">proxy-master</a>)</p> <p>I want to write function which would handle <code>ClientResponse</code> after calling <code>.gather()</code> like that:</p> <pre><code>async def async_test_proxies(proxies: list, url: str = 'icanhazip.com', enable_prints: bool = False) -&gt; list: def is_proxy_works(html: str, proxy: str, url: str, enable_prints: bool) -&gt; bool: ... proxies_works = [] async with ClientSession() as s: tasks = [asyncio.create_task(session_request(s, url, proxy)) for proxy in proxies] results = await asyncio.gather(*tasks, return_exceptions=True) for i in range(len(results)): r = handle_response(results[i]) if type(r) is str: if is_proxy_works(r, proxies[i], url, enable_prints) is True: proxies_works.append(proxies[i]) print(f'{len(proxies_works)}/{len(proxies)} proxies works') if enable_prints else ... return proxies_works async def session_request(s: ClientSession, url: str, proxy: str, timeout: int = 3) -&gt; ClientResponse: async with s.get( f'https://{url}', proxy=f'http://{proxy}', timeout=timeout ) as r: return r def handle_response(r: ClientResponse) -&gt; bool | str: match r.status: case 200: return str(r.text()) case _: return False print(test_proxies(get_proxies_from_txt(), enable_prints=True)) </code></pre> <p><strong>Error</strong>:</p> <pre><code>RuntimeWarning: coroutine 'ClientResponse.text' was never awaited return str(r.text()) RuntimeWarning: Enable tracemalloc to get the object allocation traceback </code></pre> <p><strong>Question</strong>: Why coroutine <code>ClientResponse.text</code> was never awaited if i used await here</p> <p><code>results = await asyncio.gather(*tasks, return_exceptions=True)</code></p> <p>to wait results? Any possible to write <code>responseHandler</code> function...?</p> <p><strong>Question_2</strong>: offtop but.. Does <code>.gather()</code> guarantee to return responses in the same sequence as input tasks?</p>
[ { "answer_id": 74164901, "author": "m2r105", "author_id": 18164421, "author_profile": "https://Stackoverflow.com/users/18164421", "pm_score": 1, "selected": false, "text": "num1 = float(input(\"Enter the first value \")) \nnum2 = float(input(\"Enter the second value \"))\noperator = inpu...
2022/10/22
[ "https://Stackoverflow.com/questions/74164866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15637940/" ]
74,164,875
<p>I was trying to pass a variable from parent component to child component. For this purpose, I wanted to use <code>@Input()</code> <a href="https://angular.io/guide/inputs-outputs" rel="nofollow noreferrer">method</a> but when I tried to connect the two component, I got a blank page in whole site. Simply, web site doesn't respond at all.</p> <p>I write the code below to parent.html</p> <pre><code>&lt;app-test [id] = &quot;id&quot; [name]=&quot;name&quot; [request]=&quot;request&quot; [label]=&quot;label&quot;&gt;&lt;/app-test&gt; </code></pre> <p>Then, I add the input methods into test.ts (child)</p> <pre><code>import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.component.css'] }) export class TestComponent implements OnInit { @Input() id =-1; @Input() name=''; @Input() request=''; @Input() label=''; parameters:any=[]; countryId:number=0; apiList:any; constructor() { } ngOnInit(): void { } } </code></pre> <p>And then, I got a blank page. No error at the start but after 30 seconds, I got the error below in inspector console. Can you help me out please?</p> <pre><code>Uncaught (in promise): RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded </code></pre> <p>Edit: My parent component:</p> <pre><code>import { Component, OnInit } from '@angular/core'; import {MenuItem} from 'primeng/api'; import { TheDataOfEverythingService } from 'src/app/service/the-data-of-everything.service'; @Component({ selector: 'app-header', templateUrl: './header.component.html', styleUrls: ['./header.component.css'] }) export class HeaderComponent implements OnInit { display:boolean = false; items: MenuItem[]=[]; sidebarItems: MenuItem[]=[]; id:number=-1; name:string=''; request:string=''; label:string=''; constructor(private service:TheDataOfEverythingService) { } ngOnInit(): void { this.getApiList(); this.items = [ { label:'Home', icon:'pi pi-fw pi-home', routerLink: '/home' }, { label:'Contact', icon:'pi pi-fw pi-phone', routerLink: ['/contact'], }, { label:'Sign Up', icon:'pi pi-fw pi-user-plus' } ]; this.sidebarItems = [ { label:'World', icon:'pi pi-fw pi-globe', items: [] }, ] } apiList:MenuItem[]=[]; getApiList(){ this.service.getAllData(&quot;ApiList&quot;) .subscribe(data=&gt; { this.apiList = data as MenuItem[]; let index; this.apiList.forEach(item=&gt;{ const newMenuItem: MenuItem ={ label: item.label, //icon: item.icon, routerLink: item.routerLink } if(newMenuItem.routerLink.includes('world')){ index = this.sidebarItems.findIndex(e=&gt; e.label == &quot;World&quot;) this.sidebarItems[index].items?.push(newMenuItem); } }) }); } } </code></pre> <p>edit 2: HTML of my parent component:</p> <pre><code>&lt;p-menubar [model]=&quot;items&quot;&gt; &lt;ng-template pTemplate=&quot;start&quot;&gt; &lt;a (click)=&quot;display = true&quot;&gt; &lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/f/f2/Noun_Data_2223266.svg&quot; height=&quot;40&quot; class=&quot;mr-2&quot;&gt; &lt;/a&gt; &lt;/ng-template&gt; &lt;ng-template pTemplate=&quot;end&quot;&gt; &lt;input type=&quot;text&quot; pInputText placeholder=&quot;Search&quot;&gt; &lt;/ng-template&gt; &lt;/p-menubar&gt; &lt;p-sidebar [(visible)]=&quot;display&quot;&gt; &lt;p-panelMenu [model]=&quot;sidebarItems&quot; [style]=&quot;{'width':'280px'}&quot;&gt;&lt;/p-panelMenu&gt; &lt;/p-sidebar&gt; &lt;app-test [id] = &quot;id&quot; [name]=&quot;name&quot; [request]=&quot;request&quot; [label]=&quot;label&quot;&gt;&lt;/app-test&gt; </code></pre>
[ { "answer_id": 74164901, "author": "m2r105", "author_id": 18164421, "author_profile": "https://Stackoverflow.com/users/18164421", "pm_score": 1, "selected": false, "text": "num1 = float(input(\"Enter the first value \")) \nnum2 = float(input(\"Enter the second value \"))\noperator = inpu...
2022/10/22
[ "https://Stackoverflow.com/questions/74164875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16002501/" ]
74,164,893
<p>I have been trying to solve this problem for more than a week, but finally I am forced to ask for help.</p> <p>I am just implementing a search filter in Vue 2, using Vuetify, but something is going wrong</p> <p>This is how the search filter looks:</p> <pre><code> &lt;v-text-field v-model=&quot;search&quot; label=&quot;Look for name...&quot;&gt;&lt;/v-text-field&gt; </code></pre> <p>I have a variable called search in the component data that is two-binding with the text-field v-model</p> <p>Secondly, I have an array of items:</p> <pre><code>items: [ { default: true, name: 'Text 1', }, { default: false, name: 'Text 2', }, { default: false, name: 'Text 3', }, { default: false, name: 'Text 4', }, ], </code></pre> <p>I render the list in a div using v-for</p> <pre><code>&lt;div v-for=&quot;(item, index) in filteredItems&quot;&gt; &lt;div style=&quot;display: flex&quot;&gt; &lt;input type=&quot;radio&quot; :checked=&quot;item.default&quot; @click=&quot;changeDefault(item, index)&quot; /&gt; &lt;h1&gt;{{ item.name }}&lt;/h1&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is how the component looks: <a href="https://i.stack.imgur.com/mYRvX.png" rel="nofollow noreferrer">List and search filter rendered</a></p> <p>How the filter works? Here is the code</p> <pre><code>filteredItems() { if (this.search) { return this.items.filter((item) =&gt; { return item.name.toLowerCase().match(this.search); }); } else { return this.items; } }, </code></pre> <p>As you can see in the rendered list, items have a radio button which can be selected. When some of them are clicked, we call a function called <em>changeDefault</em> whose code is this (just get the default true item and set it to false, and the new one to true)</p> <pre><code>changeDefault(item, index) { let indexOfDefaultTrue = this.items.findIndex((item) =&gt; item.default === true); this.items[indexOfDefaultTrue].default = false; this.items[index].default = true; }, </code></pre> <p>All seems to be working, but the issue is that, if i search for Text 2 (for instance) and click the radio button, it turns to active, but when i clear the filter, it seems like nothing happened It only happens if i use the search method, if i click an item on the initial list, radio button changes properly. <a href="https://i.stack.imgur.com/vxYaY.png" rel="nofollow noreferrer">Text 2 search</a> <a href="https://i.stack.imgur.com/iGkRa.png" rel="nofollow noreferrer">After i clear the search</a></p> <p>It looks like the list didnt render the new items or something like that? Im big stucked. Thank you very much, i wish someone can help me!</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;template&gt; &lt;v-app&gt; &lt;v-main&gt; &lt;v-text-field v-model="search" label="Look for name..."&gt;&lt;/v-text-field&gt; &lt;div v-for="(item, index) in filteredItems"&gt; &lt;div style="display: flex"&gt; &lt;input type="radio" :checked="item.default" @click="changeDefault(item, index)" /&gt; &lt;h1&gt;{{ item.name }}&lt;/h1&gt; &lt;/div&gt; &lt;/div&gt; &lt;/v-main&gt; &lt;/v-app&gt; &lt;/template&gt; &lt;script&gt; export default { name: 'App', components: {}, data: () =&gt; ({ search: '', items: [ { default: true, name: 'Text 1', }, { default: false, name: 'Text 2', }, { default: false, name: 'Text 3', }, { default: false, name: 'Text 4', }, ], }), methods: { changeDefault(item, index) { console.log(item); let indexOfDefaultTrue = this.items.findIndex((item) =&gt; item.default === true); console.log(indexOfDefaultTrue); this.items[indexOfDefaultTrue].default = false; this.items[index].default = true; console.log(this.items); }, }, computed: { filteredItems() { if (this.search) { return this.items.filter((item) =&gt; { return item.name.toLowerCase().match(this.search); }); } else { return this.items; } }, }, }; &lt;/script&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74165332, "author": "Adam Edney", "author_id": 2847349, "author_profile": "https://Stackoverflow.com/users/2847349", "pm_score": 1, "selected": true, "text": "function changeDefault(clickedItem) {\n \n let indexOfDefaultTrue = items.findIndex((item) => item.default...
2022/10/22
[ "https://Stackoverflow.com/questions/74164893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15961129/" ]
74,164,896
<p>My website receives some text through API call and that value is displayed on textarea on the page. I want to run a function to perform some tasks after the value is set to textarea. But I don't see any event triggering when setting textarea value through program. I cannot find any related questions, solutions or articles regarding this.</p> <p>Below is the demonstration of the problem I am facing.</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>txt.onchange = () =&gt; { alert("textarea changed (onchange event)"); } txt.onkeyup = () =&gt; { alert("textarea changed (onkeyup event)"); } txt.onkeydown = () =&gt; { alert("textarea changed (onkeydown event)"); } txt.oninput = () =&gt; { alert("textarea changed (oninput event)"); } changetxt.onclick = () =&gt; { txt.value = "value is set programmetically."; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;textarea id="txt" rows="10"&gt;&lt;/textarea&gt; &lt;button id="changetxt"&gt;Update Textarea&lt;/button&gt;</code></pre> </div> </div> </p> <p>I want some way to detect textarea value is changed through program.</p>
[ { "answer_id": 74165159, "author": "amer", "author_id": 5072590, "author_profile": "https://Stackoverflow.com/users/5072590", "pm_score": 0, "selected": false, "text": "const { get, set } = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');\nconst t = document.getEl...
2022/10/22
[ "https://Stackoverflow.com/questions/74164896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9045600/" ]
74,164,914
<p>Android - Display Int onClick with Buttons increment , decremet [Error: Cannot resolve method β€˜display(int)’ ] I am getting a error on Android Studio as what I believe is because I'm inserting multiple 'displays'. Can someone advise &amp; explain what I need to do and why it causes this error so I know for future?</p> <p>Please see below for the following error:</p> <pre><code>package com.example.justjava; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.text.NumberFormat; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView num = findViewById(R.id.num); Button order1 = findViewById(R.id.order); /** * This method is called when the plus button is clicked. */ public void increment (View view) { int quantity = 2; display(quantity); } /** * This method is called when the minus button is clicked. */ public void onClick (View view) { int quantity = 2; display(quantity); } /** * This method is called when the order button is clicked. */ order1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int quantity = 2; display1(quantity); displayPrice(quantity*5); } /** * This method displays the given price on the screen. */ private void displayPrice(int number) { TextView priceTextView = (TextView) findViewById(R.id.price_text_view); priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); } /** * This method displays the given quantity value on the screen. */ private void display1(int number) { // TextView quantity = (TextView) findViewById(R.id.quantity); num.setText(&quot;&quot; + number); } }); } } </code></pre>
[ { "answer_id": 74165159, "author": "amer", "author_id": 5072590, "author_profile": "https://Stackoverflow.com/users/5072590", "pm_score": 0, "selected": false, "text": "const { get, set } = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');\nconst t = document.getEl...
2022/10/22
[ "https://Stackoverflow.com/questions/74164914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20074099/" ]
74,164,919
<p>I created a new VUE 3 and typescript application using vite. I later installed primevue and primeflex. When I run npm run dev, I get the error seen below:</p> <p><a href="https://i.stack.imgur.com/YPmv6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YPmv6.png" alt="enter image description here" /></a></p> <p>How do I fix this? My <a href="https://github.com/isogunro/my-app" rel="nofollow noreferrer">repo</a>, if that will shed light.</p>
[ { "answer_id": 74212757, "author": "Fabian Wagner - a6a2f5842", "author_id": 8592812, "author_profile": "https://Stackoverflow.com/users/8592812", "pm_score": 2, "selected": false, "text": "npm install --save-dev sass\n" }, { "answer_id": 74234828, "author": "mohammad", "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6462490/" ]
74,164,947
<p>How do I change the default rows per page (5) using the standard MIU Pagination from <code>import Pagination from '@mui/material/Pagination';</code>? I want to show 10 rows per page but looking through the documentation I couldn't find a prop to handle this.</p> <pre><code> &lt;Pagination count={props.totalPages} page={props.pageNo} onChange={props.handleClick} /&gt; </code></pre>
[ { "answer_id": 74212757, "author": "Fabian Wagner - a6a2f5842", "author_id": 8592812, "author_profile": "https://Stackoverflow.com/users/8592812", "pm_score": 2, "selected": false, "text": "npm install --save-dev sass\n" }, { "answer_id": 74234828, "author": "mohammad", "...
2022/10/22
[ "https://Stackoverflow.com/questions/74164947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6263953/" ]
74,164,948
<p>I want to check if there is a value in a certain variable I have. Below I put an example of a logic that I want to achieve.</p> <p>No matter how hard I tried, I was able to write a very sketchy code as a result of 3 hours of work and research, but it has nothing to do with what I want to achieve.</p> <p>My Code:</p> <pre class="lang-js prettyprint-override"><code>const Files = [ { Name: 'System', Type: 'directory', Value: [ { Name: 'Main', Type: 'directory', Value: [ { Name: 'Drivers', Type: 'directory', Value: [ { Name: 'Startup', Type: 'file', Value: new FileSystem.File('Startup', 0x1, 'test blah blah'), }, ], }, ], }, ], }, ]; BlahBlah.has(Files, 'System-&gt;Main-&gt;Drivers'); // [File] BlahBlah.has(Files, 'System-&gt;Main-&gt;Drivers-&gt;Startup'); // File BlahBlah.has(Files, 'System-&gt;Main-&gt;Drivers-&gt;AnyWhere'); // undefined BlahBlah.has(Files, 'System-&gt;Main-&gt;AnyRandomDirectory'); // NaN </code></pre> <p>My Function:</p> <pre class="lang-js prettyprint-override"><code>function text2Binary(str: string, spliter: string = ' '): string { return str .split('') .map(function (char) { return char.charCodeAt(0).toString(2); }) .join(spliter); } export function FileTypeFromNumber(e: number) { if (typeof e != 'number') try { e = Number(e); } catch (_) { return null; } return { 0x1: { Name: 'Executable File', Extension: 'exe', }, 0x2: { Name: 'Text Document', Extension: 'txt', }, }[e]; } export type FileTypes = | 0x1 | 0x2 | 0x3 | 0x4 | 0x5 | 0x6 | 0x7 | 0x8 | 0x9 | null; export class File { Name: string; Type: { Name: string; Extension: string; }; Content: string; Size: number; constructor(name: string, type: FileTypes, content: string) { this.Name = name; this.Type = FileTypeFromNumber(type); this.Content = content; this.Size = text2Binary(content, '').length; } } export class Directory { public Name: string; public Files: (File | Directory)[] = []; constructor(name: string) { this.Name = name; } addFile(file: File | Directory) { this.Files.push(file); } getFile(name: string): null | (File | Directory)[] { if (typeof name != 'string') try { name = String(name); } catch (_) { return null; } const Result = this.Files.filter((e) =&gt; e.Name == name); return Result.length == 0 ? null : Result; } getSize() { return this.Files.map((e) =&gt; e instanceof Directory ? e.getSize() : e.Size ).reduce((a, b) =&gt; a + b, 0); } has(name) { return this.Files.some((e) =&gt; e.Name == name); } getJSON() { return this.Files.map((e) =&gt; ({ ...e })); } } interface x { Content: string; Name: string; Size: number; Type: string; } export function ConvertFromJSONtoDirectory(json: any[]) { return json.map((value) =&gt; { const isDirectory = value.Type == 'directory'; if (!isDirectory) { return value.Value; } const self = new Directory(value.Name); ConvertFromJSONtoDirectory(value.Value).map((e) =&gt; self.addFile(e)); return self; }); } export default class DirectorySystem { Memory: Map&lt;any, any&gt;; Current: string | null; constructor(Current = null) { this.Memory = new Map(); this.Current = Current; } addDirectory(directory: Directory): null | true { if (!(directory instanceof Directory)) return null; if (this.Memory.has(directory.Name)) return null; this.Memory.set(directory.Name, directory); return true; } getDirectory(DirectoryName: string): boolean | Directory { if (typeof DirectoryName != 'string') try { DirectoryName = String(DirectoryName); } catch (_) { return null; } const Result = this.Memory.has(DirectoryName); return Result ? this.Memory.get(DirectoryName) : Result; } getDirectoryCurrent() { if (this.Current == null) return this; } changeDirectory(by: -1 | 1, value: string) { if (by == -1) { if (this.Current == null) return null; if (this.Current.includes('-&gt;')) { this.Current = this.Current.split('-&gt;').slice(0, -1).join('-&gt;'); } else { this.Current = null; } return this.Current; } else if (by == 1) { let Position = [this.Current, value].join('-&gt;'); if (this.Current == null) { Position = Position.split('-&gt;').slice(1).join('-&gt;'); } let Result = this.has(Position); console.log(Result); } } has(query: string) { try { return query.split('-&gt;').reduce((a, b) =&gt; { if (Array.isArray(a)) { const f = a.filter((e) =&gt; e['Name'] == b); if (a.length &gt; 0) { return f['Files']; } else { return a; } } return a['Files']; }, this.getJSON()); } catch (_) { return false; } } getJSON(): x[][] { return [...this.Memory.values()].reduce((a, b) =&gt; { a[b.Name] = b.getJSON(); return a; }, {}); } } </code></pre> <p>Result: (Thanks Michael M. and chill 389cc for helping me understand the error)</p> <pre class="lang-js prettyprint-override"><code>has( query: string, overwrite = null ) { // If overwrite argument is not null, we are going use it. let files = overwrite == null ? this.getJSON() : overwrite; // Split string for getting more usable type with converting string to Array. const QueryParams = query.split('-&gt;').filter(String); // If we dont have no query, we can return current status. if (QueryParams.length == 0) return overwrite; if (Array.isArray(files)) { const SearchFor = QueryParams.shift(); const Result = files.filter((e) =&gt; { if (e instanceof Directory) { const x = e.Name == SearchFor; return x ? e : false; } return e.Name == SearchFor; })[0]; // If we cant find any indexing result if (!Result) return false; // We found a file and if we dont have any query this is mean we found it! if (Result instanceof File) return QueryParams.length == 0; // We found a Directory and we doesnt have any Query now, so we can return true. if (Result instanceof Directory &amp;&amp; QueryParams.length == 0) return true; if ( Result.Name != SearchFor || (QueryParams.length != 0 &amp;&amp; Result.Files.length == 0) ) // If name not suits or still we has Query and not enough file for indexing. return false; // If nothing happens on upper section, return rescyned version of this function. return this.has(QueryParams.join('-&gt;'), Result.Files); } else { // If value is Object, Try Search param in object, and return it. const Result = files[QueryParams.shift()]; return !Result ? false : this.has(QueryParams.join('-&gt;'), Result); } } </code></pre>
[ { "answer_id": 74165215, "author": "Michael M.", "author_id": 13376511, "author_profile": "https://Stackoverflow.com/users/13376511", "pm_score": 2, "selected": true, "text": "interface Entry {\n Name: string,\n Type: string,\n Value: Array<Entry> | any,\n};\n\nconst Files = [\n {\n ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18084063/" ]
74,164,953
<p>Given the following code:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;algorithm&gt; #include &lt;cstddef&gt; #include &lt;iterator&gt; #include &lt;source_location&gt; template&lt;std::size_t N&gt; struct StringWrapper { // consteval to force only compile-time strings consteval StringWrapper(const char (&amp;format_string)[N], std::source_location source_location = std::source_location::current()) : SourceInfo{ source_location } { std::copy(std::begin(format_string), std::end(format_string), std::begin(FormatString)); } char FormatString[N]{}; // This here to motivate not using StringWrapper as non-type template argument std::source_location SourceInfo{}; }; // class-template-argument-deduction is not necessary here, see the first case in main // variadic template, thus putting std::source_location at the end is not an option template&lt;std::size_t N, class... Args&gt; void log(StringWrapper&lt;N&gt; format_string, Args&amp;&amp;... args); int main() { log(StringWrapper{ &quot;This {}, explicitly instantiating, but deducing the parameter&quot; }, &quot;works&quot;); log(&quot;This {}, could not match 'StringWrapper&lt;N&gt;' against 'const char *'&quot;, &quot;fails&quot;); } </code></pre> <p>What could be a possible workaround to this issue that would not require a change on the callsite?</p> <p>One possibility is to use a <code>std::string_view</code>, however that would not give me access to <code>N</code> as a constant expression in the implementation of <code>log</code> and is thus not an option in my case.</p> <p>Another possibility is to directly take a <code>const char (&amp;)[N]</code>, however then I am losing the <code>std::source_location</code> which is not an option either.</p> <p>I understand why overload resolution would favor a function that takes a <code>const char*</code> over a function that takes a <code>const char (&amp;)[N]</code>, however I do not understand why 'StringWrapper' is not even attempted to match against 'const char (&amp;)[N]' however.</p>
[ { "answer_id": 74165450, "author": "apple apple", "author_id": 5980430, "author_profile": "https://Stackoverflow.com/users/5980430", "pm_score": 2, "selected": false, "text": "log" }, { "answer_id": 74171931, "author": "apple apple", "author_id": 5980430, "author_prof...
2022/10/22
[ "https://Stackoverflow.com/questions/74164953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4861523/" ]
74,164,965
<pre><code>let zed = [ { name: 'tom', stat1: undefined, stat2: 3 }, { name: 'nic', stat1: undefined, stat2: undefined }, { name: 'joe', stat1: 5, stat2: undefined }, ] zed.forEach((value, index, array) =&gt; { Object.keys(value).forEach(key =&gt; { array[index][key] = array[index][key] === undefined ? 0 : array[index][key]; }); }); </code></pre> <p>The code above works but we are concerned about performance on much larger arrays of objects in our react application. Also not sure if mutating the array inside of a <code>forEach()</code> is considered a bad practice in React, perhaps it is better to create a new array somehow with <code>.map()</code>. Any recommendations on the best way to replace <code>undefined</code> with <code>0</code>?</p>
[ { "answer_id": 74165011, "author": "Haim Abeles", "author_id": 15298697, "author_profile": "https://Stackoverflow.com/users/15298697", "pm_score": 2, "selected": false, "text": "JSON.stringfy()" }, { "answer_id": 74165017, "author": "mscdeveloper", "author_id": 8656248, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5573294/" ]
74,164,983
<p>Using AlpineJS I am submitting a form and displaying error messages when the API return an error:</p> <pre><code> &lt;form x-data=&quot;inquiry()&quot; x-on:submit.prevent=&quot;submit&quot; method=&quot;post&quot;&gt; &lt;label&gt;Name&lt;/label&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; x-model=&quot;data.name.value&quot;&gt; &lt;span x-show=&quot;data.name.error !== null&quot; x-text=&quot;data.name.error&quot;&gt;&lt;/span&gt; &lt;label&gt;Email&lt;/label&gt; &lt;input type=&quot;text&quot; name=&quot;email&quot; x-model=&quot;data.email.value&quot;&gt; &lt;span x-show=&quot;data.email.error !== null&quot; x-text=&quot;data.email.error&quot;&gt;&lt;/span&gt; &lt;button&gt;Submit&lt;/button&gt; &lt;/form&gt; &lt;script type=&quot;text/javascript&quot;&gt; function inquiry() { return { data: { name: { value: &quot;&quot;, error: null }, email: { value: &quot;&quot;, error: null } }, submit() { fetch(&quot;/inquiries&quot;, { method: &quot;POST&quot;, headers: { &quot;Accept&quot;: &quot;application/json&quot;, &quot;Content-Type&quot;: &quot;application/json&quot; }, body: JSON.stringify({ name: this.data.name.value, email: this.data.email.value }) .then((response) =&gt; { if (response.ok) { } else { response.json().then((body) =&gt; { for (const key in this.data) this.data[key].error = body.errors.find(x =&gt; x.source.toLowerCase() == key.toLowerCase()) ?? null; }); } }) } }; } &lt;/script&gt; </code></pre> <p>When I submit the form with errors I get the response:</p> <pre><code>{ &quot;errors&quot;: [ { &quot;source&quot;: &quot;Email&quot;, &quot;detail&quot;: &quot;The email is invalid&quot; }, { &quot;source&quot;: &quot;Name&quot;, &quot;detail&quot;: &quot;The name is required&quot; }, ] } </code></pre> <p>But, for example, the <code>span</code> that would show the error detail for <code>name</code> renders:</p> <pre><code>[object Object] </code></pre> <p>What am I missing?</p>
[ { "answer_id": 74165011, "author": "Haim Abeles", "author_id": 15298697, "author_profile": "https://Stackoverflow.com/users/15298697", "pm_score": 2, "selected": false, "text": "JSON.stringfy()" }, { "answer_id": 74165017, "author": "mscdeveloper", "author_id": 8656248, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74164983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/577805/" ]
74,165,004
<p>i have 2d list implementation as follows. It shows no. of times every student topped in exams:-</p> <pre><code> list = main_record ['student1',1] ['student2',1] ['student2',2] ['student1',5] ['student3',3] </code></pre> <p>i have another list of unique students as follows:-</p> <pre><code> list = students_enrolled ['student1','student2','student3'] </code></pre> <p>which i want to display student ranking based on their distinctions as follows:-</p> <pre><code> list = student_ranking ['student1','student3','student2'] </code></pre> <p>What built in functions can be useful. I could not pose proper query on net. In other words i need python equivalent of following queries:-</p> <pre><code>select max(main_record[1]) where name = student1 &gt;&gt;&gt; result = 5 select max(main_record[1]) where name = student2 &gt;&gt;&gt; result = 2 select max(main_record[1]) where name = student3 &gt;&gt;&gt; result = 3 </code></pre>
[ { "answer_id": 74165106, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": true, "text": "dict" }, { "answer_id": 74165122, "author": "BokiX", "author_id": 16843389, "author_profile": "ht...
2022/10/22
[ "https://Stackoverflow.com/questions/74165004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1028289/" ]
74,165,015
<p>Is there a loop that will iterate through the siblings elements, if it gets to one of the studentscreening(see below) and that student does not have the tag being used, then input null/na ??</p> <p>Below is what is in my xml file [studentinfo.xml]:</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;StudentBreakdown&gt; &lt;Studentdata&gt; &lt;StudentScreening&gt; &lt;name&gt;Sam Davies&lt;/name&gt; &lt;age&gt;15&lt;/age&gt; &lt;hair&gt;Black&lt;/hair&gt; &lt;eyes&gt;Blue&lt;/eyes&gt; &lt;grade&gt;10&lt;/grade&gt; &lt;teacher&gt;Draco Malfoy&lt;/teacher&gt; &lt;dorm&gt;Innovation Hall&lt;/dorm&gt; &lt;/StudentScreening&gt; &lt;StudentScreening&gt; &lt;name&gt;Cassie Stone&lt;/name&gt; &lt;age&gt;14&lt;/age&gt; &lt;hair&gt;Science&lt;/hair&gt; &lt;grade&gt;9&lt;/grade&gt; &lt;teacher&gt;Luna Lovegood&lt;/teacher&gt; &lt;/StudentScreening&gt; &lt;StudentScreening&gt; &lt;name&gt;Derek Brandon&lt;/name&gt; &lt;age&gt;17&lt;/age&gt; &lt;eyes&gt;green&lt;/eyes&gt; &lt;teacher&gt;Ron Weasley&lt;/teacher&gt; &lt;dorm&gt;Hogtie Manor&lt;/dorm&gt; &lt;/StudentScreening&gt; &lt;/Studentdata&gt; &lt;/StudentBreakdown&gt; </code></pre> <p>My code is iterating through the studentinfo.xml file and inputting the information into a <code>pandas</code> dataframe(df1) per the columns I've mapped the tags to.</p> <p>Below is a sample of my code:</p> <pre><code>import pandas as pd from bs4 import BeautifulSoup with open('studentinfo.xml', 'r') as f: file = f.read() def parse_xml(file): soup = BeautifulSoup(file, 'xml') df1 = pd.DataFrame(columns=['StudentName', 'Age', 'Hair', 'Eyes', 'Grade', 'Teacher', 'Dorm']) all_items = soup.find_all('info') items_length = len(all_items) for index, info in enumerate(all_items): StudentName = info.find('&lt;name&gt;').text Age = info.find('&lt;age&gt;').text Hair = info.find('&lt;hair&gt;').text Eyes = info.find('&lt;eyes&gt;').text Grade = info.find('&lt;grade&gt;').text Teacher = info.find('&lt;teacher&gt;').text Dorm = info.find('&lt;dorm&gt;').text row = { 'StudentName': StudentName, 'Age': Age, 'Hair': Hair, 'Eyes': Eyes, 'Grade': Grade, 'Teacher': Teacher, 'Dorm': Dorm } df1 = df1.append(row, ingore_index=True) print(f'Appending row %s of %s' %(index+1, items_length)) return df1 </code></pre> <p>When I try to run the code I get this error: 'AttributeError: 'NoneType' object has no attribute 'text'' Which my conclusion as to why I was getting this error was because not every StudentScreening has the same child tags being used.</p> <p>What condition can be added to my code that says: &quot; As I am looping through, If an element tag is not present, input null in the dataframe and continue to enumerate over the file&quot; ??????</p>
[ { "answer_id": 74165106, "author": "I'mahdi", "author_id": 1740577, "author_profile": "https://Stackoverflow.com/users/1740577", "pm_score": 2, "selected": true, "text": "dict" }, { "answer_id": 74165122, "author": "BokiX", "author_id": 16843389, "author_profile": "ht...
2022/10/22
[ "https://Stackoverflow.com/questions/74165015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18696224/" ]
74,165,034
<p>Hoping to sort (below left) by sector but distribute evenly (below right):</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Name</th> <th>Sector.</th> <th>Name.</th> <th>Sector</th> </tr> </thead> <tbody> <tr> <td>A</td> <td>1</td> <td>A</td> <td>1</td> </tr> <tr> <td>B</td> <td>1</td> <td>E</td> <td>2</td> </tr> <tr> <td>C</td> <td>1</td> <td>H</td> <td>3</td> </tr> <tr> <td>D</td> <td>4</td> <td>D</td> <td>4</td> </tr> <tr> <td>E</td> <td>2</td> <td>B</td> <td>1</td> </tr> <tr> <td>F</td> <td>2</td> <td>F</td> <td>2</td> </tr> <tr> <td>G</td> <td>2</td> <td>J</td> <td>3</td> </tr> <tr> <td>H</td> <td>3</td> <td>I</td> <td>4</td> </tr> <tr> <td>I</td> <td>4</td> <td>C</td> <td>1</td> </tr> <tr> <td>J</td> <td>3</td> <td>G</td> <td>2</td> </tr> </tbody> </table> </div> <p>Real data is 70+ rows with 4 sectors.</p> <p>I've worked around it manually but would love to figure out how to do it with a formula in excel.</p> <p>Here's a more complete (and hopefully more accurate) idea - the carouselOrder is the column I'd like to generate via a formula.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>guestID</th> <th>guestSector</th> <th>carouselOrder</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>1</td> <td>5</td> </tr> <tr> <td>3</td> <td>1</td> <td>9</td> </tr> <tr> <td>4</td> <td>1</td> <td>13</td> </tr> <tr> <td>5</td> <td>2</td> <td>2</td> </tr> <tr> <td>6</td> <td>2</td> <td>6</td> </tr> <tr> <td>7</td> <td>2</td> <td>10</td> </tr> <tr> <td>8</td> <td>2</td> <td>14</td> </tr> <tr> <td>9</td> <td>3</td> <td>3</td> </tr> <tr> <td>10</td> <td>3</td> <td>7</td> </tr> <tr> <td>11</td> <td>3</td> <td>11</td> </tr> <tr> <td>12</td> <td>2</td> <td>18</td> </tr> <tr> <td>13</td> <td>1</td> <td>17</td> </tr> <tr> <td>14</td> <td>1</td> <td>20</td> </tr> <tr> <td>15</td> <td>1</td> <td>23</td> </tr> <tr> <td>16</td> <td>2</td> <td>21</td> </tr> <tr> <td>17</td> <td>2</td> <td>24</td> </tr> <tr> <td>18</td> <td>2</td> <td>27</td> </tr> <tr> <td>19</td> <td>1</td> <td>26</td> </tr> <tr> <td>20</td> <td>1</td> <td>29</td> </tr> <tr> <td>21</td> <td>1</td> <td>30</td> </tr> <tr> <td>22</td> <td>1</td> <td>31</td> </tr> <tr> <td>23</td> <td>3</td> <td>15</td> </tr> <tr> <td>24</td> <td>3</td> <td>19</td> </tr> <tr> <td>25</td> <td>3</td> <td>22</td> </tr> <tr> <td>26</td> <td>3</td> <td>25</td> </tr> <tr> <td>27</td> <td>3</td> <td>28</td> </tr> <tr> <td>28</td> <td>1</td> <td>32</td> </tr> <tr> <td>29</td> <td>4</td> <td>4</td> </tr> <tr> <td>30</td> <td>4</td> <td>8</td> </tr> <tr> <td>31</td> <td>4</td> <td>12</td> </tr> <tr> <td>32</td> <td>4</td> <td>16</td> </tr> </tbody> </table> </div>
[ { "answer_id": 74166312, "author": "P.b", "author_id": 12634230, "author_profile": "https://Stackoverflow.com/users/12634230", "pm_score": 2, "selected": false, "text": "D2" }, { "answer_id": 74169252, "author": "David Leal", "author_id": 6237093, "author_profile": "h...
2022/10/22
[ "https://Stackoverflow.com/questions/74165034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16240193/" ]
74,165,073
<p>I want to make a <code>div</code> appear smoothly as shown in the GIF below. I assume this can be done using CSS animation but I have never worked on CSS animation before.</p> <p>How to achieve it using CSS animation?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { background:red; } .container { background:white; padding:20px; position: absolute; bottom:20px; left:45%; border-radius:10px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt; This is magic! &lt;/div&gt;</code></pre> </div> </div> </p> <p><a href="https://i.stack.imgur.com/2ivei.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ivei.gif" alt="enter image description here" /></a></p>
[ { "answer_id": 74165293, "author": "yousoumar", "author_id": 15288641, "author_profile": "https://Stackoverflow.com/users/15288641", "pm_score": 3, "selected": true, "text": "@keyframes" }, { "answer_id": 74165309, "author": "Blye", "author_id": 5726956, "author_profi...
2022/10/22
[ "https://Stackoverflow.com/questions/74165073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17175848/" ]
74,165,123
<p>I have a web service that returns an SseEmiter, i am using it to program a loading bar but...Well, the method to receive it is this:</p> <pre><code>static async synchronize(component: Vue) { let xhr = new XMLHttpRequest(); xhr.open('PATCH', 'myUrl.com'); xhr.responseType = &quot;text&quot; xhr.setRequestHeader('Authorization', 'mySessionToken') xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;text/event-stream&quot;) xhr.onload = function () { if (this.status &gt;= 200 &amp;&amp; this.status &lt; 300) { resolve(xhr.response) } else { reject({status: this.status, statusText: xhr.statusText}) } } xhr.onerror = function () {reject({status: this.status, statusText: xhr.statusText})} xhr.onreadystatechange = function() {if (xhr.readyState == XMLHttpRequest.DONE) { alert(xhr.responseText) }} xhr.onprogress = function(onEvent) { console.log(xhr.response) } xhr.send() } </code></pre> <p>Right now this works, but...The <code>xhr.response</code> data returns this as a string.</p> <pre><code>data:&quot;{ hello: '1' }&quot; data:&quot;{ hello: '2' }&quot; data:&quot;{ hello: '3' }&quot; data:&quot;{ hello: '4' }&quot; data:&quot;{ hello: '5' }&quot; data:&quot;{ hello: '6' }&quot; data:&quot;{ hello: '7' }&quot; data:&quot;{ hello: '8' }&quot; data:&quot;{ hello: '9' }&quot; data:&quot;{ hello: '10' }&quot; data:&quot;{ hello: '11' }&quot; data:&quot;{ hello: '12' }&quot; data:&quot;{ hello: '13' }&quot; data:&quot;{ hello: '14' }&quot; data:&quot;{ hello: '15' }&quot; data:&quot;{ hello: '16' }&quot; data:&quot;{ hello: '17' }&quot; data:&quot;{ hello: '18' }&quot; data:&quot;{ hello: '19' }&quot; //And so on until it reach 100. </code></pre> <p>This doesn't seem like a problem, but what happens is that on each emitted event, the entire state history is returned, getting larger with each value:</p> <p><a href="https://i.stack.imgur.com/FCcyu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FCcyu.png" alt="enter image description here" /></a></p> <p>In short, is there any way to get ONLY the last value of such response? <code>Json.parse()</code> is throwing errors, probably because the response is not formatted as json.</p> <p>I could share some code of the web service where the SseEmitter comes from, but i don't think it's necessary to resolve this. Thanks for any help!</p>
[ { "answer_id": 74165293, "author": "yousoumar", "author_id": 15288641, "author_profile": "https://Stackoverflow.com/users/15288641", "pm_score": 3, "selected": true, "text": "@keyframes" }, { "answer_id": 74165309, "author": "Blye", "author_id": 5726956, "author_profi...
2022/10/22
[ "https://Stackoverflow.com/questions/74165123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17196717/" ]
74,165,145
<p>I've written a function that returns the Width, Height, and Dominant Color of an image, and I don't know how to store the results into a database. Here's the code I have so far:</p> <pre><code>import os from colorthief import ColorThief from PIL import Image os.chdir(&quot;x&quot;) def get_details(): for f in os.listdir(&quot;x&quot;): if f.endswith(&quot;.jpg&quot;): i = Image.open(f) fn, fext = os.path.splitext(f) print(f&quot;The file name is: {fn}{fext}&quot;) width = i.width print(f&quot;The image width is: {width}px&quot;) height = i.height print(f&quot;The Image height is: {height}px&quot;) ct = ColorThief(f) dominant_color = ct.get_color(quality=1) domcol = dominant_color def rgb_to_hex(domcol): return str(&quot;#%02x%02x%02x&quot; % domcol).upper() print(f&quot;The Dominant Color is: {rgb_to_hex(domcol)}&quot;) get_details() </code></pre>
[ { "answer_id": 74165293, "author": "yousoumar", "author_id": 15288641, "author_profile": "https://Stackoverflow.com/users/15288641", "pm_score": 3, "selected": true, "text": "@keyframes" }, { "answer_id": 74165309, "author": "Blye", "author_id": 5726956, "author_profi...
2022/10/22
[ "https://Stackoverflow.com/questions/74165145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20263333/" ]
74,165,151
<p>Let's say I have following python code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt fig=plt.figure() ax=plt.axes(projection='3d') x=y=np.linspace(1,10,100) X,Y=np.meshgrid(x,y) Z=np.sin(X)**3+np.cos(Y)**3 ax.plot_surface(X,Y,Z) plt.show() </code></pre> <p>How do I calculate from this code the gradient and plot it? I am also confused in what numpy.gradient() function exaclty returns.</p> <p>I have here the graph of the function. <a href="https://i.stack.imgur.com/eAzOE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eAzOE.png" alt="enter image description here" /></a></p>
[ { "answer_id": 74165490, "author": "chrslg", "author_id": 20037042, "author_profile": "https://Stackoverflow.com/users/20037042", "pm_score": 1, "selected": false, "text": "np.gradient(Z)" }, { "answer_id": 74167566, "author": "jlandercy", "author_id": 3067485, "autho...
2022/10/22
[ "https://Stackoverflow.com/questions/74165151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12548284/" ]
74,165,156
<p>So I want to change many arrays in a similar way but I'm wondering if instead of doing something like this</p> <pre><code>for (int i = 0; i &lt; 4; i++) { if(i==0) { attack1[0] = attacks[i]; attack1[1] = Convert.ToString(atdmg[i]); attack1[2] = ateffect[i]; attack1[3] = Convert.ToString(ataccur[i]); attack1[4] = Convert.ToString(atmul[i]); } if (i == 1) { attack2[0] = attacks[i]; attack2[1] = Convert.ToString(atdmg[i]); attack2[2] = ateffect[i]; attack2[3] = Convert.ToString(ataccur[i]); attack2[4] = Convert.ToString(atmul[i]); } if (i == 2) { attack3[0] = attacks[i]; attack3[1] = Convert.ToString(atdmg[i]); attack3[2] = ateffect[i]; attack3[3] = Convert.ToString(ataccur[i]); attack3[4] = Convert.ToString(atmul[i]); } if (i == 3) { attack4[0] = attacks[i]; attack4[1] = Convert.ToString(atdmg[i]); attack4[2] = ateffect[i]; attack4[3] = Convert.ToString(ataccur[i]); attack4[4] = Convert.ToString(atmul[i]); } } </code></pre> <p>I could do something like this</p> <pre><code>for (int i = 0; i &lt; 4; i++) { attacki[0] = attacks[i]; attacki[1] = Convert.ToString(atdmg[i]); attacki[2] = ateffect[i]; attacki[3] = Convert.ToString(ataccur[i]); attacki[4] = Convert.ToString(atmul[i]); } </code></pre> <p>so that I don't have to type each one. The point of the code is to put information from other arrays into other arrays to simplify printing information in the long run</p>
[ { "answer_id": 74165490, "author": "chrslg", "author_id": 20037042, "author_profile": "https://Stackoverflow.com/users/20037042", "pm_score": 1, "selected": false, "text": "np.gradient(Z)" }, { "answer_id": 74167566, "author": "jlandercy", "author_id": 3067485, "autho...
2022/10/22
[ "https://Stackoverflow.com/questions/74165156", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309477/" ]
74,165,188
<p>I have this test data that I am trying to use to create a JSON for just select items. I have the items listed and would just like to output a JSON list with select item.</p> <p>What I have:</p> <pre class="lang-py prettyprint-override"><code>import json # Data to be written dictionary ={ &quot;id&quot;: &quot;04&quot;, &quot;name&quot;: &quot;sunil&quot;, &quot;department&quot;: &quot;HR&quot; } # Serializing json x= json.dumps(dictionary,indent=0) # JSON String y = json.loads(x) </code></pre> <pre><code># Goal is to print: { &quot;id&quot;: &quot;04&quot;, &quot;name&quot;: &quot;sunil&quot; } </code></pre>
[ { "answer_id": 74165510, "author": "AJ Paumier", "author_id": 17185740, "author_profile": "https://Stackoverflow.com/users/17185740", "pm_score": 2, "selected": false, "text": "del y['department']\n" }, { "answer_id": 74166399, "author": "AJ Paumier", "author_id": 1718574...
2022/10/22
[ "https://Stackoverflow.com/questions/74165188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309544/" ]
74,165,196
<p>i want to remove the array element if it's arrivalTime is equal to the current time i tried <code>time==traintime5? arrivalarr.pop(): []</code> but it didn't worked, i also tried array.filter but didn't worked so please any one help me. thankyou</p> <p>full code</p> <pre><code>import React, {Component} from 'react' import {useState} from 'react'; function Home() { var today = new Date(), time = today.toLocaleTimeString(today.getHours, today.getMinutes); const date1 = today.toLocaleDateString(today.getDate); var traintime1= today.toLocaleTimeString( today.setMinutes(31,0,0)); var traintime2= today.toLocaleTimeString( today.setMinutes(17,0,0)); var traintime3= today.toLocaleTimeString( today.setMinutes(19,0,0)); var traintime4= today.toLocaleTimeString( today.setMinutes(11,0,0)); var traintime5= today.toLocaleTimeString( today.setMinutes(18,0,0)); const arrivalarr= [ { TrainName : &quot;train1&quot;, TrainNo : &quot;1234&quot;, platformno : &quot;1&quot;, arrivalTime : traintime1 }, { TrainName : &quot;train2&quot;, TrainNo : &quot;1235&quot;, platformno : &quot;2&quot;, arrivalTime : traintime2 }, { TrainName : &quot;train3&quot;, TrainNo : &quot;1236&quot;, platformno : &quot;3&quot;, arrivalTime : traintime3 }, { TrainName : &quot;train4&quot;, TrainNo : &quot;1237&quot;, platformno : &quot;4&quot;, arrivalTime : traintime4 }, { TrainName : &quot;train5&quot;, TrainNo : &quot;1238&quot;, platformno : &quot;5&quot;, arrivalTime : traintime5 } ] </code></pre> <p>and this is my return , in this i wanted ony 4 trains when the time current time reaches any of the above 5 set time.</p> <pre><code> &lt;div&gt; &lt;div&gt; &lt;span&gt; Arrival table &lt;/span&gt;&lt;br /&gt; &lt;span&gt;Bangalore Time {time} date {date1}&lt;/span&gt;&lt;br /&gt; train name trainno platformno arrivalTime &lt;br /&gt; {arrivalarr.map(({TrainName, TrainNo, platformno, arrivalTime})=&gt;( &lt;p key={TrainName}&gt; {TrainName} {TrainNo} {platformno} {arrivalTime}&lt;/p&gt; ))} &lt;/div&gt; &lt;/div&gt; ) } export default Home </code></pre>
[ { "answer_id": 74165510, "author": "AJ Paumier", "author_id": 17185740, "author_profile": "https://Stackoverflow.com/users/17185740", "pm_score": 2, "selected": false, "text": "del y['department']\n" }, { "answer_id": 74166399, "author": "AJ Paumier", "author_id": 1718574...
2022/10/22
[ "https://Stackoverflow.com/questions/74165196", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12423466/" ]
74,165,197
<p>recently I was forced to migrate from VPS hosting I had. I was away from home when I was asked to perform backups before the end of lease, so I had no time to backup all of the data in a way that backup should've been performed and that left me with all of my VPS data packed into a single .tar.gz.</p> <p>Almost everything went smooth, the last thing that gives me nightmares is restoring my previous Gitlab-CE data.</p> <p>This time I went with the dockerized version of Gitlab-CE. (gitlab/gitlab-ce:12.4.0-ce.0)</p> <p>To be sure that I am not using wrong version during this process, I extracted which version I had installed from one of license files found in the backup.</p> <p>I have confirmed that this image works without my data being mounted to volumes, but whenever I've tried to mount volumes recovered from backup:</p> <blockquote> <p>/home/gitlab/logs:/var/log/gitlab</p> <p>/home/gitlab/data:/var/opt/gitlab</p> <p>/home/gitlab/config:/etc/gitlab</p> </blockquote> <p>I was stuck with a fatal error regarding postgres db:</p> <blockquote> <p>[execute] psql: FATAL: database locale is incompatible with operating system</p> <p>DETAIL: The database was initialized with LC_COLLATE &quot;en_US.UTF-8&quot;, which is not recognized by setlocale().</p> <p>HINT: Recreate the database with another locale or install the missing locale.</p> </blockquote> <p>I have tried setting ENV variables <strong>LANG, LANGUAGE, LC_ALL</strong> to different values without any luck.</p> <p>I was not able to find solution on the internet so far, I wish I could've made a backup properly.</p> <p>My wish is to restore old repositories (and if possible user accounts) from old installation I have stored.</p> <p>Anything that could lead me into possible solution is very much appreciated!</p> <p><em>This is my first question on stack so please forgive me if it is formed improperly, or is being asked in a wrong section.</em></p>
[ { "answer_id": 74177495, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 1, "selected": true, "text": "apt-get update && apt-get install -yqq locales tzdata && locale-gen en_US.UTF-8\n" }, { "answer_id": 74182885, "au...
2022/10/22
[ "https://Stackoverflow.com/questions/74165197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309417/" ]
74,165,310
<p>edit: meant 'null termination' wherever 'padding' is used.</p> <p>I am using the following function to compare a string (in this case the argv[1]) to an array of accepted arguments.</p> <pre><code>const char *ARGS_HELP[] = {&quot;-h&quot;, &quot;--help&quot;, &quot;-help&quot;, &quot;help&quot;, NULL}; const char *ARGS_BUILD[] = {&quot;-b&quot;, &quot;--build&quot;, NULL}; int strcmp_array(char *a, const char *b[]) { //printf(&quot;a = \&quot;%s\&quot; b[0] = \&quot;%s\&quot; b[1] = \&quot;%s\&quot; b[2] = \&quot;%s\&quot; b[3] = \&quot;%s\&quot; b[4] = \&quot;%s\&quot; b[5] = \&quot;%s\&quot; b[6] = \&quot;%s\ \n&quot;,a,b[0],b[1],b[2],b[3],b[4],b[5],b[6]); int len = 0; while (b[len] != NULL) { len++; } for (int i = 0; i &lt; len; i++) { //printf(&quot;Comparing \&quot;%s\&quot; to \&quot;%s\&quot;\n&quot;,a,b[i]); if (strcmp(a, b[i]) == 0) { return 0; } } return 1; } int main(int argc, char *argv[]) { if (argc == 1 || strcmp_array(argv[1], ARGS_HELP) == 0) { printf(&quot;%s&quot;, HELP_PAGE); return 0; } } </code></pre> <p>I noticed that when I ran my program with &quot;--build&quot; as argv[1], it would still trigger the help page. I wondered why since ARGS_HELP and ARGS_BUILD are two separate const char arrays. I noticed strcmp_array was looping through all the possible combinations. This is because I had not inserted NULL at the ends of each array to signify its end. Who can explain why this happens, why doesn't the compiler automatically insert a NULL character at the end of the const char arrays?</p> <p>With padding</p> <pre><code>const char *ARGS_HELP[] = {&quot;-h&quot;, &quot;--help&quot;, &quot;-help&quot;, &quot;help&quot;, NULL}; const char *ARGS_BUILD[] = {&quot;-b&quot;, &quot;--build&quot;, NULL}; a = &quot;--build&quot; b[0] = &quot;-h&quot; b[1] = &quot;--help&quot; b[2] = &quot;-help&quot; b[3] = &quot;help&quot; b[4] = &quot;(null)&quot; b[5] = &quot;(null)&quot; b[6] = &quot;-b&quot; </code></pre> <p>Without null padding</p> <pre><code>const char *ARGS_HELP[] = {&quot;-h&quot;, &quot;--help&quot;, &quot;-help&quot;, &quot;help&quot;}; const char *ARGS_BUILD[] = {&quot;-b&quot;, &quot;--build&quot;}; a = &quot;--build&quot; b[0] = &quot;-h&quot; b[1] = &quot;--help&quot; b[2] = &quot;-help&quot; b[3] = &quot;help&quot; b[4] = &quot;-b&quot; b[5] = &quot;--build&quot; </code></pre> <p>I should always pad my char arrays with NULL from now on?</p> <p>I am not a computer scientist. I am relatively new to C.</p>
[ { "answer_id": 74165353, "author": "tadman", "author_id": 87189, "author_profile": "https://Stackoverflow.com/users/87189", "pm_score": 3, "selected": true, "text": "NULL" } ]
2022/10/22
[ "https://Stackoverflow.com/questions/74165310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5865895/" ]
74,165,313
<p>I want to create <code>ori.same.maf.barcodes</code> variable to store the strings of <code>ori.maf.barcode</code> if the substrings before fourth &quot;-&quot; character matches the strings in <code>sub.same.barcodes</code>.</p> <p>How <code>sub.same.barcodes</code> and <code>ori.maf.barcode</code> were generated. <code>sub.maf.barcode</code> is the subset of the <code>ori.maf.barcode$Tumor_Sample_Barcode</code>. The <code>sub.same.barcodes</code> is the intersect of <code>sub.maf.barcode</code> and <code>sub.met.barcode</code>. Now, I want to match <code>sub.same.barcodes</code> back to <code>ori.maf.barcode</code>.</p> <pre><code>ori.maf.barcode &lt;- maf@clinical.data sub.maf.barcode &lt;- gsub(&quot;^([^-]*-[^-]*-[^-]*-[^-]*).*&quot;, &quot;\\1&quot;, ori.maf.barcode$Tumor_Sample_Barcode) # Remove the dashes and keep only the first 4 sub.same.barcodes &lt;- intersect(sub.maf.barcode, sub.met.barcode) </code></pre> <p>Attempt:</p> <pre><code>ori.same.maf.barcodes &lt;- ori.maf.barcode %in% sub.same.barcodes </code></pre> <p>But my code returns &quot;FALSE&quot; instead of a character vector.</p> <p><code>dput(ori.maf.barcode[1:20])</code></p> <pre><code>structure(list(Tumor_Sample_Barcode = c(&quot;TCGA-2K-A9WE-01A-11D-A382-10&quot;, &quot;TCGA-2Z-A9J1-01A-11D-A382-10&quot;, &quot;TCGA-2Z-A9J2-01A-11D-A382-10&quot;, &quot;TCGA-2Z-A9J3-01A-12D-A382-10&quot;, &quot;TCGA-2Z-A9J5-01A-21D-A382-10&quot;, &quot;TCGA-2Z-A9J6-01A-11D-A382-10&quot;, &quot;TCGA-2Z-A9J7-01A-11D-A382-10&quot;, &quot;TCGA-2Z-A9J8-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JD-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JG-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JI-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JJ-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JK-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JM-01A-12D-A42J-10&quot;, &quot;TCGA-2Z-A9JN-01A-21D-A42J-10&quot;, &quot;TCGA-2Z-A9JO-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JQ-01A-11D-A42J-10&quot;, &quot;TCGA-2Z-A9JR-01A-12D-A42J-10&quot;, &quot;TCGA-2Z-A9JS-01A-21D-A42J-10&quot;, &quot;TCGA-3Z-A93Z-01A-11D-A36X-10&quot;)), class = c(&quot;data.table&quot;, &quot;data.frame&quot; ), row.names = c(NA, -20L), .internal.selfref = &lt;pointer: 0x0000025e377005d0&gt;) </code></pre> <p><code>dput(sub.met.barcode[1:20])</code></p> <pre><code>c(&quot;TCGA-BQ-7058-01A&quot;, &quot;TCGA-DZ-6131-01A&quot;, &quot;TCGA-UZ-A9PZ-01A&quot;, &quot;TCGA-2Z-A9JQ-01A&quot;, &quot;TCGA-BQ-5887-11A&quot;, &quot;TCGA-G7-7502-01A&quot;, &quot;TCGA-B1-A47M-11A&quot;, &quot;TCGA-SX-A7SO-01A&quot;, &quot;TCGA-HE-A5NJ-01A&quot;, &quot;TCGA-MH-A856-01A&quot;, &quot;TCGA-A4-8312-01A&quot;, &quot;TCGA-BQ-5892-01A&quot;, &quot;TCGA-A4-7732-11A&quot;, &quot;TCGA-5P-A9K9-01A&quot;, &quot;TCGA-UZ-A9PX-01A&quot;, &quot;TCGA-BQ-7061-01A&quot;, &quot;TCGA-BQ-5876-01A&quot;, &quot;TCGA-DZ-6134-01A&quot;, &quot;TCGA-BQ-5884-01A&quot;, &quot;TCGA-BQ-5889-11A&quot;) </code></pre>
[ { "answer_id": 74165370, "author": "sconfluentus", "author_id": 6258859, "author_profile": "https://Stackoverflow.com/users/6258859", "pm_score": 0, "selected": false, "text": "ori.maf.barcode %in% sub.same.barcodes" }, { "answer_id": 74165417, "author": "br00t", "author_...
2022/10/22
[ "https://Stackoverflow.com/questions/74165313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20076555/" ]
74,165,352
<p>my problem is that the heading &quot;greeting&quot; influences the position of my navigation bar.<br /> I want it to stay at the top right corner of the screen but the heading moves it down a bit, which is inconvenient.<br /> Could someone please give me some advice?<br /> I thank you in advance<br /> here the html code:</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt; &lt;/head&gt; &lt;h1 id = &quot;greeting&quot;&gt; Hello &lt;/h1&gt; &lt;body&gt; &lt;ul class=&quot;navBar&quot;&gt; &lt;li&gt;&lt;a class=&quot;navLinks&quot; href=&quot;about.html&quot;&gt; About me &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and the css code:</p> <pre><code>@font-face { font-family: Terminal; src: url(Fonts/Terminal.ttf); } body { background-color: #333333; } #greeting { text-align:center; font-family:Terminal; } .navBar { list-style-type: none; margin: 0; padding: 0; width: 200px; background-color: black; height: 5000px; z-index: 0; } .navLinks { display: block; color: lime; padding: 8px 16px; text-decoration: none; font-family: Terminal; } .navLinks:hover { background-color: lime; color: black; } * { padding: 0px; margin: 0px; } </code></pre>
[ { "answer_id": 74165463, "author": "kimia shahbaghi", "author_id": 20275256, "author_profile": "https://Stackoverflow.com/users/20275256", "pm_score": 2, "selected": false, "text": "@font-face {\n font-family: Terminal;\n src: url(Fonts/Terminal.ttf);\n}\n\n body {\n backgrou...
2022/10/22
[ "https://Stackoverflow.com/questions/74165352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309583/" ]
74,165,449
<p>Referencing the snippet below, I would like to be able to call <code>f</code> only with an object having a single property. Typescript should complain about additional properties, even when set to <code>undefined</code>.</p> <pre class="lang-js prettyprint-override"><code>interface A { a: number; b?: never; } interface B { a?: never; b: number; } const f = (arg: A | B) =&gt; {}; // OK f({ a: 0 }); // Error: Type 'number' is not assignable to type 'undefined'. f({ a: 0, b: 0 }); // OK, but I would like to have an error f({ a: 0, b: undefined }); </code></pre> <p>In my case <code>f</code> is a <a href="https://beta.reactjs.org/apis/react/useReducer#dispatch" rel="nofollow noreferrer">useReducer dispatcher</a> which if called with <code>{ a: 0, b: undefined }</code> would set the property <code>b</code> of my component state to <code>undefined</code>, while if called with <code>{ a: 0 }</code> would leave the property <code>b</code> alone.</p> <p>There is no reason why I would ever dispatch an <code>{ a: 0, b: undefined }</code> action, but still, is there a way to have TypeScript covering my shoulders?</p>
[ { "answer_id": 74165469, "author": "Guillaume Brunerie", "author_id": 521624, "author_profile": "https://Stackoverflow.com/users/521624", "pm_score": 0, "selected": false, "text": "never" }, { "answer_id": 74187087, "author": "jcalz", "author_id": 2887218, "author_pro...
2022/10/22
[ "https://Stackoverflow.com/questions/74165449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18928520/" ]
74,165,500
<p>I have various implementations of a <code>partial class DeviceServices</code> to provide platform specific implementations of certain device or OS specific features for Android, iOS and so on. My app is targeting API level 33.0 and the minimum version is API level 21.0.</p> <p>Some APIs are specific to certain Android versions and higher, so I want to make sure that they only get called on the supported version. However, I always receive the following warning (and similar ones depending on the API being used):</p> <p><em><strong>warning CA1416: This call site is reachable on: 'Android' 21.0 and later. 'WindowInsets.Type.SystemBars()' is only supported on: 'android' 30.0 and later.</strong></em></p> <p>The following code to hide and show the system bars works on all my devices and the emulators that I have tried so far, but I am concerned about earlier Android versions. I still receive the warning above with it despite checking for the correct target API version:</p> <pre class="lang-cs prettyprint-override"><code>static partial class DeviceServices { private static Activity _activity; public static void SetActivity(Activity activity) { _activity = activity; } public static partial void HideSystemControls() { #if ANDROID30_0_OR_GREATER if (Build.VERSION.SdkInt &gt;= BuildVersionCodes.R) //R == API level 30.0 { _activity?.Window?.InsetsController?.Hide(WindowInsets.Type.SystemBars()); } #endif } public static partial void ShowSystemControls() { #if ANDROID30_0_OR_GREATER if (Build.VERSION.SdkInt &gt;= BuildVersionCodes.R) //R == API level 30.0 { _activity?.Window?.InsetsController?.Show(WindowInsets.Type.SystemBars()); } #endif } } </code></pre> <p>So, what is the correct way to do this? I'm not sure how to proceed. I've used platform-specific APIs plenty of times and never had any problems with it before, but this warning concerns me. I had a look at the support article about this warning already, too, but I didn't find it very helpful: <a href="https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416</a>. I also don't want to suppress the warnings. Maybe I am missing something here or can I simply ignore the warning in this case?</p> <p><strong>Update:</strong></p> <p>I am using Visual Studio 2022 17.4 Preview 2.1 and .NET 7.0 RC1.</p> <p>I have also tried calling the APIs directly from within the <code>MainActivity</code>, but keep receiving the same warnings after a rebuild.</p> <p><strong>Update 2:</strong></p> <p><a href="https://github.com/ewerspej/maui-samples" rel="nofollow noreferrer">Here is a sample repository</a> where the problem can be reproduced, just uncomment the following code block in the <em>MainActivity.cs</em> file:</p> <pre class="lang-cs prettyprint-override"><code> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); //#if ANDROID30_0_OR_GREATER // if (Build.VERSION.SdkInt &gt;= BuildVersionCodes.R) //R == API level 30.0 // { // Window?.InsetsController?.Hide(WindowInsets.Type.SystemBars()); // } //#endif } </code></pre>
[ { "answer_id": 74177284, "author": "Liyun Zhang - MSFT", "author_id": 17455524, "author_profile": "https://Stackoverflow.com/users/17455524", "pm_score": 1, "selected": false, "text": "<uses-sdk android:minSdkVersion=\"21\" android:targetSdkVersion=\"33\" android:maxSdkVersion=\"33\"/>" ...
2022/10/22
[ "https://Stackoverflow.com/questions/74165500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4308455/" ]
74,165,509
<p>I have a pretty simple task where i need to generate every integer below 15 that isn't 10. I know that this is a pretty basic question but i don't know how to solve it.</p> <pre><code>i = 0 while i &lt; 16 and i != 10: print(i) i += 1 </code></pre> <p>I tried this but it just loops 0 forever. Any help would be appreciated!</p>
[ { "answer_id": 74165543, "author": "SkyFarm", "author_id": 17941715, "author_profile": "https://Stackoverflow.com/users/17941715", "pm_score": 0, "selected": false, "text": "i = 0\nwhile (i < 16):\n if i != 10:\n print(i)\n i = i + 1\n \n" }, { "answer_id": 74165556, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74165509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309787/" ]
74,165,515
<p>I want to get the records that which user is suspended and which one is deleted, is there any way to get?</p> <pre><code>from TwitterAPI import TwitterAPI api = TwitterAPI(consumer_key, consumer_secret, auth_type='oAuth2') usersfiles=['',''] #LIST of users for user in usersfiles: print(user,type(user)) #api.request('users/show', users/lookup r = api.request('users/show', {'screen_name':user}) print(r.json()) </code></pre> <p>while error is</p> <pre><code>{'errors': [{'code': 50, 'message': 'User not found.'}]} </code></pre> <p>but if i use</p> <pre><code>r = api.request('users/lookup', {'screen_name':user}) </code></pre> <p>then error is</p> <pre><code>{'errors': [{'code': 17, 'message': 'No user matches for specified terms.'}]} </code></pre> <p>Furthermore is there any efficient way to perform the task as i have around 400K users</p> <p>for reference: <code>https://twitter.com/Harrison5l5po</code> is suspended and <code>https://twitter.com/FourthLongRadio</code> does not exist</p>
[ { "answer_id": 74281007, "author": "Pruthvi", "author_id": 4424477, "author_profile": "https://Stackoverflow.com/users/4424477", "pm_score": 0, "selected": false, "text": "for user in usersfiles:\n print(user) #api.request('users/show', users/lookup\n username = re.search(\"\\w+$\", us...
2022/10/22
[ "https://Stackoverflow.com/questions/74165515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3809691/" ]
74,165,517
<p>I'm going to have about 7 states for my screen and want to navigate them in specific order using BottomNavigationBar with two items, of which first goes &quot;back&quot; and second one forth. Problem is, there's a default index for BottomNavigationBar, which is 0, and the first option is always higlighted. Is there a way to make it no highlighted, or maybe another widget that looks like BottomNavigationBar, that fits better with what I'm trying to do? I use BottomNavigationBar in my app already for other screen, and would like to maintain the similar look.</p>
[ { "answer_id": 74281007, "author": "Pruthvi", "author_id": 4424477, "author_profile": "https://Stackoverflow.com/users/4424477", "pm_score": 0, "selected": false, "text": "for user in usersfiles:\n print(user) #api.request('users/show', users/lookup\n username = re.search(\"\\w+$\", us...
2022/10/22
[ "https://Stackoverflow.com/questions/74165517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20309771/" ]
74,165,530
<p>My question is: How do I combine multiple csv files where each file contains additional headings as well as the core data.</p> <p>For example:</p> <p><strong>File1</strong></p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Candidate</th> <th>Age</th> </tr> </thead> <tbody> <tr> <td>Alex</td> <td>21</td> </tr> <tr> <td>Bob</td> <td>25</td> </tr> </tbody> </table> </div> <p><strong>File2</strong></p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Candidate</th> <th>Location</th> </tr> </thead> <tbody> <tr> <td>Alex</td> <td>London</td> </tr> <tr> <td>Bob</td> <td>York</td> </tr> </tbody> </table> </div> <p><strong>File3</strong></p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Candidate</th> <th>ID</th> </tr> </thead> <tbody> <tr> <td>Alex</td> <td>0234</td> </tr> <tr> <td>Bob</td> <td>0128</td> </tr> </tbody> </table> </div> <p><strong>Desired Combined File</strong></p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Candidate</th> <th>ID</th> <th>Age</th> <th>Location</th> </tr> </thead> <tbody> <tr> <td>Alex</td> <td>0234</td> <td>21</td> <td>London</td> </tr> <tr> <td>Bob</td> <td>0128</td> <td>25</td> <td>York</td> </tr> </tbody> </table> </div> <p>When I import from folder into Excel, in PowerQuery editor this hits a wall due to the schemas being different. Am I missing something obvious?</p>
[ { "answer_id": 74165605, "author": "Peter", "author_id": 7108589, "author_profile": "https://Stackoverflow.com/users/7108589", "pm_score": 2, "selected": false, "text": "let\n Source = Table.NestedJoin(\n #\"File 1\", {\"Candidate\"}, \n #\"File 2\", {\"Candidate\"}, \n ...
2022/10/22
[ "https://Stackoverflow.com/questions/74165530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12352398/" ]
74,165,538
<pre><code>sortByAmountHighToLow(trades) { return trades.sort((a, b) =&gt; { return b.total - a.total; }); }, </code></pre> <p>I have this right now (in Vue) which sorts an array of numbers from high to low, as it should.</p> <p>What I instead need is a sorting function which does not look at negative numbers differently from positive numbers.</p> <p>This is the output I would like (high to low): [-531, 245, -195, 54, -12]</p> <p>I'm getting: [245, 54, -12, -195, -513]</p> <p>I hope this clearly explains what I need.</p>
[ { "answer_id": 74165558, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 3, "selected": true, "text": "const array = [245, 54, -12, -195, -513]\n\narray.sort((a, b) => Math.abs(b) - Math.abs(a))\n\nconsole.log(array)" }...
2022/10/22
[ "https://Stackoverflow.com/questions/74165538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14724942/" ]
74,165,552
<p>I am trying to create a module that wraps all classes, and use them somewhere else.</p> <pre class="lang-py prettyprint-override"><code>class Mixins: class B: pass class C: pass b = Mixins.B() print(Mixins.__all_subclasses__()) # [Mixins.B, Mixins.C] </code></pre> <p>I mean, I can stack all subclasses in a list after I created one, but not elegant. is there an instinctive built-in for me to do this? python 3.7.</p>
[ { "answer_id": 74165558, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 3, "selected": true, "text": "const array = [245, 54, -12, -195, -513]\n\narray.sort((a, b) => Math.abs(b) - Math.abs(a))\n\nconsole.log(array)" }...
2022/10/22
[ "https://Stackoverflow.com/questions/74165552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11645617/" ]
74,165,589
<p>For some reason, I can't get .map() to render the data. I tried running the function directly in render and called it from render and nothing happened.</p> <pre><code>function Contracts(props) { const [isLoaded, setLoaded] = useState(true); const [error, setError] = useState(null); const [equipment, setEquipment] = useState([]); useEffect(() =&gt; { const getContracts = async () =&gt; { let snapshot = await db.getAllContracts(); setTimeout(10000); if (snapshot) { console.log(snapshot); setError(null); setLoaded(true); snapshot.forEach((item, i) =&gt; { console.log(item[1]); equipment.push({ value: item, date: item.Dato, status: item.Status, start: item.StartLocation, end: item.EndLocation, col: item.Collateral, reward: item.Reward }); }) console.log(equipment); } else { setLoaded(false); } } getContracts(); }, []) const handleClick = (e) =&gt; { let target = e.target; let selectedEquipmentIndex = target.parentElement.getAttribute(&quot;dataset-id&quot;); this.setState({ selectedEquipment: selectedEquipmentIndex }); } const renderItems = () =&gt; { const data = equipment; console.log(data); const listItems = data.map( (element) =&gt; { console.log(element); return ( &lt;id className=&quot;row&quot; key={element} dataset-id={element} onClick={handleClick}&gt; &lt;p className=&quot;date&quot;&gt;{element.date.toString()}&lt;/p&gt; &lt;p className=&quot;status&quot;&gt;{element.status}&lt;/p&gt; &lt;p className=&quot;start&quot;&gt;{element.start}&lt;/p&gt; &lt;p className=&quot;end&quot;&gt;{element.end}&lt;/p&gt; &lt;p className=&quot;col&quot;&gt;{element.col}&lt;/p&gt; &lt;p className=&quot;reward&quot;&gt;{element.reward}&lt;/p&gt; &lt;/id&gt; ) } ) return ( &lt;div&gt; {listItems} &lt;/div&gt; ) } if (error) { return &lt;div&gt;Error: {error.message}&lt;/div&gt;; } else if (!isLoaded) { return &lt;div&gt;Loading...&lt;/div&gt;; } else { return ( &lt;article id=&quot;header&quot;&gt; &lt;article id=&quot;content&quot;&gt; &lt;section class=&quot;container&quot;&gt; &lt;div classname=&quot;header&quot;&gt;&lt;h1&gt;&lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;titleArea&quot;&gt; &lt;div className=&quot;eqnavn&quot;&gt;&lt;h1&gt;Date: &lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;eqstatus&quot;&gt;&lt;h1&gt;Status: &lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;eqstart&quot;&gt;&lt;h1&gt;Start: &lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;eqend&quot;&gt;&lt;h1&gt;End: &lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;eqcol&quot;&gt;&lt;h1&gt;Collateral: &lt;/h1&gt;&lt;/div&gt; &lt;div className=&quot;eqreward&quot;&gt;&lt;h1&gt;Reward: &lt;/h1&gt;&lt;/div&gt; &lt;/div&gt; {renderItems} &lt;/section&gt; &lt;/article&gt; &lt;/article&gt; ) } } export default Contracts; </code></pre> <p>And I do get data from my database:</p> <pre><code> [{…}] 0: col: &quot;270000&quot; date: 1666454928600 end: &quot;asdas&quot; reward: 49705 start: &quot;asdasd&quot; status: &quot;Not Taken&quot; value: {EndLocation: 'asdas', Size: 'Max 40T Space Safe', StartLocation: 'asdasd', Collateral: '270000', Username: 'Saphyron', …} </code></pre> <p>I hope someone can help me cause I'm getting stuck. Tried following some of the guides here but most is 5+ years old and does not work sadly.</p>
[ { "answer_id": 74165558, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 3, "selected": true, "text": "const array = [245, 54, -12, -195, -513]\n\narray.sort((a, b) => Math.abs(b) - Math.abs(a))\n\nconsole.log(array)" }...
2022/10/22
[ "https://Stackoverflow.com/questions/74165589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17603286/" ]
74,165,606
<p>I'm trying to clone a specific branch (the &quot;dev&quot; branch) of a GitHub repository. With the git command I can run something like</p> <pre><code>git clone --branch dev https://github.com/user/repo </code></pre> <p>What's the equivalent of this in <code>gh</code> (GitHub CLI)? I can't find it in the docs</p>
[ { "answer_id": 74165558, "author": "Konrad", "author_id": 5089567, "author_profile": "https://Stackoverflow.com/users/5089567", "pm_score": 3, "selected": true, "text": "const array = [245, 54, -12, -195, -513]\n\narray.sort((a, b) => Math.abs(b) - Math.abs(a))\n\nconsole.log(array)" }...
2022/10/22
[ "https://Stackoverflow.com/questions/74165606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10418247/" ]
74,165,625
<p>How can i code so people can't add/remove list elements from the inspector, but still be able to see the elements?</p> <p>Something like</p> <pre class="lang-cs prettyprint-override"><code>[ReadOnlyField, NonReorderable]public List&lt;CustomType&gt; CustomTypeList = new(); </code></pre>
[ { "answer_id": 74169168, "author": "Toan Tran", "author_id": 20312281, "author_profile": "https://Stackoverflow.com/users/20312281", "pm_score": 1, "selected": true, "text": " using System.Collections;\n using System.Collections.Generic;\n using UnityEngine;\n #if UNITY_EDITO...
2022/10/22
[ "https://Stackoverflow.com/questions/74165625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20254662/" ]
74,165,627
<p>I'm trying to create settings page from json. But first i'm checking if creating is working on static array:</p> <pre><code>import 'package:flutter/material.dart'; import 'package:settings_ui/settings_ui.dart'; class _SettingsScreenState extends State&lt;SettingsScreen&gt; { bool lockInBackground = true; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { var tilearray = [{'name':'settings no 1'},{'name':'settings no 2'},{'name':'settings no 3'}]; List&lt;SettingsTile&gt; tiles = []; log('{$tilearray}'); tiles.add( SettingsTile.switchTile( initialValue: lockInBackground, onToggle: (bool value) { setState(() { lockInBackground = value; }); }, leading: Icon(Icons.phonelink_lock), title: Text('settings no 0'))); tilearray.map((item) =&gt; log('test{$item.name}')); tilearray.map((item) =&gt; tiles.add( SettingsTile.switchTile( initialValue: lockInBackground, onToggle: (bool value) { setState(() { lockInBackground = value; }); }, leading: Icon(Icons.phonelink_lock), //title: Text(item['name']!)))); title: Text('debug item')))); log('{$tiles}'); return Scaffold( appBar: AppBar(title: Text('Settings UI')), body: SettingsList( sections: [ SettingsSection( title: Text('First Section'), tiles: tiles, ) ] ) ); } } </code></pre> <p>But the result is only one SettingsTile (Setting no 0)...</p> <p>The comment I add to check if there's a problem with array item, but no. It looks like tilearray is empty.</p> <p>It is strange that <code>tilearray.map((item) =&gt; log('test{$item.name}'));</code> is empty too</p>
[ { "answer_id": 74165716, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 1, "selected": false, "text": "\nclass SettingsScreen extends StatefulWidget {\n const SettingsScreen({super.key});\n\n @override\n Stat...
2022/10/22
[ "https://Stackoverflow.com/questions/74165627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/354420/" ]
74,165,629
<p>In my Kubernetes cluster, I have a ConfigMap object containing the address of my Postgres pod. It was created with the following YAML:</p> <pre><code>apiVersion: v1 kind: ConfigMap metadata: name: postgres-configmap data: database_url: postgres-service </code></pre> <p>Now I reference this value in one of my Deployment's configuration:</p> <pre><code>env: - name: DB_ADDRESS valueFrom: configMapKeyRef: name: postgres-configmap key: database_url </code></pre> <p>This deployment is a Spring Boot application that intends to communicate with the database. Thus it reads the database's URL from the DB_ADDRESS environment variable. (ignore the default values, those are used only during development)</p> <pre><code>datasource: url: ${DB_ADDRESS:jdbc:postgresql://localhost:5432/users} username: ${POSTGRES_USER:postgres} password: ${POSTGRES_PASSWORD:mysecretpassword} </code></pre> <p>So, according to the logs, the problem is that the address has to have the <code>jdbc:postgresql://</code> prefix. Either in the ConfigMap's YAML or in the application.yml I would need to concatenate the prefix protocol string with the variable. Any idea how to do it in yml or suggestion of some other workaround?</p>
[ { "answer_id": 74165716, "author": "Yeasin Sheikh", "author_id": 10157127, "author_profile": "https://Stackoverflow.com/users/10157127", "pm_score": 1, "selected": false, "text": "\nclass SettingsScreen extends StatefulWidget {\n const SettingsScreen({super.key});\n\n @override\n Stat...
2022/10/22
[ "https://Stackoverflow.com/questions/74165629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7874286/" ]
74,165,636
<p>I'm trying to map a lambda function to variable that can be a float, int, or list.</p> <p><strong>Test #1</strong>, this works:</p> <pre><code>val = [0.1] test = list(map(lambda x: max(x, 1 - x), val)) </code></pre> <p><strong>Test #2</strong>, this throws <code>TypeError: 'float' object is not iterable</code>:</p> <pre><code>val = 0.1 test = list(map(lambda x: max(x, 1 - x), val)) </code></pre> <p>I tried to solve it with <code>list(val)</code> (that is, <code>list(map(lambda x: max(x, 1 - x), list(val)))</code>), but it throws the same error.</p> <p><strong>How can I get it to work in both Test #1 and Test #2?</strong> Python 3.7</p>
[ { "answer_id": 74165674, "author": "doxdeveloper", "author_id": 16561009, "author_profile": "https://Stackoverflow.com/users/16561009", "pm_score": 0, "selected": false, "text": "val" }, { "answer_id": 74165718, "author": "Muhammad Akhlaq Mahar", "author_id": 17416783, ...
2022/10/22
[ "https://Stackoverflow.com/questions/74165636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10976654/" ]
74,165,651
<p>I want to position a div at the center of the screen. The issue is when the div is small, from left 45% looks fine but when the div is longer(ie more width), I need to make it from left 30%</p> <p>Is there a smart way to position the div at the center based on the size of div.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { background:blue; } .box { position: absolute; top:10px; left:30%; background:white; padding:10px; border-radius:10px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="box"&gt; This is long div so need left = 30 percent &lt;/div&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 74165693, "author": "Mohammed Ahmed", "author_id": 4292093, "author_profile": "https://Stackoverflow.com/users/4292093", "pm_score": 1, "selected": false, "text": ".box {\n position: absolute;\n top:10px;\n left:50%;\n background:white;\n padding:10px;\n borde...
2022/10/22
[ "https://Stackoverflow.com/questions/74165651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17848757/" ]