Gang's Tech Stuff

We have started using gerrit for code review in our project from last one year. And whenever I push some changes to gerrit, it highlights the spaces present at the end of the lines. I was looking for such an option in Vim so that I don’t miss such spaces in the code, and I found it here, just add following lines to your .vimrc.

 

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/

 

Hope it helps!

 

Advertisements
Tags:

There might be some instances where you want to wait for the ENTER key from the user. And with a constraint stating ‘not to use’ any non-standard libraries. I faced this situation a while ago and found out a simple solution stated below:


std::cout << “Press ENTER to continue…”;
std::cin.ignore( std::numeric_limits::max(), ‘\n’ );

Readers are kindly requested to share the different ways to achieve this task if they know!

One might face a situation where he wants to know what all queries are running on an Oracle DB or may be there is a lock on a table due to a update/delete query and you want to kill that query. In such cases, you can use following query to display all the sessions, the related queries, status, etc.

column sid          format 999999           heading ‘SID’
column sh           format 999999           heading ‘Serial#’
column pid          format a18              heading ‘PID’
column ia           format a1               heading ‘Active’
column iw           format a1               heading ‘Waiting’
column secs         format 999999999        heading ‘Seconds|In Event’
column event        format a25              heading ‘Event’
column sql          format a45              heading ‘SQL’
set linesize 132
set pagesize 50

select  s.sid sid,
s.serial# sh,
s.process pid,
decode (s.status, ‘INACTIVE’, ‘N’, ‘Y’) ia,
decode (sw.wait_time, 0, ‘Y’, ‘N’) iw,
decode (sw.wait_time, 0, sw.seconds_in_wait, sw.seconds_in_wait-sw.wait_time/100) secs,
sw.event event,
decode (sq.sql_text, null, ‘ – Not Available -‘, sq.sql_text) sql
from    v$session_wait sw,
v$session s,
v$sql sq
where   s.sid = sw.sid and
s.sql_hash_value = sq.hash_value(+) and
s.program like ‘%&program%’
and upper(sq.sql_text) not like ‘%CONFIGURATION%’;

 

And to kill a particular session, use following query:

alter system kill session ‘<Serial#>,<PID>’;

 

Hope this helps.

Have you even wondered how many physical/virtual processors your machine is having? Well, you psrinfo is the command which can display that information.

psrinfo – displays information about processors.
prtconf – print system configuration.
dmesg – collect system diagnostic messages to form error log.

Ex:

(My machine is having 4 physical processors which are divided into 8 Virtual processors)

$> psrinfo -p
4


$> psrinfo -pv
The UltraSPARC-IV physical processor has 2 virtual processors (0, 16)
The UltraSPARC-IV physical processor has 2 virtual processors (1, 17)
The UltraSPARC-IV physical processor has 2 virtual processors (2, 18)
The UltraSPARC-IV physical processor has 2 virtual processors (3, 19)

Refer the man pages for more information on the above commands.

One must be wondering how come the executable permission of a shell script file got changed after check-in. Well, at least I did when I need to re-release the patch just because of these Permissions.

Usually, when we make some script file to Clearcase elements, its permission will still be maintained. But when we check-in the same file, it’ll be having Read-Only permissions.

So, how to retain the permissions of a file after check in also? Use ‘protect’ option.

ct protect -r -chmod 555 <directory-or-file-name>

Note:  ‘-r’ option is valid only for Directories.

Have you ever wondered why there is no toUpper() kind of function in shell script? Well, i think the reason is typeset command.

What does it do exactly? A lot:

* Set a parameter as an integer by using -i option so as to fasten the arithmetic operations on that variable.

* Convert to lower case using -l

* Mark a variable as Read-only using -r

etc…

Converting into upper case? Yes, you guessed it right, use -u option.

How to use it? You can use it before assignment or after assignment, does not make much difference.

prompt $> typeset -u temp_var
prompt $> temp_var=hi
prompt $> echo $temp_var
HI
prompt $> temp_var2=hey
prompt $> typeset -u temp_var2
prompt $> echo $temp_var2
HEY

Whats more? You can even give more that one variable to this typeset command.

prompt $> typeset -l temp_var temp_var2
prompt $> echo $temp_var $temp_var2
hi hey

For more information on typeset, use man typeset.

How do one can rename a Clearcase View on Unix/Linux/Solaris? Very simple, use rename command. :-p
Just kiddin, never mind. 😉

Well, renaming a Clearcase View requires the renaming of both the storage and the tag. Here are the basic steps for the same but you are recomended to refer the Product Documentation if it doesn’t work:

1. Stop the view
PROMPT> cleartool endview <view-tag>

2. Remove the view tag to untag the view
PROMPT> cleartool rmtag -view <view-tag>

3. Remove the Clearcase registry entry to unregister the view object
PROMPT> cleartool unregister -view <vie-storage-path-name>.vps

4. Rename the view storage directory
PROMPT> mv <old-view-storage>.vps <new-view-storage>.vps

5. Register the new name fo the view storage
PROMPT> cleartool register -view <new-view-storage-path-name>.vps

6. Create a new tag for the view
PROMPT> cleartool mktag -view -tag <new-view-tag> <new-view-storage-path-name>.vps

As it is on Solaris machine, no need to start the view explicitly. You can directly start working by setting the new view.

Note: These steps are just for rename operation. If you wish to move, not rename, the snapshot view directory which contains special files, you need to take some additional steps.