Using the clipboard in WSH

How to get the text from the clipboard


set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
textFromClipboard = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
WScript.Echo textFromClipboard

How to put the text into clipboard


textIntoClipboard = "Some text" & VbCrLf & "Some more text"

Set objIE = WScript.CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop

objIE.document.ParentWindow.ClipboardData.SetData "text", textIntoClipboard
objIE.Quit

The detailed explanation could be found here.

Oracle: check the existence of logon/logoff triggers


select
decode((count(trigger_name)),0,'LOGON trigger missing',
'Number of logon triggers: ' || count(trigger_name) ) "INFO"
from sys.dba_triggers
where
TRIGGERING_EVENT like 'LOGON%'
and status='ENABLED'
and owner='SYS'
union
select
decode((count(trigger_name)),0,'LOGOFF trigger missing','',
'Number of logoff triggers:' || count(trigger_name)) "INFO"
from sys.dba_triggers
where
TRIGGERING_EVENT like 'LOGOFF%'
and status='ENABLED'
and owner='SYS'

The field TRIGGERING_EVENT could have the spaces at the end! Very clever…

Unix shell: workaround for loop problem

It’s not possible to get the value of the loop variables in some versions of ksh.

Example:

#!/bin/ksh

num=0
cat $0 | while read line ; do
let num=num+1
done

echo "Number=$num"

This script will return “Number=0” as the result on some Linux machines.

Here is the workaround for the problem: You should change the redirection method for the input file.

#!/bin/ksh

l=0
while read line ; do
let l=l+1
done < $0 echo "Number=$l"

The last script will return the correct result: "Number=9"

Another possibility is to use the named pipe:

#!/bin/ksh

TMPPIPE=/tmp/thepipe.$$
mkfifo $TMPPIPE
cat $0 > $TMPPIPE &
num=0
while read line ; do
let num=num+1
done < $TMPPIPE echo "Number=$num"

JavaScript: Soundex implementation

There is a special algorithm for comparision strings, which sound similar (Soundex).

Here is JavaScript Soundex implementation:

function soundex ( s_src )
{
var s_rez = "0000" ;
var new_code, prev, idx

a_codes = { "bfpv": 1, "cgjkqsxz":2, "dt": 3, "l": 4, "mn": 5, "r": 6 };

s_src = s_src.toLowerCase().replace(/ /g,"")

if ( s_src.length < 1) { return(s_rez); } s_rez = s_src.substr(0,1); prev = "0"; for ( idx = 1 ; idx < s_src.length ; idx++) { new_code = "0"; cur_char = s_src.substr(idx,1) for (s_code in a_codes) if (s_code.indexOf(cur_char) >= 0)
{ new_code = a_codes[ s_code ] ; break ; }

if (new_code != prev && new_code != "0" ) {
s_rez += new_code;
}

prev = new_code;
}

s_rez = s_rez + "0000"

return s_rez.substr(0,4);
}

Oracle: usage of the tablespaces


set pagesize 10000

set COLSEP '|'
set VERIFY off
set serveroutput on size 1000000
BREAK ON report

column tablespace_name format a30 heading 'TABLESPACE'
column sizegb format 9999999999D9 heading 'SIZE-Gb'
column usedproc format 999D99 heading 'USED-%'
column status format a10 heading 'STATUS'
COMPUTE sum LABEL 'Total size:' of sizegb ON report

SELECT b.tablespace_name ,
b.bytes/1024/1024/1024 as sizegb ,
NVL(100-((a.bytes/b.bytes)*100), 100) usedproc,
replace(c.status,' ','_') status
FROM
( select tablespace_name,
sum(bytes) bytes
from dba_free_space
group by tablespace_name
) a ,
( select tablespace_name,
sum(bytes) bytes
from dba_data_files
group by tablespace_name
) b ,
dba_tablespaces c
WHERE b.tablespace_name = a.tablespace_name (+)
AND b.tablespace_name = c.tablespace_name
union
select f.TABLESPACE_NAME,
f.TOTAL_MB/1024 sizegb,
nvl( (u.USED_MB/f.TOTAL_MB)*100, 0 ) usedproc,
'TEMPORARY' status
from
(
select f1.TABLESPACE_NAME,sum( f1.BYTES/1024/1024 ) TOTAL_MB
from (
select TABLESPACE_NAME,BYTES
from dba_temp_files
union all
select TABLESPACE_NAME,BYTES
from dba_data_files
where TABLESPACE_NAME in (
select TABLESPACE_NAME
from dba_tablespaces
where CONTENTS='TEMPORARY'
)
) f1
group by f1.TABLESPACE_NAME
) f,
(
select u1.TABLESPACE,
sum(u1.blocks) * max((select value from v$parameter where name='db_block_size')/1024/1024) USED_MB
from v$sort_usage u1
group by u1.TABLESPACE
) u
where f.TABLESPACE_NAME = u.tablespace (+)
ORDER BY 1;