Number of non repeating lines – unique count
You could try using uniq man uniq and do the following sort file | uniq -u | wc -l
You could try using uniq man uniq and do the following sort file | uniq -u | wc -l
You will want to look into the nl2br() function along with the trim(). The nl2br() will insert <br /> before the newline character (\n) and the trim() will remove any ending \n or whitespace characters. $text = trim($_POST[‘textareaname’]); // remove the last \n or whitespace character $text = nl2br($text); // insert <br /> before \n … Read more
You should use “beginPath()“. That is it. function lineDraw() { var canvas=document.getElementById(“myCanvas”); var context=canvas.getContext(“2d”); context.clearRect(0, 0, context.width,context.height); context.beginPath();//ADD THIS LINE!<<<<<<<<<<<<< context.moveTo(0,0); context.lineTo(event.clientX,event.clientY); context.stroke(); }
Either use Array#each to iterate over your array and call IO#puts to write each element to the file (puts adds a record separator, typically a newline character): File.open(“test.txt”, “w+”) do |f| a.each { |element| f.puts(element) } end Or pass the whole array to puts: File.open(“test.txt”, “w+”) do |f| f.puts(a) end From the documentation: If called … Read more
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
EDIT: This same trick was already posted by someone else in a previous thread. It is easy to have std::istream_iterator do what you want: namespace detail { class Line : std::string { friend std::istream & operator>>(std::istream & is, Line & line) { return std::getline(is, line); } }; } template<class OutIt> void read_lines(std::istream& is, OutIt dest) … Read more
You can write a LINQ-based line reader pretty easily using an iterator block: static IEnumerable<SomeType> ReadFrom(string file) { string line; using(var reader = File.OpenText(file)) { while((line = reader.ReadLine()) != null) { SomeType newRecord = /* parse line */ yield return newRecord; } } } or to make Jon happy: static IEnumerable<string> ReadFrom(string file) { string … Read more
if (distance(A, C) + distance(B, C) == distance(A, B)) return true; // C is on the line. return false; // C is not on the line. or just: return distance(A, C) + distance(B, C) == distance(A, B); The way this works is rather simple. If C lies on the AB line, you’ll get the following … Read more
Canvas calculates from the half of a pixel ctx.moveTo(50,150.5); ctx.lineTo(150,150.5); So starting at a half will fix it Fixed version: http://jsfiddle.net/9bMPD/357/ This answer explains why it works that way.
On a POSIX operating system (e.g. Linux or OS X) you can write the following into your Bash shell: wc -l `find . -iname “*.php”` This will count the lines in all php-files in the current directory and also subdirectories. (Note that those single ‘quotes’ are backticks, not actual single quotes)