AutoIt: script for hotkeys usage

This script allows You to define the global Windows hotkeys via the configuration file.

The syntax of the config file is simple:

Hotkey,Program,Parameters

Here “Hotkey” is the combination of the keyboard key with one of the identifiers:

^ Ctrl
! Alt
+ Shift
# Windows-Key

Example:

;Win+C – start calculator
#{c},calc.exe

;Win+Shift+N – start notepad
+#{n},notepad.exe

;Win+N – start notepad++ together with apploc.exe
#{n},%windir%\AppPatch\AppLoc.exe,”%ProgramFiles%\Notepad++\notepad++.exe” -nosession /L0419

Continue reading AutoIt: script for hotkeys usage

Oracle: buffer overflow (ORU-10027)

Sometimes it’s necessary to show the output of the PL/SQL script.
Usually the dbms_output package is used:

SET serveroutput ON
DECLARE
 i NUMBER ;
BEGIN
 i:=0 ;
 WHILE i< 100000 LOOP
  i:=i+1 ;
  dbms_output.put_line('This is just test line #' || TO_CHAR(i) ) ;
 END LOOP ;
END;
/

After several thousands lines the following error message is displayed:

ORA-20000: ORU-10027: buffer overflow, limit of 20000 bytes
ORA-06512: at “SYS.DBMS_OUTPUT”, line 32
ORA-06512: at “SYS.DBMS_OUTPUT”, line 97
ORA-06512: at “SYS.DBMS_OUTPUT”, line 112
ORA-06512: at line 8

The error message means, that the internal buffer of dbms_output is full. How to increase it?
The following methods could be used:

...
dbms_package.enable(100000) ;
...
...
SET serveroutput ON SIZE 100000
...

In Oracle 10gR2 the new addition “size unlimited” could be used:

...
SET serveroutput ON SIZE unlimited
...

If these methods do not work, the temporary table could be used:

CREATE SEQUENCE my_output_seq ;
CREATE global TEMPORARY TABLE my_output_table( my_row NUMBER, my_out VARCHAR2(120) ) ;
...
INSERT INTO my_output_table VALUES ( my_output_seq.NEXTVAL, 'This is some string' ) ;
...
SELECT my_out FROM my_output_table ORDER BY my_row ;
DROP TABLE my_output_table ;
DROP SEQUENCE my_output_seq ;

MS Word: put syntax highlighed code into the document

Here is the simple method to put the code with highlighting into the Word document:

  1. Download and install Notepad++. This is easy-to-use and yet very powerful text editor with a lot of features, support of the plugins etc.
  2. Put your code into the Notepad++ edit window

  3. Configure the language, if Notepad++ did not do this automatically:
    Language->your language
    npp language select
    If necessary the additional configuration could be done in the Style Configurator: Settings->Style Configurator…

  4. Export the highlighted text with help of NppExport plugin: Plugins->NppExport
    It has the following options:
    npp export options

  5. Select “Copy RTF to clipboard”
  6. Paste the content of the clipboard into the Word document
  7. Make any changes in the Word document if necessary

Oracle: how to clone profiles

Here is the simple script for cloning the Oracle profiles.

SET serveroutput ON

DECLARE
 CURSOR c_profiles IS
  SELECT PROFILE, RESOURCE_NAME, LIMIT
  FROM dba_profiles
  ORDER BY PROFILE, resource_name;

  s_PROFILE                     dba_profiles.PROFILE%TYPE ;
  s_prev_PROFILE        dba_profiles.PROFILE%TYPE ;
  s_RESOURCE_NAME       dba_profiles.RESOURCE_NAME%TYPE ;
  s_LIMIT                       dba_profiles.LIMIT%TYPE ;
BEGIN

s_prev_PROFILE := 'no_such_profile' ;

