EzDevInfo.com

console interview questions

Top console frequently asked interview questions

How do I call controller/view methods from the console in Rails?

When I load script/console, some times I want play with the output of a controller or a view helper method.

Are there ways to:

  • simulate a request?
  • call methods from a controller instance on said request?
  • test helper methods, either via said controller instance or another way?

Source: (StackOverflow)

Advertisements

sudo echo "something" >> /etc/privilegedFile doesn't work... is there an alternative?

This is a pretty simple question, at least it seems like it should be, about sudo permissions in Linux.

There are a lot of times when I just want to append something to /etc/hosts or a similar file but end up not being able to because both > and >> are not allowed, even with root.

Is there someway to make this work without having to su or sudo su into root?


Source: (StackOverflow)

How to run a .sh-script in an Unix console/Mac terminal?

I know it, forget it and relearn it again. Time to write it down.


Source: (StackOverflow)

How do I trap ctrl-c in a C# console app

I would like to be able to trap ctrl-c in a C# console application so that I can carry out some cleanups before exiting. What is the best way of doing this?


Source: (StackOverflow)

How to color the Git console in Ubuntu?

I recently saw that the Git console in Windows is colored, e.g. Green for additions, red for deletions, etc. How do I color my Ubuntu Git console like that?

To install it, I used the command: $ apt-get install git-core


Source: (StackOverflow)

How do I increase the capacity of the Eclipse output console?

Even with the "scroll lock" option enabled for the Eclipse console, eventually it overfills and starts auto-scrolling on me.

Is there some way of increasing the capacity of the console so that it stores more lines? I wasn't able to find the option.


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)

clear javascript console in Google Chrome

I was wondering if I could clear up the console with some command..

console.log(), can print... is there a command to clear up console?..

I've tried to console.log(console); and got this functions below...

assert: function assert() { [native code] }
constructor: function Console() { [native code] }
count: function count() { [native code] }
debug: function debug() { [native code] }
dir: function dir() { [native code] }
dirxml: function dirxml() { [native code] }
error: function error() { [native code] }
group: function group() { [native code] }
groupEnd: function groupEnd() { [native code] }
info: function info() { [native code] }
log: function log() { [native code] }
markTimeline: function markTimeline() { [native code] }
profile: function profile() { [native code] }
profileEnd: function profileEnd() { [native code] }
time: function time() { [native code] }
timeEnd: function timeEnd() { [native code] }
trace: function trace() { [native code] }
warn: function warn() { [native code] }
__proto__: Object

[ I guess there's no way to clear up the console... but I wanted someone to say it to me... ]


Source: (StackOverflow)

.NET Global exception handler in console application

Question: I want to define a global exception handler for unhandled exceptions in my console application. In asp.net, one can define one in global.asax, and in windows applications /services, one can define as below

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);

But how can I define a global exception handler for a console application ?
currentDomain seems not to work (.NET 2.0) ?

Edit:

Argh, stupid mistake.
In VB.NET, one needs to add the "AddHandler" keyword in front of currentDomain, or else one doesn't see the UnhandledException event in IntelliSense...
That's because the VB.NET and C# compilers treat event handling differently.


Source: (StackOverflow)

How to make Google Chrome JavaScript console persistent?

Since I'm building a dynamic site, I need to track the changes between pages, ie. Ajax calls, POST, GET stuff and similar stuff.

I'm looking for the same functionality like in Firebug (where you can enable "persistent" and the console is not cleared every time you reload a page or submit a form.

So, my questions is: is there a way to make Google Chrome JavaScript console persistent? (And if yes, how?)

Update: Copying the answer here, if anyone's still looking for this, Chrome 14+ has a setting in Developer Tools > Settings labelled "Console: Preserve log on navigation".

Update 2: the latest versions of Chrome (33+) have this option by right-clicking in the console.


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)

Disable Rails SQL logging in console

Is there a way to disable SQL query logging when I'm executing commands in the console? Ideally, it would be great if I can just disable it and re-enable it with a command in the console.

I'm trying to debug something and using "puts" to print out some relevant data. However, the sql query output is making it hard to read.


Edit: I found another solution, since setting the logger to nil sometimes raised an error, if something other than my code tried to call logger.warn

Instead of setting the logger to nil you can set the level of the logger to 1.

ActiveRecord::Base.logger.level = 1 # or Logger::INFO

Source: (StackOverflow)

How to clear python interpreter console?

Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff, etc.

Like any console, after a while the visible backlog of past commands and prints gets to be cluttered, and sometimes confusing when re-running the same command several times. I'm wondering if, and how, to clear the Python interpreter console.

I've heard about doing a system call and either calling cls on Windows or clear on Linux, but I was hoping there was something I could command the interpreter itself to do.

Note: I'm running on Windows, so Ctrl+L doesn't work.


Source: (StackOverflow)

Text Progress Bar in the Console

Is there a good way to do the following?

I wrote a simple console app to upload and download files from an FTP server using the ftplib.

Each time some data chunks are downloaded, I want to update a text progress bar, even if it's just a number.

But I don't want to erase all the text that's been printed to the console. (Doing a "clear" and then printing the updated percentage.)


Source: (StackOverflow)