Wednesday, December 30, 2009

Installing RMagic in fedora

To install RMagic gem for graphic operations in fedora os follow the below instructions
open terminal by Application -> System Tools -> Terminal
login as root by giving command su
#su
#password: enter root password
goto ruby path
#cd usr/lib/ruby
issue the below command
[root@localhost ruby]
gem install rmagick --no-rdoc --no-ri
you should see the below message if successfully installed RMagic gem
Building native extensions. This could take a while...
Successfully installed rmagick-2.12.2
1 gem installed
To see the gem in your local gems list issue the below command
[root@localhost ruby]# gem list --local

*** LOCAL GEMS ***

actionmailer (2.3.4)
-------------------
-------------------
Rmagic(2.12.2)
------------------
etc.,

For Windows users
c:\> gem install rmagick-2.0.0-x86-mswin32.gem

Bydefault gem install will look for the particular gem name in rubyforge site.
You can also mention the path for git repository if the gem is available in github.

Thursday, December 24, 2009

Rails error: initialize_without_backlog': Address already in use - bind(2)

When try to start the webserver for the application some times this error may happen. This happen when you already run any application in the same port number. Make sure you are not running any other rails application with that same web server in the same system.

If you already start the server one one application, stop it for that application and run for the new application you want.

Good Luck -:)

Wednesday, December 23, 2009

Item Stock Availability check for oscommerce

Availability contribution allows you to set an unique message to
display on each product relating to the availability of the item.
Two messages can be set, one for in-stock and another for out of stock.
Includes convenient admin tool to add and modify the messages
menu on the product edit page. Allows you to include the actual
stock quantity in the message.

donwload this addon from below url
http://addons.oscommerce.com/info/4948

Userfull admin features in oscommerce

Here are few of the features available for the siteadmin in oscommerce.

Manage administrators
Manage Administrators including add new admin, or edit / delte admin information.

Manage customers
View and manage the customers registered to the site

Manage orders
Process and Manage orders made by customers

Categories, subcatagories and products
Managing all categories, subcategories and products in the site. Site admin can add/ edit or delete catgories, subcategories and products.

Product Attributes
Managing all product attributes like color, price etc.,

Product Reviews
View the statistics of each product reviewed by customer

Multilanguage
Site was entirely in multilanguage. Admin can manage the content for each locationization.

Reports
View the reports of products viewed, products purchased

Send Emails
Sending emails to customers

Monday, December 21, 2009

Best Employee Award



I got Best Employee of the year 2008 award on December 14th 2009. I had a warm hug with my CEO.

Wednesday, December 16, 2009

PHP sending emails with gmail smtp to prevent spam mails

1 Download PHPMailer from http://phpmailer.sourceforge.net
2 Extract to folder phpmailer
3 Create a file email.php
4 Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage)

require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "
; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

5 Open the file class.smtp.php in phpmailer directory
6 Paste this code
$host = "ssl://smtp.gmail.com";
$port = 465;
before the line 104 #connect to the smtp server
Hint: Search for #connect
7 Open this page in browser and it will send the email using GMail.

Hint: When you want to email the details from a form, set the variables using the form variables.
eg. $mail->Username=$_POST['email']

Thursday, November 26, 2009

Jquery datagrid for rails applications


With jquery grid plugin along with 2dcJqgrid Rails plugin are awesome for creating datagrids in rails applications which allows users to navigate, search, add/ edit / delete operation in one place.
See the sample screenshot above.

Rails Developement Standards

Application must be under version control. Use SVN
Never put log files or database.yml file into subversion.
Use either Postrgres, Oracle or Mysql for your db.
Session data should be stored in the database
Migrations should NOT contain any db specific SQL.
Use Rspec for testing. Rspec is available as plugin
Application must have Unit and Functional tests.
All application gems should be installed in RAILS_ROOT/vendor/gems folder
Always freeze rails, ( Fix For rails freeze gems )
If your application uses CAS authentication, use the ucb_rails_security plugin
Controller Methods should be no longer than 5-8 lines of code. If you find your self with really large controller methods you are probably violating the following standard.
Application domain logic should go into the model, NOT in the controller or view.
Try to limit each controller's actions to: index, new, create, edit, update, destroy. This is not always possible. However, if you notice that a given controller has more than 10 methods, it probably time to refactor.

