Pages

Wednesday, August 17, 2011

Ruby GUI and FXRuby Installation

Why about GUI and FXRuby all of a sudden?

Its a tremendous movement we made from desktop to web 2.0 apps and again back to native desktop apps(iphone/ipad) Seesmic/Tweetdeck apps broadly classifying as RIA.

Hence my long time dream, has been pondering about throwing the silver cup of Java swing and bringing platinum Ruby stones in GUI front, finding space in replacing existing legacy Java swing applications with a neat Ruby GUI like TK-Ruby.

To my horror, nothing has been honored in Ruby world apart from Rails and geeks see Ruby as a Web DSL and where as rails has made routes.rb itself a DSL.

I forayed to figure out any Ruby GUI library in par with AIR/Silverlight, but my search collaboration with mountain view only ended up in disparity.

Finally ended up in installing FXRuby to see fortune in it, written a small GUI ruby program as below,


require 'rubygems'
require 'fox16'
include Fox


application = FXApp.new("CompositeGUI", "CompositeGUI")
main_window = FXMainWindow.new(application, "Composite",nil, nil, DECOR_ALL)
main_window.width = 400
main_window.height = 200


#Vertical Frame
super_frame = FXVerticalFrame.new(main_window,LAYOUT_FILL_X|LAYOUT_FILL_Y)
FXLabel.new(super_frame, "Text Editor Application")


#Horizontal Frame
text_editor = FXHorizontalFrame.new(super_frame,LAYOUT_FILL_X|LAYOUT_FILL_Y)
text = FXText.new(text_editor, nil, 0,TEXT_READONLY|TEXT_WORDWRAP|LAYOUT_FILL_X|LAYOUT_FILL_Y)
text.text = "This is some text."


# Button bar along the bottom
button_frame = FXVerticalFrame.new(text_editor,LAYOUT_SIDE_RIGHT|LAYOUT_FILL_Y)
FXButton.new(button_frame, "Cut")
FXButton.new(button_frame, "Copy")
FXButton.new(button_frame, "Paste")


#create FX application and run
application.create
main_window.show(PLACEMENT_SCREEN)
application.run 


and when I ran, landed with the below error message,

LoadError: no such file to load -- fox16.so from line no 2 require 'fox16'
I installed fxruby-1.6.20-x86-linux.gem and wondering any fox library kit need to be installed in my system and searched in my ubuntu for fox library dependency but left with no clue.
Then I uninstalled and downloaded fxruby-1.6.20.gem and installed. Native extensions were built, then I could ran my fxruby program with ease,



Though not appealing, enough qualified to place it beside AIR or Silverlight GUI, this could be the half brother of Java Swing.

For enterprise Java swing applications and migrating it ruby I saw this article, 
Don't know practically how far this works








Tuesday, June 21, 2011

Ruby Modules: A perfect name space resolver?

Coming from java background, I was looking for package equivalent in Ruby and read in Programming Ruby 1.9 book that Ruby Module serves two purposes, 1) Namespace conflict resolver 2) Mixin Though, mixin is applauded one, now the one that bothers me is Namespace conflict resolver. lemme idealize it in to a simple example
module A

def test
  puts "I am in module A"
end

end

module B

def test
  puts "I am in module B"
end

end

Class Payment

include A
include B

end

p = Payment.new

p.test #prints - I am in module A

Now how to invoke test method in module B? But the same if I rewrite the those module methods as a class level methods, this works
module A

def self.test
  puts "I am in module A"
end

end

module B

def self.test
  puts "I am in module B"
end

end

Class Payment

include A
include B

def test_modules
  A.test
  B.test
end

end

p = Payment.new

p.test_modules #prints fine - I am in module A, I am in module B

when I do,
p.A.test #bangs - `
': undefined method `A' for # (NoMethodError)
What is this actually? I couldn't understand the concept, Is someone who could help me on this? Is Ruby a perfect namespace conflict resolver?

P.S - I got to know clear about this by watching this video MetaProgramming for Fun by Dave Thomas

Wednesday, March 2, 2011

Ruby Floating floats like a Dead Fish

I was so serious in attempting to solve a problem that Thoughtworks usually gives to its new recruits to test their Object Orientation skills. In that there is a Sales Tax problem which involves lot of math library, floating point calculations rather than using our brain memory in it.

While when I do the rounding of a sales tax calculation to the nearest 0.05, I faced the problem in my ruby
                                               
Though I agree that this is my first time where I am doing intense floating point calculations and round off, could someone explain me why this inconsistency happens with ruby?

I need at least two decimal places right in my calculations, rather than implementing a work around to round off a 8 decimal float number .


Also it should be noted that round(n) as written in Float class in ruby, which rounds to 'n' decimal places doesn't work with Jruby. Any clue on this???

Sunday, December 26, 2010

How to run PHP files inside public_html directory in Ubuntu 10.10 a.k.a Maverick Meerkat

By default, php files doesnt gets interpreted when placed inside public_html in Ubuntu 10.10. ie in Maverick Meerkat.

