Erasmoclaytonjohn's Profile

60
Points

Questions
10

Answers
7

  • Asked on August 31, 2020 in Python.

    A left-hand whitespace boundary – a position in the string that is either a string start or right after a whitespace character – can be expressed with

    (?<!\S)   # A negative lookbehind requiring no non-whitespace char immediately to the left of the current position (?<=\s|^) # A positive lookbehind requiring a whitespace or start of string immediately to the left of the current position (?:\s|^)  # A non-capturing group matching either a whitespace or start of string  (\s|^)    # A capturing group matching either a whitespace or start of string 

    See a regex demo. Python 3 demo:

    import re rx = r'(?<!\S)GBP([\W\d])' text = 'GBP 5 Off when you spend GBP75.00' print( re.sub(rx, r'£\1', text) ) # => £ 5 Off when you spend £75.00 

    Note you may use \1 instead of \g<1> in the replacement pattern since there is no need in an unambiguous backreference when it is not followed with a digit.

    BONUS: A right-hand whitespace boundary can be expressed with the following patterns:

    (?!\S)   # A negative lookahead requiring no non-whitespace char immediately to the right of the current position (?=\s|$) # A positive lookahead requiring a whitespace or end of string immediately to the right of the current position (?:\s|$)  # A non-capturing group matching either a whitespace or end of string  (\s|$)    # A capturing group matching either a whitespace or end of string 
    • 20 views
    • 8 answers
    • 0 votes
  • Asked on August 31, 2020 in Swift.

    If you are working with money, currency etc it is much better to use Decimal than Double and it will also solve your problem here, change the declaration of d as below

    let d: Decimal = -1 * 0 

    and the formatter will produce "$0.00"

    • 13 views
    • 2 answers
    • 0 votes
  • Asked on August 31, 2020 in iOS.

    The normal Xcode clearing works for me:

    1. Clean build folder (shift + command + k)
    2. Close Xcode completely
    3. Delete ‘DerivedData’ content (/Library/Developer/Xcode/DerivedData)
    4. Try again (run Xcode & build)
    • 16 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in .NET.

    It’s really hard to tell what could be the exact reason why the comparison fails. However, I can try to suggest several approaches to find the problem in your code.

    First, lets apply ToList() at the end of your query for DataHere to skip possible multiple call for the driver.FindElements(...):

    var DataHere = (from row in                      driver.FindElements(By.CssSelector("#users_table .slick-viewport .slick-row"))                      select new UserTableRow(row)).ToList(); 

    Second, even before getting into foreach loop, it would be wise to check if your DataHere has items, otherwise, you will be guaranteed to have false results for every AlreadyExist check.

    // Now we will iterate through cells in the table and compare to what we already have in the list if (DataHere.Any()) {    foreach (var row in rows)    {       // ...    } } 

    And the last point, ask yourself:

    What kind of check am I performing (exact or contain)?

    If the answer is "contain" then use Contains or IndexOf method for comparing cus.Username and row.Text.

    Is the check case sensitive or not?

    If the answer is not case sensitive then apply one of the ToLower(), ToLowerInvariant(), ToUpper(), ToUperInvariant() methods to both cus.Username and row.Text during comparison.

    Finally, if both of the above points are true then combine the suggestions.

    • 15 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in .NET.

    HttpClientHandler

    You have to override SendAsync

    internal class MyHttpClientHandler : HttpClientHandler {     protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)     {          // Do before call          var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);          // do after call          return response;     } }  var handler = new MyHttpClientHandler();  var client = new HttpClient(handler) {     BaseAddress = new Uri("my-api-uri") };  
    • 16 views
    • 2 answers
    • 0 votes
  • Asked on August 31, 2020 in .NET.

    I have upgraded Windows 10 and ran into the same issues, that the Power Toys install was mangled.

    I did find the msi using the wayback machine: https://web.archive.org/web/*/https://download.microsoft.com/download/f/a/c/fac1342d-044d-4d88-ae97-d278ef697064/NETCFv35PowerToys.msi

    click i.e. the year 2008 which shows July 26th, you can download it by clicking on that date

    • 16 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in .NET.

    This is one of the scenarios that the options pattern was created for.

    1. Create your strongly-typed options class:
    public class RootServiceOptions {     public bool MyParam { get; set; } } 
    1. Change your constructor to accept an instance of IOptions<RootServiceOptions>:
    class RootService : IRootService {    private readonly ILogger<RootService> _logger;    private readonly bool _myParam;     public RootService(ILogger<RootService> logger, IOptions<RootServiceOptions> options) =>       (_logger, _myParam) = (logger, options.Value.MyParam); } 
    1. Create and populate RootServiceOptions in Startup.cs/ConfigureServices using the Configure extension method:
    // o is of type RootServiceOptions and is the instance that will be injected services.Configure<RootServiceOptions>(o => o.MyParam = <boolean value from somewhere>); 
    1. Profit.
    • 12 views
    • 2 answers
    • 0 votes