Reading local text file into a JavaScript array [duplicate]

Using Node.js sync mode: var fs = require(“fs”); var text = fs.readFileSync(“./mytext.txt”); var textByLine = text.split(“\n”) async mode: var fs = require(“fs”); fs.readFile(“./mytext.txt”, function(text){ var textByLine = text.split(“\n”) }); UPDATE As of at least Node 6, readFileSync returns a Buffer, so it must first be converted to a string in order for split to work: … Read more

Drawing a Long String on to a Bitmap results in Drawing Issues

When drawing a string of characters (ASCII or a form of Unicode encoded symbols) using Graphics.DrawString() with a fixed sized Font, the resulting graphics appear to generate a sort of grid, degrading the visual quality of the rendering. A solution is to substitute the GDI+ Graphics methods with the GDI methods, using TextRenderer.MeasureText() and TextRenderer.DrawText(). … Read more

Is there a flexible way to modify the contents of an editable element?

Your problem consists of two subproblems: Identify the target element of the contextmenu action. Insert a custom text fragment at the caret (remove any selection if it is present). Subproblem 1: Identifying the target element If crbug.com/39507 is resolved, then getting the element is easy. This feature request is almost 5 year old without any … Read more

Is there a Python module for converting RTF to plain text? [closed]

I’ve been working on a library called Pyth, which can do this: http://pypi.python.org/pypi/pyth/ Converting an RTF file to plaintext looks something like this: from pyth.plugins.rtf15.reader import Rtf15Reader from pyth.plugins.plaintext.writer import PlaintextWriter doc = Rtf15Reader.read(open(‘sample.rtf’)) print PlaintextWriter.write(doc).getvalue() Pyth can also generate RTF files, read and write XHTML, generate documents from Python markup a la Nevow’s stan, … Read more

Making text background transparent but not text itself

Don’t use opacity for this, set the background to an RGBA-value instead to only make the background semi-transparent. In your case it would be like this. .content { padding:20px; width:710px; position:relative; background: rgb(204, 204, 204); /* Fallback for older browsers without RGBA-support */ background: rgba(204, 204, 204, 0.5); } See http://css-tricks.com/rgba-browser-support/ for more info and … Read more

Using BufferedReader to read Text File

This is the problem: while (br.readLine() != null) { System.out.println(br.readLine()); } You’ve got two calls to readLine – the first only checks that there’s a line (but reads it and throws it away) and the second reads the next line. You want: String line; while ((line = br.readLine()) != null) { System.out.println(line); } Now we’re … Read more

Replace string in text file using PHP

Does this work: $msgid = $_GET[‘msgid’]; $oldMessage=””; $deletedFormat=””; //read the entire string $str=file_get_contents(‘msghistory.txt’); //replace something in the file string – this is a VERY simple example $str=str_replace($oldMessage, $deletedFormat,$str); //write the entire string file_put_contents(‘msghistory.txt’, $str);

Inner text shadow with CSS

Here’s a little trick I discovered using the :before and :after pseudo-elements: .depth { color: black; position: relative; } .depth:before, .depth:after { content: attr(title); color: rgba(255,255,255,.1); position: absolute; } .depth:before { top: 1px; left: 1px } .depth:after { top: 2px; left: 2px } The title attribute needs to be the same as the content. Demo: … Read more