Monday, January 12, 2009

Recursing through Directories in Ruby

I was trying to print the directories and files recursively, this task was daunting, for me, in Ruby, as I am from Java. I was trying to do the same way that the way we do it in Java. During this course of time, I tried in several ways. Now, the way I implemented is different, Ruby way.

Here our task is to print only the files and its size. In ruby, the code is as follows.

require 'FileUtils'
class DirectoryProbe
def self.print_all_files filename
if File.directory?(filename)
Dir.chdir(filename)
files = Dir['**/*']
files.each{ |file|
unless File.directory?(file)
puts "#{file} \t #{File.size(file)} bytes"
end
}
end
end
end


Dir.chdir(file) issues a command cd in windows and linux. The code Dir['**/*'] returns the array containing all the files in the directory recursively. After that I work on each file separately.

Wednesday, January 7, 2009

Decorating Your Mac OS X

Are you new to Leopard, then this post is for you, now read on...

In Thoughtworks, I was given MacBook Pro just few weeks back. I always heard that MacBooks are great. But I was really skeptic about it. I had questions like when Apple can do it why not Ubuntu or Microsoft guys. So this post is about how my MacBooks is and few must-know shortcuts for MacBook.

Though I have experience working with Ubuntu, I cannot actually say Ubuntu is best after working with MacBook. It is not an underestimating statement about Ubuntu. Ubuntu very well provides the animation capabilities exactly similar to MacBooks. The reason is that Ubuntu lacks several things naturally like rendering of windows, fonts etc. The color it has chosen for windows looks so gloomy. In psychological terms, the brownish color brings you a nice sleep even if you are very much awake. Here Microsoft windows wins to its extent. So let's request Canonical to bring Ubuntu with the color that is very pleasing to our brains. We should be already thankful to Canonical for its effort to bring Ubuntu as a delightful Linux distribution, and the best choice of operating system next to Mac OS X.

As you are a beginner, let's decorate our MacBook with the following applciations.
Firefox - World's best browser with extensions of your choice.
QuickSilver - It is like SpotLight, once you use it, You will never uninstall it, this application is quite great.
Folx - The only good download manager with resume support, though still in beta.
Real Player - The one of the good players apart from ITunes and QuickTime. It comes with media download manager, which automatically provides great integration with Firefox. So you don't have to install any special download manager extension for Firefox. Whenever you encounter an media file in the page like youtube site for example, it automatically notifies whether you wanna download that file. So it is fantastic applicaiton.
Vienna - It is the best open source RSS application
Adium - The best internet messenger for Mac, it support yahoo, gtalk etc.
VLC - The unbeatably best media player on the earth.

If you are a programmer, you might prefer to install the following applications too
Smultron - good html editor.
TextMate - The best mac Editor for almost all the languages.
Eclipse - All in all better and open source programming IDE.
Netbeans - The best dynamic languages IDE.
VirtualBox - the platform agnostic open source virtual player from Sun Microsystems. Install this, if you prefer to install Windows or Linux in your Mac Machine.

These are some of the reguarly and very frequently used shortcuts in Mac

show the desktop - F11
Show the dashboard - F12
Force Quit - Command + Option + Escape
Logout - shift + command + Q
Logout immediately - Option + shift + command + Q
Minimize Window - Command + M
Minimize all Windows - Option + Command + M
Inverse the color - Control + Option + Command + 8
Hide the Dock - Option + Command + D
Move the File - Command + Drag
Screenshot - Command + Shift + 3
Shutdown Dialog Box - Control + Eject
Restart the Machine - Control + Command + Eject
Sleep - Option + Command + Eject

Tuesday, December 9, 2008

Intellij - Ubuntu Does this combination work?

Hey Ya, It works.

The most intelligent Java IDE on earth is definitely Intellij Idea. I was in a plan of migrating to Ubuntu because of the nature of Ubuntu. It looks great, perfect fit for me as I knew a bit of linux administration with its forefathers (Debian). It is quite faster too than its competitor Windows(Maharaj), Will talk about why Ubuntu later on in a different post.

As a programmer, I faced lots of difficulties in Ubuntu. My immediate need was to have a perfect editor to fit my bill. Then I installed Jedit. Though Gedit is good enough, as I wanted to lots of functionalities, i went with it.

