Monday, May 25, 2009

Finding grants from data dictionary



Unless you make an full export with grants you won’t get all grants when doing a export/import with Oracle. So if you don’t have a list of all grants across those schemas you imported, you will have a huge job of compiling and establishing which grants are missing.

The solution to this is to find those grants through the data dictionary on the source system. For instance, if you want to find all grants made by the PORTAL schema, the query would be like this:


SET HEADING OFF
SET PAGES 999
SPOOL grants.sql
SELECT 'GRANT '||privilege||' ON '||owner||'.'||table_name||' TO '||grantee||DECODE(grantable,'YES',' WITH GRANT OPTION;',';')
FROM DBA_TAB_PRIVS
WHERE grantor = 'PORTAL';
SPOOL OFF
EXIT


Now you have everything you need in the grants.sql and this script can now be run on the target system.

Syncronize and optimize Portal text indexes


To improve performance with Oracle Text based searches in Oracle Portal, you should on a regular basis make sure to syncronize and optimize Portal text indexes (if this is not allready set up during installation).



sqlplus portal/<password>

exec wwv_context.sync
exec wwv_context.optimize
exit

Which languages are installed in my Portal ?

select title from portal.WWNLS_SYS_LANGUAGE$
where installed <> 0;

Oracle Q-Quote


To avoid quoting quotes in string, Oracle 10g offers the Q-Quote technique.



Let’s say yoy want to select the following from dual: I’m into rock’n’roll

This would normally mean you should quote the three quotes, but with the Q-Quote technique it’s much simpler:
SQL> SELECT q'[I'm into rock'n'roll]' FROM dual;

Mac keyboard combinations on a Windows keyboard



I recently bought a Mac mini and a Belkin KVM switch, which enables me to use my existing monitor, keyboard and mouse with both my current Windows PC and my new Mac mini. There are however quite a few characters I couldn’t find when using the Windows keyboard on Mac, so I will use this thread to remember them. Thanks to Allan for supplying many of the keystrokes for a Windows keyboard with Danish layout.

  1. Commercial at @ : ALT Gr-* (just ALT-* in some applications)

  2. Pipe | : ALT-i

  3. Left brace { : SHIFT-ALT-8

  4. Right brace } : SHIFT-ALT-9

  5. Apple Command Key: Windows Key

  6. Less than < : §

  7. Greater than > : SHIFT-§

  8. Copy : Windows Key-C

  9. Cut : Windows Key-X

  10. Paste : Windows Key-V

  11. Quit Application : Windows Key-Q

  12. Dollar $ : <

  13. Euro € : SHIFT-4

  14. Backslash \ : SHIFT-ALT-7


I also found this article, which suggests a software solution to the problem. When I get a Mac keyboard, I should study this. The layout of a Mac keyboard can also be useful.

Software for your Mac



VersionTracker is much like download.com, except it also has a large collection of software for Mac OS X. You browse by categories, and can sort by licenses, so it’s easy to find software at a decent price (for instance free).

I was however not satisfied with any of the FTP clients I found for Mac. As a devoted FileZilla user, I didn’t think any of the FTP/SCP clients for Mac was living up to the standard. Furtunatly the FileZilla project has decided to release FileZilla on Linux and Mac too, and there is allready a beta available :)

A really nice open source text editor with syntax highlighting is Smultron.

Add A New Harddisk To Linux Using Parted


If you have added a new harddrive, and want to take advantage of it in Linux, parted is a great tool to get you started. Parted is like fdisk, but a bit more challenging. Please note that when following this tutorial you will loose any data on the harddrive in question.



Finding the device name


