Installing mysql gem in Fedora12

Posted in Ruby On Rails on January 8, 2010 by Asanga Bandara Wijekoon

When I try to install mysql gem in fedora 12 new distribution I had to faced some issues. So I think the way I figured out may help to others also to get rid this issue. First I mention what I have earlier installed in my machine.

  • ruby(1.8.6)
  • rubygems (1.3.5)
  • rails (2.3.5)
  • Mysql Server version: 5.1.41 Source distribution and client

So what I need was to configure mysql which can be used in my rails projects. To do that follow the below steps as those are listed.

  • log as root and install ruby-devel and mysql-devel. These liabraries provide lot of neccery configuration instructions needs to mysql gem.
# yum install -y ruby-devel 
# yum install -y mysql-devel
  • Then fire normal gem installing command as

# gem install -y mysql -p http://proxy_address:port — –with-mysql-config=/usr/bin/mysql_config

If u are not work under proxy you can eliminate “-p http://proxy_address:port” part.

I think this will help you for your developings.

Each firefox user with owned user profile

Posted in Thoughts on October 13, 2009 by Asanga Bandara Wijekoon

Most of the web users love to use Firefox because it is the greatest browser still present in the world. You may have faced same experience as I, which is same pc same user accont used by many users. We are going to experience clouding world and we are not depend on the Machine os. Recently Google also announced they are going to make chrome os as a web os. Though there are lot of Web Operating Systems we are not familiar with them as we do with firefox. Of course firefox is not a web os but it seems like one of that. Amazon cloud supports only on Firefox. There are lot of add-ons which make Firefox as webtop.

images

So I think its better if Firefox works as a normal webos. Then anyone who work on same user account in the same machine will not be a issue when dealing with the web. Firefox will handle all the user based settings. Users only have to log to the user account of the Firefox and customized profile will be prompt to the user by Firefox.

Commanding for War Games

Posted in Thoughts on June 24, 2009 by Asanga Bandara Wijekoon

Actually this is not my opinion and it is belongs to Mr. BLD Senavithne. He is my e-Business teacher and the thing he told us is fantastic and I think this will useful for others. I think most of you have played “General” kind of war games. Every time when we are playing, we have to move our mouse and click in thousand times. Actually what happen in real wars Rankers usually order to the soldiers. Now a days we are using voice recognitions systems in our pcs. If not computer game players do not think twice for spent little too much bit of money for buying equipments for playing games.

To give a better experience to the player game developers can make games which can command using a mike or something.

North Korean Issue

Posted in world issus on May 31, 2009 by Asanga Bandara Wijekoon

These days North Korea does lot of military based researches and some of them are nuclear ones. By the way USA and some of other European countries blamed for that. So I though to talk about this topic.

We all know UK accepts anything if its came form USA side and actually that is a shame for them. American (USA people) came form UK but they challenge UK on long time ago and finally they won the freedom form the UK. Now its seems like UK struggling to get rid from USA governing on UK and though they accepting anything told by the USA. So afterward I don’t think world should consider the what the UK saying because they only append the part of “We are with you” to the Americans decisions. By the force of this economical crisis USA was fallen and before that by the help of Tony Blear and other leaders, UK also faced the economical difficulties. Anyway USA has the ability to survival from this crisis and UK also should have a way to get rid of it. So they are try to create good relationship with the USA and get the advantages of that and it seems like other European countries are not too much worried about UK. We all know what UK did when Europeans were went to the Euro. So the reason to talk more about the USA and UK they are the main opposite parties in the North Korean issue. I have a doubt that both these countries do have the ethical right to reject the North Koreans doings. They are talking a world of peas and we all seen what they did to Iraq and Afghanistan and earlier to Vietnam.

After the World War II, Soviet Union and United State troops controlled the northern and southern halves of the country respectively by defeating the Japan. Northern part lead to a communist country and southern part lead to more open economical governing. Actually Korea is one of a best symbol which represent worlds main two governing forces. I don’t think Koreans need to live in two separated countries. It seems powerful countries made this wound and now all the Koreans had to bear this wound and they need to cure from this. Japan is the side of USA in most of the time and china and Russia are main threat for USA. So USA help as much as they can to protect South Korean government and China and Russia help for North Korea to protect communist government and by doing that they also revenging from USA.

