ORA-03113: end-of-file on communication channel

One of the lesser used features in an application using Oracle Database installed on a UNIX server stopped working recently throwing the ORA-03113 error. The oerr utility provided the following information:

$ oerr ora 3113

ORA-03113: end-of-file on communication channel

Cause: The connection between Client and Server process was broken.

Action: There was a communication error that requires further investigation.

This meant that one of these most probable things had happened:

  • The network connection was lost
  • The server process had crashed

(Note that ORA-03113 is a generic error and there are over 1000 bugs related to it on Oracle Support!)

First possibility was quickly eliminated as the error wasn’t encountered just once or twice which might happen due to that rare, momentary glitch in network connectivity. But it did happen every single time that particular feature was used.

This meant that something in the function invoked, when the feature in question was run, was causing the server process to die. Running through the code using a test script led to the point of failure.

A simple dynamic SQL query was being executed without event.

-- The following query is being used multiple times later on
v_sqlstr := 'SELECT column1, column2, SUM( column_qty ) AS proposed_qty
             FROM a_global_temporary_table	-- or any table
             WHERE column1 = ' || column1_value ||
             ' GROUP BY column1, column2' ||
             ' ORDER BY MOD( SUM( column_qty ) )';

-- Count the number of rows returned by the "ordered" query above
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM (' || v_sqlstr || ')' INTO v_count;

But why?

Playing around with bits and pieces of the query stored in v_sqlstr led to the finding that when trying to get COUNT(*) using v_sqlstr as the source, including the MOD() in the ORDER BY clause of the query was causing the server process to crash. Weird!

To fix the issue, and because you don’t need an ordered result set to take a count, I removed the ORDER BY clause from the original query and appended it back only after taking the count, as shown below:

-- The following query is being used multiple times
v_sqlstr := 'SELECT column1, column2, SUM( column_qty ) AS proposed_qty
             FROM a_global_temporary_table	-- or any table
             WHERE column1 = ' || column1_value ||
             ' GROUP BY column1, column2';

-- Count the number of rows returned by the query above
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM (' || v_sqlstr || ')' INTO v_count;

-- Append the ORDER BY clause to the original query
v_sqlstr := v_sqlstr || ' ORDER BY MOD( SUM( column_qty ) )';

And things were back on track!

This is just one of the many possible causes and fixes for this error. I hope you find it useful in case you get stuck in a similar situation. Cheers!

Posted in Databases, Oracle | Tagged , | 2 Comments

Custom post type archives with WordPress Cuztom Helper

WordPress Cuztom Helper now enables custom post type archives out of the box.  In the same way that posts are shown on their own archive with archive.php, custom post types will use archive-{post_type}.php .

I decided to add this feature because one, generally, wants to be able to view all the posts of a custom post type. So if you have a custom post type named ‘Acme Products’, you can view all the products of this type by visiting example.com/acme-products/ in the browser.

In WordPress, custom post type archive pages are not enabled by default when you register a post type. If we left it like this in WordPress Cuztom Helper, one would either have to create a page template manually


/* Template Name: Custom Post Type Archive */

//somewhere in the template file 
global $query_string; 
query_posts($query_string . "post_type=YOUR-CUSTOM-POST-TYPE&post_status=publish&posts_per_page=10"); 
if ( have_posts() ) : while ( have_posts() ) : the_post();

and then create a blank page, choose the template and publish it, which is a lot of unnecessary work just to view posts of a custom post type. Or one would set

'has_archive' => true

while registering a custom post type. When has_archive is set to true, the custom post type slug is used for the archive page by default, which is a little unintuitive because acme_products/ makes more sense than acme_product/ when you want to view more than one product of Acme Product post type (it’s an archive page and not a single page).

There is an additional benefit to this i.e. saving the trouble of having to deal with slugs manually. Instead of trying to figure out slug_to_view_all_acme_products, you simply register your Acme Product post type and this will be done for you. In exceptional cases, such as for a custom post type named Music or Country Music where it makes sense to use the post type slug as archive slug, you simply set

