Wednesday, February 27, 2008

Ignoring files in subversion

Two lessons for today
  1. How to ignore files in subversion
  2. How to create a transcript
1. How to ignore files in subversion
To ignore a directory: svn propedit svn:ignore
The above command will open an editor, add the directory you want to ignore in the editor and exit from the editor. Note that the directory you are trying to ignore is not added to the repository or else it won't work.
To ignore a file: svn propedit svn:ignore
Again in the editor, add the files you want to ignore and exit. You can even use wildcards when you enter the file names. Ex: '*' to ignore all the files in the directory.

I have shown a method to ignore files using propedit. The same can be done using propset also. Details are here and here.

2. How to create a transcript

You will most probably be asked for a transcript while you are asking for help on IRC channels. Transcript is a copy of the text printed on the terminal. Whatever you have typed and whatever has been printed to the terminal by the commands that you executed.

The simplest way to create a transcript in Linux is to run the script command. After running the script command, run/type whatever commands you want to and when done, type 'exit' to stop the script. A file with the name typescript is created which will have the transcript of whatever you have done on the terminal.

Tuesday, February 19, 2008

Use your GPRS phone as modem in Ubuntu

'Bunch of me: Linux Redux: Use your GPRS phone as modem in Ubuntu tells how to do it.

Configuring Bluetooth on Ubuntu

This article on LinuxQuestions.org explains clearly how to configure bluetooth on Ubuntu to send/receive files to/from bluetooth devices and also how to set up bluetooth keyboard and mouse.

Few useful linux commands

- To see how long your machine has been running
$ uptime
- To see some computer stats
$ lspci
- To see system temperature and battery charge
$ acpi -t
- To see a list of all running processes
$ ps aux
- To view the current date, time and year
$ date
- For a simple calendar
$ cal
- To see what programs are running with path names
$ ps -aux
- To see your current IP address
$ ifconfig -a
- To see what your system is doing at startup
$ dmesg
- To see information about the computer users
$ finger -l

More commands later...

Thursday, February 14, 2008

Social Graph API

Social Graph API is something to check out. Here is a blog from Google Code Blog. I haven't checked it out yet but plan to do so soon. I hope it does what it claims to do and does that well.

If you are wondering what this API does, here is a snippet from Google's blog entry.

we crawl the Web to find publicly declared relationships between people's accounts, just like Google crawls the Web for links between pages. But instead of returning links to HTML documents, the API returns JSON data structures representing the social relationships we discovered from all the XFN and FOAF. When a user signs up for your app, you can use the API to remind them who they've said they're friends with on other sites and ask them if they want to be friends on your new site.

Wednesday, February 13, 2008

Social application for Orkut

I have checked out Open Social, a common set of APIs which can be used to build social applications that work across multiple websites. I think it is really cool and at the same time not so good.

I think it is cool because, there will be a lot of applications that will be created for Orkut now, just like those you find on Facebook. But at the same time, the saddest part is that there will be many useless applications which will clutter the site and confuse everybody.

Google has announced that Open Social applications will be available to users now. So, gear up and be ready to see it on your Orkut login sometime soon. Earlier, these were available only in the sandbox.

Well, I am looking forward for an application which could allow you to tag and share photos from your friends' albums. I really like few photos from my friend's photo album and would like to tag them so that I can easily see them when I want and also would like to allow our common friends to see what I have tagged. Hoping to see if something similar would be available.

Grand Challenges for Engineering

National Academy of Engineering has a special site where in it will publish the grand challenges for engineering for the 21st century. The committee members are selected from varied fields. I am really looking forward to see what the grand challenges will be.

The challenges identified will be published to the website on 15th Feb, so don't forget to check them out.

Saturday, February 09, 2008

Accessing ext2 or ext3 file systems on windows

Ext2 or Ext3 file systems are commonly used by the Linux operating system. Support for these file systems is not by default built in to windows operating systems.

