Odellrubengladys's Profile




  • Asked on July 16, 2020 in HTML.

    Django provides support for this natively: {{ forloop.counter }}

    {% extends 'equipment/base.html'%} {% block content%} {% for instance in obj_list %}  <article class="media content-section">   <div class="media-body">     <div class="article-metadata">       <a class="mr-2" href="#">{{ forloop.counter }}. {{ instance.type }}</a>         <small class="text-muted">{{ instance.date_posted}}</small>     </div>   </div> </article> {% endfor %} 
    • 1 answers
    • 0 votes
  • I tried to modify the code and try to achieve the result as close as other browsers.

    I applied the media queries and I try to set the list-style-position, text-indent, and padding specifically for the IE browser.

    Now it looks almost similar as it looks in other browsers.

    Modified code:

    <!DOCTYPE html> <html>    <head>       <title>Untitled Page</title>       <style>          @supports not (-ms-high-contrast: none)           {          img           {          float: left;          margin-right: 10px;          }          ol           {          position: relative;          padding-left: 5px;          left: 10px;          }          #container          {          width:300px;          background-color:skyblue;          padding:5px;          }          }          @media all and (-ms-high-contrast: none), (-ms-high-contrast: active)           {          img           {          float: left;          margin-right: 35px;          }          ol           {          position: relative;          padding-left: 5px;          margin-left: 10px;          }          ol li           {          list-style-position: inside;          text-indent: -1.8em;          padding-left: 1em;          }          #container          {          width:300px;          background-color:skyblue;          padding:5px;          }          }       </style>    </head>    <body>       <div id="container">          <img src="https://via.placeholder.com/100">          <div>Below are bullets</div>          <ol>             <li>This is the bullet This is the bullet This is the bullet</li>             <li>This is the bullet</li>             <li>This is the bullet</li>             <li>This is the bullet This is the bullet This is the bullet</li>             <li>This is the bullet</li>             <li>This is the bullet</li>          </ol>       </div>    </body> </html>

    Output in the IE 11 and Google Chrome browser:

    enter image description here

    Further, you can try to modify the code as per your own requirement.

    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Java.

    static initializer blocks are only executed once when a class is initialized by the JVM whereas instance initializer blocks are executed every time an instance of a class is created. Instance initializer blocks execute before the code in the constructor but after the call to parent’s class constructor (i.e. after super() call).

    Java compiler copies the code of instance initializer blocks in to every constructor. Instance initializer block code is placed after the super() call. So following code:

    {     System.out.println("B non-static initializer block"); }  public B() {     super("test");     System.out.println("B constructor"); } 

    will be transformed in to:

    public B() {     super("test");     System.out.println("B non-static initializer block");     System.out.println("B constructor"); } 

    This explains why test is printed on the console before instance initializer block of the B class executes.

    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.
    • The dataframe needs to be reshaped depending on the what needs to be plotted.
    • Convert the data to long format with .stack
    • Drop Contract
    • Drop the duplicates
    • The data value range is large, so if you don’t use log scale on y, some values won’t display.
    • Dataframe df is the data in the question
    import pandas as pd import matplotlib.pyplot as plt import seaborn as sns  # dataframe to long format dfl = df.set_index(['Contract', 'Sections']).stack().reset_index()  # drop dfl.drop(columns=['Contract'], inplace=True) dfl.drop_duplicates(inplace=True)  # plot sns.barplot('Sections', 0, data=dfl, hue='level_2') plt.yscale('log') 

    enter image description here

    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Java.

    Almost all the answers given requires a full deserialization of the JSON into a Java object before accessing the value in the property of interest. Another alternative, which does not go this route is to use JsonPATH which is like XPath for JSON and allows traversing of JSON objects.

    It is a specification and the good folks at JayWay have created a Java implementation for the specification which you can find here: https://github.com/jayway/JsonPath

    So basically to use it, add it to your project, eg:

    <dependency>     <groupId>com.jayway.jsonpath</groupId>     <artifactId>json-path</artifactId>     <version>${version}</version> </dependency> 

    and to use:

    String pageName = JsonPath.read(yourJsonString, "$.pageInfo.pageName"); String pagePic = JsonPath.read(yourJsonString, "$.pageInfo.pagePic"); String post_id = JsonPath.read(yourJsonString, "$.pagePosts[0].post_id"); 


    Check the JsonPath specification page for more information on the other ways to transverse JSON.

    • 30 answers
    • 0 votes
  • Asked on July 16, 2020 in Java.

    May be changing the class name will execute this code.bcoz I think "Main" is keyword and we can’t use it.

    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    If you want to affect the URL scheme for all server-generated URLs (url_for and redirect), rather than having to set _scheme on every call, it seems that the “correct” answer is to use WSGI middleware, as in this snippet: http://flask.pocoo.org/snippets/35/

    (This Flask bug seems to confirm that that is the preferred way.)

    Basically, if your WSGI environment has environ['wsgi.url_scheme'] = 'https', then url_for will generate https: URLs.

    I was getting http:// URLs from url_for because my server was deployed behind an Elastic Beanstalk load balancer, which communicates with the server in regular HTTP. My solution (specific to Elastic Beanstalk) was like this (simplified from the snippet linked above):

    class ReverseProxied(object):     def __init__(self, app):         self.app = app      def __call__(self, environ, start_response):         scheme = environ.get('HTTP_X_FORWARDED_PROTO')         if scheme:             environ['wsgi.url_scheme'] = scheme         return self.app(environ, start_response)  app = Flask(__name__) app.wsgi_app = ReverseProxied(app.wsgi_app) 

    The Elastic Beanstalk-specific part of that is HTTP_X_FORWARDED_PROTO. Other environments would have other ways of determining whether the external URL included https. If you just want to always use HTTPS, you could unconditionally set environ['wsgi.url_scheme'] = 'https'.

    PREFERRED_URL_SCHEME is not the way to do this. It’s ignored whenever a request is in progress.

    • 5 answers
    • 0 votes
  • Asked on July 16, 2020 in Numpy.

    These answers do help explain this, but it still isn’t perfectly intuitive for a non-programmer (i.e. someone like me who is learning Python for the first time in context of data science coursework). I still find using the terms “along” or “for each” wrt to rows and columns to be confusing.

    What makes more sense to me is to say it this way:

    • Axis 0 will act on all the ROWS in each COLUMN
    • Axis 1 will act on all the COLUMNS in each ROW

    So a mean on axis 0 will be the mean of all the rows in each column, and a mean on axis 1 will be a mean of all the columns in each row.

    Ultimately this is saying the same thing as @zhangxaochen and @Michael, but in a way that is easier for me to internalize.

    • 21 answers
    • 0 votes
  • as your exception states you are trying to find org.apache.xmlbeams.XmlExceptiom. but looking a the docs I found https://xmlbeans.apache.org/docs/3.0.0/reference/org/apache/xmlbeans/XmlException.html and the correct package and class name seems to be:

    • 1 answers
    • 0 votes
  • In Java, you can escape quotes with \:

    String value = " \"ROM\" "; 
    • 10 answers
    • 0 votes