pretty-print

Preferred method for viewing code generated by Template Haskell

折月煮酒 提交于 2019-11-27 01:13:35
问题 As you know, Template Haskell is used to generate various kinds of AST splices programmatically at compile-time. However, a splice can often be very opaque, and it is often difficult to discern what a splice actually generates. If you run the Q monad for a splice, and the splice is well-typed, you get a show able representation of the generated piece of AST, but this representation can be very difficult to understand, because of its unstructured layout. What is the preferred method for

Any way to properly pretty-print ordered dictionaries?

早过忘川 提交于 2019-11-27 00:05:00
问题 I like the pprint module in Python. I use it a lot for testing and debugging. I frequently use the width option to make sure the output fits nicely within my terminal window. It has worked fine until they added the new ordered dictionary type in Python 2.7 (another cool feature I really like). If I try to pretty-print an ordered dictionary, it doesn't show nicely. Instead of having each key-value pair on its own line, the whole thing shows up on one long line, which wraps many times and is

How to format strings using printf() to get equal length in the output?

我的梦境 提交于 2019-11-26 22:04:16
I have two functions, one which produces messages like Starting initialization... and another which checks return codes and outputs "Ok" , "Warning" or "Error" . However, the output that is produced is of the different length: Starting initialization...Ok. Checking init scripts...Ok. How can I get something like this: Starting initialization... Ok. Checking init scripts... Ok. You can specify width on string fields, e.g. printf("%-20s", "initialization..."); and then whatever's printed with that field will be blank-padded to the width you indicate. The - left-justifies your text in that field.

How do I make Jackson's build() method pretty-print its JSON output?

点点圈 提交于 2019-11-26 22:03:04
问题 Merged with When using Spring MVC for REST, how do you enable Jackson to pretty-print rendered JSON?. I use Spring, Jersey and Jackson to provide an API that produces JSON. My @Component has a @Get method that returns Response.ok(entity).build(). That output is very compact. How do I make that output pretty / formatted? 来源: https://stackoverflow.com/questions/6176881/how-do-i-make-jacksons-build-method-pretty-print-its-json-output

Convert JSON String to Pretty Print JSON output using Jackson

大兔子大兔子 提交于 2019-11-26 21:33:34
This is the JSON string I have: {"attributes":[{"nm":"ACCOUNT","lv":[{"v":{"Id":null,"State":null},"vt":"java.util.Map","cn":1}],"vt":"java.util.Map","status":"SUCCESS","lmd":13585},{"nm":"PROFILE","lv":[{"v":{"Party":null,"Ads":null},"vt":"java.util.Map","cn":2}],"vt":"java.util.Map","status":"SUCCESS","lmd":41962}]} I need to convert the above JSON String into Pretty Print JSON Output (using Jackson), like below: { "attributes": [ { "nm": "ACCOUNT", "lv": [ { "v": { "Id": null, "State": null }, "vt": "java.util.Map", "cn": 1 } ], "vt": "java.util.Map", "status": "SUCCESS", "lmd": 13585 }, {

How can I get Express to output nicely formatted HTML?

蹲街弑〆低调 提交于 2019-11-26 21:17:57
When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted HTML? In your main app.js or what is in it's place: Express 4.x if (app.get('env') === 'development') { app.locals.pretty = true; } Express 3.x app.configure('development', function(){ app.use(express.errorHandler()); app.locals.pretty = true; }); Express 2.x app.configure('development', function(){ app.use(express.errorHandler()); app.set('view

How can I pretty-print XML source using VB6 and MSXML?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 17:40:56
问题 I've been looking after this for months now and I mostly found sites asking the same question. The answers I did found were always for .NET or C++ or involved XSLT. 回答1: After months of research I've come up with this. Public Function PrettyPrintXML(XML As String) As String Dim Reader As New SAXXMLReader60 Dim Writer As New MXXMLWriter60 Writer.indent = True Writer.standalone = False Writer.omitXMLDeclaration = False Writer.encoding = "utf-8" Set Reader.contentHandler = Writer Set Reader

Clearest way to comma-delimit a list?

谁说胖子不能爱 提交于 2019-11-26 17:01:01
What is the clearest way to comma-delimit a list in Java? I know several ways of doing it, but I'm wondering what the best way is (where "best" means clearest and/or shortest, not the most efficient. I have a list and I want to loop over it, printing each value. I want to print a comma between each item, but not after the last one (nor before the first one). List --> Item ( , Item ) * List --> ( Item , ) * Item Sample solution 1: boolean isFirst = true; for (Item i : list) { if (isFirst) { System.out.print(i); // no comma isFirst = false; } else { System.out.print(", "+i); // comma } } Sample

Javascript console.log(object) vs. concatenating string

廉价感情. 提交于 2019-11-26 16:31:24
问题 I'm running this in node.js: > x = { 'foo' : 'bar' } { foo: 'bar' } > console.log(x) { foo: 'bar' } undefined > console.log("hmm: " + x) hmm: [object Object] undefined What I don't understand is why console.log(x) "pretty-prints" the object, whereas string concatenation "ugly-prints" it. And more importantly, what's the best way to make it print hmm: { foo: 'bar' } ? 回答1: The + x coerces the object x into a string, which is just [object Object] : http://jsfiddle.net/Ze32g/ The pretty printing

How can I beautify JavaScript code using Command Line?

别等时光非礼了梦想. 提交于 2019-11-26 15:46:54
I am writing a batch script in order to beautify JavaScript code. It needs to work on both Windows and Linux . How can I beautify JavaScript code using the command line tools? Alan Storm First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/ , because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js Second, download and install The Mozilla group's Java based Javascript engine, Rhino . "Install" is a little bit misleading; Download the zip file, extract everything,