Preventing open a new window for each folder in linux

1. Double-click on the "Computer" icon on your desktop.
2. Go to the "Edit" menu and choose "Preferences."
3. Click on the "Behavior" tab.
4. Put a check in the box marked "Always open in browser windows

Sending Tons of emails from your Ruby on Rails Application

A correct way to send tons of massive emails from your website is queuing the emails and send them one by one. If you send all at once directly from your site some hosting servers may allows only some amount of emails per hour. Shared hosting servers allow you send only 25 emails from your site per hour. Fortunately there is one plugin available for Rails which can store the outgoing emails in database as a queue and send them eventually. That plugin is called ar_mailer you can install it and send tons of emails happlily. See the process of how to install and more at http://www.ameravant.com/posts/sending-tons-of-emails-in-ruby-on-rails-with-ar_mailer

Ruby on Rails Easy roles plugin

Easy roles is a plugin for Ruby on Rails which is very usefull for your site if it has lot of roles. So by using this plugin you can restrict the access to controllers based on the roles. Follow the below process to install it for your application.

cd yourappname

ruby script/plugin install git://github.com/platform45/easy_roles.git

Now the plugin is installed in your vendor/plugins folder

Below is the Basic Setup process you need to do after plugin installed successfully
Add the following to your enviroment.rb in the rails initializer block
config.gem 'easy_roles', :source => 'http://gemcutter.org'

Add a "roles" column to your users model, and set the default value to "--- []". Please note you can call this column anything you like, I like to use the name "roles" for meaning full.

For users table migration table add below
t.string :roles, :default => "--- []"

Then you need to add "easy_roles :column_name" and some logic to your model.


class User < ActiveRecord::Base

# Serialize roles as an array
serialize :roles, Array

# Create an empty roles array on create
before_validation_on_create :make_default_roles

# Convenience method, is user an admin?
def admin?
has_role?("admin")
end

# Checks to see if a user has requested role
def has_role?(role)
roles.include?(role)
end

# Add a role to a user
def add_role(role)
self.roles << role
end

# Remove a role from a user
def remove_role(role)
self.roles.delete(role)
end

# Clear all users roles
def clear_roles
self.roles = []
end

private
def make_default_roles
clear_roles if roles.nil?
end
end

And thats it.
The above model gives you the options like below in controllers
@user = User.first
@user.add_role 'admin'
@user.save!

@user.has_role? 'admin'
=> true

@user.admin?
=> true

@user.remove_role 'admin'
@user.save!

@user.admin?
=> false

Usage
Easy roles extends your model, and adds a few methods needed for basic role authorization.

adding a role to a user
add_role 'role'

removing a role from a user
remove_role 'role'

check to see if a user has a certain role
has_role? 'role'
# or
is_role? # role being anything you like, for example 'is_admin?' or 'is_awesome?'

== Examples

@user = User.first

@user.add_role 'admin'

@user.is_admin?
=> true

@user.has_role? 'admin'
=> true

@user.is_awesome?
=> false

@user.add_role 'awesome'

@user.is_awesome?
=> true

@user.remove_role 'admin'

@user.is_admin?
=> false

etc etc

== Protecting controllers

There are many ways to implement views for specific roles, so I did not specifically supply one. Here's an example on what you could do:

class ApplicationController < ActionController::Base

def admin_required
unless current_user && current_user.is_admin?
flash[:error] = "Sorry, you don't have access to that."
redirect_to root_url and return false
end
end

end

Then in your AdminsController or any controller that you only want admins to view:

class AdminsController < ApplicationController
before_filter :admin_required
end

class MarksController < ApplicationController
before_filter :admin_required, :only => :create, :update
end

check out more information at
http://blog.platform45.com/2009/10/05/howto-basic-roles-for-users for implementation

World's Famous IDE eclipse's support for PHP

