Edgarvirgiliostephanie's Profile

245
Points

Questions
47

Answers
33

  • Asked on July 17, 2020 in Python.

    Another mothod.

    from simplified_scrapy import SimplifiedDoc xml = '''<item>         <title>Defensive Moves</title>         <link>www.timmy256.wordpress.com</link>         <pubDate></pubDate>         <dc:creator><![CDATA[jross]]></dc:creator>         <guid isPermaLink="false"> www.timmy256.wordpress.com </guid>            <description></description>         <content:encoded><![CDATA[I love playing basketball and eating food.]]></content:encoded>         </item>''' doc = SimplifiedDoc(xml) print(doc.select('item>content:encoded>html()')[9:-3]) 

    Result:

    I love playing basketball and eating food. 

    Here are more examples: https://github.com/yiyedata/simplified-scrapy-demo/tree/master/doc_examples

    • 439 views
    • 1 answers
    • 0 votes
  • Asked on July 17, 2020 in XML.

    In your application’s manifest, look for <Application> tag, then go to AppTheme‘s definition.

    <application         android:theme="@style/AppTheme" 

    And you can set the new color in App theme style.

    • 422 views
    • 1 answers
    • 0 votes
  • The desired output clarified the objective.

    Each <offer> element has 2 types of child elements:

    1. Standard set of elements to be converted into a rectangular data set.
    2. The remaining dynamic set of elements to be kept as XML.

    The CustomFields column, XML data type, should contain remaining XML elements that were not shredded and converted into a rectangular/relational data set.

    It is assumed that the id attribute value is unique for each <offer> element.

    Please see additional implementation details comments inside the T-SQL.

    SQL

    DECLARE @XmlDocument XML =  N'<?xml version="1.0"?> <offers>     <offer id="1" type="model">         <url>http://....</url>         <price>1500</price>          <vendor>НP</vendor>         <vendorCode>Q7533A</vendorCode>         <model>Color LaserJet 3000</model>     </offer>     <offer id="2" type="book">         <url>http://...</url>         <price>100</price>          <author>Tom</author>         <name>Name</name>         <year>2009</year>         <language>eng</language>     </offer> </offers>';  /* (1) We are using CROSS APPLY to get the XML's values into a result set as normal columns. In our case they are offer.OfferId and offer.OfferType (2) These columns are passed into XQuery by using sql:column(). (3) The XQuery FLWOR expression filters out not needed elements that were shredded. */ -- INSERT INTO Offers (Id, Url, Price, CustomFields) SELECT c.value('@id','INT') AS id     , c.value('(url/text())[1]','NVARCHAR(50)') AS Url     , c.value('(price/text())[1]','INT') AS Price     --, offer.OfferId     , @XmlDocument.query('<offer id="{sql:column("offer.OfferId")}" type="{sql:column("offer.OfferType")}">     {         for $x in /offers/offer[@id=sql:column("offer.OfferId")]/*[not(local-name(.) = ("url", "price","CategoryId","Picture"))]         return $x     }     </offer>') AS CustomFields  FROM @XmlDocument.nodes('/offers/offer')AS t(c)     CROSS APPLY (SELECT t.c.value('@id','INT') AS OfferId                         , t.c.value('@type','VARCHAR(30)') AS OfferType          ) AS offer; 

    Output

    +----+-------------+-------+-------------------------------------------------------------------------------------------------------------------------+ | id |     Url     | Price |                                                      CustomFields                                                       | +----+-------------+-------+-------------------------------------------------------------------------------------------------------------------------+ |  1 | http://.... |  1500 | <offer id="1" type="model"><vendor>НP</vendor><vendorCode>Q7533A</vendorCode><model>Color LaserJet 3000</model></offer> | |  2 | http://...  |   100 | <offer id="2" type="book"><author>Tom</author><name>Name</name><year>2009</year><language>eng</language></offer>        | +----+-------------+-------+-------------------------------------------------------------------------------------------------------------------------+ 
    • 479 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in .NET.

    I end up by doing this:

    public interface ILogExtender  {     ILog Log { get; set; } } 

    //interface implementation:

    public class LogExtender : ILogExtender {     public ILog Log { get; set; } } 
       [SecuritySafeCritical]     public class SomeExtensionLog4NetExtension : UnityContainerExtension     {         protected override void Initialize()         {             Context.Policies.Set(typeof(ILogExtender), typeof(ResolveDelegateFactory), (ResolveDelegateFactory)GetResolver);         }          public ResolveDelegate<BuilderContext> GetResolver(ref BuilderContext context)         {             return (ref BuilderContext c) => new LogExtender() { Log = LogManager.GetLogger("AuthenticationLog") };         }     } 

    Note the need to implement the new interface and set the ILog from Logmanager to it. It’s a bit dirty – but is working.

    this endup usefull as it allows me to had two diferent ways of using log4net – which was a request as i need to write de default logs to one place and specifics to another.

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

    You can use if statement as well. If id = 4 is true then set value = 1 else set value = 0. Hope this may help you.

    Update table set value = if(id=4, 1,0) 
    • 419 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Hmm, here’s a somewhat roundabout idea to solve this problem. You can crop a PIL Image object, by specifying pixels to crop like so: https://stackoverflow.com/a/43591567/13095028. The cropped image can then be saved to disk with Image.save(). You can also convert a matplotlib figure to PIL Image like so: https://stackoverflow.com/a/61755066/13095028.

    Combining these ideas gives the following which you can plug under your existing code. You’ll need to convert your bbox from inches to pixels.

    # Import PIL from PIL import Image  # Grab current figure object fig = plt.gcf()  # Use code snippet from 2nd link to convert matplotlib fig to PIL Image def fig2img(fig):     """Convert a Matplotlib figure to a PIL Image and return it"""     import io     buf = io.BytesIO()     fig.savefig(buf)     buf.seek(0)     img = Image.open(buf)     return img  img = fig2img(fig)  # Use code from 1st link to crop and save # Note: Fill in your bbox area in pixels here!! area = (400, 400, 800, 800) cropped_img = img.crop(area) cropped_img.save(plotOutDir+'/'+ "new") 
    • 424 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Basically, everything on your computer is eventually represented by 0’s and 1’s. The purpose of b-notation isn’t as you expected it to be.

    I would like to refer you to a great answer that might help you understand what the b-notation is for and how to use it properly: What does the 'b' character do in front of a string literal?

    Good luck.

    • 424 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in php.

    after you ensue no spelling problem between controller and route, try one of these possible solutions:

    1. run php artisan config:cache
    2. run composer dump-autoload
    3. check your web.php routes and change the forward / slash to backward \

    check this link it will help

    • 366 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in HTML.
    setInterval(()=>{alert('theres no need for this')},1000);

    • 317 views
    • 2 answers
    • 0 votes
  • Summing the multiplication of digits with their respective power of ten:

    i.e: 123 = 100+20+3 = 1*100 + 2+10 + 3*1 = 1*(10^2) + 2*(10^1) + 3*(10^0)

    function atoi(array) {  // use exp as (length - i), other option would be to reverse the array. // multiply a[i] * 10^(exp) and sum  let sum = 0;  for (let i = 0; i < array.length; i++) {     let exp = array.length-(i+1);     let value = array[i] * Math.pow(10,exp);     sum+=value; }  return sum; 

    }

    • 1126 views
    • 27 answers
    • 0 votes