Search and replace the the string in Javascript

replace(search str, replace_str):  Replaces the very first occuance oif the search string.

string = 'Praise the Lord';
string = replace('Praise', 'Jesus is');
alert(string);

This returns: "Jesus is the Lord"



Continue Reading

RUBY: Creating dynamic directory in ruby

system()  method executes any commands that we can able to execute through terminal or konsole(console).

e.g
folder = "/tmp"
system("mkdir #{folder}") if !File.directory?(folder)

If you found any errors in the above coding , try to include the ftools library.

e.g
require 'ftools'
folder = "/tmp"
system("mkdir #{folder}") if !File.directory?(folder)

Continue Reading

Write a file oin ruby on rails


log_path = '/home/project/logs'
system("mkdir #{log_path}") if !File.directory?(log_path)
log_content = "test content"
File.open("#{log_path}/log_#{Time.now.to_i}.txt", 'a') { |file|
  file.write "#{log_content}"
}
Continue Reading

RUBY: Ruby on Rails - string replace

gsub

gsub() is the always very useful function in ruby.

Syntax:
string.gsub("<search char>","<replace Char>")
        string.gsub(/'/,"") #replce/remove single quotes from the string


You should be careful that the string variable should not have a nil value. Otherwise it will rise a nil exception. 


Continue Reading

Ruby On Rails - Getting Started


Ruby on Rails, often shortened to Rails, is an open source full-stack web application framework for the Ruby programming language. Ruby on Rails runs on the general-purpose programming language Ruby, which predates it by more than a decade. Rails is a full-stack framework, meaning that it gives the web developer the ability to create pages and applications that gather information from the web server, talk to or query the database, and render templates out of the box. As a result, Rails features a routing system that is independent of the web server.
Continue Reading

Add two Time values in php

function addTime($a, $b)
{
   $sec=$min=$hr=0;
   $a = explode(':',$a);
   $b = explode(':',$b);

   if(($a[2]+$b[2])>= 60)
   {
     $sec=($a[2]+$b[2]) % 60;
     $min+=1;

   }
   else
   $sec=($a[2]+$b[2]);

   if(($a[1]+$b[1]+$min)>= 60)
   {
      $min=($a[1]+$b[1]+$min) % 60;
     $hr+=1;
   }
   else
    $min=$a[1]+$b[1]+$min;
    $hr=$a[0]+$b[0]+$hr;

   $added_time=$hr.":".$min.":".$sec;
   return $added_time;
}
Continue Reading

PHP: Get full web page URL from address bar in php



There are two functions in php to get full url from address bar.


1. $_SERVER['HTTP_HOST']
2. $_SERVER['REQUEST_URI']


$_SERVER['HTTP_HOST'] this function will show only server name.
$_SERVER['REQUEST_URI'] this function will show you the path to file of your url.


Sample Code:
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Continue Reading

PHP: Create CSV file format in php

fputcsv

(PHP 5 >= 5.1.0RC1)
fputcsv --  Format line as CSV and write to file pointer

Description

int fputcsv ( resource handle [, array fields [, string delimiter [, string enclosure]]] )

fputcsv() formats a line (passed as a fields array) as CSV and write it to the specified file handle. Returns the length of the written string, or FALSE on failure.
The optional delimiter parameter sets the field delimiter (one character only). Defaults as a comma: ,.
The optional enclosure parameter sets the field enclosure (one character only) and defaults to a double quotation mark: ".

Example 1. fputcsv() example

$list 
= array (
    
'aaa,bbb,ccc,dddd',
    
'123,456,789',
    
'"aaa","bbb"');
$fp fopen('file.csv''w');

foreach (
$list as $line) {
    
fputcsv($fpsplit(','$line));
}
fclose($fp);?>
Continue Reading

What Is PHP?

What Is PHP? PHP stands for PHP: Hypertext Preprocessor, a recursive acronym. It is mainly a Web server side scripting language. But it can also be used for other purposes.

PHP was originally created by Rasmus Lerdorf in 1995 as a simple Web page generation tool named as PHP/FI (Personal Home Page/Forms Interpreter). Today it becomes the number one of server side scripting languages.


Main features of PHP:

* Cookies - PHP transparently supports HTTP cookies.
* Sessions - PHP supports sessions to allow you to preserve certain data across subsequent accesses.
* Connection handling - PHP maintains a connection in 3 possible states: NORMAL, ABORTED, and TIMEOUT.
* Using remote files - PHP allows you to open remote files with Internet protocols like HTTP or FTP.
* Persistent Database Connections - PHP supports persistent connections to database servers.
* File uploads - PHP allows Web users to upload single or multiple files.
* Safe mode - PHP supports a safe mode with many built-in functions restricted or disabled.
* Command line - PHP supports many command line options.
Continue Reading

What is the difference between Primary Key and Unique key?

Primary Key: A column in a table whose values uniquely identify the
rows in the table. A primary key value cannot be NULL.

Unique Key: Unique Keys are used to uniquely identify each row in the
table. There can be one and only one row for each unique key value. So
NULL can be a unique key.There can be only one primary key for a table but there can be more
than one unique for a table.
Continue Reading

PHP: Performance Tips - For Loop

Don't use for($i=0; $i<=count($arrPerson); $i++) { . . } 
instead of use for($i=0,$total = count($arrPerson); $i<$total; $i++) { .  . }
The previous one will call count function for each iteration of the loop while the second one will call count function just once

Continue Reading

Connect the Mysql Database from local client Computer

Create the New privilege for the Client computer name as the host name.
Then try the following sample code into your client computer,
It will be work exactly.

Sample PHP Code :
$con=mysql_connect('IP Address','root','') or die("Database Connection Failed
". mysql_error());
mysql_select_db('',$con);
$test_query=mysql_query('SELECT * FROM

'); while($row=mysql_fetch_array($test_query)) { echo $row[column].' '; } ?>
Continue Reading