Archive for the ‘Uncategorized’ category

Making a particular URL path case-insensitive

April 20th, 2009

I wanted to make the /execed path case-insensitive, so that /ExecEd, /Execed, /EXECED/, etc. would work. This requires a RewriteCond to prevent an infinite loop:

RewriteCond %{REQUEST_URI} !^/execed
RewriteRule ^/execed/?$ /execed/ [R=301,L,nocase]

Note that our server config is written out by Perl code. So escape the $ character if you want to avoid an hour of tearing your hair out wondering why this doesn’t work:

RewriteCond %{REQUEST_URI} !^/execed
RewriteRule ^/execed/?\$ /execed/ [R=301,L,nocase]

Transfering files via the X clipboard

March 25th, 2009

In X systems you can copy text by highlighting it with the mouse. This automatically copies it to the “primary” clipboard. You can paste it with a middle mouse click(right click if you’re using putty I believe). This becomes so fast and natural that Ctrl+C/Ctrl+V starts to feel painfully difficult in comparison. Frequently I want to quickly copy the contents of a file from one server to another. In the past I’ve done this with:

[skh2@webdev-rhel4 mip]$ cat agreement-form.html

Then I select the output with the mouse and paste it into a file on another computer. Selecting the text of the file is tedious for longer files. I thought there must be a way to transfer the contents of a file directly to the clipboard, and it turns out there is!

http://sourceforge.net/projects/xclip

After installing this I can do:

[steve@box mip]$ xclip agreement-form.html

Then move to another computer and redirect the clipboard contents to a file:

[steve@otherbox mip]$ xclip -o > agreement-form.html

All too easy!

Fresh Soup vs. Grease

March 12th, 2009

How come Goldwyn-Smith hall gets Zeus and the Hotel School gets Mac’s “cafe”?

Just asking.

Palm Mojo

January 12th, 2009

I thought that Palm had faded away, but they are back promoting a new phone with a new OS and SDK. According to Ars Technica , “all the software running on the device is a combination of HTML, CSS, and JavaScript.” It also uses a JSON-based message bus to communicate with the device’s various services. It sounds quite similar to the way we’ve been discussing writing our apps, with an HTML/CSS/JavaScript UI using JSON to interact with a RESTful backend web service.

SQL Trace

January 8th, 2009

PowerDNS can use a SQL database to store DNS records. I was trying to use the latest version with Oracle on the backend and it was silently failing. I wanted to know what SQL, if any it was querying with so I could track down the error. It is possible to use a listener trace to snoop for SQL, but that requires restarting the listener. You can turn on SQL tracing without bringing down the database though.

$ sqlplus sys as sysdba

...

SQL> alter system set sql_trace=true;

System altered.

... Attempt to query PowerDNS ...

SQL> alter system set sql_trace=false;

System altered.

SQL> quit

The trace files are written to /u01/app/oracle/admin/sha/udump. There are a lot of them, so it helps to list only the ones that were modified within the last day:

$ cd /u01/app/oracle/admin/sha/udump/
$ find . -mtime -1 -print
./sha_ora_28587.trc
./sha_ora_28561.trc
./sha_ora_28477.trc
./sha_ora_28515.trc
etc...
$ find . -mtime -1 -print | xargs grep record
./sha_ora_18406.trc:SELECT "domain_id", "name", "type", "ttl", "prio", "content" FROM "records" WHERE "name"='test.example.com'

As you can see it helps to have a known string in the SQL to search for. You can also use the tkprof utility to process the trace files and produce more readable output. Also, if you open a trace file in SQLDeveloper it has a nice way of presenting the data. Here is some more information on SQL trace and tkprof.

Fixing a broken link throughout the site

December 12th, 2008

Today our link checking script reported 225 broken links. Most of these were due to Adobe changing the location of their Acrobat Reader download page. Usually when this happens I’m too lazy to figure out how to script the update. But this number of links finally tipped the scales in favor of my being too lazy to update them by hand. It turned out that most of them were produced by one or two dynamic pages, but at least I learned something :-) .

First I used grep to store the list of files containing the broken link in a text file:

