Splitting large text file into smaller text files by line numbers using Python

lines_per_file = 300 smallfile = None with open(‘really_big_file.txt’) as bigfile: for lineno, line in enumerate(bigfile): if lineno % lines_per_file == 0: if smallfile: smallfile.close() small_filename=”small_file_{}.txt”.format(lineno + lines_per_file) smallfile = open(small_filename, “w”) smallfile.write(line) if smallfile: smallfile.close()

Efficient maths algorithm to calculate intersections

Most of the answers already here seem to follow the general idea that: find the intersection of two straight lines passing the given points. determine if the intersection belong to both line segments. But when intersection does not occur often, a better way probably is to reverse these steps: express the straight lines in the … Read more

remove empty lines from text file with PowerShell

I found a nice one liner here >> http://www.pixelchef.net/remove-empty-lines-file-powershell. Just tested it out with several blanks lines including newlines only as well as lines with just spaces, just tabs, and combinations. (gc file.txt) | ? {$_.trim() -ne “” } | set-content file.txt See the original for some notes about the code. Nice 🙂

Limit numbers of lines in TextView

You just have to set a number of lines in your TextView like this: android:maxLines = “10” and you must also add: android:minLines=”1″ The rest of this not necessary if you are not using scrolling and a property which says that this TextView should be scrollable vertically: android:scrollbars = “vertical” And in your Java-code: yourTextView.setMovementMethod(new … Read more

How do I draw lines using XNA?

When working with XNA, everything (even 2d primitives) have to be expressed in a way that a 3d card can understand, which means that a line is just a set of vertices. MSDN has a pretty good walkthrough here: http://msdn.microsoft.com/en-us/library/bb196414.aspx#ID2EEF You’ll find that it takes more code to render a primitive line than it would … Read more

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