Lavernkaseyeffie's Profile

210
Points

Questions
40

Answers
41

  • Asked on July 17, 2020 in ASP.Net Core.

    To answer my own question, here’s a possible workaround:

        services         .AddMvc(config =>             {                 ...                 config.OutputFormatters.Add(new CustomXmlOutputFormatter());                 config.RespectBrowserAcceptHeader = true;             }); 
    public class CustomXmlOutputFormatter : TextOutputFormatter     {         public CustomXmlOutputFormatter()         {             SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/xml"));             SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/xml"));              SupportedEncodings.Add(Encoding.UTF8);             SupportedEncodings.Add(Encoding.Unicode);         }          protected override bool CanWriteType(Type type)         {             return true;         }          public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)         {             if (context == null) throw new ArgumentNullException(nameof(context));             if (selectedEncoding == null) throw new ArgumentNullException(nameof(selectedEncoding));              var httpContext = context.HttpContext;              var json = JsonConvert.SerializeObject(new { item = context.Object });              var xml = JsonConvert.DeserializeXNode(json, "root");              var buffer = new StringBuilder(xml.ToString());              await httpContext.Response.WriteAsync(buffer.ToString());         }     } 
    • 491 views
    • 1 answers
    • 0 votes
  • Asked on July 17, 2020 in XML.

    This XPath,

    //article[not(ancestor::article)] 

    will select all article elements that have no article ancestors, so for your example XML, it will only select article elements with id attribute values of 1 or 2.

    To more generally limit selection based upon depth (as is asked in your question’s title), the number of ancestors can be counted:

    • //article[count(ancestor::article) < 3] for those article elements with less than three article ancestors.
    • //article[count(ancestor::*) < 3] for those article elements with less than three ancestors of any type.
    • //*[count(ancestor::*) < 3] for any elements with less than three ancestors.
    • 410 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in .NET.

    If i understood your problem correctly – you can achieve something like this with generics:

    public interface ICombinableAction<T> where T : ICombinableAction<T> {     public void CombineActions(T toCombine); }  public class MoveAllObjects : ICombinableAction<MoveAllObjects> {     public void CombineActions(MoveAllObjects toCombine)     {      } } 
    • 335 views
    • 1 answers
    • 0 votes
  • I just added log4net package to both the projects and error is gone now.

    • 572 views
    • 1 answers
    • 0 votes
  • There are a few mistakes in the code. I’m not sure if you are trying to also have a list of sub-services as the text depicts. If so, see this link, https://stackoverflow.com/a/62902173/6326441.

    var bodyText = @"Hi, The following service(s) has reported issues:{{ for service in services }}     ""{{ service.key }}"": ""{{service.value}}""{{end}} Thanks "; var keyValuePairs = new Dictionary<string, string>() {     {"UserManagement",  "UserManagement has following unhealthy subservice(s)"},     {"DNS",  "Network has following unhealthy subservice(s)"} };   var template1 = Template.Parse(bodyText); var result1 = template1.Render(new { services = keyValuePairs }); Console.WriteLine(result1.ToString()); 

    This will result in the following:

    Hi, The following service(s) has reported issues:     "UserManagement": "UserManagement has following unhealthy subservice(s)"     "DNS": "Network has following unhealthy subservice(s)" Thanks  
    • 386 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Linux.

    In my case, I was using mb_split, which uses regex. Therefore I also had to manually make sure the regex encoding was utf-8 by doing mb_regex_encoding('UTF-8');

    As a side note, I also discovered by running mb_internal_encoding() that the internal encoding wasn’t utf-8, and I changed that by running mb_internal_encoding("UTF-8");.

    • 726 views
    • 15 answers
    • 0 votes
  • I am using WAMP server. Actually its files showed that openssl is opened. But manually I went to the folder and edited php.ini. Then I found it has not opened openssl.I uncommented it and it worked after after WAMP restart.

    • 687 views
    • 18 answers
    • 0 votes
  • This is written about in the official docs here.

    Any function returned from useEffect is used for "cleaning up".

    In your first example doRequest returns something other than undefined, which React will try to call as a function to "clean up" when the component unmounts.

    Example of useEffect with a clean up function:

    useEffect(() => {   document.addEventListener("resize", handleResize);   // This is a "clean up" function   return () => {     document.removeEventListener("resize", handleResize);   }; }, []); 

    Example of useEffect without a clean up function. Note this is bad as the listener will still fire after the component unmounts.

    useEffect(() => {   document.addEventListener("resize", handleResize); }, []); 
    • 375 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Java Script.

    Group them into an object instead of making them separate functions, and access them using a key:

    let functions = {                                          // keys are the possible values of valor   "A": function() { /* ... */ },                           // you can either define the functions here   "B": CalculaBDeA,                                        // ... or assign a reference to an already existing function   "C": function() { /* ... */ },   "D": function() { /* ... */ },   /* ... */ }  function QueCalculamos(valor) {   if(functions.hasOwnProperty(valor)) {                     // if the functions object contains a function for valor     return functions[valor];                                // return it   }    throw "there is no function for '" + valor + "'";        // otherwise throw an error or return something else to signal failure } 

    Demo:

    let functions = {   "A": function() {     console.log("Function A");   },   "B": function() {     console.log("Function B");   },   "C": function() {     console.log("Function C");   },   "D": function() {     console.log("Function D");   },   /* ... */ }  function QueCalculamos(valor) {   if (functions.hasOwnProperty(valor)) {     return functions[valor];   }    throw "there is no function for '" + valor + "'"; }   let exe = QueCalculamos("C"); exe();

    • 370 views
    • 3 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    This should do for you Split the string by a chain of whitespace,@,text immediately after @and whitespace after the text. This results in a list. remove the list corner brackets while separating elements by space using .str.join(' ')

    df.Name=df.Name.str.split('\s\@\s\w+\s').str.join(' ')     0    George sold 
    • 353 views
    • 6 answers
    • 0 votes