Monday, October 25, 2010

Installing Redmine for Windows Server in 10 minutes

1. Download version 1.8 of Ruby – the link is to the “all-in-one” installer for Windows. You need version 1.8, not 1.9 as Redmine only works on 1.8 right now.
2. Set up so Ruby’s “bin” folder is in your system or command prompt path. You should be able to type “ruby” at the command prompt and not get any “file not found” errors.
3. Create yourself some sort of “Ruby apps” folder and open a command prompt at that location, e.g. C:\Ruby\Apps or something
4. At the command prompt: “gem install rails“
5. At the command prompt: “gem install mongrel“
6. At the command prompt: “gem install rack -v=1.0.1“
7. At the command prompt: “gem sources -a“
8. At the command prompt: “gem install win32-service --platform mswin32“
9. At the command prompt: “gem install mongrel_service --platform i386-mswin32“
10. Download the latest stable version of Redmine and unzip into a subfolder of your Ruby apps dir (e.g. C:\Ruby\Apps\Redmine)
11. Configure the database.yml for Redmine to point to a database for your Redmine instance to use (I’ll leave that up to you)
12. If you’re using Redmine v0.8.7 or above, at the command prompt: “rake generate_session_store”
13. In the Redmine folder, at the command prompt: “rake db:migrate RAILS_ENV=production“
14. Test your Redmine installation is working, at the command prompt: “mongrel_rails start“, then hit http://localhost:[port]/ in your browser where [port] is the port Mongrel started with. Kill the server with Ctrl+C once you’ve verified Redmine is working.
15. Install Redmine as a Windows service, at the command prompt: “mongrel_rails service::install -N Redmine -c [your redmine folder] -p [portno] -e production“, replacing [your redmine folder] with the full path to the Redmine folder in the filesystem, and the [portno] being the port you’d like redmine to server on, e.g. 80 for standard http port 80.

Warning: With the latest version of MySQL, you may get several errors such as: "!!! The bundled mysql.rb driver has been removed from Ruby 2.2" and when you try to do "gem install mysql" you may also get many errors. Attempting to perform any rake commands subsequently fail. One possible solution:
Try to download the following DLL file from the InstantRails project:
Copy this file into your \Ruby\bin directory and try running your rake commands again.

Monday, October 18, 2010

Flash plugin for 64 bit Ubuntu 10.04

Use the Adobe Flash PPA and install the flashplugin64-installer package. You can do this by copying and pasting the following into a terminal:
sudo add-apt-repository ppa:sevenmachines/flash 
&& sudo apt-get update 
&& sudo apt-get install flashplugin64-installer
You will need to restart your browser after installing for Flash to work.

Sunday, June 13, 2010

Moving Magento to another server (either localhost or public host)

Step 1: Copy every files in your application folder and FTP to your new host. In this case, I don't recommend you install a new clean Magento in your new host due to the change in version of Magento can cause a lot of trouble. In this step, you better compress all your files if you can extract it on your new host.
Step 2: Moving database to the new host should be consisting of a two simple step. Step 2.1: Export your database to a file. Step 2.2: Import your database from a file to new MySQL server. Sounds easy, right. Well it is. At least it should be. I wonder is it my bad karma, or what is it when it comes to Magento? Personal lack of experience? Whatever it is, result can sometimes be quite time consuming. Anyway here is my solution to the error problems and entire process of moving magento database from one host to another.
First, make a backup of entire Magento database with all the default phpMyAdmin options. Backup your database to .sql file.
Let’s suppose your development site is located at http://xxx and your live site is located at http://yyy.
Second step for you would be to open the backup file you created at first step and do Search/ReplaceAll from “xxx” to “yyy”. Magento stores complete url paths inside the database. Therefore you’ll end up with database full of url paths. My backup file had total more than 100000 occurrences of “xxx”. Huge number.
Anyway this is a must do. There is no point at importing database to new server if you haven’t done this replacement since Magento pools links from database. So if you haven’t done replacement and have done import then basically your Magento on http://xxx would look for links of http://yyy like http://xxx/some-product-name. This off course isn’t good.
If you finish searching/replacing your .sql file, DO NOT rush to import it. If you try to import file as is, you’ll most likely get some errors from MySQL concerning foreign key constraint an so on. I lost about 3 hours of mine time testing and checking things out to get around this. Here’s how. Open your .sql backup file again in your favorite editor and do the following steps.
Place these lines of SQL code on very top of the .sql file:
Place these lines of SQL code on very end of the .sql file:
Now you’re ready to import your .sql file to live MySQL database. Or not? I suggest you ZIP your .sql file and then do import of .zip file trough phpMyAdmin. At least you’re upload will be faster. For example my .sql file was 13MB in size while .zip was 500KB. During the import you should not get any error messages.
Step 3: Having in mind that the root of your Magento is http://yyy you now need to open http://yyy/app/etc/local.xml file and modify it’s database connection information accordingly to your new database in Save the changes open your browser to Your Magento should be working.
Step 4: Clear old cache by empty the following folders: var/cache and var/session.
This guide should get you up n running if you’re moving you’re site from one hosting to another. There are few more things to keep in mind it the site is not working. First you need to check folder write permissions trough FTP. Folders like /app, /app/etc, /var, /var/log, /var/session and so on, need to have appropriate access rights (755, 775, 777). Play around with it. There is one more thing that can cause problems. That is .htaccess file. If you’re moving a file from one site to another, and dumping it into same folder, then you probably won’t need to change this. But if you’re dumping it into some sub folder like http://yyy/store/ then you’ll have to write following into .htaccess file “RewriteBase /store/” and don’t forget your .sql Search/replace all to set it now replace of “http://xxx” with “http://yyy/store/” since you’re dumping Magento into sub folder.
Step 5: This step is neccessary in the case you are using Magento 1.3 and moving to the host with PHP 5.3 version only. If you are using Magento 1.4 or your host is still using PHP 5.2, things should be fine now. You should enable Mage::setIsDeveloperMode(true); in your index.php file to see where is the problems. The problem caused by 2 functions which are deprecated in PHP 5.3: ___toString to __invoke and split() to explode().
Try to change in file /lib/Varien/Object.php on line ~ 484
public function ___toString(array $arrAttributes = array(), $valueSeparator=',')
To this
public function __invoke(array $arrAttributes = array(), $valueSeparator=',')
And in file /app/code/core/Mage/Core/Controller/Request/Http.php on line 274
$host = split(':', $_SERVER['HTTP_HOST']);
$host = explode(':', $_SERVER['HTTP_HOST']); 
Hope you make it; I did. It took me 7 hours to do something it takes 2h max. However, I’m ready for the round two now.
Feel free to post comments. I could use some community feedback

