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

Saturday, March 9, 2013

Encrypting files and folders in Ubuntu

Hi,
      Its easy to bye-pass your system and access your content through recovery mode and so its necessary to Encrypt your files and folders. In Ubuntu, all your files and folders comes under "Home". So, if we encrypt that home folder, then our whole system becomes encrypted!

     There are two options available for encrypting your files and folders.

1. Encrypting while Ubuntu installation itself.
2. Encrypting a particular folder and placing your files and folders there.

     If you are doing an "Fresh installation", then you can easily able to encrypt your home folder using the option "Require my password to login and to decrypt my home folder".

    
     This option provides you with an extra layer of security. Your home folder
is where your personal files are stored.

     By selecting this option, Ubuntu will automatically enable encryption on your home folder, meaning that files and folders must be decrypted using your password before they can be accessed.

     Therefore if someone had physical access to your hard drive (for example, if
your computer was stolen and the hard drive removed
), they would still not
be able to see your files without knowing your password.

(Tip: If you choose this option, be careful not to enable automatic login at a later date. It will cause complications with your encrypted home folder, and will potentially lock you out of important files.)

     1. Whenever the installation get completed, you'll prompted for your login password by this encryption program.

     2. After providing your password, you'll prompted to enter a "Pass-phrase" which helps you to encrypt and decrypt your home folder. (Please don't forget this Pass-phrase, because this will helpful for you if want to manually unlock it)


     3. Or else, you just press the 'Enter key' which Ubuntu will automatically generates a Pass-phrase for you. All you need to do is, just copy and paste it anywhere and keep it safely!

Alternative method:
     In case, if you failed to choose the above option, then no need to worry. You can go for this alternative method, where you are going to create one "Private folder" which is encrypted.

     Inside this private folder, you can save your important documents, files, folders and all these will be encrypted (Hacker can't bye-pass your system and access this private folder and content which are inside it)

     Just follow these steps!
1. Install the ecryptfs-utils software package using the following command.
$ sudo apt-get install ecryptfs-utils
2.Setup your Private directory.
# ecryptfs-setup-private
3. Enter your account's password when prompted.
4. Either choose a mount phrase or let ubuntu to generate.
5. Record both passphrases in a safe location. These are required if you ever
   have to recover your data manually.
6. Logout and login back to mount your encrypted folder.


     Now you are ready to use it. After the Private folder has been set up, any files or folders in it will automatically be encrypted.

Hope you enjoy this! Don't hesitate to ask!

Share/Bookmark

Installing IP messenger on Ubuntu linux

Hi to all Linux users.

Now you can able to install IP-messenger in your linux (Ubuntu) systems.

* IP-messenger connects the people in same network (Platform independent)
* Using this IP-messenger you can able to send all type of files and messages to your neighbors who are    using IP-messenger.
* IP-messenger is purely independent of wi-fi and LAN systems. Its possible to connect a 'wired LAN system' and 'wi-fi system' using IP-messenger.


You are able to download the IP-messenger from the following link:
(If you are using Ubuntu lower than Lucid Lynx 10.04)

If you are using Ubuntu 10.04, then you can easily install it through your "synaptic package manager or Ubuntu software center" (Tip: Search for 'Gnome2 ip messenger')

If you are using Ubuntu lower then 10.04 then please follow the steps to install it:

* Download the IP messenger from the above site
* Extract the tar.gz file
* cd /g2ipmsg-0.9.6
* sudo apt-get install libxml-parser-perl libgnomeui-dev libpanel-applet2-dev gettext intltool
* ./configure
* make
* sudo make install

Now restart the system and start using IP messenger through
* sudo g2ipmsg


Hope you all enjoy this.

Share/Bookmark