formatting

Go back up a line in a linux console?

做~自己de王妃 提交于 2019-12-21 20:36:31
问题 I know I can go back the line and overwrite its contents with \r . Now how can I go up into the previous line to change that? Or is there even a way to print to a specific cursor location in the console window? My goal is to create some self-refreshing multiline console app with PHP. 回答1: Use ANSI escape codes to move the cursor. For example: Esc [ 1 F . To put the Escape character in a string you'll need to specify its value numerically, for example "\x1B[1F" As sujoy suggests, you can use

How to sort flat array into multidimensional tree

烈酒焚心 提交于 2019-12-21 17:40:15
问题 I have a table like id catagory suboff 1 software 0 2 programming 1 3 Testing 1 4 Designing 1 5 Hospital 0 6 Doctor 5 7 Nurses 5 9 Teaching 0 10 php programming 2 11 .net programming 2 How to write a code to get all these information in a multidimensional array based on the suboff as follows, -software --programming ---php programming --- .net programming --testing --designing -hospital --doctor --nurses -teaching 回答1: Assuming MySQL as your DB engine: // We'll need two arrays for this $temp

python's “.format” function

橙三吉。 提交于 2019-12-21 17:22:17
问题 Recently, I found ''.format function very useful because it can improve readability a lot comparing to the % formatting. Trying to achieve simple string formatting: data = {'year':2012, 'month':'april', 'location': 'q2dm1'} year = 2012 month = 'april' location = 'q2dm1' a = "year: {year}, month: {month}, location: {location}" print a.format(data) print a.format(year=year, month=month, location=location) print a.format(year, month, location) Whilst two first prints do format as I expect (yes,

what's the best way to format an xml string in ruby?

此生再无相见时 提交于 2019-12-21 12:46:13
问题 given an xml string like this: <some><nested><xml>value</xml></nested></some> what's the best option (using ruby) to format it into something readable like: <some> <nested> <xml>value</xml> </nested> </some> 回答1: require "rexml/document" include REXML source ='<some><nested><xml>value</xml></nested></some>' doc = Document.new( source ) doc.write( targetstr = "", 2 ) #indents with 2 spaces puts targetstr The #write writes to anything that takes <<(string), so this is valid too: doc.write(

How to set NLog's fileName to the process start date?

本秂侑毒 提交于 2019-12-21 12:07:12
问题 I tried <target name="txtFile" xsi:type="File" fileName="${date:format=yyyy-MM-dd HH-mm-ss}.txt" layout="${longdate} ${level} ${message}"/> but it creates a new file each minute. I realize that there is ${processinfo:property=StartTime} but I couldn't format it. I tried: ${processinfo:property=StartTime:format=yyyy-MM-dd HH-mm-ss} but it doesn't work 回答1: Using the Cached Layout Renderer For a solution that doesn't require code, use the Cached Layout Renderer: <target name="txtFile" xsi:type=

Format number with thousands separator in Excel using Apache POI

两盒软妹~` 提交于 2019-12-21 11:34:33
问题 I want to format some number cells, with a comma as thousands separator. For example: 12 -> 12 1200 -> 1,200 12000 -> 12,000 12000000 -> 12,000,000 120000000 -> 120,000,000 I have the following code. What should I use as formatStr ? Is there an easy way? Or do I have to detect the number of zeros in order to produce something like this #,###,### ? String formatStr = ""; HSSFCellStyle style = workbook.createCellStyle(); HSSFDataFormat format = workbook.createDataFormat(); style.setDataFormat

“user-select: none” and strange behaviour in Firefox

时光毁灭记忆、已成空白 提交于 2019-12-21 09:29:33
问题 I am trying to prevent text highlighting in Firefox for some, but not all elements on the page. Consider the following: <div style="-moz-user-select: none;"> I cannot be highlighted <div style="-moz-user-select: text;"> I should be highlightable, but am not. </div> </div> As I understand it, using the above css rules, the text of the inner div should be highlightable. However this does not appear to work. In practice none of the text can be highlighted. I am wondering if I am doing something

In Rails, how can I allow some html in a text area?

…衆ロ難τιáo~ 提交于 2019-12-21 07:36:06
问题 I have a Rails app (blog) that I am creating. Very basic stuff. In my content area I have a text area for the content of the post. I am needing to include some html in the text area (links, formating, etc). <%= f.text_area :content %> Is there another tag that I can use instead of text_area, that will allow me to do this? 回答1: Have you tried this in the views? <%= content.html_safe %> 回答2: This is an old question but I guess there's a pretty straight forward view helper for this: sanitize . I

Java - How to format a number to a 2 char string?

风流意气都作罢 提交于 2019-12-21 06:50:23
问题 How would I format an int between 0 and 99 to a string which is 2 chars. E.g 4 becomes "04" 36 becomes "36" Thanks in advance. 回答1: Use String.format(). Example: class Test{ public static void main(String[]args){ System.out.println(String.format("%02d", 42)); //42 System.out.println(String.format("%02d", 7)); //07 } } Edit: luiscubal's comment got me thinking, so I figured why not benchmark the three alternatives. import java.text.*; interface Fmt{ public String f(int x); } class Test{ static

How to display percent-values using ContentStringFormat?

不羁的心 提交于 2019-12-21 06:36:06
问题 Greetings to the enlightened ones! I'm playing on this for several hours now, but wasn't successful (perhaps because I'm quite new to WPF): I have a DataGrid whose DataContext is bound to a DataTable. The DataGrid is of fixed size and its purpose is to hold a value table y(x) (i.e. the headers show the x-values and the corresponding y-values are pasted from the clipboard and shown in the first DataGridRow). So far so good. The values are pasted (assigned as strings to dataTable.rows[0][i]