dbms_output.enable(1000000);
OPEN c_profiles;
LOOP
  FETCH c_profiles INTO s_PROFILE,s_RESOURCE_NAME,s_LIMIT ;
  IF ( s_prev_profile <> s_profile ) THEN
    BEGIN
      dbms_output.put_line ( '--');
      dbms_output.put_line ( 'create profile "'||s_profile||'" limit ' ||s_RESOURCE_NAME|| ' ' || s_LIMIT||';' ) ;
      s_prev_profile := s_profile ;
    END;
  ELSE
       dbms_output.put_line ( 'alter profile "'||s_profile|| '" limit ' ||s_RESOURCE_NAME|| ' ' || s_LIMIT || ';' ) ;
  END IF;
  EXIT WHEN c_profiles%NOTFOUND ;
END LOOP ;

CLOSE c_profiles ;

END;
/

Continue reading Oracle: how to clone profiles

Windows: local printer option is greyed out

Some time ago I need to add the local printer to the system, however, this option was greyed out in the “Add printer” wizard.
The problem was caused by local policy, preventing the adding of the new devices to the system.

The following should be done to enable “Add local printer” option

  1. Start the policy editor (Control Panel -> Administrative tools -> Local security policy)
  2. Select “Local policy” item
  3. Find the item “Devices: Prevent Users from Installing Printer Drivers” in the section Security Settings -> Security Options and change it to Enabled
  4. Go to “Security Settings -> User Rights Assignment” section and check, that “Load & Unalod Drivers” option contains the active user group. It important, that even if it has “All Staff” already, it still could miss “Administrators” group, so it’s necessary to add it manually.

Windows 7: remove SP1 installation files

Here is the command to remove old installation files for SP1.

dism /online /cleanup-image /spsuperseded

Warning! The uninstallation of the Service Pack 1 will be impossible after removing these files!

Unix: print in color

This simple procedure takes 3 arguments as the parameters:

  • Text
  • Foreground color
  • Background color

It prints the text to the terminal in selected colors.

function print_color {
 local text=$1
 local fg=$2
 local bg=$3
 case "$fg" in
 red) fg="31m" ;;
 green) fg="32m" ;;
 yellow) fg="33m" ;;
 blue) fg="34m" ;;
 white) fg="37m" ;;
 black) fg="30m" ;;
 *) fg="37m" ;;
 esac
 case "$bg" in
 red) bg="41m" ;;
 green) bg="42m" ;;
 yellow) bg="43m" ;;
 blue) bg="44m" ;;
 white) bg="47m" ;;
 black) bg="40m" ;;
 *) bg="40m" ;;
 esac
 echo -en "\033[${fg}\033[${bg}${text}\033[0m"
}

Unix: rename files to lowercase

It’s very simple to rename the files to lowercase/uppercase using awk:

Lowercase

ls -1rt | awk '{ printf("mv %s %s\n", $0, tolower($0)) | "sh" } END { close("sh") }'

Uppercase

ls -1rt | awk '{ printf("mv %s %s\n", $0, toupper($0)) | "sh" } END { close("sh") }'

Unix: how to get md5 sum

Here are the possibilities to calculate md5 sum:

(Linux): md5sum filename

(Solaris): digest -a md5 -v filename

Oracle: quotes and quote operator

There are several methods to put the quote into the string.

The first (and very traditional) one: use 2 quotes.

SELECT 'This '' is quote' FROM dual;

If there are more than one quote, it’s difficult to read and write such strings

The second: use chr(39)

SELECT 'This ' || CHR(39) || ' is quote' FROM dual;

The third: put the quote into the variable

DECLARE
 s_quote VARCHAR2(1) := '''' ;
BEGIN
 dbms_output.put_line('This ' || s_quote || ' is quote' ) ;
END;

And, finally, Oracle 10g has added new feature: quote operator.

SELECT q'[This ' IS quote]' from dual ;

The general form is q’X string X’. Here X is just some character. If the brackets are used, Oracle expects the closing bracket for the end of the string.

Here are the additional examples:

SELECT q'(This ' IS quote)' from dual ;
select q'
|This ' is quote|' FROM dual ;
SELECT q'#This ' IS quote#' from dual ;
select q'
#This ' is quote#' FROM dual ;
SELECT q'?This ' IS quote?' from dual ;
select q'
TThis ' is quoteT' FROM dual ;