'has_archive' => true

and your archive will be accessible at example.com/music/ or example.com/country_music

And when you want to disable the archive, simply set

'has_archive' => false

One just doesn’t have to deal with slugs unless one wants to use something drastically different. Another advantage of using archive over writing a Page Template is that one doesn’t have to create an archive-{post_type}.php page unless one is using custom taxonomies or metaboxes. Simply, the existing archive.php file be used. One also doesn’t have to use query_posts unless absolutely required.

So, from now on, custom post type archives are turned on when registering Custom Post Types with WordPress Cuztom Helper, as the default behavior. There you go. Download WordPress-Cuztom-Helper and take your custom post types to the next level with archives.

Posted in WordPress | Tagged , , , | 3 Comments

Download online course videos from Stanford Center for Professional Development

Stanford Center for Professional Development

It is particularly difficult to watch online videos on SCPD using a ‘mystanfordconnection’ account when you want to watch them at a faster speed. You might also want to refer to video tutorials when without internet access.

To address these issues, I have written a Python tool that lets you download all the videos from the Stanford courses that you’re enrolled in, while they are still available to you. All the videos can be downloaded in parallel.

Get download-scpd-videos. The instructions are for Mac OS X. For Linux or Windows, simply install the dependencies (mechanize, BeautifulSoup and mimms) using your package manager of choice, packaged binaries or building them from source.

Note: Only for educational purposes. Use with explicit permission from Stanford Connection for Professional Development and for personal and non-commercial purposes only. Use this script with good judgment, common sense, discretion, and assume full responsibility for misuse. I accept NO responsibility for your use of this tool.

Posted in Python | Tagged , , , , , | Leave a comment

Install CakePHP in a subdirectory of WordPress

Let’s say you have a WordPress installation which is accessible in the browser at example.com and you want to install CakePHP in a sub-directory (or a directory inside a sub-directory) within WordPress so that it is accessible at something like example.com/cake/ or example.com/project/cake/ in the browser.

To achieve this, you need to modify the .htaccess files used by WordPress as well as CakePHP. I’ll explain how to modify .htaccess files in the following steps.

Step 1: Modifying .htaccess file in WordPress

In the directory where WordPress is installed ( in the same folder as wp-config.php file ), edit the .htaccess file and add the following line, assuming that your CakePHP subdirectory will be called ‘cake’

RewriteRule ^cake/(.*)$ /cake/$1 [L,QSA]

so that your .htaccess file looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^cake/(.*)$ /cake/$1 [L,QSA]
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>
# END WordPress

If your ‘cake’ is going to be inside another sub-directory of WordPress installation called ‘project’, then this line should look like:

RewriteRule ^cake/(.*)$ /project/cake/$1 [L,QSA]

If you don’t do this step, visiting example.com/cake/ or example.com/project/cake/ will try to open as a WordPress page which, obviously, isn’t right and will fail.

Step 2: Modifying .htaccess files in CakePHP

After completing Step 1, you will need to add the following RewriteBase statement in the .htaccess files used by CakePHP. If you don’t complete this step, your CakePHP app will show up but fail to load CSS / JS or any other assets in /app/webroot.

RewriteBase /cake

So, first of all, navigate to /cake/ or /project/cake/ , whichever is your CakePHP folder and edit the .htaccess so that it looks like this:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /cake
 RewriteRule ^$ app/webroot/ [L]
 RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Then navigate to the ‘app’ folder inside ‘cake’ and edit the .htaccess file so that it looks like this:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /cake
 RewriteRule ^$ webroot/ [L]
 RewriteRule (.*) webroot/$1 [L]
</IfModule>

Finally, navigate to webroot folder inside this ‘app’ folder so and edit the .htaccess file so that it looks like this:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /cake
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

That’s it. You’re good to go.

Visiting example.com in the browser will open your WordPress website, while example.com/cake/ or example.com/project/cake/ , depending on how you configured it, will open your CakePHP app.