The first task is to find the devicename of your new harddrive. SCSI disks are usually given device names like /dev/sda, /dev/sdb, /dev/sdc, /dev/sdd and so on (dependening of how many phsyical disks you have got. IDE disks are usually given device names like /dev/hda, /dev/hdb, /dev/hdc, /dev/hdd and so on. In this tutorial we will image we have added a second SCSI disk, we will treat it as /dev/sdb



Using parted


As root, type
parted /dev/sdb
and parted will now startup, expecting to perform work on our new harddrive.

First we create a disk label
(parted) mklabel msdos

Then we need to find the size of the disk, or more correctly the start- and end sector of the disk
(parted) print

The print command should display something like this:

Disk geometry for /dev/sdb: 0.000-102400.000 megabytes
Disk label type: msdos
Minor Start End Type Filesystem Flags


The geometry data will come in handy in our next command where we create a filesystem on the disk
(parted) mkpart primary ext2 0.000 102400.000

We can also make extra sure that we get a ext2 disk with the following command (please note that parted doesn’t support ext3):
(parted) mkfs 1 ext2

Now exit parted:
(parted) quit

Mounting the new drive


First create the mountpoint that you want to use for the new drive:
# mkdir /u01

Change the filesystem from ext2 to ext3:
# tune2fs -j /dev/sdb1
Now edit /etc/fstab and add the following line:
/dev/sdb1 /u01 ext3 defaults 1 1

The mount the new drive on mountpoint /u01:
# mount -a

Finally check that the new drive is mounted:
# df -k

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 5526416 2081024 3164660 40% /
/dev/sda1 101086 8613 87254 9% /boot
none 387852 0 387852 0% /dev/shm
/dev/sdb1 10317828 33460 9760252 1% /u01

Taking screenshots on a Mac



  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop

  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop

  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop

  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard

  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard

  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard


These screenshot tricks where found in MacRumors.

Hitchhiker’s Guide to HTML development


My first encounter with the Internet was in the late 80′ties. A friend of mine was fetching games for his Commodore64 through a modem link. This modem looked like it had been stolen from a sovjet military base in a spy movie or something. In 1993 I started at collegue, and since then I have been using the Internet allmost on a daily basis. Initially I was using Bulletin Board Systems (BBS) through telnet connections, but in 1995 I discovered the World Wide Web. Using Emacs and Netscape Navigator I started to make simple websites. With blinking text, large headers, fuzzy GIFs and nasty colors it worked, but looked awful. I learned HTML at a time when the markup language itself was so new. As a result of this, I early discovered many of the pitfalls that you can encounter when developing thin web applications. Many years have pasted since then.



HTML has been extended several times, and it can be utilized further by JavaScript, Cascading Stylesheet and multiple forms of active content. This article will focus on how you can achieve success with web development and which pitfalls to look out for. It doesn’t matter if you are using static HTML or dynamic HTML through languages like PHP, ASP, JSP or whatever. The guidelines and pitfalls are the same.

Follow standards


During the browser war between Netscape and Microsoft, web developers often found themself writing if-then statements which checked for browser vendor before supplying browser specific HTML and possibly JavaScript code. Today most end users are using Internet Explorer, but that should not prevent a web developer from using markup that any other modern web browser can understand.



The way to do this without complicated if-then statements is simply to follow the HTML or XHTML specifications produced by the World Wide Web Consortium (W3C). All modern browser should follow these standards to ensure your website looks allmost the same in any browser. The World Wide Web Consortium also has a W3C validator service which checks your HTML/XHTML code and let’s you know if it doesn’t follow the standard. In general, you should keep your HTML files clean. In other words they should contain plain HTML/XHTML and nothing else.

Today many websites are not W3C compliant, causing a very bad user experience for those not using Internet Explorer. Also remember that the ones using alternate browsers often are those likely to shop online anyway, so make sure they are happy.

Use stylesheets


All colors, sizes and layout should be kept in CSS files (Cascading Stylesheet). In addition to a clean source, it also makes it incredible easy to replace all colors, sizes and layout without changing your markup. There is a similar W3C service for validating your Cascading Stylesheet. If you are not a web developer, but are getting your website made by a web design agency, you should demand that their finished product is fully W3C HTML/XHTML and CSS compliant.



Use naming standards


When naming HTML, CSS or image files there are a few standards you should enforce. Filenames should be written in lowercase letters only, and they should only contain A-Z charcters and 0-9 number. Stay away from national alphabet extentions or special characters. You should also limit the lenght of the filenames. The reasons for these strict rules are as follows: Your website might be developed on one operating system (for instance Mac OS X), but shall run on another operating system (for instance Linux or Windows 2003 Server). Some operating systems are case sensitive - others are not. Therefore it’s vital to use just one case all over the place, and lowercase looks far better than uppercase. When you refer to these files from within other files, make sure to use the same case (lowercase). For instance, imagine you have an image called logo.png that you want to refer to in an HTML page. The code <img src=”Logo.PNG“> would not work on most operating systems. Instead you should have written it in the correct case: <img src=”logo.png”>



Limit bandwidth usage


Unless you are developing a website for an art gallery or something, you should limit the number and size of images shown on your website. The general rule is: Only show images that have some relevance. Also you should take efforts to reduce the size of the image file. Ideally no image file should be larger than 25K, preferably much smaller.



When people visit your website they are not there to look at graphics (unless it’s an art gallery). They are there to read, and if it takes too long to load the page, they will give up and go somewhere else. Please remember that not all users are sitting on fast DSL connections.

Use Portable Network Graphics


In general the PNG format has better compression than JPEG. This of course will give slightly less quality to your graphics, but for the human eye it won’t make much difference. And then again, unless you are running an art gallery, image quality is not the first priority. In addition to JPEG and PNG there is another very popular format which are mostly used for icons. It’s called GIF. Unfortunatly GIF is a commercial format, so unless you have made your GIF files using an image editor that pays royalties to Unisys., you are in trouble. Both legally and finacially. PNG on the other hand is a free format, and can be used anywhere without having to think about royalties, and it’s of far better quality than GIF.



Be careful with JavaScript


When Netscape introduced JavaScript as standardized language to bring life to else boring HTML files, I thought it was a good idea. So did Microsoft, but their implementation of it extended Netscape’s standard in such a way it only worked in Internet Explorer. Web developers either had to make browser specific sets of JavaScript functions - or simply write JavaScript that excluded all browsers except Internet Explorer. Very few web developers actually took the time to write something that worked in multiple browsers. Naturally Microsoft’s implementation of JavaScript was full of security holes, so many end users completly disabled JavaScript regardless of which browser they were using.



Instead of writing lots of if-then statements to cover every possible scenario, I would recommend that you write JavaScript only when appropriate, and make sure to actually test it in mainstreaim browsers before you release it.

Avoid active content


Some people and companies uses active content heavily on their website. For instance applications written with Java Web Start, commersials written with Flash, charts written in SVG, and all kinds of other plugins. In my experience, end users hate this. Unless the active content has a valid use, don’t have it on your website! In addition to annoying users, it also spends lots of bandwidth.



Final remarks


Don’t panic! These were just my top pics, but I could also have written about pop-up ads, dead links or other issues. If you have any other guidelines for HTML development, please share them with me. Also keep in mind that travelling through cyberspace does not require a towel.



Upgrade Fedora Core from version 5 to 6


I found an execellent guid on how to upgrade from FC5 to FC6 the other day. Unfortunatly I did not bookmark the site, but I did save the steps to a text file, which I will post here for future use.



Upgrade Fedora Core


yum update
yum clean all
rpm -Uhv http://download.fedora.redhat.com/pub/fedora/linux/core/6/i386/os/Fedora/RPMS/fedora-release-6-4.noarch.rpm
http://download.fedora.redhat.com/pub/fedora/linux/core/6/i386/os/Fedora/RPMS/fedora-release-notes-6-3.noarch.rpm
yum -y update
yum -y update

I don’t know why I had to run yum -y update twice.

Upgrade the kernel


rpm -Uhv http://mirrors.dotsrc.org/fedora/updates/6/i386/kernel-2.6.18-1.2869.fc6.i686.rpm
http://mirrors.dotsrc.org/fedora/updates/6/i386/kernel-doc-2.6.18-1.2869.fc6.noarch.rpm
http://mirrors.dotsrc.org/fedora/updates/6/i386/kernel-devel-2.6.18-1.2869.fc6.i686.rpm

Reboot server to use the new kernel


init 6

The telnet hack


One of the most famous and useful hacks either when testing websites or firewall access to websites is “the telnet hack”. When you think of it, a web browser is just like an advanced telnet client executing HTTP commands. Thus using the classic telnet application and writing the HTTP commands your self has proven a good way of testing both website content and website access through firewalls. The syntax is: telnet <server> <port>



Get webserver version


# telnet www.httpforum.com 80
Trying 80.166.163.20…
Connected to www.httpforum.com (80.166.163.20).
Escape character is ‘^]’.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Date: Wed, 30 Mar 2005 18:44:46 GMT
Server: Apache
Connection: close
Content-Type: text/html; charset=utf-8

