Single line css
#wrapper {
width:800px;
margin:0 auto;
}
#header {
height:100px;
position:relative;
}
#feature .post {
width:490px;
float:left;
}
Multiline css
#wrapper {width:800px; margin:0 auto;}
#header {height:100px; position:relative;}
#feature .post {width:490px; float:left;}
If you use, Multiline css then you can easily find the style for an element when ever you need to customise it also the number of lines per style sheet would be decreased.
Monday, July 5, 2010
Backup database using php code
Hello Frineds,
Below code would take entire database backup and store it in the current folder. You can run this script automatically using crop job, so that you would have your database backup for every day or every week as you wish.
//backup_tables('localhost','root','rot','database_name','table_name'); //To backup one specific table
backup_tables('localhost','root','rot','database_name'); // To backup entire database
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
Below code would take entire database backup and store it in the current folder. You can run this script automatically using crop job, so that you would have your database backup for every day or every week as you wish.
//backup_tables('localhost','root','rot','database_name','table_name'); //To backup one specific table
backup_tables('localhost','root','rot','database_name'); // To backup entire database
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
Difference between echo & return statements in function
Hi,
Here is the explanation about where we should use echo and where we should use return statements while working with functions.
If you want to print some thing on browser and continue execution of the process then you have to use echo statement.
Ex:
function test()
{
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
test();
}
$count--;
}
test();
?>
Here static variable is initialised only once when first called the test function and then it will maintain the value of $count till the end of the process.
O/P:12345678910
When you use the return statement the program execution stopped in that line and output some thing to the variable. So Calling return in your script or function will either end the script or end the function and then return the value
Ex:
function test($arg)
{
if ( $arg == 'ban' ) {
return 'Banana';
}
else
{
// There's nothing else to do, so end execution of this function
return;
}
}
$fruit = test('banana');
if ($fruit=='Banana')
{
echo 'Banana';
}
?>
Here is the explanation about where we should use echo and where we should use return statements while working with functions.
If you want to print some thing on browser and continue execution of the process then you have to use echo statement.
Ex:
Recursive functions with static variables
function test()
{
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
test();
}
$count--;
}
test();
?>
Here static variable is initialised only once when first called the test function and then it will maintain the value of $count till the end of the process.
O/P:12345678910
When you use the return statement the program execution stopped in that line and output some thing to the variable. So Calling return in your script or function will either end the script or end the function and then return the value
Ex:
function test($arg)
{
if ( $arg == 'ban' ) {
return 'Banana';
}
else
{
// There's nothing else to do, so end execution of this function
return;
}
}
$fruit = test('banana');
if ($fruit=='Banana')
{
echo 'Banana';
}
?>
Friday, July 2, 2010
PHP start session only once to prevent warnings
session_id() returns an empty string if there is no current session, so to test if a session already exists, its better to write this :
if(session_id() == "")
{
session_start();
}
else
{
// Anything you want
}
if(session_id() == "")
{
session_start();
}
else
{
// Anything you want
}
Thursday, July 1, 2010
Get current page URL along with SSL protocal and port number In PHP
Hi, Below code will get the current page URL along with SSL protocal and port number
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
echo curPageURL();
?>
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
echo curPageURL();
?>
Search features in eclipse editor
Simple search and replace
Ctrl + F
Advanced search and replace
Ctrl + H
When you press Ctrl + H then search window will open in eclipse editor
Containing text: which text do you want to find. Ex: if you don't know some function was defined, then simply you can search for function funname(
File name patterns
*.php will search in all php files
*.* will search win all files
Scope
Workspace OR Enclosing Projects
Workspace means search in all projects
Enclosing Projects means search in current working project
Ctrl + F
Advanced search and replace
Ctrl + H
When you press Ctrl + H then search window will open in eclipse editor
Containing text: which text do you want to find. Ex: if you don't know some function was defined, then simply you can search for function funname(
File name patterns
*.php will search in all php files
*.* will search win all files
Scope
Workspace OR Enclosing Projects
Workspace means search in all projects
Enclosing Projects means search in current working project
Phonegap - an opensource framework for developing iphone and other applications
Phonegap is an open source framework for developing different mobile applications. By using HTML, CSS and Javascript we can create appliations with core features of iPhone, Ipad, Android, Palm, Symbian, Blackberry etc.,,
Sample code
http://github.com/sintaxi/phonegap
Official website
http://www.phonegap.com/
Sample code
http://github.com/sintaxi/phonegap
Official website
http://www.phonegap.com/
Tuesday, June 29, 2010
Open new tab in browser using js
//open new tab with blank address
window.open('', '_blank', 'toolbar=0,location=0,menubar=0');
//open new tab with url
window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
window.open('', '_blank', 'toolbar=0,location=0,menubar=0');
//open new tab with url
window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
Monday, June 28, 2010
Wordpress plugin development
Hi Friends,
Here is very good information provided for wp plugin developement, it explained in a very easy way.
http://www.problogdesign.com/wordpress/a-novice-guide-to-wordpress-plugin-development/
Here is very good information provided for wp plugin developement, it explained in a very easy way.
http://www.problogdesign.com/wordpress/a-novice-guide-to-wordpress-plugin-development/
Thursday, June 24, 2010
Visual way to provide feedback and ask your employee to do necessary changes
Visual way to provide feedback and ask your employee to do necessary changes either on design or content of the webpage. To get started sign up at http://www.notableapp.com/
Jquery selectors reference for beginners
Hi Friends,
Jquery selectors are used to apply effects for all elements or some or group of elements by using classes or IDs and tag names.
Ex: $(‘#id’); This selector selects an element with the given ID.
$(‘.class’) The class selector will gather all elements in the document with the given class name
:first $(‘ul li:first’); Returns the first element in a result set
You can see the complete information at below url.
http://www.pamaya.com/jquery-selectors-and-attribute-selectors-reference-and-examples/
Jquery selectors are used to apply effects for all elements or some or group of elements by using classes or IDs and tag names.
Ex: $(‘#id’); This selector selects an element with the given ID.
$(‘.class’) The class selector will gather all elements in the document with the given class name
:first $(‘ul li:first’); Returns the first element in a result set
You can see the complete information at below url.
http://www.pamaya.com/jquery-selectors-and-attribute-selectors-reference-and-examples/
Wednesday, June 23, 2010
Tricky interview questions revealed by yahoo
When it comes to appearing for a job interview, we all prepare ourselves by finding out about our potential employers, but at times we are asked an off-the-wall question that leaves us stumped.
In order to help us prepare for such questions, Glassdoor.com, a two-year-old Sausalito, Calif. website that bills itself as "the TripAdvisor for careers", compiled a list of some of the top oddball interview questions.
Glassdoor gets its information directly from employees who work at 84,000 companies, reports ABC News.
According to Rusty Rueff, a consultant at Glassdoor, who is the author of Talent Force: A New Manifesto for the Human Side of Business and former head of human resources said ninety percent of people don't know how to deal with them.
Rueff advises, first you have to realize that the interviewer isn't trying to make you look stupid, as stupid as the question may seem.
With a question like "How many hair salons are there in Japan", the interviewer is giving you an opportunity to demonstrate your thought processes.
Rueff says you should think out loud, like the contestants on Who Wants to be a Millionaire? You might start by saying, we'd have to know the population of Japan, and then we'd have to figure out what percentage of them get their hair done and how often.
Rueff says it's fine to pull out a pen and paper and start doing some calculations right there in the interview.nother example, which may seem equally impossible to answer: Why are manhole covers round?
Just start thinking through the question, out loud, Connie Thanasoulis-Cerrachio, a career services consultant at Vault.com advises.
"I would say, a round manhole cover could keep the framework of the tunnel stronger, because a round frame is much stronger than a square frame," she suggested.
Other weird-seeming questions, like "If you were a brick in a wall, which brick would you be and why," or "If you could be any animal, what would you be and why," are really just invitations to show a side of your personality.
Thanasoulis-Cerrachio says a friend who is chief executive of a market research company used to ask applicants what kind of car they would be.
"She wanted someone fast, who thought quickly. She wanted someone who wanted to be a Maserati, not a Bentley," Thanasoulis-Cerrachio said.
For the brick question, Thanasoulis-Cerrachio advises saying something like, "I would want to be a foundational brick because I'm a solid person. You can build on my experience and I will never let you down." (ANI)
In order to help us prepare for such questions, Glassdoor.com, a two-year-old Sausalito, Calif. website that bills itself as "the TripAdvisor for careers", compiled a list of some of the top oddball interview questions.
Glassdoor gets its information directly from employees who work at 84,000 companies, reports ABC News.
According to Rusty Rueff, a consultant at Glassdoor, who is the author of Talent Force: A New Manifesto for the Human Side of Business and former head of human resources said ninety percent of people don't know how to deal with them.
Rueff advises, first you have to realize that the interviewer isn't trying to make you look stupid, as stupid as the question may seem.
With a question like "How many hair salons are there in Japan", the interviewer is giving you an opportunity to demonstrate your thought processes.
Rueff says you should think out loud, like the contestants on Who Wants to be a Millionaire? You might start by saying, we'd have to know the population of Japan, and then we'd have to figure out what percentage of them get their hair done and how often.
Rueff says it's fine to pull out a pen and paper and start doing some calculations right there in the interview.nother example, which may seem equally impossible to answer: Why are manhole covers round?
Just start thinking through the question, out loud, Connie Thanasoulis-Cerrachio, a career services consultant at Vault.com advises.
"I would say, a round manhole cover could keep the framework of the tunnel stronger, because a round frame is much stronger than a square frame," she suggested.
Other weird-seeming questions, like "If you were a brick in a wall, which brick would you be and why," or "If you could be any animal, what would you be and why," are really just invitations to show a side of your personality.
Thanasoulis-Cerrachio says a friend who is chief executive of a market research company used to ask applicants what kind of car they would be.
"She wanted someone fast, who thought quickly. She wanted someone who wanted to be a Maserati, not a Bentley," Thanasoulis-Cerrachio said.
For the brick question, Thanasoulis-Cerrachio advises saying something like, "I would want to be a foundational brick because I'm a solid person. You can build on my experience and I will never let you down." (ANI)
Friday, June 18, 2010
Move Wordpress to another host
Simple process to get work.
Wordpress application run in another host or another url.
Wordpress will configure all the paths in database only, ex: when you upload any image, its absolute path stored in database. And all content will reside in wp-content folder.
New host
1. First install new wordpress in new host
Old host
2. Take mysql backup from old site. or goto Tools -> Import in wp-admin.
This should be used later for running old application
Old host
3.
Login admin panel of old site, Goto settings -> General
change WordPress address (URL) and Blog address (URL) against new host and click "Save Changes"
Now the database will updated with new host urls.
4. Old host
Goto phpmyadmin and export the database or goto Tools -> Export in wp-admin.
5. Old host
Revert back the database with old one, i.e we took backup on step-2.
New host
6. Import the old application's database which we get from step 4.
New host
7. Copy the wp-content folder from old host and pasted it into new host.
Now, upon completion of these steps we can sucessfully run the same application in both the hosts.
( OR )
You can copy all the files from old server and pasted it in new server and follow below process.
wp-config.php is the main configuration file for database connections and others.
Edit wp-config.php file to suit with your database
//DB_USER etc.,
Open database goto wp_options table and change the below two rows
option_value='your-new-url' where option_name='site url' and
option_value='your-new-url' where option_name='home'.
If you didn't change this siteurl value in this table your site will connect to old site when you try to access admin panel.
After done, goto /wp-admin section through browser and enter admin details.
Then goto Settings -> General -> change urls.
Now site configured and worked properly in new server or localhost.
In database replace every occurance of http://oldserver/wp-content links with http://newserver/wp-content. So that image links are worked currectly.
Some settings are fixed in wp-settings.php file.
Complete Reference
http://www.dollarshower.com/move-wordpress-blog-to-another-host-server/
http://support.hostgator.com/articles/pre-sales-questions/how-to-transfer-your-wordpress-blog-from-one-host-to-another-host
http://www.makeuseof.com/tag/move-wordpress-blog-host/
Custom fields in wordpress
http://codex.wordpress.org/Using_Custom_Fields
Wordpress application run in another host or another url.
Wordpress will configure all the paths in database only, ex: when you upload any image, its absolute path stored in database. And all content will reside in wp-content folder.
New host
1. First install new wordpress in new host
Old host
2. Take mysql backup from old site. or goto Tools -> Import in wp-admin.
This should be used later for running old application
Old host
3.
Login admin panel of old site, Goto settings -> General
change WordPress address (URL) and Blog address (URL) against new host and click "Save Changes"
Now the database will updated with new host urls.
4. Old host
Goto phpmyadmin and export the database or goto Tools -> Export in wp-admin.
5. Old host
Revert back the database with old one, i.e we took backup on step-2.
New host
6. Import the old application's database which we get from step 4.
New host
7. Copy the wp-content folder from old host and pasted it into new host.
Now, upon completion of these steps we can sucessfully run the same application in both the hosts.
( OR )
You can copy all the files from old server and pasted it in new server and follow below process.
wp-config.php is the main configuration file for database connections and others.
Edit wp-config.php file to suit with your database
//DB_USER etc.,
Open database goto wp_options table and change the below two rows
option_value='your-new-url' where option_name='site url' and
option_value='your-new-url' where option_name='home'.
If you didn't change this siteurl value in this table your site will connect to old site when you try to access admin panel.
After done, goto /wp-admin section through browser and enter admin details.
Then goto Settings -> General -> change urls.
Now site configured and worked properly in new server or localhost.
In database replace every occurance of http://oldserver/wp-content links with http://newserver/wp-content. So that image links are worked currectly.
Some settings are fixed in wp-settings.php file.
Complete Reference
http://www.dollarshower.com/move-wordpress-blog-to-another-host-server/
http://support.hostgator.com/articles/pre-sales-questions/how-to-transfer-your-wordpress-blog-from-one-host-to-another-host
http://www.makeuseof.com/tag/move-wordpress-blog-host/
Custom fields in wordpress
http://codex.wordpress.org/Using_Custom_Fields
Move Wordpress to another host
http://www.dollarshower.com/move-wordpress-blog-to-another-host-server/
http://support.hostgator.com/articles/pre-sales-questions/how-to-transfer-your-wordpress-blog-from-one-host-to-another-host
http://www.makeuseof.com/tag/move-wordpress-blog-host/
Bigdump used to import large databases
http://www.ozerov.de/bigdump.php
http://support.hostgator.com/articles/pre-sales-questions/how-to-transfer-your-wordpress-blog-from-one-host-to-another-host
http://www.makeuseof.com/tag/move-wordpress-blog-host/
Bigdump used to import large databases
http://www.ozerov.de/bigdump.php
Monday, May 24, 2010
About Rails Framework
Rails is a web-application and persistence framework that includes everything
needed to create database-backed web-applications according to the
Model-View-Control pattern of separation. This pattern splits the view (also
called the presentation) into "dumb" templates that are primarily responsible
for inserting pre-built data in between HTML tags. The model contains the
"smart" domain objects (such as Account, Product, Person, Post) that holds all
the business logic and knows how to persist themselves to a database. The
controller handles the incoming requests (such as Save New Account, Update
Product, Show Post) by manipulating the model and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
link:files/vendor/rails/activerecord/README.html.
The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
1. At the command prompt, start a new Rails application using the rails command
and your application name. Ex: rails myapp
(If you've downloaded Rails in a complete tgz or zip, this step is already done)
2. Change directory into myapp and start the web server: script/server (run with --help for options)
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
4. Follow the guidelines to start developing your application
== Web Servers
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
that you can always get up and running quickly.
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
getting up and running with mongrel is as easy as: gem install mongrel.
More info at: http://mongrel.rubyforge.org
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
Mongrel and WEBrick and also suited for production use, but requires additional
installation and currently only works well on OS X/Unix (Windows users are encouraged
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
http://www.lighttpd.net.
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
for production.
But of course its also possible to run Rails on any platform that supports FCGI.
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
== Debugging Rails
Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
First area to check is the application log files. Have "tail -f" commands running
on the server.log and development.log. Rails will automatically display debugging
and runtime information to these files. Debugging info will also be shown in the
browser on requests from 127.0.0.1.
You can also log your own messages directly into the log file from your code using
the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end
The result will be a message in your log file along the lines of:
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
More information on how to use the logger is at http://www.ruby-doc.org/core/
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
These two online (and free) books will bring you up to speed on the Ruby language
and also on programming in general.
== Debugger
Debugger support is available through the debugger command when you start your Mongrel or
Webrick server with --debugger. This means that you can break out of execution at any point
in the code, investigate and change the model, AND then resume execution! Example:
class WeblogController < ActionController::Base
def index
@posts = Post.find(:all)
debugger
end
end
So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
=> "[#nil, \"body\"=>nil, \"id\"=>\"1\"}>,
#\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
...and even better is that you can examine how your runtime objects actually work:
>> f = @posts.first
=> #nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
Finally, when you're ready to resume execution, you enter "cont"
== Console
You can interact with the domain model by starting the console through script/console.
Here you'll have all parts of the application configured, just like it is when the
application is running. You can inspect domain models, change values, and save to the
database. Starting the script without arguments will launch it in the development environment.
Passing an argument will specify a different environment, like script/console production.
To reload your controllers and models after launching the console run reload!
== Description of Contents
app
Holds all the code that's specific to this particular application.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from ApplicationController
which itself descends from ActionController::Base.
app/models
Holds models that should be named like post.rb.
Most models will descend from ActiveRecord::Base.
app/views
Holds the template files for the view that should be named like
weblogs/index.erb for the WeblogsController#index action. All views use eRuby
syntax.
app/views/layouts
Holds the template files for layouts to be used with views. This models the common
header/footer method of wrapping views. In your views, define a layout using the
layout :default and create a file named default.erb. Inside default.erb,
call <% yield %> to render the view using this layout.
app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are generated
for you automatically when using script/generate for controllers. Helpers can be used to
wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
db
Contains the database schema in schema.rb. db/migrate contains all
the sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when generated
using rake doc:app
lib
Application specific libraries. Basically, any kind of custom code that doesn't
belong under controllers, models, or helpers. This directory is in the load path.
public
The directory available for the web server. Contains subdirectories for images, stylesheets,
and javascripts. Also contains the dispatchers and the default HTML files. This should be
set as the DOCUMENT_ROOT of your web server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the script/generate scripts, template
test files will be generated for you and placed in this directory.
vendor
External libraries that the application depends on. Also includes the plugins subdirectory.
This directory is in the load path.
needed to create database-backed web-applications according to the
Model-View-Control pattern of separation. This pattern splits the view (also
called the presentation) into "dumb" templates that are primarily responsible
for inserting pre-built data in between HTML tags. The model contains the
"smart" domain objects (such as Account, Product, Person, Post) that holds all
the business logic and knows how to persist themselves to a database. The
controller handles the incoming requests (such as Save New Account, Update
Product, Show Post) by manipulating the model and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
link:files/vendor/rails/activerecord/README.html.
The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
1. At the command prompt, start a new Rails application using the rails command
and your application name. Ex: rails myapp
(If you've downloaded Rails in a complete tgz or zip, this step is already done)
2. Change directory into myapp and start the web server: script/server (run with --help for options)
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
4. Follow the guidelines to start developing your application
== Web Servers
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
that you can always get up and running quickly.
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
getting up and running with mongrel is as easy as: gem install mongrel.
More info at: http://mongrel.rubyforge.org
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
Mongrel and WEBrick and also suited for production use, but requires additional
installation and currently only works well on OS X/Unix (Windows users are encouraged
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
http://www.lighttpd.net.
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
for production.
But of course its also possible to run Rails on any platform that supports FCGI.
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
== Debugging Rails
Sometimes your application goes wrong. Fortunately there are a lot of tools that
will help you debug it and get it back on the rails.
First area to check is the application log files. Have "tail -f" commands running
on the server.log and development.log. Rails will automatically display debugging
and runtime information to these files. Debugging info will also be shown in the
browser on requests from 127.0.0.1.
You can also log your own messages directly into the log file from your code using
the Ruby logger class from inside your controllers. Example:
class WeblogController < ActionController::Base
def destroy
@weblog = Weblog.find(params[:id])
@weblog.destroy
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
end
end
The result will be a message in your log file along the lines of:
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
More information on how to use the logger is at http://www.ruby-doc.org/core/
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
These two online (and free) books will bring you up to speed on the Ruby language
and also on programming in general.
== Debugger
Debugger support is available through the debugger command when you start your Mongrel or
Webrick server with --debugger. This means that you can break out of execution at any point
in the code, investigate and change the model, AND then resume execution! Example:
class WeblogController < ActionController::Base
def index
@posts = Post.find(:all)
debugger
end
end
So the controller will accept the action, run the first line, then present you
with a IRB prompt in the server window. Here you can do things like:
>> @posts.inspect
=> "[#
#
>> @posts.first.title = "hello from a debugger"
=> "hello from a debugger"
...and even better is that you can examine how your runtime objects actually work:
>> f = @posts.first
=> #
>> f.
Display all 152 possibilities? (y or n)
Finally, when you're ready to resume execution, you enter "cont"
== Console
You can interact with the domain model by starting the console through script/console.
Here you'll have all parts of the application configured, just like it is when the
application is running. You can inspect domain models, change values, and save to the
database. Starting the script without arguments will launch it in the development environment.
Passing an argument will specify a different environment, like script/console production.
To reload your controllers and models after launching the console run reload!
== Description of Contents
app
Holds all the code that's specific to this particular application.
app/controllers
Holds controllers that should be named like weblogs_controller.rb for
automated URL mapping. All controllers should descend from ApplicationController
which itself descends from ActionController::Base.
app/models
Holds models that should be named like post.rb.
Most models will descend from ActiveRecord::Base.
app/views
Holds the template files for the view that should be named like
weblogs/index.erb for the WeblogsController#index action. All views use eRuby
syntax.
app/views/layouts
Holds the template files for layouts to be used with views. This models the common
header/footer method of wrapping views. In your views, define a layout using the
layout :default and create a file named default.erb. Inside default.erb,
call <% yield %> to render the view using this layout.
app/helpers
Holds view helpers that should be named like weblogs_helper.rb. These are generated
for you automatically when using script/generate for controllers. Helpers can be used to
wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
db
Contains the database schema in schema.rb. db/migrate contains all
the sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when generated
using rake doc:app
lib
Application specific libraries. Basically, any kind of custom code that doesn't
belong under controllers, models, or helpers. This directory is in the load path.
public
The directory available for the web server. Contains subdirectories for images, stylesheets,
and javascripts. Also contains the dispatchers and the default HTML files. This should be
set as the DOCUMENT_ROOT of your web server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the script/generate scripts, template
test files will be generated for you and placed in this directory.
vendor
External libraries that the application depends on. Also includes the plugins subdirectory.
This directory is in the load path.
Monday, May 17, 2010
Free hosting for php mysql applications
Free hosting for php,mysql applications with no ads, no hidden charges. Provides control panel. cpanel and FTP etc.,
http://www.000webhost.com/307968.html
http://www.000webhost.com/307968.html
Thursday, May 13, 2010
Different styles for each post in wordpress
Use below process to set different styles for different posts
$postid=$post->ID;
if($postid == 88)
{
$newclass = 'some-css-class-name';
}
h3 class="<= $newclass;?>" > $the_title /h3
$postid=$post->ID;
if($postid == 88)
{
$newclass = 'some-css-class-name';
}
h3 class="<= $newclass;?>" > $the_title /h3
Monday, May 10, 2010
Usefull URLs
Pro drupal book
http://rapidshare.com/files/195879972/pro-drupal-development.pdf
Git on windows
http://kylecordes.com/2008/04/30/git-windows-go/
30+ Applications for doing business on facebook
http://mashable.com/2009/01/22/business-facebook-apps/
Rails automatically detect users geolocation
http://github.com/parolkar/geo_mere_laal
Wordpress Plugin Development
http://www.problogdesign.com/wordpress/a-novice-guide-to-wordpress-plugin-development/
*** Strengths of PHP
http://www.slideshare.net/ijansch/enterprise-php-288851
Search companies
http://www.naukri2000.com/careers/searchemp.php3
http://rapidshare.com/files/195879972/pro-drupal-development.pdf
Git on windows
http://kylecordes.com/2008/04/30/git-windows-go/
30+ Applications for doing business on facebook
http://mashable.com/2009/01/22/business-facebook-apps/
Rails automatically detect users geolocation
http://github.com/parolkar/geo_mere_laal
Wordpress Plugin Development
http://www.problogdesign.com/wordpress/a-novice-guide-to-wordpress-plugin-development/
*** Strengths of PHP
http://www.slideshare.net/ijansch/enterprise-php-288851
Search companies
http://www.naukri2000.com/careers/searchemp.php3
Friday, May 7, 2010
Images websites and blogs
http://wallpapers99.com
http://wallpapers123.blogspot.com
http://www.imagesbazaar.com
http://www.corbis.com
http://wallpapers123.blogspot.com
http://www.imagesbazaar.com
http://www.corbis.com
Tuesday, May 4, 2010
Get results by taking user defined starting id
Below query fetched the results as firt row with id 36
SELECT * from users where uid=36 union SELECT * from users where uid!=36
SELECT * from users where uid=36 union SELECT * from users where uid!=36
Subscribe to:
Posts (Atom)