Posted in Apache, CakePHP, WordPress | Tagged , , , | 8 Comments

Fix HTTP 500 Internal Server Error on renaming CakePHP root directory

If you have to rename your CakePHP root folder for some reason, you might come across HTTP 500 Internal Server Error. This generally happens because of PHP opcode caching done by PHP accelerators for performance boosts.

The problem can usually be fixed by restarting your server. If not, you might have to clear the PHP opcode cache manually.

Clearing PHP opcode cache in XCache
Clearing PHP opcode cache in XCache

If you’re using MAMP (or MAMP Pro) on a Mac, which comes bundled with XCache, you can easily fix it by visiting XCache tab from server start page and using the clear button against the PHP cache. If you have a different PHP dev setup, check for other PHP accelerators like APC or eAccelerator.

This will fix your problem and your CakePHP app will continue to function normally after renaming the CakePHP root directory.

Posted in Apache, CakePHP, MAMP | Tagged , , | 1 Comment

Bug fix for undefined variable notice in CPT-onomies 1.1.1

CPT-onomies WordPress Plugin by Rachel Carden enables you to use your custom post types as taxonomies and create relationships between your posts by using custom post type post titles as taxonomy terms, in a similar fashion as you would create taxonomy relationships.

Since it is not yet possible to create relationships between custom post types like that with WordPress, out of the box, I am using CPT-onomies v1.1.1 for a project that I’m presently working on.

While playing around, I stumbled across a bug which introduced a debug notice in the WordPress dashboard and didn’t let me publish or update posts for those custom post types which used a cpt-onomy (custom post type as a taxonomy). I reported it to Rachel and she responded quickly with a fix.

CPT-onomies v1.1.1 bug

Until a new version of the plugin comes out with the fix, to get rid of the debug ‘Notice’, you can change line 931 of manager.php in the plugin root directory from:

