web analytics

Perl: how to get the position of the match

Let’s search for the word “brave” in the string “Hello, new brave world!”. There are several methods to get the position of the match in Perl.

#1 – use POS function Function pos returns the position, where search was finished.

$txt = "Hello, brave new world!" ; $txt =~ m/(brave)/g; my $pos = pos($txt) – […]

Oracle: who is connected to the server

Here is the simple query, showing who is connected to the server.

col username FOR a15 col program FOR a25 trun SELECT sid, serial#, username, program, SUBSTR(module,1,10) module, logon_time FROM v$session ORDER BY 1,2;

This is almost the same query, limiting the output to the active users:

SELECT sid, serial#, username, program, SUBSTR(module,1,10) module, logon_time […]

Oracle: kill session

The command to kill Oracle is simple:

ALTER SYSTEM KILL SESSION ‘&sid,&serial’;

sid – session ID serial – session serial number

If the version 11g and this is RAC, additional syntax is possible:

ALTER SYSTEM KILL SESSION ‘&sid,&serial,@&inst_id’;

inst_id – instance id number (1, 2, 3 …)

Script to find the […]

mySQL: How to reset root password

If the password for the mysql “root” user is lost, it’s still possible reset it to some other value. The restart of the mySQL server will be necessary, of course.

The following should be done:

Stop the server It could be done normally:

/etc/init.d/mysql stop

or effectively:

ps -ef | grep mysql … mysql 25079 […]

VBA: how to read text file

This is just example, how to read text file in Visual Basic for Applications (for example, in Excel macro).

It’s just a stub: there is no error processing here, the source file is really text file, no problems with permissions etc.

Sub read_from_text_file() txtFile = Application.GetOpenFilename("Text Files (*.txt), *.txt") If txtFile = False Then […]