I remember trying to access windows file systems (FAT and NTFS) from linux and linux file systems (ext2 and ext3) from windows while I was in college. Back then, there wasn't a stable driver for NTFS on linux. Drivers could read from NTFS partitions but weren't stable enought for writing to it. But now, there are drivers that can read/write to both FAT/NTFS and are pretty stable. And you can find these drivers included in linux distributions by default.

I was surprised to see the windows drives mounted automatically on ubuntu and delighted to find out that I could write to those drives. This solved half my problems of sharing data between my two operating systems - windows vista and ubuntu linux. I was further delighted after seeing the search results for "accessing ext3 from windows". I found three results useful. The first one was for Explore2fs - a GUI tool for accessing ext2/ext3 file systems from windows. I had already used this while I was in college and know it's limitations. Windows programs cannot access those file systems, and files had to be copied to a windows drive to be accessed from programs. The other two results (Ext2 file system drivers) were of much interest to me this time. I chose Stephan Schreiber's implementation and installed it on vista. This implementation comes with an installer. Can be uninstalled from Add/Remove programs. Provides the ability to mount the file systems in read only mode along with support for large files (files larger than 2GB). My linux partition was mounted as a new drive and I could access it from all windows programs just as other windows drives. Now, I no longer have to worry about where to put my data so that it can be easily accessed from both the operating systems.

FYI, the ext2 file system driver I didn't mention above was Ext2Fsd, an open source project available on sourgeforge.

Thursday, February 07, 2008

Customizing search in Windows XP to index files with unknown file extensions

First of all, why would you want to customize search in Windows XP to index files with unknown file extensions?

Assume you have a java file (a file with a .java extension) and when you perform a search, text in this file is not searched. Why? Because it is an unknown file extension for Windows XP and it will not index this file. I know it is a plain text file and should be searched but it is not.

Perform the following to enable windows to index files with unknown extensions
  1. Goto Start -> Search -> Change preferences
  2. Click on With Indexing Service (for faster local searches) or Without Indexing Service.
  3. Select Yes, enable Indexing Service. It might already be selected if it was Without Indexing Service in the previous step.
  4. Click on Change Indexing Service settings (Advanced).
  5. In the Indexing service window goto view menu and click on customize.
  6. In the Customize View window check Console tree check box under the MMC section and click on ok.
  7. Right click on Indexing Service on Local Machine and select properties.
  8. On the generation tab, check Index files with unknown extensions check box and click on ok.
  9. Close the Indexing Service window and click on ok in the search window.
  10. Click on All files and folders and start searching. It will find any word in any file with any extension.

Wednesday, February 06, 2008

Responding to DOM Events using Javascript

Responding to events occurring on a web page using javascript is a necessity these days rather than a preference. Look at the various popular websites today and you will realize that. So, I set out to explore this a little and the following is what I have learned for the first phase, if you want to say so.

A simple example of an event that can occur on a web page is a mousemove event that occurs when the mouse is moved. Events can be organized into three major categories -
  1. UI events - generated by user interaction through an external device (mouse, keyboard, etc.)
  2. UI Logical events - device independent user interface events such as focus change messages or element triggering notifications.
  3. Mutation events - caused by any action which modifies the structure of the document.

Event Propagation

Let us look at the event flow before we jump into the details of event listener registration.

Once an event originates, it is passed through the Document Object Model in three phases -
  1. The capturing phase - the event is first sent to the window, then to the document, followed by each ancestor of the DOM element where the event occurred downwards until it reaches that element.
  2. The target phase - the event is sent to the target DOM element. Target element is the one on which the event has occurred. For example, the target element for a click event is the element which is clicked.
  3. The bubbling phase - the event is sent to each element back upwards until it reaches the window again.
