Tuesday, April 9, 2013

How to delete all .svn folders using Windows Command Prompt?

I was working in a application which contained many “.svn” folder and so i wanted to delete all the folders at once so i fired this command
It will delete all the folders recursively
FOR /R . %f IN (.svn) DO RD /s /q %f

Share/Bookmark

What is the difference between DDL and DML in MySQL?

DDL
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
CREATE – to create table in the database
ALTER – alters the table of the database
DROP – delete table from the database
TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
DML
Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
SELECT – retrieve data from the a database
INSERT – insert data into a table
UPDATE – updates existing data within a table
DELETE – deletes all records from a table, the space for the records remain

Share/Bookmark

How to Check MySQL Version from Command Prompt

Today I was asked to provide MYSQL version which we have used within our integrated system.
We as a developers are not bothered about the version, I was not aware of it and on my local system I have WAMP installed, so it directly gives the MYSQL version.
So to get MYSQL version from “mysql” command line, I got help from one of the site which asked to use the following line of code

select version ();
This will display the current MYSQL version used within system

Share/Bookmark

How to fetch Twitter latest updates using PHP?

many a times we need to fetch twitter updates on to our business website or elsewhere.
This is can very well achieved using the following lines of code.

<?php
$username='sachin_rt';
$format='xml';

$tweet=simplexml_load_file("https://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");

echo $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\0\" target=\"_blank\">\0</a>", $tweet->status[0]->text);
?>
Source
Also if when we need to with our wordpress site

//Set parameter for query string
$username = 'sachin_rt';
$num = '10';
// Get the data from Twitter JSON API
$json = wp_remote_get("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$num");
// Decode JSON into array
$data = json_decode($json['body'], true);
//Create unordered list
echo '<ul class="twitter">';
//Loop through all twitter tweets and display the text with the time it was created
foreach($data as $tweets)
{
    $text = $tweets['text'];
    $date = $tweets['created_at'];
    //Make time human readable ie. 6 hours ago
    $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
    echo '<li>'.ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\0\" target=\"_blank\">\0</a>", $text) . ' '. $h_time . '</li>';
}
//Close list
echo '</ul>';

Share/Bookmark

How to get last element of an array?

Answer:
To get the last element use the end()
<?php

$arr = array('php', 'online', 'tutorials');
echo end($arr); // tutorials
?>

Share/Bookmark

How to repeat a string n times in PHP?

Question
How to repeat a string n times in PHP?
Answer
<?php
echo str_repeat(" www.maxergyinfotech.com ", 30);
?>
Explanation
This function will repeat a particular string 30times and display on the screen

Share/Bookmark

How to find no of checkboxes using javascript?

To find no of checkboxes in html using jQuery or javascript
var inputs = document.getElementsByTagName("input"); //or document.forms[0].elements;  
var cbs = []; //will contain all checkboxes  
var checked = []; //will contain all checked checkboxes  
for (var i = 0; i < inputs.length; i++) {  
  if (inputs[i].type == "checkbox") {  
    cbs.push(inputs[i]);  
    if (inputs[i].checked) {  
      checked.push(inputs[i]);  
    }  
  }  }  var nbCbs = cbs.length; //number of checkboxes  
var nbChecked = checked.length; //number of checked checkboxes 
The following code gives no of check boxes present and no of checked.
Using the above code I have written following code
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function chking()
{
/* For Running jQuery */
var cbs = $("input:checkbox"); //find all checkboxes  
var nbCbs = cbs.size(); //the number of checkboxes  
   var checked = $("input[@type=checkbox]:checked"); //find all checked checkboxes + radio buttons  
var nbChecked = checked.size(); 
/* For Running jQuery */
/* For Running Javascript */
var inputs = document.getElementsByTagName("input"); //or document.forms[0].elements;  
var cbs = []; //will contain all checkboxes  
var checked = []; //will contain all checked checkboxes  
for (var i = 0; i < inputs.length; i++) {  
  if (inputs[i].type == "checkbox") {  
    cbs.push(inputs[i]);  
    if (inputs[i].checked) {  
      checked.push(inputs[i]);  
    }  
  }  }  var nbCbs = cbs.length; //number of checkboxes  
var nbChecked = checked.length; //number of checked checkboxes 

alert(nbCbs);

alert(nbChecked);
/* For Running Javascript */
}
</script>
</head>
<body>
<form method="post" action="">
<input type="checkbox" name="cricket" value="cricket" /> cricket<input type="checkbox" name="football" value="football" /> football<input type="checkbox" name="hockey" value="hockey" /> hockey<input type="checkbox" name="chess" value="chess" /> chess<input type="checkbox" name="cards" value="cards" /> cards<input type="button" value="check" onclick="chking();" />
</form>
</body>
</html>

Share/Bookmark

Redirect Naked URL with www using htaccess file

There is some times requirement to redirect naked URL to URL having “www”.
We have the solutions with our .htaccess file.
The following line of code will help us to achieve the purpose.

### re-direct to www
RewriteCond %{HTTP_HOST} ^phpblogworld.blogspot.in
RewriteRule (.*) http://phpblogworld.blogspot.in/$1 [R=301,L]

Share/Bookmark