When I installed Intellij Idea in Ubuntu it looked terrible. If you are not concerned about working in Ubuntu, that would be the day you will work last on Intellij Idea in Ubuntu.

So here is mentioned what you have to make it look great.
Under IDE Settings select the Look and Feel of Intellij, Choose Nimbus, it is the open source and modern theme developed for Java. So Now IDE looks great.
Then we have to tweak fonts that appear over Intellij. Now go to appearance under Editor, select checkbox for using anti-aliasing effect. Now the fonts look good to certain extent.
For making things look great issue the following command in the terminal

sudo apt-get install ttf-liberation

Now this will install liberation fonts. If you wanna check how liberation fonts looks like follow this link Liberation Fonts

You may want to install microsoft specific fonts in Ubuntu, for that, issue the following command,

sudo apt-get install msttcorefonts

You may set Arial 12 for the IDE appearance.

Once you install this font, restart your IDE. During restarting, Intellij essentially reloads the fonts installed in your system. Now Settings --> Editor --> Colors & Fonts ---> Fonts
Now select Liberation Mono and the size is 13 and spacing is 1.5.

Now it looks awesome. Isn't it?

Tuesday, July 1, 2008

Surprise GWT Visit

Guys,

This post is about my encounter with GWT (Google Web Toolkit). It is really a wonderful product from Google from the developer's perspective.

The benefit as a developer what I can say is, it provides you a way to debug in the hosted mode in the way we do debugging in Eclipse. You don't have to worry about getting into javascript hassles. Everything you can do right from Java IDE. Again for the modification to reflect, you just need to refresh the browser that GWT came with. If you would like to run your GWT application from weblogic server or any other server, you can always use the option -noserver in the shell. If you are bit familiar with the way that Swing works, you can become a great programmer with GWT. I don't find it appropriate to develop GUI with GWT, rather than going with creating HTML and adding javascript on top of that. My question is that why would Google try to challenge the way we write the web pages now. Even for the simple change in GUI we may have to look forward to changing the Java file and compile it. I guess this might be appropriate for developing the simple and small application. Though I agree that you can develop the HTML and on top of it you can plug in GWT apps in certain tags. I found it not welcomeable.

When you integrate GWT with frameworks like Spring etc, you need to make some more effort. In this time you need to seek the help from utilities like GWT-SL and GWT-WL. But this time you will be losing the facility provided by Hosted mode that GWT boasts of, especially debugging. Though it can be enabled using proprietary servers like Weblogic, Websphere, etc. I tend to think of tomcat server, which is my favorite, I will tell you why too.

One of the hassles that GWT gave, when i was trying out is that my page had had two gwt placeholders, one of which contained main app, and another one small placeholder where I had planned to show a PopupPanel. when I integrated both of these panels, I couldn't show popup panels as expected. But when I had added only one panel to my page, it showed brilliantly. The cause is that it was not firing events for button clicks and so on. And in the DiaglogBox of GWT, you can have only one panel, even though you can make it that way. Anyways I was not impressed much with the GUI styles provided by GWT. For the sake of it, I tried to use ExtJS for GWT. It was highly impressive. It addressed all of my issues very well. But, when I started using it, I realized that though it was an open source library, it had a dubious license, meaning that when you develop applications using GWT - Ext Js, you should keep your complete code of your application open sourced. For my home work, it sufficed, but I couldn't recommend for my clients to use it due to its policies.

So at last, for my project with my client, I ended up recommending Dojo with DWR (Direct web Remoting) . I find this combination appropriate. The reason is that Dojo addresses all the GUI related functionalities. DWR addressed the functionalities like serialization and deserialization of java objects into javascript.

I initially recommended Open Laszlo for our work as it is sufficient to address almost we can imagine, I couldn't recollect why it was rejected. If you see the functionality provided by Open Laszlo, it gives two stark options, one is that it converts the complete GUI as Dynamic javascript and if your browser has Flash plugin installed( I don't think somebody wouldn't have), it will show your application as flash based application, which I consider as appropriate for most of the possible situtations. On top of Open Laszlo, you have lots of add ons too.