The below image shows how the event is propagated through the three phases. Let us assume that a mouse click event has occurred on the table element. Shaded elements show the order in which the event is propagated. The propagation of the event will start with the capturing phase. Any event listener registered on the window will be called to handle the event followed by document, html, body and so on until the parent of the target element is reached. The target element in this case is the table. This ends the capturing phase after which the target phase starts. In this phase, any click event listener registered on the table element will be called. In the bubbling phase, the event propagates back to the top calling any event listeners registered for the mouse click event.


An event listener being registered on an element may choose to have that listener capture events by specifying the useCapture parameter of the addEventListener method to be true.

Any event handler may choose to prevent further event propagation by calling the stopPropagation method of the event object. If any event listener calls this method, all additional listeners on the current element will be triggered but bubbling will cease at that level. Only one call to stopPropagation is required to prevent further bubbling.

Some events are cancelable. These events have a default action associated with them. An example of this is a hyperlink in a web browser. When the user clicks on the hyperlink the default action is generally to activate that hyperlink. Event listeners have the option of canceling the implementation's default action or allowing the default action to proceed. Cancellation is accomplished by calling the event object's preventDefault method. If one or more event listeners call preventDefault during any phase of event flow the default action will be canceled.


Registering Event Listeners

There are two ways to attach an event listener to an element. First, by using an attribute with script as its value. Second, by calling an element's addEventListener method. The former may only handle bubbling events but tends to be simpler to write. The latter can handle events at any phase and may also be used to attach multiple listeners for an event to an element.

Attribute Event Listeners

To use the attribute form, place an attribute on the element where you want the event listener to be, the name of which should be the event name preceded by the word 'on'. For example, the corresponding attribute for the 'click' event is 'onclick'. The value of the attribute should be some script that should be executed when the event occurs. Typically, this code will be short and just call a function defined in a separate script. An example of responding to a button being pressed:

<input type="button" label="OK" onclick="alert('Button was pressed!');" />

Since the click event will bubble, it is also possible to place the event listener on an enclosing element. In the example below, the listener has been placed on a div and will receive events for both elements.

<div onclick="alert(event.target.tagName);">
<input type="button" label="OK" />
<p>This is a paragraph</p>
</div>

In this example, the click event will bubble up from the button or paragraph to the div, where it is handled. If a second listener (the onclick attribute) were placed on the button, its code will be called first, followed by the handler on the div. Event handlers are passed the event object as an implied argument called 'event'. This is used to get specific information about the event. One commonly used property is the 'target' property of the event, which holds the element where the event actually occured. In the example we display an alert containing the target's tag name. The target is useful when using a bubbling event so that you could have a set of buttons which are all handled by a single script.


DOM Event Listeners

The second way to add an event handler is to call an element's addEventListener method. This allows you to attach an event listener dynamically and listen for events during the capturing phase. The syntax is as follows:

<input type="button" id="okbutton" label="OK"/>
<script>
function buttonPressed(event){
alert('Button was pressed!');
}
var button = document.getElementById("okbutton");
button.addEventListener('click', buttonPressed, true);
</script>


The getElementById() function returns the element with a given id, in this case the button. The addEventListener() function is called to add a new capturing event listener. The first argument is the name of the event to listen to. The second argument is the event listener function which will be called when the event occurs. Finally, the last argument should be true for capturing listeners. You can also listen during the bubbling phase by setting the last argument to false. The event listener function passed as the second argument should take one argument, the event object, as shown in the declaration for the buttonPressed function above.

Note: addEventListener will not work with Internet Explorer, you need to use attachEvent instead.


References:

Registering event handlers section is taken from XUL tutorial mentioned as the second reference above.

Monday, February 04, 2008

How to Debug PHP with Vim and XDebug on Linux

XDebug is definitely a wonderful tool for debugging PHP. I tried using Eclipse IDE for remote debugging but it had some version conflicts and so I searched for some other IDE but I didn't imagine that Vim will turn out to be the one.

This Box.net blog tells you how to do debug PHP with Vim and XDebug on Linux.