Last week North Korea did a nuclear research under the land. They said it was succeed. Anyway South Korea has reactors and they make electricity by use of them and still North Koreans try to engage the reactors for the electricity producing. Both countries has the nuclear power. Anyway North Korea stands now on eight place in the nuclear weapons power and they has great and powerful ground army near 1,000,000. I am adding some important details comparing North and South Korean military power.

_45837223_ns_korea466x224

Based on these facts it is obvious that South Korean have the fear on North Korea. Now its seems like other countries like China also considering this issue and they  told they are not accepting the research done by the North Koreans. Anyway if USA or China can do the nuclear experiment why  North Korean can not do. One time India told that to USA as an reply when they doing the “Agni” missal experiments and USA opposed to that.

What I feel now is most of the countries try to increase their military power. Not only North Korea but also India (baying AWACAS planes), Pakistan, Israel, China ( they also going to increase the power of their navy), Iran, etc. So are they ready for the another world war?

Observer Pattern

Posted in Design Pattern with Java, C++ and Ruby on May 30, 2009 by Asanga Bandara Wijekoon

First of all I need to emphasis that any pattern does not depend on a language and actually it is a powerful concept. Programmer should have the ability to format it according to the language going to use. My first explanation is based on Observer Pattern. This pattern use to implement to one-to-many relationship. Here we have a subject object and if its state is changed it inform to all the observer objects.  Let me explain it first using Java.
In Java we have pre implemented way of this pattern but I think its better to explain how we implement this pattern on our hand with better suiting to our interest and after that I explain how to use the lava pre-implemented pattern implementation.
First we define an interface for create concrete subject class. Here I need to note that we always try to code for an interface and not use concrete classes. This is good programming practice and it helps to manage code very much and dynamic object creation. Basically this interface and concrete class is for doing the a server kind of a job by managing the observers and they are some sort of clients.

public interface Subject {
public void registerObserver(Observer o);

/* observers are the clients who were been updating when subject status were changed*/
public void removeObserver(Observer o);
public void notifyObservers();
}

Now we are defining the ConcreteSubject class.
import java.util.*;
public class ConcreateSubject implements Subject {
private ArrayList observers;
public ConcreateSubject() {
observers = new ArrayList();
}
public void registerObserver(Observer o) {
observers.add(o);
}
public void removeObserver(Observer o) {
int i = observers.indexOf(o);
if (i >= 0) {
observers.remove(i);
}
}

public void notifyObservers() {
for (int i = 0; i < observers.size(); i++) {
Observer observer = (Observer)observers.get(i);
observer.update();
}
}
}

Now we need to inform the updates to the observers. To implement that I used an interface named it as Observer. Here one to many relationship perform as one subject relate to many observers.

public interface Observer {
public void update();
}

Now we are implement it using concrete observer class.
public ConcreteObserver implements Observer {
public void update(){
System.out.println(“updated”);
}
}

