Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Passionable Logo Passionable Logo
Sign InSign Up

Passionable

Passionable Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions

Language

Share
  • Facebook
0Followers
10Answers
10Questions
Home/Language
  • Recent Questions
  • Most Answered
  • Answers
  • No Answers
  • Most Visited
  • Most Voted
  • Random
  1. Asked: December 14, 2021In: Language

    Easiest way to convert int to string in C++

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 5:49 am

    C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string. #include <string> std::string s = std::to_string(42); is therefore the shortest way I can think of. You can even omit naming the typRead more

    C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string.

    #include <string> 
    
    std::string s = std::to_string(42);
    

    is therefore the shortest way I can think of. You can even omit naming the type, using the auto keyword:

    auto s = std::to_string(42);
    

    Note: see [string.conversions] (21.5 in n3242)

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Asked: December 14, 2021In: Language

    Get the full URL in PHP

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 5:47 am

    Have a look at $_SERVER['REQUEST_URI'], i.e. $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; (Note that the double quoted string syntax is perfectly correct) If you want to support both HTTP and HTTPS, you can use $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'Read more

    Have a look at $_SERVER['REQUEST_URI'], i.e.

    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    

    (Note that the double quoted string syntax is perfectly correct)

    If you want to support both HTTP and HTTPS, you can use

    $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    

    Editor’s note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Asked: December 14, 2021In: Language

    Problem with gif with transparent background

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 5:46 am

    here another one How to fix .gif with corrupted alpha channel (stuck pixels) collected with Graphicsmagick? Your gif is disposal = 3 that means it needs previous image as it renders incrementally. The problem is the image is with black background and not white ... Here are the disposals possible: ifRead more

    here another one How to fix .gif with corrupted alpha channel (stuck pixels) collected with Graphicsmagick?

    Your gif is disposal = 3 that means it needs previous image as it renders incrementally. The problem is the image is with black background and not white …

    Here are the disposals possible:

         if (disposal==0) s="no animation";
    else if (disposal==1) s="leave image as is";
    else if (disposal==2) s="clear with background";
    else if (disposal==3) s="restore previous image";
    else                  s="reserved";
    

    When I render it with my decoder it looks like this:

    [![capture][1]][1]

    So there are 2 possible things at play here:

    1. transparency

    maybe this should be handled as transparent image with background but even decent image viewer (like FastStone Image Viewer) shows the same thing so I doubt this is the case…

    1. extentions

    This is the most likely cause. Nowadays WEB browsers (for few years now) depend on undocumented custom made extentions added to GIFs extention packets (and not part of any GIF specs) and ignores the GIF file format completely for some aspects of rendering (like looping). Simply because all of them use the same image lib for decoding GIFs which is simply coded badly (or by design)…

    for more info see:

    • Animated gif only loops once in Chrome and Firefox

    So my guess is the GIF of yours have some extention packet telling brownser to use different disposal method then the one stored in GIF header. So simply your GIF is buggy and only buggy GIF decoder can render it properly …

    So your decoder ignores the background color of GIF hence rendering incorrectly as the incremental render does not work with non black color background …

    And yes those white lines are with gaps … its not aliasing … [1]: https://i.stack.imgur.com/6Kbbp.gif

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Asked: December 14, 2021In: Language

    TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 5:37 am

    You opened the file in binary mode: with open(fname, 'rb') as f: This means that all data read from the file is returned as bytes objects, not str. You cannot then use a string in a containment test: if 'some-pattern' in tmp: continue You'd have to use a bytes object to test against tmp instead: ifRead more

    You opened the file in binary mode:

    with open(fname, 'rb') as f:
    

    This means that all data read from the file is returned as bytes objects, not str. You cannot then use a string in a containment test:

    if 'some-pattern' in tmp: continue
    

    You’d have to use a bytes object to test against tmp instead:

    if b'some-pattern' in tmp: continue
    

    or open the file as a textfile instead by replacing the 'rb' mode with 'r'.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. Asked: December 14, 2021In: Language

    Does Python have a string ‘contains’ substring method?

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 5:03 am

    You can use the in operator: if "blah" not in somestring: continue

    You can use the in operator:

    if "blah" not in somestring: 
        continue
    
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  6. Asked: December 14, 2021In: Language

    ValueError: invalid literal for int() with base 10: ”

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 4:37 am

    Just for the record: >>> int('55063.000000') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '55063.000000' Got me here... >>> int(float('55063.000000')) 55063 Has to be used!

    Just for the record:

    >>> int('55063.000000')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: '55063.000000'
    

    Got me here…

    >>> int(float('55063.000000'))
    55063
    

    Has to be used!

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  7. Asked: December 14, 2021In: Language

    Git refusing to merge unrelated histories on rebase

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 4:31 am

    The default behavior has changed since Git 2.9: "git merge" used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history mergedRead more

    The default behavior has changed since Git 2.9:

    “git merge” used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch --allow-unrelated-histories option to be used in a rare event that merges histories of two projects that started their lives independently.

    See the Git release changelog for more information.

    You can use --allow-unrelated-histories to force the merge to happen.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  8. Asked: December 14, 2021In: Language

    Failed to load resource: the server responded with a status of 404 (Not Found)

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 4:29 am

    Your files are not under the jsp folder that's why it is not found. You have to go back again 1 folder Try this: <script src="../../Jquery/prettify.js"></script>

    Your files are not under the jsp folder that’s why it is not found. You have to go back again 1 folder Try this:

    <script src="../../Jquery/prettify.js"></script>
    
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  9. Asked: December 14, 2021In: Language

    Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 4:27 am

    If I understood it right you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. A tutorial about hRead more

    If I understood it right you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request. A tutorial about how to achieve that is Using CORS.

    When you are using Postman they are not restricted by this policy. Quoted from Cross-Origin XMLHttpRequest:

    Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they’re limited by the same origin policy. Extensions aren’t so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  10. Asked: December 14, 2021In: Language

    What’s the difference between “{}” and “[]” while declaring a JavaScript array?

    Alek Richter Enlightened
    Added an answer on December 14, 2021 at 4:21 am

    Nobody seems to be explaining the difference between an array and an object. [] is declaring an array. {} is declaring an object. An array has all the features of an object with additional features (you can think of an array like a sub-class of an object) where additional methods and capabilities arRead more

    Nobody seems to be explaining the difference between an array and an object.

    [] is declaring an array.

    {} is declaring an object.

    An array has all the features of an object with additional features (you can think of an array like a sub-class of an object) where additional methods and capabilities are added in the Array sub-class. In fact, typeof [] === "object" to further show you that an array is an object.

    The additional features consist of a magic .length property that keeps track of the number of items in the array and a whole slew of methods for operating on the array such as .push(), .pop(), .slice(), .splice(), etc… You can see a list of array methods here.

    An object gives you the ability to associate a property name with a value as in:

    var x = {};
    x.foo = 3;
    x["whatever"] = 10;
    console.log(x.foo);      // shows 3
    console.log(x.whatever); // shows 10
    

    Object properties can be accessed either via the x.foo syntax or via the array-like syntax x["foo"]. The advantage of the latter syntax is that you can use a variable as the property name like x[myvar] and using the latter syntax, you can use property names that contain characters that Javascript won’t allow in the x.foo syntax.

    A property name can be any string value.


    An array is an object so it has all the same capabilities of an object plus a bunch of additional features for managing an ordered, sequential list of numbered indexes starting from 0 and going up to some length. Arrays are typically used for an ordered list of items that are accessed by numerical index. And, because the array is ordered, there are lots of useful features to manage the order of the list .sort() or to add or remove things from the list.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 4k
  • Best Answers 0
  • Users 2
  • Popular
  • Answers
  • Alek Richter

    Truth value of a Series is ambiguous. Use a.empty, a.bool(), ...

    • 2 Answers
  • Alek Richter

    What is a NullPointerException, and how do I fix it?

    • 2 Answers
  • Alek Richter

    Make MS Word document look like it has been typeset ...

    • 2 Answers
  • Alek Richter
    Alek Richter added an answer Pandas DataFrame columns are Pandas Series when you pull them… January 13, 2022 at 2:21 pm
  • Alek Richter
    Alek Richter added an answer The handshake failure could have occurred due to various reasons:… January 13, 2022 at 2:19 pm
  • Alek Richter
    Alek Richter added an answer Mac OS X doesn't have apt-get. There is a package… January 13, 2022 at 2:18 pm

Top Members

Alek Richter

Alek Richter

  • 4k Questions
  • 1k Points
Enlightened

Trending Tags

questin question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • New Questions
  • Trending Questions
  • Must read Questions
  • Hot Questions

© 2021 Passionable. All Rights Reserved