'cpt_onomy_archive_slug' => ( isset( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) && !empty( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt[ 'cpt_onomy_archive_slug' ] : NULL );

to

'cpt_onomy_archive_slug' => ( isset( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) && !empty( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt_settings[ 'cpt_onomy_archive_slug' ] : NULL );

This will remove the notice and you’ll be able to publish or update posts of custom post types which use a cpt-onomy without a hassle.

Posted in Plugins, WordPress | Tagged , , , | Leave a comment

Getting Port 80 for Apache to work in MAMP or MAMP Pro

Setting Apache to use Port 80 in MAMP

Setting Apache to use Port 80 in MAMP

If you’re stuck with MAMP (or MAMP Pro) unable to use the default Apache and MySQL ports (Port 80 and Port 3306 respectively) when you change them in preferences, use the following steps to ensure that the changes you make are saved and work:

  1. Launch MAMP. Open Terminal by typing terminal into Spotlight (Command + Space).
  2. Open MAMP Preferences (Command + , ) and click on Reset MAMP Ports (Port 8888 and Port 8889 for Apache and MySQL respectively). Click on OK.
  3. Switch to the terminal. Type sudo apachectl stop to shutdown the system Apache.
  4. Restart MAMP.
  5. Open MAMP Preferences once again and click on Set to Default Apache and MySQL ports. This will set the Apache and MySQL ports to 80 and 3306 respectively.
  6. Switch to the terminal. Type sudo apachectl restart to restart Apache.
  7. Switch back to MAMP and click on Open Start Page (or go to http://localhost/MAMP/?language=English in your browser)

And you’re done.

By using Port 80 for Apache HTTP server, instead of having a URL like http://localhost:8888 you’ll have a clean URL like http://localhost

This is useful in certain cases, for example WordPress multi-site installation where you cannot create a network if “WordPress address (URL)” uses a port number other than ‘:80′, ‘:443′.

Setting preferences in MAMP usually works without a hassle but I encountered this problem, today morning. Only the default MAMP ports seemed to work, no matter what I set in the preferences. This led to a lot of wasted time and productivity. I hope this how-to guide saves you some hair and valuable time.

Posted in Apache, Mac OSX, MAMP | Tagged , , , , , , , | 15 Comments

Humanoid Robot NAO performing Sun Salutation

I had the opportunity to implement the Human Robot Interaction module on the NAO Humanoid Robot during my internship at Gade Autonomous Systems Private Limited in Hyderabad recently. As a part of it, I programmed the NAO humanoid robot to perform the Surya Namaskar, the traditional Indian practice of Sun salutation. The video is a bit shaky in the start but gets better in a few seconds. Watch it here.

The development environment used was Choreographe by Aldebaran Robotics running on Ubuntu 11.10. Python was the primary programming language used. The behavior was simulated on NAOsim powered by Cogmation Robotics running remotely on a Windows 7 machine. The development of this behavior deliberately utilized all 3 methods that enable one to integrate motion into a behavior

  1. Using the Timeline Editor
  2. Using the Recording Mode
  3. Using the Motion API (ALMotion)

Each of these methods have their own ups and downs. For example programming in the actuator position values using the Motion API gives you unparalleled precision but at the same time it is time consuming. The timeline panel or the motion editor as it maybe called lets you define frames and animations or behaviors in those frames in a snap. In the recording mode, you can manually move NAO’s body to a specific pose and record the actuator position values.

The experience in building this behavior for NAO humanoid robot gave valuable learning as to how the simulator NAOsim tightly interfaced with the development suite Choreographe and Telepathe to allow for testing behaviors in a virtual world with real physics before playing it on NAO in the real world. Development, in particular, improved the understanding of synchronous and asynchronous flows while programming using the APIs as well as using the box-based GUI.

The inspiration for building this particular behavior came from observing the locals performing their religious practices while I stayed there and ideas from my dad and (the founder) Sasi Gade’s mom.

Me, teaching Surya Namaskar to NAO Humanoid Robot

Posted in Humanoid Robot | 2 Comments

pyblobs with OpenCV 2.1 on Ubuntu 11.10

pyblobs is a Python interface for cvBlobsLib. To use it with OpenCV 2.1 on Ubuntu 11.10 follow these steps.

Prerequisites

The following dependencies are required to use pyblobs library:

sudo apt-get install swig
sudo apt-get install libcv-dev
sudo apt-get install python2.7-dev
sudo apt-get install python-opencv

If you are using Python 2.6, then use sudo apt-get install python2.6-dev instead.

Getting the pyblobs library

Use svn to grab the source code

cd /path/to/Downloads/
svn checkout http://pyblobs.googlecode.com/svn/trunk/ pyblobs-read-only

Patching the files

The code from the trunk as of now uses Python 2.5 (python2.5-dev) and not the best way to link shared objects in the make_swig_shadow.sh file. There is another issue with building the pyblobs library to be used with OpenCV 2.1 in the file BlobExtraction.cpp

Hence, I have created two patch files for the aforementioned files:

Download these to the same directory as the downloaded library (pyblobs-read-only) and then run the following commands in the terminal:

cd /path/to/Downloads/pyblobs-read-only/
patch make_swig_shadow.sh make_swig_shadow.patch
patch BlobExtraction.cpp BlobExtraction.patch

If you are using Python 2.6, then after patching edit make_swig_shadow.sh and replace any occurennces of python2.7 with python2.6 .

Installation

To install

make
./make_swig_shadow.sh

To check your install, go to your Python shell and try the following imports:

>>> from blobs.BlobResult import CBlobResult
>>> from blobs.Blob import CBlob

If all goes well, you shouldn’t see any errors. Now you can work with pyblobs and OpenCV2.1 on Ubuntu 11.10!

That said, to get the example file demo.py working, you might need to modify it a little to use objects and methods from the newer OpenCV Python API. For example, in my programs I replace

from opencv import cv
from opencv import highgui

with import cv2.cv as cv to use the new API as cv.MethodName() instead of cv.cvMethodName() or highgui.cvMethodName(). Makes life a lot easier!

Posted in Computer Vision, Python | Tagged , , | 4 Comments