steve@oracledev:~/perforce/depot/mainline/weblive/wwwroot$ grep -rl http://www.adobe.com/products/acrobat/readstep2.html . > /tmp/acrobat_link_files.txt

Then I marked those files for edit in Perforce:

steve@oracledev:~/perforce/depot/mainline/weblive/wwwroot$ cat /tmp/acrobat_link_files.txt | p4 -x - edit

Then I used sed to update the link in those files. If you’ve used perl-style regular expressions this will look familiar:

steve@oracledev:~/perforce/depot/mainline/weblive/wwwroot$ cat /tmp/acrobat_link_files.txt | xargs sed -i 's|http://www.adobe.com/products/acrobat/readstep2.html|http://get.adobe.com/reader/|g'

The xargs command calls the sed command for each line of the acrobat_link_files.txt file, passing the line as an argument. The -i switch to sed tells it to update the given file in place.

Perhaps next time I’ll really get my unix geek on and figure out how to do it in 1 line instead of 3.

Update: I’ve got it down to 1 command! The tee command can redistribute stdin to multiple outputs. Here it redirects stdin to the p4 edit command and also to stdout. We need to redirect p4 edit’s output to /dev/null or else that will also get sent to stdout and sed won’t know what to do with it.

steve@oracledev:~/perforce/depot/mainline/weblive/wwwroot/students/ugrad$ grep -rl http://certification.cornell.edu . | tee >(p4 -x - edit 1>/dev/null) | xargs sed -i 's|http://certification.cornell.edu/\?|https://certification.cornell.edu/|g'

Update: I’ve created a shell script to make this easier:

steve@oracledev:~/depot/mainline/common/scripts/bin$ ./bulk_update_urls.sh
Usage: ./bulk_update_urls.sh http://original.url.net/ http://new.url.net/ /path/to/target/dir

steve@oracledev:~/depot/mainline/common/scripts/bin$ ./bulk_update_urls.sh http://www.payments.cornell.edu/Travel_Forms.cfm http://www.dfa.cornell.edu/dfa/payments/essentials/advances/index.cfm ~/depot/mainline/websw/intraroot/

//depot/mainline/websw/intraroot/howdoi/mngcourse/host.html#3 - opened for edit
//depot/mainline/websw/intraroot/howdoi/travel/cashProcedures.html#1 - opened for edit
//depot/mainline/websw/intraroot/howdoi/travel/tranform.html#3 - opened for edit
//depot/mainline/websw/intraroot/howdoi/travel.html#14 - opened for edit

Oracle constraint: how to ensure that a column value can only accept lowercase entries

November 25th, 2008

alter table schema_name.table_name add constraint constraint_name check (field_name = lower(field_name));

Purge /* oracle sql */

November 25th, 2008

The drop table command moves a table into the recycle bin unless purge is also specified.
SQL> drop table schema_name.table_name purge;

Caution:

You cannot roll back a PURGE statement, nor can you recover an object after it is purged.

More details about purge can be found at:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9018.htm

P4WSAD: The Perforce Plug-in for Eclipse

November 17th, 2008

P4WSAD, the Perforce plugin for Eclipse enables you to access Perforce from within the Eclipse IDE.
Perforce Perspective has almost all the same features as P4 Client:

  • P4 Depots
  • P4 Jobs
  • P4 Log Console
  • P4 Pending Changelists
  • P4 Revision Control
  • P4 Submitted Changelists

Installation notes can be found at:
http://www.perforce.com/perforce/products/p4wsad.html

Release notes can be found at:
http://www.perforce.com/perforce/doc.081/user/p4wsadnotes.txt

p4 where

November 14th, 2008

When you’re setting up your workspace view in Perforce it can be confusing to figure out how to map directories in the depot to particular directories in your local filesystem. I just noticed the ‘p4 where’ command which looks like it could help with this by showing the predicted location of a given file in the client view and filesystem:

$ p4 where //depot/mainline/path/to/index.html
//depot/mainline/path/to/index.html //sha-skh2-webphp5/depot/mainline/path/to/index.html /home/skh2/depot/mainline/path/to/index.html