Sunday, May 9, 2010

Web Servers and Application Servers

Starting with Web Programming, usually most programmers are acquainted with some servers like IIS from Microsoft or Apache HTTP Server. Those two servers are classified as Web Servers (Wiki) while some of the other well known servers like Apache Tomcat, Red Hat JBoss, Oracle Glassfish, IBM WebSphere, Oracle WebLogic, Apple WebObjects,... are always mentioned as Application Servers (Wiki). So what is the main difference between Web Servers and Application Servers?

1) The Web Server

A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser.
Understand that a Web server's delegation model is fairly simple. When a request comes into the Web server, the Web server simply passes the request to the program best able to handle it. The Web server doesn't provide any functionality beyond simply providing an environment in which the server-side program can execute and pass back the generated responses. The server-side program usually provides for itself such functions as transaction processing, database connectivity, and messaging.
While a Web server may not itself support transactions or database connection pooling, it may employ various strategies for fault tolerance and scalability such as load balancing, caching, and clustering—features oftentimes erroneously assigned as features reserved only for application servers.

2) The Application Server

As for the application server, according to our definition, an application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object (or a function in the procedural world).
Such application server clients can include GUIs (graphical user interface) running on a PC, a Web server, or even other application servers. The information traveling back and forth between an application server and its client is not restricted to simple display markup. Instead, the information is program logic. Since the logic takes the form of data and method calls and not static HTML, the client can employ the exposed business logic however it wants.
In most cases, the server exposes this business logic through a component API, such as the EJB (Enterprise JavaBean) component model found on J2EE (Java 2 Platform, Enterprise Edition) application servers. Moreover, the application server manages its own resources. Such gate-keeping duties include security, transaction processing, resource pooling, and messaging. Like a Web server, an application server may also employ various scalability and fault-tolerance techniques.

3) Examples

As an example, consider an online store that provides real-time pricing and availability information. Most likely, the site will provide a form with which you can choose a product. When you submit your query, the site performs a lookup and returns the results embedded within an HTML page. The site may implement this functionality in numerous ways. I'll show you one scenario that doesn't use an application server and another that does. Seeing how these scenarios differ will help you to see the application server's function.

Scenario 1: Web server without an application server

In the first scenario, a Web server alone provides the online store's functionality. The Web server takes your request, then passes it to a server-side program able to handle the request. The server-side program looks up the pricing information from a database or a flat file. Once retrieved, the server-side program uses the information to formulate the HTML response, then the Web server sends it back to your Web browser.
To summarize, a Web server simply processes HTTP requests by responding with HTML pages.

Scenario 2: Web server with an application server

Scenario 2 resembles Scenario 1 in that the Web server still delegates the response generation to a script. However, you can now put the business logic for the pricing lookup onto an application server. With that change, instead of the script knowing how to look up the data and formulate a response, the script can simply call the application server's lookup service. The script can then use the service's result when the script generates its HTML response.
In this scenario, the application server serves the business logic for looking up a product's pricing information. That functionality doesn't say anything about display or how the client must use the information. Instead, the client and application server send data back and forth. When a client calls the application server's lookup service, the service simply looks up the information and returns it to the client.
By separating the pricing logic from the HTML response-generating code, the pricing logic becomes far more reusable between applications. A second client, such as a cash register, could also call the same service as a clerk checks out a customer. In contrast, in Scenario 1 the pricing lookup service is not reusable because the information is embedded within the HTML page. To summarize, in Scenario 2's model, the Web server handles HTTP requests by replying with an HTML page while the application server serves application logic by processing pricing and availability requests.