Hi,
If you already installed eclipse in your system then you have to update it for php support. To do so follow the below steps
1. Open the eclipse IDE
2. Then goto menu Help -> Software updates
There you see Two main tabs Installed softwares and Available softwares. If phpeclipse is not there in installed softwares list then check in Available softwares list. If not avaliable there also Then click on Add site and enter below url.
http://update.phpeclipse.net/update/stable/1.2.x
Then that eclipse's update url is added to available softwares list. Check that module and click install. It will take few minutes and install phpeclipse and PDT (PHP Development Tools) to your existing eclipse IDE.
After installed successfully Goto menu Window -> open perspective
and select PHP to start working on PHP Projects.

The process is same to enable any other technologies support in eclipse for developing applications.

If you are not installed eclipse IDE in your system then you can directly install it from the official website http://www.eclipse.org/



Tuesday, November 24, 2009

File permissions in Linux

Hi,
By using chown command through terminal you can give file permissions to the users in linux operating systems without login as root. By default you are not able to access some folders in the linux os due to the security reasons. But sometimes you need to access some folders. Ex: If you want to run php files you need to place the files in the folder called /var/www/html but other than root account no one have write permission to this folder.

So if you want to enable write permissions to that folder for your account simply
open the terminal as
# applications > system tools > Terminal
enter su in the terminal to login as root
#su
it will ask you the root password, give the root password
then run the below command
#chown username /var/www/html/

Now you have the write permissions to that folder.

Flash Plugin for Firefox in Fedora11 OS

To enable flash player support for your firebox browser in Linux operating system goto the abode site using below link
http://labs.adobe.com/downloads/flashplayer10.html

and download the linux version tar file uncompress the tar file and Copy the file libflashplayer.so in to the folder /usr/lib/mozilla/plugins.

That's it you just need to restart the firefox by File -> Exit and see your firefox is now enabled with flash support.

Tuesday, November 17, 2009

Youtube clone

Hi Friends, If you are a PHP Mysql Developer then this post is exactly for you. You can develop youtube alike site with your existing knowledge. Just goto the phpmotion site at http://www.phpmotion.com/ and download the source and unzip it and upload to the hosting server. Then run that through browser. It asks you the necessary settings, after giving all details the youtube like site owns you. See the demo http://demo.phpmotiontemplates.com/. I used this script for creating media sharing site. It works more than as youtube site.

Friday, November 6, 2009

Googlemap show Directions between two places

Place the below js code in head tag
var map;
var directionsPanel;
var directions;
function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(42.351505,-71.094455),12);
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
directions.load("from:kakinada,india to:Kurnool,india");
}
Place the two divs in html body with ids map_convas, route
Call onload="initialize()" onunload="GUnload()" in body tag.
directions.load("from:kakinada,india to:Kurnool,india");
here you you can also place lat,long pairs in place of from and two address

Some usefull sites for Ruby on Rails newbies

From http://api.rubyonrails.org/
study all activerecord, actionview and actioncontroller classes
Ex: classes -> active record::call backs
which explains what action done before or after creating a record in database or before deleting a record from one table what needs to done in other tables etc

Ruby hashes. Means associatinve arrays in php. Each values is associated with one key like $array=new array(‘color’ => ‘whilte’ , ‘Height’ => ‘6 feet’)
http://www.rubyonrailsexamples.com/category/ruby-hash/

Validation classes and lot more
http://apidock.com/rails/ActiveRecord/Validations/ClassMethods
http://apidock.com/rails/ActiveRecord/Base
All methods and available for active record like save update delete etc
*********************************

Find Some things to look at
http://www.palmcoder.net/?p=265

Tutorials
Rails ajax (Implementing remote call is very easy in RoR)
http://onlamp.com/onlamp/2005/06/09/rails_ajax.html

Link_to_remote with passing textbox value as a parameter
http://onlamp.com/onlamp/2005/06/09/rails_ajax.html

Forum

http://railsforum.com

Check username availablility
http://railsforum.com/viewtopic.php?id=22828

Gems
http://ariejan.net/gems/

http://www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials

Testing
http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-unit-testing.htm

Ruby on Rails Easy Deployment

Actually Ruby on Rails deployment is little bit tricky compare to PHP. PHP programs tend to require less memory to run so they tend to be easier to deploy. With the release of mod_rails and Ruby Enterprise Edition Rails becomes easier to deploy than PHP once the initial Apache add-ons are made. See from below site for full details
http://b.lesseverything.com/2008/8/25/comparing-php-to-ruby-on-rails

