Cross-platform way of getting temp directory in Python

That would be the tempfile module. It has functions to get the temporary directory, and also has some shortcuts to create temporary files and directories in it, either named or unnamed. Example: import tempfile print tempfile.gettempdir() # prints the current temporary directory f = tempfile.TemporaryFile() f.write(‘something on temporaryfile’) f.seek(0) # return to beginning of file … Read more

What is the best way to find the user’s home directory in Java?

The bug you reference (bug 4787391) has been fixed in Java 8. Even if you are using an older version of Java, the System.getProperty(“user.home”) approach is probably still the best. The user.home approach seems to work in a very large number of cases. A 100% bulletproof solution on Windows is hard, because Windows has a … Read more

How to check if running in Cygwin, Mac or Linux?

Usually, uname with its various options will tell you what environment you’re running in: pax> uname -a CYGWIN_NT-5.1 IBM-L3F3936 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin pax> uname -s CYGWIN_NT-5.1 And, according to the very helpful schot (in the comments), uname -s gives Darwin for OSX and Linux for Linux, while my Cygwin gives CYGWIN_NT-5.1. But you … Read more

What is “stdafx.h” used for in Visual Studio?

All C++ compilers have one serious performance problem to deal with. Compiling C++ code is a long, slow process. Compiling headers included on top of C++ files is a very long, slow process. Compiling the huge header structures that form part of Windows API and other large API libraries is a very, very long, slow … Read more

How to get current time and date in C++?

Since C++ 11 you can use std::chrono::system_clock::now() Example (copied from en.cppreference.com): #include <iostream> #include <chrono> #include <ctime> int main() { auto start = std::chrono::system_clock::now(); // Some computation here auto end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end-start; std::time_t end_time = std::chrono::system_clock::to_time_t(end); std::cout << “finished computation at ” << std::ctime(&end_time) << “elapsed time: ” << elapsed_seconds.count() << … Read more

What’s the strategy for handling CRLF (carriage return, line feed) with Git?

Almost four years after asking this question, I have finally found an answer that completely satisfies me! See the details in github:help‘s guide to Dealing with line endings. Git allows you to set the line ending properties for a repo directly using the text attribute in the .gitattributes file. This file is committed into the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)