Make Passwords Asterisks visible on your Linux Terminal

display opassword on linux terminal

When you run a command with sudo in Linux, the terminal prompts you to type in your password—and doesn’t give you any visual feedback. Here’s a quick tweak that’ll bring back those familiar asterisks (*) when you type in your password.

Run the following command in terminal.

sudo visudo

Scroll down to the line that looks like this
Defaults env_reset

and change it to
Defaults env_reset,pwfeedback

Press Ctrl+X to finish editing, Y to save changes, and Enter to exit if you’re on Ubuntu. Other Linux distros may have different commands depending on the default editor.

Now, when you run a command with sudo, you should get visual feedback when you type in your password. This should work in all versions of Ubuntu after version 10.04, as well as many other versions of Linux.

Text to Speech with PHP & Google API

text to speech

In this tutorial we will see how to convert text to speech using Google API.It’s damn easy and you may use it to integrate it with your video or use it for your website.

Google API that we will be using is :
http://translate.google.com/translate_tts?tl=en&q=

Here the q variable is empty we need to pass our text separated by a ‘+’ sign.

Eg : http://translate.google.com/translate_tts?tl=en&q=My+name+is+Mukta+Chourishi
Try this on latest browsers.

I have written the complete code below.Try it out.

<?php
if($_POST){
//get the text
$text = substr($_POST['txttext'], 0, 100);

//we are passing as a query string so encode it, space will become +
$text = urlencode($text);

//give a file name and path to store the file
$file  = 'filename';
$file = $file . ".mp3";

//now get the content from the Google API using file_get_contents
$mp3 = file_get_contents("http://translate.google.com/translate_tts?tl=en&q=$text");

//save the mp3 file to the path
file_put_contents($file, $mp3);
}
?>
<html>
<body>
<h2>Text to Speech PHP Script</h2>

<form action="" method="post">
Enter your text:
<textarea name="txttext" rows="5" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Convert">
</form>

<?php  if($_POST){?>

<!-- play the audio file using a player. Here I'm used a HTML5 player. You can use any player insted-->
<audio controls="controls" autoplay="autoplay">
<source src="<?php echo $file; ?>" type="audio/mp3" />
</audio>

<?php }?>

</body>
</html>

HTML to PDF

html to pdf

In this post , I will cover as how you convert an HTML page into PDF  file on a fly.

You basically need an fpdf  library to do the task.You may download it from http://www.fpdf.org/en/download.php

We will be using HTML2FPDF class of fpdf library.

Now let us see, how to convert a sample HTML page into a PDF file using HTML2FPDF Library.

Below is the code for the conversion.

<?php
 require('html2fpdf.php');
 $pdf=new HTML2FPDF();
 $pdf->AddPage();
 $fp = fopen("sample.html","r");
 $strContent = fread($fp, filesize("sample.html"));
 fclose($fp);
 $pdf->WriteHTML($strContent);
 $pdf->Output("sample.pdf");
 echo "PDF file is generated successfully!";
 ?>

Just that simple.You just need to include html2fpdf.php.Here I have passed sample.html page,the pdf generated will have same content of sample.html page,however in the pdf format.

PHP Best Practices

php

  1. Do friendship with the PHP manual.

    • If you are new to php its time to get thorough with the php manual.
    • The manual is incredible very well documented.It has very helpful comments following each article.
    • Before Googling up the problem just head straight into the manual.
  2. Turn on Error Reporting.

    • When you are developing an application it is recommended you turn on error reporting.
    • With error reporting enabled you will see errors that might not be visible otherwise.
    • However during production turn it off back as you might not wish to make your visitors look on those stupid errors.
  3. Try an IDE

    • IDE are very helpful tools for developing an app.
    • They saves a lot of time and make your development easier.
    • Some of the features provided by an IDE are
      • Code Completion. (IDE has intelligence.Understands what you want to write)
      • Syntax Highlightning.(Displays warnings & errors in your code)
      • Code Formatting.(Makes indentation of code possible).
  4. Follow DRY approach

    • DRY stands for “Don’t Repeat Yourself”.
    • Very clear by the name it means don’t have redundant code.
  5. Improve Readability by indenting your code and using white spaces.

    • If you don’t follow this principle your code might end up looking like a garbage.
    • Use it properly so that your code becomes more readable and easy to search.
  6. Don’t use PHP short tags (<?=?>)

    • Often programmers use short tags when accessing variables.
    • However it saves some space but is deprecated.
    • Better use full tags (<?php ?>).
  7. Use proper naming conventions for variables & functions.

    • Use proper , meaningful names while declaring variables,functions and classes.This will help you and a fellow co-worker to understand your code.
  8. Keep Commenting the code.

    • Aside from using white space and indentations to separate the code, you’ll also want to use inline comments to annotate your code. You’ll thank yourself later when you’re needing to go back and find something in the code, or if you just can’t remember what a certain function did. It’s also useful for anyone else who needs to look over your code.
  9. Try a PHP framework.

    • A framework will definitely teach you valuable programming concepts(separating logic from design etc).
    • PHP framework like CodeIgniter or CakePHP allows you to quickly create an application.
    • You can learn a lot about PHP using PHP frameworks. Continue reading

Creating repository at GitHub

STEP 1 : You need to have an account at github.com to create a repository.Definitely you also need git to be installed on your local machine.

STEP 2 : It’s time to go on command line.

git config --global user.name "Your Name Here"

Of course, you’ll need to replace “Your Name Here” with your own name in quotations. It can be your legal name, your online handle, anything. Git doesn’t care, it just needs to know to whom to credit commits and future projects.

Next, tell it your email and make sure it’s the same email you used when you signed up for a GitHub.com account just a moment ago. Do it like this:

git config --global user.email "your_email@youremail.com"

STEP 3 : Create your online repository.

Go back to github.com and then on create repository page.Give your repository a short and memorable name.Now that you have created a repo , lets now add our local directory to repository.

STEP 4 : Initialize git.

On your local system in command prompt follow below steps.

mkdir gitproject

cd gitproject

git init

STEP 5 : Commit with git

Suppose we are inside gitproject directory where we last left off.Follow below steps.

touch readme.txt

You may then see the status with git status command.This will display output which says readme file as untracked.To make it noticed to got we need to add it.

Use git add readme.txt to add file.Hooray we added our first file, so its time to commit.

git commit -m “Add readme.txt” .Here m stands for any message attached with the commit.

STEP 6 : Connect your local repository to github repository.

We need to tell git that our repository exists somewhere online.

git remote add origin https://github.com/username/gitproject.git

To confirm type : git remote -v

STEP 7 : Push Data

Now we want to upload, or “push,” our changes up to the GitHub remote repo. That’s easy. Just type:

git push

GitHub for Newbies.

What is Github ?

GitHub is a web-based hosting service for software development projects that use the Git revision control system. (Source : Wikipedia)

What is Git ?

Git is version control software, which means it manages changes to a project without overwriting any part of that project.

Why use Git ?

Say you and a coworker are both updating pages on the same website. You make your changes, save them, and upload them back to the website. So far, so good. The problem comes when your coworker is working on the same page as you at the same time. One of you is about to have your work overwritten and erased.

A version control application like Git keeps that from happening. You and your coworker can each upload your revisions to the same page, and Git will save two copies. Later, you can merge your changes together without losing any work along the way. You can even revert to an earlier version at any time, because Git keeps a “snapshot” of every change ever made. Continue reading