Connection closed by foreign host.

So this shows us that www.httpforum.com is running Apache and the webservers default character set is UTF-8

Is the site available


# telnet www.httpforum.com 80
Trying 80.166.163.20…
telnet: connect to address 80.166.163.20: Connection refused telnet:
Unable to connect to remote host: Connection refused

Well, seems like I have forgotten to open port 80 in the firewall, or that the webserver is not running. Please note that if there is a firewall between the webserver and your client, the telnet hack is a far better option than ping, as the ping protocol is most likely limited by the firewall. People who pings a webserver and get no respons from the host, often take this as a proof the webserver is not started or that it’s network services are not running, but since ping is disabled by most firewalls, you can’t trust the ping command. In addition, tracert/traceroute command is also often blocked in firewalls, so you can’t trust that command either. The telnet hack is the only sure method of checking if the firewall is open on the web port (default 80 for HTTP and default 443 for HTTPS).

How To Fix The Win XP Search Tool



  1. Launch regedit




  2. Open HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex




  3. Double-click FilterFilesWithUnknownExtensions




  4. Change the data value to 1



Finding Windows Uptime


How can one find out how long a Windows system has been running ? Many are probably using Task Manager, and looking at how long System Idle Process has been running. This is however an uncertain method because multiple physical or virtual CPUs will give an incorrect picture. There are two more precise Command Prompt commands to find it:





  1. systeminfo




  2. net statistics server




