How to delete and replace last line in the terminal using bash?

The carriage return by itself only moves the cursor to the beginning of the line. That’s OK if each new line of output is at least as long as the previous one, but if the new line is shorter, the previous line will not be completely overwritten, e.g.: $ echo -e “abcdefghijklmnopqrstuvwxyz\r0123456789” 0123456789klmnopqrstuvwxyz To actually … Read more

3D Line-Plane Intersection

Here is a Python example which finds the intersection of a line and a plane. Where the plane can be either a point and a normal, or a 4d vector (normal form), In the examples below (code for both is provided). Also note that this function calculates a value representing where the point is on … Read more

How to split strings over multiple lines in Bash?

This is what you may want $ echo “continuation”\ > “lines” continuation lines If this creates two arguments to echo and you only want one, then let’s look at string concatenation. In bash, placing two strings next to each other concatenate: $ echo “continuation””lines” continuationlines So a continuation line without an indent is one way … Read more

Delete final line in file with python

Because I routinely work with many-gigabyte files, looping through as mentioned in the answers didn’t work for me. The solution I use: with open(sys.argv[1], “r+”, encoding = “utf-8”) as file: # Move the pointer (similar to a cursor in a text editor) to the end of the file file.seek(0, os.SEEK_END) # This code means the … Read more

OpenGL ES iPhone – drawing anti aliased lines

One can achieve the effect of anti aliasing very cheaply using vertices with opacity 0. Here’s an image example to explain: Comparison with AA: You can read a paper about this here: http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf You could do something along this way: // Colors is a pointer to unsigned bytes (4 per color). // Should alternate in … Read more

How do cache lines work?

If the cache line containing the byte or word you’re loading is not already present in the cache, your CPU will request the 64 bytes that begin at the cache line boundary (the largest address below the one you need that is multiple of 64). Modern PC memory modules transfer 64 bits (8 bytes) at … Read more

OpenGL Scale Single Pixel Line

There is no “320×240 glOrtho canvas”. There is only the window’s actual resolution: 960×720. All you are doing is scaling up the coordinates of the primitives you render. So, your code says to render a line from, for example, (20, 20) to (40, 40). And OpenGL (eventually) scales those coordinates by 3 in each dimension: … Read more