4) Caveats

Recently, XML Web services have blurred the line between application servers and Web servers. By passing an XML payload to a Web server, the Web server can now process the data and respond much as application servers have in the past.
Additionally, most application servers also contain a Web server, meaning you can consider a Web server a subset of an application server. While application servers contain Web server functionality, developers rarely deploy application servers in that capacity. Instead, when needed, they often deploy standalone Web servers in tandem with application servers. Such a separation of functionality aids performance (simple Web requests won't impact application server performance), deployment configuration (dedicated Web servers, clustering, and so on), and allows for best-of-breed product selection.

Wednesday, May 5, 2010

Log4j vs java.util.logging

While Log4j and JUL are almost conceptually identical, they do differ in terms of functionality. Their difference can be summarized as, "Whatever JUL can do, Log4j can also do - and more." They differ most in the areas of useful appender/handler implementations, useful formatter/layout implementations, and configuration flexibility.

Tuesday, May 4, 2010

Making WAR archive for the GWT applications using Eclipse/Ant builder

In some web server like Tomcat or Glassfish, it is convenient to have an archive war to publish as your web application. But making war in GWT applications is not that simple due to the numerous dependencies and rich library included.
The most challenging part of the problem is to write the Ant build.xml file. In order to solve this issue, I have used a small trick. GWT comes with a utility called webAppCreator which not only sets up the GWT project and creates some handy starter app code, but also provides a build.xml and JDT launch configuration file. The syntax is like below:
webAppCreator -out HelloGWT com.mycompany.mywebapp.HelloGWT
In order to generate the war archive, you just copy the build.xml into your project folder. I make changes accordingly in the following points:
1)arg value="com.mycompany.mywebapp.HelloGWT" => "" in both target gwtc and devmode
2)zip destfile=".war" basedir="war"
Another issues is whether you want to use Eclipse to make war file or use normal Ant builder.
If your choice is Eclipse, go to Run > External Tools > External Tools Configurations, and create a new Ant build, pick the build.xml for your project, your project as the base directory, then move to the Targets tab, and select the war target, deselecting the build target since war depends on build already. It's a good idea to name this Configuration "MyWebApp war" or similar. When the target is run, your code will be compiled into the war subdirectory, which will then be zipped into MyWebApp.war in the project directory.
In my case, I preferred to make war file on my own using Ant builder. I modified the build.xml as below


(remove target "war" and "clean")
Using command line to locate your project folder. Run "ant" => making war.

Monday, May 3, 2010

Interview @Helios Lab Pte. Ltd

Although it is quite a long time since I had a job interview, I personally satisfied with my performance disregarding the outcome. This interview in some way benefited more than the actual result. Some of the main knowledges I somehow have heard of or reading through before or after the interview:
1) SPRING Framework: facilitates Domain Driven Design, isolates Business Logics and Displays.
2) Inversion of Control, Aspect Oriented Programming, Design Patterns, Java Message Services, Java Management Extensions, all the important features of J2EE.
3) Google Web Toolkit and J2EE.
4) GlassFish Java Server.
 The senior developer also asked me some Java questions which I cannot answer. One question mentioned about the Gabbage Collection Mechanism in Java, and the other questions asked about some Collections in Java which are Thread Safe.

Saturday, May 1, 2010

Testing SyntaxHighlighter

// Comment
public class Testing {
   public Testing() {

   public void Method() {
      /* Another Comment
      on multiple lines */
      int x = 9;

Compile 1st C++ Program in Ubuntu

Having installed Ubuntu for quite a long time, and I finally have learnt how to program C++ in this Unix environment. 

I type my C++ program using gedit that is available under Ubuntu.
I tried this code first hand and it does not worked.

$ gcc -o  hw1 hw1.cpp

I found out the reason is that gcc is used for only C program files and not C++. The following command is actually worked out.

$ g++ -o  hw1 hw1.cpp

This -o basically used to suggest name for the executable file that g++ would create. In case if you typed something like the following:

$ g++ hw1.cpp

You would be having a a.out in the same directory as the source C file. This is the default name of the executable that g++ creates. This would create problems when you compile many programs in one directory. So you override this with the -o option followed by the name of the executable.

Would create an executable by the name hw1 for your source code named hw1.cpp.

Running the executable that you created is as simple as typing the following at the prompt.

$ ./hw1
$ ./a.out

Or whatever you named your executable. 

Tuesday, March 30, 2010

Blogging with my HTC

@SBS during midnight