How can I highlight the line of text that is closest to the mouse?

Not sure if jQuery will help you out much here, but you could take a look at the element.getClientRects method, documented on MSDN and MDC. More specifically, this example at MSDN is sort of similar to what you want to achieve, highlighting lines using a cleverly z-indexed div element that goes behind the text at … Read more

Process very large (>20GB) text file line by line

It’s more idiomatic to write your code like this def ProcessLargeTextFile(): with open(“filepath”, “r”) as r, open(“outfilepath”, “w”) as w: for line in r: x, y, z = line.split(‘ ‘)[:3] w.write(line.replace(x,x[:-3]).replace(y,y[:-3]).replace(z,z[:-3])) The main saving here is to just do the split once, but if the CPU is not being taxed, this is likely to make … Read more

How to draw an updating line

You need to have two drawing calls: One for the non-persistent line that follows the cursor in the MouseMove using someControls.CreateGraphics the other for the persisting line, triggered in the MouseUp, where you store the coordinates and call Invalidate on your canvas control and draw in the Paint event of your canvas using its e.Graphics … Read more

How to draw a directed arrow line in Java?

Although Pete’s post is awesomely comprehensive, I’m using this method to draw a very simple line with a little triangle at its end. // create an AffineTransform // and a triangle centered on (0,0) and pointing downward // somewhere outside Swing’s paint loop AffineTransform tx = new AffineTransform(); Line2D.Double line = new Line2D.Double(0,0,100,100); Polygon arrowHead … Read more

Drawing Multiple Lines in D3.js

Yes. First I would restructure your data for easier iteration, like this: var series = [ [{time: 1, value: 2}, {time: 2, value: 4}, {time: 3, value: 8}], [{time: 1, value: 5}, {time: 2, value: 9}, {time: 3, value: 12}], [{time: 1, value: 3}, {time: 2, value: 2}, {time: 3, value: 2}], [{time: 1, value: … Read more

How to place multiple evenly-spaced arrowheads along an SVG line?

Based on a clarification of the question, here’s an implementation of creating intermediary points along a <polyline> element such that the marker-mid=”url(#arrowhead)” attribute will work. See below that for an introduction to markers and arrowheads. Demo: http://jsfiddle.net/Zv57N/ midMarkers(document.querySelector(‘polyline’),6); // Given a polygon/polyline, create intermediary points along the // “straightaways” spaced no closer than `spacing` distance … Read more

How to save memory when reading a file in Php?

Try SplFileObject echo memory_get_usage(), PHP_EOL; // 333200 $file = new SplFileObject(‘bible.txt’); // 996kb $file->seek(5000); // jump to line 5000 (zero-based) echo $file->current(), PHP_EOL; // output current line echo memory_get_usage(), PHP_EOL; // 342984 vs 3319864 when using file() For outputting the current line, you can either use current() or just echo $file. I find it clearer … Read more

How can I format a list to print each element on a separate line in python? [duplicate]

Embrace the future! Just to be complete, you can also do this the Python 3k way by using the print function: from __future__ import print_function # Py 2.6+; In Py 3k not needed mylist = [’10’, 12, ’14’] # Note that 12 is an int print(*mylist,sep=’\n’) Prints: 10 12 14 Eventually, print as Python statement … Read more

tech