A bit about

Hello, everyone! All you can see below is just my bank of information. Some material I've found in the fathomless net, some I've learned myself. Don't think all of the information here is right or actual, but may be it could be of use for you :) All feedback is welcome, especially constructive ones :)

Thursday, October 22, 2009

QT: Window in the center of screen

The problem is how to position Qt windows in the center of screen. Found the solution here. It's a Russian site, but I hope the code is visible. There are just two similar codes for positioning. I liked the second one :) It's shorter and clearer.
QRect frect = frameGeometry();
frect.moveCenter(QDesktopWidget().availableGeometry().center());
move(frect.topLeft())

I assume that this code is placed inside a constructor of the window which is positioned.

Linux: start remote detached screen

Screen is very useful tool in case when it's necessary to start remote command without wait for its completeness. But by default it doesn't allow to detach screen without an actual terminal:
$ ssh Server "screen -m -d echo test"
Must be connected to a terminal.

The solution is to use ssh's -t flag:
$ ssh -t Server "screen -m -d echo test"

Tuesday, October 20, 2009

Linux: ps output fomat

It took for me some time to find the solution, because "ps --help" doesn't print the full information especially about output format. I often need to obtain some process ID from script, based on command name and its arguments.

The first solution is to parse "ps -aux". But it's not convenient because pid is not the first column. I found command in the man page:
$ ps -eo pid,comm,args
It allows one to define certain columns. Possible keys are:
pcpu; group; ppid; user; args; comm; rgroup; nice; pid; pgid; etime; ruser; time; tty; vsz

Thursday, October 15, 2009

MS SQL: Drop view if it exists

Microsoft recommends the following way of dropping database view without an error message if the view doesn't exist (http://msdn.microsoft.com/en-us/library/aa258835%28SQL.80%29.aspx):
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME = 'View_myview')
DROP VIEW dbo.View_myview
GO