We ignored most of the proprietary RIA tools because our client was not inclined to use any proprietary technologies. I prefer the same too.

So what is next? I have to burn my hands in Dojo and its internals and DWR and its internals. My project is going to start in a week, I need to prepare myself for it.

See you soon once again with some more nice information.

Monday, May 26, 2008

Interview programming challenge 5#

This post gives you answer for the question posted at

http://www.dev102.com/2008/05/26/a-programming-job-interview-challenge-5-records-sorting/

You are asked to sort a collection of records. The records are stored in a file on the disk, and the size of the file is much bigger than available memory you can work with. Assume a record size is 10 bytes and file size is 1GB. you read and write data to/from disk in units of pages where each page is 1KB big. You have few (less than 10) available pages of physical memory. Assume you are given a method to compare two records.

How can you sort the records under the described conditions?

* Hint - Using the virtual memory is not the correct answer.


The appropriate solution for this problem would be to use algorithm based on Insertion Sort



Interview programming challenge 4#

This current post give the solution for a problem given in the following URL,

http://www.dev102.com/2008/05/19/a-programming-job-interview-challenge-4/

How would you implement the following method: Foo(7) = 17 and Foo(17) = 7. Any other input to that method is not defined so you can return anything you want. Just follow those rules:

  • Conditional statements (if, switch, …) are not allowed.
  • Usage of containers (hash tables, arrays, …) are not allowed.
The solution for this question would be as following, the following code is written in java

public int Foo(int x){
return 22^x;
}

Tuesday, May 20, 2008

Buggy Firefox 3.0

There is no question about which is the best browser on the earth, it is obviously, as you know Firefox, at least in the developer point of view. There is no question again about other browser like Opera and Safari, they do better too. It just depends on user's preferences. Here I intentionally left out Internet Explorer. It hurts me a lot daily. Whenever I have to open a link in Outlook 2003, when I click on it, always Internet Explorer tends to pop up, which I really hate.

When Firefox 1.5 was released, I was so excited to see some browser out there to help overcome some grievances that Internet Explorer brought. That was the time, Firefox was the best browser. My happy browsing days started. I recommended all my friends and colleagues to use Firefox browser. My friends who are developers really started liking the way the Firefox behaved. My friends who are not computer literates didn't like the Firefox, the reason is this, they got very much used to Internet Explorer. Anyways, they've got used to Firefox now. It was a kinda sense of achievement that I could influence whole of my developer community to use Firefox browser, including .Net Professionals. :)

Then Firefox 2.0 was released. It introduced few new features, It came with bugs too. None of my friends really liked Firefox 2.0. The reason could be that it brought in few new features, usability was not that great. It was sluggish too. I had to use lot many add-ons to enjoy browsing. There came a sad new that Mozilla is going drop the support for Firefox 1.5. Then all of my colleagues were forced to move to Firefox 2.0.

After few weeks, Mozilla announced Firefox 3.0, it included lot many changes in the browser. Most of them were user friendly features. I was so excited to introduce my friends about Firefox 3.0, There are excited about it too. Now almost all of my friends are using Firefox 3.0. Furthermore Firefox 3.0 boasts to be a fastest browser available on earth. It is 70% faster than the previous version. It uses little memory footprint too. I guess Firefox has sticked to its basics.

Since the introduction of beta version of Firefox 3.0, it seems to be targetting much on Windows Vista while ignoring Windows XP, (Here I am ignoring other than Windows platforms). So many features that work on my vista lappy :), doesn't work on my office windows XP desktop. For example, if I have more than one tabs open, and if I close the browser, it just closes silently in XP desktop. But in vista, it gives options like save and quit, etc. Since the delivery of Firefox 3.0 RC1, it is supposed to make Firefox a default browser too, if you click on an option to make it a default browser.

Here are my questions,

1. Has Microsoft signed a deal with Mozilla corporation to make better browser for Windows Vista, Considering the fans of Firefox 3.0, like the way Mozilla signed a $55 million deal with Google for making it a default search provider?

2. How much Google paid Apple for making Google default search provider?

3. Is Mozilla on the way to endorsing the Vista for Firefox fans?

I am looking forward to answers from you...