Getting a machine’s external IP address with Python

I liked the http://ipify.org. They even provide Python code for using their API. # This example requires the requests library be installed. You can learn more # about the Requests library here: http://docs.python-requests.org/en/latest/ from requests import get ip = get(‘https://api.ipify.org’).content.decode(‘utf8’) print(‘My public IP address is: {}’.format(ip))

Template Specialization VS Function Overloading

Short story: overload when you can, specialise when you need to. Long story: C++ treats specialisation and overloads very differently. This is best explained with an example. template <typename T> void foo(T); template <typename T> void foo(T*); // overload of foo(T) template <> void foo<int>(int*); // specialisation of foo(T*) foo(new int); // calls foo<int>(int*); Now … Read more

Read whole ASCII file into C++ std::string [duplicate]

There are a couple of possibilities. One I like uses a stringstream as a go-between: std::ifstream t(“file.txt”); std::stringstream buffer; buffer << t.rdbuf(); Now the contents of “file.txt” are available in a string as buffer.str(). Another possibility (though I certainly don’t like it as well) is much more like your original: std::ifstream t(“file.txt”); t.seekg(0, std::ios::end); size_t … Read more