What is the JavaScript string newline character?

Is \n the universal newline character sequence in JavaScript for all platforms? If not, how do I determine the character for the current environment? I’m not asking about the HTML newline element (<BR/>). I’m asking about the newline character sequence used within JavaScript strings. 15 s 15 I’ve just tested a few browsers using this … Read more

git-diff to ignore ^M

In a project where some of the files contains ^M as newline separators. Diffing these files are apparently impossible, since git-diff sees it as the entire file is just a single line. How does one diff with the previous version? Is there an option like “treat ^M as newline when diffing” ? prompt> git-diff “HEAD^” … Read more

What are carriage return, linefeed, and form feed?

What is the meaning of the following control characters: Carriage return Line feed Form feed 13 s 13 Carriage return means to return to the beginning of the current line without advancing downward. The name comes from a printer’s carriage, as monitors were rare when the name was coined. This is commonly escaped as \r, … Read more

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

I tried committing files with CRLF-ending lines, but it failed. I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead try Mercurial. How to properly handle CRLF line endings? 9 s 9 Almost four years after asking this question, I … Read more

Writing a list to a file with Python

Is this the cleanest way to write a list to a file, since writelines() doesn’t insert newline characters? file.writelines([“%s\n” % item for item in list]) It seems like there would be a standard way… 26 s 26 You can use a loop: with open(‘your_file.txt’, ‘w’) as f: for item in my_list: f.write(“%s\n” % item) In … Read more