Hueykareemliz's Profile

235
Points

Questions
45

Answers
40

  • Asked on July 17, 2020 in XML.

    I wanted to do something similar. I finally had to find the TextView among the SearchView children:

    for (TextView textView : findChildrenByClass(searchView, TextView.class)) {     textView.setTextColor(Color.WHITE); } 

    If you want the util method:

    public static <V extends View> Collection<V> findChildrenByClass(ViewGroup viewGroup, Class<V> clazz) {      return gatherChildrenByClass(viewGroup, clazz, new ArrayList<V>()); }  private static <V extends View> Collection<V> gatherChildrenByClass(ViewGroup viewGroup, Class<V> clazz, Collection<V> childrenFound) {      for (int i = 0; i < viewGroup.getChildCount(); i++)     {         final View child = viewGroup.getChildAt(i);         if (clazz.isAssignableFrom(child.getClass())) {             childrenFound.add((V)child);         }         if (child instanceof ViewGroup) {             gatherChildrenByClass((ViewGroup) child, clazz, childrenFound);         }     }      return childrenFound; } 
    • 1207 views
    • 30 answers
    • 0 votes
  • Asked on July 16, 2020 in Linq.

    You need to select the "value" nodes and analyze then in your loop. For example to get you started:

    var s = @"<?xml version=""1.0"" encoding=""utf - 8""?> <values> <value> <id>aaaaa</id> <condition>true</condition> </value>  <value> <id>bbbb</id> <condition>false</condition> </value>  <value> <id>ccccc</id> <condition>true</condition> </value> </values>";  XmlDocument doc = new XmlDocument(); doc.LoadXml(s);  var nodes = doc.SelectNodes("/values/value"); foreach (XmlElement node in nodes) {     if (node.SelectSingleNode("condition").InnerText == "true")     {         Console.WriteLine(node.SelectSingleNode("id").InnerText); // prints "aaaaa" and "ccccc"     } } 
    • 444 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in .NET.

    This was a breaking change in .NET Core 3.0, for consistency between languages and IEEE-754 compliance.

    Quoting from Floating-Point Parsing and Formatting improvements in .NET Core 3.0:

    ToString(), ToString("G"), and ToString("R") will now return the shortest roundtrippable string.

    The emphasis in the above is on "roundtrippable". Before this change, the negative zero "-0" did not roundtrip correctly, which was fixed by the combination of Fixing up the Double/Single parsing code to be correct #20707 and Roundtrip string format for single/double doesn’t roundtrip -0 #9883.

    • 376 views
    • 1 answers
    • 0 votes
  • I found it,the project will set ViewLocationExpanderContext by theme name

    • 397 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in .NET.

    First of all, we need look at this MSDN – HttpClient Class.

    HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.

    Anyway, here is what you missed.

    public void CallServiceTest() {     var wRef2 = CallInItsOwnScope(() =>     {         // HttpClient -> HttpMessageInvoker(IDisposable), so it can be disposed.         using (var client = new HttpClient())         {              using (var response = client.GetAsync(new Uri("https://postman-echo.com/get?foo1=bar1&foo2=bar2")).Result)             {                 return new WeakReference(response);             }         }     });     GC.Collect();     GC.WaitForPendingFinalizers();     Assert.IsFalse(wRef2.IsAlive); }  
    • 359 views
    • 1 answers
    • 0 votes
  • Your results do not seem consistent with your data. Based on your explanation and existing query, I suspect that you are looking for conditional aggregation. In MySQL, you would phrase this as:

    select      username,     count(*)/60 as hour_streamed,     avg(category like 'Call of Duty%') as if_call_of_duty  from minute_streamed group by username 

    This aggregates records by username; hour_streamed is the total number of record per user (in all categories), divided by 60. if_call_of_duty is the ratio of records that relate to categories that start with 'Call of Duty'.

    • 438 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    Actually you’re doing a Cross-Join (selecting data from multiple tables without any relationship or restriction).

    Here you have 2 ways to solve this:

    1. Using Join
    SELECT     A.ADJ_CLOSE,     B.ADJ_CLOSE FROM     TCS AS A JOIN MCS AS B     ON A.ADJ_CLOSE = B.ADJ_CLOSE ORDER BY     A.DATE DESC LIMIT     2; 
    1. Using WHERE
    SELECT     A.ADJ_CLOSE,     B.ADJ_CLOSE FROM     (SELECT ADJ_CLOSE FROM TCS ORDER BY DATE DESC LIMIT 2) AS A,     (SELECT ADJ_CLOSE FROM MCS ORDER BY DATE DESC LIMIT 2) AS B WHERE     A.ADJ_CLOSE = B.ADJ_CLOSE; 
    • 336 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function (os.system('command')).

    since it is a command file (cmd), and only the shell can run it, then shell argument must set to be true. since you are setting the shell argument to true, the command needs to be string form and not a list.

    use the Popen method for spawn a new process and the communicte for waiting on that process (you can time it out as well). if you whish to communicate with the child process, provide the PIPES (see mu example, but you dont have to!)

    the code below for python 3.3 and beyond

    import subprocess  try:     proc=subprocess.Popen('myfile.cmd', shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)     outs, errs = proc.communicate(timeout=15)  #timing out the execution, just if you want, you dont have to! except TimeoutExpired:     proc.kill()     outs, errs = proc.communicate() 

    for older python versions

    proc = subprocess.Popen('myfile.cmd', shell=True) t=10 while proc.poll() is None and t >= 0:     print('Still waiting')     time.sleep(1)     t -= 1  proc.kill() 

    In both cases (python versions) if you dont need the timeout feature and you dont need to interact with the child process, then just, use:

    proc = subprocess.Popen('myfile.cmd', shell=True) proc.communicate() 
    • 367 views
    • 2 answers
    • 0 votes
  • bot.join_voice_channel was the discord.py method, not the discord.py@rewrite one. You now have to use VoiceChannel.connect(). If your bot is already connected, then you can use VoiceClient.move_to (If you want only one player on your discord server).

    Here’s how you use those two methods:

    @bot.command(name="join") async def join(ctx):     channel = ctx.author.voice.channel     voice = get(self.bot.voice_clients, guild=ctx.guild)      if voice and voice.is_connected():         await voice.move_to(channel)     else:         voice = await channel.connect() 

    References: https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=migrating#voice-changes

    • 383 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    You can also use df.apply() to iterate over rows and access multiple columns for a function.

    docs: DataFrame.apply()

    def valuation_formula(x, y):     return x * y * 0.5  df['price'] = df.apply(lambda row: valuation_formula(row['x'], row['y']), axis=1) 
    • 1096 views
    • 22 answers
    • 0 votes