EzDevInfo.com

printing interview questions

Top printing frequently asked interview questions

Print
only?

How do I print the indicated div (without manually disabling all other content on the page)?

I want to avoid a new preview dialog, so crating a new window with this content is not useful...

The page contains a couple of tables, one of them contains the div I want to print - the table is styled with visual styles for the web, that should not be shown in print....


Source: (StackOverflow)

Need to remove href values when printing in Chrome

I'm attempting to customize the print CSS, and finding that it prints links out with the href value as well as the link.

This is in Chrome.

For this HTML:

<a rel='nofollow' href="http://www.google.com">Google</a>

It prints:

Google (http://www.google.com)

And I want it to print:

Google

Source: (StackOverflow)

Advertisements

How to print binary tree diagram?

How can I print a binary tree in Java so that the output is like:

   4 
  / \ 
 2   5 

My node:

public class Node<A extends Comparable> {
    Node<A> left, right;
    A data;

    public Node(A data){
        this.data = data;
    }
}

Source: (StackOverflow)

How can I write to console in PHP?

Is it possible write string or log into the console?

What I mean

Just like in jsp, if we print something like system.out.println("some") it will be there at console not at page.


Source: (StackOverflow)

Landscape printing from HTML

I have a HTML report, which needs to be printed landscape because of the many columns. It there a way to do this, without the user having to change the document settings?

And what are the options amongst browsers.


Source: (StackOverflow)

Printing without newline (print 'a',) prints a space, how to remove?

I have this code:

>>> for i in xrange(20):
...     print 'a',
... 
a a a a a a a a a a a a a a a a a a a a

I want to output 'a', without ' ' like this:

aaaaaaaaaaaaaaaaaaaa

Is it possible?


Source: (StackOverflow)

How do I hide an element when printing a web page?

I have a link on my webpage to print the webpage. However, the link is also visible in the printout itself.

Is there javascript or HTML code which would hide the link button when I click the print link?

Example:

 "Good Evening"
 Print (click Here To Print)

I want to hide this "Print" label when it prints the text "Good Evening". The "Print" label should not show on the printout itself.


Source: (StackOverflow)

Print a file skipping X lines in Bash

I have a very long file which I want to print but skipping the first 1e6 lines for example. I look into the cat man page but I did not see any option to do this. I am looking for a command to do this or a simple bash program.


Source: (StackOverflow)

Python - The difference between sys.stdout.write and print

Are there situations in which sys.stdout.write() is preferable to print?

(Examples: better performance; code that makes more sense)


Source: (StackOverflow)

How to deal with page breaks when printing a large HTML table

I have a project which requires printing a HTML table with many rows.

My problem is the way the table is printed over multiple page. It will sometimes cut a row in half, making it unreadable because one half is on the bleeding edge of a page and the remainder is printer on the top of the next page.

The only plausible solution I can think of is using stacked DIVs instead of a table and force page-breaks if needed.. but before going through the whole change I thought I could ask here before.

Any ideas ?


Source: (StackOverflow)

What's the simplest way to print a Java array?

In Java, arrays don't override toString(), so if you try to print one directly, you get weird output including the memory location:

int[] intArray = new int[] {1, 2, 3, 4, 5};
System.out.println(intArray);     // prints something like '[I@3343c8b3'

But usually we'd actually want something more like [1, 2, 3, 4, 5]. What's the simplest way of doing that? Here are some example inputs and outputs:

// array of primitives:
int[] intArray = new int[] {1, 2, 3, 4, 5};
//output: [1, 2, 3, 4, 5]

// array of object references:
String[] strArray = new String[] {"John", "Mary", "Bob"};
//output: [John, Mary, Bob]

Source: (StackOverflow)

Python: How to print a class or objects of class using print()?

I am learning the ropes in Python. When I try to print an object of class Foobar using the print() function, I get an output like this:

<__main__.Foobar instance at 0x7ff2a18c>

Is there a way I can set the printing behaviour (or the string representation) of a class and its objects? For instance, when I call print() on a class object, I would like to print its data members in a certain format. How to achieve this in Python?

If you are familiar with C++ classes, the above can be achieved for the standard ostream by adding a friend ostream& operator << (ostream&, const Foobar&) method for the class.


Source: (StackOverflow)

Suggestions for debugging print stylesheets?

I've recently been working on a print stylesheet for a website, and I realized that I was at a loss for effective ways to tweak it. It's one thing to have a reload cycle for working on the on-screen layout:

  • change code
  • command-tab
  • reload

but that whole process gets much more arduous when you're trying to print:

  • change code
  • command-tab
  • reload
  • print
  • squint at print-preview image
  • open PDF in Preview for further inspection

Are there tools I'm missing out on here? Does WebKit's inspector have a "pretend this is paged media" checkbox? Is there some magic that Firebug (shudder) can do?


Source: (StackOverflow)

Get line number while using grep

Hello I am using grep recursive to search files for a string, and all the matched files and the lines containing that string are print on the terminal. But is it possible to get the line numbers of those lines too??

ex: presently what I get is /var/www/file.php: $options = "this.target", but what I am trying to get is /var/www/file.php: 1142 $options = "this.target";, well where 1142 would be the line number containing that string.

Syntax I am using to grep recursively is sudo grep -r 'pattern' '/var/www/file.php'

Hey one more question is, how do we get results for not equal to a pattern. Like all the files but not the ones having a certain string?


Source: (StackOverflow)

Why doesn't "System.out.println" work in Android?

I want to print something in console, so that I can debug it. But for some reason, nothing prints in my Android application.

How do I debug then?

public class HelloWebview extends Activity {
    WebView webview;    
    private static final String LOG_TAG = "WebViewDemo";
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebChromeClient(new MyWebChromeClient());
        webview.loadUrl("http://example.com/");    
        System.out.println("I am here");
    }

Source: (StackOverflow)