Tracing JInitiator 1.3.22



In the Windows Control Panel open the Jinitiator Control Panel.
Enter the following in the “Java Run Time parameters” textfield:

-Djavaplugin.trace=true
-Djavaplugin.trace.option=basic|net|security|ext|liveconnect

The traceoptions are cumulative, so if you use security traceoption it will
also record basic and net traces.

These trace messages are shown both on the Jinitiator Console, and in the file
C:\Documents and Settings\<username>\jinitiator1322.trace

Upgrade Fedora Core from version 6 to 7



Upgrade the release

yum -y update

yum clean all

rpm -Uhv <url>/fedora-release-7-3.noarch.rpm <url>/fedora-release-notes-7.0.0-1.noarch.rpm

Where the <url> for instance is http://ftp-stud.hs-esslingen.de/pub/fedora/linux/releases/7/Fedora/i386/os/Fedora/

yum -y update

Upgrade the kernel

rpm -Uhv <url>/kernel-2.6.21-1.3194.fc7.i686.rpm <url>/kernel-doc-2.6.21-1.3194.fc7.noarch.rpm <url>/kernel-headers-2.6.21-1.3194.fc7.i386.rpm <url>/kernel-devel-2.6.21-1.3194.fc7.i686.rpm

Where the <url> for instance is http://ftp-stud.hs-esslingen.de/pub/fedora/linux/releases/7/Fedora/i386/os/Fedora/

Reboot server to use the new kernel

init 6

Update the rest

yum -y update

Schedule a job using DBMS_SCHEDULER


In this article I show how you can setup automatic rebuild of Portal indexes every day at 04.00 am.



Create your PL/SQL procedure


sqlplus portal/<password>

CREATE OR REPLACE PROCEDURE my_analyze_portal IS
BEGIN
wwsbr_stats.delete_stats;
wwsbr_stats.gather_stats;
wwsbr_stats.enable_monitoring;
wwsbr_stats.gather_stale;
commit;
END;
/

Submit the job


sqlplus portal/<password>

BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'job_my_analyze_portal',
job_type => 'STORED_PROCEDURE',
job_action => 'my_analyze_portal',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=daily; byhour=4; byminute=0; bysecond=0',
end_date => NULL,
enabled => TRUE,
comments => 'Refresh Portal indexes.');
END;
/

COMMIT;

EXIT

View the job


You can view the current status of this job at any time.



SELECT job_name, enabled, last_start_date,next_run_date,comments
FROM user_scheduler_jobs
WHERE job_action='my_analyze_portal';

Put DBMS_SCHEDULER to the test



Imagine you have a job that should run every third minute, monday to friday and sunday, but only between 18.00 and midnight. How would you do that with DBMS_JOB ? The short answer is: You wouldn’t! The longer answer would be to have a chain of jobs enabling, disabling and redefining eachothers.

With DBMS_SCHEDULER however, this is just a walk in the park, and can be achieved with one single statement in a block:

BEGIN
dbms_scheduler.create_schedule (
schedule_name => ‘WOW_SCHEDULE’,
repeat_interval => ‘FREQ=DAILY; BYDAY=1,2,3,5,7; BYHOUR=18,19,20,21,22,23; BYMINUTE=0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57; BYSECOND=0′,
comments => ‘Every third minut between 18.00 and midnight monday to friday and sundays’);
END;
/

Find an attribute’s value dynamically

Imagine you have a custom attribute on a lot of Portal pages and you want to read it’s value programatically in order to use it in some other context. This is one way you could do it:


SELECT ta.value
FROM portal.wwv_things t, portal.wwv_thingattributes ta
WHERE t.id = ta.masterthingid
AND ta.attributeid IN (
SELECT id FROM portal.wwsbr_attribute$ WHERE name = '&attributeName'
AND siteid IN (SELECT id FROM portal.wwsbr_sites$ WHERE name = '&siteName')
)
AND t.siteid IN (SELECT id FROM portal.wwsbr_sites$ WHERE name = '&siteName')
AND t.cornerid=&pageId;