Pagination gem for Ruby on Rails

For ruby on rails there is a gem available for pagination called will_paginate to provide pagination to the database results. Process to install this gem to your application.
1. rake gems:install
2. gem sources -a http://gems.github.com
3. gem install mislav-will_paginate
For the first time to install gems package run step 1. If you already run this command no need to run again. step 2 is to append the gems to your rails. Step 3 will install the will_paginate gem to your application.

Usage:
After installed gem successfully follow the below steps to enable pagination to your models.

1. In your config\environment.rb file add
Rails::initializer.run do |config|
config.gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate', :source => 'http://gems.github.com'
end


2. rake gems:install

3. In your model, mention how many records display per page

def self.per_page
5
end

4. In your controller, replace
@yourmodels = Yourmodel.find
with
@yourmodels = Yourmodel.paginate :page => params[:page], :order => 'created_at DESC'
5. In your index view, add below to see the pagination
<%= will_paginate @models %>

see http://localhost:3000/models
-----------------------End-------------------------------------------

Thursday, September 17, 2009

Cupcake A forum plugin for cakephp

A plugin called “Cupcake Forum” released for CakePHP. Now you can integrate forum to your cakephp applications within fraction of minutes. The plugin comes with all the basic features of a famous phpbb forum some of which include topics, posts, replies, users, polls, moderators, staff and much more.
Download: http://www.milesj.me/resources/script/forum-plugin
Demo: http://www.milesj.me/forum

Wednesday, September 9, 2009

Sobi2 Plugin

Joomla sobi2 component. Used to develop website with multiple modules, multiple categories, and subcategories and also create entries (Forms) for end users to submit their data to the site. And admin can manage this data and also the end user can edit his own data. It is very useful for developing sites in joomla.
See All About Sobi2

PHP Dynamic Timezones Setting

Some queries work well in one timezone will effected in another timezones. Because timezones are varied from server to server. To overcome this problem you can set the default timezone for the site irrespective of the server time by using the below function.

date_default_timezone_set('Timezone')

here 'Timezone' is the string for example for setting Indian Standard Time it is "Asia/Calcutta", for Los Angels it is "America/Los_Angeles" etc

Ex: date_default_timezone_set('Asia/Calcutta')

Checkout the timezones list at php.net

Friday, July 17, 2009

Geolocalization to get lattitude and longitude values

Geolocalization is the process of getting lattitude and longitude values for given address. The code below gives you the lat long values from google for your addresses.

Copy paste options are not working in dreamweaver

In my dream weaver copy paste options are not working. Its gives an erroraneous alert "While executing DWShortcuts_HTMLSource_Find_Replace command in menus.xml, the following JavaScript error(s) occured:".

The solution that i got from somewhere was to basically clear the configurations for dreamweaver.

C:\Documents and Settings\\Application Data\Macromedia\Dreamweaver MX 2004\Configuration

To acertain if this is the case, you can simply test it by moving the configuration folder to somewhere else. If it still doesnt work, simply put it back.

Now my dreamweaver works fine again without having to reinstall it.

Encoding and Decoding the strings in PHP

base64_encode and base64_decode functions are used to encode and decode your strings.
Ex code:
';
$encode=base64_encode($str);
echo 'Encoded : ',$encode,'
';
echo 'Decoded : ',base64_decode($encode);
?>

How to clear file upload field value using js

We can't assign or remove value through js for file upload field. We can remove value only through reset button only.
But we can do it simply as below.
First take that file field in div or any other container tags like span etc.,
and in js give that div's innerHTML as input type="file" name="img". So new file upload element is created within that div.

Thursday, July 16, 2009

About Joomla module

Joomla module is logic with interface which can placed at multiple pages at user defined position of the pages. We can easily make it enable / disable and change it's position at any time.
Example: “online friends” is one module which can be placed in different pages at what ever position we want.
There are so many modules available freely at http://extensions.joomla.org/
You can develop your own module for any of specific purpose and call it in all pages or some of the pages you want.