So that’s it. Now we are considering the Java inbuilt observer pattern support. Resource classes are available in the java.util package. Here we have Observable interface works as the Subject interface in our previous example and Observer is as normal Observer as in our previous example. (source codes of below examples took from http://www.java2s.com/Code/Java/Design-Pattern/Observableandobserver.htm)

import java.util.Observable;
import java.util.Observer;

public class MessageBoard extends Observable {
private String message;

public String getMessage() {
return message;
}

public void changeMessage(String message) {
this.message = message;
setChanged();
notifyObservers(message);
}

public static void main(String[] args) {
MessageBoard board = new MessageBoard();
Student bob =  new Student();
Student joe = new Student();
board.addObserver(bob);
board.addObserver(joe);
board.changeMessage(“More Homework!”);
}
}

class Student implements Observer {
public void update(Observable o,  Object arg) {
System.out.println(“Message board changed: ” + arg);
}
}

Introduction For Pattern

Posted in Design Pattern with Java, C++ and Ruby on April 6, 2009 by Asanga Bandara Wijekoon

I hope to share my knowledge on design patterns with you and I will post series of posts on this topic. First I am going to discuss what is design pattern and why people use this and then list what are the design patterns I am going to cover here. I will explain each pattern using Java,c++ and Ruby example codes. Usually pattern will not depend on a language user of it should have to have the ability to use it with any programming language.

A design pattern is a solution well tested by thousands of programmers and it gives solution for a problem in a context (problem domain). When we are using pattern for solve a problem always should consider following fact.

“Don’t consider pattern first and push it to solve the problem by forcing”

Good designers are not try to push patterns for the solution by force manner and they apply pattern in natural way. When they design solutions them fit to some patterns and then they used them. They strongly recommend that don’t make more complex the solution by pushing patterns to it in an unnecessary manner. Anyway for simple system also, its good to use a pattern if it drive for changes in future because by using pattern we can easily change the code. Other than that I need to mention here about the “forces” of a design, which is a buzzword in system designing and it consists of problem and the constraints in the context. Finally in this post I list patterns I’m going to address in my future posts in below,

  1. Observer pattern
  2. Decorator pattern
  3. Factory pattern
  4. Singleton pattern
  5. Command pattern
  6. Adapter pattern
  7. Facade pattern
  8. Template Method pattern
  9. Iterator pattern
  10. Composite pattern
  11. State pattern
  12. Strategy pattern
  13. Proxy pattern
  14. Compound pattern

Ruby Time object issues

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

I faced this problem when I try to deduct database stored time objects. My self and I think most of developers use time object to store time. But time objedct create and store with an aditional information like year, month and time, etc.

So when we try to decduct two time objects it just not give us only the time difference as what we belive. It calculate the difference of both time object not only considering the time but also with considering year, month and day difference.

So be aware about that when u are calculating the time difference and I mention some methods to overcome that issue in below.

(time_object_2) – (time_object_1)%86400

this will give only the time difference. Other than that u can cast all the time object to a current time object year, month and day by using

today=Time.now #today time object

time_object # which is the time object we neet to cast for certain year month and day

cast_time_object=Time.mktime(today.year,today.month,today.day, time_object.hour, time_object.min, time_object.sec,0)

code. Now we can deduct time objects and we can calculate correct time different.


How to access rails inner hash with in a hash

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

Most of the time u are posting u’r post with hash with include another hash. As an example I copy a post parameters I have posted.

Parameters: {“commit”=>”Create”, “date”=>{“minute”=>”30″, “hour”=>”19″}}

I copped this from mongrel  server console.  So how access the :minute value?

Ruby give us a way for accessing inner hash with another hash. So we can access this using following method

params [:date][:minute]

Rails automatically assign post parameter to the “params” hash. Here params is the first hash and we access the date hash with in it. Then we access it’s minute key and get the value.

Rails Ajax and tr issues

Posted in Ruby On Rails on April 6, 2009 by Asanga Bandara Wijekoon

I think this post may help for rails new users. First I will mention how I faced the problem.

I used pure html and prototype functions with in a <tr> tag.

code is

<img src=”/images/delete_img.png” onclick=”new Ajax.Updater(’show_time_table’,'/showtimes/<%=showtime.id%>/’, {method:’delete’})”/>
I used this with in a <tr> tag and I don’t mention about the <td>. Here ajax call not execute until I put this code inside a <td> tag.

Ruby On Rails – Raisl 2.2.2 with mysql

Posted in Ruby On Rails on October 7, 2008 by Asanga Bandara Wijekoon

I have faced lot of difficulties in my ROR programming experiences and I think the way I answer those problem may useful for others also. So today onwards I will publish some useful posts for ROR developers.

Raisl 2.2.2 with mysql

Currently I am using windows xp machine with ROR 2.2.2. New Rails version doesn’t come with mysql gem. So we have to manually install it. If u are working in a secure network most of the time u may have to give proxy address for installing plugin or gems. We can give it as

set http_proxy=http://<your proxy address>:<port>

command. After u gave it then u can install mysql gem by just firing the command

gem install mysql

When u installing this gem u may face some problem with documentation. But make sure for proper usage at least u should install the gem. Then u can restart u’r server.

Ops, Now it says there is a missing libmysql.dll file. So download it and then copy it to windows/system folder.

Ok then u can again restart u’r server and now all works fine.

Go ahead and feel rails coolest features.