formatting

Python ''.format(): "tuple index out of range"?

Consider the following snippet: >>> def foo(port, out, udp=False, ipv6=False, data=''): ... if not data: ... data = 'foo {family} {:port} {direction}'.format( ... family=('ipv6' if ipv6 else 'ipv4'), ... port=port, ... direction=('out' if...

Emacs code to automatically set indent-tabs-mode according to existing code

Is there ready Emacs code/package to automatically set indent-tabs-mode according to the file being visited? That is, if the currently visited file uses tabs for indentation, indent-tabs-mode should be set buffer-locally to true. Correspondingly if spaces are used, indent-tabs-mode should be set to false. The purpose of this is to automa...

Howto Format dict string outputs nicely

I wonder if there is an easy way to format Strings of dict-outputs such as this: { 'planet' : { 'name' : 'Earth', 'has' : { 'plants' : 'yes', 'animals' : 'yes', 'cryptonite' : 'no' } } } ..., where a simple str(dict) just would give you a quite unreadable ... {'planet' : {'has': {'plants': 'yes', 'an...

Converting Wikitext to plain text in Java

Any script available for converting Wikitext to Plain text? I prefer it implemented in Java. Thanks! ...

String format question

Hi, I'm using infragistic grid, and setting DisplayFormat of each column. DisplayFormat is type of string, and uses it`s value to show value of cellValue.ToString(DisplayFormat), when showing values to user in a grid (as Infra docs saying) In grid I have doubles, that have many numbers after point, and I don`t know how many. And I need ...

<TR> Formatting not happening in Firefox

Hi, I want to hide/unhide a group of HTML Table rows using javascript. To do so, I define each such row, whose visibility is to be toggled, as follows: When an appropriate event is fired, I toggle its state as follows: document.getElementById('rowId1').style.display = 'none';//or 'block' The above code works in both firefox and IE. B...

Declare function at end of file in Python.

Greetings StackOverflow, Is it possible to call a function without first fully defining it? When attempting, i get the error: "*function_name* is not defined". I am coming from a c++ background so this issue stumps me. Declaring the function before works: def Kerma(): return "energy / mass" print Kerma() However, atte...

Best Eclipse Code Formatters?

The default eclipse formatter formats my java code really funny. For example: hello.show().x().y() would be formatted oddly. .x() and .y() would be placed on a seperate line. Are there any other basic formatters that can do a better job? Examples and links welcome. ...

Is there a publicly available piece of Coldfusion code that will reliably convert e-mail "source code" into plain text?

I'm modifying the Coldfusion-based interface for a listserv admin application to show snippits of recently-posted messages on a page. The messages are all stored in a SQL Server 2005 database on the listserv's mail server, and in theory it should be easy enough to query the recent ones and display them. However, the "message" column of t...

How to convert byte size into human readable format in java?

How to convert byte size into human-readable format in Java? Like 1024 should become "1 Kb" and 1024*1024 should become "1 Mb". I am kind of sick of writing this utility method for each project. Are there any static methods in Apache Commons for this? ...

How can I take an xml string and display it on my page similiar to how StackOverflow does it with 'insert code'?

Hi All, I'm using the DataContractSerializer to convert and object returned from a WCF call to xml. The client would like to see that xml string in a webpage. If I output the string directly to a label, the browser strips out the angle brackets obviously. My question is how can I do something similar to StackOverflow? Are they doing a ...

How can I guarantee type safety in a function that accepts an unlimited amount of arguments?

The FastFormat library works like this: string example; fastformat::fmt(example, "I am asking {0} question on {1}", 1, "stackoverflow"); It also claims "100% type-safety". I can understand how other libraries such as boost::format achieve that by overloading operator%, something I do fairly often with my code too. But if I was able t...

How do I apply formatting to a particular word in a docx file using Win32::Ole in Perl?

For example, my docx file contains the following sentences: This is a Perl example This is a Python example This is another Perl example I want to apply bold style to all the occurrences of the word "Perl" like so: This is a Perl example This is a Python example This is another Perl example I've so far come up with the following scri...

Custom formatting mvc grid

Who could tell me why this formatting doesn't work in case of Ajax Binding? .RowAction(row => { if (row.DataItem.Probability == 100) row.HtmlAttributes["style"] = "color:green;"; }) ...

How to parse a string into a java.sql.date

Hi i am trying to parse a string into a java.sql.date Here is what i am doing private static SimpleDateFormat sdfout = new SimpleDateFormat("yyyy.MM.dd.HH.mm"); try{ String date = "2010.09.30.13.18"; task.setDueDate(new java.sql.Date(sdfout.parse(date).getTime())); } The problem is that i only get th...

How to add nice formated anotations to a R base graph using expression and the value of a variable?

Say, I have a variable rv which has some numerical value. Now, I want to plot the value of this variable on a base plot but preceded by a nicely formatted symbol e.g., r subscript m, using expression. To write on the plot I use mtext. However, what I get is either the value of the variable, but no nicely formatted symbol (left annotation...

Any easy ways to unformat a date?

Hi, I've got a bunch of dates in this String format: String date = "Wed Sep 15 16:31:05 BST 2010"; and I'd like to convert it back to a date or calendar object. Before I go and reinvent the wheel, are there any easy ways of doing this, preferably present in the JDK? ...

Should it be if() or if ()?

When you have line of code with a parenthetical statement, do you include a space before the parenthetical? For example, should it be if() or if () Thanks in advance! ...

MVC 2, Format Model display into a textbox

I have an easy one for you guys. In my view I have a textbox, like so: <%= Html.TextBoxFor(x => x.Price, new { @class = "text tiny" })%> Price is a decimal. When the form loads up. the textbox displays "0". I would like it to display "0.00". I tried <%= Html.TextBoxFor(x => String.Format("{0:0.00}", x.Price), new { @class = "text ...

How to create a formating and indentaion code in C#

How to start with creating a program to format C and their derived code into .net style formatted code so that if I input any program. This program can recognize and reformat by properly adding indentation and other things. ...