When you install php5 in ubuntu 10.10 or 10.04, planning to place your php files inside public_html directory in your user area, here is the solution for you.

Create public_html in your user area


First of all check whether enable-modules under your apache server
for that
goto /etc/apache2/mods-enabled/ folder and check userdir.conf, userdir.load modules are enabled by simply typing ls command

if not then goto /etc/apache2/mods-enabled and create symbolic link as follow


sudo ln -s ../mods-available/userdir.load

sudo ln -s ../mods-available/userdir.conf


or you can enable using the following command

sudo a2enmod userdir



Finally create public_html folder under your home directory an give full access permission to it.

Restart your apache server (sudo /etc/init.d/apache2 restart or service apache2 force-reload)

Access it through following link.

http://localhost/~[your_home_directory_name]/ (for me it's http://localhost/~hariharank12/)


To run PHP files inside public_html in Ubuntu 10.10

In the new php.conf file which is present in /etc/apache2/mods-available/php5.conf, the php engine inside user directory is turned off as like below.



 
 php_admin_value engine Off
 
 


Comment those above lines.

Finally php5.conf will look like below.


    
        SetHandler application/x-httpd-php
    
    
        SetHandler application/x-httpd-php-source
    
    # To re-enable php in user directories comment the following lines
    # (from  to .) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
#    
#        
#            php_admin_value engine Off
#        
#    
#


Again restart the apache web server.


Test with some php files placing inside public_html folder and hitting URL with localhost/~username/php_file_name.

It should work now! :)

For more detailed description why php files running inside public_html is disabled, see the following link

Chmsee instead of Gnochm in Ubuntu 10.10

If you are wondering, how to open chm files in Ubuntu 10.10, here is a solution for you.

Gnochm has been removed from the repository, and instead replaced by chmsee.

chmsee has the following features.

A chm file viewer written in GTK+

- Uses gecko rendering engine
- Bookmarks
- Support to open multiple files at once

one difference I feel is you cannot search in chmsee application.


Simply you can install chmsee like

apt-get install chmsee

Wednesday, May 26, 2010

Ruby Cerification Exams and Rails Certifications

If a person wants to take Ruby Certifications and searches in google, he is fruitfully landed in to pages of irrelevancy, because the ruby central organization hasn't leaned to give certification exams to developers and architects.

Why we need certification first?

The certification exams will solve the following purposes

- Developers will have the deep understanding of the language, what it can afford, what it can address, how it can make job easier.

- Popularity of the language, by ads and bringing attention to the enterprises.

- Income to the open source world, where they can have budget for innovation

- With Certified Engineers and Architects, We can start making proposals to enterprises where they fond of using Spring and Hibernate like Verizon and Bank of America, making them to feel the power of Ruby language, convincing them that we have enough resources and architects to deliver projects in Ruby Language.

Then why not Ruby central can come forward in offering Certification Exams and create a better developers in the Ruby world?

Dynamic Nature of Ruby - Part 1

This is something a post after a long break, still something that ponders me is the level of penetration of open source in enterprises.

This post is fairly for the new bees who are chain smokers of Java Cigarettes and now want to change their brand and experience a new feel, and less harm to their body in terms of strain. Also at later stage wish to cover the enterprise ruby.

To begin with, definitely one should accept that famous of python was revealed only by the search giant google through its products like gmail,youtube, and google search etc.

In late 2000 dynamic languages sprouted and PHP were more dominant in web languages, even though Yahoo uses PHP extensively, but for enterprises PHP is still treated as a KM languages or developing a mere KM applications.

A popular framework called Rails which evolved with a new stratum such as Convention Over Configuration and DRY principles striked the chord in and around 2005 and this was made possible by a powerful Dynamic Language called 'Ruby'


Thoughworks is a company usually called king of Agile, which uses Ruby predominantly in their works as well as do enterprise proposals based on Ruby language.

Ruby Language Symbol

Ruby is a dynamic, Object oriented programming language that is influenced by the right mixture of Python, Small Talk, Perl, Lisp

Is Ruby a scripting language? No, more than a scripting language.

Its object Oriented by nature.

For instance, even if you declare a variable i =10, the variable 'i' is an object of type fixnum.

Suppose you want to perform a Modulus operation for the variable i = -10, in a typical static languages like java, it will make a light year waste for you in importing and declaring the essential classes and sub classes.

Yes in Java you need to import Math class to perform this and call abs fn from the Math Class like this

Math.abs(i)

Even if you feel that you want to save time in importing classes and decided to go for IDE like eclipse, it will take hell lot of time to load in windows and hang around, where installing these IDE's are always less preferenced in linux.

Whereas in Ruby, its pretty simple that even simple guesses from our mindset will work to find a clue,

Here is the solution in Ruby,
irb>>i.abs #prints 10, mod value of i

if you ask me how a variable can have a member function, in Ruby its not a variable, its a object of class type 'fixnum'

Each and everything as an object makes ruby to create wonders.

Even more ruby has interesting features ....TBC part 2